예제 #1
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;
 }