vars = &$INFO; } } //-------------------------------- // Import $INFO, now! //-------------------------------- $INFO = array(); require ROOT_PATH."conf_global.php"; if ( USE_DEBUG ) { $Debug = new Debug; $Debug->startTimer(); } require ROOT_PATH."sources/functions.php"; class my_FUNC extends FUNC { /*-------------------------------------------------------------------------*/ // ERROR FUNCTIONS /*-------------------------------------------------------------------------*/ function my_FUNC() { parent::FUNC(); } function Error($error) { global $ibforums, $std, $_page, $page_data, $output; $ibforums->lang = $this->load_words($ibforums->lang, "lang_error", $ibforums->lang_id); $msg_title = $ibforums->lang['msg_head']; $msg_text = $error['MSG_TXT']?$error['MSG_TXT']:$ibforums->lang[$error['MSG']]; if ($error['EXTRA']) { $msg_text = preg_replace( "/<#EXTRA#>/", $error['EXTRA'], $msg_text ); } out_start(); if ( USE_DEBUG ) { $output .= clean_post($_page->build_row( array ( 'forum_name' => $page_data['board_title'], 'forum_url' => $page_data['board_link'], 'topic_name' => $msg_title, 'topic_url' => $page_data['board_link'], 'post_url' => $page_data['board_link'], 'post_rfc_date'=> gmdate('r'), 'post_date' => $std->get_date(gmmktime(), 'LONG'), 'author_name' => $page_data['board_title'], 'author_url' => $page_data['board_link'], 'post_text' => $msg_text))); get_debug_info($output); } out_finish(); } } $std = new my_FUNC; $sess = new session(); //-------------------------------- // Load the DB driver and such //-------------------------------- $INFO['sql_driver'] = !$INFO['sql_driver'] ? 'mySQL' : $INFO['sql_driver']; require (ROOT_PATH."sources/Drivers/".$INFO['sql_driver'].".php"); $DB = new db_driver; $DB->obj['sql_database'] = $INFO['sql_database']; $DB->obj['sql_user'] = $INFO['sql_user']; $DB->obj['sql_pass'] = $INFO['sql_pass']; $DB->obj['sql_host'] = $INFO['sql_host']; $DB->obj['sql_tbl_prefix'] = $INFO['sql_tbl_prefix']; // Get a DB connection $DB->connect(); $ibforums = new info(); $ibforums->input = $std->parse_incoming(); $ibforums->member = $sess->authorise(); $ibforums->location = $sess->location; $ibforums->base_url = $ibforums->vars['board_url'].'/index.'.$ibforums->vars['php_ext']; if ( USE_DEBUG ) { $DB->obj['debug'] = ($INFO['sql_debug'] == 1) ? $ibforums->input['debug'] : 0; } //Skin loading if (USE_TEMPLATE){ $ibforums->skin = $std->load_skin(); $ibforums->skin_rid = $ibforums->skin['set_id']; $ibforums->skin_id = 's'.$ibforums->skin['set_id']; $ibforums->vars['img_url'] = 'style_images/' . $ibforums->skin['img_dir']; $page_data['skin_templt_path'] = $ibforums->vars['board_url'].'/'.$page_data['skin_folder_name'].'/'.($page_data['skin_templt_path']?$page_data['skin_templt_path']:$ibforums->skin_id); $page_data['skin_images_path'] = $ibforums->vars['board_url'].'/'.($page_data['skin_images_path']?$page_data['skin_images_path']:$ibforums->vars['img_url']); }else{ $page_data['skin_images_path'] = $ibforums->vars['board_url'].'/'.$page_data['skin_images_path']; } //Lang loading //$ibforums->vars['default_language'] = ($ibforums->vars['default_language'] == "")?'en':$ibforums->vars['default_language']; //$ibforums->lang_id = ($ibforums->member['language'] && is_dir(ROOT_PATH."lang/".$ibforums->member['language'])) ? $ibforums->member['language'] : $ibforums->vars['default_language']; //$ibforums->lang = $std->load_words($ibforums->lang, 'lang_rss', $ibforums->lang_id); $_page = new page_builder(); //-------------------------------- // Do we have permission to view // the board? //-------------------------------- if ($ibforums->member['g_view_board'] != 1) { $std->Error( array('MSG' => 'no_view_board') ); } //-------------------------------- // Is the board offline? //-------------------------------- if ($ibforums->vars['board_offline'] == 1) { if ($ibforums->member['g_access_offline'] != 1) { $std->Error( array('MSG' => 'offline_title') ); } } require ROOT_PATH."sources/lib/post_parser.php"; $parser = new post_parser(); $posts = get_posts(); $xml = ""; foreach ($posts as $post) { $xml .= $_page->build_row($post); } get_debug_info($xml); // output out_start(); $output .= clean_post($xml); out_finish(); //+------------------------------------------------ // GLOBAL ROUTINES //+------------------------------------------------ function get_debug_info(&$xml){ global $ibforums,$Debug,$DB,$page_data,$_page,$std; if ( USE_DEBUG ) { $text = "[ UserID: ".$ibforums->member['id']." ]   [ Script Execution time: ".sprintf( "%.4f",$Debug->endTimer())." ]   [ ".$DB->get_query_cnt()." queries used ]"; if ($DB->obj['debug']){ flush(); $text .= "

