<?php
//#################################################################################################
// Module class
//#################################################################################################
// chillyCMS - Content Management System
// Copyright (C) 2008
// Stefanie Wiegand <hide@address.com> & Johannes Cox <hide@address.com>
//
// This program is licensed under the GPL 3.0 license. For more information see LICENSE.txt.
//#################################################################################################
defined('DOIT') or die('Restricted access');
require_once("database.class.php");
class Module {
//Class variables//////////////////////////////////////////////////////////////////////////
private $modid;
private $name; //Name of the module == folder in /modules
private $author;
private $version;
private $type; //0=main module, 1=submodule
private $outputfile; //file that manages the output (mostly index.php)
private $settings;
//Functions////////////////////////////////////////////////////////////////////////////////
//Constructor for creating/uploading a module
function __construct() {}
//Destructor
function __destruct() { $modid=$name=$author=$version=$type=$outputfile=$settings=false; }
//Getter
public function __get($name) {
if (isset($this->$name)) { return $this->$name; }
else { return false; }
}
//Store to database
function store() {
global $l_core,$page;
$action="insert";
$error=false;
$page->query("select name,version from system_modules where name='$this->name' limit 1");
$result = $page->db->getdata();
//module already exists
if (is_array($result) && !empty($result)) {
//is it a new version? -> update
if (version_compare($this->version,$result["version"],">")) {
$action="update";
//it is the same or an old version: do nothing
} else {
$page->debug('Module already exists in same or newer version');
return array($l_core["msg_modexists_err"],"bad");
}
}
if ($action=="insert") {
$page->debug('New module - inserting...');
$sql="insert into system_modules (`name`,`author`,`version`,`type`) values ".
"('$this->name','$this->author','$this->version',$this->type)";
} elseif ($action=="update") {
$page->debug('Existing module - updating...');
$sql="update system_modules set ".
"`author`='$this->author',`version`='$this->version',`type`=$this->type where name='$this->name'";
}
if (!$page->query($sql)) { $error=true; }
if (!$error) { $msg = array($l_core["msg_modupload_ok"].": ".$this->name,"good"); }
else { $msg = array($l_core["msg_modupload_err"]." ".$this->name,"bad"); }
return $msg;
}
//fill in data
function fill($name,$author,$version,$type,$outputfile,$settings=null) {
//Set values
$this->modid="";
$this->name=$name;
$this->author=$author;
$this->version=$version;
$this->type=$type;
$this->outputfile=$outputfile;
$this->settings=$settings;
}
//Load data from database
function load($id) {
global $page;
$page->query("select * from system_modules where modid=$id limit 1");
$result = $page->db->getdata();
$this->modid = $id;
$this->name = $result["name"];
$this->author = $result["author"];
$this->version = $result["version"];
$this->type = $result["type"];
$this->settings = $result["settings"];
//load outputfile
include(PATH."/modules/".$this->name."/config.php");
$this->outputfile = $outputfile;
}
} ?>