X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=fbpost%2Ffbpost.php;h=72373ff949d9678834716a2a679e2c42eea4cb07;hb=18a17e33bcf47840d1824ee8cf7094483fd4f068;hp=38fe192039d8dee3b51996e73590ee2b24ff96d8;hpb=76a8623053ae12e4dcb0e63c58e5a14d0a46ba62;p=friendica-addons.git diff --git a/fbpost/fbpost.php b/fbpost/fbpost.php index 38fe1920..72373ff9 100644 --- a/fbpost/fbpost.php +++ b/fbpost/fbpost.php @@ -4,6 +4,7 @@ * Version: 1.3 * Author: Mike Macgirvin * Author: Tobias Hößl + * Status: Unsupported * */ @@ -248,9 +249,10 @@ function fbpost_content(&$a) { $o .= '
'; //read_stream,publish_stream,manage_pages,photo_upload,user_groups,offline_access + //export_stream,read_stream,publish_stream,manage_pages,photo_upload,user_groups,publish_actions,user_friends,share_item,video_upload,status_update - $o .= '' . t('Install Facebook Post connector for this account.') . ''; + $o .= '' . t('Install Facebook Post connector for this account.') . ''; $o .= '
'; } @@ -261,8 +263,10 @@ function fbpost_content(&$a) { $o .= '
'; - $o .= '' . t('Re-authenticate [This is necessary whenever your Facebook password is changed.]') . ''; + //export_stream,read_stream,publish_stream,manage_pages,photo_upload,user_groups,publish_actions,user_friends,share_item,video_upload,status_update + + $o .= '' . t('Re-authenticate [This is necessary whenever your Facebook password is changed.]') . ''; $o .= '
'; $o .= '
'; @@ -428,6 +432,9 @@ function fbpost_post_hook(&$a,&$b) { logger('fbpost_post_hook: Facebook post first check successful', LOGGER_DEBUG); // if post comes from facebook don't send it back + if($b['extid'] == NETWORK_FACEBOOK) + return; + if(($b['app'] == "Facebook") AND ($b['verb'] != ACTIVITY_LIKE)) return; @@ -982,15 +989,21 @@ function fbpost_cleanpicture($url) { function fbpost_fetchwall($a, $uid) { require_once("include/oembed.php"); require_once("include/network.php"); - require_once('mod/item.php'); + require_once("include/items.php"); + require_once("mod/item.php"); + require_once("include/bbcode.php"); $access_token = get_pconfig($uid,'facebook','access_token'); $post_to_page = get_pconfig($uid,'facebook','post_to_page'); + $mirror_page = get_pconfig($uid,'facebook','mirror_page'); $lastcreated = get_pconfig($uid,'facebook','last_created'); if ((int)$post_to_page == 0) $post_to_page = "me"; + if ((int)$mirror_page != 0) + $post_to_page = $mirror_page; + $url = "https://graph.facebook.com/".$post_to_page."/feed?access_token=".$access_token; $first_time = ($lastcreated == ""); @@ -1016,7 +1029,11 @@ function fbpost_fetchwall($a, $uid) { if ($item->application->id == get_config('facebook','appid')) continue; - if(isset($item->privacy) && ($item->privacy->value !== 'EVERYONE') && ($item->privacy->value !== '')) + if(isset($item->privacy) && ($item->privacy->value !== 'EVERYONE') && ((int)$mirror_page == 0)) + continue; + elseif(isset($item->privacy) && ($item->privacy->value !== 'EVERYONE') && ($item->privacy->value !== '')) + continue; + elseif(!isset($item->privacy)) continue; if (($post_to_page != $item->from->id) AND ((int)$post_to_page != 0)) @@ -1032,19 +1049,24 @@ function fbpost_fetchwall($a, $uid) { $_REQUEST["type"] = "wall"; $_REQUEST["api_source"] = true; $_REQUEST["profile_uid"] = $uid; - $_REQUEST["source"] = "Facebook"; + //$_REQUEST["source"] = "Facebook"; + $_REQUEST["source"] = $item->application->name; + $_REQUEST["extid"] = NETWORK_FACEBOOK; $_REQUEST["title"] = ""; $_REQUEST["body"] = (isset($item->message) ? escape_tags($item->message) : ''); + $pagedata = array(); $content = ""; - $type = ""; + $pagedata["type"] = ""; if(isset($item->name) and isset($item->link)) { $item->link = original_url($item->link); $oembed_data = oembed_fetch_url($item->link); - $type = $oembed_data->type; + $pagedata["type"] = $oembed_data->type; + $pagedata["url"] = $item->link; + $pagedata["title"] = $item->name; $content = "[bookmark=".$item->link."]".$item->name."[/bookmark]"; // If a link is not only attached but also added in the body, look if it can be removed in the body. @@ -1056,70 +1078,77 @@ function fbpost_fetchwall($a, $uid) { } elseif (isset($item->name)) $content .= "[b]".$item->name."[/b]"; - $quote = ""; + $pagedata["text"] = ""; if(isset($item->description) and ($item->type != "photo")) - $quote = $item->description; + $pagedata["text"] = $item->description; if(isset($item->caption) and ($item->type == "photo")) - $quote = $item->caption; + $pagedata["text"] = $item->caption; // 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 (($type == "") OR ($type == "link")) { + if (($pagedata["type"] == "") OR ($pagedata["type"] == "link")) { - $type = $item->type; + $pagedata["type"] = $item->type; if (isset($item->picture)) - $picture = $item->picture; + $pagedata["images"][0]["src"] = $item->picture; - if (($type == "photo") AND isset($item->object_id)) { + if (($pagedata["type"] == "photo") AND isset($item->object_id)) { logger('fbpost_fetchwall: fetching fbid '.$item->object_id, LOGGER_DEBUG); $url = "https://graph.facebook.com/".$item->object_id."?access_token=".$access_token; $feed = fetch_url($url); $data = json_decode($feed); if (isset($data->images)) { - $picture = $data->images[0]->source; - logger('fbpost_fetchwall: got fbid image '.$preview, LOGGER_DEBUG); + $pagedata["images"][0]["src"] = $data->images[0]->source; + logger('got fbid image from images for '.$item->object_id, LOGGER_DEBUG); + } elseif (isset($data->source)) { + $pagedata["images"][0]["src"] = $data->source; + logger('got fbid image from source for '.$item->object_id, LOGGER_DEBUG); + } elseif (isset($data->picture)) { + $pagedata["images"][0]["src"] = $data->picture; + logger('got fbid image from picture for '.$item->object_id, LOGGER_DEBUG); } } - $picture = fbpost_cleanpicture($picture); + if(trim($_REQUEST["body"].$content.$pagedata["text"]) == '') { + logger('facebook: empty body 1 '.$item->id.' '.print_r($item, true)); + continue; + } + + $pagedata["images"][0]["src"] = fbpost_cleanpicture($pagedata["images"][0]["src"]); - if(($picture != "") && isset($item->link)) { + if(($pagedata["images"][0]["src"] != "") && isset($item->link)) { $item->link = original_url($item->link); - $content .= "\n".'[url='.$item->link.'][img]'.$picture.'[/img][/url]'; + $pagedata["url"] = $item->link; + $content .= "\n".'[url='.$item->link.'][img]'.$pagedata["images"][0]["src"].'[/img][/url]'; } else { - if ($picture != "") - $content .= "\n".'[img]'.$picture.'[/img]'; + if ($pagedata["images"][0]["src"] != "") + $content .= "\n".'[img]'.$pagedata["images"][0]["src"].'[/img]'; // if just a link, it may be a wall photo - check if(isset($item->link)) $content .= fbpost_get_photo($uid,$item->link); } } - if(trim($_REQUEST["body"].$content.$quote) == '') { - logger('facebook: empty body '.$item->id.' '.print_r($item, true)); + if(trim($_REQUEST["body"].$content.$pagedata["text"]) == '') { + logger('facebook: empty body 2 '.$item->id.' '.print_r($item, true)); continue; } - if ($content) - $_REQUEST["body"] .= "\n"; - - if ($type) - $_REQUEST["body"] .= "[class=type-".$type."]"; - - if ($content) - $_REQUEST["body"] .= trim($content); + if ($pagedata["type"] != "") + $_REQUEST["body"] .= add_page_info_data($pagedata); + else { + if ($content) + $_REQUEST["body"] .= "\n".trim($content); - if ($quote) - $_REQUEST["body"] .= "\n[quote]".$quote."[/quote]"; + if ($pagedata["text"]) + $_REQUEST["body"] .= "\n[quote]".$pagedata["text"]."[/quote]"; - if ($type) - $_REQUEST["body"] .= "[/class]"; - - $_REQUEST["body"] = trim($_REQUEST["body"]); + $_REQUEST["body"] = trim($_REQUEST["body"]); + } if (isset($item->place)) { if ($item->place->name or $item->place->location->street or @@ -1141,6 +1170,17 @@ function fbpost_fetchwall($a, $uid) { .' '.substr($item->place->location->longitude, 0, 8); } + if(trim($_REQUEST["body"]) == '') { + logger('facebook: empty body 3 '.$item->id.' '.print_r($item, true)); + continue; + } + + if(trim(strip_tags(bbcode($_REQUEST["body"], false, false))) == '') { + logger('facebook: empty body 4 '.$item->id.' '.print_r($item, true)); + continue; + } + + //print_r($_REQUEST); logger('facebook: posting for user '.$uid); item_post($a);