示例#1
0
 public function actionEditGlobalCss()
 {
     $formModel = new GlobalCSSFormModel();
     if (isset($_POST['GlobalCSSFormModel'])) {
         $formModel->setAttributes($_POST['GlobalCSSFormModel']);
         if ($formModel->save()) {
             $formModel->css = GlobalCSSFormModel::getGlobalCss();
             X2Flashes::addFlash('success', Yii::t('app', 'CSS saved'));
         }
     } else {
         $formModel->css = GlobalCSSFormModel::getGlobalCss();
         if (!$formModel->css) {
             X2Flashes::addFlash('error', Yii::t('app', 'Could not read file ' . GlobalCSSFormModel::getGlobalCssPath()));
         }
     }
     $this->render('editGlobalCss', array('formModel' => $formModel));
 }
示例#2
0
 /**
  * Inserts the scripts in the head section.
  * @param string $output the output to be inserted with scripts.
  * This method is Copyright (c) 2008-2014 by Yii Software LLC
  * http://www.yiiframework.com/license/ 
  */
 public function renderHead(&$output)
 {
     parent::renderHead($output);
     $html = '';
     foreach ($this->metaTags as $meta) {
         $html .= CHtml::metaTag($meta['content'], null, null, $meta) . "\n";
     }
     foreach ($this->linkTags as $link) {
         $html .= CHtml::linkTag(null, null, null, null, $link) . "\n";
     }
     /* x2modstart */
     if (Auxlib::getIEVer() < 10) {
         // group registered css files using import statements
         $mergedCss = '';
         $mediaType = null;
         foreach ($this->cssFiles as $url => $media) {
             if ($mediaType === null) {
                 $mediaType = $media;
             }
             $text = '@import url("' . $url . '");';
             if ($media !== $mediaType) {
                 $html .= CHtml::css($mergedCss, $mediaType) . "\n";
                 $mergedCss = '';
                 $mediaType = $media;
             }
             $mergedCss .= "\n" . $text;
         }
         if ($mergedCss) {
             $html .= CHtml::css($mergedCss, $mediaType) . "\n";
         }
     } else {
         foreach ($this->cssFiles as $url => $media) {
             $html .= CHtml::cssFile($url, $media) . "\n";
         }
     }
     if (Auxlib::getIEVer() < 10) {
         // merge inline css
         $mergedCss = '';
         $mediaType = null;
         foreach ($this->css as $css) {
             $text = $css[0];
             $media = $css[1];
             if (is_array($text) && isset($text['text'])) {
                 $text = $text['text'];
             }
             if ($mediaType === null) {
                 $mediaType = $media;
             }
             if (preg_match('/@import/', $text)) {
                 if ($mergedCss) {
                     $html .= CHtml::css($mergedCss, $mediaType) . "\n";
                 }
                 $mergedCss = '';
                 $mediaType = null;
                 $html .= CHtml::css($text, $media) . "\n";
                 continue;
             }
             if ($media !== $mediaType) {
                 $html .= CHtml::css($mergedCss, $mediaType) . "\n";
                 $mergedCss = '';
                 $mediaType = $media;
             }
             $mergedCss .= "\n" . $text;
         }
         if ($mergedCss) {
             $html .= CHtml::css($mergedCss, $mediaType) . "\n";
         }
     } else {
         foreach ($this->css as $css) {
             $text = $css[0];
             $media = $css[1];
             if (is_array($text) && isset($text['text']) && isset($text['htmlOptions'])) {
                 // special case for css registered with html options
                 $html .= X2Html::css($text['text'], $media, $text['htmlOptions']);
                 continue;
             }
             $html .= CHtml::css($text, $media) . "\n";
         }
     }
     // prevent global css from being applied if this is an admin or guest request
     if (!Yii::app()->controller instanceof AdminController && !Yii::app()->user->isGuest) {
         $globalCssUrl = GlobalCSSFormModel::getGlobalCssUrl();
         $html .= CHtml::cssFile($globalCssUrl . $this->getCacheBusterSuffix($globalCssUrl)) . "\n";
     }
     /* x2modend */
     if ($this->enableJavaScript) {
         if (isset($this->scriptFiles[self::POS_HEAD])) {
             foreach ($this->scriptFiles[self::POS_HEAD] as $scriptFileValueUrl => $scriptFileValue) {
                 if (is_array($scriptFileValue)) {
                     $html .= CHtml::scriptFile($scriptFileValueUrl, $scriptFileValue) . "\n";
                 } else {
                     $html .= CHtml::scriptFile($scriptFileValueUrl) . "\n";
                 }
             }
         }
         if (isset($this->scripts[self::POS_HEAD])) {
             $html .= $this->renderScriptBatch($this->scripts[self::POS_HEAD]);
         }
     }
     if ($html !== '') {
         $count = 0;
         $output = preg_replace('/(<title\\b[^>]*>|<\\/head\\s*>)/is', '<###head###>$1', $output, 1, $count);
         if ($count) {
             $output = str_replace('<###head###>', $html, $output);
         } else {
             $output = $html . $output;
         }
     }
 }