protected function getInput()
 {
     if ($this->form->getValue("id") && $this->form->getValue("plugin_id")) {
         $fieldObj = JUDownloadFrontHelperField::getField($this->form->getValue("id"));
         $html = $fieldObj->getPredefinedValuesHtml();
     } else {
         $html = '<span class="readonly">' . JText::_('COM_JUDOWNLOAD_NO_VALUE') . '</span>';
     }
     return $html;
 }
Exemple #2
0
 public function display($tpl = null)
 {
     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->model = $this->getModel();
     $this->app = JFactory::getApplication();
     $cat_id = $this->item->cat_id ? $this->item->cat_id : $this->app->input->get('cat_id');
     $this->params = JUDownloadHelper::getParams(null, $this->item->id);
     if ($cat_id == JUDownloadFrontHelperCategory::getRootCategory()->id && !$this->params->get('allow_add_doc_to_root', 0)) {
         JError::raiseError(500, JText::_('COM_JUDOWNLOAD_CAN_NOT_ADD_DOCUMENT_TO_ROOT_CATEGORY'));
         return false;
     }
     if ($tempDocument = JUDownloadHelper::getTempDocument($this->item->id)) {
         $editPendingDocLink = '<a href="index.php?option=com_judownload&task=document.edit&approve=1&id=' . $tempDocument->id . '">' . $tempDocument->title . '</a>';
         JError::raiseNotice('', JText::sprintf('COM_JUDOWNLOAD_THIS_DOCUMENT_HAS_PENDING_DOCUMENT_X_PLEASE_APPROVE_PENDING_DOCUMENT_FIRST', $editPendingDocLink));
     }
     if ($this->item->approved < 0) {
         $oriDocId = abs($this->item->approved);
         $oriDocObj = JUDownloadHelper::getDocumentById($oriDocId);
         $editOriDocLink = '<a href="index.php?option=com_judownload&task=document.edit&id=' . $oriDocId . '">' . $oriDocObj->title . '</a>';
         JError::raiseNotice('', JText::sprintf('COM_JUDOWNLOAD_ORIGINAL_DOCUMENT_X', $editOriDocLink));
     }
     $this->script = $this->get('Script');
     $this->plugins = $this->get('Plugins');
     $this->fieldsetDetails = $this->model->getCoreFields('details');
     $this->fieldsetPublishing = $this->model->getCoreFields('publishing');
     $this->fieldsetTemplateStyleAndLayout = $this->model->getCoreFields('template_style');
     $this->fieldsetMetadata = $this->model->getCoreFields('metadata');
     $this->fieldCatid = JUDownloadFrontHelperField::getField('cat_id', $this->item);
     $this->fieldGallery = JUDownloadFrontHelperField::getField('gallery', $this->item);
     $this->files = $this->get('Files');
     $this->changeLogs = $this->get('ChangeLogs');
     $this->versions = $this->get('Versions');
     $this->extraFields = $this->get('ExtraFields');
     $this->fieldsData = $this->app->getUserState("com_judownload.edit.document.fieldsdata", array());
     $this->relatedDocuments = $this->get('RelatedDocuments');
     $this->canDo = JUDownloadHelper::getActions('com_judownload', 'category', $this->item->cat_id);
     $this->addToolBar();
     $this->setDocument();
     parent::display($tpl);
 }
