From 920c8a8f2a59467bffee1a1a4fcafd7a5c29e511 Mon Sep 17 00:00:00 2001 From: liugang Date: Mon, 18 Aug 2025 11:50:20 +0800 Subject: [PATCH] * [perf] Optimize search module variable usage and simplify field control access. --- module/search/control.php | 2 +- module/search/model.php | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/module/search/control.php b/module/search/control.php index e3da90eed0..86000bde2f 100644 --- a/module/search/control.php +++ b/module/search/control.php @@ -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); diff --git a/module/search/model.php b/module/search/model.php index c532f81a7e..92566d7d4b 100644 --- a/module/search/model.php +++ b/module/search/model.php @@ -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')