1.1 --- a/system/classes/listfactory.class.php Sun Oct 25 22:01:38 2009 +0000
1.2 +++ b/system/classes/listfactory.class.php Sun Oct 25 23:15:27 2009 +0000
1.3 @@ -47,15 +47,15 @@
1.4 // Set up the fields that will be seen by the user
1.5 $obj->setField(
1.6 '#', // Title of the field
1.7 - ROW_NUMBER, // The field identifier can be either:
1.8 - // ROW_NUMBER - The number of each row will be displayed
1.9 - // SQL_TITLE - The title given the the SQL query will be displayed
1.10 + LF_ROW_NUMBER, // The field identifier can be either:
1.11 + // LF_ROW_NUMBER - The number of each row will be displayed
1.12 + // LF_SOURCE_TITLE - The title given the the SQL query will be displayed
1.13 // <string> - SQL column name
1.14 true, // Enables the field
1.15 true, // The field can be sorted
1.16 '<b>%d.</b>' // Formats the data
1.17 );
1.18 - $obj->setField('Type', SQL_TITLE, true, true, '<b>%s</b>');
1.19 + $obj->setField('Type', LF_SOURCE_TITLE, true, true, '<b>%s</b>');
1.20 $obj->setField('Title', 'title');
1.21 $obj->setField('Text', 'text');
1.22 $obj->setField('Date', 'date');
1.23 @@ -72,7 +72,7 @@
1.24 // Set up some queries to execute
1.25 $sql = 'SELECT sid AS id, title, introtext AS text, date FROM stories';
1.26 $obj->setQuery(
1.27 - 'Story', // The name given to the query which will be displayed in the SQL_TITLE field (optional)
1.28 + 'Story', // The name given to the query which will be displayed in the LF_SOURCE_TITLE field (optional)
1.29 'story',
1.30 $sql, // The SQL string without the LIMIT or ORDER BY clauses. Notice the column names match the field identifiers
1.31 5 // The rank of the query, 5 highest = more results, 1 lowest = least results
1.32 @@ -84,7 +84,7 @@
1.33 // Note: the array must match the field identifier names stated previously
1.34 $extra_row = array(
1.35 'id' => -1,
1.36 - SQL_TITLE => 'Extra Row',
1.37 + LF_SOURCE_TITLE => 'Extra Row',
1.38 'title' => 'An extra row example',
1.39 'text' => 'With some really really really long text.....<b>and HTML</b>',
1.40 'date' => '2008-07-08 03:00:00'
1.41 @@ -132,7 +132,7 @@
1.42
1.43 // PRIVATE VARIABLES
1.44 var $_fields = array();
1.45 - var $_query_arr = array();
1.46 + var $_sources_arr = array();
1.47 var $_total_rank = 0;
1.48 var $_sort_arr = array();
1.49 var $_def_sort_arr = array();
1.50 @@ -148,7 +148,7 @@
1.51 * Constructor
1.52 *
1.53 * Sets up private url variable and defines the
1.54 - * SQL_TITLE, SQL_NAME and ROW_NUMBER constants.
1.55 + * LF_SOURCE_TITLE, LF_SOURCE_NAME and LF_ROW_NUMBER constants.
1.56 *
1.57 * @access public
1.58 * @param string $url The URL of the page the table appears on
1.59 @@ -171,9 +171,9 @@
1.60 $this->_page_limits = array(10, 15, 20, 25, 30, 35);
1.61 }
1.62
1.63 - define('SQL_TITLE', 0);
1.64 - define('SQL_NAME', 1);
1.65 - define('ROW_NUMBER', 2);
1.66 + define('LF_SOURCE_TITLE', 0);
1.67 + define('LF_SOURCE_NAME', 1);
1.68 + define('LF_ROW_NUMBER', 2);
1.69 }
1.70
1.71 /**
1.72 @@ -191,7 +191,7 @@
1.73 /**
1.74 * Sets a field in the list.
1.75 *
1.76 - * Note: ROW_NUMBER cannot be sorted
1.77 + * Note: LF_ROW_NUMBER cannot be sorted
1.78 *
1.79 * @access public
1.80 * @param string $title The title of the field which is displayed to the user
1.81 @@ -203,7 +203,7 @@
1.82 */
1.83 function setField( $title, $name, $display = true, $sort = true, $format = '%s' )
1.84 {
1.85 - if ($name === ROW_NUMBER) {
1.86 + if ($name === LF_ROW_NUMBER) {
1.87 $sort = false;
1.88 }
1.89 $this->_fields[] = array(
1.90 @@ -227,7 +227,7 @@
1.91 */
1.92 function setQuery( $title, $name, $sql, $rank )
1.93 {
1.94 - $this->_query_arr[] = array(
1.95 + $this->_sources_arr[] = array(
1.96 'type' => 'sql',
1.97 'title' => $title,
1.98 'name' => $name,
1.99 @@ -237,13 +237,30 @@
1.100 $this->_total_rank += $rank;
1.101 }
1.102
1.103 - function setCallback( $title, $name, $function, $rank, $total )
1.104 + /**
1.105 + * Sets a callback function that provides another source for results.
1.106 + *
1.107 + * The function will be passed two parameters, $offset and $limit,
1.108 + * which will determine how many results are requested. The callback
1.109 + * function should then return a multidimensional array containing
1.110 + * the results. This provides an alternative to the setQuery()
1.111 + * function as results can be sourced from anywhere.
1.112 + *
1.113 + * @access public
1.114 + * @param string $title The text that's displayed to the user
1.115 + * @param string $name The local name given to the query
1.116 + * @param string $function Any callable function, method or lambda
1.117 + * @param int $rank The rating that determins how many results will be returned
1.118 + * @param int $total The total number of results that are avaliable
1.119 + *
1.120 + */
1.121 + function setCallback( $title, $name, $callback, $rank, $total )
1.122 {
1.123 - $this->_query_arr[] = array(
1.124 + $this->_sources_arr[] = array(
1.125 'type' => 'callback',
1.126 'title' => $title,
1.127 'name' => $name,
1.128 - 'func' => $function,
1.129 + 'func' => $callback,
1.130 'rank' => $rank,
1.131 'total' => $total
1.132 );
1.133 @@ -251,7 +268,8 @@
1.134 }
1.135
1.136 /**
1.137 - * Sets the callback function that gets called when formatting a row
1.138 + * Sets the callback function thats called on every row for styling
1.139 + * or formatting.
1.140 *
1.141 * @access public
1.142 * @param callback $function Any callable function, method or lambda
1.143 @@ -300,20 +318,21 @@
1.144 }
1.145
1.146 /**
1.147 - * Gets the total number of results from a query
1.148 + * Gets the total number of results from source item, either an sql
1.149 + * query or a callback function.
1.150 *
1.151 * @access private
1.152 - * @param string $sql The query
1.153 + * @param array $source The source we are currently working with
1.154 * @return int Total number of rows
1.155 *
1.156 */
1.157 - function _getTotal( $param )
1.158 + function _getTotal( $source )
1.159 {
1.160 - if ($param['type'] == 'callback') {
1.161 - return $param['total'];
1.162 + if ($source['type'] == 'callback') {
1.163 + return $source['total'];
1.164 }
1.165 else {
1.166 - $sql = $param['sql'];
1.167 + $sql = $source['sql'];
1.168 }
1.169
1.170 if (is_array($sql)) {
1.171 @@ -382,6 +401,42 @@
1.172 }
1.173
1.174 /**
1.175 + * Applies styling to each row and adds extra meta details that are
1.176 + * used else where in the ListFactory.
1.177 + *
1.178 + * @access private
1.179 + * @param array $row_arr A single results row
1.180 + * @param array $source The source we are currently working with
1.181 + * @return array The row with styling applied and extra meta details
1.182 + *
1.183 + */
1.184 + function _fillrow( $row_arr, $source )
1.185 + {
1.186 + $col = array();
1.187 + $col[LF_SOURCE_TITLE] = $source['title'];
1.188 + $col[LF_SOURCE_NAME] = $source['name'];
1.189 +
1.190 + foreach ($this->_fields as $field)
1.191 + {
1.192 + if (!is_numeric($field['name']) && $field['name'][0] != '_') {
1.193 + if (empty($row_arr[ $field['name'] ])) {
1.194 + $col[ $field['name'] ] = 'LF_NULL';
1.195 + } else {
1.196 + $col[ $field['name'] ] = $row_arr[ $field['name'] ];
1.197 + }
1.198 + }
1.199 + }
1.200 +
1.201 + // Need to call the format function before and after
1.202 + // sorting the results.
1.203 + if (is_callable($this->_function)) {
1.204 + $col = call_user_func_array($this->_function, array(true, $col));
1.205 + }
1.206 +
1.207 + return $col;
1.208 + }
1.209 +
1.210 + /**
1.211 * Executes pre set queries
1.212 *
1.213 * @access public
1.214 @@ -400,7 +455,7 @@
1.215 if (is_numeric($this->_sort_arr['field']))
1.216 {
1.217 $ord = $this->_def_sort_arr['field'];
1.218 - $this->_sort_arr['field'] = SQL_TITLE;
1.219 + $this->_sort_arr['field'] = LF_SOURCE_TITLE;
1.220 }
1.221 else
1.222 {
1.223 @@ -424,10 +479,10 @@
1.224 $num_query_results = $this->_per_page - $this->_total_found;
1.225 $pp_total = $this->_total_found;
1.226 $limits = array();
1.227 - for ($i = 0; $i < count($this->_query_arr); $i++)
1.228 + for ($i = 0; $i < count($this->_sources_arr); $i++)
1.229 {
1.230 - $limits[$i]['total'] = $this->_getTotal($this->_query_arr[$i]);
1.231 - $limits[$i]['pp'] = round(($this->_query_arr[$i]['rank'] / $this->_total_rank) * $num_query_results);
1.232 + $limits[$i]['total'] = $this->_getTotal($this->_sources_arr[$i]);
1.233 + $limits[$i]['pp'] = round(($this->_sources_arr[$i]['rank'] / $this->_total_rank) * $num_query_results);
1.234 $this->_total_found += $limits[$i]['total'];
1.235 $pp_total += $limits[$i]['pp'];
1.236 }
1.237 @@ -438,45 +493,30 @@
1.238 }
1.239 $limits = $this->_getLimits($limits);
1.240
1.241 - // Execute each query in turn
1.242 - for ($i = 0; $i < count($this->_query_arr); $i++)
1.243 + // Retrieve the results from each source in turn
1.244 + for ($i = 0; $i < count($this->_sources_arr); $i++)
1.245 {
1.246 if ($limits[$i]['limit'] <= 0) {
1.247 continue;
1.248 }
1.249
1.250 // This is a callback function
1.251 - if ($this->_query_arr[$i]['type'] == 'callback')
1.252 + if ($this->_sources_arr[$i]['type'] == 'callback')
1.253 {
1.254 - if (is_callable($this->_query_arr[$i]['func']))
1.255 + if (is_callable($this->_sources_arr[$i]['func']))
1.256 {
1.257 - $callback_rows = call_user_func_array($this->_query_arr[$i]['func'], array($limits[$i]['offset'], $limits[$i]['limit']));
1.258 + $callback_rows = call_user_func_array(
1.259 + $this->_sources_arr[$i]['func'],
1.260 + array($limits[$i]['offset'],
1.261 + $limits[$i]['limit'])
1.262 + );
1.263
1.264 - foreach ($callback_rows as $row)
1.265 - {
1.266 - $col = array();
1.267 - $col[SQL_TITLE] = $this->_query_arr[$i]['title'];
1.268 - $col[SQL_NAME] = $this->_query_arr[$i]['name'];
1.269 -
1.270 - foreach ($this->_fields as $field)
1.271 - {
1.272 - if (!is_numeric($field['name']) && $field['name'][0] != '_') {
1.273 - if (empty($row[ $field['name'] ])) {
1.274 - $col[ $field['name'] ] = 'LF_NULL';
1.275 - } else {
1.276 - $col[ $field['name'] ] = $row[ $field['name'] ];
1.277 - }
1.278 - }
1.279 - }
1.280 -
1.281 - // Need to call the format function before and after
1.282 - // sorting the results.
1.283 - if (is_callable($this->_function)) {
1.284 - $col = call_user_func_array($this->_function, array(true, $col));
1.285 - }
1.286 -
1.287 - $rows_arr[] = $col;
1.288 + foreach ($callback_rows as $row) {
1.289 + $rows_arr[] = $this->_fillrow($row, $this->_sources_arr[$i]);
1.290 }
1.291 + } else {
1.292 + COM_errorLog('ListFactory: A callback function was set for "'.
1.293 + $this->_sources_arr[$i]['name'].'", but it could not be found.');
1.294 }
1.295 continue;
1.296 }
1.297 @@ -484,42 +524,16 @@
1.298 // This is an SQL query, so execute it and format the results
1.299 $limit_sql = " LIMIT {$limits[$i]['offset']},{$limits[$i]['limit']}";
1.300
1.301 - if (is_array($this->_query_arr[$i]['sql']))
1.302 - {
1.303 - $this->_query_arr[$i]['sql']['mysql'] .= $order_sql . $limit_sql;
1.304 - $this->_query_arr[$i]['sql']['mssql'] .= $order_sql . $limit_sql;
1.305 - }
1.306 - else
1.307 - {
1.308 - $this->_query_arr[$i]['sql'] .= $order_sql . $limit_sql;
1.309 + if (is_array($this->_sources_arr[$i]['sql'])) {
1.310 + $this->_sources_arr[$i]['sql']['mysql'] .= $order_sql . $limit_sql;
1.311 + $this->_sources_arr[$i]['sql']['mssql'] .= $order_sql . $limit_sql;
1.312 + } else {
1.313 + $this->_sources_arr[$i]['sql'] .= $order_sql . $limit_sql;
1.314 }
1.315
1.316 - $result = DB_query($this->_query_arr[$i]['sql']);
1.317 -
1.318 - while ($A = DB_fetchArray($result))
1.319 - {
1.320 - $col = array();
1.321 - $col[SQL_TITLE] = $this->_query_arr[$i]['title'];
1.322 - $col[SQL_NAME] = $this->_query_arr[$i]['name'];
1.323 -
1.324 - foreach ($this->_fields as $field)
1.325 - {
1.326 - if (!is_numeric($field['name']) && $field['name'][0] != '_') {
1.327 - if (empty($A[ $field['name'] ])) {
1.328 - $col[ $field['name'] ] = 'LF_NULL';
1.329 - } else {
1.330 - $col[ $field['name'] ] = $A[ $field['name'] ];
1.331 - }
1.332 - }
1.333 - }
1.334 -
1.335 - // Need to call the format function before and after
1.336 - // sorting the results.
1.337 - if (is_callable($this->_function)) {
1.338 - $col = call_user_func_array($this->_function, array(true, $col));
1.339 - }
1.340 -
1.341 - $rows_arr[] = $col;
1.342 + $result = DB_query($this->_sources_arr[$i]['sql']);
1.343 + while ($A = DB_fetchArray($result)) {
1.344 + $rows_arr[] = $this->_fillrow($A, $this->_sources_arr[$i]);
1.345 }
1.346 }
1.347
1.348 @@ -686,7 +700,7 @@
1.349 if ($field['display'] == true)
1.350 {
1.351 $fieldvalue = '';
1.352 - if ($field['name'] == ROW_NUMBER) {
1.353 + if ($field['name'] == LF_ROW_NUMBER) {
1.354 $fieldvalue = $r + $offset;
1.355 } else if (!empty($row[ $field['name'] ])) {
1.356 $fieldvalue = $row[ $field['name'] ];
1.357 @@ -710,7 +724,8 @@
1.358 }
1.359
1.360 // Print page numbers
1.361 - $page_url = $this->_page_url . 'order=' . $this->_sort_arr['field'] . '&direction=' . $this->_sort_arr['direction'] . '&results=' . $this->_per_page;
1.362 + $page_url = $this->_page_url.'order='.$this->_sort_arr['field'] .
1.363 + '&direction='.$this->_sort_arr['direction'].'&results='.$this->_per_page;
1.364 $num_pages = ceil($this->_total_found / $this->_per_page);
1.365 if ($num_pages > 1) {
1.366 $list_templates->set_var('google_paging', COM_printPageNavigation($page_url, $this->_page, $num_pages, 'page=', false, '', ''));
2.1 --- a/system/classes/search.class.php Sun Oct 25 22:01:38 2009 +0000
2.2 +++ b/system/classes/search.class.php Sun Oct 25 23:15:27 2009 +0000
2.3 @@ -95,7 +95,7 @@
2.4 // In case we got a username instead of uid, convert it. This should
2.5 // make custom themes for search page easier.
2.6 if (!is_numeric($this->_author) && !preg_match('/^([0-9]+)$/', $this->_author) && $this->_author != '') {
2.7 - $this->_author = DB_getItem($_TABLES['users'], 'uid', "username='" . addslashes ($this->_author) . "'");
2.8 + $this->_author = DB_getItem($_TABLES['users'], 'uid', 'username=\'' . addslashes ($this->_author) . '\'');
2.9 }
2.10
2.11 if ($this->_author < 1) {
2.12 @@ -353,18 +353,18 @@
2.13 // Make sure the query is SQL safe
2.14 $query = trim(addslashes($this->_query));
2.15
2.16 - $sql = "SELECT s.sid AS id, s.title AS title, s.introtext AS description, ";
2.17 - $sql .= "UNIX_TIMESTAMP(s.date) AS date, s.uid AS uid, s.hits AS hits, ";
2.18 - $sql .= "CONCAT('/article.php?story=',s.sid) AS url ";
2.19 - $sql .= "FROM {$_TABLES['stories']} AS s, {$_TABLES['users']} AS u ";
2.20 - $sql .= "WHERE (draft_flag = 0) AND (date <= NOW()) AND (u.uid = s.uid) ";
2.21 + $sql = 'SELECT s.sid AS id, s.title AS title, s.introtext AS description, ';
2.22 + $sql .= 'UNIX_TIMESTAMP(s.date) AS date, s.uid AS uid, s.hits AS hits, ';
2.23 + $sql .= 'CONCAT(\'/article.php?story=\',s.sid) AS url ';
2.24 + $sql .= 'FROM '.$_TABLES['stories'].' AS s, '.$_TABLES['users'].' AS u ';
2.25 + $sql .= 'WHERE (draft_flag = 0) AND (date <= NOW()) AND (u.uid = s.uid) ';
2.26 $sql .= COM_getPermSQL('AND') . COM_getTopicSQL('AND') . COM_getLangSQL('sid', 'AND') . ' ';
2.27
2.28 if (!empty($this->_topic)) {
2.29 - $sql .= "AND (s.tid = '$this->_topic') ";
2.30 + $sql .= 'AND (s.tid = \''.$this->_topic.'\') ';
2.31 }
2.32 if (!empty($this->_author)) {
2.33 - $sql .= "AND (s.uid = '$this->_author') ";
2.34 + $sql .= 'AND (s.uid = \''.$this->_author.'\') ';
2.35 }
2.36
2.37 $search_s = new SearchCriteria('stories', $LANG09[65]);
2.38 @@ -379,26 +379,26 @@
2.39 $search_s->setURLRewrite(true);
2.40
2.41 // Search Story Comments
2.42 - $sql = "SELECT c.cid AS id, c.title AS title, c.comment AS description, ";
2.43 - $sql .= "UNIX_TIMESTAMP(c.date) AS date, c.uid AS uid, ";
2.44 + $sql = 'SELECT c.cid AS id, c.title AS title, c.comment AS description, ';
2.45 + $sql .= 'UNIX_TIMESTAMP(c.date) AS date, c.uid AS uid, ';
2.46
2.47 // MSSQL has a problem when concatenating numeric values
2.48 if ($_DB_dbms == 'mssql') {
2.49 - $sql .= "'/comment.php?mode=view&cid=' + CAST(c.cid AS varchar(10)) AS url ";
2.50 + $sql .= '\'/comment.php?mode=view&cid=\' + CAST(c.cid AS varchar(10)) AS url ';
2.51 } else {
2.52 - $sql .= "CONCAT('/comment.php?mode=view&cid=',c.cid) AS url ";
2.53 + $sql .= 'CONCAT(\'/comment.php?mode=view&cid=\',c.cid) AS url ';
2.54 }
2.55
2.56 - $sql .= "FROM {$_TABLES['users']} AS u, {$_TABLES['comments']} AS c ";
2.57 - $sql .= "LEFT JOIN {$_TABLES['stories']} AS s ON ((s.sid = c.sid) ";
2.58 - $sql .= COM_getPermSQL('AND',0,2,'s') . COM_getTopicSQL('AND',0,'s') . COM_getLangSQL('sid','AND','s') . ") ";
2.59 - $sql .= "WHERE (u.uid = c.uid) AND (s.draft_flag = 0) AND (s.commentcode >= 0) AND (s.date <= NOW()) ";
2.60 + $sql .= 'FROM '.$_TABLES['users'].' AS u, '.$_TABLES['comments'].' AS c ';
2.61 + $sql .= 'LEFT JOIN '.$_TABLES['stories'].' AS s ON ((s.sid = c.sid) ';
2.62 + $sql .= COM_getPermSQL('AND',0,2,'s').COM_getTopicSQL('AND',0,'s').COM_getLangSQL('sid','AND','s').') ';
2.63 + $sql .= 'WHERE (u.uid = c.uid) AND (s.draft_flag = 0) AND (s.commentcode >= 0) AND (s.date <= NOW()) ';
2.64
2.65 if (!empty($this->_topic)) {
2.66 - $sql .= "AND (s.tid = '$this->_topic') ";
2.67 + $sql .= 'AND (s.tid = \''.$this->_topic.'\') ';
2.68 }
2.69 if (!empty($this->_author)) {
2.70 - $sql .= "AND (c.uid = '$this->_author') ";
2.71 + $sql .= 'AND (c.uid = \''.$this->_author.'\') ';
2.72 }
2.73
2.74 $search_c = new SearchCriteria('comments', array($LANG09[65],$LANG09[66]));
2.75 @@ -470,28 +470,28 @@
2.76 if ($style == 'table')
2.77 {
2.78 $obj->setStyle('table');
2.79 - // Title Name Display Sort Format
2.80 - $obj->setField($LANG09[62], ROW_NUMBER, $show_num, false, '<b>%d.</b>');
2.81 - $obj->setField($LANG09[5], SQL_TITLE, $show_type, true, '<b>%s</b>');
2.82 - $obj->setField($LANG09[16], 'title', true, true);
2.83 - $obj->setField($LANG09[63], 'description', true, false);
2.84 - $obj->setField($LANG09[17], 'date', true, true);
2.85 - $obj->setField($LANG09[18], 'uid', $show_user, true);
2.86 - $obj->setField($LANG09[50], 'hits', $show_hits, true);
2.87 + // Title Name Display Sort Format
2.88 + $obj->setField($LANG09[62], LF_ROW_NUMBER, $show_num, false, '<b>%d.</b>');
2.89 + $obj->setField($LANG09[5], LF_SOURCE_TITLE,$show_type, true, '<b>%s</b>');
2.90 + $obj->setField($LANG09[16], 'title', true, true);
2.91 + $obj->setField($LANG09[63], 'description', true, false);
2.92 + $obj->setField($LANG09[17], 'date', true, true);
2.93 + $obj->setField($LANG09[18], 'uid', $show_user, true);
2.94 + $obj->setField($LANG09[50], 'hits', $show_hits, true);
2.95 $this->_wordlength = 7;
2.96 }
2.97 else if ($style == 'google')
2.98 {
2.99 $obj->setStyle('inline');
2.100 - $obj->setField('', ROW_NUMBER, $show_num, false, '<b>%d.</b>');
2.101 - $obj->setField($LANG09[16], 'title', true, true, '%s<br>');
2.102 - $obj->setField('', 'description', true, false, '%s<br>');
2.103 - $obj->setField('', '_html', true, false, '<span style="color:green;">');
2.104 - $obj->setField($LANG09[18], 'uid', $show_user, true, $LANG01[104].' %s ');
2.105 - $obj->setField($LANG09[17], 'date', true, true, $LANG01[36].' %s');
2.106 - $obj->setField($LANG09[5], SQL_TITLE, $show_type, true, ' - %s');
2.107 - $obj->setField($LANG09[50], 'hits', $show_hits, true, ' - %s '.$LANG09[50]);
2.108 - $obj->setField('', '_html', true, false, '</span>');
2.109 + $obj->setField('', LF_ROW_NUMBER, $show_num, false, '<b>%d.</b>');
2.110 + $obj->setField($LANG09[16], 'title', true, true, '%s<br>');
2.111 + $obj->setField('', 'description', true, false, '%s<br>');
2.112 + $obj->setField('', '_html', true, false, '<span style="color:green;">');
2.113 + $obj->setField($LANG09[18], 'uid', $show_user, true, $LANG01[104].' %s ');
2.114 + $obj->setField($LANG09[17], 'date', true, true, $LANG01[36].' %s');
2.115 + $obj->setField($LANG09[5], LF_SOURCE_TITLE,$show_type, true, ' - %s');
2.116 + $obj->setField($LANG09[50], 'hits', $show_hits, true, ' - %s '.$LANG09[50]);
2.117 + $obj->setField('', '_html', true, false, '</span>');
2.118 $this->_wordlength = 50;
2.119 }
2.120 $obj->setDefaultSort('hits');
2.121 @@ -503,7 +503,9 @@
2.122
2.123 // Have plugins do their searches
2.124 $page = isset($_GET['page']) ? COM_applyFilter($_GET['page'], true) : 1;
2.125 - $result_plugins = PLG_doSearch($this->_query, $this->_dateStart, $this->_dateEnd, $this->_topic, $this->_type, $this->_author, $this->_keyType, $page, 5);
2.126 + $result_plugins = PLG_doSearch($this->_query, $this->_dateStart,
2.127 + $this->_dateEnd, $this->_topic, $this->_type,
2.128 + $this->_author, $this->_keyType, $page, 5);
2.129
2.130 // Add core searches
2.131 $result_plugins = array_merge($result_plugins, $this->_searchStories());
2.132 @@ -517,13 +519,13 @@
2.133 {
2.134 if (is_a($result, 'SearchCriteria'))
2.135 {
2.136 - $debug_info = $result->getName() . " using APIv2";
2.137 + $debug_info = $result->getName().' using APIv2';
2.138
2.139 if ($this->_type != 'all' && $this->_type != $result->getName())
2.140 {
2.141 if ($this->_verbose) {
2.142 $new_api++;
2.143 - COM_errorLog("$debug_info. Skipped as type is not " . $this->_type);
2.144 + COM_errorLog($debug_info.'. Skipped as type is not '.$this->_type);
2.145 }
2.146 continue;
2.147 }
2.148 @@ -536,24 +538,19 @@
2.149 $api_callback_func = $result->getCallback();
2.150 if (!empty($api_callback_func))
2.151 {
2.152 - $debug_info .= " with Callback Function " . $api_callback_func;
2.153 + $debug_info .= ' with Callback Function.';
2.154 $obj->setCallback($result->getLabel(), $result->getName(), $api_callback_func, $result->getRank(), $result->getTotal());
2.155 }
2.156 else
2.157 {
2.158 - if ($_CONF['search_use_fulltext'] == true && $result->getFTSQL() != '')
2.159 - {
2.160 - $debug_info .= " with SQL FULLTEXT. ";
2.161 + if ($_CONF['search_use_fulltext'] == true && $result->getFTSQL() != '') {
2.162 $sql = $result->getFTSQL();
2.163 - }
2.164 - else
2.165 - {
2.166 - $debug_info .= " with SQL LIKE. ";
2.167 + } else {
2.168 $sql = $result->getSQL();
2.169 }
2.170
2.171 $sql = $this->_convertsql($sql);
2.172 - $debug_info .= "SQL = " . print_r($sql,1);
2.173 + $debug_info .= ' with SQL = '.print_r($sql,1);
2.174 $obj->setQuery($result->getLabel(), $result->getName(), $sql, $result->getRank());
2.175 }
2.176
2.177 @@ -570,9 +567,9 @@
2.178 // Some backwards compatibility
2.179 if ($this->_verbose) {
2.180 $old_api++;
2.181 - $debug_info = $result->plugin_name . " using APIv1 with backwards compatibility.";
2.182 - $debug_info .= " Count: " . $result->num_searchresults;
2.183 - $debug_info .= " Headings: " . implode(",", $result->searchheading);
2.184 + $debug_info = $result->plugin_name.' using APIv1 with backwards compatibility.';
2.185 + $debug_info .= ' Count: ' . $result->num_searchresults;
2.186 + $debug_info .= ' Headings: ' . implode(',', $result->searchheading);
2.187 COM_errorLog($debug_info);
2.188 }
2.189
2.190 @@ -601,19 +598,12 @@
2.191 // Convert the date back to a timestamp
2.192 $date = $old_row[ $col_date ];
2.193 $date = substr($date, 0, strpos($date, '@'));
2.194 - if ($date == '')
2.195 - {
2.196 - $date = $old_row[$col_date];
2.197 - }
2.198 - else
2.199 - {
2.200 - $date = strtotime($date);
2.201 - }
2.202 + $date = ($date == '' ? $old_row[$col_date] : strtotime($date));
2.203 }
2.204
2.205 $api_results = array(
2.206 - SQL_NAME => $result->plugin_name,
2.207 - SQL_TITLE => $label,
2.208 + LF_SOURCE_NAME => $result->plugin_name,
2.209 + LF_SOURCE_TITLE => $label,
2.210 'title' => $col_title == -1 ? '<i>' . $LANG09[70] . '</i>' : $old_row[$col_title],
2.211 'description' => $col_desc == -1 ? '<i>' . $LANG09[70] . '</i>' : $old_row[$col_desc],
2.212 'date' => $col_date == -1 ? 'LF_NULL' : $date,
2.213 @@ -630,7 +620,7 @@
2.214
2.215 // Find out how many plugins are on the old/new system
2.216 if ($this->_verbose) {
2.217 - COM_errorLog("Search Plugins using APIv1: $old_api APIv2: $new_api");
2.218 + COM_errorLog('Search Plugins using APIv1: '.$old_api.' APIv2: '.$new_api);
2.219 }
2.220
2.221 // Execute the queries
2.222 @@ -658,7 +648,7 @@
2.223 }
2.224
2.225 // Clean the query string so that sprintf works as expected
2.226 - $searchQuery = str_replace("%", "%%", $searchQuery);
2.227 + $searchQuery = str_replace('%', '%%', $searchQuery);
2.228
2.229 $retval = "{$LANG09[25]} $searchQuery. ";
2.230 if (count($results) == 0)
2.231 @@ -671,9 +661,10 @@
2.232 else
2.233 {
2.234 $retval .= $LANG09[64] . " ($searchtime {$LANG09[27]}). ";
2.235 - $retval .= str_replace("%", "%%", COM_createLink($LANG09[61], $url.'refine'));
2.236 + $retval .= str_replace('%', '%%', COM_createLink($LANG09[61], $url.'refine'));
2.237 $retval = '<p>' . $retval . '</p>' . LB;
2.238 - $retval = $obj->getFormattedOutput($results, $LANG09[11], $retval, '', $_CONF['search_show_sort'], $_CONF['search_show_limit']);
2.239 + $retval = $obj->getFormattedOutput($results, $LANG09[11], $retval, '',
2.240 + $_CONF['search_show_sort'], $_CONF['search_show_limit']);
2.241 }
2.242
2.243 return $retval;
2.244 @@ -697,7 +688,9 @@
2.245
2.246 if ($preSort)
2.247 {
2.248 - $row[SQL_TITLE] = is_array($row[SQL_TITLE]) ? implode($_CONF['search_separator'],$row[SQL_TITLE]) : $row[SQL_TITLE];
2.249 + if (is_array($row[LF_SOURCE_TITLE])) {
2.250 + $row[LF_SOURCE_TITLE] = implode($_CONF['search_separator'], $row[LF_SOURCE_TITLE]);
2.251 + }
2.252
2.253 if (is_numeric($row['uid']))
2.254 {
2.255 @@ -715,17 +708,18 @@
2.256 }
2.257 else
2.258 {
2.259 - $row[SQL_TITLE] = COM_createLink($row[SQL_TITLE], $this->_searchURL.'&type='.$row[SQL_NAME].'&mode=search');
2.260 + $row[LF_SOURCE_TITLE] = COM_createLink($row[LF_SOURCE_TITLE],
2.261 + $this->_searchURL.'&type='.$row[LF_SOURCE_NAME].'&mode=search');
2.262
2.263 if ($row['url'] != '#')
2.264 {
2.265 $row['url'] = ($row['url'][0] == '/' ? $_CONF['site_url'] : '') . $row['url'];
2.266 - if (isset($this->_url_rewrite[$row[SQL_NAME]]) &&
2.267 - $this->_url_rewrite[$row[SQL_NAME]]) {
2.268 + if (isset($this->_url_rewrite[$row[LF_SOURCE_NAME]]) &&
2.269 + $this->_url_rewrite[$row[LF_SOURCE_NAME]]) {
2.270 $row['url'] = COM_buildUrl($row['url']);
2.271 }
2.272 - if (isset($this->_append_query[$row[SQL_NAME]]) &&
2.273 - $this->_append_query[$row[SQL_NAME]]) {
2.274 + if (isset($this->_append_query[$row[LF_SOURCE_NAME]]) &&
2.275 + $this->_append_query[$row[LF_SOURCE_NAME]]) {
2.276 $row['url'] .= (strpos($row['url'],'?') ? '&' : '?') . 'query=' . urlencode($this->_query);
2.277 }
2.278 }