From 3ec286b17a552caf59e52260dbe66332cc605f9c Mon Sep 17 00:00:00 2001 From: Lester Caine Date: Mon, 2 Jul 2007 08:05:56 +0000 Subject: Complete conversion of pagination and tidy up content type selection --- index.php | 59 ++++++++++++++++++++-------------------------------- search_lib.php | 54 +++++++++++++++++++++++++---------------------- templates/search.tpl | 4 ++-- 3 files changed, 53 insertions(+), 64 deletions(-) diff --git a/index.php b/index.php index 6ec6b8b..f898c89 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,6 @@ assign( 'contentTypes', $contentTypes ); if( !empty($_REQUEST["highlight"]) ) { @@ -38,9 +38,11 @@ if ($gBitSystem->isFeatureActive("stats_search")) { $searchlib->register_search(isset($_REQUEST["words"]) ? $_REQUEST["words"] : ''); } -$content_type_guid = ''; -if (isset($_REQUEST["content_type_guid"])) { - $content_type_guid = $_REQUEST["content_type_guid"]; +if (!isset($_REQUEST["content_type_guid"])) { + $_REQUEST["content_type_guid"] = ''; + $where2 = "Page"; +} else { + $where2 = $contentTypes[$_REQUEST["content_type_guid"]]; } LibertyContent::prepGetList($_REQUEST); @@ -54,60 +56,43 @@ $gBitSmarty->assign('searchType', $_REQUEST['usePart'] ? "Using Partial Word Sea // Build the query using words if ((!isset($_REQUEST["words"])) || (empty($_REQUEST["words"]))) { - $words = ''; + $_REQUEST["words"] = ''; } else { - $words = strip_tags($_REQUEST["words"]); -} -$gBitSmarty->assign('words', $words); -$results = $searchlib->find($content_type_guid, $words, $_REQUEST['offset'], $_REQUEST['max_records'], $_REQUEST["usePart"]); -$cant = $results['cant']; - -switch ($content_type_guid) { - case "bitarticle" : $where2 = "Article"; break; - case "bitpage" : $where2 = "Wiki Page"; break; - case "bitblogpost" : $where2 = "Blog Post"; break; - case "bitcomment" : $where2 = "Comment"; break; - default : $where2 = "Page"; break; + $_REQUEST["words"] = strip_tags($_REQUEST["words"]); } +$gBitSmarty->assign('words', $_REQUEST["words"]); +$results = $searchlib->find( $_REQUEST ); -if ($cant <> 1) $where2 .= "s"; -$gBitSmarty->assign('content_type_guid', $content_type_guid); +if ($_REQUEST['cant'] <> 1) $where2 .= "s"; $gBitSmarty->assign('where2', tra($where2)); +$gBitSmarty->assign('content_type_guid', $_REQUEST["content_type_guid"]); $stubContent = new LibertyContent(); -if ( $cant > 0 ) { - foreach( array_keys( $results['data'] ) as $k ) { - if( empty( $results['data'][$k]['title'] ) ) { +if ( $_REQUEST['cant'] > 0 ) { + foreach( array_keys( $results ) as $k ) { + if( empty( $results[$k]['title'] ) ) { $date_format = $gBitSystem->get_long_date_format(); if( $gBitSystem->mServerTimestamp->get_display_offset() ) { $date_format = preg_replace( "/ ?%Z/", "", $date_format ); } else { $date_format = preg_replace( "/%Z/", "UTC", $date_format ); } - $date_string = $gBitSystem->mServerTimestamp->getDisplayDateFromUTC( $results['data'][$k]['created'] ); - $results['data'][$k]['title'] = $gBitSystem->mServerTimestamp->strftime( $date_format, $date_string, true ); + $date_string = $gBitSystem->mServerTimestamp->getDisplayDateFromUTC( $results[$k]['created'] ); + $results[$k]['title'] = $gBitSystem->mServerTimestamp->strftime( $date_format, $date_string, true ); } - if( !empty( $results['data'][$k]['data'] ) ) { - $results['data'][$k]['parsed'] = $stubContent->parseData( $results['data'][$k] ); + if( !empty( $results[$k]['data'] ) ) { + $results[$k]['parsed'] = $stubContent->parseData( $results[$k] ); } } } -// calculate page number -$numPages = ceil( $cant / $gBitSystem->getConfig( 'max_records' ) ); -$gBitSmarty->assign( 'numPages', $numPages ); - -$_REQUEST['cant'] = $cant; -$_REQUEST['control']['parameters']['highlight'] = $_REQUEST["highlight"]; -$_REQUEST['control']['parameters']['content_type_guid'] = $content_type_guid; LibertyContent::postGetList( $_REQUEST ); -$gBitSmarty->assign_by_ref( 'listInfo', $_REQUEST["control"] ); -$gBitSmarty->assign('cant_results', $cant); +$gBitSmarty->assign_by_ref( 'listInfo', $_REQUEST['listInfo'] ); $partialOnOff = $_REQUEST["usePart"] ? 'checked' : ''; $gBitSmarty->assign('partialOnOff', $partialOnOff); // Find search results (build array) -$gBitSmarty->assign_by_ref('results', $results["data"]); +$gBitSmarty->assign_by_ref('results', $results); // Display the template $gBitSystem->display( 'bitpackage:search/search.tpl', 'Search Results for: '.strip_tags($_REQUEST["highlight"])); diff --git a/search_lib.php b/search_lib.php index e54fcdc..0fd78ef 100644 --- a/search_lib.php +++ b/search_lib.php @@ -1,6 +1,6 @@ get_wordlist_from_syllables($words); - if(array($wordList)) { - $words = array_merge($words, $wordList); + function find( &$pParamHash ) { // $where, $words, $offset, $max_records, $plUsePart = false) { + $pParamHash['words'] = preg_split("/[\W]+/", strtolower($pParamHash['words']), -1, PREG_SPLIT_NO_EMPTY); + if ( isset($pParamHash['$plUsePart']) && $pParamHash['$plUsePart'] ) { + $wordList = $this->get_wordlist_from_syllables( $pParamHash['words'] ); + if ( array( $wordList ) ) { + $pParamHash['words'] = array_merge( $pParamHash['words'], $wordList ); } } -// $res = $this->find_exact($where, $words, $offset, $max_records); - $res = $this->find_exact_generic($where, $words, $offset, $max_records); + $res = $this->find_exact_generic( $pParamHash ); return $res; } @@ -157,25 +156,25 @@ class SearchLib extends BitBase { return $ret; } - function find_exact_generic($where, $words, $offset, $max_records) { + function find_exact_generic( &$pParamHash ) { global $gPage, $gBitSystem, $gLibertySystem, $gBitDbType; $allowed = array(); $ret = array(); foreach( $gLibertySystem->mContentTypes as $contentType ) { - if (($where == $contentType["content_type_guid"] or $where == "") // pages ? + if (( $pParamHash['content_type_guid'] == $contentType["content_type_guid"] or $pParamHash['content_type_guid'] == "" ) // pages ? and $this->has_permission($contentType["content_type_guid"])) { $allowed[] = $contentType["content_type_guid"]; } } - if (count($allowed) > 0 && count($words) > 0) { + if (count($allowed) > 0 && count($pParamHash['words']) > 0) { // Putting in the below hack because mssql cannot select distinct on a text blob column. - $qPlaceHolders1 = implode(',', array_fill(0, count($words), '?')); + $qPlaceHolders1 = implode(',', array_fill(0, count($pParamHash['words']), '?')); $selectSql = ''; $joinSql = ''; $whereSql = " AND lc.`content_type_guid` IN (" . implode(',', array_fill(0, count($allowed), '?')) . ") "; - $bindVars = array_merge( $words, $allowed ); + $bindVars = array_merge( $pParamHash['words'], $allowed ); LibertyContent::getServicesSql( 'content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars ); $query = "SELECT @@ -219,15 +218,16 @@ class SearchLib extends BitBase { GROUP BY si.`content_id` )>0 $whereSql"; - $result = $this->mDb->query( $query, array_merge( $words ,$bindVars), $max_records, $offset ); - $cant = $this->mDb->getOne( $querycant, $bindVars ); + $result = $this->mDb->query( $query, array_merge( $pParamHash['words'] ,$bindVars), $pParamHash['max_records'], $pParamHash['offset'] ); + $pParamHash['cant'] = $this->mDb->getOne( $querycant, $bindVars ); while ($res = $result->fetchRow()) { $res['href'] = BIT_ROOT_URL . "index.php?content_id=" . $res['content_id']; $ret[] = $res; } - return array('data' => $ret, 'cant' => $cant); + return $ret; } else { - return array('data' => array(),'cant' => 0); + $pParamHash['cant'] = 0; + return array(); } } @@ -235,12 +235,16 @@ class SearchLib extends BitBase { global $gBitUser; $ret = false; switch ($pContentType) { - case "bitarticle" : $perm = "p_articles_read"; break; - case "bitpage" : $perm = "p_wiki_view_page"; break; - case "bitblogpost" : $perm = "p_blogs_view"; break; - case "bitcomment" : $perm = "p_liberty_read_comments"; break; - case "fisheyegallery" : $perm = "p_fisheye_view"; break; - default : $perm = ""; break; + case "bitarticle" : $perm = "p_articles_read"; break; + case "bitpage" : $perm = "p_wiki_view_page"; break; + case "bitblog" : $perm = "p_blogs_view"; break; + case "bitblogpost" : $perm = "p_blogs_view"; break; + case "bitcomment" : $perm = "p_liberty_read_comments"; break; + case "fisheyegallery" : $perm = "p_fisheye_view"; break; + case "fisheyeitem" : $perm = "p_fisheye_view"; break; + case "treasurygallery" : $perm = "p_treasury_view"; break; + case "treasuryitem" : $perm = "p_treasury_view"; break; + default : $perm = ""; break; } return $gBitUser->hasPermission($perm); } diff --git a/templates/search.tpl b/templates/search.tpl index 0a0919c..0e4e1f3 100644 --- a/templates/search.tpl +++ b/templates/search.tpl @@ -34,7 +34,7 @@ {/form} - {if $words}

{tr}Found '{$words|escape:htmlall}' in {$cant_results} {if $where2}{$where2}{else}pages{/if}{/tr}

{/if} + {if $words}

{tr}Found '{$words|escape:htmlall}' in {$listInfo.total_records} {if $where2}{$where2}{else}pages{/if}{/tr}

{/if} {section name=search loop=$results} {* using capture for no particular reason appart from a nicer layout - xing *} @@ -68,7 +68,7 @@ {if $words}
{tr}No pages matched the search criteria{/tr}
{/if} {/section} - {pagination} + {pagination usePart=$partialOnOff content_type_guid=$content_type_guid highlight=$words|escape } {/strip} -- cgit v1.3