Пример #1
0
 /**
  * @return string
  */
 public function ServiceCss()
 {
     $sResult = '';
     $bAdmin = !empty($this->aPaths[2]) && 'Admin' === $this->aPaths[2];
     $bJson = !empty($this->aPaths[9]) && 'Json' === $this->aPaths[9];
     if ($bJson) {
         @\header('Content-Type: application/json; charset=utf-8');
     } else {
         @\header('Content-Type: text/css; charset=utf-8');
     }
     $sTheme = '';
     if (!empty($this->aPaths[4])) {
         $sTheme = $this->oActions->ValidateTheme($this->aPaths[4]);
         $sRealTheme = $sTheme;
         $bCustomTheme = '@custom' === \substr($sTheme, -7);
         if ($bCustomTheme) {
             $sRealTheme = \substr($sTheme, 0, -7);
         }
         $bCacheEnabled = $this->Config()->Get('labs', 'cache_system_data', true);
         if ($bCacheEnabled) {
             $this->oActions->verifyCacheByKey($this->sQuery);
         }
         $sCacheFileName = '';
         if ($bCacheEnabled) {
             $sCacheFileName = \RainLoop\KeyPathHelper::CssCache($sTheme, $this->oActions->Plugins()->Hash());
             $sResult = $this->Cacher()->Get($sCacheFileName);
         }
         if (0 === \strlen($sResult)) {
             try {
                 include_once APP_VERSION_ROOT_PATH . 'app/libraries/lessphp/ctype.php';
                 include_once APP_VERSION_ROOT_PATH . 'app/libraries/lessphp/lessc.inc.php';
                 $oLess = new \lessc();
                 $oLess->setFormatter('compressed');
                 $aResult = array();
                 $sThemeFile = ($bCustomTheme ? APP_INDEX_ROOT_PATH : APP_VERSION_ROOT_PATH) . 'themes/' . $sRealTheme . '/styles.less';
                 $sThemeExtFile = ($bCustomTheme ? APP_INDEX_ROOT_PATH : APP_VERSION_ROOT_PATH) . 'themes/' . $sRealTheme . '/ext.less';
                 $sThemeValuesFile = APP_VERSION_ROOT_PATH . 'app/templates/Themes/values.less';
                 $sThemeTemplateFile = APP_VERSION_ROOT_PATH . 'app/templates/Themes/template.less';
                 if (\file_exists($sThemeFile) && \file_exists($sThemeTemplateFile) && \file_exists($sThemeValuesFile)) {
                     $aResult[] = '@base: "' . ($bCustomTheme ? \RainLoop\Utils::WebPath() : \RainLoop\Utils::WebVersionPath()) . 'themes/' . $sRealTheme . '/";';
                     $aResult[] = \file_get_contents($sThemeValuesFile);
                     $aResult[] = \file_get_contents($sThemeFile);
                     $aResult[] = \file_get_contents($sThemeTemplateFile);
                     if (\file_exists($sThemeExtFile)) {
                         $aResult[] = \file_get_contents($sThemeExtFile);
                     }
                 }
                 $aResult[] = $this->Plugins()->CompileCss($bAdmin);
                 $sResult = $oLess->compile(\implode("\n", $aResult));
                 if ($bCacheEnabled) {
                     if (0 < \strlen($sCacheFileName)) {
                         $this->Cacher()->Set($sCacheFileName, $sResult);
                     }
                 }
             } catch (\Exception $oException) {
                 $this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR, 'LESS');
             }
         }
         if ($bCacheEnabled) {
             $this->oActions->cacheByKey($this->sQuery);
         }
     }
     return $bJson ? \MailSo\Base\Utils::Php2js(array($sTheme, $sResult), $this->Logger()) : $sResult;
 }