Merge pull request #186 from annando/master

Bidirectional Statusnet sync, bugfix for posting facebook comments and some title improvements
This commit is contained in:
fabrixxm 2014-04-22 16:13:44 +02:00
commit 02735d12ff
16 changed files with 1398 additions and 798 deletions

View file

@ -53,11 +53,11 @@ function appnetpost_settings(&$a,&$s) {
$def_checked = (($def_enabled) ? ' checked="checked" ' : '');
$s .= '<span id="settings_appnetpost_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_appnetpost_expanded\'); openClose(\'settings_appnetpost_inflated\');">';
$s .= '<h3>' . t('App.net') . '</h3>';
$s .= '<h3>' . t('App.net Export') . '</h3>';
$s .= '</span>';
$s .= '<div id="settings_appnetpost_expanded" class="settings-block" style="display: none;">';
$s .= '<span class="fakelink" onclick="openClose(\'settings_appnetpost_expanded\'); openClose(\'settings_appnetpost_inflated\');">';
$s .= '<h3>' . t('App.net') . '</h3>';
$s .= '<h3>' . t('App.net Export') . '</h3>';
$s .= '</span>';
$s .= '<div id="appnetpost-enable-wrapper">';
@ -196,65 +196,6 @@ function appnetpost_init() {
killme();
}
function appnetpost_original_url($url, $depth=1) {
if ($depth > 10)
return($url);
$siteinfo = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0');
$header = curl_exec($ch);
$curl_info = @curl_getinfo($ch);
$http_code = $curl_info['http_code'];
curl_close($ch);
if ((($curl_info['http_code'] == "301") OR ($curl_info['http_code'] == "302"))
AND (($curl_info['redirect_url'] != "") OR ($curl_info['location'] != ""))) {
if ($curl_info['redirect_url'] != "")
return(appnetpost_original_url($curl_info['redirect_url'], ++$depth));
else
return(appnetpost_original_url($curl_info['location'], ++$depth));
}
$pos = strpos($header, "\r\n\r\n");
if ($pos)
$body = trim(substr($header, $pos));
else
$body = $header;
$doc = new DOMDocument();
@$doc->loadHTML($body);
$xpath = new DomXPath($doc);
$list = $xpath->query("//meta[@content]");
foreach ($list as $node) {
$attr = array();
if ($node->attributes->length)
foreach ($node->attributes as $attribute)
$attr[$attribute->name] = $attribute->value;
if (@$attr["http-equiv"] == 'refresh') {
$path = $attr["content"];
$pathinfo = explode(";", $path);
$content = "";
foreach ($pathinfo AS $value)
if (substr(strtolower($value), 0, 4) == "url=")
return(appnetpost_original_url(substr($value, 4), ++$depth));
}
}
return($url);
}
if (! function_exists( 'short_link' )) {
function short_link($url) {
require_once('library/slinky.php');
@ -387,7 +328,7 @@ function appnetpost_feeditem($pid, $uid) {
if ($title == "")
continue;
//$origlink = appnetpost_original_url($origlink);
//$origlink = original_url($origlink);
$html = nl2br($title);

View file

@ -71,11 +71,11 @@ function blogger_settings(&$a,&$s) {
/* Add some HTML to the existing form */
$s .= '<span id="settings_blogger_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_blogger_expanded\'); openClose(\'settings_blogger_inflated\');">';
$s .= '<h3>' . t('Blogger') . '</h3>';
$s .= '<h3>' . t('Blogger Export') . '</h3>';
$s .= '</span>';
$s .= '<div id="settings_blogger_expanded" class="settings-block" style="display: none;">';
$s .= '<span class="fakelink" onclick="openClose(\'settings_blogger_expanded\'); openClose(\'settings_blogger_inflated\');">';
$s .= '<h3>' . t('Blogger') . '</h3>';
$s .= '<h3>' . t('Blogger Export') . '</h3>';
$s .= '</span>';
$s .= '<div id="blogger-enable-wrapper">';

View file

@ -61,11 +61,12 @@ class Diasphp {
return $this;
}
function post($text) {
function post($text, $provider = "diasphp") {
// post-daten vorbereiten
$datatopost = json_encode(array(
'aspect_ids' => 'public',
'status_message' => array('text' => $text)
'status_message' => array('text' => $text,
'provider_display_name' => $provider)
));
// header vorbereiten

View file

@ -39,6 +39,8 @@ function diaspora_jot_nets(&$a,&$b) {
}
function diaspora_queue_hook(&$a,&$b) {
$hostname = $a->get_hostname();
$qi = q("SELECT * FROM `queue` WHERE `network` = '%s'",
dbesc(NETWORK_DIASPORA2)
);
@ -85,7 +87,7 @@ function diaspora_queue_hook(&$a,&$b) {
logger('diaspora_queue: try to log in '.$diaspora_username, LOGGER_DEBUG);
$conn->login($diaspora_username, $diaspora_password);
logger('diaspora_queue: try to send '.$body, LOGGER_DEBUG);
$conn->post($post);
$conn->post($post, $hostname);
logger('diaspora_queue: send '.$userdata['uid'].' success', LOGGER_DEBUG);
@ -144,11 +146,11 @@ function diaspora_settings(&$a,&$s) {
/* Add some HTML to the existing form */
$s .= '<span id="settings_diaspora_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_diaspora_expanded\'); openClose(\'settings_diaspora_inflated\');">';
$s .= '<h3>' . t('Diaspora') . '</h3>';
$s .= '<h3>' . t('Diaspora Export') . '</h3>';
$s .= '</span>';
$s .= '<div id="settings_diaspora_expanded" class="settings-block" style="display: none;">';
$s .= '<span class="fakelink" onclick="openClose(\'settings_diaspora_expanded\'); openClose(\'settings_diaspora_inflated\');">';
$s .= '<h3>' . t('Diaspora') . '</h3>';
$s .= '<h3>' . t('Diaspora Export') . '</h3>';
$s .= '</span>';
if ($status) {
@ -233,6 +235,7 @@ function diaspora_post_local(&$a,&$b) {
function diaspora_send(&$a,&$b) {
$hostname = $a->get_hostname();
logger('diaspora_send: invoked');
@ -303,7 +306,7 @@ function diaspora_send(&$a,&$b) {
logger('diaspora_send: try to send '.$body, LOGGER_DEBUG);
//throw new Exception('Test');
$conn->post($body);
$conn->post($body, $hostname);
logger('diaspora_send: success');
} catch (Exception $e) {

View file

@ -207,7 +207,7 @@ function fbpost_content(&$a) {
$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="'
. $a->get_baseurl() . '/addon/fbpost/fbpost.css' . '" media="all" />' . "\r\n";
$o .= '<h3>' . t('Facebook') . '</h3>';
$o .= '<h3>' . t('Facebook Export/Mirror') . '</h3>';
if(! $fb_installed) {
$o .= '<div id="fbpost-enable-wrapper">';
@ -293,7 +293,7 @@ function fbpost_content(&$a) {
function fbpost_plugin_settings(&$a,&$b) {
$b .= '<div class="settings-block">';
$b .= '<a href="fbpost"><h3>' . t('Facebook') . '</a></h3>';
$b .= '<a href="fbpost"><h3>' . t('Facebook Export/Mirror') . '</a></h3>';
$b .= '</div>';
}
@ -571,6 +571,7 @@ function fbpost_post_hook(&$a,&$b) {
$allow_str = dbesc(implode(', ',$recipients));
if($allow_str) {
logger("fbpost_post_hook: private post to: ".$allow_str, LOGGER_DEBUG);
$r = q("SELECT `notify` FROM `contact` WHERE `id` IN ( $allow_str ) AND `network` = 'face'");
if(count($r))
foreach($r as $rr)
@ -633,7 +634,7 @@ function fbpost_post_hook(&$a,&$b) {
logger('fbpost_post_hook: original msg=' . $msg, LOGGER_DATA);
// To-Do: if it is a reply, then only do a simple bbcode2plain conversion
if ($toplevel) {
$msgarr = fbpost_createmsg($b);
$msg = $msgarr["msg"];
$link = $msgarr["link"];
@ -649,6 +650,16 @@ function fbpost_post_hook(&$a,&$b) {
if(!strlen($msg))
$msg = $image;
} else {
require_once("include/bbcode.php");
require_once("include/html2plain.php");
$msg = bb_CleanPictureLinks($msg);
$msg = bbcode($msg, false, false, 2, true);
$msg = trim(html2plain($msg, 0));
$link = "";
$image = "";
$linkname = "";
}
// If there is nothing to post then exit
if(!strlen($msg))
@ -1105,7 +1116,7 @@ function fbpost_fetchwall($a, $uid) {
}
if ($content)
$_REQUEST["body"] .= "\n\n";
$_REQUEST["body"] .= "\n";
if ($type)
$_REQUEST["body"] .= "[class=type-".$type."]";

View file

@ -177,7 +177,7 @@ function fbsync_cron($a,$b) {
}
}
logger('fbsync: cron_end');
logger('fbsync_cron: cron_end');
set_config('fbsync','last_poll', time());
}
@ -322,7 +322,7 @@ function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $cr
}
if ($content)
$postarray["body"] .= "\n\n";
$postarray["body"] .= "\n";
if ($type)
$postarray["body"] .= "[class=type-".$type."]";
@ -692,7 +692,7 @@ function fbsync_fetch_contact($uid, $contact, $create_user) {
dbesc(normalise_link($contact->url)),
dbesc($contact->username."@facebook.com"),
dbesc("facebook::".$contact->id),
dbesc(''),
dbesc($contact->id),
dbesc("facebook::".$contact->id),
dbesc($contact->name),
dbesc($contact->username),
@ -764,7 +764,8 @@ function fbsync_fetch_contact($uid, $contact, $create_user) {
`nurl` = '%s',
`addr` = '%s',
`name` = '%s',
`nick` = '%s'
`nick` = '%s',
`notify` = '%s'
WHERE `id` = %d",
dbesc($photos[0]),
dbesc($photos[1]),
@ -777,6 +778,7 @@ function fbsync_fetch_contact($uid, $contact, $create_user) {
dbesc($contact->username."@facebook.com"),
dbesc($contact->name),
dbesc($contact->username),
dbesc($contact->id),
intval($r[0]['id'])
);
}

View file

@ -34,11 +34,11 @@ function fromgplus_addon_settings(&$a,&$s) {
$account = get_pconfig(local_user(),'fromgplus','account');
$s .= '<span id="settings_fromgplus_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_fromgplus_expanded\'); openClose(\'settings_fromgplus_inflated\');">';
$s .= '<h3>' . t('Google+ Mirroring').'</h3>';
$s .= '<h3>' . t('Google+ Mirror').'</h3>';
$s .= '</span>';
$s .= '<div id="settings_fromgplus_expanded" class="settings-block" style="display: none;">';
$s .= '<span class="fakelink" onclick="openClose(\'settings_fromgplus_expanded\'); openClose(\'settings_fromgplus_inflated\');">';
$s .= '<h3>' . t('Google+ Mirroring').'</h3>';
$s .= '<h3>' . t('Google+ Mirror').'</h3>';
$s .= '</span>';
$s .= '<div id="fromgplus-wrapper">';
@ -263,7 +263,7 @@ function fromgplus_handleattachments($item, $displaytext) {
break;
case "article":
$post .= "\n\n[class=type-link][bookmark=".$attachment->url."]".fromgplus_html2bbcode($attachment->displayName)."[/bookmark]\n";
$post .= "\n[class=type-link][bookmark=".$attachment->url."]".fromgplus_html2bbcode($attachment->displayName)."[/bookmark]\n";
$images = fromgplus_cleanupgoogleproxy($attachment->fullImage, $attachment->image);
//if ($images["preview"] != "")

View file

@ -59,11 +59,11 @@ function gpluspost_settings(&$a,&$s) {
$skip_checked = (($skip_enabled) ? ' checked="checked" ' : '');
$s .= '<span id="settings_gpluspost_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_gpluspost_expanded\'); openClose(\'settings_gpluspost_inflated\');">';
$s .= '<h3>' . t('Google+') . '</h3>';
$s .= '<h3>' . t('Google+ Export') . '</h3>';
$s .= '</span>';
$s .= '<div id="settings_gpluspost_expanded" class="settings-block" style="display: none;">';
$s .= '<span class="fakelink" onclick="openClose(\'settings_gpluspost_expanded\'); openClose(\'settings_gpluspost_inflated\');">';
$s .= '<h3>' . t('Google+') . '</h3>';
$s .= '<h3>' . t('Google+ Export') . '</h3>';
$s .= '</span>';
$s .= '<div id="gpluspost-enable-wrapper">';
@ -214,70 +214,12 @@ function gpluspost_init() {
killme();
}
function gpluspost_original_url($url, $depth=1) {
if ($depth > 10)
return($url);
$siteinfo = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0');
$header = curl_exec($ch);
$curl_info = @curl_getinfo($ch);
$http_code = $curl_info['http_code'];
curl_close($ch);
if ((($curl_info['http_code'] == "301") OR ($curl_info['http_code'] == "302"))
AND (($curl_info['redirect_url'] != "") OR ($curl_info['location'] != ""))) {
if ($curl_info['redirect_url'] != "")
return(gpluspost_original_url($curl_info['redirect_url'], ++$depth));
else
return(gpluspost_original_url($curl_info['location'], ++$depth));
}
$pos = strpos($header, "\r\n\r\n");
if ($pos)
$body = trim(substr($header, $pos));
else
$body = $header;
$doc = new DOMDocument();
@$doc->loadHTML($body);
$xpath = new DomXPath($doc);
$list = $xpath->query("//meta[@content]");
foreach ($list as $node) {
$attr = array();
if ($node->attributes->length)
foreach ($node->attributes as $attribute)
$attr[$attribute->name] = $attribute->value;
if (@$attr["http-equiv"] == 'refresh') {
$path = $attr["content"];
$pathinfo = explode(";", $path);
$content = "";
foreach ($pathinfo AS $value)
if (substr(strtolower($value), 0, 4) == "url=")
return(gpluspost_original_url(substr($value, 4), ++$depth));
}
}
return($url);
}
function gpluspost_feeditem($pid, $uid) {
global $a;
require_once('include/bbcode.php');
require_once("include/html2plain.php");
require_once("include/network.php");
$skipwithoutlink = get_pconfig($uid,'gpluspost','skip_without_link');
@ -365,7 +307,7 @@ function gpluspost_feeditem($pid, $uid) {
$title = trim(str_replace($msglink, "", $title));
$msglink = gpluspost_original_url($msglink);
$msglink = original_url($msglink);
if ($uid == 0)
$title = $item["author-name"].": ".$title;

View file

@ -64,11 +64,11 @@ function libertree_settings(&$a,&$s) {
/* Add some HTML to the existing form */
$s .= '<span id="settings_libertree_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_libertree_expanded\'); openClose(\'settings_libertree_inflated\');">';
$s .= '<h3>' . t('libertree') . '</h3>';
$s .= '<h3>' . t('libertree Export') . '</h3>';
$s .= '</span>';
$s .= '<div id="settings_libertree_expanded" class="settings-block" style="display: none;">';
$s .= '<span class="fakelink" onclick="openClose(\'settings_libertree_expanded\'); openClose(\'settings_libertree_inflated\');">';
$s .= '<h3>' . t('libertree') . '</h3>';
$s .= '<h3>' . t('libertree Export') . '</h3>';
$s .= '</span>';
$s .= '<div id="libertree-enable-wrapper">';

View file

@ -288,11 +288,11 @@ function privacy_image_cache_img_cb($matches) {
// if the picture seems to be from another picture cache then take the original source
$queryvar = privacy_image_cache_parse_query($matches[2]);
if ($queryvar['url'] != "")
if (($queryvar['url'] != "") AND (substr($queryvar['url'], 0, 4) == "http"))
$matches[2] = urldecode($queryvar['url']);
// if fetching facebook pictures don't fetch the thumbnail but the big one
if (strpos($matches[2], ".fbcdn.net/") and (substr($matches[2], -6) == "_s.jpg"))
if (((strpos($matches[2], ".fbcdn.net/") OR strpos($matches[2], "/fbcdn-photos-"))) and (substr($matches[2], -6) == "_s.jpg"))
$matches[2] = substr($matches[2], 0, -6)."_n.jpg";
// following line changed per bug #431

View file

@ -219,11 +219,11 @@ function pumpio_settings(&$a,&$s) {
/* Add some HTML to the existing form */
$s .= '<span id="settings_pumpio_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_pumpio_expanded\'); openClose(\'settings_pumpio_inflated\');">';
$s .= '<h3>' . t('Pump.io') . '</h3>';
$s .= '<h3>' . t('Pump.io Import/Export/Mirror') . '</h3>';
$s .= '</span>';
$s .= '<div id="settings_pumpio_expanded" class="settings-block" style="display: none;">';
$s .= '<span class="fakelink" onclick="openClose(\'settings_pumpio_expanded\'); openClose(\'settings_pumpio_inflated\');">';
$s .= '<h3>' . t('Pump.io') . '</h3>';
$s .= '<h3>' . t('Pump.io Import/Export/Mirror') . '</h3>';
$s .= '</span>';
$s .= '<div id="pumpio-username-wrapper">';

View file

@ -24,6 +24,8 @@
#statusnet-sendtaglinks-label,
#statusnet-shortening-label,
#statusnet-mirror-label,
#statusnet-import-label,
#statusnet-create_user-label,
#statusnet-pin-label,
#statusnet-enable-label {
float: left;

927
statusnet/statusnet.php Executable file → Normal file

File diff suppressed because it is too large Load diff

View file

@ -182,11 +182,11 @@ function tumblr_settings(&$a,&$s) {
/* Add some HTML to the existing form */
$s .= '<span id="settings_tumblr_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_tumblr_expanded\'); openClose(\'settings_tumblr_inflated\');">';
$s .= '<h3>' . t('Tumblr') . '</h3>';
$s .= '<h3>' . t('Tumblr Export') . '</h3>';
$s .= '</span>';
$s .= '<div id="settings_tumblr_expanded" class="settings-block" style="display: none;">';
$s .= '<span class="fakelink" onclick="openClose(\'settings_tumblr_expanded\'); openClose(\'settings_tumblr_inflated\');">';
$s .= '<h3>' . t('Tumblr') . '</h3>';
$s .= '<h3>' . t('Tumblr Export') . '</h3>';
$s .= '</span>';
$s .= '<div id="tumblr-username-wrapper">';

View file

@ -230,12 +230,14 @@ function twitter_settings(&$a,&$s) {
$create_userenabled = get_pconfig(local_user(),'twitter','create_user');
$create_userchecked = (($create_userenabled) ? ' checked="checked" ' : '');
$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 .= '<h3>'. t('Twitter') .'</h3>';
$s .= '<h3>'. t('Twitter Import/Export/Mirror') .'</h3>';
$s .= '</span>';
$s .= '<div id="settings_twitter_expanded" class="settings-block" style="display: none;">';
$s .= '<span class="fakelink" onclick="openClose(\'settings_twitter_expanded\'); openClose(\'settings_twitter_inflated\');">';
$s .= '<h3>'. t('Twitter') .'</h3>';
$s .= '<h3>'. t('Twitter Import/Export/Mirror') .'</h3>';
$s .= '</span>';
if ( (!$ckey) && (!$csecret) ) {
@ -296,13 +298,16 @@ function twitter_settings(&$a,&$s) {
$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><div class="clear"></div>';
$s .= '<div class="clear"></div>';
}
$s .= '</div>';
$s .= '<label id="twitter-import-label" for="twitter-import">'.t('Import the remote timeline').'</label>';
$s .= '<input id="twitter-import" type="checkbox" name="twitter-import" value="1" '. $importchecked . '/>';
@ -1006,7 +1011,6 @@ function twitter_fetchtimeline($a, $uid) {
}
}
//$converted = twitter_convertmsg($a, $_REQUEST['body'], true, $has_picture);
$converted = twitter_expand_entities($a, $_REQUEST['body'], $post->retweeted_status, true, $has_picture);
$_REQUEST['body'] = $converted["body"];
@ -1030,7 +1034,6 @@ function twitter_fetchtimeline($a, $uid) {
}
}
//$converted = twitter_convertmsg($a, $_REQUEST["body"], true, $has_picture);
$converted = twitter_expand_entities($a, $_REQUEST["body"], $post, true, $has_picture);
$_REQUEST['body'] = $converted["body"];
}
@ -1305,6 +1308,7 @@ function twitter_fetchuser($a, $uid, $screen_name = "", $user_id = "") {
function twitter_expand_entities($a, $body, $item, $no_tags = false, $dontincludemedia) {
require_once("include/oembed.php");
require_once("include/network.php");
$tags = "";
@ -1317,7 +1321,7 @@ function twitter_expand_entities($a, $body, $item, $no_tags = false, $dontinclud
foreach ($item->entities->urls AS $url) {
if ($url->url AND $url->expanded_url AND $url->display_url) {
$expanded_url = twitter_original_url($url->expanded_url);
$expanded_url = original_url($url->expanded_url);
$oembed_data = oembed_fetch_url($expanded_url);
@ -1341,7 +1345,6 @@ function twitter_expand_entities($a, $body, $item, $no_tags = false, $dontinclud
$body = str_replace($url->url,
"[url=".$expanded_url."]".$expanded_url."[/url]",
$body);
//"[url=".$expanded_url."]".$url->display_url."[/url]",
else {
$img_str = fetch_url($expanded_url, true, $redirects, 4);
@ -1358,7 +1361,6 @@ function twitter_expand_entities($a, $body, $item, $no_tags = false, $dontinclud
$type = $oembed_data->type;
$footerurl = $expanded_url;
$footerlink = "[url=".$expanded_url."]".$expanded_url."[/url]";
//$footerlink = "[url=".$expanded_url."]".$url->display_url."[/url]";
$body = str_replace($url->url, $footerlink, $body);
}
@ -1367,7 +1369,7 @@ function twitter_expand_entities($a, $body, $item, $no_tags = false, $dontinclud
}
if ($footerurl != "")
$footer = twitter_siteinfo($footerurl, $dontincludemedia);
$footer = add_page_info($footerurl);
if (($footerlink != "") AND (trim($footer) != "")) {
$removedlink = trim(str_replace($footerlink, "", $body));
@ -1375,7 +1377,7 @@ function twitter_expand_entities($a, $body, $item, $no_tags = false, $dontinclud
if (strstr($body, $removedlink))
$body = $removedlink;
$body .= "\n\n[class=type-".$type."]".$footer."[/class]";
$body .= $footer;
}
if ($no_tags)
@ -1546,7 +1548,6 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing
}
}
//$converted = twitter_convertmsg($a, $postarray['body'], false, $has_picture);
$converted = twitter_expand_entities($a, $postarray['body'], $post, false, $has_picture);
$postarray['body'] = $converted["body"];
$postarray['tag'] = $converted["tags"];
@ -1584,7 +1585,6 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing
}
}
//$converted = twitter_convertmsg($a, $postarray['body'], false, $has_picture);
$converted = twitter_expand_entities($a, $postarray['body'], $post->retweeted_status, false, $has_picture);
$postarray['body'] = $converted["body"];
$postarray['tag'] = $converted["tags"];
@ -1839,213 +1839,6 @@ function twitter_fetchhometimeline($a, $uid) {
set_pconfig($uid, 'twitter', 'lastmentionid', $lastid);
}
function twitter_original_url($url, $depth=1, $fetchbody = false) {
if ($depth > 10)
return($url);
$siteinfo = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
if ($fetchbody)
curl_setopt($ch, CURLOPT_NOBODY, 0);
else
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0');
$header = curl_exec($ch);
$curl_info = @curl_getinfo($ch);
$http_code = $curl_info['http_code'];
curl_close($ch);
if ((($curl_info['http_code'] == "301") OR ($curl_info['http_code'] == "302"))
AND (($curl_info['redirect_url'] != "") OR ($curl_info['location'] != ""))) {
if ($curl_info['redirect_url'] != "")
return(twitter_original_url($curl_info['redirect_url'], ++$depth, $fetchbody));
else
return(twitter_original_url($curl_info['location'], ++$depth, $fetchbody));
}
$pos = strpos($header, "\r\n\r\n");
if ($pos)
$body = trim(substr($header, $pos));
else
$body = $header;
if (trim($body) == "")
return(twitter_original_url($url, ++$depth, true));
$doc = new DOMDocument();
@$doc->loadHTML($body);
$xpath = new DomXPath($doc);
$list = $xpath->query("//meta[@content]");
foreach ($list as $node) {
$attr = array();
if ($node->attributes->length)
foreach ($node->attributes as $attribute)
$attr[$attribute->name] = $attribute->value;
if (@$attr["http-equiv"] == 'refresh') {
$path = $attr["content"];
$pathinfo = explode(";", $path);
$content = "";
foreach ($pathinfo AS $value)
if (substr(strtolower($value), 0, 4) == "url=")
return(twitter_original_url(substr($value, 4), ++$depth));
}
}
return($url);
}
function twitter_siteinfo($url, $dontincludemedia) {
require_once("mod/parse_url.php");
// Fetch site infos - but only from the meta data
$data = parseurl_getsiteinfo($url, true);
if ($dontincludemedia)
unset($data["images"]);
if (!is_string($data["text"]) AND (sizeof($data["images"]) == 0) AND ($data["title"] == $url))
return("");
if (is_string($data["title"]))
$text .= "[bookmark=".$url."]".trim($data["title"])."[/bookmark]\n";
// Add a spoiler to the extra information
//if ((sizeof($data["images"]) > 0) OR is_string($data["text"]))
// $text .= "[spoiler]";
if (sizeof($data["images"]) > 0) {
$imagedata = $data["images"][0];
//$text .= '[img='.$imagedata["width"].'x'.$imagedata["height"].']'.$imagedata["src"].'[/img]' . "\n";
$text .= '[img]'.$imagedata["src"].'[/img]'."\n";
}
if (is_string($data["text"]))
$text .= "[quote]".$data["text"]."[/quote]";
//if ((sizeof($data["images"]) > 0) OR is_string($data["text"]))
// $text .= "[/spoiler]";
return($text);
}
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);
$footer = "";
$footerurl = "";
$type = "";
if ($links) {
foreach ($matches AS $match) {
$expanded_url = twitter_original_url($match[2]);
$oembed_data = oembed_fetch_url($expanded_url);
if ($type == "")
$type = $oembed_data->type;
if ($oembed_data->type != "link")
$body = str_replace($match[2], "\n[url]".$expanded_url."[/url]\n", $body);
else {
$img_str = fetch_url($expanded_url, true, $redirects, 4);
$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/") {
$type = "photo";
$body = str_replace($match[2], "[img]".$expanded_url."[/img]", $body);
$dontincludemedia = true;
} else {
$type = $oembed_data->type;
$footerurl = $expanded_url;
$footerlink = "[url=".$expanded_url."]".$expanded_url."[/url]";
$body = str_replace($match[2], $footerlink, $body);
}
}
}
if ($footerurl != "")
$footer = twitter_siteinfo($footerurl, $dontincludemedia);
if (($footerlink != "") AND (trim($footer) != "")) {
$removedlink = trim(str_replace($footerlink, "", $body));
if (strstr($body, $removedlink))
$body = $removedlink;
$body .= "\n\n[class=type-".$type."]".$footer."[/class]";
}
}
if ($no_tags)
return(array("body" => $body, "tags" => ""));
$str_tags = '';
$tags = get_tags($body);
if(count($tags)) {
foreach($tags as $tag) {
if (strstr(trim($tag), " "))
continue;
if(strpos($tag,'#') === 0) {
if(strpos($tag,'[url='))
continue;
// don't link tags that are already embedded in links
if(preg_match('/\[(.*?)' . preg_quote($tag,'/') . '(.*?)\]/',$body))
continue;
if(preg_match('/\[(.*?)\]\((.*?)' . preg_quote($tag,'/') . '(.*?)\)/',$body))
continue;
$basetag = str_replace('_',' ',substr($tag,1));
$body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body);
if(strlen($str_tags))
$str_tags .= ',';
$str_tags .= '#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]';
continue;
} elseif(strpos($tag,'@') === 0) {
$basetag = substr($tag,1);
$body = str_replace($tag,'@[url=https://twitter.com/' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body);
}
}
}
$cnt = preg_match_all('/@\[url=(.*?)\[\/url\]/ism',$body,$matches,PREG_SET_ORDER);
if($cnt) {
foreach($matches as $mtch) {
if(strlen($str_tags))
$str_tags .= ',';
$str_tags .= '@[url=' . $mtch[1] . '[/url]';
}
}
return(array("body"=>$body, "tags"=>$str_tags));
}
function twitter_fetch_own_contact($a, $uid) {
$ckey = get_config('twitter', 'consumerkey');
$csecret = get_config('twitter', 'consumersecret');

View file

@ -73,11 +73,11 @@ function wppost_settings(&$a,&$s) {
/* Add some HTML to the existing form */
$s .= '<span id="settings_wppost_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_wppost_expanded\'); openClose(\'settings_wppost_inflated\');">';
$s .= '<h3>' . t('WordPress') . '</h3>';
$s .= '<h3>' . t('WordPress Export') . '</h3>';
$s .= '</span>';
$s .= '<div id="settings_wppost_expanded" class="settings-block" style="display: none;">';
$s .= '<span class="fakelink" onclick="openClose(\'settings_wppost_expanded\'); openClose(\'settings_wppost_inflated\');">';
$s .= '<h3>' . t('WordPress') . '</h3>';
$s .= '<h3>' . t('WordPress Export') . '</h3>';
$s .= '</span>';
$s .= '<div id="wppost-enable-wrapper">';
$s .= '<label id="wppost-enable-label" for="wppost-checkbox">' . t('Enable WordPress Post Plugin') . '</label>';