/***************************************************************************

    supportware
    Copyright (C) 2001-2010 by c.holzheuer
    c.holzheuer@sourceworx.org

    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 option) any later version.

***************************************************************************/


#include <sxpageforum.h>


sxpageforumstart::sxpageforumstart( const ddstring& name, ddwebsite* site ) 
: sxpageforumbase( name, site )
{	
	
	context.pagetype = "start";
	
	// 'home' gibbet nicht mehr
	add_request_handler( "home;default.asp",			"xx_dummy", 			(ddmemptr) &sxpage::on_redirect );	
	// == '/'
	add_request_handler( "index.html;mostwanted",	"xx_forum_start", (ddmemptr) &sxpage::on_overview );
	
	
	context.navilinkbase ="/mostwanted/";
	_linkroot = "/mostwanted/";
	
	add_inner_call( "sn_box_teaser",					 			(ddmemptr) &sxpageforumstart::create_box_teaser );
	add_inner_call( "sn_box_news",					 				(ddmemptr) &sxpageforumstart::create_box_news );
	add_inner_call( "sn_box_top_news",					 		(ddmemptr) &sxpageforumstart::create_box_top_news );

	try
	{
		// die caches füllen
		get_view( "sxpageforumstart.overview" ).execute( "create" );	
	}
	catch( exception& error )
	{
		cout << "---ERROR: " << error.what() << endl;
		throw( error );
	}
	
}


/**
	'homegroups' etc. einfangen und weiterleiten.
*/

dd_result sxpageforumstart::on_redirect( dditem& item )
{
	// home/x geht nach /mostwanted, /home geht nach /
	if( get_split_path().size() == 1 )
		return create_redirect( "/", ret_301_moved_permanently );
	return create_redirect( "/mostwanted/" + get_split_path()[1], ret_301_moved_permanently );		
}



/***************************************************************************

    supportware
    Copyright (C) 2001-2010 by c.holzheuer
    c.holzheuer@sourceworx.org

    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 option) any later version.

***************************************************************************/


sxpageforumoverview::sxpageforumoverview( const ddstring& name, ddwebsite* site ) 
: sxpageforumbase( name, site )
{	
	
	add_request_handler( "forum",						 "xx_forum_overview", 	(ddmemptr) &sxpage::on_overview );
	
	context.navilinkbase ="/forum/";
		
	add_request_handler( "query0", 					 "xx_forum_query1",		(ddmemptr) &sxpageforumstart::query_stage0 );  
  add_request_handler( "query1", 					 "xx_forum_query1",		(ddmemptr) &sxpageforumstart::query_stage1 );  
	add_request_handler( "query2", 					 "xx_forum_query2",		(ddmemptr) &sxpageforumstart::query_stage2, 2 ); 
	add_request_handler( "query3", 					 "xx_forum_query2",		(ddmemptr) &sxpageforumstart::query_stage2 ); 
	add_request_handler( "query4", 					 "xx_forum_query3",		(ddmemptr) &sxpageforumstart::query_stage3 );
	
}	



/***************************************************************************

    supportware
    Copyright (C) 2001-2008 by c.holzheuer
    c.holzheuer@sourceworx.org

    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 option) any later version.

***************************************************************************/


sxpageforumgroups::sxpageforumgroups( const ddstring& name, ddwebsite* site ) 
: sxpageforumbase( name, site )
{	
	
	// alten kram weiterschicken
	add_request_handler( "homegroups",						"xx_dummy", 							(ddmemptr) &sxpage::on_redirect, 2 );
	add_request_handler( "forumgroups",						"xx_dummy", 							(ddmemptr) &sxpage::on_redirect, 2 );
	
	add_request_handler( "recipesgroups",					"xx_dummy", 							(ddmemptr) &sxpage::on_redirect, 2 );
	add_request_handler( "cheatsgroups",					"xx_dummy", 							(ddmemptr) &sxpage::on_redirect, 2 );
	add_request_handler( "solutionsgroups",				"xx_dummy", 							(ddmemptr) &sxpage::on_redirect, 2 );
	add_request_handler( "faqsgroups",						"xx_dummy", 							(ddmemptr) &sxpage::on_redirect, 2 );
	add_request_handler( "groupfaqs",							"xx_dummy", 							(ddmemptr) &sxpage::on_redirect, 2 );
	
	add_request_handler( "groups",								"xx_forum_groups", 	 			(ddmemptr) &sxpageforumbase::on_show_group, 2 );
	
	// rest
	init_requests();
	
	_linkroot = "/groups/";

}


