Skip to content

Commit b5a7ee8

Browse files
committed
feat(plugins): added plugin administration backend
1 parent 889f339 commit b5a7ee8

File tree

13 files changed

+145
-3
lines changed

13 files changed

+145
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This is a log of major user-visible changes in each phpMyFAQ release.
1111
- added configuration to edit robots.txt (Thorsten)
1212
- added Symfony Routing for administration backend (Thorsten)
1313
- added code snippets plugin with syntax highlighting in WYSIWYG editor (Thorsten)
14+
- added plugin administration backend (Thorsten)
1415
- improved online update feature (Thorsten)
1516
- migrated from WYSIWYG editor from TinyMCE to Jodit Editor (Thorsten)
1617
- migrated from Webpack to Vite v6 (Thorsten)

phpmyfaq/assets/templates/admin/configuration/elasticsearch.twig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<h1 class="h2">
66
<i aria-hidden="true" class="bi bi-wrench"></i>
77
{{ 'msgAdminHeaderElasticsearch' | translate }}
8-
<?= Translation::get('msgAdminHeaderElasticsearch') ?>
98
</h1>
109
<div class="btn-toolbar mb-2 mb-md-0">
1110
<div class="btn-group mr-2">
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{% extends '@admin/index.twig' %}
2+
3+
{% block content %}
4+
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
5+
<h1 class="h2">
6+
<i aria-hidden="true" class="bi bi-wrench"></i>
7+
{{ 'msgPlugins' | translate }}
8+
</h1>
9+
</div>
10+
11+
<div class="row">
12+
<div class="col-lg-12">
13+
14+
<p>
15+
{{ 'msgPluginListing' | translate }}
16+
</p>
17+
18+
<table class="table table-striped">
19+
<thead>
20+
<tr>
21+
<th>{{ 'msgPluginName' | translate }}</th>
22+
<th>{{ 'msgPluginVersion' | translate }}</th>
23+
<th>{{ 'msgPluginAuthor' | translate }}</th>
24+
<th>{{ 'msgPluginDescription' | translate }}</th>
25+
</tr>
26+
</thead>
27+
<tbody>
28+
{% for plugin in pluginList %}
29+
<tr>
30+
<td>{{ plugin.name }}</td>
31+
<td>{{ plugin.version }}</td>
32+
<td>{{ plugin.author }}</td>
33+
<td>{{ plugin.description }}</td>
34+
</tr>
35+
{% endfor %}
36+
</tbody>
37+
</table>
38+
39+
</div>
40+
</div>
41+
42+
{% endblock %}
43+

phpmyfaq/content/plugins/HelloWorld/HelloWorldPlugin.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,17 @@ public function getName(): string
3232

3333
public function getVersion(): string
3434
{
35-
return '0.1.0';
35+
return '0.2.0';
36+
}
37+
38+
public function getDescription(): string
39+
{
40+
return 'A simple Hello World plugin';
41+
}
42+
43+
public function getAuthor(): string
44+
{
45+
return 'phpMyFAQ Team';
3646
}
3747

3848
public function getDependencies(): array

