Exemplo n.º 1
0
 public static function add(\Concrete\Core\Conversation\Conversation $cnv, Author $author, $cnvMessageSubject, $cnvMessageBody, $parentMessage = false)
 {
     $db = Loader::db();
     $date = Loader::helper('date')->getOverridableNow();
     $uID = 0;
     $user = $author->getUser();
     $cnvMessageAuthorName = $author->getName();
     $cnvMessageAuthorEmail = $author->getEmail();
     $cnvMessageAuthorWebsite = $author->getWebsite();
     if (is_object($user)) {
         $uID = $user->getUserID();
     }
     $cnvMessageParentID = 0;
     $cnvMessageLevel = 0;
     if (is_object($parentMessage)) {
         $cnvMessageParentID = $parentMessage->getConversationMessageID();
         $cnvMessageLevel = $parentMessage->getConversationMessageLevel() + 1;
     }
     $cnvID = 0;
     if ($cnv instanceof Conversation) {
         $cnvID = $cnv->getConversationID();
     }
     $editor = ConversationEditor::getActive();
     $cnvEditorID = $editor->getConversationEditorID();
     /** @var \Concrete\Core\Permission\IPService $iph */
     $iph = Core::make('helper/validation/ip');
     $ip = $iph->getRequestIP();
     $r = $db->Execute('insert into ConversationMessages (cnvMessageSubject, cnvMessageBody, cnvMessageDateCreated, cnvMessageParentID, cnvEditorID, cnvMessageLevel, cnvID, uID, cnvMessageAuthorName, cnvMessageAuthorEmail, cnvMessageAuthorWebsite, cnvMessageSubmitIP, cnvMessageSubmitUserAgent) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', array($cnvMessageSubject, $cnvMessageBody, $date, $cnvMessageParentID, $cnvEditorID, $cnvMessageLevel, $cnvID, $uID, $cnvMessageAuthorName, $cnvMessageAuthorEmail, $cnvMessageAuthorWebsite, $ip === false ? '' : $ip->getIp(), $_SERVER['HTTP_USER_AGENT']));
     $cnvMessageID = $db->Insert_ID();
     $message = static::getByID($cnvMessageID);
     $event = new MessageEvent($message);
     Events::dispatch('on_new_conversation_message', $event);
     if ($cnv instanceof \Concrete\Core\Conversation\Conversation) {
         $cnv->updateConversationSummary();
         $users = $cnv->getConversationUsersToEmail();
         $c = $cnv->getConversationPageObject();
         if (is_object($c)) {
             $formatter = new AuthorFormatter($author);
             $cnvMessageBody = html_entity_decode($cnvMessageBody, ENT_QUOTES, APP_CHARSET);
             foreach ($users as $ui) {
                 $mail = Core::make('mail');
                 $mail->to($ui->getUserEmail());
                 $mail->addParameter('title', $c->getCollectionName());
                 $mail->addParameter('link', $c->getCollectionLink(true));
                 $mail->addParameter('poster', $formatter->getDisplayName());
                 $mail->addParameter('body', Core::make('helper/text')->prettyStripTags($cnvMessageBody));
                 $mail->load('new_conversation_message');
                 $mail->sendMail();
             }
         }
     }
     return static::getByID($cnvMessageID);
 }
Exemplo n.º 2
0
 /**
  * Returns a formatted conversation message body string, based on configuration options supplied.
  *
  * @param \Concrete\Core\Conversation\Conversation $cnv
  * @param string $cnvMessageBody
  * @param array $config
  *
  * @return string
  */
 public function formatConversationMessageBody($cnv, $cnvMessageBody, $config = array())
 {
     /** @var  \Concrete\Core\Html\Service\Html $htmlHelper */
     $htmlHelper = Core::make('helper/html');
     $cnvMessageBody = $htmlHelper->noFollowHref($cnvMessageBody);
     if (isset($config['htmlawed'])) {
         $default = array('safe' => 1, 'elements' => 'p, br, strong, em, strike, a');
         $conf = array_merge($default, (array) $config['htmlawed']);
         $lawed = htmLawed($cnvMessageBody, $conf);
     } else {
         $lawed = $cnvMessageBody;
     }
     if ($config['mention'] !== false) {
         $users = $cnv->getConversationMessageUsers();
         $needle = array();
         $haystack = array();
         foreach ($users as $user) {
             $needle[] = "@" . $user->getUserName();
             $haystack[] = "<a href='" . $user->getUserPublicProfileURL() . "'>'@" . $user->getUserName() . "</a>";
         }
         return str_ireplace($needle, $haystack, $lawed);
     }
     return $lawed;
 }
