144 lines
2.3 KiB
C++
Executable File
144 lines
2.3 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2008-2011, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#include "notify.h"
|
|
#include "templates/templates.h"
|
|
#include "core/request.h"
|
|
#include "core/config.h"
|
|
#include "core/users.h"
|
|
#include "core/dirs.h"
|
|
#include "core/plugin.h"
|
|
|
|
|
|
|
|
|
|
Notify::Notify()
|
|
{
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Notify::SetCur(Cur * pcur)
|
|
{
|
|
cur = pcur;
|
|
}
|
|
|
|
|
|
void Notify::SetConfig(Config * pconfig)
|
|
{
|
|
config = pconfig;
|
|
}
|
|
|
|
|
|
void Notify::SetUsers(Users * pusers)
|
|
{
|
|
users = pusers;
|
|
}
|
|
|
|
void Notify::SetDirs(Dirs * pdirs)
|
|
{
|
|
dirs = pdirs;
|
|
}
|
|
|
|
void Notify::SetThreadManager(ThreadManager * pmanager)
|
|
{
|
|
thread_manager = pmanager;
|
|
}
|
|
|
|
|
|
void Notify::Init()
|
|
{
|
|
notify_thread.SetConfig(config);
|
|
notify_thread.SetUsers(users);
|
|
notify_thread.SetNotifyPool(¬ify_pool);
|
|
notify_thread.SetPatterns(&patterns);
|
|
thread_manager->Add(¬ify_thread);
|
|
|
|
patterns.SetUTF8(config->utf8);
|
|
patterns.SetDirectories(config->txt_templates_dir, config->txt_templates_dir_default);
|
|
patterns.SetLocale(&TemplatesFunctions::locale);
|
|
patterns.SetLocaleFilter(&TemplatesFunctions::locale_filter);
|
|
|
|
notify_template_cms = AddTemplate(L"notify_email_cms.txt");
|
|
|
|
plugin.Call(WINIX_NOTIFY_ADD_TEMPLATE);
|
|
}
|
|
|
|
|
|
|
|
void Notify::ReadTemplates()
|
|
{
|
|
patterns.Reload();
|
|
notify_thread.PatternsChanged();
|
|
}
|
|
|
|
|
|
|
|
|
|
void Notify::ItemChanged(int notify_code, const Item & item)
|
|
{
|
|
if( notify_code == 0 )
|
|
return;
|
|
|
|
msg.code = notify_code;
|
|
msg.template_index = notify_template_cms;
|
|
CreateItemLink(item, msg.item_link, msg.dir_link);
|
|
|
|
ItemChanged(msg);
|
|
}
|
|
|
|
|
|
|
|
// raw form
|
|
void Notify::ItemChanged(const NotifyMsg & msg)
|
|
{
|
|
notify_pool.Add(msg);
|
|
notify_thread.WakeUpThread(); // we are in the first locked thread
|
|
}
|
|
|
|
|
|
|
|
size_t Notify::AddTemplate(const std::wstring & file_name)
|
|
{
|
|
return patterns.Add(file_name, false);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Notify::CreateItemLink(const Item & item, std::wstring & item_link, std::wstring & dir_link)
|
|
{
|
|
static std::wstring tmp_path;
|
|
|
|
if( item.type == Item::dir )
|
|
{
|
|
dirs->MakePath(item.id, tmp_path);
|
|
item_link = config->url_proto;
|
|
item_link += config->base_url;
|
|
item_link += tmp_path;
|
|
dir_link = item_link;
|
|
}
|
|
else
|
|
{
|
|
dirs->MakePath(item.parent_id, tmp_path);
|
|
item_link = config->url_proto;
|
|
item_link += config->base_url;
|
|
item_link += tmp_path;
|
|
dir_link = item_link;
|
|
item_link += item.url;
|
|
}
|
|
}
|
|
|
|
|
|
|