OStatus: Attachment links are now added as enclosures

This commit is contained in:
Michael Vogel 2015-06-06 13:15:37 +02:00
parent e6e7562986
commit f34135f34d
3 changed files with 41 additions and 11 deletions

View File

@ -13,9 +13,9 @@ function bb_map_location($match) {
return str_replace($match[0],'<div class="map" >' . generate_named_map($match[1]) . '</div>', $match[0]);
}
function bb_attachment($Text, $plaintext = false, $tryoembed = true) {
function bb_attachment($Text, $simplehtml = false, $tryoembed = true) {
$Text = preg_replace_callback("/(.*?)\[attachment(.*?)\](.*?)\[\/attachment\]/ism",
function ($match) use ($plaintext, $tryoembed){
function ($match) use ($simplehtml, $tryoembed){
$attributes = $match[2];
@ -83,7 +83,10 @@ function bb_attachment($Text, $plaintext = false, $tryoembed = true) {
$image = "";
}
if ($plaintext)
if ($simplehtml == 7)
$text = sprintf('<a href="%s" title="%s" class="attachment thumbnail" rel="nofollow external">%s</a>',
$url, $title, $title);
elseif (($simplehtml != 4) AND ($simplehtml != 0))
$text = sprintf('<a href="%s" target="_blank">%s</a><br>', $url, $title);
else {
$text = sprintf('<span class="type-%s">', $type);
@ -871,7 +874,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
}
// Handle attached links or videos
$Text = bb_attachment($Text, ($simplehtml != 4) AND ($simplehtml != 0), $tryoembed);
$Text = bb_attachment($Text, $simplehtml, $tryoembed);
$Text = str_replace(array("\r","\n"), array('<br />','<br />'), $Text);

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('include/plaintext.php');
require_once('mod/share.php');
function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0, $forpubsub = false) {
@ -4344,7 +4345,8 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) {
if ($item['title'] != "")
$htmlbody = "[b]".$item['title']."[/b]\n\n".$htmlbody;
$htmlbody = bbcode(bb_remove_share_information($htmlbody), false, false, 7);
//$htmlbody = bbcode(bb_remove_share_information($htmlbody), false, false, 7);
$htmlbody = bbcode($htmlbody, false, false, 7);
$o .= '<id>' . xmlify($item['uri']) . '</id>' . "\r\n";
$o .= '<title>' . xmlify($item['title']) . '</title>' . "\r\n";
@ -4401,6 +4403,8 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) {
}
}
$o .= item_get_attachment($item);
$o .= item_getfeedattach($item);
$mentioned = get_mentions($item);
@ -4578,6 +4582,28 @@ function item_getfeedtags($item) {
return $ret;
}
function item_get_attachment($item) {
$o = "";
$siteinfo = get_attached_data($item["body"]);
switch($siteinfo["type"]) {
case 'link':
$o = '<link rel="enclosure" href="'.xmlify($siteinfo["url"]).'" type="text/html; charset=UTF-8" length="" title="'.xmlify($siteinfo["title"]).'"/>'."\r\n";
break;
case 'photo':
$imgdata = get_photo_info($siteinfo["image"]);
$o = '<link rel="enclosure" href="'.xmlify($siteinfo["image"]).'" type="'.$imgdata["mime"].'" length="'.$imgdata["size"].'"/>'."\r\n";
break;
case 'video':
$o = '<link rel="enclosure" href="'.xmlify($siteinfo["url"]).'" type="text/html; charset=UTF-8" length="" title="'.xmlify($siteinfo["title"]).'"/>'."\r\n";
break;
default:
break;
}
return $o;
}
function item_getfeedattach($item) {
$ret = '';
$arr = explode('[/attach],',$item['attach']);
@ -4951,7 +4977,7 @@ function list_post_dates($uid, $wall) {
return array();
// Set the start and end date to the beginning of the month
$dnow = substr($dnow,0,8).'01';
$dnow = substr($dnow,0,8).'01';
$dthen = substr($dthen,0,8).'01';
$ret = array();
@ -4967,7 +4993,7 @@ function list_post_dates($uid, $wall) {
$str = day_translate(datetime_convert('','',$dnow,'F'));
if(! $ret[$dyear])
$ret[$dyear] = array();
$ret[$dyear][] = array($str,$end_month,$start_month);
$ret[$dyear][] = array($str,$end_month,$start_month);
$dnow = datetime_convert('','',$dnow . ' -1 month', 'Y-m-d');
}
return $ret;
@ -5015,12 +5041,12 @@ function posted_date_widget($url,$uid,$wall) {
if(! $visible_years)
$visible_years = 5;
$ret = list_post_dates($uid,$wall);
$ret = list_post_dates($uid,$wall);
if(! count($ret))
return $o;
$cutoff_year = intval(datetime_convert('',date_default_timezone_get(),'now','Y')) - $visible_years;
$cutoff_year = intval(datetime_convert('',date_default_timezone_get(),'now','Y')) - $visible_years;
$cutoff = ((array_key_exists($cutoff_year,$ret))? true : false);
$o = replace_macros(get_markup_template('posted_date_widget.tpl'),array(
@ -5030,7 +5056,7 @@ function posted_date_widget($url,$uid,$wall) {
'$cutoff' => $cutoff,
'$url' => $url,
'$dates' => $ret,
'$showmore' => t('show more')
'$showmore' => t('show more')
));
return $o;

View File

@ -53,8 +53,9 @@ function check_conversations($override = false) {
logger('cron_start');
$start = date("Y-m-d H:i:s", time() - ($poll_timeframe * 60));
$conversations = q("SELECT * FROM `term` WHERE `type` = 7 AND `term` > '%s'",
$conversations = q("SELECT `oid`, `url` FROM `term` WHERE `type` = 7 AND `term` > '%s' GROUP BY `url` ORDER BY `term` DESC",
dbesc($start));
foreach ($conversations AS $conversation) {
$id = $conversation['oid'];
$url = $conversation['url'];