From b36d79904497bab6255a995921010a39eefc4a7e Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 7 Jan 2015 01:46:13 +0100 Subject: [PATCH] Fetching "location" and "about" from diaspora. Displaying them on the "display" page. --- boot.php | 5 ++++- include/diaspora.php | 21 +++++++++++-------- include/items.php | 2 +- include/threads.php | 16 +++++++------- mod/display.php | 23 +++++++++++---------- view/templates/profile_vcard.tpl | 2 ++ view/theme/vier/templates/profile_vcard.tpl | 2 ++ 7 files changed, 40 insertions(+), 31 deletions(-) diff --git a/boot.php b/boot.php index ec2a4a1acf..9e5a32b66b 100644 --- a/boot.php +++ b/boot.php @@ -1649,8 +1649,10 @@ if(! function_exists('profile_sidebar')) { $homepage = ((x($profile,'homepage') == 1) ? t('Homepage:') : False); + $about = ((x($profile,'about') == 1) ? t('About:') : False); + if(($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) { - $location = $pdesc = $gender = $marital = $homepage = False; + $location = $pdesc = $gender = $marital = $homepage = $about = False; } $firstname = ((strpos($profile['name'],' ')) @@ -1695,6 +1697,7 @@ if(! function_exists('profile_sidebar')) { '$pdesc' => $pdesc, '$marital' => $marital, '$homepage' => $homepage, + '$about' => $about, '$network' => t('Network:'), '$diaspora' => $diaspora, '$contact_block' => $contact_block, diff --git a/include/diaspora.php b/include/diaspora.php index 99288b773c..b5cb0f0e23 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -2028,7 +2028,7 @@ function diaspora_retraction($importer,$xml) { dbesc(datetime_convert()), intval($r[0]['id']) ); - delete_thread($r[0]['id']); + delete_thread($r[0]['id'], $r[0]['parent-uri']); } } } @@ -2101,7 +2101,7 @@ function diaspora_signed_retraction($importer,$xml,$msg) { dbesc(datetime_convert()), intval($r[0]['id']) ); - delete_thread($r[0]['id']); + delete_thread($r[0]['id'], $r[0]['parent-uri']); // Now check if the retraction needs to be relayed by us // @@ -2161,14 +2161,15 @@ function diaspora_profile($importer,$xml,$msg) { $name = unxmlify($xml->first_name) . ((strlen($xml->last_name)) ? ' ' . unxmlify($xml->last_name) : ''); $image_url = unxmlify($xml->image_url); $birthday = unxmlify($xml->birthday); + $location = unxmlify($xml->location); + $about = diaspora2bb(unxmlify($xml->bio)); $handle_parts = explode("@", $diaspora_handle); if($name === '') { $name = $handle_parts[0]; } - - + if( preg_match("|^https?://|", $image_url) === 0) { $image_url = "http://" . $handle_parts[1] . $image_url; } @@ -2182,8 +2183,8 @@ function diaspora_profile($importer,$xml,$msg) { require_once('include/Photo.php'); $images = import_profile_photo($image_url,$importer['uid'],$contact['id']); - - // Generic birthday. We don't know the timezone. The year is irrelevant. + + // Generic birthday. We don't know the timezone. The year is irrelevant. $birthday = str_replace('1000','1901',$birthday); @@ -2196,9 +2197,9 @@ function diaspora_profile($importer,$xml,$msg) { $birthday = $contact['bd']; // TODO: update name on item['author-name'] if the name changed. See consume_feed() - // Not doing this currently because D* protocol is scheduled for revision soon. + // Not doing this currently because D* protocol is scheduled for revision soon. - $r = q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' , `bd` = '%s' WHERE `id` = %d AND `uid` = %d", + $r = q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' , `bd` = '%s', `location` = '%s', `about` = '%s' WHERE `id` = %d AND `uid` = %d", dbesc($name), dbesc(datetime_convert()), dbesc($images[0]), @@ -2206,9 +2207,11 @@ function diaspora_profile($importer,$xml,$msg) { dbesc($images[2]), dbesc(datetime_convert()), dbesc($birthday), + dbesc($location), + dbesc($about), intval($contact['id']), intval($importer['uid']) - ); + ); /* if($r) { if($oldphotos) { diff --git a/include/items.php b/include/items.php index c1352cebbe..1637de15b3 100644 --- a/include/items.php +++ b/include/items.php @@ -4509,7 +4509,7 @@ function drop_item($id,$interactive = true) { ); create_tags_from_item($item['id']); create_files_from_item($item['id']); - delete_thread($item['id']); + delete_thread($item['id'], $item['parent-uri']); // clean up categories and tags so they don't end up as orphans diff --git a/include/threads.php b/include/threads.php index 8febe49e9b..e9a0d7f1f2 100644 --- a/include/threads.php +++ b/include/threads.php @@ -149,28 +149,26 @@ function delete_thread_uri($itemuri, $uid) { if(count($messages)) foreach ($messages as $message) - delete_thread($message["id"]); + delete_thread($message["id"], $itemuri); } -function delete_thread($itemid) { - // To-Do: - // There is no "uri" in the thread table ... - $item = q("SELECT `uri`, `uid` FROM `thread` WHERE `iid` = %d", intval($itemid)); +function delete_thread($itemid, $itemuri = "") { + $item = q("SELECT `uid` FROM `thread` WHERE `iid` = %d", intval($itemid)); $result = q("DELETE FROM `thread` WHERE `iid` = %d", intval($itemid)); logger("delete_thread: Deleted thread for item ".$itemid." - ".print_r($result, true), LOGGER_DEBUG); - if (count($item)) { + if ($itemuri != "") { $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND NOT (`uid` IN (%d, 0))", - dbesc($item["uri"]), + dbesc($itemuri), intval($item["uid"]) ); if (!count($r)) { $r = q("DELETE FROM `item` WHERE `uri` = '%s' AND `uid` = 0)", - dbesc($item["uri"]) + dbesc($itemuri) ); - logger("delete_thread: Deleted shadow for item ".$item["uri"]." - ".print_r($result, true), LOGGER_DEBUG); + logger("delete_thread: Deleted shadow for item ".$itemuri." - ".print_r($result, true), LOGGER_DEBUG); } } } diff --git a/mod/display.php b/mod/display.php index abb03b6d5b..d1da53cf16 100644 --- a/mod/display.php +++ b/mod/display.php @@ -16,7 +16,7 @@ function display_init(&$a) { // Does the local user have this item? if (local_user()) { - $r = q("SELECT `id`, `parent`, `author-name`, `author-link`, `author-avatar`, `network`, `body` FROM `item` + $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()); if (count($r)) { @@ -43,7 +43,7 @@ function display_init(&$a) { } if (count($r)) { if ($r[0]["id"] != $r[0]["parent"]) - $r = q("SELECT `id`, `author-name`, `author-link`, `author-avatar`, `network`, `body` FROM `item` + $r = q("SELECT `id`, `author-name`, `author-link`, `author-avatar`, `network`, `body`, `uid` FROM `item` WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 AND `id` = %d", $r[0]["parent"]); @@ -88,21 +88,22 @@ function display_fetchauthor($a, $item) { $profiledata["photo"] = proxy_url($item["author-avatar"]); $profiledata["url"] = $item["author-link"]; $profiledata["network"] = $item["network"]; + $profiledata["address"] = "Ort".print_r($item, true); - // Fetching profile data from unique contacts - // To-do: Extend "unique contacts" table for further contact data like location, ... - $r = q("SELECT `avatar`, `nick` FROM `unique_contacts` WHERE `url` = '%s'", normalise_link($profiledata["url"])); + // 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]["avatar"]); + $profiledata["photo"] = proxy_url($r[0]["photo"]); + $profiledata["address"] = $r[0]["location"]; + $profiledata["about"] = $r[0]["about"]; if ($r[0]["nick"] != "") $profiledata["nickname"] = $r[0]["nick"]; } else { - // Is this case possible? - // Fetching further contact data from the contact table, when it isn't available in the "unique contacts" - $r = q("SELECT `photo`, `nick` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d", - normalise_link($profiledata["url"]), $itemuid); + // Fetching profile data from unique contacts + $r = q("SELECT `avatar`, `nick` FROM `unique_contacts` WHERE `url` = '%s'", normalise_link($profiledata["url"])); if (count($r)) { - $profiledata["photo"] = proxy_url($r[0]["photo"]); + $profiledata["photo"] = proxy_url($r[0]["avatar"]); if ($r[0]["nick"] != "") $profiledata["nickname"] = $r[0]["nick"]; } diff --git a/view/templates/profile_vcard.tpl b/view/templates/profile_vcard.tpl index e72d25371d..9bbb7f8a42 100644 --- a/view/templates/profile_vcard.tpl +++ b/view/templates/profile_vcard.tpl @@ -35,6 +35,8 @@ {{if $homepage}}
{{$homepage}}
{{$profile.homepage}}
{{/if}} + {{if $about}}
{{$about}}
{{$profile.about}}
{{/if}} + {{include file="diaspora_vcard.tpl"}}