diff --git a/mod/admin.php b/mod/admin.php index b3933a16bf..22fd5adf3e 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -10,7 +10,6 @@ use Friendica\BaseModule; use Friendica\Content\Feature; use Friendica\Content\Pager; use Friendica\Content\Text\Markdown; -use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\Logger; @@ -91,17 +90,6 @@ function admin_post(App $a) case 'users': admin_page_users_post($a); break; - case 'addons': - if ($a->argc > 2 && - is_file("addon/" . $a->argv[2] . "/" . $a->argv[2] . ".php")) { - include_once "addon/" . $a->argv[2] . "/" . $a->argv[2] . ".php"; - if (function_exists($a->argv[2] . '_addon_admin_post')) { - $func = $a->argv[2] . '_addon_admin_post'; - $func($a); - } - } - $return_path = 'admin/addons/' . $a->argv[2]; - break; case 'themes': if ($a->argc < 2) { if ($a->isAjax()) { @@ -220,17 +208,7 @@ function admin_content(App $a) ]] ]; - /* get addons admin page */ - - $r = q("SELECT `name` FROM `addon` WHERE `plugin_admin` = 1 ORDER BY `name`"); $aside_tools['addons_admin'] = []; - $addons_admin = []; - foreach ($r as $h) { - $addon = $h['name']; - $aside_tools['addons_admin'][] = ["admin/addons/" . $addon, $addon, "addon"]; - // temp addons with admin - $addons_admin[] = $addon; - } $t = Renderer::getMarkupTemplate('admin/aside.tpl'); $a->page['aside'] .= Renderer::replaceMacros($t, [ @@ -253,9 +231,6 @@ function admin_content(App $a) case 'users': $o = admin_page_users($a); break; - case 'addons': - $o = admin_page_addons($a, $addons_admin); - break; case 'themes': $o = admin_page_themes($a); break; @@ -1668,102 +1643,6 @@ function admin_page_users(App $a) return $o; } -/** - * @brief Addons admin page - * - * This function generates the admin panel page for managing addons on the - * friendica node. If an addon name is given a single page showing the details - * for this addon is generated. If no name is given, a list of available - * addons is shown. - * - * The template used for displaying the list of addons and the details of the - * addon are the same as used for the templates. - * - * The returned string returned hulds the HTML code of the page. - * - * @param App $a - * @param array $addons_admin A list of admin addon names - * @return string - * @throws \Friendica\Network\HTTPException\InternalServerErrorException - */ -function admin_page_addons(App $a, array $addons_admin) -{ - /* - * Single addon - */ - if ($a->argc == 3) { - $addon = $a->argv[2]; - if (!is_file("addon/$addon/$addon.php")) { - notice(L10n::t("Item not found.")); - return ''; - } - - if (defaults($_GET, 'a', '') == "t") { - BaseModule::checkFormSecurityTokenRedirectOnError('/admin/addons', 'admin_themes', 't'); - - // Toggle addon status - if (Addon::isEnabled($addon)) { - Addon::uninstall($addon); - info(L10n::t("Addon %s disabled.", $addon)); - } else { - Addon::install($addon); - info(L10n::t("Addon %s enabled.", $addon)); - } - - Addon::saveEnabledList(); - $a->internalRedirect('admin/addons'); - return ''; // NOTREACHED - } - - // display addon details - if (Addon::isEnabled($addon)) { - $status = "on"; - $action = L10n::t("Disable"); - } else { - $status = "off"; - $action = L10n::t("Enable"); - } - - $readme = null; - if (is_file("addon/$addon/README.md")) { - $readme = Markdown::convert(file_get_contents("addon/$addon/README.md"), false); - } elseif (is_file("addon/$addon/README")) { - $readme = "
" . file_get_contents("addon/$addon/README") . ""; - } - - $admin_form = ""; - if (in_array($addon, $addons_admin)) { - require_once "addon/$addon/$addon.php"; - $func = $addon . '_addon_admin'; - $func($a, $admin_form); - } - - $t = Renderer::getMarkupTemplate('admin/addon_details.tpl'); - - return Renderer::replaceMacros($t, [ - '$title' => L10n::t('Administration'), - '$page' => L10n::t('Addons'), - '$toggle' => L10n::t('Toggle'), - '$settings' => L10n::t('Settings'), - '$baseurl' => $a->getBaseURL(true), - - '$addon' => $addon, - '$status' => $status, - '$action' => $action, - '$info' => Addon::getInfo($addon), - '$str_author' => L10n::t('Author: '), - '$str_maintainer' => L10n::t('Maintainer: '), - - '$admin_form' => $admin_form, - '$function' => 'addons', - '$screenshot' => '', - '$readme' => $readme, - - '$form_security_token' => BaseModule::getFormSecurityToken("admin_themes"), - ]); - } -} - /** * @param array $themes * @param string $th diff --git a/src/App/Router.php b/src/App/Router.php index eacf95db35..6c152eb8a0 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -122,6 +122,8 @@ class Router $collector->addRoute(['GET'] , '[/]' , Module\Admin\Summary::class); $collector->addRoute(['GET', 'POST'], '/addons' , Module\Admin\Addons\Index::class); + $collector->addRoute(['GET', 'POST'], '/addons/{addon}' , Module\Admin\Addons\Details::class); + $collector->addRoute(['GET'] , '/federation' , Module\Admin\Federation::class); $collector->addRoute(['GET', 'POST'], '/themes' , Module\Admin\Themes\Index::class); diff --git a/src/Module/Admin/Addons/Details.php b/src/Module/Admin/Addons/Details.php new file mode 100644 index 0000000000..9ef2035dec --- /dev/null +++ b/src/Module/Admin/Addons/Details.php @@ -0,0 +1,129 @@ +argc > 2) { + // @TODO: Replace with parameter from router + $addon = $a->argv[2]; + $addon = Strings::sanitizeFilePathItem($addon); + if (is_file('addon/' . $addon . '/' . $addon . '.php')) { + include_once 'addon/' . $addon . '/' . $addon . '.php'; + if (function_exists($addon . '_addon_admin_post')) { + $func = $addon . '_addon_admin_post'; + $func($a); + } + + $a->internalRedirect('admin/addons/' . $addon); + } + } + + $a->internalRedirect('admin/addons'); + } + + public static function content() + { + parent::content(); + + $a = self::getApp(); + + $addons_admin = []; + $addonsAdminStmt = DBA::select('addon', ['name'], ['plugin_admin' => 1], ['order' => ['name']]); + foreach (DBA::toArray($addonsAdminStmt) as $addon) { + $addonName = $addon['name']; + // temp addons with admin + $addons_admin[] = $addonName; + } + + if ($a->argc > 2) { + // @TODO: Replace with parameter from router + $addon = $a->argv[2]; + $addon = Strings::sanitizeFilePathItem($addon); + if (!is_file("addon/$addon/$addon.php")) { + notice(L10n::t('Item not found.')); + $a->internalRedirect('admin/addons'); + } + + if (defaults($_GET, 'action', '') == 'toggle') { + parent::checkFormSecurityTokenRedirectOnError('/admin/addons', 'admin_themes', 't'); + + // Toggle addon status + if (Addon::isEnabled($addon)) { + Addon::uninstall($addon); + info(L10n::t('Addon %s disabled.', $addon)); + } else { + Addon::install($addon); + info(L10n::t('Addon %s enabled.', $addon)); + } + + Addon::saveEnabledList(); + + $a->internalRedirect('admin/addons/' . $addon); + } + + // display addon details + if (Addon::isEnabled($addon)) { + $status = 'on'; + $action = L10n::t('Disable'); + } else { + $status = 'off'; + $action = L10n::t('Enable'); + } + + $readme = null; + if (is_file("addon/$addon/README.md")) { + $readme = Markdown::convert(file_get_contents("addon/$addon/README.md"), false); + } elseif (is_file("addon/$addon/README")) { + $readme = '
' . file_get_contents("addon/$addon/README") . ''; + } + + $admin_form = ''; + if (in_array($addon, $addons_admin)) { + require_once "addon/$addon/$addon.php"; + $func = $addon . '_addon_admin'; + $func($a, $admin_form); + } + + $t = Renderer::getMarkupTemplate('admin/addons/details.tpl'); + + return Renderer::replaceMacros($t, [ + '$title' => L10n::t('Administration'), + '$page' => L10n::t('Addons'), + '$toggle' => L10n::t('Toggle'), + '$settings' => L10n::t('Settings'), + '$baseurl' => $a->getBaseURL(true), + + '$addon' => $addon, + '$status' => $status, + '$action' => $action, + '$info' => Addon::getInfo($addon), + '$str_author' => L10n::t('Author: '), + '$str_maintainer' => L10n::t('Maintainer: '), + + '$admin_form' => $admin_form, + '$function' => 'addons', + '$screenshot' => '', + '$readme' => $readme, + + '$form_security_token' => parent::getFormSecurityToken('admin_themes'), + ]); + } + + $a->internalRedirect('admin/addons'); + } +} \ No newline at end of file diff --git a/view/templates/admin/addons/details.tpl b/view/templates/admin/addons/details.tpl new file mode 100644 index 0000000000..f5bb165e05 --- /dev/null +++ b/view/templates/admin/addons/details.tpl @@ -0,0 +1,37 @@ + +
{{$info.name}} - {{$info.version}} : {{$action}}
+{{$info.description nofilter}}
+ + + +{{$str_maintainer}} + {{foreach $info.maintainer as $a name=maintainers}} + {{if $a.link}}{{$a.name}}{{else}}{{$a.name}}{{/if}}{{if $smarty.foreach.maintainers.last}}{{else}}, {{/if}} + {{/foreach}} +
+ + {{if $screenshot}} + + {{/if}} + + {{if $admin_form}} +