/** * @param $uniqueId * @param $message * @param $appType * @param $creator * @param $isOwner * @param string $processFunc * @param string $templateFile * @param int $wallId * @param int $photoId to attach photoid in the wall if exists * @return stdClass */ public static function saveWall($uniqueId, $message, $appType, &$creator, $isOwner, $processFunc = '', $templateFile = 'wall/content', $wallId = 0, $photoId = 0) { $my = CFactory::getUser(); // Add some required parameters, otherwise assert here CError::assert($uniqueId, '', '!empty', __FILE__, __LINE__); CError::assert($appType, '', '!empty', __FILE__, __LINE__); CError::assert($my->id, '', '!empty', __FILE__, __LINE__); // Load the models $wall = JTable::getInstance('Wall', 'CTable'); $wall->load($wallId); if ($wallId == 0) { // Get current date $now = JFactory::getDate(); $now = $now->toSql(); // Set the wall properties $wall->type = $appType; $wall->contentid = $uniqueId; $wall->post_by = $creator->id; $wall->date = $now; $wall->published = 1; // @todo: set the ip address $wall->ip = $_SERVER['REMOTE_ADDR']; } //if photo id is not 0, this wall is appended with a picture if ($photoId > 0) { //lets check if the photo belongs to the uploader $photo = JTable::getInstance('Photo', 'CTable'); $photo->load($photoId); //save the data into the wall table $wallParam = new CParameter($wall->params); if ($photo->creator == $my->id && $photo->albumid == '-1') { $wallParam->set('attached_photo_id', $photoId); //sets the status to ready so that it wont be deleted on cron run $photo->status = 'ready'; $photo->store(); } $wall->params = $wallParam->toString(); } elseif ($photoId == -1) { //if there is nothing, remove the param if applicable $wallParam = new CParameter($wall->params); //delete from db and files $photoModel = CFactory::getModel('photos'); if ($wallParam->get('attached_photo_id') > 0) { $photoTable = $photoModel->getPhoto($wallParam->get('attached_photo_id')); $photoTable->delete(); } $wallParam->set('attached_photo_id', 0); $wall->params = $wallParam->toString(); } /* URL fetch */ $graphObject = CParsers::linkFetch($message); if ($graphObject) { $graphObject->merge(new CParameter($wall->params)); $wall->params = $graphObject->toString(); } $wall->comment = $message; // Store the wall message $wall->store(); // Convert it to array so that the walls can be processed by plugins $args = array(); $args[0] = $wall; //Process wall comments $comment = new CComment(); $wallComments = $wall->comment; $wall->comment = $comment->stripCommentData($wall->comment); // Trigger the wall comments CWall::triggerWallComments($args); $wallData = new stdClass(); $wallData->id = $wall->id; $wallData->content = CWallLibrary::_getWallHTML($wall, $wallComments, $appType, $isOwner, $processFunc, $templateFile); $wallData->content = CStringHelper::replaceThumbnails($wallData->content); CTags::add($wall); return $wallData; }
/** * * @param type $text * @return type */ public function ajaxGetFetchUrl($text) { $graphObject = CParsers::linkFetch($text); if ($graphObject) { $data = (array) $graphObject->toObject(); die(json_encode($data)); } die(json_encode($graphObject)); }
/** * Add reply via ajax * @todo: check permission and message ownership */ public function ajaxAddReply($msgId, $reply, $photoId = 0) { $filter = JFilterInput::getInstance(); $msgId = $filter->clean($msgId, 'int'); //$reply = $filter->clean($reply, 'string'); $photoId = $filter->clean($photoId, 'int'); $my = CFactory::getUser(); $model = $this->getModel('inbox'); $message = $model->getMessage($msgId); $messageRecipient = $model->getParticipantsID($msgId, $my->id); if ($my->id == 0) { return $this->ajaxBlockUnregister(); } // Block users $getBlockStatus = new blockUser(); $userModel = CFactory::getModel('User'); $bannedList = $userModel->getBannedUser(); $newRecipient = array(); foreach ($messageRecipient as $recipient) { if ($getBlockStatus->isUserBlocked($recipient, 'inbox')) { continue; } $newRecipient[] = $recipient; } $messageRecipient = $newRecipient; // @rule: Spam checks if ($this->_isSpam($my, $reply)) { $json = array('error' => JText::_('COM_COMMUNITY_INBOX_MESSAGE_MARKED_SPAM')); die(json_encode($json)); } if (empty($reply) && $photoId == 0) { $json = array('error' => JText::_('COM_COMMUNITY_INBOX_MESSAGE_CANNOT_BE_EMPTY')); die(json_encode($json)); } if (empty($messageRecipient)) { $json = array('error' => JText::_('COM_COMMUNITY_INBOX_MESSAGE_CANNOT_FIND_RECIPIENT')); die(json_encode($json)); } // make sure we can only reply to message that belogn to current user if (!$model->canReply($my->id, $msgId)) { $json = array('error' => JText::_('COM_COMMUNITY_PERMISSION_DENIED_WARNING')); die(json_encode($json)); } if (in_array($messageRecipient[0], $bannedList)) { $json = array('error' => JText::_('COM_COMMUNITY_USER_BANNED')); die(json_encode($json)); } $date = JFactory::getDate(); //get the time without any offset! $obj = new stdClass(); $obj->id = null; $obj->from = $my->id; $obj->posted_on = $date->toSql(); $obj->from_name = $my->name; $obj->subject = 'RE:' . $message->subject; $obj->body = $reply; $body = new JRegistry(); $body->set('content', $obj->body); // photo attachment if ($photoId > 0) { //lets check if the photo belongs to the uploader $photo = JTable::getInstance('Photo', 'CTable'); $photo->load($photoId); if ($photo->creator == $my->id && $photo->albumid == '-1') { $body->set('attached_photo_id', $photoId); //sets the status to ready so that it wont be deleted on cron run $photo->status = 'ready'; $photo->store(); } } /** * @since 3.2.1 * Message URL fetching */ if (preg_match("/\\b(?:(?:https?|ftp):\\/\\/|www\\.)[-a-z0-9+&@#\\/%?=~_|!:,.;]*[-a-z0-9+&@#\\/%=~_|]/i", $obj->body)) { $graphObject = CParsers::linkFetch($obj->body); if ($graphObject) { $graphObject->merge($body); $obj->body = $graphObject->toString(); } } else { $obj->body = $body->toString(); } $model->sendReply($obj, $msgId); $deleteLink = CRoute::_('index.php?option=com_community&view=inbox&task=remove&msgid=' . $obj->id); $authorLink = CRoute::_('index.php?option=com_community&view=profile&userid=' . $my->id); //add user points CUserPoints::assignPoint('inbox.message.reply'); // Add notification foreach ($messageRecipient as $row) { $params = new CParameter(''); $params->set('message', $reply); $params->set('title', $obj->subject); $params->set('url', 'index.php?option=com_community&view=inbox&task=read&msgid=' . $msgId); $params->set('msg_url', 'index.php?option=com_community&view=inbox&task=read&msgid=' . $msgId); $params->set('msg', JText::_('COM_COMMUNITY_PRIVATE_MESSAGE')); $params->set('msg', JText::_('COM_COMMUNITY_PRIVATE_MESSAGE')); CNotificationLibrary::add('inbox_create_message', $my->id, $row, JText::_('COM_COMMUNITY_SENT_YOU_MESSAGE'), '', 'inbox.sent', $params); } // onMessageDisplay Event trigger $appsLib = CAppPlugins::getInstance(); $appsLib->loadApplications(); $args = array(); $args[] = $obj; $appsLib->triggerEvent('onMessageDisplay', $args); $params = new JRegistry($obj->body); // Escape content $content = $originalContent = $params->get('content'); $content = CTemplate::escape($content); $content = CStringHelper::autoLink($content); $content = nl2br($content); $content = CStringHelper::getEmoticon($content); $content = CStringHelper::converttagtolink($content); //get thumbnail if available $photoThumbnail = ''; if ($params->get('attached_photo_id')) { $photo = JTable::getInstance('Photo', 'CTable'); $photo->load($params->get('attached_photo_id')); $photoThumbnail = $photo->getThumbURI(); } $tmpl = new CTemplate(); $tmpl->set('user', CFactory::getUser($obj->from)); $tmpl->set('msg', $obj); $tmpl->set('originalContent', $originalContent); $tmpl->set('content', $content); $tmpl->set('params', $params); $tmpl->set('removeLink', $deleteLink); $tmpl->set('authorLink', $authorLink); $tmpl->set('photoThumbnail', $photoThumbnail); $html = $tmpl->fetch('inbox.message'); $json = array('success' => true, 'html' => $html); die(json_encode($json)); }
public function send($vars) { $db = $this->getDBO(); $my = CFactory::getUser(); // @todo: user db table later on //$cDate = JFactory::getDate(gmdate('Y-m-d H:i:s'), $mainframe->getCfg('offset'));//get the current date from system. //$date = cGetDate(); $date = JFactory::getDate(); //get the time without any offset! $cDate = $date->toSql(); $obj = new stdClass(); $obj->id = null; $obj->from = $my->id; $obj->posted_on = $date->toSql(); $obj->from_name = $my->name; $obj->subject = $vars['subject']; $obj->body = $vars['body']; $body = new JRegistry(); $body->set('content', CUserHelper::replaceAliasURL($obj->body)); // photo attachment if (isset($vars['photo'])) { $photoId = $vars['photo']; if ($photoId > 0) { //lets check if the photo belongs to the uploader $photo = JTable::getInstance('Photo', 'CTable'); $photo->load($photoId); if ($photo->creator == $my->id && $photo->albumid == '-1') { $body->set('attached_photo_id', $photoId); //sets the status to ready so that it wont be deleted on cron run $photo->status = 'ready'; $photo->store(); } } } /** * @since 3.2.1 * Message URL fetching */ if (preg_match("/\\b(?:(?:https?|ftp):\\/\\/|www\\.)[-a-z0-9+&@#\\/%?=~_|!:,.;]*[-a-z0-9+&@#\\/%=~_|]/i", $obj->body)) { $graphObject = CParsers::linkFetch($obj->body); if ($graphObject) { $graphObject->merge($body); $obj->body = $graphObject->toString(); } } else { $obj->body = $body->toString(); } // Don't add message if user is sending message to themselve if ($vars['to'] != $my->id) { $db->insertObject('#__community_msg', $obj, 'id'); // Update the parent $obj->parent = $obj->id; $db->updateObject('#__community_msg', $obj, 'id'); } if (is_array($vars['to'])) { //multiple recepint foreach ($vars['to'] as $sToId) { if ($vars['to'] != $my->id) { $this->addReceipient($obj, $sToId); } } } else { //single recepient if ($vars['to'] != $my->id) { $this->addReceipient($obj, $vars['to']); } } return $obj->id; }