Esempio n. 1
0
 /** Get set of default e-mail headers
  * @return array
  */
 public static function get_default_headers()
 {
     if (!isset(self::$default_headers['X-Mailer'])) {
         self::$default_headers["X-Mailer"] = \System\Status::introduce();
     }
     return self::$default_headers;
 }
Esempio n. 2
0
 /** Make a get request to URL
  * @param string $url Requested URL
  * @return array
  */
 public static function get($url, $head = false)
 {
     if (function_exists('curl_init')) {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_USERAGENT, \System\Status::introduce());
         curl_setopt($ch, CURLOPT_HEADER, 1);
         if ($head) {
             curl_setopt($ch, CURLOPT_NOBODY, true);
         }
         $content = curl_exec($ch);
         $dataray = array("status" => curl_getinfo($ch, CURLINFO_HTTP_CODE));
         curl_close($ch);
         if ($dataray['status'] === \System\Http\Response::NO_RESPONSE) {
             throw new \System\Error\Connection(sprintf('Remote server was not found for URL "%s".', $url));
         }
         if ($dataray['status'] === \System\Http\Response::FORBIDDEN) {
             throw new \System\Error\Offcom(sprintf('Access to URL "%s" was denied', $url));
         }
         if ($dataray['status'] === \System\Http\Response::PAGE_NOT_FOUND) {
             throw new \System\Error\Offcom(sprintf('Requested URL "%s" was not found', $url));
         }
         isset($content[1]) && ($dataray['content'] = $content);
         return new Response($dataray);
     } else {
         throw new \System\Error\Internal('Please allow CURL extension for System\\Offcom\\Request class');
     }
 }
Esempio n. 3
0
 /** Dump function - displays debug info on all arguments
  * @return void
  */
 function v()
 {
     $trace = debug_backtrace();
     $var = func_get_args();
     if (count($var) == 1) {
         $var = $var[0];
     }
     $path = '';
     if (isset($trace[0]['file'])) {
         $path .= basename($trace[0]['file']);
         if (isset($trace[0]['line'])) {
             $path .= ":" . $trace[0]['line'];
         }
         $path .= ", ";
     }
     if (isset($trace[0]['class'])) {
         $path .= $trace[0]['class'] . '::' . $trace[0]['function'] . "()";
     } elseif (isset($trace[0]['function'])) {
         $path .= $trace[0]['function'] . "()";
     }
     try {
         $cli = \System\Status::on_cli();
     } catch (\Exception $e) {
         $cli = true;
     }
     if (!$cli) {
         echo '<div class="debug dump"><b>' . $path . "</b><pre>";
     }
     function_exists('var_export') && !is_string($var) ? var_dump($var) : print_r($var);
     if ($cli) {
         echo "\n";
     } else {
         echo '</pre></div>';
     }
 }
Esempio n. 4
0
 public static function cmd_config()
 {
     \System\Init::full();
     \Helper\Cli::out_flist(array("list" => array("Framework" => \System\Status::introduce(), "Environment" => \System\Settings::get_env())));
     \Helper\Cli::out();
     \Helper\Cli::out("Loaded config files");
     \Helper\Cli::sep();
     \Helper\Cli::out_flist(array("list" => \System\Settings::get_loaded_files(), "margin" => 2, "show_keys" => false));
 }
Esempio n. 5
0
 /** Create request object from current hit
  * @return self
  */
 public static function from_hit()
 {
     if (\System\Status::on_cli()) {
         $data = array("time" => def($_SERVER['REQUEST_TIME_FLOAT'], microtime(true)), "cli" => true, "secure" => false);
     } else {
         $data = array("cli" => false, "ajax" => strtolower(def($_SERVER['HTTP_X_REQUESTED_WITH'])) == self::IDENT_XHR, "host" => def($_SERVER['HTTP_HOST']), "path" => def($_SERVER['REQUEST_URI']), "protocol" => def($_SERVER['REQUEST_SCHEME']), "referrer" => def($_SERVER['HTTP_REFERER']), "agent" => def($_SERVER['HTTP_USER_AGENT']), "query" => def($_SERVER['QUERY_STRING']), "time" => def($_SERVER['REQUEST_TIME_FLOAT'], microtime(true)), "secure" => any($_SERVER['HTTPS']), "method" => strtolower(def($_SERVER['REQUEST_METHOD'])), "cookies" => &$_COOKIE, "session" => &$_SESSION);
         if ($data['query']) {
             $path = explode('?', $data['path']);
             $data['path'] = $path[0];
         }
         if (isset($_GET['path'])) {
             $data['path'] = $_GET['path'];
         }
     }
     $obj = new self($data);
     return $obj->prepare_input();
 }
Esempio n. 6
0
 /** Render HTML meta tag section
  * @return $this
  */
 public function render_meta()
 {
     $this->content_for("meta", array("name" => 'generator', "content" => \System\Status::introduce()));
     $this->content_for("meta", array("http-equiv" => 'content-type', "content" => 'text/html; charset=utf-8'));
     $this->content_for("meta", array("charset" => 'utf-8'));
     $meta = $this->get_content_from("meta");
     foreach ($meta as $name => $value) {
         if ($value) {
             $this->content_for("head", '<meta' . \System\Template\Tag::html_attrs('meta', $value) . '>');
         }
     }
     return $this;
 }
Esempio n. 7
0
 /** Send HTTP headers
  * @return void
  */
 public function send_headers()
 {
     if (\System\Status::on_cli()) {
         return $this;
     }
     session_write_close();
     def($this->headers['Content-Encoding'], 'gz');
     def($this->headers['Generator'], 'pwf');
     if (!isset($this->headers['Content-Type'])) {
         if ($this->mime) {
             $mime = $this->mime;
         } else {
             try {
                 $mime = \System\Output::get_mime($this->renderer->format);
             } catch (\System\Error\Argument $e) {
                 $mime = 'text/html; charset=utf-8';
             }
         }
         def($this->headers["Content-Type"], $mime . ";charset=utf-8");
     }
     if (isset($this->size)) {
         def($this->headers['Content-Length'], $this->size);
     }
     if ($this->status == self::OK && empty($this->content)) {
         $this->status(self::NO_CONTENT);
     }
     header(self::get_status($this->status));
     foreach ($this->headers as $name => $content) {
         if (is_numeric($name)) {
             header($content);
         } else {
             $name = implode('-', array_map('ucfirst', explode('-', $name)));
             header($name . ": " . $content);
         }
     }
     return $this;
 }