예제 #1
0
 public static function firstChar(array $data = array(), DocumentParser $modx, $_DocLister, prepare_DL_Extender $_extDocLister)
 {
     $char = mb_substr($data['pagetitle'], 0, 1, 'UTF-8');
     $oldChar = $_extDocLister->getStore('char');
     if ($oldChar !== $char) {
         $sanitarInIDs = $_DocLister->sanitarIn($_DocLister->getIDs());
         $where = sqlHelper::trimLogicalOp($_DocLister->getCFGDef('addWhereList', ''));
         $where = sqlHelper::trimLogicalOp(($where ? $where . ' AND ' : '') . $_DocLister->filtersWhere());
         $where = sqlHelper::trimLogicalOp(($where ? $where . ' AND ' : '') . "SUBSTRING(c.pagetitle,1,1) = '" . $modx->db->escape($char) . "'");
         if ($_DocLister->getCFGDef('idType', 'parents') == 'parents') {
             if ($where != '') {
                 $where .= " AND ";
             }
             $where = "WHERE {$where} c.parent IN (" . $sanitarInIDs . ")";
             if (!$_DocLister->getCFGDef('showNoPublish', 0)) {
                 $where .= " AND c.deleted=0 AND c.published=1";
             }
         } else {
             if ($sanitarInIDs != "''") {
                 $where .= ($where ? " AND " : "") . "c.id IN ({$sanitarInIDs}) AND";
             }
             $where = sqlHelper::trimLogicalOp($where);
             if ($_DocLister->getCFGDef('showNoPublish', 0)) {
                 if ($where != '') {
                     $where = "WHERE {$where}";
                 }
             } else {
                 if ($where != '') {
                     $where = "WHERE {$where} AND ";
                 } else {
                     $where = "WHERE {$where} ";
                 }
                 $where .= "c.deleted=0 AND c.published=1";
             }
         }
         $q = $_DocLister->dbQuery("SELECT count(c.id) as total FROM " . $_DocLister->getTable('site_content', 'c') . " " . $where);
         $total = $modx->db->getValue($q);
         $data['OnNewChar'] = $_DocLister->parseChunk($_DocLister->getCFGDef('tplOnNewChar'), compact("char", "total"));
         $_extDocLister->setStore('char', $char);
         if ($oldChar !== null) {
             $data['CharSeparator'] = $_DocLister->parseChunk($_DocLister->getCFGDef('tplCharSeparator'), compact("char", "total"));
         }
     }
     return $data;
 }
