本文整理汇总了PHP中Piwik_Config类的典型用法代码示例。如果您正苦于以下问题:PHP Piwik_Config类的具体用法?PHP Piwik_Config怎么用?PHP Piwik_Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Piwik_Config类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_callableApiMethods_doNotFail
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();
}
示例2: test_fetchRemoteFile
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);
}
示例3: getPurgeDataSettings
/**
* 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;
}
示例4: update
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());
}
示例5: setUp
public function setUp()
{
parent::setUp();
Piwik::createConfigObject();
Piwik_Config::getInstance()->setTestEnvironment();
Piwik_DataTable_Manager::getInstance()->deleteAll();
}
示例6: update
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>");
}
示例7: init
function init()
{
$config = Piwik_Config::getInstance();
$config->log['log_only_when_debug_parameter'] = 0;
$config->log['logger_message'] = array("logger_message" => "screen");
Piwik::createLogObject();
}
示例8: testAllSuperUserIncluded
/**
*
* @group Plugins
* @group UsersManager
*/
public function testAllSuperUserIncluded()
{
Piwik_Config::getInstance()->superuser = array('login' => 'superusertest', 'password' => 'passwordsuperusertest', 'email' => 'superuser@example.com');
$user = array('login' => 'user', 'password' => "geqgeagae", 'email' => "test@test.com", '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', 'fake@fale.co', 'ega');
$exceptionNotRaised = true;
} catch (Exception $expected) {
$this->assertRegExp("(UsersManager_ExceptionSuperUser)", $expected->getMessage());
}
try {
Piwik_UsersManager_API::getInstance()->updateUser('superusertest', 'te', 'fake@fale.co', 'ega');
$exceptionNotRaised = true;
} catch (Exception $expected) {
$this->assertRegExp("(UsersManager_ExceptionSuperUser)", $expected->getMessage());
}
try {
Piwik_UsersManager_API::getInstance()->deleteUser('superusertest', 'te', 'fake@fale.co', 'ega');
$exceptionNotRaised = true;
} catch (Exception $expected) {
$this->assertRegExp("(UsersManager_ExceptionSuperUser)", $expected->getMessage());
}
try {
Piwik_UsersManager_API::getInstance()->deleteUser('superusertest', 'te', 'fake@fale.co', 'ega');
$exceptionNotRaised = true;
} catch (Exception $expected) {
$this->assertRegExp("(UsersManager_ExceptionSuperUser)", $expected->getMessage());
}
if ($exceptionNotRaised) {
$this->fail();
}
}
示例9: test_getAcceptableOrigins
/**
* @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);
}
示例10: __construct
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');
}
}
示例11: sendRequest
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;
}
示例12: getInstance
/**
* Returns the singleton Piwik_Config
*
* @return Piwik_Config
*/
public static function getInstance()
{
if (self::$instance == null) {
self::$instance = new self();
}
return self::$instance;
}
示例13: setGeneralSettings
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;
}
示例14: authenticate
/**
* 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);
}
示例15: sendFeedback
/**
* 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, '<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();
}