SQL Total Time: {$DB->sql_time} for ".$DB->get_query_cnt()." queries
".$ibforums->debug_html."
Total SQL Time: {$DB->sql_time}
"; } $xml .= $_page->build_row( array ( 'forum_name' => $page_data['board_title'], 'forum_url' => $page_data['board_link'], 'topic_title' => "Debug Info", 'topic_url' => $page_data['board_link'], 'post_url' => $page_data['board_link'], 'post_rfc_date'=> gmdate('r'), 'post_date' => $std->get_date(gmmktime(), 'LONG'), 'author_name' => "Debug Info:", 'author_url' => $page_data['board_link'], 'post_text' => $text)); } } function get_posts(){ global $DB, $std, $ibforums; $posts = array(); $allowed = array(); $forbidden = array(); $forums = array(); $topics = array(); // Get forums info $DB->query("SELECT id,parent_id,read_perms,password,redirect_on,status,name FROM ibf_forums"); if (!$DB->get_num_rows()){ $std->Error( array('MSG_TXT'=>"Нет записей, соответствующих вашему запросу")); } while ($row = $DB->fetch_row() ){ /* Check if we have proper permissions to access the row, if not * put it to the 'forbidden' list, otherwise use 'allowed' list */ if ($row['password'] or $row['redirect_on'] or $std->check_perms($row['read_perms']) != TRUE or !$row['status']){ $forbidden[$row['id']] = $row['id']; }else{ $allowed[$row['id']] = $row['id']; } $forums[$row['id']] = $row; if ($row['parent_id']>0 && $ibforums->input['fs']==1) $forums[$row['parent_id']]['childs'][$row['id']] = $row['id']; } $DB->free_result(); // Build posts where clause $whereClause = buildUserWhereClause($allowed, $forbidden, $forums); // Get posts data $DB->query("SELECT pid, author_name, post_date, forum_id, topic_id, author_id, post FROM ibf_posts ".$whereClause." ORDER BY pid DESC LIMIT 0, ".((intval($ibforums->input['pn']) && intval($ibforums->input['pn'])input['pn']) : POST_LIMIT)); $posts_num = $DB->get_num_rows(); if (!$posts_num){ $std->Error( array('MSG_TXT'=>"Нет записей, соответствующих вашему запросу")); } for ($i=0; $i<$posts_num; $i++){ $row=$DB->fetch_row(); $posts[$i]["post_id"] = $row["pid"]; $posts[$i]["post_text"] = $row["post"]; $posts[$i]["post_date"] = $std->get_date($row['post_date'], 'LONG'); $posts[$i]["post_rfc_date"] = date('r', $row['post_date']); $posts[$i]["post_url"] = $ibforums->base_url."?act=ST&f=".$row['forum_id']."&t=".$row['topic_id']."&hl=&view=findpost&p=".$row['pid']; $posts[$i]["forum_id"] = $row['forum_id']; $posts[$i]["forum_name"] = $forums[$row['forum_id']]['name']; $posts[$i]["forum_url"] = $ibforums->base_url."?act=SF&f=".$row['forum_id']; $posts[$i]["author_id"] = $row['author_id']; $posts[$i]["author_name"] = $row['author_name']; $posts[$i]["author_url"] = $ibforums->base_url."?act=Profile&CODE=03&MID=".$row['author_id']; $posts[$i]["topic_id"] = $row['topic_id']; $topics[$row['topic_id']] = $row['topic_id']; } $DB->free_result(); unset($forums); /* Add topic names and urls to the output */ $where_clause = buildWhereClause($topics, "tid=", "OR"); $where_clause = finishWhereClause($where_clause); if (strlen($where_clause)){ $DB->query("SELECT tid,title FROM ibf_topics".$where_clause); while ($topic = $DB->fetch_row()){ $topics[$topic['tid']] = preg_replace("'&'si", "&", $topic['title']); } $DB->free_result(); foreach ($posts as $i=>$row) { $posts[$i]["topic_name"] = $topics[$row['topic_id']]; $posts[$i]["topic_url"] = $ibforums->base_url."?act=ST&f=".$row['forum_id']."&t=".$row['topic_id']."&hl=&#entry".$row['post_id']; } } unset($topics); return $posts; } function buildUserWhereClause(&$allowed, &$forbidden, $forums=null){ global $ibforums; $whereClause = ($ibforums->member["id"] && $ibforums->input["sl"]==1)?"post_date > ".$ibforums->member['last_visit']:""; if (is_array($forums)){ $_forums = array(); /* The following code deals with forum related input variables */ if (isset($ibforums->input["nf"])) { /* A user asked for all posts except ones from the ?nf= forums, get * their ids from the nf input variable and forbid them in the where * clause */ preg_match_all("/(?<=,|^)([0-9]+)(?=,|$)/", $ibforums->input["nf"], $in); foreach ($in[1] as $value) if (isset($forums[$value]["id"]) && isset($allowed[$value])){ if (!isset($_forums[$value])) $_forums[$value] = $value; // get fs if ($ibforums->input["fs"]==1 && is_array($forums[$value]['childs'])){ foreach ($forums[$value]['childs'] as $_value) { if (!isset($_forums[$_value])) $_forums[$_value] = $_value; } } } $whereClause = buildWhereClause($_forums, "forum_id!=", "AND", $whereClause, "AND", false); } elseif (isset($ibforums->input["f"])) { /* A user asked for posts only from the forums specified in the * ?f= request, get their ids from the f input variable and add * them to the where clause */ preg_match_all("/(?<=,|^)([0-9]+)(?=,|$)/", $ibforums->input["f"], $in); foreach ($in[1] as $value) if (isset($forums[$value]["id"]) && !isset($forbidden[$value])){ if (!isset($_forums[$value])) $_forums[$value] = $value; // get fs if ($ibforums->input["fs"]==1 && is_array($forums[$value]['childs'])){ foreach ($forums[$value]['childs'] as $_value) { if (!isset($_forums[$_value])) $_forums[$_value] = $_value; } } } $whereClause = buildWhereClause($_forums, "forum_id=", "OR", $whereClause, "AND", true); } else { /* Default actions, when no input variables specified - either addd * all allowed forums or forbid all forbidden forums in the where clause * depending of which set is larger. */ if (count($forbidden) > count($allowed)){ $whereClause=buildWhereClause($allowed, "forum_id=", "OR", $whereClause, "AND", true); } else { $whereClause=buildWhereClause($forbidden, "forum_id!=", "AND", $whereClause, "AND", false); } } /* The following code handles topic related input variables */ if (isset($ibforums->input["nt"])) { /* A user asked to exclude several topics, get their ids from nt input * variable and forbid them in the where clause */ preg_match_all("/(?<=,|^)([0-9]+)(?=,|$)/", $ibforums->input["nt"], $in); foreach ($in[1] as $value) $_topics[] = $value; $whereClause = buildWhereClause($_topics, "topic_id!=", "AND", $whereClause, "AND", false); } elseif (isset($ibforums->input["t"])) { /* A user asked for only specified topics, get their ids from t input * variable and add them to the where clause */ preg_match_all("/(?<=,|^)([0-9]+)(?=,|$)/", $ibforums->input["t"], $in); foreach ($in[1] as $value) $_topics[] = $value; $whereClause = buildWhereClause($_topics, "topic_id=", "OR", $whereClause, "AND", true); } } $whereClause = finishWhereClause($whereClause); unset($allowed); unset($forbidden); return $whereClause; } /* Prepend WHERE to the string given as an argument */ function finishWhereClause($whereClause = null) { if (strlen($whereClause) > 0) return " WHERE ".$whereClause; } function buildWhereClause($data = null, $field_key = "", $delimiter = "AND", $where_clause = "", $delimiter_where_clause = "AND", $restrict = true) { $_where_clause = ""; if (is_array($data)) { foreach($data as $field_value) { $field_value = intval($field_value); if ($field_value) { if (strlen($_where_clause) > 0) $_where_clause .= " ".$delimiter." "; $_where_clause .= $field_key.$field_value; } } } /* If restrict is set, then empty data causes WHERE FALSE */ if ($restrict && strlen($_where_clause) == 0) $_where_clause = " FALSE "; if (strlen($_where_clause) > 0) { $_where_clause = "(" . $_where_clause . ")"; if (strlen($where_clause)) $where_clause .= " ".$delimiter_where_clause . " " . $_where_clause ; else $where_clause = $_where_clause; } return $where_clause; } function clean_post($post) { global $ibforums, $parser; $post = preg_replace( "#

