Пример #1
0
 /**
  *
  * @return ImapMessageAttachment [] 
  */
 public function &getAttachments()
 {
     if (!$this->_imapAttachmentsLoaded) {
         $this->_imapAttachmentsLoaded = true;
         $imap = $this->getImapConnection();
         $this->_loadBodyParts();
         $parts = $imap->find_message_attachments($this->_getStruct(), $this->_bodyPartNumbers);
         $uniqueNames = array();
         foreach ($parts as $part) {
             //ignore applefile's
             //	Don't ignore it as it seems to be a valid attachment in some mails.
             //				if($part['subtype']=='applefile')
             //					continue;
             $a = new ImapMessageAttachment();
             $a->setImapParams($this->account, $this->mailbox, $this->uid);
             if (empty($part['name']) || $part['name'] == 'false') {
                 if (!empty($part['subject'])) {
                     $a->name = \GO\Base\Fs\File::stripInvalidChars(\GO\Base\Mail\Utils::mimeHeaderDecode($part['subject'])) . '.eml';
                 } elseif ($part['type'] == 'message') {
                     $a->name = isset($part['description']) ? \GO\Base\Fs\File::stripInvalidChars($part['description']) . '.eml' : 'message.eml';
                 } elseif ($part['subtype'] == 'calendar') {
                     $a->name = \GO::t('event', 'email') . '.ics';
                 } else {
                     if ($part['type'] == 'text') {
                         $a->name = $part['subtype'] . '.txt';
                     } else {
                         $a->name = $part['type'] . '-' . $part['subtype'];
                     }
                 }
             } else {
                 $a->name = \GO\Base\Mail\Utils::mimeHeaderDecode($part['name']);
                 $extension = \GO\Base\Fs\File::getExtension($a->name);
                 if (!empty($part['filename']) && empty($extension)) {
                     $a->name = \GO\Base\Mail\Utils::mimeHeaderDecode($part['filename']);
                 }
             }
             $i = 1;
             $a->name = !empty($a->name) ? $a->name : \GO::t('noname', 'email');
             $file = new \GO\Base\Fs\File($a->name);
             while (in_array($a->name, $uniqueNames)) {
                 $a->name = $file->nameWithoutExtension() . ' (' . $i . ').' . $file->extension();
                 $i++;
             }
             $uniqueNames[] = $a->name;
             $a->disposition = isset($part['disposition']) ? strtolower($part['disposition']) : '';
             $a->number = $part['number'];
             $a->content_id = '';
             if (!empty($part["id"])) {
                 //when an image has an id it belongs somewhere in the text we gathered above so replace the
                 //source id with the correct link to display the image.
                 $tmp_id = $part["id"];
                 if (strpos($tmp_id, '>')) {
                     $tmp_id = substr($part["id"], 1, -1);
                 }
                 $id = $tmp_id;
                 $a->content_id = $id;
             }
             $a->mime = $part['type'] . '/' . $part['subtype'];
             $a->index = count($this->attachments);
             $a->size = intval($part['size']);
             $a->encoding = $part['encoding'];
             $a->charset = !empty($part['charset']) ? $part['charset'] : $this->charset;
             $this->addAttachment($a);
         }
     }
     return $this->attachments;
 }
Пример #2
0
 static function render($params, $tag, \GO\Site\Model\Content $content)
 {
     $html = '';
     if (empty($params['path'])) {
         return "Error: path attribute must be set in img tag!";
     }
     //Change Tickets.png into public/site/1/files/Tickets.png
     $folder = new \GO\Base\Fs\Folder(Site::model()->getPublicPath());
     $fullRelPath = $folder->stripFileStoragePath() . '/files/' . $params['path'];
     //		var_dump($p);
     $thumbParams = $params;
     unset($thumbParams['path'], $thumbParams['lightbox'], $thumbParams['alt'], $thumbParams['class'], $thumbParams['style'], $thumbParams['astyle'], $thumbParams['caption'], $thumbParams['aclass']);
     if (!isset($thumbParams['lw']) && !isset($thumbParams['w'])) {
         $thumbParams['lw'] = 300;
     }
     if (!isset($thumbParams['ph']) && !isset($thumbParams['ph'])) {
         $thumbParams['ph'] = 300;
     }
     $thumb = Site::thumb($fullRelPath, $thumbParams);
     if (!isset($params['caption'])) {
         $file = new \GO\Base\Fs\File($fullRelPath);
         $params['caption'] = $file->nameWithoutExtension();
     }
     if (!isset($params['alt'])) {
         $params['alt'] = isset($params['caption']) ? $params['caption'] : basename($tag['params']['path']);
     }
     $html .= '<img src="' . $thumb . '" alt="' . $params['alt'] . '"';
     $html .= 'class="thumb-img"';
     $html .= ' />';
     if (!isset($params['lightbox'])) {
         $params['lightbox'] = "thumb";
     }
     if (!empty($params['lightbox'])) {
         $a = '<a';
         if (isset($params['caption'])) {
             $a .= ' title="' . $params['caption'] . '"';
         }
         if (!isset($params['aclass'])) {
             $params['aclass'] = 'thumb-a';
         }
         $a .= ' class="' . $params['aclass'] . '"';
         if (isset($params['astyle'])) {
             $a .= ' style="' . $params['astyle'] . '"';
         }
         $a .= ' data-lightbox="' . $params['lightbox'] . '" href="' . \Site::file($params['path'], false) . '">' . $html . '</a>';
         // Create an url to the original image
         $html = $a;
     }
     if (isset($params['caption'])) {
         $html .= '<div class="thumb-caption">' . $params['caption'] . '</div>';
     }
     if (!isset($params['class'])) {
         $params['class'] = 'thumb-wrap';
     }
     $wrap = '<div class="' . $params['class'] . '"';
     if (isset($params['style'])) {
         $wrap .= 'style="' . $params['style'] . '"';
     }
     $wrap .= '>';
     $html = $wrap . $html . '</div>';
     return $html;
 }