Example #1
0
 /**
  * Apply customized static files to frontend
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function applyThemeCustomization(\Magento\Framework\Event\Observer $observer)
 {
     /** @var $themeFile \Magento\Core\Model\Theme\File */
     foreach ($this->_currentTheme->getCustomization()->getFiles() as $themeFile) {
         try {
             $service = $themeFile->getCustomizationService();
             if ($service instanceof \Magento\Framework\View\Design\Theme\Customization\FileAssetInterface) {
                 $identifier = $themeFile->getData('file_path');
                 $dirPath = \Magento\Framework\View\Design\Theme\Customization\Path::DIR_NAME . '/' . $this->_currentTheme->getId();
                 $asset = $this->_assetRepo->createArbitrary($identifier, $dirPath, \Magento\Framework\App\Filesystem::MEDIA_DIR, \Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
                 $this->_pageAssets->add($identifier, $asset);
             }
         } catch (\InvalidArgumentException $e) {
             $this->_logger->logException($e);
         }
     }
 }
 public static function update($values, $user)
 {
     $id = $values['id'];
     if ($id) {
         $q = new Doctrine_Query();
         $q = $q->select('t.*')->from('Theme t');
         $q = $q->addWhere('id = ?', array($id));
         if (!$user->getRole() == User::ADMIN) {
             $q = $q->addWhere('user_id = ?', array($user->getId()));
         }
         $theme = $q->fetchOne();
     } else {
         $theme = new Theme();
     }
     if ($theme) {
         $theme->setName($values['name']);
         $theme->setDescription($values['description']);
         if (!$theme->getUserId()) {
             $theme->setUserId($user->getId());
         }
         $file = $values['file'];
         if ($file) {
             $filename = $file->getOriginalName();
             $theme->setFileName($filename);
         }
         $theme->setApproved(false);
         $theme->save();
         $folderpath = $theme->getFolderPath();
         if (!is_dir($folderpath)) {
             mkdir($folderpath);
         }
         if ($file) {
             $filepath = $folderpath . $theme->getFileName();
             $file->save($filepath);
         }
         $screenshot = $values['screenshot'];
         if ($screenshot) {
             $screenshotpath = $folderpath . $theme->getId() . $screenshot->getOriginalName();
             $screenshot->save($screenshotpath);
             $smallThumb = new Thumbnail($screenshotpath);
             if ($smallThumb->getCurrentWidth() > 150 || $smallThumb->getCurrentHeight() > 150) {
                 $smallThumb->resize(150, 150);
             }
             $smallThumb->show(100, $folderpath . 'smallthumb.png');
             $bigThumb = new Thumbnail($screenshotpath);
             if ($bigThumb->getCurrentWidth() > 500 || $bigThumb->getCurrentHeight() > 500) {
                 $bigThumb->resize(500, 500);
             }
             $bigThumb->show(100, $folderpath . 'bigthumb.png');
             $screenshot = new Thumbnail($screenshotpath);
             $screenshot->show(100, $folderpath . 'screenshot.png');
             unlink($screenshotpath);
         }
         $outputs = array();
         if ($file) {
             exec(Tools::get('edje_list_path') . ' ' . $filepath, $outputs);
             $groups = array_splice($outputs, 4);
             $groups = array_keys(array_flip($groups));
             $name = substr($outputs[0], 6);
             if ($name) {
                 $theme->setName($name);
             }
             $author = substr($outputs[1], 8);
             if ($author) {
                 $theme->setAuthor($author);
             }
             $license = substr($outputs[2], 9);
             $theme->setLicense($license);
             $version = substr($outputs[3], 9);
             $theme->setVersion($version);
             $theme->save();
             $theme->clearThemeGroups();
             foreach ($groups as $group) {
                 $theme->addThemeGroup($group);
             }
         }
         return $theme;
     }
     return null;
 }
 /**
  * Clear playlists themes definitions on unassign action.
  *
  * @param Theme $theme
  * @param array $themePlaylists
  *
  * @return bool
  */
 public function removeThemeFromPlaylists($theme, $themePlaylists)
 {
     if (empty($themePlaylists)) {
         return false;
     }
     $newThemePlaylists = $this->buildNewThemePlaylists($themePlaylists);
     foreach ($newThemePlaylists as $playlistName => $themePlaylist) {
         $playlist = $this->em->getRepository('Newscoop\\Entity\\Playlist')->getPlaylistByTitle($playlistName)->getOneOrNullResult();
         if (!$playlist) {
             continue;
         }
         $themes = $playlist->getThemes();
         unset($themes[$theme->getId()]);
         $playlist->setThemes($themes);
     }
     $this->em->flush();
     return true;
 }
Example #4
0
 /**
  * bool update(Theme $theme)
  *
  * Update a theme in the theme table.
  *
  * @param Theme $theme theme to insert
  * @return boolean returns false, if error occurs
  * @access public
  */
 function update($theme)
 {
     if (!$theme instanceof Theme) {
         $this->_error = "Argument is an inappropriate object.";
         return false;
     }
     if ($this->existCssFile($theme->getCssFile(), $theme->getId())) {
         $this->_isError = true;
         $this->_error = "File is already in use.";
         return false;
     }
     if (!$this->_writeCssFile($theme->getCssFile(), $theme->getCssRules())) {
         return false;
     }
     $sql = "UPDATE " . $this->_table . " SET ";
     $sql .= "theme_name='" . urlencode($theme->getName()) . "', ";
     $sql .= "css_file='" . urlencode($theme->getCssFile()) . "'";
     $sql .= " WHERE id_theme=" . $theme->getId();
     return $this->exec($sql);
 }
Example #5
0
    exit;
}
/**
 * Checking permissions
 */
require_once "../auth/login_check.php";
loginCheck(OPEN_PROFILE_ADMINISTRATOR);
/**
 * Validate data
 */
$errorLocation = "../admin/theme_edit_form.php?key=" . intval($_POST["id_theme"]);
// controlling var
require_once "../model/Query/Theme.php";
$theme = new Theme();
$theme->setId($_POST["id_theme"]);
$_POST["id_theme"] = $theme->getId();
require_once "../admin/theme_validate_post.php";
/**
 * Destroy form values and errors
 */
Form::unsetSession();
/**
 * Update theme
 */
$themeQ = new Query_Theme();
if ($themeQ->existCssFile($theme->getCssFile(), $theme->getId())) {
    FlashMsg:
    add(sprintf(_("Filename of theme, %s, already exists. The changes have no effect."), $theme->getName()));
} else {
    $themeQ->update($theme);
    FlashMsg::add(sprintf(_("Theme, %s, has been updated."), $theme->getName()));