]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
Merge pull request #14 from duthied/master
[friendica.git] / include / items.php
index facd8b2d4df313e9ed99b2fa24ead393dd2d6873..32f0728c33fa5b16f9119477c20be8815ed59079 100644 (file)
@@ -717,6 +717,7 @@ function item_store($arr,$force_parent = false) {
        $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['title']         = ((x($arr,'title'))         ? notags(trim($arr['title']))         : '');
@@ -865,6 +866,14 @@ function item_store($arr,$force_parent = false) {
                intval($current_post)
        );
 
+       // update the commented timestamp on the parent
+
+       q("UPDATE `item` set `commented` = '%s', `changed` = '%s' WHERE `id` = %d LIMIT 1",
+               dbesc(datetime_convert()),
+               dbesc(datetime_convert()),
+               intval($parent_id)
+       );
+
        if($dsprsig) {
                q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
                        intval($current_post),
@@ -1033,6 +1042,9 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
        if((! $curl_stat) || (! strlen($xml)))
                return(-1); // timed out
 
+       if(($curl_stat == 503) && (stristr($a->get_curl_headers(),'retry-after')))
+               return(-1);
+
        if(strpos($xml,'<?xml') === false) {
                logger('dfrn_deliver: phase 2: no valid XML returned');
                logger('dfrn_deliver: phase 2: returned XML: ' . $xml, LOGGER_DATA);
@@ -1479,6 +1491,20 @@ 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;
 
@@ -1510,7 +1536,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']));
@@ -1520,14 +1546,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 {
@@ -1543,13 +1569,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];
@@ -1581,7 +1606,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"
@@ -1605,14 +1630,32 @@ 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) {
+
+function subscribe_to_hub($url,$importer,$contact,$submode = 'subscribe') {
 
        if(is_array($importer)) {
                $r = q("SELECT `nickname` FROM `user` WHERE `uid` = %d LIMIT 1",
                        intval($importer['uid'])
                );
        }
+
+       // Diaspora has different message-ids in feeds than they do 
+       // through the direct Diaspora protocol. If we try and use
+       // the feed, we'll get duplicates. So don't.
+
        if((! count($r)) || $contact['network'] === NETWORK_DIASPORA)
                return;
 
@@ -1622,7 +1665,7 @@ function subscribe_to_hub($url,$importer,$contact) {
 
        $verify_token = ((strlen($contact['hub-verify'])) ? $contact['hub-verify'] : random_string());
 
-       $params= 'hub.mode=subscribe&hub.callback=' . urlencode($push_url) . '&hub.topic=' . urlencode($contact['poll']) . '&hub.verify=async&hub.verify_token=' . $verify_token;
+       $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);