Massively updated avatar handling

This commit is contained in:
Michael Vogel 2016-06-19 01:07:20 +02:00
parent 8762fb671f
commit e512a83ecc
13 changed files with 169 additions and 108 deletions

View file

@ -451,8 +451,18 @@ function get_contact($url, $uid = 0) {
$data = probe_url($url); $data = probe_url($url);
// Does this address belongs to a valid network? // Does this address belongs to a valid network?
if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA))) if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA))) {
return 0; 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"]; $url = $data["url"];
@ -490,6 +500,16 @@ function get_contact($url, $uid = 0) {
return 0; return 0;
$contactid = $contact[0]["id"]; $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 != "")) if ((count($contact) > 1) AND ($uid == 0) AND ($contactid != 0) AND ($url != ""))

View file

@ -408,6 +408,11 @@ function bb_ShareAttributes($share, $simplehtml) {
if ($itemcache == "") if ($itemcache == "")
$reldate = (($posted) ? " " . relative_date($posted) : ''); $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); $data = get_contact_details_by_url($profile);
if (isset($data["name"]) AND isset($data["addr"])) if (isset($data["name"]) AND isset($data["addr"]))
@ -423,8 +428,8 @@ function bb_ShareAttributes($share, $simplehtml) {
if (isset($data["name"])) if (isset($data["name"]))
$author = $data["name"]; $author = $data["name"];
if (isset($data["photo"])) if (isset($data["thumb"]))
$avatar = $data["photo"]; $avatar = $data["thumb"];
$preshare = trim($share[1]); $preshare = trim($share[1]);
@ -490,6 +495,8 @@ function bb_ShareAttributes($share, $simplehtml) {
default: default:
$text = trim($share[1])."\n"; $text = trim($share[1])."\n";
$avatar = proxy_url($avatar, false, PROXY_SIZE_THUMB);
$tpl = get_markup_template('shared_content.tpl'); $tpl = get_markup_template('shared_content.tpl');
$text .= replace_macros($tpl, $text .= replace_macros($tpl,
array( array(

View file

@ -373,15 +373,55 @@ function visible_activity($item) {
return true; 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 * @brief List of all contact fields that are needed for the conversation function
*/ */
function contact_fieldlist() { function contact_fieldlist() {
$fieldlist = "`contact`.`network`, `contact`.`url`, `contact`.`name`, `contact`.`writable`, return "`contact`.`network`, `contact`.`url`, `contact`.`name`, `contact`.`writable`,
`contact`.`self`, `contact`.`id` AS `cid`, `contact`.`alias`"; `contact`.`self`, `contact`.`id` AS `cid`, `contact`.`alias`";
return $fieldlist;
} }
/** /**
@ -389,9 +429,15 @@ function contact_fieldlist() {
*/ */
function contact_condition() { 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. These Fields are not added below (yet). They are here to for bug search.
`item`.`type`, `item`.`type`,
`item`.`object`,
`item`.`extid`, `item`.`extid`,
`item`.`received`, `item`.`received`,
`item`.`changed`, `item`.`changed`,
`item`.`author-avatar`, `item`.`moderated`,
`item`.`object`,
`item`.`target-type`, `item`.`target-type`,
`item`.`target`, `item`.`target`,
`item`.`resource-id`, `item`.`resource-id`,
@ -414,10 +460,8 @@ These Fields are not added below (yet). They are here to for bug search.
`item`.`attach`, `item`.`attach`,
`item`.`inform`, `item`.`inform`,
`item`.`pubmail`, `item`.`pubmail`,
`item`.`moderated`,
`item`.`visible`, `item`.`visible`,
`item`.`spam`, `item`.`spam`,
`item`.`starred`,
`item`.`bookmark`, `item`.`bookmark`,
`item`.`unseen`, `item`.`unseen`,
`item`.`deleted`, `item`.`deleted`,
@ -430,18 +474,18 @@ These Fields are not added below (yet). They are here to for bug search.
`item`.`shadow`, `item`.`shadow`,
*/ */
$fieldlist = "`item`.`author-link`, `item`.`verb`, `item`.`id`, `item`.`parent`, `item`.`file`, return "`item`.`author-link`, `item`.`author-name`, `item`.`author-avatar`,
`item`.`uid`, `item`.`author-name`, `item`.`location`, `item`.`coord`, `item`.`owner-link`, `item`.`owner-name`, `item`.`owner-avatar`,
`item`.`title`, `item`.`uri`, `item`.`created`, `item`.`app`, `item`.`guid`, `item`.`contact-id`, `item`.`uid`, `item`.`id`, `item`.`parent`,
`item`.`contact-id`, `item`.`thr-parent`, `item`.`parent-uri`, `item`.`rendered-hash`, `item`.`uri`, `item`.`thr-parent`, `item`.`parent-uri`,
`item`.`body`, `item`.`rendered-html`, `item`.`private`, `item`.`edited`, `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`.`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`"; `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() { function item_condition() {
$condition = "`item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`"; return "`item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`";
return $condition;
} }
/** /**
@ -623,7 +665,6 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
$comment = ''; $comment = '';
$owner_url = ''; $owner_url = '';
$owner_photo = '';
$owner_name = ''; $owner_name = '';
$sparkle = ''; $sparkle = '';
@ -668,18 +709,6 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
$tags[] = $prefix."<a href=\"".$tag["url"]."\" target=\"_blank\">".$tag["term"]."</a>"; $tags[] = $prefix."<a href=\"".$tag["url"]."\" target=\"_blank\">".$tag["term"]."</a>";
} }
/*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; $sp = false;
$profile_link = best_link_url($item,$sp); $profile_link = best_link_url($item,$sp);
if($profile_link === 'mailbox') if($profile_link === 'mailbox')
@ -689,12 +718,21 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
else else
$profile_link = zrl($profile_link); $profile_link = zrl($profile_link);
// Don't rely on the author-avatar. It is better to use the data from the contact table if (!isset($item['author-thumb'])) {
$author_contact = get_contact_details_by_url($item['author-link'], $profile_owner); $author_contact = get_contact_details_by_url($item['author-link'], $profile_owner);
if ($author_contact["thumb"]) if ($author_contact["thumb"])
$profile_avatar = $author_contact["thumb"]; $item['author-thumb'] = $author_contact["thumb"];
else else
$profile_avatar = $item['author-avatar']; $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' => ''); $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
call_hooks('render_location',$locate); call_hooks('render_location',$locate);
@ -762,7 +800,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
'name' => $profile_name_e, 'name' => $profile_name_e,
'sparkle' => $sparkle, 'sparkle' => $sparkle,
'lock' => $lock, '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'], 'title' => $item['title_e'],
'body' => $body_e, 'body' => $body_e,
'tags' => $tags_e, 'tags' => $tags_e,
@ -781,7 +819,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
'indent' => '', 'indent' => '',
'owner_name' => $owner_name_e, 'owner_name' => $owner_name_e,
'owner_url' => $owner_url, '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), 'plink' => get_plink($item),
'edpost' => false, 'edpost' => false,
'isstarred' => $isstarred, 'isstarred' => $isstarred,

View file

@ -1298,6 +1298,8 @@ function db_definition() {
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"contact-id" => array("type" => "int(11) 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"), "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"), "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"), "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"), "commented" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),

View file

@ -1631,17 +1631,23 @@ class dfrn {
$fields = array( $fields = array(
'owner-link' => array($old["url"], $relocate["url"]), 'owner-link' => array($old["url"], $relocate["url"]),
'author-link' => array($old["url"], $relocate["url"]), 'author-link' => array($old["url"], $relocate["url"]),
'owner-avatar' => array($old["photo"], $relocate["photo"]), //'owner-avatar' => array($old["photo"], $relocate["photo"]),
'author-avatar' => array($old["photo"], $relocate["photo"]), //'author-avatar' => array($old["photo"], $relocate["photo"]),
); );
foreach ($fields as $n=>$f){ foreach ($fields as $n=>$f) {
$x = q("UPDATE `item` SET `%s` = '%s' WHERE `%s` = '%s' AND `uid` = %d", $r = q("SELECT `id` FROM `item` WHERE `%s` = '%s' AND `uid` = %d LIMIT 1",
$n, dbesc($f[1]),
$n, dbesc($f[0]), $n, dbesc($f[0]),
intval($importer["importer_uid"])); 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 /// @TODO
/// merge with current record, current contents have priority /// merge with current record, current contents have priority

View file

@ -1,7 +1,9 @@
<?php <?php
function add_thread($itemid, $onlyshadow = false) { function add_thread($itemid, $onlyshadow = false) {
$items = q("SELECT `uid`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, `gcontact-id`, $items = q("SELECT `uid`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`,
`deleted`, `origin`, `forum_mode`, `mention`, `network` FROM `item` WHERE `id` = %d AND (`parent` = %d OR `parent` = 0) LIMIT 1", intval($itemid), intval($itemid)); `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, `gcontact-id`,
`deleted`, `origin`, `forum_mode`, `mention`, `network`, `author-id`, `owner-id`
FROM `item` WHERE `id` = %d AND (`parent` = %d OR `parent` = 0) LIMIT 1", intval($itemid), intval($itemid));
if (!$items) if (!$items)
return; return;

View file

@ -131,8 +131,7 @@ function community_getitems($start, $itemspage) {
WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated` WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
AND NOT `thread`.`private` AND `thread`.`wall` AND NOT `thread`.`private` AND `thread`.`wall`
ORDER BY `thread`.`received` DESC LIMIT %d, %d", ORDER BY `thread`.`received` DESC LIMIT %d, %d",
item_fieldlist(), contact_fieldlist(), item_fieldlist(), contact_fieldlist(), contact_condition(),
contact_condition(),
intval($start), intval($itemspage) intval($start), intval($itemspage)
); );
@ -142,14 +141,15 @@ function community_getitems($start, $itemspage) {
function community_getpublicitems($start, $itemspage) { function community_getpublicitems($start, $itemspage) {
$r = q("SELECT %s, `author-name` AS `name`, `owner-avatar` AS `photo`, $r = q("SELECT %s, %s, `author-name` AS `name`, `owner-avatar` AS `photo`,
`owner-link` AS `url`, `owner-avatar` AS `thumb` `owner-link` AS `url`, `owner-avatar` AS `thumb`
FROM `thread` FROM `thread`
INNER JOIN `item` ON `item`.`id` = `thread`.`iid` INNER JOIN `item` ON `item`.`id` = `thread`.`iid` %s
WHERE `thread`.`uid` = 0 WHERE `thread`.`uid` = 0
ORDER BY `thread`.`created` DESC LIMIT %d, %d", ORDER BY `thread`.`created` DESC LIMIT %d, %d",
item_fieldlist(), intval($start), item_fieldlist(), zcontact_fieldlist(),
intval($itemspage) zcontact_join(),
intval($start), intval($itemspage)
); );
return($r); return($r);

View file

@ -362,18 +362,15 @@ function display_content(&$a, $update = 0) {
return ''; return '';
} }
$r = q("SELECT %s, %s FROM `item` $r = q(item_query()." AND `item`.`uid` = %d
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s
WHERE %s AND `item`.`uid` = %d
AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `id` = %d) AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `id` = %d)
$sql_extra $sql_extra
ORDER BY `parent` DESC, `gravity` ASC, `id` ASC", ORDER BY `parent` DESC, `gravity` ASC, `id` ASC",
item_fieldlist(), contact_fieldlist(),
contact_condition(), item_condition(),
intval($a->profile['uid']), intval($a->profile['uid']),
intval($item_id) intval($item_id)
); );
if(!$r && local_user()) { if(!$r && local_user()) {
// Check if this is another person's link to a post that we have // Check if this is another person's link to a post that we have
$r = q("SELECT `item`.uri FROM `item` $r = q("SELECT `item`.uri FROM `item`
@ -385,13 +382,9 @@ function display_content(&$a, $update = 0) {
if($r) { if($r) {
$item_uri = $r[0]['uri']; $item_uri = $r[0]['uri'];
$r = q("SELECT %s, %s FROM `item` $r = q(item_query()." AND `item`.`uid` = %d
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s
WHERE %s AND `item`.`uid` = %d
AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `uri` = '%s' AND uid = %d) AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `uri` = '%s' AND uid = %d)
ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ", ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ",
item_fieldlist(), contact_fieldlist(),
contact_condition(), item_condition(),
intval(local_user()), intval(local_user()),
dbesc($item_uri), dbesc($item_uri),
intval(local_user()) intval(local_user())
@ -399,7 +392,6 @@ function display_content(&$a, $update = 0) {
} }
} }
if($r) { if($r) {
if((local_user()) && (local_user() == $a->profile['uid'])) { if((local_user()) && (local_user() == $a->profile['uid'])) {

View file

@ -720,14 +720,12 @@ function network_content(&$a, $update = 0) {
$sql_order = "`item`.`received`"; $sql_order = "`item`.`received`";
// "New Item View" - show all items unthreaded in reverse created date order // "New Item View" - show all items unthreaded in reverse created date order
$items = q("SELECT %s, %s FROM $sql_table $sql_post_table $items = q("SELECT %s FROM $sql_table $sql_post_table %s
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s
WHERE %s AND `item`.`uid` = %d WHERE %s AND `item`.`uid` = %d
$simple_update $simple_update
$sql_extra $sql_nets $sql_extra $sql_nets
ORDER BY $sql_order DESC $pager_sql ", ORDER BY $sql_order DESC $pager_sql ",
item_fieldlist(), contact_fieldlist(), item_fieldlists(), item_joins(), item_condition(),
contact_condition(), item_condition(),
intval($_SESSION['uid']) intval($_SESSION['uid'])
); );
@ -806,14 +804,9 @@ function network_content(&$a, $update = 0) {
$items = array(); $items = array();
foreach ($parents_arr AS $parents) { foreach ($parents_arr AS $parents) {
// $sql_extra ORDER BY `item`.`commented` DESC LIMIT %d", $thread_items = q(item_query()." AND `item`.`uid` = %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
AND `item`.`parent` = %d AND `item`.`parent` = %d
ORDER BY `item`.`commented` DESC LIMIT %d", ORDER BY `item`.`commented` DESC LIMIT %d",
item_fieldlist(), contact_fieldlist(),
contact_condition(), item_condition(),
intval(local_user()), intval(local_user()),
intval($parents), intval($parents),
intval($max_comments + 1) intval($max_comments + 1)

View file

@ -108,7 +108,7 @@ function notes_content(&$a,$update = false) {
$parents_arr[] = $rr['item_id']; $parents_arr[] = $rr['item_id'];
$parents_str = implode(', ', $parents_arr); $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 LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s
WHERE %s AND `item`.`uid` = %d AND `item`.`parent` IN (%s) WHERE %s AND `item`.`uid` = %d AND `item`.`parent` IN (%s)
$sql_extra $sql_extra

View file

@ -303,13 +303,9 @@ function profile_content(&$a, $update = 0) {
$parents_arr[] = $rr['item_id']; $parents_arr[] = $rr['item_id'];
$parents_str = implode(', ', $parents_arr); $parents_str = implode(', ', $parents_arr);
$items = q("SELECT %s, %s FROM `item` $items = q(item_query()." AND `item`.`uid` = %d
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s
WHERE %s AND `item`.`uid` = %d
AND `item`.`parent` IN (%s) AND `item`.`parent` IN (%s)
$sql_extra ", $sql_extra ",
item_fieldlist(), contact_fieldlist(),
contact_condition(), item_condition(),
intval($a->profile['profile_uid']), intval($a->profile['profile_uid']),
dbesc($parents_str) dbesc($parents_str)
); );

View file

@ -191,14 +191,12 @@ function search_content(&$a) {
if($tag) { if($tag) {
logger("Start tag search for '".$search."'", LOGGER_DEBUG); logger("Start tag search for '".$search."'", LOGGER_DEBUG);
$r = q("SELECT STRAIGHT_JOIN %s, %s $r = q("SELECT STRAIGHT_JOIN %s
FROM `term` FROM `term`
INNER JOIN `item` ON `item`.`id`=`term`.`oid` INNER JOIN `item` ON `item`.`id`=`term`.`oid` %s
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %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' 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 ", ORDER BY term.created DESC LIMIT %d , %d ",
item_fieldlist(), contact_fieldlist(), item_fieldlists(), item_joins(), item_condition(),
contact_condition(), item_condition(),
intval(local_user()), intval(local_user()),
intval(TERM_OBJ_POST), intval(TERM_HASHTAG), dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), dbesc(protect_sprintf($search)),
intval($a->pager['start']), intval($a->pager['itemspage'])); 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)))); $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
} }
$r = q("SELECT STRAIGHT_JOIN %s, %s $r = q("SELECT STRAIGHT_JOIN %s
FROM `item` FROM `item` %s
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s
WHERE %s AND (`item`.`uid` = 0 OR (`item`.`uid` = %s AND NOT `item`.`global`)) WHERE %s AND (`item`.`uid` = 0 OR (`item`.`uid` = %s AND NOT `item`.`global`))
$sql_extra $sql_extra
GROUP BY `item`.`uri` ORDER BY `item`.`id` DESC LIMIT %d , %d", GROUP BY `item`.`uri` ORDER BY `item`.`id` DESC LIMIT %d , %d",
item_fieldlist(), contact_fieldlist(), item_fieldlists(), item_joins(), item_condition(),
contact_condition(), item_condition(),
intval(local_user()), intval(local_user()),
intval($a->pager['start']), intval($a->pager['itemspage'])); intval($a->pager['start']), intval($a->pager['itemspage']));
} }

View file

@ -150,12 +150,21 @@ class Item extends BaseObject {
else else
$profile_link = zrl($profile_link); $profile_link = zrl($profile_link);
// Don't rely on the author-avatar. It is better to use the data from the contact table if (!isset($item['author-thumb'])) {
$author_contact = get_contact_details_by_url($item['author-link'], $conv->get_profile_owner()); $author_contact = get_contact_details_by_url($item['author-link'], $conv->get_profile_owner());
if ($author_contact["thumb"]) if ($author_contact["thumb"])
$profile_avatar = $author_contact["thumb"]; $item['author-thumb'] = $author_contact["thumb"];
else else
$profile_avatar = $item['author-avatar']; $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' => ''); $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
call_hooks('render_location',$locate); call_hooks('render_location',$locate);
@ -364,7 +373,7 @@ class Item extends BaseObject {
'profile_url' => $profile_link, 'profile_url' => $profile_link,
'item_photo_menu' => item_photo_menu($item), 'item_photo_menu' => item_photo_menu($item),
'name' => $name_e, '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, 'osparkle' => $osparkle,
'sparkle' => $sparkle, 'sparkle' => $sparkle,
'title' => $title_e, 'title' => $title_e,
@ -377,7 +386,7 @@ class Item extends BaseObject {
'indent' => $indent, 'indent' => $indent,
'shiny' => $shiny, 'shiny' => $shiny,
'owner_url' => $this->get_owner_url(), '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), 'owner_name' => htmlentities($owner_name_e),
'plink' => get_plink($item), 'plink' => get_plink($item),
'edpost' => ((feature_enabled($conv->get_profile_owner(),'edit_posts')) ? $edpost : ''), 'edpost' => ((feature_enabled($conv->get_profile_owner(),'edit_posts')) ? $edpost : ''),