예제 #1
0
파일: Type.php 프로젝트: raz0rsdge/horde
 function getUploadedFileType($field)
 {
     /* Get any index on the field name. */
     $index = Horde_Array::getArrayParts($field, $base, $keys);
     if ($index) {
         /* Index present, fetch the mime type var to check. */
         $keys_path = array_merge(array($base, 'type'), $keys);
         $type = Horde_Array::getElement($_FILES, $keys_path);
         $keys_path = array_merge(array($base, 'tmp_name'), $keys);
         $tmp_name = Horde_Array::getElement($_FILES, $keys_path);
     } else {
         /* No index, simple set up of vars to check. */
         $type = $_FILES[$field]['type'];
         $tmp_name = $_FILES[$field]['tmp_name'];
     }
     if (empty($type) || $type == 'application/octet-stream') {
         /* Type wasn't set on upload, try analising the upload. */
         if (!($type = Horde_Mime_Magic::analyzeFile($tmp_name, isset($GLOBALS['conf']['mime']['magic_db']) ? $GLOBALS['conf']['mime']['magic_db'] : null))) {
             if ($index) {
                 /* Get the name value. */
                 $keys_path = array_merge(array($base, 'name'), $keys);
                 $name = Horde_Array::getElement($_FILES, $keys_path);
                 /* Work out the type from the file name. */
                 $type = Horde_Mime_Magic::filenameToMime($name);
                 /* Set the type. */
                 $keys_path = array_merge(array($base, 'type'), $keys);
                 Horde_Array::getElement($_FILES, $keys_path, $type);
             } else {
                 /* Work out the type from the file name. */
                 $type = Horde_Mime_Magic::filenameToMime($_FILES[$field]['name']);
                 /* Set the type. */
                 $_FILES[$field]['type'] = Horde_Mime_Magic::filenameToMime($_FILES[$field]['name']);
             }
         }
     }
     return $type;
 }
예제 #2
0
파일: Api.php 프로젝트: horde/horde
 /**
  * Return an event attachment.
  *
  * @param string $calendar  The calendar ID.
  * @param string $uid       The UID of the event the file is attached to.
  * @param string $filename  The name of the file.
  *
  * @return array  An array containing the following keys:
  *   data (stream):  A file pointer to the attachment data.
  *   content-type (string): The mime-type of the contents.
  *
  * @throws Kronolith_Exception
  * @since  4.3.0
  */
 public function getAttachment($calendar, $uid, $filename)
 {
     $event = $this->eventFromUID($uid, $calendar);
     // Use localfile so we can use a stream.
     try {
         $local_file = $event->vfsInit()->readFile(Kronolith::VFS_PATH . '/' . $event->getVfsUid(), $filename);
         if (!($fp = @fopen($local_file, 'rb'))) {
             throw new Kronolith_Exception('Unable to open attachment.');
         }
     } catch (Horde_Vfs_Exception $e) {
         throw new Kronolith_Exception($e);
     }
     // Try to determine type.
     return array('data' => $fp, 'content-type' => Horde_Mime_Magic::filenameToMime($filename, false));
 }
예제 #3
0
 /**
  * Creates a new file in the directory
  *
  * @param string $name Name of the file
  * @param resource|string $data Initial payload
  * @return null|string
  */
 public function createFile($name, $data = null)
 {
     list($app) = explode('/', $this->_path);
     if (is_resource($data)) {
         $content = new Horde_Stream_Existing(array('stream' => $data));
         $type = Horde_Mime_Magic::analyzeData($content->getString(0, 100), $this->_mimedb);
     } else {
         $content = $data;
         $type = Horde_Mime_Magic::analyzeData($content, $this->_mimedb);
     }
     if (!$type) {
         $type = Horde_Mime_Magic::filenameToMime($name);
     }
     try {
         $this->_registry->callByPackage($app, 'put', array($this->_path . '/' . $name, $content, $type));
     } catch (Horde_Exception $e) {
         throw new DAV\Exception($e->getMessage(), $e->getCode(), $e);
     }
 }
