Exemplo n.º 1
0
 public function generateHead()
 {
     $cacheVersion = $this->getCacheVersion();
     $cssFiles = $this->getCss();
     $inDesignPreview = false;
     $data = ipRequest()->getRequest();
     if (!empty($data['ipDesign']['pCfg']) || !empty($data['restoreDefault'])) {
         $inDesignPreview = \Ip\Internal\Design\ConfigModel::instance()->isInPreviewState();
     }
     if ($inDesignPreview) {
         $themeAssetsUrl = ipThemeUrl(\Ip\Application::ASSETS_DIR . '/');
         $designService = \Ip\Internal\Design\Service::instance();
         $theme = ipConfig()->theme();
         foreach ($cssFiles as &$file) {
             if (strpos($file['value'], $themeAssetsUrl) === 0) {
                 $pathinfo = pathinfo($file['value']);
                 if ($pathinfo['extension'] == 'css' && $themeAssetsUrl . $pathinfo['basename'] == $file['value']) {
                     $themeFile = \Ip\Application::ASSETS_DIR . '/' . $pathinfo['filename'] . '.less';
                     if (file_exists(ipThemeFile($themeFile))) {
                         $file['value'] = $designService->getRealTimeUrl($theme, $themeFile);
                         $file['cacheFix'] = false;
                     }
                 }
             }
             if ($file['cacheFix']) {
                 $file['value'] .= (strpos($file['value'], '?') !== false ? '&' : '?') . $cacheVersion;
             }
         }
     } else {
         foreach ($cssFiles as &$file) {
             if ($file['cacheFix']) {
                 $file['value'] .= (strpos($file['value'], '?') !== false ? '&' : '?') . $cacheVersion;
             }
         }
     }
     $cssFiles = ipFilter('ipCss', $cssFiles);
     $response = ipResponse();
     $data = array('title' => $response->getTitle(), 'keywords' => $response->getKeywords(), 'description' => $response->getDescription(), 'favicon' => $response->getFavicon(), 'charset' => $response->getCharset(), 'css' => $cssFiles);
     $head = ipView('Ip/Internal/Config/view/head.php', $data)->render();
     $head = ipFilter('ipHead', $head);
     return $head;
 }
Exemplo n.º 2
0
 /**
  * Get theme option. Options can be viewed or set using UI via Theme options dialog box.
  * @param $name
  * @param null $default
  * @return string
  */
 public function getThemeOption($name, $default = null)
 {
     $themeService = \Ip\Internal\Design\Service::instance();
     return $themeService->getThemeOption($name, $default);
 }
Exemplo n.º 3
0
 public function installTheme($themeName)
 {
     $themes = $this->getAvailableThemes();
     if (!isset($themes[$themeName])) {
         throw new \Ip\Exception("Theme '" . esc($themeName) . "' does not exist.");
     }
     $theme = $themes[$themeName];
     ipEvent('ipBeforeThemeInstalled', array('themeName' => $themeName));
     \Ip\ServiceLocator::storage()->set('Ip', 'theme', $themeName);
     $service = Service::instance();
     $service->saveWidgetOptions($theme);
     //write down default theme options
     $options = $theme->getOptionsAsArray();
     foreach ($options as $option) {
         if (empty($option['name']) || empty($option['default'])) {
             continue;
         }
         $configModel = ConfigModel::instance();
         $newValue = $configModel->getConfigValue($themeName, $option['name'], $option['default']);
         $configModel->setConfigValue($themeName, $option['name'], $newValue);
     }
     ipEvent('ipThemeInstalled', array('themeName' => $themeName));
 }