plugins:np_if:np_if_code

Source code: NP_if.php

NP_if.php

<?php
class NP_else extends NucleusPlugin{
	var $np_if;
	function doTemplateVar(){
		$this->np_if->args=func_get_args();
		$item=array_shift($this->np_if->args);
		$this->np_if->_if($this,$item);
	}
	function doTemplateCommentsVar(){
		$this->np_if->args=func_get_args();
		$item=array_shift($this->np_if->args);
		$comment=array_shift($this->np_if->args);
		$this->np_if->_if($this,$item);
	}
	function doItemVar(){
		$this->np_if->args=func_get_args();
		$item=array_shift($this->np_if->args);
		if (!$this->np_if->_authorIsAdmin($item)) return;
		$this->np_if->_if($this,$item);
	}
}
 
class NP_if extends NP_else {
	function getName() { return 'NP_if'; }
	function getMinNucleusVersion() { return 220; }
	function getAuthor()  { return 'Katsumi'; }
	function getVersion() { return '0.1.3'; }
	function getURL() {return 'http://japan.nucleuscms.org/wiki/plugins:np_if';}
	function getDescription() { return $this->getName().' plugin'; }
	function supportsFeature($what) { return ($what=='SqlTablePrefix')?1:0; }
	function getEventList() { return array('InitSkinParse'); }
	var $handler=false;
	function event_InitSkinParse(&$data){
		global $CONF,$manager;
		if ($CONF['UsingAdminArea']) return;
		$this->handler=new ACTIONS($data['type']);
		$this->np_if=&$this;
		$commands=array('ifnot','else','endif','elseif','elseifnot');
		foreach($commands as $name) {
			$name='NP_'.$name;
			$manager->cachedInfo['installedPlugins'][]=$name;
			$manager->plugins[$name]=new $name;
			$manager->plugins[$name]->np_if=&$this;
		}
	}
	var $args=array();
	function _if(&$class,&$item){
		$this->item=&$item;
		$name=substr(get_class($class),3);
		call_user_func_array(array(&$this->handler,'parse_'.$name),$this->args);
	}
	var $adminitems=array();
	function _authorIsAdmin(&$item){
		if (!isset($this->adminitems[$item->itemid])) {
			$query='SELECT madmin as result FROM '.sql_table('member').
				' WHERE mnumber='.(int)$item->authorid.' LIMIT 1';
			$this->adminitems[$item->itemid]=quickQuery($query);
		}
		return $this->adminitems[$item->itemid];
	}
	var $item=false;
	function doIf($name='',$value=''){
		if (!$this->item) return false;
		if (!isset($this->item->$name)) return false;
		return $this->item->$name==rawurldecode($value);
	}
}
 
class NP_ifnot extends NP_else {}
class NP_endif extends NP_else {}
class NP_elseif extends NP_else {}
class NP_elseifnot extends NP_else {}
?>
 
plugins/np_if/np_if_code.txt · 最終更新: 2011/03/23 21:28 (外部編集)