Курсовая работа: Разработка сайта. Система поиска по сайту
}
$term_paper=parse_ini_file (". /inc/config. inc. dat",1) or error ("не могу загрузить основной файл параметров",". /inc/config. inc. dat");
include ($term_paper ['file'] ['functions']);
CheckConf ($term_paper);
while (list ($section,$array) =each ($term_paper))
while (list ($key,$value) =each ($array))
$term_paper ['other'] [chr (73). chr (110). chr (105). ucfirst (strtolower ($section)). ucfirst (strtolower ($key))] =$value;
settype ($FirstTime=term_paper_time (),"integer");
if (isset ($_GET ['query']))
{
$query=$UserQuery=term_paper_stripslashes ($_GET ['query']);
preg_match_all ("/\w+/",$query,$QueryArray);
$TempQuery=array_unique ($QueryArray [0]);
$QueryArray [0] =$term_paper ['result'] =null;
while (list (,$value) =each ($TempQuery))
$QueryArray [0] [] =$value;
$result=array ();
$found=0;
if (! $QueryCount=count ($QueryArray [0]))
{
ParseTemplate ($term_paper ['templates'] ['top']);
if (empty ($query))
$term_paper ['other'] ['error'] =$term_paper ['error'] ['EmptyQuery'];
else
$term_paper ['other'] ['error'] =$term_paper ['error'] ['EmptyQueryAfterStrip'];
ParseTemplate ($term_paper ['templates'] ['error']);
ParseTemplate ($term_paper ['templates'] ['bottom']);
exit;
}
elseif ($QueryCount==1)
$query=$QueryArray [0] [0];
else
if (! empty ($query))
{
ParseTemplate ($term_paper ['templates'] ['top']);
$OpenDataFile=fopen ($term_paper ['file'] ['data'],'r');
flock ($OpenDataFile,1);
flock ($OpenDataFile,2);
while (! feof ($OpenDataFile))
if (preg_match ("/". $query. "/i",$string=fgets ($OpenDataFile)))
{
/*
list ($term_paper ['other'] ['link'],$term_paper ['other'] ['document']) =split (" ",$string,2);
$term_paper ['other'] ['document'] =substr ($term_paper ['other'] ['document'],0,$term_paper ['other'] ['MaxChars']);
$term_paper ['other'] ['document'] =trim (preg_replace ("/". $query. "/i","<b>\\0</b>",$term_paper ['other'] ['document'])).". ";
ParseTemplate ($term_paper ['templates'] ['result']);
flush ();
*/
$result [] =$string;
$found++;
}
fclose ($OpenDataFile);
if (! $found)
{
$term_paper ['other'] ['error'] =$term_paper ['error'] ['NoFound'];
ParseTemplate ($term_paper ['templates'] ['error']);
}
else
{
$term_paper ['other'] ['navigation'] =term_paper_array_navigation (
(isset ($result))? $result: null,
(isset ($term_paper ['other'] ['MaxShow']))? $term_paper ['other'] ['MaxShow']: null,
(isset ($term_paper ['other'] ['MaxPages']))? $term_paper ['other'] ['MaxPages']: null,
"? query=". $UserQuery. "&SearchPage=",
(isset ($_GET ['SearchPage']))? $_GET ['SearchPage']: null,
null,
null,
(isset ($term_paper ['color'] ['NotActive']))? $term_paper ['color'] ['NotActive']: null,
null,
(isset ($term_paper ['color'] ['CurrentPage']))? $term_paper ['color'] ['CurrentPage']: null,
null,
null,
" "
);
$term_paper ['strings'] =$term_paper_array_navigation;
while (list ($number,$string) =each ($term_paper ['strings'] ['result_strings']))
{
$term_paper ['other'] ['num'] =$term_paper ['strings'] ['count_all_strings'] - $term_paper ['strings'] ['start_string'] - $number;
list ($term_paper ['other'] ['link'],$term_paper ['other'] ['title'],$term_paper ['other'] ['document']) =split (" ",$string,3);
$term_paper ['other'] ['document'] =substr ($term_paper ['other'] ['document'],0,$term_paper ['other'] ['MaxChars']);
$term_paper ['other'] ['document'] =trim (preg_replace ("/". $query. "/i","<b>\\0</b>",$term_paper ['other'] ['document'])).". ";
ParseTemplate ($term_paper ['templates'] ['result']);
flush ();
}
}
$term_paper ['other'] ['query'] =htmlspecialchars ($UserQuery);
$term_paper ['other'] ['docs'] = (empty ($found))?"ноль": $found;
$term_paper ['other'] ['time'] =round (term_paper_time () - $FirstTime,3);
ParseTemplate ($term_paper ['templates'] ['stat']);
if (! empty ($found))
ParseTemplate ($term_paper ['templates'] ['navigation']);
ParseTemplate ($term_paper ['templates'] ['bottom']);
}
}
else
{
$LoadingBody=null;
$OpenLoadingFile=fopen ($term_paper ['dir'] ['templates']. chr (47). $term_paper ['template'] ['parse']. chr (47). $term_paper ['templates'] ['loading'],'r');
$LoadingBody=fread ($OpenLoadingFile,filesize ($term_paper ['dir'] ['templates']. chr (47). $term_paper ['template'] ['parse']. chr (47). $term_paper ['templates'] ['loading']));
fclose ($OpenLoadingFile);
$term_paper ['other'] ['LoadingHtmlCode'] =addslashes (term_paper_strip_new_line ($LoadingBody));
ParseTemplate ($term_paper ['templates'] ['form']);
}
? >
<br><br><br>
<div align="center">
<table>
<tr><a href=". /down.html">На главную</a></tr>
<tr><img src=". /img/logo_pic. gif"></tr>
</table></div>
Листинг admin. php
<? php
function error ($error,$file) {exit ('<font face="verdana" size="1" color="#de0000"><b>'. $error. '<br> ['.htmlspecialchars ($file). '] </b></font>'); }
@set_time_limit (0);
@SetLocale (LC_ALL,"ru_RU. CP1251");
if (isset ($_GET))
while (list ($key,$value) =each ($_GET))
$$key=$value;
header ("Expires: Mon, 26 Jul 1997 05: 00: 00 GMT");
header ("Last-Modified:". gmdate ("D, d M Y H: i: s")." GMT");
header ("Cache-Control: no-store, no-cache, must-revalidate");
header ("Cache-Control: post-check=0, pre-check=0", false);
header ("Pragma: no-cache");
function read_dir ($dir)
{
if ($OpenDir=opendir ($dir))
{
while ( ($file=readdir ($OpenDir))! ==false)
{
if ($file! =". "&&$file! =". ")
{
if (is_dir ($dir. chr (47). $file))
{
if (! is_readable ($dir. chr (47). $file))
error ("нет прав для чтения текущий папки",$dir. chr (47). $file);
elseif (! is_writeable ($dir. chr (47). $file))
error ("нет прав для записи в текущую папку",$dir. chr (47). $file);
else
read_dir ($dir. chr (47). $file);
}
else
{
if (! is_readable ($dir. chr (47). $file))
error ("нет прав для чтения файла",$dir. chr (47). $file);
elseif (! is_writeable ($dir. chr (47). $file))
error ("нет прав для записи в файл",$dir. chr (47). $file);
}
}
}
}
else error ("нет прав",$dir);
}
function CheckConf ($conf)
{
while (list ($section,$array) =each ($conf))
while (list ($key,$value) =each ($array))
if (! strlen ($value))
error ("В файле параметров скрипта, а именно в секции <font color=green>". $section. "</font>, пуст ключ <font color=green>". $key. "</font>",$conf ['dir'] ['path']. "/". $conf ['dir'] ['inc']. "/config. inc. dat");
}
if (! is_readable (". /inc")) error ("нет прав для чтения текущий папки",". /inc");
elseif (! is_writeable (". /inc")) error ("нет прав для записи в текущую папку",". /inc");
elseread_dir (". /inc");
$term_paper=parse_ini_file (". /inc/config. inc. dat",1);
CheckConf ($term_paper);
include (". /inc/functions. inc. php");
if (isset ($_SERVER ['QUERY_STRING']) &&$_SERVER ['QUERY_STRING'] =="exit")
{
$_COOKIE=null;
setcookie ($term_paper ['script'] ['prefix']. "password",null);
}
#$term_paper ['sections'] =array (
#10=>"Создание базы (индексация сайта)",
#20=>"Смена пароля",
#);
$term_paper ['sections'] =array (
'Основное меню'=>array (
'10'=>'создание базы (индексация сайта) '
),
'Пароль'=>array (
'20'=>'смена пароля'
),
'Информация'=>array (
'30'=>'версия PHP интерпретатора',
'40'=>'операционная система'
)
);
function CheckPostRequest ()
{
global $term_paper;
if (! count ($_POST)) return 0;
elseif (! isset ($_POST ['password'])) return 0;
elseif (strlen ($_POST ['password']) ==32) return 0;
else
{
setcookie ($term_paper ['script'] ['prefix']. "password",md5 ($_POST ['password']));
$_COOKIE [$term_paper ['script'] ['prefix']. "password"] =md5 ($_POST ['password']);
return 1;
}
}
function CheckAdminPassword ($password)
{
global $term_paper;
$PasswordFile=term_paper_read_file (". /inc/password. inc. dat");
if (! isset ($password)) return 0;
elseif (! isset ($PasswordFile [0])) return 0;