Ejemplo n.º 1
0
	public static function loadLanguageForTopLevelCat()
	{
		$app  = JFactory::getApplication();
		$view = $app->input->getString('view', '');
		$id   = $app->input->getInt('id', 0);

		if (isset($view))
		{
			switch ($view)
			{
				case 'category':
					$topLevelCats = JUDownloadHelper::getCatsByLevel(1, $id);
					break;

				case 'document':
					$catId        = JUDownloadFrontHelperCategory::getMainCategoryId($id);
					$topLevelCats = JUDownloadHelper::getCatsByLevel(1, $catId);
					break;
			}

			if (!empty($topLevelCats))
			{
				$topLevelCat = $topLevelCats[0];
				if ($view == 'category' || $view == 'document')
				{
					JUDownloadFrontHelperLanguage::loadLanguageFile('com_judownload_' . $topLevelCat->id, JPATH_SITE);
				}
			}
		}

		return;
	}
Ejemplo n.º 2
0
	public static function findItemIdOfDocument($id)
	{
		$catId = JUDownloadFrontHelperCategory::getMainCategoryId($id);

		return self::findItemIdOfCategory($catId);
	}
Ejemplo n.º 3
0
	public static function getCurrentCatId()
	{
		$app    = JFactory::getApplication();
		$option = $app->input->getString('option', '');
		$view   = $app->input->getString('view', '');
		$catId  = JUDownloadFrontHelperCategory::getRootCategory()->id;
		if ($option == 'com_judownload' && $view)
		{
			if ($view == 'document')
			{
				$docId = $app->input->getInt('id', 0);
				if ($docId > 0)
				{
					$catId = JUDownloadFrontHelperCategory::getMainCategoryId($docId);
				}
			}
			elseif ($view == 'category' || $view == 'categories')
			{
				$catId = $app->input->getInt('id', 0);
			}
		}

		return $catId;
	}
Ejemplo n.º 4
0
	public function setSessionCommentForm($documentId)
	{
		$session              = JFactory::getSession();
		$app                  = JFactory::getApplication();
		$criteriaRatingValues = array('judl-comment-rating-single' => $app->input->getFloat('judl_comment_rating_single', 0));
		$mainCatId            = JUDownloadFrontHelperCategory::getMainCategoryId($documentId);
		$criteriaArray        = JUDownloadFrontHelperCriteria::getCriteriasByCatId($mainCatId);

		if (count($criteriaArray))
		{
			foreach ($criteriaArray AS $value)
			{
				$criteriaRatingValues[$value->id] = $app->input->getString('criteria-' . $value->id, '');
			}
		}

		$commentForm                     = array();
		$commentForm['rating']           = $criteriaRatingValues;
		$commentForm['title']            = $app->input->getString('title', '');
		$commentForm['guest_name']       = $app->input->getString('guest_name', '');
		$commentForm['guest_email']      = $app->input->getString('guest_email', '');
		$commentForm['comment']          = $app->input->getString('comment', '');
		$commentForm['parent_id']        = $app->input->getInt('parent_id', '');
		$commentForm['comment_language'] = $app->input->getString('comment_language', '*');

		if ($app->input->getString('website', ''))
		{
			$commentForm['website'] = $app->input->getString('website', '');
		}
		
		$session->set('judownload_commentform_' . $documentId, $commentForm);
	}
Ejemplo n.º 5
0
	public function delete()
	{
		
		JSession::checkToken('get') or die(JText::_('JINVALID_TOKEN'));

		
		$cid = JFactory::getApplication()->input->get('id', array(), 'array');

		if (!is_array($cid) || count($cid) < 1)
		{
			JError::raiseWarning(500, JText::_('COM_JUDOWNLOAD_NO_ITEM_SELECTED'));
			$this->setRedirect($this->getReturnPage());
		}
		else
		{
			
			$model = $this->getModel();

			
			jimport('joomla.utilities.arrayhelper');
			JArrayHelper::toInteger($cid);

			
			if ($model->delete($cid))
			{
				$this->setMessage(JText::plural($this->text_prefix . '_N_ITEMS_DELETED', count($cid)));
			}
			else
			{
				$this->setMessage($model->getError());
			}

			$isDocumentPublished = JUDownloadFrontHelperDocument::isDocumentPublished($cid[0]);
			if ($isDocumentPublished)
			{
				$mainCategoryId = JUDownloadFrontHelperCategory::getMainCategoryId($cid[0]);
				$this->setRedirect(JRoute::_(JUDownloadHelperRoute::getCategoryRoute($mainCategoryId), false));
			}
			else
			{
				$this->setRedirect($this->getReturnPage());
			}
		}
	}
Ejemplo n.º 6
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;
	}
