aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorTobias Diekershoff <tobias.diekershoff@gmx.net>2011-10-05 20:59:21 +0200
committerTobias Diekershoff <tobias.diekershoff@gmx.net>2011-10-05 20:59:21 +0200
commit90870d4872dbc8ff408183a79fd005b905aa86c2 (patch)
treecdd66eea79a7638b520576d381d08368b05a19c1 /include
parente88a8564c849b199ca552fa307f385b422d5d00a (diff)
parent5cb0b0ed4591a578720e0c985974db2d95f3810a (diff)
downloadvolse-hubzilla-90870d4872dbc8ff408183a79fd005b905aa86c2.tar.gz
volse-hubzilla-90870d4872dbc8ff408183a79fd005b905aa86c2.tar.bz2
volse-hubzilla-90870d4872dbc8ff408183a79fd005b905aa86c2.zip
Merge branch 'master' of git://github.com/friendika/Free-Friendika
Diffstat (limited to 'include')
-rw-r--r--include/conversation.php29
-rw-r--r--include/delivery.php12
-rw-r--r--include/items.php81
-rw-r--r--include/notifier.php16
-rw-r--r--include/poller.php17
-rw-r--r--include/text.php6
6 files changed, 123 insertions, 38 deletions
diff --git a/include/conversation.php b/include/conversation.php
index ebe582f4c..10b34ebe6 100644
--- a/include/conversation.php
+++ b/include/conversation.php
@@ -142,8 +142,8 @@ function conversation(&$a, $items, $mode, $update) {
// array with html for each thread (parent+comments)
- $treads = array();
- $treadsid = -1;
+ $threads = array();
+ $threadsid = -1;
if(count($items)) {
@@ -155,7 +155,7 @@ function conversation(&$a, $items, $mode, $update) {
$tpl = get_markup_template('search_item.tpl');
foreach($items as $item) {
- $treadsid++;
+ $threadsid++;
$comment = '';
$owner_url = '';
@@ -220,7 +220,7 @@ function conversation(&$a, $items, $mode, $update) {
$body = prepare_body($item,true);
- $treads[$treadsid] .= replace_macros($tpl,array(
+ $tmp_item = replace_macros($tpl,array(
'$id' => $item['item_id'],
'$linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
'$profile_url' => $profile_link,
@@ -251,6 +251,11 @@ function conversation(&$a, $items, $mode, $update) {
'$wait' => t('Please wait'),
));
+ $arr = array('item' => $item, 'output' => $tmp_item);
+ call_hooks('display_item', $arr);
+
+ $threads[$threadsid] .= $arr['output'];
+
}
}
@@ -331,8 +336,8 @@ function conversation(&$a, $items, $mode, $update) {
$comments_seen = 0;
$comments_collapsed = false;
- $treadsid++;
- $treads[$treadsid] = "";
+ $threadsid++;
+ $threads[$threadsid] = "";
}
else {
// prevent private email from leaking into public conversation
@@ -346,7 +351,7 @@ function conversation(&$a, $items, $mode, $update) {
if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
if(! $comments_collapsed) {
- $treads[$treadsid] .= '<div class="ccollapse-wrapper fakelink" id="ccollapse-wrapper-' . $item['parent']
+ $threads[$threadsid] .= '<div class="ccollapse-wrapper fakelink" id="ccollapse-wrapper-' . $item['parent']
. '" onclick="openClose(' . '\'ccollapse-' . $item['parent'] . '\'); $(\'#ccollapse-wrapper-' . $item['parent'] . '\').hide();" >'
. sprintf( t('See all %d comments'), $comments[$item['parent']]) . '</div>'
. '<div class="ccollapse" id="ccollapse-' . $item['parent'] . '" style="display: none;" >';
@@ -354,7 +359,7 @@ function conversation(&$a, $items, $mode, $update) {
}
}
if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
- $treads[$treadsid] .= '</div>';
+ $threads[$threadsid] .= '</div>';
}
$redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
@@ -450,7 +455,7 @@ function conversation(&$a, $items, $mode, $update) {
);
$star = false;
- $starred = "unstarred";
+ $isstarred = "unstarred";
if ($profile_owner == local_user() && $toplevelpost) {
$isstarred = (($item['starred']) ? "starred" : "unstarred");
@@ -559,7 +564,7 @@ function conversation(&$a, $items, $mode, $update) {
$arr = array('item' => $item, 'output' => $tmp_item);
call_hooks('display_item', $arr);
- $treads[$treadsid] .= $arr['output'];
+ $threads[$threadsid] .= $arr['output'];
}
}
}
@@ -568,11 +573,11 @@ function conversation(&$a, $items, $mode, $update) {
// if author collapsing is in force but didn't get closed, close it off now.
/*if($blowhard_count >= 3)
- $treads[$treadsid] .= '</div>';*/
+ $threads[$threadsid] .= '</div>';*/
$page_template = get_markup_template("conversation.tpl");
$o .= replace_macros($page_template, array(
- '$treads' => $treads,
+ '$threads' => $threads,
'$dropping' => ($dropping?t('Delete Selected Items'):False),
));
diff --git a/include/delivery.php b/include/delivery.php
index 06cc1f679..1ba1d9c3a 100644
--- a/include/delivery.php
+++ b/include/delivery.php
@@ -72,7 +72,7 @@ function delivery_run($argv, $argc){
$normal_mode = false;
$expire = true;
$items = q("SELECT * FROM `item` WHERE `uid` = %d AND `wall` = 1
- AND `deleted` = 1 AND `changed` > UTC_TIMESTAMP - INTERVAL 30 MINUTE",
+ AND `deleted` = 1 AND `changed` > UTC_TIMESTAMP() - INTERVAL 30 MINUTE",
intval($item_id)
);
$uid = $item_id;
@@ -96,6 +96,8 @@ function delivery_run($argv, $argc){
$uid = $r[0]['uid'];
$updated = $r[0]['edited'];
+ if(! $parent_id)
+ return;
$items = q("SELECT `item`.*, `sign`.`signed_text`,`sign`.`signature`,`sign`.`signer`
@@ -121,7 +123,6 @@ function delivery_run($argv, $argc){
if( ! ($icontacts && count($icontacts)))
return;
-
// avoid race condition with deleting entries
if($items[0]['deleted']) {
@@ -267,7 +268,12 @@ function delivery_run($argv, $argc){
if(! $item_contact)
continue;
- $atom .= atom_entry($item,'text',$item_contact,$owner,true);
+ if($normal_mode) {
+ if($item_id == $item['id'] || $item['id'] == $item['parent'])
+ $atom .= atom_entry($item,'text',$item_contact,$owner,true);
+ }
+ else
+ $atom .= atom_entry($item,'text',$item_contact,$owner,true);
}
diff --git a/include/items.php b/include/items.php
index a1baf7471..93a730d22 100644
--- a/include/items.php
+++ b/include/items.php
@@ -807,6 +807,14 @@ function item_store($arr,$force_parent = false) {
}
}
+ $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+ dbesc($arr['uri']),
+ dbesc($arr['uid'])
+ );
+ if($r && count($r)) {
+ logger('item-store: duplicate item ignored. ' . print_r($arr,true));
+ return 0;
+ }
call_hooks('post_remote',$arr);
@@ -1070,10 +1078,21 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
* have a contact record.
* $hub = should we find a hub declation in the feed, pass it back to our calling process, who might (or
* might not) try and subscribe to it.
+ * $datedir sorts in reverse order
+ * $pass - by default ($pass = 0) we cannot guarantee that a parent item has been
+ * imported prior to its children being seen in the stream unless we are certain
+ * of how the feed is arranged/ordered.
+ * With $pass = 1, we only pull parent items out of the stream.
+ * With $pass = 2, we only pull children (comments/likes).
*
+ * So running this twice, first with pass 1 and then with pass 2 will do the right
+ * thing regardless of feed ordering. This won't be adequate in a fully-threaded
+ * model where comments can have sub-threads. That would require some massive sorting
+ * to get all the feed items into a mostly linear ordering, and might still require
+ * recursion.
*/
-function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $secure_feed = false) {
+function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) {
require_once('library/simplepie/simplepie.inc');
@@ -1241,7 +1260,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $secure_fee
// process any deleted entries
$del_entries = $feed->get_feed_tags(NAMESPACE_TOMB, 'deleted-entry');
- if(is_array($del_entries) && count($del_entries)) {
+ if(is_array($del_entries) && count($del_entries) && $pass != 2) {
foreach($del_entries as $dentry) {
$deleted = false;
if(isset($dentry['attribs']['']['ref'])) {
@@ -1333,7 +1352,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $secure_fee
$parent_uri = $rawthread[0]['attribs']['']['ref'];
}
- if(($is_reply) && is_array($contact)) {
+ if(($is_reply) && is_array($contact) && $pass != 1) {
// Have we seen it? If not, import it.
@@ -1385,7 +1404,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $secure_fee
}
$force_parent = false;
- if($contact['network'] === 'stat') {
+ if($contact['network'] === NETWORK_OSTATUS) {
$force_parent = true;
if(strlen($datarray['title']))
unset($datarray['title']);
@@ -1397,7 +1416,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $secure_fee
$datarray['last-child'] = 1;
}
- if(($contact['network'] === 'feed') || (! strlen($contact['notify']))) {
+ if(($contact['network'] === NETWORK_FEED) || (! strlen($contact['notify']))) {
// one way feed - no remote comment ability
$datarray['last-child'] = 0;
}
@@ -1430,6 +1449,8 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $secure_fee
$datarray['author-avatar'] = $contact['thumb'];
}
+ // special handling for events
+
if((x($datarray,'object-type')) && ($datarray['object-type'] === ACTIVITY_OBJ_EVENT)) {
$ev = bbtoevent($datarray['body']);
if(x($ev,'desc') && x($ev,'start')) {
@@ -1491,16 +1512,28 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $secure_fee
lose_follower($importer,$contact,$datarray,$item);
return;
}
+
+ if(activity_match($datarray['verb'],ACTIVITY_REQ_FRIEND)) {
+ logger('consume-feed: New friend request');
+ new_follower($importer,$contact,$datarray,$item,true);
+ return;
+ }
+ if(activity_match($datarray['verb'],ACTIVITY_UNFRIEND)) {
+ lose_sharer($importer,$contact,$datarray,$item);
+ return;
+ }
+
+
if(! is_array($contact))
return;
- if($contact['network'] === 'stat' || stristr($permalink,'twitter.com')) {
+ if($contact['network'] === NETWORK_OSTATUS || stristr($permalink,'twitter.com')) {
if(strlen($datarray['title']))
unset($datarray['title']);
$datarray['last-child'] = 1;
}
- if(($contact['network'] === 'feed') || (! strlen($contact['notify']))) {
+ if(($contact['network'] === NETWORK_FEED) || (! strlen($contact['notify']))) {
// one way feed - no remote comment ability
$datarray['last-child'] = 0;
}
@@ -1522,7 +1555,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $secure_fee
}
}
-function new_follower($importer,$contact,$datarray,$item) {
+function new_follower($importer,$contact,$datarray,$item,$sharing = false) {
$url = notags(trim($datarray['author-link']));
$name = notags(trim($datarray['author-name']));
$photo = notags(trim($datarray['author-avatar']));
@@ -1532,14 +1565,14 @@ function new_follower($importer,$contact,$datarray,$item) {
$nick = $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data'];
if(is_array($contact)) {
- if($contact['network'] == 'stat' && $contact['rel'] == CONTACT_IS_SHARING) {
+ if(($contact['network'] == NETWORK_OSTATUS && $contact['rel'] == CONTACT_IS_SHARING)
+ || ($sharing && $contact['rel'] == CONTACT_IS_FOLLOWER)) {
$r = q("UPDATE `contact` SET `rel` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval(CONTACT_IS_FRIEND),
intval($contact['id']),
intval($importer['uid'])
);
}
-
// send email notification to owner?
}
else {
@@ -1555,13 +1588,12 @@ function new_follower($importer,$contact,$datarray,$item) {
dbesc($name),
dbesc($nick),
dbesc($photo),
- dbesc('stat'),
- intval(CONTACT_IS_FOLLOWER)
+ dbesc(($sharing) ? NETWORK_ZOT : NETWORK_OSTATUS),
+ intval(($sharing) ? CONTACT_IS_SHARING : CONTACT_IS_FOLLOWER)
);
- $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `pending` = 1 AND `rel` = %d LIMIT 1",
+ $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `pending` = 1 LIMIT 1",
intval($importer['uid']),
- dbesc($url),
- intval(CONTACT_IS_FOLLOWER)
+ dbesc($url)
);
if(count($r))
$contact_record = $r[0];
@@ -1593,7 +1625,7 @@ function new_follower($importer,$contact,$datarray,$item) {
'$sitename' => $a->config['sitename']
));
$res = mail($r[0]['email'],
- t("You have a new follower at ") . $a->config['sitename'],
+ (($sharing) ? t('A new person is sharing with you at ') : t("You have a new follower at ")) . $a->config['sitename'],
$email,
'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
. 'Content-type: text/plain; charset=UTF-8' . "\n"
@@ -1617,8 +1649,21 @@ function lose_follower($importer,$contact,$datarray,$item) {
}
}
+function lose_sharer($importer,$contact,$datarray,$item) {
+
+ if(($contact['rel'] == CONTACT_IS_FRIEND) || ($contact['rel'] == CONTACT_IS_FOLLOWER)) {
+ q("UPDATE `contact` SET `rel` = %d WHERE `id` = %d LIMIT 1",
+ intval(CONTACT_IS_FOLLOWER),
+ intval($contact['id'])
+ );
+ }
+ else {
+ contact_remove($contact['id']);
+ }
+}
+
-function subscribe_to_hub($url,$importer,$contact,$submode = 'subscribe') {
+function subscribe_to_hub($url,$importer,$contact,$hubmode = 'subscribe') {
if(is_array($importer)) {
$r = q("SELECT `nickname` FROM `user` WHERE `uid` = %d LIMIT 1",
@@ -1641,7 +1686,7 @@ function subscribe_to_hub($url,$importer,$contact,$submode = 'subscribe') {
$params= 'hub.mode=' . $hubmode . '&hub.callback=' . urlencode($push_url) . '&hub.topic=' . urlencode($contact['poll']) . '&hub.verify=async&hub.verify_token=' . $verify_token;
- logger('subscribe_to_hub: subscribing ' . $contact['name'] . ' to hub ' . $url . ' with verifier ' . $verify_token);
+ logger('subscribe_to_hub: ' . $hubmode . ' ' . $contact['name'] . ' to hub ' . $url . ' endpoint: ' . $push_url . ' with verifier ' . $verify_token);
if(! strlen($contact['hub-verify'])) {
$r = q("UPDATE `contact` SET `hub-verify` = '%s' WHERE `id` = %d LIMIT 1",
diff --git a/include/notifier.php b/include/notifier.php
index 748d15743..c3f7f33ea 100644
--- a/include/notifier.php
+++ b/include/notifier.php
@@ -86,7 +86,7 @@ function notifier_run($argv, $argc){
$normal_mode = false;
$expire = true;
$items = q("SELECT * FROM `item` WHERE `uid` = %d AND `wall` = 1
- AND `deleted` = 1 AND `changed` > UTC_TIMESTAMP - INTERVAL 10 MINUTE",
+ AND `deleted` = 1 AND `changed` > UTC_TIMESTAMP() - INTERVAL 10 MINUTE",
intval($item_id)
);
$uid = $item_id;
@@ -123,6 +123,9 @@ function notifier_run($argv, $argc){
$uid = $r[0]['uid'];
$updated = $r[0]['edited'];
+ if(! $parent_id)
+ return;
+
$items = q("SELECT `item`.*, `sign`.`signed_text`,`sign`.`signature`,`sign`.`signer`
FROM `item` LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id` WHERE `parent` = %d ORDER BY `id` ASC",
intval($parent_id)
@@ -357,7 +360,16 @@ function notifier_run($argv, $argc){
if(! $contact)
continue;
- $atom .= atom_entry($item,'text',$contact,$owner,true);
+ if($normal_mode) {
+
+ // we only need the current item, but include the parent because without it
+ // older sites without a corresponding dfrn_notify change may do the wrong thing.
+
+ if($item_id == $item['id'] || $item['id'] == $item['parent'])
+ $atom .= atom_entry($item,'text',$contact,$owner,true);
+ }
+ else
+ $atom .= atom_entry($item,'text',$contact,$owner,true);
if(($top_level) && ($public_message) && ($item['author-link'] === $item['owner-link']) && (! $expire))
$slaps[] = atom_entry($item,'html',$contact,$owner,true);
diff --git a/include/poller.php b/include/poller.php
index 07076508f..427f8887c 100644
--- a/include/poller.php
+++ b/include/poller.php
@@ -44,6 +44,12 @@ function poller_run($argv, $argc){
AND `account_expires_on` != '0000-00-00 00:00:00'
AND `account_expires_on` < UTC_TIMESTAMP() ");
+ $abandon_days = intval(get_config('system','account_abandon_days'));
+ if($abandon_days < 1)
+ $abandon_days = 0;
+
+
+
// once daily run expire in background
$d1 = get_config('system','last_expire_day');
@@ -92,12 +98,17 @@ function poller_run($argv, $argc){
// and which have a polling address and ignore Diaspora since
// we are unable to match those posts with a Diaspora GUID and prevent duplicates.
+ $abandon_sql = (($abandon_days)
+ ? sprintf(" AND `user`.`login_date` > UTC_TIMESTAMP() - INTERVAL %d DAY ", intval($abandon_days))
+ : ''
+ );
+
$contacts = q("SELECT `contact`.`id` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
WHERE ( `rel` = %d OR `rel` = %d ) AND `poll` != ''
AND `network` != '%s'
$sql_extra
AND `self` = 0 AND `contact`.`blocked` = 0 AND `contact`.`readonly` = 0
- AND `user`.`account_expired` = 0 ORDER BY RAND()",
+ AND `user`.`account_expired` = 0 $abandon_sql ORDER BY RAND()",
intval(CONTACT_IS_SHARING),
intval(CONTACT_IS_FRIEND),
dbesc(NETWORK_DIASPORA)
@@ -475,11 +486,11 @@ function poller_run($argv, $argc){
}
- consume_feed($xml,$importer,$contact,$hub,1, true);
+ consume_feed($xml,$importer,$contact,$hub,1,1);
// do it twice. Ensures that children of parents which may be later in the stream aren't tossed
- consume_feed($xml,$importer,$contact,$hub,1);
+ consume_feed($xml,$importer,$contact,$hub,1,2);
$hubmode = 'subscribe';
if($contact['network'] === NETWORK_DFRN || $contact['blocked'] || $contact['readonly'])
diff --git a/include/text.php b/include/text.php
index 656cd8809..701c1e41b 100644
--- a/include/text.php
+++ b/include/text.php
@@ -744,7 +744,12 @@ function link_compare($a,$b) {
if(! function_exists('prepare_body')) {
function prepare_body($item,$attach = false) {
+ call_hooks('prepare_body_init', $item);
+
$s = prepare_text($item['body']);
+
+ call_hooks('prepare_body', $s);
+
if(! $attach)
return $s;
@@ -776,6 +781,7 @@ function prepare_body($item,$attach = false) {
}
$s .= '<div class="clear"></div></div>';
}
+ call_hooks('prepare_body_final', $s);
return $s;
}}