error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
$render_start = time() + microtime();
// stop spammers, harvesters & etc
include "httpbl.php";
$httpbl = new httpbl("dykwtnwsqxbq");
$result = $httpbl->isListed($_SERVER['REMOTE_ADDR']);
if (is_array($result))
{
if (($result['harvester'] == 1) || ($result['comment_spammer'] == 1))
{
header('HTTP/1.1 403 Forbidden');
echo("
403 ForbiddenHttp:BL reports that you (" . $_SERVER['REMOTE_ADDR'] . ") are harvester or spammer.
If it is not true please go here: http://www.projecthoneypot.org/
Or contact with me at: drJeckyll at Jeckyll.net
");
$fp = fopen("httpbl_403.log", "a+");
fwrite($fp, date("Y:m:d H:i:s") . "\t" . $_SERVER['REMOTE_ADDR'] . "\t" . $result['harvester'] . "\t" . $result['comment_spammer'] . "\n");
fclose($fp);
exit;
}
}
require_once "config.php";
if (version_compare(PHP_VERSION, "5.6", "<"))
require_once $SQL_TYPE . ".php";
else
require_once $SQL_TYPE . "i.php";
require_once "functions.php";
require_once "template.php";
//session_name('itCMS_public');
session_name('itCMS');
session_start();
$sql = @sql_connect();
if (!$sql)
{
die("Connection error...");
}
// get configuration as global var
$_CONFIG = get_config($sql);
// check DB
check_db();
// short url
// find params if we are called with friendly url
$request = str_replace("index.php", "", html_entity_decode(urldecode($_SERVER['REQUEST_URI'])));
if ($request == "/") $request = "";
# remove all leading dots and slashes
$request = preg_replace("/^[.]*/", "", $request);
$request = preg_replace("/^[\/]*/", "", $request);
$request = preg_replace("/^[\?]*/", "", $request);
// seo
if (!count($_POST))
{
$a = explode("/", $request);
if (count($a) > 0)
foreach ($a as $b)
{
$c = explode(".", $b);
if (count($c) > 0)
{
if (preg_match("#^(.*?)\[(.*?)\]\[\]$#", html_entity_decode($c[0]), $matches))
{
//print_r($matches);
// nested array
$_GET[$matches[1]][$matches[2]][] = html_entity_decode($c[1]);
} else
if (preg_match("#^(.*?)\[(.*?)\]$#", html_entity_decode($c[0]), $matches))
{
// single array
$_GET[$matches[1]][$matches[2]] = html_entity_decode($c[1]);
} else
{
// no array
$_GET[html_entity_decode($c[0])] = html_entity_decode($c[1]);
}
}
}
}
if (!count($_POST))
{
@include "url/" . $_CONFIG['template'] . "/url.php";
if (!($handled))
{
if (preg_match("/^url([0-9]+)/", $request, $matches))
{
$q = "SELECT * FROM " . $SQL_PREFIX . "url WHERE url_id = " . $matches[1];
$result = sql_query($q, $sql);
if (sql_num_rows($result))
{
$row = sql_fetch_object($result);
$value = unserialize($row->url_value);
$_GET = array_merge($_GET, $value);
//$_POST = array_merge($_POST, $value);
//$_POST = $value;
//$_GET = $value;
$short_url_id = $row->url_id;
}
} else
{
// did we have short url?
// if not create one now :)
parse_str($request, $params);
ksort($params);
$_params = serialize($params);
$q = "SELECT * FROM " . $SQL_PREFIX . "url WHERE url_value = '" . $_params . "'";
$result = sql_query($q, $sql);
if (!sql_num_rows($result))
{
$q = "INSERT INTO " . $SQL_PREFIX . "url (url_value, url_original) VALUES ('" . $_params . "', '" . $request . "')";
sql_query($q, $sql);
$short_url_id = sql_last_insert_id($sql);
} else
{
$row = sql_fetch_object($result);
$short_url_id = $row->url_id;
}
}
}
}
// did we have language - no ? ok we set 2 (Bulgarian) for default
$lang = get_http_var('lang', $_CONFIG['default_language'], "int");
// did we have some category - no ? ok go to main
$cat = get_http_var('cat', $_CONFIG['default_page'], "int");
if (get_http_var('catname', '', 'anum') != "")
{
$q = "SELECT * FROM " . CATEGORIES_TABLE . " WHERE cat_name = '" . get_http_var('catname', '', 'anum') . "'";
$result = sql_query($q, $sql);
if (sql_num_rows($result) > 0)
{
$row = sql_fetch_object($result);
$cat = $row->cat_id;
}
}
// did we have some subcategory = no ? ok leave it empty
$subcat = get_http_var('subcat', '', 'int');
# fallback to english if there is no such language
$q = "SELECT lang_name, lang_name_display FROM " . LANGUAGES_TABLE . " WHERE lang_id=" . $lang;
$lang_result = sql_query($q, $sql);
if (sql_num_rows($lang_result) == 0)
{
$lang = 1;
$lang_name = "english";
$lang_name_display = "English";
} else
{
$lang_row = sql_fetch_object($lang_result);
$lang_name = $lang_row->lang_name;
$lang_name_display = $lang_row->lang_name_display;
}
$lang_abbr = "";
// prefix _en for english lang
if ($lang == 1) $lang_abbr = "_en";
$template_name = "templates/" . $_CONFIG['template'] . "/";
$content = new Template(".");
///////////////////////////////////////////////////////////
if (get_http_var('step', '', 'str') == "logout")
{
session_destroy();
header("Location: /");
exit;
}
if (get_http_var('step', '', 'str') == "login")
{
if (user_login($_POST['username'], $_POST['password']))
{
$step = "categories";
} else
{
$_SESSION['module_auth'] = 0;
$step = "login";
$error = L_LOGIN_ERROR;
}
}
if (get_http_var('step', '', 'str') == "activation")
{
@include_once "modules/feedback/templates/" . $_CONFIG['template'] . "/lang" . $lang_abbr . ".php";
@include_once "modules/feedback/templates/" . $_CONFIG['template'] . "/config.php";
if (($feedback_config['allow_register']) && ($feedback_config['need_confirm']))
{
$username = get_http_var('user', '', 'anum');
$hash = get_http_var('key', '', 'anum');
if (($username != "") && ($hash != ""))
{
$q = "SELECT * FROM " . USERS_TABLE . " WHERE username = '" . $username . "' AND user_hash = '" . $hash . "'";
$result = sql_query($q, $sql);
if (sql_num_rows($result) > 0)
{
$row = sql_fetch_object($result);
if (!$row->user_active)
{
$user_info = unserialize($row->user_info);
$q = "UPDATE " . USERS_TABLE . " SET user_active = 1 WHERE username = '" . $username . "'";
sql_query($q, $sql);
$text = $feedback_config['register_email_text' . $lang_abbr];
foreach ($user_info as $key => $value)
{
$text .= $key . ": " . $value . "
\n";
}
$headers = 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\n";
$headers .= 'Return-Path: ' . $feedback_config['register_email_from'] . "\n";
$headers .= 'From: ' . $feedback_config['register_email_from'] . "\n";
// send to owner
mail(
$feedback_config['register_email_to'],
$feedback_config['register_email_subject' . $lang_abbr],
$text,
$headers
);
// send to user
mail(
$row->user_email,
$feedback_config['register_email_subject' . $lang_abbr],
$text,
$headers
);
// already activated
$q = "SELECT * FROM " . CATEGORIES_TABLE . " WHERE cat_name = 'message'";
$result = sql_query($q, $sql);
if (sql_num_rows($result, $sql))
{
$row = sql_fetch_object($result);
$cat = $row->cat_id;
$message_TEXT = L_USER_ACTIVATED;
}
} else
{
// already activated
$q = "SELECT * FROM " . CATEGORIES_TABLE . " WHERE cat_name = 'message'";
$result = sql_query($q, $sql);
if (sql_num_rows($result, $sql))
{
$row = sql_fetch_object($result);
$cat = $row->cat_id;
$message_TEXT = L_USER_ALREADY_ACTIVATED;
}
}
}
}
}
}
if (get_http_var('step', '', 'str') == "passforget")
{
$username = get_http_var('user', '', 'username');
$hash = get_http_var('key', '', 'anum');
if (($username != "") && ($hash != ""))
{
$q = "SELECT * FROM " . USERS_TABLE . " WHERE username = '" . $username . "' AND user_hash = '" . $hash . "'";
$result = sql_query($q, $sql);
if (sql_num_rows($result))
{
$row = sql_fetch_object($result);
$new_password = genRandomString();
$q = "UPDATE " . USERS_TABLE . " SET user_password = '" . md5($new_password) . "', user_hash = '" . genRandomString() . "' WHERE username = '" . $username . "'";
sql_query($q, $sql);
mail(
$row->user_email,
'Нова парола',
'Новата ви парола е в ' . $_SERVER['SERVER_NAME'] . ': ' . $new_password,
'Return-Path: ' . $feedback_config['register_email_from'] . "\n" .
'From: ' . $feedback_config['register_email_from'] . "\n" .
'MIME-Version: 1.0' . "\n" .
'Content-type: text/html; charset=UTF-8' . "\n"
);
$message_TEXT = "Новата парола беше изпратена на e-mail Ви";
} else $message_TEXT = "Невалиден линк за възстановяване на парола";
} else $message_TEXT = "Невалиден линк за възстановяване на парола";
$q = "SELECT * FROM " . CATEGORIES_TABLE . " WHERE cat_name = 'message'";
$result = sql_query($q, $sql);
if (sql_num_rows($result, $sql))
{
$row = sql_fetch_object($result);
$cat = $row->cat_id;
}
}
$q = "SELECT * FROM " . CATEGORIES_TABLE . " WHERE cat_id = " . ($subcat != "" ? $subcat : $cat);
$result = sql_query($q, $sql);
$row = sql_fetch_object($result);
if ($row->cat_access != "")
{
include_once "templates/admin/lang_general.php";
$allowed = false;
if (($_SESSION['auth']) || ($_SESSION['module_auth']))
{
$access = unserialize($row->cat_access);
if (count($access) > 0)
{
if (is_array($_SESSION['user_groups_id']))
{
if (count(array_intersect($access, $_SESSION['user_groups_id'])) > 0)
{
$allowed = true;
}
}
} else $allowed = true;
} else
{
$access = unserialize($row->cat_access);
if (count($access) == 0) $allowed = true;
}
if (!$allowed)
{
// revert to message module
$q = "SELECT * FROM " . CATEGORIES_TABLE . " WHERE cat_name = 'message'";
$result = sql_query($q, $sql);
if (sql_num_rows($result, $sql) > 0)
{
$row = sql_fetch_object($result);
$cat = $row->cat_id;
unset($subcat);
$message_TEXT = L_ACCESS_DENIED;
} else
{
echo "access denied";
exit;
}
}
}
///////////////////////////////////////////////////////////
if ((get_http_var('step', '', 'str') == "module_action") && (get_http_var('modname', '', 'str') != ""))
{
$q = "SELECT * FROM " . CATEGORIES_TABLE . " WHERE cat_name = '" . get_http_var('modname', '', 'str') . "'";
$revert_cat_result = sql_query($q, $sql);
if (sql_num_rows($revert_cat_result) == 1)
{
$revert_cat_row = sql_fetch_object($revert_cat_result);
$cat = $revert_cat_row->cat_id;
}
}
$q = "SELECT cat_name AS name, cat_type_name AS type, cat_type_type AS cat_type_, cat_lang_translation_name AS trans_name, cat_lang_translation_content AS trans_content, cat_parent_id AS parent, cat_access AS access FROM " . CATEGORIES_TABLE . ", " . CATEGORIES_LANGUAGE_TABLE . ", " . CATEGORIES_TYPE_TABLE . " WHERE cat_lang_category_id=cat_id AND cat_type_id = cat_type AND cat_lang_category_id=" . ($subcat != "" ? $subcat : $cat) . " AND cat_lang_language_id=" . $lang;
$cat_result = sql_query($q, $sql);
$cat_info = sql_fetch_object($cat_result);
if ($cat_info->type != "stand_alone")
{
if ($cat_info->cat_type_ == 'module')
{
$prefix = "modules/" . $cat_info->type . "/" . $template_name . "/";
} else
{
$prefix = $template_name;
}
// allow different templates
if (file_exists($prefix . 'templates.php'))
{
include_once $prefix . 'templates.php';
$execute = "if (function_exists(\"" . $cat_info->type . "_template_callback\")) \$callback_result = " . $cat_info->type . "_template_callback(); else \$callback_result = '';";
eval($execute);
}
if (file_exists($prefix . $cat_info->type . '_' . $callback_result . '.php'))
$module_content = $prefix . $cat_info->type . '_' . $callback_result . '.php';
else
$module_content = $prefix . $cat_info->type . '.php';
$content->set_filenames(array(
'header' => $template_name . 'header.php',
'content' => (sql_num_rows($cat_result) == 0) ? $prefix . "not_found.php" : $module_content,
'footer' => $template_name . 'footer.php',
)
);
// poise _GET and _POST to content with {_variable_}
if (count($_GET))
foreach ($_GET as $g => $v)
{
$content->assign_vars(array(
'_' . $g . '_' => $v,
)
);
}
if (count($_POST))
foreach ($_POST as $p => $v)
{
$content->assign_vars(array(
'_' . $p . '_' => $v,
)
);
}
} else
{
$template = "images/" . $_CONFIG['template'] . "/templates/" . $cat_info->trans_name;
if (file_exists($template))
$content->set_filenames(array(
'content' => $template,
)
);
}
//////////////////////////////////////////////
$search = get_http_var('search', '', 'anum', '\*\.\-');
if ($search != "")
{
$page = get_http_var('page', 0, 'int');
$search_query_fulltext = do_search($search, $lang);
$product_cat = -1;
//print_r($search_query_fulltext);
$q = "SELECT * FROM " . CATEGORIES_TABLE . ", " . CATEGORIES_LANGUAGE_TABLE . $search_query_fulltext[0] . " WHERE cat_lang_category_id = cat_id AND cat_lang_language_id = " . $lang . $search_query_fulltext[1];
$all_search_result = sql_query($q, $sql);
$q = "SELECT * FROM " . CATEGORIES_TABLE . ", " . CATEGORIES_LANGUAGE_TABLE . $search_query_fulltext[0] . " WHERE cat_lang_category_id = cat_id AND cat_lang_language_id = " . $lang . $search_query_fulltext[1] . " ORDER BY cat_lang_id LIMIT " . $page . ", 10";
$search_result = sql_query($q, $sql);
$content->set_filenames(array(
'content' => $prefix . 'search.php',
)
);
while ($search_row = sql_fetch_object($search_result))
{
$text = strip_tags($search_row->cat_lang_translation_content);
$text = preg_replace('/( ){2,}/', ' ', $text);
$text_arr = explode(" ", $text);
$content->assign_block_vars('search_row', array(
'ID' => $search_row->cat_id,
'TITLE' => $search_row->cat_lang_translation_name,
'CONTENT_SHORT' => join(" ", array_slice($text_arr, 0, 30)) . "...",
)
);
}
$content->assign_vars(array(
'SEARCH' => $search,
'PAGES' => generate_pagination("?search=" . $search, sql_num_rows($all_search_result), 10, $page),
)
);
}
//////////////////////////////////////////////
if (($cat_info->cat_type_ == "module") && (get_http_var('parent', '', 'int') != ''))
{
$cat = get_http_var('parent', '', 'int');
}
$page = parse_content($cat_info->trans_content); //parse_content
$page_title = $cat_info->trans_name;
$page_description = $_CONFIG['description'];
$page_keywords = $_CONFIG['keywords'];
$content->assign_vars(array(
'PAGE_TITLE' => $_CONFIG['page_title'],
'DESCRIPTION' => $_CONFIG['description'],
'KEYWORDS' => $_CONFIG['keywords'],
//'TITLE' => $page_title,
'CONTENT' => ($page != '') ? $page : ($_CONFIG['dont_under_construction'] ? "" : "Under construction
"),
'LANG' => $lang,
'LANGNAME' => $lang_name,
'CAT' => $cat,
'SUBCAT' => $subcat,
'CATNAME' => ($cat_info->name == "") ? 'main' : $cat_info->name,
'VERSION' => $_CONFIG['version'],
'TEMPLATE' => $template_name,
'TEMPLATE_NAME' => $_CONFIG['template'],
'SCREEN' => file_get_contents("js/screen.js"),
'CLOCK' => date("H:m d/m/Y"),
'DATE' => date("d/m/Y"),
'HOUR' => date("H:m"),
)
);
if (($_SESSION['module_auth']) || ($_SESSION['auth']))
$content->assign_block_vars('switch_AUTH', array(
'USERNAME' => $_SESSION['username'],
));
else
$content->assign_block_vars('switch_NOT_AUTH', array());
$content->assign_block_vars('switch_CAT_' . $cat_info->name, array());
if (get_http_var('step', 0, 'int') == "module_action")
{
if (file_exists("modules/" . get_http_var("modname") . "/" . get_http_var("modname") . ".php"))
{
define('MODULE_OK', 1);
include_once "modules/" . get_http_var("modname") . "/" . get_http_var("modname") . ".php";
}
}
$content->assign_block_vars('switch_LANG_' . $lang_name, array());
$q = "SELECT count(cat_id) as cat_count, cat_layout FROM " . CATEGORIES_TABLE . " WHERE cat_parent_id = 0 GROUP BY cat_layout";
$result = sql_query($q, $sql);
$cat_count = array();
while ($row = sql_fetch_object($result))
{
$cat_count[$row->cat_layout] = $row->cat_count;
}
$q = "SELECT * FROM " . CATEGORIES_TABLE . ", " . CATEGORIES_LANGUAGE_TABLE . " WHERE cat_parent_id=0 AND cat_layout <> 'hidden' AND cat_lang_category_id = cat_id AND cat_lang_language_id = " . $lang . " ORDER BY cat_position";
$result = sql_query($q, $sql);
$cat_odd_even = array();
while ($row = sql_fetch_object($result))
{
$cat_odd_even[$row->cat_layout]++;
if ($row->cat_lang_translation_name != '')
{
$url = build_url($row->cat_id, $lang);
$content->assign_block_vars($row->cat_layout . '_main_categories_row', array(
'ID' => $row->cat_id,
'NAME' => $row->cat_name,
'TITLE' => $row->cat_lang_translation_name,
'SELECTED' => ($cat == $row->cat_id) ? "-over" : "",
'URL' => $url[0],
'ODD_EVEN' => ($cat_odd_even[$row->cat_layout] % 2 == 0 ? "even" : "odd"),
)
);
}
$cat_count[$row->cat_layout]--;
if ($cat_count[$row->cat_layout] > 0)
$content->assign_block_vars($row->cat_layout . '_main_categories_row.switch_MORE', array());
else
$content->assign_block_vars($row->cat_layout . '_main_categories_row.switch_LAST', array());
if ($row->cat_id == $cat)
{
$content->assign_vars(array(
'MAIN_TITLE' => ($subcat != '') ? $row->cat_lang_translation_name : "",
'MAIN_CATNAME' => $row->cat_name,
)
);
}
if ($_CONFIG['parse_subcat'])
{
$q = "SELECT * FROM " . CATEGORIES_TABLE . ", " . CATEGORIES_LANGUAGE_TABLE . " WHERE cat_parent_id = " . $row->cat_id . " AND cat_lang_category_id=cat_id AND cat_lang_language_id=" . $lang . " ORDER BY cat_position";
//AND cat_layout = '" . $row->cat_layout . "'
$sub_result = sql_query($q, $sql);
while ($sub_row = sql_fetch_object($sub_result))
{
if ($sub_row->cat_lang_translation_name != '')
{
$url = build_url($sub_row->cat_id, $lang);
$content->assign_block_vars($row->cat_layout . '_main_categories_row.' . $sub_row->cat_layout . '_subrow', array(
'NAME' => $sub_row->cat_lang_translation_name,
'CATNAME' => $sub_row->cat_name,
'CAT' => $sub_row->cat_id,
'SUBCAT' => $row->cat_id,
'URL' => $url[0],
)
);
// all subcats in one
$content->assign_block_vars($row->cat_layout . '_main_categories_row.subrow', array(
'NAME' => $sub_row->cat_lang_translation_name,
'CATNAME' => $sub_row->cat_name,
'CAT' => $sub_row->cat_id,
'SUBCAT' => $row->cat_id,
'URL' => $url[0],
)
);
}
}
}
}
/////////////////////////////////////////////////////////////////////////////
//echo "---" . $cat_info->parent;
if (($subcat != $cat) && ($subcat != 0))
$_parent = $subcat;
else
$_parent = $cat;
$a = '';
$category_path = array();
while ($_parent != 0)
{
$q = "SELECT * FROM " . CATEGORIES_TABLE . ", " . CATEGORIES_LANGUAGE_TABLE . " WHERE cat_id = " . $_parent . " AND cat_lang_category_id = cat_id AND cat_lang_language_id = " . $lang;
$_cat_result = sql_query($q, $sql);
$_cat_row = sql_fetch_object($_cat_result);
$a = '» | ' . $_cat_row->cat_lang_translation_name . '' . $a;
$_parent = $_cat_row->cat_parent_id;
$top_cat = $_cat_row->cat_id;
$category_path[] = array(
'id' => $_cat_row->cat_id,
//'parent' => $_parent,
'name' => $_cat_row->cat_lang_translation_name,
);
}
//if ($cat_info->parent != "0")
{
// | » | ' . ($lang == 1 ? "Home" : "Начало") . ' |
$a = '';
$content->assign_vars(array('CATEGORY_PATH' => $a));
unset($a);
$content->assign_vars(array('TOPCAT' => $top_cat));
}
for ($t = count($category_path) - 1; $t >= 0; $t--)
{
$content->assign_block_vars('category_path_row', array(
'CAT' => $category_path[$t]['id'],
//'SUBCAT' => ($category_path[$t]['parent'] == 0 ? "" : $category_path[$t]['parent']),
'NAME' => $category_path[$t]['name'],
)
);
if ($t > 0) $content->assign_block_vars('category_path_row.switch_MORE', array());
}
/////////////////////////////////////////////////////////////////////////////
$q = "SELECT * FROM " . USERS_LEVEL_TABLE . ", " . MODULES_TABLE . " WHERE user_level_user_id = -1 AND user_level_module_id = module_id";
$result = sql_query($q, $sql);
while ($row = sql_fetch_object($result))
{
define('MODULE_OK', 1);
include_once "modules/" . $row->module_name . "/" . $row->module_name . ".php";
}
// next / prev
$q = "SELECT * FROM " . CATEGORIES_TABLE . ", " . CATEGORIES_LANGUAGE_TABLE . " WHERE cat_parent_id=" . ($cat_info->parent == "" ? "0" : $cat_info->parent) . " AND cat_lang_category_id=cat_id AND cat_lang_language_id=" . $lang . " AND cat_layout <> 'hidden' ORDER BY cat_position";
$result = sql_query($q, $sql);
$_pos = 0;
if (sql_num_rows($result) > 0)
{
while ($_row = sql_fetch_object($result))
{
if ($_row->cat_id == $cat)
{
if ($_pos < sql_num_rows($result))
{
$next_row = sql_fetch_object($result);
}
break;
}
$prev_row = $_row;
$_pos++;
}
sql_data_seek($result, 0);
}
if ($prev_row->cat_id)
{
$content->assign_block_vars('switch_PREV_CAT', array(
'PREV_ID' => $prev_row->cat_id,
'PREV_CAT' => $prev_row->cat_name,
'PREV_TITLE' => $prev_row->cat_lang_translation_name,
)
);
$content->assign_block_vars('switch_PREV_CAT.switch_LANG_' . $lang_name, array());
} else
{
$content->assign_block_vars('switch_NO_PREV_CAT', array());
$content->assign_block_vars('switch_NO_PREV_CAT.switch_LANG_' . $lang_name, array());
}
if ($next_row->cat_id)
{
$content->assign_block_vars('switch_NEXT_CAT', array(
'NEXT_ID' => $next_row->cat_id,
'NEXT_NAME' => $next_row->cat_name,
'NEXT_TITLE' => $next_row->cat_lang_translation_name,
)
);
$content->assign_block_vars('switch_NEXT_CAT.switch_LANG_' . $lang_name, array());
} else
{
$content->assign_block_vars('switch_NO_NEXT_CAT', array());
$content->assign_block_vars('switch_NO_NEXT_CAT.switch_LANG_' . $lang_name, array());
}
// / next / prev
if ($cat_info->cat_type_ == "module")
{
define('MODULE_OK', 1);
include_once "modules/" . $cat_info->type . "/" . $cat_info->type . ".php";
} else
if (($cat_info->type != "content") &&($cat_info->type != "stand_alone"))
{
$q = "SELECT cat_id AS subcat, cat_lang_translation_name AS name, cat_name AS real_name, cat_lang_translation_content AS content, cat_layout AS layout FROM " . CATEGORIES_TABLE . ", " . CATEGORIES_LANGUAGE_TABLE . " WHERE cat_parent_id=" . $cat . " AND cat_lang_category_id=cat_id AND cat_lang_language_id=" . $lang . " AND cat_layout <> 'hidden' ORDER BY cat_position";
$result = sql_query($q, $sql);
$count = sql_num_rows($result);
while ($row = sql_fetch_object($result))
{
if ($row->name != '')
{
$url = build_url($row->subcat, $lang);
$content->assign_block_vars($row->layout . '_categories_row', array(
'NAME' => $row->name,
'REAL_NAME' => $row->real_name,
'CAT' => $cat,
'SUBCAT' => $row->subcat,
'ON' => ($subcat == $row->subcat) ? "on" : "off",
'URL' => $url[0],
)
);
if ($_CONFIG['parse_subcat'])
{
$q = "SELECT * FROM " . CATEGORIES_TABLE . ", " . CATEGORIES_LANGUAGE_TABLE . " WHERE cat_parent_id = " . $row->subcat . " AND cat_lang_category_id=cat_id AND cat_lang_language_id=" . $lang . " ORDER BY cat_position";
//echo $q . "
";
//AND cat_layout = '" . $row->layout . "'
$sub_result = sql_query($q, $sql);
while ($sub_row = sql_fetch_object($sub_result))
{
if ($sub_row->cat_lang_translation_name != '')
{
$url = build_url($sub_row->cat_id, $lang);
//echo $row->layout . '_categories_row.' . $sub_row->cat_layout . '_subrow';
//echo $sub_row->cat_name;
$content->assign_block_vars($row->layout . '_categories_row.' . $sub_row->layout . '_subrow', array(
'NAME' => $sub_row->cat_lang_translation_name,
'REALNAME' => $sub_row->cat_name,
'CAT' => $sub_row->cat_id,
'SUBCAT' => $row->subcat,
'ON' => ($sub_row->cat_id == $subcat) ? "on" : "off",
'URL' => $url[0],
)
);
}
// all subcats in one
if ($sub_row->cat_lang_translation_name != '')
$content->assign_block_vars($row->layout . '_categories_row.subrow', array(
'NAME' => $sub_row->cat_lang_translation_name,
'REAL_NAME' => $sub_row->cat_name,
'CAT' => $sub_row->cat_id,
'SUBCAT' => $row->subcat,
'ON' => ($sub_row->cat_id == $subcat) ? "on" : "off",
)
);
}
}
if ($subcat != $row->subcat)
{
$content->assign_block_vars($row->layout . '_categories_row.switch_LINK', array());
} else
{
if ($subcat != "")
{
$content->assign_vars(array(
'MAINTITLE' => $cat_info->trans_name,
'TITLE' => $row->name,
'CONTENT' => parse_content($row->content), //parse_content
)
);
}
}
}
$count--;
if ($count > 0)
$content->assign_block_vars($row->layout . '_categories_row.switch_MORE', array());
else
$content->assign_block_vars($row->layout . '_categories_row.switch_LAST', array());
}
}
$content->assign_vars(array(
'TITLE' => $page_title,
'DESCRIPTION' => $page_description,
'KEYWORDS' => $page_keywords,
)
);
if ($cat_info->type != "stand_alone")
{
$contents = fetch_contents($content->parse('header') . $content->parse('content') . $content->parse('footer'));
for ($t = 0; $t < count($contents); $t++)
{
$content->assign_block_vars('contents_row', array(
'NAME' => $contents[$t]['NAME'],
'CONTENT' => $contents[$t]['CONTENT'],
)
);
$content->assign_vars(array(
'CONTENT_' . $contents[$t]['NAME'] => $contents[$t]['CONTENT'],
));
if ($t < count($contents) - 1) $content->assign_block_vars('contents_row.switch_MORE', array());
}
$page = parse_content($content->parse('header') . $content->parse('content') . $content->parse('footer'), 1, $content);
/*
$page = parse_content($content->parse('header'));
$page .= parse_content($content->parse('content'));
$page .= parse_content($content->parse('footer'));
*/
} else
{
$page = parse_content($content->parse('content'));
}
// remove all [[xxx]] which are not parsed
$page = preg_replace('#\[\[([a-z0-9а-я\-_]*?)\]\]#isu', "", $page);
echo $page;
sql_close($sql);
?>