Example #1
0
 private static function addWidgets()
 {
     if (!self::$hookCalled) {
         self::$hookCalled = true;
         Piwik_PostEvent('WidgetsList.add');
     }
 }
	function dispatch($notification = null)
	{
		if($notification)
		{
			$exception = $notification->getNotificationObject();
			$message = $exception->getMessage();
		}
		else
		{
			$message = '';
		}

		Piwik_Translate::getInstance()->loadCoreTranslation();

		Piwik_PostEvent('Installation.startInstallation', $this);

		$step = Piwik_Common::getRequestVar('action', 'welcome', 'string');
		$controller = $this->getInstallationController();
		if(in_array($step, array_keys($controller->getInstallationSteps())) || $step == 'saveLanguage')
		{
			$controller->$step($message);
		}
		else
		{
			Piwik::exitWithErrorMessage(Piwik_Translate('Installation_NoConfigFound'));
		}

		exit;
	}	
Example #3
0
 /**
  * Triggers the AdminMenu.add hook and returns the menu.
  *
  * @return Array
  */
 public function get()
 {
     if (!$this->menu) {
         Piwik_PostEvent('AdminMenu.add');
     }
     return parent::get();
 }
Example #4
0
 public function __construct()
 {
     if (!isset($_SESSION['currentStepDone'])) {
         $_SESSION['currentStepDone'] = '';
     }
     Piwik_PostEvent('InstallationController.construct', $this);
 }
Example #5
0
 /**
  * Main method to process logs for a day. The only logic done here is computing the number of visits, actions, etc.
  * All the other reports are computed inside plugins listening to the event 'ArchiveProcessing_Day.compute'.
  * See some of the plugins for an example eg. 'Provider'
  */
 protected function compute()
 {
     if (!$this->isThereSomeVisits()) {
         return;
     }
     Piwik_PostEvent('ArchiveProcessing_Day.compute', $this);
 }
Example #6
0
 function get()
 {
     Piwik_PostEvent('Menu.add');
     $this->applyEdits();
     $this->applyRenames();
     $this->applyOrdering();
     return $this->menu;
 }
Example #7
0
 /**
  * Triggers the Menu.add hook and returns the menu.
  *
  * @return Array
  */
 public function get()
 {
     // We trigger the Event only once!
     if (!$this->menu) {
         Piwik_PostEvent('Menu.add');
     }
     return parent::get();
 }
Example #8
0
 public function __construct()
 {
     $this->session = new Zend_Session_Namespace("Installation");
     if (!isset($this->session->currentStepDone)) {
         $this->session->currentStepDone = '';
     }
     Piwik_PostEvent('InstallationController.construct', $this);
 }
Example #9
0
 static function get()
 {
     if (!self::$hookCalled) {
         self::$hookCalled = true;
         Piwik_PostEvent('WidgetsList.add');
     }
     return self::$widgets;
 }
 public function __construct()
 {
     $this->session = new Piwik_Session_Namespace('Piwik_Installation');
     if (!isset($this->session->currentStepDone)) {
         $this->session->currentStepDone = '';
         $this->session->skipThisStep = array();
     }
     Piwik_PostEvent('InstallationController.construct', $this);
 }
	static public function runTasks()
	{
		// Gets the array where rescheduled timetables are stored
		$option = Piwik_GetOption(self::TIMETABLE_OPTION_STRING);

        $timetable = self::getTimetableFromOption($option);
        if($timetable === false) {
            return;
        }

		if(isset($GLOBALS['PIWIK_TRACKER_DEBUG_FORCE_SCHEDULED_TASKS']) && $GLOBALS['PIWIK_TRACKER_DEBUG_FORCE_SCHEDULED_TASKS'])
		{
			$timetable = array();
		}
		// Collects tasks
		Piwik_PostEvent(self::GET_TASKS_EVENT, $tasks);

		$return = array();
		// Loop through each task
		foreach ($tasks as $task)
		{
			$scheduledTime = $task->getScheduledTime();
			$className = $task->getClassName();
			$methodName = $task->getMethodName();

			$fullyQualifiedMethodName = get_class($className) . '.' . $methodName;
				
			/*
			 * Task has to be executed if :
			 * 	- it is the first time, ie. rescheduledTime is not set
			 *  - that task has already been executed and the current system time is greater than the
			 *    rescheduled time.
			 */
			if ( !isset($timetable[$fullyQualifiedMethodName])
    			|| (isset($timetable[$fullyQualifiedMethodName])
    			&& time() >= $timetable[$fullyQualifiedMethodName]) )
			{
				// Updates the rescheduled time
				$timetable[$fullyQualifiedMethodName] = $scheduledTime->getRescheduledTime();
				Piwik_SetOption(self::TIMETABLE_OPTION_STRING, serialize($timetable));

				// Run the task
				try {
					$timer = new Piwik_Timer;
					call_user_func ( array($className,$methodName) );
					$message = $timer->__toString();
				} catch(Exception $e) {
					$message = 'ERROR: '.$e->getMessage();
				}
				$return[] = array('task' => $fullyQualifiedMethodName, 'output' => $message);

			}
		}
		return $return;

	}
