public function init() { parent::init(); $themeDir = SSViewer::get_theme_folder(); Requirements::javascript('framework/thirdparty/jquery/jquery.js'); if (Locator::getLocations()) { Requirements::javascript('http://maps.google.com/maps/api/js?sensor=false'); Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js'); Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js'); } Requirements::css('locator/css/map.css'); $featured = Locator::getLocations(array('Featured' => 1))->count() > 0 ? 'featuredLocations: true' : 'featuredLocations: false'; // map config based on user input in Settings tab // AutoGeocode or Full Map $load = $this->data()->AutoGeocode ? 'autoGeocode: true, fullMapStart: false,' : 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; $base = Director::baseFolder(); $themePath = $base . '/' . $themeDir; $listTemplatePath = file_exists($themePath . '/templates/location-list-description.html') ? $themeDir . '/templates/location-list-description.html' : 'locator/templates/location-list-description.html'; $infowindowTemplatePath = file_exists($themePath . '/templates/infowindow-description.html') ? $themeDir . '/templates/infowindow-description.html' : 'locator/templates/infowindow-description.html'; // in page or modal $modal = $this->data()->ModalWindow ? 'modalWindow: true' : 'modalWindow: false'; $kilometer = $this->data()->Unit == 'km' ? 'lengthUnit: "km"' : 'lengthUnit: "m"'; $link = $this->Link() . 'xml.xml'; // init map if (Locator::getLocations()) { Requirements::customScript("\n \$(function(\$) {\n \$('#map-container').storeLocator({\n " . $load . "\n dataLocation: '" . $link . "',\n listTemplatePath: '" . $listTemplatePath . "',\n infowindowTemplatePath: '" . $infowindowTemplatePath . "',\n originMarker: true,\n " . $modal . ', ' . $featured . ",\n slideMap: false,\n zoomLevel: 0,\n distanceAlert: 120,\n formID: 'Form_LocationSearch',\n inputID: 'Form_LocationSearch_address',\n categoryID: 'Form_LocationSearch_category',\n distanceAlert: -1,\n " . $kilometer . ' }); }); '); } }
/** * Returns the path for the compiled CSS file. Falls back on * the theme_dir/css if {@link self::$compiled_path} is undefined. * * @return string */ public function getCompiledPath() { $new_file = basename($this->uncompiledFile, ".less") . ".css"; if (!$this->config()->compiled_path) { return SSViewer::get_theme_folder() . "/css/" . $new_file; } return $this->config()->compiled_path . "/" . $new_file; }
public function init() { parent::init(); Requirements::clear(); $themeDir = SSViewer::get_theme_folder(); Requirements::css("{$themeDir}/css/dp_calendar.css"); Requirements::combine_files('combined.css', array("{$themeDir}/css/reset.css", "{$themeDir}/css/layout.css", "{$themeDir}/css/typography.css", "{$themeDir}/css/form.css", "{$themeDir}/css/flexslider.css")); Requirements::javascript('http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'); Requirements::combine_files('combined.js', array("{$themeDir}/javascript/lib/jquery.ui.core.js", "{$themeDir}/javascript/lib/jquery.ui.position.js", "{$themeDir}/javascript/lib/jquery.ui.datepicker.js", "{$themeDir}/javascript/lib/jquery.flexslider.js", "{$themeDir}/javascript/lib/date.js", "{$themeDir}/javascript/lib/jquery.dp_calendar.js", "{$themeDir}/javascript/script.js")); Requirements::set_combined_files_folder("{$themeDir}/_combined"); }
protected function getFolderList($ext) { $subFolders = array(); if (strrpos($ext, "css", -strlen($ext)) !== false) { $subFolders[] = "css"; } else { if (strrpos($ext, "js", -strlen($ext)) !== false) { $subFolders[] = "javascript"; $subFolders[] = "js"; } } $baseFolders = array(SSViewer::get_theme_folder(), project()); $result = array(); foreach ($baseFolders as $baseFolder) { foreach ($subFolders as $subFolder) { $result[] = $baseFolder . '/' . $subFolder; } } return $result; }
function onAfterInit() { $themeDir = SSViewer::get_theme_folder(); // Add the combined scripts. if (method_exists($this->owner, 'getScriptOverrides')) { $scripts = $this->owner->getScriptOverrides(); } else { $scripts = array("{$themeDir}/js/lib/jquery.js", "{$themeDir}/js/lib/jquery-ui-1.8.21.custom.js", 'themes/module_bootstrap/js/bootstrap-transition.js', 'themes/module_bootstrap/js/bootstrap-scrollspy.js', 'themes/module_bootstrap/js/bootstrap-collapse.js', 'themes/module_bootstrap/js/bootstrap-carousel.js', "{$themeDir}/js/general.js", "{$themeDir}/js/express.js", "{$themeDir}/js/forms.js"); if (method_exists($this->owner, 'getScriptIncludes')) { $scripts = array_merge($scripts, $this->owner->getScriptIncludes()); } } Requirements::combine_files('scripts.js', $scripts); // Add the combined styles. if (method_exists($this->owner, 'getStyleOverrides')) { $styles = $this->owner->getStyleOverrides(); } else { $styles = array("{$themeDir}/css/layout.css", "{$themeDir}/css/typography.css"); if (method_exists($this->owner, 'getStyleIncludes')) { $styles = array_merge($styles, $this->owner->getStyleIncludes()); } } Requirements::combine_files('styles.css', $styles); // Print styles if (method_exists($this->owner, 'getPrintStyleOverrides')) { $printStyles = $this->owner->getPrintStyleOverrides(); } else { $printStyles = array("{$themeDir}/css/print.css"); if (method_exists($this->owner, 'getPrintStyleIncludes')) { $printStyles = array_merge($printStyles, $this->owner->getPrintStyleIncludes()); } } foreach ($printStyles as $printStyle) { Requirements::css($printStyle, 'print'); } // Extra folder to keep the relative paths consistent when combining. Requirements::set_combined_files_folder(ASSETS_DIR . '/_compiled/p'); }
/** * @see Requirements::themedCSS() */ public function themedCSS($name, $module = null, $media = null) { $theme = SSViewer::current_theme(); $path = SSViewer::get_theme_folder() . "/css/$name.css"; if (file_exists(BASE_PATH . '/' . $path)) { $this->css($path, $media); return; } if ($module) { $this->css("$module/css/$name.css"); } }
/** * Registers the given themeable stylesheet as required. * * A CSS file in the current theme path name 'themename/css/$name.css' is first searched for, * and it that doesn't exist and the module parameter is set then a CSS file with that name in * the module is used. * * @param string $name The name of the file - eg '/css/File.css' would have the name 'File' * @param string $module The module to fall back to if the css file does not exist in the * current theme. * @param string $media Comma-separated list of media types to use in the link tag * (e.g. 'screen,projector') */ public function themedCSS($name, $module = null, $media = null) { $theme = SSViewer::get_theme_folder(); $project = project(); $absbase = BASE_PATH . DIRECTORY_SEPARATOR; $abstheme = $absbase . $theme; $absproject = $absbase . $project; $css = "/css/{$name}.css"; if (file_exists($absproject . $css)) { $this->css($project . $css, $media); } elseif ($module && file_exists($abstheme . '_' . $module . $css)) { $this->css($theme . '_' . $module . $css, $media); } elseif (file_exists($abstheme . $css)) { $this->css($theme . $css, $media); } elseif ($module) { $this->css($module . $css, $media); } }
public function init() { parent::init(); Requirements::javascript(implode(DIRECTORY_SEPARATOR, array(SSViewer::get_theme_folder(), 'dist/bundle.js'))); }
/** * Sets up the default template paths */ protected static function init_template_paths() { global $project; self::$template_path = array(); self::$template_path[] = BASE_PATH . '/' . SSViewer::get_theme_folder() . '/templates/php'; self::$template_path[] = BASE_PATH . '/' . $project . '/templates/php'; }
protected function iconTags($baseURL = "", $hasBaseFolderFavicon = false) { $favicon = null; if (!$baseURL) { $baseURL = Director::absoluteBaseURL(); } $cacheKey = 'metatags_ExtendedMetaTags_iconsTags_' . preg_replace("/[^A-Za-z0-9]/", '', $baseURL); $baseURL = rtrim($baseURL, "/"); $cache = SS_Cache::factory($cacheKey); $html = $cache->load($cacheKey); if (!$html) { $html = ''; $sizes = array("16", "32", "57", "72", "76", "96", "114", "120", "128", "144", "152", "180", "192", "310"); foreach ($sizes as $size) { $themeFolder = SSViewer::get_theme_folder(); $file = "/" . $themeFolder . '/icons/' . 'icon-' . $size . 'x' . $size . '.png'; if (file_exists(Director::baseFolder() . $file)) { $html .= ' <link rel="icon" type="image/png" sizes="' . $size . 'x' . $size . '" href="' . $baseURL . $file . '" /> <link rel="apple-touch-icon" type="image/png" sizes="' . $size . 'x' . $size . '" href="' . $baseURL . $file . '" />'; } elseif ($this->owner->getSiteConfig()->FaviconID) { if ($favicon = $this->owner->getSiteConfig()->Favicon()) { if ($favicon->exists() && $favicon instanceof Image) { $generatedImage = $favicon->setWidth($size); if ($generatedImage) { $html .= ' <link rel="icon" type="image/png" sizes="' . $size . 'x' . $size . '" href="' . $baseURL . $generatedImage->Link() . '" /> <link rel="apple-touch-icon" type="image/png" sizes="' . $size . 'x' . $size . '" href="' . $baseURL . $generatedImage->Link() . '" />'; } else { $favicon = null; } } else { $favicon = null; } } } } if ($hasBaseFolderFavicon) { //do nothing } else { $faviconLink = ""; $themeFolder = SSViewer::get_theme_folder(); $faviconLocation = "/" . $themeFolder . '/icons/favicon.ico'; if (file_exists(Director::baseFolder() . $faviconLocation)) { $faviconLink = $baseURL . $faviconLocation; } elseif ($favicon) { $generatedImage = $favicon->setWidth(16); $faviconLink = $baseURL . $generatedImage->Link(); } if ($faviconLink) { $html .= ' <link rel="SHORTCUT ICON" href="' . $faviconLink . '" />'; } } $cache->save($html, $cacheKey); } return $html; }
/** * @see Requirements::themedCSS() */ public function themedCSS($name, $module = null, $media = null) { $path = SSViewer::get_theme_folder(); $abspath = BASE_PATH . DIRECTORY_SEPARATOR . $path; $css = "/css/{$name}.css"; if ($module && file_exists($abspath . '_' . $module . $css)) { $this->css($path . '_' . $module . $css, $media); } else { if (file_exists($abspath . $css)) { $this->css($path . $css, $media); } else { if ($module) { $this->css($module . $css); } } } }
<?php Requirements::set_backend(new LessCompiler()); /* Add default ThemeDir variable */ LessCompiler::addVariable('ThemeDir', '"' . Director::baseURL() . SSViewer::get_theme_folder() . '"'); /* Set default cache directory */ LessCompiler::setCacheDir(TEMP_FOLDER . '/less-cache'); /* Set default cache method */ LessCompiler::setCacheMethod('serialize');
/** * Get location of all editor.css files * * @return array */ protected function getEditorCSS() { $editor = array(); $editor[] = Controller::join_links(Director::absoluteBaseURL(), FRAMEWORK_ADMIN_DIR . '/css/editor.css'); if ($theme = SSViewer::get_theme_folder()) { $editorDir = $theme . '/css/editor.css'; if (file_exists(BASE_PATH . '/' . $editorDir)) { $editor[] = Controller::join_links(Director::absoluteBaseURL(), $editorDir); } } return $editor; }
public function onBeforeInit() { $this->owner->theme_dir = SSViewer::get_theme_folder(); }
/** * Get compiled template data to render a string with * * @param DataObject $context * @param Member $user * @param array $extraData * @return ArrayData */ public function getTemplateData($context, $user = null, $extraData = array()) { // useful global data $data = array('ThemeDir' => SSViewer::get_theme_folder(), 'SiteConfig' => SiteConfig::current_site_config()); // the context object, keyed by it's class name $data[$context->ClassName] = $context; // data as defined by the context object $contextData = $context->getNotificationTemplateData(); if (is_array($contextData)) { $data = array_merge($data, $contextData); } // the member the notification is being sent to $data['Member'] = $user; // extra data $data = array_merge($data, $extraData); return ArrayData::create($data); }
public static function ThemeDir() { return SSViewer::get_theme_folder(); }
public function onAfterInit() { if ($this->isAdminBackend()) { return; } $themeDir = SSViewer::get_theme_folder(); $config = SiteConfig::current_site_config(); if ($config->Theme) { $themeDir = THEMES_DIR . '/' . $config->Theme; // Properly update theme if set in config to make themedCSS work properly Config::inst()->update('SSViewer', 'theme', $config->Theme); } $stylesPath = $config->StylesPath(); $stylesFile = Director::baseFolder() . $stylesPath; $disabled = false; if (defined('THEME_FRAMEWORK_DISABLE_COMPILE')) { $disabled = true; } // Refresh theme also on flush $dev = Director::isDev(); if (filter_input(INPUT_GET, 'flush') && Permission::check('ADMIN')) { $dev = true; } // Refresh theme files if updated in dev if ($dev && !$disabled) { if (is_file($stylesFile)) { $timeCompiled = filemtime($stylesFile); } else { $timeCompiled = 0; } $baseCss = Director::baseFolder() . '/' . $themeDir . '/css/all.css'; if (!is_file($baseCss)) { return; } $timeOriginal = filemtime($baseCss); // We need to recompile the styles if ($timeOriginal > $timeCompiled) { $config->compileStyles(); } } if (!$disabled && is_file($stylesFile)) { // We use compiled file Requirements::css(trim($stylesPath, '/')); } else { // We use theme file Requirements::themedCSS('all'); } Requirements::javascript($themeDir . '/javascript/init.js'); }
/** * Compile styles from theme/css/all.less to assets/Theme/styles.css */ public function compileStyles() { $destination = Director::baseFolder() . $this->StylesPath(); if ($this->owner->Theme) { $themeDir = 'themes/' . $this->owner->Theme; } else { $themeDir = SSViewer::get_theme_folder(); } $parser = new Less_Parser($this->lessEnvOptions()); try { $parser->parseFile(Director::baseFolder() . '/' . $themeDir . '/css/all.less', '/' . $themeDir . '/css'); $vars = array('base_color' => '#ffffff'); foreach (self::$styles_variables as $var) { if ($this->owner->{$var}) { $less_var = strtolower(preg_replace('/([a-z])([A-Z])/', '$1-$2', $var)); $vars[$less_var] = $this->owner->{$var}; } } if (!empty($vars)) { $parser->ModifyVars($vars); } $css = $parser->getCss(); $baseDir = Director::baseFolder() . '/assets/Theme'; if (!is_dir($baseDir)) { mkdir($baseDir, 0777, true); } file_put_contents($destination, $css); } catch (Exception $ex) { SS_Log::log('Failed to create css files : ' . $ex->getMessage(), SS_Log::DEBUG); } }
public function getThemeCSSPath($name, $module = null, $media = null) { Deprecation::notice('0.1.5', $this->owner->ClassName . '->getThemeCSSPath() is deprecated. Use Requirements::css("file") instead'); $result = false; $theme = SSViewer::get_theme_folder(); $project = project(); $absbase = BASE_PATH . DIRECTORY_SEPARATOR; $abstheme = $absbase . $theme; $absproject = $absbase . $project; $css = "/css/{$name}.css"; if (file_exists($absproject . $css)) { $result = $project . $css; } elseif ($module && file_exists($abstheme . '_' . $module . $css)) { $result = $theme . '_' . $module . $css; } elseif (file_exists($abstheme . $css)) { $result = $theme . $css; } elseif ($module) { $result = $module . $css; } return $result; }