/** * Execute the controller, delete the record and redirect to comments view. * * @return boolean True if controller finished execution. */ public function execute() { if (!JFactory::getUser()->authorise('comment.delete', 'com_monitor')) { throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 403); } $app = JFactory::getApplication(); $model = new MonitorModelComment($app); $ids = $app->input->get('cid', array(), 'array'); if (count($ids) <= 0) { $ids = $app->input->get('id', array(), 'array'); } if (count($ids) <= 0) { $app->enqueueMessage(JText::_('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST'), 'error'); } else { $model->delete($ids); $app->enqueueMessage(JText::_('COM_MONITOR_COMMENT_DELETED')); } if ($app->isAdmin()) { $app->redirect(JRoute::_('index.php?option=com_monitor&view=comments', false)); } else { $issue_id = $this->input->getInt('issue_id', null); if ($issue_id) { $app->redirect(JRoute::_('index.php?option=com_monitor&view=issue&id=' . $issue_id, false)); } else { $app->redirect(JRoute::_('index.php?option=com_monitor&view=issues', false)); } } return true; }
/** * Method to render the view. * * @return string The rendered view. * * @since 12.1 * @throws RuntimeException */ public function render() { $this->items = $this->model->getComments(); $this->filterForm = $this->model->getFilterForm(); $this->defaultTitle = JText::_('COM_MONITOR_COMMENTS'); $this->setLayout('default'); return parent::render(); }
/** * Method to render the view. * * @return string The rendered view. * * @throws RuntimeException */ public function render() { $this->item = $this->model->getComment(); if ($this->getLayout() == null) { $this->setLayout('edit'); } $this->form = $this->model->getForm(); // Attachments $this->attachments = $this->model->getCommentAttachments(); $this->addToolbar(); return parent::render(); }
/** * Execute the controller, load a form for the given comment. * * @return boolean True if controller finished execution. */ public function execute() { $cid = $this->input->get('cid', array(), 'array'); $id = $cid ? $cid[0] : $this->input->getInt('id'); $model = new MonitorModelComment(); if (!$model->canEdit(JFactory::getUser(), $id)) { throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 403); } $model->setCommentId($id); $model->loadForm(); $view = new MonitorViewCommentHtml($model); $view->setLayout('edit'); echo $view->render(); return true; }
/** * Method to render the view. * * @return string The rendered view. * * @since 12.1 * @throws RuntimeException */ public function render() { $this->prefix = 'comment'; $comments = $this->model->getComments(); $this->items = $comments; $user = JFactory::getUser(); $this->canDeleteComments = $user->authorise('comment.delete', 'com_monitor'); $this->canEditComments = $user->authorise('comment.edit', 'com_monitor'); $this->canEditOwnComments = $user->authorise('comment.edit.own', 'com_monitor'); $this->canEditIssues = $user->authorise('issue.edit', 'com_monitor'); $this->canEditOwnIssues = $user->authorise('issue.edit.own', 'com_monitor'); $this->canEditProjects = $user->authorise('project.edit', 'com_monitor'); $this->setLayout('default'); $this->addToolbar(); return parent::render(); }
/** * Execute the controller, save the values from the form and redirect to comments view. * * @return boolean True if controller finished execution. */ public function execute() { $app = JFactory::getApplication(); $issue_id = $this->input->getInt('issue_id'); $id = $this->input->getInt('id'); $model = new MonitorModelComment($app); $user = JFactory::getUser(); if (!$model->canEdit($user, $id)) { throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 403); } $result = $model->save($this->input); if ($result === false) { $url = 'index.php?option=com_monitor&task=comment.edit'; if ($id) { $url .= '&id=' . $id; } elseif ($issue_id) { $url .= '&issue_id=' . $issue_id; } $app->redirect(JRoute::_($url, false)); return false; } $app->enqueueMessage(JText::_('COM_MONITOR_COMMENT_SAVED')); $commentLink = JRoute::_('index.php?option=com_monitor&view=issue&id=' . $issue_id . '#comment-' . $result, false); if (!$id) { // Send notification mails for new comments. $modelSubscription = new MonitorModelSubscription(); $modelSubscription->notifyIssue($issue_id, $user, $commentLink); // Mark issue as unread. $modelNotification = new MonitorModelNotifications(); $modelNotification->markUnread($issue_id, $result); } if ($app->isAdmin()) { $app->redirect(JRoute::_('index.php?option=com_monitor&view=comments', false)); } else { $app->redirect($commentLink); } return true; }
/** * Event called after display of content. * * @param string $context The context of the content being passed to the plugin. * @param mixed &$item The item displayed. * @param mixed $params Additional parameters. * @param integer $page Optional page number. * * @return string Returned value from this event will be displayed after the content of the item. */ public function onContentAfterDisplay($context, &$item, $params, $page = 0) { $allowed_contexts = array('com_contact.contact'); if (!in_array($context, $allowed_contexts)) { return null; } // Check if the component is installed and enabled. if (!JComponentHelper::isEnabled('com_monitor')) { return null; } JLoader::register('MonitorHelper', JPATH_ROOT . '/administrator/components/com_monitor/helper/helper.php'); JLoader::register('MonitorModelAbstract', JPATH_ROOT . '/administrator/components/com_monitor/model/abstract.php'); JLoader::register('MonitorModelComment', JPATH_ROOT . '/administrator/components/com_monitor/model/comment.php'); JLoader::register('MonitorModelIssue', JPATH_ROOT . '/administrator/components/com_monitor/model/issue.php'); $modelIssue = new MonitorModelIssue(null, false); $modelComment = new MonitorModelComment(null, false); // Load language files from the component. $lang = JFactory::getLanguage(); $lang->load('com_monitor', JPATH_SITE . '/components/com_monitor'); $filters = array('author' => $item->user_id); $listIssues = array('fullordering' => 'i.created DESC', 'limit' => $this->params->get('limit_issues', 10)); $listComments = array('fullordering' => 'c.created DESC', 'limit' => $this->params->get('limit_comments', 10)); $comments = $modelComment->getComments($filters, $listComments); // Process the content plugins on comments. $dispatcher = JEventDispatcher::getInstance(); JPluginHelper::importPlugin('content'); if ($comments) { foreach ($comments as $comment) { $dispatcher->trigger('onContentPrepare', array('plg_monitorcontributions.comment', &$comment, &$this->params, 0)); } } $displayData = array('item' => $item); $displayData['issues'] = $modelIssue->getIssues($filters, $listIssues); $displayData['comments'] = $comments; $displayData['params'] = $this->params->merge(JComponentHelper::getParams('com_monitor')); return JLayoutHelper::render('contributions', $displayData, __DIR__ . '/layouts'); }
/** * Execute the controller, load a form for the given comment. * * @return boolean True if controller finished execution. */ public function execute() { $model = new MonitorModelComment(); $id = $this->input->getInt('id'); // Get the params // TODO: may be removed when new MVC is implemented completely $app = JFactory::getApplication(); if ($app instanceof JApplicationSite) { $params = $app->getParams(); } // ACL: Check if user can create $user = JFactory::getUser(); if (!$model->canEdit($user, $id)) { if ($user->guest && isset($params) && $params->get('redirect_login', 1)) { $this->app->enqueueMessage(JText::_('JGLOBAL_YOU_MUST_LOGIN_FIRST'), 'error'); $this->app->redirect(JRoute::_('index.php?option=com_users&view=login&return=' . base64_encode(JUri::getInstance()->toString()), '403')); } else { throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 403); } } if ($id != 0) { $model->setCommentId($id); } else { $issue_id = $this->input->getInt('issue_id'); if ($issue_id == 0) { $this->app->enqueueMessage(JText::_('COM_MONITOR_ERROR_INVALID_ID'), 'error'); return false; } $model->setIssueId($issue_id); } $model->loadForm(); $view = new MonitorViewCommentHtml($model); $view->setLayout('edit'); echo $view->render(); return true; }
/** * Method to render the view. * * @return string The rendered view. * * @throws RuntimeException */ public function render() { $this->item = $this->model->getComment(); if ($this->getLayout() == null) { $this->setLayout('edit'); } if ($this->item) { $this->model->setIssueId($this->item->issue_id); } $this->issue_id = $this->model->getIssueId(); $this->issue_title = $this->model->getIssueTitle(); $this->form = $this->model->getForm(); $this->defaultTitle = JText::sprintf('COM_MONITOR_CREATE_COMMENT_TITLE', $this->issue_title); $this->attachments = $this->model->getCommentAttachments(); return parent::render(); }
/** * Method to render the view. * * @return string The rendered view. * * @throws RuntimeException */ public function render() { $this->item = $this->model->getIssue(); $user = JFactory::getUser(); $app = JFactory::getApplication(); if ($this->item) { if (!in_array($this->item->access, $user->getAuthorisedViewLevels())) { if ($user->guest && $this->params->get('redirect_login', 1)) { $app->enqueueMessage(JText::_('JGLOBAL_YOU_MUST_LOGIN_FIRST'), 'error'); $app->redirect(JRoute::_('index.php?option=com_users&view=login&return=' . base64_encode(JUri::getInstance()->toString()), '403')); } else { throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 403); } } $this->canEditIssue = $this->model->canEdit($user, $this->item->id); // Title if ($this->layout === 'edit') { $this->defaultTitle = JText::sprintf('COM_MONITOR_EDIT_ISSUE', $this->item->title); } else { $this->defaultTitle = $this->escape($this->item->title); } // Avatar if (JPluginHelper::isEnabled('user', 'cmavatar')) { // Include the CMAvatar plugin. require_once JPATH_PLUGINS . '/user/cmavatar/helper.php'; $this->avatars = array(); $this->avatars[$this->item->author_id] = PlgUserCMAvatarHelper::getAvatar($this->item->author_id); } // Buttons if ($this->getLayout() === 'default') { if ($this->canEditIssue) { $this->buttons['edit'] = array('url' => 'index.php?option=com_monitor&task=issue.edit&id=' . $this->item->id, 'text' => 'JGLOBAL_EDIT', 'title' => 'JGLOBAL_EDIT', 'icon' => 'icon-pencil-2'); } if ($this->params->get('enable_notifications', 1) && !$user->guest) { $subscribed = $this->modelSubscription->isSubscriberIssue($this->item->id, $user->id); $task = $subscribed ? 'unsubscribe' : 'subscribe'; $this->buttons['subscribe'] = array('url' => 'index.php?option=com_monitor&task=issue.' . $task . '&id=' . $this->item->id, 'text' => $subscribed ? 'COM_MONITOR_UNSUBSCRIBE_ISSUE' : 'COM_MONITOR_SUBSCRIBE_ISSUE', 'title' => $subscribed ? 'COM_MONITOR_UNSUBSCRIBE_ISSUE_DESC' : 'COM_MONITOR_SUBSCRIBE_ISSUE_DESC', 'icon' => $subscribed ? 'icon-star' : 'icon-star-empty'); } } } else { $this->canEditIssue = $this->model->canEdit($user); $this->defaultTitle = JText::_('COM_MONITOR_CREATE_ISSUE'); } $this->canDeleteComments = $user->authorise('comment.delete', 'com_monitor'); $this->canEditComments = $user->authorise('comment.edit', 'com_monitor'); $this->canEditOwnComments = $user->authorise('comment.edit.own', 'com_monitor'); // Comments if ($this->modelComment) { $this->comments = $this->modelComment->getIssueComments($this->item->id); foreach ($this->comments as $comment) { // Avatars if ($this->avatars !== null) { if (!isset($this->avatars[$comment->author_id])) { $this->avatars[$comment->author_id] = PlgUserCMAvatarHelper::getAvatar($comment->author_id); } } // Attachments $comment->attachments = $this->modelComment->getCommentAttachments($comment->id); } // Pagination $this->pagination = $this->modelComment->getPagination(); // Ordering $this->listOrder = $this->escape($this->modelComment->getState()->get('list.ordering')); $this->listDir = $this->escape($this->modelComment->getState()->get('list.direction')); } $this->status = $this->model->getStatus(); $this->defaultStatus = $this->model->getDefaultStatus(); // Attachments $this->attachments = $this->model->getAttachments(); // Process the content plugins. $dispatcher = JEventDispatcher::getInstance(); JPluginHelper::importPlugin('content'); if ($this->item && $this->getLayout() === 'default') { $dispatcher->trigger('onContentPrepare', array('com_monitor.issue', &$this->item, &$this->params, 0)); $this->item->event = new stdClass(); $results = $dispatcher->trigger('onContentAfterTitle', array('com_monitor.issue', &$this->item, &$this->params, 0)); $this->item->event->afterDisplayTitle = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_monitor.issue', &$this->item, &$this->params, 0)); $this->item->event->beforeDisplayContent = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentAfterDisplay', array('com_monitor.issue', &$this->item, &$this->params, 0)); $this->item->event->afterDisplayContent = trim(implode("\n", $results)); if ($this->comments) { foreach ($this->comments as $comment) { $dispatcher->trigger('onContentPrepare', array('com_monitor.comment', &$comment, &$this->params, 0)); } } } return parent::render(); }