Menu

[r522]: / wikipp / trunk / options.cpp  Maximize  Restore  History

Download this file

144 lines (129 with data), 3.0 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
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include "options.h"
#include "wiki.h"
namespace apps {
using namespace dbixx;
void global_options::load(archive &a) {
a>>users_only_edit;
}
void global_options::save(archive &a) const
{
a<<users_only_edit;
}
void locale_options::load(archive &a)
{
a>>title>>about>>copyright;
}
void locale_options::save(archive &a) const
{
a<<title<<about<<copyright;
}
options::options(wiki &w):
master(w)
{
wi.url_next.add("^/options/?$",
boost::bind(&options::edit,this));
on_start.connect(boost::bind(&options::reset,this));
reset();
}
void options::reset()
{
loaded=false;
}
string options::edit_url()
{
return wi.root()+"/options/";
}
void options::load()
{
if(loaded)
return;
if(!cache.fetch_data("global_ops",global)) {
sql<< "SELECT value FROM options "
"WHERE lang='global' AND name='users_only_edit' ";
row r;
if(sql.single(r)) {
string v;
r >> v;
global.users_only_edit=atoi(v.c_str());
}
else {
global.users_only_edit=0;
}
cache.store_data("global_ops",global);
}
if(cache.fetch_data("local_ops:"+locale,local))
return;
result res;
sql<< "SELECT value,name FROM options "
"WHERE lang=?",locale,res;
row r;
while(res.next(r)) {
string v,n;
r>>v>>n;
if(n=="title")
local.title=v;
else if(n=="about")
local.about=v;
else if(n=="copyright")
local.copyright=v;
}
if(local.title.empty())
local.title=gettext("Wiki++ &mdash; CppCMS Wiki");
if(local.about.empty())
local.about=
gettext("## About\n"
"\n"
"Wiki++ is a wiki engine powered by\n"
"[CppCMS](http://cppcms.sf.net/) web development framework.\n");
if(local.copyright.empty())
local.copyright=gettext("&copy; All Rights Reserverd");
cache.store_data("local_ops:"+locale,local);
}
void options::save()
{
sql<< "DELETE FROM options "
"WHERE lang='global' OR lang=?",
locale,exec();
sql<< "INSERT INTO options(value,name,lang) "
"VALUES(?,'users_only_edit','global')",
global.users_only_edit,exec();
sql<< "INSERT INTO options(value,name,lang) "
"VALUES(?,'title',?)",
local.title,locale,exec();
sql<< "INSERT INTO options(value,name,lang) "
"VALUES(?,'about',?)",
local.about,locale,exec();
sql<< "INSERT INTO options(value,name,lang) "
"VALUES(?,'copyright',?)",
local.copyright,locale,exec();
cache.rise("global_ops");
cache.rise("local_ops:"+locale);
}
void options::edit()
{
if(!wi.users.auth()) {
wi.users.error_forbidden();
return;
}
data::edit_options c(&wi);
if(env->getRequestMethod()=="POST") {
c.form.load(*cgi);
if(c.form.validate()) {
global.users_only_edit=c.form.users_only.get();
local.title=c.form.wiki_title.get();
local.copyright=c.form.copyright.get();
local.about=c.form.about.get();
save();
}
}
else {
load();
c.form.users_only.set(global.users_only_edit);
c.form.wiki_title.set(local.title);
c.form.copyright.set(local.copyright);
c.form.about.set(local.about);
}
ini(c);
render("edit_options",c);
}
}
MongoDB Logo MongoDB