/** * Handles the request to the API. * It first checks that the method called (parameter 'method') is available in the module (it means that the method exists and is public) * It then reads the parameters from the request string and throws an exception if there are missing parameters. * It then calls the API Proxy which will call the requested method. * * @return mixed The data resulting from the API call */ public function process() { // read the format requested for the output data $outputFormat = strtolower(Piwik_Common::getRequestVar('format', 'xml', 'string', $this->request)); // create the response $response = new Piwik_API_ResponseBuilder($this->request, $outputFormat); try { // read parameters $moduleMethod = Piwik_Common::getRequestVar('method', null, null, $this->request); list($module, $method) = $this->extractModuleAndMethod($moduleMethod); if (!Piwik_PluginsManager::getInstance()->isPluginActivated($module)) { throw new Piwik_FrontController_PluginDeactivatedException($module); } $module = "Piwik_" . $module . "_API"; // if a token_auth is specified in the API request, we load the right permissions $token_auth = Piwik_Common::getRequestVar('token_auth', '', 'string', $this->request); if ($token_auth) { Piwik_PostEvent('API.Request.authenticate', $token_auth); Zend_Registry::get('access')->reloadAccess(); } // call the method $returnedValue = Piwik_API_Proxy::getInstance()->call($module, $method, $this->request); $toReturn = $response->getResponse($returnedValue); } catch (Exception $e) { $toReturn = $response->getResponseException($e); } return $toReturn; }
static function update() { try { Piwik_PluginsManager::getInstance()->activatePlugin('CustomVariables'); } catch (Exception $e) { } }
function dispatch() { $language = Piwik_Common::getRequestVar('language', '', 'string'); if($language != '') { $updaterController = new Piwik_CoreUpdater_Controller(); $updaterController->saveLanguage(); exit; } $updater = new Piwik_Updater(); $updater->addComponentToCheck('core', Piwik_Version::VERSION); $plugins = Piwik_PluginsManager::getInstance()->getInstalledPlugins(); foreach($plugins as $pluginName => $plugin) { $updater->addComponentToCheck($pluginName, $plugin->getVersion()); } $componentsWithUpdateFile = $updater->getComponentsWithUpdateFile(); if(count($componentsWithUpdateFile) == 0) { return; } $updaterController = new Piwik_CoreUpdater_Controller(); $updaterController->runUpdaterAndExit($updater, $componentsWithUpdateFile); }
/** * Returns the singleton Piwik_PluginsManager * * @return Piwik_PluginsManager */ public static function getInstance() { if (self::$instance == null) { self::$instance = new self(); } return self::$instance; }
static function update() { // first we disable the plugins and keep an array of warnings messages $pluginsToDisableMessage = array( 'SearchEnginePosition' => "SearchEnginePosition plugin was disabled, because it is not compatible with the new Piwik 0.6. \n You can download the latest version of the plugin, compatible with Piwik 0.6.\n<a target='_blank' href='?module=Proxy&action=redirect&url=http://dev.piwik.org/trac/ticket/502'>Click here.</a>", 'GeoIP' => "GeoIP plugin was disabled, because it is not compatible with the new Piwik 0.6. \nYou can download the latest version of the plugin, compatible with Piwik 0.6.\n<a target='_blank' href='?module=Proxy&action=redirect&url=http://dev.piwik.org/trac/ticket/45'>Click here.</a>" ); $disabledPlugins = array(); foreach($pluginsToDisableMessage as $pluginToDisable => $warningMessage) { if(Piwik_PluginsManager::getInstance()->isPluginActivated($pluginToDisable)) { Piwik_PluginsManager::getInstance()->deactivatePlugin($pluginToDisable); $disabledPlugins[] = $warningMessage; } } // Run the SQL Piwik_Updater::updateDatabase(__FILE__, self::getSql()); // Outputs warning message, pointing users to the plugin download page if(!empty($disabledPlugins)) { throw new Exception("The following plugins were disabled during the upgrade:" ."<ul><li>" . implode('</li><li>', $disabledPlugins) . "</li></ul>"); } }
function worldMap() { if (!Piwik_PluginsManager::getInstance()->isPluginActivated('UserCountry')) { return ''; } $idSite = Piwik_Common::getRequestVar('idSite', 1, 'int'); Piwik::checkUserHasViewAccess($idSite); $period = Piwik_Common::getRequestVar('period'); $date = Piwik_Common::getRequestVar('date'); $token_auth = Piwik::getCurrentUserTokenAuth(); $view = Piwik_View::factory('worldmap'); $view->dataUrl = "?module=API" . "&method=API.getProcessedReport&format=XML" . "&apiModule=UserCountry&apiAction=getCountry" . "&idSite=" . $idSite . "&period=" . $period . "&date=" . $date . "&token_auth=" . $token_auth . "&segment=" . Piwik_Common::unsanitizeInputValue(Piwik_Common::getRequestVar('segment', '')) . "&filter_limit=-1"; // definition of the color scale $view->hueMin = 218; $view->hueMax = 216; $view->satMin = "0.285"; $view->satMax = "0.9"; $view->lgtMin = ".97"; $view->lgtMax = ".44"; $request = new Piwik_API_Request('method=API.getMetadata&format=PHP' . '&apiModule=UserCountry&apiAction=getCountry' . '&idSite=' . $idSite . '&period=' . $period . '&date=' . $date . '&token_auth=' . $token_auth . '&filter_limit=-1'); $metaData = $request->process(); $metrics = array(); foreach ($metaData[0]['metrics'] as $id => $val) { if (Piwik_Common::getRequestVar('period') == 'day' || $id != 'nb_uniq_visitors') { $metrics[] = array($id, $val); } } foreach ($metaData[0]['processedMetrics'] as $id => $val) { $metrics[] = array($id, $val); } $view->metrics = $metrics; $view->defaultMetric = 'nb_visits'; echo $view->render(); }
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(); }
/** * Returns array containing data about the website: goals, URLs, etc. * * @param int $idSite * @return array */ static function getCacheWebsiteAttributes($idSite) { require_once PIWIK_INCLUDE_PATH . '/core/Loader.php'; static $cache = null; if (is_null($cache)) { $cache = new Piwik_CacheFile('tracker'); } $filename = $idSite; $cacheContent = $cache->get($filename); if ($cacheContent !== false) { return $cacheContent; } if (defined('PIWIK_TRACKER_MODE') && PIWIK_TRACKER_MODE) { require_once PIWIK_INCLUDE_PATH . '/core/PluginsManager.php'; require_once PIWIK_INCLUDE_PATH . '/core/Translate.php'; require_once PIWIK_INCLUDE_PATH . '/core/Option.php'; Zend_Registry::set('db', Piwik_Tracker::getDatabase()); Piwik::createAccessObject(); Piwik::createConfigObject(); Piwik::setUserIsSuperUser(); $pluginsManager = Piwik_PluginsManager::getInstance(); $pluginsManager->setPluginsToLoad(Zend_Registry::get('config')->Plugins->Plugins->toArray()); } $content = array(); Piwik_PostEvent('Common.fetchWebsiteAttributes', $content, $idSite); // if nothing is returned from the plugins, we don't save the content // this is not expected: all websites are expected to have at least one URL if (!empty($content)) { $cache->set($filename, $content); } return $content; }
function activate() { Piwik::checkUserIsSuperUser(); $pluginName = Piwik_Common::getRequestVar('pluginName', null, 'string'); Piwik_PluginsManager::getInstance()->activatePlugin($pluginName); Piwik_Url::redirectToUrl('index.php?module=CorePluginsAdmin'); }
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; }
static function update() { try { Piwik_PluginsManager::getInstance()->activatePlugin('PrivacyManager'); } catch (Exception $e) { } }
static function update() { Piwik_Updater::updateDatabase(__FILE__, self::getSql()); try { Piwik_PluginsManager::getInstance()->activatePlugin('Transitions'); } catch (Exception $e) { } }
/** * Returns the singleton Piwik_PluginsManager * * @return Piwik_PluginsManager */ public static function getInstance() { if (self::$instance == null) { $c = __CLASS__; self::$instance = new $c(); } return self::$instance; }
public function activate() { Piwik::checkUserIsSuperUser(); $this->checkTokenInUrl(); $pluginName = Piwik_Common::getRequestVar('pluginName', null, 'string'); Piwik_PluginsManager::getInstance()->activatePlugin($pluginName); Piwik_Url::redirectToReferer(); }
function __construct() { parent::__construct(); Piwik_Config::getInstance()->setTestEnvironment(); Piwik_PluginsManager::getInstance()->unloadPlugins(); Piwik_PluginsManager::getInstance()->loadPlugins(array('LanguagesManager')); $plugin = Piwik_PluginsManager::getInstance()->getLoadedPlugin('LanguagesManager'); $plugin->install(); }
public function setUp() { parent::setUp(); // setup the access layer $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = true; Zend_Registry::set('access', $pseudoMockAccess); Piwik_PluginsManager::getInstance()->loadPlugins(array('SitesManager')); }
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')); }
function addNewFunnel() { $view = Piwik_View::factory('add_new_funnel'); $this->setGeneralVariablesView($view); $view->goalsPluginDeactived = !Piwik_PluginsManager::getInstance()->isPluginActivated('Goals'); $view->userCanEditFunnels = Piwik::isUserHasAdminAccess($this->idSite); $view->onlyShowAddNewFunnel = true; $view->goalsWithoutFunnels = Piwik_Funnels_API::getInstance()->getGoalsWithoutFunnels($this->idSite); echo $view->render(); }
public function reloadLanguage($language = false) { if (empty($language)) { $language = $this->getLanguageToLoad(); } $this->unloadEnglishTranslation(); $this->loadEnglishTranslation(); $this->loadCoreTranslation($language); Piwik_PluginsManager::getInstance()->loadPluginTranslations($language); }
public function ecommerceReport() { if (!Piwik_PluginsManager::getInstance()->isPluginActivated('CustomVariables')) { throw new Exception("Ecommerce Tracking requires that the plugin Custom Variables is enabled. Please enable the plugin CustomVariables (or ask your admin)."); } $view = $this->getGoalReportView($idGoal = Piwik_Archive::LABEL_ECOMMERCE_ORDER); $view->displayFullReport = true; $view->goalDimensions = Piwik_Goals::getReportsWithGoalMetrics(); echo $view->render(); }
public function setUp() { parent::setUp(); $access = new Piwik_Access(); Zend_Registry::set('access', $access); $access->setSuperUser(true); $this->idSiteAccess = Piwik_SitesManager_API::getInstance()->addSite("test", "http://test"); Piwik_PluginsManager::getInstance()->loadPlugins(array('MultiSites', 'VisitsSummary', 'Actions')); Piwik_PluginsManager::getInstance()->installLoadedPlugins(); }
/** * Smarty {assignTopBar} function plugin. * Initialize top nav bar text and links. * * @param array $params * @param Smarty $smarty */ function smarty_function_assignTopBar($params, &$smarty) { $topBarElements = array(); $elements = array(array('CoreHome', Piwik_Translate('General_Dashboard'), array('module' => 'CoreHome', 'action' => 'index')), array('MultiSites', Piwik_Translate('General_MultiSitesSummary'), array('module' => 'MultiSites', 'action' => 'index')), array('Widgetize', Piwik_Translate('General_Widgets'), array('module' => 'Widgetize', 'action' => 'index')), array('API', Piwik_Translate('General_API'), array('module' => 'API', 'action' => 'listAllAPI')), array('Feedback', Piwik_Translate('General_GiveUsYourFeedback'), array('module' => 'Feedback', 'action' => 'index'), 'id="topbar-feedback"')); foreach ($elements as $element) { if (Piwik_PluginsManager::getInstance()->isPluginActivated($element[0])) { $topBarElements[] = $element; } } $smarty->assign("topBarElements", $topBarElements); }
/** * Smarty {assignTopBar} function plugin. * Initialize top nav bar text and links. * * @param array $params * @param Smarty $smarty */ function smarty_function_assignTopBar($params, &$smarty) { $topBarElements = array(); $elements = array(array('CoreHome', Piwik_Translate('General_YourDashboard'), array('module' => 'CoreHome', 'action' => 'index')), array('Widgetize', Piwik_Translate('General_Widgets'), array('module' => 'Widgetize', 'action' => 'index')), array('API', Piwik_Translate('General_API'), array('module' => 'API', 'action' => 'listAllAPI')), array('Feedback', Piwik_Translate('General_GiveUsYourFeedback'), array('module' => 'Feedback', 'action' => 'index', 'keepThis' => 'true', 'TB_iframe' => 'true', 'height' => '400', 'width' => '350'), 'title="' . Piwik_Translate('General_GiveUsYourFeedback') . '" class="thickbox"')); foreach ($elements as $element) { if (Piwik_PluginsManager::getInstance()->isPluginActivated($element[0])) { $topBarElements[] = $element; } } $smarty->assign("topBarElements", $topBarElements); }
/** * trigger loading all plugins with an API.php file in the Proxy */ public function __construct() { $plugins = Piwik_PluginsManager::getInstance()->getLoadedPluginsName(); foreach ($plugins as $plugin) { $plugin = Piwik::unprefixClass($plugin); try { Piwik_API_Proxy::getInstance()->registerClass('Piwik_' . $plugin . '_API'); } catch (Exception $e) { } } }
/** * When the MultiSites plugin is not activated, the SMS content should invite the user to activate it back * * @group Plugins * @group MobileMessaging */ public function testWarnUserViaSMSMultiSitesDeactivated() { // safety net Piwik_PluginsManager::getInstance()->loadPlugins(array('PDFReports', 'MobileMessaging')); $this->assertFalse(Piwik_PluginsManager::getInstance()->isPluginActivated('MultiSites')); $PdfReportsAPIInstance = Piwik_PDFReports_API::getInstance(); $reportId = $PdfReportsAPIInstance->addReport($this->idSiteAccess, 'description', 'month', 'mobile', 'sms', array(), array("phoneNumbers" => array('33698896656'))); list($outputFilename, $prettyDate, $websiteName, $additionalFiles) = $PdfReportsAPIInstance->generateReport($reportId, '01-01-2010', 'en', 2); $handle = fopen($outputFilename, "r"); $contents = fread($handle, filesize($outputFilename)); fclose($handle); $this->assertEquals(Piwik_Translate('MobileMessaging_MultiSites_Must_Be_Activated'), $contents); }
public static function getComponentUpdates($updater) { $updater->addComponentToCheck('core', Piwik_Version::VERSION); $plugins = Piwik_PluginsManager::getInstance()->getLoadedPlugins(); foreach ($plugins as $pluginName => $plugin) { $updater->addComponentToCheck($pluginName, $plugin->getVersion()); } $componentsWithUpdateFile = $updater->getComponentsWithUpdateFile(); if (count($componentsWithUpdateFile) == 0 && !$updater->hasNewVersion('core')) { return null; } return $componentsWithUpdateFile; }
public function setUp() { parent::setUp(); Piwik::createConfigObject(); Piwik_Config::getInstance()->setTestEnvironment(); // setup the access layer (required in Segment contrustor testing if anonymous is allowed to use segments) $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = true; Zend_Registry::set('access', $pseudoMockAccess); // Load and install plugins $pluginsManager = Piwik_PluginsManager::getInstance(); $pluginsManager->loadPlugins(Piwik_Config::getInstance()->Plugins['Plugins']); }
function detectGoals($idSite) { if (!Piwik_PluginsManager::getInstance()->isPluginActivated('Goals')) { return false; } $url = $this->action->getActionUrl(); $actionType = $this->action->getActionType(); $goals = $this->getGoalDefinitions($idSite); foreach ($goals as $goal) { $attribute = $goal['match_attribute']; // if the attribute to match is not the type of the current action if ($actionType == Piwik_Tracker_Action::TYPE_ACTION && $attribute != 'url' || $actionType == Piwik_Tracker_Action::TYPE_DOWNLOAD && $attribute != 'file' || $actionType == Piwik_Tracker_Action::TYPE_OUTLINK && $attribute != 'external_website') { continue; } $pattern_type = $goal['pattern_type']; switch ($pattern_type) { case 'regex': $pattern = '/' . $goal['pattern'] . '/'; if (!$goal['case_sensitive']) { $pattern .= 'i'; } $match = preg_match($pattern, $url) == 1; break; case 'contains': if ($goal['case_sensitive']) { $matched = strpos($url, $goal['pattern']); } else { $matched = stripos($url, $goal['pattern']); } $match = $matched !== false; break; case 'exact': if ($goal['case_sensitive']) { $matched = strcmp($goal['pattern'], $url); } else { $matched = strcasecmp($goal['pattern'], $url); } $match = $matched == 0; break; default: throw new Exception("Pattern type {$pattern_type} not valid."); break; } if ($match) { $this->matchedGoals[] = $goal; } } // var_dump($this->matchedGoals);exit; return count($this->matchedGoals) > 0; }
public function setUp() { parent::setUp(); // setup the access layer $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = true; //finally we set the user as a super user by default Zend_Registry::set('access', $pseudoMockAccess); Piwik_PluginsManager::getInstance()->loadPlugins(array('API', 'UserCountry', 'PDFReports')); Piwik_PluginsManager::getInstance()->installLoadedPlugins(); $this->idSiteAccess = Piwik_SitesManager_API::getInstance()->addSite("Test", array("http://piwik.net")); $idSite = Piwik_SitesManager_API::getInstance()->addSite("Test", array("http://piwik.net")); FakeAccess::setIdSitesView(array($this->idSiteAccess, 2)); }
function redirectToCoreHomeIndex() { $defaultReport = Piwik_UsersManager_API::getInstance()->getUserPreference(Piwik::getCurrentUserLogin(), Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT); $module = 'CoreHome'; $action = 'index'; // User preference: default report to load is the All Websites dashboard if ($defaultReport == 'MultiSites' && Piwik_PluginsManager::getInstance()->isPluginActivated('MultiSites')) { $module = 'MultiSites'; } if ($defaultReport == Piwik::getLoginPluginName()) { $module = Piwik::getLoginPluginName(); } $idSite = Piwik_Common::getRequestVar('idSite', false, 'int'); parent::redirectToIndex($module, $action, !empty($idSite) ? $idSite : null); }