⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plugincreatetool.php

📁 一款基于PHP的网络日记程序。WikyBlog支持:多用户的 BLOG
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?phpdefined('WikyBlog') or die("Not an entry point...");class createPluginTool{	var $types = array();		//used for checking	var $existingVars = array();	var $usedCols = array();		//resulting files	var $sqlFile, $infoFile, $classFile;			function createPluginTool(){		global $page;				includeFile('admin/CheckPrivs.php');		if( !checkPrivs::isGranted() ){			return;		}				$temp = get_class_vars('dbPage');		foreach($temp as $var => $value){			$this->existingVars[strtolower($var)] = $value;		}		if( array_key_exists('content', $this->existingVars ) ){			unset($this->existingVars['content']);		}		if( array_key_exists('keywords', $this->existingVars ) ){			unset($this->existingVars['keywords']);		}				$this->types['SPECIAL TYPES'] = FALSE;		$this->types['WIKI SYNTAX'] = 'WIKI SYNTAX';		$this->types['URL'] = 'url';				$this->types['LIST TYPES'] = FALSE;		$this->types['ENUM'] = 'list';		$this->types['SET'] = 'list';				$this->types['DATE & TIME TYPES'] = FALSE;		$this->types['DATE'] = 'date';		//$this->types['DATETIME'] = 'date';		//$this->types['TIMESTAMP'] = 'date';		$this->types['TIME'] = 'date';		//$this->types['YEAR'] = 'date';				$this->types['STRING TYPES'] = FALSE;		$this->types['CHAR'] = 'len';		$this->types['VARCHAR'] = 'len';		$this->types['BINARY'] = 'len';		$this->types['VARBINARY'] = 'len';				$this->types['NUMERIC TYPES'] = FALSE;		$this->types['TINYINT'] = 'int';		$this->types['SMALLINT'] = 'int';		$this->types['MEDIUMINT'] = 'int';		$this->types['INT'] = 'int';		$this->types['BIGINT'] = 'int';		// $this->types['FLOAT'] = 'dec';		// $this->types['DOUBLE'] = 'dec';		// $this->types['DECIMAL'] = 'dec';						//$this->types['TEXT'] = 'text';		//$this->types['TINYBLOB'] = 'text';		//$this->types['TINYTEXT'] = 'text';		//$this->types['BLOB'] = 'text';		//$this->types['MEDIUMBLOB'] = 'text';		//$this->types['MEDIUMTEXT'] = 'text';		//$this->types['LONGBLOB'] = 'text';		//$this->types['LONGTEXT'] = 'text';						//$this->types['BOOL'] = '';	}		function createScripts(){		global $packageVersion,$page,$rootDir;						//		//	SQL File		//					$this->sqlFile = array();			$this->sqlFile['Engine'] = 'MyISAM';			$this->sqlFile['Collation'] = 'utf8_general_ci';			$this->sqlFile['Default_charset'] = 'DEFAULT CHARSET=utf8';			$this->sqlFile['columns'] = array();			$this->sqlFile['columns']['file_id'] = '`file_id` int(8) unsigned NOT NULL';			$this->sqlFile['columns']['owner'] = '`owner` varchar(20) NOT NULL';			$this->sqlFile['columns']['title'] = '`title` varchar(40) NOT NULL';			$this->sqlFile['columns']['summary'] = '`summary` varchar(200) DEFAULT NULL';			$this->sqlFile['columns']['hitcounter'] = '`hitcounter` mediumint(8) unsigned NOT NULL';			$this->sqlFile['keys'] = array();			$this->sqlFile['keys']['PRIMARY'] = 'PRIMARY KEY (`owner`, `title`)';			$this->sqlFile['keys']['file_id'] = 'UNIQUE (`file_id`)';						foreach($_POST['add'] as $array){				$this->createSql($array);			}			//message(showArray($this->sqlFile));					//		//	dbInfo File		//						$plugin = toStorage($_POST['plugin']);			$lowerName = wbStrtolower($plugin);			$this->infoFile = array();			$this->infoFile[] = '<'.'?'.'php';			$this->infoFile[] = '$installInfo[\'class\'] = \''.$lowerName.'\';';			$this->infoFile[] = '$installInfo[\'dbTable\'] = "`{$wbTablePrefix}xt_{$lowerName}`";';					$this->createClass($plugin);		return $plugin;	}		function modify($plugin){		global $rootDir,$packageVersion,$page,$dbObject;		$lowerName = wbStrtolower($plugin);		$page->formAction = $dbObject->links['Create Plugin'].'?plugin='.$lowerName;		//		//	Output		//			ob_start();						echo '<p>';			echo 'The following textareas contain the generated code for your plugin.';			echo '</p>';						echo '<h2>Manual Installation</h2>';			echo '<ol>';				echo '<li>Create a directory <tt>'.$rootDir.'/plugins/'.$lowerName.'.</tt></li>';				echo '<li>In this directory create three files: <tt>class.php, dbInfo.php, installSQL.php</tt>  </li>';				echo '<li>Cut and paste the code in the following textareas into the corresponding files.  </li>';				echo '<li>Go to '.wbLinks::admin('DataTypes','Manage Plugins').' install your new plugin.</li>';			echo '</ol>';						echo '<h2>Plugin Code</h2>';						echo '<h3 class="heading">class.php</h3>';			echo '<div style="margin:0 3em 0 3em;">';			echo '<textarea wrap="off" style="width:100%;margin:0;" rows="20">';			$temp = '<'.'?'.'php'."\n";			$temp .= 'defined(\'WikyBlog\') or die(\'Not an entry point...\');'."\n";			$temp .= implode("\n",$this->classFile);						echo htmlspecialchars($temp);			echo '</textarea>';			echo '</div>';												echo '<h3 class="heading">dbInfo.php</h3>';			echo '<div style="margin:0 3em 0 3em;">';			echo '<textarea wrap="off" style="width:100%;" rows="7">';			$temp = implode("\n",$this->infoFile);			echo htmlspecialchars($temp);			echo '</textarea>';			echo '</div>';						echo '<h3 class="heading">installSQL.php</h3>';			echo '<div style="margin:0 3em 0 3em;">';			echo '<textarea wrap="off" style="width:100%;" rows="7">';						//this is from admin/PluginSQL.php			$text = '<'.'?'."php\n";			$text .= "//\n";			$text .= "//\t\tWikyBlog Generated File\n";			$text .= "//\t\tpackage version ".$packageVersion."\n";			$text .= "//\t\tadminPluginSQL.php\n";					$text .= "//\t\t********************************************************************************************************\n";			$text .= "//\t\tThis file contains a serialized array used to create/alter database tables used by the WikyBlog software\n";			$text .= "//\t\tDon't edit anything in this file!\n";			$text .= "//\n\n";			$text .= 'defined(\'WikyBlog\') or die(\'Not an entry point...\');';			$text .= "\n\n";			$text .= '$dbData = \'';			$array = array();			$array['xt_'.wbStrtolower($plugin)] = $this->sqlFile;			$text .= addcslashes(serialize($array),"\'");			$text .= '\';';			$text .= "\n\n\n";			echo htmlspecialchars($text);			echo '</textarea>';			echo '</div>';						$page->contentA['Plugin Code'] = wb::get_clean();		return true;	}		function addToDB($plugin){		global $wbTables,$wbTablePrefix,$page,$dbInfo;		$lowerName = wbStrtolower($plugin);		includeFile('admin/PluginAdd.php');		$selector = 'class:'.$lowerName;				//		//	class		//				$class = implode("\n",$this->classFile);			if( !pluginAdd::ad_object($selector,$class) ){				$page->contentA['Plugin Installation'] = '<div style="text-align:center;margin:5em;">Plugin installation failed. (2)</div>';				return;			}					//		//	dbInfo and sql		//				$info = array();			$info['dbPlugin'] = true;			$info['dbTable'] = 	"`{$wbTablePrefix}xt_{$lowerName}`";			$info['class'] = $lowerName;						$array = array();			$array['xt_'.$lowerName] = $this->sqlFile;			$temp = serialize($array);						if( !pluginAdd::add($plugin,$temp,$info) ){				$page->contentA['Plugin Installation'] = '<div style="text-align:center;margin:5em;">Plugin installation failed. (2)</div>';				return;			}					$page->contentA['Plugin Installation'] = '<div style="text-align:center;margin:5em;">Plugin added successfully.</div>';			}		////////////////////////////////////////////////////////////////////////	//	//		Create the class File	//	function createClass($name){		$tab = "\t";						$t =& $this->classFile;		$t = array();						$dbValues = ' array(\'owner\'=>1,\'title\'=>1';		$vars = array();		$user = array();				foreach($_POST['add'] as $i => $array){			$temp = strtolower($array['name']);			if( $temp == 'keywords'){				$user[] = '\''.$temp.'\'=>1';							}else{				$dbValues .= ',\''.$temp.'\'=>1';				$user[] = '\''.$temp.'\'=>1';				$vars[] = '$'.$temp;			}		}		$dbValues .= ');';		$userValues = ' array('.implode(',',$user).');';						$t[] = '';		$t[] = 'class '.$name.' extends dbPage{';		$t[] = '';				if( count($vars) > 0){			$t[] = $tab.'var '.implode(',',$vars).';';			$t[] = '';		}				$t[] = '';		$t[] = $tab.'var $dbValues ='.$dbValues;		$t[] = $tab.'var $userValues ='.$userValues;		$t[] = '';		$t[] = $tab.'function '.$name.'($type){';		$t[] = $tab.$tab.'$this->objectType = $type;';		$t[] = $tab.$tab.'$this->setDbInfo();';		$t[] = $tab.'}';				$t[] = '';		$t[] = $tab.'function setLinks(){';		$t[] = $tab.$tab.'global $page,$pageOwner,$lang;';		$t[] = $tab.$tab.'parent::setLinks();';		$t[] = $tab.$tab.'$page->displayTitle = $lang[$this->objectType] .\' > \'.toDisplay($this->title);';		$t[] = $tab.$tab.'$this->links[\'?\'] = \''.$name.'\';';		$t[] = $tab.'}';				//newPage		//		//!!	hmm.. they won't all have content!		//		$t[] = '';		$t[] = $tab.'function newPage(){';		$t[] = $tab.$tab.'global $includeDir,$page,$userLanguage,$lang;';		$t[] = $tab.$tab.'parent::newPage();';		$t[] = $tab.$tab.'if( $this->editable ){';		$t[] = $tab.$tab.$tab.'$this->content = wbLang::text(\'DEFAULT_CONTENT\',$this->uniqLink);';		$t[] = $tab.$tab.$tab.'if( empty($page->userCmd) && cookies() ){';		$t[] = $tab.$tab.$tab.$tab.'$page->userCmd = \'edit\';';		$t[] = $tab.$tab.$tab.'}';		$t[] = $tab.$tab.'}else{';		$t[] = $tab.$tab.$tab.'$this->content = $lang[\'DEFAULT_CONTENT_PROTECTED\'];';		$t[] = $tab.$tab.'}';				foreach($_POST['add'] as $array){			$lowerName = strtolower($array['name']);			switch($array['type']){				case 'URL':					$t[] = $tab.$tab.'$this->'.$lowerName.' = "http://";';				break;				case 'DATE':					$t[] = $tab.$tab.'$this->'.$lowerName.' = "0000-00-00";';				break;				case 'TIME':					$t[] = $tab.$tab.'$this->'.$lowerName.' = "00:00:00";';				break;			}		}		$t[] = $tab.'}';		$t[] = '';						//outputObj		$t[] = '';		$t[] = $tab.'function outputObj($field=true){';		$t[] = $tab.$tab.'global $page,$wbParser;';		$t[] = $tab.$tab.'includeFile(\'tool/pluginDisplay.php\');';		$t[] = $tab.$tab.'ob_start();';		$t[] = $tab.$tab.'initiateParser();';		$t[] = $tab.$tab.'$field = $this->getOutputField($field);';		$t[] = '';		$t[] = $tab.$tab.'echo \'<table cellpadding="7">\';';				$savebarKeywords = false;		$len = count($_POST['add']);		$i = 1;		foreach($_POST['add'] as $array){			$lowerName = strtolower($array['name']);			if( ($i == $len) && ($lowerName =='keywords')){				if( $array['type'] === 'VARCHAR' ){					$savebarKeywords = true;					continue;				}			}			$i++;						switch($array['type']){								case 'WIKI SYNTAX':					$t[] = $tab.$tab.'pluginDisplay::wiki($this->'.$lowerName.');';				break;								case 'URL':					$t[] = $tab.$tab.'pluginDisplay::url(\''.$array['name'].'\',$this->'.$lowerName.');';				break;				case 'TIME':					$t[] = $tab.$tab.'pluginDisplay::time(\''.$array['name'].'\',$this->'.$lowerName.');';				break;				case 'DATE':					$t[] = $tab.$tab.'pluginDisplay::date(\''.$array['name'].'\',$this->'.$lowerName.');';				break;				default:					$t[] = $tab.$tab.'pluginDisplay::display(\''.$array['name'].'\',$this->'.$lowerName.');';				break;			}		}		$t[] = $tab.$tab.'echo \'</table>\';';		$t[] = '';						$t[] = $tab.$tab.'$page->contentA[$field] = wb::get_clean();';		$t[] = $tab.$tab.'$page->contentShowId = $field;';		$t[] = $tab.$tab.'return $field;';		$t[] = $tab.'}';		$t[] = '';								//abbrevOutput		$t[] = '';		$t[] = $tab.'function abbrevOutput(&$row){';		$t[] = $tab.$tab.'includeFile(\'tool/pluginDisplay.php\');';		$t[] = $tab.$tab.'pluginDisplay::abbrevHeading($row);';		$t[] = '';		$t[] = $tab.$tab.'echo \'<table>\';';				$i = 0;		$comment = '';		foreach($_POST['add'] as $array){			if( $i == 3 ){				$comment = '//';				$t[] = '';				$t[] = $tab.$tab.$comment.'The following values were commented out to create an abbreviated display for this object.';			}			$i++;						$lowerName = strtolower($array['name']);						switch($array['type']){				case 'WIKI SYNTAX':					$t[] = $tab.$tab.$comment.'pluginDisplay::abbrevWiki($row->'.$lowerName.',$row->uniqLink);';				break;								case 'URL':					$t[] = $tab.$tab.$comment.'pluginDisplay::url(\''.$array['name'].'\',$row->'.$lowerName.');';				break;				case 'TIME':					$t[] = $tab.$tab.$comment.'pluginDisplay::time(\''.$array['name'].'\',$row->'.$lowerName.');';				break;				case 'DATE':					$t[] = $tab.$tab.$comment.'pluginDisplay::date(\''.$array['name'].'\',$row->'.$lowerName.');';				break;				default:					$t[] = $tab.$tab.$comment.'pluginDisplay::display(\''.$array['name'].'\',$row->'.$lowerName.');';				break;			}					}				$t[] = '';		$t[] = $tab.$tab.'echo \'</table>\';';		$t[] = $tab.'}';		$t[] = '';						//setFromPost		$t[] = '';		$t[] = $tab.'function setFromPost(){';		$t[] = $tab.$tab.'includeFile(\'tool/pluginEdit.php\');';				foreach($_POST['add'] as $array){			if( isset($array['type']) ){				$name = strtolower($array['name']);				switch($array['type']){					case 'SET':						$t[] = $tab.$tab.'pluginFromPost::setSet(\''.$name.'\');';					break;				}			}					}		$t[] = $tab.$tab.'parent::setFromPost();';		$t[] = $tab.'}';		$t[] = '';		//check		$t[] = '';		$t[] = $tab.'function checkData($warn=true){';		$t[] = $tab.$tab.'if(!$warn){ return;}';		$t[] = $tab.$tab.'global $wbParser,$lang;';		$t[] = $tab.$tab.'includeFile(\'tool/pluginCheck.php\');';			foreach($_POST['add'] as $array){				$name = strtolower($array['name']);				switch($array['type']){					case 'URL':						$t[] = $tab.$tab.'pluginCheck::url(\''.$name.'\',$warn);';					break;					case 'WIKI SYNTAX':						$t[] = $tab.$tab.'pluginCheck::wiki(\''.$name.'\',$warn);';							break;										///Date and Time					case 'DATE':						$this->classFile[] = $tab.$tab.'pluginCheck::date(\''.$array['name'].'\');';					break;					case 'TIME':						$this->classFile[] = $tab.$tab.'pluginCheck::time(\''.$array['name'].'\');';					break;										///Integers					case 'TINYINT':						$this->classFile[] = $tab.$tab.'pluginCheck::integer(\''.$array['name'].'\',\'TINYINT\');';					break;					case 'SMALLINT':						$this->classFile[] = $tab.$tab.'pluginCheck::integer(\''.$array['name'].'\',\'SMALLINT\');';					break;					case 'MEDIUMINT':						$this->classFile[] = $tab.$tab.'pluginCheck::integer(\''.$array['name'].'\',\'MEDIUMINT\');';					break;					case 'INT':						$this->classFile[] = $tab.$tab.'pluginCheck::integer(\''.$array['name'].'\',\'INT\');';					break;					case 'BIGINT':						$this->classFile[] = $tab.$tab.'pluginCheck::integer(\''.$array['name'].'\',\'BIGINT\');';					break;				}			}		$t[] = $tab.'}';		$t[] = '';				//editValues		$t[] = '';		$t[] = $tab.'function editValues(){';		$t[] = $tab.$tab.'global $page,$jsNum;';		$t[] = $tab.$tab.'$page->css2 = true;';		$t[] = $tab.$tab.'$page->scripts[] = \'/include/\'.$jsNum.\'/editing.js\';';

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -