Пример #1
0
 /**
  * Вызов экстенедара с параметрами полученными в этой функции
  *
  * @param DocLister $DocLister объект класса DocLister
  * @param mixed $config , ... неограниченное число параметров (используются для конфигурации экстендера)
  * @return mixed ответ от экстендера (как правило это string)
  */
 public function init($DocLister)
 {
     $this->DocLister->debug->debug('Run extender ' . get_class($this), 'runExtender', 2);
     $flag = false;
     if ($DocLister instanceof DocLister) {
         $this->DocLister = $DocLister;
         $this->modx = $this->DocLister->getMODX();
         $flag = $this->checkParam(func_get_args())->run();
     }
     $this->DocLister->debug->debugEnd('runExtender');
     return $flag;
 }
Пример #2
0
 public function dumpData($data, $wrap = '', $charset = 'UTF-8')
 {
     $out = $this->DocLister->sanitarData(print_r($data, 1), $charset);
     if (!empty($wrap) && is_string($wrap)) {
         $out = "<{$wrap}>{$out}</{$wrap}>";
     }
     return $out;
 }
Пример #3
0
 public function getJSON($data, $fields, $array = array())
 {
     $out = array();
     $fields = is_array($fields) ? $fields : explode(",", $fields);
     $date = $this->getCFGDef('dateSource', 'pub_date');
     foreach ($data as $num => $item) {
         switch (true) {
             case (array('1') == $fields || in_array('summary', $fields)) && $this->checkExtender('summary'):
                 $out[$num]['summary'] = mb_strlen($this->_docs[$num]['introtext'], 'UTF-8') > 0 ? $this->_docs[$num]['introtext'] : $this->extender['summary']->init($this, array("content" => $this->_docs[$num]['content'], "summary" => $this->getCFGDef("summary", "")));
                 //without break
             case (array('1') == $fields || in_array('date', $fields)) && $date != 'date':
                 $tmp = isset($this->_docs[$num][$date]) && $date != 'createdon' && $this->_docs[$num][$date] != 0 && $this->_docs[$num][$date] == (int) $this->_docs[$num][$date] ? $this->_docs[$num][$date] : $this->_docs[$num]['createdon'];
                 $out[$num]['date'] = strftime($this->getCFGDef('dateFormat', '%d.%b.%y %H:%M'), $tmp + $this->modx->config['server_offset_time']);
                 //without break
         }
     }
     return parent::getJSON($data, $fields, $out);
 }
Пример #4
0
 /**
  * Конструктор условий для WHERE секции
  *
  * @param $table_alias алиас таблицы
  * @param $field поле для фильтрации
  * @param $operator оператор сопоставления
  * @param $value искомое значение
  * @return string
  */
 protected function build_sql_where($table_alias, $field, $operator, $value)
 {
     $this->DocLister->debug->debug('Build SQL query for filters: ' . $this->DocLister->debug->dumpData(func_get_args()), 'buildQuery', 2);
     $output = sqlHelper::tildeField($field, $table_alias);
     switch ($operator) {
         case '=':
         case 'eq':
         case 'is':
             $output .= " = '" . $this->modx->db->escape($value) . "'";
             break;
         case '!=':
         case 'no':
         case 'isnot':
             $output .= " != '" . $this->modx->db->escape($value) . "'";
             break;
         case '>':
         case 'gt':
             $output .= ' > ' . str_replace(',', '.', floatval($value));
             break;
         case '<':
         case 'lt':
             $output .= ' < ' . str_replace(',', '.', floatval($value));
             break;
         case '<=':
         case 'elt':
             $output .= ' <= ' . str_replace(',', '.', floatval($value));
             break;
         case '>=':
         case 'egt':
             $output .= ' >= ' . str_replace(',', '.', floatval($value));
             break;
         case '%':
         case 'like':
             $output = $this->DocLister->LikeEscape($output, $value);
             break;
         case 'like-r':
             $output = $this->DocLister->LikeEscape($output, $value, '=', '[+value+]%');
             break;
         case 'like-l':
             $output = $this->DocLister->LikeEscape($output, $value, '=', '%[+value+]');
             break;
         case 'regexp':
             $output .= " REGEXP '" . $this->modx->db->escape($value) . "'";
             break;
         case 'against':
             /** content:pagetitle,description,content,introtext:against:искомая строка */
             if (trim($value) != '') {
                 $field = explode(",", $this->field);
                 $field = implode(",", $this->DocLister->renameKeyArr($field, $this->getTableAlias()));
                 $output = "MATCH ({$field}) AGAINST ('{$this->modx->db->escape($value)}*')";
             }
             break;
         case 'containsOne':
             $words = explode($this->DocLister->getCFGDef('filter_delimiter', ','), $value);
             $word_arr = array();
             foreach ($words as $word) {
                 /**
                  * $word оставляю без trim, т.к. мало ли, вдруг важно найти не просто слово, а именно его начало
                  * Т.е. хочется найти не слово содержащее $word, а начинающееся с $word. Для примера:
                  * искомый $word = " когда". С trim найдем "...мне некогда..." и "...тут когда-то...";
                  * Без trim будт обнаружено только "...тут когда-то..."
                  */
                 $word_arr[] = $this->DocLister->LikeEscape($output, $word);
             }
             if (!empty($word_arr)) {
                 $output = '(' . implode(' OR ', $word_arr) . ')';
             } else {
                 $output = '';
             }
             break;
         case 'in':
             $output .= ' IN(' . $this->DocLister->sanitarIn($value, ',', true) . ')';
             break;
         case 'notin':
             $output .= ' NOT IN(' . $this->DocLister->sanitarIn($value, ',', true) . ')';
             break;
         default:
             $output = '';
     }
     $this->DocLister->debug->debugEnd("buildQuery");
     return $output;
 }
Пример #5
0
 public function changeSortType($field, $type)
 {
     $type = trim($type);
     switch (strtoupper($type)) {
         case 'TVDATETIME':
             $field = "STR_TO_DATE(" . $field . ",'%d-%m-%Y %H:%i:%s')";
             break;
         default:
             $field = parent::changeSortType($field, $type);
     }
     return $field;
 }
Пример #6
0
 public function getJSON($data, $fields, $array = array())
 {
     $out = array();
     $fields = is_array($fields) ? $fields : explode(",", $fields);
     $date = $this->getCFGDef('dateSource', 'pub_date');
     /**
      * @var $extSummary summary_DL_Extender
      */
     $extSummary = $this->getExtender('summary');
     /**
      * @var $extPrepare prepare_DL_Extender
      */
     $extPrepare = $this->getExtender('prepare');
     /**
      * @var $extE e_DL_Extender
      */
     $extE = $this->getExtender('e', true, true);
     foreach ($data as $num => $item) {
         $row = $item;
         switch (true) {
             case (array('1') == $fields || in_array('summary', $fields)) && $extSummary:
                 $row['summary'] = $this->getSummary($this->_docs[$num], $extSummary, 'introtext');
                 //without break
             case (array('1') == $fields || in_array('date', $fields)) && $date != 'date':
                 $tmp = isset($this->_docs[$num][$date]) && $date != 'createdon' && $this->_docs[$num][$date] != 0 && $this->_docs[$num][$date] == (int) $this->_docs[$num][$date] ? $this->_docs[$num][$date] : $this->_docs[$num]['createdon'];
                 $row['date'] = strftime($this->getCFGDef('dateFormat', '%d.%b.%y %H:%M'), $tmp + $this->modx->config['server_offset_time']);
                 //without break
         }
         if ($extE && ($tmp = $extE->init($this, array('data' => $row)))) {
             if (is_array($tmp)) {
                 $row = $tmp;
             }
         }
         if ($extPrepare) {
             $row = $extPrepare->init($this, array('data' => $row));
             if (is_bool($row) && $row === false) {
                 continue;
             }
         }
         $out[$num] = $row;
     }
     return parent::getJSON($out, $fields, $out);
 }
Пример #7
0
 public function init(DocLister $DocLister, $filter)
 {
     $this->extTV = $DocLister->getExtender('tv', true, true);
     return parent::init($DocLister, $filter);
 }