]> git.mxchange.org Git - friendica-addons.git/blobdiff - blockem/blockem.php
Issue 3873
[friendica-addons.git] / blockem / blockem.php
index 43f34554e24071cc92a492c2121a4b8d244f8632..d8855886c0c751ccd203b6a4c565ecc4205428e1 100755 (executable)
@@ -9,6 +9,8 @@
  * 
  */
 
+use Friendica\Core\PConfig;
+
 function blockem_install() {
        register_hook('prepare_body', 'addon/blockem/blockem.php', 'blockem_prepare_body');
        register_hook('display_item', 'addon/blockem/blockem.php', 'blockem_display_item');
@@ -16,6 +18,7 @@ function blockem_install() {
        register_hook('plugin_settings_post', 'addon/blockem/blockem.php', 'blockem_addon_settings_post');
        register_hook('conversation_start', 'addon/blockem/blockem.php', 'blockem_conversation_start');
        register_hook('item_photo_menu', 'addon/blockem/blockem.php', 'blockem_item_photo_menu');
+       register_hook('enotify_store', 'addon/blockem/blockem.php', 'blockem_enotify_store' );
 }
 
 
@@ -26,6 +29,7 @@ function blockem_uninstall() {
        unregister_hook('plugin_settings_post', 'addon/blockem/blockem.php', 'blockem_addon_settings_post');
        unregister_hook('conversation_start', 'addon/blockem/blockem.php', 'blockem_conversation_start');
        unregister_hook('item_photo_menu', 'addon/blockem/blockem.php', 'blockem_item_photo_menu');
+       unregister_hook('enotify_store', 'addon/blockem/blockem.php', 'blockem_enotify_store' );
 
 }
 
@@ -43,18 +47,24 @@ function blockem_addon_settings(&$a,&$s) {
     $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');
+       $words = PConfig::get(local_user(),'blockem','words');
        if(! $words)
                $words = '';
 
-    $s .= '<div class="settings-block">';
-    $s .= '<h3>' . t('"Blockem" Settings') . '</h3>';
+    $s .= '<span id="settings_blockem_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_blockem_expanded\'); openClose(\'settings_blockem_inflated\');">';
+    $s .= '<h3>' . t('"Blockem"') . '</h3>';
+    $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"') . '</h3>';
+    $s .= '</span>';
+
     $s .= '<div id="blockem-wrapper">';
     $s .= '<label id="blockem-label" for="blockem-words">' . t('Comma separated profile URLS to block') . ' </label>';
     $s .= '<textarea id="blockem-words" type="text" name="blockem-words" >' . htmlspecialchars($words) . '</textarea>';
     $s .= '</div><div class="clear"></div>';
 
-    $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="blockem-submit" name="blockem-submit" class="settings-submit" value="' . t('Submit') . '" /></div></div>';
+    $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="blockem-submit" name="blockem-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div></div>';
 
        return;
 
@@ -66,11 +76,40 @@ function blockem_addon_settings_post(&$a,&$b) {
                return;
 
        if($_POST['blockem-submit']) {
-               set_pconfig(local_user(),'blockem','words',trim($_POST['blockem-words']));
+               PConfig::set(local_user(),'blockem','words',trim($_POST['blockem-words']));
                info( t('BLOCKEM Settings saved.') . EOL);
        }
 }
 
+
+function blockem_enotify_store(&$a,&$b) {
+
+       $words = PConfig::get($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;
+       }
+}
+
 function blockem_prepare_body(&$a,&$b) {
 
        if(! local_user())
@@ -78,7 +117,7 @@ function blockem_prepare_body(&$a,&$b) {
 
        $words = null;
        if(local_user()) {
-               $words = get_pconfig(local_user(),'blockem','words');
+               $words = PConfig::get(local_user(),'blockem','words');
        }
        if($words) {
                $arr = explode(',',$words);
@@ -101,15 +140,15 @@ function blockem_prepare_body(&$a,&$b) {
                }
        }
        if($found) {
-               $rnd = random_string(8);        
+               $rnd = random_string(8);
                $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>';  
        }
 }
 
 
 function blockem_display_item(&$a,&$b) {
-       if(strstr($b['output'],'id="blockem-wrap-'))
-               $b['output'] = preg_replace('/\<img(.*?)src=\"(.*?)\" class=\"wall\-item\-photo(.*?)\>/','<img$1src="' . $a->get_baseurl() . "/images/default-profile-sm.jpg" . '" class="wall-item-photo$3>',$b['output']);
+       if(strstr($b['output']['body'],'id="blockem-wrap-'))
+               $b['output']['thumb'] = $a->get_baseurl() . "/images/person-80.jpg";
 }
 
 
@@ -118,7 +157,7 @@ function blockem_conversation_start(&$a,&$b) {
        if(! local_user())
                return;
 
-       $words = get_pconfig(local_user(),'blockem','words');
+       $words = PConfig::get(local_user(),'blockem','words');
        if($words) {
                $a->data['blockem'] = explode(',',$words);
        }
@@ -157,9 +196,9 @@ function blockem_item_photo_menu(&$a,&$b) {
                }
        }
        if($blocked)
-               $b['menu'][ t('Unblock Author')] = 'javascript:blockemUnblock("' . $author . '");';
+               $b['menu'][ t('Unblock Author')] = 'javascript:blockemUnblock(\'' . $author . '\');';
        else
-               $b['menu'][ t('Block Author')] = 'javascript:blockemBlock("' . $author . '");';
+               $b['menu'][ t('Block Author')] = 'javascript:blockemBlock(\'' . $author . '\');';
 }
 
 function blockem_module() {}
@@ -170,7 +209,7 @@ function blockem_init(&$a) {
        if(! local_user())
                return;
 
-       $words = get_pconfig(local_user(),'blockem','words');
+       $words = PConfig::get(local_user(),'blockem','words');
 
        if(array_key_exists('block',$_GET) && $_GET['block']) {
                if(strlen($words))
@@ -190,7 +229,7 @@ function blockem_init(&$a) {
                $words = implode(',',$newarr);
        }
 
-       set_pconfig(local_user(),'blockem','words',$words);
+       PConfig::set(local_user(),'blockem','words',$words);
        info( t('blockem settings updated') . EOL );
        killme();
-}
\ No newline at end of file
+}