/**
 * Posts an event from a smarty template. This event can then be hooked by another plugin.
 * The event will be posted along with a string value that plugins can edit.
 * This is useful to allow other plugins to add content at a specific entry point in the template.
 * This string will be returned by the smarty function.
 *
 * Examples:
 * <pre>
 *         {postEvent name="template_footerUserCountry"}
 * </pre>
 *
 * Plugins can then hook on this event by using the Piwik_AddAction function:
 *     Piwik_AddAction('template_footerUserCountry', 'functionToHookOnThisEvent');
 *
 * @param $params array([name] => The name of the event)
 * @param $smarty
 * @throws Exception
 * @return string The string eventually modified by the plugins listening to this event
 */
function smarty_function_postEvent($params, &$smarty)
{
    if (!isset($params['name'])) {
        throw new Exception("The smarty function postEvent needs a 'name' parameter.");
    }
    $eventName = $params['name'];
    $str = '';
    Piwik_PostEvent($eventName, $str);
    return $str;
}
Example #13
0
 /**
  * runTasks collects tasks defined within piwik plugins, runs them if they are scheduled and reschedules
  * the tasks that have been executed.
  *
  * @return array
  */
 public static function runTasks()
 {
     // Gets the array where rescheduled timetables are stored
     $option = Piwik_GetOption(self::TIMETABLE_OPTION_STRING);
     $timetable = self::getTimetableFromOption($option);
     if ($timetable === false) {
         return;
     }
     $forceScheduledTasks = false;
     if (isset($GLOBALS['PIWIK_TRACKER_DEBUG_FORCE_SCHEDULED_TASKS']) && $GLOBALS['PIWIK_TRACKER_DEBUG_FORCE_SCHEDULED_TASKS'] || DEBUG_FORCE_SCHEDULED_TASKS) {
         $forceScheduledTasks = true;
         $timetable = array();
     }
     // Collects tasks
     Piwik_PostEvent(self::GET_TASKS_EVENT, $tasks);
     $return = array();
     // for every priority level, starting with the highest and concluding with the lowest
     for ($priority = Piwik_ScheduledTask::HIGHEST_PRIORITY; $priority <= Piwik_ScheduledTask::LOWEST_PRIORITY; ++$priority) {
         // Loop through each task
         foreach ($tasks as $task) {
             // if the task does not have the current priority level, don't execute it yet
             if ($task->getPriority() != $priority) {
                 continue;
             }
             $scheduledTime = $task->getScheduledTime();
             $className = $task->getClassName();
             $methodName = $task->getMethodName();
             $fullyQualifiedMethodName = get_class($className) . '.' . $methodName;
             /*
              * Task has to be executed if :
              * 	- it is the first time, ie. rescheduledTime is not set
              *  - that task has already been executed and the current system time is greater than the
              *    rescheduled time.
              */
             if (!isset($timetable[$fullyQualifiedMethodName]) || isset($timetable[$fullyQualifiedMethodName]) && time() >= $timetable[$fullyQualifiedMethodName] || $forceScheduledTasks) {
                 // Updates the rescheduled time
                 $timetable[$fullyQualifiedMethodName] = $scheduledTime->getRescheduledTime();
                 Piwik_SetOption(self::TIMETABLE_OPTION_STRING, serialize($timetable));
                 self::$running = true;
                 // Run the task
                 try {
                     $timer = new Piwik_Timer();
                     call_user_func(array($className, $methodName));
                     $message = $timer->__toString();
                 } catch (Exception $e) {
                     $message = 'ERROR: ' . $e->getMessage();
                 }
                 self::$running = false;
                 $return[] = array('task' => $fullyQualifiedMethodName, 'output' => $message);
             }
         }
     }
     return $return;
 }
