Пример #1
0
 function output()
 {
     //set all template variables
     foreach ($this->vars as $var => $val) {
         ${$var} = $val;
     }
     if ($this->parent_view) {
         foreach ($this->parent_view->vars as $var => $val) {
             ${$var} = $val;
         }
     }
     // TODO: Check extract() for an alternative method
     $path = Kennel::cascade("{$this->view}", 'views');
     if (!$path) {
         return debug::error("View <strong>{$this->view}</strong> not found.");
     }
     //begin intercepting the output buffer
     ob_start();
     if ($path) {
         require $path;
     }
     //return the output and close the buffer
     return ob_get_clean();
     //unset all template variables
     foreach ($this->vars as $var => $val) {
         unset(${$var});
     }
 }
Пример #2
0
 /**
  * Checks whether there are a message set to a given slot
  * 
  * @param string $slot the slot to check
  */
 static function has($slot)
 {
     if (!session_id()) {
         session_start();
     }
     $app_id = Kennel::getSetting('application', 'id');
     if (isset($_SESSION["{$app_id}-flash"][$slot]) && count($_SESSION["{$app_id}-flash"][$slot]) > 0) {
         return true;
     } else {
         return false;
     }
 }
Пример #3
0
 static function file($uri)
 {
     # Absolute paths
     if (substr($uri, 0, 7) === 'http://') {
         return $uri;
     }
     # Cascading Resource
     $path = Kennel::cascade($uri, 'file', true);
     if ($path) {
         return $path;
     } else {
         debug::error("assets helper: File <b>{$uri}</b> not found.", 1);
     }
 }
Пример #4
0
 function getLang($long_title = false)
 {
     if (router::$PREFIX) {
         $code = router::$PREFIX;
     } elseif (Kennel::getSetting('i18n', 'detect') && ($browser = self::browser() && preg_match('/' . Kennel::getSetting('i18n', 'list') . '/', self::browser()))) {
         $code = self::browser();
     } else {
         $code = Kennel::getSetting('i18n', 'default');
     }
     if ($long_title) {
         return self::$LANGS[$code];
     } else {
         return $code;
     }
 }
Пример #5
0
 static function connect($host = null, $user = null, $pass = null, $database = null)
 {
     if (self::$CONN && @mysql_ping(self::$CONN)) {
         return;
     }
     self::$host = Kennel::getSetting('database', 'host');
     self::$user = Kennel::getSetting('database', 'user');
     self::$pass = Kennel::getSetting('database', 'pass');
     self::$database = Kennel::getSetting('database', 'database');
     self::$CONN = mysql_connect($host ? $host : self::$host, $user ? $user : self::$user, $pass ? $pass : self::$pass);
     if (function_exists('mysql_set_charset')) {
         mysql_set_charset('utf-8', self::$CONN);
     }
     mysql_select_db($database ? $database : self::$database, self::$CONN);
 }
Пример #6
0
 function __construct($model_name)
 {
     if (!$model_name) {
         debug::error("Schema::__construct - undefined model name.");
     }
     $path = Kennel::cascade($model_name, 'schemas');
     if (!$path) {
         debug::error("Schema::__construct - model schema for \"{$model_name}\" not found.");
     }
     $doc = new DOMDocument();
     $doc->load(realpath($path));
     $root = $doc->getElementsByTagName('model')->item(0);
     if (Kennel::getSetting('database', 'prefix')) {
         $this->table = Kennel::getSetting('database', 'prefix') . '_' . $root->getAttribute('table');
     } else {
         $this->table = $root->getAttribute('table');
     }
     $fields = $doc->getElementsByTagName('field');
     foreach ($fields as $field) {
         $this->fields[] = new Field($this->table, $field);
     }
 }
