Ejemplo n.º 1
0
 /**
  * Updates/adds whole theme content, generating static files and inserting theme content in DB.
  *
  * @param integer $id
  */
 public function processTheme($id)
 {
     $theme = $this->getThemeById($id);
     $themeName = $theme->getName();
     if (!file_exists($this->getRootDir($themeName))) {
         throw new LogicException("Can't find theme dir for `" . $themeName . "`!");
     }
     $themeStaticDir = $this->getStaticDir($themeName);
     $themeRootDir = $this->getRootDir($themeName);
     $mobileRootDir = $this->getRootDir($themeName, true);
     // deleting DB entries and files
     $this->unlinkTheme($theme->getId());
     mkdir($themeStaticDir);
     // copy all static files
     UTIL_File::copyDir($themeRootDir, $this->getStaticDir($themeName));
     $files = UTIL_File::findFiles($themeStaticDir, array('psd', 'html'));
     foreach ($files as $file) {
         unlink($file);
     }
     $themeControls = array();
     // copy main css file
     if (file_exists($themeRootDir . self::CSS_FILE_NAME)) {
         $controlsContent = file_get_contents($themeRootDir . self::CSS_FILE_NAME);
         $themeControls = $this->getThemeControls($controlsContent);
         $mobileControls = array();
         if (file_exists($mobileRootDir . self::CSS_FILE_NAME)) {
             $controlsContent .= PHP_EOL . file_get_contents($mobileRootDir . self::CSS_FILE_NAME);
             $mobileControls = $this->getThemeControls(file_get_contents($mobileRootDir . self::CSS_FILE_NAME));
             foreach ($mobileControls as $key => $val) {
                 $mobileControls[$key]['mobile'] = true;
             }
         }
         $themeControls = array_merge($mobileControls, $themeControls);
         // adding theme controls in DB
         if (!empty($themeControls)) {
             foreach ($themeControls as $value) {
                 $themeControl = new BOL_ThemeControl();
                 $themeControl->setAttribute($value['attrName']);
                 $themeControl->setKey($value['key']);
                 $themeControl->setSection($value['section']);
                 $themeControl->setSelector($value['selector']);
                 $themeControl->setThemeId($theme->getId());
                 $themeControl->setDefaultValue($value['defaultValue']);
                 $themeControl->setType($value['type']);
                 $themeControl->setLabel($value['label']);
                 if (isset($value['description'])) {
                     $themeControl->setDescription(trim($value['description']));
                 }
                 $themeControl->setMobile(!empty($value['mobile']));
                 $this->themeControlDao->save($themeControl);
             }
         }
     }
     // decorators
     if (file_exists($this->getDecoratorsDir($themeName))) {
         $files = UTIL_File::findFiles($this->getDecoratorsDir($themeName), array('html'), 0);
         foreach ($files as $value) {
             $decoratorEntry = new BOL_ThemeContent();
             $decoratorEntry->setThemeId($theme->getId());
             $decoratorEntry->setType(BOL_ThemeContentDao::VALUE_TYPE_ENUM_DECORATOR);
             $decoratorEntry->setValue(UTIL_File::stripExtension(basename($value)));
             $this->themeContentDao->save($decoratorEntry);
         }
     }
     // master pages
     if (file_exists($this->getMasterPagesDir($themeName))) {
         $files = UTIL_File::findFiles($this->getMasterPagesDir($themeName), array('html'), 0);
         foreach ($files as $value) {
             $masterPageEntry = new BOL_ThemeContent();
             $masterPageEntry->setThemeId($theme->getId());
             $masterPageEntry->setType(BOL_ThemeContentDao::VALUE_TYPE_ENUM_MASTER_PAGE);
             $masterPageEntry->setValue(UTIL_File::stripExtension(basename($value)));
             $this->themeContentDao->save($masterPageEntry);
         }
     }
     if (file_exists($this->getMasterPagesDir($themeName, true))) {
         $files = UTIL_File::findFiles($this->getMasterPagesDir($themeName, true), array('html'), 0);
         foreach ($files as $value) {
             $masterPageEntry = new BOL_ThemeContent();
             $masterPageEntry->setThemeId($theme->getId());
             $masterPageEntry->setType(BOL_ThemeContentDao::VALUE_TYPE_ENUM_MOBILE_MASTER_PAGE);
             $masterPageEntry->setValue(UTIL_File::stripExtension(basename($value)));
             $this->themeContentDao->save($masterPageEntry);
         }
     }
     // xml master page assignes
     $xml = simplexml_load_file($this->getRootDir($themeName) . self::MANIFEST_FILE);
     $masterPages = (array) $xml->masterPages;
     foreach ($masterPages as $key => $value) {
         $masterPageLinkEntry = new BOL_ThemeMasterPage();
         $masterPageLinkEntry->setThemeId($theme->getId());
         $masterPageLinkEntry->setDocumentKey(trim($key));
         $masterPageLinkEntry->setMasterPage(trim($value));
         $this->themeMasterPageDao->save($masterPageLinkEntry);
     }
 }