예제 #4
0
파일: Luxor.php 프로젝트: jubinpatel/horde
 function dirExpand($dir)
 {
     global $files, $mime_drivers, $mime_drivers_map;
     $result = Horde::loadConfiguration('mime_drivers.php', array('mime_drivers', 'mime_drivers_map'), 'horde');
     extract($result);
     $result = Horde::loadConfiguration('mime_drivers.php', array('mime_drivers', 'mime_drivers_map'), 'luxor');
     if (isset($result['mime_drivers'])) {
         $mime_drivers = array_replace_recursive($mime_drivers, $result['mime_drivers']);
     }
     if (isset($result['mime_drivers_map'])) {
         $mime_drivers_map = array_replace_recursive($mime_drivers_map, $result['mime_drivers_map']);
     }
     $nodes = $files->getDir($dir);
     if (is_a($nodes, 'PEAR_Error')) {
         return $nodes;
     }
     $index = $files->getIndex($dir);
     if (is_a($index, 'PEAR_Error')) {
         return $index;
     }
     if ($dir != '/') {
         array_unshift($nodes, '../');
     }
     $list = array();
     foreach ($nodes as $node) {
         $link = Luxor::url($dir . $node);
         $modtime = $files->getFiletime($dir . $node);
         $modtime = $modtime ? gmdate('Y-m-d H:i:s', $modtime) : '-';
         $description = empty($index[$node]) ? ' ' : $index[$node];
         if (substr($node, -1) == '/') {
             $filesize = '-';
             $bytes = '';
             if ($node == '../') {
                 $icon = Horde::img('parent.png', _("Up to parent"));
                 $node = _("Parent Directory");
             } else {
                 $icon = Horde::img('folder.png', $node);
             }
         } else {
             if (preg_match('/^.*\\.[oa]$|^core$|^00-INDEX$/', $node)) {
                 continue;
             }
             $icon = Horde::img($GLOBALS['injector']->getInstance('Horde_Core_Factory_MimeViewer')->getIcon(Horde_Mime_Magic::filenameToMime($node)), '', '', '');
             $filesize = $files->getFilesize($dir . $node);
             if ($filesize < 1 << 10) {
                 $bytes = _("bytes");
             } else {
                 $bytes = _("kbytes");
                 $filesize = $filesize >> 10;
             }
         }
         $list[] = array('icon' => $icon, 'name' => $node, 'link' => $link, 'filesize' => $filesize, 'bytes' => $bytes, 'modtime' => $modtime, 'description' => $description);
     }
     return $list;
 }
