/** * If this MIME part can contain embedded MIME part(s), and those part(s) * exist, return a representation of that data. * * @return mixed A Horde_Mime_Part object representing the embedded data. * Returns null if no embedded MIME part(s) exist. */ protected function _getEmbeddedMimeParts() { /* Get the data from the attachment. */ try { if (!($tnef = $this->getConfigParam('tnef'))) { $tnef = Horde_Compress::factory('Tnef'); $this->setConfigParam('tnef', $tnef); } $tnefData = $tnef->decompress($this->_mimepart->getContents()); } catch (Horde_Compress_Exception $e) { $tnefData = array(); } if (!count($tnefData)) { return null; } $mixed = new Horde_Mime_Part(); $mixed->setType('multipart/mixed'); reset($tnefData); while (list(, $data) = each($tnefData)) { $temp_part = new Horde_Mime_Part(); $temp_part->setName($data['name']); $temp_part->setDescription($data['name']); $temp_part->setContents($data['stream']); /* Short-circuit MIME-type guessing for winmail.dat parts; * we're showing enough entries for them already. */ $type = $data['type'] . '/' . $data['subtype']; if (in_array($type, array('application/octet-stream', 'application/base64'))) { $type = Horde_Mime_Magic::filenameToMIME($data['name']); } $temp_part->setType($type); $mixed->addPart($temp_part); } return $mixed; }
public function testBug325() { if (!extension_loaded('fileinfo')) { $this->markTestSkipped('The fileinfo extension is not available.'); } $this->assertEquals('text/plain', Horde_Mime_Magic::analyzeFile(__DIR__ . '/fixtures/flowed_msg.txt')); }
/** * Returns a copy of the MIME extension map. * * @return array The MIME extension map. */ protected static function _getMimeExtensionMap() { if (is_null(self::$_map)) { require __DIR__ . '/mime.mapping.php'; self::$_map = $mime_extension_map; } return self::$_map; }
/** * Return the full rendered version of the Horde_Mime_Part object. * * URL parameters used by this function: * - c: (integer) The VCARD component that contains an image. * - p: (integer) The index of image inside the component to display. * * @return array See parent::render(). * @throws Horde_Exception */ protected function _renderInline() { $vars = $GLOBALS['injector']->getInstance('Horde_Variables'); if (!isset($vars->p)) { $imp_contents = $this->getConfigParam('imp_contents'); $GLOBALS['injector']->getInstance('Horde_Core_Factory_Imple')->create('IMP_Ajax_Imple_VcardImport', array('mime_id' => $this->_mimepart->getMimeId(), 'muid' => strval($imp_contents->getIndicesOb()))); $this->_imageUrl = $this->getConfigParam('imp_contents')->urlView($this->_mimepart, 'download_render', array('params' => array('mode' => IMP_Contents::RENDER_INLINE))); return parent::_renderInline(); } /* Send the requested photo. */ $data = $this->_mimepart->getContents(); $ical = new Horde_Icalendar(); if (!$ical->parsevCalendar($data, 'VCALENDAR', $this->_mimepart->getCharset())) { // TODO: Error reporting return array(); } $components = $ical->getComponents(); if (!isset($components[$vars->c])) { // TODO: Error reporting return array(); } $name = $components[$vars->c]->getAttributeDefault('FN', false); if ($name === false) { $name = $components[$vars->c]->printableName(); } if (empty($name)) { $name = preg_replace('/\\..*?$/', '', $this->_mimepart->getName()); } $photos = $components[$vars->c]->getAllAttributes('PHOTO'); if (!isset($photos[$vars->p])) { // TODO: Error reporting return array(); } $type = 'image/' . Horde_String::lower($photos[$vars->p]['params']['TYPE']); return array($this->_mimepart->getMimeId() => array('data' => base64_decode($photos[$vars->p]['value']), 'name' => $name . '.' . Horde_Mime_Magic::mimeToExt($type), 'type' => $type)); }
/** * @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="" /> ' . 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'); }
/** * Adds an attachment to the outgoing compose message. * * @param string $atc_file Temporary file containing attachment contents. * @param integer $bytes Size of data, in bytes. * @param string $filename Filename of data. * @param string $type MIME type of data. * * @return IMP_Compose_Attachment Attachment object. * @throws IMP_Compose_Exception */ protected function _addAttachment($atc_file, $bytes, $filename, $type) { global $conf, $injector; $atc = new Horde_Mime_Part(); $atc->setBytes($bytes); /* Try to determine the MIME type from 1) the extension and * then 2) analysis of the file (if available). */ if (strlen($filename)) { $atc->setName($filename); if ($type == 'application/octet-stream') { $type = Horde_Mime_Magic::filenameToMIME($filename, false); } } $atc->setType($type); if ($atc->getType() == 'application/octet-stream' || $atc->getPrimaryType() == 'text') { $analyze = Horde_Mime_Magic::analyzeFile($atc_file, empty($conf['mime']['magic_db']) ? null : $conf['mime']['magic_db'], array('nostrip' => true)); $atc->setCharset('UTF-8'); if ($analyze) { $ctype = new Horde_Mime_Headers_ContentParam('Content-Type', $analyze); $atc->setType($ctype->value); if (isset($ctype->params['charset'])) { $atc->setCharset($ctype->params['charset']); } } } else { $atc->setHeaderCharset('UTF-8'); } $atc_ob = new IMP_Compose_Attachment($this, $atc, $atc_file); /* Check for attachment size limitations. */ $size_limit = null; if ($atc_ob->linked) { if (!empty($conf['compose']['link_attach_size_limit'])) { $linked = true; $size_limit = 'link_attach_size_limit'; } } elseif (!empty($conf['compose']['attach_size_limit'])) { $linked = false; $size_limit = 'attach_size_limit'; } if (!is_null($size_limit)) { $total_size = $conf['compose'][$size_limit] - $bytes; foreach ($this as $val) { if ($val->linked == $linked) { $total_size -= $val->getPart()->getBytes(); } } if ($total_size < 0) { throw new IMP_Compose_Exception(strlen($filename) ? sprintf(_("Attached file \"%s\" exceeds the attachment size limits. File NOT attached."), $filename) : _("Attached file exceeds the attachment size limits. File NOT attached.")); } } try { $injector->getInstance('Horde_Core_Hooks')->callHook('compose_attachment', 'imp', array($atc_ob)); } catch (Horde_Exception_HookNotSet $e) { } $this->_atc[$atc_ob->id] = $atc_ob; $this->changed = 'changed'; return $atc_ob; }
$currDir = $injector->getInstance('Horde_Core_Factory_TextFilter')->filter($currentDir, 'space2html', array('encode' => true, 'encode_all' => true)); require CHORA_TEMPLATES . '/directory/dir.inc'; } echo '</tbody>'; } /* Display all of the files in this directory */ $readmes = array(); if ($fileList) { echo '<tbody>'; foreach ($fileList as $currFile) { if ($conf['hide_restricted'] && Chora::isRestricted($currFile->getFileName())) { continue; } $lg = $currFile->getLastLog(); $realname = $currFile->getFileName(); $mimeType = Horde_Mime_Magic::filenameToMIME($realname); $currFile->mimeType = $mimeType; if (Horde_String::lower(Horde_String::substr($realname, 0, 6)) == 'readme') { $readmes[] = $currFile; } $icon = $injector->getInstance('Horde_Core_Factory_MimeViewer')->getIcon($mimeType); $author = Chora::showAuthorName($lg->getAuthor()); $filerev = $lg->getRevision(); $date = $lg->getDate(); $log = $lg->getMessage(); $attic = $currFile->isDeleted(); $fileName = $where . ($attic ? '/' . 'Attic' : '') . '/' . $realname; $name = $injector->getInstance('Horde_Core_Factory_TextFilter')->filter($realname, 'space2html', array('encode' => true, 'encode_all' => true)); $url = Chora::url('browsefile', $fileName, $branchArgs); $readableDate = Chora::readableTime($date); if ($log) {
} } else { $file_name = $tmpdir . '/mod_' . $file; if (!file_exists($file_name)) { copy($tmpdir . '/' . $file, $file_name); } } if (!file_exists($file_name)) { Horde::log(sprintf('Image not found [%s]', $file_name), 'ERR'); exit; } $file_data = file_get_contents($file_name); break; } /* Load the image object. */ $type = Horde_Mime_Magic::analyzeData($file_data); $image = $injector->getInstance('Horde_Core_Factory_Image')->create(array('data' => $file_data, 'type' => $type)); /* Check if no editing action required and send the image to browser. */ if (empty($action)) { $image->display(); exit; } /* Image editing required. */ switch ($action) { case 'rotate': $image->rotate($vars->v); break; case 'flip': $image->flip(); break; case 'mirror':
/** * Returns an unsorted file list of the specified directory. * * @param string $path The path of the directory. * @param string|array $filter Regular expression(s) to filter * file/directory name on. * @param boolean $dotfiles Show dotfiles? * @param boolean $dironly Show only directories? * * @return array File list. * @throws Horde_Vfs_Exception */ protected function _listFolder($path, $filter = null, $dotfiles = true, $dironly = false) { $list = array(); if ($path == '/') { try { $apps = $this->_registry->listApps(null, false, Horde_Perms::READ); } catch (Horde_Exception $e) { throw new Horde_Vfs_Exception($e->getMessage()); } foreach ($apps as $app) { if ($this->_registry->hasMethod('browse', $app)) { $file = array('name' => $app, 'date' => time(), 'type' => '**dir', 'size' => -1); $list[] = $file; } } return $list; } if (substr($path, 0, 1) == '/') { $path = substr($path, 1); } $pieces = explode('/', $path); try { $items = $this->_registry->callByPackage($pieces[0], 'browse', array('path' => $path, 'properties' => array('name', 'browseable', 'contenttype', 'contentlength', 'modified'))); } catch (Horde_Exception $e) { throw new Horde_Vfs_Exception($e->getMessage()); } if (!is_array(reset($items))) { /* We return an object's content. */ throw new Horde_Vfs_Exception('Unknown error'); } foreach ($items as $sub_path => $i) { if ($dironly && !$i['browseable']) { continue; } $name = basename($sub_path); if ($this->_filterMatch($filter, $name)) { continue; } $type = class_exists('Horde_Mime_Magic') ? Horde_Mime_Magic::mimeToExt(empty($i['contenttype']) ? 'application/octet-stream' : $i['contenttype']) : '**none'; $file = array('name' => $name, 'date' => empty($i['modified']) ? 0 : $i['modified'], 'type' => $i['browseable'] ? '**dir' : $type, 'size' => empty($i['contentlength']) ? 0 : $i['contentlength']); $list[] = $file; } return $list; }
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; }
echo implode("\n", $VC->diff($fl, $vars->r1, $vars->r2, array('num' => $num, 'type' => $type))) . "\n"; exit; } /* Human-Readable diff. */ $abbrev_r1 = $VC->abbrev($vars->r1); $abbrev_r2 = $VC->abbrev($vars->r2); $title = sprintf(_("Diff for %s between version %s and %s"), $injector->getInstance('Horde_Core_Factory_TextFilter')->filter($where, 'space2html', array('encode' => true, 'encode_all' => true)), $abbrev_r1, $abbrev_r2); /* Format log entries. */ $log_messages = array(); foreach ($VC->getRevisionRange($fl, $vars->r1, $vars->r2) as $val) { $clog = $fl->getLog($val); if (!is_null($clog)) { $log_messages[] = $clog; } } $page_output->addScriptFile('stripe.js', 'horde'); Chora::header($title); require CHORA_TEMPLATES . '/diff/header.inc'; $mime_type = Horde_Mime_Magic::filenameToMIME($fullname); if (substr($mime_type, 0, 6) == 'image/') { /* Check for images. */ $url1 = Chora::url('co', $where, array('r' => $vars->r1, 'p' => 1)); $url2 = Chora::url('co', $where, array('r' => $vars->r2, 'p' => 1)); echo "<tr><td><img src=\"{$url1}\" alt=\"" . htmlspecialchars($vars->r1) . '" /></td>' . "<td><img src=\"{$url2}\" alt=\"" . htmlspecialchars($vars->r2) . '" /></td></tr>'; } else { $view = $injector->createInstance('Horde_View'); $view->addHelper('Chora_Diff_Helper'); echo $view->diff($fl, $vars->r1, $vars->r2); echo $view->diffCaption(); } $page_output->footer();
/** * Returns the links to view, download, and delete an attachment. * * @param integer $ticket A ticket ID. * @param string $file An attachment name. * @param integer $queue The ticket's queue ID. * * @return array List of URLs. */ public static function attachmentUrl($ticket, $file, $queue) { global $injector, $registry; $links = array(); // Can we view the attachment online? $mime_part = new Horde_Mime_Part(); $mime_part->setType(Horde_Mime_Magic::extToMime($file['type'])); $viewer = $injector->getInstance('Horde_Core_Factory_MimeViewer')->create($mime_part); if ($viewer && !$viewer instanceof Horde_Mime_Viewer_Default) { $links['view'] = Horde::url('view.php')->add(array('actionID' => 'view_file', 'type' => $file['type'], 'file' => $file['name'], 'ticket' => $ticket))->link(array('title' => $file['name'], 'target' => '_blank')) . $file['name'] . '</a>'; } else { $links['view'] = $file['name']; } // We can always download attachments. $url_params = array('actionID' => 'download_file', 'file' => $file['name'], 'ticket' => $ticket); $links['download'] = $registry->downloadUrl($file['name'], $url_params)->link(array('title' => $file['name'])) . Horde::img('download.png', _("Download")) . '</a>'; // Admins can delete attachments. if (self::hasPermission($queue, 'queue', Horde_Perms::DELETE)) { $links['delete'] = Horde::url('ticket/delete_attachment.php')->add(array('file' => $file['name'], 'id' => $ticket, 'url' => Horde::selfUrl(true, false, true)))->link(array('title' => sprintf(_("Delete %s"), $file['name']), 'onclick' => 'return window.confirm(\'' . addslashes(sprintf(_("Permanently delete %s?"), $file['name'])) . '\');')) . Horde::img('delete.png', sprintf(_("Delete %s"), $file['name'])) . '</a>'; } return $links; }
} $gollem_vfs = $injector->getInstance('Gollem_Vfs'); $stream = null; $data = ''; try { if (is_callable(array($gollem_vfs, 'readStream'))) { $stream = $gollem_vfs->readStream($vars->dir, $vars->file); } else { $data = $gollem_vfs->read($vars->dir, $vars->file); } } catch (Horde_Vfs_Exception $e) { Horde::log($e, 'NOTICE'); throw $e; } $mime_part = new Horde_Mime_Part(); $mime_part->setType(Horde_Mime_Magic::extToMime($vars->type)); $mime_part->setContents(is_resource($stream) ? $stream : $data); $mime_part->setName($vars->file); // We don't know better. $mime_part->setCharset('US-ASCII'); $ret = $injector->getInstance('Horde_Core_Factory_MimeViewer')->create($mime_part)->render('full'); reset($ret); $key = key($ret); try { $size = $gollem_vfs->size($vars->dir, $vars->file); } catch (Horde_Vfs_Exception $e) { $size = null; } if (empty($ret)) { $browser->downloadHeaders($vars->file, null, false, $size); if (is_resource($stream)) {
if (substr($val['link'], 0, 1) == '/') { $parts = explode('/', $val['link']); $name = array_pop($parts); $dir = implode('/', $parts); } else { $name = $val['link']; $dir = Gollem::$backend['dir']; } $url = $manager_url->copy()->add('dir', Gollem::subdirectory($dir, $name)); $item['link'] = $item['name'] . ' -> ' . $url->link() . $val['link'] . '</a>'; } else { $item['link'] = $item['name'] . ' -> ' . $val['link']; } break; default: $mime_type = Horde_Mime_Magic::extToMime($val['type']); // Edit link if possible. if (strpos($mime_type, 'text/') === 0) { $url = $edit_url->copy()->add(array('actionID' => 'edit_file', 'type' => $val['type'], 'file' => $val['name'], 'dir' => Gollem::$backend['dir'], 'driver' => Gollem::$backend['driver'])); $item['edit'] = Horde::link('#', '', '', '_blank', Horde::popupJs($url)); } // We can always download files. $item['dl'] = $registry->downloadUrl($val['name'], array('dir' => Gollem::$backend['dir'], 'backend' => $GLOBALS['session']->get('gollem', 'backend_key')))->link(array('title' => sprintf(_("Download %s"), $val['name']))); // Try a view link. $url = $view_url->copy()->add(array('type' => $val['type'], 'file' => $val['name'], 'dir' => Gollem::$backend['dir'], 'driver' => Gollem::$backend['driver'])); $item['link'] = Horde::link('#', '', '', '_blank', Horde::popupJs($url)) . $name . '</a>'; break; } $entry[] = $item; } /* Set up the variables needed for the header row. */
/** * Convert an ActiveSync contact message into a hash suitable for * importing via self::add(). * * @param Horde_ActiveSync_Message_Contact $message The contact message * object. * * @return array A contact hash. */ public function fromASContact(Horde_ActiveSync_Message_Contact $message) { $hash = array(); foreach (self::$_asMap as $turbaField => $asField) { if (!$message->isGhosted($asField)) { try { $hash[$turbaField] = $message->{$asField}; } catch (InvalidArgumentException $e) { } } } /* Requires special handling */ try { if ($message->getProtocolVersion() >= Horde_ActiveSync::VERSION_TWELVE) { if (!empty($message->airsyncbasebody)) { $hash['notes'] = $message->airsyncbasebody->data; } } else { $hash['notes'] = $message->body; } } catch (InvalidArgumentException $e) { } // picture ($message->picture *should* already be base64 encdoed) if (!$message->isGhosted('picture')) { $hash['photo'] = base64_decode($message->picture); if (!empty($hash['photo'])) { $hash['phototype'] = Horde_Mime_Magic::analyzeData($hash['photo']); } else { $hash['phototype'] = null; } } /* Email addresses */ $hash['emails'] = array(); if (!$message->isGhosted('email1address')) { $e = Horde_Icalendar_Vcard::getBareEmail($message->email1address); $hash['emails'][] = $hash['email'] = $e ? $e : ''; } if (!$message->isGhosted('email2address')) { $e = Horde_Icalendar_Vcard::getBareEmail($message->email2address); $hash['emails'][] = $hash['homeEmail'] = $e ? $e : ''; } if (!$message->isGhosted('email3address')) { $e = Horde_Icalendar_Vcard::getBareEmail($message->email3address); $hash['emails'][] = $hash['workEmail'] = $e ? $e : ''; } $hash['emails'] = implode(',', $hash['emails']); /* Categories */ if (is_array($message->categories) && count($message->categories)) { $hash['__tags'] = $message->categories; } /* Children */ if (is_array($message->children) && count($message->children)) { // We use a comma as incoming delimiter as it's the most // common even though it might be used withing a name string. $hash['children'] = implode(', ', $message->children); } elseif (!$message->isGhosted('children')) { $hash['children'] = ''; } /* Birthday and Anniversary */ if (!empty($message->birthday)) { $bday = clone $message->birthday; $bday->setTimezone(date_default_timezone_get()); $hash['birthday'] = $bday->format('Y-m-d'); } elseif (!$message->isGhosted('birthday')) { $hash['birthday'] = ''; } if (!empty($message->anniversary)) { $anniversary = clone $message->anniversary; $anniversary->setTimezone(date_default_timezone_get()); $hash['anniversary'] = $anniversary->format('Y-m-d'); } elseif (!$message->isGhosted('anniversary')) { $hash['anniversary'] = ''; } /* Countries */ include 'Horde/Nls/Countries.php'; if (!empty($message->homecountry)) { if (!empty($this->map['homeCountryFree'])) { $hash['homeCountryFree'] = $message->homecountry; } else { $country = array_search($message->homecountry, $countries); if ($country === false) { $country = $message->homecountry; } $hash['homeCountry'] = $country; } } elseif (!$message->isGhosted('homecountry')) { $hash['homeCountry'] = ''; } if (!empty($message->businesscountry)) { if (!empty($this->map['workCountryFree'])) { $hash['workCountryFree'] = $message->businesscountry; } else { $country = array_search($message->businesscountry, $countries); if ($country === false) { $country = $message->businesscountry; } $hash['workCountry'] = $country; } } elseif (!$message->isGhosted('businesscountry')) { $hash['workCountry'] = ''; } if (!empty($message->othercountry)) { if (!empty($this->map['otherCountryFree'])) { $hash['otherCountryFree'] = $message->othercountry; } else { $country = array_search($message->othercountry, $countries); if ($country === false) { $country = $message->othercountry; } $hash['otherCountry'] = $country; } } elseif (!$message->isGhosted('othercountry')) { $hash['otherCountry'] = ''; } return $hash; }
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(); } }
/** * 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; } }
/** * Convert a TNEF attachment into a multipart/mixed part. * * @param integer|Horde_Mime_part $data Either a mime part id or a * Horde_Mime_Part object containing * the TNEF attachment. * * @return Horde_Mime_Part The multipart/mixed MIME part containing any * attachment data we can decode. */ protected function _decodeTnefData($data) { $wrapper = new Horde_Mime_Part(); $wrapper->setType('multipart/mixed'); if (!$data instanceof Horde_Mime_Part) { $mime_part = $this->getMimePart($data); } else { $mime_part = $data; } $tnef_parser = Horde_Compress::factory('Tnef'); try { $tnef_data = $tnef_parser->decompress($mime_part->getContents()); } catch (Horde_Compress_Exception $e) { return false; } if (!count($tnef_data)) { return false; } reset($tnef_data); while (list(, $data) = each($tnef_data)) { $tmp_part = new Horde_Mime_Part(); $tmp_part->setName($data['name']); $tmp_part->setDescription($data['name']); $tmp_part->setContents($data['stream']); $type = $data['type'] . '/' . $data['subtype']; if (in_array($type, array('application/octet-stream', 'application/base64'))) { $type = Horde_Mime_Magic::filenameToMIME($data['name']); } $tmp_part->setType($type); $wrapper->addPart($tmp_part); } return $wrapper; }
/** * Sends the correct HTTP headers to the browser to download this image. * * @param string $view The view to download. */ public function downloadHeaders($view = 'full') { global $browser, $conf; $filename = $this->filename; if ($view != 'full') { if ($ext = Horde_Mime_Magic::mimeToExt('image/' . $conf['image']['type'])) { $filename .= '.' . $ext; } } $browser->downloadHeaders($filename); }
/** * 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)); }
/** * 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'); } } }
/** * 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); } }
/** * Get summary info for a MIME ID. * * @param string $id The MIME ID. * @param integer $mask A bitmask indicating what information to return: * <pre> * Always output: * 'type' = MIME type * * IMP_Contents::SUMMARY_BYTES * Output: parts = 'bytes' * * IMP_Contents::SUMMARY_SIZE * Output: parts = 'size' * * IMP_Contents::SUMMARY_ICON * IMP_Contents::SUMMARY_ICON_RAW * Output: parts = 'icon' * * IMP_Contents::SUMMARY_DESCRIP * Output: parts = 'description_raw' * * IMP_Contents::SUMMARY_DESCRIP_LINK * Output: parts = 'description' * * IMP_Contents::SUMMARY_DOWNLOAD * Output: parts = 'download', 'download_url' * * IMP_Contents::SUMMARY_IMAGE_SAVE * Output: parts = 'img_save' * * IMP_Contents::SUMMARY_PRINT * IMP_Contents::SUMMARY_PRINT_STUB * Output: parts = 'print' * * IMP_Contents::SUMMARY_STRIP * Output: parts = 'strip' * </pre> * * @return array An array with the requested information. */ public function getSummary($id, $mask = 0) { $autodetect_link = false; $param_array = array(); $this->_buildMessage(); $part = array('bytes' => null, 'download' => null, 'download_url' => null, 'id' => $id, 'img_save' => null, 'size' => null, 'strip' => null); $mime_part = $this->getMimePart($id, array('nocontents' => true)); if (!$mime_part) { return $part; } $mime_type = $mime_part->getType(); /* If this is an attachment that has no specific MIME type info, see * if we can guess a rendering type. */ if (in_array($mime_type, array('application/octet-stream', 'application/base64'))) { $mime_type = Horde_Mime_Magic::filenameToMIME($mime_part->getName()); if ($mime_type == $mime_part->getType()) { $autodetect_link = true; } else { $mime_part = clone $mime_part; $mime_part->setType($mime_type); $param_array['ctype'] = $mime_type; } } $part['type'] = $mime_type; /* Is this part an attachment? */ $is_atc = $mime_part->isAttachment(); /* Get bytes/size information. */ if ($mask & self::SUMMARY_BYTES || $mask & self::SUMMARY_SIZE) { $part['bytes'] = $size = $mime_part->getBytes(); $part['size'] = $size > 1048576 ? sprintf(_("%s MB"), IMP::numberFormat($size / 1048576, 1)) : sprintf(_("%s KB"), max(round($size / 1024), 1)); } /* Get part's icon. */ if ($mask & self::SUMMARY_ICON || $mask & self::SUMMARY_ICON_RAW) { $part['icon'] = $GLOBALS['injector']->getInstance('IMP_Factory_MimeViewer')->getIcon($mime_type); if ($mask & self::SUMMARY_ICON) { $part['icon'] = Horde_Themes_Image::tag($part['icon'], array('attr' => array('title' => $mime_type))); } } else { $part['icon'] = null; } /* Get part's description. */ $description = $this->getPartName($mime_part, true); if ($mask & self::SUMMARY_DESCRIP_LINK) { if (($can_d = $this->canDisplay($mime_part, self::RENDER_FULL)) || $autodetect_link) { $part['description'] = $this->linkViewJS($mime_part, 'view_attach', htmlspecialchars($description), array('jstext' => sprintf(_("View %s"), $description), 'params' => array_filter(array_merge($param_array, array('autodetect' => !$can_d))))); } else { $part['description'] = htmlspecialchars($description); } } if ($mask & self::SUMMARY_DESCRIP) { $part['description_raw'] = $description; } /* Download column. */ if ($is_atc && $mask & self::SUMMARY_DOWNLOAD) { $part['download'] = $this->linkView($mime_part, 'download_attach', '', array('attr' => array('download' => $mime_part->getName(true) ?: $mime_part->getPrimaryType()), 'class' => 'iconImg downloadAtc', 'jstext' => _("Download"))); $part['download_url'] = $this->urlView($mime_part, 'download_attach'); } /* Display the image save link if the required registry calls are * present. */ if ($mask & self::SUMMARY_IMAGE_SAVE && $GLOBALS['registry']->hasMethod('images/selectGalleries') && $mime_part->getPrimaryType() == 'image') { $part['img_save'] = Horde::link('#', _("Save Image in Gallery"), 'iconImg saveImgAtc', null, Horde::popupJs(IMP_Basic_Saveimage::url(), array('params' => array('muid' => strval($this->getIndicesOb()), 'id' => $id), 'height' => 200, 'width' => 450, 'urlencode' => true)) . 'return false;') . '</a>'; } /* Add print link? */ if (($mask & self::SUMMARY_PRINT || $mask & self::SUMMARY_PRINT_STUB) && $this->canDisplay($id, self::RENDER_FULL)) { $part['print'] = $mask & self::SUMMARY_PRINT ? $this->linkViewJS($mime_part, 'print_attach', '', array('css' => 'iconImg printAtc', 'jstext' => _("Print"), 'onload' => 'IMP_JS.printWindow', 'params' => $param_array)) : Horde::link('#', _("Print"), 'iconImg printAtc', null, null, null, null, array('mimeid' => $id)) . '</a>'; } /* Strip Attachment? Allow stripping of base parts other than the * base multipart and the base text (body) part. */ if ($mask & self::SUMMARY_STRIP && $id != 0 && intval($id) != 1 && strpos($id, '.') === false) { $part['strip'] = Horde::link(Horde::selfUrlParams()->add(array('actionID' => 'strip_attachment', 'imapid' => $id, 'muid' => strval($this->getIndicesOb()), 'token' => $GLOBALS['session']->getToken())), _("Strip Attachment"), 'iconImg deleteImg stripAtc', null, null, null, null, array('mimeid' => $id)) . '</a>'; } return $part; }
/** * Read an image from the filesystem. * * @param string $file The filename of the image. * @param array $override Overwrite the file array with these values. * * @return array The image data of the file as an array * @throws Horde_Exception_NotFound */ public static function getImageFromFile($file, $override = array()) { if (!file_exists($file)) { throw new Horde_Exception_NotFound(sprintf(_("The file \"%s\" doesn't exist."), $file)); } global $conf; // Get the mime type of the file (and make sure it's an image). $mime_type = Horde_Mime_Magic::analyzeFile($file, isset($conf['mime']['magic_db']) ? $conf['mime']['magic_db'] : null); if (strpos($mime_type, 'image') === false) { throw new Horde_Exception_NotFound(sprintf(_("Can't get unknown file type \"%s\"."), $file)); } $image = array('image_filename' => basename($file), 'image_caption' => '', 'image_type' => $mime_type, 'data' => file_get_contents($file)); // Override the array e.g., if we're changing filename to something else. if (count($override)) { $image = array_merge($image, $override); } return $image; }
public function setMapiAttribute($type, $name, $value) { switch ($name) { case Horde_Compress_Tnef::MAPI_ATTACH_LONG_FILENAME: $this->name = preg_replace('/.*[\\/](.*)$/', '\\1', $value); break; case Horde_Compress_Tnef::MAPI_ATTACH_MIME_TAG: $type = str_replace("", '', preg_replace('/^(.*)\\/.*/', '\\1', $value)); $subtype = str_replace("", '', preg_replace('/.*\\/(.*)$/', '\\1', $value)); $this->type = $type; $this->subtype = $subtype; break; case Horde_Compress_Tnef::MAPI_ATTACH_EXTENSION: $value = Horde_Mime_Magic::extToMime($value); $type = str_replace("", '', preg_replace('/^(.*)\\/.*/', '\\1', $value)); $subtype = str_replace("", '', preg_replace('/.*\\/(.*)$/', '\\1', $value)); $this->type = $type; $this->subtype = $subtype; } }
/** * Stores an object in the Kolab message store. * * TODO * * @return string The object id, possibly updated. * @throws Turba_Exception */ protected function _store($attributes, $object_id = null) { if (isset($attributes['__type']) && $attributes['__type'] == 'Group') { $this->_convertMembers($attributes); $data = $this->_getListData(); } else { if (isset($attributes['photo']) && isset($attributes['phototype'])) { $filename = 'photo.' . Horde_Mime_Magic::mimeToExt($attributes['phototype']); $attributes['_attachments'][$filename] = array('type' => $attributes['phototype'], 'content' => Horde_Stream_Wrapper_String::getStream($attributes['photo'])); $attributes['picture'] = $filename; unset($attributes['photo'], $attributes['phototype']); } // EAS sets the date fields to '' instead of null -> fix it up $fix_date_fields = array('birthday', 'anniversary'); foreach ($fix_date_fields as $fix_date) { if (empty($attributes[$fix_date])) { unset($attributes[$fix_date]); } } $data = $this->_getData(); } if ($object_id === null) { $object_id = $data->create($attributes); } else { $data->modify($attributes); } /* Invalidate cache. */ $this->_connected = false; return Horde_Url::uriB64Encode($object_id); }
/** * Returns a link to display and download a file from the VFS backend * associated with this object. * * @param string $file The file name. * * @return string The HTML code of the generated link. */ public function vfsDisplayUrl($file) { global $registry; $mime_part = new Horde_Mime_Part(); $mime_part->setType(Horde_Mime_Magic::extToMime($file['type'])); $viewer = $GLOBALS['injector']->getInstance('Horde_Core_Factory_MimeViewer')->create($mime_part); // We can always download files. $url_params = array('actionID' => 'download_file', 'file' => $file['name'], 'type' => $file['type'], 'source' => $this->driver->getName(), 'key' => $this->getValue('__key')); $dl = Horde::link($registry->downloadUrl($file['name'], $url_params), $file['name']) . Horde_Themes_Image::tag('download.png', array('alt' => _("Download"))) . '</a>'; // Let's see if we can view this one, too. if ($viewer && !$viewer instanceof Horde_Mime_Viewer_Default) { $url = Horde::url('view.php')->add($url_params)->add('actionID', 'view_file'); $link = Horde::link($url, $file['name'], null, '_blank') . $file['name'] . '</a>'; } else { $link = $file['name']; } return $link . ' ' . $dl; }
try { $injector->getInstance('Gollem_Vfs')->writeData($vars->dir, $vars->file, $vars->content); $message = sprintf(_("%s successfully saved."), $vars->file); } catch (Horde_Vfs_Exception $e) { $message = sprintf(_("Access denied to %s"), $vars->file); } echo Horde::wrapInlineScript(array('alert(' . Horde_Serialize::serialize($message, Horde_Serialize::JSON) . ')')); break; case 'edit_file': try { $data = $injector->getInstance('Gollem_Vfs')->read($vars->dir, $vars->file); } catch (Horde_Vfs_Exception $e) { echo Horde::wrapInlineScript(array('alert(' . Horde_Serialize::serialize(sprintf(_("Access denied to %s"), $vars->file), Horde_Serialize::JSON) . ')')); break; } $mime_type = Horde_Mime_Magic::extToMIME($vars->type); if (strpos($mime_type, 'text/') !== 0) { break; } if ($mime_type == 'text/html') { $injector->getInstance('Horde_Editor')->initialize(array('id' => 'content')); } $view = $injector->createInstance('Horde_View'); $view->self_url = Horde::url('edit.php'); $view->forminput = Horde_Util::formInput(); $view->vars = $vars; $view->data = $data; $page_output->addScriptFile('edit.js'); $page_output->topbar = $page_output->sidebar = false; $page_output->header(array('title' => $title)); $notification->notify(array('listeners' => 'status'));
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; }
/** * 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; }