<?
/*
HPE - News Portal Engine
Copyright (C) 2000-2001 Mike Krus
This program is free software; it 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.
READ LICENSE.TXT IN THE BASE DIRECTORY FOR INFORMATION
ABOUT REDISTRIBUTING THIS SOURCE CODE
*/
class HPEPage
{
var $url; //! The base url for the page
var $name; //! The name of this type
var $desc; //! Short Description of this type
var $flags; //! Flags controlling the behavior
var $showpath; //! Path the display sub page
var $editpath; //! Path the display sub page
function HPEPage()
{
$this->url = "";
$this->name = "";
$this->desc = "";
$this->flags = 0;
$this->showpath = "";
$this->editpath = "";
}
function AcceptsModule($type)
{
return false;
}
};
class HPEPageBoxes extends HPEPage
{
var $basepath;
function HPEPageBoxes()
{
$this->HPEPage();
$this->Reset();
}
function Reset()
{
$this->type = "newsbox";
$this->url = "";
$this->name = "Module Boxes";
$this->desc = "Arrange your choice of modules in 3 columns";
$this->flags = (HPEPageEditable | HPEPageExternEdit | HPEPageMailable);
$this->editpath = $GLOBALS["HPEinc"] . "/plugins/page.newsboxes.edit.inc";
}
function UnSerializeFromXML(&$XMLtree, $path, &$pgdata)
{
global $HPEtheConfig;
for($j=1, $k=0; $j<=3; $j++, $k++)
{
$pgdata["column$k"] = array();
$n = $XMLtree->getAttribute("$path/column($j)", "numelts");
for($i=1; $i<=$n; $i++)
{
$srctype = $XMLtree->getAttribute("$path/column($j)/module($i)", "type");
$srcdata = array( "type" => $srctype );
if(isset($HPEtheConfig->modhandlers[$srctype]))
{
$HPEtheConfig->modhandlers[$srctype]["control"]->UnSerializeFromXML($XMLtree,
"$path/column($j)/module($i)", $srcdata);
$pgdata["column" . ($j - 1)][$i-1] = $srcdata;
}
else
{
global $HPEtheUser;
HPEWatchdog("user", "User $HPEtheUser->userid : Module type $srctype unknown");
}
}
}
}
function SerializeToXML(&$pgdata)
{
global $HPEtheConfig;
$data = "\t\t<PAGE type=\"$this->type\" id=\"" . $pgdata["id"] .
"\" title=\"" . HPEXMLString($pgdata["title"]) . "\">\n";
for($i=0; $i<3; $i++)
{
$n = count($pgdata["column$i"]);
if($n == 0)
{
$data .= "\t\t\t<COLUMN numelts=\"0\"/>\n";
continue;
}
$data .= "\t\t\t<COLUMN numelts=\"$n\">\n";
for($j=0; $j<$n; $j++)
{
$srctype = $pgdata["column$i"][$j]["type"];
$data .= $HPEtheConfig->modhandlers[$srctype]["control"]->SerializeToXML($pgdata["column$i"][$j]);
}
$data .= "\t\t\t</COLUMN>\n";
}
$data .= "\t\t</PAGE>\n";
return $data;
}
function Create($param)
{
$data = array();
$data["column0"] = array();
$data["column1"] = array();
$data["column2"] = array();
return $data;
}
function AcceptsModule($type)
{
return ($type == 0 || $type == 1 || $type == 4);
}
function AddModule(&$pgdata, &$moddata)
{
$c = 0;
if(count($pgdata["column1"]) < count($pgdata["column$c"])) $c = 1;
if(count($pgdata["column2"]) < count($pgdata["column$c"])) $c = 2;
$pgdata["column$c"][] = $moddata;
}
function &GetModule(&$pgdata, $modid)
{
$t = 0;
for($i=0; $i<3; $i++)
{
$n = count($pgdata["column$i"]);
$l = $t + $n - 1;
if($modid <= $l)
{
$nc = array();
for($j=0; $j<$n; $j++)
if(($j + $t) == $modid) return $pgdata["column$i"][$j];
}
$t += $n;
}
return "";
}
function RemoveModule(&$pgdata, $modid)
{
$t = 0;
for($i=0; $i<3; $i++)
{
$n = count($pgdata["column$i"]);
$l = $t + $n - 1;
if($modid <= $l)
{
$nc = array();
for($j=0, $k=0; $j<$n; $j++)
{
if(($j + $t) == $modid) continue;
$nc[$k] = $pgdata["column$i"][$j];
$k++;
}
$pgdata["column$i"] = $nc;
return "";
}
$t += $n;
}
return "Module not found";
}
function Show()
{
global $HPEtheUser;
global $HPEtheThemeMaker;
global $page;
echo $HPEtheThemeMaker->TPLRun("page.newsboxes", $this->GetData($HPEtheUser->pages[$page]));
}
function GetData(&$pagedata)
{
global $HPEtheConfig;
$n = 0;
$data = array ( "title" => $pagedata["title"] );
for($i=0;$i<3; $i++)
{
$ln = count($pagedata["column$i"]);
$data["COL"][$i] = array( );
for($j=0; $j<$ln; $j++)
{
if(isset($pagedata["column$i"][$j]))
{
$t = $pagedata["column$i"][$j]["type"];
if(isset($HPEtheConfig->modhandlers[$t]))
$data["COL"][$i][$j] = $HPEtheConfig->modhandlers[$t]["control"]->show($pagedata["column$i"][$j], $n);
}
else $data["COL"][$i][$j] = "";
$n++;
}
}
return $data;
}
};
class HPEPageNewsLog extends HPEPage
{
function HPEPageNewsLog()
{
$this->HPEPage();
$this->Reset();
}
function Reset()
{
$this->type = "newslog";
$this->url = "";
$this->name = "Multisource headlines in a flat list";
$this->desc = "Arrange your choice of modules in a flat list";
$this->flags = (HPEPageEditable | HPEPageExternEdit | HPEPageMailable);
$this->editpath = $GLOBALS["HPEinc"] . "/plugins/page.newslog.edit.inc";
}
function UnSerializeFromXML(&$XMLtree, $path, &$pgdata)
{
global $HPEtheConfig;
$pgdata["mode"] = $XMLtree->getAttribute($path, "mode");
$pgdata["outdate"] = $XMLtree->getAttribute($path, "outdate");
if(empty($pgdata["outdate"]))
$pgdata["outdate"] = 0;
$pgdata["sources"] = array();
$i = 1;
while(1)
{
$type = $XMLtree->getAttribute("$path/module($i)", "type");
if($type == "") break;
$srcdata = array( "type" => $type );
if(isset($HPEtheConfig->modhandlers[$type]))
{
$HPEtheConfig->modhandlers[$type]["control"]->UnSerializeFromXML($XMLtree, "$path/module($i)", $srcdata);
$pgdata["sources"][] = $srcdata;
}
$i++;
}
}
function SerializeToXML(&$pgdata)
{
global $HPEtheConfig;
if(!isset($pgdata["outdate"]))
$pgdata["outdate"] = 0;
$data = "\t\t<PAGE type=\"" . $pgdata["type"] . "\" id=\"" . $pgdata["id"] .
"\" title=\"" . HPEXMLString($pgdata["title"]) . "\" mode=\"" . $pgdata["mode"] . "\" " .
"outdate=\"" . $pgdata["outdate"] . "\">\n";
$n = count($pgdata["sources"]);
for($i=0; $i<$n; $i++)
if(isset($HPEtheConfig->modhandlers[$pgdata["sources"][$i]["type"]]) && $pgdata["sources"][$i]["type"] == 0)
$data .= $HPEtheConfig->modhandlers[$pgdata["sources"][$i]["type"]]["control"]->SerializeToXML($pgdata["sources"][$i]);
$data .= "\t\t</PAGE>\n";
return $data;
}
function Create($param)
{
$data = array();
$data["sources"] = array( );
$data["mode"] = "flat";
return $data;
}
function AcceptsModule($type)
{
return ($type == 0 || $type == 4);
}
function AddModule(&$pgdata, &$moddata)
{
if($moddata["type"] == 0 || $moddate["type"] == 4)
$pgdata["sources"][] = $moddata;
}
function &GetModule(&$pgdata, $modid)
{
if(isset($pgdata["sources"][$modid]))
return $pgdata["sources"][$modid];
return "";
}
function RemoveModule(&$pgdata, $modid)
{
$n = count($pgdata["sources"]);
$ns = array();
for($j=0, $k=0; $j<$n; $j++)
{
if($j == $modid) continue;
$ns[$k] = $pgdata["sources"][$j];
$k++;
}
if(count($ns) == $n - 1)
{
$pgdata["sources"] = $ns;
return "";
}
return "Module not found";
}
function Show()
{
global $HPEtheUser;
global $HPEtheThemeMaker;
global $page;
echo $HPEtheThemeMaker->TPLRun("page.newslog", $this->GetData($HPEtheUser->pages[$page]));
}
function GetData(&$pagedata)
{
global $HPEinc;
global $page;
global $HPEtheConfig;
global $HPEtheUser;
$data = array();
$data["items"] = array();
$nitems = 0;
$n = count($pagedata["sources"]);
if($n)
{
$srcids = array();
$modids = array();
for($i=0; $i<$n; $i++)
{
$srcids[] = $pagedata["sources"][$i]["source"];
$modids[$pagedata["sources"][$i]["source"]] = $i;
}
$nitems = HPELoadMultiNews($data, $srcids, 0, $sort = ($pagedata["mode"] == "flat" ? 0 : 1), $HPEtheUser->level);
reset($data["items"]);
$outdate = $pagedata["outdate"] * 3600 * 24;
while(list($key, $val) = each($data["items"]))
{
if($outdate && $data["items"][$key]["date"] < time() - $outdate)
{
unset($data["items"][$key]);
continue;
}
$data["items"][$key]["link"] = $HPEtheConfig->siteroot . "click/" . $data["items"][$key]["id"] . "/";
$data["items"][$key]["elink"] = "";
$data["items"][$key]["ulink"] = "";
}
}
$data["title"] = $pagedata["title"];
return $data;
}
};
class HPEPageRandSources extends HPEPage
{
function HPEPageRandSources() {
$this->HPEPage();
$this->Reset();
}
function Reset() {
$this->type = "newsrandsrc";
$this->url = "";
$this->name = "Random News";
$this->desc = "Show 9 randomly selected news boxes";
$this->flags = (HPEPageHasDefValues);
}
function UnSerializeFromXML(&$XMLtree, $path, &$data)
{
}
function SerializeToXML(&$pgdata)
{
$data = "\t\t<PAGE type=\"" . $pgdata["type"] . "\" id=\"" . $pgdata["id"] .
"\" title=\"" . HPEXMLString($pgdata["title"]) . "\" />\n";
return $data;
}
function Create($param)
{
$data = array();
return $data;
}
function Show()
{
global $HPEtheConfig;
global $HPEtheDB;
global $HPEtheThemeMaker;
global $page;
$HPEtheNEWSmodule = &$HPEtheConfig->modhandlers[0]["control"];
$data = array();
$data["title"] = ($page == -1 ? $this->name : "");
$query = "SELECT count(*) FROM $HPEtheDB->dbtnewssites;";
$numsites = $HPEtheDB->one_data($query);
if($numsites)
{
mt_srand((double)microtime() * 1000000);
$data["COL"] = array( );
for($i=0; $i<3; $i++)
{
$data["COL"][$i] = array( );
for($j=0; $j<3; $j++)
{
$k = 0;
$id = 0;
while($k < 10)
{
$t = mt_rand(1, $numsites);
HPELoadSingleNews($srcdata, $t);
if(count($srcdata) && !($srcdata["flags"] & HPENewsDisable))
{
$data["COL"][$i][$j] = $HPEtheNEWSmodule->showChannel( $t, 5 );
break;
}
}
}
}
}
echo $HPEtheThemeMaker->TPLRun("page.newsboxes", $data);
}
};
class HPEPageRecentSources extends HPEPage
{
function HPEPageRecentSources()
{
$this->HPEPage();
$this->Reset();
}
function Reset()
{
$this->type = "newsrecentsrc";
$this->url = "";
$this->name = "Recent News Sources";
$this->desc = "Show news boxes for 9 most recent sources";
$this->flags = (HPEPageHasDefValues);
}
function UnSerializeFromXML(&$XMLtree, $path, &$data)
{
}
function SerializeToXML(&$pgdata)
{
$data = "\t\t<PAGE type=\"" . $pgdata["type"] . "\" id=\"" . $pgdata["id"] .
"\" title=\"" . HPEXMLString($pgdata["title"]) . "\" />\n";
return $data;
}
function Create($param)
{
$data = array();
return $data;
}
function Show()
{
global $HPEtheConfig;
global $HPEtheDB;
global $HPEtheThemeMaker;
global $page;
$HPEtheNEWSmodule = &$HPEtheConfig->modhandlers[0]["control"];
$data = array( );
$data["title"] = ($page == -1 ? $this->name : "");
$result = $HPEtheDB->query("SELECT siteid FROM $HPEtheDB->dbtnewssites WHERE !(flags & " . HPENewsDisable . ") ORDER BY siteid DESC LIMIT 9");
if(!$HPEtheDB->iserror($result))
{
$k=0;
$data["COL"] = array( );
for($i=0; $i<3; $i++)
{
$data["COL"][$i] = array( );
for($j=0; $j<3; $j++)
{
$row = $HPEtheDB->getrow($result);
if(!$row)
break;
$data["COL"][$i][$j] = $HPEtheNEWSmodule->showChannel( $row["siteid"], 5 );
}
}
}
echo $HPEtheThemeMaker->TPLRun("sources.recent", $data);
}
};
class HPEPageNewsNavigator extends HPEPage
{
function HPEPageNewsNavigator()
{
$this->HPEPage();
$this->Reset();
}
function Reset()
{
$this->type = "newscat";
$this->url = "";
$this->name = "News Navigator";
$this->desc = "Browse News Items by Category";
$this->flags = (HPEPageHasDefValues | HPEPageEditable);
$this->showpath = $GLOBALS["HPEinc"] . "/plugins/page.newsnav.show.inc";
}
function UnSerializeFromXML(&$XMLtree, $path, &$data)
{
$data["cat"] = $XMLtree->getAttribute($path, "cat");
$data["excludes"] = $XMLtree->getAttribute($path, "excludes");
}
function SerializeToXML(&$pgdata)
{
$data = "\t\t<PAGE type=\"" . $pgdata["type"] . "\" id=\"" . $pgdata["id"] .
"\" title=\"" . HPEXMLString($pgdata["title"]) . "\" cat=\"" . $pgdata["cat"] . "\" " .
" excludes=\"" . $pgdata["excludes"] . "\" />\n";
return $data;
}
function Create($param)
{
$data = array();
if($param == "") {
$data["cat"] = 0;
$data["excludes"] = "";
} else {
$data["cat"] = $param["cat"];
$data["excludes"] = $param["excludes"];
}
return $data;
}
};
class HPEPageTeaser extends HPEPage
{
function HPEPageTeaser()
{
$this->HPEPage();
$this->Reset();
}
function Reset()
{
$this->type = "teaser";
$this->url = "";
$this->name = "Teaser";
$this->desc = "Main Page for guest users";
$this->flags = (HPEPageHidden);
}
function UnSerializeFromXML(&$XMLtree, $path, &$data)
{
}
function SerializeToXML(&$pgdata)
{
$data = "\t\t<PAGE type=\"" . $pgdata["type"] . "\" id=\"" . $pgdata["id"] .
"\" title=\"" . HPEXMLString($pgdata["title"]) . "\" />\n";
return $data;
}
function Create($param)
{
die("Can't create a page of type '$this->type'");
}
function Show()
{
global $HPEtheThemeMaker;
global $HPEtheDB;
global $HPEtheUser;
$data = array(
"numsites" => $HPEtheDB->one_data("SELECT count(*) FROM $HPEtheDB->dbtnewssites")
);
echo $HPEtheThemeMaker->TPLRun("teaser", $data);
}
};
?>