예제 #1
0
파일: View.php 프로젝트: klando/pgpiwik
 public function render()
 {
     try {
         $this->currentModule = Piwik::getModule();
         $this->currentPluginName = Piwik::getCurrentPlugin()->getName();
         $this->userLogin = Piwik::getCurrentUserLogin();
         $showWebsiteSelectorInUserInterface = Zend_Registry::get('config')->General->show_website_selector_in_user_interface;
         if ($showWebsiteSelectorInUserInterface) {
             $sites = Piwik_SitesManager_API::getSitesWithAtLeastViewAccess();
             usort($sites, create_function('$site1, $site2', 'return strcasecmp($site1["name"], $site2["name"]);'));
             $this->sites = $sites;
         }
         $this->showWebsiteSelectorInUserInterface = $showWebsiteSelectorInUserInterface;
         $this->url = Piwik_Url::getCurrentUrl();
         $this->token_auth = Piwik::getCurrentUserTokenAuth();
         $this->userHasSomeAdminAccess = Piwik::isUserHasSomeAdminAccess();
         $this->userIsSuperUser = Piwik::isUserIsSuperUser();
         $this->piwik_version = Piwik_Version::VERSION;
         $this->latest_version_available = Piwik_UpdateCheck::isNewestVersionAvailable();
         $this->loginModule = Zend_Registry::get('auth')->getName();
     } catch (Exception $e) {
         // can fail, for example at installation (no plugin loaded yet)
     }
     $this->totalTimeGeneration = Zend_Registry::get('timer')->getTime();
     try {
         $this->totalNumberOfQueries = Piwik::getQueryCount();
     } catch (Exception $e) {
         $this->totalNumberOfQueries = 0;
     }
     header('Content-Type: text/html; charset=utf-8');
     header("Pragma: ");
     header("Cache-Control: no-store, must-revalidate");
     return $this->smarty->fetch($this->template);
 }
예제 #2
0
	function initAuthenticationObject($notification)
	{
		$auth = new Piwik_Login_Auth();
		Zend_Registry::set('auth', $auth);

		$action = Piwik::getAction();
		if(Piwik::getModule() === 'API'
			&& (empty($action) || $action == 'index'))
		{
			return;
		}

		$authCookieName = Zend_Registry::get('config')->General->login_cookie_name;
		$authCookieExpiry = time() + Zend_Registry::get('config')->General->login_cookie_expire;
		$authCookie = new Piwik_Cookie($authCookieName, $authCookieExpiry);
		$defaultLogin = '******';
		$defaultTokenAuth = 'anonymous';
		if($authCookie->isCookieFound())
		{
			$defaultLogin = $authCookie->get('login');
			$defaultTokenAuth = $authCookie->get('token_auth');
		}
		$auth->setLogin($defaultLogin);
		$auth->setTokenAuth($defaultTokenAuth);
	}
예제 #3
0
	/**
	 * Renders the current view.
	 *
	 * @return string Generated template
	 */
	public function render()
	{
		try {
			$this->currentModule = Piwik::getModule();
			$userLogin = Piwik::getCurrentUserLogin();
			$this->userLogin = $userLogin;
			
			// workaround for #1331
			$count = method_exists('Piwik', 'getWebsitesCountToDisplay') ? Piwik::getWebsitesCountToDisplay() : 1;

			$sites = Piwik_SitesManager_API::getInstance()->getSitesWithAtLeastViewAccess($count);
			usort($sites, create_function('$site1, $site2', 'return strcasecmp($site1["name"], $site2["name"]);'));
			$this->sites = $sites;
			$this->url = Piwik_Common::sanitizeInputValue(Piwik_Url::getCurrentUrl());
			$this->token_auth = Piwik::getCurrentUserTokenAuth();
			$this->userHasSomeAdminAccess = Piwik::isUserHasSomeAdminAccess();
			$this->userIsSuperUser = Piwik::isUserIsSuperUser();
			$this->latest_version_available = Piwik_UpdateCheck::isNewestVersionAvailable();
			$this->disableLink = Piwik_Common::getRequestVar('disableLink', 0, 'int');
			$this->isWidget = Piwik_Common::getRequestVar('widget', 0, 'int');
			if(Zend_Registry::get('config')->General->autocomplete_min_sites <= count($sites))
			{
				$this->show_autocompleter = true;
			}
			else
			{
				$this->show_autocompleter = false;
			}

			// workaround for #1331
			$this->loginModule = method_exists('Piwik', 'getLoginPluginName') ? Piwik::getLoginPluginName() : 'Login';
			
			$user = Piwik_UsersManager_API::getInstance()->getUser($userLogin);
			$this->userAlias = $user['alias'];
			
		} catch(Exception $e) {
			// can fail, for example at installation (no plugin loaded yet)
		}
		
		$this->totalTimeGeneration = Zend_Registry::get('timer')->getTime();
		try {
			$this->totalNumberOfQueries = Piwik::getQueryCount();
		}
		catch(Exception $e){
			$this->totalNumberOfQueries = 0;
		}
 
		// workaround for #1331
		if(method_exists('Piwik', 'overrideCacheControlHeaders'))
		{
			Piwik::overrideCacheControlHeaders('no-store');
		}
		@header('Content-Type: '.$this->contentType);
		if($this->xFrameOptions)
		{
			@header('X-Frame-Options: '.$this->xFrameOptions);
		}
		
		return $this->smarty->fetch($this->template);
	}
