source: trunk/search.php @ 1798

Revision 1798, 4.4 KB checked in by driehle, 3 years ago (diff)

Moved Jlog 1.5 branch into trunk/ as we will focus on Jlog 1.5 development in the future

  • Property svn:keywords set to Date Rev Author HeadURL
Line 
1<?php
2
3/**
4 * Jlog
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 *
20 * $HeadURL$
21 * $Rev$
22 * $Author$
23 * $Date$
24 **/
25
26require_once('./config.inc.php');
27require_once(JLOG_LIBPATH . '/bootstrap.php');
28
29
30 $c['meta']['robots']       = "noindex, follow";
31 $c['meta']['title'] = $l['content_search_header'];
32 $c['main'] = "<h2 class='search'>".$l['content_search_header']."</h2>";
33
34 $searchstring = strip($_GET['q']);
35
36    $c['main'] .= '     <form id="searchform" action="'.JLOG_PATH.'/search.php" accept-charset="UTF-8">
37      <p><input class="userdata" type="text" name="q" size="30" value="'.htmlspecialchars($searchstring, ENT_QUOTES).'" />
38         <input class="send" type="submit" value="'.$l['content_search'].'" /></p>
39     </form>
40     <script type="text/javascript">jlog_searchpage = true;</script>
41';
42
43if(!empty($searchstring)) {
44
45 $sql_searchstring = escape_for_mysql($searchstring);
46
47 $sql = "
48                SELECT
49                    id,
50                    url,
51                    UNIX_TIMESTAMP(date) AS date_url,
52                    0 AS comment_id,
53                    topic,
54                    UNIX_TIMESTAMP(date) AS date,
55                    keywords,
56                    teaser,
57                    section,
58                    comments,
59                    MATCH ( topic, keywords, teaser, content ) AGAINST ('".$sql_searchstring."') AS scoring
60                FROM ".JLOG_DB_CONTENT."
61                WHERE
62                  MATCH ( topic, keywords, teaser, content ) AGAINST ( '".$sql_searchstring."' )
63
64                UNION
65                SELECT
66                    ".JLOG_DB_COMMENTS.".reference AS id,
67                    ".JLOG_DB_CONTENT.".url AS url,
68                    UNIX_TIMESTAMP(".JLOG_DB_CONTENT.".date) AS date_url,
69                    ".JLOG_DB_COMMENTS.".id AS comment_id,
70                    name AS topic,
71                    UNIX_TIMESTAMP(".JLOG_DB_COMMENTS.".date) AS date,
72                    'comment_keywords' AS keywords,
73                    ".JLOG_DB_COMMENTS.".content AS teaser,
74                    'comment',
75                    2,
76                    MATCH(name, city, email, homepage, ".JLOG_DB_COMMENTS.".content) AGAINST ('".$sql_searchstring."') AS scoring
77                FROM ".JLOG_DB_COMMENTS.", ".JLOG_DB_CONTENT."
78                WHERE
79                  MATCH ( name, city, email, homepage, ".JLOG_DB_COMMENTS.".content ) AGAINST ( '".$sql_searchstring."' )
80                  AND ".JLOG_DB_COMMENTS.".reference = ".JLOG_DB_CONTENT.".id
81                  AND ".JLOG_DB_COMMENTS.".type = ''
82
83                ORDER BY scoring desc
84                LIMIT 40;";
85
86
87     $search = new Query($sql);
88     if($search->error()) {
89        echo "<pre>\n";
90        echo $search->getError();
91        echo "</pre>\n";
92        die();
93     }
94
95    if($search->numRows() < 1) {
96        $c['main'] .= "<p>".$l['content_nothing_found']."</p>";
97    }
98    else {
99        $cc = count_comments();
100        $c['main'] .= "<ul class='search'>\n";
101        while( $data = $search->fetch() ) {
102            $c['main'] .= " <li>";
103            if($data['comment_id'] == 0) $c['main'] .= do_teaser($data, $cc, '<h3>', '</h3>');
104            else {
105                $data['url'] = $data['url'].'#c'.$data['comment_id'];
106                if(empty($data['topic'])) $data['topic'] = $l['comments_anonym'];
107                $data['topic'] = $l['comments_by'].": ".$data['topic'];
108   
109                list($data['teaser']) = explode('|*|JLOG_BREAK|*|', wordwrap(str_replace("\n", ' ', html_entity_decode(strip_tags($bbcomments->parse(trim($data['teaser']))))), 300, ' ...|*|JLOG_BREAK|*|'));
110   
111                $c['main'] .= do_teaser($data, 0, '<h4>', '</h4>');
112            }
113            $c['main'] .= " </li>\n";
114        }
115        $c['main'] .= "</ul>\n";
116    }
117}
118require(JLOG_BASEPATH.'scripts'.DIRECTORY_SEPARATOR.'do_template.php');
119echo $body;
120
121// eof
Note: See TracBrowser for help on using the repository browser.