Design improvements for importing posts from twitter, facebook and G+

This commit is contained in:
Michael Vogel 2013-12-08 15:00:49 +01:00
parent e564d0e94a
commit 70742b56c2
4 changed files with 109 additions and 72 deletions

View File

@ -982,6 +982,8 @@ function fbpost_cron($a,$b) {
} }
function fbpost_fetchwall($a, $uid) { function fbpost_fetchwall($a, $uid) {
require_once("include/oembed.php");
$access_token = get_pconfig($uid,'facebook','access_token'); $access_token = get_pconfig($uid,'facebook','access_token');
$post_to_page = get_pconfig($uid,'facebook','post_to_page'); $post_to_page = get_pconfig($uid,'facebook','post_to_page');
$lastcreated = get_pconfig($uid,'facebook','last_created'); $lastcreated = get_pconfig($uid,'facebook','last_created');
@ -1036,24 +1038,15 @@ function fbpost_fetchwall($a, $uid) {
$_REQUEST["body"] = (isset($item->message) ? escape_tags($item->message) : ''); $_REQUEST["body"] = (isset($item->message) ? escape_tags($item->message) : '');
if(isset($item->name) and isset($item->link)) $content = "";
$_REQUEST["body"] .= "\n\n[bookmark=".$item->link."]".$item->name."[/bookmark]"; $type = "";
elseif (isset($item->name))
$_REQUEST["body"] .= "\n\n[b]" . $item->name."[/b]";
/*if(isset($item->caption)) { if(isset($item->name) and isset($item->link)) {
if(!isset($item->name) and isset($item->link)) $oembed_data = oembed_fetch_url($item->link);
$_REQUEST["body"] .= "\n\n[bookmark=".$item->link."]".$item->caption."[/bookmark]"; $type = $oembed_data->type;
//else $content = "[bookmark=".$item->link."]".$item->name."[/bookmark]";
// $_REQUEST["body"] .= "[i]" . $item->caption."[/i]\n"; } elseif (isset($item->name))
} $content .= "[b]".$item->name."[/b]";
if(!isset($item->caption) and !isset($item->name)) {
if (isset($item->link))
$_REQUEST["body"] .= "\n[url]".$item->link."[/url]\n";
else
$_REQUEST["body"] .= "\n";
}*/
$quote = ""; $quote = "";
if(isset($item->description) and ($item->type != "photo")) if(isset($item->description) and ($item->type != "photo"))
@ -1062,38 +1055,44 @@ function fbpost_fetchwall($a, $uid) {
if(isset($item->caption) and ($item->type == "photo")) if(isset($item->caption) and ($item->type == "photo"))
$quote = $item->caption; $quote = $item->caption;
//if (isset($item->properties)) // Only import the picture when the message is no video
// foreach ($item->properties as $property) // oembed display a picture of the video as well
// $quote .= "\n".$property->name.": [url=".$property->href."]".$property->text."[/url]"; //if ($item->type != "video") {
//if (($item->type != "video") and ($item->type != "photo")) {
if (($type == "") OR ($type == "link")) {
$type = $item->type;
if(isset($item->picture) && isset($item->link))
$content .= "\n".'[url='.$item->link.'][img]'.fpost_cleanpicture($item->picture).'[/img][/url]';
else {
if (isset($item->picture))
$content .= "\n".'[img]'.fpost_cleanpicture($item->picture).'[/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));
continue;
}
if ($content)
$_REQUEST["body"] .= "\n\n";
if ($type)
$_REQUEST["body"] .= "[class=type-".$type."]";
if ($content)
$_REQUEST["body"] .= $content;
if ($quote) if ($quote)
$_REQUEST["body"] .= "\n[quote]".$quote."[/quote]"; $_REQUEST["body"] .= "\n[quote]".$quote."[/quote]";
// Only import the picture when the message is no video if ($type)
// oembed display a picture of the video as well $_REQUEST["body"] .= "[/class]";
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 {
if (isset($item->picture))
$_REQUEST["body"] .= "\n".'[img]'.fpost_cleanpicture($item->picture).'[/img]';
// if just a link, it may be a wall photo - check
if(isset($item->link))
$_REQUEST["body"] .= fbpost_get_photo($uid,$item->link);
}
}
/*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));
continue;
}
$_REQUEST["body"] = trim($_REQUEST["body"]); $_REQUEST["body"] = trim($_REQUEST["body"]);

View File

@ -184,6 +184,8 @@ function fbsync_cron($a,$b) {
function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $create_user) { function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $create_user) {
require_once("include/oembed.php");
// check if it was already imported // check if it was already imported
$r = q("SELECT * FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1", $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1",
intval($uid), intval($uid),
@ -267,10 +269,15 @@ function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $cr
$postarray["body"] = $msgdata["body"]; $postarray["body"] = $msgdata["body"];
$postarray["tag"] = $msgdata["tags"]; $postarray["tag"] = $msgdata["tags"];
if(isset($post->attachment->name) and isset($post->attachment->href)) $content = "";
$postarray["body"] .= "\n\n[bookmark=".$post->attachment->href."]".$post->attachment->name."[/bookmark]"; $type = "";
elseif (isset($post->attachment->name) AND ($post->attachment->name != ""))
$postarray["body"] .= "\n\n[b]" . $post->attachment->name."[/b]"; if (isset($post->attachment->name) and isset($post->attachment->href)) {
$oembed_data = oembed_fetch_url($post->attachment->href);
$type = $oembed_data->type;
$content = "[bookmark=".$post->attachment->href."]".$post->attachment->name."[/bookmark]";
} elseif (isset($post->attachment->name) AND ($post->attachment->name != ""))
$content = "[b]" . $post->attachment->name."[/b]";
$quote = ""; $quote = "";
if(isset($post->attachment->description) and ($post->attachment->fb_object_type != "photo")) if(isset($post->attachment->description) and ($post->attachment->fb_object_type != "photo"))
@ -279,12 +286,13 @@ function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $cr
if(isset($post->attachment->caption) and ($post->attachment->fb_object_type == "photo")) if(isset($post->attachment->caption) and ($post->attachment->fb_object_type == "photo"))
$quote = $post->attachment->caption; $quote = $post->attachment->caption;
if ($quote.$post->attachment->href.$postarray["body"] == "") if ($quote.$post->attachment->href.$content.$postarray["body"] == "")
return; return;
if (isset($post->attachment->media) AND !strstr($post->attachment->href, "://www.youtube.com/") if (isset($post->attachment->media) // AND !strstr($post->attachment->href, "://www.youtube.com/")
AND !strstr($post->attachment->href, "://youtu.be/") //AND !strstr($post->attachment->href, "://youtu.be/")
AND !strstr($post->attachment->href, ".vimeo.com/")) { //AND !strstr($post->attachment->href, ".vimeo.com/"))
AND (($type == "") OR ($type == "link"))) {
foreach ($post->attachment->media AS $media) { foreach ($post->attachment->media AS $media) {
//$media->photo->owner = number_format($media->photo->owner, 0, '', ''); //$media->photo->owner = number_format($media->photo->owner, 0, '', '');
//if ($media->photo->owner != '') { //if ($media->photo->owner != '') {
@ -293,21 +301,36 @@ function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $cr
// $postarray['author-avatar'] = $contacts[$media->photo->owner]->pic_square; // $postarray['author-avatar'] = $contacts[$media->photo->owner]->pic_square;
//} //}
if (isset($media->type))
$type = $media->type;
if(isset($media->src) && isset($media->href) AND ($media->src != "") AND ($media->href != "")) if(isset($media->src) && isset($media->href) AND ($media->src != "") AND ($media->href != ""))
$postarray["body"] .= "\n".'[url='.$media->href.'][img]'.fpost_cleanpicture($media->src).'[/img][/url]'; $content .= "\n".'[url='.$media->href.'][img]'.fpost_cleanpicture($media->src).'[/img][/url]';
else { else {
if (isset($media->src) AND ($media->src != "")) if (isset($media->src) AND ($media->src != ""))
$postarray["body"] .= "\n".'[img]'.fpost_cleanpicture($media->src).'[/img]'; $content .= "\n".'[img]'.fpost_cleanpicture($media->src).'[/img]';
// if just a link, it may be a wall photo - check // if just a link, it may be a wall photo - check
if(isset($post->link)) if(isset($post->link))
$postarray["body"] .= fbpost_get_photo($media->href); $content .= fbpost_get_photo($media->href);
} }
} }
} }
if ($content)
$postarray["body"] .= "\n\n";
if ($type)
$postarray["body"] .= "[class=type-".$type."]";
if ($content)
$postarray["body"] .= $content;
if ($quote) if ($quote)
$postarray["body"] .= "\n[quote]".$quote."[/quote]"; $postarray["body"] .= "\n[quote]".trim($quote)."[/quote]";
if ($type)
$postarray["body"] .= "[/class]";
$postarray["body"] = trim($postarray["body"]); $postarray["body"] = trim($postarray["body"]);

View File

@ -247,6 +247,7 @@ function fromgplus_cleantext($text) {
function fromgplus_handleattachments($item, $displaytext) { function fromgplus_handleattachments($item, $displaytext) {
$post = ""; $post = "";
$quote = ""; $quote = "";
$type = "";
foreach ($item->object->attachments as $attachment) { foreach ($item->object->attachments as $attachment) {
switch($attachment->objectType) { switch($attachment->objectType) {
@ -262,7 +263,7 @@ function fromgplus_handleattachments($item, $displaytext) {
break; break;
case "article": case "article":
$post .= "\n\n[bookmark=".$attachment->url."]".fromgplus_html2bbcode($attachment->displayName)."[/bookmark]\n"; $post .= "\n\n[class=type-link][bookmark=".$attachment->url."]".fromgplus_html2bbcode($attachment->displayName)."[/bookmark]\n";
$images = fromgplus_cleanupgoogleproxy($attachment->fullImage, $attachment->image); $images = fromgplus_cleanupgoogleproxy($attachment->fullImage, $attachment->image);
//if ($images["preview"] != "") //if ($images["preview"] != "")
@ -276,6 +277,8 @@ function fromgplus_handleattachments($item, $displaytext) {
$quote = trim(fromgplus_html2bbcode($attachment->content)); $quote = trim(fromgplus_html2bbcode($attachment->content));
if ($quote != "") if ($quote != "")
$quote = "\n[quote]".$quote."[/quote]"; $quote = "\n[quote]".$quote."[/quote]";
$quote .= "[/class]";
break; break;
case "photo": case "photo":

View File

@ -1772,25 +1772,35 @@ function twitter_siteinfo($url, $dontincludemedia) {
function twitter_convertmsg($a, $body, $no_tags = false, $dontincludemedia) { function twitter_convertmsg($a, $body, $no_tags = false, $dontincludemedia) {
require_once("include/oembed.php");
$links = preg_match_all("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", $body,$matches,PREG_SET_ORDER); $links = preg_match_all("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", $body,$matches,PREG_SET_ORDER);
$footer = ""; $footer = "";
$footerurl = ""; $footerurl = "";
$type = "";
if ($links) { if ($links) {
foreach ($matches AS $match) { foreach ($matches AS $match) {
$expanded_url = twitter_original_url($match[2]); $expanded_url = twitter_original_url($match[2]);
$oembed_data = oembed_fetch_url($expanded_url);
if ($type == "")
$type = $oembed_data->type;
// To-Do: // To-Do:
// Twitlonger // Twitlonger
if (strstr($expanded_url, "//www.youtube.com/")) // if (strstr($expanded_url, "//www.youtube.com/"))
$body = str_replace($match[2], "\n[youtube]".$expanded_url."[/youtube]\n", $body); // $body = str_replace($match[2], "\n[youtube]".$expanded_url."[/youtube]\n", $body);
elseif (strstr($expanded_url, "//player.vimeo.com/")) // elseif (strstr($expanded_url, "//player.vimeo.com/"))
$body = str_replace($match[2], "\n[vimeo]".$expanded_url."[/vimeo]\n", $body); // $body = str_replace($match[2], "\n[vimeo]".$expanded_url."[/vimeo]\n", $body);
elseif (strstr($expanded_url, "//twitpic.com/")) // Test // elseif (strstr($expanded_url, "//twitpic.com/")) // Test
$body = str_replace($match[2], "\n[url]".$expanded_url."[/url]\n", $body); // $body = str_replace($match[2], "\n[url]".$expanded_url."[/url]\n", $body);
elseif (strstr($expanded_url, "//instagram.com/")) // elseif (strstr($expanded_url, "//instagram.com/"))
// $body = str_replace($match[2], "\n[url]".$expanded_url."[/url]\n", $body);
if ($oembed_data->type != "link")
$body = str_replace($match[2], "\n[url]".$expanded_url."[/url]\n", $body); $body = str_replace($match[2], "\n[url]".$expanded_url."[/url]\n", $body);
else { else {
$img_str = fetch_url($expanded_url, true, $redirects, 4); $img_str = fetch_url($expanded_url, true, $redirects, 4);
@ -1801,9 +1811,11 @@ function twitter_convertmsg($a, $body, $no_tags = false, $dontincludemedia) {
unlink($tempfile); unlink($tempfile);
if (substr($mime, 0, 6) == "image/") { if (substr($mime, 0, 6) == "image/") {
$type = "photo";
$body = str_replace($match[2], "[img]".$expanded_url."[/img]", $body); $body = str_replace($match[2], "[img]".$expanded_url."[/img]", $body);
$dontincludemedia = true; $dontincludemedia = true;
} else { } else {
$type = $oembed_data->type;
$footerurl = $expanded_url; $footerurl = $expanded_url;
$footerlink = "[url=".$expanded_url."]".$expanded_url."[/url]"; $footerlink = "[url=".$expanded_url."]".$expanded_url."[/url]";
@ -1813,7 +1825,7 @@ function twitter_convertmsg($a, $body, $no_tags = false, $dontincludemedia) {
} }
if ($footerurl != "") if ($footerurl != "")
$footer = "\n\n".twitter_siteinfo($footerurl, $dontincludemedia); $footer = twitter_siteinfo($footerurl, $dontincludemedia);
if (($footerlink != "") AND (trim($footer) != "")) { if (($footerlink != "") AND (trim($footer) != "")) {
$removedlink = trim(str_replace($footerlink, "", $body)); $removedlink = trim(str_replace($footerlink, "", $body));
@ -1821,7 +1833,7 @@ function twitter_convertmsg($a, $body, $no_tags = false, $dontincludemedia) {
if (strstr($body, $removedlink)) if (strstr($body, $removedlink))
$body = $removedlink; $body = $removedlink;
$body .= $footer; $body .= "\n\n[class=type-".$type."]".$footer."[/class]";
} }
} }