/**
  * The actual update function. Add your update task in here
  *
  * @return void
  */
 protected function processUpdates()
 {
     $report = Tools::updateJavaScript();
     if ($report['error']) {
         $this->messageArray[] = [FlashMessage::ERROR, 'ERROR', $report['message']];
     } else {
         $this->messageArray[] = [FlashMessage::OK, 'OK', $report['message']];
     }
 }
Exemplo n.º 2
0
 /**
  * This is the main method that is called when a task is executed
  *
  * @return bool Returns true on successful execution, false on error
  */
 public function execute()
 {
     $report = Tools::updateJavaScript();
     if ($report['error']) {
         return false;
     } else {
         return true;
     }
 }
Exemplo n.º 3
0
 /**
  * Insert javascript-tags for google-analytics
  *
  * @param array $params
  * @param \TYPO3\CMS\Core\Page\PageRenderer $pObj
  * @return void
  */
 public function renderPreProcess($params, $pObj)
 {
     if (TYPO3_MODE === 'FE') {
         // Get plugin-configuration
         $conf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_libjsanalytics.']['settings.'];
         // Exclude the analytics-snippet on some pages
         $pageExclude = GeneralUtility::trimExplode(',', $conf['pageExclude'], true);
         // Generate script-tag for google-analytics if enabled
         if ((int) $conf['enable'] && !in_array($GLOBALS['TSFE']->id, $pageExclude)) {
             $analyticsPreScript = '';
             $analyticsPostScript = '';
             // Instruct analytics.js to use the name defined in typoscript
             if (!empty($conf['gaObjectName']) && $conf['gaObjectName'] !== 'ga') {
                 $gaObjectName = $conf['gaObjectName'];
             } else {
                 $gaObjectName = 'ga';
             }
             // Get filePath to analytics.js
             $analyticsJavascriptFile = Tools::getConfParam('localFile');
             if ($conf['forceCdn'] || !file_exists(PATH_site . $analyticsJavascriptFile)) {
                 $analyticsJavascriptFile = Tools::getConfParam('sourceFile');
             } else {
                 // If local file is not available, fall back to CDN
                 if (empty($analyticsJavascriptFile)) {
                     $analyticsJavascriptFile = Tools::getConfParam('sourceFile');
                 } else {
                     // Prefix file with absRefPrefix if path is relative
                     if (!GeneralUtility::isAbsPath($analyticsJavascriptFile)) {
                         $analyticsJavascriptFile = $GLOBALS['TSFE']->absRefPrefix . $analyticsJavascriptFile;
                     }
                     // Append filename with version numbers
                     $analyticsJavascriptFile = GeneralUtility::createVersionNumberedFilename($analyticsJavascriptFile);
                 }
             }
             // Insert different codeblocks for different integration (old/new)
             if ((int) $conf['alternative']) {
                 if ($conf['gaObjectName'] !== 'ga') {
                     $scriptTag .= LF . 'window.GoogleAnalyticsObject = \'' . $gaObjectName . '\';';
                 }
                 // Create an initial analytics() function
                 // The queued commands will be executed once analytics.js loads
                 $scriptTag .= LF . 'window.' . $gaObjectName . ' = window.' . $gaObjectName . ' || function() {' . '(' . $gaObjectName . '.q = ' . $gaObjectName . '.q || []).push(arguments)};';
                 // Set the time (as an integer) this tag was executed (Used for timing hits)
                 $scriptTag .= LF . $gaObjectName . '.l =+ new Date;';
                 // Compile final script-tag for analytics.js
                 $analyticsPostScript = LF . '<script src="' . $analyticsJavascriptFile . '" type="text/javascript" async="async"></script>';
             } else {
                 // Compile final script-tag for analytics.js
                 $analyticsPreScript = LF . '(function(i,s,o,g,r,a,m){i[\'GoogleAnalyticsObject\']=r;i[r]=i[r]||function(){' . LF . '(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),' . LF . 'm=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)' . LF . '})(window,document,\'script\',\'' . $analyticsJavascriptFile . '\',\'' . $gaObjectName . '\');';
             }
             // Create the tracker
             foreach ($conf['gaObject.'] as $gaName => $gaTracker) {
                 // Set the name of the tracker if defined in typoscript
                 $trackerName = '';
                 if ($gaName !== 'default.') {
                     $trackerName = $gaName;
                 }
                 // Check if analytics objects are defined
                 if (is_array($gaTracker)) {
                     $scriptTag .= $this->iterateTrackerMethods($gaObjectName, $trackerName, $gaTracker);
                 }
             }
             // TEST/TODO
             // Add additional javascript to a single page if defined in PageTSConfig
             //debug($GLOBALS['TSFE']->page['TSconfig']);
             /*
              $pageTS = BackendUtility::getPagesTSconfig($GLOBALS['TSFE']->id, [$GLOBALS['TSFE']->id]);
              if (isset($pageTS['tx_libjsanalytics.'])) {
              $analyticsPageTS = $pageTS['tx_libjsanalytics.'];
              if (is_array($analyticsPageTS['additionalScript.'])) {
              $scriptTag .= LF . $this->getCobject($analyticsPageTS['additionalScript'], $analyticsPageTS['additionalScript.']);
              }
              }
             */
             // Compile final codeblock
             $scriptTag = '<script type="text/javascript">' . LF . '/*<![CDATA[*/' . $analyticsPreScript . $scriptTag . LF . '/*]]>*/' . LF . '</script>' . $analyticsPostScript;
             // Add final code to HTML
             $pObj->addHeaderData($scriptTag);
         }
     }
 }
Exemplo n.º 4
0
 /**
  *
  */
 private static function setReport($error, $languageKey, $replacement = [])
 {
     $message = LocalizationUtility::translate('tools.' . $languageKey, self::$extensionKey, $replacement);
     self::$report['error'] = $error;
     self::$report['message'] = $message;
     if ($error) {
         Tools::getLogger(__CLASS__)->error($message);
     }
 }