aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorPaolo T <tuscanhobbit@users.noreply.github.com>2013-10-25 00:09:42 -0700
committerPaolo T <tuscanhobbit@users.noreply.github.com>2013-10-25 00:09:42 -0700
commitb23f3fc03b6bc751aab67fe2258a21f7c65bab8e (patch)
tree84c997aa781afa566536ca5f66eb8f90ef468476 /include
parentd30f718e0836a031e43d5403480aa049561e736e (diff)
parent0b0bd3c20765d267ec6d7cc261c7713917a22582 (diff)
downloadvolse-hubzilla-b23f3fc03b6bc751aab67fe2258a21f7c65bab8e.tar.gz
volse-hubzilla-b23f3fc03b6bc751aab67fe2258a21f7c65bab8e.tar.bz2
volse-hubzilla-b23f3fc03b6bc751aab67fe2258a21f7c65bab8e.zip
Merge pull request #3 from friendica/master
Align to main project HEAD
Diffstat (limited to 'include')
-rw-r--r--include/ConversationObject.php16
-rw-r--r--include/ItemObject.php3
-rw-r--r--include/api.php8
-rw-r--r--include/auth.php3
-rw-r--r--include/comanche.php17
-rw-r--r--include/conversation.php10
-rw-r--r--include/dir_fns.php28
-rw-r--r--include/directory.php17
-rwxr-xr-xinclude/items.php40
-rw-r--r--include/notifier.php7
-rw-r--r--include/oauth.php9
-rw-r--r--include/onedirsync.php23
-rw-r--r--include/poller.php2
-rwxr-xr-xinclude/text.php168
-rw-r--r--include/zot.php22
15 files changed, 269 insertions, 104 deletions
diff --git a/include/ConversationObject.php b/include/ConversationObject.php
index bb144d893..d8c6bca77 100644
--- a/include/ConversationObject.php
+++ b/include/ConversationObject.php
@@ -22,10 +22,17 @@ class Conversation extends BaseObject {
private $commentable = false;
private $profile_owner = 0;
private $preview = false;
+ private $prepared_item = '';
- public function __construct($mode, $preview) {
+
+ // $prepared_item is for use by alternate conversation structures such as photos
+ // wherein we've already prepared a top level item which doesn't look anything like
+ // a normal "post" item
+
+ public function __construct($mode, $preview, $prepared_item = '') {
$this->set_mode($mode);
$this->preview = $preview;
+ $this->prepared_item = $prepared_item;
}
/**
@@ -180,7 +187,12 @@ class Conversation extends BaseObject {
foreach($this->threads as $item) {
- $item_data = $item->get_template_data($alike, $dlike);
+ if(($item->get_data_value('id') == $item->get_data_value('parent')) && $this->prepared_item) {
+ $item_data = $this->prepared_item;
+ }
+ else {
+ $item_data = $item->get_template_data($alike, $dlike);
+ }
if(!$item_data) {
logger('[ERROR] Conversation::get_template_data : Failed to get item template data ('. $item->get_id() .').', LOGGER_DEBUG);
return false;
diff --git a/include/ItemObject.php b/include/ItemObject.php
index df9386232..59b4538df 100644
--- a/include/ItemObject.php
+++ b/include/ItemObject.php
@@ -201,6 +201,7 @@ class Item extends BaseObject {
'linktitle' => sprintf( t('View %s\'s profile - %s'), $profile_name, $item['author']['xchan_addr']),
'olinktitle' => sprintf( t('View %s\'s profile - %s'), $this->get_owner_name(), $item['owner']['xchan_addr']),
'to' => t('to'),
+ 'via' => t('via'),
'wall' => t('Wall-to-Wall'),
'vwall' => t('via Wall-To-Wall:'),
'profile_url' => $profile_link,
@@ -228,7 +229,7 @@ class Item extends BaseObject {
'like' => $like,
'dislike' => ((feature_enabled($conv->get_profile_owner(),'dislike')) ? $dislike : ''),
'share' => $share,
- 'plink' => get_plink($item),
+ 'plink' => get_plink($item,$mode),
'edpost' => ((feature_enabled($conv->get_profile_owner(),'edit_posts')) ? $edpost : ''),
'star' => ((feature_enabled($conv->get_profile_owner(),'star_posts')) ? $star : ''),
'tagger' => ((feature_enabled($conv->get_profile_owner(),'commtag')) ? $tagger : ''),
diff --git a/include/api.php b/include/api.php
index 2760914e9..1dd970cbc 100644
--- a/include/api.php
+++ b/include/api.php
@@ -72,7 +72,9 @@ require_once('include/photos.php');
// login with oauth
try {
$oauth = new FKOAuth1();
- list($consumer,$token) = $oauth->verify_request(OAuthRequest::from_request());
+ $req = OAuthRequest::from_request();
+ list($consumer,$token) = $oauth->verify_request($req);
+// list($consumer,$token) = $oauth->verify_request(OAuthRequest::from_request());
if (!is_null($token)){
$oauth->loginUser($token->uid);
call_hooks('logged_in', $a->user);
@@ -676,7 +678,6 @@ require_once('include/photos.php');
}
}
-
// call out normal post function
require_once('mod/item.php');
@@ -696,7 +697,7 @@ require_once('include/photos.php');
require_once('include/security.php');
$lastwall = q("SELECT * from item where 1
- and item_private != 0 and item_restrict = 0
+ and item_private = 0 and item_restrict = 0
and author_xchan = '%s'
and allow_cid = '' and allow_gid = '' and deny_cid = '' and deny_gid = ''
and verb = '%s'
@@ -749,6 +750,7 @@ require_once('include/photos.php');
);
$status_info['user'] = $user_info;
}
+
return api_apply_template("status", $type, array('$status' => $status_info));
}
diff --git a/include/auth.php b/include/auth.php
index d04ebbe43..8eb8bf333 100644
--- a/include/auth.php
+++ b/include/auth.php
@@ -61,7 +61,8 @@ if((isset($_SESSION)) && (x($_SESSION,'authenticated')) && ((! (x($_POST,'auth-p
if(((x($_POST,'auth-params')) && ($_POST['auth-params'] === 'logout')) || ($a->module === 'logout')) {
// process logout request
- call_hooks("logging_out");
+ $args = array('channel_id' => local_user());
+ call_hooks('logging_out', $args);
nuke_session();
info( t('Logged out.') . EOL);
goaway(z_root());
diff --git a/include/comanche.php b/include/comanche.php
index f1dd0e521..4c6ea2f54 100644
--- a/include/comanche.php
+++ b/include/comanche.php
@@ -2,6 +2,7 @@
require_once('include/security.php');
require_once('include/menu.php');
+
// When editing a webpage - a dropdown is needed to select a page layout
// On submit, the pdl_select value (which is the mid of an item with item_restrict = ITEM_PDL) is stored in
// the webpage's resource_id, with resource_type 'pdl'.
@@ -126,11 +127,19 @@ function comanche_webpage(&$a,$s) {
// the global app environment, or config storage until we implement argument passing
-function comanche_widget($name,$args = null) {
+function comanche_widget($name,$text) {
$a = get_app();
+ $vars = array();
+ $cnt = preg_match_all("/\[var=(.*?)\](.*?)\[\/var\]/ism", $text, $matches, PREG_SET_ORDER);
+ if($cnt) {
+ foreach($matches as $mtch) {
+ $vars[$mtch[1]] = $mtch[2];
+ }
+ }
+
$func = 'widget_' . trim($name);
if(function_exists($func))
- return $func($args);
+ return $func($vars);
}
@@ -152,10 +161,10 @@ function comanche_region(&$a,$s) {
// need to modify this to accept parameters
- $cnt = preg_match_all("/\[widget\](.*?)\[\/widget\]/ism", $s, $matches, PREG_SET_ORDER);
+ $cnt = preg_match_all("/\[widget=(.*?)\](.*?)\[\/widget\]/ism", $s, $matches, PREG_SET_ORDER);
if($cnt) {
foreach($matches as $mtch) {
- $s = str_replace($mtch[0],comanche_widget(trim($mtch[1])),$s);
+ $s = str_replace($mtch[0],comanche_widget(trim($mtch[1]),$mtch[2]),$s);
}
}
diff --git a/include/conversation.php b/include/conversation.php
index 1820a8568..a8b3150b4 100644
--- a/include/conversation.php
+++ b/include/conversation.php
@@ -397,7 +397,7 @@ function visible_activity($item) {
*/
-function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional') {
+function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $prepared_item = '') {
$tstart = dba_timer();
$t0 = $t1 = $t2 = $t3 = $t4 = $t5 = $t6 = null;
@@ -690,7 +690,7 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional') {
'owner_name' => $owner_name,
'owner_url' => $owner_url,
'owner_photo' => $owner_photo,
- 'plink' => get_plink($item),
+ 'plink' => get_plink($item,$mode),
'edpost' => false,
'isstarred' => $isstarred,
'star' => $star,
@@ -723,7 +723,7 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional') {
require_once('include/ConversationObject.php');
require_once('include/ItemObject.php');
- $conv = new Conversation($mode, $preview);
+ $conv = new Conversation($mode, $preview, $prepared_item);
// In the display mode we don't have a profile owner.
@@ -764,7 +764,7 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional') {
}
- // Can we put this after the visibility check?
+
like_puller($a,$item,$alike,'like');
if(feature_enabled($profile_owner,'dislike'))
@@ -1076,7 +1076,7 @@ function status_editor($a,$x,$popup=false) {
call_hooks('jot_networks', $jotnets);
$o .= replace_macros($tpl,array(
- '$return_path' => $a->query_string,
+ '$return_path' => ((x($x,'return_path')) ? $x['return_path'] : $a->query_string),
'$action' => $a->get_baseurl(true) . '/item',
'$share' => (x($x,'button') ? $x['button'] : t('Share')),
'$webpage' => $webpage,
diff --git a/include/dir_fns.php b/include/dir_fns.php
index 585121434..e234ae0fa 100644
--- a/include/dir_fns.php
+++ b/include/dir_fns.php
@@ -3,9 +3,23 @@
require_once('include/permissions.php');
function find_upstream_directory($dirmode) {
+ $preferred = get_config('system','directory_server');
+ if($preferred)
+ return array('url' => $preferred);
return '';
}
+function dir_sort_links() {
+
+ $o = replace_macros(get_markup_template('dir_sort_links.tpl'), array(
+ '$header' => t('Sort Options'),
+ '$normal' => t('Alphabetic'),
+ '$reverse' => t('Reverse Alphabetic'),
+ '$date' => t('Newest to Oldest')
+ ));
+ return $o;
+}
+
function sync_directories($dirmode) {
@@ -71,7 +85,7 @@ function sync_directories($dirmode) {
if(is_array($t['flags']) && in_array('deleted',$t['flags']))
$ud_flags |= UPDATE_FLAGS_DELETED;
$z = q("insert into updates ( ud_hash, ud_guid, ud_date, ud_flags, ud_addr )
- values ( '%s', '%s', '%s', '%d, '%s' ) ",
+ values ( '%s', '%s', '%s', %d, '%s' ) ",
dbesc($t['hash']),
dbesc($t['transaction_id']),
dbesc($t['timestamp']),
@@ -89,18 +103,22 @@ function update_directory_entry($ud) {
logger('update_directory_entry: ' . print_r($ud,true), LOGGER_DATA);
if($ud['ud_addr'] && (! ($ud['ud_flags'] & UPDATE_FLAGS_DELETED))) {
+ $success = false;
$x = zot_finger($ud['ud_addr'],'');
if($x['success']) {
$j = json_decode($x['body'],true);
+ if($j)
+ $success = true;
$y = import_xchan($j,0);
}
- else {
+ if(! $success) {
$r = q("update updates set ud_last = '%s' where ud_addr = '%s'",
dbesc(datetime_convert()),
dbesc($ud['ud_addr'])
);
}
}
+
}
@@ -111,7 +129,7 @@ function syncdirs($uid) {
logger('syncdirs', LOGGER_DEBUG);
- $p = q("select channel.channel_hash, channel_timezone, profile.* from profile left join channel on channel_id = uid where uid = %d and is_default = 1",
+ $p = q("select channel.channel_hash, channel_address, channel_timezone, profile.* from profile left join channel on channel_id = uid where uid = %d and is_default = 1",
intval($uid)
);
@@ -182,6 +200,8 @@ function syncdirs($uid) {
}
}
- // TODO send refresh zots to downstream directory servers
+ $ud_hash = random_string();
+ update_modtime($ud_hash,$hash,$p[0]['channel_address'] . '@' . get_app()->get_hostname(),1);
+
}
diff --git a/include/directory.php b/include/directory.php
index c0a8928c0..16f819805 100644
--- a/include/directory.php
+++ b/include/directory.php
@@ -49,8 +49,25 @@ function directory_run($argv, $argc){
$packet = zot_build_packet($channel,'refresh');
$z = zot_zot($url,$packet);
+
// re-queue if unsuccessful
+ if(! $z['success']) {
+ $hash = random_string();
+ q("insert into outq ( outq_hash, outq_account, outq_channel, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg )
+ values ( '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%s' )",
+ dbesc($hash),
+ intval($channel['channel_account_id']),
+ intval($channel['channel_id']),
+ dbesc($url),
+ intval(1),
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
+ dbesc($packet),
+ dbesc('')
+ );
+ }
+
// Now update all the connections
proc_run('php','include/notifier.php','refresh_all',$channel['channel_id']);
diff --git a/include/items.php b/include/items.php
index 800684ae2..18aab93fa 100755
--- a/include/items.php
+++ b/include/items.php
@@ -1429,6 +1429,8 @@ function item_store($arr,$allow_exec = false) {
return ret;
}
+ $uplinked_comment = false;
+
// If a page layout is provided, ensure it exists and belongs to us.
if(array_key_exists('layout_mid',$arr) && $arr['layout_mid']) {
@@ -1620,6 +1622,16 @@ function item_store($arr,$allow_exec = false) {
if($r[0]['item_flags'] & ITEM_WALL)
$arr['item_flags'] = $arr['item_flags'] | ITEM_WALL;
+
+ // An uplinked comment might arrive with a downstream owner.
+ // Fix it.
+
+ if($r[0]['owner_xchan'] !== $arr['owner_xchan']) {
+ $arr['owner_xchan'] = $r[0]['owner_xchan'];
+ $uplinked_comment = true;
+ }
+
+
// if the parent is private, force privacy for the entire conversation
// This differs from the above settings as it subtly allows comments from
// email correspondents to be private even if the overall thread is not.
@@ -1805,6 +1817,11 @@ function item_store_update($arr,$allow_exec = false) {
return $ret;
}
+ // override the unseen flag with the original
+
+ if($arr['item_flags'] & ITEM_UNSEEN)
+ $arr['item_flags'] = $arr['item_flags'] ^ ITEM_UNSEEN;
+
if($orig[0]['item_flags'] & ITEM_VERIFIED)
$orig[0]['item_flags'] = $orig[0]['item_flags'] ^ ITEM_VERIFIED;
@@ -1813,6 +1830,7 @@ function item_store_update($arr,$allow_exec = false) {
unset($arr['id']);
unset($arr['uid']);
+
if(array_key_exists('edit',$arr))
unset($arr['edit']);
$arr['mimetype'] = ((x($arr,'mimetype')) ? notags(trim($arr['mimetype'])) : 'text/bbcode');
@@ -1890,7 +1908,7 @@ function item_store_update($arr,$allow_exec = false) {
$arr['edited'] = ((x($arr,'edited') !== false) ? datetime_convert('UTC','UTC',$arr['edited']) : datetime_convert());
$arr['expires'] = ((x($arr,'expires') !== false) ? datetime_convert('UTC','UTC',$arr['expires']) : $orig[0]['expires']);
- $arr['commented'] = datetime_convert();
+ $arr['commented'] = $orig[0]['commented'];
$arr['received'] = datetime_convert();
$arr['changed'] = datetime_convert();
$arr['title'] = ((x($arr,'title')) ? notags(trim($arr['title'])) : '');
@@ -2136,11 +2154,9 @@ function tag_deliver($uid,$item_id) {
intval($uid)
);
-// issue #59
-// FIXME - check security on post and allowed senders, right now we just allow it. The author *may* be foreign and the original owner is lost on our copy of the post. So this could be very hard to verify. For instance what happens if the top-level post was a wall-to-wall?
-// if(($x) && ($x[0]['item_flags'] & ITEM_UPLINK) && ($x[0]['author_xchan'] == $item['author_xchan'])) {
+
if(($x) && ($x[0]['item_flags'] & ITEM_UPLINK)) {
-// logger('tag_deliver: creating second delivery chain for owner comment.');
+
logger('tag_deliver: creating second delivery chain for comment to tagged post.');
// now change this copy of the post to a forum head message and deliver to all the tgroup members
@@ -2150,6 +2166,14 @@ function tag_deliver($uid,$item_id) {
$flag_bits = ITEM_WALL|ITEM_ORIGIN;
+ // maintain the original source, which will be the original item owner and was stored in source_xchan
+ // when we created the delivery fork
+
+ $r = q("update item set source_xchan = '%s' where id = %d limit 1",
+ dbesc($x[0]['source_xchan']),
+ intval($item_id)
+ );
+
$r = q("update item set item_flags = ( item_flags | %d ), owner_xchan = '%s', allow_cid = '%s', allow_gid = '%s',
deny_cid = '%s', deny_gid = '%s', item_private = %d where id = %d limit 1",
intval($flag_bits),
@@ -2249,6 +2273,12 @@ function tag_deliver($uid,$item_id) {
$flag_bits = ITEM_WALL|ITEM_ORIGIN|ITEM_UPLINK;
+ // preserve the source
+
+ $r = q("update item set source_xchan = owner_xchan where id = %d limit 1",
+ intval($item_id)
+ );
+
$r = q("update item set item_flags = ( item_flags | %d ), owner_xchan = '%s', allow_cid = '%s', allow_gid = '%s',
deny_cid = '%s', deny_gid = '%s', item_private = %d where id = %d limit 1",
intval($flag_bits),
diff --git a/include/notifier.php b/include/notifier.php
index 0c7ac5264..1407be4b3 100644
--- a/include/notifier.php
+++ b/include/notifier.php
@@ -325,12 +325,13 @@ function notifier_run($argv, $argc){
// tag_deliver'd post which needs to be sent back to the original author
if(($cmd === 'uplink') && ($parent_item['item_flags'] & ITEM_UPLINK) && (! $top_level_post)) {
- $uplink = true;
+ logger('notifier: uplink');
+ $uplink = true;
}
if(($relay_to_owner || $uplink) && ($cmd !== 'relay')) {
logger('notifier: followup relay', LOGGER_DEBUG);
- $recipients = array(($uplink) ? $parent_item['author_xchan'] : $parent_item['owner_xchan']);
+ $recipients = array(($uplink) ? $parent_item['source_xchan'] : $parent_item['owner_xchan']);
$private = true;
if(! $encoded_item['flags'])
$encoded_item['flags'] = array();
@@ -443,7 +444,7 @@ function notifier_run($argv, $argc){
$n = zot_build_packet($channel,$packet_type);
q("insert into outq ( outq_hash, outq_account, outq_channel, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) values ( '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%s' )",
dbesc($hash),
- intval($channel['channel_account']),
+ intval($channel['channel_account_id']),
intval($channel['channel_id']),
dbesc($hub['hubloc_callback']),
intval(1),
diff --git a/include/oauth.php b/include/oauth.php
index b10802ecd..8eb8a83d8 100644
--- a/include/oauth.php
+++ b/include/oauth.php
@@ -151,15 +151,22 @@ class FKOAuth1 extends OAuthServer {
header('HTTP/1.0 401 Unauthorized');
die('This api requires login');
}
+
$_SESSION['uid'] = $record['channel_id'];
$_SESSION['theme'] = $record['channel_theme'];
$_SESSION['account_id'] = $record['channel_account_id'];
$_SESSION['mobile_theme'] = get_pconfig($record['channel_id'], 'system', 'mobile_theme');
$_SESSION['authenticated'] = 1;
-// $_SESSION['page_flags'] = $record['page-flags'];
$_SESSION['my_url'] = $a->get_baseurl() . '/channel/' . $record['channel_address'];
$_SESSION['addr'] = $_SERVER['REMOTE_ADDR'];
$_SESSION['allow_api'] = true;
+ $x = q("select * from account where account_id = %d limit 1",
+ intval($record['channel_account_id'])
+ );
+ if($x)
+ $a->account = $x[0];
+
+ change_channel($record['channel_id']);
$a->channel = $record;
diff --git a/include/onedirsync.php b/include/onedirsync.php
index b9c17628a..8ae1df5e5 100644
--- a/include/onedirsync.php
+++ b/include/onedirsync.php
@@ -12,7 +12,7 @@ function onedirsync_run($argv, $argc){
cli_startup();
$a = get_app();
- logger('onedirsync: start');
+ logger('onedirsync: start ' . intval($argv[1]));
if(($argc > 1) && (intval($argv[1])))
$update_id = intval($argv[1]);
@@ -28,9 +28,28 @@ function onedirsync_run($argv, $argc){
if(! $r)
return;
- if($r['ud_flags'] & UPDATE_FLAGS_UPDATED)
+ if(($r[0]['ud_flags'] & UPDATE_FLAGS_UPDATED) || (! $r[0]['ud_addr']))
return;
+ // Have we probed this channel more recently than the other directory server
+ // (where we received this update from) ?
+ // If we have, we don't need to do anything except mark any older entries updated
+
+ $x = q("select * from updates where ud_addr = '%s' and ud_date > '%s' and ( ud_flags & %d ) order by ud_date desc limit 1",
+ dbesc($r[0]['ud_addr']),
+ dbesc($r[0]['ud_date']),
+ intval(UPDATE_FLAGS_UPDATED)
+ );
+ if($x) {
+ $y = q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and not ( ud_flags & %d ) and ud_date < '%s' ",
+ intval(UPDATE_FLAGS_UPDATED),
+ dbesc($r[0]['ud_addr']),
+ intval(UPDATE_FLAGS_UPDATED),
+ dbesc($x[0]['ud_date'])
+ );
+ return;
+ }
+
update_directory_entry($r[0]);
return;
diff --git a/include/poller.php b/include/poller.php
index 95eb810a0..94ca99e54 100644
--- a/include/poller.php
+++ b/include/poller.php
@@ -242,7 +242,7 @@ function poller_run($argv, $argc){
}
if($dirmode == DIRECTORY_MODE_SECONDARY || $dirmode == DIRECTORY_MODE_PRIMARY) {
- $r = q("select ud_id from updates where not ( ud_flags & %d ) and ( ud_last = '0000-00-00 00:00:00' OR ud_last > UTC_TIMESTAMP() - INTERVAL 7 DAY ) ",
+ $r = q("select distinct ud_addr, updates.* from updates where not ( ud_flags & %d ) and ud_addr != '' and ( ud_last = '0000-00-00 00:00:00' OR ud_last > UTC_TIMESTAMP() - INTERVAL 7 DAY ) group by ud_addr ",
intval(UPDATE_FLAGS_UPDATED)
);
if($r) {
diff --git a/include/text.php b/include/text.php
index 8f700458c..1ff9d27cb 100755
--- a/include/text.php
+++ b/include/text.php
@@ -364,7 +364,7 @@ function alt_pager(&$a, $i, $more = '', $less = '') {
return replace_macros(get_markup_template('alt_pager.tpl'),array(
'$has_less' => (($a->pager['page'] > 1) ? true : false),
- '$has_more' => (($i > 0 && $i == $a->pager['itemspage']) ? true : false),
+ '$has_more' => (($i > 0 && $i >= $a->pager['itemspage']) ? true : false),
'$less' => $less,
'$more' => $more,
'$url' => $url,
@@ -1015,45 +1015,33 @@ function unobscure(&$item) {
}
-
-function prepare_body(&$item,$attach = false) {
-
- $a = get_app();
-
-
-
- call_hooks('prepare_body_init', $item);
-
- unobscure($item);
-
- $s = prepare_text($item['body'],$item['mimetype']);
-
- $prep_arr = array('item' => $item, 'html' => $s);
- call_hooks('prepare_body', $prep_arr);
- $s = $prep_arr['html'];
-
- if(! $attach) {
- return $s;
- }
-
+function theme_attachments(&$item) {
$arr = json_decode_plus($item['attach']);
- if(count($arr)) {
- $s .= '<div class="body-attach">';
+ if(is_array($arr) && count($arr)) {
+ $attaches = array();
foreach($arr as $r) {
- $matches = false;
$icon = '';
$icontype = substr($r['type'],0,strpos($r['type'],'/'));
+ // FIXME This should probably be a giant "if" statement in the template so that we don't have icon names
+ // embedded in php code
+
switch($icontype) {
case 'video':
+ $icon = 'icon-facetime-video';
+ break;
case 'audio':
+ $icon = 'icon-volume-up';
+ break;
case 'image':
+ $icon = 'icon-picture';
+ break;
case 'text':
- $icon = '<div class="attachtype icon s22 type-' . $icontype . '"></div>';
+ $icon = 'icon-align-justify';
break;
default:
- $icon = '<div class="attachtype icon s22 type-unkn"></div>';
+ $icon = 'icon-question';
break;
}
@@ -1062,61 +1050,102 @@ function prepare_body(&$item,$attach = false) {
$title = t('unknown.???');
$title .= ' ' . $r['length'] . ' ' . t('bytes');
- $url = $a->get_baseurl() . '/magic?f=&hash=' . $item['author_xchan'] . '&dest=' . $r['href'] . '/' . $r['revision'];
+ $url = z_root() . '/magic?f=&hash=' . $item['author_xchan'] . '&dest=' . $r['href'] . '/' . $r['revision'];
$s .= '<a href="' . $url . '" title="' . $title . '" class="attachlink" >' . $icon . '</a>';
+ $attaches[] = array('title' => $title, 'url' => $url, 'icon' => $icon );
+
}
- $s .= '<div class="clear"></div></div>';
+
+
}
-// At some point in time, posttags were removed from the threaded conversation templates, but remained in the search_item template.
-// Code to put them back was added into include/conversation.php and/or include/ItemObject.php but under new class names
-// Then it was discovered that the following bits remained of the old code.
-// Commented out, but we may decide to use this instead of the other version and put all the tag rendering in one place. In the other
-// location it is more theme-able.
-// if(is_array($item['term']) && count($item['term'])) {
-// $tstr = '';
-// foreach($item['term'] as $t) {
-// $t1 = format_term_for_display($t);
-// if($t1) {
-// if($tstr)
-// $tstr .= ' ';
-// $tstr .= $t1;
-// }
-// }
-// if($tstr)
-// $s .= '<br /><div class="posttags">' . $tstr . '</div>';
-// }
+ $s = replace_macros(get_markup_template('item_attach.tpl'), array(
+ '$attaches' => $attaches
+ ));
+
+ return $s;
+
+}
- $writeable = ((get_observer_hash() == $item['owner_xchan']) ? true : false);
- $x = '';
+function format_categories(&$item,$writeable) {
+
+ $s = '';
$terms = get_terms_oftype($item['term'],TERM_CATEGORY);
if($terms) {
+ $categories = array();
foreach($terms as $t) {
- if(strlen($x))
- $x .= ',';
- $x .= htmlspecialchars($t['term'],ENT_COMPAT,'UTF-8')
- . (($writeable) ? ' <a href="' . $a->get_baseurl() . '/filerm/' . $item['id'] . '?f=&cat=' . urlencode($t['term']) . '" title="' . t('remove') . '" >' . t('[remove]') . '</a>' : '');
+ $term = htmlspecialchars($t['term'],ENT_COMPAT,'UTF-8') ;
+ if(! trim($term))
+ continue;
+ $removelink = (($writeable) ? z_root() . '/filerm/' . $item['id'] . '?f=&cat=' . urlencode($t['term']) : '');
+ $categories[] = array('term' => $term, 'writeable' => $writeable, 'removelink' => $removelink, 'url' => $t['url']);
}
- if(strlen($x))
- $s .= '<div class="categorytags"><span>' . t('Categories:') . ' </span>' . $x . '</div>';
+ }
+ $s = replace_macros(get_markup_template('item_categories.tpl'),array(
+ '$remove' => t('remove category'),
+ '$categories' => $categories
+ ));
+ return $s;
+}
- }
+function format_filer(&$item) {
- $x = '';
+ $s = '';
$terms = get_terms_oftype($item['term'],TERM_FILE);
if($terms) {
+ $categories = array();
foreach($terms as $t) {
- if(strlen($x))
- $x .= '&nbsp;&nbsp;&nbsp;';
- $x .= htmlspecialchars($t['term'],ENT_COMPAT,'UTF-8')
- . ' <a href="' . $a->get_baseurl() . '/filerm/' . $item['id'] . '?f=&term=' . urlencode($t['term']) . '" title="' . t('remove') . '" >' . t('[remove]') . '</a>';
+ $term = htmlspecialchars($t['term'],ENT_COMPAT,'UTF-8') ;
+ if(! trim($term))
+ continue;
+ $removelink = z_root() . '/filerm/' . $item['id'] . '?f=&term=' . urlencode($t['term']);
+ $categories[] = array('term' => $term, 'removelink' => $removelink);
}
- if(strlen($x) && (local_user() == $item['uid']))
- $s .= '<div class="filesavetags"><span>' . t('Filed under:') . ' </span>' . $x . '</div>';
+ }
+ $s = replace_macros(get_markup_template('item_filer.tpl'),array(
+ '$remove' => t('remove from file'),
+ '$categories' => $categories
+ ));
+ return $s;
+}
+
+
+
+
+
+function prepare_body(&$item,$attach = false) {
+
+ $a = get_app();
+
+
+
+ call_hooks('prepare_body_init', $item);
+
+ unobscure($item);
+
+ $s = prepare_text($item['body'],$item['mimetype']);
+
+ $prep_arr = array('item' => $item, 'html' => $s);
+ call_hooks('prepare_body', $prep_arr);
+ $s = $prep_arr['html'];
+
+ if(! $attach) {
+ return $s;
}
+
+ $s .= theme_attachments($item);
+
+
+ $writeable = ((get_observer_hash() == $item['owner_xchan']) ? true : false);
+
+ $s .= format_categories($item,$writeable);
+
+ if(local_user() == $item['uid'])
+ $s .= format_filer($item);
+
// Look for spoiler
$spoilersearch = '<blockquote class="spoiler">';
@@ -1308,11 +1337,16 @@ function feed_salmonlinks($nick) {
}
-function get_plink($item) {
- $a = get_app();
- if (x($item,'plink') && ($item['item_private'] != 1)) {
+function get_plink($item,$mode) {
+ $a = get_app();
+ if($mode == 'display')
+ $key = 'plink';
+ else
+ $key = 'llink';
+
+ if (x($item,$key) && ($item['item_private'] != 1)) {
return array(
- 'href' => zid($item['plink']),
+ 'href' => zid($item[$key]),
'title' => t('link to source'),
);
}
diff --git a/include/zot.php b/include/zot.php
index b250557e6..91729f9de 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -604,11 +604,14 @@ function import_xchan($arr,$ud_flags = 1) {
);
if($r) {
logger('import_xchan: hub exists: ' . $location['url']);
- // update connection timestamp
- q("update hubloc set hubloc_connected = '%s' where hubloc_id = %d limit 1",
- dbesc(datetime_convert()),
- intval($r[0]['hubloc_id'])
- );
+ // update connection timestamp if this is the site we're talking to
+ if($location['url'] == $arr['site']['url']) {
+ q("update hubloc set hubloc_connected = '%s', hubloc_updated = '%s' where hubloc_id = %d limit 1",
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
+ intval($r[0]['hubloc_id'])
+ );
+ }
if((($r[0]['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY) && (! $location['primary']))
|| ((! ($r[0]['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY)) && ($location['primary']))) {
$r = q("update hubloc set hubloc_flags = (hubloc_flags ^ %d), hubloc_updated = '%s' where hubloc_id = %d limit 1",
@@ -723,6 +726,14 @@ function import_xchan($arr,$ud_flags = 1) {
update_modtime($xchan_hash,$guid,$arr['address'],$ud_flags);
logger('import_xchan: changed: ' . $what,LOGGER_DEBUG);
}
+ elseif(! $ud_flags) {
+ // nothing changed but we still need to update the updates record
+ q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and not (ud_flags & %d) ",
+ intval(UPDATE_FLAGS_UPDATED),
+ dbesc($arr['address']),
+ intval(UPDATE_FLAGS_UPDATED)
+ );
+ }
if(! x($ret,'message')) {
$ret['success'] = true;
@@ -1568,6 +1579,7 @@ function update_modtime($hash,$guid,$addr,$flags = 0) {
else {
q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and not (ud_flags & %d) ",
intval(UPDATE_FLAGS_UPDATED),
+ dbesc($addr),
intval(UPDATE_FLAGS_UPDATED)
);
}