]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
Merge pull request #14 from duthied/master
[friendica.git] / include / items.php
index 1603dec601c0c10cd6521a40e0405b6034dbd35d..32f0728c33fa5b16f9119477c20be8815ed59079 100644 (file)
@@ -20,6 +20,8 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0)
                for($x = 2; $x < $a->argc; $x++) {
                        if($a->argv[$x] == 'converse')
                                $converse = true;
+                       if($a->argv[$x] == 'starred')
+                               $starred = true;
                }
        }
 
@@ -376,6 +378,10 @@ function get_atom_elements($feed,$item) {
        if($dguid)
                $res['guid'] = unxmlify($dguid[0]['data']);
 
+       $bm = $item->get_item_tags(NAMESPACE_DFRN,'bookmark');
+       if($bm)
+               $res['bookmark'] = ((unxmlify($bm[0]['data']) === 'true') ? 1 : 0);
+
 
        /**
         * If there's a copy of the body content which is guaranteed to have survived mangling in transit, use it.
@@ -711,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']))         : '');
@@ -731,6 +738,7 @@ function item_store($arr,$force_parent = false) {
        $arr['deny_cid']      = ((x($arr,'deny_cid'))      ? trim($arr['deny_cid'])              : '');
        $arr['deny_gid']      = ((x($arr,'deny_gid'))      ? trim($arr['deny_gid'])              : '');
        $arr['private']       = ((x($arr,'private'))       ? intval($arr['private'])             : 0 );
+       $arr['bookmark']      = ((x($arr,'bookmark'))      ? intval($arr['bookmark'])            : 0 );
        $arr['body']          = ((x($arr,'body'))          ? trim($arr['body'])                  : '');
        $arr['tag']           = ((x($arr,'tag'))           ? notags(trim($arr['tag']))           : '');
        $arr['attach']        = ((x($arr,'attach'))        ? notags(trim($arr['attach']))        : '');
@@ -858,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),
@@ -1026,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);
@@ -1472,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;
 
@@ -1503,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']));
@@ -1513,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 {
@@ -1536,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];
@@ -1574,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"
@@ -1598,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;
 
@@ -1615,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);
 
@@ -1704,6 +1754,8 @@ function atom_entry($item,$type,$author,$owner,$comment = false) {
 
        if($item['extid'])
                $o .= '<dfrn:extid>' . xmlify($item['extid']) . '</dfrn:extid>' . "\r\n";
+       if($item['bookmark'])
+               $o .= '<dfrn:bookmark>true</dfrn:bookmark>' . "\r\n";
 
        if($item['app'])
                $o .= '<statusnet:notice_info local_id="' . $item['id'] . '" source="' . xmlify($item['app']) . '" ></statusnet:notice_info>' . "\r\n";