Ejemplo n.º 1
0
 /**
  * テーマをアップロードして適用する
  */
 public function admin_add()
 {
     $this->pageTitle = 'テーマアップロード';
     $this->subMenuElements = array('themes');
     if ($this->request->data) {
         if (empty($this->request->data['Theme']['file']['tmp_name'])) {
             $this->setMessage('ファイルのアップロードに失敗しました。', true);
         } else {
             $name = $this->request->data['Theme']['file']['name'];
             move_uploaded_file($this->request->data['Theme']['file']['tmp_name'], TMP . $name);
             App::uses('BcZip', 'Lib');
             $BcZip = new BcZip();
             if ($BcZip->extract(TMP . $name, BASER_THEMES)) {
                 $theme = $BcZip->topArchiveName;
                 unlink(TMP . $name);
                 $this->_applyTheme($theme);
                 $this->redirect(array('action' => 'index'));
             } else {
                 $msg = 'アップロードしたZIPファイルの展開に失敗しました。';
                 $msg .= '<br />' . $BcZip->error;
                 $this->setMessage($msg, true);
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * プラグインをアップロードしてインストールする
  *
  * @return void
  */
 public function admin_add()
 {
     $this->pageTitle = 'プラグインアップロード';
     $this->subMenuElements = array('plugins');
     //データなし
     if (empty($this->request->data)) {
         return;
     }
     //アップロード失敗
     if (empty($this->request->data['Plugin']['file']['tmp_name'])) {
         $this->setMessage('ファイルのアップロードに失敗しました。', true);
         return;
     }
     $zippedName = $this->request->data['Plugin']['file']['name'];
     move_uploaded_file($this->request->data['Plugin']['file']['tmp_name'], TMP . $zippedName);
     App::uses('BcZip', 'Lib');
     $BcZip = new BcZip();
     if (!$BcZip->extract(TMP . $zippedName, APP . 'Plugin' . DS)) {
         $msg = 'アップロードしたZIPファイルの展開に失敗しました。';
         $msg .= '<br />' . $BcZip->error;
         $this->setMessage($msg, true);
         $this->redirect(array('action' => 'add'));
         return;
     }
     $plugin = $BcZip->topArchiveName;
     // 解凍したプラグインフォルダがキャメルケースでない場合にキャメルケースに変換
     $plugin = preg_replace('/^\\s*?(creating|inflating):\\s*' . preg_quote(APP . 'Plugin' . DS, '/') . '/', '', $plugin);
     $plugin = explode(DS, $plugin);
     $plugin = $plugin[0];
     $srcPluginPath = APP . 'Plugin' . DS . $plugin;
     $Folder = new Folder();
     $Folder->chmod($srcPluginPath, 0777);
     $tgtPluginPath = APP . 'Plugin' . DS . Inflector::camelize($plugin);
     if ($srcPluginPath != $tgtPluginPath) {
         $Folder->move(array('to' => $tgtPluginPath, 'from' => $srcPluginPath, 'mode' => 0777));
     }
     unlink(TMP . $zippedName);
     // プラグインをインストール
     if ($this->BcManager->installPlugin($plugin)) {
         clearAllCache();
         $this->setMessage('新規プラグイン「' . $plugin . '」を baserCMS に登録しました。', false, true);
         $this->Plugin->addFavoriteAdminLink($plugin, $this->BcAuth->user());
         $this->redirect(array('action' => 'index'));
     } else {
         $this->setMessage('プラグインに問題がある為インストールを完了できません。プラグインの開発者に確認してください。', true);
     }
 }