From 4d341983cb34ee64b199295923a4dadfb5b38b6e Mon Sep 17 00:00:00 2001
From: mattab <matthieu.aubry@gmail.com>
Date: Wed, 9 Oct 2013 15:27:46 +1300
Subject: [PATCH] Refs #4202 removing functions Piwik_PostEvent and moving to
 Piwik::postEvent

---
 core/API/Proxy.php                            |  9 ++--
 core/API/Request.php                          |  3 +-
 core/Access.php                               |  4 +-
 core/ArchiveProcessor/Day.php                 |  3 +-
 core/ArchiveProcessor/Period.php              |  3 +-
 core/AssetManager.php                         |  8 ++--
 core/Config.php                               |  2 +-
 core/Db.php                                   |  2 +-
 core/Error.php                                |  6 +--
 core/ExceptionHandler.php                     |  6 +--
 core/FrontController.php                      | 20 ++++-----
 core/Log.php                                  |  8 ++--
 core/Menu/Admin.php                           |  2 +-
 core/Menu/Main.php                            |  3 +-
 core/Menu/Top.php                             |  3 +-
 core/Piwik.php                                | 44 ++++++++++++++++---
 core/SettingsPiwik.php                        |  4 +-
 core/TaskScheduler.php                        |  2 +-
 core/Tracker.php                              |  4 +-
 core/Tracker/Action.php                       |  3 +-
 core/Tracker/Cache.php                        |  4 +-
 core/Tracker/GoalManager.php                  |  5 ++-
 core/Tracker/Referrer.php                     |  3 +-
 core/Tracker/Request.php                      |  3 +-
 core/Tracker/Visit.php                        |  9 ++--
 core/Tracker/VisitExcluded.php                |  3 +-
 core/Translate.php                            |  4 +-
 core/Twig.php                                 |  2 +-
 core/ViewDataTable.php                        |  6 +--
 core/ViewDataTable/Visualization.php          |  3 +-
 core/WidgetsList.php                          |  2 +-
 core/functions.php                            | 39 ----------------
 plugins/API/API.php                           |  2 +-
 plugins/API/ProcessedReport.php               |  4 +-
 plugins/Goals/Goals.php                       |  2 +-
 plugins/Live/API.php                          |  2 +-
 plugins/Login/Controller.php                  |  2 +-
 plugins/Overlay/API.php                       |  2 +-
 plugins/PrivacyManager/LogDataPurger.php      |  5 ++-
 plugins/Provider/Provider.php                 |  5 ++-
 plugins/ScheduledReports/API.php              | 20 ++++-----
 plugins/SegmentEditor/API.php                 |  2 +-
 plugins/SitesManager/API.php                  |  2 +-
 plugins/UserCountryMap/UserCountryMap.php     |  3 +-
 plugins/UsersManager/API.php                  |  6 +--
 plugins/UsersManager/Controller.php           |  2 +-
 plugins/VisitorInterest/VisitorInterest.php   |  5 ++-
 tests/PHPUnit/Core/TaskSchedulerTest.php      |  2 +-
 tests/PHPUnit/Integration/ArchiveCronTest.php |  2 +-
 tests/PHPUnit/IntegrationTestCase.php         |  2 +-
 tests/PHPUnit/Plugins/PrivacyManagerTest.php  |  2 +-
 tests/PHPUnit/TestingEnvironment.php          | 10 ++---
 tests/PHPUnit/UITest.php                      |  2 +-
 53 files changed, 159 insertions(+), 147 deletions(-)

diff --git a/core/API/Proxy.php b/core/API/Proxy.php
index 759f466437..80810c3c31 100644
--- a/core/API/Proxy.php
+++ b/core/API/Proxy.php
@@ -13,6 +13,7 @@ namespace Piwik\API;
 
 use Exception;
 use Piwik\Common;
+use Piwik\Piwik;
 use ReflectionClass;
 use ReflectionMethod;
 
@@ -187,14 +188,14 @@ class Proxy
              *
              * The `$fnalParameters` contains all paramteres that will be passed to the actual API method.
              */
-            Piwik_PostEvent(sprintf('API.Request.dispatch', $pluginName, $methodName), array(&$finalParameters));
+            Piwik::postEvent(sprintf('API.Request.dispatch', $pluginName, $methodName), array(&$finalParameters));
 
             /**
              * This event is similar to the `API.Request.dispatch` event. It distinguishes the possibility to subscribe
              * only to a specific API method instead of all API methods. You can use it for example to modify any input
              * parameters or to execute any other logic before the actual API method is called.
              */
-            Piwik_PostEvent(sprintf('API.%s.%s', $pluginName, $methodName), array(&$finalParameters));
+            Piwik::postEvent(sprintf('API.%s.%s', $pluginName, $methodName), array(&$finalParameters));
 
             // call the method
             $returnedValue = call_user_func_array(array($object, $methodName), $finalParameters);
@@ -223,7 +224,7 @@ class Proxy
              * );
              * ```
              */
-            Piwik_PostEvent(sprintf('API.%s.%s.end', $pluginName, $methodName), $endHookParams);
+            Piwik::postEvent(sprintf('API.%s.%s.end', $pluginName, $methodName), $endHookParams);
 
             /**
              * Generic hook that plugins can use to modify any output of any API method. The event is triggered after
@@ -240,7 +241,7 @@ class Proxy
              * );
              * ```
              */
-            Piwik_PostEvent(sprintf('API.Request.dispatch.end', $pluginName, $methodName), $endHookParams);
+            Piwik::postEvent(sprintf('API.Request.dispatch.end', $pluginName, $methodName), $endHookParams);
 
             // Restore the request
             $_GET = $saveGET;
diff --git a/core/API/Request.php b/core/API/Request.php
index 9ab13d4f6a..bf43170d0a 100644
--- a/core/API/Request.php
+++ b/core/API/Request.php
@@ -14,6 +14,7 @@ use Exception;
 use Piwik\Access;
 use Piwik\Common;
 use Piwik\DataTable;
+use Piwik\Piwik;
 use Piwik\PluginDeactivatedException;
 use Piwik\PluginsManager;
 use Piwik\SettingsServer;
@@ -186,7 +187,7 @@ class Request
              * This event is triggered when authenticating the API call, only if the token_auth is found in the request.
              * In this case the current session should authenticate using this token_auth.
              */
-            Piwik_PostEvent('API.Request.authenticate', array($token_auth));
+            Piwik::postEvent('API.Request.authenticate', array($token_auth));
             Access::getInstance()->reloadAccess();
             SettingsServer::raiseMemoryLimitIfNecessary();
         }
diff --git a/core/Access.php b/core/Access.php
index e4414500ae..7ee7128f27 100644
--- a/core/Access.php
+++ b/core/Access.php
@@ -49,7 +49,7 @@ class Access
         if (self::$instance == null) {
             self::$instance = new self;
 
-            Piwik_PostTestEvent('Access.createAccessSingleton', array(self::$instance));
+            Piwik::postTestEvent('Access.createAccessSingleton', array(self::$instance));
         }
         return self::$instance;
     }
@@ -216,7 +216,7 @@ class Access
         $this->idsitesByAccess['superuser'] = $allSitesId;
         $this->login = Config::getInstance()->superuser['login'];
 
-        Piwik_PostTestEvent('Access.loadingSuperUserAccess', array(&$this->idsitesByAccess, &$this->login));
+        Piwik::postTestEvent('Access.loadingSuperUserAccess', array(&$this->idsitesByAccess, &$this->login));
 
         return true;
     }
diff --git a/core/ArchiveProcessor/Day.php b/core/ArchiveProcessor/Day.php
index d9f0b88f0c..1a512ba932 100644
--- a/core/ArchiveProcessor/Day.php
+++ b/core/ArchiveProcessor/Day.php
@@ -14,6 +14,7 @@ use Piwik\ArchiveProcessor;
 use Piwik\DataArray;
 use Piwik\DataTable;
 use Piwik\Metrics;
+use Piwik\Piwik;
 
 /**
  * This class
@@ -120,6 +121,6 @@ class Day extends ArchiveProcessor
          * }
          * ```
          */
