示例#1
0
文件: inbox.php 项目: Jougito/DynWeb
 /**
  * A new message submitted via ajax
  */
 public function ajaxSend($postVars)
 {
     //$postVars pending filtering
     $objResponse = new JAXResponse();
     $config = CFactory::getConfig();
     $my = CFactory::getUser();
     if ($my->id == 0) {
         return $this->ajaxBlockUnregister();
     }
     //CFactory::load( 'helpers', 'time' );
     $inboxModel = $this->getModel('inbox');
     $lastSent = $inboxModel->getLastSentTime($my->id);
     $dateNow = new JDate();
     // We need to make sure that this guy are not spamming other people inbox
     // by checking against his last message time. Make sure it doesn't exceed
     // pmFloodLimit config (in seconds).
     if ($dateNow->toUnix() - $lastSent->toUnix() < $config->get('floodLimit') && !COwnerHelper::isCommunityAdmin()) {
         $json = array();
         $json['title'] = JText::_('COM_COMMUNITY_NOTICE');
         $json['error'] = JText::sprintf('COM_COMMUNITY_PLEASE_WAIT_BEFORE_SENDING_MESSAGE', $config->get('floodLimit'));
         die(json_encode($json));
     }
     // Prevent users to send message to themselves.
     if ($postVars['to'] == $my->id) {
         $json = array();
         $json['title'] = JText::_('COM_COMMUNITY_NOTICE');
         $json['error'] = JText::_('COM_COMMUNITY_INBOX_MESSAGE_CANNOT_SEND_TO_SELF');
         die(json_encode($json));
     }
     $postVars = CAjaxHelper::toArray($postVars);
     $doCont = true;
     $errMsg = "";
     $resizeH = 0;
     if ($this->_isSpam($my, $postVars['subject'] . ' ' . $postVars['body'])) {
         $json = array();
         $json['title'] = JText::_('COM_COMMUNITY_NOTICE');
         $json['error'] = JText::_('COM_COMMUNITY_INBOX_MESSAGE_MARKED_SPAM');
         die(json_encode($json));
     }
     if (empty($postVars['subject']) || JString::trim($postVars['subject']) == '') {
         $json = array();
         $json['title'] = JText::_('COM_COMMUNITY_INBOX_TITLE_WRITE');
         $json['error'] = JText::_('COM_COMMUNITY_INBOX_SUBJECT_MISSING');
         $json['samestep'] = true;
         die(json_encode($json));
     }
     if (empty($postVars['body']) || JString::trim($postVars['body']) == '') {
         $json = array();
         $json['title'] = JText::_('COM_COMMUNITY_INBOX_TITLE_WRITE');
         $json['error'] = JText::_('COM_COMMUNITY_INBOX_MESSAGE_MISSING');
         $json['samestep'] = true;
         die(json_encode($json));
     }
     $data = $postVars;
     $model = $this->getModel('inbox');
     $pattern = "/<br \\/>/i";
     $replacement = "\r\n";
     $data['body'] = preg_replace($pattern, $replacement, $data['body']);
     $data['photo'] = isset($data['photo']) ? $data['photo'] : '';
     $msgid = $model->send($data);
     // Add user points.
     CUserPoints::assignPoint('inbox.message.send');
     // Add notification.
     $params = new CParameter('');
     $params->set('url', 'index.php?option=com_community&view=inbox&task=read&msgid=' . $msgid);
     $params->set('message', $data['body']);
     $params->set('title', $data['subject']);
     $params->set('msg_url', 'index.php?option=com_community&view=inbox&task=read&msgid=' . $msgid);
     $params->set('msg', JText::_('COM_COMMUNITY_PRIVATE_MESSAGE'));
     CNotificationLibrary::add('inbox_create_message', $my->id, $data['to'], JText::sprintf('COM_COMMUNITY_SENT_YOU_MESSAGE'), '', 'inbox.sent', $params);
     // Send response.
     $json = array();
     $json['message'] = JText::_('COM_COMMUNITY_INBOX_MESSAGE_SENT');
     die(json_encode($json));
 }
