f4b951843a82a8db18fe65bc622c824bc3c69c6d
[friendica-addons.git] / qcomment / qcomment.php
1 <?php
2
3
4 /**
5  * Name: Quick Comment
6  * Description: Two click comments
7  * Version: 1.0
8  * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
9  * 
10  * Provides a set of text "snippets" which can be inserted into a comment window by clicking on them.
11  * First enable the addon in the system admin panel. 
12  * Then each person can tailor their choice of words in Settings->Plugin Settings in the Qcomment 
13  * pane. Initially no qcomments are provided, but on viewing the settings page, a default set of
14  * of words is suggested. These can be accepted (click Submit) or edited first. Each text line represents 
15  * a different qcomment. 
16  * Many themes will hide the qcomments above or immediately adjacent to the comment input box until
17  * you wish to use them. On some themes they may be visible.
18  * Wave the mouse around near the comment input box and the qcomments will show up. Click on any of 
19  * them to open the comment window fully and insert the qcomment. Then "Submit" will submit it.
20  *
21  */
22
23 use Friendica\Core\PConfig;
24
25 function qcomment_install() {
26         register_hook('plugin_settings', 'addon/qcomment/qcomment.php', 'qcomment_addon_settings');
27         register_hook('plugin_settings_post', 'addon/qcomment/qcomment.php', 'qcomment_addon_settings_post');
28
29 }
30
31
32 function qcomment_uninstall() {
33         unregister_hook('plugin_settings', 'addon/qcomment/qcomment.php', 'qcomment_addon_settings');
34         unregister_hook('plugin_settings_post', 'addon/qcomment/qcomment.php', 'qcomment_addon_settings_post');
35
36 }
37
38
39
40
41
42 function qcomment_addon_settings(&$a, &$s)
43 {
44         if (! local_user()) {
45                 return;
46         }
47
48         /* Add our stylesheet to the page so we can make our settings look nice */
49
50         $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->get_baseurl() . '/addon/qcomment/qcomment.css' . '" media="all" />' . "\r\n";
51
52         $words = PConfig::get(local_user(), 'qcomment', 'words', t(':-)') . "\n" . t(':-(') . "\n" .  t('lol'));
53
54         $s .= '<div class="settings-block">';
55         $s .= '<h3>' . t('Quick Comment Settings') . '</h3>';
56         $s .= '<div id="qcomment-wrapper">';
57         $s .= '<div id="qcomment-desc">' . t("Quick comments are found near comment boxes, sometimes hidden. Click them to provide simple replies.") . '</div>';
58         $s .= '<label id="qcomment-label" for="qcomment-words">' . t('Enter quick comments, one per line') . ' </label>';
59         $s .= '<textarea id="qcomment-words" type="text" name="qcomment-words" >' . htmlspecialchars(unxmlify($words)) . '</textarea>';
60         $s .= '</div><div class="clear"></div>';
61
62         $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="qcomment-submit" name="qcomment-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div>';
63         $s .= '</div>';
64
65         return;
66 }
67
68 function qcomment_addon_settings_post(&$a,&$b) {
69
70         if(! local_user())
71                 return;
72
73         if($_POST['qcomment-submit']) {
74                 PConfig::set(local_user(),'qcomment','words',xmlify($_POST['qcomment-words']));
75                 info( t('Quick Comment settings saved.') . EOL);
76         }
77 }
78