-        Piwik_PostEvent('ArchiveProcessor.Day.compute', array(&$this));
+        Piwik::postEvent('ArchiveProcessor.Day.compute', array(&$this));
     }
 }
diff --git a/core/ArchiveProcessor/Period.php b/core/ArchiveProcessor/Period.php
index a85debf563..8a87c1fd1e 100644
--- a/core/ArchiveProcessor/Period.php
+++ b/core/ArchiveProcessor/Period.php
@@ -18,6 +18,7 @@ use Piwik\Common;
 use Piwik\DataTable;
 use Piwik\DataTable\Manager;
 use Piwik\Metrics;
+use Piwik\Piwik;
 use Piwik\SettingsPiwik;
 
 /**
@@ -201,7 +202,7 @@ class Period extends ArchiveProcessor
          * }
          * ```
          */
-        Piwik_PostEvent('ArchiveProcessor.Period.compute', array(&$this));
+        Piwik::postEvent('ArchiveProcessor.Period.compute', array(&$this));
     }
 
     protected function aggregateCoreVisitsMetrics()
diff --git a/core/AssetManager.php b/core/AssetManager.php
index f199ce85fa..1adfae0f86 100644
--- a/core/AssetManager.php
+++ b/core/AssetManager.php
@@ -165,7 +165,7 @@ class AssetManager
          * merged into one file but before the generated CSS is written to disk. It can be used to change the modify the
          * stylesheets to your needs, like replacing image paths or adding further custom stylesheets.
          */
-        Piwik_PostEvent('AssetManager.filterMergedStylesheets', array(&$mergedContent));
+        Piwik::postEvent('AssetManager.filterMergedStylesheets', array(&$mergedContent));
 
         $mergedContent =
             $firstLineCompileHash . "\n"
@@ -300,7 +300,7 @@ class AssetManager
          * }
          * ```
          */
-        Piwik_PostEvent(self::STYLESHEET_IMPORT_EVENT, array(&$stylesheets));
+        Piwik::postEvent(self::STYLESHEET_IMPORT_EVENT, array(&$stylesheets));
 
         $stylesheets = self::sortCssFiles($stylesheets);
 
@@ -382,7 +382,7 @@ class AssetManager
          * generated JS file is written to disk. It can be used to change the generated JavaScript to your needs,
          * like adding further scripts or storing the generated file somewhere else.
          */
-        Piwik_PostEvent('AssetManager.filterMergedJavaScripts', array(&$mergedContent));
+        Piwik::postEvent('AssetManager.filterMergedJavaScripts', array(&$mergedContent));
 
         self::writeAssetToFile($mergedContent, self::MERGED_JS_FILE);
     }
@@ -428,7 +428,7 @@ class AssetManager
          * }
          * ```
          */
-        Piwik_PostEvent(self::JAVASCRIPT_IMPORT_EVENT, array(&$jsFiles));
+        Piwik::postEvent(self::JAVASCRIPT_IMPORT_EVENT, array(&$jsFiles));
         $jsFiles = self::sortJsFiles($jsFiles);
         return $jsFiles;
     }
diff --git a/core/Config.php b/core/Config.php
index dfade33673..4926bbda30 100644
--- a/core/Config.php
+++ b/core/Config.php
@@ -300,7 +300,7 @@ class Config
 
             // must be called here, not in init(), since setTestEnvironment() calls init(). (this avoids
             // infinite recursion)
-            Piwik_PostTestEvent('Config.createConfigSingleton', array(self::$instance));
+            Piwik::postTestEvent('Config.createConfigSingleton', array(self::$instance));
         }
 
         // check cache for merged section
diff --git a/core/Db.php b/core/Db.php
index c6119205e5..476423753c 100644
--- a/core/Db.php
+++ b/core/Db.php
@@ -59,7 +59,7 @@ class Db
          * datatabase settings defined in the config. The reporting database config is used in case someone accesses
          * the Piwik UI.
          */
-        Piwik_PostEvent('Reporting.getDatabaseConfig', array(&$dbInfos));
+        Piwik::postEvent('Reporting.getDatabaseConfig', array(&$dbInfos));
 
         $dbInfos['profiler'] = $config->Debug['enable_sql_profiler'];
 
diff --git a/core/Error.php b/core/Error.php
index 9b1ed7b8dd..3e54ef45ec 100644
--- a/core/Error.php
+++ b/core/Error.php
@@ -160,9 +160,9 @@ class Error
 
     public static function setErrorHandler()
     {
-        Piwik_AddAction('Log.formatFileMessage', array('\\Piwik\\Error', 'formatFileAndDBLogMessage'));
-        Piwik_AddAction('Log.formatDatabaseMessage', array('\\Piwik\\Error', 'formatFileAndDBLogMessage'));
-        Piwik_AddAction('Log.formatScreenMessage', array('\\Piwik\\Error', 'formatScreenMessage'));
+        Piwik::addAction('Log.formatFileMessage', array('\\Piwik\\Error', 'formatFileAndDBLogMessage'));
+        Piwik::addAction('Log.formatDatabaseMessage', array('\\Piwik\\Error', 'formatFileAndDBLogMessage'));
+        Piwik::addAction('Log.formatScreenMessage', array('\\Piwik\\Error', 'formatScreenMessage'));
 
         set_error_handler(array('\\Piwik\\Error', 'errorHandler'));
     }
diff --git a/core/ExceptionHandler.php b/core/ExceptionHandler.php
index 7df2734884..9c08ecc3ce 100644
--- a/core/ExceptionHandler.php
+++ b/core/ExceptionHandler.php
@@ -28,9 +28,9 @@ class ExceptionHandler
 
     public static function setUp()
     {
-        Piwik_AddAction('Log.formatFileMessage', array('\\Piwik\\ExceptionHandler', 'formatFileAndDBLogMessage'));
-        Piwik_AddAction('Log.formatDatabaseMessage', array('\\Piwik\\ExceptionHandler', 'formatFileAndDBLogMessage'));
-        Piwik_AddAction('Log.formatScreenMessage', array('\\Piwik\\ExceptionHandler', 'formatScreenMessage'));
+        Piwik::addAction('Log.formatFileMessage', array('\\Piwik\\ExceptionHandler', 'formatFileAndDBLogMessage'));
+        Piwik::addAction('Log.formatDatabaseMessage', array('\\Piwik\\ExceptionHandler', 'formatFileAndDBLogMessage'));
+        Piwik::addAction('Log.formatScreenMessage', array('\\Piwik\\ExceptionHandler', 'formatScreenMessage'));
 
         set_exception_handler(array('\\Piwik\\ExceptionHandler', 'exceptionHandler'));
     }
diff --git a/core/FrontController.php b/core/FrontController.php
index 02f16e7ccb..e1068e46d8 100644
--- a/core/FrontController.php
+++ b/core/FrontController.php
@@ -130,14 +130,14 @@ class FrontController
          *
          * The `$params` array contains the following properties: `array($module, $action, $parameters, $controller)`
          */
-        Piwik_PostEvent('Request.dispatch', $params);
+        Piwik::postEvent('Request.dispatch', $params);
 
         /**
          * This event is similar to the `Request.dispatch` hook. It distinguishes the possibility to subscribe only to a
          * specific controller method instead of all controller methods. You can use it for example to modify any input
          * parameters or execute any other logic before the actual controller is called.
          */
