| 1 |
<?php
|
| 2 |
|
| 3 |
class Dummy {}
|
| 4 |
|
| 5 |
function utf_encode($string, $direction = "encode")
|
| 6 |
{
|
| 7 |
/*
|
| 8 |
+-------------------------------------------------------------------------+
|
| 9 |
| Copyright (c) 2002-2004 Roman Ivanov |
|
| 10 |
+-------------------------------------------------------------------------+
|
| 11 |
| Author: Roman Ivanov <thingol@mail.ru> |
|
| 12 |
+-------------------------------------------------------------------------+
|
| 13 |
*/
|
| 14 |
|
| 15 |
//òàáëèöû ïåðåêîäèðîâêè äëÿ strtr()
|
| 16 |
|
| 17 |
$tran = array(
|
| 18 |
"%A8"=>"%D0%81", "%B8"=>"%D1%91", "%C0"=>"%D0%90", "%C1"=>"%D0%91", "%C2"=>"%D0%92", "%C3"=>"%D0%93",
|
| 19 |
"%C4"=>"%D0%94", "%C5"=>"%D0%95", "%C6"=>"%D0%96", "%C7"=>"%D0%97", "%C8"=>"%D0%98", "%C9"=>"%D0%99",
|
| 20 |
"%CA"=>"%D0%9A", "%CB"=>"%D0%9B", "%CC"=>"%D0%9C", "%CD"=>"%D0%9D", "%CE"=>"%D0%9E", "%CF"=>"%D0%9F",
|
| 21 |
"%D0"=>"%D0%A0", "%D1"=>"%D0%A1", "%D2"=>"%D0%A2", "%D3"=>"%D0%A3", "%D4"=>"%D0%A4", "%D5"=>"%D0%A5",
|
| 22 |
"%D6"=>"%D0%A6", "%D7"=>"%D0%A7", "%D8"=>"%D0%A8", "%D9"=>"%D0%A9", "%DA"=>"%D0%AA", "%DB"=>"%D0%AB",
|
| 23 |
"%DC"=>"%D0%AC", "%DD"=>"%D0%AD", "%DE"=>"%D0%AE", "%DF"=>"%D0%AF", "%E0"=>"%D0%B0", "%E1"=>"%D0%B1",
|
| 24 |
"%E2"=>"%D0%B2", "%E3"=>"%D0%B3", "%E4"=>"%D0%B4", "%E5"=>"%D0%B5", "%E6"=>"%D0%B6", "%E7"=>"%D0%B7",
|
| 25 |
"%E8"=>"%D0%B8", "%E9"=>"%D0%B9", "%EA"=>"%D0%BA", "%EB"=>"%D0%BB", "%EC"=>"%D0%BC", "%ED"=>"%D0%BD",
|
| 26 |
"%EE"=>"%D0%BE", "%EF"=>"%D0%BF", "%F0"=>"%D1%80", "%F1"=>"%D1%81", "%F2"=>"%D1%82", "%F3"=>"%D1%83",
|
| 27 |
"%F4"=>"%D1%84", "%F5"=>"%D1%85", "%F6"=>"%D1%86", "%F7"=>"%D1%87", "%F8"=>"%D1%88", "%F9"=>"%D1%89",
|
| 28 |
"%FA"=>"%D1%8A", "%FB"=>"%D1%8B", "%FC"=>"%D1%8C", "%FD"=>"%D1%8D", "%FE"=>"%D1%8E", "%FF"=>"%D1%8F",
|
| 29 |
);
|
| 30 |
|
| 31 |
|
| 32 |
$typo = array(
|
| 33 |
"%C2%A7"=>"§",
|
| 34 |
"%C2%A9"=>"©",
|
| 35 |
"%C2%AB"=>"«",
|
| 36 |
"%C2%AE"=>"®",
|
| 37 |
"%C2%B0"=>"°",
|
| 38 |
"%C2%B1"=>"±",
|
| 39 |
"%C2%BB"=>"»",
|
| 40 |
"%E2%80%93"=>"–",
|
| 41 |
"%E2%80%94"=>"—",
|
| 42 |
"%E2%80%9C"=>"“",
|
| 43 |
"%E2%80%9D"=>"”",
|
| 44 |
"%E2%80%9E"=>"„",
|
| 45 |
"%E2%80%A6"=>"…",
|
| 46 |
"%E2%84%96"=>"№",
|
| 47 |
"%E2%84%A2"=>"™",
|
| 48 |
"%C2%A4"=>"¤",
|
| 49 |
"%C2%B6"=>"¶",
|
| 50 |
"%C2%B7"=>"·",
|
| 51 |
"%E2%80%98"=>"‘",
|
| 52 |
"%E2%80%99"=>"’",
|
| 53 |
"%E2%80%A2"=>"•",
|
| 54 |
);
|
| 55 |
|
| 56 |
$rtypo = array(
|
| 57 |
"%84"=>"%E2%80%9E",
|
| 58 |
"%85"=>"%E2%80%A6",
|
| 59 |
"%91"=>"%E2%80%98",
|
| 60 |
"%92"=>"%E2%80%99",
|
| 61 |
"%93"=>"%E2%80%9C",
|
| 62 |
"%94"=>"%E2%80%9D",
|
| 63 |
"%95"=>"%E2%80%A2",
|
| 64 |
"%96"=>"%E2%80%93",
|
| 65 |
"%97"=>"%E2%80%94",
|
| 66 |
"%99"=>"%E2%84%A2",
|
| 67 |
"%A7"=>"%C2%A7",
|
| 68 |
"%A9"=>"%C2%A9",
|
| 69 |
"%AB"=>"%C2%AB",
|
| 70 |
"%AE"=>"%C2%AE",
|
| 71 |
"%B0"=>"%C2%B0",
|
| 72 |
"%B1"=>"%C2%B1",
|
| 73 |
"%BB"=>"%C2%BB",
|
| 74 |
);
|
| 75 |
|
| 76 |
if ($direction == "encode")
|
| 77 |
{
|
| 78 |
$tran = array_merge($tran,$rtypo);
|
| 79 |
$string = strtr(urlencode($string),$tran);
|
| 80 |
}
|
| 81 |
else
|
| 82 |
{
|
| 83 |
$rtran = array_flip($tran);
|
| 84 |
$rtran = array_merge($rtran,$typo);
|
| 85 |
$string = strtr(urlencode($string),$rtran);
|
| 86 |
}
|
| 87 |
return urldecode($string);
|
| 88 |
}
|
| 89 |
|
| 90 |
function typografica_filter($op, $delta = 0, $format = -1, $text = '') {
|
| 91 |
switch ($op) {
|
| 92 |
case 'list':
|
| 93 |
return array(0 => t('Typografica filter'));
|
| 94 |
|
| 95 |
case 'description':
|
| 96 |
return t('Process inputed text so it becomes more corresponding to typografica rules');
|
| 97 |
|
| 98 |
case 'prepare':
|
| 99 |
return $text;
|
| 100 |
|
| 101 |
case "process":
|
| 102 |
require_once("classes/typografica.php");
|
| 103 |
$dummy = new Dummy();
|
| 104 |
$typo = new typografica( &$dummy );
|
| 105 |
|
| 106 |
$text = utf_encode($text, "decode");
|
| 107 |
$text = $typo->correct( $text );
|
| 108 |
$text = utf_encode($text, "encode");
|
| 109 |
|
| 110 |
return $text;
|
| 111 |
default:
|
| 112 |
return $text;
|
| 113 |
}
|
| 114 |
}
|
| 115 |
|
| 116 |
function typografica_help($section) {
|
| 117 |
switch ($section) {
|
| 118 |
case 'admin/modules#description':
|
| 119 |
return t('Adds additional filter for making text corresponding to russian typographic rules.');
|
| 120 |
break;
|
| 121 |
}
|
| 122 |
}
|
| 123 |
|
| 124 |
?>
|