Beispiel #1
0
 public function updateTracker()
 {
     try {
         $trackerUpdater = new TrackerUpdater();
         $trackerUpdater->update();
     } catch (\Exception $e) {
         Log::error('There was an error while updating the javascript tracker: ' . $e->getMessage());
     }
 }
Beispiel #2
0
 /**
  * Detects whether plugin trackers will be automatically added to piwik.js or not. If not, the plugin tracker files
  * need to be loaded manually.
  * @return bool
  */
 public function doesIncludePluginTrackersAutomatically()
 {
     Piwik::checkUserHasSomeAdminAccess();
     try {
         $updater = new TrackerUpdater();
         $updater->checkWillSucceed();
         return true;
     } catch (AccessDeniedException $e) {
         return false;
     } catch (\Exception $e) {
         return false;
     }
 }
Beispiel #3
0
 public function updateTracker($sourceFile, $targetFile, $ignoreMinified)
 {
     $pluginTrackerFiles = new PluginTrackerFiles();
     if ($ignoreMinified) {
         if (empty($sourceFile) || $sourceFile === $this->getPathOriginalPiwikJs()) {
             // no custom source file was requested
             $sourceFile = PIWIK_DOCUMENT_ROOT . TrackerUpdater::DEVELOPMENT_PIWIK_JS;
         }
         $pluginTrackerFiles->ignoreMinified();
     }
     $updater = new TrackerUpdater($sourceFile, $targetFile);
     $updater->setTrackerFiles($pluginTrackerFiles);
     $updater->checkWillSucceed();
     $updater->update();
 }
Beispiel #4
0
// between requests so the browser knows it is the same file and know where to breakpoint.
//$cacheBuster= 'nocb'; // uncomment to debug
$root = dirname(__FILE__) . '/../..';
try {
    $mysql = (include_once $root . "/tests/PHPUnit/bootstrap.php");
} catch (Exception $e) {
    echo 'alert("' . $e->getMessage() . '")';
    $mysql = false;
}
use Piwik\Plugins\CustomPiwikJs\TrackerUpdater;
use Piwik\Plugins\CustomPiwikJs\TrackingCode\JsTestPluginTrackerFiles;
$targetFileName = '/tests/resources/piwik.test.js';
$sourceFile = PIWIK_DOCUMENT_ROOT . TrackerUpdater::DEVELOPMENT_PIWIK_JS;
$targetFile = PIWIK_DOCUMENT_ROOT . $targetFileName;
file_put_contents($targetFile, '');
$updater = new TrackerUpdater($sourceFile, $targetFile);
$updater->setTrackerFiles(new JsTestPluginTrackerFiles());
$updater->checkWillSucceed();
$updater->update();
if (file_exists("stub.tpl")) {
    echo file_get_contents("stub.tpl");
}
?>
 <script type="text/javascript">
function getToken() {
    return "<?php 
$token = md5(uniqid(mt_rand(), true));
echo $token;
?>
";
}
Beispiel #5
0
 private static function isModifiedPathValid($path)
 {
     if ($path === 'piwik.js') {
         // we could have used a postEvent hook to enrich "\Piwik\Manifest::$files;" which would also benefit plugins
         // that want to check for file integrity but we do not want to risk to break anything right now. It is not
         // as trivial because piwik.js might be already updated, or updated on the next request. We cannot define
         // 2 or 3 different filesizes and md5 hashes for one file so we check it here.
         if (Plugin\Manager::getInstance()->isPluginActivated('CustomPiwikJs')) {
             $trackerUpdater = new TrackerUpdater();
             if ($trackerUpdater->getCurrentTrackerFileContent() === $trackerUpdater->getUpdatedTrackerFileContent()) {
                 // file was already updated, eg manually or via custom piwik.js, this is a valid piwik.js file as
                 // it was enriched by tracker plugins
                 return true;
             }
             try {
                 // the piwik.js tracker file was not updated yet, but may be updated just after the update by
                 // one of the events CustomPiwikJs is listening to or by a scheduled task.
                 // In this case, we check whether such an update will succeed later and if it will, the file is
                 // valid as well as it will be updated on the next request
                 $trackerUpdater->checkWillSucceed();
                 return true;
             } catch (AccessDeniedException $e) {
                 return false;
             }
         }
     }
     return false;
 }