/** * Ajax call for 'done' */ public function done() { // Update user 'done' count $my = JXFactory::getUser(); $script = ''; $state = JRequest::getVar('state'); $item = JRequest::getVar('item'); $this->setdone(); // Update milestone stats $data = $this->data->getData(); if (isset($data->milestone) && !empty($data->milestone)) { $milestone = JTable::getInstance('Stream', 'StreamTable'); $milestone->load($data->milestone); $milestone->updateProgessStats(); $milestone->store(true); $script .= '$(\'div.progress[milestone="' . $milestone->id . '"]\').find("div.bar").css("width", "' . $milestone->getParam('progress') . '%")'; } if (intval($state) === 1) { // Trigger Complete Todo item email notification StreamNotification::trigger('todo_complete_item', $this->data, $my, $item); } $todoDone = $my->getParam('todo_done'); if ($state) { $todoDone++; } else { $todoDone--; } $my->setParam('todo_done', $todoDone); $my->save(); $data = array(); if (isset($milestone)) { $data['html2'] = $milestone->getMilestoneHTML($milestone); $data['milestone_id'] = $milestone->id; } $data['html'] = $this->data->getHTML(); $data['id'] = $this->data->id; $data['script'] = $script; echo json_encode($data); exit; }
/** * Add message */ public function add() { $user = JXFactory::getUser(); // Store stream $comment = JTable::getInstance('Comment', 'StreamTable'); $message = JTable::getInstance('Stream', 'StreamTable'); $message->load(JRequest::getVar('stream_id')); $user_id = JRequest::getVar('anon', false) ? JUserHelper::getUserId('anon') : $user->id; // People need to be able to read the message to add comment if (!$user->authorise('stream.message.read', $message)) { // No reason this code would ever get here! exit; } $comment->bind(JRequest::get('POST', JREQUEST_ALLOWRAW)); $comment->raw = json_encode(JRequest::get('POST', JREQUEST_ALLOWRAW)); $comment->user_id = $user_id; $comment->group_id = $message->group_id; $comment->store(); // Update group stats, if it is a group message if (!empty($comment->group_id)) { $group = JTable::getInstance('Group', 'StreamTable'); $group->load($comment->group_id); $group->setParam('last_comment', $comment->id); $group->store(); } // Trigger Notification StreamNotification::trigger('profile_post_comment', $comment); // If the updated date is set further than the current date, it is a pinned stream item and shouldn't be updated $now = new JDate(); $updated = new JDate($message->updated); $preventUpdate = $updated->toUnix() > $now->toUnix(); // Check pinned item status too? For now... naa // Update stream stats. Recalculate the count $this->_recalculateCommentCount($comment->stream_id, $preventUpdate); // Get the HTML code to append $tmpl = new StreamTemplate(); header('Content-Type: text/html; charset=UTF-8'); echo $tmpl->set('comment', $comment)->fetch('comment.item'); exit; }
/** * Ajax join */ public function follow() { $my = JXFactory::getUser(); $group = JTable::getInstance('Group', 'StreamTable'); $group->load(JRequest::getVar('group_id')); $group->followers = JXUtility::csvInsert($group->followers, $my->id); $group->store(); // Store user cache $groupList = $my->getParam('groups_follow'); $groupList = JXUtility::csvInsert($groupList, $group->id); $my->setParam('groups_follow', $groupList); $my->save(); // Trigger Group Follow Notification StreamNotification::trigger('group_follow', $group, $my); $data = array(); $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; }
/** * Add user to the item follower */ public function follow() { $stream_id = JRequest::getVar('stream_id'); $stream = JTable::getInstance('Stream', 'StreamTable'); $stream->load($stream_id); $stream->follow(); $stream->store(); // Trigger Event Join Notification StreamNotification::trigger('event_join', $stream); $data = array(); $data['html'] = $stream->getHTML('full'); $data['id'] = $stream_id; header('Content-Type: text/json'); echo json_encode($data); exit; }
public function replaceNew() { $my = JXFactory::getUser(); $file_id = JRequest::getInt('file_id'); $file = JTable::getInstance('File', 'StreamTable'); $result = new stdClass(); $result->error = true; if (intval($file_id) > 0) { $file->load($file_id); $previousFilename = $file->filename; if ($file->user_id != $my->id) { continue; } require JPATH_ROOT . DS . 'components' . DS . 'com_stream' . DS . 'controllers' . DS . 'system.php'; $systemController = new StreamControllerSystem(); $result = $systemController->handleUpload(); if (isset($result['success']) && $result['success']) { // Get mime type if (function_exists('finfo_open')) { $finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension $file->mimetype = finfo_file($finfo, JPATH_ROOT . DS . $result['path']); finfo_close($finfo); } else { $file->mimetype = @mime_content_type(JPATH_ROOT . DS . $result['path']); } $newFileExt = array_pop(explode('.', $result['filename'])); $oldFileExt = array_pop(explode('.', $file->filename)); $file->filename = preg_replace('/\\.\\w+$/', '.' . $newFileExt, $file->filename); // Delete the old one before saving the new one to the file db entry if ($file->getParam('has_preview')) { JFile::delete(JPATH_ROOT . DS . $file->path); $pathinfo = pathinfo($file->path); $thumbPath = JPATH_ROOT . DS . $pathinfo['dirname'] . DS . $pathinfo['filename'] . '_thumb.jpg'; JFile::delete($thumbPath); $thumbPath = JPATH_ROOT . DS . $pathinfo['dirname'] . DS . $pathinfo['filename'] . '_preview.jpg'; JFile::delete($thumbPath); } // set the file entry to the new uploaded file $file->path = $result['path']; $file->filesize = filesize(JPATH_ROOT . DS . $file->path); $file->store(); // Trigger Mentioned Name Notification $notificationType = 'file_replace_new'; StreamNotification::trigger($notificationType, $file, $previousFilename); $result['filename'] = $file->filename; $result['newext'] = $newFileExt; $result['oldext'] = $oldFileExt; $result['filesize'] = '(' . StreamMessage::formatBytes($file->filesize) . ')'; if ($file->getParam('has_preview')) { $pathinfo = pathinfo($result['path']); $result['preview'] = JURI::root() . str_replace(DS, '/', $file->getParam('thumb_path')); } else { $result['preview'] = JURI::root(); } } } echo htmlspecialchars(json_encode($result), ENT_NOQUOTES); exit; }