Menu

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

Download this file

181 lines (164 with data), 4.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
 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include "options.h"
#include "wiki.h"
#include "options_data.h"
namespace data {
options_form::options_form(wiki *_w):
w(_w),
users_only("uonly",w->gettext("Users Only")),
contact_mail("contact",w->gettext("Contact e-mail")),
wiki_title("wtitle",w->gettext("Wiki Title")),
about("about",w->gettext("About Wiki")),
copyright("copy",w->gettext("Copyright String")),
submit("submit",w->gettext("Submit"))
{
*this & users_only & contact_mail & wiki_title & copyright & about & submit;
wiki_title.set_nonempty();
copyright.set_nonempty();
contact_mail.set_nonempty();
about.set_nonempty();
about.rows=10;
about.cols=40;
users_only.help=w->gettext("Disable creation of new articles by visitors");
}
} // namespace data
namespace apps {
using namespace dbixx;
void global_options::load(archive &a) {
a>>users_only_edit>>contact;
}
void global_options::save(archive &a) const
{
a<<users_only_edit<<contact;
}
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;
global.users_only_edit=0;
global.contact.clear();
local.about.clear();
local.title.clear();
local.copyright.clear();
if(!cache.fetch_data("global_ops",global)) {
result res;
sql<< "SELECT name,value FROM options "
"WHERE lang='global' ",res;
row r;
while(res.next(r)) {
string n,v;
r >> n >> v;
if(n=="users_only_edit")
global.users_only_edit=atoi(v.c_str());
else if(n=="contact")
global.contact=v;
}
if(global.contact.empty())
global.contact="no@mail";
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);
loaded=true;
}
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(?,'contact','global')",
global.contact,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();
global.contact=c.form.contact_mail.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);
c.form.contact_mail.set(global.contact);
}
ini(c);
render("edit_options",c);
}
}
MongoDB Logo MongoDB