public function __construct() { Ac::on("AC_Module_on_create_i18n", function () { Ac::setConfig("available_languages", array("en", "es", "de", "it"), "i18n"); }); parent::__construct('app'); }
public function langFromBrowser() { $browser_langs = explode(",", Ac::request()->languages()); foreach ($browser_langs as $i => $lang) { if (in_array($lang, $this->config("available_languages"))) { return $lang; } } return $this->config("default_language", 'en'); }
public function __handle() { $this->meta_description = ""; $this->meta_keywords = ""; $this->meta_robots = "NOINDEX,NOFOLLOW"; $this->link_canonical = Ac::router()->directoryUrl(); if (Ac::response()->isSuccessful()) { Ac::response()->status(404); } $this->body(func_num_args() > 0 ? print_r(func_get_arg(0), true) : "<html><head></head><body><h1>" . Ac::response()->getStatusMessage() . "</h1></body></html>"); }
/** * Process a template and return its content * @param string $template Template filename * @param array $vars Variables passed to the template * @return string|false The template contents */ public static function process($template, array $vars = array()) { static::$level++; extract($vars, EXTR_OVERWRITE); ob_start(); try { include $template; $content = ob_get_contents(); ob_end_clean(); static::$level--; } catch (Exception $e) { Ac::log()->error($e->getMessage(), "Ac_View error " . $e->getCode(), $e->getFile(), $e->getLine()); $content = false; @ob_end_clean(); static::$level--; } return $content; }
<tr> <th>current module</th> <td><?php echo App::module()->name(); ?> </td> </tr> <tr> <th>loaded modules</th> <td><?php echo implode(", ", array_keys(Ac::loader()->getModules())); ?> </td> </tr> <?php $vars = Ac::router()->toArray(); foreach ($vars as $i => $v) { if ($i == "controllerInstance") { continue; } if ($i == "resource") { $v = '[' . implode(",", $v) . ']'; } if ($i == "params") { $v = '[' . implode(",", $v) . ']'; } ?> <tr> <th><?php echo $i; ?>
/** * * @param string $from Table name * @param string $where * @param string $limit * @return bool */ public function delete($from, $where = null, $limit = null) { list($_this, $from, $where, $limit) = Ac::trigger(__CLASS__ . "_before_" . __FUNCTION__, array($this, $from, $where, $limit)); if (!empty($where)) { $where = "WHERE ({$where})"; } if (!empty($limit)) { $limit = "LIMIT " . $limit; } $this->exec("DELETE FROM `{$from}` {$where} {$limit}"); $result = $this->lastRowCount > 0; Ac::trigger(__CLASS__ . "_on_" . __FUNCTION__, array($this, $from, $where, $limit, $result)); return $result; }
public static function tableName() { return Ac::db()->getConfig("prefix") . static::constant("TABLE_NAME"); }
protected function header($name = null, $value = null) { return Ac::response()->header($name, $value); }
public function setConfig($name, $value) { return Ac::setConfig($name, $value, $this->name); }
<link rel="shortcut icon" type="image/png" href="<?php echo Ac::url("assets"); ?> img/favicon.png?r=0" /> <link rel="stylesheet" href="<?php echo Ac::url("static"); ?> bootstrap/css/bootstrap.min.css" type="text/css" media="all" /> <link rel="stylesheet" href="<?php echo Ac::url("static"); ?> jqueryui/css/bootstrap/theme.css" type="text/css" media="all" /> <link rel="stylesheet" href="<?php echo Ac::url("static"); ?> anidcore/css/anidcore-inc.css" type="text/css" media="all" /> <link rel="stylesheet" href="<?php echo Ac::url("assets"); ?> css/styles-inc.css" type="text/css" media="all" /> <script type="text/javascript" src="<?php echo Ac::url("static"); ?> scripts-inc.js"></script> <script type="text/javascript" src="<?php echo Ac::url("assets"); ?> js/scripts-inc.js"></script>
/** * Clean all existing output buffers * @return string The resulting output buffer. */ public function cleanOb() { $ob = ""; while (ob_get_level() > 0) { $ob .= ob_get_clean(); } $ob = trim($ob); if (!empty($ob)) { Ac::log()->log($ob, "Output Buffer detected before send response", array("filename" => "output.log")); } return $ob; }
/** * Returns the Ac_Log instance or calls the Ac_Log::log() function if some parameter is passed * @param mixed $data * @param string $label * @param array $options * @return Ac_Log|void */ public static function log() { if (empty(self::$log)) { $log_class = self::config("log.class", "Ac_Log_File"); self::$log = new $log_class(); if (!self::$log instanceof Ac_Log) { self::exception("{$log_class} is not a valid Ac_Log instance"); } } if (func_num_args() > 0) { return call_user_func_array(array(self::$log, 'log'), func_get_args()); } return self::$log; }
public function call() { Ac::trigger(__CLASS__ . "_before_" . __FUNCTION__, $this); $klass = $this->controller; $fn = $this->action; $result = null; if ($fn == "__index") { $validate_fn = "validate_index"; } elseif ($fn == "__handle") { $validate_fn = "validate_handle"; } else { $validate_fn = str_replace("action_", "validate_", $this->action); } $this->controllerInstance = new $klass(); $is_valid = false; if (!is_callable(array($this->controllerInstance, $fn))) { $fn = "__handle"; } if (method_exists($klass, $validate_fn)) { if ($this->controllerInstance->{$validate_fn}($this->action)) { $is_valid = true; $result = $this->controllerInstance->{$fn}(); } else { $result = $this->controllerInstance->__handle(); } } else { if ($this->controllerInstance->__validate($this->action)) { $is_valid = true; $result = $this->controllerInstance->{$fn}(); } else { $result = $this->controllerInstance->__handle(); } } $result = Ac::trigger(__CLASS__ . "_on_" . __FUNCTION__, $result); return $result; }
<div class="hero-unit"> <h1>Error 404</h1> <p> Page not found </p> <p> <a class="btn btn-large" href="<?php echo Ac::url(); ?> "> « Back</a> </p> </div> <?php include "debug.php";
public function getConfig() { if (empty($this->config)) { $this->config = Ac::trigger("AcImportConfig", array_merge(array("modules.config" => array(), "modules.autoload" => array(), "http.default_format" => "html", "views.class" => "Ac_View", "router.default_controller" => "index", "router.on_index" => "error", "log.enabled" => true, "log.class" => "Ac_Log_File", "cache.enabled" => false, "cache.class" => "Ac_Storage_Cache_File", "cache.path" => AC_PATH_APP . "cache" . _DS, "key.names" => array(), "server.default_mimetype" => "text/html", "server.default_charset" => "UTF-8", "server.locale" => "en_US.UTF8", "server.timezone" => "UTC", "server.memory_limit" => "180M", "server.max_execution_time" => 60, "server.max_input_time" => -1, "server.post_max_size" => "24M", "server.upload_max_file_size" => "16M", "server.display_errors" => true, "server.error_reporting" => -1, "server.error_log_file" => AC_PATH_LOGS . 'php_errors.log', "session.sessid_lifetime" => 180, "session.cookie_path" => preg_replace('/\\/index\\.php.*/', '/', $_SERVER["SCRIPT_NAME"]), "session.cookie_secure" => isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on", "session.cookie_lifetime" => 0, "session.gc_maxlifetime" => 1440, "session.cache_expire" => 180, "session.cache_limiter" => "nocache"), include AC_PATH_APP . "config.php")); } return $this->config; }
/** * Constructor (protected access) * * @param array|null $context If present, these are used instead of global server variables * @return void */ protected function __construct(array $context = null) { if (!empty($context)) { $this->context = array_merge(self::$default_context, $context); } else { $con = array(); $_SERVER = array_merge(self::$default_server, $_SERVER); /** * In some HTTP servers DOCUMENT_ROOT points to a unaccessible directory or is not set */ $_SERVER['DOCUMENT_ROOT'] = substr($_SERVER['SCRIPT_FILENAME'], 0, -strlen($_SERVER['SCRIPT_NAME'])); /** * Server name, domain or hostname */ $con['host'] = $_SERVER['SERVER_NAME']; $con["host_id"] = ac_str_slug($con["host"], "_", array(".")); $con["host_url"] = ""; /** * Scheme and protocol version */ $protocol = explode('/', trim($_SERVER["SERVER_PROTOCOL"]), 2); $https = strtolower($_SERVER["HTTPS"]) == "on" ? true : false; $con["scheme"] = $https ? 'https' : strtolower($protocol[0]); $con["version"] = strtolower($protocol[1]); /** * Server port */ $con["port"] = $_SERVER['SERVER_PORT']; $con["host_url"] = $con["scheme"] . '://' . $con["host"] . ($con["port"] == 80 ? "" : ":" . $con["port"]) . "/"; /** * Request origin (sent by modern browsers in preflight Cross Domain requests) */ $con["origin"] = $_SERVER["HTTP_ORIGIN"]; /** * Request method (supports method overriding using X_REQUEST_METHOD in POST) */ $con['method'] = isset($_POST["X_REQUEST_METHOD"]) ? $_POST["X_REQUEST_METHOD"] : $_SERVER['REQUEST_METHOD']; /** * Directory: * Relative directory or subdirectory of the public document root */ if (isset($_SERVER["SCRIPT_NAME"])) { $dir = explode("/", trim($_SERVER["SCRIPT_NAME"], "/ ")); array_pop($dir); //script file, usually index.php $dir = implode("/", $dir); $dir = !empty($dir) ? $dir . "/" : null; } else { $dir = ""; } $con['directory'] = $dir; /* * Resource: * Request resource (without directory or query string) */ $resource = ''; if (!empty($_SERVER["PATH_INFO"])) { $resource = $_SERVER["PATH_INFO"]; } else { $currentUri = explode("?", $_SERVER["REQUEST_URI"], 2); $resource = substr(trim($currentUri[0], "/ "), strlen($con['directory'])); } $con['resource'] = explode('.', trim($resource, '/ ') . "/"); if ($con["resource"] == "/") { $con["resource"] = ""; } /** * Requested resource format */ if (empty($con['resource']) || count($con['resource']) == 1) { $con['resource'] = implode('.', $con['resource']); $con['format'] = Ac::config("http.default_format", "html"); } else { $con['format'] = strtolower(array_pop($con['resource'])); if (empty($con['format'])) { $con['format'] = Ac::config("http.default_format", "html"); } $con['resource'] = implode('.', $con['resource']); } /** * Query string */ $con['query_string'] = $_SERVER["QUERY_STRING"]; /** * Raw input stream (readable one time only; not available for mutipart/form-data requests) */ $rawInput = @file_get_contents('php://input'); if (!$rawInput) { $rawInput = ''; } $con['raw_input'] = $rawInput; /** * Client user agent */ $con['user_agent'] = $_SERVER["HTTP_USER_AGENT"]; /** * Client keyboard language (comma separated and lowercased) */ $con['languages'] = preg_replace("/\\;q\\=[0-9]{1,}\\.[0-9]{1,}/", "", $_SERVER["HTTP_ACCEPT_LANGUAGE"]); /** * Client IP */ $con['client_ip'] = in_array($_SERVER["REMOTE_ADDR"], array('::1', '127.0.0.1')) ? 'localhost' : $_SERVER["REMOTE_ADDR"]; /** * Is CLI ? */ $con['is_cli'] = PHP_SAPI == "cli"; /** * Is AJAX ? */ $con['is_ajax'] = strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'; $this->context = $con; $this->generateId(); } }
* When using a legacy application with PHP >= 5.3, it is recommended to disable * deprecated notices. Disable with: E_ALL & ~E_DEPRECATED */ error_reporting(E_ALL | E_STRICT); /** * Display errors by default */ ini_set("display_errors", true); /** * Set default charset, locale and timezone */ ini_set('default_charset', 'UTF-8'); setlocale(LC_ALL, 'en_US.UTF8'); date_default_timezone_set('UTC'); //Check PHP 5.3 if (version_compare(PHP_VERSION, "5.3", "<")) { throw new RuntimeException("Anidcore Framework needs PHP 5.3 or greater in order to run"); } // Change dir to root dir chdir(AC_PATH); // Include AC_PATH in include path restore_include_path(); set_include_path(get_include_path() . PATH_SEPARATOR . AC_PATH); // Load the core require_once AC_PATH_SYSTEM . "functions.php"; require_once AC_PATH_SYSTEM . "classes" . _DS . "ac" . _DS . "loader.php"; if (is_readable(AC_PATH_APP . "install.php")) { require_once AC_PATH_APP . "install.php"; } else { Ac::run(true); }