Merge pull request #200 from annando/master
app.net: Support for inline links, new temporary paths functions, privacy_image_cache now with different sizespull/201/head
commit
38a59cad11
|
@ -8,7 +8,10 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
Some marker in the post so that reimported posts can be treated better. (BBCode over app.net?)
|
||||
To-Do:
|
||||
- Use embedded pictures for the attachment information (large attachment)
|
||||
- Sound links must be handled
|
||||
- https://alpha.app.net/sr_rolando/post/32365203 - double pictures
|
||||
*/
|
||||
|
||||
define('APPNET_DEFAULT_POLL_INTERVAL', 5); // given in minutes
|
||||
|
@ -58,11 +61,35 @@ function appnet_content(&$a) {
|
|||
return $o;
|
||||
}
|
||||
|
||||
function appnet_plugin_admin(&$a, &$o){
|
||||
$t = get_markup_template( "admin.tpl", "addon/appnet/" );
|
||||
|
||||
$o = replace_macros($t, array(
|
||||
'$submit' => t('Save Settings'),
|
||||
// name, label, value, help, [extra values]
|
||||
'$clientid' => array('clientid', t('Client ID'), get_config('appnet', 'clientid' ), ''),
|
||||
'$clientsecret' => array('clientsecret', t('Client Secret'), get_config('appnet', 'clientsecret' ), ''),
|
||||
));
|
||||
}
|
||||
|
||||
function appnet_plugin_admin_post(&$a){
|
||||
$clientid = ((x($_POST,'clientid')) ? notags(trim($_POST['clientid'])) : '');
|
||||
$clientsecret = ((x($_POST,'clientsecret')) ? notags(trim($_POST['clientsecret'])): '');
|
||||
set_config('appnet','clientid',$clientid);
|
||||
set_config('appnet','clientsecret',$clientsecret);
|
||||
info( t('Settings updated.'). EOL );
|
||||
}
|
||||
|
||||
function appnet_connect(&$a) {
|
||||
require_once 'addon/appnet/AppDotNet.php';
|
||||
|
||||
$clientId = get_config('appnet','clientid');
|
||||
$clientSecret = get_config('appnet','clientsecret');
|
||||
|
||||
if (($clientId == "") OR ($clientSecret == "")) {
|
||||
$clientId = get_pconfig(local_user(),'appnet','clientid');
|
||||
$clientSecret = get_pconfig(local_user(),'appnet','clientsecret');
|
||||
}
|
||||
|
||||
$app = new AppDotNet($clientId, $clientSecret);
|
||||
|
||||
|
@ -102,8 +129,14 @@ function appnet_settings(&$a,&$s) {
|
|||
return;
|
||||
|
||||
$token = get_pconfig(local_user(),'appnet','token');
|
||||
|
||||
$app_clientId = get_config('appnet','clientid');
|
||||
$app_clientSecret = get_config('appnet','clientsecret');
|
||||
|
||||
if (($app_clientId == "") OR ($app_clientSecret == "")) {
|
||||
$app_clientId = get_pconfig(local_user(),'appnet','clientid');
|
||||
$app_clientSecret = get_pconfig(local_user(),'appnet','clientsecret');
|
||||
}
|
||||
|
||||
/* 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/appnet/appnet.css' . '" media="all" />' . "\r\n";
|
||||
|
@ -122,11 +155,11 @@ function appnet_settings(&$a,&$s) {
|
|||
$ownid = get_pconfig(local_user(),'appnet','ownid');
|
||||
|
||||
$s .= '<span id="settings_appnet_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_appnet_expanded\'); openClose(\'settings_appnet_inflated\');">';
|
||||
$s .= '<img class="connector'.$css.'" src="images/appnet.png" /><h3 class="connector">'. t('App.net Export').'</h3>';
|
||||
$s .= '<img class="connector'.$css.'" src="images/appnet.png" /><h3 class="connector">'. t('App.net Import/Export').'</h3>';
|
||||
$s .= '</span>';
|
||||
$s .= '<div id="settings_appnet_expanded" class="settings-block" style="display: none;">';
|
||||
$s .= '<span class="fakelink" onclick="openClose(\'settings_appnet_expanded\'); openClose(\'settings_appnet_inflated\');">';
|
||||
$s .= '<img class="connector'.$css.'" src="images/appnet.png" /><h3 class="connector">'. t('App.net Export').'</h3>';
|
||||
$s .= '<img class="connector'.$css.'" src="images/appnet.png" /><h3 class="connector">'. t('App.net Import/Export').'</h3>';
|
||||
$s .= '</span>';
|
||||
|
||||
if ($token != "") {
|
||||
|
@ -158,7 +191,6 @@ function appnet_settings(&$a,&$s) {
|
|||
catch (AppDotNetException $e) {
|
||||
$s .= t("<p>Error fetching user profile. Please clear the configuration and try again.</p>");
|
||||
}
|
||||
//$s .= print_r($userdata, true);
|
||||
|
||||
} elseif (($app_clientId == '') OR ($app_clientSecret == '')) {
|
||||
$s .= t("<p>You have two ways to connect to App.net.</p>");
|
||||
|
@ -167,11 +199,11 @@ function appnet_settings(&$a,&$s) {
|
|||
$s .= sprintf(t("Use '%s' as Redirect URI<p>"), $a->get_baseurl().'/appnet/connect');
|
||||
$s .= '<div id="appnet-clientid-wrapper">';
|
||||
$s .= '<label id="appnet-clientid-label" for="appnet-clientid">' . t('Client ID') . '</label>';
|
||||
$s .= '<input id="appnet-clientid" type="text" name="clientid" value="'.$app_clientId.'" />';
|
||||
$s .= '<input id="appnet-clientid" type="text" name="clientid" value="" />';
|
||||
$s .= '</div><div class="clear"></div>';
|
||||
$s .= '<div id="appnet-clientsecret-wrapper">';
|
||||
$s .= '<label id="appnet-clientsecret-label" for="appnet-clientsecret">' . t('Client Secret') . '</label>';
|
||||
$s .= '<input id="appnet-clientsecret" type="text" name="clientsecret" value="'.$app_clientSecret.'" />';
|
||||
$s .= '<input id="appnet-clientsecret" type="text" name="clientsecret" value="" />';
|
||||
$s .= '</div><div class="clear"></div>';
|
||||
$s .= "<hr />";
|
||||
$s .= t('<p>Second way: fetch a token at <a href="http://dev-lite.jonathonduerig.com/">http://dev-lite.jonathonduerig.com/</a>. ');
|
||||
|
@ -256,6 +288,105 @@ function appnet_post_local(&$a,&$b) {
|
|||
}
|
||||
}
|
||||
|
||||
function appnet_create_entities($a, $b, $postdata) {
|
||||
require_once("include/bbcode.php");
|
||||
require_once("include/plaintext.php");
|
||||
|
||||
$bbcode = $b["body"];
|
||||
$bbcode = bb_remove_share_information($bbcode, false, true);
|
||||
|
||||
// Change pure links in text to bbcode uris
|
||||
$bbcode = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1[url=$2]$2[/url]', $bbcode);
|
||||
|
||||
$URLSearchString = "^\[\]";
|
||||
|
||||
$bbcode = preg_replace("/#\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",'#$2',$bbcode);
|
||||
$bbcode = preg_replace("/@\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",'@$2',$bbcode);
|
||||
$bbcode = preg_replace("/\[bookmark\=([$URLSearchString]*)\](.*?)\[\/bookmark\]/ism",'[url=$1]$2[/url]',$bbcode);
|
||||
$bbcode = preg_replace("/\[video\](.*?)\[\/video\]/ism",'[url=$1]$1[/url]',$bbcode);
|
||||
$bbcode = preg_replace("/\[youtube\]https?:\/\/(.*?)\[\/youtube\]/ism",'[url=https://$1]https://$1[/url]',$bbcode);
|
||||
$bbcode = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism",
|
||||
'[url=https://www.youtube.com/watch?v=$1]https://www.youtube.com/watch?v=$1[/url]', $bbcode);
|
||||
$bbcode = preg_replace("/\[vimeo\]https?:\/\/(.*?)\[\/vimeo\]/ism",'[url=https://$1]https://$1[/url]',$bbcode);
|
||||
$bbcode = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism",
|
||||
'[url=https://vimeo.com/$1]https://vimeo.com/$1[/url]', $bbcode);
|
||||
//$bbcode = preg_replace("/\[vimeo\](.*?)\[\/vimeo\]/ism",'[url=$1]$1[/url]',$bbcode);
|
||||
|
||||
$bbcode = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $bbcode);
|
||||
|
||||
|
||||
preg_match_all("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", $bbcode, $urls, PREG_SET_ORDER);
|
||||
|
||||
$bbcode = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",'$1',$bbcode);
|
||||
|
||||
$b["body"] = $bbcode;
|
||||
|
||||
// To-Do:
|
||||
// Bilder
|
||||
// https://alpha.app.net/heluecht/post/32424376
|
||||
// https://alpha.app.net/heluecht/post/32424307
|
||||
|
||||
$plaintext = plaintext($a, $b, 0, false, 6);
|
||||
|
||||
$text = $plaintext["text"];
|
||||
|
||||
$start = 0;
|
||||
$entities = array();
|
||||
|
||||
foreach ($urls AS $url) {
|
||||
$lenurl = iconv_strlen($url[1], "UTF-8");
|
||||
$len = iconv_strlen($url[2], "UTF-8");
|
||||
$pos = iconv_strpos($text, $url[1], $start, "UTF-8");
|
||||
$pre = iconv_substr($text, 0, $pos, "UTF-8");
|
||||
$post = iconv_substr($text, $pos + $lenurl, 1000000, "UTF-8");
|
||||
|
||||
$mid = $url[2];
|
||||
$html = bbcode($mid, false, false, 6);
|
||||
$mid = html2plain($html, 0, true);
|
||||
|
||||
$mid = trim(html_entity_decode($mid,ENT_QUOTES,'UTF-8'));
|
||||
|
||||
$text = $pre.$mid.$post;
|
||||
|
||||
if ($mid != "")
|
||||
$entities[] = array("pos" => $pos, "len" => $len, "url" => $url[1], "text" => $mid);
|
||||
|
||||
$start = $pos + 1;
|
||||
}
|
||||
|
||||
if (isset($postdata["url"]) AND isset($postdata["title"])) {
|
||||
$postdata["title"] = shortenmsg($postdata["title"], 90);
|
||||
$max = 256 - strlen($postdata["title"]);
|
||||
$text = shortenmsg($text, $max);
|
||||
$text .= "\n[".$postdata["title"]."](".$postdata["url"].")";
|
||||
} elseif (isset($postdata["url"])) {
|
||||
$postdata["url"] = short_link($postdata["url"]);
|
||||
$max = 240;
|
||||
$text = shortenmsg($text, $max);
|
||||
$text .= " [".$postdata["url"]."](".$postdata["url"].")";
|
||||
} else {
|
||||
$max = 256;
|
||||
$text = shortenmsg($text, $max);
|
||||
}
|
||||
|
||||
if (iconv_strlen($text, "UTF-8") < $max)
|
||||
$max = iconv_strlen($text, "UTF-8");
|
||||
|
||||
krsort($entities);
|
||||
foreach ($entities AS $entity) {
|
||||
//if (iconv_strlen($text, "UTF-8") >= $entity["pos"] + $entity["len"]) {
|
||||
if (($entity["pos"] + $entity["len"]) <= $max) {
|
||||
$pre = iconv_substr($text, 0, $entity["pos"], "UTF-8");
|
||||
$post = iconv_substr($text, $entity["pos"] + $entity["len"], 1000000, "UTF-8");
|
||||
|
||||
$text = $pre."[".$entity["text"]."](".$entity["url"].")".$post;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return($text);
|
||||
}
|
||||
|
||||
function appnet_send(&$a,&$b) {
|
||||
|
||||
logger('appnet_send: invoked for post '.$b['id']." ".$b['app']);
|
||||
|
@ -340,12 +471,12 @@ function appnet_send(&$a,&$b) {
|
|||
require_once("include/plaintext.php");
|
||||
require_once("include/network.php");
|
||||
|
||||
$post = plaintext($a, $b, 256, false);
|
||||
$post = plaintext($a, $b, 256, false, 6);
|
||||
logger("appnet_send: converted message ".$b["id"]." result: ".print_r($post, true), LOGGER_DEBUG);
|
||||
|
||||
if (isset($post["image"])) {
|
||||
$img_str = fetch_url($post['image'],true, $redirects, 10);
|
||||
$tempfile = tempnam(get_config("system","temppath"), "cache");
|
||||
$tempfile = tempnam(get_temppath(), "cache");
|
||||
file_put_contents($tempfile, $img_str);
|
||||
|
||||
try {
|
||||
|
@ -362,7 +493,7 @@ function appnet_send(&$a,&$b) {
|
|||
);
|
||||
}
|
||||
catch (AppDotNetException $e) {
|
||||
logger("appnet_send: Error creating file");
|
||||
logger("appnet_send: Error creating file ".appnet_error($e->getMessage()));
|
||||
}
|
||||
|
||||
unlink($tempfile);
|
||||
|
@ -376,23 +507,20 @@ function appnet_send(&$a,&$b) {
|
|||
);
|
||||
|
||||
// Adding the original post
|
||||
$attached_data = get_attached_data($b["body"]);
|
||||
$attached_data["post-uri"] = $b["uri"];
|
||||
$attached_data["post-title"] = $b["title"];
|
||||
$attached_data["post-body"] = substr($b["body"], 0, 4000); // To-Do: Better shortening
|
||||
$attached_data["post-tag"] = $b["tag"];
|
||||
$attached_data["author-name"] = $b["author-name"];
|
||||
$attached_data["author-link"] = $b["author-link"];
|
||||
$attached_data["author-avatar"] = $b["author-avatar"];
|
||||
|
||||
$data["annotations"][] = array(
|
||||
"type" => "com.friendica.post",
|
||||
"value" => array(
|
||||
"uri" => $b["uri"],
|
||||
"title" => $b["title"],
|
||||
"body" => substr($b["body"], 0, 4000), // To-Do: Better shortening
|
||||
"tag" => $b["tag"],
|
||||
"author-name" => $b["author-name"],
|
||||
"author-link" => $b["author-link"],
|
||||
"author-avatar" => $b["author-avatar"],
|
||||
)
|
||||
"value" => $attached_data
|
||||
);
|
||||
|
||||
|
||||
// To-Do
|
||||
// Alle Links verkürzen
|
||||
|
||||
if (isset($post["url"]) AND !isset($post["title"])) {
|
||||
$display_url = str_replace(array("http://www.", "https://www."), array("", ""), $post["url"]);
|
||||
$display_url = str_replace(array("http://", "https://"), array("", ""), $display_url);
|
||||
|
@ -403,27 +531,17 @@ function appnet_send(&$a,&$b) {
|
|||
$post["title"] = $display_url;
|
||||
}
|
||||
|
||||
if (isset($post["url"]) AND isset($post["title"])) {
|
||||
$post["title"] = shortenmsg($post["title"], 90);
|
||||
$post["text"] = shortenmsg($post["text"], 256 - strlen($post["title"]));
|
||||
$post["text"] .= "\n[".$post["title"]."](".$post["url"].")";
|
||||
} elseif (isset($post["url"])) {
|
||||
$post["url"] = short_link($post["url"]);
|
||||
$post["text"] = shortenmsg($post["text"], 240);
|
||||
$post["text"] .= " ".$post["url"];
|
||||
}
|
||||
$text = appnet_create_entities($a, $b, $post);
|
||||
|
||||
//print_r($post);
|
||||
$data["entities"]["parse_links"] = true;
|
||||
$data["entities"]["parse_markdown_links"] = true;
|
||||
|
||||
if ($iscomment)
|
||||
$data["reply_to"] = substr($orig_post["uri"], 5);
|
||||
|
||||
try {
|
||||
$ret = $app->createPost($post["text"], $data);
|
||||
logger("appnet_send: sending message ".$b["id"]." ".$text." ".print_r($data, true), LOGGER_DEBUG);
|
||||
$ret = $app->createPost($text, $data);
|
||||
logger("appnet_send: send message ".$b["id"]." result: ".print_r($ret, true), LOGGER_DEBUG);
|
||||
|
||||
if ($iscomment) {
|
||||
logger('appnet_send: Update extid '.$ret["id"]." for post id ".$b['id']);
|
||||
q("UPDATE `item` SET `extid` = '%s' WHERE `id` = %d",
|
||||
|
@ -433,7 +551,7 @@ function appnet_send(&$a,&$b) {
|
|||
}
|
||||
}
|
||||
catch (AppDotNetException $e) {
|
||||
logger("appnet_send: Error sending message ".$b["id"]);
|
||||
logger("appnet_send: Error sending message ".$b["id"]." ".appnet_error($e->getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -465,7 +583,7 @@ function appnet_action($a, $uid, $pid, $action) {
|
|||
logger("appnet_action '".$action."' send, result: " . print_r($result, true), LOGGER_DEBUG);
|
||||
}
|
||||
catch (AppDotNetException $e) {
|
||||
logger("appnet_action: Error sending action ".$action." pid ".$pid, LOGGER_DEBUG);
|
||||
logger("appnet_action: Error sending action ".$action." pid ".$pid." ".appnet_error($e->getMessage()), LOGGER_DEBUG);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -516,7 +634,7 @@ function appnet_is_repost($a, $uid, $body) {
|
|||
return true;
|
||||
}
|
||||
catch (AppDotNetException $e) {
|
||||
logger('appnet_is_repost: error doing repost', LOGGER_DEBUG);
|
||||
logger('appnet_is_repost: error doing repost '.appnet_error($e->getMessage()), LOGGER_DEBUG);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -568,7 +686,7 @@ function appnet_fetchstream($a, $uid) {
|
|||
$stream = $app->getUserStream($param);
|
||||
}
|
||||
catch (AppDotNetException $e) {
|
||||
logger("appnet_fetchstream: Error fetching stream for user ".$uid);
|
||||
logger("appnet_fetchstream: Error fetching stream for user ".$uid." ".appnet_error($e->getMessage()));
|
||||
}
|
||||
|
||||
$stream = array_reverse($stream);
|
||||
|
@ -622,7 +740,7 @@ function appnet_fetchstream($a, $uid) {
|
|||
$mentions = $app->getUserMentions("me", $param);
|
||||
}
|
||||
catch (AppDotNetException $e) {
|
||||
logger("appnet_fetchstream: Error fetching mentions for user ".$uid);
|
||||
logger("appnet_fetchstream: Error fetching mentions for user ".$uid." ".appnet_error($e->getMessage()));
|
||||
}
|
||||
|
||||
$mentions = array_reverse($mentions);
|
||||
|
@ -729,7 +847,7 @@ function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $th
|
|||
$thread = $app->getPostReplies($post["thread_id"], $param);
|
||||
}
|
||||
catch (AppDotNetException $e) {
|
||||
logger("appnet_createpost: Error fetching thread for user ".$uid);
|
||||
logger("appnet_createpost: Error fetching thread for user ".$uid." ".appnet_error($e->getMessage()));
|
||||
}
|
||||
$thread = array_reverse($thread);
|
||||
foreach ($thread AS $tpost) {
|
||||
|
@ -778,9 +896,6 @@ function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $th
|
|||
} else
|
||||
$postarray['body'] = $content["text"];
|
||||
|
||||
if (is_array($content["annotations"]))
|
||||
$postarray['body'] = appnet_expand_annotations($a, $postarray['body'], $content["annotations"]);
|
||||
|
||||
if (sizeof($content["entities"]["links"]))
|
||||
foreach($content["entities"]["links"] AS $link) {
|
||||
$url = normalise_link($link["url"]);
|
||||
|
@ -796,15 +911,16 @@ function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $th
|
|||
unset($links[$url]);
|
||||
}
|
||||
} elseif ($annotation[type] == "com.friendica.post") {
|
||||
$links = array();
|
||||
if (isset($annotation["value"]["embeddable_url"]))
|
||||
$postarray['title'] = $annotation["value"]["title"];
|
||||
// Nur zum Testen deaktiviert
|
||||
//$links = array();
|
||||
//if (isset($annotation["value"]["post-title"]))
|
||||
// $postarray['title'] = $annotation["value"]["post-title"];
|
||||
|
||||
if (isset($annotation["value"]["body"]))
|
||||
$postarray['body'] = $annotation["value"]["body"];
|
||||
//if (isset($annotation["value"]["post-body"]))
|
||||
// $postarray['body'] = $annotation["value"]["post-body"];
|
||||
|
||||
if (isset($annotation["value"]["tag"]))
|
||||
$postarray['tag'] = $annotation["value"]["tag"];
|
||||
//if (isset($annotation["value"]["post-tag"]))
|
||||
// $postarray['tag'] = $annotation["value"]["post-tag"];
|
||||
|
||||
if (isset($annotation["value"]["author-name"]))
|
||||
$postarray['author-name'] = $annotation["value"]["author-name"];
|
||||
|
@ -818,6 +934,17 @@ function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $th
|
|||
|
||||
}
|
||||
|
||||
$page_info = "";
|
||||
|
||||
if (is_array($content["annotations"])) {
|
||||
$photo = appnet_expand_annotations($a, $content["annotations"]);
|
||||
if (($photo["large"] != "") AND ($photo["url"] != ""))
|
||||
$page_info = "\n[url=".$photo["url"]."][img]".$photo["large"]."[/img][/url]";
|
||||
elseif ($photo["url"] != "")
|
||||
$page_info = "\n[img]".$photo["url"]."[/img]";
|
||||
} else
|
||||
$photo = array("url" => "", "large" => "");
|
||||
|
||||
if (sizeof($links)) {
|
||||
$link = array_pop($links);
|
||||
$url = "[url=".$link."]".$link."[/url]";
|
||||
|
@ -827,17 +954,17 @@ function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $th
|
|||
if (($removedlink == "") OR strstr($postarray['body'], $removedlink))
|
||||
$postarray['body'] = $removedlink;
|
||||
|
||||
$postarray['body'] .= add_page_info($link);
|
||||
$page_info = add_page_info($link, false, $photo["url"]);
|
||||
}
|
||||
|
||||
$postarray['body'] .= $page_info;
|
||||
|
||||
$postarray['created'] = datetime_convert('UTC','UTC',$post["created_at"]);
|
||||
$postarray['edited'] = datetime_convert('UTC','UTC',$post["created_at"]);
|
||||
|
||||
$postarray['app'] = $post["source"]["name"];
|
||||
|
||||
return($postarray);
|
||||
//print_r($postarray);
|
||||
//print_r($post);
|
||||
}
|
||||
|
||||
function appnet_expand_entities($a, $body, $entities) {
|
||||
|
@ -866,6 +993,9 @@ function appnet_expand_entities($a, $body, $entities) {
|
|||
|
||||
foreach ($entities["links"] AS $links) {
|
||||
$url = "[url=".$links["url"]."]".$links["text"]."[/url]";
|
||||
if (isset($links["amended_len"]) AND ($links["amended_len"] > $links["len"]))
|
||||
$replace[$links["pos"]] = array("pos"=> $links["pos"], "len"=> $links["amended_len"], "replace"=> $url);
|
||||
else
|
||||
$replace[$links["pos"]] = array("pos"=> $links["pos"], "len"=> $links["len"], "replace"=> $url);
|
||||
}
|
||||
|
||||
|
@ -875,6 +1005,8 @@ function appnet_expand_entities($a, $body, $entities) {
|
|||
foreach ($replace AS $entity) {
|
||||
$pre = substr_unicode($body, 0, $entity["pos"]);
|
||||
$post = substr_unicode($body, $entity["pos"] + $entity["len"]);
|
||||
//$pre = iconv_substr($body, 0, $entity["pos"], "UTF-8");
|
||||
//$post = iconv_substr($body, $entity["pos"] + $entity["len"], "UTF-8");
|
||||
|
||||
$body = $pre.$entity["replace"].$post;
|
||||
}
|
||||
|
@ -883,16 +1015,24 @@ function appnet_expand_entities($a, $body, $entities) {
|
|||
return(array("body" => $body, "tags" => implode($tags_arr, ",")));
|
||||
}
|
||||
|
||||
function appnet_expand_annotations($a, $body, $annotations) {
|
||||
function appnet_expand_annotations($a, $annotations) {
|
||||
$photo = array("url" => "", "large" => "");
|
||||
foreach ($annotations AS $annotation) {
|
||||
if ($annotation["value"]["type"] == "photo") {
|
||||
if (($annotation["value"]["thumbnail_large_url"] != "") AND ($annotation["value"]["url"] != ""))
|
||||
$body .= "\n[url=".$annotation["value"]["url"]."][img]".$annotation["value"]["thumbnail_large_url"]."[/img][/url]";
|
||||
elseif ($annotation["value"]["url"] != "")
|
||||
$body .= "\n[img]".$annotation["value"]["url"]."[/img]";
|
||||
if (($annotation[type] == "net.app.core.oembed") AND
|
||||
($annotation["value"]["type"] == "photo")) {
|
||||
if ($annotation["value"]["url"] != "")
|
||||
$photo["url"] = $annotation["value"]["url"];
|
||||
|
||||
if ($annotation["value"]["thumbnail_large_url"] != "")
|
||||
$photo["large"] = $annotation["value"]["thumbnail_large_url"];
|
||||
|
||||
//if (($annotation["value"]["thumbnail_large_url"] != "") AND ($annotation["value"]["url"] != ""))
|
||||
// $embedded = "\n[url=".$annotation["value"]["url"]."][img]".$annotation["value"]["thumbnail_large_url"]."[/img][/url]";
|
||||
//elseif ($annotation["value"]["url"] != "")
|
||||
// $embedded = "\n[img]".$annotation["value"]["url"]."[/img]";
|
||||
}
|
||||
}
|
||||
return $body;
|
||||
return $photo;
|
||||
}
|
||||
|
||||
function appnet_fetchcontact($a, $uid, $contact, $me, $create_user) {
|
||||
|
@ -975,7 +1115,7 @@ function appnet_fetchcontact($a, $uid, $contact, $me, $create_user) {
|
|||
|
||||
//$update_photo = (($r[0]['avatar-date'] < datetime_convert('','','now -2 days')) ? true : false);
|
||||
$update_photo = ($r[0]['avatar-date'] < datetime_convert('','','now -12 hours'));
|
||||
$update_photo = true;
|
||||
|
||||
// check that we have all the photos, this has been known to fail on occasion
|
||||
|
||||
if((! $r[0]['photo']) || (! $r[0]['thumb']) || (! $r[0]['micro']) || ($update_photo)) {
|
||||
|
@ -1045,3 +1185,23 @@ function appnet_cron($a,$b) {
|
|||
|
||||
set_config('appnet','last_poll', time());
|
||||
}
|
||||
|
||||
function appnet_error($msg) {
|
||||
$msg = trim($msg);
|
||||
$pos = strrpos($msg, "\r\n\r\n");
|
||||
|
||||
if (!$pos)
|
||||
return($msg);
|
||||
|
||||
$msg = substr($msg, $pos + 4);
|
||||
|
||||
$error = json_decode($msg);
|
||||
|
||||
if ($error == NULL)
|
||||
return($msg);
|
||||
|
||||
if (isset($error->meta->error_message))
|
||||
return($error->meta->error_message);
|
||||
else
|
||||
return(print_r($error));
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
{{include file="field_input.tpl" field=$clientid}}
|
||||
{{include file="field_input.tpl" field=$clientsecret}}
|
||||
<div class="submit"><input type="submit" name="page_site" value="{{$submit}}" /></div>
|
|
@ -60,6 +60,13 @@ function buffer_plugin_admin(&$a, &$o){
|
|||
'$client_secret' => array('client_secret', t('Client Secret'), get_config('buffer', 'client_secret' ), ''),
|
||||
));
|
||||
}
|
||||
function buffer_plugin_admin_post(&$a){
|
||||
$client_id = ((x($_POST,'client_id')) ? notags(trim($_POST['client_id'])) : '');
|
||||
$client_secret = ((x($_POST,'client_secret')) ? notags(trim($_POST['client_secret'])): '');
|
||||
set_config('buffer','client_id',$client_id);
|
||||
set_config('buffer','client_secret',$client_secret);
|
||||
info( t('Settings updated.'). EOL );
|
||||
}
|
||||
|
||||
function buffer_connect(&$a) {
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
postToGooglePlus.php
|
|
@ -6,6 +6,7 @@
|
|||
* Version: 1.0
|
||||
* Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
|
||||
* Author: Tony Baldwin <https://free-haven.org/u/tony>
|
||||
* Status: Unsupported
|
||||
*/
|
||||
|
||||
function posterous_install() {
|
||||
|
|
|
@ -61,6 +61,7 @@ function privacy_image_cache_init() {
|
|||
}
|
||||
|
||||
$thumb = false;
|
||||
$size = 1024;
|
||||
|
||||
// If the cache path isn't there, try to create it
|
||||
if (!is_dir($_SERVER["DOCUMENT_ROOT"]."/privacy_image_cache"))
|
||||
|
@ -79,6 +80,20 @@ function privacy_image_cache_init() {
|
|||
else
|
||||
$url = $a->argv[1];
|
||||
|
||||
//$thumb = (isset($a->argv[3]) and ($a->argv[3] == "thumb"));
|
||||
if (isset($a->argv[3]) and ($a->argv[3] == "thumb"))
|
||||
$size = 200;
|
||||
|
||||
// thumb, small, medium and large.
|
||||
if (substr($url, -6) == ":thumb")
|
||||
$size = 150;
|
||||
if (substr($url, -6) == ":small")
|
||||
$size = 340;
|
||||
if (substr($url, -7) == ":medium")
|
||||
$size = 600;
|
||||
if (substr($url, -6) == ":large")
|
||||
$size = 1024;
|
||||
|
||||
$pos = strrpos($url, "=.");
|
||||
if ($pos)
|
||||
$url = substr($url, 0, $pos+1);
|
||||
|
@ -89,7 +104,6 @@ function privacy_image_cache_init() {
|
|||
|
||||
if ($url)
|
||||
$_REQUEST['url'] = $url;
|
||||
$thumb = (isset($a->argv[3]) and ($a->argv[3] == "thumb"));
|
||||
}
|
||||
|
||||
if (!$direct_cache) {
|
||||
|
@ -142,7 +156,7 @@ function privacy_image_cache_init() {
|
|||
$redirects = 0;
|
||||
$img_str = fetch_url($_REQUEST['url'],true, $redirects, 10);
|
||||
|
||||
$tempfile = tempnam(get_config("system","temppath"), "cache");
|
||||
$tempfile = tempnam(get_temppath(), "cache");
|
||||
file_put_contents($tempfile, $img_str);
|
||||
$mime = image_type_to_mime_type(exif_imagetype($tempfile));
|
||||
unlink($tempfile);
|
||||
|
@ -186,10 +200,10 @@ function privacy_image_cache_init() {
|
|||
if (!$direct_cache AND ($cachefile == ""))
|
||||
$img->store(0, 0, $urlhash, $_REQUEST['url'], '', 100);
|
||||
|
||||
if ($thumb) {
|
||||
$img->scaleImage(200); // Test
|
||||
$img_str = $img->imageString();
|
||||
}
|
||||
//if ($thumb) {
|
||||
// $img->scaleImage(200); // Test
|
||||
// $img_str = $img->imageString();
|
||||
//}
|
||||
}
|
||||
//$mime = "image/jpeg";
|
||||
}
|
||||
|
@ -199,7 +213,8 @@ function privacy_image_cache_init() {
|
|||
if ($mime != "image/gif") {
|
||||
$img = new Photo($img_str, $mime);
|
||||
if($img->is_valid()) {
|
||||
$img->scaleImage(1024); // Test
|
||||
//$img->scaleImage(1024); // Test
|
||||
$img->scaleImage($size);
|
||||
$img_str = $img->imageString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -820,7 +820,7 @@ class CodebirdSN
|
|||
}
|
||||
|
||||
// To-Do
|
||||
$tempfile = tempnam(get_config("system","temppath"), "mimecheck");
|
||||
$tempfile = tempnam(get_temppath(), "mimecheck");
|
||||
file_put_contents($tempfile, $data);
|
||||
$mime = image_type_to_mime_type(exif_imagetype($tempfile));
|
||||
unlink($tempfile);
|
||||
|
|
|
@ -570,7 +570,7 @@ function statusnet_post_hook(&$a,&$b) {
|
|||
|
||||
if ($image != "") {
|
||||
$img_str = fetch_url($image);
|
||||
$tempfile = tempnam(get_config("system","temppath"), "cache");
|
||||
$tempfile = tempnam(get_temppath(), "cache");
|
||||
file_put_contents($tempfile, $img_str);
|
||||
$postdata = array("status" => $msg, "media[]" => $tempfile);
|
||||
} else
|
||||
|
@ -1446,7 +1446,7 @@ function statusnet_convertmsg($a, $body, $no_tags = false) {
|
|||
else {
|
||||
$img_str = fetch_url($expanded_url, true, $redirects, 4);
|
||||
|
||||
$tempfile = tempnam(get_config("system","temppath"), "cache");
|
||||
$tempfile = tempnam(get_temppath(), "cache");
|
||||
file_put_contents($tempfile, $img_str);
|
||||
$mime = image_type_to_mime_type(exif_imagetype($tempfile));
|
||||
unlink($tempfile);
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
Define in your .htconfig.php:
|
||||
$a->config['tumblr']['consumer_key'] = "your-consumer-key";
|
||||
$a->config['tumblr']['consumer_secret'] = "your-consumer-secret";
|
||||
|
||||
You can get it here:
|
||||
Register an application at this address:
|
||||
http://www.tumblr.com/oauth/apps
|
||||
|
||||
use (your server name)addon/tumblr/callback.php as callback URL
|
||||
|
||||
Tumblr-OAuth-Library:
|
||||
https://groups.google.com/d/msg/tumblr-api/g6SeIBWvsnE/gnWqT9jFSlEJ
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
{{include file="field_input.tpl" field=$consumer_key}}
|
||||
{{include file="field_input.tpl" field=$consumer_secret}}
|
||||
<div class="submit"><input type="submit" name="page_site" value="{{$submit}}" /></div>
|
|
@ -54,6 +54,25 @@ function tumblr_content(&$a) {
|
|||
return $o;
|
||||
}
|
||||
|
||||
function tumblr_plugin_admin(&$a, &$o){
|
||||
$t = get_markup_template( "admin.tpl", "addon/tumblr/" );
|
||||
|
||||
$o = replace_macros($t, array(
|
||||
'$submit' => t('Save Settings'),
|
||||
// name, label, value, help, [extra values]
|
||||
'$consumer_key' => array('consumer_key', t('Consumer Key'), get_config('tumblr', 'consumer_key' ), ''),
|
||||
'$consumer_secret' => array('consumer_secret', t('Consumer Secret'), get_config('tumblr', 'consumer_secret' ), ''),
|
||||
));
|
||||
}
|
||||
|
||||
function tumblr_plugin_admin_post(&$a){
|
||||
$consumer_key = ((x($_POST,'consumer_key')) ? notags(trim($_POST['consumer_key'])) : '');
|
||||
$consumer_secret = ((x($_POST,'consumer_secret')) ? notags(trim($_POST['consumer_secret'])): '');
|
||||
set_config('tumblr','consumer_key',$consumer_key);
|
||||
set_config('tumblr','consumer_secret',$consumer_secret);
|
||||
info( t('Settings updated.'). EOL );
|
||||
}
|
||||
|
||||
function tumblr_connect($a) {
|
||||
// Start a session. This is necessary to hold on to a few keys the callback script will also need
|
||||
session_start();
|
||||
|
|
|
@ -479,7 +479,7 @@ function twitter_post_hook(&$a,&$b) {
|
|||
if(strlen($msg) and ($image != "")) {
|
||||
$img_str = fetch_url($image);
|
||||
|
||||
$tempfile = tempnam(get_config("system","temppath"), "cache");
|
||||
$tempfile = tempnam(get_temppath(), "cache");
|
||||
file_put_contents($tempfile, $img_str);
|
||||
|
||||
// Twitter had changed something so that the old library doesn't work anymore
|
||||
|
@ -712,19 +712,23 @@ function twitter_fetchtimeline($a, $uid) {
|
|||
|
||||
$_REQUEST['body'] = $post->retweeted_status->text;
|
||||
|
||||
$picture = "";
|
||||
|
||||
// media
|
||||
if (is_array($post->retweeted_status->entities->media)) {
|
||||
foreach($post->retweeted_status->entities->media AS $media) {
|
||||
switch($media->type) {
|
||||
case 'photo':
|
||||
$_REQUEST['body'] = str_replace($media->url, "\n\n[img]".$media->media_url_https."[/img]\n", $_REQUEST['body']);
|
||||
$has_picture = true;
|
||||
//$_REQUEST['body'] = str_replace($media->url, "\n\n[img]".$media->media_url_https."[/img]\n", $_REQUEST['body']);
|
||||
//$has_picture = true;
|
||||
$_REQUEST['body'] = str_replace($media->url, "", $_REQUEST['body']);
|
||||
$picture = $media->media_url_https;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$converted = twitter_expand_entities($a, $_REQUEST['body'], $post->retweeted_status, true, $has_picture);
|
||||
$converted = twitter_expand_entities($a, $_REQUEST['body'], $post->retweeted_status, true, $picture);
|
||||
$_REQUEST['body'] = $converted["body"];
|
||||
|
||||
$_REQUEST['body'] = "[share author='".$post->retweeted_status->user->name.
|
||||
|
@ -736,18 +740,22 @@ function twitter_fetchtimeline($a, $uid) {
|
|||
} else {
|
||||
$_REQUEST["body"] = $post->text;
|
||||
|
||||
$picture = "";
|
||||
|
||||
if (is_array($post->entities->media)) {
|
||||
foreach($post->entities->media AS $media) {
|
||||
switch($media->type) {
|
||||
case 'photo':
|
||||
$_REQUEST['body'] = str_replace($media->url, "\n\n[img]".$media->media_url_https."[/img]\n", $_REQUEST['body']);
|
||||
$has_picture = true;
|
||||
//$_REQUEST['body'] = str_replace($media->url, "\n\n[img]".$media->media_url_https."[/img]\n", $_REQUEST['body']);
|
||||
//$has_picture = true;
|
||||
$_REQUEST['body'] = str_replace($media->url, "", $_REQUEST['body']);
|
||||
$picture = $media->media_url_https;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$converted = twitter_expand_entities($a, $_REQUEST["body"], $post, true, $has_picture);
|
||||
$converted = twitter_expand_entities($a, $_REQUEST["body"], $post, true, $picture);
|
||||
$_REQUEST['body'] = $converted["body"];
|
||||
}
|
||||
|
||||
|
@ -1019,7 +1027,7 @@ function twitter_fetchuser($a, $uid, $screen_name = "", $user_id = "") {
|
|||
return $contact_id;
|
||||
}
|
||||
|
||||
function twitter_expand_entities($a, $body, $item, $no_tags = false, $dontincludemedia) {
|
||||
function twitter_expand_entities($a, $body, $item, $no_tags = false, $picture) {
|
||||
require_once("include/oembed.php");
|
||||
require_once("include/network.php");
|
||||
|
||||
|
@ -1054,11 +1062,12 @@ function twitter_expand_entities($a, $body, $item, $no_tags = false, $dontinclud
|
|||
$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) {
|
||||
//} elseif (($oembed_data->type == "photo") AND isset($oembed_data->url) AND !$dontincludemedia) {
|
||||
} elseif (($oembed_data->type == "photo") AND isset($oembed_data->url)) {
|
||||
$body = str_replace($url->url,
|
||||
"[url=".$expanded_url."][img]".$oembed_data->url."[/img][/url]",
|
||||
$body);
|
||||
$dontincludemedia = true;
|
||||
//$dontincludemedia = true;
|
||||
} elseif ($oembed_data->type != "link")
|
||||
$body = str_replace($url->url,
|
||||
"[url=".$expanded_url."]".$expanded_url."[/url]",
|
||||
|
@ -1066,7 +1075,7 @@ function twitter_expand_entities($a, $body, $item, $no_tags = false, $dontinclud
|
|||
else {
|
||||
$img_str = fetch_url($expanded_url, true, $redirects, 4);
|
||||
|
||||
$tempfile = tempnam(get_config("system","temppath"), "cache");
|
||||
$tempfile = tempnam(get_temppath(), "cache");
|
||||
file_put_contents($tempfile, $img_str);
|
||||
$mime = image_type_to_mime_type(exif_imagetype($tempfile));
|
||||
unlink($tempfile);
|
||||
|
@ -1074,7 +1083,7 @@ function twitter_expand_entities($a, $body, $item, $no_tags = false, $dontinclud
|
|||
if (substr($mime, 0, 6) == "image/") {
|
||||
$type = "photo";
|
||||
$body = str_replace($url->url, "[img]".$expanded_url."[/img]", $body);
|
||||
$dontincludemedia = true;
|
||||
//$dontincludemedia = true;
|
||||
} else {
|
||||
$type = $oembed_data->type;
|
||||
$footerurl = $expanded_url;
|
||||
|
@ -1087,7 +1096,7 @@ function twitter_expand_entities($a, $body, $item, $no_tags = false, $dontinclud
|
|||
}
|
||||
|
||||
if ($footerurl != "")
|
||||
$footer = add_page_info($footerurl);
|
||||
$footer = add_page_info($footerurl, false, $picture);
|
||||
|
||||
if (($footerlink != "") AND (trim($footer) != "")) {
|
||||
$removedlink = trim(str_replace($footerlink, "", $body));
|
||||
|
@ -1098,6 +1107,9 @@ function twitter_expand_entities($a, $body, $item, $no_tags = false, $dontinclud
|
|||
$body .= $footer;
|
||||
}
|
||||
|
||||
if (($footer == "") AND ($picture != ""))
|
||||
$body .= "\n\n[img]".$picture."[/img]\n";
|
||||
|
||||
if ($no_tags)
|
||||
return(array("body" => $body, "tags" => ""));
|
||||
|
||||
|
@ -1252,13 +1264,17 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing
|
|||
|
||||
$postarray['body'] = $post->text;
|
||||
|
||||
$picture = "";
|
||||
|
||||
// media
|
||||
if (is_array($post->entities->media)) {
|
||||
foreach($post->entities->media AS $media) {
|
||||
switch($media->type) {
|
||||
case 'photo':
|
||||
$postarray['body'] = str_replace($media->url, "\n\n[img]".$media->media_url_https."[/img]\n", $postarray['body']);
|
||||
$has_picture = true;
|
||||
//$postarray['body'] = str_replace($media->url, "\n\n[img]".$media->media_url_https."[/img]\n", $postarray['body']);
|
||||
//$has_picture = true;
|
||||
$postarray['body'] = str_replace($media->url, "", $postarray['body']);
|
||||
$picture = $media->media_url_https;
|
||||
break;
|
||||
default:
|
||||
$postarray['body'] .= print_r($media, true);
|
||||
|
@ -1266,7 +1282,7 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing
|
|||
}
|
||||
}
|
||||
|
||||
$converted = twitter_expand_entities($a, $postarray['body'], $post, false, $has_picture);
|
||||
$converted = twitter_expand_entities($a, $postarray['body'], $post, false, $picture);
|
||||
$postarray['body'] = $converted["body"];
|
||||
$postarray['tag'] = $converted["tags"];
|
||||
|
||||
|
@ -1289,13 +1305,17 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing
|
|||
|
||||
$postarray['body'] = $post->retweeted_status->text;
|
||||
|
||||
$picture = "";
|
||||
|
||||
// media
|
||||
if (is_array($post->retweeted_status->entities->media)) {
|
||||
foreach($post->retweeted_status->entities->media AS $media) {
|
||||
switch($media->type) {
|
||||
case 'photo':
|
||||
$postarray['body'] = str_replace($media->url, "\n\n[img]".$media->media_url_https."[/img]\n", $postarray['body']);
|
||||
$has_picture = true;
|
||||
//$postarray['body'] = str_replace($media->url, "\n\n[img]".$media->media_url_https."[/img]\n", $postarray['body']);
|
||||
//$has_picture = true;
|
||||
$postarray['body'] = str_replace($media->url, "", $postarray['body']);
|
||||
$picture = $media->media_url_https;
|
||||
break;
|
||||
default:
|
||||
$postarray['body'] .= print_r($media, true);
|
||||
|
@ -1303,7 +1323,7 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing
|
|||
}
|
||||
}
|
||||
|
||||
$converted = twitter_expand_entities($a, $postarray['body'], $post->retweeted_status, false, $has_picture);
|
||||
$converted = twitter_expand_entities($a, $postarray['body'], $post->retweeted_status, false, $picture);
|
||||
$postarray['body'] = $converted["body"];
|
||||
$postarray['tag'] = $converted["tags"];
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* Description: Expose in user XRD the link to external user's unhosted-enabled storage
|
||||
* Version: 1.0
|
||||
* Author: Fabio Comuni <http://kirgroup.com/profile/fabrixxm>
|
||||
* Status: Unsupported
|
||||
*/
|
||||
|
||||
function uhremotestorage_install() {
|
||||
|
|
Loading…
Reference in New Issue