Ejemplo n.º 7
0
 public function getExportData($exportColumns, $filter)
 {
     $db = JFactory::getDbo();
     $exportData = array();
     $selectFields = $this->getDocumentTableFieldsName();
     foreach ($selectFields as $index => $field) {
         if ($field == 'id') {
             continue;
         }
         if (isset($this->field_name_id_array[$field])) {
             $fieldId = $this->field_name_id_array[$field];
             if (!in_array($fieldId, $exportColumns)) {
                 unset($selectFields[$index]);
             } else {
                 $indexField = array_search($fieldId, $exportColumns);
                 unset($exportColumns[$indexField]);
             }
         } else {
             if (!in_array($field, $exportColumns)) {
                 unset($selectFields[$index]);
             } else {
                 $indexField = array_search($field, $exportColumns);
                 unset($exportColumns[$indexField]);
             }
         }
     }
     if (in_array($this->field_name_id_array['description'], $exportColumns)) {
         $selectFields[] = 'introtext';
         $selectFields[] = 'fulltext';
         $indexField = array_search($this->field_name_id_array['description'], $exportColumns);
         unset($exportColumns[$indexField]);
     }
     $query = $this->_prepareQuery($selectFields, $filter);
     $limit = 0;
     if (!empty($filter['csv_limit_export']) && is_numeric($filter['csv_limit_export'])) {
         $limit = $filter['csv_limit_export'];
     }
     $db->setQuery($query, 0, $limit);
     $documents = $db->loadObjectList();
     if (!empty($documents)) {
         foreach ($documents as $document) {
             $docId = $document->id;
             $mainCatId = JUDownloadFrontHelperCategory::getMainCategoryId($docId);
             $data = get_object_vars($document);
             if (!in_array($this->field_name_id_array['id'], $exportColumns)) {
                 unset($data['id']);
             }
             if (isset($data['introtext'])) {
                 $data['description'] = !empty($data['fulltext']) ? $data['introtext'] . "<hr id=\"system-readmore\" />" . $data['fulltext'] : $data['introtext'];
                 unset($data['introtext']);
                 unset($data['fulltext']);
             }
             if (in_array($this->field_name_id_array['rating'], $exportColumns)) {
                 $query = $db->getQuery(true);
                 $query->select('score')->from('#__judownload_rating')->where('doc_id = ' . $docId);
                 $db->setQuery($query);
                 $data['rating'] = $db->loadResult();
             }
             foreach ($exportColumns as $fieldId) {
                 if (is_numeric($fieldId) && $fieldId != $this->field_name_id_array['id'] && $fieldId != $this->field_name_id_array['tags']) {
                     $query = $db->getQuery(true);
                     $query->select('value')->from('#__judownload_fields_values')->where('doc_id = ' . $docId)->where('field_id = ' . $fieldId);
                     $db->setQuery($query);
                     $data['field_' . $fieldId] = $db->loadColumn();
                 }
             }
             if (in_array($this->field_name_id_array['tags'], $exportColumns)) {
                 $query = $db->getQuery(true);
                 $query->select('t.title')->from('#__judownload_tags AS t')->join('', '#__judownload_tags_xref AS txref ON txref.tag_id = t.id')->where('txref.doc_id = ' . $docId);
                 $db->setQuery($query);
                 $tags = $db->loadColumn();
                 $data['tags'] = $tags;
             }
             if (in_array('main_cat', $exportColumns)) {
                 $data['main_cat'] = $mainCatId;
             }
             if (in_array('secondary_cats', $exportColumns)) {
                 $query = $db->getQuery(true);
                 $query->select("c.id");
                 $query->from("#__judownload_categories AS c");
                 $query->join("", "#__judownload_documents_xref AS dxref ON (c.id = dxref.cat_id)");
                 $query->where("dxref.doc_id = " . $docId);
                 $query->where("dxref.main = 0");
                 $query->order('dxref.ordering ASC');
                 $db->setQuery($query);
                 $cats = $db->loadColumn();
                 if (!empty($cats)) {
                     $data['secondary_cats'] = $cats;
                 } else {
                     $data['secondary_cats'] = '';
                 }
             }
             if (in_array('gallery', $exportColumns)) {
                 $query = $db->getQuery(true);
                 $query->select('file_name')->from('#__judownload_images')->where('doc_id = ' . $docId);
                 $db->setQuery($query);
                 $imagesName = $db->loadColumn();
                 foreach ($imagesName as $index => $imageName) {
                     $imagesName[$index] = JUDownloadFrontHelper::getDirectory('document_original_image_directory', 'media/com_judownload/images/gallery/original/', true) . $docId . '/' . $imageName;
                 }
                 $data['gallery'] = $imagesName;
             }
             if (in_array('files', $exportColumns)) {
                 $query = $db->getQuery(true);
                 $query->select('file_name')->from('#__judownload_files')->where('doc_id = ' . $docId);
                 $db->setQuery($query);
                 $filesName = $db->loadColumn();
                 foreach ($filesName as $index => $fileName) {
                     $filesName[$index] = JUDownloadFrontHelper::getDirectory("file_directory", "media/com_judownload/files/", true) . $docId . '/' . $fileName;
                 }
                 $data['files'] = $filesName;
             }
             if (in_array('related_docs', $exportColumns)) {
                 $query = $db->getQuery(true);
                 $query->select('doc_id_related')->from('#__judownload_documents_relations')->where('doc_id = ' . $docId);
                 $db->setQuery($query);
                 $relatedDocs = $db->loadColumn();
                 $data['related_docs'] = $relatedDocs;
             }
             $exportData[] = $this->filterExportFieldValue($data);
         }
     }
     $columns = array_keys($exportData[0]);
     array_unshift($exportData, $columns);
     return $exportData;
 }
