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.forumattachments.php

    r1935 r2090  
    6161    } else { 
    6262 
    63         // get the required variables (could be POST or GET vars!) 
    64         if (isset($stext)) { 
    65             $stext = stripinput($stext); 
     63        // make sure the sub search ID is defined 
     64        if (!isset($sub_search_id)) $sub_search_id = 0; 
     65 
     66        // retrieve the search criteria 
     67        if (isset($_SESSION['search'])) { 
     68            // from the session store (used when paging through the results) 
     69            $stext = $_SESSION['search']['stext']; 
     70            $qtype = $_SESSION['search']['qtype']; 
     71            $datelimit = $_SESSION['search']['datelimit']; 
     72            $boolean = $_SESSION['search']['boolean']; 
     73            $sortby = $_SESSION['search']['sortby']; 
     74            $order = $_SESSION['search']['order']; 
     75            $limit = $_SESSION['search']['limit']; 
     76            $contentfilter_forums = $_SESSION['search']['contentfilter_forums']; 
     77            $contentfilter_users = $_SESSION['search']['contentfilter_users']; 
    6678        } else { 
     79            // from the search form 
    6780            $stext = isset($_POST['stext']) ? stripinput($_POST['stext']) : ""; 
    68         } 
    69         $stext = str_replace(',', ' ', $stext); 
     81            $stext = str_replace(',', ' ', $stext); 
     82            $boolean = isset($_POST['boolean']) ? 0 : 1; 
     83            $qtype = isset($_POST['qtype']) ? stripinput($_POST['qtype']) : "AND"; 
     84            if ($qtype != "OR" && $qtype != "AND") { 
     85                $qtype = "AND"; 
     86            } 
     87            $sortby = isset($_POST['sortby']) ? stripinput($_POST['sortby']) : "score"; 
     88            if (!in_array($sortby, $select_filters)) { 
     89                $sortby = $select_filters[0]; 
     90            } 
     91            $order = isset($_POST['order']) && isNum($_POST['order']) ? $_POST['order'] : 1; 
     92            $limit = isset($_POST['limit']) && isNum($_POST['limit']) ? $_POST['limit'] : 0; 
     93            $datelimit = isset($_POST['datelimit']) && isNum($_POST['datelimit']) ? $_POST['datelimit'] : 0; 
     94            // add a forum filter if requested 
     95            if (isset($_POST['contentfilter_forums']) && isNum($_POST['contentfilter_forums']) && $_POST['contentfilter_forums'] > 0 ) { 
     96                $contentfilter_forums =  stripinput($_POST['contentfilter_forums']); 
     97            } 
     98            // add an author if requested 
     99            if (isset($_POST['contentfilter_users']) && isNum($_POST['contentfilter_users']) && $_POST['contentfilter_users'] > 0 ) { 
     100                $contentfilter_users = stripinput($_POST['contentfilter_users']); 
     101            } 
     102        } 
    70103        $variables['stext'] = $stext; 
    71         // note: qtype not used because of a fulltext query 
    72         if (!isset($qtype)) { 
    73             $qtype = isset($_POST['qtype']) ? $_POST['qtype'] : "AND"; 
    74         } 
    75         if ($qtype != "OR" && $qtype != "AND") { 
    76             $qtype = "AND"; 
    77         } 
    78         if (!isset($datelimit)) { 
    79             $datelimit = isset($_POST['datelimit']) ? $_POST['datelimit'] : 0; 
    80         } 
    81         if (!isNum($datelimit)) { 
    82             $datelimit = 0; 
    83         } 
    84         if (!isset($sortby)) { 
    85             $sortby = isset($_POST['sortby']) ? $_POST['sortby'] : "score"; 
    86         } 
    87         if (!in_array($sortby, $select_filters)) { 
    88             $sortby = $select_filters[0]; 
    89         } 
    90         if (!isset($order)) { 
    91             $order = isset($_POST['order']) ? $_POST['order'] : 1; 
    92         } 
    93         if (!isNum($order)) { 
    94             $order = 1; 
    95         } 
    96         if (!isset($limit)) { 
    97             $limit = isset($_POST['limit']) ? $_POST['limit'] : 0; 
    98         } 
    99         if (!isNum($limit)) { 
    100             $limit = 0; 
    101         } 
    102         if (!isset($boolean)) { 
    103             $boolean = isset($_POST['boolean']) ? 0 : 1; 
    104         } 
    105  
    106         if (!isset($sub_search_id)) $sub_search_id = 0; 
    107  
    108         // construct the page navigator URL to allow paging 
    109         $variables['pagenav_url'] = FUSION_SELF."?action=search&search_id=".$search_id."&"; 
    110         $variables['pagenav_url'] .= "stext=".urlencode($stext)."&"; 
    111         $variables['pagenav_url'] .= "boolean=".$boolean."&"; 
    112         $variables['pagenav_url'] .= "datelimit=".$datelimit."&"; 
    113         $variables['pagenav_url'] .= "sortby=".$sortby."&"; 
    114         $variables['pagenav_url'] .= "order=".$order."&"; 
    115         $variables['pagenav_url'] .= "limit=".$limit."&"; 
     104 
     105        // store the search parameters in the session record 
     106        $_SESSION['search'] = array('stext' => $stext, 
     107                                    'qtype' => $qtype, 
     108                                    'datelimit' => $datelimit, 
     109                                    'boolean' => $boolean, 
     110                                    'sortby' => $sortby, 
     111                                    'order' => $order, 
     112                                    'limit' => $limit, 
     113                                    'contentfilter_forums' => $contentfilter_forums, 
     114                                    'contentfilter_users' => $contentfilter_users 
     115                                ); 
    116116 
    117117        // basis of the query for this search 
     
    149149 
    150150        // add a forum filter if requested 
    151         if (isset($_POST['contentfilter_forums']) && isNum($_POST['contentfilter_forums']) && $_POST['contentfilter_forums'] > 0 ) { 
    152             $sql .= " AND tp.forum_id = '".$_POST['contentfilter_forums']."'"; 
     151        if (!empty($contentfilter_forums)) { 
     152            $sql .= " AND tp.forum_id = '".$contentfilter_forums."'"; 
    153153        } 
    154154        // add an author if requested 
    155         if (isset($_POST['contentfilter_users']) && isNum($_POST['contentfilter_users']) && $_POST['contentfilter_users'] > 0 ) { 
    156             $sql .= " AND (tp.post_author = '".$_POST['contentfilter_users']."'"." OR tp.post_edituser = '".$_POST['contentfilter_users']."')"; 
     155        if (!empty($contentfilter_users)) { 
     156            $sql .= " AND (tp.post_author = '".$contentfilter_users."'"." OR tp.post_edituser = '".$contentfilter_users."')"; 
    157157        } 
    158158 
Note: See TracChangeset for help on using the changeset viewer.