New function for building the "share" header

This commit is contained in:
Michael Vogel 2015-04-05 20:43:06 +02:00
parent a4afebb796
commit 57528cb987
4 changed files with 31 additions and 26 deletions

View File

@ -7,6 +7,7 @@
require_once("include/conversation.php");
require_once("include/oauth.php");
require_once("include/html2plain.php");
require_once("mod/share.php");
/*
* Twitter-Like API
*
@ -1389,10 +1390,8 @@
$pos = strpos($r[0]['body'], "[share");
$post = substr($r[0]['body'], $pos);
} else {
$post = "[share author='".str_replace("'", "'", $r[0]['author-name']).
"' profile='".$r[0]['author-link'].
"' avatar='".$r[0]['author-avatar'].
"' link='".$r[0]['plink']."']";
$post = share_header($r[0]['author-name'], $r[0]['author-link'], $r[0]['author-avatar'], $r[0]['guid'], $r[0]['created'], $r[0]['plink']);
$post .= $r[0]['body'];
$post .= "[/share]";
}

View File

@ -7,6 +7,7 @@ require_once('include/contact_selectors.php');
require_once('include/queue_fn.php');
require_once('include/lock.php');
require_once('include/threads.php');
require_once('mod/share.php');
function diaspora_dispatch_public($msg) {
@ -1165,12 +1166,8 @@ function diaspora_reshare($importer,$xml,$msg) {
$datarray['owner-link'] = $contact['url'];
$datarray['owner-avatar'] = ((x($contact,'thumb')) ? $contact['thumb'] : $contact['photo']);
if (!intval(get_config('system','wall-to-wall_share'))) {
$prefix = "[share author='".str_replace(array("'", "[", "]"), array("'", "[", "]"),$person['name']).
"' profile='".$person['url'].
"' avatar='".((x($person,'thumb')) ? $person['thumb'] : $person['photo']).
"' guid='".$orig_guid.
"' posted='".$orig_created.
"' link='".str_replace(array("'", "[", "]"), array("'", "[", "]"),$orig_url)."']";
$prefix = share_header($person['name'], $person['url'], ((x($person,'thumb')) ? $person['thumb'] : $person['photo']), $orig_guid, $orig_created, $orig_url);
$datarray['author-name'] = $contact['name'];
$datarray['author-link'] = $contact['url'];
$datarray['author-avatar'] = $contact['thumb'];
@ -1199,7 +1196,7 @@ function diaspora_reshare($importer,$xml,$msg) {
$datarray2['contact-id'] = get_contact($person['url'], 0);
$datarray2['guid'] = $orig_guid;
$datarray2['uri'] = $datarray2['parent-uri'] = $orig_author.':'.$orig_guid;
$datarray2['changed'] = $datarray2['created'] = $datarray2['edited'] = datetime_convert('UTC','UTC',$orig_created);
$datarray2['changed'] = $datarray2['created'] = $datarray2['edited'] = $datarray2['commented'] = $datarray2['received'] = datetime_convert('UTC','UTC',$orig_created);
$datarray2['plink'] = 'https://'.substr($orig_author,strpos($orig_author,'@')+1).'/posts/'.$orig_guid;
$datarray2['author-name'] = $person['name'];

View File

@ -12,6 +12,7 @@ require_once('include/email.php');
require_once('include/ostatus_conversation.php');
require_once('include/threads.php');
require_once('include/socgraph.php');
require_once('mod/share.php');
function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) {
@ -838,10 +839,8 @@ function get_atom_elements($feed, $item, $contact = array()) {
logger('get_atom_elements: fixing sender of repeated message.');
if (!intval(get_config('system','wall-to-wall_share'))) {
$prefix = "[share author='".str_replace("'", "'",$name).
"' profile='".$uri.
"' avatar='".$avatar.
"' link='".$orig_uri."']";
logger("Repeated data: ".print_r($child["http://activitystrea.ms/spec/1.0/"]["object"][0]["child"][SIMPLEPIE_NAMESPACE_ATOM_10], true), LOGGER_DEBUG);
$prefix = share_header($name, $uri, $avatar, "", "", $orig_uri);
$res["body"] = $prefix.html2bbcode($message)."[/share]";
} else {
@ -1183,9 +1182,9 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
$arr['owner-avatar'] = ((x($arr,'owner-avatar')) ? notags(trim($arr['owner-avatar'])) : '');
$arr['created'] = ((x($arr,'created') !== false) ? datetime_convert('UTC','UTC',$arr['created']) : datetime_convert());
$arr['edited'] = ((x($arr,'edited') !== false) ? datetime_convert('UTC','UTC',$arr['edited']) : datetime_convert());
$arr['commented'] = datetime_convert();
$arr['received'] = datetime_convert();
$arr['changed'] = datetime_convert();
$arr['commented'] = ((x($arr,'commented') !== false) ? datetime_convert('UTC','UTC',$arr['commented']) : datetime_convert());
$arr['received'] = ((x($arr,'received') !== false) ? datetime_convert('UTC','UTC',$arr['received']) : datetime_convert());
$arr['changed'] = ((x($arr,'changed') !== false) ? datetime_convert('UTC','UTC',$arr['changed']) : datetime_convert());
$arr['title'] = ((x($arr,'title')) ? notags(trim($arr['title'])) : '');
$arr['location'] = ((x($arr,'location')) ? notags(trim($arr['location'])) : '');
$arr['coord'] = ((x($arr,'coord')) ? notags(trim($arr['coord'])) : '');

View File

@ -1,7 +1,4 @@
<?php
require_once('include/bbcode.php');
function share_init(&$a) {
$post_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
@ -23,11 +20,8 @@ function share_init(&$a) {
$pos = strpos($r[0]['body'], "[share");
$o = substr($r[0]['body'], $pos);
} else {
$o = "[share author='".str_replace("'", "&#039;",$r[0]['author-name']).
"' profile='".$r[0]['author-link'].
"' avatar='".$r[0]['author-avatar'].
"' link='".$r[0]['plink'].
"' posted='".$r[0]['created']."']\n";
$o = share_header($r[0]['author-name'], $r[0]['author-link'], $r[0]['author-avatar'], $r[0]['guid'], $r[0]['created'], $r[0]['plink']);
if($r[0]['title'])
$o .= '[b]'.$r[0]['title'].'[/b]'."\n";
$o .= $r[0]['body'];
@ -46,3 +40,19 @@ function share_init(&$a) {
echo $o;
killme();
}
function share_header($author, $profile, $avatar, $guid, $posted, $link) {
$header = "[share author='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$author).
"' profile='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$profile).
"' avatar='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$avatar);
if ($guid)
$header .= "' guid='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$guid);
if ($posted)
$header .= "' posted='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$posted);
$header .= "' link='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$link)."']";
return $header;
}