]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
Merge remote-tracking branch 'remotes/friendica/master' into moveme
[friendica.git] / include / items.php
index f70e96fcbe8a08dcbf89197f19373f1dd1dc2e11..5ad89d8c180d9afeeb3e20706db2e1aeb4651cfd 100755 (executable)
@@ -76,6 +76,7 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0)
                        killme();
 
                $contact = $r[0];
+               require_once('include/security.php');
                $groups = init_groups_visitor($contact['id']);
 
                if(count($groups)) {
@@ -1186,7 +1187,7 @@ function tag_deliver($uid,$item_id) {
 
        // use a local photo if we have one
 
-       $r = q("select thumb from contact where uid = %d and nurl = '%s' limit 1",
+       $r = q("select * from contact where uid = %d and nurl = '%s' limit 1",
                intval($u[0]['uid']),
                dbesc(normalise_link($item['author-link']))
        );
@@ -1210,6 +1211,11 @@ function tag_deliver($uid,$item_id) {
                'otype'        => 'item'
        ));
 
+
+       $arr = array('item' => $item, 'user' => $u[0], 'contact' => $r[0]);
+
+       call_hooks('tagged', $arr);
+
        if((! $community_page) && (! $prvgroup))
                return;
 
@@ -2162,9 +2168,10 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
 }
 
 function local_delivery($importer,$data) {
-
        $a = get_app();
 
+    logger(__function__, LOGGER_TRACE);
+
        if($importer['readonly']) {
                // We aren't receiving stuff from this person. But we will quietly ignore them
                // rather than a blatant "go away" message.
@@ -2299,7 +2306,7 @@ function local_delivery($importer,$data) {
        }
 
 
-/*
+
        // Currently unsupported - needs a lot of work
        $reloc = $feed->get_feed_tags( NAMESPACE_DFRN, 'relocate' );
        if(isset($reloc[0]['child'][NAMESPACE_DFRN])) {
@@ -2309,23 +2316,79 @@ function local_delivery($importer,$data) {
                $newloc['cid'] = $importer['id'];
                $newloc['name'] = notags(unxmlify($base['name'][0]['data']));
                $newloc['photo'] = notags(unxmlify($base['photo'][0]['data']));
+               $newloc['thumb'] = notags(unxmlify($base['thumb'][0]['data']));
+               $newloc['micro'] = notags(unxmlify($base['micro'][0]['data']));
                $newloc['url'] = notags(unxmlify($base['url'][0]['data']));
                $newloc['request'] = notags(unxmlify($base['request'][0]['data']));
                $newloc['confirm'] = notags(unxmlify($base['confirm'][0]['data']));
                $newloc['notify'] = notags(unxmlify($base['notify'][0]['data']));
                $newloc['poll'] = notags(unxmlify($base['poll'][0]['data']));
-               $newloc['site-pubkey'] = notags(unxmlify($base['site-pubkey'][0]['data']));
-               $newloc['pubkey'] = notags(unxmlify($base['pubkey'][0]['data']));
-               $newloc['prvkey'] = notags(unxmlify($base['prvkey'][0]['data']));
+               $newloc['sitepubkey'] = notags(unxmlify($base['sitepubkey'][0]['data']));
+               /** relocated user must have original key pair */
+               /*$newloc['pubkey'] = notags(unxmlify($base['pubkey'][0]['data']));
+               $newloc['prvkey'] = notags(unxmlify($base['prvkey'][0]['data']));*/
+               
+        logger("items:relocate contact ".print_r($newloc, true).print_r($importer, true), LOGGER_DEBUG);
+        
+        // update contact
+        $r = q("SELECT photo, url FROM contact WHERE id=%d AND uid=%d;",
+                    intval($importer['id']),
+                                       intval($importer['importer_uid']));
+               if ($r === false) 
+                       return 1;
+        $old = $r[0];
+        
+        $x = q("UPDATE contact SET
+                        name = '%s',
+                        photo = '%s',
+                        thumb = '%s',
+                        micro = '%s',
+                        url = '%s',
+                        request = '%s',
+                        confirm = '%s',
+                        notify = '%s',
+                        poll = '%s',
+                        `site-pubkey` = '%s'
+                WHERE id=%d AND uid=%d;",
+                    dbesc($newloc['name']),
+                    dbesc($newloc['photo']),
+                    dbesc($newloc['thumb']),
+                    dbesc($newloc['micro']),
+                    dbesc($newloc['url']),
+                    dbesc($newloc['request']),
+                    dbesc($newloc['confirm']),
+                    dbesc($newloc['notify']),
+                    dbesc($newloc['poll']),
+                    dbesc($newloc['sitepubkey']),
+                    intval($importer['id']),
+                                       intval($importer['importer_uid']));
+
+        if ($x === false)
+                       return 1;
+        // update items
+        $fields = array(
+            'owner-link' => array($old['url'], $newloc['url']),
+            'author-link' => array($old['url'], $newloc['url']),
+            'owner-avatar' => array($old['photo'], $newloc['photo']),
+            'author-avatar' => array($old['photo'], $newloc['photo']),
+        );
+        foreach ($fields as $n=>$f){
+            $x = q("UPDATE item SET `%s`='%s' WHERE `%s`='%s' AND uid=%d",
+                        $n, dbesc($f[1]),
+                        $n, dbesc($f[0]),
+                        intval($importer['importer_uid']));
+                       if ($x === false)
+                               return 1;
+               }
                
                // TODO
                // merge with current record, current contents have priority
                // update record, set url-updated
                // update profile photos
                // schedule a scan?
-
+        return 0;
        }
-*/
+
 
        // handle friend suggestion notification
 
@@ -3895,10 +3958,10 @@ function drop_item($id,$interactive = true) {
 
                // send the notification upstream/downstream as the case may be
 
+               proc_run('php',"include/notifier.php","drop","$drop_id");
+
                if(! $interactive)
                        return $owner;
-
-               proc_run('php',"include/notifier.php","drop","$drop_id");
                goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
                //NOTREACHED
        }