Ejemplo n.º 8
0
	public function download()
	{
		
		JSession::checkToken('request') or die(JText::_('JINVALID_TOKEN'));

		
		$model = $this->getModel();

		
		$model->deleteExpiredTmpFiles();

		
		$app = JFactory::getApplication();
		
		$submittedCategoryId = $app->input->getInt('cat_id', 0);
		$documentIds         = $app->input->get('doc_id', null, null);
		$fileIds             = $app->input->get('file_id', null, null);
		$version             = $app->input->get('version', '', 'string');

		$serverTime      = JFactory::getDate()->toSql();
		$serverTimeStamp = strtotime($serverTime);

		$valuesStoreId = (array) $app->getUserState('com_judownload.download.storeid');

		$params                 = JUDownloadHelper::getParams();
		$noCountingDownloadTime = (int) $params->get('no_counting_download_time', 300);
		
		if ($noCountingDownloadTime > 0)
		{
			if (!empty($valuesStoreId))
			{
				foreach ($valuesStoreId AS $keyStoreId => $valueStoreId)
				{
					if ($serverTimeStamp - $keyStoreId > $noCountingDownloadTime)
					{
						unset($valuesStoreId[$keyStoreId]);
					}
				}
			}

			$app->setUserState('com_judownload.download.storeid', $valuesStoreId);
		}

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

		
		if (isset($fileIds))
		{
			
			if (is_array($fileIds))
			{
				
				$fileIdArray = $fileIds;
			}
			else
			{
				
				$fileIdArray = explode(',', $fileIds);
			}

			
			if (count($fileIdArray) > 0)
			{
				
				if (count($fileIdArray) > 1)
				{
					
					$documentId = (int) $documentIds;
					if (!$documentIds)
					{
						$message = JText::_('COM_JUDOWNLOAD_NO_DOCUMENT_DETECTED');
						$this->setRedirect($this->getReturnPage(), $message, 'error');

						return false;
					}

					
					$fileObjectList   = $model->getAllFilesOfDocument($documentId);
					$validFileIdArray = array();
					foreach ($fileObjectList AS $fileObject)
					{
						if (in_array($fileObject->id, $fileIdArray))
						{
							$validFileIdArray[] = $fileObject->id;
						}
					}
				}
				
				else
				{
					$fileObject = $model->getFileObject($fileIdArray[0]);
					$documentId = $fileObject->doc_id;
					if (isset($documentIds))
					{
						$documentIdPost = (int) $documentIds;
						if ($documentIdPost != $documentId)
						{
							$message = JText::_('COM_JUDOWNLOAD_INVALID_DATA');
							$this->setRedirect($this->getReturnPage(), $message, 'error');

							return false;
						}
					}
					$validFileIdArray = $fileIdArray;
					
					$physicalFilePath = $model->getPhysicalFilePath($validFileIdArray[0]);
					$physicalFilePath = JPath::clean($physicalFilePath);
					if (!JFile::exists($physicalFilePath))
					{
						$message = JText::_('COM_JUDOWNLOAD_FILE_DOES_NOT_EXIST');
						$this->setRedirect($this->getReturnPage(), $message, 'error');

						return false;
					}
				}

				
				$canDownloadDocument = $model->canDownloadDocument($documentId);
				if ($canDownloadDocument)
				{
					if (count($validFileIdArray) > 0)
					{
						
						$externalField = new JUDownloadFieldCore_external_link();
						$document      = JUDownloadHelper::getDocumentById($documentId);
						if ($externalField->isPublished() && $document->external_link != '')
						{
							$dispatcher->trigger('onAfterDownloadDocument', array($documentId, array(), 0));

							
							$logData = array(
								'user_id'   => JFactory::getUser()->id,
								'event'     => 'document.download',
								'item_id'   => $documentId,
								'doc_id'    => $documentId,
								'value'     => 0,
								'reference' => 'external'
							);
							JUDownloadFrontHelperLog::addLog($logData);

							
							JUDownloadFrontHelperMail::sendEmailByEvent('document.download', $documentId);

							
							$model->updateDocumentDownloadCounter($documentId);

							
							$this->setRedirect(JRoute::_($document->external_link, false));

							return true;
						}

						if (count($validFileIdArray) > 1)
						{
							$params = JUDownloadHelper::getParams(null, (int) $documentId);
							
							if (!$params->get('allow_zip_file', 1))
							{
								$message = JText::_('COM_JUDOWNLOAD_INVALID_DOWNLOAD_DATA');
								$this->setRedirect($this->getReturnPage(), $message, 'error');

								return false;
							}
						}

						
						foreach ($validFileIdArray AS $validFileId)
						{
							$canDownloadFile = $model->canDownloadFile($validFileId, false);
							if (!$canDownloadFile)
							{
								$fileObject = $model->getFileObject($validFileId);
								$message    = JText::sprintf('COM_JUDOWNLOAD_YOU_CAN_NOT_DOWNLOAD_FILE_X', $fileObject->rename);
								$this->setRedirect($this->getReturnPage(), $message, 'error');

								return false;
							}
						}

						if ($noCountingDownloadTime > 0)
						{
							sort($validFileIdArray);
							$storeID = md5('file' . serialize($validFileIdArray) . $version);
							if (in_array($storeID, $valuesStoreId))
							{
								$generalCheck = true;
							}
							else
							{
								
								$generalCheck = $model->generalCheckDownload();
							}
						}
						else
						{
							$generalCheck = $model->generalCheckDownload();
						}

						if (!$generalCheck)
						{
							$message = $model->getError();
							$this->setRedirect($this->getReturnPage(), $message, 'error');

							return false;
						}

						if ($model->download('file', $validFileIdArray, $documentId, $version) === false)
						{
							$message = $model->getError();
							$this->setRedirect($this->getReturnPage(), $message, 'error');

							return false;
						}

					}
					
					else
					{
						$message = JText::_('COM_JUDOWNLOAD_INVALID_DOWNLOAD_DATA');
						$this->setRedirect($this->getReturnPage(), $message, 'error');

						return false;
					}
				}
				
				else
				{
					$message          = implode("<br/>", $model->getErrors());
					$params           = JUDownloadHelper::getParams(null, $documentId);
					$display_messages = $params->get('show_rule_messages', 'modal');
					if ($display_messages == "redirect")
					{
						$return = $app->input->get('return', null, 'base64');
						$this->setRedirect(JRoute::_('index.php?option=com_judownload&view=downloaderror&return=' . $return, false), $message, 'error');
					}
					else
					{
						$this->setRedirect($this->getReturnPage(), $message, 'error');
					}

					return false;
				}
			}
			
			else
			{
				$message = JText::_('COM_JUDOWNLOAD_NO_FILE_TO_DOWNLOAD');
				$this->setRedirect($this->getReturnPage(), $message, 'error');

				return false;
			}
		}
		
		else
		{
			
			if (is_array($documentIds))
			{
				$documentIdArray = $documentIds;
			}
			else
			{
				$documentIdArray = explode(',', $documentIds);
			}

			if (count($documentIdArray) > 0)
			{
				
				if (count($documentIdArray) > 1)
				{
					$categoryId = $submittedCategoryId;
					
					if (!$categoryId)
					{
						$message = JText::_('COM_JUDOWNLOAD_NO_CATEGORY_DETECTED');
						$this->setRedirect($this->getReturnPage(), $message, 'error');

						return false;
					}

					$params = JUDownloadHelper::getParams(null, $categoryId);
					
					if (!$params->get('allow_download_multi_docs', 0))
					{
						$message = JText::_('COM_JUDOWNLOAD_INVALID_DOWNLOAD_DATA');
						$this->setRedirect($this->getReturnPage(), $message, 'error');

						return false;
					}

					
					$validDocumentIdArray = array();

					
					$documentIdsInCat = $model->getChildDocumentIds($categoryId);

					foreach ($documentIdsInCat AS $documentIdInCat)
					{
						if (in_array($documentIdInCat, $documentIdArray))
						{
							$validDocumentIdArray[] = $documentIdInCat;
						}
					}
				}
				
				else
				{
					$documentId = $documentIdArray[0];
					$categoryId = JUDownloadFrontHelperCategory::getMainCategoryId($documentId);

					$validDocumentIdArray = $documentIdArray;
					$documentIdInCat      = JUDownloadHelper::getDocumentById($documentId);
					$externalField        = new JUDownloadFieldCore_external_link();
					if ($externalField->isPublished() && $documentIdInCat->external_link != '')
					{
						$dispatcher->trigger('onAfterDownloadDocument', array($documentId, array(), 0));

						
						$logData = array(
							'user_id'   => JFactory::getUser()->id,
							'event'     => 'document.download',
							'item_id'   => $documentId,
							'doc_id'    => $documentId,
							'value'     => 0,
							'reference' => 'external'
						);
						JUDownloadFrontHelperLog::addLog($logData);

						
						JUDownloadFrontHelperMail::sendEmailByEvent('document.download', $documentId);

						
						$model->updateDocumentDownloadCounter($documentId);

						
						$this->setRedirect(JRoute::_($documentIdInCat->external_link, false));

						return true;
					}
				}

				if (count($validDocumentIdArray) > 1)
				{
					$params = JUDownloadHelper::getParams($categoryId);
					
					if (!$params->get('allow_zip_file', 1))
					{
						$message = JText::_('COM_JUDOWNLOAD_INVALID_DOWNLOAD_DATA');
						$this->setRedirect($this->getReturnPage(), $message, 'error');

						return false;
					}
				}
				elseif (count($validDocumentIdArray) == 1)
				{
					$filesInDocument = JUDownloadFrontHelperDocument::getFilesByDocumentId((int) $validDocumentIdArray[0]);
					if (count($filesInDocument) > 1)
					{
						if (!$params->get('allow_zip_file', 1))
						{
							$linkFiles = JUDownloadHelperRoute::getDocumentRoute((int) $validDocumentIdArray[0]);
							$linkFiles .= '#judl-files';
							$app->redirect(JRoute::_($linkFiles, false));
						}
					}
				}

				
				foreach ($validDocumentIdArray AS $documentId)
				{
					$canDownloadDocument = $model->canDownloadDocument($documentId);
					if (!$canDownloadDocument)
					{
						$message          = implode("<br/>", $model->getErrors());
						$params           = JUDownloadHelper::getParams(null, $documentId);
						$display_messages = $params->get('show_rule_messages', 'modal');
						if ($display_messages == "redirect")
						{
							$return = $app->input->get('return', null, 'base64');
							$this->setRedirect(JRoute::_('index.php?option=com_judownload&view=downloaderror&return=' . $return, false), $message, 'error');
						}
						else
						{
							$this->setRedirect($this->getReturnPage(), $message, 'error');
						}

						return false;
					}
				}

				
				if ($noCountingDownloadTime > 0)
				{
					sort($validDocumentIdArray);
					$storeID = md5('document' . serialize($validDocumentIdArray) . $version);
					if (in_array($storeID, $valuesStoreId))
					{
						$generalCheck = true;
					}
					else
					{
						
						$generalCheck = $model->generalCheckDownload();
					}
				}
				else
				{
					$generalCheck = $model->generalCheckDownload();
				}

				if (!$generalCheck)
				{
					$message = $model->getError();
					$this->setRedirect($this->getReturnPage(), $message, 'error');

					return false;
				}

				
				if (count($validDocumentIdArray) == 1)
				{
					if (count($filesInDocument) == 1)
					{
						
						if (!$params->get('allow_zip_file', 1))
						{
							$fileObject = $filesInDocument[0];
							$fileId     = $fileObject->id;
							if ($model->download('file', array($fileId), $validDocumentIdArray[0], $version) === false)
							{
								$message = $model->getError();
								$this->setRedirect($this->getReturnPage(), $message, 'error');

								return false;
							}
						}
					}
				}

				if ($model->download('document', $validDocumentIdArray, $categoryId, $version) === false)
				{
					$message = $model->getError();
					$this->setRedirect($this->getReturnPage(), $message, 'error');

					return false;
				}
			}
			
			else
			{
				$message = JText::_('COM_JUDOWNLOAD_NO_DOCUMENT_TO_DOWNLOAD');
				$this->setRedirect($this->getReturnPage(), $message, 'error');

				return false;
			}
		}
	}
