/** * xml定義からhandlerを処理する * @param string $file アプリケーションXMLのファイルパス */ public static final function load($file = null) { if (!isset($file)) { $file = App::mode() . App::called_filename(); } if (!self::$is_app_cache || !Store::has($file)) { $parse_app = self::parse_app($file, false); if (self::$is_app_cache) { Store::set($file, $parse_app); } } if (self::$is_app_cache) { $parse_app = Store::get($file); } if (empty($parse_app['apps'])) { throw new RuntimeException('undef app'); } $app_result = null; $in_app = $match_handle = false; $app_index = 0; try { foreach ($parse_app['apps'] as $app) { switch ($app['type']) { case 'handle': $self = new self('_inc_session_=false'); foreach ($app['modules'] as $module) { $self->add_module(self::import_instance($module)); } if ($self->has_module('flow_handle_begin')) { $self->call_module('flow_handle_begin', $self); } try { if ($self->handler($app['maps'], $app_index++)->is_pattern()) { $self->cp(self::execute_var($app['vars'])); $src = $self->read(); if ($self->has_module('flow_handle_end')) { $self->call_module('flow_handle_end', $src, $self); } print $src; $in_app = true; $match_handle = true; if (!$parse_app["handler_multiple"]) { exit; } } } catch (Exception $e) { Log::warn($e); if (isset($app['on_error']['status'])) { Http::status_header((int) $app['on_error']['status']); } if (isset($app['on_error']['redirect'])) { $this->save_exception($e); $this->redirect($app['on_error']['redirect']); } else { if (isset($app['on_error']['template'])) { if (!$e instanceof Exceptions) { Exceptions::add($e); } $self->output($app['on_error']['template']); } else { throw $e; } } } break; case 'invoke': $class_name = isset($app['class']) ? Lib::import($app['class']) : get_class($app_result); $ref_class = new ReflectionClass($class_name); foreach ($app['methods'] as $method) { $invoke_class = $ref_class->getMethod($method['method'])->isStatic() ? $class_name : (isset($app['class']) ? new $class_name() : $app_result); $args = array(); foreach ($method['args'] as $arg) { if ($arg['type'] === 'result') { $args[] =& $app_result; } else { $args[] = $arg['value']; } } if (is_object($invoke_class)) { foreach ($app['modules'] as $module) { $invoke_class->add_module(self::import_instance($module)); } } $app_result = call_user_func_array(array($invoke_class, $method['method']), $args); $in_app = true; } break; } } if (!$match_handle) { Log::debug("nomatch"); if ($parse_app["nomatch_redirect"] !== null) { Http::redirect(App::url($parse_app["nomatch_redirect"])); } if ($parse_app["nomatch_template"] !== null) { Http::status_header(404); $self = new self(); $self->output($parse_app["nomatch_template"]); } } if (!$in_app) { Http::status_header(404); } } catch (Exception $e) { if (!$e instanceof Exceptions) { Exceptions::add($e); } } exit; }
<?php require_once 'app/init.php'; if (Auth::check()) { redirect_to(App::url()); } ?> <?php echo View::make('header')->render(); ?> <div id="service"> <div class="container"> <div class="row centered"> <div class="row"> <div class="col-md-6 col-md-offset-3"> <h3 class="page-header">Impressum und Disclaimer</h3> </div> </div> </div> </div> </div> <?php echo View::make('footer')->render();
/** * アプリケーションのurlを取得する * * @param string $path * @return string */ function url($path = null) { return App::url($path); }
public static function getPhoneThumbnail($id) { PDOConnexion::setParameters('phonedeals', 'root', 'root'); $db = PDOConnexion::getInstance(); $sql = 'SELECT name, color FROM phone WHERE id = :id'; $sth = $db->prepare($sql); $sth->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Phone'); $sth->execute(array(':id' => $id)); $req = $sth->fetch(); $colors = explode(',', $req->color); $imgUrl = 'uploads/phones/' . $id . '/' . App::url($req->name) . '-' . $colors[0] . '.jpg'; if (!file_exists($imgUrl)) { return 'img/default-thumbnail.jpg'; } return $imgUrl; }
} ?> <?php echo View::make('header')->render(); ?> <div class="row"> <div class="col-md-6"> <h3 class="page-header"> <?php _e('main.connecting_with'); echo Config::get("auth.providers.{$provider}"); ?> <a href="<?php echo App::url(); ?> " class="btn btn-info btn-sm"><?php _e('main.cancel'); ?> </a> </h3> <?php if (OAuth::fails()) { echo '<div class="alert alert-danger alert-dismissible"><span class="close" data-dismiss="alert">×</span><ul>'; foreach (OAuth::errors()->all('<li>:message</li>') as $error) { echo $error; } echo '</ul></div>'; }
/** * @covers \Phix\App::url */ public function testUrl() { $app = new App(array('baseUrl' => array('/foo'))); $url = $app->url(array('bar')); $this->assertEquals('/foo/bar', $url); $app->url(function () { return array('bar'); }); $this->assertEquals('/foo/bar', $url); }
<?php require_once 'app/init.php'; if (isset($_GET['logout'])) { Auth::logout(); redirect_to(App::url('admin.php')); } if (Auth::guest()) { echo View::make('admin.login')->render(); exit; } if (!Auth::userCan('dashboard')) { echo View::make('admin.restricted')->render(); exit; } $page = isset($_GET['page']) ? $_GET['page'] : 'dashboard'; if (View::exists("admin.{$page}")) { echo View::make('admin.' . $page)->render(); } else { echo View::make('admin.404')->render(); }
/** * work dirを変更する * -work PATH * @param Request $req * @param string $value PATH */ public static function __setup_work__(Request $req, $value) { $path = File::absolute(App::work() . '/', $value); self::app_config_update(App::url(), $path, App::mode()); self::info_print('work dir changed `' . $path . '`'); }
/** * xmlのmapのnameからurlを返す * @param string $test_file テストファイルパス * @param string $map_name テストファイルにひも付くアプリケーションXMLのMAP名 * @return string */ public static function map_url($test_file, $map_name) { $args = func_get_args(); array_shift($args); array_shift($args); if (!empty(self::$current_map_test_file)) { $test_file = self::$current_map_test_file; } if (!isset(self::$maps[$test_file]) && preg_match("/^(.+)\\/([^\\/]+)_test\\.php\$/", $test_file, $match)) { list(, $dir, $file) = $match; $dir = str_replace(self::path(), "", $dir); if (substr($dir, 0, 1) == "/") { $dir = substr($dir, 1); } if (substr($dir, -1) == "/") { $dir = substr($dir, 0, -1); } $target_file = App::path($dir . "/" . $file . ".php"); if (is_file($target_file)) { $parse_app = Flow::parse_app($target_file); foreach ($parse_app['apps'] as $app) { if ($app['type'] == 'handle') { foreach ($app['maps'] as $p => $c) { $count = 0; if (!empty($p)) { $p = substr(preg_replace_callback("/([^\\\\])(\\(.*?[^\\\\]\\))/", create_function('$m', 'return $m[1]."%s";'), " " . $p, -1, $count), 1); } if (!empty($c['name'])) { self::$maps[$test_file][$c['name']][$count] = $p; } } } } } } if (!isset(self::$maps[$test_file])) { throw new InvalidArgumentException($test_file . " is not app"); } if (!isset(self::$maps[$test_file][$map_name]) || !isset(self::$maps[$test_file][$map_name][sizeof($args)])) { throw new InvalidArgumentException($test_file . "[" . $map_name . "](" . sizeof($args) . ") not found"); } return App::url(vsprintf(self::$maps[$test_file][$map_name][sizeof($args)], $args)); }
/** * 初期定義 * * @param string $path アプリケーションのルートパス * @param string $url アプリケーションのURL * @param string $work 一時ファイルを書き出すパス * @param string $mode モード */ public static function config_path($path, $url = null, $work = null, $mode = null) { if (empty($path)) { $debug = debug_backtrace(false); $debug = array_pop($debug); $path = $debug['file']; } if (is_file($path)) { $path = dirname($path); } self::$path = preg_replace("/^(.+)\\/\$/", "\\1", str_replace("\\", "/", $path)) . "/"; if (isset($work)) { if (is_file($work)) { $work = dirname($work); } self::$work = preg_replace("/^(.+)\\/\$/", "\\1", str_replace("\\", "/", $work)) . "/"; } else { self::$work = self::$path . 'work/'; } if (!empty($url)) { self::$url = preg_replace("/^(.+)\\/\$/", "\\1", $url) . "/"; self::$surl = preg_replace("/^http:\\/\\/(.+)\$/", "https://\$1", self::$url); } if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { list($lang) = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']); list($lang) = explode('-', $lang); self::lang($lang); self::set_messages(self::$path); } self::$mode = empty($mode) ? 'noname' : $mode; if (is_file(App::path('__repository__.xml'))) { Repository::load_map(App::path('__repository__.xml')); } if (is_file(App::path('__common__.php'))) { require_once App::path('__common__.php'); } if (is_file(App::path('__common_' . $mode) . '__.php')) { require_once App::path('__common_' . $mode . '__.php'); } }
public function __construct() { $this->dir = \App::url('web/assets/'); }
<script src="<?php echo asset_url('js/vendor/iframeResizer.contentWindow.min.js'); ?> "></script> <script src="<?php echo asset_url('js/easylogin.js'); ?> "></script> <script src="<?php echo asset_url('js/main.js'); ?> "></script> <script> EasyLogin.options = { ajaxUrl: '<?php echo App::url("ajax.php"); ?> ', lang: <?php echo json_encode(trans('main.js')); ?> , debug: <?php echo Config::get('app.debug') ? 1 : 0; ?> , }; </script> </head> <body> <?php
/** * メディアURL * @return string */ public static function base_media_url() { return isset(self::$base_media_url) ? self::$base_media_url : App::url('resources/media', false) . '/'; }
echo __t("Admin Panel"); ?> </a> </li> <li class="divider"></li> <li><a href="#"><i class="icon-envelope"></i> <?php echo __t("Web mail"); ?> </a></li> <li><a href="#"><i class="icon-user"></i> <?php echo __t("Server admin"); ?> </a></li> <li> <a href="mailto:contact@example.com?subject=Support&body=Ref:<?php echo urlencode(" " . App::url("current")); ?> "> <i class="icon-question-sign"></i> <?php echo __t("Support"); ?> </a> </li> </ul> </li> <li> <form class="navbar-search"> <input name="acq" type="text" class="search-query span2" placeholder="<?php echo __t("Search"); ?>
function ajax_avatar() { if (Auth::guest()) { exit; } $userId = Auth::user()->id; $options = array('upload_dir' => app('path.base') . '/uploads/', 'upload_url' => App::url('uploads/'), 'max_file_size' => 5000000, 'max_width' => 2000, 'max_height' => 2000, 'versions' => array('' => array('crop' => true, 'max_width' => 300, 'max_height' => 300)), 'upload_start' => function ($image, $instance) use($userId) { $image->name = "~{$userId}.{$image->type}"; }, 'crop_start' => function ($image, $instance) use($userId) { $image->name = "{$userId}.{$image->type}"; }, 'crop_complete' => function ($image, $instance) use($userId) { Usermeta::update($userId, 'avatar_image', $image->name); }); new Hazzard\Support\ImagePicker($options, trans('imgpicker')); }