【php开源代码栏目提醒】:网学会员为需要php开源代码的朋友们搜集整理了skinie.php相关资料,希望对各位网友有所帮助!
<?php
/*
* Nucleus:
PHP/MySQL Weblog CMS (http://nucleuscms.org/)
* Copyright (C) 2002-2005 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
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* (see nucleus/documentation/index.html#license for more info)
*/
/**
* This class contains two classes that can be used for importing and
* exporting Nucleus skins: SKINIMPORT and SKINEXPORT
*
* @license http://nucleuscms.org/license.txt GNU General Public License
* @copyright Copyright (C) 2002-2005 The Nucleus Group
* @version $Id: skinie.php 760 2005-08-15 10:51:09Z dekarma $
*/
class SKINIMPORT {
// hardcoded value (see constructor). When 1, interesting info about the
// parsing process is sent to the output
var $debug;
// parser/file pointer
var $parser;
var $fp;
// which data has been read?
var $metaDataRead;
var $allRead;
// extracted data
var $skins;
var $templates;
var $info;
// to maintain track of where we are inside the XML file
var $inXml;
var $inData;
var $inMeta;
var $inSkin;
var $inTemplate;
var $currentName;
var $currentPartName;
var $cdata;
/**
* constructor initializes data structures
*/
function SKINIMPORT() {
// disable magic_quotes_runtime if it's turned on
set_magic_quotes_runtime(0);
// debugging mode?
$this->debug = 0;
$this->reset();
}
function reset() {
if ($this->parser)
xml_parser_free($this->parser);
// XML file pointer
$this->fp = 0;
// which data has been read?
$this->metaDataRead = 0;
$this->allRead = 0;
// to maintain track of where we are inside the XML file
$this->inXml = 0;
$this->inData = 0;
$this->inMeta = 0;
$this->inSkin = 0;
$this->inTemplate = 0;
$this->currentName = '';
$this->currentPartName = '';
// character data pile
$this->cdata = '';
// list of skinnames and templatenames (will be array of array)
$this->skins = array();
$this->templates = array();
// extra info included in the XML files (e.g. installation notes)
$this->info = '';
// init XML parser
$this->parser = xml_parser_create();
xml_set_object($this->parser, $this);
xml_set_element_handler($this->parser, 'startElement', 'endElement');
xml_set_character_data_handler($this->parser, 'characterData');
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 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)
*/
function readFile($filename, $metaOnly = 0) {
// open file
$this->fp = @fopen($filename, 'r');
if (!$this->fp) return 'Failed to open file/URL';
// here we go!
$this->inXml = 1;
while (!feof($this->fp)) {
$tempbuffer .= fread($this->fp, 4096);
}
fclose($this->fp);
/*
[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)
// 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
$tempbuffer = preg_replace_callback(
"/(<!\[CDATA\[[^]]*?<!\[CDATA\[[^]]*)((?:\]\].*?<!\[CDATA.*?)*)(\]\])(.*\]\])/ms",
create_function(
'$matches',
'return $matches[1] . preg_replace("/(\]\])(.*?<!\[CDATA)/ms","]]]]><![CDATA[$2",$matches[2])."]]]]><![CDATA[".$matches[4];'
),
$tempbuffer
);
*/
$temp = tmpfile();
fwrite($temp, $tempbuffer);
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 />';
}
// all done
$this->inXml = 0;
fclose($temp);
}
/**
* Returns the list of skin names
*/
function getSkinNames() {
return array_keys($this->skins);
}
/**
* Returns the list of template names
*/
function getTemplateNames() {
return array_keys($this->templates);
}
/**
* Returns the extra information included in the XML file
*/
function getInfo() {
return $this->info;
}
/**
* Writes the