* Description: Posts to app.net with the help of ifttt.com
* Version: 0.1
* Author: Michael Vogel <https://pirati.ca/profile/heluecht>
+ * Status: Unsupported
*/
function appnetpost_install() {
<?php
/**
* Name: Buffer Post Connector
- * Description: Post to Buffer
- * Version: 0.1 alpha
+ * Description: Post to Buffer (Linkedin, App.net, Google+, Facebook, Twitter)
+ * Version: 0.2
* Author: Michael Vogel <http://pirati.ca/profile/heluecht>
*/
require('addon/buffer/bufferapp.php');
}
}
-function fbpost_createmsg($b) {
- require_once("include/bbcode.php");
- require_once("include/html2plain.php");
-
- $b['body'] = bb_CleanPictureLinks($b['body']);
-
- // Looking for the first image
- $image = '';
- if(preg_match("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/is",$b['body'],$matches))
- $image = $matches[3];
-
- if ($image == '')
- if(preg_match("/\[img\](.*?)\[\/img\]/is",$b['body'],$matches))
- $image = $matches[1];
-
- $multipleimages = (strpos($b['body'], "[img") != strrpos($b['body'], "[img"));
-
- // When saved into the database the content is sent through htmlspecialchars
- // That means that we have to decode all image-urls
- $image = htmlspecialchars_decode($image);
-
- $body = $b["body"];
- if ($b["title"] != "")
- $body = $b["title"]."\n\n".$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 all quotes after the bookmark
- // they are mostly only the content after the bookmark.
- $body2 = preg_replace("/\[quote\=([^\]]*)\](.*?)\[\/quote\]/ism",'',$body2);
- $body2 = preg_replace("/\[quote\](.*?)\[\/quote\]/ism",'',$body2);
-
- $pos2 = strpos($body2, "[/bookmark]");
- if ($pos2)
- $body2 = substr($body2, $pos2 + 11);
-
- $body = $body1.$body2;
- }
-
- // Add some newlines so that the message could be cut better
- $body = str_replace(array("[quote", "[bookmark", "[/bookmark]", "[/quote]"),
- array("\n[quote", "\n[bookmark", "[/bookmark]\n", "[/quote]\n"), $body);
-
- // remove the recycle signs and the names since they aren't helpful on twitter
- // $recycle = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8');
- // $body = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', "\n", $body);
-
- // At first convert the text to html
- $html = bbcode($body, false, false, 2);
-
- // Then convert it to plain text
- //$msg = trim($b['title']." \n\n".html2plain($html, 0, true));
- $msg = trim(html2plain($html, 0, true));
- $msg = html_entity_decode($msg,ENT_QUOTES,'UTF-8');
-
- // Removing multiple newlines
- while (strpos($msg, "\n\n\n") !== false)
- $msg = str_replace("\n\n\n", "\n\n", $msg);
-
- // Removing multiple spaces
- while (strpos($msg, " ") !== false)
- $msg = str_replace(" ", " ", $msg);
-
- // Removing URLs
- $msg = preg_replace('/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/i', "", $msg);
-
- $msg = trim($msg);
-
- $link = '';
- $linkname = '';
- // look for bookmark-bbcode and handle it with priority
- if(preg_match("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/is",$b['body'],$matches)) {
- $link = $matches[1];
- $linkname = $matches[2];
- }
-
- $multiplelinks = (strpos($b['body'], "[bookmark") != strrpos($b['body'], "[bookmark"));
-
- if ($multiplelinks)
- $linkname = '';
-
- // 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);
- }
- $multiplelinks = (sizeof($links) > 1);
- }
-
- $msglink = "";
- if ($multiplelinks)
- $msglink = $b["plink"];
- else if ($link != "")
- $msglink = $link;
- else if ($multipleimages)
- $msglink = $b["plink"];
- else if ($image != "")
- $msglink = $image;
-
- // Removing multiple spaces - again
- while (strpos($msg, " ") !== false)
- $msg = str_replace(" ", " ", $msg);
-
- if ($msglink != "") {
- // Looking if the link points to an image
- $img_str = fetch_url($msglink);
-
- $tempfile = tempnam(get_config("system","temppath"), "cache");
- file_put_contents($tempfile, $img_str);
- $mime = image_type_to_mime_type(exif_imagetype($tempfile));
- unlink($tempfile);
- } else
- $mime = "";
-
- if (($image == $msglink) OR (substr($mime, 0, 6) == "image/"))
- return(array("msg"=>trim($msg), "link"=>"", "linkname"=>$linkname, "image"=>$msglink));
- else
- return(array("msg"=>trim($msg), "link"=>$msglink, "linkname"=>$linkname,"image"=>$image));
-}
-
/**
* @param App $a
* @param object $b
logger('fbpost_post_hook: original msg=' . $msg, LOGGER_DATA);
if ($toplevel) {
- $msgarr = fbpost_createmsg($b);
- $msg = $msgarr["msg"];
- $link = $msgarr["link"];
+ require_once("include/plaintext.php");
+ $msgarr = plaintext($a, $b, 0, false);
+ $msg = $msgarr["text"];
+ $link = $msgarr["url"];
$image = $msgarr["image"];
- $linkname = $msgarr["linkname"];
+ $linkname = $msgarr["title"];
// Fallback - if message is empty
if(!strlen($msg))
$trash = html_entity_decode("", ENT_QUOTES, 'UTF-8');
$text = strip_tags($text);
- $text = html_entity_decode($text);
+ $text = html_entity_decode($text, ENT_QUOTES);
$text = trim($text);
$text = str_replace(array("\n", "\r", " ", $trash), array("", "", "", ""), $text);
return($text);
if($username && $password) {
require_once("addon/gpluspost/postToGooglePlus.php");
require_once("include/plaintext.php");
- require_once("include/network.php");
$item = $b;
function openstreetmap_install() {
register_hook('render_location', 'addon/openstreetmap/openstreetmap.php', 'openstreetmap_location');
- register_hook('page_header', 'addon/openstreetmap/openstreetmap.php', 'openstreetmap_alterheader');\r
+ register_hook('page_header', 'addon/openstreetmap/openstreetmap.php', 'openstreetmap_alterheader');
logger("installed openstreetmap");
}
}
function openstreetmap_alterheader($a, &$navHtml) {
- $addScriptTag='<script type="text/javascript" src="' . $a->get_baseurl() . '/addon/openstreetmap/openstreetmap.js' . '"></script>' . "\r\n";\r
+ $addScriptTag='<script type="text/javascript" src="' . $a->get_baseurl() . '/addon/openstreetmap/openstreetmap.js' . '"></script>' . "\r\n";
$a->page['htmlhead'] .= $addScriptTag;
}
$location = '';
$coord = '';
-
+
if($item['location'] && !$item['coord'] && true){ //if only a location is given, find the lat-lon
$geo_account='demo';
-\r
- $s = fetch_url('http://api.geonames.org/search?maxRows=1&fuzzy=0.8&q=' . $item['location'] . '&username=' . $geo_account);\r
-\r
- if($s){\r
- $xml = parse_xml_string($s);\r
-\r
- if($xml->geoname->lat && $xml->geoname->lng){\r
- $item['coord'] = $xml->geoname->lat . ' ' . $xml->geoname->lng;
- }\r
+
+ $s = fetch_url('http://api.geonames.org/search?maxRows=1&fuzzy=0.8&q=' . $item['location'] . '&username=' . $geo_account);
+
+ if($s){
+ $xml = parse_xml_string($s);
+
+ if($xml->geoname->lat && $xml->geoname->lng){
+ $item['coord'] = $xml->geoname->lat.' '.$xml->geoname->lng;
+ }
}
}
- $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="'.$tmsserver.'?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
+ $location = (($item['location']) ? '<a target="map" title="'.$item['location'].'" href="'.$tmsserver.'?q='.urlencode($item['location']).'">'.$item['location'].'</a>' : '');
if($item['coord']) {
$coords = explode(' ', $item['coord']);
if(count($coords) > 1) {
- $coord = '<a target="map" class="OSMMapLink" title="' . $item['coord'] . '" href="'.$tmsserver.'?lat=' . urlencode($coords[0]) . '&lon=' . urlencode($coords[1]) . '&zoom='.$zoom.'"> Map </a>' ;
+ $coord = '<a target="map" class="OSMMapLink" title="'.$item['coord'].'" href="'.$tmsserver.'?lat='.urlencode($coords[0]).'&lon=' . urlencode($coords[1]).'&zoom='.$zoom.'">'.t("Map").'</a>' ;
}
}
if(strlen($coord)) {
if($location)
- $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
+ $location .= ' <span class="smalltext">('.$coord.')</span>';
else
- $location = '<span class="smalltext">' . $coord . '</span>';
+ $location = '<span class="smalltext">'.$coord.'</span>';
}
$item['html'] = $location;
return;
del_pconfig(local_user(), 'statusnet', 'oauthtoken');
del_pconfig(local_user(), 'statusnet', 'oauthsecret');
del_pconfig(local_user(), 'statusnet', 'baseapi');
- del_pconfig(local_user(), 'statusnet', 'post_taglinks');
del_pconfig(local_user(), 'statusnet', 'lastid');
del_pconfig(local_user(), 'statusnet', 'mirror_posts');
- del_pconfig(local_user(), 'statusnet', 'intelligent_shortening');
del_pconfig(local_user(), 'statusnet', 'import');
del_pconfig(local_user(), 'statusnet', 'create_user');
del_pconfig(local_user(), 'statusnet', 'own_id');
// to post a dent for every new __public__ posting to the wall
set_pconfig(local_user(),'statusnet','post',intval($_POST['statusnet-enable']));
set_pconfig(local_user(),'statusnet','post_by_default',intval($_POST['statusnet-default']));
- set_pconfig(local_user(),'statusnet','post_taglinks',intval($_POST['statusnet-sendtaglinks']));
set_pconfig(local_user(), 'statusnet', 'mirror_posts', intval($_POST['statusnet-mirror']));
- set_pconfig(local_user(), 'statusnet', 'intelligent_shortening', intval($_POST['statusnet-shortening']));
set_pconfig(local_user(), 'statusnet', 'import', intval($_POST['statusnet-import']));
set_pconfig(local_user(), 'statusnet', 'create_user', intval($_POST['statusnet-create_user']));
info( t('StatusNet settings updated.') . EOL);
* 3) Checkbox for "Send public notices (respect size limitation)
*/
$api = get_pconfig(local_user(), 'statusnet', 'baseapi');
- $ckey = get_pconfig(local_user(), 'statusnet', 'consumerkey' );
- $csecret = get_pconfig(local_user(), 'statusnet', 'consumersecret' );
- $otoken = get_pconfig(local_user(), 'statusnet', 'oauthtoken' );
- $osecret = get_pconfig(local_user(), 'statusnet', 'oauthsecret' );
+ $ckey = get_pconfig(local_user(), 'statusnet', 'consumerkey');
+ $csecret = get_pconfig(local_user(), 'statusnet', 'consumersecret');
+ $otoken = get_pconfig(local_user(), 'statusnet', 'oauthtoken');
+ $osecret = get_pconfig(local_user(), 'statusnet', 'oauthsecret');
$enabled = get_pconfig(local_user(), 'statusnet', 'post');
$checked = (($enabled) ? ' checked="checked" ' : '');
$defenabled = get_pconfig(local_user(),'statusnet','post_by_default');
$defchecked = (($defenabled) ? ' checked="checked" ' : '');
- $linksenabled = get_pconfig(local_user(),'statusnet','post_taglinks');
- $linkschecked = (($linksenabled) ? ' checked="checked" ' : '');
$mirrorenabled = get_pconfig(local_user(),'statusnet','mirror_posts');
$mirrorchecked = (($mirrorenabled) ? ' checked="checked" ' : '');
- $shorteningenabled = get_pconfig(local_user(),'statusnet','intelligent_shortening');
- $shorteningchecked = (($shorteningenabled) ? ' checked="checked" ' : '');
$importenabled = get_pconfig(local_user(),'statusnet','import');
$importchecked = (($importenabled) ? ' checked="checked" ' : '');
$create_userenabled = get_pconfig(local_user(),'statusnet','create_user');
$css = (($enabled) ? '' : '-disabled');
- $globalshortening = get_config('statusnet','intelligent_shortening');
-
-
$s .= '<span id="settings_statusnet_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_statusnet_expanded\'); openClose(\'settings_statusnet_inflated\');">';
$s .= '<img class="connector'.$css.'" src="images/gnusocial.png" /><h3 class="connector">'. t('StatusNet Import/Export/Mirror').'</h3>';
$s .= '</span>';
$s .= '<label id="statusnet-mirror-label" for="statusnet-mirror">'.t('Mirror all posts from statusnet that are no replies or repeated messages').'</label>';
$s .= '<input id="statusnet-mirror" type="checkbox" name="statusnet-mirror" value="1" '. $mirrorchecked . '/>';
$s .= '<div class="clear"></div>';
-
- if (!$globalshortening) {
- $s .= '<label id="statusnet-shortening-label" for="statusnet-shortening">'.t('Shortening method that optimizes the post').'</label>';
- $s .= '<input id="statusnet-shortening" type="checkbox" name="statusnet-shortening" value="1" '. $shorteningchecked . '/>';
- $s .= '<div class="clear"></div>';
-
- $s .= '<label id="statusnet-sendtaglinks-label" for="statusnet-sendtaglinks">'.t('Send linked #-tags and @-names to StatusNet').'</label>';
- $s .= '<input id="statusnet-sendtaglinks" type="checkbox" name="statusnet-sendtaglinks" value="1" '. $linkschecked . '/>';
- $s .= '<div class="clear"></div>';
- }
$s .= '</div>';
$s .= '<label id="statusnet-import-label" for="statusnet-import">'.t('Import the remote timeline').'</label>';
}
}
-if (! function_exists( 'short_link' )) {
-function short_link($url) {
- require_once('library/slinky.php');
- $slinky = new Slinky( $url );
- $yourls_url = get_config('yourls','url1');
- if ($yourls_url) {
- $yourls_username = get_config('yourls','username1');
- $yourls_password = get_config('yourls', 'password1');
- $yourls_ssl = get_config('yourls', 'ssl1');
- $yourls = new Slinky_YourLS();
- $yourls->set( 'username', $yourls_username );
- $yourls->set( 'password', $yourls_password );
- $yourls->set( 'ssl', $yourls_ssl );
- $yourls->set( 'yourls-url', $yourls_url );
- $slinky->set_cascade( array( $yourls, new Slinky_UR1ca(), new Slinky_Trim(), new Slinky_IsGd(), new Slinky_TinyURL() ) );
- }
- else {
- // setup a cascade of shortening services
- // try to get a short link from these services
- // in the order ur1.ca, trim, id.gd, tinyurl
- $slinky->set_cascade( array( new Slinky_UR1ca(), new Slinky_Trim(), new Slinky_IsGd(), new Slinky_TinyURL() ) );
- }
- return $slinky->short();
-} };
-
-function statusnet_shortenmsg($b, $max_char) {
- require_once("include/api.php");
- require_once("include/bbcode.php");
- require_once("include/html2plain.php");
-
- $b['body'] = bb_CleanPictureLinks($b['body']);
-
- // Looking for the first image
- $cleaned_body = api_clean_plain_items($b['body']);
- $image = '';
- if(preg_match("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/is",$cleaned_body,$matches))
- $image = $matches[3];
-
- if ($image == '')
- if(preg_match("/\[img\](.*?)\[\/img\]/is",$cleaned_body,$matches))
- $image = $matches[1];
-
- $multipleimages = (strpos($cleaned_body, "[img") != strrpos($cleaned_body, "[img"));
-
- // When saved into the database the content is sent through htmlspecialchars
- // That means that we have to decode all image-urls
- $image = htmlspecialchars_decode($image);
-
- $body = $b["body"];
- if ($b["title"] != "")
- $body = $b["title"]."\n\n".$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 all quotes after the bookmark
- // they are mostly only the content after the bookmark.
- $body2 = preg_replace("/\[quote\=([^\]]*)\](.*?)\[\/quote\]/ism",'',$body2);
- $body2 = preg_replace("/\[quote\](.*?)\[\/quote\]/ism",'',$body2);
- $body = $body1.$body2;
- }
-
- // Add some newlines so that the message could be cut better
- $body = str_replace(array("[quote", "[bookmark", "[/bookmark]", "[/quote]"),
- array("\n[quote", "\n[bookmark", "[/bookmark]\n", "[/quote]\n"), $body);
-
- // remove the recycle signs and the names since they aren't helpful on statusnet
- // recycle 1
- $recycle = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8');
- $body = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', "\n", $body);
- // recycle 2 (Test)
- $recycle = html_entity_decode("◌ ", ENT_QUOTES, 'UTF-8');
- $body = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', "\n", $body);
-
- // remove the share element
- //$body = preg_replace("/\[share(.*?)\](.*?)\[\/share\]/ism","\n\n$2\n\n",$body);
-
- // At first convert the text to html
- $html = bbcode(api_clean_plain_items($body), false, false, 2);
-
- // Then convert it to plain text
- //$msg = trim($b['title']." \n\n".html2plain($html, 0, true));
- $msg = trim(html2plain($html, 0, true));
- $msg = html_entity_decode($msg,ENT_QUOTES,'UTF-8');
-
- // Removing multiple newlines
- while (strpos($msg, "\n\n\n") !== false)
- $msg = str_replace("\n\n\n", "\n\n", $msg);
-
- // Removing multiple spaces
- while (strpos($msg, " ") !== false)
- $msg = str_replace(" ", " ", $msg);
-
- $origmsg = $msg;
-
- // Removing URLs
- $msg = preg_replace('/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/i', "", $msg);
-
- $msg = trim($msg);
-
- $link = '';
- // look for bookmark-bbcode and handle it with priority
- if(preg_match("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/is",$b['body'],$matches))
- $link = $matches[1];
-
- $multiplelinks = (strpos($b['body'], "[bookmark") != strrpos($b['body'], "[bookmark"));
-
- // 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);
- }
- $multiplelinks = (sizeof($links) > 1);
- }
-
- $msglink = "";
- if ($multiplelinks)
- $msglink = $b["plink"];
- else if ($link != "")
- $msglink = $link;
- else if ($multipleimages)
- $msglink = $b["plink"];
- else if ($image != "")
- $msglink = $image;
-
- if (($msglink == "") and strlen($msg) > $max_char)
- $msglink = $b["plink"];
-
- // If the message is short enough then don't modify it. (if the link exists in the original message)
- if ((strlen(trim($origmsg)) <= $max_char) AND (($msglink == "") OR strpos($origmsg, $msglink)))
- return(array("msg"=>trim($origmsg), "image"=>""));
-
- // If the message is short enough and contains a picture then post the picture as well
- if ((strlen(trim($origmsg)) <= ($max_char - 20)) AND strpos($origmsg, $msglink))
- return(array("msg"=>trim($origmsg), "image"=>$image));
-
- // If the message is short enough and the link exists in the original message don't modify it as well
- if ((strlen(trim($origmsg)) <= $max_char) AND strpos($origmsg, $msglink))
- return(array("msg"=>trim($origmsg), "image"=>""));
-
- // Preserve the unshortened link
- $orig_link = $msglink;
-
- if (strlen($msglink) > 20)
- $msglink = short_link($msglink);
-
- if (strlen(trim($msg." ".$msglink)) > $max_char) {
- $msg = substr($msg, 0, $max_char - (strlen($msglink)));
- $lastchar = substr($msg, -1);
- $msg = substr($msg, 0, -1);
- $pos = strrpos($msg, "\n");
- if ($pos > 0)
- $msg = substr($msg, 0, $pos);
- else if ($lastchar != "\n")
- $msg = substr($msg, 0, -3)."...";
- }
- //$msg = str_replace("\n", " ", $msg);
-
- // Removing multiple spaces - again
- while (strpos($msg, " ") !== false)
- $msg = str_replace(" ", " ", $msg);
-
- //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." ".$msglink) <= ($max_char - 20)))
- return(array("msg"=>trim($msg." ".$msglink)."\n", "image"=>$image));
- else
- return(array("msg"=>trim($msg." ".$msglink), "image"=>""));
-}
-
function statusnet_action($a, $uid, $pid, $action) {
$api = get_pconfig($uid, 'statusnet', 'baseapi');
$ckey = get_pconfig($uid, 'statusnet', 'consumerkey');
$csecret = get_pconfig($b['uid'], 'statusnet', 'consumersecret');
$otoken = get_pconfig($b['uid'], 'statusnet', 'oauthtoken');
$osecret = get_pconfig($b['uid'], 'statusnet', 'oauthsecret');
- $intelligent_shortening = get_pconfig($b['uid'], 'statusnet', 'intelligent_shortening');
-
- // Global setting overrides this
- if (get_config('statusnet','intelligent_shortening'))
- $intelligent_shortening = get_config('statusnet','intelligent_shortening');
if($ckey && $csecret && $otoken && $osecret) {
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
- // shorten all the links in a 200000 character long essay.
$tempfile = "";
- $intelligent_shortening = get_config('statusnet','intelligent_shortening');
- if (!$intelligent_shortening) {
- if (! $b['title']=='') {
- $tmp = $b['title'].": \n".$b['body'];
- // $tmp = substr($tmp, 0, 4*$max_char);
- } else {
- $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);
- // preserve links to images, videos and audios
- $tmp = preg_replace( '/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism', '$3', $tmp);
- $tmp = preg_replace( '/\[\\/?img(\\s+.*?\]|\])/i', '', $tmp);
- $tmp = preg_replace( '/\[\\/?video(\\s+.*?\]|\])/i', '', $tmp);
- $tmp = preg_replace( '/\[\\/?youtube(\\s+.*?\]|\])/i', '', $tmp);
- $tmp = preg_replace( '/\[\\/?vimeo(\\s+.*?\]|\])/i', '', $tmp);
- $tmp = preg_replace( '/\[\\/?audio(\\s+.*?\]|\])/i', '', $tmp);
- $linksenabled = get_pconfig($b['uid'],'statusnet','post_taglinks');
- // if a #tag is linked, don't send the [url] over to SN
- // 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);
- // recycle 1
- $recycle = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8');
- $tmp = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', $recycle.'$2', $tmp);
- // recycle 2 (test)
- $recycle = html_entity_decode("◌ ", ENT_QUOTES, 'UTF-8');
- $tmp = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', $recycle.'$2', $tmp);
- }
- // preserve links to webpages
- $tmp = preg_replace( '/\[url\=(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)\](\w+.*?)\[\/url\]/i', '$2 $1', $tmp);
- $tmp = preg_replace( '/\[bookmark\=(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)\](\w+.*?)\[\/bookmark\]/i', '$2 $1', $tmp);
- // find all http or https links in the body of the entry and
- // apply the shortener if the link is longer then 20 characters
- if (( strlen($tmp)>$max_char ) && ( $max_char > 0 )) {
- preg_match_all ( '/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/i', $tmp, $allurls );
- foreach ($allurls as $url) {
- foreach ($url as $u) {
- if (strlen($u)>20) {
- $sl = short_link($u);
- $tmp = str_replace( $u, $sl, $tmp );
- }
- }
- }
- }
- // ok, all the links we want to send out are save, now strip
- // away the remaining bbcode
- //$msg = strip_tags(bbcode($tmp, false, false));
- $msg = bbcode($tmp, false, false, true);
- $msg = str_replace(array('<br>','<br />'),"\n",$msg);
- $msg = strip_tags($msg);
-
- // 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 = nl2br(substr($msg, 0, $max_char-strlen($shortlink)-4));
- $msg = str_replace(array('<br>','<br />'),' ',$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;
- }
-
- $msg = trim($msg);
- $postdata = array('status' => $msg);
- } else {
-/* $msgarr = statusnet_shortenmsg($b, $max_char);
- $msg = $msgarr["msg"];
+ require_once("include/plaintext.php");
+ require_once("include/network.php");
+ $msgarr = plaintext($a, $b, $max_char, true);
+ $msg = $msgarr["text"];
+
+ if (($msg == "") AND isset($msgarr["title"]))
+ $msg = shortenmsg($msgarr["title"], $max_char - 50);
+
+ $image = "";
+
+ if (isset($msgarr["url"])) {
+ if ((strlen($msgarr["url"]) > 20) AND
+ ((strlen($msg." \n".$msgarr["url"]) > $max_char)))
+ $msg .= " \n".short_link($msgarr["url"]);
+ else
+ $msg .= " \n".$msgarr["url"];
+ } elseif (isset($msgarr["image"]))
$image = $msgarr["image"];
-*/
- require_once("include/plaintext.php");
- require_once("include/network.php");
- $msgarr = plaintext($a, $b, $max_char, true);
- $msg = $msgarr["text"];
-
- if (($msg == "") AND isset($msgarr["title"]))
- $msg = shortenmsg($msgarr["title"], $max_char - 50);
-
- $image = "";
-
- if (isset($msgarr["url"])) {
- if ((strlen($msgarr["url"]) > 20) AND
- ((strlen($msg." ".$msgarr["url"]) > $max_char)))
- $msg .= " ".short_link($msgarr["url"]);
- else
- $msg .= " ".$msgarr["url"];
- } elseif (isset($msgarr["image"]))
- $image = $msgarr["image"];
-
- if ($image != "") {
- $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);
- }
+
+ if ($image != "") {
+ $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)) {
$footer = "";
$footerurl = "";
+ $footerlink = "";
$type = "";
if ($links) {
$expanded_url = original_url($match[1]);
- $oembed_data = oembed_fetch_url($expanded_url);
-
+ $oembed_data = oembed_fetch_url($expanded_url, true);
+print_r($oembed_data);
if ($type == "")
$type = $oembed_data->type;
+ if ($oembed_data->type == "video") {
+ //$body = str_replace($search, "[video]".$expanded_url."[/video]", $body);
+ $type = $oembed_data->type;
+ $footerurl = $expanded_url;
+ $footerlink = "[url=".$expanded_url."]".$expanded_url."[/url]";
- if ($oembed_data->type == "video")
- $body = str_replace($search, "[video]".$expanded_url."[/video]", $body);
- elseif (($oembed_data->type == "photo") AND isset($oembed_data->url) AND !$dontincludemedia)
+ $body = str_replace($search, $footerlink, $body);
+ } elseif (($oembed_data->type == "photo") AND isset($oembed_data->url) AND !$dontincludemedia)
$body = str_replace($search, "[url=".$expanded_url."][img]".$oembed_data->url."[/img][/url]", $body);
elseif ($oembed_data->type != "link")
$body = str_replace($search, "[url=".$expanded_url."]".$expanded_url."[/url]", $body);
$footerurl = $expanded_url;
$footerlink = "[url=".$expanded_url."]".$expanded_url."[/url]";
- $body = str_replace($search, $expanded_url, $body);
+ $body = str_replace($search, $footerlink, $body);
}
}
}
/**
* Name: Tumblr Post Connector
* Description: Post to Tumblr
- * Version: 1.0
+ * Version: 2.0
* Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
+ * Author: Michael Vogel <https://pirati.ca/profile/heluecht>
*/
require_once('library/OAuth1.php');
if(count($tag_arr))
$tags = implode(',',$tag_arr);
- $link = "";
- $video = false;
$title = trim($b['title']);
+ require_once('include/plaintext.php');
- // Checking for a bookmark
- if(preg_match("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/is",$b['body'],$matches)) {
- $link = $matches[1];
- if ($title == '')
- $title = html_entity_decode($matches[2],ENT_QUOTES,'UTF-8');
+ $siteinfo = get_attached_data($b["body"]);
- $body = $b['body'];
- // splitting the text in two parts:
- // before and after the bookmark
- $pos = strpos($body, "[bookmark");
- $body1 = substr($body, 0, $pos);
- $body2 = substr($body, $pos);
+ $params = array(
+ 'state' => 'published',
+ 'tags' => $tags,
+ 'tweet' => 'off',
+ 'format' => 'html');
- // Removing the bookmark
- $body2 = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",'',$body2);
- $body = $body1.$body2;
+ if (!isset($siteinfo["type"]))
+ $siteinfo["type"] = "";
- $video = ((stristr($link,'youtube')) || (stristr($link,'youtu.be')) || (stristr($mtch[1],'vimeo')));
- }
+ if (($title == "") AND isset($siteinfo["title"]))
+ $title = $siteinfo["title"];
- $params = array(
- 'format' => 'html',
- 'tweet' => 'off',
- 'tags' => $tags);
-
- if (($link != '') and $video) {
- $params['type'] = "video";
- $params['embed'] = $link;
- if ($title != '')
- $params['caption'] = '<h1><a href="'.$link.'">'.$title.
- "</a></h1><p>".bbcode($body, false, false, 4)."</p>";
- else
+ if (isset($siteinfo["text"]))
+ $body = $siteinfo["text"];
+ else
+ $body = bb_remove_share_information($b["body"]);
+
+ switch ($siteinfo["type"]) {
+ case "photo":
+ $params['type'] = "photo";
$params['caption'] = bbcode($body, false, false, 4);
- } else if (($link != '') and !$video) {
- $params['type'] = "link";
- $params['title'] = $title;
- $params['url'] = $link;
- $params['description'] = bbcode($b["body"], false, false, 4);
- } else {
- $params['type'] = "text";
- $params['title'] = $title;
- $params['body'] = bbcode($b['body'], false, false, 4);
+
+ if (isset($siteinfo["url"]))
+ $params['link'] = $siteinfo["url"];
+
+ $params['source'] = $siteinfo["image"];
+ break;
+ case "link":
+ $params['type'] = "link";
+ $params['title'] = $title;
+ $params['url'] = $siteinfo["url"];
+ $params['description'] = bbcode($body, false, false, 4);
+ break;
+ case "audio":
+ $params['type'] = "audio";
+ $params['external_url'] = $siteinfo["url"];
+ $params['caption'] = bbcode($body, false, false, 4);
+ break;
+ case "video":
+ $params['type'] = "video";
+ $params['embed'] = $siteinfo["url"];
+ $params['caption'] = bbcode($body, false, false, 4);
+ break;
+ default:
+ $params['type'] = "text";
+ $params['title'] = $title;
+ $params['body'] = bbcode($b['body'], false, false, 4);
+ break;
}
+ if (isset($params['caption']) AND (trim($title) != ""))
+ $params['caption'] = '<h1>'.$title."</h1>".
+ "<p>".$params['caption']."</p>";
+
+ if (trim($params['caption']) == "")
+ $params['caption'] = bbcode("[quote]".$siteinfo["description"]."[/quote]", false, false, 4);
+
$consumer_key = get_config('tumblr','consumer_key');
$consumer_secret = get_config('tumblr','consumer_secret');
// Make an API call with the TumblrOAuth instance.
$x = $tum_oauth->post($tmbl_blog,$params);
-
$ret_code = $tum_oauth->http_code;
-
+ //print_r($params);
if($ret_code == 201)
logger('tumblr_send: success');
elseif($ret_code == 403)
del_pconfig(local_user(), 'twitter', 'oauthsecret');
del_pconfig(local_user(), 'twitter', 'post');
del_pconfig(local_user(), 'twitter', 'post_by_default');
- del_pconfig(local_user(), 'twitter', 'post_taglinks');
del_pconfig(local_user(), 'twitter', 'lastid');
del_pconfig(local_user(), 'twitter', 'mirror_posts');
- del_pconfig(local_user(), 'twitter', 'intelligent_shortening');
del_pconfig(local_user(), 'twitter', 'import');
del_pconfig(local_user(), 'twitter', 'create_user');
del_pconfig(local_user(), 'twitter', 'own_id');
set_pconfig(local_user(),'twitter', 'oauthtoken', $token['oauth_token']);
set_pconfig(local_user(),'twitter', 'oauthsecret', $token['oauth_token_secret']);
set_pconfig(local_user(),'twitter', 'post', 1);
- set_pconfig(local_user(),'twitter', 'post_taglinks', 1);
// reload the Addon Settings page, if we don't do it see Bug #42
goaway($a->get_baseurl().'/settings/connectors');
} else {
// to post a tweet for every new __public__ posting to the wall
set_pconfig(local_user(),'twitter','post',intval($_POST['twitter-enable']));
set_pconfig(local_user(),'twitter','post_by_default',intval($_POST['twitter-default']));
- set_pconfig(local_user(),'twitter','post_taglinks',intval($_POST['twitter-sendtaglinks']));
set_pconfig(local_user(), 'twitter', 'mirror_posts', intval($_POST['twitter-mirror']));
- set_pconfig(local_user(), 'twitter', 'intelligent_shortening', intval($_POST['twitter-shortening']));
set_pconfig(local_user(), 'twitter', 'import', intval($_POST['twitter-import']));
set_pconfig(local_user(), 'twitter', 'create_user', intval($_POST['twitter-create_user']));
info( t('Twitter settings updated.') . EOL);
$checked = (($enabled) ? ' checked="checked" ' : '');
$defenabled = get_pconfig(local_user(),'twitter','post_by_default');
$defchecked = (($defenabled) ? ' checked="checked" ' : '');
- $linksenabled = get_pconfig(local_user(),'twitter','post_taglinks');
- $linkschecked = (($linksenabled) ? ' checked="checked" ' : '');
$mirrorenabled = get_pconfig(local_user(),'twitter','mirror_posts');
$mirrorchecked = (($mirrorenabled) ? ' checked="checked" ' : '');
- $shorteningenabled = get_pconfig(local_user(),'twitter','intelligent_shortening');
- $shorteningchecked = (($shorteningenabled) ? ' checked="checked" ' : '');
$importenabled = get_pconfig(local_user(),'twitter','import');
$importchecked = (($importenabled) ? ' checked="checked" ' : '');
$create_userenabled = get_pconfig(local_user(),'twitter','create_user');
$css = (($enabled) ? '' : '-disabled');
- $globalshortening = get_config('twitter','intelligent_shortening');
-
$s .= '<span id="settings_twitter_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_twitter_expanded\'); openClose(\'settings_twitter_inflated\');">';
$s .= '<img class="connector'.$css.'" src="images/twitter.png" /><h3 class="connector">'. t('Twitter Import/Export/Mirror').'</h3>';
$s .= '</span>';
$s .= '<label id="twitter-mirror-label" for="twitter-mirror">'.t('Mirror all posts from twitter that are no replies').'</label>';
$s .= '<input id="twitter-mirror" type="checkbox" name="twitter-mirror" value="1" '. $mirrorchecked . '/>';
$s .= '<div class="clear"></div>';
-
- if (!$globalshortening) {
- $s .= '<label id="twitter-shortening-label" for="twitter-shortening">'.t('Shortening method that optimizes the tweet').'</label>';
- $s .= '<input id="twitter-shortening" type="checkbox" name="twitter-shortening" value="1" '. $shorteningchecked . '/>';
- $s .= '<div class="clear"></div>';
-
- $s .= '<label id="twitter-sendtaglinks-label" for="twitter-sendtaglinks">'.t('Send linked #-tags and @-names to Twitter').'</label>';
- $s .= '<input id="twitter-sendtaglinks" type="checkbox" name="twitter-sendtaglinks" value="1" '. $linkschecked . '/>';
- $s .= '<div class="clear"></div>';
- }
$s .= '</div>';
$s .= '<label id="twitter-import-label" for="twitter-import">'.t('Import the remote timeline').'</label>';
}
}
-if (! function_exists('short_link')) {
-function short_link ($url) {
- require_once('library/slinky.php');
- $slinky = new Slinky( $url );
- $yourls_url = get_config('yourls','url1');
- if ($yourls_url) {
- $yourls_username = get_config('yourls','username1');
- $yourls_password = get_config('yourls', 'password1');
- $yourls_ssl = get_config('yourls', 'ssl1');
- $yourls = new Slinky_YourLS();
- $yourls->set( 'username', $yourls_username );
- $yourls->set( 'password', $yourls_password );
- $yourls->set( 'ssl', $yourls_ssl );
- $yourls->set( 'yourls-url', $yourls_url );
- $slinky->set_cascade( array( $yourls, new Slinky_UR1ca(), new Slinky_Trim(), new Slinky_IsGd(), new Slinky_TinyURL() ) );
- }
- else {
- // setup a cascade of shortening services
- // try to get a short link from these services
- // in the order ur1.ca, trim, id.gd, tinyurl
- $slinky->set_cascade( array( new Slinky_UR1ca(), new Slinky_Trim(), new Slinky_IsGd(), new Slinky_TinyURL() ) );
- }
- return $slinky->short();
-} };
-
-function twitter_shortenmsg($b, $shortlink = false) {
- require_once("include/api.php");
- require_once("include/bbcode.php");
- require_once("include/html2plain.php");
-
- $max_char = 140;
-
- $b['body'] = bb_CleanPictureLinks($b['body']);
-
- // Looking for the first image
- $cleaned_body = api_clean_plain_items($b['body']);
- $image = '';
- if(preg_match("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/is",$cleaned_body,$matches))
- $image = $matches[3];
-
- if ($image == '')
- if(preg_match("/\[img\](.*?)\[\/img\]/is",$cleaned_body,$matches))
- $image = $matches[1];
-
- $multipleimages = (strpos($cleaned_body, "[img") != strrpos($cleaned_body, "[img"));
-
- // When saved into the database the content is sent through htmlspecialchars
- // That means that we have to decode all image-urls
- $image = htmlspecialchars_decode($image);
-
- $body = $b["body"];
- if ($b["title"] != "")
- $body = $b["title"]."\n\n".$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 all quotes after the bookmark
- // they are mostly only the content after the bookmark.
- $body2 = preg_replace("/\[quote\=([^\]]*)\](.*?)\[\/quote\]/ism",'',$body2);
- $body2 = preg_replace("/\[quote\](.*?)\[\/quote\]/ism",'',$body2);
- $body = $body1.$body2;
- }
-
- // Add some newlines so that the message could be cut better
- $body = str_replace(array("[quote", "[bookmark", "[/bookmark]", "[/quote]"),
- array("\n[quote", "\n[bookmark", "[/bookmark]\n", "[/quote]\n"), $body);
-
- // remove the recycle signs and the names since they aren't helpful on twitter
- // recycle 1
- $recycle = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8');
- $body = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', "\n", $body);
- // recycle 2 (Test)
- $recycle = html_entity_decode("◌ ", ENT_QUOTES, 'UTF-8');
- $body = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', "\n", $body);
-
- // remove the share element
- //$body = preg_replace("/\[share(.*?)\](.*?)\[\/share\]/ism","\n\n$2\n\n",$body);
-
- // At first convert the text to html
- $html = bbcode(api_clean_plain_items($body), false, false, 2);
-
- // Then convert it to plain text
- $msg = trim(html2plain($html, 0, true));
- $msg = html_entity_decode($msg,ENT_QUOTES,'UTF-8');
-
- // Removing multiple newlines
- while (strpos($msg, "\n\n\n") !== false)
- $msg = str_replace("\n\n\n", "\n\n", $msg);
-
- // Removing multiple spaces
- while (strpos($msg, " ") !== false)
- $msg = str_replace(" ", " ", $msg);
-
- $origmsg = trim($msg);
-
- // Removing URLs
- $msg = preg_replace('/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/i', "", $msg);
-
- $msg = trim($msg);
-
- $link = '';
- // look for bookmark-bbcode and handle it with priority
- if(preg_match("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/is",$b['body'],$matches))
- $link = $matches[1];
-
- $multiplelinks = (strpos($b['body'], "[bookmark") != strrpos($b['body'], "[bookmark"));
-
- // If there is no bookmark element then take the first link
- if ($link == '') {
- $links = collecturls($html);
-
- foreach($links AS $singlelink) {
- $img_str = fetch_url($singlelink);
-
- $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 (substr($mime, 0, 6) == "image/") {
- $image = $singlelink;
- unset($links[$singlelink]);
- }
- }
-
- if (sizeof($links) > 0) {
- reset($links);
- $link = current($links);
- }
- $multiplelinks = (sizeof($links) > 1);
- }
-
- $msglink = "";
- if ($multiplelinks)
- $msglink = $b["plink"];
- else if ($link != "")
- $msglink = $link;
- else if ($multipleimages)
- $msglink = $b["plink"];
- else if ($image != "")
- $msglink = $image;
-
- if (($msglink == "") and strlen($msg) > $max_char)
- $msglink = $b["plink"];
-
- // If the message is short enough then don't modify it.
- if ((strlen($origmsg) <= $max_char) AND ($msglink == ""))
- return(array("msg"=>$origmsg, "image"=>""));
-
- // If the message is short enough and contains a picture then post the picture as well
- if ((strlen($origmsg) <= ($max_char - 23)) AND strpos($origmsg, $msglink))
- return(array("msg"=>$origmsg, "image"=>$image));
-
- // If the message is short enough and the link exists in the original message don't modify it as well
- // -3 because of the bad shortener of twitter
- if ((strlen($origmsg) <= ($max_char - 3)) AND strpos($origmsg, $msglink))
- return(array("msg"=>$origmsg, "image"=>""));
-
- // Preserve the unshortened link
- $orig_link = $msglink;
-
- // Just replace the message link with a 22 character long string
- // Twitter calculates with this length
- if (trim($msglink) <> '')
- $msglink = "1234567890123456789012";
-
- if (strlen(trim($msg." ".$msglink)) > ($max_char)) {
- $msg = substr($msg, 0, ($max_char) - (strlen($msglink)));
- $lastchar = substr($msg, -1);
- $msg = substr($msg, 0, -1);
- $pos = strrpos($msg, "\n");
- if ($pos > 0)
- $msg = substr($msg, 0, $pos);
- else if ($lastchar != "\n")
- $msg = substr($msg, 0, -3)."...";
-
- // if the post contains a picture and a link then the system tries to cut the post earlier.
- // So the link and the picture can be posted.
- if (($image != "") AND ($orig_link != $image)) {
- $msg2 = substr($msg, 0, ($max_char - 20) - (strlen($msglink)));
- $lastchar = substr($msg2, -1);
- $msg2 = substr($msg2, 0, -1);
- $pos = strrpos($msg2, "\n");
- if ($pos > 0)
- $msg = substr($msg2, 0, $pos);
- else if ($lastchar == "\n")
- $msg = trim($msg2);
- }
-
- }
- // Removing multiple spaces - again
- while (strpos($msg, " ") !== false)
- $msg = str_replace(" ", " ", $msg);
-
- $msg = trim($msg);
-
- // Removing multiple newlines
- //while (strpos($msg, "\n\n") !== false)
- // $msg = str_replace("\n\n", "\n", $msg);
-
- // 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"=>$msg, "image"=>$orig_link));
- else if (($image != $orig_link) AND ($image != "") AND (strlen($msg." ".$msglink) <= ($max_char - 23))) {
- if ($shortlink)
- $orig_link = short_link($orig_link);
-
- return(array("msg"=>$msg." ".$orig_link, "image"=>$image));
- } else {
- if ($shortlink)
- $orig_link = short_link($orig_link);
-
- return(array("msg"=>$msg." ".$orig_link, "image"=>""));
- }
-}
-
function twitter_action($a, $uid, $pid, $action) {
$ckey = get_config('twitter', 'consumerkey');
* Post to Twitter
*/
+ require_once("include/network.php");
+
if (!get_pconfig($b["uid"],'twitter','import')) {
if($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited']))
return;
$csecret = get_config('twitter', 'consumersecret');
$otoken = get_pconfig($b['uid'], 'twitter', 'oauthtoken');
$osecret = get_pconfig($b['uid'], 'twitter', 'oauthsecret');
- $intelligent_shortening = get_pconfig($b['uid'], 'twitter', 'intelligent_shortening');
-
- // Global setting overrides this
- if (get_config('twitter','intelligent_shortening'))
- $intelligent_shortening = get_config('twitter','intelligent_shortening');
if($ckey && $csecret && $otoken && $osecret) {
logger('twitter: we have customer key and oauth stuff, going to send.', LOGGER_DEBUG);
require_once('include/bbcode.php');
$tweet = new TwitterOAuth($ckey,$csecret,$otoken,$osecret);
- // in theory max char is 140 but T. uses t.co to make links
- // longer so we give them 10 characters extra
- if (!$intelligent_shortening) {
- $max_char = 130; // max. length for a tweet
- // we will only work with up to two times the length of the dent
- // we can later send to Twitter. 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, 4*$max_char);
- } else {
- $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);
- // preserve links to images, videos and audios
- $tmp = preg_replace( '/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism', '$3', $tmp);
- $tmp = preg_replace( '/\[\\/?img(\\s+.*?\]|\])/i', '', $tmp);
- $tmp = preg_replace( '/\[\\/?video(\\s+.*?\]|\])/i', '', $tmp);
- $tmp = preg_replace( '/\[\\/?youtube(\\s+.*?\]|\])/i', '', $tmp);
- $tmp = preg_replace( '/\[\\/?vimeo(\\s+.*?\]|\])/i', '', $tmp);
- $tmp = preg_replace( '/\[\\/?audio(\\s+.*?\]|\])/i', '', $tmp);
- $linksenabled = get_pconfig($b['uid'],'twitter','post_taglinks');
- // if a #tag is linked, don't send the [url] over to SN
- // 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);
- // recycle 1
- $recycle = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8');
- $tmp = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', $recycle.'$2', $tmp);
- // recycle 2 (Test)
- $recycle = html_entity_decode("◌ ", ENT_QUOTES, 'UTF-8');
- $tmp = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', $recycle.'$2', $tmp);
- }
- $tmp = preg_replace( '/\[url\=(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)\](\w+.*?)\[\/url\]/i', '$2 $1', $tmp);
- $tmp = preg_replace( '/\[bookmark\=(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)\](\w+.*?)\[\/bookmark\]/i', '$2 $1', $tmp);
- // find all http or https links in the body of the entry and
- // apply the shortener if the link is longer then 20 characters
- if (( strlen($tmp)>$max_char ) && ( $max_char > 0 )) {
- preg_match_all ( '/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/i', $tmp, $allurls );
- foreach ($allurls as $url) {
- foreach ($url as $u) {
- if (strlen($u)>20) {
- $sl = short_link($u);
- $tmp = str_replace( $u, $sl, $tmp );
- }
- }
- }
- }
- // ok, all the links we want to send out are save, now strip
- // away the remaining bbcode
- //$msg = strip_tags(bbcode($tmp, false, false));
- $msg = bbcode($tmp, false, false, true);
- $msg = str_replace(array('<br>','<br />'),"\n",$msg);
- $msg = strip_tags($msg);
-
- // 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 = nl2br(substr($msg, 0, $max_char-strlen($shortlink)-4));
- $msg = str_replace(array('<br>','<br />'),' ',$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;
- }
+ $max_char = 140;
+ require_once("include/plaintext.php");
+ $msgarr = plaintext($a, $b, $max_char, true);
+ $msg = $msgarr["text"];
- $msg = trim($msg);
- $image = "";
- } else {
- $msgarr = twitter_shortenmsg($b);
- $msg = $msgarr["msg"];
- $image = $msgarr["image"];
- }
+ if (($msg == "") AND isset($msgarr["title"]))
+ $msg = shortenmsg($msgarr["title"], $max_char - 50);
+
+ $image = "";
+
+ if (isset($msgarr["url"]))
+ $msg .= "\n".$msgarr["url"];
+ elseif (isset($msgarr["image"]))
+ $image = $msgarr["image"];
// and now tweet it :-)
if(strlen($msg) and ($image != "")) {
$type = $oembed_data->type;
if ($oembed_data->type == "video") {
- $body = str_replace($url->url,
- "[video]".$expanded_url."[/video]", $body);
- $dontincludemedia = true;
+ //$body = str_replace($url->url,
+ // "[video]".$expanded_url."[/video]", $body);
+ //$dontincludemedia = true;
+ $type = $oembed_data->type;
+ $footerurl = $expanded_url;
+ $footerlink = "[url=".$expanded_url."]".$expanded_url."[/url]";
+
+ $body = str_replace($url->url, $footerlink, $body);
} elseif (($oembed_data->type == "photo") AND isset($oembed_data->url) AND !$dontincludemedia) {
$body = str_replace($url->url,
"[url=".$expanded_url."][img]".$oembed_data->url."[/img][/url]",
#wppost-enable-label, #wppost-username-label, #wppost-password-label,
-#wppost-blog-label, #wppost-bydefault-label, #wppost-backlink-label {
+#wppost-blog-label, #wppost-bydefault-label,
+#wppost-backlink-label, #wppost-shortcheck-label {
float: left;
width: 200px;
margin-top: 10px;
}
#wppost-checkbox, #wppost-username, #wppost-password,
-#wppost-blog, #wppost-bydefault, #wppost-backlink {
+#wppost-blog, #wppost-bydefault,
+#wppost-shortcheck, #wppost-backlink {
float: left;
margin-top: 10px;
}
function wppost_settings(&$a,&$s) {
- if(! local_user())
- return;
+ if(! local_user())
+ return;
- /* Add our stylesheet to the page so we can make our settings look nice */
+ /* Add our stylesheet to the page so we can make our settings look nice */
- $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/wppost/wppost.css' . '" media="all" />' . "\r\n";
+ $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/wppost/wppost.css' . '" media="all" />' . "\r\n";
- /* Get the current state of our config variables */
+ /* Get the current state of our config variables */
- $enabled = get_pconfig(local_user(),'wppost','post');
- $checked = (($enabled) ? ' checked="checked" ' : '');
+ $enabled = get_pconfig(local_user(),'wppost','post');
+ $checked = (($enabled) ? ' checked="checked" ' : '');
- $css = (($enabled) ? '' : '-disabled');
+ $css = (($enabled) ? '' : '-disabled');
- $def_enabled = get_pconfig(local_user(),'wppost','post_by_default');
- $back_enabled = get_pconfig(local_user(),'wppost','backlink');
+ $def_enabled = get_pconfig(local_user(),'wppost','post_by_default');
+ $back_enabled = get_pconfig(local_user(),'wppost','backlink');
+ $shortcheck_enabled = get_pconfig(local_user(),'wppost','shortcheck');
- $def_checked = (($def_enabled) ? ' checked="checked" ' : '');
- $back_checked = (($back_enabled) ? ' checked="checked" ' : '');
+ $def_checked = (($def_enabled) ? ' checked="checked" ' : '');
+ $back_checked = (($back_enabled) ? ' checked="checked" ' : '');
+ $shortcheck_checked = (($shortcheck_enabled) ? ' checked="checked" ' : '');
$wp_username = get_pconfig(local_user(), 'wppost', 'wp_username');
$wp_password = get_pconfig(local_user(), 'wppost', 'wp_password');
$s .= '<div id="wppost-backlink-wrapper">';
$s .= '<label id="wppost-backlink-label" for="wppost-backlink">' . t('Provide a backlink to the Friendica post') . '</label>';
$s .= '<input id="wppost-backlink" type="checkbox" name="wp_backlink" value="1" ' . $back_checked . '/>';
+ $s .= '</div><div class="clear"></div>';
+ $s .= '<div id="wppost-shortcheck-wrapper">';
+ $s .= '<label id="wppost-shortcheck-label" for="wppost-shortcheck">' . t("Don't post messages that are too short") . '</label>';
+ $s .= '<input id="wppost-shortcheck" type="checkbox" name="wp_shortcheck" value="1" '.$shortcheck_checked.'/>';
$s .= '</div><div class="clear"></div>';
/* provide a submit button */
set_pconfig(local_user(),'wppost','wp_password',trim($_POST['wp_password']));
set_pconfig(local_user(),'wppost','wp_blog',trim($_POST['wp_blog']));
set_pconfig(local_user(),'wppost','backlink',trim($_POST['wp_backlink']));
+ set_pconfig(local_user(),'wppost','shortcheck',trim($_POST['wp_shortcheck']));
}
function wppost_send(&$a,&$b) {
- if($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited']))
- return;
+ if($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited']))
+ return;
- if(! strstr($b['postopts'],'wppost'))
- return;
+ if(! strstr($b['postopts'],'wppost'))
+ return;
- if($b['parent'] != $b['id'])
- return;
+ if($b['parent'] != $b['id'])
+ return;
$wp_username = xmlify(get_pconfig($b['uid'],'wppost','wp_username'));
require_once('include/bbcode.php');
require_once('include/html2plain.php');
+ require_once('include/plaintext.php');
$wptitle = trim($b['title']);
+ if (intval(get_pconfig($b['uid'],'wppost','shortcheck'))) {
+ // Checking, if its a post that is worth a blog post
+ $postentry = false;
+ $siteinfo = get_attached_data($b["body"]);
+
+ // Is it a link to an aricle, a video or a photo?
+ if (isset($siteinfo["type"]))
+ if (in_array($siteinfo["type"], array("link", "audio", "video", "photo")))
+ $postentry = true;
+
+ // Does it have a title?
+ if ($wptitle != "")
+ $postentry = true;
+
+ // Is it larger than 500 characters?
+ if (strlen($b['body']) > 500)
+ $postentry = true;
+
+ if (!$postentry)
+ return;
+ }
+
// If the title is empty then try to guess
if ($wptitle == '') {
// Take the description from the bookmark