Merge pull request #2602 from annando/1606-item-query-cleanup

Some item query cleanup
This commit is contained in:
rabuzarus 2016-06-13 09:27:21 +02:00 committed by GitHub
commit 08d5975105
11 changed files with 132 additions and 110 deletions

View file

@ -1309,7 +1309,7 @@
$r = q("SELECT STRAIGHT_JOIN `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
`contact`.`id` AS `cid`
FROM `item`, `contact`
WHERE `item`.`uid` = %d AND `verb` = '%s'
AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
@ -1388,7 +1388,7 @@
$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`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`,
`contact`.`id` AS `cid`,
`user`.`nickname`, `user`.`hidewall`
FROM `item` STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
STRAIGHT_JOIN `user` ON `user`.`uid` = `item`.`uid`
@ -1457,7 +1457,7 @@
$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`.`dfrn-id`, `contact`.`self`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
`contact`.`id` AS `cid`
FROM `item`, `contact`
WHERE `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
AND `contact`.`id` = `item`.`contact-id` AND `item`.`uid` = %d AND `item`.`verb` = '%s'
@ -1534,7 +1534,7 @@
$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`.`dfrn-id`, `contact`.`self`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
`contact`.`id` AS `cid`
FROM `item`
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `item`.`parent` = %d AND `item`.`visible`
@ -1586,7 +1586,7 @@
$r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`nick` as `reply_author`,
`contact`.`name`, `contact`.`photo` as `reply_photo`, `contact`.`url` as `reply_url`, `contact`.`rel`,
`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
`contact`.`id` AS `cid`
FROM `item`, `contact`
WHERE `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
AND `contact`.`id` = `item`.`contact-id`
@ -1699,7 +1699,7 @@
$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`.`dfrn-id`, `contact`.`self`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
`contact`.`id` AS `cid`
FROM `item` FORCE INDEX (`uid_id`), `contact`
WHERE `item`.`uid` = %d AND `verb` = '%s'
AND NOT (`item`.`author-link` IN ('https://%s', 'http://%s'))
@ -1776,7 +1776,7 @@
$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`.`dfrn-id`, `contact`.`self`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
`contact`.`id` AS `cid`
FROM `item`, `contact`
WHERE `item`.`uid` = %d AND `verb` = '%s'
AND `item`.`contact-id` = %d
@ -1904,7 +1904,7 @@
$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`.`dfrn-id`, `contact`.`self`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
`contact`.`id` AS `cid`
FROM `item`, `contact`
WHERE `item`.`uid` = %d
AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0

View file

@ -373,6 +373,55 @@ function visible_activity($item) {
return true;
}
/**
* @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;
}
/**
* @brief SQL condition for contacts
*/
function contact_condition() {
$condition = "NOT `contact`.`blocked` AND NOT `contact`.`pending`";
return $condition;
}
/**
* @brief List of all item fields that are needed for the conversation function
*/
function item_fieldlist() {
$fieldlist = "`item`.`author-link`, `item`.`verb`, `item`.`id`, `item`.`parent`,
`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`,
`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`.`id` AS `item_id`, `item`.`network` AS `item_network`";
return $fieldlist;
}
/**
* @brief SQL condition for items
*/
function item_condition() {
$condition = "`item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`";
return $condition;
}
/**
* "Render" a conversation or list of items for HTML display.

View file

@ -197,7 +197,6 @@ class dfrn {
`contact`.`name`, `contact`.`network`, `contact`.`photo`, `contact`.`url`,
`contact`.`name-date`, `contact`.`uri-date`, `contact`.`avatar-date`,
`contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
`contact`.`id` AS `contact-id`, `contact`.`uid` AS `contact-uid`,
`sign`.`signed_text`, `sign`.`signature`, `sign`.`signer`
FROM `item` $sql_post_table
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`

View file

@ -114,7 +114,9 @@ load_translation_table($lang);
*
*/
$stamp1 = microtime(true);
session_start();
$a->save_timestamp($stamp1, "parser");
/**
* Language was set earlier, but we can over-ride it in the session.

View file

@ -120,23 +120,20 @@ function community_getitems($start, $itemspage) {
if (get_config('system','community_page_style') == CP_GLOBAL_COMMUNITY)
return(community_getpublicitems($start, $itemspage));
$r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`,
`contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`,
`user`.`nickname`, `user`.`hidewall`
$r = q("SELECT %s, %s, `user`.`nickname`
FROM `thread` FORCE INDEX (`wall_private_received`)
INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND `user`.`hidewall` = 0
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 `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`self`
WHERE `thread`.`visible` = 1 AND `thread`.`deleted` = 0 and `thread`.`moderated` = 0
AND `thread`.`private` = 0 AND `thread`.`wall` = 1
AND %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",
intval($start),
intval($itemspage)
item_fieldlist(), contact_fieldlist(),
contact_condition(),
intval($start), intval($itemspage)
);
return($r);
@ -144,14 +141,14 @@ function community_getitems($start, $itemspage) {
}
function community_getpublicitems($start, $itemspage) {
$r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
`author-name` AS `name`, `owner-avatar` AS `photo`,
$r = q("SELECT %s, `author-name` AS `name`, `owner-avatar` AS `photo`,
`owner-link` AS `url`, `owner-avatar` AS `thumb`
FROM `thread`
INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
WHERE `thread`.`uid` = 0
ORDER BY `thread`.`created` DESC LIMIT %d, %d",
intval($start),
item_fieldlist(), intval($start),
intval($itemspage)
);

View file

@ -217,7 +217,7 @@ function content_content(&$a, $update = 0) {
$items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
`contact`.`id` AS `cid`
FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `item`.`uid` = %d AND `item`.`visible` = 1
AND `item`.`deleted` = 0 and `item`.`moderated` = 0
@ -268,7 +268,7 @@ function content_content(&$a, $update = 0) {
$items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`writable`,
`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
`contact`.`id` AS `cid`
FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
AND `item`.`moderated` = 0

View file

@ -362,17 +362,14 @@ function display_content(&$a, $update = 0) {
return '';
}
$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`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted`
AND NOT `item`.`moderated`
$r = 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` = (SELECT `parent` FROM `item` WHERE `id` = %d)
$sql_extra
ORDER BY `parent` DESC, `gravity` ASC, `id` ASC",
item_fieldlist(), contact_fieldlist(),
contact_condition(), item_condition(),
intval($a->profile['uid']),
intval($item_id)
);
@ -388,16 +385,13 @@ function display_content(&$a, $update = 0) {
if($r) {
$item_uri = $r[0]['uri'];
$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`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted`
AND NOT `item`.`moderated`
$r = 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` = (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())

View file

@ -720,17 +720,14 @@ 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 `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
`contact`.`id` AS `cid`, `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 `item`.`deleted` = 0 AND `item`.`moderated` = 0
$items = q("SELECT %s, %s FROM $sql_table $sql_post_table
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %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(),
intval($_SESSION['uid'])
);
@ -810,16 +807,13 @@ function network_content(&$a, $update = 0) {
foreach ($parents_arr AS $parents) {
// $sql_extra ORDER BY `item`.`commented` DESC LIMIT %d",
$thread_items = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`writable`,
`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
`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
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
AND `item`.`moderated` = 0
$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
ORDER BY `item`.`commented` DESC LIMIT %d",
item_fieldlist(), contact_fieldlist(),
contact_condition(), item_condition(),
intval(local_user()),
intval($parents),
intval($max_comments + 1)

View file

@ -73,12 +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`
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 and `item`.`moderated` = 0
AND `item`.`deleted` = 0 AND `item`.`type` = 'note'
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`self` = 1
AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 0
FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %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(),
intval(local_user())
);
@ -88,14 +87,13 @@ function notes_content(&$a,$update = false) {
$a->set_pager_itemspage(40);
}
$r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact-uid`
FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
and `item`.`moderated` = 0 AND `item`.`type` = 'note'
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`self` = 1
AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 0
$r = q("SELECT `item`.`id` AS `item_id` FROM `item`
LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND %s AND `contact`.`self`
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(),
intval(local_user()),
intval($a->pager['start']),
intval($a->pager['itemspage'])
@ -110,16 +108,13 @@ function notes_content(&$a,$update = false) {
$parents_arr[] = $rr['item_id'];
$parents_str = implode(', ', $parents_arr);
$r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`network`, `contact`.`rel`,
`contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
AND `item`.`parent` IN ( %s )
$r = q("SELECT %s, %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
ORDER BY `parent` DESC, `gravity` ASC, `item`.`id` ASC ",
item_fieldlist(), contact_fieldlist(),
contact_condition(), item_condition(),
intval(local_user()),
dbesc($parents_str)
);

View file

@ -216,8 +216,7 @@ function profile_content(&$a, $update = 0) {
if($update) {
$r = q("SELECT distinct(parent) AS `item_id`, `item`.`network` AS `item_network`,
`contact`.`uid` AS `contact-uid`
$r = q("SELECT distinct(parent) AS `item_id`, `item`.`network` AS `item_network`
FROM `item` 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
@ -282,8 +281,7 @@ function profile_content(&$a, $update = 0) {
$pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
$r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network`,
`thread`.`uid` AS `contact-uid`
$r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network`
FROM `thread` FORCE INDEX (`uid_created`) INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
$sql_post_table INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
@ -305,17 +303,13 @@ function profile_content(&$a, $update = 0) {
$parents_arr[] = $rr['item_id'];
$parents_str = implode(', ', $parents_arr);
$items = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`network`, `contact`.`rel`,
`contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
FROM `item`, `contact`
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
and `item`.`moderated` = 0
AND `contact`.`id` = `item`.`contact-id`
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
$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` IN (%s)
$sql_extra ",
item_fieldlist(), contact_fieldlist(),
contact_condition(), item_condition(),
intval($a->profile['profile_uid']),
dbesc($parents_str)
);

View file

@ -191,17 +191,16 @@ function search_content(&$a) {
if($tag) {
logger("Start tag search for '".$search."'", LOGGER_DEBUG);
$r = q("SELECT STRAIGHT_JOIN `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`,
`contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
$r = q("SELECT STRAIGHT_JOIN %s, %s
FROM `term`
INNER JOIN `item` ON `item`.`id`=`term`.`oid`
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
AND (`term`.`uid` = 0 OR (`term`.`uid` = %d AND NOT `term`.`global`)) AND `term`.`otype` = %d AND `term`.`type` = %d AND `term`.`term` = '%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'
ORDER BY term.created DESC LIMIT %d , %d ",
intval(local_user()), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), dbesc(protect_sprintf($search)),
item_fieldlist(), contact_fieldlist(),
contact_condition(), item_condition(),
intval(local_user()),
intval(TERM_OBJ_POST), intval(TERM_HASHTAG), dbesc(protect_sprintf($search)),
intval($a->pager['start']), intval($a->pager['itemspage']));
} else {
logger("Start fulltext search for '".$search."'", LOGGER_DEBUG);
@ -212,17 +211,16 @@ function search_content(&$a) {
$sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
}
$r = q("SELECT STRAIGHT_JOIN `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`,
`contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
$r = q("SELECT STRAIGHT_JOIN %s, %s
FROM `item`
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
AND (`item`.`uid` = 0 OR (`item`.`uid` = %s AND NOT `item`.`global`))
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`))
$sql_extra
GROUP BY `item`.`uri` ORDER BY `item`.`id` DESC LIMIT %d , %d",
intval(local_user()), intval($a->pager['start']), intval($a->pager['itemspage']));
item_fieldlist(), contact_fieldlist(),
contact_condition(), item_condition(),
intval(local_user()),
intval($a->pager['start']), intval($a->pager['itemspage']));
}
if(! count($r)) {