More work with paths.
Add additional data to HTML, restructuring code as necessary.
- Now includes class names by date and path (assigned to <body>).
- Add sanitizer, I used drupal 7's css sanitizer as a reference (just their preg_replace() part).
Functions like get_is_root() is a bit awkward, change the behavior and name to be more suitable.
- get_is_root() and set_is_root() are both now is_root() such that is_root() functions as get_is_root() when no parameters are specified and functions as set_is_root() when parameters are specified.
- this is repeated for all other similar functions.
I decided to separate /a/ paths into two paths:
- /a/ - administrative paths (for advanced and technical administration).
- /m/ - management paths (which is where most of the non-user related website logged in access will be involved in).
Other fixes and changes.
// provide a language to fallback to if none is set.
const LANGUAGE_CLASS_DEFAULT = 'c_base_language_us_only';
- // reserved path groups: array(97, 99, 100, 102, 115, 116, 120, 121).
- const RESERVED_PATH_GROUP = array(c_base_ascii::LOWER_A, c_base_ascii::LOWER_C, c_base_ascii::LOWER_D, c_base_ascii::LOWER_F, c_base_ascii::LOWER_S, c_base_ascii::LOWER_T, c_base_ascii::LOWER_U, c_base_ascii::LOWER_X);
-
- // a class name to prepend to css classes or id attributes.
- const CSS_BASE = 'reservation-';
+ // reserved path groups: array(97, 99, 100, 102, 109, 115, 116, 120, 121).
+ const RESERVED_PATH_GROUP = array(c_base_ascii::LOWER_A, c_base_ascii::LOWER_C, c_base_ascii::LOWER_D, c_base_ascii::LOWER_F, c_base_ascii::LOWER_M, c_base_ascii::LOWER_S, c_base_ascii::LOWER_T, c_base_ascii::LOWER_U, c_base_ascii::LOWER_X);
// Represents the current timestamp of this PHP process/session, see: self::s_get_timestamp_session().
// Represents the default language class in use.
// This must be a class that implements: i_base_language.
// In most cases, this should be expected to be defined.
- private static $s_language = NULL;
+ private static $s_languages = NULL;
+
+
+ /**
+ * Set the default timezone.
+ *
+ * @param string $timezone
+ * The timezone string.
+ *
+ * @return c_base_return_status
+ * TRUE on success.
+ * FALSE with error bit set is returned on error.
+ */
+ public static function s_set_timezone($timezone) {
+ if (!($timezone instanceof i_base_language)) {
+ $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'timezone', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+ self::$s_timezone = $timezone;
+ return new c_base_return_true();
+ }
+
+ /**
+ * Set the default language.
+ *
+ * @param i_base_language $languages
+ * Must be a class that implements i_base_language.
+ *
+ * @return c_base_return_status
+ * TRUE on success.
+ * FALSE with error bit set is returned on error.
+ *
+ * @see: i_base_language()
+ */
+ public static function s_set_languages($languages) {
+ if (!($languages instanceof i_base_language)) {
+ $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'languages', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ self::$s_languages = $languages;
+ return new c_base_return_true();
+ }
/**
* Get a date string, relative to UTC, with support for milliseconds and microseconds.
}
/**
- * Set the default language.
- *
- * @param i_base_language $language
- * Must be a class that implements i_base_language.
- *
- * @return c_base_return_status
- * TRUE on success.
- * FALSE with error bit set is returned on error.
- *
- * @see: i_base_language
- */
- public static function s_set_languages($language) {
- if (!($language instanceof i_base_language)) {
- $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'language', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
- return c_base_return_error::s_false($error);
- }
-
- self::$s_language = $language;
- return new c_base_return_true();
- }
-
- /**
* Get the currently assigned language class.
*
* @return i_base_language
* @see: i_base_language
*/
public static function s_get_languages() {
- if (is_null(self::$s_language)) {
+ if (is_null(self::$s_languages)) {
$class = self::LANGUAGE_CLASS_DEFAULT;
- self::$s_language = new $class();
+ self::$s_languages = new $class();
unset($class);
}
- return self::$s_language;
+ return self::$s_languages;
}
/**
* @see: i_base_language
*/
public static function s_get_languages_class() {
- if (is_null(self::$s_language)) {
+ if (is_null(self::$s_languages)) {
$class = self::LANGUAGE_CLASS_DEFAULT;
- self::$s_language = new $class();
+ self::$s_languages = new $class();
return c_base_return_string::s_new($class);
}
- $class = get_class($this->s_language);
+ $class = get_class($this->s_languages);
return c_base_return_string::s_new($class);
}
}
}
/**
+ * Sanitizes a string to ensure it can be used as a CSS class name (or an id attribute name).
+ *
+ * Full performs the complete sanitization, only allowing dash, a-z, A-Z, underscore, 0-9,and ISO characters.
+ * Partial will replace all non-words with '_'.
+ * - After calling partial, a full sanitization still must be performed.
+ *
+ * @param string $text
+ * The text to sanitize.
+ * @param bool $partial
+ * (optional) When TRUE, the text is treated as a partial name.
+ * When FALSE, the text is treated as a full name.
+ *
+ * @return c_base_return_string
+ * A string is always returned.
+ * An empty string with the error bit set is returned on error.
+ */
+ public static function sanitize_css($text, $partial = FALSE) {
+ if (!is_string($text)) {
+ $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'text', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_value('', 'c_base_return_string', $error);
+ }
+
+ if (!is_bool($partial)) {
+ $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'partial', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_value('', 'c_base_return_string', $error);
+ }
+
+ if ($partial) {
+ $sanitized = preg_replace('/(\W)+/i', '_', $text);
+ }
+ else {
+ // (From drupal 7's drupal_clean_css_identifier() function.)
+ // Allowed characters: the dash (U+002D), a-z (U+0030 - U+0039), A-Z (U+0041 - U+005A), the underscore (U+005F), 0-9 (U+0061 - U+007A), and ISO 10646 characters U+00A1 and higher.
+ $sanitized = preg_replace('/[^\x{002D}\x{0030}-\x{0039}\x{0041}-\x{005A}\x{005F}\x{0061}-\x{007A}\x{00A1}-\x{FFFF}]/u', '', $text);
+ }
+
+ if (is_string($sanitized)) {
+ return c_base_return_string::s_new($sanitized);
+ }
+ unset($sanitized);
+
+ $error = c_base_error::s_log(' ' . $response['error']['message'], array('arguments' => array(':operation_name' => 'preg_replace', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::OPERATION_FAILURE);
+ return c_base_return_error::s_value('', 'c_base_return_string', $error);
+ }
+
+ /**
* Assign a unique numeric id to represent this HTML page.
*
* @param int $id
case c_base_mime::TYPE_UNKNOWN:
case c_base_mime::TYPE_PROVIDED:
case c_base_mime::TYPE_STREAM:
- case c_base_mime::TYPE_MULTIPART:
case c_base_mime::TYPE_TEXT_PLAIN:
case c_base_mime::TYPE_TEXT_HTML:
case c_base_mime::TYPE_TEXT_RSS:
return c_base_return_string::s_new($this->attributes[$attribute]);
}
+ case c_base_markup_attributes::ATTRIBUTE_XLINK_SHOW:
+ case c_base_markup_attributes::ATTRIBUTE_XLINK_ACTUATE:
+ case c_base_markup_attributes::ATTRIBUTE_XLINK_HREF:
+ if ($body) {
+ return c_base_return_string::s_new($this->attributes_body[$attribute]);
+ }
+ else {
+ return c_base_return_string::s_new($this->attributes[$attribute]);
+ }
+
case c_base_markup_attributes::ATTRIBUTE_ASYNCHRONOUS:
case c_base_markup_attributes::ATTRIBUTE_ATTRIBUTE_NAME:
case c_base_markup_attributes::ATTRIBUTE_AUTO_COMPLETE:
}
break;
+ case c_base_markup_attributes::ATTRIBUTE_XLINK_SHOW:
+ case c_base_markup_attributes::ATTRIBUTE_XLINK_ACTUATE:
+ case c_base_markup_attributes::ATTRIBUTE_XLINK_HREF:
+ if (!is_string($value)) {
+ return new c_base_return_false();
+ }
+ break;
+
case c_base_markup_attributes::ATTRIBUTE_ARIA_ATOMIC:
case c_base_markup_attributes::ATTRIBUTE_ARIA_AUTOCOMPLETE:
case c_base_markup_attributes::ATTRIBUTE_ARIA_ACTIVE_DESCENDANT:
private $request_time;
private $response;
+ private $request_uri_relative;
+ private $request_uri_query;
+
private $content;
private $content_is_file;
private $buffer_enabled;
$this->request_time = NULL;
$this->response = array();
+ $this->request_uri_relative = NULL;
+ $this->request_uri_query = NULL;
+
$this->content = NULL;
$this->content_is_file = NULL;
$this->buffer_enabled = FALSE;
unset($this->request_time);
unset($this->response);
+ unset($this->request_uri_relative);
+ unset($this->request_uri_query);
+
unset($this->content);
unset($this->content_is_file);
unset($this->buffer_enabled);
}
/**
+ * Return the relative part of the request URI that is also relative to the base path.
+ *
+ * @param string $base_path
+ * The base_path to remove from the request uri.
+ * @param, bool $with_query
+ * (optional) If TRUE, the query is appended to the string.
+ * If FALSE, the query is ommitted.
+ *
+ * @return c_base_return_string
+ * A string is always returned.
+ * A string with error bit set is returned on error.
+ */
+ public function get_request_uri_relative($base_path, $with_query = FALSE) {
+ if (!is_string($base_path)) {
+ $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'base_path', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_value('', 'c_base_return_string', $error);
+ }
+
+ if (!is_bool($with_query)) {
+ $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'with_query', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_value('', 'c_base_return_string', $error);
+ }
+
+ if (is_string($this->request_uri_relative)) {
+ if ($with_query) {
+ return c_base_return_string::s_new($this->request_uri_relative . '?' . $this->request_uri_query);
+ }
+
+ return c_base_return_string::s_new($this->request_uri_relative);
+ }
+
+ $request_uri = $this->get_request(c_base_http::REQUEST_URI)->get_value_exact();
+ if (!isset($request_uri['defined']) || !$request_uri['defined']) {
+ unset($request_uri);
+ return c_base_return_string::s_new('');
+ }
+
+ // strip the base path from the requested uri.
+ if (strlen($base_path) > 0) {
+ $request_uri['data']['path'] = preg_replace('@^' . preg_quote($base_path, '@') . '@i', '', $request_uri['data']['path']);
+ $request_uri['data']['path'] = preg_replace('@/$@', '', $request_uri['data']['path']);
+ }
+
+ $this->request_uri_relative = $request_uri['data']['path'];
+ $this->request_uri_query = '';
+
+ if (is_string($request_uri['data']['query'])) {
+ $this->request_uri_query = http_build_query($request_uri['data']['query']);
+ }
+ unset($request_uri);
+
+ if ($with_query) {
+ return c_base_return_string::s_new($this->request_uri_relative . '?' . $this->request_uri_query);
+ }
+
+ return c_base_return_string::s_new($this->request_uri_relative);
+ }
+
+ /**
* Get the HTTP response array.
*
* Load the entire HTTP response array or a specific response field.
const ATTRIBUTE_ARIA_VALUE_MINIMIM = 309; // text
const ATTRIBUTE_ARIA_VALUE_NOW = 310; // text
const ATTRIBUTE_ARIA_VALUE_TEXT = 311; // text
+
+ // xml attributes
+ const ATTRIBUTE_XLINK_SHOW = 312; // text
+ const ATTRIBUTE_XLINK_ACTUATE = 313; // text
+ const ATTRIBUTE_XLINK_HREF = 314; // text
}
/**
}
break;
+ case c_base_markup_attributes::ATTRIBUTE_XLINK_SHOW:
+ case c_base_markup_attributes::ATTRIBUTE_XLINK_ACTUATE:
+ case c_base_markup_attributes::ATTRIBUTE_XLINK_HREF:
+ if (!is_string($value)) {
+ return new c_base_return_false();
+ }
+ break;
+
case c_base_markup_attributes::ATTRIBUTE_ASYNCHRONOUS:
case c_base_markup_attributes::ATTRIBUTE_ATTRIBUTE_NAME:
case c_base_markup_attributes::ATTRIBUTE_AUTO_COMPLETE:
case c_base_markup_attributes::ATTRIBUTE_ARIA_VALUE_TEXT:
return c_base_return_string::s_new($this->attributes[$attribute]);
+ case c_base_markup_attributes::ATTRIBUTE_XLINK_SHOW:
+ case c_base_markup_attributes::ATTRIBUTE_XLINK_ACTUATE:
+ case c_base_markup_attributes::ATTRIBUTE_XLINK_HREF:
+ return c_base_return_string::s_new($this->attributes[$attribute]);
+
case c_base_markup_attributes::ATTRIBUTE_ASYNCHRONOUS:
case c_base_markup_attributes::ATTRIBUTE_ATTRIBUTE_NAME:
case c_base_markup_attributes::ATTRIBUTE_AUTO_COMPLETE:
case c_base_mime::TYPE_UNKNOWN:
case c_base_mime::TYPE_PROVIDED:
case c_base_mime::TYPE_STREAM:
- case c_base_mime::TYPE_MULTIPART:
case c_base_mime::TYPE_TEXT_PLAIN:
case c_base_mime::TYPE_TEXT_HTML:
case c_base_mime::TYPE_TEXT_RSS:
const TYPE_AUDIO = 3000;
const TYPE_AUDIO_WAV = 3001;
const TYPE_AUDIO_OGG = 3002;
- const TYPE_AUDIO_SPEEX = 3003;
- const TYPE_AUDIO_FLAC = 3004;
- const TYPE_AUDIO_MP3 = 3005;
- const TYPE_AUDIO_MP4 = 3006;
- const TYPE_AUDIO_MIDI = 3007;
- const TYPE_AUDIO_BASIC = 3008;
+ const TYPE_AUDIO_OPUS = 3003;
+ const TYPE_AUDIO_SPEEX = 3004;
+ const TYPE_AUDIO_FLAC = 3005;
+ const TYPE_AUDIO_MP3 = 3006;
+ const TYPE_AUDIO_MP4 = 3007;
+ const TYPE_AUDIO_MIDI = 3008;
+ const TYPE_AUDIO_BASIC = 3009;
const TYPE_VIDEO = 4000;
const TYPE_VIDEO_MPEG = 4001;
self::TYPE_AUDIO => array('audio/*'),
self::TYPE_AUDIO_WAV => array('audio/wav'),
self::TYPE_AUDIO_OGG => array('audio/ogg'),
+ self::TYPE_AUDIO_OPUS => array('audio/opus'),
self::TYPE_AUDIO_SPEEX => array('audio/speex'),
self::TYPE_AUDIO_FLAC => array('audio/flac'),
self::TYPE_AUDIO_MP3 => array('audio/mpeg'),
if (is_null($category)) {
$result = NULL;
- if (array_key_exists($id, self::$s_names_basic)) {
- return c_base_return_array::s_new(self::$s_names_basic[$id]);
+ if (array_key_exists($id, self::$s_names_provided)) {
+ return c_base_return_array::s_new(self::$s_names_provided[$id]);
}
if (array_key_exists($id, self::$s_names_text)) {
}
if ($category == self::CATEGORY_PROVIDED) {
- if (array_key_exists($id, self::$s_names_basic)) {
- return c_base_return_array::s_new(self::$s_names_basic[$id]);
+ if (array_key_exists($id, self::$s_names_provided)) {
+ return c_base_return_array::s_new(self::$s_names_provided[$id]);
}
}
elseif ($category == self::CATEGORY_TEXT) {
c_base_http::HTTP_METHOD_OPTIONS => c_base_http::HTTP_METHOD_OPTIONS,
);
+ private const DEFAULT_SANITIZE_HTML = array(
+ 'flags' => ENT_HTML5 | ENT_NOQUOTES | ENT_DISALLOWED | ENT_SUBSTITUTE,
+ 'encoding' => 'UTF-8',
+ );
+
protected $id_group = NULL;
protected $is_content = NULL;
protected $include_name = NULL;
protected $allowed_methods = NULL;
+ protected $sanitize_html = NULL;
+
/**
* Class constructor.
$this->include_name = NULL;
$this->allowed_methods = self::DEFAULT_ALLOWED_METHODS;
+ $this->sanitize_html = self::DEFAULT_SANITIZE_HTML;
}
/**
unset($this->include_name);
unset($this->allowed_methods);
+ unset($this->sanitize_html);
parent::__destruct();
}
$path->set_value($field_path);
if (is_bool($is_private)) {
- $path->set_is_private($is_private);
+ $path->is_private($is_private);
}
else {
- $path->set_is_private(TRUE);
+ $path->is_private(TRUE);
}
- $path->set_is_content(TRUE);
+ $path->is_content(TRUE);
$timestamp_session = c_base_defaults_global::s_get_timestamp_session();
$path->set_date_created($timestamp_session);
$path->set_field_destination($field_destination);
if (is_bool($is_private)) {
- $path->set_is_private($is_private);
+ $path->is_private($is_private);
}
else {
- $path->set_is_private(TRUE);
+ $path->is_private(TRUE);
}
- $path->set_is_alias(TRUE);
+ $path->is_alias(TRUE);
$timestamp_session = c_base_defaults_global::s_get_timestamp_session();
$path->set_date_created($timestamp_session);
$path->set_field_response_code($field_response_code);
if (is_bool($is_private)) {
- $path->set_is_private($is_private);
+ $path->is_private($is_private);
}
else {
- $path->set_is_private(TRUE);
+ $path->is_private(TRUE);
}
- $path->set_is_redirect(TRUE);
+ $path->is_redirect(TRUE);
$timestamp_session = c_base_defaults_global::s_get_timestamp_session();
$path->set_date_created($timestamp_session);
*
* @return c_base_return_status
* TRUE on success, FALSE otherwise.
+ * FALSE with error bit set is returned on error.
*/
public function set_id_group($id_group) {
if (!is_int($id_group) || $id_group < 0) {
}
/**
- * Assigns the is content boolean setting.
- *
- * @param bool $is_content
- * The is content boolean associated with the path.
- *
- * @return c_base_return_status
- * TRUE on success, FALSE otherwise.
- */
- public function set_is_content($is_content) {
- if (!is_bool($is_content)) {
- $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'is_content', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
- return c_base_return_error::s_false($error);
- }
-
- $this->is_content = $is_content;
- return new c_base_return_true();
- }
-
- /**
- * Assigns the is alias boolean setting.
- *
- * @param bool $is_alias
- * The is alias boolean associated with the path.
- *
- * @return c_base_return_status
- * TRUE on success, FALSE otherwise.
- */
- public function set_is_alias($is_alias) {
- if (!is_bool($is_alias)) {
- $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'is_alias', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
- return c_base_return_error::s_false($error);
- }
-
- $this->is_alias = $is_alias;
- return new c_base_return_true();
- }
-
- /**
- * Assigns the is redirect boolean setting.
- *
- * @param bool $is_redirect
- * The is redirect boolean associated with the path.
- *
- * @return c_base_return_status
- * TRUE on success, FALSE otherwise.
- */
- public function set_is_redirect($is_redirect) {
- if (!is_bool($is_redirect)) {
- $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'is_redirect', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
- return c_base_return_error::s_false($error);
- }
-
- $this->is_redirect = $is_redirect;
- return new c_base_return_true();
- }
-
- /**
- * Assigns the is coded boolean setting.
- *
- * @param bool $is_coded
- * The is coded boolean associated with the path.
- *
- * @return c_base_return_status
- * TRUE on success, FALSE otherwise.
- */
- public function set_is_coded($is_coded) {
- if (!is_bool($is_coded)) {
- $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'is_coded', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
- return c_base_return_error::s_false($error);
- }
-
- $this->is_coded = $is_coded;
- return new c_base_return_true();
- }
-
- /**
- * Assigns the is dynamic boolean setting.
- *
- * @param bool $is_dynamic
- * The is dynamic boolean associated with the path.
- *
- * @return c_base_return_status
- * TRUE on success, FALSE otherwise.
- */
- public function set_is_dynamic($is_dynamic) {
- if (!is_bool($is_dynamic)) {
- $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'is_dynamic', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
- return c_base_return_error::s_false($error);
- }
-
- $this->is_dynamic = $is_dynamic;
- return new c_base_return_true();
- }
-
- /**
- * Assigns the is user boolean name setting.
- *
- * @param bool $is_user
- * The is user boolean associated with the path.
- *
- * @return c_base_return_status
- * TRUE on success, FALSE otherwise.
- */
- public function set_is_user($is_user) {
- if (!is_bool($is_user)) {
- $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'is_user', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
- return c_base_return_error::s_false($error);
- }
-
- $this->is_user = $is_user;
- return new c_base_return_true();
- }
-
- /**
- * Assigns the is private boolean setting.
- *
- * @param bool $is_private
- * The is private boolean associated with the path.
- *
- * @return c_base_return_status
- * TRUE on success, FALSE otherwise.
- */
- public function set_is_private($is_private) {
- if (!is_bool($is_private)) {
- $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'is_private', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
- return c_base_return_error::s_false($error);
- }
-
- $this->is_private = $is_private;
- return new c_base_return_true();
- }
-
- /**
- * Assigns the is locked boolean setting.
- *
- * @param bool $is_locked
- * The is locked boolean associated with the path.
- *
- * @return c_base_return_status
- * TRUE on success, FALSE otherwise.
- */
- public function set_is_locked($is_locked) {
- if (!is_bool($is_locked)) {
- $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'is_locked', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
- return c_base_return_error::s_false($error);
- }
-
- $this->is_locked = $is_locked;
- return new c_base_return_true();
- }
-
- /**
- * Assigns the is root boolean setting.
- *
- * @param bool $is_root
- * The is root boolean associated with the path.
- *
- * @return c_base_return_status
- * TRUE on success, FALSE otherwise.
- */
- public function set_is_root($is_root) {
- if (!is_bool($is_root)) {
- $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'is_root', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
- return c_base_return_error::s_false($error);
- }
-
- $this->is_root = $is_root;
- return new c_base_return_true();
- }
-
- /**
* Assigns the destination field setting.
*
* @param string|array $field_destination
*
* @return c_base_return_status
* TRUE on success, FALSE otherwise.
+ * FALSE with error bit set is returned on error.
*/
public function set_field_destination($field_destination) {
if (!is_string($field_destination) && !is_array($field_destination)) {
*
* @return c_base_return_status
* TRUE on success, FALSE otherwise.
+ * FALSE with error bit set is returned on error.
*/
public function set_field_response_code($field_response_code) {
if (!is_int($field_response_code)) {
*
* @return c_base_return_status
* TRUE on success, FALSE otherwise.
+ * FALSE with error bit set is returned on error.
*/
public function set_date_created($date_created) {
if (!is_float($date_created) && !is_int($date_created)) {
*
* @return c_base_return_status
* TRUE on success, FALSE otherwise.
+ * FALSE with error bit set is returned on error.
*/
public function set_date_changed($date_changed) {
if (!is_float($date_changed) && !is_int($date_changed)) {
*
* @return c_base_return_status
* TRUE on success, FALSE otherwise.
+ * FALSE with error bit set is returned on error.
*/
public function set_date_locked($date_locked) {
if (!is_float($date_locked) && !is_int($date_locked)) {
*
* @return c_base_return_status
* TRUE on success, FALSE otherwise.
+ * FALSE with error bit set is returned on error.
*/
public function set_include_directory($directory) {
if (!is_string($directory) && !is_null($directory)) {
*
* @return c_base_return_status
* TRUE on success, FALSE otherwise.
+ * FALSE with error bit set is returned on error.
*/
public function set_include_name($name) {
if (!is_string($name) && !is_null($name)) {
*
* @return c_base_return_status
* TRUE on success, FALSE otherwise.
+ * FALSE with error bit set is returned on error.
*/
public function set_allowed_method($method, $append = TRUE) {
if (!is_int($method)) {
*
* @return c_base_return_status
* TRUE on success, FALSE otherwise.
+ * FALSE with error bit set is returned on error.
*/
public function set_allowed_methods($methods) {
if (!is_array($methods)) {
}
/**
+ * Assign html sanitization settings.
+ *
+ * @param int|null $flags
+ * (optional) An integer representing the flags to be directly passed to htmlspecialchars().
+ * @param string|null $encoding
+ * (optional) A string representing the encodong to be directly passed to htmlspecialchars().
+ *
+ * @return c_base_return_status
+ * TRUE on success, FALSE otherwise.
+ * FALSE with error bit set is returned on error.
+ *
+ * @see: htmlspecialchars()
+ */
+ public function set_sanitize_html($flags = NULL, $encoding = NULL) {
+ if (!is_null($flags) && !is_int($flags)) {
+ $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'flags', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ if (!is_null($encoding) && !is_string($encoding)) {
+ $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'encoding', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ if (!is_array($this->sanitize_html)) {
+ $this->sanitize_html = self::DEFAULT_SANITIZE_HTML;
+ }
+
+ if (!is_null($flags)) {
+ $this->sanitize_html['flags'] = $flags;
+ }
+
+ if (!is_null($encoding)) {
+ $this->sanitize_html['encoding'] = $encoding;
+ }
+
+ return new c_base_return_true();
+ }
+
+ /**
* Gets the ID sort setting.
*
* @return c_base_return_int
return c_base_return_int::s_new($this->id_group);
}
-
/**
- * Gets the is content boolean setting.
+ * Get or Assign the is content boolean setting.
*
- * @return c_base_return_bool
- * Is content on success.
- * Error bit is set on error.
+ * @param bool|null $is_content
+ * When a boolean, this is assigned as the current is content setting.
+ * When NULL, the current setting is returned.
+ *
+ * @return c_base_return_bool|c_base_return_status
+ * When $is_content is NULL, is content boolean setting on success.
+ * FALSE with error bit is set on error.
*/
- public function get_is_content() {
- if (!is_bool($this->is_content)) {
- $this->is_content = FALSE;
+ public function is_content($is_content = NULL) {
+ if (!is_null($is_content) && !is_bool($is_content)) {
+ $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'is_content', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ if (is_null($is_content)) {
+ if (!is_bool($this->is_content)) {
+ $this->is_content = FALSE;
+ }
+
+ if ($this->is_content) {
+ return new c_base_return_true();
+ }
+
+ return new c_base_return_false();
}
- return c_base_return_bool::s_new($this->is_content);
+ $this->is_content = $is_content;
+ return new c_base_return_true();
}
/**
- * Gets the is alias boolean setting.
+ * Get or Assign the is alias boolean setting.
*
- * @return c_base_return_bool
- * Is alias on success.
- * Error bit is set on error.
+ * @param bool|null $is_alias
+ * When a boolean, this is assigned as the current is alias setting.
+ * When NULL, the current setting is returned.
+ *
+ * @return c_base_return_bool|c_base_return_status
+ * When $is_alias is NULL, is alias boolean setting on success.
+ * FALSE with error bit is set on error.
*/
- public function get_is_alias() {
- if (!is_bool($this->is_alias)) {
- $this->is_alias = FALSE;
+ public function is_alias($is_alias = NULL) {
+ if (!is_null($is_alias) && !is_bool($is_alias)) {
+ $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'is_alias', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
}
- return c_base_return_bool::s_new($this->is_alias);
+ if (is_null($is_alias)) {
+ if (!is_bool($this->is_alias)) {
+ $this->is_alias = FALSE;
+ }
+
+ if ($this->is_alias) {
+ return new c_base_return_true();
+ }
+
+ return new c_base_return_false();
+ }
+
+ $this->is_alias = $is_alias;
+ return new c_base_return_true();
}
/**
- * Gets the is redirect boolean setting.
+ * Get or Assign the is redirect boolean setting.
*
- * @return c_base_return_bool
- * Is redirect on success.
- * Error bit is set on error.
+ * @param bool|null $is_redirect
+ * When a boolean, this is assigned as the current is redirect setting.
+ * When NULL, the current setting is returned.
+ *
+ * @return c_base_return_bool|c_base_return_status
+ * When $is_redirect is NULL, is redirect boolean setting on success.
+ * FALSE with error bit is set on error.
*/
- public function get_is_redirect() {
- if (!is_bool($this->is_redirect)) {
- $this->is_redirect = FALSE;
+ public function is_redirect($is_redirect = NULL) {
+ if (!is_null($is_redirect) && !is_bool($is_redirect)) {
+ $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'is_redirect', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
+ if (is_null($is_redirect)) {
+ if (!is_bool($this->is_redirect)) {
+ $this->is_redirect = FALSE;
+ }
+
+ if ($this->is_redirect) {
+ return new c_base_return_true();
+ }
+
+ return new c_base_return_false();
}
- return c_base_return_bool::s_new($this->is_redirect);
+ $this->is_redirect = $is_redirect;
+ return new c_base_return_true();
}
/**
- * Gets the is private boolean setting.
+ * Get or Assign the is private boolean setting.
*
- * @return c_base_return_bool
- * Is private on success.
- * Error bit is set on error.
+ * @param bool|null $is_private
+ * When a boolean, this is assigned as the current is private setting.
+ * When NULL, the current setting is returned.
+ *
+ * @return c_base_return_bool|c_base_return_status
+ * When $is_private is NULL, is private boolean setting on success.
+ * FALSE with error bit is set on error.
*/
- public function get_is_private() {
- if (!is_bool($this->is_private)) {
- $this->is_private = FALSE;
+ public function is_private($is_private = NULL) {
+ if (!is_null($is_private) && !is_bool($is_private)) {
+ $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'is_private', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
}
- return c_base_return_bool::s_new($this->is_private);
+ if (is_null($is_private)) {
+ if (!is_bool($this->is_private)) {
+ $this->is_private = FALSE;
+ }
+
+ if ($this->is_private) {
+ return new c_base_return_true();
+ }
+
+ return new c_base_return_false();
+ }
+
+ $this->is_private = $is_private;
+ return new c_base_return_true();
}
/**
- * Gets the is locked boolean setting.
+ * Get or Assign the is locked boolean setting.
*
- * @return c_base_return_bool
- * Is locked on success.
- * Error bit is set on error.
+ * @param bool|null $is_locked
+ * When a boolean, this is assigned as the current is locked setting.
+ * When NULL, the current setting is returned.
+ *
+ * @return c_base_return_bool|c_base_return_status
+ * When $is_locked is NULL, is locked boolean setting on success.
+ * FALSE with error bit is set on error.
*/
- public function get_is_locked() {
- if (!is_bool($this->is_locked)) {
- $this->is_locked = FALSE;
+ public function is_locked($is_locked = NULL) {
+ if (!is_null($is_locked) && !is_bool($is_locked)) {
+ $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'is_locked', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
}
- return c_base_return_bool::s_new($this->is_locked);
+ if (is_null($is_locked)) {
+ if (!is_bool($this->is_locked)) {
+ $this->is_locked = FALSE;
+ }
+
+ if ($this->is_locked) {
+ return new c_base_return_true();
+ }
+
+ return new c_base_return_false();
+ }
+
+ $this->is_locked = $is_locked;
+ return new c_base_return_true();
}
/**
- * Gets the is root boolean setting.
+ * Get or Assign the is root boolean setting.
*
- * @return c_base_return_bool
- * Is root on success.
- * Error bit is set on error.
+ * @param bool|null $is_root
+ * When a boolean, this is assigned as the current is root setting.
+ * When NULL, the current setting is returned.
+ *
+ * @return c_base_return_bool|c_base_return_status
+ * When $is_root is NULL, is root boolean setting on success.
+ * FALSE with error bit is set on error.
*/
- public function get_is_root() {
- if (!is_bool($this->is_root)) {
- $this->is_root = FALSE;
+ public function is_root($is_root = NULL) {
+ if (!is_null($is_root) && !is_bool($is_root)) {
+ $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'is_root', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
}
- return c_base_return_bool::s_new($this->is_root);
+ if (is_null($is_root)) {
+ if (!is_bool($this->is_root)) {
+ $this->is_root = FALSE;
+ }
+
+ if ($this->is_root) {
+ return new c_base_return_true();
+ }
+
+ return new c_base_return_false();
+ }
+
+ $this->is_root = $is_root;
+ return new c_base_return_true();
}
/**
}
/**
+ * 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
return $method;
}
+
+ /**
+ * Replace all occurences of arguments within string.
+ *
+ * Perform sanitization based on the first character.
+ * If first character is ':', do not perform sanitization.
+ * If first character is '@', santize as HTML text.
+ *
+ * I recommend wrapping placeholders in '{' and '}' to help enforce uniqueness.
+ * - For example the string ':words' could be confused with two different placeholders: ':word' and ':words'.
+ * - By using ':{words}' and ':{word}', there there should be fewer chances of mixups.
+ *
+ * @param string &$string
+ * The string to perform replacements on.
+ * @param array $arguments
+ * An array of replacement arguments.
+ *
+ * @see: htmlspecialchars()
+ * @see: str_replace()
+ */
+ protected function pr_process_replacements(&$string, $arguments) {
+ foreach ($arguments as $place_holder => $replacement) {
+ $type = mb_substr($place_holder, 0, 1);
+
+ if ($type == ':') {
+ $sanitized = $replacement;
+ }
+ elseif ($type == '@') {
+ $sanitized = htmlspecialchars($replacement, $this->sanitize_html['flags'], $this->sanitize_html['encoding']);
+ }
+ else {
+ unset($type);
+
+ // do not perform replacements on unknown placeholders.
+ continue;
+ }
+ unset($type);
+
+ $string = str_replace($place_holder, $sanitized, $string);
+ }
+ unset($place_holder);
+ unset($replacement);
+ }
}
/**
$this->problems = NULL;
- $this->logged_in = TRUE;
+ $this->logged_in = FALSE;
}
/**
return c_base_return_error::s_false($error);
}
- $this->cookie = $cookie;
+ $this->cookie = clone($cookie);
return new c_base_return_true();
}
}
/**
- * Returns the stored system name.
+ * Returns the cookie associated with this session.
*
* @return c_base_cookie|c_base_return_null
* The session cookie or NULL if undefined.
return new c_base_return_null();
}
- return $this->cookie;
+ return clone($this->cookie);
}
/**
* If null, this is variable ignored.
* @param array|null $classes
* (optional) An array of strings representing additional classes to append.
+ * @param string|null $text
+ * (optional) Text to assign the tag.
*
* @return c_base_markup_tag|c_base_return_status
* A newly created tag is returned on success.
* FALSE with the error bit set is returned on error.
*/
- public static function s_create_tag($type, $id = NULL, $classes = NULL) {
+ public static function s_create_tag($type, $id = NULL, $classes = NULL, $text = NULL) {
if (!is_null($id) && !is_string($id)) {
$error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'id', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
return c_base_return_error::s_false($error);
return c_base_return_error::s_false($error);
}
+ if (!is_null($text) && !is_string($text)) {
+ $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'text', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
+ return c_base_return_error::s_false($error);
+ }
+
$tag = new c_base_markup_tag();
$result = $tag->set_type($type);
$tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_CLASS, $class);
unset($class);
+ if (is_string($text)) {
+ $tag->set_text($text);
+ }
+
return $tag;
}
/**
+ * Create a tag with the supplied text.
+ *
+ * @param int $type
+ * A c_base_markup_tag type id.
+ * @param string $text
+ * Text to assign the tag.
+ *
+ * @return c_base_markup_tag|c_base_return_status
+ * A newly created tag is returned on success.
+ * FALSE with the error bit set is returned on error.
+ *
+ * @see: self::s_create_tag()
+ */
+ public static function s_create_tag_text($type, $text) {
+ return self::s_create_tag($type, NULL, NULL, $text);
+ }
+
+ /**
* Assign the markup html to be themed.
*
* @param c_base_html $html
$markup .= '</u>';
}
elseif ($type === c_base_markup_tag::TYPE_UNORDERED_LIST) {
- $markup .= '<a' . $this->p_render_markup_attributes_global($tag) . $this->p_render_markup_attributes_event_handler($tag) . '>';
+ $markup .= '<ul' . $this->p_render_markup_attributes_global($tag) . $this->p_render_markup_attributes_event_handler($tag) . '>';
$markup .= $tag->get_text()->get_value_exact();
$markup .= $child_markup;
- $markup .= '</a>';
+ $markup .= '</ul>';
}
elseif ($type === c_base_markup_tag::TYPE_URL) {
$markup .= '<input' . $this->p_render_markup_attributes_global($tag) . $this->p_render_markup_attributes_input($tag, 'url') . $this->p_render_markup_attributes_event_handler($tag) . '>';
// attribute: type
$attribute = $tag->get_attribute(c_base_markup_attributes::ATTRIBUTE_TYPE)->get_value_exact();
if (!empty($attribute)) {
- $mime_types = c_base_mime::s_get_names_by_id($attribute);
+ $mime_types = c_base_mime::s_get_names_by_id($attribute)->get_value();
if (is_array($mime_types)) {
// use the first mime type available.
The following is the URL path naming strategy that I intend to use on my projects.
Paths that begin with the following:
- /a/ = Administrative/Management/Logged-In Paths.
+ /a/ = Administrative Paths.
/c/ = Cache Paths.
/d/ = Data Paths, such as RSS Feeds.
/f/ = File Paths.
/s/ = Form Submit Paths.
+ /m/ = Management / System Paths.
/t/ = Theme Paths.
/u/ = User Paths (similar to /a/, but focused on users or custom user content).
/x/ = Ajax Paths.
- /f/c/% - Load file '%' by file checksum.
- /f/s/% - Load checksum for file '%'.
+Example /m/ paths:
+- /m/dashboard - Dashboard
+- /m/content - Listing of site content.
+- /m/logs - Listing of site logs.
+
Example /s/ paths:
- /s/login - Login form
- /s/logout - Logout form
require_once('program/reservation/reservation_database.php');
require_once('program/reservation/reservation_session.php');
require_once('program/reservation/reservation_paths.php');
-require_once('program/reservation/reservation_build.php');
/**
* Load all custom settings.
// base settings
$settings['base_scheme'] = 'https';
$settings['base_host'] = 'localhost';
- $settings['base_path'] = $settings['cookie_path'];
+ $settings['base_path'] = $settings['cookie_path']; // must end in a trailing slash.
if (!isset($_SERVER["HTTPS"])) {
$settings['base_scheme'] = 'http';
}
+ // The HTML tag <p>, represents a paragraph.
+ // However, many sites, services, and developers incorrectly use it to represent text.
+ // The definition of the word 'paragraph' contradicts this current usage of the HTML tag <p>.
+ // It is also important to note that many browsers will alter the content of the <p> tag to remove blocks of any kind, such as <ul>.
+ // The <span> tag does not seem to have this issue.
+ // Therefore, the use of HTML <p> tag is consider non-safe and likely to cause problems with formatting (because client browsers alter the HTML).
+ // This provides a way to still use <p> tags despite the implementation, usage, and context flaws.
+ $settings['standard_issue-use_p_tags'] = FALSE;
+
// default supported languages.
c_base_defaults_global::s_set_languages(new c_base_language_limited());
+ // default time related settings.
+ c_base_defaults_global::s_get_timestamp_session(TRUE);
+ c_base_defaults_global::s_set_timezone('America/Chicago');
+
+
return $settings;
}
function reservation_process_request(&$http, &$database, &$session, &$settings) {
$session_user = $session->get_name()->get_value_exact();
if (is_null($session_user)) {
- $logged_in = FALSE;
+ $session->set_logged_in(FALSE);
// @todo: delete old cookies, if they expire.
$cookie_login = $session->get_cookie();
unset($user_name);
unset($password);
- $logged_in = FALSE;
+ $session->set_logged_in(FALSE);
}
else {
- $logged_in = TRUE;
+ $session->set_logged_in(TRUE);
reservation_database_string($database, $settings, $user_name, $password);
unset($user_name);
}
$paths = new c_reservation_paths();
- $executed = $paths->reservation_process_path($http, $database, $session, $settings, $logged_in);
- unset($logged_in);
+ $executed = $paths->reservation_process_path($http, $database, $session, $settings);
unset($paths);
return $executed->get_output();
* Provides path handler for the access denied pages.
*/
-require_once('common/base/classes/base_error.php');
require_once('common/base/classes/base_return.php');
-require_once('common/base/classes/base_path.php');
-require_once('common/base/classes/base_html.php');
-require_once('common/base/classes/base_cookie.php');
-require_once('common/base/classes/base_session.php');
+require_once('common/base/classes/base_http_status.php');
require_once('common/theme/classes/theme_html.php');
-class c_reservation_path_access_denied extends c_base_path {
+class c_reservation_path_access_denied extends c_reservation_path {
/**
* Implements do_execute().
*/
return $executed;
}
+ $this->pr_assign_defaults($settings);
- // Wrapper
- $wrapper = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_SECTION, c_base_defaults_global::CSS_BASE . c_base_defaults_global::CSS_BASE . 'content-wrapper', array(c_base_defaults_global::CSS_BASE . 'error-path', 'error-path-access_denied', 'error-path-access_denied'));
-
-
- // H1
- $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_H1);
- $tag->set_text($this->pr_get_text(0));
- $wrapper->set_tag($tag);
- unset($tag);
-
-
- // Content
- $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_DIVIDER);
- $tag->set_text($this->pr_get_text(1));
- $wrapper->set_tag($tag);
- unset($tag);
+ $wrapper = $this->pr_create_tag_wrapper();
+ $wrapper->set_tag($this->pr_create_tag_title(0));
+ $wrapper->set_tag($this->pr_create_tag_text_block(1));
// initialize the content as HTML.
- $html = c_reservation_build::s_create_html($http, $database, $session, $settings, $this->pr_get_title());
+ $html = $this->pr_create_html($http, $database, $session, $settings);
$html->set_tag($wrapper);
unset($wrapper);
- $executed = new c_base_path_executed();
$executed->set_output($html);
unset($html);
}
/**
- * Load the title text associated with this page.
- *
- * This is provided here as a means for a language class to override with a custom language for the title.
- *
- * @return string|null
- * A string is returned as the custom title.
- * NULL is returned to enforce default title.
- */
- protected function pr_get_title() {
- return NULL;
- }
-
- /**
- * Load text for a supported language.
- *
- * @param int $index
- * A number representing which block of text to return.
+ * Implements pr_get_text().
*/
- protected function pr_get_text($code) {
+ protected function pr_get_text($code, $arguments = array()) {
+ $string = '';
switch ($code) {
case 0:
- return 'Access Denied';
+ $string = 'Access Denied';
+ break;
case 1:
- return 'You are not authorized to access this resource.';
+ $string = 'You are not authorized to access this resource.';
+ break;
+ }
+
+ if (!empty($arguments)) {
+ $this->pr_process_replacements($string, $arguments);
}
- return '';
+ return $string;
}
}
* Provides path handler for the not found pages.
*/
-require_once('common/base/classes/base_error.php');
require_once('common/base/classes/base_return.php');
-require_once('common/base/classes/base_path.php');
-require_once('common/base/classes/base_html.php');
-require_once('common/base/classes/base_cookie.php');
-require_once('common/base/classes/base_session.php');
+require_once('common/base/classes/base_http_status.php');
require_once('common/theme/classes/theme_html.php');
-class c_reservation_path_bad_method extends c_base_path {
+class c_reservation_path_bad_method extends c_reservation_path {
/**
* Implements do_execute().
*/
return $executed;
}
+ $this->pr_assign_defaults($settings);
- // Wrapper
- $wrapper = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_SECTION, c_base_defaults_global::CSS_BASE . c_base_defaults_global::CSS_BASE . 'content-wrapper', array(c_base_defaults_global::CSS_BASE . 'error-path', 'error-path', 'error-path-bad_method'));
-
-
- // H1
- $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_H1);
- $tag->set_text($this->pr_get_text(0));
- $wrapper->set_tag($tag);
- unset($tag);
-
-
- // Content
- $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_DIVIDER);
- $tag->set_text($this->pr_get_text(1));
- $wrapper->set_tag($tag);
- unset($tag);
+ $wrapper = $this->pr_create_tag_wrapper();
+ $wrapper->set_tag($this->pr_create_tag_title(0));
+ $wrapper->set_tag($this->pr_create_tag_text_block(1));
// initialize the content as HTML.
- $html = c_reservation_build::s_create_html($http, $database, $session, $settings, $this->pr_get_title());
+ $html = $this->pr_create_html($http, $database, $session, $settings);
$html->set_tag($wrapper);
unset($wrapper);
- $executed = new c_base_path_executed();
$executed->set_output($html);
unset($html);
}
/**
- * Load the title text associated with this page.
- *
- * This is provided here as a means for a language class to override with a custom language for the title.
- *
- * @return string|null
- * A string is returned as the custom title.
- * NULL is returned to enforce default title.
- */
- protected function pr_get_title() {
- return NULL;
- }
-
- /**
- * Load text for a supported language.
- *
- * @param int $index
- * A number representing which block of text to return.
+ * Implements pr_get_text().
*/
- protected function pr_get_text($code) {
+ protected function pr_get_text($code, $arguments = array()) {
+ $string = '';
switch ($code) {
case 0:
- return 'Bad Method';
+ $string = 'Bad Method';
+ break;
case 1:
- return 'The provided HTTP request method is either unsupported or invalid for the request path.';
+ $string = 'The provided HTTP request method is either unsupported or invalid for the request path.';
+ break;
+ }
+
+ if (!empty($arguments)) {
+ $this->pr_process_replacements($string, $arguments);
}
- return '';
+ return $string;
}
}
/**
* Implements pr_get_title().
*/
- protected function pr_get_title() {
+ protected function pr_get_title($arguments = array()) {
return '予約システム';
}
/**
* Implements pr_get_text().
*/
- protected function pr_get_text($code) {
+ protected function pr_get_text($code, $arguments = array()) {
+ $string = '';
switch ($code) {
case 0:
- return 'アクセス拒否';
+ $string = 'アクセス拒否';
+ break;
case 1:
- return 'このリソースにアクセスする権限がありません。';
+ $string = 'このリソースにアクセスする権限がありません。';
+ break;
}
- return '';
+ if (!empty($arguments)) {
+ $this->pr_process_replacements($string, $arguments);
+ }
+
+ return $string;
}
}
/**
* Implements pr_get_title().
*/
- protected function pr_get_title() {
+ protected function pr_get_title($arguments = array()) {
return '予約システム';
}
/**
* Implements pr_get_text().
*/
- protected function pr_get_text($code) {
+ protected function pr_get_text($code, $arguments = array()) {
+ $string = '';
switch ($code) {
case 0:
- return '悪い方法';
+ $string = '悪い方法';
+ break;
case 1:
- return '指定されたHTTP要求メソッドは、要求パスに対してサポートされていないか無効です。';
+ $string = '指定されたHTTP要求メソッドは、要求パスに対してサポートされていないか無効です。';
+ break;
}
- return '';
+ if (!empty($arguments)) {
+ $this->pr_process_replacements($string, $arguments);
+ }
+
+ return $string;
}
}
/**
* Implements pr_get_title().
*/
- protected function pr_get_title() {
+ protected function pr_get_title($arguments = array()) {
return '予約システム';
}
/**
* Implements pr_get_text().
*/
- protected function pr_get_text($code) {
+ protected function pr_get_text($code, $arguments = array()) {
+ $string = '';
switch ($code) {
case 0:
- return '見つかりません';
+ $string = '見つかりません';
+ break;
case 1:
- return 'リクエストしたページは利用できません。';
+ $string = 'リクエストしたページは利用できません。';
+ break;
}
- return '';
+ if (!empty($arguments)) {
+ $this->pr_process_replacements($string, $arguments);
+ }
+
+ return $string;
}
}
/**
* Implements pr_get_title().
*/
- protected function pr_get_title() {
+ protected function pr_get_title($arguments = array()) {
return '予約システム';
}
/**
* Implements pr_get_text().
*/
- protected function pr_get_text($code) {
+ protected function pr_get_text($code, $arguments = array()) {
+ $string = '';
switch ($code) {
case 0:
- return 'サーバーエラー';
+ $string = 'サーバーエラー';
+ break;
case 1:
- return 'リクエストの処理中に問題が発生しました。しばらくしてからもう一度お試しください。';
+ $string = 'リクエストの処理中に問題が発生しました。しばらくしてからもう一度お試しください。';
+ break;
}
- return '';
+ if (!empty($arguments)) {
+ $this->pr_process_replacements($string, $arguments);
+ }
+
+ return $string;
}
}
* Provides path handler for the not found pages.
*/
-require_once('common/base/classes/base_error.php');
require_once('common/base/classes/base_return.php');
-require_once('common/base/classes/base_path.php');
-require_once('common/base/classes/base_html.php');
-require_once('common/base/classes/base_cookie.php');
-require_once('common/base/classes/base_session.php');
+require_once('common/base/classes/base_http_status.php');
require_once('common/theme/classes/theme_html.php');
-class c_reservation_path_not_found extends c_base_path {
+class c_reservation_path_not_found extends c_reservation_path {
/**
* Implements do_execute().
*/
return $executed;
}
+ $this->pr_assign_defaults($settings);
- // Wrapper
- $wrapper = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_SECTION, c_base_defaults_global::CSS_BASE . c_base_defaults_global::CSS_BASE . 'content-wrapper', array(c_base_defaults_global::CSS_BASE . 'error-path', 'error-path', 'error-path-not_found'));
-
-
- // H1
- $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_H1);
- $tag->set_text($this->pr_get_text(0));
- $wrapper->set_tag($tag);
- unset($tag);
-
-
- // Content
- $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_DIVIDER);
- $tag->set_text($this->pr_get_text(1));
- $wrapper->set_tag($tag);
- unset($tag);
+ $wrapper = $this->pr_create_tag_wrapper();
+ $wrapper->set_tag($this->pr_create_tag_title(0));
+ $wrapper->set_tag($this->pr_create_tag_text_block(1));
// initialize the content as HTML.
- $html = c_reservation_build::s_create_html($http, $database, $session, $settings, $this->pr_get_title());
+ $html = $this->pr_create_html($http, $database, $session, $settings);
$html->set_tag($wrapper);
unset($wrapper);
- $executed = new c_base_path_executed();
$executed->set_output($html);
unset($html);
}
/**
- * Load the title text associated with this page.
- *
- * This is provided here as a means for a language class to override with a custom language for the title.
- *
- * @return string|null
- * A string is returned as the custom title.
- * NULL is returned to enforce default title.
- */
- protected function pr_get_title() {
- return NULL;
- }
-
- /**
- * Load text for a supported language.
- *
- * @param int $index
- * A number representing which block of text to return.
+ * Implements pr_get_text().
*/
- protected function pr_get_text($code) {
+ protected function pr_get_text($code, $arguments = array()) {
+ $string = '';
switch ($code) {
case 0:
- return 'Page Not Found';
+ $string = 'Page Not Found';
+ break;
case 1:
- return 'The page you requested is not available.';
+ $string = 'The page you requested is not available.';
+ break;
+ }
+
+ if (!empty($arguments)) {
+ $this->pr_process_replacements($string, $arguments);
}
- return '';
+ return $string;
}
}
--- /dev/null
+<?php
+/**
+ * @file
+ * Provides path handler for the server rror pages.
+ */
+
+require_once('common/base/classes/base_return.php');
+
+/**
+ * Provide the HTTP options response.
+ *
+ * This does not provide any content body.
+ */
+final class c_reservation_path_options_method extends c_reservation_path {
+
+ /**
+ * Implements do_execute().
+ */
+ public function do_execute(&$http, &$database, &$session, $settings = array()) {
+ // the parent function performs validation on the parameters.
+ $executed = parent::do_execute($http, $database, $session, $settings);
+ if (c_base_return::s_has_error($executed)) {
+ return $executed;
+ }
+
+
+ // assign HTTP response status.
+ $allowed_methods = $this->allowed_methods;
+ $allowed_method = array_shift($allowed_methods);
+ $http->set_response_allow($allowed_method, TRUE);
+
+ if (!empty($allowed_methods)) {
+ foreach ($allowed_methods as $allowed_method) {
+ $http->set_response_allow($allowed_method);
+ }
+ }
+ unset($allowed_method);
+ unset($allowed_methods);
+
+ return $executed;
+ }
+
+ /**
+ * Implements pr_get_text().
+ */
+ protected function pr_get_text($code, $arguments = array()) {
+ return '';
+ }
+}
* Provides path handler for the server rror pages.
*/
-require_once('common/base/classes/base_error.php');
require_once('common/base/classes/base_return.php');
-require_once('common/base/classes/base_path.php');
-require_once('common/base/classes/base_html.php');
-require_once('common/base/classes/base_cookie.php');
-require_once('common/base/classes/base_session.php');
+require_once('common/base/classes/base_http_status.php');
require_once('common/theme/classes/theme_html.php');
-class c_reservation_path_server_error extends c_base_path {
+class c_reservation_path_server_error extends c_reservation_path {
/**
* Implements do_execute().
*/
return $executed;
}
+ $this->pr_assign_defaults($settings);
- // Wrapper
- $wrapper = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_SECTION, c_base_defaults_global::CSS_BASE . c_base_defaults_global::CSS_BASE . 'content-wrapper', array(c_base_defaults_global::CSS_BASE . 'error-path', 'error-path', 'error-path-not_found'));
-
-
- // H1
- $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_H1);
- $tag->set_text($this->pr_get_text(0));
- $wrapper->set_tag($tag);
- unset($tag);
-
-
- // Content
- $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_DIVIDER);
- $tag->set_text($this->pr_get_text(1));
- $wrapper->set_tag($tag);
- unset($tag);
+ $wrapper = $this->pr_create_tag_wrapper();
+ $wrapper->set_tag($this->pr_create_tag_title(0));
+ $wrapper->set_tag($this->pr_create_tag_text_block(1));
// initialize the content as HTML.
- $html = c_reservation_build::s_create_html($http, $database, $session, $settings, $this->pr_get_title());
+ $html = $this->pr_create_html($http, $database, $session, $settings);
$html->set_tag($wrapper);
unset($wrapper);
- $executed = new c_base_path_executed();
$executed->set_output($html);
unset($html);
}
/**
- * Load the title text associated with this page.
- *
- * This is provided here as a means for a language class to override with a custom language for the title.
- *
- * @return string|null
- * A string is returned as the custom title.
- * NULL is returned to enforce default title.
- */
- protected function pr_get_title() {
- return NULL;
- }
-
- /**
- * Load text for a supported language.
- *
- * @param int $index
- * A number representing which block of text to return.
+ * Implements pr_get_text().
*/
- protected function pr_get_text($code) {
+ protected function pr_get_text($code, $arguments = array()) {
+ $string = '';
switch ($code) {
case 0:
- return 'Server Error';
+ $string = 'Server Error';
+ break;
case 1:
- return 'Something went wrong while processing your request, please try again later.';
+ $string = 'Something went wrong while processing your request, please try again later.';
+ break;
+ }
+
+ if (!empty($arguments)) {
+ $this->pr_process_replacements($string, $arguments);
}
- return '';
+ return $string;
}
}
require_once('common/theme/classes/theme_html.php');
-class c_reservation_path_user_dashboard extends c_base_path {
+class c_reservation_path_user_dashboard extends c_reservation_path {
/**
* Implements do_execute().
return $executed;
}
+ $this->pr_assign_defaults($settings);
- // Wrapper
- $wrapper = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_SECTION, c_base_defaults_global::CSS_BASE . c_base_defaults_global::CSS_BASE . 'content-wrapper', array(c_base_defaults_global::CSS_BASE . 'dashboard-user', 'dashboard-user'));
-
-
- // Dashboard Content
- $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_H1);
- $tag->set_text($this->pr_get_text(0));
- $wrapper->set_tag($tag);
- unset($tag);
-
- $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_DIVIDER);
- $tag->set_text($this->pr_get_text(1));
- $wrapper->set_tag($tag);
- unset($tag);
+ $wrapper = $this->pr_create_tag_wrapper();
+ $wrapper->set_tag($this->pr_create_tag_title(0));
+ $wrapper->set_tag($this->pr_create_tag_text_block(1));
$roles = array();
$roles_object = $session->get_setting('roles');
}
unset($roles_object);
- $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_DIVIDER);
- $tag->set_text($this->pr_get_text(2) . ' ' . $settings['database_user']);
- $wrapper->set_tag($tag);
- unset($tag);
+ $wrapper->set_tag($this->pr_create_tag_text_block($this->pr_get_text(2, array('@{user}' => $this->user_name))));
- $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_DIVIDER);
- $tag->set_text($this->pr_get_text(3));
- $wrapper->set_tag($tag);
- unset($tag);
+ $block = $this->pr_create_tag_text_block(NULL);
+ $block->set_tag($this->pr_create_tag_text(3));
$tag_ul = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_UNORDERED_LIST);
}
unset($role);
- $wrapper->set_tag($tag_ul);
+ $block->set_tag($tag_ul);
+ unset($tag_ul);
+
+ $wrapper->set_tag($block);
+ unset($block);
// initialize the content as HTML.
- $html = c_reservation_build::s_create_html($http, $database, $session, $settings);
+ $html = $this->pr_create_html($http, $database, $session, $settings);
$html->set_tag($wrapper);
- $executed = new c_base_path_executed();
$executed->set_output($html);
unset($html);
}
/**
- * Load text for a supported language.
- *
- * @param int $index
- * A number representing which block of text to return.
+ * Implements pr_get_text().
*/
- protected function pr_get_text($code) {
+ protected function pr_get_text($code, $arguments = array()) {
switch ($code) {
case 0:
- return 'Dashboard';
+ $string = 'Dashboard';
+ break;
case 1:
- return 'All links will go here.';
+ $string = 'All links will go here.';
+ break;
case 2:
- return 'You are currently logged in as:';
+ $string = 'You are currently logged in as: @{user}.';
+ break;
case 3:
- return 'You are currently assigned the following roles:';
+ $string = 'You are currently assigned the following roles:';
+ break;
case 4:
- return 'Public';
+ $string = 'Public';
+ break;
case 5:
- return 'User';
+ $string = 'User';
+ break;
case 6:
- return 'Requester';
+ $string = 'Requester';
+ break;
case 7:
- return 'Drafter';
+ $string = 'Drafter';
+ break;
case 8:
- return 'Editor';
+ $string = 'Editor';
+ break;
case 9:
- return 'Reviewer';
+ $string = 'Reviewer';
+ break;
case 10:
- return 'Financer';
+ $string = 'Financer';
+ break;
case 11:
- return 'Insurer';
+ $string = 'Insurer';
+ break;
case 12:
- return 'Publisher';
+ $string = 'Publisher';
+ break;
case 13:
- return 'Auditor';
+ $string = 'Auditor';
+ break;
case 14:
- return 'Manager';
+ $string = 'Manager';
+ break;
case 15:
- return 'Administer';
+ $string = 'Administer';
+ break;
+ }
+
+ if (!empty($arguments)) {
+ $this->pr_process_replacements($string, $arguments);
}
- return '';
+ return $string;
}
}
/**
* Implements pr_get_text().
*/
- protected function pr_get_text($code) {
+ protected function pr_get_text($code, $arguments = array()) {
+ $string = '';
switch ($code) {
case 0:
- return 'ダッシュボード';
+ $string = 'ダッシュボード';
+ break;
case 1:
// note: currently not converting this because all text in this area will undergo major changes.
- return parent::pr_get_text($code);
+ $string = parent::pr_get_text($code);
+ break;
case 2:
- return 'あなたは現在次のようにログインしています:';
+ $string = 'あなたは現在、@{user}としてログインしています。';
+ break;
case 3:
- return '現在、次の役割が割り当てられています。';
+ $string = '現在、次の役割が割り当てられています。';
+ break;
case 4:
- return 'パブリック';
+ $string = 'パブリック';
+ break;
case 5:
- return 'ユーザー';
+ $string = 'ユーザー';
+ break;
case 6:
- return 'リクエスタ';
+ $string = 'リクエスタ';
+ break;
case 7:
- return 'ドレイター';
+ $string = 'ドレイター';
+ break;
case 8:
- return '編集者';
+ $string = '編集者';
+ break;
case 9:
- return 'レビューア';
+ $string = 'レビューア';
+ break;
case 10:
- return 'ファイナンサー';
+ $string = 'ファイナンサー';
+ break;
case 11:
- return '保険会社';
+ $string = '保険会社';
+ break;
case 12:
- return '出版社';
+ $string = '出版社';
+ break;
case 13:
- return '審査員';
+ $string = '審査員';
+ break;
case 14:
- return 'マネージャー';
+ $string = 'マネージャー';
+ break;
case 15:
- return '管理者';
+ $string = '管理者';
+ break;
}
- return '';
+ if (!empty($arguments)) {
+ $this->pr_process_replacements($string, $arguments);
+ }
+
+ return $string;
}
}
/**
* Implements pr_get_text().
*/
- protected function pr_get_text($code) {
+ protected function pr_get_text($code, $arguments = array()) {
+ $string = '';
switch ($code) {
case 0:
- return 'システムへのログイン';
+ $string = 'システムへのログイン';
+ break;
case 1:
- return 'ユーザー名';
+ $string = 'ユーザー名';
+ break;
case 2:
- return 'パスワード';
+ $string = 'パスワード';
+ break;
+ case 3:
+ $string = 'ログインした';
+ break;
+ case 4:
+ $string = '現在、システムに@{user}としてログインしています。';
+ break;
+ case 5:
+ $string = 'してもいいです';
+ break;
+ case 6:
+ $string = 'ログアウト';
+ break;
+ case 7:
+ $string = 'いつでも';
+ break;
+ case 8:
+ $string = 'ログイン失敗';
+ break;
+ case 9:
+ $string = 'あなたは既にログインしています。';
+ break;
}
- return '';
+ if (!empty($arguments)) {
+ $this->pr_process_replacements($string, $arguments);
+ }
+
+ return $string;
}
}
/**
* Implements pr_get_text().
*/
- protected function pr_get_text($code) {
+ protected function pr_get_text($code, $arguments = array()) {
+ $string = '';
switch ($code) {
case 0:
- return 'あなたはログアウトしました';
+ $string = 'あなたはログアウトしました';
+ break;
case 1:
- return 'あなたはシステムからログアウトされています。';
+ $string = 'あなたはシステムからログアウトされています。';
+ break;
}
- return '';
+ if (!empty($arguments)) {
+ $this->pr_process_replacements($string, $arguments);
+ }
+
+ return $string;
}
}
*
* This listens on: /u/login
*/
-class c_reservation_path_user_login extends c_base_path {
+class c_reservation_path_user_login extends c_reservation_path {
private const PATH_REDIRECTS = 'program/reservation/reservation_redirects.php';
/**
return $executed;
}
+ $this->pr_assign_defaults($settings);
+
// initialize the content as HTML.
- $html = c_reservation_build::s_create_html($http, $database, $session, $settings);
+ $html = $this->pr_create_html($http, $database, $session, $settings);
+ $wrapper = $this->pr_create_tag_wrapper();
+
+ $logged_in = $session->get_logged_in()->get_value_exact();
+ if ($logged_in) {
+ $method = $this->pr_get_method($http);
+
+ if ($method == c_base_http::HTTP_METHOD_POST) {
+ unset($method);
+
+
+ // forbid POST request on login pages for already logged in users.
+ $this->http->set_response_status(c_base_http_status::FORBIDDEN);
+
+
+ // Content
+ $wrapper->set_tag($this->pr_create_tag_title(8));
+ $wrapper->set_tag($this->pr_create_tag_text_block(9));
+ }
+ else {
+ unset($method);
+
+
+ // Content
+ $wrapper->set_tag($this->pr_create_tag_title(3));
+ $wrapper->set_tag($this->pr_create_tag_text_block(4, array('@{user}' => $this->user_name)));
+
+ $wrapper->set_tag($this->pr_create_tag_break());
+
+ $wrapper->set_tag($this->pr_create_tag_text_block(9));
+
+ $block = $this->pr_create_tag_text_block(NULL);
+ $block->set_tag($this->pr_create_tag_text(5));
+
+ $href = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_A);
+ $href->set_text($this->pr_get_text(6));
+ $href->set_attribute(c_base_markup_attributes::ATTRIBUTE_HREF, $this->base_path . 'u/logout');
+ $block->set_tag($href);
+ unset($href);
+
+ $block->set_tag(c_theme_html::s_create_tag_text(c_base_markup_tag::TYPE_SPAN, $this->pr_get_text(7)));
+ $wrapper->set_tag($block);
+ unset($block);
+ }
+
+ $html->set_tag($wrapper);
+ unset($wrapper);
+
+ $executed->set_output($html);
+ unset($html);
+
+ return $executed;
+ }
// handle any resulting errors.
// successfully logged in.
require_once(self::PATH_REDIRECTS);
- $destination = $settings['uri'];
+ $request_uri = $http->get_request(c_base_http::REQUEST_URI)->get_value_exact();
+ if (isset($request_uri['data']) && is_array($request_uri['data'])) {
+ $destination = $request_uri['data'];
+ }
+ else {
+ $destination = array(
+ 'scheme' => NULL,
+ 'authority' => NULL,
+ 'path' => NULL,
+ 'query' => NULL,
+ 'fragment' => NULL,
+ 'url' => TRUE,
+ 'current' => $start,
+ 'invalid' => FALSE,
+ );
+ }
+ unset($request_uri);
+
$destination['path'] = $settings['base_path'] . 'u/dashboard';
// note: by using a SEE OTHER redirect, the client knows to make a GET request and that the redirect is temporary.
else {
$form_defaults = array();
}
+ unset($logged_in);
// login form
$form = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_FORM, 'login_form', array('login_form'));
$form->set_attribute(c_base_markup_attributes::ATTRIBUTE_ROLE, 'form');
$form->set_attribute(c_base_markup_attributes::ATTRIBUTE_ACCEPT_CHARACTER_SET, c_base_charset::UTF_8);
-
- // H1
- $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_H1);
- $tag->set_text($this->pr_get_text(0));
- $form->set_tag($tag);
- unset($tag);
+ $form->set_tag($this->pr_create_tag_title(0));
// form id: represents the form.
// button: submit
$tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_SUBMIT, 'login_form-login', array('login_form-button-login'));
$tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_VALUE, 'Login');
- #$tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_ACTION, $settings['base_path'] . '/s/u/login'); // custom submit destination, but would require /s/u/login to redirect back to here.
+ #$tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_ACTION, $settings['base_path'] . 's/u/login'); // custom submit destination, but would require /s/u/login to redirect back to here.
$form->set_tag($tag);
unset($tag);
unset($problem_fields);
// Wrapper
- $wrapper = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_SECTION, c_base_defaults_global::CSS_BASE . c_base_defaults_global::CSS_BASE . 'content-wrapper', array(c_base_defaults_global::CSS_BASE . 'content-wrapper', 'content-wrapper'));
$wrapper->set_tag($form);
unset($form);
$html->set_tag($wrapper);
unset($wrapper);
- $executed = new c_base_path_executed();
$executed->set_output($html);
unset($html);
}
/**
- * Load text for a supported language.
- *
- * @param int $index
- * A number representing which block of text to return.
+ * Implements pr_get_text().
*/
- protected function pr_get_text($code) {
+ protected function pr_get_text($code, $arguments = array()) {
+ $string = '';
switch ($code) {
case 0:
- return 'Login to System';
+ $string = 'Login to System';
+ break;
case 1:
- return 'Username';
+ $string = 'Username';
+ break;
case 2:
- return 'Password';
+ $string = 'Password';
+ break;
+ case 3:
+ $string = 'Logged In';
+ break;
+ case 4:
+ $string = 'You are currently logged in to the system as @{user}.';
+ break;
+ case 5:
+ $string = 'You may ';
+ break;
+ case 6:
+ $string = 'logout';
+ break;
+ case 7:
+ $string = ' at any time.';
+ break;
+ case 8:
+ $string = 'Login Failure';
+ break;
+ case 9:
+ $string = 'You are already logged in.';
+ break;
+ }
+
+ if (!empty($arguments)) {
+ $this->pr_process_replacements($string, $arguments);
}
- return '';
+ return $string;
}
}
/**
* Provides a form for the user logout.
*
- * This listens on: /s/u/logout
+ * This listens on: /u/logout
*/
-class c_reservation_path_form_user_logout extends c_base_path {
+class c_reservation_path_user_logout extends c_reservation_path {
/**
* Implements do_execute().
return $executed;
}
+ $this->pr_assign_defaults($settings);
- // Wrapper
- $wrapper = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_SECTION, c_base_defaults_global::CSS_BASE . c_base_defaults_global::CSS_BASE . 'content-wrapper', array(c_base_defaults_global::CSS_BASE . 'content-wrapper', 'content-wrapper'));
+ $result = $this->p_do_logout($database, $session, $settings);
-
- // H1
- $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_H1);
- $tag->set_text($this->pr_get_text(0));
- $wrapper->set_tag($tag);
- unset($tag);
-
- // H1
- $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_DIVIDER);
- $tag->set_text($this->pr_get_text(1));
- $wrapper->set_tag($tag);
- unset($tag);
+ $wrapper = $this->pr_create_tag_wrapper();
+ $wrapper->set_tag($this->pr_create_tag_title(0));
+ $wrapper->set_tag($this->pr_create_tag_text_block(1));
// initialize the content as HTML.
- $html = c_reservation_build::s_create_html($http, $database, $session, $settings);
+ $html = $this->pr_create_html($http, $database, $session, $settings);
$html->set_tag($wrapper);
unset($wrapper);
- $executed = new c_base_path_executed();
$executed->set_output($html);
unset($html);
- reservation_session_logout($database, $session, $settings);
-
return $executed;
}
* An array of problems on failure.
*/
private function p_do_logout(&$database, &$session, $settings) {
+ if (!$database->is_connected()->get_value_exact()) {
+ $connected = reservation_database_connect($database);
+ if (c_base_return::s_has_error($connected)) {
+ unset($connected);
+ unset($already_connected);
+ return FALSE;
+ }
+ unset($connected);
+ }
+
+ // @todo: write to database logout log entry.
+
+ $cookie_login = $session->get_cookie();
+
+ $database->do_disconnect();
+ $session->do_terminate();
+ $session->do_disconnect();
+ $session->set_logged_in(FALSE);
+
+ // remove username and password from database string.
+ reservation_database_string($database, $settings);
+
+ // delete the login cookie.
+ if ($cookie_login instanceof c_base_cookie) {
+ $cookie_login->set_expires(-1);
+ $cookie_login->set_max_age(-1);
+ $result = $session->set_cookie($cookie_login);
+ }
+ unset($cookie_login);
+
+ return TRUE;
}
/**
- * Load text for a supported language.
- *
- * @param int $index
- * A number representing which block of text to return.
+ * Implements pr_get_text().
*/
- protected function pr_get_text($code) {
+ protected function pr_get_text($code, $arguments = array()) {
+ $string = '';
switch ($code) {
case 0:
- return 'You Have Logged Out';
+ $string = 'You Have Logged Out';
+ break;
case 1:
- return 'You have been logged out of the system.';
+ $string = 'You have been logged out of the system.';
+ break;
+ }
+
+ if (!empty($arguments)) {
+ $this->pr_process_replacements($string, $arguments);
}
- return '';
+ return $string;
}
}
require_once('common/base/classes/base_error.php');
require_once('common/base/classes/base_return.php');
require_once('common/base/classes/base_markup.php');
-require_once('common/base/classes/base_html.php');
require_once('common/base/classes/base_http.php');
-require_once('common/base/classes/base_charset.php');
require_once('common/base/classes/base_ascii.php');
-require_once('common/base/classes/base_form.php');
require_once('common/base/classes/base_path.php');
+require_once('common/base/classes/base_mime.php');
+
+require_once('common/theme/classes/theme_html.php');
require_once('program/reservation/reservation_database.php');
require_once('program/reservation/reservation_session.php');
class c_reservation_paths {
// paths to common files (not url paths).
- private const PATH_LOGIN = 'program/reservation/paths/u/';
- private const PATH_LOGOUT = 'program/reservation/paths/u/';
- private const PATH_ACCESS_DENIED = 'program/reservation/internal/';
- private const PATH_NOT_FOUND = 'program/reservation/internal/';
- private const PATH_BAD_METHOD = 'program/reservation/internal/';
- private const PATH_SERVER_ERROR = 'program/reservation/internal/';
- private const PATH_REDIRECTS = 'program/reservation/';
-
- private const NAME_LOGIN = 'login';
- private const NAME_LOGOUT = 'logout';
- private const NAME_ACCESS_DENIED = 'access_denied';
- private const NAME_NOT_FOUND = 'not_found';
- private const NAME_BAD_METHOD = 'bad_method';
- private const NAME_SERVER_ERROR = 'server_error';
- private const NAME_REDIRECTS = 'reservation_redirects';
-
- private $http = NULL;
- private $database = NULL;
- private $settings = NULL;
- private $session = NULL;
- private $output = NULL;
- private $logged_in = NULL;
+ private const PATH_LOGIN = 'program/reservation/paths/u/';
+ private const PATH_LOGOUT = 'program/reservation/paths/u/';
+ private const PATH_ACCESS_DENIED = 'program/reservation/internal/';
+ private const PATH_NOT_FOUND = 'program/reservation/internal/';
+ private const PATH_BAD_METHOD = 'program/reservation/internal/';
+ private const PATH_SERVER_ERROR = 'program/reservation/internal/';
+ private const PATH_OPTIONS_METHOD = 'program/reservation/internal/';
+ private const PATH_REDIRECTS = 'program/reservation/';
+ private const PATH_DASHBOARD_USER = 'program/reservation/paths/u/';
+ private const PATH_DASHBOARD_MANAGEMENT = 'program/reservation/paths/m/';
+ private const PATH_DASHBOARD_ADMINISTER = 'program/reservation/paths/a/';
+
+ private const NAME_LOGIN = 'login';
+ private const NAME_LOGOUT = 'logout';
+ private const NAME_ACCESS_DENIED = 'access_denied';
+ private const NAME_NOT_FOUND = 'not_found';
+ private const NAME_BAD_METHOD = 'bad_method';
+ private const NAME_SERVER_ERROR = 'server_error';
+ private const NAME_OPTIONS_METHOD = 'options';
+ private const NAME_REDIRECTS = 'reservation_redirects';
+ private const NAME_DASHBOARD_USER = 'dashboard';
+ private const NAME_DASHBOARD_MANAGEMENT = 'dashboard';
+ private const NAME_DASHBOARD_ADMINISTER = 'dashboard';
+
+ private const SCRIPT_EXTENSION = '.php';
+
+ // a class name to prepend to css classes or id attributes.
+ const CSS_BASE = 'reservation-';
+
+ private $http = NULL;
+ private $database = NULL;
+ private $settings = NULL;
+ private $session = NULL;
+ private $output = NULL;
private $paths = NULL;
private $path = NULL;
* Class constructor.
*/
public function __construct() {
- $this->http = NULL;
- $this->database = NULL;
- $this->settings = NULL;
- $this->session = NULL;
- $this->output = NULL;
- $this->logged_in = NULL;
+ $this->http = NULL;
+ $this->database = NULL;
+ $this->settings = NULL;
+ $this->session = NULL;
+ $this->output = NULL;
$this->paths = NULL;
$this->path = NULL;
unset($this->settings);
unset($this->session);
unset($this->output);
- unset($this->logged_in);
unset($this->paths);
unset($this->path);
* The html page object.
* @param array $settings
* The system settings array.
- * @param bool $logged_in
- * (optional) TRUE of logged in, FALSE otherwise.
*
* @return c_base_path_executed
* The execution results.
* The execution results with the error bit set on error.
*/
- public function reservation_process_path(&$http, &$database, &$session, $settings, $logged_in = TRUE) {
+ public function reservation_process_path(&$http, &$database, &$session, $settings) {
// @todo: these parameter errors might need a custom service unavailable and system log support.
if (!($http instanceof c_base_http)) {
$error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'http', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
return c_base_return_error::s_value(array(), 'c_base_path_executed', $error);
}
- if (!is_bool($logged_in)) {
- $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'logged_in', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT);
- return c_base_return_error::s_value(array(), 'c_base_path_executed', $error);
- }
-
$this->http = &$http;
$this->database = &$database;
$this->settings = $settings;
$this->session = &$session;
$this->output = NULL;
- $this->logged_in = $logged_in;
$this->p_get_language_alias();
}
- $request_uri = $http->get_request(c_base_http::REQUEST_URI)->get_value_exact();
-
- $this->settings['uri'] = array(
- 'scheme' => '',
- 'authority' => '',
- 'path' => '',
- 'query' => array(),
- 'fragment' => '',
- 'url' => TRUE,
- );
-
- if (isset($request_uri['data'])) {
- $this->settings['uri'] = $request_uri['data'];
- }
- unset($request_uri);
-
- // strip the base path from the requested uri.
- if (!empty($settings['base_path'])) {
- $this->settings['uri']['path'] = preg_replace('@^' . preg_quote($settings['base_path'], '@') . '@i', '', $this->settings['uri']['path']);
- $this->settings['uri']['path'] = preg_replace('@/$@', '', $this->settings['uri']['path']);
- }
-
-
// load all available paths.
$this->p_paths_create();
// find the path
- $handler_settings = $this->paths->find_path($this->settings['uri']['path'])->get_value();
+ $path = $this->http->get_request_uri_relative($settings['base_path'])->get_value_exact();
+ $handler_settings = $this->paths->find_path($path)->get_value();
+ unset($path);
+
if (!is_array($handler_settings)) {
// for all invalid pages, report bad method if not HTTP GET or HTTP POST.
if ($method !== c_base_http::HTTP_METHOD_GET && $method !== c_base_http::HTTP_METHOD_POST) {
unset($method);
// successfully logged in.
- require_once(self::PATH_REDIRECTS . self::NAME_REDIRECTS . '.php');
+ require_once(self::PATH_REDIRECTS . self::NAME_REDIRECTS . self::SCRIPT_EXTENSION);
if (!is_string($handler_settings['redirect'])) {
$handler_settings['redirect'] = '';
}
else {
if (!empty($handler_settings['include_name']) && is_string($handler_settings['include_name'])) {
- require_once($handler_settings['include_directory'] . $handler_settings['include_name']);
+ require_once($handler_settings['include_directory'] . $handler_settings['include_name'] . self::SCRIPT_EXTENSION);
}
// execute path handler, using custom-language if defined.
if (empty($handler_settings['handler'])) {
- $server_error = $this->p_get_path_server_error();
- return $server_error->do_execute($this->http, $this->database, $this->session, $this->settings);
+ return $this->p_get_path_server_error()->do_execute($this->http, $this->database, $this->session, $this->settings);
}
elseif (is_string($this->alias)) {
@include_once($handler_settings['include_directory'] . $this->alias . '/' . $handler_settings['include_name']);
// attempt to fallback to default handler if the language-specific handler class is not found.
if (!class_exists($handler_settings['handler'])) {
- $server_error = $this->p_get_path_server_error();
- return $server_error->do_execute($this->http, $this->database, $this->session, $this->settings);
+ return $this->p_get_path_server_error()->do_execute($this->http, $this->database, $this->session, $this->settings);
}
else {
$this->path = new $handler_settings['handler']();
$this->path = new $handler_settings['handler']();
}
else {
- $server_error = $this->p_get_path_server_error();
- return $server_error->do_execute($this->http, $this->database, $this->session, $this->settings);
+ return $this->p_get_path_server_error()->do_execute($this->http, $this->database, $this->session, $this->settings);
}
}
if (isset($handler_settings['is_root']) && $handler_settings['is_root']) {
- $this->path->set_is_root(TRUE);
+ $this->path->is_root(TRUE);
}
}
unset($handler_settings);
$this->paths = new c_base_paths();
// set root path to be the user dashboard.
- $this->paths->set_path('', 'c_reservation_path_user_dashboard', 'program/reservation/paths/u/', 'dashboard.php');
+ $this->paths->set_path('', 'c_reservation_path_user_dashboard', self::PATH_DASHBOARD_USER, self::NAME_DASHBOARD_USER);
// create login/logout paths
- $this->paths->set_path('/u/login', 'c_reservation_path_user_login', 'program/reservation/paths/u/', 'login.php');
- $this->paths->set_path('/u/logout', 'c_reservation_path_user_logout', 'program/reservation/paths/u/', 'logout.php');
+ $this->paths->set_path('/u/login', 'c_reservation_path_user_login', self::PATH_LOGIN, self::NAME_LOGIN);
+ $this->paths->set_path('/u/logout', 'c_reservation_path_user_logout', self::PATH_LOGOUT, self::NAME_LOGOUT);
- // user dashboard
- $this->paths->set_path('/u/dashboard', 'c_reservation_path_user_dashboard', 'program/reservation/paths/u/', 'dashboard.php');
+ // dashboards
+ $this->paths->set_path('/u/dashboard', 'c_reservation_path_user_dashboard', self::PATH_DASHBOARD_USER, self::NAME_DASHBOARD_USER);
+ #$this->paths->set_path('/m/dashboard', 'c_reservation_path_management_dashboard', self::PATH_DASHBOARD_MANAGEMENT, self::NAME_DASHBOARD_MANAGEMENT);
+ #$this->paths->set_path('/a/dashboard', 'c_reservation_path_administer_dashboard', self::PATH_DASHBOARD_ADMINISTER, self::NAME_DASHBOARD_ADMINISTER);
}
/**
$id_group = $this->path->get_id_group()->get_value_exact();
// regardless of path-specific settings, the following paths always require login credentials to access.
- if ($id_group === c_base_ascii::LOWER_A || $id_group === c_base_ascii::LOWER_U) {
- $this->path->set_is_private(TRUE);
+ if ($id_group === c_base_ascii::LOWER_A || $id_group === c_base_ascii::LOWER_M || $id_group === c_base_ascii::LOWER_U) {
+ $this->path->is_private(TRUE);
}
if ($this->path instanceof c_reservation_path_user_login) {
unset($id_group);
return $this->path->do_execute($this->http, $this->database, $this->session, $this->settings);
}
+ elseif ($this->path instanceof c_reservation_path_user_logout) {
+ // if the user is not logged in. then provide a page not found for logout path.
+ if (!$this->session->get_logged_in()->get_value_exact()) {
+ return $this->p_get_path_not_found()->do_execute($this->http, $this->database, $this->session, $this->settings);
+ }
+ }
+ elseif ($this->path instanceof c_reservation_path_user_dashboard && $id_group === 0) {
+ // the user dashboard is setup as the site root.
+ // when path is root, there is no id_group, so explicitly assign the group.
+ $id_group = c_base_ascii::LOWER_U;
+
+ // @todo: do this for other dashboards as well (manager, and administer).
+ }
// if the request is private, make sure the user is logged in.
- if ($id_group === c_base_ascii::LOWER_A || $id_group === c_base_ascii::LOWER_U || $this->path->get_is_private()->get_value_exact()) {
- if ($this->logged_in) {
+ if ($id_group === c_base_ascii::LOWER_A || $id_group === c_base_ascii::LOWER_M || $id_group === c_base_ascii::LOWER_U || $this->path->is_private()->get_value_exact()) {
+ if ($this->session->get_logged_in()->get_value_exact()) {
unset($id_group);
return $this->path->do_execute($this->http, $this->database, $this->session, $this->settings);
}
- elseif ($this->path->get_is_root()->get_value_exact()) {
+ elseif ($this->path->is_root()->get_value_exact()) {
unset($id_group);
$this->http->set_response_status(c_base_http_status::FORBIDDEN);
}
else {
// some special case paths always provide login prompt along with access denied.
- if ($id_group === c_base_ascii::LOWER_A || $id_group === c_base_ascii::LOWER_U) {
+ if ($id_group === c_base_ascii::LOWER_A || $id_group === c_base_ascii::LOWER_M || $id_group === c_base_ascii::LOWER_U) {
unset($id_group);
$this->http->set_response_status(c_base_http_status::FORBIDDEN);
// these always return not found for these paths.
$failsafe_path = $this->p_get_path_not_found();
}
- elseif ($this->path->get_is_private()->get_value_exact() && $id_group !== c_base_ascii::NULL) {
+ elseif ($this->path->is_private()->get_value_exact() && $id_group !== c_base_ascii::NULL) {
// non private, and non-special case paths should return access denied as per normal behavior.
$failsafe_path = $this->p_get_path_access_denied();
}
* Load and return the internal server error path.
*/
private function p_get_path_options_method() {
- return new c_reservation_path_options_method();
+ return $this->p_include_path(self::PATH_OPTIONS_METHOD, self::NAME_OPTIONS_METHOD, 'c_reservation_path_options_method');
}
/**
* The created c_base_path object.
*/
private function p_include_path($path, $name, $class) {
- require_once($path . $name . '.php');
+ require_once($path . $name . self::SCRIPT_EXTENSION);
// use default if no aliases are found.
if (is_null($this->alias)) {
}
// use include_once instead of require_require to allow for failsafe behavior.
- @include_once($path . $this->alias . '/' . $name . '.php');
+ @include_once($path . $this->alias . '/' . $name . self::SCRIPT_EXTENSION);
$language_class = $class . '_' . $this->alias;
if (class_exists($language_class)) {
}
/**
- * Provide the HTTP options response.
- *
- * This does not provide any content body.
+ * Provides reservation-specific path functionality.
*/
-final class c_reservation_path_options_method extends c_base_path {
+class c_reservation_path extends c_base_path {
+ protected $use_p_tags = NULL;
+ protected $base_path = NULL;
+ protected $user_name = NULL;
+
+
+ /**
+ * Class constructor.
+ */
+ public function __construct() {
+ parent::__construct();
+
+ $this->use_p_tags = FALSE;
+ $this->base_path = '';
+ $this->user_name = '';
+ }
+
+ /**
+ * Class destructor.
+ */
+ public function __destruct() {
+ unset($this->use_p_tags);
+ unset($this->base_path);
+ unset($this->user_name);
+
+ parent::__destruct();
+ }
+
+ /**
+ * Load any default settings.
+ *
+ * Very validation is performed.
+ *
+ * @param array $settings
+ * The array containing all of the settings to parse.
+ */
+ protected function pr_assign_defaults($settings) {
+ if (isset($settings['standard_issue-use_p_tags']) && is_bool($settings['standard_issue-use_p_tags'])) {
+ $this->use_p_tags = $settings['standard_issue-use_p_tags'];
+ }
+
+ if (isset($settings['base_path']) && is_string($settings['base_path'])) {
+ $this->base_path = $settings['base_path'];
+ }
+
+ if (isset($settings['database_user']) && is_string($settings['database_user'])) {
+ $this->user_name = $settings['database_user'];
+ }
+ }
+
+ /**
+ * Creates the standard wrapper.
+ *
+ * @return c_base_markup_tag
+ * The generated markup tag.
+ */
+ protected function pr_create_tag_wrapper() {
+ return c_theme_html::s_create_tag(c_base_markup_tag::TYPE_SECTION, c_reservation_paths::CSS_BASE . c_reservation_paths::CSS_BASE . 'content-wrapper', array(c_reservation_paths::CSS_BASE . 'content-wrapper', 'content-wrapper'));
+ }
+
+ /**
+ * Creates the standard break tag.
+ *
+ * @return c_base_markup_tag
+ * The generated markup tag.
+ */
+ protected function pr_create_tag_break() {
+ return c_theme_html::s_create_tag(c_base_markup_tag::TYPE_BREAK);
+ }
/**
- * Implements do_execute().
+ * Creates the standard title.
+ *
+ * @param int|string $text
+ * The text or the text code to use.
+ * @param array $arguments
+ * (optional) An array of arguments to convert into text.
+ *
+ * @return c_base_markup_tag
+ * The generated markup tag.
*/
- public function do_execute(&$http, &$database, &$session, $settings = array()) {
- // the parent function performs validation on the parameters.
- $executed = parent::do_execute($http, $database, $session, $settings);
- if (c_base_return::s_has_error($executed)) {
- return $executed;
+ protected function pr_create_tag_title($text, $arguments = array()) {
+ if (is_int($text)) {
+ return c_theme_html::s_create_tag(c_base_markup_tag::TYPE_H1, NULL, array('as-title'), $this->pr_get_text($text, $arguments));
+ }
+
+ return c_theme_html::s_create_tag(c_base_markup_tag::TYPE_H1, NULL, array('as-title'), $text);
+ }
+
+ /**
+ * Creates the standard text.
+ *
+ * @param int|string $text
+ * The text or the text code to use.
+ * @param array $arguments
+ * (optional) An array of arguments to convert into text.
+ *
+ * @return c_base_markup_tag
+ * The generated markup tag.
+ */
+ protected function pr_create_tag_text($text, $arguments = array()) {
+ $type = c_base_markup_tag::TYPE_SPAN;
+ if ($this->use_p_tags) {
+ $type = c_base_markup_tag::TYPE_PARAGRAPH;
+ }
+
+ if (is_int($text)) {
+ return c_theme_html::s_create_tag($type, NULL, array('as-text'), $this->pr_get_text($text, $arguments));
+ }
+
+ return c_theme_html::s_create_tag($type, NULL, array('as-text'), $text);
+ }
+
+ /**
+ * Creates the standard paragraph.
+ *
+ * @param int|string $text
+ * The text or the text code to use.
+ * @param array $arguments
+ * (optional) An array of arguments to convert into text.
+ *
+ * @return c_base_markup_tag
+ * The generated markup tag.
+ */
+ protected function pr_create_tag_paragraph($text, $arguments = array()) {
+ $type = c_base_markup_tag::TYPE_SPAN;
+ if ($this->use_p_tags) {
+ $type = c_base_markup_tag::TYPE_PARAGRAPH;
+ }
+
+ if (is_int($text)) {
+ return c_theme_html::s_create_tag($type, NULL, array('as-paragraph'), $this->pr_get_text($text, $arguments));
+ }
+
+ return c_theme_html::s_create_tag($type, NULL, array('as-paragraph'), $text);
+ }
+
+ /**
+ * Creates the standard text, wrapped in a block.
+ *
+ * @param int|string|null $text
+ * The text or the text code to use.
+ * If NULL, only the block is created.
+ * @param array $arguments
+ * (optional) An array of arguments to convert into text.
+ *
+ * @return c_base_markup_tag
+ * The generated markup tag.
+ */
+ protected function pr_create_tag_text_block($text, $arguments = array()) {
+ $block = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_DIVIDER, NULL, array('as-text-block'));
+
+ if (!is_null($text)) {
+ $type = c_base_markup_tag::TYPE_SPAN;
+ if ($this->use_p_tags) {
+ $type = c_base_markup_tag::TYPE_PARAGRAPH;
+ }
+
+ if (is_int($text)) {
+ $tag = c_theme_html::s_create_tag($type, NULL, array('as-text'), $this->pr_get_text($text, $arguments));
+ }
+ else {
+ $tag = c_theme_html::s_create_tag($type, NULL, array('as-text'), $text);
+ }
+ unset($type);
+
+ $block->set_tag($tag);
+ unset($tag);
}
+ return $block;
+ }
+
+ /**
+ * Creates the standard text, wrapped in a block.
+ *
+ * @param int|string|null $text
+ * The text or the text code to use.
+ * If NULL, only the block is created.
+ * @param array $arguments
+ * (optional) An array of arguments to convert into text.
+ *
+ * @return c_base_markup_tag
+ * The generated markup tag.
+ */
+ protected function pr_create_tag_paragraph_block($text, $arguments = array()) {
+ $block = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_DIVIDER, NULL, array('as-paragraph-block'));
- // assign HTTP response status.
- $allowed_methods = $this->allowed_methods;
- $allowed_method = array_shift($allowed_methods);
- $http->set_response_allow($allowed_method, TRUE);
+ if (!is_null($text)) {
+ $type = c_base_markup_tag::TYPE_SPAN;
+ if ($this->use_p_tags) {
+ $type = c_base_markup_tag::TYPE_PARAGRAPH;
+ }
- if (!empty($allowed_methods)) {
- foreach ($allowed_methods as $allowed_method) {
- $http->set_response_allow($allowed_method);
+ if (is_int($text)) {
+ $tag = c_theme_html::s_create_tag($type, NULL, array('as-paragraph'), $this->pr_get_text($text, $arguments));
+ }
+ else {
+ $tag = c_theme_html::s_create_tag($type, NULL, array('as-paragraph'), $text);
}
+ unset($type);
+
+ $block->set_tag($tag);
+ unset($tag);
}
- unset($allowed_method);
- unset($allowed_methods);
- return $executed;
+ return $block;
}
/**
*
* This is provided here as a means for a language class to override with a custom language for the title.
*
+ * @param array $arguments
+ * (optional) An array of arguments to convert into text.
+ *
* @return string|null
* A string is returned as the custom title.
* NULL is returned to enforce default title.
*/
- protected function pr_get_title() {
+ protected function pr_get_title($arguments = array()) {
return NULL;
}
*
* @param int $index
* A number representing which block of text to return.
+ * @param array $arguments
+ * (optional) An array of arguments to convert into text.
*/
- protected function pr_get_text($code) {
- switch ($code) {
- case 0:
- return 'Server Error';
- case 1:
- return 'Something went wrong while processing your request, please try again later.';
+ protected function pr_get_text($code, $arguments = array()) {
+ return '';
+ }
+
+ /**
+ * Create a new HTML markup class with default settings populated.
+ *
+ * @param c_base_http $http
+ * The entire HTTP information to allow for the execution to access anything that is necessary.
+ * @param c_base_database $database
+ * The database object, which is usually used by form and ajax paths.
+ * @param c_base_session &$session
+ * The current session.
+ * @param array $settings
+ * An array of additional settings that are usually site-specific.
+ *
+ * @return c_base_html
+ * The generated html is returned on success.
+ * The generated html with error bit set is returned on error.
+ */
+ protected function pr_create_html(&$http, &$database, &$session, $settings) {
+ $title = $this->pr_get_title();
+
+ $html = new c_base_html();
+
+
+ // assign class attributes
+ $class = array(
+ 'reservation',
+ 'javascript-disabled',
+ 'is-html5',
+ );
+
+ // add date/time classes.
+ $instance = c_base_defaults_global::s_get_timestamp_session()->get_value_exact();
+ $class[] = 'date-year-' . $html->sanitize_css(date('Y', $instance))->get_value_exact();
+ $class[] = 'date-month-' . $html->sanitize_css(strtolower(date('F', $instance)))->get_value_exact();
+ $class[] = 'date-week_day-' . $html->sanitize_css(strtolower(date('l', $instance)))->get_value_exact();
+ $class[] = 'date-day-' . $html->sanitize_css(date('d', $instance))->get_value_exact();
+ $class[] = 'time-hour-' . $html->sanitize_css(date('H', $instance))->get_value_exact();
+ $class[] = 'time-minutes-' . $html->sanitize_css(date('m', $instance))->get_value_exact();
+ $class[] = 'time-seconds-' . $html->sanitize_css(date('s', $instance))->get_value_exact();
+ unset($instance);
+
+ // add path classes
+ $path = $http->get_request_uri_relative($settings['base_path'])->get_value_exact();
+ $path_parts = explode('/', $path);
+
+ if (is_array($path_parts)) {
+ $sanitized = NULL;
+ $delta = 0;
+ foreach ($path_parts as $path_part) {
+ $sanitized_part = $html->sanitize_css($path_part, TRUE)->get_value_exact();
+ $sanitized .= '-' . $sanitized_part;
+
+ $class[] = 'path-part-' . $delta . '-' . $html->sanitize_css($sanitized_part)->get_value_exact();
+ $delta++;
+ }
+ unset($path_part);
+ unset($sanitized_part);
+
+ $class[] = 'path-full-' . $html->sanitize_css(substr($sanitized, 1))->get_value_exact();
+ unset($sanitized);
}
+ unset($path_parts);
- return '';
+ $html->set_attribute_body(c_base_markup_attributes::ATTRIBUTE_CLASS, $class);
+ unset($class);
+
+
+ // assign id attribute
+ $html->set_attribute(c_base_markup_attributes::ATTRIBUTE_ID, 'reservation-system');
+ $html->set_attribute_body(c_base_markup_attributes::ATTRIBUTE_ID, 'reservation-system-body');
+
+
+ // assign language attribute.
+ $language = i_base_language::ENGLISH_US;
+ $languages = $http->get_response_content_language()->get_value_exact();
+ if (is_array($languages) && !empty($languages)) {
+ $language = reset($languages);
+ }
+
+ $html->set_attribute(c_base_markup_attributes::ATTRIBUTE_LANGUAGE, $language);
+ unset($language);
+
+
+ // assign default direction attribute
+ $html->set_attribute(c_base_markup_attributes::ATTRIBUTE_DIRECTION, 'ltr');
+
+
+ // assign title header tag (setting title tag at delta 0 so that it can easily be overriden as needed).
+ $tag = new c_base_markup_tag();
+ $tag->set_type(c_base_markup_tag::TYPE_TITLE);
+
+ if (is_string($title)) {
+ $tag->set_text($title);
+ }
+ else {
+ $tag->set_text('Reservation System');
+ }
+
+ $html->set_header($tag, 0);
+ unset($tag);
+
+
+ // assign base header tag
+ if (isset($this->settings['base_path']) && is_string($this->settings['base_path']) && mb_strlen($this->settings['base_scheme']) > 0) {
+ $href = '';
+ if (isset($this->settings['base_scheme']) && is_string($this->settings['base_scheme']) && mb_strlen($this->settings['base_scheme']) > 0) {
+ if (isset($this->settings['base_host']) && is_string($this->settings['base_host']) && mb_strlen($this->settings['base_host']) > 0) {
+ $href .= $this->settings['base_scheme'] . '://' . $this->settings['base_host'];
+ }
+ }
+
+ $href .= $this->settings['base_path'];
+
+ $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_BASE);
+ $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_HREF, $href);
+ $html->set_header($tag);
+ unset($tag);
+ unset($href);
+ }
+
+
+ // assign http-equiv header tag
+ $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META);
+ $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_HTTP_EQUIV, 'Content-Type');
+ $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_CONTENT, 'text/html; charset=utf-8');
+ $html->set_header($tag);
+ unset($tag);
+
+
+ // assign charset header tag
+ $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META);
+ $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_CHARACTER_SET, c_base_charset::UTF_8);
+ $html->set_header($tag);
+ unset($tag);
+
+
+ // assign canonical header tag
+ #$tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META);
+ #$tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_REL, 'canonical');
+ #$tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_HREF, 'http://localhost/');
+ #$html->set_header($tag);
+ #unset($tag);
+
+
+ // assign shortlink header tag
+ #$tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META);
+ #$tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_REL, 'shortlink');
+ #$tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_HREF, '/');
+ #$html->set_header($tag);
+ #unset($tag);
+
+
+ // assign description header tag
+ $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META);
+ $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_NAME, 'description');
+ $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_CONTENT, 'A reservation/scheduling system.');
+ $html->set_header($tag);
+ unset($tag);
+
+
+ // assign distribution header tag
+ $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META);
+ $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_NAME, 'distribution');
+ $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_CONTENT, 'web');
+ $html->set_header($tag);
+ unset($tag);
+
+
+ // assign robots header tag
+ $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META);
+ $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_NAME, 'robots');
+ $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_CONTENT, 'INDEX,FOLLOW');
+ $html->set_header($tag);
+ unset($tag);
+
+
+ // assign expires header tag
+ #$tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META);
+ #$tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_HTTP_EQUIV, 'expires');
+ #$tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_CONTENT, c_base_defaults_global::s_get_date('r', strtotime('+30 minutes'))->get_value_exact());
+ #$html->set_header($tag);
+ #unset($tag);
+
+
+ // assign viewport header tag
+ $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META);
+ $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_NAME, 'viewport');
+ $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_CONTENT, 'width=device-width, initial-scale=1');
+ $html->set_header($tag);
+ unset($tag);
+
+
+ // assign content http-equiv header tag
+ $aliases = array();
+ if (is_array($languages) && !empty($languages)) {
+ // assign the primary language.
+ $language_aliases = c_base_defaults_global::s_get_languages()::s_get_aliases_by_id(reset($languages))->get_value_exact();
+ if (is_array($language_aliases) && !empty($language_aliases)) {
+ $html->set_attribute(c_base_markup_attributes::ATTRIBUTE_LANGUAGE, reset($language_aliases));
+ }
+ unset($language_aliases);
+
+ foreach ($languages as $language) {
+ $language_aliases = c_base_defaults_global::s_get_languages()::s_get_aliases_by_id($language)->get_value_exact();
+ if (is_array($language_aliases) && !empty($language_aliases)) {
+ $aliases[] = array_pop($language_aliases);
+ }
+ unset($language_aliases);
+ }
+ unset($language);
+ }
+ unset($languages);
+
+ if (!empty($aliases)) {
+ $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META);
+ $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_HTTP_EQUIV, 'content-language');
+ $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_CONTENT, implode(', ', $aliases));
+ $html->set_header($tag);
+ unset($tag);
+ }
+ unset($aliases);
+
+
+ // provide a custom javascript for detecting if javascript is enabled and storing in a css class name.
+ $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_SCRIPT);
+ $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_TYPE, c_base_mime::TYPE_TEXT_JS);
+
+ $javascript = 'function f_reservation_hmtl_javascript_detection() {';
+ $javascript .= 'document.body.removeAttribute(\'onLoad\');';
+ $javascript .= 'document.body.className = document.body.className.replace(/\bjavascript-disabled\b/i, \'javascript-enabled\');';
+ $javascript .= '}';
+ $tag->set_text($javascript);
+ unset($javascript);
+
+ $html->set_header($tag);
+ $html->set_attribute_body(c_base_markup_attributes::ATTRIBUTE_ON_LOAD, 'f_reservation_hmtl_javascript_detection();');
+ unset($tag);
+
+ return $html;
}
-}
+}
}
if (is_bool($is_private)) {
- $path->set_is_private($is_private);
+ $path->is_private($is_private);
}
else {
- $path->set_is_private(TRUE);
+ $path->is_private(TRUE);
}
- $path->set_is_redirect(TRUE);
+ $path->is_redirect(TRUE);
$timestamp_session = c_base_defaults_global::s_get_timestamp_session();
$path->set_date_created($timestamp_session);
$settings['database_user'] = $user_name;
$settings['database_password'] = $password;
}
+
+ $session->set_logged_in(TRUE);
}