]> git.mxchange.org Git - friendica-addons.git/blob - group_text/group_text.php
[various] Remove App dependency from hook functions
[friendica-addons.git] / group_text / group_text.php
1 <?php
2 /**
3  * Name: Group Text
4  * Description: Disable images in group edit menu
5  * Version: 1.0
6  * Author: Thomas Willingham <https://kakste.com/profile/beardyunixer>
7  */
8
9 use Friendica\App;
10 use Friendica\Core\Hook;
11 use Friendica\Core\Logger;
12 use Friendica\Core\Renderer;
13 use Friendica\DI;
14
15 function group_text_install()
16 {
17         Hook::register('addon_settings', 'addon/group_text/group_text.php', 'group_text_settings');
18         Hook::register('addon_settings_post', 'addon/group_text/group_text.php', 'group_text_settings_post');
19 }
20
21 /**
22  *
23  * Callback from the settings post function.
24  * $post contains the $_POST array.
25  * We will make sure we've got a valid user account
26  * and if so set our configuration setting for this person.
27  *
28  */
29
30 function group_text_settings_post(array $post)
31 {
32         if (!DI::userSession()->getLocalUserId() || empty($post['group_text-submit'])) {
33                 return;
34         }
35
36         DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'groupedit_image_limit', intval($post['group_text']));
37 }
38
39
40 /**
41  *
42  * Called from the Addon Setting form.
43  * Add our own settings info to the page.
44  *
45  */
46
47 function group_text_settings(array &$data)
48 {
49         if (!DI::userSession()->getLocalUserId()) {
50                 return;
51         }
52
53         $enabled = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'groupedit_image_limit');
54
55         $t    = Renderer::getMarkupTemplate('settings.tpl', 'addon/group_text/');
56         $html = Renderer::replaceMacros($t, [
57                 '$enabled' => ['group_text', DI::l10n()->t('Use a text only (non-image) group selector in the "group edit" menu'), $enabled],
58         ]);
59
60         $data = [
61                 'addon' => 'group_text',
62                 'title' => DI::l10n()->t('Group Text'),
63                 'html'  => $html,
64         ];
65 }