added: forum
added: mount params can have arguments (in parentheses) added: mount params: withheader, withinfo, restrictcreatethread, only_root_can_remove, can_use_emacs_on(level), can_use_mkdir_on(level), added: table Item has 'subject' column now removed: column 'subject' from table Content git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@505 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
3d001e7458
commit
1eb42446f8
|
@ -1,25 +1,25 @@
|
|||
# DO NOT DELETE
|
||||
|
||||
cat.o: content.h ../core/item.h ../templates/templates.h ../../ezc/src/ezc.h
|
||||
cat.o: ../templates/patterncacher.h ../app/templates.h ../core/request.h
|
||||
cat.o: ../core/requesttypes.h ../core/session.h ../core/done.h ../core/item.h
|
||||
cat.o: ../core/error.h ../core/log.h ../core/user.h ../core/function.h
|
||||
cat.o: ../core/thread.h ../core/error.h
|
||||
cat.o: ../templates/patterncacher.h ../app/templates.h ../core/thread.h
|
||||
cat.o: ../core/request.h ../core/requesttypes.h ../core/session.h
|
||||
cat.o: ../core/done.h ../core/item.h ../core/error.h ../core/log.h
|
||||
cat.o: ../core/user.h ../core/function.h ../core/thread.h ../core/error.h
|
||||
content.o: content.h ../core/item.h ../templates/templates.h
|
||||
content.o: ../../ezc/src/ezc.h ../templates/patterncacher.h
|
||||
content.o: ../app/templates.h ../core/request.h ../core/requesttypes.h
|
||||
content.o: ../core/session.h ../core/done.h ../core/item.h ../core/error.h
|
||||
content.o: ../core/log.h ../core/user.h ../core/function.h ../core/thread.h
|
||||
content.o: ../core/error.h ../core/db.h ../core/group.h
|
||||
content.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/data.h
|
||||
content.o: ../core/dirs.h ../core/users.h ../core/groups.h
|
||||
content.o: ../app/templates.h ../core/thread.h ../core/request.h
|
||||
content.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||
content.o: ../core/item.h ../core/error.h ../core/log.h ../core/user.h
|
||||
content.o: ../core/function.h ../core/thread.h ../core/error.h ../core/db.h
|
||||
content.o: ../core/group.h ../core/dircontainer.h ../core/ugcontainer.h
|
||||
content.o: ../core/data.h ../core/dirs.h ../core/users.h ../core/groups.h
|
||||
content.o: ../core/functions.h ../core/lastcontainer.h ../core/mounts.h
|
||||
content.o: ../core/mount.h ../app/content.h
|
||||
content.o: ../core/mount.h ../app/content.h ../core/misc.h
|
||||
createthread.o: content.h ../core/item.h ../templates/templates.h
|
||||
createthread.o: ../../ezc/src/ezc.h ../templates/patterncacher.h
|
||||
createthread.o: ../app/templates.h ../core/request.h ../core/requesttypes.h
|
||||
createthread.o: ../core/session.h ../core/done.h ../core/item.h
|
||||
createthread.o: ../core/error.h ../core/log.h ../core/user.h
|
||||
createthread.o: ../app/templates.h ../core/thread.h ../core/request.h
|
||||
createthread.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||
createthread.o: ../core/item.h ../core/error.h ../core/log.h ../core/user.h
|
||||
createthread.o: ../core/function.h ../core/thread.h ../core/error.h
|
||||
createthread.o: ../core/db.h ../core/group.h ../core/dircontainer.h
|
||||
createthread.o: ../core/ugcontainer.h ../core/mount.h ../core/data.h
|
||||
|
@ -28,93 +28,94 @@ createthread.o: ../core/functions.h ../core/lastcontainer.h ../core/mounts.h
|
|||
createthread.o: ../core/mount.h
|
||||
default.o: content.h ../core/item.h ../templates/templates.h
|
||||
default.o: ../../ezc/src/ezc.h ../templates/patterncacher.h
|
||||
default.o: ../app/templates.h ../core/request.h ../core/requesttypes.h
|
||||
default.o: ../core/session.h ../core/done.h ../core/item.h ../core/error.h
|
||||
default.o: ../core/log.h ../core/user.h ../core/function.h ../core/thread.h
|
||||
default.o: ../core/error.h ../core/db.h ../core/group.h
|
||||
default.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/data.h
|
||||
default.o: ../core/dirs.h ../core/users.h ../core/groups.h
|
||||
default.o: ../app/templates.h ../core/thread.h ../core/request.h
|
||||
default.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||
default.o: ../core/item.h ../core/error.h ../core/log.h ../core/user.h
|
||||
default.o: ../core/function.h ../core/thread.h ../core/error.h ../core/db.h
|
||||
default.o: ../core/group.h ../core/dircontainer.h ../core/ugcontainer.h
|
||||
default.o: ../core/data.h ../core/dirs.h ../core/users.h ../core/groups.h
|
||||
default.o: ../core/functions.h ../core/lastcontainer.h ../core/mounts.h
|
||||
default.o: ../core/mount.h
|
||||
emacs.o: content.h ../core/item.h ../templates/templates.h
|
||||
emacs.o: ../../ezc/src/ezc.h ../templates/patterncacher.h ../app/templates.h
|
||||
emacs.o: ../core/request.h ../core/requesttypes.h ../core/session.h
|
||||
emacs.o: ../core/done.h ../core/item.h ../core/error.h ../core/log.h
|
||||
emacs.o: ../core/user.h ../core/function.h ../core/thread.h ../core/error.h
|
||||
emacs.o: ../core/misc.h ../core/db.h ../core/group.h ../core/dircontainer.h
|
||||
emacs.o: ../core/thread.h ../core/request.h ../core/requesttypes.h
|
||||
emacs.o: ../core/session.h ../core/done.h ../core/item.h ../core/error.h
|
||||
emacs.o: ../core/log.h ../core/user.h ../core/function.h ../core/thread.h
|
||||
emacs.o: ../core/error.h ../core/db.h ../core/group.h ../core/dircontainer.h
|
||||
emacs.o: ../core/ugcontainer.h ../core/data.h ../core/dirs.h ../core/users.h
|
||||
emacs.o: ../core/groups.h ../core/functions.h ../core/lastcontainer.h
|
||||
emacs.o: ../core/mounts.h ../core/mount.h
|
||||
last.o: content.h ../core/item.h ../templates/templates.h ../../ezc/src/ezc.h
|
||||
last.o: ../templates/patterncacher.h ../app/templates.h
|
||||
last.o: ../templates/patterncacher.h ../app/templates.h ../core/thread.h
|
||||
login.o: content.h ../core/item.h ../templates/templates.h
|
||||
login.o: ../../ezc/src/ezc.h ../templates/patterncacher.h ../app/templates.h
|
||||
login.o: ../core/request.h ../core/requesttypes.h ../core/session.h
|
||||
login.o: ../core/done.h ../core/item.h ../core/error.h ../core/log.h
|
||||
login.o: ../core/user.h ../core/function.h ../core/thread.h ../core/error.h
|
||||
login.o: ../core/db.h ../core/group.h ../core/dircontainer.h
|
||||
login.o: ../core/thread.h ../core/request.h ../core/requesttypes.h
|
||||
login.o: ../core/session.h ../core/done.h ../core/item.h ../core/error.h
|
||||
login.o: ../core/log.h ../core/user.h ../core/function.h ../core/thread.h
|
||||
login.o: ../core/error.h ../core/db.h ../core/group.h ../core/dircontainer.h
|
||||
login.o: ../core/ugcontainer.h ../core/data.h ../core/dirs.h ../core/users.h
|
||||
login.o: ../core/groups.h ../core/functions.h ../core/lastcontainer.h
|
||||
login.o: ../core/mounts.h ../core/mount.h
|
||||
logout.o: content.h ../core/item.h ../templates/templates.h
|
||||
logout.o: ../../ezc/src/ezc.h ../templates/patterncacher.h ../app/templates.h
|
||||
logout.o: ../core/request.h ../core/requesttypes.h ../core/session.h
|
||||
logout.o: ../core/done.h ../core/item.h ../core/error.h ../core/log.h
|
||||
logout.o: ../core/user.h ../core/function.h ../core/thread.h ../core/data.h
|
||||
logout.o: ../core/dirs.h ../core/dircontainer.h ../core/users.h
|
||||
logout.o: ../core/ugcontainer.h ../core/groups.h ../core/group.h
|
||||
logout.o: ../core/functions.h ../core/lastcontainer.h ../core/mounts.h
|
||||
logout.o: ../core/mount.h
|
||||
logout.o: ../core/thread.h ../core/request.h ../core/requesttypes.h
|
||||
logout.o: ../core/session.h ../core/done.h ../core/item.h ../core/error.h
|
||||
logout.o: ../core/log.h ../core/user.h ../core/function.h ../core/thread.h
|
||||
logout.o: ../core/data.h ../core/dirs.h ../core/dircontainer.h
|
||||
logout.o: ../core/users.h ../core/ugcontainer.h ../core/groups.h
|
||||
logout.o: ../core/group.h ../core/functions.h ../core/lastcontainer.h
|
||||
logout.o: ../core/mounts.h ../core/mount.h
|
||||
ls.o: content.h ../core/item.h ../templates/templates.h ../../ezc/src/ezc.h
|
||||
ls.o: ../templates/patterncacher.h ../app/templates.h ../core/request.h
|
||||
ls.o: ../core/requesttypes.h ../core/session.h ../core/done.h ../core/item.h
|
||||
ls.o: ../core/error.h ../core/log.h ../core/user.h ../core/function.h
|
||||
ls.o: ../core/thread.h ../core/db.h ../core/group.h ../core/dircontainer.h
|
||||
ls.o: ../core/ugcontainer.h
|
||||
ls.o: ../templates/patterncacher.h ../app/templates.h ../core/thread.h
|
||||
ls.o: ../core/request.h ../core/requesttypes.h ../core/session.h
|
||||
ls.o: ../core/done.h ../core/item.h ../core/error.h ../core/log.h
|
||||
ls.o: ../core/user.h ../core/function.h ../core/thread.h ../core/db.h
|
||||
ls.o: ../core/group.h ../core/dircontainer.h ../core/ugcontainer.h
|
||||
mkdir.o: content.h ../core/item.h ../templates/templates.h
|
||||
mkdir.o: ../../ezc/src/ezc.h ../templates/patterncacher.h ../app/templates.h
|
||||
mkdir.o: ../core/request.h ../core/requesttypes.h ../core/session.h
|
||||
mkdir.o: ../core/done.h ../core/item.h ../core/error.h ../core/log.h
|
||||
mkdir.o: ../core/user.h ../core/function.h ../core/thread.h ../core/error.h
|
||||
mkdir.o: ../core/db.h ../core/group.h ../core/dircontainer.h
|
||||
mkdir.o: ../core/thread.h ../core/request.h ../core/requesttypes.h
|
||||
mkdir.o: ../core/session.h ../core/done.h ../core/item.h ../core/error.h
|
||||
mkdir.o: ../core/log.h ../core/user.h ../core/function.h ../core/thread.h
|
||||
mkdir.o: ../core/error.h ../core/db.h ../core/group.h ../core/dircontainer.h
|
||||
mkdir.o: ../core/ugcontainer.h ../core/data.h ../core/dirs.h ../core/users.h
|
||||
mkdir.o: ../core/groups.h ../core/functions.h ../core/lastcontainer.h
|
||||
mkdir.o: ../core/mounts.h ../core/mount.h
|
||||
node.o: content.h ../core/item.h ../templates/templates.h ../../ezc/src/ezc.h
|
||||
node.o: ../templates/patterncacher.h ../app/templates.h ../core/request.h
|
||||
node.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||
node.o: ../core/item.h ../core/error.h ../core/log.h ../core/user.h
|
||||
node.o: ../core/function.h ../core/thread.h
|
||||
node.o: ../templates/patterncacher.h ../app/templates.h ../core/thread.h
|
||||
node.o: ../core/request.h ../core/requesttypes.h ../core/session.h
|
||||
node.o: ../core/done.h ../core/item.h ../core/error.h ../core/log.h
|
||||
node.o: ../core/user.h ../core/function.h ../core/thread.h
|
||||
priv.o: content.h ../core/item.h ../templates/templates.h ../../ezc/src/ezc.h
|
||||
priv.o: ../templates/patterncacher.h ../app/templates.h ../core/request.h
|
||||
priv.o: ../core/requesttypes.h ../core/session.h ../core/done.h
|
||||
priv.o: ../core/item.h ../core/error.h ../core/log.h ../core/user.h
|
||||
priv.o: ../core/function.h ../core/thread.h ../core/error.h ../core/db.h
|
||||
priv.o: ../core/group.h ../core/dircontainer.h ../core/ugcontainer.h
|
||||
priv.o: ../core/data.h ../core/dirs.h ../core/users.h ../core/groups.h
|
||||
priv.o: ../core/functions.h ../core/lastcontainer.h ../core/mounts.h
|
||||
priv.o: ../core/mount.h
|
||||
priv.o: ../templates/patterncacher.h ../app/templates.h ../core/thread.h
|
||||
priv.o: ../core/request.h ../core/requesttypes.h ../core/session.h
|
||||
priv.o: ../core/done.h ../core/item.h ../core/error.h ../core/log.h
|
||||
priv.o: ../core/user.h ../core/function.h ../core/thread.h ../core/error.h
|
||||
priv.o: ../core/db.h ../core/group.h ../core/dircontainer.h
|
||||
priv.o: ../core/ugcontainer.h ../core/data.h ../core/dirs.h ../core/users.h
|
||||
priv.o: ../core/groups.h ../core/functions.h ../core/lastcontainer.h
|
||||
priv.o: ../core/mounts.h ../core/mount.h
|
||||
rm.o: content.h ../core/item.h ../templates/templates.h ../../ezc/src/ezc.h
|
||||
rm.o: ../templates/patterncacher.h ../app/templates.h ../core/request.h
|
||||
rm.o: ../core/requesttypes.h ../core/session.h ../core/done.h ../core/item.h
|
||||
rm.o: ../core/error.h ../core/log.h ../core/user.h ../core/function.h
|
||||
rm.o: ../core/thread.h ../core/error.h ../core/db.h ../core/group.h
|
||||
rm.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/data.h
|
||||
rm.o: ../core/dirs.h ../core/users.h ../core/groups.h ../core/functions.h
|
||||
rm.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
|
||||
rm.o: ../templates/patterncacher.h ../app/templates.h ../core/thread.h
|
||||
rm.o: ../core/request.h ../core/requesttypes.h ../core/session.h
|
||||
rm.o: ../core/done.h ../core/item.h ../core/error.h ../core/log.h
|
||||
rm.o: ../core/user.h ../core/function.h ../core/thread.h ../core/error.h
|
||||
rm.o: ../core/db.h ../core/group.h ../core/dircontainer.h
|
||||
rm.o: ../core/ugcontainer.h ../core/data.h ../core/dirs.h ../core/users.h
|
||||
rm.o: ../core/groups.h ../core/functions.h ../core/lastcontainer.h
|
||||
rm.o: ../core/mounts.h ../core/mount.h
|
||||
run.o: content.h ../core/item.h ../templates/templates.h ../../ezc/src/ezc.h
|
||||
run.o: ../templates/patterncacher.h ../app/templates.h ../core/request.h
|
||||
run.o: ../core/requesttypes.h ../core/session.h ../core/done.h ../core/item.h
|
||||
run.o: ../core/error.h ../core/log.h ../core/user.h ../core/function.h
|
||||
run.o: ../core/thread.h ../core/error.h
|
||||
run.o: ../templates/patterncacher.h ../app/templates.h ../core/thread.h
|
||||
run.o: ../core/request.h ../core/requesttypes.h ../core/session.h
|
||||
run.o: ../core/done.h ../core/item.h ../core/error.h ../core/log.h
|
||||
run.o: ../core/user.h ../core/function.h ../core/thread.h ../core/error.h
|
||||
thread.o: content.h ../core/item.h ../templates/templates.h
|
||||
thread.o: ../../ezc/src/ezc.h ../templates/patterncacher.h ../app/templates.h
|
||||
thread.o: ../core/request.h ../core/requesttypes.h ../core/session.h
|
||||
thread.o: ../core/done.h ../core/item.h ../core/error.h ../core/log.h
|
||||
thread.o: ../core/user.h ../core/function.h ../core/thread.h ../core/db.h
|
||||
thread.o: ../core/group.h ../core/dircontainer.h ../core/ugcontainer.h
|
||||
thread.o: ../core/data.h ../core/dirs.h ../core/users.h ../core/groups.h
|
||||
thread.o: ../core/functions.h ../core/lastcontainer.h ../core/mounts.h
|
||||
thread.o: ../core/mount.h ../core/mount.h
|
||||
thread.o: ../core/thread.h ../core/request.h ../core/requesttypes.h
|
||||
thread.o: ../core/session.h ../core/done.h ../core/item.h ../core/error.h
|
||||
thread.o: ../core/log.h ../core/user.h ../core/function.h ../core/thread.h
|
||||
thread.o: ../core/db.h ../core/group.h ../core/dircontainer.h
|
||||
thread.o: ../core/ugcontainer.h ../core/data.h ../core/dirs.h ../core/users.h
|
||||
thread.o: ../core/groups.h ../core/functions.h ../core/lastcontainer.h
|
||||
thread.o: ../core/mounts.h ../core/mount.h ../core/mount.h
|
||||
who.o: content.h ../core/item.h ../templates/templates.h ../../ezc/src/ezc.h
|
||||
who.o: ../templates/patterncacher.h ../app/templates.h
|
||||
who.o: ../templates/patterncacher.h ../app/templates.h ../core/thread.h
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "../core/db.h"
|
||||
#include "../core/data.h"
|
||||
#include "../app/content.h"
|
||||
|
||||
#include "../core/misc.h"
|
||||
|
||||
|
||||
bool Content::Init()
|
||||
|
@ -59,9 +59,7 @@ void Content::SetDefaultFunctionForFile()
|
|||
|
||||
void Content::SetDefaultFunctionForDir()
|
||||
{
|
||||
Mount mount = data.mounts.GetCurrentMountPoint();
|
||||
|
||||
if( mount.type == Mount::thread )
|
||||
if( data.mounts.CurrentMountType() == Mount::thread )
|
||||
{
|
||||
request.pfunction = data.functions.GetFunction(FUN_THREAD);
|
||||
|
||||
|
@ -341,15 +339,35 @@ void Content::ReadAdditionalInfo()
|
|||
if( request.dir_table.empty() )
|
||||
return;
|
||||
|
||||
Mount mount = data.mounts.GetCurrentMountPoint();
|
||||
|
||||
if( mount.type == Mount::thread )
|
||||
if( data.mounts.CurrentMountType() == Mount::thread )
|
||||
{
|
||||
db.GetThreadByDirId(request.dir_table.back()->id, request.thread);
|
||||
if( db.GetThreadByDirId(request.dir_table.back()->id, request.thread) == Error::ok )
|
||||
request.is_thread = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Content::PrepareUrl(Item & item)
|
||||
{
|
||||
TrimWhite(item.url);
|
||||
|
||||
if( item.url.empty() )
|
||||
item.url = item.subject; // if the subject is empty then the url will be corrected by CorrectUrl()
|
||||
|
||||
CorrectUrl(item);
|
||||
|
||||
if( data.functions.GetFunction(item.url) )
|
||||
{
|
||||
// the name provided by an user is the same as a name of a function
|
||||
// we add one underscore character at the beginning
|
||||
|
||||
// names of functions should not begin with an underscore '_'
|
||||
// and we can simply add one '_' at the beginning
|
||||
// and the name will be unique
|
||||
item.url.insert(item.url.begin(), '_');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
#include "../core/item.h"
|
||||
#include "../templates/templates.h"
|
||||
|
||||
#include "../core/thread.h"
|
||||
|
||||
class Content
|
||||
{
|
||||
|
@ -55,6 +55,8 @@ class Content
|
|||
void FunRun();
|
||||
void FunWho();
|
||||
void FunLast();
|
||||
|
||||
static bool FunThreadSort(const Thread & t1, const Thread & t2);
|
||||
void FunThread();
|
||||
void FunCreateThread();
|
||||
|
||||
|
@ -62,10 +64,11 @@ class Content
|
|||
void PostFunEmacsAdd();
|
||||
void PostFunEmacsEdit(bool with_url);
|
||||
void PostFunEmacs();
|
||||
void PostFunMkdir(bool add_to_dir_table = false);
|
||||
void PostFunMkdir(bool add_to_dir_table = false, int mask = 0755 );
|
||||
long PostFunDefaultParsePath();
|
||||
void PostFunDefault();
|
||||
void PostFunPriv();
|
||||
void PostFunPriv(Item & item);
|
||||
|
||||
bool FunCreateThreadCheckAccess();
|
||||
void PostFunCreateThread();
|
||||
|
|
|
@ -15,18 +15,9 @@
|
|||
#include "../core/data.h"
|
||||
|
||||
|
||||
|
||||
bool Content::FunCreateThreadCheckAccess()
|
||||
{
|
||||
Mount mount = data.mounts.GetCurrentMountPoint();
|
||||
|
||||
if( mount.type != Mount::thread )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !request.HasWriteAccess(*request.dir_table.back()) || request.is_item )
|
||||
if( !request.CanCreateThread() )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
return false;
|
||||
|
@ -42,28 +33,35 @@ void Content::PostFunCreateThread()
|
|||
if( !FunCreateThreadCheckAccess() )
|
||||
return;
|
||||
|
||||
request.post_table.insert( std::make_pair(std::string("url"), std::string()) ); // !! tymczasowo, zrobic aby mkdir i emacs nie rzucaly wyjatkiem gdy nie ma url zdefiniowanego
|
||||
|
||||
PostFunMkdir(true);
|
||||
request.thread.parent_id = request.dir_table.back()->id;
|
||||
PostFunMkdir(true, 0777); // !! tymczasowo 777 aby wszyscy mogli wysylac posty
|
||||
|
||||
if( request.session->done_status == Error::ok )
|
||||
{
|
||||
request.thread.dir_id = request.dir_table.back()->id;
|
||||
request.thread.subject = request.PostVar("subject");
|
||||
request.thread.closed = false;
|
||||
|
||||
request.session->done_status = db.AddThread(request.thread);
|
||||
PostFunEmacs();
|
||||
|
||||
if( request.session->done_status == Error::ok )
|
||||
{
|
||||
request.thread.dir_id = request.dir_table.back()->id;
|
||||
request.thread.closed = false;
|
||||
request.thread.items = 1;
|
||||
request.thread.last_item = request.item; // set by PostFunEmacs()
|
||||
|
||||
request.session->done_status = db.AddThread(request.thread);
|
||||
}
|
||||
|
||||
|
||||
if( request.session->done_status == Error::ok )
|
||||
{
|
||||
PostFunEmacs();
|
||||
|
||||
if( request.session->done_status == Error::ok )
|
||||
{
|
||||
request.session->done = Done::added_thread;
|
||||
RedirectTo(*request.dir_table.back());
|
||||
}
|
||||
request.session->done = Done::added_thread;
|
||||
RedirectTo(*request.dir_table.back());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -75,6 +73,8 @@ void Content::PostFunCreateThread()
|
|||
void Content::FunCreateThread()
|
||||
{
|
||||
FunCreateThreadCheckAccess();
|
||||
|
||||
TemplatesFunctions::thread_show_edit_subject_var = true; // !! tymczasowe rozwiazanie
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#include "content.h"
|
||||
#include "../core/request.h"
|
||||
#include "../core/error.h"
|
||||
#include "../core/misc.h"
|
||||
#include "../core/db.h"
|
||||
#include "../core/data.h"
|
||||
|
||||
|
@ -18,22 +17,6 @@
|
|||
|
||||
|
||||
|
||||
void Content::PrepareUrl(Item & item)
|
||||
{
|
||||
CorrectUrl(item);
|
||||
|
||||
if( data.functions.GetFunction(item.url) )
|
||||
{
|
||||
// the name provided by an user is the same as a name of a function
|
||||
// we add one underscore character at the beginning
|
||||
|
||||
// names of functions should not begin with an underscore '_'
|
||||
// and we can simply add one '_' at the beginning
|
||||
// and the name will be unique
|
||||
item.url.insert(item.url.begin(), '_');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Content::PostFunEmacsAdd()
|
||||
|
@ -47,10 +30,11 @@ void Content::PostFunEmacsAdd()
|
|||
request.item.privileges = 0644; // !! tymczasowo, bedzie uzyte umask
|
||||
request.item.parent_id = request.dir_table.back()->id;
|
||||
request.item.type = Item::file;
|
||||
request.item.content_type = 1;// !! tymczasowo formatted text
|
||||
|
||||
// dates (creation and modification) is set by request.item.Clear() at the beginning
|
||||
|
||||
if( !request.HasWriteAccess(*request.dir_table.back() ) )
|
||||
if( !request.CanUseEmacs(*request.dir_table.back() ) )
|
||||
throw Error(Error::permision_denied);
|
||||
|
||||
request.session->done_status = db.AddItem(request.item);
|
||||
|
@ -62,7 +46,7 @@ void Content::PostFunEmacsEdit(bool with_url)
|
|||
{
|
||||
request.session->done = Done::edited_item;
|
||||
|
||||
if( !request.HasWriteAccess(request.item) )
|
||||
if( !request.CanUseEmacs(request.item) )
|
||||
throw Error(Error::permision_denied);
|
||||
|
||||
time_t t = std::time(0);
|
||||
|
@ -78,11 +62,30 @@ void Content::PostFunEmacsEdit(bool with_url)
|
|||
|
||||
void Content::PostFunEmacs()
|
||||
{
|
||||
bool adding = true;
|
||||
|
||||
if( request.is_item )
|
||||
adding = false;
|
||||
|
||||
try
|
||||
{
|
||||
// these old values are ignored (if exists)
|
||||
|
||||
//!! tymczasowo, zabezpieczenie przed pustym url-em
|
||||
try {
|
||||
request.item.url = request.PostVar("url");
|
||||
request.item.subject = request.PostVar("subject");
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
}
|
||||
|
||||
if( request.item.subject.empty() )
|
||||
request.item.subject = request.dir_table.back()->subject;
|
||||
// !! dodac skladanie tytuly z ostatniego katalogu i liczby okreslajacej ile jest elementow w srodku
|
||||
// !! nie bedzie obciazany modul wyszukujacy bardzo
|
||||
////////
|
||||
|
||||
request.item.content = request.PostVar("content");
|
||||
|
||||
bool with_url = false;
|
||||
|
@ -92,10 +95,11 @@ void Content::PostFunEmacs()
|
|||
|
||||
PrepareUrl(request.item);
|
||||
|
||||
if( request.is_item )
|
||||
PostFunEmacsEdit(with_url);
|
||||
else
|
||||
if( adding )
|
||||
PostFunEmacsAdd();
|
||||
else
|
||||
PostFunEmacsEdit(with_url);
|
||||
|
||||
}
|
||||
catch(const Error & e)
|
||||
{
|
||||
|
@ -106,9 +110,22 @@ void Content::PostFunEmacs()
|
|||
|
||||
if( request.session->done_status == Error::ok )
|
||||
{
|
||||
request.session->item = request.item;
|
||||
request.session->done_timer = 2;
|
||||
RedirectTo(request.item);
|
||||
if( data.mounts.CurrentMountType() == Mount::thread )
|
||||
{
|
||||
if( adding )
|
||||
db.EditThreadAddItem(request.dir_table.back()->id, request.item.id);
|
||||
|
||||
|
||||
// request.session->item = request.item;
|
||||
// request.session->done_timer = 2;
|
||||
RedirectTo(*request.dir_table.back());
|
||||
}
|
||||
else
|
||||
{
|
||||
request.session->item = request.item;
|
||||
request.session->done_timer = 2;
|
||||
RedirectTo(request.item);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -128,14 +145,14 @@ void Content::FunEmacs()
|
|||
if( !request.is_item )
|
||||
{
|
||||
// adding a new item
|
||||
if( !request.HasReadWriteAccess(*request.dir_table.back()) )
|
||||
if( !request.CanUseEmacs(*request.dir_table.back()) )
|
||||
request.status = Error::permision_denied;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// editing an existing item
|
||||
if( !request.HasReadWriteAccess(request.item) )
|
||||
if( !request.CanUseEmacs(request.item) )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
return;
|
||||
|
|
|
@ -21,16 +21,9 @@ void Content::FunLs()
|
|||
request.item_table.push_back( request.item );
|
||||
return;
|
||||
}
|
||||
|
||||
// !! a gdzie sprawdzenie uprawnien?
|
||||
|
||||
// we're showing the whole directory
|
||||
Item item_ref;
|
||||
|
||||
item_ref.parent_id = request.dir_table.back()->id;
|
||||
|
||||
// !! zrobic inna metode, inny interfejs (jako parametr niech bierze parent_id), i zeby nie odczytywala contentu i subjectu (a moze tylko subject? przyda sie przy ls -l)
|
||||
db.GetItems(request.item_table, item_ref);
|
||||
// we're reading only files here
|
||||
db.GetItems(request.item_table, request.dir_table.back()->id, Item::file, false, false, true);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -16,9 +16,9 @@
|
|||
|
||||
|
||||
|
||||
void Content::PostFunMkdir(bool add_to_dir_table)
|
||||
void Content::PostFunMkdir(bool add_to_dir_table, int mask)
|
||||
{
|
||||
if( !request.HasWriteAccess(*request.dir_table.back()) )
|
||||
if( !request.CanUseMkdir(*request.dir_table.back()) )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
return;
|
||||
|
@ -30,12 +30,13 @@ void Content::PostFunMkdir(bool add_to_dir_table)
|
|||
try
|
||||
{
|
||||
item.type = Item::dir;
|
||||
item.subject = request.PostVar("subject");
|
||||
item.url = request.PostVar("url");
|
||||
item.parent_id = request.dir_table.back()->id;
|
||||
item.user_id = request.session->puser ? request.session->puser->id : -1;
|
||||
item.group_id = -1;
|
||||
item.privileges = 0755; // !! tymczasowo, bedzie uzyte umask
|
||||
item.default_item = -1; // !! tymczasowo, bedzie formularz z wprowadzeniem
|
||||
item.privileges = mask;
|
||||
item.default_item = -1;
|
||||
|
||||
// dates (creation and modification) is set by the Item() constructor
|
||||
|
||||
|
@ -72,7 +73,7 @@ void Content::PostFunMkdir(bool add_to_dir_table)
|
|||
|
||||
void Content::FunMkdir()
|
||||
{
|
||||
if( !request.HasWriteAccess(*request.dir_table.back()) )
|
||||
if( !request.CanUseMkdir(*request.dir_table.back()) )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
return;
|
||||
|
|
|
@ -14,76 +14,70 @@
|
|||
#include "../core/data.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::PostFunPriv()
|
||||
void Content::PostFunPriv(Item & item)
|
||||
{
|
||||
// !! narazie tylko dla plikow
|
||||
if( !request.is_item )
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
long user_id = data.users.GetUserId( request.PostVar("user") );
|
||||
long group_id = data.groups.GetGroupId( request.PostVar("group") );
|
||||
int privileges = strtol( request.PostVar("privileges").c_str() , 0, 8);
|
||||
|
||||
if( !request.CanChangeUser(request.item, user_id) )
|
||||
if( user_id==item.user_id && group_id==item.group_id && privileges==item.privileges )
|
||||
{
|
||||
log << log3 << "Content: PostFunPriv: nothing to change" << logend;
|
||||
throw Error(Error::ok);
|
||||
}
|
||||
|
||||
if( !request.CanChangeUser(item, user_id) )
|
||||
throw Error(Error::cant_change_user);
|
||||
|
||||
if( !request.CanChangeGroup(request.item, group_id) )
|
||||
if( !request.CanChangeGroup(item, group_id) )
|
||||
throw Error(Error::cant_change_group);
|
||||
|
||||
if( !request.CanChangePrivileges(request.item, privileges) )
|
||||
if( !request.CanChangePrivileges(item, privileges) )
|
||||
throw Error(Error::cant_change_privileges);
|
||||
|
||||
request.item.user_id = user_id;
|
||||
request.item.group_id = group_id;
|
||||
request.item.privileges = privileges;
|
||||
item.user_id = user_id;
|
||||
item.group_id = group_id;
|
||||
item.privileges = privileges;
|
||||
|
||||
request.session->done = Done::privileged_item;
|
||||
request.session->done_status = db.EditPrivById(request.item, request.item.id);
|
||||
request.session->done_status = db.EditPrivById(item, item.id);
|
||||
}
|
||||
catch(const Error & e)
|
||||
{
|
||||
log << log1 << "Content: FunChmod: Error: " << e << logend;
|
||||
request.session->done_status = e;
|
||||
}
|
||||
|
||||
if( request.session->done_status == Error::ok )
|
||||
{
|
||||
request.session->item = request.item;
|
||||
request.session->done_timer = 2;
|
||||
RedirectTo(request.item);
|
||||
request.session->item = item;
|
||||
request.session->done_timer = 2;
|
||||
RedirectTo(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Content: PostFunPrivileges: Error: " << static_cast<int>(request.session->done_status) << logend;
|
||||
}
|
||||
log << log1 << "Content: PostFunPriv: Error: " << static_cast<int>(request.session->done_status) << logend;
|
||||
}
|
||||
|
||||
request.status = request.session->done_status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::PostFunPriv()
|
||||
{
|
||||
if( request.is_item )
|
||||
PostFunPriv( request.item );
|
||||
else
|
||||
PostFunPriv( *request.dir_table.back() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Content::FunPriv()
|
||||
{
|
||||
if( !request.is_item )
|
||||
{
|
||||
// !! chwilowi tylko dla plikow
|
||||
request.status == Error::item_required;
|
||||
return;
|
||||
}
|
||||
|
||||
// you must be an owner of the item (or a superuser)
|
||||
// !! moze wykorzystac request.CanChangeUser() ?
|
||||
if( !request.session->puser || (!request.session->puser->super_user && request.session->puser->id != request.item.user_id) )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
return;
|
||||
}
|
||||
|
||||
// we do not check permissions here
|
||||
// permissions depends on the user, group, and privileges
|
||||
}
|
||||
|
|
|
@ -53,33 +53,17 @@ void Content::FunRmDirRecursive()
|
|||
|
||||
void Content::FunRmDir()
|
||||
{
|
||||
if( request.dir_table.size() == 1 )
|
||||
if( !request.CanRemove(*request.dir_table.back()) )
|
||||
{
|
||||
// rm for the root dir
|
||||
// only the superuser can do it
|
||||
if( !request.session->puser || !request.session->puser->super_user )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
return;
|
||||
}
|
||||
request.status = Error::permision_denied;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Item * last_but_one_dir = *(--(--request.dir_table.end()));
|
||||
|
||||
if( !request.HasWriteAccess(*last_but_one_dir) )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( request.param_table.empty() )
|
||||
request.status = Error::permision_denied;
|
||||
else
|
||||
if( request.IsParam("confirm") )
|
||||
return;
|
||||
return;
|
||||
else
|
||||
if( request.IsParam("r") )
|
||||
FunRmDirRecursive();
|
||||
|
@ -96,7 +80,7 @@ void Content::FunRm()
|
|||
return;
|
||||
}
|
||||
|
||||
if( !request.HasWriteAccess(*request.dir_table.back()) )
|
||||
if( !request.CanRemove(request.item) )
|
||||
{
|
||||
request.status = Error::permision_denied;
|
||||
return;
|
||||
|
|
|
@ -13,24 +13,35 @@
|
|||
#include "../core/data.h"
|
||||
#include "../core/mount.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
bool Content::FunThreadSort(const Thread & t1, const Thread & t2)
|
||||
{
|
||||
Item * pdir1 = data.dirs.GetDir(t1.dir_id);
|
||||
Item * pdir2 = data.dirs.GetDir(t2.dir_id);
|
||||
|
||||
if( !pdir1 || !pdir2 )
|
||||
return false;
|
||||
|
||||
time_t time1 = mktime(&pdir1->date_creation);
|
||||
time_t time2 = mktime(&pdir2->date_creation);
|
||||
|
||||
return time1 > time2;
|
||||
}
|
||||
|
||||
|
||||
void Content::FunThread()
|
||||
{
|
||||
// we're showing the whole directory
|
||||
Item item_ref;
|
||||
|
||||
item_ref.parent_id = request.dir_table.back()->id;
|
||||
|
||||
// !! zrobic inna metode, inny interfejs (jako parametr niech bierze parent_id), i zeby nie odczytywala contentu i subjectu (a moze tylko subject? przyda sie przy ls -l)
|
||||
bool asc = true;
|
||||
|
||||
Mount mount = data.mounts.GetCurrentMountPoint();
|
||||
if( mount.IsParam(Mount::desc) )
|
||||
if( data.mounts.CurrentMountIsParam(Mount::desc) )
|
||||
asc = false;
|
||||
|
||||
db.GetItems(request.item_table, item_ref, asc);
|
||||
db.GetItems(request.item_table, request.dir_table.back()->id, Item::file, true, true, asc);
|
||||
db.GetThreads(request.dir_table.back()->id, request.thread_tab);
|
||||
|
||||
std::sort(request.thread_tab.begin(), request.thread_tab.end(), FunThreadSort);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -30,12 +30,12 @@ lastcontainer.o: lastcontainer.h log.h
|
|||
log.o: log.h
|
||||
main.o: requestcontroller.h ../content/content.h ../core/item.h
|
||||
main.o: ../templates/templates.h ../../ezc/src/ezc.h
|
||||
main.o: ../templates/patterncacher.h ../app/templates.h sessionmanager.h
|
||||
main.o: sessioncontainer.h session.h done.h item.h error.h log.h user.h
|
||||
main.o: functionparser.h requesttypes.h ../app/content.h data.h dirs.h
|
||||
main.o: dircontainer.h users.h ugcontainer.h groups.h group.h functions.h
|
||||
main.o: function.h lastcontainer.h mounts.h mount.h request.h thread.h db.h
|
||||
main.o: config.h ../confparser/confparser.h
|
||||
main.o: ../templates/patterncacher.h ../app/templates.h ../core/thread.h
|
||||
main.o: sessionmanager.h sessioncontainer.h session.h done.h item.h error.h
|
||||
main.o: log.h user.h functionparser.h requesttypes.h ../app/content.h data.h
|
||||
main.o: dirs.h dircontainer.h users.h ugcontainer.h groups.h group.h
|
||||
main.o: functions.h function.h lastcontainer.h mounts.h mount.h request.h
|
||||
main.o: thread.h db.h config.h ../confparser/confparser.h
|
||||
misc.o: misc.h item.h log.h
|
||||
mount.o: mount.h
|
||||
mountparser.o: mountparser.h mount.h item.h error.h log.h data.h dirs.h
|
||||
|
@ -47,17 +47,19 @@ mounts.o: lastcontainer.h request.h requesttypes.h session.h done.h error.h
|
|||
mounts.o: thread.h mountparser.h
|
||||
request.o: request.h requesttypes.h session.h done.h item.h error.h log.h
|
||||
request.o: user.h function.h thread.h getparser.h httpsimpleparser.h
|
||||
request.o: postparser.h cookieparser.h
|
||||
request.o: postparser.h cookieparser.h data.h dirs.h dircontainer.h users.h
|
||||
request.o: ugcontainer.h groups.h group.h functions.h lastcontainer.h
|
||||
request.o: mounts.h mount.h
|
||||
requestcontroller.o: requestcontroller.h ../content/content.h ../core/item.h
|
||||
requestcontroller.o: ../templates/templates.h ../../ezc/src/ezc.h
|
||||
requestcontroller.o: ../templates/patterncacher.h ../app/templates.h
|
||||
requestcontroller.o: sessionmanager.h sessioncontainer.h session.h done.h
|
||||
requestcontroller.o: item.h error.h log.h user.h functionparser.h
|
||||
requestcontroller.o: requesttypes.h ../app/content.h data.h dirs.h
|
||||
requestcontroller.o: dircontainer.h users.h ugcontainer.h groups.h group.h
|
||||
requestcontroller.o: functions.h function.h lastcontainer.h mounts.h mount.h
|
||||
requestcontroller.o: request.h thread.h postparser.h httpsimpleparser.h
|
||||
requestcontroller.o: cookieparser.h
|
||||
requestcontroller.o: ../core/thread.h sessionmanager.h sessioncontainer.h
|
||||
requestcontroller.o: session.h done.h item.h error.h log.h user.h
|
||||
requestcontroller.o: functionparser.h requesttypes.h ../app/content.h data.h
|
||||
requestcontroller.o: dirs.h dircontainer.h users.h ugcontainer.h groups.h
|
||||
requestcontroller.o: group.h functions.h function.h lastcontainer.h mounts.h
|
||||
requestcontroller.o: mount.h request.h thread.h postparser.h
|
||||
requestcontroller.o: httpsimpleparser.h cookieparser.h
|
||||
session.o: session.h done.h item.h error.h log.h user.h
|
||||
sessioncontainer.o: sessioncontainer.h session.h done.h item.h error.h log.h
|
||||
sessioncontainer.o: user.h data.h dirs.h dircontainer.h users.h ugcontainer.h
|
||||
|
|
223
core/db.cpp
223
core/db.cpp
|
@ -361,6 +361,7 @@ void Db::CheckAllUrlSubject()
|
|||
{
|
||||
AssertConnection();
|
||||
std::ostringstream query, query2;
|
||||
// !! subject zostal wrzucony do tabeli item
|
||||
query << "select item.id, subject from core.item left join core.content on item.content_id = content.id where url is null or url=''";
|
||||
|
||||
r = AssertQuery(query.str());
|
||||
|
@ -419,16 +420,17 @@ Error Db::AddItemIntoItem(Item & item)
|
|||
{
|
||||
AssertConnection();
|
||||
std::ostringstream query;
|
||||
query << "insert into core.item (user_id, group_id, privileges, date_creation, date_modification, type, parent_id, content_id, default_item, url) values (";
|
||||
query << '\'' << item.user_id << "', ";
|
||||
query << '\'' << item.group_id << "', ";
|
||||
query << '\'' << item.privileges << "', ";
|
||||
query << '\'' << ConvertTime(item.date_creation) << "', ";
|
||||
query << "insert into core.item (user_id, group_id, privileges, date_creation, date_modification, type, parent_id, content_id, default_item, subject, url) values (";
|
||||
query << '\'' << item.user_id << "', ";
|
||||
query << '\'' << item.group_id << "', ";
|
||||
query << '\'' << item.privileges << "', ";
|
||||
query << '\'' << ConvertTime(item.date_creation) << "', ";
|
||||
query << '\'' << ConvertTime(item.date_modification) << "', ";
|
||||
query << '\'' << static_cast<int>(item.type) << "', ";
|
||||
query << '\'' << item.parent_id << "', ";
|
||||
query << '\'' << item.content_id << "', ";
|
||||
query << '\'' << item.default_item << "', ";
|
||||
query << '\'' << static_cast<int>(item.type) << "', ";
|
||||
query << '\'' << item.parent_id << "', ";
|
||||
query << '\'' << item.content_id << "', ";
|
||||
query << '\'' << item.default_item << "', ";
|
||||
query << '\'' << Escape(item.subject) << "', ";
|
||||
|
||||
url_without_id = AddItemCreateUrlSubject(item);
|
||||
|
||||
|
@ -468,10 +470,9 @@ Error Db::AddItemIntoContent(Item & item)
|
|||
{
|
||||
AssertConnection();
|
||||
std::ostringstream query;
|
||||
query << "insert into core.content (subject, content, content_type) values (";
|
||||
query << '\'' << Escape(item.subject) << "', ";
|
||||
query << '\'' << Escape(item.content) << "', ";
|
||||
query << '\'' << item.content_type << "');";
|
||||
query << "insert into core.content (content, content_type) values (";
|
||||
query << '\'' << Escape(item.content) << "', ";
|
||||
query << '\'' << item.content_type << "');";
|
||||
|
||||
r = AssertQuery(query.str());
|
||||
AssertResultStatus(r, PGRES_COMMAND_OK);
|
||||
|
@ -511,8 +512,7 @@ return result;
|
|||
|
||||
|
||||
|
||||
// !! with_subject zamienic na with_url
|
||||
Error Db::EditItemInItem(Item & item, bool with_subject)
|
||||
Error Db::EditItemInItem(Item & item, bool with_url)
|
||||
{
|
||||
PGresult * r = 0;
|
||||
Error result = Error::ok;
|
||||
|
@ -522,22 +522,23 @@ Error Db::EditItemInItem(Item & item, bool with_subject)
|
|||
{
|
||||
AssertConnection();
|
||||
std::ostringstream query;
|
||||
query << "update core.item set (user_id, group_id, privileges, date_creation, date_modification, type, default_item, parent_id";
|
||||
query << "update core.item set (user_id, group_id, privileges, date_creation, date_modification, type, default_item, parent_id, subject";
|
||||
|
||||
if( with_subject )
|
||||
if( with_url )
|
||||
query << ", url";
|
||||
|
||||
query << ") = (";
|
||||
query << '\'' << item.user_id << "', ";
|
||||
query << '\'' << item.group_id << "', ";
|
||||
query << '\'' << item.privileges << "', ";
|
||||
query << '\'' << ConvertTime(item.date_creation) << "', ";
|
||||
query << '\'' << item.user_id << "', ";
|
||||
query << '\'' << item.group_id << "', ";
|
||||
query << '\'' << item.privileges << "', ";
|
||||
query << '\'' << ConvertTime(item.date_creation) << "', ";
|
||||
query << '\'' << ConvertTime(item.date_modification) << "', ";
|
||||
query << '\'' << static_cast<int>(item.type) << "', ";
|
||||
query << '\'' << item.default_item << "', ";
|
||||
query << '\'' << item.parent_id << "' ";
|
||||
query << '\'' << static_cast<int>(item.type) << "', ";
|
||||
query << '\'' << item.default_item << "', ";
|
||||
query << '\'' << item.parent_id << "', ";
|
||||
query << '\'' << Escape(item.subject) << "' ";
|
||||
|
||||
if( with_subject )
|
||||
if( with_url )
|
||||
{
|
||||
url_without_id = AddItemCreateUrlSubject(item);
|
||||
|
||||
|
@ -552,7 +553,7 @@ Error Db::EditItemInItem(Item & item, bool with_subject)
|
|||
r = AssertQuery(query.str());
|
||||
AssertResultStatus(r, PGRES_COMMAND_OK);
|
||||
|
||||
if( with_subject && !url_without_id )
|
||||
if( with_url && !url_without_id )
|
||||
ToString(item.url, item.id);
|
||||
}
|
||||
catch(const Error & e)
|
||||
|
@ -576,9 +577,8 @@ Error Db::EditItemInContent(Item & item)
|
|||
{
|
||||
AssertConnection();
|
||||
std::ostringstream query;
|
||||
query << "update core.content set (subject, content, content_type) = (";
|
||||
query << "update core.content set (content, content_type) = (";
|
||||
|
||||
query << '\'' << Escape(item.subject) << "', ";
|
||||
query << '\'' << Escape(item.content) << "', ";
|
||||
query << '\'' << item.content_type << "' ";
|
||||
|
||||
|
@ -664,9 +664,8 @@ return result;
|
|||
|
||||
|
||||
// item.id must be set
|
||||
// !! with_subject zamienic na with_url
|
||||
// !! moze nazwa poprostu EditItem (nie trzeba tego ById) ? (sprawdzic czy nie koliduje z inna nazwa)
|
||||
Error Db::EditItemById(Item & item, bool with_subject)
|
||||
Error Db::EditItemById(Item & item, bool with_url)
|
||||
{
|
||||
Error result = Error::ok;
|
||||
|
||||
|
@ -681,7 +680,7 @@ Error Db::EditItemById(Item & item, bool with_subject)
|
|||
result = EditItemInContent(item);
|
||||
|
||||
if( result == Error::ok )
|
||||
result = EditItemInItem(item, with_subject);
|
||||
result = EditItemInItem(item, with_url);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -691,7 +690,7 @@ return result;
|
|||
|
||||
// item.url and item.parent_id must be set
|
||||
// doesn't work with directiories
|
||||
Error Db::EditItemByUrl(Item & item, bool with_subject)
|
||||
Error Db::EditItemByUrl(Item & item, bool with_url)
|
||||
{
|
||||
Error result = EditItemGetId(item);
|
||||
|
||||
|
@ -700,7 +699,7 @@ Error Db::EditItemByUrl(Item & item, bool with_subject)
|
|||
result = EditItemInContent(item);
|
||||
|
||||
if( result == Error::ok )
|
||||
result = EditItemInItem(item, with_subject);
|
||||
result = EditItemInItem(item, with_url);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -747,33 +746,48 @@ return result;
|
|||
|
||||
|
||||
|
||||
PGresult * Db::GetItemsQuery(Item & item_ref, bool asc)
|
||||
PGresult * Db::GetItemsQuery(long parent_id, Item::Type type, bool with_subject, bool with_content, bool sort_asc)
|
||||
{
|
||||
std::ostringstream query;
|
||||
query << "select * from core.item left join core.content on item.content_id = content.id where type!='0' and parent_id='" << item_ref.parent_id << "'";
|
||||
query << "select item.id, user_id, group_id, privileges, date_creation, date_modification, url, type, parent_id, content_id, default_item";
|
||||
|
||||
if( item_ref.id != -1 )
|
||||
query << " and item.id='" << item_ref.id << "'";
|
||||
if( type != Item::dir )
|
||||
{
|
||||
if( with_subject )
|
||||
query << ", subject";
|
||||
|
||||
if( with_content )
|
||||
query << ", content, content_type";
|
||||
}
|
||||
|
||||
if( !item_ref.url.empty() )
|
||||
query << " and url='" << Escape(item_ref.url) << "'";
|
||||
query << " from core.item";
|
||||
|
||||
if( type != Item::dir && with_content )
|
||||
query << " left join core.content on item.content_id = content.id";
|
||||
|
||||
query << " where parent_id='" << parent_id << "'";
|
||||
|
||||
query << " order by item.date_modification";
|
||||
if( type == Item::dir )
|
||||
query << " and type='0'";
|
||||
|
||||
if( type == Item::file )
|
||||
query << " and type='1'";
|
||||
|
||||
if( asc )
|
||||
query << " order by item.date_creation";
|
||||
|
||||
if( sort_asc )
|
||||
query << " asc";
|
||||
else
|
||||
query << " desc";
|
||||
|
||||
query << ';';
|
||||
|
||||
|
||||
return AssertQuery(query.str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Db::GetItems(std::vector<Item> & item_table, Item & item_ref, bool asc)
|
||||
void Db::GetItems(std::vector<Item> & item_table, long parent_id, Item::Type type, bool with_subject, bool with_content, bool sort_asc)
|
||||
{
|
||||
item_table.clear();
|
||||
PGresult * r = 0;
|
||||
|
@ -782,7 +796,7 @@ void Db::GetItems(std::vector<Item> & item_table, Item & item_ref, bool asc)
|
|||
{
|
||||
AssertConnection();
|
||||
|
||||
r = GetItemsQuery(item_ref, asc);
|
||||
r = GetItemsQuery(parent_id, type, with_subject, with_content, sort_asc);
|
||||
AssertResultStatus(r, PGRES_TUPLES_OK);
|
||||
|
||||
Item item;
|
||||
|
@ -930,7 +944,8 @@ long Db::GetDirId(long parent_id, const std::string & url)
|
|||
|
||||
|
||||
|
||||
|
||||
// !! w tej metodzie odczytujemy tylko uprawnienia?
|
||||
// bo w tej chwili jest caly item odczytywany
|
||||
bool Db::GetPriv(Item & item, long id)
|
||||
{
|
||||
bool result = false;
|
||||
|
@ -1380,7 +1395,7 @@ Error Db::GetThreadByDirId(long dir_id, Thread & thread)
|
|||
AssertConnection();
|
||||
|
||||
std::ostringstream query;
|
||||
query << "select id, dir_id, subject, closed from core.thread where thread.dir_id = " << dir_id << ";";
|
||||
query << "select thread.id, thread.parent_id, thread.dir_id, thread.closed, thread.items, thread.last_item, item.date_modification, item.user_id from core.thread left join core.item on thread.last_item = item.id where thread.dir_id = '" << dir_id << "';";
|
||||
|
||||
r = AssertQuery( query.str() );
|
||||
AssertResultStatus(r, PGRES_TUPLES_OK);
|
||||
|
@ -1391,20 +1406,81 @@ Error Db::GetThreadByDirId(long dir_id, Thread & thread)
|
|||
log << log1 << "Db: there is more than one thread with dir_id: " << dir_id << logend;
|
||||
else
|
||||
if( rows == 0 )
|
||||
{
|
||||
log << log1 << "Db: there is no a thread with dir_id: " << dir_id << logend;
|
||||
throw Error(Error::no_thread);
|
||||
}
|
||||
|
||||
int cid = AssertColumn(r, "id");
|
||||
int cdir_id = AssertColumn(r, "dir_id");
|
||||
int csubject = AssertColumn(r, "subject");
|
||||
int cclosed = AssertColumn(r, "closed");
|
||||
int cid = AssertColumn(r, "id");
|
||||
int cparent_id = AssertColumn(r, "parent_id");
|
||||
int cdir_id = AssertColumn(r, "dir_id");
|
||||
int cclosed = AssertColumn(r, "closed");
|
||||
int citems = AssertColumn(r, "items");
|
||||
int clast_item = AssertColumn(r, "last_item");
|
||||
int cdate_modification = PQfnumber(r, "date_modification");
|
||||
int cuser_id = PQfnumber(r, "user_id");
|
||||
|
||||
thread.id = atol( AssertValue(r, 0, cid) );
|
||||
thread.parent_id = atol( AssertValue(r, 0, cparent_id) );
|
||||
thread.dir_id = atol( AssertValue(r, 0, cdir_id) );
|
||||
thread.closed = atol( AssertValue(r, 0, cclosed) ) == 0 ? false : true;
|
||||
thread.items = atol( AssertValue(r, 0, citems) );
|
||||
thread.last_item.id = atol( AssertValue(r, 0, clast_item) );
|
||||
thread.last_item.date_modification = ConvertTime( Db::AssertValue(r, 0, cdate_modification) );
|
||||
thread.last_item.user_id = atol( Db::AssertValue(r, 0, cuser_id) );
|
||||
}
|
||||
catch(const Error & e)
|
||||
{
|
||||
status = e;
|
||||
}
|
||||
|
||||
ClearResult(r);
|
||||
|
||||
thread.id = atol( AssertValue(r, 0, cid) );
|
||||
thread.dir_id = atol( AssertValue(r, 0, cdir_id) );
|
||||
thread.subject = AssertValue(r, 0, csubject);
|
||||
thread.closed = atol( AssertValue(r, 0, cclosed) ) == 0 ? false : true;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Error Db::GetThreads(long parent_id, std::vector<Thread> & thread_tab)
|
||||
{
|
||||
PGresult * r = 0;
|
||||
Error status = Error::ok;
|
||||
|
||||
try
|
||||
{
|
||||
AssertConnection();
|
||||
|
||||
std::ostringstream query;
|
||||
query << "select thread.id, thread.parent_id, thread.dir_id, thread.closed, thread.items, thread.last_item, item.date_modification, item.user_id "
|
||||
"from core.thread left join core.item on thread.last_item = item.id "
|
||||
"where thread.parent_id = '" << parent_id << "' order by date_modification asc;";
|
||||
|
||||
r = AssertQuery( query.str() );
|
||||
AssertResultStatus(r, PGRES_TUPLES_OK);
|
||||
|
||||
int rows = PQntuples(r);
|
||||
Thread thread;
|
||||
|
||||
int cid = AssertColumn(r, "id");
|
||||
int cparent_id = AssertColumn(r, "parent_id");
|
||||
int cdir_id = AssertColumn(r, "dir_id");
|
||||
int cclosed = AssertColumn(r, "closed");
|
||||
int citems = AssertColumn(r, "items");
|
||||
int clast_item = AssertColumn(r, "last_item");
|
||||
int cdate_modification = PQfnumber(r, "date_modification");
|
||||
int cuser_id = PQfnumber(r, "user_id");
|
||||
|
||||
for(int i=0 ; i<rows ; ++i)
|
||||
{
|
||||
thread.id = atol( AssertValue(r, i, cid) );
|
||||
thread.parent_id = atol( AssertValue(r, i, cparent_id) );
|
||||
thread.dir_id = atol( AssertValue(r, i, cdir_id) );
|
||||
thread.closed = atol( AssertValue(r, i, cclosed) ) == 0 ? false : true;
|
||||
thread.items = atol( AssertValue(r, i, citems) );
|
||||
thread.last_item.id = atol( AssertValue(r, i, clast_item) );
|
||||
thread.last_item.date_modification = ConvertTime( Db::AssertValue(r, i, cdate_modification) );
|
||||
thread.last_item.user_id = atol( Db::AssertValue(r, i, cuser_id) );
|
||||
|
||||
thread_tab.push_back(thread);
|
||||
}
|
||||
}
|
||||
catch(const Error & e)
|
||||
{
|
||||
|
@ -1420,6 +1496,7 @@ return status;
|
|||
|
||||
|
||||
|
||||
|
||||
Error Db::AddThread(Thread & thread)
|
||||
{
|
||||
PGresult * r = 0;
|
||||
|
@ -1429,10 +1506,12 @@ Error Db::AddThread(Thread & thread)
|
|||
{
|
||||
AssertConnection();
|
||||
std::ostringstream query;
|
||||
query << "insert into core.thread (dir_id, subject, closed) values (";
|
||||
query << "insert into core.thread (parent_id, dir_id, closed, items, last_item) values (";
|
||||
query << '\'' << thread.parent_id << "', ";
|
||||
query << '\'' << thread.dir_id << "', ";
|
||||
query << '\'' << Escape(thread.subject) << "', ";
|
||||
query << '\'' << (thread.closed ? 1 : 0 ) << "'); ";
|
||||
query << '\'' << (thread.closed ? 1 : 0 ) << "', ";
|
||||
query << '\'' << thread.items << "', ";
|
||||
query << '\'' << thread.last_item.id << "'); ";
|
||||
|
||||
r = AssertQuery(query.str());
|
||||
AssertResultStatus(r, PGRES_COMMAND_OK);
|
||||
|
@ -1451,3 +1530,27 @@ return status;
|
|||
}
|
||||
|
||||
|
||||
|
||||
Error Db::EditThreadAddItem(long dir_id, long item_id)
|
||||
{
|
||||
PGresult * r = 0;
|
||||
Error status = Error::ok;
|
||||
|
||||
try
|
||||
{
|
||||
AssertConnection();
|
||||
std::ostringstream query;
|
||||
query << "update core.thread set (last_item, items) = ('" << item_id << "', items+1) where dir_id='" << dir_id << "';";
|
||||
|
||||
r = AssertQuery(query.str());
|
||||
AssertResultStatus(r, PGRES_COMMAND_OK);
|
||||
}
|
||||
catch(const Error & e)
|
||||
{
|
||||
status = e;
|
||||
}
|
||||
|
||||
ClearResult(r);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
|
18
core/db.h
18
core/db.h
|
@ -45,11 +45,15 @@ public:
|
|||
void Init(const std::string & database, const std::string & user, const std::string & pass);
|
||||
bool CheckUser(std::string & login, std::string & password, long & user_id);
|
||||
Error AddItem(Item & item);
|
||||
Error EditItemById(Item & item, bool with_subject = true);
|
||||
Error EditItemByUrl(Item & item, bool with_subject = true);
|
||||
Error EditItemById(Item & item, bool with_url = true);
|
||||
Error EditItemByUrl(Item & item, bool with_url = true);
|
||||
void CheckAllUrlSubject();
|
||||
void GetItems(std::vector<Item> & item_table, Item & item_ref, bool asc = true);
|
||||
|
||||
void GetItems(std::vector<Item> & item_table, long parent_id, Item::Type type, bool with_subject, bool with_content, bool sort_asc);
|
||||
|
||||
void GetItem(std::vector<Item> & item_table, long id);
|
||||
|
||||
|
||||
bool GetPriv(Item & item, long id);
|
||||
Error EditPrivById(Item & item, long id);
|
||||
|
||||
|
@ -78,7 +82,9 @@ public:
|
|||
|
||||
Error AddThread(Thread & thread);
|
||||
Error GetThreadByDirId(long dir_id, Thread & thread);
|
||||
|
||||
Error GetThreads(long parent_id, std::vector<Thread> & thread_tab);
|
||||
Error EditThreadAddItem(long dir_id, long item_id);
|
||||
|
||||
protected:
|
||||
|
||||
PGconn * pg_conn;
|
||||
|
@ -103,14 +109,14 @@ protected:
|
|||
Error AddItemIntoContent(Item & item);
|
||||
Error AddItemIntoItem(Item & item);
|
||||
|
||||
Error EditItemInItem(Item & item, bool with_subject);
|
||||
Error EditItemInItem(Item & item, bool with_url);
|
||||
Error EditItemInContent(Item & item);
|
||||
Error EditItemGetId(Item & item);
|
||||
Error EditItemGetContentId(Item & item);
|
||||
|
||||
void CheckAllUrlSubjectModifyItem(Item & item);
|
||||
|
||||
PGresult * GetItemsQuery(Item & item_ref, bool asc = true);
|
||||
PGresult * GetItemsQuery(long parent_id, Item::Type type, bool with_subject, bool with_content, bool sort_asc);
|
||||
|
||||
bool DelItemDelItem(const Item & item);
|
||||
void DelItemDelContent(const Item & item);
|
||||
|
|
10
core/item.h
10
core/item.h
|
@ -32,19 +32,23 @@ std::string content;
|
|||
std::string url;
|
||||
|
||||
|
||||
// 0 - simple txt
|
||||
// 1 - formatted txt
|
||||
// 2 - html
|
||||
// 3 - bbcode
|
||||
int content_type;
|
||||
|
||||
|
||||
|
||||
enum Type
|
||||
{
|
||||
dir = 0,
|
||||
file = 1,
|
||||
|
||||
|
||||
|
||||
|
||||
none = 1000
|
||||
};
|
||||
|
||||
|
||||
Type type;
|
||||
|
||||
//item_type;
|
||||
|
|
|
@ -40,11 +40,6 @@ return true;
|
|||
|
||||
|
||||
|
||||
LastContainer::LastContainer()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
LastContainer::Iterator LastContainer::Begin()
|
||||
{
|
||||
|
|
|
@ -60,10 +60,6 @@ public:
|
|||
|
||||
public:
|
||||
|
||||
// !! nie potrzebny, skasowac po stworzeniu jednej biblioteki cmslu.a
|
||||
// chwilowo bez tego wystepuja problemy z linkowaniem
|
||||
LastContainer();
|
||||
|
||||
Iterator Begin();
|
||||
Iterator End();
|
||||
void UserLogin(long user_id, const std::string & name, unsigned int ip, long session_id);
|
||||
|
|
|
@ -56,10 +56,9 @@ void print_syntax()
|
|||
|
||||
|
||||
|
||||
|
||||
int main(int argv, char ** argc)
|
||||
{
|
||||
|
||||
|
||||
std::srand(std::time(0));
|
||||
|
||||
if( argv != 2 )
|
||||
|
|
134
core/misc.cpp
134
core/misc.cpp
|
@ -64,6 +64,8 @@ std::string::iterator i;
|
|||
*i = '_';
|
||||
}
|
||||
}
|
||||
|
||||
ToSmall(item.url);
|
||||
|
||||
if( item.url.empty() )
|
||||
item.url = "bez_nazwy"; // !! wrzucic do pliku konfiguracyjnego
|
||||
|
@ -157,21 +159,38 @@ return c;
|
|||
}
|
||||
|
||||
|
||||
bool HtmlTryChar(std::ostringstream & out, int c)
|
||||
{
|
||||
if( c == '<' )
|
||||
{
|
||||
out << "<";
|
||||
return true;
|
||||
}
|
||||
else
|
||||
if( c == '>' )
|
||||
{
|
||||
out << ">";
|
||||
return true;
|
||||
}
|
||||
else
|
||||
if( c == '&' )
|
||||
{
|
||||
out << "&";
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void HtmlEscape(std::ostringstream & out, const std::string & in)
|
||||
{
|
||||
std::string::const_iterator i;
|
||||
|
||||
for(i = in.begin() ; i != in.end() ; ++i)
|
||||
{
|
||||
if( *i == '<' )
|
||||
out << "<";
|
||||
else
|
||||
if( *i == '>' )
|
||||
out << ">";
|
||||
else
|
||||
if( *i == '&' )
|
||||
out << "&";
|
||||
else
|
||||
if( !HtmlTryChar(out, *i) )
|
||||
out << *i;
|
||||
}
|
||||
}
|
||||
|
@ -187,6 +206,52 @@ return out.str();
|
|||
}
|
||||
|
||||
|
||||
void HtmlEscapeFormTxt(std::ostringstream & out, const std::string & in)
|
||||
{
|
||||
std::string::const_iterator i;
|
||||
int was_enter = 0; // how many enteres there were before
|
||||
|
||||
out << "<p>";
|
||||
|
||||
for(i = in.begin() ; i != in.end() ; ++i)
|
||||
{
|
||||
if( !HtmlTryChar(out, *i) )
|
||||
{
|
||||
if( *i == 13 )
|
||||
// skipping stupid characters (\r\n\ in dos mode)
|
||||
continue;
|
||||
|
||||
if( *i == 10 )
|
||||
{
|
||||
++was_enter;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( was_enter == 1 )
|
||||
out << "<br>\n";
|
||||
else
|
||||
if( was_enter > 1 )
|
||||
out << "</p>\n<p>";
|
||||
|
||||
out << *i;
|
||||
was_enter = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out << "</p>\n";
|
||||
}
|
||||
|
||||
|
||||
std::string HtmlEscapeFormTxt(const std::string & in)
|
||||
{
|
||||
std::ostringstream out;
|
||||
|
||||
HtmlEscapeFormTxt(out, in);
|
||||
|
||||
return out.str();
|
||||
}
|
||||
|
||||
|
||||
const char * DateToStr(int year, int month, int day, int hour, int min, int sec)
|
||||
{
|
||||
|
@ -213,7 +278,7 @@ static char buffer[100];
|
|||
|
||||
const char * DateToStr(tm * ptm)
|
||||
{
|
||||
return DateToStr(ptm->tm_year + 1900, ptm->tm_mon+1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
|
||||
return DateToStr(ptm->tm_year + 1900, ptm->tm_mon+1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
|
||||
}
|
||||
|
||||
|
||||
|
@ -243,4 +308,53 @@ return buffer;
|
|||
}
|
||||
|
||||
|
||||
bool IsWhite(int s)
|
||||
{
|
||||
if( s==' ' || s=='\t' || s==13 )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void TrimWhite(std::string & s)
|
||||
{
|
||||
std::string::size_type i;
|
||||
|
||||
if( s.empty() )
|
||||
return;
|
||||
|
||||
// looking for white characters at the end
|
||||
for(i=s.size()-1 ; i>0 && IsWhite(s[i]) ; --i);
|
||||
|
||||
if( i==0 && IsWhite(s[i]) )
|
||||
{
|
||||
// the whole string has white characters
|
||||
s.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// deleting white characters at the end
|
||||
if( i != s.size() - 1 )
|
||||
s.erase(i+1, std::string::npos);
|
||||
|
||||
// looking for white characters at the beginning
|
||||
for(i=0 ; i<s.size() && IsWhite(s[i]) ; ++i);
|
||||
|
||||
// deleting white characters at the beginning
|
||||
if( i != 0 )
|
||||
s.erase(0, i);
|
||||
}
|
||||
|
||||
|
||||
void ToSmall(std::string & s)
|
||||
{
|
||||
std::string::size_type i;
|
||||
|
||||
for(i=0 ; i<s.size() ; ++i)
|
||||
{
|
||||
if( s[i]>='A' && s[i]<='Z' )
|
||||
s[i] = s[i] - 'A' + 'a';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,10 +30,17 @@ void CorrectUrl(Item & item);
|
|||
void SetUrlFromSubject(Item & item);
|
||||
|
||||
void HtmlEscape(std::ostringstream & out, const std::string & in);
|
||||
void HtmlEscapeFormTxt(std::ostringstream & out, const std::string & in);
|
||||
std::string HtmlEscape(const std::string & in);
|
||||
std::string HtmlEscapeFormTxt(const std::string & in);
|
||||
|
||||
const char * DateToStr(int year, int month, int day, int hour, int min, int sec);
|
||||
const char * DateToStr(tm * ptm);
|
||||
const char * DateToStr(time_t t);
|
||||
const char * IpToStr(unsigned int ip_);
|
||||
|
||||
bool IsWhite(int s);
|
||||
void TrimWhite(std::string & s);
|
||||
void ToSmall(std::string & s);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -32,7 +32,7 @@ const char * Mount::TypeToStr()
|
|||
|
||||
case thread:
|
||||
sprintf(buffer, "thread");
|
||||
break;
|
||||
break;
|
||||
|
||||
default:
|
||||
sprintf(buffer, "the name is not set");
|
||||
|
@ -43,7 +43,7 @@ return buffer;
|
|||
}
|
||||
|
||||
|
||||
bool Mount::ParseStrParam(const std::string & param)
|
||||
bool Mount::ParseStrParam(const std::string & param, const std::vector<int> & args)
|
||||
{
|
||||
Param p = none;
|
||||
|
||||
|
@ -53,12 +53,30 @@ bool Mount::ParseStrParam(const std::string & param)
|
|||
if( param == "desc" )
|
||||
p = desc;
|
||||
else
|
||||
if( param == "withheader" )
|
||||
p = withheader;
|
||||
else
|
||||
if( param == "withinfo" )
|
||||
p = withinfo;
|
||||
else
|
||||
if( param == "restrictcreatethread" )
|
||||
p = restrictcreatethread;
|
||||
else
|
||||
if( param == "only_root_can_remove" )
|
||||
p = only_root_can_remove;
|
||||
else
|
||||
if( param == "can_use_emacs_on" )
|
||||
p = can_use_emacs_on;
|
||||
else
|
||||
if( param == "can_use_mkdir_on" )
|
||||
p = can_use_mkdir_on;
|
||||
else
|
||||
if( param == "none" )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
|
||||
param_table.insert(p);
|
||||
param_table.insert( std::make_pair(p, args) );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -66,10 +84,35 @@ return true;
|
|||
|
||||
bool Mount::IsParam(Param p)
|
||||
{
|
||||
std::set<Param>::iterator i = param_table.find(p);
|
||||
ParamTable::iterator i = param_table.find(p);
|
||||
|
||||
if( i == param_table.end() )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Mount::IsParam(Param p, int * first_arg)
|
||||
{
|
||||
ParamTable::iterator i = param_table.find(p);
|
||||
|
||||
if( i == param_table.end() )
|
||||
{
|
||||
*first_arg = -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !i->second.empty() )
|
||||
*first_arg = i->second[0];
|
||||
else
|
||||
*first_arg = -1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Mount::ClearParams()
|
||||
{
|
||||
param_table.clear();
|
||||
}
|
||||
|
|
18
core/mount.h
18
core/mount.h
|
@ -11,8 +11,9 @@
|
|||
#ifndef headerfilecmslucoremount
|
||||
#define headerfilecmslucoremount
|
||||
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
class Mount
|
||||
|
@ -31,7 +32,13 @@ public:
|
|||
{
|
||||
none = 0,
|
||||
asc,
|
||||
desc
|
||||
desc,
|
||||
withheader,
|
||||
withinfo,
|
||||
restrictcreatethread,
|
||||
only_root_can_remove,
|
||||
can_use_emacs_on,
|
||||
can_use_mkdir_on
|
||||
};
|
||||
|
||||
|
||||
|
@ -40,11 +47,14 @@ public:
|
|||
|
||||
Mount();
|
||||
const char * TypeToStr();
|
||||
bool ParseStrParam(const std::string & param);
|
||||
bool ParseStrParam(const std::string & param, const std::vector<int> & args);
|
||||
bool IsParam(Param p);
|
||||
bool IsParam(Param p, int * first_arg);
|
||||
void ClearParams();
|
||||
|
||||
private:
|
||||
std::set<Param> param_table;
|
||||
typedef std::map<Param, std::vector<int> > ParamTable;
|
||||
ParamTable param_table;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -52,17 +52,77 @@ void MountParser::ReadWord(std::string & res)
|
|||
}
|
||||
|
||||
|
||||
void MountParser::ReadParam(std::string & res)
|
||||
bool MountParser::ReadParamArg(int & out)
|
||||
{
|
||||
res.clear();
|
||||
SkipWhite();
|
||||
|
||||
while( *pinput && *pinput!=10 && *pinput!=',' && !IsWhite(*pinput) )
|
||||
char * new_pos;
|
||||
long temp = strtol(pinput, &new_pos, 10);
|
||||
|
||||
if( pinput == new_pos )
|
||||
return false;
|
||||
|
||||
pinput = new_pos;
|
||||
SkipWhite();
|
||||
|
||||
// here can we make a test whether the temp is greater from 'int' type
|
||||
out = (int)temp;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void MountParser::ReadParamArgs(std::vector<int> & args)
|
||||
{
|
||||
int arg;
|
||||
|
||||
while( ReadParamArg(arg) )
|
||||
{
|
||||
args.push_back(arg);
|
||||
|
||||
log << log3 << "MP: mount param arg: " << arg << logend;
|
||||
|
||||
if( *pinput == ',' )
|
||||
++pinput;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MountParser::ReadParam(std::string & res, std::vector<int> & args)
|
||||
{
|
||||
SkipWhite();
|
||||
res.clear();
|
||||
args.clear();
|
||||
|
||||
while( *pinput && *pinput!=10 && *pinput!=',' && *pinput!='(' && !IsWhite(*pinput) )
|
||||
{
|
||||
res += *pinput;
|
||||
++pinput;
|
||||
}
|
||||
|
||||
if( *pinput==',' )
|
||||
if( res.empty() )
|
||||
return;
|
||||
|
||||
|
||||
// reading arguments
|
||||
SkipWhite();
|
||||
if( *pinput == '(' )
|
||||
{
|
||||
++pinput;
|
||||
ReadParamArgs(args);
|
||||
|
||||
if( *pinput != ')' )
|
||||
{
|
||||
// there should be ')' at the end
|
||||
// temporarily we do nothing
|
||||
}
|
||||
else
|
||||
{
|
||||
++pinput;
|
||||
}
|
||||
}
|
||||
|
||||
if( *pinput == ',' )
|
||||
++pinput;
|
||||
|
||||
}
|
||||
|
@ -118,11 +178,11 @@ void MountParser::ReadMountPoint()
|
|||
|
||||
void MountParser::ReadMountParams()
|
||||
{
|
||||
SkipWhite();
|
||||
mount.ClearParams();
|
||||
|
||||
for( ReadParam(temp) ; !temp.empty() ; ReadParam(temp) )
|
||||
for( ReadParam(temp, param_args) ; !temp.empty() ; ReadParam(temp, param_args) )
|
||||
{
|
||||
if( !mount.ParseStrParam(temp) )
|
||||
if( !mount.ParseStrParam(temp, param_args) )
|
||||
{
|
||||
log << log1 << "MP: unknown mount param: " << temp << logend;
|
||||
err = Error::mount_no_param;
|
||||
|
|
|
@ -12,6 +12,9 @@
|
|||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "mount.h"
|
||||
#include "item.h"
|
||||
|
@ -32,7 +35,9 @@ private:
|
|||
void SkipWhite();
|
||||
void SkipLine();
|
||||
void ReadWord(std::string & res);
|
||||
void ReadParam(std::string & res);
|
||||
bool ReadParamArg(int & out);
|
||||
void ReadParamArgs(std::vector<int> & args);
|
||||
void ReadParam(std::string & res, std::vector<int> & args);
|
||||
void ReadMountType();
|
||||
void ReadMountPoint();
|
||||
void ReadMountParams();
|
||||
|
@ -40,6 +45,8 @@ private:
|
|||
|
||||
const char * pinput;
|
||||
std::string temp;
|
||||
std::vector<int> param_args;
|
||||
|
||||
|
||||
Mount mount;
|
||||
|
||||
|
|
|
@ -19,7 +19,10 @@ void Mounts::ReadMounts()
|
|||
MountParser mp;
|
||||
|
||||
// !! tymczasowo - bedzie odczyt z bazy z /etc/fstab
|
||||
std::string temp = "thread /news desc";
|
||||
std::string temp =
|
||||
"cms / withheader, withinfo \n"
|
||||
"thread /news desc, withheader, withinfo, restrictcreatethread(-1) \n"
|
||||
"thread /forum asc, withinfo, restrictcreatethread(3), only_root_can_remove, can_use_emacs_on(4), can_use_mkdir_on(3)";
|
||||
|
||||
Error err = mp.Parse(temp, mount_table);
|
||||
|
||||
|
@ -34,12 +37,27 @@ void Mounts::ReadMounts()
|
|||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Mount Mounts::GetCurrentMountPoint()
|
||||
{
|
||||
return current_dir;
|
||||
}
|
||||
*/
|
||||
|
||||
Mount::Type Mounts::CurrentMountType()
|
||||
{
|
||||
return current_dir.type;
|
||||
}
|
||||
|
||||
bool Mounts::CurrentMountIsParam(Mount::Param p)
|
||||
{
|
||||
return current_dir.IsParam(p);
|
||||
}
|
||||
|
||||
bool Mounts::CurrentMountIsParam(Mount::Param p, int * first_arg)
|
||||
{
|
||||
return current_dir.IsParam(p, first_arg);
|
||||
}
|
||||
|
||||
|
||||
void Mounts::MountCmsForRoot()
|
||||
|
|
|
@ -24,7 +24,15 @@ public:
|
|||
void ReadMounts();
|
||||
|
||||
void CalculateCurrentMountType();
|
||||
Mount GetCurrentMountPoint();
|
||||
|
||||
// !! nie lepiej aby zwracal tutaj referencje albo wskaznik na biezacy punkt?
|
||||
// !! w Mount mamy strukture std::set
|
||||
//Mount GetCurrentMountPoint();
|
||||
|
||||
Mount::Type CurrentMountType();
|
||||
bool CurrentMountIsParam(Mount::Param p);
|
||||
bool CurrentMountIsParam(Mount::Param p, int * first_arg);
|
||||
|
||||
void MountCmsForRoot();
|
||||
|
||||
|
||||
|
|
161
core/request.cpp
161
core/request.cpp
|
@ -12,7 +12,7 @@
|
|||
#include "postparser.h"
|
||||
#include "cookieparser.h"
|
||||
#include "log.h"
|
||||
|
||||
#include "data.h"
|
||||
|
||||
|
||||
Request::Request() : char_empty(0)
|
||||
|
@ -66,7 +66,10 @@ void Request::Clear()
|
|||
|
||||
status = Error::ok;
|
||||
|
||||
is_thread = false;
|
||||
thread.Clear();
|
||||
|
||||
thread_tab.clear();
|
||||
}
|
||||
|
||||
|
||||
|
@ -491,4 +494,160 @@ bool Request::HasReadExecAccess(const Item & item)
|
|||
}
|
||||
|
||||
|
||||
// returning true if we can create a thread in the current directory
|
||||
bool Request::CanCreateThread(bool check_root)
|
||||
{
|
||||
if( request.dir_table.empty() )
|
||||
return false;
|
||||
|
||||
if( request.is_item )
|
||||
return false;
|
||||
|
||||
if( !HasWriteAccess(*request.dir_table.back()) )
|
||||
return false;
|
||||
|
||||
if( data.mounts.CurrentMountType() != Mount::thread )
|
||||
return false;
|
||||
|
||||
if( !check_root && session && session->puser && session->puser->super_user )
|
||||
// super can create thread regardless of the restrictcreatethread option
|
||||
return true;
|
||||
|
||||
|
||||
// !! w przyszlosci mozna odczytywac wiecej parametrow od restrictcreatethread
|
||||
// tymczasowo wykorzystujemy tylko pierwszy
|
||||
int level;
|
||||
if( data.mounts.CurrentMountIsParam(Mount::restrictcreatethread, &level) )
|
||||
{
|
||||
if( level == -1 )
|
||||
return false;
|
||||
|
||||
// we can only allow on a specific level
|
||||
if( int(request.dir_table.size()) != level )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Request::CanRemove(const Item & item)
|
||||
{
|
||||
if( item.parent_id == -1 )
|
||||
{
|
||||
// rm for the root dir
|
||||
// only the superuser can do it
|
||||
if( !request.session->puser || !request.session->puser->super_user )
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Item * last_but_one_dir = data.dirs.GetDir(item.parent_id);
|
||||
|
||||
if( !last_but_one_dir )
|
||||
// ops, there is no a parent dir
|
||||
return false;
|
||||
|
||||
if( !request.HasWriteAccess(*last_but_one_dir) )
|
||||
return false;
|
||||
}
|
||||
|
||||
if( data.mounts.CurrentMountIsParam(Mount::only_root_can_remove) )
|
||||
// this can be deleted only be a root
|
||||
if( !request.session->puser || !request.session->puser->super_user )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Request::CanUseEmacs(const Item & item, bool check_root)
|
||||
{
|
||||
if( !check_root && request.session->puser && request.session->puser->super_user )
|
||||
// super user can use emacs everywhere
|
||||
return true;
|
||||
|
||||
if( !request.HasWriteAccess(item) )
|
||||
return false;
|
||||
|
||||
int level;
|
||||
if( data.mounts.CurrentMountIsParam(Mount::can_use_emacs_on, &level) )
|
||||
if( level != int(request.dir_table.size()) )
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Request::CanUseMkdir(const Item & item, bool check_root)
|
||||
{
|
||||
// you can create a directory only in a directory
|
||||
if( item.type != Item::dir )
|
||||
return false;
|
||||
|
||||
if( !check_root && request.session->puser && request.session->puser->super_user )
|
||||
// super user can use mkdir everywhere
|
||||
return true;
|
||||
|
||||
if( !request.HasWriteAccess(item) )
|
||||
return false;
|
||||
|
||||
int level;
|
||||
if( data.mounts.CurrentMountIsParam(Mount::can_use_mkdir_on, &level) )
|
||||
if( level != int(request.dir_table.size()) )
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Request::CanUseHtml(long user_id)
|
||||
{
|
||||
User * puser = data.users.GetUser(user_id);
|
||||
|
||||
if( !puser )
|
||||
return false;
|
||||
|
||||
if( puser->super_user )
|
||||
// super user can use html
|
||||
return true;
|
||||
|
||||
long group = data.groups.GetGroupId("allow_html");
|
||||
|
||||
if( group == -1 )
|
||||
// there is no such a group
|
||||
return false;
|
||||
|
||||
if( puser->IsMemberOf(group) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Request::CanUseBBCode(long user_id)
|
||||
{
|
||||
User * puser = data.users.GetUser(user_id);
|
||||
|
||||
if( !puser )
|
||||
return false;
|
||||
|
||||
if( puser->super_user )
|
||||
// super user can use bbcode
|
||||
return true;
|
||||
|
||||
long group = data.groups.GetGroupId("allow_bbcode");
|
||||
|
||||
if( group == -1 )
|
||||
// there is no such a group
|
||||
return false;
|
||||
|
||||
if( puser->IsMemberOf(group) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -111,8 +111,12 @@ struct Request
|
|||
//std::vector<Item> dir_table2;
|
||||
|
||||
// current thread (if exists)
|
||||
|
||||
bool is_thread;
|
||||
Thread thread;
|
||||
|
||||
std::vector<Thread> thread_tab;
|
||||
|
||||
// this string is used for many purposes such as redirecting
|
||||
std::string str;
|
||||
|
||||
|
@ -156,7 +160,13 @@ struct Request
|
|||
bool HasReadWriteAccess(const Item & item);
|
||||
bool HasReadExecAccess(const Item & item);
|
||||
|
||||
bool CanCreateThread(bool check_root = false);
|
||||
bool CanRemove(const Item & item);
|
||||
bool CanUseEmacs(const Item & item, bool check_root = false);
|
||||
bool CanUseMkdir(const Item & item, bool check_root = false);
|
||||
|
||||
bool CanUseHtml(long user_id);
|
||||
bool CanUseBBCode(long user_id);
|
||||
|
||||
private:
|
||||
// used to set some env_* variables into it, when the server didn't set that variable
|
||||
|
|
|
@ -19,17 +19,26 @@ class Thread
|
|||
public:
|
||||
|
||||
long id;
|
||||
|
||||
// !! parent_id potrzebne w ogole jest?
|
||||
long parent_id;
|
||||
|
||||
long dir_id;
|
||||
std::string subject;
|
||||
bool closed;
|
||||
|
||||
// how many items there are inside
|
||||
long items;
|
||||
|
||||
// last item in the directory (this variable is mainly for reading)
|
||||
// at the moment only used: id, date_modification, user_id
|
||||
Item last_item;
|
||||
|
||||
void Clear()
|
||||
{
|
||||
id = dir_id = -1;
|
||||
id = parent_id = dir_id = -1;
|
||||
last_item.Clear();
|
||||
closed = false;
|
||||
subject.clear();
|
||||
items = 0;
|
||||
}
|
||||
|
||||
Thread()
|
||||
|
|
|
@ -37,6 +37,12 @@ last.o: ../core/group.h ../core/functions.h ../core/function.h
|
|||
last.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
|
||||
last.o: ../core/request.h ../core/requesttypes.h ../core/session.h
|
||||
last.o: ../core/done.h ../core/error.h ../core/thread.h ../core/misc.h
|
||||
mount.o: templates.h ../../ezc/src/ezc.h patterncacher.h ../core/item.h
|
||||
mount.o: ../app/templates.h ../core/data.h ../core/dirs.h ../core/item.h
|
||||
mount.o: ../core/dircontainer.h ../core/users.h ../core/user.h
|
||||
mount.o: ../core/ugcontainer.h ../core/log.h ../core/groups.h ../core/group.h
|
||||
mount.o: ../core/functions.h ../core/function.h ../core/lastcontainer.h
|
||||
mount.o: ../core/mounts.h ../core/mount.h
|
||||
patterncacher.o: patterncacher.h ../core/item.h ../../ezc/src/ezc.h
|
||||
patterncacher.o: ../core/data.h ../core/dirs.h ../core/item.h
|
||||
patterncacher.o: ../core/dircontainer.h ../core/users.h ../core/user.h
|
||||
|
@ -88,7 +94,7 @@ who.o: templates.h ../../ezc/src/ezc.h patterncacher.h ../core/item.h
|
|||
who.o: ../app/templates.h ../core/sessioncontainer.h ../core/session.h
|
||||
who.o: ../core/done.h ../core/item.h ../core/error.h ../core/log.h
|
||||
who.o: ../core/user.h ../core/requestcontroller.h ../content/content.h
|
||||
who.o: ../templates/templates.h ../core/sessionmanager.h
|
||||
who.o: ../templates/templates.h ../core/thread.h ../core/sessionmanager.h
|
||||
who.o: ../core/sessioncontainer.h ../core/functionparser.h
|
||||
who.o: ../core/requesttypes.h ../app/content.h ../core/data.h ../core/dirs.h
|
||||
who.o: ../core/dircontainer.h ../core/users.h ../core/ugcontainer.h
|
||||
|
|
|
@ -1 +1 @@
|
|||
o = dir.o doc.o done.o item.o last.o patterncacher.o priv.o sys.o templates.o thread.o user.o who.o
|
||||
o = dir.o doc.o done.o item.o last.o mount.o patterncacher.o priv.o sys.o templates.o thread.o user.o who.o
|
||||
|
|
|
@ -31,7 +31,8 @@ void dir(Info & i)
|
|||
}
|
||||
|
||||
|
||||
|
||||
//!! moze wystarczy sprawdzac tylko ostatni katalog?
|
||||
// bo inaczej i tak bylo by 'access denied'
|
||||
void dir_can_read_exec(Info & i)
|
||||
{
|
||||
bool result = true;
|
||||
|
@ -49,6 +50,52 @@ bool result = true;
|
|||
}
|
||||
|
||||
|
||||
void dir_can_write(Info & i)
|
||||
{
|
||||
i.result = request.HasWriteAccess(*request.dir_table.back());
|
||||
}
|
||||
|
||||
|
||||
void dir_can_remove(Info & i)
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
|
||||
if( request.dir_table.size() == 1 )
|
||||
{
|
||||
// rm for the root dir
|
||||
// only the superuser can do it
|
||||
if( !request.session->puser || !request.session->puser->super_user )
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Item * last_but_one_dir = *(--(--request.dir_table.end()));
|
||||
|
||||
if( !request.HasWriteAccess(*last_but_one_dir) )
|
||||
result = false;
|
||||
}
|
||||
|
||||
i.result = result;
|
||||
}
|
||||
|
||||
|
||||
void dir_can_use_emacs(Info & i)
|
||||
{
|
||||
if( !request.dir_table.empty() )
|
||||
i.result = request.CanUseEmacs(*request.dir_table.back(), true);
|
||||
else
|
||||
i.result = false;
|
||||
}
|
||||
|
||||
|
||||
void dir_can_use_mkdir(Info & i)
|
||||
{
|
||||
if( !request.dir_table.empty() )
|
||||
i.result = request.CanUseMkdir(*request.dir_table.back(), true);
|
||||
else
|
||||
i.result = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -133,7 +180,6 @@ void dir_last_default_item_init()
|
|||
dir_last_default_item_reqid = request.id;
|
||||
|
||||
dir_last_default_item.Clear();
|
||||
log << "inicjalizacja dir_last_default_item" << logend;
|
||||
|
||||
if( request.dir_table.empty() )
|
||||
return;
|
||||
|
@ -174,6 +220,12 @@ void dir_last_default_item_url(Info & i)
|
|||
}
|
||||
|
||||
|
||||
void dir_last_subject(Info & i)
|
||||
{
|
||||
HtmlEscape(i.out, request.dir_table.back()->subject);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void dir_old(Info & i)
|
||||
{
|
||||
|
@ -184,6 +236,8 @@ void dir_old(Info & i)
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ void doc_title(Info & i)
|
|||
|
||||
// from 1 means skipping the root directory
|
||||
for(a = 1 ; a<request.dir_table.size() ; ++a)
|
||||
i.out << " / " << request.dir_table[a]->url;
|
||||
i.out << " / " << request.dir_table[a]->subject;
|
||||
|
||||
if( request.is_item )
|
||||
i.out << " / " << request.item.subject;
|
||||
|
|
|
@ -63,6 +63,36 @@ void item_content_noescape(Info & i)
|
|||
}
|
||||
|
||||
|
||||
void item_print_content(Info & i)
|
||||
{
|
||||
if( request.item.content_type == 0 ) // simple txt
|
||||
{
|
||||
HtmlEscape(i.out, request.item.content);
|
||||
}
|
||||
else
|
||||
if( request.item.content_type == 1 ) // formatted txt
|
||||
{
|
||||
HtmlEscapeFormTxt(i.out, request.item.content);
|
||||
}
|
||||
else
|
||||
if( request.item.content_type == 2 ) // html
|
||||
{
|
||||
if( request.CanUseHtml(request.item.user_id) )
|
||||
i.out << request.item.content;
|
||||
else
|
||||
HtmlEscape(i.out, request.item.content);
|
||||
}
|
||||
else
|
||||
if( request.item.content_type == 3 ) // bbcode
|
||||
{
|
||||
if( request.CanUseBBCode(request.item.user_id) )
|
||||
HtmlEscape(i.out, request.item.content); // tutaj bedzie parsowanie bbcodu i tworzenie odpowiadajacego mu html-a
|
||||
else
|
||||
i.out << request.item.content;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void item_privileges(Info & i)
|
||||
{
|
||||
i.out << std::setbase(8) << request.item.privileges << std::setbase(10);
|
||||
|
@ -96,6 +126,11 @@ void item_can_read(Info & i)
|
|||
i.result = true;
|
||||
}
|
||||
|
||||
void item_can_write(Info & i)
|
||||
{
|
||||
if( request.HasWriteAccess(request.item) )
|
||||
i.result = true;
|
||||
}
|
||||
|
||||
void item_info(Info & i)
|
||||
{
|
||||
|
@ -111,7 +146,7 @@ void item_user(Info & i)
|
|||
if( puser )
|
||||
HtmlEscape(i.out, puser->name);
|
||||
else
|
||||
i.out << "unknown";
|
||||
i.out << "~guest"; // !! dodac do konfiga
|
||||
}
|
||||
|
||||
|
||||
|
@ -278,6 +313,41 @@ void item_tab_content_noescape(Info & i)
|
|||
}
|
||||
|
||||
|
||||
void item_tab_print_content(Info & i)
|
||||
{
|
||||
if( item_index >= request.item_table.size() )
|
||||
return;
|
||||
|
||||
int type = request.item_table[item_index].content_type;
|
||||
|
||||
if( type == 0 ) // simple txt
|
||||
{
|
||||
HtmlEscape(i.out, request.item_table[item_index].content);
|
||||
}
|
||||
else
|
||||
if( type == 1 ) // formatted txt
|
||||
{
|
||||
HtmlEscapeFormTxt(i.out, request.item_table[item_index].content);
|
||||
}
|
||||
else
|
||||
if( type == 2 ) // html
|
||||
{
|
||||
if( request.CanUseHtml(request.item_table[item_index].user_id) )
|
||||
i.out << request.item_table[item_index].content;
|
||||
else
|
||||
HtmlEscape(i.out, request.item_table[item_index].content);
|
||||
}
|
||||
else
|
||||
if( type == 3 ) // bbcode
|
||||
{
|
||||
if( request.CanUseBBCode(request.item_table[item_index].user_id) )
|
||||
HtmlEscape(i.out, request.item_table[item_index].content); // tutaj bedzie parsowanie bbcodu i tworzenie odpowiadajacego mu html-a
|
||||
else
|
||||
i.out << request.item_table[item_index].content;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void item_tab_privileges(Info & i)
|
||||
{
|
||||
if( item_index < request.item_table.size() )
|
||||
|
@ -343,7 +413,7 @@ void item_tab_user(Info & i)
|
|||
if( puser )
|
||||
HtmlEscape(i.out, puser->name);
|
||||
else
|
||||
i.out << "unknown";
|
||||
i.out << "~guest"; // !! dodac do konfiga
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2009, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
#include "../core/data.h"
|
||||
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
void mount_param_withheader(Info & i)
|
||||
{
|
||||
i.result = data.mounts.CurrentMountIsParam(Mount::withheader);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void mount_param_withinfo(Info & i)
|
||||
{
|
||||
i.result = data.mounts.CurrentMountIsParam(Mount::withinfo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ static size_t priv_user_reqid = 0;
|
|||
|
||||
|
||||
|
||||
void priv_user_tab_init()
|
||||
void priv_user_tab_init(Item & item)
|
||||
{
|
||||
priv_user_reqid = request.id;
|
||||
priv_user_table.clear();
|
||||
|
@ -33,7 +33,7 @@ void priv_user_tab_init()
|
|||
if( !request.session->puser )
|
||||
{
|
||||
// not logged
|
||||
priv_user_table.push_back(request.item.user_id);
|
||||
priv_user_table.push_back(item.user_id);
|
||||
}
|
||||
else
|
||||
if( request.session->puser->super_user )
|
||||
|
@ -48,11 +48,20 @@ void priv_user_tab_init()
|
|||
else
|
||||
{
|
||||
// others
|
||||
priv_user_table.push_back(request.item.user_id);
|
||||
priv_user_table.push_back(item.user_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void priv_user_tab_init()
|
||||
{
|
||||
if( request.is_item )
|
||||
priv_user_tab_init(request.item);
|
||||
else
|
||||
priv_user_tab_init(*request.dir_table.back());
|
||||
}
|
||||
|
||||
|
||||
void priv_user_tab(Info & i)
|
||||
{
|
||||
if( priv_user_reqid != request.id )
|
||||
|
@ -95,8 +104,16 @@ void priv_user_tab_isdefault(Info & i)
|
|||
{
|
||||
long uid = priv_user_table[priv_user_index];
|
||||
|
||||
if( uid == request.item.user_id )
|
||||
i.result = true;
|
||||
if( request.is_item )
|
||||
{
|
||||
if( uid == request.item.user_id )
|
||||
i.result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( uid == request.dir_table.back()->user_id )
|
||||
i.result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,7 +130,7 @@ static size_t priv_group_reqid = 0;
|
|||
|
||||
|
||||
|
||||
void priv_group_tab_init()
|
||||
void priv_group_tab_init(Item & item)
|
||||
{
|
||||
priv_group_reqid = request.id;
|
||||
priv_group_table.clear();
|
||||
|
@ -121,7 +138,7 @@ void priv_group_tab_init()
|
|||
if( !request.session->puser )
|
||||
{
|
||||
// not logged
|
||||
priv_group_table.push_back(request.item.group_id);
|
||||
priv_group_table.push_back(item.group_id);
|
||||
}
|
||||
else
|
||||
if( request.session->puser->super_user )
|
||||
|
@ -134,7 +151,7 @@ void priv_group_tab_init()
|
|||
priv_group_table.push_back(-1);
|
||||
}
|
||||
else
|
||||
if( request.session->puser->id == request.item.user_id )
|
||||
if( request.session->puser->id == item.user_id )
|
||||
{
|
||||
bool was_current_group = false;
|
||||
// owner of the item -- is allowed to change only to a group in which he belongs to
|
||||
|
@ -142,13 +159,13 @@ void priv_group_tab_init()
|
|||
{
|
||||
priv_group_table.push_back( request.session->puser->groups[i] );
|
||||
|
||||
if( request.item.group_id == request.session->puser->groups[i] )
|
||||
if( item.group_id == request.session->puser->groups[i] )
|
||||
was_current_group = true;
|
||||
}
|
||||
|
||||
// we're showing the item.group_id if it's different
|
||||
if( !was_current_group )
|
||||
priv_group_table.push_back(request.item.group_id);
|
||||
priv_group_table.push_back(item.group_id);
|
||||
|
||||
// switching to -1 is allowed too
|
||||
priv_group_table.push_back(-1);
|
||||
|
@ -156,11 +173,20 @@ void priv_group_tab_init()
|
|||
else
|
||||
{
|
||||
// not the owner and not a super user -- the same as not logged
|
||||
priv_group_table.push_back(request.item.group_id);
|
||||
priv_group_table.push_back(item.group_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void priv_group_tab_init()
|
||||
{
|
||||
if( request.is_item )
|
||||
priv_group_tab_init(request.item);
|
||||
else
|
||||
priv_group_tab_init(*request.dir_table.back());
|
||||
}
|
||||
|
||||
|
||||
void priv_group_tab(Info & i)
|
||||
{
|
||||
if( priv_group_reqid != request.id )
|
||||
|
@ -203,12 +229,28 @@ void priv_group_tab_isdefault(Info & i)
|
|||
{
|
||||
long gid = priv_group_table[priv_group_index];
|
||||
|
||||
if( gid == request.item.group_id )
|
||||
i.result = true;
|
||||
if( request.is_item )
|
||||
{
|
||||
if( gid == request.item.group_id )
|
||||
i.result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( gid == request.dir_table.back()->group_id )
|
||||
i.result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void priv_privileges(Info & i)
|
||||
{
|
||||
if( request.is_item )
|
||||
i.out << std::setbase(8) << request.item.privileges << std::setbase(10);
|
||||
else
|
||||
i.out << std::setbase(8) << request.dir_table.back()->privileges << std::setbase(10);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -145,6 +145,9 @@ Ezc::Pattern * p = 0;
|
|||
break;
|
||||
|
||||
case Error::permision_denied:
|
||||
case Error::cant_change_user:
|
||||
case Error::cant_change_group:
|
||||
case Error::cant_change_privileges:
|
||||
p = &pat_err_per_denied;
|
||||
break;
|
||||
|
||||
|
@ -216,11 +219,13 @@ void Templates::CreateFunctions()
|
|||
functions.Insert("item_subject_noescape", item_subject_noescape);
|
||||
functions.Insert("item_content", item_content);
|
||||
functions.Insert("item_content_noescape", item_content_noescape);
|
||||
functions.Insert("item_print_content", item_print_content);
|
||||
functions.Insert("item_privileges", item_privileges);
|
||||
functions.Insert("item_dir", item_dir);
|
||||
functions.Insert("item_url", item_url);
|
||||
functions.Insert("item_link", item_link);
|
||||
functions.Insert("item_can_read", item_can_read);
|
||||
functions.Insert("item_can_write", item_can_write);
|
||||
functions.Insert("item_info", item_info);
|
||||
functions.Insert("item_user", item_user);
|
||||
functions.Insert("item_date_creation", item_date_creation);
|
||||
|
@ -244,6 +249,7 @@ void Templates::CreateFunctions()
|
|||
functions.Insert("item_tab_subject_noescape", item_tab_subject_noescape);
|
||||
functions.Insert("item_tab_content", item_tab_content);
|
||||
functions.Insert("item_tab_content_noescape", item_tab_content_noescape);
|
||||
functions.Insert("item_tab_print_content", item_tab_print_content);
|
||||
functions.Insert("item_tab_privileges", item_tab_privileges);
|
||||
functions.Insert("item_tab_dir", item_tab_dir);
|
||||
functions.Insert("item_tab_url", item_tab_url);
|
||||
|
@ -262,6 +268,10 @@ void Templates::CreateFunctions()
|
|||
*/
|
||||
functions.Insert("dir", dir);
|
||||
functions.Insert("dir_can_read_exec", dir_can_read_exec);
|
||||
functions.Insert("dir_can_write", dir_can_write);
|
||||
functions.Insert("dir_can_remove", dir_can_remove);
|
||||
functions.Insert("dir_can_use_emacs", dir_can_use_emacs);
|
||||
functions.Insert("dir_can_use_mkdir", dir_can_use_mkdir);
|
||||
|
||||
functions.Insert("dir_childs_tab", dir_childs_tab);
|
||||
functions.Insert("dir_childs_tab_url", dir_childs_tab_url);
|
||||
|
@ -272,6 +282,7 @@ void Templates::CreateFunctions()
|
|||
|
||||
functions.Insert("dir_last_default_item_dir", dir_last_default_item_dir);
|
||||
functions.Insert("dir_last_default_item_url", dir_last_default_item_url);
|
||||
functions.Insert("dir_last_subject", dir_last_subject);
|
||||
|
||||
functions.Insert("dir_old", dir_old);
|
||||
|
||||
|
@ -294,6 +305,8 @@ void Templates::CreateFunctions()
|
|||
functions.Insert("priv_group_tab_name", priv_group_tab_name);
|
||||
functions.Insert("priv_group_tab_isdefault", priv_group_tab_isdefault);
|
||||
|
||||
functions.Insert("priv_privileges", priv_privileges);
|
||||
|
||||
|
||||
/*
|
||||
done
|
||||
|
@ -341,7 +354,24 @@ void Templates::CreateFunctions()
|
|||
/*
|
||||
thread
|
||||
*/
|
||||
functions.Insert("thread_subject", thread_subject);
|
||||
functions.Insert("thread_is", thread_is);
|
||||
functions.Insert("thread_subject", thread_subject);
|
||||
functions.Insert("thread_show_edit_subject", thread_show_edit_subject);
|
||||
functions.Insert("thread_tab", thread_tab);
|
||||
functions.Insert("thread_tab_url", thread_tab_url);
|
||||
functions.Insert("thread_tab_subject", thread_tab_subject);
|
||||
functions.Insert("thread_tab_author", thread_tab_author);
|
||||
functions.Insert("thread_tab_answers", thread_tab_answers);
|
||||
functions.Insert("thread_tab_last_item_date_modification", thread_tab_last_item_date_modification);
|
||||
functions.Insert("thread_tab_last_item_user", thread_tab_last_item_user);
|
||||
functions.Insert("thread_can_create", thread_can_create);
|
||||
|
||||
|
||||
/*
|
||||
mount
|
||||
*/
|
||||
functions.Insert("mount_param_withheader", mount_param_withheader);
|
||||
functions.Insert("mount_param_withinfo", mount_param_withinfo);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@ namespace TemplatesFunctions
|
|||
{
|
||||
using Ezc::Info;
|
||||
|
||||
extern bool thread_show_edit_subject_var;
|
||||
|
||||
extern PatternCacher pattern_cacher;
|
||||
extern Ezc::Functions functions;
|
||||
extern Ezc::Pattern pat_item_info;
|
||||
|
@ -60,11 +62,13 @@ namespace TemplatesFunctions
|
|||
void item_subject_noescape(Info & i);
|
||||
void item_content(Info & i);
|
||||
void item_content_noescape(Info & i);
|
||||
void item_print_content(Info & i);
|
||||
void item_privileges(Info & i);
|
||||
void item_dir(Info & i); // the same as full_dir()
|
||||
void item_url(Info & i);
|
||||
void item_link(Info & i);
|
||||
void item_can_read(Info & i);
|
||||
void item_can_write(Info & i);
|
||||
void item_info(Info & i);
|
||||
void item_user(Info & i);
|
||||
void item_date_creation(Info & i);
|
||||
|
@ -89,6 +93,7 @@ namespace TemplatesFunctions
|
|||
void item_tab_subject_noescape(Info & i);
|
||||
void item_tab_content(Info & i);
|
||||
void item_tab_content_noescape(Info & i);
|
||||
void item_tab_print_content(Info & i);
|
||||
void item_tab_privileges(Info & i);
|
||||
void item_tab_dir(Info & i);
|
||||
void item_tab_url(Info & i);
|
||||
|
@ -107,6 +112,10 @@ namespace TemplatesFunctions
|
|||
*/
|
||||
void dir(Info & i);
|
||||
void dir_can_read_exec(Info & i);
|
||||
void dir_can_write(Info & i);
|
||||
void dir_can_remove(Info & i);
|
||||
void dir_can_use_emacs(Info & i);
|
||||
void dir_can_use_mkdir(Info & i);
|
||||
|
||||
void dir_childs_tab(Info & i);
|
||||
void dir_childs_tab_url(Info & i);
|
||||
|
@ -117,7 +126,8 @@ namespace TemplatesFunctions
|
|||
|
||||
void dir_last_default_item_dir(Info &);
|
||||
void dir_last_default_item_url(Info & i);
|
||||
|
||||
void dir_last_subject(Info & i);
|
||||
|
||||
void dir_old(Info & i);
|
||||
|
||||
|
||||
|
@ -140,7 +150,7 @@ namespace TemplatesFunctions
|
|||
void priv_group_tab_name(Info & i);
|
||||
void priv_group_tab_isdefault(Info & i);
|
||||
|
||||
|
||||
void priv_privileges(Info & i);
|
||||
|
||||
/*
|
||||
done
|
||||
|
@ -185,8 +195,23 @@ namespace TemplatesFunctions
|
|||
/*
|
||||
thread
|
||||
*/
|
||||
void thread_is(Info & i);
|
||||
void thread_show_edit_subject(Info & i);
|
||||
void thread_subject(Info & i);
|
||||
void thread_tab(Info & i);
|
||||
void thread_tab_url(Info & i);
|
||||
void thread_tab_subject(Info & i);
|
||||
void thread_tab_author(Info & i);
|
||||
void thread_tab_answers(Info & i);
|
||||
void thread_tab_last_item_date_modification(Info & i);
|
||||
void thread_tab_last_item_user(Info & i);
|
||||
void thread_can_create(Info & i);
|
||||
|
||||
/*
|
||||
mount
|
||||
*/
|
||||
void mount_param_withheader(Info & i);
|
||||
void mount_param_withinfo(Info & i);
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
|
|
@ -17,10 +17,160 @@
|
|||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
void thread_is(Info & i)
|
||||
{
|
||||
i.result = request.is_thread;
|
||||
}
|
||||
|
||||
|
||||
bool thread_show_edit_subject_var = false; // !! tymczasowe rozwiazanie, cos lepszego wymyslec
|
||||
|
||||
|
||||
void thread_show_edit_subject(Info & i)
|
||||
{
|
||||
i.result = thread_show_edit_subject_var;
|
||||
|
||||
thread_show_edit_subject_var = false;
|
||||
}
|
||||
|
||||
|
||||
void thread_subject(Info & i)
|
||||
{
|
||||
HtmlEscape(i.out, request.thread.subject);
|
||||
Item * dir = data.dirs.GetDir( request.thread.dir_id );
|
||||
|
||||
if( dir )
|
||||
{
|
||||
HtmlEscape(i.out, dir->subject);
|
||||
}
|
||||
else
|
||||
{
|
||||
i.out << "<!-- unknown subject -->";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static size_t thread_tab_index;
|
||||
|
||||
|
||||
|
||||
void thread_tab(Info & i)
|
||||
{
|
||||
thread_tab_index = i.iter;
|
||||
|
||||
i.result = thread_tab_index < request.thread_tab.size();
|
||||
}
|
||||
|
||||
|
||||
void thread_tab_url(Info & i)
|
||||
{
|
||||
if( thread_tab_index < request.thread_tab.size() )
|
||||
{
|
||||
Item * dir = data.dirs.GetDir( request.thread_tab[thread_tab_index].dir_id );
|
||||
|
||||
if( dir )
|
||||
{
|
||||
HtmlEscape(i.out, dir->url);
|
||||
}
|
||||
else
|
||||
{
|
||||
i.out << "<!-- unknown directory -->";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void thread_tab_subject(Info & i)
|
||||
{
|
||||
if( thread_tab_index < request.thread_tab.size() )
|
||||
{
|
||||
Item * dir = data.dirs.GetDir( request.thread_tab[thread_tab_index].dir_id );
|
||||
|
||||
if( dir )
|
||||
{
|
||||
HtmlEscape(i.out, dir->subject);
|
||||
}
|
||||
else
|
||||
{
|
||||
i.out << "<!-- unknown subject -->";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void thread_tab_answers(Info & i)
|
||||
{
|
||||
if( thread_tab_index < request.thread_tab.size() )
|
||||
{
|
||||
long a = request.thread_tab[thread_tab_index].items;
|
||||
|
||||
// the first is created by the author
|
||||
// we count only the rest
|
||||
if( a > 0 )
|
||||
--a;
|
||||
|
||||
i.out << a;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void thread_tab_author(Info & i)
|
||||
{
|
||||
bool unknown = true;
|
||||
|
||||
|
||||
if( thread_tab_index < request.thread_tab.size() )
|
||||
{
|
||||
Item * dir = data.dirs.GetDir( request.thread_tab[thread_tab_index].dir_id );
|
||||
|
||||
if( dir )
|
||||
{
|
||||
User * puser = data.users.GetUser(dir->user_id);
|
||||
unknown = false;
|
||||
|
||||
if( puser )
|
||||
HtmlEscape(i.out, puser->name);
|
||||
else
|
||||
HtmlEscape(i.out, "~guest"); // !! dodac to do data
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( unknown )
|
||||
{
|
||||
i.out << "<!-- unknown user -->";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void thread_tab_last_item_date_modification(Info & i)
|
||||
{
|
||||
if( thread_tab_index < request.thread_tab.size() )
|
||||
if( request.thread_tab[thread_tab_index].last_item.id != -1 )
|
||||
i.out << DateToStr( &request.thread_tab[thread_tab_index].last_item.date_modification );
|
||||
}
|
||||
|
||||
|
||||
void thread_tab_last_item_user(Info & i)
|
||||
{
|
||||
if( thread_tab_index < request.thread_tab.size() )
|
||||
{
|
||||
if( request.thread_tab[thread_tab_index].last_item.id != -1 )
|
||||
{
|
||||
User * puser = data.users.GetUser( request.thread_tab[thread_tab_index].last_item.user_id );
|
||||
|
||||
if( puser )
|
||||
HtmlEscape(i.out, puser->name);
|
||||
else
|
||||
HtmlEscape(i.out, "~guest"); // !! dodac to do data
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void thread_can_create(Info & i)
|
||||
{
|
||||
i.result = request.CanCreateThread(true);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue