root/trunk/common/livesearch.php

Revision 776, 1.8 KB (checked in by michiel, 9 months ago)

update copyright year.

Closes #180

  • Property svn:keywords set to Id
Line 
1<?php
2/**
3 * MvBlog -- An open source no-nosense blogtool
4 *
5 * Copyright (C) 2005-2008, Michiel van Baak
6 * Michiel van Baak <mvanbaak@users.sourceforge.net>
7 *
8 * See http://www.mvblog.org for more information on MvBlog.
9 * That page also provides Bugtrackers, Filereleases etc.
10 *
11 * This program is free software, distributed under the terms of
12 * the GNU General Public License Version 2. See the LICENSE file
13 * at the top of the source tree.
14 *
15 * @package MvBlog
16 * @author Michiel van Baak
17 * @version %%VERSION%%
18 * @copyright 2005-2008 Michiel van Baak
19 */
20require("mvblog.php");
21$mvblog = new MvBlog();
22//get all the authors in an array
23$res =& $mvblog->db->query("SELECT * FROM authors");
24
25if (PEAR::isError($res)) {
26    die($res->getMessage());
27}
28
29while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
30    $authors[$row["id"]]["fullname"] = $row["fullname"];
31    $authors[$row["id"]]["email"]    = $row["email"];
32}
33
34$searchstring = urldecode($_REQUEST["s"]);
35$query  = "SELECT id,title FROM articles WHERE public=1 AND active=1 AND aside=0 AND";
36$query .= sprintf(" (upper(title) LIKE '%%%s%%' OR upper(head) LIKE '%%%s%%' OR upper(body) LIKE '%%%s%%')",
37    preg_quote(strip_tags(strtoupper($searchstring)), "'"),
38    preg_quote(strip_tags(strtoupper($searchstring)), "'"),
39    preg_quote(strip_tags(strtoupper($searchstring)), "'")
40);
41$query .= " ORDER BY date DESC";
42
43$mvblog->db->setLimit(5);
44$res =& $mvblog->db->query($query);
45$ret = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
46$ret .= "<channel>\n";
47$ret .= "\t<title>search results</title>\n";
48
49while ($row = $res->fetchRow()) {
50    if (!trim($row[1])) {
51        $row[1] = "[no title]";
52    }
53    $ret .= "\t<item>\n";
54    $ret .= "\t\t<articleID>".$row[0]."</articleID>\n";
55    $ret .= "\t\t<articleTitle>".stripslashes($row[1])."</articleTitle>\n";
56    $ret .= "\t</item>\n";
57}
58$ret .= "</channel>\n";
59header("Content-Type: text/xml");
60echo $ret;
61?>
Note: See TracBrowser for help on using the browser.