function show_error($message, $status) { if (!is_cli_request()) { set_status_header($status); header('Content-type: application/json'); } $data = array('message' => $message); echo json_encode($data); exit; }
function initialize($params = array()) { if (count($params) > 0) { foreach ($params as $key => $val) { if (isset($this->{$key})) { $this->{$key} = $val; } } } if (!isset($this->find_rules)) { $this->find_rules = array(function () { if (is_cli_request()) { return 'cli'; } }, 'ext'); } }
function xlog($data, $to_screen = true) { $d = print_r($data, 1); if ($to_screen) { if (!is_cli_request()) { echo '<pre class="-debug prettyprint">'; } else { echo '[' . date('Y-m-d H:i:s') . "] "; } echo $d . "\n\n"; if (!is_cli_request()) { echo '</pre>' . "\n"; } } if (function_exists('log_message')) { log_message('info', $d); } }
/** * General Error Page * * This function takes an error message as input * (either as a string or an array) and displays * it using the specified template. * * @access private * @param string the heading * @param string the message * @param string the template name * @param int the status code * @return string */ function show_error($heading, $message, $template = 'error_general', $status_code = 500) { if (is_cli_request()) { $prefix = 'cli_'; $message = implode("\n", !is_array($message) ? array($message) : $message); } else { set_status_header($status_code); $prefix = ''; $message = '<p>' . implode('</p><p>', !is_array($message) ? array($message) : $message) . '</p>'; } if (ob_get_level() > $this->ob_level + 1) { ob_end_flush(); } ob_start(); if (file_exists(APPPATH . 'errors/' . $prefix . $template . '.php')) { include APPPATH . 'errors/' . $prefix . $template . '.php'; } else { include ARCHPATH . 'errors/' . $prefix . $template . '.php'; } $buffer = ob_get_contents(); ob_end_clean(); return $buffer; }
function ark_bootstrap($dir) { define('ARCHPHP_VERSION', '0.0.1'); define('COREPATH', __DIR__ . '/../'); define('ARCHPATH', COREPATH . 'ark/'); define('BASEPATH', COREPATH . 'system/'); define('ROOTPATH', $dir); define('APPROOTPATH', ROOTPATH . 'application/'); set_exception_handler('ark_handle_exceptions'); register_shutdown_function('ark_handle_shutdown'); spl_autoload_register('ark_autoload_class'); require_once ROOTPATH . 'config/ark.php'; $config['default'] = $config['default'] ? $config['default'] : 'default'; if (is_cli_request()) { $path = APPROOTPATH . $_SERVER['ARKAPPID'] . '/'; } else { $a = !empty($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '/'; $a = explode($a, $_SERVER['SCRIPT_NAME']); $a = explode('/index.php', $a[0]); $a = explode('/', $a[0]); $a = $a[count($a) - 1]; if (empty($a)) { $a = $config['default']; } $path = APPROOTPATH . $a . '/'; } if (!file_exists($path)) { $path = APPROOTPATH . $config['default'] . '/'; } define('APPPATH', $path); define('APPMODPATH', APPPATH . 'modules/'); define('ARCHMODPATH', ARCHPATH . 'modules/'); $manifest = ark_get_manifest(); define('ENVIRONMENT', $manifest['ENVIRONMENT']); define('DATAPATH', isset($manifest['DATAPATH']) ? $manifest['DATAPATH'] : 'data/'); define('THEMEPATH', isset($manifest['THEMEPATH']) ? $manifest['THEMEPATH'] : 'themes/'); }
function sess_destroy() { if (!is_cli_request()) { session_destroy(); session_start(); } $_SESSION = array(); }