Exemple #3
0
	public static function getDocumentsSearch($searchword, $state, $cat_id = null)
	{
		
		$searchword = trim($searchword);

		$app        = JFactory::getApplication();
		$user       = JFactory::getUser();
		$levels     = $user->getAuthorisedViewLevels();
		$levels_str = implode(',', $levels);
		$db         = JFactory::getDbo();
		$nullDate   = $db->getNullDate();
		$nowDate    = JFactory::getDate()->toSql();
		$query      = $db->getQuery(true);

		$listOrder = $state->get('list.ordering');
		$listDirn  = $state->get('list.direction');
		
		if ($app->isAdmin())
		{
			$query->SELECT('d.id, d.title, d.alias, d.published, d.publish_up, d.publish_down, d.checked_out, d.checked_out_time, d.featured, d.access, d.created_by, d.downloads, d.language');

			$query->SELECT('c.id AS category_id, c.title AS category_title');

			$where_str = $app->isSite() ? ' AND cm.published = 1' : '';
			$query->SELECT('(SELECT COUNT(*) FROM #__judownload_comments AS cm WHERE (cm.doc_id = d.id AND cm.approved = 1' . $where_str . ')) AS comments');

			$query->SELECT('(SELECT COUNT(*) FROM #__judownload_reports AS r WHERE r.item_id = d.id AND r.type="document") AS reports');

			$where_str = $app->isSite() ? ' AND s.published = 1' : '';
			$query->SELECT('(SELECT COUNT(*) FROM #__judownload_subscriptions AS s WHERE s.item_id = d.id AND s.type="document"' . $where_str . ') AS subscriptions');

			$query->SELECT('ua.name AS created_by_name');
			$query->JOIN("LEFT", "#__users AS ua ON d.created_by = ua.id");

			$query->SELECT('ua3.name AS checked_out_name');
			$query->JOIN("LEFT", "#__users AS ua3 ON d.checked_out = ua3.id");

			$query->SELECT("vl.title AS access_title");
			$query->JOIN("LEFT", "#__viewlevels AS vl ON d.access = vl.id");
		}
		
		else
		{
			$query->SELECT('d.*');
			if ($app->isSite())
			{
				JUDownloadFrontHelper::optimizeListDocumentQuery($query);
			}
		}

		$query->FROM('#__judownload_documents AS d');
		$query->JOIN('', '#__judownload_documents_xref AS dxref ON d.id = dxref.doc_id');
		$query->JOIN('', '#__judownload_categories AS c ON (c.id = dxref.cat_id)');

		
		$field_query = $db->getQuery(true);
		
		$field_query->select("field.*");
		$field_query->from("#__judownload_fields AS field");
		$field_query->select("plg.folder");
		$field_query->join("", "#__judownload_plugins AS plg ON field.plugin_id = plg.id");
		$field_query->join("", "#__judownload_fields_groups AS field_group ON field_group.id = field.group_id");
		$field_query->join("", "#__judownload_categories AS c2 ON (c2.fieldgroup_id = field_group.id OR field.group_id = 1)");
		if ($app->isSite())
		{
			if (is_array($cat_id))
			{
				$cat_id = (array) $cat_id;
				$field_query->where('(c2.id IN (' . implode(",", $cat_id) . ') OR field.group_id = 1)');
			}
			elseif ($cat_id)
			{
				$cat_id = (int) $cat_id;
				$field_query->where('(c2.id = ' . $cat_id . ' OR field.group_id = 1)');
			}
			$field_query->where('c2.published = 1');
			$field_query->where('c2.publish_up <= ' . $db->quote($nowDate));
			$field_query->where('(c2.publish_down = ' . $db->quote($nullDate) . ' OR c2.publish_down > ' . $db->quote($nowDate) . ')');
		}
		
		$field_query->where('field.simple_search = 1');
		$field_query->where('field.published = 1');
		$field_query->where('field.publish_up <= ' . $db->quote($nowDate));
		$field_query->where('(field.publish_down = ' . $db->quote($nullDate) . ' OR field.publish_down > ' . $db->quote($nowDate) . ')');
		$field_query->where('(field.field_name != "cat_id"');
		$field_query->where("field_group.published = 1)");
		$field_query->group('field.id');
		$db->setQuery($field_query);
		$fields = $db->loadObjectList();
		$where  = array();
		if ($fields)
		{
			foreach ($fields AS $field)
			{
				if ($searchword)
				{
					$fieldClass = JUDownloadFrontHelperField::getField($field);
					$fieldClass->onSimpleSearch($query, $where, $searchword);
				}
			}

			if (!empty($where))
			{
				$query->WHERE("(" . implode(" OR ", $where) . ")");
			}
		}

		$app = JFactory::getApplication();
		if ($app->isAdmin())
		{
			$published = $state->get('filter.state');
			if (is_numeric($published))
			{
				$query->WHERE('d.published = ' . (int) $published);
			}

			$cat_id = $state->get('filter.category');
			if (is_numeric($cat_id))
			{
				$query->WHERE('dxref.cat_id = ' . (int) $cat_id);
			}

			$access_level = $state->get('filter.access');
			if (is_numeric($access_level) && ($access_level != 0))
			{
				$query->WHERE('d.access = ' . (int) $access_level);
			}

			
			$language = $state->get('filter.language');
			if ($language)
			{
				$query->where('d.language = ' . $db->quote($language));
			}
		}
		else
		{
			$query->where('d.published = 1');
			if ($cat_id)
			{
				if (is_array($cat_id))
				{
					$cat_id = (array) $cat_id;
					$query->where('c.id IN (' . implode(",", $cat_id) . ')');
				}
				elseif ($cat_id)
				{
					$cat_id = (int) $cat_id;
					$query->where('c.id = ' . $cat_id);
				}
			}

			$query->where('d.publish_up <= ' . $db->quote($nowDate));
			$query->where('(d.publish_down = ' . $db->quote($nullDate) . ' OR d.publish_down > ' . $db->quote($nowDate) . ')');

			
			if ($user->get('guest'))
			{
				$query->where('d.access IN (' . $levels_str . ')');
			}
			else
			{
				$query->where('(d.access IN (' . $levels_str . ') OR (d.created_by = ' . $user->id . '))');
			}
		}

		$query->where('d.approved = 1');

		JUDownloadFrontHelperField::appendFieldOrderingPriority($query, null, $listOrder, $listDirn);

		
		$query->group('d.id');

		return $query;
	}
