Ejemplo n.º 1
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']);
     }
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
0
 /**
  * Path to xml theme file.
  *
  * @return string
  */
 public function formPath()
 {
     $plugin = Plugin::aliasToName($this->_theme->get('alias'));
     if (!CakePlugin::loaded($plugin)) {
         CakePlugin::load($plugin);
     }
     $path = CakePlugin::path($plugin) . Theme::getInstance()->getFileName();
     return $path;
 }