From 0e35427dfcc06ee00fcb0f6369a0b76a2db1cbff Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 15 Jun 2016 21:20:55 +0200 Subject: [PATCH 1/9] New fields "author-id" and "owner-id" in the item table --- boot.php | 2 +- database.sql | 4 +++- include/dbstructure.php | 2 ++ include/items.php | 6 ++++++ update.php | 2 +- 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/boot.php b/boot.php index 318a87346..62baf116d 100644 --- a/boot.php +++ b/boot.php @@ -38,7 +38,7 @@ define ( 'FRIENDICA_PLATFORM', 'Friendica'); define ( 'FRIENDICA_CODENAME', 'Asparagus'); define ( 'FRIENDICA_VERSION', '3.5-dev' ); define ( 'DFRN_PROTOCOL_VERSION', '2.23' ); -define ( 'DB_UPDATE_VERSION', 1196 ); +define ( 'DB_UPDATE_VERSION', 1197 ); /** * @brief Constant with a HTML line break. diff --git a/database.sql b/database.sql index 8269a8bba..275982d84 100644 --- a/database.sql +++ b/database.sql @@ -1,6 +1,6 @@ -- ------------------------------------------ -- Friendica 3.5-dev (Asparagus) --- DB_UPDATE_VERSION 1196 +-- DB_UPDATE_VERSION 1197 -- ------------------------------------------ @@ -458,9 +458,11 @@ CREATE TABLE IF NOT EXISTS `item` ( `commented` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `received` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `changed` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `owner-id` int(11) NOT NULL DEFAULT 0, `owner-name` varchar(255) NOT NULL DEFAULT '', `owner-link` varchar(255) NOT NULL DEFAULT '', `owner-avatar` varchar(255) NOT NULL DEFAULT '', + `author-id` int(11) NOT NULL DEFAULT 0, `author-name` varchar(255) NOT NULL DEFAULT '', `author-link` varchar(255) NOT NULL DEFAULT '', `author-avatar` varchar(255) NOT NULL DEFAULT '', diff --git a/include/dbstructure.php b/include/dbstructure.php index f89a3ff92..8ae3ae6c8 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -792,9 +792,11 @@ function db_definition() { "commented" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"), "received" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"), "changed" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"), + "owner-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "owner-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "owner-link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "owner-avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), + "author-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "author-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "author-link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "author-avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), diff --git a/include/items.php b/include/items.php index 203b7d0ee..f5e568306 100644 --- a/include/items.php +++ b/include/items.php @@ -584,6 +584,12 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa "photo" => $arr['author-avatar'], "name" => $arr['author-name'])); } + if ($arr["author-id"] == 0) + $arr["author-id"] = get_contact($arr["author-link"], 0); + + if ($arr["owner-id"] == 0) + $arr["owner-id"] = get_contact($arr["owner-link"], 0); + if ($arr['guid'] != "") { // Checking if there is already an item with the same guid logger('checking for an item for user '.$arr['uid'].' on network '.$arr['network'].' with the guid '.$arr['guid'], LOGGER_DEBUG); diff --git a/update.php b/update.php index 1189ac4a9..f2d790aa4 100644 --- a/update.php +++ b/update.php @@ -1,6 +1,6 @@ Date: Sun, 19 Jun 2016 01:07:20 +0200 Subject: [PATCH 2/9] Massively updated avatar handling --- include/Contact.php | 24 +++++++- include/bbcode.php | 11 +++- include/conversation.php | 126 +++++++++++++++++++++++++-------------- include/dbstructure.php | 2 + include/dfrn.php | 20 ++++--- include/threads.php | 6 +- mod/community.php | 12 ++-- mod/display.php | 14 +---- mod/network.php | 13 +--- mod/notes.php | 2 +- mod/profile.php | 6 +- mod/search.php | 16 ++--- object/Item.php | 25 +++++--- 13 files changed, 169 insertions(+), 108 deletions(-) diff --git a/include/Contact.php b/include/Contact.php index 86ef4a30f..896edaac7 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -451,8 +451,18 @@ function get_contact($url, $uid = 0) { $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; + if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA))) { + if ($uid != 0) + return 0; + + // Get data from the gcontact table + $r = q("SELECT `name`, `nick`, `url`, `photo`, `addr`, `alias`, `network` FROM `gcontact` WHERE `nurl` = '%s'", + dbesc(normalise_link($url))); + if (!$r) + return 0; + + $data = $r[0]; + } $url = $data["url"]; @@ -490,6 +500,16 @@ function get_contact($url, $uid = 0) { return 0; $contactid = $contact[0]["id"]; + + // Update the newly created contact from data in the gcontact table + $r = q("SELECT `location`, `about`, `keywords`, `gender` FROM `gcontact` WHERE `nurl` = '%s'", + dbesc(normalise_link($data["url"]))); + if ($r) { + logger("Update contact ".$data["url"]); + q("UPDATE `contact` SET `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `id` = %d", + dbesc($r["location"]), dbesc($r["about"]), dbesc($r["keywords"]), + dbesc($r["gender"]), intval($contactid)); + } } if ((count($contact) > 1) AND ($uid == 0) AND ($contactid != 0) AND ($url != "")) diff --git a/include/bbcode.php b/include/bbcode.php index 62f56558f..84425e8ef 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -408,6 +408,11 @@ function bb_ShareAttributes($share, $simplehtml) { if ($itemcache == "") $reldate = (($posted) ? " " . relative_date($posted) : ''); + // We only call this so that a previously unknown contact can be added. + // This is important for the function "get_contact_details_by_url". + // This function then can fetch an entry from the contact table. + get_contact($profile, 0); + $data = get_contact_details_by_url($profile); if (isset($data["name"]) AND isset($data["addr"])) @@ -423,8 +428,8 @@ function bb_ShareAttributes($share, $simplehtml) { if (isset($data["name"])) $author = $data["name"]; - if (isset($data["photo"])) - $avatar = $data["photo"]; + if (isset($data["thumb"])) + $avatar = $data["thumb"]; $preshare = trim($share[1]); @@ -490,6 +495,8 @@ function bb_ShareAttributes($share, $simplehtml) { default: $text = trim($share[1])."\n"; + $avatar = proxy_url($avatar, false, PROXY_SIZE_THUMB); + $tpl = get_markup_template('shared_content.tpl'); $text .= replace_macros($tpl, array( diff --git a/include/conversation.php b/include/conversation.php index 87ad42b04..411ffe388 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -373,15 +373,55 @@ function visible_activity($item) { return true; } +/** + * @brief SQL query for items + */ +function item_query() { + + return "SELECT ".item_fieldlists()." FROM `item` ". + item_joins()." WHERE ".item_condition(); +} + +/** + * @brief All fieldlists that are needed for the item query + */ +function item_fieldlists() { + + return item_fieldlist().", ".zcontact_fieldlist().", ".contact_fieldlist(); +} + +/** + * @brief SQL join for contacts + */ +function item_joins() { + + return contact_join()." ".zcontact_join(); +} + +/** + * @brief Fieldlist for author and owner + */ +function zcontact_fieldlist() { + + return "`author`.`thumb` AS `author-thumb`, `owner`.`thumb` AS `owner-thumb`"; +} + +/** + * @brief Join for author and owner + */ +function zcontact_join() { + + return "LEFT JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id` + LEFT JOIN `contact` AS `owner` ON `owner`.`id`=`item`.`author-id`"; +} + /** * @brief List of all contact fields that are needed for the conversation function */ function contact_fieldlist() { - $fieldlist = "`contact`.`network`, `contact`.`url`, `contact`.`name`, `contact`.`writable`, - `contact`.`self`, `contact`.`id` AS `cid`, `contact`.`alias`"; - - return $fieldlist; + return "`contact`.`network`, `contact`.`url`, `contact`.`name`, `contact`.`writable`, + `contact`.`self`, `contact`.`id` AS `cid`, `contact`.`alias`"; } /** @@ -389,9 +429,15 @@ function contact_fieldlist() { */ function contact_condition() { - $condition = "NOT `contact`.`blocked` AND NOT `contact`.`pending`"; + return "NOT `contact`.`blocked` AND NOT `contact`.`pending`"; +} - return $condition; +/** + * @brief SQL join for contacts + */ +function contact_join() { + + return "INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND ".contact_condition(); } /** @@ -402,11 +448,11 @@ function item_fieldlist() { /* These Fields are not added below (yet). They are here to for bug search. `item`.`type`, +`item`.`object`, `item`.`extid`, `item`.`received`, `item`.`changed`, -`item`.`author-avatar`, -`item`.`object`, +`item`.`moderated`, `item`.`target-type`, `item`.`target`, `item`.`resource-id`, @@ -414,10 +460,8 @@ These Fields are not added below (yet). They are here to for bug search. `item`.`attach`, `item`.`inform`, `item`.`pubmail`, -`item`.`moderated`, `item`.`visible`, `item`.`spam`, -`item`.`starred`, `item`.`bookmark`, `item`.`unseen`, `item`.`deleted`, @@ -430,18 +474,18 @@ These Fields are not added below (yet). They are here to for bug search. `item`.`shadow`, */ - $fieldlist = "`item`.`author-link`, `item`.`verb`, `item`.`id`, `item`.`parent`, `item`.`file`, - `item`.`uid`, `item`.`author-name`, `item`.`location`, `item`.`coord`, - `item`.`title`, `item`.`uri`, `item`.`created`, `item`.`app`, `item`.`guid`, - `item`.`contact-id`, `item`.`thr-parent`, `item`.`parent-uri`, `item`.`rendered-hash`, - `item`.`body`, `item`.`rendered-html`, `item`.`private`, `item`.`edited`, + return "`item`.`author-link`, `item`.`author-name`, `item`.`author-avatar`, + `item`.`owner-link`, `item`.`owner-name`, `item`.`owner-avatar`, + `item`.`contact-id`, `item`.`uid`, `item`.`id`, `item`.`parent`, + `item`.`uri`, `item`.`thr-parent`, `item`.`parent-uri`, + `item`.`commented`, `item`.`created`, `item`.`edited`, + `item`.`verb`, `item`.`object-type`, `item`.`postopts`, `item`.`plink`, + `item`.`guid`, `item`.`wall`, `item`.`private`, `item`.`starred`, + `item`.`title`, `item`.`body`, `item`.`file`, `item`.`event-id`, + `item`.`location`, `item`.`coord`, `item`.`app`, + `item`.`rendered-hash`, `item`.`rendered-html`, `item`.`allow_cid`, `item`.`allow_gid`, `item`.`deny_cid`, `item`.`deny_gid`, - `item`.`event-id`, `item`.`object-type`, `item`.`starred`, `item`.`created`, - `item`.`postopts`, `item`.`owner-link`, `item`.`owner-name`, `item`.`owner-avatar`, - `item`.`plink`, `item`.`wall`, `item`.`commented`, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`"; - - return $fieldlist; } /** @@ -449,9 +493,7 @@ These Fields are not added below (yet). They are here to for bug search. */ function item_condition() { - $condition = "`item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`"; - - return $condition; + return "`item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`"; } /** @@ -623,7 +665,6 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { $comment = ''; $owner_url = ''; - $owner_photo = ''; $owner_name = ''; $sparkle = ''; @@ -668,18 +709,6 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { $tags[] = $prefix."".$tag["term"].""; } - /*foreach(explode(',',$item['tag']) as $tag){ - $tag = trim($tag); - if ($tag!="") { - $t = bbcode($tag); - $tags[] = $t; - if($t[0] == '#') - $hashtags[] = $t; - elseif($t[0] == '@') - $mentions[] = $t; - } - }*/ - $sp = false; $profile_link = best_link_url($item,$sp); if($profile_link === 'mailbox') @@ -689,12 +718,21 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { else $profile_link = zrl($profile_link); - // Don't rely on the author-avatar. It is better to use the data from the contact table - $author_contact = get_contact_details_by_url($item['author-link'], $profile_owner); - if ($author_contact["thumb"]) - $profile_avatar = $author_contact["thumb"]; - else - $profile_avatar = $item['author-avatar']; + if (!isset($item['author-thumb'])) { + $author_contact = get_contact_details_by_url($item['author-link'], $profile_owner); + if ($author_contact["thumb"]) + $item['author-thumb'] = $author_contact["thumb"]; + else + $item['author-thumb'] = $item['author-avatar']; + } + + if (!isset($item['owner-thumb'])) { + $owner_contact = get_contact_details_by_url($item['owner-link'], $profile_owner); + if ($owner_contact["thumb"]) + $item['owner-thumb'] = $owner_contact["thumb"]; + else + $item['owner-thumb'] = $item['owner-avatar']; + } $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => ''); call_hooks('render_location',$locate); @@ -762,7 +800,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { 'name' => $profile_name_e, 'sparkle' => $sparkle, 'lock' => $lock, - 'thumb' => App::remove_baseurl(proxy_url($profile_avatar, false, PROXY_SIZE_THUMB)), + 'thumb' => App::remove_baseurl(proxy_url($item['author-thumb'], false, PROXY_SIZE_THUMB)), 'title' => $item['title_e'], 'body' => $body_e, 'tags' => $tags_e, @@ -781,7 +819,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { 'indent' => '', 'owner_name' => $owner_name_e, 'owner_url' => $owner_url, - 'owner_photo' => proxy_url($owner_photo, false, PROXY_SIZE_THUMB), + 'owner_photo' => App::remove_baseurl(proxy_url($item['owner-thumb'], false, PROXY_SIZE_THUMB)), 'plink' => get_plink($item), 'edpost' => false, 'isstarred' => $isstarred, diff --git a/include/dbstructure.php b/include/dbstructure.php index 8ae3ae6c8..549d077ed 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -1298,6 +1298,8 @@ function db_definition() { "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "contact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"), "gcontact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"), + "owner-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"), + "author-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"), "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"), "edited" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"), "commented" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"), diff --git a/include/dfrn.php b/include/dfrn.php index c9b907acc..9828763bf 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -1631,17 +1631,23 @@ class dfrn { $fields = array( 'owner-link' => array($old["url"], $relocate["url"]), 'author-link' => array($old["url"], $relocate["url"]), - 'owner-avatar' => array($old["photo"], $relocate["photo"]), - 'author-avatar' => array($old["photo"], $relocate["photo"]), + //'owner-avatar' => array($old["photo"], $relocate["photo"]), + //'author-avatar' => array($old["photo"], $relocate["photo"]), ); - foreach ($fields as $n=>$f){ - $x = q("UPDATE `item` SET `%s` = '%s' WHERE `%s` = '%s' AND `uid` = %d", - $n, dbesc($f[1]), + foreach ($fields as $n=>$f) { + $r = q("SELECT `id` FROM `item` WHERE `%s` = '%s' AND `uid` = %d LIMIT 1", $n, dbesc($f[0]), intval($importer["importer_uid"])); - if ($x === false) - return false; + + if ($r) { + $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 false; } + } /// @TODO /// merge with current record, current contents have priority diff --git a/include/threads.php b/include/threads.php index 0320eaa01..0b2b26e8d 100644 --- a/include/threads.php +++ b/include/threads.php @@ -1,7 +1,9 @@ profile['uid']), intval($item_id) ); + if(!$r && local_user()) { // Check if this is another person's link to a post that we have $r = q("SELECT `item`.uri FROM `item` @@ -385,13 +382,9 @@ function display_content(&$a, $update = 0) { if($r) { $item_uri = $r[0]['uri']; - $r = q("SELECT %s, %s FROM `item` - INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s - WHERE %s AND `item`.`uid` = %d + $r = q(item_query()." AND `item`.`uid` = %d AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `uri` = '%s' AND uid = %d) ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ", - item_fieldlist(), contact_fieldlist(), - contact_condition(), item_condition(), intval(local_user()), dbesc($item_uri), intval(local_user()) @@ -399,7 +392,6 @@ function display_content(&$a, $update = 0) { } } - if($r) { if((local_user()) && (local_user() == $a->profile['uid'])) { diff --git a/mod/network.php b/mod/network.php index ba97b4a4c..1ac732d11 100644 --- a/mod/network.php +++ b/mod/network.php @@ -720,14 +720,12 @@ function network_content(&$a, $update = 0) { $sql_order = "`item`.`received`"; // "New Item View" - show all items unthreaded in reverse created date order - $items = q("SELECT %s, %s FROM $sql_table $sql_post_table - INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s + $items = q("SELECT %s FROM $sql_table $sql_post_table %s WHERE %s AND `item`.`uid` = %d $simple_update $sql_extra $sql_nets ORDER BY $sql_order DESC $pager_sql ", - item_fieldlist(), contact_fieldlist(), - contact_condition(), item_condition(), + item_fieldlists(), item_joins(), item_condition(), intval($_SESSION['uid']) ); @@ -806,14 +804,9 @@ function network_content(&$a, $update = 0) { $items = array(); foreach ($parents_arr AS $parents) { -// $sql_extra ORDER BY `item`.`commented` DESC LIMIT %d", - $thread_items = q("SELECT %s, %s FROM `item` - INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s - WHERE %s AND `item`.`uid` = %d + $thread_items = q(item_query()." AND `item`.`uid` = %d AND `item`.`parent` = %d ORDER BY `item`.`commented` DESC LIMIT %d", - item_fieldlist(), contact_fieldlist(), - contact_condition(), item_condition(), intval(local_user()), intval($parents), intval($max_comments + 1) diff --git a/mod/notes.php b/mod/notes.php index 8d93fc13d..24d541be5 100644 --- a/mod/notes.php +++ b/mod/notes.php @@ -108,7 +108,7 @@ function notes_content(&$a,$update = false) { $parents_arr[] = $rr['item_id']; $parents_str = implode(', ', $parents_arr); - $r = q("SELECT %s, %s FROM `item` + $r = q("SELECT %s FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s WHERE %s AND `item`.`uid` = %d AND `item`.`parent` IN (%s) $sql_extra diff --git a/mod/profile.php b/mod/profile.php index 88de0227b..67db5d0d9 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -303,13 +303,9 @@ function profile_content(&$a, $update = 0) { $parents_arr[] = $rr['item_id']; $parents_str = implode(', ', $parents_arr); - $items = q("SELECT %s, %s FROM `item` - INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s - WHERE %s AND `item`.`uid` = %d + $items = q(item_query()." AND `item`.`uid` = %d AND `item`.`parent` IN (%s) $sql_extra ", - item_fieldlist(), contact_fieldlist(), - contact_condition(), item_condition(), intval($a->profile['profile_uid']), dbesc($parents_str) ); diff --git a/mod/search.php b/mod/search.php index 99ec6c5f7..d2251ce58 100644 --- a/mod/search.php +++ b/mod/search.php @@ -191,14 +191,12 @@ function search_content(&$a) { if($tag) { logger("Start tag search for '".$search."'", LOGGER_DEBUG); - $r = q("SELECT STRAIGHT_JOIN %s, %s + $r = q("SELECT STRAIGHT_JOIN %s FROM `term` - INNER JOIN `item` ON `item`.`id`=`term`.`oid` - INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s + INNER JOIN `item` ON `item`.`id`=`term`.`oid` %s WHERE %s AND (`term`.`uid` = 0 OR (`term`.`uid` = %d AND NOT `term`.`global`)) AND `term`.`otype` = %d AND `term`.`type` = %d AND `term`.`term` = '%s' ORDER BY term.created DESC LIMIT %d , %d ", - item_fieldlist(), contact_fieldlist(), - contact_condition(), item_condition(), + item_fieldlists(), item_joins(), item_condition(), intval(local_user()), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), dbesc(protect_sprintf($search)), intval($a->pager['start']), intval($a->pager['itemspage'])); @@ -211,14 +209,12 @@ function search_content(&$a) { $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search)))); } - $r = q("SELECT STRAIGHT_JOIN %s, %s - FROM `item` - INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s + $r = q("SELECT STRAIGHT_JOIN %s + FROM `item` %s WHERE %s AND (`item`.`uid` = 0 OR (`item`.`uid` = %s AND NOT `item`.`global`)) $sql_extra GROUP BY `item`.`uri` ORDER BY `item`.`id` DESC LIMIT %d , %d", - item_fieldlist(), contact_fieldlist(), - contact_condition(), item_condition(), + item_fieldlists(), item_joins(), item_condition(), intval(local_user()), intval($a->pager['start']), intval($a->pager['itemspage'])); } diff --git a/object/Item.php b/object/Item.php index ad3da4701..e6d6bd45f 100644 --- a/object/Item.php +++ b/object/Item.php @@ -150,12 +150,21 @@ class Item extends BaseObject { else $profile_link = zrl($profile_link); - // Don't rely on the author-avatar. It is better to use the data from the contact table - $author_contact = get_contact_details_by_url($item['author-link'], $conv->get_profile_owner()); - if ($author_contact["thumb"]) - $profile_avatar = $author_contact["thumb"]; - else - $profile_avatar = $item['author-avatar']; + if (!isset($item['author-thumb'])) { + $author_contact = get_contact_details_by_url($item['author-link'], $conv->get_profile_owner()); + if ($author_contact["thumb"]) + $item['author-thumb'] = $author_contact["thumb"]; + else + $item['author-thumb'] = $item['author-avatar']; + } + + if (!isset($item['owner-thumb'])) { + $owner_contact = get_contact_details_by_url($item['owner-link'], $conv->get_profile_owner()); + if ($owner_contact["thumb"]) + $item['owner-thumb'] = $owner_contact["thumb"]; + else + $item['owner-thumb'] = $item['owner-avatar']; + } $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => ''); call_hooks('render_location',$locate); @@ -364,7 +373,7 @@ class Item extends BaseObject { 'profile_url' => $profile_link, 'item_photo_menu' => item_photo_menu($item), 'name' => $name_e, - 'thumb' => $a->remove_baseurl(proxy_url($profile_avatar, false, PROXY_SIZE_THUMB)), + 'thumb' => $a->remove_baseurl(proxy_url($item['author-thumb'], false, PROXY_SIZE_THUMB)), 'osparkle' => $osparkle, 'sparkle' => $sparkle, 'title' => $title_e, @@ -377,7 +386,7 @@ class Item extends BaseObject { 'indent' => $indent, 'shiny' => $shiny, 'owner_url' => $this->get_owner_url(), - 'owner_photo' => proxy_url($this->get_owner_photo(), false, PROXY_SIZE_THUMB), + 'owner_photo' => $a->remove_baseurl(proxy_url($item['owner-thumb'], false, PROXY_SIZE_THUMB)), 'owner_name' => htmlentities($owner_name_e), 'plink' => get_plink($item), 'edpost' => ((feature_enabled($conv->get_profile_owner(),'edit_posts')) ? $edpost : ''), From c3ed6f7d0116dfc5a5a13ee5c88b75bb8c86a76c Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 19 Jun 2016 01:22:32 +0200 Subject: [PATCH 3/9] Improved default value handling --- include/Contact.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/include/Contact.php b/include/Contact.php index 896edaac7..3ee491e50 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -255,11 +255,20 @@ function get_contact_details_by_url($url, $uid = -1, $default = array()) { $profile["bd"] = (++$current_year)."-".$month."-".$day; } else $profile["bd"] = "0000-00-00"; - } else { + } else $profile = $default; - if (!isset($profile["thumb"]) AND isset($profile["photo"])) - $profile["thumb"] = $profile["photo"]; - } + + if (($profile["photo"] == "") AND isset($default["photo"])) + $profile["photo"] = $default["photo"]; + + if (($profile["name"] == "") AND isset($default["name"])) + $profile["name"] = $default["name"]; + + if (($profile["network"] == "") AND isset($default["network"])) + $profile["network"] = $default["network"]; + + if (!isset($profile["thumb"]) AND isset($profile["photo"])) + $profile["thumb"] = $profile["photo"]; if ((($profile["addr"] == "") OR ($profile["name"] == "")) AND ($profile["gid"] != 0) AND in_array($profile["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) From 91db7a549cdd50ea06ca0b53fc20369ad088141b Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 19 Jun 2016 08:32:38 +0200 Subject: [PATCH 4/9] Optimised the amount of function for the item query --- include/conversation.php | 103 +++++++++++---------------------------- mod/community.php | 13 ++--- mod/notes.php | 15 +++--- 3 files changed, 40 insertions(+), 91 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index 411ffe388..ffd9d45e2 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -383,68 +383,10 @@ function item_query() { } /** - * @brief All fieldlists that are needed for the item query + * @brief List of all data fields that are needed for displaying items */ function item_fieldlists() { - return item_fieldlist().", ".zcontact_fieldlist().", ".contact_fieldlist(); -} - -/** - * @brief SQL join for contacts - */ -function item_joins() { - - return contact_join()." ".zcontact_join(); -} - -/** - * @brief Fieldlist for author and owner - */ -function zcontact_fieldlist() { - - return "`author`.`thumb` AS `author-thumb`, `owner`.`thumb` AS `owner-thumb`"; -} - -/** - * @brief Join for author and owner - */ -function zcontact_join() { - - return "LEFT JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id` - LEFT JOIN `contact` AS `owner` ON `owner`.`id`=`item`.`author-id`"; -} - -/** - * @brief List of all contact fields that are needed for the conversation function - */ -function contact_fieldlist() { - - return "`contact`.`network`, `contact`.`url`, `contact`.`name`, `contact`.`writable`, - `contact`.`self`, `contact`.`id` AS `cid`, `contact`.`alias`"; -} - -/** - * @brief SQL condition for contacts - */ -function contact_condition() { - - return "NOT `contact`.`blocked` AND NOT `contact`.`pending`"; -} - -/** - * @brief SQL join for contacts - */ -function contact_join() { - - return "INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND ".contact_condition(); -} - -/** - * @brief List of all item fields that are needed for the conversation function - */ -function item_fieldlist() { - /* These Fields are not added below (yet). They are here to for bug search. `item`.`type`, @@ -475,21 +417,37 @@ These Fields are not added below (yet). They are here to for bug search. */ return "`item`.`author-link`, `item`.`author-name`, `item`.`author-avatar`, - `item`.`owner-link`, `item`.`owner-name`, `item`.`owner-avatar`, - `item`.`contact-id`, `item`.`uid`, `item`.`id`, `item`.`parent`, - `item`.`uri`, `item`.`thr-parent`, `item`.`parent-uri`, - `item`.`commented`, `item`.`created`, `item`.`edited`, - `item`.`verb`, `item`.`object-type`, `item`.`postopts`, `item`.`plink`, - `item`.`guid`, `item`.`wall`, `item`.`private`, `item`.`starred`, - `item`.`title`, `item`.`body`, `item`.`file`, `item`.`event-id`, - `item`.`location`, `item`.`coord`, `item`.`app`, - `item`.`rendered-hash`, `item`.`rendered-html`, - `item`.`allow_cid`, `item`.`allow_gid`, `item`.`deny_cid`, `item`.`deny_gid`, - `item`.`id` AS `item_id`, `item`.`network` AS `item_network`"; + `item`.`owner-link`, `item`.`owner-name`, `item`.`owner-avatar`, + `item`.`contact-id`, `item`.`uid`, `item`.`id`, `item`.`parent`, + `item`.`uri`, `item`.`thr-parent`, `item`.`parent-uri`, + `item`.`commented`, `item`.`created`, `item`.`edited`, + `item`.`verb`, `item`.`object-type`, `item`.`postopts`, `item`.`plink`, + `item`.`guid`, `item`.`wall`, `item`.`private`, `item`.`starred`, + `item`.`title`, `item`.`body`, `item`.`file`, `item`.`event-id`, + `item`.`location`, `item`.`coord`, `item`.`app`, + `item`.`rendered-hash`, `item`.`rendered-html`, + `item`.`allow_cid`, `item`.`allow_gid`, `item`.`deny_cid`, `item`.`deny_gid`, + `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, + + `author`.`thumb` AS `author-thumb`, `owner`.`thumb` AS `owner-thumb`, + + `contact`.`network`, `contact`.`url`, `contact`.`name`, `contact`.`writable`, + `contact`.`self`, `contact`.`id` AS `cid`, `contact`.`alias`"; } /** - * @brief SQL condition for items + * @brief SQL join for contacts that are needed for displaying items + */ +function item_joins() { + + return "STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND + NOT `contact`.`blocked` AND NOT `contact`.`pending` + LEFT JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id` + LEFT JOIN `contact` AS `owner` ON `owner`.`id`=`item`.`author-id`"; +} + +/** + * @brief SQL condition for items that are needed for displaying items */ function item_condition() { @@ -923,8 +881,6 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { function best_link_url($item,&$sparkle,$ssl_state = false) { - $a = get_app(); - $best_url = ''; $sparkle = false; @@ -951,7 +907,6 @@ function best_link_url($item,&$sparkle,$ssl_state = false) { if(! function_exists('item_photo_menu')){ function item_photo_menu($item){ - $a = get_app(); $ssl_state = false; diff --git a/mod/community.php b/mod/community.php index 535e7dc3f..06a96c740 100644 --- a/mod/community.php +++ b/mod/community.php @@ -120,18 +120,17 @@ function community_getitems($start, $itemspage) { if (get_config('system','community_page_style') == CP_GLOBAL_COMMUNITY) return(community_getpublicitems($start, $itemspage)); - $r = q("SELECT %s, %s, `user`.`nickname` + $r = q("SELECT %s FROM `thread` FORCE INDEX (`wall_private_received`) INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND NOT `user`.`hidewall` INNER JOIN `item` ON `item`.`id` = `thread`.`iid` AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' - INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` - AND %s AND `contact`.`self` + %s AND `contact`.`self` WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated` AND NOT `thread`.`private` AND `thread`.`wall` ORDER BY `thread`.`received` DESC LIMIT %d, %d", - item_fieldlist(), contact_fieldlist(), contact_condition(), + item_fieldlists(), item_joins(), intval($start), intval($itemspage) ); @@ -141,14 +140,12 @@ function community_getitems($start, $itemspage) { function community_getpublicitems($start, $itemspage) { - $r = q("SELECT %s, %s, `author-name` AS `name`, `owner-avatar` AS `photo`, - `owner-link` AS `url`, `owner-avatar` AS `thumb` + $r = q("SELECT %s FROM `thread` INNER JOIN `item` ON `item`.`id` = `thread`.`iid` %s WHERE `thread`.`uid` = 0 ORDER BY `thread`.`created` DESC LIMIT %d, %d", - item_fieldlist(), zcontact_fieldlist(), - zcontact_join(), + item_fieldlists(), item_joins(), intval($start), intval($itemspage) ); diff --git a/mod/notes.php b/mod/notes.php index 24d541be5..a25d090ed 100644 --- a/mod/notes.php +++ b/mod/notes.php @@ -73,11 +73,11 @@ function notes_content(&$a,$update = false) { $sql_extra = " AND `allow_cid` = '<" . $a->contact['id'] . ">' "; $r = q("SELECT COUNT(*) AS `total` - FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s + FROM `item` %s WHERE %s AND `item`.`uid` = %d AND `item`.`type` = 'note' AND `contact`.`self` AND `item`.`id` = `item`.`parent` AND NOT `item`.`wall` $sql_extra ", - contact_condition(), item_condition(), + item_joins(), item_condition(), intval(local_user()) ); @@ -87,13 +87,12 @@ function notes_content(&$a,$update = false) { $a->set_pager_itemspage(40); } - $r = q("SELECT `item`.`id` AS `item_id` FROM `item` - LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s AND `contact`.`self` + $r = q("SELECT `item`.`id` AS `item_id` FROM `item` %s WHERE %s AND `item`.`uid` = %d AND `item`.`type` = 'note' AND `item`.`id` = `item`.`parent` AND NOT `item`.`wall` $sql_extra ORDER BY `item`.`created` DESC LIMIT %d ,%d ", - contact_condition(), item_condition(), + item_joins(), item_condition(), intval(local_user()), intval($a->pager['start']), intval($a->pager['itemspage']) @@ -108,13 +107,11 @@ function notes_content(&$a,$update = false) { $parents_arr[] = $rr['item_id']; $parents_str = implode(', ', $parents_arr); - $r = q("SELECT %s FROM `item` - LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s + $r = q("SELECT %s FROM `item` %s WHERE %s AND `item`.`uid` = %d AND `item`.`parent` IN (%s) $sql_extra ORDER BY `parent` DESC, `gravity` ASC, `item`.`id` ASC ", - item_fieldlist(), contact_fieldlist(), - contact_condition(), item_condition(), + item_fieldlists(), item_joins(), item_condition(), intval(local_user()), dbesc($parents_str) ); From 0adff6f6b893bd7562547bb00021f358383f51ba Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 19 Jun 2016 20:01:25 +0200 Subject: [PATCH 5/9] Fix for author-thumb/owner-thumb - DFRN: Relocate stuff --- include/conversation.php | 2 +- include/dfrn.php | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index ffd9d45e2..c4d4fcdde 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -443,7 +443,7 @@ function item_joins() { return "STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND NOT `contact`.`blocked` AND NOT `contact`.`pending` LEFT JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id` - LEFT JOIN `contact` AS `owner` ON `owner`.`id`=`item`.`author-id`"; + LEFT JOIN `contact` AS `owner` ON `owner`.`id`=`item`.`owner-id`"; } /** diff --git a/include/dfrn.php b/include/dfrn.php index 9828763bf..9d91cbce7 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -369,6 +369,7 @@ class dfrn { xml::add_element($doc, $relocate, "dfrn:url", $owner['url']); xml::add_element($doc, $relocate, "dfrn:name", $owner['name']); xml::add_element($doc, $relocate, "dfrn:addr", $owner['addr']); + xml::add_element($doc, $relocate, "dfrn:avatar", $owner['avatar']); xml::add_element($doc, $relocate, "dfrn:photo", $photos[4]); xml::add_element($doc, $relocate, "dfrn:thumb", $photos[5]); xml::add_element($doc, $relocate, "dfrn:micro", $photos[6]); @@ -1548,6 +1549,7 @@ class dfrn { $relocate["url"] = $xpath->query("dfrn:url/text()", $relocation)->item(0)->nodeValue; $relocate["addr"] = $xpath->query("dfrn:addr/text()", $relocation)->item(0)->nodeValue; $relocate["name"] = $xpath->query("dfrn:name/text()", $relocation)->item(0)->nodeValue; + $relocate["avatar"] = $xpath->query("dfrn:avatar/text()", $relocation)->item(0)->nodeValue; $relocate["photo"] = $xpath->query("dfrn:photo/text()", $relocation)->item(0)->nodeValue; $relocate["thumb"] = $xpath->query("dfrn:thumb/text()", $relocation)->item(0)->nodeValue; $relocate["micro"] = $xpath->query("dfrn:micro/text()", $relocation)->item(0)->nodeValue; @@ -1557,6 +1559,9 @@ class dfrn { $relocate["poll"] = $xpath->query("dfrn:poll/text()", $relocation)->item(0)->nodeValue; $relocate["sitepubkey"] = $xpath->query("dfrn:sitepubkey/text()", $relocation)->item(0)->nodeValue; + if (($relocate["avatar"] == "") AND ($relocate["photo"] != "")) + $relocate["avatar"] = $relocate["photo"]; + if ($relocate["addr"] == "") $relocate["addr"] = preg_replace("=(https?://)(.*)/profile/(.*)=ism", "$3@$2", $relocate["url"]); @@ -1583,7 +1588,7 @@ class dfrn { `server_url` = '%s' WHERE `nurl` = '%s';", dbesc($relocate["name"]), - dbesc($relocate["photo"]), + dbesc($relocate["avatar"]), dbesc($relocate["url"]), dbesc(normalise_link($relocate["url"])), dbesc($relocate["addr"]), @@ -1595,9 +1600,7 @@ class dfrn { // Update the contact table. We try to find every entry. $x = q("UPDATE `contact` SET `name` = '%s', - `photo` = '%s', - `thumb` = '%s', - `micro` = '%s', + `avatar` = '%s', `url` = '%s', `nurl` = '%s', `addr` = '%s', @@ -1608,9 +1611,7 @@ class dfrn { `site-pubkey` = '%s' WHERE (`id` = %d AND `uid` = %d) OR (`nurl` = '%s');", dbesc($relocate["name"]), - dbesc($relocate["photo"]), - dbesc($relocate["thumb"]), - dbesc($relocate["micro"]), + dbesc($relocate["avatar"]), dbesc($relocate["url"]), dbesc(normalise_link($relocate["url"])), dbesc($relocate["addr"]), @@ -1623,6 +1624,8 @@ class dfrn { intval($importer["importer_uid"]), dbesc(normalise_link($old["url"]))); + update_contact_avatar($relocate["avatar"], $importer["importer_uid"], $importer["id"], true); + if ($x === false) return false; From 51b5d16f1b3384552e1f060cf9c5305c989fa54c Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 19 Jun 2016 21:41:06 +0200 Subject: [PATCH 6/9] Improved SQL queries --- mod/network.php | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/mod/network.php b/mod/network.php index 1ac732d11..6d30797fe 100644 --- a/mod/network.php +++ b/mod/network.php @@ -682,8 +682,8 @@ function network_content(&$a, $update = 0) { if(get_config('system', 'old_pager')) { $r = q("SELECT COUNT(*) AS `total` FROM $sql_table $sql_post_table INNER JOIN `contact` ON `contact`.`id` = $sql_table.`contact-id` - AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 - WHERE $sql_table.`uid` = %d AND $sql_table.`visible` = 1 AND $sql_table.`deleted` = 0 + AND NOT `contact`.`blocked` AND NOT `contact`.`pending` + WHERE $sql_table.`uid` = %d AND $sql_table.`visible` AND NOT $sql_table.`deleted` $sql_extra2 $sql_extra3 $sql_extra $sql_nets ", intval($_SESSION['uid']) @@ -714,7 +714,7 @@ function network_content(&$a, $update = 0) { } if($nouveau) { - $simple_update = (($update) ? " AND `item`.`unseen` = 1 " : ''); + $simple_update = (($update) ? " AND `item`.`unseen` " : ''); if ($sql_order == "") $sql_order = "`item`.`received`"; @@ -753,28 +753,26 @@ function network_content(&$a, $update = 0) { // Fetch a page full of parent items for this page if($update) { - if (!get_config("system", "like_no_comment")) - $sql_extra4 = "(`item`.`deleted` = 0 - OR `item`.`verb` = '".ACTIVITY_LIKE."' OR `item`.`verb` = '".ACTIVITY_DISLIKE."' - OR `item`.`verb` = '".ACTIVITY_ATTEND."' OR `item`.`verb` = '".ACTIVITY_ATTENDNO."' - OR `item`.`verb` = '".ACTIVITY_ATTENDMAYBE."')"; + if (get_config("system", "like_no_comment")) + $sql_extra4 = " AND `item`.`verb` = '".ACTIVITY_POST."'"; else - $sql_extra4 = "`item`.`deleted` = 0 AND `item`.`verb` = '".ACTIVITY_POST."'"; + $sql_extra4 = ""; $r = q("SELECT `item`.`parent` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid` FROM $sql_table $sql_post_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 - WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND $sql_extra4 - AND `item`.`moderated` = 0 AND `item`.`unseen` = 1 - $sql_extra3 $sql_extra $sql_nets ORDER BY `item_id` DESC LIMIT 100", + AND NOT `contact`.`blocked` AND NOT `contact`.`pending` + WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` $sql_extra4 + AND NOT `item`.`moderated` AND `item`.`unseen` + $sql_extra3 $sql_extra $sql_nets + ORDER BY `item_id` DESC LIMIT 100", intval(local_user()) ); } else { $r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid` FROM $sql_table $sql_post_table STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` - AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 - WHERE `thread`.`uid` = %d AND `thread`.`visible` = 1 AND `thread`.`deleted` = 0 - AND `thread`.`moderated` = 0 + AND NOT `contact`.`blocked` AND NOT `contact`.`pending` + WHERE `thread`.`uid` = %d AND `thread`.`visible` AND NOT `thread`.`deleted` + AND NOT `thread`.`moderated` $sql_extra2 $sql_extra3 $sql_extra $sql_nets ORDER BY $sql_order DESC $pager_sql ", intval(local_user()) From 140886a6a50307ffa527a0f1b2650c40e7c2bf36 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 20 Jun 2016 06:29:56 +0200 Subject: [PATCH 7/9] Updated database.sql --- database.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/database.sql b/database.sql index 275982d84..4a36384d9 100644 --- a/database.sql +++ b/database.sql @@ -964,6 +964,8 @@ CREATE TABLE IF NOT EXISTS `thread` ( `uid` int(10) unsigned NOT NULL DEFAULT 0, `contact-id` int(11) unsigned NOT NULL DEFAULT 0, `gcontact-id` int(11) unsigned NOT NULL DEFAULT 0, + `owner-id` int(11) unsigned NOT NULL DEFAULT 0, + `author-id` int(11) unsigned NOT NULL DEFAULT 0, `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `edited` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `commented` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', From 939bd965c5702baa13099a878a261b8243076d6b Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 20 Jun 2016 22:03:40 +0200 Subject: [PATCH 8/9] Search query optimized --- mod/search.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mod/search.php b/mod/search.php index d2251ce58..a83725999 100644 --- a/mod/search.php +++ b/mod/search.php @@ -191,9 +191,9 @@ function search_content(&$a) { if($tag) { logger("Start tag search for '".$search."'", LOGGER_DEBUG); - $r = q("SELECT STRAIGHT_JOIN %s + $r = q("SELECT %s FROM `term` - INNER JOIN `item` ON `item`.`id`=`term`.`oid` %s + STRAIGHT_JOIN `item` ON `item`.`id`=`term`.`oid` %s WHERE %s AND (`term`.`uid` = 0 OR (`term`.`uid` = %d AND NOT `term`.`global`)) AND `term`.`otype` = %d AND `term`.`type` = %d AND `term`.`term` = '%s' ORDER BY term.created DESC LIMIT %d , %d ", item_fieldlists(), item_joins(), item_condition(), @@ -209,7 +209,8 @@ function search_content(&$a) { $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search)))); } - $r = q("SELECT STRAIGHT_JOIN %s + + $r = q("SELECT %s FROM `item` %s WHERE %s AND (`item`.`uid` = 0 OR (`item`.`uid` = %s AND NOT `item`.`global`)) $sql_extra From 9a7653a4feafc191e449e0d33915b3083122d38d Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 21 Jun 2016 07:54:45 +0200 Subject: [PATCH 9/9] Store the author-id and owner-id in mod/item.php as well --- mod/item.php | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/mod/item.php b/mod/item.php index d0e1ffed5..6f5f8fc1e 100644 --- a/mod/item.php +++ b/mod/item.php @@ -25,6 +25,7 @@ require_once('include/text.php'); require_once('include/items.php'); require_once('include/Scrape.php'); require_once('include/diaspora.php'); +require_once('include/Contact.php'); function item_post(&$a) { @@ -676,9 +677,11 @@ function item_post(&$a) { $datarray['owner-name'] = $contact_record['name']; $datarray['owner-link'] = $contact_record['url']; $datarray['owner-avatar'] = $contact_record['thumb']; + $datarray["owner-id"] = get_contact($datarray["owner-link"], 0); $datarray['author-name'] = $author['name']; $datarray['author-link'] = $author['url']; $datarray['author-avatar'] = $author['thumb']; + $datarray["author-id"] = get_contact($datarray["author-link"], 0); $datarray['created'] = datetime_convert(); $datarray['edited'] = datetime_convert(); $datarray['commented'] = datetime_convert(); @@ -711,6 +714,7 @@ function item_post(&$a) { $datarray['moderated'] = $allow_moderated; $datarray['gcontact-id'] = get_gcontact_id(array("url" => $datarray['author-link'], "network" => $datarray['network'], "photo" => $datarray['author-avatar'], "name" => $datarray['author-name'])); + /** * These fields are for the convenience of plugins... * 'self' if true indicates the owner is posting on their own wall @@ -790,10 +794,24 @@ function item_post(&$a) { $post_id = 0; - $r = q("INSERT INTO `item` (`guid`, `extid`, `uid`,`type`,`wall`,`gravity`, `network`, `contact-id`,`owner-name`,`owner-link`,`owner-avatar`, `author-name`, `author-link`, `author-avatar`, - `created`, `edited`, `commented`, `received`, `changed`, `uri`, `thr-parent`, `title`, `body`, `app`, `location`, `coord`, `tag`, `inform`, `verb`, `object-type`, `postopts`, - `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `private`, `pubmail`, `attach`, `bookmark`,`origin`, `moderated`, `file`, `rendered-html`, `rendered-hash`) - VALUES( '%s', '%s', %d, '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, %d, '%s', '%s', '%s')", + $r = q("INSERT INTO `item` (`guid`, `extid`, `uid`,`type`,`wall`,`gravity`, `network`, `contact-id`, + `owner-name`,`owner-link`,`owner-avatar`, `owner-id`, + `author-name`, `author-link`, `author-avatar`, `author-id`, + `created`, `edited`, `commented`, `received`, `changed`, + `uri`, `thr-parent`, `title`, `body`, `app`, `location`, `coord`, + `tag`, `inform`, `verb`, `object-type`, `postopts`, + `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `private`, + `pubmail`, `attach`, `bookmark`,`origin`, `moderated`, `file`, + `rendered-html`, `rendered-hash`) + VALUES('%s', '%s', %d, '%s', %d, %d, '%s', %d, + '%s', '%s', '%s', %d, + '%s', '%s', '%s', %d, + '%s', '%s', '%s', '%s', '%s', + '%s', '%s', '%s', '%s', '%s', '%s', '%s', + '%s', '%s', '%s', '%s', '%s', + '%s', '%s', '%s', '%s', %d, + %d, '%s', %d, %d, %d, '%s', + '%s', '%s')", dbesc($datarray['guid']), dbesc($datarray['extid']), intval($datarray['uid']), @@ -805,9 +823,11 @@ function item_post(&$a) { dbesc($datarray['owner-name']), dbesc($datarray['owner-link']), dbesc($datarray['owner-avatar']), + intval($datarray['owner-id']), dbesc($datarray['author-name']), dbesc($datarray['author-link']), dbesc($datarray['author-avatar']), + intval($datarray['author-id']), dbesc($datarray['created']), dbesc($datarray['edited']), dbesc($datarray['commented']),