Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prise en compte des liens externes pour les urls des pages statiques #403

Merged
merged 1 commit into from
Apr 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 27 additions & 18 deletions core/lib/class.plx.utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class plxUtils {

const THUMB_WIDTH = 48;
const THUMB_HEIGHT = 48;
const REMOVE_WORDS = array(
'en' => 'an?|as|at|before|but|by|for|from|is|in(?:to)?|like|off?on(?:to)?|per|since|than|the|this|that|to|up|via|with',
'de' => 'das|der|die|fur|am',
'fr' => 'a|de?|des|du|e?n|la|le|une?|vers'
);

/**
* Méthode qui vérifie si une variable est définie.
* Renvoie la valeur de la variable ou la valeur par défaut passée en paramètre
Expand Down Expand Up @@ -98,7 +104,7 @@ public static function checkSite(&$site, $reset=true) {
# On vérifie le site via une expression régulière
# Méthode imme_emosol - http://mathiasbynens.be/demo/url-regex
# modifiée par Amaury Graillat pour prendre en compte les tirets dans les urls
if(preg_match('@(https?|ftp)://(-\.)?([^\s/?\.#]+\.?)+([/?][^\s]*)?$@iS', $site))
if(preg_match('@(https?|s?ftp)://(-\.)?([^\s/?\.#]+\.?)+([/?][^\s]*)?$@iS', $site))
return true;
else {
if($reset) $site='';
Expand Down Expand Up @@ -440,15 +446,15 @@ public static function testLibXml($format="<li><span style=\"color:#color\">#sym
* @param charset charset à utiliser dans le formatage de la chaine (par défaut utf-8)
* @return string chaine formatée
**/
public static function removeAccents($str,$charset='utf-8') {
public static function removeAccents($str, $charset=PLX_CHARSET) {

$str = htmlentities($str, ENT_NOQUOTES, $charset);
$a = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ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', 'ż', 'Ž', 'ž', 'ſ', 'ƒ', 'Ơ', 'ơ', 'Ư', 'ư', 'Ǎ', 'ǎ', 'Ǐ', 'ǐ', 'Ǒ', 'ǒ', 'Ǔ', 'ǔ', 'Ǖ', 'ǖ', 'Ǘ', 'ǘ', 'Ǚ', 'ǚ', 'Ǜ', 'ǜ', 'Ǻ', 'ǻ', 'Ǽ', 'ǽ', 'Ǿ', 'ǿ');
$b = array('A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o');
$str = str_replace($a, $b, $str);
$str = preg_replace('#\&([A-za-z])(?:acute|cedil|circ|grave|ring|tilde|uml|uro)\;#', '\1', $str);
$str = preg_replace('#\&([A-za-z]{2})(?:lig)\;#', '\1', $str); # pour les ligatures e.g. '&oelig;'
$str = preg_replace('#\&[^;]+\;#', '', $str); # supprime les autres caractères
$str = preg_replace('#\&[^;]+\;#', '', $str); # supprime les entités HTML
return $str;
}

Expand Down Expand Up @@ -514,32 +520,35 @@ public static function translitterate($str, $reverse=false) {
* @param boolean $remove retire les mots sans valeur sémantique
* @param string $replace
* @param boolean $lower
* @return string valid URL
* @return string valid URL
* @author J.P. Pourrez (bazooka07)
* */
public static function urlify($str, $remove=true, $replace='-', $lower=true) {
public static function urlify($url, $remove=true, $replace='-', $lower=true) {

$remove_words = array(
'en' => 'a|an|as|at|before|but|by|for|from|is|into|in|like|off?|on|onto|per|since|than|the|this|that|to|up|via|with',
'de' => 'das|der|die|fur|am',
'fr' => 'a|de?|des|du|e?n|la|le|une?|vers'
);
$scheme = parse_url($url, PHP_URL_SCHEME);
if(!empty($scheme)) {
if($scheme == 'data') { return $url; }

$clean_str = plxUtils::translitterate(trim(html_entity_decode($str)));
$url = substr($url, strlen($scheme) + 3); // http://
}
$clean_url = plxUtils::translitterate(trim(html_entity_decode($url)));

if($remove && defined('PLX_SITE_LANG') && array_key_exists(PLX_SITE_LANG, $remove_words)) {
$tmpstr = preg_replace('@\b('.$remove_words[PLX_SITE_LANG].')\b@u', $replace, $clean_str);
$clean_str = preg_replace('@\s*'.$replace.'(\s*'.$replace.')*\s*@', $replace, $tmpstr);
if($remove && defined('PLX_SITE_LANG') && array_key_exists(PLX_SITE_LANG, self::REMOVE_WORDS)) {
$clean_url = preg_replace('@\b(' . self::REMOVE_WORDS[PLX_SITE_LANG] . ')\b@u', $replace, $clean_url);
}

// remove accents
$clean_str = plxUtils::removeAccents($clean_str,PLX_CHARSET);
$clean_url = plxUtils::removeAccents($clean_url, PLX_CHARSET);

// remove whitespace
$clean_str = preg_replace('@\s+@',$replace,$clean_str);
$clean_url = preg_replace('@[\s' . $replace . ']+@', $replace, $clean_url);

// remove non-alphanumeric character
$clean_str = trim(preg_replace('@[^\w-]@','',$clean_str),'-');
$clean_url = trim(preg_replace('@[^\w\.-]+@', '', $clean_url), '-');

if($lower) { $clean_url = strtolower($clean_url); }

return ($lower) ? strtolower($clean_str) : $clean_str;
return (empty($scheme)) ? $clean_url : $scheme . '://' . $clean_url;
}

/**
Expand Down