コード例 #1
0
 /**
  * Create a stream context for the request
  */
 protected function _ctx()
 {
     $content = '';
     # Prepare headers
     $headers = $this->headers->exportPlain();
     # Post data
     if (!empty($this->post) || !empty($this->upload)) {
         $this->method = 'POST';
     }
     # File uploads
     if (empty($this->upload)) {
         // Generic POST
         $content = $this->_http_build_query($this->post);
         $headers[] = 'Content-Type: application/x-www-form-urlencoded';
     } else {
         # Prepare multipart
         $boundary = '--------------------------' . uniqid() . uniqid();
         $headers[] = 'Content-Type: multipart/form-data; boundary=' . $boundary;
         # Generic fields
         foreach ($this->_http_build_query_array($this->post) as $name => $value) {
             $content .= "--" . $boundary . "\r\n";
             $content .= 'Content-Disposition: form-data; name="' . $name . '"' . "\r\n";
             $content .= "\r\n";
             $content .= $value;
             $content .= "\r\n";
         }
         # File uploads
         foreach ($this->upload as $upload) {
             $content .= "--" . $boundary . "\r\n";
             $content .= 'Content-Disposition: form-data; name="' . $upload->name . '"; filename="' . $upload->filename . '"' . "\r\n";
             if (!empty($upload->mime)) {
                 $content .= 'Content-Type: ' . $upload->mime . "\r\n";
             }
             $content .= "\r\n";
             $content .= $upload->contents;
             $content .= "\r\n";
         }
         # Finalize
         $content .= "--" . $boundary . "--\r\n";
     }
     // Create the context
     $ctx = stream_context_create(array('http' => array('method' => $this->method, 'content' => $content, 'timeout' => $this->options['timeout'], 'header' => implode("\r\n", $headers))));
     #echo '<pre>', var_export($headers,1), htmlspecialchars($content), '</pre>'; die();
     // Finish
     return $ctx;
 }
コード例 #2
0
ファイル: css.php プロジェクト: cbsistem/nexos
| GPL V2 or higher.                                                 |
+-------------------------------------------------------------------+
| block-Sample.php - Example NexOS block file                       |
| Authors:                                                          |
|  Steven Sheeley                                                   |
|  Richard R. Pufky                                                 |
|      and the Myndworx Asylum Dev Team                             |
| eMail: support at myndworx dot com                                |
| Website: http://www.nexoscms.org and http://www.myndworx.com      |
+-------------------------------------------------------------------+
|Original Copyright below                                           |
+-------------------------------------------------------------------+
*/
/*********************************************
  Dragonfly CMS, Copyright (c) 2004 by CPGNuke Dev Team
  http://dragonflycms.org
  Released under GNU GPL version 2 or any later version

  $Source: /cvs/html/includes/load/css.php,v $
  $Revision: 1.1 $
  $Author: nanocaiordo $
  $Date: 2011/04/17 06:50:09 $
**********************************************/
if (!defined('CPG_NUKE')) {
    exit;
}
require CLASS_PATH . 'css.php';
if (false === CSS::request()) {
    HttpHeaders::flush(404, 'File not found');
}
CSS::flushToClient();
コード例 #3
0
ファイル: js.php プロジェクト: cbsistem/nexos
 public static final function flushToClient()
 {
     $ETag = md5(implode(';', self::$files));
     $gzip = GZIP_OUT ? '.gz' : '';
     $cachedFile = CACHE_PATH . 'js#' . $ETag;
     header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time() + (DEVELOPER_MODE ? 0 : 60 * 60 * 24)));
     header('Cache-Control: public');
     header('Content-Type: application/javascript; charset: utf-8');
     if (!DEVELOPER_MODE && is_file($cachedFile . $gzip) && filemtime($cachedFile . $gzip) > self::$mtime) {
         if ($gzip) {
             header('Content-Encoding: gzip');
         }
         header('Content-Length:' . filesize($cachedFile . $gzip));
         if ($status = HttpUtils::entityCache($ETag, self::$mtime)) {
             HttpHeaders::flush($status);
         } else {
             readfile($cachedFile . $gzip);
         }
         exit;
     }
     $buffer = '';
     foreach (self::$files as $file) {
         $buffer .= file_get_contents($file);
     }
     $buffer = preg_replace('#^(\\s+)#m', '', $buffer);
     $buffer = preg_replace('#[\\r\\n]+#', '', $buffer);
     $buffer = str_replace(';}', '}', $buffer);
     if (GZIPSUPPORT && ($gz = gzopen($cachedFile . '.gz', 'w9'))) {
         gzwrite($gz, $buffer);
         gzclose($gz);
     }
     file_put_contents($cachedFile, $buffer);
     if (is_file($cachedFile . $gzip) || !$gzip) {
         if ($gzip) {
             header('Content-Encoding: gzip');
         }
         header('Content-Length:' . filesize($cachedFile . $gzip));
         exit(readfile($cachedFile . $gzip));
     } else {
         ob_start('ob_gzhandler');
         exit($buffer);
     }
 }
