setIsTrackerApiRequest() public static method

Mark the current request as a Tracker API request
public static setIsTrackerApiRequest ( )
Exemplo n.º 1
0
 private function makeTrackerInstance()
 {
     SettingsServer::setIsTrackerApiRequest();
     $storage = Factory::make('PluginName');
     SettingsServer::setIsNotTrackerApiRequest();
     return $storage;
 }
Exemplo n.º 2
0
require_once PIWIK_INCLUDE_PATH . '/core/Tracker/Cache.php';
require_once PIWIK_INCLUDE_PATH . '/core/Tracker/Request.php';
require_once PIWIK_INCLUDE_PATH . '/core/Cookie.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/Factory.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Base.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Generic.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Mysql/Generic.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Pgsql/Generic.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Mysql/LogAction.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Pgsql/LogAction.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Mysql/LogVisit.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Pgsql/LogVisit.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Mysql/LogLinkVisitAction.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Pgsql/LogLinkVisitAction.php';
// TODO should move to Tracker application class later. currently needed for environment validation.
SettingsServer::setIsTrackerApiRequest();
$environment = new \Piwik\Application\Environment('tracker');
$environment->init();
Tracker::loadTrackerEnvironment();
$tracker = new Tracker();
$requestSet = new RequestSet();
ob_start();
try {
    $handler = Handler\Factory::make();
    $response = $tracker->main($handler, $requestSet);
    if (!is_null($response)) {
        echo $response;
    }
} catch (Exception $e) {
    echo "Error:" . $e->getMessage();
    exit(1);
Exemplo n.º 3
0
 protected function sendRequest($url, $method = 'GET', $data = null, $force = false)
 {
     if ($this->DEBUG_APPEND_URL) {
         $url .= $this->DEBUG_APPEND_URL;
     }
     // if doing a bulk request, store the url
     if ($this->doBulkRequests && !$force) {
         $this->storedTrackingActions[] = $url;
         return true;
     }
     if ($method == 'POST') {
         $requests = array();
         foreach ($this->storedTrackingActions as $action) {
             $requests[] = $this->parseUrl($action);
         }
         $testEnvironmentArgs = array();
     } else {
         $testEnvironmentArgs = $this->parseUrl($url);
         $requests = array($testEnvironmentArgs);
     }
     // unset cached values
     Cache::$cache = null;
     Tracker\Visit::$dimensions = null;
     // save some values
     $plugins = Config::getInstance()->Plugins['Plugins'];
     $oldTrackerConfig = Config::getInstance()->Tracker;
     \Piwik\Plugin\Manager::getInstance()->unloadPlugins();
     // modify config
     \Piwik\SettingsServer::setIsTrackerApiRequest();
     $GLOBALS['PIWIK_TRACKER_LOCAL_TRACKING'] = true;
     Tracker::$initTrackerMode = false;
     Tracker::setTestEnvironment($testEnvironmentArgs, $method);
     // set language
     $oldLang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '';
     $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $this->acceptLanguage;
     // set user agent
     $oldUserAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
     $_SERVER['HTTP_USER_AGENT'] = $this->userAgent;
     // set cookie
     $oldCookie = $_COOKIE;
     //        parse_str(parse_url($this->requestCookie, PHP_URL_QUERY), $_COOKIE);
     // do tracking and capture output
     ob_start();
     $localTracker = new Tracker();
     $request = new Tracker\RequestSet();
     $request->setRequests($requests);
     \Piwik\Plugin\Manager::getInstance()->loadTrackerPlugins();
     $handler = Tracker\Handler\Factory::make();
     $response = $localTracker->main($handler, $request);
     if (!is_null($response)) {
         echo $response;
     }
     $output = ob_get_contents();
     ob_end_clean();
     // restore vars
     Config::getInstance()->Tracker = $oldTrackerConfig;
     $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $oldLang;
     $_SERVER['HTTP_USER_AGENT'] = $oldUserAgent;
     $_COOKIE = $oldCookie;
     $GLOBALS['PIWIK_TRACKER_LOCAL_TRACKING'] = false;
     \Piwik\SettingsServer::setIsNotTrackerApiRequest();
     unset($_GET['bots']);
     // reload plugins
     \Piwik\Plugin\Manager::getInstance()->loadPlugins($plugins);
     return $output;
 }
Exemplo n.º 4
0
 public static function loadTrackerEnvironment()
 {
     SettingsServer::setIsTrackerApiRequest();
     $GLOBALS['PIWIK_TRACKER_DEBUG'] = self::isDebugEnabled();
     PluginManager::getInstance()->loadTrackerPlugins();
 }
Exemplo n.º 5
0
 public function test_addSetting_shouldPassTrackerStorage_IfInTrackerMode()
 {
     $this->setSuperUser();
     SettingsServer::setIsTrackerApiRequest();
     $settings = $this->createSettingsInstance();
     $setting = $this->buildUserSetting('myname', 'mytitle', 'myRandomName');
     $settings->addSetting($setting);
     SettingsServer::setIsNotTrackerApiRequest();
     $storage = $setting->getStorage();
     $this->assertTrue($storage instanceof SettingsStorage);
 }