]> git.mxchange.org Git - friendica-addons.git/blobdiff - fbpost/fbpost.php
template for admin config dialog
[friendica-addons.git] / fbpost / fbpost.php
index 0c7e454a1664d0bad828f9786cc2e30db53399d5..ba60f4e64bdca3b6eb7c62ddbec399f340f7e2af 100644 (file)
@@ -394,6 +394,10 @@ function fbpost_post_hook(&$a,&$b) {
        if($b['deleted'] || ($b['created'] !== $b['edited']))
                return;
 
+       // Don't transmit answers (have to be cleaned up in the following code)
+       if($b['parent'] != $b['id'])
+               return;
+
        // if post comes from facebook don't send it back
        if($b['app'] == "Facebook")
                return;
@@ -1016,23 +1020,35 @@ function fbpost_fetchwall($a, $uid) {
 
        $url = "https://graph.facebook.com/".$post_to_page."/feed?access_token=".$access_token;
 
+       $first_time = ($lastcreated == "");
+
        if ($lastcreated != "")
                $url .= "&since=".urlencode($lastcreated);
 
        $feed = fetch_url($url);
        $data = json_decode($feed);
+
+       if (!is_array($data->data))
+               return;
+
        $items = array_reverse($data->data);
 
        foreach ($items as $item) {
                if ($item->created_time > $lastcreated)
                        $lastcreated = $item->created_time;
 
+               if ($first_time)
+                       continue;
+
                if ($item->application->id == get_config('facebook','appid'))
                        continue;
 
                if(isset($item->privacy) && ($item->privacy->value !== 'EVERYONE') && ($item->privacy->value !== ''))
                        continue;
 
+               if (($post_to_page != $item->from->id) AND ((int)$post_to_page != 0))
+                       continue;
+
                $_SESSION["authenticated"] = true;
                $_SESSION["uid"] = $uid;
 
@@ -1048,7 +1064,7 @@ function fbpost_fetchwall($a, $uid) {
                elseif (isset($item->name))
                        $_REQUEST["body"] .= "\n\n[b]" . $item->name."[/b]";
 
-               if(isset($item->caption)) {
+               /*if(isset($item->caption)) {
                        if(!isset($item->name) and isset($item->link))
                                $_REQUEST["body"] .= "\n\n[bookmark=".$item->link."]".$item->caption."[/bookmark]";
                        //else
@@ -1060,15 +1076,18 @@ function fbpost_fetchwall($a, $uid) {
                                        $_REQUEST["body"] .= "\n[url]".$item->link."[/url]\n";
                                else
                                        $_REQUEST["body"] .= "\n";
-               }
+               }*/
 
                $quote = "";
-               if(isset($item->description))
+               if(isset($item->description) and ($item->type != "photo"))
                        $quote = $item->description;
 
-               if (isset($item->properties))
-                       foreach ($item->properties as $property)
-                               $quote .= "\n".$property->name.": [url=".$property->href."]".$property->text."[/url]";
+               if(isset($item->caption) and ($item->type == "photo"))
+                       $quote = $item->caption;
+
+               //if (isset($item->properties))
+               //      foreach ($item->properties as $property)
+               //              $quote .= "\n".$property->name.": [url=".$property->href."]".$property->text."[/url]";
 
                if ($quote)
                        $_REQUEST["body"] .= "\n[quote]".$quote."[/quote]";
@@ -1076,6 +1095,7 @@ function fbpost_fetchwall($a, $uid) {
                // Only import the picture when the message is no video
                // oembed display a picture of the video as well
                if ($item->type != "video") {
+               //if (($item->type != "video") and ($item->type != "photo")) {
                        if(isset($item->picture) && isset($item->link))
                                $_REQUEST["body"] .= "\n".'[url='.$item->link.'][img]'.fpost_cleanpicture($item->picture).'[/img][/url]';
                        else {