Ejemplo n.º 9
0
 public function delete($pk = null)
 {
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_judownload/tables');
     $k = $this->_tbl_key;
     $pk = is_null($pk) ? $this->{$k} : $pk;
     $db = JFactory::getDbo();
     $query = "DELETE FROM #__judownload_subscriptions WHERE item_id = {$pk} AND type = 'document'";
     $db->setQuery($query);
     $db->execute();
     $query = "SELECT * FROM #__judownload_comments WHERE doc_id = " . $pk;
     $db->setQuery($query);
     $commentIds = $db->loadColumn();
     if ($commentIds) {
         $commentTable = JTable::getInstance("Comment", "JUDownloadTable");
         foreach ($commentIds as $commentId) {
             $commentTable->delete($commentId);
         }
     }
     $query = "SELECT id FROM #__judownload_rating WHERE doc_id = {$pk}";
     $db->setQuery($query);
     $ratingItemIds = $db->loadColumn();
     if ($ratingItemIds) {
         $ratingTable = JTable::getInstance("Rating", "JUDownloadTable");
         foreach ($ratingItemIds as $ratingItemId) {
             $ratingTable->delete($ratingItemId);
         }
     }
     $query = "DELETE FROM #__judownload_reports WHERE item_id = {$pk} AND type = 'document'";
     $db->setQuery($query);
     $db->execute();
     $query = "SELECT id FROM #__judownload_collections_items WHERE doc_id = {$pk}";
     $db->setQuery($query);
     $collectionItemIds = $db->loadColumn();
     if ($collectionItemIds) {
         $collectionItemTable = JTable::getInstance("CollectionItem", "JUDownloadTable");
         foreach ($collectionItemIds as $collectionItemId) {
             $collectionItemTable->delete($collectionItemId);
         }
     }
     JUDownloadHelper::deleteLogs('document', $pk);
     $query = "DELETE FROM #__judownload_mailqs\r\n\t\t\t      WHERE item_id =" . $pk . "\r\n\t\t\t\t\t\tAND email_id IN (SELECT id FROM #__judownload_emails WHERE (`event` LIKE 'document.%' AND `event` != 'document.delete'))";
     $db->setQuery($query);
     $db->execute();
     $query = $db->getQuery(true);
     $query->select('id');
     $query->from('#__judownload_documents');
     $query->where('approved=' . -$pk);
     $db->setQuery($query);
     $tempDocIds = $db->loadColumn();
     if (count($tempDocIds)) {
         foreach ($tempDocIds as $tempDocId) {
             $this->deleteMainData($tempDocId, true);
         }
     }
     $cat_id = JUDownloadFrontHelperCategory::getMainCategoryId($this->id);
     $this->deleteMainData($pk);
     if (parent::delete($pk)) {
         $app = JFactory::getApplication();
         if ($app->isSite()) {
             $registry = new JRegistry();
             $registry->loadObject($this);
             $mailData = $registry->toArray();
             $mailData['cat_id'] = $cat_id;
             if ($this->approved < 1) {
                 JUDownloadFrontHelperMail::sendEmailByEvent('document.reject', $this->id, $mailData);
             } else {
                 JUDownloadFrontHelperMail::sendEmailByEvent('document.delete', $this->id, $mailData);
             }
         }
         return true;
     } else {
         return false;
     }
 }