Exemple #4
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'];
		}
	}
Exemple #5
0
 public function getGalleryField()
 {
     $app = JFactory::getApplication();
     $docId = $app->input->getInt('id', 0);
     $galleryField = JUDownloadFrontHelperField::getField('gallery', $docId);
     if ($this->getDocumentSubmitType($docId) == 'submit' && $galleryField->canSubmit() || $this->getDocumentSubmitType($docId) == 'edit' && $galleryField->canEdit()) {
         return $galleryField;
     }
     return null;
 }
$app  = JFactory::getApplication();
$task = $app->input->get('task');

switch ($task)
{
	case 'captcha':
		$namespace = $app->input->getString('captcha_namespace', '');
		JUDownloadFrontHelperCaptcha::captchaSecurityImages($namespace);
		exit;
		break;

	case 'rawdata':
		$field_id = $app->input->getInt('field_id', 0);
		$doc_id   = $app->input->getInt('doc_id', 0);
		$fieldObj = JUDownloadFrontHelperField::getField($field_id, $doc_id);
		JUDownloadHelper::obCleanData();
		$fieldObj->getRawData();
		exit;
		break;

	case 'cron':
		
		JUDownloadFrontHelperMail::sendMailq();
		exit;
		break;

	default:
		$controller = JControllerLegacy::getInstance('judownload');

		
Exemple #7
0
	public function redirectUrl()
	{
		$app     = JFactory::getApplication();
		$fieldId = $app->input->getInt('field_id');
		$docId   = $app->input->getInt('doc_id');

		$field = JUDownloadFrontHelperField::getField($fieldId, $docId);
		$field->redirectUrl();
	}
Exemple #8
0
 public function delete($pk = null)
 {
     $k = $this->_tbl_key;
     $pk = is_null($pk) ? $this->{$k} : $pk;
     $this->load($pk);
     $pk = is_null($pk) ? $this->id : $pk;
     $db = JFactory::getDbo();
     $fieldObj = JUDownloadFrontHelperField::getField($pk);
     $fieldObj->onDelete(true);
     $query = "DELETE FROM #__judownload_fields_ordering WHERE field_id = {$pk}";
     $db->setQuery($query);
     $db->execute();
     $query = "DELETE FROM #__judownload_fields_values WHERE field_id = {$pk}";
     $db->setQuery($query);
     $db->execute();
     return parent::delete($pk);
 }
Exemple #9
0
	public static function appendFieldOrderingPriority(&$query = null, $catIds = null, $ordering = null, $direction = null)
	{
		if (!$catIds)
		{
			$catIds = JUDownloadFrontHelperCategory::getRootCategory()->id;
		}

		$storeId = md5(__METHOD__ . "::" . serialize($catIds) . "::$ordering");
		if (!isset(self::$cache[$storeId]))
		{
			$db             = JFactory::getDbo();
			$nullDate       = $db->getNullDate();
			$nowDate        = JFactory::getDate()->toSql();
			$priority_query = $db->getQuery(true);
			$priority_query->select("field.*");
			$priority_query->from("#__judownload_fields AS field");
			$priority_query->select("plg.folder");
			$priority_query->join("", "#__judownload_plugins AS plg ON field.plugin_id = plg.id ");
			$priority_query->join("", "#__judownload_fields_groups AS field_group ON field.group_id = field_group.id");
			$priority_query->join("", "#__judownload_categories AS c ON (
																			(
																				c.fieldgroup_id = field_group.id AND
																				c.published = 1 AND
																				c.publish_up <= " . $db->quote($nowDate) . " AND
																				(c.publish_down = " . $db->quote($nullDate) . " OR c.publish_down > " . $db->quote($nowDate) . ")
																			) OR field.group_id = 1
																		 )");
			$where   = array();
			$where[] = 'field.published = 1';
			$where[] = 'field.publish_up <= ' . $db->quote($nowDate);
			$where[] = '(field.publish_down = ' . $db->quote($nullDate) . ' OR field.publish_down > ' . $db->quote($nowDate) . ')';

			if (is_array($catIds))
			{
				$where[] = "(c.id IN (" . implode(",", $catIds) . ") OR field.group_id = 1)";
			}
			else
			{
				$where[] = "(c.id = $catIds OR field.group_id = 1)";
			}

			$where[] = 'field.allow_priority = 1';
			$where[] = 'field_group.published = 1';

			
			$priority_query->where("(" . implode(" AND ", $where) . ")", "OR");

			if ($ordering)
			{
				$where   = array();
				$where[] = "(field.id = '$ordering' OR field.field_name = '$ordering')";
				$app     = JFactory::getApplication();
				if ($app->isSite())
				{
					$where[] = "field.frontend_ordering = 1";
				}
				else
				{
					$where[] = "field.backend_list_view >= 1";
				}
				$where[] = "field.published = 1";
				$where[] = "field.publish_up <= " . $db->quote($nowDate);
				$where[] = "(field.publish_down = " . $db->quote($nullDate) . " OR field.publish_down >= " . $db->quote($nowDate) . ")";
				$priority_query->where("(" . implode(" AND ", $where) . ")", "OR");
			}
			$priority_query->group('field.id');

			$priority_query->order('field.priority ASC');

			$db->setQuery($priority_query);

			self::$cache[$storeId] = $db->loadObjectList();
		}

		$priorityFields = self::$cache[$storeId];

		$priority_order = array();
		
		$_ordering = "";
		foreach ($priorityFields AS $priorityField)
		{
			$field = JUDownloadFrontHelperField::getField($priorityField);
			if ($field)
			{
				$priority = $field->orderingPriority($query);
				if ($priority)
				{
					$priority_order[] = $priority['ordering'] . ' ' . $priority['direction'];
				}

				if ($ordering && $field->id == $ordering && $priority)
				{
					$_ordering = $priority['ordering'];
				}
			}
		}

		$priority_str = "";
		if ($priority_order)
		{
			$priority_str = implode(", ", $priority_order);
		}

		if ($_ordering)
		{
			$ordering_str = $_ordering . " " . $direction;
			if ($priority_str)
			{
				$priority_str = $ordering_str . ", " . $priority_str;
			}
		}

		if ($priority_str)
		{
			$query->order($priority_str);
		}

		return $priority_str;
	}
Exemple #10
0
	public static function documentHasPassword($doc)
	{
		if (!is_object($doc))
		{
			$doc = JUDownloadHelper::getDocumentById($doc);
		}

		if (is_object($doc))
		{
			
			$passwordField = JUDownloadFrontHelperField::getField('download_password', $doc);
			if (!is_object($passwordField) || !$passwordField->isPublished())
			{
				return false;
			}

			if ($doc->download_password != '')
			{
				return true;
			}
		}

		
		return false;
	}
Exemple #11
0
	public static function canEditStateDocument($documentObject)
	{
		if (!is_object($documentObject))
		{
			return false;
		}
		$documentId = $documentObject->id;

		if (!isset($documentObject->cat_id))
		{
			$documentObject = JUDownloadHelper::getDocumentById($documentId);
		}

		$mainCatId = $documentObject->cat_id;

		
		$userCanDoCategory = JUDownloadFrontHelperPermission::canDoCategory($mainCatId);
		if (!$userCanDoCategory)
		{
			return false;
		}

		if ($documentObject->id)
		{
			
			$isDocumentOwner = JUDownloadFrontHelperPermission::isDocumentOwner($documentObject->id);
			if ($isDocumentOwner)
			{
				$params                    = JUDownloadHelper::getParams($mainCatId);
				$ownerCanEditStateDocument = $params->get('document_owner_can_edit_state_document', 0);
				if ($ownerCanEditStateDocument)
				{
					return true;
				}
			}
		}

		
		$isModerator = JUDownloadFrontHelperModerator::isModerator();
		if ($isModerator)
		{
			$modCanEditState = JUDownloadFrontHelperModerator::checkModeratorCanDoWithDocument($mainCatId, 'document_edit_state');
			if ($modCanEditState)
			{
				return true;
			}

			if ($documentObject->id && $documentObject->approved <= 0)
			{
				$modCanApprove = JUDownloadFrontHelperModerator::checkModeratorCanDoWithDocument($mainCatId, 'document_approve');
				if ($modCanApprove)
				{
					return true;
				}
			}
		}

		
		$user = JFactory::getUser();
		if (!$user->get('guest'))
		{
			$corePublished = JUDownloadFrontHelperField::getField('published', $documentObject);
			if ($corePublished)
			{
				if ($documentObject->approved <= 0)
				{
					if ($corePublished->canSubmit())
					{
						return true;
					}
				}
				elseif ($documentObject->approved == 1)
				{
					if ($corePublished->canEdit())
					{
						return true;
					}
				}
			}
		}

		return false;
	}
							<?php 
                break;
            case "published":
                if ($item->main) {
                    echo JHtml::_('jgrid.published', $item->published, $i, 'documents.', $canChange, 'doc', $item->publish_up, $item->publish_down);
                } else {
                    echo JHtml::_('jgrid.published', $item->published, $i, 'documents.', false, 'doc', $item->publish_up, $item->publish_down);
                }
                break;
            case "featured":
                if ($item->main) {
                    echo JHtml::_('judownloadadministrator.featured', $item->featured, $i, $canChange, 'documents', 'doc');
                } else {
                    echo JHtml::_('judownloadadministrator.featured', $item->featured, $i, false);
                }
                break;
            default:
                $field = JUDownloadFrontHelperField::getField($field, $item->id);
                echo $field->getBackendOutput();
                break;
        }
        echo '</td>';
    }
    ?>
			</tr>
		<?php 
}
?>
		</tbody>
	</table>
