function test_callableApiMethods_doNotFail()
 {
     Piwik::createConfigObject();
     Piwik_Config::getInstance()->setTestEnvironment();
     Piwik::createLogObject();
     Piwik::createAccessObject();
     Piwik::createDatabaseObject();
     Piwik::setUserIsSuperUser();
     Piwik_Translate::getInstance()->loadEnglishTranslation();
     $pluginsManager = Piwik_PluginsManager::getInstance();
     $pluginsManager->loadPlugins(Piwik_Config::getInstance()->Plugins['Plugins']);
     Piwik_SitesManager_API::getInstance()->addSite("name", "http://example.org");
     $apiGenerator = new Piwik_API_DocumentationGenerator_CallAllMethods();
     $requestUrls = $apiGenerator->getAllRequestsWithParameters();
     $this->assertTrue(count($requestUrls) > 20);
     foreach ($requestUrls as $url) {
         $call = new Piwik_API_Request($url);
         $output = $call->process();
         //			var_dump($url);
         //			var_dump($output);
         $this->assertTrue(!empty($output));
     }
     Piwik_Translate::getInstance()->unloadEnglishTranslation();
     $this->pass();
 }
Ejemplo n.º 2
0
 public function test_fetchRemoteFile()
 {
     Piwik::createConfigObject();
     Piwik_Config::getInstance()->setTestEnvironment();
     $methods = array('curl', 'fopen', 'socket');
     $this->assertTrue(in_array(Piwik_Http::getTransportMethod(), $methods));
     foreach ($methods as $method) {
         $version = '';
         try {
             $version = Piwik_Http::sendHttpRequestBy($method, 'http://api.piwik.org/1.0/getLatestVersion/', 5);
         } catch (Exception $e) {
             var_dump($e->getMessage());
         }
         $this->assertTrue(preg_match('/^([0-9.]+)$/', $version), $method);
     }
     $destinationPath = PIWIK_USER_PATH . '/tmp/latest/LATEST';
     try {
         Piwik_Http::fetchRemoteFile('http://api.piwik.org/1.0/getLatestVersion/', $destinationPath, 3);
     } catch (Exception $e) {
         var_dump($e->getMessage());
     }
     $this->assertTrue(filesize($destinationPath) > 0);
     $destinationPath = PIWIK_USER_PATH . '/tmp/latest/latest.zip';
     try {
         Piwik_Http::fetchRemoteFile('http://piwik.org/latest.zip', $destinationPath, 3);
     } catch (Exception $e) {
         var_dump($e->getMessage());
     }
     $this->assertTrue(filesize($destinationPath) > 0);
 }
Ejemplo n.º 3
0
 /**
  * Returns the settings for the data purging feature.
  * 
  * @return array
  */
 public static function getPurgeDataSettings()
 {
     $settings = array();
     // load settings from ini config
     try {
         $oldSettings = array('enable_auto_database_size_estimate', 'delete_logs_enable', 'delete_logs_schedule_lowest_interval', 'delete_logs_older_than');
         $deleteLogsSettings = Piwik_Config::getInstance()->Deletelogs;
         foreach ($oldSettings as $settingName) {
             $settings[$settingName] = $deleteLogsSettings[$settingName];
         }
     } catch (Exception $e) {
         // ignore
     }
     // load the settings for the data purging settings
     foreach (self::$defaultPurgeDataOptions as $optionName => $defaultValue) {
         $value = Piwik_GetOption($optionName);
         if ($value !== false) {
             $settings[$optionName] = $value;
         } else {
             // if the option hasn't been set/created, use the default value
             if (!isset($settings[$optionName])) {
                 $settings[$optionName] = $defaultValue;
             }
             // option is not saved in the DB, so save it now
             Piwik_SetOption($optionName, $settings[$optionName]);
         }
     }
     return $settings;
 }
Ejemplo n.º 4
0
	static function update()
	{
		$config = Zend_Registry::get('config');
		$dbInfos = $config->database->toArray();
		if(!isset($dbInfos['schema']))
		{
			try {
				if(is_writable( Piwik_Config::getDefaultUserConfigPath() ))
				{
					$dbInfos['schema'] = 'Myisam';
					$config->database = $dbInfos;

					$config->__destruct();
					Piwik::createConfigObject();
				}
				else
				{
					throw new Exception('mandatory update failed');
				}
			} catch(Exception $e) {
				throw new Piwik_Updater_UpdateErrorException("Please edit your config/config.ini.php file and add below <code>[database]</code> the following line: <br /><code>schema = Myisam</code>");
			}
		}

		Piwik_Updater::updateDatabase(__FILE__, self::getSql());
	}