Exemplo n.º 3
0
 public function save($post)
 {
     $helperFile = Core::make('helper/concrete/file');
     $db = Database::get();
     $cnvID = $db->GetOne('select cnvID from btCoreConversation where bID = ?', array($this->bID));
     if (!$cnvID) {
         $conversation = Conversation::add();
         $b = $this->getBlockObject();
         $xc = $b->getBlockCollectionObject();
         $conversation->setConversationPageObject($xc);
     } else {
         $conversation = Conversation::getByID($cnvID);
     }
     $values = $post + array('attachmentOverridesEnabled' => null, 'attachmentsEnabled' => null, 'itemsPerPage' => null, 'maxFilesGuest' => null, 'maxFilesRegistered' => null, 'maxFileSizeGuest' => null, 'maxFileSizeRegistered' => null, 'enableOrdering' => null, 'enableCommentRating' => null, 'notificationOverridesEnabled' => null, 'subscriptionEnabled' => null, 'fileExtensions' => null);
     if ($values['attachmentOverridesEnabled']) {
         $conversation->setConversationAttachmentOverridesEnabled(intval($values['attachmentOverridesEnabled']));
     } else {
         $conversation->setConversationAttachmentOverridesEnabled(0);
     }
     if ($values['attachmentsEnabled']) {
         $conversation->setConversationAttachmentsEnabled(intval($values['attachmentsEnabled']));
     }
     if (!$values['itemsPerPage']) {
         $values['itemsPerPage'] = 0;
     }
     if ($values['maxFilesGuest']) {
         $conversation->setConversationMaxFilesGuest(intval($values['maxFilesGuest']));
     }
     if ($values['maxFilesRegistered']) {
         $conversation->setConversationMaxFilesRegistered(intval($values['maxFilesRegistered']));
     }
     if ($values['maxFileSizeGuest']) {
         $conversation->setConversationMaxFileSizeGuest(intval($values['maxFileSizeGuest']));
     }
     if ($values['maxFileSizeRegistered']) {
         $conversation->setConversationMaxFilesRegistered(intval($values['maxFileSizeRegistered']));
     }
     if (!$values['enableOrdering']) {
         $values['enableOrdering'] = 0;
     }
     if (!$values['enableCommentRating']) {
         $values['enableCommentRating'] = 0;
     }
     if ($values['notificationOverridesEnabled']) {
         $conversation->setConversationNotificationOverridesEnabled(true);
         $users = array();
         if (is_array($this->post('notificationUsers'))) {
             foreach ($this->post('notificationUsers') as $uID) {
                 $ui = \UserInfo::getByID($uID);
                 if (is_object($ui)) {
                     $users[] = $ui;
                 }
             }
         }
         $conversation->setConversationSubscribedUsers($users);
         $conversation->setConversationSubscriptionEnabled(intval($values['subscriptionEnabled']));
     } else {
         $conversation->setConversationNotificationOverridesEnabled(false);
         $conversation->setConversationSubscriptionEnabled(0);
     }
     if ($values['fileExtensions']) {
         $receivedExtensions = preg_split('{,}', strtolower($values['fileExtensions']), null, PREG_SPLIT_NO_EMPTY);
         $fileExtensions = $helperFile->serializeUploadFileExtensions($receivedExtensions);
         $conversation->setConversationFileExtensions($fileExtensions);
     }
     $values['cnvID'] = $conversation->getConversationID();
     parent::save($values);
 }
