Example #1
0
 public function display($tpl = null)
 {
     if (!JUDownloadHelper::hasMultiRating()) {
         JError::raiseError(500, JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'));
         return false;
     }
     if (count($errors = $this->get('Errors'))) {
         JError::raiseError(500, implode('<br />', $errors));
         return false;
     }
     $this->form = $this->get('Form');
     $this->item = $this->get('Item');
     $this->script = $this->get('Script');
     $this->canDo = JUDownloadHelper::getActions('com_judownload');
     $this->addToolBar();
     parent::display($tpl);
     $this->setDocument();
 }
Example #2
0
 protected function getOptions()
 {
     $options = array();
     foreach ($this->element->children() as $option) {
         if ($option->getName() != 'option') {
             continue;
         }
         $disabled = $option['disabled'] == 'true';
         if (!$disabled && $option['value'] == 'bycriteria' && !JUDownloadHelper::hasMultiRating()) {
             $disabled = true;
         }
         $tmp = JHtml::_('select.option', (string) $option['value'], JText::alt(trim((string) $option), preg_replace('/[^a-zA-Z0-9_\\-]/', '_', $this->fieldname)), 'value', 'text', (string) $disabled);
         $tmp->class = (string) $option['class'];
         $tmp->onclick = (string) $option['onclick'];
         $options[] = $tmp;
     }
     reset($options);
     return $options;
 }
Example #3
0
 public function display($tpl = null)
 {
     if (!JUDownloadHelper::hasMultiRating()) {
         JError::raiseError(500, JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'));
         return false;
     }
     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("criteria.edit");
     $this->groupCanDoDelete = JUDownloadHelper::checkGroupPermission("criterias.delete");
     $this->addToolBar();
     if (JUDownloadHelper::isJoomla3x()) {
         $this->filterForm = $this->get('FilterForm');
         $this->activeFilters = $this->get('ActiveFilters');
     }
     parent::display($tpl);
     $this->setDocument();
 }
Example #4
0
                                <a href="<?php 
            echo JRoute::_('index.php?option=com_judownload&amp;task=fieldgroup.edit&amp;id=' . $item->fieldgroup_id);
            ?>
">
                                    <?php 
            echo $item->field_group_title;
            ?>
                                </a>
                            <?php 
        } else {
            echo $item->field_group_title;
        }
        ?>
                        </td>
						<?php 
        if (JUDownloadHelper::hasMultiRating()) {
            ?>
							<td>
								<?php 
            if ($item->selected_criteriagroup > 0) {
                ?>
									<a href="<?php 
                echo JRoute::_('index.php?option=com_judownload&amp;task=criteriagroup.edit&amp;id=' . $item->selected_criteriagroup);
                ?>
">
										<?php 
                echo $item->selected_criteriagroup_title;
                ?>
									</a>
								<?php 
            } else {
Example #5
0
    ?>
/administrator/components/com_judownload/assets/img/icon/criteria.png" />
					<span><?php 
    echo JText::_('COM_JUDOWNLOAD_DASHBOARD_CRITERIAS');
    ?>
</span>
				</a>
			</div>
		</div>
	</div>
<?php 
}
?>

<?php 
if (JUDownloadHelper::checkGroupPermission(null, "criteriagroups") && JUDownloadHelper::hasMultiRating()) {
    ?>
	<div class="cpanel">
		<div class="icon-wrapper">
			<div class="icon">
				<a href="<?php 
    echo JRoute::_('index.php?option=com_judownload&amp;view=criteriagroups');
    ?>
">
					<img alt="<?php 
    echo JText::_('COM_JUDOWNLOAD_DASHBOARD_CRITERIA_GROUPS');
    ?>
" src="<?php 
    echo JUri::root(true);
    ?>
/administrator/components/com_judownload/assets/img/icon/criteria-group.png" />
Example #6
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__);
		}
	}
