From 8bae40449f2a5bfcc6ef86f82be1e15bdb9b9acd Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 22 Oct 2021 08:07:19 +0000 Subject: remove library/urlify and use vendor/jbroadway/urlify instead --- Zotlabs/Module/Impel.php | 71 +++++++------- Zotlabs/Module/Import.php | 6 +- Zotlabs/Module/Item.php | 5 +- Zotlabs/Module/New_channel.php | 8 +- include/import.php | 3 +- library/urlify/.gitignore | 3 - library/urlify/INSTALL | 10 -- library/urlify/README.md | 70 -------------- library/urlify/URLify.php | 188 ------------------------------------ library/urlify/composer.json | 21 ---- library/urlify/tests/URLifyTest.php | 31 ------ library/urlify/tests/bootstrap.php | 9 -- library/urlify/tests/phpunit.xml | 8 -- 13 files changed, 46 insertions(+), 387 deletions(-) delete mode 100644 library/urlify/.gitignore delete mode 100644 library/urlify/INSTALL delete mode 100644 library/urlify/README.md delete mode 100644 library/urlify/URLify.php delete mode 100644 library/urlify/composer.json delete mode 100644 library/urlify/tests/URLifyTest.php delete mode 100644 library/urlify/tests/bootstrap.php delete mode 100644 library/urlify/tests/phpunit.xml diff --git a/Zotlabs/Module/Impel.php b/Zotlabs/Module/Impel.php index e05027d9f..869de2669 100644 --- a/Zotlabs/Module/Impel.php +++ b/Zotlabs/Module/Impel.php @@ -1,5 +1,9 @@ false); - + if(! local_channel()) json_return_and_die($ret); - + logger('impel: ' . print_r($_REQUEST,true), LOGGER_DATA); - + $elm = $_REQUEST['element']; $x = base64url_decode($elm); if(! $x) json_return_and_die($ret); - + $j = json_decode($x,true); if(! $j) json_return_and_die($ret); - + // logger('element: ' . print_r($j,true)); $channel = \App::get_channel(); - + $arr = array(); $is_menu = false; - + // a portable menu has its links rewritten with the local baseurl $portable_menu = false; - + switch($j['type']) { case 'webpage': $arr['item_type'] = ITEM_TYPE_WEBPAGE; @@ -58,12 +62,12 @@ class Impel extends \Zotlabs\Web\Controller { case 'menu': $is_menu = true; $installed_type = t('menu'); - break; + break; default: logger('mod_impel: unrecognised element type' . print_r($j,true)); break; } - + if($is_menu) { $m = array(); $m['menu_channel_id'] = local_channel(); @@ -73,23 +77,23 @@ class Impel extends \Zotlabs\Web\Controller { $m['menu_created'] = datetime_convert($j['created']); if($j['edited']) $m['menu_edited'] = datetime_convert($j['edited']); - + $m['menu_flags'] = 0; if($j['flags']) { if(in_array('bookmark',$j['flags'])) $m['menu_flags'] |= MENU_BOOKMARK; if(in_array('system',$j['flags'])) $m['menu_flags'] |= MENU_SYSTEM; - + } - + $menu_id = menu_create($m); - + if($menu_id) { if(is_array($j['items'])) { foreach($j['items'] as $it) { $mitem = array(); - + $mitem['mitem_link'] = str_replace('[channelurl]',z_root() . '/channel/' . $channel['channel_address'],$it['link']); $mitem['mitem_link'] = str_replace('[pageurl]',z_root() . '/page/' . $channel['channel_address'],$it['link']); $mitem['mitem_link'] = str_replace('[cloudurl]',z_root() . '/cloud/' . $channel['channel_address'],$it['link']); @@ -115,7 +119,7 @@ class Impel extends \Zotlabs\Web\Controller { intval(local_channel()) ); } - } + } $ret['success'] = true; } $x = $ret; @@ -132,22 +136,21 @@ class Impel extends \Zotlabs\Web\Controller { $arr['owner_xchan'] = get_observer_hash(); $arr['author_xchan'] = (($j['author_xchan']) ? $j['author_xchan'] : get_observer_hash()); $arr['mimetype'] = (($j['mimetype']) ? $j['mimetype'] : 'text/bbcode'); - + if(! $j['mid']) { $j['uuid'] = item_message_id(); $j['mid'] = z_root() . '/item/' . $j['uuid']; } $arr['uuid'] = $j['uuid']; $arr['mid'] = $arr['parent_mid'] = $j['mid']; - - + + if($j['pagetitle']) { - require_once('library/urlify/URLify.php'); - $pagetitle = strtolower(\URLify::transliterate($j['pagetitle'])); + $pagetitle = strtolower(URLify::transliterate($j['pagetitle'])); } - + // Verify ability to use html or php!!! - + $execflag = ((intval($channel['channel_id']) == intval(local_channel()) && ($channel['channel_pageflags'] & PAGE_ALLOWCODE)) ? true : false); $i = q("select id, edited, item_deleted from item where mid = '%s' and uid = %d limit 1", @@ -156,7 +159,7 @@ class Impel extends \Zotlabs\Web\Controller { ); \Zotlabs\Lib\IConfig::Set($arr,'system',$namespace,(($pagetitle) ? $pagetitle : substr($arr['mid'],0,16)),true); - + if($i) { $arr['id'] = $i[0]['id']; // don't update if it has the same timestamp as the original @@ -174,24 +177,24 @@ class Impel extends \Zotlabs\Web\Controller { else $x = item_store($arr,$execflag); } - + if($x && $x['success']) { $item_id = $x['item_id']; } } - + if($x['success']) { $ret['success'] = true; - info( sprintf( t('%s element installed'), $installed_type)); + info( sprintf( t('%s element installed'), $installed_type)); } else { - notice( sprintf( t('%s element installation failed'), $installed_type)); + notice( sprintf( t('%s element installation failed'), $installed_type)); } - - //??? should perhaps return ret? + + //??? should perhaps return ret? json_return_and_die(true); - + } - + } diff --git a/Zotlabs/Module/Import.php b/Zotlabs/Module/Import.php index 2a7ea100c..ec47e370b 100644 --- a/Zotlabs/Module/Import.php +++ b/Zotlabs/Module/Import.php @@ -5,14 +5,12 @@ namespace Zotlabs\Module; require_once('include/channel.php'); require_once('include/import.php'); require_once('include/perm_upgrade.php'); -require_once('library/urlify/URLify.php'); use App; +use URLify; use Zotlabs\Daemon\Master; use Zotlabs\Lib\Libzot; use Zotlabs\Web\Controller; -use Zotlabs\Web\HTTPSig; -use Zotlabs\Lib\PConfig; /** @@ -175,7 +173,7 @@ class Import extends Controller { } if ((!$x) || strlen($x) > 64) { - $x = strtolower(\URLify::transliterate($newname)); + $x = strtolower(URLify::transliterate($newname)); } $newname = $x; } diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php index 7099a54e5..34ca4fcdf 100644 --- a/Zotlabs/Module/Item.php +++ b/Zotlabs/Module/Item.php @@ -2,6 +2,7 @@ namespace Zotlabs\Module; +use URLify; use Zotlabs\Lib\Config; use Zotlabs\Lib\IConfig; use Zotlabs\Lib\Enotify; @@ -15,7 +16,6 @@ use Zotlabs\Lib\Libzot; use Zotlabs\Lib\Libsync; use Zotlabs\Lib\ThreadListener; use Zotlabs\Access\PermissionRoles; -use App; require_once('include/crypto.php'); require_once('include/items.php'); @@ -415,8 +415,7 @@ class Item extends Controller { } if($pagetitle) { - require_once('library/urlify/URLify.php'); - $pagetitle = strtolower(\URLify::transliterate($pagetitle)); + $pagetitle = strtolower(URLify::transliterate($pagetitle)); } diff --git a/Zotlabs/Module/New_channel.php b/Zotlabs/Module/New_channel.php index 84d492f8f..3b0b35258 100644 --- a/Zotlabs/Module/New_channel.php +++ b/Zotlabs/Module/New_channel.php @@ -1,6 +1,8 @@ 1) ? argv(1) : ''); if($cmd === 'autofill.json') { - require_once('library/urlify/URLify.php'); $result = array('error' => false, 'message' => ''); $n = trim($_REQUEST['name']); @@ -24,7 +25,7 @@ class New_channel extends \Zotlabs\Web\Controller { } if((! $x) || strlen($x) > 64) - $x = strtolower(\URLify::transliterate($n)); + $x = strtolower(URLify::transliterate($n)); $test = array(); @@ -46,7 +47,6 @@ class New_channel extends \Zotlabs\Web\Controller { } if($cmd === 'checkaddr.json') { - require_once('library/urlify/URLify.php'); $result = array('error' => false, 'message' => ''); $n = trim($_REQUEST['nick']); if(! $n) { @@ -60,7 +60,7 @@ class New_channel extends \Zotlabs\Web\Controller { } if((! $x) || strlen($x) > 64) - $x = strtolower(\URLify::transliterate($n)); + $x = strtolower(URLify::transliterate($n)); $test = array(); diff --git a/include/import.php b/include/import.php index b0a1a77e5..8707a9430 100644 --- a/include/import.php +++ b/include/import.php @@ -1719,8 +1719,7 @@ function import_webpage_element($element, $channel, $type) { $namespace = 'WEBPAGE'; $name = $element['pagelink']; if($name) { - require_once('library/urlify/URLify.php'); - $name = strtolower(\URLify::transliterate($name)); + $name = strtolower(URLify::transliterate($name)); } $arr['title'] = $element['title']; $arr['term'] = $element['term']; diff --git a/library/urlify/.gitignore b/library/urlify/.gitignore deleted file mode 100644 index 9df9b994a..000000000 --- a/library/urlify/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -vendor -composer.phar -composer.lock diff --git a/library/urlify/INSTALL b/library/urlify/INSTALL deleted file mode 100644 index e92e55e11..000000000 --- a/library/urlify/INSTALL +++ /dev/null @@ -1,10 +0,0 @@ -To install URLify, you can add it as a dependency ar by downloading the composer.phar executable. - -$ curl -s http://getcomposer.org/installer | php - -and run install - -$ php composer.phar install - -For more details, see http://getcomposer.org. - diff --git a/library/urlify/README.md b/library/urlify/README.md deleted file mode 100644 index 7c2c42a12..000000000 --- a/library/urlify/README.md +++ /dev/null @@ -1,70 +0,0 @@ -# URLify for PHP - -A PHP port of [URLify.js](https://github.com/django/django/blob/master/django/contrib/admin/static/admin/js/urlify.js) -from the Django project. Handles symbols from Latin languages, Greek, Turkish, -Russian, Ukrainian, Czech, Polish, and Latvian. Symbols it cannot transliterate -it will simply omit. - -* Author: [jbroadway](http://github.com/jbroadway) -* License: MIT - -## Usage: - -To generate slugs for URLs: - -```php - -``` - -To simply transliterate characters: - -```php - -``` - -To extend the character list: - -```php - '?', '®' => '(r)', '¼' => '1/4', - '¼' => '1/2', '¾' => '3/4', '¶' => 'P' -)); - -echo URLify::downcode ('¿ ® ¼ ¼ ¾ ¶'); -// "? (r) 1/2 1/2 3/4 P" - -?> -``` - -To extend the list of words to remove: - -```php - -``` diff --git a/library/urlify/URLify.php b/library/urlify/URLify.php deleted file mode 100644 index 1337f9a91..000000000 --- a/library/urlify/URLify.php +++ /dev/null @@ -1,188 +0,0 @@ - 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', 'Ø' => 'O', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', 'Ű' => 'U', - 'Ý' => 'Y', 'Þ' => 'TH', 'ß' => 'ss', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => - 'a', 'å' => 'a', 'æ' => 'ae', 'ç' => 'c', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', - 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ð' => 'd', 'ñ' => 'n', 'ò' => 'o', 'ó' => - 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ő' => 'o', 'ø' => 'o', 'ù' => 'u', 'ú' => 'u', - 'û' => 'u', 'ü' => 'u', 'ű' => 'u', 'ý' => 'y', 'þ' => 'th', 'ÿ' => 'y' - ), - 'latin_symbols_map' => array ( - '©' => '(c)' - ), - 'greek_map' => array ( - 'α' => 'a', 'β' => 'b', 'γ' => 'g', 'δ' => 'd', 'ε' => 'e', 'ζ' => 'z', 'η' => 'h', 'θ' => '8', - 'ι' => 'i', 'κ' => 'k', 'λ' => 'l', 'μ' => 'm', 'ν' => 'n', 'ξ' => '3', 'ο' => 'o', 'π' => 'p', - 'ρ' => 'r', 'σ' => 's', 'τ' => 't', 'υ' => 'y', 'φ' => 'f', 'χ' => 'x', 'ψ' => 'ps', 'ω' => 'w', - 'ά' => 'a', 'έ' => 'e', 'ί' => 'i', 'ό' => 'o', 'ύ' => 'y', 'ή' => 'h', 'ώ' => 'w', 'ς' => 's', - 'ϊ' => 'i', 'ΰ' => 'y', 'ϋ' => 'y', 'ΐ' => 'i', - 'Α' => 'A', 'Β' => 'B', 'Γ' => 'G', 'Δ' => 'D', 'Ε' => 'E', 'Ζ' => 'Z', 'Η' => 'H', 'Θ' => '8', - 'Ι' => 'I', 'Κ' => 'K', 'Λ' => 'L', 'Μ' => 'M', 'Ν' => 'N', 'Ξ' => '3', 'Ο' => 'O', 'Π' => 'P', - 'Ρ' => 'R', 'Σ' => 'S', 'Τ' => 'T', 'Υ' => 'Y', 'Φ' => 'F', 'Χ' => 'X', 'Ψ' => 'PS', 'Ω' => 'W', - 'Ά' => 'A', 'Έ' => 'E', 'Ί' => 'I', 'Ό' => 'O', 'Ύ' => 'Y', 'Ή' => 'H', 'Ώ' => 'W', 'Ϊ' => 'I', - 'Ϋ' => 'Y' - ), - 'turkish_map' => array ( - 'ş' => 's', 'Ş' => 'S', 'ı' => 'i', 'İ' => 'I', 'ç' => 'c', 'Ç' => 'C', 'ü' => 'u', 'Ü' => 'U', - 'ö' => 'o', 'Ö' => 'O', 'ğ' => 'g', 'Ğ' => 'G' - ), - 'russian_map' => array ( - 'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd', 'е' => 'e', 'ё' => 'yo', 'ж' => 'zh', - 'з' => 'z', 'и' => 'i', 'й' => 'j', 'к' => 'k', 'л' => 'l', 'м' => 'm', 'н' => 'n', 'о' => 'o', - 'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't', 'у' => 'u', 'ф' => 'f', 'х' => 'h', 'ц' => 'c', - 'ч' => 'ch', 'ш' => 'sh', 'щ' => 'sh', 'ъ' => '', 'ы' => 'y', 'ь' => '', 'э' => 'e', 'ю' => 'yu', - 'я' => 'ya', - 'А' => 'A', 'Б' => 'B', 'В' => 'V', 'Г' => 'G', 'Д' => 'D', 'Е' => 'E', 'Ё' => 'Yo', 'Ж' => 'Zh', - 'З' => 'Z', 'И' => 'I', 'Й' => 'J', 'К' => 'K', 'Л' => 'L', 'М' => 'M', 'Н' => 'N', 'О' => 'O', - 'П' => 'P', 'Р' => 'R', 'С' => 'S', 'Т' => 'T', 'У' => 'U', 'Ф' => 'F', 'Х' => 'H', 'Ц' => 'C', - 'Ч' => 'Ch', 'Ш' => 'Sh', 'Щ' => 'Sh', 'Ъ' => '', 'Ы' => 'Y', 'Ь' => '', 'Э' => 'E', 'Ю' => 'Yu', - 'Я' => 'Ya' - ), - 'ukrainian_map' => array ( - 'Є' => 'Ye', 'І' => 'I', 'Ї' => 'Yi', 'Ґ' => 'G', 'є' => 'ye', 'і' => 'i', 'ї' => 'yi', 'ґ' => 'g' - ), - 'czech_map' => array ( - 'č' => 'c', 'ď' => 'd', 'ě' => 'e', 'ň' => 'n', 'ř' => 'r', 'š' => 's', 'ť' => 't', 'ů' => 'u', - 'ž' => 'z', 'Č' => 'C', 'Ď' => 'D', 'Ě' => 'E', 'Ň' => 'N', 'Ř' => 'R', 'Š' => 'S', 'Ť' => 'T', - 'Ů' => 'U', 'Ž' => 'Z' - ), - 'polish_map' => array ( - 'ą' => 'a', 'ć' => 'c', 'ę' => 'e', 'ł' => 'l', 'ń' => 'n', 'ó' => 'o', 'ś' => 's', 'ź' => 'z', - 'ż' => 'z', 'Ą' => 'A', 'Ć' => 'C', 'Ę' => 'e', 'Ł' => 'L', 'Ń' => 'N', 'Ó' => 'O', 'Ś' => 'S', - 'Ź' => 'Z', 'Ż' => 'Z' - ), - 'latvian_map' => array ( - 'ā' => 'a', 'č' => 'c', 'ē' => 'e', 'ģ' => 'g', 'ī' => 'i', 'ķ' => 'k', 'ļ' => 'l', 'ņ' => 'n', - 'š' => 's', 'ū' => 'u', 'ž' => 'z', 'Ā' => 'A', 'Č' => 'C', 'Ē' => 'E', 'Ģ' => 'G', 'Ī' => 'i', - 'Ķ' => 'k', 'Ļ' => 'L', 'Ņ' => 'N', 'Š' => 'S', 'Ū' => 'u', 'Ž' => 'Z' - ) - ); - - /** - * List of words to remove from URLs. - */ - public static $remove_list = array ( - 'a', 'an', 'as', 'at', 'before', 'but', 'by', 'for', 'from', - 'is', 'in', 'into', 'like', 'of', 'off', 'on', 'onto', 'per', - 'since', 'than', 'the', 'this', 'that', 'to', 'up', 'via', - 'with' - ); - - /** - * The character map. - */ - private static $map = array (); - - /** - * The character list as a string. - */ - private static $chars = ''; - - /** - * The character list as a regular expression. - */ - private static $regex = ''; - - /** - * Initializes the character map. - */ - private static function init () { - if (count (self::$map) > 0) { - return; - } - - foreach (self::$maps as $map) { - foreach ($map as $orig => $conv) { - self::$map[$orig] = $conv; - self::$chars .= $orig; - } - } - - self::$regex = '/[' . self::$chars . ']/u'; - } - - /** - * Add new characters to the list. `$map` should be a hash. - */ - public static function add_chars ($map) { - if (! is_array ($map)) { - throw new LogicException ('$map must be an associative array.'); - } - self::$maps[] = $map; - self::$map = array (); - self::$chars = ''; - } - - /** - * Append words to the remove list. Accepts either single words - * or an array of words. - */ - public static function remove_words ($words) { - $words = is_array ($words) ? $words : array ($words); - self::$remove_list = array_merge (self::$remove_list, $words); - } - - /** - * Transliterates characters to their ASCII equivalents. - */ - public static function downcode ($text) { - self::init (); - - if (preg_match_all (self::$regex, $text, $matches)) { - for ($i = 0; $i < count ($matches[0]); $i++) { - $char = $matches[0][$i]; - if (isset (self::$map[$char])) { - $text = str_replace ($char, self::$map[$char], $text); - } - } - } - return $text; - } - - /** - * Filters a string, e.g., "Petty theft" to "petty-theft" - */ - public static function filter ($text, $length = 60) { - $text = self::downcode ($text); - - // remove all these words from the string before urlifying - $text = preg_replace ('/\b(' . join ('|', self::$remove_list) . ')\b/i', '', $text); - - // if downcode doesn't hit, the char will be stripped here - $text = preg_replace ('/[^-\w\s]/', '', $text); // remove unneeded chars - $text = preg_replace ('/^\s+|\s+$/', '', $text); // trim leading/trailing spaces - $text = preg_replace ('/[-\s]+/', '-', $text); // convert spaces to hyphens - $text = strtolower ($text); // convert to lowercase - return trim (substr ($text, 0, $length), '-'); // trim to first $length chars - } - - /** - * Alias of `URLify::downcode()`. - */ - public static function transliterate ($text) { - return self::downcode ($text); - } -} - -?> \ No newline at end of file diff --git a/library/urlify/composer.json b/library/urlify/composer.json deleted file mode 100644 index 2d95f6aa6..000000000 --- a/library/urlify/composer.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "jbroadway/urlify", - "type": "library", - "description": "PHP port of URLify.js from the Django project. Transliterates non-ascii characters for use in URLs.", - "keywords": ["urlify","transliterate","translit","transliteration","url","encode","slug","link","iconv"], - "homepage": "https://github.com/jbroadway/urlify", - "license": "MIT", - "authors": [ - { - "name": "Johnny Broadway", - "email": "johnny@johnnybroadway.com", - "homepage": "http://www.johnnybroadway.com/" - } - ], - "require": { - "php": ">=5.3.0" - }, - "autoload": { - "psr-0": { "URLify": "" } - } -} diff --git a/library/urlify/tests/URLifyTest.php b/library/urlify/tests/URLifyTest.php deleted file mode 100644 index 26ecb5dea..000000000 --- a/library/urlify/tests/URLifyTest.php +++ /dev/null @@ -1,31 +0,0 @@ -assertEquals (' J\'etudie le francais ', URLify::downcode (' J\'étudie le français ')); - $this->assertEquals ('Lo siento, no hablo espanol.', URLify::downcode ('Lo siento, no hablo español.')); - $this->assertEquals ('F3PWS', URLify::downcode ('ΦΞΠΏΣ')); - } - - function test_filter () { - $this->assertEquals ('jetudie-le-francais', URLify::filter (' J\'étudie le français ')); - $this->assertEquals ('lo-siento-no-hablo-espanol', URLify::filter ('Lo siento, no hablo español.')); - $this->assertEquals ('f3pws', URLify::filter ('ΦΞΠΏΣ')); - } - - function test_add_chars () { - $this->assertEquals ('¿ ® ¼ ¼ ¾ ¶', URLify::downcode ('¿ ® ¼ ¼ ¾ ¶')); - URLify::add_chars (array ( - '¿' => '?', '®' => '(r)', '¼' => '1/4', - '¼' => '1/2', '¾' => '3/4', '¶' => 'P' - )); - $this->assertEquals ('? (r) 1/2 1/2 3/4 P', URLify::downcode ('¿ ® ¼ ¼ ¾ ¶')); - } - - function test_remove_words () { - $this->assertEquals ('foo-bar', URLify::filter ('foo bar')); - URLify::remove_words (array ('foo', 'bar')); - $this->assertEquals ('', URLify::filter ('foo bar')); - } -} - -?> diff --git a/library/urlify/tests/bootstrap.php b/library/urlify/tests/bootstrap.php deleted file mode 100644 index d56d46665..000000000 --- a/library/urlify/tests/bootstrap.php +++ /dev/null @@ -1,9 +0,0 @@ - - - . - - - - - -- cgit v1.2.3