8 require_once(CH_DIRECTORY_PATH_INC .
'db.inc.php');
9 require_once(CH_DIRECTORY_PATH_INC .
'utils.inc.php');
10 require_once(CH_DIRECTORY_PATH_INC .
'design.inc.php');
50 $this->aClasses =
$GLOBALS[
'MySQL']->fromCache(
'sys_objects_search',
'getAllWithKey',
53 `ClassName` as `class`,
54 `ClassPath` as `file`,
56 FROM `sys_objects_search`',
'ObjectName'
61 if (isset($this->aClasses[$sValue]))
62 $this->aChoice[$sValue] = $this->aClasses[$sValue];
75 foreach ($this->aChoice
as $sKey => $aValue) {
76 if (!class_exists($aValue[
'class'])) {
77 $sClassPath = str_replace(
'{tmpl}',
$GLOBALS[
'oSysTemplate']->getCode(), $aValue[
'file']);
78 require_once(CH_DIRECTORY_PATH_ROOT . $sClassPath);
80 $oEx =
new $aValue[
'class']();
81 $oEx->id = $aValue[
'id'];
82 $sCode .= $oEx->processing();
220 if (isset($this->aPseud[
'id']))
221 $this->aCurrent[
'ident'] = $this->aPseud[
'id'];
232 if ($this->aCurrent[
'paginate'][
'totalNum'] > 0) {
248 if (count($aData) > 0) {
250 foreach ($aData
as $iKey => $aValue) {
272 if (!isset($this->aCurrent[
'rss'][
'fields']) || !isset($this->aCurrent[
'rss'][
'link']))
276 $f = &$this->aCurrent[
'rss'][
'fields'];
278 foreach ($aData
as $k => $a) {
281 if(isset(
$f[
'Image']))
286 require_once(CH_DIRECTORY_PATH_CLASSES .
'ChWsbRssFactory.php');
288 $oRss->SetRssHeader();
289 return $oRss->GenRssByCustomData(
291 $this->aCurrent[
'rss'][
'title'] ? $this->aCurrent[
'rss'][
'title'] : $this->aCurrent[
'title'],
292 $this->aCurrent[
'rss'][
'link'],
293 $this->aCurrent[
'rss'][
'fields'],
294 isset($this->aCurrent[
'rss'][
'image']) ? $this->aCurrent[
'rss'][
'image'] :
'',
295 isset($this->aCurrent[
'rss'][
'profile']) ? $this->aCurrent[
'rss'][
'profile'] : 0
325 function setFieldUnit ($sFieldName, $sTableName, $sOperator =
'', $bRenameMode =
true)
327 if (strlen($sOperator) > 0) {
328 $sqlUnit =
"$sOperator(`$sTableName`.`$sFieldName`)";
330 $sqlUnit =
"`$sTableName`.`$sFieldName`";
332 if (isset($this->aPseud) && $bRenameMode !==
false) {
333 $sKey = array_search($sFieldName, $this->aPseud);
334 if ($sKey !==
false) {
335 $sqlUnit .=
" as `$sKey`";
336 unset($this->aPseud[$sKey]);
339 return $sqlUnit .
', ';
380 if ($this->aCurrent[
'paginate'][
'totalNum'] > 0) {
396 if (isset($this->aCurrent[
'join']) && is_array($this->aCurrent[
'join'])) {
397 $aSql = array(
'join'=>
'',
'ownFields'=>
'',
'joinFields'=>
'',
'groupBy'=>
'');
398 foreach ($this->aCurrent[
'join']
as $sKey => $aValue) {
399 if (is_array($aValue[
'joinFields'])) {
400 foreach ($aValue[
'joinFields']
as $sValue) {
401 $aSql[
'joinFields'] .= $this->
setFieldUnit($sValue, $aValue[
'table'], isset($aValue[
'operator']) ? $aValue[
'operator'] :
null, $bRenameMode);
405 if (isset($aValue[
'groupTable']))
406 $aSql[
'groupBy'] =
"GROUP BY `{$aValue['groupTable']}`.`{$aValue['groupField']}`, ";
407 $sOn = isset($aValue[
'mainTable']) ? $aValue[
'mainTable'] : $this->aCurrent[
'table'];
408 $aSql[
'join'] .=
" {$aValue['type']} JOIN `{$aValue['table']}` ON `{$aValue['table']}`.`{$aValue['onField']}`=`$sOn`.`{$aValue['mainField']}`";
409 $aSql[
'ownFields'] .= $this->
setFieldUnit($aValue[
'mainField'], $sOn,
'', $bRenameMode);
411 $aSql[
'joinFields'] = trim($aSql[
'joinFields'],
', ');
412 $aSql[
'groupBy'] = trim($aSql[
'groupBy'],
', ');
425 $aSql = array(
'ownFields'=>
'',
'joinFields'=>
'',
'order'=>
'');
428 foreach ($this->aCurrent[
'ownFields']
as $sValue) {
429 $aSql[
'ownFields'] .= $this->
setFieldUnit($sValue, $this->aCurrent[
'table']);
433 if (!
empty($aJoins)) {
434 $aSql[
'ownFields'] .= $aJoins[
'ownFields'];
435 $aSql[
'joinFields'] .= $aJoins[
'joinFields'];
436 $aSql[
'join'] = $aJoins[
'join'];
437 $aSql[
'groupBy'] = $aJoins[
'groupBy'];
439 $aSql[
'ownFields'] = trim($aSql[
'ownFields'],
', ');
441 $aSql[
'from'] =
" FROM `{$this->aCurrent['table']}`";
452 $aSort = $this->
getSorting($this->aCurrent[
'sorting']);
453 foreach ($aSort
as $sKey => $sValue)
454 $aSql[$sKey] .= $sValue;
458 if (is_array($aRate)) {
459 foreach ($aRate
as $sKey => $sValue)
460 $aSql[$sKey] .= $sValue;
464 $sqlQuery =
"SELECT {$aSql['ownFields']} {$aSql['joinFields']} {$aSql['from']} {$aSql['join']} {$aSql['where']} {$aSql['groupBy']} {$aSql['order']} {$aSql['limit']}";
479 $sKeyword =
ch_get(
'keyword');
480 if ($sKeyword !==
false)
481 $this->aCurrent[
'restriction'][
'keyword'] = array(
484 'operator' =>
'against'
487 if (isset(
$_GET[
'ownerName'])) {
489 $iUser = (int)
db_value(
"SELECT `ID` FROM `Profiles` WHERE `NickName`='$sName'");
490 $GLOBALS[
'oTopMenu']->setCurrentProfileID($iUser);
491 } elseif (isset(
$_GET[
'userID']))
492 $iUser = (int)
$_GET[
'userID'];
495 $this->aCurrent[
'restriction'][
'owner'][
'value'] = $iUser;
499 $this->aCurrent[
'paginate'][
'totalNum'] =
$iTotalNum;
501 $this->aCurrent[
'paginate'][
'totalPages'] = ceil(
$iTotalNum / $this->aCurrent[
'paginate'][
'perPage'] );
503 $this->aCurrent[
'paginate'][
'totalNum'] = 0;
504 $this->aCurrent[
'paginate'][
'totalPages'] = 0;
516 $sqlQuery =
"SELECT COUNT(*) FROM `{$this->aCurrent['table']}` {$aJoins['join']} " . $this->
getRestriction() .
" {$aJoins['groupBy']}";
528 if (isset($this->aCurrent[
'restriction'])) {
530 foreach ($this->aCurrent[
'restriction']
as $sKey => $aValue) {
532 if (isset($aValue[
'operator']) && !
empty($aValue[
'value'])) {
533 $sFieldTable = isset($aValue[
'table']) ? $aValue[
'table'] : $this->aCurrent[
'table'];
534 $sqlCondition =
"`{$sFieldTable}`.`{$aValue['field']}` ";
535 if (!isset($aValue[
'no_quote_value']))
537 switch ($aValue[
'operator']) {
539 $aCond = isset($aValue[
'field']) && strlen($aValue[
'field']) > 0 ? $aValue[
'field'] : $this->aCurrent[
'searchFields'];
543 $sqlCondition .=
"LIKE '%" . $aValue[
'value'] .
"%'";
548 $sqlCondition .= strtoupper($aValue[
'operator']) .
'('.$sValuesString.
')';
551 $sqlCondition .= $aValue[
'operator'] . (isset($aValue[
'no_quote_value']) && $aValue[
'no_quote_value'] ? $aValue[
'value'] :
"'" . $aValue[
'value'] .
"'");
555 if (strlen($sqlCondition) > 0)
556 $aWhere[] = $sqlCondition;
558 $sqlWhere .=
"WHERE ". implode(
' AND ', $aWhere);
570 if (isset($this->aCurrent[
'paginate'])) {
571 $sqlFrom = ( $this->aCurrent[
'paginate'][
'page'] - 1 ) * $this->aCurrent[
'paginate'][
'perPage'];
572 $sqlTo = $this->aCurrent[
'paginate'][
'perPage'];
574 return 'LIMIT ' . $sqlFrom .
', '.$sqlTo;
584 $this->aCurrent[
'sorting'] = isset(
$_GET[$this->aCurrent[
'name'] .
'_mode']) ?
$_GET[$this->aCurrent[
'name'] .
'_mode'] : $this->aCurrent[
'sorting'];
595 if (is_array($aOverride) && !
empty($aOverride))
599 switch ($sSortType) {
601 $aSql[
'order'] =
"ORDER BY RAND()";
605 $aSql[
'order'] =
"ORDER BY `Rate` $sHow, `RateCount` $sHow, `date` $sHow";
608 if (is_array($this->aCurrent[
'restriction'][
'keyword'])) {
609 $aSql[
'order'] =
"ORDER BY `score` DESC";
610 $aSql[
'ownFields'] .= $this->
getSearchFieldsCond($this->aCurrent[
'searchFields'], $this->aCurrent[
'restriction'][
'keyword'][
'value'],
'score').
', ';
614 $aSql[
'order'] =
"ORDER BY `voteTime` DESC";
620 $aSql[
'order'] =
"ORDER BY `date` DESC";
642 $this->aCurrent[
'paginate'][
'perPage'] = (isset(
$_GET[
'per_page']) && (int)
$_GET[
'per_page'] != 0) ? (int)
$_GET[
'per_page'] : $this->aCurrent[
'paginate'][
'perPage'];
643 if (
empty($this->aCurrent[
'paginate'][
'perPage']))
644 $this->aCurrent[
'paginate'][
'perPage'] = 10;
646 $this->aCurrent[
'paginate'][
'page'] = isset($this->aCurrent[
'paginate'][
'forcePage'])
647 ? (int)$this->aCurrent[
'paginate'][
'forcePage']
650 if ($this->aCurrent[
'paginate'][
'page'] < 1)
651 $this->aCurrent[
'paginate'][
'page'] = 1;
664 if (strlen($sKeyword) > 0) {
665 $bLike =
getParam(
'useLikeOperator');
667 'function' =>
'MATCH',
668 'operator' =>
'AGAINST',
671 if ($bLike ==
'on') {
673 'function' =>
'CONCAT',
674 'operator' =>
'LIKE',
675 'word' =>
'%' . preg_replace(
'/\s+/',
'%', $sKeyword) .
'%'
678 $sqlWhere =
" {$aSql['function']}(";
681 $sqlWhere .=
"`{$this->aCurrent['table']}`.`$sValue`, ";
683 $sqlWhere .=
"`{$this->aCurrent['table']}`.`$aFields`";
684 $sqlWhere = trim($sqlWhere,
', ') .
") {$aSql['operator']} ('{$aSql['word']}')";
686 if (strlen($sPseud) > 0)
687 $sqlWhere .=
" as `$sPseud`";
701 $sqlPart = is_array($aValues) ? implode(
"','", $aValues) : $aValues;
702 return "'".$sqlPart.
"'";
711 if ($this->iRate == 1)