]> git.mxchange.org Git - friendica-addons.git/blobdiff - fromgplus/fromgplus.php
fromgplus: Picture posts had doubled content due to some strange unicode character.
[friendica-addons.git] / fromgplus / fromgplus.php
index 94b12af345647ce815c0ab1d8026bd0dcd53ed3c..5269f7a079f47c509119a34c152e1d0838b665dc 100644 (file)
 define('FROMGPLUS_DEFAULT_POLL_INTERVAL', 30); // given in minutes
 
 function fromgplus_install() {
-       register_hook('plugin_settings', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings');
-       register_hook('plugin_settings_post', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings_post');
+       register_hook('connector_settings', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings');
+       register_hook('connector_settings_post', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings_post');
        register_hook('cron', 'addon/fromgplus/fromgplus.php', 'fromgplus_cron');
 }
 
 function fromgplus_uninstall() {
+       unregister_hook('connector_settings', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings');
+       unregister_hook('connector_settings_post', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings_post');
+       unregister_hook('cron', 'addon/fromgplus/fromgplus.php', 'fromgplus_cron');
+
+       // Old hooks
        unregister_hook('plugin_settings', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings');
        unregister_hook('plugin_settings_post', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings_post');
-       unregister_hook('cron', 'addon/fromgplus/fromgplus.php', 'fromgplus_cron');
 }
 
 function fromgplus_addon_settings(&$a,&$s) {
@@ -97,6 +101,10 @@ function fromgplus_post($a, $uid, $source, $body, $location) {
 
        //$uid = 2;
 
+       // Don't know what it is. Maybe some trash from the mobile client
+       $trash = html_entity_decode("", ENT_QUOTES, 'UTF-8');
+       $body = str_replace($trash, "", $body);
+
        $body = trim($body);
 
         if (substr($body, 0, 3) == "[b]") {
@@ -218,6 +226,18 @@ function fromgplus_cleanupgoogleproxy($fullImage, $image) {
        return($cleaned);
 }
 
+function fromgplus_cleantext($text) {
+
+       // Don't know what it is. But it is added to the text.
+       $trash = html_entity_decode("", ENT_QUOTES, 'UTF-8');
+
+       $text = strip_tags($text);
+       $text = html_entity_decode($text);
+       $text = trim($text);
+       $text = str_replace(array("\n", "\r", " ", $trash), array("", "", "", ""), $text);
+       return($text);
+}
+
 function fromgplus_handleattachments($item, $displaytext) {
        $post = "";
        $quote = "";
@@ -239,9 +259,11 @@ function fromgplus_handleattachments($item, $displaytext) {
                                $post .= "\n\n[bookmark=".$attachment->url."]".fromgplus_html2bbcode($attachment->displayName)."[/bookmark]\n";
 
                                $images = fromgplus_cleanupgoogleproxy($attachment->fullImage, $attachment->image);
-                               if ($images["preview"] != "")
-                                       $post .= "\n[url=".$images["full"]."][img]".$images["preview"]."[/img][/url]\n";
-                               elseif ($images["full"] != "")
+                               //if ($images["preview"] != "")
+                               //      $post .= "\n[url=".$images["full"]."][img]".$images["preview"]."[/img][/url]\n";
+                               //elseif ($images["full"] != "")
+                               //      $post .= "\n[img]".$images["full"]."[/img]\n";
+                               if ($images["full"] != "")
                                        $post .= "\n[img]".$images["full"]."[/img]\n";
 
                                //$post .= "[quote]".trim(fromgplus_html2bbcode($attachment->content))."[/quote]";
@@ -257,7 +279,7 @@ function fromgplus_handleattachments($item, $displaytext) {
                                elseif ($images["full"] != "")
                                        $post .= "\n[img]".$images["full"]."[/img]\n";
 
-                               if (($attachment->displayName != "") AND ($attachment->displayName != $displaytext))
+                               if (($attachment->displayName != "") AND (fromgplus_cleantext($attachment->displayName) != fromgplus_cleantext($displaytext)))
                                        $post .= fromgplus_html2bbcode($attachment->displayName)."\n";
                                break;
 
@@ -294,6 +316,9 @@ function fromgplus_handleattachments($item, $displaytext) {
 function fromgplus_fetch($a, $uid) {
        $maxfetch = 20;
 
+       // Special blank to identify postings from the googleplus connector
+       $blank = html_entity_decode(" ", ENT_QUOTES, 'UTF-8');
+
        $account = get_pconfig($uid,'fromgplus','account');
        $key = get_config('fromgplus','key');
 
@@ -320,6 +345,15 @@ function fromgplus_fetch($a, $uid) {
                        $lastdate = strtotime($item->published);
 
                if ($item->access->description == "Public")
+
+                       // Loop prevention - ignore postings from HootSuite
+                       if ($item->provider->title == "HootSuite")
+                               continue;
+
+                       // Loop prevention through the special blank from the googleplus connector
+                       if (strstr($item->object->content, $blank))
+                               continue;
+
                        switch($item->object->objectType) {
                                case "note":
                                        $post = fromgplus_html2bbcode($item->object->content);
@@ -333,9 +367,7 @@ function fromgplus_fetch($a, $uid) {
                                        else
                                                $location = "";
 
-                                       // Loop prevention - should be made better
-                                       if ($item->provider->title != "HootSuite")
-                                               fromgplus_post($a, $uid, "Google+", $post, $location);
+                                       fromgplus_post($a, $uid, "Google+", $post, $location);
                                        //fromgplus_post($a, $uid, $item->provider->title, $post, $location);
 
                                        break;
@@ -343,7 +375,7 @@ function fromgplus_fetch($a, $uid) {
                                case "activity":
                                        $post = fromgplus_html2bbcode($item->annotation)."\n";
 
-                                       if (intval(get_config('system','new_share'))) {
+                                       if (!intval(get_config('system','old_share'))) {
                                                $post .= "[share author='".str_replace("'", "'",$item->object->actor->displayName).
                                                                "' profile='".$item->object->actor->url.
                                                                "' avatar='".$item->object->actor->image->url.
@@ -369,9 +401,7 @@ function fromgplus_fetch($a, $uid) {
                                        else
                                                $location = "";
 
-                                       // Loop prevention - should be made better
-                                       if ($item->provider->title != "HootSuite")
-                                               fromgplus_post($a, $uid, "Google+", $post, $location);
+                                       fromgplus_post($a, $uid, "Google+", $post, $location);
                                        //fromgplus_post($a, $uid, $item->provider->title, $post, $location);
                                        break;
                        }