public function fix_fluent_menu() { if (!class_exists('Fluent')) { return; } $conf = SiteConfig::current_site_config(); $localesNames = Fluent::locale_names(); if ($conf->hasExtension('ActiveLocalesExtension') && $conf->ActiveLocales) { $localesNames = $conf->ActiveLocalesNames(); } $locales = json_encode($localesNames); $locale = json_encode(Fluent::current_locale()); // If we have only one locale, set this one as default if (count($localesNames) === 1) { $locale = json_encode(key($localesNames)); } $param = json_encode(Fluent::config()->query_param); $buttonTitle = json_encode(_t('Fluent.ChangeLocale', 'Change Locale')); Requirements::block('FluentHeadScript'); Requirements::insertHeadTags(<<<EOT <script type="text/javascript"> //<![CDATA[ \tvar fluentLocales = {$locales}; \tvar fluentLocale = {$locale}; \tvar fluentParam = {$param}; \tvar fluentButtonTitle = {$buttonTitle}; //]]> </script> EOT , 'FluentHeadScriptSubsite'); }
public function init() { parent::init(); Requirements::clear(); Requirements::insertHeadTags('<meta http-equiv="Content-language" content="' . i18n::get_locale() . '" />'); Requirements::themedCSS('sendfriend', 'screen'); }
/** * Insert the data to pass to JS in to the DOM * @return void */ public static function insert() { if (!self::$has_inserted) { self::$has_inserted = true; Requirements::insertHeadTags(self::get_script_tag()); } }
public function onAfterInit() { $config = SiteConfig::current_site_config(); // include the JS snippet into the frontend page markup if ($trackingID = $config->GoogleAnalyticsTrackingID) { $data = array('GoogleAnalyticsTrackingID' => $trackingID, 'GoogleAnalyticsParameters' => $config->GoogleAnalyticsParameters, 'GoogleAnalyticsConstructorParameters' => $config->GoogleAnalyticsConstructorParameters); $analyticsData = new ArrayData($data); Requirements::insertHeadTags($analyticsData->renderWith('GoogleAnalyticsJSSnippet'), 'GoogleAnalytics'); } }
/** * Inlcudes the CSS and Javascript files required by the cwsoft-foldergallery module * * @return void */ function init() { parent::init(); // include i18n Javascript library and lang files // it doesn't work without the meta-tag (see http://open.silverstripe.org/ticket/7949) Requirements::insertHeadTags('<meta http-equiv="Content-language" content="' . i18n::get_locale() . '" />'); Requirements::javascript(FRAMEWORK_DIR . "/javascript/i18n.js"); Requirements::add_i18n_javascript('cwsoft-foldergallery/javascript/lang'); // load cwsoft-foldergallery Javascript files into head Requirements::set_write_js_to_body(false); // include required cwsoft-foldergallery CSS and Javascript files Requirements::css('cwsoft-foldergallery/thirdparty/colorbox/colorbox.css'); Requirements::css('cwsoft-foldergallery/css/cwsoft-foldergallery.css'); Requirements::javascript('cwsoft-foldergallery/thirdparty/jquery/jquery.min.js'); Requirements::javascript('cwsoft-foldergallery/thirdparty/colorbox/jquery.colorbox-min.js'); Requirements::javascript('cwsoft-foldergallery/javascript/cwsoft-foldergallery.js'); }
function SendFriendLink() { if (self::$JSMode == 'Jquery') { Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery/jquery.min.js'); Requirements::javascript(SENDFRIEND_DIR . '/thirdparty/jquery.simplemodal/jquery.simplemodal.1.4.2.min.js'); Requirements::javascript(SENDFRIEND_DIR . '/thirdparty/jquery.simplemodal/popup.js'); Requirements::css(SENDFRIEND_DIR . '/thirdparty/jquery.simplemodal/css/basic.css', 'screen'); return '<a href="' . Director::absoluteBaseURL() . 'sendfriend?sendurl=' . Director::absoluteBaseURL() . $this->owner->URLSegment . '" id="tellafriend">' . _t('SendFriend.SENDFRIENDLINK', "Send to a friend") . '</a>'; } else { //default mode Requirements::insertHeadTags('<script type="text/javascript">var GB_ROOT_DIR = "' . Director::absoluteBaseURL() . SENDFRIEND_DIR . '/thirdparty/greybox/";</script>'); Requirements::javascript(SENDFRIEND_DIR . '/thirdparty/greybox/AJS.js'); Requirements::javascript(SENDFRIEND_DIR . '/thirdparty/greybox/AJS_fx.js'); Requirements::javascript(SENDFRIEND_DIR . '/thirdparty/greybox/gb_scripts.js'); Requirements::css(SENDFRIEND_DIR . '/thirdparty/greybox/gb_styles.css', 'screen'); return '<a href="' . Director::absoluteBaseURL() . 'sendfriend?sendurl=' . Director::absoluteBaseURL() . $this->owner->URLSegment . '" rel="gb_page_center[' . SENDFRIEND_POPUP_WIDTH . ', ' . SENDFRIEND_POPUP_HEIGHT . ']">' . _t('SendFriend.SENDFRIENDLINK', "Send to a friend") . '</a>'; } }
public function onAfterInit() { if ($this->owner instanceof DevelopmentAdmin || $this->owner instanceof DatabaseAdmin || class_exists('DevBuildController') && $this->owner instanceof DevBuildController) { return; } // include the JS snippet into the frontend page markup if (GoogleAnalyticsLiteConfig::get_google_config('code')) { $code = GoogleAnalyticsLiteConfig::get_google_config('code'); $SnippetPlacement = GoogleAnalyticsLiteConfig::get_google_config('placement'); $snippet = new ArrayData(array('GoogleAnalyticsCode' => $code)); $snippetHtml = $snippet->renderWith('GoogleAnalyticsLiteJSSnippet'); if ($SnippetPlacement === 'Head') { Requirements::insertHeadTags(sprintf("<script type=\"text/javascript\">%s</script>", $snippetHtml->Value)); } else { Requirements::customScript($snippetHtml); } } }
public function onBeforeInit() { /* ========================================= * Combine JS =========================================*/ Requirements::combine_files('combined.js', array('boilerplate/javascript/jquery.1.11.1.min.js', 'boilerplate/javascript/modernizr.2.8.3.js', 'boilerplate/javascript/bootstrap-3.2.0.min.js', 'boilerplate/javascript/script.js')); /* ========================================= * CSS =========================================*/ Requirements::css('boilerplate/css/main.min.css'); //Requirements::css('themes/boilerplate/css/main.min.css'); /* ========================================= * IE Shivs =========================================*/ $baseHref = Director::BaseURL(); Requirements::insertHeadTags('<!--[if lt IE 9]> <script type="text/javascript" src="' . $baseHref . 'boilerplate/javascript/html5.js"></script> <script type="text/javascript" src="' . $baseHref . 'boilerplate/javascript/respond.min.js"></script> <![endif]-->'); }
public function init() { parent::init(); Requirements::set_combined_files_folder(project() . '/_combinedfiles'); Requirements::combine_files('main.js', array(THIRDPARTY_DIR . '/jquery/jquery.min.js', THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js', PROJECT_THIRDPARTY_DIR . '/magnific-popup/jquery.magnific-popup.min.js', project() . '/javascript/plugins.js', project() . '/javascript/timer.js', project() . '/javascript/main.js')); // insert modernizr into <head> for html5shiv to work Requirements::insertHeadTags(sprintf('<script src="%s"></script>', PROJECT_THIRDPARTY_DIR . '/modernizr/modernizr.min.js')); // insert google analytics into <head> to also track visitors that cancle the pageload before it completed //Requirements::insertHeadTags(sprintf( // "<script> // (function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]= // function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date; // e=o.createElement(i);r=o.getElementsByTagName(i)[0]; // e.src='//www.google-analytics.com/analytics.js'; // r.parentNode.insertBefore(e,r)}(window,document,'script','ga')); // ga('create','%s');ga('send','pageview'); // </script>", // 'UA-XXXXX-X' //)); Requirements::combine_files('main.css', array(PROJECT_THIRDPARTY_DIR . '/normalize-css/normalize.css', PROJECT_THIRDPARTY_DIR . '/magnific-popup/magnific-popup.css', project() . '/css/screen.css', project() . '/css/typography.css', project() . '/css/form.css', project() . '/css/header.css', project() . '/css/footer.css', project() . '/css/layout.css', project() . '/css/legacy.css')); Requirements::css(project() . '/css/print.css', 'print'); }
public function init() { $dirName = basename(dirname(dirname(dirname(__FILE__)))); $locales = json_encode(Fluent::locale_names()); $locale = json_encode(Fluent::current_locale()); $param = json_encode(Fluent::config()->query_param); $buttonTitle = json_encode(_t('Fluent.ChangeLocale', 'Change Locale')); // Force the variables to be written to the head, to ensure these are available for other scripts to pick up. Requirements::insertHeadTags(<<<EOT <script type="text/javascript"> //<![CDATA[ \tvar fluentLocales = {$locales}; \tvar fluentLocale = {$locale}; \tvar fluentParam = {$param}; \tvar fluentButtonTitle = {$buttonTitle}; //]]> </script> EOT , 'FluentHeadScript'); Requirements::javascript("{$dirName}/javascript/fluent.js"); Requirements::css("{$dirName}/css/fluent.css"); }
public function onAfterInit() { $config = WebAppConfig::current_site_config(); $icons = $config->WebAppIcons(); $splashScreens = $config->WebAppStartupScreens(); $tags = ''; $tags .= '<meta name="viewport" content="initial-scale=1, user-scalable=' . $config->UserScalable . $config->MinimalUI . '">'; $tags .= '<meta name="apple-mobile-web-app-capable" content="' . $config->Fullscreen . '">'; $tags .= '<meta name="apple-mobile-web-app-status-bar-style" content="' . $config->StatusBar . '">'; $tags .= '<meta name="apple-mobile-web-app-title" content="' . $config->AppTitle . '">'; foreach ($icons as $icon) { $size = $icon->Size; $url = $icon->Image()->URL; $tags .= '<link href="' . $url . '" sizes="' . $size . '" rel="apple-touch-icon">'; } foreach ($splashScreens as $splashScreen) { $media = $splashScreen->Media; $url = $splashScreen->Image()->URL; $tags .= '<link href="' . $url . '" media="' . $media . '" rel="apple-touch-startup-image">'; } Requirements::insertHeadTags($tags); }
public function init() { $baseHref = Director::BaseURL(); /** ----------------------------------------- * Javascript * ----------------------------------------*/ Requirements::insertHeadTags('<script type="text/javascript" src="' . $baseHref . project() . '/javascript/lib/modernizr.min.js"></script>', 'Modernizr'); /** * Set All JS to be right before the closing </body> tag. */ Requirements::set_force_js_to_bottom(true); if (Director::isDev()) { Requirements::javascript(project() . '/javascript/main.js'); } else { Requirements::javascript(project() . '/javascript/main.min.js'); } /** ----------------------------------------- * CSS * ----------------------------------------*/ Requirements::css(project() . '/css/main.min.css', 'all'); parent::init(); }
function IncludeTrackingEvents() { $page = $this->owner->data(); $events = SiteConfig::current_site_config()->GoogleTrackEvents()->where('EXISTS ( SELECT 1 FROM GoogleTrackEvent_Pages gep WHERE gep.GoogleTrackEventID = GoogleTrackEvent.ID AND gep.SiteTreeID = ' . $page->ID . ' LIMIT 1 )'); if ($events->count()) { $strCode = ""; Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js'); Requirements::javascript(THIRDPARTY_DIR . '/jquery-livequery/jquery.livequery.js'); foreach ($events as $event) { $strEvent = 'click'; if ($event->EventType == 'Hover') { $strEvent = 'mouseenter'; } $strCategory = addslashes($event->Category); $strAction = addslashes($event->Action); $strLabel = addslashes($event->Label); $strCode .= <<<JS (function(){ \t\$("{$event->Target}").livequery('{$strEvent}', function(){ \t\tif(typeof _gaq !== 'undefined'){ \t\t\t_gaq.push(['_trackEvent', '{$strCategory}', '{$strAction}', '{$strLabel}']); \t\t} \t}); })(jQuery); JS; } if (SiteConfig::current_site_config()->GoogleAnalyticsPosition == 'Head') { Requirements::insertHeadTags('<script>' . $strCode . '</script>', 'GA_TRACKERS'); } else { Requirements::customScript($strCode, 'GA_TRACKERS'); } } }
/** * Include an link to the feed * * @param string $url URL of the feed * @param string $title Title to show */ public static function linkToFeed($url, $title = null) { $title = Convert::raw2xml($title); Requirements::insertHeadTags('<link rel="alternate" type="application/rss+xml" title="' . $title . '" href="' . $url . '" />'); }
/** * Puts together all the requirements. * * @param array $additionalJS (foo.js, bar.js) * @param array $additionalCSS (name => media type) * @param Boolean $force - run it again * */ public function addBasicMetatagRequirements($additionalJS = array(), $additionalCSS = array(), $force = false) { if (!isset(self::$_metatags_building_completed[$this->owner->dataRecord->ID]) || $force) { $combineJS = Config::inst()->get("MetaTagsContentControllerEXT", "combine_js_files_into_one"); $combineCSS = Config::inst()->get("MetaTagsContentControllerEXT", "combine_css_files_into_one"); if ($combineJS || $combineCSS) { $folderForCombinedFiles = Config::inst()->get("MetaTagsContentControllerEXT", "folder_for_combined_files"); $folderForCombinedFilesWithBase = Director::baseFolder() . "/" . $folderForCombinedFiles; } if ($combineJS) { $jsFile = $folderForCombinedFiles . "/MetaTagAutomation.js"; } if ($combineCSS) { $cssFile = $folderForCombinedFiles . "/MetaTagAutomation.css"; } $jQueryCDNLocation = Config::inst()->get("MetaTagsContentControllerEXT", "jquery_cdn_location"); $cssArray = Config::inst()->get("MetaTagsContentControllerEXT", "default_css"); $jsArray = Config::inst()->get("MetaTagsContentControllerEXT", "default_js"); $jsArray = array_unique(array_merge($jsArray, $additionalJS)); //javascript if ($combineJS && file_exists($folderForCombinedFilesWithBase . $jsFile)) { Requirements::javascript($jsFile); } else { foreach ($jsArray as $key => $js) { if (strpos($js, "framework/thirdparty/jquery/jquery.js") !== false) { //remove, as already included unset($jsArray[$key]); } else { if (!isset($alreadyDone[$js])) { Requirements::javascript($js); $alreadyDone[$js] = 1; } } } } //put jQuery back in, if needed. if (!$jQueryCDNLocation) { array_unshift($jsArray, "framework/thirdparty/jquery/jquery.js"); } if ($combineJS) { Requirements::combine_files($jsFile, $jsArray); } //css if ($combineCSS && file_exists($folderForCombinedFilesWithBase . $cssFile)) { Requirements::css($cssFile); } else { $themeFolder = SSViewer::get_theme_folder(); $cssArrayLocationOnly = array(); $expendadCSSArray = array(); foreach ($cssArray as $name => $media) { if (strpos($name, '.css')) { $expendadCSSArray[] = array("media" => $media, "location" => $name); } else { $expendadCSSArray[] = array("media" => $media, "location" => $themeFolder . '/css/' . $name . '.css'); } } $expendadCSSArray = array_merge($expendadCSSArray, $additionalCSS); foreach ($expendadCSSArray as $cssArraySub) { Requirements::css($cssArraySub["location"], $cssArraySub["media"]); $cssArrayLocationOnly[] = $cssArraySub["location"]; } if ($combineCSS) { Requirements::combine_files($cssFile, $cssArrayLocationOnly); } } //google font $googleFontArray = Config::inst()->get('MetaTagsContentControllerEXT', 'google_font_collection'); if ($googleFontArray && count($googleFontArray)) { $protocol = Director::protocol(); foreach ($googleFontArray as $font) { Requirements::insertHeadTags(' <link href="' . $protocol . 'fonts.googleapis.com/css?family=' . urlencode($font) . '" rel="stylesheet" type="text/css" />'); } } //ie header... if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) { header('X-UA-Compatible: IE=edge,chrome=1'); } self::$_metatags_building_completed[$this->owner->dataRecord->ID] = true; } }
/** * Sets i18n locale and adds Content-language to meta tags. * @param string $locale */ public static function setup_locale($locale = "") { if ($locale != "") { Requirements::insertHeadTags('<meta http-equiv="Content-language" content="' . i18n::get_lang_from_locale($locale) . '" />'); i18n::set_locale($locale); } else { Debug::show("Your locale is not properly set. Remember that for using this function you need to use Object::add_extension('SiteTree', 'Translatable'); in your project _config.php"); } }
public function onAfterInit() { if ($this->GAID()) { Requirements::insertHeadTags($this->owner->renderWith('GoogleAnalyticsCode'), 'GoogleAnalyticsCode'); } }
public function loadGoogleMap() { $js = ''; $this->loadDefaults(); if (!self::$includes_are_done) { Requirements::themedCSS("googleMap"); Requirements::javascript(THIRDPARTY_DIR . "/jquery/jquery.js"); Requirements::javascript("googlemap/javascript/googleMapStatic.js"); Requirements::javascript("googlemap/javascript/loadAjaxInfoWindow.js"); Requirements::insertHeadTags('<style type="text/css">v\\:* {behavior:url(#default#VML);}</style>', "GoogleMapCustomHeadTag"); if (!$this->getShowStaticMapFirst()) { Requirements::javascript("http://maps.googleapis.com/maps/api/js?v=3.16&sensor=" . $this->showFalseOrTrue(self::$uses_sensor)); Requirements::javascript("googlemap/javascript/googleMaps.js"); $js .= 'var scriptsLoaded = true; jQuery(document).ready( function() { initiateGoogleMap();} );'; } else { $js .= 'var scriptsLoaded = false;'; Requirements::javascript('http://www.google.com/jsapi?key=' . Config::inst()->get("GoogleMap", "GoogleMapAPIKey")); // } $js .= 'var absoluteBaseURL = "' . Director::absoluteBaseURL() . '";'; $js .= $this->createJavascript(); Requirements::customScript($js, "GoogleMapCustomScript"); self::$includes_are_done = true; } }
/** * Generates and embeds the RSS header link for the global version rss feed */ public function linkToAllSiteRSSFeed() { if (!Config::inst()->get('VersionFeed', 'allchanges_enabled') || !SiteConfig::current_site_config()->AllChangesEnabled) { return; } // RSS feed to all-site changes. $title = Convert::raw2xml($this->linkToAllSitesRSSFeedTitle()); $url = $this->owner->getSiteRSSLink(); Requirements::insertHeadTags('<link rel="alternate" type="application/rss+xml" title="' . $title . '" href="' . $url . '" />'); }
public static function setupRequirements($cssArray = array(), $jsArray = array()) { $siteConfig = SiteConfig::current_site_config(); // Don't combine files if in admin to prevent error on "login as someone else" screen $inAdmin = is_subclass_of(Controller::curr(), "LeftAndMain"); // Setup requirements if (isset(Page_Controller::$themeFolderAndSubfolder) && Page_Controller::$themeFolderAndSubfolder) { self::$themeFolderAndSubfolder = Page_Controller::$themeFolderAndSubfolder; } else { $currentTheme = SSViewer::current_theme(); self::$themeFolderAndSubfolder = 'themes/' . $currentTheme; } //Set a custom combined folder under themes so relative paths to images within CSS and JavaScript files don't break Requirements::set_combined_files_folder(self::$themeFolderAndSubfolder . '/combined'); // CSS array if (count($cssArray)) { foreach ($cssArray as $css) { Requirements::css($css); } if (!$inAdmin) { Requirements::combine_files("combined-" . $siteConfig->ID . ".css", $cssArray); } } // Javascript array if (count($jsArray)) { foreach ($jsArray as $js) { Requirements::javascript($js); } if (!$inAdmin) { Requirements::combine_files("combined-" . $siteConfig->ID . ".js", $jsArray); } } if (!$inAdmin) { Requirements::process_combined_files(); } // Google analytics if (!Director::isDev()) { if (isset($siteConfig->GoogleAnalyticsCode)) { Requirements::insertHeadTags($siteConfig->GoogleAnalyticsCode); } } // End Google analytics }
/** * load some requirements first * * @return void * * @author Sascha Koehler <*****@*****.**>, * Sebastian Diel <*****@*****.**> * @since 29.10.2013 */ public function onBeforeInit() { if (!$this->owner instanceof Security || $this->owner->urlParams['Action'] != 'ping') { // ------------------------------------------------------------------- // load scripts // ------------------------------------------------------------------- Requirements::block('sapphire/thirdparty/jquery/jquery.js'); if (self::$include_meta_content_language) { Requirements::insertHeadTags('<meta http-equiv="Content-language" content="' . i18n::get_locale() . '" />', 'CustomHtmlFormContentLanguageTag'); } Requirements::add_i18n_javascript('customhtmlform/javascript/lang'); if (!class_exists('RequirementsEngine')) { if (self::$do_use_own_jquery) { Requirements::javascript('customhtmlform/script/jquery.js'); } Requirements::javascript('customhtmlform/script/jquery.scrollTo.min.js'); Requirements::javascript('customhtmlform/script/jquery.pixeltricks.forms.checkFormData.js'); Requirements::javascript('customhtmlform/script/jquery.pixeltricks.forms.events.js'); Requirements::javascript('customhtmlform/script/jquery.pixeltricks.forms.validator.js'); Requirements::javascript(SAPPHIRE_DIR . "/javascript/i18n.js"); Requirements::add_i18n_javascript('customhtmlform/javascript/lang'); } } $this->owner->isFrontendPage = true; }
Requirements::set_write_js_to_body(true); Requirements::set_combined_files_enabled(true); // HTML5 Shims // ----------- $shimRequirements = array('thirdparty/selectivizr/index.js', 'thirdparty/respond/dest/respond.min.js', 'thirdparty/modernizr/modernizr.js'); Requirements::combine_files('lte-ie8-shims.js', $shimRequirements); Requirements::process_combined_files(); // forces ss to generate the file regardless of blocking // CSS // --- $cssRequirements = array('themes/project/css/main.css', 'themes/project/css/typography.css'); Requirements::combine_files('application.css', $cssRequirements); // Primary JS // ---------- $jsRequirements = array('thirdparty/jquery/dist/jquery.min.js', 'project/javascript/main.js', 'project/javascript/forms.js'); Requirements::combine_files('application.js', $jsRequirements); // Asset loading // ------------- // block jquery // block the combined shims + component files so we can lead them manually RequirementsHelper::require_block(array_merge(array('assets/_combinedfiles/lte-ie8-shims.js', 'framework/thirdparty/jquery/jquery.js'), $shimRequirements)); // dump this into a conditional Requirements::insertHeadTags(' <!--[if (gte IE 6)&(lte IE 8)]> <script src="/assets/_combinedfiles/lte-ie8-shims.js"></script> <![endif]--> '); // block all front end requirements from the cms LeftAndMainHelper::require_block(array_merge(array('assets/_combinedfiles/application.css', 'assets/_combinedfiles/application.js', 'assets/_combinedfiles/lte-ie8-shims.js'), $cssRequirements, $jsRequirements, $shimRequirements)); // let the cms load its preferred version of jquery LeftAndMainHelper::require_unblock(array('framework/thirdparty/jquery/jquery.js'));
public static function include_default_js() { $configObj = MarkdownEditorConfig::get('default'); Requirements::insertHeadTags('<script>var markdownEditorConfigs = {};</script>', 'MarkdownEditorConfigHolder'); Requirements::insertHeadTags('<script>' . $configObj->generateJS() . '</script>', 'MarkdownEditorConfig_default'); }
protected function genUniversalAnalyticsCode() { if (count(self::$tracker_names) == 0) { return false; } $ga_insert = false; $ErrorCode = Controller::curr()->ErrorCode; if ($ErrorCode) { $ecode = $ErrorCode == 404 ? '404 Page Not Found' : $ErrorCode . ' Page Error'; foreach (self::$tracker_names as $t) { $ga_insert .= self::$global_name . '("' . $t . 'send","event","' . $ecode . '",window.location.pathname+window.location.search,window.referrer);' . "\n"; } } else { foreach (self::$tracker_names as $t) { $ga_insert .= self::$global_name . '("' . $t . 'send","pageview");' . "\n"; } } $headerscript = '(function(i,s,o,g,r,a,m){i["GoogleAnalyticsObject"]=r;i[r]=i[r]||function(){' . "\n" . '(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),' . "\n" . 'm=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)' . "\n" . '})(window,document,"script","//www.google-analytics.com/analytics.js","' . self::$global_name . '");' . "\n" . self::$ga_trackers . $ga_insert; Requirements::insertHeadTags('<script type="text/javascript">//<![CDATA[' . "\n" . $this->compressGUACode($headerscript) . "\n" . '//]]></script>'); }
/** * @param DownloadTempFile $dl * @return HTMLText */ protected function displayDownloadPage(DownloadTempFile $dl) { $downloadPage = Config::inst()->get('Downloadable', 'download_page'); if ($downloadPage) { $downloadPage = SiteTree::get_by_link($downloadPage); } if (!$downloadPage || !$downloadPage->exists()) { return $this->sendTempFile($dl); } else { $dl->LastUsedAt = date('Y-m-d H:i:s'); $dl->write(); } // Just in case $this->dataRecord = $downloadPage; // Add a meta tag that will refresh with the request that actually does the processing // In the future this could be wrapped in a <noscript> and we could do some better ajax // work to make this more userfriendly (such as a progress bar for multiple files, etc) Requirements::insertHeadTags('<meta http-equiv="refresh" content="1; url=' . $dl->Link() . '">'); // And....render return $this->customise($downloadPage)->renderWith(array('DownloadPage', 'Page', 'Page')); }
public function onAfterInit() { if ($this->ShowGoogleAnalytics()) { $config = SiteConfig::current_site_config(); if ($config->GoogleAnalyticsUseUniversalAnalytics) { // universal analytics if (!self::$use_template) { // cookie domain $domain = 'auto'; if ($config->GoogleAnalyticsCookieDomain && strlen(trim($config->GoogleAnalyticsCookieDomain)) > 0) { $domain = trim($config->GoogleAnalyticsCookieDomain); } // page view url $pageview = "ga('send', 'pageview');"; if ($urldata = $this->owner->getCustomPageViewUrl()) { if (is_array($urldata)) { $pageview = ""; // check if associative array if (array_keys($urldata) !== range(0, count($urldata) - 1)) { foreach ($urldata as $url => $title) { $pageview .= "ga('send', { 'hitType': 'pageview', 'page': '{$url}', 'title': '{$title}' });"; } } else { foreach ($urldata as $url) { $pageview .= "ga('send', 'pageview', '{$url}');"; } } } else { if (is_string($urldata)) { $pageview = "ga('send', 'pageview', '{$urldata}');"; } } } // tracking code Requirements::insertHeadTags("\n\t\t\t\t\t\t<script type=\"text/javascript\">\n\t\t\t\t\t\t\t(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n\t\t\t\t\t\t\t(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\n\t\t\t\t\t\t\tm=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n\t\t\t\t\t\t\t})(window,document,'script','//www.google-analytics.com/analytics.js','ga');\n\t\t\t\t\t\t\tga('create', '" . $config->GoogleAnalyticsID . "', '" . $domain . "');\n\t\t\t\t\t\t\t" . $pageview . "\n\t\t\t\t\t\t</script>\n\t\t\t\t\t"); } // event tracking if ($config->GoogleAnalyticsUseEventTracking) { Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.min.js'); Requirements::javascript(GOOGLEANALYTICS_DIR . '/javascript/event-tracking-universal.js'); } } else { // asynchronous analytics if (!self::$use_template) { // cookie domain $domain = ''; if ($config->GoogleAnalyticsCookieDomain && strlen(trim($config->GoogleAnalyticsCookieDomain)) > 0) { $domain = "_gaq.push(['_setDomainName', '" . trim($config->GoogleAnalyticsCookieDomain) . "']);"; } // page view url $pageview = "_gaq.push(['_trackPageview']);"; if ($urldata = $this->owner->getCustomPageViewUrl()) { if (is_array($urldata)) { $pageview = ""; // check if associative array if (array_keys($urldata) !== range(0, count($urldata) - 1)) { foreach ($urldata as $url => $title) { $pageview .= "_gaq.push(['_trackPageview', '{$url}']);"; } } else { foreach ($urldata as $url) { $pageview .= "_gaq.push(['_trackPageview', '{$url}']);"; } } } else { if (is_string($urldata)) { $pageview = "_gaq.push(['_trackPageview', '{$urldata}']);"; } } } // tracking code Requirements::insertHeadTags("\n\t\t\t\t\t\t<script type=\"text/javascript\">\n\t\t\t\t\t\t\tvar _gaq = _gaq || [];\n\t\t\t\t\t\t\t_gaq.push(['_setAccount', '" . $config->GoogleAnalyticsID . "']);\n\t\t\t\t\t\t\t" . $domain . "\n\t\t\t\t\t\t\t" . $pageview . "\n\t\t\t\t\t\t\t(function() {\n\t\t\t\t\t\t\t\tvar ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\n\t\t\t\t\t\t\t\tga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n\t\t\t\t\t\t\t\tvar s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\n\t\t\t\t\t\t\t})();\n\t\t\t\t\t\t</script>\n\t\t\t\t\t"); } // event tracking if ($config->GoogleAnalyticsUseEventTracking) { Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.min.js'); Requirements::javascript(GOOGLEANALYTICS_DIR . '/javascript/event-tracking.js'); } } } }
/** * @param DownloadTempFile $dl * @return HTMLText */ protected function displayCrunchingPage(DownloadTempFile $dl) { $crunchingPage = Config::inst()->get('Downloadable', 'crunching_page'); if ($crunchingPage) { $crunchingPage = SiteTree::get_by_link($crunchingPage); } if (!$crunchingPage || !$crunchingPage->exists()) { $crunchingPage = new Page(); $crunchingPage->Title = _t('Downloadable.CRUNCHINGTITLE', 'Processing Your Download'); $crunchingPage->Content = _t('Downloadable.CRUNCHINGBODY', '<p>Please wait while your download is prepared.</p>'); } // Just in case $this->dataRecord = $crunchingPage; // Add a meta tag that will refresh with the request that actually does the processing // In the future this could be wrapped in a <noscript> and we could do some better ajax // work to make this more userfriendly (such as a progress bar for multiple files, etc) Requirements::insertHeadTags('<meta http-equiv="refresh" content="1; url=' . $dl->getProcessingLink() . '">'); // And....render return $this->customise($crunchingPage)->renderWith(array('CrunchingPage', 'Page', 'Page')); }
public function onAfterInit() { if ($this->ShowGoogleAnalytics()) { $config = SiteConfig::current_site_config(); if ($config->GoogleAnalyticsType == "Universal Analytics") { // universal analytics if (!self::$use_template) { // cookie domain $domain = 'auto'; if ($config->GoogleAnalyticsCookieDomain && strlen(trim($config->GoogleAnalyticsCookieDomain)) > 0) { $domain = trim($config->GoogleAnalyticsCookieDomain); } // page view url $pageview = "ga('send', 'pageview');"; if ($urldata = $this->owner->getCustomPageViewUrl()) { if (is_array($urldata)) { $pageview = ""; // check if associative array if (array_keys($urldata) !== range(0, count($urldata) - 1)) { foreach ($urldata as $url => $title) { $pageview .= "ga('send', { 'hitType': 'pageview', 'page': '{$url}', 'title': '{$title}' });"; } } else { foreach ($urldata as $url) { $pageview .= "ga('send', 'pageview', '{$url}');"; } } } elseif (is_string($urldata)) { $pageview = "ga('send', 'pageview', '{$urldata}');"; } } // tracking code Requirements::insertHeadTags("\n\t\t\t\t\t\t<script type=\"text/javascript\">\n\t\t\t\t\t\t\t(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n\t\t\t\t\t\t\t(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\n\t\t\t\t\t\t\tm=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n\t\t\t\t\t\t\t})(window,document,'script','//www.google-analytics.com/analytics.js','ga');\n\t\t\t\t\t\t\tga('create', '" . $config->GoogleAnalyticsID . "', '" . $domain . "');\n\t\t\t\t\t\t\t" . $pageview . "\n\t\t\t\t\t\t</script>\n\t\t\t\t\t"); } // event tracking if ($config->GoogleAnalyticsUseEventTracking) { Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.min.js'); Requirements::javascript(GOOGLEANALYTICS_DIR . '/javascript/event-tracking-universal.js'); } } else { if ($config->GoogleAnalyticsType == "Old Asynchronous Analytics") { // asynchronous analytics if (!self::$use_template) { // cookie domain $domain = ''; if ($config->GoogleAnalyticsCookieDomain && strlen(trim($config->GoogleAnalyticsCookieDomain)) > 0) { $domain = "_gaq.push(['_setDomainName', '" . trim($config->GoogleAnalyticsCookieDomain) . "']);"; } // page view url $pageview = "_gaq.push(['_trackPageview']);"; if ($urldata = $this->owner->getCustomPageViewUrl()) { if (is_array($urldata)) { $pageview = ""; // check if associative array if (array_keys($urldata) !== range(0, count($urldata) - 1)) { foreach ($urldata as $url => $title) { $pageview .= "_gaq.push(['_trackPageview', '{$url}']);"; } } else { foreach ($urldata as $url) { $pageview .= "_gaq.push(['_trackPageview', '{$url}']);"; } } } elseif (is_string($urldata)) { $pageview = "_gaq.push(['_trackPageview', '{$urldata}']);"; } } // tracking code Requirements::insertHeadTags("\n\t\t\t\t\t\t<script type=\"text/javascript\">\n\t\t\t\t\t\t\tvar _gaq = _gaq || [];\n\t\t\t\t\t\t\t_gaq.push(['_setAccount', '" . $config->GoogleAnalyticsID . "']);\n\t\t\t\t\t\t\t" . $domain . "\n\t\t\t\t\t\t\t" . $pageview . "\n\t\t\t\t\t\t\t(function() {\n\t\t\t\t\t\t\t\tvar ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\n\t\t\t\t\t\t\t\tga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n\t\t\t\t\t\t\t\tvar s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\n\t\t\t\t\t\t\t})();\n\t\t\t\t\t\t</script>\n\t\t\t\t\t"); } // event tracking if ($config->GoogleAnalyticsUseEventTracking) { Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.min.js'); Requirements::javascript(GOOGLEANALYTICS_DIR . '/javascript/event-tracking.js'); } } else { // google tag manager if (!self::$use_template) { $pageviews = array(); // virtual page view url if ($urldata = $this->owner->getCustomPageViewUrl()) { if (is_array($urldata)) { // check if associative array if (array_keys($urldata) !== range(0, count($urldata) - 1)) { foreach ($urldata as $url => $title) { $pageviews[] = array('virtualPageURL' => $url, 'virtualPageTitle' => $title); } } else { foreach ($urldata as $url) { $pageviews[] = array('virtualPageURL' => $url); } } } elseif (is_string($urldata)) { $pageviews[] = array('virtualPageURL' => $urldata); } if (count($pageviews)) { $tag = "<script>dataLayer = [];"; foreach ($pageviews as $pageview) { $tag .= "dataLayer.push({'event': 'VirtualPageview','virtualPageURL': '" . $pageview['virtualPageURL'] . "'"; if (isset($pageview['virtualPageTitle'])) { $tag .= ",'virtualPageTitle': '" . $pageview['virtualPageTitle'] . "'"; } $tag .= "});"; } $tag .= "</script>"; Requirements::insertHeadTags($tag); } } // tracking code Requirements::insertHeadTags("\n\t<noscript><iframe src=\"//www.googletagmanager.com/ns.html?id=" . $config->GoogleAnalyticsID . "\"\n\theight=\"0\" width=\"0\" style=\"display:none;visibility:hidden\"></iframe></noscript>\n\t<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':\n\tnew Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],\n\tj=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=\n\t'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);\n\t})(window,document,'script','dataLayer','" . $config->GoogleAnalyticsID . "');</script>\n\t\t\t\t\t"); } } } } }