]> git.mxchange.org Git - friendica-addons.git/blob - qcomment/qcomment.php
4c78b82244afff287f3e9c392dcdfc024850e57c
[friendica-addons.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         Hook::register('addon_settings', 'addon/qcomment/qcomment.php', 'qcomment_addon_settings');
26         Hook::register('addon_settings_post', 'addon/qcomment/qcomment.php', 'qcomment_addon_settings_post');
27
28 }
29
30 function qcomment_addon_settings(&$a, &$s)
31 {
32         if (! local_user()) {
33                 return;
34         }
35
36         /* Add our stylesheet to the page so we can make our settings look nice */
37
38         DI::page()['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . DI::baseUrl()->get() . '/addon/qcomment/qcomment.css' . '" media="all" />' . "\r\n";
39
40         $words = DI::pConfig()->get(local_user(), 'qcomment', 'words', DI::l10n()->t(':-)') . "\n" . DI::l10n()->t(':-(') . "\n" .  DI::l10n()->t('lol'));
41
42         $s .= '<div class="settings-block">';
43         $s .= '<h3>' . DI::l10n()->t('Quick Comment Settings') . '</h3>';
44         $s .= '<div id="qcomment-wrapper">';
45         $s .= '<div id="qcomment-desc">' . DI::l10n()->t("Quick comments are found near comment boxes, sometimes hidden. Click them to provide simple replies.") . '</div>';
46         $s .= '<label id="qcomment-label" for="qcomment-words">' . DI::l10n()->t('Enter quick comments, one per line') . ' </label>';
47         $s .= '<textarea id="qcomment-words" type="text" name="qcomment-words" >' . htmlspecialchars(XML::unescape($words)) . '</textarea>';
48         $s .= '</div><div class="clear"></div>';
49
50         $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="qcomment-submit" name="qcomment-submit" class="settings-submit" value="' . DI::l10n()->t('Save Settings') . '" /></div>';
51         $s .= '</div>';
52
53         return;
54 }
55
56 function qcomment_addon_settings_post(&$a, &$b)
57 {
58         if (! local_user()) {
59                 return;
60         }
61
62         if ($_POST['qcomment-submit']) {
63                 DI::pConfig()->set(local_user(), 'qcomment', 'words', XML::escape($_POST['qcomment-words']));
64         }
65 }