diff options
22 files changed, 65 insertions, 41 deletions
diff --git a/application/PluginManager.php b/application/plugin/PluginManager.php index 1ed4db4b..f7b24a8e 100644 --- a/application/PluginManager.php +++ b/application/plugin/PluginManager.php | |||
@@ -1,4 +1,8 @@ | |||
1 | <?php | 1 | <?php |
2 | namespace Shaarli\Plugin; | ||
3 | |||
4 | use Shaarli\Config\ConfigManager; | ||
5 | use Shaarli\Plugin\Exception\PluginFileNotFoundException; | ||
2 | 6 | ||
3 | /** | 7 | /** |
4 | * Class PluginManager | 8 | * Class PluginManager |
@@ -9,12 +13,14 @@ class PluginManager | |||
9 | { | 13 | { |
10 | /** | 14 | /** |
11 | * List of authorized plugins from configuration file. | 15 | * List of authorized plugins from configuration file. |
16 | * | ||
12 | * @var array $authorizedPlugins | 17 | * @var array $authorizedPlugins |
13 | */ | 18 | */ |
14 | private $authorizedPlugins; | 19 | private $authorizedPlugins; |
15 | 20 | ||
16 | /** | 21 | /** |
17 | * List of loaded plugins. | 22 | * List of loaded plugins. |
23 | * | ||
18 | * @var array $loadedPlugins | 24 | * @var array $loadedPlugins |
19 | */ | 25 | */ |
20 | private $loadedPlugins = array(); | 26 | private $loadedPlugins = array(); |
@@ -31,12 +37,14 @@ class PluginManager | |||
31 | 37 | ||
32 | /** | 38 | /** |
33 | * Plugins subdirectory. | 39 | * Plugins subdirectory. |
40 | * | ||
34 | * @var string $PLUGINS_PATH | 41 | * @var string $PLUGINS_PATH |
35 | */ | 42 | */ |
36 | public static $PLUGINS_PATH = 'plugins'; | 43 | public static $PLUGINS_PATH = 'plugins'; |
37 | 44 | ||
38 | /** | 45 | /** |
39 | * Plugins meta files extension. | 46 | * Plugins meta files extension. |
47 | * | ||
40 | * @var string $META_EXT | 48 | * @var string $META_EXT |
41 | */ | 49 | */ |
42 | public static $META_EXT = 'meta'; | 50 | public static $META_EXT = 'meta'; |
@@ -84,9 +92,9 @@ class PluginManager | |||
84 | /** | 92 | /** |
85 | * Execute all plugins registered hook. | 93 | * Execute all plugins registered hook. |
86 | * | 94 | * |
87 | * @param string $hook name of the hook to trigger. | 95 | * @param string $hook name of the hook to trigger. |
88 | * @param array $data list of data to manipulate passed by reference. | 96 | * @param array $data list of data to manipulate passed by reference. |
89 | * @param array $params additional parameters such as page target. | 97 | * @param array $params additional parameters such as page target. |
90 | * | 98 | * |
91 | * @return void | 99 | * @return void |
92 | */ | 100 | */ |
@@ -118,7 +126,7 @@ class PluginManager | |||
118 | * @param string $pluginName plugin's name. | 126 | * @param string $pluginName plugin's name. |
119 | * | 127 | * |
120 | * @return void | 128 | * @return void |
121 | * @throws PluginFileNotFoundException - plugin files not found. | 129 | * @throws \Shaarli\Plugin\Exception\PluginFileNotFoundException - plugin files not found. |
122 | */ | 130 | */ |
123 | private function loadPlugin($dir, $pluginName) | 131 | private function loadPlugin($dir, $pluginName) |
124 | { | 132 | { |
@@ -204,8 +212,8 @@ class PluginManager | |||
204 | 212 | ||
205 | $metaData[$plugin]['parameters'][$param]['value'] = ''; | 213 | $metaData[$plugin]['parameters'][$param]['value'] = ''; |
206 | // Optional parameter description in parameter.PARAM_NAME= | 214 | // Optional parameter description in parameter.PARAM_NAME= |
207 | if (isset($metaData[$plugin]['parameter.'. $param])) { | 215 | if (isset($metaData[$plugin]['parameter.' . $param])) { |
208 | $metaData[$plugin]['parameters'][$param]['desc'] = t($metaData[$plugin]['parameter.'. $param]); | 216 | $metaData[$plugin]['parameters'][$param]['desc'] = t($metaData[$plugin]['parameter.' . $param]); |
209 | } | 217 | } |
210 | } | 218 | } |
211 | } | 219 | } |
@@ -223,22 +231,3 @@ class PluginManager | |||
223 | return $this->errors; | 231 | return $this->errors; |
224 | } | 232 | } |
225 | } | 233 | } |
226 | |||
227 | /** | ||
228 | * Class PluginFileNotFoundException | ||
229 | * | ||
230 | * Raise when plugin files can't be found. | ||
231 | */ | ||
232 | class PluginFileNotFoundException extends Exception | ||
233 | { | ||
234 | /** | ||
235 | * Construct exception with plugin name. | ||
236 | * Generate message. | ||
237 | * | ||
238 | * @param string $pluginName name of the plugin not found | ||
239 | */ | ||
240 | public function __construct($pluginName) | ||
241 | { | ||
242 | $this->message = sprintf(t('Plugin "%s" files not found.'), $pluginName); | ||
243 | } | ||
244 | } | ||
diff --git a/application/plugin/exception/PluginFileNotFoundException.php b/application/plugin/exception/PluginFileNotFoundException.php new file mode 100644 index 00000000..e5386f02 --- /dev/null +++ b/application/plugin/exception/PluginFileNotFoundException.php | |||
@@ -0,0 +1,23 @@ | |||
1 | <?php | ||
2 | namespace Shaarli\Plugin\Exception; | ||
3 | |||
4 | use Exception; | ||
5 | |||
6 | /** | ||
7 | * Class PluginFileNotFoundException | ||
8 | * | ||
9 | * Raise when plugin files can't be found. | ||
10 | */ | ||
11 | class PluginFileNotFoundException extends Exception | ||
12 | { | ||
13 | /** | ||
14 | * Construct exception with plugin name. | ||
15 | * Generate message. | ||
16 | * | ||
17 | * @param string $pluginName name of the plugin not found | ||
18 | */ | ||
19 | public function __construct($pluginName) | ||
20 | { | ||
21 | $this->message = sprintf(t('Plugin "%s" files not found.'), $pluginName); | ||
22 | } | ||
23 | } | ||
diff --git a/composer.json b/composer.json index c1f47317..a2df466a 100644 --- a/composer.json +++ b/composer.json | |||
@@ -46,6 +46,8 @@ | |||
46 | "Shaarli\\Feed\\": "application/feed", | 46 | "Shaarli\\Feed\\": "application/feed", |
47 | "Shaarli\\Http\\": "application/http", | 47 | "Shaarli\\Http\\": "application/http", |
48 | "Shaarli\\Netscape\\": "application/netscape", | 48 | "Shaarli\\Netscape\\": "application/netscape", |
49 | "Shaarli\\Plugin\\": "application/plugin", | ||
50 | "Shaarli\\Plugin\\Exception\\": "application/plugin/exception", | ||
49 | "Shaarli\\Render\\": "application/render", | 51 | "Shaarli\\Render\\": "application/render", |
50 | "Shaarli\\Security\\": "application/security", | 52 | "Shaarli\\Security\\": "application/security", |
51 | "Shaarli\\Updater\\": "application/updater", | 53 | "Shaarli\\Updater\\": "application/updater", |
@@ -65,7 +65,6 @@ require_once 'application/updater/UpdaterUtils.php'; | |||
65 | require_once 'application/FileUtils.php'; | 65 | require_once 'application/FileUtils.php'; |
66 | require_once 'application/TimeZone.php'; | 66 | require_once 'application/TimeZone.php'; |
67 | require_once 'application/Utils.php'; | 67 | require_once 'application/Utils.php'; |
68 | require_once 'application/PluginManager.php'; | ||
69 | 68 | ||
70 | use \Shaarli\ApplicationUtils; | 69 | use \Shaarli\ApplicationUtils; |
71 | use \Shaarli\Bookmark\Exception\LinkNotFoundException; | 70 | use \Shaarli\Bookmark\Exception\LinkNotFoundException; |
@@ -76,6 +75,7 @@ use \Shaarli\Feed\FeedBuilder; | |||
76 | use \Shaarli\History; | 75 | use \Shaarli\History; |
77 | use \Shaarli\Languages; | 76 | use \Shaarli\Languages; |
78 | use \Shaarli\Netscape\NetscapeBookmarkUtils; | 77 | use \Shaarli\Netscape\NetscapeBookmarkUtils; |
78 | use \Shaarli\Plugin\PluginManager; | ||
79 | use \Shaarli\Render\PageBuilder; | 79 | use \Shaarli\Render\PageBuilder; |
80 | use \Shaarli\Render\ThemeUtils; | 80 | use \Shaarli\Render\ThemeUtils; |
81 | use \Shaarli\Router; | 81 | use \Shaarli\Router; |
diff --git a/plugins/archiveorg/archiveorg.php b/plugins/archiveorg/archiveorg.php index 5dcea5a6..0ee1c73c 100644 --- a/plugins/archiveorg/archiveorg.php +++ b/plugins/archiveorg/archiveorg.php | |||
@@ -5,6 +5,8 @@ | |||
5 | * Add an icon in the link list for archive.org. | 5 | * Add an icon in the link list for archive.org. |
6 | */ | 6 | */ |
7 | 7 | ||
8 | use Shaarli\Plugin\PluginManager; | ||
9 | |||
8 | /** | 10 | /** |
9 | * Add archive.org icon to link_plugin when rendering linklist. | 11 | * Add archive.org icon to link_plugin when rendering linklist. |
10 | * | 12 | * |
diff --git a/plugins/demo_plugin/demo_plugin.php b/plugins/demo_plugin/demo_plugin.php index 94ce38f8..95ea7fe2 100644 --- a/plugins/demo_plugin/demo_plugin.php +++ b/plugins/demo_plugin/demo_plugin.php | |||
@@ -15,6 +15,7 @@ | |||
15 | */ | 15 | */ |
16 | 16 | ||
17 | use Shaarli\Config\ConfigManager; | 17 | use Shaarli\Config\ConfigManager; |
18 | use Shaarli\Plugin\PluginManager; | ||
18 | use Shaarli\Router; | 19 | use Shaarli\Router; |
19 | 20 | ||
20 | /** | 21 | /** |
diff --git a/plugins/isso/isso.php b/plugins/isso/isso.php index 9bdd5909..dab75dd5 100644 --- a/plugins/isso/isso.php +++ b/plugins/isso/isso.php | |||
@@ -5,6 +5,7 @@ | |||
5 | */ | 5 | */ |
6 | 6 | ||
7 | use Shaarli\Config\ConfigManager; | 7 | use Shaarli\Config\ConfigManager; |
8 | use Shaarli\Plugin\PluginManager; | ||
8 | use Shaarli\Router; | 9 | use Shaarli\Router; |
9 | 10 | ||
10 | /** | 11 | /** |
diff --git a/plugins/markdown/markdown.php b/plugins/markdown/markdown.php index 9928a488..628970d6 100644 --- a/plugins/markdown/markdown.php +++ b/plugins/markdown/markdown.php | |||
@@ -7,6 +7,7 @@ | |||
7 | */ | 7 | */ |
8 | 8 | ||
9 | use Shaarli\Config\ConfigManager; | 9 | use Shaarli\Config\ConfigManager; |
10 | use Shaarli\Plugin\PluginManager; | ||
10 | use Shaarli\Router; | 11 | use Shaarli\Router; |
11 | 12 | ||
12 | /* | 13 | /* |
diff --git a/plugins/piwik/piwik.php b/plugins/piwik/piwik.php index ca00c2be..17b1aecc 100644 --- a/plugins/piwik/piwik.php +++ b/plugins/piwik/piwik.php | |||
@@ -4,6 +4,8 @@ | |||
4 | * Adds tracking code on each page. | 4 | * Adds tracking code on each page. |
5 | */ | 5 | */ |
6 | 6 | ||
7 | use Shaarli\Plugin\PluginManager; | ||
8 | |||
7 | /** | 9 | /** |
8 | * Initialization function. | 10 | * Initialization function. |
9 | * It will be called when the plugin is loaded. | 11 | * It will be called when the plugin is loaded. |
diff --git a/plugins/playvideos/playvideos.php b/plugins/playvideos/playvideos.php index bb5b9e98..0341ed59 100644 --- a/plugins/playvideos/playvideos.php +++ b/plugins/playvideos/playvideos.php | |||
@@ -6,6 +6,7 @@ | |||
6 | * Note: this plugin adds jQuery. | 6 | * Note: this plugin adds jQuery. |
7 | */ | 7 | */ |
8 | 8 | ||
9 | use Shaarli\Plugin\PluginManager; | ||
9 | use Shaarli\Router; | 10 | use Shaarli\Router; |
10 | 11 | ||
11 | /** | 12 | /** |
diff --git a/plugins/pubsubhubbub/pubsubhubbub.php b/plugins/pubsubhubbub/pubsubhubbub.php index a7bd34c1..2878c050 100644 --- a/plugins/pubsubhubbub/pubsubhubbub.php +++ b/plugins/pubsubhubbub/pubsubhubbub.php | |||
@@ -12,6 +12,7 @@ | |||
12 | use pubsubhubbub\publisher\Publisher; | 12 | use pubsubhubbub\publisher\Publisher; |
13 | use Shaarli\Config\ConfigManager; | 13 | use Shaarli\Config\ConfigManager; |
14 | use Shaarli\Feed\FeedBuilder; | 14 | use Shaarli\Feed\FeedBuilder; |
15 | use Shaarli\Plugin\PluginManager; | ||
15 | use Shaarli\Router; | 16 | use Shaarli\Router; |
16 | 17 | ||
17 | /** | 18 | /** |
diff --git a/plugins/qrcode/qrcode.php b/plugins/qrcode/qrcode.php index 21908cee..34eef8be 100644 --- a/plugins/qrcode/qrcode.php +++ b/plugins/qrcode/qrcode.php | |||
@@ -5,6 +5,7 @@ | |||
5 | * Display a QRCode icon in link list. | 5 | * Display a QRCode icon in link list. |
6 | */ | 6 | */ |
7 | 7 | ||
8 | use Shaarli\Plugin\PluginManager; | ||
8 | use Shaarli\Router; | 9 | use Shaarli\Router; |
9 | 10 | ||
10 | /** | 11 | /** |
diff --git a/plugins/wallabag/wallabag.php b/plugins/wallabag/wallabag.php index a6476c71..5ba1611d 100644 --- a/plugins/wallabag/wallabag.php +++ b/plugins/wallabag/wallabag.php | |||
@@ -6,6 +6,7 @@ | |||
6 | 6 | ||
7 | require_once 'WallabagInstance.php'; | 7 | require_once 'WallabagInstance.php'; |
8 | use Shaarli\Config\ConfigManager; | 8 | use Shaarli\Config\ConfigManager; |
9 | use Shaarli\Plugin\PluginManager; | ||
9 | 10 | ||
10 | /** | 11 | /** |
11 | * Init function, return an error if the server is not set. | 12 | * Init function, return an error if the server is not set. |
diff --git a/tests/PluginManagerTest.php b/tests/PluginManagerTest.php index 01de959c..71761ac1 100644 --- a/tests/PluginManagerTest.php +++ b/tests/PluginManagerTest.php | |||
@@ -1,16 +1,12 @@ | |||
1 | <?php | 1 | <?php |
2 | use Shaarli\Config\ConfigManager; | 2 | namespace Shaarli\Plugin; |
3 | 3 | ||
4 | /** | 4 | use Shaarli\Config\ConfigManager; |
5 | * Plugin Manager tests | ||
6 | */ | ||
7 | |||
8 | require_once 'application/PluginManager.php'; | ||
9 | 5 | ||
10 | /** | 6 | /** |
11 | * Unit tests for Plugins | 7 | * Unit tests for Plugins |
12 | */ | 8 | */ |
13 | class PluginManagerTest extends PHPUnit_Framework_TestCase | 9 | class PluginManagerTest extends \PHPUnit\Framework\TestCase |
14 | { | 10 | { |
15 | /** | 11 | /** |
16 | * Path to tests plugin. | 12 | * Path to tests plugin. |
diff --git a/tests/plugins/PluginAddlinkTest.php b/tests/plugins/PluginAddlinkTest.php index f6fea7af..e0a0107d 100644 --- a/tests/plugins/PluginAddlinkTest.php +++ b/tests/plugins/PluginAddlinkTest.php | |||
@@ -1,19 +1,14 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | /** | 3 | use Shaarli\Plugin\PluginManager; |
4 | * PluginPlayvideosTest.php | ||
5 | */ | ||
6 | |||
7 | use Shaarli\Router; | 4 | use Shaarli\Router; |
8 | 5 | ||
9 | require_once 'plugins/addlink_toolbar/addlink_toolbar.php'; | 6 | require_once 'plugins/addlink_toolbar/addlink_toolbar.php'; |
10 | require_once 'application/Router.php'; | ||
11 | 7 | ||
12 | /** | 8 | /** |
13 | * Class PluginAddlinkTest | ||
14 | * Unit test for the Addlink toolbar plugin | 9 | * Unit test for the Addlink toolbar plugin |
15 | */ | 10 | */ |
16 | class PluginAddlinkTest extends PHPUnit_Framework_TestCase | 11 | class PluginAddlinkTest extends \PHPUnit\Framework\TestCase |
17 | { | 12 | { |
18 | /** | 13 | /** |
19 | * Reset plugin path. | 14 | * Reset plugin path. |
diff --git a/tests/plugins/PluginArchiveorgTest.php b/tests/plugins/PluginArchiveorgTest.php index fecd5f2c..d06bfa59 100644 --- a/tests/plugins/PluginArchiveorgTest.php +++ b/tests/plugins/PluginArchiveorgTest.php | |||
@@ -4,6 +4,8 @@ | |||
4 | * PluginArchiveorgTest.php | 4 | * PluginArchiveorgTest.php |
5 | */ | 5 | */ |
6 | 6 | ||
7 | use Shaarli\Plugin\PluginManager; | ||
8 | |||
7 | require_once 'plugins/archiveorg/archiveorg.php'; | 9 | require_once 'plugins/archiveorg/archiveorg.php'; |
8 | 10 | ||
9 | /** | 11 | /** |
diff --git a/tests/plugins/PluginIssoTest.php b/tests/plugins/PluginIssoTest.php index f5fa1daa..7aee2197 100644 --- a/tests/plugins/PluginIssoTest.php +++ b/tests/plugins/PluginIssoTest.php | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | use Shaarli\Bookmark\LinkDB; | 3 | use Shaarli\Bookmark\LinkDB; |
4 | use Shaarli\Config\ConfigManager; | 4 | use Shaarli\Config\ConfigManager; |
5 | use Shaarli\Plugin\PluginManager; | ||
5 | 6 | ||
6 | require_once 'plugins/isso/isso.php'; | 7 | require_once 'plugins/isso/isso.php'; |
7 | 8 | ||
diff --git a/tests/plugins/PluginMarkdownTest.php b/tests/plugins/PluginMarkdownTest.php index d6951866..90a19e7b 100644 --- a/tests/plugins/PluginMarkdownTest.php +++ b/tests/plugins/PluginMarkdownTest.php | |||
@@ -1,5 +1,6 @@ | |||
1 | <?php | 1 | <?php |
2 | use Shaarli\Config\ConfigManager; | 2 | use Shaarli\Config\ConfigManager; |
3 | use Shaarli\Plugin\PluginManager; | ||
3 | 4 | ||
4 | /** | 5 | /** |
5 | * PluginMarkdownTest.php | 6 | * PluginMarkdownTest.php |
diff --git a/tests/plugins/PluginPlayvideosTest.php b/tests/plugins/PluginPlayvideosTest.php index 7ee92400..aa3ad143 100644 --- a/tests/plugins/PluginPlayvideosTest.php +++ b/tests/plugins/PluginPlayvideosTest.php | |||
@@ -4,6 +4,7 @@ | |||
4 | * PluginPlayvideosTest.php | 4 | * PluginPlayvideosTest.php |
5 | */ | 5 | */ |
6 | 6 | ||
7 | use Shaarli\Plugin\PluginManager; | ||
7 | use Shaarli\Router; | 8 | use Shaarli\Router; |
8 | 9 | ||
9 | require_once 'plugins/playvideos/playvideos.php'; | 10 | require_once 'plugins/playvideos/playvideos.php'; |
diff --git a/tests/plugins/PluginPubsubhubbubTest.php b/tests/plugins/PluginPubsubhubbubTest.php index 75f146f2..4680513e 100644 --- a/tests/plugins/PluginPubsubhubbubTest.php +++ b/tests/plugins/PluginPubsubhubbubTest.php | |||
@@ -1,5 +1,6 @@ | |||
1 | <?php | 1 | <?php |
2 | use Shaarli\Config\ConfigManager; | 2 | use Shaarli\Config\ConfigManager; |
3 | use Shaarli\Plugin\PluginManager; | ||
3 | use Shaarli\Router; | 4 | use Shaarli\Router; |
4 | 5 | ||
5 | require_once 'plugins/pubsubhubbub/pubsubhubbub.php'; | 6 | require_once 'plugins/pubsubhubbub/pubsubhubbub.php'; |
diff --git a/tests/plugins/PluginQrcodeTest.php b/tests/plugins/PluginQrcodeTest.php index 419965eb..325e3109 100644 --- a/tests/plugins/PluginQrcodeTest.php +++ b/tests/plugins/PluginQrcodeTest.php | |||
@@ -3,6 +3,7 @@ | |||
3 | * PluginQrcodeTest.php | 3 | * PluginQrcodeTest.php |
4 | */ | 4 | */ |
5 | 5 | ||
6 | use Shaarli\Plugin\PluginManager; | ||
6 | use Shaarli\Router; | 7 | use Shaarli\Router; |
7 | 8 | ||
8 | require_once 'plugins/qrcode/qrcode.php'; | 9 | require_once 'plugins/qrcode/qrcode.php'; |
diff --git a/tests/plugins/PluginWallabagTest.php b/tests/plugins/PluginWallabagTest.php index 76b7887e..4e445efb 100644 --- a/tests/plugins/PluginWallabagTest.php +++ b/tests/plugins/PluginWallabagTest.php | |||
@@ -1,5 +1,6 @@ | |||
1 | <?php | 1 | <?php |
2 | use Shaarli\Config\ConfigManager; | 2 | use Shaarli\Config\ConfigManager; |
3 | use Shaarli\Plugin\PluginManager; | ||
3 | 4 | ||
4 | /** | 5 | /** |
5 | * PluginWallabagTest.php.php | 6 | * PluginWallabagTest.php.php |
@@ -11,7 +12,7 @@ require_once 'plugins/wallabag/wallabag.php'; | |||
11 | * Class PluginWallabagTest | 12 | * Class PluginWallabagTest |
12 | * Unit test for the Wallabag plugin | 13 | * Unit test for the Wallabag plugin |
13 | */ | 14 | */ |
14 | class PluginWallabagTest extends PHPUnit_Framework_TestCase | 15 | class PluginWallabagTest extends \PHPUnit\Framework\TestCase |
15 | { | 16 | { |
16 | /** | 17 | /** |
17 | * Reset plugin path | 18 | * Reset plugin path |