From 26807c782bfc13fd6c446bb8260e83b97db7ce8f Mon Sep 17 00:00:00 2001 From: garvinhicking Date: Wed, 19 Oct 2005 13:24:01 +0000 Subject: [PATCH] fetch entryproperties in search results --- docs/NEWS | 3 ++ include/functions_entries.inc.php | 66 +++++++++++++++++++------------ 2 files changed, 43 insertions(+), 26 deletions(-) diff --git a/docs/NEWS b/docs/NEWS index c86bbe7..a92642c 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -3,6 +3,9 @@ Version 0.9-beta3 () ------------------------------------------------------------------------ + * Also fetch and display entryproperties in the results of a search. + Fixes bug #1329379 (garvinhicking) + * Fix some dreaded "only variables can be returned by referenced" PHP 4.4 notices on some minor occasions (garvinhicking) diff --git a/include/functions_entries.inc.php b/include/functions_entries.inc.php index 7080b31..1233fdc 100644 --- a/include/functions_entries.inc.php +++ b/include/functions_entries.inc.php @@ -286,39 +286,48 @@ function serendipity_fetchEntries($range = null, $full = true, $limit = '', $fet // First code for this was sending 15 queries for 15 fetched entries, // this is now limited to just one query per fetched articles group - $search_ids = array(); // An array to hold all ids of the entry we want to fetch. - $assoc_ids = array(); // A temporary key association container to not have to loop through the return array once again. + serendipity_fetchEntryData($ret); + } - foreach($ret AS $i => $entry) { - $search_ids[] = $entry['id']; - $ret[$i]['categories'] = array(); // make sure every article gets its category association - $assoc_ids[$entry['id']] = $i; // store temporary reference - } + return $ret; +} - serendipity_plugin_api::hook_event('frontend_entryproperties', $ret, $assoc_ids); +/** + * Attach special entry data to entry + */ +function serendipity_fetchEntryData(&$ret) { + global $serendipity; - $query = "SELECT - ec.entryid, - c.categoryid, - c.category_name, - c.category_description, - c.category_icon, - c.parentid - FROM {$serendipity['dbPrefix']}category AS c - LEFT JOIN {$serendipity['dbPrefix']}entrycat AS ec - ON ec.categoryid = c.categoryid - WHERE " . serendipity_db_in_sql('ec.entryid', $search_ids); + $search_ids = array(); // An array to hold all ids of the entry we want to fetch. + $assoc_ids = array(); // A temporary key association container to not have to loop through the return array once again. + + foreach($ret AS $i => $entry) { + $search_ids[] = $entry['id']; + $ret[$i]['categories'] = array(); // make sure every article gets its category association + $assoc_ids[$entry['id']] = $i; // store temporary reference + } - $search_ret = serendipity_db_query($query, false, 'assoc'); + serendipity_plugin_api::hook_event('frontend_entryproperties', $ret, $assoc_ids); - if (is_array($search_ret)) { - foreach($search_ret AS $i => $entry) { - $ret[$assoc_ids[$entry['entryid']]]['categories'][] = $entry; - } + $query = "SELECT + ec.entryid, + c.categoryid, + c.category_name, + c.category_description, + c.category_icon, + c.parentid + FROM {$serendipity['dbPrefix']}category AS c + LEFT JOIN {$serendipity['dbPrefix']}entrycat AS ec + ON ec.categoryid = c.categoryid + WHERE " . serendipity_db_in_sql('ec.entryid', $search_ids); + + $search_ret = serendipity_db_query($query, false, 'assoc'); + + if (is_array($search_ret)) { + foreach($search_ret AS $i => $entry) { + $ret[$assoc_ids[$entry['entryid']]]['categories'][] = $entry; } } - - return $ret; } /** @@ -573,6 +582,11 @@ function serendipity_searchEntries($term, $limit = '') { $limit"; $search = serendipity_db_query($querystring); + + if (is_array($search)) { + serendipity_fetchEntryData($search); + } + return $search; } -- 2.39.5