-        Piwik_PostEvent(sprintf('Controller.%s.%s', $module, $action), array($parameters));
+        Piwik::postEvent(sprintf('Controller.%s.%s', $module, $action), array($parameters));
 
         try {
             $result = call_user_func_array(array($params[3], $params[1]), $params[2]);
@@ -147,14 +147,14 @@ class FrontController
              * only to the end of a specific controller method instead of all controller methods. You can use it for
              * example to modify the response of a single controller method.
              */
-            Piwik_PostEvent(sprintf('Controller.%s.%s.end', $module, $action), array(&$result, $parameters));
+            Piwik::postEvent(sprintf('Controller.%s.%s.end', $module, $action), array(&$result, $parameters));
 
             /**
              * Generic hook that plugins can use to modify any output of any controller method. The event is triggered
              * after a controller method is executed but before the result is send to the user. The parameters
              * originally passed to the method are available as well.
              */
-            Piwik_PostEvent('Request.dispatch.end', array(&$result, $parameters));
+            Piwik::postEvent('Request.dispatch.end', array(&$result, $parameters));
 
             return $result;
 
@@ -165,7 +165,7 @@ class FrontController
              * required permissions to do this. You can subscribe to this event to display a custom error message or
              * to display a custom login form in such a case.
              */
-            Piwik_PostEvent('User.isNotAuthorized', array($exception), $pending = true);
+            Piwik::postEvent('User.isNotAuthorized', array($exception), $pending = true);
         } catch (Exception $e) {
             $debugTrace = $e->getTraceAsString();
             $message = Common::sanitizeInputValue($e->getMessage());
@@ -245,7 +245,7 @@ class FrontController
              * installed yet. The event can be used to start the installation process or to display a custom error
              * message.
              */
-            Piwik_PostEvent('Config.NoConfigurationFile', array($exception), $pending = true);
+            Piwik::postEvent('Config.NoConfigurationFile', array($exception), $pending = true);
             $exceptionToThrow = $exception;
         }
         return $exceptionToThrow;
@@ -318,7 +318,7 @@ class FrontController
                  * are missing. The event can be used to start the installation process or to display a custom error
                  * message.
                  */
-                Piwik_PostEvent('Config.badConfigurationFile', array($exception), $pending = true);
+                Piwik::postEvent('Config.badConfigurationFile', array($exception), $pending = true);
                 throw $exception;
             }
 
@@ -329,7 +329,7 @@ class FrontController
              * This event is the first event triggered just after the platform is initialized and plugins are loaded.
              * You can use this event to do early initialization. Note: the user is not authenticated yet.
              */
-            Piwik_PostEvent('Request.dispatchCoreAndPluginUpdatesScreen');
+            Piwik::postEvent('Request.dispatchCoreAndPluginUpdatesScreen');
 
             PluginsManager::getInstance()->installLoadedPlugins();
 
@@ -342,7 +342,7 @@ class FrontController
              * This event is triggered before the user is authenticated. You can use it to create your own
              * authentication object which implements the `Piwik\Auth` interface, and override the default authentication logic.
              */
-            Piwik_PostEvent('Request.initAuthenticationObject');
+            Piwik::postEvent('Request.initAuthenticationObject');
             try {
                 $authAdapter = Registry::get('auth');
             } catch (Exception $e) {
@@ -368,7 +368,7 @@ class FrontController
              * the user is authenticated but before the platform is going to dispatch the actual request. You can use
              * it to check for any updates.
              */
-            Piwik_PostEvent('Updater.checkForUpdates');
+            Piwik::postEvent('Updater.checkForUpdates');
         } catch (Exception $e) {
 
             if (self::shouldRethrowException()) {
diff --git a/core/Log.php b/core/Log.php
index 9be82abe78..026f63c839 100644
--- a/core/Log.php
+++ b/core/Log.php
@@ -299,7 +299,7 @@ class Log
          * // 'myloggername' can now be used in the log_writers config option.
          * ```
          */
-        Piwik_PostEvent(self::GET_AVAILABLE_WRITERS_EVENT, array(&$writers));
+        Piwik::postEvent(self::GET_AVAILABLE_WRITERS_EVENT, array(&$writers));
 
         $writers['file'] = array($this, 'logToFile');
         $writers['screen'] = array($this, 'logToScreen');
@@ -322,7 +322,7 @@ class Log
              * check if the object is of a certain type and if it is, set $message to the
              * string that should be logged.
              */
-            Piwik_PostEvent(self::FORMAT_FILE_MESSAGE_EVENT, array(&$message, $level, $tag, $datetime, $logger));
+            Piwik::postEvent(self::FORMAT_FILE_MESSAGE_EVENT, array(&$message, $level, $tag, $datetime, $logger));
         }
 
         if (empty($message)) {
@@ -366,7 +366,7 @@ class Log
              * The result of this callback can be HTML so no sanitization is done on the result.
              * This means YOU MUST SANITIZE THE MESSAGE YOURSELF if you use this event.
              */
-            Piwik_PostEvent(self::FORMAT_SCREEN_MESSAGE_EVENT, array(&$message, $level, $tag, $datetime, $logger));
+            Piwik::postEvent(self::FORMAT_SCREEN_MESSAGE_EVENT, array(&$message, $level, $tag, $datetime, $logger));
         }
 
         if (empty($message)) {
@@ -391,7 +391,7 @@ class Log
              * check if the object is of a certain type and if it is, set $message to the
              * string that should be logged.
              */
-            Piwik_PostEvent(self::FORMAT_DATABASE_MESSAGE_EVENT, array(&$message, $level, $tag, $datetime, $logger));
+            Piwik::postEvent(self::FORMAT_DATABASE_MESSAGE_EVENT, array(&$message, $level, $tag, $datetime, $logger));
         }
 
         if (empty($message)) {
diff --git a/core/Menu/Admin.php b/core/Menu/Admin.php
index d32335d4d4..2c9bf93393 100644
--- a/core/Menu/Admin.php
+++ b/core/Menu/Admin.php
@@ -59,7 +59,7 @@ class Admin extends MenuAbstract
              * }
              * ```
              */
-            Piwik_PostEvent('Menu.Admin.addItems');
+            Piwik::postEvent('Menu.Admin.addItems');
         }
         return parent::get();
     }
diff --git a/core/Menu/Main.php b/core/Menu/Main.php
index 1511a3f9fb..db858f8c74 100644
--- a/core/Menu/Main.php
+++ b/core/Menu/Main.php
@@ -9,6 +9,7 @@
  * @package Piwik_Menu
  */
 namespace Piwik\Menu;
+use Piwik\Piwik;
 
 
 /**
@@ -79,7 +80,7 @@ class Main extends MenuAbstract
              * }
              * ```
              */
-            Piwik_PostEvent('Menu.Reporting.addItems');
+            Piwik::postEvent('Menu.Reporting.addItems');
         }
         return parent::get();
     }
diff --git a/core/Menu/Top.php b/core/Menu/Top.php
index 7901a13d71..52d6f7ef31 100644
--- a/core/Menu/Top.php
+++ b/core/Menu/Top.php
@@ -9,6 +9,7 @@
  * @package Piwik_Menu
  */
 namespace Piwik\Menu;
+use Piwik\Piwik;
 
 
 /**
@@ -79,7 +80,7 @@ class Top extends MenuAbstract
              * }
              * ```
              */
-            Piwik_PostEvent('Menu.Top.addItems');
+            Piwik::postEvent('Menu.Top.addItems');
         }
         return parent::get();
     }
diff --git a/core/Piwik.php b/core/Piwik.php
index 8da79c3f08..3be8c765eb 100644
--- a/core/Piwik.php
+++ b/core/Piwik.php
@@ -46,7 +46,6 @@ class Piwik
         'range' => 5,
     );
 
-
     const LABEL_ID_GOAL_IS_ECOMMERCE_CART = 'ecommerceAbandonedCart';
     const LABEL_ID_GOAL_IS_ECOMMERCE_ORDER = 'ecommerceOrder';
 
@@ -82,10 +81,6 @@ class Piwik
         exit;
     }
 
-    /*
-     * Amounts, Percentages, Currency, Time, Math Operations, and Pretty Printing
-     */
-
     /**
      * Computes the division of i1 by i2. If either i1 or i2 are not number, or if i2 has a value of zero
      * we return 0 to avoid the division by zero.
@@ -646,4 +641,43 @@ class Piwik
         $parts = explode('\\', $className);
         return end($parts);
     }
+
+
+    /**
+     * 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.
+     * @param bool $pending
+     * @param null $plugins
+     * @return void
+     * @api
+     */
+    public static function postEvent($eventName, $params = array(), $pending = false, $plugins = null)
+    {
+        EventDispatcher::getInstance()->postEvent($eventName, $params, $pending, $plugins);
+    }
+
+    /**
+     * Register an action to execute for a given event
+     *
+     * @param string $eventName Name of event
+     * @param callable $function Callback hook
+     * @api
+     */
+    public static function addAction($eventName, $function)
+    {
+        EventDispatcher::getInstance()->addObserver($eventName, $function);
+    }
+
+    /**
+     * Posts an event if we are currently running tests. Whether we are running tests is
+     * determined by looking for the PIWIK_TEST_MODE constant.
+     */
+    public static function postTestEvent($eventName, $params = array(), $pending = false, $plugins = null)
+    {
+        if (defined('PIWIK_TEST_MODE')) {
+            Piwik::postEvent($eventName, $params, $pending, $plugins);
+        }
+    }
 }