예제 #5
0
파일: Driver.php 프로젝트: raz0rsdge/horde
 /**
  * Sends email notifications to a list of recipients.
  *
  * We do some ugly work in here to make sure that no one gets comments
  * mailed to them that they shouldn't see (because of group permissions).
  *
  * @param array $opts  Option hash with notification information.
  *                     Possible values:
  *                     - ticket:     (Whups_Ticket) A ticket. If not set,
  *                                   this is assumed to be a reminder
  *                                   message.
  *                     - recipients: (array|string) The list of recipients,
  *                                   with user names as keys and user roles
  *                                   as values.
  *                     - subject:    (string) The email subject.
  *                     - view:       (Horde_View) The view object for the
  *                                   message text.
  *                     - template:   (string) The template file for the
  *                                   message text.
  *                     - from:       (string) The email sender.
  *                     - new:        (boolean, optional) Whether the passed
  *                                   ticket was just created.
  */
 public function mail(array $opts)
 {
     global $conf, $registry, $prefs;
     $opts = array_merge(array('ticket' => false, 'new' => false), $opts);
     /* Set up recipients and message headers. */
     $mail = new Horde_Mime_Mail(array('X-Whups-Generated' => 1, 'User-Agent' => 'Whups ' . $registry->getVersion(), 'Precedence' => 'bulk', 'Auto-Submitted' => $opts['ticket'] ? 'auto-replied' : 'auto-generated'));
     $mail_always = null;
     if ($opts['ticket'] && !empty($conf['mail']['always_copy'])) {
         $mail_always = $conf['mail']['always_copy'];
         if (strpos($mail_always, '<@>') !== false) {
             try {
                 $mail_always = str_replace('<@>', $opts['ticket']->get('queue_name'), $mail_always);
             } catch (Whups_Exception $e) {
                 $mail_always = null;
             }
         }
         if ($mail_always && !isset($opts['recipients'][$mail_always])) {
             $opts['recipients'][$mail_always] = 'always';
         }
     }
     if ($opts['ticket'] && ($queue = $this->getQueue($opts['ticket']->get('queue'))) && !empty($queue['email'])) {
         $mail->addHeader('From', $queue['email']);
     } elseif (!empty($conf['mail']['from_addr'])) {
         $mail->addHeader('From', $conf['mail']['from_addr']);
     } else {
         $mail->addHeader('From', Whups::formatUser($opts['from']));
     }
     if (!empty($conf['mail']['return_path'])) {
         $mail->addHeader('Return-Path', $conf['mail']['return_path']);
     }
     if ($opts['ticket']) {
         $opts['subject'] = '[' . $registry->get('name') . ' #' . $opts['ticket']->getId() . '] ' . $opts['subject'];
     }
     $mail->addHeader('Subject', $opts['subject']);
     /* Get our array of comments, sorted in the appropriate order. */
     if ($opts['ticket']) {
         $comments = $this->getHistory($opts['ticket']->getId());
         if ($conf['mail']['commenthistory'] == 'new' && count($comments)) {
             $comments = array_pop($comments);
             $comments = array($comments);
         } elseif ($conf['mail']['commenthistory'] != 'chronological') {
             $comments = array_reverse($comments);
         }
     } else {
         $comments = array();
     }
     /* Don't notify any email address more than once. */
     $seen_email_addresses = array();
     /* Get VFS handle for attachments. */
     if ($opts['ticket']) {
         $vfs = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create();
         try {
             $attachments = Whups::getAttachments($opts['ticket']->getId());
         } catch (Whups_Exception $e) {
             $attachments = array();
             Horde::log($e);
         }
     }
     $from = Whups::getUserAttributes($opts['from']);
     foreach ($opts['recipients'] as $user => $role) {
         /* Make sure to check permissions as a guest for the 'always_copy'
          * address, and as the recipient for all others. */
         $to = $full_name = '';
         if (!empty($mail_always) && $user == $mail_always) {
             $details = null;
             $mycomments = Whups::permissionsFilter($comments, 'comment', Horde_Perms::READ, '');
             $to = $mail_always;
         } else {
             $details = Whups::getUserAttributes($user);
             if (!empty($details['email'])) {
                 $to = Whups::formatUser($details);
                 $mycomments = Whups::permissionsFilter($comments, 'comment', Horde_Perms::READ, $details['user']);
             }
             $full_name = $details['name'];
         }
         /* We may have no recipients due to users excluding themselves
          * from self notifies. */
         if (!$to) {
             continue;
         }
         if ($details && $details['type'] == 'user') {
             $user_prefs = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Prefs')->create('whups', array('user' => $details['user']));
             if (($details['user'] == $registry->getAuth() || !$registry->getAuth()) && $from['type'] == 'user' && $details['user'] == $from['user'] && $user_prefs->getValue('email_others_only')) {
                 continue;
             }
         }
         if ($opts['ticket']) {
             /* Add attachments. */
             $attachmentAdded = false;
             if (empty($GLOBALS['conf']['mail']['link_attach'])) {
                 /* We need to remove all attachments because the attachment
                  * list is potentially limited by permissions. */
                 $mail->clearParts();
                 foreach ($mycomments as $comment) {
                     foreach ($comment['changes'] as $change) {
                         if ($change['type'] != 'attachment') {
                             continue;
                         }
                         foreach ($attachments as $attachment) {
                             if ($attachment['name'] != $change['value']) {
                                 continue;
                             }
                             if (!isset($attachment['part'])) {
                                 $attachment['part'] = new Horde_Mime_Part();
                                 $attachment['part']->setType(Horde_Mime_Magic::filenameToMime($change['value'], false));
                                 $attachment['part']->setDisposition('attachment');
                                 $attachment['part']->setContents($vfs->read(Whups::VFS_ATTACH_PATH . '/' . $opts['ticket']->getId(), $change['value']));
                                 $attachment['part']->setName($change['value']);
                             }
                             $mail->addMimePart($attachment['part']);
                             $attachmentAdded = true;
                             break;
                         }
                     }
                 }
             }
             $formattedComment = $this->formatComments($mycomments, $opts['ticket']->getId());
             if (!$attachmentAdded && !strlen(trim($formattedComment)) && $details && $details['type'] == 'user' && $user_prefs->getValue('email_comments_only')) {
                 continue;
             }
             $opts['view']->comment = $formattedComment;
         }
         $addr_ob = new Horde_Mail_Rfc822_Address($to);
         if ($addr_ob->valid) {
             $bare_address = $addr_ob->bare_address;
             if (!empty($seen_email_addresses[$bare_address])) {
                 continue;
             }
             $seen_email_addresses[$bare_address] = true;
             if (empty($full_name) && !is_null($addr_ob->personal)) {
                 $full_name = $addr_ob->personal;
             }
         }
         // Use email address as fallback.
         if (empty($full_name)) {
             $full_name = $to;
         }
         $opts['view']->full_name = $full_name;
         $opts['view']->role = $role;
         $body = $opts['view']->render($opts['template']);
         if (!strlen(trim($body))) {
             continue;
         }
         $mail->setBody($body);
         $mail->addHeaderOb(Horde_Mime_Headers_MessageId::create());
         if ($opts['ticket']) {
             $message_id = '<whups-' . $opts['ticket']->getId() . '-' . md5($user) . '@' . $conf['server']['name'] . '>';
             if ($opts['new']) {
                 $mail->addHeader('Message-ID', $message_id);
             } else {
                 $mail->addHeader('In-Reply-To', $message_id);
                 $mail->addHeader('References', $message_id);
             }
         }
         $mail->clearRecipients();
         $mail->addHeader('To', $to);
         try {
             $mail->send($GLOBALS['injector']->getInstance('Horde_Mail'), true);
             $entry = sprintf('%s Message sent to %s from "%s"', $_SERVER['REMOTE_ADDR'], $to, $GLOBALS['registry']->getAuth());
             Horde::log($entry, 'INFO');
         } catch (Horde_Mime_Exception $e) {
             Horde::log($e, 'ERR');
         }
     }
 }
