gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r584 - i18nHTML/src


From: grothoff
Subject: [GNUnet-SVN] r584 - i18nHTML/src
Date: Sun, 3 Apr 2005 19:54:57 -0700 (PDT)

Author: grothoff
Date: 2005-04-03 19:54:54 -0700 (Sun, 03 Apr 2005)
New Revision: 584

Modified:
   i18nHTML/src/commitTranslation.php
   i18nHTML/src/i18nhtml.inc
   i18nHTML/src/translate.php
   i18nHTML/src/vote.php
Log:
bugfixes

Modified: i18nHTML/src/commitTranslation.php
===================================================================
--- i18nHTML/src/commitTranslation.php  2005-04-04 02:02:32 UTC (rev 583)
+++ i18nHTML/src/commitTranslation.php  2005-04-04 02:54:54 UTC (rev 584)
@@ -18,7 +18,7 @@
      Boston, MA 02111-1307, USA.
 */
 include("i18nhtml.inc");
-$text = $_REQUEST['text'];
+$text = mysql_real_escape_string($_REQUEST['text']);
 $translation = $_REQUEST['translation'];
 $back = $_REQUEST['back'];
 if (!$connection) {
@@ -47,7 +47,9 @@
   generateFooter();
   echo "</body></html>";
 } else {
-  if (array_count_values($text)['%'] != array_count_values($t)['%']) {
+  $txtCnt = count_chars($text, 1);
+  $tCnt = count_chars($text, 1);
+  if ($txtCnt['%'] != $tCnt['%']) {
       echo "<html><head>";
       TITLE("Commit failed.");
       echo "</head><body>";
@@ -55,7 +57,7 @@
       W("The number of percent signs in source text and translation do not 
match.");     
       W("Note that you must preserve all %%s expressions unchanged.");
       W("Also, a single displayed %% sign must be translated into two (%%%%) 
such signs.");
-      echo "</body></html>"
+      echo "</body></html>";
   } else {
     $query = "INSERT INTO map VALUES(\"$text\", \"$lang\", \"$t\", 1, \"" . 
$_SERVER['REMOTE_ADDR'] . "\");";
     $result = mysql_query($query, $connection);

Modified: i18nHTML/src/i18nhtml.inc
===================================================================
--- i18nHTML/src/i18nhtml.inc   2005-04-04 02:02:32 UTC (rev 583)
+++ i18nHTML/src/i18nhtml.inc   2005-04-04 02:54:54 UTC (rev 584)
@@ -305,7 +305,299 @@
   return $text;
 }
 
+
 /**
+ * transcode unicode entities to/from HTML entities
+ *
+ * Also, this function transforms HTML entities into their equivalent Unicode 
entities.
+ * For example, w.bloggar posts pages using HTML entities.
+ * If you have to modify these pages using web forms, you would like to get 
UTF-8 instead.
+ *
+ * @link 
http://www.evolt.org/article/A_Simple_Character_Entity_Chart/17/21234/ A Simple 
Character Entity Chart
+ *
+ * @param string the string to be transcoded
+ * @param boolean TRUE to transcode to Unicode, FALSE to transcode to HTML
+ * @return a transcoded string
+ */
+function transcode($input, $to_unicode=TRUE) {
+  
+  // initialize tables only once
+  static $html_entities, $unicode_entities;
+  if(!is_array($html_entities)) {
+    
+    
+    // numerical order
+    $codes = array(
+                  '&#160;'     => '&nbsp;',    // non-breaking space
+                  '&#161;'     => '&iexcl;',   // inverted exclamation mark
+                  '&#162;'     => '&cent;',    // cent sign
+                  '&#163;'     => '&pound;',   // pound sign
+                  '&#164;'     => '&curren;',  // currency sign
+                  '&#165;'     => '&yen;',             // yen sign
+                  '&#166;'     => '&brvbar;',  // broken bar
+                  '&#167;'     => '&sect;',    // section sign
+                  '&#168;'     => '&uml;',             // diaeresis
+                  '&#169;'     => '&copy;',    // copyright sign
+                  '&#170;'     => '&ordf;',    // feminine ordinal indicator
+                  '&#171;'     => '&laquo;',   // left-pointing double angle 
quotation mark
+                  '&#172;'     => '&not;',             // not sign
+                  '&#173;'     => '&shy;',             // soft hyphen
+                  '&#174;'     => '&reg;',             // registered sign
+                  '&#175;'     => '&macr;',    // macron
+                  '&#176;'     => '&deg;',             // degree sign
+                  '&#177;'     => '&plusmn;',  // plus-minus sign
+                  '&#178;'     => '&sup2;',    // superscript two
+                  '&#179;'     => '&sup3;',    // superscript three
+                  '&#180;'     => '&acute;',   // acute accent
+                  '&#181;'     => '&micro;',   // micro sign
+                  '&#182;'     => '&para;',    // pilcrow sign
+                  '&#183;'     => '&middot;',  // middle dot
+                  '&#184;'     => '&cedil;',   // cedilla
+                  '&#185;'     => '&sup1;',    // superscript one
+                  '&#186;'     => '&ordm;',    // masculine ordinal indicator
+                  '&#187;'     => '&raquo;',   // right-pointing double angle 
quotation mark
+                  '&#188;'     => '&frac14;',  // vulgar fraction one quarter
+                  '&#189;'     => '&frac12;',  // vulgar fraction one half
+                  '&#190;'     => '&frac34;',  // vulgar fraction three 
quarters
+                  '&#191;'     => '&iquest;',  // inverted question mark
+                  '&#192;'     => '&Agrave;',  // latin capital letter A with 
grave
+                  '&#193;'     => '&Aacute;',  // latin capital letter A with 
acute
+                  '&#194;'     => '&Acirc;',   // latin capital letter A with 
circumflex
+                  '&#195;'     => '&Atilde;',  // latin capital letter A with 
tilde
+                  '&#196;'     => '&Auml;',    // latin capital letter A with 
diaeresis
+                  '&#197;'     => '&Aring;',   // latin capital letter A with 
ring above
+                  '&#198;'     => '&AElig;',   // latin capital letter AE
+                  '&#199;'     => '&Ccedil;',  // latin capital letter C with 
cedilla
+                  '&#200;'     => '&Egrave;',  // latin capital letter E with 
grave
+                  '&#201;'     => '&Eacute;',  // latin capital letter E with 
acute
+                  '&#202;'     => '&Ecirc;',   // latin capital letter E with 
circumflex
+                  '&#203;'     => '&Euml;',    // latin capital letter E with 
diaeresis
+                  '&#204;'     => '&Igrave;',  // latin capital letter I with 
grave
+                  '&#205;'     => '&Iacute;',  // latin capital letter I with 
acute
+                  '&#206;'     => '&Icirc;',   // latin capital letter I with 
circumflex
+                  '&#207;'     => '&Iuml;',    // latin capital letter I with 
diaeresis
+                  '&#208;'     => '&ETH;',             // latin capital letter 
ETH
+                  '&#209;'     => '&Ntilde;',  // latin capital letter N with 
tilde
+                  '&#210;'     => '&Ograve;',  // latin capital letter O with 
grave
+                  '&#211;'     => '&Oacute;',  // latin capital letter O with 
acute
+                  '&#212;'     => '&Ocirc;',   // latin capital letter O with 
circumflex
+                  '&#213;'     => '&Otilde;',  // latin capital letter O with 
tilde
+                  '&#214;'     => '&Ouml;',    // latin capital letter O with 
diaeresis
+                  '&#215;'     => '&times;',   // multiplication sign
+                  '&#216;'     => '&Oslash;',  // latin capital letter O with 
stroke
+                  '&#217;'     => '&Ugrave;',  // latin capital letter U with 
grave
+                  '&#218;'     => '&Uacute;',  // latin capital letter U with 
acute
+                  '&#219;'     => '&Ucirc;',   // latin capital letter U with 
circumflex
+                  '&#220;'     => '&Uuml;',    // latin capital letter U with 
diaeresis
+                  '&#221;'     => '&Yacute;',  // latin capital letter Y with 
acute
+                  '&#222;'     => '&THORN;',   // latin capital letter THORN
+                  '&#223;'     => '&szlig;',   // latin small letter sharp s
+                  '&#224;'     => '&agrave;',  // latin small letter a with 
grave
+                  '&#225;'     => '&aacute;',  // latin small letter a with 
acute
+                  '&#226;'     => '&acirc;',   // latin small letter a with 
circumflex
+                  '&#227;'     => '&atilde;',  // latin small letter a with 
tilde
+                  '&#228;'     => '&auml;',    // latin small letter a with 
diaeresis
+                  '&#229;'     => '&aring;',   // latin small letter a with 
ring above
+                  '&#230;'     => '&aelig;',   // latin small letter ae
+                  '&#231;'     => '&ccedil;',  // latin small letter c with 
cedilla
+                  '&#232;'     => '&egrave;',  // latin small letter e with 
grave
+                  '&#233;'     => '&eacute;',  // latin small letter e with 
acute
+                  '&#234;'     => '&ecirc;',   // latin small letter e with 
circumflex
+                  '&#235;'     => '&euml;',    // latin small letter e with 
diaeresis
+                  '&#236;'     => '&igrave;',  // latin small letter i with 
grave
+                  '&#237;'     => '&iacute;',  // latin small letter i with 
acute
+                  '&#238;'     => '&icirc;',   // latin small letter i with 
circumflex
+                  '&#239;'     => '&iuml;',    // latin small letter i with 
diaeresis
+                  '&#240;'     => '&eth;',             // latin small letter 
eth
+                  '&#241;'     => '&ntilde;',  // latin small letter n with 
tilde
+                  '&#242;'     => '&ograve;',  // latin small letter o with 
grave
+                  '&#243;'     => '&oacute;',  // latin small letter o with 
acute
+                  '&#244;'     => '&ocirc;',   // latin small letter o with 
circumflex
+                  '&#245;'     => '&otilde;',  // latin small letter o with 
tilde
+                  '&#246;'     => '&ouml;',    // latin small letter o with 
diaeresis
+                  '&#247;'     => '&divide;',  // division sign
+                  '&#248;'     => '&oslash;',  // latin small letter o with 
stroke
+                  '&#249;'     => '&ugrave;',  // latin small letter u with 
grave
+                  '&#250;'     => '&uacute;',  // latin small letter u with 
acute
+                  '&#251;'     => '&ucirc;',   // latin small letter u with 
circumflex
+                  '&#252;'     => '&uuml;',    // latin small letter u with 
diaeresis
+                  '&#253;'     => '&yacute;',  // latin small letter y with 
acute
+                  '&#254;'     => '&thorn;',   // latin small letter thorn
+                  '&#255;'     => '&yuml;',    //
+                  '&#338;'     => '&OElig;',   // latin capital ligature OE
+                  '&#339;'     => '&oelig;',   // latin small ligature oe
+                  '&#352;'     => '&Scaron;',  // latin capital letter S with 
caron
+                  '&#353;'     => '&scaron;',  // latin small letter s with 
caron
+                  '&#376;'     => '&Yuml;',    // latin capital letter Y with 
diaeresis
+                  '&#402;'     => '&fnof;' ,   // latin small f with hook
+                  '&#710;'     => '&circ;',    // modifier letter circumflex 
accent
+                  '&#732;'     => '&tilde;',   // small tilde
+                  '&#913;'     => '&Alpha;',   // greek capital letter alpha
+                  '&#914;'     => '&Beta;',    // greek capital letter beta
+                  '&#915;'     => '&Gamma;',   // greek capital letter gamma
+                  '&#916;'     => '&Delta;',   // greek capital letter delta
+                  '&#917;'     => '&Epsilon;', // greek capital letter epsilon
+                  '&#918;'     => '&Zeta;',    // greek capital letter zeta
+                  '&#919;'     => '&Eta;',             // greek capital letter 
eta
+                  '&#920;'     => '&Theta;',   // greek capital letter theta
+                  '&#921;'     => '&Iota;',    // greek capital letter iota
+                  '&#922;'     => '&Kappa;',   // greek capital letter kappa
+                  '&#923;'     => '&Lambda;',  // greek capital letter lambda
+                  '&#924;'     => '&Mu;',              // greek capital letter 
mu
+                  '&#925;'     => '&Nu;',              // greek capital letter 
nu
+                  '&#926;'     => '&Xi;',              // greek capital letter 
xi
+                  '&#927;'     => '&Omicron;', // greek capital letter omicron
+                  '&#928;'     => '&Pi;',              // greek capital letter 
pi
+                  '&#929;'     => '&Rho;',             // greek capital letter 
rho
+                  '&#931;'     => '&Sigma;',   // greek capital letter sigma
+                  '&#932;'     => '&Tau;',             // greek capital letter 
tau
+                  '&#933;'     => '&Upsilon;', // greek capital letter upsilon
+                  '&#934;'     => '&Phi;',             // greek capital letter 
phi
+                  '&#935;'     => '&Chi;',             // greek capital letter 
chi
+                  '&#936;'     => '&Psi;',             // greek capital letter 
psi
+                  '&#937;'     => '&Omega;',   // greek capital letter omega
+                  '&#945;'     => '&alpha;',   // greek small letter alpha
+                  '&#946;'     => '&beta;',    // greek small letter beta
+                  '&#947;'     => '&gamma;',   // greek small letter gamma
+                  '&#948;'     => '&delta;',   // greek small letter delta
+                  '&#949;'     => '&epsilon;', // greek small letter epsilon
+                  '&#950;'     => '&zeta;',    // greek small letter zeta
+                  '&#951;'     => '&eta;',             // greek small letter 
eta
+                  '&#952;'     => '&theta;',   // greek small letter theta
+                  '&#953;'     => '&iota;',    // greek small letter iota
+                  '&#954;'     => '&kappa;',   // greek small letter kappa
+                  '&#955;'     => '&lambda;',  // greek small letter lambda
+                  '&#956;'     => '&mu;',              // greek small letter mu
+                  '&#957;'     => '&nu;',              // greek small letter nu
+                  '&#958;'     => '&xi;',              // greek small letter xi
+                  '&#959;'     => '&omicron;', // greek small letter omicron
+                  '&#960;'     => '&pi;',              // greek small letter pi
+                  '&#961;'     => '&rho;',             // greek small letter 
rho
+                  '&#962;'     => '&sigmaf;',  // greek small letter final 
sigma
+                  '&#963;'     => '&sigma;',   // greek small letter sigma
+                  '&#964;'     => '&tau;',             // greek small letter 
tau
+                  '&#965;'     => '&upsilon;', // greek small letter upsilon
+                  '&#966;'     => '&phi;',             // greek small letter 
phi
+                  '&#967;'     => '&chi;',             // greek small letter 
chi
+                  '&#968;'     => '&psi;',             // greek small letter 
psi
+                  '&#969;'     => '&omega;',   // greek small letter omega
+                  '&#977;'     => '&thetasym;',        // greek small letter 
theta symbol
+                  '&#978;'     => '&upsih;',   // greek upsilon with hook 
symbol
+                  '&#982;'     => '&piv;',             // greek pi symbol
+                  '&#8194;'    => '&ensp;',    // en space
+                  '&#8195;'    => '&emsp;',    // em space
+                  '&#8201;'    => '&thinsp;',  // thin space
+                  '&#8204;'    => '&zwnj;',    // zero width non-joiner
+                  '&#8205;'    => '&zwj;',             // zero width joiner
+                  '&#8206;'    => '&lrm;',             // left-to-right mark
+                  '&#8207;'    => '&rlm;',             // right-to-left mark
+                  '&#8211;'    => '&ndash;',   // en dash
+                  '&#8212;'    => '&mdash;',   // em dash
+                  '&#8216;'    => '&lsquo;',   // left single quotation mark
+                  '&#8217;'    => '&rsquo;',   // right single quotation mark
+                  '&#8218;'    => '&sbquo;',   // single low-9 quotation mark
+                  '&#8220;'    => '&ldquo;',   // left double quotation mark
+                  '&#8221;'    => '&rdquo;',   // right double quotation mark
+                  '&#8222;'    => '&bdquo;',   // double low-9 quotation mark
+                  '&#8224;'    => '&dagger;',  // dagger
+                  '&#8225;'    => '&Dagger;',  // double dagger
+                  '&#8226;'    => '&bull;',    // bullet
+                  '&#8230;'    => '&hellip;',  // horizontal ellipsis
+                  '&#8240;'    => '&permil;',  // per mille sign
+                  '&#8242;'    => '&prime;',   // primeminutes
+                  '&#8243;'    => '&Prime;',   // double prime
+                  '&#8249;'    => '&lsaquo;',  // single left-pointing angle 
quotation mark
+                  '&#8250;'    => '&rsaquo;',  // single right-pointing angle 
quotation mark
+                  '&#8254;'    => '&oline;',   // overline
+                  '&#8260;'    => '&frasl;',   // fraction slash
+                  '&#8364;'    => '&euro;',    // euro sign
+                  '&#8465;'    => '&image;',   // blackletter capital I
+                  '&#8472;'    => '&weierp;',  // script capital P
+                  '&#8476;'    => '&real;',    // blackletter capital R
+                  '&#8482;'    => '&trade;',   // trade mark sign
+                  '&#8501;'    => '&alefsym;', // alef symbol
+                  '&#8592;'    => '&larr;',    // leftwards arrow
+                  '&#8593;'    => '&uarr;',    // upwards arrow
+                  '&#8594;'    => '&rarr;',    // rightwards arrow
+                  '&#8595;'    => '&darr;',    // downwards arrow
+                  '&#8596;'    => '&harr;',    // left right arrow
+                  '&#8629;'    => '&crarr;',   // downwards arrow with corner 
leftwards
+                  '&#8656;'    => '&lArr;',    // leftwards double arrow
+                  '&#8657;'    => '&uArr;',    // upwards double arrow
+                  '&#8658;'    => '&rArr;',    // rightwards double arrow
+                  '&#8659;'    => '&dArr;',    // downwards double arrow
+                  '&#8660;'    => '&hArr;',    // left right double arrow
+                  '&#8704;'    => '&forall;',  // for all
+                  '&#8706;'    => '&part;',    // partial differential
+                  '&#8707;'    => '&exist;',   // there exists
+                  '&#8709;'    => '&empty;',   // empty set
+                  '&#8711;'    => '&nabla;',   // nabla
+                  '&#8712;'    => '&isin;',    // element of
+                  '&#8713;'    => '&notin;',   // not an element of
+                  '&#8715;'    => '&ni;',              // contains as member
+                  '&#8719;'    => '&prod;',    // n-ary product
+                  '&#8721;'    => '&sum;',             // n-ary sumation
+                  '&#8722;'    => '&minus;',   // minus sign
+                  '&#8727;'    => '&lowast;',  // asterisk operator
+                  '&#8730;'    => '&radic;',   // square root
+                  '&#8733;'    => '&prop;',    // proportional to
+                  '&#8734;'    => '&infin;',   // infinity
+                  '&#8736;'    => '&ang;',             // angle
+                  '&#8743;'    => '&and;',             // logical and
+                  '&#8744;'    => '&or;',              // logical or
+                  '&#8745;'    => '&cap;',             // intersection
+                  '&#8746;'    => '&cup;',             // union
+                  '&#8747;'    => '&int;',             // integral
+                  '&#8756;'    => '&there4;',  // therefore
+                  '&#8764;'    => '&sim;',             // tilde operator
+                  '&#8773;'    => '&cong;',    // approximately equal to
+                  '&#8776;'    => '&asymp;',   // almost equal to
+                  '&#8800;'    => '&ne;',              // not equal to
+                  '&#8801;'    => '&equiv;',   // identical to
+                  '&#8804;'    => '&le;',              // less-than or equal to
+                  '&#8805;'    => '&ge;',              // greater-than or 
equal to
+                  '&#8834;'    => '&sub;',             // subset of
+                  '&#8835;'    => '&sup;',             // superset of
+                  '&#8836;'    => '&nsub;',    // not a subset of
+                  '&#8838;'    => '&sube;',    // subset of or equal to
+                  '&#8839;'    => '&supe;',    // superset of or equal to
+                  '&#8853;'    => '&oplus;',   // circled plus
+                  '&#8855;'    => '&otimes;',  // circled times
+                  '&#8869;'    => '&perp;',    // up tack
+                  '&#8901;'    => '&sdot;',    // dot operator
+                  '&#8968;'    => '&lceil;',   // left ceiling
+                  '&#8969;'    => '&rceil;',   // right ceiling
+                  '&#8970;'    => '&lfloor;',  // left floor
+                  '&#8971;'    => '&rfloor;',  // right floor
+                  '&#9001;'    => '&lang;',    // left-pointing angle bracket
+                  '&#9002;'    => '&rang;',    // right-pointing angle bracket
+                  '&#9674;'    => '&loz;',             // lozenge
+                  '&#9824;'    => '&spades;',  // black spade suit
+                  '&#9827;'    => '&clubs;',   // black club suit
+                  '&#9829;'    => '&hearts;',  // black heart suit
+                  '&#9830;'    => '&diams;'    // black diam suit
+                  );
+    
+    // split entities for use in str_replace()
+    foreach($codes as  $unicode_entity => $html_entity) {
+      $unicode_entities[] = $unicode_entity;
+      $html_entities[] = $html_entity;
+    }
+  }
+  
+  // transcode HTML entities to Unicode
+  if($to_unicode)
+    return str_replace($html_entities, $unicode_entities, $input);
+  
+  // transcode Unicode entities to HTML entities
+  else
+    return str_replace($unicode_entities, $html_entities, $input);
+}
+
+
+
+
+/**
  * transcode multi-byte characters to HTML representations for Unicode
  *
  * This function is aiming to preserve Unicode characters through storage in a 
ISO-8859-1 compliant system.
@@ -329,7 +621,7 @@
 function to_unicode($input) {
   
   // transcode HTML entities to Unicode entities
-  $input = utf8::transcode($input);
+  $input = transcode($input);
   
   // scan the whole string
   $output = '';
@@ -533,7 +825,7 @@
   global $lang;
   global $languagecodes;
   echo "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" 
>";
-  echo "<title>" . W_($a,$b) . "</title>\n";
+  echo "<title>" . TRANSLATE_($a,$b) . "</title>\n";
   if (isset($languagecodes[$lang])) {
     echo "<meta name=\"content-language\" content=\"" . 
          $languagecodes[$lang] . "\">";

Modified: i18nHTML/src/translate.php
===================================================================
--- i18nHTML/src/translate.php  2005-04-04 02:02:32 UTC (rev 583)
+++ i18nHTML/src/translate.php  2005-04-04 02:54:54 UTC (rev 584)
@@ -43,7 +43,7 @@
 W("Destination language: ");
 W($lang);
 P();
-echo "<form method="POST" action=\"" . $i18nHTMLbase . 
"commitTranslation.php\">\n";
+echo "<form method=\"POST\" action=\"" . $i18nHTMLbase . 
"commitTranslation.php\">\n";
 echo "<input type=hidden name=\"text\" value=\"" . urlencode($text) . "\">\n";
 echo "<input type=hidden name=\"xlang\" value=\"$xlang\">\n";
 echo "<input type=hidden name=\"back\" value=\"$back\">\n";

Modified: i18nHTML/src/vote.php
===================================================================
--- i18nHTML/src/vote.php       2005-04-04 02:02:32 UTC (rev 583)
+++ i18nHTML/src/vote.php       2005-04-04 02:54:54 UTC (rev 584)
@@ -31,8 +31,8 @@
  } 
 $text = $_REQUEST['text'];
 $translation = $_REQUEST['translation'];
-$u = urlencode($text);
-$t = urlencode($translation);
+$u = mysql_real_escape_string($text);
+$t = mysql_real_escape_string(to_unicode($translation));
 echo "text = " . $text . "<br>\n";
 echo "translation = " . $translation . "<br>\n";
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]