moved some thread files to plugins/thread

git-svn-id: svn://ttmath.org/publicrep/winix/trunk@705 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2011-01-05 21:44:19 +00:00
parent 8154c403d8
commit 3fad25b8c8
18 changed files with 1175 additions and 1334 deletions

154
plugins/thread/createthread.cpp Executable file
View File

@@ -0,0 +1,154 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "createthread.h"
#include "functions.h"
namespace Thread
{
CreateThread::CreateThread()
{
fun.url = L"createthread";
}
// returning true if we can create a thread in the current directory
bool CreateThread::HasAccess(bool check_root)
{
if( request->dir_tab.empty() )
return false;
if( request->is_item )
return false;
if( !system->HasWriteAccess(*request->dir_tab.back()) )
return false;
if( !system->mounts.pmount || system->mounts.pmount->type != system->mounts.MountTypeThread() )
return false;
if( !check_root && request->session && request->session->puser && request->session->puser->super_user )
// super can create thread regardless of the restrictcreatethread option
return true;
if( !system->mounts.pmount->IsPar(system->mounts.MountParCreatethreadOn()) )
return true;
if( system->mounts.pmount->IsArg(system->mounts.MountParCreatethreadOn(), request->dir_tab.size()) )
return true;
return false;
}
bool CreateThread::HasAccess()
{
return HasAccess(false);
}
bool CreateThread::FunCreateThreadCheckAbuse()
{
if( !system->rebus.CheckRebus() )
{
request->status = WINIX_ERR_INCORRECT_REBUS;
return false;
}
functions->CheckGetPostTimes();
if( request->session->spam_score > 0 )
{
request->status = WINIX_ERR_SPAM;
log << log1 << "Content: ignoring due to suspected spamming" << logend;
return false;
}
return true;
}
void CreateThread::ReadThread()
{
thread.parent_id = request->dir_tab.back()->id;
}
void CreateThread::AddThread()
{
thread.dir_id = request->dir_tab.back()->id;
thread.closed = false;
thread.items = 1;
thread.last_item = request->item; // set by PostFunEmacsAdd()
request->status = db->AddThread(thread);
}
void CreateThread::PostFunCreateThreadLogAndRedirect()
{
if( request->status == WINIX_ERR_OK )
{
log << log2 << "Content: added a new thread" << logend;
system->RedirectToLastDir();
}
else
{
log << log1 << "Content: problem with adding a new thread, error code: "
<< request->status << logend;
}
}
void CreateThread::MakePost()
{
functions->ReadItem(request->item, Item::dir);
functions->SetUser(request->item);
ReadThread();
request->item.privileges = 0777; // !! tymczasowo 777 aby wszyscy mogli wysylac posty
if( !FunCreateThreadCheckAbuse() )
{
functions->ReadItemContentWithType(request->item); // for correctly displaying the form
return;
}
request->status = system->dirs.AddDirectory(request->item, true, 0, WINIX_NOTIFY_CODE_THREAD_ADD);
if( request->status == WINIX_ERR_OK )
{
functions->ReadItemContentWithType(request->item);
request->item.type = Item::file;
request->item.privileges = 0644; // !! tymczasowo
request->item.parent_id = request->dir_tab.back()->id;
request->status = system->AddFile(request->item);
if( request->status == WINIX_ERR_OK )
AddThread();
}
PostFunCreateThreadLogAndRedirect();
}
} // namespace

43
plugins/thread/createthread.h Executable file
View File

@@ -0,0 +1,43 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfile_winix_plugins_thread_createthread
#define headerfile_winix_plugins_thread_createthread
#include "functions/functionbase.h"
namespace Thread
{
class CreateThread : public FunctionBase
{
public:
CreateThread();
bool HasAccess(bool check_root);
bool HasAccess();
void MakePost();
private:
Thread thread;
bool FunCreateThreadCheckAbuse();
void ReadThread();
void AddThread();
void PostFunCreateThreadLogAndRedirect();
};
} // namespace
#endif

89
plugins/thread/funthread.cpp Executable file
View File

@@ -0,0 +1,89 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include <algorithm>
#include "core/misc.h"
#include "funthread.h"
namespace Thread
{
FunThread::FunThread()
{
fun.url = L"thread";
Clear();
}
bool FunThread::HasAccess()
{
return !request->is_item;
}
void FunThread::Clear()
{
thread.Clear();
thread_tab.clear();
}
void FunThread::CreateSortIndexByDate()
{
size_t i;
for(i = 0; i < thread_tab.size() ; ++i)
{
Item * pdir = system->dirs.GetDir(thread_tab[i].dir_id);
if( pdir )
thread_tab[i].sort = (unsigned long)Time(pdir->date_creation);
else
thread_tab[i].sort = 0;
}
}
bool FunThread::FunThreadSort(const Thread & t1, const Thread & t2)
{
return t1.sort > t2.sort;
}
void FunThread::MakeGet()
{
is_thread = (db->GetThreadByDirId(request->dir_tab.back()->id, thread) == WINIX_ERR_OK);
DbItemQuery iq;
if( system->mounts.pmount->IsArg(system->mounts.MountParThread(), L"sort_desc") )
iq.sort_asc = false;
iq.WhereParentId(request->dir_tab.back()->id);
iq.WhereType(Item::file);
iq.WhereFileType(WINIX_ITEM_FILETYPE_NONE);
db->GetItems(request->item_tab, iq);
db->GetThreads(request->dir_tab.back()->id, thread_tab);
system->CheckAccessToItems(request->item_tab);
CreateSortIndexByDate();
std::sort(thread_tab.begin(), thread_tab.end(), FunThreadSort);
Clear();
}
} // namespace

45
plugins/thread/funthread.h Executable file
View File

