]> Kevux Git Server - koopa/commitdiff
Progress: work on breadcrumbs and related
authorKevin Day <thekevinday@gmail.com>
Fri, 12 May 2017 21:13:01 +0000 (16:13 -0500)
committerKevin Day <thekevinday@gmail.com>
Fri, 12 May 2017 21:13:01 +0000 (16:13 -0500)
common/base/classes/base_array.php
common/base/classes/base_paths.php
common/standard/classes/standard_path.php
common/standard/classes/standard_paths.php
common/standard/internal/access_denied.php
common/standard/internal/bad_method.php
common/standard/internal/index.php
common/standard/internal/not_found.php
common/standard/internal/server_error.php

index 060cc573065ed64ab5b5c160399e6dff99f287fa..e59caf5219f91f36b29885a44350259aeb98bc0b 100644 (file)
@@ -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
index 7952dd47145b8f0cd378fbddcaf972246b9596ce..8aaf9429438da9cf31d00ebe93e3d9bc4a1803fa 100644 (file)
@@ -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))) {
index f3eaa5aed92656e7a7ccead57807db29c19c559b..a9bc1ef67d6ada523c978f9b77cdf911ac4108ff 100644 (file)
@@ -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();
   }
 }
+
index 560f254dba0a479df385820ffb8c82a568becd4e..8384adcffc3d262da53d33d756f88546b6554ce5 100644 (file)
@@ -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);
index d72501c8ce247019fb9631f91037c5179a682f96..9ff65a347340eca88b5efba9d90c5d1417a7478a 100644 (file)
@@ -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);
   }
 
   /**
index 3b276d92b8892b1fc4ea89ebf0e675038fa282ee..fe9f8a4d2186c0566634298b4b6b4d7ad55b472a 100644 (file)
@@ -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);
   }
 
   /**
index 7ae67ef41d9d9ecf03cf3e2882445741672a795d..06ee70fb61fc269cab0152b8d358553ea9ccd616 100644 (file)
@@ -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.
   }
 
   /**
index 4b94b2488861b59f39b9798247a2bc97ebbdf972..7c63e896318b0f2c3036b6fc57e84371fa8c889e 100644 (file)
@@ -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);
   }
 
   /**
index ac43c4b525e0c3a5ba4936bbfbedf35c686a7506..ea313ce37599e78cba43aeb28519602e4c9c9b7c 100644 (file)
@@ -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);
   }
 
   /**