Location: PHPKode > projects > ProNuke. Postnuke To Oracle > postnuke/html/modules/News/funcs.php
<?php
// File: $Id: funcs.php,v 1.21 2001/12/10 20:55:15 niceguyeddie 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: Utility functions for news
// ----------------------------------------------------------------------

/*
 * Get an array of articles given specific
 * where and limit clauses
 */
function getArticles($where, $order, $limit) {

	global $dbconn, $currentlang, $multilingual, $pntable, $pnconfig;

    // Columns
    $storiescolumn = $pntable['stories_column'];
    $storiescatcolumn= $pntable['stories_cat_column'];
    $topicscolumn = $pntable['topics_column'];

    // Base query
    $query = "SELECT $storiescolumn[aid] AS \"aid\",
                    $storiescolumn[bodytext] AS \"bodytext\",
                    $storiescatcolumn[themeoverride] AS \"catthemeoverride\",
                    $storiescolumn[catid] AS \"cid\",
                    $storiescatcolumn[title] AS \"cattitle\",
                    $storiescolumn[comments] AS \"comments\",
                    $storiescolumn[counter] AS \"counter\",
                    $storiescolumn[hometext] AS \"hometext\",
                    $storiescolumn[informant] AS \"informant\",
                    $storiescolumn[notes] AS \"notes\",
                    $storiescolumn[sid] AS \"sid\",
                    $storiescolumn[themeoverride] AS \"themeoverride\",
                    $topicscolumn[topicid] AS \"tid\",
                    $storiescolumn[time] AS \"time\",
                    $storiescolumn[title] AS \"title\",
                    $topicscolumn[topicname] AS \"topicname\",
                    $topicscolumn[topicimage] AS \"topicimage\",
                    $topicscolumn[topictext] AS \"topictext\",
                    $topicscolumn[counter] AS \"tcounter\",
                    $storiescolumn[time] AS \"unixtime\",
                    $storiescolumn[withcomm] AS \"withcomm\"
             FROM $pntable[stories]";

    // left join syntax is not consistent.  We check for oracle and assume
    // MySQL if not.  Other databases added here.

    //===FTO . This structure was optimized to avoid copy of same blocks

    //===FTO . Test for every ORACLE compatible drivers
       if ( strstr('oci8,oracle,oci8po,oracle_odbc',$pnconfig['dbtype'] ) )
        {
        $query .=  " , $pntable[stories_cat], $pntable[topics]
                    WHERE $storiescolumn[catid]=$storiescatcolumn[catid](+)
                     AND $topicscolumn[topicid]=$storiescolumn[topic] ";

// FTO. ADO will do that alone !
//        if (!empty($limit)) {
//            $query .= " AND ROWNUM < $limit";
//        }

//        if (!empty($where)) {
//            $query .= " AND $where";
//        }


    } else {   // Assume mysql
        $query .= " LEFT JOIN $pntable[stories_cat] ON $storiescolumn[catid] = $storiescatcolumn[catid]
                    LEFT JOIN $pntable[topics] ON $storiescolumn[topic] = $topicscolumn[topicid] WHERE 1 ";
        }

//===FTO . Add IS NULL for ORACLE
//ORACLEDONE

        if ($multilingual == 1) {
            $query .= " AND ($storiescolumn[alanguage]='$currentlang' OR $storiescolumn[alanguage]='' OR $storiescolumn[alanguage] IS NULL)";
        }

        if (!empty($where))
           {
            $query .= " AND $where";
           }


        // User-added order by clause

              if (!empty($order)) {
            $query .= " ORDER BY $order";
        }

        // Run query
        // Modified to use SelectLimit when necesary
        // just to be ADODB compliant


        if (!empty($order)) {
            $result = $dbconn->SelectLimit($query,$limit);
        }
        else {
            $result = $dbconn->Execute($query);
        }


        // Error check
        if($dbconn->ErrorNo()<>0) {
            echo "DB Error: getArticles: " . $dbconn->ErrorNo() . ': ' . $dbconn->ErrorMsg() . '<br>';
            exit ();
        }

        // Compile rows
        $i = 0;
        $res = array();
        while(!$result->EOF) {
            $row = $result->GetRowAssoc(false);
            $row['unixtime']=$result->UnixTimeStamp($row['unixtime']);

            // A couple of bits for back-compatibility
            $row['topicid'] = $row['tid'];
            $row['topic'] = $row['tid'];
            $row['catid'] = $row['cid'];
            $res[$i] = $row;
            $i++;
            $result->MoveNext();
        }

        $result->Close();
        return($res);

}

