Example #1
0
 /**
  * Returns templates link for pagination
  *
  * @param string $url
  * @param int $page
  * @param string $tpl
  *
  * @return string $href
  */
 public function makePageLink($url = '', $page = 1, $tpl = '')
 {
     if (empty($url)) {
         $url = $this->getBaseUrl();
     }
     $link = $pcre = '';
     if (!empty($this->pdoTools->config['pageLinkScheme'])) {
         $pls = $this->pdoTools->makePlaceholders(array('pageVarKey' => $this->pdoTools->config['pageVarKey'], 'page' => $page));
         $link = str_replace($pls['pl'], $pls['vl'], $this->pdoTools->config['pageLinkScheme']);
         $pcre = preg_replace('#\\d+#', '(\\d+)', $link);
     }
     $href = !empty($link) ? preg_replace('#' . $pcre . '#', '', $url) : $url;
     if ($page > 1 || $page == 1 && !empty($this->pdoTools->config['ajax'])) {
         if (!empty($link)) {
             $href = rtrim($href, '/') . '/' . ltrim($link, '/');
         } else {
             $href .= strpos($href, '?') !== false ? '&' : '?';
             $href .= $this->pdoTools->config['pageVarKey'] . '=' . $page;
         }
     }
     if (!empty($_GET)) {
         $request = $_GET;
         unset($request[$this->req_var]);
         unset($request[$this->pdoTools->config['pageVarKey']]);
         if (!empty($request)) {
             $href .= strpos($href, '?') !== false ? '&' : '?';
             $href .= http_build_query($request);
         }
     }
     if (!empty($href) && $this->modx->getOption('xhtml_urls', null, false)) {
         $href = preg_replace("/&(?!amp;)/", "&", $href);
     }
     $data = array('page' => $page, 'pageNo' => $page, 'href' => $href);
     return !empty($tpl) ? $this->pdoTools->getChunk($tpl, $data) : $href;
 }
Example #2
0
 /**
  * Transform array to placeholders
  *
  * @param array $array
  * @param string $plPrefix
  * @param string $prefix
  * @param string $suffix
  *
  * @return array
  */
 public function makePlaceholders(array $array = array(), $plPrefix = '', $prefix = '[[+', $suffix = ']]')
 {
     if ($this->pdoTools) {
         return $this->pdoTools->makePlaceholders($array, $plPrefix, $prefix, $suffix);
     }
     $result = array('pl' => array(), 'vl' => array());
     foreach ($array as $k => $v) {
         if (is_array($v)) {
             $result = array_merge_recursive($result, $this->makePlaceholders($v, $plPrefix . $k . '.', $prefix, $suffix));
         } else {
             $pl = $plPrefix . $k;
             $result['pl'][$pl] = $prefix . $pl . $suffix;
             $result['vl'][$pl] = $v;
         }
     }
     return $result;
 }