예제 #6
0
파일: Upload.php 프로젝트: jubinpatel/horde
 /**
  * Checks for a file uploaded via the pluploader. If one is found, handle
  * it, send the server json response and exit.
  */
 protected function _handleFileUpload()
 {
     if ($filename = Horde_Util::getFormData('name')) {
         if (isset($_SERVER["HTTP_CONTENT_TYPE"])) {
             $type = $_SERVER["HTTP_CONTENT_TYPE"];
         } elseif (isset($_SERVER["CONTENT_TYPE"])) {
             $type = $_SERVER["CONTENT_TYPE"];
         }
         if (empty($type) || $type == 'application/octet-stream') {
             $temp = Horde_Util::getTempFile('', true);
             $out = fopen($temp, 'w+');
             if ($out) {
                 // Read binary input stream and append it to temp file
                 $in = fopen("php://input", "rb");
                 if ($in) {
                     stream_copy_to_stream($in, $out);
                     rewind($out);
                     fclose($in);
                 } else {
                     fclose($out);
                     header('Content-Type: application/json');
                     echo '{ "status" : "500", "file": "' . $temp . '", error" : { "message": "Failed to open input stream." } }';
                     exit;
                 }
             } else {
                 header('Content-Type: application/json');
                 echo '{ "status" : "500", "file": "' . $temp . '", error" : { "message": "Failed to open output stream." } }';
                 exit;
             }
             // // Don't know type. Try to deduce it.
             if (!($type = Horde_Mime_Magic::analyzeFile($temp, isset($GLOBALS['conf']['mime']['magic_db']) ? $GLOBALS['conf']['mime']['magic_db'] : null))) {
                 $type = Horde_Mime_Magic::filenameToMime($filename);
             }
         } elseif (strpos($type, "multipart") !== false) {
             // Handle mulitpart uploads
             $temp = Horde_Util::getTempFile('', true);
             $out = fopen($temp, 'w+');
             if ($out) {
                 $in = fopen($_FILES['file']['tmp_name'], 'rb');
                 if ($in) {
                     stream_copy_to_stream($in, $out);
                     rewind($out);
                     fclose($in);
                 } else {
                     fclose($out);
                     header('Content-Type: application/json');
                     echo '{ "status" : "500", "file": "' . $temp . '", error" : { "message": "Failed to open input stream." } }';
                     exit;
                 }
             } else {
                 header('Content-Type: application/json');
                 echo '{ "status" : "500", "file": "' . $temp . '", error" : { "message": "Failed to open output stream." } }';
                 exit;
             }
         }
         // Figure out what to do with the file
         if (in_array($type, array('x-extension/zip', 'application/x-compressed', 'application/x-zip-compressed', 'application/zip')) || Horde_Mime_Magic::filenameToMime($temp) == 'application/zip') {
             // ZIP file
             try {
                 $image_ids = $this->_handleZip($temp);
             } catch (Ansel_Exception $e) {
                 $notification->push(sprintf(_("There was an error processing the uploaded archive: %s"), $e->getMessage()), 'horde.error');
             }
         } else {
             // Try and make sure the image is in a recognizeable format.
             if (getimagesize($temp) === false) {
                 header('Content-Type: application/json');
                 echo '{ "status" : "400", "error" : { "message": "Not a valid, supported image file." }, "id" : "id" }';
                 exit;
             }
             // Add the image to the gallery
             $image_data = array('image_filename' => $filename, 'image_type' => $type, 'data' => stream_get_contents($out));
             fclose($out);
             try {
                 $image_ids = array($this->_gallery->addImage($image_data));
             } catch (Ansel_Exception $e) {
                 header('Content-Type: application/json');
                 echo '{ "status" : "400", "error" : { "message": "Not a valid, supported image file." }, "id" : "id" }';
                 exit;
             }
             unset($data);
         }
         // Try to auto generate some thumbnails.
         $qtask = new Ansel_Queue_ProcessThumbs($image_ids);
         $queue = $GLOBALS['injector']->getInstance('Horde_Queue_Storage');
         $queue->add($qtask);
         header('Content-Type: application/json');
         echo '{ "status" : "200", "error" : {} }';
         exit;
     }
 }
