From 4d06519b0ef45156cf5b6b0a02a8b7693e70af6c Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Fri, 12 May 2017 16:13:01 -0500 Subject: [PATCH] Progress: work on breadcrumbs and related --- common/base/classes/base_array.php | 96 ++++++++++++++++++++++++++++++ common/base/classes/base_paths.php | 4 ++ common/standard/classes/standard_path.php | 15 ++--- common/standard/classes/standard_paths.php | 6 ++ common/standard/internal/access_denied.php | 44 ++++++++++++-- common/standard/internal/bad_method.php | 44 ++++++++++++-- common/standard/internal/index.php | 3 - common/standard/internal/not_found.php | 46 +++++++++++--- common/standard/internal/server_error.php | 44 ++++++++++++-- 9 files changed, 267 insertions(+), 35 deletions(-) diff --git a/common/base/classes/base_array.php b/common/base/classes/base_array.php index 060cc57..e59caf5 100644 --- a/common/base/classes/base_array.php +++ b/common/base/classes/base_array.php @@ -212,6 +212,102 @@ class c_base_array extends c_base_rfc_string { } /** + * Return the first item in the array after calling reset(). + * + * @return c_base_return_status|c_base_return_value + * Value on success, FALSE otherwise. + * FALSE without error bit set is returned if no items are defined. + * FALSE with the error bit set is returned on error. + */ + public function get_item_reset() { + if (!is_array($this->items) || empty($this->items)) { + return new c_base_return_false(); + } + + return c_base_return_value::s_new(reset($this->items)); + } + + /** + * Return the first item in the array after calling current(). + * + * @return c_base_return_status|c_base_return_value + * Value on success, FALSE otherwise. + * FALSE without error bit set is returned if no items are defined. + * FALSE with the error bit set is returned on error. + */ + public function get_item_current() { + if (!is_array($this->items) || empty($this->items)) { + return new c_base_return_false(); + } + + return c_base_return_value::s_new(current($this->items)); + } + + /** + * Return the first item in the array after calling each(). + * + * @return c_base_return_status|c_base_return_value + * Value on success, FALSE otherwise. + * FALSE without error bit set is returned if no items are defined. + * FALSE with the error bit set is returned on error. + */ + public function get_item_each() { + if (!is_array($this->items) || empty($this->items)) { + return new c_base_return_false(); + } + + return c_base_return_value::s_new(each($this->items)); + } + + /** + * Return the first item in the array after calling next(). + * + * @return c_base_return_status|c_base_return_value + * Value on success, FALSE otherwise. + * FALSE without error bit set is returned if no items are defined. + * FALSE with the error bit set is returned on error. + */ + public function get_item_next() { + if (!is_array($this->items) || empty($this->items)) { + return new c_base_return_false(); + } + + return c_base_return_value::s_new(next($this->items)); + } + + /** + * Return the first item in the array after calling prev(). + * + * @return c_base_return_status|c_base_return_value + * Value on success, FALSE otherwise. + * FALSE without error bit set is returned if no items are defined. + * FALSE with the error bit set is returned on error. + */ + public function get_item_previous() { + if (!is_array($this->items) || empty($this->items)) { + return new c_base_return_false(); + } + + return c_base_return_value::s_new(prev($this->items)); + } + + /** + * Return the first item in the array after calling end(). + * + * @return c_base_return_status|c_base_return_value + * Value on success, FALSE otherwise. + * FALSE without error bit set is returned if no items are defined. + * FALSE with the error bit set is returned on error. + */ + public function get_item_end() { + if (!is_array($this->items) || empty($this->items)) { + return new c_base_return_false(); + } + + return c_base_return_value::s_new(end($this->items)); + } + + /** * Return the item at a specific index in the array. * * @param string $key diff --git a/common/base/classes/base_paths.php b/common/base/classes/base_paths.php index 7952dd4..8aaf942 100644 --- a/common/base/classes/base_paths.php +++ b/common/base/classes/base_paths.php @@ -330,6 +330,10 @@ class c_base_paths extends c_base_return { $path_tree = &$this->paths[$id_group]; $path_tree_history = array(); + if (is_array($this->root)) { + $path_tree_history[] = $this->root; + } + // @fixme: the current design needs to handle multiple possible wildcard paths when searching (such as '/a/b/c/%', '/a/%/c', where '/a/b/c/%' would prevent '/a/%/c' from ever matching). $path_part = array_shift($path_parts); if (is_array($path_tree) && (array_key_exists($path_part, $path_tree) || array_key_exists('%', $path_tree))) { diff --git a/common/standard/classes/standard_path.php b/common/standard/classes/standard_path.php index f3eaa5a..a9bc1ef 100644 --- a/common/standard/classes/standard_path.php +++ b/common/standard/classes/standard_path.php @@ -132,7 +132,7 @@ class c_standard_path extends c_base_path { * If not defined, then NULL is returned. * NULL with the error bit set is returned on error. */ - protected function get_breadcrumbs() { + public function get_breadcrumbs() { if (!($this->breadcrumbs instanceof c_base_menu_item)) { $this->pr_build_breadcrumbs(); } @@ -1067,7 +1067,7 @@ class c_standard_path extends c_base_path { * FALSE with error bit set is returned on error. */ protected function pr_build_menu_header() { - $menu = $this->pr_include_menu(self::PATH_MENU_HEADER, self::NAME_MENU_HEADER, self::HANDLER_MENU_HEADER); + $menu = $this->pr_include_path(self::PATH_MENU_HEADER, self::NAME_MENU_HEADER, self::HANDLER_MENU_HEADER); return $menu->do_build($this->http, $this->database, $this->session, $this->settings); } @@ -1089,7 +1089,7 @@ class c_standard_path extends c_base_path { * FALSE with error bit set is returned on error. */ protected function pr_build_menu_utility(&$http, &$database, &$session, $settings) { - $menu = $this->pr_include_menu(self::PATH_MENU_UTILITY, self::NAME_MENU_UTILITY, self::HANDLER_MENU_UTILITY); + $menu = $this->pr_include_path(self::PATH_MENU_UTILITY, self::NAME_MENU_UTILITY, self::HANDLER_MENU_UTILITY); return $menu->do_build($this->http, $this->database, $this->session, $this->settings); } @@ -1111,7 +1111,7 @@ class c_standard_path extends c_base_path { * FALSE with error bit set is returned on error. */ protected function pr_build_menu_breadcrumbs(&$http, &$database, &$session, $settings) { - $menu = $this->pr_include_menu(self::PATH_MENU_BREADCRUMBS, self::NAME_MENU_BREADCRUMBS, self::HANDLER_MENU_BREADCRUMBS); + $menu = $this->pr_include_path(self::PATH_MENU_BREADCRUMBS, self::NAME_MENU_BREADCRUMBS, self::HANDLER_MENU_BREADCRUMBS); return $menu->do_build($http, $database, $session, $settings, $this->breadcrumbs); } @@ -1133,7 +1133,7 @@ class c_standard_path extends c_base_path { * FALSE with error bit set is returned on error. */ protected function pr_build_menu_content(&$http, &$database, &$session, $settings) { - $menu = $this->pr_include_menu(self::PATH_MENU_CONTENT, self::NAME_MENU_CONTENT, self::HANDLER_MENU_CONTENT); + $menu = $this->pr_include_path(self::PATH_MENU_CONTENT, self::NAME_MENU_CONTENT, self::HANDLER_MENU_CONTENT); return $menu->do_build($this->http, $this->database, $this->session, $this->settings); } @@ -1155,7 +1155,7 @@ class c_standard_path extends c_base_path { * FALSE with error bit set is returned on error. */ protected function pr_build_menu_footer(&$http, &$database, &$session, $settings) { - $menu = $this->pr_include_menu(self::PATH_MENU_FOOTER, self::NAME_MENU_FOOTER, self::HANDLER_MENU_FOOTER); + $menu = $this->pr_include_path(self::PATH_MENU_FOOTER, self::NAME_MENU_FOOTER, self::HANDLER_MENU_FOOTER); return $menu->do_build($this->http, $this->database, $this->session, $this->settings); } @@ -1273,7 +1273,7 @@ class c_standard_path extends c_base_path { * @return c_base_meni * The created c_base_meni object. */ - protected function pr_include_menu($path, $name, $class) { + protected function pr_include_path($path, $name, $class) { require_once($path . $name . self::SCRIPT_EXTENSION); // use default if no aliases are found. @@ -1294,3 +1294,4 @@ class c_standard_path extends c_base_path { return new $class(); } } + diff --git a/common/standard/classes/standard_paths.php b/common/standard/classes/standard_paths.php index 560f254..8384adc 100644 --- a/common/standard/classes/standard_paths.php +++ b/common/standard/classes/standard_paths.php @@ -331,6 +331,12 @@ class c_standard_paths extends c_base_return { } else { $path_tree->set_items(array()); + + $handler_settings_index = $this->paths->find_path('')->get_value(); + if (isset($handler_settings_index['handler'])) { + $path_tree->set_item_append($handler_settings_index); + } + unset($handler_settings_index); } $path_failsafe->set_path_tree($path_tree); diff --git a/common/standard/internal/access_denied.php b/common/standard/internal/access_denied.php index d72501c..9ff65a3 100644 --- a/common/standard/internal/access_denied.php +++ b/common/standard/internal/access_denied.php @@ -17,14 +17,46 @@ class c_standard_path_access_denied extends c_standard_path { * Build the breadcrumb. */ protected function pr_build_breadcrumbs() { - $this->breadcrumbs = new c_base_menu_item(); + $handler_settings = $this->path_tree->get_item_reset()->get_value(); - $item = $this->pr_create_breadcrumbs_item($this->pr_get_text_breadcrumbs(0), ''); - $this->breadcrumbs->set_item($item); - unset($item); + if (!isset($handler_settings['include_name']) || !is_string($handler_settings['include_name'])) { + return parent::pr_build_breadcrumbs(); + } + + if (!isset($handler_settings['include_directory']) || !is_string($handler_settings['include_directory'])) { + return parent::pr_build_breadcrumbs(); + } + + if (!isset($handler_settings['handler']) || !is_string($handler_settings['handler'])) { + return parent::pr_build_breadcrumbs(); + } + + require_once($handler_settings['include_directory'] . $handler_settings['include_name'] . self::SCRIPT_EXTENSION); + + + $handler = NULL; + if (is_string($this->language_alias)) { + @include_once($handler_settings['include_directory'] . $this->language_alias . '/' . $handler_settings['include_name'] . self::SCRIPT_EXTENSION); + + $handler_class = $handler_settings['handler'] . '_' . $this->language_alias; + if (class_exists($handler_class)) { + $handler = new $handler_class(); + } + unset($handler_class); + } + + if (is_null($handler)) { + if (class_exists($handler_settings['handler'])) { + $handler = new $handler_settings['handler'](); + } + else { + unset($handler); + return parent::pr_build_breadcrumbs(); + } + } - // @todo: check the url path and attempt to get a breadcrumb for the current path. - // this will require external functions because the breadcrumb language specific text must be loaded. + $this->breadcrumbs = $handler->get_breadcrumbs(); + unset($handler); } /** diff --git a/common/standard/internal/bad_method.php b/common/standard/internal/bad_method.php index 3b276d9..fe9f8a4 100644 --- a/common/standard/internal/bad_method.php +++ b/common/standard/internal/bad_method.php @@ -17,14 +17,46 @@ class c_standard_path_bad_method extends c_standard_path { * Build the breadcrumb. */ protected function pr_build_breadcrumbs() { - $this->breadcrumbs = new c_base_menu_item(); + $handler_settings = $this->path_tree->get_item_reset()->get_value(); - $item = $this->pr_create_breadcrumbs_item($this->pr_get_text_breadcrumbs(0), ''); - $this->breadcrumbs->set_item($item); - unset($item); + if (!isset($handler_settings['include_name']) || !is_string($handler_settings['include_name'])) { + return parent::pr_build_breadcrumbs(); + } + + if (!isset($handler_settings['include_directory']) || !is_string($handler_settings['include_directory'])) { + return parent::pr_build_breadcrumbs(); + } + + if (!isset($handler_settings['handler']) || !is_string($handler_settings['handler'])) { + return parent::pr_build_breadcrumbs(); + } + + require_once($handler_settings['include_directory'] . $handler_settings['include_name'] . self::SCRIPT_EXTENSION); + + + $handler = NULL; + if (is_string($this->language_alias)) { + @include_once($handler_settings['include_directory'] . $this->language_alias . '/' . $handler_settings['include_name'] . self::SCRIPT_EXTENSION); + + $handler_class = $handler_settings['handler'] . '_' . $this->language_alias; + if (class_exists($handler_class)) { + $handler = new $handler_class(); + } + unset($handler_class); + } + + if (is_null($handler)) { + if (class_exists($handler_settings['handler'])) { + $handler = new $handler_settings['handler'](); + } + else { + unset($handler); + return parent::pr_build_breadcrumbs(); + } + } - // @todo: check the url path and attempt to get a breadcrumb for the current path. - // this will require external functions because the breadcrumb language specific text must be loaded. + $this->breadcrumbs = $handler->get_breadcrumbs(); + unset($handler); } /** diff --git a/common/standard/internal/index.php b/common/standard/internal/index.php index 7ae67ef..06ee70f 100644 --- a/common/standard/internal/index.php +++ b/common/standard/internal/index.php @@ -23,9 +23,6 @@ class c_standard_path_index extends c_standard_path { $item = $this->pr_create_breadcrumbs_item($this->pr_get_text_breadcrumbs(0), ''); $this->breadcrumbs->set_item($item); unset($item); - - // @todo: check the url path and attempt to get a breadcrumb for the current path. - // this will require external functions because the breadcrumb language specific text must be loaded. } /** diff --git a/common/standard/internal/not_found.php b/common/standard/internal/not_found.php index 4b94b24..7c63e89 100644 --- a/common/standard/internal/not_found.php +++ b/common/standard/internal/not_found.php @@ -15,16 +15,48 @@ class c_standard_path_not_found extends c_standard_path { /** * Build the breadcrumb. - * + */ protected function pr_build_breadcrumbs() { - $this->breadcrumbs = new c_base_menu_item(); + $handler_settings = $this->path_tree->get_item_reset()->get_value(); + + if (!isset($handler_settings['include_name']) || !is_string($handler_settings['include_name'])) { + return parent::pr_build_breadcrumbs(); + } + + if (!isset($handler_settings['include_directory']) || !is_string($handler_settings['include_directory'])) { + return parent::pr_build_breadcrumbs(); + } + + if (!isset($handler_settings['handler']) || !is_string($handler_settings['handler'])) { + return parent::pr_build_breadcrumbs(); + } - $item = $this->pr_create_breadcrumbs_item($this->pr_get_text_breadcrumbs(0), ''); - $this->breadcrumbs->set_item($item); - unset($item); + require_once($handler_settings['include_directory'] . $handler_settings['include_name'] . self::SCRIPT_EXTENSION); + + + $handler = NULL; + if (is_string($this->language_alias)) { + @include_once($handler_settings['include_directory'] . $this->language_alias . '/' . $handler_settings['include_name'] . self::SCRIPT_EXTENSION); + + $handler_class = $handler_settings['handler'] . '_' . $this->language_alias; + if (class_exists($handler_class)) { + $handler = new $handler_class(); + } + unset($handler_class); + } + + if (is_null($handler)) { + if (class_exists($handler_settings['handler'])) { + $handler = new $handler_settings['handler'](); + } + else { + unset($handler); + return parent::pr_build_breadcrumbs(); + } + } - // @todo: check the url path and attempt to get a breadcrumb for the current path. - // this will require external functions because the breadcrumb language specific text must be loaded. + $this->breadcrumbs = $handler->get_breadcrumbs(); + unset($handler); } /** diff --git a/common/standard/internal/server_error.php b/common/standard/internal/server_error.php index ac43c4b..ea313ce 100644 --- a/common/standard/internal/server_error.php +++ b/common/standard/internal/server_error.php @@ -17,14 +17,46 @@ class c_standard_path_server_error extends c_standard_path { * Build the breadcrumb. */ protected function pr_build_breadcrumbs() { - $this->breadcrumbs = new c_base_menu_item(); + $handler_settings = $this->path_tree->get_item_reset()->get_value(); - $item = $this->pr_create_breadcrumbs_item($this->pr_get_text_breadcrumbs(0), ''); - $this->breadcrumbs->set_item($item); - unset($item); + if (!isset($handler_settings['include_name']) || !is_string($handler_settings['include_name'])) { + return parent::pr_build_breadcrumbs(); + } + + if (!isset($handler_settings['include_directory']) || !is_string($handler_settings['include_directory'])) { + return parent::pr_build_breadcrumbs(); + } + + if (!isset($handler_settings['handler']) || !is_string($handler_settings['handler'])) { + return parent::pr_build_breadcrumbs(); + } + + require_once($handler_settings['include_directory'] . $handler_settings['include_name'] . self::SCRIPT_EXTENSION); + + + $handler = NULL; + if (is_string($this->language_alias)) { + @include_once($handler_settings['include_directory'] . $this->language_alias . '/' . $handler_settings['include_name'] . self::SCRIPT_EXTENSION); + + $handler_class = $handler_settings['handler'] . '_' . $this->language_alias; + if (class_exists($handler_class)) { + $handler = new $handler_class(); + } + unset($handler_class); + } + + if (is_null($handler)) { + if (class_exists($handler_settings['handler'])) { + $handler = new $handler_settings['handler'](); + } + else { + unset($handler); + return parent::pr_build_breadcrumbs(); + } + } - // @todo: check the url path and attempt to get a breadcrumb for the current path. - // this will require external functions because the breadcrumb language specific text must be loaded. + $this->breadcrumbs = $handler->get_breadcrumbs(); + unset($handler); } /** -- 1.8.3.1