/*
 * Generate raw information for a given article
 * Requires row to have previously gone through
 * getArticles() and meet the prerequisites
 * for it
 */
function genArticleInfo($row) {


    setlocale(LC_TIME, $GLOBALS['locale']);
    $myts = new myTextSanitizer;

    // Copy stuff passed in so far
    $info = $row;

    // Version
    $info['version'] = 1;

    // Dates
    $info['longdatetime'] = ml_ftime(_DATETIMELONG, GetUserTime($info['unixtime']));
    $info['briefdatetime'] = ml_ftime(_DATETIMEBRIEF, GetUserTime($info['unixtime']));
    $info['longdate'] = ml_ftime(_DATELONG, GetUserTime($info['unixtime']));
    $info['briefdate'] = ml_ftime(_DATEBRIEF, GetUserTime($info['unixtime']));

    // Tidy-up
    if (empty($info['informant'])) {
        $info['informant'] = "anonymous";
    }

    // Sanitize (and transform)
    $info['title'] = $myts->makeTareaData4Show($info['title']);
    $info['hometext'] = $myts->makeTareaData4Show($info['hometext']);
    $info['bodytext'] = $myts->makeTareaData4Show($info['bodytext']);
    $info['notes'] = $myts->makeTareaData4Show($info['notes']);

    // Create 'Cateogry: title'-style header -- Credit to Rabbit for the older theme compatibility.
    if ($info['catid']) {
        $info['catandtitle'] = "$info[cattitle]: $info[title]";
    } else {
        $info['catandtitle'] = $info['title'];
    }

    $info['maintext'] = "$info[hometext]\n$info[bodytext]";
    if (!empty($info['notes'])) {
        $info['fulltext'] = "$info[maintext]\n$info[notes]";
    } else {
        $info['fulltext'] = "$info[maintext]";
    }

    return($info);
}

/*

 * Generate an array of links for a given article

 * Requires info to have previously gone through

 * genArticleInfo() and meet the prerequisites

 * for it

 */
function genArticleLinks($info) {

    global $cookie;

    // Component and instance
    $component = 'Stories::';
    $instance = "$info[aid]:$info[cattitle]:$info[sid]";

    /* User prefs for comments */
    if (isset($cookie[4])) {
        $extra = "&amp;mode=$cookie[4]";
    } else {
        $extra = '&amp;mode=thread';
    }

    if (isset($cookie[5])) {
        $extra .= "&amp;order=$cookie[5]";
    } else {
        $extra .= '&amp;order=0';
    }

    $commentextra = $extra;

    if (isset($cookie[6])) {
        $commentextra .= "&amp;thold=$cookie[6]";
    } else {
        $commentextra .= '&amp;thold=0';
    }

    // Allowed to comment?
    if (authorised(0, $component, $instance, ACCESS_COMMENT)) {
        $comment = "modules.php?op=modload&amp;name=News&amp;file=article&amp;sid=$info[sid]$commentextra";
    } else {
        $comment = "";
    }

    // Allowed to read full article?
    if (authorised(0, $component, $instance, ACCESS_READ)) {
        $fullarticle = "modules.php?op=modload&amp;name=News&amp;file=article&amp;sid=$info[sid]$extra";
    } else {
        $fullarticle = "";
    }

    // Set up the array itself
    $links = array (
                    "category" => "modules.php?op=modload&amp;name=News&amp;file=index&amp;catid=$info[catid]",
                    "comment" => $comment,
                    "fullarticle" => $fullarticle,
                    "searchtopic" => "modules.php?op=modload&amp;name=Search&amp;file=index&amp;action=search&amp;overview=1&amp;active_stories=1&amp;stories_topics[0]=$info[tid]",
                    "print" => "print.php?sid=$info[sid]",
                    "send" => "modules.php?op=modload&amp;name=Recommend_Us&amp;file=index&amp;req=FriendSend&amp;sid=$info[sid]",
                    "version" => 1
                    );

    return $links;
}

/*
 * Generate an array of preformatted HTML bites for a given article
 * Requires info to have previously gone through
 * genArticleInfo() and meet the prerequisites
 * for it
 * Requires links to have been generated from
 * genArticleLinks()
 */
