2019-05-02 00:01:43 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Module\Admin\Addons;
|
|
|
|
|
|
|
|
use Friendica\Content\Text\Markdown;
|
|
|
|
use Friendica\Core\Addon;
|
|
|
|
use Friendica\Core\L10n;
|
|
|
|
use Friendica\Core\Renderer;
|
2019-12-15 16:34:11 -05:00
|
|
|
use Friendica\DI;
|
2019-05-02 00:01:43 -04:00
|
|
|
use Friendica\Module\BaseAdminModule;
|
|
|
|
use Friendica\Util\Strings;
|
|
|
|
|
|
|
|
class Details extends BaseAdminModule
|
|
|
|
{
|
2019-11-05 16:48:54 -05:00
|
|
|
public static function post(array $parameters = [])
|
2019-05-02 00:01:43 -04:00
|
|
|
{
|
2019-11-05 15:22:54 -05:00
|
|
|
parent::post($parameters);
|
2019-05-02 00:01:43 -04:00
|
|
|
|
2019-12-15 16:34:11 -05:00
|
|
|
$a = DI::app();
|
2019-05-02 00:01:43 -04:00
|
|
|
|
|
|
|
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')) {
|
|
|
|
include_once 'addon/' . $addon . '/' . $addon . '.php';
|
|
|
|
if (function_exists($addon . '_addon_admin_post')) {
|
|
|
|
$func = $addon . '_addon_admin_post';
|
|
|
|
$func($a);
|
|
|
|
}
|
|
|
|
|
2019-12-15 18:28:31 -05:00
|
|
|
DI::baseUrl()->redirect('admin/addons/' . $addon);
|
2019-05-02 00:01:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-15 18:28:31 -05:00
|
|
|
DI::baseUrl()->redirect('admin/addons');
|
2019-05-02 00:01:43 -04:00
|
|
|
}
|
|
|
|
|
2019-11-05 16:48:54 -05:00
|
|
|
public static function content(array $parameters = [])
|
2019-05-02 00:01:43 -04:00
|
|
|
{
|
2019-11-05 15:22:54 -05:00
|
|
|
parent::content($parameters);
|
2019-05-02 00:01:43 -04:00
|
|
|
|
2019-12-15 16:34:11 -05:00
|
|
|
$a = DI::app();
|
2019-05-02 00:01:43 -04:00
|
|
|
|
|
|
|
$addons_admin = Addon::getAdminList();
|
|
|
|
|
|
|
|
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")) {
|
2020-01-18 14:52:34 -05:00
|
|
|
notice(DI::l10n()->t('Addon not found.'));
|
2019-05-08 00:46:42 -04:00
|
|
|
Addon::uninstall($addon);
|
2019-12-15 18:28:31 -05:00
|
|
|
DI::baseUrl()->redirect('admin/addons');
|
2019-05-02 00:01:43 -04:00
|
|
|
}
|
|
|
|
|
2019-10-15 09:20:32 -04:00
|
|
|
if (($_GET['action'] ?? '') == 'toggle') {
|
2019-05-02 00:01:43 -04:00
|
|
|
parent::checkFormSecurityTokenRedirectOnError('/admin/addons', 'admin_themes', 't');
|
|
|
|
|
|
|
|
// Toggle addon status
|
|
|
|
if (Addon::isEnabled($addon)) {
|
|
|
|
Addon::uninstall($addon);
|
2020-01-18 14:52:34 -05:00
|
|
|
info(DI::l10n()->t('Addon %s disabled.', $addon));
|
2019-05-02 00:01:43 -04:00
|
|
|
} else {
|
|
|
|
Addon::install($addon);
|
2020-01-18 14:52:34 -05:00
|
|
|
info(DI::l10n()->t('Addon %s enabled.', $addon));
|
2019-05-02 00:01:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Addon::saveEnabledList();
|
|
|
|
|
2019-12-15 18:28:31 -05:00
|
|
|
DI::baseUrl()->redirect('admin/addons/' . $addon);
|
2019-05-02 00:01:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// display addon details
|
|
|
|
if (Addon::isEnabled($addon)) {
|
|
|
|
$status = 'on';
|
2020-01-18 14:52:34 -05:00
|
|
|
$action = DI::l10n()->t('Disable');
|
2019-05-02 00:01:43 -04:00
|
|
|
} else {
|
|
|
|
$status = 'off';
|
2020-01-18 14:52:34 -05:00
|
|
|
$action = DI::l10n()->t('Enable');
|
2019-05-02 00:01:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
$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 = '<pre>' . file_get_contents("addon/$addon/README") . '</pre>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$admin_form = '';
|
|
|
|
if (array_key_exists($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, [
|
2020-01-18 14:52:34 -05:00
|
|
|
'$title' => DI::l10n()->t('Administration'),
|
|
|
|
'$page' => DI::l10n()->t('Addons'),
|
|
|
|
'$toggle' => DI::l10n()->t('Toggle'),
|
|
|
|
'$settings' => DI::l10n()->t('Settings'),
|
2019-12-15 19:05:15 -05:00
|
|
|
'$baseurl' => DI::baseUrl()->get(true),
|
2019-05-02 00:01:43 -04:00
|
|
|
|
|
|
|
'$addon' => $addon,
|
|
|
|
'$status' => $status,
|
|
|
|
'$action' => $action,
|
|
|
|
'$info' => Addon::getInfo($addon),
|
2020-01-18 14:52:34 -05:00
|
|
|
'$str_author' => DI::l10n()->t('Author: '),
|
|
|
|
'$str_maintainer' => DI::l10n()->t('Maintainer: '),
|
2019-05-02 00:01:43 -04:00
|
|
|
|
|
|
|
'$admin_form' => $admin_form,
|
|
|
|
'$function' => 'addons',
|
|
|
|
'$screenshot' => '',
|
|
|
|
'$readme' => $readme,
|
|
|
|
|
|
|
|
'$form_security_token' => parent::getFormSecurityToken('admin_themes'),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2019-12-15 18:28:31 -05:00
|
|
|
DI::baseUrl()->redirect('admin/addons');
|
2019-05-02 00:01:43 -04:00
|
|
|
}
|
|
|
|
}
|