вот собственно код... строка 262
<?php
/**
* Основные функции
*
* @package wmcore
* @version $Id: site.inc,v 3.5.6 2008/10/28 12:49:12 art Exp $
* @author Artem Orlov 1999-2008
* @author Nik Komarkov 1999-2006
*/
define('SITE_DIR', dirname(dirname(dirname(__FILE__))).'/');
/**
* признак режима редактирования сайта
*/
define('EDITOR', false);
require (SITE_DIR.'cms/inc/utils.inc');
require (SITE_DIR.'cms/inc/ini.inc');
require (SITE_DIR.'cms/inc/smarty/Smarty.class.php');
/**
* Инициализации шаблонной системы Smarty
*
*/
$smarty = new Smarty;
$smarty->use_sub_dirs = false;
$smarty->_file_perms = 0664;
$smarty->_dir_perms = 0771;
$smarty->caching = false; // кэширование
$smarty->template_dir = SITE_DIR.'cms/templates/'.$site['design'];
$smarty->cache_dir = SITE_DIR.'cms/cache/'.$site['design'];
$smarty->compile_dir = SITE_DIR.'cms/templates_c/'.$site['design'];
$smarty->config_dir = SITE_DIR.'cms/configs';
$smarty->plugins_dir[] = 'custom';
chdir(SITE_DIR);
/**
* Инициализация данных текущего раздела
*/
$current_category = array(
'category_id' => 2,
'parent_id' => CATEGORY_PARENT_ID,
'tag' => SITE_DEFAULT_LANG,
'title' => '',
'pic' => '',
'type' => 0,
'url' => '',
'description' => '',
'description_top' => '',
'description_bottom' => '',
'navy_tag' => '',
'navy_array' => array(),
'menu_visible' => '1');
/**
* Параметры документа
*/
$http_file_values = array();
/**
* Параметры раздела
*/
$http_category_values = array();
/**
* Уровень раздела в дереве сайта
*/
$global_level = 0;
/**
* Разбор строки запроса
*/
if (isset($_SERVER['PATH_INFO']) && SITE_URLPARCE) {
if (preg_match("{^([A-Z/0-9_\.]*?)([,-].*?)?(/(([A-Z0-9_\-,]*)\.html))?$}i", $_SERVER['PATH_INFO'], $url_matches)) {
$sql = "select *, unix_timestamp(page_datetime) page_datetime from category where navy_tag='". mysql_real_escape_string($url_matches[1])."'";
$query = mysql_query ($sql, $link) or sql_error ($sql, $link, __FILE__, __LINE__);
if ($query && mysql_num_rows($query)) {
$current_category = mysql_fetch_assoc ($query);
$current_category['navy_array'] = unserialize($current_category['navy_array']);
category_stripcslashes($current_category);
// Получаем параметры раздела
if (isset($url_matches[2]) && trim($url_matches[2]) != '') {
$http_category_values = preg_split ("/[,-]+/", $url_matches[2]);
array_shift ($http_category_values); // Стирание первого пустого значения
}
if (isset($url_matches[5]) && trim($url_matches[5]) != '') {
$http_file_values = preg_split ("/[,-]+/", $url_matches[5]);
}
}
else {
header("HTTP/1.0 404 Not Found");
header("Location: /404\n\n");
exit;
}
}
else {
header("HTTP/1.0 404 Not Found");
header("Location: /404\n\n");
exit;
}
unset($url_matches);
$global_level = intval(count($current_category['navy_array']));
$global_level--;
/**
* построение правильных ссылок на разделы
*/
for ($i=$global_level; $i>=0; $i--) {
category_item($current_category['navy_array'][$i]);
}
unset($i);
}
define('SITE_LANG', ($current_category['navy_array'][0]['tag'] != '') ? $current_category['navy_array'][0]['tag'] : SITE_DEFAULT_LANG);
/**
* Автоматическая загрузка модулей
*
*/
if ($autoloaddir = @opendir(SITE_DIR.'cms/inc/auto')) {
while (($autoloadfile = readdir($autoloaddir)) !== false) {
if (preg_match("/^[^.].*?\.inc$/",$autoloadfile)) require (SITE_DIR.'cms/inc/auto/'.$autoloadfile);
}
unset($autoloadfile);
}
closedir($autoloaddir);
unset($autoloaddir);
/**
* загружаем основные сообщения
*/
wm_get_common_messages();
/**
* Текстовые блоки
*/
category_text_block($current_category);
/**
* Правильная ссылка на текущий раздел
*/
$current_category['navy_url'] = ($GLOBALS['site']['url_rewrite']) ? strip_lang($current_category['navy_tag']) : '/index'.$current_category['navy_tag'];
/**
* заголовок страницы и мета данные
*/
seo_page_data($current_category);
$smarty->assign_by_ref('current_category', $current_category);
/**
* логирование запросов от поисковых систем
*/
if ($site['searchengine_log'] && searchengine()) {
seo_crawler_log();
}
else {
session_start();
session_register('last_url');
$_SESSION['last_url'] = $_SERVER['REQUEST_URI'];
}
/**
* Инициализация списка подразделов
*/
$category_rows = array();
/**
* Извлечение и выполнение кода PHP из текcта
*
* @param string $arg_body тело документа
* @return обработанный текст
*/
function eval_string($arg_body) {
return preg_replace_callback("/(<\?|<\?php|{php})(.*?)(\?>|{\/php})/is", create_function('$matches', 'ob_start(); eval($matches[2]); $txt = ob_get_contents(); ob_end_clean(); return $txt;'), $arg_body);
}
/**
* Вывод текущего раздела
*
* @author Nikolay Komarkov
* @author Artem Orlov
* @param $current_category Данные текущего раздела
* @return
* @since 1.0
*/
function category_show(&$current_category) {
global $link, $category_rows, $smarty, $http_category_values;
/**
* список подразделов
*/
$sql = 'select *
from category
where parent_id='.$current_category['category_id'].' and '.SITE_SQL_LIMIT.'
order by prioritet, title';
$query = mysql_query($sql, $link) or sql_error ($sql, $link, __FILE__, __LINE__);
if ($query) {
while ($row = mysql_fetch_assoc($query)) {
category_item($row);
category_stripcslashes($row);
$category_rows[] = $row;
}
}
// подключение внешних файлов
if ($current_category['type'] == 2) {
$current_category['description_top'] = get_remote_document($current_category['description_top']);
$current_category['description_bottom'] = get_remote_document($current_category['description_bottom']);
}
$current_category['description_top'] = eval_string($current_category['description_top']);
/**
* Подключение пользовательской функции
*/
if (function_exists($current_category['user_function'])) {
eval('$current_category["description_top"] .= '.$current_category["user_function"].'('.$current_category["user_function_params"].');');
}
$current_category['description_bottom'] = eval_string($current_category['description_bottom']);
$smarty->assign_by_ref('category_rows', $category_rows);
return $smarty->fetch($current_category['category_layout']);
}
/**
* Подготовка ссылки на раздел
*
* @param array $category
*/
function category_item(&$category) {
if ($category['type'] == 0 || $category['type'] == 2) {
$category['href'] = ($GLOBALS['site']['url_rewrite']) ? strip_lang($category['navy_tag']) : "/index".$category['navy_tag'];
}
elseif ($category['type'] == 1) {
$category['href'] = $category['url'];
}
}
/**
* Текстовые блоки
*
* @param array $current_category
*/
function category_text_block(&$category) {
global $link;
$child_list = '';
$sql = 'select child_list from category where category_id='.$category['navy_array'][0]['category_id'];
$query = mysql_query ($sql, $link) or sql_error ($query, $link, __FILE__, __LINE__);
if ($query && mysql_num_rows($query)) {
list($child_list) = mysql_fetch_row($query);
}
if ($child_list != '') {
$child_list = $child_list.','.$category['navy_array'][0]['category_id'];
}
else {
$child_list = $category['navy_array'][0]['category_id'];
}
$sql = "select * from category_texts
where category_id=".$category['category_id'].'
or (recursive=1 and category_id in ('.$child_list.'))
or recursive=2
order by recursive desc';
$query = mysql_query ($sql, $link) or sql_error ($query, $link, __FILE__, __LINE__);
if ($query && mysql_num_rows($query)) {
while ($row = mysql_fetch_assoc($query)) {
if (!isset($category['text'][$row['tag']])) {
$row['text_block'] = stripcslashes($row['text_block']);
$row['user_function_params'] = stripcslashes($row['user_function_params']);
/**
* Подключение пользовательской функции
*/
if ($row['user_function'] != '' && function_exists($row['user_function'])) {
eval('$row["text_block"] .= '.$row['user_function'].'('.$row['user_function_params'].');');
}
$category['text'][$row['tag']] = $row['text_block'];
}
}
unset($row);
}
}
/**
* Подготовка ссылки на документ
*
* @param array $doc
*/
function document_item (&$doc) {
if (!isset($doc['navy_tag']) || $doc['navy_tag'] == '') {
$doc['navy_tag'] = $GLOBALS['current_category']['navy_tag'];
}
// Обычный или с подгружаемым файлом
if ($doc['type'] == 0 || $doc['type'] == 2) {
$doc['href'] = (($GLOBALS['site']['url_rewrite']) ? strip_lang($doc['navy_tag']) : '/index'.$doc['navy_tag']).'/'.$doc['doc_id'].'.html';
}
// файл
elseif ($doc['type'] == 4) {
$doc['extention_pic'] = '/pic/ext/doc.gif';
if (preg_match("/([^\.]+)$/", $doc['url'], $matches)) {
$doc['extention'] = strtolower($matches[1]);
if (file_exists(SITE_DIR.$GLOBALS['site']['html'].'/pic/ext/'.$doc['extention'].'.gif')) {
$doc['extention_pic'] = '/pic/ext/'.$doc['extention'].'.gif';
}
}
document_size($doc);
$doc['href'] = $doc['url'];
}
// видео
elseif ($doc['type'] == 5) {
document_size($doc);
$doc['href'] = (($GLOBALS['site']['url_rewrite']) ? strip_lang($doc['navy_tag']) : '/index'.$doc['navy_tag']).'/'.$doc['doc_id'].'.html';
}
// Внутрення ссылка
else {
$doc['href'] = $doc['url'];
}
}
/**
* Размер документа
*
* @param array $doc
*/
function document_size (&$doc) {
$a = array("B", "KB", "MB", "GB", "TB", "PB");
$doc['size'] = 0;
$doc['size_fancy'] = '';
if (file_exists(SITE_DIR.$GLOBALS['site']['html'].'/'.$doc['url'])) {
$pos = 0;
$size = filesize(SITE_DIR.$GLOBALS['site']['html'].'/'.$doc['url']);
$doc['size'] = $size;
while ($size >= 1024) {
$size /= 1024;
$pos++;
}
$doc['size_fancy'] = round($size,2).' '.$a[$pos];
$doc['filename'] = basename($doc['url']);
}
}
/**
* Вывод документа
*
* @author Artem Orlov <art@ural.ru>
* @param array $params Параметы из $http_file_vars
* @return HTML
*/
function document_show($params) {
global $smarty, $link, $current_category;
$doc_id = isset($params[0]) ? intval($params[0]) : 0;
if ($doc_id == 0) {
header("HTTP/1.0 404 Not Found");
header('Location: '.strip_lang('/'.SITE_LANG.'/404')."\n\n");
exit;
}
if (!$smarty->is_cached('document_show.tpl', $current_category['category_id'].'|'.$doc_id)) {
$sql = 'select *, unix_timestamp(add_date) add_date_uts, unix_timestamp(update_date) update_date_uts, unix_timestamp(page_datetime) page_datetime
from doc
where doc_id='.$doc_id.' and category_id='.$current_category['category_id'];
$q = mysql_query($sql, $link) or sql_error ($sql, $link, __FILE__, __LINE__);
if ($q && mysql_num_rows ($q)) {
$document = mysql_fetch_assoc($q);
document_stripcslashes($document);
/**
* получение внешнего файла
*/
if ($document['type'] == 2) {
$document['document'] = get_remote_document($document['document']);
}
/**
* информация о видео файле
*/
elseif ($document['type'] == 5) {
if (preg_match("/\.flv$/i", $document['url'])) {
$document['flash_video'] = true;
require_once(SITE_DIR.'cms/inc/amf0/flvinfo2.php');
$flvinfo = new FLVInfo2();
$info = $flvinfo->getInfo(SITE_DIR.$GLOBALS['site']['html'].$document['url'], true);
$document['width'] = intval($info->video->width);
$document['height'] = intval($info->video->height);
$document['width_standart'] = 480; // Youtube standart
$document['height_standart'] = intval(480*$document['height']/$document['width']);
//if (!file_exists(SITE_DIR.$document['pic'])) {
// $document['pic'] = '/pic/preview.jpg';
//}
}
else {
$document['flash_video'] = false;
require_once(SITE_DIR.'cms/inc/getid3/getid3.php');
$getid3 = new getID3;
$getid3->Analyze(SITE_DIR.$GLOBALS['site']['html'].$document['url']);
$document['video'] = @$getid3->info['video'];
$document['video_x2'] = intval($document['video']['resolution_x']*1.5);
$document['video_y2'] = intval($document['video']['resolution_y']*1.7);
}
document_size($document);
}
/**
* Подключение пользовательской функции
*/
if (function_exists($document['user_function'])) {
eval('$document["document"] .= '.$document["user_function"].'('.$document["user_function_params"].');');
}
$current_category['page_title'] = (trim($document['page_title']) != '') ? $document['page_title'] : $document['title'];
$current_category['page_description'] = (trim($document['page_description']) != '') ? $document['page_description'] : $current_category['page_description'];
$current_category['page_keywords'] = (trim($document['page_keywords']) != '') ? $document['page_keywords'] : $current_category['page_keywords'];
$current_category['page_datetime'] = ($document['page_datetime'] > $current_category['page_datetime']) ? $document['page_datetime'] : $current_category['page_datetime'];
$smarty->assign('document', $document);
}
else {
header("HTTP/1.0 404 Not Found");
header('Location: '.strip_lang('/'.SITE_LANG.'/404')."\n\n");
exit;
}
}
return $smarty->fetch('document_show.tpl', $current_category['category_id'].'|'.$doc_id);
}
/**
* Получение удаленного файла
*
* @author Artem Orlov
* @param string $document тело документа должно содержать ссылку на файл или урл
* @return тело внешнего документа или исходный текст
* @since 3.0
*/
function get_remote_document($document) {
if (preg_match('{^((ftp|http|file)<img src="img/smilies/hmm.png" width="15" height="15" alt="hmm" />/(\S+)).*?$}i', $document, $remote_url)) {
if ($remote_url[2] == 'file') { // открыть файл с файловой системы
$remote_fp = fopen ($remote_url[3], 'r');
}
elseif ($remote_url[2] == 'ftp' || $remote_url[2] == 'http') { // открыть файл через HTTP или FTP
$remote_fp = fopen ($remote_url[1], 'r');
}
if ($remote_fp) {
$remote_file = '';
while (!feof($remote_fp)) {
$remote_file .= fread ($remote_fp, 1024);
}
fclose ($remote_fp);
$root_url = '';
if (preg_match('{^(http://\S+)/.*?$}i', $document, $ok)) {
$root_url = $ok[1];
}
return $remote_file;
}
else {
return $document;
}
}
else {
return $document;
}
}
/**
* show_template
*
* отображение указанного шаблона
*
* @author Nik Komarkov <nik@ural.ru> 2005
*/
function show_template ($tpl) {
global $smarty;
return $smarty->fetch($tpl);
}
/**
* Заголовок и мета данные страницы
*
* @param array $current_category
*/
function seo_page_data(&$current_category) {
global $global_level;
/**
* Мета описание страницы
*/
if (!isset($current_category['page_description']) || trim($current_category['page_description']) == '') {
for ($i=$global_level; $i>=0; $i--) {
if (isset($current_category['navy_array'][$i]['page_description']) && trim($current_category['navy_array'][$i]['page_description']) != '') {
$current_category['page_description'] = $current_category['navy_array'][$i]['page_description'];
break;
}
}
unset($i);
}
/**
* Мета ключевые слова страницы
*/
if (!isset($current_category['page_keywords']) || trim($current_category['page_keywords']) == '') {
for ($i=$global_level; $i>=0; $i--) {
if (isset($current_category['navy_array'][$i]['page_keywords']) && trim($current_category['navy_array'][$i]['page_keywords']) != '') {
$current_category['page_keywords'] = $current_category['navy_array'][$i]['page_keywords'];
break;
}
}
unset($i);
}
/**
* Заголовок страницы
*/
if (!isset($current_category['page_title']) || trim($current_category['page_title']) == '') {
$current_category['page_title'] = $GLOBALS['site']['name'];
$current_category['page_title'] .= (isset($current_category['navy_array'][$global_level-1]['title']) && $global_level > 1) ? ' '.$GLOBALS['site']['delimiter'].' '.$current_category['navy_array'][$global_level-1]['title'] : '';
$current_category['page_title'] .= (isset($current_category['navy_array'][$global_level]['title']) && $global_level != 0) ? ' '.$GLOBALS['site']['delimiter'].' '.$current_category['navy_array'][$global_level]['title'] : '';
}
}
/**
* логирование запросов поисковых систем
*
*/
function seo_crawler_log() {
$user_log_fp = fopen (SITE_DIR.'search_engines'.strftime("_%Y%m").'.log', 'a');
fwrite ($user_log_fp, "----------------------------\n");
fwrite ($user_log_fp, strftime("%Y.%m.%d %T")."\n");
fwrite ($user_log_fp, $_SERVER['REMOTE_ADDR'].' => '.$_SERVER['REQUEST_URI']."\n");
if (function_exists('getallheaders')) {
$se_headers = getallheaders();
while (list($se_key,$se_val)=each($se_headers)) {
fwrite ($user_log_fp, "$se_key => $se_val\n");
}
}
fclose ($user_log_fp);
}
?>
Отредактированно SkyVolkov (21.06.2009 15:59:02)