Esempio n. 1
0
 /**
  * Create a new instance for an ComposerMessage for example.
  * 
  * @param \GO\Base\Fs\File $file The temporary file
  * @return \MessageAttachment 
  */
 public function createFromTempFile(\GO\Base\Fs\File $file)
 {
     //		$a['name'] = $file->name();
     $a = new MessageAttachment();
     $a->name = $file->name();
     $a->mime = $file->mimeType();
     $a->setTempFile($file);
     $a->size = $file->size();
     return $a;
 }
Esempio n. 2
0
 public function getAsArray($redundantly = false)
 {
     if (isset($this->id) && (int) $this->id > 0) {
         $content = array();
         if (!is_null($this->text)) {
             $content['text'] = $this->text;
         } else {
             if (!is_null($this->image_id)) {
                 $domain = 'http' . (Request::server('HTTPS') ? '' : 's') . '://' . Request::server('HTTP_HOST');
                 $attachment = MessageAttachment::find($this->image_id);
                 $content['image'] = array('id' => (int) $attachment->id, 'thumb' => $domain . '/api/messages/attach/thumb/' . $attachment->id, 'origin' => $domain . '/api/messages/attach/gallery/' . $attachment->id, 'width' => $attachment->width, 'height' => $attachment->height);
             } else {
                 if (!is_null($this->car_id)) {
                     $car = Car::withTrashed()->find($this->car_id);
                     $content['car'] = array('id' => (int) $car->id, 'mark' => (int) $car->mark, 'model' => (int) $car->model, 'year' => (int) $car->year, 'color' => (int) $car->color, 'vehicle_type' => (int) $car->vehicle_type, 'body_type' => (int) $car->body_type);
                     if (!is_null($this->car_number)) {
                         $content['car']['number'] = $this->car_number;
                     }
                 } else {
                     if (!is_null($this->lat)) {
                         $content['geo'] = array('lat' => (double) $this->lat, 'long' => (double) $this->lng, 'location' => $this->location);
                     }
                 }
             }
         }
         if ($redundantly) {
             $user = User::find($this->user_id);
             return array('message_id' => (int) $this->id, 'chat_id' => (int) $this->chat_id, 'user' => array('id' => (int) $user->id, 'name' => $user->name, 'img' => array('middle' => $user->img_middle)), 'content' => $content, 'timestamp' => $this->getTimestamp(), 'delivered_at' => $this->delivered_at, 'viewed_at' => $this->viewed_at);
         } else {
             return array('message_id' => (int) $this->id, 'chat_id' => (int) $this->chat_id, 'user_id' => (int) $this->user_id, 'content' => $content, 'timestamp' => $this->getTimestamp(), 'delivered_at' => $this->delivered_at, 'viewed_at' => $this->viewed_at);
         }
     }
     return array();
 }
Esempio n. 3
0
 public function getUrl()
 {
     if ($this->hasTempFile()) {
         return parent::getUrl();
     } else {
         $params = array("account_id" => $this->account->id, "mailbox" => $this->mailbox, "uid" => $this->uid, "number" => $this->number, "encoding" => $this->encoding, "filename" => $this->name);
     }
     $nameArr = explode('.', $this->name);
     if (\GO::modules()->isInstalled('addressbook') && $nameArr[count($nameArr) - 1] == 'vcf') {
         return \GO::url('addressbook/contact/handleAttachedVCard', $params);
     }
     return \GO::url('email/message/attachment', $params);
 }
