Newer
Older
mattpiwik
a validé
<?php
/**
* Piwik - Open source web analytics
mattpiwik
a validé
* @link http://piwik.org
mattpiwik
a validé
* @package Piwik
*/
namespace Piwik;
use Piwik\Plugin\MetadataLoader;
mattpiwik
a validé
*/
require_once PIWIK_INCLUDE_PATH . '/core/Plugin/MetadataLoader.php';
mattpiwik
a validé
/**
* Abstract class to define a Plugin.
mattpiwik
a validé
* Any plugin has to at least implement the abstract methods of this class.
mattpiwik
a validé
* @package Piwik
*/
class Plugin
mattpiwik
a validé
{
Benaka Moorthi
a validé
/**
* Name of this plugin.
*
Benaka Moorthi
a validé
* @var string
*/
protected $pluginName;
Benaka Moorthi
a validé
/**
* Holds plugin metadata.
*
Benaka Moorthi
a validé
* @var array
*/
private $pluginInformation;
Benaka Moorthi
a validé
/**
* Constructor.
*
Benaka Moorthi
a validé
* @param string|bool $pluginName A plugin name to force. If not supplied, it is set
* to last part of the class name.
Benaka Moorthi
a validé
*/
public function __construct($pluginName = false)
{
if (empty($pluginName)) {
mattab
a validé
$pluginName = explode('\\', get_class($this));
$pluginName = end($pluginName);
Benaka Moorthi
a validé
}
$this->pluginName = $pluginName;
$metadataLoader = new MetadataLoader($pluginName);
Benaka Moorthi
a validé
$this->pluginInformation = $metadataLoader->load();
Thomas Steur
a validé
if ($this->hasDefinedPluginInformationInPluginClass() && $metadataLoader->hasPluginJson()) {
throw new \Exception('Plugin ' . $pluginName . ' has defined the method getInformation() and as well as having a plugin.json file. Please delete the getInformation() method from the plugin class.');
}
}
private function hasDefinedPluginInformationInPluginClass()
{
$myClassName = get_class();
$pluginClassName = get_class($this);
if ($pluginClassName == $myClassName) {
// plugin has not defined its own class
return false;
}
$foo = new \ReflectionMethod(get_class($this), 'getInformation');
$declaringClass = $foo->getDeclaringClass()->getName();
return $declaringClass != $myClassName;
Benaka Moorthi
a validé
}
/**
* Returns the plugin details
* - 'description' => string // 1-2 sentence description of the plugin
* - 'author' => string // plugin author
* - 'author_homepage' => string // author homepage URL (or email "mailto:youremail@example.org")
* - 'homepage' => string // plugin homepage URL
* - 'license' => string // plugin license
* - 'license_homepage' => string // license homepage URL
* - 'version' => string // plugin version number; examples and 3rd party plugins must not use Version::VERSION; 3rd party plugins must increment the version number with each plugin release
* - 'theme' => bool // Whether this plugin is a theme (a theme is a plugin, but a plugin is not necessarily a theme)
*
* @return array
*/
Benaka Moorthi
a validé
return $this->pluginInformation;
/**
* Returns the list of hooks registered with the methods names
*
* @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()
{
return array();
}
/**
* Executed after loading plugin and registering translations
* Useful for code that uses translated strings from the plugin.
*/
public function postLoad()
{
return;
}
robocoder
a validé
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**
* Install the plugin
* - create tables
* - update existing tables
* - etc.
*/
public function install()
{
return;
}
/**
* Remove the created resources during the install
*/
public function uninstall()
{
return;
}
/**
* Executed every time the plugin is enabled
*/
public function activate()
{
return;
}
/**
* Executed every time the plugin is disabled
*/
public function deactivate()
{
return;
}
/**
* Returns the plugin version number
*
* @return string
*/
{
$info = $this->getInformation();
return $info['version'];
}
/**
* Whether this plugin is a theme
*
* @return bool
*/
final public function isTheme()
{
$info = $this->getInformation();
return !empty($info['theme']) && (bool)$info['theme'];
}
/**
* Returns the plugin's base class name without the "Piwik_" prefix,
mattab
a validé
* e.g., "UserCountry" when the plugin class is "UserCountry"
*
* @return string
*/
final public function getPluginName()
{