Menu

[r618]: / wikipp / trunk / wiki.cpp  Maximize  Restore  History

Download this file

72 lines (59 with data), 1.1 kB

 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 "wiki.h"
#include <boost/bind.hpp>
#include <cgicc/HTTPRedirectHeader.h>
#include <boost/format.hpp>
#include "utf8/utf8.h"
using namespace dbixx;
using cgicc::HTTPRedirectHeader;
namespace apps {
wiki::wiki(worker_thread &w) :
application(w),
page(*this),
options(*this),
users(*this),
index(*this)
{
dbixx_load(sql);
script=app.config.sval("wikipp.script");
url.add("^/(\\w+)(/.*)$",
boost::bind(&wiki::run,this,$1,$2));
use_template("view");
}
string wiki::root(string l)
{
if(l.empty()) l=locale;
return script+"/"+l;
}
bool wiki::set_locale(string lang)
{
if(lang!="en") {
vector<string> const &lst=app.config.slist("locale.lang_list");
vector<string>::const_iterator p,e;
for(p=lst.begin(),e=lst.end();p!=e;++p) {
if(lang==*p) {
break;
}
}
if(p==e) {
return false;
}
}
locale=lang;
set_lang(lang);
return true;
}
void wiki::on_404()
{
page.redirect();
}
void wiki::run(string l,string u)
{
if(!set_locale(l)) {
on_404();
return;
}
if(url_next.parse(u)<0) {
page.redirect(l);
}
}
}
MongoDB Logo MongoDB