(.+?)\[mergetime\][0-9]{10}\[/mergetime\]<\/b>#i", "", $post ); $post = preg_replace("#\[hide\](.+?)\[\/hide\]#ies", "hiden_block", $post); // replace quote tag if (CHANGE_STYLE){ $post = preg_replace( "#(.+?)#", "
:
", $post ); $post = preg_replace( "#(.+?)#", "
(\\1, \\2):
", $post ); $post = preg_replace( "##", "
(\\1):
", $post ); $post = preg_replace( "#(.+?)#", '
', $post ); } // replace hide tag if (method_exists($parser,'regex_hide_hidden')){ $post = $parser->regex_hide_hidden($post); if (CHANGE_STYLE){ $post = preg_replace( "#(.+?)#", "
:
", $post ); $post = preg_replace( "#(.+?)#", "
", $post ); } } // replace code tag if (CHANGE_STYLE){ $post = preg_replace( "#(.+?)#", "
:
", $post ); $post = preg_replace( "#(.+?)#", "
", $post ); } // remove comments (save traffic ;) $post = preg_replace( "##", '', $post ); // remove macros $post = preg_replace( "#<\{.+?\}>#", '', $post ); return $post; } function out_start(){ global $_page, $output; @header('Content-Type: text/xml'); @header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT'); @header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); @header('Pragma: public'); $output = $_page->build_header(); if (USE_BOARD_IMG) $output .= $_page->build_image(); } function out_finish(){ global $DB, $ibforums, $_page, $output; $output .= $_page->build_footer(); $DB->close_db(); die($output); } class page_builder { function page_builder(){ global $ibforums, $page_data; $page_data['board_title'] = $page_data['board_title']?$page_data['board_title']:$ibforums->vars['board_name']; $page_data['board_link'] = $page_data['board_link']?$page_data['board_url']:$ibforums->vars['board_url']."/"; $page_data['board_description'] = $page_data['board_description']?$page_data['board_title']:$ibforums->vars['board_name']; $page_data['img_link'] = $page_data['img_link']?$page_data['img_link']:$ibforums->vars['board_url']."/rss_icon.gif"; $page_data['img_width'] = intval($page_data['img_width']); $page_data['img_width'] = ($page_data['img_width'] && $page_data['img_width']<100)?$page_data['img_width']:100; $page_data['img_height'] = intval($page_data['img_height']); $page_data['img_height'] = ($page_data['img_height'] && $page_data['img_height']<50)?$page_data['img_height']:50; } function build_header(){ global $page_data; $template = USE_TEMPLATE?'':''; return << {$template} {$page_data['board_title']} {$page_data['board_link']} {$page_data['board_description']} vicers_rss ru {$page_data['last_build']} {$page_data['skin_images_path']} EOF; } function build_image() { global $page_data; return << {$page_data['board_title']} {$page_data['board_link']} {$page_data['img_link']} {$page_data['img_width']} {$page_data['img_height']} EOF; } function build_row($data) { return << {$data['forum_name']} / {$data['topic_name']} {$data['post_url']} {$data['author_name']} {$data['author_name']} пишет
: {$data['post_text']} ]]> {$data['forum_name']} {$data['post_rfc_date']} {$data['topic_url']} {$data['post_url']} {$data['post_date']} {$data['forum_name']} {$data['forum_url']} {$data['topic_name']} {$data['topic_url']} {$data['author_name']} {$data['author_url']} EOF; } function build_footer(){ return << EOF; } } ?>