Exemplo n.º 4
0
 public function filterByConversation(Conversation $cnv)
 {
     $this->filter('cnvID', $cnv->getConversationID());
 }
 public function getConversationObject()
 {
     return Conversation::getByID($this->cnvID);
 }
Exemplo n.º 6
0
 public function save()
 {
     $helper_file = Loader::helper('concrete/file');
     Config::save('conversations.files.guest.max_size', intval($this->post('maxFileSizeGuest')));
     Config::save('conversations.files.registered.max_size', intval($this->post('maxFileSizeRegistered')));
     Config::save('conversations.files.guest.max', intval($this->post('maxFilesGuest')));
     Config::save('conversations.files.registered.max', intval($this->post('maxFilesRegistered')));
     Config::save('conversations.attachments_enabled', !!$this->post('attachmentsEnabled'));
     Config::save('conversations.subscription_enabled', !!$this->post('subscriptionEnabled'));
     $users = array();
     if (is_array($this->post('defaultUsers'))) {
         foreach ($this->post('defaultUsers') as $uID) {
             $ui = \UserInfo::getByID($uID);
             if (is_object($ui)) {
                 $users[] = $ui;
             }
         }
     }
     Conversation::setDefaultSubscribedUsers($users);
     if ($this->post('fileExtensions')) {
         $types = preg_split('{,}', $this->post('fileExtensions'), null, PREG_SPLIT_NO_EMPTY);
         $types = $helper_file->serializeUploadFileExtensions($types);
         Config::save('conversations.files.allowed_types', $types);
     }
     $this->saveEditors();
     $this->success();
 }
Exemplo n.º 7
0
 public function getConversationSubscribedUsers()
 {
     if ($this->getConversationNotificationOverridesEnabled() > 0) {
         $db = Loader::db();
         $r = $db->GetCol('select uID from ConversationSubscriptions where cnvID = ? order by uID asc', array($this->getConversationID()));
         $users = array();
         foreach ($r as $uID) {
             $ui = \UserInfo::getByID($uID);
             if (is_object($ui)) {
                 $users[] = $ui;
             }
         }
     } else {
         $users = \Conversation::getDefaultSubscribedUsers();
     }
     return $users;
 }
Exemplo n.º 8
0
<?php

