]> git.mxchange.org Git - friendica-addons.git/blobdiff - fbsync/fbsync.php
Merge pull request #211 from tobiasd/20140622
[friendica-addons.git] / fbsync / fbsync.php
index fc9d7c187db0ed2b5254737cc3b94437e39cc01c..51d2747f93d8640570032d8eda81f575c796b412 100644 (file)
@@ -213,6 +213,8 @@ function fbsync_expire($a,$b) {
 
 function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $create_user) {
 
+       $access_token = get_pconfig($uid,'facebook','access_token');
+
        require_once("include/oembed.php");
 
        // check if it was already imported
@@ -343,6 +345,13 @@ function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $cr
                        $type = "link";
 
                $content = "[bookmark=".$post->attachment->href."]".$post->attachment->name."[/bookmark]";
+
+               // If a link is not only attached but also added in the body, look if it can be removed in the body.
+               $removedlink = trim(str_replace($post->attachment->href, "", $postarray["body"]));
+
+               if (($removedlink == "") OR strstr($postarray["body"], $removedlink))
+                       $postarray["body"] = $removedlink;
+
        } elseif (isset($post->attachment->name) AND ($post->attachment->name != ""))
                $content = "[b]" . $post->attachment->name."[/b]";
 
@@ -365,10 +374,23 @@ function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $cr
                        if (isset($media->src))
                                $preview = $media->src;
 
-                       if (isset($media->photo))
+                       if (isset($media->photo)) {
                                if (isset($media->photo->images) AND (count($media->photo->images) > 1))
                                        $preview = $media->photo->images[1]->src;
 
+                               if (isset($media->photo->fbid)) {
+                                       logger('fbsync_createpost: fetching fbid '.$media->photo->fbid, LOGGER_DEBUG);
+                                       $url = "https://graph.facebook.com/".$media->photo->fbid."?access_token=".$access_token;
+                                       $feed = fetch_url($url);
+                                       $data = json_decode($feed);
+                                       if (isset($data->images)) {
+                                               $preview = $data->images[0]->source;
+                                               logger('fbsync_createpost: got fbid '.$media->photo->fbid.' image '.$preview, LOGGER_DEBUG);
+                                       } else
+                                               logger('fbsync_createpost: error fetching fbid '.$media->photo->fbid.' '.print_r($data, true), LOGGER_DEBUG);
+                               }
+                       }
+
                        if (isset($media->href) AND ($preview != "") AND ($media->href != ""))
                                $content .= "\n".'[url='.$media->href.'][img]'.$preview.'[/img][/url]';
                        else {
@@ -610,8 +632,7 @@ function fbsync_createcomment($a, $uid, $self_id, $self, $user, $contacts, $appl
                                        'to_email'     => $user[0]['email'],
                                        'uid'          => $user[0]['uid'],
                                        'item'         => $postarray,
-                                       //'link'         => $a->get_baseurl() . '/display/' . $user[0]['nickname'] . '/' . $item,
-                                       'link'         => $a->get_baseurl().'/display/'.get_item_guid($item),
+                                       'link'         => $a->get_baseurl().'/display/'.urlencode(get_item_guid($item)),
                                        'source_name'  => $postarray['author-name'],
                                        'source_link'  => $postarray['author-link'],
                                        'source_photo' => $postarray['author-avatar'],