<?php
/*
* Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
- * Copyright (C) 2002-2006 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
* exporting Nucleus skins: SKINIMPORT and SKINEXPORT
*
* @license http://nucleuscms.org/license.txt GNU General Public License
- * @copyright Copyright (C) 2002-2006 The Nucleus Group
- * @version $Id: skinie.php,v 1.5 2006-07-12 07:11:47 kimitake Exp $
- * $NucleusJP: skinie.php,v 1.4 2005/08/13 07:33:02 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 {
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;
);
*/
$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
// 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) {
$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);
}
$clashes = array();
foreach ($this->skins as $skinName => $data) {
- if (SKIN::exists($skinName))
+ if (SKIN::exists($skinName)) {
array_push($clashes, $skinName);
+ }
}
return $clashes;
$clashes = array();
foreach ($this->templates as $templateName => $data) {
- if (TEMPLATE::exists($templateName))
+ if (TEMPLATE::exists($templateName)) {
array_push($clashes, $templateName);
+ }
}
return $clashes;
* Called by XML parser for each new start element encountered
*/
function startElement($parser, $name, $attrs) {
- if ($this->debug) echo 'START: ', $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':
$this->currentPartName = $attrs['name'];
break;
default:
- echo 'UNEXPECTED TAG: ' , $name , '<br />';
+ echo _SKINIE_SEELEMENT_UNEXPECTEDTAG . htmlspecialchars($name, ENT_QUOTES) . '<br />';
break;
}
* Called by the XML parser for each closing tag encountered
*/
function endElement($parser, $name) {
- if ($this->debug) echo 'END: ', $name, '<br />';
+ if ($this->debug) {
+ echo 'END: ' . htmlspecialchars($name, ENT_QUOTES) . '<br />';
+ }
switch ($name) {
case 'nucleusskin':
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) {
}
break;
default:
- echo 'UNEXPECTED TAG: ' , $name, '<br />';
+ echo _SKINIE_SEELEMENT_UNEXPECTEDTAG . htmlspecialchars($name, ENT_QUOTES) . '<br />';
break;
}
$this->clearCharacterData();
* 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;
}
* 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');
+ }
}
/**
* @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);
* @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);
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);
-
- echo "\t", '<skin name="',htmlspecialchars($skinName),'" type="',htmlspecialchars($skinObj->getContentType()),'" includeMode="',htmlspecialchars($skinObj->getIncludeMode()),'" includePrefix="',htmlspecialchars($skinObj->getIncludePrefix()),'">',"\n";
-
- echo "\t\t", '<description>',htmlspecialchars($skinObj->getDescription()),'</description>',"\n";
+ $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);
+ }
- $res = sql_query('SELECT stype, scontent FROM '.sql_table('skin').' WHERE sdesc='.$skinId);
- while ($partObj = mysql_fetch_object($res)) {
- echo "\t\t",'<part name="',htmlspecialchars($partObj->stype),'">';
- echo '<![CDATA[', $this->escapeCDATA($partObj->scontent),']]>';
+ echo "\t" . '<skin name="' . $skinName . '" type="' . $contentT . '" includeMode="' . $incMode . '" includePrefix="' . $incPrefx . '">' . "\n";
+
+ echo "\t\t" . '<description>' . $skinDesc . '</description>' . "\n";
+
+ $que = 'SELECT'
+ . ' stype,'
+ . ' scontent '
+ . 'FROM '
+ . sql_table('skin')
+ . ' WHERE'
+ . ' sdesc = ' . $skinId;
+ $res = sql_query($que);
+ while ($partObj = sql_fetch_object($res)) {
+ $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";
}
// contents templates
foreach ($this->templates as $templateId => $templateName) {
- $templateId = intval($templateId);
-
- echo "\t",'<template name="',htmlspecialchars($templateName),'">',"\n";
-
- echo "\t\t",'<description>',htmlspecialchars(TEMPLATE::getDesc($templateId)),'</description>',"\n";
+ $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);
+ }
- $res = sql_query('SELECT tpartname, tcontent FROM '.sql_table('template').' WHERE tdesc='.$templateId);
- while ($partObj = mysql_fetch_object($res)) {
- echo "\t\t",'<part name="',htmlspecialchars($partObj->tpartname),'">';
- echo '<![CDATA[', $this->escapeCDATA($partObj->tcontent) ,']]>';
- echo '</part>',"\n\n";
+ echo "\t" . '<template name="' . $templateName . '">' . "\n";
+
+ echo "\t\t" . '<description>' . $templateDesc . "</description>\n";
+
+ $que = 'SELECT'
+ . ' tpartname,'
+ . ' tcontent'
+ . ' FROM '
+ . sql_table('template')
+ . ' WHERE'
+ . ' tdesc = ' . $templateId;
+ $res = sql_query($que);
+ while ($partObj = sql_fetch_object($res)) {
+ $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";