public static function footerUserCountry(&$out) { $out = '<div> <h2>' . Piwik::translate('Provider_WidgetProviders') . '</h2>'; $out .= FrontController::getInstance()->fetchDispatch('Provider', 'getProvider'); $out .= '</div>'; }
/** * Execute command like: ./console core:run-scheduled-tasks */ protected function execute(InputInterface $input, OutputInterface $output) { $this->forceRunAllTasksIfRequested($input); FrontController::getInstance()->init(); API::getInstance()->runScheduledTasks(); $this->writeSuccessMessage($output, array('Scheduled Tasks executed')); }
public static function footerVisitsFrequency(&$out) { $out = '</div> <div id="rightcolumn"> '; $out .= FrontController::getInstance()->fetchDispatch('VisitorInterest', 'index'); $out .= '</div>'; }
/** * Redirects to Login form with error message. * Listens to User.isNotAuthorized hook. */ public function noAccess(Exception $exception) { $frontController = FrontController::getInstance(); if (Common::isXmlHttpRequest()) { echo $frontController->dispatch('Login', 'ajaxNoAccess', array($exception->getMessage())); return; } echo $frontController->dispatch('Login', 'login', array($exception->getMessage())); }
/** * Testing that getOne does not error out when format=rss, #10407 * * @group Plugins */ public function testWhenRssFormatGetOneDoesNotError() { $_GET = array('method' => 'MultiSites.getOne', 'idSite' => $this->idSiteAccess, 'period' => 'month', 'date' => 'last10', 'format' => 'rss'); $output = FrontController::getInstance()->fetchDispatch('API'); $this->assertContains('<item>', $output); $this->assertContains('</rss>', $output); $this->assertNotContains('error', $output); $_GET = array(); }
public function getEcommerceLog($fetch = false) { $saveGET = $_GET; $_GET['segment'] = urlencode('visitEcommerceStatus!=none'); $_GET['widget'] = 1; $output = FrontController::getInstance()->dispatch('Live', 'getVisitorLog', array($fetch)); $_GET = $saveGET; return $output; }
private function requestGetAllWithGroups($params) { $oldGet = $_GET; $params['period'] = 'day'; $params['date'] = '2013-01-23'; $_GET = $params; $sites = FrontController::getInstance()->dispatch('MultiSites', 'getAllWithGroups'); $_GET = $oldGet; return $sites; }
/** * Execute command like: ./console core:run-scheduled-tasks */ protected function execute(InputInterface $input, OutputInterface $output) { $this->forceRunAllTasksIfRequested($input); FrontController::getInstance()->init(); $scheduledTasksResults = API::getInstance()->runScheduledTasks(); foreach ($scheduledTasksResults as $scheduledTasksResult) { $output->writeln(sprintf('<comment>%s</comment> - %s', $scheduledTasksResult['task'], $scheduledTasksResult['output'])); } $this->writeSuccessMessage($output, array('Scheduled Tasks executed')); }
protected function _getDashboardView($template) { $view = new View($template); $this->setGeneralVariablesView($view); $view->availableWidgets = Common::json_encode(WidgetsList::get()); $view->availableLayouts = $this->getAvailableLayouts(); $view->dashboardId = Common::getRequestVar('idDashboard', 1, 'int'); // get the layout via FrontController so controller events are posted $view->dashboardLayout = FrontController::getInstance()->dispatch('Dashboard', 'getDashboardLayout', array($checkToken = false)); return $view; }
public function showInContext() { $controllerName = Common::getRequestVar('moduleToLoad'); $actionName = Common::getRequestVar('actionToLoad', 'index'); if ($actionName == 'showInContext') { throw new Exception("Preventing infinite recursion..."); } $view = $this->getDefaultIndexView(); $view->content = FrontController::getInstance()->fetchDispatch($controllerName, $actionName); return $view->render(); }
/** * @param $lastError * @return mixed|void * @throws AuthenticationFailedException * @throws Exception */ private static function generateSafeModeOutput($lastError) { Common::sendResponseCode(500); $controller = FrontController::getInstance(); try { $controller->init(); $message = $controller->dispatch('CorePluginsAdmin', 'safemode', array($lastError)); } catch (Exception $e) { // may fail in safe mode (eg. global.ini.php not found) $message = sprintf("Piwik encoutered an error: %s (which lead to: %s)", $lastError['message'], $e->getMessage()); } return $message; }
/** * Execute command like: ./console core:run-scheduled-tasks */ protected function execute(InputInterface $input, OutputInterface $output) { $this->forceRunAllTasksIfRequested($input); FrontController::getInstance()->init(); // TODO use dependency injection /** @var Scheduler $scheduler */ $scheduler = StaticContainer::get('Piwik\\Scheduler\\Scheduler'); $task = $input->getArgument('task'); if ($task) { $this->runSingleTask($scheduler, $task, $output); } else { $scheduler->run(); } $this->writeSuccessMessage($output, array('Scheduled Tasks executed')); }
/** * @param \Exception|null $exception */ public function dispatch($exception = null) { if ($exception) { $message = $exception->getMessage(); } else { $message = ''; } $action = Common::getRequestVar('action', 'welcome', 'string'); if ($this->isAllowedAction($action)) { echo FrontController::getInstance()->dispatch('Installation', $action, array($message)); } else { Piwik::exitWithErrorMessage(Piwik::translate('Installation_NoConfigFound')); } exit; }
public function iframe() { Request::reloadAuthUsingTokenAuth(); $this->init(); $controllerName = Common::getRequestVar('moduleToWidgetize'); $actionName = Common::getRequestVar('actionToWidgetize'); if ($controllerName == 'Dashboard' && $actionName == 'index') { $view = new View('@Widgetize/iframe_empty'); } else { $view = new View('@Widgetize/iframe'); } $this->setGeneralVariablesView($view); $view->setXFrameOptions('allow'); $view->content = FrontController::getInstance()->fetchDispatch($controllerName, $actionName); return $view->render(); }
/** * @param \Exception|null $exception */ public function dispatch($exception = null) { if ($exception) { $message = $exception->getMessage(); } else { $message = ''; } Translate::loadCoreTranslation(); $step = Common::getRequestVar('action', 'welcome', 'string'); $controller = $this->getInstallationController(); $isActionWhiteListed = in_array($step, array('saveLanguage', 'getBaseCss')); if (in_array($step, array_keys($controller->getInstallationSteps())) || $isActionWhiteListed) { echo FrontController::getInstance()->dispatch('Installation', $step, array($message)); } else { Piwik::exitWithErrorMessage(Piwik::translate('Installation_NoConfigFound')); } exit; }
public function iframe() { Request::reloadAuthUsingTokenAuth(); $this->init(); $controllerName = Common::getRequestVar('moduleToWidgetize'); $actionName = Common::getRequestVar('actionToWidgetize'); if ($controllerName == 'API') { throw new \Exception("Widgetizing API requests is not supported for security reasons. Please change query parameter 'moduleToWidgetize'."); } if ($controllerName == 'Dashboard' && $actionName == 'index') { $view = new View('@Widgetize/iframe_empty'); } else { $view = new View('@Widgetize/iframe'); } $this->setGeneralVariablesView($view); $view->setXFrameOptions('allow'); $view->content = FrontController::getInstance()->fetchDispatch($controllerName, $actionName); return $view->render(); }
private function call($id, $url, $params) { if (!defined('PIWIK_INCLUDE_PATH')) { return false; } if (PIWIK_INCLUDE_PATH === FALSE) { return array('result' => 'error', 'message' => __('Could not resolve', 'wp-piwik') . ' "' . htmlentities(self::$settings->getGlobalOption('piwik_path')) . '": ' . __('realpath() returns false', 'wp-piwik') . '.'); } if (file_exists(PIWIK_INCLUDE_PATH . "/index.php")) { require_once PIWIK_INCLUDE_PATH . "/index.php"; } if (file_exists(PIWIK_INCLUDE_PATH . "/core/API/Request.php")) { require_once PIWIK_INCLUDE_PATH . "/core/API/Request.php"; } if (class_exists('\\Piwik\\Application\\Environment') && !self::$piwikEnvironment) { // Piwik 2.14.* compatibility fix self::$piwikEnvironment = new \Piwik\Application\Environment(null); self::$piwikEnvironment->init(); } if (class_exists('Piwik\\FrontController')) { \Piwik\FrontController::getInstance()->init(); } else { return array('result' => 'error', 'message' => __('Class Piwik\\FrontController does not exists.', 'wp-piwik')); } if (class_exists('Piwik\\API\\Request')) { $request = new \Piwik\API\Request($params . '&token_auth=' . self::$settings->getGlobalOption('piwik_token')); } else { return array('result' => 'error', 'message' => __('Class Piwik\\API\\Request does not exists.', 'wp-piwik')); } if (isset($request)) { $result = $request->process(); } else { $result = null; } if (!headers_sent()) { header("Content-Type: text/html", true); } $result = $this->unserialize($result); if ($GLOBALS['wp-piwik_debug']) { self::$debug[$id] = array($params . '&token_auth=...'); } return $result; }
* * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @package Piwik */ use Piwik\Error; use Piwik\ExceptionHandler; use Piwik\FrontController; use Piwik\Plugin\ControllerAdmin as PluginControllerAdmin; PluginControllerAdmin::disableEacceleratorIfEnabled(); if (!defined('PIWIK_ENABLE_ERROR_HANDLER') || PIWIK_ENABLE_ERROR_HANDLER) { require_once PIWIK_INCLUDE_PATH . '/core/Error.php'; Error::setErrorHandler(); require_once PIWIK_INCLUDE_PATH . '/core/ExceptionHandler.php'; ExceptionHandler::setUp(); } FrontController::setUpSafeMode(); if (!defined('PIWIK_ENABLE_DISPATCH')) { define('PIWIK_ENABLE_DISPATCH', true); } if (PIWIK_ENABLE_DISPATCH) { $controller = FrontController::getInstance(); $controller->init(); $response = $controller->dispatch(); if (is_array($response)) { var_export($response); } elseif (!is_null($response)) { echo $response; } }
public static function triggerSafeModeWhenError() { $lastError = error_get_last(); if (!empty($lastError) && $lastError['type'] == E_ERROR) { Common::sendResponseCode(500); $controller = FrontController::getInstance(); $controller->init(); $message = $controller->dispatch('CorePluginsAdmin', 'safemode', array($lastError)); echo $message; } }
public static function insertMapInLocationReport(&$out) { $out = '<h2>' . Piwik::translate('UserCountryMap_VisitorMap') . '</h2>'; $out .= FrontController::getInstance()->fetchDispatch('UserCountryMap', 'visitorMap'); }
public static function footerVisitsFrequency(&$out) { $out .= FrontController::getInstance()->fetchDispatch('VisitorInterest', 'index'); }
public function getEcommerceLog($fetch = false) { $saveGET = $_GET; $filterEcommerce = Common::getRequestVar('filterEcommerce', self::ECOMMERCE_LOG_SHOW_ORDERS, 'int'); if ($filterEcommerce == self::ECOMMERCE_LOG_SHOW_ORDERS) { $segment = urlencode('visitEcommerceStatus==ordered,visitEcommerceStatus==orderedThenAbandonedCart'); } else { $segment = urlencode('visitEcommerceStatus==abandonedCart,visitEcommerceStatus==orderedThenAbandonedCart'); } $_GET['segment'] = $segment; $_GET['filterEcommerce'] = $filterEcommerce; $_GET['widget'] = 1; $output = FrontController::getInstance()->dispatch('Live', 'getVisitorLog', array($fetch)); $_GET = $saveGET; return $output; }
/** * Helper method used to redirect the current HTTP request to another module/action. * * This function will exit immediately after executing. * * @param string $moduleToRedirect The plugin to redirect to, eg. `"MultiSites"`. * @param string $actionToRedirect Action, eg. `"index"`. * @param int|null $websiteId The new idSite query parameter, eg, `1`. * @param string|null $defaultPeriod The new period query parameter, eg, `'day'`. * @param string|null $defaultDate The new date query parameter, eg, `'today'`. * @param array $parameters Other query parameters to append to the URL. * @api */ public function redirectToIndex($moduleToRedirect, $actionToRedirect, $websiteId = null, $defaultPeriod = null, $defaultDate = null, $parameters = array()) { try { $this->doRedirectToUrl($moduleToRedirect, $actionToRedirect, $websiteId, $defaultPeriod, $defaultDate, $parameters); } catch (Exception $e) { // no website ID to default to, so could not redirect } if (Piwik::hasUserSuperUserAccess()) { Piwik_ExitWithMessage("Error: no website was found in this Piwik installation.\n\t\t\t<br />Check the table '" . Common::prefixTable('site') . "' in your database, it should contain your Piwik websites.", false, true); } if (!Piwik::isUserIsAnonymous()) { $emails = implode(',', Piwik::getAllSuperUserAccessEmailAddresses()); $errorMessage = sprintf(Piwik::translate('CoreHome_NoPrivilegesAskPiwikAdmin'), $currentLogin, "<br/><a href='mailto:" . $emails . "?subject=Access to Piwik for user {$currentLogin}'>", "</a>"); $errorMessage .= "<br /><br /> <b><a href='index.php?module=" . Registry::get('auth')->getName() . "&action=logout'>› " . Piwik::translate('General_Logout') . "</a></b><br />"; Piwik_ExitWithMessage($errorMessage, false, true); } echo FrontController::getInstance()->dispatch(Piwik::getLoginPluginName(), false); exit; }
/** * Redirects to Login form with error message. * Listens to User.isNotAuthorized hook. */ public function noAccess(Exception $exception) { $exceptionMessage = $exception->getMessage(); echo FrontController::getInstance()->dispatch('Login', 'login', array($exceptionMessage)); }
public static function footerUserCountry(&$out) { $out .= '<h2 piwik-enriched-headline>' . Piwik::translate('Provider_WidgetProviders') . '</h2>'; $out .= FrontController::getInstance()->fetchDispatch('Provider', 'getProvider'); }
/** * Renders this view. * * @return string The rendered view. */ public function render() { /** * Triggered before rendering {@link ReportsByDimension} views. * * Plugins can use this event to configure {@link ReportsByDimension} instances by * adding or removing reports to display. * * @param ReportsByDimension $this The view instance. */ Piwik::postEvent('View.ReportsByDimension.render', array($this)); $this->firstReport = ""; // if there are reports & report categories added, render the first one so we can // display it initially $categories = $this->dimensionCategories; if (!empty($categories)) { $firstCategory = reset($categories); $firstReportInfo = reset($firstCategory); $oldGet = $_GET; $oldPost = $_POST; foreach ($firstReportInfo['params'] as $key => $value) { $_GET[$key] = $value; } $_POST = array(); $module = $firstReportInfo['params']['module']; $action = $firstReportInfo['params']['action']; $this->firstReport = FrontController::getInstance()->fetchDispatch($module, $action); $_GET = $oldGet; $_POST = $oldPost; } return parent::render(); }
/** * Helper method used to redirect the current HTTP request to another module/action. * * This function will exit immediately after executing. * * @param string $moduleToRedirect The plugin to redirect to, eg. `"MultiSites"`. * @param string $actionToRedirect Action, eg. `"index"`. * @param int|null $websiteId The new idSite query parameter, eg, `1`. * @param string|null $defaultPeriod The new period query parameter, eg, `'day'`. * @param string|null $defaultDate The new date query parameter, eg, `'today'`. * @param array $parameters Other query parameters to append to the URL. * @api */ public function redirectToIndex($moduleToRedirect, $actionToRedirect, $websiteId = null, $defaultPeriod = null, $defaultDate = null, $parameters = array()) { $userPreferences = new UserPreferences(); if (empty($websiteId)) { $websiteId = $userPreferences->getDefaultWebsiteId(); } if (empty($defaultDate)) { $defaultDate = $userPreferences->getDefaultDate(); } if (empty($defaultPeriod)) { $defaultPeriod = $userPreferences->getDefaultPeriod(); } $parametersString = ''; if (!empty($parameters)) { $parametersString = '&' . Url::getQueryStringFromParameters($parameters); } if ($websiteId) { $url = "index.php?module=" . $moduleToRedirect . "&action=" . $actionToRedirect . "&idSite=" . $websiteId . "&period=" . $defaultPeriod . "&date=" . $defaultDate . $parametersString; Url::redirectToUrl($url); exit; } if (Piwik::hasUserSuperUserAccess()) { Piwik_ExitWithMessage("Error: no website was found in this Piwik installation.\n\t\t\t<br />Check the table '" . Common::prefixTable('site') . "' in your database, it should contain your Piwik websites.", false, true); } $currentLogin = Piwik::getCurrentUserLogin(); if (!empty($currentLogin) && $currentLogin != 'anonymous') { $emails = implode(',', Piwik::getAllSuperUserAccessEmailAddresses()); $errorMessage = sprintf(Piwik::translate('CoreHome_NoPrivilegesAskPiwikAdmin'), $currentLogin, "<br/><a href='mailto:" . $emails . "?subject=Access to Piwik for user {$currentLogin}'>", "</a>"); $errorMessage .= "<br /><br /> <b><a href='index.php?module=" . Registry::get('auth')->getName() . "&action=logout'>› " . Piwik::translate('General_Logout') . "</a></b><br />"; Piwik_ExitWithMessage($errorMessage, false, true); } echo FrontController::getInstance()->dispatch(Piwik::getLoginPluginName(), false); exit; }
* * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * */ use Piwik\Config; use Piwik\FrontController; error_reporting(E_ALL | E_NOTICE); define('PIWIK_DOCUMENT_ROOT', dirname(__FILE__) == '/' ? '' : dirname(__FILE__) . '/../..'); if (file_exists(PIWIK_DOCUMENT_ROOT . '/bootstrap.php')) { require_once PIWIK_DOCUMENT_ROOT . '/bootstrap.php'; } if (!defined('PIWIK_USER_PATH')) { define('PIWIK_USER_PATH', PIWIK_DOCUMENT_ROOT); } if (!defined('PIWIK_INCLUDE_PATH')) { define('PIWIK_INCLUDE_PATH', PIWIK_DOCUMENT_ROOT); } ignore_user_abort(true); set_time_limit(0); @date_default_timezone_set('UTC'); require_once PIWIK_INCLUDE_PATH . '/libs/upgradephp/upgrade.php'; require_once PIWIK_INCLUDE_PATH . '/core/testMinimumPhpVersion.php'; require_once PIWIK_INCLUDE_PATH . '/core/Loader.php'; $GLOBALS['PIWIK_TRACKER_DEBUG'] = false; define('PIWIK_ENABLE_DISPATCH', false); Config::getInstance()->log['log_writers'][] = 'screen'; Config::getInstance()->log['log_level'] = 'VERBOSE'; Config::getInstance()->log['string_message_format'] = "%message%"; FrontController::getInstance()->init();
/** Creates two dashboards that split the widgets up into different groups. */ public function setupDashboards() { $dashboardColumnCount = 3; $dashboardCount = 4; $layout = array(); for ($j = 0; $j != $dashboardColumnCount; ++$j) { $layout[] = array(); } $dashboards = array(); for ($i = 0; $i != $dashboardCount; ++$i) { $dashboards[] = $layout; } $oldGet = $_GET; $_GET['idSite'] = 1; $_GET['token_auth'] = Fixture::getTokenAuth(); // collect widgets & sort them so widget order is not important $allWidgets = array(); foreach (WidgetsList::get() as $category => $widgets) { $allWidgets = array_merge($allWidgets, $widgets); } usort($allWidgets, function ($lhs, $rhs) { return strcmp($lhs['uniqueId'], $rhs['uniqueId']); }); $widgetsPerDashboard = ceil(count($allWidgets) / $dashboardCount); // group widgets so they will be spread out across 3 dashboards $groupedWidgets = array(); $dashboard = 0; foreach ($allWidgets as $widget) { if ($widget['uniqueId'] == 'widgetSEOgetRank' || $widget['uniqueId'] == 'widgetReferrersgetKeywordsForPage' || $widget['uniqueId'] == 'widgetLivegetVisitorProfilePopup' || $widget['uniqueId'] == 'widgetActionsgetPageTitles' || strpos($widget['uniqueId'], 'widgetExample') === 0) { continue; } $widgetEntry = array('uniqueId' => $widget['uniqueId'], 'parameters' => $widget['parameters']); // dashboard images must have height of less than 4000px to avoid odd discoloration of last line of image $widgetEntry['parameters']['filter_limit'] = 5; $groupedWidgets[$dashboard][] = $widgetEntry; if (count($groupedWidgets[$dashboard]) >= $widgetsPerDashboard) { $dashboard = $dashboard + 1; } // sanity check if ($dashboard >= $dashboardCount) { throw new Exception("Unexpected error: Incorrect dashboard widget placement logic. Something's wrong w/ the code."); } } // distribute widgets in each dashboard $column = 0; foreach ($groupedWidgets as $dashboardIndex => $dashboardWidgets) { foreach ($dashboardWidgets as $widget) { $column = ($column + 1) % $dashboardColumnCount; $dashboards[$dashboardIndex][$column][] = $widget; } } foreach ($dashboards as $id => $layout) { if ($id == 0) { $_GET['name'] = self::makeXssContent('dashboard name' . $id); } else { $_GET['name'] = 'dashboard name' . $id; } $_GET['layout'] = json_encode($layout); $_GET['idDashboard'] = $id + 1; FrontController::getInstance()->fetchDispatch('Dashboard', 'saveLayout'); } // create empty dashboard $dashboard = array(array(array('uniqueId' => "widgetVisitsSummarygetEvolutionGraphcolumnsArray", 'parameters' => array('module' => 'VisitsSummary', 'action' => 'getEvolutionGraph', 'columns' => 'nb_visits'))), array(), array()); $_GET['name'] = 'D4'; $_GET['layout'] = json_encode($dashboard); $_GET['idDashboard'] = 5; $_GET['idSite'] = 2; FrontController::getInstance()->fetchDispatch('Dashboard', 'saveLayout'); $_GET = $oldGet; }
public static function footerUserCountry(&$out) { $out .= '<div><h2>' . Piwik::translate('UserLanguage_BrowserLanguage') . '</h2>'; $out .= FrontController::getInstance()->fetchDispatch('UserLanguage', 'getLanguage'); $out .= '</div>'; }