Changeset 36

Show
Ignore:
Timestamp:
2007-11-27 15:12:31 (4 years ago)
Author:
hannes
Message:

using authentication code on search page, enabling the default permissions of that page to be changed again

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/classes/pages/Search.php

    r20 r36  
    3232    public function __construct() { 
    3333        global $LANG, $F, $C, $SETTINGS; 
    34         global $all, $results, $search_scope, $search_mode, $page
     34        global $all, $results, $search_scope, $search_mode, $page, $auth_code
    3535        // define title and location 
    3636        $this->title = ' - ' . $LANG['Search']; 
     
    136136                        break; 
    137137                    } 
    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); 
    217225                        } 
    218226                    } else { 
    219                         // errors occured -> message 
    220                         $q->closeCursor(); 
    221                         $this->html->body->addChild('div', $_error); 
    222                     } 
     227                        // auth code wrong 
     228                        $div = $this->html->body->addChild('div', $LANG['error_authentication_code']); 
     229                        $div->addAttribute('class', 'message'); 
     230                    } 
     231                    // remove auth code form session 
     232                    $session_code->destroy(); 
    223233                } else { 
    224234                    // too little time between two searches 
     
    283293                $_col2 .= '</select></td>'; 
    284294                $form->addRawTableRow(Array($LANG['in'] . ':', $_col2)); 
     295                // authentication code 
     296                $session_code = new Authcode(); 
     297                $session_code->generate(); 
     298                $form->addRawTableRow(Array('<td>' . $LANG['Authentication_Code'] .  ':<br />' . $session_code->get() . '</td>', '<td><input type="text" name="auth_code" /></td>')); 
    285299                $form->addTableEnd(); 
    286300                $form->addTable(); 
  • trunk/db/data.sql

    r34 r36  
    2727INSERT INTO %prefix%rights VALUES('Search',2,1,1); 
    2828INSERT INTO %prefix%rights VALUES('Search',4,1,1); 
    29 INSERT INTO %prefix%rights VALUES('Search',5,0,0); 
     29INSERT INTO %prefix%rights VALUES('Search',5,1,1); 
    3030INSERT INTO %prefix%rights VALUES('Mail',1,1,1); 
    3131INSERT INTO %prefix%rights VALUES('Mail',2,1,1); 
     
    179179INSERT INTO %prefix%rights_default VALUES('Search',2,1,1); 
    180180INSERT INTO %prefix%rights_default VALUES('Search',4,1,1); 
    181 INSERT INTO %prefix%rights_default VALUES('Search',5,0,0); 
     181INSERT INTO %prefix%rights_default VALUES('Search',5,1,1); 
    182182INSERT INTO %prefix%rights_default VALUES('Mail',1,1,1); 
    183183INSERT INTO %prefix%rights_default VALUES('Mail',2,1,1); 
  • trunk/includes/config/settings.tmpl

    r34 r36  
    3030$SETTINGS['polls'] = 1; // polls on (1) or off (0) 
    3131$SETTINGS['floodcontrol'] = 30; // number of seconds someone has to wait between two posts 
    32 $SETTINGS['floodcontrol_search'] = 10; // number of seconds someone has to wait between two searches 
     32$SETTINGS['floodcontrol_search'] = 15; // number of seconds someone has to wait between two searches 
    3333$SETTINGS['maxuploadsize'] = 102400; // maximum file size of attachments in bytes 
    3434$SETTINGS['uploadextensions'] = '.gif,.jpg,.jpeg,.bmp,.png,.zip,.rar,.ace,.7z,.txt,.rtf'; // allowed file extensions for attachments (seperated by commas)