]> git.mxchange.org Git - friendica.git/blobdiff - mod/display.php
Merge develop into 0602_contact_profile
[friendica.git] / mod / display.php
index 374de6caccfaddaa5557a4a4cbc07cd6bfee3d6d..4e33927072bdf8123e17abc7a485a22dd768666a 100644 (file)
@@ -18,7 +18,7 @@ function display_init(&$a) {
                if (local_user()) {
                        $r = q("SELECT `id`, `parent`, `author-name`, `author-link`, `author-avatar`, `network`, `body`, `uid` FROM `item`
                                WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
-                                       AND `guid` = '%s' AND `uid` = %d", $a->argv[1], local_user());
+                                       AND `guid` = '%s' AND `uid` = %d", dbesc($a->argv[1]), local_user());
                        if (count($r)) {
                                $nick = $a->user["nickname"];
                                $itemuid = local_user();
@@ -34,13 +34,25 @@ function display_init(&$a) {
                                        AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''
                                        AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''
                                        AND `item`.`private` = 0 AND NOT `user`.`hidewall`
-                                       AND `item`.`guid` = '%s'", $a->argv[1]);
+                                       AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
                                //      AND `item`.`private` = 0 AND `item`.`wall` = 1
                        if (count($r)) {
                                $nick = $r[0]["nickname"];
                                $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'", dbesc($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`
@@ -77,42 +89,16 @@ function display_init(&$a) {
 }
 
 function display_fetchauthor($a, $item) {
-       require_once("mod/proxy.php");
-       require_once("include/bbcode.php");
 
        $profiledata = array();
        $profiledata["uid"] = -1;
        $profiledata["nickname"] = $item["author-name"];
        $profiledata["name"] = $item["author-name"];
        $profiledata["picdate"] = "";
-       $profiledata["photo"] = proxy_url($item["author-avatar"]);
+       $profiledata["photo"] = $item["author-avatar"];
        $profiledata["url"] = $item["author-link"];
        $profiledata["network"] = $item["network"];
 
-       // Fetching further contact data from the contact table
-       $r = q("SELECT `photo`, `nick`, `location`, `about` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
-               normalise_link($profiledata["url"]), $item["uid"]);
-       if (count($r)) {
-               $profiledata["photo"] = proxy_url($r[0]["photo"]);
-               $profiledata["address"] = proxy_parse_html(bbcode($r[0]["location"]));
-               $profiledata["about"] = proxy_parse_html(bbcode($r[0]["about"]));
-               if ($r[0]["nick"] != "")
-                       $profiledata["nickname"] = $r[0]["nick"];
-       }
-
-       // Fetching profile data from unique contacts
-       $r = q("SELECT `avatar`, `nick`, `location`, `about` FROM `unique_contacts` WHERE `url` = '%s'", normalise_link($profiledata["url"]));
-       if (count($r)) {
-               if ($profiledata["photo"] == "")
-                       $profiledata["photo"] = proxy_url($r[0]["avatar"]);
-               if ($profiledata["address"] == "")
-                       $profiledata["address"] = proxy_parse_html(bbcode($r[0]["location"]));
-               if ($profiledata["about"] == "")
-                       $profiledata["about"] = proxy_parse_html(bbcode($r[0]["about"]));
-               if (($profiledata["nickname"] == "") AND ($r[0]["nick"] != ""))
-                       $profiledata["nickname"] = $r[0]["nick"];
-       }
-
        // Check for a repeated message
        $skip = false;
        $body = trim($item["body"]);
@@ -166,26 +152,67 @@ function display_fetchauthor($a, $item) {
 
                $profiledata["address"] = "";
                $profiledata["about"] = "";
+       }
 
-               // Fetching profile data from unique contacts
-               if ($profiledata["url"] != "") {
-                       $r = q("SELECT `avatar`, `nick`, `location`, `about` FROM `unique_contacts` WHERE `url` = '%s'", normalise_link($profiledata["url"]));
-                       if (count($r)) {
-                               $profiledata["photo"] = proxy_url($r[0]["avatar"]);
-                               $profiledata["address"] = proxy_parse_html(bbcode($r[0]["location"]));
-                               $profiledata["about"] = proxy_parse_html(bbcode($r[0]["about"]));
-                               if ($r[0]["nick"] != "")
-                                       $profiledata["nickname"] = $r[0]["nick"];
+       // Don't show details from Diaspora contacts if you don't follow the contact
+       $showdetails = ($profiledata["network"] != NETWORK_DIASPORA);
+
+       // Fetching further contact data from the contact table
+       $r = q("SELECT `uid`, `network`, `name`, `photo`, `nick`, `addr`, `location`, `about`, `gender`, `keywords`
+               FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `network` = '%s' AND `rel` IN (%d, %d)",
+               dbesc(normalise_link($profiledata["url"])), intval(local_user()), dbesc($item["network"]),
+               intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND));
+       if (!count($r))
+               $r = q("SELECT `uid`, `network`, `name`, `photo`, `nick`, `addr`, `location`, `about`, `gender`, `keywords`
+                       FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `rel` IN (%d, %d)",
+                       dbesc(normalise_link($profiledata["url"])), intval(local_user()),
+                       intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND));
+
+       if (count($r)) {
+               $profiledata["name"] = $r[0]["name"];
+               $profiledata["photo"] = $r[0]["photo"];
+               $profiledata["nickname"] = $r[0]["nick"];
+               $profiledata["addr"] = $r[0]["addr"];
+               $profiledata["keywords"] = $r[0]["keywords"];
+               $profiledata["network"] = $r[0]["network"];
+
+               if (local_user() OR $showdetails) {
+                       $showdetails = true;
+                       $profiledata["address"] = $r[0]["location"];
+                       $profiledata["about"] = $r[0]["about"];
+                       $profiledata["gender"] = $r[0]["gender"];
+               }
+       }
+
+       // Fetching profile data from global contacts
+       if ($profiledata["network"] != NETWORK_FEED) {
+               $r = q("SELECT `name`, `photo`, `nick`, `addr`, `location`, `about`, `gender`, `keywords`, `network` FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($profiledata["url"])));
+               if (count($r)) {
+                       $profiledata["name"] = $r[0]["name"];
+                       $profiledata["photo"] = $r[0]["photo"];
+                       $profiledata["nickname"] = $r[0]["nick"];
+                       $profiledata["addr"] = $r[0]["addr"];
+                       $profiledata["network"] = $r[0]["network"];
+
+                       if ($r[0]["keywords"])
+                               $profiledata["keywords"] = $r[0]["keywords"];
+
+                       if ($showdetails) {
+                               if ($r[0]["location"])
+                                       $profiledata["address"] = $r[0]["location"];
+
+                               if ($r[0]["about"])
+                                       $profiledata["about"] = $r[0]["about"];
+
+                               if ($r[0]["gender"])
+                                       $profiledata["gender"] = $r[0]["gender"];
                        }
                }
        }
 
        if (local_user()) {
-               if ($profiledata["network"] == NETWORK_DFRN) {
-                       $connect = str_replace("/profile/", "/dfrn_request/", $profiledata["url"])."&addr=".bin2hex($a->get_baseurl()."/profile/".$a->user["nickname"]);
-                       $profiledata["remoteconnect"] = $connect;
-               } elseif ($profiledata["network"] == NETWORK_DIASPORA)
-                       $profiledata["remoteconnect"] = $a->get_baseurl()."/contacts?add=".GetProfileUsername($profiledata["url"], "", true);
+               if (in_array($profiledata["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS)))
+                       $profiledata["remoteconnect"] = $a->get_baseurl()."/follow?url=".urlencode($profiledata["url"]);
        } elseif ($profiledata["network"] == NETWORK_DFRN) {
                $connect = str_replace("/profile/", "/dfrn_request/", $profiledata["url"]);
                $profiledata["remoteconnect"] = $connect;
@@ -201,7 +228,6 @@ function display_content(&$a, $update = 0) {
                return;
        }
 
-       require_once("include/bbcode.php");
        require_once('include/security.php');
        require_once('include/conversation.php');
        require_once('include/acl_selectors.php');
@@ -232,7 +258,7 @@ function display_content(&$a, $update = 0) {
                        if (local_user()) {
                                $r = q("SELECT `id` FROM `item`
                                        WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
-                                               AND `guid` = '%s' AND `uid` = %d", $a->argv[1], local_user());
+                                               AND `guid` = '%s' AND `uid` = %d", dbesc($a->argv[1]), local_user());
                                if (count($r)) {
                                        $item_id = $r[0]["id"];
                                        $nick = $a->user["nickname"];
@@ -245,13 +271,25 @@ function display_content(&$a, $update = 0) {
                                                AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''
                                                AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''
                                                AND `item`.`private` = 0  AND NOT `user`.`hidewall`
-                                               AND `item`.`guid` = '%s'", $a->argv[1]);
+                                               AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
                                        //      AND `item`.`private` = 0 AND `item`.`wall` = 1
                                if (count($r)) {
                                        $item_id = $r[0]["id"];
                                        $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'", dbesc($a->argv[1]));
+                                       //      AND `item`.`private` = 0 AND `item`.`wall` = 1
+                               if (count($r)) {
+                                       $item_id = $r[0]["id"];
+                               }
+                       }
                }
        }
 
@@ -309,16 +347,18 @@ function display_content(&$a, $update = 0) {
                return;
        }
 
+       // Why do we need this on the display page? We don't have the possibility to write new content here.
+       // Ad editing of posts work without this as well.
+       // We should remove this completely for the 3.5.1 release.
+       /*
        if ($is_owner) {
-               $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
-
                $x = array(
                        'is_owner' => true,
                        'allow_location' => $a->user['allow_location'],
                        'default_location' => $a->user['default-location'],
                        'nickname' => $a->user['nickname'],
                        'lockstate' => ( (is_array($a->user)) && ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) || (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))) ? 'lock' : 'unlock'),
-                       'acl' => populate_acl($a->user, $celeb),
+                       'acl' => populate_acl($a->user, true),
                        'bang' => '',
                        'visitor' => 'block',
                        'profile_uid' => local_user(),
@@ -326,6 +366,7 @@ function display_content(&$a, $update = 0) {
                );
                $o .= status_editor($a,$x,0,true);
        }
+       */
 
        $sql_extra = item_permissions_sql($a->profile['uid'],$remote_contact,$groups);
 
@@ -379,7 +420,7 @@ function display_content(&$a, $update = 0) {
 
                        $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,  `item`.`network` AS `item_network`,
                                `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
-                               `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, 
+                               `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
                                `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
                                FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
                                AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0