Example #14
0
 function startInstallation()
 {
     Piwik_PostEvent('Installation.startInstallation', $this);
     $step = Piwik_Common::getRequestVar('action', 'welcome', 'string');
     $controller = $this->getInstallationController();
     if (in_array($step, $controller->getInstallationSteps())) {
         $controller->{$step}();
     } else {
         Piwik::exitWithErrorMessage(Piwik_Translate('Installation_NoConfigFound'));
     }
     exit;
 }
Example #15
0
 public function archiveDay($notification)
 {
     /**
      * @var Piwik_ArchiveProcessing_Day 
      */
     $this->archiveProcessing = $notification->getNotificationObject();
     $this->archiveDayAggregateVisits($this->archiveProcessing);
     $this->archiveDayAggregateGoals($this->archiveProcessing);
     Piwik_PostEvent('Referers.archiveDay', $this);
     $this->archiveDayRecordInDatabase($this->archiveProcessing);
     $this->cleanup();
 }
Example #16
0
 public static function getReportsWithGoalMetrics()
 {
     $dimensions = array();
     Piwik_PostEvent('Goals.getReportsWithGoalMetrics', $dimensions);
     $dimensionsByGroup = array();
     foreach ($dimensions as $dimension) {
         $group = $dimension['category'];
         unset($dimension['category']);
         $dimensionsByGroup[$group][] = $dimension;
     }
     return $dimensionsByGroup;
 }
Example #17
0
 /**
  * Given an Object implementing Piwik_iView interface, we either:
  * - echo the output of the rendering if fetch = false
  * - returns the output of the rendering if fetch = true
  *
  * @param Piwik_ViewDataTable $view
  * @param bool $fetch
  * @return string|void
  */
 protected function renderView(Piwik_ViewDataTable $view, $fetch = false)
 {
     Piwik_PostEvent('Controller.renderView', $this, array('view' => $view, 'controllerName' => $view->getCurrentControllerName(), 'controllerAction' => $view->getCurrentControllerAction(), 'apiMethodToRequestDataTable' => $view->getApiMethodToRequestDataTable(), 'controllerActionCalledWhenRequestSubTable' => $view->getControllerActionCalledWhenRequestSubTable()));
     $standardColumnNameToTranslation = array_map('Piwik_Translate', $this->standardColumnNameToTranslation);
     $view->setColumnsTranslations($standardColumnNameToTranslation);
     $view->main();
     $rendered = $view->getView()->render();
     if ($fetch) {
         return $rendered;
     }
     echo $rendered;
 }
Example #18
0
 function dispatch()
 {
     Piwik_Translate::getInstance()->loadUserTranslation();
     Piwik_PostEvent('Installation.startInstallation', $this);
     $step = Piwik_Common::getRequestVar('action', 'welcome', 'string');
     $controller = $this->getInstallationController();
     if (in_array($step, array_keys($controller->getInstallationSteps())) || $step == 'saveLanguage') {
         $controller->{$step}();
     } else {
         Piwik::exitWithErrorMessage(Piwik_Translate('Installation_NoConfigFound'));
     }
     exit;
 }
