Esempio n. 1
0
 /**
  * Returns the url of the compiled css file. The stylesheet will be
  * compiled automatically in case it doesn't exist yet.
  * 
  * @param	integer		$styleID
  * @param	boolean		$rtl
  * @return	string
  */
 public function getURL($styleID = null, $rtl = null)
 {
     // default values
     if ($styleID === null) {
         $styleID = StyleCacheBuilder::getInstance()->getData(array(), 'default');
     }
     if ($rtl === null) {
         $rtl = WCF::getLanguage()->get('wcf.global.pageDirection') == 'rtl';
     }
     // compile stylesheet if necessary
     if (!file_exists($this->getLocation($styleID, $rtl))) {
         $this->compile($styleID);
     }
     //return filename with appended caching parameter
     $filename = 'style/style-' . $styleID . '-' . $this->stylesheetID . ($rtl ? '-rtl' : '') . '.css';
     return WCF::getPath('cms') . $filename . '?m=' . filemtime(CMS_DIR . $filename);
 }
Esempio n. 2
0
 /**
  * Copies a style.
  * 
  * @return	array<string>
  */
 public function copy()
 {
     // get unique style name
     $sql = "SELECT\tstyleName\n\t\t\tFROM\twcf" . WCF_N . "_style\n\t\t\tWHERE\tstyleName LIKE ?\n\t\t\t\tAND styleID <> ?";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array($this->styleEditor->styleName . '%', $this->styleEditor->styleID));
     $numbers = array();
     $regEx = new Regex('\\((\\d+)\\)$');
     while ($row = $statement->fetchArray()) {
         $styleName = $row['styleName'];
         if ($regEx->match($styleName)) {
             $matches = $regEx->getMatches();
             // check if name matches the pattern 'styleName (x)'
             if ($styleName == $this->styleEditor->styleName . ' (' . $matches[1] . ')') {
                 $numbers[] = $matches[1];
             }
         }
     }
     $number = count($numbers) ? max($numbers) + 1 : 2;
     $styleName = $this->styleEditor->styleName . ' (' . $number . ')';
     // create the new style
     $newStyle = StyleEditor::create(array('styleName' => $styleName, 'templateGroupID' => $this->styleEditor->templateGroupID, 'isDisabled' => 1, 'styleDescription' => $this->styleEditor->styleDescription, 'styleVersion' => $this->styleEditor->styleVersion, 'styleDate' => $this->styleEditor->styleDate, 'copyright' => $this->styleEditor->copyright, 'license' => $this->styleEditor->license, 'authorName' => $this->styleEditor->authorName, 'authorURL' => $this->styleEditor->authorURL, 'imagePath' => $this->styleEditor->imagePath));
     // check if style description uses i18n
     if (preg_match('~^wcf.style.styleDescription\\d+$~', $newStyle->styleDescription)) {
         $styleDescription = 'wcf.style.styleDescription' . $newStyle->styleID;
         // copy language items
         $sql = "INSERT INTO\twcf" . WCF_N . "_language_item\n\t\t\t\t\t\t(languageID, languageItem, languageItemValue, languageItemOriginIsSystem, languageCategoryID, packageID)\n\t\t\t\tSELECT\t\tlanguageID, '" . $styleDescription . "', languageItemValue, 0, languageCategoryID, packageID\n\t\t\t\tFROM\t\twcf" . WCF_N . "_language_item\n\t\t\t\tWHERE\t\tlanguageItem = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array($newStyle->styleDescription));
         // update style description
         $styleEditor = new StyleEditor($newStyle);
         $styleEditor->update(array('styleDescription' => $styleDescription));
     }
     // copy style variables
     $sql = "INSERT INTO\twcf" . WCF_N . "_style_variable_value\n\t\t\t\t\t(styleID, variableID, variableValue)\n\t\t\tSELECT\t\t" . $newStyle->styleID . " AS styleID, value.variableID, value.variableValue\n\t\t\tFROM\t\twcf" . WCF_N . "_style_variable_value value\n\t\t\tWHERE\t\tvalue.styleID = ?";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array($this->styleEditor->styleID));
     // copy preview image
     if ($this->styleEditor->image) {
         // get extension
         $fileExtension = mb_substr($this->styleEditor->image, mb_strrpos($this->styleEditor->image, '.'));
         // copy existing preview image
         if (@copy(WCF_DIR . 'images/' . $this->styleEditor->image, WCF_DIR . 'images/stylePreview-' . $newStyle->styleID . $fileExtension)) {
             // bypass StyleEditor::update() to avoid scaling of already fitting image
             $sql = "UPDATE\twcf" . WCF_N . "_style\n\t\t\t\t\tSET\timage = ?\n\t\t\t\t\tWHERE\tstyleID = ?";
             $statement = WCF::getDB()->prepareStatement($sql);
             $statement->execute(array('stylePreview-' . $newStyle->styleID . $fileExtension, $newStyle->styleID));
         }
     }
     // copy images
     if ($this->styleEditor->imagePath && is_dir(WCF_DIR . $this->styleEditor->imagePath)) {
         $path = FileUtil::removeTrailingSlash($this->styleEditor->imagePath);
         $newPath = '';
         $i = 2;
         while (true) {
             $newPath = "{$path}-{$i}/";
             if (!file_exists(WCF_DIR . $newPath)) {
                 break;
             }
             $i++;
         }
         if (!FileUtil::makePath(WCF_DIR . $newPath)) {
             $newPath = '';
         }
         if ($newPath) {
             $src = FileUtil::addTrailingSlash(WCF_DIR . $this->styleEditor->imagePath);
             $dst = WCF_DIR . $newPath;
             $dir = opendir($src);
             while (($file = readdir($dir)) !== false) {
                 if ($file != '.' && $file != '..' && !is_dir($file)) {
                     @copy($src . $file, $dst . $file);
                 }
             }
             closedir($dir);
         }
         $sql = "UPDATE\twcf" . WCF_N . "_style\n\t\t\t\tSET\timagePath = ?\n\t\t\t\tWHERE\tstyleID = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array($newPath, $newStyle->styleID));
     }
     StyleCacheBuilder::getInstance()->reset();
     return array('redirectURL' => LinkHandler::getInstance()->getLink('StyleEdit', array('id' => $newStyle->styleID)));
 }
Esempio n. 3
0
 /**
  * @see	\wcf\data\IEditableCachedObject::resetCache()
  */
 public static function resetCache()
 {
     StyleCacheBuilder::getInstance()->reset();
 }
Esempio n. 4
0
 /**
  * @see	\wcf\system\exception\SystemException::init()
  */
 protected function init()
 {
     // load cache
     $this->cache = StyleCacheBuilder::getInstance()->getData();
 }
Esempio n. 5
0
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     parent::save();
     StyleCacheBuilder::getInstance()->reset();
     @unlink($this->source['tmp_name']);
     $this->saved();
     WCF::getTPL()->assign('success', true);
 }