示例#2
0
 public function ajaxSaveFriend($postVars)
 {
     $objResponse = new JAXResponse();
     $filter = JFilterInput::getInstance();
     $postVars = $filter->clean($postVars, 'array');
     //@todo filter paramater
     $model =& $this->getModel('friends');
     $my = CFactory::getUser();
     if ($my->id == 0) {
         return $this->ajaxBlockUnregister();
     }
     $postVars = CAjaxHelper::toArray($postVars);
     $id = $postVars['userid'];
     //get it from post
     $msg = strip_tags($postVars['msg']);
     $data = CFactory::getUser($id);
     // @rule: Do not allow users to request more friend requests as they are allowed to.
     CFactory::load('libraries', 'limits');
     if (CLimitsLibrary::exceedDaily('friends')) {
         $actions = '<form method="post" action="" style="float:right;">';
         $actions .= '<input type="button" class="button" onclick="cWindowHide();return false;" name="cancel" value="' . JText::_('COM_COMMUNITY_BUTTON_CLOSE_BUTTON') . '" />';
         $actions .= '</form>';
         $html = JText::_('COM_COMMUNITY_LIMIT_FRIEND_REQUEST_REACHED');
         $objResponse->addScriptCall('cWindowAddContent', $html, $actions);
         return $objResponse->sendResponse();
     }
     if (count($postVars) > 0) {
         $model->addFriend($id, $my->id, $msg);
         $html = JText::sprintf('COM_COMMUNITY_FRIENDS_WILL_RECEIVE_REQUEST', $data->getDisplayName());
         $actions = '<button class="button" onclick="cWindowHide();" name="close">' . JText::_('COM_COMMUNITY_BUTTON_CLOSE_BUTTON') . '</button>';
         $objResponse->addScriptCall('cWindowAddContent', $html, $actions);
         // Add notification
         CFactory::load('libraries', 'notification');
         $params = new CParameter('');
         $params->set('url', 'index.php?option=com_community&view=friends&task=pending');
         $params->set('msg', $msg);
         CNotificationLibrary::add('etype_friends_request_connection', $my->id, $id, JText::sprintf('COM_COMMUNITY_FRIEND_ADD_REQUEST', $my->getDisplayName()), '', 'friends.request', $params);
         //add user points - friends.request.add removed @ 20090313
         //trigger for onFriendRequest
         $eventObject = new stdClass();
         $eventObject->profileOwnerId = $my->id;
         $eventObject->friendId = $id;
         $this->triggerFriendEvents('onFriendRequest', $eventObject);
         unset($eventObject);
     }
     return $objResponse->sendResponse();
 }