</div>
Exemple #13
0
 public static function getAdvSearchFields()
 {
     $app = JFactory::getApplication();
     $db = JFactory::getDbo();
     $nullDate = $db->quote($db->getNullDate());
     $nowDate = $db->quote(JFactory::getDate()->toSql());
     $query = $db->getQuery(true);
     $query->select('plg.folder, field.*, field_group.name AS filed_group_name');
     $query->from('#__judownload_fields AS field');
     $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');
     if ($app->isSite()) {
         $query->where('field.advanced_search = 1');
     }
     $query->where('field_group.published = 1');
     $query->where('field.published = 1');
     $query->where('field.field_name != "cat_id"');
     $query->where('field.publish_up <= ' . $nowDate);
     $query->where('(field.publish_down = ' . $nullDate . ' OR field.publish_down > ' . $nowDate . ')');
     $query->order('field.group_id');
     $db->setQuery($query);
     $fields = $db->loadObjectList();
     if ($fields) {
         $fieldGroups = array();
         foreach ($fields as $field) {
             if (!isset($fieldGroups[$field->group_id])) {
                 $fieldGroups[$field->group_id] = new stdClass();
                 $fieldGroups[$field->group_id]->name = $field->filed_group_name;
                 $fieldGroups[$field->group_id]->id = $field->group_id;
                 $fieldGroups[$field->group_id]->fields = array();
             }
             $fieldGroups[$field->group_id]->fields[] = JUDownloadFrontHelperField::getField($field);
         }
         return $fieldGroups;
     }
     return null;
 }
