Exemplo n.º 1
0
 function _convertFile($inFile, $code, $charset, $language)
 {
     $oldLines = file($inFile);
     $txt = implode('', $oldLines);
     $txt = str_replace('<', '<', $txt);
     $txt = str_replace('>', '>', $txt);
     $txt = str_replace("’", "'", $txt);
     if ($code == 'de-DE' || $code == 'fr-FR' || $code == 'it-IT') {
         $txt = htmlentities(utf8_decode($txt));
     } else {
         $converter = new JCommentsUtf8($charset);
         $txt = $converter->utf8ToStr($txt);
     }
     $txt = str_replace('&lt;', '<', $txt);
     $txt = str_replace('&gt;', '>', $txt);
     $txt = str_replace('&quot;', '"', $txt);
     $txt = str_replace('&amp;quot;', '&quot;', $txt);
     $txt = str_replace('&amp;gt;', '&gt;', $txt);
     $txt = str_replace('&amp;lt;', '&lt;', $txt);
     $txt = str_replace('Note : All ini files need to be saved as UTF-8 - No BOM', 'Note: this file need to be saved in ' . $charset . ' charset', $txt);
     $inFile = str_replace($code . '.com_jcomments.ini', $language . '.ini', $inFile);
     $fp = fopen($inFile, "w");
     if ($fp) {
         fputs($fp, $txt);
         fclose($fp);
     }
 }
Exemplo n.º 2
0
 function convertEncoding($value)
 {
     $iso = explode('=', _ISO);
     $charset = strtolower($iso[1]);
     if ($charset != 'utf-8' && is_file(JCOMMENTS_LIBRARIES . DS . 'convert' . DS . 'maps' . DS . $charset)) {
         if (!defined('CONVERT_TABLES_DIR')) {
             require_once JCOMMENTS_LIBRARIES . DS . 'convert' . DS . 'utf8.class.php';
         }
         $encoding =& JCommentsUtf8::getInstance($charset);
         $needEntities = false;
         if (is_array($value)) {
             $newArray = array();
             foreach ($value as $k => $v) {
                 if (is_array($v)) {
                     $newArray[$k] = JCommentsAJAX::convertEncoding($v);
                 } else {
                     if ($v != '') {
                         if ($needEntities === true) {
                             $newArray[$k] = $encoding->utf8_to_entities($v);
                         } else {
                             $newArray[$k] = JCommentsText::isUTF8($v) ? $encoding->utf8ToStr($v) : $v;
                             if ($encoding->encodingFailed($newArray[$k])) {
                                 $newArray[$k] = $encoding->utf8_to_entities($v);
                                 $needEntities = true;
                             }
                         }
                     }
                 }
             }
             return $newArray;
         } else {
             if ($value != '') {
                 $text = $value;
                 if (JCommentsText::isUTF8($value)) {
                     $text = $encoding->utf8ToStr($value);
                     if ($encoding->encodingFailed($text)) {
                         $text = $encoding->utf8_to_entities($value);
                     }
                 }
                 return $text;
             }
         }
     }
     return $value;
 }
    function importJomComment($source, $language)
    {
        $db =& JCommentsFactory::getDBO();
        $query = "SELECT c.*" . "\n, u.email as user_email, u.name as user_name, u.username as user_username " . "\nFROM #__jomcomment AS c" . "\nLEFT JOIN #__users AS u ON c.user_id = u.id";
        $db->setQuery($query);
        $rows = $db->loadObjectList();
        $iso = explode('=', _ISO);
        $charset = strtolower((string) $iso[1]);
        if ($charset != 'utf-8') {
            $entity_replace = create_function('$string', '
				$num = substr($string, 0, 1) === \'x\' ? hexdec(substr($string, 1)) : (int) $string;
				return $num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) ? \'\' : ($num < 0x80 ? \'&#\' . $num . \';\' : ($num < 0x800 ? chr(192 | $num >> 6) . chr(128 | $num & 63) : ($num < 0x10000 ? chr(224 | $num >> 12) . chr(128 | $num >> 6 & 63) . chr(128 | $num & 63) : chr(240 | $num >> 18) . chr(128 | $num >> 12 & 63) . chr(128 | $num >> 6 & 63) . chr(128 | $num & 63))));');
            require_once JCOMMENTS_BASE . DS . 'libraries' . DS . 'convert' . DS . 'utf8.class.php';
            $encoding =& JCommentsUtf8::getInstance($charset);
        }
        foreach ($rows as $row) {
            if ($charset != 'utf-8') {
                $row->comment = preg_replace('~(&#(\\d{1,7}|x[0-9a-fA-F]{1,6});)~e', '$entity_replace(\'\\2\')', $row->comment);
                $row->comment = $encoding->utf8ToStr($row->comment);
                $row->name = preg_replace('~(&#(\\d{1,7}|x[0-9a-fA-F]{1,6});)~e', '$entity_replace(\'\\2\')', $row->name);
                $row->name = $encoding->utf8ToStr($row->name);
                $row->username = preg_replace('~(&#(\\d{1,7}|x[0-9a-fA-F]{1,6});)~e', '$entity_replace(\'\\2\')', $row->username);
                $row->username = $encoding->utf8ToStr($row->username);
                $row->title = preg_replace('~(&#(\\d{1,7}|x[0-9a-fA-F]{1,6});)~e', '$entity_replace(\'\\2\')', $row->title);
                $row->title = $encoding->utf8ToStr($row->title);
            }
            $comment = new JCommentsImportedComment($db);
            $comment->object_id = $row->contentid;
            $comment->object_group = isset($row->option) && $row->option != '' ? $row->option : 'com_content';
            $comment->userid = $row->user_id;
            $comment->name = $row->user_name ? $row->user_name : $row->name;
            $comment->username = $row->user_username ? $row->user_username : $row->name;
            $comment->email = $row->user_email ? $row->user_email : $row->email;
            $comment->homepage = $row->website;
            $comment->title = $row->title;
            $comment->comment = $row->comment;
            $comment->ip = $row->ip;
            $comment->published = $row->published;
            $comment->date = $row->date;
            $comment->source = $source;
            $comment->lang = $language;
            $comment->store();
        }
    }