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);
}
}