|
| 1 | +<?php |
| 2 | + |
| 3 | +// This is a PLUGIN TEMPLATE. |
| 4 | + |
| 5 | +// Copy this file to a new name like abc_myplugin.php. Edit the code, then |
| 6 | +// run this file at the command line to produce a plugin for distribution: |
| 7 | +// $ php abc_myplugin.php > abc_myplugin-0.1.txt |
| 8 | + |
| 9 | +// Plugin name is optional. If unset, it will be extracted from the current |
| 10 | +// file name. Uncomment and edit this line to override: |
| 11 | +$plugin['name'] = 'wcz_utf8_url'; |
| 12 | + |
| 13 | +$plugin['version'] = '0.1.4'; |
| 14 | +$plugin['author'] = 'whocarez'; |
| 15 | +$plugin['author_uri'] = ''; |
| 16 | +$plugin['description'] = 'Automatic UTF-8 permlinks'; |
| 17 | +$plugin['type'] = 1; // 0 for regular plugin; 1 if it includes admin-side code |
| 18 | +$plugin['order'] = 5; # use 5 as a default; ranges from 1 to 9 |
| 19 | + |
| 20 | + |
| 21 | +@include_once('zem_tpl.php'); |
| 22 | + |
| 23 | +if (0) { |
| 24 | +?> |
| 25 | +# --- BEGIN PLUGIN HELP --- |
| 26 | + |
| 27 | +Just install and activate. |
| 28 | +Adjust Textpattern->Advanced Options->“Maximum URL length (in characters)” to your needs. |
| 29 | + |
| 30 | +# --- END PLUGIN HELP --- |
| 31 | +<?php |
| 32 | +} |
| 33 | + |
| 34 | +# --- BEGIN PLUGIN CODE --- |
| 35 | + |
| 36 | +/* |
| 37 | + wcz_utf8_url - Makes UTF-8 permlinks for SEO |
| 38 | +
|
| 39 | + Written by whocarez with help of the Textpattern Community |
| 40 | +
|
| 41 | + Released under the GNU General Public License 3 |
| 42 | + See: http://www.gnu.org/licenses/gpl.html |
| 43 | +
|
| 44 | + Version history: |
| 45 | + 0.1.4 - minor fix of preserving already existing dashes/minuses |
| 46 | + 0.1.3 - added remove small words |
| 47 | + 0.1.2 - minor fixes with double dashes and trimming the url string |
| 48 | + 0.1.1 - minor fixes |
| 49 | + 0.1.0 - initial release |
| 50 | +
|
| 51 | +*/ |
| 52 | + |
| 53 | +register_callback('wcz_utf8_url','sanitize_for_url'); |
| 54 | +function wcz_utf8_url($event,$step,$text) { |
| 55 | + |
| 56 | +// replace slash and backslash before deleting unneeded signs, you may consider to add some more replacings e.g. € with Euro or евро |
| 57 | + $text = str_replace(array("1+1","$","€","%","/","\\"),array("1plus1"," Dollar"," Euro"," Prozent"," "," "),$text); |
| 58 | +// Remove all unneeded symbols ... |
| 59 | + $text = preg_replace("/[\p{P}\p{No}\p{Nl}\p{M}\p{C}\p{S}]/u","-",$text); |
| 60 | +// Collapse spaces, minuses, (back-)slashes and non-words |
| 61 | + $text = preg_replace('/[\s\-\/\\\\]+/', '-', $text); |
| 62 | +// Trim url string |
| 63 | + $text = trim($text,"-"); |
| 64 | +// Remove small words |
| 65 | +// $text = preg_replace("/(^|-)[\p{Ll}\p{Lu}\p{Lt}\p{Lo}]{1,2}(?=-|$)/u","", $text); |
| 66 | + |
| 67 | +$text = trim(preg_replace("/(^|-)(([\p{Ll}\p{Lu}\p{Lt}\p{Lo}]{1,3})(?<!new|wer|wen|wie|was|wo|wem|how|who|zug|uni|job|gps|bus|tod|tot|eko|öko|eu|dai|gai|hiv|df|ing|ua|upa|oun|omv|otp|ss|umc|twi|tvi|usa|uno|bio|see|kuh|fuß|not|kot|tür|sex|uhu|rat|dvd|cd|tau|rot|tor|tat|bit|sau|ehe|gut|mfg|ard|zdf|rtl|mdr|tee|uhr|zoo|zeh|rss|xml|pdf|axt|fan|nuß|neu|fkk|aal|bug|ost|alt|rom|ddr|fdj|sed|kgb|fbi|cia|sbu|ohr|age|ece|bip|mts|gus|ntn|cme|ntn|iwf|wto|scm|man|uah|eon|nbu|obi|tv|isd|ilo|akw|who|ooo|stb|gas|em))(?=-|$)/ui","", $text),"-"); |
| 68 | +// Remove all non-whitelisted characters |
| 69 | + $text = preg_replace("/[^\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Nd}\-_]/u","",$text); |
| 70 | + $text = trim(mb_strtolower($text),'-'); |
| 71 | + return $text; |
| 72 | +} |
| 73 | + |
| 74 | +function update_urls() { |
| 75 | +$rs = safe_rows('Title','textpattern','1=1'); |
| 76 | +foreach($rs as $a) |
| 77 | +safe_update('textpattern',"url_title='".sanitizeForUrl($a['Title'])."'","Title='".doSlash($a['Title'])."'"); |
| 78 | + |
| 79 | +} |
| 80 | + |
| 81 | +# --- END PLUGIN CODE --- |
| 82 | + |
| 83 | +?> |
0 commit comments