Skip to content

Commit 71ae4b9

Browse files
committed
directory
1 parent 53a1456 commit 71ae4b9

File tree

4 files changed

+247
-0
lines changed

4 files changed

+247
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Unicode-url-for-Textpattern
2+
===========================
3+
4+
Plugin for using unicode urls instead of transliterations to ASCII characters
5+
6+
wcz_utf8_url – uses UTF-8 permlinks instead of transliterated ones for SEO
7+
8+
Features
9+
10+
automatically handles non ASCII characters
11+
integrated function for updating all of your existing titles – use on your OWN risk —> <txp:update_urls />
12+
works with German, Russian, Ukrainian (on live sites)
13+
tested with Japanese
14+
15+
16+
Tested with:
17+
18+
Textpattern 4.4.0+, MySQL 5.1.49, PHP 5.3.3 (Debian Squeeze)
19+
20+
21+
22+
To do
23+
24+
make list of “small words” a parameter
25+
26+
Feedback
27+
28+
Comments are most welcome.

wcz_utf8_url-0.1.4.txt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# wcz_utf8_url v0.1.4
2+
# Automatic UTF-8 permlinks
3+
# whocarez
4+
#
5+
6+
# ......................................................................
7+
# This is a plugin for Textpattern - http://textpattern.com/
8+
# To install: textpattern > admin > plugins
9+
# Paste the following text into the 'Install plugin' box:
10+
# ......................................................................
11+
12+
YToxMDp7czo0OiJuYW1lIjtzOjEyOiJ3Y3pfdXRmOF91cmwiO3M6NzoidmVyc2lvbiI7czo1
13+
OiIwLjEuNCI7czo2OiJhdXRob3IiO3M6ODoid2hvY2FyZXoiO3M6MTA6ImF1dGhvcl91cmki
14+
O3M6MDoiIjtzOjExOiJkZXNjcmlwdGlvbiI7czoyNToiQXV0b21hdGljIFVURi04IHBlcm1s
15+
aW5rcyI7czo0OiJ0eXBlIjtpOjE7czo1OiJvcmRlciI7aTo1O3M6NDoiaGVscCI7czoxMjI6
16+
IgpKdXN0IGluc3RhbGwgYW5kIGFjdGl2YXRlLgpBZGp1c3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M6MzoibWQ1IjtzOjMyOiJlZDg2Y2ZlYzhlNmZlNDhi
59+
ZWQ5YmNhNWRlNjQ0MDBmNyI7fQ==

wcz_utf8_url.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
?>

zem_tpl.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
// Either copy classTextile.php to your plugin directory, or uncomment the following
4+
// line and edit it to give the location where classTextile.php can be found
5+
#ini_set('include_path', ini_get('include_path') . ':/full/path/to/textile');
6+
7+
if (empty($test)) {
8+
echo compile_plugin();
9+
exit;
10+
}
11+
12+
// -----------------------------------------------------
13+
14+
function extract_section($lines, $section) {
15+
$result = "";
16+
17+
$start_delim = "# --- BEGIN PLUGIN $section ---";
18+
$end_delim = "# --- END PLUGIN $section ---";
19+
20+
$start = array_search($start_delim, $lines) + 1;
21+
$end = array_search($end_delim, $lines);
22+
23+
$content = array_slice($lines, $start, $end-$start);
24+
25+
return join("\n", $content);
26+
27+
}
28+
29+
function compile_plugin($file='') {
30+
global $plugin;
31+
32+
if (empty($file))
33+
$file = $_SERVER['SCRIPT_FILENAME'];
34+
35+
if (!isset($plugin['name'])) {
36+
$plugin['name'] = basename($file, '.php');
37+
}
38+
39+
# Read the contents of this file, and strip line ends
40+
$content = file($file);
41+
for ($i=0; $i < count($content); $i++) {
42+
$content[$i] = rtrim($content[$i]);
43+
}
44+
45+
$plugin['help'] = extract_section($content, 'HELP');
46+
$plugin['code'] = extract_section($content, 'CODE');
47+
48+
@include('classTextile.php');
49+
if (class_exists('Textile')) {
50+
$textile = new Textile();
51+
$plugin['help'] = $textile->TextileThis($plugin['help']);
52+
}
53+
54+
$plugin['md5'] = md5( $plugin['code'] );
55+
56+
// to produce a copy of the plugin for distribution, load this file in a browser.
57+
58+
header('Content-type: text/plain');
59+
$header = <<<EOF
60+
# {$plugin['name']} v{$plugin['version']}
61+
# {$plugin['description']}
62+
# {$plugin['author']}
63+
# {$plugin['author_uri']}
64+
65+
# ......................................................................
66+
# This is a plugin for Textpattern - http://textpattern.com/
67+
# To install: textpattern > admin > plugins
68+
# Paste the following text into the 'Install plugin' box:
69+
# ......................................................................
70+
EOF;
71+
72+
return $header . "\n\n" . trim(chunk_split(base64_encode(serialize($plugin)), 72)). "\n";
73+
74+
}
75+
76+
77+
?>

0 commit comments

Comments
 (0)