Ejemplo n.º 2
0
 /**
  * Updates/adds whole theme content, generating static files and inserting theme content in DB.
  *
  * @param int $id
  */
 public function processTheme($id)
 {
     $theme = $this->getThemeById($id);
     if (empty($theme)) {
         throw new InvalidArgumentException("Can't process theme with id `" . $id . "`, not found!");
     }
     $themeName = $theme->getKey();
     if (!file_exists($this->getRootDir($themeName))) {
         throw new LogicException("Can't find theme dir for `" . $themeName . "`!");
     }
     $themeStaticDir = $this->getStaticDir($themeName);
     $themeRootDir = $this->getRootDir($themeName);
     $mobileRootDir = $this->getRootDir($themeName, true);
     // deleting DB entries and files
     $this->unlinkTheme($theme->getId());
     mkdir($themeStaticDir);
     // copy all static files
     UTIL_File::copyDir($themeRootDir, $this->getStaticDir($themeName), function ($itemPath) {
         if (substr($itemPath, 0, 1) == ".") {
             return false;
         }
         if (is_dir($itemPath)) {
             return true;
         }
         $fileExtension = strtolower(UTIL_File::getExtension(basename($itemPath)));
         if (in_array($fileExtension, array("psd", "html"))) {
             return false;
         }
         return true;
     });
     $themeControls = array();
     // copy main css file
     if (file_exists($themeRootDir . self::CSS_FILE_NAME)) {
         $controlsContent = file_get_contents($themeRootDir . self::CSS_FILE_NAME);
         $themeControls = $this->getThemeControls($controlsContent);
         $mobileControls = array();
         if (file_exists($mobileRootDir . self::CSS_FILE_NAME)) {
             $controlsContent .= PHP_EOL . file_get_contents($mobileRootDir . self::CSS_FILE_NAME);
             $mobileControls = $this->getThemeControls(file_get_contents($mobileRootDir . self::CSS_FILE_NAME));
             foreach ($mobileControls as $key => $val) {
                 $mobileControls[$key]["mobile"] = true;
             }
         }
         $themeControls = array_merge($mobileControls, $themeControls);
         // adding theme controls in DB
         if (!empty($themeControls)) {
             foreach ($themeControls as $value) {
                 $themeControl = new BOL_ThemeControl();
                 $themeControl->setAttribute($value["attrName"]);
                 $themeControl->setKey($value["key"]);
                 $themeControl->setSection($value["section"]);
                 $themeControl->setSelector($value["selector"]);
                 $themeControl->setThemeId($theme->getId());
                 $themeControl->setDefaultValue($value["defaultValue"]);
                 $themeControl->setType($value["type"]);
                 $themeControl->setLabel($value["label"]);
                 if (isset($value["description"])) {
                     $themeControl->setDescription(trim($value["description"]));
                 }
                 $themeControl->setMobile(!empty($value["mobile"]));
                 $this->themeControlDao->save($themeControl);
             }
         }
     }
     // decorators
     if (file_exists($this->getDecoratorsDir($themeName))) {
         $files = UTIL_File::findFiles($this->getDecoratorsDir($themeName), array("html"), 0);
         foreach ($files as $value) {
             $decoratorEntry = new BOL_ThemeContent();
             $decoratorEntry->setThemeId($theme->getId());
             $decoratorEntry->setType(BOL_ThemeContentDao::VALUE_TYPE_ENUM_DECORATOR);
             $decoratorEntry->setValue(UTIL_File::stripExtension(basename($value)));
             $this->themeContentDao->save($decoratorEntry);
         }
     }
     // master pages
     if (file_exists($this->getMasterPagesDir($themeName))) {
         $files = UTIL_File::findFiles($this->getMasterPagesDir($themeName), array("html"), 0);
         foreach ($files as $value) {
             $masterPageEntry = new BOL_ThemeContent();
             $masterPageEntry->setThemeId($theme->getId());
             $masterPageEntry->setType(BOL_ThemeContentDao::VALUE_TYPE_ENUM_MASTER_PAGE);
             $masterPageEntry->setValue(UTIL_File::stripExtension(basename($value)));
             $this->themeContentDao->save($masterPageEntry);
         }
     }
     if (file_exists($this->getMasterPagesDir($themeName, true))) {
         $files = UTIL_File::findFiles($this->getMasterPagesDir($themeName, true), array("html"), 0);
         foreach ($files as $value) {
             $masterPageEntry = new BOL_ThemeContent();
             $masterPageEntry->setThemeId($theme->getId());
             $masterPageEntry->setType(BOL_ThemeContentDao::VALUE_TYPE_ENUM_MOBILE_MASTER_PAGE);
             $masterPageEntry->setValue(UTIL_File::stripExtension(basename($value)));
             $this->themeContentDao->save($masterPageEntry);
         }
     }
     // xml master page assignes
     $xml = simplexml_load_file($this->getRootDir($themeName) . self::THEME_XML);
     $masterPages = (array) $xml->masterPages;
     foreach ($masterPages as $key => $value) {
         $masterPageLinkEntry = new BOL_ThemeMasterPage();
         $masterPageLinkEntry->setThemeId($theme->getId());
         $masterPageLinkEntry->setDocumentKey(trim($key));
         $masterPageLinkEntry->setMasterPage(trim($value));
         $this->themeMasterPageDao->save($masterPageLinkEntry);
     }
 }