Ejemplo n.º 5
0
 public function setUp()
 {
     parent::setUp();
     Piwik::createConfigObject();
     Piwik_Config::getInstance()->setTestEnvironment();
     Piwik_DataTable_Manager::getInstance()->deleteAll();
 }
Ejemplo n.º 6
0
	static function update()
	{
		$config = Zend_Registry::get('config');
		$salt = Piwik_Common::generateUniqId();
		try {
			if(isset($config->superuser->salt))
			{
				return;
			}

			if(is_writable( Piwik_Config::getDefaultUserConfigPath() ))
			{
				$superuser_info = $config->superuser->toArray();
				$superuser_info['salt'] = $salt;
				$config->superuser = $superuser_info;
				$config->__destruct();

				Piwik::createConfigObject();

				return;
			}
		} catch(Exception $e) { }

		throw new Piwik_Updater_UpdateErrorException("Edit config.ini.php and add below <code>[superuser]</code> the following line <br/><code>salt = $salt</code>");
	}
 function init()
 {
     $config = Piwik_Config::getInstance();
     $config->log['log_only_when_debug_parameter'] = 0;
     $config->log['logger_message'] = array("logger_message" => "screen");
     Piwik::createLogObject();
 }
Ejemplo n.º 8
0
 /**
  * 
  * @group Plugins
  * @group UsersManager
  */
 public function testAllSuperUserIncluded()
 {
     Piwik_Config::getInstance()->superuser = array('login' => 'superusertest', 'password' => 'passwordsuperusertest', 'email' => '*****@*****.**');
     $user = array('login' => 'user', 'password' => "geqgeagae", 'email' => "*****@*****.**", 'alias' => "alias");
     Piwik_UsersManager_API::getInstance()->addUser($user['login'], $user['password'], $user['email'], $user['alias']);
     $exceptionNotRaised = false;
     try {
         Piwik_UsersManager_API::getInstance()->addUser('superusertest', 'te', '*****@*****.**', 'ega');
         $exceptionNotRaised = true;
     } catch (Exception $expected) {
         $this->assertRegExp("(UsersManager_ExceptionSuperUser)", $expected->getMessage());
     }
     try {
         Piwik_UsersManager_API::getInstance()->updateUser('superusertest', 'te', '*****@*****.**', 'ega');
         $exceptionNotRaised = true;
     } catch (Exception $expected) {
         $this->assertRegExp("(UsersManager_ExceptionSuperUser)", $expected->getMessage());
     }
     try {
         Piwik_UsersManager_API::getInstance()->deleteUser('superusertest', 'te', '*****@*****.**', 'ega');
         $exceptionNotRaised = true;
     } catch (Exception $expected) {
         $this->assertRegExp("(UsersManager_ExceptionSuperUser)", $expected->getMessage());
     }
     try {
         Piwik_UsersManager_API::getInstance()->deleteUser('superusertest', 'te', '*****@*****.**', 'ega');
         $exceptionNotRaised = true;
     } catch (Exception $expected) {
         $this->assertRegExp("(UsersManager_ExceptionSuperUser)", $expected->getMessage());
     }
     if ($exceptionNotRaised) {
         $this->fail();
     }
 }
Ejemplo n.º 9
0
 /**
  * @dataProvider getAcceptableOriginsTestData
  * @group Core
  * @group Nonce
  */
 public function test_getAcceptableOrigins($host, $expected)
 {
     Piwik_Config::getInstance()->General['enable_trusted_host_check'] = 0;
     $_SERVER['HTTP_HOST'] = $host;
     Piwik_Config::getInstance()->General['trusted_hosts'] = array('example.com');
     $this->assertEquals($expected, Piwik_Nonce::getAcceptableOrigins(), $host);
 }
