public function delete($pk = null, $children = true) { $k = $this->_tbl_key; $pk = is_null($pk) ? $this->{$k} : $pk; if ($this->_trackAssets) { $name = $this->_getAssetName(); $asset = JTable::getInstance('Asset'); if (!$asset->_lock()) { return false; } if ($asset->loadByName($name)) { if (!$asset->delete(null, $children)) { $this->setError($asset->getError()); $asset->_unlock(); return false; } $asset->_unlock(); } else { $this->setError($asset->getError()); $asset->_unlock(); return false; } } if (!($node = $this->_getNode($pk))) { $this->_unlock(); return false; } $commentObjList = array(); if ($children) { $tree = $this->getTree($pk); foreach ($tree as $comment) { $this->_delete($comment); $commentObjList[] = JUDownloadFrontHelperComment::getCommentObject($comment->id); } if (!$this->_lock()) { return false; } $query = $this->_db->getQuery(true); $query->delete(); $query->from($this->_tbl); $query->where('lft BETWEEN ' . (int) $node->lft . ' AND ' . (int) $node->rgt); $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED'); $query = $this->_db->getQuery(true); $query->update($this->_tbl); $query->set('lft = lft - ' . (int) $node->width); $query->where('lft > ' . (int) $node->rgt); $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED'); $query = $this->_db->getQuery(true); $query->update($this->_tbl); $query->set('rgt = rgt - ' . (int) $node->width); $query->where('rgt > ' . (int) $node->rgt); $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED'); } else { $this->_delete($node); if (!$this->_lock()) { return false; } $query = $this->_db->getQuery(true); $query->delete(); $query->from($this->_tbl); $query->where('lft = ' . (int) $node->lft); $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED'); $query = $this->_db->getQuery(true); $query->update($this->_tbl); $query->set('lft = lft - 1'); $query->set('rgt = rgt - 1'); $query->set('level = level - 1'); $query->where('lft BETWEEN ' . (int) $node->lft . ' AND ' . (int) $node->rgt); $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED'); $query = $this->_db->getQuery(true); $query->update($this->_tbl); $query->set('parent_id = ' . (int) $node->parent_id); $query->where('parent_id = ' . (int) $node->{$k}); $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED'); $query = $this->_db->getQuery(true); $query->update($this->_tbl); $query->set('lft = lft - 2'); $query->where('lft > ' . (int) $node->rgt); $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED'); $query = $this->_db->getQuery(true); $query->update($this->_tbl); $query->set('rgt = rgt - 2'); $query->where('rgt > ' . (int) $node->rgt); $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED'); } $this->_unlock(); if ($children && !empty($commentObjList)) { foreach ($commentObjList as $commentObj) { if ($commentObj->approved == 0) { JUDownloadFrontHelperMail::sendEmailByEvent('comment.reject', $commentObj->id, get_object_vars($commentObj)); } elseif (JUDownloadFrontHelperModerator::isModerator()) { JUDownloadFrontHelperMail::sendEmailByEvent('comment.moddelete', $commentObj->id, get_object_vars($commentObj)); } else { JUDownloadFrontHelperMail::sendEmailByEvent('comment.userdelete', $commentObj->id, get_object_vars($commentObj)); } } } else { $commentObj = JUDownloadFrontHelperComment::getCommentObject($node->id); if ($commentObj->approved == 0) { JUDownloadFrontHelperMail::sendEmailByEvent('comment.reject', $commentObj->id, get_object_vars($commentObj)); } elseif (JUDownloadFrontHelperModerator::isModerator()) { JUDownloadFrontHelperMail::sendEmailByEvent('comment.moddelete', $commentObj->id, get_object_vars($commentObj)); } else { JUDownloadFrontHelperMail::sendEmailByEvent('comment.userdelete', $commentObj->id, get_object_vars($commentObj)); } } return true; }
<?php echo JText::_('COM_JUDOWNLOAD_FIELD_ID'); ?> </th> </tr> </thead> <tbody> <?php if (is_array($this->items) && count($this->items)) { // @todo recheck hosting require_once JPATH_SITE . '/components/com_judownload/models/document.php'; $documentModel = JModelLegacy::getInstance('Document', 'JUDownloadModel'); foreach ($this->items AS $i => $item) { $canEdit = JUDownloadFrontHelperModerator::checkModeratorCanDoWithComment($item->id, 'comment_edit'); ?> <tr> <td class="center"> <input type="checkbox" checked="checked" class="judl-cb" name="cid[]" value="<?php echo $item->id; ?>" id="judl-cb-<?php echo $i; ?>"/> </td> <td> <?php if ($item->checked_out) { if ($item->checkout_link) { $checkedOutUser = JFactory::getUser($item->checked_out); $checkedOutTime = JHtml::_('date', $item->checked_out_time);
protected function getValue() { $app = JFactory::getApplication(); if ($app->isSite() && isset($this->doc->total_comments) && !is_null($this->doc->total_comments)) { return $this->doc->total_comments; } $user = JFactory::getUser(); $db = JFactory::getDbo(); if ($app->isSite()) { $query = $db->getQuery(true); $query->select('COUNT(*)'); $query->from('#__judownload_comments AS cm'); $query->where('doc_id =' . $this->doc_id); $query->where('level = 1'); $query->where('approved = 1'); $moderator = JUDownloadFrontHelperModerator::getModerator($this->doc->cat_id); $getAll = false; if ($user->authorise('core.admin', 'com_judownload')) { $getAll = true; } if (is_object($moderator)) { if ($moderator->comment_edit || $moderator->comment_edit_state || $moderator->comment_delete) { $getAll = true; } } if (!$getAll) { $query->where('published = 1'); $params = JUDownloadHelper::getParams(null, $this->doc_id); $negative_vote_comment = $params->get('negative_vote_comment'); if (is_numeric($negative_vote_comment) && $negative_vote_comment > 0) { $query->where('(total_votes - helpful_votes) <' . $negative_vote_comment); } } } else { $query = $db->getQuery(true); $query->select('COUNT(*)'); $query->from('#__judownload_comments AS cm'); $query->where('doc_id =' . $this->doc_id); $query->where('level = 1'); $query->where('approved = 1'); } $db->setQuery($query); $totalComments = $db->loadResult(); return $totalComments; }
protected function canEditState($record) { $rootComment = JUDownloadFrontHelperComment::getRootComment(); if (isset($record->id) && $record->id == $rootComment->id) { return false; } $app = JFactory::getApplication(); if ($app->isSite()) { $modCanEditState = JUDownloadFrontHelperModerator::checkModeratorCanDoWithComment($record->id, 'comment_edit_state'); if ($modCanEditState) { return true; } return false; } return parent::canEditState($record); }
public static function checkPassword($documentObject) { $isDocumentOwner = JUDownloadFrontHelperPermission::isDocumentOwner($documentObject->id); $isModerator = JUDownloadFrontHelperModerator::isModerator(); if ($isDocumentOwner) { $asset = 'com_judownload.document.' . $documentObject->id; $user = JFactory::getUser(); if ($user->authorise('judl.document.download.own.no_restrict', $asset)) { return true; } } if ($isModerator) { $mainCategory = JUDownloadFrontHelperCategory::getMainCategory($documentObject->id); $modCanDownload = JUDownloadFrontHelperModerator::checkModeratorCanDoWithDocument($mainCategory->id, 'document_download'); if ($modCanDownload) { return true; } if ($documentObject->approved < 1) { $modCanApproval = JUDownloadFrontHelperModerator::checkModeratorCanDoWithDocument($mainCategory->id, 'document_approve'); if ($modCanApproval) { return true; } } } $session = JFactory::getSession(); if ($session->get('judl-download-password-' . $documentObject->id, '') === $documentObject->download_password) { return true; } else { return false; } }
public function getTotalChildComments($parentId) { $documentId = (int) $this->getState('document.id'); $mainCategoryId = JUDownloadFrontHelperCategory::getMainCategoryId($documentId); $user = JFactory::getUser(); $params = $this->getState('params'); $db = $this->getDbo(); $query = $db->getQuery(true); $query->select('COUNT(*)'); $query->from('#__judownload_comments AS cm'); $query->where('cm.approved = 1'); $query->where('cm.parent_id = ' . $parentId); $maxLevel = $params->get('max_comment_level', 5); $query->where('cm.level <= ' . $maxLevel); $getAll = false; $isModerator = JUDownloadFrontHelperModerator::isModerator(); if ($isModerator) { $moderator = JUDownloadFrontHelperModerator::getModerator($mainCategoryId); if ($user->authorise('core.admin', 'com_judownload') || ($moderator && ($moderator->comment_edit || $moderator->comment_edit_state || $moderator->comment_delete))) { $getAll = true; } } if (!$getAll) { $query->where('cm.published = 1'); $negative_vote_comment = $params->get('negative_vote_comment'); if (is_numeric($negative_vote_comment) && $negative_vote_comment > 0) { $query->where('(cm.total_votes - cm.helpful_votes) <' . $negative_vote_comment); } } $db->setQuery($query); return $db->loadResult(); }
<span class="stat-info"><?php echo $this->totalCollections ?></span> <span> <a href="<?php echo $this->collections; ?>"><?php echo JText::_('COM_JUDOWNLOAD_COLLECTIONS'); ?></a></span> </li> <li> <span class="stat-info"><?php echo $this->totalSubscriptions ?></span> <span> <a href="<?php echo $this->subscriptions; ?>"><?php echo JText::_('COM_JUDOWNLOAD_SUBSCRIPTIONS'); ?></a></span> </li> </ul> </div> </div> </div> <?php $isModerator = JUDownloadFrontHelperModerator::isModerator(); if ($isModerator) { ?> <div id="quick-box-wrapper"> <div class="quick-box"> <div class="quick-box-head"> <div class="quick-box-title"><?php echo JText::_('COM_JUDOWNLOAD_MODERATOR_AREA'); ?></div> </div> <div class="quick-box-body clearfix"> <ul class="stat-list"> <li> <span class="stat-info"><?php echo $this->total_document_mod_can_view; ?></span> <span> <a href="<?php echo $this->documents_link; ?>"><?php echo JText::_('COM_JUDOWNLOAD_DOCUMENTS'); ?></a></span>
public static function canCheckInComment($commentId) { JTable::addIncludePath(JPATH_ADMINISTRATOR . "/components/com_judownload/tables"); $commentTable = JTable::getInstance('Comment', 'JUDownloadTable'); $commentTable->load($commentId); if (property_exists($commentTable, 'checked_out') && property_exists($commentTable, 'checked_out_time') && $commentTable->checked_out > 0) { $user = JFactory::getUser(); $isModerator = JUDownloadFrontHelperModerator::isModerator(); $isCommentOwner = JUDownloadFrontHelperPermission::isCommentOwner($commentId); if ($isModerator || $isCommentOwner || $commentTable->checked_out == $user->id) { $canEditComment = JUDownloadFrontHelperPermission::canEditComment($commentId); if ($canEditComment) { return true; } } } return false; }
public static function optimizeListDocumentQuery(&$query, $massSelect = false) { $user = JFactory::getUser(); $query->select('cmain.id AS cat_id'); $query->join('', '#__judownload_documents_xref AS dxmain ON d.id = dxmain.doc_id AND dxmain.main = 1'); $query->join('', '#__judownload_categories AS cmain ON cmain.id = dxmain.cat_id'); $categoryIdArrayCanAccess = JUDownloadFrontHelperCategory::getAccessibleCategoryIds(); if (is_array($categoryIdArrayCanAccess) && count($categoryIdArrayCanAccess) > 0) { $query->where('cmain.id IN(' . implode(",", $categoryIdArrayCanAccess) . ')'); } else { $query->where('cmain.id IN("")'); } if ($massSelect) { $query->select('(SELECT COUNT(*) FROM #__judownload_files AS f WHERE f.doc_id = d.id AND f.published = 1) AS total_files'); $commentsField = new JUDownloadFieldCore_comments(); if ($commentsField->canView(array("view" => "list"))) { $isModerator = JUDownloadFrontHelperModerator::isModerator(); if (!$isModerator && !$user->authorise('core.admin', 'com_judownload')) { $params = JUDownloadHelper::getParams(); $negative_vote_comment = $params->get('negative_vote_comment'); if (is_numeric($negative_vote_comment) && $negative_vote_comment > 0) { $query->select('(SELECT COUNT(*) FROM #__judownload_comments AS cm WHERE cm.doc_id = d.id AND cm.approved = 1 AND cm.published = 1 AND cm.level = 1 AND (cm.total_votes - cm.helpful_votes) < ' . $negative_vote_comment . ' ) AS total_comments'); } else { $query->select('(SELECT COUNT(*) FROM #__judownload_comments AS cm WHERE cm.doc_id = d.id AND cm.approved = 1 AND cm.published = 1 AND cm.level = 1) AS total_comments'); } } } $subscriptionsField = new JUDownloadFieldCore_subscriptions(); if ($subscriptionsField->canView(array("view" => "list"))) { $query->select('(SELECT COUNT(*) FROM #__judownload_subscriptions AS sub WHERE sub.item_id = d.id AND sub.type = "document" AND sub.published = 1) AS total_subscriptions'); } $reportsField = new JUDownloadFieldCore_reports(); if ($reportsField->canView(array("view" => "list"))) { $query->select('(SELECT COUNT(*) FROM #__judownload_reports AS r WHERE r.item_id = d.id AND r.type = "document") AS total_reports'); } $categoriesField = new JUDownloadFieldCore_categories(); if ($categoriesField->canView(array("view" => "list"))) { $query->select('(SELECT GROUP_CONCAT(catids.id ORDER BY dx_catids.main DESC, dx_catids.ordering ASC SEPARATOR ",") FROM (#__judownload_categories AS catids JOIN #__judownload_documents_xref AS dx_catids ON catids.id = dx_catids.cat_id) WHERE d.id = dx_catids.doc_id GROUP BY d.id) AS cat_ids'); $query->select('(SELECT GROUP_CONCAT(cattitles.title ORDER BY dx_cattitles.main DESC, dx_cattitles.ordering ASC SEPARATOR "|||") FROM (#__judownload_categories AS cattitles JOIN #__judownload_documents_xref AS dx_cattitles ON cattitles.id = dx_cattitles.cat_id) WHERE d.id = dx_cattitles.doc_id GROUP BY d.id) AS cat_titles'); } $tagsField = new JUDownloadFieldCore_tags(); if ($tagsField->canView(array("view" => "list"))) { $query->select('IFNULL ((SELECT GROUP_CONCAT(tagids.id ORDER BY tx_tagids.ordering ASC SEPARATOR ",") FROM (#__judownload_tags AS tagids JOIN #__judownload_tags_xref AS tx_tagids ON tagids.id = tx_tagids.tag_id) WHERE d.id = tx_tagids.doc_id GROUP BY d.id), "") AS tag_ids'); $query->select('IFNULL ((SELECT GROUP_CONCAT(tagtitles.title ORDER BY tx_tagtitles.ordering ASC SEPARATOR "|||") FROM (#__judownload_tags AS tagtitles JOIN #__judownload_tags_xref AS tx_tagtitles ON tagtitles.id = tx_tagtitles.tag_id) WHERE d.id = tx_tagtitles.doc_id GROUP BY d.id), "") AS tag_titles'); } $app = JFactory::getApplication(); $accessLevel = implode(',', $user->getAuthorisedViewLevels()); $db = JFactory::getDbo(); $date = JFactory::getDate(); $nullDate = $db->quote($db->getNullDate()); $nowDate = $db->quote($date->toSql()); $fieldQuery = $db->getQuery(true); $fieldQuery->select('field.id'); $fieldQuery->from('#__judownload_fields AS field'); $fieldQuery->where('field.field_name = ""'); $fieldQuery->where('field.list_view = 1'); $fieldQuery->where('field.published = 1'); $fieldQuery->where('field.publish_up <= ' . $nowDate); $fieldQuery->where('(field.publish_down = ' . $nullDate . ' OR field.publish_down > ' . $nowDate . ')'); $fieldQuery->where('(field.access IN (' . $accessLevel . ') OR field.who_can_download_can_access = 1)'); $view = $app->input->get('view', ''); if ($view == 'category' || $view == 'tree') { $cat_id = $app->input->getInt('id', 0); $category = JUDownloadHelper::getCategoryById($cat_id); if (is_object($category)) { $fieldQuery->where('field.group_id = ' . $category->fieldgroup_id); } } else { $fieldQuery->join('', '#__judownload_categories AS c ON (field.group_id = c.fieldgroup_id OR field.group_id = 1)'); if (is_array($categoryIdArrayCanAccess) && count($categoryIdArrayCanAccess) > 0) { $fieldQuery->where('c.id IN(' . implode(",", $categoryIdArrayCanAccess) . ')'); } else { $fieldQuery->where('c.id IN("")'); } } $fieldQuery->join('', '#__judownload_fields_groups AS field_group ON field.group_id = field_group.id'); $fieldQuery->where('field_group.published = 1'); $fieldQuery->where('field_group.access IN (' . $accessLevel . ')'); $fieldQuery->group('field.id'); $db->setQuery($fieldQuery); $fields = $db->loadObjectList(); foreach ($fields AS $field) { $query->select('IFNULL (fields_values_' . $field->id . '.value, "") AS field_values_' . $field->id); $query->join('LEFT', '#__judownload_fields_values AS fields_values_' . $field->id . ' ON fields_values_' . $field->id . '.doc_id = d.id AND fields_values_' . $field->id . '.field_id = ' . $field->id); } } }
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]; }
public function canSubmit($userID = null) { if (!$this->isPublished()) { return false; } $app = JFactory::getApplication(); if ($app->isAdmin()) { return true; } else { if ($userID) { $user = JFactory::getUser($userID); } else { $user = JFactory::getUser(); } if ($app->input->getInt('approve', 0) == 1) { if (is_object($this->doc) && $this->doc->approved <= 0) { $modCanApprove = JUDownloadFrontHelperModerator::checkModeratorCanDoWithDocument($this->doc->cat_id, 'document_approve'); if ($modCanApprove) { return true; } } } $approvalOption = $app->input->post->get("approval_option"); $approvalOptionArray = array("ignore", "approve", "delete"); if (in_array($approvalOption, $approvalOptionArray)) { if (is_object($this->doc) && $this->doc->approved <= 0) { $categoriesField = new JUDownloadFieldCore_categories(); $newMainCategory = $this->fields_data[$categoriesField->id]['main']; if ($newMainCategory) { $modCanApprove = JUDownloadFrontHelperModerator::checkModeratorCanDoWithDocument($newMainCategory, 'document_approve'); if ($modCanApprove) { return true; } } } } if ($user) { $assetName = 'com_judownload.field.' . (int) $this->id; return $user->authorise("judl.field.value.submit", $assetName); } } return false; }