public function before() { parent::before(); if (!\Auth::check() && !$this->getNotLoginAllowed()) { \Response::redirect('/ucenter/login?to_url=' . \Input::uri()); } }
/** * The basic welcome message * * @access public * @return Response */ public function action_index() { if (!Auth::check()) { return Response::redirect('auth/login?url=' . Input::uri()); } return Response::forge(View::forge('welcome/index')); }
/** * Will attempt to find an item based on the current URL, and route it through a controller before returning a 404 error * * @access public * @return Response */ public function action_catchall() { // Will try to find the model based on the URL $model = $this->model = \CMF::currentModel(); \CMF::$routed = true; // Return the normal 404 error if not found if (is_null($model)) { $action = trim(\Input::uri(), '/'); if (!empty($action)) { return \Request::forge('base/' . $action, false)->execute()->response(); } return $this->show404(); } // So the model was found - check if it has a controller to route to $template = \CMF::$template; $action = \CMF::$action; if (\CMF::hasController($template)) { $module = \CMF::$module; $path = \CMF::$path; $route = (empty($module) ? '' : $module . '/') . $path . (empty($action) ? '' : '/' . $action); return \Request::forge($route, false)->execute()->response(); } else { if (!empty($action)) { return $this->show404(); } else { if (\CMF::$root) { return \Request::forge('base/' . $action, false)->execute()->response(); } } } }
public function action_index() { $ext = Input::extension(); Log::info('500:' . Input::uri() . '.' . $ext); $this->response_status = 500; $this->template->content = View_Smarty::forge('500'); }
public function action_send() { if (!\Security::check_token()) { \Log::error('CSRF: ' . \Input::uri() . ' ' . \Input::ip() . ' "' . \Input::user_agent() . '"'); throw new HttpInvalidInputException('Invalid input data'); } $val = $this->form()->validation(); $val->add_callable('myvalidation'); if ($val->run()) { $post = $val->validated(); \Config::load('contact', true); $data = array(); $data['email'] = $post['email']; $data['name'] = $post['name']; $data['to'] = \Config::get('contact.admin_email'); $data['to_name'] = \Config::get('contact.admin_name'); $data['subject'] = \Config::get('contact.mail_subject'); $data['ip'] = \Input::ip(); $data['ua'] = \Input::user_agent(); $langs = implode(' ', $post['lang']); $data['body'] = <<<END ==================== 名前: {$post['name']} メールアドレス: {$post['email']} IPアドレス: {$data['ip']} ブラウザ: {$data['ua']} ==================== コメント: {$post['comment']} 性別: {$post['gender']} 問い合わせの種類: {$post['kind']} 好きな鳥: {$langs} ==================== END; try { $this->sendmail($data); $this->save($data); $this->template->title = 'コンタクトフォーム: 送信完了'; $this->template->content = View::forge('contact/send'); } catch (EmailValidationFailedException $e) { $this->template->title = 'コンタクトフォーム: 送信エラー'; $this->template->content = View::forge('contact/error'); \Log::error(__METHOD__ . ' email validation error: ' . $e->getMessage()); } catch (EmailSendingFailedException $e) { $this->template->title = 'コンタクトフォーム: 送信エラー'; $this->template->content = View::forge('contact/error'); \Log::error(__METHOD__ . ' email sending error: ' . $e->getMessage()); } catch (EmailSavingFailedException $e) { $this->template->title = 'コンタクトフォーム: 送信エラー'; $this->template->content = View::forge('contact/error'); \Log::error(__METHOD__ . ' email saving error: ' . $e->getMessage()); } } else { $this->template->title = 'コンタクトフォーム: エラー'; $this->template->content = View::forge('contact/index'); $this->template->content->set_safe('html_error', $val->show_errors()); } }
public function uri($includeBaseUrl = false) { $base = \Uri::base(false); $baseUrl = $this->generateBaseUrl(); if ($includeBaseUrl && strpos($base, $baseUrl) === false && strpos($base, 'http') !== 0 && strpos($base, '//') !== 0) { $base = $baseUrl . trim($base, '/'); } return rtrim($base, '/') . '/' . trim(\Input::uri(), '/'); }
public function Action_Index() { if (!Auth::check()) { return Response::redirect('auth/login?url=' . Input::uri()); } $data["auth_username"] = Auth::get('username', 'Unnamed'); $this->template->title = "F**k you!"; $this->template->auth_username = $data["auth_username"]; $this->template->content = View::Forge('dashboard/index', $data); }
public function action_index() { $ext = Input::extension(); Log::info('404:' . Input::uri() . '.' . $ext); // コンテンツの場合は404を返す $ext = Input::extension(); if (in_array($ext, array('png', 'jpg', 'jpeg', 'gif', 'js', 'css', 'aspx', 'xml', 'json'))) { header('HTTP/1.1 404 Not Found'); exit; } $this->response_status = 404; $this->template->content = View_Smarty::forge('404'); }
public function before() { parent::before(); try { if (!$this->user) { \Session::set_flash('error', "Please login to access this page."); //non logged in users must login first $destination = Uri::create(Input::uri()); Response::redirect(Uri::create('user/login', array(), array('destination' => $destination))); //require login first } } catch (Exception $e) { \Session::set_flash('error', $e->getMessage()); \Response::redirect('/welcome/404'); } }
/** * renders the navigation * * @param array array with tag attribute settings * @access public * @return void */ public static function render($type = 'default', array $attributes = array(), $header = false) { if (empty($type)) { return; } $links = \Config::get('navigation.' . $type, false); if (empty($links)) { throw new BootstrapException('Missing navigation links in config'); return; } $callback = \Config::get('bootstrap.navigation_links_callback', null); if ($callback != null) { $links = $callback($links); } foreach ($links as $key => &$link) { if (empty($link['url'])) { $link['url'] = \Inflector::friendly_title($link['title'], '-', true); } // Set link to active if it matches the current page URI. if (!isset($link['active'])) { $link['active'] = $link['url'] == ltrim(\Input::uri(), '/'); } if (empty($link['attributes'])) { $link['attributes'] = array(); } $anchor_classs = \Config::get('bootstrap.navigation.anchor_class', true); if ($anchor_classs) { if (!isset($link['attributes']['class'])) { $link['class'] = \Inflector::friendly_title($link['title'], '-', true); } $anchor_prefix = \Config::get('bootstrap.navigation.anchor_prefix', 'nav-'); if (!empty($anchor_prefix)) { $link['class'] = $anchor_prefix . $link['class']; } } if (!empty($link['class'])) { $link['attributes']['class'] = $link['class']; } } if (isset($attributes['class'])) { $attributes['class'] = 'nav ' . $attributes['class']; } else { $attributes['class'] = 'nav'; } echo \View::forge('navigation', array('header' => $header, 'links' => $links, 'attributes' => array_to_attr($attributes)))->render(); }
public function router($method, $params) { Config::load('base'); //$action = $this->request->controller . '_' . $this->request->action; $action = $this->request->route->translation; Logger::params($action, Input::all(), $this->params()); // ssl $cfg = empty($this->subsystem) ? 'site' : 'site.' . $this->subsystem; list($need, $action_list, $both_list) = $this->get_onoff(Config::get($cfg . '.ssl')); $redirect = false; if (empty($both_list) || !in_array($action, $both_list)) { $ssl = Input::protocol() == 'http'; if ($ssl) { $redirect = $need ? in_array($action, $action_list) : !in_array($action, $action_list); } else { $redirect = $need ? !in_array($action, $action_list) : in_array($action, $action_list); } } if ($redirect) { return Response::redirect(Uri::create(Input::uri(), [], [], $ssl)); } // authentication $flg = false; list($need, $action_list, $both_list) = $this->get_onoff(Config::get($cfg . '.auth')); if (empty($both_list) || !in_array($action, $both_list)) { if ($this->is_login()) { $flg = $need ? !in_array($action, $action_list) : in_array($action, $action_list); } else { $flg = $need ? in_array($action, $action_list) : !in_array($action, $action_list); } } if ($flg) { return Response::redirect($this->subsystem . '/auth'); } // call controller $call = 'action_' . $this->request->action; if (is_callable([$this, $call])) { $this->{$call}($params); } }
/** * @access public * @return Response */ public function action_pictures() { $data = array(); $data['Form'] = new \Form(); $data['Input'] = new \Input(); // $options = array(); $options = \Input::get(); $config = array('pagination_url' => \Input::uri() . '?' . http_build_query($options), 'total_items' => \Collection\Interaction::countSearchResults($options), 'uri_segment' => 'page', 'name' => 'bootstrap', 'per_page' => 50); $pagination = \Pagination::forge('venues', $config); $data['pagination'] = $pagination->render(); // get venues $options['per_page'] = $pagination->per_page; $options['offset'] = $pagination->offset; $data['pictures'] = \Collection\Interaction::search($options); // get all regions $options = array(); $data['regions'] = \Collection\Region::search($options); $data['order_by'] = \Form::select('order_by', \Input::get('order_by'), array('time_created' => 'Date', 'likes' => 'Likes', 'comments' => 'Comments'), array('style' => 'width: 80px')); $data['order_dir'] = \Form::select('order_dir', \Input::get('order_dir'), array('desc' => 'Desc', 'asc' => 'Asc'), array('style' => 'width: 80px')); $data['date_range'] = \Form::select('filter[date_range]', \Input::get('filter.date_range'), array('today' => 'Today', 'yesterday' => 'Yesterday', 'last2days' => 'Last 2 days ago', '2days' => '2 days ago', '3days' => '3 days ago', 'thisweek' => 'This week', 'thismonth' => 'This month'), array('style' => 'width: 80px')); $view = \View::forge('dashboard/pictures.twig', $data); return \Response::forge($view); }
/** * Finds the model associated with the given URL * * @param string $url The URL to search against (no trailing slashes please) * @param string|null $type The model class, in case you want to narrow down the search * @return object The model */ public static function getItemByUrl($url, $type = null) { // Plain query for the urls table to avoid initialising Doctrine for 404s $url_item = \DB::query("SELECT type, item_id, parent_id FROM urls WHERE url = '{$url}' AND alias_id IS NULL " . ($type !== null ? "AND type = '{$type}' " : "") . "ORDER BY item_id DESC")->execute(); // If multilingual is enabled, we need to check the ext_translations table too if (count($url_item) === 0 && static::langEnabled()) { $lang = static::$lang ?: static::$lang_default; if ($item_id = \DB::query("SELECT foreign_key FROM ext_translations WHERE locale = '{$lang}' AND field = 'url' AND object_class = 'CMF\\\\Model\\\\URL' AND content = '{$url}'")->execute()->get('foreign_key')) { $url_item = \DB::query("SELECT type, item_id FROM urls WHERE id = {$item_id}")->execute(); } } if (count($url_item) === 0 && $url == '/') { $url_item = static::settings()->start_page; if (is_null($url_item)) { return null; } $item = $url_item->item(); } else { if (count($url_item) === 0) { return null; } else { $url_item = $url_item[0]; $type = $url_item['type']; // Redirect if (!empty($url_item['parent_id'])) { $parentUrl = \DB::query("SELECT url FROM urls WHERE id = " . $url_item['parent_id'])->execute()->get('url'); if (!empty($parentUrl)) { $uri = '/' . ltrim(\Input::uri(), '/'); $q = \Input::get(); if (isset($q[$uri])) { unset($q[$uri]); } $qs = str_replace('=&', '&', trim(http_build_query($q), '=')); return \Response::redirect($parentUrl . (!empty($qs) ? '?' . $qs : ''), 'location', !empty($type) && is_numeric($type) ? intval($type) : 301); } } if (empty($type) || $type == \CMF\Model\URL::TYPE_EXTERNAL || !class_exists($type) || is_null($url_item['item_id'])) { return null; } $item = $type::select('item')->where('item.id = ' . $url_item['item_id'])->getQuery()->getResult(); } } if (is_array($item) && count($item) > 0) { $item = $item[0]; } else { $item = null; } return $item; }
/** * Construct takes a URI or detects it if none is given and generates * the segments. * * @param string The URI * @return void */ public function __construct($uri = null) { if (\Fuel::$profiling) { \Profiler::mark(__METHOD__ . ' Start'); } $this->uri = trim($uri ?: \Input::uri(), '/'); $this->segments = $this->uri === '' ? array() : explode('/', $this->uri); if (\Fuel::$profiling) { \Profiler::mark(__METHOD__ . ' End'); } }
/** * Construct takes a URI or detects it if none is given and generates * the segments. * * @param string The URI * @return void */ public function __construct($uri = null) { if (\Fuel::$profiling) { \Profiler::mark(__METHOD__ . ' Start'); } // if the route is a closure, an object will be passed here is_object($uri) and $uri = null; $this->uri = trim($uri ?: \Input::uri(), '/'); if (empty($this->uri)) { $this->segments = array(); } else { $this->segments = explode('/', $this->uri); } if (\Fuel::$profiling) { \Profiler::mark(__METHOD__ . ' End'); } }
/** * Processes the config and generates data for the template to render the sidebar * @return array The sidebar config */ public static function getSidebarConfig() { $sidebar_config = \Config::get(static::$sidebar_config_path, array()); $current_group = 0; $output = array(array('heading' => false, 'items' => array())); $class_prefix = static::$current_module != '_root_' ? ucfirst(static::$current_module) . '\\' : ''; // Check if the first item is a heading if (isset($sidebar_config[0]['heading'])) { $item = array_shift($sidebar_config); $output[0]['heading'] = $item['heading']; } foreach ($sidebar_config as $item) { if (isset($item['heading'])) { $current_group++; $output[$current_group] = array('heading' => $item['heading'], 'items' => array()); } else { if (isset($item['model'])) { $class_name = $class_prefix . $item['model']; if (!class_exists($class_name)) { $class_name = $item['model']; } if (!\CMF\Auth::can('view', $class_name)) { continue; } $metadata = $class_name::metadata(); $output[$current_group]['items'][] = array('icon' => isset($item['icon']) ? $item['icon'] : $class_name::icon(), 'title' => isset($item['title']) ? $item['title'] : $class_name::plural(), 'href' => '/admin/' . $metadata->table['name'], 'class' => $class_name, 'active' => $class_name === static::$current_class); } else { if (isset($item['link'])) { if (!isset($item['title'])) { $parts = explode('/', $item['link']); $item['title'] = \Inflector::humanize(str_replace('-', ' ', array_pop($parts))); } $uri = trim(\Input::uri(), '/'); $cmp = trim($item['link'], '/'); $output[$current_group]['items'][] = array('icon' => isset($item['icon']) ? $item['icon'] : 'dashboard', 'title' => $item['title'], 'href' => $item['link'], 'active' => strpos($uri, $cmp) === 0); } } } } return $output; }
protected static function log($msg, $method) { $uri = \Input::uri(); $ip = \Input::ip(); $agent = \Input::user_agent(); $msg = $msg . ' [' . $uri . ' ' . $ip . ' "' . $agent . '"]'; \Log::write('Auth', $msg, $method); }
public static function log_error($msg, $value) { Log::error($msg . ': ' . Input::uri() . ' ' . rawurlencode($value) . ' ' . Input::ip() . ' "' . Input::user_agent() . '"'); }
/** * redirect to url that contain language * example: * http://localhost/ -> http://localhost/en * http://localhost/page -> http://localhost/en/page * * @author Vee Winch. * @license MIT * @link http://rundiz.com The author's website. * @package Fuel Start */ public function redirectLanguageUri() { $locales = \Config::get('locales'); $default_lang = \Config::get('language'); if (is_array($locales) && !empty($locales)) { if (!count($this->segments)) { // current uri is in root web. the url is http://domain.tld/fuelphp_root_web/ $need_redirect = true; // redirect to http://domain.tld/fuelphp_root_web/{lang} $redirect_url = $default_lang; } else { // current url is in dir or /lang $uri_exp = explode('/', \Input::uri()); // the \Input::uri will return uri segments with / at the start. when explode it, the first array might be null. // check that first array of exploded uri is not null. if (isset($uri_exp[0]) && $uri_exp[0] != null) { $first_uri = $uri_exp[0]; } elseif (isset($uri_exp[1])) { $first_uri = $uri_exp[1]; } else { // in case that \Input::uri with exploded / is not array or something wrong. $first_uri = $default_lang; } // if first uri is NOT in locales. if (!array_key_exists($first_uri, $locales)) { // first uri segment is not lang. the url is http://domain.tld/fuelphp_root_web/page $need_redirect = true; // redirect to http://domain.tld/fuelphp_root_web/{lang}/page $redirect_url = $default_lang . '/' . implode('/', $this->segments); } } // if need to redirect. if (isset($need_redirect) && $need_redirect === true) { // set no cache header. $response = new Response(); $response->set_header('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate'); $response->set_header('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT'); $response->set_header('Pragma', 'no-cache'); $response->send_headers(); // clean vars. unset($default_lang, $first_uri, $locales, $need_redirect); // go! redirect. (do not use fuelphp redirect because it generate error 404 in home page) $redirect_url = self::createNL($redirect_url); // use redirect manually. $response->set_status(301); $response->set_header('Location', $redirect_url); $response->send(true); exit; } // clean vars. unset($default_lang, $locales); } // clean vars. unset($default_lang, $locales); }
public static function log_error($message, $level = 'error') { if (!FBD_OUTPUT_ERROR_LOG_LEVEL) { return; } if (!in_array($level, array('error', 'warning', 'info', 'debug'))) { throw new InvalidArgumentException('Second parameter is invalid.'); } switch (FBD_OUTPUT_ERROR_LOG_LEVEL) { case 'error': if (in_array($level, array('warning', 'info', 'debug'))) { return; } break; case 'warning': if (in_array($level, array('info', 'debug'))) { return; } break; case 'info': if ($level == 'debug') { return; } break; case 'debug': default: break; } \Log::$level($message . ': ' . \Input::uri() . ' ' . \Input::ip() . ' "' . \Input::user_agent() . '"'); }
/** * Returns all segments in an array * * @return array */ public static function segments() { if ($request = \Request::active()) { $uri = \Uri::admin('string'); $uri = trim($uri ?: \Input::uri(), '/'); if (empty($uri)) { $segments = array(); } else { $segments = explode('/', $uri); } return $segments; } return null; }