Автор: Michael Slusarz (slusarz@horde.org)
Пример #1
0
 /**
  * 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;
 }
Пример #2
0
 /**
  * Return the full rendered version of the Horde_Mime_Part object.
  *
  * URL parameters used by this function:
  *   - zip_attachment: (integer) The ZIP attachment to download.
  *
  * @return array  See parent::render().
  * @throws Horde_Exception
  */
 protected function _render()
 {
     $vars = $GLOBALS['injector']->getInstance('Horde_Variables');
     if (!isset($vars->zip_attachment)) {
         return array();
     }
     /* Send the requested file. Its position in the zip archive is located
      * in 'zip_attachment'. */
     $data = $this->_mimepart->getContents();
     $fileKey = $vars->zip_attachment - 1;
     if (!($zip = $this->getConfigParam('zip'))) {
         $zip = Horde_Compress::factory('Zip');
         $this->setConfigParam('zip', $zip);
     }
     $zipInfo = $zip->decompress($data, array('action' => Horde_Compress_Zip::ZIP_LIST));
     /* Verify that the requested file exists. */
     if (isset($zipInfo[$fileKey])) {
         $text = $zip->decompress($data, array('action' => Horde_Compress_Zip::ZIP_DATA, 'info' => $zipInfo, 'key' => $fileKey));
         if (!empty($text)) {
             return array($this->_mimepart->getMimeId() => array('data' => $text, 'name' => basename($zipInfo[$fileKey]['name']), 'type' => 'application/octet-stream'));
         }
     }
     // TODO: Error reporting
     return array();
 }
Пример #3
0
 /**
  * Return the full rendered version of the Horde_Mime_Part object.
  *
  * URL parameters used by this function:
  * <pre>
  * 'zip_attachment' - (integer) The ZIP attachment to download.
  * </pre>
  *
  * @return array  See parent::render().
  */
 protected function _render()
 {
     if (!($zip_atc = Horde_Util::getFormData('zip_attachment'))) {
         $this->_callback = array($this, '_whupsCallback');
         return parent::_render();
     }
     /* Send the requested file. Its position in the zip archive is located
      * in 'zip_attachment'. */
     $data = $this->_mimepart->getContents();
     if (!($zip = $this->getConfigParam('zip'))) {
         $zip = Horde_Compress::factory('zip');
         $this->setConfigParam('zip', $zip);
     }
     $fileKey = $zip_atc - 1;
     $zipInfo = $zip->decompress($data, array('action' => Horde_Compress_Zip::ZIP_LIST));
     /* Verify that the requested file exists. */
     if (isset($zipInfo[$fileKey])) {
         $text = $zip->decompress($data, array('action' => Horde_Compress_Zip::ZIP_DATA, 'info' => &$zipInfo, 'key' => $fileKey));
         if (!empty($text)) {
             return array($this->_mimepart->getMimeId() => array('data' => $text, 'name' => basename($zipInfo[$fileKey]['name']), 'status' => array(), 'type' => 'application/octet-stream'));
         }
     }
     // TODO: Error reporting
     return array();
 }
