OSDN Git Service

EUCのインストールファイル削除
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / libs / skinie.php
index 1f62bc5..825f23c 100755 (executable)
@@ -1,7 +1,7 @@
 <?php
 /*
  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
- * Copyright (C) 2002-2007 The Nucleus Group
+ * Copyright (C) 2002-2009 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,9 +14,9 @@
  *     exporting Nucleus skins: SKINIMPORT and SKINEXPORT
  *
  * @license http://nucleuscms.org/license.txt GNU General Public License
- * @copyright Copyright (C) 2002-2007 The Nucleus Group
- * @version $Id: skinie.php,v 1.8 2007-03-22 03:30:14 kmorimatsu Exp $
- * @version $NucleusJP: skinie.php,v 1.7 2007/02/04 06:28:46 kimitake Exp $
+ * @copyright Copyright (C) 2002-2009 The Nucleus Group
+ * @version $Id$
+ * @version $NucleusJP: skinie.php,v 1.9.2.1 2007/09/05 07:46:30 kimitake Exp $
  */
 
 class SKINIMPORT {
@@ -114,7 +114,9 @@ class SKINIMPORT {
        function readFile($filename, $metaOnly = 0) {
                // open file
                $this->fp = @fopen($filename, 'r');
-               if (!$this->fp) return 'Failed to open file/URL';
+               if (!$this->fp) {
+                       return _SKINIE_ERROR_FAILEDOPEN_FILEURL;
+               }
 
                // here we go!
                $this->inXml = 1;
@@ -144,13 +146,25 @@ class SKINIMPORT {
                );
 */
                $temp = tmpfile();
-               fwrite($temp, $tempbuffer);
+//             fwrite($temp, $tempbuffer);
+               if (!function_exists('mb_convert_encoding')) {
+                       fwrite($temp, $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));
+                       }
+               }
                rewind($temp);
 
                while ( ($buffer = fread($temp, 4096) ) && (!$metaOnly || ($metaOnly && !$this->metaDataRead))) {
                        $err = xml_parse( $this->parser, $buffer, feof($temp) );
-                       if (!$err && $this->debug)
-                               echo 'ERROR: ', xml_error_string(xml_get_error_code($this->parser)), '<br />';
+                       if (!$err && $this->debug) {
+                               echo _ERROR . ': ' . xml_error_string(xml_get_error_code($this->parser)) . '<br />';
+                       }
                }
 
                // all done
@@ -192,8 +206,9 @@ class SKINIMPORT {
 
                // if not allowed to overwrite, check if any nameclashes exists
                if (!$allowOverwrite) {
-                       if ((sizeof($existingSkins) > 0) || (sizeof($existingTemplates) > 0))
-                               return 'Name clashes detected, re-run with allowOverwrite = 1 to force overwrite';
+                       if ((sizeof($existingSkins) > 0) || (sizeof($existingTemplates) > 0)) {
+                               return _SKINIE_NAME_CLASHES_DETECTED;
+                       }
                }
 
                foreach ($this->skins as $skinName => $data) {
@@ -206,9 +221,21 @@ class SKINIMPORT {
                                $skinObj->deleteAllParts();
 
                                // update general info
-                               $skinObj->updateGeneralInfo($skinName, $data['description'], $data['type'], $data['includeMode'], $data['includePrefix']);
+                               $skinObj->updateGeneralInfo(
+                                       $skinName,
+                                       $data['description'],
+                                       $data['type'],
+                                       $data['includeMode'],
+                                       $data['includePrefix']
+                               );
                        } else {
-                               $skinid = SKIN::createNew($skinName, $data['description'], $data['type'], $data['includeMode'], $data['includePrefix']);
+                               $skinid = SKIN::createNew(
+                                       $skinName,
+                                       $data['description'],
+                                       $data['type'],
+                                       $data['includeMode'],
+                                       $data['includePrefix']
+                               );
                                $skinObj = new SKIN($skinid);
                        }
 
@@ -250,8 +277,9 @@ class SKINIMPORT {
                $clashes = array();
 
                foreach ($this->skins as $skinName => $data) {
-                       if (SKIN::exists($skinName))
+                       if (SKIN::exists($skinName)) {
                                array_push($clashes, $skinName);
+                       }
                }
 
                return $clashes;
@@ -265,8 +293,9 @@ class SKINIMPORT {
                $clashes = array();
 
                foreach ($this->templates as $templateName => $data) {
-                       if (TEMPLATE::exists($templateName))
+                       if (TEMPLATE::exists($templateName)) {
                                array_push($clashes, $templateName);
+                       }
                }
 
                return $clashes;
@@ -276,7 +305,13 @@ class SKINIMPORT {
         * Called by XML parser for each new start element encountered
         */
        function startElement($parser, $name, $attrs) {
-               if ($this->debug) echo 'START: ', htmlspecialchars($name), '<br />';
+               foreach($attrs as $key=>$value) {
+                       $attrs[$key] = htmlspecialchars($value, ENT_QUOTES);
+               }
+
+               if ($this->debug) {
+                       echo 'START: ' . htmlspecialchars($name, ENT_QUOTES) . '<br />';
+               }
 
                switch ($name) {
                        case 'nucleusskin':
@@ -318,7 +353,7 @@ class SKINIMPORT {
                                $this->currentPartName = $attrs['name'];
                                break;
                        default:
-                               echo 'UNEXPECTED TAG: ' , htmlspecialchars($name) , '<br />';
+                               echo _SKINIE_SEELEMENT_UNEXPECTEDTAG . htmlspecialchars($name, ENT_QUOTES) . '<br />';
                                break;
                }
 
@@ -331,7 +366,9 @@ class SKINIMPORT {
          * Called by the XML parser for each closing tag encountered
          */
        function endElement($parser, $name) {
-               if ($this->debug) echo 'END: ', htmlspecialchars($name), '<br />';
+               if ($this->debug) {
+                       echo 'END: ' . htmlspecialchars($name, ENT_QUOTES) . '<br />';
+               }
 
                switch ($name) {
                        case 'nucleusskin':
@@ -345,10 +382,14 @@ class SKINIMPORT {
                        case 'info':
                                $this->info = $this->getCharacterData();
                        case 'skin':
-                               if (!$this->inMeta) $this->inSkin = 0;
+                               if (!$this->inMeta) {
+                                       $this->inSkin = 0;
+                               }
                                break;
                        case 'template':
-                               if (!$this->inMeta) $this->inTemplate = 0;
+                               if (!$this->inMeta) {
+                                       $this->inTemplate = 0;
+                               }
                                break;
                        case 'description':
                                if ($this->inSkin) {
@@ -365,7 +406,7 @@ class SKINIMPORT {
                                }
                                break;
                        default:
-                               echo 'UNEXPECTED TAG: ' , htmlspecialchars($name), '<br />';
+                               echo _SKINIE_SEELEMENT_UNEXPECTEDTAG . htmlspecialchars($name, ENT_QUOTES) . '<br />';
                                break;
                }
                $this->clearCharacterData();
@@ -376,7 +417,9 @@ class SKINIMPORT {
         * Called by XML parser for data inside elements
         */
        function characterData ($parser, $data) {
-               if ($this->debug) echo 'NEW DATA: ', htmlspecialchars($data), '<br />';
+               if ($this->debug) {
+                       echo 'NEW DATA: ' . htmlspecialchars($data, ENT_QUOTES) . '<br />';
+               }
                $this->cdata .= $data;
        }
 
@@ -384,7 +427,14 @@ class SKINIMPORT {
         * Returns the data collected so far
         */
        function getCharacterData() {
-               return $this->cdata;
+//             echo $this->cdata;
+               if ( (strtoupper(_CHARSET) == 'UTF-8')
+                       or (strtoupper(_CHARSET) == 'ISO-8859-1')
+                       or (!function_exists('mb_convert_encoding')) ) {
+                       return $this->cdata;
+               } else {
+                       return mb_convert_encoding($this->cdata, _CHARSET ,'UTF-8');
+               }
        }
 
        /**
@@ -453,7 +503,10 @@ class SKINEXPORT {
         * @result false when no such ID exists
         */
        function addTemplate($id) {
-               if (!TEMPLATE::existsID($id)) return 0;
+               if (!TEMPLATE::existsID($id)) {
+                       return 0;
+               }
+
 
                $this->templates[$id] = TEMPLATE::getNameFromId($id);
 
@@ -468,7 +521,9 @@ class SKINEXPORT {
         * @result false when no such ID exists
         */
        function addSkin($id) {
-               if (!SKIN::existsID($id)) return 0;
+               if (!SKIN::existsID($id)) {
+                       return 0;
+               }
 
                $this->skins[$id] = SKIN::getNameFromId($id);
 
@@ -506,30 +561,69 @@ class SKINEXPORT {
                echo "\t<meta>\n";
                        // skins
                        foreach ($this->skins as $skinId => $skinName) {
-                               echo "\t\t", '<skin name="',htmlspecialchars($skinName),'" />',"\n";
+                               $skinName = htmlspecialchars($skinName, ENT_QUOTES);
+                               if (_CHARSET != 'UTF-8') {
+                                       $skinName = mb_convert_encoding($skinName, 'UTF-8', _CHARSET);
+                               }
+                               echo "\t\t" . '<skin name="' . $skinName . '" />' . "\n";
                        }
                        // templates
                        foreach ($this->templates as $templateId => $templateName) {
-                               echo "\t\t", '<template name="',htmlspecialchars($templateName),'" />',"\n";
+                               $templateName = htmlspecialchars($templateName, ENT_QUOTES);
+                               if (_CHARSET != 'UTF-8') {
+                                       $templateName = mb_convert_encoding($templateName, 'UTF-8', _CHARSET);
+                               }
+                               echo "\t\t" . '<template name="' . $templateName . '" />' . "\n";
                        }
                        // extra info
-                       if ($this->info)
-                               echo "\t\t<info><![CDATA[",$this->info,"]]></info>\n";
+                       if ($this->info) {
+                               if (_CHARSET != 'UTF-8') {
+                                       $skin_info = mb_convert_encoding($this->info, 'UTF-8', _CHARSET);
+                               } else {
+                                       $skin_info = $this->info;
+                               }
+                               echo "\t\t<info><![CDATA[" . $skin_info . "]]></info>\n";
+                       }
                echo "\t</meta>\n\n\n";
 
                // contents skins
                foreach ($this->skins as $skinId => $skinName) {
-                       $skinId = intval($skinId);
-                       $skinObj = new SKIN($skinId);
+                       $skinId   = intval($skinId);
+                       $skinObj  = new SKIN($skinId);
+                       $skinName = htmlspecialchars($skinName, ENT_QUOTES);
+                       $contentT = htmlspecialchars($skinObj->getContentType(), ENT_QUOTES);
+                       $incMode  = htmlspecialchars($skinObj->getIncludeMode(), ENT_QUOTES);
+                       $incPrefx = htmlspecialchars($skinObj->getIncludePrefix(), ENT_QUOTES);
+                       $skinDesc = htmlspecialchars($skinObj->getDescription(), ENT_QUOTES);
+                       if (_CHARSET != 'UTF-8') {
+                               $skinName = mb_convert_encoding($skinName, 'UTF-8', _CHARSET);
+                               $contentT = mb_convert_encoding($contentT, 'UTF-8', _CHARSET);
+                               $incMode  = mb_convert_encoding($incMode,  'UTF-8', _CHARSET);
+                               $incPrefx = mb_convert_encoding($incPrefx, 'UTF-8', _CHARSET);
+                               $skinDesc = mb_convert_encoding($skinDesc, 'UTF-8', _CHARSET);
+                       }
 
-                       echo "\t", '<skin name="',htmlspecialchars($skinName),'" type="',htmlspecialchars($skinObj->getContentType()),'" includeMode="',htmlspecialchars($skinObj->getIncludeMode()),'" includePrefix="',htmlspecialchars($skinObj->getIncludePrefix()),'">',"\n";
+                       echo "\t" . '<skin name="' . $skinName . '" type="' . $contentT . '" includeMode="' . $incMode . '" includePrefix="' . $incPrefx . '">' . "\n";
 
-                       echo "\t\t", '<description>',htmlspecialchars($skinObj->getDescription()),'</description>',"\n";
+                       echo "\t\t" . '<description>' . $skinDesc . '</description>' . "\n";
 
-                       $res = sql_query('SELECT stype, scontent FROM '.sql_table('skin').' WHERE sdesc='.$skinId);
+                       $que = 'SELECT'
+                                . '    stype,'
+                                . '    scontent '
+                                . 'FROM '
+                                .      sql_table('skin')
+                                . ' WHERE'
+                                . '    sdesc = ' . $skinId;
+                       $res = sql_query($que);
                        while ($partObj = mysql_fetch_object($res)) {
-                               echo "\t\t",'<part name="',htmlspecialchars($partObj->stype),'">';
-                               echo '<![CDATA[', $this->escapeCDATA($partObj->scontent),']]>';
+                               $type  = htmlspecialchars($partObj->stype, ENT_QUOTES);
+                               $cdata = $this->escapeCDATA($partObj->scontent);
+                               if (_CHARSET != 'UTF-8') {
+                                       $type  = mb_convert_encoding($type,  'UTF-8', _CHARSET);
+                                       $cdata = mb_convert_encoding($cdata, 'UTF-8', _CHARSET);
+                               }
+                               echo "\t\t" . '<part name="' . $type . '">';
+                               echo '<![CDATA[' . $cdata . ']]>';
                                echo "</part>\n\n";
                        }
 
@@ -538,17 +632,36 @@ class SKINEXPORT {
 
                // contents templates
                foreach ($this->templates as $templateId => $templateName) {
-                       $templateId = intval($templateId);
+                       $templateId   = intval($templateId);
+                       $templateName = htmlspecialchars($templateName, ENT_QUOTES);
+                       $templateDesc = htmlspecialchars(TEMPLATE::getDesc($templateId), ENT_QUOTES);
+                       if (_CHARSET != 'UTF-8') {
+                               $templateName = mb_convert_encoding($templateName, 'UTF-8', _CHARSET);
+                               $templateDesc = mb_convert_encoding($templateDesc, 'UTF-8', _CHARSET);
+                       }
 
-                       echo "\t",'<template name="',htmlspecialchars($templateName),'">',"\n";
+                       echo "\t" . '<template name="' . $templateName . '">' . "\n";
 
-                       echo "\t\t",'<description>',htmlspecialchars(TEMPLATE::getDesc($templateId)),'</description>',"\n";
+                       echo "\t\t" . '<description>' . $templateDesc . "</description>\n";
 
-                       $res = sql_query('SELECT tpartname, tcontent FROM '.sql_table('template').' WHERE tdesc='.$templateId);
+                       $que =  'SELECT'
+                                .     ' tpartname,'
+                                .     ' tcontent'
+                                . ' FROM '
+                                .     sql_table('template')
+                                . ' WHERE'
+                                .     ' tdesc = ' . $templateId;
+                       $res = sql_query($que);
                        while ($partObj = mysql_fetch_object($res)) {
-                               echo "\t\t",'<part name="',htmlspecialchars($partObj->tpartname),'">';
-                               echo '<![CDATA[', $this->escapeCDATA($partObj->tcontent) ,']]>';
-                               echo '</part>',"\n\n";
+                               $type  = htmlspecialchars($partObj->tpartname, ENT_QUOTES);
+                               $cdata = $this->escapeCDATA($partObj->tcontent);
+                               if (_CHARSET != 'UTF-8') {
+                                       $type  = mb_convert_encoding($type,  'UTF-8', _CHARSET);
+                                       $cdata = mb_convert_encoding($cdata, 'UTF-8', _CHARSET);
+                               }
+                               echo "\t\t" . '<part name="' . $type . '">';
+                               echo '<![CDATA[' .  $cdata . ']]>';
+                               echo '</part>' . "\n\n";
                        }
 
                        echo "\t</template>\n\n\n";