Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authormattab <matthieu.aubry@gmail.com>2013-07-15 12:03:23 +0400
committermattab <matthieu.aubry@gmail.com>2013-07-15 12:03:23 +0400
commit27f7dca5777e6be6e96010b5623b6ef4aec293b8 (patch)
tree252a462ea8961330f4fa89818518fdb02052b19a /core
parent4b7419587bc0b9d02362697ff60bc8c59751dded (diff)
Refs #3942
* Removing getInformation() call from core plugins * Renamed translation key PDFReports_PluginDescriptionReports => PDFReports_PluginDescription
Diffstat (limited to 'core')
-rw-r--r--core/Plugin.php37
-rw-r--r--core/PluginsManager.php68
-rw-r--r--core/Translate.php6
3 files changed, 70 insertions, 41 deletions
diff --git a/core/Plugin.php b/core/Plugin.php
index 811f43eccf..c2e5fafca6 100644
--- a/core/Plugin.php
+++ b/core/Plugin.php
@@ -26,13 +26,31 @@ abstract class Piwik_Plugin
* - 'license' => string // plugin license
* - 'license_homepage' => string // license homepage URL
* - 'version' => string // plugin version number; examples and 3rd party plugins must not use Piwik_Version::VERSION; 3rd party plugins must increment the version number with each plugin release
- * - 'translationAvailable' => bool // is there a translation file in plugins/your-plugin/lang/* ?
- * - 'TrackerPlugin' => bool // should we load this plugin during the stats logging process?
* - 'theme' => bool // Whether this plugin is a theme (a theme is a plugin, but a plugin is not necessarily a theme)
*
* @return array
*/
- abstract public function getInformation();
+ public function getInformation()
+ {
+ $descriptionKey = $this->getPluginName() . '_PluginDescription';
+ $translation = Piwik_Translate($descriptionKey);
+ $info = array(
+ 'description' => $translation,
+ 'homepage' => 'http://piwik.org/',
+ 'author' => 'Piwik',
+ 'author_homepage' => 'http://piwik.org/',
+ 'license' => 'GPL v3 or later',
+ 'license_homepage' => 'http://www.gnu.org/licenses/gpl.html',
+ 'version' => Piwik_Version::VERSION,
+ 'theme' => false,
+ );
+
+ $infoFromJson = Piwik_PluginsManager::getInstance()->loadInfoFromJson($this);
+ if(!empty($infoFromJson)) {
+ $info = array_merge($info, $infoFromJson);
+ }
+ return $info;
+ }
/**
* Returns the list of hooks registered with the methods names
@@ -130,17 +148,4 @@ abstract class Piwik_Plugin
{
return Piwik_Common::unprefixClass(get_class($this));
}
-
- /**
- * Returns the plugin's base class name without the "Piwik_" prefix,
- * e.g., "UserCountry" when the plugin class is "Piwik_UserCountry"
- *
- * @deprecated since 1.2 - for backward compatibility
- *
- * @return string
- */
- final public function getClassName()
- {
- return $this->getPluginName();
- }
}
diff --git a/core/PluginsManager.php b/core/PluginsManager.php
index ab341e5654..bf3cf47bd8 100644
--- a/core/PluginsManager.php
+++ b/core/PluginsManager.php
@@ -53,7 +53,11 @@ class Piwik_PluginsManager
'LanguagesManager',
);
+ // If a plugin hooks onto at least an event starting with "Tracker.", we load the plugin during tracker
+ const TRACKER_EVENT_PREFIX = 'Tracker.';
+
static private $instance = null;
+ const PLUGIN_JSON_FILENAME = 'plugin.piwik.json';
/**
* Returns the singleton Piwik_PluginsManager
@@ -145,7 +149,7 @@ class Piwik_PluginsManager
*/
public function readPluginsDirectory()
{
- $pluginsName = _glob(PIWIK_INCLUDE_PATH . '/plugins/*', GLOB_ONLYDIR);
+ $pluginsName = _glob($this->getPluginsDirectory() . '*', GLOB_ONLYDIR);
$result = array();
if ($pluginsName != false) {
foreach ($pluginsName as $path) {
@@ -159,6 +163,28 @@ class Piwik_PluginsManager
return $result;
}
+ public function loadInfoFromJson(Piwik_Plugin $plugin)
+ {
+ $path = $this->getPluginsDirectory() . $plugin->getPluginName() . '/' . self::PLUGIN_JSON_FILENAME;
+ if(!file_exists($path)) {
+ return false;
+ }
+ $json = file_get_contents($path);
+ if(!$json) {
+ return false;
+ }
+ $info = Piwik_Common::json_decode($json, $assoc = true);
+ if(!is_array($info) || empty($info)) {
+ throw new Exception("Invalid JSON file: $path");
+ }
+ return $info;
+ }
+
+ protected function getPluginsDirectory()
+ {
+ return PIWIK_INCLUDE_PATH . '/plugins/';
+ }
+
/**
* Deactivate plugin
*
@@ -391,7 +417,7 @@ class Piwik_PluginsManager
throw new Exception(sprintf("The plugin filename '%s' is not a valid filename", $pluginFileName));
}
- $path = PIWIK_INCLUDE_PATH . '/plugins/' . $pluginFileName;
+ $path = $this->getPluginsDirectory() . $pluginFileName;
if (!file_exists($path)) {
// ToDo: We should log this - but this will crash in Tracker mode since core/Piwik is not loaded
@@ -413,7 +439,7 @@ class Piwik_PluginsManager
}
$this->addLoadedPlugin($pluginName, $newPlugin);
-
+
Piwik_EventDispatcher::getInstance()->postPendingEventsTo($newPlugin);
return $newPlugin;
@@ -493,7 +519,7 @@ class Piwik_PluginsManager
* @param Piwik_Plugin $plugin
* @param string $langCode
* @throws Exception
- * @return void
+ * @return bool whether the translation was found and loaded
*/
private function loadTranslation($plugin, $langCode)
{
@@ -502,19 +528,9 @@ class Piwik_PluginsManager
return;
}
- $infos = $plugin->getInformation();
- if (!isset($infos['translationAvailable'])) {
- $infos['translationAvailable'] = false;
- }
- $translationAvailable = $infos['translationAvailable'];
-
- if (!$translationAvailable) {
- return;
- }
-
$pluginName = $plugin->getPluginName();
- $path = PIWIK_INCLUDE_PATH . '/plugins/' . $pluginName . '/lang/%s.php';
+ $path = $this->getPluginsDirectory() . $pluginName . '/lang/%s.php';
$defaultLangPath = sprintf($path, $langCode);
$defaultEnglishLangPath = sprintf($path, 'en');
@@ -526,9 +542,10 @@ class Piwik_PluginsManager
} elseif (file_exists($defaultEnglishLangPath)) {
require $defaultEnglishLangPath;
} else {
- throw new Exception("Language file not found for the plugin '$pluginName'.");
+ return false;
}
Piwik_Translate::getInstance()->mergeTranslationArray($translations);
+ return true;
}
/**
@@ -583,12 +600,7 @@ class Piwik_PluginsManager
$saveConfig = true;
}
- $information = $plugin->getInformation();
-
- // if the plugin is to be loaded during the statistics logging
- if (isset($information['TrackerPlugin'])
- && $information['TrackerPlugin'] === true
- ) {
+ if ($this->isTrackerPlugin($plugin)) {
$pluginsTracker = Piwik_Config::getInstance()->Plugins_Tracker['Plugins_Tracker'];
if (is_null($pluginsTracker)) {
$pluginsTracker = array();
@@ -604,6 +616,18 @@ class Piwik_PluginsManager
Piwik_Config::getInstance()->forceSave();
}
}
+
+ protected function isTrackerPlugin(Piwik_Plugin $plugin)
+ {
+ $hooks = $plugin->getListHooksRegistered();
+ $hookNames = array_keys($hooks);
+ foreach ($hookNames as $name) {
+ if (strpos($name, self::TRACKER_EVENT_PREFIX) === 0) {
+ return true;
+ }
+ }
+ return false;
+ }
}
/**
diff --git a/core/Translate.php b/core/Translate.php
index d2b95e700b..177cb64ca7 100644
--- a/core/Translate.php
+++ b/core/Translate.php
@@ -31,7 +31,7 @@ class Piwik_Translate
public function loadEnglishTranslation()
{
- $this->loadTranslation('en');
+ $this->loadCoreTranslationFile('en');
}
public function unloadEnglishTranslation()
@@ -64,10 +64,10 @@ class Piwik_Translate
if ($this->loadedLanguage == $language) {
return;
}
- $this->loadTranslation($language);
+ $this->loadCoreTranslationFile($language);
}
- private function loadTranslation($language)
+ private function loadCoreTranslationFile($language)
{
$translations = array();
$path = PIWIK_INCLUDE_PATH . '/lang/' . $language . '.php';