Пример #1
0
 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);
 }
Пример #2
0
 /**
  * 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);
 }
Пример #3
0
 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);
 }
Пример #4
0
                    </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 
Пример #5
0
    $profileAvatar = null;
    if ($this->params->get("integration_display_owner_avatar", 0)) {
        $profileAvatar = JHtml::_("userideas.avatar", $this->socialProfiles, $item->user_id, $this->integrationOptions);
    }
    echo JHtml::_("userideas.publishedByOn", $name, $item->record_date, $profile, $profileAvatar, $this->integrationOptions);
    echo JHtml::_("userideas.category", $item->category, $item->catslug);
    echo JHtml::_("userideas.status", $item->status);
    ?>
            </div>
            <div class="pull-right">

                <?php 
    if ($this->commentsEnabled) {
        ?>
            	<a class="btn btn-small" href="<?php 
        echo JRoute::_(UserIdeasHelperRoute::getDetailsRoute($item->slug, $item->catid)) . "#comments";
        ?>
" >
            		<i class="icon-comment"></i>
            		<?php 
        echo JText::_("COM_USERIDEAS_COMMENTS");
        ?>
            		<?php 
        echo "( " . $commentsNumber . " )";
        ?>
            	</a> 
            	<?php 
    }
    ?>

            	<?php 
 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;
 }
Пример #7
0
 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;
 }