コード例 #4
0
ファイル: httpheaders.php プロジェクト: cbsistem/nexos
 /**
  * @access public clear Reset class headers buffer
  */
 public static function clear()
 {
     self::$to_send = array();
 }
コード例 #5
0
ファイル: css.php プロジェクト: cbsistem/nexos
 public static final function flushToClient()
 {
     $ETag = md5(implode(';', self::$files));
     $gzip = GZIP_OUT ? '.gz' : '';
     $cachedFile = CACHE_PATH . 'css#' . $ETag;
     header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time() + (DEVELOPER_MODE ? 0 : 60 * 60 * 24)));
     header('Cache-Control: public');
     header('Content-Type: text/css; charset: utf-8');
     if (!DEVELOPER_MODE && is_file($cachedFile . $gzip) && filemtime($cachedFile . $gzip) > self::$mtime) {
         if ($gzip) {
             header('Content-Encoding: gzip');
         }
         header('Content-Length:' . filesize($cachedFile . $gzip));
         if ($status = HttpUtils::entityCache($ETag, self::$mtime)) {
             HttpHeaders::flush($status);
         } else {
             readfile($cachedFile . $gzip);
         }
         exit;
     }
     $buffer = '';
     foreach (self::$files as $file) {
         $buffer .= file_get_contents($file);
     }
     $buffer = preg_replace('#((url\\(|src=)["\']?)(../)?images/#', '$1' . BASEHREF . 'themes/' . self::$theme . '/images/', $buffer);
     $buffer = trim(preg_replace('#\\s+#', ' ', $buffer));
     $buffer = preg_replace('#/\\*.*?\\*/#s', '', $buffer);
     $buffer = preg_replace('#\\s*[^{}]+{\\s*}\\s*#', '', $buffer);
     $buffer = preg_replace('#\\s*([{},;:])\\s*#', '$1', $buffer);
     $buffer = str_replace(';}', '}', $buffer);
     if (GZIPSUPPORT && ($gz = gzopen($cachedFile . '.gz', 'w9'))) {
         gzwrite($gz, $buffer);
         gzclose($gz);
     }
     file_put_contents($cachedFile, $buffer);
     if (is_file($cachedFile . $gzip) || !$gzip) {
         if ($gzip) {
             header('Content-Encoding: gzip');
         }
         header('Content-Length:' . filesize($cachedFile . $gzip));
         exit(readfile($cachedFile . $gzip));
     } else {
         ob_start('ob_gzhandler');
         exit($buffer);
     }
 }
コード例 #6
0
ファイル: httputils.php プロジェクト: cbsistem/nexos
 /**
  * http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.3.3
  * http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.19 .24 .25 .26 .28 .44
  * if the request method is GET or HEAD, the server SHOULD respond with a 304 (Not Modified) response,
  * including the cache- related header fields (particularly ETag) of one of the entities that matched.
  * For all other request methods, the server MUST respond with a status of 412 (Precondition Failed).
  */
 public final function entityCache($ETag, $time)
 {
     $ETag = "\"{$ETag}\"";
     HttpHeaders::add('ETag: ' . $ETag);
     if (!empty($_SERVER['HTTP_IF_NONE_MATCH'])) {
         if (false !== strpos($_SERVER['HTTP_IF_NONE_MATCH'], $ETag)) {
             return 304;
         }
         # If none of the entity tags match,
         # then the server MAY perform the requested method as if the If-None-Match header field did not exist,
         # but MUST also ignore any If-Modified-Since header field(s) in the request.
         $_SERVER['HTTP_IF_MODIFIED_SINCE'] = null;
     }
     if (isset($_SERVER['HTTP_IF_MATCH']) && false === strpos($_SERVER['HTTP_IF_MATCH'], $ETag)) {
         return 412;
     }
     $time = (int) $time;
     HttpHeaders::add('Last-Modified: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', $time));
     # DATE_RFC1123
     if (!empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $time <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
         return 304;
     }
     if (!empty($_SERVER['HTTP_IF_UNMODIFIED_SINCE']) && $time > strtotime($_SERVER['HTTP_IF_UNMODIFIED_SINCE'])) {
         return 412;
     }
     HttpHeaders::flush();
 }