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 .= ">\n"; } if ($element["type"] == "close") $new_xml_content .= "\n"; } $new_xml_content .= ''; // get matching keywords from pool $keyword_arr=array(); if (DEF_CREATE_KEYWORDS) { $key_pool_arr=array(); $key_pool_case_arr=array(); $query_rc=mysqli_query($_SESSION["mysqli_connect_id"], "select keyword from Keyword where language_id={$_SESSION['s_language_id']}"); while (list($keyword)=mysqli_fetch_array($query_rc)) { $key_pool_arr[]=strtolower($keyword); $key_pool_case_arr[]=$keyword; } $used_word_arr=array(); $word_arr=array(); $interpunktion_arr=array(".", ",", ";", ":", "\n", "\r"); foreach ($particle_arr as $index => $val) { $val=str_replace($interpunktion_arr, "", $val); $val=strtolower($val); $val_arr=explode(" ", $val); foreach ($val_arr as $index2 => $val2) { if ($val2 && !$used_word_arr[$val2]) { $word_arr[]=$val2; $used_word_arr[$val2]=1; } } } $meta_arr=array_unique(array_intersect($key_pool_arr, $word_arr)); //print_r($key_pool_arr); //print_r($meta_arr); foreach ($meta_arr as $index => $val) { $keyword_arr[]=$key_pool_case_arr[$index]; } } // get meta data $query_rc=mysqli_query($_SESSION["mysqli_connect_id"], "select name, description from Meta where language_id={$_SESSION['s_language_id']}"); $standard_keywords=""; $meta_str = ""; while (list($name, $description)=mysqli_fetch_array($query_rc)) { if ($name == "title") $meta_str .= "<![CDATA[$description]]>\n"; else if ($name == "keywords") $standard_keywords .= "$description "; else $meta_str .= "\n"; } $keywords=implode(",", $keyword_arr); if ($standard_keywords) { if ($keywords) $keywords .= "," . $standard_keywords; else $keywords = $standard_keywords; } $keywords=substr($keywords,0,1000); if ($keywords) $meta_str .= "\n"; $meta_str .= "\n"; // build new xml stream (with module output) $new_xml_content = DEF_XML_VERSION_ENCODING . "$meta_str" . $new_xml_content; //echo $new_xml_content; //fputs(fopen('/tmp/trace.xml','w'),$new_xml_content); $arguments = array( '/_xml' => $new_xml_content, ); // Allocate a new XSLT processor $xh = xslt_create(); xslt_set_base( $xh, "$XSL_root"); xslt_set_error_handler($xh, "trap_xslt_error"); // Process the document $result = xslt_process($xh, "arg:/_xml", $XSL_page, NULL, $arguments); if ($result) { echo $result; if ($generate_static_file) fputs(fopen($static_file_name, 'w'), $result); } else { // mail($admin_mail, "XML-Fehler", "content ID: $cID\n\nReferer: $HTTP_REFERER\n\n" . $error_msg_xsl . "\n\nXML content:\n\n" . $new_xml_content, "From: $admin_mail"); echo $error_msg_xsl . "\n\nXML content:\n\n" . $new_xml_content; } xslt_free($xh); ?>