<?php
// File: $Id: dl-util.php,v 1.3 2001/12/09 15:44:49 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: function lib, routines used by many other functions
// ----------------------------------------------------------------------
/**
* @usedby nothing
*/
function SearchForm() {
echo "<form action=\"modules.php\" method=\"post\">"
."<input type=\"hidden\" name=\"op\" value=\"modload\">\n"
."<input type=\"hidden\" name=\"name\" value=\"$ModName\">\n"
."<input type=\"hidden\" name=\"file\" value=\"index\">\n"
."<input type=\"hidden\" name=\"req\" value=\"search\">\n"
."<input type=\"hidden\" name=\"query\" value=\"$query\">\n"
."<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">"
."<tr><td><font class=\"pn-normal\"><input type=\"text\" size=\"25\" name=\"query\"> <input type=\"submit\" value=\""._SEARCH."\"></td></tr>"
."</table>"
."</form>";
}
/**
* @usedby nothing
*/
function downloadinfomenu($lid, $ttitle) {
global $ModName, $modurl;
echo "<br><font class=\"pn-normal\">[ ";
$cattitle = downloads_CatNameFromIID($lid);
if (authorised(0, 'Downloads::Item', "$ttitle:$cattitle:$lid", ACCESS_COMMENT)) {
echo "<a class=\"pn-normal\" href=\"$modurl&req=viewdownloadcomments&lid=$lid&ttitle=$ttitle\">"._DOWNLOADCOMMENTS."</a> |";
}
echo "<a class=\"pn-normal\" href=\"$modurl&req=viewdownloaddetails&lid=$lid&ttitle=$ttitle\">"._ADDITIONALDET."</a>"
." | <a class=\"pn-normal\" href=\"$modurl&req=viewdownloadeditorial&lid=$lid&ttitle=$ttitle\">"._EDITORREVIEW."</a>";
if (authorised(0, 'Downloads::Item', "$ttitle:$cattitle:$lid", ACCESS_EDIT)) {
echo " | <a class=\"pn-normal\" href=\"$modurl&req=modifydownloadrequest&lid=$lid\">"._MODIFY."</a>";
}
echo " | <a class=\"pn-normal\" href=\"$modurl&req=brokendownload&lid=$lid\">"._REPORTBROKEN."</a> ]</font>"; // get->post??
}
/**
* @usedby mostpopular, search, toprated, viewlink
*/
function detecteditorial($lid, $ttitle, $img) {
global $pntable, $ModName, $dbconn, $modurl;
$column = &$pntable['downloads_editorials_column'];
$resulted2 = $dbconn->Execute("SELECT $column[adminid]
FROM $pntable[downloads_editorials]
WHERE $column[downloadid]=$lid");
if (!$resulted2->EOF) {
if ($img == 1) {
echo " <a class=\"pn-normal\" href=\"$modurl&req=viewdownloadeditorial&lid=$lid&ttitle=$ttitle\"><img src=\"modules/$ModName/images/cool.gif\" alt=\""._EDITORIAL."\" border=\"0\"></a>";
} else {
echo " | <a class=\"pn-normal\" href=\"$modurl&req=viewdownloadeditorial&lid=$lid&ttitle=$ttitle\">"._EDITORIAL."</a>";
}
}
}
/**
* @usedby mostpopular, search, toprated, viewlink
*/
function popgraphic($hits) {
global $ModName;
include(WHERE_IS_PERSO."config.php");
if ($hits>=$popular) {
echo " <img src=\"modules/$ModName/images/popular.gif\" alt=\""._POPULAR."\">";
}
}
/**
* @usedby search, viewdownload
*/
function convertorderbyin($orderby) {
if ($orderby == "titleA") $orderby = "title ASC";
if ($orderby == "dateA") $orderby = "date ASC";
if ($orderby == "hitsA") $orderby = "hits ASC";
if ($orderby == "ratingA") $orderby = "downloadratingsummary ASC";
if ($orderby == "titleD") $orderby = "title DESC";
if ($orderby == "dateD") $orderby = "date DESC";
if ($orderby == "hitsD") $orderby = "hits DESC";
if ($orderby == "ratingD") $orderby = "downloadratingsummary DESC";
return $orderby;
}
/**
*
* @usedby search, viewdownload
*/
function convertorderbytrans($orderby) {
if ($orderby == "hits ASC") $orderbyTrans = ""._POPULARITY1."";
if ($orderby == "hits DESC") $orderbyTrans = ""._POPULARITY2."";
if ($orderby == "title ASC") $orderbyTrans = ""._TITLEAZ."";
if ($orderby == "title DESC") $orderbyTrans = ""._TITLEZA."";
if ($orderby == "date ASC") $orderbyTrans = ""._DDATE1."";
if ($orderby == "date DESC") $orderbyTrans = ""._DDATE2."";
if ($orderby == "downloadratingsummary ASC") $orderbyTrans = ""._RATING1."";
if ($orderby == "downloadratingsummary DESC") $orderbyTrans = ""._RATING2."";
return $orderbyTrans;
}
/**
* @usedby viewlink, search,
*/
function convertorderbyout($orderby) {
if ($orderby == "title ASC") $orderby = "titleA";
if ($orderby == "date ASC") $orderby = "dateA";
if ($orderby == "hits ASC") $orderby = "hitsA";
if ($orderby == "downloadratingsummary ASC") $orderby = "ratingA";
if ($orderby == "title DESC") $orderby = "titleD";
if ($orderby == "date DESC") $orderby = "dateD";
if ($orderby == "hits DESC") $orderby = "hitsD";
if ($orderby == "downloadratingsummary DESC") $orderby = "ratingD";
return $orderby;
}
/**
* @usedby index, mostpopular, serach, toprated, viewlink
*/
function visit($lid) {
global $pntable, $ModName, $dbconn;
$column = &$pntable['downloads_downloads_column'];
$dbconn->Execute("UPDATE $pntable[downloads_downloads]
SET $column[hits]=$column[hits]+1
WHERE $column[lid]=$lid");
$result = $dbconn->Execute("SELECT $column[url]
FROM $pntable[downloads_downloads]
WHERE $column[lid]=$lid");
list($url) = $result->fields;
Header("Location: ".$url);
}
/**
* @usedby index, search, viewlink
*/
function CountSubLinks($cid)
{
global $pntable, $dbconn;
$ct=0;
$column = &$pntable['links_links_column'];
$result=$dbconn->Execute("SELECT COUNT(*) FROM $pntable[links_links] WHERE $column[cat_id]=$cid");
list($ct) = $result->fields;
// Now get all child nodes
$column = &$pntable['links_categories_column'];
$result=$dbconn->Execute("SELECT $column[cat_id] FROM $pntable[links_categories] WHERE $column[parent_id]=$cid");
// FTO Check EOF and databse error
if (!$result) {
PN_DBMsgError($dbconn, __FILE__, __LINE__, "An error ocurred");
die();
}
while(!$result->EOF) {
list($sid)=$result->fields;
$result->MoveNext();
$ct+=CountSubLinks($sid);
}
return $ct;
}
/* Link Graphics */
/**
* categorynewlinkgraphic
* @usedby index, viewlink
*/
function categorynewdownloadgraphic($cat) {
global $pntable, $ModName, $locale, $dbconn;
$column = &$pntable['downloads_downloads_column'];
$sql = "SELECT $column[date]
FROM $pntable[downloads_downloads]
WHERE $column[cid]=$cat
ORDER BY $column[date]";
$newresult = $dbconn->SelectLimit($sql,1);
list($time)=$newresult->fields;
echo " ";
setlocale (LC_TIME, $locale);
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, $datetime);
$datetime = ml_ftime(""._LINKSDATESTRING."", mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]));
$datetime = ucfirst($datetime);
$startdate = time();
$count = 0;
while ($count <= 7) {
$daysold = date("d-M-Y", $startdate);
if ("$daysold" == "$datetime") {
if ($count<=1) {
echo "<img src=\"modules/$ModName/images/new_1.gif\" alt=\""._DCATNEWTODAY."\">";
}
if ($count<=3 && $count>1) {
echo "<img src=\"modules/$ModName/images/new_3.gif\" alt=\""._DCATLAST3DAYS."\">";
}
if ($count<=7 && $count>3) {
echo "<img src=\"modules/$ModName/images/new_7.gif\" alt=\""._DCATTHISWEEK."\">";
}
}
$count++;
$startdate = (time()-(86400 * $count));
}
}
/**
* newdownloadgraphic
* @usedby mostpopular, search
*/
function newdownloadgraphic($datetime, $time) {
global $ModName, $locale;
echo " ";
setlocale (LC_TIME, $locale);
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, $datetime);
$datetime = ml_ftime(""._LINKSDATESTRING."", mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]));
$datetime = ucfirst($datetime);
$startdate = time();
$count = 0;
while ($count <= 7) {
$daysold = date("d-M-Y", $startdate);
if ("$daysold" == "$datetime") {
if ($count<=1) {
echo "<img src=\"modules/$ModName/images/new_1.gif\" alt=\""._NEWTODAY."\">";
}
if ($count<=3 && $count>1) {
echo "<img src=\"modules/$ModName/images/new_3.gif\" alt=\""._NEWLAST3DAYS."\">";
}
if ($count<=7 && $count>3) {
echo "<img src=\"modules/$ModName/images/new_7.gif\" alt=\""._NEWTHISWEEK."\">";
}
}
$count++;
$startdate = (time()-(86400 * $count));
}
}
/**
* subcategorynewlinkgraphic
*
* Post-Nuke mod -- Create a the new function for generating the 'new' graphics for
* sub-categoires, based on the post-nuke categorynewlinkgraphic($cid)
* @usedby index, viewlink
*/
function subcategorynewlinkgraphic($sid) {
global $pntable, $dbconn, $ModName;
$column = &$pntable['links_links_column'];
$query = buildSimpleQuery ('links_links', array ('date'), "$column[cat_id]=$sid", "$column[date] DESC", 1);
$newresult = $dbconn->Execute($query);
list($time)=$newresult->fields;
echo " ";
setlocale ("LC_TIME", "$locale");
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, $datetime);
$datetime = strftime(""._LINKSDATESTRING."", mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]));
$datetime = ucfirst($datetime);
$startdate = time();
$count = 0;
while ($count <= 7) {
$daysold = date("d-M-Y", $startdate);
if ("$daysold" == "$datetime") {
if ($count<=1) {
echo "<img src=\"modules/$ModName/images/newred.gif\" alt=\""._CATNEWTODAY."\">";
}
if ($count<=3 && $count>1) {
echo "<img src=\"modules/$ModName/images/newgreen.gif\" alt=\""._CATLAST3DAYS."\">";
}
if ($count<=7 && $count>3) {
echo "<img src=\"modules/$ModName/images/newblue.gif\" alt=\""._CATTHISWEEK."\">";
}
}
$count++;
$startdate = (time()-(86400 * $count));
}
}
/**
* CatList
* Recursivly creates option tags for each sub category of $scat, selects category $sel
* @usedby search, popular, addlink
*/
function CatList($scat, $sel) {
global $pntable, $dbconn;
$s="";
$column = &$pntable['links_categories_column'];
$result=$dbconn->Execute("SELECT $column[cat_id] FROM $pntable[links_categories] WHERE $column[parent_id]=$scat");
// FTO Check EOF and databse error
if (!$result) {
PN_DBMsgError($dbconn, __FILE__, __LINE__, "An error ocurred");
die();
}
while(!$result->EOF) {
list($cid)=$result->fields;
$result->MoveNext();
if ($sel==$cid) {
$selstr=" selected";
} else {
$selstr='';
}
$s.="<option value=\"$cid\"$selstr>".CatPath($cid,0,0,0)."</option>";
$s.=CatList($cid, $sel);
}
return $s;
}
/**
* Catpath
* Creates the full path for a category title
* New function by toph, 20/8/2001
* @usedby search, popular, addlink
*/
function CatPath($cid, $start, $links, $linkmyself) {
global $pntable, $dbconn, $ModName;
global $modurl;
$column = &$pntable['links_categories_column'];
$result=$dbconn->Execute("SELECT $column[parent_id], $column[title] FROM $pntable[links_categories] WHERE $column[cat_id]=$cid");
list($pid, $title)=$result->fields;
if ($linkmyself) {
$cpath = "<a href=\"${modurl}&req=viewlink&cid=$cid\">$title</a>";
} else {
$cpath = $title;
}
while ($pid!=0) {
$column = &$pntable['links_categories_column'];
$result=$dbconn->Execute("SELECT $column[cat_id], $column[parent_id], $column[title] FROM $pntable[links_categories] WHERE $column[cat_id]=$pid");
list($cid, $pid, $title)=$result->fields;
if ($links) {
$cpath = "<a href=\"${modurl}&req=viewlink&cid=$cid\">".$title.'</a> / '.$cpath;
} else {
$cpath = $title.' / '.$cpath;
}
}
if ($start) {
$cpath="<a href=\"${modurl}\">"._START."</a> / ".$cpath;
}
return $cpath;
}
/**
* @usedby mostpopular, search, toprated, viewlink
*/
function LinksBottomMenu($lid, $transfertitle, $totalvotes, $totalcomments){
global $ModName;
global $modurl;
if (authorised(0, 'Web links::Category', '::', ACCESS_COMMENT)) {
echo "</font><br><font class=\"pn-normal\"><a class=\"pn-normal\" href=\"${modurl}&req=ratelink&lid=$lid&ttitle=$transfertitle\">"._RATESITE."</a>";
}
echo " | <a class=\"pn-normal\" href=\"${modurl}&req=brokenlink&lid=$lid\">"._REPORTBROKEN."</a>";
if (authorised(0, 'Web links::Category', '::', ACCESS_READ)) {
if ($totalvotes != 0) {
echo " | <a class=\"pn-normal\" href=\"${modurl}&req=viewlinkdetails&lid=$lid&ttitle=$transfertitle\">"._DETAILS."</a>";
}
}
if (authorised(0, 'Web links::Category', '::', ACCESS_COMMENT)) {
if ($totalcomments != 0) {
echo " | <a class=\"pn-normal\" href=\"${modurl}&req=viewlinkcomments&lid=$lid&ttitle=$transfertitle\">"._COMMENTS." ($totalcomments)</a></font>";
}
}
}
function web_links_rateMakeStar($score, $max_score)
{
// this code is take from harpia project http://sourceforge.net/projects/harpia
global $ModName;
$score /= 2; $max_score /=2; // 5 stars. comment for 10 stars
$basedir="modules/$ModName/images/" ; // for $basedir/image/xxx.gif
$rateImgFull = $basedir.'rate_full.gif';
$rateImgHalf = $basedir.'rate_half.gif';
$rateImgNone = $basedir.'rate_none.gif';
// Break up score
if (strpos($score,".")==0){
$full_stars=$score;
}else{
$full_stars=substr($score,0,strpos($score,"."));
}
// *** Is there half star
if (substr($score,strpos($score,".")+1)==0){
$half_stars=0;
}else{
$half_stars=1;
}
// *** Build Star Line
$blank_stars=$max_score-($full_stars+$half_stars);
$star_line="";
for ($i=1;$i<=$max_score;$i++){
if ($i<=$full_stars){
$star_line.="<img src='".$rateImgFull."' border='0'>";
}elseif ($i<=($half_stars+$full_stars)){
$star_line.="<img src='".$rateImgHalf."' border='0'>";
}elseif ($i<=$max_score){
$star_line.="<img src='".$rateImgNone."' border='0'>";
}
}
return $star_line;
}
/**
* @usedby rating
*/
function downloadfooter($lid,$ttitle) {
global $ModName, $modurl;
echo "<font class=\"pn-normal\">[ <a class=\"pn-normal\" href=\"$modurl&req=getit&lid=$lid\">"._DOWNLOADNOW."</a>";
if (authorised(0, 'Downloads::', '::', ACCESS_COMMENT)){
echo "| <a class=\"pn-normal\" href=\"$modurl&req=ratedownload&lid=$lid&ttitle=$ttitle\">"._RATETHISSITE."</a>";
}
echo" ]</font><br><br>";
downloadfooterchild($lid);
}
/**
* @usedby rating
*/
function downloadfooterchild($lid) {
global $ModName, $modurl;
include(WHERE_IS_PERSO."config.php");
if (authorised(0, 'Downloads::', '::', ACCESS_COMMENT)){
if ($useoutsidevoting = 1) {
echo "<br><font class=\"pn-normal\">"._ISTHISYOURSITE." <a class=\"pn-normal\" href=\"$modurl&req=outsidedownloadsetup&lid=$lid\">"._ALLOWTORATE."</a></font>";
}
}
}
function drawvotestats($baton) {
global $bgcolor1, $bgcolor2, $ModName;
if ($baton['weight']) { // Note on the weighing of votes
echo '<tr><td valign="top" colspan="2"><font class="pn-normal"<br><br>'
.$baton['weighnote'].' '.$baton['weightext'].' '._TO.' 1.</font></td></tr>';
}
echo '<tr><td colspan="2" bgcolor="'.$bgcolor2.'">'
.'<font class="pn-normal">'.$baton['users'].'</font></td></tr>'
.'<tr><td bgcolor="'.$bgcolor1.'"><font class="pn-normal">'
._NUMBEROFRATINGS.': '.$baton['votes'].'</font></td>'
.'<td align="center" rowspan="5" width="200">';
if ($baton['votes'] == '0') {
echo '<font class="pn-normal">'.$baton['novotes'].'</font>';
} else {
echo '<table border="1" width="200">' // charts table
.'<tr><td valign="top" align="center" colspan="10" bgcolor="'.$bgcolor2.'">'
.'<font class="pn-sub">'._BREAKDOWNBYVAL.'</font></td>'
.'</tr><tr>';
for ($i=1; $i<=10; $i++) {
echo '<td bgcolor="'.$bgcolor1.'" valign="bottom">'
.'<img border="0" alt="'.$baton['vv'][$i].' '._LVOTES.' ('.$baton['vvpercent'][$i].'% '
._LTOTALVOTES.')" src="modules/'.$ModName.'/images/blackpixel.gif" width="15" height="'
.$baton['vvcharth'][$i].'"></td>';
}
echo '</tr><tr><td colspan="10" bgcolor="'.$bgcolor2.'">'
.'<table cellspacing="0" cellpadding="0" border="0" width="205"><tr>';
for ($i=1; $i<=10; $i++) {
echo '<td width="10%" valign="bottom" align="center"><font class="pn-sub">'.$i.'</font></td>';
}
echo '</tr></table></td></tr></table>';
}
echo '</td></tr>';
echo '<tr><td bgcolor="'.$bgcolor2.'"><font class="pn-normal">'._DOWNLOADRATING.': '.$baton['avg'].'</font></td></tr>'
.'<tr><td bgcolor="'.$bgcolor1.'"><font class="pn-normal">'._HIGHRATING.': '.$baton['top'].'</font></td></tr>'
.'<tr><td bgcolor="'.$bgcolor2.'"><font class="pn-normal">'._LOWRATING.': '.$baton['low'].'</font></td></tr>'
.'<tr><td bgcolor="'.$bgcolor1.'"><font class="pn-normal">';
if (!$baton['weight']) {
echo _NUMOFCOMMENTS.': '.$baton['comments'].'</font></td></tr>';
} else {
echo ' ';
}
echo '</td></tr>';
}
/*
* Get the category name given its CID
*/
function downloads_CatNameFromCID($cid)
{
global $dbconn, $pntable;
$dlcattable = $pntable['downloads_categories'];
$dlcatcolumn = &$pntable['downloads_categories_column'];
$query = "SELECT $dlcatcolumn[title]
FROM $dlcattable
WHERE $dlcatcolumn[cid] = $cid";
$result = $dbconn->Execute($query);
list($catname) = $result->fields;
$result->Close();
return $catname;
}
/*
* Get the item name given its IID
*/
function downloads_ItemNameFromIID($iid)
{
global $dbconn, $pntable;
$dlitemtable = $pntable['downloads_downloads'];
$dlitemcolumn = &$pntable['downloads_downloads_column'];
$query = "SELECT $dlitemcolumn[title]
FROM $dlitemtable
WHERE $dlitemcolumn[lid] = $iid";
$result = $dbconn->Execute($query);
list($itemname) = $result->fields;
$result->Close();
return $itemname;
}
/*
* Get the item category given its IID
*/
function downloads_CatNameFromIID($iid)
{
global $dbconn, $pntable;
$dlitemtable = $pntable['downloads_downloads'];
$dlitemcolumn = &$pntable['downloads_downloads_column'];
$query = "SELECT $dlitemcolumn[cid]
FROM $dlitemtable
WHERE $dlitemcolumn[lid] = $iid";
$result = $dbconn->Execute($query);
list($cid) = $result->fields;
$result->Close();
$dlcattable = $pntable['downloads_categories'];
$dlcatcolumn = &$pntable['downloads_categories_column'];
$query = "SELECT $dlcatcolumn[title]
FROM $dlcattable
WHERE $dlcatcolumn[cid] = $cid";
$result = $dbconn->Execute($query);
list($catname) = $result->fields;
$result->Close();
return $catname;
}
function CoolSize($size) {
$mb = 1024*1024;
if ( $size > $mb ) {
$mysize = sprintf ("%01.2f",$size/$mb) . " MB";
} elseif ( $size >= 1024 ) {
$mysize = sprintf ("%01.2f",$size/1024) . " Kb";
} else {
$mysize = $size . " bytes";
}
return $mysize;
}
?>