Viewing file: module.php (3.25 KB) -rwxrwxrwx Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?
class SearchInSite
{
var $UserMode = true;
var $AdminMode = false;
var $SearchMode = false;
var $PanelMode = true;
var $Table;
var $UserTable;
var $Directory;
var $UserAsynchMode = false;
var $ClassName = 'SearchInSite';
var $RowsByPage = 20;
function SearchInSite()
{
$this->Directory = dirname(__FILE__);
$this->Table = new AMTable2('AMCMS_search');
$this->Table->AddIndexField('search_id');
$this->Table->Module($this->ClassName);
}
function GetChachedRows($text)
{
$rows = $this->Table->DeleteRows("search_date <= INTERVAL -1 DAY + CURDATE()");
$rows = $this->Table->GetRows("", "search_keywords = '$text'");
if ($rows != null)
{
return $rows[0];
}
else
return null;
}
function Cache($text, $rows)
{
global $ulang;
$row['search_keywords'] = $text;
$row['search_lang'] = $ulang;
$row['search_date'] = GetCurrentDateAndTime();
$row['search_result_count'] = count($rows);
$row['search_result'] = serialize($rows);
$this->Table->Insert($row);
}
function User()
{
global $ulang, $ULANG, $Modules;
{
$smarty = GetUserSmarty($this->ClassName);
if ($_GET['text'] == $ULANG['SearchInitText'])
$_GET['text'] = "";
$text = addslashes($_GET['text']);
$cached = $this->GetChachedRows($text);
/* echo $cached;
if ($cached)
$rows = unserialize($cached['search_result']);
else*/
{
$rows = array();
foreach($Modules as $key => $value)
if ($value->SearchMode)
$rows = array_merge($rows, $value->Search($text));
$indexes = array();
foreach($rows as $key => $value)
$indexes[] = $value['Relev'];
array_multisort($indexes, SORT_DESC, $rows, SORT_ASC);
for ($i = 0; $i < count($rows); $i++)
$rows[$i]['number'] = $i + 1;
$this->Cache($text, $rows);
}
$pageNum = $_GET['pageNum'];
if ($pageNum <= 0 || $pageNum >= 100000)
$pageNum = 1;
$effectedRows = array();
$pageNavigator = new CPageNavigator(count($rows), $pageNum, $this->RowsByPage);
$start = $pageNavigator->GetStartIndex();
for($i = $start; $i < $start + $this->RowsByPage; $i++)
if ($rows[$i])
$effectedRows[] = $rows[$i];
$smarty->assign("navigator", $pageNavigator->GetNavigator("/search", $ULANG["Pages"]));
$smarty->assign("rows", $effectedRows);
$result['Title'] = GetParam('ModuleSearchInSite', $ulang);
$result['Content'] = $smarty->fetch("search-result.tpl");
$navigator = new AMNavigator();
$navigator->AddLink(GetParam('ModuleSearchInSite', $ulang), "/search");
$result['GlobalParams']['Navigator'] = $navigator->Fetch();
$result['GlobalParams']['PageTitle'] = $navigator->GetTitleForPage();
$result['Module'] = $this->ClassName;
$result['Print'] = true;
//$result['print'] = true;
return $result;
}
}
function Panel()
{
global $ULANG, $ulang;
$action = '/search';
$smarty = GetUserSmarty($this->ClassName);
$result['SearchInSite'] = array( 'Title' => GetParam('ModuleSearchInSite', $ulang),
'Content' => $smarty->fetch("search-panel.tpl"),
'Module' => $this->ClassName,
);
return $result;
}
}
$Modules ['SearchInSite'] = new SearchInSite();
?>
|