Exemple #14
0
 public function cancel($key = null)
 {
     JSession::checkToken() or die(JText::_('JINVALID_TOKEN'));
     $app = JFactory::getApplication();
     $doc_id = $app->input->getInt('id', 0);
     if ($doc_id) {
         $documentObject = JUDownloadHelper::getDocumentById($doc_id);
         $cat_id = $documentObject->cat_id;
     } else {
         $fieldCategory = JUDownloadFrontHelperField::getField('cat_id');
         $fieldData = $app->input->post->get('fields', array(), 'array');
         $cat_id = $fieldData[$fieldCategory->id]['main'];
     }
     if (!$cat_id) {
         $rootCategory = JUDownloadFrontHelperCategory::getRootCategory();
         $cat_id = $rootCategory->id;
     }
     $files = $app->input->get("judlfiles", array(), 'array');
     $context = $this->option . ".edit." . $this->context;
     if (isset($files)) {
         $file_directory = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("file_directory", "media/com_judownload/files/");
         $file_directory_tmp = $file_directory . "tmp/";
         $files = array_values($files);
         foreach ($files as $file) {
             if (isset($file['file_name']) && $file['file_name']) {
                 $file_path = $file_directory_tmp . $file['file_name'];
                 if (JFile::exists($file_path)) {
                     JFile::delete($file_path);
                 }
             }
             if (isset($file['replace']) && $file['replace']) {
                 $file_path = $file_directory_tmp . $file['replace'];
                 if (JFile::exists($file_path)) {
                     JFile::delete($file_path);
                 }
             }
         }
     }
     $app->setUserState($context . '.data', null);
     $app->setUserState($context . '.fieldsdata', null);
     $app->setUserState($context . '.changelogs', null);
     $app->setUserState($context . '.versions', null);
     $app->setUserState($context . '.files', null);
     $app->setUserState($context . '.related_documents', null);
     if ($doc_id) {
         $db = JFactory::getDbo();
         $query = "SELECT cat_id FROM #__judownload_documents_xref WHERE doc_id = {$doc_id} AND main = 1";
         $db->setQuery($query);
         $cat_id = $db->loadResult();
     }
     parent::cancel($key = null);
     if ($this->view_list == "pendingdocuments") {
         $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list . $this->getRedirectToListAppend(), false));
     } else {
         $this->setRedirect("index.php?option=com_judownload&view=listcats&cat_id={$cat_id}");
     }
 }
