Exemplo n.º 1
0
 /**
  * Decodes/Transcodes a string according to the selected charset, and the charset of the blog
  *
  * @access public
  * @param  string   input string to convert
  * @return string   converted string
  */
 function &decode($string)
 {
     // xml_parser_* functions do recoding from ISO-8859-1/UTF-8
     if (!$this->force_recode && (LANG_CHARSET == 'ISO-8859-1' || LANG_CHARSET == 'UTF-8')) {
         return $string;
     }
     $target = $this->data['charset'];
     switch ($target) {
         case 'native':
             return $string;
         case 'ISO-8859-1':
             if (function_exists('iconv')) {
                 $out = iconv('ISO-8859-1', LANG_CHARSET, $string);
             } elseif (function_exists('recode')) {
                 $out = recode('iso-8859-1..' . LANG_CHARSET, $string);
             } elseif (LANG_CHARSET == 'UTF-8') {
                 return utf8_encode($string);
             } else {
                 return $string;
             }
             return $out;
         case 'UTF-8':
         default:
             $out = utf8_decode($string);
             return $out;
     }
 }
Exemplo n.º 2
0
 private function array_recode($fromto, $input)
 {
     if (!is_array($input)) {
         $uns = @unserialize($input);
         if (is_array($uns)) {
             $uns = $this->array_recode($fromto, $uns);
             return serialize($uns);
         } else {
             $tmp = @json_encode($input);
             $e = json_last_error();
             if ($e) {
                 $fix = recode($fromto, $input);
                 // error_log("UTF8 fix from [$input] to [$fix]");
                 return $fix;
             } else {
                 return $input;
             }
         }
     } else {
         foreach ($input as $i => $v) {
             $input[$i] = $this->array_recode($fromto, $v);
         }
         return $input;
     }
 }
 function &decode($string)
 {
     $target = $this->get_config('charset', 'native');
     // xml_parser_* functions to recoding from ISO-8859-1/UTF-8
     if (LANG_CHARSET == 'ISO-8859-1' || LANG_CHARSET == 'UTF-8') {
         return $string;
     }
     switch ($target) {
         case 'native':
             return $string;
         case 'ISO-8859-1':
             if (function_exists('iconv')) {
                 $out = iconv('ISO-8859-1', LANG_CHARSET, $string);
             } elseif (function_exists('recode')) {
                 $out = recode('iso-8859-1..' . LANG_CHARSET, $string);
             } else {
                 return $string;
             }
             return $out;
         case 'UTF-8':
         default:
             $out = utf8_decode($string);
             return $out;
     }
 }
 function decode($charset, &$array)
 {
     if (LANG_CHARSET == 'ISO-8859-1' || LANG_CHARSET == 'UTF-8') {
         // Luckily PHP5 supports
         // xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, LANG_CHARSET);
         // which means we need no transcoding here.
         return true;
     }
     if ($charset == LANG_CHARSET) {
         return true;
     } elseif ($charset == 'utf-8') {
         foreach ($array as $key => $val) {
             $array[$key] = utf8_decode($val);
         }
     } elseif ($charset == 'iso-8859-1') {
         foreach ($array as $key => $val) {
             if (function_exists('iconv')) {
                 $array[$key] = iconv('ISO-8859-1', LANG_CHARSET, $val);
             } elseif (function_exists('recode')) {
                 $array[$key] = recode('iso-8859-1..' . LANG_CHARSET, $val);
             }
         }
     }
     return true;
 }
