<?
/*
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
*/
require_once "$HPEinc/Smarty.class.php";
require_once "$HPEinc/PHPClientSniffer.inc";
require_once "$HPEinc/pagemaker.inc";
$HPEClientSniffer = new sniffer;
if(!isset($HPEDefTPLData))
$HPEDefTPLData = array();
$HPEDefTPLData = array_merge( $HPEDefTPLData, array(
"HPECURDATE" => time(),
"HPERANDOM5" => mt_rand(10000, 999999),
"HPEVERSION" => $HPEVersion,
"HPECONFIG" => array(
"dbnews" => $HPEtheConfig->storenewsindb,
"hasemail" => $HPEtheConfig->hasemail
),
"HPESITENAME" => $HPEtheConfig->sitename,
"HPESITELINK" => $HPEtheConfig->siteurl,
"HPESITEROOT" => $HPEtheConfig->siteroot,
"HPEADMINNAME" => $HPEtheConfig->adminname,
"HPEADMINMAIL" => $HPEtheConfig->adminemail,
"HPEBROWSER" => $HPEClientSniffer,
"HPEEXT" => "php",
"HPEINC" => $HPEinc,
"HPEREFERER" => isset($HTTP_REFERER) ? $HTTP_REFERER : ""
) );
class HPESmarty extends Smarty
{
function HPESmarty($basedir = "")
{
global $HPEtheConfig;
global $HPEtheUser;
global $HPEtheThemeMaker;
global $HPEinc;
global $page;
global $HPEClientSniffer;
$this->template_dir = $basedir . '/templates'; // name of directory for templates
$this->compile_dir = $basedir . '/templates_c'; // name of directory for compiled templates
$this->cache_dir = $basedir . '/cache'; // directory where cache files are located
$this->config_dir = $HPEinc . '/lang'; // directory where config files are located
$this->Smarty();
$this->assign( $GLOBALS["HPEDefTPLData"] );
$this->assign( array(
"HPETHEMEROOT" => $HPEtheThemeMaker->themeurl,
"HPETHEMEPATH" => $HPEtheThemeMaker->themepath,
"HPETHISPAGE" => $HPEtheConfig->makeURLToPage(),
"HPEPAGE" => (isset($page) ? $page : -1)
) );
if(isset($HPEtheUser))
{
$this->assign( array(
"HPELANG" => $HPEtheUser->lang,
"HPEUSERID" => $HPEtheUser->userid,
"HPEUSER" => array(
"lang" => $HPEtheUser->lang,
"level" => $HPEtheUser->level,
"isguest" => ($HPEtheUser->userid == 0),
"isadmin" => $HPEtheUser->isadmin,
"login" => $HPEtheUser->userlogin,
"name" => $HPEtheUser->name,
"email" => $HPEtheUser->email,
"iseditor" => $HPEtheUser->iseditor,
"hlshowdesc" => $HPEtheUser->showdesc,
"hlshowdate" => $HPEtheUser->showdate,
"nbpages" => $HPEtheUser->nbpages,
"nosmarttags" => $HPEtheUser->nosmarttags,
"p2blogger" => $HPEtheUser->post2blogger,
"p2manila" => $HPEtheUser->post2manila,
"p2radio" => $HPEtheUser->post2radio
)
) );
if($HPEtheUser->userid == 0)
{
$n = count($HPEtheConfig->langcodes);
$langs = array();
for($i=0; $i<$n; $i++)
$langs[$i] = array(
"id" => $HPEtheConfig->langcodes[$i],
"name" => $HPEtheConfig->langnames[$HPEtheConfig->langcodes[$i]]
);
$this->assign("langs", $langs);
}
$GLOBALS["HPELANG"] = $HPEtheUser->lang;
}
else
{
$GLOBALS["HPELANG"] = "en";
$this->assign( array(
"HPELANG" => $HPEtheConfig->deflang,
"HPEUSERID" => 0,
"HPEUSER" => array(
"lang" => $HPEtheConfig->deflang,
"level" => 0,
"isguest" => 1,
"isadmin" => 0,
"login" => "guest",
"name" => "guest",
"email" => "nobody@nowhere.com",
"iseditor" => 0,
"hlshowdesc" => 1,
"hlshowdate" => 1,
"nbpages" => 0,
"nosmarttags" => 1,
"p2blogger" => 0,
"p2manila" => 0,
"p2radio" => 0
)
) );
}
$this->custom_mods["wordwrap"] = "smarty_mod_wordwrap";
$this->custom_mods["striptags"] = "smarty_mod_striptags";
$this->custom_mods["ucfirst"] = "smarty_mod_ucfirst";
$this->register_resource("lang", "get_HPElang_template");
}
};
function get_HPElang_template(&$smarty, $tpl_name, &$tpl_source, &$tpl_timestamp)
{
global $HPEinc;
global $HPEtheConfig;
global $HPEtheThemeMaker;
// echo "Processing $tpl_name<BR>\n";
if(file_exists($smarty->template_dir . "/$tpl_name"))
{
$cf = fopen($smarty->template_dir . "/$tpl_name", "r");
if($cf)
{
$tpl_source = fread($cf, filesize($smarty->template_dir . "/$tpl_name"));
fclose($cf);
$tpl_timestamp = filemtime($smarty->template_dir . "/$tpl_name");
}
else return false;
}
else
{
$parts = explode(".", $tpl_name, 2);
if(count($parts) != 2)
return false;
if(!in_array($parts[0], $HPEtheConfig->langcodes))
return false;
$lang = $parts[0];
$tpl_name = $parts[1];
if(file_exists($smarty->template_dir . "/en.$tpl_name"))
{
$cf = fopen($smarty->template_dir . "/en.$tpl_name", "r");
if($cf)
{
$tpl_source = fread($cf, filesize($smarty->template_dir . "/en.$tpl_name"));
fclose($cf);
$tpl_timestamp = filemtime($smarty->template_dir . "/en.$tpl_name");
}
else return false;
}
if(!file_exists($smarty->template_dir . "/$tpl_name"))
return false;
$cf = fopen($smarty->template_dir . "/$tpl_name", "r");
if(!$cf)
return false;
$tpl_source = fread($cf, filesize($smarty->template_dir . "/$tpl_name"));
fclose($cf);
$langdate = 0;
$langfile = $smarty->template_dir . "/$lang.xml";
if(file_exists($langfile))
$langdate = filemtime($langfile);
$langfile = "$HPEinc/lang/$lang.xml";
if(file_exists($langfile))
$langdate = max(filemtime($langfile), $langdate);
$langfile = $HPEtheConfig->localpath . "/lang/$lang.xml";
if(file_exists($langfile))
$langdate = max(filemtime($langfile), $langdate);
$tpl_timestamp = max($langdate, filemtime($smarty->template_dir . "/$tpl_name"));
$cfd = @filemtime($smarty->compile_dir . "/lang%3A$lang." . $tpl_name . ".php");
if($tpl_timestamp <= $cfd)
return true;
$HPEtheThemeMaker->GetLangStrings("en", $smarty->template_dir);
$HPEtheThemeMaker->GetLangStrings($lang, $smarty->template_dir);
$tpl_source = strtr($tpl_source, $HPEtheThemeMaker->langstrings);
// die("<pre>$tpl_source");
}
return true;
}
function insert_HPEGetNewsSource($params)
{
global $HPEtheConfig;
while(list($key, $val) = each($params))
$$key = $val;
if(!isset($source)) return "no source given";
if(!isset($maxitems)) $maxitems = 0;
if(!isset($modid)) $modid = -1;
return $HPEtheConfig->modhandlers[0]["control"]->showChannel($source, $maxitems, $modid);
}
function insert_HPEGetNewsHeadlines($params)
{
global $HPEtheConfig;
global $HPEtheThemeMaker;
global $HPEinc;
global $HPEtheUser;
while(list($key, $val) = each($params))
$$key = $val;
if(!isset($source)) return "no source given";
else
{
$source = explode(",", $source);
if(count($source) == 0)
return "source syntax error";
}
if(!isset($maxitems)) $maxitems = 0;
if(!isset($sort)) $sort = 1;
$nitems = HPELoadMultiNews(&$data, $source, $maxitems, $sort, $HPEtheUser->level);
for($i=0; $i<$nitems; $i++)
{
$data["items"][$i]["elink"] = "";
$data["items"][$i]["ulink"] = "";
$data["items"][$i]["link"] = $HPEtheConfig->siteroot . "click/" . $data["items"][$i]["id"] . "/";
}
return $HPEtheThemeMaker->TPLRun("itemlist", $data);
}
function insert_HPEGetNewsArchives($params)
{
global $HPEtheConfig;
global $HPEtheThemeMaker;
global $HPEinc;
while(list($key, $val) = each($params))
$$key = $val;
if(!isset($source))
return "no source given";
$nitems = HPELoadArchives(&$data, $source);
for($i=0; $i<$nitems; $i++)
{
$data["items"][$i]["elink"] = "";
$data["items"][$i]["ulink"] = "";
$data["items"][$i]["link"] = $HPEtheConfig->siteroot . "click/" . $data["items"][$i]["id"] . "/";
}
return $HPEtheThemeMaker->TPLRun("itemlist", $data);
}
function insert_HPEGetCustomNews($params)
{
global $HPEtheConfig;
global $HPEtheThemeMaker;
global $HPEinc;
while(list($key, $val) = each($params))
$$key = $val;
if(!isset($agent)) return "no agent given";
if(!isset($maxitems)) $maxitems = 0;
$nitems = HPELoadCustomNews(&$data, $agent, $maxitems);
for($i=0; $i<$nitems; $i++)
{
$data["items"][$i]["elink"] = "";
$data["items"][$i]["ulink"] = "";
$data["items"][$i]["link"] = $HPEtheConfig->siteroot . "click/" . $data["items"][$i]["id"] . "/";
}
return $HPEtheThemeMaker->TPLRun("itemlist", $data);
}
function insert_HPELastUpdates($params)
{
global $HPEtheDB;
global $HPEtheConfig;
global $HPEtheThemeMaker;
while(list($key, $val) = each($params))
$$key = $val;
if(!isset($category)) $category = 0;
if(!isset($maxsources)) $maxsources = 30;
$query = "SELECT s.siteid, s.sitename, s.description, u.lastmod, u.ncount FROM $HPEtheDB->dbtnewsupdates AS u, $HPEtheDB->dbtnewssites AS s WHERE u.id=s.siteid AND u.ncount >= 0 AND !(s.flags & " . HPENewsDisable . ") ";
if($category)
$query .= "AND s.categorie=$category ";
$query .= "ORDER BY u.lastmod DESC LIMIT $maxsources";
$result = $HPEtheDB->query($query);
if(!$HPEtheDB->iserror($result))
{
$i = 0;
$data = array(
"sources" => array()
);
while($row = $HPEtheDB->getrow($result))
{
$data["sources"][$i] = array(
"title" => $row["sitename"],
"url" => $HPEtheConfig->siteurl . "sources/info/" . $row["siteid"] . "/",
"desc" => $row["description"],
"lastmod" => $row["lastmod"],
"day" => $row["lastmod"] - ($row["lastmod"] % (3600 * 24)),
"newcount" => $row["ncount"]
);
++$i;
}
return $HPEtheThemeMaker->TPLRun("sidebox.recentupdates", $data);
}
else return "";
}
function insert_HPENewChannels($params)
{
global $HPEtheConfig;
while(list($key, $val) = each($params))
$$key = $val;
return $HPEtheConfig->modhandlers[2]["control"]->show(0, -1);
}
function smarty_mod_wordwrap($string, $width=72, $break="\n", $cut=false)
{
return wordwrap($string, $width, $break, $cut);
}
function smarty_mod_striptags($string)
{
return strip_tags($string);
}
function smarty_mod_ucfirst($string)
{
return ucfirst($string);
}
class HPEThemeMaker
{
var $id;
var $imgpath;
var $themepath;
var $themeurl;
var $mode = "";
var $tpl;
var $extwin = "_self";
var $lang = "en";
var $langstrings;
function HPEThemeMaker()
{
global $HPEtheConfig;
$this->themepath = $HPEtheConfig->themes[$HPEtheConfig->deftheme]["path"];
$this->themeurl = $HPEtheConfig->themes[$HPEtheConfig->deftheme]["url"];
$this->langstrings = array();
}
function initTheme($id)
{
global $HPEtheUser;
global $HPEtheConfig;
global $HPEinc;
if(isset($HPEtheConfig->themes[$id]))
{
$this->themepath = $HPEtheConfig->themes[$id]["path"];
$this->themeurl = $HPEtheConfig->themes[$id]["url"];
}
elseif(@is_dir("$HPEtheConfig->localpath/$id"))
{
$this->themepath = "$HPEtheConfig->localpath/$id";
$this->themeurl = preg_replace("%$HPEinc%", $HPEtheConfig->siteurl . "HPE", $HPEtheConfig->localpath) . "/$id";
}
elseif(@is_dir("$HPEinc/$id"))
{
$this->themepath = "$HPEinc/$id";
$this->themeurl = $HPEtheConfig->siteurl . "HPE/$id";
}
else
{
$this->themepath = $HPEtheConfig->themes[$HPEtheConfig->deftheme]["path"];
$this->themeurl = $HPEtheConfig->themes[$HPEtheConfig->deftheme]["url"];
}
if(isset($HPEtheUser))
{
if($HPEtheUser->extwin)
$this->extwin="blank";
$this->lang = $HPEtheUser->lang;
}
$HPEtheConfig->phpinclude = ereg_replace("^%HPEtheme%", $this->themeurl, $HPEtheConfig->phpinclude);
}
function ClearCompileDir()
{
global $HPEtheConfig;
for($i=0; $i<count($HPEtheConfig->themes); $i++)
{
$smarty = new HPESmarty($HPEtheConfig->themes[$i]["path"]);
$smarty->clear_compile_dir();
unset($smarty);
}
}
function TPLRun($tpl, $data)
{
global $HPEtheConfig;
global $HPEthePager;
$smarty = new HPESmarty($this->themepath);
$HPEthePager->GetPageData($data);
$smarty->assign($data);
$smarty->assign("HPELINKTARGET", $this->extwin);
if(!strstr($tpl, ":"))
$tpl = "lang:$this->lang.$tpl.tpl";
else $tpl = "$tpl.tpl";
$res = $smarty->fetch($tpl);
return $res;
}
function TPLModule(&$data, $comment, $closelink, $editlink, $configlink, $moduletpl)
{
global $HPEtheConfig;
$smarty = new HPESmarty($this->themepath);
$smarty->compile_check = true;
$smarty->assign( array(
"HPELINKTARGET" => $this->extwin,
"MODULECOMMENT" => $comment,
"MODULECLOSELINK" => $closelink,
"MODULEEDITLINK" => $editlink,
"MODULECONFIGLINK" => $configlink
) );
$smarty->assign( $data );
return $smarty->fetch("lang:$this->lang.$moduletpl.tpl");
}
function TPLSectionBegin($title)
{
global $HPEtheConfig;
$smarty = new HPESmarty($this->themepath);
$smarty->assign( array(
"title" => $title
) );
return $smarty->fetch("lang:$this->lang.section.begin.tpl");
}
function TPLSectionEnd()
{
global $HPEtheConfig;
$smarty = new HPESmarty($this->themepath);
return $smarty->fetch("lang:$this->lang.section.end.tpl");
}
function TPLFrameBegin()
{
return $this->TPLSectionBegin("");
}
function TPLFrameEnd()
{
return $this->TPLSectionEnd();
}
function GetLangStrings($lang, $tpldir)
{
global $HPEinc;
global $HPEtheConfig;
$this->ParseLangFile("$HPEinc/lang/$lang.xml");
$langfile = $HPEtheConfig->localpath . "/lang/$lang.xml";
if(file_exists($langfile))
$this->ParseLangFile($langfile);
$langfile = "$tpldir/$lang.xml";
if(file_exists($langfile))
$this->ParseLangFile($langfile);
}
function ParseLangFile($langfile)
{
$XMLtree = new XMLtree;
if ($err = $XMLtree->parse($langfile))
die("Failed to parse XML language file $langfile: $err\n");
$secndx = 1;
while(1)
{
$strndx = 1;
$section = $XMLtree->getAttribute("/lang(1)/section($secndx)", "title");
if(empty($section))
break;
while(1)
{
$strlabel = $XMLtree->getEltByPath("/lang(1)/section($secndx)/string($strndx)/label(1)");
if(empty($strlabel))
break;
$strtext = $XMLtree->getEltByPath("/lang(1)/section($secndx)/string($strndx)/text(1)");
if(empty($strtext))
continue;
$strtext = str_replace("<", " <", $strtext);
$strtext = str_replace(">", "> ", $strtext);
$this->langstrings["{%" . $strlabel . "%}"] = $strtext;
$strndx++;
}
$secndx++;
}
}
};
$HPEtheThemeMaker = new HPEThemeMaker();
function beginframe($ocls = "", $icls = "")
{
global $HPEtheThemeMaker;
echo $HPEtheThemeMaker->TPLFrameBegin();
}
function endframe()
{
global $HPEtheThemeMaker;
echo $HPEtheThemeMaker->TPLFrameEnd();
}
function beginsection($section)
{
global $HPEtheThemeMaker;
echo $HPEtheThemeMaker->TPLSectionBegin($section);
}
function endsection()
{
global $HPEtheThemeMaker;
echo $HPEtheThemeMaker->TPLSectionEnd();
}
?>