Location: PHPKode > projects > ProNuke. Postnuke To Oracle > postnuke/html/includes/blocks/stories.php
<?php
// File: $Id: stories.php,v 1.17 2001/12/04 00:50:23 gregorrothfuss Exp $
// ----------------------------------------------------------------------
// POST-NUKE Content Management System
// Copyright (C) 2001 by the Post-Nuke Development Team.
// http://www.postnuke.com/
// ----------------------------------------------------------------------
// Based on:
// PHP-NUKE Web Portal System - http://phpnuke.org/
// Thatware - http://thatware.org/
// ----------------------------------------------------------------------
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// 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.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------
// Original Author of file: Jim McDonald
// Purpose of file: Display titles of stories, with lots of options
// ----------------------------------------------------------------------

$blocks_modules['stories'] = array(
    'func_display' => 'blocks_stories_block',
    'func_edit' => 'blocks_stories_select',
    'func_update' => 'blocks_stories_update',
    'text_type' => 'Stories',
    'text_type_long' => 'Story Titles',
    'allow_multiple' => true,
    'form_content' => false,
    'form_refresh' => false,
    'show_preview' => true
);

// security schema not needed - uses 'Stories'

function blocks_stories_block($row)
{
    global $pntable, $dbconn, $pnconfig;

    // Break out options from our content field
    $vars = getVarsFromContent($row);
    $row['content'] = "";


    // Base query
    $storiescolumn = &$pntable['stories_column'];
    $storiescatcolumn = &$pntable['stories_cat_column'];

    $query = "SELECT $storiescolumn[sid],
                     $storiescolumn[title] ,
                     $storiescatcolumn[title],
                     $storiescolumn[time]
                     FROM $pntable[stories], $pntable[stories_cat]
                     WHERE $storiescolumn[catid] = $storiescatcolumn[catid]";


    // Qualifier for front-page/not front-page news
    // type = 0 - front-page news
    // type = 1 - not front-page news
    // type = 2 - all news

//FTO : Use ihome from PNTables

    if ($vars['type'] != 2) {

        $query .= " AND $storiescolumn[ihome]=$vars[type]";
    }

    // Qualifier for particular topic
    // topic = -1 - all topics

//FTO : Use topic from PNTables
    if ($vars['topic'] != -1) {
        $query .= " AND $storiescolumn[topic]=$vars[topic]";
    }

    // Qualifier for particular category
    // category = -1 - all categories
    if ($vars['category'] != -1) {
        $query .= " AND category=$vars[category]";
    }

    // Qualifier for how many stories

    if ( strstr('oci8,oracle,oci8po,oracle_odbc',$pnconfig['dbtype'] ) )
        $query .= " ORDER BY $storiescolumn[time] DESC";

    $result = $dbconn->SelectLimit($query,$vars['limit']);

    // FTO Check EOF and database error

    if (!$result) {
        PN_DBMsgError($dbconn, __FILE__, __LINE__, "An error ocurred");
        die();
    }

    while(! $result->EOF ) {

        list($sid, $title, $cattitle, $time) = $result->fields;

        $time=$result->UnixTimeStamp($time);
        if (authorised(0, 'Stories::', "$aid:$cattitle:$sid", ACCESS_READ)) {
            $row['content'] .= "<strong><big>&middot;</big></strong>&nbsp;<font class=\"pn-sub\"><a class=\"pn-normal\" href=\"modules.php?op=modload&amp;name=News&amp;file=article&amp;sid=$sid\">$title</a> (".ml_ftime(_DATEBRIEF,$time).")</font><br>\n";
        }
        $result->MoveNext();
    }
    if (!empty($row['content'])) {
        themesideblock($row);
    }
}

