| 138 | | // evaluate if there has been at least one search term long enough to be considered |
|---|
| 139 | | if ($_n === 0) { |
|---|
| 140 | | $_error = $LANG['error_keywords_too_short']; |
|---|
| 141 | | } |
|---|
| 142 | | // insert condition into query |
|---|
| 143 | | $query = str_replace('%cond%', $_cond, $query); |
|---|
| 144 | | // default: first page |
|---|
| 145 | | if (!isset($page) || $page == '') { $page = 1; } |
|---|
| 146 | | $start = ($page - 1) * $SETTINGS['postsperpage']; |
|---|
| 147 | | $query2 = $query . ' LIMIT ' . $start . ', ' . $SETTINGS['postsperpage']; |
|---|
| 148 | | $query = str_replace('p.postid, p.topic, p.poster, p.posttime, p.post, t.topictitle', 'COUNT(*)', $query); |
|---|
| 149 | | // prepare database query |
|---|
| 150 | | $q = $C->prepare($query); |
|---|
| 151 | | $q2 = $C->prepare($query2); |
|---|
| 152 | | // bind search terms |
|---|
| 153 | | if ($search_mode == 'member') { |
|---|
| 154 | | $q->bindParam(':username', $_username, PDO::PARAM_STR); |
|---|
| 155 | | $q2->bindParam(':username', $_username, PDO::PARAM_STR); |
|---|
| 156 | | } |
|---|
| 157 | | $j = 0; |
|---|
| 158 | | while ($bind_words[$j] != '') { |
|---|
| 159 | | $q->bindValue(':word' . $j, '%' . $bind_words[$j] . '%', PDO::PARAM_STR); |
|---|
| 160 | | $q2->bindValue(':word' . $j, '%' . $bind_words[$j] . '%', PDO::PARAM_STR); |
|---|
| 161 | | $j++; |
|---|
| 162 | | } |
|---|
| 163 | | if ($scope[0] != 'all' && $scope[0] != '') { |
|---|
| 164 | | $q->bindParam(':scope1', $scope[1], PDO::PARAM_INT, 12); |
|---|
| 165 | | $q2->bindParam(':scope1', $scope[1], PDO::PARAM_INT, 12); |
|---|
| 166 | | } |
|---|
| 167 | | // any errors in the query? |
|---|
| 168 | | if ($q2 === FALSE || $q === FALSE) { |
|---|
| 169 | | $_error = $LANG['error_input']; |
|---|
| 170 | | } |
|---|
| 171 | | // only continue if no errors so far |
|---|
| 172 | | if ($_error == '') { |
|---|
| 173 | | // execute database query: number of results |
|---|
| 174 | | $q->execute(); |
|---|
| 175 | | $_num_results = $q->fetchColumn(0); |
|---|
| 176 | | $q = NULL; |
|---|
| 177 | | // build page navigation |
|---|
| 178 | | $pages = new Pagination($SETTINGS['postsperpage'], $page, $_num_results); |
|---|
| 179 | | // display page navigation |
|---|
| 180 | | if ($_pagination = $pages->display('search', Array('all', 'search_mode', 'search_scope', 'results'), Array(urlencode($all), $search_mode, $search_scope, $results))) { |
|---|
| 181 | | $this->html->body->addElement($_pagination); |
|---|
| 182 | | } |
|---|
| 183 | | // header |
|---|
| 184 | | $this->html->body->addChild('h2', $LANG['Search']); |
|---|
| 185 | | // execute database query: actual results for this page |
|---|
| 186 | | $q2->execute(); |
|---|
| 187 | | // display results |
|---|
| 188 | | $table = new Table('searchresults'); |
|---|
| 189 | | $table->addHeaderRow(Array('<th colspan="2">' . $LANG['Results'] . '</th>')); |
|---|
| 190 | | $n = 0; |
|---|
| 191 | | while ($row = $q2->fetchObject()) { |
|---|
| 192 | | // topic title |
|---|
| 193 | | // format post preview |
|---|
| 194 | | $postpreview = substr($F->post($row->post, TRUE), 0, 200); |
|---|
| 195 | | // remove incomplete words at the end of post preview |
|---|
| 196 | | if (strrpos($postpreview, ' ') !== FALSE) { |
|---|
| 197 | | $postpreview = substr($postpreview ,0 , strrpos($postpreview, ' ')); |
|---|
| 198 | | } |
|---|
| 199 | | // remove incomplete <br /> tag at the end if needed |
|---|
| 200 | | if (strrpos($postpreview, '<') !== FALSE && (strlen($postpreview) - strrpos($postpreview, '<')) === 3) { |
|---|
| 201 | | $postpreview = substr($postpreview, 0, strlen($postpreview) - 3); |
|---|
| 202 | | } |
|---|
| 203 | | // add it to table |
|---|
| 204 | | $table->addRow(Array('<td><a href="' . $F->link('topic') . 'id=' . $row->topic . '"><strong>' . $row->topictitle . '</strong></a><br />' . $postpreview . '...<br /></td>', '<td nowrap="nowrap">' . $LANG['Posted'] . ' ' . $LANG['by'] . ' ' . $row->poster . '<br />' . $LANG['at'] . ' ' . $F->datetime($row->posttime, FALSE, TRUE) . '<br />' . $LANG['on'] . ' ' . $F->datetime($row->posttime, TRUE, FALSE) . '</td>')); |
|---|
| 205 | | $n++; |
|---|
| 206 | | } |
|---|
| 207 | | $q2 = NULL; |
|---|
| 208 | | if ($n === 0) { |
|---|
| 209 | | // no results |
|---|
| 210 | | $table->addRow(Array('<td colspan="2">' . $LANG['none'] . '</td>')); |
|---|
| 211 | | } |
|---|
| 212 | | // add table |
|---|
| 213 | | $this->html->body->addElement($table->get()); |
|---|
| 214 | | // page navigation again |
|---|
| 215 | | if ($_pagination) { |
|---|
| 216 | | $this->html->body->addElement($_pagination); |
|---|
| | 138 | // check authentication code |
|---|
| | 139 | $session_code = new Authcode(); |
|---|
| | 140 | if ($search_mode == 'member' || $session_code->check($auth_code)) { |
|---|
| | 141 | // evaluate if there has been at least one search term long enough to be considered |
|---|
| | 142 | if ($_n === 0) { |
|---|
| | 143 | $_error = $LANG['error_keywords_too_short']; |
|---|
| | 144 | } |
|---|
| | 145 | // insert condition into query |
|---|
| | 146 | $query = str_replace('%cond%', $_cond, $query); |
|---|
| | 147 | // default: first page |
|---|
| | 148 | if (!isset($page) || $page == '') { $page = 1; } |
|---|
| | 149 | $start = ($page - 1) * $SETTINGS['postsperpage']; |
|---|
| | 150 | $query2 = $query . ' LIMIT ' . $start . ', ' . $SETTINGS['postsperpage']; |
|---|
| | 151 | $query = str_replace('p.postid, p.topic, p.poster, p.posttime, p.post, t.topictitle', 'COUNT(*)', $query); |
|---|
| | 152 | // prepare database query |
|---|
| | 153 | $q = $C->prepare($query); |
|---|
| | 154 | $q2 = $C->prepare($query2); |
|---|
| | 155 | // bind search terms |
|---|
| | 156 | if ($search_mode == 'member') { |
|---|
| | 157 | $q->bindParam(':username', $_username, PDO::PARAM_STR); |
|---|
| | 158 | $q2->bindParam(':username', $_username, PDO::PARAM_STR); |
|---|
| | 159 | } |
|---|
| | 160 | $j = 0; |
|---|
| | 161 | while ($bind_words[$j] != '') { |
|---|
| | 162 | $q->bindValue(':word' . $j, '%' . $bind_words[$j] . '%', PDO::PARAM_STR); |
|---|
| | 163 | $q2->bindValue(':word' . $j, '%' . $bind_words[$j] . '%', PDO::PARAM_STR); |
|---|
| | 164 | $j++; |
|---|
| | 165 | } |
|---|
| | 166 | if ($scope[0] != 'all' && $scope[0] != '') { |
|---|
| | 167 | $q->bindParam(':scope1', $scope[1], PDO::PARAM_INT, 12); |
|---|
| | 168 | $q2->bindParam(':scope1', $scope[1], PDO::PARAM_INT, 12); |
|---|
| | 169 | } |
|---|
| | 170 | // any errors in the query? |
|---|
| | 171 | if ($q2 === FALSE || $q === FALSE) { |
|---|
| | 172 | $_error = $LANG['error_input']; |
|---|
| | 173 | } |
|---|
| | 174 | // only continue if no errors so far |
|---|
| | 175 | if ($_error == '') { |
|---|
| | 176 | // execute database query: number of results |
|---|
| | 177 | $q->execute(); |
|---|
| | 178 | $_num_results = $q->fetchColumn(0); |
|---|
| | 179 | $q = NULL; |
|---|
| | 180 | // build page navigation |
|---|
| | 181 | $pages = new Pagination($SETTINGS['postsperpage'], $page, $_num_results); |
|---|
| | 182 | // display page navigation |
|---|
| | 183 | if ($_pagination = $pages->display('search', Array('all', 'search_mode', 'search_scope', 'results'), Array(urlencode($all), $search_mode, $search_scope, $results))) { |
|---|
| | 184 | $this->html->body->addElement($_pagination); |
|---|
| | 185 | } |
|---|
| | 186 | // header |
|---|
| | 187 | $this->html->body->addChild('h2', $LANG['Search']); |
|---|
| | 188 | // execute database query: actual results for this page |
|---|
| | 189 | $q2->execute(); |
|---|
| | 190 | // display results |
|---|
| | 191 | $table = new Table('searchresults'); |
|---|
| | 192 | $table->addHeaderRow(Array('<th colspan="2">' . $LANG['Results'] . '</th>')); |
|---|
| | 193 | $n = 0; |
|---|
| | 194 | while ($row = $q2->fetchObject()) { |
|---|
| | 195 | // topic title |
|---|
| | 196 | // format post preview |
|---|
| | 197 | $postpreview = substr($F->post($row->post, TRUE), 0, 200); |
|---|
| | 198 | // remove incomplete words at the end of post preview |
|---|
| | 199 | if (strrpos($postpreview, ' ') !== FALSE) { |
|---|
| | 200 | $postpreview = substr($postpreview ,0 , strrpos($postpreview, ' ')); |
|---|
| | 201 | } |
|---|
| | 202 | // remove incomplete <br /> tag at the end if needed |
|---|
| | 203 | if (strrpos($postpreview, '<') !== FALSE && (strlen($postpreview) - strrpos($postpreview, '<')) === 3) { |
|---|
| | 204 | $postpreview = substr($postpreview, 0, strlen($postpreview) - 3); |
|---|
| | 205 | } |
|---|
| | 206 | // add it to table |
|---|
| | 207 | $table->addRow(Array('<td><a href="' . $F->link('topic') . 'id=' . $row->topic . '"><strong>' . $row->topictitle . '</strong></a><br />' . $postpreview . '...<br /></td>', '<td nowrap="nowrap">' . $LANG['Posted'] . ' ' . $LANG['by'] . ' ' . $row->poster . '<br />' . $LANG['at'] . ' ' . $F->datetime($row->posttime, FALSE, TRUE) . '<br />' . $LANG['on'] . ' ' . $F->datetime($row->posttime, TRUE, FALSE) . '</td>')); |
|---|
| | 208 | $n++; |
|---|
| | 209 | } |
|---|
| | 210 | $q2 = NULL; |
|---|
| | 211 | if ($n === 0) { |
|---|
| | 212 | // no results |
|---|
| | 213 | $table->addRow(Array('<td colspan="2">' . $LANG['none'] . '</td>')); |
|---|
| | 214 | } |
|---|
| | 215 | // add table |
|---|
| | 216 | $this->html->body->addElement($table->get()); |
|---|
| | 217 | // page navigation again |
|---|
| | 218 | if ($_pagination) { |
|---|
| | 219 | $this->html->body->addElement($_pagination); |
|---|
| | 220 | } |
|---|
| | 221 | } else { |
|---|
| | 222 | // errors occured -> message |
|---|
| | 223 | $q->closeCursor(); |
|---|
| | 224 | $this->html->body->addChild('div', $_error); |
|---|