Пример #1
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;
	}
Пример #2
0
	public function getOutput($options = array())
	{
		if (!$this->isPublished())
		{
			return "";
		}

		$options = new JRegistry($options);

		$this->initMultipleRatingField();

		
		$this->loadDefaultAssets();

		if ($this->doc->cat_id)
		{
			$this->criteriaGroupId = JUDownloadFrontHelperCriteria::getCriteriaGroupIdByCategoryId($this->doc->cat_id);
		}

		if (JUDownloadHelper::hasMultiRating())
		{
			if ($this->criteriaGroupId)
			{
				$this->criteriaObjectList = JUDownloadFrontHelperCriteria::getCriteriasByCatId($this->doc->cat_id);
			}
		}

		
		$this->selectedStar = round($this->doc->rating * $this->totalStars / 10, 2);

		
		if ($this->isDetailsView($options))
		{
			$this->canRateDocument = JUDownloadFrontHelperPermission::canRateDocument($this->doc_id);

			$document = JFactory::getDocument();

			
			$document->addStyleSheet(JUri::root(true) . "/components/com_judownload/assets/css/jquery.rating.css");
			$document->addScript(JUri::root(true) . "/components/com_judownload/assets/js/jquery.MetaData.js");
			$document->addScript(JUri::root(true) . "/components/com_judownload/assets/js/jquery.rating.js");

			$singleRatingScript = '
				jQuery(document).ready(function ($) {
					$(".judl-single-rating").rating({
						callback: function (value) {
									var str = $(this).attr("name");
									var patt = /^judl-document-rating-result-(.*)$/i;
							var result = str.match(patt);
							var documentId = result[1];
							var ratingValue = $(this).val();
							var objectDocument = {};
							var token = $("#judl-single-rating-token").attr("name");
							objectDocument.doc_id = documentId;
							objectDocument.ratingValue = ratingValue;
							if ($.isNumeric(documentId) && (ratingValue > 0 && ratingValue <= 10)) {
								$.ajax({
									type: "POST",
									url : "index.php?option=com_judownload&task=document.singleRating&" + token + "=1",
									data: objectDocument
								}).done(function (msg) {
									alert(msg);
									
								});
							}
						}
					});
				});';

			if ($this->canRateDocument)
			{
				$document->addScriptDeclaration($singleRatingScript);
			}
		}

		if (is_object($this->multiRating))
		{
			return $this->multiRating->getOutput($options);
		}
		else
		{
			$this->setVariable('options', $options);
			$this->setVariable('className', __CLASS__);

			return $this->fetch('output.php', __CLASS__);
		}
	}
Пример #3
0
	public function validateCriteria($data)
	{
		$documentId = $data['doc_id'];
		$params     = JUDownloadHelper::getParams(null, $documentId);

		
		$dataValid       = array();
		$canRateDocument = JUDownloadFrontHelperPermission::canRateDocument($documentId);
		if ($canRateDocument && $params->get('enable_doc_rate_in_comment_form', 1))
		{
			$mainCatId     = JUDownloadFrontHelperCategory::getMainCategoryId($documentId);
			$criteriaArray = JUDownloadFrontHelperCriteria::getCriteriasByCatId($mainCatId);
			$postCriteria  = $data['criteria'];
			if (count($criteriaArray) > 0)
			{
				foreach ($criteriaArray AS $key => $criteria)
				{
					if ($criteria->required)
					{
						if (isset($postCriteria[$criteria->id]) && $postCriteria[$criteria->id] > 0 && $postCriteria[$criteria->id] <= 10)
						{
							$criteria->value = $postCriteria[$criteria->id];
						}
						else
						{
							
							echo JText::_('Invalid Field ' . $criteria->title);
							exit;
						}
					}
					else
					{
						if (isset($postCriteria[$criteria->id]) && $postCriteria[$criteria->id] > 0 && $postCriteria[$criteria->id] <= 10)
						{
							$criteria->value = $postCriteria[$criteria->id];
						}
						else
						{
							unset($criteriaArray[$key]);
						}
					}
				}

				$dataValid['criteria_array'] = $criteriaArray;
			}
			else
			{
				
				if ($params->get('require_doc_rate_in_comment_form', 1))
				{
					if (($data['judl_comment_rating_single'] <= 0) && ($data['judl_comment_rating_single'] > 10))
					{
						return false;
					}

					$dataValid['ratingValue'] = $data['judl_comment_rating_single'];
				}
			}
		}

		return $dataValid;
	}