Example #1
0
 public function display($tpl = null)
 {
     if (count($errors = $this->get('Errors'))) {
         JError::raiseError(500, implode('<br />', $errors));
         return false;
     }
     $this->items = $this->get('Items');
     $this->pagination = $this->get('Pagination');
     $this->state = $this->get('State');
     $this->canDo = JUDownloadHelper::getActions('com_judownload');
     $this->groupCanDoManage = JUDownloadHelper::checkGroupPermission("comment.edit");
     $this->groupCanDoDelete = JUDownloadHelper::checkGroupPermission("comments.delete");
     $this->rootComment = JUDownloadFrontHelperComment::getRootComment();
     foreach ($this->items as &$item) {
         $this->ordering[$item->parent_id][] = $item->id;
     }
     $this->addToolBar();
     if (JUDownloadHelper::isJoomla3x()) {
         $layout = JFactory::getApplication()->input->get('layout', '');
         if ($layout != 'modal') {
             $this->filterForm = $this->get('FilterForm');
             $this->activeFilters = $this->get('ActiveFilters');
         }
     }
     parent::display($tpl);
     $this->setDocument();
 }
Example #2
0
 protected function allowEdit($data = array(), $key = 'id')
 {
     $recordId = (int) isset($data[$key]) ? $data[$key] : 0;
     $user = JFactory::getUser();
     $userId = $user->get('id');
     $rootComment = JUDownloadFrontHelperComment::getRootComment();
     if ($recordId && $recordId == $rootComment->id) {
         return false;
     }
     if ($user->authorise('core.edit', 'com_judownload')) {
         return true;
     }
     if ($user->authorise('core.edit.own', 'com_judownload')) {
         $ownerId = (int) isset($data['user_id']) ? $data['user_id'] : 0;
         if (empty($ownerId) && $recordId) {
             $record = $this->getModel()->getItem($recordId);
             if (empty($record)) {
                 return false;
             }
             $ownerId = $record->user_id;
         }
         if ($ownerId == $userId) {
             return true;
         }
     }
     return parent::allowEdit($data, $key);
 }
 function approve($comment_ids)
 {
     if (!is_array($comment_ids) || empty($comment_ids)) {
         $this->setError('COM_JUDOWNLOAD_NO_ITEM_SELECTED');
         return false;
     }
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_judownload/tables');
     $comment_table = JTable::getInstance("Comment", "JUDownloadTable");
     $count = 0;
     $comment_ids = (array) $comment_ids;
     $rootComment = JUDownloadFrontHelperComment::getRootComment();
     $docIds = array();
     foreach ($comment_ids as $comment_id) {
         $comment_table->reset();
         if ($comment_table->load($comment_id) && $comment_table->parent_id == $rootComment->id && $comment_table->approved == 0) {
             $docIds[$comment_table->doc_id] = $comment_table->doc_id;
         }
         $user = JFactory::getUser();
         $date = JFactory::getDate();
         $comment_table->approved = 1;
         $comment_table->published = 1;
         $comment_table->approved_by = $user->id;
         $comment_table->approved_time = $date->toSql();
         $comment_table->store();
         $count++;
         JUDownloadFrontHelperMail::sendEmailByEvent('comment.approve', $comment_id);
         $logData = array('user_id' => $comment_table->user_id, 'event' => 'comment.approve', 'item_id' => $comment_id, 'doc_id' => $comment_table->doc_id, 'value' => 0, 'reference' => '');
         JUDownloadFrontHelperLog::addLog($logData);
     }
     foreach ($docIds as $docId) {
         JUDownloadHelper::rebuildRating($docId);
     }
     return $count;
 }
