/** * 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)); }
/** * @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 $properties */ public function __construct($properties = null) { parent::__construct($properties); $this->_extracted = new JRegistry(); $this->_init(); }
/** * * @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)); }
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; }
/** * Parse body to get data * @return JRegistry */ public function parse() { $contentType = $this->getInfo('content_type'); if ($contentType) { if (strpos($contentType, ';') !== false) { $contentType = explode(';', $contentType); $contentType = trim($contentType[0]); } switch ($contentType) { case 'text/html': $parser = CParsers::getParser('metas', array('content' => $this->getBody(), 'url' => $this->getInfo('url'))); /* extract meta data from body */ $data = $parser->extract(); /** * Images process * @todo need to improve */ $images = $data->get('image'); $counter = 0; $limit = $this->get('max_images', 5); if (is_array($images)) { $_images = array(); foreach ($images as $key => $imageUrl) { //$imageUrl = strtolower($imageUrl); /* This imageurl already have valid path */ if (strpos(strtolower($imageUrl), 'http://') !== false || strpos(strtolower($imageUrl), 'https://') !== false) { } else { /* Image have no URL than we need add it */ $host = parse_url($this->getInfo('url'), PHP_URL_HOST); $url = JUri::getInstance($this->getInfo('url')); if (substr($imageUrl, 0, 2) == '//') { $imageUrl = $url->getScheme() . ':' . $imageUrl; } else { $url = JUri::getInstance($this->getInfo('url')); $url = $url->getScheme() . '://' . $host; $imageUrl = strtolower($url . $imageUrl); } } $imgArr = explode('.', $imageUrl); if (count($imgArr) == 1 || !in_array($imgArr[count($imgArr) - 1], array('jpg', 'png', 'jpeg', 'gif'))) { continue; } /** * Read image and make sure image size is valid */ $imageContent = @file_get_contents($imageUrl); if ($imageContent) { $im = imagecreatefromstring($imageContent); $width = imagesx($im); $height = imagesy($im); if ($width >= $this->get('max_image_width', 128) && $height >= $this->get('max_image_height', 128) && $counter <= $limit) { $_images[] = $imageUrl; $counter++; } } } } $data->set('image', $_images); return $data; } } }
/** * Parse body to get data * @return JRegistry */ public function parse() { $contentType = $this->getInfo('content_type'); if ($contentType) { if (strpos($contentType, ';') !== false) { $contentType = explode(';', $contentType); $contentType = trim($contentType[0]); } switch ($contentType) { case 'text/html': $parser = CParsers::getParser('metas', array('content' => $this->getBody(), 'url' => $this->getInfo('url'))); /* extract meta data from body */ $data = $parser->extract(); /** * Images process * @todo need to improve */ $images = $data->get('image'); $limit = $this->get('max_images', 4); if (is_array($images)) { $_images = array(); foreach ($images as $key => $imageUrl) { // Stop if max_images reached. if ($limit > 0 && count($_images) >= $limit) { break; } //$imageUrl = strtolower($imageUrl); /* This imageurl already have valid path */ if (strpos(strtolower($imageUrl), 'http://') !== false || strpos(strtolower($imageUrl), 'https://') !== false) { } else { /* Image have no URL than we need add it */ $host = parse_url($this->getInfo('url'), PHP_URL_HOST); $url = JUri::getInstance($this->getInfo('url')); if (substr($imageUrl, 0, 2) == '//') { $imageUrl = $url->getScheme() . ':' . $imageUrl; } else { $url = JUri::getInstance($this->getInfo('url')); $url = $url->getScheme() . '://' . $host; $imageUrl = strtolower($url . $imageUrl); } } // Exclude base64 image data. if (strpos($imageUrl, ';base64,')) { continue; } // Read image and make sure image size is valid try { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_URL, $imageUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_TIMEOUT, 20); $imageContent = curl_exec($ch); curl_close($ch); if ($imageContent) { $im = @imagecreatefromstring($imageContent); $width = @imagesx($im); $height = @imagesy($im); if ($width >= $this->get('max_image_width', 128) && $height >= $this->get('max_image_height', 128)) { $_images[] = $imageUrl; } } } catch (Exception $e) { // do nothing } } } $data->set('image', $_images); return $data; } } }