예제 #7
0
 /**
  * @throws Wicked_Exception
  */
 public function displayContents($isBlock)
 {
     $view = $GLOBALS['injector']->createInstance('Horde_View');
     $view->addHelper('Wicked_View_Helper_Navigation');
     $view->name = $this->pageName();
     $view->text = $this->getProcessor()->transform($this->getText());
     if ($isBlock) {
         return $view->render('display/standard');
     }
     $view->showTools = true;
     if ($this->allows(Wicked::MODE_EDIT) && !$this->isLocked(Wicked::lockUser())) {
         $view->edit = Horde::widget(array('url' => Wicked::url('EditPage')->add('referrer', $this->pageName()), 'title' => _("_Edit"), 'class' => 'wicked-edit'));
     }
     if ($this->isLocked()) {
         if ($this->allows(Wicked::MODE_UNLOCKING)) {
             $view->unlock = Horde::widget(array('url' => $this->pageUrl(null, 'unlock')->remove('version'), 'title' => _("Un_lock"), 'class' => 'wicked-unlock'));
         }
     } else {
         if ($this->allows(Wicked::MODE_LOCKING)) {
             $view->lock = Horde::widget(array('url' => $this->pageUrl(null, 'lock')->remove('version'), 'title' => _("_Lock"), 'class' => 'wicked-lock'));
         }
     }
     if ($this->allows(Wicked::MODE_REMOVE)) {
         $params = array('referrer' => $this->pageName());
         if ($this->isOld()) {
             $params['version'] = $this->version();
         }
         $view->remove = Horde::widget(array('url' => Wicked::url('DeletePage')->add($params), 'title' => _("_Delete"), 'class' => 'wicked-delete'));
     }
     if ($this->allows(Wicked::MODE_REMOVE) && !$this->isLocked(Wicked::lockUser())) {
         $view->rename = Horde::widget(array('url' => Wicked::url('MergeOrRename')->add('referrer', $this->pageName()), 'title' => _("_Merge/Rename")));
     }
     $view->backLinks = Horde::widget(array('url' => Wicked::url('BackLinks')->add('referrer', $this->pageName()), 'title' => _("_Backlinks")));
     $view->likePages = Horde::widget(array('url' => Wicked::url('LikePages')->add('referrer', $this->pageName()), 'title' => _("S_imilar Pages")));
     $view->attachedFiles = Horde::widget(array('url' => Wicked::url('AttachedFiles')->add('referrer', $this->pageName()), 'title' => _("Attachments")));
     if ($this->allows(Wicked::MODE_HISTORY)) {
         $view->changes = Horde::widget(array('url' => $this->pageUrl('history.php')->remove('version'), 'title' => _("Hi_story")));
     }
     if ($GLOBALS['registry']->isAdmin()) {
         $permsurl = Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/admin/perms/edit.php')->add(array('category' => 'wicked:pages:' . $this->pageId(), 'autocreate' => 1, 'autocreate_copy' => 'wicked', 'autocreate_guest' => Horde_Perms::SHOW | Horde_Perms::READ, 'autocreate_default' => Horde_Perms::SHOW | Horde_Perms::READ | Horde_Perms::EDIT | Horde_Perms::DELETE));
         $view->perms = Horde::widget(array('url' => $permsurl, 'target' => '_blank', 'title' => _("Permissio_ns")));
     }
     if ($histories = $GLOBALS['session']->get('wicked', 'history')) {
         $view->history = Horde::widget(array('url' => '#', 'onclick' => 'document.location = document.display.history[document.display.history.selectedIndex].value;', 'title' => _("Ba_ck to")));
         $view->histories = array();
         foreach ($histories as $history) {
             if (!strlen($history)) {
                 continue;
             }
             $view->histories[(string) Wicked::url($history)] = $history;
         }
     }
     $pageId = $GLOBALS['wicked']->getPageId($this->pageName());
     $attachments = $GLOBALS['wicked']->getAttachedFiles($pageId);
     if (count($attachments)) {
         $view->attachments = array();
         foreach ($attachments as $attachment) {
             $url = $GLOBALS['registry']->downloadUrl($attachment['attachment_name'], array('page' => $this->pageName(), 'file' => $attachment['attachment_name'], 'version' => $attachment['attachment_version']));
             $icon = $GLOBALS['injector']->getInstance('Horde_Core_Factory_MimeViewer')->getIcon(Horde_Mime_Magic::filenameToMime($attachment['attachment_name']));
             $view->attachments[] = Horde::link($url) . '<img src="' . $icon . '" width="16" height="16" alt="" />&nbsp;' . htmlspecialchars($attachment['attachment_name']) . '</a>';
         }
     }
     $view->downloadPlain = Wicked::url($this->pageName())->add(array('actionID' => 'export', 'format' => 'plain'))->link() . _("Plain Text") . '</a>';
     $view->downloadHtml = Wicked::url($this->pageName())->add(array('actionID' => 'export', 'format' => 'html'))->link() . _("HTML") . '</a>';
     $view->downloadLatex = Wicked::url($this->pageName())->add(array('actionID' => 'export', 'format' => 'tex'))->link() . _("Latex") . '</a>';
     $view->downloadRest = Wicked::url($this->pageName())->add(array('actionID' => 'export', 'format' => 'rst'))->link() . _("reStructuredText") . '</a>';
     return $view->render('display/standard');
 }
