public function configureTopMenu(MenuTop $menu) { if (Piwik::isUserIsAnonymous() || !SettingsPiwik::isPiwikInstalled()) { $langManager = new LanguagesManager(); $menu->addHtml('LanguageSelector', $langManager->getLanguagesSelector(), true, $order = 30, false); } }
public function isInstalled() { if (is_null($this->isInstalled)) { $this->isInstalled = SettingsPiwik::isPiwikInstalled(); } return $this->isInstalled; }
public function validate() { $this->checkConfigFileExists($this->settingsProvider->getPathGlobal()); if (SettingsPiwik::isPiwikInstalled()) { $this->checkConfigFileExists($this->settingsProvider->getPathLocal(), $startInstaller = false); return; } $startInstaller = true; if (SettingsServer::isTrackerApiRequest()) { // if Piwik is not installed yet, the piwik.php should do nothing and not return an error throw new NotYetInstalledException("As Piwik is not installed yet, the Tracking API cannot proceed and will exit without error."); } if (Common::isPhpCliMode()) { // in CLI, do not start/redirect to installer, simply output the exception at the top $startInstaller = false; } // Start the installation when config file not found $this->checkConfigFileExists($this->settingsProvider->getPathLocal(), $startInstaller); }
private function checkPiwikIsNotInstalled() { if (!SettingsPiwik::isPiwikInstalled()) { return; } \Piwik\Plugins\Login\Controller::clearSession(); $message = Piwik::translate('Installation_InvalidStateError', array('<br /><strong>', '</strong>', '<a href=\'' . Common::sanitizeInputValue(Url::getCurrentUrlWithoutFileName()) . '\'>', '</a>')); Piwik::exitWithErrorMessage($message); }
/** * Main - tracks the visit/action * * @param array $args Optional Request Array */ public function main($args = null) { if (!SettingsPiwik::isPiwikInstalled()) { return $this->handleEmptyRequest(); } try { $tokenAuth = $this->initRequests($args); } catch (Exception $ex) { $this->exitWithException($ex, true); } $this->initOutputBuffer(); if (!empty($this->requests)) { $this->beginTransaction(); try { foreach ($this->requests as $params) { $isAuthenticated = $this->trackRequest($params, $tokenAuth); } $this->runScheduledTasksIfAllowed($isAuthenticated); $this->commitTransaction(); } catch (DbException $e) { Common::printDebug($e->getMessage()); $this->rollbackTransaction(); } } else { $this->handleEmptyRequest(); } Piwik::postEvent('Tracker.end'); $this->end(); $this->flushOutputBuffer(); }
if ('@USERNAME@' !== $testDb['username']) { return; // testDb is already configured, we do not want to overwrite any existing settings. } $db = $config->database; $testDb['username'] = $db['username']; if (empty($testDb['password'])) { $testDb['password'] = $db['password']; } if (empty($testDb['host'])) { $testDb['host'] = $db['host']; } $testDb['tables_prefix'] = ''; // tables_prefix has to be empty for UI tests $config->database_tests = $testDb; $config->forceSave(); } if (!SettingsPiwik::isPiwikInstalled()) { throw new Exception('Piwik needs to be installed in order to run the tests'); } $config = Config::getInstance(); prepareServerVariables($config); prepareTestDatabaseConfig($config); checkPiwikSetupForTests(); function checkPiwikSetupForTests() { if (empty($_SERVER['REQUEST_URI']) || $_SERVER['REQUEST_URI'] == '@REQUEST_URI@') { echo "WARNING: for tests to pass, you must first:\n1) Install webserver on localhost, eg. apache\n2) Make these Piwik files available on the webserver, at eg. http://localhost/dev/piwik/\n3) Install Piwik by going through the installation process\n4) Configure tests section if needed in config/config.ini.php:\n[tests]\nhttp_host = \"localhost\"\nrequest_uri = \"@REQUEST_URI@\"\nremote_addr = \"127.0.0.1\"\n\nTry again."; exit(1); } }
protected function handleSSLRedirection() { // Specifically disable for the opt out iframe if (Piwik::getModule() == 'CoreAdminHome' && Piwik::getAction() == 'optOut') { return; } // Disable Https for VisitorGenerator if (Piwik::getModule() == 'VisitorGenerator') { return; } if (Common::isPhpCliMode()) { return; } // Only enable this feature after Piwik is already installed if (!SettingsPiwik::isPiwikInstalled()) { return; } // proceed only when force_ssl = 1 if (!SettingsPiwik::isHttpsForced()) { return; } Url::redirectToHttps(); }
protected function prepareDispatch($module, $action, $parameters) { if (is_null($module)) { $module = Common::getRequestVar('module', self::DEFAULT_MODULE, 'string'); } if (is_null($action)) { $action = Common::getRequestVar('action', false); } if (SettingsPiwik::isPiwikInstalled() && ($module !== 'API' || $action && $action !== 'index')) { Session::start(); $this->closeSessionEarlyForFasterUI(); } if (is_null($parameters)) { $parameters = array(); } if (!ctype_alnum($module)) { throw new Exception("Invalid module name '{$module}'"); } list($module, $action) = Request::getRenamedModuleAndAction($module, $action); if (!\Piwik\Plugin\Manager::getInstance()->isPluginActivated($module)) { throw new PluginDeactivatedException($module); } return array($module, $action, $parameters); }
/** * @return bool */ public static function isHttpsForced() { if (!SettingsPiwik::isPiwikInstalled()) { // Only enable this feature after Piwik is already installed return false; } return Config::getInstance()->General['force_ssl'] == 1; }
$eventToPersist = 'Tracker.end'; $cacheId .= 'tracker'; } else { $eventToPersist = 'Request.dispatch.end'; $cacheId .= 'ui'; } $cache = new Eager($backend, $cacheId); \Piwik\Piwik::addAction($eventToPersist, function () use($cache) { $cache->persistCacheIfNeeded(43200); }); return $cache; }, 'Piwik\\Cache\\Backend' => function (ContainerInterface $c) { // If Piwik is not installed yet, it's possible the tmp/ folder is not writable // we prevent failing with an unclear message eg. coming from doctrine-cache // by forcing to use a cache backend which always works ie. array if (!\Piwik\SettingsPiwik::isPiwikInstalled()) { $backend = 'array'; } else { try { $backend = $c->get('ini.Cache.backend'); } catch (NotFoundException $ex) { $backend = 'chained'; // happens if global.ini.php is not available } } return \Piwik\Cache::buildBackend($backend); }, 'cache.eager.cache_id' => function () { return 'eagercache-' . str_replace(array('.', '-'), '', \Piwik\Version::VERSION) . '-'; }, 'Psr\\Log\\LoggerInterface' => DI\object('Psr\\Log\\NullLogger'), 'Piwik\\Translation\\Loader\\LoaderInterface' => DI\object('Piwik\\Translation\\Loader\\LoaderCache')->constructor(DI\get('Piwik\\Translation\\Loader\\JsonFileLoader')), 'observers.global' => array(), 'Piwik\\EventDispatcher' => DI\object()->constructorParameter('observers', DI\get('observers.global')), 'Zend_Validate_EmailAddress' => function () { return new \Zend_Validate_EmailAddress(array('hostname' => new \Zend_Validate_Hostname(array('tld' => false)))); }, 'Piwik\\Tracker\\VisitorRecognizer' => DI\object()->constructorParameter('trustCookiesOnly', DI\get('ini.Tracker.trust_visitors_cookies'))->constructorParameter('visitStandardLength', DI\get('ini.Tracker.visit_standard_length'))->constructorParameter('lookbackNSecondsCustom', DI\get('ini.Tracker.window_look_back_for_visitor'))->constructorParameter('trackerAlwaysNewVisitor', DI\get('ini.Debug.tracker_always_new_visitor')), 'Piwik\\Tracker\\Settings' => DI\object()->constructorParameter('isSameFingerprintsAcrossWebsites', DI\get('ini.Tracker.enable_fingerprinting_across_websites')));