X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=statusnet%2Fstatusnet.php;h=d7ec4abb3948e89016abe026157d8d3ac2fbcffd;hb=57441b4def0f4bb42044ea444b6c59bcaa166d61;hp=897c54152c158ea7bb4c6f46a1a0d0ca79a8d08a;hpb=b6ab56fd7fe37194423738fc82c3050d2aed00f4;p=friendica-addons.git diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index 897c5415..d7ec4abb 100755 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -2,8 +2,8 @@ /** * Name: StatusNet Connector * Description: Relay public postings to a connected StatusNet account - * Version: 1.0.4 - * Author: Tobias Diekershoff + * Version: 1.0.5 + * Author: Tobias Diekershoff */ /* StatusNet Plugin for Friendica @@ -342,7 +342,7 @@ function statusnet_settings(&$a,&$s) { $s .= ''; $s .= ''; $s .= '
'; - $s .= ''; + $s .= ''; $s .= ''; $s .= '
'; @@ -426,18 +426,18 @@ function statusnet_post_hook(&$a,&$b) { if($ckey && $csecret && $otoken && $osecret) { - require_once('include/bbcode.php'); + require_once('include/bbcode.php'); $dent = new StatusNetOAuth($api,$ckey,$csecret,$otoken,$osecret); $max_char = $dent->get_maxlength(); // max. length for a dent // we will only work with up to two times the length of the dent - // we can later send to StatusNet. This way we can "gain" some - // information during shortening of potential links but do not + // we can later send to StatusNet. This way we can "gain" some + // information during shortening of potential links but do not // shorten all the links in a 200000 character long essay. if (! $b['title']=='') { - $tmp = $b['title'] . ' : '. $b['body']; - $tmp = substr($tmp, 0, 2*$max_char); + $tmp = $b['title'].": \n".$b['body']; +// $tmp = substr($tmp, 0, 4*$max_char); } else { - $tmp = substr($b['body'], 0, 2*$max_char); + $tmp = $b['body']; // substr($b['body'], 0, 3*$max_char); } // if [url=bla][img]blub.png[/img][/url] get blub.png $tmp = preg_replace( '/\[url\=(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)\]\[img\](\\w+.*?)\\[\\/img\]\\[\\/url\]/i', '$2', $tmp); @@ -453,7 +453,10 @@ function statusnet_post_hook(&$a,&$b) { // that is, don't send if the option is not set in the // connector settings if ($linksenabled=='0') { + // #-tags $tmp = preg_replace( '/#\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', '#$2', $tmp); + // @-mentions + $tmp = preg_replace( '/@\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', '@$2', $tmp); } // preserve links to webpages $tmp = preg_replace( '/\[url\=(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)\](\w+.*?)\[\/url\]/i', '$2 $1', $tmp); @@ -473,19 +476,30 @@ function statusnet_post_hook(&$a,&$b) { } // ok, all the links we want to send out are save, now strip // away the remaining bbcode - $msg = strip_tags(bbcode($tmp)); + $msg = strip_tags(bbcode($tmp, false, false)); // quotes not working - let's try this $msg = html_entity_decode($msg); if (( strlen($msg) > $max_char) && $max_char > 0) { $shortlink = short_link( $b['plink'] ); // the new message will be shortened such that "... $shortlink" // will fit into the character limit - $msg = substr($msg, 0, $max_char-strlen($shortlink)-4); + $msg = nl2br(substr($msg, 0, $max_char-strlen($shortlink)-4)); + $msg = str_replace(array('
','
'),' ',$msg); + $e = explode(' ', $msg); + // remove the last word from the cut down message to + // avoid sending cut words to the MicroBlog + array_pop($e); + $msg = implode(' ', $e); $msg .= '... ' . $shortlink; } - // and now tweet it :-) - if(strlen($msg)) - $dent->post('statuses/update', array('status' => $msg)); + // and now dent it :-) + if(strlen($msg)) { + $result = $dent->post('statuses/update', array('status' => $msg)); + logger('statusnet_post send, result: ' . print_r($result, true), LOGGER_DEBUG); + if ($result->error) { + logger('Send to StatusNet failed: "' . $result->error . '"'); + } + } } }