Ejemplo n.º 10
0
 public function __construct($smConf = array(), $filter = true)
 {
     parent::__construct();
     if (count($smConf) == 0) {
         $smConf = Piwik_Config::getInstance()->smarty;
     }
     foreach ($smConf as $key => $value) {
         $this->{$key} = $value;
     }
     $this->template_dir = $smConf['template_dir'];
     array_walk($this->template_dir, array("Piwik_Smarty", "addPiwikPath"), PIWIK_INCLUDE_PATH);
     $this->plugins_dir = $smConf['plugins_dir'];
     array_walk($this->plugins_dir, array("Piwik_Smarty", "addPiwikPath"), PIWIK_INCLUDE_PATH);
     $this->compile_dir = $smConf['compile_dir'];
     Piwik_Smarty::addPiwikPath($this->compile_dir, null, PIWIK_USER_PATH);
     $this->cache_dir = $smConf['cache_dir'];
     Piwik_Smarty::addPiwikPath($this->cache_dir, null, PIWIK_USER_PATH);
     $error_reporting = $smConf['error_reporting'];
     if ($error_reporting != (string) (int) $error_reporting) {
         $error_reporting = self::bitwise_eval($error_reporting);
     }
     $this->error_reporting = $error_reporting;
     if ($filter) {
         $this->load_filter('output', 'cachebuster');
         $use_ajax_cdn = Piwik_Config::getInstance()->General['use_ajax_cdn'];
         if ($use_ajax_cdn) {
             $this->load_filter('output', 'ajaxcdn');
         }
         $this->load_filter('output', 'trimwhitespace');
     }
 }
Ejemplo n.º 11
0
 protected function sendRequest($url, $method = 'GET', $data = null, $force = false)
 {
     // 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
     Piwik_Common::$trackerCache = null;
     Piwik_Tracker::setForceIp(null);
     Piwik_Tracker::setForceDateTime(null);
     Piwik_Tracker::setForceVisitorId(null);
     // save some values
     $plugins = Piwik_Config::getInstance()->Plugins['Plugins'];
     $pluginsTracker = Piwik_Config::getInstance()->Plugins_Tracker['Plugins_Tracker'];
     $oldTrackerConfig = Piwik_Config::getInstance()->Tracker;
     Piwik_PluginsManager::getInstance()->unloadPlugins();
     // modify config
     $GLOBALS['PIWIK_TRACKER_MODE'] = true;
     $GLOBALS['PIWIK_TRACKER_LOCAL_TRACKING'] = true;
     Piwik_Common::$initTrackerMode = false;
     Piwik_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 Piwik_Tracker();
     $localTracker->main($requests);
     $output = ob_get_contents();
     ob_end_clean();
     // restore vars
     Piwik_Config::getInstance()->Plugins_Tracker['Plugins_Tracker'] = $pluginsTracker;
     Piwik_Config::getInstance()->Tracker = $oldTrackerConfig;
     $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $oldLang;
     $_SERVER['HTTP_USER_AGENT'] = $oldUserAgent;
     $_COOKIE = $oldCookie;
     $GLOBALS['PIWIK_TRACKER_LOCAL_TRACKING'] = false;
     $GLOBALS['PIWIK_TRACKER_MODE'] = false;
     unset($_GET['bots']);
     // reload plugins
     Piwik_PluginsManager::getInstance()->loadPlugins($plugins);
     return $output;
 }
