]> git.mxchange.org Git - friendica-addons.git/blob - blockem/blockem.php
add blockem plugin
[friendica-addons.git] / blockem / blockem.php
1 <?php
2
3
4 /**
5  * Name: blockem
6  * Description: block people
7  * Version: 1.0
8  * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
9  * 
10  */
11
12 function blockem_install() {
13         register_hook('prepare_body', 'addon/blockem/blockem.php', 'blockem_prepare_body');
14         register_hook('plugin_settings', 'addon/blockem/blockem.php', 'blockem_addon_settings');
15         register_hook('plugin_settings_post', 'addon/blockem/blockem.php', 'blockem_addon_settings_post');
16
17 }
18
19
20 function blockem_uninstall() {
21         unregister_hook('prepare_body', 'addon/blockem/blockem.php', 'blockem_prepare_body');
22         unregister_hook('plugin_settings', 'addon/blockem/blockem.php', 'blockem_addon_settings');
23         unregister_hook('plugin_settings_post', 'addon/blockem/blockem.php', 'blockem_addon_settings_post');
24
25 }
26
27
28
29
30
31 function blockem_addon_settings(&$a,&$s) {
32
33
34         if(! local_user())
35                 return;
36
37     /* Add our stylesheet to the page so we can make our settings look nice */
38
39     $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->get_baseurl() . '/addon/blockem/blockem.css' . '" media="all" />' . "\r\n";
40
41
42         $words = get_pconfig(local_user(),'blockem','words');
43         if(! $words)
44                 $words = '';
45
46     $s .= '<div class="settings-block">';
47     $s .= '<h3>' . t('"Blockem" Settings') . '</h3>';
48     $s .= '<div id="blockem-wrapper">';
49     $s .= '<label id="blockem-label" for="blockem-words">' . t('Comma separated profile URLS to block') . ' </label>';
50     $s .= '<input id="blockem-words" type="text" name="blockem-words" value="' . $words .'" />';
51     $s .= '</div><div class="clear"></div>';
52
53     $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="blockem-submit" name="blockem-submit" class="settings-submit" value="' . t('Submit') . '" /></div></div>';
54
55         return;
56
57 }
58
59 function blockem_addon_settings_post(&$a,&$b) {
60
61         if(! local_user())
62                 return;
63
64         if($_POST['blockem-submit']) {
65                 set_pconfig(local_user(),'blockem','words',trim($_POST['blockem-words']));
66                 info( t('BLOCKEM Settings saved.') . EOL);
67         }
68 }
69
70 function blockem_prepare_body(&$a,&$b) {
71
72         if(! local_user())
73                 return;
74
75         $words = null;
76         if(local_user()) {
77                 $words = get_pconfig(local_user(),'blockem','words');
78         }
79         if($words) {
80                 $arr = explode(',',$words);
81         }
82         else {
83                 return;
84         }
85
86         $found = false;
87         if(count($arr)) {
88                 foreach($arr as $word) {
89                         if(! strlen(trim($word))) {
90                                 continue;
91                         }
92
93                         if(link_compare($b['item']['author-link'],$word)) {
94                                 $found = true;
95                                 break;
96                         }
97                 }
98         }
99         if($found) {
100                 $rnd = random_string(8);
101                 $b['item']['author-avatar'] = $a->get_baseurl() . "/images/default-profile-sm.jpg";
102                 $b['html'] = 
103 '<script>$("#wall-item-photo-' . $b['item']['id'] . '").removeAttr("src")</script>' . 
104 '<div id="blockem-wrap-' . $rnd . '" class="fakelink" onclick=openClose(\'blockem-' . $rnd . '\'); >' . sprintf( t('Blocked %s - Click to open/close'),$word ) . '</div><div id="blockem-' . $rnd . '" style="display: none; " >' . $b['html'] . '</div>';  
105         }
106 }