// to prevent session data mixup when we come from admin preview session_name("CMSFISID"); include("Init.php"); include("function/trap_xslt_error.php"); include("admin/Functions.inc"); $cID=$_POST['cID'] . $_GET['cID']; $force_dynamic=$_GET['force_dynamic']; if (!$cID) { $query_rc=mysqli_query($_SESSION["mysqli_connect_id"], "select min(content_id) from Content where content_id>0"); list($cID)=mysqli_fetch_array($query_rc); } if (isset($_GET['set_state'])) $_SESSION['s_state'] = quote_smart($_GET['set_state']); if (!isset($_SESSION['s_state'])) $_SESSION['s_state']=0; if (isset($_GET['set_language_id'])) $_SESSION['s_language_id']=quote_smart($_GET['set_language_id']); // collect statistic data (skip preview mode) if ($_SESSION['s_state']==0) { if (!$_SESSION['s_visitor_id']) { $query_rc=mysqli_query($_SESSION["mysqli_connect_id"], "insert into StatisticVisitor (entry_date, visit_seconds) values(now(), 1)"); $_SESSION['s_visitor_id'] = mysqli_insert_id($_SESSION["mysqli_connect_id"]); $_SESSION['s_visitor_start_time']=time(); } else { $tmp_visit_time=time()-$_SESSION['s_visitor_start_time']; $query_rc=mysqli_query($_SESSION["mysqli_connect_id"], "update StatisticVisitor set visit_seconds=$tmp_visit_time where visitor_id={$_SESSION['s_visitor_id']}"); } $query_rc=mysqli_query($_SESSION["mysqli_connect_id"], "insert into StatisticPage (visitor_id, content_id) values({$_SESSION['s_visitor_id']}, ". quote_smart($cID) .")"); } // static page available and convenient? if ($_SESSION['s_state'] != 0 || $_GET['from_search']) $force_dynamic=true; if (!$force_dynamic) { $today=date("d.m.Y"); $today_file_name = CMS_STATIC_PATH . "/today"; if (file_exists($today_file_name)) { $fh=fopen($today_file_name,'r'); if (filesize($today_file_name)) $today_date=fread($fh, filesize($today_file_name)); fclose($fh); } if ($today != $today_date) { reinit_static_pages(true); $fh=fopen($today_file_name,'w'); $today_date=fwrite($fh, $today); fclose($fh); } } $static_file_name = CMS_STATIC_PATH . "/{$cID}_{$_SESSION['s_language_id']}.html"; if (!$force_dynamic && file_exists($static_file_name)) { if (filesize($static_file_name) == 0) { $generate_static_file=true; } else { echo fread(fopen($static_file_name,'r'), filesize($static_file_name)); die(); } } //get content from DB $query_rc=mysqli_query($_SESSION["mysqli_connect_id"], "select xml_content from Content where content_id=". quote_smart($cID) ." and state={$_SESSION['s_state']}"); list($xml_content)=mysqli_fetch_array($query_rc); $particle_arr=array(); $query_rc=mysqli_query($_SESSION["mysqli_connect_id"], "select particle_id, particle from ContentParticle where content_id=". quote_smart($cID) ." and state={$_SESSION['s_state']} and language_id={$_SESSION['s_language_id']}"); while (list($particle_id, $particle)=mysqli_fetch_array($query_rc)) { $particle_arr[$particle_id]=$particle; } // analyze xml content $xml_parser = xml_parser_create(); if (!xml_parse_into_struct($xml_parser,$xml_content,$content_arr,$index_arr)) { die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); } xml_parser_free($xml_parser); //print_r($content_arr); //print_r($particle_arr); //print_r($index_arr); // find and process modules $module_result_arr = array(); foreach ($index_arr as $tag => $tag_index_arr) { if (strpos($tag , MOD_NAME_START) === 0) { $index_start = -1; $index_stop = -1; foreach ($tag_index_arr as $tag_index => $content_index) { // echo "tag_index $tag_index, content_index: $content_index
\n"; //echo "start: $index_start, stop: $index_stop
\n"; if ($content_arr[$content_index]['type'] == 'open' || $content_arr[$content_index]['type'] == 'complete') { $index_start = $content_index; } if ($content_arr[$content_index]['type'] == 'close' || $content_arr[$content_index]['type'] == 'complete') { $index_stop = $content_index; } // start and end index was found, process module now if ($index_start != -1 && $index_stop != -1) { //echo "start: $index_start, stop: $index_stop
\n"; $module_name=$content_arr[$index_start]['tag']; $param_arr=""; for ($i=$index_start; $i<=$index_stop; $i++) { // skip own module name if ($module_name != $content_arr[$i]['tag']) { // parameter elements must be complete if ($content_arr[$i]['type'] == 'complete') { $param_arr[$content_arr[$i]['tag']] = $particle_arr[$content_arr[$i]['attributes']['PARTICLE_ID']]; } } } //print_r($param_arr); ob_start(); include("module/$module_name.php"); $module_xml_content = ob_get_contents(); ob_end_clean(); //echo "
mod output: $module_xml_content
";
$module_result_arr[$index_start] = array('module_name' => $module_name, 'module_xml_content' => $module_xml_content);
// reset indices for next module search
$index_start = -1;
$index_stop = -1;
}
}
}
}
//print_r($module_result_arr);
// mark search items in text
if ($_SESSION['s_search_item'] && $_GET['from_search']) {
foreach ($particle_arr as $particle_index => $particle_element) {
$particle_element=preg_replace("/({$_SESSION['s_search_item']})/i", "$1", $particle_element);
$particle_arr[$particle_index]=preg_replace("/]*href=([\"\']??)([^\" >]*?)([^\" >]*?)<\/span>([^\" >]*?)\\1([^>]*)>(.*)<\/a>/siU", "$6", $particle_element);
}
}
// build new xml stream (with module output)
$new_xml_content = ""; // add meta data as last step
$in_module=false;
foreach ($content_arr as $content_index => $element) {
// echo " $content_index
";
// print_r($module_result_arr[$content_index]);
// print_r($element);
if ($module_result_arr[$content_index]) {
$in_module=true;
$module_name=$module_result_arr[$content_index]['module_name'];
$new_xml_content .= $module_result_arr[$content_index]['module_xml_content'];
}
if ($in_module && $module_name == $element["tag"] && ($element["type"] == 'close' || $element["type"] == 'complete')) {
$in_module=false;
continue;
}
if ($in_module)
continue;
if ($element["type"] == "open") {
$new_xml_content .= "<".$element["tag"];
if ($element["attributes"]) {
foreach ($element["attributes"] as $attribute => $attribute_value)
$new_xml_content .= " $attribute=\"$attribute_value\"";
}
$new_xml_content .= ">";
}
if ($element["type"] == "complete") {
$new_xml_content .= "<".$element["tag"];
if ($element["attributes"]) {
foreach ($element["attributes"] as $attribute => $attribute_value)
$new_xml_content .= " $attribute=\"$attribute_value\"";
}
$new_xml_content .= ">