Example #7
0
 public function copyDocuments($document_id_arr, $tocat_id_arr, $copy_option_arr, $tmp_doc = false, &$filesStoreMap = array(), &$versionsStoreMap = array(), &$fieldsData = array())
 {
     $dispatcher = JDispatcher::getInstance();
     JTable::addIncludePath(JPATH_ADMINISTRATOR . "/components/com_judownload/tables");
     $db = JFactory::getDbo();
     $user = JFactory::getUser();
     $catTable = JTable::getInstance("Category", "JUDownloadTable");
     $table = $this->getTable();
     if (empty($document_id_arr)) {
         return false;
     }
     if (empty($tocat_id_arr)) {
         return false;
     }
     set_time_limit(0);
     $assetTable = JTable::getInstance('Asset', 'JTable');
     $fileTable = JTable::getInstance("File", "JUDownloadTable");
     $commentTable = JTable::getInstance("Comment", "JUDownloadTable");
     $reportTable = JTable::getInstance("Report", "JUDownloadTable");
     $subscriptionTable = JTable::getInstance("Subscription", "JUDownloadTable");
     $changelogTable = JTable::getInstance("Changelog", "JUDownloadTable");
     $logTable = JTable::getInstance("Log", "JUDownloadTable");
     $versionTable = JTable::getInstance("Version", "JUDownloadTable");
     $total_copied_documents = 0;
     foreach ($tocat_id_arr as $tocat_id) {
         $catTable->reset();
         if (!$catTable->load($tocat_id)) {
             continue;
         }
         $assetName = 'com_judownload.category.' . (int) $tocat_id;
         $canDoCreate = $user->authorise('judl.document.create', $assetName);
         if (!$canDoCreate) {
             JError::raiseWarning(401, JText::sprintf('COM_JUDOWNLOAD_CAN_NOT_CREATE_DOCUMENT_IN_THIS_CATEGORY', $catTable->title));
             continue;
         }
         foreach ($document_id_arr as $doc_id) {
             $table->reset();
             if (!$table->load($doc_id)) {
                 continue;
             }
             $oldTable = $table;
             $table->id = 0;
             $table->cat_id = $tocat_id;
             do {
                 $query = $db->getQuery(true);
                 $query->SELECT('COUNT(*)');
                 $query->FROM('#__judownload_documents AS d');
                 $query->JOIN('', '#__judownload_documents_xref AS dxref ON dxref.doc_id = d.id');
                 $query->JOIN('', '#__judownload_categories AS c ON dxref.cat_id = c.id');
                 $query->WHERE('c.id = ' . $tocat_id);
                 $query->WHERE('d.alias = "' . $table->alias . '"');
                 $db->setQuery($query);
                 $sameAliasDocument = $db->loadResult();
                 if ($sameAliasDocument) {
                     $table->title = JString::increment($table->title);
                     $table->alias = JApplication::stringURLSafe(JString::increment($table->alias, 'dash'));
                 }
             } while ($sameAliasDocument);
             if ($table->style_id == -1) {
                 $old_cat_id = JUDownloadFrontHelperCategory::getMainCategoryId($doc_id);
                 if ($old_cat_id != $tocat_id) {
                     $oldTemplateStyleObject = JUDownloadFrontHelperTemplate::getTemplateStyleOfCategory($old_cat_id);
                     $newTemplateStyleObject = JUDownloadFrontHelperTemplate::getTemplateStyleOfCategory($tocat_id);
                     if ($oldTemplateStyleObject->template_id != $newTemplateStyleObject->template_id) {
                         if (in_array('keep_template_params', $copy_option_arr) && $tmp_doc == false) {
                             $table->style_id = $oldTemplateStyleObject->style_id;
                         } else {
                             if ($tmp_doc == false) {
                                 $table->template_params = '';
                             }
                         }
                     }
                 }
             }
             if (!in_array('copy_downloads', $copy_option_arr) && $tmp_doc == false) {
                 $table->downloads = 0;
             }
             if (!in_array('copy_rates', $copy_option_arr) && $tmp_doc == false) {
                 $table->rating = 0;
                 $table->total_votes = 0;
             }
             if (!in_array('copy_hits', $copy_option_arr) && $tmp_doc == false) {
                 $table->hits = 0;
             }
             if (in_array('copy_permission', $copy_option_arr)) {
                 $assetTable->reset();
                 if ($assetTable->loadByName('com_judownload.document.' . $doc_id)) {
                     $table->setRules($assetTable->rules);
                 } else {
                     $table->setRules('{}');
                 }
             } else {
                 $table->setRules('{}');
             }
             if (!$table->check()) {
                 continue;
             }
             $result = $dispatcher->trigger('onContentBeforeCopy', array($this->option . '.' . $this->name, $table, $oldTable, $copy_option_arr));
             if (in_array(false, $result, true)) {
                 $this->setError($table->getError());
                 return false;
             }
             if ($table->store()) {
                 $table->checkIn();
                 $total_copied_documents++;
             } else {
                 continue;
             }
             $newDocId = $table->id;
             if ($table->icon) {
                 $ori_icon_name = $table->icon;
                 $new_icon_name = $newDocId . substr($ori_icon_name, strpos($ori_icon_name, '_'));
                 $query = "UPDATE #__judownload_documents SET icon = '" . $new_icon_name . "' WHERE id=" . $newDocId;
                 $db->setQuery($query);
                 $db->execute();
                 $icon_directory = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("document_icon_directory", "media/com_judownload/images/document/");
                 if (JFile::exists($icon_directory . $ori_icon_name)) {
                     JFile::copy($icon_directory . $ori_icon_name, $icon_directory . $new_icon_name);
                 }
                 if (JFile::exists($icon_directory . "original/" . $ori_icon_name)) {
                     JFile::copy($icon_directory . "original/" . $ori_icon_name, $icon_directory . "original/" . $new_icon_name);
                 }
             }
             $query = "INSERT INTO #__judownload_documents_xref (doc_id, cat_id, main) VALUES({$newDocId}, {$tocat_id}, 1)";
             $db->setQuery($query);
             $db->execute();
             $query = "SELECT * FROM #__judownload_tags_xref WHERE doc_id=" . $doc_id . " ORDER BY ordering ASC";
             $db->setQuery($query);
             $tags = $db->loadObjectList();
             if (!empty($tags)) {
                 foreach ($tags as $tag) {
                     $query = "INSERT INTO #__judownload_tags_xref (tag_id, doc_id, ordering) VALUES (" . $tag->tag_id . ", " . $newDocId . ", " . $tag->ordering . ")";
                     $db->setQuery($query);
                     $db->execute();
                 }
             }
             $ori_fieldgroup_id = JUDownloadHelper::getFieldGroupIdByDocId($doc_id);
             $copy_extra_fields = in_array("copy_extra_fields", $copy_option_arr);
             if ($copy_extra_fields) {
                 $copy_extra_fields = $ori_fieldgroup_id == $catTable->fieldgroup_id ? true : false;
             }
             $query = $db->getQuery(true);
             $query->select("field.*");
             $query->from("#__judownload_fields AS field");
             $query->select("plg.folder");
             $query->join("", "#__judownload_plugins AS plg ON field.plugin_id = plg.id");
             if ($copy_extra_fields && $ori_fieldgroup_id) {
                 $query->where("field.group_id IN (1, {$ori_fieldgroup_id})");
             } else {
                 $query->where("field.group_id = 1");
             }
             $db->setQuery($query);
             $fields = $db->loadObjectList();
             foreach ($fields as $field) {
                 $fieldObj = JUDownloadFrontHelperField::getField($field, $doc_id);
                 $fieldObj->onCopy($newDocId, $fieldsData);
             }
             if (in_array('copy_files', $copy_option_arr)) {
                 $query = "SELECT * FROM #__judownload_files WHERE doc_id = " . $doc_id;
                 $db->setQuery($query);
                 $files = $db->loadObjectList();
                 if ($files) {
                     foreach ($files as $file) {
                         $fileTable->reset();
                         if ($fileTable->bind($file) && $fileTable->check()) {
                             $fileTable->id = 0;
                             $fileTable->doc_id = $newDocId;
                             if ($fileTable->store()) {
                                 $filesStoreMap[$file->id] = $fileTable->id;
                                 $query = "SELECT id FROM #__judownload_versions WHERE file_id = " . $file->id;
                                 $db->setQuery($query);
                                 $oldFileVersionIds = $db->loadColumn();
                                 foreach ($oldFileVersionIds as $oldFileVersionId) {
                                     if ($versionTable->load($oldFileVersionId)) {
                                         $versionTable->id = 0;
                                         $versionTable->doc_id = $newDocId;
                                         $versionTable->file_id = $fileTable->id;
                                         $versionTable->store();
                                         $versionsStoreMap[$oldFileVersionId] = $versionTable->id;
                                     }
                                 }
                             }
                         } else {
                             continue;
                         }
                     }
                 }
                 $file_directory = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("file_directory", "media/com_judownload/files/");
                 $ori_directory = JPath::clean($file_directory . $doc_id);
                 $new_directory = JPath::clean($file_directory . $newDocId);
                 if (JFolder::exists($ori_directory)) {
                     JFolder::copy($ori_directory, $new_directory);
                 }
             }
             $query = "SELECT id FROM #__judownload_versions WHERE doc_id = " . $doc_id . " AND file_id = 0";
             $db->setQuery($query);
             $oldDocVersionIds = $db->loadColumn();
             foreach ($oldDocVersionIds as $oldDocVersionId) {
                 if ($versionTable->load($oldDocVersionId)) {
                     $versionTable->id = 0;
                     $versionTable->doc_id = $newDocId;
                     $versionTable->store();
                     $versionsStoreMap[$oldDocVersionId] = $versionTable->id;
                 }
             }
             if (in_array('copy_changelogs', $copy_option_arr)) {
                 $query = "SELECT * FROM #__judownload_changelogs WHERE `doc_id` = {$doc_id}";
                 $db->setQuery($query);
                 $changelogs = $db->loadObjectList();
                 if ($changelogs) {
                     foreach ($changelogs as $changelog) {
                         $changelogTable->reset();
                         if ($changelogTable->bind($changelog) && $changelogTable->check()) {
                             $changelogTable->id = 0;
                             $changelogTable->doc_id = $newDocId;
                             $changelogTable->store();
                         } else {
                             continue;
                         }
                     }
                 }
             }
             if (in_array('copy_related_documents', $copy_option_arr)) {
                 $query = "INSERT INTO `#__judownload_documents_relations` (doc_id, doc_id_related, ordering) SELECT {$newDocId}, doc_id_related, ordering FROM `#__judownload_documents_relations` WHERE doc_id = {$doc_id}";
                 $db->setQuery($query);
                 $db->execute();
             }
             if (in_array('copy_rates', $copy_option_arr)) {
                 $ratingMapping = array();
                 $query = "SELECT * FROM #__judownload_rating WHERE doc_id = {$doc_id}";
                 $db->setQuery($query);
                 $ratings = $db->loadObjectList();
                 if (count($ratings)) {
                     $criteriagroup_id = JUDownloadHelper::getCriteriaGroupIdByDocId($doc_id);
                     foreach ($ratings as $rating) {
                         $oldRatingId = $rating->id;
                         $rating->id = 0;
                         $rating->doc_id = $newDocId;
                         if ($db->insertObject('#__judownload_rating', $rating, 'id')) {
                             if (JUDownloadHelper::hasMultiRating() && $criteriagroup_id && $criteriagroup_id == $catTable->criteriagroup_id) {
                                 JUDownloadMultiRating::copyCriteriaValue($rating->id, $oldRatingId);
                             }
                             $ratingMapping[$oldRatingId] = $rating->id;
                         }
                     }
                 }
             }
             if (in_array('copy_comments', $copy_option_arr)) {
                 $query = "SELECT id FROM #__judownload_comments WHERE doc_id=" . $doc_id . " AND parent_id = 1";
                 $db->setQuery($query);
                 $commentIds = $db->loadColumn();
                 $commentMapping = array();
                 while (!empty($commentIds)) {
                     $commentId = array_shift($commentIds);
                     $query = "SELECT id FROM #__judownload_comments WHERE doc_id=" . $doc_id . " AND parent_id = {$commentId}";
                     $db->setQuery($query);
                     $_commentIds = $db->loadColumn();
                     foreach ($_commentIds as $_commentId) {
                         if (!in_array($_commentId, $commentIds)) {
                             array_push($commentIds, $_commentId);
                         }
                     }
                     $commentTable->load($commentId, true);
                     $commentTable->id = 0;
                     $commentTable->doc_id = $newDocId;
                     $commentTable->parent_id = isset($commentMapping[$commentTable->parent_id]) ? $commentMapping[$commentTable->parent_id] : 0;
                     if (in_array('copy_rates', $copy_option_arr)) {
                         $commentTable->rating_id = isset($ratingMapping[$commentTable->rating_id]) ? $ratingMapping[$commentTable->rating_id] : 0;
                     }
                     $commentTable->store();
                     $new_comment_id = $commentTable->id;
                     $commentMapping[$commentId] = $new_comment_id;
                     $query = "SELECT * FROM #__judownload_reports WHERE `item_id` = {$commentId} AND `type` = 'comment'";
                     $db->setQuery($query);
                     $reports = $db->loadObjectList();
                     if ($reports) {
                         foreach ($reports as $report) {
                             $reportTable->reset();
                             if ($reportTable->bind($report) && $reportTable->check()) {
                                 $reportTable->id = 0;
                                 $reportTable->item_id = $new_comment_id;
                                 $reportTable->store();
                             } else {
                                 continue;
                             }
                         }
                     }
                     $query = "SELECT * FROM #__judownload_subscriptions WHERE `item_id` = {$commentId} AND `type` = 'comment'";
                     $db->setQuery($query);
                     $subscriptions = $db->loadObjectList();
                     if ($subscriptions) {
                         foreach ($subscriptions as $subscription) {
                             $subscriptionTable->reset();
                             if ($subscriptionTable->bind($subscription) && $subscriptionTable->check()) {
                                 $subscriptionTable->id = 0;
                                 $subscriptionTable->item_id = $new_comment_id;
                                 $subscriptionTable->store();
                             } else {
                                 continue;
                             }
                         }
                     }
                 }
             }
             if (in_array('copy_reports', $copy_option_arr)) {
                 $query = "SELECT * FROM #__judownload_reports WHERE `item_id` = {$doc_id} AND `type` = 'document'";
                 $db->setQuery($query);
                 $reports = $db->loadObjectList();
                 if ($reports) {
                     foreach ($reports as $report) {
                         $reportTable->reset();
                         if ($reportTable->bind($report) && $reportTable->check()) {
                             $reportTable->id = 0;
                             $reportTable->item_id = $newDocId;
                             $reportTable->store();
                         } else {
                             continue;
                         }
                     }
                 }
             }
             if (in_array('copy_subscriptions', $copy_option_arr)) {
                 $query = "SELECT * FROM #__judownload_subscriptions WHERE `item_id` = {$doc_id} AND `type` = 'document'";
                 $db->setQuery($query);
                 $subscriptions = $db->loadObjectList();
                 if ($subscriptions) {
                     foreach ($subscriptions as $subscription) {
                         $subscriptionTable->reset();
                         if ($subscriptionTable->bind($subscription) && $subscriptionTable->check()) {
                             $subscriptionTable->id = 0;
                             $subscriptionTable->item_id = $newDocId;
                             $subscriptionTable->store();
                         } else {
                             continue;
                         }
                     }
                 }
             }
             if (in_array('copy_logs', $copy_option_arr)) {
                 $query = "SELECT * FROM #__judownload_logs WHERE (`doc_id` = {$doc_id})";
                 $db->setQuery($query);
                 $logs = $db->loadObjectList();
                 if ($logs) {
                     foreach ($logs as $log) {
                         $logTable->reset();
                         if ($logTable->bind($log) && $logTable->check()) {
                             $logTable->id = 0;
                             $logTable->item_id = $newDocId;
                             $logTable->doc_id = $newDocId;
                             $logTable->store();
                         } else {
                             continue;
                         }
                     }
                 }
             }
             if ($tmp_doc) {
                 return $newDocId;
             }
             $this->cleanCache();
             $dispatcher->trigger('onContentAfterCopy', array($this->option . '.' . $this->name, $table, $oldTable, $copy_option_arr));
         }
     }
     return $total_copied_documents;
 }
