コード例 #1
0
ファイル: superglobal.php プロジェクト: nemein/openpsa
 /**
  * Returns the complete context data array
  *
  * @return array The data of all contexts
  */
 function get_all_contexts()
 {
     return midcom_core_context::get_all();
 }
コード例 #2
0
ファイル: content.php プロジェクト: nemein/openpsa
 /**
  * This little helper ensures that the headers Accept-Ranges, Content-Length
  * and Last-Modified are present. The lastmod timestamp is taken out of the
  * component context information if it is populated correctly there; if not, the
  * system time is used instead.
  *
  * To force browsers to revalidate the page on every request (login changes would
  * go unnoticed otherwise), the Cache-Control header max-age=0 is added automatically.
  *
  * @param Array &$cache_data The current cache data that will be written to the database.
  */
 private function _complete_sent_headers(&$cache_data)
 {
     // Detected headers flags
     $ranges = false;
     $size = false;
     $lastmod = false;
     foreach ($this->_sent_headers as $header) {
         if (strncasecmp($header, 'Accept-Ranges', 13) == 0) {
             $ranges = true;
         } else {
             if (strncasecmp($header, 'Content-Length', 14) == 0) {
                 $size = true;
             } else {
                 if (strncasecmp($header, 'Last-Modified', 13) == 0) {
                     $lastmod = true;
                     // Populate last modified timestamp (force GMT):
                     $tmp = substr($header, 15);
                     if (strpos($tmp, 'GMT') === false) {
                         $tmp .= ' GMT';
                     }
                     $this->_last_modified = strtotime($tmp);
                     if ($this->_last_modified == -1) {
                         debug_add("Failed to extract the timecode from the last modified header '{$header}', defaulting to the current time.", MIDCOM_LOG_WARN);
                         $this->_last_modified = time();
                     }
                 }
             }
         }
     }
     if (!$ranges) {
         $header = "Accept-Ranges: none";
         _midcom_header($header);
         $this->_sent_headers[] = $header;
     }
     if (!$size) {
         /* TODO: Doublecheck the way this is handled, it seems it's one byte too short
            which causes issues with Squid for example (could be that we output extra
            whitespace somewhere or something), now we just don't send it if headers_strategy
            implies caching */
         switch ($this->_headers_strategy) {
             case 'public':
             case 'private':
                 break;
             default:
                 $header = "Content-Length: " . ob_get_length();
                 _midcom_header($header);
                 $this->_sent_headers[] = $header;
                 break;
         }
     }
     if (!$lastmod) {
         /* Determine Last-Modified using MidCOM's component context,
          * Fallback to time() if this fails.
          */
         $time = 0;
         foreach (midcom_core_context::get_all() as $id => $context) {
             $meta = midcom::get('metadata')->get_request_metadata($id);
             if ($meta['lastmodified'] > $time) {
                 $time = $meta['lastmodified'];
             }
         }
         if ($time == 0 || !is_numeric($time)) {
             $time = time();
         }
         $header = "Last-Modified: " . gmdate('D, d M Y H:i:s', $time) . ' GMT';
         _midcom_header($header);
         $this->_sent_headers[] = $header;
         $this->_last_modified = $time;
     }
     $this->cache_control_headers();
     if (is_array($this->_force_headers) && !empty($this->_force_headers)) {
         foreach ($this->_force_headers as $header => $value) {
             $header_string = "{$header}: {$value}";
             _midcom_header($header_string, true);
             $this->_replace_sent_header($header, $header_string);
         }
     }
 }