public function get($p = False) { $cls = $this->_cls; $fcls = $this->_fcls; $objects = new \Core\Li(); return $fcls::mapper()->get_list(\Core\Storage::container()->get_storage($cls)->fetch($p)); }
public static function start() { //注册AUTOLOAD方法 spl_autoload_register('Core\\LWH::autoload'); \Core\Storage::connect('File'); //选择文件存储引擎 $mode = (include LWH_PATH . 'Mode/' . APP_MODE . CONF_EXT); //模式配置文件 //加载核心类与函数 foreach ($mode['core'] as $file) { is_file($file) && (include $file); } //加载配置文件 foreach ($mode['config'] as $file) { is_file($file) && C(include $file); } date_default_timezone_set(C('DEFAULT_TIMEZONE')); //设置时区 //加载tags行为类 //注册错误处理函数 register_shutdown_function('Core\\LWH::fatalError'); //致命错误处理 set_error_handler('Core\\LWH::appError'); //普通错误处理 // set_exception_handler('Core\LWH::appException');//异常处理自定义throw new \Exception($e); \Core\App::run(); }
public function render($file, $data = []) { $data['stock'] = $this->storage->getAll(); $loader = new \Twig_Loader_Filesystem(PATH_PLUGINS); $twig = new \Twig_Environment($loader, array('cache' => defined('PATH_CACHE') ? PATH_CACHE : '')); $template = $twig->loadTemplate($file); return $template->render($data); }
public function index() { $t = $this->_template; $t->articles = \Plugins\Articles\Article::mapper()->attach_storage(\Core\Storage::container()->get_storage('Article'))->get_latest_articles(False, 'Agent', 'alias'); $t->content = $t->render('news.php'); $t->title = 'News'; echo $t->render('main.php'); }
protected function _edit_agent() { $t = $this->_template; $t->add('_jsapps', 'agent_form'); $storage = \Core\Storage::container()->get_storage('Agent'); $mapper = \Trouble\Agent::mapper()->attach_storage($storage); $t->errors = array(); if ($this->_args['alias']) { $t->title = "Edit Agent"; $agent = \Trouble\Agent::container()->get_by_alias($this->_args['alias']); $this->_auth->check_admin('agent', $agent->id); } else { try { $t->title = "Edit Yourself"; $agent = \Trouble\Agent::container()->get_by_id($this->_auth->user_id()); } catch (\Core\AuthNotLoggedInError $e) { $t->title = "Agent Application"; $t->new = True; $agent = \Trouble\Agent::create(); } } $t->agent = $agent; return $t->render('forms/agent.php'); }
public function get_by_id($id, $agent = False) { $params = static::params($agent); $params['filters'][] = new \Core\Filter('id', $id); $games = \Core\Storage::container()->get_storage('Game')->fetch($params); if (count($games) == 0) { throw new GameNotFoundError(); } return Game::mapper()->create_object($games[0]); }
public function save() { \Core\Storage::container()->get_storage($this->_cls)->save($this); return $this; }
protected function _edit() { $t = $this->_template; $t->add('_jsapps', 'game_form'); $storage = \Core\Storage::container()->get_storage('Game'); $mapper = \Trouble\Game::mapper()->attach_storage($storage); try { if ($this->_args['game_id']) { $t->title = "Edit Game"; $game = $this->_game; $this->_auth->check_admin('game', $game->id); $game->form_start_date = $game->start_date->format('Y-m-d'); $game->form_end_date = $game->end_date->format('Y-m-d'); $t->administration = $this->_administration($game); $t->vouchers = $this->_vouchers($game); } else { $t->title = "Game Creation"; $t->new = True; $game = \Trouble\Game::create($_POST, True); } $t->game = $game; return $t->render('forms/game.php'); } catch (\Core\AuthDeniedError $e) { throw new \Core\HTTPError(401, "Editing Game"); } catch (\Core\AuthNotLoggedInError $e) { throw new \Core\HTTPError(401, "Editing Game"); } }
public function is_root($user_id, $user_field = 'user') { $roots = \Core\Storage::container()->get_storage('Admin')->fetch(array('filters' => array(new \Core\Filter($user_field, $user_id), new \Core\Filter('type', 'ROOT')))); if (count($roots) > 0) { return True; } return False; }
/** * 解析和获取模板内容 用于输出 * @access public * @param string $templateFile 模板文件名 * @param string $content 模板输出内容 * @param string $prefix 模板缓存前缀 * @return string */ public function fetch($templateFile = '', $content = '', $prefix = '') { if (empty($content)) { $layoutFile = $this->parseLayout(); $templateFile = $this->parseTemplate($templateFile); // 模板文件不存在直接返回 if (!is_file($templateFile)) { halt("TemplateFile: {$templateFile} is not existent"); } $tmplContent = file_get_contents($templateFile); //开启layout if ($layoutFile) { if (false !== strpos($tmplContent, '{__NOLAYOUT__}')) { // 可以单独定义不使用布局 $tmplContent = str_replace('{__NOLAYOUT__}', '', $tmplContent); } else { // 替换布局的主体内容 $tmplContent = str_replace('{__CONTENT__}', $tmplContent, file_get_contents($layoutFile)); } } } else { $templateFile = $tmplContent = $content; } // 内容过滤标签 Hook::listen('view_filter', $tmplContent); //缓存 $cacheFile = APP_PATH . 'Runtime/' . CONTROLLER_NAME . '/' . ACTION_NAME . '-' . md5($templateFile . $layoutFile) . C('RUNTIME_SUFFIX'); if (!empty($content) && Storage::has($cacheFile) || $this->checkCache($cacheFile, $templateFile, $layoutFile)) { // echo '已经有缓存了!'; } else { // echo '进行缓存了!'; \Core\Storage::put($cacheFile, $tmplContent); } return $cacheFile; }
public function save_game() { import('core.validation'); import('trouble.game'); $validator = \Core\Validator::validator('\\Trouble\\Game'); $editing = $_POST['id'] > 0 ? True : False; try { if ($editing) { $this->_auth->check_admin('game', $_POST['id']); $game = \Trouble\Game::container()->get_by_id($_POST['id']); $validator->set_id($game->id); $game->overwrite($_POST, True); } else { $game = \Trouble\Game::mapper()->create_object($_POST); $game->creator = $this->_auth->user_id(); } try { \Core\Auth::hash($game, 'password'); } catch (\Core\AuthEmptyPasswordError $e) { $game->remove('password'); } $validator->validate($_POST); \Core\Storage::container()->get_storage('Game')->save($game); if (!$editing) { $this->_auth->add_admin('game', $game->id, $game->creator); } if ($editing) { echo $this->_return_message("Success", "Saved."); } else { echo $this->_return_message("Success", "Created game."); } } catch (\Core\ValidationError $e) { echo $this->_return_message("Fail", "Validation error(s):", $e->get_errors()); } catch (\Core\AuthNotLoggedInError $e) { $this->_not_logged_in(); } catch (\Core\AuthDeniedError $e) { $this->_access_denied(); } catch (\Exception $e) { $this->_unhandled_exception($e); } }
protected function _edit_article($tok, $author, $id=False) { $t = \Plugins\Articles\Plugin::get_template('admin/edit.php'); $t->admin_url = "/admin"; $t->tok = $tok; try { if($id) { $t->title = "Edit Article"; $article = \Plugins\Articles\Article::container() ->get_by_id($id); } else { $t->title = "Create Article"; $t->new = True; $article = \Plugins\Articles\Article::create($_POST, True); } if($_POST['_do'] == '1' && $this->_confirmed_request) { $article->overwrite($_POST); $article->form_values(); $validator = \Core\Validator::validator('\Plugins\Articles\Article'); $validator->validate($_POST, \Plugins\Articles\Article::validation()); if($t->new) { $article->author = $author; } \Core\Storage::container() ->get_storage('Article') ->save($article); } $t->article = $article; } catch(\Core\ValidationError $e) { return $this->_return_message("Fail", "Validation error(s):", $e->get_errors(), $t); } return $t->render(); }
public function find_by_game(\Trouble\Game $game, $limit = 20) { $items = \Core\Storage::container()->get_storage('Kill')->fetch(array("joins" => KillContainer::_standard_joins(), "filter" => new \Core\Filter("game", $game['id']))); $kills = Kill::mapper()->get_list($items); return $kills; }
public function __construct($args) { parent::__construct($args); }
function logWrite($log, $destination = '') { $now = date('c'); $destination = BASE_PATH . APP_NAME . '/Runtime/Log/' . (empty($destination) ? date('y_m_d') . '.log' : $destination); //检测日志文件大小,超过配置大小则备份日志文件重新生成 if (is_file($destination) && 2097152 <= filesize($destination)) { rename($destination, dirname($destination) . '/' . time() . '-' . basename($destination)); } \Core\Storage::append($destination, "[{$now}] " . $_SERVER['REMOTE_ADDR'] . ' ' . $_SERVER['REQUEST_URI'] . "\r\n{$log}\r\n"); // error_log("[{$now}] ".$_SERVER['REMOTE_ADDR'].' '.$_SERVER['REQUEST_URI']."\r\n{$log}\r\n", 3,$destination); }