Example #4
0
	public function display($tpl = null)
	{
		$this->items        = $this->get('Items');
		$this->params       = JUDownloadHelper::getParams();
		$this->state        = $this->get('State');
		$this->pagination   = $this->get('Pagination');
		$this->root_comment = JUDownloadFrontHelperComment::getRootComment();

		
		if (count($errors = $this->get('Errors')))
		{
			JError::raiseError(500, implode("\n", $errors));

			return false;
		}

		
		$this->order_name_array = array(
			'cm.title'         => JText::_('COM_JUDOWNLOAD_FIELD_TITLE'),
			'cm.created'       => JText::_('COM_JUDOWNLOAD_FIELD_CREATED'),
			'r.score'          => JText::_('COM_JUDOWNLOAD_FIELD_RATING_SCORE'),
			'cm.helpful_votes' => JText::_('COM_JUDOWNLOAD_FIELD_HELPFUL_VOTES'),
			'cm.total_votes'   => JText::_('COM_JUDOWNLOAD_FIELD_TOTAL_VOTES'));

		$this->order_dir_array = array(
			'ASC'  => JText::_('COM_JUDOWNLOAD_ASC'),
			'DESC' => JText::_('COM_JUDOWNLOAD_DESC'));

		$this->listOrder = $this->escape($this->state->get('list.ordering'));
		$this->listDirn  = $this->escape($this->state->get('list.direction'));

		$this->_prepareDocument();
		$this->_setBreadcrumb();

		parent::display($tpl);
	}