function genArticlePreformat($info, $links) {
    global $pnconfig, $tipath;

    // Component and instance
    $component = 'Stories::';
    $instance = "$info[aid]:$info[cattitle]:$info[sid]";

    // Only allow send if the module exists
    if (moduleAvailable("Recommend_Us")) {
        $send = "<a class=\"pn-normal\" href=\"$links[send]\"><img src=\"images/global/friend.gif\" border=\"0\" alt=\""._FRIEND."\" width=\"15\" height=\"11\"></a>";
    } else {
        $send = "";
    }

    // Autolink
    if ($pnconfig['autolinkpref'] > 1) {
        $link = new autolinker;
        $hometext = $link->linkIt($info['hometext']);
    } else {
        $hometext = $info['hometext'];
    }

    if ($pnconfig['autolinkpref'] > 0) {
        $link = new autolinker;
        $bodytext = $link->linkIt($info['bodytext']);
    } else {
        $bodytext = $info['bodytext'];
    }

    // Only bother with readmore if there is more to read
    $bytesmore = strlen($info['bodytext']);
    $readmore = "";
    $bytesmorelink = "";
    if ($bytesmore > 0) {
        if (authorised(0, $component, $instance, ACCESS_READ)) {
            $readmore = "<a class=\"pn-normal\" href=\"$links[fullarticle]\">"._READMORE."</a>";
        }
        $bytesmorelink = "$bytesmore "._BYTESMORE;
    }

    // Allowed to read full article?
    if (authorised(0, $component, $instance, ACCESS_READ)) {
        $title = "<a class=\"pn-title\" href=\"$links[fullarticle]\">$info[title]</a>";
    } else {
        $title = $info['title'];
    }

    // Allowed to read full article?
    if (authorised(0, $component, $instance, ACCESS_READ)) {
        $print = "<a class=\"pn-normal\" href=\"$links[print]\"><img src=\"images/global/print.gif\" border=\"0\" alt=\""._PRINTER."\" width=\"15\" height=\"11\"></a>";
    } else {
        $print = '';
    }

    // Work out how to say 'comment(s)(?)' correctly
    $comment = "";
    if ($info['withcomm'] == 0) {
        if ($info['comments'] == 0) {
            $comment = _COMMENTSQ;
        } else if ($info['comments'] == 1) {
            $comment = "1 " . _COMMENT;
        } else {
            $comment = "$info[comments] "._COMMENTS;
        }
    }

    // Allowed to comment?
    if (authorised(0, $component, $instance, ACCESS_COMMENT)) {
        $comment = "<a class=\"pn-normal\" href=\"$links[comment]\">$comment</a>";
    } else {
        $comment = "";
    }

    // Notes, if there are any
    if (!empty($info['notes'])) {
        $notes = _NOTE." <i>$info[notes]</i>";
    } else {
        $notes = "";
    }

    // Set up the array itself
    $preformat = array(
                       "bodytext" => $bodytext,
                       "bytesmore" => $bytesmorelink,
                       "category" => "<a href=\"$links[category]\">$info[cattitle]</a>",
                       "comment" => $comment,
                       "hometext" => $hometext,
                       "notes" => $notes,
                       "searchtopic" => "<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]=$info[tid]\"><img src=\"$tipath$info[topicimage]\" border=\"0\" Alt=\"$info[topictext]\" align=\"left\" hspace=\"5\" vspace=\"5\"></a>",
                       "print" => $print,
                       "readmore" => $readmore,
                       "send" => $send,
                       "title" => $title,
                       "version" => 1
                       );

    // More complex extras - use values in the array
    $preformat['more'] = "";
    if ($bytesmore > 0) {
        $preformat['more'] .= "$preformat[readmore] ($preformat[bytesmore]) ";
    }
    $preformat['more'] .= "$preformat[comment] $preformat[send] $preformat[print]";

    if ($info['catid']) {
        $preformat['catandtitle'] = "$preformat[category]: $preformat[title]";
    } else {
        $preformat['catandtitle'] = $preformat['title'];
    }

    $preformat['maintext'] = "$preformat[hometext]<BR><BR>$preformat[bodytext]";
    if (!empty($preformat['notes'])) {
        $preformat['fulltext'] = "$preformat[maintext]<BR><BR>$preformat[notes]";
    } else {
        $preformat['fulltext'] = "$preformat[maintext]";
    }

    return $preformat;
}

