public function __call($method, $args) { $id = md5($method . serialize($args) . serialize(get_object_vars($this->object))); if (($value = $this->backend->get($id)) === null) { $value = call_user_func_array(array($this->object, $method), $args); $this->backend->add($id, $value); } return $value; }
public function html_list($document) { Backend::add('Sub Title', $document->getMeta('name')); Backend::add('TabLinks', $this->getTabLinks(Controller::$action)); Backend::add('Object', $document); Backend::addContent(Render::renderFile('document_list.tpl.php')); }
function main() { $start = microtime(true); require BACKEND_FOLDER . '/classes/Backend.obj.php'; Backend::init(); Backend::add('start', $start); Controller::serve(); }
public function html_display($content) { Backend::add('Sub Title', 'Revisions for ' . $content->array['name']); Backend::add('content', $content); Backend::add('revisions', $content->object->revisions); Backend::addContent(Render::renderFile('content_revision.display.tpl.php')); return true; }
function html_index($result) { if (Render::checkTemplateFile('home.index.tpl.php')) { Backend::addContent(Render::file('home.index.tpl.php')); } else { Backend::add('Sub Title', 'Welcome'); Backend::addContent('<h3>Welcome to #Title#</h3><p>The code for this URL is in the Home Controller</p>'); } return true; }
function get_list($start, $count, array $options = array()) { $Assignments = new AssignmentObj(); if ($start === 'all') { $limit = 'all'; } else { $limit = "{$start}, {$count}"; } $conditions = array('`assignments`.`active` = 1'); $joins = array(array('type' => 'LEFT', 'table' => '`roles`', 'conditions' => array('`roles`.`id` = `assignments`.`role_id`', '`roles`.`active` = 1'))); $fields = array('`assignments`.*', '`roles`.`name` AS `role`'); list($query, $params) = $Assignments->getSelectSQL(array('conditions' => $conditions, 'joins' => $joins, 'fields' => $fields, 'limit' => $limit)); $Assignments->read(array('query' => $query, 'parameters' => $params)); Backend::add('Assignments', $Assignments); Backend::addContent(Render::renderFile('assignment_list.tpl.php')); }
public function get_list($start, $count, array $options = array()) { $toret = false; Backend::add('Sub Title', 'List'); $obj_name = class_name(Controller::$area) . 'Obj'; if (class_exists($obj_name, true)) { $object = new $obj_name(); if ($start === 'all') { $object->read(array()); } else { $object->read(array('limit' => "{$start}, {$count}")); } $toret = $object; } else { Controller::whoops(); } return $toret; }
<?php require_once dirname(__FILE__) . '/../Backend.class.php'; $be = new Backend(); print_r($be->add('test', __DIR__ . '/scripts/test.php', array('writelog' => TRUE))); print_r($be->update('test', array('guard' => TRUE))); print_r($be->start('test')); // 在系统中 kill 该进程,过1分钟后查看到进程自动恢复
public function html_search($result) { foreach ($result as $name => $value) { Backend::add($name, $value); } Backend::addContent(Render::file('backend_search.tpl.php')); }
public function html_define($values) { if ($values) { if ($values['function']) { Backend::add('Sub Title', $values['class'] . '::' . $values['function']); Backend::addContent(Render::renderFile('api_function.tpl.php', $values)); } else { Backend::add('Sub Title', $values['class']); Backend::addContent(Render::renderFile('api_class.tpl.php', $values)); } } return true; }
public function whoops($title, $message, $code_hint = false) { Backend::add('Sub Title', $title); Backend::addContent('<ht>' . $message . '<hr>'); parent::whoops($title, $message, $code_hint); }
/** * {@inheritDoc} */ public function add($id, $value, $ttl = null) { $id = $this->id($id); $ttl = $this->computeTTL($ttl); return $this->backend->add($id, $value, $ttl); }
/** * This function adds all styles and scripts to the HTML. It also retrieves primary and secondary links from the App * */ public static function hook_post_display($data, $controller) { Backend::add('Styles', array_unique(array_filter(Backend::getStyles()))); Backend::add('Scripts', array_unique(array_filter(Backend::getScripts()))); return $data; }
public static function hook_start() { $user = self::check(); if ($user && in_array('superadmin', $user->roles) && !Backend::getConfig('application.NoSuperWarning')) { Backend::addInfo('You are the super user. Be carefull, careless clicking costs lives...'); } self::$current_user = $user; Backend::add('BackendUser', $user); }
public function html_import($result) { switch (true) { case $result instanceof DBObject: if (!Backend::get('Sub Title')) { Backend::add('Sub Title', 'Import'); Backend::add('Sub Title', 'Import ' . $result->getMeta('name')); } $template_file = array($result->getArea() . '.import.tpl.php', $result->getArea() . '/import.tpl.php'); if (!Render::checkTemplateFile($template_file[0]) && !Render::checkTemplateFile($template_file[1])) { $template_file = 'std_import.tpl.php'; } Backend::addContent(Render::file($template_file, array('db_object' => $result))); break; case is_numeric($result) && $result >= 0: Backend::addSuccess($result . ' records imported'); Controller::redirect('?q=' . Controller::$area . '/list'); break; default: Controller::redirect(); break; } return $result; }
$data = $_SERVER['argv'][4]; $mode = array_key_exists(5, $_SERVER['argv']) ? $_SERVER['argv'][5] : $mode; } else { $mode = $_SERVER['argv'][3]; $data = array_key_exists(5, $_SERVER['argv']) ? $_SERVER['argv'][5] : $data; } } if ($data) { parse_str($data, $data); } if ($mode == 'html') { $mode = 'chunk'; } //Build the complete path $path = 'q=' . $path; if ($method == 'get' && is_array($data)) { $path .= '&' . urldecode(http_build_query($data)); } $path .= '&mode=' . $mode; if (DEBUG > 1) { $path .= '&debug=' . (DEBUG - 1); } if (DEBUG) { echo 'Path: ' . $path . PHP_EOL; } //Execute the query $start = microtime(true); include BACKEND_FOLDER . '/classes/Backend.obj.php'; \Backend::add('start', $start); \Controller::serve($path, $method, $data, false); echo PHP_EOL;
public function html_permissions($result) { if (is_post()) { if ($result === false) { Backend::addError('Could not update Permissions'); } else { Backend::addSuccess($result . ' Permissions Updated'); } Controller::redirect('previous'); } //GET if (!empty(Controller::$parameters[0])) { Backend::add('Sub Title', class_name(Controller::$parameters[0]) . ' Permissions'); Links::add('All Permissions', '?q=gate_manager/permissions', 'secondary'); } else { Backend::add('Sub Title', ConfigValue::get('Title') . ' Permissions'); } Backend::addContent(Render::renderFile('gate_manager.permissions.tpl.php', (array) $result)); }
<?php require_once dirname(__FILE__) . '/../Backend.class.php'; $be = new Backend(); print_r($be->add('test', __DIR__ . '/scripts/test.php')); print_r($be->update('test', array('autostart' => TRUE))); /* restart your server and you will see the result below Array ( [code] => OK [data] => UP ) */ print_r($be->status('test'));
function html_manage($result) { Backend::add('Sub Title', 'Manage Components'); Backend::add('result', $result); Links::add('Admin', '?q=admin/index', 'secondary'); Backend::addScript(SITE_LINK . 'js/jquery.js'); Backend::addScript(SITE_LINK . 'js/component.manage.js'); Backend::addContent(Render::file('component.manage.tpl.php')); }
public static function init(array $options = array()) { if (ob_get_level() === 0) { ob_start('ob_gzhandler'); } self::$initialized = true; self::$options = $options; if (!defined('SITE_STATE')) { define('SITE_STATE', 'production'); } if (defined('SITE_FOLDER') && !defined('APP_FOLDER')) { define('APP_FOLDER', SITE_FOLDER); } if (defined('APP_FOLDER') && !defined('SITE_FOLDER')) { define('SITE_FOLDER', APP_FOLDER); } if (file_exists(APP_FOLDER . '/constants.inc.php')) { include_once APP_FOLDER . '/constants.inc.php'; } if (defined('SITE_FOLDER') && file_exists(SITE_FOLDER . '/constants.inc.php')) { include_once SITE_FOLDER . '/constants.inc.php'; } if (file_exists(APP_FOLDER . '/functions.inc.php')) { include_once APP_FOLDER . '/functions.inc.php'; } if (defined('SITE_FOLDER') && file_exists(SITE_FOLDER . '/functions.inc.php')) { include_once SITE_FOLDER . '/functions.inc.php'; } if (file_exists(APP_FOLDER . '/modifiers.inc.php')) { include_once APP_FOLDER . '/modifiers.inc.php'; } if (defined('SITE_FOLDER') && file_exists(SITE_FOLDER . '/modifiers.inc.php')) { include_once SITE_FOLDER . '/modifiers.inc.php'; } require BACKEND_FOLDER . '/constants.inc.php'; require BACKEND_FOLDER . '/functions.inc.php'; require BACKEND_FOLDER . '/modifiers.inc.php'; self::requireFile('classes', 'Controller'); self::requireFile('utilities', 'BackendConfig'); self::requireFile('classes', 'AreaCtl'); self::requireFile('classes', 'TableCtl'); self::requireFile('controllers', 'Component'); self::requireFile('controllers', 'Value'); self::requireFile('controllers', 'ConfigValue'); self::requireFile('classes', 'View'); self::requireFile('utilities', 'Request'); self::requireFile('utilities', 'Parser'); //TODO Maybe add a config value to decide if this should be included... include BACKEND_FOLDER . '/libraries/Markdown/markdown.php'; spl_autoload_register(array('Backend', '__autoload')); set_error_handler(array('Backend', '__error_handler')); set_exception_handler(array('Backend', '__exception_handler')); register_shutdown_function(array('Controller', 'finish')); //Configs self::initConfigs(); //Some constants $url = parse_url(get_current_url()); $folder = !empty($url['path']) ? $url['path'] : '/'; if (substr($folder, -1) != '/' && substr($folder, -1) != '\\') { $folder = dirname($folder); } if ($folder != '.') { if (substr($folder, strlen($folder) - 1) != '/') { $folder .= '/'; } define('WEB_SUB_FOLDER', $folder); } else { define('WEB_SUB_FOLDER', '/'); } Backend::add('WEB_SUB_FOLDER', WEB_SUB_FOLDER); $domain = !empty($url['host']) ? $url['host'] : 'localhost'; define('SITE_DOMAIN', $domain); Backend::add('SITE_DOMAIN', SITE_DOMAIN); $scheme = !empty($_SERVER['HTTPS']) ? 'https://' : 'http://'; $url = SITE_DOMAIN . WEB_SUB_FOLDER; define('SITE_LINK', $scheme . $url); Backend::add('SITE_LINK', SITE_LINK); //Application Values $values = self::$config->getValue('application'); if (is_array($values)) { foreach ($values as $name => $value) { self::add($name, $value); } } //Init DBs $with_database = self::initDBs(); //Check if we can connect to the default DB if ($with_database) { try { $def = self::getDB(); } catch (Exception $e) { $with_database = false; } } define('BACKEND_WITH_DATABASE', $with_database); }
public function html_display() { Backend::add('Sub Title', 'Administer this Website'); }
function html_index($result) { Backend::add('Sub Title', 'Manage Application'); Backend::add('result', $result); $admin_links = array(); $components = Component::getActive(); foreach ($components as $component) { if (method_exists($component['name'], 'adminLinks')) { $links = call_user_func(array($component['name'], 'adminLinks')); if (is_array($links) && count($links)) { $admin_links[$component['name']] = $links; } } } Backend::add('admin_links', $admin_links); Backend::addContent(Render::file('admin.index.tpl.php')); }
function html_index() { Backend::add('Sub Title', 'Links'); return true; }
public static function hook_table_update($data, $object) { $tags = self::getTagNames($object); Backend::add('tags', $tags); return $data; }
public static function action() { if (self::$whoopsed) { return array(null, null); } $control_name = class_name(self::$area); if (Controller::$debug) { Backend::addNotice('Trying Controller ' . $control_name); } $controller = class_exists($control_name, true) ? new $control_name() : false; if (!($controller instanceof AreaCtl && Component::isActive($control_name))) { if (Backend::getDB('default')) { //We have a DB Controller::whoops('Component ' . $control_name . ' is Inactive or Invalid', array('message' => 'The requested component doesn\'t exist or is inactive.', 'code_hint' => 404)); self::$area = ConfigValue::get('DefaultErrorController', 'home'); self::$action = ConfigValue::get('DefaultErrorAction', 'error'); $control_name = class_name(self::$area); } else { //No DB, allow Content to check if the template exists self::$parameters[0] = self::$area . '/' . self::$action; if (count(self::$parameters[0]) > 1) { self::$parameters = array(self::$parameters[0]); } self::$area = ConfigValue::get('DefaultErrorController', 'content'); self::$action = ConfigValue::get('DefaultErrorAction', 'display'); $control_name = class_name(self::$area); } } $controller = class_exists($control_name, true) ? new $control_name() : false; if (!($controller instanceof AreaCtl && Component::isActive($control_name))) { Controller::whoops('Invalid Error Area Controller', 'The DefaultErrorController is invalid or inactive.'); return null; } Backend::add('Area', self::$area); Backend::add('Action', self::$action); if (Controller::$debug) { Backend::addNotice('Code for this page is in the ' . get_class($controller) . ' Controller'); } $result = null; $run_action = Hook::run('action', 'pre', array(), array('toret' => true)); if ($run_action) { $result = $controller->action(); } Hook::run('action', 'post'); return array($controller, $result); }