예제 #8
0
파일: Mail.php 프로젝트: pzhu2004/moodle
 /**
  * Adds an attachment.
  *
  * @param string $file     The path to the file.
  * @param string $name     The file name to use for the attachment.
  * @param string $type     The content type of the file.
  * @param string $charset  The character set of the part (only relevant for
  *                         text parts.
  *
  * @return integer  The part number.
  */
 public function addAttachment($file, $name = null, $type = null, $charset = 'us-ascii')
 {
     if (empty($name)) {
         $name = basename($file);
     }
     if (empty($type)) {
         $type = Horde_Mime_Magic::filenameToMime($file, false);
     }
     $num = $this->addPart($type, file_get_contents($file), $charset, 'attachment');
     $this->_parts[$num]->setName($name);
     return $num;
 }
예제 #9
0
파일: source.php 프로젝트: raz0rsdge/horde
function printfile_raw($pathname)
{
    global $mime_drivers, $mime_drivers_map;
    $result = Horde::loadConfiguration('mime_drivers.php', array('mime_drivers', 'mime_drivers_map'), 'horde');
    extract($result);
    $result = Horde::loadConfiguration('mime_drivers.php', array('mime_drivers', 'mime_drivers_map'), 'luxor');
    if (isset($result['mime_drivers'])) {
        $mime_drivers = array_replace_recursive($mime_drivers, $result['mime_drivers']);
    }
    if (isset($result['mime_drivers_map'])) {
        $mime_drivers_map = array_replace_recursive($mime_drivers_map, $result['mime_drivers_map']);
    }
    $filename = $GLOBALS['files']->toReal($pathname);
    $data = file_get_contents($filename);
    $mime_part = new Horde_Mime_Part(Horde_Mime_Magic::filenameToMime($pathname), $data);
    $mime_part->setName($pathname);
    $viewer = $GLOBALS['injector']->getInstance('Horde_Core_Factory_MimeViewer')->create($mime_part);
    if ($viewer->getType() == 'text/plain') {
        return '<pre class="fixed">' . htmlspecialchars($viewer->render()) . '</pre>';
    } else {
        return $viewer->render();
    }
}
예제 #10
0
 /**
  */
 public function download(Horde_Variables $vars)
 {
     global $wicked;
     $page = $vars->get('page', 'Wiki/Home');
     $page_id = ($id = $wicked->getPageId($page)) === false ? $page : $id;
     $version = $vars->version;
     if (empty($version)) {
         try {
             $attachments = $wicked->getAttachedFiles($page_id);
             foreach ($attachments as $attachment) {
                 if ($attachment['attachment_name'] == $vars->file) {
                     $version = $attachment['attachment_version'];
                 }
             }
         } catch (Wicked_Exception $e) {
         }
         if (empty($version)) {
             // If we redirect here, we cause an infinite loop with inline
             // attachments.
             header('HTTP/1.1 404 Not Found');
             exit;
         }
     }
     try {
         $data = $wicked->getAttachmentContents($page_id, $vars->file, $version);
         $wicked->logAttachmentDownload($page_id, $vars->file);
     } catch (Wicked_Exception $e) {
         // If we redirect here, we cause an infinite loop with inline
         // attachments.
         header('HTTP/1.1 404 Not Found');
         echo $e->getMessage();
         exit;
     }
     $type = Horde_Mime_Magic::analyzeData($data, isset($conf['mime']['magic_db']) ? $conf['mime']['magic_db'] : null);
     if ($type === false) {
         $type = Horde_Mime_Magic::filenameToMime($vars->file, false);
     }
     return array('data' => $data, 'file' => $vars->file, 'type' => $type);
 }