Ejemplo n.º 10
0
	public static function getDocumentLayout($docId)
	{
		$storeId = md5(__METHOD__ . "::" . $docId);
		if (!isset(self::$cache[$storeId]))
		{
			$db    = JFactory::getDbo();
			$query = $db->getQuery(true);
			$query->select('layout');
			$query->from('#__judownload_documents');
			$query->where('id =' . $docId);
			$db->setQuery($query);
			$layout = $db->loadResult();

			
			if ($layout == -2)
			{
				$params = JUDownloadHelper::getParams(null, $docId);
				$layout = $params->get('layout_document', '_:default');
			}
			
			elseif ($layout == -1)
			{
				$parentId = (int) JUDownloadFrontHelperCategory::getMainCategoryId($docId);
				
				if ($parentId == 0)
				{
					$params = JUDownloadHelper::getParams(null, $docId);
					$layout = $params->get('layout_document', '_:default');
				}
				
				else
				{
					$layout = JUDownloadFrontHelperDocument::getDocumentLayoutFromCategory($parentId);
				}
			}
			else
			{
				$layout = trim($layout);
			}

			self::$cache[$storeId] = $layout;
		}

		return self::$cache[$storeId];
	}
Ejemplo n.º 11
0
	public static function canAutoApprovalDocumentWhenEdit($documentId, $newMainCategoryId)
	{
		$documentObject = JUDownloadHelper::getDocumentById($documentId);

		if ($documentObject->approved == 1)
		{
			$originalDocumentId     = $documentObject->id;
			$originalDocumentObject = $documentObject;
			$mainCategoryId         = JUDownloadFrontHelperCategory::getMainCategoryId($originalDocumentObject->id);
			$params                 = JUDownloadHelper::getParams($newMainCategoryId);
		}
		elseif ($documentObject->approved < 0)
		{
			$tempDocumentObject     = $documentObject;
			$originalDocumentId     = abs($documentObject->approved);
			$originalDocumentObject = JUDownloadHelper::getDocumentById($originalDocumentId);
			$mainCategoryId         = JUDownloadFrontHelperCategory::getMainCategoryId($originalDocumentObject->id);
			$params                 = JUDownloadHelper::getParams($newMainCategoryId);
		}
		else
		{
			return false;
		}

		
		$isDocumentOwner              = JUDownloadFrontHelperPermission::isDocumentOwner($originalDocumentObject->id);
		$autoApprovalForDocumentOwner = $params->get('document_owner_can_edit_document_auto_approval', 1);
		if ($isDocumentOwner && $autoApprovalForDocumentOwner)
		{
			return true;
		}

		$user = JFactory::getUser();

		
		if ($mainCategoryId == $newMainCategoryId)
		{
			if ($user->authorise('judl.document.edit.auto_approval', 'com_judownload.category.' . $mainCategoryId))
			{
				return true;
			}
		}
		else
		{
			if ($user->authorise('judl.document.create.auto_approval', 'com_judownload.category.' . $newMainCategoryId))
			{
				return true;
			}
		}

		
		
		if (!$user->get('guest'))
		{
			$autoApprovalDocumentThreshold = (int) $params->get('auto_approval_document_threshold', 0);
			if ($autoApprovalDocumentThreshold > 0)
			{
				$totalApprovedDocumentsOfUser = JUDownloadFrontHelperDocument::getTotalDocumentsOfUserApprovedByMod($user->id);
				if ($totalApprovedDocumentsOfUser >= $autoApprovalDocumentThreshold)
				{
					return true;
				}
			}
		}

		return false;
	}
