IMP_Compose::_linkAttachments PHP Method

_linkAttachments() protected method

Adds linked attachments to message.
protected _linkAttachments ( &$body, mixed $html )
$html mixed HTML data (Horde_Domhtml) or null.
    protected function _linkAttachments(&$body, $html)
    {
        global $conf;
        if (empty($conf['compose']['link_attachments'])) {
            return;
        }
        $link_all = false;
        $linked = array();
        if (!empty($conf['compose']['link_attach_size_hard'])) {
            $limit = intval($conf['compose']['link_attach_size_hard']);
            foreach ($this as $val) {
                if (($limit -= $val->getPart()->getBytes()) < 0) {
                    $link_all = true;
                    break;
                }
            }
        }
        foreach (iterator_to_array($this) as $key => $val) {
            if ($link_all && !$val->linked) {
                $val = new IMP_Compose_Attachment($this, $val->getPart(), $val->storage->getTempFile());
                $val->forceLinked = true;
                unset($this[$key]);
                $this[$key] = $val;
            }
            if ($val->linked && !$val->related) {
                $linked[] = $val;
            }
        }
        if (empty($linked)) {
            return;
        }
        if ($del_time = IMP_Compose_LinkedAttachment::keepDate(false)) {
            /* Subtract 1 from time to get the last day of the previous
             * month. */
            $expire = ' (' . sprintf(_("links will expire on %s"), strftime('%x', $del_time - 1)) . ')';
        }
        $body .= "\n-----\n" . _("Attachments") . $expire . ":\n";
        if ($html) {
            $body = $html->getBody();
            $dom = $html->dom;
            $body->appendChild($dom->createElement('HR'));
            $body->appendChild($div = $dom->createElement('DIV'));
            $div->appendChild($dom->createElement('H4', _("Attachments") . $expire . ':'));
            $div->appendChild($ol = $dom->createElement('OL'));
        }
        $i = 0;
        foreach ($linked as $val) {
            $apart = $val->getPart();
            $name = $apart->getName(true);
            $size = IMP::sizeFormat($apart->getBytes());
            $url = strval($val->link_url->setRaw(true));
            $body .= "\n" . ++$i . '. ' . $name . ' (' . $size . ') [' . $apart->getType() . "]\n" . sprintf(_("Download link: %s"), $url) . "\n";
            if ($html) {
                $ol->appendChild($li = $dom->createElement('LI'));
                $li->appendChild($dom->createElement('STRONG', $name));
                $li->appendChild($dom->createTextNode(' (' . $size . ') [' . htmlspecialchars($apart->getType()) . ']'));
                $li->appendChild($dom->createElement('BR'));
                $li->appendChild($dom->createTextNode(_("Download link") . ': '));
                $li->appendChild($a = $dom->createElement('A', htmlspecialchars($url)));
                $a->setAttribute('href', $url);
            }
        }
    }