Example #1
0
 /**
  * Returns an instance of class (singleton pattern implementation).
  *
  * @return BOL_ThemeControlDao
  */
 public static function getInstance()
 {
     if (self::$classInstance === null) {
         self::$classInstance = new self();
     }
     return self::$classInstance;
 }
Example #2
0
 /**
  *
  * @param integer $themeId
  */
 public function updateCustomCssFile($themeId)
 {
     $theme = $this->themeDao->findById($themeId);
     if ($theme->getCustomCssFileName() !== null) {
         $oldCssFilePath = $this->getUserfileImagesDir() . $theme->getCustomCssFileName();
         $oldMobileCssFilePath = $this->getUserfileImagesDir() . 'mobile_' . $theme->getCustomCssFileName();
         if (OW::getStorage()->fileExists($oldCssFilePath)) {
             OW::getStorage()->removeFile($oldCssFilePath);
         }
         if (OW::getStorage()->fileExists($oldMobileCssFilePath)) {
             OW::getStorage()->removeFile($oldMobileCssFilePath);
         }
     }
     if ($theme === null) {
         throw new InvalidArgumentException("Can't find theme `" . $themeId . "` !");
     }
     $controls = $this->themeControlDao->findThemeControls($theme->getId());
     if (!$this->themeControlValueDao->findByThemeId($themeId) && !$theme->getCustomCss()) {
         $theme->setCustomCssFileName(null);
         $this->themeDao->save($theme);
         return;
     }
     $cssString = '';
     $mobileCssString = '';
     foreach ($controls as $control) {
         if ($control['value'] !== null && trim($control['value']) !== 'default') {
             $controlString = $control['selector'] . '{' . $control['attribute'] . ':' . $control['value'] . '}' . PHP_EOL;
             if ((bool) $control['mobile']) {
                 $mobileCssString .= $controlString;
             } else {
                 $cssString .= $controlString;
             }
         }
     }
     if ($theme->getCustomCss() !== null && strlen(trim($theme->getCustomCss())) > 0) {
         $cssString .= trim($theme->getCustomCss());
     }
     if ($theme->getMobileCustomCss() !== null && strlen(trim($theme->getCustomCss())) > 0) {
         $mobileCssString .= trim($theme->getMobileCustomCss());
     }
     $newCssFileName = uniqid($theme->getName()) . '.css';
     $theme->setCustomCssFileName($newCssFileName);
     $this->themeDao->save($theme);
     $newCssFilePath = $this->getUserfileImagesDir() . $newCssFileName;
     $tempCssFilePath = $this->getUserfileImagesDir() . 'temp.css';
     file_put_contents($tempCssFilePath, $cssString);
     OW::getStorage()->copyFile($tempCssFilePath, $newCssFilePath);
     unlink($tempCssFilePath);
     $tempCssFilePath = $this->getUserfileImagesDir() . 'tempmobile.css';
     $newCssFileName = 'mobile_' . $newCssFileName;
     $newCssFilePath = $this->getUserfileImagesDir() . $newCssFileName;
     file_put_contents($tempCssFilePath, $mobileCssString);
     OW::getStorage()->copyFile($tempCssFilePath, $newCssFilePath);
     unlink($tempCssFilePath);
     OW::getEventManager()->trigger(new OW_Event('base.update_custom_css_file', array('name' => $theme->getName())));
 }