Example #19
0
 public function get()
 {
     if (!is_null($this->adminMenu)) {
         return;
     }
     Piwik_PostEvent('AdminMenu.add');
     foreach ($this->adminMenu as $key => &$element) {
         if (is_null($element)) {
             unset($this->adminMenu[$key]);
         }
     }
     return $this->adminMenu;
 }
 public static function setUpBeforeClass($dbName = false, $createEmptyDatabase = true, $createConfig = true)
 {
     try {
         Piwik::$piwikUrlCache = '';
         if ($createConfig) {
             self::createTestConfig();
         }
         if ($dbName === false) {
             $dbName = Piwik_Config::getInstance()->database['dbname'];
         }
         self::connectWithoutDatabase();
         if ($createEmptyDatabase) {
             Piwik::dropDatabase();
         }
         Piwik::createDatabase($dbName);
         Piwik::disconnectDatabase();
         // reconnect once we're sure the database exists
         Piwik_Config::getInstance()->database['dbname'] = $dbName;
         Piwik::createDatabaseObject();
         Piwik::createTables();
         Piwik::createLogObject();
         Piwik_PluginsManager::getInstance()->loadPlugins(array());
     } catch (Exception $e) {
         self::fail("TEST INITIALIZATION FAILED: " . $e->getMessage());
     }
     include "DataFiles/SearchEngines.php";
     include "DataFiles/Languages.php";
     include "DataFiles/Countries.php";
     include "DataFiles/Currencies.php";
     include "DataFiles/LanguageToCountry.php";
     Piwik::createAccessObject();
     Piwik_PostEvent('FrontController.initAuthenticationObject');
     // We need to be SU to create websites for tests
     Piwik::setUserIsSuperUser();
     // Load and install plugins
     $pluginsManager = Piwik_PluginsManager::getInstance();
     $plugins = $pluginsManager->readPluginsDirectory();
     $pluginsManager->loadPlugins($plugins);
     if ($createEmptyDatabase) {
         $pluginsManager->installLoadedPlugins();
     }
     $_GET = $_REQUEST = array();
     $_SERVER['HTTP_REFERER'] = '';
     // Make sure translations are loaded to check messages in English
     Piwik_Translate::getInstance()->loadEnglishTranslation();
     Piwik_LanguagesManager_API::getInstance()->setLanguageForUser('superUserLogin', 'en');
     // List of Modules, or Module.Method that should not be called as part of the XML output compare
     // Usually these modules either return random changing data, or are already tested in specific unit tests.
     self::setApiNotToCall(self::$defaultApiNotToCall);
     self::setApiToCall(array());
 }
Example #21
0
 /**
  * Main method to process logs for a day. The only logic done here is computing the number of visits, actions, etc.
  * All the other reports are computed inside plugins listening to the event 'ArchiveProcessing_Day.compute'.
  * See some of the plugins for an example eg. 'Provider'
  * 
  * @return void
  */
 protected function compute()
 {
     $query = "SELECT \tcount(distinct visitor_idcookie) as nb_uniq_visitors, \n\t\t\t\t\t\t\tcount(*) as nb_visits,\n\t\t\t\t\t\t\tsum(visit_total_actions) as nb_actions, \n\t\t\t\t\t\t\tmax(visit_total_actions) as max_actions, \n\t\t\t\t\t\t\tsum(visit_total_time) as sum_visit_length,\n\t\t\t\t\t\t\tsum(case visit_total_actions when 1 then 1 else 0 end) as bounce_count \n\t\t\t\t\tFROM " . $this->logTable . "\n\t\t\t\t\tWHERE visit_server_date = ?\n\t\t\t\t\t\tAND idsite = ?\n\t\t\t\t\tGROUP BY visit_server_date\n\t\t\t\t\tORDER BY NULL\n\t\t\t\t ";
     $row = $this->db->fetchRow($query, array($this->strDateStart, $this->idsite));
     //		echo " archiving ".$this->strDateStart;
     if ($row === false) {
         return;
     }
     $this->isThereSomeVisits = true;
     foreach ($row as $name => $value) {
         $record = new Piwik_ArchiveProcessing_Record_Numeric($name, $value);
     }
     Piwik_PostEvent('ArchiveProcessing_Day.compute', $this);
 }
