Merge pull request #146 from annando/master
Picture posts for statusnet, picture posts with twitter are working again - and some "fromglus" stuffpull/147/merge
commit
70fa10bf64
|
@ -218,6 +218,14 @@ function fromgplus_cleanupgoogleproxy($fullImage, $image) {
|
|||
return($cleaned);
|
||||
}
|
||||
|
||||
function fromgplus_cleantext($text) {
|
||||
$text = strip_tags($text);
|
||||
$text = html_entity_decode($text);
|
||||
$text = trim($text);
|
||||
$text = str_replace(array("\n", "\r", " "), array("", "", ""), $text);
|
||||
return($text);
|
||||
}
|
||||
|
||||
function fromgplus_handleattachments($item, $displaytext) {
|
||||
$post = "";
|
||||
$quote = "";
|
||||
|
@ -239,9 +247,11 @@ function fromgplus_handleattachments($item, $displaytext) {
|
|||
$post .= "\n\n[bookmark=".$attachment->url."]".fromgplus_html2bbcode($attachment->displayName)."[/bookmark]\n";
|
||||
|
||||
$images = fromgplus_cleanupgoogleproxy($attachment->fullImage, $attachment->image);
|
||||
if ($images["preview"] != "")
|
||||
$post .= "\n[url=".$images["full"]."][img]".$images["preview"]."[/img][/url]\n";
|
||||
elseif ($images["full"] != "")
|
||||
//if ($images["preview"] != "")
|
||||
// $post .= "\n[url=".$images["full"]."][img]".$images["preview"]."[/img][/url]\n";
|
||||
//elseif ($images["full"] != "")
|
||||
// $post .= "\n[img]".$images["full"]."[/img]\n";
|
||||
if ($images["full"] != "")
|
||||
$post .= "\n[img]".$images["full"]."[/img]\n";
|
||||
|
||||
//$post .= "[quote]".trim(fromgplus_html2bbcode($attachment->content))."[/quote]";
|
||||
|
@ -257,7 +267,7 @@ function fromgplus_handleattachments($item, $displaytext) {
|
|||
elseif ($images["full"] != "")
|
||||
$post .= "\n[img]".$images["full"]."[/img]\n";
|
||||
|
||||
if (($attachment->displayName != "") AND ($attachment->displayName != $displaytext))
|
||||
if (($attachment->displayName != "") AND (fromgplus_cleantext($attachment->displayName) != fromgplus_cleantext($displaytext)))
|
||||
$post .= fromgplus_html2bbcode($attachment->displayName)."\n";
|
||||
break;
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -550,6 +550,9 @@ function statusnet_shortenmsg($b, $max_char) {
|
|||
if ((strlen(trim($origmsg)) <= $max_char) AND (strpos($origmsg, $msglink) OR ($msglink == "")))
|
||||
return(array("msg"=>trim($origmsg), "image"=>""));
|
||||
|
||||
// Preserve the unshortened link
|
||||
$orig_link = $msglink;
|
||||
|
||||
if (strlen($msglink) > 20)
|
||||
$msglink = short_link($msglink);
|
||||
|
||||
|
@ -569,7 +572,22 @@ function statusnet_shortenmsg($b, $max_char) {
|
|||
while (strpos($msg, " ") !== false)
|
||||
$msg = str_replace(" ", " ", $msg);
|
||||
|
||||
return(array("msg"=>trim($msg."\n".$msglink), "image"=>$image));
|
||||
//return(array("msg"=>trim($msg."\n".$msglink), "image"=>$image));
|
||||
|
||||
// Looking if the link points to an image
|
||||
$img_str = fetch_url($orig_link);
|
||||
|
||||
$tempfile = tempnam(get_config("system","temppath"), "cache");
|
||||
file_put_contents($tempfile, $img_str);
|
||||
$mime = image_type_to_mime_type(exif_imagetype($tempfile));
|
||||
unlink($tempfile);
|
||||
|
||||
if (($image == $orig_link) OR (substr($mime, 0, 6) == "image/"))
|
||||
return(array("msg"=>trim($msg), "image"=>$orig_link));
|
||||
else if (($image != $orig_link) AND ($image != "") AND (strlen($msg."\n".$msglink) <= ($max_char - 20)))
|
||||
return(array("msg"=>trim($msg."\n".$msglink), "image"=>$image));
|
||||
else
|
||||
return(array("msg"=>trim($msg."\n".$msglink), "image"=>""));
|
||||
}
|
||||
|
||||
function statusnet_post_hook(&$a,&$b) {
|
||||
|
@ -697,18 +715,25 @@ function statusnet_post_hook(&$a,&$b) {
|
|||
$msg = $msgarr["msg"];
|
||||
$image = $msgarr["image"];
|
||||
if ($image != "") {
|
||||
$imagedata = file_get_contents($image);
|
||||
$tempfile = tempnam(get_config("system","temppath"), "upload");
|
||||
file_put_contents($tempfile, $imagedata);
|
||||
$postdata = array("status"=>$msg, "media"=>"@".$tempfile);
|
||||
$img_str = fetch_url($image);
|
||||
$tempfile = tempnam(get_config("system","temppath"), "cache");
|
||||
file_put_contents($tempfile, $img_str);
|
||||
$postdata = array("status" => $msg, "media[]" => $tempfile);
|
||||
} else
|
||||
$postdata = array("status"=>$msg);
|
||||
}
|
||||
|
||||
// and now dent it :-)
|
||||
if(strlen($msg)) {
|
||||
//$result = $dent->post('statuses/update', array('status' => $msg));
|
||||
$result = $dent->post('statuses/update', $postdata);
|
||||
|
||||
// New code that is able to post pictures
|
||||
require_once("addon/statusnet/codebird.php");
|
||||
$cb = \CodebirdSN\CodebirdSN::getInstance();
|
||||
$cb->setAPIEndpoint($api);
|
||||
$cb->setConsumerKey($ckey, $csecret);
|
||||
$cb->setToken($otoken, $osecret);
|
||||
$result = $cb->statuses_update($postdata);
|
||||
//$result = $dent->post('statuses/update', $postdata);
|
||||
logger('statusnet_post send, result: ' . print_r($result, true).
|
||||
"\nmessage: ".$msg, LOGGER_DEBUG."\nOriginal post: ".print_r($b, true)."\nPost Data: ".print_r($postdata, true));
|
||||
if ($result->error) {
|
||||
|
@ -721,9 +746,9 @@ function statusnet_post_hook(&$a,&$b) {
|
|||
}
|
||||
|
||||
function statusnet_plugin_admin_post(&$a){
|
||||
|
||||
|
||||
$sites = array();
|
||||
|
||||
|
||||
foreach($_POST['sitename'] as $id=>$sitename){
|
||||
$sitename=trim($sitename);
|
||||
$apiurl=trim($_POST['apiurl'][$id]);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -305,7 +305,7 @@ function short_link ($url) {
|
|||
return $slinky->short();
|
||||
} };
|
||||
|
||||
function twitter_shortenmsg($b) {
|
||||
function twitter_shortenmsg($b, $shortlink = false) {
|
||||
require_once("include/bbcode.php");
|
||||
require_once("include/html2plain.php");
|
||||
|
||||
|
@ -449,10 +449,12 @@ function twitter_shortenmsg($b) {
|
|||
//if (strlen(trim($msg." ".$msglink)) > ($max_char - 3)) {
|
||||
// $msg = substr($msg, 0, ($max_char - 3) - (strlen($msglink)));
|
||||
|
||||
// Just replace the message link with a 15 character long string
|
||||
// Just replace the message link with a 20 character long string
|
||||
// Twitter shortens it anyway to this length
|
||||
// 15 should be enough - but sometimes posts don't get posted - although they would fit.
|
||||
if (trim($msglink) <> '')
|
||||
$msglink = "123456789012345";
|
||||
// $msglink = "12345678901234567890";
|
||||
|
||||
if (strlen(trim($msg." ".$msglink)) > ($max_char)) {
|
||||
$msg = substr($msg, 0, ($max_char) - (strlen($msglink)));
|
||||
|
@ -498,10 +500,17 @@ function twitter_shortenmsg($b) {
|
|||
|
||||
if (($image == $orig_link) OR (substr($mime, 0, 6) == "image/"))
|
||||
return(array("msg"=>trim($msg), "image"=>$orig_link));
|
||||
else if (($image != $orig_link) AND ($image != "") AND (strlen($msg."\n".$msglink) <= ($max_char - 20)))
|
||||
else if (($image != $orig_link) AND ($image != "") AND (strlen($msg."\n".$msglink) <= ($max_char - 20))) {
|
||||
if ($shortlink)
|
||||
$orig_link = short_link($orig_link);
|
||||
|
||||
return(array("msg"=>trim($msg."\n".$orig_link), "image"=>$image));
|
||||
else
|
||||
} else {
|
||||
if ($shortlink)
|
||||
$orig_link = short_link($orig_link);
|
||||
|
||||
return(array("msg"=>trim($msg."\n".$orig_link), "image"=>""));
|
||||
}
|
||||
}
|
||||
|
||||
function twitter_post_hook(&$a,&$b) {
|
||||
|
@ -634,17 +643,33 @@ function twitter_post_hook(&$a,&$b) {
|
|||
|
||||
$tempfile = tempnam(get_config("system","temppath"), "cache");
|
||||
file_put_contents($tempfile, $img_str);
|
||||
|
||||
// For testing purposes
|
||||
// trying a new library for twitter
|
||||
// To-Do:
|
||||
// Switching completely to this library with all functions
|
||||
require_once("addon/twitter/codebird.php");
|
||||
|
||||
$cb = \Codebird\Codebird::getInstance();
|
||||
$cb->setConsumerKey($ckey, $csecret);
|
||||
$cb->setToken($otoken, $osecret);
|
||||
$result = $cb->statuses_updateWithMedia(array('status' => $msg, 'media[]' => $tempfile));
|
||||
unlink($tempfile);
|
||||
|
||||
/*
|
||||
$mime = image_type_to_mime_type(exif_imagetype($tempfile));
|
||||
unlink($tempfile);
|
||||
|
||||
$filename = "upload";
|
||||
|
||||
$result = $tweet->post('statuses/update_with_media', array('media[]' => "{$img_str};type=".$mime.";filename={$filename}" , 'status' => $msg));
|
||||
*/
|
||||
|
||||
logger('twitter_post_with_media send, result: ' . print_r($result, true), LOGGER_DEBUG);
|
||||
if ($result->error) {
|
||||
logger('Send to Twitter failed: "' . $result->error . '"');
|
||||
if ($result->errors OR $result->error) {
|
||||
logger('Send to Twitter failed: "' . $result->errors . '"');
|
||||
// Workaround: Remove the picture link so that the post can be reposted without it
|
||||
$msg .= " ".$image;
|
||||
$image = "";
|
||||
}
|
||||
}
|
||||
|
@ -652,8 +677,24 @@ function twitter_post_hook(&$a,&$b) {
|
|||
if(strlen($msg) and ($image == "")) {
|
||||
$result = $tweet->post('statuses/update', array('status' => $msg));
|
||||
logger('twitter_post send, result: ' . print_r($result, true), LOGGER_DEBUG);
|
||||
if ($result->error)
|
||||
logger('Send to Twitter failed: "' . $result->error . '"');
|
||||
if ($result->errors OR $result->error) {
|
||||
logger('Send to Twitter failed: "' . $result->errors . '"');
|
||||
|
||||
// experimental
|
||||
// Sometims Twitter seems to think that posts are too long - although they aren't
|
||||
// Test 1:
|
||||
// Shorten the urls
|
||||
// Test 2:
|
||||
// Reduce the maximum length
|
||||
if ($intelligent_shortening) {
|
||||
$msgarr = twitter_shortenmsg($b, true);
|
||||
$msg = $msgarr["msg"];
|
||||
$image = $msgarr["image"];
|
||||
$result = $tweet->post('statuses/update', array('status' => $msg));
|
||||
logger('twitter_post send, result: ' . print_r($result, true), LOGGER_DEBUG);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue