Esempio n. 1
0
 /**
  * Ajax leave
  */
 public function leave()
 {
     $my = JXFactory::getUser();
     $group = JTable::getInstance('Group', 'StreamTable');
     $group->load(JRequest::getVar('group_id'));
     /* update activity table */
     $activity = new StreamActivity();
     $activity->update($my->id, 'groups');
     // If you leave, you also unfollow a group
     $group->followers = JXUtility::csvRemove($group->followers, $my->id);
     $group->members = JXUtility::csvRemove($group->members, $my->id);
     $group->store();
     // Store user cache
     $groupList = $my->getParam('groups_member');
     $groupList = JXUtility::csvRemove($groupList, $group->id);
     $my->setParam('groups_member', $groupList);
     $my->save();
     $data = array();
     // leaving private group should redirect to group list page to avoid error msg
     if ($group->access) {
         $data['redirect'] = JRoute::_('index.php?option=com_stream&view=groups', FALSE);
     } else {
         $data['redirect'] = JRoute::_('index.php?option=com_stream&view=groups&task=show&group_id=' . $group->id, FALSE);
     }
     header('Content-Type: text/json');
     echo json_encode($data);
     exit;
 }
Esempio n. 2
0
 /**
  *  Save stream
  */
 public function save()
 {
     // Store stream
     $message_id = JRequest::getInt('message_id');
     $streamModel = StreamFactory::getModel('stream');
     $stream = JTable::getInstance('Stream', 'StreamTable');
     $stream->load($message_id);
     $my = JXFactory::getUser();
     if (!$my->authorise('stream.message.edit', $stream)) {
         exit;
     }
     /* update the activity records */
     $activity = new StreamActivity();
     $activity->update($my->id, $stream->type);
     //	Update attachement there might be addition and removals
     $oldFiles = $stream->getFiles();
     $oldMilestone = isset($stream->getData()->milestone) ? $stream->getData()->milestone : null;
     $stream->bind(JRequest::get('POST', JREQUEST_ALLOWRAW));
     // Checking on invalid data type
     if (JRequest::getVar('type') == 'event') {
         /* this rarely happen but will do if somehow javascript validation is skipped */
         $eventModel = StreamFactory::getModel('events');
         $fallbackEventDuration = $eventModel->determinedEventDuration(JRequest::getVar('start_date'), JRequest::getVar('end_date'));
         $stream->start_date = strpos(JRequest::getVar('start_date'), '0000-00-00 00:00') === false ? JRequest::getVar('start_date') : $fallbackEventDuration['startDate']->format('Y-m-d h:i');
         $stream->end_date = strpos(JRequest::getVar('end_date'), '0000-00-00 00:00') === false ? JRequest::getVar('end_date') : $fallbackEventDuration['endDate']->format('Y-m-d h:i');
     }
     // edit should re-save the linkable link
     $stream->setParam('linkable_link', JRequest::getVar('linkable_link'));
     // Custom filtering
     $this->_filterVideoURL($stream);
     $this->_filterSlideShare($stream);
     // If location is specified, validate them
     $stream->setParam('loc_valid', 0);
     if (JRequest::getVar('location')) {
         jimport('joomla.utilities.map');
         if (JMap::validateAddress(JRequest::getVar('location'))) {
             $stream->setParam('loc_valid', 1);
         }
         $stream->setParam('hide_map', JRequest::getVar('hide_map', '0'));
     } else {
         $rawData = json_decode($stream->raw);
         $rawData->location = "";
         $stream->raw = json_encode($rawData);
         $stream->store();
     }
     // When edit the stream message, also need to process the tags
     $hashtags = StreamMessage::getHashtags($stream->message);
     $rawData = json_decode($stream->raw);
     foreach ($hashtags as $tag) {
         $unsupportedChars = array(',');
         $tag = str_replace($unsupportedChars, '', $tag);
         $hashedTag = '#' . trim($tag) . '#';
         if (!JXUtility::csvExist($rawData->tags, $hashedTag)) {
             $tagsTrend = new StreamTag();
             $tagsTrend->updateTrending($tag, $stream->group_id, true);
             $rawData->tags = JXUtility::csvInsert($rawData->tags, $hashedTag);
             // only update the hit if it is a newly added tag
             $hashtag = JTable::getInstance('Hashtag', 'StreamTable');
             $hashtag->load(array('hashtag' => $tag));
             $hashtag->hit();
             $hashtag->store();
         }
     }
     $stream->raw = json_encode($rawData);
     $pinTill = JRequest::getString('pinned', 0);
     if ($pinTill) {
         // Update pin to top status
         $pinTillDate = new JDate($stream->created);
         $pinTillDate->modify('+' . $pinTill);
         $stream->updated = $pinTillDate->toMySQL();
         $stream->store(true);
     } else {
         // If save is done within 5 mins of last edit, do not update the 'updated' time
         $now = new JDate();
         $updated = new JDate($stream->updated);
         $timediff = JXDate::timeDifference($updated->toUnix(), $now->toUnix());
         $stream->pinned = 0;
         $stream->store($timediff['days'] == 0 && $timediff['hours'] == 0 && $timediff['minutes'] < STREAM_EDIT_INTERVAL);
     }
     // Delete file attachment that are no longer used
     $newFiles = $stream->getFiles();
     $requestFiles = JRequest::getVar('attachment', array());
     foreach ($oldFiles as $file) {
         if (!in_array($file->id, $requestFiles)) {
             $file->delete();
         }
     }
     if (JRequest::getVar('group_id')) {
         $group = JTable::getInstance('Group', 'StreamTable');
         $group->load(JRequest::getVar('group_id'));
         if ($group) {
             // the parameter need to be updated otherwise stream will be visible when moved to private group
             $stream->setParam('group_id', $group->id);
             $stream->access = $group->access;
             $stream->store(true);
             // Upgrade group stats if necessary
             $group->setParam('last_message', $stream->id);
             $group->setParam('message_count', $streamModel->countStream(array('group_id' => $group->id)));
             $group->setParam($stream->type . '_count', $streamModel->countStream(array('group_id' => $group->id, 'type' => $stream->type)));
             $group->store();
         }
     }
     // For all new attachment, we need to set their owner
     $fileModel = StreamFactory::getModel('files');
     $fileModel->updateOwner($stream);
     // Update related milestone
     $this->_updateMilestone($stream, $oldMilestone);
     $data = array();
     $data['html'] = $stream->getHTML();
     $data['id'] = $message_id;
     header('Content-Type: text/json');
     echo json_encode($data);
     exit;
 }