diff --git a/library/Katharsis/Autoload.php b/library/Katharsis/Autoload.php index 776419b..fd8a341 100644 --- a/library/Katharsis/Autoload.php +++ b/library/Katharsis/Autoload.php @@ -1,51 +1,40 @@ - - * @version 0.5.2 - * @package Katharsis - */ -class Katharsis_Autoload -{ - /** - * @var array - */ - protected static $_classLocations = array( - 'library', - 'application/controller', - 'application/model' - ); - - /** - * Registering autoload method - * - * @return void - */ - public static function init() - { - spl_autoload_register('Katharsis_Autoload::autoload'); - } - - /** - * Actual autoload method. Loads class files automatically when they are needed - * - * @return void - */ - public static function autoload($classname) - { - $name = str_replace("_", DIRECTORY_SEPARATOR, $classname); - - foreach(self::$_classLocations as $location) - { - if(file_exists($location . DIRECTORY_SEPARATOR . $name . ".php")) - { - require_once $location . DIRECTORY_SEPARATOR . $name . ".php"; - return; - } - } - - die('Autoload: could not load class "' . $classname . '"'); - } -} \ No newline at end of file + \ No newline at end of file diff --git a/library/Katharsis/Bootstrap.php b/library/Katharsis/Bootstrap.php index d7a2a9d..226426e 100644 --- a/library/Katharsis/Bootstrap.php +++ b/library/Katharsis/Bootstrap.php @@ -1,29 +1,23 @@ - - * @version 0.5.2 - * @package Katharsis - */ -class Katharsis_Bootstrap -{ - /** - * Central application routing method - * - * @return void - */ - public static function run() - { - $router = Katharsis_ControllerRouting::getInstance(); - - $router->init(); - - Katharsis_Controller_Plugin::preControllerHook(); - - $router->route(); - - Katharsis_Controller_Plugin::postControllerHook(); - } -} \ No newline at end of file +init(); + } + + public static function run() + { + $router = Katharsis_ControllerRouting::getInstance(); + + Katharsis_Controller_Plugin::preControllerHook(); + + $router->route(); + + Katharsis_Controller_Plugin::postControllerHook(); + } +} +?> \ No newline at end of file diff --git a/library/Katharsis/Controller/Abstract.php b/library/Katharsis/Controller/Abstract.php index 460b3e6..0d53407 100644 --- a/library/Katharsis/Controller/Abstract.php +++ b/library/Katharsis/Controller/Abstract.php @@ -1,105 +1,57 @@ - - * @version 0.5.2 - * @package Katharsis - */ -abstract class Katharsis_Controller_Abstract -{ - /** - * @var Katharsis_Db5 - */ - protected $_con; - - /** - * @var Katharsis_View - */ - protected $_view; - - /** - * Instances class attributes, calles init method - * - * @return void - */ - public final function __construct() - { - $this->_con = Katharsis_DatabaseConnector::getConnection(); - $this->_view = Katharsis_View::getInstance(); - $this->init(); - } - - /** - * Overwrite this method instead of using a constructor - * - * @return void - */ - public function init() - { - } - - /** - * If subclass hasn't got a __call method, this exception will be thrown - * - * @return void - */ - public function __call($action, $params) - { - throw new Katharsis_Exception('Action "' . $action . '" doesn\'t exist.'); - } - - /** - * Returns a specific request parameter - * - * @param string $key - * @return mixed - */ - protected function _getParam($key) - { - $params = Katharsis_Request::getParams(); - if(array_key_exists($key,$params)) - { - return $params[$key]; - } - return null; - } - - /** - * Returns all request parameters - * - * @return array - */ - protected function _getAllParams() - { - return Katharsis_Request::getParams(); - } - - /** - * Forward to an other action - * - * @param string $action - * @param string $controller - * @param array $getParams - * @return void - */ - protected function _location($action, $controller = null, $getParams = null) - { - if($controller === null) - { - $controller = Katharsis_Request::getControllerName(); - } - - $paramstring = ""; - if($getParams !== null) - { - foreach($getParams as $key => $value) - { - $paramstring .= "/" . (string) $key . "/" . (string) $value; - } - } - - header("location: " . $this->_view->base . "/" . $controller . "/" . $action . $paramstring); - } -} \ No newline at end of file +_con = Katharsis_DatabaseConnector::getConnection(); + $this->_view = Katharsis_View::getInstance(); + $this->init(); + } + + public function init() + { + } + + public function __call($action, $params) + { + throw new Katharsis_Exception('Die von Ihnen angeforderte Seite (Action) "' . substr($action, 0, -6) . '" konnte nicht gefunden werden.'); + } + + protected function _getParam($key) + { + $params = Katharsis_Request::getParams(); + if(array_key_exists($key,$params)) + { + return $params[$key]; + } + return null; + } + + protected function _getAllParams() + { + return Katharsis_Request::getParams(); + } + + protected function _location($action, $controller = null, $getParams = null) + { + if($controller === null) + { + $controller = Katharsis_Request::getControllerName(); + } + + $paramstring = ""; + if($getParams !== null) + { + foreach($getParams as $key => $value) + { + $paramstring .= "/" . (string) $key . "/" . (string) $value; + } + } + + header("location: " . $this->_view->base . "/" . $controller . "/" . $action . $paramstring); + } +} +?> \ No newline at end of file diff --git a/library/Katharsis/Controller/Plugin.php b/library/Katharsis/Controller/Plugin.php index 0959e3a..07db012 100644 --- a/library/Katharsis/Controller/Plugin.php +++ b/library/Katharsis/Controller/Plugin.php @@ -1,53 +1,27 @@ - - * @version 0.5.2 - * @package Katharsis - */ -class Katharsis_Controller_Plugin -{ - /** - * @var array - */ - protected static $_plugins; - - /** - * Register all plugins with this method - * Plugins will be called in the same order as they have been registered - * - * @param object $object - an instance of your plugin - * @return void - */ - public static function registerPlugin($object) - { - self::$_plugins[] = $object; - } - - /** - * Processes preController methods of all plugins - * - * @return void - */ - public static function preControllerHook() - { - foreach(self::$_plugins as $plugin) - { - $plugin->preController(); - } - } - - /** - * Processes postController methods of all plugins - * - * @return void - */ - public static function postControllerHook() - { - foreach(self::$_plugins as $plugin) - { - $plugin->postController(); - } - } -} \ No newline at end of file +preController(); + } + } + + public static function postControllerHook() + { + foreach(self::$_plugins as $plugin) + { + $plugin->postController(); + } + } +} +?> \ No newline at end of file diff --git a/library/Katharsis/Controller/Plugin/Abstract.php b/library/Katharsis/Controller/Plugin/Abstract.php index dd4663f..fdc2602 100644 --- a/library/Katharsis/Controller/Plugin/Abstract.php +++ b/library/Katharsis/Controller/Plugin/Abstract.php @@ -1,36 +1,19 @@ - - * @version 0.5.2 - * @package Katharsis - */ -abstract class Katharsis_Controller_Plugin_Abstract -{ - public function __construct() - { - $this->_con = Katharsis_DatabaseConnector::getConnection(); - } - - /** - * Overwrite this method, if you want something to be processed - * _before_ the controller is called - * - * @return void - */ - public function preController() - { - } - - /** - * Overwrite this method, if you want something to be processed - * _after_ the controller was called - * - * @return void - */ - public function postController() - { - } -} \ No newline at end of file +_con = Katharsis_DatabaseConnector::getConnection(); + } + + public function preController() + { + } + + public function postController() + { + } +} +?> \ No newline at end of file diff --git a/library/Katharsis/Controller/Plugin/AutoScriptControl.php b/library/Katharsis/Controller/Plugin/AutoScriptControl.php new file mode 100644 index 0000000..33d1ba6 --- /dev/null +++ b/library/Katharsis/Controller/Plugin/AutoScriptControl.php @@ -0,0 +1,21 @@ +autoScriptFile = false; + + + + $scriptName = ucfirst(Katharsis_Request::getControllerName()) . '/' . strtolower(Katharsis_Request::getActionName()); + $autoScriptFile = 'scripts/DidgeridooArtwork/' . $scriptName . '.js'; + $sl = DIRECTORY_SEPARATOR; + + if(file_exists(getcwd() . $sl . str_replace('/', $sl, $autoScriptFile))) + { + $view->autoScriptFile = $view->base . '/' . $autoScriptFile; + } + } +} \ No newline at end of file diff --git a/library/Katharsis/Controller/Plugin/Autorender.php b/library/Katharsis/Controller/Plugin/Autorender.php index ce698a3..4b72b9a 100644 --- a/library/Katharsis/Controller/Plugin/Autorender.php +++ b/library/Katharsis/Controller/Plugin/Autorender.php @@ -1,33 +1,20 @@ - - * @version 0.5.2 - * @package Katharsis - */ -class Katharsis_Controller_Plugin_Autorender extends Katharsis_Controller_Plugin_Abstract -{ - /** - * Renders a controller/action.phtml template automaticly after processing controller - * - * @return void - */ - public function postController() - { - - $view = Katharsis_View::getInstance(); - - $view->controllerAction = false; - - $templateName = strtolower(Katharsis_Request::getControllerName()) . DIRECTORY_SEPARATOR . strtolower(Katharsis_Request::getActionName()); - - if(file_exists('application/view' . DIRECTORY_SEPARATOR . $templateName . '.phtml')) - { - $view->controllerAction = $templateName; - } - - $view = Katharsis_View::getInstance(); - echo $view->render('main'); - } -} \ No newline at end of file +stageContent = false; + + $templateName = ucfirst(Katharsis_Request::getControllerName()) . DIRECTORY_SEPARATOR . strtolower(Katharsis_Request::getActionName()); + + if(file_exists(getcwd() . '/application/view' . DIRECTORY_SEPARATOR . $templateName . '.phtml')) + { + $view->stageContent = $view->render($templateName); + } + + echo $view->render('main'); + } +} +?> \ No newline at end of file diff --git a/library/Katharsis/ControllerRouting.php b/library/Katharsis/ControllerRouting.php index 18aeb19..e6904a0 100644 --- a/library/Katharsis/ControllerRouting.php +++ b/library/Katharsis/ControllerRouting.php @@ -1,136 +1,102 @@ - - * @version 0.5.2 - * @package Katharsis - */ -class Katharsis_ControllerRouting -{ - /** - * @var Katharsis_ControllerRouting - */ - protected static $_instance = null; - - /** - * Singleton. Returns the same instance every time - * - * @return Katharsis_ControllerRouting - */ - public static function getInstance() - { - if(self::$_instance === null) - { - self::$_instance = new self(); - } - return self::$_instance; - } - - /** - * Sets default controller and action names - * - * @return void - */ - protected function __construct() - { - Katharsis_Request::setControllerName('index'); - Katharsis_Request::setActionName('index'); - } - - /** - * Initiates routing process - * - * @return void - */ - public function init() - { - $paramstring = ""; - $baseUrl = preg_replace('#(.*/)[^/]+#', '\1', $_SERVER['SCRIPT_NAME']); - - if(preg_match("~.*" . $baseUrl . "([^/\?]+)/([^/\?]+)/*([^\?]*)~", $_SERVER['REQUEST_URI'], $matches)) - { - $controller = $matches[1]; - $action = $matches[2]; - $paramstring = $matches[3]; - $params = $this->_buildParams($paramstring); - - Katharsis_Request::setControllerName($controller); - Katharsis_Request::setActionName($action); - } else if(preg_match("~.*" . $baseUrl . "([^/\?]+)/*([^\?]*)~", $_SERVER['REQUEST_URI'], $matches)) - { - $controller = $matches[1]; - $paramstring = $matches[2]; - $params = $this->_buildParams($paramstring); - - Katharsis_Request::setControllerName($controller); - } else - { - if(array_key_exists('controller', $_GET)) - { - $controller = $_GET['controller']; - Katharsis_Request::setControllerName($controller); - } - - if(array_key_exists('action', $_GET)) - { - $action = $_GET['action']; - Katharsis_Request::setActionName($action); - } - - $params = $_GET; - } - - Katharsis_Request::setParams($params); - - Katharsis_View::getInstance()->requestHook(); - } - - - /** - * Routing processing method - * - * @return void - */ - public function route() - { - $controllerName = ucfirst(Katharsis_Request::getControllerName()) . 'Controller'; - $action = Katharsis_Request::getActionName() . 'Action'; - - if(class_exists($controllerName)) - { - $controllerObject = new $controllerName(); - - $controllerObject->$action(); - } - } - - - /** - * Splits parameters to an array and returns them - * - * @return array - */ - protected function _buildParams($string) - { - $params = array(); - if(trim($string) !== '') - { - $urlparams = explode("/", $string); - - for($i = 0; $i < count($urlparams); $i=$i+2) - { - if(array_key_exists($i+1, $urlparams)) - { - $params[$urlparams[$i]] = $urlparams[$i+1]; - } else - { - $params[$urlparams[$i]] = null; - } - } - } - - return $params; - } -} \ No newline at end of file +_buildParams($paramstring); + + Katharsis_Request::setControllerName($controller); + Katharsis_Request::setActionName($action); + } + else if(preg_match("~/([^/\?]+)/*([^\?]*)~", $_SERVER['REQUEST_URI'], $matches)) + { + $controller = $matches[1]; + $paramstring = $matches[2]; + $params = $this->_buildParams($paramstring); + + Katharsis_Request::setControllerName($controller); + } + else + { + if(array_key_exists('controller', $_GET)) + { + $controller = $_GET['controller']; + Katharsis_Request::setControllerName($controller); + } + + if(array_key_exists('action', $_GET)) + { + $action = $_GET['action']; + Katharsis_Request::setActionName($action); + } + + $params = $_GET; + } + + Katharsis_Request::setParams($params); + + Katharsis_View::getInstance()->requestHook(); + } + + public function route() + { + $controllerName = ucfirst(Katharsis_Request::getControllerName()) . 'Controller'; + $action = Katharsis_Request::getActionName() . 'Action'; + + if(class_exists($controllerName)) + { + $controllerObject = new $controllerName(); + + $controllerObject->$action(); + } + + } + + protected function _buildParams($string) + { + $params = array(); + if(trim($string) !== '') + { + $urlparams = explode("/", $string); + + for($i = 0; $i < count($urlparams); $i=$i+2) + { + if(array_key_exists($i+1, $urlparams)) + { + $params[$urlparams[$i]] = $urlparams[$i+1]; + } else + { + $params[$urlparams[$i]] = null; + } + } + } + + return $params; + } +} +?> \ No newline at end of file diff --git a/library/Katharsis/DatabaseConnector.php b/library/Katharsis/DatabaseConnector.php index 021bde7..98f12e4 100644 --- a/library/Katharsis/DatabaseConnector.php +++ b/library/Katharsis/DatabaseConnector.php @@ -1,130 +1,92 @@ - - * @version 0.5.2 - * @package Katharsis - */ -class Katharsis_DatabaseConnector -{ - /** - * @var array - */ - public static $_conns = array(); - - /** - * Reading ini file information and connecting - * - * @param string $requestedName - * @return Katharsis_Db5 - */ - protected static function connect($requestedName = null) - { - $ini = parse_ini_file('config/database.config.ini', true); - if($ini !== array()) - { - $conInformation = self::_selectConnection($ini, $requestedName); - return self::_realConnect($conInformation); - } else - { - return null; - } - } - - /** - * Connects to all connections in config file - * - * @param string $requestedName - * @return void - */ - public static function connectAll() - { - $groups = parse_ini_file('config/database.config.ini', true); - - foreach($groups as $iniName => $conInformation) - { - if(preg_match("~^connection:([^:]+)~", $iniName, $matches)) - { - self::getConnection($matches[1]); - } - } - } - - /** - * Calling Katharsis Db connecting method - * - * @param string $requestedName - * @return Katharsis_Db5 - */ - protected static function _realConnect($conInformation) - { - $con = new Katharsis_Db5($conInformation['host'], $conInformation['user'], $conInformation['password'], $conInformation['database']); - - self::$_conns[$conInformation['name']]['connection'] = $con; - self::$_conns[$conInformation['name']]['info'] = $conInformation; - - return $con; - } - - /** - * Returns specified or default connection - * - * @param string $requestedName - * @return Katharsis_Db5 - */ - public static function getConnection($requestedName = null) - { - if($requestedName === null) - { - foreach(self::$_conns as $con) - { - if($con['info']['default'] === true) - { - return $con['connection']; - } - } - return self::connect(null); - } else - { - if(in_array($requestedName, array_keys(self::$_conns))) - { - return self::$_conns[$requestedName]['connection']; - } - return self::connect($requestedName); - } - } - - /** - * Returns an array of connection information - * - * @param array $ini - * @param string $requestedName - * @return array - */ - protected static function _selectConnection($ini, $requestedName = null) - { - foreach($ini as $name => $connectionInfo) - { - if($requestedName === null) - { - if(preg_match("~^connection:([^:]+):default~", $name, $matches)) - { - $connectionInfo['name'] = $matches[1]; - $connectionInfo['default'] = true; - return $connectionInfo; - } - } else - { - if(preg_match("~^connection:" . $requestedName . ".*~", $name)) - { - $connectionInfo['default'] = false; - $connectionInfo['name'] = $requestedName; - return $connectionInfo; - } - } - } - throw new Katharsis_Exception('Could not find database connection information for "' . $requestedName . '"'); - } -} \ No newline at end of file + $conInformation) + { + if(preg_match("~^connection:([^:]+)~", $iniName, $matches)) + { + self::getConnection($matches[1]); + } + } + } + + protected static function _realConnect($conInformation) + { + //$con = new PDO('mysql:host=' . $conInformation['host'] . ';dbname=' . $conInformation['database'], $conInformation['user'], $conInformation['password']); + + + $con = new Katharsis_Db5($conInformation['host'], $conInformation['user'], $conInformation['password'], $conInformation['database']); + + self::$_conns[$conInformation['name']]['connection'] = $con; + self::$_conns[$conInformation['name']]['info'] = $conInformation; + + return $con; + } + + public static function getConnection($requestedName = null) + { + if($requestedName === null) + { + foreach(self::$_conns as $con) + { + if($con['info']['default'] === true) + { + return $con['connection']; + } + } + return self::connect(null); + } else + { + if(in_array($requestedName, array_keys(self::$_conns))) + { + return self::$_conns[$requestedName]['connection']; + } + return self::connect($requestedName); + } + } + + protected static function _selectConnection($ini, $requestedName = null) + { + foreach($ini as $name => $connectionInfo) + { + if($requestedName === null) + { + if(preg_match("~^connection:([^:]+):default~", $name, $matches)) + { + $connectionInfo['name'] = $matches[1]; + $connectionInfo['default'] = true; + return $connectionInfo; + } + } else + { + if(preg_match("~^connection:" . $requestedName . ".*~", $name)) + { + $connectionInfo['default'] = false; + $connectionInfo['name'] = $requestedName; + return $connectionInfo; + } + } + } + throw new Katharsis_Exception('Could not find database connection information for "' . $requestedName . '"'); + } +} +?> \ No newline at end of file diff --git a/library/Katharsis/Db5.php b/library/Katharsis/Db5.php index a282e43..5469b1b 100644 --- a/library/Katharsis/Db5.php +++ b/library/Katharsis/Db5.php @@ -1,627 +1,631 @@ - - * @version 0.5.2 - * @package Katharsis - */ -class Katharsis_Db5 -{ - /** - * @var string - */ - const FETCHMODE_ASSOC = 'ASSOC'; - - /** - * @var string - */ - const FETCHMODE_ARRAY = 'ARRAY'; - - /** - * @var Mysql Resource - */ - private $_connection = null; - - /** - * @var string - */ - private $_host = null; - - /** - * @var string - */ - private $_user = null; - - /** - * @var string - */ - private $_password = null; - - /** - * @var string - */ - private $_database = null; - - /** - * @var string - */ - private $_lastStatement = ""; - - /** - * @var array - */ - private $_lastResult = array(); - - /** - * @var array - */ - private $_lastError = array(); - - /** - * @var int - */ - private $_lastRowCount = 0; - - /** - * Create a connection - * - * @param $host - * @param $user - * @param $password - * @param $database - * - * @return KatharsisDbConnector - */ - public function __construct($host = null, $user = null, $password = null, $database = null) - { - $this->setHost($host); - $this->setUser($user); - $this->setPassword($password); - $this->setDatabase($database); - - if($host !== null && $user !== null && $password !== null && $database !== null) - { - $this->connect(); - } - } - - /** - * Sets the value of $_host - * - * @param string $host - * @author Karl Pannek - */ - public function setHost($value) - { - $this->_host = $value; - } - - /** - * Sets the value of $_user - * - * @param string $user - * @author Karl Pannek - */ - public function setUser($value) - { - $this->_user = $value; - } - - /** - * Sets the value of $_password - * - * @param string $password - * @author Karl Pannek - */ - public function setPassword($value) - { - $this->_password = $value; - } - - /** - * Sets the value of $_database - * - * @param string $database - * @author Karl Pannek - */ - public function setDatabase($value) - { - $this->_database = $value; - $this->_selectDatabase(); - } - - /** - * Returns the value of $_host - * - * @return string - * @author Karl Pannek - */ - public function getHost() - { - return $this->_host; - } - - /** - * Returns the value of $_user - * - * @return string - * @author Karl Pannek - */ - public function getUser() - { - return $this->_user; - } - - /** - * Returns the value of $_password - * - * @return string - * @author Karl Pannek - */ - public function getPassword() - { - return $this->_password; - } - - /** - * Returns the value of $_database - * - * @return string - * @author Karl Pannek - */ - public function getDatabase() - { - return $this->_database; - } - - /** - * Connect to database - * - * - * @return void - */ - public function connect() - { - $this->_connection = @mysql_connect( - $this->getHost(), - $this->getUser(), - $this->getPassword(), - true - ); - - if(!$this->_connection) - { - throw new KatharsisDb5_Exception('Could not connect to "' . $this->getHost() . '" with user "' . $this->getUser() . '".'); - } - - $this->_selectDatabase(); - } - - /** - * Disconnect database connection - * @return bool - */ - public function disconnect() - { - $this->_connection = null; - return (bool) mysql_close($this->_connection); - } - -/** - * Checks connection to database - * - * @return bool - */ - public function isConnected() - { - if($this->_connection !== null && $this->_connection !== false) - { - return true; - } else - { - return false; - } - } - - /** - * Returns mysql connection link resource - * - * @return mysql link resource - */ - public function getMysqlResource () - { - return $this->_connection; - } - - /** - * Executes a Sql statement - * - * @param $statement - * @return bool - */ - public function run ($statement) - { - if($this->_execute($statement)) - { - return true; - } else - { - return false; - } - } - - /** - * Returns Result set for incremental fetching - * - * @param $statement - * @return KatharsisDb5_ResultSet - */ - public function runForIncrementalFetch ($statement) - { - $resultSet = $this->_execute($statement); - return new KatharsisDb5_ResultSet($resultSet); - } - - /** - * Inserts a row into a specified table - * - * @param $table - * @param $values - * @return bool - */ - public function insert ($table, $values = array()) - { - $sets = array(); - - foreach($values as $key => $value) - { - if(is_string($value)) - { - $value = "'" . mysql_real_escape_string($value, $this->_connection) . "'"; - } - $sets[] = "`" . $key . "` = " . $value; - } - - $sql = 'INSERT INTO ' . $table; - - if($values !== array()) - { - $sql .= ' SET ' . implode(',', $sets); - } else - { - $sql .= ' () VALUES () '; - } - - return $this->run($sql); - } - - /** - * Executes Query and returns number of rows - * - * @param $statement - * @return int - */ - public function count ($statement) - { - $result = $this->_execute($statement); - $this->_lastRowCount = mysql_num_rows($result); - return $this->_lastRowCount; - } - - /** - * Returns a fetched result set (All rows) - * - * @param $statement - * @param $fetchmode - * @return array - */ - public function fetchAll($statement, $fetchmode = self::FETCHMODE_ASSOC) - { - return $this->_fetch($statement, $fetchmode, false); - } - - /** - * Returns a fetched result (One rows) - * - * @param $statement - * @param $fetchmode - * @return array - */ - public function fetchOne($statement, $fetchmode = self::FETCHMODE_ASSOC) - { - return $this->_fetch($statement, $fetchmode, true); - } - - public function fetchField ($statement, $field = null) - { - if($field === null) - { - $result = $this->_fetch($statement, self::FETCHMODE_ARRAY, true); - return isset($result[0]) ? $result[0] : null; - } else - { - $result = $this->_fetch($statement, self::FETCHMODE_ASSOC, true); - if(array_key_exists($field, $result)) - { - return $result[$field]; - } - return null; - } - } - - /** - * Prints out details of the last query (Html formatted) - * - * @return void - */ - public function analyseLast () - { - $debug = debug_backtrace(); - $file = explode("/", str_replace("\\", "/", $debug[0]['file'])); - $file = $file[count($file)-1]; - - - echo '
';
-
-		echo '';
-		echo '
QUERY ANALYSIS | from ' . $file . ' on line ' . $debug[0]['line'] . ''; - echo '
'; - echo '
'; - echo 'Statement:
'; - echo '

'; - print_r((string) $this->_lastStatement); - echo '

'; - echo '
'; - - echo '
'; - echo 'Result:
'; - echo '

'; - print_r($this->_lastResult); - echo '

'; - echo '
'; - - if($this->_lastError) - { - echo '
'; - echo 'Error:
'; - echo '

'; - echo ''; - echo ''; - echo ''; - echo '
Number:' . $this->_lastError['number'] . '
Message:' . $this->_lastError['message'] . '
'; - echo '

'; - echo '
'; - } - echo '
'; - } - - /** - * Prepares a statement with certain values - * - * @param $statement - * @param $values - * @return string - */ - public function createStatement ($statement, $values = array()) - { - foreach($values as $key => $value) - { - $wasString = false; - if(is_string($value)) - { - $wasString = true; - } - - if($this->_connection !== null) - { - $value = mysql_real_escape_string($value); - } else - { - $value = mysql_escape_string($value); - } - - // if string, or a integer, but wanting to request via LIKE - if($wasString || preg_match('~%' . $key . '|' . $key . '%~', $statement)) - { - $statement = preg_replace('~\:(%*)' . $key . '(%*)~', "'" . '${1}' . (string) $value . '${2}' . "'", $statement); - } else - { - $statement = str_replace(":" . $key, $value, $statement); - } - } - - return $statement; - } - - /** - * Last primary key that has been inserted - * - * @return int - */ - public function lastInsertId () - { - return mysql_insert_id($this->_connection); - } - - /** - * Returns the number of rows from the last executed statement - * - * @return int - */ - public function lastRowCount () - { - return $this->_lastRowCount; - } - - /** - * Select a database for usage - * - * @return void - * @throws KatharsisDb5_Exception - */ - protected function _selectDatabase() - { - if($this->isConnected() && $this->getDatabase() !== null) - { - if(!mysql_select_db($this->getDatabase(), $this->_connection)) - { - throw new KatharsisDb5_Exception('Could not select database "' . $this->getDatabase() . '".'); - } - } - } - - /** - * Executes Sql statement - * - * @param $statement - * @return mysql resource - */ - protected function _execute($statement) - { - if(!$this->isConnected()) - { - throw new KatharsisDb5_Exception("Not connected to database."); - } - if($result = mysql_query($statement, $this->_connection)) - { - $this->_lastStatement = $statement; - $this->_lastRowCount = mysql_affected_rows($this->_connection); - } - - if(mysql_error($this->_connection)) - { - $this->_lastError['number'] = mysql_errno($this->_connection); - $this->_lastError['message'] = mysql_error($this->_connection); - } else - { - $this->_lastError = array(); - } - - return $result; - } - - /** - * Fetches database result - * - * @param $statement - * @param $fetchmode - * @param $fetchOne - * @return array - */ - protected function _fetch($statement, $fetchmode = self::FETCHMODE_ASSOC, $fetchOne = false) - { - $result = $this->_execute($statement); - - if(!$result) - { - $this->_lastResult = array(); - return array(); - } - - $fetchedResult = array(); - - switch($fetchmode) - { - case self::FETCHMODE_ASSOC: - while($row = mysql_fetch_assoc($result)) - { - if($fetchOne) - { - $fetchedResult = $row; - break; - } else - { - $fetchedResult[] = $row; - } - } - break; - - case self::FETCHMODE_ARRAY: - while($row = mysql_fetch_row($result)) - { - if($fetchOne) - { - $fetchedResult = $row; - break; - } else - { - $fetchedResult[] = $row; - } - } - break; - - default: - throw new KatharsisDb5_Exception('Wrong Fetchmode'); - break; - } - - $this->_lastResult = $fetchedResult; - - return $fetchedResult; - } -} - -/** - * KatharsisDb exception spicification - * - * @author Karl Pannek - * @version 0.5.2 - * @package Katharsis - */ -class KatharsisDb5_Exception extends Exception {} - -/** - * KatharsisDb Result Set - * - * @author Karl Pannek - * @version 0.5.2 - * @package Katharsis - - */ -class KatharsisDb5_ResultSet -{ - /** - * @var Mysql Resource - */ - private $_resultSet; - - /** - * @var Katharsis_Db5 - */ - private $_connection; - - /** - * Sets class attributes - * - * @param Mysql Resource $resultSet - */ - public function __construct($resultSet) - { - $this->_resultSet = $resultSet; - } - - /** - * Fetching next row - * - * @param Mysql Resource $resultSet - */ - public function fetchNext ($fetchmode = Katharsis_Db5::FETCHMODE_ASSOC) - { - switch ($fetchmode) - { - case Katharsis_Db5::FETCHMODE_ASSOC: - return mysql_fetch_assoc($this->_resultSet); - break; - - case Katharsis_Db5::FETCHMODE_ARRAY: - return mysql_fetch_row($this->_resultSet); - break; - - default: - throw new KatharsisDb5_Exception('Wrong Fetchmode'); - break; - } - } -} \ No newline at end of file +setHost($host); + $this->setUser($user); + $this->setPassword($password); + $this->setDatabase($database); + + if($host !== null && $user !== null && $password !== null && $database !== null) + { + $this->connect(); + } + } + + /** + * Sets the value of $_host + * + * @param string $host + * @author Karl Pannek + */ + public function setHost($value) + { + $this->_host = $value; + } + + /** + * Sets the value of $_user + * + * @param string $user + * @author Karl Pannek + */ + public function setUser($value) + { + $this->_user = $value; + } + + /** + * Sets the value of $_password + * + * @param string $password + * @author Karl Pannek + */ + public function setPassword($value) + { + $this->_password = $value; + } + + /** + * Sets the value of $_database + * + * @param string $database + * @author Karl Pannek + */ + public function setDatabase($value) + { + $this->_database = $value; + $this->_selectDatabase(); + } + + /** + * Returns the value of $_host + * + * @return string + * @author Karl Pannek + */ + public function getHost() + { + return $this->_host; + } + + /** + * Returns the value of $_user + * + * @return string + * @author Karl Pannek + */ + public function getUser() + { + return $this->_user; + } + + /** + * Returns the value of $_password + * + * @return string + * @author Karl Pannek + */ + public function getPassword() + { + return $this->_password; + } + + /** + * Returns the value of $_database + * + * @return string + * @author Karl Pannek + */ + public function getDatabase() + { + return $this->_database; + } + + /** + * Connect to database + * + * + * @return void + */ + public function connect() + { + $this->_connection = mysql_connect( + $this->getHost(), + $this->getUser(), + $this->getPassword(), + true + ); + + if(!$this->_connection) + { + throw new KatharsisDb5_Exception('Could not connect to "' . $this->getHost() . '" with user "' . $this->getUser() . '".'); + } + + $this->_selectDatabase(); + } + + /** + * Disconnect database connection + * @return bool + */ + public function disconnect() + { + $this->_connection = null; + return (bool) mysql_close($this->_connection); + } + +/** + * Checks connection to database + * + * @return bool + */ + public function isConnected() + { + if($this->_connection !== null && $this->_connection !== false) + { + return true; + } else + { + return false; + } + } + + /** + * Returns mysql connection link resource + * + * @return mysql link resource + */ + public function getMysqlResource () + { + return $this->_connection; + } + + /** + * Executes a Sql statement + * + * @param $statement + * @return bool + */ + public function run ($statement) + { + if($this->_execute($statement)) + { + return true; + } else + { + return false; + } + } + + /** + * Returns Result set for incremental fetching + * + * @param $statement + * @return KatharsisDb5_ResultSet + */ + public function runForIncrementalFetch ($statement) + { + $resultSet = $this->_execute($statement); + return new KatharsisDb5_ResultSet($resultSet); + } + + /** + * Inserts a row into a specified table + * + * @param $table + * @param $values + * @return bool + */ + public function insert ($table, $values = array()) + { + $sets = array(); + + foreach($values as $key => $value) + { + if(is_string($value)) + { + $value = "'" . mysql_real_escape_string($value, $this->_connection) . "'"; + } + if($value === null) + { + $value = 'NULL'; + } + $sets[] = "`" . $key . "` = " . $value; + } + + $sql = 'INSERT INTO ' . $table; + + if($values !== array()) + { + $sql .= ' SET ' . implode(',', $sets); + } else + { + $sql .= ' () VALUES () '; + } + + return $this->run($sql); + } + + public function simpleDelete($table, $fieldvalue, $fieldname = 'id') + { + $sql = "DELETE FROM " . $table . " WHERE " . $fieldname . " = :field"; + $sql = $this->createStatement($sql, array('field' => $fieldvalue)); + return $this->run($sql); + } + + /** + * Executes Query and returns number of rows + * + * @param $statement + * @return int + */ + public function count ($statement) + { + $result = $this->_execute($statement); + $this->_lastRowCount = mysql_num_rows($result); + return $this->_lastRowCount; + } + + /** + * Returns a fetched result set (All rows) + * + * @param $statement + * @param $fetchmode + * @return array + */ + public function fetchAll($statement, $fetchmode = self::FETCHMODE_ASSOC) + { + return $this->_fetch($statement, $fetchmode, false); + } + + /** + * Returns a fetched result (One rows) + * + * @param $statement + * @param $fetchmode + * @return array + */ + public function fetchOne($statement, $fetchmode = self::FETCHMODE_ASSOC) + { + return $this->_fetch($statement, $fetchmode, true); + } + + /** + * Returns a fetched result (One rows) + * + * @param $statement + * @param $fetchmode + * @return array + */ + public function fetchField ($statement, $field = 0) + { + if(intval($field) === $field) + { + $result = $this->_fetch($statement, self::FETCHMODE_ARRAY, true); + } else + { + $result = $this->_fetch($statement, self::FETCHMODE_ASSOC, true); + } + + return array_key_exists($field, $result) ? $result[$field] : null; + } + + /** + * Prints out details of the last query (Html formatted) + * + * @return void + */ + public function analyseLast () + { + $debug = debug_backtrace(); + $file = explode("/", str_replace("\\", "/", $debug[0]['file'])); + $file = $file[count($file)-1]; + + + echo '
';
+
+		echo '';
+		echo '
QUERY ANALYSIS | from ' . $file . ' on line ' . $debug[0]['line'] . ''; + echo '
'; + echo '
'; + echo 'Statement:
'; + echo '

'; + print_r((string) $this->_lastStatement); + echo '

'; + echo '
'; + + echo '
'; + echo 'Result:
'; + echo '

'; + print_r($this->_lastResult); + echo '

'; + echo '
'; + + if($this->_lastError) + { + echo '
'; + echo 'Error:
'; + echo '

'; + echo ''; + echo ''; + echo ''; + echo '
Number:' . $this->_lastError['number'] . '
Message:' . $this->_lastError['message'] . '
'; + echo '

'; + echo '
'; + } + echo '
'; + } + + /** + * Prepares a statement with certain values + * + * @param $statement + * @param $values + * @return string + */ + public function createStatement ($statement, $values = array()) + { + foreach($values as $key => $value) + { + if($value === null) + { + $statement = str_replace(":" . $key, 'NULL', $statement); + continue; + } + + $wasString = false; + if(is_string($value)) + { + $wasString = true; + } + + if($this->_connection !== null) + { + $value = mysql_real_escape_string($value); + } else + { + $value = mysql_escape_string($value); + } + + // if string, or a integer, but wanting to request via LIKE + if($wasString || preg_match('~%' . $key . '|' . $key . '%~', $statement)) + { + $statement = preg_replace('~\:(%*)' . $key . '(%*)~', "'" . '${1}' . (string) $value . '${2}' . "'", $statement); + } else + { + $statement = str_replace(":" . $key, $value, $statement); + } + } + + return $statement; + } + + public function getEmptyColumnArray($table) + { + $sql = $this->createStatement("SHOW COLUMNS FROM " . $table); + $columns = $this->fetchAll($sql); + $result = array(); + foreach($columns as $column) + { + $result[$column['Field']] = $column['Default']; + } + return $result; + } + + /** + * Last primary key that has been inserted + * + * @return int + */ + public function lastInsertId () + { + return mysql_insert_id($this->_connection); + } + + /** + * Returns the number of rows fro m the last executed statement + * + * @return int + */ + public function lastRowCount () + { + return $this->_lastRowCount; + } + + /** + * Select a database for usage + * + * @return void + * @throws KatharsisDb5_Exception + */ + protected function _selectDatabase() + { + if($this->isConnected() && $this->getDatabase() !== null) + { + if(!mysql_select_db($this->getDatabase(), $this->_connection)) + { + throw new KatharsisDb5_Exception('Could not select database "' . $this->getDatabase() . '".'); + } + } + } + + /** + * Executes Sql statement + * + * @param $statement + * @return mysql resource + */ + protected function _execute($statement) + { + if(!$this->isConnected()) + { + throw new KatharsisDb5_Exception("Not connected to database."); + } + if($result = mysql_query($statement, $this->_connection)) + { + $this->_lastRowCount = mysql_affected_rows($this->_connection); + } + $this->_lastStatement = $statement; + + if(mysql_error($this->_connection)) + { + $this->_lastError['number'] = mysql_errno($this->_connection); + $this->_lastError['message'] = mysql_error($this->_connection); + $this->analyseLast(); + } else + { + $this->_lastError = array(); + $this->_lastResult = " "; + } + + return $result; + } + + /** + * Fetches database result + * + * @param $statement + * @param $fetchmode + * @param $fetchOne + * @return array + */ + protected function _fetch($statement, $fetchmode = self::FETCHMODE_ASSOC, $fetchOne = false) + { + $result = $this->_execute($statement); + + if(!$result) + { + $this->_lastResult = array(); + return array(); + } + + $fetchedResult = array(); + + switch($fetchmode) + { + case self::FETCHMODE_ASSOC: + while($row = mysql_fetch_assoc($result)) + { + if($fetchOne) + { + $fetchedResult = $row; + break; + } else + { + $fetchedResult[] = $row; + } + } + break; + + case self::FETCHMODE_ARRAY: + while($row = mysql_fetch_row($result)) + { + if($fetchOne) + { + $fetchedResult = $row; + break; + } else + { + $fetchedResult[] = $row; + } + } + break; + + default: + throw new KatharsisDb5_Exception('Wrong Fetchmode'); + break; + } + + $this->_lastResult = $fetchedResult; + + return $fetchedResult; + } +} + +/** + * KatharsisDb exception spicification + * + * @author Karl Pannek + */ +class KatharsisDb5_Exception extends Exception {} + +/** + * KatharsisDb Result Set + * + * @author Karl Pannek + */ +class KatharsisDb5_ResultSet +{ + private $_resultSet; + private $_connection; + + public function __construct($resultSet) + { + $this->_resultSet = $resultSet; + } + + public function fetchNext ($fetchmode = Katharsis_Db5::FETCHMODE_ASSOC) + { + switch ($fetchmode) + { + case Katharsis_Db5::FETCHMODE_ASSOC: + return mysql_fetch_assoc($this->_resultSet); + break; + + case Katharsis_Db5::FETCHMODE_ARRAY: + return mysql_fetch_row($this->_resultSet); + break; + + default: + throw new KatharsisDb5_Exception('Wrong Fetchmode'); + break; + } + } + +} +?> \ No newline at end of file diff --git a/library/Katharsis/Exception.php b/library/Katharsis/Exception.php index 9e09ee7..7523094 100644 --- a/library/Katharsis/Exception.php +++ b/library/Katharsis/Exception.php @@ -1,11 +1,4 @@ - - * @version 0.5.2 - * @package Katharsis - */ -class Katharsis_Exception extends Exception -{ + - * @version 0.5.2 - * @package Katharsis - */ -abstract class Katharsis_Model_Abstract -{ - /** - * @var Katharsis_Db5 - */ - protected $_con; - - /** - * Instances class attributes, calles init method - * - * @return void - */ - public final function __construct() - { - $this->_con = Katharsis_DatabaseConnector::getConnection(); - $this->init(); - } - - /** - * Overwrite this method instead of using a constructor - * - * @return void - */ - public function init() - { - } -} \ No newline at end of file +_con = Katharsis_DatabaseConnector::getConnection(); + $this->init(); + } + + public function init() + { + } +} +?> \ No newline at end of file diff --git a/library/Katharsis/Request.php b/library/Katharsis/Request.php index 8470fa1..bef1451 100644 --- a/library/Katharsis/Request.php +++ b/library/Katharsis/Request.php @@ -1,93 +1,44 @@ - - * @version 0.5.2 - * @package Katharsis - */ -class Katharsis_Request -{ - /** - * @var string - */ - protected static $_controller; - - /** - * @var string - */ - protected static $_action; - - /** - * @var array - */ - protected static $_params = array(); - - /** - * Set name of controller - * - * @param string $name - * @return void - */ - public static function setControllerName($name) - { - self::$_controller = $name; - } - - /** - * Set name of action - * - * @param string $name - * @return void - */ - public static function setActionName($name) - { - self::$_action = $name; - } - - /** - * Set parameters - * - * @param array $params - * @return void - */ - public static function setParams($params) - { - foreach($_POST as $key => $value) - { - $params[$key] = $value; - } - self::$_params = $params; - } - - /** - * Get controller name - * - * @return string - */ - public static function getControllerName() - { - return self::$_controller; - } - - /** - * Get action name - * - * @return string - */ - public static function getActionName() - { - return self::$_action; - } - - /** - * Get parameter array - * - * @return array - */ - public static function getParams() - { - return self::$_params; - } -} \ No newline at end of file + $value) + { + $params[$key] = $value; + } + self::$_params = $params; + + } + + public static function getControllerName() + { + return self::$_controller; + } + + public static function getActionName() + { + return self::$_action; + } + + + public static function getParams() + { + return self::$_params; + } +} +?> \ No newline at end of file diff --git a/library/Katharsis/View.php b/library/Katharsis/View.php index a5dc791..6fe506e 100644 --- a/library/Katharsis/View.php +++ b/library/Katharsis/View.php @@ -1,101 +1,73 @@ - - * @version 0.5.2 - * @package Katharsis - */ -class Katharsis_View -{ - /** - * @var Katharsis_View - */ - protected static $_instance = null; - - /** - * @var array - */ - protected $_params = array(); - - /** - * Singleton. Returns the same instance every time - * - * @return Katharsis_View - */ - public static function getInstance() - { - if(self::$_instance === null) - { - self::$_instance = new self(); - } - return self::$_instance; - } - - /** - * Sets base application path - * - * @return void - */ - protected function __construct() - { - $base = preg_replace('/(.+)\/[^\/]+/', '\1', $_SERVER['SCRIPT_NAME']); - $this->_params['base'] = $base != $_SERVER['SCRIPT_NAME'] ? $base : ''; - } - - /** - * Magical get method, gets specific param - * - * @param string $name - * @return string - */ - public function __get($name) - { - if(array_key_exists($name, $this->_params)) - { - return $this->_params[$name]; - } - return null; - } - - /** - * Magical set method, sets specific param - * - * @param string name - * @param string value - */ - public function __set($name, $value) - { - $this->_params[$name] = $value; - } - - /** - * Template rendering method - * - * @param string $template - * @return string - */ - public function render($template) - { - ob_start(); - if(file_exists('application/view/' . $template . '.phtml')) - { - include('application/view/' . $template . '.phtml'); - } - $output = ob_get_contents(); - ob_end_clean(); - - return $output; - } - - /** - * Sets Request params into View params - * - * @return void - */ - public function requestHook() - { - $this->_params['params'] = Katharsis_Request::getParams(); - } -} \ No newline at end of file +_items['base'] = $base != $_SERVER['SCRIPT_NAME'] ? $base : ''; + } + + public function __get($name) + { + if(array_key_exists($name, $this->_items)) + { + if(is_array($this->_items[$name])) + { + return (array) $this->_items[$name]; + } + return $this->_items[$name]; + } + return null; + } + + public function __set($name, $value) + { + $this->_items[$name] = $value; + } + + public function render($template) + { + ob_start(); + if(file_exists('application/view/' . $template . '.phtml')) + { + include('application/view/' . $template . '.phtml'); + } + $output = ob_get_contents(); + ob_end_clean(); + + return $output; + } + + public function requestHook() + { + } + + public function _getParam($key) + { + $params = Katharsis_Request::getParams(); + if(array_key_exists($key,$params)) + { + return $params[$key]; + } + return null; + } + + public function formatDate($date) + { + $date = explode("-", $date); + return $date[2] . '.' . $date[1] . '.' . $date[0]; + } +} +?> \ No newline at end of file diff --git a/public/.htaccess b/public/.htaccess index f9567cf..0b3ece8 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -1,4 +1,7 @@ RewriteEngine On + +RewriteBase / + RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d diff --git a/public/index.php b/public/index.php index 735eb4f..13aa649 100644 --- a/public/index.php +++ b/public/index.php @@ -23,6 +23,7 @@ Katharsis_Controller_Plugin::registerPlugin(new DidgeridooArtwork_Controller_Plu try { + Katharsis_Bootstrap::init(); Katharsis_Bootstrap::run(); } catch(Exception $e) {