Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/main/classes/general/ |
Upload File : |
<?php IncludeModuleLangFile(__FILE__); /** * @deprecated */ abstract class CAllFilterQuery { var $cnt = 0; var $m_query; var $m_words; var $m_fields; var $m_kav; var $default_query_type; var $rus_bool_lang; var $error; var $procent; var $ex_sep; var $clob; var $div_fields; var $clob_upper; var $errorno; /* $default_query_type - logic for spaces $rus_bool_lang - use russian logic words $ex_sep - array with exceptions for delimiters */ public function __construct($default_query_type = "and", $rus_bool_lang = "yes", $procent="Y", $ex_sep = array(), $clob="N", $div_fields="Y", $clob_upper="N") { $this->m_query = ""; $this->m_fields = ""; $this->default_query_type = $default_query_type; $this->rus_bool_lang = $rus_bool_lang; $this->m_kav = array(); $this->error = ""; $this->procent = $procent; $this->ex_sep = $ex_sep; $this->clob = $clob; $this->clob_upper = $clob_upper; $this->div_fields = $div_fields; } abstract public function BuildWhereClause($word); public function GetQueryString($fields, $query) { $this->m_words = array(); if($this->div_fields=="Y") $this->m_fields = explode(",", $fields); else $this->m_fields = $fields; if(!is_array($this->m_fields)) $this->m_fields=array($this->m_fields); $query = $this->CutKav($query); $query = $this->ParseQ($query); if($query == "( )" || $query == '') { $this->error=GetMessage("FILTER_ERROR3"); $this->errorno=3; return false; } $query = $this->PrepareQuery($query); return $query; } public function CutKav($query) { $bdcnt = 0; while (preg_match("/\"([^\"]*)\"/",$query,$pt)) { $res = $pt[1]; if(trim($pt[1]) <> '') { $trimpt = $bdcnt."cut5"; $this->m_kav[$trimpt] = $res; $query = str_replace("\"".$pt[1]."\"", " ".$trimpt." ", $query); } else { $query = str_replace("\"".$pt[1]."\"", " ", $query); } $bdcnt++; if($bdcnt>100) break; } $bdcnt = 0; while (preg_match("/'([^']*)'/",$query,$pt)) { $res = $pt[1]; if(trim($pt[1]) <> '') { $trimpt = $bdcnt."cut6"; $this->m_kav[$trimpt] = $res; $query = str_replace("'".$pt[1]."'", " ".$trimpt." ", $query); } else { $query = str_replace("'".$pt[1]."'", " ", $query); } $bdcnt++; if($bdcnt>100) break; } return $query; } public function ParseQ($q) { $q = trim($q); if($q == '') return ''; $q=$this->ParseStr($q); $q = str_replace( array("&" , "|" , "~" , "(" , ")"), array(" && ", " || ", " ! ", " ( ", " ) "), $q ); $q="( $q )"; $q = preg_replace("/\\s+/u", " ", $q); return $q; } public function ParseStr($qwe) { $qwe=trim($qwe); $qwe=preg_replace("/ {0,}\\+ {0,}/", "&", $qwe); $qwe=preg_replace("/ {0,}([()|~]) {0,}/", "\\1", $qwe); // default query type is and if(mb_strtolower($this->default_query_type) == 'or') $default_op = "|"; else $default_op = "&"; $qwe=preg_replace("/( {1,}|\\&\\|{1,}|\\|\\&{1,})/", $default_op, $qwe); // remove unnesessary boolean operators $qwe=preg_replace("/\\|+/", "|", $qwe); $qwe=preg_replace("/\\&+/", "&", $qwe); $qwe=preg_replace("/\\~+/", "~", $qwe); $qwe=preg_replace("/\\|\\&\\|/", "&", $qwe); $qwe=preg_replace("/[|&~]+$/", "", $qwe); $qwe=preg_replace("/^[|&]+/", "", $qwe); // transform "w1 ~w2" -> "w1 default_op ~ w2" // ") ~w" -> ") default_op ~w" // "w ~ (" -> "w default_op ~(" // ") w" -> ") default_op w" // "w (" -> "w default_op (" // ")(" -> ") default_op (" $qwe=preg_replace("/([^&~|()]+)~([^&~|()]+)/", "\\1".$default_op."~\\2", $qwe); $qwe=preg_replace("/\\)~{1,}/", ")".$default_op."~", $qwe); $qwe=preg_replace("/~{1,}\\(/", ($default_op=="|"? "~|(": "&~("), $qwe); $qwe=preg_replace("/\\)([^&~|()]+)/", ")".$default_op."\\1", $qwe); $qwe=preg_replace("/([^&~|()]+)\\(/", "\\1".$default_op."(", $qwe); $qwe=preg_replace("/\\) *\\(/", ")".$default_op."(", $qwe); // remove unnesessary boolean operators $qwe=preg_replace("/\\|+/", "|", $qwe); $qwe=preg_replace("/\\&+/", "&", $qwe); // remove errornous format of query - ie: '(&', '&)', '(|', '|)', '~&', '~|', '~)' $qwe=preg_replace("/\\(\\&{1,}/", "(", $qwe); $qwe=preg_replace("/\\&{1,}\\)/", ")", $qwe); $qwe=preg_replace("/\\~{1,}\\)/", ")", $qwe); $qwe=preg_replace("/\\(\\|{1,}/", "(", $qwe); $qwe=preg_replace("/\\|{1,}\\)/", ")", $qwe); $qwe=preg_replace("/\\~{1,}\\&{1,}/", "&", $qwe); $qwe=preg_replace("/\\~{1,}\\|{1,}/", "|", $qwe); $qwe=preg_replace("/\\(\\)/", "", $qwe); $qwe=preg_replace("/^[|&]{1,}/", "", $qwe); $qwe=preg_replace("/[|&~]{1,}\$/", "", $qwe); $qwe=preg_replace("/\\|\\&/", "&", $qwe); $qwe=preg_replace("/\\&\\|/", "|", $qwe); // remove unnesessary boolean operators $qwe=preg_replace("/\\|+/", "|", $qwe); $qwe=preg_replace("/\\&+/", "&", $qwe); return($qwe); } public function PrepareQuery($q) { $state = 0; $qu = ''; $n = 0; $this->error = ''; foreach (preg_split('/ +/', $q) as $t) { if ($state) { if (($t === '||') || ($t === '&&')) { $state = 0; $qu .= $t === '||' ? ' OR ' : ' AND '; } elseif ($t === ')') { $n--; $qu .= ')'; } else { $this->error = GetMessage('FILTER_ERROR2') . ' ' . $t; $this->errorno = 2; break; } } else { if (($t === '||') || ($t === '&&') || ($t === ')')) { $this->error = GetMessage('FILTER_ERROR2') . ' ' . $t; $this->errorno = 2; } elseif ($t === '!') { $qu .= ' NOT '; } elseif ($t === '(') { $n++; $qu .= '('; } else { $state = 1; $qu .= ' ' . $this->BuildWhereClause($t) . ' '; } } } if (($this->error === '') && ($n !== 0)) { $this->error = GetMessage('FILTER_ERROR1'); $this->errorno = 1; } if ($this->error !== '') { return 0; } return $qu; } } class CFilterQuery extends CAllFilterQuery { public function BuildWhereClause($word) { $this->cnt++; //if($this->cnt>10) return "1=1"; global $DB; if (isset($this->m_kav[$word])) $word = $this->m_kav[$word]; $this->m_words[] = $word; $n = count($this->m_fields); $ret = ""; if ($n>1) $ret = "("; for ($i=0; $i<$n; $i++) { $field = $this->m_fields[$i]; if ($this->procent=="Y") { $ret.= " (upper($field) like upper('%".$DB->ForSqlLike($word, 2000)."%') and $field is not null) "; } elseif (str_contains($word, "%") || str_contains($word, "_")) { $ret.= " (upper($field) like upper('".$DB->ForSqlLike($word, 2000)."') and $field is not null) "; } else { $ret.= " ($field='".$DB->ForSql($word, 2000)."' and $field is not null) "; } if ($i<>$n-1) $ret.= " OR "; } if ($n>1) $ret.= ")"; return $ret; } }