Ejemplo n.º 1
0
 /**
  * Get the path to the document in the static cache
  *
  * @return string
  */
 static function get_cache_path(midcom_db_attachment $attachment, $check_privileges = true)
 {
     if (!$GLOBALS['midcom_config']['attachment_cache_enabled']) {
         return null;
     }
     // Check if the attachment can be read anonymously
     if ($check_privileges && !$attachment->can_do('midgard:read', 'EVERYONE')) {
         return null;
     }
     // Copy the file to the static directory
     if (!file_exists($GLOBALS['midcom_config']['attachment_cache_root'])) {
         mkdir($GLOBALS['midcom_config']['attachment_cache_root']);
     }
     $subdir = substr($attachment->guid, 0, 1);
     if (!file_exists("{$GLOBALS['midcom_config']['attachment_cache_root']}/{$subdir}")) {
         mkdir("{$GLOBALS['midcom_config']['attachment_cache_root']}/{$subdir}");
     }
     $filename = "{$GLOBALS['midcom_config']['attachment_cache_root']}/{$subdir}/{$attachment->guid}_{$attachment->name}";
     return $filename;
 }
Ejemplo n.º 2
0
 private function _process_serveattachmentguid($value)
 {
     if ($this->_context->parser->argc > 1) {
         debug_add('Too many arguments remaining for serve_attachment.', MIDCOM_LOG_ERROR);
     }
     $attachment = new midcom_db_attachment($value);
     if (!$attachment->can_do('midgard:autoserve_attachment')) {
         throw new midcom_error_notfound('Failed to access attachment: Autoserving denied.');
     }
     $this->serve_attachment($attachment);
     midcom::get()->finish();
     _midcom_stop_request();
 }