'$form_security_token' => BaseModule::getFormSecurityToken("admin_themes"),
]);
}
-
- /*
- * List addons
- */
- if (!empty($_GET['a']) && $_GET['a'] == "r") {
- BaseModule::checkFormSecurityTokenRedirectOnError($a->getBaseURL() . '/admin/addons', 'admin_themes', 't');
- Addon::reload();
- info("Addons reloaded");
- $a->internalRedirect('admin/addons');
- }
-
- $addons = [];
- $files = glob("addon/*/");
- if (is_array($files)) {
- foreach ($files as $file) {
- if (is_dir($file)) {
- list($tmp, $id) = array_map("trim", explode("/", $file));
- $info = Addon::getInfo($id);
- $show_addon = true;
-
- // If the addon is unsupported, then only show it, when it is enabled
- if ((strtolower($info["status"]) == "unsupported") && !Addon::isEnabled($id)) {
- $show_addon = false;
- }
-
- // Override the above szenario, when the admin really wants to see outdated stuff
- if (Config::get("system", "show_unsupported_addons")) {
- $show_addon = true;
- }
-
- if ($show_addon) {
- $addons[] = [$id, (Addon::isEnabled($id) ? "on" : "off"), $info];
- }
- }
- }
- }
-
- $t = Renderer::getMarkupTemplate('admin/addons.tpl');
- return Renderer::replaceMacros($t, [
- '$title' => L10n::t('Administration'),
- '$page' => L10n::t('Addons'),
- '$submit' => L10n::t('Save Settings'),
- '$reload' => L10n::t('Reload active addons'),
- '$baseurl' => System::baseUrl(true),
- '$function' => 'addons',
- '$addons' => $addons,
- '$pcount' => count($addons),
- '$noplugshint' => L10n::t('There are currently no addons available on your node. You can find the official addon repository at %1$s and might find other interesting addons in the open addon registry at %2$s', 'https://github.com/friendica/friendica-addons', 'http://addons.friendi.ca'),
- '$form_security_token' => BaseModule::getFormSecurityToken("admin_themes"),
- ]);
}
/**
$this->routeCollector->addGroup('/admin', function (RouteCollector $collector) {
$collector->addRoute(['GET'] , '[/]' , Module\Admin\Summary::class);
+
+ $collector->addRoute(['GET', 'POST'], '/addons' , Module\Admin\Addons\Index::class);
$collector->addRoute(['GET'] , '/federation' , Module\Admin\Federation::class);
$collector->addRoute(['GET', 'POST'], '/themes' , Module\Admin\Themes\Index::class);
*/
private static $addons = [];
+ public static function getAvailableList()
+ {
+ $addons = [];
+ $files = glob('addon/*/');
+ if (is_array($files)) {
+ foreach ($files as $file) {
+ if (is_dir($file)) {
+ list($tmp, $addon) = array_map('trim', explode('/', $file));
+ $info = self::getInfo($addon);
+
+ if (Config::get('system', 'show_unsupported_addons')
+ || strtolower($info['status']) != 'unsupported'
+ || self::isEnabled($addon)
+ ) {
+ $addons[] = [$addon, (self::isEnabled($addon) ? 'on' : 'off'), $info];
+ }
+ }
+ }
+ }
+
+ return $addons;
+ }
+
/**
* @brief Synchronize addons:
*
}
unset(self::$addons[array_search($addon, self::$addons)]);
+
+ Addon::saveEnabledList();
}
/**
self::$addons[] = $addon;
}
+ Addon::saveEnabledList();
+
return true;
} else {
- Logger::error("Addon {addon}: {action} failed", ['action' => 'uninstall', 'addon' => $addon]);
+ Logger::error("Addon {addon}: {action} failed", ['action' => 'install', 'addon' => $addon]);
return false;
}
}
* Saves the current enabled addon list in the system.addon config key
*
* @return boolean
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function saveEnabledList()
{
- return Config::set("system", "addon", implode(", ", self::$addons));
+ return Config::set('system', 'addon', implode(', ', self::$addons));
}
/**
--- /dev/null
+<?php\r
+\r
+namespace Friendica\Module\Admin\Addons;\r
+\r
+use Friendica\Content\Text\Markdown;\r
+use Friendica\Core\Addon;\r
+use Friendica\Core\Config;\r
+use Friendica\Core\L10n;\r
+use Friendica\Core\Renderer;\r
+use Friendica\Core\System;\r
+use Friendica\Database\DBA;\r
+use Friendica\Module\BaseAdminModule;\r
+\r
+class Index extends BaseAdminModule\r
+{\r
+ public static function content()\r
+ {\r
+ parent::content();\r
+\r
+ $a = self::getApp();\r
+\r
+ // reload active themes\r
+ if (!empty($_GET['action'])) {\r
+ parent::checkFormSecurityTokenRedirectOnError('/admin/addons', 'admin_addons', 't');\r
+\r
+ switch ($_GET['action']) {\r
+ case 'reload':\r
+ Addon::reload();\r
+ info('Addons reloaded');\r
+ break;\r
+\r
+ case 'toggle' :\r
+ $addon = defaults($_GET, 'addon', '');\r
+ if (Addon::isEnabled($addon)) {\r
+ Addon::uninstall($addon);\r
+ info(L10n::t('Addon %s disabled.', $addon));\r
+ } elseif (Addon::install($addon)) {\r
+ info(L10n::t('Addon %s enabled.', $addon));\r
+ } else {\r
+ info(L10n::t('Addon %s failed to install.', $addon));\r
+ }\r
+\r
+ break;\r
+\r
+ }\r
+\r
+ $a->internalRedirect('admin/addons');\r
+ }\r
+\r
+ $addons_admin = [];\r
+ $addonsAdminStmt = DBA::select('addon', ['name'], ['plugin_admin' => 1], ['order' => ['name']]);\r
+ foreach (DBA::toArray($addonsAdminStmt) as $addon) {\r
+ $addons_admin[] = $addon['name'];\r
+ }\r
+\r
+ $addons = Addon::getAvailableList();\r
+\r
+ $t = Renderer::getMarkupTemplate('admin/addons/index.tpl');\r
+ return Renderer::replaceMacros($t, [\r
+ '$title' => L10n::t('Administration'),\r
+ '$page' => L10n::t('Addons'),\r
+ '$submit' => L10n::t('Save Settings'),\r
+ '$reload' => L10n::t('Reload active addons'),\r
+ '$baseurl' => System::baseUrl(true),\r
+ '$function' => 'addons',\r
+ '$addons' => $addons,\r
+ '$pcount' => count($addons),\r
+ '$noplugshint' => L10n::t('There are currently no addons available on your node. You can find the official addon repository at %1$s and might find other interesting addons in the open addon registry at %2$s', 'https://github.com/friendica/friendica-addons', 'http://addons.friendi.ca'),\r
+ '$form_security_token' => parent::getFormSecurityToken('admin_addons'),\r
+ ]);\r
+ }\r
+}
\ No newline at end of file
'federation' => ['admin/federation' , L10n::t('Federation Statistics') , 'federation']\r
]],\r
'configuration' => [L10n::t('Configuration'), [\r
+ 'addons' => ['admin/addons' , L10n::t('Addons') , 'addons'],\r
'themes' => ['admin/themes' , L10n::t('Themes') , 'themes'],\r
'tos' => ['admin/tos' , L10n::t('Terms of Service') , 'tos'],\r
]],\r
+++ /dev/null
-
-<div id='adminpage'>
- <h1>{{$title}} - {{$page}}</h1>
- {{if $pcount eq 0}}
- <div class="error-message">
- {{$noplugshint}}
- </div>
- {{else}}
- <a class="btn" href="{{$baseurl}}/admin/{{$function}}?a=r&t={{$form_security_token}}">{{$reload}}</a>
- <ul id='addonslist'>
- {{foreach $addons as $p}}
- <li class='addon {{$p.1}}'>
- <a class='toggleaddon' href='{{$baseurl}}/admin/{{$function}}/{{$p.0}}?a=t&t={{$form_security_token}}' title="{{if $p.1==on}}Disable{{else}}Enable{{/if}}" ><span class='icon {{$p.1}}'></span></a>
- <a href='{{$baseurl}}/admin/{{$function}}/{{$p.0}}'><span class='name'>{{$p.2.name}}</span></a> - <span class="version">{{$p.2.version}}</span>
- {{if $p.2.experimental}} {{$experimental}} {{/if}}{{if $p.2.unsupported}} {{$unsupported}} {{/if}}
-
- <div class='desc'>{{$p.2.description nofilter}}</div>
- </li>
- {{/foreach}}
- </ul>
- {{/if}}
-</div>
+++ /dev/null
-
-<div id='adminpage'>
- <h1>{{$title}} - {{$page}}</h1>
- {{if $pcount eq 0}}
- <div class="error-message">
- {{$noplugshint}}
- </div>
- {{else}}
- <a class="btn" href="{{$baseurl}}/admin/{{$function}}?a=r&t={{$form_security_token}}">{{$reload}}</a>
- <ul id='addonslist'>
- {{foreach $addons as $p}}
- <li class="addon {{$p.1}}">
- <span class="offset-anchor" id="{{$p.0}}"></span>
- <a class='toggleaddon' href='{{$baseurl}}/admin/{{$function}}/{{$p.0}}?a=t&t={{$form_security_token}}#{{$p.0}}' title="{{if $p.1==on}}Disable{{else}}Enable{{/if}}" ><span class='icon {{$p.1}}'></span></a>
- <a href='{{$baseurl}}/admin/{{$function}}/{{$p.0}}'><span class='name'>{{$p.2.name}}</span></a> - <span class="version">{{$p.2.version}}</span>
- {{if $p.2.experimental}} {{$experimental}} {{/if}}{{if $p.2.unsupported}} {{$unsupported}} {{/if}}
- <div class='desc'>{{$p.2.description nofilter}}</div>
- </li>
- {{/foreach}}
- </ul>
- {{/if}}
-</div>