Ejemplo n.º 12
0
	public static function getFeed($feedDocuments, &$document)
	{
		$db     = JFactory::getDbo();
		$app    = JFactory::getApplication();
		$params = JUDownloadHelper::getParams();

		$image     = $params->get('rss_thumbnail_source', 'icon');
		$feedEmail = $params->get('rss_email', 'none');
		$siteEmail = $app->get('mailfrom');

		foreach ($feedDocuments AS $doc)
		{
			$title = $doc->title;
			$title = html_entity_decode($title, ENT_COMPAT, 'UTF-8');

			$categoryId = JUDownloadFrontHelperCategory::getMainCategoryId($doc->id);
			$category   = JUDownloadFrontHelperCategory::getCategory($categoryId);

			$feedItem        = new JFeedItem();
			$feedItem->title = $title;
			$feedItem->link  = JRoute::_(JUDownloadHelperRoute::getDocumentRoute($doc->id));
			if ($feedEmail != 'none')
			{
				$user             = JFactory::getUser($doc->created_by);
				$feedItem->author = $doc->created_by_alias ? $doc->created_by_alias : $user->name;
				
				if ($feedEmail == 'site')
				{
					$feedItem->authorEmail = $siteEmail;
				}
				elseif ($feedEmail === 'author')
				{
					$feedItem->authorEmail = $doc->email ? $doc->email : $user->email;
				}
			}

			$feedItem->category = $category->title;
			@$date = $doc->publish_up ? date('r', strtotime($doc->publish_up)) : '';
			$feedItem->date        = $date;
			$feedItem->description = "";

			if ($params->get('rss_show_thumbnail', 1))
			{
				
				if ($image == 'icon' && $doc->icon)
				{
					$imageUrl = JUri::root() . JUDownloadFrontHelper::getDirectory("document_icon_directory", "media/com_judownload/images/document/", true) . $doc->icon;
				}
				
				else
				{
					$query = "SELECT file_name FROM #__judownload_images WHERE doc_id = " . $doc->id . " ORDER BY ordering ASC LIMIT 1";
					$db->setQuery($query);
					$firstImage = $db->loadResult();
					$imageUrl   = JUri::root() . JUDownloadFrontHelper::getDirectory("document_small_image_directory", "media/com_judownload/images/gallery/small/", true) . $firstImage;
				}
				$feedItem->description = "<img src='" . $imageUrl . "' align=\"" . $params->get('rss_thumbnail_alignment', 'left') . "\" />";
			}
			$feedItem->description .= $doc->introtext;
			$document->addItem($feedItem);
		}
	}
Ejemplo n.º 13
0
	public static function getTemplateStyleOfDocument($documentId)
	{
		$storeId = md5(__METHOD__ . "::" . (int) $documentId);

		if (!isset(self::$cache[$storeId]))
		{
			$documentObject = JUDownloadHelper::getDocumentById($documentId);
			$styleId        = $documentObject->style_id;
			if ($styleId == -2)
			{
				$templateStyleObject = self::getDefaultTemplateStyle();
			}
			elseif ($styleId == -1)
			{
				$mainCategoryId      = JUDownloadFrontHelperCategory::getMainCategoryId($documentId);
				$templateStyleObject = self::getTemplateStyleOfCategory($mainCategoryId);
			}
			else
			{
				$templateStyleObject = self::getTemplateStyleObject($styleId);
			}

			if (is_object($templateStyleObject))
			{
				self::$cache[$storeId] = $templateStyleObject;
			}
			else
			{
				self::$cache[$storeId] = self::getDefaultTemplateStyle();
			}
		}

		return self::$cache[$storeId];
	}