diff --git a/core/SettingsPiwik.php b/core/SettingsPiwik.php
index 24e857d3f0..a7412d9a3c 100644
--- a/core/SettingsPiwik.php
+++ b/core/SettingsPiwik.php
@@ -66,7 +66,7 @@ class SettingsPiwik
              * This event is triggered when the automatic archiving runs.
              * You can use it to add segments to the list of segments to pre-process during archiving.
              */
-            Piwik_PostEvent('Segments.getKnownSegmentsToArchiveAllSites', array(&$segmentsToProcess));
+            Piwik::postEvent('Segments.getKnownSegmentsToArchiveAllSites', array(&$segmentsToProcess));
 
             self::$cachedKnownSegmentsToArchive = array_unique($segmentsToProcess);
         }
@@ -82,7 +82,7 @@ class SettingsPiwik
         /**
          * @matt
          */
-        Piwik_PostEvent('Segments.getKnownSegmentsToArchiveForSite', array(&$segments, $idSite));
+        Piwik::postEvent('Segments.getKnownSegmentsToArchiveForSite', array(&$segments, $idSite));
         return $segments;
     }
 
diff --git a/core/TaskScheduler.php b/core/TaskScheduler.php
index 2b529566d9..a81268c4c9 100644
--- a/core/TaskScheduler.php
+++ b/core/TaskScheduler.php
@@ -65,7 +65,7 @@ class TaskScheduler
          * }
          * ```
          */
-        Piwik_PostEvent(self::GET_TASKS_EVENT, array(&$tasks));
+        Piwik::postEvent(self::GET_TASKS_EVENT, array(&$tasks));
         /** @var ScheduledTask[] $tasks */
 
         // remove from timetable tasks that are not active anymore
diff --git a/core/Tracker.php b/core/Tracker.php
index a9a3855695..0db9fb2adf 100644
--- a/core/Tracker.php
+++ b/core/Tracker.php
@@ -561,7 +561,7 @@ class Tracker
          * datatabase settings defined in the config. The tracker database config is used in case a new pageview/visit
          * will be tracked.
          */
-        Piwik_PostEvent('Tracker.getDatabaseConfig', array(&$configDb));
+        Piwik::postEvent('Tracker.getDatabaseConfig', array(&$configDb));
 
         $db = Tracker::factory($configDb);
         $db->connect();
@@ -614,7 +614,7 @@ class Tracker
          * usage of your own or your extended visit object but make sure to implement the
          * `Piwik\Tracker\VisitInterface`.
          */
-        Piwik_PostEvent('Tracker.makeNewVisitObject', array(&$visit));
+        Piwik::postEvent('Tracker.makeNewVisitObject', array(&$visit));
 
         if (is_null($visit)) {
             $visit = new Visit();
diff --git a/core/Tracker/Action.php b/core/Tracker/Action.php
index c869cf8a53..cba622ed99 100644
--- a/core/Tracker/Action.php
+++ b/core/Tracker/Action.php
@@ -14,6 +14,7 @@ namespace Piwik\Tracker;
 use Exception;
 use Piwik\Common;
 use Piwik\Config;
+use Piwik\Piwik;
 use Piwik\Tracker;
 use Piwik\UrlHelper;
 
@@ -644,7 +645,7 @@ class Action implements ActionInterface
          * This hook is called after saving (and updating) visitor information. You can use it for instance to sync the
          * recorded action with third party systems.
          */
-        Piwik_PostEvent('Tracker.recordAction', array($trackerAction = $this, $info));
+        Piwik::postEvent('Tracker.recordAction', array($trackerAction = $this, $info));
     }
 
     public function getCustomVariables()
diff --git a/core/Tracker/Cache.php b/core/Tracker/Cache.php
index de62ad590b..948d1a34ad 100644
--- a/core/Tracker/Cache.php
+++ b/core/Tracker/Cache.php
@@ -65,7 +65,7 @@ class Cache
          * This hook is called to get the details of a specific site depending on the id. You can use this to add any
          * custom attributes to the website.
          */
-        Piwik_PostEvent('Site.getSiteAttributes', array(&$content, $idSite));
+        Piwik::postEvent('Site.getSiteAttributes', array(&$content, $idSite));
 
         // restore original user privilege
         Piwik::setUserIsSuperUser($isSuperUser);
@@ -113,7 +113,7 @@ class Cache
          * This event is triggered to add any custom content to the Tracker cache. You may want to cache any tracker
          * data that is expensive to re-calculate on each tracking request.
          */
-        Piwik_PostEvent('Tracker.setTrackerCacheGeneral', array(&$cacheContent));
+        Piwik::postEvent('Tracker.setTrackerCacheGeneral', array(&$cacheContent));
         self::setCacheGeneral($cacheContent);
         return $cacheContent;
     }
diff --git a/core/Tracker/GoalManager.php b/core/Tracker/GoalManager.php
index 7c8b3bbc81..a60864ce47 100644
--- a/core/Tracker/GoalManager.php
+++ b/core/Tracker/GoalManager.php
@@ -13,6 +13,7 @@ namespace Piwik\Tracker;
 use Exception;
 use Piwik\Common;
 use Piwik\Config;
+use Piwik\Piwik;
 use Piwik\Tracker;
 
 /**
@@ -409,7 +410,7 @@ class GoalManager
          * This hook is called after recording an ecommerce goal. You can use it for instance to sync the recorded goal
          * with third party systems. `$goal` contains all available information like `items` and `revenue`.
          */
-        Piwik_PostEvent('Tracker.recordEcommerceGoal', array($goal));
+        Piwik::postEvent('Tracker.recordEcommerceGoal', array($goal));
     }
 
     /**
@@ -774,7 +775,7 @@ class GoalManager
              * This hook is called after recording a standard goal. You can use it for instance to sync the recorded
              * goal with third party systems. `$goal` contains all available information like `url` and `revenue`.
              */
-            Piwik_PostEvent('Tracker.recordStandardGoals', array($newGoal));
+            Piwik::postEvent('Tracker.recordStandardGoals', array($newGoal));
         }
     }
 
diff --git a/core/Tracker/Referrer.php b/core/Tracker/Referrer.php
index 5954ca1dc8..28c7c966c1 100644
--- a/core/Tracker/Referrer.php
+++ b/core/Tracker/Referrer.php
@@ -11,6 +11,7 @@
 namespace Piwik\Tracker;
 
 use Piwik\Common;
+use Piwik\Piwik;
 use Piwik\UrlHelper;
 
 /**
@@ -132,7 +133,7 @@ class Referrer
          * This event is triggered after basic search engine detection has been attempted. A plugin can use this event
          * to modify or provide new results based on the passed referrer URL.
          */
-        Piwik_PostEvent('Tracker.detectReferrerSearchEngine', array(&$searchEngineInformation, $this->referrerUrl));
+        Piwik::postEvent('Tracker.detectReferrerSearchEngine', array(&$searchEngineInformation, $this->referrerUrl));
         if ($searchEngineInformation === false) {
             return false;
         }
diff --git a/core/Tracker/Request.php b/core/Tracker/Request.php
index 7ae021fb0b..8a7218979f 100644
--- a/core/Tracker/Request.php
+++ b/core/Tracker/Request.php
@@ -6,6 +6,7 @@ use Piwik\Common;
 use Piwik\Config;
 use Piwik\Cookie;
 use Piwik\IP;
+use Piwik\Piwik;
 use Piwik\Tracker;
 
 /**
@@ -297,7 +298,7 @@ class Request
          * be higher than `0`, otherwise an exception will be triggered. By default the idSite is specified on the URL
          * parameter `idsite`.
          */
-        Piwik_PostEvent('Tracker.setSiteId', array(&$idSite, $this->params));
+        Piwik::postEvent('Tracker.setSiteId', array(&$idSite, $this->params));
         if ($idSite <= 0) {
             throw new Exception('Invalid idSite');
         }
diff --git a/core/Tracker/Visit.php b/core/Tracker/Visit.php
index ca55b00e75..cadd3ac9f7 100644
--- a/core/Tracker/Visit.php
+++ b/core/Tracker/Visit.php
@@ -16,6 +16,7 @@ use Piwik\Common;
 use Piwik\Config;
 
 use Piwik\IP;
+use Piwik\Piwik;
 use Piwik\Tracker;
 use UserAgentParser;
 
@@ -95,7 +96,7 @@ class Visit implements VisitInterface
         /**
          * This event can be used for instance to anonymize the IP (after testing for IP exclusion).
          */
-        Piwik_PostEvent('Tracker.setVisitorIp', array(&$this->visitorInfo['location_ip']));
+        Piwik::postEvent('Tracker.setVisitorIp', array(&$this->visitorInfo['location_ip']));
 
         $this->visitorCustomVariables = $this->request->getCustomVariables($scope = 'visit');
         if (!empty($this->visitorCustomVariables)) {
@@ -309,7 +310,7 @@ class Visit implements VisitInterface
          * This event is triggered before saving a known visitor. Use it to change any visitor information before
          * the visitor is saved.
          */
-        Piwik_PostEvent('Tracker.knownVisitorUpdate', array(&$valuesToUpdate));
+        Piwik::postEvent('Tracker.knownVisitorUpdate', array(&$valuesToUpdate));
 
         $this->visitorInfo['time_spent_ref_action'] = $this->getTimeSpentReferrerAction();
 
@@ -354,7 +355,7 @@ class Visit implements VisitInterface
          * After a known visitor is saved and updated by Piwik, this event is called. Useful for plugins that want to
          * register information about a returning visitor, or filter the existing information.
          */
-        Piwik_PostEvent('Tracker.knownVisitorInformation', array(&$this->visitorInfo));
+        Piwik::postEvent('Tracker.knownVisitorInformation', array(&$this->visitorInfo));
     }
 
     /**
@@ -476,7 +477,7 @@ class Visit implements VisitInterface
          * new information about a visitor, or filter the existing information. `$extraInfo` contains the UserAgent.
          * You can for instance change the user's location country depending on the User Agent.
          */
-        Piwik_PostEvent('Tracker.newVisitorInformation', array(&$this->visitorInfo, $extraInfo));
+        Piwik::postEvent('Tracker.newVisitorInformation', array(&$this->visitorInfo, $extraInfo));
 
         $this->request->overrideLocation($this->visitorInfo);
 
diff --git a/core/Tracker/VisitExcluded.php b/core/Tracker/VisitExcluded.php
index 2374e31b91..48d37036c6 100644
--- a/core/Tracker/VisitExcluded.php
+++ b/core/Tracker/VisitExcluded.php
@@ -12,6 +12,7 @@ namespace Piwik\Tracker;
 
 use Piwik\Common;
 use Piwik\IP;
+use Piwik\Piwik;
 
 /**
  * This class contains the logic to exclude some visitors from being tracked as per user settings
@@ -75,7 +76,7 @@ class VisitExcluded
          * At every page view, this event will be called. It is useful for plugins that want to exclude specific visits
          * (ie. IP excluding, Cookie excluding). If you set `$excluded` to `true`, the visit will be excluded.
          */
-        Piwik_PostEvent('Tracker.isExcludedVisit', array(&$excluded));
+        Piwik::postEvent('Tracker.isExcludedVisit', array(&$excluded));
 
         /*
          * Following exclude operations happen after the hook.
diff --git a/core/Translate.php b/core/Translate.php
index 6c03b88236..22b2193f17 100644
--- a/core/Translate.php
+++ b/core/Translate.php
@@ -119,7 +119,7 @@ class Translate
              * it for instance to detect the users language by using a third party API such as a CMS. The language that
              * is set in the request URL is passed as an argument.
              */
-            Piwik_PostEvent('User.getLanguage', array(&$lang));
+            Piwik::postEvent('User.getLanguage', array(&$lang));
 
             self::$languageToLoad = $lang;
         }
@@ -188,7 +188,7 @@ class Translate
          * }
          * ```
          */
