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

📄 plugins.php

📁 一款基于PHP的网络日记程序。WikyBlog支持:多用户的 BLOG
💻 PHP
字号:
<?phpdefined('WikyBlog') or die("Not an entry point...");global $page,$pageOwner,$dbObject,$lang;$dbObject->links['Install Plugins'] = $page->formAction = '/Admin/'.$pageOwner['username'].'/DataTypes';$dbObject->links['PluginSQL'] = '/Admin/'.$pageOwner['username'].'/PluginSQL';$dbObject->links['?'] = 'Install Plugins';$page->displayTitle = 'Install Plugins';if( $_SESSION['userlevel'] !== 4){	$page->contentA[$page->displayTitle] = 'You must be an administrator to access this page.';	return;}class adminPlugins{	var $available = array();	var $installed = array();	var $pluginDir;			function adminPlugins(){		global $page,$rootDir,$lang;		$this->pluginDir = $rootDir.'/plugins';				includeFile('admin/CheckPrivs.php');		if( !checkPrivs::isGranted() ){			return;		}				ob_start();		$this->getPlugins();				switch( $page->userCmd ){			case 'upgrade':				$this->upgrade();				$this->show();			break;			case 'install':				$this->install();			break;						case 'confirm install';				$this->confirmedInstall();				$this->show();			break;						default:				$this->show();			break;					}				$page->contentA['Install Plugins'] = wb::get_clean();	}		//This should just update the current config..	function saveConfig(){		global $wbTables;				$query = 'SELECT revision, modified, data FROM '.$wbTables['config'].' ORDER BY revision DESC LIMIT 1'; 		$result = wbDB::runQuery($query);		$row = mysql_fetch_assoc($result);		$data = unserialize($row['data']);		$revision = $row['revision'];				//Update		$serialized = serialize($data);		if( $serialized == $row['data'] ){			return;		}				$query = 'UPDATE '.$wbTables['config'].' SET `modified`=`modified`, `data`="'.wbDB::escape($serialized).'"';		$query .= ' WHERE `revision` = '.$revision;		wbDB::runQuery($query);		$num = mysql_affected_rows();		if( $num < 1){			message('<b>Warning</b> This configuration was not updated.');		}else{			message('Your configuration has been updated.');		}			}		///////////////////////////////////////////////////////////////////////////	//	//	Upgrade	//	function upgrade(){		global $page,$dbInfo;				$class = $dbInfo[$page->cmdArg[0]]['class'];				$infoFile = $this->pluginDir.'/'.$class.'/dbInfo.php';		$classFile = $this->pluginDir.'/'.$class.'/class.php';		$sqlFile = $this->pluginDir.'/'.$class.'/installSQL.php';				if( !file_exists($infoFile) ){			return;		}		if( !file_exists($classFile) ){			return;		}		if( !file_exists($sqlFile) ){			return;		}		$files = array($infoFile,$classFile,$sqlFile);				if( $this->installUpdate($page->cmdArg[0],$class,$files) ){			message('<tt>'.$page->cmdArg[0].'</tt> was successfully upgraded.');		}	}		///////////////////////////////////////////////////////////////////////////	//	//	Install	//	function confirmedInstall(){		global $page;		includeFile('admin/PluginAdd.php');				$name = toStorage($_POST['as']);		$lowerName = wbStrtolower($name);		//		//	Check		//					$regExp = '^[A-Za-z0-9_-]+$';			if(!eregi($regExp,$name)){				message('The <tt>Install as:</tt> field can only contain alphanumeric, underscore and dash characters.');				return false;			}					if( !pluginAdd::checkName($lowerName) ){				return;			}				//		//	install		//			if( $this->installUpdate($name,$page->cmdArg[0],$this->available[$page->cmdArg[0]]) ){								message('<tt>'.$page->cmdArg[0].'</tt> was installed successfully.');				unset($this->available[$page->cmdArg[0]]);				$this->saveConfig();			}	}			function installUpdate($name,$which,$files){		global $page,$wbTablePrefix,$dbObject;		require_once('installDB.php');		$lowerName = wbStrtolower($name);						list($infoFile, $classFile, $sqlFile) = $files;				//Get the data		require_once($sqlFile);		if( !isset($dbData) ){			message('Invalid installSQL.php file. Consult the plugin developer for more information.');			return false;		}		require_once($infoFile);		if( !isset($installInfo) ){			message('Invalid dbInfo.php file. Consult the plugin developer for more information.');			return false;		}		$installInfo['isPlugin'] = true;		if( pluginAdd::add($name,$dbData,$installInfo) ){			return true;		}		return false;	}			function install(){		global $page;				$_POST += array('as'=>$page->cmdArg[0]);				if( !isset($this->available[$page->cmdArg[0]]) ){			message('Invalid data type: '.$page->cmdArg[0]);			return;		}				echo '<table style="margin-left:auto;margin-right:auto;" cellpadding="10">';		echo '<tr><td>';			echo 'Installing Plugin: ';			echo '</td><td>';			echo $page->cmdArg[0];			echo '</td><td class="sm">';			echo 'The name of the plugin your are installing.';			echo '</td></tr>';		echo '<tr><td>';			echo 'Install as: ';			echo '</td><td>';			echo '<input type="text" name="as" value="'.$_POST['as'].'" >';			echo '</td><td class="sm">';			echo 'A unique name for your data type that will be used for urls and page titles. (a-zA-Z only) ';			echo '</td></tr>';					echo '<tr><td>';			echo '</td><td>';			echo '<input type="submit" name="cmd['.$page->cmdArg[0].']" value="Confirm Install" /> ';			echo '<input type="submit" name="cmd" value="Cancel" />';			echo '</td></tr>';		echo '</table>';				echo '<p class="sm" style="text-align:center;">';		echo 'You should always backup your data before installing new components.';		echo '</p>';				}		///////////////////////////////////////////////////////////////////////////	//	//	Show	//	function show(){		global $dbInfo;				echo '<table style="width:100%" cellpadding="15"><tr><td width="50%">';		$this->showUninstalled();		echo '</td></tr>';				echo '<tr><td>';		echo '<h3 class="heading">Your Plugin Directory</h3><div class="underline"></div>';		echo '<ul><li>';		echo '<tt>'.$this->pluginDir.'</tt>';		echo '</li></ul>';				echo '</td></tr>';				echo '<tr><td colspan="2">';		echo '<h3 class="heading">How To Install Plugins</h3><div class="underline"></div>				<ol>				<li> Download plugins from <a href="http://www.wikyblog.com/Main/Plugins">WikyBlog.com</a>.</li>				<li> Copy the appropriate files into your plugins directory.</li>				<li> Reload this page, then click "Install" for the new plugin.</li>				</ol>';						echo '</td></tr>';				echo '<tr><td colspan="2">';		echo '<h3 class="heading">Plugin Development</h3><div class="underline"></div>';		echo 'If you plan on creating a custom plugin, the following may be useful.';		echo '<ul>';		echo '<li>'.wbLinks::admin('CreatePlugin','Plugin Creator').' This script can output php code for custom plugins.</li>';		echo '<li>'.wbLinks::admin('PluginSQL','Plugin Development').' This script will create the data needed in a plugin\'s installSQL.php file.</li>';		echo '<li>Integrated debugging is available. Uncomment the following line in your wiki.php file.<br><pre>	define(\'wbDebug\',true);</pre></li>';		echo '</ul>';				echo '</td></tr>';				echo '</td></tr></table>';	}		function showUninstalled(){		global $lang,$dbInfo;				$i = 0;		$classes[] = ' class="tableRowOdd" ';		$classes[] = ' class="tableRowEven" ';							echo '<table class="tableRows" style="width:100%" >';		echo '<tr><th style="white-space:nowrap" colspan="2">'.$lang['available_plugins'].'</th><th>'.$lang['options'].'</th></tr>';		foreach($this->available as $space => $null){			echo '<tr'.$classes[($i%2)].'>';			echo '<td colspan="2">';			echo $space;			echo '</td>';			echo '<td>';			echo '<input type="submit" name="cmd['.$space.']" value="Install" />';			echo '</td>';			echo '</tr>';			$i++;		}		if( $i === 0){			echo '<tr>';			echo '<td style="text-align:center" colspan="3">';			echo $lang['empty'];			echo '</td>';			echo '</tr>';					}				if( count($this->installed) < 1){			echo '</table>';			return;		}		$i = 0;		echo '<tr><td>&nbsp;</td></tr>';		echo '<tr><th style="white-space:nowrap">Installed Plugins</th><th>Installed As</th><th>'.$lang['options'].'</th></tr>';		foreach($this->installed as $plugin => $class){			echo '<tr'.$classes[($i%2)].'>';			echo '<td>';			echo $plugin;			echo '</td>';			echo '<td>';			echo $class;			echo '</td>';			echo '<td>';			echo '<input type="submit" name="cmd['.$class.']" value="Upgrade" />';			echo ' '.wbLinks::admin('ManageTypes?cmd['.$class.']=Remove','Remove');			echo '</td>';			echo '</tr>';			$i++;		}				echo '</table>';							}	function getPlugins(){		global $rootDir,$dbInfo;				$newInfo = array();				if( !file_exists($this->pluginDir) ){			return;		}		$dh = @opendir($this->pluginDir);		if(!$dh ){			return;		}				while(($file = readdir($dh)) !== false){			if( strpos($file,'.') === 0){				continue;			}						$fullPath = $this->pluginDir.'/'.$file;			if( !is_dir($fullPath) ){				continue;			}						$infoFile = $this->pluginDir.'/'.$file.'/dbInfo.php';			$classFile = $this->pluginDir.'/'.$file.'/class.php';			$sqlFile = $this->pluginDir.'/'.$file.'/installSQL.php';						if( !file_exists($infoFile) ){				if( defined('wbDebug') && wbDebug == true){					message('dbInfo.php doesn\'t exist for plugin <tt>'.$file.'</tt>');				}				continue;			}			if( !file_exists($classFile) ){				if( defined('wbDebug') && wbDebug == true){					message('class.php doesn\'t exist for plugin <tt>'.$file.'</tt>');				}				continue;			}			if( !file_exists($sqlFile) ){				if( defined('wbDebug') && wbDebug == true){					message('installSQL.php doesn\'t exist for plugin <tt>'.$file.'</tt>');				}				continue;			}			$this->available[$file] = array($infoFile,$classFile,$sqlFile);		}				//cannot have two of the same plugin because of database table names!		foreach($dbInfo as $space => $info){			$class =& $info['class'];			if( isset($info['isPlugin']) && isset($this->available[$class])){				unset($this->available[$class]);				$this->installed[$class] = $space;			}		}	}	}new adminPlugins();

⌨️ 快捷键说明

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