]> git.mxchange.org Git - friendica.git/commitdiff
Merge remote-tracking branch 'upstream/develop' into 1501-central-item-storage
authorMichael Vogel <icarus@dabo.de>
Sun, 1 Feb 2015 12:28:32 +0000 (13:28 +0100)
committerMichael Vogel <icarus@dabo.de>
Sun, 1 Feb 2015 12:28:32 +0000 (13:28 +0100)
boot.php
include/Contact.php
include/diaspora.php
mod/display.php
mod/noscrape.php

index 4ff0e4fbea5e2110923a39cfa5895a396256b922..dd6bc6ac5d6f6c58b9fcb7ca28a0c7898dcde193 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -1405,11 +1405,11 @@ if(! function_exists('get_max_import_size')) {
 if(! function_exists('profile_load')) {
        function profile_load(&$a, $nickname, $profile = 0, $profiledata = array()) {
 
-               $user = q("select uid from user where nickname = '%s' limit 1",
+               $user = q("SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
                        dbesc($nickname)
                );
 
-               if(! ($user && count($user))) {
+               if(!$user && count($user) && !count($profiledata)) {
                        logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
                        notice( t('Requested account is not available.') . EOL );
                        $a->error = 404;
@@ -1440,7 +1440,7 @@ if(! function_exists('profile_load')) {
                                        intval($profile_int)
                        );
                }
-               if((! $r) && (!  count($r))) {
+               if((!$r) && (!count($r))) {
                        $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile`
                                        INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
                                        WHERE `user`.`nickname` = '%s' AND `profile`.`is-default` = 1 and `contact`.`self` = 1 LIMIT 1",
@@ -1448,7 +1448,7 @@ if(! function_exists('profile_load')) {
                        );
                }
 
-               if(($r === false) || (! count($r))) {
+               if(($r === false) || (!count($r)) && !count($profiledata)) {
                        logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
                        notice( t('Requested profile is not available.') . EOL );
                        $a->error = 404;
@@ -1457,7 +1457,7 @@ if(! function_exists('profile_load')) {
 
                // fetch user tags if this isn't the default profile
 
-               if(! $r[0]['is-default']) {
+               if(!$r[0]['is-default']) {
                        $x = q("select `pub_keywords` from `profile` where uid = %d and `is-default` = 1 limit 1",
                                        intval($r[0]['profile_uid'])
                        );
index a6429bbf49eced95df08533580c48bfd3087327f..30bd8b607434de07aab6ae9a9a0cadc115dc7a31 100644 (file)
@@ -293,3 +293,77 @@ function contacts_not_grouped($uid,$start = 0,$count = 0) {
        return $r;
 }
 
+function get_contact($url, $uid = 0) {
+       require_once("include/Scrape.php");
+
+       $data = array();
+
+       // is it an address in the format user@server.tld?
+       if (!strstr($url, "http") OR strstr($url, "@")) {
+               $data = probe_url($url);
+               $url = $data["url"];
+               if ($url == "")
+                       return 0;
+       }
+
+       $contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
+                       dbesc(normalise_link($url)),
+                       intval($uid));
+       if ($contact)
+               return($contact[0]["id"]);
+
+       if (!count($data))
+               $data = probe_url($url);
+
+       // Does this address belongs to a valid network?
+       if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
+               return 0;
+
+       q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`,
+                               `name`, `nick`, `photo`, `network`, `pubkey`, `rel`, `priority`,
+                               `batch`, `request`, `confirm`, `poco`,
+                               `writable`, `blocked`, `readonly`, `pending`)
+                               VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', '%s', '%s', 1, 0, 0, 0)",
+               intval($uid),
+               dbesc(datetime_convert()),
+               dbesc($data["url"]),
+               dbesc(normalise_link($data["url"])),
+               dbesc($data["addr"]),
+               dbesc($data["alias"]),
+               dbesc($data["notify"]),
+               dbesc($data["poll"]),
+               dbesc($data["name"]),
+               dbesc($data["nick"]),
+               dbesc($data["photo"]),
+               dbesc($data["network"]),
+               dbesc($data["pubkey"]),
+               intval(CONTACT_IS_SHARING),
+               intval($data["priority"]),
+               dbesc($data["batch"]),
+               dbesc($data["request"]),
+               dbesc($data["confirm"]),
+               dbesc($data["poco"])
+       );
+
+       $contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
+                       dbesc(normalise_link($url)),
+                       intval($uid));
+       if (!$contact)
+               return 0;
+
+       require_once("Photo.php");
+
+       $photos = import_profile_photo($data["photo"],$uid,$contact[0]["id"]);
+
+       q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s', `name-date` = '%s', `uri-date` = '%s', `avatar-date` = '%s' WHERE `id` = %d",
+               dbesc($photos[0]),
+               dbesc($photos[1]),
+               dbesc($photos[2]),
+               dbesc(datetime_convert()),
+               dbesc(datetime_convert()),
+               dbesc(datetime_convert()),
+               intval($contact[0]["id"])
+       );
+
+       return $contact[0]["id"];
+}
index affd59d489fa8887802cca18a4bc4760398fd764..c3099e21963215a8793203302c971f3cced59023 100755 (executable)
@@ -897,13 +897,6 @@ function diaspora_post($importer,$xml,$msg) {
 
        $message_id = item_store($datarray);
 
-       //if($message_id) {
-       //      q("update item set plink = '%s' where id = %d",
-       //              dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id),
-       //              intval($message_id)
-       //      );
-       //}
-
        return;
 
 }
@@ -1102,7 +1095,8 @@ function diaspora_reshare($importer,$xml,$msg) {
                        $orig_created = $item["created"];
                        $orig_author = $item["author"];
                        $orig_guid = $item["guid"];
-                       //$create_original_post = ($body != "");
+                       $create_original_post = ($body != "");
+                       $orig_url = $a->get_baseurl()."/display/".$orig_guid;
                }
        }
 
@@ -1164,12 +1158,13 @@ function diaspora_reshare($importer,$xml,$msg) {
        $datarray['visible'] = ((strlen($body)) ? 1 : 0);
 
        // Store the original item of a reshare
-       // Deactivated by now. Items without a matching contact can't be shown via "mod/display.php" by now.
        if ($create_original_post) {
+               require_once("include/Contact.php");
+
                $datarray2 = $datarray;
 
                $datarray2['uid'] = 0;
-               $datarray2['contact-id'] = 0;
+               $datarray2['contact-id'] = get_contact($person['url'], 0);
                $datarray2['guid'] = $orig_guid;
                $datarray2['uri'] = $datarray2['parent-uri'] = $orig_author.':'.$orig_guid;
                $datarray2['changed'] = $datarray2['created'] = $datarray2['edited'] = datetime_convert('UTC','UTC',$orig_created);
index 374de6caccfaddaa5557a4a4cbc07cd6bfee3d6d..f483977cd4f847aebc639bbe93a4f85a499b921d 100644 (file)
@@ -41,6 +41,18 @@ function display_init(&$a) {
                                $itemuid = $r[0]["uid"];
                        }
                }
+
+               // Is it an item with uid=0?
+               if ($nick == "") {
+                       $r = q("SELECT `item`.`id`, `item`.`parent`, `item`.`author-name`,
+                               `item`.`author-link`, `item`.`author-avatar`, `item`.`network`, `item`.`uid`, `item`.`body`
+                               FROM `item` WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
+                                       AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''
+                                       AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''
+                                       AND `item`.`private` = 0 AND `item`.`uid` = 0
+                                       AND `item`.`guid` = '%s'", $a->argv[1]);
+                               //      AND `item`.`private` = 0 AND `item`.`wall` = 1
+               }
                if (count($r)) {
                        if ($r[0]["id"] != $r[0]["parent"])
                                $r = q("SELECT `id`, `author-name`, `author-link`, `author-avatar`, `network`, `body`, `uid` FROM `item`
@@ -252,6 +264,18 @@ function display_content(&$a, $update = 0) {
                                        $nick = $r[0]["nickname"];
                                }
                        }
+                       if ($nick == "") {
+                               $r = q("SELECT `item`.`id` FROM `item`
+                                       WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
+                                               AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''
+                                               AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''
+                                               AND `item`.`private` = 0  AND `item`.`uid` = 0
+                                               AND `item`.`guid` = '%s'", $a->argv[1]);
+                                       //      AND `item`.`private` = 0 AND `item`.`wall` = 1
+                               if (count($r)) {
+                                       $item_id = $r[0]["id"];
+                               }
+                       }
                }
        }
 
index e037300fc20c9b993fe7ca863ab23f022e537b62..a859efd41ef922aa29f2d3f2ceac6a4134a2d451 100644 (file)
@@ -1,30 +1,30 @@
 <?php
 
 function noscrape_init(&$a) {
-       
+
        if(get_config('system','disable_noscrape'))
                killme();
-       
+
        if($a->argc > 1)
                $which = $a->argv[1];
-       else 
+       else
                killme();
-       
+
        $profile = 0;
        if((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) {
                $which = $a->user['nickname'];
                $profile = $a->argv[1];
        }
-       
+
        profile_load($a,$which,$profile);
-       
+
        if(!$a->profile['net-publish'])
                killme();
-       
+
        $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : '');
        $keywords = str_replace(array('#',',',' ',',,'),array('',' ',',',','),$keywords);
        $keywords = explode(',', $keywords);
-       
+
        $json_info = array(
                'fn' => $a->profile['name'],
                'key' => $a->profile['pubkey'],
@@ -33,19 +33,19 @@ function noscrape_init(&$a) {
                'photo' => $a->profile['photo'],
                'tags' => $keywords
        );
-       
+
        //These are optional fields.
-       $profile_fields = array('pdesc', 'locality', 'region', 'postal-code', 'country-name', 'gender', 'marital');
+       $profile_fields = array('pdesc', 'locality', 'region', 'postal-code', 'country-name', 'gender', 'marital', 'about');
        foreach($profile_fields as $field)
                if(!empty($a->profile[$field])) $json_info["$field"] = $a->profile[$field];
-       
+
        $dfrn_pages = array('request', 'confirm', 'notify', 'poll');
        foreach($dfrn_pages as $dfrn)
                $json_info["dfrn-{$dfrn}"] = $a->get_baseurl()."/dfrn_{$dfrn}/{$which}";
-       
+
        //Output all the JSON!
        header('Content-type: application/json; charset=utf-8');
        echo json_encode($json_info);
        exit;
-       
+
 }