예제 #2
0
            $action = "regexp";
            $char = "^[{$char}]";
        } else {
            $char = null;
        }
    }
}
if (is_null($char)) {
    $modx->sendErrorPage();
}
$p =& $modx->event->params;
if (!is_array($p)) {
    $p = array();
}
if (!empty($loadfilter)) {
    $field = explode(".", $field);
    $field = end($field);
    if (!empty($p['filters'])) {
        $p['filters'] = rtrim(trim($p['filters']), ";") . ";";
    }
    $p['filters'] = "AND({$loadfilter}:{$field}:{$action}:{$char})";
} else {
    $field = sqlHelper::tildeField($field);
    if ($action == 'regexp') {
        $where = $field . " REGEXP '" . $modx->db->escape($char) . "'";
    } else {
        $where = sqlHelper::LikeEscape($modx, $field, $char, '=', '[+value+]%');
    }
    $p['addWhereList'] = empty($p['addWhereList']) ? $where : sqlHelper::trimLogicalOp($p['addWhereList']) . " AND " . $where;
}
return $modx->runSnippet("DocLister", $p);
예제 #3
0
 /**
  * @TODO: 3) Формирование ленты в случайном порядке (если отключена пагинация и есть соответствующий запрос)
  * @TODO: 5) Добавить фильтрацию по основным параметрам документа
  */
 protected function getChildrenList()
 {
     $where = array();
     $out = array();
     $tmpWhere = $this->getCFGDef('addWhereList', '');
     $tmpWhere = sqlHelper::trimLogicalOp($tmpWhere);
     if (!empty($tmpWhere)) {
         $where[] = $tmpWhere;
     }
     $tmpWhere = sqlHelper::trimLogicalOp($this->_filters['where']);
     if (!empty($tmpWhere)) {
         $where[] = $tmpWhere;
     }
     $tbl_site_content = $this->getTable('site_content', 'c');
     $sort = $this->SortOrderSQL("if(c.pub_date=0,c.createdon,c.pub_date)");
     list($from, $sort) = $this->injectSortByTV($tbl_site_content . ' ' . $this->_filters['join'], $sort);
     $sanitarInIDs = $this->sanitarIn($this->IDs);
     $tmpWhere = null;
     if ($sanitarInIDs != "''") {
         switch ($this->getCFGDef('showParent', '0')) {
             case '-1':
                 $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")";
                 break;
             case 0:
                 $tmpWhere = "c.parent IN (" . $sanitarInIDs . ") AND c.id NOT IN(" . $sanitarInIDs . ")";
                 break;
             case 1:
             default:
                 $tmpWhere = "(c.parent IN (" . $sanitarInIDs . ") OR c.id IN({$sanitarInIDs}))";
                 break;
         }
     }
     if (($addDocs = $this->getCFGDef('documents', '')) != '') {
         $addDocs = $this->sanitarIn($this->cleanIDs($addDocs));
         if (empty($tmpWhere)) {
             $tmpWhere = "c.id IN({$addDocs})";
         } else {
             $tmpWhere = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))";
         }
     }
     if (!empty($tmpWhere)) {
         $where[] = $tmpWhere;
     }
     if (!$this->getCFGDef('showNoPublish', 0)) {
         $where[] = "c.deleted=0 AND c.published=1";
     }
     if (!empty($where)) {
         $where = "WHERE " . implode(" AND ", $where);
     } else {
         $where = '';
     }
     $fields = $this->getCFGDef('selectFields', 'c.*');
     $group = $this->getGroupSQL($this->getCFGDef('groupBy', 'c.id'));
     if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
         $sql = $this->dbQuery("SELECT {$fields} FROM " . $from . " " . $where . " " . $group . " " . $sort . " " . $this->LimitSQL($this->getCFGDef('queryLimit', 0)));
         $rows = $this->modx->db->makeArray($sql);
         foreach ($rows as $item) {
             $out[$item['id']] = $item;
         }
     }
     return $out;
 }
예제 #4
0
 protected function getChildrenList()
 {
     $where = array();
     $out = array();
     $tmpWhere = $this->getCFGDef('addWhereList', '');
     $tmpWhere = sqlHelper::trimLogicalOp($tmpWhere);
     if (!empty($tmpWhere)) {
         $where[] = $tmpWhere;
     }
     $sanitarInIDs = $this->sanitarIn($this->IDs);
     $tmpWhere = null;
     if ($sanitarInIDs != "''") {
         $tmpWhere = "(`{$this->getParentField()}` IN (" . $sanitarInIDs . ")";
         switch ($this->getCFGDef('showParent', '0')) {
             case -1:
                 $tmpWhere .= ")";
                 break;
             case 0:
                 $tmpWhere .= " AND `{$this->getPK()}` NOT IN(" . $sanitarInIDs . "))";
                 break;
             case 1:
             default:
                 $tmpWhere .= " OR `{$this->getPK()}` IN({$sanitarInIDs}))";
                 break;
         }
     }
     if (($addDocs = $this->getCFGDef('documents', '')) != '') {
         $addDocs = $this->sanitarIn($this->cleanIDs($addDocs));
         if (empty($tmpWhere)) {
             $tmpWhere = $this->getPK() . " IN({$addDocs})";
         } else {
             $tmpWhere = "((" . $tmpWhere . ") OR {$this->getPK()} IN({$addDocs}))";
         }
     }
     if (!empty($tmpWhere)) {
         $where[] = $tmpWhere;
     }
     if (!empty($where)) {
         $where = "WHERE " . implode(" AND ", $where);
     } else {
         $where = '';
     }
     $fields = $this->getCFGDef('selectFields', '*');
     $group = $this->getGroupSQL($this->getCFGDef('groupBy', "`{$this->getPK()}`"));
     if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
         $sql = $this->dbQuery("SELECT {$fields} FROM " . $this->table . " " . $where . " " . $group . " " . $this->SortOrderSQL($this->getPK()) . " " . $this->LimitSQL($this->getCFGDef('queryLimit', 0)));
         $rows = $this->modx->db->makeArray($sql);
         foreach ($rows as $item) {
             $out[$item[$this->getPK()]] = $item;
         }
     }
     return $out;
 }