friendica-addons/blockem/blockem.php

234 lines
6.1 KiB
PHP
Raw Normal View History

2012-01-10 04:16:09 -05:00
<?php
/**
* Name: blockem
* Description: block people
* Version: 1.0
* Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
*
*/
function blockem_install() {
register_hook('prepare_body', 'addon/blockem/blockem.php', 'blockem_prepare_body');
2012-01-10 19:54:47 -05:00
register_hook('display_item', 'addon/blockem/blockem.php', 'blockem_display_item');
2012-01-10 04:16:09 -05:00
register_hook('plugin_settings', 'addon/blockem/blockem.php', 'blockem_addon_settings');
register_hook('plugin_settings_post', 'addon/blockem/blockem.php', 'blockem_addon_settings_post');
2012-01-11 20:36:20 -05:00
register_hook('conversation_start', 'addon/blockem/blockem.php', 'blockem_conversation_start');
register_hook('item_photo_menu', 'addon/blockem/blockem.php', 'blockem_item_photo_menu');
2013-05-09 04:18:03 -04:00
register_hook('enotify_store', 'addon/blockem/blockem.php', 'blockem_enotify_store' );
2012-01-10 04:16:09 -05:00
}
function blockem_uninstall() {
unregister_hook('prepare_body', 'addon/blockem/blockem.php', 'blockem_prepare_body');
2012-01-10 19:54:47 -05:00
unregister_hook('display_item', 'addon/blockem/blockem.php', 'blockem_display_item');
2012-01-10 04:16:09 -05:00
unregister_hook('plugin_settings', 'addon/blockem/blockem.php', 'blockem_addon_settings');
unregister_hook('plugin_settings_post', 'addon/blockem/blockem.php', 'blockem_addon_settings_post');
2012-01-11 20:36:20 -05:00
unregister_hook('conversation_start', 'addon/blockem/blockem.php', 'blockem_conversation_start');
unregister_hook('item_photo_menu', 'addon/blockem/blockem.php', 'blockem_item_photo_menu');
2013-05-09 04:18:03 -04:00
unregister_hook('enotify_store', 'addon/blockem/blockem.php', 'blockem_enotify_store' );
2012-01-10 04:16:09 -05:00
}
function blockem_addon_settings(&$a,&$s) {
if(! local_user())
return;
/* Add our stylesheet to the page so we can make our settings look nice */
$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/blockem/blockem.css' . '" media="all" />' . "\r\n";
$words = get_pconfig(local_user(),'blockem','words');
if(! $words)
$words = '';
2013-11-30 15:18:37 -05:00
$s .= '<span id="settings_blockem_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_blockem_expanded\'); openClose(\'settings_blockem_inflated\');">';
2012-01-10 04:16:09 -05:00
$s .= '<h3>' . t('"Blockem" Settings') . '</h3>';
2013-11-30 15:18:37 -05:00
$s .= '</span>';
$s .= '<div id="settings_blockem_expanded" class="settings-block" style="display: none;">';
$s .= '<span class="fakelink" onclick="openClose(\'settings_blockem_expanded\'); openClose(\'settings_blockem_inflated\');">';
$s .= '<h3>' . t('"Blockem" Settings') . '</h3>';
$s .= '</span>';
2012-01-10 04:16:09 -05:00
$s .= '<div id="blockem-wrapper">';
$s .= '<label id="blockem-label" for="blockem-words">' . t('Comma separated profile URLS to block') . ' </label>';
2012-01-10 19:54:47 -05:00
$s .= '<textarea id="blockem-words" type="text" name="blockem-words" >' . htmlspecialchars($words) . '</textarea>';
2012-01-10 04:16:09 -05:00
$s .= '</div><div class="clear"></div>';
2013-11-19 07:43:58 -05:00
$s .= '<div class="settings-submit-wrapper" ><input type="submit" id="blockem-submit" name="blockem-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div></div>';
2012-01-10 04:16:09 -05:00
return;
}
function blockem_addon_settings_post(&$a,&$b) {
if(! local_user())
return;
if($_POST['blockem-submit']) {
set_pconfig(local_user(),'blockem','words',trim($_POST['blockem-words']));
info( t('BLOCKEM Settings saved.') . EOL);
}
}
2013-05-09 04:18:03 -04:00
function blockem_enotify_store(&$a,&$b) {
$words = get_pconfig($b['uid'],'blockem','words');
if($words) {
$arr = explode(',',$words);
}
else {
return;
}
$found = false;
if(count($arr)) {
foreach($arr as $word) {
if(! strlen(trim($word))) {
continue;
}
if(link_compare($b['url'],$word)) {
$found = true;
break;
}
}
}
if($found) {
$b['abort'] = true;
}
}
2012-01-10 04:16:09 -05:00
function blockem_prepare_body(&$a,&$b) {
if(! local_user())
return;
$words = null;
if(local_user()) {
$words = get_pconfig(local_user(),'blockem','words');
}
if($words) {
$arr = explode(',',$words);
}
else {
return;
}
$found = false;
if(count($arr)) {
foreach($arr as $word) {
if(! strlen(trim($word))) {
continue;
}
if(link_compare($b['item']['author-link'],$word)) {
$found = true;
break;
}
}
}
if($found) {
$rnd = random_string(8);
2012-01-10 19:54:47 -05:00
$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>';
2012-01-10 04:16:09 -05:00
}
}
2012-01-10 19:54:47 -05:00
function blockem_display_item(&$a,&$b) {
if(strstr($b['output']['body'],'id="blockem-wrap-'))
2012-03-20 18:44:53 -04:00
$b['output']['thumb'] = $a->get_baseurl() . "/images/person-80.jpg";
2012-01-10 19:54:47 -05:00
}
2012-01-11 20:36:20 -05:00
function blockem_conversation_start(&$a,&$b) {
if(! local_user())
return;
$words = get_pconfig(local_user(),'blockem','words');
if($words) {
$a->data['blockem'] = explode(',',$words);
}
$a->page['htmlhead'] .= <<< EOT
<script>
function blockemBlock(author) {
$.get('blockem?block=' +author, function(data) {
location.reload(true);
});
}
function blockemUnblock(author) {
$.get('blockem?unblock=' +author, function(data) {
location.reload(true);
});
}
</script>
EOT;
}
function blockem_item_photo_menu(&$a,&$b) {
2012-01-11 20:52:53 -05:00
if((! local_user()) || ($b['item']['self']))
return;
2012-01-11 20:36:20 -05:00
$blocked = false;
$author = $b['item']['author-link'];
if(is_array($a->data['blockem'])) {
foreach($a->data['blockem'] as $bloke) {
if(link_compare($bloke,$author)) {
$blocked = true;
break;
}
}
}
if($blocked)
2012-08-14 17:10:19 -04:00
$b['menu'][ t('Unblock Author')] = 'javascript:blockemUnblock(\'' . $author . '\');';
2012-01-11 20:36:20 -05:00
else
2012-08-14 17:10:19 -04:00
$b['menu'][ t('Block Author')] = 'javascript:blockemBlock(\'' . $author . '\');';
2012-01-11 20:36:20 -05:00
}
function blockem_module() {}
function blockem_init(&$a) {
if(! local_user())
return;
$words = get_pconfig(local_user(),'blockem','words');
if(array_key_exists('block',$_GET) && $_GET['block']) {
if(strlen($words))
$words .= ',';
$words .= trim($_GET['block']);
}
if(array_key_exists('unblock',$_GET) && $_GET['unblock']) {
$arr = explode(',',$words);
$newarr = array();
if(count($arr)) {
foreach($arr as $x) {
if(! link_compare(trim($x),trim($_GET['unblock'])))
$newarr[] = $x;
}
}
$words = implode(',',$newarr);
}
set_pconfig(local_user(),'blockem','words',$words);
info( t('blockem settings updated') . EOL );
killme();
}