diff --git a/core/API/DocumentationGenerator.php b/core/API/DocumentationGenerator.php index 34ee2c1034ce47c85d63abdc189f60b4ad0ed97b..bc3dcf8b014fc38e5a043fb18ac4a7680388d524 100644 --- a/core/API/DocumentationGenerator.php +++ b/core/API/DocumentationGenerator.php @@ -25,7 +25,7 @@ class Piwik_API_DocumentationGenerator { $plugins = Piwik_PluginsManager::getInstance()->getLoadedPluginsName(); foreach ($plugins as $plugin) { - $plugin = Piwik::unprefixClass($plugin); + $plugin = Piwik_Common::unprefixClass($plugin); try { Piwik_API_Proxy::getInstance()->registerClass('Piwik_' . $plugin . '_API'); } catch (Exception $e) { diff --git a/core/API/Proxy.php b/core/API/Proxy.php index e7ed698f6e5f88df9b184cc0a506e7705e37162b..8bb16832ac6c9384baf7cec58adec2458c4d57ef 100644 --- a/core/API/Proxy.php +++ b/core/API/Proxy.php @@ -190,12 +190,13 @@ class Piwik_API_Proxy // allow plugins to manipulate the value if (substr($className, 0, 6) == 'Piwik_' && substr($className, -4) == '_API') { $pluginName = substr($className, 6, -4); - Piwik_PostEvent('API.Proxy.processReturnValue', $returnedValue, array( - 'className' => $className, - 'module' => $pluginName, - 'action' => $methodName, - 'parameters' => &$parametersRequest - )); + Piwik_PostEvent('API.Proxy.processReturnValue', array( + &$returnedValue, + array('className' => $className, + 'module' => $pluginName, + 'action' => $methodName, + 'parameters' => &$parametersRequest) + )); } // Restore the request diff --git a/core/API/Request.php b/core/API/Request.php index 1d074cc03ea8af4274eb4a2b97256aeca7f758d9..53654cec5874bb9fbdf1226c11b2cea9b2207fbd 100644 --- a/core/API/Request.php +++ b/core/API/Request.php @@ -164,7 +164,7 @@ class Piwik_API_Request // if a token_auth is specified in the API request, we load the right permissions $token_auth = Piwik_Common::getRequestVar('token_auth', '', 'string', $request); if ($token_auth) { - Piwik_PostEvent('API.Request.authenticate', $token_auth); + Piwik_PostEvent('API.Request.authenticate', array($token_auth)); Zend_Registry::get('access')->reloadAccess(); Piwik::raiseMemoryLimitIfNecessary(); } diff --git a/core/ArchiveProcessor/Day.php b/core/ArchiveProcessor/Day.php index aeb49cc450fae845785eafbc23c2f58b7948233f..7507da0591ed70461b7899f55e9f70bb4a91e34d 100644 --- a/core/ArchiveProcessor/Day.php +++ b/core/ArchiveProcessor/Day.php @@ -97,6 +97,6 @@ class Piwik_ArchiveProcessor_Day extends Piwik_ArchiveProcessor protected function compute() { - Piwik_PostEvent('ArchiveProcessing_Day.compute', $this); + Piwik_PostEvent('ArchiveProcessing_Day.compute', array(&$this)); } } diff --git a/core/ArchiveProcessor/Period.php b/core/ArchiveProcessor/Period.php index ff052ac6ae24725678646eefba6d150ff2da7ba5..e16cf8956d440b076ef851b950e807d34973544c 100644 --- a/core/ArchiveProcessor/Period.php +++ b/core/ArchiveProcessor/Period.php @@ -173,7 +173,7 @@ class Piwik_ArchiveProcessor_Period extends Piwik_ArchiveProcessor protected function compute() { - Piwik_PostEvent('ArchiveProcessing_Period.compute', $this); + Piwik_PostEvent('ArchiveProcessing_Period.compute', array(&$this)); } protected function aggregateCoreVisitsMetrics() diff --git a/core/AssetManager.php b/core/AssetManager.php index a1a1f9b14c571826baaf3f5401b0e2d7f9d40a3c..ca8ba38c37a868a5e68bc0ea346e00710646c7f7 100644 --- a/core/AssetManager.php +++ b/core/AssetManager.php @@ -123,7 +123,7 @@ class Piwik_AssetManager $mergedContent = cssmin::minify($mergedContent); $mergedContent = str_replace("\n", "\r\n", $mergedContent); - Piwik_PostEvent('AssetManager.filterMergedCss', $mergedContent); + Piwik_PostEvent('AssetManager.filterMergedCss', array(&$mergedContent)); self::writeAssetToFile($mergedContent, self::MERGED_CSS_FILE); } @@ -174,7 +174,7 @@ class Piwik_AssetManager private static function getCssFiles() { $cssFiles = array(); - Piwik_PostEvent(self::CSS_IMPORT_EVENT, $cssFiles); + Piwik_PostEvent(self::CSS_IMPORT_EVENT, array(&$cssFiles)); $cssFiles = self::sortCssFiles($cssFiles); return $cssFiles; } @@ -237,7 +237,7 @@ class Piwik_AssetManager } $mergedContent = str_replace("\n", "\r\n", $mergedContent); - Piwik_PostEvent('AssetManager.filterMergedJs', $mergedContent); + Piwik_PostEvent('AssetManager.filterMergedJs', array(&$mergedContent)); self::writeAssetToFile($mergedContent, self::MERGED_JS_FILE); } @@ -266,7 +266,7 @@ class Piwik_AssetManager private static function getJsFiles() { $jsFiles = array(); - Piwik_PostEvent(self::JS_IMPORT_EVENT, $jsFiles); + Piwik_PostEvent(self::JS_IMPORT_EVENT, array(&$jsFiles)); $jsFiles = self::sortJsFiles($jsFiles); return $jsFiles; } diff --git a/core/Common.php b/core/Common.php index 8e442a37a9f2774e9a3602d96c3799ec7d5a92be..e9a4625573d29edf4f808d76d7bb79b8573df2b0 100644 --- a/core/Common.php +++ b/core/Common.php @@ -20,6 +20,8 @@ */ class Piwik_Common { + const CLASSES_PREFIX = 'Piwik_'; + /** * Const used to map the referer type to an integer in the log_visit table */ @@ -1025,7 +1027,7 @@ class Piwik_Common public static function getCountry($lang, $enableLanguageToCountryGuess, $ip) { $country = null; - Piwik_PostEvent('Common.getCountry', $country, $ip); + Piwik_PostEvent('Common.getCountry', array(&$country, $ip)); if (!empty($country)) { return strtolower($country); } @@ -1549,6 +1551,21 @@ class Piwik_Common ? Piwik_UserCountry_LocationProvider_Default::ID : $cache['currentLocationProviderId']; } + + /** + * Unprefix class name (if needed) + * + * @param string $class + * @return string + */ + public static function unprefixClass($class) + { + $lenPrefix = strlen(self::CLASSES_PREFIX); + if (!strncmp($class, self::CLASSES_PREFIX, $lenPrefix)) { + return substr($class, $lenPrefix); + } + return $class; + } } /** diff --git a/core/Controller.php b/core/Controller.php index 0ae3c333208ae96ea8e98f70949c7be461229bf6..b961f8759e28ef1a8e535b7fda8c0895659dbb66 100644 --- a/core/Controller.php +++ b/core/Controller.php @@ -134,7 +134,7 @@ abstract class Piwik_Controller */ protected function renderView(Piwik_ViewDataTable $view, $fetch = false) { - Piwik_PostEvent('Controller.renderView', + Piwik_PostEvent('Controller.renderView', array( $this, array('view' => $view, 'controllerName' => $view->getCurrentControllerName(), @@ -142,7 +142,7 @@ abstract class Piwik_Controller 'apiMethodToRequestDataTable' => $view->getApiMethodToRequestDataTable(), 'controllerActionCalledWhenRequestSubTable' => $view->getControllerActionCalledWhenRequestSubTable(), ) - ); + )); $view->main(); @@ -698,7 +698,7 @@ abstract class Piwik_Controller $defaultWebsiteId = $defaultReport; } - Piwik_PostEvent('Controller.getDefaultWebsiteId', $defaultWebsiteId); + Piwik_PostEvent('Controller.getDefaultWebsiteId', array(&$defaultWebsiteId)); if ($defaultWebsiteId) { return $defaultWebsiteId; diff --git a/core/Db/Schema.php b/core/Db/Schema.php index 8cf56ccb8553482d33b7901322bac73715110d95..e9057e4852a1580dc9b39d058ec7457435cd75a2 100644 --- a/core/Db/Schema.php +++ b/core/Db/Schema.php @@ -128,7 +128,7 @@ class Piwik_Db_Schema private function loadSchema() { $schema = null; - Piwik_PostEvent('Schema.loadSchema', $schema); + Piwik_PostEvent('Schema.loadSchema', array(&$schema)); if ($schema === null) { $config = Piwik_Config::getInstance(); $dbInfos = $config->database; @@ -260,4 +260,4 @@ class Piwik_Db_Schema { return $this->getSchema()->hasTables(); } -} \ No newline at end of file +} diff --git a/core/EventDispatcher.php b/core/EventDispatcher.php new file mode 100644 index 0000000000000000000000000000000000000000..f39148c7a4e1bce8ee34ca4d0f5e3952add827b2 --- /dev/null +++ b/core/EventDispatcher.php @@ -0,0 +1,206 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + * @category Piwik + * @package Piwik + */ + +/** + * This class allows code to post events from anywhere in Piwik and for + * plugins to associate callbacks to be executed when events are posted. + */ +class Piwik_EventDispatcher +{ + // implementation details for postEvent + const EVENT_CALLBACK_GROUP_FIRST = 0; + const EVENT_CALLBACK_GROUP_SECOND = 1; + const EVENT_CALLBACK_GROUP_THIRD = 2; + + /** + * Singleton instance. + */ + private static $instance = null; + + /** + * Returns the singleton EventDispatcher instance. Creates it if necessary. + */ + public static function getInstance() + { + if (self::$instance === null) { + self::$instance = new Piwik_EventDispatcher(); + } + return self::$instance; + } + + /** + * Array of observers (callbacks attached to events) that are not methods + * of plugin classes. + * + * @var array + */ + private $extraObservers = array(); + + /** + * Array storing information for all pending events. Each item in the array + * will be an array w/ two elements: + * + * array( + * 'Event.Name', // the event name + * array('event', 'parameters') // the parameters to pass to event observers + * ) + * + * @var array + */ + private $pendingEvents = array(); + + /** + * Triggers an event, executing all callbacks associated with it. + * + * @param string $eventName The name of the event, ie, API.getReportMetadata. + * @param array $params The parameters to pass to each callback when executing. + * @param bool $pending Whether this event should be posted again for plugins + * loaded after the event is fired. + * @param array|null $plugins The plugins to post events to. If null, the event + * is posted to all plugins. The elements of this array + * can be either the Piwik_Plugin objects themselves + * or their string names. + */ + public function postEvent($eventName, $params, $pending = false, $plugins = null) + { + if ($pending) { + $this->pendingEvents[] = array($eventName, $params); + } + + if (empty($plugins)) { + $plugins = Piwik_PluginsManager::getInstance()->getLoadedPlugins(); + } + + $callbacks = array(); + + // collect all callbacks to execute + foreach ($plugins as $plugin) { + if (is_string($plugin)) { + $plugin = Piwik_PluginsManager::getInstance()->getLoadedPlugin($plugin); + } + + $hooks = $plugin->getListHooksRegistered(); + + if (isset($hooks[$eventName])) { + list($pluginFunction, $callbackGroup) = $this->getCallbackFunctionAndGroupNumber($hooks[$eventName]); + + $callbacks[$callbackGroup][] = array($plugin, $pluginFunction); + } + } + + if (isset($this->extraObservers[$eventName])) { + foreach ($this->extraObservers[$eventName] as $callbackInfo) { + list($callback, $callbackGroup) = $this->getCallbackFunctionAndGroupNumber($callbackInfo); + + $callbacks[$callbackGroup][] = $callback; + } + } + + // execute callbacks in order + foreach ($callbacks as $callbackGroup) { + foreach ($callbackGroup as $callback) { + call_user_func_array($callback, $params); + } + } + } + + /** + * Associates a callback that is not a plugin class method with an event + * name. + * + * @param string $eventName + * @param array $callback This can be a normal PHP callback or an array + * that looks like this: + * array( + * 'function' => $callback, + * 'before' => true + * ) + * or this: + * array( + * 'function' => $callback, + * 'after' => true + * ) + * If 'before' is set, the callback will be executed + * before normal & 'after' ones. If 'after' then it + * will be executed after normal ones. + */ + public function addObserver($eventName, $callback) + { + $this->extraObservers[$eventName][] = $callback; + } + + /** + * Removes all registered observers for an event name. Only used for testing. + * + * @param string $eventName + */ + public function clearObservers($eventName) + { + $this->extraObservers[$eventName] = array(); + } + + /** + * Re-posts all pending events to the given plugin. + * + * @param Piwik_Plugin $plugin + */ + public function postPendingEventsTo($plugin) + { + foreach ($this->pendingEvents as $eventInfo) { + list($eventName, $eventParams) = $eventInfo; + $this->postEvent($eventName, $eventParams, $pending = false, array($plugin)); + } + } + + private function getCallbackFunctionAndGroupNumber($hookInfo) + { + if (is_array($hookInfo) + && !empty($hookInfo['function']) + ) { + $pluginFunction = $hookInfo['function']; + if (!empty($hookInfo['before'])) { + $callbackGroup = self::EVENT_CALLBACK_GROUP_FIRST; + } else if (!empty($hookInfo['after'])) { + $callbackGroup = self::EVENT_CALLBACK_GROUP_SECOND; + } else { + $callbackGroup = self::EVENT_CALLBACK_GROUP_THIRD; + } + } else { + $pluginFunction = $hookInfo; + $callbackGroup = self::EVENT_CALLBACK_GROUP_SECOND; + } + + return array($pluginFunction, $callbackGroup); + } +} + +/** + * Post an event to the dispatcher which will notice the observers. + * + * @param string $eventName The event name. + * @param array $params The parameter array to forward to observer callbacks. + * @return void + */ +function Piwik_PostEvent($eventName, $params = array(), $pending = false, $plugins = null) +{ + Piwik_EventDispatcher::getInstance()->postEvent($eventName, $params, $pending, $plugins); +} + +/** + * Register an action to execute for a given event + * + * @param string $eventName Name of event + * @param function $function Callback hook + */ +function Piwik_AddAction($eventName, $function) +{ + Piwik_EventDispatcher::getInstance()->addObserver($eventName, $function); +} diff --git a/core/FrontController.php b/core/FrontController.php index f9b6e947c95c6f18eafff3c93a9037aedaff396c..1f0845fbc36cf131ba6813b032087be0e4d283b4 100644 --- a/core/FrontController.php +++ b/core/FrontController.php @@ -124,7 +124,7 @@ class Piwik_FrontController try { return call_user_func_array(array($params[0], $params[1]), $params[2]); } catch (Piwik_Access_NoAccessException $e) { - Piwik_PostEvent('FrontController.NoAccessException', $e); + Piwik_PostEvent('FrontController.NoAccessException', array($e), $pending = true); } catch (Exception $e) { $debugTrace = $e->getTraceAsString(); $message = Piwik_Common::sanitizeInputValue($e->getMessage()); @@ -191,7 +191,7 @@ class Piwik_FrontController try { Piwik::createConfigObject(); } catch (Exception $e) { - Piwik_PostEvent('FrontController.NoConfigurationFile', $e, $info = array(), $pending = true); + Piwik_PostEvent('FrontController.NoConfigurationFile', array($e), $pending = true); $exceptionToThrow = $e; } return $exceptionToThrow; @@ -261,7 +261,7 @@ class Piwik_FrontController if (self::shouldRethrowException()) { throw $e; } - Piwik_PostEvent('FrontController.badConfigurationFile', $e, $info = array(), $pending = true); + Piwik_PostEvent('FrontController.badConfigurationFile', array($e), $pending = true); throw $e; } diff --git a/core/Piwik.php b/core/Piwik.php index d9f2ba99136c6f5d9b38193037231d0d14be0364..8f2d737fe01fc315c3634b0e51181f437d87433d 100644 --- a/core/Piwik.php +++ b/core/Piwik.php @@ -22,7 +22,6 @@ require_once PIWIK_INCLUDE_PATH . '/core/Translate.php'; */ class Piwik { - const CLASSES_PREFIX = 'Piwik_'; const COMPRESSED_FILE_LOCATION = '/tmp/assets/'; /** @@ -84,25 +83,10 @@ class Piwik */ static public function prefixClass($class) { - if (!strncmp($class, Piwik::CLASSES_PREFIX, strlen(Piwik::CLASSES_PREFIX))) { + if (!strncmp($class, Piwik_Common::CLASSES_PREFIX, strlen(Piwik_Common::CLASSES_PREFIX))) { return $class; } - return Piwik::CLASSES_PREFIX . $class; - } - - /** - * Unprefix class name (if needed) - * - * @param string $class - * @return string - */ - static public function unprefixClass($class) - { - $lenPrefix = strlen(Piwik::CLASSES_PREFIX); - if (!strncmp($class, Piwik::CLASSES_PREFIX, $lenPrefix)) { - return substr($class, $lenPrefix); - } - return $class; + return Piwik_Common::CLASSES_PREFIX . $class; } /** @@ -1550,8 +1534,8 @@ class Piwik $segments = Piwik_Config::getInstance()->Segments; $cachedResult = isset($segments['Segments']) ? $segments['Segments'] : array(); - Piwik_PostEvent('Piwik.getKnownSegmentsToArchiveAllSites', $cachedResult); - + Piwik_PostEvent('Piwik.getKnownSegmentsToArchiveAllSites', array(&$cachedResult)); + $cachedResult = array_unique($cachedResult); } @@ -1561,7 +1545,7 @@ class Piwik static public function getKnownSegmentsToArchiveForSite($idSite) { $segments = array(); - Piwik_PostEvent('Piwik.getKnownSegmentsToArchiveForSite', $segments, $idSite); + Piwik_PostEvent('Piwik.getKnownSegmentsToArchiveForSite', array(&$segments, $idSite)); return $segments; } @@ -1922,12 +1906,12 @@ class Piwik $dbInfos = $config->database; } - Piwik_PostEvent('Reporting.getDatabaseConfig', $dbInfos); + Piwik_PostEvent('Reporting.getDatabaseConfig', array(&$dbInfos)); $dbInfos['profiler'] = $config->Debug['enable_sql_profiler']; $db = null; - Piwik_PostEvent('Reporting.createDatabase', $db); + Piwik_PostEvent('Reporting.createDatabase', array(&$db)); if (is_null($db)) { $adapter = $dbInfos['adapter']; $db = @Piwik_Db_Adapter::factory($adapter, $dbInfos); diff --git a/core/Plugin.php b/core/Plugin.php index cfc6a0cdb4b6e354cdf34eaea34e5c52a2507918..65ae6bc54b823b102cfb62fafe6724a6f32654e9 100644 --- a/core/Plugin.php +++ b/core/Plugin.php @@ -36,7 +36,17 @@ abstract class Piwik_Plugin /** * Returns the list of hooks registered with the methods names * - * @return array + * @return array eg, array( + * 'API.getReportMetadata' => 'myPluginFunction', + * 'Another.event' => array( + * 'function' => 'myOtherPluginFunction', + * 'after' => true // execute after callbacks w/o ordering + * ) + * 'Yet.Another.event' => array( + * 'function' => 'myOtherPluginFunction', + * 'before' => true // execute before callbacks w/o ordering + * ) + * ) */ public function getListHooksRegistered() { @@ -106,7 +116,7 @@ abstract class Piwik_Plugin */ final public function getPluginName() { - return Piwik::unprefixClass(get_class($this)); + return Piwik_Common::unprefixClass(get_class($this)); } /** diff --git a/core/PluginsArchiver.php b/core/PluginsArchiver.php index d3f0fb31aaf3ef7ab7b00a47565ad324ccf7c56b..e322108033fdb4633e2481f38f2bbf4d9c0afe67 100644 --- a/core/PluginsArchiver.php +++ b/core/PluginsArchiver.php @@ -30,7 +30,7 @@ abstract class Piwik_PluginsArchiver // TODO: Review this concept / each plugin should somehow maintain the list of report names they generate public function shouldArchive() { - $pluginName = Piwik::unprefixClass(get_class($this)); + $pluginName = Piwik_Common::unprefixClass(get_class($this)); $pluginName = str_replace("_Archiver", "", $pluginName); return $this->getProcessor()->shouldProcessReportsForPlugin($pluginName); } @@ -50,4 +50,4 @@ abstract class Piwik_PluginsArchiver { return $this->getProcessor()->getLogAggregator(); } -} \ No newline at end of file +} diff --git a/core/PluginsManager.php b/core/PluginsManager.php index 5e4c7e3a5fc4ddf8bc46883fe14902d2a316f410..f003859a39082ba773244aae03c7034396e25506 100644 --- a/core/PluginsManager.php +++ b/core/PluginsManager.php @@ -16,6 +16,7 @@ * @see core/Menu/Top.php * @see core/PluginsFunctions/WidgetsList.php * @see core/PluginsFunctions/Sql.php + * @see core/EventDispatcher.php */ require_once PIWIK_INCLUDE_PATH . '/core/Menu/Abstract.php'; require_once PIWIK_INCLUDE_PATH . '/core/Menu/Main.php'; @@ -23,6 +24,7 @@ require_once PIWIK_INCLUDE_PATH . '/core/Menu/Admin.php'; require_once PIWIK_INCLUDE_PATH . '/core/Menu/Top.php'; require_once PIWIK_INCLUDE_PATH . '/core/PluginsFunctions/WidgetsList.php'; require_once PIWIK_INCLUDE_PATH . '/core/PluginsFunctions/Sql.php'; +require_once PIWIK_INCLUDE_PATH . '/core/EventDispatcher.php'; /** * Plugin manager @@ -32,11 +34,6 @@ require_once PIWIK_INCLUDE_PATH . '/core/PluginsFunctions/Sql.php'; */ class Piwik_PluginsManager { - /** - * @var Event_Dispatcher - */ - public $dispatcher; - protected $pluginsToLoad = array(); protected $doLoadPlugins = true; @@ -71,11 +68,6 @@ class Piwik_PluginsManager return self::$instance; } - private function __construct() - { - $this->dispatcher = Event_Dispatcher::getInstance(); - } - /** * Update Plugins config * @@ -377,12 +369,6 @@ class Piwik_PluginsManager if ($newPlugin === null) { continue; } - - if ($this->doLoadPlugins - && $this->isPluginActivated($pluginName) - ) { - $this->addPluginObservers($newPlugin); - } } } } @@ -429,6 +415,8 @@ class Piwik_PluginsManager } $this->addLoadedPlugin($pluginName, $newPlugin); + + Piwik_EventDispatcher::getInstance()->postPendingEventsTo($newPlugin); return $newPlugin; } @@ -450,14 +438,7 @@ class Piwik_PluginsManager $plugin = $oPlugin; } - $hooks = $plugin->getListHooksRegistered(); - foreach ($hooks as $hookName => $methodToCall) { - $success = $this->dispatcher->removeObserver(array($plugin, $methodToCall), $hookName); - if ($success !== true) { - throw new Exception("Error unloading plugin = " . $plugin->getPluginName() . ", method = $methodToCall, hook = $hookName "); - } - } unset($this->loadedPlugins[$plugin->getPluginName()]); } @@ -497,21 +478,6 @@ class Piwik_PluginsManager } } - - /** - * For the given plugin, add all the observers of this plugin. - * - * @param Piwik_Plugin $plugin - */ - private function addPluginObservers(Piwik_Plugin $plugin) - { - $hooks = $plugin->getListHooksRegistered(); - - foreach ($hooks as $hookName => $methodToCall) { - $this->dispatcher->addObserver(array($plugin, $methodToCall), $hookName); - } - } - /** * Add a plugin in the loaded plugins array * @@ -658,66 +624,3 @@ class Piwik_PluginsManager_PluginException extends Exception } } -/** - * Post an event to the dispatcher which will notice the observers - * - * @param string $eventName The event name - * @param mixed $object Object, array or string that the listeners can read and/or modify. - * Listeners can call $object =& $notification->getNotificationObject(); to fetch and then modify this variable. - * @param array $info Additional array of data that can be used by the listeners, but not edited - * @param bool $pending Should the notification be posted to plugins that register after the notification was sent? - * @return void - */ -function Piwik_PostEvent($eventName, &$object = null, $info = array(), $pending = false) -{ - $notification = new Piwik_Event_Notification($object, $eventName, $info); - Piwik_PluginsManager::getInstance()->dispatcher->postNotification($notification, $pending, $bubble = false); -} - -/** - * Register an action to execute for a given event - * - * @param string $hookName Name of event - * @param function $function Callback hook - */ -function Piwik_AddAction($hookName, $function) -{ - Piwik_PluginsManager::getInstance()->dispatcher->addObserver($function, $hookName); -} - -/** - * Event notification - * - * @package Piwik - * - * @see Event_Notification, libs/Event/Notification.php - * @link http://pear.php.net/package/Event_Dispatcher/docs/latest/Event_Dispatcher/Event_Notification.html - */ -class Piwik_Event_Notification extends Event_Notification -{ - static $showProfiler = false; - - /** - * Use notification counter to profile runtime execution - * time and memory usage. - */ - function increaseNotificationCount( /* array($className|object, $method) */) - { - parent::increaseNotificationCount(); - if (self::$showProfiler && func_num_args() == 1) { - $callback = func_get_arg(0); - if (is_array($callback)) { - $className = is_object($callback[0]) ? get_class($callback[0]) : $callback[0]; - $method = $callback[1]; - - echo "after $className -> $method <br />"; - echo "-"; - Piwik::printTimer(); - echo "<br />"; - echo "-"; - Piwik::printMemoryLeak(); - echo "<br />"; - } - } - } -} diff --git a/core/TaskScheduler.php b/core/TaskScheduler.php index 1a29780f725c58218d4bfe786d861d1b950e1212..a606a359a51e421a7c60fc95523cb9713434b4fc 100644 --- a/core/TaskScheduler.php +++ b/core/TaskScheduler.php @@ -41,7 +41,7 @@ class Piwik_TaskScheduler // collect tasks $tasks = array(); - Piwik_PostEvent(self::GET_TASKS_EVENT, $tasks); + Piwik_PostEvent(self::GET_TASKS_EVENT, array(&$tasks)); // remove from timetable tasks that are not active anymore $activeTaskNames = array(); diff --git a/core/Tracker.php b/core/Tracker.php index 6396667d0cbd1da63ed0a407b72d6bc6f849ad86..ab4c65520d3d25c564fcf8699de2aa0cf8431e08 100644 --- a/core/Tracker.php +++ b/core/Tracker.php @@ -490,7 +490,7 @@ class Piwik_Tracker $configDb['port'] = '3306'; } - Piwik_PostEvent('Tracker.getDatabaseConfig', $configDb); + Piwik_PostEvent('Tracker.getDatabaseConfig', array(&$configDb)); $db = Piwik_Tracker::factory($configDb); $db->connect(); @@ -506,7 +506,7 @@ class Piwik_Tracker try { $db = null; - Piwik_PostEvent('Tracker.createDatabase', $db); + Piwik_PostEvent('Tracker.createDatabase', array(&$db)); if (is_null($db)) { $db = self::connectPiwikTrackerDb(); } @@ -542,7 +542,7 @@ class Piwik_Tracker protected function getNewVisitObject() { $visit = null; - Piwik_PostEvent('Tracker.getNewVisitObject', $visit); + Piwik_PostEvent('Tracker.getNewVisitObject', array(&$visit)); if (is_null($visit)) { $visit = new Piwik_Tracker_Visit(); diff --git a/core/Tracker/Action.php b/core/Tracker/Action.php index 3ea0cfb5bb776f0cb45251ecd783f28b2d7bb42d..f4b3bb328865c3aee1f5ae470a43701010aea02e 100644 --- a/core/Tracker/Action.php +++ b/core/Tracker/Action.php @@ -709,7 +709,7 @@ class Piwik_Tracker_Action implements Piwik_Tracker_Action_Interface /* * send the Action object ($this) and the list of ids ($info) as arguments to the event */ - Piwik_PostEvent('Tracker.Action.record', $this, $info); + Piwik_PostEvent('Tracker.Action.record', array($this, $info)); } public function getCustomVariables() diff --git a/core/Tracker/Cache.php b/core/Tracker/Cache.php index e7077d17bd5c5f0435b3c0b5cd63cafea1085de3..d277d94f847775a0b21718dd04b76cc0c11aee23 100644 --- a/core/Tracker/Cache.php +++ b/core/Tracker/Cache.php @@ -54,7 +54,7 @@ class Piwik_Tracker_Cache Piwik::setUserIsSuperUser(); $content = array(); - Piwik_PostEvent('Common.fetchWebsiteAttributes', $content, $idSite); + Piwik_PostEvent('Common.fetchWebsiteAttributes', array(&$content, $idSite)); // restore original user privilege Piwik::setUserIsSuperUser($isSuperUser); diff --git a/core/Tracker/GoalManager.php b/core/Tracker/GoalManager.php index fa870d1f3c1776458b20c2a1d7e2c11b570e7722..1f674ce438b17fb584d969af20556d664899ce8c 100644 --- a/core/Tracker/GoalManager.php +++ b/core/Tracker/GoalManager.php @@ -401,7 +401,7 @@ class Piwik_Tracker_GoalManager $this->recordEcommerceItems($goal, $items); } - Piwik_PostEvent('Tracker.recordEcommerceGoal', $goal); + Piwik_PostEvent('Tracker.recordEcommerceGoal', array($goal)); } /** @@ -762,7 +762,7 @@ class Piwik_Tracker_GoalManager $this->recordGoal($newGoal); - Piwik_PostEvent('Tracker.recordStandardGoals', $newGoal); + Piwik_PostEvent('Tracker.recordStandardGoals', array($newGoal)); } } diff --git a/core/Tracker/Referer.php b/core/Tracker/Referer.php index 168c04e158e7e0e79a6f810b2aaf08309cd84b6d..c941e0e480a52cbfd45cdfb4dd7f5215ae7240d9 100644 --- a/core/Tracker/Referer.php +++ b/core/Tracker/Referer.php @@ -124,7 +124,7 @@ class Piwik_Tracker_Referer protected function detectRefererSearchEngine() { $searchEngineInformation = Piwik_Common::extractSearchEngineInformationFromUrl($this->refererUrl); - Piwik_PostEvent('Tracker.detectRefererSearchEngine', $searchEngineInformation, $this->refererUrl); + Piwik_PostEvent('Tracker.detectRefererSearchEngine', array(&$searchEngineInformation, $this->refererUrl)); if ($searchEngineInformation === false) { return false; } diff --git a/core/Tracker/Request.php b/core/Tracker/Request.php index ec656d758269a58d618869808a411deb400a62a8..486808e3aef61ae6672b68cd1f2762e7eb168903 100644 --- a/core/Tracker/Request.php +++ b/core/Tracker/Request.php @@ -260,7 +260,7 @@ class Piwik_Tracker_Request public function getIdSite() { $idSite = Piwik_Common::getRequestVar('idsite', 0, 'int', $this->params); - Piwik_PostEvent('Tracker.setRequest.idSite', $idSite, $this->params); + Piwik_PostEvent('Tracker.setRequest.idSite', array(&$idSite, $this->params)); if ($idSite <= 0) { throw new Exception('Invalid idSite'); } @@ -483,4 +483,4 @@ class Piwik_Tracker_Request { return count($this->params); } -} \ No newline at end of file +} diff --git a/core/Tracker/Visit.php b/core/Tracker/Visit.php index 3533e7a929894744063c2f0df3c3c807b8b9e0fa..3058656d51594843217144b067b912acd43972a7 100644 --- a/core/Tracker/Visit.php +++ b/core/Tracker/Visit.php @@ -89,7 +89,7 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface } // Anonymize IP (after testing for IP exclusion) - Piwik_PostEvent('Tracker.Visit.setVisitorIp', $this->visitorInfo['location_ip']); + Piwik_PostEvent('Tracker.Visit.setVisitorIp', array(&$this->visitorInfo['location_ip'])); $this->visitorCustomVariables = $this->request->getCustomVariables($scope = 'visit'); if (!empty($this->visitorCustomVariables)) { @@ -300,7 +300,7 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface $valuesToUpdate = array_merge($valuesToUpdate, $this->visitorCustomVariables); // trigger event before update - Piwik_PostEvent('Tracker.knownVisitorUpdate', $valuesToUpdate); + Piwik_PostEvent('Tracker.knownVisitorUpdate', array(&$valuesToUpdate)); $this->visitorInfo['time_spent_ref_action'] = $this->getTimeSpentRefererAction(); @@ -341,7 +341,7 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface . " wasn't found in the DB, we fallback to a new visitor"); } - Piwik_PostEvent('Tracker.knownVisitorInformation', $this->visitorInfo); + Piwik_PostEvent('Tracker.knownVisitorInformation', array(&$this->visitorInfo)); } /** @@ -461,7 +461,7 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface $extraInfo = array( 'UserAgent' => $this->request->getUserAgent(), ); - Piwik_PostEvent('Tracker.newVisitorInformation', $this->visitorInfo, $extraInfo); + Piwik_PostEvent('Tracker.newVisitorInformation', array(&$this->visitorInfo, $extraInfo)); $debugVisitInfo = $this->visitorInfo; $debugVisitInfo['idvisitor'] = bin2hex($debugVisitInfo['idvisitor']); @@ -494,7 +494,7 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface { $location = array(); $userInfo = array('lang' => $browserLang, 'ip' => Piwik_IP::N2P($this->getVisitorIp())); - Piwik_PostEvent('Tracker.getVisitorLocation', $location, $userInfo); + Piwik_PostEvent('Tracker.getVisitorLocation', array(&$location, $userInfo)); $location = $this->request->enrichLocation($location); @@ -561,7 +561,7 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface */ protected function saveVisitorInformation() { - Piwik_PostEvent('Tracker.saveVisitorInformation', $this->visitorInfo); + Piwik_PostEvent('Tracker.saveVisitorInformation', array(&$this->visitorInfo)); $this->visitorInfo['location_browser_lang'] = substr($this->visitorInfo['location_browser_lang'], 0, 20); $this->visitorInfo['referer_name'] = substr($this->visitorInfo['referer_name'], 0, 70); @@ -581,7 +581,7 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface $this->visitorInfo['visit_first_action_time'] = $this->request->getCurrentTimestamp(); $this->visitorInfo['visit_last_action_time'] = $this->request->getCurrentTimestamp(); - Piwik_PostEvent('Tracker.saveVisitorInformation.end', $this->visitorInfo); + Piwik_PostEvent('Tracker.saveVisitorInformation.end', array(&$this->visitorInfo)); } /** @@ -622,7 +622,6 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface return $this->visitorInfo['location_ip']; } - /** * This methods tries to see if the visitor has visited the website before. * @@ -965,7 +964,7 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface protected function newAction() { $action = null; - Piwik_PostEvent('Tracker.newAction', $action); + Piwik_PostEvent('Tracker.newAction', array(&$action)); if (is_null($action)) { $action = new Piwik_Tracker_Action($this->request); diff --git a/core/Tracker/VisitExcluded.php b/core/Tracker/VisitExcluded.php index 233bb289ed16457a66e8fdf13fa7d1ae4395f09d..2ac0f1826fb32a0ca14e63cb994aa5b8e0b1d04b 100644 --- a/core/Tracker/VisitExcluded.php +++ b/core/Tracker/VisitExcluded.php @@ -63,7 +63,7 @@ class Piwik_Tracker_VisitExcluded } /* custom filters can override the built-in filters above */ - Piwik_PostEvent('Tracker.Visit.isExcluded', $excluded); + Piwik_PostEvent('Tracker.Visit.isExcluded', array(&$excluded)); /* * Following exclude operations happen after the hook. diff --git a/core/Translate.php b/core/Translate.php index e19ea422fcffc626144c3a949f5970963df0b54c..807638357c562b41e5274b2fd60b131feab3392d 100644 --- a/core/Translate.php +++ b/core/Translate.php @@ -97,7 +97,7 @@ class Piwik_Translate if (is_null(self::$languageToLoad)) { $lang = Piwik_Common::getRequestVar('language', '', 'string'); - Piwik_PostEvent('Translate.getLanguageToLoad', $lang); + Piwik_PostEvent('Translate.getLanguageToLoad', array(&$lang)); self::$languageToLoad = $lang; } diff --git a/core/Twig.php b/core/Twig.php index 73440180c2e2ffc7f0f41276d3605cb874c69f4a..47497b00be5cac153827de43dc5aa058585534ad 100644 --- a/core/Twig.php +++ b/core/Twig.php @@ -90,7 +90,7 @@ class Piwik_Twig { $postEventFunction = new Twig_SimpleFunction('postEvent', function ($eventName) { $str = ''; - Piwik_PostEvent($eventName, $str); + Piwik_PostEvent($eventName, array(&$str)); return $str; }, array('is_safe' => array('html'))); $this->twig->addFunction($postEventFunction); @@ -222,7 +222,7 @@ class Piwik_Twig { $plugins = Piwik_PluginsManager::getInstance()->getLoadedPluginsName(); foreach($plugins as $name) { - $name = Piwik::unprefixClass($name); + $name = Piwik_Common::unprefixClass($name); $path = sprintf("%s/plugins/%s/templates/", PIWIK_INCLUDE_PATH, $name); if (is_dir($path)) { $loader->addPath(PIWIK_INCLUDE_PATH . '/plugins/' . $name . '/templates', $name); diff --git a/core/Visualization/Chart.php b/core/Visualization/Chart.php index 1cde982ef01f06fa4a301085d26bd36934d42bb2..74d4bf1b5278510e2d8d05e01fd51f50799807f2 100644 --- a/core/Visualization/Chart.php +++ b/core/Visualization/Chart.php @@ -165,7 +165,7 @@ abstract class Piwik_Visualization_Chart implements Piwik_View_Interface 'seriesPicker' => &$this->seriesPicker ); - Piwik_PostEvent('Visualization_Chart.render', $data); + Piwik_PostEvent('Visualization_Chart.render', array(&$data)); return Piwik_Common::json_encode($data); } diff --git a/libs/Event/Dispatcher.php b/libs/Event/Dispatcher.php deleted file mode 100644 index 8818f15976e02222a83fc0e8311c078a4a6b44e2..0000000000000000000000000000000000000000 --- a/libs/Event/Dispatcher.php +++ /dev/null @@ -1,485 +0,0 @@ -<?php -// +-----------------------------------------------------------------------+ -// | Copyright (c) 2005, Bertrand Mansion | -// | All rights reserved. | -// | | -// | Redistribution and use in source and binary forms, with or without | -// | modification, are permitted provided that the following conditions | -// | are met: | -// | | -// | o Redistributions of source code must retain the above copyright | -// | notice, this list of conditions and the following disclaimer. | -// | o Redistributions in binary form must reproduce the above copyright | -// | notice, this list of conditions and the following disclaimer in the | -// | documentation and/or other materials provided with the distribution.| -// | o The names of the authors may not be used to endorse or promote | -// | products derived from this software without specific prior written | -// | permission. | -// | | -// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | -// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | -// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | -// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | -// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | -// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | -// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | -// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | -// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | -// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | -// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | -// | | -// +-----------------------------------------------------------------------+ -// | Author: Bertrand Mansion <bmansion@mamasam.com> | -// | Stephan Schmidt <schst@php.net> | -// +-----------------------------------------------------------------------+ -// -// $Id$ - -/** - * Pseudo 'static property' for Notification object - * @global array $GLOBALS["_Event_Dispatcher"] - */ -$GLOBALS['_Event_Dispatcher'] = array( - 'NotificationClass' => 'Event_Notification' - ); - -/** - * Registers a global observer - */ -define('EVENT_DISPATCHER_GLOBAL', ''); - -/** - * Dispatch notifications using PHP callbacks - * - * The Event_Dispatcher acts acts as a notification dispatch table. - * It is used to notify other objects of interesting things, if - * they meet certain criteria. This information is encapsulated - * in {@link Event_Notification} objects. Client objects register - * themselves with the Event_Dispatcher as observers of specific - * notifications posted by other objects. When an event occurs, - * an object posts an appropriate notification to the Event_Dispatcher. - * The Event_Dispatcher dispatches a message to each - * registered observer, passing the notification as the sole argument. - * - * The Event_Dispatcher is actually a combination of three design - * patterns: the Singleton, {@link http://c2.com/cgi/wiki?MediatorPattern Mediator}, - * and Observer patterns. The idea behind Event_Dispatcher is borrowed from - * {@link http://developer.apple.com/documentation/Cocoa/Conceptual/Notifications/index.html Apple's Cocoa framework}. - * - * @category Event - * @package Event_Dispatcher - * @author Bertrand Mansion <bmansion@mamasam.com> - * @author Stephan Schmidt <schst@php.net> - * @copyright 1997-2005 The PHP Group - * @license http://www.opensource.org/licenses/bsd-license.php BSD License - * @version Release: @package_version@ - * @link http://pear.php.net/package/Event_Dispatcher - */ -class Event_Dispatcher -{ - /** - * Registered observer callbacks - * @var array - * @access private - */ - var $_ro = array(); - - /** - * Pending notifications - * @var array - * @access private - */ - var $_pending = array(); - - /** - * Nested observers - * @var array - * @access private - */ - var $_nestedDispatchers = array(); - - /** - * Name of the dispatcher - * @var string - * @access private - */ - var $_name = null; - - /** - * Class used for notifications - * @var string - * @access private - */ - var $_notificationClass = null; - - /** - * PHP4 constructor - * - * Please use {@link getInstance()} instead. - * - * @access private - * @param string Name of the notification dispatcher. - */ -// function Event_Dispatcher($name) -// { -// Event_Dispatcher::__construct($name); -// } - - /** - * PHP5 constructor - * - * Please use {@link getInstance()} instead. - * - * @access private - * @param string Name of the notification dispatcher. - */ - function __construct($name) - { - $this->_name = $name; - $this->_notificationClass = $GLOBALS['_Event_Dispatcher']['NotificationClass']; - } - - /** - * Returns a notification dispatcher singleton - * - * There is usually no need to have more than one notification - * center for an application so this is the recommended way - * to get a Event_Dispatcher object. - * - * @param string Name of the notification dispatcher. - * The default notification dispatcher is named __default. - * - * @return object Event_Dispatcher - */ - static function getInstance($name = '__default') - { - static $dispatchers = array(); - - if (!isset($dispatchers[$name])) { - $dispatchers[$name] = new Event_Dispatcher($name); - } - - return $dispatchers[$name]; - } - - /** - * Registers an observer callback - * - * This method registers a {@link http://www.php.net/manual/en/language.pseudo-types.php#language.types.callback callback} - * which is called when the notification corresponding to the - * criteria given at registration time is posted. - * The criteria are the notification name and eventually the - * class of the object posted with the notification. - * - * If there are any pending notifications corresponding to the criteria - * given here, the callback will be called straight away. - * - * If the notification name is empty, the observer will receive all the - * posted notifications. Same goes for the class name. - * - * @access public - * @param mixed A PHP callback - * @param string Expected notification name, serves as a filter - * @param string Expected contained object class, serves as a filter - * @return void - */ - function addObserver($callback, $nName = EVENT_DISPATCHER_GLOBAL, $class = null) - { - if (is_array($callback)) { - if (is_object($callback[0])) { - // Note : PHP4 does not allow correct object comparison so - // only the class name is used for registration checks. - $reg = get_class($callback[0]).'::'.$callback[1]; - } else { - $reg = $callback[0].'::'.$callback[1]; - } - } else { - $reg = $callback; - } - - $this->_ro[$nName][$reg] = array( - 'callback' => $callback, - 'class' => $class - ); - - // Post eventual pending notifications for this observer - if (isset($this->_pending[$nName])) { - foreach (array_keys($this->_pending[$nName]) as $k) { - $notification =& $this->_pending[$nName][$k]; - if (!$notification->isNotificationCancelled()) { - $object = $notification->getNotificationObject(); - $objClass = is_object($object) ? get_class($object) : null; - if (empty($class) || strcasecmp($class, $objClass) == 0) { - call_user_func_array($callback, array(&$notification)); - //-- Piwik Hack --// - $notification->increaseNotificationCount($callback); - //-- End Piwik Hack --// - } - } - } - } - } - - /** - * Creates and posts a notification object - * - * The purpose of the optional associated object is generally to pass - * the object posting the notification to the observers, so that the - * observers can query the posting object for more information about - * the event. - * - * Notifications are by default added to a pending notification list. - * This way, if an observer is not registered by the time they are - * posted, it will still be notified when it is added as an observer. - * This behaviour can be turned off in order to make sure that only - * the registered observers will be notified. - * - * The info array serves as a container for any kind of useful - * information. It is added to the notification object and posted along. - * - * @access public - * @param object Notification associated object - * @param string Notification name - * @param array Optional user information - * @param bool Whether the notification is pending - * @param bool Whether you want the notification to bubble up - * @return object The notification object - */ - function &post(&$object, $nName, $info = array(), $pending = true, $bubble = true) - { - $notification = new $this->_notificationClass($object, $nName, $info); - return $this->postNotification($notification, $pending, $bubble); - } - - /** - * Posts the {@link Event_Notification} object - * - * @access public - * @param object The Notification object - * @param bool Whether to post the notification immediately - * @param bool Whether you want the notification to bubble up - * @see Event_Dispatcher::post() - * @return object The notification object - */ - function &postNotification(&$notification, $pending = true, $bubble = true) - { - $nName = $notification->getNotificationName(); - if ($pending === true) { - $this->_pending[$nName][] =& $notification; - } - - $object = $notification->getNotificationObject(); - $objClass = is_object($object) ? get_class($object) : null; - - // Find the registered observers - if (isset($this->_ro[$nName])) { - foreach (array_keys($this->_ro[$nName]) as $k) { - $rObserver =& $this->_ro[$nName][$k]; - if ($notification->isNotificationCancelled()) { - return $notification; - } - if (empty($rObserver['class']) || - strcasecmp($rObserver['class'], $objClass) == 0) { - $callback = $rObserver['callback']; - call_user_func_array($callback, array(&$notification)); - //-- Piwik Hack --// - $notification->increaseNotificationCount($callback); - //-- End Piwik Hack --// - } - } - } - - // Notify globally registered observers - if (isset($this->_ro[EVENT_DISPATCHER_GLOBAL])) { - foreach (array_keys($this->_ro[EVENT_DISPATCHER_GLOBAL]) as $k) { - $rObserver =& $this->_ro[EVENT_DISPATCHER_GLOBAL][$k]; - if ($notification->isNotificationCancelled()) { - return $notification; - } - if (empty($rObserver['class']) || - strcasecmp($rObserver['class'], $objClass) == 0) { - call_user_func_array($rObserver['callback'], array(&$notification)); - //-- Piwik Hack --// - $notification->increaseNotificationCount(get_class($rObserver['callback'][0]), $rObserver['callback'][1]); - //-- End Piwik Hack --// - } - } - } - - if ($bubble === false) { - return $notification; - } - - // Notify in nested dispatchers - foreach (array_keys($this->_nestedDispatchers) as $nested) { - $notification =& $this->_nestedDispatchers[$nested]->postNotification($notification, $pending); - } - - return $notification; - } - - /** - * Removes a registered observer that correspond to the given criteria - * - * @access public - * @param mixed A PHP callback - * @param string Notification name - * @param string Contained object class - * @return bool True if an observer was removed, false otherwise - */ - function removeObserver($callback, $nName = EVENT_DISPATCHER_GLOBAL, $class = null) - { - if (is_array($callback)) { - if (is_object($callback[0])) { - $reg = get_class($callback[0]).'::'.$callback[1]; - } else { - $reg = $callback[0].'::'.$callback[1]; - } - } else { - $reg = $callback; - } - - $removed = false; - if (isset($this->_ro[$nName][$reg])) { - if (!empty($class)) { - if (strcasecmp($this->_ro[$nName][$reg]['class'], $class) == 0) { - unset($this->_ro[$nName][$reg]); - $removed = true; - } - } else { - unset($this->_ro[$nName][$reg]); - $removed = true; - } - } - - if (isset($this->_ro[$nName]) && count($this->_ro[$nName]) == 0) { - unset($this->_ro[$nName]); - } - return $removed; - } - - /** - * Check, whether the specified observer has been registered with the - * dispatcher - * - * @access public - * @param mixed A PHP callback - * @param string Notification name - * @param string Contained object class - * @return bool True if the observer has been registered, false otherwise - */ - function observerRegistered($callback, $nName = EVENT_DISPATCHER_GLOBAL, $class = null) - { - if (is_array($callback)) { - if (is_object($callback[0])) { - $reg = get_class($callback[0]).'::'.$callback[1]; - } else { - $reg = $callback[0].'::'.$callback[1]; - } - } else { - $reg = $callback; - } - - if (!isset($this->_ro[$nName][$reg])) { - return false; - } - if (empty($class)) { - return true; - } - if (strcasecmp($this->_ro[$nName][$reg]['class'], $class) == 0) { - return true; - } - return false; - } - - /** - * Get all observers, that have been registered for a notification - * - * @access public - * @param string Notification name - * @param string Contained object class - * @return array List of all observers - */ - function getObservers($nName = EVENT_DISPATCHER_GLOBAL, $class = null) - { - $observers = array(); - if (!isset($this->_ro[$nName])) { - return $observers; - } - foreach ($this->_ro[$nName] as $reg => $observer) { - if ($class == null || $observer['class'] == null || strcasecmp($observer['class'], $class) == 0) { - $observers[] = $reg; - } - } - return $observers; - } - - /** - * Get the name of the dispatcher. - * - * The name is the unique identifier of a dispatcher. - * - * @access public - * @return string name of the dispatcher - */ - function getName() - { - return $this->_name; - } - - /** - * add a new nested dispatcher - * - * Notifications will be broadcasted to this dispatcher as well, which - * allows you to create event bubbling. - * - * @access public - * @param Event_Dispatcher The nested dispatcher - */ - function addNestedDispatcher(&$dispatcher) - { - $name = $dispatcher->getName(); - $this->_nestedDispatchers[$name] =& $dispatcher; - } - - /** - * remove a nested dispatcher - * - * @access public - * @param Event_Dispatcher Dispatcher to remove - * @return boolean - */ - function removeNestedDispatcher($dispatcher) - { - if (is_object($dispatcher)) { - $dispatcher = $dispatcher->getName(); - } - if (!isset($this->_nestedDispatchers[$dispatcher])) { - return false; - } - unset($this->_nestedDispatchers[$dispatcher]); - return true; - } - - /** - * Changes the class used for notifications - * - * You may call this method on an object to change it for a single - * dispatcher or statically, to set the default for all dispatchers - * that will be created. - * - * @access public - * @param string name of the notification class - * @return boolean - */ - function setNotificationClass($class) - { - if (isset($this) && is_a($this, 'Event_Dispatcher')) { - $this->_notificationClass = $class; - return true; - } - $GLOBALS['_Event_Dispatcher']['NotificationClass'] = $class; - return true; - } - -} diff --git a/libs/Event/Notification.php b/libs/Event/Notification.php deleted file mode 100644 index 1ce2ccde8dc91e3d74dd224b98e72379e21b857b..0000000000000000000000000000000000000000 --- a/libs/Event/Notification.php +++ /dev/null @@ -1,193 +0,0 @@ -<?php -// +-----------------------------------------------------------------------+ -// | Copyright (c) 2005, Bertrand Mansion | -// | All rights reserved. | -// | | -// | Redistribution and use in source and binary forms, with or without | -// | modification, are permitted provided that the following conditions | -// | are met: | -// | | -// | o Redistributions of source code must retain the above copyright | -// | notice, this list of conditions and the following disclaimer. | -// | o Redistributions in binary form must reproduce the above copyright | -// | notice, this list of conditions and the following disclaimer in the | -// | documentation and/or other materials provided with the distribution.| -// | o The names of the authors may not be used to endorse or promote | -// | products derived from this software without specific prior written | -// | permission. | -// | | -// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | -// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | -// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | -// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | -// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | -// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | -// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | -// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | -// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | -// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | -// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | -// | | -// +-----------------------------------------------------------------------+ -// | Author: Bertrand Mansion <bmansion@mamasam.com> | -// | Stephan Schmidt <schst@php.net> | -// +-----------------------------------------------------------------------+ -// -// $Id$ - -/** - * Default state of the notification - */ -define('EVENT_NOTIFICATION_STATE_DEFAULT', 0); - -/** - * Notification has been cancelled - */ -define('EVENT_NOTIFICATION_STATE_CANCELLED', 1); - -/** - * A Notification object - * - * The Notification object can be easily subclassed and serves as a container - * for the information about the notification. It holds an object which is - * usually a reference to the object that posted the notification, - * a notification name used to identify the notification and some user - * information which can be anything you need. - * - * @category Event - * @package Event_Dispatcher - * @author Bertrand Mansion <bmansion@mamasam.com> - * @author Stephan Schmidt <schst@php.net> - * @copyright 1997-2005 The PHP Group - * @license http://www.opensource.org/licenses/bsd-license.php BSD License - * @version Release: @package_version@ - * @link http://pear.php.net/package/Event_Dispatcher - */ -class Event_Notification -{ - /** - * name of the notofication - * @var string - * @access private - */ - var $_notificationName; - - /** - * object of interesed (the sender of the notification, in most cases) - * @var object - * @access private - */ - var $_notificationObject; - - /** - * additional information about the notification - * @var mixed - * @access private - */ - var $_notificationInfo = array(); - - /** - * state of the notification - * - * This may be: - * - EVENT_NOTIFICATION_STATE_DEFAULT - * - EVENT_NOTIFICATION_STATE_CANCELLED - * - * @var integer - * @access private - */ - var $_notificationState = EVENT_NOTIFICATION_STATE_DEFAULT; - - /** - * amount of observers that received this notification - * @var mixed - * @access private - */ - var $_notificationCount = 0; - - /** - * Constructor - * - * @access public - * @param object The object of interest for the notification, - * usually is the posting object - * @param string Notification name - * @param array Free information array - */ - function Event_Notification(&$object, $name, $info = array()) - { - $this->_notificationObject =& $object; - $this->_notificationName = $name; - $this->_notificationInfo = $info; - } - - /** - * Returns the notification name - * @return string Notification name - */ - function getNotificationName() - { - return $this->_notificationName; - } - - /** - * Returns the contained object - * @return object Contained object - */ - function &getNotificationObject() - { - return $this->_notificationObject; - } - - /** - * Returns the user info array - * @return array user info - */ - function getNotificationInfo() - { - return $this->_notificationInfo; - } - - /** - * Increase the internal count - * - * @access public - */ - function increaseNotificationCount() - { - ++$this->_notificationCount; - } - - /** - * Get the number of posted notifications - * - * @access public - * @return int - */ - function getNotificationCount() - { - return $this->_notificationCount; - } - - /** - * Cancel the notification - * - * @access public - * @return void - */ - function cancelNotification() - { - $this->_notificationState = EVENT_NOTIFICATION_STATE_CANCELLED; - } - - /** - * Checks whether the notification has been cancelled - * - * @access public - * @return boolean - */ - function isNotificationCancelled() - { - return ($this->_notificationState === EVENT_NOTIFICATION_STATE_CANCELLED); - } -} diff --git a/piwik.php b/piwik.php index efc21743109d6f62c5350ca9d52651f4ca606746..0429c7792d1a7c5950464c0940b7980d3017905e 100644 --- a/piwik.php +++ b/piwik.php @@ -31,8 +31,6 @@ if (!defined('PIWIK_INCLUDE_PATH')) { @ignore_user_abort(true); require_once PIWIK_INCLUDE_PATH . '/libs/upgradephp/upgrade.php'; -require_once PIWIK_INCLUDE_PATH . '/libs/Event/Dispatcher.php'; -require_once PIWIK_INCLUDE_PATH . '/libs/Event/Notification.php'; require_once PIWIK_INCLUDE_PATH . '/core/PluginsManager.php'; require_once PIWIK_INCLUDE_PATH . '/core/Plugin.php'; require_once PIWIK_INCLUDE_PATH . '/core/Common.php'; diff --git a/plugins/API/API.php b/plugins/API/API.php index 9843a2ce05ba63c986b9d9cc64e1536dd3369ddc..e7fdca482b0b9d26af75e4b5261e68b292643c9c 100644 --- a/plugins/API/API.php +++ b/plugins/API/API.php @@ -55,13 +55,8 @@ class Piwik_API extends Piwik_Plugin } } - /** - * @param Piwik_Event_Notification $notification notification object - */ - public function getCssFiles($notification) + public function getCssFiles(&$cssFiles) { - $cssFiles = & $notification->getNotificationObject(); - $cssFiles[] = "plugins/API/stylesheets/listAllAPI.css"; } } @@ -133,7 +128,7 @@ class Piwik_API_API public function getSegmentsMetadata($idSites = array(), $_hideImplementationData = true) { $segments = array(); - Piwik_PostEvent('API.getSegmentsMetadata', $segments, $idSites); + Piwik_PostEvent('API.getSegmentsMetadata', array(&$segments, $idSites)); $isAuthenticatedWithViewAccess = Piwik::isUserHasViewAccess($idSites) && !Piwik::isUserIsAnonymous(); @@ -411,7 +406,6 @@ class Piwik_API_API $reporter = new Piwik_API_ProcessedReport(); $metadata = $reporter->getReportMetadata($idSites, $period, $date, $hideMetricsDoc, $showSubtableReports); return $metadata; - } public function getProcessedReport($idSite, $period, $date, $apiModule, $apiAction, $segment = false, diff --git a/plugins/API/ProcessedReport.php b/plugins/API/ProcessedReport.php index f37a2c65274858aef94e78ff5affc72ea70d69ba..63cc65bde35ccb6119c0f0d66df2a6ec0251f46a 100644 --- a/plugins/API/ProcessedReport.php +++ b/plugins/API/ProcessedReport.php @@ -65,7 +65,7 @@ class Piwik_API_ProcessedReport $parameters = array('idSites' => $idSites, 'period' => $period, 'date' => $date); $availableReports = array(); - Piwik_PostEvent('API.getReportMetadata', $availableReports, $parameters); + Piwik_PostEvent('API.getReportMetadata', array(&$availableReports, $parameters)); foreach ($availableReports as &$availableReport) { if (!isset($availableReport['metrics'])) { $availableReport['metrics'] = Piwik_Metrics::getDefaultMetrics(); @@ -84,9 +84,7 @@ class Piwik_API_ProcessedReport } // Some plugins need to add custom metrics after all plugins hooked in - Piwik_PostEvent('API.getReportMetadata.end', $availableReports, $parameters); - // Oh this is not pretty! Until we have event listeners order parameter... - Piwik_PostEvent('API.getReportMetadata.end.end', $availableReports, $parameters); + Piwik_PostEvent('API.getReportMetadata.end', array(&$availableReports, $parameters)); // Sort results to ensure consistent order usort($availableReports, array($this, 'sort')); @@ -540,4 +538,4 @@ class Piwik_API_ProcessedReport ); } -} \ No newline at end of file +} diff --git a/plugins/Actions/Actions.php b/plugins/Actions/Actions.php index 7af357ee76782b4896559da4ee532001186aef5c..505ecbb29d7ce007cdfe307cf420d6cefb5da25e 100644 --- a/plugins/Actions/Actions.php +++ b/plugins/Actions/Actions.php @@ -42,12 +42,8 @@ class Piwik_Actions extends Piwik_Plugin return $hooks; } - /** - * @param Piwik_Event_Notification $notification notification object - */ - public function getSegmentsMetadata($notification) + public function getSegmentsMetadata(&$segments) { - $segments =& $notification->getNotificationObject(); $sqlFilter = array($this, 'getIdActionFromSegment'); // entry and exit pages of visit @@ -176,15 +172,8 @@ class Piwik_Actions extends Piwik_Plugin ); } - /** - * Returns metadata for available reports - * - * @param Piwik_Event_Notification $notification notification object - */ - public function getReportMetadata($notification) + public function getReportMetadata(&$reports) { - $reports = & $notification->getNotificationObject(); - $reports[] = array( 'category' => Piwik_Translate('Actions_Actions'), 'name' => Piwik_Translate('Actions_Actions') . ' - ' . Piwik_Translate('General_MainMetrics'), @@ -561,30 +550,22 @@ class Piwik_Actions extends Piwik_Plugin return Piwik_Site::isSiteSearchEnabledFor($idSite); } - /** * Compute all the actions along with their hierarchies. * * For each action we process the "interest statistics" : * visits, unique visitors, bounce count, sum visit length. - * - * @param Piwik_Event_Notification $notification notification object */ - public function archiveDay($notification) + public function archiveDay(Piwik_ArchiveProcessor_Day $archiveProcessor) { - /* @var $archiveProcessor Piwik_ArchiveProcessor_Day */ - $archiveProcessor = $notification->getNotificationObject(); - $archiving = new Piwik_Actions_Archiver($archiveProcessor); if($archiving->shouldArchive()) { $archiving->archiveDay(); } } - function archivePeriod($notification) + function archivePeriod(Piwik_ArchiveProcessor_Period $archiveProcessor) { - $archiveProcessor = $notification->getNotificationObject(); - $archiving = new Piwik_Actions_Archiver($archiveProcessor); if($archiving->shouldArchive()) { $archiving->archivePeriod(); diff --git a/plugins/Annotations/Annotations.php b/plugins/Annotations/Annotations.php index f8fcf7139431f1164d3574c10146ea21e8a1e483..f95617937de1e81ea399082a071a108784e07a27 100755 --- a/plugins/Annotations/Annotations.php +++ b/plugins/Annotations/Annotations.php @@ -47,23 +47,17 @@ class Piwik_Annotations extends Piwik_Plugin /** * Adds css files for this plugin to the list in the event notification. - * - * @param Piwik_Event_Notification $notification notification object */ - function getCssFiles($notification) + public function getCssFiles(&$cssFiles) { - $cssFiles = & $notification->getNotificationObject(); $cssFiles[] = "plugins/Annotations/stylesheets/annotations.css"; } /** * Adds js files for this plugin to the list in the event notification. - * - * @param Piwik_Event_Notification $notification notification object */ - function getJsFiles($notification) + public function getJsFiles(&$jsFiles) { - $jsFiles = & $notification->getNotificationObject(); $jsFiles[] = "plugins/Annotations/javascripts/annotations.js"; } } diff --git a/plugins/AnonymizeIP/AnonymizeIP.php b/plugins/AnonymizeIP/AnonymizeIP.php index e7b311fc267866584ffc0825c7d1c7d46e31b7d9..35942d18b22097dc5a9a2292940c3c2b8a55d962 100644 --- a/plugins/AnonymizeIP/AnonymizeIP.php +++ b/plugins/AnonymizeIP/AnonymizeIP.php @@ -65,12 +65,9 @@ class Piwik_AnonymizeIP extends Piwik_Plugin /** * Hook on Tracker.Visit.setVisitorIp to anonymize visitor IP addresses - * - * @param Piwik_Event_Notification $notification notification object */ - function setVisitorIpAddress($notification) + public function setVisitorIpAddress(&$ip) { - $ip =& $notification->getNotificationObject(); $ip = self::applyIPMask($ip, Piwik_Config::getInstance()->Tracker['ip_address_mask_length']); } } diff --git a/plugins/CoreAdminHome/CoreAdminHome.php b/plugins/CoreAdminHome/CoreAdminHome.php index b23df6d5ac58dfd237a3a6f40bbf47a81cabba32..bce5c3caafd153db1c888f4dc5eec607121df2e8 100644 --- a/plugins/CoreAdminHome/CoreAdminHome.php +++ b/plugins/CoreAdminHome/CoreAdminHome.php @@ -35,13 +35,8 @@ class Piwik_CoreAdminHome extends Piwik_Plugin ); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getScheduledTasks($notification) + public function getScheduledTasks(&$tasks) { - $tasks = & $notification->getNotificationObject(); - // general data purge on older archive tables, executed daily $purgeArchiveTablesTask = new Piwik_ScheduledTask ($this, 'purgeOutdatedArchives', @@ -59,13 +54,8 @@ class Piwik_CoreAdminHome extends Piwik_Plugin $tasks[] = $optimizeArchiveTableTask; } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getCssFiles($notification) + public function getCssFiles(&$cssFiles) { - $cssFiles = & $notification->getNotificationObject(); - $cssFiles[] = "libs/jquery/themes/base/jquery-ui.css"; $cssFiles[] = "plugins/CoreAdminHome/stylesheets/menu.css"; $cssFiles[] = "plugins/Zeitgeist/stylesheets/common.css"; @@ -73,13 +63,8 @@ class Piwik_CoreAdminHome extends Piwik_Plugin $cssFiles[] = "plugins/CoreHome/stylesheets/donate.css"; } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getJsFiles($notification) + public function getJsFiles(&$jsFiles) { - $jsFiles = & $notification->getNotificationObject(); - $jsFiles[] = "libs/jquery/jquery.js"; $jsFiles[] = "libs/jquery/jquery-ui.js"; $jsFiles[] = "libs/jquery/jquery.browser.js"; diff --git a/plugins/CoreHome/CoreHome.php b/plugins/CoreHome/CoreHome.php index a10b7a0968e11cbd06e79b916942c9143ec01a26..20312002c2c2432b3a3ea3e41b737cb288de905d 100644 --- a/plugins/CoreHome/CoreHome.php +++ b/plugins/CoreHome/CoreHome.php @@ -36,7 +36,6 @@ class Piwik_CoreHome extends Piwik_Plugin /** * Adds the donate form widget. - * */ public function addWidgets() { @@ -44,13 +43,8 @@ class Piwik_CoreHome extends Piwik_Plugin Piwik_AddWidget('Example Widgets', 'Installation_Welcome', 'CoreHome', 'getPromoVideo'); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getCssFiles($notification) + public function getCssFiles(&$cssFiles) { - $cssFiles = & $notification->getNotificationObject(); - $cssFiles[] = "libs/jquery/themes/base/jquery-ui.css"; $cssFiles[] = "plugins/Zeitgeist/stylesheets/common.css"; $cssFiles[] = "plugins/CoreHome/stylesheets/corehome.css"; @@ -63,13 +57,8 @@ class Piwik_CoreHome extends Piwik_Plugin $cssFiles[] = "plugins/CoreHome/stylesheets/promo.css"; } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getJsFiles($notification) + public function getJsFiles(&$jsFiles) { - $jsFiles = & $notification->getNotificationObject(); - $jsFiles[] = "libs/jquery/jquery.js"; $jsFiles[] = "libs/jquery/jquery-ui.js"; $jsFiles[] = "libs/jquery/jquery.browser.js"; diff --git a/plugins/CustomVariables/CustomVariables.php b/plugins/CustomVariables/CustomVariables.php index 3f3421fe4161dbf51617ed4b84ec31dd4894409f..9792032e6b74068b50bda2a17f8307897113f12c 100644 --- a/plugins/CustomVariables/CustomVariables.php +++ b/plugins/CustomVariables/CustomVariables.php @@ -27,7 +27,7 @@ class Piwik_CustomVariables extends Piwik_Plugin return $info; } - function getListHooksRegistered() + public function getListHooksRegistered() { $hooks = array( 'ArchiveProcessing_Day.compute' => 'archiveDay', @@ -41,25 +41,21 @@ class Piwik_CustomVariables extends Piwik_Plugin return $hooks; } - function addWidgets() + public function addWidgets() { Piwik_AddWidget('General_Visitors', 'CustomVariables_CustomVariables', 'CustomVariables', 'getCustomVariables'); } - function addMenus() + public function addMenus() { Piwik_AddMenu('General_Visitors', 'CustomVariables_CustomVariables', array('module' => 'CustomVariables', 'action' => 'index'), $display = true, $order = 50); } /** * Returns metadata for available reports - * - * @param Piwik_Event_Notification $notification notification object */ - public function getReportMetadata($notification) + public function getReportMetadata(&$reports) { - $reports = & $notification->getNotificationObject(); - $documentation = Piwik_Translate('CustomVariables_CustomVariablesReportDocumentation', array('<br />', '<a href="http://piwik.org/docs/custom-variables/" target="_blank">', '</a>')); @@ -82,12 +78,8 @@ class Piwik_CustomVariables extends Piwik_Plugin 'order' => 15); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - public function getSegmentsMetadata($notification) + public function getSegmentsMetadata(&$segments) { - $segments =& $notification->getNotificationObject(); for ($i = 1; $i <= Piwik_Tracker::MAX_CUSTOM_VARIABLES; $i++) { $segments[] = array( 'type' => 'dimension', @@ -126,12 +118,9 @@ class Piwik_CustomVariables extends Piwik_Plugin /** * Adds Goal dimensions, so that the dimensions are displayed in the UI Goal Overview page - * - * @param Piwik_Event_Notification $notification notification object */ - function getReportsWithGoalMetrics($notification) + public function getReportsWithGoalMetrics(&$dimensions) { - $dimensions =& $notification->getNotificationObject(); $dimensions = array_merge($dimensions, array( array('category' => Piwik_Translate('General_Visit'), 'name' => Piwik_Translate('CustomVariables_CustomVariables'), @@ -143,29 +132,20 @@ class Piwik_CustomVariables extends Piwik_Plugin /** * Hooks on daily archive to trigger various log processing - * - * @param Piwik_Event_Notification $notification notification object */ - public function archiveDay($notification) + public function archiveDay(Piwik_ArchiveProcessor_Day $archiveProcessor) { - $archiveProcessor = $notification->getNotificationObject(); - $archiving = new Piwik_CustomVariables_Archiver($archiveProcessor); if($archiving->shouldArchive()) { $archiving->archiveDay(); } } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function archivePeriod($notification) + public function archivePeriod(Piwik_ArchiveProcessor_Period $archiveProcessor) { - $archiveProcessor = $notification->getNotificationObject(); $archiving = new Piwik_CustomVariables_Archiver($archiveProcessor); if($archiving->shouldArchive()) { $archiving->archivePeriod(); } } - } diff --git a/plugins/DBStats/DBStats.php b/plugins/DBStats/DBStats.php index 044e01ddc867760bfe436735d39cd1013456cb4a..05f72ada33b5dba2341aad1e534583b8ee330e23 100644 --- a/plugins/DBStats/DBStats.php +++ b/plugins/DBStats/DBStats.php @@ -46,13 +46,9 @@ class Piwik_DBStats extends Piwik_Plugin /** * Gets all scheduled tasks executed by this plugin. - * - * @param Piwik_Event_Notification $notification notification object */ - public function getScheduledTasks($notification) + public function getScheduledTasks(&$tasks) { - $tasks = & $notification->getNotificationObject(); - $cacheDataByArchiveNameReportsTask = new Piwik_ScheduledTask( $this, 'cacheDataByArchiveNameReports', @@ -77,12 +73,8 @@ class Piwik_DBStats extends Piwik_Plugin Piwik_SetOption(self::TIME_OF_LAST_TASK_RUN_OPTION, $now); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getCssFiles($notification) + public function getCssFiles(&$cssFiles) { - $cssFiles = & $notification->getNotificationObject(); $cssFiles[] = "plugins/DBStats/stylesheets/dbstatsTable.css"; } diff --git a/plugins/Dashboard/Dashboard.php b/plugins/Dashboard/Dashboard.php index 716e055bd7c3e09f3eb8c950b9ad67f928f42fff..5ad1c74b7fce68e92c9999d338e63f3f9d633606 100644 --- a/plugins/Dashboard/Dashboard.php +++ b/plugins/Dashboard/Dashboard.php @@ -226,13 +226,8 @@ class Piwik_Dashboard extends Piwik_Plugin Piwik_AddTopMenu('General_Dashboard', $urlParams, true, 1, $isHTML = false, $tooltip); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getJsFiles($notification) + public function getJsFiles(&$jsFiles) { - $jsFiles = & $notification->getNotificationObject(); - $jsFiles[] = "plugins/Dashboard/javascripts/widgetMenu.js"; $jsFiles[] = "libs/javascript/json2.js"; $jsFiles[] = "plugins/Dashboard/javascripts/dashboardObject.js"; @@ -240,23 +235,14 @@ class Piwik_Dashboard extends Piwik_Plugin $jsFiles[] = "plugins/Dashboard/javascripts/dashboard.js"; } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getCssFiles($notification) + public function getCssFiles(&$cssFiles) { - $cssFiles = & $notification->getNotificationObject(); - $cssFiles[] = "plugins/CoreHome/stylesheets/datatable.css"; $cssFiles[] = "plugins/Dashboard/stylesheets/dashboard.css"; } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function deleteDashboardLayout($notification) + public function deleteDashboardLayout($userLogin) { - $userLogin = $notification->getNotificationObject(); Piwik_Query('DELETE FROM ' . Piwik_Common::prefixTable('user_dashboard') . ' WHERE login = ?', array($userLogin)); } diff --git a/plugins/DevicesDetection/DevicesDetection.php b/plugins/DevicesDetection/DevicesDetection.php index 30c55ffe375fa786dc33f1ca5ca92fd5cf5f5406..2409c58fb2908ac1eda45a2eb592aa14c7534d9c 100644 --- a/plugins/DevicesDetection/DevicesDetection.php +++ b/plugins/DevicesDetection/DevicesDetection.php @@ -131,13 +131,10 @@ class Piwik_DevicesDetection extends Piwik_Plugin /** * Get segments meta data - * - * @param Piwik_Event_Notification $notification notification object */ - public function getSegmentsMetadata($notification) + public function getSegmentsMetadata(&$segments) { // Note: only one field segmented so far: deviceType - $segments =& $notification->getNotificationObject(); foreach ($this->getRawMetadataReports() as $report) { @list($category, $name, $apiModule, $apiAction, $columnName, $segment, $sqlSegment, $acceptedValues) = $report; @@ -154,14 +151,8 @@ class Piwik_DevicesDetection extends Piwik_Plugin } } - - /** - * @param Piwik_Event_Notification $notification notification object - */ - public function getReportMetadata($notification) + public function getReportMetadata(&$reports) { - $reports = & $notification->getNotificationObject(); - $i = 0; foreach ($this->getRawMetadataReports() as $report) { list($category, $name, $apiModule, $apiAction, $columnName) = $report; @@ -211,11 +202,8 @@ class Piwik_DevicesDetection extends Piwik_Plugin } } - public function parseMobileVisitData($notification) + public function parseMobileVisitData(&$visitorInfo, $extraInfo) { - $visitorInfo = &$notification->getNotificationObject(); - - $extraInfo = $notification->getNotificationInfo(); $userAgent = $extraInfo['UserAgent']; $UAParser = new UserAgentParserEnhanced($userAgent); @@ -237,19 +225,16 @@ class Piwik_DevicesDetection extends Piwik_Plugin printDebug($deviceInfo); } - public function archiveDay($notification) + public function archiveDay(Piwik_ArchiveProcessor_Day $archiveProcessor) { - $archiveProcessor = $notification->getNotificationObject(); - $archiving = new Piwik_DevicesDetection_Archiver($archiveProcessor); if($archiving->shouldArchive()) { $archiving->archiveDay(); } } - public function archivePeriod($notification) + public function archivePeriod(Piwik_ArchiveProcessor_Period $archiveProcessor) { - $archiveProcessor = $notification->getNotificationObject(); $archiving = new Piwik_DevicesDetection_Archiver($archiveProcessor); if($archiving->shouldArchive()) { $archiving->archivePeriod(); @@ -260,5 +245,4 @@ class Piwik_DevicesDetection extends Piwik_Plugin { Piwik_AddMenu('General_Visitors', 'DevicesDetection_submenu', array('module' => 'DevicesDetection', 'action' => 'index')); } - -} \ No newline at end of file +} diff --git a/plugins/DoNotTrack/DoNotTrack.php b/plugins/DoNotTrack/DoNotTrack.php index 9d84d0d0e4b7254fa9c4107cdba6cf1494699e9e..954827c2c6a0f0ffd48405d30c02f006ee798e29 100644 --- a/plugins/DoNotTrack/DoNotTrack.php +++ b/plugins/DoNotTrack/DoNotTrack.php @@ -44,10 +44,7 @@ class Piwik_DoNotTrack extends Piwik_Plugin ); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function checkHeader($notification) + function checkHeader(&$exclude) { if ((isset($_SERVER['HTTP_X_DO_NOT_TRACK']) && $_SERVER['HTTP_X_DO_NOT_TRACK'] === '1') || (isset($_SERVER['HTTP_DNT']) && substr($_SERVER['HTTP_DNT'], 0, 1) === '1') @@ -59,7 +56,6 @@ class Piwik_DoNotTrack extends Piwik_Plugin return; } - $exclude =& $notification->getNotificationObject(); $exclude = true; printDebug("DoNotTrack found."); diff --git a/plugins/ExamplePlugin/ExamplePlugin.php b/plugins/ExamplePlugin/ExamplePlugin.php index 1334436bf4715d59d2ea45ae45de631b6ade11de..4c054e4b8caa757c0ff9edb913120d79df93dbbc 100644 --- a/plugins/ExamplePlugin/ExamplePlugin.php +++ b/plugins/ExamplePlugin/ExamplePlugin.php @@ -54,12 +54,8 @@ class Piwik_ExamplePlugin extends Piwik_Plugin // Executed every time plugin is disabled } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function addUniqueVisitorsColumnToGivenReport($notification) + public function addUniqueVisitorsColumnToGivenReport($view) { - $view = $notification->getNotificationInfo(); $view = $view['view']; if ($view->getCurrentControllerName() == 'Referers' && $view->getCurrentControllerAction() == 'getWebsites' @@ -68,7 +64,7 @@ class Piwik_ExamplePlugin extends Piwik_Plugin } } - function addWidgets() + public function addWidgets() { // we register the widgets so they appear in the "Add a new widget" window in the dashboard // Note that the first two parameters can be either a normal string, or an index to a translation string diff --git a/plugins/ExampleRssWidget/ExampleRssWidget.php b/plugins/ExampleRssWidget/ExampleRssWidget.php index fdf1bc78d70c4dc21af046d9e50d6d475ab37bdd..0df7ebb5d0e7f04e41a39dfadce3520317f97e75 100644 --- a/plugins/ExampleRssWidget/ExampleRssWidget.php +++ b/plugins/ExampleRssWidget/ExampleRssWidget.php @@ -45,13 +45,8 @@ class Piwik_ExampleRssWidget extends Piwik_Plugin ); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - public function getCssFiles($notification) + public function getCssFiles(&$cssFiles) { - $cssFiles = & $notification->getNotificationObject(); - $cssFiles[] = "plugins/ExampleRssWidget/stylesheets/rss.css"; } @@ -60,4 +55,4 @@ class Piwik_ExampleRssWidget extends Piwik_Plugin Piwik_AddWidget('Example Widgets', 'Piwik.org Blog', 'ExampleRssWidget', 'rssPiwik'); Piwik_AddWidget('Example Widgets', 'Piwik Changelog', 'ExampleRssWidget', 'rssChangelog'); } -} \ No newline at end of file +} diff --git a/plugins/Feedback/Feedback.php b/plugins/Feedback/Feedback.php index d5142451945285e4040961a2daedeba3de471924..50bab49f99e6d3223fe655298722988924242cf0 100644 --- a/plugins/Feedback/Feedback.php +++ b/plugins/Feedback/Feedback.php @@ -46,24 +46,13 @@ class Piwik_Feedback extends Piwik_Plugin ); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getCssFiles($notification) + public function getCssFiles(&$cssFiles) { - $cssFiles = & $notification->getNotificationObject(); - $cssFiles[] = "plugins/Feedback/stylesheets/feedback.css"; } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getJsFiles($notification) + public function getJsFiles(&$jsFiles) { - $jsFiles = & $notification->getNotificationObject(); - $jsFiles[] = "plugins/Feedback/javascripts/feedback.js"; } - } diff --git a/plugins/Goals/Goals.php b/plugins/Goals/Goals.php index 2ae78f60cc7b7b35db7113b5908d43805f1ac74f..855adb9e3029b0d7b8ea1c71daa4974ede3efd8c 100644 --- a/plugins/Goals/Goals.php +++ b/plugins/Goals/Goals.php @@ -24,7 +24,7 @@ class Piwik_Goals extends Piwik_Plugin static public function getReportsWithGoalMetrics() { $dimensions = array(); - Piwik_PostEvent('Goals.getReportsWithGoalMetrics', $dimensions); + Piwik_PostEvent('Goals.getReportsWithGoalMetrics', array(&$dimensions)); $dimensionsByGroup = array(); foreach ($dimensions as $dimension) { $group = $dimension['category']; @@ -93,12 +93,9 @@ class Piwik_Goals extends Piwik_Plugin /** * Delete goals recorded for this site - * - * @param Piwik_Event_Notification $notification notification object */ - function deleteSiteGoals($notification) + function deleteSiteGoals($idSite) { - $idSite = & $notification->getNotificationObject(); Piwik_Query("DELETE FROM " . Piwik_Common::prefixTable('goal') . " WHERE idsite = ? ", array($idSite)); } @@ -108,14 +105,10 @@ class Piwik_Goals extends Piwik_Plugin * and for each goal. * * Also, this will update metadata of all other reports that have Goal segmentation - * - * @param Piwik_Event_Notification $notification notification object */ - public function getReportMetadata($notification) + public function getReportMetadata(&$reports, $info) { - $info = $notification->getNotificationInfo(); $idSites = $info['idSites']; - $reports = & $notification->getNotificationObject(); // Processed in AddColumnsProcessedMetricsGoal // These metrics will also be available for some reports, for each goal @@ -333,7 +326,7 @@ class Piwik_Goals extends Piwik_Plugin * to all reports that have Goal segmentation */ $reportsWithGoals = array(); - Piwik_PostEvent('Goals.getReportsWithGoalMetrics', $reportsWithGoals); + Piwik_PostEvent('Goals.getReportsWithGoalMetrics', array(&$reportsWithGoals)); foreach ($reportsWithGoals as $reportWithGoals) { // Select this report from the API metadata array // and add the Goal metrics to it @@ -367,12 +360,9 @@ class Piwik_Goals extends Piwik_Plugin * This function executes when the 'Goals.getReportsWithGoalMetrics' event fires. It * adds the 'visits to conversion' report metadata to the list of goal reports so * this report will be displayed. - * - * @param Piwik_Event_Notification $notification notification object */ - function getActualReportsWithGoalMetrics($notification) + public function getActualReportsWithGoalMetrics(&$dimensions) { - $dimensions =& $notification->getNotificationObject(); $dimensions = array_merge($dimensions, array( array('category' => Piwik_Translate('General_Visit'), 'name' => Piwik_Translate('Goals_VisitsUntilConv'), @@ -387,12 +377,8 @@ class Piwik_Goals extends Piwik_Plugin )); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - public function getSegmentsMetadata($notification) + public function getSegmentsMetadata(&$segments) { - $segments =& $notification->getNotificationObject(); $segments[] = array( 'type' => 'dimension', 'category' => Piwik_Translate('General_Visit'), @@ -403,37 +389,23 @@ class Piwik_Goals extends Piwik_Plugin ); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getJsFiles($notification) + public function getJsFiles(&$jsFiles) { - $jsFiles = & $notification->getNotificationObject(); $jsFiles[] = "plugins/Goals/javascripts/goalsForm.js"; } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getCssFiles($notification) + public function getCssFiles(&$cssFiles) { - $cssFiles = & $notification->getNotificationObject(); $cssFiles[] = "plugins/Goals/stylesheets/goals.css"; } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function fetchGoalsFromDb($notification) + public function fetchGoalsFromDb(&$array, $idSite) { - $idsite = $notification->getNotificationInfo(); - // add the 'goal' entry in the website array - $array =& $notification->getNotificationObject(); - $array['goals'] = Piwik_Goals_API::getInstance()->getGoals($idsite); + $array['goals'] = Piwik_Goals_API::getInstance()->getGoals($idSite); } - function addWidgets() + public function addWidgets() { $idSite = Piwik_Common::getRequestVar('idSite', null, 'int'); @@ -502,17 +474,9 @@ class Piwik_Goals extends Piwik_Plugin * Hooks on the Daily archiving. * Will process Goal stats overall and for each Goal. * Also processes the New VS Returning visitors conversion stats. - * - * @param Piwik_Event_Notification $notification - * @return void */ - function archiveDay($notification) + public function archiveDay(Piwik_ArchiveProcessor_Day $archiveProcessor) { - /** - * @var Piwik_ArchiveProcessor_Day - */ - $archiveProcessor = $notification->getNotificationObject(); - $archiving = new Piwik_Goals_Archiver($archiveProcessor); if($archiving->shouldArchive()) { $archiving->archiveDay(); @@ -522,14 +486,9 @@ class Piwik_Goals extends Piwik_Plugin /** * Hooks on Period archiving. * Sums up Goal conversions stats, and processes overall conversion rate - * - * @param Piwik_Event_Notification $notification - * @return void */ - function archivePeriod($notification) + public function archivePeriod(Piwik_ArchiveProcessor_Period $archiveProcessor) { - $archiveProcessor = $notification->getNotificationObject(); - $archiving = new Piwik_Goals_Archiver($archiveProcessor); if($archiving->shouldArchive()) { $archiving->archivePeriod(); diff --git a/plugins/ImageGraph/ImageGraph.php b/plugins/ImageGraph/ImageGraph.php index 06e973f46209575890dda9ad0fc2d76de5f6d401..9ee7fa7f27b2ce643be14fc91b300e77a3b5e21c 100644 --- a/plugins/ImageGraph/ImageGraph.php +++ b/plugins/ImageGraph/ImageGraph.php @@ -36,7 +36,8 @@ class Piwik_ImageGraph extends Piwik_Plugin function getListHooksRegistered() { $hooks = array( - 'API.getReportMetadata.end.end' => 'getReportMetadata', + 'API.getReportMetadata.end' => array('function' => 'getReportMetadata', + 'after' => true), ); return $hooks; } @@ -45,13 +46,10 @@ class Piwik_ImageGraph extends Piwik_Plugin const GRAPH_EVOLUTION_LAST_PERIODS = 30; /** - * @param Piwik_Event_Notification $notification notification object * @return mixed */ - public function getReportMetadata($notification) + public function getReportMetadata(&$reports, $info) { - $info = $notification->getNotificationInfo(); - $reports = & $notification->getNotificationObject(); $idSites = $info['idSites']; // If only one website is selected, we add the Graph URL diff --git a/plugins/Installation/Controller.php b/plugins/Installation/Controller.php index 57cbae5dcece84f39132c0a14afc439622addfea..ba556775bcd7468f0cb9260a6a7ccfa70f8f8fd6 100644 --- a/plugins/Installation/Controller.php +++ b/plugins/Installation/Controller.php @@ -39,7 +39,7 @@ class Piwik_Installation_Controller extends Piwik_Controller_Admin $this->session->skipThisStep = array(); } - Piwik_PostEvent('InstallationController.construct', $this); + Piwik_PostEvent('InstallationController.construct', array($this)); } /** diff --git a/plugins/Installation/Installation.php b/plugins/Installation/Installation.php index b6301f5926f069221ef2d1559ef982efc9fabcc3..660be7c8eda70411edd2ef6edd5ff0df23428165 100644 --- a/plugins/Installation/Installation.php +++ b/plugins/Installation/Installation.php @@ -50,13 +50,9 @@ class Piwik_Installation extends Piwik_Plugin return new $this->installationControllerName(); } - /** - * @param Piwik_Event_Notification|null $notification notification object - */ - function dispatch($notification = null) + public function dispatch($exception = null) { - if ($notification) { - $exception = $notification->getNotificationObject(); + if ($exception) { $message = $exception->getMessage(); } else { $message = ''; @@ -64,7 +60,7 @@ class Piwik_Installation extends Piwik_Plugin Piwik_Translate::getInstance()->loadCoreTranslation(); - Piwik_PostEvent('Installation.startInstallation', $this); + Piwik_PostEvent('Installation.startInstallation', array($this)); $step = Piwik_Common::getRequestVar('action', 'welcome', 'string'); $controller = $this->getInstallationController(); @@ -91,10 +87,8 @@ class Piwik_Installation extends Piwik_Plugin /** * Adds CSS files to list of CSS files for asset manager. */ - public function getCss($notification) + public function getCss(&$cssFiles) { - $cssFiles = & $notification->getNotificationObject(); - $cssFiles[] = "plugins/Installation/stylesheets/systemCheckPage.css"; } } diff --git a/plugins/LanguagesManager/LanguagesManager.php b/plugins/LanguagesManager/LanguagesManager.php index a0cf7d0039107aa1623a73733e4c2e62965ddb86..3d18f9eb49d2ac50ba505822e13cee57f38f4c46 100644 --- a/plugins/LanguagesManager/LanguagesManager.php +++ b/plugins/LanguagesManager/LanguagesManager.php @@ -38,30 +38,17 @@ class Piwik_LanguagesManager extends Piwik_Plugin ); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getCssFiles($notification) + public function getCssFiles(&$cssFiles) { - $cssFiles = & $notification->getNotificationObject(); - $cssFiles[] = "plugins/Zeitgeist/stylesheets/styles.css"; } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getJsFiles($notification) + public function getJsFiles(&$jsFiles) { - $jsFiles = & $notification->getNotificationObject(); - $jsFiles[] = "plugins/LanguagesManager/javascripts/languageSelector.js"; } - /** - * Show styled language selection drop-down list - */ - function showLanguagesSelector() + public function showLanguagesSelector() { Piwik_AddTopMenu('LanguageSelector', $this->getLanguagesSelector(), true, $order = 30, true); } @@ -70,12 +57,9 @@ class Piwik_LanguagesManager extends Piwik_Plugin * Adds the languages drop-down list to topbars other than the main one rendered * in CoreHome/templates/top_bar.twig. The 'other' topbars are on the Installation * and CoreUpdater screens. - * - * @param Piwik_Event_Notification $notification notification object */ - public function addLanguagesManagerToOtherTopBar($notification) + public function addLanguagesManagerToOtherTopBar(&$str) { - $str =& $notification->getNotificationObject(); // piwik object & scripts aren't loaded in 'other' topbars $str .= "<script type='text/javascript'>if (!window.piwik) window.piwik={};</script>"; $str .= "<script type='text/javascript' src='plugins/LanguagesManager/javascripts/languageSelector.js'></script>"; @@ -96,12 +80,8 @@ class Piwik_LanguagesManager extends Piwik_Plugin return $view->render(); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getLanguageToLoad($notification) + function getLanguageToLoad(&$language) { - $language =& $notification->getNotificationObject(); if (empty($language)) { $language = self::getLanguageCodeForCurrentUser(); } @@ -110,12 +90,8 @@ class Piwik_LanguagesManager extends Piwik_Plugin } } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function deleteUserLanguage($notification) + public function deleteUserLanguage($userLogin) { - $userLogin = $notification->getNotificationObject(); Piwik_Query('DELETE FROM ' . Piwik_Common::prefixTable('user_language') . ' WHERE login = ?', $userLogin); } diff --git a/plugins/Live/Live.php b/plugins/Live/Live.php index 2b8ff54b42c485388532b95c1b97b21bfaddd8fc..95a86d96e29244dbe75840fdfa340acdff81f897 100644 --- a/plugins/Live/Live.php +++ b/plugins/Live/Live.php @@ -35,23 +35,13 @@ class Piwik_Live extends Piwik_Plugin ); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getCssFiles($notification) + public function getCssFiles(&$cssFiles) { - $cssFiles = & $notification->getNotificationObject(); - $cssFiles[] = "plugins/Live/stylesheets/live.css"; } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getJsFiles($notification) + public function getJsFiles(&$jsFiles) { - $jsFiles = & $notification->getNotificationObject(); - $jsFiles[] = "plugins/Live/javascripts/live.js"; } diff --git a/plugins/Login/Controller.php b/plugins/Login/Controller.php index ba3e3cf35585281a8accc224a5a1935e16148567..7b602d39e44088fa557cf3c7e9b924731d286b69 100644 --- a/plugins/Login/Controller.php +++ b/plugins/Login/Controller.php @@ -149,7 +149,7 @@ class Piwik_Login_Controller extends Piwik_Controller 'rememberMe' => $rememberMe, ); Piwik_Nonce::discardNonce('Piwik_Login.login'); - Piwik_PostEvent('Login.initSession', $info); + Piwik_PostEvent('Login.initSession', array(&$info)); Piwik_Url::redirectToUrl($urlToRedirect); } diff --git a/plugins/Login/Login.php b/plugins/Login/Login.php index 5b92eaca870574e32066b4140d002f7cec72ed4f..575a05c6a46eb61d9942b97ba7438cb7890fa923 100644 --- a/plugins/Login/Login.php +++ b/plugins/Login/Login.php @@ -26,7 +26,7 @@ class Piwik_Login extends Piwik_Plugin return $info; } - function getListHooksRegistered() + public function getListHooksRegistered() { $hooks = array( 'FrontController.initAuthenticationObject' => 'initAuthenticationObject', @@ -40,13 +40,9 @@ class Piwik_Login extends Piwik_Plugin /** * Redirects to Login form with error message. * Listens to FrontController.NoAccessException hook. - * - * @param Piwik_Event_Notification $notification notification object */ - function noAccess($notification) + public function noAccess(Exception $exception) { - /* @var Exception $exception */ - $exception = $notification->getNotificationObject(); $exceptionMessage = $exception->getMessage(); $controller = new Piwik_Login_Controller(); @@ -56,12 +52,9 @@ class Piwik_Login extends Piwik_Plugin /** * Set login name and autehntication token for authentication request. * Listens to API.Request.authenticate hook. - * - * @param Piwik_Event_Notification $notification notification object */ - function ApiRequestAuthenticate($notification) + public function ApiRequestAuthenticate($tokenAuth) { - $tokenAuth = $notification->getNotificationObject(); Zend_Registry::get('auth')->setLogin($login = null); Zend_Registry::get('auth')->setTokenAuth($tokenAuth); } @@ -69,16 +62,12 @@ class Piwik_Login extends Piwik_Plugin /** * Initializes the authentication object. * Listens to FrontController.initAuthenticationObject hook. - * - * @param Piwik_Event_Notification $notification notification object */ - function initAuthenticationObject($notification) + function initAuthenticationObject($allowCookieAuthentication = false) { $auth = new Piwik_Login_Auth(); Zend_Registry::set('auth', $auth); - $allowCookieAuthentication = $notification->getNotificationInfo(); - $action = Piwik::getAction(); if (Piwik::getModule() === 'API' && (empty($action) || $action == 'index') @@ -104,13 +93,11 @@ class Piwik_Login extends Piwik_Plugin /** * Authenticate user and initializes the session. * Listens to Login.initSession hook. - * - * @param Piwik_Event_Notification $notification notification object + * * @throws Exception */ - function initSession($notification) + public function initSession($info) { - $info = $notification->getNotificationObject(); $login = $info['login']; $md5Password = $info['md5Password']; $rememberMe = $info['rememberMe']; diff --git a/plugins/MobileMessaging/MobileMessaging.php b/plugins/MobileMessaging/MobileMessaging.php index 76f994517f56b367e7088e224596b50b603abc9c..6cc34fe5c4f417aef45de1bac8b560d1bdf6b446 100644 --- a/plugins/MobileMessaging/MobileMessaging.php +++ b/plugins/MobileMessaging/MobileMessaging.php @@ -103,34 +103,20 @@ class Piwik_MobileMessaging extends Piwik_Plugin /** * Get JavaScript files - * - * @param Piwik_Event_Notification $notification notification object */ - function getJsFiles($notification) + public function getJsFiles(&$jsFiles) { - $jsFiles = & $notification->getNotificationObject(); - $jsFiles[] = "plugins/MobileMessaging/javascripts/MobileMessagingSettings.js"; } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getCssFiles($notification) + public function getCssFiles($cssFiles) { - $cssFiles = & $notification->getNotificationObject(); - $cssFiles[] = "plugins/MobileMessaging/stylesheets/MobileMessagingSettings.css"; } - - /** - * @param Piwik_Event_Notification $notification notification object - */ - function validateReportParameters($notification) + + public function validateReportParameters(&$parameters, $info) { - if (self::manageEvent($notification)) { - $parameters = & $notification->getNotificationObject(); - + if (self::manageEvent($info)) { // phone number validation $availablePhoneNumbers = Piwik_MobileMessaging_API::getInstance()->getActivatedPhoneNumbers(); @@ -147,15 +133,9 @@ class Piwik_MobileMessaging extends Piwik_Plugin } } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getReportMetadata($notification) + public function getReportMetadata(&$availableReportMetadata, $notificationInfo) { - if (self::manageEvent($notification)) { - $availableReportMetadata = & $notification->getNotificationObject(); - - $notificationInfo = $notification->getNotificationInfo(); + if (self::manageEvent($notificationInfo)) { $idSite = $notificationInfo[Piwik_PDFReports_API::ID_SITE_INFO_KEY]; foreach (self::$availableReports as $availableReport) { @@ -173,45 +153,28 @@ class Piwik_MobileMessaging extends Piwik_Plugin } } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getReportTypes($notification) + public function getReportTypes(&$reportTypes) { - $reportTypes = & $notification->getNotificationObject(); $reportTypes = array_merge($reportTypes, self::$managedReportTypes); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getReportFormats($notification) + public function getReportFormats(&$reportFormats, $info) { - if (self::manageEvent($notification)) { - $reportFormats = & $notification->getNotificationObject(); + if (self::manageEvent($info)) { $reportFormats = array_merge($reportFormats, self::$managedReportFormats); } } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getReportParameters($notification) + public function getReportParameters(&$availableParameters, $info) { - if (self::manageEvent($notification)) { - $availableParameters = & $notification->getNotificationObject(); + if (self::manageEvent($info)) { $availableParameters = self::$availableParameters; } } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getRendererInstance($notification) + public function getRendererInstance(&$reportRenderer, $info) { - if (self::manageEvent($notification)) { - $reportRenderer = & $notification->getNotificationObject(); - + if (self::manageEvent($info)) { if (Piwik_PluginsManager::getInstance()->isPluginActivated('MultiSites')) { $reportRenderer = new Piwik_MobileMessaging_ReportRenderer_Sms(); } else { @@ -222,35 +185,24 @@ class Piwik_MobileMessaging extends Piwik_Plugin } } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function allowMultipleReports($notification) + public function allowMultipleReports(&$allowMultipleReports, $info) { - if (self::manageEvent($notification)) { - $allowMultipleReports = & $notification->getNotificationObject(); + if (self::manageEvent($info)) { $allowMultipleReports = false; } } - function getReportRecipients($notification) + public function getReportRecipients(&$recipients, $notificationInfo) { - if (self::manageEvent($notification)) { - $recipients = & $notification->getNotificationObject(); - $notificationInfo = $notification->getNotificationInfo(); - + if (self::manageEvent($notificationInfo)) { $report = $notificationInfo[Piwik_PDFReports_API::REPORT_KEY]; $recipients = $report['parameters'][self::PHONE_NUMBERS_PARAMETER]; } } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function sendReport($notification) + public function sendReport($notificationInfo) { - if (self::manageEvent($notification)) { - $notificationInfo = $notification->getNotificationInfo(); + if (self::manageEvent($notificationInfo)) { $report = $notificationInfo[Piwik_PDFReports_API::REPORT_KEY]; $contents = $notificationInfo[Piwik_PDFReports_API::REPORT_CONTENT_KEY]; $reportSubject = $notificationInfo[Piwik_PDFReports_API::REPORT_SUBJECT_KEY]; @@ -274,25 +226,20 @@ class Piwik_MobileMessaging extends Piwik_Plugin } } - /** - * @param Piwik_Event_Notification $notification notification object - */ - static public function template_reportParametersPDFReports($notification) + static public function template_reportParametersPDFReports(&$out) { if (Piwik::isUserIsAnonymous()) { return; } - $out =& $notification->getNotificationObject(); $view = new Piwik_View('@MobileMessaging/reportParametersPDFReports'); $view->reportType = self::MOBILE_TYPE; $view->phoneNumbers = Piwik_MobileMessaging_API::getInstance()->getActivatedPhoneNumbers(); $out .= $view->render(); } - private static function manageEvent($notification) + private static function manageEvent($notificationInfo) { - $notificationInfo = $notification->getNotificationInfo(); return in_array($notificationInfo[Piwik_PDFReports_API::REPORT_TYPE_INFO_KEY], array_keys(self::$managedReportTypes)); } diff --git a/plugins/MultiSites/MultiSites.php b/plugins/MultiSites/MultiSites.php index aa23d48040eaf4b709e269d87933eea3fb7b108e..6d3f65af7733da0642053be5f26ffeb877e4f7ff 100644 --- a/plugins/MultiSites/MultiSites.php +++ b/plugins/MultiSites/MultiSites.php @@ -35,10 +35,7 @@ class Piwik_MultiSites extends Piwik_Plugin ); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - public function getReportMetadata($notification) + public function getReportMetadata(&$reports) { $metadataMetrics = array(); foreach (Piwik_MultiSites_API::getApiMetrics($enhanced = true) as $metricName => $metricSettings) { @@ -48,8 +45,6 @@ class Piwik_MultiSites extends Piwik_Plugin Piwik_Translate($metricSettings[Piwik_MultiSites_API::METRIC_TRANSLATION_KEY]) . " " . Piwik_Translate('MultiSites_Evolution'); } - $reports = & $notification->getNotificationObject(); - $reports[] = array( 'category' => Piwik_Translate('General_MultiSitesSummary'), 'name' => Piwik_Translate('General_AllWebsitesDashboard'), @@ -82,23 +77,13 @@ class Piwik_MultiSites extends Piwik_Plugin Piwik_AddTopMenu('General_MultiSitesSummary', $urlParams, true, 3, $isHTML = false, $tooltip); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getJsFiles($notification) + public function getJsFiles(&$jsFiles) { - $jsFiles = & $notification->getNotificationObject(); - $jsFiles[] = "plugins/MultiSites/javascripts/multiSites.js"; } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getCssFiles($notification) + public function getCssFiles(&$cssFiles) { - $cssFiles = & $notification->getNotificationObject(); - $cssFiles[] = "plugins/MultiSites/stylesheets/multiSites.css"; } } diff --git a/plugins/Overlay/API.php b/plugins/Overlay/API.php index 413406fe43998af94c701450b418804a4be3ff40..9c06d11177315b7580baa1626ed7b72856a11620 100644 --- a/plugins/Overlay/API.php +++ b/plugins/Overlay/API.php @@ -106,7 +106,8 @@ class Piwik_Overlay_API private function authenticate($idSite) { $notification = null; - Piwik_PostEvent('FrontController.initAuthenticationObject', $notification, $allowCookieAuthentication = true); + Piwik_PostEvent('FrontController.initAuthenticationObject', + array(&$notification, $allowCookieAuthentication = true)); $auth = Zend_Registry::get('auth'); $success = Zend_Registry::get('access')->reloadAccess($auth); diff --git a/plugins/Overlay/Overlay.php b/plugins/Overlay/Overlay.php index abf8faaf96c7e9b88202c44c3ba2a2d790e27155..e317b748e6b8c1c1bb5bec1d3eb200ca8cbb499b 100644 --- a/plugins/Overlay/Overlay.php +++ b/plugins/Overlay/Overlay.php @@ -28,11 +28,9 @@ class Piwik_Overlay extends Piwik_Plugin ); } - public function getJsFiles($notification) + public function getJsFiles(&$jsFiles) { - $jsFiles = & $notification->getNotificationObject(); $jsFiles[] = 'plugins/Overlay/javascripts/rowaction.js'; $jsFiles[] = 'plugins/Overlay/javascripts/Overlay_Helper.js'; } - } diff --git a/plugins/PDFReports/API.php b/plugins/PDFReports/API.php index d3b0fccb9563393c460474bf1efa0d6c28770275..4858f62ebeeabe34d4e54d4842c18c4447042a2a 100644 --- a/plugins/PDFReports/API.php +++ b/plugins/PDFReports/API.php @@ -400,16 +400,14 @@ class Piwik_PDFReports_API // allow plugins to alter processed reports Piwik_PostEvent( self::PROCESS_REPORTS_EVENT, - $processedReports, - $notificationInfo + array(&$processedReports, $notificationInfo) ); // retrieve report renderer instance $reportRenderer = null; Piwik_PostEvent( self::GET_RENDERER_INSTANCE_EVENT, - $reportRenderer, - $notificationInfo + array(&$reportRenderer, $notificationInfo) ); // init report renderer @@ -518,19 +516,19 @@ class Piwik_PDFReports_API $contents = fread($handle, filesize($outputFilename)); fclose($handle); - $notificationObject = null; Piwik_PostEvent( self::SEND_REPORT_EVENT, - $notificationObject, - $notificationInfo = array( - self::REPORT_TYPE_INFO_KEY => $report['type'], - self::REPORT_KEY => $report, - self::REPORT_CONTENT_KEY => $contents, - self::FILENAME_KEY => $filename, - self::PRETTY_DATE_KEY => $prettyDate, - self::REPORT_SUBJECT_KEY => $reportSubject, - self::REPORT_TITLE_KEY => $reportTitle, - self::ADDITIONAL_FILES_KEY => $additionalFiles, + array( + $notificationInfo = array( + self::REPORT_TYPE_INFO_KEY => $report['type'], + self::REPORT_KEY => $report, + self::REPORT_CONTENT_KEY => $contents, + self::FILENAME_KEY => $filename, + self::PRETTY_DATE_KEY => $prettyDate, + self::REPORT_SUBJECT_KEY => $reportSubject, + self::REPORT_TITLE_KEY => $reportTitle, + self::ADDITIONAL_FILES_KEY => $additionalFiles, + ) ) ); @@ -570,7 +568,7 @@ class Piwik_PDFReports_API self::REPORT_TYPE_INFO_KEY => $reportType ); - Piwik_PostEvent(self::GET_REPORT_PARAMETERS_EVENT, $availableParameters, $notificationInfo); + Piwik_PostEvent(self::GET_REPORT_PARAMETERS_EVENT, array(&$availableParameters, $notificationInfo)); // unset invalid parameters $availableParameterKeys = array_keys($availableParameters); @@ -588,7 +586,7 @@ class Piwik_PDFReports_API } // delegate report parameter validation - Piwik_PostEvent(self::VALIDATE_PARAMETERS_EVENT, $parameters, $notificationInfo); + Piwik_PostEvent(self::VALIDATE_PARAMETERS_EVENT, array(&$parameters, $notificationInfo)); return Piwik_Common::json_encode($parameters); } @@ -702,8 +700,7 @@ class Piwik_PDFReports_API $availableReportMetadata = array(); Piwik_PostEvent( self::GET_REPORT_METADATA_EVENT, - $availableReportMetadata, - $notificationInfo + array(&$availableReportMetadata, $notificationInfo) ); return $availableReportMetadata; @@ -717,9 +714,11 @@ class Piwik_PDFReports_API $allowMultipleReports = null; Piwik_PostEvent( self::ALLOW_MULTIPLE_REPORTS_EVENT, - $allowMultipleReports, - $notificationInfo = array( - self::REPORT_TYPE_INFO_KEY => $reportType, + array( + &$allowMultipleReports, + $notificationInfo = array( + self::REPORT_TYPE_INFO_KEY => $reportType, + ) ) ); return $allowMultipleReports; @@ -731,7 +730,7 @@ class Piwik_PDFReports_API static public function getReportTypes() { $reportTypes = array(); - Piwik_PostEvent(self::GET_REPORT_TYPES_EVENT, $reportTypes); + Piwik_PostEvent(self::GET_REPORT_TYPES_EVENT, array(&$reportTypes)); return $reportTypes; } @@ -745,9 +744,11 @@ class Piwik_PDFReports_API Piwik_PostEvent( self::GET_REPORT_FORMATS_EVENT, - $reportFormats, - $notificationInfo = array( - self::REPORT_TYPE_INFO_KEY => $reportType + array( + &$reportFormats, + $notificationInfo = array( + self::REPORT_TYPE_INFO_KEY => $reportType + ) ) ); @@ -766,7 +767,7 @@ class Piwik_PDFReports_API // retrieve report renderer instance $recipients = array(); - Piwik_PostEvent(self::GET_REPORT_RECIPIENTS_EVENT, $recipients, $notificationInfo); + Piwik_PostEvent(self::GET_REPORT_RECIPIENTS_EVENT, array(&$recipients, $notificationInfo)); return $recipients; } diff --git a/plugins/PDFReports/PDFReports.php b/plugins/PDFReports/PDFReports.php index 60f3055ffb71632a4cc82a39f67f0a29ad99c6e2..6df17b85f16e864bdefe8a2e7cf0115074fe6ba2 100644 --- a/plugins/PDFReports/PDFReports.php +++ b/plugins/PDFReports/PDFReports.php @@ -89,13 +89,9 @@ class Piwik_PDFReports extends Piwik_Plugin /** * Delete reports for the website - * - * @param Piwik_Event_Notification $notification notification object */ - function deleteSiteReport($notification) + public function deleteSiteReport(&$idSite) { - $idSite = & $notification->getNotificationObject(); - $idReports = Piwik_PDFReports_API::getInstance()->getReports($idSite); foreach ($idReports as $report) { @@ -104,23 +100,14 @@ class Piwik_PDFReports extends Piwik_Plugin } } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getJsFiles($notification) + public function getJsFiles(&$jsFiles) { - $jsFiles = & $notification->getNotificationObject(); $jsFiles[] = "plugins/PDFReports/javascripts/pdf.js"; } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function validateReportParameters($notification) + public function validateReportParameters(&$parameters, $info) { - if (self::manageEvent($notification)) { - $parameters = & $notification->getNotificationObject(); - + if (self::manageEvent($info)) { $reportFormat = $parameters[self::DISPLAY_FORMAT_PARAMETER]; $availableDisplayFormats = array_keys(self::getDisplayFormats()); if (!in_array($reportFormat, $availableDisplayFormats)) { @@ -160,15 +147,9 @@ class Piwik_PDFReports extends Piwik_Plugin return $value == 'true' || $value == 1 || $value == '1' || $value === true; } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getReportMetadata($notification) + public function getReportMetadata(&$reportMetadata, $notificationInfo) { - if (self::manageEvent($notification)) { - $reportMetadata = & $notification->getNotificationObject(); - - $notificationInfo = $notification->getNotificationInfo(); + if (self::manageEvent($notificationInfo)) { $idSite = $notificationInfo[Piwik_PDFReports_API::ID_SITE_INFO_KEY]; $availableReportMetadata = Piwik_API_API::getInstance()->getReportMetadata($idSite); @@ -188,46 +169,28 @@ class Piwik_PDFReports extends Piwik_Plugin } } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getReportTypes($notification) + public function getReportTypes(&$reportTypes) { - $reportTypes = & $notification->getNotificationObject(); $reportTypes = array_merge($reportTypes, self::$managedReportTypes); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getReportFormats($notification) + public function getReportFormats(&$reportFormats, $info) { - if (self::manageEvent($notification)) { - $reportFormats = & $notification->getNotificationObject(); + if (self::manageEvent($info)) { $reportFormats = self::$managedReportFormats; } } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getReportParameters($notification) + public function getReportParameters(&$availableParameters, $info) { - if (self::manageEvent($notification)) { - $availableParameters = & $notification->getNotificationObject(); + if (self::manageEvent($info)) { $availableParameters = self::$availableParameters; } } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function processReports($notification) + public function processReports(&$processedReports, $notificationInfo) { - if (self::manageEvent($notification)) { - $processedReports = & $notification->getNotificationObject(); - - $notificationInfo = $notification->getNotificationInfo(); + if (self::manageEvent($notificationInfo)) { $report = $notificationInfo[Piwik_PDFReports_API::REPORT_KEY]; $displayFormat = $report['parameters'][self::DISPLAY_FORMAT_PARAMETER]; @@ -266,15 +229,9 @@ class Piwik_PDFReports extends Piwik_Plugin } } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getRendererInstance($notification) + public function getRendererInstance(&$reportRenderer, $notificationInfo) { - if (self::manageEvent($notification)) { - $reportRenderer = & $notification->getNotificationObject(); - $notificationInfo = $notification->getNotificationInfo(); - + if (self::manageEvent($notificationInfo)) { $reportFormat = $notificationInfo[Piwik_PDFReports_API::REPORT_KEY]['format']; $outputType = $notificationInfo[Piwik_PDFReports_API::OUTPUT_TYPE_INFO_KEY]; @@ -286,24 +243,16 @@ class Piwik_PDFReports extends Piwik_Plugin } } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function allowMultipleReports($notification) + public function allowMultipleReports(&$allowMultipleReports, $info) { - if (self::manageEvent($notification)) { - $allowMultipleReports = & $notification->getNotificationObject(); + if (self::manageEvent($info)) { $allowMultipleReports = true; } } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function sendReport($notification) + public function sendReport($notificationInfo) { - if (self::manageEvent($notification)) { - $notificationInfo = $notification->getNotificationInfo(); + if (self::manageEvent($notificationInfo)) { $report = $notificationInfo[Piwik_PDFReports_API::REPORT_KEY]; $reportTitle = $notificationInfo[Piwik_PDFReports_API::REPORT_TITLE_KEY]; $prettyDate = $notificationInfo[Piwik_PDFReports_API::PRETTY_DATE_KEY]; @@ -424,15 +373,9 @@ class Piwik_PDFReports extends Piwik_Plugin } } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getReportRecipients($notification) + public function getReportRecipients(&$recipients, $notificationInfo) { - if (self::manageEvent($notification)) { - $recipients = & $notification->getNotificationObject(); - $notificationInfo = $notification->getNotificationInfo(); - + if (self::manageEvent($notificationInfo)) { $report = $notificationInfo[Piwik_PDFReports_API::REPORT_KEY]; $parameters = $report['parameters']; $eMailMe = $parameters[self::EMAIL_ME_PARAMETER]; @@ -449,13 +392,8 @@ class Piwik_PDFReports extends Piwik_Plugin } } - /** - * @param Piwik_Event_Notification $notification notification object - */ - static public function template_reportParametersPDFReports($notification) + static public function template_reportParametersPDFReports(&$out) { - $out =& $notification->getNotificationObject(); - $view = new Piwik_View('@PDFReports/reportParametersPDFReports'); $view->currentUserEmail = Piwik::getCurrentUserEmail(); $view->displayFormats = self::getDisplayFormats(); @@ -466,22 +404,17 @@ class Piwik_PDFReports extends Piwik_Plugin $out .= $view->render(); } - private static function manageEvent($notification) + private static function manageEvent($info) { - $notificationInfo = $notification->getNotificationInfo(); return in_array( - $notificationInfo[Piwik_PDFReports_API::REPORT_TYPE_INFO_KEY], + $info[Piwik_PDFReports_API::REPORT_TYPE_INFO_KEY], array_keys(self::$managedReportTypes) ); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getScheduledTasks($notification) + public function getScheduledTasks(&$tasks) { $arbitraryDateInUTC = Piwik_Date::factory('2011-01-01'); - $tasks = & $notification->getNotificationObject(); foreach (Piwik_PDFReports_API::getInstance()->getReports() as $report) { if (!$report['deleted'] && $report['period'] != Piwik_ScheduledTime::PERIOD_NEVER) { $midnightInSiteTimezone = @@ -506,12 +439,8 @@ class Piwik_PDFReports extends Piwik_Plugin } } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function segmentDeletion($notification) + public function segmentDeletion(&$idSegment) { - $idSegment = & $notification->getNotificationObject(); $reportsUsingSegment = Piwik_PDFReports_API::getInstance()->getReports(false, false, false, true, $idSegment); if (count($reportsUsingSegment) > 0) { @@ -579,16 +508,12 @@ class Piwik_PDFReports extends Piwik_Plugin return self::PDF_REPORTS_TOP_MENU_TRANSLATION_KEY; } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function deleteUserReport($notification) + public function deleteUserReport($userLogin) { - $userLogin = $notification->getNotificationObject(); Piwik_Query('DELETE FROM ' . Piwik_Common::prefixTable('report') . ' WHERE login = ?', $userLogin); } - function install() + public function install() { $queries[] = ' CREATE TABLE `' . Piwik_Common::prefixTable('report') . '` ( diff --git a/plugins/PrivacyManager/PrivacyManager.php b/plugins/PrivacyManager/PrivacyManager.php index dc0b436c61aeccd6fe30b152886330c22f2991ed..afb59c3cc5d9782b874a4a982274d8dc41cfbb0e 100644 --- a/plugins/PrivacyManager/PrivacyManager.php +++ b/plugins/PrivacyManager/PrivacyManager.php @@ -66,13 +66,8 @@ class Piwik_PrivacyManager extends Piwik_Plugin ); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getScheduledTasks($notification) + public function getScheduledTasks(&$tasks) { - $tasks = & $notification->getNotificationObject(); - // both tasks are low priority so they will execute after most others, but not lowest, so // they will execute before the optimize tables task @@ -87,13 +82,8 @@ class Piwik_PrivacyManager extends Piwik_Plugin $tasks[] = $purgeLogDataTask; } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getJsFiles($notification) + public function getJsFiles(&$jsFiles) { - $jsFiles = & $notification->getNotificationObject(); - $jsFiles[] = "plugins/PrivacyManager/javascripts/privacySettings.js"; } diff --git a/plugins/Provider/Provider.php b/plugins/Provider/Provider.php index f6d1ff1b68b11389049cba208d5859c26f3555ba..14563a6dc694a874104f491711db5da25f6d701e 100644 --- a/plugins/Provider/Provider.php +++ b/plugins/Provider/Provider.php @@ -42,12 +42,8 @@ class Piwik_Provider extends Piwik_Plugin return $hooks; } - /** - * @param Piwik_Event_Notification $notification notification object - */ - public function getReportMetadata($notification) + public function getReportMetadata(&$reports) { - $reports = & $notification->getNotificationObject(); $reports[] = array( 'category' => Piwik_Translate('General_Visitors'), 'name' => Piwik_Translate('Provider_ColumnProvider'), @@ -59,12 +55,8 @@ class Piwik_Provider extends Piwik_Plugin ); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - public function getSegmentsMetadata($notification) + public function getSegmentsMetadata(&$segments) { - $segments =& $notification->getNotificationObject(); $segments[] = array( 'type' => 'dimension', 'category' => 'Visit Location', @@ -116,13 +108,9 @@ class Piwik_Provider extends Piwik_Plugin /** * Logs the provider in the log_visit table - * - * @param Piwik_Event_Notification $notification notification object */ - public function logProviderInfo($notification) + public function logProviderInfo(&$visitorInfo) { - $visitorInfo =& $notification->getNotificationObject(); - // if provider info has already been set, abort if (!empty($visitorInfo['location_provider'])) { return; @@ -174,7 +162,7 @@ class Piwik_Provider extends Piwik_Plugin return 'Ip'; } else { $cleanHostname = null; - Piwik_PostEvent('Provider.getCleanHostname', $cleanHostname, $hostname); + Piwik_PostEvent('Provider.getCleanHostname', array(&$cleanHostname, $hostname)); if ($cleanHostname !== null) { return $cleanHostname; } @@ -202,12 +190,8 @@ class Piwik_Provider extends Piwik_Plugin return trim(strtolower(@Piwik_IP::getHostByAddr($ip))); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - static public function footerUserCountry($notification) + static public function footerUserCountry(&$out) { - $out =& $notification->getNotificationObject(); $out = '<div> <h2>' . Piwik_Translate('Provider_WidgetProviders') . '</h2>'; $out .= Piwik_FrontController::getInstance()->fetchDispatch('Provider', 'getProvider'); @@ -216,32 +200,20 @@ class Piwik_Provider extends Piwik_Plugin /** * Daily archive: processes the report Visits by Provider - * - * @param Piwik_Event_Notification $notification notification object */ - function archiveDay($notification) + public function archiveDay(Piwik_ArchiveProcessor_Day $archiveProcessor) { - $archiveProcessor = $notification->getNotificationObject(); - $archiving = new Piwik_Provider_Archiver($archiveProcessor); if($archiving->shouldArchive()) { $archiving->archiveDay(); } } - /** - * @param Piwik_Event_Notification $notification notification object - * @return mixed - */ - function archivePeriod($notification) + public function archivePeriod(Piwik_ArchiveProcessor_Period $archiveProcessor) { - $archiveProcessor = $notification->getNotificationObject(); - $archiving = new Piwik_Provider_Archiver($archiveProcessor); if($archiving->shouldArchive()) { $archiving->archivePeriod(); } } - - } diff --git a/plugins/Referers/Referers.php b/plugins/Referers/Referers.php index 2c45b57592ed11d5559540a1a1fd3c40e8685312..80ad71d6e866cd0c65581fcc325513afa2597a2a 100644 --- a/plugins/Referers/Referers.php +++ b/plugins/Referers/Referers.php @@ -43,12 +43,8 @@ class Piwik_Referers extends Piwik_Plugin return $hooks; } - /** - * @param Piwik_Event_Notification $notification notification object - */ - public function getReportMetadata($notification) + public function getReportMetadata(&$reports) { - $reports = & $notification->getNotificationObject(); $reports = array_merge($reports, array( array( 'category' => Piwik_Translate('Referers_Referers'), @@ -174,12 +170,8 @@ class Piwik_Referers extends Piwik_Plugin )); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - public function getSegmentsMetadata($notification) + public function getSegmentsMetadata(&$segments) { - $segments =& $notification->getNotificationObject(); $segments[] = array( 'type' => 'dimension', 'category' => 'Referers_Referers', @@ -246,13 +238,9 @@ class Piwik_Referers extends Piwik_Plugin /** * Adds Goal dimensions, so that the dimensions are displayed in the UI Goal Overview page - * - * @param Piwik_Event_Notification $notification notification object - * @return void */ - function getReportsWithGoalMetrics($notification) + public function getReportsWithGoalMetrics(&$dimensions) { - $dimensions =& $notification->getNotificationObject(); $dimensions = array_merge($dimensions, array( array('category' => Piwik_Translate('Referers_Referers'), 'name' => Piwik_Translate('Referers_Keywords'), @@ -284,13 +272,9 @@ class Piwik_Referers extends Piwik_Plugin /** * Hooks on daily archive to trigger various log processing - * - * @param Piwik_Event_Notification $notification notification object */ - public function archiveDay($notification) + public function archiveDay(Piwik_ArchiveProcessor_Day $archiveProcessor) { - $archiveProcessor = $notification->getNotificationObject(); - $archiving = new Piwik_Referers_Archiver($archiveProcessor); if ($archiving->shouldArchive()) { $archiving->archiveDay(); @@ -300,12 +284,9 @@ class Piwik_Referers extends Piwik_Plugin /** * Period archiving: sums up daily stats and sums report tables, * making sure that tables are still truncated. - * - * @param Piwik_Event_Notification $notification notification object */ - function archivePeriod($notification) + public function archivePeriod(Piwik_ArchiveProcessor_Period $archiveProcessor) { - $archiveProcessor = $notification->getNotificationObject(); $archiving = new Piwik_Referers_Archiver($archiveProcessor); if($archiving->shouldArchive()) { $archiving->archivePeriod(); diff --git a/plugins/SegmentEditor/API.php b/plugins/SegmentEditor/API.php index ad420009ea33cc5d410cc44cc46942ee01bee143..5d0aef113d4ba0f64bf75c8530f5c07c3d499212 100644 --- a/plugins/SegmentEditor/API.php +++ b/plugins/SegmentEditor/API.php @@ -127,7 +127,7 @@ class Piwik_SegmentEditor_API $this->checkUserIsNotAnonymous(); // allow plugins using the segment to throw an exception or propagate the deletion - Piwik_PostEvent(self::DELETE_SEGMENT_EVENT, $idSegment); + Piwik_PostEvent(self::DELETE_SEGMENT_EVENT, array(&$idSegment)); $segment = $this->getSegmentOrFail($idSegment); $db = Zend_Registry::get('db'); diff --git a/plugins/SegmentEditor/SegmentEditor.php b/plugins/SegmentEditor/SegmentEditor.php index d95f9b8a8cdcbe1b88d3a727165145c8f2305adb..ce1825a5240a6b1d8699a886c1b777dceea4ec4a 100644 --- a/plugins/SegmentEditor/SegmentEditor.php +++ b/plugins/SegmentEditor/SegmentEditor.php @@ -35,26 +35,22 @@ class Piwik_SegmentEditor extends Piwik_Plugin ); } - function getSegmentEditorHtml($notification) + function getSegmentEditorHtml(&$out) { - $out =& $notification->getNotificationObject(); $controller = new Piwik_SegmentEditor_Controller(); $out .= $controller->getSelector(); } - public function getKnownSegmentsToArchiveAllSites($notification) + public function getKnownSegmentsToArchiveAllSites(&$segments) { - $segments =& $notification->getNotificationObject(); $segmentsToAutoArchive = Piwik_SegmentEditor_API::getInstance()->getAll($idSite = false, $returnAutoArchived = true); foreach ($segmentsToAutoArchive as $segment) { $segments[] = $segment['definition']; } } - public function getKnownSegmentsToArchiveForSite($notification) + public function getKnownSegmentsToArchiveForSite(&$segments, $idSite) { - $segments =& $notification->getNotificationObject(); - $idSite = $notification->getNotificationInfo(); $segmentToAutoArchive = Piwik_SegmentEditor_API::getInstance()->getAll($idSite, $returnAutoArchived = true); foreach ($segmentToAutoArchive as $segmentInfo) { @@ -89,21 +85,18 @@ class Piwik_SegmentEditor extends Piwik_Plugin } } - public function getJsFiles($notification) + public function getJsFiles(&$jsFiles) { - $jsFiles = & $notification->getNotificationObject(); $jsFiles[] = "plugins/SegmentEditor/javascripts/jquery.jscrollpane.js"; $jsFiles[] = "plugins/SegmentEditor/javascripts/Segmentation.js"; $jsFiles[] = "plugins/SegmentEditor/javascripts/jquery.mousewheel.js"; $jsFiles[] = "plugins/SegmentEditor/javascripts/mwheelIntent.js"; } - public function getCssFiles($notification) + public function getCssFiles(&$cssFiles) { - $cssFiles = & $notification->getNotificationObject(); $cssFiles[] = "plugins/SegmentEditor/stylesheets/segmentation.css"; $cssFiles[] = "plugins/SegmentEditor/stylesheets/jquery.jscrollpane.css"; $cssFiles[] = "plugins/SegmentEditor/stylesheets/scroll.css"; } - } diff --git a/plugins/SitesManager/API.php b/plugins/SitesManager/API.php index 77fc07d507a986d0df9aa17d0ccef82853ea936d..fcb5d7fbfef48cc83584c1c31a3cb9010fd15b3b 100644 --- a/plugins/SitesManager/API.php +++ b/plugins/SitesManager/API.php @@ -518,7 +518,7 @@ class Piwik_SitesManager_API Zend_Registry::get('access')->reloadAccess(); $this->postUpdateWebsite($idSite); - Piwik_PostEvent('SitesManager.addSite', $idSite); + Piwik_PostEvent('SitesManager.addSite', array($idSite)); return (int)$idSite; } @@ -564,7 +564,7 @@ class Piwik_SitesManager_API // we do not delete logs here on purpose (you can run these queries on the log_ tables to delete all data) Piwik_Tracker_Cache::deleteCacheWebsiteAttributes($idSite); - Piwik_PostEvent('SitesManager.deleteSite', $idSite); + Piwik_PostEvent('SitesManager.deleteSite', array($idSite)); } @@ -1025,7 +1025,7 @@ class Piwik_SitesManager_API } $this->postUpdateWebsite($idSite); - Piwik_PostEvent('SitesManager.updateSite', $idSite); + Piwik_PostEvent('SitesManager.updateSite', array($idSite)); } private function checkAndReturnCommaSeparatedStringList($parameters) diff --git a/plugins/SitesManager/SitesManager.php b/plugins/SitesManager/SitesManager.php index b2b5821d0aedae8d119c8e8252dee88d71d56d6e..81f7c8a60ba2bf840c3f25f9bc1af3423bedbf3d 100644 --- a/plugins/SitesManager/SitesManager.php +++ b/plugins/SitesManager/SitesManager.php @@ -50,41 +50,32 @@ class Piwik_SitesManager extends Piwik_Plugin /** * Get CSS files - * - * @param Piwik_Event_Notification $notification notification object */ - function getCssFiles($notification) + public function getCssFiles(&$cssFiles) { - $cssFiles = & $notification->getNotificationObject(); - $cssFiles[] = "plugins/SitesManager/stylesheets/SitesManager.css"; $cssFiles[] = "plugins/Zeitgeist/stylesheets/styles.css"; } /** * Get JavaScript files - * - * @param Piwik_Event_Notification $notification notification object */ - function getJsFiles($notification) + public function getJsFiles(&$jsFiles) { - $jsFiles = & $notification->getNotificationObject(); - $jsFiles[] = "plugins/SitesManager/javascripts/SitesManager.js"; } /** * Hooks when a website tracker cache is flushed (website updated, cache deleted, or empty cache) * Will record in the tracker config file all data needed for this website in Tracker. - * - * @param Piwik_Event_Notification $notification notification object + * * @return void */ - function recordWebsiteDataInCache($notification) + public function recordWebsiteDataInCache(&$array, $idSite) { - $idSite = (int)$notification->getNotificationInfo(); + $idSite = (int)$idSite; + // add the 'hosts' entry in the website array - $array =& $notification->getNotificationObject(); $array['hosts'] = $this->getTrackerHosts($idSite); $website = Piwik_SitesManager_API::getInstance()->getSiteFromId($idSite); diff --git a/plugins/Transitions/Transitions.php b/plugins/Transitions/Transitions.php index b503266fc30628740c32db60a991848d1bb42805..2eabcbc6434ef603d2f961b249c5c348c90502a8 100644 --- a/plugins/Transitions/Transitions.php +++ b/plugins/Transitions/Transitions.php @@ -33,17 +33,13 @@ class Piwik_Transitions extends Piwik_Plugin ); } - public function getCssFiles($notification) + public function getCssFiles(&$cssFiles) { - $cssFiles = & $notification->getNotificationObject(); $cssFiles[] = 'plugins/Transitions/stylesheets/transitions.css'; } - public function getJsFiles($notification) + public function getJsFiles(&$jsFiles) { - $jsFiles = & $notification->getNotificationObject(); $jsFiles[] = 'plugins/Transitions/javascripts/transitions.js'; } - - -} \ No newline at end of file +} diff --git a/plugins/UserCountry/UserCountry.php b/plugins/UserCountry/UserCountry.php index 1e69e344e4772c58a863e15bec1c54db38a3f3c8..bd74c18f795eb491fbdb35720bea1d1998472500 100644 --- a/plugins/UserCountry/UserCountry.php +++ b/plugins/UserCountry/UserCountry.php @@ -52,45 +52,25 @@ class Piwik_UserCountry extends Piwik_Plugin return $hooks; } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getScheduledTasks($notification) + public function getScheduledTasks(&$tasks) { - $tasks = & $notification->getNotificationObject(); - // add the auto updater task $tasks[] = Piwik_UserCountry_GeoIPAutoUpdater::makeScheduledTask(); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getCssFiles($notification) + public function getCssFiles(&$cssFiles) { - $cssFiles = & $notification->getNotificationObject(); - $cssFiles[] = "plugins/UserCountry/stylesheets/userCountry.css"; } - /** - * @param Piwik_Event_Notification $notification notification object - */ - public function getJsFiles($notification) + public function getJsFiles(&$jsFiles) { - $jsFiles = & $notification->getNotificationObject(); - $jsFiles[] = "plugins/UserCountry/javascripts/userCountry.js"; } - /** - * @param Piwik_Event_Notification $notification notification object - */ - public function getVisitorLocation($notification) + public function getVisitorLocation(&$location, $visitorInfo) { require_once PIWIK_INCLUDE_PATH . "/plugins/UserCountry/LocationProvider.php"; - $location = & $notification->getNotificationObject(); - $visitorInfo = $notification->getNotificationInfo(); $id = Piwik_Common::getCurrentLocationProviderId(); $provider = Piwik_UserCountry_LocationProvider::getProviderById($id); @@ -146,12 +126,8 @@ class Piwik_UserCountry extends Piwik_Plugin $order = 8); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - public function getSegmentsMetadata($notification) + public function getSegmentsMetadata(&$segments) { - $segments =& $notification->getNotificationObject(); $segments[] = array( 'type' => 'dimension', 'category' => 'Visit Location', @@ -203,10 +179,7 @@ class Piwik_UserCountry extends Piwik_Plugin ); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - public function getReportMetadata($notification) + public function getReportMetadata(&$reports) { $metrics = array( 'nb_visits' => Piwik_Translate('General_ColumnNbVisits'), @@ -214,8 +187,6 @@ class Piwik_UserCountry extends Piwik_Plugin 'nb_actions' => Piwik_Translate('General_ColumnNbActions'), ); - $reports = & $notification->getNotificationObject(); - $reports[] = array( 'category' => Piwik_Translate('General_Visitors'), 'name' => Piwik_Translate('UserCountry_Country'), @@ -257,12 +228,8 @@ class Piwik_UserCountry extends Piwik_Plugin ); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getReportsWithGoalMetrics($notification) + public function getReportsWithGoalMetrics(&$dimensions) { - $dimensions =& $notification->getNotificationObject(); $dimensions = array_merge($dimensions, array( array('category' => Piwik_Translate('General_Visit'), 'name' => Piwik_Translate('UserCountry_Country'), @@ -285,28 +252,16 @@ class Piwik_UserCountry extends Piwik_Plugin )); } - /** - * @param Piwik_Event_Notification $notification notification object - * @return mixed - */ - function archivePeriod($notification) + public function archivePeriod(Piwik_ArchiveProcessor_Period $archiveProcessor) { - $archiveProcessor = $notification->getNotificationObject(); - $archiving = new Piwik_UserCountry_Archiver($archiveProcessor); if($archiving->shouldArchive()) { $archiving->archivePeriod(); } } - /** - * @param Piwik_Event_Notification $notification notification object - * @return mixed - */ - function archiveDay($notification) + public function archiveDay(Piwik_ArchiveProcessor_Day $archiveProcessor) { - $archiveProcessor = $notification->getNotificationObject(); - $archiving = new Piwik_UserCountry_Archiver($archiveProcessor); if($archiving->shouldArchive()) { $archiving->archiveDay(); @@ -332,5 +287,4 @@ class Piwik_UserCountry extends Piwik_Plugin return array('SQL' => "'" . implode("', '", $result) . "', ?", 'bind' => '-'); // HACK: SegmentExpression requires a $bind, even if there's nothing to bind } - } diff --git a/plugins/UserCountryMap/UserCountryMap.php b/plugins/UserCountryMap/UserCountryMap.php index adbf9d5dba0a96c3a6899f21539abdd701ed0055..20cc85796127bcf17a444542fe8e1e5be832fd42 100644 --- a/plugins/UserCountryMap/UserCountryMap.php +++ b/plugins/UserCountryMap/UserCountryMap.php @@ -34,9 +34,8 @@ class Piwik_UserCountryMap extends Piwik_Plugin Piwik_AddAction('template_leftColumnUserCountry', array('Piwik_UserCountryMap', 'insertMapInLocationReport')); } - static public function insertMapInLocationReport($notification) + static public function insertMapInLocationReport(&$out) { - $out =& $notification->getNotificationObject(); $out = '<h2>' . Piwik_Translate('UserCountryMap_VisitorMap') . '</h2>'; $out .= Piwik_FrontController::getInstance()->fetchDispatch('UserCountryMap', 'visitorMap'); } @@ -51,17 +50,13 @@ class Piwik_UserCountryMap extends Piwik_Plugin return $hooks; } - function addMenu() + public function addMenu() { Piwik_AddMenu('General_Visitors', 'UserCountryMap_RealTimeMap', array('module' => 'UserCountryMap', 'action' => 'realtimeWorldMap'), true, $order = 70); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - public function getJsFiles($notification) + public function getJsFiles(&$jsFiles) { - $jsFiles = & $notification->getNotificationObject(); $jsFiles[] = "plugins/UserCountryMap/javascripts/vendor/raphael.min.js"; $jsFiles[] = "plugins/UserCountryMap/javascripts/vendor/jquery.qtip.min.js"; $jsFiles[] = "plugins/UserCountryMap/javascripts/vendor/kartograph.min.js"; @@ -70,11 +65,9 @@ class Piwik_UserCountryMap extends Piwik_Plugin $jsFiles[] = "plugins/UserCountryMap/javascripts/realtime-map.js"; } - public function getCssFiles($notification) + public function getCssFiles(&$cssFiles) { - $cssFiles = &$notification->getNotificationObject(); $cssFiles[] = "plugins/UserCountryMap/stylesheets/visitor-map.css"; $cssFiles[] = "plugins/UserCountryMap/stylesheets/realtime-map.css"; } - } diff --git a/plugins/UserSettings/UserSettings.php b/plugins/UserSettings/UserSettings.php index 19b5252360c356495dfdf59882dfa8d185b50e07..e3d907628048693db3541484770bcc645cb9f376 100644 --- a/plugins/UserSettings/UserSettings.php +++ b/plugins/UserSettings/UserSettings.php @@ -177,13 +177,9 @@ class Piwik_UserSettings extends Piwik_Plugin /* * Registers reports metadata - * - * @param Piwik_Event_Notification $notification notification object */ - public function getReportMetadata($notification) + public function getReportMetadata(&$reports) { - $reports = & $notification->getNotificationObject(); - $i = 0; foreach ($this->reportMetadata as $report) { list($category, $name, $apiModule, $apiAction, $columnName) = $report; @@ -221,12 +217,9 @@ class Piwik_UserSettings extends Piwik_Plugin /** * Get segments meta data - * - * @param Piwik_Event_Notification $notification notification object */ - public function getSegmentsMetadata($notification) + public function getSegmentsMetadata(&$segments) { - $segments =& $notification->getNotificationObject(); foreach ($this->reportMetadata as $report) { @list($category, $name, $apiModule, $apiAction, $columnName, $segment, $sqlSegment, $acceptedValues, $sqlFilter) = $report; if (empty($segment)) continue; @@ -267,30 +260,20 @@ class Piwik_UserSettings extends Piwik_Plugin * Daily archive of User Settings report. Processes reports for Visits by Resolution, * by Browser, Browser family, etc. Some reports are built from the logs, some reports * are superset of an existing report (eg. Browser family is built from the Browser report) - * - * @param Piwik_Event_Notification $notification notification object */ - function archiveDay($notification) + public function archiveDay(Piwik_ArchiveProcessor_Day $archiveProcessor) { - $archiveProcessor = $notification->getNotificationObject(); - $archiving = new Piwik_UserSettings_Archiver($archiveProcessor); if($archiving->shouldArchive()) { $archiving->archiveDay(); } } - /** * Period archiving: simply sums up daily archives - * - * @param Piwik_Event_Notification $notification notification object - * @return void */ - function archivePeriod($notification) + public function archivePeriod(Piwik_ArchiveProcessor_Period $archiveProcessor) { - $archiveProcessor = $notification->getNotificationObject(); - $archiving = new Piwik_UserSettings_Archiver($archiveProcessor); if($archiving->shouldArchive()) { $archiving->archivePeriod(); diff --git a/plugins/UsersManager/API.php b/plugins/UsersManager/API.php index 7937c90ec47621c813cf8e53981865685416b180..65ca931704f68db80c39f2775fb3da201454c542 100644 --- a/plugins/UsersManager/API.php +++ b/plugins/UsersManager/API.php @@ -388,7 +388,7 @@ class Piwik_UsersManager_API Zend_Registry::get('access')->reloadAccess(); Piwik_Tracker_Cache::deleteTrackerCache(); - Piwik_PostEvent('UsersManager.addUser', $userLogin); + Piwik_PostEvent('UsersManager.addUser', array($userLogin)); } /** @@ -445,7 +445,7 @@ class Piwik_UsersManager_API ); Piwik_Tracker_Cache::deleteTrackerCache(); - Piwik_PostEvent('UsersManager.updateUser', $userLogin); + Piwik_PostEvent('UsersManager.updateUser', array($userLogin)); } /** @@ -630,7 +630,7 @@ class Piwik_UsersManager_API $db = Zend_Registry::get('db'); $db->query("DELETE FROM " . Piwik_Common::prefixTable("user") . " WHERE login = ?", $userLogin); - Piwik_PostEvent('UsersManager.deleteUser', $userLogin); + Piwik_PostEvent('UsersManager.deleteUser', array($userLogin)); } diff --git a/plugins/UsersManager/Controller.php b/plugins/UsersManager/Controller.php index 57063bfbdd3f5e1719ad59e9cc289afd51a349ef..79388fef7eb94d0340d7439fac3348a4a9a89747 100644 --- a/plugins/UsersManager/Controller.php +++ b/plugins/UsersManager/Controller.php @@ -312,7 +312,7 @@ class Piwik_UsersManager_Controller extends Piwik_Controller_Admin 'md5Password' => md5($newPassword), 'rememberMe' => false, ); - Piwik_PostEvent('Login.initSession', $info); + Piwik_PostEvent('Login.initSession', array($info)); } Piwik_UsersManager_API::getInstance()->setUserPreference($userLogin, diff --git a/plugins/UsersManager/UsersManager.php b/plugins/UsersManager/UsersManager.php index 5046f34caec6fe09fab9dca20d5bcf0b144cc7f6..1eea389e7ed0e2b9a0cf850db9eb4a166ccbeb3f 100644 --- a/plugins/UsersManager/UsersManager.php +++ b/plugins/UsersManager/UsersManager.php @@ -45,7 +45,7 @@ class Piwik_UsersManager extends Piwik_Plugin * * @return array */ - function getListHooksRegistered() + public function getListHooksRegistered() { return array( 'AdminMenu.add' => 'addMenu', @@ -62,12 +62,10 @@ class Piwik_UsersManager extends Piwik_Plugin * Will record in the tracker config file the list of Admin token_auth for this website. This * will be used when the Tracking API is used with setIp(), setForceDateTime(), setVisitorId(), etc. * - * @param Piwik_Event_Notification $notification notification object * @return void */ - function recordAdminUsersInCache($notification) + public function recordAdminUsersInCache(&$array, $idSite) { - $idSite = $notification->getNotificationInfo(); // add the 'hosts' entry in the website array $users = Piwik_UsersManager_API::getInstance()->getUsersWithSiteAccess($idSite, 'admin'); @@ -75,19 +73,13 @@ class Piwik_UsersManager extends Piwik_Plugin foreach ($users as $user) { $tokens[] = $user['token_auth']; } - $array =& $notification->getNotificationObject(); - $array['admin_token_auth'] = $tokens; } /** * Delete user preferences associated with a particular site - * - * @param Piwik_Event_Notification $notification notification object */ - function deleteSite($notification) + public function deleteSite(&$idSite) { - $idSite = & $notification->getNotificationObject(); - Piwik_Option::getInstance()->deleteLike('%\_' . Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT, $idSite); } @@ -95,26 +87,18 @@ class Piwik_UsersManager extends Piwik_Plugin * Return list of plug-in specific JavaScript files to be imported by the asset manager * * @see Piwik_AssetManager - * - * @param Piwik_Event_Notification $notification notification object */ - function getJsFiles($notification) + public function getJsFiles(&$jsFiles) { - $jsFiles = & $notification->getNotificationObject(); - $jsFiles[] = "plugins/UsersManager/javascripts/usersManager.js"; $jsFiles[] = "plugins/UsersManager/javascripts/usersSettings.js"; } /** * Get CSS files - * - * @param Piwik_Event_Notification $notification notification object */ - function getCssFiles($notification) + function getCssFiles(&$cssFiles) { - $cssFiles = & $notification->getNotificationObject(); - $cssFiles[] = "plugins/UsersManager/stylesheets/usersManager.css"; } diff --git a/plugins/VisitFrequency/VisitFrequency.php b/plugins/VisitFrequency/VisitFrequency.php index 717e3f8eae4f2405ed81ddb1563034d9565f5421..a5bdf08f9a4aadf3a323eabbe11a0281ddcedd68 100644 --- a/plugins/VisitFrequency/VisitFrequency.php +++ b/plugins/VisitFrequency/VisitFrequency.php @@ -36,12 +36,8 @@ class Piwik_VisitFrequency extends Piwik_Plugin return $hooks; } - /** - * @param Piwik_Event_Notification $notification notification object - */ - public function getReportMetadata($notification) + public function getReportMetadata(&$reports) { - $reports = & $notification->getNotificationObject(); $reports[] = array( 'category' => Piwik_Translate('General_Visitors'), 'name' => Piwik_Translate('VisitFrequency_ColumnReturningVisits'), @@ -76,4 +72,3 @@ class Piwik_VisitFrequency extends Piwik_Plugin Piwik_AddMenu('General_Visitors', 'VisitFrequency_SubmenuFrequency', array('module' => 'VisitFrequency', 'action' => 'index')); } } - diff --git a/plugins/VisitTime/VisitTime.php b/plugins/VisitTime/VisitTime.php index b74a48f59ee7b75d13397f09334f79e21b5a3bc7..36ecd86f65048480d9a4ceaafb8ca2a2ce145087 100644 --- a/plugins/VisitTime/VisitTime.php +++ b/plugins/VisitTime/VisitTime.php @@ -40,12 +40,8 @@ class Piwik_VisitTime extends Piwik_Plugin return $hooks; } - /** - * @param Piwik_Event_Notification $notification notification object - */ - public function getReportMetadata($notification) + public function getReportMetadata(&$reports) { - $reports = & $notification->getNotificationObject(); $reports[] = array( 'category' => Piwik_Translate('VisitsSummary_VisitsSummary'), 'name' => Piwik_Translate('VisitTime_WidgetLocalTime'), @@ -92,12 +88,8 @@ class Piwik_VisitTime extends Piwik_Plugin Piwik_AddMenu('General_Visitors', 'VisitTime_SubmenuTimes', array('module' => 'VisitTime', 'action' => 'index')); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getReportsWithGoalMetrics($notification) + public function getReportsWithGoalMetrics(&$dimensions) { - $dimensions =& $notification->getNotificationObject(); $dimensions[] = array('category' => Piwik_Translate('VisitTime_ColumnServerTime'), 'name' => Piwik_Translate('VisitTime_ColumnServerTime'), 'module' => 'VisitTime', @@ -105,12 +97,8 @@ class Piwik_VisitTime extends Piwik_Plugin ); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - public function getSegmentsMetadata($notification) + public function getSegmentsMetadata(&$segments) { - $segments =& $notification->getNotificationObject(); $acceptedValues = "0, 1, 2, 3, ..., 20, 21, 22, 23"; $segments[] = array( 'type' => 'dimension', @@ -130,10 +118,8 @@ class Piwik_VisitTime extends Piwik_Plugin ); } - function archivePeriod($notification) + public function archivePeriod(Piwik_ArchiveProcessor_Period $archiveProcessor) { - $archiveProcessor = $notification->getNotificationObject(); - $archiving = new Piwik_VisitTime_Archiver($archiveProcessor); if($archiving->shouldArchive()) { $archiving->archivePeriod(); @@ -141,14 +127,11 @@ class Piwik_VisitTime extends Piwik_Plugin } - public function archiveDay($notification) + public function archiveDay(Piwik_ArchiveProcessor_Day $archiveProcessor) { - $archiveProcessor = $notification->getNotificationObject(); $archiving = new Piwik_VisitTime_Archiver($archiveProcessor); if($archiving->shouldArchive()) { $archiving->archiveDay(); } } - } - diff --git a/plugins/VisitorInterest/VisitorInterest.php b/plugins/VisitorInterest/VisitorInterest.php index b3cd8a002383e70abacd3b3265ba81cef39d507a..32549798bcc8c0cebae56b20aeab30b0c4362434 100644 --- a/plugins/VisitorInterest/VisitorInterest.php +++ b/plugins/VisitorInterest/VisitorInterest.php @@ -38,12 +38,8 @@ class Piwik_VisitorInterest extends Piwik_Plugin return $hooks; } - /** - * @param Piwik_Event_Notification $notification notification object - */ - public function getReportMetadata($notification) + public function getReportMetadata(&$reports) { - $reports = & $notification->getNotificationObject(); $reports[] = array( 'category' => Piwik_Translate('General_Visitors'), 'name' => Piwik_Translate('VisitorInterest_WidgetLengths'), @@ -123,42 +119,29 @@ class Piwik_VisitorInterest extends Piwik_Plugin Piwik_AddAction('template_footerVisitsFrequency', array('Piwik_VisitorInterest', 'footerVisitsFrequency')); } - function archivePeriod($notification) + public function archivePeriod(Piwik_ArchiveProcessor_Period $archiveProcessor) { - $archiveProcessor = $notification->getNotificationObject(); - $archiving = new Piwik_VisitorInterest_Archiver($archiveProcessor); if($archiving->shouldArchive()) { $archiving->archivePeriod(); } } - public function archiveDay($notification) + public function archiveDay(Piwik_ArchiveProcessor_Day $archiveProcessor) { - $archiveProcessor = $notification->getNotificationObject(); - $archiving = new Piwik_VisitorInterest_Archiver($archiveProcessor); if($archiving->shouldArchive()) { $archiving->archiveDay(); } } - - /** - * @param Piwik_Event_Notification $notification notification object - */ - static public function headerVisitsFrequency($notification) + static public function headerVisitsFrequency(&$out) { - $out =& $notification->getNotificationObject(); $out = '<div id="leftcolumn">'; } - /** - * @param Piwik_Event_Notification $notification notification object - */ - static public function footerVisitsFrequency($notification) + static public function footerVisitsFrequency(&$out) { - $out =& $notification->getNotificationObject(); $out = '</div> <div id="rightcolumn"> '; @@ -166,4 +149,3 @@ class Piwik_VisitorInterest extends Piwik_Plugin $out .= '</div>'; } } - diff --git a/plugins/VisitsSummary/VisitsSummary.php b/plugins/VisitsSummary/VisitsSummary.php index 0744b0424a28cb4ee49a1d88c7c734e47ffe7eaa..f7ba58937e373f155a6e2bd162a55d6fe98edcda 100644 --- a/plugins/VisitsSummary/VisitsSummary.php +++ b/plugins/VisitsSummary/VisitsSummary.php @@ -39,12 +39,8 @@ class Piwik_VisitsSummary extends Piwik_Plugin ); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - public function getReportMetadata($notification) + public function getReportMetadata(&$reports) { - $reports = & $notification->getNotificationObject(); $reports[] = array( 'category' => Piwik_Translate('VisitsSummary_VisitsSummary'), 'name' => Piwik_Translate('VisitsSummary_VisitsSummary'), diff --git a/plugins/Widgetize/Widgetize.php b/plugins/Widgetize/Widgetize.php index 31b5a95a5c690a71c01ce71a34a68d251715b109..c8ba33afeb91638a823e4f9f72a1cad07b6207e2 100644 --- a/plugins/Widgetize/Widgetize.php +++ b/plugins/Widgetize/Widgetize.php @@ -44,13 +44,8 @@ class Piwik_Widgetize extends Piwik_Plugin Piwik_AddTopMenu('General_Widgets', $urlParams, true, 5, $isHTML = false, $tooltip); } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getJsFiles($notification) + public function getJsFiles(&$jsFiles) { - $jsFiles = & $notification->getNotificationObject(); - $jsFiles[] = "libs/jquery/jquery.truncate.js"; $jsFiles[] = "libs/jquery/jquery.scrollTo.js"; $jsFiles[] = "plugins/Zeitgeist/javascripts/piwikHelper.js"; @@ -59,13 +54,8 @@ class Piwik_Widgetize extends Piwik_Plugin $jsFiles[] = "plugins/Widgetize/javascripts/widgetize.js"; } - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getCssFiles($notification) + public function getCssFiles(&$cssFiles) { - $cssFiles = & $notification->getNotificationObject(); - $cssFiles[] = "plugins/Widgetize/stylesheets/widgetize.css"; $cssFiles[] = "plugins/CoreHome/stylesheets/corehome.css"; $cssFiles[] = "plugins/CoreHome/stylesheets/datatable.css"; diff --git a/tests/PHPUnit/Core/JsProxyTest.php b/tests/PHPUnit/Core/JsProxyTest.php index 295cf5a682cb4afa928f4ae683d46959c4275a50..2efbcdae74e3afb80c91f6e856f927b368dedc96 100644 --- a/tests/PHPUnit/Core/JsProxyTest.php +++ b/tests/PHPUnit/Core/JsProxyTest.php @@ -35,8 +35,11 @@ class Test_Piwik_JsProxy extends PHPUnit_Framework_TestCase curl_close($curlHandle); $this->assertEquals($responseInfo["http_code"], 200, 'Ok response'); - $ok = $fullResponse == base64_decode("R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="); - $this->assertTrue($ok, '1*1 pixel was expected, got: "'.$fullResponse.'"'); + $this->assertEquals( + "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==", + base64_encode($fullResponse), + 'checking for image content' + ); } /** diff --git a/tests/PHPUnit/Core/PiwikTest.php b/tests/PHPUnit/Core/PiwikTest.php index ade7e91778b225daad4d69c56d59ac47cb502201..1d8f075c2b766845bd907db451bc03598c1e297c 100644 --- a/tests/PHPUnit/Core/PiwikTest.php +++ b/tests/PHPUnit/Core/PiwikTest.php @@ -106,6 +106,10 @@ class PiwikTest extends DatabaseTestCase */ public function testGetPrettyTimeFromSeconds($seconds, $expected) { + if (($seconds * 100) > PHP_INT_MAX) { + $this->markTestSkipped("Will not pass on 32-bit machine."); + } + Piwik_Translate::getInstance()->loadEnglishTranslation(); $sentenceExpected = str_replace(' ', ' ', $expected[0]); diff --git a/tests/PHPUnit/Core/TaskSchedulerTest.php b/tests/PHPUnit/Core/TaskSchedulerTest.php index a774666e5a4a83fba7b8254c0795a03aa799ac8d..f168abc6ad23621f1cb7d40897a100305535283a 100644 --- a/tests/PHPUnit/Core/TaskSchedulerTest.php +++ b/tests/PHPUnit/Core/TaskSchedulerTest.php @@ -277,8 +277,15 @@ class TaskSchedulerTest extends PHPUnit_Framework_TestCase */ public function testRunTasks($expectedTimetable, $expectedExecutedTasks, $timetableBeforeTaskExecution, $configuredTasks) { - // stub the event dispatcher so we can control the returned event notification - Piwik_PluginsManager::getInstance()->dispatcher = new MockEventDispatcher($configuredTasks); + // temporarily unload plugins + $plugins = Piwik_PluginsManager::getInstance()->getLoadedPlugins(); + $plugins = array_map(function ($p) { return $p->getPluginName(); }, $plugins); + Piwik_PluginsManager::getInstance()->unloadPlugins(); + + // make sure the get tasks event returns our configured tasks + Piwik_AddAction(Piwik_TaskScheduler::GET_TASKS_EVENT, function(&$tasks) use($configuredTasks) { + $tasks = $configuredTasks; + }); // stub the piwik option object to control the returned option value self::stubPiwikOption(serialize($timetableBeforeTaskExecution)); @@ -299,8 +306,9 @@ class TaskSchedulerTest extends PHPUnit_Framework_TestCase $getTimetableFromOptionTable->setAccessible(TRUE); $this->assertEquals($expectedTimetable, $getTimetableFromOptionTable->invoke(new Piwik_TaskScheduler())); - // restore event dispatcher & piwik options - Piwik_PluginsManager::getInstance()->dispatcher = Event_Dispatcher::getInstance(); + // restore loaded plugins & piwik options + Piwik_EventDispatcher::getInstance()->clearObservers(Piwik_TaskScheduler::GET_TASKS_EVENT); + Piwik_PluginsManager::getInstance()->loadPlugins($plugins); self::resetPiwikOption(); } diff --git a/tests/PHPUnit/MockEventDispatcher.php b/tests/PHPUnit/MockEventDispatcher.php deleted file mode 100644 index a5528e61e0e94dd3e61bf390efdad10049dbe998..0000000000000000000000000000000000000000 --- a/tests/PHPUnit/MockEventDispatcher.php +++ /dev/null @@ -1,23 +0,0 @@ -<?php -/** - * Piwik - Open source web analytics - * - * @link http://piwik.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - */ -class MockEventDispatcher extends Event_Dispatcher -{ - private $forcedNotificationObject = false; - - function __construct($forcedNotificationObject) - { - $this->forcedNotificationObject = $forcedNotificationObject; - } - - function &postNotification(&$notification, $pending = true, $bubble = true) - { - $notification->_notificationObject = $this->forcedNotificationObject; - - return $notification; - } -} diff --git a/tests/PHPUnit/Plugins/MobileMessagingTest.php b/tests/PHPUnit/Plugins/MobileMessagingTest.php index 04689274c06910a4b3fb0fada9ef7e42f1ed9798..8843b3e2c6f46c56ead3c98371abd9b5c1aa53a6 100644 --- a/tests/PHPUnit/Plugins/MobileMessagingTest.php +++ b/tests/PHPUnit/Plugins/MobileMessagingTest.php @@ -230,17 +230,13 @@ class MobileMessagingTest extends DatabaseTestCase */ public function testSendReport($expectedReportContent, $expectedPhoneNumber, $expectedFrom, $reportContent, $phoneNumber, $reportSubject) { - $eventNotification = new Piwik_Event_Notification( - $this, - null, - array( - Piwik_PDFReports_API::REPORT_CONTENT_KEY => $reportContent, - Piwik_PDFReports_API::REPORT_SUBJECT_KEY => $reportSubject, - Piwik_PDFReports_API::REPORT_TYPE_INFO_KEY => Piwik_MobileMessaging::MOBILE_TYPE, - Piwik_PDFReports_API::REPORT_KEY => array( - 'parameters' => array(Piwik_MobileMessaging::PHONE_NUMBERS_PARAMETER => array($phoneNumber)), - ), - ) + $notificationInfo = array( + Piwik_PDFReports_API::REPORT_CONTENT_KEY => $reportContent, + Piwik_PDFReports_API::REPORT_SUBJECT_KEY => $reportSubject, + Piwik_PDFReports_API::REPORT_TYPE_INFO_KEY => Piwik_MobileMessaging::MOBILE_TYPE, + Piwik_PDFReports_API::REPORT_KEY => array( + 'parameters' => array(Piwik_MobileMessaging::PHONE_NUMBERS_PARAMETER => array($phoneNumber)), + ), ); $stubbedMobileMessagingAPI = $this->getMock('Piwik_MobileMessaging_API'); @@ -255,7 +251,7 @@ class MobileMessagingTest extends DatabaseTestCase $stubbedMobileMessagingAPIClass->setValue($stubbedMobileMessagingAPI); $mobileMessaging = new Piwik_MobileMessaging(); - $mobileMessaging->sendReport($eventNotification); + $mobileMessaging->sendReport($notificationInfo); // restore Piwik_MobileMessaging_API $stubbedMobileMessagingAPIClass->setValue(null); diff --git a/tests/PHPUnit/Plugins/PDFReportsTest.php b/tests/PHPUnit/Plugins/PDFReportsTest.php index 23777914db49508ed109863db4e77eab43f12cdc..3ddb0c1915d7c404b6e108659c81101f1ed4cb1d 100644 --- a/tests/PHPUnit/Plugins/PDFReportsTest.php +++ b/tests/PHPUnit/Plugins/PDFReportsTest.php @@ -381,7 +381,7 @@ class PDFReportsTest extends DatabaseTestCase $pdfReportPlugin = new Piwik_PDFReports(); $tasks = array(); - $pdfReportPlugin->getScheduledTasks(new Piwik_Event_Notification($tasks, 'fakeEvent')); + $pdfReportPlugin->getScheduledTasks($tasks); $this->assertEquals($expectedTasks, $tasks); // restore Piwik_PDFReports_API diff --git a/tests/PHPUnit/Plugins/PrivacyManagerTest.php b/tests/PHPUnit/Plugins/PrivacyManagerTest.php index d227c951d7351480b0965c8140941754a49f35b8..1d4b235c79613fe76571f332d845ccc4efb521b8 100755 --- a/tests/PHPUnit/Plugins/PrivacyManagerTest.php +++ b/tests/PHPUnit/Plugins/PrivacyManagerTest.php @@ -804,10 +804,8 @@ class PrivacyManagerTest extends IntegrationTestCase * does the insert into the temporary table. When log_actions are deleted, this idaction should still * be kept. w/ the wrong strategy, it won't be and there will be a dangling reference * in the log_link_visit_action table. - * - * @param Piwik_Event_Notification $notification notification object */ - public function addReferenceToUnusedAction($notification) + public function addReferenceToUnusedAction() { $unusedIdAction = $this->unusedIdAction; if (empty($unusedIdAction)) // make sure we only do this for one test case diff --git a/tests/PHPUnit/bootstrap.php b/tests/PHPUnit/bootstrap.php index 53a09c14db81adaf4bcb9465c625177d58e0dda5..e31ac8cc72a52d82074c9ad3c36607cb26df3a83 100644 --- a/tests/PHPUnit/bootstrap.php +++ b/tests/PHPUnit/bootstrap.php @@ -60,7 +60,6 @@ require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/DatabaseTestCase.php'; require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/IntegrationTestCase.php'; require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/FakeAccess.php'; require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/MockPiwikOption.php'; -require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/MockEventDispatcher.php'; require_once PIWIK_INCLUDE_PATH . '/vendor/autoload.php'; // required to build code coverage for uncovered files