private function _get_permissions() { if (CORE_DEBUG === false) { $err = new core_error('CxFFFF'); $err->set_fatal()->set_log(false)->run(); exit; } }
public static function do_call($command, $arguments) { // Separa o objeto do método if (preg_match(CORE_VALID_CALLER, $command, $command_details) === 1) { // Se um objeto for definido, significa que é uma chamada a um método estático de uma library if (!empty($command_details['object'])) { // Carrega a biblioteca, se necessário $command_details['object'] = self::load_library($command_details['object']); // Executa a chamada e retorna a informação obtida return call_user_func_array(array($command_details['object'], $command_details['method']), $arguments); } // Executa a chamada e retorna a informação obtida return call_user_func_array(self::load_helper($command_details['method']), $arguments); } // Se não for possível, lança uma exceção $error = new core_error('Cx2001', array('arguments' => $arguments, 'command_format' => CORE_VALID_CALLER), array('command' => $command)); $error->run(); }
private function _type_transform($type_data, $default_type = null) { if ($type_data === null) { $type_data = $default_type; } if (is_string($type_data) || is_array($type_data)) { $list = core::parse_setlist($type_data); $code = 0; foreach ($list as $item) { switch ($item) { case 'ok': $code |= self::TYPE_OK; break; case 'info': $code |= self::TYPE_INFO; break; case 'error': $code |= self::TYPE_ERROR; break; case 'warning': $code |= self::TYPE_WARNING; break; case 'exception': $code |= self::TYPE_EXCEPTION; break; case 'all': $code = self::TYPE_ALL; break; default: $error = new core_error('Cx2007', null, array('args' => array($item, $type_data))); $error->run(); } } return $code; } return $type_data; }
public static function autoload($class) { $class = strtolower($class); if (strpos($class, '_') !== false) { list($folder) = explode('_', $class); $file = 'class/' . $folder . '/' . substr($class, strlen($folder) + 1); } else { $file = 'class/' . $class; } try { self::import($file); return true; } catch (Exception $exc) { $trace = $exc->getTrace(); foreach ($trace as $log) { if (empty($log['class']) && $log['function'] == 'class_exists') { return false; } } core_error::exception_error($exc); } }
function error($message, $tplname) { core_error::template_error($message, $tplname); }
public static function write_error_log($message) { $message = core_error::clear($message); $time = time(); $file = DZF_ROOT . './data/log/' . date("Ym") . '_errorlog.php'; $hash = md5($message); $uid = getglobal('uid'); $ip = getglobal('clientip'); $user = '******' . intval($uid) . '; IP=' . $ip . '; RIP:' . $_SERVER['REMOTE_ADDR']; $uri = 'Request: ' . dhtmlspecialchars(core_error::clear($_SERVER['REQUEST_URI'])); $message = "<?PHP exit;?>\t{$time}\t{$message}\t{$hash}\t{$user} {$uri}\n"; if ($fp = @fopen($file, 'rb')) { $lastlen = 10000; $maxtime = 60 * 10; $offset = filesize($file) - $lastlen; if ($offset > 0) { fseek($fp, $offset); } if ($data = fread($fp, $lastlen)) { $array = explode("\n", $data); if (is_array($array)) { foreach ($array as $key => $val) { $row = explode("\t", $val); if ($row[0] != '<?PHP exit;?>') { continue; } if ($row[3] == $hash && $row[1] > $time - $maxtime) { return; } } } } } error_log($message, 3, $file); }
private function _throw_exception() { if (($this->_status & self::STATUS_CONTROLLER_NOT_FOUND) === self::STATUS_CONTROLLER_NOT_FOUND) { $error = new core_error('Cx2002', null, array('args' => array($this->_modular_data->fullpath))); } else { if (($this->_status & self::STATUS_METHOD_REQUIRED) === self::STATUS_METHOD_REQUIRED) { $error = new core_error('Cx2003', null, array('args' => array($this->_modular_data->url))); } else { if (($this->_status & self::STATUS_PATH_REQUIRED) === self::STATUS_PATH_REQUIRED) { $error = new core_error('Cx2004', null, array('args' => array($this->_modular_data->url))); } else { if (($this->_status & self::STATUS_MODULAR_REQUIRED) === self::STATUS_MODULAR_REQUIRED) { $error = new core_error('Cx2005', null, array('args' => array($this->_modular_data->url))); } else { if (($this->_status & self::STATUS_METHOD_NOT_EXISTS) === self::STATUS_METHOD_NOT_EXISTS) { $error = new core_error('Cx2006', null, array('args' => array("{$this->_modular_data->class}::{$this->_modular_data->method}"))); } } } } } $error->run(); }
function template($file, $templateid = 0, $tpldir = '', $gettplfile = 0, $primaltpl = '') { global $_G; static $_init_style = false; if ($_init_style === false) { ext::app()->_init_style(); $_init_style = true; } $oldfile = $file; if (strpos($file, ':') !== false) { $clonefile = ''; list($templateid, $file, $clonefile) = explode(':', $file); $oldfile = $file; $file = empty($clonefile) ? $file : $file . '_' . $clonefile; if ($templateid == 'diy') { $indiy = false; $_G['style']['tpldirectory'] = $tpldir ? $tpldir : (defined('TPLDIR') ? TPLDIR : ''); $_G['style']['prefile'] = ''; $diypath = SITE_ROOT . './data/diy/' . $_G['style']['tpldirectory'] . '/'; //DIY模板文件目录 $preend = '_diy_preview'; $_GET['preview'] = !empty($_GET['preview']) ? $_GET['preview'] : ''; $curtplname = $oldfile; $basescript = $_G['mod'] == 'viewthread' && !empty($_G['thread']) ? 'forum' : $_G['basescript']; if (isset($_G['cache']['diytemplatename' . $basescript])) { $diytemplatename =& $_G['cache']['diytemplatename' . $basescript]; } else { if (!isset($_G['cache']['diytemplatename'])) { loadcache('diytemplatename'); } $diytemplatename =& $_G['cache']['diytemplatename']; } $tplsavemod = 0; if (isset($diytemplatename[$file]) && file_exists($diypath . $file . '.htm') && ($tplsavemod = 1) || empty($_G['forum']['styleid']) && ($file = $primaltpl ? $primaltpl : $oldfile) && isset($diytemplatename[$file]) && file_exists($diypath . $file . '.htm')) { $tpldir = 'data/diy/' . $_G['style']['tpldirectory'] . '/'; !$gettplfile && ($_G['style']['tplsavemod'] = $tplsavemod); $curtplname = $file; if (isset($_GET['diy']) && $_GET['diy'] == 'yes' || isset($_GET['diy']) && $_GET['preview'] == 'yes') { //DIY模式或预览模式下做以下判断 $flag = file_exists($diypath . $file . $preend . '.htm'); if ($_GET['preview'] == 'yes') { $file .= $flag ? $preend : ''; } else { $_G['style']['prefile'] = $flag ? 1 : ''; } } $indiy = true; } else { $file = $primaltpl ? $primaltpl : $oldfile; } $tplrefresh = $_G['config']['output']['tplrefresh']; if ($indiy && ($tplrefresh == 1 || $tplrefresh > 1 && !($_G['timestamp'] % $tplrefresh)) && filemtime($diypath . $file . '.htm') < filemtime(SITE_ROOT . $_G['style']['tpldirectory'] . '/' . ($primaltpl ? $primaltpl : $oldfile) . '.htm')) { if (!updatediytemplate($file, $_G['style']['tpldirectory'])) { unlink($diypath . $file . '.htm'); $tpldir = ''; } } if (!$gettplfile && empty($_G['style']['tplfile'])) { $_G['style']['tplfile'] = empty($clonefile) ? $curtplname : $oldfile . ':' . $clonefile; } $_G['style']['prefile'] = !empty($_GET['preview']) && $_GET['preview'] == 'yes' ? '' : $_G['style']['prefile']; } else { $tpldir = './source/plugin/' . $templateid . '/template'; } } $file .= !empty($_G['inajax']) && ($file == 'common/header' || $file == 'common/footer') ? '_ajax' : ''; $tpldir = $tpldir ? $tpldir : (defined('TPLDIR') ? TPLDIR : ''); $templateid = $templateid ? $templateid : (defined('TEMPLATEID') ? TEMPLATEID : ''); $filebak = $file; if (defined('IN_MOBILE') && !defined('TPL_DEFAULT') && strpos($file, 'mobile/') === false || isset($_G['forcemobilemessage']) && $_G['forcemobilemessage']) { $file = 'mobile/' . $oldfile; } if (!$tpldir) { $tpldir = './template/default'; } $tplfile = $tpldir . '/' . $file . '.htm'; $file == 'common/header' && defined('CURMODULE') && CURMODULE && ($file = 'common/header_' . $_G['basescript'] . '_' . CURMODULE); if (defined('IN_MOBILE') && !defined('TPL_DEFAULT')) { if (strpos($tpldir, 'plugin')) { if (!file_exists(SITE_ROOT . $tpldir . '/' . $file . '.htm') && !file_exists(SITE_ROOT . $tpldir . '/' . $file . '.php')) { core_error::template_error('template_notfound', $tpldir . '/' . $file . '.htm'); } else { $mobiletplfile = $tpldir . '/' . $file . '.htm'; } } !$mobiletplfile && ($mobiletplfile = $file . '.htm'); if (strpos($tpldir, 'plugin') && (file_exists(SITE_ROOT . $mobiletplfile) || file_exists(substr(SITE_ROOT . $mobiletplfile, 0, -4) . '.php'))) { $tplfile = $mobiletplfile; } elseif (!file_exists(SITE_ROOT . TPLDIR . '/' . $mobiletplfile) && !file_exists(substr(SITE_ROOT . TPLDIR . '/' . $mobiletplfile, 0, -4) . '.php')) { $mobiletplfile = './template/default/' . $mobiletplfile; if (!file_exists(SITE_ROOT . $mobiletplfile) && !$_G['forcemobilemessage']) { $tplfile = str_replace('mobile/', '', $tplfile); $file = str_replace('mobile/', '', $file); define('TPL_DEFAULT', true); } else { $tplfile = $mobiletplfile; } } else { $tplfile = TPLDIR . '/' . $mobiletplfile; } } $cachefile = './data/template/' . SITE_LANG . '_' . (defined('STYLEID') ? STYLEID . '_' : '_') . $templateid . '_' . str_replace('/', '_', $file) . '.tpl.php'; if ($templateid != 1 && !file_exists(SITE_ROOT . $tplfile) && !file_exists(substr(SITE_ROOT . $tplfile, 0, -4) . '.php') && !file_exists(SITE_ROOT . ($tplfile = $tpldir . $filebak . '.htm'))) { $tplfile = './template/default/' . $filebak . '.htm'; } if ($gettplfile) { return $tplfile; } checktplrefresh($tplfile, $tplfile, @filemtime(SITE_ROOT . $cachefile), $templateid, $cachefile, $tpldir, $file); return SITE_ROOT . $cachefile; }
public function required() { if ($this->_status !== self::STATUS_SUCCESS) { if (($this->_status & self::STATUS_VIEW_IS_INSECURE) === self::STATUS_VIEW_IS_INSECURE) { $error = new core_error('Cx2008', null, array('args' => array($this->_proposed_view))); } else { if (($this->_status & self::STATUS_VIEW_HAS_REMAINS) === self::STATUS_VIEW_HAS_REMAINS) { $remains = join('/', $this->_modular_data->remains); $error = new core_error('Cx2009', null, array('args' => array($remains, $this->_proposed_view))); } else { if (($this->_status & self::STATUS_VIEW_IS_EMPTY) === self::STATUS_VIEW_IS_EMPTY) { $error = new core_error('Cx200A'); } else { if (($this->_status & self::STATUS_VIEW_NOT_FOUND) === self::STATUS_VIEW_NOT_FOUND) { $error = new core_error('Cx200B', null, array('args' => array($this->_path))); } } } } $error->run(); } return $this; }
public function query($query_string) { // Inicia a conexão, se necessário if ($this->_connected === false) { $this->connect(); } // Armazena o resultado da query $query = $this->_connection->query($this->_last_query = $query_string); // Se a query falhar if ($query === false) { $error = new core_error('Cx3000', array('error' => $this->_connection->error, 'errno' => $this->_connection->errno, 'sql' => $this->_last_query)); $error->set_fatal(true); $error->run(); } return $query; }
function template($file, $templateid = 0, $tpldir = '', $gettplfile = 0, $primaltpl = '') { global $_G; static $_init_style = false; if ($_init_style === false) { ext::app()->_init_style(); $_init_style = true; } $oldfile = $file; if (strpos($file, ':') !== false) { $clonefile = ''; list($templateid, $file, $clonefile) = explode(':', $file); $oldfile = $file; $file = empty($clonefile) ? $file : $file . '_' . $clonefile; } $file .= !empty($_G['inajax']) && ($file == 'global/header' || $file == 'global/footer') ? '_ajax' : ''; //DEBUG 判断加载前台还是后台模版 $is_admin_path = $_G['config']['admin_folder'] . '/'; $is_admin = strpos($_G['PHP_SELF'], $is_admin_path); if (!$is_admin) { $tpldir = $tpldir ? $tpldir : (defined('TPLDIR') ? TPLDIR : ''); $is_admin_path = ''; } else { $is_admin_str = ''; $tpldir = $tpldir ? $tpldir : (defined('ADMIN_TPLDIR') ? ADMIN_TPLDIR : ''); $tpldir = $is_admin_path . trim($tpldir, './'); } $templateid = $templateid ? $templateid : (defined('TEMPLATEID') ? TEMPLATEID : ''); $filebak = $file; if (defined('IN_MOBILE') && !defined('TPL_DEFAULT') && strpos($file, 'mobile/') === false || isset($_G['forcemobilemessage']) && $_G['forcemobilemessage']) { $file = 'mobile/' . $oldfile; } if (!$tpldir) { $tpldir = $is_admin_path . './template/default'; } $tplfile = $tpldir . '/' . $file . '.htm'; $file == 'global/header' && defined('CURMODULE') && CURMODULE && ($file = 'global/header_' . $_G['basescript'] . '_' . CURMODULE); if (defined('IN_MOBILE') && !defined('TPL_DEFAULT')) { if (strpos($tpldir, 'plugin')) { if (!file_exists(SITE_ROOT . $tpldir . '/' . $file . '.htm') && !file_exists(SITE_ROOT . $tpldir . '/' . $file . '.php')) { core_error::template_error('template_notfound', $tpldir . '/' . $file . '.htm'); } else { $mobiletplfile = $tpldir . '/' . $file . '.htm'; } } !$mobiletplfile && ($mobiletplfile = $file . '.htm'); if (strpos($tpldir, 'plugin') && (file_exists(SITE_ROOT . $mobiletplfile) || file_exists(substr(SITE_ROOT . $mobiletplfile, 0, -4) . '.php'))) { $tplfile = $mobiletplfile; } elseif (!file_exists(SITE_ROOT . TPLDIR . '/' . $mobiletplfile) && !file_exists(substr(SITE_ROOT . TPLDIR . '/' . $mobiletplfile, 0, -4) . '.php')) { $mobiletplfile = $is_admin_path . './template/default/' . $mobiletplfile; if (!file_exists(SITE_ROOT . $mobiletplfile) && !$_G['forcemobilemessage']) { $tplfile = str_replace('mobile/', '', $tplfile); $file = str_replace('mobile/', '', $file); define('TPL_DEFAULT', true); } else { $tplfile = $mobiletplfile; } } else { $tplfile = TPLDIR . '/' . $mobiletplfile; } } $cachefile = $is_admin_path . './data/template/' . SITE_LANG . '_' . (defined('STYLEID') ? STYLEID . '_' : '_') . $templateid . '_' . str_replace('/', '_', $file) . '.tpl.php'; if ($templateid != 1 && !file_exists(SITE_ROOT . $tplfile) && !file_exists(substr(SITE_ROOT . $tplfile, 0, -4) . '.php') && !file_exists(SITE_ROOT . ($tplfile = $tpldir . $filebak . '.htm'))) { $tplfile = $is_admin_path . './template/default/' . $filebak . '.htm'; } if ($gettplfile) { return $tplfile; } checktplrefresh($tplfile, $tplfile, @filemtime(SITE_ROOT . $cachefile), $templateid, $cachefile, $tpldir, $file); return SITE_ROOT . $cachefile; }
public static function get_modular_parts($modular_path, $configs = null) { $configs = (array) $configs; // Aplica o modular path !isset($configs['modular_path_auto']) && ($configs['modular_path_auto'] = false); // Se for uma string, é necessário quebrar a informação if (is_string($modular_path)) { !isset($configs['split_by']) && ($configs['split_by'] = '_'); !isset($configs['group_by']) && ($configs['group_by'] = '__'); !isset($configs['neutral_by']) && ($configs['neutral_by'] = ""); !isset($configs['make_underlined']) && ($configs['make_underlined'] = true); $modular_path = str_replace($configs['group_by'], $configs['neutral_by'], $modular_path); $modular_path = explode($configs['split_by'], $modular_path); foreach ($modular_path as $key => $item) { $modular_path[$key] = str_replace($configs['neutral_by'], $configs['split_by'], $item); } if ($configs['modular_path_auto'] === true && $modular_path[0][0] === '_') { $modular_path[0] = substr($modular_path[0], 1); } } else { if ($modular_path === null) { $modular_path = array(); } } // Após ter a array, é necessário fazer a busca pelos arquivos !isset($configs['start_dir']) && ($configs['start_dir'] = CORE_MODULES); !isset($configs['search_modules']) && ($configs['search_modules'] = true); !isset($configs['search_paths']) && ($configs['search_paths'] = true); !isset($configs['path_repeat']) && ($configs['path_repeat'] = true); !isset($configs['path_clip']) && ($configs['path_clip'] = false); !isset($configs['path_clip_empty']) && ($configs['path_clip_empty'] = false); !isset($configs['path_extension']) && ($configs['path_extension'] = null); !isset($configs['file_extension']) && ($configs['file_extension'] = 'php'); !isset($configs['make_fullpath']) && ($configs['make_fullpath'] = false); !isset($configs['make_underlined']) && ($configs['make_underlined'] = false); // Em modo depuração, verifica se alguma configuração não suportada foi definida if (CORE_DEBUG === true) { static $config_keys = array('modular_path_auto', 'split_by', 'group_by', 'neutral_by', 'make_underlined', 'start_dir', 'search_modules', 'search_paths', 'path_repeat', 'path_clip', 'path_clip_empty', 'path_extension', 'file_extension', 'make_fullpath'); $config_diff = array_diff(array_keys($configs), $config_keys); if (!empty($config_diff)) { $error = new core_error('Cx2000', null, array('unknow_keys' => $config_diff)); $error->run(); } } // Define o diretório de partida $current_path = $configs['start_dir']; // Prepara os resultados $result = new stdclass(); // Se for necessário "clipar" o último elemento do path... if ($configs['path_clip'] === true) { $result->clipped = array_pop($modular_path); } // Se necessário, remove o último elemento do path se ele estiver vazio if ($configs['path_clip_empty'] === true && end($modular_path) === '') { array_pop($modular_path); } // Repete a última definição do path, se possível $last_try = $configs['path_repeat']; $using_last_try = false; // Se necessário, aplica a raiz do módulo if ($configs['modular_path_auto'] === true) { if (empty($modular_path[0])) { array_shift($modular_path); } else { $modular_path = array_merge(self::get_caller_module_path(), $modular_path); } } // Se for necessário buscar por módulos... if ($configs['search_modules'] === true && empty($modular_path) === false) { $result->modular = array(); // Para cada parte do array, verifica se é um diretório $last_key = count($modular_path) - 1; foreach ($modular_path as $key => $value) { // Propõe um diretório, a partir do segundo é usado um underline submodular $proposed_path = $current_path . ($key === 0 ? "/{$value}" : "/_{$value}"); // Se o diretório for aceito, adiciona aos módulos, aceita a proposta e continua a busca if (is_dir($proposed_path)) { // Se for necessário dar duplo underline... if ($configs['make_underlined'] === true) { $value = str_replace('_', '__', $value); } // Registra a ocorrência $result->modular[] = $value; $current_path = $proposed_path; // Se for a última chave, limpa o modular if ($last_key === $key) { $modular_path = array(); break; } continue; } // Quando terminar os diretórios, remove os caminhos encontrados do modular path $modular_path = array_slice($modular_path, $key); break; } // Se nenhum modular for cadastro, apaga a variável if (empty($result->modular)) { unset($result->modular); } // Se for necessário repetir if ($last_try === true && empty($modular_path) && !empty($result->modular)) { $last_try = false; $using_last_try = true; array_unshift($modular_path, end($result->modular)); } } // Após buscar o módulo, se for necessário, anexa o complemento if (!empty($configs['path_extension'])) { $current_path .= $configs['path_extension']; } // Se for necessário buscar por paths... if ($configs['search_paths'] === true && empty($modular_path) === false) { $result->path = array(); // Para cada modular, busca pelo sub-diretório while (true) { $last_key = count($modular_path) - 1; foreach ($modular_path as $key => $item_value) { $value = $item_value; // Propõe um diretório $proposed_path = $current_path . "/{$value}"; // Se o diretório for aceito, adiciona aos paths, aceita a proposta e continua a busca if (is_dir($proposed_path)) { // Se for necessário dar duplo underline... if ($configs['make_underlined'] === true) { $value = str_replace('_', '__', $value); } // Registra a ocorrência $result->path[] = $value; $current_path = $proposed_path; // Se for a última chave, limpa o modular if ($last_key === $key) { // Em última chance, verifica se pode ser um arquivo if ($last_try === true) { $proposed_file = "{$current_path}/{$item_value}.{$configs['file_extension']}"; if (is_file($proposed_file)) { $last_try = false; $result->path[] = $value; $current_path = $proposed_file; // Adiciona um informativo $result->repeated = true; } } $modular_path = array(); break 2; } continue; } // Propõe um arquivo $proposed_file = $proposed_path . ".{$configs['file_extension']}"; // Se for um arquivo, adiciona aos paths // Ao achar um arquivo, fecha a busca e avança a chave, simulando uma nova proposta if (is_file($proposed_file)) { // Se for necessário dar duplo underline... if ($configs['make_underlined'] === true) { $value = str_replace('_', '__', $value); } // Registra a ocorrência $result->path[] = $value; $current_path = $proposed_file; $key++; $last_try = false; } // Quando terminar os diretórios, remove os caminhos encontrados do modular path $modular_path = array_slice($modular_path, $key); break 2; } } // Se nenhum path for cadastro, apaga a variável if (empty($result->path)) { unset($result->path); } } // Se sobrar alguma informação no path, armazena if ($using_last_try === false) { if (!empty($modular_path)) { $result->remains = $modular_path; } } else { if (empty($modular_path)) { $result->repeated = true; } } // Se for necessário gerar o path completo... if ($configs['make_fullpath'] === true) { $result->fullpath = self::get_path_fixed(realpath($current_path)); } // Retorna o resultado gerado return $result; }