Пример #7
0
 private function getModels()
 {
     $models = array();
     // User Models
     $dir = Kennel::getPath() . '/application/models/';
     if (is_dir($dir)) {
         foreach (scandir($dir) as $filename) {
             $path_info = pathinfo($filename);
             if ($path_info['extension'] && $path_info['extension'] == 'xml') {
                 $models[] = array('dir' => $dir, 'info' => $path_info, 'source' => 'application');
             }
         }
     }
     // Module Models
     foreach (Kennel::$MODULES as $module) {
         $dir = Kennel::getPath() . "/modules/{$module['id']}/models/";
         if (is_dir($dir)) {
             foreach (scandir($dir) as $filename) {
                 $path_info = pathinfo($filename);
                 if (isset($path_info['extension']) && $path_info['extension'] == 'xml') {
                     $models[] = array('dir' => $dir, 'info' => $path_info, 'source' => $module['id']);
                 }
             }
         }
     }
     // System Models
     $dir = Kennel::getPath() . "/system/models/";
     if (is_dir($dir)) {
         foreach (scandir($dir) as $filename) {
             $path_info = pathinfo($filename);
             if ($path_info['extension'] && $path_info['extension'] == 'xml') {
                 $models[] = array('dir' => $dir, 'info' => $path_info, 'source' => 'system');
             }
         }
     }
     self::$DB = new MySQL();
     $rs = self::$DB->query("SHOW TABLES");
     $tables = array();
     while ($row = self::$DB->fetch_array($rs)) {
         $tables[] = $row[0];
     }
     foreach ($models as $id => $model) {
         //self::checkModel($model['info']['filename']);
         // FILENAME was only introduced in PHP 5.2 and Terra Empresas is gay
         $filename = substr($model['info']['basename'], 0, strpos($model['info']['basename'], '.xml'));
         $schema = ORM::getSchema($filename);
         $result = array_search($schema->table, $tables);
         if ($result !== FALSE) {
             $models[$id]['status'] = 'ok';
         } else {
             $models[$id]['status'] = '';
         }
     }
     return $models;
 }
Пример #8
0
<?php

error_reporting(E_ALL);
require_once 'system/core/Core.php';
// Example request hook:
/*
require_once('system/helpers/debug.php');
require_once('system/core/Request.php');

Request::hook(function($args) {
	if (count($args) > 0 && in_array($args[0], array('ksetup', 'cms'))) return $args;
	
	$cinema = array_shift($args);
	
	if (!cine::set($cinema))
	{
		Kennel::controllerAction('main', 'pick');
		exit();
	}
		
	return $args;
});
*/
Kennel::init();
Пример #9
0
 function getTitle()
 {
     if ($this->title && Kennel::getSetting('application', 'title')) {
         return $this->title . " {$this->titleSeparator} " . Kennel::getSetting('application', 'title');
     } elseif (!$this->title && Kennel::getSetting('application', 'title')) {
         return Kennel::getSetting('application', 'title');
     } elseif ($this->title && !Kennel::getSetting('application', 'title')) {
         return $this->title;
     } else {
         return 'Untitled';
     }
 }
Пример #10
0
 /**
  * @param Model $user
  * @param string $realm
  */
 static function updateUser($user, $realm = 'admin')
 {
     if (!session_id()) {
         session_start();
     }
     $app_id = Kennel::getSetting('application', 'id');
     $_SESSION["{$app_id}-{$realm}"] = $user->toArray();
     self::$user[$realm] = $user;
 }
Пример #11
0
 static function error($errstr, $backtrace_level = 0)
 {
     // Skip if settings are not found
     if (Kennel::getSetting('application', 'debug_mode')) {
         self::dumpError($errstr, $backtrace_level);
     }
 }
Пример #12
0
 static function fetchModules()
 {
     // Initialize the variable
     self::$MODULES = array();
     // Skip if the modules folder do not exist
     if (!file_exists(self::getPath('modules'))) {
         return null;
     }
     // Get through the file list in the modules directory
     $files = scandir(self::getPath('modules'));
     foreach ($files as $file) {
         // Get only valid directories
         if (is_dir(Kennel::getPath('modules') . '/' . $file) && $file != '.' && $file != '..' && $file != '.svn') {
             if (is_file(Kennel::getPath('modules') . "/{$file}/info.php")) {
                 if (isset($info)) {
                     unset($info);
                 }
                 include Kennel::getPath('modules') . "/{$file}/info.php";
                 self::$MODULES[$file] = $info;
             }
         }
     }
 }
Пример #13
0
 /**
  *  Static methods 
  */
 static function getInstance($model_name)
 {
     $path = Kennel::cascade($model_name, 'models');
     if ($path) {
         $class = ucfirst($model_name) . '_model';
         $instance = new $class();
     } else {
         $class = 'Model';
         $instance = new $class($model_name);
     }
     return $instance;
 }
