Skip to content

Commit

Permalink
fix #1174
Browse files Browse the repository at this point in the history
also better performance of seo_zenphoto
  • Loading branch information
sbillard committed Jul 2, 2018
1 parent 0995bab commit 1f4e621
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 67 deletions.
52 changes: 28 additions & 24 deletions zp-core/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2094,18 +2094,43 @@ function commentsAllowed($type) {
* @return string
*/
function seoFriendly($string) {
$string = trim($string);
$string = trim(preg_replace('~\s+\.\s*~', '.', $string));
if (zp_has_filter('seoFriendly')) {
$string = zp_apply_filter('seoFriendly', $string);
} else { // no filter, do basic cleanup
$string = trim($string);
$string = preg_replace("/\s+/", "-", $string);
$string = preg_replace("/[^a-zA-Z0-9_.-]/", "-", $string);
$string = str_replace(array('---', '--'), '-', $string);
}
$string = preg_replace("/\s+/", "-", $string);
$string = str_replace(array('---', '--'), '-', $string);
return $string;
}

/**
*
* emit the javascript seojs() function
*/
function seoFriendlyJS() {
?>
function seoFriendlyJS(fname) {
fname = fname.trim();
fname = fname.replace(/\s+\.\s*/,'.');
<?php
if (zp_has_filter('seoFriendly_js')) {
echo zp_apply_filter('seoFriendly_js', '');
} else { // no filter, do basic cleanup
?>
fname = fname.replace(/[^a-zA-Z0-9_.-]/g, '-');
<?php
}
?>
fname = fname.replace(/\s+/g, '-');
fname = fname.replace(/--*/g, '-');
return fname;
}
<?php
}

function load_jQuery_CSS() {
?>
<link rel="stylesheet" href="<?php echo WEBPATH . '/' . ZENFOLDER; ?>/js/jQueryui/jquery-ui-1.12.css" type="text/css" />
Expand Down Expand Up @@ -2149,27 +2174,6 @@ function load_jQuery_scripts($where, $ui = true) {
}
}

/**
*
* emit the javascript seojs() function
*/
function seoFriendlyJS() {
if (zp_has_filter('seoFriendly_js')) {
echo zp_apply_filter('seoFriendly_js');
} else {
?>
function seoFriendlyJS(fname) {
fname=fname.trim();
fname=fname.replace(/\s+\.\s*/,'.');
fname = fname.replace(/\s+/g, '-');
fname = fname.replace(/[^a-zA-Z0-9_.-]/g, '-');
fname = fname.replace(/--*/g, '-');
return fname;
}
<?php
}
}

if (!function_exists('hex2bin')) {

function hex2bin($h) {
Expand Down
14 changes: 3 additions & 11 deletions zp-core/zp-extensions/seo_null.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

/**
* Changes <i>white space</i> characters to hyphens.
* Changes <i>white space</i> characters to hyphens. Bypasses the standard replacement of
* non-ascii characaters with a hyphen
*
* @author Stephen Billard (sbillard)
*
Expand All @@ -11,7 +12,6 @@
$plugin_is_filter = 5 | ADMIN_PLUGIN;
$plugin_description = gettext('SEO <em>Null</em> filter.');
$plugin_notice = gettext('The only translation performed is one or more <em>white space</em> characters are converted to a <em>hyphen</em>.');
$plugin_disable = (zp_has_filter('seoFriendly') && !extensionEnabled('seo_null')) ? sprintf(gettext('Only one SEO filter plugin may be enabled. <a href="#%1$s"><code>%1$s</code></a> is already enabled.'), stripSuffix(get_filterScript('seoFriendly'))) : '';

zp_register_filter('seoFriendly', 'null_seo::filter');
zp_register_filter('seoFriendly_js', 'null_seo::js');
Expand Down Expand Up @@ -51,19 +51,11 @@ function handleOption($option, $currentValue) {
* @return string
*/
static function filter($string) {
$string = preg_replace("/\s+/", "-", $string);
return $string;
}

static function js($string) {
$js = "
function seoFriendlyJS(fname) {
fname=fname.trim();
fname=fname.replace(/\s+\.\s*/,'.');
fname = fname.replace(/\s+/g, '-');
return fname;
}\n";
return $js;
return $string;
}

}
Expand Down
43 changes: 11 additions & 32 deletions zp-core/zp-extensions/seo_zenphoto.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,11 @@
*/
$plugin_is_filter = defaultExtension(5 | ADMIN_PLUGIN);
$plugin_description = gettext("SEO filter to translate extended characters into their basic alpha-numeric equivalents.");
$plugin_disable = (zp_has_filter('seoFriendly') && !extensionEnabled('seo_zenphoto')) ? sprintf(gettext('Only one SEO filter plugin may be enabled. <a href="#%1$s"><code>%1$s</code></a> is already enabled.'), stripSuffix(get_filterScript('seoFriendly'))) : '';

$option_interface = 'zenphoto_seo';

if ($plugin_disable) {
enableExtension('zenphoto_seo', 0);
} else {
zp_register_filter('seoFriendly', 'zenphoto_seo::filter');
zp_register_filter('seoFriendly_js', 'zenphoto_seo::js');
}
zp_register_filter('seoFriendly', 'zenphoto_seo::filter');
zp_register_filter('seoFriendly_js', 'zenphoto_seo::js');

/**
* Option handler class
Expand All @@ -44,6 +39,9 @@ function __construct() {
* @return array
*/
function getOptionsSupported() {

echo seoFriendly('Töasted álmonds');

return array(gettext('Lowercase only') => array('key' => 'zenphoto_seo_lowercase', 'type' => OPTION_TYPE_CHECKBOX,
'desc' => gettext('When set, all characters are converted to lower case.')));
}
Expand Down Expand Up @@ -79,7 +77,6 @@ function handleOption($option, $currentValue) {
"" => "A",
"" => "A",
"" => "A",
"Å" => "A",
"Ä" => "AE",
"Æ" => "AE",
"Ǽ" => "AE",
Expand Down Expand Up @@ -167,7 +164,6 @@ function handleOption($option, $currentValue) {
"Į" => "I",
"Ȋ" => "I",
"" => "I",
"" => "I",
"Ɨ" => "I",
"" => "I",
"Ĵ" => "J",
Expand All @@ -179,7 +175,6 @@ function handleOption($option, $currentValue) {
"Ķ" => "K",
"" => "L",
"" => "L",
"" => "L",
"Ļ" => "L",
"" => "L",
"Ľ" => "L",
Expand Down Expand Up @@ -521,13 +516,10 @@ function handleOption($option, $currentValue) {
"" => "p",
"" => "p",
"ƥ" => "p",
"ŕ" => "p",
"" => "p",
"ř" => "p",
"ȑ" => "p",
"ȓ" => "p",
"" => "p",
"ŗ" => "p",
"" => "p",
"" => "p",
"ś" => "s",
Expand All @@ -541,6 +533,7 @@ function handleOption($option, $currentValue) {
"" => "s",
"" => "s",
"ß" => "ss",
"" => "SS",
"" => "t",
"" => "t",
"" => "t",
Expand Down Expand Up @@ -578,7 +571,6 @@ function handleOption($option, $currentValue) {
"ǖ" => "u",
"ǜ" => "u",
"ǘ" => "u",
"ǖ" => "u",
"ǚ" => "u",
"" => "u",
"" => "u",
Expand Down Expand Up @@ -859,8 +851,6 @@ function handleOption($option, $currentValue) {
"" => "O",
"" => "O",
"Ő" => "O",
"ø" => "o",
"Ø" => "O",
"ö" => "oe",
"Ö" => "Oe",
"" => "p",
Expand All @@ -881,9 +871,6 @@ function handleOption($option, $currentValue) {
"" => "ts",
"" => "ts",
"" => "u",
"ü" => "u",
"ü" => "u",
"Ü" => "Ue",
"" => "v",
"" => "y",
"" => "y",
Expand Down Expand Up @@ -1082,17 +1069,16 @@ function handleOption($option, $currentValue) {
* @return string
*/
static function filter($string) {
// strip/convert a few specific characters
$string = strtr($string, zenphoto_seo::$specialchars);
if (getOption('zenphoto_seo_lowercase'))
$string = str_replace(array_keys(self::$specialchars), self::$specialchars, $string);
if (getOption('zenphoto_seo_lowercase')) {
$string = strtolower($string);
}
$string = preg_replace("/\s+/", "-", $string);
$string = preg_replace("/[^a-zA-Z0-9_.-]/", "-", $string);
$string = str_replace(array('---', '--'), '-', $string);
return $string;
}

static function js($string) {
static function js($js) {
$xlate = array();
foreach (zenphoto_seo::$specialchars as $from => $to) {
if (array_key_exists($to, $xlate)) {
Expand All @@ -1101,11 +1087,6 @@ static function js($string) {
$xlate[$to] = $from;
}
}
$js = '
function seoFriendlyJS(fname) {
fname=fname.trim();
fname=fname.replace(/\s+\.\s*/,".");
';

foreach ($xlate as $to => $from) {
$js .= " fname = fname.replace(/[" . $from . "]/g, '" . $to . "');\n";
Expand All @@ -1115,11 +1096,9 @@ function seoFriendlyJS(fname) {
$js .= " fname = fname.toLowerCase();\n";
}
$js .= "
fname = fname.replace(/\s+/g, '-');
fname = fname.replace(/[^a-zA-Z0-9_.-]/g, '-');
fname = fname.replace(/--*/g, '-');
return fname;
}\n";
";
return $js;
}

Expand Down

0 comments on commit 1f4e621

Please sign in to comment.