<?php
/**
 * ------------------------------------------------------------------------
 * JUDownload for Joomla 2.5, 3.x
 * ------------------------------------------------------------------------
 *
 * @copyright      Copyright (C) 2010-2015 JoomUltra Co., Ltd. All Rights Reserved.
 * @license        GNU General Public License version 2 or later; see LICENSE.txt
 * @author         JoomUltra Co., Ltd
 * @website        http://www.joomultra.com
 * @----------------------------------------------------------------------@
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

if (JUDownloadHelper::hasMultiRating() && isset($this->item->fields['rating']) && $this->item->fields['rating']->canView())
{
	echo $this->item->fields['rating']->getDisplayPrefixText() . ' ' . $this->item->fields['rating']->getOutput(array("view" => "details", "template" => $this->template, "type" => "multi_rating")) . ' ' . $this->item->fields['rating']->getDisplaySuffixText();
}
?>
Example #9
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 #10
0
	public function multiRating()
	{
		
		JSession::checkToken() or die(JText::_('JINVALID_TOKEN'));

		
		$app        = JFactory::getApplication();
		$data       = $app->input->getArray($_POST);
		$documentId = $data['doc_id'];
		$params     = JUDownloadHelper::getParams(null, $documentId);

		
		$canRateDocument = JUDownloadFrontHelperPermission::canRateDocument($documentId);

		JUDownloadHelper::obCleanData();

		if (!$canRateDocument)
		{
			echo JText::_('COM_JUDOWNLOAD_YOU_CAN_NOT_VOTE_ON_THIS_DOCUMENT');
			exit;
		}

		if (!JUDownloadHelper::hasMultiRating())
		{
			echo JText::_('COM_JUDOWNLOAD_MULTI_RATING_HAS_BEEN_DISABLED_PLEASE_CONTACT_ADMINISTRATOR');
			exit;
		}

		$inputCookie = $app->input->cookie;

		$ratingInterval = $params->get('rating_interval', 86400);
		$user           = JFactory::getUser();
		$timeNow        = JFactory::getDate()->toSql();
		$timeNowStamp   = strtotime($timeNow);
		if ($user->get('guest'))
		{
			
			$lastTimeRated = $inputCookie->get('judl-document-rated-' . $documentId, null);
			if ($lastTimeRated != null)
			{
				if ($timeNowStamp > $lastTimeRated)
				{
					if ($timeNowStamp - $lastTimeRated < $ratingInterval)
					{
						echo JText::_('COM_JUDOWNLOAD_YOU_ARE_ALREADY_VOTED_ON_THIS_DOCUMENT');
						exit;
					}
				}
			}
		}
		else
		{
			$lastTimeRated = JUDownloadFrontHelperRating::getLastTimeVoteDocumentOfUser($user->id, $documentId);
			if (!$lastTimeRated)
			{
				$lastTimeRated = 0;
			}
			$lastTimeRated = strtotime($lastTimeRated);
			if ($lastTimeRated > 0)
			{
				if ($timeNowStamp > $lastTimeRated)
				{
					if ($timeNowStamp - $lastTimeRated < $ratingInterval)
					{
						
						echo JText::_('COM_JUDOWNLOAD_YOU_ARE_ALREADY_VOTED_ON_THIS_DOCUMENT');
						exit;
					}
				}
			}
		}

		
		$dataValid     = array();
		$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]);
					}
				}
			}
		}
		else
		{
			echo JText::_('COM_JUDOWNLOAD_VOTING_FAILED_PLEASE_CONTACT_ADMINISTRATOR');
			exit;
		}

		$model = $this->getModel();
		JUDownloadHelper::obCleanData();
		if ($model->saveRating($dataValid, $documentId, $criteriaArray))
		{
			echo JText::_('COM_JUDOWNLOAD_THANK_YOU_FOR_VOTING');

		}
		else
		{
			echo JText::_('COM_JUDOWNLOAD_VOTING_FAILED_PLEASE_CONTACT_ADMINISTRATOR');
		}
		exit;
	}
Example #11
0
	public static function canRateDocument($documentId)
	{
		$documentObject = JUDownloadHelper::getDocumentById($documentId);
		if (!is_object($documentObject))
		{
			return false;
		}

		$params = JUDownloadHelper::getParams(null, $documentId);
		if (!$params->get('enable_document_rate', 1))
		{
			return false;
		}

		$userCanViewDocument = JUDownloadFrontHelperPermission::userCanDoDocument($documentId, true);
		if (!$userCanViewDocument)
		{
			return false;
		}

		$ratingField = new JUDownloadFieldCore_rating();
		if (!$ratingField->canView())
		{
			return false;
		}

		$user            = JFactory::getUser();
		$criteriaGroupId = JUDownloadFrontHelperCriteria::getCriteriaGroupIdByCategoryId($documentObject->cat_id);
		if ($criteriaGroupId == 0 || !JUDownloadHelper::hasMultiRating())
		{
			$assetName = 'com_judownload.category.' . $documentObject->cat_id;
			
			if ($user->authorise('judl.single.rate', $assetName) || (JUDownloadFrontHelperPermission::canDownloadDocument($documentId) && $params->get('can_download_can_rate', 0)))
			{
				if ($user->authorise('judl.single.rate.many_times', $assetName))
				{
					return true;
				}
				else
				{
					
					if ($user->get('guest'))
					{
						$session = JFactory::getSession();
						if (!$session->has('judl-document-rated-' . $documentId))
						{
							return true;
						}
					}
					
					else
					{
						$totalVoteTimes = JUDownloadFrontHelperRating::getTotalDocumentVotesOfUser($user->id, $documentId);
						if ($totalVoteTimes == 0)
						{
							return true;
						}
					}
				}
			}
		}
		else
		{
			$assetName = 'com_judownload.criteriagroup.' . $criteriaGroupId;
			
			if ($user->authorise('judl.criteria.rate', $assetName) || (JUDownloadFrontHelperPermission::canDownloadDocument($documentId) && $params->get('can_download_can_rate', 0)))
			{
				if ($user->authorise('judl.criteria.rate.many_times', $assetName))
				{
					return true;
				}
				else
				{
					
					if ($user->get('guest'))
					{
						$session = JFactory::getSession();
						if (!$session->has('judl-document-rated-' . $documentId))
						{
							return true;
						}
					}
					
					else
					{
						$totalVoteTimes = JUDownloadFrontHelperRating::getTotalDocumentVotesOfUser($user->id, $documentId);
						if ($totalVoteTimes == 0)
						{
							return true;
						}
					}
				}
			}
		}

		return false;
	}