public function __construct() { $registry = registry::getInstance(); $path = empty($_SERVER['REQUEST_URI']) || $_SERVER['REQUEST_URI'] == "/" ? $registry->config['default_controller'] : ltrim(strtolower($_SERVER['REQUEST_URI']), "/"); if (strstr($path, "/")) { $arr = explode('/', $path); $page = $arr[0]; $action = empty($arr[1]) ? 'index' : $arr[1]; } else { $page = $path; $action = "index"; } $file = 'application/controllers/controller.' . $page . '.php'; if (file_exists($file)) { $class = strtolower($page); if (class_exists($class)) { $controller = new $class(); if (!is_callable(array($controller, $action))) { $this->handle404(); } else { $controller->{$action}(); } } else { $this->handle404(); } } else { $this->handle404(); } }
public function __construct() { parent::__construct(); $this->registry = registry::getInstance(); $this->html = html::getInstance(); $this->plugin = plugin::getInstance(); }
function __construct() { parent::__construct(); $this->registry = registry::getInstance(); $this->addAction('index_init', 'init'); $this->addAction('index_load', 'addToolbar'); }
/** * @author Damien Lasserre <*****@*****.**> * @param $_config_file */ public function __construct($_config_file) { /** @var string $log_path */ $log_path = APPLICATION_PATH . '/tmp/application.log'; if (file_exists($_config_file)) { /** @var array $_attributes */ $_attributes = parse_ini_file($_config_file, true); /** @var definition\config[] $_config */ $_config = new \stdClass(); foreach ($_attributes as $_env => $_parameters) { if ($_env == APPLICATION_ENV) { foreach ($_parameters as $_parameter => $value) { /** @var definition\config _parameter */ $_config->{$_parameter} = new definition\config(); $_config->{$_parameter}->_setName($_parameter)->_setValue($value)->_activate(); } } } if (isset($_config->log_path) and $_config->log_path->isActivated()) { $log_path = $_config->log_path; } if (is_file($log_path)) { defined('APPLICATION_PATH_LOG') || define('APPLICATION_PATH_LOG', $log_path); } $this->_configuration = $_config; /** Set in registry */ registry::getInstance()->add('config', $this); } }
/** * executes all controllers and compile the final HTML Document. * * @return string finalHTML */ public function execute() { if (HANDHELD) { header('Pragma: public'); header("Expires: " . gmdate("Y-m-d\\TH:i:s\\Z", time() + 60 * 30)); header('Cache-Control: no-store, must-revalidate, post-check=0, pre-check=0, no-transform, max-age=1800'); } foreach ($this->mountPoints as $column => $controllers) { ${$column} = ""; foreach ($controllers as $c) { ${$column} .= $c->execute(); } } $pageTitle = $this->title; $pageDescription = $this->description; $bodyClass = $this->bodyClass; foreach (registry::getInstance() as $k => $v) { ${$k} = $v; } isset($contentType) ? http_response::content($contentType) : http_response::content(CONTENT_TYPE); ob_start(); require $this->file; // output is gzipped and minified (NO; PROBLEMS WITH CODE BLOCKS!). // ob_postprocess(trim(preg_replace('/\s+/', ' ', ob_get_clean()))); echo ob_get_clean(); }
public function __construct($mountPoints = false) { $this->file = VIEW . '/layout.phtml'; $reg =& registry::getInstance(); $mountPoints = $mountPoints !== false ? $mountPoints : $reg['columns']; foreach ($mountPoints as $wrap) { $this->mountPoints[$wrap] = array(); } }
static function getModels() { // registry preparation $registry = registry::getInstance(); // validate input $modelId = http_request::getString('model'); $entityId = http_request::getString('entityId'); // get all models $registry['models'] = new model_dir(ROOT . '/model'); }
public function __construct() { $this->registry = registry::getInstance(); $this->path = $this->registry["path"]; $this->html = html::getInstance(); $this->session = $this->registry["session"]; $this->cookie = $this->registry["cookie"]; $this->ajax = new ajax(); $this->l10n = l10n::getInstance(); }
function __construct() { parent::__construct(); $this->registry = registry::getInstance(); if (!defined('GESHI_VERSION')) { require_once Absolute_Path . "app/plugins/geshi/GeSHi.php"; } $this->addAction('index_post_content', 'source_code_beautifier'); $this->addAction('admin_comments_content', 'comment_source_code_beautifier'); $this->addAction('index_comment_content', 'comment_source_code_beautifier'); }
/** * @author Damien Lasserre <*****@*****.**> * @param string $_path * @param null $_session_id * @return bool|void * @throws \Exception */ public function open($_path, $_session_id = null) { /** @var array $_config */ $_config = registry::getInstance()->get('config'); if (extension_loaded('memcached')) { $memcached = new \Memcached(); $memcached->addServer($_config['memcached_host'], $_config['memcached_port']); $this->_memcached = $memcached; } else { throw new \Exception('Memcached was not installed, please install'); } }
public static function find($arr, $fields = null) { $class = get_called_class(); $registry = registry::getInstance(); $registry->db->select(is_array($fields) && count($fields) > 0 ? implode(",", $fields) : '*')->from($class)->where($arr); $rows = $registry->db->fetch(); $count = count($rows); if ($count) { return $count == 1 ? $rows[0] : $rows; } else { return false; } }
function __construct($alias, $values = NULL) { if ($alias) { $this->registry = registry::getInstance(); $db = $this->registry->get('db'); $rs = $db->query("SELECT * FROM `email_template` WHERE `alias`=" . $db->escape($alias)) or die(__METHOD__ . ': ' . $db->lastError); if ($sa = $db->fetch($rs)) { $this->loadDataFromArray($sa); } $this->attachments = EmailTemplateAttachment::getList($this->id); $this->embedded = EmailTemplateEmbedded::getList($this->id); } }
/** * @author Damien Lasserre <*****@*****.**> * @param null $_adapter * @return cache * * @description simple singleton */ public static function getInstance($_adapter = null) { if (null === $_adapter) { /** @var array $_config */ $_config = registry::getInstance()->get('config'); /** @var string $_adapter */ $_adapter = $_config['cache_adapter']; } if (!is_array(self::$_instance) or array_key_exists($_adapter, self::$_instance)) { self::$_instance[$_adapter] = new cache($_adapter); } /** Return */ return self::$_instance[$_adapter]; }
function getList($templateId) { $this->templateId = intval($templateId); $result = []; if ($this->templateId) { $this->registry = registry::getInstance(); $db = $this->registry->get(static::DB); $rs = $db->query("SELECT * FROM `" . static::TABLE . "` WHERE `email_template_id`=" . $this->templateId) or die(__METHOD__ . ': ' . $db->lastError); while ($sa = $db->fetch($rs)) { $item = new static(); $item->loadDataFromArray($sa); } } return $result; }
public function __construct() { parent::__construct(); $R = registry::getInstance(); $class = $R->router->getClass(); if ($class["action"] != "login" && $class["action"] != "logout") { if ($this->session->check("logged") == false) { $this->redirect("admin/login/nosession/"); } } $this->plugin->call('admin_init'); $C = new configuration(); $this->blogConfig = $C->getBlogConfiguration(); $this->userConf = $C->getUserConfiguration(1); $this->view->blogConfig = $this->blogConfig; $this->view->userConf = $this->userConf; }
public function __construct() { $this->registry = registry::getInstance(); $this->session = $this->registry["session"]; $this->cookie = $this->registry["cookie"]; $this->view = $this->registry["views"]; $this->themes = $this->registry["themes"]; $this->path = $this->registry["path"]; $this->l10n = l10n::getInstance(); $this->html = html::getInstance(); $this->ajax = new ajax(); $this->pagination = pagination::getInstance(); if ($_SERVER["REQUEST_METHOD"] == "POST") { $this->data = $_POST; } else { $this->data = NULL; } $this->isAjax = $this->isAjax(); }
/** * Compile the view * * @return $HTMLSource the compiled view */ public function compile() { $registry =& registry::getInstance(); $user =& user::getInstance(); foreach ($registry->fetchWhole() as $k => $v) { ${$k} = $v; } ob_start(); require $this->file; $body = ob_get_clean(); isset($contentType) ? http_response::content($contentType) : http_response::content(CONTENT_TYPE); if ($this->hasLayout) { ob_start(); require strchr($bodyid, 'admin') ? LAYOUT_ADMIN : LAYOUT; return ob_get_clean(); } else { return $body; } }
public function __construct() { $this->registry = registry::getInstance(); $this->validateErrors = $this->registry->validateErrors; $this->filterErrors = $this->registry->filterErrors; $this->db = $this->registry["db"]; $this->table = $this->modelName(); $rs = $this->db->query("SHOW COLUMNS FROM " . $this->table); while ($row = $this->db->fetchRow()) { $this->columns[$row["Field"]] = $row; $this->record[$row["Field"]] = ""; if ($row["Key"] === "PRI") { $this->keyField = $row["Field"]; } } if (empty($this->keyField)) { throw new Exception("Primary Column not found for Table: '" . $this->table . "'"); } }
/** * executes all controllers and compile the final HTML Document. * * @return string finalHTML */ public function execute() { foreach ($this->mountPoints as $column => $controllers) { ${$column} = ""; foreach ($controllers as $c) { ${$column} .= $c->execute(); } } $pageTitle = $this->title; $pageDescription = $this->description; $bodyClass = $this->bodyClass; foreach (registry::getInstance() as $k => $v) { ${$k} = $v; } ob_start(); require $this->file; // output is gzipped and minified (NO; PROBLEMS WITH CODE BLOCKS!). // ob_postprocess(trim(preg_replace('/\s+/', ' ', ob_get_clean()))); echo ob_postprocess(ob_get_clean()); }
/** * Compile the view * * @return $HTMLSource the compiled view */ public function compile($registry = false) { if ($registry === false) { $registry =& registry::getInstance(); } $user =& user::getInstance(); foreach ($registry as $k => $v) { ${$k} = $v; } ob_start(); require $this->file; $body = ob_get_clean(); isset($contentType) ? http_response::content($contentType) : http_response::content(CONTENT_TYPE); $isFragment = isset($this->isFragment); if (defined('LAYOUT') && !$isFragment) { ob_start(); require LAYOUT; $body = ob_get_clean(); } return $body; }
public function delegate() { $registry =& registry::getInstance(); $rule = ''; $defaultPage = $this->rules[0]; $loginPage = $this->rules[0]; if (!isset($_GET['c'])) { $rule = $defaultPage; } else { $rule = array_key_exists($_GET['c'], $this->rules) ? $this->rules[$_GET['c']] : $defaultPage; } $userOnline = $registry['user']->isOnline(); $requireUser = !in_array($_GET['c'], $this->validOffline); if ($requireUser && !$userOnline) { $rule = $loginPage; } if (substr($rule, 0, 6) != '/pages') { $action_path = ROOT . '/controller' . $rule . '.php'; if (!file_exists($action_path)) { throw new Exception('controller file ' . $action_path . ' missing!'); } $controller = new controller($action_path); } else { $action_path = ROOT . '/controller' . $rule . '.php'; if (!file_exists($action_path)) { throw new Exception('controller file missing!'); } $template_path = ROOT . '/view' . substr($rule, 6) . '.phtml'; if (!file_exists($template_path)) { throw new Exception('template file ' . $template_path . ' missing!'); } $view = new view($template_path); $controller = new controller($action_path, $view); } return $controller; }
<?php /** * do.login.php * * login script * @author Anders Ytterström <*****@*****.**> * @since 2007-08-13 */ require '../../../init.php'; $registry =& registry::getInstance(); $user =& user::getInstance(); $model = new model_photos(); $name = http_request::getString('id'); $alt = http_request::getString('alt'); $body = http_request::getString('body'); if (!$user->isOnline()) { http_response::redir('/login.php'); } if (!$alt || !$body) { form::setSF('editPhoto', array('alt' => $alt, 'body' => $body)); $_SESSION['msg'] = "badData"; http_response::redir('/admin/fotoalbum/redigera.php?id=' . $name); } $model->update($name, $alt, $body); form::clearSF('editPhoto'); $_SESSION['success'] = true; http_response::redir('/admin/fotoalbum/');
public function __construct() { $this->registry = registry::getInstance(); }
/** * parse the url and search for a matching rule. If match, return new controller object. If page, * add view object to controller. * * @return controller the resolved controller */ public function delegate($uri = false) { function removeEmpty($arr) { return !(strlen($arr) == 0); } $defaultPage = $this->rules[0]; $loginPage = $this->rules[1]; $registry =& registry::getInstance(); $user =& user::getInstance(); if ($uri == false) { $uri = parse_url(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/', PHP_URL_PATH); } $this->output = substr(strrchr($uri, '.'), 0); $this->task = explode('/', substr($uri, strpos($uri, '/'))); array_shift($this->task); $this->task = array_filter($this->task, 'removeEmpty'); // see if the uri pointt directly to a page $task = "/"; foreach ($this->task as $t) { $task .= $t . ' '; } $task = strtr(trim($task), ' ', '/'); $action_path = sprintf("%s/pages%s", CONTROLLER, $task); $template_path = sprintf("%s%s", VIEW, $task); $action_path .= is_dir($action_path) && file_exists($action_path . '/index.php') ? '/index.php' : '.php'; $template_path .= is_dir($template_path) && file_exists($template_path . '/index.phtml') ? '/index.phtml' : '.phtml'; if (is_file($action_path) || is_file($template_path)) { $requireUser = in_array($task, $this->closed); $userOnline = $user->isOnline(); if ($requireUser && !$userOnline) { http_response::redir('/login'); die; } $view = new view($template_path); $controller = file_exists($action_path) ? $action_path : false; return new controller($controller, $view); } // no easy way, search rules $rule = array(); foreach ($this->rules as $r) { if ($this->findRule($r)) { $rule += $r; } } if (count($rule) == 0) { throw new Exception('no request match'); } $requireUser = in_array($rule[0], $this->closed); $userOnline = $user->isOnline(); if ($requireUser && !$userOnline) { $rule = $loginPage; } foreach ($rule[2] as $k => $v) { $_GET[$v] = $_REQUEST[$v] = $this->task[$k]; } if ($this->output == '.do') { $action_path = sprintf('%s/%s/%s.php', CONTROLLER, isset($noscript) ? 'pages' : 'scripts', $rule[0]); if (!file_exists($action_path)) { throw new Exception(sprintf('controller file <em>%s</em> missing!', $action_path)); } $controller = new controller($action_path); } else { $action_path = CONTROLLER . '/pages' . $rule[0] . '.php'; if (!file_exists($action_path)) { $action_path = false; } $template_path = VIEW . $rule[0] . '.phtml'; if (!file_exists($template_path)) { throw new Exception('template file ' . $template_path . ' missing!'); } $view = new view($template_path); $controller = new controller($action_path, $view); } return $controller; }
public function __construct() { $this->registry = registry::getInstance(); $this->registry->plugins = $this->plugins; $this->init_plugins(); }
/** * parse the url and search for a matching rule. If match, return new controller object. If page, * add view object to controller. * * @return controller the resolved controller */ public function delegate($uri = false) { $reg = registry::getInstance(); $routes = $this->getSummary(); $isCrud = "/\\.do\$/"; // makes it possible to have the boot strap not in root, // ex http://site.com/project1/lolcat // found at http://www.phpaddiction.com/tags/axial/url-routing-with-php-part-one/ $requestURI = explode('/', $_SERVER['REQUEST_URI']); $scriptName = explode('/', $_SERVER['SCRIPT_NAME']); for ($i = 0, $max = count($scriptName); $i < $max; $i++) { if ($requestURI[$i] == $scriptName[$i]) { unset($requestURI[$i]); } } $path = '/' . join('/', $requestURI); // login halts further execution. if ($path === '/login.do') { require LIBRARY . '/auth/login.php'; die; } if ($path === '/logout.do') { require LIBRARY . '/auth/logout.php'; die; } $action = preg_match($isCrud, $path) ? 'crud' : 'page'; $delegated = false; foreach ($routes as $route) { $matchCorrect = preg_match_all($route['pattern'], $path, $matches); $containsVars = false; $vars = explode(',', $route['args']); foreach ($vars as $v) { if (strlen($v) > 0 && !strpos($v, '=')) { $containVars = true; } } if ($containsVars) { // there is variables in the uri, check them $vars = explode(',', $route['args']); if (is_array($vars) && strlen($vars[0]) == 0) { unset($vars[0]); } $varsCorrect = count($matches) - 1 === count($vars); } else { // no vars in the uri, sign it ok $varsCorrect = true; } if ($matchCorrect != 0 && $varsCorrect) { for ($r = 0, $maxR = count($vars); $r < $maxR; $r++) { if ($vars[$r] != '') { if (strpos($vars[$r], '=')) { // fördefinierad, uri skippas $kv = explode('=', $vars[$r]); $_GET[$kv[0]] = $_REQUEST[$kv[0]] = $kv[1]; } else { // från uri $_GET[$vars[$r]] = $_REQUEST[$vars[$r]] = $matches[$r + 1][0]; } } } $controllers = $this->getEntity($route['id']); $reg['route'] = new page(); foreach ($controllers as $controller) { $reg['route']->addContent($controller['mpId'], new controller_page($controller['service'], $controller['action'])); } $reg['route']->execute(); $delegated = true; break; } } if ($delegated == false) { // try to resolve anonymous controller /* todo: här ska applikationen försöka hitta en ensam page controller. */ try { if ($action == 'crud') { preg_match("/^(.+?)\\/(.+?)\\.do\$/", $path, $matches); $service = $matches[1]; $controller = $matches[2]; $controller = new controller_crud($service, $controller); $controller->execute(); } else { http_response::redir('/'); } } catch (Exception $e) { throw $e; } } }
public function __construct() { $this->registry = registry::getInstance(); $this->path = $this->registry["path"]; $this->l10n = l10n::getInstance(); }
/** * set custom theme, temporary in a session or stored in a cookie * * @param int $themeid * @param bool[optional] $remember * @return void */ public function setTheme($themeid, $remember = false) { $reg = registry::getInstance(); $themes = $reg['themes']; if (in_array($themeid, $themes)) { if ($remember) { setcookie('theme', $themeid, time() + 60 * 60 * 24 * 999, '/', '.madr.se', false, true); } else { setcookie('theme', '', time() - 4200, '/', '.madr.se'); } $this->theme = $_SESSION['theme'] = $themeid; } }
function logModelAction($id) { $user =& user::getInstance(); $registry =& registry::getInstance(); $data = sprintf("[%s] %s(%d)-%s:%s:%s", date('Y-m-d H:i:s', time()), $user->getName(), $user->getId(), $registry['modelLabel'], $registry['actionRoute'], $id); file_put_contents(LIBRARY . '/cms/log/model.log', $data, FILE_APPEND); }
private function __construct() { $registry = registry::getInstance(); $db = $registry->db; self::populateList($db); }