-        Piwik_PostEvent(self::GET_CLIENT_SIDE_TRANSLATION_KEYS_EVENT, array(&$result));
+        Piwik::postEvent(self::GET_CLIENT_SIDE_TRANSLATION_KEYS_EVENT, array(&$result));
 
         $result = array_unique($result);
 
diff --git a/core/Twig.php b/core/Twig.php
index 8ec3fa5bee..d0a3ddea5b 100644
--- a/core/Twig.php
+++ b/core/Twig.php
@@ -115,7 +115,7 @@ class Twig
     {
         $postEventFunction = new Twig_SimpleFunction('postEvent', function ($eventName) {
             $str = '';
-            Piwik_PostEvent($eventName, array(&$str));
+            Piwik::postEvent($eventName, array(&$str));
             return $str;
         }, array('is_safe' => array('html')));
         $this->twig->addFunction($postEventFunction);
diff --git a/core/ViewDataTable.php b/core/ViewDataTable.php
index d93d95dbd3..1977cf8243 100644
--- a/core/ViewDataTable.php
+++ b/core/ViewDataTable.php
@@ -441,7 +441,7 @@ class ViewDataTable
              * }
              * ```
              */
-            Piwik_PostEvent('Visualization.getReportDisplayProperties', array(&self::$reportPropertiesCache));
+            Piwik::postEvent('Visualization.getReportDisplayProperties', array(&self::$reportPropertiesCache));
         }
 
         return self::$reportPropertiesCache;
@@ -1106,7 +1106,7 @@ class ViewDataTable
          * that provide new visualizations can use this event to make sure certain reports
          * are configured differently when viewed with the new visualization.
          */
-        Piwik_PostEvent(self::CONFIGURE_VIEW_EVENT, array($viewDataTable = $this));
+        Piwik::postEvent(self::CONFIGURE_VIEW_EVENT, array($viewDataTable = $this));
         $this->overrideViewProperties();
 
         try {
@@ -1299,7 +1299,7 @@ class ViewDataTable
          * )
          * ```
          */
-        Piwik_PostEvent(self::CONFIGURE_FOOTER_ICONS_EVENT, array(&$result, $viewDataTable = $this));
+        Piwik::postEvent(self::CONFIGURE_FOOTER_ICONS_EVENT, array(&$result, $viewDataTable = $this));
 
         return $result;
     }
diff --git a/core/ViewDataTable/Visualization.php b/core/ViewDataTable/Visualization.php
index 98111be77a..5adf6b3cf6 100644
--- a/core/ViewDataTable/Visualization.php
+++ b/core/ViewDataTable/Visualization.php
@@ -12,6 +12,7 @@
 namespace Piwik\ViewDataTable;
 
 use Piwik\DataTable;
+use Piwik\Piwik;
 use Piwik\View;
 
 /**
@@ -154,7 +155,7 @@ abstract class Visualization extends View
          * This event is used to gather all available DataTable visualizations. Callbacks should add visualization
          * class names to the incoming array.
          */