Ejemplo n.º 14
0
	public function canDownloadDocument($documentId, $checkPassword = true)
	{
		$storeId = md5(__METHOD__ . "::$documentId::" . (int) $checkPassword);
		if (!isset($this->cache[$storeId]))
		{
			
			$mainCategoryId = JUDownloadFrontHelperCategory::getMainCategoryId($documentId);
			$canDoCategory  = JUDownloadFrontHelperPermission::canDoCategory($mainCategoryId);
			if (!$canDoCategory)
			{
				$this->cache[$storeId] = false;

				return $this->cache[$storeId];
			}

			
			$isDocumentOwner = JUDownloadFrontHelperPermission::isDocumentOwner($documentId);
			if ($isDocumentOwner)
			{
				
				$asset = 'com_judownload.document.' . $documentId;
				$user  = JFactory::getUser();
				if ($user->authorise('judl.document.download.own.no_restrict', $asset))
				{
					$this->cache[$storeId] = true;

					return $this->cache[$storeId];
				}
			}

			
			$isModerator = JUDownloadFrontHelperModerator::isModerator();
			if ($isModerator)
			{
				$documentObject = JUDownloadHelper::getDocumentById($documentId);
				
				if ($documentObject->approved < 1)
				{
					
					$modCanApprove = JUDownloadFrontHelperModerator::checkModeratorCanDoWithDocument($mainCategoryId, 'document_approve');
					if ($modCanApprove)
					{
						$this->cache[$storeId] = true;

						return $this->cache[$storeId];
					}
				}

				
				$modCanDownload = JUDownloadFrontHelperModerator::checkModeratorCanDoWithDocument($mainCategoryId, 'document_download');
				if ($modCanDownload)
				{
					$this->cache[$storeId] = true;

					return $this->cache[$storeId];
				}
			}

			
			if ($isDocumentOwner)
			{
				$userCanDoDocument = true;
			}
			else
			{
				$userCanDoDocument = JUDownloadFrontHelperPermission::userCanDoDocument($documentId, true);
			}

			
			if (!$userCanDoDocument)
			{
				$this->cache[$storeId] = false;

				return $this->cache[$storeId];
			}

			
			if (!$isModerator || ($isModerator && !$modCanDownload))
			{
				
				$validDownloadRules = JUDownloadFrontHelperDocument::getDownloadRuleErrorMessages($documentId);

				
				if ($validDownloadRules !== true)
				{
					$message = array();
					$message = array_merge($message, $validDownloadRules);
					
					$this->setError(implode("<br/>", $message));

					$this->cache[$storeId] = false;

					return $this->cache[$storeId];
				}
			}

			$documentObject = JUDownloadHelper::getDocumentById($documentId);
			$hasPassword    = JUDownloadFrontHelperDocument::documentHasPassword($documentObject);
			
			if ($hasPassword && $checkPassword)
			{
				$validPassword = JUDownloadFrontHelperPassword::checkPassword($documentObject);

				
				if (!$validPassword)
				{
					$this->setError(JText::_('COM_JUDOWNLOAD_INVALID_DOWNLOAD_PASSWORD'));

					$this->cache[$storeId] = false;

					return $this->cache[$storeId];
				}
			}

			$this->cache[$storeId] = true;

			return $this->cache[$storeId];
		}

		return $this->cache[$storeId];
	}
Ejemplo n.º 15
0
 public function validateFields($fieldsData, $docId)
 {
     $app = JFactory::getApplication();
     $params = JUDownloadHelper::getParams();
     $db = JFactory::getDbo();
     $nullDate = $db->getNullDate();
     $nowDate = JFactory::getDate()->toSql();
     $error = false;
     $isNew = $docId == 0 ? true : false;
     $categoriesField = JUDownloadFrontHelperField::getField('cat_id', $docId);
     if ($this->getDocumentSubmitType($docId) == 'submit' && $categoriesField->canSubmit() || $this->getDocumentSubmitType($docId) == 'edit' && $categoriesField->canEdit()) {
         $fieldValueCategories = $fieldsData[$categoriesField->id];
         $categoriesField->is_new = $isNew;
         $categoriesField->fields_data = $fieldsData;
         $fieldValueCategories = $categoriesField->filterField($fieldValueCategories);
         $valid = $categoriesField->PHPValidate($fieldValueCategories);
         if ($valid === true) {
             $fieldsData[$categoriesField->id] = $fieldValueCategories;
             $catId = $fieldsData[$categoriesField->id]['main'];
         } else {
             $this->setError($valid);
             if ($isNew) {
                 return false;
             }
             $catId = JUDownloadFrontHelperCategory::getMainCategoryId($docId);
             $error = true;
             unset($fieldsData[$categoriesField->id]);
         }
     } else {
         $catId = JUDownloadFrontHelperCategory::getMainCategoryId($docId);
     }
     $form = $this->getFormDefault();
     $xml_field_name_publishing = array();
     $elementsInPublishing = $form->xpath('//fieldset[@name="publishing"]/field | //field[@fieldset="publishing"]');
     foreach ($elementsInPublishing as $elementsInPublishingKey => $elementsInPublishingVal) {
         $elementInPublishing = $elementsInPublishingVal->attributes();
         $xml_field_name_publishing[] = (string) $elementInPublishing['name'];
     }
     $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");
     $query->join("", "#__judownload_fields_groups AS field_group ON field_group.id = field.group_id");
     $query->join("", "#__judownload_categories AS c ON (c.fieldgroup_id = field.group_id OR field.group_id = 1 )");
     $query->where("field_group.published = 1");
     $query->where("field.published = 1");
     $query->where('field.publish_up <= ' . $db->quote($nowDate));
     $query->where('(field.publish_down = ' . $db->quote($nullDate) . ' OR field.publish_down >= ' . $db->quote($nowDate) . ')');
     $query->where("(c.id = " . $catId . " OR field.group_id = 1)");
     $query->where("field.field_name != 'cat_id'");
     if ($app->isSite() && !$params->get('submit_form_show_tab_publishing', 0)) {
         if (!empty($xml_field_name_publishing)) {
             $query->where('field.field_name NOT IN (' . implode(',', $db->quote($xml_field_name_publishing)) . ')');
         }
     }
     $query->group('field.id');
     $db->setQuery($query);
     $fields = $db->loadObjectList();
     foreach ($fields as $field) {
         $fieldObj = JUDownloadFrontHelperField::getField($field, $docId);
         if ($this->getDocumentSubmitType($docId) == 'submit' && $fieldObj->canSubmit() || $this->getDocumentSubmitType($docId) == 'edit' && $fieldObj->canEdit()) {
             $fieldValue = isset($fieldsData[$field->id]) ? $fieldsData[$field->id] : null;
             $fieldObj->is_new = $isNew;
             $fieldObj->fields_data = $fieldsData;
             $fieldValue = $fieldObj->filterField($fieldValue);
             $valid = $fieldObj->PHPValidate($fieldValue);
             if ($valid === true) {
                 $fieldsData[$field->id] = $fieldValue;
             } else {
                 $error = true;
                 unset($fieldsData[$field->id]);
                 $this->setError($valid);
             }
         }
     }
     if ($error) {
         return false;
     } else {
         return $fieldsData;
     }
 }
