|
From: Jon O. <jon...@us...> - 2007-07-22 21:17:42
|
Update of /cvsroot/mxbb/mx_ggsitemaps/includes In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv10068/includes Added Files: .htaccess common_GGsitemaps.php index.htm index_forum.php index_kb.php index_mx.php sitemap_forum.php sitemap_kb.php sitemap_mx.php Log Message: Added this module, for now, so i do not loose it --- NEW FILE: index_mx.php --- <?php /** * * @package mxBB Portal Module - mx_ggsitemaps * @version $Id: index_mx.php,v 1.1 2007/07/22 21:17:35 jonohlsson Exp $ * @copyright (c) 2002-2006 [www.phpbb-seo.com] mxBB Project Team * @license http://opensource.org/licenses/gpl-license.php GNU General Public License v2 * */ if ( !defined('IN_PHPBB') && !defined('IN_PORTAL') ) { die('Hacking attempt'); exit; } // Should be enough as a check if ( defined('IN_PORTAL') ) { //Output start if necessary if (!$started) { header("Content-type: text/xml"); $started = true; echo $I_header; } echo "\t" . '<sitemap>' . "\n"; echo "\t\t" . '<loc>' . ( ($Rewrite_sitemap) ? $root_url.'mx-sitemap.xml' : $root_url."sitemap.php?mx" ) . '</loc>' . "\n"; echo "\t" . '</sitemap>' . "\n"; } ?> --- NEW FILE: sitemap_mx.php --- <?php /** * * @package mxBB Portal Module - mx_ggsitemaps * @version $Id: sitemap_mx.php,v 1.1 2007/07/22 21:17:36 jonohlsson Exp $ * @copyright (c) 2002-2006 [www.phpbb-seo.com] mxBB Project Team * @license http://opensource.org/licenses/gpl-license.php GNU General Public License v2 * */ // // First basic security // if ( !defined('IN_PHPBB') && !defined('IN_PORTAL') ) { die('Hacking attempt'); exit; } // Let's start with checking what to do $mx_map = ( isset( $HTTP_GET_VARS['mx'] ) ) ? TRUE : FALSE; if ( $mx_map ) { // // First get all visible blocks // $sql = "SELECT block_id FROM " . BLOCK_TABLE . " WHERE show_block = 1"; if ( !$result = $db->sql_query( $sql ) ) { mx_message_die( GENERAL_ERROR, 'Could not obtain block results', '', __LINE__, __FILE__, $sql ); } $block_rowset = $db->sql_fetchrowset( $result ); $db->sql_freeresult($result); // // Get all pages with view access // /* $sql = "SELECT * FROM " . PAGE_TABLE . " ORDER BY page_id"; if ( !( $result = $db->sql_query( $sql ) ) ) { mx_message_die( GENERAL_ERROR, "Couldn't get list of page", "", __LINE__, __FILE__, $sql ); } $valid_page_ids_array = array(); while ( $page_row = $db->sql_fetchrow( $result )) { // // Page auth // $mx_page_temp = new mx_page(); $mx_page_temp->init($page_row['page_id']); if ( $mx_page_temp->auth_view ) { $valid_page_ids_array[] = $page_row['page_id']; } } $db->sql_freeresult($result); */ $valid_page_ids_array = array(); foreach( $mx_page->page_rowset as $temp_key => $page_row ) { $_auth_ary = $mx_page->auth($page_row['auth_view'], $page_row['auth_view_group'], $page_row['auth_moderator_group']); if ($_auth_ary['auth_view']) { $valid_page_ids_array[] = $page_row['page_id']; } } // // Now find the associated pages // $page_ids = array(); $block_ids = array(); $valid_page_ids = ''; foreach($block_rowset as $key => $block_row) { $page_id_array = get_page_id($block_row['block_id'], false, true); if (in_array($page_id_array['page_id'], $valid_page_ids_array)) { $page_ids[$block_row['block_id']] = $page_id_array; $block_ids[] = $block_row['block_id']; } } $valid_block_ids = implode( ', ', $block_ids ); // // Output start // header("Content-type: text/xml"); $started = true; echo $S_header; // Homepage location echo "\t" . '<url>' . "\n"; echo "\t\t" . '<loc>' . $root_url . '</loc>' . "\n"; //echo "\t\t" . '<lastmod>' . gmdate('Y-m-d\TH:i:s'.'+00:00', time() ) . '</lastmod>' . "\n"; echo "\t\t" . '<changefreq>always</changefreq>' . "\n"; echo "\t\t" . '<priority>1.0</priority>' . "\n"; echo "\t" . '</url>' . "\n"; // // Dump out the results // $pageids = array(); foreach($page_ids as $block_id => $page_row ) { if (is_array($page_row) && !empty($page_row['block_id'])) { $dynamic_block_id = $page_row['block_id']; $pageid = $page_row['page_id']; $priority = '0.8'; } else if (is_array($page_row)) { $dynamic_block_id = ''; $pageid = $page_row['page_id']; $priority = '1.0'; } else { $dynamic_block_id = ''; $pageid = $page_row; $priority = '1.0'; } // // Remove duplicate pages // if (empty($dynamic_block_id)) { if (in_array($pageid,$pageids) ) { continue; } else { $pageids[] = $pageid; } } $page_title = $page_row['page_name']; $page_desc = $page_row['page_desc']; $temp_url = !empty($dynamic_block_id) ? mx_append_sid( PORTAL_URL . 'index.php?page=' . $pageid . '&dynamic_block=' . $dynamic_block_id, false, true ) : mx_append_sid( PORTAL_URL . 'index.php?page=' . $pageid ); // // Built mx urls // echo "\t" . '<url>' . "\n"; echo "\t\t" . '<loc>' . $temp_url . '</loc>' . "\n"; //echo "\t\t" . '<lastmod>' . gmdate('Y-m-d\TH:i:s'.'+00:00', time() ) . '</lastmod>' . "\n"; echo "\t\t" . '<changefreq>always</changefreq>' . "\n"; echo "\t\t" . '<priority>'.$priority.'</priority>' . "\n"; echo "\t" . '</url>' . "\n"; } $db->sql_freeresult($result); unset($page_ids); unset($block_rowset); unset($page_row); // Dump the page since there's nothing left to do echo $S_footer; exit; } ?> --- NEW FILE: common_GGsitemaps.php --- <?php /** * * @package mxBB Portal Module - mx_ggsitemaps * @version $Id: common_GGsitemaps.php,v 1.1 2007/07/22 21:17:31 jonohlsson Exp $ * @copyright (c) 2002-2006 [www.phpbb-seo.com] mxBB Project Team * @license http://opensource.org/licenses/gpl-license.php GNU General Public License v2 * */ if ( !defined('IN_PHPBB') && !defined('IN_PORTAL') ) { die('Hacking attempt'); exit; } // // Define table names. // if (defined('IN_PORTAL')) { $table_prefix = $mx_table_prefix; } define('GGSITEMAP_TABLE', $table_prefix.'ggsitemap_config'); // message_die selector function mx_sitemaps_message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = '', $err_file = '', $sql = '') { global $phpbb; if ($phpbb) { message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = '', $err_file = '', $sql = ''); } else { mx_message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = '', $err_file = '', $sql = ''); } } // Basically the mxBB Portal mx_redirect function // Used to circumvent header already sent matters function mx_sitemaps_redirect($url) { global $db, $board_config; // // Save any possible changes made in session variables, otherwise we will loose them. // See comments here: // http://www.php.net/session // http://www.php.net/session_write_close // @session_write_close(); @session_start(); if ( !empty($db) ) { $db->sql_close(); } if ( strstr(urldecode($url), "\n") || strstr(urldecode($url), "\r") ) { message_die(GENERAL_ERROR, 'Tried to redirect to potentially insecure url.'); } // Redirect via an HTML form for PITA webservers if (@preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE'))) { header('Refresh: 0; URL=' . $url); echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><meta http-equiv="refresh" content="0; url=' . $url . '"><title>Redirect</title></head><body><div align="center">If your browser does not support meta redirection please click <a href="' . $url . '">HERE</a> to be redirected</div></body></html>'; exit; } // Behave as per HTTP/1.1 spec for others header("Status: 302 Found", false, 302); header('Location: ' . $root_url . $url); exit; } if (defined('IN_ADMIN')) { // // Load language files. // if( file_exists($module_root_path2 . 'language/lang_' . $board_config['default_lang'] . '/lang_google_sitemap.' . $phpEx) ) { include_once($module_root_path2 . 'language/lang_' . $board_config['default_lang'] . '/lang_google_sitemap.' . $phpEx); } else { include_once($module_root_path2 . 'language/lang_english/lang_google_sitemap.' . $phpEx); } // One small cosmetic function for easy compatibility with phpbb // Basically the phpbb make clickable function if (!function_exists('make_link')) { function make_link($text) { $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text); // pad it with a space so we can match things at the start of the 1st line. $ret = ' ' . $text; // matches an "xxxx://yyyy" URL at the start of a line, or after a space. // xxxx can only be alpha characters. // yyyy is anything up to the first space, newline, comma, double quote or < $ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret); // matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing // Must contain at least 2 dots. xxxx contains either alphanum, or "-" // zzzz is optional.. will contain everything up to the first space, newline, // comma, double quote or <. $ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret); // Remove our padding.. $ret = substr($ret, 1); return($ret); } } } ?> --- NEW FILE: .htaccess --- <Limit GET POST PUT> Order Allow,Deny Deny from All </Limit> --- NEW FILE: index_kb.php --- <?php /** * * @package mxBB Portal Module - mx_ggsitemaps * @version $Id: index_kb.php,v 1.1 2007/07/22 21:17:34 jonohlsson Exp $ * @copyright (c) 2002-2006 [www.phpbb-seo.com] mxBB Project Team * @license http://opensource.org/licenses/gpl-license.php GNU General Public License v2 * */ if ( !defined('IN_PHPBB') && !defined('IN_PORTAL') ) { die('Hacking attempt'); exit; } if ($is_index) { if ( ( defined('IN_PORTAL') ) && file_exists( $module_root_path . 'mx_kb/includes/functions_kb.php' ) ) { $kb_installed = TRUE; define( 'KB_CATEGORIES_TABLE', $mx_table_prefix . 'kb_categories' ); } elseif ( file_exists( $phpbb_root_path . 'includes/functions_kb.php' ) ) { $kb_installed = TRUE; define( 'KB_CATEGORIES_TABLE', $table_prefix . 'kb_categories' ); } if ( $kb_installed ) { // Grab necessary info // Here, some postgresql && oracle wizards are welcome to validate this switch // I just could not test it, and by the way am not a postgresql && oracle guru :-) switch(SQL_LAYER) { case 'postgresql': $sql = "SELECT c.*, p.post_time, p.post_username, u.username, u.user_id FROM " . KB_CATEGORIES_TABLE . " c, " . FORUMS_TABLE . " f, " . POSTS_TABLE . " p WHERE f.forum_id = c.comments_forum_id AND p.post_id = f.forum_last_post_id UNION ( SELECT c.*, NULL, NULL, NULL, NULL FROM " . KB_CATEGORIES_TABLE . " c WHERE NOT EXISTS ( SELECT p.post_time FROM " . POSTS_TABLE . " p WHERE p.post_id = f.forum_last_post_id ) ) ORDER BY forum_last_post_id " . $ggsitemap_config['sitemap_sort']; break; case 'oracle': $sql = "SELECT c.*, p.post_time, p.post_username, u.username, u.user_id FROM " . FORUMS_TABLE . " f, " . POSTS_TABLE . " p, " . USERS_TABLE . " u WHERE f.forum_id = c.comments_forum_id(+) AND p.post_id = f.forum_last_post_id(+) ORDER BY f.forum_last_post_id " . $ggsitemap_config['sitemap_sort']; break; default: $sql = "SELECT c.category_id, c.category_name, c.auth_view, f.forum_last_post_id, p.post_time FROM (( " . KB_CATEGORIES_TABLE . " c LEFT JOIN " . FORUMS_TABLE . " f ON f.forum_id = c.comments_forum_id ) LEFT JOIN " . POSTS_TABLE . " p ON p.post_id = f.forum_last_post_id ) ORDER BY f.forum_last_post_id " . $ggsitemap_config['sitemap_sort']; break; } if ( !($result = $db->sql_query($sql)) ) { $query_ok = FALSE; if (!$started) { mx_sitemaps_message_die(GENERAL_ERROR, "Could not obtain category data", '', __LINE__, __FILE__, $sql); } } // I do this here to handle sql errors the best possible if ( $query_ok ) { $kb_cats = $db->sql_fetchrowset( $result ); $db->sql_freeresult($result); //Output start if necessary if (!$started) { header("Content-type: text/xml"); $started = true; echo $I_header; } // KB cat loop $last_kb_comment = 0; for ($x = 0; $x < count($kb_cats); $x++) { // Only output sitemaps for public Cats with properly set non empty comment forum. if ( ($kb_cats[$x]['auth_view'] == '0') && ($kb_cats[$x]['forum_last_post_id']) ) { $kb_forum_id = $kb_cats[$x]['comments_forum_id']; $kb_last_mod_time = '<lastmod>' . gmdate('Y-m-d\TH:i:s'.'+00:00',$kb_cats[$x]['post_time']) . '</lastmod>'; // This get used for the kb cat sitemap $last_kb_comment = ( $kb_cats[$x]['post_time'] > $last_kb_comment ) ? $kb_cats[$x]['post_time'] : $last_kb_comment; // Either mod rewrite or not for sitemaps $kb_sitemap_url = ($Rewrite_sitemap) ? $root_url.'kb-sitemap-'.$kb_cats[$x]['category_id'].'.xml' : $root_url.'sitemap.'.$phpEx.'?kbid='.$kb_cats[$x]['category_id']; echo "\t" . '<sitemap>' . "\n"; echo "\t\t" . '<loc>' . $kb_sitemap_url . '</loc>' . "\n"; echo "\t\t" . $kb_last_mod_time . "\n"; echo "\t" . '</sitemap>' . "\n"; } } // Either mod rewrite or not for sitemaps $sitemap_kbcat_url = ($Rewrite_sitemap) ? $root_url.'sitemap-kbcat.xml' : $root_url.'sitemap.'.$phpEx.'?kbcat'; echo "\t" . '<sitemap>' . "\n"; echo "\t\t" . '<loc>' . $sitemap_kbcat_url . '</loc>' . "\n"; echo "\t\t" . '<lastmod>' . gmdate('Y-m-d\TH:i:s'.'+00:00', $last_ever ) . '</lastmod>' . "\n"; echo "\t" . '</sitemap>' . "\n"; unset ($kb_cats); } } } ?> --- NEW FILE: index_forum.php --- <?php /** * * @package mxBB Portal Module - mx_ggsitemaps * @version $Id: index_forum.php,v 1.1 2007/07/22 21:17:33 jonohlsson Exp $ * @copyright (c) 2002-2006 [www.phpbb-seo.com] mxBB Project Team * @license http://opensource.org/licenses/gpl-license.php GNU General Public License v2 * */ if ( !defined('IN_PHPBB') && !defined('IN_PORTAL') ) { die('Hacking attempt'); exit; } if ( $is_index ) { // Let's build the forum's sitemaps list, while grabbing info usefull for main mx sitemap too // Check the forum's last post date and grab all necessary infos // Define appropriate sql, The postgresql && oracle one are left as they are in the forum's index // Could get rid of user info here, like I did For default, but It works like this with not much harm so ... // postgresql && oracle coder welcome to opt thoses ;-) switch(SQL_LAYER) { case 'postgresql': $sql = "SELECT f.*, p.post_time, p.post_username, u.username, u.user_id FROM " . FORUMS_TABLE . " f, " . POSTS_TABLE . " p, " . USERS_TABLE . " u WHERE p.post_id = f.forum_last_post_id AND u.user_id = p.poster_id UNION ( SELECT f.*, NULL, NULL, NULL, NULL FROM " . FORUMS_TABLE . " f WHERE NOT EXISTS ( SELECT p.post_time FROM " . POSTS_TABLE . " p WHERE p.post_id = f.forum_last_post_id ) ) ORDER BY forum_last_post_id " . $ggsitemap_config['sitemap_sort']; break; case 'oracle': $sql = "SELECT f.*, p.post_time, p.post_username, u.username, u.user_id FROM " . FORUMS_TABLE . " f, " . POSTS_TABLE . " p, " . USERS_TABLE . " u WHERE p.post_id = f.forum_last_post_id(+) AND u.user_id = p.poster_id(+) ORDER BY f.forum_last_post_id " . $ggsitemap_config['sitemap_sort']; break; default: $sql = "SELECT f.*, p.post_time FROM ( " . FORUMS_TABLE . " f LEFT JOIN " . POSTS_TABLE . " p ON p.post_id = f.forum_last_post_id ) ORDER BY f.forum_last_post_id " . $ggsitemap_config['sitemap_sort']; break; } if ( !($result = $db->sql_query($sql)) ) { $query_ok = FALSE; if (!$started) { mx_sitemaps_message_die(GENERAL_ERROR, "Could not obtain Forum data", '', __LINE__, __FILE__, $sql); } } $forum_data = array(); while( $row = $db->sql_fetchrow($result) ) { $forum_data[] = $row; } $db->sql_freeresult($result); // Reset vars $forum_sitemap_urls = ''; $last_mod_time = ''; $last_mod = array(); $last_ever = 0; //Output start if necessary if (!$started) { header("Content-type: text/xml"); $started = true; echo $I_header; } if ( ($total_forums = count($forum_data)) && $query_ok) { // Forum maps loop for($j = 0; $j < $total_forums; $j++) { if ( ($forum_data[$j]['auth_view'] == '0') && ($forum_data[$j]['auth_read'] == '0') && ( $forum_data[$j]['forum_last_post_id'] ) ) { $forum_id = $forum_data[$j]['forum_id']; $last_mod_time = '<lastmod>' . gmdate('Y-m-d\TH:i:s'.'+00:00', $forum_data[$j]['post_time']) . '</lastmod>'; // This get used for sitemap forums $last_ever = ( $forum_data[$j]['post_time'] > $last_ever ) ? $forum_data[$j]['post_time'] : $last_ever; // Either mod rewrite or not for forum sitemaps $forum_sitemap_urls = ($Rewrite_sitemap) ? $root_url.'forum-sitemap-'.$forum_id.'.xml' : $root_url.'sitemap.'.$phpEx.'?fid='.$forum_id; echo "\t" . '<sitemap>' . "\n"; echo "\t\t" . '<loc>' . $forum_sitemap_urls . '</loc>' . "\n"; echo "\t\t" . $last_mod_time . "\n"; echo "\t" . '</sitemap>' . "\n"; } }// End Forum map loop //Forum maps locations // Either mod rewrite or not for sitemaps $sitemap_forums_url = ($Rewrite_sitemap) ? $root_url.'sitemap-forum.xml' : $root_url.'sitemap.'.$phpEx.'?forum'; echo "\t" . '<sitemap>' . "\n"; echo "\t\t" . '<loc>' . $sitemap_forums_url . '</loc>' . "\n"; echo "\t\t" . '<lastmod>' . gmdate('Y-m-d\TH:i:s'.'+00:00', $last_ever ) . '</lastmod>' . "\n"; echo "\t" . '</sitemap>' . "\n"; unset($forum_data); } } ?> --- NEW FILE: sitemap_forum.php --- <?php /** * * @package mxBB Portal Module - mx_ggsitemaps * @version $Id: sitemap_forum.php,v 1.1 2007/07/22 21:17:36 jonohlsson Exp $ * @copyright (c) 2002-2006 [www.phpbb-seo.com] mxBB Project Team * @license http://opensource.org/licenses/gpl-license.php GNU General Public License v2 * */ // First basic security if ( !defined('IN_PHPBB') && !defined('IN_PORTAL') ) { die('Hacking attempt'); exit; } // Let's start with checking what to do $forum_id = ( isset( $HTTP_GET_VARS['fid'] ) ) ? intval( $HTTP_GET_VARS['fid'] ) : FALSE; $forum_map = ( isset( $HTTP_GET_VARS['forum'] ) ) ? TRUE : FALSE; // Go for forum if that's what to do if ($forum_id) { // Check forum auth and grab necessary infos $sql = "SELECT f.*, p.post_time FROM ". FORUMS_TABLE ." AS f, " . POSTS_TABLE . " AS p WHERE f.forum_id = $forum_id AND p.post_id = f.forum_last_post_id"; if ( !($result = $db->sql_query($sql)) ) { mx_sitemaps_message_die(GENERAL_ERROR, "Could not obtain Forum data", '', __LINE__, __FILE__, $sql); } $forum_data = $db->sql_fetchrow($result); $db->sql_freeresult($result); if ( ( $forum_data['auth_view'] != '0' ) || ( $forum_data['auth_read'] != '0' ) ) { mx_sitemaps_message_die(GENERAL_MESSAGE, 'Invalid Sitemap'); } // This forum is allowed and has posts, so let's start $forum_id = $forum_data['forum_id']; // So let's go for max item per query if($ggsitemap_config['sitemap_sort'] == "ASC") { $order = "DESC"; } else { $order = "ASC"; } $sql = "SELECT topic_last_post_id FROM " . TOPICS_TABLE . " WHERE forum_id = $forum_id ORDER BY topic_last_post_id $order LIMIT 1"; if ( !($result = $db->sql_query($sql)) ) { mx_sitemaps_message_die(GENERAL_ERROR, 'Error getting topic information', '', __LINE__, __FILE__, $sql); } $result = $db->sql_fetchrow($result); $lastid = $result['topic_last_post_id']; $sql = "SELECT COUNT(topic_id) AS forum_topics FROM " . TOPICS_TABLE . " WHERE forum_id = $forum_id"; if ( !($result = $db->sql_query($sql)) ) { mx_sitemaps_message_die(GENERAL_ERROR, 'Could not obtain limited topics count information', '', __LINE__, __FILE__, $sql); } $row = $db->sql_fetchrow($result); $topics_count = ( $row['forum_topics'] ) ? $row['forum_topics'] : 1; $forum_url = 'viewforum.' . $phpEx . '?f=' . $forum_id; //Output start header("Content-type: text/xml"); $started = true; echo $S_header; echo "\t" . '<url>' . "\n"; echo "\t\t" . '<loc>' . $server_url . $forum_url . '</loc>' . "\n"; echo "\t\t" . '<lastmod>' . gmdate('Y-m-d\TH:i:s'.'+00:00', $forum_data['post_time']) . '</lastmod>' . "\n"; echo "\t\t" . '<changefreq>always</changefreq>' . "\n"; echo "\t\t" . '<priority>1.0</priority>' . "\n"; echo "\t" . '</url>' . "\n"; // Absolute limit $topic_sofar = 0; // topic limit per query $last_topic = 0; while( ( $lasttopic != $lastid ) && ( $topic_sofar < $topics_count ) && ($topic_sofar < $url_limit) ) { $result = ""; //Newest topics first if(is_numeric($lasttopic) && $ggsitemap_config['sitemap_sort'] == "ASC") { $lasttopic++; $wheresql = "AND t.topic_last_post_id >= $lasttopic"; } //Oldest topics first elseif(is_numeric($lasttopic)) { $lasttopic--; $wheresql = "AND t.topic_last_post_id <= $lasttopic"; } else { $wheresql = ""; } $sql = "SELECT t.topic_id, t.topic_type, t.topic_status, t.topic_replies, p.post_time FROM " . TOPICS_TABLE . " AS t, " . POSTS_TABLE . " AS p WHERE t.topic_last_post_id=p.post_id AND t.forum_id = $forum_id $wheresql ORDER BY t.topic_last_post_id " . $ggsitemap_config['sitemap_sort'] . " LIMIT $topic_sofar,$sql_limit"; if ( !($result = $db->sql_query($sql)) ) { $query_ok = FALSE; if (!$started) { mx_sitemaps_message_die(GENERAL_ERROR, "Could not obtain category data", '', __LINE__, __FILE__, $sql); } } // I do this here to handle sql errors the best possible if ( $query_ok ) { $topics = $db->sql_fetchrowset($result); $db->sql_freeresult($result); // Simple result limit used to separate query here too ;-) $topic_sofar = $topic_sofar + $sql_limit; for ($x = 0; $x < count($topics); $x++) { $topic = $topics[$x]; $topic_url = 'viewtopic.' . $phpEx . '?t=' . $topic['topic_id']; switch ($topic['topic_type']) { case 2: $topic_priority = $ggsitemap_config['sitemap_announce_priority']; break; case 1: $topic_priority = $ggsitemap_config['sitemap_sticky_priority']; break; default: $topic_priority = $ggsitemap_config['sitemap_default_priority']; } if ($topic['topic_status'] == 1) { $topic_change = "never"; } else { $topic_change = "always"; } $paginated = $board_config['posts_per_page']; if($topic['topic_replies'] > $paginated) { // Reset Pages limits for this topic $pag_limit1 = $ggsitemap_config['sitemap_limitdown']; $pag_limit2 = $ggsitemap_config['sitemap_limitup']; $pages = ceil($topic['topic_replies'] / $paginated); // If $pag_limit2 too big for this topic, lets output all pages $pag_limit2 = ( $pages < $pag_limit2 ) ? ($pages - 1) : $pag_limit2; $i=0; while ( ($i <= $pages) ) { if ( ( $i <= $pag_limit1 ) || ( $i > ($pages - $pag_limit2 ) ) ) { $start = ( $i == 0 ) ? '' : "&start=" . $paginated * $i; echo "\t" . '<url>' . "\n"; echo "\t\t" . '<loc>' . $server_url . $topic_url . $start . '</loc>' . "\n"; echo "\t\t" . '<lastmod>' . gmdate('Y-m-d\TH:i:s'.'+00:00', $topic['post_time']) . '</lastmod>' . "\n"; echo "\t\t" . '<changefreq>' . $topic_change . '</changefreq>' . "\n"; echo "\t\t" . '<priority>' . $topic_priority . '</priority>' . "\n"; echo "\t" . '</url>' . "\n"; $i++; $topic_sofar++; } else { $i++; $topic_sofar++; } } } else { echo "\t" . '<url>' . "\n"; echo "\t\t" . '<loc>' . $server_url . $topic_url . '</loc>' . "\n"; echo "\t\t" . '<lastmod>' . gmdate('Y-m-d\TH:i:s'.'+00:00', $topic['post_time']) . '</lastmod>' . "\n"; echo "\t\t" . '<changefreq>' . $topic_change . '</changefreq>' . "\n"; echo "\t\t" . '<priority>' . $topic_priority . '</priority>' . "\n"; echo "\t" . '</url>' . "\n"; } $lasttopic = $topic['topic_last_post_id']; }// End topic loop unset($topics); unset($topic); } }// End Query limit loop // Dump the page since there's nothing left to do echo $S_footer; exit; } // End Forum sitemaps elseif ($forum_map) { // Check the forum's last post date and grab all necessary infos // Define appropriate sql, The postgresql && oracle one are left as they are in the forum's index // Could get rid of user info here, like I did For default, but It works like this with not much arm so ... // postgresql && oracle coder welcome to opt thoses here too ;-) switch(SQL_LAYER) { case 'postgresql': $sql = "SELECT f.*, p.post_time, p.post_username, u.username, u.user_id FROM " . FORUMS_TABLE . " f, " . POSTS_TABLE . " p, " . USERS_TABLE . " u WHERE p.post_id = f.forum_last_post_id AND u.user_id = p.poster_id UNION ( SELECT f.*, NULL, NULL, NULL, NULL FROM " . FORUMS_TABLE . " f WHERE NOT EXISTS ( SELECT p.post_time FROM " . POSTS_TABLE . " p WHERE p.post_id = f.forum_last_post_id ) ) ORDER BY forum_last_post_id " . $ggsitemap_config['sitemap_sort']; break; case 'oracle': $sql = "SELECT f.*, p.post_time, p.post_username, u.username, u.user_id FROM " . FORUMS_TABLE . " f, " . POSTS_TABLE . " p, " . USERS_TABLE . " u WHERE p.post_id = f.forum_last_post_id(+) AND u.user_id = p.poster_id(+) ORDER BY f.forum_last_post_id " . $ggsitemap_config['sitemap_sort']; break; default: $sql = "SELECT f.*, p.post_time FROM ( " . FORUMS_TABLE . " f LEFT JOIN " . POSTS_TABLE . " p ON p.post_id = f.forum_last_post_id ) ORDER BY f.forum_last_post_id " . $ggsitemap_config['sitemap_sort']; break; } if ( !($result = $db->sql_query($sql)) ) { mx_sitemaps_message_die(GENERAL_ERROR, 'Could not query forums information', '', __LINE__, __FILE__, $sql); } $forum_datas = array(); while( $row = $db->sql_fetchrow($result) ) { $forum_datas[] = $row; } $db->sql_freeresult($result); //Output start header("Content-type: text/xml"); $started = true; echo $S_header; // Forums loop $last_ever = 0; if ($total_forums = count($forum_datas)) { for($j = 0; $j < $total_forums; $j++) { if ( ($forum_datas[$j]['auth_view'] == '0') && ($forum_datas[$j]['auth_read'] == '0') ) { $forum_id = $forum_datas[$j]['forum_id']; $last_mod_time = ( $forum_datas[$j]['forum_last_post_id'] ) ? '<lastmod>' . gmdate('Y-m-d\TH:i:s'.'+00:00', $forum_datas[$j]['post_time']) . '</lastmod>': ''; // This get used for the Forum index location $last_ever = ( $forum_datas[$j]['post_time'] > $last_ever ) ? $forum_datas[$j]['post_time'] : $last_ever; $forum_urls = $server_url . 'viewforum.' . $phpEx . '?f=' . $forum_id; echo "\t" . '<url>' . "\n"; echo "\t\t" . '<loc>' . $forum_urls . '</loc>' . "\n"; echo "\t\t" . $last_mod_time . "\n"; echo "\t\t" . '<changefreq>always</changefreq>' . "\n"; echo "\t\t" . '<priority>1.0</priority>' . "\n"; echo "\t" . '</url>' . "\n"; } } }// End Forum map loop // Forum index location echo "\t" . '<url>' . "\n"; echo "\t\t" . '<loc>' . $server_url . "index." . $phpEx . '</loc>' . "\n"; echo "\t\t" . '<lastmod>' . gmdate('Y-m-d\TH:i:s'.'+00:00', $last_ever ) . '</lastmod>' . "\n"; echo "\t\t" . '<changefreq>always</changefreq>' . "\n"; echo "\t\t" . '<priority>1.0</priority>' . "\n"; echo "\t" . '</url>' . "\n"; unset ($forum_datas); // Dump the page since there's nothing left to do echo $S_footer; exit; } // End sitemap forums ?> --- NEW FILE: index.htm --- <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF" text="#000000"> </body> </html> --- NEW FILE: sitemap_kb.php --- <?php /** * * @package mxBB Portal Module - mx_ggsitemaps * @version $Id: sitemap_kb.php,v 1.1 2007/07/22 21:17:36 jonohlsson Exp $ * @copyright (c) 2002-2006 [www.phpbb-seo.com] mxBB Project Team * @license http://opensource.org/licenses/gpl-license.php GNU General Public License v2 * */ if ( !defined('IN_PHPBB') && !defined('IN_PORTAL') ) { die('Hacking attempt'); exit; } // Check if installed and how if ( ( defined('IN_PORTAL') ) && file_exists( $module_root_path . 'mx_kb/includes/functions_kb.php' ) ) { $kb_installed = TRUE; define( 'KB_CATEGORIES_TABLE', $mx_table_prefix . 'kb_categories' ); define( 'KB_ARTICLES_TABLE', $mx_table_prefix . 'kb_articles' ); // Then set kb's page ID $page_id = $ggsitemap_config['sitemap_kb_mx_page']; // Built KB url $kb_page_url = 'index.'.$phpEx.'?page='.$page_id; } elseif ( file_exists( $phpbb_root_path . 'includes/functions_kb.php' ) ) { $kb_installed = TRUE; define( 'KB_CATEGORIES_TABLE', $table_prefix . 'kb_categories' ); define( 'KB_ARTICLES_TABLE', $table_prefix . 'kb_articles' ); $kb_page_url = 'kb.' . $phpEx; } // Let's start with checking what to do $kb_cat_id = ( isset( $HTTP_GET_VARS['kbid'] ) ) ? intval( $HTTP_GET_VARS['kbid'] ) : FALSE; $kb_cat_map = ( isset( $HTTP_GET_VARS['kbcat'] ) ) ? TRUE : FALSE; // Asking for a kb cat sitemap ? if ($kb_cat_id) { if ( $kb_installed ) { // check for kb cat auth and grab necessary datas $sql = "SELECT c.category_id, c.category_name, c.auth_view, p.post_time FROM ".KB_CATEGORIES_TABLE." AS c, " . FORUMS_TABLE . " AS f, " . POSTS_TABLE . " AS p WHERE category_id = $kb_cat_id AND f.forum_id = c.comments_forum_id AND p.post_id = f.forum_last_post_id"; if ( !($result = $db->sql_query($sql)) ) { mx_sitemaps_message_die(GENERAL_ERROR, "Could not obtain category data", '', __LINE__, __FILE__, $sql); } $kb_cats = $db->sql_fetchrow( $result ); $db->sql_freeresult($result); if ( $kb_cats['auth_view'] != '0' ) { mx_sitemaps_message_die(GENERAL_MESSAGE, 'Invalid Sitemap'); } // This cat is allowed, and has comment forum properly set so let's start $kb_cat_id = $kb_cats['category_id']; // So let's go for max item per query if($ggsitemap_config['sitemap_sort'] == "ASC") { $order = "DESC"; } else { $order = "ASC"; } $sql = "SELECT a.article_id, a.topic_id, t.topic_id, t.topic_last_post_id FROM " . KB_ARTICLES_TABLE . " AS a, " . TOPICS_TABLE . " AS t WHERE article_category_id = $kb_cat_id AND t.topic_id = a.topic_id ORDER BY t.topic_last_post_id $order LIMIT 1"; if ( !($result = $db->sql_query($sql)) ) { mx_sitemaps_message_die(GENERAL_ERROR, 'Error getting topic information', '', __LINE__, __FILE__, $sql); } $result = $db->sql_fetchrow($result); $last_kb_id = $result['topic_last_post_id']; $sql = "SELECT COUNT(article_id) AS cat_articles FROM " . KB_ARTICLES_TABLE . " WHERE article_category_id = $kb_cat_id"; if ( !($result = $db->sql_query($sql)) ) { mx_sitemaps_message_die(GENERAL_ERROR, 'Could not obtain limited topics count information', '', __LINE__, __FILE__, $sql); } $row = $db->sql_fetchrowset($result); $db->sql_freeresult($result); $article_count = ( $row['cat_articles'] ) ? $row['cat_articles'] : 1; //Output start header("Content-type: text/xml"); $started = true; echo $S_header; echo "\t" . '<url>' . "\n"; echo "\t\t" . '<loc>' . $root_url . $kb_page_url . '&mode=cat&cat=' . $kb_cat_id . '</loc>' . "\n"; echo "\t\t" . '<lastmod>' . gmdate('Y-m-d\TH:i:s'.'+00:00', $kb_cats['post_time'] ) . '</lastmod>' . "\n"; echo "\t\t" . '<changefreq>always</changefreq>' . "\n"; echo "\t\t" . '<priority>1.0</priority>' . "\n"; echo "\t" . '</url>' . "\n"; // Absolute limit $article_sofar = 0; // topic limit per query $last_article = 0; while( ( $last_kb_art != $last_kb_id ) && ( $article_sofar < $article_count ) && ($article_sofar < $url_limit) ) { //Newest articles first if(is_numeric($last_kb_art) && $ggsitemap_config['sitemap_sort'] == "ASC") { $last_kb_art++; $wheresql = "AND t.topic_last_post_id >= $last_kb_art"; } //Oldest articles first elseif(is_numeric($last_kb_art)) { $last_kb_art--; $wheresql = "AND t.topic_last_post_id <= $last_kb_art"; } else { $wheresql = ""; } // Select only approved articles $sql = "SELECT a.article_id, a.article_category_id, a.article_title, a.article_date, a.approved, a.topic_id, p.post_time FROM " . KB_ARTICLES_TABLE . " AS a, " . TOPICS_TABLE . " AS t, " . POSTS_TABLE . " AS p WHERE a.article_category_id = $kb_cat_id $wheresql AND a.approved = 1 AND t.topic_id = a.topic_id AND p.post_id = t.topic_last_post_id ORDER BY t.topic_last_post_id " . $ggsitemap_config['sitemap_sort'] . " LIMIT $article_sofar,$sql_limit"; if ( !( $article_result = $db->sql_query( $sql ) ) ) { $query_ok = FALSE; if (!$started) { mx_sitemaps_message_die(GENERAL_ERROR, "Could not obtain category data", '', __LINE__, __FILE__, $sql); } } // I do this here to handle sql errors the best possible if ( $query_ok ) { $kb_articles = $db->sql_fetchrowset($article_result); $db->sql_freeresult($article_result); // Simple result limit used to separate query here too ;-) $article_sofar = $topic_sofar + $sql_limit; for ($x = 0; $x < count($kb_articles); $x++) { $kb_article = $kb_articles[$x]; echo "\t" . '<url>' . "\n"; echo "\t\t" . '<loc>' . $root_url . $kb_page_url . '&mode=article&k=' . $kb_article['article_id'] . '</loc>' . "\n"; echo "\t\t" . '<lastmod>' . gmdate('Y-m-d\TH:i:s'.'+00:00', $kb_article['post_time'] ) . '</lastmod>' . "\n"; echo "\t\t" . '<changefreq>always</changefreq>' . "\n"; echo "\t\t" . '<priority>1.0</priority>' . "\n"; echo "\t" . '</url>' . "\n"; $last_kb_art = $kb_article['article_id']; }// End article loop unset ($kb_cats); unset ($kb_articles); } }// End Query limit loop // Dump the page since there's nothing left to do echo $S_footer; exit; } } // Why not a kb cat sitemap if asked for elseif ($kb_cat_map) { if ( KB_INSTALLED ) { // Here, some postgresql && oracle wizards are welcome to validate this switch // I just could not test it, and by the way am not a postgresql && oracle guru :-) switch(SQL_LAYER) { case 'postgresql': $sql = "SELECT c.*, p.post_time, p.post_username, u.username, u.user_id FROM " . KB_CATEGORIES_TABLE . " c, " . FORUMS_TABLE . " f, " . POSTS_TABLE . " p WHERE f.forum_id = c.comments_forum_id AND p.post_id = f.forum_last_post_id UNION ( SELECT c.*, NULL, NULL, NULL, NULL FROM " . KB_CATEGORIES_TABLE . " c WHERE NOT EXISTS ( SELECT p.post_time FROM " . POSTS_TABLE . " p WHERE p.post_id = f.forum_last_post_id ) ) ORDER BY forum_last_post_id " . $ggsitemap_config['sitemap_sort']; break; case 'oracle': $sql = "SELECT c.*, p.post_time, p.post_username, u.username, u.user_id FROM " . FORUMS_TABLE . " f, " . POSTS_TABLE . " p, " . USERS_TABLE . " u WHERE f.forum_id = c.comments_forum_id(+) AND p.post_id = f.forum_last_post_id(+) ORDER BY f.forum_last_post_id " . $ggsitemap_config['sitemap_sort']; break; default: $sql = "SELECT c.category_id, c.category_name, c.auth_view, p.post_time, f.forum_last_post_id FROM (( " . KB_CATEGORIES_TABLE . " c LEFT JOIN " . FORUMS_TABLE . " f ON f.forum_id = c.comments_forum_id ) LEFT JOIN " . POSTS_TABLE . " p ON p.post_id = f.forum_last_post_id ) ORDER BY f.forum_last_post_id " . $ggsitemap_config['sitemap_sort']; break; } if ( !($result = $db->sql_query($sql)) ) { mx_sitemaps_message_die(GENERAL_ERROR, "Could not obtain category data", '', __LINE__, __FILE__, $sql); } $kb_cats = $db->sql_fetchrowset( $result ); $db->sql_freeresult($result); //Output start header("Content-type: text/xml"); $started = true; echo $S_header; // Cat loop $last_kb_comment = 0; for ($x = 0; $x < count($kb_cats); $x++) { if ( ($kb_cats[$x]['auth_view'] == '0') ) { $kb_last_mod_time = ( $kb_cats[$x]['forum_last_post_id'] ) ? '<lastmod>' . gmdate('Y-m-d\TH:i:s'.'+00:00', $kb_cats[$x]['post_time']) . '</lastmod>': ''; $last_kb_comment = ( $kb_cats[$x]['post_time'] > $last_ever ) ? $kb_cats[$x]['post_time'] : $last_ever; echo "\t" . '<url>' . "\n"; echo "\t\t" . '<loc>' . $root_url . $kb_page_url . '&mode=cat&cat=' . $kb_cats[$x]['category_id'] . '</loc>' . "\n"; echo "\t\t" . $kb_last_mod_time . "\n"; echo "\t\t" . '<changefreq>always</changefreq>' . "\n"; echo "\t\t" . '<priority>1.0</priority>' . "\n"; echo "\t" . '</url>' . "\n"; } } // KB index location echo "\t" . '<url>' . "\n"; echo "\t\t" . '<loc>' . $root_url . $kb_page_url . '</loc>' . "\n"; echo "\t\t" . '<lastmod>' . gmdate('Y-m-d\TH:i:s'.'+00:00', $last_kb_comment ) . '</lastmod>' . "\n"; echo "\t\t" . '<changefreq>always</changefreq>' . "\n"; echo "\t\t" . '<priority>1.0</priority>' . "\n"; echo "\t" . '</url>' . "\n"; unset ($kb_cats); // Dump the page since there's nothing left to do echo $S_footer; exit; } else { mx_sitemaps_message_die(GENERAL_MESSAGE, 'Invalid sitemap kb cat'); } } ?> |