OSDN Git Service

Fix importing skin error in detecting charactor encoding, refering to http://japan...
authorsakamocchi <sakamocchi@1ca29b6e-896d-4ea0-84a5-967f57386b96>
Wed, 19 Jan 2011 08:43:47 +0000 (08:43 +0000)
committersakamocchi <sakamocchi@1ca29b6e-896d-4ea0-84a5-967f57386b96>
Wed, 19 Jan 2011 08:43:47 +0000 (08:43 +0000)
git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/nucleus-jp/trunk@1094 1ca29b6e-896d-4ea0-84a5-967f57386b96

utf8/nucleus/libs/skinie.php

index 99c15cb..454fe22 100755 (executable)
@@ -1,7 +1,7 @@
 <?php
 /*
  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
- * Copyright (C) 2002-2010 The Nucleus Group
+ * Copyright (C) 2002-2011 The Nucleus Group
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -14,7 +14,7 @@
  *     exporting Nucleus skins: SKINIMPORT and SKINEXPORT
  *
  * @license http://nucleuscms.org/license.txt GNU General Public License
- * @copyright Copyright (C) 2002-2010 The Nucleus Group
+ * @copyright Copyright (C) 2002-2011 The Nucleus Group
  * @version $Id$
  * @version $NucleusJP: skinie.php,v 1.9.2.1 2007/09/05 07:46:30 kimitake Exp $
  */
@@ -103,36 +103,32 @@ class SKINIMPORT {
 
        }
 
-       /**
-        * Reads an XML file into memory
-        *
-        * @param $filename
-        *              Which file to read
-        * @param $metaOnly
-        *              Set to 1 when only the metadata needs to be read (optional, default 0)
-        */
+/**
+ * Reads an XML file into memory
+ * 
+ * @param $filename
+ *     Which file to read
+ * @param $metaOnly
+ *     Set to 1 when only the metadata needs to be read (optional, default 0)
+ * 
+ * [2004/08/04]        Modified by Japanese Package Release Team according to the URL below,
+ *                                     http://japan.nucleuscms.org/bb/viewtopic.php?t=4416
+ * [2004/08/04]        Modified by dakarma
+ *                                     Took this out since it messes up good XML if it has skins/templates
+ *                                     with CDATA sections. need to investigate consequences.
+ *                                     see bug [ 999914 ] Import fails (multiple skins in XML/one of them with CDATA)
+ */
        function readFile($filename, $metaOnly = 0) {
                // open file
                $this->fp = @fopen($filename, 'r');
                if (!$this->fp) {
                        return _SKINIE_ERROR_FAILEDOPEN_FILEURL;
                }
-
-               // here we go!
+               
                $this->inXml = 1;
-
-               $tempbuffer = null;
-
-               while (!feof($this->fp)) {
-                       $tempbuffer .= fread($this->fp, 4096);
-               }
-               fclose($this->fp);
-
+               $tempbuffer = fread($this->fp,filesize($filename));
 /*
-       [2004-08-04] dekarma - Took this out since it messes up good XML if it has skins/templates
-                                                  with CDATA sections. need to investigate consequences.
-                                                  see bug [ 999914 ] Import fails (multiple skins in XML/one of them with CDATA)
-
+               dakarma wrote
                // backwards compatibility with the non-wellformed skinbackup.xml files
                // generated by v2/v3 (when CDATA sections were present in skins)
                // split up those CDATA sections into multiple ones
@@ -145,31 +141,27 @@ class SKINIMPORT {
                        $tempbuffer
                );
 */
-               $temp = tmpfile();
-//             fwrite($temp, $tempbuffer);
-               if (!function_exists('mb_convert_encoding')) {
-                       fwrite($temp, $tempbuffer);
+               // JP Team wrote
+               if (function_exists('mb_convert_encoding') && (strtoupper(_CHARSET) != 'ISO-8859-1')) {
+                       mb_detect_order("ASCII, EUC-JP, UTF-8, JIS, SJIS, EUC-CN, ISO-8859-1");
+                       $temp_encode = mb_detect_encoding($tempbuffer);
                } else {
-                       if (strtoupper(_CHARSET) == 'ISO-8859-1') {
-                               fwrite($temp, $tempbuffer);
-                       } else {
-                               mb_detect_order("ASCII, JIS, SJIS, UTF-8, EUC-JP, ISO-8859-1");
-                               $temp_encode = mb_detect_encoding($tempbuffer);
-                               fwrite($temp, mb_convert_encoding($tempbuffer, 'UTF-8', $temp_encode));
-                       }
+                       $temp_encode = null;
                }
-               rewind($temp);
-
-               while ( ($buffer = fread($temp, 4096) ) && (!$metaOnly || ($metaOnly && !$this->metaDataRead))) {
-                       $err = xml_parse( $this->parser, $buffer, feof($temp) );
+               rewind($this->fp);
+               
+               while ( ($buffer = fgets($this->fp, 4096) ) && (!$metaOnly || ($metaOnly && !$this->metaDataRead))) {
+                       if ($temp_encode) {
+                               $buffer = mb_convert_encoding($buffer, 'UTF-8', $temp_encode);
+                       }
+                       $err = xml_parse( $this->parser, $buffer, feof($this->fp) );
                        if (!$err && $this->debug) {
                                echo _ERROR . ': ' . xml_error_string(xml_get_error_code($this->parser)) . '<br />';
                        }
                }
-
-               // all done
+               
                $this->inXml = 0;
-               fclose($temp);
+               fclose($this->fp);
        }
 
        /**