/** * Throws a new 404 exception. * * @throws Eight_Exception_404 * @return void */ public static function trigger($page = NULL) { // Silence 404 errors (as matched within the ignore array) and die quietly if (in_array(Router::$complete_uri, arr::c(Eight::config('core.ignore_page_not_found')))) { Eight::shutdown(); exit; } throw new Eight_Exception_404($page); }
/** * Finds an array of files matching the given id or tag. * * @param string cache key or tag * @param bool search for tags * @return array of filenames matching the id or tag */ public function exists($keys, $tag = NO) { if ($keys === YES) { // Find all the files return glob($this->config['directory'] . '*~*~*'); } elseif ($tag === YES) { // Find all the files that have the tag name $paths = array(); foreach ((array) $keys as $tag) { $paths = array_merge($paths, glob($this->config['directory'] . '*~*' . $tag . '*~*')); } // Find all tags matching the given tag $files = array(); foreach ($paths as $path) { // Split the files $tags = explode('~', basename($path)); // Find valid tags if (count($tags) !== 3 or empty($tags[1])) { continue; } // Split the tags by plus signs, used to separate tags $item_tags = explode('+', $tags[1]); // Check each supplied tag, and match aginst the tags on each item. foreach ($keys as $tag) { if (in_array($tag, $item_tags)) { // Add the file to the array, it has the requested tag $files[] = $path; } } } return $files; } else { $paths = array(); foreach ((array) $keys as $key) { // Find the file matching the given key $paths = array_merge($paths, arr::c(glob($this->config['directory'] . str_replace(array('/', '\\', ' '), '_', $key) . '~*'))); } return $paths; } }
/** * Checks for the specified role * * @param string role to check for * @return boolean does the user have this role? */ public function has_role($role) { if (!$this->loaded) { return false; } if (!is_array($this->roles) or $this->roles === NULL) { self::db()->use_master(YES); $rs = self::db()->join('user_roles AS ur', 'ur.user_role_role_id = r.role_id', 'LEFT')->where('ur.user_role_user_id', $this->id)->get('roles AS r')->result_array(); foreach (arr::c($rs) as $r) { $this->roles[$r['role_id']] = $r['role_name']; } unset($r, $rs); } // After we loaded them...if we still have no roles if (!is_array($this->roles) or count($this->roles) == 0) { return false; } if (is_string($role) and !ctype_digit($role)) { return in_array($role, $this->roles); } else { return isset($this->roles[$role]); } }
public function __to_assoc() { $assoc = array(); foreach (arr::c($this->data) as $key => $val) { $key = str_replace($this->column_prefix, "", $key); $assoc[$key] = $val; } return $assoc; }
/** * Displays a 404 page, unless config says to ignore page not found. * * @param string URI of page * @param string custom template * @throws Eight_Exception_404 */ public static function show_404($page = NO, $template = NO) { if (in_array($page, arr::c(Eight::config('core.ignore_page_not_found')))) { return FALSE; } throw new Eight_Exception_404($page, $template); }
/** * Return the errors array. * * @param boolean load errors from a lang file * @return array */ public function errors($file = nil, $seperator = false) { if ($file === nil) { return $this->errors; } else { $errors = array(); foreach ($this->errors as $input => $error) { // Key for this input error $key = "{$file}.{$input}.{$error}"; if (($errors[$input] = Eight::lang($key)) === $key) { // Get the default error message $errors[$input] = Eight::lang("{$file}.{$input}.default"); } } if (!$seperator) { return $errors; } else { $string = ''; $seperator = is_bool($seperator) ? "<br />\n" : $seperator . "\n"; foreach (arr::c($errors) as $error) { $string .= $error . $seperator; } return $string; } } }