Example #22
0
File: Day.php Project: ntulip/piwik
 /**
  * Main method to process logs for a day. The only logic done here is computing the number of visits, actions, etc.
  * All the other reports are computed inside plugins listening to the event 'ArchiveProcessing_Day.compute'.
  * See some of the plugins for an example eg. 'Provider'
  */
 protected function compute()
 {
     $query = "SELECT \tcount(distinct visitor_idcookie) as nb_uniq_visitors, \n\t\t\t\t\t\t\tcount(*) as nb_visits,\n\t\t\t\t\t\t\tsum(visit_total_actions) as nb_actions, \n\t\t\t\t\t\t\tmax(visit_total_actions) as max_actions, \n\t\t\t\t\t\t\tsum(visit_total_time) as sum_visit_length,\n\t\t\t\t\t\t\tsum(case visit_total_actions when 1 then 1 else 0 end) as bounce_count,\n\t\t\t\t\t\t\tsum(case visit_goal_converted when 1 then 1 else 0 end) as nb_visits_converted\n\t\t\t\t\tFROM " . $this->logTable . "\n\t\t\t\t\tWHERE visit_server_date = ?\n\t\t\t\t\t\tAND idsite = ?\n\t\t\t\t\tGROUP BY visit_server_date\n\t\t\t\t\tORDER BY NULL\n\t\t\t\t ";
     $row = $this->db->fetchRow($query, array($this->strDateStart, $this->idsite));
     if ($row === false || $row === null) {
         return;
     }
     $this->isThereSomeVisits = true;
     foreach ($row as $name => $value) {
         $this->insertNumericRecord($name, $value);
     }
     $this->setNumberOfVisits($row['nb_visits']);
     $this->setNumberOfVisitsConverted($row['nb_visits_converted']);
     Piwik_PostEvent('ArchiveProcessing_Day.compute', $this);
 }
Example #23
0
 /**
  * @return string the language filename prefix, eg 'en' for english
  * @throws exception if the language set is not a valid filename
  */
 public function getLanguageToLoad()
 {
     static $language = null;
     if (!is_null($language)) {
         return $language;
     }
     Piwik_PostEvent('Translate.getLanguageToLoad', $language);
     if (is_null($language) || empty($language)) {
         $language = Zend_Registry::get('config')->General->default_language;
     }
     if (Piwik_Common::isValidFilename($language)) {
         return $language;
     } else {
         throw new Exception("The language selected ('{$language}') is not a valid language file ");
     }
 }
Example #24
0
 /**
  * Returns all available widgets
  * The event WidgetsList.add is used to create the list
  *
  * @return array
  */
 public static function get()
 {
     if (!self::$hookCalled) {
         self::$hookCalled = true;
         Piwik_PostEvent('WidgetsList.add');
     }
     uksort(self::$widgets, array('Piwik_WidgetsList', '_sortWidgetCategories'));
     $widgets = array();
     foreach (self::$widgets as $key => $v) {
         if (isset($widgets[Piwik_Translate($key)])) {
             $v = array_merge($widgets[Piwik_Translate($key)], $v);
         }
         $widgets[Piwik_Translate($key)] = $v;
     }
     return $widgets;
 }
Example #25
0
 /**
  * Constructs the request to the API, given the request url
  * 
  * @param string GET request that defines the API call (must at least contain a "method" parameter) 
  *  Example: method=UserSettings.getWideScreen&idSite=1&date=yesterday&period=week&format=xml
  * 	If a request is not provided, then we use the $_GET and $_POST superglobal and fetch
  * 	the values directly from the HTTP GET query.
  */
 function __construct($request = null)
 {
     $defaultRequest = $_GET + $_POST;
     $requestArray = $defaultRequest;
     if (!is_null($request)) {
         $request = trim($request);
         $request = str_replace(array("\n", "\t"), '', $request);
         parse_str($request, $requestArray);
         // if a token_auth is specified in the API request, we load the right permissions
         if (isset($requestArray['token_auth'])) {
             Piwik_PostEvent('API.Request.authenticate', $requestArray['token_auth']);
             Zend_Registry::get('access')->reloadAccess();
         }
         $requestArray = $requestArray + $defaultRequest;
     }
     foreach ($requestArray as &$element) {
         if (!is_array($element)) {
             $element = trim($element);
         }
     }
     $this->request = $requestArray;
 }
