From d2ae2f7900501e17318aeb9ebad6ed567f0cd15c Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 3 May 2017 23:24:15 -0500 Subject: [PATCH] Progress: minor cleanups and bugfixes, prepare management and administration dashboards --- common/base/classes/base_path.php | 511 +++++++++++++++--------------- common/base/classes/base_return.php | 32 +- common/standard/classes/standard_path.php | 2 +- common/standard/paths/a/dashboard.php | 80 +++++ common/standard/paths/a/ja/dashboard.php | 29 ++ common/standard/paths/m/dashboard.php | 80 +++++ common/standard/paths/m/ja/dashboard.php | 29 ++ common/standard/paths/u/dashboard.php | 4 +- 8 files changed, 492 insertions(+), 275 deletions(-) create mode 100644 common/standard/paths/a/ja/dashboard.php create mode 100644 common/standard/paths/m/dashboard.php create mode 100644 common/standard/paths/m/ja/dashboard.php diff --git a/common/base/classes/base_path.php b/common/base/classes/base_path.php index 6dc890d..bb82731 100644 --- a/common/base/classes/base_path.php +++ b/common/base/classes/base_path.php @@ -74,27 +74,27 @@ class c_base_path extends c_base_rfc_string { 'encoding' => 'UTF-8', ); - protected $id_group = NULL; + protected $id_group; - protected $is_content = NULL; - protected $is_alias = NULL; - protected $is_redirect = NULL; - protected $is_private = NULL; - protected $is_locked = NULL; - protected $is_root = NULL; + protected $is_content; + protected $is_alias; + protected $is_redirect; + protected $is_private; + protected $is_locked; + protected $is_root; - protected $field_destination = NULL; - protected $field_response_code = NULL; + protected $field_destination; + protected $field_response_code; - protected $date_created = NULL; - protected $date_changed = NULL; - protected $date_locked = NULL; + protected $date_created; + protected $date_changed; + protected $date_locked; - protected $include_directory = NULL; - protected $include_name = NULL; + protected $include_directory; + protected $include_name; - protected $allowed_methods = NULL; - protected $sanitize_html = NULL; + protected $allowed_methods; + protected $sanitize_html; /** @@ -112,7 +112,6 @@ class c_base_path extends c_base_rfc_string { $this->is_locked = FALSE; $this->is_root = FALSE; - $this->field_destination = NULL; $this->field_response_code = NULL; @@ -178,91 +177,6 @@ class c_base_path extends c_base_rfc_string { } /** - * Assign the value. - * - * The string must be a valid URL path. - * - * This removes multiple consecutive '/'. - * This removes any '/' prefix. - * This removes any '/' suffix. - * This limits the string size to 256 characters. - * - * @param string $value - * Any value so long as it is a string. - * NULL is not allowed. - * - * @return bool - * TRUE on success, FALSE otherwise. - */ - public function set_value($value) { - if (!is_string($value)) { - return FALSE; - } - - $sanitized = self::pr_sanitize_path($value); - - // the path wildcard is intentionally non-standard. - // remove it so that it does not cause the validator to fail. - $without_wildcard = preg_replace('@(^%/|^%$|/%/|/%$)@', '', $sanitized); - if (!is_string($without_wildcard)) { - return FALSE; - } - - // check to see if sanitized value is allowed. - $without_wilcard_parts = $this->pr_rfc_string_prepare($without_wildcard); - unset($without_wildcard); - - if ($without_wilcard_parts['invalid']) { - unset($without_wilcard_parts); - unset($sanitized); - return FALSE; - } - - $validated = $this->pr_rfc_string_is_path($without_wilcard_parts['ordinals'], $without_wilcard_parts['characters']); - if ($validated['invalid']) { - unset($without_wilcard_parts); - unset($validated); - unset($sanitized); - return FALSE; - } - unset($without_wilcard_parts); - unset($validated); - - $this->value = $sanitized; - unset($sanitized); - - return TRUE; - } - - /** - * Return the value. - * - * @return string|null $value - * The value array stored within this class. - */ - public function get_value() { - if (!is_string($this->value)) { - return NULL; - } - - return $this->value; - } - - /** - * Return the value of the expected type. - * - * @return DOMNode $value - * The value DOMNode stored within this class. - */ - public function get_value_exact() { - if (!is_string($this->value)) { - return ''; - } - - return $this->value; - } - - /** * Create a content path. * * @param int $id_group @@ -414,6 +328,63 @@ class c_base_path extends c_base_rfc_string { } /** + * Assign the value. + * + * The string must be a valid URL path. + * + * This removes multiple consecutive '/'. + * This removes any '/' prefix. + * This removes any '/' suffix. + * This limits the string size to 256 characters. + * + * @param string $value + * Any value so long as it is a string. + * NULL is not allowed. + * + * @return bool + * TRUE on success, FALSE otherwise. + */ + public function set_value($value) { + if (!is_string($value)) { + return FALSE; + } + + $sanitized = self::pr_sanitize_path($value); + + // the path wildcard is intentionally non-standard. + // remove it so that it does not cause the validator to fail. + $without_wildcard = preg_replace('@(^%/|^%$|/%/|/%$)@', '', $sanitized); + if (!is_string($without_wildcard)) { + return FALSE; + } + + // check to see if sanitized value is allowed. + $without_wilcard_parts = $this->pr_rfc_string_prepare($without_wildcard); + unset($without_wildcard); + + if ($without_wilcard_parts['invalid']) { + unset($without_wilcard_parts); + unset($sanitized); + return FALSE; + } + + $validated = $this->pr_rfc_string_is_path($without_wilcard_parts['ordinals'], $without_wilcard_parts['characters']); + if ($validated['invalid']) { + unset($without_wilcard_parts); + unset($validated); + unset($sanitized); + return FALSE; + } + unset($without_wilcard_parts); + unset($validated); + + $this->value = $sanitized; + unset($sanitized); + + return TRUE; + } + + /** * Assigns sort id. * * @param int $id_group @@ -679,6 +650,34 @@ class c_base_path extends c_base_rfc_string { } /** + * Return the value. + * + * @return string|null + * The value array stored within this class. + */ + public function get_value() { + if (!is_string($this->value)) { + return NULL; + } + + return $this->value; + } + + /** + * Return the value of the expected type. + * + * @return DOMNode + * The value DOMNode stored within this class. + */ + public function get_value_exact() { + if (!is_string($this->value)) { + return ''; + } + + return $this->value; + } + + /** * Gets the ID sort setting. * * @return c_base_return_int @@ -695,6 +694,160 @@ class c_base_path extends c_base_rfc_string { } /** + * Gets the destination field setting. + * + * @return c_base_return_string|c_base_return_array + * Destination field on success. + * An empty string is returned if not defined. + * Error bit is set on error. + */ + public function get_field_destination() { + if (!is_string($this->field_destination) && !is_array($this->field_destination)) { + return c_base_return_string::s_new(''); + } + + if (is_string($this->field_destination)) { + return c_base_return_string::s_new($this->field_destination); + } + + return c_base_return_array::s_new($this->field_destination); + } + + /** + * Gets the response code field setting. + * + * @return c_base_return_int + * Response code on success. + * An empty string is returned if not defined. + * Error bit is set on error. + */ + public function get_field_response_code() { + if (!is_int($this->field_response_code)) { + return c_base_return_int::s_new(''); + } + + return c_base_return_int::s_new($this->field_response_code); + } + + /** + * Gets the date created setting. + * + * @return c_base_return_float|c_base_return_null + * Date created on success. + * FALSE is returned if the date is not assigned. + * Error bit is set on error. + */ + public function get_date_created() { + if (!is_float($this->date_created)) { + return new c_base_return_false(); + } + + return c_base_return_float::s_new($this->date_created); + } + + /** + * Gets the date changed setting. + * + * @return c_base_return_float|c_base_return_null + * Date changed on success. + * FALSE is returned if the date is not assigned. + * Error bit is set on error. + */ + public function get_date_changed() { + if (!is_float($this->date_changed)) { + return new c_base_return_null(); + } + + return c_base_return_float::s_new($this->date_changed); + } + + /** + * Gets the date locked setting. + * + * @return c_base_return_float|c_base_return_null + * Date locked on success. + * NULL is returned if the date is not assigned. + * Error bit is set on error. + */ + public function get_date_locked() { + if (!is_float($this->date_locked)) { + return new c_base_return_null(); + } + + return c_base_return_float::s_new($this->date_locked); + } + + /** + * Get the assigned include path directory. + * + * This is the prefix part of the path. + * + * @return c_base_return_string|c_base_return_null + * Include path string on success. + * NULL is returned if the include path is not assigned. + * Error bit is set on error. + */ + public function get_include_directory() { + if (!is_string($this->include_directory)) { + return new c_base_return_null(); + } + + return c_base_return_string::s_new($this->include_directory); + } + + /** + * Get the assigned include path name. + * + * This is the suffix part of the path. + * + * @return c_base_return_string|c_base_return_null + * Include path string on success. + * NULL is returned if the include path is not assigned. + * Error bit is set on error. + */ + public function get_include_name() { + if (!is_string($this->include_name)) { + return new c_base_return_null(); + } + + return c_base_return_string::s_new($this->include_name); + } + + /** + * Get the assigned include path name. + * + * This is the suffix part of the path. + * + * @return c_base_return_array + * An array of allowed methods is returned. + * An empty array with the error bit set is returned on error. + */ + public function get_allowed_methods() { + if (!is_array($this->allowed_methods)) { + $this->allowed_methods = self::DEFAULT_ALLOWED_METHODS; + } + + return c_base_return_array::s_new($this->allowed_methods); + } + + /** + * Get the currently assigned HTML sanitization settings. + * + * @return c_base_return_array + * An array of html sanitization settings. + * An empty array with the error bit set is returned on error. + * + * @see: htmlspecialchars() + */ + public function get_sanitize_html() { + if (!is_array($this->sanitize_html)) { + $this->sanitize_html = self::DEFAULT_SANITIZE_HTML; + } + + return c_base_return_array::s_new($this->sanitize_html); + } + + /** * Get or Assign the is content boolean setting. * * @param bool|null $is_content @@ -893,160 +1046,6 @@ class c_base_path extends c_base_rfc_string { } /** - * Gets the destination field setting. - * - * @return c_base_return_string|c_base_return_array - * Destination field on success. - * An empty string is returned if not defined. - * Error bit is set on error. - */ - public function get_field_destination() { - if (!is_string($this->field_destination) && !is_array($this->field_destination)) { - return c_base_return_string::s_new(''); - } - - if (is_string($this->field_destination)) { - return c_base_return_string::s_new($this->field_destination); - } - - return c_base_return_array::s_new($this->field_destination); - } - - /** - * Gets the response code field setting. - * - * @return c_base_return_int - * Response code on success. - * An empty string is returned if not defined. - * Error bit is set on error. - */ - public function get_field_response_code() { - if (!is_int($this->field_response_code)) { - return c_base_return_int::s_new(''); - } - - return c_base_return_int::s_new($this->field_response_code); - } - - /** - * Gets the date created setting. - * - * @return c_base_return_float|c_base_return_null - * Date created on success. - * FALSE is returned if the date is not assigned. - * Error bit is set on error. - */ - public function get_date_created() { - if (!is_float($this->date_created)) { - return new c_base_return_false(); - } - - return c_base_return_float::s_new($this->date_created); - } - - /** - * Gets the date changed setting. - * - * @return c_base_return_float|c_base_return_null - * Date changed on success. - * FALSE is returned if the date is not assigned. - * Error bit is set on error. - */ - public function get_date_changed() { - if (!is_float($this->date_changed)) { - return new c_base_return_null(); - } - - return c_base_return_float::s_new($this->date_changed); - } - - /** - * Gets the date locked setting. - * - * @return c_base_return_float|c_base_return_null - * Date locked on success. - * NULL is returned if the date is not assigned. - * Error bit is set on error. - */ - public function get_date_locked() { - if (!is_float($this->date_locked)) { - return new c_base_return_null(); - } - - return c_base_return_float::s_new($this->date_locked); - } - - /** - * Get the assigned include path directory. - * - * This is the prefix part of the path. - * - * @return c_base_return_string|c_base_return_null - * Include path string on success. - * NULL is returned if the include path is not assigned. - * Error bit is set on error. - */ - public function get_include_directory() { - if (!is_string($this->include_directory)) { - return new c_base_return_null(); - } - - return c_base_return_string::s_new($this->include_directory); - } - - /** - * Get the assigned include path name. - * - * This is the suffix part of the path. - * - * @return c_base_return_string|c_base_return_null - * Include path string on success. - * NULL is returned if the include path is not assigned. - * Error bit is set on error. - */ - public function get_include_name() { - if (!is_string($this->include_name)) { - return new c_base_return_null(); - } - - return c_base_return_string::s_new($this->include_name); - } - - /** - * Get the assigned include path name. - * - * This is the suffix part of the path. - * - * @return c_base_return_array - * An array of allowed methods is returned. - * An empty array with the error bit set is returned on error. - */ - public function get_allowed_methods() { - if (!is_array($this->allowed_methods)) { - $this->allowed_methods = self::DEFAULT_ALLOWED_METHODS; - } - - return c_base_return_array::s_new($this->allowed_methods); - } - - /** - * Get the currently assigned HTML sanitization settings. - * - * @return c_base_return_array - * An array of html sanitization settings. - * An empty array with the error bit set is returned on error. - * - * @see: htmlspecialchars() - */ - public function get_sanitize_html() { - if (!is_array($this->sanitize_html)) { - $this->sanitize_html = self::DEFAULT_SANITIZE_HTML; - } - - return c_base_return_array::s_new($this->sanitize_html); - } - - /** * Execute using the specified path, rendering the page. * * @param c_base_http $http diff --git a/common/base/classes/base_return.php b/common/base/classes/base_return.php index df0eb1a..09de24c 100644 --- a/common/base/classes/base_return.php +++ b/common/base/classes/base_return.php @@ -30,14 +30,7 @@ require_once('common/base/classes/base_error.php'); * @require class base_error */ trait t_base_return_value { - protected $value = NULL; - - /** - * Class destructor. - */ - public function __destruct() { - unset($this->value); - } + protected $value; /** * Assign the value. @@ -207,14 +200,7 @@ trait t_base_return_value_exact { * This is added as a consideration and may be removed it ends up being unused. */ trait t_base_return_message { - protected $message = NULL; - - /** - * Class destructor. - */ - public function __destruct() { - unset($this->message); - } + protected $message; /** * Assign the message. @@ -550,6 +536,20 @@ class c_base_return_value extends c_base_return { use t_base_return_value; /** + * Class constructor. + */ + public function __construct() { + $this->value = NULL; + } + + /** + * Class destructor. + */ + public function __destruct() { + unset($this->value); + } + + /** * @see: t_base_return_value::p_s_new() */ public static function s_new($value) { diff --git a/common/standard/classes/standard_path.php b/common/standard/classes/standard_path.php index f3a447b..b2582a1 100644 --- a/common/standard/classes/standard_path.php +++ b/common/standard/classes/standard_path.php @@ -775,7 +775,7 @@ class c_standard_path extends c_base_path { } } - $href .= $request_uri['path']; + $href .= $this->request_uri['path']; $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_BASE); $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_HREF, $href); diff --git a/common/standard/paths/a/dashboard.php b/common/standard/paths/a/dashboard.php index e69de29..f6b10e7 100644 --- a/common/standard/paths/a/dashboard.php +++ b/common/standard/paths/a/dashboard.php @@ -0,0 +1,80 @@ +pr_assign_defaults($http, $database, $session, $settings); + + $wrapper = $this->pr_create_tag_section(array(1 => 0)); + + + // initialize the content as HTML. + $this->pr_create_html(); + $this->html->set_tag($wrapper); + unset($wrapper); + + $executed->set_output($this->html); + unset($this->html); + + + return $executed; + } + + /** + * Implementation of pr_create_html_add_header_link_canonical(). + */ + protected function pr_create_html_add_header_link_canonical() { + $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_LINK); + $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_REL, 'canonical'); + $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_HREF, $this->settings['base_scheme'] . '://' . $this->settings['base_host'] . $this->settings['base_port'] . $this->settings['base_path'] . self::PATH_SELF); + $this->html->set_header($tag); + + unset($tag); + } + + /** + * Implements pr_get_title(). + */ + protected function pr_get_title($arguments = array()) { + return $this->pr_get_text(0, $arguments); + } + + /** + * Implements pr_get_text(). + */ + protected function pr_get_text($code, $arguments = array()) { + switch ($code) { + case 0: + $string = 'Administration Dashboard'; + break; + } + + if (!empty($arguments)) { + $this->pr_process_replacements($string, $arguments); + } + + return $string; + } +} diff --git a/common/standard/paths/a/ja/dashboard.php b/common/standard/paths/a/ja/dashboard.php new file mode 100644 index 0000000..ae9a97e --- /dev/null +++ b/common/standard/paths/a/ja/dashboard.php @@ -0,0 +1,29 @@ +pr_process_replacements($string, $arguments); + } + + return $string; + } +} diff --git a/common/standard/paths/m/dashboard.php b/common/standard/paths/m/dashboard.php new file mode 100644 index 0000000..158f73e --- /dev/null +++ b/common/standard/paths/m/dashboard.php @@ -0,0 +1,80 @@ +pr_assign_defaults($http, $database, $session, $settings); + + $wrapper = $this->pr_create_tag_section(array(1 => 0)); + + + // initialize the content as HTML. + $this->pr_create_html(); + $this->html->set_tag($wrapper); + unset($wrapper); + + $executed->set_output($this->html); + unset($this->html); + + + return $executed; + } + + /** + * Implementation of pr_create_html_add_header_link_canonical(). + */ + protected function pr_create_html_add_header_link_canonical() { + $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_LINK); + $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_REL, 'canonical'); + $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_HREF, $this->settings['base_scheme'] . '://' . $this->settings['base_host'] . $this->settings['base_port'] . $this->settings['base_path'] . self::PATH_SELF); + $this->html->set_header($tag); + + unset($tag); + } + + /** + * Implements pr_get_title(). + */ + protected function pr_get_title($arguments = array()) { + return $this->pr_get_text(0, $arguments); + } + + /** + * Implements pr_get_text(). + */ + protected function pr_get_text($code, $arguments = array()) { + switch ($code) { + case 0: + $string = 'Management Dashboard'; + break; + } + + if (!empty($arguments)) { + $this->pr_process_replacements($string, $arguments); + } + + return $string; + } +} diff --git a/common/standard/paths/m/ja/dashboard.php b/common/standard/paths/m/ja/dashboard.php new file mode 100644 index 0000000..359dccd --- /dev/null +++ b/common/standard/paths/m/ja/dashboard.php @@ -0,0 +1,29 @@ +pr_process_replacements($string, $arguments); + } + + return $string; + } +} diff --git a/common/standard/paths/u/dashboard.php b/common/standard/paths/u/dashboard.php index d02790d..e2ea8ca 100644 --- a/common/standard/paths/u/dashboard.php +++ b/common/standard/paths/u/dashboard.php @@ -13,7 +13,7 @@ require_once('common/standard/classes/standard_path.php'); require_once('common/theme/classes/theme_html.php'); class c_standard_path_user_dashboard extends c_standard_path { - protected const PATH_DASHBOARD_USER = 'u/dashboard'; + protected const PATH_SELF = 'u/dashboard'; /** * Implements do_execute(). @@ -118,7 +118,7 @@ class c_standard_path_user_dashboard extends c_standard_path { protected function pr_create_html_add_header_link_canonical() { $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_LINK); $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_REL, 'canonical'); - $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_HREF, $this->settings['base_scheme'] . '://' . $this->settings['base_host'] . $this->settings['base_port'] . $this->settings['base_path'] . self::PATH_DASHBOARD_USER); + $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_HREF, $this->settings['base_scheme'] . '://' . $this->settings['base_host'] . $this->settings['base_port'] . $this->settings['base_path'] . self::PATH_SELF); $this->html->set_header($tag); unset($tag); -- 1.8.3.1