예제 #4
0
/**
 * Returns the current AdminMenu name
 * @return boolean
 */
function Piwik_GetCurrentAdminMenuName()
{
    $menu = Piwik_GetAdminMenu();
    $currentModule = Piwik::getModule();
    $currentAction = Piwik::getAction();
    foreach ($menu as $name => $parameters) {
        if ($parameters['_url']['module'] == $currentModule && $parameters['_url']['action'] == $currentAction) {
            return $name;
        }
    }
    return false;
}
예제 #5
0
 /**
  * Renders the current view.
  *
  * @return string Generated template
  */
 public function render()
 {
     try {
         $this->currentModule = Piwik::getModule();
         $this->currentAction = Piwik::getAction();
         $userLogin = Piwik::getCurrentUserLogin();
         $this->userLogin = $userLogin;
         $count = Piwik::getWebsitesCountToDisplay();
         $sites = Piwik_SitesManager_API::getInstance()->getSitesWithAtLeastViewAccess($count);
         usort($sites, create_function('$site1, $site2', 'return strcasecmp($site1["name"], $site2["name"]);'));
         $this->sites = $sites;
         $this->url = Piwik_Common::sanitizeInputValue(Piwik_Url::getCurrentUrl());
         $this->token_auth = Piwik::getCurrentUserTokenAuth();
         $this->userHasSomeAdminAccess = Piwik::isUserHasSomeAdminAccess();
         $this->userIsSuperUser = Piwik::isUserIsSuperUser();
         $this->latest_version_available = Piwik_UpdateCheck::isNewestVersionAvailable();
         $this->disableLink = Piwik_Common::getRequestVar('disableLink', 0, 'int');
         $this->isWidget = Piwik_Common::getRequestVar('widget', 0, 'int');
         if (Piwik_Config::getInstance()->General['autocomplete_min_sites'] <= count($sites)) {
             $this->show_autocompleter = true;
         } else {
             $this->show_autocompleter = false;
         }
         $this->loginModule = Piwik::getLoginPluginName();
         $user = Piwik_UsersManager_API::getInstance()->getUser($userLogin);
         $this->userAlias = $user['alias'];
     } catch (Exception $e) {
         // can fail, for example at installation (no plugin loaded yet)
     }
     $this->totalTimeGeneration = Zend_Registry::get('timer')->getTime();
     try {
         $this->totalNumberOfQueries = Piwik::getQueryCount();
     } catch (Exception $e) {
         $this->totalNumberOfQueries = 0;
     }
     Piwik::overrideCacheControlHeaders('no-store');
     @header('Content-Type: ' . $this->contentType);
     // always sending this header, sometimes empty, to ensure that Dashboard embed loads (which could call this header() multiple times, the last one will prevail)
     @header('X-Frame-Options: ' . (string) $this->xFrameOptions);
     return $this->smarty->fetch($this->template);
 }
예제 #6
0
 /**
  * Initializes the authentication object.
  * Listens to FrontController.initAuthenticationObject hook.
  *
  * @param Piwik_Event_Notification $notification  notification object
  */
 function initAuthenticationObject($notification)
 {
     $auth = new Piwik_Login_Auth();
     Zend_Registry::set('auth', $auth);
     $allowCookieAuthentication = $notification->getNotificationInfo();
     $action = Piwik::getAction();
     if (Piwik::getModule() === 'API' && (empty($action) || $action == 'index') && $allowCookieAuthentication !== true) {
         return;
     }
     $authCookieName = Piwik_Config::getInstance()->General['login_cookie_name'];
     $authCookieExpiry = 0;
     $authCookiePath = Piwik_Config::getInstance()->General['login_cookie_path'];
     $authCookie = new Piwik_Cookie($authCookieName, $authCookieExpiry, $authCookiePath);
     $defaultLogin = '******';
     $defaultTokenAuth = 'anonymous';
     if ($authCookie->isCookieFound()) {
         $defaultLogin = $authCookie->get('login');
         $defaultTokenAuth = $authCookie->get('token_auth');
     }
     $auth->setLogin($defaultLogin);
     $auth->setTokenAuth($defaultTokenAuth);
 }