Example #26
0
	public function get()
	{
		if(!is_null($this->adminMenuOrdered))
		{
			return $this->adminMenuOrdered;
		}
		
		Piwik_PostEvent('AdminMenu.add');

		$this->adminMenuOrdered = array();
		ksort($this->adminMenu);
		foreach($this->adminMenu as $order => $menu)
		{
			foreach($menu as $key => &$element)
    		{
    			if(!is_null($element))
    			{
    				$this->adminMenuOrdered[$key] = $element;
    			}
    		}
		}
		return $this->adminMenuOrdered;
	}
Example #27
0
 protected function initSettings($smConf)
 {
     if (count($smConf) == 0) {
         $smConf = Piwik_Config::getInstance()->smarty;
     }
     foreach ($smConf as $key => $value) {
         $this->{$key} = $value;
     }
     $this->template_dir = $smConf['template_dir'];
     array_walk($this->template_dir, array("Piwik_Smarty", "addPiwikPath"), PIWIK_INCLUDE_PATH);
     $this->plugins_dir = $smConf['plugins_dir'];
     array_walk($this->plugins_dir, array("Piwik_Smarty", "addPiwikPath"), PIWIK_INCLUDE_PATH);
     $this->compile_dir = $smConf['compile_dir'];
     Piwik_Smarty::addPiwikPath($this->compile_dir, null, PIWIK_USER_PATH);
     $this->cache_dir = $smConf['cache_dir'];
     Piwik_Smarty::addPiwikPath($this->cache_dir, null, PIWIK_USER_PATH);
     $error_reporting = $smConf['error_reporting'];
     if ($error_reporting != (string) (int) $error_reporting) {
         $error_reporting = self::bitwise_eval($error_reporting);
     }
     $this->error_reporting = $error_reporting;
     Piwik_PostEvent('Smarty.initSettings', $this);
 }
Example #28
0
 /**
  * Returns the Tracker_Visit object.
  * This method can be overwritten to use a different Tracker_Visit object
  *
  * @throws Exception
  * @return Piwik_Tracker_Visit
  */
 protected function getNewVisitObject()
 {
     $visit = null;
     Piwik_PostEvent('Tracker.getNewVisitObject', $visit);
     if (is_null($visit)) {
         $visit = new Piwik_Tracker_Visit(self::$forcedIpString, self::$forcedDateTime);
         $visit->setForcedVisitorId(self::$forcedVisitorId);
     } elseif (!$visit instanceof Piwik_Tracker_Visit_Interface) {
         throw new Exception("The Visit object set in the plugin must implement Piwik_Tracker_Visit_Interface");
     }
     return $visit;
 }
Example #29
0
 /**
  * Returns the hostname extension (site.co.jp in fvae.VARG.ceaga.site.co.jp)
  * given the full hostname looked up from the IP
  *
  * @param string $hostname
  *
  * @return string
  */
 private function getCleanHostname($hostname)
 {
     $extToExclude = array('com', 'net', 'org', 'co');
     $off = strrpos($hostname, '.');
     $ext = substr($hostname, $off);
     if (empty($off) || is_numeric($ext) || strlen($hostname) < 5) {
         return 'Ip';
     } else {
         $cleanHostname = null;
         Piwik_PostEvent('Provider.getCleanHostname', $cleanHostname, $hostname);
         if ($cleanHostname !== null) {
             return $cleanHostname;
         }
         $e = explode('.', $hostname);
         $s = sizeof($e);
         // if extension not correct
         if (isset($e[$s - 2]) && in_array($e[$s - 2], $extToExclude)) {
             return $e[$s - 3] . "." . $e[$s - 2] . "." . $e[$s - 1];
         } else {
             return $e[$s - 2] . "." . $e[$s - 1];
         }
     }
 }
Example #30
0
 /**
  * Returns the Tracker_Visit object.
  * This method can be overwritten to use a different Tracker_Visit object
  *
  * @return Piwik_Tracker_Visit
  */
 protected function getNewVisitObject()
 {
     $visit = null;
     Piwik_PostEvent('Tracker.getNewVisitObject', $visit);
     if (is_null($visit)) {
         $visit = new Piwik_Tracker_Visit();
     } elseif (!$visit instanceof Piwik_Tracker_Visit_Interface) {
         throw new Exception("The Visit object set in the plugin must implement Piwik_Tracker_Visit_Interface");
     }
     return $visit;
 }