]> git.mxchange.org Git - friendica-addons.git/blobdiff - fbpost/fbpost.php
Merge pull request #125 from tobiasd/impressum
[friendica-addons.git] / fbpost / fbpost.php
index cdb1f05ac28d620618f4a222083c1bb7733aabf0..ba60f4e64bdca3b6eb7c62ddbec399f340f7e2af 100644 (file)
@@ -213,7 +213,7 @@ function fbpost_content(&$a) {
                $o .= '<div id="fbpost-enable-wrapper">';
 
                $o .= '<a href="https://www.facebook.com/dialog/oauth?client_id=' . $appid . '&redirect_uri=' 
-                       . $a->get_baseurl() . '/fbpost/' . $a->user['nickname'] . '&scope=publish_stream,manage_pages,photo_upload,user_groups,offline_access">' . t('Install Facebook Post connector for this account.') . '</a>';
+                       . $a->get_baseurl() . '/fbpost/' . $a->user['nickname'] . '&scope=read_stream,publish_stream,manage_pages,photo_upload,user_groups,offline_access">' . t('Install Facebook Post connector for this account.') . '</a>';
                $o .= '</div>';
        }
 
@@ -225,7 +225,7 @@ function fbpost_content(&$a) {
                $o .= '<div id="fbpost-enable-wrapper">';
 
                $o .= '<a href="https://www.facebook.com/dialog/oauth?client_id=' . $appid . '&redirect_uri=' 
-                       . $a->get_baseurl() . '/fbpost/' . $a->user['nickname'] . '&scope=publish_stream,manage_pages,photo_upload,user_groups,offline_access">' . t('Re-authenticate [This is necessary whenever your Facebook password is changed.]') . '</a>';
+                       . $a->get_baseurl() . '/fbpost/' . $a->user['nickname'] . '&scope=read_stream,publish_stream,manage_pages,photo_upload,user_groups,offline_access">' . t('Re-authenticate [This is necessary whenever your Facebook password is changed.]') . '</a>';
                $o .= '</div>';
 
                $o .= '<div id="fbpost-post-default-form">';
@@ -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;
@@ -1008,28 +1012,42 @@ function fbpost_cron($a,$b) {
 
 function fbpost_fetchwall($a, $uid) {
        $access_token = get_pconfig($uid,'facebook','access_token');
+       $post_to_page = get_pconfig($uid,'facebook','post_to_page');
        $lastcreated = get_pconfig($uid,'facebook','last_created');
-       $lastcreated = "";
 
-       $url = 'https://graph.facebook.com/me/feed?access_token='.$access_token;
+       if ((int)$post_to_page == 0)
+               $post_to_page = "me";
+
+       $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')
+               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;
@@ -1046,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
@@ -1058,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]";
@@ -1074,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 {
@@ -1085,10 +1107,11 @@ function fbpost_fetchwall($a, $uid) {
                        }
                }
 
-               if (($datarray['app'] == "Events") and isset($item->actions))
+               /*if (($datarray['app'] == "Events") and isset($item->actions))
                        foreach ($item->actions as $action)
                                if ($action->name == "View")
                                        $_REQUEST["body"] .= " [url=".$action->link."]".$item->story."[/url]";
+               */
 
                if(trim($_REQUEST["body"]) == '') {
                        logger('facebook: empty body '.$item->id.' '.print_r($item, true));