コード例 #1
0
ファイル: HookRender.php プロジェクト: zwq/unpei
 protected function getHooks()
 {
     $plugins = Plugins::model()->findAllByAttributes(array('enable' => 1));
     if (!$plugins) {
         return;
     }
     foreach ($plugins as $plugin) {
         foreach (unserialize($plugin->hooks) as $pos => $hook) {
             $this->hooks[$pos][] = array('identify' => $plugin->identify, 'path' => $plugin->path, 'hook' => $hook);
         }
     }
     return TRUE;
 }
コード例 #2
0
ファイル: PluginController.php プロジェクト: lhfcainiao/basic
 public function actionIndex()
 {
     if (!$_GET['id']) {
         $this->redirect(Yii::app()->homeUrl);
     }
     $id = $_GET['id'];
     $plugin = Plugins::model()->findbyAttributes(array('identify' => $id, 'enable' => 1));
     if (!$plugin) {
         $this->render('miss', array('name' => $id));
         exit;
     }
     if (!isset($_GET['action'])) {
         $action = strtolower($plugin->identify);
     } else {
         $action = strtolower($_GET['action']);
     }
     $class = $this->_loadPlugin($plugin);
     $method = 'action' . $action;
     if (method_exists($class, $method)) {
         $class->{$method}();
         Yii:
         app()->end();
     }
     $actions = array_change_key_case($class->Actions(), CASE_LOWER);
     if ($action) {
         if (isset($actions[$action])) {
             $actionClass = $this->_loadAction($actions[$action], $plugin);
             if ($actionClass) {
                 $actionClass->Owner($class);
                 $actionClass->run();
                 Yii::app()->end();
             }
         }
     }
     $this->redirect(Yii::app()->homeUrl);
 }
コード例 #3
0
ファイル: Plugins.php プロジェクト: Gnafu/wiz
 public static function processArchive($dir, $file)
 {
     $_error = 'ok';
     $pluginName = substr($file, 0, -4);
     $destDir = Yii::getPathOfAlias('webroot') . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . $pluginName;
     $model = Plugins::model()->findByPk($pluginName);
     //remove plugin entry
     if ($model) {
         $model->delete();
     }
     //remove dir
     if (file_exists($destDir)) {
         Plugins::rrmdir($destDir);
     }
     //remove plugin table
     $connection = Yii::app()->db;
     try {
         $command = $connection->createCommand('DROP TABLE ' . $pluginName . ';')->execute();
     } catch (Exception $e) {
         $_error = $e;
     }
     $zip = zip_open($dir . $file);
     $dir = Plugins::extractZip($pluginName, $dir, $file, $destDir);
     if ($dir) {
         $version = $description = $changelog = $sql = '';
         //Open images directory
         $d = opendir($dir);
         //List files in images directory
         while (($file = readdir($d)) !== false) {
             if (strpos($file, '.info') !== false) {
                 $_in_file = fopen($dir . $file, 'r');
                 while ($line = fgets($_in_file)) {
                     if ($line === FALSE) {
                         //ERROR
                         echo 'error';
                         return;
                     }
                     if (preg_match('/^\\[[a-zA-Z0-9]{1,}\\]/', $line, $matches)) {
                         $section = str_replace(array('[', ']'), array('', ''), $matches[0]);
                         continue;
                     }
                     if ($section == 'version') {
                         $version .= $line;
                     }
                     if ($section == 'description') {
                         $description .= $line;
                     }
                     if ($section == 'changelog') {
                         $changelog .= $line;
                     }
                 }
                 //$version = file_get_contents($dir.$file);
                 //$description = '';
                 continue;
             }
             if (strpos($file, '.sql') !== false) {
                 $sql = file_get_contents($dir . $file);
                 continue;
             }
         }
         closedir($d);
         if ($sql) {
             $connection = Yii::app()->db;
             try {
                 $command = $connection->createCommand($sql)->execute();
             } catch (Exception $e) {
                 $_error = $e;
             }
         }
         $plugin = new Plugins();
         $plugin->name = 'Foo';
         $plugin->username = Yii::app()->user->id;
         $plugin->timestamp = date(Yii::app()->params['dateTimeFormatDB']);
         $plugin->version = $version;
         $plugin->description = $description;
         $plugin->changelog = $changelog;
         $plugin->priority = 0;
         $plugin->users = '*';
         $plugin->status = substr($_error, 0, 4000);
         //truncate to max length
         $plugin->enable = true;
         if ($plugin->save()) {
             return Yii::app()->createUrl($pluginName . '/' . $pluginName . '/index', array());
         }
     }
     return;
 }
コード例 #4
0
ファイル: ExtraController.php プロジェクト: Gnafu/wiz
 public function actionIndex()
 {
     $plugins = Plugins::model()->findAllByAttributes(array('status' => 'ok'));
     $this->render('index', array('plugins' => $plugins));
 }