/** * Upload theme. * * @return \Cake\Network\Response|void * @throws \Exception */ public function upload() { $themeEntity = $this->Themes->newEntity(); if ($this->request->is(['post', 'put'])) { $Installer = new ThemeInstaller($this->request); $isValidate = $Installer->validate()->isValid(); if ($isValidate) { if ($Installer->open() && $Installer->extract()->getResult()) { $result = $Installer->getOutput(); $alias = Plugin::nameToAlias($result['name']); $themeEntity = $this->Themes->patchEntity($themeEntity, ['params' => [], 'name' => $result['name'], 'alias' => $alias, 'client_id' => ThemeExtension::getInstance()->getClientIdByAttr($result['data'])]); if ($this->Themes->save($themeEntity)) { $this->Flash->success($result['message']); } else { Event::dispatch('Controller.Themes.failSave', $this, ['theme' => $themeEntity]); $this->Flash->error(__d('extensions', 'The template was not saved, try again')); } } else { $this->Flash->success(__d('extensions', 'Can not install theme.')); } } else { $Installer->setFlashErrors($this->Flash); } return $this->redirect(['action' => 'index']); } }
/** * Extract valid theme archive. * * @return $this|void */ public function extract() { $Zip = $this->zip(); $Theme = ThemeExtension::getInstance(); $name = $this->_attr->get('name'); $path = $Theme->getPath() . $name . DS; $alias = Plugin::nameToAlias($name); $isExits = $this->table()->findByAlias($alias)->first(); if (is_dir($path) && $isExits !== null) { $this->_setOutput(__d('extensions', 'The theme «{0}» already exits.', sprintf('<strong>%s</strong>', $name))); } new Folder($path); $tmp = $this->_request->data($this->_inputName); $Zip->open($tmp); $Zip->extractTo($path); if (!empty($this->_rootPath[$tmp])) { $old = $path . DS . $this->_rootPath[$tmp]; $new = $path; $Folder = new Folder($old); $Folder->move($new); } $this->_setResult(true); $this->_setOutput(__d('extensions', 'The theme «{0}» has bin successful uploaded.', sprintf('<strong>%s</strong>', $name)), true); return $this; }
/** * Configuration plugin action. * * @param null $plugin */ public function config($plugin = null) { $plugin = UnionPlugin::aliasToName($plugin); $alias = UnionPlugin::nameToAlias($plugin); $pluginName = UnionPlugin::getFullName($plugin); $isLoaded = CakePlugin::loaded($plugin); if ($isLoaded) { $configs = $this->Plugins->find()->where(['alias' => $alias])->first(); if (!$configs) { $configs = $this->Plugins->newEntity(['params' => [], 'alias' => $alias, 'name' => $pluginName]); } if ($this->request->is(['post', 'put'])) { $configs = $this->Plugins->patchEntity($configs, $this->request->data); if ($result = $this->Plugins->save($configs)) { $this->Flash->success(__d('extensions', 'The settings has been saved.')); return $this->Union->setRedirect(['apply' => ['action' => 'config', $result->alias]]); } else { $this->Flash->error(__d('extensions', 'The settings could not be saved. Please, try again.')); } } Event::dispatch($plugin . '.Config.Admin.Controller', $this); $this->set('configs', $configs); $this->viewBuilder()->templatePath('Admin/Plugin'); $this->render($plugin . '.config'); } else { throw new MissingPluginException(['plugin' => $plugin]); } }
/** * Array list skip plugin by plugin name from configuration. * * @return array */ public function skipPlgForAdminIndex() { $plugins = []; $skipPlugins = ['Union/Core', 'Union/TinyMce']; foreach ($skipPlugins as $skipPlugin) { $plugins[] = Plugin::nameToAlias($skipPlugin); } return $plugins; }
<?php /** * This is a simple content management system based on CakePHP. * * @version 1.0.x * @copyright Copyright (C) by cool-code.ru * @license http://www.opensource.org/licenses/mit-license.php MIT License * @coder Segrey Kalistratov <*****@*****.**> */ use Union\Core\Lib\Nav; use Union\Core\Lib\Plugin; // Global menus navigation. Nav::add('sidebar', 'system', ['title' => __d('union', 'System'), 'weight' => 0, 'icon' => 'home', 'children' => ['general_settings' => ['title' => __d('union', 'General settings'), 'weight' => 0, 'url' => ['plugin' => 'Union/Extensions', 'controller' => 'Plugins', 'action' => 'config', Plugin::nameToAlias('Union/Core')]]]]);
<?php /** * This is a simple content management system based on CakePHP. * * @version 1.0.x * @copyright Copyright (C) by cool-code.ru * @license http://www.opensource.org/licenses/mit-license.php MIT License * @coder Segrey Kalistratov <*****@*****.**> */ use Union\Core\Lib\Nav; use Union\Core\Lib\Plugin; // Global menus navigation. Nav::add('sidebar', 'users', ['title' => __d('community', 'Users'), 'icon' => 'group', 'weight' => 10, 'children' => ['roles' => ['title' => __d('community', 'Roles'), 'weight' => 0, 'url' => ['plugin' => 'Union/Community', 'controller' => 'Roles', 'action' => 'index']], 'users' => ['title' => __d('community', 'Users'), 'weight' => 0, 'url' => ['plugin' => 'Union/Community', 'controller' => 'Users', 'action' => 'index']], 'settings' => ['title' => __d('community', 'Settings'), 'weight' => 0, 'icon' => 'cog', 'url' => ['plugin' => 'Union/Extensions', 'controller' => 'Plugins', 'action' => 'config', Plugin::nameToAlias('Union/Community')]]]]);
/** * Write migration version in database. * * @param AbstractMigration $migrationObj * @return bool|string|void */ protected function _execute(AbstractMigration $migrationObj) { $version = $migrationObj->getVersion(); $sqlInsert = sprintf('INSERT INTO %s (' . 'version' . ') VALUES (' . '\'%s\'' . ');', $this->_schemaTableName, $version); $this->_adapter->query($sqlInsert); $sqlCheck = sprintf('SELECT version FROM %s WHERE version=\'%s\'', $this->_schemaTableName, $version); $versionResult = $this->_adapter->fetchRow($sqlCheck); $pluginAlias = UnionPlugin::nameToAlias($this->_plugin); $pluginName = UnionPlugin::getFullName($this->_plugin); if (!empty($versionResult)) { return __d('union', 'The version «{0}» of plugin «{1}» has bin success migrated.', sprintf('<strong>%s</strong>', $version), sprintf('<strong>%s</strong>', __d($pluginAlias, $pluginName))); } return false; }