/** * HTML Error If exists */ public static function htmlError() { /* ======================== * Getting & Set config * ======================== */ $error_to_show_ = Config::get('show_error_count', 3); if (!is_numeric($error_to_show_) && !empty($error_to_show_)) { $error_to_show = 3; Config::replace('show_error_count', $error_to_show); } else { $error_to_show = abs($error_to_show_) < 0 || abs($error_to_show_) >= 30 ? 30 : abs(intval($error_to_show_)); $error_to_show_ !== $error_to_show && Config::replace('show_error_count', $error_to_show); } /* ======================== * Getting & Set Language * ======================== */ if (!is_string(static::$x_html_error_type) || !trim(static::$x_html_error_type)) { static::$x_html_error_type = 'Error Type'; } if (!is_string(static::$x_html_error_message) || !trim(static::$x_html_error_message)) { static::$x_html_error_message = 'Error Message'; } if (!is_string(static::$x_html_error_file) || !trim(static::$x_html_error_file)) { static::$x_html_error_file = 'Error File'; } if (!is_string(static::$x_html_error_line) || !trim(static::$x_html_error_line)) { static::$x_html_error_line = 'Error Line'; } if (!is_string(static::$x_html_error_more) || is_numeric(static::$x_html_error_more) || !trim(static::$x_html_error_more)) { static::$x_html_error_more = null; } else { static::$x_html_error_more = 'And %[more_error]% more.'; } if (!is_string(static::$x_html_error_document_root) || is_numeric(static::$x_html_error_document_root)) { static::$x_html_error_document_root = null; } else { static::$x_html_error_document_root = !trim(static::$x_html_error_document_root) ? '' : '{DOCUMENT ROOT}'; } $err_type = static::$x_html_error_type; $err_msg = static::$x_html_error_message; $err_file = static::$x_html_error_file; $err_line = static::$x_html_error_line; $another_error = static::$x_html_error_more; $doc_root = static::$x_html_error_document_root; // default returns $html = false; // get Error $error = static::getError(); if ($error_to_show && !empty($error)) { $html = " <div class=\"x_error_info\">\n"; $c = 0; // length of document root $strlen_doc_root = strlen(Path::documentRoot()); // split error to shown on html foreach ($error as $key => $value) { /** * If static::$x_html_error_document_root is not null * will be set alternative */ if (static::$x_html_error_document_root !== null) { // safe output show replaced document root to static::$x_html_error_document_root // default set {DOCUMENT ROOT} $value['file'] = substr_replace($value['file'], static::$x_html_error_document_root !== '' ? '<span class="x_error_doc_root">' . static::$x_html_error_document_root . '</span>' : '', 0, $strlen_doc_root); } $html .= " <div class=\"x_error_section\">\n"; $html .= " <table class=\"x_error_table\">\n"; $html .= " <tr class=\"x_error_type\">\n"; $html .= " <td class=\"x_error_label\"><span>{$err_type}</span></td>\n" . " <td class=\"x_error_value\"><span><span class=\"x_error_type_code\">{$value['type']}</span>" . "<span class=\"x_error_type_string\">{$value['type_string']}</span>" . "</span></td>\n"; $html .= " </tr>\n"; $html .= " <tr class=\"x_error_message\">\n"; $html .= " <td class=\"x_error_label\"><span>{$err_msg}</span></td>\n" . " <td class=\"x_error_value\"><span>{$value['message']}</span></td>\n"; $html .= " </tr>\n"; $html .= " <tr class=\"x_error_file\">\n"; $html .= " <td class=\"x_error_label\"><span>{$err_file}</span></td>\n" . " <td class=\"x_error_value\"><span>{$value['file']}</span></td>\n"; $html .= " </tr>\n"; $html .= " <tr class=\"x_error_line\">\n"; $html .= " <td class=\"x_error_label\"><span>{$err_line}</span></td>\n" . " <td class=\"x_error_value\"><span>{$value['line']}</span></td>\n"; $html .= " </tr>\n"; $html .= " </table>\n"; $html .= " </div>\n"; $c++; /** * check if has limit */ if ($c >= $error_to_show && ($error_count = count($error) - $c) > 0) { if (static::$x_html_error_more) { $html .= " <div class=\"x_error_more\">\n"; $html .= " <div class=\"x_error_more_info\">" . str_replace('%[more_error]%', "<span class=\"x_error_more_count\">{$error_count}</span>", static::$x_html_error_more) . "</div>\n"; $html .= " </div>\n"; } // stop break; } } $html .= " </div>"; unset($error); } return $html; }
/** * Init , template * becarefull, if template has been called once it will be no affected to this init * @return object current class */ public function standardInit() { /** * If one has been called no call anymore! * @var boolean static cached */ static $has_called; // prevent multiple called if ($has_called) { return $this; } $has_called = true; $has_set = false; if (!$this->templates_directory || !is_string($this->templates_directory)) { $template = Config::Get('template_directory', null); if (!$template && ($template = realpath('templates'))) { $template = 'templates'; } elseif ($template && is_string($template)) { $has_set = true; $template = $template ? realpath(trim($template)) : null; } $this->templates_directory = !$template ? null : $template; unset($template); } /** * Checking */ if (!$this->templates_directory || is_string($this->templates_directory) && trim($this->templates_directory) !== '' && !Internal::isDir($this->templates_directory)) { if ($has_set || is_string($this->templates_directory)) { trigger_error('Templates directory does not exists!', E_USER_ERROR); } return $this; } /** * Templates Directory Replace if it can * That we just try */ Config::replace('templates_directory', $this->templates_directory); if (!$this->x_default_template || !is_string($this->x_default_template) || !trim($this->x_default_template)) { $this->x_default_template = 'Default'; } if (!is_string($this->x_file_to_read) || !trim($this->x_file_to_read)) { $this->x_file_to_read = 'templates.php'; } /** * Trimming empty right and left * @var string */ $this->x_default_template = trim($this->x_default_template); $this->x_file_to_read = trim($this->x_file_to_read); if (!is_array($this->x_mustbe_exist)) { trigger_error('Invalid Templates Definition!', E_USER_ERROR); return $this; } if (!is_array($this->x_headers)) { trigger_error('Invalid Templates Headers Definition!', E_USER_ERROR); return $this; } // add file to read to be must be exists in_array($this->x_file_to_read, $this->x_mustbe_exist) || ($this->x_mustbe_exist[] = $this->x_file_to_read); $this->templates_directory = Path::cleanPath(realpath($this->templates_directory)); $this->buildInit(); // set if (!empty($this->x_list_templates)) { if (!array_key_exists($this->x_default_template, $this->x_list_templates)) { $activeTemplate = $this->getAllTemplate(); $this->x_default_template = key($activeTemplate); } // set active templates $this->setActiveTemplate($this->x_default_template); } return $this; }