/* * * System * rozpoczęcie: 2006-12-12 * modyfikacje: 2011-01-19 * **/ class system { private $config; public $tpl; /* zewnetrzny template */ public $modulesLoaded = array(); /* zaladowane moduly */ private $modulesList; /* zawiera liste dostepnych modulow */ private $vars; /* holds system variables */ /** * * Instancja klasy Sql * @var ML\SQL\SQL */ public $sql; private $modulePrefix = ''; public static $instance; private function disableMagicQuotes() { // zignorowanie magicznych quotek, nawet jak są włączone... if (version_compare(phpversion(), '5.3', '<')) { // Dla PHP 5.2 i wcześniejszych wyłączmy magic quotes function removeSlashes(&$value) { if (is_array($value)) { return array_map('removeSlashes', $value); } else { return stripslashes($value); } } // end removeSlashes(); set_magic_quotes_runtime(0); if (get_magic_quotes_gpc()) { $_POST = array_map('removeSlashes', $_POST); $_REQUEST = array_map('removeSlashes', $_REQUEST); $_GET = array_map('removeSlashes', $_GET); $_COOKIE = array_map('removeSlashes', $_COOKIE); } } } private function requiredPHPConfiguration() { $errors = array(); /* if (get_magic_quotes_gpc()) { $errors[] = 'Turn OFF magic quotes please!'; }*/ // TODO wpisać wymagane moduły do PHPa if (version_compare(phpversion(), '5.3', '<')) { $errors[] = 'Required PHP 5.3 or later!'; } if (!extension_loaded('gd') || !function_exists('gd_info')) { $errors[] = 'It looks like GD is not installed.'; } if (!empty($errors)) { die("
Fix following errors: \n" . implode("
", $errors));
}
}
/**
* Pobiera instancję systemu.
* @return system
*/
public static function getInstance() {
if (!isset(self::$instance)) {
$c = __CLASS__;
self::$instance = new $c;
}
return self::$instance;
}
protected function __construct() {
$cli = !isset($_SERVER['HTTP_HOST']);
$this->set("CLI", $cli);
define('CLI', $cli);
date_default_timezone_set('Europe/Warsaw');
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__);
$this->requiredPHPConfiguration();
// Rozważy warto zmianę autoloadera zenda na tego z Symfony lub dodanie loadera z symfony... :)
// Autoloader zenda raczej nie porywa możliwościami. :)
require_once('Zend/Loader/Autoloader.php');
Zend_Loader_Autoloader::getInstance();
// TODO cel, to likwidacja require i zrobienie nazw klas tak, żeby ładowały się automatycznie za pomocą
// autoloadera zgodnego ze standardem PSR-0
require_once('ML-Lib/loader.php'); // Klasa SQL itp
require_once('functions.php');
require_once('class.module.php');
require_once('class.cms_module.php');
require_once('class.autoload.php');
require_once('class.template.php');
require_once('class.tree.php');
require_once('class.cms_tree.php');
require_once('class.paginate_base.php');
require_once('class.paginate.php');
require_once('class.pagedresults.php');
require_once('class.simple_paginate.php');
require_once('class.config.php');
require_once('helper.php');
require_once('class.mailer.php');
require_once('AF_Forms/Form.php');
require_once('class.model_paginate.php');
// włącz poniższą linijkę, jeżeli zamiast notice, warning, itp chcesz miec wyjątki...
// Wszystko, co normalnie wyświetlane byłoby na ekranie wywali wyjątek, zgodnie z error reporting.
// Niestety biblioteka E2e nie ma ładnego Error handlera, który wyświetli błąd w przystępny sposób (jak we frameworkach)
// ML\E2e\ErrorHandler::run();
CMSAutoload::register();
$config = Config::run(dirname(__FILE__).'/../config');
if (requestInt('debug')) {
$config->debug = true;
}
$this->config = $config->get();
// TODO zrobić logowanie błędów PHPa do plików!
if (getConfig('debug') == false) {
ini_set('display_errors', '0');
error_reporting(0);
}
}
function getConfig() {
return $this->config;
}
function start() {
if (!CLI) {
if (isset($_GET['print'])){
$this->tpl = new Template('tpl/print.php');
}
else {
$this->tpl = new Template('tpl/index.php');
}
}
$this->dbStart();
}
function show() {
echo $this->tpl->fetch();
}
function halt() {
$this->stop();
exit(0);
}
public function getModule($modName) {
if (isset($this->modulesLoaded[$modName])) {
return $this->modulesLoaded[$modName];
}
return null;
}
private function addModule($modName, module $object) {
$this->modulesLoaded[$modName] = $object;
}
public function setModulePrefix($prefix) {
$this->modulePrefix = $prefix;
}
/**
*
* TODO Ładowanie modułów powinno się odbywac niezależnie od klasy system. System powinien dostac w parametrze
* klasę ModuleLoadera i będzie się do instancji tej klasy odwoływał, gdy będzie szukał modułów.
*
* TODO należy zrezygnowac z ładowania modułów z index.php i nazwamodułu.php i zostawic tylko opcję 2 - nazwamodułu.php.
*
* Ładuje moduły
* @param string $modName
* @param string $prefix
* @throws NotFoundException
*/
public function loadModule($modName, $prefix = false) {
if ($prefix === false) {
$prefix = IS_CMS?'cms_':'';
}
$filename = "$modName/$modName.php";
$modPath = CMS_PATH . "mod/$filename";
if (IS_CMS || $prefix == 'cms_') {
$modPath = ADMIN_PATH . "mod/$filename";
}
if (file_exists($modPath)) {
$class = $prefix.$modName;
$module = $this->getModule($class);
if (!$module) {
include_once($modPath);
$module = new $class();
$this->addModule($class, $module);
}
return $module;
}
else {
throw new NotFoundException("Module '$modName' in '$modPath' not found!");
}
}
public function dbStart() {
// Najnowsza wersja biblioteki na GitHubie :)
// https://github.com/renq/ML-Lib
$settings = new ML\SQL\Settings($this->config['db']);
$connection = new ML\SQL\Connection_PDO_MySQL($settings);
if (getConfig('db_debug')) {
$connection = new ML\SQL\Connection_Decorator_Debug($connection);
}
$strategy = new ML\SQL\Strategy_MySQL($connection);
$this->sql = new ML\SQL\SQL($connection, $strategy);
}
public function setTemplate(Template $tpl) {
$this->tpl = $tpl;
}
public function getTemplate() {
return $this->tpl;
}
/**
* Zatrzymuje system.
* Zamyka połączenie do bazy, czyści flashowe zmienne sesyjne
* @return void
*/
public function stop() {
//$this->sql->stop();
unset($this->sql);
}
public function set($name, $value) {
$this->vars[$name] = $value;
}
public function get($name) {
return isset($this->vars[$name])?$this->vars[$name]:false;
}
public function setConfig($array) {
$this->config = $array;
}
/**
* @return Sql
*/
public function getSql() {
return $this->sql;
}
}
?>
/**
*
* My System
* Klasa, do której dopisujemy modyfikacje systemu potrzebne do jednego projektu
* @author Michał Lipek
*
**/
class my_system extends system {
public static $instance;
protected function __construct() {
parent::__construct();
Zend_Loader_Autoloader::getInstance()->registerNamespace(array('PYS', 'GSub'));
}
public function start() {
parent::start();
}
/**
* @return my_system
*/
public static function getInstance() {
if (!isset(self::$instance)) {
$c = __CLASS__;
self::$instance = new $c;
parent::$instance = self::$instance;
}
return self::$instance;
}
public function dbStart() {
parent::dbStart();
}
}
?>
Fatal error: Uncaught Error: Class "my_system" not found in /home/hosting/www/berling.com.pl/www/index.php:16
Stack trace:
#0 {main}
thrown in /home/hosting/www/berling.com.pl/www/index.php on line 16