Here is the ID search hack we implemented in our PMF:
In the functions.php find: (line 1261 to 1320)
if (0 == $num) {
$keys = preg_split("/\s+/", $begriff);
$numKeys = count($keys);
$where = '';
for ($i = 0; $i < $numKeys; $i++) {
if (strlen($where) != 0 ) {
$where = $where." OR ";
}
$where = $where.'('.SQLPREFIX."faqdata.thema LIKE '%".$keys[$i]."%' OR ".SQLPREFIX."faqdata.content LIKE '%".$keys[$i]."%' OR ".SQLPREFIX."faqdata.keywords LIKE '%".$keys[$i]."%') AND ".SQLPREFIX.'faqdata.active = \'yes\'';
}
$where = " WHERE (".$where.") AND active = 'yes'";
$query = 'SELECT '.SQLPREFIX.'faqdata.id AS id, '.SQLPREFIX.'faqdata.lang AS lang, '.SQLPREFIX.'faqcategoryrelations.category_id AS category_id, '.SQLPREFIX.'faqdata.thema AS thema, '.SQLPREFIX.'faqdata.content AS content FROM '.SQLPREFIX.'faqdata LEFT JOIN '.SQLPREFIX.'faqcategoryrelations ON '.SQLPREFIX.'faqdata.id = '.SQLPREFIX.'faqcategoryrelations.record_id AND '.SQLPREFIX.'faqdata.lang = '.SQLPREFIX.'faqcategoryrelations.record_lang '.$where;
$result = $db->query($query);
$num = $db->num_rows($result);
}
$pages = ceil($num / $PMF_CONF["numRecordsPage"]);
$last = $seite * $PMF_CONF["numRecordsPage"];
$first = $last - $PMF_CONF["numRecordsPage"];
if ($last > $num) {
$last = $num;
}
if ($num > 0) {
if ($num == "1") {
$output .= "<p>".$num.$PMF_LANG["msgSearchAmount"]."</p>\n";
} else {
$output .= "<p>".$num.$PMF_LANG["msgSearchAmounts"]."</p>\n";
}
if ($pages > 1) {
$output .= "<p><strong>".$PMF_LANG["msgPage"].$seite." ".$PMF_LANG["msgVoteFrom"]." ".$pages.$PMF_LANG["msgPages"]."</strong></p>";
}
$output .= "<ul class=\"phpmyfaq_ul\">\n";
$counter = 0;
$displayedCounter = 0;
while (($row = $db->fetch_object($result)) && $displayedCounter < $PMF_CONF['numRecordsPage']) {
$counter ++;
if ($counter <= $first) {
continue;
}
$displayedCounter++;
$rubriktext = $tree->getPath($row->category_id);
$thema = PMF_htmlentities(chopString($row->thema, 15),ENT_NOQUOTES, $PMF_LANG['metaCharset']);
$content = stripslashes(chopString(strip_tags($row->content), 25));
$begriff = str_replace(array('^', '.', '?', '*', '+', '{', '}', '(', ')', '[', ']'), '', $begriff);
$begriff = preg_quote($begriff, '/');
if (strlen($begriff) > 1) {
$thema = preg_replace_callback('/(((href|src|title|alt|class|style|id|name)="[^"]*)?'.$begriff.'(?(1).*"))/mis', "highlight_no_links", $thema);
$content = preg_replace_callback('/(((href|src|title|alt|class|style|id|name)="[^"]*)?'.$begriff.'(?(1).*"))/mis', "highlight_no_links", $content);
}
$output .= "<li><strong>".$rubriktext."</strong>: <a href=\"".$_SERVER["PHP_SELF"]."?".$sids."action=artikel&cat=".$row->category_id."&id=".$row->id."&highlight=".$begriff."\">".stripslashes($thema)."...</a><br /><div style=\"font-size: 10px;\"><strong>".$PMF_LANG["msgSearchContent"]."</strong> ".stripslashes($content)."...</div><br /></li>\n";
}
$output .= "</ul>\n";
}
And replace it with: (Red is what has been modified)
if (0 == $num) {
$keys = preg_split("/\s+/", $begriff);
$numKeys = count($keys);
$where = '';
for ($i = 0; $i < $numKeys; $i++) {
if (strlen($where) != 0 ) {
$where = $where." OR ";
}
$where = $where.'('.SQLPREFIX."faqdata.thema LIKE '%".$keys[$i]."%' OR ".SQLPREFIX."faqdata.content LIKE '%".$keys[$i]."%' OR ".SQLPREFIX."faqdata.keywords LIKE '%".$keys[$i]."%') AND ".SQLPREFIX.'faqdata.active = \'yes\'';
}
if (is_numeric($begriff))
{
$where = " WHERE faqdata.id =" .$begriff. " AND active = 'yes'";
$query="SELECT faqdata.id AS id, faqdata.lang AS lang, 0 AS category_id, faqdata.thema AS thema, faqdata.content AS content FROM faqdata " .$where;
}
else
{
$where = " WHERE (".$where.") AND active = 'yes'";
$query = 'SELECT '.SQLPREFIX.'faqdata.id AS id, '.SQLPREFIX.'faqdata.lang AS lang, '.SQLPREFIX.'faqcategoryrelations.category_id AS category_id, '.SQLPREFIX.'faqdata.thema AS thema, '.SQLPREFIX.'faqdata.content AS content FROM '.SQLPREFIX.'faqdata LEFT JOIN '.SQLPREFIX.'faqcategoryrelations ON '.SQLPREFIX.'faqdata.id = '.SQLPREFIX.'faqcategoryrelations.record_id AND '.SQLPREFIX.'faqdata.lang = '.SQLPREFIX.'faqcategoryrelations.record_lang '.$where;
}
$result = $db->query($query);
$num = $db->num_rows($result);
}
$pages = ceil($num / $PMF_CONF["numRecordsPage"]);
$last = $seite * $PMF_CONF["numRecordsPage"];
$first = $last - $PMF_CONF["numRecordsPage"];
if ($last > $num) {
$last = $num;
}
if ($num > 0) {
if ($num == "1") {
$output .= "<p>".$num.$PMF_LANG["msgSearchAmount"]."</p>\n";
} else {
$output .= "<p>".$num.$PMF_LANG["msgSearchAmounts"]."</p>\n";
}
if ($pages > 1) {
$output .= "<p><strong>".$PMF_LANG["msgPage"].$seite." ".$PMF_LANG["msgVoteFrom"]." ".$pages.$PMF_LANG["msgPages"]."</strong></p>";
}
$output .= "<ul class=\"phpmyfaq_ul\">\n";
$counter = 0;
$displayedCounter = 0;
while (($row = $db->fetch_object($result)) && $displayedCounter < $PMF_CONF['numRecordsPage']) {
$counter ++;
if ($counter <= $first) {
continue;
}
$displayedCounter++;
$rubriktext = $tree->getPath($row->category_id);
$thema = PMF_htmlentities(chopString($row->thema, 15),ENT_NOQUOTES, $PMF_LANG['metaCharset']);
$content = stripslashes(chopString(strip_tags($row->content), 25));
$begriff = str_replace(array('^', '.', '?', '*', '+', '{', '}', '(', ')', '[', ']'), '', $begriff);
$begriff = preg_quote($begriff, '/');
if (strlen($begriff) > 1) {
$thema = preg_replace_callback('/(((href|src|title|alt|class|style|id|name)="[^"]*)?'.$begriff.'(?(1).*"))/mis', "highlight_no_links", $thema);
$content = preg_replace_callback('/(((href|src|title|alt|class|style|id|name)="[^"]*)?'.$begriff.'(?(1).*"))/mis', "highlight_no_links", $content);
}
if ($row->category_id==0)
$output .= "<li><strong>".$PMF_LANG["msgArticleId"].$row->id." </strong> <a href=\"".$_SERVER["PHP_SELF"]."?".$sids."action=artikel&cat=".$row->category_id."&id=".$row->id."&highlight=".$begriff."\">".stripslashes($thema)."...</a><br /><div style=\"font-size: 10px;\"><strong>".$PMF_LANG["msgSearchContent"]."</strong> ".stripslashes($content)."...</div><br /></li>\n";
else
$output .= "<li><strong>".$rubriktext."</strong>: <a href=\"".$_SERVER["PHP_SELF"]."?".$sids."action=artikel&cat=".$row->category_id."&id=".$row->id."&highlight=".$begriff."\">".stripslashes($thema)."...</a><br /><div style=\"font-size: 10px;\"><strong>".$PMF_LANG["msgSearchContent"]."</strong> ".stripslashes($content)."...</div><br /></li>\n";
}
$output .= "</ul>\n";
}
Basically if what you put on the search box is only a number, it looks for the particular article id. When the query is done it shows the article once even if it belongs to multiple categories. Also shows the article ID and strips the category as well.
If the search box has a character other than a number it follows the normal search.
To show the article ID in your articles you will have to add the following:
In the language_en.php
I added:
$PMF_LANG["msgArticleId"] = "Article ID: ";
under // Contentpages
In the artikel.php I added the red line
$tpl->processTemplate ("writeContent", array(
"writeId" => $PMF_LANG["msgArticleId"].$id,
"writeRubrik" => $writeCategory,
In order for the article id to show: In the template artikel.tpl add
{writeId} whereever you want the article ID to show
Now I only need to do the search ID hack in the admin area.