/**
	'homegroups' etc. einfangen und weiterleiten.
*/

dd_result sxpageforumgroups::on_redirect( dditem& item )
{
	return create_redirect( "/groups/" + get_split_path()[1], ret_301_moved_permanently );
}


/***************************************************************************

    supportware
    Copyright (C) 2001-2010 by c.holzheuer
    c.holzheuer@sourceworx.org

    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 option) any later version.

***************************************************************************/


sxpageforumthread::sxpageforumthread( const ddstring& name, ddwebsite* site ) 
: sxpageforumbase( name, site )
{	
	add_request_handler( "t", "xx_forum_show", 	(ddmemptr) &sxpage::on_show, 2 );
		
	// rest
	init_requests();

	_linkroot = "/t/";
	
}


/**
 	Einen Thread anzeigen, neues Format '/t/'. Dabei werden threads vor 09/2007
 	(id<1612470) aufs die startseite umgeleitet
*/

dd_result sxpageforumthread::on_show_entry( dditem& item )
{
	//ddbasetime timer;
	//timer.start();
	//log_error( "TRY: forum new: " + get_full_path() );
	//log_error( "OK:  forum new: " + get_full_path() + " : " + ddstrutil::from_double( timer.elapsed() ) );	

	if( context.id.empty() || !context.id.is_number() )
		return create_error( "Fehlerhafte ID" );
	
	if( context.id.as_int() <= DDLASTID )
	//	return create_redirect( "/threads/" + context.id, true );	
	// neu: lieber auf die startseite umleiten
		return create_redirect( "/" );	
	
	dd_result result = sxpageforumbase::on_show_entry( item );
	//log_error( "OK:  forum new: " + get_full_path() + " : " + ddstrutil::from_double( timer.elapsed() ) );	
	
	return result;


}
/***************************************************************************

    supportware
    Copyright (C) 2001-2008 by c.holzheuer
    c.holzheuer@sourceworx.org

    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 option) any later version.

***************************************************************************/


sxpageforumthreadold::sxpageforumthreadold( const ddstring& name, const ddstring& linkbase, ddwebsite* site ) 
: sxpageforumbase( name, site )
{	
	add_request_handler( linkbase, 							"xx_forum_show", 		 			(ddmemptr) &sxpage::on_show, 2 );
	// rest
	init_requests();
	
	context.navilinkbase = "/" + linkbase + "/";

}


/**
 	Einen Thread anzeigen, altes Format. Dabei werden threads ab 09/2007
 	(id>1612470) aufs neue format umgeleitet
*/

dd_result sxpageforumthreadold::on_show_entry( dditem& item )
{
	//ddbasetime timer;
	//timer.start();
	//log_error( "TRY: forum old: " + get_full_path() );
	
	if( context.id.empty() || !context.id.is_number() )
		return create_error( "Fehlerhafte ID", ddwebresponse::ret_404_not_found );
	
	if( context.id.as_int() > DDLASTID && get_split_path()[0] == "threads" )
		return create_redirect( "/t/" + context.id, ret_301_moved_permanently );
	
	dd_result result = sxpageforumbase::on_show_entry( item );
	//log_error( "OK:  forum old: " + get_full_path() + " : " + ddstrutil::from_double( timer.elapsed() ) );	
	
	return result;
	

}
	

	