Esempio n. 1
0
 /**
  * Gets a modResource collection that matches the search terms
  *
  * @param string $str The string to use to search with.
  * @param array $scriptProperties
  * @return array An array of modResource results of the search.
  */
 public function getSearchResults($str = '', array $scriptProperties = array())
 {
     if (!empty($str)) {
         $this->searchString = strip_tags($this->modx->sanitizeString($str));
     }
     $this->loadDriver($scriptProperties);
     $this->response = $this->driver->search($str, $scriptProperties);
     $this->searchResultsCount = $this->response['total'];
     $this->docs = $this->response['results'];
     return $this->response;
 }
    /**
     * Get the getPage and getArchives call to display listings of posts on the container.
     *
     * @param string $placeholderPrefix
     * @return string
     */
    public function getPostListingCall($placeholderPrefix = '')
    {
        $settings = $this->getContainerSettings();
        $where = array('class_key' => 'Article');
        if (!empty($_REQUEST['arc_user'])) {
            $userPk = $this->xpdo->sanitizeString($_REQUEST['arc_user']);
            if (intval($userPk) == 0) {
                /** @var modUser $user */
                $user = $this->xpdo->getObject('modUser', array('username' => $userPk));
                if ($user) {
                    $userPk = $user->get('id');
                } else {
                    $userPk = false;
                }
            }
            if ($userPk !== false) {
                $where['createdby:='] = $userPk;
                $this->set('cacheable', false);
            }
        }
        $output = '[[!getPage?
          &elementClass=`modSnippet`
          &element=`getArchives`
          &makeArchive=`0`
          &cache=`1`
          &parents=`' . $this->get('id') . '`
          &where=`' . $this->xpdo->toJSON($where) . '`
          &showHidden=`1`
          &includeContent=`1`
          &includeTVs=`' . $this->xpdo->getOption('archivesIncludeTVs', $settings, 0) . '`
          &includeTVsList=`' . $this->xpdo->getOption('includeTVsList', $settings, '') . '`
          &processTVs=`' . $this->xpdo->getOption('archivesProcessTVs', $settings, 0) . '`
          &processTVsList=`' . $this->xpdo->getOption('processTVsList', $settings, '') . '`
          &tagKey=`articlestags`
          &tagSearchType=`contains`
          &sortby=`' . $this->xpdo->getOption('sortBy', $settings, 'publishedon') . '`
          &sortdir=`' . $this->xpdo->getOption('sortDir', $settings, 'DESC') . '`
          &tpl=`' . $this->xpdo->getOption('tplArticleRow', $settings, 'sample.ArticleRowTpl') . '`

          &limit=`' . $this->xpdo->getOption('articlesPerPage', $settings, 10) . '`
          &pageLimit=`' . $this->xpdo->getOption('pageLimit', $settings, 5) . '`
          &pageVarKey=`' . $this->xpdo->getOption('pageVarKey', $settings, 'page') . '`
          &pageNavVar=`' . $this->xpdo->getOption('pageNavVar', $settings, 'page.nav') . '`
          &totalVar=`' . $this->xpdo->getOption('pageTotalVar', $settings, 'total') . '`
          &offset=`' . $this->xpdo->getOption('pageOffset', $settings, 0) . '`

          &pageNavTpl=`' . $this->xpdo->getOption('pageNavTpl', $settings, '<li[[+classes]]><a[[+classes]][[+title]] href="[[+href]]">[[+pageNo]]</a></li>') . '`
          &pageActiveTpl=`' . $this->xpdo->getOption('pageActiveTpl', $settings, '<li[[+activeClasses]]><a[[+activeClasses:default=` class="active"`]][[+title]] href="[[+href]]">[[+pageNo]]</a></li>') . '`
          &pageFirstTpl=`' . $this->xpdo->getOption('pageFirstTpl', $settings, '<li class="control"><a[[+classes]][[+title]] href="[[+href]]">First</a></li>') . '`
          &pageLastTpl=`' . $this->xpdo->getOption('pageLastTpl', $settings, '<li class="control"><a[[+classes]][[+title]] href="[[+href]]">Last</a></li>') . '`
          &pagePrevTpl=`' . $this->xpdo->getOption('pagePrevTpl', $settings, '<li class="control"><a[[+classes]][[+title]] href="[[+href]]">&lt;&lt;</a></li>') . '`
          &pageNextTpl=`' . $this->xpdo->getOption('pageNextTpl', $settings, '<li class="control"><a[[+classes]][[+title]] href="[[+href]]">&gt;&gt;</a></li>') . '`

          ' . $this->xpdo->getOption('otherGetArchives', $settings, '') . '
        ]]';
        $this->xpdo->setPlaceholder($placeholderPrefix . 'articles', $output);
        $this->xpdo->setPlaceholder($placeholderPrefix . 'paging', '[[!+page.nav:notempty=`
<div class="paging">
<ul class="pageList">
  [[!+page.nav]]
</ul>
</div>
`]]');
        return $output;
    }