2013-04-29 06:22:45 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Name: superblock
|
|
|
|
* Description: block people
|
|
|
|
* Version: 1.0
|
|
|
|
* Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
|
2017-04-21 08:47:33 +02:00
|
|
|
*
|
2013-04-29 06:22:45 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-07 00:55:24 +01:00
|
|
|
use Friendica\Core\PConfig;
|
|
|
|
|
2013-04-29 06:22:45 +02:00
|
|
|
function superblock_install() {
|
|
|
|
|
|
|
|
register_hook('plugin_settings', 'addon/superblock/superblock.php', 'superblock_addon_settings');
|
|
|
|
register_hook('plugin_settings_post', 'addon/superblock/superblock.php', 'superblock_addon_settings_post');
|
|
|
|
register_hook('conversation_start', 'addon/superblock/superblock.php', 'superblock_conversation_start');
|
|
|
|
register_hook('item_photo_menu', 'addon/superblock/superblock.php', 'superblock_item_photo_menu');
|
2013-05-09 10:18:03 +02:00
|
|
|
register_hook('enotify_store', 'addon/superblock/superblock.php', 'superblock_enotify_store');
|
|
|
|
|
2013-04-29 06:22:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function superblock_uninstall() {
|
|
|
|
|
|
|
|
unregister_hook('plugin_settings', 'addon/superblock/superblock.php', 'superblock_addon_settings');
|
|
|
|
unregister_hook('plugin_settings_post', 'addon/superblock/superblock.php', 'superblock_addon_settings_post');
|
|
|
|
unregister_hook('conversation_start', 'addon/superblock/superblock.php', 'superblock_conversation_start');
|
|
|
|
unregister_hook('item_photo_menu', 'addon/superblock/superblock.php', 'superblock_item_photo_menu');
|
2013-05-09 10:18:03 +02:00
|
|
|
unregister_hook('enotify_store', 'addon/superblock/superblock.php', 'superblock_enotify_store');
|
2013-04-29 06:22:45 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function superblock_addon_settings(&$a,&$s) {
|
|
|
|
|
2017-04-21 08:47:33 +02:00
|
|
|
if(! local_user()) {
|
2013-04-29 06:22:45 +02:00
|
|
|
return;
|
2017-04-21 08:47:33 +02:00
|
|
|
}
|
2013-04-29 06:22:45 +02:00
|
|
|
|
2017-04-21 08:47:33 +02:00
|
|
|
/* Add our stylesheet to the page so we can make our settings look nice */
|
2013-04-29 06:22:45 +02:00
|
|
|
|
2017-04-21 08:47:33 +02:00
|
|
|
$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/superblock/superblock.css' . '" media="all" />' . "\r\n";
|
2013-04-29 06:22:45 +02:00
|
|
|
|
2017-11-07 00:55:24 +01:00
|
|
|
$words = PConfig::get(local_user(),'system','blocked');
|
2017-04-21 08:47:33 +02:00
|
|
|
if(! $words) {
|
2013-04-29 06:22:45 +02:00
|
|
|
$words = '';
|
2017-04-21 08:47:33 +02:00
|
|
|
}
|
2013-04-29 06:22:45 +02:00
|
|
|
|
2017-04-21 08:47:33 +02:00
|
|
|
$s .= '<span id="settings_superblock_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_superblock_expanded\'); openClose(\'settings_superblock_inflated\');">';
|
|
|
|
$s .= '<h3>' . t('"Superblock"') . '</h3>';
|
|
|
|
$s .= '</span>';
|
|
|
|
$s .= '<div id="settings_superblock_expanded" class="settings-block" style="display: none;">';
|
|
|
|
$s .= '<span class="fakelink" onclick="openClose(\'settings_superblock_expanded\'); openClose(\'settings_superblock_inflated\');">';
|
|
|
|
$s .= '<h3>' . t('"Superblock"') . '</h3>';
|
|
|
|
$s .= '</span>';
|
|
|
|
$s .= '<div id="superblock-wrapper">';
|
|
|
|
$s .= '<label id="superblock-label" for="superblock-words">' . t('Comma separated profile URLS to block') . ' </label>';
|
|
|
|
$s .= '<textarea id="superblock-words" type="text" name="superblock-words" >' . htmlspecialchars($words) . '</textarea>';
|
|
|
|
$s .= '</div><div class="clear"></div>';
|
2013-04-29 06:22:45 +02:00
|
|
|
|
2017-04-21 08:47:33 +02:00
|
|
|
$s .= '<div class="settings-submit-wrapper" ><input type="submit" id="superblock-submit" name="superblock-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div></div>';
|
2013-04-29 06:22:45 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
function superblock_addon_settings_post(&$a,&$b) {
|
|
|
|
|
|
|
|
if(! local_user())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if($_POST['superblock-submit']) {
|
2017-11-07 00:55:24 +01:00
|
|
|
PConfig::set(local_user(),'system','blocked',trim($_POST['superblock-words']));
|
2013-04-29 06:22:45 +02:00
|
|
|
info( t('SUPERBLOCK Settings saved.') . EOL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-09 10:18:03 +02:00
|
|
|
function superblock_enotify_store(&$a,&$b) {
|
|
|
|
|
2017-11-07 00:55:24 +01:00
|
|
|
$words = PConfig::get($b['uid'],'system','blocked');
|
2013-05-09 10:18:03 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-29 06:22:45 +02:00
|
|
|
function superblock_conversation_start(&$a,&$b) {
|
|
|
|
|
|
|
|
if(! local_user())
|
|
|
|
return;
|
|
|
|
|
2017-11-07 00:55:24 +01:00
|
|
|
$words = PConfig::get(local_user(),'system','blocked');
|
2013-04-29 06:22:45 +02:00
|
|
|
if($words) {
|
|
|
|
$a->data['superblock'] = explode(',',$words);
|
|
|
|
}
|
|
|
|
$a->page['htmlhead'] .= <<< EOT
|
|
|
|
|
|
|
|
<script>
|
|
|
|
function superblockBlock(author) {
|
|
|
|
$.get('superblock?block=' +author, function(data) {
|
|
|
|
location.reload(true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
EOT;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function superblock_item_photo_menu(&$a,&$b) {
|
|
|
|
|
|
|
|
if((! local_user()) || ($b['item']['self']))
|
|
|
|
return;
|
|
|
|
|
|
|
|
$blocked = false;
|
|
|
|
$author = $b['item']['author-link'];
|
|
|
|
if(is_array($a->data['superblock'])) {
|
|
|
|
foreach($a->data['superblock'] as $bloke) {
|
|
|
|
if(link_compare($bloke,$author)) {
|
|
|
|
$blocked = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-29 06:50:24 +02:00
|
|
|
$b['menu'][ t('Block Completely')] = 'javascript:superblockBlock(\'' . $author . '\'); return false;';
|
2013-04-29 06:22:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function superblock_module() {}
|
|
|
|
|
|
|
|
|
|
|
|
function superblock_init(&$a) {
|
|
|
|
|
|
|
|
if(! local_user())
|
|
|
|
return;
|
|
|
|
|
2017-11-07 00:55:24 +01:00
|
|
|
$words = PConfig::get(local_user(),'system','blocked');
|
2013-04-29 06:22:45 +02:00
|
|
|
|
|
|
|
if(array_key_exists('block',$_GET) && $_GET['block']) {
|
|
|
|
if(strlen($words))
|
|
|
|
$words .= ',';
|
|
|
|
$words .= trim($_GET['block']);
|
|
|
|
}
|
|
|
|
|
2017-11-07 00:55:24 +01:00
|
|
|
PConfig::set(local_user(),'system','blocked',$words);
|
2013-04-29 06:22:45 +02:00
|
|
|
info( t('superblock settings updated') . EOL );
|
|
|
|
killme();
|
|
|
|
}
|