forked from friendica/friendica-addons
Merge pull request #62 from annando/master
Bugfix in wppost, improvement in libertree export and changes in statusnet and twitter
This commit is contained in:
commit
2dde78cf3a
|
@ -408,6 +408,7 @@ function fb_get_friends($uid, $fullsync = true) {
|
|||
$access_token = get_pconfig($uid,'facebook','access_token');
|
||||
|
||||
$no_linking = get_pconfig($uid,'facebook','no_linking');
|
||||
|
||||
if($no_linking)
|
||||
return;
|
||||
|
||||
|
@ -443,7 +444,7 @@ function facebook_post(&$a) {
|
|||
if($uid){
|
||||
|
||||
|
||||
$fb_limited = get_config('facebook','restrict');
|
||||
$fb_limited = get_config('facebook','crestrict');
|
||||
|
||||
|
||||
$value = ((x($_POST,'post_by_default')) ? intval($_POST['post_by_default']) : 0);
|
||||
|
@ -1015,7 +1016,7 @@ function facebook_post_hook(&$a,&$b) {
|
|||
}
|
||||
|
||||
// At first convert the text to html
|
||||
$html = bbcode($body);
|
||||
$html = bbcode($body, false, false);
|
||||
|
||||
// Then convert it to plain text
|
||||
$msg = trim($b['title']." \n\n".html2plain($html, 0, true));
|
||||
|
@ -1133,7 +1134,7 @@ function facebook_post_hook(&$a,&$b) {
|
|||
// if its only a message and a subject and the message is larger than 500 characters then post it as note
|
||||
$postvars = array(
|
||||
'access_token' => $fb_token,
|
||||
'message' => bbcode($b['body']),
|
||||
'message' => bbcode($b['body'], false, false),
|
||||
'subject' => $b['title'],
|
||||
);
|
||||
$url = 'https://graph.facebook.com/me/notes';
|
||||
|
|
1
fromgplus/README
Normal file
1
fromgplus/README
Normal file
|
@ -0,0 +1 @@
|
|||
This extension is a preparation of the upcoming import of items via Google+
|
183
fromgplus/fromgplus.php
Normal file
183
fromgplus/fromgplus.php
Normal file
|
@ -0,0 +1,183 @@
|
|||
<?php
|
||||
/**
|
||||
* Name: From GPlus
|
||||
* Description: Imports posts from a Google+ account and repeats them - not working by now
|
||||
* Version: 0.1
|
||||
* Author: Michael Vogel <ike@piratenpartei.de>
|
||||
*
|
||||
*/
|
||||
|
||||
function fromgplus_install() {
|
||||
register_hook('plugin_settings', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings');
|
||||
register_hook('plugin_settings_post', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings_post');
|
||||
}
|
||||
|
||||
function fromgplus_uninstall() {
|
||||
unregister_hook('plugin_settings', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings');
|
||||
unregister_hook('plugin_settings_post', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings_post');
|
||||
}
|
||||
|
||||
function fromgplus_addon_settings(&$a,&$s) {
|
||||
|
||||
if(! local_user())
|
||||
return;
|
||||
|
||||
$enable_checked = (intval(get_pconfig(local_user(),'fromgplus','enable')) ? ' checked="checked"' : '');
|
||||
$account = get_pconfig(local_user(),'fromgplus','account');
|
||||
|
||||
$s .= '<div class="settings-block">';
|
||||
$s .= '<h3>' . t('Google+ Import Settings').'</h3>';
|
||||
$s .= '<div id="fromgplus-wrapper">';
|
||||
|
||||
$s .= '<label id="fromgplus-enable-label" for="fromgplus-enable">'.t('Enable Google+ Import').'</label>';
|
||||
$s .= '<input id="fromgplus-enable" type="checkbox" name="fromgplus-enable" value="1"'.$enable_checked.' />';
|
||||
$s .= '<div class="clear"></div>';
|
||||
$s .= '<label id="fromgplus-label" for="fromgplus-account">'.t('Google Account ID').' </label>';
|
||||
$s .= '<input id="fromgplus-account" type="text" name="fromgplus-account" value="'.$account.'" />';
|
||||
$s .= '</div><div class="clear"></div>';
|
||||
|
||||
$s .= '<div class="settings-submit-wrapper" ><input type="submit" id="fromgplus-submit" name="fromgplus-submit"
|
||||
class="settings-submit" value="' . t('Submit') . '" /></div>';
|
||||
$s .= '</div>';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
function fromgplus_addon_settings_post(&$a,&$b) {
|
||||
|
||||
if(! local_user())
|
||||
return;
|
||||
|
||||
if($_POST['fromgplus-submit']) {
|
||||
set_pconfig(local_user(),'fromgplus','account',trim($_POST['fromgplus-account']));
|
||||
$enable = ((x($_POST,'fromgplus-enable')) ? intval($_POST['fromgplus-enable']) : 0);
|
||||
set_pconfig(local_user(),'fromgplus','enable', $enable);
|
||||
info( t('Google+ Import Settings saved.') . EOL);
|
||||
}
|
||||
}
|
||||
/*
|
||||
function html2bbcode($html) {
|
||||
|
||||
$bbcode = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
|
||||
|
||||
$bbcode = str_replace(array("\n"), array(""), $bbcode);
|
||||
$bbcode = str_replace(array("<b>", "</b>"), array("[b]", "[/b]"), $bbcode);
|
||||
$bbcode = str_replace(array("<i>", "</i>"), array("[i]", "[/i]"), $bbcode);
|
||||
$bbcode = str_replace(array("<s>", "</s>"), array("[s]", "[/s]"), $bbcode);
|
||||
$bbcode = str_replace(array("<br />"), array("\n"), $bbcode);
|
||||
|
||||
$bbcode = trim(strip_tags($bbcode));
|
||||
return($bbcode);
|
||||
}
|
||||
|
||||
function friendicapost($post) {
|
||||
global $friendica;
|
||||
|
||||
$api = new Statusnet($friendica["user"], $friendica["pw"], "GooglePlus", $friendica["server"]);
|
||||
$ret = $api->updateStatus($post);
|
||||
$api->endSession();
|
||||
}
|
||||
|
||||
function handleattachments($item) {
|
||||
$post = "";
|
||||
|
||||
foreach ($item->object->attachments as $attachment) {
|
||||
switch($attachment->objectType) {
|
||||
case "video":
|
||||
//$post .= "\n\n[url=".$attachment->url."]".
|
||||
// "[size=large][b]".html2bbcode($attachment->displayName)."[/b][/size][/url]\n";
|
||||
$post .= "\n\n[bookmark=".$attachment->url."]".html2bbcode($attachment->displayName)."[/bookmark]\n";
|
||||
|
||||
//if (strpos($attachment->embed->url, "youtube.com"))
|
||||
// $post .= "[youtube]".$attachment->url."[/youtube]\n";
|
||||
//else
|
||||
/// $post .= "[url=".$attachment->url."][img]".$attachment->image->url."[/img][/url]\n";
|
||||
|
||||
///$post .= "[quote]".trim(html2bbcode($attachment->content))."[/quote]";
|
||||
break;
|
||||
|
||||
case "article":
|
||||
//$post .= "\n\n[url=".$attachment->url."]".
|
||||
// "[size=large][b]".html2bbcode($attachment->displayName)."[/b][/size][/url]\n";
|
||||
$post .= "\n\n[bookmark=".$attachment->url."]".html2bbcode($attachment->displayName)."[/bookmark]\n";
|
||||
$post .= "[quote]".trim(html2bbcode($attachment->content))."[/quote]";
|
||||
break;
|
||||
|
||||
case "photo":
|
||||
//$post .= "\n\n[url=".$attachment->fullImage->url."]".
|
||||
// "[img]".$attachment->fullImage->url."[/img][/url]\n";
|
||||
$post .= "\n\n[img]".$attachment->fullImage->url."[/img]\n";
|
||||
if ($attachment->displayName != "")
|
||||
$post .= html2bbcode($attachment->displayName)."\n";
|
||||
break;
|
||||
|
||||
case "photo-album":
|
||||
$post .= "\n\n[url=".$attachment->url."]".
|
||||
"[size=large][b]".html2bbcode($attachment->displayName)."[/b][/size][/url]\n";
|
||||
break;
|
||||
|
||||
default:
|
||||
print_r($attachment);
|
||||
die();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return($post);
|
||||
}
|
||||
|
||||
$result =
|
||||
file_get_contents("https://www.googleapis.com/plus/v1/people/".$google["id"]."/activities/public?alt=json&pp=1&key=".$google["key"]."&maxResults=".$google["maxfetch"]);
|
||||
$activities = json_decode($result);
|
||||
|
||||
$state = array("lastid"=>'');
|
||||
if (file_exists($statefile))
|
||||
$state = unserialize(file_get_contents($statefile));
|
||||
|
||||
$lastid = "";
|
||||
|
||||
foreach($activities->items as $item) {
|
||||
if ($item->id == $state["lastid"])
|
||||
break;
|
||||
|
||||
if ($lastid == "")
|
||||
$lastid = $item->id;
|
||||
|
||||
switch($item->object->objectType) {
|
||||
case "note":
|
||||
$post = html2bbcode($item->object->content);
|
||||
|
||||
if (is_array($item->object->attachments))
|
||||
$post .= handleattachments($item);
|
||||
friendicapost($post);
|
||||
break;
|
||||
|
||||
case "activity":
|
||||
$post = html2bbcode($item->annotation)."\n";
|
||||
//$post .= html2bbcode("♲ ");
|
||||
$post .= html2bbcode("♻ ");
|
||||
$post .= "[url=".$item->object->actor->url."]".$item->object->actor->displayName."[/url]";
|
||||
$post .= " \n";
|
||||
//$post .= "[quote]";
|
||||
|
||||
$post .= html2bbcode($item->object->content);
|
||||
|
||||
if (is_array($item->object->attachments))
|
||||
$post .= "\n".trim(handleattachments($item));
|
||||
|
||||
//$post .= "[/quote]";
|
||||
|
||||
friendicapost($post);
|
||||
break;
|
||||
|
||||
default:
|
||||
print_r($item);
|
||||
die();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($lastid != "") {
|
||||
$state['lastid'] = $lastid;
|
||||
file_put_contents($statefile, serialize($state));
|
||||
}
|
||||
*/
|
|
@ -169,9 +169,34 @@ function libertree_send(&$a,&$b) {
|
|||
if(count($tag_arr))
|
||||
$tags = implode(',',$tag_arr);
|
||||
|
||||
$title = $b['title'];
|
||||
$body = $b['body'];
|
||||
|
||||
// Insert a newline before and after a quote
|
||||
$body = str_ireplace("[quote", "\n\n[quote", $body);
|
||||
$body = str_ireplace("[/quote]", "[/quote]\n\n", $body);
|
||||
|
||||
// Removal of tags and mentions
|
||||
// #-tags
|
||||
$body = preg_replace('/#\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', '#$2', $body);
|
||||
// @-mentions
|
||||
$body = preg_replace('/@\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', '@$2', $body);
|
||||
|
||||
// remove multiple newlines
|
||||
do {
|
||||
$oldbody = $body;
|
||||
$body = str_replace("\n\n\n", "\n\n", $body);
|
||||
} while ($oldbody != $body);
|
||||
|
||||
// convert to markdown
|
||||
$body = bb2diaspora($body);
|
||||
|
||||
// Adding the title
|
||||
if(strlen($title))
|
||||
$body = "## ".html_entity_decode($title)."\n\n".$body;
|
||||
|
||||
$params = array(
|
||||
'text' => bb2diaspora($b['body'])
|
||||
'text' => $body
|
||||
// 'token' => $ltree_api_token
|
||||
);
|
||||
|
||||
|
|
|
@ -36,13 +36,15 @@ function privacy_image_cache_init() {
|
|||
}
|
||||
|
||||
$urlhash = 'pic:' . sha1($_REQUEST['url']);
|
||||
$r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' LIMIT 1", $urlhash );
|
||||
// Double encoded url - happens with Diaspora
|
||||
$urlhash2 = 'pic:' . sha1(urldecode($_REQUEST['url']));
|
||||
|
||||
$r = q("SELECT * FROM `photo` WHERE `resource-id` in ('%s', '%s') LIMIT 1", $urlhash, $urlhash2);
|
||||
if (count($r)) {
|
||||
$img_str = $r[0]['data'];
|
||||
$mime = $r[0]["desc"];
|
||||
if ($mime == "") $mime = "image/jpeg";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
require_once("Photo.php");
|
||||
|
||||
$img_str = fetch_url($_REQUEST['url'],true);
|
||||
|
|
|
@ -434,7 +434,7 @@ function statusnet_post_hook(&$a,&$b) {
|
|||
// 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 = $b['title'].": \n".$b['body'];
|
||||
// $tmp = substr($tmp, 0, 4*$max_char);
|
||||
} else {
|
||||
$tmp = $b['body']; // substr($b['body'], 0, 3*$max_char);
|
||||
|
@ -457,6 +457,12 @@ function statusnet_post_hook(&$a,&$b) {
|
|||
$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
|
||||
//$recycle = html_entity_decode("♻ ", ENT_QUOTES, 'UTF-8');
|
||||
//$tmp = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', 'RT @$2:', $tmp);
|
||||
}
|
||||
// preserve links to webpages
|
||||
$tmp = preg_replace( '/\[url\=(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)\](\w+.*?)\[\/url\]/i', '$2 $1', $tmp);
|
||||
|
@ -476,7 +482,7 @@ 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) {
|
||||
|
|
|
@ -168,17 +168,56 @@ function tumblr_send(&$a,&$b) {
|
|||
if(count($tag_arr))
|
||||
$tags = implode(',',$tag_arr);
|
||||
|
||||
$link = "";
|
||||
$video = false;
|
||||
$title = trim($b['title']);
|
||||
|
||||
// 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');
|
||||
|
||||
$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);
|
||||
|
||||
// Removing the bookmark
|
||||
$body2 = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",'',$body2);
|
||||
$body = $body1.$body2;
|
||||
|
||||
$video = ((stristr($link,'youtube')) || (stristr($link,'youtu.be')) || (stristr($mtch[1],'vimeo')));
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'email' => $tmbl_username,
|
||||
'password' => $tmbl_password,
|
||||
'title' => $b['title'],
|
||||
'type' => 'regular',
|
||||
'format' => 'html',
|
||||
'generator' => 'Friendica',
|
||||
'tags' => $tags,
|
||||
'body' => bbcode($b['body'])
|
||||
);
|
||||
'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)."</p>";
|
||||
else
|
||||
$params['caption'] = bbcode($body);
|
||||
} else if (($link != '') and !$video) {
|
||||
$params['type'] = "link";
|
||||
$params['name'] = $title;
|
||||
$params['url'] = $link;
|
||||
//$params['description'] = bbcode($body);
|
||||
$params['description'] = bbcode($b["body"]);
|
||||
} else {
|
||||
$params['type'] = "regular";
|
||||
$params['title'] = $title;
|
||||
$params['body'] = bbcode($b['body']);
|
||||
}
|
||||
|
||||
$x = post_url($tmbl_blog,$params);
|
||||
$ret_code = $a->get_curl_code();
|
||||
|
|
|
@ -323,6 +323,12 @@ function twitter_post_hook(&$a,&$b) {
|
|||
$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
|
||||
//$recycle = html_entity_decode("♻ ", ENT_QUOTES, 'UTF-8');
|
||||
//$tmp = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', 'RT @$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);
|
||||
|
@ -341,7 +347,7 @@ function twitter_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) {
|
||||
|
|
|
@ -179,24 +179,26 @@ function wppost_send(&$a,&$b) {
|
|||
require_once('include/bbcode.php');
|
||||
require_once('include/html2plain.php');
|
||||
|
||||
$wptitle = trim($b['title']);
|
||||
|
||||
// If the title is empty then try to guess
|
||||
if ($b['title'] == '') {
|
||||
if ($wptitle == '') {
|
||||
// Take the description from the bookmark
|
||||
if(preg_match("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/is",$b['body'],$matches))
|
||||
$b['title'] = $matches[2];
|
||||
$wptitle = $matches[2];
|
||||
|
||||
// If no bookmark is found then take the first line
|
||||
if ($b['title'] == '') {
|
||||
if ($wptitle == '') {
|
||||
$title = html2plain(bbcode($b['body']), 0, true);
|
||||
$pos = strpos($title, "\n");
|
||||
if (($pos == 0) or ($pos > 60))
|
||||
$pos = 60;
|
||||
|
||||
$b['title'] = substr($title, 0, $pos);
|
||||
$wptitle = substr($title, 0, $pos);
|
||||
}
|
||||
}
|
||||
|
||||
$title = '<title>' . (($b['title']) ? $b['title'] : t('Post from Friendica')) . '</title>';
|
||||
$title = '<title>' . (($wptitle) ? $wptitle : t('Post from Friendica')) . '</title>';
|
||||
$post = $title . bbcode($b['body']);
|
||||
|
||||
$wp_backlink = intval(get_pconfig($b['uid'],'wppost','backlink'));
|
||||
|
|
Loading…
Reference in a new issue