winix/templatesnotify/templatesnotify.cpp

130 lines
2.2 KiB
C++
Executable File

/*
* 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 "templatesnotify.h"
#include "../core/misc.h"
#include "../core/locale.h"
#include "../core/data.h"
#include "../core/log.h"
namespace TemplatesNotifyFunctions
{
TemplatesMisc::Patterns patterns;
Ezc::Functions functions;
LocaleFilter locale_filter;
// you can use this pointer in template functions (will be always valid)
NotifyMsg * notify_msg;
} // namespace TemplatesNotifyFunctions
void TemplatesNotify::CreateFunctions()
{
using namespace TemplatesNotifyFunctions;
functions.Clear();
functions.Insert("notify_item_added", notify_item_added);
functions.Insert("notify_item_edited", notify_item_edited);
functions.Insert("notify_item_deleted", notify_item_deleted);
functions.Insert("notify_dir_added", notify_dir_added);
functions.Insert("notify_to", notify_to);
functions.Insert("notify_mount_type_is_thread", notify_mount_type_is_thread);
functions.Insert("notify_mount_type_is_cms", notify_mount_type_is_cms);
functions.Insert("notify_doc_base_url", notify_doc_base_url);
functions.Insert("notify_item_dir", notify_item_dir);
functions.Insert("notify_item_link", notify_item_link);
}
void TemplatesNotify::ClearPatterns()
{
using namespace TemplatesNotifyFunctions;
TemplatesMisc::ClearPatterns(patterns, pat_last);
}
// templates are read in the main thread
// (before creating the second thread)
void TemplatesNotify::Read()
{
using namespace TemplatesNotifyFunctions;
using namespace TemplatesMisc;
ClearPatterns();
TemplatesMisc::Read(patterns, pat_email_notify, locale_filter, "notify_email.txt", true);
notify_msg = 0;
}
void TemplatesNotify::Generate(Locale::Lang lang)
{
using namespace TemplatesNotifyFunctions;
notify_str.str("");
if( !notify_msg )
return;
if( static_cast<size_t>(lang) >= patterns.size() )
{
// ops, something wrong
return;
}
Ezc::Generator generator(notify_str, patterns[lang][pat_email_notify], functions);
generator.Generate();
}
TemplatesNotify::TemplatesNotify()
{
ClearPatterns();
}