Exemplo n.º 5
0
function decode(&$data, $force = true) {

    if ($force === false && (CHARSET == 'ISO-8859-15' || CHARSET == 'UTF-8')) {
        return $data;
    }

    switch (strtolower(CHARSET)) {
       case 'utf-8':
          // The file is UTF-8 format. No changes needed.
          break;

       case 'iso-8859-15':
          $data = utf8_decode($data);
          break;

       default:
           if (function_exists('iconv')) {
             $data = iconv('UTF-8', CHARSET, $data);
           } elseif (function_exists('recode')) {
             $data = recode('utf-8..' . CHARSET, $data);
           }
           break;
      }

     return $data;
}
Exemplo n.º 6
0
            $c = $iCal->factory('Event', $ea);
            $cal->addEvent($c);
        }
        $iCal->addCalendar($cal);
        $iCal->sendHeader("calendar");
        $calendar_str = $iCal->__toString();
        header("Content-Length: " . strlen($calendar_str));
        header("Expires: 0");
        // These two lines fix pb with IE and HTTPS
        header("Cache-Control: private");
        header("Pragma: dummy=bogus");
        // Outlook needs iso8859 encoding
        header("Content-Type:text/calendar; method=REQUEST; charset=iso-8859-15");
        header("Content-Transfer-Encoding:quoted-printable");
        $re_encode = stripos($_SERVER['HTTP_USER_AGENT'], 'windows');
        // only re-encode to ISO-8859-15 if client on Windows
        if (function_exists('recode') && $re_encode !== false) {
            print recode('utf-8..iso8859-15', $calendar_str);
        } elseif (function_exists('iconv') && $re_encode !== false) {
            print iconv("UTF-8", "ISO-8859-15", $calendar_str);
        } else {
            print $calendar_str;
            // UTF-8 is good for other platforms
        }
    }
    die;
}
$smarty->assign('iCal', $iCal);
// Display the template
$smarty->assign('mid', 'tiki-calendar_export_ical.tpl');
$smarty->display("tiki.tpl");
Exemplo n.º 7
0
function get_station($statid)
{
    //return;
    $stationname = get_station_name($statid);
    $stationnameorig = urlencode(recode("UTF8..windows-1250", $stationname));
    $stationurl = "http://vred.hznet.hr/hzinfo/Default.asp?KO={$stationnameorig}&Category=hzinfo&Service=izvr3&LANG=HR&SCREEN=2";
    $html = file_get_dom($stationurl);
    //$html = file_get_dom('http://vred.hznet.hr/hzinfo/Default.asp?KO=Zagreb+Gl.+Kol.&Category=hzinfo&Service=izvr3&LANG=HR&SCREEN=2&SESSIONID=%3Csessionid%3E');
    //$statid = get_station_id($stationname);
    //if ($statid == -1) return;
    foreach ($html->find('td') as $element) {
        $foundin = 0;
        foreach ($element->find("a") as $innerel) {
            //echo trim($innerel->innertext)."\n";
            // commit previous work here
            if ($vlaknr) {
                if ($vlakiz) {
                    $vlakiz = get_station_id($vlakiz);
                } else {
                    $vlakiz = 0;
                }
                if ($vlakza) {
                    $vlakza = get_station_id($vlakza);
                } else {
                    $vlakza = 0;
                }
                $vlakdolstr = "'{$vlakdol}'";
                if ($vlakdol == '') {
                    $vlakdolstr = "NULL";
                }
                $vlakodlstr = "'{$vlakodl}'";
                if ($vlakodl == '') {
                    $vlakodlstr = "NULL";
                }
                $sun = 1;
                $sat = 1;
                $vlaknaphandled = 0;
                // blah, this is tiresome
                if ($vlaknap == "") {
                    $vlaknaphandled = 1;
                }
                if ($vlaknap == "Ne vozi nedjeljom i blagdanom") {
                    $sun = 0;
                    $vlaknaphandled = 1;
                }
                if ($vlaknap == "Ne vozi subotom") {
                    $sat = 0;
                    $vlaknaphandled = 1;
                }
                if ($vlaknap == "Vozi nedjeljom") {
                    $vlaknaphandled = 1;
                }
                if ($vlaknap == "Vozi nedjeljom i blagdanom") {
                    $vlaknaphandled = 1;
                }
                if ($vlaknap == "Vozi subotom, nedjeljom i blagdanom") {
                    $vlaknaphandled = 1;
                }
                if ($vlaknap == "Ne vozi subotom, nedjeljom i blagdanom") {
                    $sat = 0;
                    $sun = 0;
                    $vlaknaphandled = 1;
                }
                //$pos = strpos("Ne vozi subotom, nedjeljom i blagdanom", $vlaknap);
                //if ($pos > 0)
                $sql = "INSERT INTO StationMovables values('{$statid}','{$vlaknr}',{$vlakdolstr}, {$vlakodlstr}, '{$vlakiz}' ,'{$vlakza}','{$vlaknap}','{$sun}','{$sat}','{$vlaknaphandled}');";
                echo $sql . "\n";
                pg_query($sql);
            }
            $vlaknr = trim($innerel->innertext);
            $foundin = 1;
            $col = 0;
        }
        if (!$foundin) {
            $txt = trim($element->innertext);
            $txt = str_ireplace("<BR>", "", $txt);
            switch ($col) {
                case 0:
                    $vlakdol = $txt;
                    break;
                case 1:
                    $vlakodl = $txt;
                    break;
                case 6:
                    $vlakiz = recode("windows1250..UTF-8", $txt);
                    break;
                case 7:
                    $vlakza = recode("windows1250..UTF-8", $txt);
                    break;
                case 8:
                    $vlaknap = recode("windows1250..UTF-8", $txt);
                    break;
            }
            $col++;
        }
    }
    if ($vlaknr) {
        if ($vlakiz) {
            $vlakiz = get_station_id($vlakiz);
        } else {
            $vlakiz = 0;
        }
        if ($vlakza) {
            $vlakza = get_station_id($vlakza);
        } else {
            $vlakza = 0;
        }
        $vlakdolstr = "'{$vlakdol}'";
        if ($vlakdol == '') {
            $vlakdolstr = "NULL";
        }
        $vlakodlstr = "'{$vlakodl}'";
        if ($vlakodl == '') {
            $vlakodlstr = "NULL";
        }
        $sql = "INSERT INTO StationMovables values('{$statid}','{$vlaknr}',{$vlakdolstr}, {$vlakodlstr}, '{$vlakiz}' ,'{$vlakza}','{$vlaknap}');";
        echo $sql . "\n";
        pg_query($sql);
    }
    $html->clear;
    unset($html);
}
 function decode($string)
 {
     switch ($this->get_config('charset', 'native')) {
         case 'native':
             return $string;
         case 'ISO-8859-1':
             if (function_exists('iconv')) {
                 return iconv('ISO-8859-1', LANG_CHARSET, $string);
             } elseif (function_exists('recode')) {
                 return recode('iso-8859-1..' . LANG_CHARSET, $string);
             } else {
                 return $string;
             }
         case 'UTF-8':
         default:
             return utf8_decode($string);
     }
 }
 function decode(&$data, $force = false)
 {
     // xml_parser_* functions to recoding from ISO-8859-1/UTF-8
     if ($force === false && (LANG_CHARSET == 'ISO-8859-1' || LANG_CHARSET == 'UTF-8')) {
         return true;
     }
     switch (strtolower(LANG_CHARSET)) {
         case 'utf-8':
             // The XML file is UTF-8 format. No changes needed.
             break;
         case 'iso-8859-1':
             $data = utf8_decode($data);
             break;
         default:
             if (function_exists('iconv')) {
                 $data = iconv('UTF-8', LANG_CHARSET, $data);
             } elseif (function_exists('recode')) {
                 $data = recode('utf-8..' . LANG_CHARSET, $data);
             }
             break;
     }
 }
