Skip to content

Commit

Permalink
Optional Unicode-URLs unterstützen (#360)
Browse files Browse the repository at this point in the history
  • Loading branch information
gharlan authored Sep 18, 2020
1 parent be8d0d8 commit ff8314b
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 20 deletions.
6 changes: 3 additions & 3 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@

rex_delete_cache();

if (!class_exists('rex_yrewrite_seo_visibility')) {
require_once('lib/yrewrite/seo_visibility.php');
if (!class_exists('rex_yrewrite_settings')) {
require_once('lib/yrewrite/settings.php');
}
rex_yrewrite_seo_visibility::install();
rex_yrewrite_settings::install();
5 changes: 3 additions & 2 deletions lang/de_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ yrewrite_expiry_date = Deaktivierungsdatum

yrewrite_perm_url_edit = YRewrite: URL editieren
yrewrite_perm_seo_edit = YRewrite: SEO-Daten editieren
yrewrite_seo_settings = Einstellungen
yrewrite_seo_saved = Einstellungen gespeichert
yrewrite_settings = Einstellungen
yrewrite_settings_saved = Einstellungen gespeichert
yrewrite_unicode_urls = Unicode-Zeichen in URLs erlauben (Umlaute, chinesische/kyrillische Zeichen etc.)
yrewrite_hide_url_block = URL-Block verbergen
yrewrite_hide_seo_block = SEO-Block verbergen
5 changes: 3 additions & 2 deletions lang/en_gb.lang
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ yrewrite_expiry_date = Date of deactivation

yrewrite_perm_url_edit = Yrewrite: URL editing
yrewrite_perm_seo_edit = Yrewrite: SEO-Data editing
yrewrite_seo_settings = Settings
yrewrite_seo_saved = Settings updated
yrewrite_settings = Settings
yrewrite_settings_saved = Settings updated
yrewrite_unicode_urls = Allow unicode chars in URLs (umlauts, chinese/cyrillic characters etc.)
yrewrite_hide_url_block = Hide URL-Block
yrewrite_hide_seo_block = Hide SEO-Block
4 changes: 2 additions & 2 deletions lang/es_es.lang
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ yrewrite_expiry_date = fecha de desactivación

yrewrite_perm_url_edit = Yrewrite: Edición de URL
yrewrite_perm_seo_edit = Yrewrite: Edición de datos SEO
yrewrite_seo_settings = Ajustes
yrewrite_seo_saved = Configuraciones guardadas
yrewrite_settings = Ajustes
yrewrite_settings_saved = Configuraciones guardadas
yrewrite_hide_url_block = Ocultar bloque de URL
yrewrite_hide_seo_block = Ocultar bloque SEO
4 changes: 2 additions & 2 deletions lang/sv_se.lang
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ yrewrite_expiry_date = Avaktiveringsdatum

yrewrite_perm_url_edit = Yrewrite: redigera URL
yrewrite_perm_seo_edit = Yrewrite: redigera SEO-data
yrewrite_seo_settings = Inställningar
yrewrite_seo_saved = Inställningar sparades
yrewrite_settings = Inställningar
yrewrite_settings_saved = Inställningar sparades
yrewrite_hide_url_block = Dölj URL-block
yrewrite_hide_seo_block = Dölj SEO-block
7 changes: 7 additions & 0 deletions lib/yrewrite/scheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ public function getAlternativeCandidates($path, rex_yrewrite_domain $domain)
*/
public function normalize($string, $clang = 1)
{
if (rex_addon::get('yrewrite')->getConfig('unicode_urls')) {
$string = str_replace(["'", '', 'ʻ'], '', $string);
$string = preg_replace('/[^\p{L&}\p{Lo}\p{M}\p{N}\p{Sc}]+/u', '-', $string);
$string = mb_strtolower(trim($string, '-'));
return $string;
}

$string = str_replace(
['Ä', 'Ö', 'Ü', 'ä', 'ö', 'ü', 'ß', 'À', 'à', 'Á', 'á', 'ç', 'È', 'è', 'É', 'é', 'ë', 'Ì', 'ì', 'Í', 'í', 'Ï', 'ï', 'Ò', 'ò', 'Ó', 'ó', 'ô', 'Ù', 'ù', 'Ú', 'ú', 'Č', 'č', 'Ł', 'ł', 'ž', '/', '®', '©', ''],
['Ae', 'Oe', 'Ue', 'ae', 'oe', 'ue', 'ss', 'A', 'a', 'A', 'a', 'c', 'E', 'e', 'E', 'e', 'e', 'I', 'i', 'I', 'i', 'I', 'i', 'O', 'o', 'O', 'o', 'o', 'U', 'u', 'U', 'u', 'C', 'c', 'L', 'l', 'z', '-', '', '', ''],
Expand Down
16 changes: 13 additions & 3 deletions lib/yrewrite/seo_visibility.php → lib/yrewrite/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @package redaxo\yrewrite
*/

class rex_yrewrite_seo_visibility
class rex_yrewrite_settings
{
/**
* @return rex_addon
Expand All @@ -27,10 +27,13 @@ public static function processFormPost()

// Process form data
if (rex_post('submit', 'boolean')) {
$addon->setConfig('unicode_urls', rex_post('yrewrite_unicode_urls', 'bool'));
$addon->setConfig('yrewrite_hide_url_block', rex_post('yrewrite_hide_url_block', 'bool'));
$addon->setConfig('yrewrite_hide_seo_block', rex_post('yrewrite_hide_seo_block', 'bool'));

$message = rex_view::success($addon->i18n('yrewrite_seo_saved'));
rex_yrewrite::deleteCache();

$message = rex_view::success($addon->i18n('yrewrite_settings_saved'));
}

return $message;
Expand All @@ -45,6 +48,10 @@ public static function getForm()

// Checkboxes
$checkbox_elements = [
[
'label' => '<label for="yrewrite-unicode-urls">'.$addon->i18n('yrewrite_unicode_urls').'</label>',
'field' => '<input type="checkbox" id="yrewrite-unicode-urls" name="yrewrite_unicode_urls" value="1" '.($addon->getConfig('unicode_urls') ? ' checked="checked"' : '').' />',
],
[
'label' => '<label for="yrewrite-hide-url-block">'.$addon->i18n('yrewrite_hide_url_block').'</label>',
'field' => '<input type="checkbox" id="yrewrite-hide-url-block" name="yrewrite_hide_url_block" value="1" '.($addon->getConfig('yrewrite_hide_url_block') ? ' checked="checked"' : '').' />',
Expand Down Expand Up @@ -72,7 +79,7 @@ public static function getForm()
// Form
$fragment = new rex_fragment();
$fragment->setVar('class', 'edit');
$fragment->setVar('title', $addon->i18n('yrewrite_seo_settings'));
$fragment->setVar('title', $addon->i18n('yrewrite_settings'));
$fragment->setVar('body', $checkboxes, false);
$fragment->setVar('buttons', $submit, false);

Expand All @@ -90,6 +97,9 @@ public static function install()
{
$addon = self::getAddon();

if (!$addon->hasConfig('unicode_urls')) {
$addon->setConfig('unicode_urls', false);
}
if (!$addon->hasConfig('yrewrite_hide_url_block')) {
$addon->setConfig('yrewrite_hide_url_block', false);
}
Expand Down
12 changes: 6 additions & 6 deletions pages/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
<h3>' . $this->i18n('info_tipps') . '</h3>
<p>' . rex_i18n::rawMsg('yrewrite_info_tipps_text') . '
<p>' . rex_i18n::rawMsg('yrewrite_info_tipps_text') . '
<h3>' . $this->i18n('info_seo') . '</h3>
<p>' . rex_i18n::rawMsg('yrewrite_info_seo_text') . '
<br /><br />'.highlight_string('<?php
$seo = new rex_yrewrite_seo();
echo $seo->getTitleTag().PHP_EOL;
Expand All @@ -60,8 +60,8 @@
/**
* Process and display visibility settings form
*/
echo rex_yrewrite_seo_visibility::processFormPost();
echo rex_yrewrite_seo_visibility::getForm();
echo rex_yrewrite_settings::processFormPost();
echo rex_yrewrite_settings::getForm();

$domains = [];

Expand Down

0 comments on commit ff8314b

Please sign in to comment.