本文整理匯總了PHP中Typecho_Plugin::checkDependence方法的典型用法代碼示例。如果您正苦於以下問題:PHP Typecho_Plugin::checkDependence方法的具體用法?PHP Typecho_Plugin::checkDependence怎麽用?PHP Typecho_Plugin::checkDependence使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Typecho_Plugin
的用法示例。
在下文中一共展示了Typecho_Plugin::checkDependence方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: activate
/**
* 激活插件
*
* @access public
* @return void
*/
public function activate($pluginName)
{
/** 獲取插件入口 */
list($pluginFileName, $className) = Typecho_Plugin::portal($pluginName, __TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__);
$info = Typecho_Plugin::parseInfo($pluginFileName);
/** 檢測依賴信息 */
list($version, $build) = explode('/', Typecho_Common::VERSION);
if (Typecho_Plugin::checkDependence($build, $info['dependence'])) {
/** 獲取已激活插件 */
$plugins = Typecho_Plugin::export();
$activatedPlugins = $plugins['activated'];
/** 載入插件 */
require_once $pluginFileName;
/** 判斷實例化是否成功 */
if (isset($activatedPlugins[$pluginName]) || !class_exists($className) || !method_exists($className, 'activate')) {
throw new Typecho_Widget_Exception(_t('無法激活插件'), 500);
}
try {
$result = call_user_func(array($className, 'activate'));
Typecho_Plugin::activate($pluginName);
$this->update(array('value' => serialize(Typecho_Plugin::export())), $this->db->sql()->where('name = ?', 'plugins'));
} catch (Typecho_Plugin_Exception $e) {
/** 截獲異常 */
$this->widget('Widget_Notice')->set($e->getMessage(), NULL, 'error');
$this->response->goBack();
}
$form = new Typecho_Widget_Helper_Form();
call_user_func(array($className, 'config'), $form);
$personalForm = new Typecho_Widget_Helper_Form();
call_user_func(array($className, 'personalConfig'), $personalForm);
$options = $form->getValues();
$personalOptions = $personalForm->getValues();
if ($options && !$this->configHandle($pluginName, $options, true)) {
self::configPlugin($pluginName, $options);
}
if ($personalOptions && !$this->personalConfigHandle($className, $personalOptions)) {
self::configPlugin($pluginName, $personalOptions, true);
}
} else {
$result = _t('<a href="%s">%s</a> 無法在此版本的typecho下正常工作', $info['link'], $info['title']);
}
/** 設置高亮 */
$this->widget('Widget_Notice')->highlight('plugin-' . $pluginName);
if (isset($result) && is_string($result)) {
$this->widget('Widget_Notice')->set($result, NULL, 'notice');
} else {
$this->widget('Widget_Notice')->set(_t('插件已經被激活'), NULL, 'success');
}
$this->response->goBack();
}
示例2: execute
/**
* 執行函數
*
* @access public
* @return void
*/
public function execute()
{
/** 列出插件目錄 */
$pluginDirs = glob(__TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_PLUGIN_DIR__ . '/*');
$this->parameter->setDefault(array('activated' => NULL));
/** 獲取已啟用插件 */
$plugins = Typecho_Plugin::export();
$this->activatedPlugins = $plugins['activated'];
if (!empty($pluginDirs)) {
foreach ($pluginDirs as $pluginDir) {
if (is_dir($pluginDir)) {
/** 獲取插件名稱 */
$pluginName = basename($pluginDir);
/** 獲取插件主文件 */
$pluginFileName = $pluginDir . '/Plugin.php';
} else {
if (file_exists($pluginDir) && 'index.php' != basename($pluginDir)) {
$pluginFileName = $pluginDir;
$part = explode('.', basename($pluginDir));
if (2 == count($part) && 'php' == $part[1]) {
$pluginName = $part[0];
} else {
continue;
}
} else {
continue;
}
}
if (file_exists($pluginFileName)) {
$info = Typecho_Plugin::parseInfo($pluginFileName);
$info['name'] = $pluginName;
list($version, $build) = explode('/', Typecho_Common::VERSION);
$info['dependence'] = Typecho_Plugin::checkDependence($build, $info['dependence']);
/** 默認即插即用 */
$info['activated'] = true;
if ($info['activate'] || $info['deactivate'] || $info['config'] || $info['personalConfig']) {
$info['activated'] = isset($this->activatedPlugins[$pluginName]);
if (isset($this->activatedPlugins[$pluginName])) {
unset($this->activatedPlugins[$pluginName]);
}
}
if (!is_bool($this->parameter->activated) || $info['activated'] == $this->parameter->activated) {
$this->push($info);
}
}
}
}
}
示例3: install
public function install()
{
$version = $this->request->get('version');
$plugin = $this->request->get('plugin');
$require = $this->request->get('require');
$require === '*' and $require = '';
$pluginPath = __TYPECHO_ROOT_DIR__ . __TYPECHO_PLUGIN_DIR__ . '/' . $plugin . '/';
$pluginBackupPath = __TYPECHO_ROOT_DIR__ . __TYPECHO_PLUGIN_DIR__ . '/_' . $plugin . '/';
$activatedPlugins = Typecho_Plugin::export();
$existed = false;
$activated = false;
$tempFile = __TYPECHO_ROOT_DIR__ . __TYPECHO_PLUGIN_DIR__ . '/.app_store/' . $plugin . '-' . $version . '.zip';
try {
//檢查版本
list(, $buildVersion) = explode('/', Typecho_Common::VERSION);
if (!Typecho_Plugin::checkDependence($buildVersion, $require)) {
throw new VersionNotMatchException('版本不匹配,無法安裝.');
}
//查看插件是否已經存在
//查看插件是否已經激活
if (file_exists($pluginPath)) {
$existed = true;
if (file_exists($pluginPath . 'Plugin.php') and isset($activatedPlugins['activated'][$plugin])) {
$activated = true;
}
}
//插件如果存在,則需要備份下,後麵出錯可以進行回滾
if ($existed or $activated) {
file_exists($pluginBackupPath) and delete_files($pluginBackupPath) and @rmdir($pluginBackupPath);
@rename($pluginPath, $pluginBackupPath);
}
//下載新插件zip包
$archive = http_get($this->server . 'archive/' . $plugin . '/' . str_replace(' ', '%20', $version));
if (!$archive) {
throw new DownloadErrorException('下載插件包出錯!');
}
//保存文件
$fp = fopen($tempFile, 'w');
fwrite($fp, $archive);
fclose($fp);
//解壓縮文件
$unzip = new Unzip();
//創建文件夾
@mkdir($pluginPath);
$extractedFiles = $unzip->extract($tempFile, $pluginPath);
if ($extractedFiles === false) {
throw new UnzipErrorException('解壓縮出錯!');
}
//OK,解壓縮成功了
//刪除備份文件
file_exists($pluginBackupPath) and delete_files($pluginBackupPath) and @rmdir($pluginBackupPath);
//刪除臨時文件
@unlink($tempFile);
//報告首長, 安裝順利完成
echo json_encode(array('status' => true, 'activated' => $activated));
} catch (VersionNotMatchException $e) {
$e->responseJson();
} catch (DownloadErrorException $e) {
//如果存在備份包,則進行回滾
file_exists($pluginBackupPath) and @rename($pluginBackupPath, $pluginPath);
$e->responseJson();
} catch (UnzipErrorException $e) {
//清理解鎖壓縮的廢棄文件
file_exists($pluginPath) and delete_files($pluginPath) and @rmdir($pluginPath);
//如果存在備份包,則進行回滾
file_exists($pluginBackupPath) and @rename($pluginBackupPath, $pluginPath);
//刪除臨時文件
@unlink($tempFile);
$e->responseJson();
} catch (Exception $e) {
$error = new JsonableException($e->getMessage());
$error->responseJson();
}
}
示例4: execute
/**
* 執行函數
*
* @access public
* @return void
*/
public function execute()
{
/** 列出插件目錄 */
$pluginDirs = $this->getPlugins();
$this->parameter->setDefault(array('activated' => NULL));
/** 獲取已啟用插件 */
$plugins = Typecho_Plugin::export();
$this->activatedPlugins = $plugins['activated'];
if (!empty($pluginDirs)) {
foreach ($pluginDirs as $key => $pluginDir) {
$parts = $this->getPlugin($pluginDir, $key);
if (empty($parts)) {
continue;
}
list($pluginName, $pluginFileName) = $parts;
if (file_exists($pluginFileName)) {
$info = Typecho_Plugin::parseInfo($pluginFileName);
$info['name'] = $pluginName;
list($version, $build) = explode('/', Typecho_Common::VERSION);
$info['dependence'] = Typecho_Plugin::checkDependence($build, $info['dependence']);
/** 默認即插即用 */
$info['activated'] = true;
if ($info['activate'] || $info['deactivate'] || $info['config'] || $info['personalConfig']) {
$info['activated'] = isset($this->activatedPlugins[$pluginName]);
if (isset($this->activatedPlugins[$pluginName])) {
unset($this->activatedPlugins[$pluginName]);
}
}
if ($info['activated'] == $this->parameter->activated) {
$this->push($info);
}
}
}
}
}