public function initialize() { $thread = $this->getProperty('thread'); if (empty($thread)) { return $this->modx->lexicon('quip.thread_err_ns'); } $this->thread = $this->modx->getObject($this->classKey, $thread); if (empty($this->thread)) { return $this->modx->lexicon('quip.thread_err_nf'); } if (!$this->thread->checkPolicy('truncate')) { return $this->modx->lexicon('access_denied'); } return parent::initialize(); }
/** * Gets the current thread * * @static * @param modX $modx * @param quipThread $thread * @param int $parent * @param string $ids * @param string $sortBy * @param string $sortByAlias * @param string $sortDir * @return array */ public static function getThread(modX $modx, quipThread $thread, $parent = 0, $ids = '', $sortBy = 'rank', $sortByAlias = 'quipComment', $sortDir = 'ASC') { $c = $modx->newQuery('quipComment'); $c->innerJoin('quipThread', 'Thread'); $c->leftJoin('quipCommentClosure', 'Descendants'); $c->leftJoin('quipCommentClosure', 'RootDescendant', 'RootDescendant.descendant = quipComment.id AND RootDescendant.ancestor = 0'); $c->leftJoin('quipCommentClosure', 'Ancestors'); $c->leftJoin('modUser', 'Author'); $c->leftJoin('modResource', 'Resource'); $c->where(array('quipComment.thread' => $thread->get('name'), 'quipComment.deleted' => false)); if (!$thread->checkPolicy('moderate')) { $c->andCondition(array('quipComment.approved' => true), null, 2); } if (!empty($parent)) { $c->where(array('Descendants.ancestor' => $parent)); } $total = $modx->getCount('quipComment', $c); if (!empty($ids)) { $c->where(array('Descendants.ancestor:IN' => $ids)); } $c->select($modx->getSelectColumns('quipComment', 'quipComment')); $c->select(array('Thread.resource', 'Thread.idprefix', 'Thread.existing_params', 'RootDescendant.depth', 'Author.username', 'Resource.pagetitle', 'Resource.context_key')); $c->sortby($modx->escape($sortByAlias) . '.' . $modx->escape($sortBy), $sortDir); $comments = $modx->getCollection('quipComment', $c); return array('results' => $comments, 'total' => $total); }
/** * Prepare a list of Comment ids for pagination * @return array */ public function preparePaginationIds() { /* if pagination is on, get IDs of root comments so can limit properly */ $this->ids = array(); $limit = $this->getProperty('limit', 0); if (!empty($limit)) { $c = $this->modx->newQuery('quipComment'); $c->select($this->modx->getSelectColumns('quipComment', 'quipComment', '', array('id'))); $c->where(array('quipComment.thread' => $this->thread->get('name'), 'quipComment.deleted' => false, 'quipComment.parent' => 0)); if (!$this->thread->checkPolicy('moderate')) { $c->where(array('quipComment.approved' => true, 'OR:quipComment.author:=' => $this->modx->user->get('id'))); } $c->sortby($this->getProperty('sortByAlias', 'quipComment') . '.' . $this->getProperty('sortBy', 'rank'), $this->getProperty('sortDir', 'ASC')); $this->setPlaceholder('rootTotal', $this->modx->getCount('quipComment', $c)); $c->limit($limit, $this->getProperty('start', 0)); $comments = $this->modx->getCollection('quipComment', $c); $this->ids = array(); /** @var quipComment $comment */ foreach ($comments as $comment) { $this->ids[] = $comment->get('id'); } $this->ids = array_unique($this->ids); } return $this->ids; }
public function checkPermissions() { /* get parent and auth */ $requireAuth = $this->getProperty('requireAuth', false, 'isset'); $requireUsergroups = $this->getProperty('requireUsergroups', false, 'isset'); $this->parentThread = $this->modx->getOption('quip_parent', $_REQUEST, $this->getProperty('parent', 0)); $this->hasAuth = $this->modx->user->hasSessionContext($this->modx->context->get('key')) || $this->getProperty('debug', false, 'isset') || empty($requireAuth); if (!empty($requireUsergroups)) { $requireUsergroups = explode(',', $this->getProperty('requireUsergroups', false, 'isset')); $this->hasAuth = $this->modx->user->isMember($requireUsergroups); } $this->isModerator = $this->thread->checkPolicy('moderate'); }
/** * @param array $list * @return array */ public function beforeIteration(array $list) { $canApprove = $this->modx->hasPermission('quip.comment_approve'); $canRemove = $this->modx->hasPermission('quip.comment_remove'); $canUpdate = $this->modx->hasPermission('quip.comment_update'); if ($this->thread) { $canApprove = $canApprove && $this->thread->checkPolicy('comment_approve'); $canRemove = $canRemove && $this->thread->checkPolicy('comment_remove'); $canUpdate = $canUpdate && $this->thread->checkPolicy('comment_update'); } $cls = array(); if ($canApprove) { $cls[] = 'papprove'; } if ($canUpdate) { $cls[] = 'pupdate'; } if ($canRemove) { $cls[] = 'premove'; } $this->defaultCls = implode(',', $cls); return $list; }