function blocks_stories_select($row)
{
    global $pntable, $dbconn;

    // Break out options from our content field
    $vars = getVarsFromContent($row);
    $row['content'] = "";

    // Which stories to list
    $output = "<tr><td class=\"pn-normal\">Display all stories:</td><td><input type=\"radio\" name=\"type\" value=\"2\"";
    if ($vars[type] == 2) {
        $output .= " checked";
    }
    $output .= "></td></tr><td class=\"pn-normal\">Display only front-page stories:</td><td><input type=\"radio\" name=\"type\" value=\"0\"";
    if ($vars[type] == 0) {
        $output .= " checked";
    }
    $output .= "></td></tr><td class=\"pn-normal\">Display only non-front-page stories:</td><td><input type=\"radio\" name=\"type\" value=\"1\"";
    if ($vars[type] == 1) {
        $output .= " checked";
        
    }
    $output .= "></td></tr>";
    
    // Which topic
    $output .= "<td class=\"pn-normal\">Topic:</td><td><select name=\"topic\" size=\"1\">";
    $output .= "<option name=\"topic\" value=\"-1\"";
    if ($vars[topic] == -1) {
        $output .= " selected";
    }
    $output .= ">"._ALL."</option>";

    $query = "SELECT topicname, topicid FROM $pntable[topics] ORDER BY topicname";
    $result = $dbconn->Execute($query);
    while(!$result->EOF) {
        $srow = $result->GetRowAssoc(false);
        $result->MoveNext();
        $output .= "<option name=\"topic\" value=\"$srow[topicid]\"";
        if ($vars[topic] == $srow[topicid]) {
            $output .= " selected";
        }
        $output .= ">$srow[topicname]</option>";
    }
    $output .= "</select></td></tr>";

    // Which category
    $output .= "<td class=\"pn-normal\">Category:</td><td><select name=\"category\" size=\"1\">";
    $output .= "<option name=\"category\" value=\"-1\"";
    if ($vars[category] == -1) {
        $output .= " selected";
    }
    $output .= ">"._ALL."</option>";

    $query = "SELECT title, catid FROM $pntable[stories_cat] ORDER BY title";
    $result = $dbconn->Execute($query);
    while(!$result->EOF) {
        $srow = $result->GetRowAssoc(false);
        $result->MoveNext();
        $output .= "<option name=\"category\" value=\"$srow[catid]\"";
        if ($vars[category] == $srow[catid]) {
            $output .= " selected";
        }
        $output .= ">$srow[title]</option>";
    }
    $output .= "</select></td></tr>";

    // Number of stories
    $output .= "<tr><td class=\"pn-normal\">Maximum number of stories to display:</td><td><input type=\"text\" name=\"limit\" size=\"2\" value=\"$vars[limit]\"></td></tr>";

    return $output;
}

function blocks_stories_update($row)
{
    global $HTTP_POST_VARS;

    $row['content']="type=$HTTP_POST_VARS[type]
                     topic=$HTTP_POST_VARS[topic]
                     category=$HTTP_POST_VARS[category]
                     limit=$HTTP_POST_VARS[limit]";

    return($row);
}

// Get variables from content
// Format of variables:
//  name=val
//  name=val
function getVarsFromContent($row)
{

//FTO : MySQL parse \n as \r\n in the content
//            but not Oracle. Good Idea to parse with other cars.
// Why not XML syntax ?

//kill every \r (true or false) and use <:> separator

    $row['content'] = str_replace("\\r","",$row['content']);
    $row['content'] = str_replace("\\n","<:>",$row['content']);
    $row['content'] = str_replace("\r","",$row['content']);
    $row['content'] = str_replace("\n","<:>",$row['content']);
    
    $links = explode("<:>", $row['content']);
    $vars = array();

    foreach ($links as $link) {
        $link = trim($link);
        if ($link) {
            $var = explode("=", $link);
            $vars = array_merge($vars, array($var[0] => $var[1]));
        }
    }

    // Defaults
    if (empty($vars['type'])) {
        $vars['type'] = 2;
    }
    if (empty($vars['topic'])) {
        $vars['topic'] = -1;
    }
    if (empty($vars['topic'])) {
        $vars['topic'] = -1;
    }
    if (empty($vars['category'])) {
        $vars['category'] = -1;
    }
    if (empty($vars['limit'])) {
        $vars['limit'] = 10;
    }

    return($vars);
}

?>
Return current item: ProNuke. Postnuke To Oracle