Location: PHPKode > projects > ProNuke. Postnuke To Oracle > postnuke/html/includes/blocks/random.php
<?php
// File: $Id: random.php,v 1.18 2001/12/04 00:50:23 gregorrothfuss Exp $ $Name:  $
// ----------------------------------------------------------------------
// 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: Francisco Burzi
// Purpose of file:
// ----------------------------------------------------------------------

$blocks_modules['random'] = array(
    'func_display' => 'blocks_random_block',
    'text_type' => 'Random',
    'text_type_long' => 'Random Headlines',
    'allow_multiple' => false,
    'form_content' => false,
    'form_refresh' => false,
    'show_preview' => true
);


function blocks_random_block($row) {
    global $pntable, $dbconn, $multilingual, $currentlang; /* ML added globals and querylang */

    if ($multilingual == 1) {
        $column = &$pntable['stories_column'];

//FTO: Add is NULL clause for Oracle
//FTO : Use internal php randomize instead of mysql rand()

        $result = $dbconn->Execute("SELECT COUNT(*) FROM $pntable[topics]");
        list($maxrow) = $result->fields;
        srand((float) microtime()*100000000);
        $randval = rand(0,$maxrow);

        $querylang = "AND ($column[alanguage]='$currentlang' OR $column[alanguage]='' OR $column[alanguage] IS NULL)"; /* the OR is needed to display stories who are posted to ALL languages */
    } else {
        $querylang = "";
    }
    // find out what random topic to pick.  fifers notes: relies on sequential topic numbering with no holes
    $column = &$pntable['topics_column'];

//FTO : Use PHP randomize
//    $sql = "SELECT $column[topicid] FROM $pntable[topics] ORDER BY RAND()";
    $sql = "SELECT $column[topicid] FROM $pntable[topics] WHERE $column[topicid] >= $randval";

    $result = $dbconn->SelectLimit($sql,1);
    $topic = $result->fields[0];

    // grab the random topic and a link to it
    $content = "<font class=\"pn-normal\">";
    $column = &$pntable['topics_column'];
    $result = $dbconn->Execute("SELECT $column[topictext] FROM $pntable[topics] where $column[topicid]=$topic");
    list($topictext) = $result->fields;
    $title2 = "<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]=$topic\">$topictext</a>";

    $column = &$pntable['stories_column'];
	$sql = "SELECT $column[sid], $column[title] FROM $pntable[stories]
                              WHERE $column[topic]='$topic' $querylang
                              ORDER BY $column[sid] DESC";
    $result = $dbconn->SelectLimit($sql,9);

    //FTO. Test EOF and database error

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

    while(!$result->EOF) {
        list($sid, $title) = $result->fields;
        $content .= "<strong><big>&middot;</big></strong>&nbsp;<a class=\"pn-normal\" href=\"modules.php?op=modload&amp;name=News&amp;file=article&amp;sid=$sid\">$title</a><br>";
        $result->MoveNext();
    }
    $content .= "</font>";
    $row['title'] = $title2;
    $row['content'] = $content;
    themesideblock($row);
}
?>
Return current item: ProNuke. Postnuke To Oracle