Exemple #15
0
 public function save($data)
 {
     if (!$data['id']) {
         return false;
     }
     $app = JFactory::getApplication();
     $jform = $app->input->post->get('jform', array(), 'array');
     $data['params'] = isset($jform['params']) ? $jform['params'] : null;
     $table = $this->getTable();
     if ($table->load($data['id']) && $table->plugin_id == $data['plugin_id']) {
         $fieldClass = JUDownloadFrontHelperField::getField($data['id']);
         $data = $fieldClass->onSave($data);
         $data['params'] = json_encode($data['params']);
     } else {
         $data['params'] = "";
     }
     if (parent::save($data)) {
         $table = $this->getTable();
         $table->reorder("group_id = " . (int) $data['group_id']);
         $table->repriority();
         $table->reblvorder();
         return true;
     }
     return false;
 }
									<?php
									if ($commentObj->user_id > 0)
									{
										$userComment = JFactory::getUser($commentObj->user_id);
										echo $userComment->get('name');
									}
									else
									{
										echo $commentObj->guest_name;
									} ?>
									</span>
								</h3>
								<?php
								if ($commentObj->parent_id == $this->root_comment->id)
								{
									$fieldRating = JUDownloadFrontHelperField::getField('rating', $commentObj->doc_id);

									echo $fieldRating->getOutput(array('view' => 'details', 'template' => $this->template, 'type' => 'comment', 'comment_object' => $commentObj));
								} ?>
							</div>
							<!-- /.comment-user -->

							<div class="comment-text">
								<div class="judl-metadata clearfix">
									<h4 class="comment-title" itemprop="name"><?php echo $commentObj->title; ?></h4>

									<div itemprop="datePublished" class="comment-created">
										<?php echo JText::_('COM_JUDOWNLOAD_POST_ON') . " : " . $commentObj->createdAgo; ?>
									</div>

									<?php if ($commentObj->website != '')