Ejemplo n.º 16
0
	protected function _setBreadcrumb()
	{
		$categoryId = JUDownloadFrontHelperCategory::getMainCategoryId($this->item->id);

		$app          = JFactory::getApplication();
		$pathway      = $app->getPathway();
		$pathwayArray = array();
		if ($categoryId)
		{
			$pathwayArray = JUDownloadFrontHelperBreadcrumb::getBreadcrumbCategory($categoryId);
		}
		else
		{
			$pathwayArray[] = JUDownloadFrontHelperBreadcrumb::getRootPathway();
		}

		$linkDocument   = JRoute::_(JUDownloadHelperRoute::getDocumentRoute($this->item->id));
		$pathwayArray[] = JUDownloadFrontHelperBreadcrumb::createPathwayItem($this->item->title, $linkDocument);

		if ($this->_layout == 'changelogs')
		{
			$pathwayArray[] = JUDownloadFrontHelperBreadcrumb::createPathwayItem('CHANGELOGS');
		}
		elseif ($this->_layout == 'versions')
		{
			$pathwayArray[] = JUDownloadFrontHelperBreadcrumb::createPathwayItem('VERSIONS');
		}
		elseif ($this->_layout == 'print')
		{
			$pathwayArray[] = JUDownloadFrontHelperBreadcrumb::createPathwayItem('PRINT');

			$document = JFactory::getDocument();
			$document->setMetaData('robots', 'noindex, nofollow');
		}

		$pathway->setPathway($pathwayArray);
	}
Ejemplo n.º 17
0
	public function PHPValidate($values)
	{
		$rootCat = JUDownloadFrontHelperCategory::getRootCategory();
		
		if (isset($this->doc) && $this->doc->cat_id)
		{
			$params = JUDownloadHelper::getParams($this->doc->cat_id);
		}
		else
		{
			$params = JUDownloadHelper::getParams(null, $this->doc_id);
		}

		$mainCatId       = $values['main'];
		$secondaryCatIds = array_filter(explode(",", $values['secondary']));

		if (!$mainCatId)
		{
			return JText::_("COM_JUDOWNLOAD_PLEASE_SELECT_A_CATEGORY");
		}

		if ($mainCatId == $rootCat->id && !$params->get('allow_add_doc_to_root', 0))
		{
			return JText::_("COM_JUDOWNLOAD_CAN_NOT_ADD_DOCUMENT_TO_ROOT_CATEGORY");
		}

		if (!JUDownloadHelper::getCategoryById($mainCatId))
		{
			return JText::_("COM_JUDOWNLOAD_INVALID_CATEGORY");
		}

		if (1 && (count($secondaryCatIds) + 1 > 1))
		{
			return JText::sprintf("COM_JUDOWNLOAD_NUMBER_OF_CATEGORY_OVER_MAX_N_CATEGORIES", 1);
		}

		if (!$this->doc_id)
		{
			
			if (!JUDownloadFrontHelperPermission::canSubmitDocument($mainCatId))
			{
				$category = JUDownloadHelper::getCategoryById($mainCatId);

				return JText::sprintf("COM_JUDOWNLOAD_YOU_ARE_NOT_AUTHORIZED_TO_SUBMIT_DOCUMENT_TO_THIS_CATEGORY", $category->title);
			}
		}
		else
		{
			$mainCatIdDB = JUDownloadFrontHelperCategory::getMainCategoryId($this->doc_id);

			
			if ($mainCatId != $mainCatIdDB)
			{
				
				if (!JUDownloadFrontHelperPermission::canSubmitDocument($mainCatId))
				{
					$category = JUDownloadHelper::getCategoryById($mainCatId);

					return JText::sprintf("COM_JUDOWNLOAD_YOU_ARE_NOT_AUTHORIZED_TO_SUBMIT_DOCUMENT_TO_THIS_CATEGORY", $category->title);
				}
			}

			$app = JFactory::getApplication();
			
			if ($app->isSite())
			{
				
				if ($mainCatId != $mainCatIdDB)
				{
					if (!$params->get('can_change_main_category', 1))
					{
						return false;
					}
				}

				
				if (!$params->get('can_change_secondary_categories', 1))
				{
					$secondaryCatIdsDB = $this->getSecondaryCategoryIds($this->doc_id);
					if (count($secondaryCatIds) && count($secondaryCatIdsDB))
					{
						if (array_diff($secondaryCatIds, $secondaryCatIdsDB) || array_diff($secondaryCatIdsDB, $secondaryCatIds))
						{
							return false;
						}
					}
				}
			}
		}

		return true;
	}