/** * Depending on if we have customized the file, return the URL * @param $cssFile * @return string */ public function getCssUrl($cssFile) { // Just in case someone passed the .css as part of the $cssFile if (substr($cssFile, strlen($cssFile) - 4, 4) == ".css") { $cssFile = substr($cssFile, 0, -4); } // new install? if (!is_array(Yii::app()->theme->config->activecss)) { return parent::getBaseUrl() . "/css/" . $cssFile . ".css"; } $arrActiveCss = Yii::app()->theme->config->activecss; if ($this->hasAdminForm(Yii::app()->theme->name)) { if (in_array($cssFile, $arrActiveCss)) { if ($cssFile !== 'custom') { return parent::getBaseUrl() . "/css/" . $cssFile . ".css"; } else { return str_replace("http:", "", _xls_custom_css_folder()) . "_customcss/" . Yii::app()->theme->name . "/" . $cssFile . ".css"; } } } else { return parent::getBaseUrl() . "/css/" . $cssFile . ".css"; } }
/** * Download a new version of a template and trash the old one */ protected function actionUpgrade($strTheme) { /* * Steps for updating template create trash folder if doesn't exist rename old folder to trashtimestamp i.e. portland becomes 201307150916-trash-portland move to /themes/trash download new template and unzip if we have modified old custom.css copy /themes/trash/201307150916-trash-portland/css/custom.css to new /themes/portland/css/custom.css (since it's always blank) */ $arrThemes = $this->GalleryThemes; $realName = $arrThemes[$strTheme]['title']; //Make a copy of our current theme first $strCopyName = $this->copyTheme($realName); $mixResult = $this->trashTheme($realName); if ($mixResult === false) { Yii::app()->user->setFlash('error', Yii::t('admin', 'The {file} theme could not be updated because the old copy could not be deleted.', array('{file}' => "<strong>" . $arrThemes[$strTheme]['name'] . "</strong>"))); $this->redirect($this->createUrl("theme/gallery")); } //Now that the old version is in the trash, we can grab the new version normally $arrThemes = $this->GalleryThemes; $blnExtract = $this->downloadTheme($arrThemes, $strTheme); if ($blnExtract) { //New copy downloaded and extracted. Copy any custom.css and site/index.php $d = YiiBase::getPathOfAlias('webroot') . "/themes"; $strCssPath = _xls_custom_css_folder(true) . "_customcss/" . $realName; @mkdir($strCssPath, 0777, true); //We only want to copy custom.css to the new custom folder if one doesn't already exist there if (!file_exists($strCssPath . "/css/custom.css")) { @copy($mixResult . "/css/custom.css", $strCssPath . "/css/custom.css"); } @copy($mixResult . "/views/site/index.php", $d . "/" . $realName . "/views/site/index.php"); Yii::app()->user->setFlash('success', Yii::t('admin', 'The {file} theme was updated to the latest version at {time}. Any custom.css and site/index.php file changes were preserved. The old theme was renamed to {oldfile} and is still in your gallery. You may move it to the trash if no longer needed.', array('{file}' => "<strong>" . $arrThemes[$strTheme]['name'] . "</strong>", '{time}' => date("d F, Y h:i:sa"), '{oldfile}' => $strCopyName))); unlink(YiiBase::getPathOfAlias('webroot') . "/themes/" . $strTheme . ".zip"); $objCurrentSettings = Modules::model()->findByAttributes(array('module' => $realName, 'category' => 'theme')); if ($objCurrentSettings) { $objCurrentSettings->version = $arrThemes[$strTheme]['version']; $objCurrentSettings->save(); } $this->redirect($this->createUrl("theme/gallery")); } }