Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * 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']);
     }
 }
Example #3
0
 /**
  * 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]);
     }
 }
Example #4
0
 /**
  * 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;
 }
Example #5
0
 /**
  * Delete action.
  *
  * @param string|null $id Menu id.
  * @return void Redirects to index.
  * @throws \Cake\Network\Exception\NotFoundException When record not found.
  */
 public function delete($id = null)
 {
     $this->request->allowMethod(['post', 'delete']);
     $controllerName = Inflector::singularize($this->name);
     $lowerController = mb_strtolower($controllerName);
     $record = $this->{$this->name}->get($id);
     $domain = Plugin::getPluginName($this->plugin);
     if ($this->{$this->name}->delete($record)) {
         $this->Flash->success(__d($domain, 'The {0} has been deleted.', $lowerController));
     } else {
         $this->Flash->error(__d($domain, 'The {0} could not be deleted. Please, try again.', $lowerController));
     }
     return $this->redirect(['action' => 'index']);
 }
Example #6
0
 /**
  * Entity constructor.
  *
  * @param array $properties
  * @param array $options
  */
 public function __construct(array $properties = [], array $options = [])
 {
     $Theme = Theme::getInstance();
     if (isset($properties['alias'])) {
         $name = UnionPlugin::aliasToName($properties['alias']);
         $this->_xmlPath = $Theme->getPath() . $name . DS . $Theme->getFileName();
     }
     if ($this->_xmlPath) {
         $xml = Xml::build($this->_xmlPath);
         if ($xml instanceof \SimpleXMLElement) {
             $this->_xmlAttr = $Theme->setAttributes($xml);
         }
     }
     parent::__construct($properties, $options);
 }
Example #7
0
<?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')]]]]);
Example #8
0
<?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')]]]]);
Example #9
0
 /**
  * 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;
 }
Example #10
0
 /**
  * Create theme thumb popup.
  *
  * @return null|string
  */
 public function thumb()
 {
     $plugin = Plugin::aliasToName($this->_theme->get('alias'));
     return $this->Html->image($plugin . '.' . $this->_prevView, ['alt' => $plugin, 'popup' => true, 'url' => $this->Url->assetUrl($plugin . '.' . $this->_thumb, ['pathPrefix' => Configure::read('App.imageBaseUrl')]), 'class' => 'img-thumbnail']);
 }
Example #11
0
 /**
  * Get migrations data from plugin migration folder.
  *
  * @return array
  */
 public function getMigrations()
 {
     $migrationPath = UnionPlugin::migrationPath($this->getName());
     return UnionPlugin::migrationData($migrationPath);
 }
Example #12
0
<?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
 * @author          Segrey Kalistratov <*****@*****.**>
 */
use Cake\Core\Configure;
use Union\Core\Lib\Plugin;
use Union\Core\Utility\Path;
//  Default plugins.
$plugins = ['Search', 'Union/Menus', 'Union/Community', 'Union/Extensions', 'Union/TinyMce', 'Union/Modules', 'Union/FileManager'];
$activatedTheme = Path::loadedFolder() . 'themes.json';
//  Check activated themes.
if (file_exists($activatedTheme)) {
    $jsonData = file_get_contents($activatedTheme);
    $themes = json_decode($jsonData, true);
    $plugins += $themes['activated'];
    if (isset($themes['activated'])) {
        Configure::write('Theme', $themes['activated']);
    }
}
Plugin::load($plugins);
Example #13
0
 /**
  * Delete theme folder.
  *
  * @param $themeName
  * @return bool
  */
 protected function _deleteTheme($themeName)
 {
     if (!CakePlugin::loaded($themeName)) {
         CakePlugin::load($themeName);
     }
     $path = Plugin::path($themeName);
     $Folder = new Folder($path);
     return $Folder->delete();
 }