public function display($tpl = null) { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ $this->option = JFactory::getApplication()->input->getCmd('option'); $this->state = $this->get('State'); $this->item = $this->get('Item'); $this->params = $this->state->get('params'); $this->category = new Userideas\Category\Category(JFactory::getDbo()); $this->category->load($this->item->catid); $user = JFactory::getUser(); $this->userId = $user->get('id'); // Set permission state. Is it possible to be edited items? $this->canEdit = $user->authorise('core.edit.own', 'com_userideas'); $this->commentsEnabled = $this->params->get('comments_enabled', 1); $this->canComment = $user->authorise('userideas.comment.create', 'com_userideas'); $this->canEditComment = $user->authorise('userideas.comment.edit.own', 'com_userideas'); // Get the model of the comments // that I will use to load all comments for this item. $modelComments = JModelLegacy::getInstance('Comments', 'UserIdeasModel'); $this->comments = $modelComments->getItems(); // Get the model of the comment $commentModelForm = JModelLegacy::getInstance('Comment', 'UserIdeasModel'); // Validate the owner of the comment, // If someone wants to edit it. $commentId = (int) $commentModelForm->getState('comment_id'); if ($commentId > 0) { $comment = $commentModelForm->getItem($commentId, $this->userId); if (!$comment) { $app->enqueueMessage(JText::_('COM_USERIDEAS_ERROR_INVALID_COMMENT'), 'error'); $app->redirect(JRoute::_(UserIdeasHelperRoute::getItemsRoute(), false)); return; } } // Get comment form $this->form = $commentModelForm->getForm(); // Prepare integration. Load avatars and profiles. $this->prepareIntegration($this->params); // Prepare the link to the details page. $this->item->link = UserIdeasHelperRoute::getDetailsRoute($this->item->slug, $this->item->catslug); $this->item->text = $this->item->description; $this->prepareDebugMode(); $this->prepareDocument(); // Events JPluginHelper::importPlugin('content'); $dispatcher = JEventDispatcher::getInstance(); $this->item->event = new stdClass(); $offset = 0; $dispatcher->trigger('onContentPrepare', array('com_userideas.details', &$this->item, &$this->params, $offset)); $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_userideas.details', &$this->item, &$this->params, $offset)); $this->item->event->beforeDisplayContent = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentAfterDisplay', array('com_userideas.details', &$this->item, &$this->params, $offset)); $this->item->event->onContentAfterDisplay = trim(implode("\n", $results)); $this->item->description = $this->item->text; unset($this->item->text); // Count hits $model = $this->getModel(); $model->hit($this->item->id); parent::display($tpl); }
/** * Display the view */ public function display($tpl = null) { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ // Initialise variables $this->state = $this->get('State'); $this->form = $this->get('Form'); $this->params = $this->state->get("params"); $user = JFactory::getUser(); $userId = $user->get("id"); $model = $this->getModel(); if (!$user->authorise('core.create', 'com_userideas')) { $returnUrl = UserIdeasHelperRoute::getFormRoute(); $app->enqueueMessage(JText::_("COM_USERIDEAS_ERROR_NO_PERMISSIONS_TO_DO_ACTION"), "notice"); $app->redirect(JRoute::_('index.php?option=com_users&view=login&return=' . base64_encode($returnUrl), false)); return; } $itemId = $this->state->get("form.id"); if (!empty($itemId) and !$model->canEditOwn($itemId, $userId)) { $returnUrl = UserIdeasHelperRoute::getFormRoute(); $app->enqueueMessage(JText::_("COM_USERIDEAS_ERROR_NO_PERMISSIONS_TO_DO_ACTION"), "notice"); $app->redirect(JRoute::_('index.php?option=com_users&view=login&return=' . base64_encode($returnUrl), false)); return; } $this->prepareDebugMode(); $this->prepareDocument(); parent::display($tpl); }
/** * Display the view. */ public function display($tpl = null) { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ // Initialise variables $this->state = $this->get('State'); $this->item = $this->get('Item'); $this->params = $this->state->get("params"); jimport("userideas.category"); $this->category = new UserIdeasCategory(JFactory::getDbo()); $this->category->load($this->item->catid); $this->userId = JFactory::getUser()->get("id"); // Get the model of the comments // that I will use to load all comments for this item. $modelComments = JModelLegacy::getInstance("Comments", "UserIdeasModel"); $this->comments = $modelComments->getItems(); // Get the model of the comment $commentModelForm = JModelLegacy::getInstance("Comment", "UserIdeasModel"); // Validate the owner of the comment, // If someone wants to edit it. $commentId = $commentModelForm->getState("comment_id"); if (!empty($commentId)) { $comment = $commentModelForm->getItem($commentId, $this->userId); if (!$comment) { $app->enqueueMessage(JText::_("COM_USERIDEAS_ERROR_INVALID_COMMENT"), "error"); $app->redirect(JRoute::_(UserIdeasHelperRoute::getItemsRoute(), false)); return; } } // Get comment form $this->form = $commentModelForm->getForm(); // Prepare integration. Load avatars and profiles. $this->prepareIntegration($this->params); // Prepare the link to the details page. $this->item->link = UserIdeasHelperRoute::getDetailsRoute($this->item->slug, $this->item->catslug); $this->item->text = $this->item->description; $this->version = new UserIdeasVersion(); $this->prepareDebugMode(); $this->prepareDocument(); // Events JPluginHelper::importPlugin('content'); $dispatcher = JEventDispatcher::getInstance(); $this->item->event = new stdClass(); $offset = 0; $dispatcher->trigger('onContentPrepare', array('com_userideas.details', &$this->item, &$this->params, $offset)); $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_userideas.details', &$this->item, &$this->params, $offset)); $this->item->event->beforeDisplayContent = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentAfterDisplay', array('com_userideas.details', &$this->item, &$this->params, $offset)); $this->item->event->onContentAfterDisplay = trim(implode("\n", $results)); $this->item->description = $this->item->text; unset($this->item->text); // Count hits $model = $this->getModel(); $model->hit($this->item->id); parent::display($tpl); }
public function save($key = null, $urlVar = null) { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // Get the data from the form POST $data = $this->input->post->get('jform', array(), 'array'); $itemId = JArrayHelper::getValue($data, "id", 0, "int"); $redirectOptions = array("view" => "form", "id" => $itemId); // Check for valid user $userId = JFactory::getUser()->id; if (!$userId) { $redirectOptions = array("force_direction" => "index.php?option=com_users&view=login"); $this->displayNotice(JText::_('COM_USERIDEAS_ERROR_NOT_LOG_IN'), $redirectOptions); return; } // Check for valid owner of the item if (!empty($itemId)) { jimport("userideas.validator.item.owner"); $itemValidator = new UserIdeasValidatorItemOwner(JFactory::getDbo(), $itemId, $userId); if (!$itemValidator->isValid($itemId, $userId)) { $redirectOptions = array("force_direction" => UserIdeasHelperRoute::getItemsRoute()); $this->displayNotice(JText::_('COM_USERIDEAS_ERROR_INVALID_ITEM'), $redirectOptions); return; } } $model = $this->getModel(); /** @var $model UserIdeasModelForm */ $form = $model->getForm($data, false); /** @var $form JForm */ if (!$form) { throw new Exception(JText::_("COM_USERIDEAS_ERROR_FORM_CANNOT_BE_LOADED"), 500); } // Test if the data is valid. $validData = $model->validate($form, $data); // Check for validation errors. if ($validData === false) { $this->displayNotice($form->getErrors(), $redirectOptions); return; } try { $validData["user_id"] = $userId; $itemId = $model->save($validData); $redirectOptions["id"] = $itemId; } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_USERIDEAS_ERROR_SYSTEM')); } // Redirect to next page $this->displayMessage(JText::_('COM_USERIDEAS_ITEM_SAVED_SUCCESSFULLY'), $redirectOptions); }
public function save($key = null, $urlVar = null) { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // Get the data from the form POST $data = $this->input->post->get('jform', array(), 'array'); $itemId = JArrayHelper::getValue($data, "id", 0, "int"); $redirectOptions = array("view" => "form", "id" => $itemId); // Check for valid user $user = JFactory::getUser(); $userId = $user->get("id"); if (!$this->allowSave($data)) { $redirectOptions = array("force_direction" => "index.php?option=com_users&view=login"); $this->displayNotice(JText::_('COM_USERIDEAS_ERROR_NO_PERMISSIONS_TO_DO_ACTION'), $redirectOptions); return; } // Get params $params = JComponentHelper::getParams("com_userideas"); $model = $this->getModel(); /** @var $model UserIdeasModelForm */ $form = $model->getForm($data, false); /** @var $form JForm */ if (!$form) { throw new Exception(JText::_("COM_USERIDEAS_ERROR_FORM_CANNOT_BE_LOADED"), 500); } // Test if the data is valid. $validData = $model->validate($form, $data); // Check for validation errors. if ($validData === false) { $this->displayNotice($form->getErrors(), $redirectOptions); return; } try { // Set the user ID. $validData["user_id"] = (int) $userId; $itemId = $model->save($validData); $redirectOptions["id"] = $itemId; } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_USERIDEAS_ERROR_SYSTEM')); } $redirectOptions = array("force_direction" => (!$userId or strcmp("list", $params->get("redirect_when_post")) == 0) ? UserIdeasHelperRoute::getItemsRoute() : UserIdeasHelperRoute::getFormRoute($itemId)); // Redirect to next page $this->displayMessage(JText::_('COM_USERIDEAS_ITEM_SAVED_SUCCESSFULLY'), $redirectOptions); }
public function save($key = null, $urlVar = null) { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // Check for valid user id $userId = JFactory::getUser()->get("id"); if (!$userId) { $redirectOptions = array("force_direction" => "index.php?option=com_users&view=login"); $this->displayNotice(JText::_('COM_USERIDEAS_ERROR_NOT_LOG_IN'), $redirectOptions); return; } $app = JFactory::getApplication(); /** @var $app JApplicationSite */ // Get the data from the form POST $data = $app->input->post->get('jform', array(), 'array'); $itemId = JArrayHelper::getValue($data, "item_id"); // Prepare response data $redirectOptions = array("view" => "details", "id" => $itemId); $model = $this->getModel(); /** @var $model UserIdeasModelComment */ $form = $model->getForm($data, false); /** @var $form JForm * */ if (!$form) { throw new Exception(JText::_("COM_USERIDEAS_ERROR_FORM_CANNOT_BE_LOADED"), 500); } // Test if the data is valid. $validData = $model->validate($form, $data); // Check for validation errors. if ($validData === false) { $this->displayNotice($form->getErrors(), $redirectOptions); return; } try { $model->save($validData); jimport("userideas.item"); $item = new UserIdeasItem(JFactory::getDbo()); $item->load($itemId); } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_USERIDEAS_ERROR_SYSTEM')); } $redirectOptions = array("force_direction" => UserIdeasHelperRoute::getDetailsRoute($item->getSlug(), $item->getCategorySlug())); // Redirect to next page $this->displayMessage(JText::_("COM_USERIDEAS_COMMENT_SENT_SUCCESSFULLY"), $redirectOptions); }
public static function status(UserIdeasStatus $status, $displayLink = true) { if (!$status->getId()) { return ""; } $styles = $status->getParam("style_class", ""); if (!empty($displayLink)) { $html = ' <a href="' . UserIdeasHelperRoute::getItemsRoute($status->getId()) . '" class="ui-status-label"> <span class="label' . $styles . '">' . htmlspecialchars($status->getName(), ENT_QUOTES, "utf-8") . '</span> </a>'; } else { $html = '<span class="label ui-status-label ' . $styles . '">' . htmlspecialchars($status->getName(), ENT_QUOTES, "utf-8") . '</span>'; } return $html; }
</div> <div class="clearfix"></div> <div class="well well-sm clearfix"> <div class="pull-left"> <?php $profile = JHtml::_('userideas.profile', $this->socialProfiles, $comment->user_id); echo JHtml::_('userideas.publishedByOn', $comment->author, $comment->record_date, $profile); ?> </div> <div class="pull-right"> <?php if (UserIdeasHelper::isValidOwner($this->userId, $comment->user_id) and $this->canEditComment) { ?> <a class="btn btn-default btn-sm" href="<?php echo JRoute::_(UserIdeasHelperRoute::getDetailsRoute($this->item->slug, $this->item->catid) . '&comment_id=' . (int) $comment->id); ?> #ui-comment-form"> <span class="fa fa-edit"></span> <?php echo JText::_('COM_USERIDEAS_EDIT'); ?> </a> <?php } ?> </div> </div> </div> <?php
<?php echo JText::_("COM_USERIDEAS_COMMENTS"); ?> <?php echo "( " . $commentsNumber . " )"; ?> </a> <?php } ?> <?php if (UserIdeasHelper::isValidOwner($this->userId, $item->user_id) and $this->canEdit) { ?> <a class="btn btn-small" href="<?php echo JRoute::_(UserIdeasHelperRoute::getFormRoute($item->id)); ?> " > <i class="icon-edit"></i> <?php echo JText::_("COM_USERIDEAS_EDIT"); ?> </a> <?php } ?> </div> </div> </div> <?php }
/** * Method to parse Route * * @param array $segments * * @return array */ function UserIdeasParseRoute($segments) { $vars = array(); //Get the active menu item. $app = JFactory::getApplication(); $menu = $app->getMenu(); $item = $menu->getActive(); // Count route segments $count = count($segments); // Standard routing for item. If we don't pick up an Itemid then we get the view from the segments // the first segment is the view and the last segment is the id of the details, category,... if (!isset($item)) { $vars['view'] = $segments[0]; $vars['id'] = $segments[$count - 1]; return $vars; } // COUNT == 1 // Category if ($count == 1) { list($id, $alias) = explode(':', $segments[0], 2); // first we check if it is a category $category = JCategories::getInstance('UserIdeas')->get($id); if ($category and strcmp($category->alias, $alias) == 0) { // Category $vars['view'] = 'category'; $vars['id'] = $id; return $vars; } else { $idea = UserIdeasHelperRoute::getItem($id); if ($idea) { if ($idea->alias == $alias) { $vars['view'] = 'details'; $vars['catid'] = (int) $idea->catid; $vars['id'] = (int) $id; return $vars; } } } } // COUNT => 2 // If there was more than one segment, then we can determine where the URL points to // because the first segment will have the target item id prepended to it. If the // last segment has a number prepended, it is details, otherwise, it is a category. $catId = (int) $segments[0]; $itemId = (int) $segments[$count - 1]; if ($itemId > 0) { $vars['view'] = 'details'; $vars['catid'] = $catId; $vars['id'] = $itemId; } else { $vars['view'] = 'category'; $vars['id'] = $catId; } return $vars; }
protected function sendMail($emailId, $title, $itemId, $categoryId) { $result = true; $this->loadLanguage(); $app = JFactory::getApplication(); /** @var $app JApplicationSite */ jimport("userideas.email"); $email = new UserIdeasEmail(); $email->setDb(JFactory::getDbo()); $email->load($emailId); // Set sender name if (!$email->getSenderName()) { $email->setSenderName($app->get("fromname")); } $fromMail = !$email->getSenderEmail() ? $app->get("mailfrom") : $email->getSenderEmail(); $fromName = !$email->getSenderName() ? $app->get("fromname") : $email->getSenderName(); $recipientMail = $fromMail; $uri = JUri::getInstance(); $website = $uri->toString(array("scheme", "host")); $data = array("site_name" => $app->get("sitename"), "site_url" => JUri::root(), "item_title" => $title, "item_url" => $website . JRoute::_(UserIdeasHelperRoute::getDetailsRoute($itemId, $categoryId)), "sender_name" => $fromName, "sender_email" => $fromMail, "recipient_name" => $fromName); $emailMode = $this->params->get("email_mode", "plain"); // Parse data $email->parse($data); $subject = $email->getSubject(); $body = $email->getBody($emailMode); $mailer = JFactory::getMailer(); if (strcmp("html", $emailMode) == 0) { // Send as HTML message $return = $mailer->sendMail($fromMail, $fromName, $recipientMail, $subject, $body, UserIdeasConstants::MAIL_MODE_HTML); } else { // Send as plain text. $return = $mailer->sendMail($fromMail, $fromName, $recipientMail, $subject, $body, UserIdeasConstants::MAIL_MODE_PLAIN); } // Check for an error. if ($return !== true) { $error = JText::_("PLG_CONTENT_USERIDEASADMINMAIL_ERROR_MAIL_SENDING_USER"); JLog::add($error); $result = false; } return $result; }
/** * Load data about category. * We use this method in the router "UserIdeasParseRoute". * * @param int $id * * @return array */ public static function getCategory($id) { // Load all categories. if (self::$categories === null) { $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('a.id, a.alias, ' . $query->concatenate(array('a.id', 'a.alias'), ':') . ' AS slug')->from($query->quoteName('#__categories', 'a'))->where('a.extension = ' . $db->quote('com_userideas')); $db->setQuery($query); self::$categories = (array) $db->loadAssocList('id'); } return !array_key_exists($id, self::$categories) ? array() : self::$categories[$id]; }
</div> <a class="btn btn-default btn-small ui-btn-vote js-ui-btn-vote" href="javascript: void(0);" data-id="<?php echo $item->id; ?> "><?php echo JText::_('COM_USERIDEAS_VOTE'); ?> </a> </div> <div class="media-body"> <?php if ($this->params->get('show_title', $item->params->get('show_title', 1))) { ?> <h4 class="media-heading"> <a href="<?php echo JRoute::_(UserIdeasHelperRoute::getDetailsRoute($item->slug, $item->catid)); ?> "> <?php echo $this->escape($item->title); ?> </a> </h4> <?php } ?> <?php if ($this->params->get('show_intro', $item->params->get('show_intro', 1))) { ?> <?php
protected static function _findItem($needles = null) { $app = JFactory::getApplication(); $menus = $app->getMenu('site'); // Prepare the reverse lookup array. // Collect all menu items and creat an array that contains // the ID from the query string of the menu item as a key, // and the menu item id (Itemid) as a value // Example: // array( "category" => // 1(id) => 100 (Itemid), // 2(id) => 101 (Itemid) // ); if (self::$lookup === null) { self::$lookup = array(); $component = JComponentHelper::getComponent('com_userideas'); $items = $menus->getItems('component_id', $component->id); if ($items) { foreach ($items as $item) { if (isset($item->query) && isset($item->query['view'])) { $view = $item->query['view']; if (!isset(self::$lookup[$view])) { self::$lookup[$view] = array(); } if (isset($item->query['id'])) { self::$lookup[$view][$item->query['id']] = $item->id; } else { // If it is a root element that have no a request parameter ID ( categories, authors ), we set 0 for an key self::$lookup[$view][0] = $item->id; } } } } } if ($needles) { foreach ($needles as $view => $ids) { if (isset(self::$lookup[$view])) { foreach ($ids as $id) { if (isset(self::$lookup[$view][(int) $id])) { return self::$lookup[$view][(int) $id]; } } } } } else { $active = $menus->getActive(); if ($active) { return $active->id; } } return null; }
protected function sendMail($emailId, $title, $itemId, $categoryId) { $result = true; $this->loadLanguage(); $app = JFactory::getApplication(); /** @var $app JApplicationSite */ $uri = JUri::getInstance(); $website = $uri->toString(array('scheme', 'host')); $data = array('site_name' => $app->get('sitename'), 'site_url' => JUri::root(), 'item_title' => $title, 'item_url' => $website . JRoute::_(UserIdeasHelperRoute::getDetailsRoute($itemId, $categoryId))); $email = new EmailTemplates\Email(); $email->setDb(JFactory::getDbo()); $email->load($emailId); // Set sender name and email. if (!$email->getSenderName()) { $email->setSenderName($app->get('fromname')); } if (!$email->getSenderEmail()) { $email->setSenderEmail($app->get('mailfrom')); } // Prepare recipient data. $componentParams = JComponentHelper::getParams('com_userideas'); /** @var $componentParams Joomla\Registry\Registry */ $recipientId = (int) $componentParams->get('administrator_id'); if ($recipientId > 0) { $recipient = JFactory::getUser($recipientId); $recipientName = $recipient->get('name'); $recipientMail = $recipient->get('email'); } else { $recipientName = $app->get('fromname'); $recipientMail = $app->get('mailfrom'); } // Prepare data for parsing $data['sender_name'] = $email->getSenderName(); $data['sender_email'] = $email->getSenderEmail(); $data['recipient_name'] = $recipientName; $data['recipient_email'] = $recipientMail; $emailMode = $this->params->get('email_mode', 'plain'); // Parse data $email->parse($data); $subject = $email->getSubject(); $body = $email->getBody($emailMode); $mailer = JFactory::getMailer(); if (strcmp('html', $emailMode) === 0) { // Send as HTML message $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_HTML); } else { // Send as plain text. $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_PLAIN); } // Check for an error. if ($return !== true) { $error = JText::_('PLG_CONTENT_USERIDEASADMINMAIL_ERROR_MAIL_SENDING_USER'); JLog::add($error); $result = false; } return $result; }