2009-10-01 00:31:20 +02:00
|
|
|
/*
|
|
|
|
* 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"
|
2010-01-28 16:39:01 +01:00
|
|
|
#include "../core/locale.h"
|
|
|
|
#include "../core/data.h"
|
|
|
|
#include "../core/log.h"
|
|
|
|
|
2009-10-01 00:31:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace TemplatesNotifyFunctions
|
|
|
|
{
|
2010-01-28 16:39:01 +01:00
|
|
|
|
|
|
|
TemplatesMisc::Patterns patterns;
|
2009-10-01 00:31:20 +02:00
|
|
|
Ezc::Functions functions;
|
2010-02-15 01:31:14 +01:00
|
|
|
Locale locale;
|
2010-01-28 16:39:01 +01:00
|
|
|
LocaleFilter locale_filter;
|
|
|
|
|
2009-10-01 00:31:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
// you can use this pointer in template functions (will be always valid)
|
|
|
|
NotifyMsg * notify_msg;
|
|
|
|
|
|
|
|
|
2010-01-28 16:39:01 +01:00
|
|
|
} // namespace TemplatesNotifyFunctions
|
2009-10-01 00:31:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
2010-01-25 05:52:17 +01:00
|
|
|
functions.Insert("notify_mount_type_is_thread", notify_mount_type_is_thread);
|
|
|
|
functions.Insert("notify_mount_type_is_cms", notify_mount_type_is_cms);
|
2009-10-01 00:31:20 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-28 16:39:01 +01:00
|
|
|
void TemplatesNotify::ClearPatterns()
|
|
|
|
{
|
|
|
|
using namespace TemplatesNotifyFunctions;
|
2009-10-01 00:31:20 +02:00
|
|
|
|
2010-01-28 16:39:01 +01:00
|
|
|
|
|
|
|
TemplatesMisc::ClearPatterns(patterns, pat_last);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// templates are read in the main thread
|
|
|
|
// (before creating the second thread)
|
|
|
|
void TemplatesNotify::Read()
|
2009-10-01 00:31:20 +02:00
|
|
|
{
|
|
|
|
using namespace TemplatesNotifyFunctions;
|
2010-01-28 16:39:01 +01:00
|
|
|
using namespace TemplatesMisc;
|
2009-10-01 00:31:20 +02:00
|
|
|
|
2010-02-15 01:31:14 +01:00
|
|
|
Locale::Lang lang = Locale::StrToLang(data.locale_str);
|
2009-10-01 00:31:20 +02:00
|
|
|
|
2010-02-15 01:31:14 +01:00
|
|
|
if( lang != Locale::lang_unknown )
|
|
|
|
locale.SetLang(lang);
|
|
|
|
else
|
|
|
|
locale.SetLang(Locale::lang_en);
|
2010-01-28 16:39:01 +01:00
|
|
|
|
2010-02-15 01:31:14 +01:00
|
|
|
ClearPatterns();
|
|
|
|
locale.Read(data.locale_dir, data.locale_dir_default);
|
|
|
|
TemplatesMisc::Read(patterns, pat_email_notify, locale, locale_filter, "notify_email.txt", true);
|
2010-01-28 16:39:01 +01:00
|
|
|
|
2009-10-01 00:31:20 +02:00
|
|
|
notify_msg = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-28 16:39:01 +01:00
|
|
|
void TemplatesNotify::Generate(Locale::Lang lang)
|
2009-10-01 00:31:20 +02:00
|
|
|
{
|
|
|
|
using namespace TemplatesNotifyFunctions;
|
|
|
|
|
|
|
|
notify_str.str("");
|
|
|
|
|
|
|
|
if( !notify_msg )
|
|
|
|
return;
|
|
|
|
|
2010-01-28 16:39:01 +01:00
|
|
|
if( static_cast<size_t>(lang) >= patterns.size() )
|
|
|
|
{
|
|
|
|
// ops, something wrong
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ezc::Generator generator(notify_str, patterns[lang][pat_email_notify], functions);
|
2009-10-01 00:31:20 +02:00
|
|
|
generator.Generate();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-28 16:39:01 +01:00
|
|
|
TemplatesNotify::TemplatesNotify()
|
|
|
|
{
|
|
|
|
ClearPatterns();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|