phpmyfaq/src/admin-routes.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use phpMyFAQ\Controller\Administration\NewsController;
3535
use phpMyFAQ\Controller\Administration\OpenQuestionsController;
3636
use phpMyFAQ\Controller\Administration\PasswordChangeController;
37+
use phpMyFAQ\Controller\Administration\PluginController;
3738
use phpMyFAQ\Controller\Administration\RatingController;
3839
use phpMyFAQ\Controller\Administration\ReportController;
3940
use phpMyFAQ\Controller\Administration\SessionKeepAliveController;
@@ -152,6 +153,11 @@
152153
'controller' => [ConfigurationController::class, 'index'],
153154
'methods' => 'GET'
154155
],
156+
'admin.configuration.plugins' => [
157+
'path' => '/plugins',
158+
'controller' => [PluginController::class, 'index'],
159+
'methods' => 'GET'
160+
],
155161
'admin.dashboard' => [
156162
'path' => '/',
157163
'controller' => [DashboardController::class, 'index'],

phpmyfaq/src/phpMyFAQ/Controller/Administration/AbstractAdministrationController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ private function getSecondLevelEntries(Helper $adminHelper): array
222222
'msgAdminHeaderUpdate',
223223
'update'
224224
);
225+
$secLevelEntries['config'] .= $adminHelper->addMenuEntry(
226+
PermissionType::CONFIGURATION_EDIT->value,
227+
'msgPlugins',
228+
'plugins'
229+
);
225230
if ($this->configuration->get('search.enableElasticsearch')) {
226231
$secLevelEntries['config'] .= $adminHelper->addMenuEntry(
227232
PermissionType::CONFIGURATION_EDIT->value,
@@ -314,6 +319,7 @@ private function getPageFlags(Request $request): array
314319
case 'admin.instances':
315320
case 'admin.stopwords':
316321
case 'admin.system':
322+
case 'admin.configuration.plugins':
317323
case 'admin.update':
318324
$configurationPage = true;
319325
break;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace phpMyFAQ\Controller\Administration;
6+
7+
use phpMyFAQ\Core\Exception;
8+
use phpMyFAQ\Plugin\PluginException;
9+
use Symfony\Component\HttpFoundation\Request;
10+
use Symfony\Component\HttpFoundation\Response;
11+
use Symfony\Component\Routing\Attribute\Route;
12+
use Twig\Error\LoaderError;
13+
14+
class PluginController extends AbstractAdministrationController
15+
{
16+
/**
17+
* @throws PluginException
18+
* @throws LoaderError
19+
* @throws Exception
20+
* @throws \Exception
21+
*/
22+
#[Route('/plugins')]
23+
public function index(Request $request): Response
24+
{
25+
$pluginManager = $this->container->get('phpmyfaq.plugin.plugin-manager');
26+
$pluginManager->loadPlugins();
27+
28+
return $this->render(
29+
'@admin/configuration/plugins.twig',
30+
[
31+
... $this->getHeader($request),
32+
... $this->getFooter(),
33+
'pluginList' => $pluginManager->getPlugins(),
34+
]
35+
);
36+
}
37+
}

phpmyfaq/src/phpMyFAQ/Plugin/PluginInterface.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@ public function getName(): string;
3535
*/
3636
public function getVersion(): string;
3737

38+
/**
39+
* Returns the description of the plugin
40+
*
41+
* @return string
42+
*/
43+
public function getDescription(): string;
44+
45+
/**
46+
* Returns the author of the plugin
47+
*
48+
* @return string
49+
*/
50+
public function getAuthor(): string;
51+
3852
/**
3953
* Returns the dependencies of the plugin
4054
*

phpmyfaq/src/phpMyFAQ/System.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class System
6262
/**
6363
* Plugin version.
6464
*/
65-
private const PLUGIN_VERSION = '0.1.0';
65+
private const PLUGIN_VERSION = '0.2.0';
6666

6767
/**
6868
* Minimum required PHP version.

phpmyfaq/src/services.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
use phpMyFAQ\Language;
4848
use phpMyFAQ\News;
4949
use phpMyFAQ\Notification;
50+
use phpMyFAQ\Plugin\PluginManager;
51+
use phpMyFAQ\Plugins;
5052
use phpMyFAQ\Question;
5153
use phpMyFAQ\Rating;
5254
use phpMyFAQ\Search;
@@ -248,6 +250,8 @@
248250
new Reference('phpmyfaq.configuration')
249251
]);
250252

253+
$services->set('phpmyfaq.plugin.plugin-manager', PluginManager::class);
254+
251255
$services->set('phpmyfaq.question', Question::class)
252256
->args([
253257
new Reference('phpmyfaq.configuration')

0 commit comments

Comments
 (0)