Example #1
0
 public static function serve_attachment($guid)
 {
     $attachment = new midcom_db_attachment($guid);
     $resolver = new midcom_core_resolver(midcom_core_context::get());
     $resolver->serve_attachment($attachment);
 }
Example #2
0
 /**
  * Deliver a blob to the client.
  *
  * This is a replacement for mgd_serve_attachment that should work around most of
  * its bugs: It is missing all important HTTP Headers concerning file size,
  * modification date and expiration. It will not call _midcom_stop_request() when it is finished,
  * you still have to do that yourself. It will add the following HTTP Headers:
  *
  * - Cache-Control: public max-age=$expires
  * - Expires: GMT Date $now+$expires
  * - Last-Modified: GMT Date of the last modified timestamp of the Attachment
  * - Content-Length: The Length of the Attachment in Bytes
  * - Accept-Ranges: none
  *
  * This should enable caching of browsers for Navigation images and so on. You can
  * influence the expiration of the served attachment with the parameter $expires.
  * It is the time in seconds till the client should refetch the file. The default
  * for this is 24 hours. If you set it to "0" caching will be prohibited by
  * changing the sent headers like this:
  *
  * - Pragma: no-cache
  * - Cache-Control: no-cache
  * - Expires: Current GMT Date
  *
  * If expires is set to -1, no expires header gets sent.
  *
  * @param MidgardAttachment &$attachment    A reference to the attachment to be delivered.
  * @param int $expires HTTP-Expires timeout in seconds, set this to 0 for uncacheable pages, or to -1 for no Expire header.
  */
 function serve_attachment(&$attachment, $expires = -1)
 {
     $resolver = new midcom_core_resolver(midcom_core_context::get());
     $resolver->serve_attachment($attachment, $expires);
 }
Example #3
0
 /**
  * Process the request
  *
  * Basically this method will parse the URL and search for a component that can
  * handle the request. If one is found, it will process the request, if not, it
  * will report an error, depending on the situation.
  *
  * Details: The logic will traverse the node tree and for each node it will load
  * the component that is responsible for it. This component gets the chance to
  * accept the request (this is encapsulated in the _can_handle call), which is
  * basically a call to can_handle. If the component declares to be able to handle
  * the call, its handle function is executed. Depending if the handle was successful
  * or not, it will either display an HTTP error page or prepares the content handler
  * to display the content later on.
  *
  * If the parsing process doesn't find any component that declares to be able to
  * handle the request, an HTTP 404 - Not Found error is triggered.
  */
 private function _process(midcom_core_context $context)
 {
     $resolver = new midcom_core_resolver($context);
     $handler = $resolver->process();
     if (false === $handler) {
         /**
          * Simple: if current context is not '0' we were called from another context.
          * If so we should not break application now - just gracefully continue.
          */
         if ($context->id == 0) {
             // We couldn't fetch a node due to access restrictions
             if (midcom_connection::get_error() == MGD_ERR_ACCESS_DENIED) {
                 throw new midcom_error_forbidden(midcom::get('i18n')->get_string('access denied', 'midcom'));
             } else {
                 throw new midcom_error_notfound("This page is not available on this server.");
             }
         }
         $this->_status = MIDCOM_STATUS_ABORT;
         return false;
     }
     $context->run($handler);
     if ($context->id == 0 && $this->skip_page_style == true) {
         $this->_status = MIDCOM_STATUS_CONTENT;
         // Enter Context
         $oldcontext = $context;
         midcom_core_context::get(0)->set_current();
         midcom::get('style')->enter_context(0);
         $this->_output();
         // Leave Context
         midcom::get('style')->leave_context();
         $oldcontext->set_current();
         $this->finish();
         _midcom_stop_request();
     } else {
         $this->_status = MIDCOM_STATUS_CONTENT;
     }
 }