/**
 * Updates autonews
 *
 * This function selects all appropriate autonews items from the autonews table
 * (keeping in mind the current time and language) and removes them from that
 * table; it also inserts them into the stories table.
 *
 * @return none
 * @author ?
 */

function automatednews() {
    global $pntable, $dbconn, $multilingual, $currentlang;


    //===FTO . Add IS NULL for ORACLE
    //ORACLEDONE

    if ($multilingual == 1) {
        $column = &$pntable['autonews_column'];
        $querylang = "WHERE ($column[alanguage]='$currentlang' OR $column[alanguage]='' OR $column[alanguage] IS NULL)";

    } else {
        $querylang = "";
    }
    
    $today = getdate();
    $day = $today['mday'];
    if ($day < 10) {
        $day = "0$day";
    }
    $month = $today['mon'];
    if ($month < 10) {
        $month = "0$month";
    }
    $year = $today['year'];
    $hour = $today['hours'];
    if ($hour < 10) {
        $hour = "0$hour";
    }
    $min = $today['minutes'];
    if ($min < 10) {
        $min = "0$min";
    }
    $sec = "00";
    $column = &$pntable['autonews_column'];
    $result = $dbconn->Execute("SELECT $column[anid], $column[time]
                              FROM $pntable[autonews]
                              $querylang");


     //FTO : Changed for testing EOF and database error

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

    while(!$result->EOF) {

        list($anid, $time) = $result->fields;
        $result->MoveNext();
        
// EugenioBaldi Change the test of date
//        ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $time, $date);
        $timenews = substr($time, 0,4).substr($time, 5,2).substr($time, 8,2).substr($time, 11,2).substr($time, 14,2).substr($time, 17,2) ;
        $timenewsn = $timenews + 1 - 1;
        $now = "$year$month$day$hour$min$sec";
        $nown = $now + 1 - 1;
        if ($timenewsn < $nown)     {

            $column = &$pntable['autonews_column'];
            $result2 = $dbconn->Execute("SELECT $column[catid], $column[aid], $column[title], $column[hometext], $column[bodytext], $column[topic], $column[informant], $column[notes], $column[ihome], $column[alanguage] FROM $pntable[autonews] WHERE $column[anid]='$anid'");

                //FTO : Changed for testing EOF (prob with Oracle before)
                //ORACLEDONE
                if (!$result2) {
                     PN_DBMsgError($dbconn, __FILE__, __LINE__, "An error ocurred");
                     die();
                }

                while(!$result2->EOF) {
                    list($catid, $aid, $title, $hometext, $bodytext, $topic, $author, $notes, $ihome, $alanguage) = $result2->fields;
                    $title = stripslashes(FixQuotes($title));
                    $hometext = stripslashes(FixQuotes($hometext));
                    $bodytext = stripslashes(FixQuotes($bodytext));
                    $notes = stripslashes(FixQuotes($notes));
                    $scol = &$pntable['stories_column'];
                    // FTO : Add SEQ suffix to avoid conflict name with ORACLE
                    $new_sid = $dbconn->GenId("{$pntable['stories']}_SEQ");

                    //FTO Use a php date time to stay compatible with
                    //    all databases.
                    $now=$dbconn->DBTimeStamp(mktime());

                    $insert = $dbconn->Execute("INSERT INTO $pntable[stories] ($scol[sid], $scol[cid], $scol[aid], $scol[title], $scol[time], $scol[hometext], $scol[bodytext], $scol[comments], $scol[counter], $scol[topic], $scol[informant], $scol[notes], $scol[ihome], $scol[themeoverride], $scol[alanguage] ) VALUES ($new_sid, '$catid', '$aid', '$title', $now, '$hometext', '$bodytext', '0', '0', '$topic', '$author', '$notes', '$ihome', '', '$alanguage')");
                    if ($insert === false) {
                        error_log ("Problem deleting autonews story: $anid, '$title'");
                        PN_DBMsgError($dbconn, __FILE__, __LINE__, "Problem deleting autonews story");
                    } else {
                        $dbconn->Execute("DELETE FROM $pntable[autonews] where $column[anid]='$anid'");
                                        }
                    $result2->MoveNext();
                }

        }
    }
}

?>
Return current item: ProNuke. Postnuke To Oracle