defined('C5_EXECUTE') or die("Access Denied.");
use Concrete\Core\Conversation\Conversation;
$val = Loader::helper('validation/token');
$helperFile = Loader::helper('concrete/file');
$file = new stdClass();
// json return value holder
$error = array();
$pageObj = Page::getByID($_POST['cID']);
$areaObj = Area::get($pageObj, $_POST['blockAreaHandle']);
$blockObj = Block::getByID($_POST['bID'], $pageObj, $areaObj);
$conversation = Conversation::getByID($blockObj->getController()->cnvID);
if (!is_object($conversation)) {
    $error[] = t('Invalid Conversation.');
    $file->error = $error;
    echo Loader::helper('json')->encode($file);
    exit;
}
if ($conversation->getConversationAttachmentOverridesEnabled() > 0) {
    // check individual conversation for allowing attachments.
    if ($conversation->getConversationAttachmentsEnabled != 1) {
        $error[] = t('This conversation does not allow file attachments.');
        $file->error = $error;
        echo Loader::helper('json')->encode($file);
        exit;
    }
} else {
    if (!!Config::get('concrete.conversations.attachments_enabled')) {
        // check global config settings for whether or not file attachments should be allowed.
        $error[] = t('This conversation does not allow file attachments.');
Exemplo n.º 9
0
 public function save()
 {
     $config = Core::make('config');
     if (Core::make('token')->validate('conversations.settings.save')) {
         $helper_file = Core::make('helper/concrete/file');
         $config->save('conversations.files.guest.max_size', intval($this->post('maxFileSizeGuest')));
         $config->save('conversations.files.registered.max_size', intval($this->post('maxFileSizeRegistered')));
         $config->save('conversations.files.guest.max', intval($this->post('maxFilesGuest')));
         $config->save('conversations.files.registered.max', intval($this->post('maxFilesRegistered')));
         $config->save('conversations.attachments_enabled', (bool) $this->post('attachmentsEnabled'));
         $config->save('conversations.subscription_enabled', (bool) $this->post('subscriptionEnabled'));
         $users = array();
         if (is_array($this->post('defaultUsers'))) {
             foreach ($this->post('defaultUsers') as $uID) {
                 $ui = \UserInfo::getByID($uID);
                 if (is_object($ui)) {
                     $users[] = $ui;
                 }
             }
         }
         Conversation::setDefaultSubscribedUsers($users);
         if ($this->post('fileExtensions')) {
             $types = preg_split('{,}', $this->post('fileExtensions'), null, PREG_SPLIT_NO_EMPTY);
             $types = $helper_file->serializeUploadFileExtensions($types);
             $config->save('conversations.files.allowed_types', $types);
         }
         $this->saveEditors();
         $this->success();
     } else {
         $this->error->add('Invalid Token.');
         $this->view();
     }
 }
Exemplo n.º 10
0
 public function getLandingPageConversations($cID)
 {
     $db = Database::connection();
     $res = $db->GetRow("select cnvID from Conversations where cID = ?", $cID);
     if ($res) {
         $cnv = Conversation::getByID($res['cnvID']);
         $ml = new MessageList();
         $ml->filterByConversation($cnv);
         $ml->filterByNotDeleted();
         $ml->filterByApproved();
         $ml->sortByDateDescending();
         $messages = $ml->get();
     }
     return $messages;
 }
Exemplo n.º 11
0
 public function setPropertiesFromArray($arr)
 {
     return parent::setPropertiesFromArray($arr);
 }
Exemplo n.º 12
0
 public function save($post)
 {
     $helperFile = Loader::helper('concrete/file');
     $db = Loader::db();
     $cnvID = $db->GetOne('select cnvID from btCoreConversation where bID = ?', array($this->bID));
     if (!$cnvID) {
         $conversation = Conversation::add();
         $b = $this->getBlockObject();
         $xc = $b->getBlockCollectionObject();
         $conversation->setConversationPageObject($xc);
     } else {
         $conversation = Conversation::getByID($cnvID);
     }
     $values = $post;
     if ($values['attachmentOverridesEnabled']) {
         $conversation->setConversationAttachmentOverridesEnabled(intval($values['attachmentOverridesEnabled']));
     } else {
         $conversation->setConversationAttachmentOverridesEnabled(0);
     }
     if ($values['attachmentsEnabled']) {
         $conversation->setConversationAttachmentsEnabled(intval($values['attachmentsEnabled']));
     }
     if (!$values['itemsPerPage']) {
         $values['itemsPerPage'] = 0;
     }
     if ($values['maxFilesGuest']) {
         $conversation->setConversationMaxFilesGuest(intval($values['maxFilesGuest']));
     }
     if ($values['maxFilesRegistered']) {
         $conversation->setConversationMaxFilesRegistered(intval($values['maxFilesRegistered']));
     }
     if ($values['maxFileSizeGuest']) {
         $conversation->setConversationMaxFileSizeGuest(intval($values['maxFileSizeGuest']));
     }
     if ($values['maxFileSizeRegistered']) {
         $conversation->setConversationMaxFilesRegistered(intval($values['maxFileSizeRegistered']));
     }
     if (!$values['enableOrdering']) {
         $values['enableOrdering'] = 0;
     }
     if (!$values['attachmentsEnabled']) {
         $conversation->setConversationAttachmentsEnabled(intval($values['attachmentsEnabled']));
     }
     if (!$values['enableCommentRating']) {
         $values['enableCommentRating'] = 0;
     }
     if ($values['fileExtensions']) {
         $receivedExtensions = preg_split('{,}', strtolower($values['fileExtensions']), null, PREG_SPLIT_NO_EMPTY);
         $conversation->setConversationFileExtensions($helperFile->serializeUploadFileExtensions($receivedExtensions));
     }
     $values['cnvID'] = $conversation->getConversationID();
     parent::save($values);
 }