Example #5
0
	protected function _prepareData()
	{
		
		$this->token = JSession::getFormToken();

		
		$this->session = JFactory::getSession();

		
		$this->item->changelogs = JUDownloadFrontHelper::getChangeLogField($this->item->id);

		
		$this->item->versions = $this->model->getVersions($this->item->id);

		
		$this->item->related_documents = $this->model->getRelatedDocuments($this->item->id);
		if (count($this->item->related_documents))
		{
			foreach ($this->item->related_documents AS $documentRelated)
			{
				$documentRelated->link = JRoute::_(JUDownloadHelperRoute::getDocumentRoute($documentRelated->id));
				$documentRelated->icon = JUDownloadHelper::getDocumentIcon($documentRelated->icon);
			}
		}

		
		$this->item->files               = JUDownloadFrontHelperDocument::getFilesByDocumentId($this->item->id);
		$this->can_download_document     = JUDownloadFrontHelperPermission::canDownloadDocument($this->item->id, false);
		$this->display_download_rule_msg = $this->params->get('show_rule_messages', 'modal');

		
		$additionFields = array();
		if (trim($this->item->external_link))
		{
			$additionFields[] = 'external_link';
		}

		if ($this->item->license_id && $this->item->confirm_license)
		{
			$additionFields[] = 'license_id';
			$additionFields[] = 'confirm_license';
		}

		$this->item->fieldGallery = JUDownloadFrontHelperField::getField('gallery', $this->item);
		$this->item->fields       = JUDownloadFrontHelperField::getFields($this->item, 2, array(), array('gallery'), $additionFields);

		
		$this->item->license = JUDownloadFrontHelper::getLicense($this->item->license_id);

		$user = JFactory::getUser();
		$uri  = JUri::getInstance();
		
		if ($this->item->checked_out > 0 && $this->item->checked_out != $user->get('id'))
		{
			if (JUDownloadFrontHelperPermission::canCheckInDocument($this->item->id))
			{
				$this->item->checkin_link = JRoute::_('index.php?option=com_judownload&task=forms.checkin&id=' . $this->item->id . '&' . JSession::getFormToken() . '=1' . '&return=' . base64_encode(urlencode($uri)));
			}
		}
		else
		{
			$this->item->edit_link = JRoute::_('index.php?option=com_judownload&task=form.edit&id=' . $this->item->id . '&Itemid=' . JUDownloadHelperRoute::findItemIdOfDocument($this->item->id));

			if ($this->item->published == 1)
			{
				$this->item->editstate_link = JRoute::_('index.php?option=com_judownload&task=forms.unpublish&id=' . $this->item->id . '&return=' . base64_encode(urlencode($uri)) . '&' . JSession::getFormToken() . '=1&Itemid=' . JUDownloadHelperRoute::findItemIdOfDocument($this->item->id));
			}
			else
			{
				$this->item->editstate_link = JRoute::_('index.php?option=com_judownload&task=forms.publish&id=' . $this->item->id . '&return=' . base64_encode(urlencode($uri)) . '&' . JSession::getFormToken() . '=1&Itemid=' . JUDownloadHelperRoute::findItemIdOfDocument($this->item->id));
			}
		}

		$this->item->delete_link = JRoute::_('index.php?option=com_judownload&task=forms.delete&id=' . $this->item->id . '&return=' . base64_encode(urlencode($uri)) . '&' . JSession::getFormToken() . '=1&Itemid=' . JUDownloadHelperRoute::findItemIdOfDocument($this->item->id));

		
		if ($this->item->is_subscriber)
		{
			$this->item->unsubscribe_link = $this->model->getUnsubscribeLink($this->item->id);
		}
		else
		{
			$this->item->subscribe_link = $this->model->getSubscribeLink($this->item->id);
		}

		$this->item->contact_link = JRoute::_(JUDownloadHelperRoute::getContactRoute($this->item->id));

		$this->item->report_link = JRoute::_(JUDownloadHelperRoute::getReportDocumentRoute($this->item->id));

		$this->item->print_link = JRoute::_(JUDownloadHelperRoute::getDocumentRoute($this->item->id) . '&layout=print&tmpl=component&print=1');

		
		$this->item->comment = new stdClass();
		
		$this->item->comment->total_comments_no_filter = $this->model->getTotalCommentsOfDocument($this->item->id);

		
		$this->root_comment = JUDownloadFrontHelperComment::getRootComment();

		
		$langArray   = JHtml::_('contentlanguage.existing');
		$JAll        = new JObject();
		$JAll->text  = JText::_('JALL');
		$JAll->value = '*';
		array_unshift($langArray, $JAll);
		$this->langArray = $langArray;

		
		$this->item->comment->items = $this->get('Items');
		foreach ($this->item->comment->items AS $comment)
		{
			if (JUDownloadFrontHelperPermission::canCheckInComment($comment->id))
			{
				$uri                    = JUri::getInstance();
				$comment->checkout_link = 'index.php?option=com_judownload&task=modcomments.checkin&cid=' . $comment->id . '&' . JSession::getFormToken() . '=1' . '&return=' . base64_encode(urlencode($uri));
			}
			else
			{
				$comment->checkout_link = '';
			}
		}

		$this->item->comment->pagination = $this->get('Pagination');

		
		$this->item->comment->total_comments = $this->get('Total');

		
		$this->item->comment->parent_id = $this->root_comment->id;

		
		$this->website_field_in_comment_form = $this->params->get('website_field_in_comment_form', 0);
		$this->min_comment_characters        = $this->params->get('min_comment_characters', 20);
		$this->max_comment_characters        = $this->params->get('max_comment_characters', 1000);

		
		$this->allow_vote_comment      = $this->params->get('allow_vote_comment', 1);
		$this->allow_vote_down_comment = $this->params->get('allow_vote_down_comment', 1);

		
		$this->order_comment_name_array = $this->model->getCommentOrderingOptions();

		
		$this->order_comment_dir_array = array(
			'ASC'  => JText::_('COM_JUDOWNLOAD_ASC'),
			'DESC' => JText::_('COM_JUDOWNLOAD_DESC')
		);

		
		$this->total_stars          = $this->params->get('number_rating_stars', 5);
		$this->filter_comment_stars = array('' => JText::_('COM_JUDOWNLOAD_ANY_STAR'));
		for ($i = 0; $i <= $this->total_stars; $i++)
		{

			$score                              = ($i == 0) ? 0 : round((($i - 1) * 10) / $this->total_stars, 5) . ',' . round(($i * 10) / $this->total_stars, 5);
			$this->filter_comment_stars[$score] = JText::plural('COM_JUDOWNLOAD_N_STAR', $i);
		}

		
		if ($this->params->get('filter_comment_language', 0))
		{
			$this->list_lang_comment = $this->escape($this->state->get('list.lang'));
		}
		$this->list_order_comment  = $this->escape($this->state->get('list.ordering'));
		$this->list_dir_comment    = $this->escape($this->state->get('list.direction'));
		$this->filter_comment_star = $this->state->get('list.star_filter', '');

		
		$this->website  = $this->title = $this->email = $this->comment = $this->name = '';
		$this->language = '*';
		$form           = $this->session->get('judownload_commentform_' . $this->item->id, null);
		$this->form     = $form;
		if (!empty($form) && $form['parent_id'] == $this->root_comment->id)
		{
			$this->title    = $form['title'];
			$this->name     = $form['guest_name'];
			$this->email    = $form['guest_email'];
			$this->comment  = $form['comment'];
			$this->website  = (isset($form['website'])) ? $form['website'] : '';
			$this->language = $form['comment_language'];
		}
	}