Пример #14
0
 static function process()
 {
     // Set the method
     self::$METHOD = $_SERVER['REQUEST_METHOD'];
     // Get the request parts
     $request_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     if (Kennel::getSetting('application', 'use_mod_rewrite')) {
         $action_string = substr(trim($request_url, '/'), strlen(Kennel::$ROOT_URL));
     } else {
         $action_string = substr(trim($request_url, '/'), strlen(Kennel::$ROOT_URL . '/index.php'));
     }
     $action_string = str_replace(strstr($action_string, '?'), '', $action_string);
     $action_array = array_filter(explode('/', $action_string));
     // Reasign action keys (to avoid empty entries due to double slashes) and convert to lowercase
     foreach ($action_array as $key => $part) {
         if ($part) {
             if (strpos($part, ':') === false) {
                 self::$PARTS[] = input::clean($part);
             } else {
                 $named_arg = explode(':', $part);
                 self::$NAMED_ARGS[$named_arg[0]] = $named_arg[1];
             }
         }
     }
     // Process any hooks if present
     if (is_array(self::$HOOKS) && count(self::$HOOKS > 0)) {
         foreach (self::$HOOKS as $hook) {
             self::$PARTS = call_user_func($hook, self::$PARTS);
         }
     }
     // Make the Resource String available to the API
     self::$RESOURCE = implode('/', self::$PARTS);
     // i18n URL redirection
     if (Kennel::getSetting('i18n', 'enabled') && Kennel::getSetting('i18n', 'redirect') && !router::$PREFIX) {
         header('location: ' . url(Request::$RESOURCE, i18n::getLang()));
     }
     // 0. Render the Home Page if no Request::PARTS are present
     if (count(self::$PARTS) == 0) {
         self::$CONTROLLER = 'Main';
         self::$ACTION = 'index';
     }
     // 1. First check: method in the main controller
     if (isset(self::$PARTS[0]) && method_exists('Main_controller', str_replace('-', '_', self::$PARTS[0]))) {
         self::$CONTROLLER = 'main';
         self::$ACTION = str_replace('-', '_', self::$PARTS[0]);
         self::$ARGS = array_slice(self::$PARTS, 1);
     }
     // 2. Second check: user defined controller...
     if (isset(self::$PARTS[0]) && is_file(Kennel::$ROOT_PATH . '/application/controllers/' . str_replace('-', '_', self::$PARTS[0]) . '.php')) {
         self::$CONTROLLER = ucfirst(str_replace('-', '_', self::$PARTS[0]));
         if (isset(self::$PARTS[1]) && method_exists(self::$CONTROLLER . '_controller', str_replace('-', '_', self::$PARTS[1]))) {
             self::$ACTION = str_replace('-', '_', self::$PARTS[1]);
             self::$ARGS = array_slice(self::$PARTS, 2);
         } else {
             self::$ACTION = 'index';
             self::$ARGS = array_slice(self::$PARTS, 1);
         }
     }
     // 3. Third check: module controller
     if (isset(self::$PARTS[0])) {
         if (!Kennel::$MODULES) {
             Kennel::fetchModules();
         }
         foreach (Kennel::$MODULES as $module => $info) {
             if (is_file(Kennel::$ROOT_PATH . "/modules/{$module}/controllers/" . str_replace('-', '_', self::$PARTS[0]) . '.php')) {
                 self::$CONTROLLER = ucfirst(str_replace('-', '_', self::$PARTS[0]));
                 if (isset(self::$PARTS[1]) && method_exists(self::$CONTROLLER . '_controller', str_replace('-', '_', self::$PARTS[1]))) {
                     self::$ACTION = str_replace('-', '_', self::$PARTS[1]);
                     self::$ARGS = array_slice(self::$PARTS, 2);
                 } else {
                     self::$ACTION = 'index';
                     self::$ARGS = array_slice(self::$PARTS, 1);
                 }
             }
         }
     }
     // 4. Forth check: system controller
     if (isset(self::$PARTS[0]) && is_file(Kennel::$ROOT_PATH . '/system/controllers/' . str_replace('-', '_', self::$PARTS[0]) . '.php')) {
         self::$CONTROLLER = ucfirst(str_replace('-', '_', self::$PARTS[0]));
         if (isset(self::$PARTS[1])) {
             if (method_exists(self::$CONTROLLER . '_controller', str_replace('-', '_', self::$PARTS[1]))) {
                 self::$ACTION = str_replace('-', '_', self::$PARTS[1]);
                 self::$ARGS = array_slice(self::$PARTS, 2);
             }
         } else {
             self::$ACTION = 'index';
             self::$ARGS = array_slice(self::$PARTS, 1);
         }
     }
     // 5. Fifth check: nothing found
     if (!self::$CONTROLLER) {
         self::$CONTROLLER = 'Main';
     }
     if (!self::$ACTION) {
         self::$ACTION = 'notfound';
     }
     if (self::$CONTROLLER == 'Main' && self::$ACTION == 'notfound') {
         self::$ARGS = self::$PARTS;
     }
     return Kennel::controllerAction(self::$CONTROLLER, self::$ACTION, self::$ARGS);
 }