Changeset 2090 in ExiteCMS for trunk/includes/search/search.pm.php


Ignore:
Timestamp:
12/04/08 14:28:48 (3 years ago)
Author:
WanWizard
Message:

rewritten part of the search module logic. Now a session variable is used to store the search parameters, so they don't have to be exposed in the URL anymore
fixed some syntax errors in queries when using MySQL5.x
fixed some layout and locale issues in the search module output

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/search/search.pm.php

    r1935 r2090  
    3232    } else { 
    3333 
    34         // get the required variables (could be POST or GET vars!) 
    35         if (isset($stext)) { 
    36             $stext = stripinput($stext); 
     34        // make sure the sub search ID is defined 
     35        if (!isset($sub_search_id)) $sub_search_id = 0; 
     36 
     37        // retrieve the search criteria 
     38        if (isset($_SESSION['search'])) { 
     39            // from the session store (used when paging through the results) 
     40            $stext = $_SESSION['search']['stext']; 
     41            $qtype = $_SESSION['search']['qtype']; 
     42            $datelimit = $_SESSION['search']['datelimit']; 
     43            $boolean = $_SESSION['search']['boolean']; 
     44            $sortby = $_SESSION['search']['sortby']; 
     45            $order = $_SESSION['search']['order']; 
     46            $limit = $_SESSION['search']['limit']; 
     47            $contentfilter_forums = $_SESSION['search']['contentfilter_forums']; 
     48            $contentfilter_users = $_SESSION['search']['contentfilter_users']; 
    3749        } else { 
     50            // from the search form 
    3851            $stext = isset($_POST['stext']) ? stripinput($_POST['stext']) : ""; 
    39         } 
    40         $stext = str_replace(',', ' ', $stext); 
     52            $stext = str_replace(',', ' ', $stext); 
     53            $boolean = isset($_POST['boolean']) ? 0 : 1; 
     54            $qtype = isset($_POST['qtype']) ? stripinput($_POST['qtype']) : "AND"; 
     55            if ($qtype != "OR" && $qtype != "AND") { 
     56                $qtype = "AND"; 
     57            } 
     58            $sortby = isset($_POST['sortby']) ? stripinput($_POST['sortby']) : "score"; 
     59            if (!in_array($sortby, $select_filters)) { 
     60                $sortby = $select_filters[0]; 
     61            } 
     62            $order = isset($_POST['order']) && isNum($_POST['order']) ? $_POST['order'] : 1; 
     63            $limit = isset($_POST['limit']) && isNum($_POST['limit']) ? $_POST['limit'] : 0; 
     64            $datelimit = isset($_POST['datelimit']) && isNum($_POST['datelimit']) ? $_POST['datelimit'] : 0; 
     65            // add a forum filter if requested 
     66            if (isset($_POST['contentfilter_forums']) && isNum($_POST['contentfilter_forums']) && $_POST['contentfilter_forums'] > 0 ) { 
     67                $contentfilter_forums =  stripinput($_POST['contentfilter_forums']); 
     68            } 
     69            // add an author if requested 
     70            if (isset($_POST['contentfilter_users']) && isNum($_POST['contentfilter_users']) && $_POST['contentfilter_users'] > 0 ) { 
     71                $contentfilter_users = stripinput($_POST['contentfilter_users']); 
     72            } 
     73        } 
    4174        $variables['stext'] = $stext; 
    42         // note: qtype not used because of a fulltext query 
    43         if (!isset($qtype)) { 
    44             $qtype = isset($_POST['qtype']) ? $_POST['qtype'] : "AND"; 
    45         } 
    46         if ($qtype != "OR" && $qtype != "AND") { 
    47             $qtype = "AND"; 
    48         } 
    49         if (!isset($datelimit)) { 
    50             $datelimit = isset($_POST['datelimit']) ? $_POST['datelimit'] : 0; 
    51         } 
    52         if (!isNum($datelimit)) { 
    53             $datelimit = 0; 
    54         } 
    55         if (!isset($sortby)) { 
    56             $sortby = isset($_POST['sortby']) ? $_POST['sortby'] : "score"; 
    57         } 
    58         if (!in_array($sortby, $select_filters)) { 
    59             $sortby = $select_filters[0]; 
    60         } 
    61         if (!isset($order)) { 
    62             $order = isset($_POST['order']) ? $_POST['order'] : 1; 
    63         } 
    64         if (!isNum($order)) { 
    65             $order = 1; 
    66         } 
    67         if (!isset($limit)) { 
    68             $limit = isset($_POST['limit']) ? $_POST['limit'] : 0; 
    69         } 
    70         if (!isNum($limit)) { 
    71             $limit = 0; 
    72         } 
    73         if (!isset($boolean)) { 
    74             $boolean = isset($_POST['boolean']) ? 0 : 1; 
    75         } 
    76  
    77         if (!isset($sub_search_id)) $sub_search_id = 0; 
    78  
    79         // construct the page navigator URL to allow paging 
    80         $variables['pagenav_url'] = FUSION_SELF."?action=search&search_id=".$search_id."&"; 
    81         $variables['pagenav_url'] .= "stext=".urlencode($stext)."&"; 
    82         $variables['pagenav_url'] .= "boolean=".$boolean."&"; 
    83         $variables['pagenav_url'] .= "datelimit=".$datelimit."&"; 
    84         $variables['pagenav_url'] .= "sortby=".$sortby."&"; 
    85         $variables['pagenav_url'] .= "order=".$order."&"; 
    86         $variables['pagenav_url'] .= "limit=".$limit."&"; 
     75 
     76        // store the search parameters in the session record 
     77        $_SESSION['search'] = array('stext' => $stext, 
     78                                    'qtype' => $qtype, 
     79                                    'datelimit' => $datelimit, 
     80                                    'boolean' => $boolean, 
     81                                    'sortby' => $sortby, 
     82                                    'order' => $order, 
     83                                    'limit' => $limit, 
     84                                    'contentfilter_forums' => $contentfilter_forums, 
     85                                    'contentfilter_users' => $contentfilter_users 
     86                                ); 
    8787 
    8888        // basis of the query for this search 
Note: See TracChangeset for help on using the changeset viewer.