Example #6
0
 protected function canEditState($record)
 {
     $rootComment = JUDownloadFrontHelperComment::getRootComment();
     if (isset($record->id) && $record->id == $rootComment->id) {
         return false;
     }
     $app = JFactory::getApplication();
     if ($app->isSite()) {
         $modCanEditState = JUDownloadFrontHelperModerator::checkModeratorCanDoWithComment($record->id, 'comment_edit_state');
         if ($modCanEditState) {
             return true;
         }
         return false;
     }
     return parent::canEditState($record);
 }
Example #7
0
	public function saveComment($postData = array())
	{
		
		$user    = JFactory::getUser();
		$nowDate = JFactory::getDate()->toSql();

		$title = htmlspecialchars($postData['title']);
		
		$comment = htmlspecialchars($postData['comment'], ENT_NOQUOTES);

		if ($user->get('guest'))
		{
			$guestName  = strip_tags($postData['guest_name']);
			$guestEmail = strip_tags($postData['guest_email']);
		}
		else
		{
			$guestName  = '';
			$guestEmail = '';
		}

		$website = isset($postData['website']) ? strip_tags($postData['website']) : '';

		$docId        = (int) $postData['doc_id'];
		$params       = JUDownloadHelper::getParams(null, $docId);
		$totalVotes   = 0;
		$helpfulVotes = 0;
		$ipAddress    = JUDownloadFrontHelper::getIpAddress();
		$parentId     = (int) $postData['parent_id'];
		$rootComment  = JUDownloadFrontHelperComment::getRootComment();

		
		if ($parentId == $rootComment->id)
		{
			
			$approved = JUDownloadFrontHelperPermission::canAutoApprovalComment($docId);
			$level    = 1;
			if ($params->get('filter_comment_language', 0))
			{
				$language = $postData['comment_language'];
			}
			else
			{
				$language = '*';
			}
		}
		else
		{
			
			$approved      = JUDownloadFrontHelperPermission::canAutoApprovalReplyComment($docId);
			$parentComment = $this->getCommentObject($parentId);
			$level         = $parentComment->level + 1;
			$language      = '*';
		}

		if ($approved)
		{
			$approved  = 1;
			$published = 1;
		}
		else
		{
			$approved  = 0;
			$published = 0;
		}

		$dataComment = array('title'         => $title, 'comment' => $comment, 'user_id' => $user->id,
		                     'guest_name'    => $guestName, 'guest_email' => $guestEmail, 'website' => $website,
		                     'doc_id'        => $docId, 'created' => $nowDate, 'total_votes' => $totalVotes,
		                     'helpful_votes' => $helpfulVotes, 'ip_address' => $ipAddress, 'approved' => $approved,
		                     'published'     => $published, 'parent_id' => $parentId, 'level' => $level,
		                     'language'      => $language
		);

		JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_judownload/tables');
		$commentTable = JTable::getInstance('Comment', 'JUDownloadTable');
		$commentTable->setLocation($postData['parent_id'], 'last-child');
		$commentTable->bind($dataComment);

		
		if (!$commentTable->check() || !$commentTable->store())
		{
			$this->setError($commentTable->getError());

			return false;
		}

		
		$canRateDocument = JUDownloadFrontHelperPermission::canRateDocument($docId);
		if ($canRateDocument && $params->get('enable_doc_rate_in_comment_form', 1) && ($commentTable->parent_id == $rootComment->id))
		{
			$postData['approved'] = $approved;
			$criteriaArray        = array();

			
			if (isset($postData['criteria_array']))
			{
				if (JUDownloadHelper::hasMultiRating())
				{
					$criteriaArray = $postData['criteria_array'];
					$saveRating    = $this->saveRating($postData, $docId, $criteriaArray, $commentTable->id);
				}
			}
			
			else
			{
				if (isset($postData['ratingValue']))
				{
					$saveRating = $this->saveRating($postData, $docId, $criteriaArray, $commentTable->id);
				}
			}

			if (!$saveRating)
			{
				$this->setError(JText::_('COM_JUDOWNLOAD_SAVE_RATING_FAILED'));

				return false;
			}
		}

		
		if (JUDLPROVERSION && isset($postData['subscribe']) && $postData['subscribe'])
		{
			$subscriptionData               = array();
			$subscriptionData['user_id']    = $user->id;
			$subscriptionData['type']       = 'comment';
			$subscriptionData['comment_id'] = $commentTable->id;
			$subscriptionData['name']       = ($user->id == 0) ? $guestName : $user->username;
			$subscriptionData['email']      = ($user->id == 0) ? $guestEmail : $user->email;
			$subscriptionData['item_id']    = $commentTable->id;
			$subscriptionData['ip_address'] = $ipAddress;
			$subscriptionData['created']    = $nowDate;
			$subscriptionData['published']  = ($user->id == 0 && $params->get('activate_subscription_by_email', 1)) ? 0 : 1;
			
			require_once JPATH_SITE . '/components/com_judownload/models/subscribe.php';
			JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_judownload/models');
			$subscribeModel = JModelLegacy::getInstance('Subscribe', 'JUDownloadModel');
			if (!$subscribeModel->add($subscriptionData))
			{
				$this->setError(JText::_('COM_JUDOWNLOAD_SUBSCRIBE_FAILED'));

				return false;
			}
		}

		
		if ($commentTable->parent_id == $rootComment->id)
		{
			
			JUDownloadFrontHelperMail::sendEmailByEvent('comment.create', $commentTable->id);
			
			$logData = array(
				'item_id' => $commentTable->id,
				'doc_id'  => $docId,
				'user_id' => $user->id,
				'event'   => 'comment.create'
			);

			$commentSubmitType = 'create';
		}
		
		else
		{
			
			JUDownloadFrontHelperMail::sendEmailByEvent('comment.reply', $commentTable->id);

			
			$logData           = array(
				'user_id'   => $user->id,
				'event'     => 'comment.reply',
				'item_id'   => $commentTable->id,
				'doc_id'    => $docId,
				'value'     => 0,
				'reference' => $commentTable->parent_id,
			);
			$commentSubmitType = 'reply';
		}

		JUDownloadFrontHelperLog::addLog($logData);

		
		$dispatcher = JDispatcher::getInstance();
		JPluginHelper::importPlugin('judownload');

		$dispatcher->trigger('onCommentSubmit', array($commentTable, $commentSubmitType));

		return $commentTable->id;
	}
