2011-01-20 19:37:51 +01:00
|
|
|
/*
|
|
|
|
* This file is a part of Winix
|
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010, Tomasz Sowa
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "reply.h"
|
|
|
|
#include "functions/functions.h"
|
|
|
|
#include "core/misc.h"
|
|
|
|
#include "core/plugin.h"
|
|
|
|
#include "pluginmsg.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Thread
|
|
|
|
{
|
|
|
|
|
|
|
|
Reply::Reply()
|
|
|
|
{
|
|
|
|
fun.url = L"reply";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Reply::SetTDb(TDb * ptdb)
|
|
|
|
{
|
|
|
|
tdb = ptdb;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Reply::SetThreadInfo(ThreadInfo * pthread_info)
|
|
|
|
{
|
|
|
|
thread_info = pthread_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Reply::HasAccess()
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
if( !cur->request->is_item )
|
2011-01-20 19:37:51 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
Item * dir = thread_info->FindThreadDir();
|
|
|
|
|
|
|
|
if( !dir || !system->HasWriteAccess(*dir) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
plugin.Call(WINIX_PL_THREAD_CAN_USE_REPLY);
|
|
|
|
|
|
|
|
if( plugin.True() > 0 )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if( system->mounts.pmount->type != thread_info->mount_type_thread )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Reply::MakePost()
|
|
|
|
{
|
|
|
|
Item * dir = thread_info->FindThreadDir();
|
|
|
|
|
|
|
|
if( !dir )
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
|
2011-01-20 19:37:51 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( tdb->GetThreadByFileId(cur->request->item.id, thread) != WINIX_ERR_OK )
|
2011-01-20 19:37:51 +01:00
|
|
|
{
|
|
|
|
thread.Clear();
|
2011-01-23 15:15:30 +01:00
|
|
|
thread.file_id = cur->request->item.id;
|
2011-01-20 19:37:51 +01:00
|
|
|
tdb->AddThread(thread);
|
|
|
|
}
|
|
|
|
|
|
|
|
answer.Clear();
|
2011-01-23 15:15:30 +01:00
|
|
|
answer.url = cur->request->item.url;
|
2011-01-20 19:37:51 +01:00
|
|
|
answer.url += L"_msg_";
|
|
|
|
answer.url += Toa(thread.replies + 1);
|
|
|
|
answer.subject = answer.url;
|
|
|
|
functions->ReadItem(answer, Item::file);
|
|
|
|
functions->SetUser(answer);
|
|
|
|
functions->PrepareUrl(answer);
|
|
|
|
answer.parent_id = dir->id;
|
|
|
|
answer.privileges = 0644; // !! tymczasowo
|
|
|
|
|
|
|
|
if( functions->CheckAbuse() )
|
|
|
|
return;
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->request->status = system->AddFile(answer);
|
2011-01-20 19:37:51 +01:00
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->status == WINIX_ERR_OK )
|
|
|
|
cur->request->status = tdb->EditThreadAddItem(cur->request->item.id, answer.id);
|
2011-01-20 19:37:51 +01:00
|
|
|
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->status == WINIX_ERR_OK )
|
2011-01-20 19:37:51 +01:00
|
|
|
{
|
|
|
|
log << log2 << "Reply: added an answer in a thread" << logend;
|
2011-01-23 15:15:30 +01:00
|
|
|
system->RedirectTo(cur->request->item);
|
2011-01-20 19:37:51 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
log << log1 << "Reply: problem with adding an answer, error code: "
|
2011-01-23 15:15:30 +01:00
|
|
|
<< cur->request->status << logend;
|
2011-01-20 19:37:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace
|