Esempio n. 4
0
 private function _getParts($structure, $part_number_prefix = '')
 {
     if (isset($structure->parts)) {
         $structure->ctype_primary = strtolower($structure->ctype_primary);
         $structure->ctype_secondary = strtolower($structure->ctype_secondary);
         //$part_number=0;
         foreach ($structure->parts as $part_number => $part) {
             $part->ctype_primary = strtolower($part->ctype_primary);
             $part->ctype_secondary = strtolower($part->ctype_secondary);
             //text part and no attachment so it must be the body
             if ($structure->ctype_primary == 'multipart' && $structure->ctype_secondary == 'alternative' && $part->ctype_primary == 'text' && $part->ctype_secondary == 'plain') {
                 //check if html part is there
                 if ($this->_hasHtmlPart($structure)) {
                     continue;
                 }
             }
             if ($part->ctype_primary == 'text' && ($part->ctype_secondary == 'plain' || $part->ctype_secondary == 'html') && (!isset($part->disposition) || $part->disposition != 'attachment') && empty($part->d_parameters['filename'])) {
                 $charset = isset($part->ctype_parameters['charset']) ? $part->ctype_parameters['charset'] : 'UTF-8';
                 $body = \GO\Base\Util\String::clean_utf8($part->body, $charset);
                 if (stripos($part->ctype_secondary, 'plain') !== false) {
                     $body = nl2br($body);
                 } else {
                     $body = \GO\Base\Util\String::convertLinks($body);
                     $body = \GO\Base\Util\String::sanitizeHtml($body);
                     $body = $body;
                 }
                 $this->_loadedBody .= $body;
             } elseif ($part->ctype_primary == 'multipart') {
             } else {
                 //attachment
                 if (!empty($part->ctype_parameters['name'])) {
                     $filename = $part->ctype_parameters['name'];
                 } elseif (!empty($part->d_parameters['filename'])) {
                     $filename = $part->d_parameters['filename'];
                 } elseif (!empty($part->d_parameters['filename*'])) {
                     $filename = $part->d_parameters['filename*'];
                 } else {
                     $filename = uniqid(time());
                 }
                 $mime_type = $part->ctype_primary . '/' . $part->ctype_secondary;
                 if (isset($part->headers['content-id'])) {
                     $content_id = trim($part->headers['content-id']);
                     if (strpos($content_id, '>')) {
                         $content_id = substr($part->headers['content-id'], 1, strlen($part->headers['content-id']) - 2);
                     }
                 } else {
                     $content_id = '';
                 }
                 $f = new \GO\Base\Fs\File($filename);
                 $a = new MessageAttachment();
                 $a->name = $filename;
                 $a->number = $part_number_prefix . $part_number;
                 $a->content_id = $content_id;
                 $a->mime = $mime_type;
                 $tmp_file = new \GO\Base\Fs\File($this->_getTempDir() . $filename);
                 if (!empty($part->body)) {
                     $tmp_file = new \GO\Base\Fs\File($this->_getTempDir() . $filename);
                     if (!$tmp_file->exists()) {
                         $tmp_file->putContents($part->body);
                     }
                     $a->setTempFile($tmp_file);
                 }
                 $a->index = count($this->attachments);
                 $a->size = isset($part->body) ? strlen($part->body) : 0;
                 $a->encoding = isset($part->headers['content-transfer-encoding']) ? $part->headers['content-transfer-encoding'] : '';
                 $a->disposition = isset($part->disposition) ? $part->disposition : '';
                 $this->addAttachment($a);
             }
             //$part_number++;
             if (isset($part->parts)) {
                 $this->_getParts($part, $part_number_prefix . $part_number . '.');
             }
         }
     } elseif (isset($structure->body)) {
         $charset = isset($structure->ctype_parameters['charset']) ? $structure->ctype_parameters['charset'] : 'UTF-8';
         $text_part = \GO\Base\Util\String::clean_utf8($structure->body, $charset);
         //convert text to html
         if (stripos($structure->ctype_secondary, 'plain') !== false) {
             $this->extractUuencodedAttachments($text_part);
             $text_part = nl2br($text_part);
         } else {
             $text_part = \GO\Base\Util\String::convertLinks($text_part);
             $text_part = \GO\Base\Util\String::sanitizeHtml($text_part);
         }
         $this->_loadedBody .= $text_part;
     }
 }
Esempio n. 5
0
 /**
  * Attach a image to chating
  *
  * @return Response
  */
 public function attach()
 {
     $chatId = (int) Input::get('chat_id');
     if ((int) $chatId > 0 && !is_null($chat = Chat::find((int) $chatId)) && $chat->hasMember(Auth::user()->id)) {
         if (Input::hasFile('image')) {
             $file = Input::file('image');
             if (in_array(strtolower($file->guessExtension()), array('png', 'gif', 'jpeg', 'jpg'))) {
                 $attachment = new MessageAttachment();
                 $attachment->chat_id = $chat->id;
                 $attachment->origin = '';
                 $attachment->thumb = '';
                 $attachment->save();
                 $this->log('Init images');
                 $this->log(memory_get_usage(true));
                 $origin = new ImageUtil($file);
                 $attachment->origin = $this->upload($attachment->id, 'origin', $origin->getImage());
                 $attachment->gallery = $this->upload($attachment->id, 'gallery', $origin->resize2('gallery')->getImage());
                 $origin->getImage()->destroy();
                 $origin = null;
                 $this->log('Gallery and origin images should be destroyed');
                 $this->log(memory_get_usage(true));
                 $this->log('Init thumbnail');
                 $thumb = (new ImageUtil($file))->resize2('thumbnail');
                 $this->log(memory_get_usage(true));
                 $this->log('Uploading');
                 $attachment->thumb = $this->upload($attachment->id, 'thumb', $thumb->getImage());
                 $this->log(memory_get_usage(true));
                 $attachment->width = $thumb->getWidth();
                 $attachment->height = $thumb->getHeight();
                 $thumb->getImage()->destroy();
                 $thumb = null;
                 $this->log('Thumbnail destroyed');
                 $this->log(memory_get_usage(true));
                 $attachment->save();
                 $domain = 'http' . (Request::server('HTTPS') ? '' : 's') . '://' . Request::server('HTTP_HOST');
                 return $this->respond(array('id' => (int) $attachment->id, 'thumb' => $domain . '/api/messages/attach/thumb/' . $attachment->id, 'origin' => $domain . '/api/messages/attach/gallery/' . $attachment->id, 'width' => $attachment->width, 'height' => $attachment->height));
             } else {
                 return $this->respondWithError('Image has unsupported extension (sent file extension' . strtolower($file->guessExtension()) . ')');
             }
         } else {
             return $this->respondWithError('Image isn\'t found');
         }
     } else {
         return $this->respondWithError('Chat isn\'t found');
     }
 }