Facebook: Removing useless content when posting to facebook. Now content on facebook really looks great.

This commit is contained in:
Michael Vogel 2012-03-31 17:42:17 +02:00
parent 5e9405e9dc
commit 97bbcad0f5
1 changed files with 35 additions and 13 deletions

View File

@ -796,6 +796,7 @@ function facebook_post_hook(&$a,&$b) {
if($b['verb'] == ACTIVITY_DISLIKE)
$msg = trim(strip_tags(bbcode($msg)));
// Old code
/*$search_str = $a->get_baseurl() . '/search';
if(preg_match("/\[url=(.*?)\](.*?)\[\/url\]/is",$msg,$matches)) {
@ -827,26 +828,47 @@ function facebook_post_hook(&$a,&$b) {
$msg = trim(strip_tags(bbcode($msg)));*/
// Test
// New code
// Looking for images
// Looking for the first image
$image = '';
if(preg_match("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/is",$b['body'],$matches))
$image = $matches[3];
if(preg_match("/\[img\](.*?)\[\/img\]/is",$b['body'],$matches))
$image = $matches[1];
if ($image != '')
if(preg_match("/\[img\](.*?)\[\/img\]/is",$b['body'],$matches))
$image = $matches[1];
// Replace bookmark with url
$body = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",'[url=$1]$2[/url]',$b['body']);
// Checking for a bookmark element
$body = $b['body'];
if (strpos($body, "[bookmark") !== false) {
// splitting the text in two parts:
// before and after the bookmark
$pos = strpos($body, "[bookmark");
$body1 = substr($body, 0, $pos);
$body2 = substr($body, $pos);
// Removing the bookmark and all quotes after the bookmark
// they are mostly only the content after the bookmark.
$body2 = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",'',$body2);
$body2 = preg_replace("/\[quote\=([^\]]*)\](.*?)\[\/quote\]/ism",'',$body2);
$body2 = preg_replace("/\[quote\](.*?)\[\/quote\]/ism",'',$body2);
$body = $body1.$body2;
}
// At first convert the text to html
$html = bbcode($body);
$msg = trim($b['title']." \n".html2plain($html, 0, true));
// Then convert it to plain text
$msg = trim($b['title']." \n\n".html2plain($html, 0, true));
$msg = html_entity_decode($msg,ENT_QUOTES,'UTF-8');
$toolong = false;
// Removing multiple newlines
while (strpos($msg, "\n\n\n") !== false)
$msg = str_replace("\n\n\n", "\n\n", $msg);
// add any attachments as text urls
$arr = explode(',',$b['attach']);
if(count($arr)) {
@ -865,19 +887,19 @@ function facebook_post_hook(&$a,&$b) {
if(preg_match("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/is",$b['body'],$matches))
$link = $matches[1];
// If there is no bookmark element then take the first link
if ($link == '') {
$links = collecturls($html);
if (sizeof($links) > 0) {
reset($links);
$link = current($links);
/*if (strlen($msg."\n".$link) <= FACEBOOK_MAXPOSTLEN)
$msg .= "\n".$link;
else
$toolong = true;*/
$msg .= "\n".$link;*/
}
}
if ((strlen($msg) > FACEBOOK_MAXPOSTLEN) or $toolong) {
// Since facebook increased the maxpostlen massively this never should happen again :)
if (strlen($msg) > FACEBOOK_MAXPOSTLEN) {
$shortlink = "";
require_once('library/slinky.php');