private function addParameters() { $login = '******'; $method = 'API.get'; $params = array('flat' => '0', 'expanded' => 1, 'viewDataTable' => 'tableAllColumns'); ViewDataTableManager::saveViewDataTableParameters($login, $method, $params); return array('login' => $login, 'method' => $method, 'params' => $params); }
public function onEnvironmentBootstrapped() { if (empty($_GET['ignoreClearAllViewDataTableParameters'])) { // TODO: should use testingEnvironment variable, not query param try { \Piwik\ViewDataTable\Manager::clearAllViewDataTableParameters(); } catch (\Exception $ex) { // ignore (in case DB is not setup) } } if ($this->vars->optionsOverride) { try { foreach ($this->vars->optionsOverride as $name => $value) { Option::set($name, $value); } } catch (\Exception $ex) { // ignore (in case DB is not setup) } } \Piwik\Plugins\CoreVisualizations\Visualizations\Cloud::$debugDisableShuffle = true; \Piwik\Visualization\Sparkline::$enableSparklineImages = false; \Piwik\Plugins\ExampleUI\API::$disableRandomness = true; if ($this->vars->deleteArchiveTables && !$this->vars->_archivingTablesDeleted) { $this->vars->_archivingTablesDeleted = true; DbHelper::deleteArchiveTables(); } }
/** * Returns `true` if this instance's or any of its ancestors' viewDataTable IDs equals the supplied ID, * `false` if otherwise. * * Can be used to test whether a ViewDataTable object is an instance of a certain visualization or not, * without having to know where that visualization is. * * @param string $viewDataTableId The viewDataTable ID to check for, eg, `'table'`. * @return bool */ public function isViewDataTableId($viewDataTableId) { $myIds = ViewDataTableManager::getIdsWithInheritance(get_called_class()); return in_array($viewDataTableId, $myIds); }
private function overrideSomeConfigPropertiesIfNeeded() { if (empty($this->config->footer_icons)) { $this->config->footer_icons = ViewDataTableManager::configureFooterIcons($this); } if (!$this->isPluginActivated('Goals')) { $this->config->show_goals = false; } }
public static function addHooks() { $testingEnvironment = new Piwik_TestingEnvironment(); if ($testingEnvironment->queryParamOverride) { foreach ($testingEnvironment->queryParamOverride as $key => $value) { $_GET[$key] = $value; } } if ($testingEnvironment->globalsOverride) { foreach ($testingEnvironment->globalsOverride as $key => $value) { $GLOBALS[$key] = $value; } } if ($testingEnvironment->useXhprof) { \Piwik\Profiler::setupProfilerXHProf($mainRun = false, $setupDuringTracking = true); } Config::setSingletonInstance(new Config($testingEnvironment->configFileGlobal, $testingEnvironment->configFileLocal, $testingEnvironment->configFileCommon)); \Piwik\CacheFile::$invalidateOpCacheBeforeRead = true; Piwik::addAction('Access.createAccessSingleton', function ($access) use($testingEnvironment) { if (!$testingEnvironment->testUseRegularAuth) { $access = new Piwik_MockAccess($access); \Piwik\Access::setSingletonInstance($access); } }); if (!$testingEnvironment->dontUseTestConfig) { Piwik::addAction('Config.createConfigSingleton', function (Config $config, &$cache, &$local) use($testingEnvironment) { $config->setTestEnvironment($testingEnvironment->configFileLocal, $testingEnvironment->configFileGlobal, $testingEnvironment->configFileCommon); if ($testingEnvironment->configFileLocal) { $local['General']['session_save_handler'] = 'dbtable'; } $manager = \Piwik\Plugin\Manager::getInstance(); $pluginsToLoad = $testingEnvironment->getCoreAndSupportedPlugins(); if (!empty($testingEnvironment->pluginsToLoad)) { $pluginsToLoad = array_unique(array_merge($pluginsToLoad, $testingEnvironment->pluginsToLoad)); } sort($pluginsToLoad); $local['Plugins'] = array('Plugins' => $pluginsToLoad); $local['log']['log_writers'] = array('file'); $manager->unloadPlugins(); // TODO: replace this and below w/ configOverride use if ($testingEnvironment->tablesPrefix) { $cache['database']['tables_prefix'] = $testingEnvironment->tablesPrefix; } if ($testingEnvironment->dbName) { $cache['database']['dbname'] = $testingEnvironment->dbName; } if ($testingEnvironment->configOverride) { $cache = $testingEnvironment->arrayMergeRecursiveDistinct($cache, $testingEnvironment->configOverride); } }); } Piwik::addAction('Request.dispatch', function () use($testingEnvironment) { if (empty($_GET['ignoreClearAllViewDataTableParameters'])) { // TODO: should use testingEnvironment variable, not query param \Piwik\ViewDataTable\Manager::clearAllViewDataTableParameters(); } if ($testingEnvironment->optionsOverride) { foreach ($testingEnvironment->optionsOverride as $name => $value) { Option::set($name, $value); } } \Piwik\Plugins\CoreVisualizations\Visualizations\Cloud::$debugDisableShuffle = true; \Piwik\Visualization\Sparkline::$enableSparklineImages = false; \Piwik\Plugins\ExampleUI\API::$disableRandomness = true; }); Piwik::addAction('AssetManager.getStylesheetFiles', function (&$stylesheets) { $stylesheets[] = 'tests/resources/screenshot-override/override.css'; }); Piwik::addAction('AssetManager.getJavaScriptFiles', function (&$jsFiles) { $jsFiles[] = 'tests/resources/screenshot-override/override.js'; }); self::addSendMailHook(); Piwik::addAction('Updater.checkForUpdates', function () { try { @\Piwik\Filesystem::deleteAllCacheOnUpdate(); } catch (Exception $ex) { // pass } }); $testingEnvironment->logVariables(); $testingEnvironment->executeSetupTestEnvHook(); }
/** * Creates a {@link Piwik\Plugin\ViewDataTable} instance by ID. If the **viewDataTable** query parameter is set, * this parameter's value is used as the ID. * * See {@link Piwik\Plugin\ViewDataTable} to read about the visualizations that are packaged with Piwik. * * @param string|null $defaultType A ViewDataTable ID representing the default ViewDataTable type to use. If * the **viewDataTable** query parameter is not found, this value is used as * the ID of the ViewDataTable to create. * * If a visualization type is configured for the report being displayed, it * is used instead of the default type. (See {@hook ViewDataTable.getDefaultType}). * If nothing is configured for the report and `null` is supplied for this * argument, **table** is used. * @param bool|false|string $apiAction The API method for the report that will be displayed, eg, * `'DevicesDetection.getBrowsers'`. * @param bool|false|string $controllerAction The controller name and action dedicated to displaying the report. This * action is used when reloading reports or changing the report visualization. * Defaulted to `$apiAction` if `false` is supplied. * @param bool $forceDefault If true, then the visualization type that was configured for the report will be * ignored and `$defaultType` will be used as the default. * @param bool $loadViewDataTableParametersForUser Whether the per-user parameters for this user, this ViewDataTable and this Api action * should be loaded from the user preferences and override the default params values. * @throws \Exception * @return \Piwik\Plugin\ViewDataTable */ public static function build($defaultType = null, $apiAction = false, $controllerAction = false, $forceDefault = false, $loadViewDataTableParametersForUser = null) { if (false === $controllerAction) { $controllerAction = $apiAction; } $report = self::getReport($apiAction); $defaultViewType = self::getDefaultViewTypeForReport($report, $apiAction); $params = array(); if (is_null($loadViewDataTableParametersForUser)) { $loadViewDataTableParametersForUser = '******' == Common::getRequestVar('widget', '0', 'string'); } if ($loadViewDataTableParametersForUser) { $login = Piwik::getCurrentUserLogin(); $params = Manager::getViewDataTableParameters($login, $controllerAction); } if (!self::isDefaultViewTypeForReportFixed($report)) { $savedViewDataTable = false; if (!empty($params['viewDataTable'])) { $savedViewDataTable = $params['viewDataTable']; } // order of default viewDataTables' priority is: function specified default, saved default, configured default for report // function specified default is preferred // -> force default == true : defaultType ?: saved ?: defaultView // -> force default == false : saved ?: defaultType ?: defaultView if ($forceDefault) { $defaultType = $defaultType ?: $savedViewDataTable ?: $defaultViewType; } else { $defaultType = $savedViewDataTable ?: $defaultType ?: $defaultViewType; } $type = Common::getRequestVar('viewDataTable', $defaultType, 'string'); // Common::getRequestVar removes backslashes from the defaultValue in case magic quotes are enabled. // therefore do not pass this as a default value to getRequestVar() if ('' === $type) { $type = $defaultType ?: HtmlTable::ID; } } else { $type = $defaultViewType; } $params['viewDataTable'] = $type; $visualizations = Manager::getAvailableViewDataTables(); if (array_key_exists($type, $visualizations)) { return self::createViewDataTableInstance($visualizations[$type], $controllerAction, $apiAction, $params); } if (array_key_exists($defaultType, $visualizations)) { return self::createViewDataTableInstance($visualizations[$defaultType], $controllerAction, $apiAction, $params); } if (array_key_exists(HtmlTable::ID, $visualizations)) { return self::createViewDataTableInstance($visualizations[HtmlTable::ID], $controllerAction, $apiAction, $params); } throw new \Exception('No visualization found to render ViewDataTable'); }
public function deleteUser($userLogin) { ViewDataTableManager::clearUserViewDataTableParameters($userLogin); }
public function saveViewDataTableParameters() { Piwik::checkUserIsNotAnonymous(); $this->checkTokenInUrl(); $reportId = Common::getRequestVar('report_id', null, 'string'); $parameters = (array) Common::getRequestVar('parameters', null, 'json'); $login = Piwik::getCurrentUserLogin(); ViewDataTableManager::saveViewDataTableParameters($login, $reportId, $parameters); }
/** * Creates a {@link Piwik\Plugin\ViewDataTable} instance by ID. If the **viewDataTable** query parameter is set, * this parameter's value is used as the ID. * * See {@link Piwik\Plugin\ViewDataTable} to read about the visualizations that are packaged with Piwik. * * @param string|null $defaultType A ViewDataTable ID representing the default ViewDataTable type to use. If * the **viewDataTable** query parameter is not found, this value is used as * the ID of the ViewDataTable to create. * * If a visualization type is configured for the report being displayed, it * is used instead of the default type. (See {@hook ViewDataTable.getDefaultType}). * If nothing is configured for the report and `null` is supplied for this * argument, **table** is used. * @param bool|false|string $apiAction The API method for the report that will be displayed, eg, * `'UserSettings.getBrowser'`. * @param bool|false|string $controllerAction The controller name and action dedicated to displaying the report. This * action is used when reloading reports or changing the report visualization. * Defaulted to `$apiAction` if `false` is supplied. * @param bool $forceDefault If true, then the visualization type that was configured for the report will be * ignored and `$defaultType` will be used as the default. * @throws \Exception * @return \Piwik\Plugin\ViewDataTable */ public static function build($defaultType = null, $apiAction = false, $controllerAction = false, $forceDefault = false) { if (false === $controllerAction) { $controllerAction = $apiAction; } $defaultViewType = self::getDefaultViewTypeForReport($apiAction); if (!$forceDefault && !empty($defaultViewType)) { $defaultType = $defaultViewType; } $isWidget = Common::getRequestVar('widget', '0', 'string'); if (!empty($isWidget)) { $params = array(); } else { $login = Piwik::getCurrentUserLogin(); $params = Manager::getViewDataTableParameters($login, $controllerAction); } $savedViewDataTable = false; if (!empty($params['viewDataTable'])) { $savedViewDataTable = $params['viewDataTable']; } $type = Common::getRequestVar('viewDataTable', $savedViewDataTable, 'string'); // Common::getRequestVar removes backslashes from the defaultValue in case magic quotes are enabled. // therefore do not pass this as a default value to getRequestVar() if ('' === $type) { $type = $defaultType ?: HtmlTable::ID; } $visualizations = Manager::getAvailableViewDataTables(); if (array_key_exists($type, $visualizations)) { return self::createViewDataTableInstance($visualizations[$type], $controllerAction, $apiAction, $params); } if (class_exists($type)) { return self::createViewDataTableInstance($type, $controllerAction, $apiAction, $params); } if (array_key_exists($defaultType, $visualizations)) { return self::createViewDataTableInstance($visualizations[$defaultType], $controllerAction, $apiAction, $params); } if (array_key_exists(HtmlTable::ID, $visualizations)) { return self::createViewDataTableInstance($visualizations[HtmlTable::ID], $controllerAction, $apiAction, $params); } throw new \Exception('No visualization found to render ViewDataTable'); }
/** * Creates a {@link Piwik\Plugin\ViewDataTable} instance by ID. If the **viewDataTable** query parameter is set, * this parameter's value is used as the ID. * * See {@link Piwik\Plugin\ViewDataTable} to read about the visualizations that are packaged with Piwik. * * @param string|null $defaultType A ViewDataTable ID representing the default ViewDataTable type to use. If * the **viewDataTable** query parameter is not found, this value is used as * the ID of the ViewDataTable to create. * * If a visualization type is configured for the report being displayed, it * is used instead of the default type. (See {@hook ViewDataTable.getDefaultType}). * If nothing is configured for the report and `null` is supplied for this * argument, **table** is used. * @param string|false $apiAction The API method for the report that will be displayed, eg, * `'UserSettings.getBrowser'`. * @param string|false $controllerAction The controller name and action dedicated to displaying the report. This * action is used when reloading reports or changing the report visualization. * Defaulted to `$apiAction` if `false` is supplied. * @param bool $forceDefault If true, then the visualization type that was configured for the report will be * ignored and `$defaultType` will be used as the default. * @throws \Exception * @return \Piwik\Plugin\ViewDataTable */ public static function build($defaultType = null, $apiAction = false, $controllerAction = false, $forceDefault = false) { if (false === $controllerAction) { $controllerAction = $apiAction; } $defaultViewType = self::getDefaultViewTypeForReport($apiAction); if (!$forceDefault && !empty($defaultViewType)) { $defaultType = $defaultViewType; } $type = Common::getRequestVar('viewDataTable', false, 'string'); // Common::getRequestVar removes backslashes from the defaultValue in case magic quotes are enabled. // therefore do not pass this as a default value to getRequestVar() if ('' === $type) { $type = $defaultType ?: HtmlTable::ID; } $visualizations = Manager::getAvailableViewDataTables(); if (array_key_exists($type, $visualizations)) { return new $visualizations[$type]($controllerAction, $apiAction); } if (class_exists($type)) { return new $type($controllerAction, $apiAction); } if (array_key_exists($defaultType, $visualizations)) { return new $visualizations[$defaultType]($controllerAction, $apiAction); } if (array_key_exists(HtmlTable::ID, $visualizations)) { return new $visualizations[HtmlTable::ID]($controllerAction, $apiAction); } throw new \Exception('No visualization found to render ViewDataTable'); }
<?php /** * Proxy to index.php, but will use the Test DB * Used by tests/PHPUnit/Integration/ImportLogsTest.php and tests/PHPUnit/Integration/UITest.php */ require realpath(dirname(__FILE__)) . "/includes.php"; Piwik_TestingEnvironment::addHooks(); if (empty($_GET['ignoreClearAllViewDataTableParameters'])) { \Piwik\ViewDataTable\Manager::clearAllViewDataTableParameters(); } \Piwik\Profiler::setupProfilerXHProf(); include PIWIK_INCLUDE_PATH . '/index.php';