amalydia
05-28-2005, 02:35 AM
ever wanted a search addon, which searches headline (title) and body (description) of your database (table pixelpost)
just add <SEARCH_BOX> where you want the searchbox
and <SEARCH_RESULTS> in a new template file named search_template.php
and here comes the code for search.php
<?php
/*
Requires Pixelpost version 1.4 or newer
Search_ADDon 0.1
Written by: Mirko Theophil aka amalYdia
http://www.amalydia.de
Pixelpost www: http://www.pixelpost.org/
License: http://www.gnu.org/copyleft/gpl.html
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
================================================== ==========================
NEW TAGS:
<SEARCH_RESULT>
<SEARCH_BOX>
*/
$addon_name = "Search (for PP v1.4)";
$addon_version = "0.1";
$addon_description = "$attention_call Simple Search ADDon for PP1.4.1 by amalydia.de";
//-------------------------------- SEARCH BOX
$search_box = "<form method='post' action='index.php?x=search' name='searchform' >
<label><input type='text' name='q' class='input' value='suche' /></label>
<input type='submit' value='GO' class='commentbutton' />";
$tpl = str_replace("<SEARCH_BOX>",$search_box,$tpl);
//-------------------------------- SEARCH FUNCTION
$query = mysql_query('SELECT * '
. ' FROM `'.$pixelpost_db_prefix.'pixelpost` '
. ' WHERE (`headline` '
. ' LIKE \'%'.$q.'%\' OR `body` '
. ' LIKE \'%'.$q.'%\') LIMIT 0, 30');
$i=0;
while( $row=mysql_fetch_array($query) )
{
$image_name = $row['image'];
$image_title = pullout($row['headline']);
$image_id = $row['id'];
$image_title = htmlspecialchars($image_title,ENT_QUOTES);
$image_thumbnail_no_link = "<img src='thumbnails/thumb_$image_name' alt='$image_title' title='$image_title' />";
$search_links .= "<a href='$showprefix$image_id'>$image_thumbnail_no_link</a>";
$i++;
}
if(!$search_links) {
$search_links = "Keine Ergebnisse zum Suchbegriff <i>".$q."</i> gefunden!<br/><br/>";
}
$tpl = str_replace("<SEARCH_RESULTS>",$search_links,$tpl);
?>
just add <SEARCH_BOX> where you want the searchbox
and <SEARCH_RESULTS> in a new template file named search_template.php
and here comes the code for search.php
<?php
/*
Requires Pixelpost version 1.4 or newer
Search_ADDon 0.1
Written by: Mirko Theophil aka amalYdia
http://www.amalydia.de
Pixelpost www: http://www.pixelpost.org/
License: http://www.gnu.org/copyleft/gpl.html
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
================================================== ==========================
NEW TAGS:
<SEARCH_RESULT>
<SEARCH_BOX>
*/
$addon_name = "Search (for PP v1.4)";
$addon_version = "0.1";
$addon_description = "$attention_call Simple Search ADDon for PP1.4.1 by amalydia.de";
//-------------------------------- SEARCH BOX
$search_box = "<form method='post' action='index.php?x=search' name='searchform' >
<label><input type='text' name='q' class='input' value='suche' /></label>
<input type='submit' value='GO' class='commentbutton' />";
$tpl = str_replace("<SEARCH_BOX>",$search_box,$tpl);
//-------------------------------- SEARCH FUNCTION
$query = mysql_query('SELECT * '
. ' FROM `'.$pixelpost_db_prefix.'pixelpost` '
. ' WHERE (`headline` '
. ' LIKE \'%'.$q.'%\' OR `body` '
. ' LIKE \'%'.$q.'%\') LIMIT 0, 30');
$i=0;
while( $row=mysql_fetch_array($query) )
{
$image_name = $row['image'];
$image_title = pullout($row['headline']);
$image_id = $row['id'];
$image_title = htmlspecialchars($image_title,ENT_QUOTES);
$image_thumbnail_no_link = "<img src='thumbnails/thumb_$image_name' alt='$image_title' title='$image_title' />";
$search_links .= "<a href='$showprefix$image_id'>$image_thumbnail_no_link</a>";
$i++;
}
if(!$search_links) {
$search_links = "Keine Ergebnisse zum Suchbegriff <i>".$q."</i> gefunden!<br/><br/>";
}
$tpl = str_replace("<SEARCH_RESULTS>",$search_links,$tpl);
?>