Exemplo n.º 10
0
Arquivo: Utils.php Projeto: erebot/api
 /**
  * Transforms the given text into a UTF-8 sequence.
  *
  * \param string $text
  *      The text to convert into a UTF-8 sequence.
  *
  * \param null|string $from
  *      (optional) The encoding currently used by $text.
  *      A default of "iso-8859-1" is assumed.
  *
  * \retval string
  *      The original text, converted into UTF-8.
  *
  * \throw Erebot::NotImplementedException
  *      Raised if no method could be found to convert
  *      the text. See also the notes for information on
  *      how to avoid this exception being raised.
  *
  * \note
  *      This method tries different technics to convert
  *      the text. If despite its best efforts, it still
  *      fails, you may consider installing one of PHP's
  *      extension for "Human Language and Character
  *      Encoding Support".
  */
 public static function toUTF8($text, $from = 'iso-8859-1')
 {
     $alreadyEncoded = self::isUTF8($text);
     // Special value so that double-encoded text can be decoded.
     if ($from == '__double') {
         if ($alreadyEncoded) {
             // If no decoding function is available, we'll just
             // return the double-encoded text as-is.
             // This is better than throwing an exception anyway.
             $res = $text;
             if (function_exists('utf8_decode')) {
                 $res = utf8_decode($text);
             } elseif (function_exists('iconv')) {
                 $res = iconv('utf-8', 'iso-8859-1//TRANSLIT', $text);
             } elseif (function_exists('recode')) {
                 $res = recode('utf-8..iso-8859-1', $text);
             } elseif (function_exists('mb_convert_encoding')) {
                 $res = mb_convert_encoding($text, 'iso-8859-1', 'utf-8');
             } elseif (function_exists('html_entity_decode')) {
                 $res = html_entity_decode(htmlentities($text, ENT_QUOTES, 'utf-8'), ENT_QUOTES, 'iso-8850-1');
             }
             // So, was it really double-encoded?
             return self::isUTF8($res) ? $res : $text;
         }
         // Someone tried to foul us, but we'll foul them instead.
         // Here we blindly assume the text is in ISO-8859-1.
         $from = 'iso-8859-1';
     }
     if ($alreadyEncoded) {
         return $text;
     }
     if (!strcasecmp($from, 'iso-8859-1') && function_exists('utf8_encode')) {
         return utf8_encode($text);
     }
     if (function_exists('iconv')) {
         return iconv($from, 'UTF-8//TRANSLIT', $text);
     }
     if (function_exists('recode')) {
         return recode($from . '..utf-8', $text);
     }
     if (function_exists('mb_convert_encoding')) {
         return mb_convert_encoding($text, 'UTF-8', $from);
     }
     if (function_exists('html_entity_decode')) {
         return html_entity_decode(htmlentities($text, ENT_QUOTES, $from), ENT_QUOTES, 'UTF-8');
     }
     throw new \Erebot\NotImplementedException('No way to convert to UTF-8');
 }