title, ENT_QUOTES, "UTF-8") . "\"\n");
fwrite($fp, " type=\"" . $this->type . "\"\n");
fwrite($fp, " paypalkey=\"" . $this->paypalkey . "\">\n");
fwrite($fp, " \n");
*/
}
public function show()
{
$str = "";
$str .= "
\n";
$str .= "
".$this->title."
\n";
$str .= "
\n";
$str .= "
\n";
return $str;
}
public function Payment($title, $type, $paypalkey)
{
$this->title = $title;
$this->type = $type;
$this->paypalkey = $paypalkey;
}
}
class ShopItem {
public $id;
public $title;
public $description;
public $image;
public $url;
public $payments = array();
public function write($fp)
{
/*
fwrite($fp, " title, ENT_QUOTES, "UTF-8") . "\"\n");
fwrite($fp, " description=\"" .
htmlspecialchars($this->description, ENT_QUOTES, "UTF-8") . "\"\n");
fwrite($fp, " image=\"" . $this->image . "\">\n");
fwrite($fp, " type=\"" . $this->type . "\"\n");
fwrite($fp, " paypalkey=\"" . $this->paypalkey . "\">\n");
fwrite($fp, " \n");
*/
}
public function show()
{
$str = "";
$str .= " \n";
return $str;
}
public function addPayment($payment)
{
$key = $payment->title;
$this->payments[$key] = $payment;
}
public function ShopItem($id, $title, $description, $image, $url)
{
$this->id = $id;
$this->title = $title;
$this->description = $description;
$this->image = $image;
$this->url = $url;
}
}
class Shop {
private $file;
private $shopitems = array();
// Admin config
public $admin_title = "Shop";
public $admin_submodules = array("Add Item" => "add",
"Edit Item" => "edit",
"Delete Item" => "delete");
public function admin($sub, $action, $vars)
{
switch($sub) {
case "add":
break;
case "edit":
break;
case "delete":
break;
}
}
public function run($params)
{
global $GLOBALS;
$str = "\n";
//foreach($params as $param => $value) {}
if($this->shopitems) {
foreach($this->shopitems as $shopitem) {
$str .= $shopitem->show();
}
}
$str .= "
\n";
return $str;
}
public function add($shopitem) {
$key = $shopitem->id;
$this->shopitems[$key] = $shopitem;
}
public function write()
{
/*
$fp = fopen($this->file, "w");
fwrite($fp, "\n");
fwrite($fp, "\n");
foreach($this->discs as $disc) {
$disc->write($fp);
}
fwrite($fp, "\n");
fclose($fp);
*/
}
private function read()
{
$dom = new DomDocument;
$dom->preserveWhiteSpace = FALSE;
$dom->load($this->file);
$shopitems = $dom->getElementsByTagName('shopitem');
if($shopitems) {
foreach($shopitems as $i) {
$shopitem = new ShopItem($i->getAttribute('id'),
$i->getAttribute('title'),
$i->getAttribute('description'),
$i->getAttribute('image'),
$i->getAttribute('url'));
$payments = $i->getElementsByTagName('payment');
if($payments) {
foreach($payments as $p) {
$payment = new Payment($p->getAttribute('title'),
$p->getAttribute('type'),
$p->getAttribute('paypalkey'));
$shopitem->addPayment($payment);
}
}
$this->add($shopitem);
}
}
ksort($this->shopitems);
}
public function Shop($file)
{
$this->file = $file;
if(file_exists($file)) $this->read();
}
}
function shop_init()
{
global $DATA_DIR;
return new Shop($DATA_DIR . "/shop.xml");
}
?>