-        Piwik_PostEvent(self::GET_AVAILABLE_EVENT, array(&$visualizations));
+        Piwik::postEvent(self::GET_AVAILABLE_EVENT, array(&$visualizations));
 
         $result = array();
         foreach ($visualizations as $viz) {
diff --git a/core/WidgetsList.php b/core/WidgetsList.php
index 3696cd02f2..71a813b64f 100644
--- a/core/WidgetsList.php
+++ b/core/WidgetsList.php
@@ -69,7 +69,7 @@ class WidgetsList
              * }
              * ```
              */
-            Piwik_PostEvent('WidgetsList.addWidgets');
+            Piwik::postEvent('WidgetsList.addWidgets');
         }
     }
 
diff --git a/core/functions.php b/core/functions.php
index 68fe8829a4..6cca433647 100644
--- a/core/functions.php
+++ b/core/functions.php
@@ -13,49 +13,10 @@
 namespace {
 
     use Piwik\DataTable;
-    use Piwik\EventDispatcher;
     use Piwik\Menu\Admin;
     use Piwik\Menu\Main;
     use Piwik\Menu\Top;
 
-    /**
-     * 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.
-     * @param bool $pending
-     * @param null $plugins
-     * @return void
-     * @api
-     */
-    function Piwik_PostEvent($eventName, $params = array(), $pending = false, $plugins = null)
-    {
-        EventDispatcher::getInstance()->postEvent($eventName, $params, $pending, $plugins);
-    }
-
-    /**
-     * Register an action to execute for a given event
-     *
-     * @param string $eventName Name of event
-     * @param callable $function Callback hook
-     * @api
-     */
-    function Piwik_AddAction($eventName, $function)
-    {
-        EventDispatcher::getInstance()->addObserver($eventName, $function);
-    }
-
-    /**
-     * Posts an event if we are currently running tests. Whether we are running tests is
-     * determined by looking for the PIWIK_TEST_MODE constant.
-     */
-    function Piwik_PostTestEvent($eventName, $params = array(), $pending = false, $plugins = null)
-    {
-        if (defined('PIWIK_TEST_MODE')) {
-            Piwik_PostEvent($eventName, $params, $pending, $plugins);
-        }
-    }
-
     /**
      * Returns translated string or given message if translation is not found.
      *
diff --git a/plugins/API/API.php b/plugins/API/API.php
index afe0ea8a87..41aeea28c4 100644
--- a/plugins/API/API.php
+++ b/plugins/API/API.php
@@ -99,7 +99,7 @@ class API
          * This event is triggered to get all available segments. Your plugin can use this event to add one or
          * multiple new segments.
          */
-        Piwik_PostEvent('API.getSegmentsMetadata', array(&$segments, $idSites));
+        Piwik::postEvent('API.getSegmentsMetadata', array(&$segments, $idSites));
 
         $isAuthenticatedWithViewAccess = Piwik::isUserHasViewAccess($idSites) && !Piwik::isUserIsAnonymous();
 
diff --git a/plugins/API/ProcessedReport.php b/plugins/API/ProcessedReport.php
index eeea9bb4ca..af7c271762 100644
--- a/plugins/API/ProcessedReport.php
+++ b/plugins/API/ProcessedReport.php
@@ -90,7 +90,7 @@ class ProcessedReport
          * multiple reports. By doing that the report will be for instance available in ScheduledReports as well as
          * in the Piwik Mobile App.
          */
-        Piwik_PostEvent('API.getReportMetadata', array(&$availableReports, $parameters));
+        Piwik::postEvent('API.getReportMetadata', array(&$availableReports, $parameters));
         foreach ($availableReports as &$availableReport) {
             if (!isset($availableReport['metrics'])) {
                 $availableReport['metrics'] = Metrics::getDefaultMetrics();
@@ -112,7 +112,7 @@ class ProcessedReport
          * This event is triggered after all available reports are collected. Plugins can add custom metrics to
          * other reports or remove reports from the list of all available reports.
          */
-        Piwik_PostEvent('API.getReportMetadata.end', array(&$availableReports, $parameters));
+        Piwik::postEvent('API.getReportMetadata.end', array(&$availableReports, $parameters));
 
         // Sort results to ensure consistent order
         usort($availableReports, array($this, 'sort'));
diff --git a/plugins/Goals/Goals.php b/plugins/Goals/Goals.php
index 21a34d2562..847fabd7ad 100644
--- a/plugins/Goals/Goals.php
+++ b/plugins/Goals/Goals.php
@@ -359,7 +359,7 @@ class Goals extends \Piwik\Plugin
          * This event is triggered by the Goals plugin to gather the list of all reports which define Goal metrics (conversions, revenue).
          * You can use this event to add your report to the list of reports displayed in the left column of the Goals Overview report.
          */
-        Piwik_PostEvent('Goals.getReportsWithGoalMetrics', array(&$reportsWithGoals));
+        Piwik::postEvent('Goals.getReportsWithGoalMetrics', array(&$reportsWithGoals));
 
         return $reportsWithGoals;
     }
diff --git a/plugins/Live/API.php b/plugins/Live/API.php
index 065521a263..3cfc1bba75 100644
--- a/plugins/Live/API.php
+++ b/plugins/Live/API.php
@@ -370,7 +370,7 @@ class API
          * - visitorAvatar: A URL to an image to display in the top left corner of the popup.
          * - visitorDescription: Text to be used as the tooltip of the avatar image.
          */
-        Piwik_PostEvent('Live.getExtraVisitorDetails', array(&$result));
+        Piwik::postEvent('Live.getExtraVisitorDetails', array(&$result));
 
         return $result;
     }
diff --git a/plugins/Login/Controller.php b/plugins/Login/Controller.php
index c390710693..ea9cd8788e 100644
--- a/plugins/Login/Controller.php
+++ b/plugins/Login/Controller.php
@@ -184,7 +184,7 @@ class Controller extends \Piwik\Controller
          * }
          * ```
          */
-        Piwik_PostEvent('Login.initSession', array(&$info));
+        Piwik::postEvent('Login.initSession', array(&$info));
         Url::redirectToUrl($urlToRedirect);
     }
 
diff --git a/plugins/Overlay/API.php b/plugins/Overlay/API.php
index de5fb7f39d..37ac6b7e49 100644
--- a/plugins/Overlay/API.php
+++ b/plugins/Overlay/API.php
@@ -121,7 +121,7 @@ class API
          * authentication object instead of the Piwik authentication. Make sure to implement the `Piwik\Auth`
          * interface in case you want to define your own authentication.
          */
-        Piwik_PostEvent('Request.initAuthenticationObject', array($allowCookieAuthentication = true));
+        Piwik::postEvent('Request.initAuthenticationObject', array($allowCookieAuthentication = true));
 
         $auth = \Piwik\Registry::get('auth');
         $success = Access::getInstance()->reloadAccess($auth);
diff --git a/plugins/PrivacyManager/LogDataPurger.php b/plugins/PrivacyManager/LogDataPurger.php
index 152b71de36..eb95300a07 100755
--- a/plugins/PrivacyManager/LogDataPurger.php
+++ b/plugins/PrivacyManager/LogDataPurger.php
@@ -15,6 +15,7 @@ use Piwik\Common;
 use Piwik\Date;
 use Piwik\Db;
 use Piwik\Log;
+use Piwik\Piwik;
 
 /**
  * Purges the log_visit, log_conversion and related tables of old visit data.
@@ -230,12 +231,12 @@ class LogDataPurger
             /**
              * @ignore
              */
-            Piwik_PostEvent("LogDataPurger.ActionsToKeepInserted.olderThan");
+            Piwik::postEvent("LogDataPurger.ActionsToKeepInserted.olderThan");
         } else {
             /**
              * @ignore
              */
-            Piwik_PostEvent("LogDataPurger.ActionsToKeepInserted.newerThan");
+            Piwik::postEvent("LogDataPurger.ActionsToKeepInserted.newerThan");
         }
     }
 
diff --git a/plugins/Provider/Provider.php b/plugins/Provider/Provider.php
index 79f8b60217..a6b67e68fd 100644
--- a/plugins/Provider/Provider.php
+++ b/plugins/Provider/Provider.php
@@ -17,6 +17,7 @@ use Piwik\Db;
 
 use Piwik\FrontController;
 use Piwik\IP;
+use Piwik\Piwik;
 use Piwik\WidgetsList;
 
 /**
@@ -103,7 +104,7 @@ class Provider extends \Piwik\Plugin
 
     public function postLoad()
     {
-        Piwik_AddAction('Template.footerUserCountry', array('Piwik\Plugins\Provider\Provider', 'footerUserCountry'));
+        Piwik::addAction('Template.footerUserCountry', array('Piwik\Plugins\Provider\Provider', 'footerUserCountry'));
     }
 
     /**
@@ -178,7 +179,7 @@ class Provider extends \Piwik\Plugin
              * }
              * ```
              */
