regenerated all strings.php files from the current translation strings (message.po)
[friendica-addons.git/.git] / qcomment / qcomment.php
1 <?php
2 /**
3  * Name: Quick Comment
4  * Description: Two click comments
5  * Version: 1.0
6  * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
7  *
8  * Provides a set of text "snippets" which can be inserted into a comment window by clicking on them.
9  * First enable the addon in the system admin panel.
10  * Then each person can tailor their choice of words in Settings->Addon Settings in the Qcomment
11  * pane. Initially no qcomments are provided, but on viewing the settings page, a default set of
12  * of words is suggested. These can be accepted (click Submit) or edited first. Each text line represents
13  * a different qcomment.
14  * Many themes will hide the qcomments above or immediately adjacent to the comment input box until
15  * you wish to use them. On some themes they may be visible.
16  * Wave the mouse around near the comment input box and the qcomments will show up. Click on any of
17  * them to open the comment window fully and insert the qcomment. Then "Submit" will submit it.
18  *
19  */
20 use Friendica\Core\Hook;
21 use Friendica\DI;
22 use Friendica\Util\XML;
23
24 function qcomment_install()
25 {
26         Hook::register('addon_settings'     , __FILE__, 'qcomment_addon_settings');
27         Hook::register('addon_settings_post', __FILE__, 'qcomment_addon_settings_post');
28         Hook::register('footer'             , __FILE__, 'qcomment_footer');
29 }
30
31 function qcomment_footer(\Friendica\App $a, &$b)
32 {
33         DI::page()->registerFooterScript(__DIR__ . '/qcomment.js');
34 }
35
36 function qcomment_addon_settings(&$a, &$s)
37 {
38         if (! local_user()) {
39                 return;
40         }
41
42         $words = DI::pConfig()->get(local_user(), 'qcomment', 'words', DI::l10n()->t(':-)') . "\n" . DI::l10n()->t(':-(') . "\n" .  DI::l10n()->t('lol'));
43
44         $t = \Friendica\Core\Renderer::getMarkupTemplate('settings.tpl', 'addon/qcomment/');
45         $s .= \Friendica\Core\Renderer::replaceMacros($t, [
46                 '$postpost'    => isset($_POST['qcomment-words']),
47                 '$header'      => DI::l10n()->t('Quick Comment Settings'),
48                 '$description' => DI::l10n()->t("Quick comments are found near comment boxes, sometimes hidden. Click them to provide simple replies."),
49                 '$save'        => DI::l10n()->t('Save Settings'),
50                 '$words'       => ['qcomment-words', DI::l10n()->t('Enter quick comments, one per line'), $words, null, ' rows="10"'],
51         ]);
52 }
53
54 function qcomment_addon_settings_post(&$a, &$b)
55 {
56         if (! local_user()) {
57                 return;
58         }
59
60         if (isset($_POST['qcomment-words'])) {
61                 DI::pConfig()->set(local_user(), 'qcomment', 'words', XML::escape($_POST['qcomment-words']));
62         }
63 }