Example #8
0
	public function addComment()
	{
		
		JSession::checkToken() or die(JText::_('JINVALID_TOKEN'));

		
		$user  = JFactory::getUser();
		$model = $this->getModel();

		
		$rootComment = JUDownloadFrontHelperComment::getRootComment();

		
		$data = $_POST;

		
		$documentId = $data['doc_id'];
		$params     = JUDownloadHelper::getParams(null, $documentId);
		$parentId   = $data['parent_id'];

		
		$model->setSessionCommentForm($documentId);

		
		if (strlen($data['title']) < 6)
		{
			$this->setError(JText::_('COM_JUDOWNLOAD_COMMENT_INVALID_TITLE'));
			$this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $documentId, false));

			return false;
		}

		
		if (strlen($data['guest_name']) < 1)
		{
			$this->setError(JText::_('COM_JUDOWNLOAD_COMMENT_INVALID_NAME'));
			$this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $documentId, false));

			return false;
		}

		
		if (isset($data['guest_email']))
		{
			if (!preg_match('/^[\w\.-]+@[\w\.-]+\.[\w\.-]{2,6}$/', $data['guest_email']))
			{
				$this->setError(JText::_('COM_JUDOWNLOAD_COMMENT_INVALID_EMAIL'));
				$this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $documentId, false));

				return false;
			}
		}

		
		if (isset($data['website']))
		{
			if (!preg_match('/^(https?:\/\/)?([\w\.-]+)\.([\w\.-]{2,6})([\/\w \.-]*)*\/?$/i', $data['website']))
			{
				$this->setError(JText::_('COM_JUDOWNLOAD_COMMENT_INVALID_WEBSITE'));
				$this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $documentId, false));

				return false;
			}
		}

		
		if (isset($data['comment_language']))
		{
			$langArray = JHtml::_('contentlanguage.existing');
			$langKey   = array_keys($langArray);
			array_unshift($langKey, '*');
			if (!in_array($data['comment_language'], $langKey))
			{
				$this->setError(JText::_('COM_JUDOWNLOAD_COMMENT_INVALID_LANGUAGE'));
				$this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $documentId, false));

				return false;
			}
		}

		
		$minCharacter     = $params->get('min_comment_characters', 20);
		$maxCharacter     = $params->get('max_comment_characters', 1000);
		$comment          = $data['comment'];
		$comment          = JUDownloadFrontHelperComment::parseCommentText($comment, $documentId);
		$comment          = strip_tags($comment);
		$commentCharacter = strlen($comment);
		if ($commentCharacter < $minCharacter || $commentCharacter > $maxCharacter)
		{
			$this->setError(JText::_('COM_JUDOWNLOAD_COMMENT_INVALID_COMMENT'));
			$this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $documentId, false));

			return false;
		}

		
		$showCaptcha = JUDownloadFrontHelperPermission::showCaptchaWhenComment($documentId);

		if ($showCaptcha)
		{
			$validCaptcha = JUDownloadFrontHelperCaptcha::checkCaptcha();
			
			if (!$validCaptcha)
			{
				if ($parentId == $rootComment->id)
				{
					$form = '#judl-comment-form';
				}
				else
				{
					$form = '#comment-reply-wrapper-' . $parentId;
				}

				$this->setError(JText::_('COM_JUDOWNLOAD_INVALID_CAPTCHA'));
				$this->setMessage($this->getError(), 'error');
				$this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $documentId . $form, false));

				return false;
			}
		}

		
		if ($user->get('guest'))
		{
			if (!$model->checkNameOfGuest($documentId))
			{
				$this->setError(JText::_('COM_JUDOWNLOAD_YOU_ARE_NOT_AUTHORIZED_TO_COMMENT_ON_THIS_DOCUMENT'));
				$this->setMessage($model->getError(), 'error');
				$this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $documentId, false));

				return false;
			}

			if (!$model->checkEmailOfGuest())
			{
				$this->setMessage($model->getError(), 'error');
				$this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $documentId, false));

				return false;
			}
		}

		if ($parentId == $rootComment->id)
		{
			
			$canComment = JUDownloadFrontHelperPermission::canComment($documentId, $data['guest_email']);
			if (!$canComment)
			{
				$this->setError(JText::_('COM_JUDOWNLOAD_YOU_ARE_NOT_AUTHORIZED_TO_COMMENT_ON_THIS_DOCUMENT'));
				$this->setMessage($this->getError(), 'error');
				$this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $documentId, false));

				return false;
			}
		}
		elseif ($parentId > 0 && $parentId != $rootComment->id)
		{
			
			$canReplyComment = JUDownloadFrontHelperPermission::canReplyComment($documentId, $parentId);
			if (!$canReplyComment)
			{
				$this->setError(JText::_('COM_JUDOWNLOAD_YOU_ARE_NOT_AUTHORIZED_TO_REPLY_THIS_COMMENT'));
				$this->setMessage($this->getError(), 'error');
				$this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $documentId, false));

				return false;
			}
		}
		else
		{
			$this->setError(JText::_('COM_JUDOWNLOAD_INVALID_DATA'));
			$this->setMessage($this->getError(), 'error');
			$this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $documentId, false));

			return false;
		}

		
		$dataValid = array();
		if ($parentId == $rootComment->id)
		{
			$canRateDocument = JUDownloadFrontHelperPermission::canRateDocument($documentId);
			if ($canRateDocument)
			{
				$dataValid = $this->validateCriteria($data, $parentId);
				if (!$dataValid)
				{
					$this->setError(JText::_('COM_JUDOWNLOAD_INVALID_RATING_VALUE'));
					$this->setMessage($this->getError(), 'error');
					$this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $documentId, false));

					return false;
				}
			}
		}

		$requiredPostNames = array('title', 'guest_name', 'guest_email', 'comment', 'parent_id', 'doc_id');

		if ($params->get('website_field_in_comment_form', 0) == 2)
		{
			array_push($requiredPostNames, 'website');
		}

		if ($parentId == $rootComment->id && $params->get('filter_comment_language', 0))
		{
			array_push($requiredPostNames, 'comment_language');
		}

		foreach ($requiredPostNames AS $requiredPostName)
		{
			if (trim($data[$requiredPostName]) == '')
			{
				$this->setError(JText::_('COM_JUDOWNLOAD_INVALID_INPUT_DATA'));
				$this->setMessage($this->getError(), 'error');
				$this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $documentId, false));

				return false;
			}
		}

		$acceptedPostNames = array('title', 'guest_name', 'guest_email', 'language', 'website', 'comment', 'parent_id', 'doc_id', 'subscribe');
		if ($params->get('website_field_in_comment_form', 0) == 2 || $params->get('website_field_in_comment_form', 0) == 1)
		{
			array_push($acceptedPostNames, 'website');
		}

		if ($params->get('filter_comment_language', 0))
		{
			array_push($acceptedPostNames, 'comment_language');
		}

		foreach ($acceptedPostNames AS $acceptedPostName)
		{
			if (isset($data[$acceptedPostName]))
			{
				$dataValid[$acceptedPostName] = $data[$acceptedPostName];
			}
		}

		$newCommentId = $model->saveComment($dataValid);
		if (!$newCommentId)
		{
			$this->setError($model->getError());
			$this->setMessage($this->getError(), 'error');
			$redirectUrl = JRoute::_(JUDownloadHelperRoute::getDocumentRoute($documentId), false);
			$this->setRedirect($redirectUrl);

			return false;
		}

		
		$session                      = JFactory::getSession();
		$timeNow                      = JFactory::getDate()->toSql();
		$timeNowStamp                 = strtotime($timeNow);
		$sessionCommentOnDocumentTime = 'judl-commented-' . $documentId;
		$sessionCommentTime           = 'judl-commented';
		$session->set($sessionCommentOnDocumentTime, $timeNowStamp);
		$session->set($sessionCommentTime, $timeNowStamp);
		
		$session->clear('judownload_commentform_' . $documentId);

		
		$this->setMessage(JText::_('COM_JUDOWNLOAD_ADD_COMMENT_SUCCESSFULLY'));
		$redirectUrl = JRoute::_(JUDownloadHelperRoute::getDocumentRoute($documentId) . '#comment-item-' . $newCommentId, false);
		$this->setRedirect($redirectUrl);

		return true;
	}
