2019-05-02 00:01:43 -04:00
|
|
|
<?php
|
2020-02-09 09:45:36 -05:00
|
|
|
/**
|
2021-03-29 02:40:20 -04:00
|
|
|
* @copyright Copyright (C) 2010-2021, the Friendica project
|
2020-02-09 09:45:36 -05:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2019-05-02 00:01:43 -04:00
|
|
|
|
|
|
|
namespace Friendica\Module\Admin\Addons;
|
|
|
|
|
|
|
|
use Friendica\Content\Text\Markdown;
|
|
|
|
use Friendica\Core\Addon;
|
|
|
|
use Friendica\Core\Renderer;
|
2019-12-15 16:34:11 -05:00
|
|
|
use Friendica\DI;
|
2020-01-22 23:14:14 -05:00
|
|
|
use Friendica\Module\BaseAdmin;
|
2019-05-02 00:01:43 -04:00
|
|
|
use Friendica\Util\Strings;
|
|
|
|
|
2020-01-22 23:14:14 -05:00
|
|
|
class Details extends BaseAdmin
|
2019-05-02 00:01:43 -04:00
|
|
|
{
|
2019-11-05 16:48:54 -05:00
|
|
|
public static function post(array $parameters = [])
|
2019-05-02 00:01:43 -04:00
|
|
|
{
|
2020-09-08 10:44:27 -04:00
|
|
|
self::checkAdminAccess();
|
2019-05-02 00:01:43 -04:00
|
|
|
|
2020-09-08 10:38:35 -04:00
|
|
|
$addon = Strings::sanitizeFilePathItem($parameters['addon']);
|
|
|
|
|
|
|
|
$redirect = 'admin/addons/' . $addon;
|
2019-05-02 00:01:43 -04:00
|
|
|
|
2020-09-08 10:38:35 -04:00
|
|
|
if (is_file('addon/' . $addon . '/' . $addon . '.php')) {
|
|
|
|
include_once 'addon/' . $addon . '/' . $addon . '.php';
|
|
|
|
|
|
|
|
if (function_exists($addon . '_addon_admin_post')) {
|
2020-09-08 10:42:25 -04:00
|
|
|
self::checkFormSecurityTokenRedirectOnError($redirect, 'admin_addons_details');
|
|
|
|
|
2020-09-08 10:38:35 -04:00
|
|
|
$func = $addon . '_addon_admin_post';
|
|
|
|
$func(DI::app());
|
2019-05-02 00:01:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-08 10:38:35 -04:00
|
|
|
DI::baseUrl()->redirect($redirect);
|
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();
|
|
|
|
|
2020-09-08 10:38:35 -04:00
|
|
|
$addon = Strings::sanitizeFilePathItem($parameters['addon']);
|
|
|
|
if (!is_file("addon/$addon/$addon.php")) {
|
|
|
|
notice(DI::l10n()->t('Addon not found.'));
|
|
|
|
Addon::uninstall($addon);
|
|
|
|
DI::baseUrl()->redirect('admin/addons');
|
|
|
|
}
|
2019-05-02 00:01:43 -04:00
|
|
|
|
2020-09-08 10:38:35 -04:00
|
|
|
if (($_GET['action'] ?? '') == 'toggle') {
|
2020-09-08 10:42:25 -04:00
|
|
|
self::checkFormSecurityTokenRedirectOnError('/admin/addons', 'admin_addons_details', 't');
|
2019-05-02 00:01:43 -04:00
|
|
|
|
2020-09-08 10:38:35 -04:00
|
|
|
// Toggle addon status
|
2019-05-02 00:01:43 -04:00
|
|
|
if (Addon::isEnabled($addon)) {
|
2020-09-08 10:38:35 -04:00
|
|
|
Addon::uninstall($addon);
|
|
|
|
info(DI::l10n()->t('Addon %s disabled.', $addon));
|
2019-05-02 00:01:43 -04:00
|
|
|
} else {
|
2020-09-08 10:38:35 -04:00
|
|
|
Addon::install($addon);
|
|
|
|
info(DI::l10n()->t('Addon %s enabled.', $addon));
|
2019-05-02 00:01:43 -04:00
|
|
|
}
|
|
|
|
|
2020-09-08 10:38:35 -04:00
|
|
|
DI::baseUrl()->redirect('admin/addons/' . $addon);
|
|
|
|
}
|
2019-05-02 00:01:43 -04:00
|
|
|
|
2020-09-08 10:38:35 -04:00
|
|
|
// display addon details
|
|
|
|
if (Addon::isEnabled($addon)) {
|
|
|
|
$status = 'on';
|
|
|
|
$action = DI::l10n()->t('Disable');
|
|
|
|
} else {
|
|
|
|
$status = 'off';
|
|
|
|
$action = DI::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 = '<pre>' . file_get_contents("addon/$addon/README") . '</pre>';
|
|
|
|
}
|
2019-05-02 00:01:43 -04:00
|
|
|
|
2020-09-08 10:38:35 -04:00
|
|
|
$admin_form = '';
|
|
|
|
if (array_key_exists($addon, $addons_admin)) {
|
|
|
|
require_once "addon/$addon/$addon.php";
|
|
|
|
$func = $addon . '_addon_admin';
|
|
|
|
$func($a, $admin_form);
|
2019-05-02 00:01:43 -04:00
|
|
|
}
|
|
|
|
|
2020-09-08 10:38:35 -04:00
|
|
|
$t = Renderer::getMarkupTemplate('admin/addons/details.tpl');
|
|
|
|
|
|
|
|
return Renderer::replaceMacros($t, [
|
|
|
|
'$title' => DI::l10n()->t('Administration'),
|
|
|
|
'$page' => DI::l10n()->t('Addons'),
|
|
|
|
'$toggle' => DI::l10n()->t('Toggle'),
|
|
|
|
'$settings' => DI::l10n()->t('Settings'),
|
|
|
|
'$baseurl' => DI::baseUrl()->get(true),
|
|
|
|
|
|
|
|
'$addon' => $addon,
|
|
|
|
'$status' => $status,
|
|
|
|
'$action' => $action,
|
|
|
|
'$info' => Addon::getInfo($addon),
|
|
|
|
'$str_author' => DI::l10n()->t('Author: '),
|
|
|
|
'$str_maintainer' => DI::l10n()->t('Maintainer: '),
|
|
|
|
|
|
|
|
'$admin_form' => $admin_form,
|
|
|
|
'$function' => 'addons',
|
|
|
|
'$screenshot' => '',
|
|
|
|
'$readme' => $readme,
|
|
|
|
|
2020-09-08 10:42:25 -04:00
|
|
|
'$form_security_token' => self::getFormSecurityToken('admin_addons_details'),
|
2020-09-08 10:38:35 -04:00
|
|
|
]);
|
2019-05-02 00:01:43 -04:00
|
|
|
}
|
|
|
|
}
|