示例#3
0
文件: inbox.php 项目: bizanto/Hooked
 /**
  * A new message submitted via ajax
  */
 function ajaxSend($postVars)
 {
     $objResponse = new JAXResponse();
     //
     $config = CFactory::getConfig();
     $my = CFactory::getUser();
     if ($my->id == 0) {
         return $this->ajaxBlockUnregister();
     }
     CFactory::load('helpers', 'time');
     $inboxModel =& $this->getModel('inbox');
     $lastSent = $inboxModel->getLastSentTime($my->id);
     $dateNow = new JDate();
     CFactory::load('helpers', 'owner');
     // We need to make sure that this guy are not spamming other people inbox
     // by checking against his last message time. Make sure it doesn't exceed
     // pmFloodLimit config (in seconds)
     if ($dateNow->toUnix() - $lastSent->toUnix() < $config->get('floodLimit') && !COwnerHelper::isCommunityAdmin()) {
         $html = '<dl id="system-message"><dt class="notice">Notice</dt><dd class="notice message"><ul><li>';
         $html .= JText::sprintf('CC PLEASE WAIT BEFORE SENDING MESSAGE', $config->get('floodLimit'));
         $html .= '</li></ul></dd></dl>';
         $objResponse->addAssign('cWindowContent', 'innerHTML', $html);
         $objResponse->addScriptCall('cWindowResize', 80);
         $action = '<button class="button" onclick="cWindowHide();" name="cancel">' . JText::_('CC BUTTON CLOSE') . '</button>';
         $objResponse->addScriptCall('cWindowActions', $action);
         return $objResponse->sendResponse();
     }
     // Prevent user to send message to themselve
     if ($postVars['to'] == $my->id) {
         $html = '<dl id="system-message"><dt class="notice">Notice</dt><dd class="notice message"><ul><li>';
         $html .= JText::_('CC MESSAGE CANNOT SEND TO SELF');
         $html .= '</li></ul></dd></dl>';
         $objResponse->addAssign('cWindowContent', 'innerHTML', $html);
         $objResponse->addScriptCall('cWindowResize', 80);
         $action = '<button class="button" onclick="cWindowHide();" name="cancel">' . JText::_('CC BUTTON CLOSE') . '</button>';
         $objResponse->addScriptCall('cWindowActions', $action);
         return $objResponse->sendResponse();
     }
     $postVars = CAjaxHelper::toArray($postVars);
     $doCont = true;
     $errMsg = "";
     $resizeH = 0;
     if (empty($postVars['subject']) || JString::trim($postVars['subject']) == '') {
         $errMsg = '<div class="message">' . JText::_('CC SUBJECT MISSING') . '</div>';
         $doCont = false;
         $resizeH += 35;
     }
     if (empty($postVars['body']) || JString::trim($postVars['body']) == '') {
         $errMsg .= '<div class="message">' . JText::_('CC MESSAGE MISSING') . '</div>';
         $doCont = false;
         $resizeH += 35;
     }
     if ($doCont) {
         $data = $postVars;
         $model =& $this->getModel('inbox');
         $pattern = "/<br \\/>/i";
         $replacement = "\r\n";
         $data['body'] = preg_replace($pattern, $replacement, $data['body']);
         $msgid = $model->send($data);
         //add user points
         CFactory::load('libraries', 'userpoints');
         CFactory::load('libraries', 'notification');
         CUserPoints::assignPoint('inbox.message.send');
         // Add notification
         $params = new JParameter('');
         $params->set('url', 'index.php?option=com_community&view=inbox&task=read&msgid=' . $msgid);
         $params->set('message', $data['body']);
         $params->set('title', $data['subject']);
         CNotificationLibrary::add('inbox.create.message', $my->id, $data['to'], JText::sprintf('CC SENT YOU MESSAGE', $my->getDisplayName()), '', 'inbox.sent', $params);
         $objResponse->addAssign('cWindowContent', 'innerHTML', JText::_('CC MESSAGE SENT'));
         $objResponse->addScriptCall('cWindowResize', 80);
         $action = '<button class="button" onclick="cWindowHide();" name="close">' . JText::_('CC BUTTON CLOSE') . '</button>';
         $objResponse->addScriptCall('cWindowActions', $action);
     } else {
         //validation failed. display error message.
         $user = CFactory::getUser($postVars['to']);
         $tmpl = new CTemplate();
         $tmpl->set('user', $user);
         $tmpl->set('subject', JString::trim($postVars['subject']));
         $tmpl->set('body', JString::trim($postVars['body']));
         $html = $tmpl->fetch('inbox.ajaxcompose');
         $action = '<button class="button" onclick="javascript:return joms.messaging.send();" name="send">' . JText::_('CC BUTTON SEND') . '</button>&nbsp;';
         $action .= '<button class="button" onclick="javascript:cWindowHide();" name="cancel">' . JText::_('CC BUTTON CANCEL') . '</button>';
         $objResponse->addAssign('cWindowContent', 'innerHTML', $errMsg . $html);
         $objResponse->addScriptCall('cWindowResize', 220 + $resizeH);
         // Change cWindow title
         $objResponse->addAssign('cwin_logo', 'innerHTML', JText::_('CC TITLE COMPOSE'));
         $objResponse->addScriptCall('cWindowActions', $action);
     }
     return $objResponse->sendResponse();
 }
