Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     if ($this->entity instanceof Message) {
         $this->message_hash = $this->entity->getHash();
         $this->message_type = $this->entity->getMessageType();
     } else {
         if (!$this->message_type) {
             $this->message_type = Message::TYPE_PRIVATE;
         }
     }
     // files being uploaded via $_FILES
     $uploads = UploadHandler::handle('attachments');
     if ($uploads) {
         foreach ($uploads as $upload) {
             if ($upload instanceof ElggFile) {
                 $this->attachment_guids[] = $upload->guid;
             }
         }
     }
     $this->attachments = Group::create($this->attachment_guids)->entities();
     $access_id = AccessCollection::create(array($this->sender_guid, $this->recipient_guids))->getCollectionId();
     foreach ($this->attachments as $attachment) {
         $attachment->origin = 'messages';
         $attachment->access_id = $access_id;
         $attachment->save();
     }
     $guid = Message::factory(array('sender' => $this->sender_guid, 'recipients' => $this->recipient_guids, 'subject' => $this->subject, 'body' => $this->body, 'message_hash' => $this->message_hash, 'attachments' => $this->attachments))->send();
     $this->entity = $guid ? get_entity($guid) : false;
     if (!$this->entity) {
         // delete attachment if message failed to send
         foreach ($this->attachments as $attachment) {
             $attachment->delete();
         }
         $this->result->addError(elgg_echo('inbox:send:error:generic'));
         return;
     }
     $sender = $this->entity->getSender();
     $this->message_type = $this->entity->getMessageType();
     $this->message_hash = $this->entity->getHash();
     $ruleset = hypeInbox()->config->getRuleset($this->message_type);
     $this->attachments = array_map(array(hypeInbox()->model, 'getLinkTag'), $this->attachments);
     $body = array_filter(array($ruleset->hasSubject() ? $this->entity->subject : '', $this->entity->getBody(), implode(', ', array_filter($this->attachments))));
     $notification_body = implode(PHP_EOL, $body);
     foreach ($this->recipient_guids as $recipient_guid) {
         $recipient = get_entity($recipient_guid);
         if (!$recipient) {
             continue;
         }
         $type_label = strtolower($ruleset->getSingularLabel($recipient->language));
         $subject = elgg_echo('inbox:notification:subject', array($type_label), $recipient->language);
         $notification = elgg_echo('inbox:notification:body', array($type_label, $sender->name, $notification_body, elgg_view('output/url', array('href' => $this->entity->getURL())), $sender->name, elgg_view('output/url', array('href' => elgg_normalize_url("messages/thread/{$this->message_hash}#reply")))), $recipient->language);
         $summary = elgg_echo('inbox:notification:summary', array($type_label), $recipient->language);
         notify_user($recipient->guid, $sender->guid, $subject, $notification, array('action' => 'send', 'object' => $this->entity, 'summary' => $summary));
     }
     $this->result->addMessage(elgg_echo('inbox:send:success'));
     $this->result->setForwardURL($this->entity->getURL());
 }
Exemplo n.º 2
0
}
if (empty(elgg_strip_tags($body))) {
    register_error(elgg_echo('inbox:send:error:no_body'));
    forward(REFERRER);
}
$enable_html = elgg_get_plugin_setting('enable_html', 'hypeInbox');
if (!$enable_html) {
    $body = elgg_strip_tags($body);
}
$message_hash = '';
$message_type = get_input('message_type', Message::TYPE_PRIVATE);
if ($original_message instanceof Message) {
    $message_hash = $original_message->getHash();
    $message_type = $original_message->getMessageType();
}
$message = Message::factory(array('sender' => $sender_guid, 'recipients' => $recipient_guids, 'subject' => $subject, 'body' => $body, 'hash' => $message_hash, 'message_type' => $message_type));
$guid = $message->send();
if (!$guid) {
    register_error(elgg_echo('inbox:send:error:generic'));
    forward(REFERRER);
}
$new_message = get_entity($guid);
$sender = $new_message->getSender();
$message_type = $new_message->getMessageType();
$message_hash = $new_message->getHash();
$ruleset = hypeInbox()->config->getRuleset($message_type);
$recipients = $new_message->getRecipients();
foreach ($recipients as $recipient) {
    if ($recipient->guid == $sender->guid) {
        continue;
    }