@@ -0,0 +1,45 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfile_winix_plugins_thread_funthread
#define headerfile_winix_plugins_thread_funthread
#include "functions/functionbase.h"
#include "core/thread.h"
namespace Thread
{
class FunThread : public FunctionBase
{
public:
FunThread();
bool HasAccess();
void MakeGet();
// current thread (if exists)
bool is_thread;
Thread thread;
std::vector<Thread> thread_tab;
private:
static bool FunThreadSort(const Thread & t1, const Thread & t2);
void CreateSortIndexByDate();
void Clear();
};
} // namespace
#endif

215
plugins/thread/templates.cpp Executable file
View File

@@ -0,0 +1,215 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "templates.h"
#include "misc.h"
#include "core/request.h"
#include "core/misc.h"
#include "functions/functions.h"
namespace Thread
{
using namespace TemplatesFunctions;
using TemplatesFunctions::system;
extern ThreadInfo thread_info;
extern FunThread fun_thread;
extern CreateThread fun_create_thread;
extern ShowThreads fun_show_threads;
void thread_is(Info & i)
{
i.res = functions->fun_thread.is_thread;
}
static size_t thread_tab_index;
void thread_tab(Info & i)
{
thread_tab_index = i.iter;
i.res = thread_tab_index < functions->fun_thread.thread_tab.size();
}
void thread_tab_url(Info & i)
{
if( thread_tab_index < functions->fun_thread.thread_tab.size() )
{
Item * dir = system->dirs.GetDir( functions->fun_thread.thread_tab[thread_tab_index].dir_id );
if( dir )
{
i.out << dir->url;
}
else
{
i.out << "<!-- unknown directory -->"; // !! do konfiga
}
}
}
void thread_tab_subject(Info & i)
{
if( thread_tab_index < functions->fun_thread.thread_tab.size() )
{
Item * dir = system->dirs.GetDir( functions->fun_thread.thread_tab[thread_tab_index].dir_id );
if( dir )
{
if( !dir->subject.empty() )
i.out << dir->subject;
else
i.out << dir->url;
}
else
{
i.out << "<!-- unknown subject -->"; // !! do konfiga
}
}
}
void thread_tab_answers(Info & i)
{
if( thread_tab_index < functions->fun_thread.thread_tab.size() )
{
long a = functions->fun_thread.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 < functions->fun_thread.thread_tab.size() )
{
Item * dir = system->dirs.GetDir( functions->fun_thread.thread_tab[thread_tab_index].dir_id );
if( dir )
{
User * puser = system->users.GetUser(dir->user_id);
unknown = false;
if( puser )
i.out << puser->name;
else
{
i.out << "~";
if( !dir->guest_name.empty() )
i.out << dir->guest_name;
else
i.out << "guest"; // !! dodac do konfiga
}
}
}
if( unknown )
{
i.out << "<!-- unknown user -->";
}
}
void thread_tab_last_item_date_modification(Info & i)
{
if( thread_tab_index < functions->fun_thread.thread_tab.size() )
if( functions->fun_thread.thread_tab[thread_tab_index].last_item.id != -1 )
i.out << DateToStr( &functions->fun_thread.thread_tab[thread_tab_index].last_item.date_modification );
}
void thread_tab_last_item_date_modification_nice(Info & i)
{
if( thread_tab_index < functions->fun_thread.thread_tab.size() )
if( functions->fun_thread.thread_tab[thread_tab_index].last_item.id != -1 )
print_date_nice(i, functions->fun_thread.thread_tab[thread_tab_index].last_item.date_modification);
}
void thread_tab_last_item_user(Info & i)
{
if( thread_tab_index < functions->fun_thread.thread_tab.size() )
{
if( functions->fun_thread.thread_tab[thread_tab_index].last_item.id != -1 )
{
User * puser = system->users.GetUser( functions->fun_thread.thread_tab[thread_tab_index].last_item.user_id );
if( puser )
i.out << puser->name;
else
{
i.out << "~";
if( !functions->fun_thread.thread_tab[thread_tab_index].last_item.guest_name.empty() )
i.out << functions->fun_thread.thread_tab[thread_tab_index].last_item.guest_name;
else
i.out << "guest"; // !! dodac do konfiga
}
}
}
}
void thread_can_create(Info & i)
{
i.res = functions->fun_createthread.HasAccess(true);
}
void AddEzcFunctions(PluginInfo & info)
{
using TemplatesFunctions::EzcFun;
EzcFun * fun = reinterpret_cast<EzcFun*>(info.p1);
fun->Insert("thread_is", thread_is);
fun->Insert("thread_tab", thread_tab);
fun->Insert("thread_tab_url", thread_tab_url);
fun->Insert("thread_tab_subject", thread_tab_subject);
fun->Insert("thread_tab_author", thread_tab_author);
fun->Insert("thread_tab_answers", thread_tab_answers);
fun->Insert("thread_tab_last_item_date_modification", thread_tab_last_item_date_modification);
fun->Insert("thread_tab_last_item_date_modification_nice", thread_tab_last_item_date_modification_nice);
fun->Insert("thread_tab_last_item_user", thread_tab_last_item_user);
fun->Insert("thread_can_create", thread_can_create);
}
} // namespace

65
plugins/thread/thread.h Executable file
View File

@@ -0,0 +1,65 @@
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2009-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfile_winix_plugins_thread_thread
#define headerfile_winix_plugins_thread_thread
#include <string>
namespace Thread
{
class Thread
{
public:
long file_id;
//long parent_id;
long dir_id;
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;
// used when sorting
unsigned long sort;
void Clear()
{
id = parent_id = dir_id = -1;
last_item.Clear();
closed = false;
items = 0;
sort = 0;
}
Thread()
{
Clear();
}
};
} // namespace
#endif