示例#4
0
 public function ajaxSaveFriend($postVars)
 {
     $objResponse = new JAXResponse();
     //@todo filter paramater
     $model =& $this->getModel('friends');
     $my = CFactory::getUser();
     if ($my->id == 0) {
         return $this->ajaxBlockUnregister();
     }
     $postVars = CAjaxHelper::toArray($postVars);
     $id = $postVars['userid'];
     //get it from post
     $msg = strip_tags($postVars['msg']);
     $data = CFactory::getUser($id);
     if (count($postVars) > 0) {
         $model->addFriend($id, $my->id, $msg);
         $html = JText::sprintf('CC FRIEND WILL RECEIVE REQUEST', $data->getDisplayName());
         $objResponse->addAssign('cWindowContent', 'innerHTML', $html);
         $objResponse->addScriptCall('cWindowResize', 110);
         $action = '<button class="button" onclick="cWindowHide();" name="close">' . JText::_('CC BUTTON CLOSE') . '</button>';
         $objResponse->addScriptCall('cWindowActions', $action);
         // Add notification
         CFactory::load('libraries', 'notification');
         $params = new JParameter('');
         $params->set('url', 'index.php?option=com_community&view=friends&task=pending');
         $params->set('msg', $msg);
         CNotificationLibrary::add('friends.create.connection', $my->id, $id, JText::sprintf('CC FRIEND ADD REQUEST', $my->getDisplayName()), '', 'friends.request', $params);
         //add user points - friends.request.add removed @ 20090313
         //trigger for onFriendRequest
         $eventObject = new stdClass();
         $eventObject->profileOwnerId = $my->id;
         $eventObject->friendId = $id;
         $this->triggerFriendEvents('onFriendRequest', $eventObject);
         unset($eventObject);
     }
     return $objResponse->sendResponse();
 }
示例#5
0
 public function ajaxSaveFriend($postVars)
 {
     $filter = JFilterInput::getInstance();
     $postVars = $filter->clean($postVars, 'array');
     //@todo filter paramater
     $model = $this->getModel('friends');
     $my = CFactory::getUser();
     if ($my->id == 0) {
         return $this->ajaxBlockUnregister();
     }
     $postVars = CAjaxHelper::toArray($postVars);
     $id = $postVars['userid'];
     //get it from post
     $msg = strip_tags($postVars['msg']);
     $data = CFactory::getUser($id);
     $connection = $model->getFriendConnection($my->id, $id);
     if (!empty($connection)) {
         die;
     }
     // @rule: Do not allow users to request more friend requests as they are allowed to.
     if (CLimitsLibrary::exceedDaily('friends')) {
         $json = array('error' => JText::_('COM_COMMUNITY_LIMIT_FRIEND_REQUEST_REACHED'));
         die(json_encode($json));
     }
     if (count($postVars) > 0) {
         $model->addFriend($id, $my->id, $msg);
         $json = array('message' => JText::sprintf('COM_COMMUNITY_FRIENDS_WILL_RECEIVE_REQUEST', $data->getDisplayName()));
         // Add notification
         $params = new CParameter('');
         $params->set('url', 'index.php?option=com_community&view=friends&task=pending');
         $params->set('msg', $msg);
         CNotificationLibrary::add('friends_request_connection', $my->id, $id, JText::_('COM_COMMUNITY_FRIEND_ADD_REQUEST'), '', 'friends.request', $params);
         //add user points - friends.request.add removed @ 20090313
         //trigger for onFriendRequest
         $eventObject = new stdClass();
         $eventObject->profileOwnerId = $my->id;
         $eventObject->friendId = $id;
         $this->triggerFriendEvents('onFriendRequest', $eventObject);
         unset($eventObject);
     }
     die(json_encode($json));
 }