summaryrefslogtreecommitdiff
path: root/src/strusCms.cpp
blob: 9d7945b3b7b8e813f5c8eda9d355e5577e8879d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "strusCms.hpp"

#include <cppcms/url_mapper.h>   
#include <cppcms/http_response.h>
#include <cppcms/json.h>
#include <cppdb/frontend.h>

namespace {

void setup_dbconnection( cppdb::session &sql )
{
	std::string driver = sql.driver( );
		
	if( driver == "sqlite3" ) {
		sql << "PRAGMA foreign_keys = 1" << cppdb::exec;
	}
}

}

namespace apps {

strusCms::strusCms( cppcms::service &srv )
	: cppcms::application( srv ),
	master( *this ),
	intro( *this ),
	user( *this ),
	page( *this ),
 	conn( settings( ).get<std::string>( "strusCms.db_connection" ) ),
 	mail( settings( ).get<std::string>( "strusCms.mail.server" ),
		settings( ).get<unsigned short>( "strusCms.mail.port" ),
		settings( ).get<std::string>( "strusCms.mail.username" ),
		settings( ).get<std::string>( "strusCms.mail.password" ),
		settings( ).get<std::string>( "strusCms.mail.from" )
		 )
{
	locale_name = "en";
	script = settings( ).get<std::string>( "strusCms.script" );
	media = settings( ).get<std::string>( "strusCms.media" );

	cppdb::session sql( conn );
	sql.once( setup_dbconnection );
	
	add( master );
	add( intro );
	add( user );
	add( page );
	
	master.register_common_pages( );

	mapper( ).root( root( ) );
}

std::string strusCms::root( std::string l )
{
	return script;
	// TODO: localization later
	//~ if( l.empty( ) ) l = locale_name;
	//~ return script + "/" + l;
}

std::string strusCms::media_root( std::string l )
{
	return media;
	// TODO: localization later
	//~ if( l.empty( ) ) l = locale_name;
	//~ return script + "/" + l;
}


}