135 lines
2.7 KiB
C++
Executable File
135 lines
2.7 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2010-2012, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#include "core/plugin.h"
|
|
#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";
|
|
files_dir = 0;
|
|
}
|
|
|
|
|
|
|
|
void Reply::SetTDb(TDb * ptdb)
|
|
{
|
|
tdb = ptdb;
|
|
}
|
|
|
|
|
|
void Reply::SetThreadInfo(ThreadInfo * pthread_info)
|
|
{
|
|
thread_info = pthread_info;
|
|
}
|
|
|
|
|
|
/*
|
|
we can use 'reply' function everywhere where 'thread_dir' mount option is defined
|
|
if there is no such a thread in 'thread' table it will be added automatically
|
|
*/
|
|
bool Reply::HasAccess()
|
|
{
|
|
if( !cur->request->is_item )
|
|
return false;
|
|
|
|
files_dir = thread_info->FindThreadDir();
|
|
|
|
if( !files_dir || !system->HasWriteAccess(*files_dir) )
|
|
return false;
|
|
|
|
|
|
PT::Space * thread_space = cur->request->item.ameta.FindSpace(L"thread");
|
|
|
|
if( thread_space )
|
|
{
|
|
if( thread_space->Bool(L"closed", false) )
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
void Reply::SendNotify(const Item & item)
|
|
{
|
|
// sending notification
|
|
notify_msg.code = WINIX_NOTIFY_CODE_REPLY;
|
|
notify_msg.template_index = thread_info->template_index;
|
|
notify_msg.dir_link = config->url_proto;
|
|
notify_msg.dir_link += config->base_url;// !! IMPROVE ME what about subdomains?
|
|
system->dirs.MakePath(item.parent_id, notify_msg.dir_link, false);
|
|
notify_msg.item_link = notify_msg.dir_link;
|
|
notify_msg.item_link += item.url;
|
|
|
|
system->notify.ItemChanged(notify_msg);
|
|
}
|
|
|
|
|
|
void Reply::MakePost()
|
|
{
|
|
// !! jak bedzie dostepne assert
|
|
// ASSERT(files_dir)
|
|
|
|
if( tdb->GetThread(cur->request->item.id, thread) != WINIX_ERR_OK )
|
|
{
|
|
thread.Clear();
|
|
thread.file_id = cur->request->item.id;
|
|
tdb->AddThread(thread);
|
|
}
|
|
|
|
answer.Clear();
|
|
answer.url = cur->request->item.url;
|
|
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 = files_dir->id;
|
|
answer.privileges = system->NewFilePrivileges();
|
|
|
|
if( functions->CheckAbuse() )
|
|
return;
|
|
|
|
plugin.Call(WINIX_PL_THREAD_PREPARE_TO_REPLY_IN_THREAD, &answer);
|
|
|
|
cur->request->status = system->AddFile(answer);
|
|
|
|
if( cur->request->status == WINIX_ERR_OK )
|
|
cur->request->status = tdb->AddAnswer(cur->request->item.id, answer.id);
|
|
|
|
|
|
if( cur->request->status == WINIX_ERR_OK )
|
|
{
|
|
log << log2 << "Reply: added an answer in a thread" << logend;
|
|
thread_info->MakeRedirectIfPossible(cur->request->item);
|
|
SendNotify(cur->request->item);
|
|
}
|
|
else
|
|
{
|
|
log << log1 << "Reply: problem with adding an answer, error code: "
|
|
<< cur->request->status << logend;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|