-            Piwik_PostEvent('Provider.getCleanHostname', array(&$cleanHostname, $hostname));
+            Piwik::postEvent('Provider.getCleanHostname', array(&$cleanHostname, $hostname));
             if ($cleanHostname !== null) {
                 return $cleanHostname;
             }
diff --git a/plugins/ScheduledReports/API.php b/plugins/ScheduledReports/API.php
index 3e45c18fde..bdac69a7db 100644
--- a/plugins/ScheduledReports/API.php
+++ b/plugins/ScheduledReports/API.php
@@ -415,7 +415,7 @@ class API
         /**
          * This event allows plugins to alter processed reports.
          */
-        Piwik_PostEvent(
+        Piwik::postEvent(
             self::PROCESS_REPORTS_EVENT,
             array(&$processedReports, $notificationInfo)
         );
@@ -424,7 +424,7 @@ class API
          * This event is triggered to retrieve the report renderer instance.
          */
         $reportRenderer = null;
-        Piwik_PostEvent(
+        Piwik::postEvent(
             self::GET_RENDERER_INSTANCE_EVENT,
             array(&$reportRenderer, $notificationInfo)
         );
@@ -535,7 +535,7 @@ class API
         $contents = fread($handle, filesize($outputFilename));
         fclose($handle);
 
-        Piwik_PostEvent(
+        Piwik::postEvent(
             self::SEND_REPORT_EVENT,
             array(
                  $notificationInfo = array(
@@ -587,7 +587,7 @@ class API
             self::REPORT_TYPE_INFO_KEY => $reportType
         );
 
-        Piwik_PostEvent(self::GET_REPORT_PARAMETERS_EVENT, array(&$availableParameters, $notificationInfo));
+        Piwik::postEvent(self::GET_REPORT_PARAMETERS_EVENT, array(&$availableParameters, $notificationInfo));
 
         // unset invalid parameters
         $availableParameterKeys = array_keys($availableParameters);
@@ -607,7 +607,7 @@ class API
         /**
          * This event is triggered to delegate report parameter validation.
          */
-        Piwik_PostEvent(self::VALIDATE_PARAMETERS_EVENT, array(&$parameters, $notificationInfo));
+        Piwik::postEvent(self::VALIDATE_PARAMETERS_EVENT, array(&$parameters, $notificationInfo));
 
         return Common::json_encode($parameters);
     }
@@ -719,7 +719,7 @@ class API
          * This event is used to retrieve all available reports.
          */
         $availableReportMetadata = array();
-        Piwik_PostEvent(
+        Piwik::postEvent(
             self::GET_REPORT_METADATA_EVENT,
             array(&$availableReportMetadata, $notificationInfo)
         );
@@ -733,7 +733,7 @@ class API
     static public function allowMultipleReports($reportType)
     {
         $allowMultipleReports = null;
-        Piwik_PostEvent(
+        Piwik::postEvent(
             self::ALLOW_MULTIPLE_REPORTS_EVENT,
             array(
                  &$allowMultipleReports,
@@ -751,7 +751,7 @@ class API
     static public function getReportTypes()
     {
         $reportTypes = array();
-        Piwik_PostEvent(self::GET_REPORT_TYPES_EVENT, array(&$reportTypes));
+        Piwik::postEvent(self::GET_REPORT_TYPES_EVENT, array(&$reportTypes));
 
         return $reportTypes;
     }
@@ -763,7 +763,7 @@ class API
     {
         $reportFormats = array();
 
-        Piwik_PostEvent(
+        Piwik::postEvent(
             self::GET_REPORT_FORMATS_EVENT,
             array(
                  &$reportFormats,
@@ -790,7 +790,7 @@ class API
          * This event is used to retrieve the report renderer instance.
          */
         $recipients = array();
-        Piwik_PostEvent(self::GET_REPORT_RECIPIENTS_EVENT, array(&$recipients, $notificationInfo));
+        Piwik::postEvent(self::GET_REPORT_RECIPIENTS_EVENT, array(&$recipients, $notificationInfo));
 
         return $recipients;
     }
diff --git a/plugins/SegmentEditor/API.php b/plugins/SegmentEditor/API.php
index f98d93e72f..e17bbacd19 100644
--- a/plugins/SegmentEditor/API.php
+++ b/plugins/SegmentEditor/API.php
@@ -314,7 +314,7 @@ class API
          * This event is triggered when a segment is deleted or made invisible. It allows plugins to throw an exception
          * or to propagate the action.
          */
-        Piwik_PostEvent(self::DEACTIVATE_SEGMENT_EVENT, array(&$idSegment));
+        Piwik::postEvent(self::DEACTIVATE_SEGMENT_EVENT, array(&$idSegment));
     }
 
     /**
diff --git a/plugins/SitesManager/API.php b/plugins/SitesManager/API.php
index fa322d1ace..00ba33b32f 100644
--- a/plugins/SitesManager/API.php
+++ b/plugins/SitesManager/API.php
@@ -599,7 +599,7 @@ class API
          * values or settings. For instance removing all goals that belong to a specific website. If you store any data
          * related to a website you may want to clean up that information.
          */
-        Piwik_PostEvent('SitesManager.deleteSite.end', array($idSite));
+        Piwik::postEvent('SitesManager.deleteSite.end', array($idSite));
     }
 
     /**
diff --git a/plugins/UserCountryMap/UserCountryMap.php b/plugins/UserCountryMap/UserCountryMap.php
index 61e24df047..8376d9bfa8 100644
--- a/plugins/UserCountryMap/UserCountryMap.php
+++ b/plugins/UserCountryMap/UserCountryMap.php
@@ -11,6 +11,7 @@
 namespace Piwik\Plugins\UserCountryMap;
 
 use Piwik\FrontController;
+use Piwik\Piwik;
 use Piwik\Version;
 use Piwik\WidgetsList;
 
@@ -39,7 +40,7 @@ class UserCountryMap extends \Piwik\Plugin
         WidgetsList::add('General_Visitors', Piwik_Translate('UserCountryMap_VisitorMap'), 'UserCountryMap', 'visitorMap');
         WidgetsList::add('Live!', Piwik_Translate('UserCountryMap_RealTimeMap'), 'UserCountryMap', 'realtimeMap');
 
-        Piwik_AddAction('Template.leftColumnUserCountry', array('Piwik\Plugins\UserCountryMap\UserCountryMap', 'insertMapInLocationReport'));
+        Piwik::addAction('Template.leftColumnUserCountry', array('Piwik\Plugins\UserCountryMap\UserCountryMap', 'insertMapInLocationReport'));
     }
 
     static public function insertMapInLocationReport(&$out)
diff --git a/plugins/UsersManager/API.php b/plugins/UsersManager/API.php
index 98ec5a97df..12a246b5a2 100644
--- a/plugins/UsersManager/API.php
+++ b/plugins/UsersManager/API.php
@@ -402,7 +402,7 @@ class API
          * This event is triggered after a new user is created and saved in the database. `$userLogin` contains all
          * relevant user information like login name, alias, email and transformed password.
          */
-        Piwik_PostEvent('UsersManager.addUser.end', array($userLogin));
+        Piwik::postEvent('UsersManager.addUser.end', array($userLogin));
     }
 
     /**
@@ -463,7 +463,7 @@ class API
          * This event is triggered after an existing user has been updated. `$userLogin` contains the updated user
          * information like login name, alias and email.
          */
-        Piwik_PostEvent('UsersManager.updateUser.end', array($userLogin));
+        Piwik::postEvent('UsersManager.updateUser.end', array($userLogin));
     }
 
     /**
@@ -654,7 +654,7 @@ class API
          * values or settings. For instance removing all created dashboards that belong to a specific user.
          * If you store any data related to a user, you may want to clean up that information.
          */
-        Piwik_PostEvent('UsersManager.deleteUser', array($userLogin));
+        Piwik::postEvent('UsersManager.deleteUser', array($userLogin));
     }
 
     /**
diff --git a/plugins/UsersManager/Controller.php b/plugins/UsersManager/Controller.php
index 3241b7e30f..35954c73cf 100644
--- a/plugins/UsersManager/Controller.php
+++ b/plugins/UsersManager/Controller.php
@@ -338,7 +338,7 @@ class Controller extends Admin
                  * ```
                  * @matt this event is also triggered twice.
                  */
-                Piwik_PostEvent('Login.initSession', array($info));
+                Piwik::postEvent('Login.initSession', array($info));
             }
 
             APIUsersManager::getInstance()->setUserPreference($userLogin,
diff --git a/plugins/VisitorInterest/VisitorInterest.php b/plugins/VisitorInterest/VisitorInterest.php
index 0120720004..4bf80255a9 100644
--- a/plugins/VisitorInterest/VisitorInterest.php
+++ b/plugins/VisitorInterest/VisitorInterest.php
@@ -14,6 +14,7 @@ use Piwik\ArchiveProcessor;
 
 use Piwik\FrontController;
 use Piwik\Metrics;
+use Piwik\Piwik;
 use Piwik\WidgetsList;
 
 /**
@@ -115,8 +116,8 @@ class VisitorInterest extends \Piwik\Plugin
 
     function postLoad()
     {
-        Piwik_AddAction('Template.headerVisitsFrequency', array('Piwik\Plugins\VisitorInterest\VisitorInterest', 'headerVisitsFrequency'));
-        Piwik_AddAction('Template.footerVisitsFrequency', array('Piwik\Plugins\VisitorInterest\VisitorInterest', 'footerVisitsFrequency'));
+        Piwik::addAction('Template.headerVisitsFrequency', array('Piwik\Plugins\VisitorInterest\VisitorInterest', 'headerVisitsFrequency'));
+        Piwik::addAction('Template.footerVisitsFrequency', array('Piwik\Plugins\VisitorInterest\VisitorInterest', 'footerVisitsFrequency'));
     }
 
     public function archivePeriod(ArchiveProcessor\Period $archiveProcessor)
diff --git a/tests/PHPUnit/Core/TaskSchedulerTest.php b/tests/PHPUnit/Core/TaskSchedulerTest.php
index 1ae9ad1eb8..821b45f7e0 100644
--- a/tests/PHPUnit/Core/TaskSchedulerTest.php
+++ b/tests/PHPUnit/Core/TaskSchedulerTest.php
@@ -288,7 +288,7 @@ class TaskSchedulerTest extends PHPUnit_Framework_TestCase
         \Piwik\PluginsManager::getInstance()->unloadPlugins();
         
         // make sure the get tasks event returns our configured tasks
-        Piwik_AddAction(TaskScheduler::GET_TASKS_EVENT, function(&$tasks) use($configuredTasks) {
+        Piwik::addAction(TaskScheduler::GET_TASKS_EVENT, function(&$tasks) use($configuredTasks) {
             $tasks = $configuredTasks;
         });
 
diff --git a/tests/PHPUnit/Integration/ArchiveCronTest.php b/tests/PHPUnit/Integration/ArchiveCronTest.php
index ddfa87cfb2..89f90c57df 100644
--- a/tests/PHPUnit/Integration/ArchiveCronTest.php
+++ b/tests/PHPUnit/Integration/ArchiveCronTest.php
@@ -20,7 +20,7 @@ class Test_Piwik_Integration_ArchiveCronTest extends IntegrationTestCase
     public static function createAccessInstance()
     {
         Access::setSingletonInstance($access = new Test_Access_OverrideLogin());
-        Piwik_PostEvent('Request.initAuthenticationObject');
+        Piwik::postEvent('Request.initAuthenticationObject');
     }
     
     public function getApiForTesting()
diff --git a/tests/PHPUnit/IntegrationTestCase.php b/tests/PHPUnit/IntegrationTestCase.php
index 9f60838c97..799ad6eaa3 100755
--- a/tests/PHPUnit/IntegrationTestCase.php
+++ b/tests/PHPUnit/IntegrationTestCase.php
@@ -57,7 +57,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
     {
         Access::setSingletonInstance(null);
         Access::getInstance();
-        Piwik_PostEvent('Request.initAuthenticationObject');
+        Piwik::postEvent('Request.initAuthenticationObject');
     }
     
     /**
diff --git a/tests/PHPUnit/Plugins/PrivacyManagerTest.php b/tests/PHPUnit/Plugins/PrivacyManagerTest.php
index 8094496109..70100d265e 100755
--- a/tests/PHPUnit/Plugins/PrivacyManagerTest.php
+++ b/tests/PHPUnit/Plugins/PrivacyManagerTest.php
@@ -512,7 +512,7 @@ class PrivacyManagerTest extends IntegrationTestCase
      */
     public function testPurgeLogDataConcurrency()
     {
-        Piwik_AddAction("LogDataPurger.ActionsToKeepInserted.olderThan", array($this, 'addReferenceToUnusedAction'));
+        Piwik::addAction("LogDataPurger.ActionsToKeepInserted.olderThan", array($this, 'addReferenceToUnusedAction'));
 
         $purger = LogDataPurger::make($this->settings, true);
 
diff --git a/tests/PHPUnit/TestingEnvironment.php b/tests/PHPUnit/TestingEnvironment.php
index 6709946988..fa43514d92 100644
--- a/tests/PHPUnit/TestingEnvironment.php
+++ b/tests/PHPUnit/TestingEnvironment.php
@@ -37,11 +37,11 @@ class Piwik_TestingEnvironment
 {
     public static function addHooks()
     {
-        Piwik_AddAction('Access.createAccessSingleton', function($access) {
+        Piwik::addAction('Access.createAccessSingleton', function($access) {
             $access = new Piwik_MockAccess($access);
             \Piwik\Access::setSingletonInstance($access);
         });
-        Piwik_AddAction('Config.createConfigSingleton', function($config) {
+        Piwik::addAction('Config.createConfigSingleton', function($config) {
             \Piwik\CacheFile::$invalidateOpCacheBeforeRead = true;
 
             $config->setTestEnvironment();
@@ -60,15 +60,15 @@ class Piwik_TestingEnvironment
             $config->General['session_save_handler'] = 'dbtables'; // to avoid weird session error in travis
             $config->superuser['email'] = 'hello@example.org';
         });
-        Piwik_AddAction('Request.dispatch', function() {
+        Piwik::addAction('Request.dispatch', function() {
             \Piwik\Plugins\CoreVisualizations\Visualizations\Cloud::$debugDisableShuffle = true;
             \Piwik\Visualization\Sparkline::$enableSparklineImages = false;
             \Piwik\Plugins\ExampleUI\API::$disableRandomness = true;
         });
-        Piwik_AddAction('AssetManager.getStylesheetFiles', function(&$stylesheets) {
+        Piwik::addAction('AssetManager.getStylesheetFiles', function(&$stylesheets) {
             $stylesheets[] = 'tests/resources/screenshot-override/override.css';
         });
-        Piwik_AddAction('AssetManager.getJavaScriptFiles', function(&$jsFiles) {
+        Piwik::addAction('AssetManager.getJavaScriptFiles', function(&$jsFiles) {
             $jsFiles[] = 'tests/resources/screenshot-override/jquery.waitforimages.js';
             $jsFiles[] = 'tests/resources/screenshot-override/override.js';
         });
diff --git a/tests/PHPUnit/UITest.php b/tests/PHPUnit/UITest.php
index bc8643607d..eb94d75467 100644
--- a/tests/PHPUnit/UITest.php
+++ b/tests/PHPUnit/UITest.php
@@ -24,7 +24,7 @@ abstract class UITest extends IntegrationTestCase
     public static function createAccessInstance()
     {
         Access::setSingletonInstance($access = new Test_Access_OverrideLogin());
-        Piwik_PostEvent('Request.initAuthenticationObject');
+        Piwik::postEvent('Request.initAuthenticationObject');
     }
     
     public static function setUpBeforeClass()
-- 
GitLab