예제 #7
0
 /**
  * Returns the plugin currently being used to display the page
  *
  * @return Piwik_Plugin
  */
 public static function getCurrentPlugin()
 {
     return Piwik_PluginsManager::getInstance()->getLoadedPlugin(Piwik::getModule());
 }
예제 #8
0
 protected function setGeneralVariablesView($view)
 {
     $view->date = $this->strDate;
     try {
         $this->setPeriodVariablesView($view);
         $period = Piwik_Period::factory(Piwik_Common::getRequestVar('period'), Piwik_Date::factory($this->strDate));
         $view->prettyDate = $period->getLocalizedLongString();
         $idSite = Piwik_Common::getRequestVar('idSite');
         $view->idSite = $idSite;
         $site = new Piwik_Site($idSite);
         $view->siteName = $site->getName();
         $view->siteMainUrl = $site->getMainUrl();
         $minDate = $site->getCreationDate();
         $view->minDateYear = $minDate->toString('Y');
         $view->minDateMonth = $minDate->toString('m');
         $view->minDateDay = $minDate->toString('d');
     } catch (Exception $e) {
         self::redirectToIndex(Piwik::getModule(), Piwik::getAction());
     }
 }
예제 #9
0
 protected function runUpdaterAndExit()
 {
     $updater = new Piwik_Updater();
     $componentsWithUpdateFile = Piwik_CoreUpdater::getComponentUpdates($updater);
     if (empty($componentsWithUpdateFile)) {
         Piwik::redirectToModule('CoreHome');
     }
     Piwik::setMaxExecutionTime(0);
     $sqlQueries = $updater->getSqlQueriesToExecute();
     if (Piwik_Common::isPhpCliMode()) {
         $view = Piwik_View::factory('update_welcome');
         $this->doWelcomeUpdates($view, $componentsWithUpdateFile);
         echo $view->render();
         if (!$this->coreError && Piwik::getModule() == 'CoreUpdater') {
             $view = Piwik_View::factory('update_database_done');
             $this->doExecuteUpdates($view, $updater, $componentsWithUpdateFile);
             echo $view->render();
         }
     } else {
         if (Piwik_Common::getRequestVar('updateCorePlugins', 0, 'integer') == 1) {
             $this->warningMessages = array();
             $view = Piwik_View::factory('update_database_done');
             $this->doExecuteUpdates($view, $updater, $componentsWithUpdateFile);
             if (count($sqlQueries) == 1 && !$this->coreError) {
                 Piwik::redirectToModule('CoreHome');
             }
             echo $view->render();
         } else {
             $view = Piwik_View::factory('update_welcome');
             $view->queries = $sqlQueries;
             $this->doWelcomeUpdates($view, $componentsWithUpdateFile);
             echo $view->render();
         }
     }
     exit;
 }
예제 #10
0
 /**
  * Called at the end of the page generation
  *
  */
 function __destruct()
 {
     try {
         Piwik::printSqlProfilingReportZend();
         Piwik::printQueryCount();
     } catch (Exception $e) {
     }
     if (Piwik::getModule() !== 'API') {
         //			Piwik::printMemoryUsage();
         //			Piwik::printTimer();
     }
 }
예제 #11
0
	protected function setGeneralVariablesView($view)
	{
		$view->date = $this->strDate;
		
		try {
			$this->setPeriodVariablesView($view);
			$period = Piwik_Period::factory(Piwik_Common::getRequestVar('period'), Piwik_Date::factory($this->strDate));
			$view->prettyDate = $period->getLocalizedLongString();
			$idSite = Piwik_Common::getRequestVar('idSite');
			$view->idSite = $idSite;
			$site = new Piwik_Site($idSite);
			$view->siteName = $site->getName();
			$view->siteMainUrl = $site->getMainUrl();
			
			$minDate = $site->getCreationDate();
			$view->minDateYear = $minDate->toString('Y');
			$view->minDateMonth = $minDate->toString('m');
			$view->minDateDay = $minDate->toString('d');

			$maxDate = Piwik_Date::factory('today');
			$view->maxDateYear = $maxDate->toString('Y');
			$view->maxDateMonth = $maxDate->toString('m');
			$view->maxDateDay = $maxDate->toString('d');

			$view->debugTrackVisitsInsidePiwikUI = Zend_Registry::get('config')->Debug->track_visits_inside_piwik_ui;

			$view->isSuperUser = Zend_Registry::get('access')->isSuperUser();
		} catch(Exception $e) {
			self::redirectToIndex(Piwik::getModule(), Piwik::getAction());
		}
	}