6 * Description: block people
8 * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
12 function blockem_install() {
13 register_hook('prepare_body', 'addon/blockem/blockem.php', 'blockem_prepare_body');
14 register_hook('display_item', 'addon/blockem/blockem.php', 'blockem_display_item');
15 register_hook('plugin_settings', 'addon/blockem/blockem.php', 'blockem_addon_settings');
16 register_hook('plugin_settings_post', 'addon/blockem/blockem.php', 'blockem_addon_settings_post');
17 register_hook('conversation_start', 'addon/blockem/blockem.php', 'blockem_conversation_start');
18 register_hook('item_photo_menu', 'addon/blockem/blockem.php', 'blockem_item_photo_menu');
19 register_hook('enotify_store', 'addon/blockem/blockem.php', 'blockem_enotify_store' );
23 function blockem_uninstall() {
24 unregister_hook('prepare_body', 'addon/blockem/blockem.php', 'blockem_prepare_body');
25 unregister_hook('display_item', 'addon/blockem/blockem.php', 'blockem_display_item');
26 unregister_hook('plugin_settings', 'addon/blockem/blockem.php', 'blockem_addon_settings');
27 unregister_hook('plugin_settings_post', 'addon/blockem/blockem.php', 'blockem_addon_settings_post');
28 unregister_hook('conversation_start', 'addon/blockem/blockem.php', 'blockem_conversation_start');
29 unregister_hook('item_photo_menu', 'addon/blockem/blockem.php', 'blockem_item_photo_menu');
30 unregister_hook('enotify_store', 'addon/blockem/blockem.php', 'blockem_enotify_store' );
38 function blockem_addon_settings(&$a,&$s) {
43 /* Add our stylesheet to the page so we can make our settings look nice */
45 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/blockem/blockem.css' . '" media="all" />' . "\r\n";
48 $words = get_pconfig(local_user(),'blockem','words');
52 $s .= '<span id="settings_blockem_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_blockem_expanded\'); openClose(\'settings_blockem_inflated\');">';
53 $s .= '<h3>' . t('"Blockem" Settings') . '</h3>';
55 $s .= '<div id="settings_blockem_expanded" class="settings-block" style="display: none;">';
56 $s .= '<span class="fakelink" onclick="openClose(\'settings_blockem_expanded\'); openClose(\'settings_blockem_inflated\');">';
57 $s .= '<h3>' . t('"Blockem" Settings') . '</h3>';
60 $s .= '<div id="blockem-wrapper">';
61 $s .= '<label id="blockem-label" for="blockem-words">' . t('Comma separated profile URLS to block') . ' </label>';
62 $s .= '<textarea id="blockem-words" type="text" name="blockem-words" >' . htmlspecialchars($words) . '</textarea>';
63 $s .= '</div><div class="clear"></div>';
65 $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="blockem-submit" name="blockem-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div></div>';
71 function blockem_addon_settings_post(&$a,&$b) {
76 if($_POST['blockem-submit']) {
77 set_pconfig(local_user(),'blockem','words',trim($_POST['blockem-words']));
78 info( t('BLOCKEM Settings saved.') . EOL);
83 function blockem_enotify_store(&$a,&$b) {
85 $words = get_pconfig($b['uid'],'blockem','words');
87 $arr = explode(',',$words);
95 foreach($arr as $word) {
96 if(! strlen(trim($word))) {
100 if(link_compare($b['url'],$word)) {
111 function blockem_prepare_body(&$a,&$b) {
118 $words = get_pconfig(local_user(),'blockem','words');
121 $arr = explode(',',$words);
129 foreach($arr as $word) {
130 if(! strlen(trim($word))) {
134 if(link_compare($b['item']['author-link'],$word)) {
141 $rnd = random_string(8);
142 $b['html'] = '<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>';
147 function blockem_display_item(&$a,&$b) {
148 if(strstr($b['output']['body'],'id="blockem-wrap-'))
149 $b['output']['thumb'] = $a->get_baseurl() . "/images/person-80.jpg";
153 function blockem_conversation_start(&$a,&$b) {
158 $words = get_pconfig(local_user(),'blockem','words');
160 $a->data['blockem'] = explode(',',$words);
162 $a->page['htmlhead'] .= <<< EOT
165 function blockemBlock(author) {
166 $.get('blockem?block=' +author, function(data) {
167 location.reload(true);
170 function blockemUnblock(author) {
171 $.get('blockem?unblock=' +author, function(data) {
172 location.reload(true);
181 function blockem_item_photo_menu(&$a,&$b) {
183 if((! local_user()) || ($b['item']['self']))
187 $author = $b['item']['author-link'];
188 if(is_array($a->data['blockem'])) {
189 foreach($a->data['blockem'] as $bloke) {
190 if(link_compare($bloke,$author)) {
197 $b['menu'][ t('Unblock Author')] = 'javascript:blockemUnblock(\'' . $author . '\');';
199 $b['menu'][ t('Block Author')] = 'javascript:blockemBlock(\'' . $author . '\');';
202 function blockem_module() {}
205 function blockem_init(&$a) {
210 $words = get_pconfig(local_user(),'blockem','words');
212 if(array_key_exists('block',$_GET) && $_GET['block']) {
215 $words .= trim($_GET['block']);
217 if(array_key_exists('unblock',$_GET) && $_GET['unblock']) {
218 $arr = explode(',',$words);
222 foreach($arr as $x) {
223 if(! link_compare(trim($x),trim($_GET['unblock'])))
227 $words = implode(',',$newarr);
230 set_pconfig(local_user(),'blockem','words',$words);
231 info( t('blockem settings updated') . EOL );