public static function get_action_name($is_api = false) { if ($is_api) { return sprintf('%s_%s', Str::lower(Request::main()->get_method()), Request::active()->action); } return Request::active()->action; }
public function before() { parent::before(); if (Request::main() === Request::active() || Request::active()->uri->uri == 'welcome/404') { $this->check_auth(); $this->set_user(); $this->set_theme(); } else { $this->set_user(); } }
/** * リンク生成に用いる変数を再計算 */ protected function _recalculate() { if (is_string($this->config['uri_segment'])) { $index_char = \Input::get($this->config['uri_segment'], null); } else { $index_char = (int) \Request::main()->uri->get_segment($this->config['uri_segment']); } // パラメータが渡されていなければデフォルトのインデックスを選択 if ($index_char === null) { $this->config['calculated_page'] = $this->config['default_page']; } else { $this->config['calculated_page'] = $index_char; } }
public function before() { parent::before(); // controllerとaction毎にcssとjsを自動読み込み $controller = mb_strtolower(str_replace('Controller/', '', strtr(Request::main()->controller, '_', '/'))); $action = Request::main()->action; if (File::exists(DOCROOT . 'assets/css/' . $controller . '.css')) { Asset::css(array($controller . '.css'), array(), 'controller_style_css', false); } if (File::exists(DOCROOT . 'assets/css/' . $controller . '/' . $action . '.css')) { Asset::css(array($controller . '/' . $action . '.css'), array(), 'action_style_css', false); } if (File::exists(DOCROOT . 'assets/js/' . $controller . '.js')) { Asset::js(array($controller . '.js'), array(), 'controller_script_js', false); } if (File::exists(DOCROOT . 'assets/js/' . $controller . '/' . $action . '.js')) { Asset::js(array($controller . '/' . $action . '.js'), array(), 'action_script_js', false); } }
/** * Sets the initial view filename and local data. * * $view = new View($file); * * @param string view filename * @param array array of values * @return void * @uses View::set_filename */ public function __construct($file = null, $data = null, $filter = null) { if (is_object($data) === true) { $data = get_object_vars($data); } elseif ($data and !is_array($data)) { throw new \InvalidArgumentException('The data parameter only accepts objects and arrays.'); } // @TODO in v1.2 remove the auto_encode_view_data reference. $this->auto_filter = is_null($filter) ? \Config::get('security.auto_filter_output', \Config::get('security.auto_encode_view_data', true)) : $filter; if ($file !== null) { $this->set_filename($file); } if ($data !== null) { // Add the values to the current data $this->data = $data; } // store the current request search paths to deal with out-of-context rendering if (class_exists('Request', false) and $active = \Request::active() and \Request::main() != $active) { $this->request_paths = $active->get_paths(); } isset($active) and $this->active_request = $active; }
/** * Gets the current URL, including the BASE_URL * * @param string the url */ public static function main() { return static::create(\Request::main()->uri->uri); }
/** * Generate values for the "properties" key for the page() method. * * @return array The array of data for the "properties" key. */ private function _get_page_properties() { $properties_data['properties'] = array('url' => \Uri::base() . 'SEGMENT_PACKAGE_NO_URL_SET', 'referrer' => \Input::referrer(), 'path' => '/' . \Uri::string()); /* * Fix: When \Request::main() is false, \Uri::main() tryies to get a property of the non-object * \Request::main(). */ if (\Request::main() instanceof \Request) { $properties_data['properties']['url'] = \Uri::main(); } return $properties_data; }
/** * Create an OpAuth instance * * @param array any call-time configuration to be used * @param bool whether or not Opauth should run automatically */ public static function forge($config = array(), $autorun = true) { // deal with passing only the autorun value if (func_num_args() == 1 and is_bool($config)) { $autorun = $config; $config = array(); } // merge the default config with the runtime config $config = \Arr::merge(\Config::get('opauth'), $config); // define the transport system we use $config['callback_transport'] = 'get'; // make sure we have a remotes table if (!isset($config['table']) and ($config['table'] = static::$provider_table) === null) { throw new \OpauthException('No providers table configured. At the moment, only SimpleAuth and OrmAuth can be auto-detected.'); } // and a security salt if (empty($config['security_salt'])) { throw new \OpauthException('There is no "security_salt" defined in the opauth.php configuration file.'); } // set some defaults, just in case isset($config['security_iteration']) or $config['security_iteration'] = 300; isset($config['security_timeout']) or $config['security_timeout'] = '2 minutes'; if (empty($config['path'])) { $parsed_url = parse_url(\Uri::base() . \Request::main()->uri->get()); $path = explode('/', trim($parsed_url['path'], '/')); // construct the path if needed // $path = \Request::main()->uri->get_segments(); $params = count(\Request::active()->route->method_params); while ($params-- > 0) { array_pop($path); } $config['path'] = '/' . implode('/', $path) . '/'; } // and construct the callback URL if needed if (empty($config['callback_url'])) { // pop the method name from the path $path = explode('/', trim($config['path'], '/')); array_pop($path); // and add 'callback' as the controller callback action $config['callback_url'] = '/' . implode('/', $path) . '/callback/'; } // determine the name of the provider we want to call if (!$autorun) { // we're processing a callback $config['provider'] = 'Callback'; } else { if (empty($config['provider'])) { $parsed_url = parse_url(\Uri::base() . \Request::main()->uri->get()); $provider = explode('/', substr($parsed_url['path'], strlen($config['path']))); $config['provider'] = ucfirst($provider[0]); } // check if we have a strategy defined for this provider $strategies = \Config::get('opauth.Strategy', array()); if (!array_key_exists(strtolower($config['provider']), array_change_key_case($strategies))) { throw new \OpauthException('Opauth strategy "' . $config['provider'] . '" is not supported'); } } // return the created Auth_Opauth object return new static($config, $autorun); }
/** * Sets the initial view filename and local data. * * $view = new View($file); * * @param string view filename * @param array array of values * @return void * @uses View::set_filename */ public function __construct($file = null, array $data = null, $encode = null) { $encode === null and $encode = static::$auto_encode; if ($file !== null) { $this->set_filename($file); } if ($data !== null) { if ($encode) { foreach ($data as $k => $v) { $data[$k] = \Security::htmlentities($v); } } // Add the values to the current data $this->_data = $data + $this->_data; } // store the current request search paths to deal with out-of-context rendering if (class_exists('Request', false) and $active = \Request::active() and \Request::main() != $active) { $this->request_paths = $active->get_paths(); } }
/** * Prepares vars for creating links */ protected function _recalculate() { // calculate the number of pages $this->config['total_pages'] = ceil($this->config['total_items'] / $this->config['per_page']) ?: 1; // get the current page number, either from the one set, or from the URI or the query string if ($this->config['current_page']) { $this->config['calculated_page'] = $this->config['current_page']; } else { if (is_string($this->config['uri_segment'])) { $this->config['calculated_page'] = \Input::get($this->config['uri_segment'], 1); } else { $this->config['calculated_page'] = (int) \Request::main()->uri->get_segment($this->config['uri_segment']); } } // make sure the current page is within bounds if ($this->config['calculated_page'] > $this->config['total_pages']) { $this->config['calculated_page'] = $this->config['total_pages']; } elseif ($this->config['calculated_page'] < 1) { $this->config['calculated_page'] = 1; } // the current page must be zero based so that the offset for page 1 is 0. $this->config['offset'] = ($this->config['calculated_page'] - 1) * $this->config['per_page']; }
protected function check_is_admin_request() { if ($this->is_admin) { return true; } if (is_enabled('admin') && Request::main()->route->module == 'admin') { return true; } return false; }
/** * Prepares vars for creating links */ protected function _recalculate() { // calculate the number of pages $this->config['total_pages'] = ceil($this->config['total_items'] / $this->config['per_page']) ?: 1; // calculate the current page number $this->config['current_page'] = ($this->config['total_items'] > 0 and $this->config['current_page'] > 1) ? $this->config['current_page'] : (int) \Request::main()->uri->get_segment($this->config['uri_segment']); // make sure the current page is within bounds if ($this->config['current_page'] > $this->config['total_pages']) { $this->config['current_page'] = $this->config['total_pages']; } elseif ($this->config['current_page'] < 1) { $this->config['current_page'] = 1; } // the current page must be zero based so that the offset for page 1 is 0. $this->config['offset'] = ($this->config['current_page'] - 1) * $this->config['per_page']; }