Example #9
0
	protected function getListQuery()
	{
		$db    = JFactory::getDbo();
		$query = $db->getQuery(true);
		$query->select('cm.*, r.score');
		$query->from('#__judownload_comments AS cm');
		$query->join('LEFT', '#__judownload_rating AS r ON cm.rating_id = r.id');
		$query->where('cm.published  = 1');
		$query->where('cm.approved  = 1');
		$rootComment = JUDownloadFrontHelperComment::getRootComment();
		$query->where('cm.id != ' . $rootComment->id);
		$params = $this->getState('params');
		if ($params->get('top_comment_level', 'toplevel') == 'toplevel')
		{
			$query->where('cm.level = 1');
		}

		
		$ordering  = $this->getState('list.ordering', 'cm.created');
		$direction = $this->getState('list.direction', 'desc');
		$query->order($ordering . ' ' . $direction);

		return $query;
	}
Example #10
0
    protected function getInput()
    {
        $app = JFactory::getApplication();
        JHtml::_('behavior.modal', 'a.modal');
        $id = $this->form->getValue('id', null, 0);
        $script = array();
        $script[] = 'function commentURL() {
				     	var commenturl = document.id("commenturl").getAttribute("href");
						commenturl = commenturl + "&doc_id="+document.id(jform_doc_id).value;
						document.id("commenturl").setAttribute("href", commenturl);
						return true;
			  		}';
        $script[] = 'function jSelectComment_' . $this->id . '(id, title, level) {
			        	if(id != document.id("' . $this->id . '").value){
							document.id("' . $this->id . '").value = id;
		        			document.id("' . $this->id . '_name").value = title;
		        			level = parseInt(level) + 1
		        			document.id("jform_level").value = level;
				        	
		        		}
				        SqueezeBox.close();
					}';
        JFactory::getDocument()->addScriptDeclaration(implode("\n", $script));
        $html = array();
        $link = 'index.php?option=com_judownload&amp;view=comments&amp;layout=modal&amp;tmpl=component&amp;id=' . $id . '&amp;function=jSelectComment_' . $this->id;
        $db = JFactory::getDbo();
        $query = $db->getQuery(true);
        $query->select('title');
        $query->from('#__judownload_comments');
        $query->where('id = ' . (int) $this->value);
        $db->setQuery($query);
        $title = $db->loadResult();
        if (empty($title)) {
            $rootComment = JUDownloadFrontHelperComment::getRootComment();
            $title = $rootComment->title;
            $value = $rootComment->id;
        } else {
            $value = $this->value;
        }
        $title = htmlspecialchars($title, ENT_QUOTES, 'UTF-8');
        $joomla_version_arr = explode(".", JVERSION);
        $priVersion = $joomla_version_arr[0];
        if ($priVersion == 3) {
            $html[] = '<span class="' . ($app->isAdmin() ? 'input-append' : '') . '">';
            $html[] = '<input type="text" id="' . $this->id . '_name" value="' . $title . '" disabled="disabled" size="' . $this->element['size'] . '" />';
            if ($app->isAdmin()) {
                $html[] = '<a class="modal btn hasTooltip" title="' . JHtml::tooltipText('COM_JUDOWNLOAD_SELECT_COMMENT') . '"  href="' . $link . '&amp;' . JSession::getFormToken() . '=1" rel="{handler: \'iframe\', size: {x: 800, y: 450}}"><i class="icon-list"></i> ' . JText::_('COM_JUDOWNLOAD_SELECT') . '</a>';
            }
            $html[] = '</span>';
        } else {
            $html[] = '<div class="fltlft">';
            $html[] = '<input type="text" id="' . $this->id . '_name" value="' . $title . '" disabled="disabled" size="' . $this->element['size'] . '" />';
            $html[] = '</div>';
            if ($app->isAdmin()) {
                $html[] = '<div class="button2-left">';
                $html[] = '<div class="blank">';
                $html[] = '<a onclick="commentURL();" id="commenturl" class="modal" title="' . JText::_('COM_JUDOWNLOAD_SELECT_COMMENT') . '"  href="' . $link . '&amp;' . JSession::getFormToken() . '=1" rel="{handler: \'iframe\', size: {x: 800, y: 450}}">' . JText::_('COM_JUDOWNLOAD_SELECT_COMMENT') . '</a>';
                $html[] = '</div>';
                $html[] = '</div>';
            }
        }
        $class = '';
        if ($this->required) {
            $class = ' class="required modal-value"';
        }
        $html[] = '<input type="hidden" id="' . $this->id . '"' . $class . ' name="' . $this->name . '" value="' . $value . '" />';
        return implode("\n", $html);
    }