Ejemplo n.º 12
0
 /**
  * Returns the singleton Piwik_Config
  *
  * @return Piwik_Config
  */
 public static function getInstance()
 {
     if (self::$instance == null) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Ejemplo n.º 13
0
 public function setGeneralSettings()
 {
     Piwik::checkUserIsSuperUser();
     $response = new Piwik_API_ResponseBuilder(Piwik_Common::getRequestVar('format'));
     try {
         $this->checkTokenInUrl();
         $enableBrowserTriggerArchiving = Piwik_Common::getRequestVar('enableBrowserTriggerArchiving');
         $todayArchiveTimeToLive = Piwik_Common::getRequestVar('todayArchiveTimeToLive');
         Piwik_ArchiveProcessing::setBrowserTriggerArchiving((bool) $enableBrowserTriggerArchiving);
         Piwik_ArchiveProcessing::setTodayArchiveTimeToLive($todayArchiveTimeToLive);
         // Update email settings
         $mail = array();
         $mail['transport'] = Piwik_Common::getRequestVar('mailUseSmtp') == '1' ? 'smtp' : '';
         $mail['port'] = Piwik_Common::getRequestVar('mailPort', '');
         $mail['host'] = Piwik_Common::unsanitizeInputValue(Piwik_Common::getRequestVar('mailHost', ''));
         $mail['type'] = Piwik_Common::getRequestVar('mailType', '');
         $mail['username'] = Piwik_Common::unsanitizeInputValue(Piwik_Common::getRequestVar('mailUsername', ''));
         $mail['password'] = Piwik_Common::unsanitizeInputValue(Piwik_Common::getRequestVar('mailPassword', ''));
         $mail['encryption'] = Piwik_Common::getRequestVar('mailEncryption', '');
         Piwik_Config::getInstance()->mail = $mail;
         // update branding settings
         Piwik_Config::getInstance()->branding['use_custom_logo'] = Piwik_Common::getRequestVar('useCustomLogo', '0');
         $toReturn = $response->getResponse();
     } catch (Exception $e) {
         $toReturn = $response->getResponseException($e);
     }
     echo $toReturn;
 }
Ejemplo n.º 14
0
    /**
     * Authenticates user
     *
     * @return Piwik_Auth_Result
     */
    public function authenticate()
    {
        $rootLogin = Piwik_Config::getInstance()->superuser['login'];
        $rootPassword = Piwik_Config::getInstance()->superuser['password'];
        $rootToken = Piwik_UsersManager_API::getInstance()->getTokenAuth($rootLogin, $rootPassword);
        if (is_null($this->login)) {
            if ($this->token_auth === $rootToken) {
                return new Piwik_Auth_Result(Piwik_Auth_Result::SUCCESS_SUPERUSER_AUTH_CODE, $rootLogin, $this->token_auth);
            }
            $login = Piwik_FetchOne('SELECT login
					FROM ' . Piwik_Common::prefixTable('user') . ' 
					WHERE token_auth = ?', array($this->token_auth));
            if (!empty($login)) {
                return new Piwik_Auth_Result(Piwik_Auth_Result::SUCCESS, $login, $this->token_auth);
            }
        } else {
            if (!empty($this->login)) {
                if ($this->login === $rootLogin && $this->getHashTokenAuth($rootLogin, $rootToken) === $this->token_auth || $rootToken === $this->token_auth) {
                    $this->setTokenAuth($rootToken);
                    return new Piwik_Auth_Result(Piwik_Auth_Result::SUCCESS_SUPERUSER_AUTH_CODE, $rootLogin, $this->token_auth);
                }
                $login = $this->login;
                $userToken = Piwik_FetchOne('SELECT token_auth
					FROM ' . Piwik_Common::prefixTable('user') . ' 
					WHERE login = ?', array($login));
                if (!empty($userToken) && ($this->getHashTokenAuth($login, $userToken) === $this->token_auth || $userToken === $this->token_auth)) {
                    $this->setTokenAuth($userToken);
                    return new Piwik_Auth_Result(Piwik_Auth_Result::SUCCESS, $login, $userToken);
                }
            }
        }
        return new Piwik_Auth_Result(Piwik_Auth_Result::FAILURE, $this->login, $this->token_auth);
    }
Ejemplo n.º 15
0
 /**
  * send email to Piwik team and display nice thanks
  */
 function sendFeedback()
 {
     $email = Piwik_Common::getRequestVar('email', '', 'string');
     $body = Piwik_Common::getRequestVar('body', '', 'string');
     $category = Piwik_Common::getRequestVar('category', '', 'string');
     $nonce = Piwik_Common::getRequestVar('nonce', '', 'string');
     $view = Piwik_View::factory('sent');
     $view->feedbackEmailAddress = Piwik_Config::getInstance()->General['feedback_email_address'];
     try {
         $minimumBodyLength = 40;
         if (strlen($body) < $minimumBodyLength || strpos($email, 'probe@') !== false || strpos($body, '&lt;probe') !== false) {
             throw new Exception(Piwik_TranslateException('Feedback_ExceptionBodyLength', array($minimumBodyLength)));
         }
         if (!Piwik::isValidEmailString($email)) {
             throw new Exception(Piwik_TranslateException('UsersManager_ExceptionInvalidEmail'));
         }
         if (preg_match('/https?:/i', $body)) {
             throw new Exception(Piwik_TranslateException('Feedback_ExceptionNoUrls'));
         }
         if (!Piwik_Nonce::verifyNonce('Piwik_Feedback.sendFeedback', $nonce)) {
             throw new Exception(Piwik_TranslateException('General_ExceptionNonceMismatch'));
         }
         Piwik_Nonce::discardNonce('Piwik_Feedback.sendFeedback');
         $mail = new Piwik_Mail();
         $mail->setFrom(Piwik_Common::unsanitizeInputValue($email));
         $mail->addTo($view->feedbackEmailAddress, 'Piwik Team');
         $mail->setSubject('[ Feedback form - Piwik ] ' . $category);
         $mail->setBodyText(Piwik_Common::unsanitizeInputValue($body) . "\n" . 'Piwik ' . Piwik_Version::VERSION . "\n" . 'IP: ' . Piwik_IP::getIpFromHeader() . "\n" . 'URL: ' . Piwik_Url::getReferer() . "\n");
         @$mail->send();
     } catch (Exception $e) {
         $view->ErrorString = $e->getMessage();
         $view->message = $body;
     }
     echo $view->render();
 }
Ejemplo n.º 16
0
 function index()
 {
     Piwik::checkUserIsSuperUser();
     $plugins = array();
     $listPlugins = array_merge(Piwik_PluginsManager::getInstance()->readPluginsDirectory(), Piwik_Config::getInstance()->Plugins['Plugins']);
     $listPlugins = array_unique($listPlugins);
     foreach ($listPlugins as $pluginName) {
         $oPlugin = Piwik_PluginsManager::getInstance()->loadPlugin($pluginName);
         $plugins[$pluginName] = array('activated' => Piwik_PluginsManager::getInstance()->isPluginActivated($pluginName), 'alwaysActivated' => Piwik_PluginsManager::getInstance()->isPluginAlwaysActivated($pluginName));
     }
     Piwik_PluginsManager::getInstance()->loadPluginTranslations();
     $loadedPlugins = Piwik_PluginsManager::getInstance()->getLoadedPlugins();
     foreach ($loadedPlugins as $oPlugin) {
         $pluginName = $oPlugin->getPluginName();
         $plugins[$pluginName]['info'] = $oPlugin->getInformation();
     }
     foreach ($plugins as $pluginName => &$plugin) {
         if (!isset($plugin['info'])) {
             $plugin['info'] = array('description' => '<strong><em>' . Piwik_Translate('CorePluginsAdmin_PluginCannotBeFound') . '</strong></em>', 'version' => Piwik_Translate('General_Unknown'));
         }
     }
     $view = Piwik_View::factory('manage');
     $view->pluginsName = $plugins;
     $this->setBasicVariablesView($view);
     $view->menu = Piwik_GetAdminMenu();
     if (!Piwik_Config::getInstance()->isFileWritable()) {
         $view->configFileNotWritable = true;
     }
     echo $view->render();
 }
Ejemplo n.º 17
0
 static function update()
 {
     $salt = Piwik_Common::generateUniqId();
     if (!isset(Piwik_Config::getInstance()->superuser['salt'])) {
         try {
             if (is_writable(Piwik_Config::getLocalConfigPath())) {
                 Piwik_Config::getInstance()->setConfigOption('superuser', 'salt', $salt);
                 Piwik_Config::getInstance()->forceSave();
             } else {
                 throw new Exception('mandatory update failed');
             }
         } catch (Exception $e) {
             throw new Piwik_Updater_UpdateErrorException("Please edit your config/config.ini.php file and add below <code>[superuser]</code> the following line: <br /><code>salt = {$salt}</code>");
         }
     }
     $plugins = Piwik_Config::getInstance()->Plugins;
     if (!in_array('MultiSites', $plugins)) {
         try {
             if (is_writable(Piwik_Config::getLocalConfigPath())) {
                 $plugins[] = 'MultiSites';
                 Piwik_Config::getInstance()->setConfigSection('Plugins', $plugins);
                 Piwik_Config::getInstance()->forceSave();
             } else {
                 throw new Exception('optional update failed');
             }
         } catch (Exception $e) {
             throw new Exception("You can now enable the new MultiSites plugin in the Plugins screen in the Piwik admin!");
         }
     }
     Piwik_Updater::updateDatabase(__FILE__, self::getSql());
 }
Ejemplo n.º 18
0
 /**
  * Check MySQL version
  *
  * @throws Exception
  */
 public function checkServerVersion()
 {
     $serverVersion = $this->getServerVersion();
     $requiredVersion = Piwik_Config::getInstance()->General['minimum_mysql_version'];
     if (version_compare($serverVersion, $requiredVersion) === -1) {
         throw new Exception(Piwik_TranslateException('General_ExceptionDatabaseVersion', array('MySQL', $serverVersion, $requiredVersion)));
     }
 }
Ejemplo n.º 19
0
    static function getSql($schema = 'Myisam')
    {
        return array('ALTER DATABASE `' . Piwik_Config::getInstance()->database['dbname'] . '` DEFAULT CHARACTER SET utf8' => false, 'ALTER TABLE `' . Piwik_Common::prefixTable('log_visit') . '` 
				DROP INDEX index_idsite_datetime_config,
				DROP INDEX index_idsite_idvisit,
				ADD INDEX index_idsite_config_datetime (idsite, config_id, visit_last_action_time),
				ADD INDEX index_idsite_datetime (idsite, visit_last_action_time)' => false);
    }
Ejemplo n.º 20
0
 public function setUp()
 {
     parent::setUp();
     $userFile = dirname(__FILE__) . '/Action.config.ini.php';
     $config = Piwik_Config::getInstance();
     $config->clear();
     $config->setTestEnvironment($userFile, false);
 }
Ejemplo n.º 21
0
 public function testWritingConfigWithSpecialCharacters()
 {
     $userFile = PIWIK_INCLUDE_PATH . '/tests/resources/Config/config.written.ini.php';
     $globalFile = PIWIK_INCLUDE_PATH . '/tests/resources/Config/global.ini.php';
     $config = new Piwik_Config($userFile, $globalFile);
     $config->init();
     $stringWritten = '&6^ geagea\'\'\'";;&';
     $config->Category = array('test' => $stringWritten);
     $this->assertEqual($config->Category->test, $stringWritten);
     unset($config);
     $config = new Piwik_Config($userFile, $globalFile);
     $config->init();
     $this->assertEqual($config->Category->test, $stringWritten);
     $config->Category = array('test' => $config->Category->test, 'test2' => $stringWritten);
     $this->assertEqual($config->Category->test, $stringWritten);
     $this->assertEqual($config->Category->test2, $stringWritten);
 }
Ejemplo n.º 22
0
 /**
  * Guesses a visitor's location using a visitor's browser language.
  * 
  * @param array $info Contains 'ip' & 'lang' keys.
  * @return array Contains the guessed country code mapped to LocationProvider::COUNTRY_CODE_KEY.
  */
 public function getLocation($info)
 {
     $enableLanguageToCountryGuess = Piwik_Config::getInstance()->Tracker['enable_language_to_country_guess'];
     $country = Piwik_Common::getCountry($info['lang'], $enableLanguageToCountryGuess, $info['ip']);
     $location = array(parent::COUNTRY_CODE_KEY => $country);
     $this->completeLocationResult($location);
     return $location;
 }
Ejemplo n.º 23
0
 function setUp()
 {
     parent::setUp();
     $GLOBALS['PIWIK_TRACKER_MODE'] = true;
     $userFile = PIWIK_PATH_TEST_TO_ROOT . '/tests/resources/Tracker/Action.config.ini.php';
     $config = Piwik_Config::getInstance();
     $config->setTestEnvironment($userFile);
 }
Ejemplo n.º 24
0
 /**
  * @dataProvider getCurrentHosts
  * @group Core
  * @group Url
  */
 public function testGetCurrentHost($description, $test)
 {
     $_SERVER['HTTP_HOST'] = $test[0];
     $_SERVER['HTTP_X_FORWARDED_HOST'] = $test[1];
     Piwik_Config::getInstance()->General['proxy_host_headers'] = array($test[2]);
     Piwik_Config::getInstance()->General['proxy_ips'] = array($test[3]);
     $this->assertEquals($test[4], Piwik_Url::getCurrentHost(), $description);
 }
Ejemplo n.º 25
0
 /**
  * Set the minimal variables in the view object
  * Extended by some admin view specific variables
  * 
  * @param Piwik_View  $view
  */
 protected function setBasicVariablesView($view)
 {
     parent::setBasicVariablesView($view);
     $view->currentAdminMenuName = Piwik_GetCurrentAdminMenuName();
     $view->enableFrames = Piwik_Config::getInstance()->General['enable_framed_settings'];
     if (!$view->enableFrames) {
         $view->setXFrameOptions('sameorigin');
     }
 }
Ejemplo n.º 26
0
 public function test_isAcceptableRemoteUrl()
 {
     Piwik::createConfigObject();
     Piwik_Config::getInstance()->setTestEnvironment();
     $data = array('http://piwik.org/' => array(true), 'http://piwik.org' => array(true), 'http://qa.piwik.org/' => array(true), 'http://forum.piwik.org/' => array(true), 'http://dev.piwik.org/' => array(true), 'http://demo.piwik.org/' => array(true), 'http://www.piwik.org/' => array(false), 'https://piwik.org/' => array(false), 'http://example.org/' => array(false));
     foreach ($data as $url => $expected) {
         $this->assertEqual(Piwik_Proxy_Controller::isPiwikUrl($url), $expected[0], $url);
     }
 }
/**
 * Smarty AJAX Libraries CDN outputfilter plugin
 *
 * File:     outputfilter.ajaxcdn.php<br>
 * Type:     outputfilter<br>
 * Name:     ajaxcdn<br>
 * Date:     Oct 13, 2009<br>
 * Purpose:  use AJAX Libraries Content Distribution Network<br>
 * Install:  Drop into the plugin directory, call
 *           <code>$smarty->load_filter('output','ajaxcdn');</code>
 *           from application.
 *
 * @param string
 * @param Smarty
 */
function smarty_outputfilter_ajaxcdn($source, &$smarty)
{
    $jquery_version = Piwik_Config::getInstance()->General['jquery_version'];
    $jqueryui_version = Piwik_Config::getInstance()->General['jqueryui_version'];
    $swfobject_version = Piwik_Config::getInstance()->General['swfobject_version'];
    $pattern = array('~<link rel="stylesheet" type="text/css" href="libs/jquery/themes/([^"]*)" />~', '~<script type="text/javascript" src="libs/jquery/jquery\\.js([^"]*)">~', '~<script type="text/javascript" src="libs/jquery/jquery-ui\\.js([^"]*)">~', '~<script type="text/javascript" src="libs/jquery/jquery-ui-18n\\.js([^"]*)">~', '~<script type="text/javascript" src="libs/swfobject/swfobject\\.js([^"]*)">~');
    $replace = array('<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/' . $jqueryui_version . '/themes/\\1" />', '<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/' . $jquery_version . '/jquery.min.js">', '<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/' . $jqueryui_version . '/jquery-ui.min.js">', '<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/' . $jqueryui_version . '/i18n/jquery-ui-18n.min.js">', '<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/' . $swfobject_version . '/swfobject.js">');
    return preg_replace($pattern, $replace, $source);
}
Ejemplo n.º 28
0
 public function setUp()
 {
     parent::setUp();
     $userFile = dirname(__FILE__) . '/Action.config.ini.php';
     $config = Piwik_Config::getInstance();
     $config->clear();
     $config->setTestEnvironment($userFile, false);
     Piwik_PluginsManager::getInstance()->loadPlugins(array('SitesManager'));
 }
Ejemplo n.º 29
0
 /**
  * @see Piwik_ViewDataTable::init()
  * @param string $currentControllerName
  * @param string $currentControllerAction
  * @param string $apiMethodToRequestDataTable
  * @param null|string $controllerActionCalledWhenRequestSubTable
  */
 function init($currentControllerName, $currentControllerAction, $apiMethodToRequestDataTable, $controllerActionCalledWhenRequestSubTable = null)
 {
     parent::init($currentControllerName, $currentControllerAction, $apiMethodToRequestDataTable, $controllerActionCalledWhenRequestSubTable);
     $this->dataTableTemplate = 'CoreHome/templates/datatable.tpl';
     $this->variablesDefault['enable_sort'] = '1';
     $this->setSortedColumn('nb_visits', 'desc');
     $this->setLimit(Piwik_Config::getInstance()->General['datatable_default_limit']);
     $this->handleLowPopulation();
 }
Ejemplo n.º 30
0
 public function initFilters()
 {
     $this->load_filter('output', 'cachebuster');
     $use_ajax_cdn = Piwik_Config::getInstance()->General['use_ajax_cdn'];
     if ($use_ajax_cdn) {
         $this->load_filter('output', 'ajaxcdn');
     }
     $this->load_filter('output', 'trimwhitespace');
 }