Exemple #17
0
 public function insertUpdateDocument($data, $isInsert = true)
 {
     $db = JFactory::getDbo();
     $iconDir = JPATH_ROOT . '/' . JUDownloadFrontHelper::getDirectory('document_icon_directory', 'media/com_judownload/images/document/');
     $originalDir = $iconDir . 'original/';
     $newMainCatId = $data['main_cat'];
     $gallery = $data['gallery'];
     $files = $data['files'];
     $fieldsData = $data['fieldsData'];
     $relatedDocs = $data['related_docs'];
     $data = $data['data'];
     $messages = array();
     if (!$isInsert) {
         $docObj = JUDownloadHelper::getDocumentById($data['id']);
         if ($docObj->cat_id != $newMainCatId) {
             $oldFieldGroup = JUDownloadHelper::getCategoryById($docObj->cat_id);
             $newFieldGroup = JUDownloadHelper::getCategoryById($newMainCatId);
             if ($oldFieldGroup->fieldgroup_id != $newFieldGroup->fieldgroup_id) {
                 $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_categories AS c ON (c.fieldgroup_id = field.group_id AND field.group_id != 1)");
                 $query->join("", "#__judownload_documents_xref AS dxref ON (dxref.cat_id = c.id AND dxref.main = 1)");
                 $query->join("", "#__judownload_documents AS d ON dxref.doc_id = d.id");
                 $query->where("d.id = " . $data['id']);
                 $query->group('field.id');
                 $query->order('field.ordering');
                 $db->setQuery($query);
                 $fields = $db->loadObjectList();
                 foreach ($fields as $field) {
                     $fieldObj = JUDownloadFrontHelperField::getField($field, $data['id']);
                     $fieldObj->onDelete();
                 }
             }
         }
     }
     $iconPath = '';
     $iconFieldId = $this->field_name_id_array['icon'];
     if (!empty($data['icon'])) {
         $iconPath = $data['icon'];
         unset($data['icon']);
     }
     if (!empty($fieldsData[$iconFieldId])) {
         $iconPath = $fieldsData[$iconFieldId];
         unset($fieldsData[$iconFieldId]);
     }
     $table = JTable::getInstance("Document", "JUDownloadTable");
     if (!$table->bind($data) || !$table->check() || !$table->store()) {
         return array('doc_id' => 0, 'messages' => $table->getErrors());
     }
     $docId = $table->id;
     $categoriesField = new JUDownloadFieldCore_categories(null, $docId);
     $categoriesField->is_new_doc = $isInsert;
     $result = $categoriesField->storeValue($fieldsData[$this->field_name_id_array['cat_id']]);
     if (!$result) {
         $table->delete($docId);
         return array('doc_id' => 0, 'messages' => $db->getErrorMsg());
     }
     $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_categories AS c ON (c.fieldgroup_id = field.group_id OR field.group_id = 1)");
     $query->join("", "#__judownload_documents_xref AS dxref ON (dxref.cat_id = c.id AND dxref.main = 1)");
     $query->join("", "#__judownload_documents AS d ON dxref.doc_id = d.id");
     $query->where("d.id = {$docId}");
     $query->where("field.field_name != 'id'");
     $query->where("field.field_name != 'cat_id'");
     $query->group('field.id');
     $query->order('ordering ASC');
     $db->setQuery($query);
     $fields = $db->loadObjectList();
     $docObj = JUDownloadHelper::getDocumentById($docId);
     foreach ($fields as $field) {
         if (isset($fieldsData[$field->id])) {
             $fieldObj = JUDownloadFrontHelperField::getField($field, $docObj);
             $fieldObj->fields_data = $fieldsData;
             $fieldValue = $fieldsData[$field->id];
             $fieldObj->is_new_doc = $isInsert;
             $fieldValue = $fieldObj->onImportDocument($fieldValue);
             $fieldObj->storeValue($fieldValue);
         }
     }
     if ($iconPath) {
         $iconPath = JUDownloadHelper::getPhysicalPath($iconPath);
         if (!$iconPath) {
             $messages[] = JText::sprintf('COM_JUDOWNLOAD_CSV_PROCESS_FILE_S_NOT_FOUND', $iconPath);
         } else {
             if ($data['id'] > 0) {
                 if ($table->icon) {
                     if (JFile::exists($iconDir . $table->icon)) {
                         JFile::delete($iconDir . $table->icon);
                         JFile::delete($originalDir . $table->icon);
                     }
                 }
             }
             $iconName = basename($iconPath);
             $iconName = $docId . "_" . JUDownloadHelper::fileNameFilter($iconName);
             if (JFile::copy($iconPath, $originalDir . $iconName) && JUDownloadHelper::renderImages($originalDir . $iconName, $iconDir . $iconName, 'document_icon', true, null, $data['id'])) {
                 $table->icon = $iconName;
                 $table->store();
             }
         }
     }
     $imageTable = JTable::getInstance("Image", "JUDownloadTable");
     if (!empty($gallery)) {
         $dir_document_ori = JPATH_SITE . "/" . JUDownloadFrontHelper::getDirectory("document_original_image_directory", "media/com_judownload/images/gallery/original/") . $docId . "/";
         $dir_document_small = JPATH_SITE . "/" . JUDownloadFrontHelper::getDirectory("document_small_image_directory", "media/com_judownload/images/gallery/small/") . $docId . "/";
         $dir_document_big = JPATH_SITE . "/" . JUDownloadFrontHelper::getDirectory("document_big_image_directory", "media/com_judownload/images/gallery/big/") . $docId . "/";
         if (!JFolder::exists($dir_document_ori)) {
             $file_index = $dir_document_ori . 'index.html';
             $buffer = "<!DOCTYPE html><title></title>";
             JFile::write($file_index, $buffer);
         }
         if (!JFolder::exists($dir_document_small)) {
             $file_index = $dir_document_small . 'index.html';
             $buffer = "<!DOCTYPE html><title></title>";
             JFile::write($file_index, $buffer);
         }
         if (!JFolder::exists($dir_document_big)) {
             $file_index = $dir_document_big . 'index.html';
             $buffer = "<!DOCTYPE html><title></title>";
             JFile::write($file_index, $buffer);
         }
         $image_ordering = 1;
         $date = JFactory::getDate();
         foreach ($gallery as $imagePath) {
             $imagePath = JUDownloadHelper::getPhysicalPath($imagePath);
             if (!$imagePath) {
                 $messages[] = JText::sprintf('COM_JUDOWNLOAD_CSV_PROCESS_FILE_S_NOT_FOUND', $imagePath);
                 continue;
             }
             $imageName = basename($imagePath);
             $imageName = JUDownloadHelper::generateImageNameByDocument($docId, $imageName);
             if (JFile::copy($imagePath, $dir_document_ori . $imageName) && JUDownloadHelper::renderImages($dir_document_ori . $imageName, $dir_document_small . $imageName, 'document_small', true, null, $data['id']) && JUDownloadHelper::renderImages($dir_document_ori . $imageName, $dir_document_big . $imageName, 'document_big', true, null, $data['id'])) {
                 $imageObj = new stdClass();
                 $imageObj->id = 0;
                 $imageObj->file_name = $imageName;
                 $imageObj->doc_id = $docId;
                 $imageObj->ordering = $image_ordering;
                 $imageObj->created = $date->toSql();
                 $imageObj->published = 1;
                 if (!$imageTable->bind($imageObj) || !$imageTable->check() || !$imageTable->store()) {
                     $messages[] = implode(' | ', $imageTable->getErrors());
                     JFile::delete($dir_document_ori . $imageName);
                     JFile::delete($dir_document_small . $imageName);
                     JFile::delete($dir_document_big . $imageName);
                 } else {
                     $image_ordering++;
                 }
             } else {
                 $messages[] = JText::sprintf('COM_JUDOWNLOAD_CSV_PROCESS_CAN_NOT_COPY_FILE_FROM_S_TO_S', $imagePath, $dir_document_ori . $imageName);
             }
         }
     }
     $fileTable = JTable::getInstance("File", "JUDownloadTable");
     if (!empty($files)) {
         $file_directory = JPATH_SITE . "/" . JUDownloadFrontHelper::getDirectory("file_directory", "media/com_judownload/files/");
         if (!JFolder::exists($file_directory . $docId . "/")) {
             $file_index = $file_directory . $docId . "/index.html";
             $buffer = "<!DOCTYPE html><title></title>";
             JFile::write($file_index, $buffer);
         }
         $file_ordering = 1;
         foreach ($files as $filePath) {
             $filePath = JUDownloadHelper::getPhysicalPath($filePath);
             if (!$filePath) {
                 $messages[] = JText::sprintf('COM_JUDOWNLOAD_CSV_PROCESS_FILE_S_NOT_FOUND', $filePath);
                 continue;
             }
             $query = $db->getQuery(true);
             $query->select('COUNT(*)')->from('#__judownload_files')->where('doc_id = ' . $docId)->where('`rename` = ' . $db->quote(basename($filePath)));
             $db->setQuery($query);
             $count = $db->loadResult();
             if ($count) {
                 $messages[] = JText::sprintf('COM_JUDOWNLOAD_CSV_PROCESS_EXISTED_FILE_S', $filePath);
                 continue;
             }
             $fileObject = array();
             $fileObject['id'] = 0;
             $fileObject['doc_id'] = $docId;
             $fileObject['ordering'] = $file_ordering;
             $fileObject['rename'] = basename($filePath);
             $fileObject['file_name'] = md5($fileObject['rename'] . JUDownloadHelper::generateRandomString(10)) . "." . JFile::getExt($fileObject['rename']);
             $fileObject['published'] = 1;
             $this->addFileInfo($fileObject, $filePath, $file_directory);
             $dest = $file_directory . $docId . "/" . $fileObject['file_name'];
             if ($fileTable->bind($fileObject) && $fileTable->check() && $fileTable->store()) {
                 if (!JFile::copy($filePath, $dest)) {
                     $fileTable->delete($fileTable->id);
                     $messages[] = JText::sprintf('COM_JUDOWNLOAD_CSV_PROCESS_CAN_NOT_COPY_FILE_FROM_S_TO_S', $filePath, $dest);
                 }
                 $file_ordering++;
             } else {
                 $messages[] = implode(' | ', $fileTable->getErrors());
             }
         }
     }
     if (!empty($relatedDocs)) {
         $ordering = 1;
         foreach ($relatedDocs as $relatedDocId) {
             $document = JUDownloadHelper::getDocumentById($relatedDocId);
             if ($document) {
                 $relatedDocObj = new stdClass();
                 $relatedDocObj->id = 0;
                 $relatedDocObj->doc_id = $docId;
                 $relatedDocObj->doc_id_related = $relatedDocId;
                 $relatedDocObj->ordering = $ordering;
                 $query = $db->getQuery(true);
                 $query->select('id')->from('#__judownload_documents_relations')->where('doc_id = ' . $docId)->where('doc_id_related = ' . $relatedDocId);
                 $db->setQuery($query);
                 $existedId = $db->loadResult();
                 if ($existedId) {
                     $relatedDocObj->id = $existedId;
                     $db->updateObject('#__judownload_documents_relations', $relatedDocObj, 'id');
                 } else {
                     $db->insertObject('#__judownload_documents_relations', $relatedDocObj);
                 }
                 $relationId = $db->insertid();
                 if ($relationId > 0) {
                     $ordering++;
                 } else {
                     $messages[] = $db->getErrorMsg();
                 }
             } else {
                 $messages[] = JText::sprintf('COM_JUDOWNLOAD_CSV_PROCESS_INVALID_RELATED_DOCUMENT_N', $relatedDocId);
             }
         }
     }
     return array('doc_id' => $docId, 'messages' => $messages);
 }