Пример #4
0
 /**
  * Return the rendered information about the Horde_Mime_Part object.
  *
  * @return array  See parent::render().
  * @throws Horde_Exception
  */
 protected function _renderInfo()
 {
     /* Currently, can't do anything without tar file. */
     $subtype = $this->_mimepart->getSubType();
     if (in_array($subtype, array('gzip', 'x-gzip', 'x-gzip-compressed'))) {
         return array();
     }
     $charset = $this->getConfigParam('charset');
     $contents = $this->_mimepart->getContents();
     /* Decompress gzipped files. */
     if (in_array($subtype, $this->_gzipSubtypes)) {
         if (!$this->getConfigParam('gzip')) {
             $this->setConfigParam('gzip', Horde_Compress::factory('Gzip'));
         }
         $contents = $this->getConfigParam('gzip')->decompress($contents);
     }
     /* Obtain the list of files/data in the tar file. */
     if (!$this->getConfigParam('tar')) {
         $this->setConfigParam('tar', Horde_Compress::factory('Tar'));
     }
     $tarData = $this->getConfigParam('tar')->decompress($contents);
     $fileCount = count($tarData);
     $name = $this->_mimepart->getName(true);
     if (empty($name)) {
         $name = Horde_Mime_Viewer_Translation::t("unnamed");
     }
     $monospace = $this->getConfigParam('monospace');
     $text = '<table><tr><td align="left"><span ' . ($monospace ? 'class="' . $monospace . '">' : 'style="font-family:monospace">') . $this->_textFilter(Horde_Mime_Viewer_Translation::t("Archive Name") . ':  ' . $name, 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n" . $this->_textFilter(Horde_Mime_Viewer_Translation::t("Archive File Size") . ': ' . strlen($contents) . ' bytes', 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n" . $this->_textFilter(sprintf(Horde_Mime_Viewer_Translation::ngettext("File Count: %d file", "File Count: %d files", $fileCount), $fileCount), 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n\n" . $this->_textFilter(str_pad(Horde_Mime_Viewer_Translation::t("File Name"), 62, ' ', STR_PAD_RIGHT) . str_pad(Horde_Mime_Viewer_Translation::t("Attributes"), 15, ' ', STR_PAD_LEFT) . str_pad(Horde_Mime_Viewer_Translation::t("Size"), 10, ' ', STR_PAD_LEFT) . str_pad(Horde_Mime_Viewer_Translation::t("Modified Date"), 19, ' ', STR_PAD_LEFT), 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n" . str_repeat('-', 106) . "\n";
     foreach ($tarData as $val) {
         $text .= $this->_textFilter(str_pad($val['name'], 62, ' ', STR_PAD_RIGHT) . str_pad($val['attr'], 15, ' ', STR_PAD_LEFT) . str_pad($val['size'], 10, ' ', STR_PAD_LEFT) . str_pad(strftime("%d-%b-%Y %H:%M", $val['date']), 19, ' ', STR_PAD_LEFT), 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n";
     }
     return $this->_renderReturn(nl2br($text . str_repeat('-', 106) . "\n</span></td></tr></table>"), 'text/html; charset=' . $charset);
 }
Пример #5
0
 /**
  * Return the rendered information about the Horde_Mime_Part object.
  *
  * @return array  See parent::render().
  * @throws Horde_Exception
  */
 protected function _renderInfo()
 {
     $charset = $this->getConfigParam('charset');
     $contents = $this->_mimepart->getContents();
     if (!$this->getConfigParam('zip')) {
         $this->setConfigParam('zip', Horde_Compress::factory('Zip'));
     }
     $zipInfo = $this->getConfigParam('zip')->decompress($contents, array('action' => Horde_Compress_Zip::ZIP_LIST));
     $fileCount = count($zipInfo);
     $name = $this->_mimepart->getName(true);
     if (empty($name)) {
         $name = Horde_Mime_Viewer_Translation::t("unnamed");
     }
     $monospace = $this->getConfigParam('monospace');
     $text = '<table><tr><td align="left"><span ' . ($monospace ? 'class="' . $monospace . '">' : 'style="font-family:monospace">') . $this->_textFilter(Horde_Mime_Viewer_Translation::t("Archive Name") . ': ' . $name . "\n" . Horde_Mime_Viewer_Translation::t("Archive File Size") . ': ' . strlen($contents) . " bytes\n" . sprintf(Horde_Mime_Viewer_Translation::ngettext("File Count: %d file", "File Count: %d files", $fileCount), $fileCount) . "\n\n" . str_repeat(' ', 15) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Attributes"), 10, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Size"), 10, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Modified Date"), 19, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Method"), 10, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Ratio"), 10, ' ', STR_PAD_LEFT) . "\n", 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . str_repeat('-', 74) . "\n";
     foreach ($zipInfo as $key => $val) {
         $ratio = empty($val['size']) ? 0 : 100 * ($val['csize'] / $val['size']);
         $val['name'] = Horde_String::pad(Horde_String::truncate($val['name'], 15), 15, ' ', STR_PAD_RIGHT);
         $val['attr'] = Horde_String::pad($val['attr'], 10, ' ', STR_PAD_LEFT);
         $val['size'] = Horde_String::pad($val['size'], 10, ' ', STR_PAD_LEFT);
         $val['date'] = Horde_String::pad(strftime("%d-%b-%Y %H:%M", $val['date']), 19, ' ', STR_PAD_LEFT);
         $val['method'] = Horde_String::pad($val['method'], 10, ' ', STR_PAD_LEFT);
         $val['ratio'] = Horde_String::pad(sprintf("%1.1f%%", $ratio), 10, ' ', STR_PAD_LEFT);
         reset($val);
         while (list($k, $v) = each($val)) {
             $val[$k] = $this->_textFilter($v, 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true));
         }
         if (!is_null($this->_callback)) {
             $val = call_user_func($this->_callback, $key, $val);
         }
         $text .= $val['name'] . $val['attr'] . $val['size'] . $val['date'] . $val['method'] . $val['ratio'] . "\n";
     }
     return $this->_renderReturn(nl2br($text . str_repeat('-', 74) . "\n</span></td></tr></table>"), 'text/html; charset=' . $charset);
 }
Пример #6
0
 /**
  */
 public function downloadAll()
 {
     global $page_output, $session;
     $headers = $this->_contents->getHeader();
     $zipfile = trim(preg_replace('/[^\\pL\\pN-+_. ]/u', '_', $headers['Subject']), ' _');
     if (empty($zipfile)) {
         $zipfile = _("attachments.zip");
     } else {
         $zipfile .= '.zip';
     }
     $page_output->disableCompression();
     $session->close();
     $tosave = array();
     foreach ($this->_contents->downloadAllList() as $val) {
         if (!($mime = $this->_getRawDownloadPart($val))) {
             continue;
         }
         if (!($name = $mime->getName(true))) {
             $name = sprintf(_("part %s"), $val);
         }
         $tosave[] = array('data' => $mime->getContents(array('stream' => true)), 'name' => $name);
     }
     if (empty($tosave)) {
         return array();
     }
     return array('data' => Horde_Compress::factory('Zip')->compress($tosave, array('stream' => true)), 'name' => $zipfile, 'type' => 'application/zip');
 }
Пример #7
0
 public function testZipCreateStream()
 {
     $compress = Horde_Compress::factory('Zip');
     $fd = fopen('php://temp', 'r+');
     fwrite($fd, $this->testdata);
     $zip_data = $compress->compress(array(array('data' => $fd, 'name' => 'test.txt')), array('stream' => true));
     // Better test needed
     $this->assertNotEmpty($zip_data);
 }
Пример #8
0
 public function testMultipleAttachments()
 {
     $data = base64_decode(file_get_contents(__DIR__ . '/fixtures/TnefAttachmentsMultiple.txt'));
     $tnef = Horde_Compress::factory('Tnef');
     $tnef_data = $tnef->decompress($data);
     $this->assertEquals($tnef_data[0]['type'], 'application');
     $this->assertEquals($tnef_data[0]['subtype'], 'octet-stream');
     $this->assertEquals($tnef_data[0]['name'], 'Lighthouse.jpg');
     $this->assertEquals($tnef_data[1]['type'], 'application');
     $this->assertEquals($tnef_data[1]['subtype'], 'octet-stream');
     $this->assertEquals($tnef_data[1]['name'], 'Penguins.jpg');
 }
Пример #9
0
 public function testInvalidRarData()
 {
     $compress = Horde_Compress::factory('Rar');
     try {
         $compress->decompress('1234');
         $this->fail('Expected exception.');
     } catch (Horde_Compress_Exception $e) {
     }
     try {
         $compress->decompress(Horde_Compress_Rar::BLOCK_START . '1234');
         $this->fail('Expected exception.');
     } catch (Horde_Compress_Exception $e) {
     }
     $compress->decompress(Horde_Compress_Rar::BLOCK_START . '1234567');
 }
Пример #10
0
 /**
  * Return the rendered information about the Horde_Mime_Part object.
  *
  * @return array  See parent::render().
  * @throws Horde_Exception
  */
 protected function _renderInfo()
 {
     $charset = $this->getConfigParam('charset');
     $contents = $this->_mimepart->getContents();
     /* Decompress gzipped files. */
     if (!($gzip = $this->getConfigParam('gzip'))) {
         $gzip = Horde_Compress::factory('Gzip');
     }
     try {
         $contents = $gzip->decompress($contents);
         $this->_metadata['compressed'] = true;
     } catch (Horde_Compress_Exception $e) {
         $this->_metadata['compressed'] = false;
     }
     /* Obtain the list of files/data in the tar file. */
     if (!($tar = $this->getConfigParam('tar'))) {
         $tar = Horde_Compress::factory('Tar');
     }
     $tarData = null;
     try {
         $tarData = $tar->decompress($contents);
     } catch (Horde_Compress_Exception $e) {
         if ($this->_metadata['compressed']) {
             /* Doubly gzip'd files are somewhat common. Try a second
              * decompression before giving up. */
             try {
                 $tarData = $tar->decompress($gzip->decompress($contents));
             } catch (Horde_Compress_Exception $e) {
             }
         }
     }
     if (is_null($tarData)) {
         return array();
     }
     $fileCount = count($tarData);
     $name = $this->_mimepart->getName(true);
     if (empty($name)) {
         $name = Horde_Mime_Viewer_Translation::t("unnamed");
     }
     $monospace = $this->getConfigParam('monospace');
     $text = '<table><tr><td align="left"><span ' . ($monospace ? 'class="' . $monospace . '">' : 'style="font-family:monospace">') . $this->_textFilter(Horde_Mime_Viewer_Translation::t("Archive Name") . ':  ' . $name, 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n" . $this->_textFilter(Horde_Mime_Viewer_Translation::t("Archive File Size") . ': ' . strlen($contents) . ' bytes', 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n" . $this->_textFilter(sprintf(Horde_Mime_Viewer_Translation::ngettext("File Count: %d file", "File Count: %d files", $fileCount), $fileCount), 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n\n" . $this->_textFilter(str_pad(Horde_Mime_Viewer_Translation::t("File Name"), 62, ' ', STR_PAD_RIGHT) . str_pad(Horde_Mime_Viewer_Translation::t("Attributes"), 15, ' ', STR_PAD_LEFT) . str_pad(Horde_Mime_Viewer_Translation::t("Size"), 10, ' ', STR_PAD_LEFT) . str_pad(Horde_Mime_Viewer_Translation::t("Modified Date"), 19, ' ', STR_PAD_LEFT), 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n" . str_repeat('-', 106) . "\n";
     foreach ($tarData as $val) {
         $text .= $this->_textFilter(str_pad($val['name'], 62, ' ', STR_PAD_RIGHT) . str_pad($val['attr'], 15, ' ', STR_PAD_LEFT) . str_pad($val['size'], 10, ' ', STR_PAD_LEFT) . str_pad(strftime("%d-%b-%Y %H:%M", $val['date']), 19, ' ', STR_PAD_LEFT), 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n";
     }
     return $this->_renderReturn(nl2br($text . str_repeat('-', 106) . "\n</span></td></tr></table>"), 'text/html; charset=' . $charset);
 }
Пример #11
0
 /**
  */
 public function downloadAttach($id, $zip = false)
 {
     global $page_output, $session;
     $session->close();
     $mime = $this->_getRawDownloadPart($id);
     $name = $this->_contents->getPartName($mime);
     /* Compress output? */
     if ($zip) {
         $data = Horde_Compress::factory('Zip')->compress(array(array('data' => $mime->getContents(), 'name' => $name)), array('stream' => true));
         $name .= '.zip';
         $type = 'application/zip';
         $page_output->disableCompression();
     } else {
         $data = $mime->getContents(array('stream' => true));
         $type = $mime->getType(true);
     }
     return array('data' => $data, 'name' => $name, 'type' => $type);
 }
Пример #12
0
 /**
  * Return the rendered information about the Horde_Mime_Part object.
  *
  * @return array  See parent::render().
  * @throws Horde_Exception
  */
 protected function _renderInfo()
 {
     $charset = $this->getConfigParam('charset');
     $contents = $this->_mimepart->getContents();
     if (!$this->getConfigParam('rar')) {
         $this->setConfigParam('rar', Horde_Compress::factory('rar'));
     }
     $rarData = $this->getConfigParam('rar')->decompress($contents);
     $fileCount = count($rarData);
     $name = $this->_mimepart->getName(true);
     if (empty($name)) {
         $name = Horde_Mime_Viewer_Translation::t("unnamed");
     }
     $monospace = $this->getConfigParam('monospace');
     $text = '<table><tr><td align="left"><span ' . ($monospace ? 'class="' . $monospace . '">' : 'style="font-family:monospace">') . $this->_textFilter(Horde_Mime_Viewer_Translation::t("Archive Name") . ':  ' . $name, 'space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n" . $this->_textFilter(Horde_Mime_Viewer_Translation::t("Archive File Size") . ': ' . strlen($contents) . ' bytes', 'space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n" . $this->_textFilter(sprintf(Horde_Mime_Viewer_Translation::ngettext("File Count: %d file", "File Count: %d files", $fileCount), $fileCount), 'space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n\n" . $this->_textFilter(Horde_String::pad(Horde_Mime_Viewer_Translation::t("File Name"), 50, ' ', STR_PAD_RIGHT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Attributes"), 10, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Size"), 10, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Modified Date"), 19, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Method"), 10, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Ratio"), 10, ' ', STR_PAD_LEFT), 'space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n" . str_repeat('-', 109) . "\n";
     foreach ($rarData as $val) {
         $ratio = empty($val['size']) ? 0 : 100 * ($val['csize'] / $val['size']);
         $text .= $this->_textFilter(Horde_String::pad($val['name'], 50, ' ', STR_PAD_RIGHT) . Horde_String::pad($val['attr'], 10, ' ', STR_PAD_LEFT) . Horde_String::pad($val['size'], 10, ' ', STR_PAD_LEFT) . Horde_String::pad(strftime("%d-%b-%Y %H:%M", $val['date']), 19, ' ', STR_PAD_LEFT) . Horde_String::pad($val['method'], 10, ' ', STR_PAD_LEFT) . Horde_String::pad(sprintf("%1.1f%%", $ratio), 10, ' ', STR_PAD_LEFT), 'space2html', array('encode' => true, 'encode_all' => true)) . "\n";
     }
     return $this->_renderReturn(nl2br($text . str_repeat('-', 106) . "\n</span></td></tr></table>"), 'text/html; charset=' . $charset);
 }
Пример #13
0
 /**
  * Return the full rendered version of the Horde_Mime_Part object.
  *
  * @return array  See parent::render().
  * @throws Horde_Exception
  */
 protected function _render()
 {
     $has_xsl = Horde_Util::extensionExists('xsl');
     if ($has_xsl) {
         $tmpdir = Horde_Util::createTempDir(true) . '/';
     }
     $fnames = array('content.xml', 'styles.xml', 'meta.xml');
     $tags = array('text:p' => 'p', 'table:table' => 'table border="0" cellspacing="1" cellpadding="0" ', 'table:table-row' => 'tr bgcolor="#cccccc"', 'table:table-cell' => 'td', 'table:number-columns-spanned=' => 'colspan=');
     if (!$this->getConfigParam('zip')) {
         $this->setConfigParam('zip', Horde_Compress::factory('Zip'));
     }
     $list = $this->getConfigParam('zip')->decompress($this->_mimepart->getContents(), array('action' => Horde_Compress_Zip::ZIP_LIST));
     foreach ($list as $key => $file) {
         if (in_array($file['name'], $fnames)) {
             $content = $this->getConfigParam('zip')->decompress($this->_mimepart->getContents(), array('action' => Horde_Compress_Zip::ZIP_DATA, 'info' => $list, 'key' => $key));
             if ($has_xsl) {
                 file_put_contents($tmpdir . $file['name'], $content);
             } elseif ($file['name'] == 'content.xml') {
                 return array($this->_mimepart->getMimeId() => array('data' => str_replace(array_keys($tags), array_values($tags), $content), 'status' => array(), 'type' => 'text/html; charset=UTF-8'));
             }
         }
     }
     if (!$has_xsl) {
         return array();
     }
     $xslt = new XSLTProcessor();
     $xsl = new DOMDocument();
     $xsl->load(realpath(__DIR__ . '/Ooo/export/xhtml/opendoc2xhtml.xsl'));
     $xslt->importStylesheet($xsl);
     $xslt->setParameter('http://www.w3.org/1999/XSL/Transform', array('metaFileURL' => 'file://' . $tmpdir . 'meta.xml', 'stylesFileURL' => 'file://' . $tmpdir . 'styles.xml', 'java' => false));
     $xml = new DOMDocument();
     $xml->load(realpath($tmpdir . 'content.xml'));
     $result = $xslt->transformToXml($xml);
     if (!$result) {
         $result = libxml_get_last_error()->message;
     }
     return array($this->_mimepart->getMimeId() => array('data' => $result, 'status' => array(), 'type' => 'text/html; charset=UTF-8'));
 }
Пример #14
0
 /**
  * Downloads all requested images as a zip file.  Assumes all permissions
  * have been checked on the requested resource.  Can request either a
  * single gallery of images, OR an array of individual image ids.
  *
  * @param Ansel_Gallery $gallery  The galleries to download
  * @param array $images           The images to download
  */
 public static function downloadImagesAsZip($gallery = null, $images = array())
 {
     global $session;
     if (empty($GLOBALS['conf']['gallery']['downloadzip'])) {
         $GLOBALS['notification']->push(_("Downloading zip files is not enabled. Talk to your server administrator."));
         Horde::url('view.php?view=List', true)->redirect();
         exit;
     }
     // Requested a gallery
     if (!is_null($gallery)) {
         // We can name the zip file with the slug if we have it
         $slug = $gallery->get('slug');
         // Set the date in case we are viewing in date mode
         $gallery->setDate(Ansel::getDateParameter());
         $images = $gallery->listImages();
     }
     // At this point, we should always have a list of images
     if (!count($images)) {
         $notification->push(sprintf(_("There are no photos in %s to download."), $gallery->get('name')), 'horde.message');
         Horde::url('view.php?view=List', true)->redirect();
         exit;
     }
     // Try to close off the current session to avoid locking it while the
     // gallery is downloading.
     $session->close();
     if (!is_null($gallery)) {
         // Check full photo permissions
         if ($gallery->canDownload()) {
             $view = 'full';
         } else {
             $view = 'screen';
         }
     }
     $zipfiles = array();
     foreach ($images as $id) {
         $image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($id);
         // If we didn't select an entire gallery, check the download
         // size for each image.
         if (!isset($view)) {
             $g = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($image->gallery);
             $v = $g->canDownload() ? 'full' : 'screen';
         } else {
             $v = $view;
         }
         $zipfiles[] = array('data' => $image->raw($v), 'name' => $image->filename);
     }
     $zip = Horde_Compress::factory('zip');
     $body = $zip->compress($zipfiles);
     if (!empty($gallery)) {
         $filename = (!empty($slug) ? $slug : $gallery->id) . '.zip';
     } else {
         $filename = 'Ansel.zip';
     }
     $GLOBALS['browser']->downloadHeaders($filename, 'application/zip', false, strlen($body));
     echo $body;
     exit;
 }
Пример #15
0
 /**
  * Handle extracting images from uploaded zip files.
  *
  * @param string $filename  The local path to the zip file.
  *
  * @return array  An array of the resulting image_ids.
  * @throws Ansel_Exception
  */
 private function _handleZip($filename)
 {
     $image_ids = array();
     /* See if we can use the zip extension for reading the file. */
     if (Horde_Util::extensionExists('zip')) {
         $zip = new ZipArchive();
         if ($zip->open($filename) !== true) {
             throw new Ansel_Exception(_("Could not open zip archive."));
         }
         /* Iterate the archive */
         for ($z = 0; $z < $zip->numFiles; $z++) {
             $zinfo = $zip->statIndex($z);
             if ($this->_isMetaFile($zinfo['name'])) {
                 continue;
             }
             /* Extract the image */
             $stream = $zip->getStream($zinfo['name']);
             $zdata = stream_get_contents($stream);
             if (!strlen($zdata)) {
                 throw new Ansel_Exception(_("Could not extract image data from zip archive."));
             }
             /* Save the image */
             $image_id = $this->_gallery->addImage(array('image_filename' => $zinfo['name'], 'image_caption' => '', 'data' => $zdata));
             $image_ids[] = $image_id;
             unset($zdata);
         }
         $zip->close();
         unset($zip);
     } else {
         /* Receiving zip data, but extension not loaded */
         $data = file_get_contents($filename);
         /* Get list of images */
         try {
             $zip = Horde_Compress::factory('zip');
             $files = $zip->decompress($data, array('action' => Horde_Compress_Zip::ZIP_LIST));
         } catch (Horde_Compress_Exception $e) {
             throw new Ansel_Exception($e);
             continue;
         }
         /* Iterate the archive */
         foreach ($files as $key => $zinfo) {
             if ($this->_isMetaFile($zinfo['name'])) {
                 continue;
             }
             /* Extract the image */
             try {
                 $zdata = $zip->decompress($data, array('action' => Horde_Compress_Zip::ZIP_DATA, 'info' => $files, 'key' => $key));
             } catch (Horde_Compress_Exception $e) {
                 throw new Ansel_Exception($e);
             }
             /* Add the image */
             $image_id = $this->_gallery->addImage(array('image_filename' => $zinfo['name'], 'image_caption' => '', 'data' => $zdata));
             $image_ids[] = $image_id;
             unset($zdata);
         }
         unset($zip);
         unset($data);
     }
     return $image_ids;
 }
Пример #16
0
 /**
  * Imports messages from a mbox (see RFC 4155) -or- a message source
  * (eml) file.
  *
  * @param string $fname  Filename containing the message data.
  * @param string $type   The MIME type of the message data.
  *
  * @return mixed  False (boolean) on fail or the number of messages
  *                imported (integer) on success.
  * @throws IMP_Exception
  */
 protected function _import($fname, $type)
 {
     if (!is_readable($fname)) {
         return false;
     }
     $fd = null;
     switch ($type) {
         case 'application/gzip':
         case 'application/x-gzip':
         case 'application/x-gzip-compressed':
             // No need to default to Horde_Compress because it uses zlib
             // also.
             if (in_array('compress.zlib', stream_get_wrappers())) {
                 $fd = 'compress.zlib://' . $fname;
             }
             break;
         case 'application/x-bzip2':
         case 'application/x-bzip':
             if (in_array('compress.bzip2', stream_get_wrappers())) {
                 $fd = 'compress.bzip2://' . $fname;
             }
             break;
         case 'application/zip':
         case 'application/x-compressed':
         case 'application/x-zip-compressed':
             if (in_array('zip', stream_get_wrappers())) {
                 $fd = 'zip://' . $fname;
             } else {
                 try {
                     $zip = Horde_Compress::factory('Zip');
                     if ($zip->canDecompress) {
                         $file_data = file_get_contents($fname);
                         $zip_info = $zip->decompress($file_data, array('action' => Horde_Compress_Zip::ZIP_LIST));
                         if (!empty($zip_info)) {
                             $fd = fopen('php://temp', 'r+');
                             foreach (array_keys($zip_info) as $key) {
                                 fwrite($fd, $zip->decompress($file_data, array('action' => Horde_Compress_Zip::ZIP_DATA, 'info' => $zip_info, 'key' => $key)));
                             }
                             rewind($fd);
                         }
                     }
                 } catch (Horde_Compress_Exception $e) {
                     if ($fd) {
                         fclose($fd);
                         $fd = null;
                     }
                 }
             }
             break;
         default:
             $fd = $fname;
             break;
     }
     if (is_null($fd)) {
         throw new IMP_Exception(_("The uploaded file cannot be opened."));
     }
     $parsed = new Horde_Mail_Mbox_Parse($fd, $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->config->import_limit);
     $this->_import = array('data' => array(), 'msgs' => 0, 'size' => 0);
     if ($pcount = count($parsed)) {
         foreach ($parsed as $key => $val) {
             $this->_importHelper($val, $key + 1 != $pcount);
         }
     } else {
         $this->_importHelper($parsed[0]);
     }
     return $this->_import['msgs'] ? $this->_import['msgs'] : false;
 }
Пример #17
0
 /**
  * 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;
 }
Пример #18
0
 /**
  * URL parameters:
  *   - actionID
  *
  * @throws IMP_Exception
  */
 public function download(Horde_Variables $vars)
 {
     global $injector, $registry;
     /* Check for an authenticated user. */
     if (!$registry->isAuthenticated(array('app' => 'imp'))) {
         $e = new IMP_Exception(_("User is not authenticated."));
         $e->logged = true;
         throw $e;
     }
     switch ($vars->actionID) {
         case 'download_all':
             $view_ob = new IMP_Contents_View(new IMP_Indices_Mailbox($vars));
             $view_ob->checkToken($vars);
             return $view_ob->downloadAll();
         case 'download_attach':
             $view_ob = new IMP_Contents_View(new IMP_Indices_Mailbox($vars));
             $view_ob->checkToken($vars);
             return $view_ob->downloadAttach($vars->id, $vars->zip);
         case 'download_mbox':
             $mlist = IMP_Mailbox::formFrom($vars->mbox_list);
             $mbox = $injector->getInstance('IMP_Mbox_Generate')->generate($mlist);
             $name = is_array($mlist) ? reset($mlist) : $mlist;
             switch ($vars->type) {
                 case 'mbox':
                     return array('data' => $mbox, 'name' => $name . '.mbox', 'type' => 'text/plain; charset=UTF-8');
                 case 'mboxzip':
                     try {
                         $data = Horde_Compress::factory('Zip')->compress(array(array('data' => $mbox, 'name' => $name . '.mbox')), array('stream' => true));
                         fclose($mbox);
                     } catch (Horde_Exception $e) {
                         fclose($mbox);
                         throw $e;
                     }
                     return array('data' => $data, 'name' => $name . '.zip', 'type' => 'application/zip');
             }
             break;
         case 'download_render':
             $view_ob = new IMP_Contents_View(new IMP_Indices_Mailbox($vars));
             $view_ob->checkToken($vars);
             return $view_ob->downloadRender($vars->id, $vars->mode, $vars->ctype);
         case 'save_message':
             $view_ob = new IMP_Contents_View(new IMP_Indices_Mailbox($vars));
             return $view_ob->saveMessage();
     }
     return array();
 }
Пример #19
0
 /**
  * Gets the configuration for a MIME type.
  *
  * @param string $type  The MIME type.
  * @param string $app   The current Horde application.
  *
  * @return array  The driver and a list of configuration parameters.
  */
 public function getViewerConfig($type, $app)
 {
     $config = $this->_getDriver($type, $app);
     $config['driver'] = Horde_String::ucfirst($config['driver']);
     $driver = $config['app'] == 'horde' ? $config['driver'] : $config['app'] . '_Mime_Viewer_' . $config['driver'];
     $params = array_merge($config, array('charset' => 'UTF-8', 'temp_file' => array('Horde', 'getTempFile'), 'text_filter' => array($this->_injector->getInstance('Horde_Core_Factory_TextFilter'), 'filter')));
     switch ($config['driver']) {
         case 'Deb':
         case 'Rpm':
             $params['monospace'] = 'fixed';
             break;
         case 'Html':
             $params['browser'] = $GLOBALS['browser'];
             $params['dns'] = $this->_injector->getInstance('Net_DNS2_Resolver');
             $params['external_callback'] = array('Horde', 'externalUrl');
             break;
         case 'Ooo':
             $params['zip'] = Horde_Compress::factory('Zip');
             break;
         case 'Rar':
             $params['monospace'] = 'fixed';
             $params['rar'] = Horde_Compress::factory('Rar');
             break;
         case 'Report':
         case 'Security':
             $params['viewer_callback'] = array($this, 'getViewerCallback');
             break;
         case 'Syntaxhighlighter':
             if ($config['app'] == 'horde') {
                 $driver = 'Horde_Core_Mime_Viewer_Syntaxhighlighter';
             }
             $params['registry'] = $GLOBALS['registry'];
             break;
         case 'Tgz':
             $params['gzip'] = Horde_Compress::factory('Gzip');
             $params['monospace'] = 'fixed';
             $params['tar'] = Horde_Compress::factory('Tar');
             break;
         case 'Tnef':
             $params['tnef'] = Horde_Compress::factory('Tnef');
             break;
         case 'Vcard':
             if ($config['app'] == 'horde') {
                 $driver = 'Horde_Core_Mime_Viewer_Vcard';
             }
             $params['browser'] = $GLOBALS['browser'];
             $params['notification'] = $GLOBALS['notification'];
             $params['prefs'] = $GLOBALS['prefs'];
             $params['registry'] = $GLOBALS['registry'];
             break;
         case 'Zip':
             $params['monospace'] = 'fixed';
             $params['zip'] = Horde_Compress::factory('Zip');
             break;
     }
     return array($this->_getDriverName($driver, 'Horde_Mime_Viewer'), $params);
 }