* [perf] Optimize search module variable usage and simplify field control access.
This commit is contained in:
@@ -55,7 +55,7 @@ class search extends control
|
||||
$this->view->queryID = (empty($module) && empty($queryID)) ? $_SESSION[$searchParams]['queryID'] : $queryID;
|
||||
$this->view->style = !empty($_SESSION[$searchParams]['style']) ? $_SESSION[$searchParams]['style'] : 'full';
|
||||
$this->view->onMenuBar = !empty($_SESSION[$searchParams]['onMenuBar']) ? $_SESSION[$searchParams]['onMenuBar'] : 'no';
|
||||
$this->view->formSession = $_SESSION[$module . 'Form'];
|
||||
$this->view->formSession = $_SESSION[$searchForm];
|
||||
$this->view->formName = $formName;
|
||||
|
||||
if($module == 'program') $this->view->options = $this->searchZen->setOptions($fields, $this->view->fieldParams, $this->view->queries);
|
||||
|
||||
@@ -47,7 +47,7 @@ class searchModel extends model
|
||||
|
||||
if($this->config->edition != 'open') $searchConfig = $this->searchTao->processBuildinFields($module, $searchConfig);
|
||||
|
||||
$searchParams['module'] = $searchConfig['module'];
|
||||
$searchParams['module'] = $module;
|
||||
$searchParams['actionURL'] = $searchConfig['actionURL'];
|
||||
$searchParams['style'] = zget($searchConfig, 'style', 'full');
|
||||
$searchParams['onMenuBar'] = zget($searchConfig, 'onMenuBar', 'no');
|
||||
@@ -119,7 +119,6 @@ class searchModel extends model
|
||||
{
|
||||
/* Init vars. */
|
||||
$module = $this->post->module;
|
||||
$searchParams = $module . 'searchParams';
|
||||
$searchConfig = $this->processSearchParams($module);
|
||||
$searchFields = $searchConfig['fields'];
|
||||
$fieldParams = $searchConfig['params'];
|
||||
@@ -146,12 +145,12 @@ class searchModel extends model
|
||||
|
||||
$field = $this->post->$fieldName;
|
||||
$value = $this->post->$valueName;
|
||||
$fieldControl = isset($fieldParams[$field]) && isset($fieldParams[$field]['control']) ? $fieldParams[$field]['control'] : '';
|
||||
$fieldControl = $fieldParams[$field]['control'] ?? '';
|
||||
if(empty($field) || $value === '' || $value === false) continue; // false means no exist this post item. '' means no search data. ignore it.
|
||||
if(!preg_match('/^[a-zA-Z0-9]+$/', $field)) continue; // Fix sql injection.
|
||||
|
||||
/* 如果是输入框,并且输入框的值为'0',或者 id 的值为'0',将值设置为zero。*/
|
||||
if(isset($fieldParams[$field]) && $fieldControl == 'input' && $value === '0') $this->post->set($valueName, 'ZERO');
|
||||
if($fieldControl == 'input' && $value === '0') $this->post->set($valueName, 'ZERO');
|
||||
if($field == 'id' && $value === '0') $this->post->set($valueName, 'ZERO');
|
||||
|
||||
/* set queryForm. */
|
||||
@@ -193,7 +192,6 @@ class searchModel extends model
|
||||
$groupItems = $this->config->search->groupItems;
|
||||
$groupAndOr = strtoupper($this->post->groupAndOr);
|
||||
$module = $this->post->module;
|
||||
$searchParams = $module . 'searchParams';
|
||||
$searchConfig = $this->processSearchParams($module);
|
||||
$fieldParams = $searchConfig['params'];
|
||||
$scoreNum = 0;
|
||||
@@ -215,13 +213,15 @@ class searchModel extends model
|
||||
/* Fix bug #2704. */
|
||||
$field = $this->post->$fieldName;
|
||||
if(!preg_match('/^[a-zA-Z0-9]+$/', $field)) continue; // Fix sql injection.
|
||||
if(isset($fieldParams[$field]) and $fieldParams[$field]['control'] == 'input' and $this->post->$valueName === '0') $this->post->set($valueName, 'ZERO');
|
||||
|
||||
$fieldControl = $fieldParams[$field]['control'] ?? '';
|
||||
if($fieldControl == 'input' and $this->post->$valueName === '0') $this->post->set($valueName, 'ZERO');
|
||||
if($field == 'id' and $this->post->$valueName === '0') $this->post->set($valueName, 'ZERO');
|
||||
|
||||
/* Skip empty values. */
|
||||
if($this->post->$valueName == false) continue;
|
||||
if($this->post->$valueName == 'ZERO') $this->post->$valueName = 0; // ZERO is special, stands to 0.
|
||||
if(isset($fieldParams[$field]) and $fieldParams[$field]['control'] == 'select' and $this->post->$valueName === 'null') $this->post->set($valueName, ''); // Null is special, stands to empty if control is select. Fix bug #3279.
|
||||
if($fieldControl == 'select' and $this->post->$valueName === 'null') $this->post->set($valueName, ''); // Null is special, stands to empty if control is select. Fix bug #3279.
|
||||
|
||||
$scoreNum += 1;
|
||||
|
||||
@@ -245,7 +245,7 @@ class searchModel extends model
|
||||
}
|
||||
else
|
||||
{
|
||||
$condition = $fieldParams[$field]['control'] == 'select' ? " LIKE CONCAT('%,', '{$value}', ',%')" : ' LIKE ' . $this->dbh->quote("%$value%");
|
||||
$condition = $fieldControl == 'select' ? " LIKE CONCAT('%,', '{$value}', ',%')" : ' LIKE ' . $this->dbh->quote("%$value%");
|
||||
}
|
||||
}
|
||||
elseif($operator == "notinclude")
|
||||
@@ -257,7 +257,7 @@ class searchModel extends model
|
||||
}
|
||||
else
|
||||
{
|
||||
$condition = $fieldParams[$field]['control'] == 'select' ? " NOT LIKE CONCAT('%,', '{$value}', ',%')" : ' NOT LIKE ' . $this->dbh->quote("%$value%");
|
||||
$condition = $fieldControl == 'select' ? " NOT LIKE CONCAT('%,', '{$value}', ',%')" : ' NOT LIKE ' . $this->dbh->quote("%$value%");
|
||||
}
|
||||
}
|
||||
elseif($operator == 'belong')
|
||||
|
||||
Reference in New Issue
Block a user