当前位置: 首页>>代码示例>>PHP>>正文


PHP Typecho_Plugin::checkDependence方法代码示例

本文整理汇总了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();
 }
开发者ID:raindali,项目名称:express,代码行数:56,代码来源:Edit.php

示例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);
                 }
             }
         }
     }
 }
开发者ID:menmenweiwei,项目名称:blog,代码行数:54,代码来源:List.php

示例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();
     }
 }
开发者ID:xau0at,项目名称:AppStore,代码行数:74,代码来源:Action.php

示例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);
                 }
             }
         }
     }
 }
开发者ID:hongweipeng,项目名称:typecho,代码行数:41,代码来源:List.php


注:本文中的Typecho_Plugin::checkDependence方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。