Location: PHPKode > projects > ProNuke. Postnuke To Oracle > postnuke/html/includes/search/stories.php
<?php // $Id: stories.php,v 1.30 2001/12/06 19:36:39 proca Exp $ $Name:  $
// ----------------------------------------------------------------------
// Post-Nuke: Content Management System
// ====================================
// Module: Search/stories/topics plugin
//
// Copyright (c) 2001 by the Post Nuke development team
// http://www.postnuke.com
// -----------------------------------------------------------------------
// Modified version of:
//
// Search Module
// ===========================
//
// Copyright (c) 2001 by Patrick Kellum (hide@address.com)
// http://www.ctarl-ctarl.com
//
// 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.
//
//
// Filename: modules/Search/stories.php
// Original Author: Patrick Kellum
// Purpose: Search reviews/users/stories/topics
// -----------------------------------------------------------------------

$myts = new MyTextSanitizer; // MyTextSanitizer object

$search_modules[] = array(
    'title' => 'Stories',
    'func_search' => 'search_stories',
    'func_opt' => 'search_stories_opt'
);
function search_stories_opt($vars) {
    global
        $bgcolor1,
        $bgcolor2,
        $bgcolor3,
        $textcolor1,
        $textcolor2,
        $pntable,
        $dbconn
    ;
    print "<table border=\"0\" width=\"100%\"><tr bgcolor=\"$bgcolor2\"><td><font class=\"pn-normal\" style=\"$text-color:$textcolor1\"><input type=\"checkbox\" name=\"active_stories\" id=\"active_stories\" value=\"1\" checked>&nbsp;<label for=\"active_stories\">"._SEARCH_STORIES_TOPICS."</label></font></td></tr></table>";
    print "<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\" summary=\"Search form to help in locating the stories you are looking for.\">"
// topics
        ."<tr>"
        ."<td nowrap align=\"right\" valign=\"top\"><font class=\"pn-normal\"><label for=\"stories_topics[]\">Topics</label>:</font></td>"
        ."<td><select name=\"stories_topics[]\" id=\"stories_topics[]\" multiple>"
        ."<option value=\"\" selected>"._SRCHALLTOPICS."</option>"
    ;
    $column = &$pntable['topics_column'];
    error_log("SELECT $column[tid] as topicid, $column[topictext] as topictext
                              FROM $pntable[topics]
                              ORDER BY $column[topictext]");
    $result = $dbconn->Execute("SELECT $column[tid] as topicid, $column[topictext] as topictext
                              FROM $pntable[topics]
                              ORDER BY $column[topictext]");

    while(!$result->EOF) {
        $row = $result->GetRowAssoc(false);
        if(strlen($row['topictext']) > 23) {
            $row['topictext'] = substr($row['topictext'],0,20) . '...';
        }
        print "<option value=\"$row[topicid]\">$row[topictext]</option>\n";
        $result->MoveNext();
    }
    print "</select></td>"
// categories
        ."</tr>"
        ."<tr>"
        ."<td nowrap align=\"right\" valign=\"top\"><font class=\"pn-normal\"><label for=\"stories_cat[]\">Categories</label>:</font></td>"
        ."<td><select name=\"stories_cat[]\" id=\"stories_cat[]\" multiple>"
        ."<option value=\"\" selected>All Categories</option>"
    ;
    $column = &$pntable['stories_cat_column'];
    $result = $dbconn->Execute("SELECT $column[catid] as catid, $column[title] as title
                              FROM $pntable[stories_cat]
                              ORDER BY $column[title]");

    while(!$result->EOF) {
        $row = $result->GetRowAssoc(false);
        if(strlen($row['title']) > 23) {
            $row['title'] = substr($row['title'],0,20) . '...';
        }
        print "<option value=\"$row[catid]\">$row[title]</option>\n";
        $result->MoveNext();
    }
    print "</select></td>"
        ."</tr>"
// author
        ."<tr>"
        ."<td nowrap align=\"right\" valign=\"top\"><font class=\"pn-normal\"><label for=\"stories_author\">Author</label>:</font></td>"
        ."<td colspan=\"3\"><font class=\"pn-normal\"><input type=\"text\" name=\"stories_author\" id=\"stories_author\" size=\"20\" maxlength=\"255\"></font></td>"
        ."</tr>"
        ."</table>"
    ;
}
function search_stories($vars) {

    if(!$vars['active_stories']) {
        return;
    }
    global
        $myts,
        $bgcolor1,
        $bgcolor2,
        $bgcolor3,
        $textcolor1,
        $textcolor2,
        $pntable,
        $dbconn,
        $currentlang,
        $multilingual
    ;
    $w = search_split_query($vars['q']);
    $flag = false;
        
    $storcol = &$pntable['stories_column'];
    $stcatcol = &$pntable['stories_cat_column'];
    $topcol = &$pntable['topics_column'];
    $query = "SELECT $storcol[sid] as sid, $topcol[tid] as topicid, $topcol[topictext] as topictext, $storcol[catid] as catid, $storcol[time] AS fdate, $storcol[title] AS story_title, $stcatcol[title] AS cat_title FROM $pntable[stories]";
    $query.= " LEFT JOIN $pntable[stories_cat] ON ($storcol[catid]=$stcatcol[catid]) LEFT JOIN $pntable[topics] ON ($storcol[topic]=$topcol[tid]) WHERE ";

// words
    foreach($w as $word) {
        if($flag) {
            switch($vars['bool']) {
                case 'AND' :
                    $query .= ' AND ';
                    break;
                case 'OR' :
                default :
                    $query .= ' OR ';
                    break;
            }
        }
        $query .= '(';
        $query .= "$storcol[title] LIKE '$word' OR ";
        $query .= "$storcol[hometext] LIKE '$word' OR ";
        $query .= "$storcol[bodytext] LIKE '$word' OR ";
        $query .= "$storcol[comments] LIKE '$word' OR ";
        $query .= "$storcol[informant] LIKE '$word' OR ";
        $query .= "$storcol[notes] LIKE '$word'";
        $query .= ')';
        $flag = true;
    }
// topics
    if($vars['stories_topics'][0]) {
        $query .= " AND (";
        $flag = false;
        foreach($vars['stories_topics'] as $v) {
            if($flag) {
                $query .= " OR ";
            }
            $query .= "$storcol[topic]=$v";
            $flag = true;
        }
        $query .= ") ";
    }
// categories
    if($vars['stories_cat'][0]) {
        $query .= " AND (";
        $flag = false;
        foreach($vars['stories_cat'] as $v) {
            if($flag) {
                $query .= " OR ";
            }
            $query .= "$stcatcol[catid]=$v";
            $flag = true;
        }
        $query .= ") ";
    }
// authors
    if($vars['stories_author']) {
        $query .= " AND (";
        $query .= "$storcol[informant] LIKE '%$vars[stories_author]%'";

        $result = $dbconn->Execute("SELECT {$pntable['users_column']['uid']} as uid FROM $pntable[users] WHERE {$pntable['users_column']['uname']} LIKE '%$vars[stories_author]%' OR {$pntable['users_column']['name']} LIKE '%$vars[stories_author]%'");
         while(!$result->EOF) {
             $row = $result->GetRowAssoc(false);
             $query .= " OR $storcol[aid]=$row[uid]";
             $result->MoveNext();
         }
        $query .= ") ";
    }

    if ($multilingual == 1) {
           $query .= " AND ($storcol[alanguage]='$currentlang' OR $storcol[alanguage]='')";
    }
    $query .= " ORDER BY $storcol[time] DESC";
    $result = $dbconn->Execute($query);
//FTO Replace record count by a counter
//    $total_rows = $result->PO_Record Count();
    $total_rows=0;
    if($vars['overview']) {
        $result->Close();
        // fifers - only run if necessary!
        $result = $dbconn->SelectLimit($query,3);
    }

    if(!$result->EOF) {
        print ""._STORIES_TOPICS.":";

        $output="";
        while(!$result->EOF) {
            $total_rows++;
            $row = $result->GetRowAssoc(false);
            $row['fdate'] = strftime(_DATELONG,$result->UnixTimeStamp($row['fdate']));
            $row[story_title] = $myts->makeTareaData4Show($row[story_title]);
            $output .= "<li><b><a class=\"pn-normal\" href=\"modules.php?op=modload&amp;name=Search&amp;file=index&amp;action=search&amp;overview=1&amp;active_stories=1&amp;stories_topics[0]=$row[topicid]\">$row[topictext]</a></b> - <a href=\"index.php?catid=$row[catid]\">$row[cat_title]</a><br>";
            If (!$row[story_title])  {
                $row[story_title] = 'no Title' ;
            }
            $output .= "<i><a class=\"pn-normal\" href=\"modules.php?op=modload&amp;name=News&amp;file=article&amp;sid=$row[sid]\">$row[story_title]</a></i><br>"
               ."$row[fdate]</li>\n"
           ;
           $result->MoveNext();
        }
        if($total_rows > 3 && $vars['overview']) {
        // Rebuild the search string from previous information
            print " <a class=\"pn-normal\" href=\"modules.php?op=modload&amp;name=Search&amp;file=index&amp;action=search&amp;active_stories=1&amp;stories_author=$vars[stories_author]";
            if ($vars['stories_cat']) {
               foreach($vars['stories_cat'] as $v) {
               print "&amp;stories_cat%5B%5D=$v";
               }
            }
            if ($vars['stories_topics']){
               foreach($vars['stories_topics'] as $v) {
               print "&amp;stories_topics%5B%5D=$v";
               }
            }
            print "&amp;bool=$vars[bool]&amp;q=$vars[q]\">"._SEEALL." $total_rows "._RESULTS."...</a>";
        }
        print "<ul>";

        print $output;

        print "</ul>\n";
    }
    else {
        print '<font class=\"pn-normal\">'._SEARCH_NO_STORIES_TOPICS.'</font>';
    }
    print "<br>";
}
?>
Return current item: ProNuke. Postnuke To Oracle