Beispiel #1
0
 /**
  * Read Directory Nested
  *
  * @param  string  $path            Path directory to be scan
  * @param  integer $directory_depth directory depth of nested to be scanned
  * @param  boolean $hidden          true if want to show hidden content
  * @return array                    path trees
  */
 public static function readDirList($path, $directory_depth = 0, $hidden = false)
 {
     $filedata = false;
     if (static::isDir($path) && ($fp = opendir($path))) {
         $new_depth = $directory_depth - 1;
         $path = Path::cleanPath($path) . '/';
         while (false !== ($file = readdir($fp))) {
             // Remove '.', '..', and hidden files [optional]
             if ($file === '.' || $file === '..' || $hidden === false && $file[0] === '.') {
                 continue;
             }
             static::isDir($path . $file) && ($path .= '/');
             if (($directory_depth < 1 || $new_depth > 0) && static::isDir($path . $file)) {
                 $filedata[$file] = static::readDirList($path . $file, $new_depth, $hidden);
             } else {
                 $filedata[] = $file;
             }
         }
         // close resource
         closedir($fp);
     }
     return $filedata;
 }
Beispiel #2
0
 /**
  * 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;
 }
Beispiel #3
0
 /**
  * Parse Request URL
  *
  * @return string Request URI parsed
  */
 protected function parseRequestUri()
 {
     // static cached
     static $return = null;
     if ($return !== null) {
         return $return;
     }
     if (!Server::get('REQUEST_URI') && !Server::get('SCRIPT_NAME')) {
         $return = '';
         return $return;
     }
     // add Request URI
     // $requri = Path::cleanSlashed(Request::getHost().'/'.Server::get('REQUEST_URI'));
     $requri = Server::get('REQUEST_URI');
     $requri = substr($requri, 0, 1) == '/' ? $requri : "/{$requri}";
     $requri = rtrim(Request::getHost(), '/') . $requri;
     $uri = parse_url('http://' . $requri);
     $query = isset($uri['query']) ? $uri['query'] : '';
     $uri = isset($uri['path']) ? $uri['path'] : '';
     $script_name = Server::get('SCRIPT_NAME');
     if (isset($script_name[0])) {
         /**
          * Set New URL Path
          */
         if (strpos($uri, $script_name) === 0) {
             $uri = substr($uri, strlen($script_name));
         } elseif (strpos($uri, dirname($script_name)) === 0) {
             $uri = substr($uri, strlen(dirname($script_name)));
         }
     }
     // This section ensures that even on servers that require the URI to be in the query string (Nginx) a correct
     // URI is found, and also fixes the QUERY_STRING server var and $_GET array.
     if (trim($uri, '/') === '' && strncmp($query, '/', 1) === 0) {
         $query = explode('?', $query, 2);
         $uri = $query[0];
         $_SERVER['QUERY_STRING'] = isset($query[1]) ? $query[1] : '';
     } else {
         $_SERVER['QUERY_STRING'] = $query;
     }
     // replace server attributes
     Server::replace($_SERVER);
     // parse the string
     parse_str($_SERVER['QUERY_STRING'], $_GET);
     // replace get
     Get::replace($_GET);
     if ($uri === '/' || $uri === '') {
         $return = '/';
     } else {
         $return = Path::removeRelativeDirectory($uri);
     }
     return $return;
 }
Beispiel #4
0
 public function setActiveTemplateDirectory($directory)
 {
     if (Internal::isDir($directory)) {
         $active = $this->getActiveTemplate();
         $this->x_list_templates[$active]['Directory'] = Path::cleanSlashed($directory);
         return true;
     }
     return false;
 }
Beispiel #5
0
 /**
  * Default error 500 output Handler
  */
 public static function error500()
 {
     $args_ = func_get_args();
     $template = Template::singleton();
     $template_dir = $template->getActiveTemplateDirectory();
     static::$x_is_fatal = true;
     if ($template_dir && $template->x_500_file && is_string($template->x_500_file)) {
         if (is_file("{$template_dir}/{$template->x_500_file}")) {
             $message = (array) reset($args_);
             // using callback to prevent direct access
             return call_user_func(function ($a) use($message) {
                 ob_start();
                 require $a;
                 $content = ob_get_clean();
                 Response::setBody($content);
                 static::displayRender();
                 exit(1);
                 // and then exit here
             }, "{$template_dir}/{$template->x_500_file}");
         }
     }
     /**
      * Body container
      * @var string
      */
     $body = "<h1 class=\"big\">500</h1>\n";
     if (Config::get('debug', true)) {
         $args_ = current($args_);
         $strlen_doc_root = strlen(Path::documentRoot());
         // safe output show replaced document root to {DOCUMENT ROOT}
         $args_['file'] = substr_replace($args_['file'], '<span class="x_error_doc_root">{DOCUMENT ROOT}</span>', 0, $strlen_doc_root);
         $body .= "    <div class=\"x_error_section\">\n" . "      <table class=\"x_error_table\">\n" . "        <tr class=\"x_error_type\">\n" . "          <td class=\"x_error_label\"><span>Error Type</span></td>\n" . "          <td class=\"x_error_value\"><span><span class=\"x_error_type_code\">{$args_['type']}</span>" . "<span class=\"x_error_type_string\">{$args_['type_string']}</span></span></td>\n" . "        </tr>\n" . "        <tr class=\"x_error_message\">\n" . "          <td class=\"x_error_label\"><span>Error Message</span></td>\n" . "          <td class=\"x_error_value\"><span>{$args_['message']}</span></td>\n" . "        </tr>\n" . "        <tr class=\"x_error_file\">\n" . "          <td class=\"x_error_label\"><span>Error File</span></td>\n" . "          <td class=\"x_error_value\"><span>{$args_['file']}</span></td>\n" . "        </tr>\n" . "        <tr class=\"x_error_line\">\n" . "          <td class=\"x_error_label\"><span>Error Line</span></td>\n" . "          <td class=\"x_error_value\"><span>{$args_['line']}</span></td>\n" . "        </tr>\n" . "      </table>\n" . "    </div>\n";
     } else {
         $body .= "<h2 class=\"desc\">Internal Server Error</h2>\n" . "<p>We are sorry for inconvenience</p>";
     }
     /**
      * Set Body
      */
     Response::setBody(Html::create('Internal Server Error', $body, array('style' => "body{font-size: 14px;font-family: helvetica, arial, sans-serif;color: #555;line-height: normal;background: #f1f1f1;}\n" . ".wrap{margin: 0 auto;max-width: 700px;text-align: center;}\n" . (Config::get('debug', false) ? ".x_error_section{display:block;padding: 10px;background: #fff;border: 1px solid #ddd;}\n" . ".x_error_table{border-collapse: collapse;border:0;border-spacing:0;}\n" . ".x_error_label{padding: 5px 10px;text-align: left;border-right: 2px solid #bbb;}\n" . ".x_error_value{padding: 5px 10px;text-align: left;border-right: 0px solid #ddd;}\n" . ".x_error_type .x_error_type_string{background: #f18181;padding: 3px 5px;color:#fff;font-weight: bold;margin-left:0px;}\n" . ".x_error_type .x_error_type_code{background: #4359fe;margin-right: 0px;padding: 3px 6px;color:#fff;font-weight: bold;}\n" : '') . ".big{font-size: 180px;margin: .7em 0 20px;}\n.desc{font-size: 28px;margin: .3em 0 0;}")));
     // doing display
     static::displayRender();
     exit(1);
     // and then exit here
 }