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; }
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)); }
public function updateConfig() { ipRequest()->mustBePost(); $configModel = ConfigModel::instance(); $form = $configModel->getThemeConfigForm(ipConfig()->theme()); $post = ipRequest()->getPost(); $errors = $form->validate($post); if ($errors) { return JsonRpc::error('Invalid form'); } $configModel = ConfigModel::instance(); $model = Model::instance(); $theme = $model->getTheme(ipConfig()->theme()); if (!$theme) { throw new \Ip\Exception("Theme doesn't exist"); } $options = $theme->getOptionsAsArray(); $valuesToStore = array(); foreach ($options as $option) { if (empty($option['name'])) { continue; } $field = $form->getField($option['name']); if (!$field) { continue; } switch ($option['type']) { case 'checkbox': /** * @var \Ip\Form\Field\Checkbox $field */ $value = $field->isChecked($post, $option['name']); break; case 'RepositoryFile': $value = ''; if (!empty($post[$option['name']][0])) { $value = $post[$option['name']][0]; } break; default: $value = $field->getValueAsString($post, $option['name']); } $valuesToStore[$option['name']] = $value; } $valuesToStore = ipFilter('ipDesignOptionsSave', $valuesToStore); foreach ($valuesToStore as $key => $value) { $configModel->setConfigValue(ipConfig()->theme(), $key, $value); } $lessCompiler = LessCompiler::instance(); $lessCompiler->rebuild(ipConfig()->theme()); \Ip\Internal\Core\Service::invalidateAssetCache(); ipAddJsVariable('ipModuleDesignConfiguration', Helper::getConfigurationBoxHtml()); return JsonRpc::result(true); }
public static function getConfigurationBoxHtml() { $configModel = ConfigModel::instance(); $form = $configModel->getThemeConfigForm(ipConfig()->theme()); $form->removeClass('ipModuleForm'); $variables = array('form' => $form); $optionsBox = ipView('view/optionsBox.php', $variables); return $optionsBox->render(); }