<?php

/********************************************************************************
	- MemHT Portal -
	
	Copyright (C) 2007-2008 by Miltenovik Manojlo
	http://www.memht.com
	
	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your opinion) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License along
	with this program; if not, see <http://www.gnu.org/licenses/> (GPLv2)
	or write to the Free Software Foundation, Inc., 51 Franklin Street,
	Fifth Floor, Boston, MA02110-1301, USA.
		
********************************************************************************/

if (stristr(htmlentities($_SERVER['PHP_SELF']), "inc_modrewrite.php")) {
	die("<table style='padding: 2px; border: 1px solid #999; background-color: #EEE; font-family: Verdana; font-size: 10px;' align='center'><tr><td><b>Error:</b> This file cannot be opened directly!</td></tr></table>");
}

function replace_for_mod_rewrite($s) {
	global $siteConfig;
	
	if (memRunHooks('ModRewriteReplace',array(&$s))) {
		$burlin = array(
			"`href=(['|\"|#])index\.php`is",
			"`href=(['|\"|#])rss\.php`is",
			"`href=(['|\"|#])sitemap\.php`is",
			"`href=(['|\"|#])pages\/([^/]+)\/pdf\.php`is"
		);
		$burlout = array(
			"href=\\1".$siteConfig['site_url']."/index.php",
			"href=\\1".$siteConfig['site_url']."/rss.php",
			"href=\\1".$siteConfig['site_url']."/sitemap.php",
			"href=\\1".$siteConfig['site_url']."/pages/$2/pdf.php"
		);
		$s = preg_replace($burlin,$burlout, $s); //index.php,rss.php,sitemap.php,pdf.php
		
		$urlin = array(
			//Home
			"`".$siteConfig['site_url']."/index\.php(['|\"|#])`is",
			//Archive
			"`".$siteConfig['site_url']."/index\.php\?page=archive(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=archive&(amp;)*arg=([^&#'\"-]+)&(amp;)*year=([0-9]+)&(amp;)*month=([0-9]+)(['|\"|#])`is",
			//Articles
			"`".$siteConfig['site_url']."/index\.php\?page=articles(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=articles&(amp;)*op=arg&(amp;)*id=([0-9]+)&(amp;)*title=([^&#'\"_]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=articles&(amp;)*op=readArticle&(amp;)*id=([0-9]+)&(amp;)*title=([^&#'\"_]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=articles&(amp;)*op=readArticle&(amp;)*id=([0-9]+)&(amp;)*title=([^&#'\"_]+)&(amp;)*pg=([0-9]+)(['|\"|#])`is",
			//Blog
			"`".$siteConfig['site_url']."/index\.php\?page=blog(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=blog&(amp;)*pg=([0-9]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=blog&(amp;)*op=categories(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=blog&(amp;)*year=([0-9]+)&(amp;)*month=([0-9]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=blog&(amp;)*year=([0-9]+)&(amp;)*month=([0-9]+)&(amp;)*pg=([0-9]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=blog&(amp;)*id=([0-9]+)&(amp;)*title=([^&#'\"_]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=blog&(amp;)*cid=([0-9]+)&(amp;)*category=([^&#'\"_]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=blog&(amp;)*cid=([0-9]+)&(amp;)*category=([^&#'\"_]+)&(amp;)*pg=([0-9]+)(['|\"|#])`is",
			//Contact
			"`".$siteConfig['site_url']."/index\.php\?page=contact(['|\"|#])`is",
			//Download
			"`".$siteConfig['site_url']."/index\.php\?page=download(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=download&(amp;)*op=category&(amp;)*id=([0-9]+)&(amp;)*title=([^&#'\"_]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=download&(amp;)*op=category&(amp;)*id=([0-9]+)&(amp;)*title=([^&#'\"_]+)&(amp;)*pg=([0-9]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=download&(amp;)*op=getFile&(amp;)*id=([0-9]+)&(amp;)*title=([^&#'\"_]+)(['|\"|#])`is",
			//Faq
			"`".$siteConfig['site_url']."/index\.php\?page=faq(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=faq&(amp;)*op=arg&(amp;)*id=([0-9]+)&(amp;)*title=([^&#'\"_]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=faq&(amp;)*op=arg&(amp;)*id=([0-9]+)&(amp;)*title=([^&#'\"_]+)&(amp;)*pg=([0-9]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=faq&(amp;)*op=read&(amp;)*id=([0-9]+)(['|\"|#])`is",
			//Forum
			"`".$siteConfig['site_url']."/index\.php\?page=forum(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=forum&(amp;)*op=viewCategory&(amp;)*id=([0-9]+)&(amp;)*title=([^&#'\"_]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=forum&(amp;)*op=viewForum&(amp;)*id=([0-9]+)&(amp;)*title=([^&#'\"_]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=forum&(amp;)*op=viewForum&(amp;)*id=([0-9]+)&(amp;)*title=([^&#'\"_]+)&(amp;)*pg=([0-9]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=forum&(amp;)*op=viewThread&(amp;)*id=([0-9]+)&(amp;)*title=([^&#'\"_]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=forum&(amp;)*op=viewThread&(amp;)*id=([0-9]+)&(amp;)*title=([^&#'\"_]+)&(amp;)*pg=([0-9]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=forum&(amp;)*op=newThread&(amp;)*id=([0-9]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=forum&(amp;)*op=reply&(amp;)*id=([0-9]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=forum&(amp;)*op=reply&(amp;)*id=([0-9]+)&(amp;)*quote=([0-9]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=forum&(amp;)*op=editPost&(amp;)*id=([0-9]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=forum&(amp;)*op=deletePost&(amp;)*id=([0-9]+)(['|\"|#])`is",
			//Gallery
			"`".$siteConfig['site_url']."/index\.php\?page=gallery(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=gallery&(amp;)*op=showGallery&(amp;)*id=([0-9]+)&(amp;)*title=([^&#'\"_]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=gallery&(amp;)*op=showGallery&(amp;)*id=([0-9]+)&(amp;)*title=([^&#'\"_]+)&(amp;)*pg=([0-9]+)(['|\"|#])`is",		
			//Guide
			"`".$siteConfig['site_url']."/index\.php\?page=guide(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=guide&(amp;)*op=arg&(amp;)*id=([0-9]+)&(amp;)*title=([^&#'\"_]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=guide&(amp;)*op=arg&(amp;)*id=([0-9]+)&(amp;)*title=([^&#'\"_]+)&(amp;)*pg=([0-9]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=guide&(amp;)*op=readGuide&(amp;)*id=([0-9]+)&(amp;)*title=([^&#'\"_]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=guide&(amp;)*op=readGuide&(amp;)*id=([0-9]+)&(amp;)*title=([^&#'\"_]+)&(amp;)*pg=([0-9]+)(['|\"|#])`is",
			//MyLinks
			"`".$siteConfig['site_url']."/index\.php\?page=mylinks(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=mylinks&(amp;)*op=showCategory&(amp;)*id=([0-9]+)&(amp;)*title=([^&#'\"_]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=mylinks&(amp;)*op=showCategory&(amp;)*id=([0-9]+)&(amp;)*title=([^&#'\"_]+)&(amp;)*pg=([0-9]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=mylinks&(amp;)*op=addLink&(amp;)*id=([0-9]+)(['|\"|#])`is",
			//MyPage
			"`".$siteConfig['site_url']."/index\.php\?page=mypage(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=mypage&(amp;)*op=openPage&(amp;)*id=([0-9]+)&(amp;)*title=([^&#'\"_]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=mypage&(amp;)*op=openPage&(amp;)*id=([0-9]+)&(amp;)*title=([^&#'\"_]+)&(amp;)*pg=([0-9]+)(['|\"|#])`is",
			//News
			"`".$siteConfig['site_url']."/index\.php\?page=news(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=news&(amp;)*pg=([0-9]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=news&(amp;)*op=readNews&(amp;)*id=([0-9]+)&(amp;)*title=([^&#'\"_]+)(['|\"|#])`is",
			//Newsletter
			"`".$siteConfig['site_url']."/index\.php\?page=newsletter(['|\"|#])`is",
			//Partners
			"`".$siteConfig['site_url']."/index\.php\?page=partners(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=partners&(amp;)*op=openPartnerLink&(amp;)*id=([0-9]+)(['|\"|#])`is",
			//Pdf
			"`".$siteConfig['site_url']."/pages\/([^/]+)\/pdf\.php\?id=([0-9]+)(['|\"|#])`is",
			//Pvt Messages
			"`".$siteConfig['site_url']."/index\.php\?page=pvtmsg(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=pvtmsg&(amp;)*pg=([0-9]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=pvtmsg&(amp;)*op=viewMessage&(amp;)*id=([0-9]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=pvtmsg&(amp;)*op=newMessage(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=pvtmsg&(amp;)*op=newMessage&(amp;)*recipient=([0-9]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=pvtmsg&(amp;)*op=reply&(amp;)*id=([0-9]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=pvtmsg&(amp;)*op=delete&(amp;)*id=([0-9]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=pvtmsg&(amp;)*op=delete&(amp;)*id=([0-9]+)&(amp;)*ok=true(['|\"|#])`is",
			//RSS
			"`".$siteConfig['site_url']."/index\.php\?page=rss(['|\"|#])`is",
			"`".$siteConfig['site_url']."/rss\.php\?page=([^&#'\"_]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/rss\.php\?page=([^&#'\"_]+)&(amp;)*(cat|topic)=([0-9]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/rss\.php\?page=([^&#'\"_]+)&(amp;)*(cat|topic)=([0-9]+)&(amp;)*items=([0-9]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/rss\.php\?page=forum&(amp;)*forum=([0-9]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/sitemap\.php(['|\"|#])`is",
			//Search
			"`".$siteConfig['site_url']."/index\.php\?page=search(['|\"|#])`is",
			//Send File
			"`".$siteConfig['site_url']."/index\.php\?page=sendfile(['|\"|#])`is",
			//Send News
			"`".$siteConfig['site_url']."/index\.php\?page=sendnews(['|\"|#])`is",
			//SiteMap
			"`".$siteConfig['site_url']."/index\.php\?page=sitemap(['|\"|#])`is",
			//Staff
			"`".$siteConfig['site_url']."/index\.php\?page=staff(['|\"|#])`is",
			//Surveys
			"`".$siteConfig['site_url']."/index\.php\?page=surveys(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=surveys&(amp;)*op=result&(amp;)*id=([0-9]+)(['|\"|#])`is",
			//Tags
			"`".$siteConfig['site_url']."/index\.php\?page=tags(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=tags&(amp;)*op=list&(amp;)*tag=([^&#'\"_]+)(['|\"|#])`is",		
			//Topics
			"`".$siteConfig['site_url']."/index\.php\?page=topics(['|\"|#])`is",
			//Users
			"`".$siteConfig['site_url']."/index\.php\?page=users(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=users&(amp;)*op=editProfile(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=users&(amp;)*logout=1(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=users&(amp;)*op=register(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=users&(amp;)*op=lostPassword(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=users&(amp;)*op=userInfo&(amp;)*uid=([0-9]+)(['|\"|#])`is",
			"`".$siteConfig['site_url']."/index\.php\?page=users&(amp;)*op=userInfo&(amp;)*usert=([^&#'\"_]+)(['|\"|#])`is"
		);
		$urlout = array(
			//Home
			$siteConfig['site_url']."/index.html\\1",
			//Archive
			$siteConfig['site_url']."/archive.html\\1",
			$siteConfig['site_url']."/archive_\\2_\\4_\\6.html\\7",
			//Articles
			$siteConfig['site_url']."/articles.html\\1",
			$siteConfig['site_url']."/articles_argument_\\3_\\5.html\\6",
			$siteConfig['site_url']."/articles_\\3_\\5.html\\6",
			$siteConfig['site_url']."/articles_\\3_\\5_\\7.html\\8",
			//Blog
			$siteConfig['site_url']."/blog.html\\1",
			$siteConfig['site_url']."/blog_\\2.html\\3",
			$siteConfig['site_url']."/blog_categories.html\\2",
			$siteConfig['site_url']."/blog_archive_\\2_\\4.html\\5",
			$siteConfig['site_url']."/blog_archive_\\2_\\4_\\6.html\\7",
			$siteConfig['site_url']."/blog_view_\\2_\\4.html\\5",
			$siteConfig['site_url']."/blog_category_\\2_\\4.html\\5",
			$siteConfig['site_url']."/blog_category_\\2_\\4_\\6.html\\7",
			//Contact
			$siteConfig['site_url']."/contact.html\\1",
			//Download
			$siteConfig['site_url']."/download.html\\1",
			$siteConfig['site_url']."/download_\\3_\\5.html\\6",
			$siteConfig['site_url']."/download_\\3_\\5_\\7.html\\8",
			$siteConfig['site_url']."/download_file_\\3_\\5.html\\6",
			//Faq
			$siteConfig['site_url']."/faq.html\\1",
			$siteConfig['site_url']."/faq_\\3_\\5.html\\6",
			$siteConfig['site_url']."/faq_\\3_\\5_\\7.html\\8",
			$siteConfig['site_url']."/faq_\\3.html\\4",
			//Forum
			$siteConfig['site_url']."/forum.html\\1",
			$siteConfig['site_url']."/forum_category_\\3_\\5.html\\6",
			$siteConfig['site_url']."/forum_list_\\3_\\5.html\\6",
			$siteConfig['site_url']."/forum_list_\\3_\\5_\\7.html\\8",
			$siteConfig['site_url']."/forum_thread_\\3_\\5.html\\6",
			$siteConfig['site_url']."/forum_thread_\\3_\\5_\\7.html\\8",
			$siteConfig['site_url']."/forum_newthread_\\3.html\\4",
			$siteConfig['site_url']."/forum_reply_\\3.html\\4",
			$siteConfig['site_url']."/forum_quote_\\3_\\5.html\\6",
			$siteConfig['site_url']."/forum_edit_\\3.html\\4",
			$siteConfig['site_url']."/forum_delete_\\3.html\\4",
			//Gallery
			$siteConfig['site_url']."/gallery.html\\1",
			$siteConfig['site_url']."/gallery_\\3_\\5.html\\6",
			$siteConfig['site_url']."/gallery_\\3_\\5_\\7.html\\8",
			//Guide
			$siteConfig['site_url']."/guide.html\\1",
			$siteConfig['site_url']."/guide_argument_\\3_\\5.html\\6",
			$siteConfig['site_url']."/guide_argument_\\3_\\5_\\7.html\\8",
			$siteConfig['site_url']."/guide_\\3_\\5.html\\6",
			$siteConfig['site_url']."/guide_\\3_\\5_\\7.html\\8",
			//MyLinks
			$siteConfig['site_url']."/mylinks.html\\1",
			$siteConfig['site_url']."/mylinks_\\3_\\5.html\\6",
			$siteConfig['site_url']."/mylinks_\\3_\\5_\\7.html\\8",
			$siteConfig['site_url']."/mylinks_add_\\3.html\\4",
			//MyPage
			$siteConfig['site_url']."/mypage.html\\1",
			$siteConfig['site_url']."/mypage_\\3_\\5.html\\6",
			$siteConfig['site_url']."/mypage_\\3_\\5_\\7.html\\8",
			//News
			$siteConfig['site_url']."/news.html\\1",
			$siteConfig['site_url']."/news_pg_\\2.html\\3",
			$siteConfig['site_url']."/news_\\3_\\5.html\\6",
			//Newsletter
			$siteConfig['site_url']."/newsletter.html\\1",
			//Partners
			$siteConfig['site_url']."/partners.html\\1",
			$siteConfig['site_url']."/partners_\\3.html\\4",
			//Pdf
			$siteConfig['site_url']."/pdf_\\1_\\2.pdf\\3",
			//Pvt Messages
			$siteConfig['site_url']."/pvtmsg.html\\1",
			$siteConfig['site_url']."/pvtmsg_\\2.html\\3",
			$siteConfig['site_url']."/pvtmsg_view_\\3.html\\4",
			$siteConfig['site_url']."/pvtmsg_new.html\\2",
			$siteConfig['site_url']."/pvtmsg_new_\\4.html\\5",
			$siteConfig['site_url']."/pvtmsg_reply_\\3.html\\4",
			$siteConfig['site_url']."/pvtmsg_delete_\\3.html\\4",
			$siteConfig['site_url']."/pvtmsg_delete_\\3_ok.html\\5",
			//RSS
			$siteConfig['site_url']."/rss.html\\1",
			$siteConfig['site_url']."/rss-\\1.xml\\2",
			$siteConfig['site_url']."/rss-\\1-\\4.xml\\5",
			$siteConfig['site_url']."/rss-\\1-\\4-\\6.xml\\7",
			$siteConfig['site_url']."/rss-forum-\\2.xml\\3",
			$siteConfig['site_url']."/sitemap.xml\\1",
			//Search
			$siteConfig['site_url']."/search.html\\1",
			//Send File
			$siteConfig['site_url']."/sendfile.html\\1",
			//Send News
			$siteConfig['site_url']."/sendnews.html\\1",
			//SiteMap
			$siteConfig['site_url']."/sitemap.html\\1",
			//Staff
			$siteConfig['site_url']."/staff.html\\1",
			//Surveys
			$siteConfig['site_url']."/surveys.html\\1",
			$siteConfig['site_url']."/surveys_result_\\3.html\\4",
			//Tags
			$siteConfig['site_url']."/tags.html\\1",
			$siteConfig['site_url']."/tags_\\3.html\\4",
			//Topics
			$siteConfig['site_url']."/topics.html\\1",
			//Users
			$siteConfig['site_url']."/users.html\\1",
			$siteConfig['site_url']."/users_edit.html\\2",
			$siteConfig['site_url']."/users_logout.html\\2",
			$siteConfig['site_url']."/users_register.html\\2",
			$siteConfig['site_url']."/users_lostpassword.html\\2",
			$siteConfig['site_url']."/users_infoid_\\3.html\\4",
			$siteConfig['site_url']."/users_info_\\3.html\\4"
		);
		
		$s = preg_replace($urlin, $urlout, $s);
		
		memRunHooks('ModRewriteReplaceEnd',array(&$s));
	}
	return replace_htmlclean($s);
}

?>