plugins:skinextensible:np_skinextensible

Source code: NP_SkinExtensible.php

NP_SkinExtensible.php

<?php 
class NP_SkinExtensible extends NucleusPlugin { 
	function getName() { return 'NP_SkinExtensible'; }
	function getMinNucleusVersion() { return 330; }
	function getAuthor()  { return 'Katsumi'; }
	function getVersion() { return '0.1.4'; }
	function getURL() {return 'http://japan.nucleuscms.org/wiki/plugins:skinextensible';}
	function getDescription() { return 'Skins are extensible by using this plugin.'; }
	function getPluginDep(){ return array('NP_SkinVarManager'); }
	function supportsFeature($what) { return ($what=='SqlTablePrefix')?1:0; }
	function getEventList() { return array('RegisterSkinVars','PreParseContents'); }
	var $history=array();
	var $biographies=array();
	function event_RegisterSkinVars(&$data){
		$data['skinvars']['skinfile']=array(&$this,'parse_skinfile');
	}
	function event_PreParseContents(&$data){
		if ($data['filename']===false) $this->_skinparse($data);
		else $this->_parsedinclude($data);
	}
	function _skinparse(&$data){
		// Get basic data.
		$skin=&$data['skin'];
		$contents=&$data['contents'];
		$skinid=$skin->getID();
		$type=$data['type'];
		// The 'extends' skin type cannot be used as skin content.
		if ($type=='extends') {
			$contents=_ERROR_SKIN;
			return;
		}
		// Get the skin data.
		$query='SELECT * FROM '.sql_table('skin').
			' WHERE sdesc='.(int)$skinid.
			' AND stype IN ("extends","'.addslashes($type).'")';
		$res=sql_query($query);
		$result=array();
		while($row=mysql_fetch_assoc($res)){
			$result[$row['stype']]=$row;
		}
		// Return if this skintype is set.
		if (isset($result[$type])) return;
		// Return if not extended.
		if (!isset($result['extends'])) return;
		// Get the family history.
		$history=preg_split('/[\r\n]+/',$result['extends']['scontent']);
		// Prepare anthestors' biographies.
		$query='SELECT * FROM '.sql_table('skin').', '.sql_table('skin_desc').
			' WHERE sdesc=sdnumber'.
			' AND stype="'.addslashes($type).'"';
		$res=sql_query($query);
		$biographies=array();
		while($row=mysql_fetch_assoc($res)){
			if (in_array($row['sdname'],$history)) $biographies[$row['sdname']]=$row;
		}
		// Copy the history and biographies as object properties.
		$this->history=$history;
		$this->biographies=$biographies;
		// Content is from the anthestor.
		foreach($history as $sname){
			if (!isset($biographies[$sname])) continue;
			// Anthestor found.  Let's change the contents to anthestor's one.
			$contents=$biographies[$sname]['scontent'];
			return;
		}
	}
	function _parsedinclude(&$data){
		// If contents already exists (i.e. file already found in parse_parsedinclude method), return.
		$contents=&$data['contents'];
		if ($contents!==false) return;
		// Initialize
		$filename=$data['basefilename'];
		// Get prefix
		$prefix=$this->_getPrefix($filename);
		if (!$prefix) return;
		// Read the file
		global $DIR_SKINS;
		$fullpath=$DIR_SKINS.$prefix.$filename;
		$contents=file_get_contents($fullpath);
	}
	function parse_skinfile($skinType,$filename) {
		global $CONF,$DIR_SKINS;
		$orgprefix=PARSER::getProperty('IncludePrefix');
		if (file_exists($DIR_SKINS. $orgprefix .$filename)) {
			$prefix=$orgprefix;
		} elseif ($prefix=$this->_getPrefix($filename)) {
		} else $prefix=$orgprefix;
		echo $CONF['SkinsURL'] . $prefix . $filename;
	}
	function _getPrefix($filename){
		static $biographies;
		if (!isset($biographies)) $biographies=$this->biographies;
		// Seek the history
		foreach($this->history as $sname){
			if (!isset($biographies[$sname])) continue;
			if ($biographies[$sname]['sdincmode']!='skindir') continue;
			global $DIR_SKINS;
			$fullpath=$DIR_SKINS.$biographies[$sname]['sdincpref'].$filename;
			if (!file_exists($fullpath)) continue;
			return $biographies[$sname]['sdincpref'];
		}
		return false;
	}
 
}
 
plugins/skinextensible/np_skinextensible.txt · 最終更新: 2011/03/23 21:28 (外部編集)