added: notifications to users' emails

(core/notify.h core/notify.cpp)
       templatesnotify directory
       all notifications are managed by a second thread


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@512 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2009-09-30 22:31:20 +00:00
parent 9902ce2b78
commit 85b678a8fb
30 changed files with 769 additions and 37 deletions

22
templatesnotify/Makefile Executable file
View File

@@ -0,0 +1,22 @@
include Makefile.o.dep
all: $(o)
.SUFFIXES: .cpp .o
.cpp.o:
$(CXX) -c $(CXXFLAGS) $<
depend:
makedepend $(DEPMACROS) -Y. -f- *.cpp > Makefile.dep
echo -n "o = " > Makefile.o.dep
ls -1 *.cpp | xargs -I foo echo -n foo " " | sed -E "s/([^\.]*)\.cpp[ ]/\1\.o/g" >> Makefile.o.dep
clean:
rm -f *.o
include Makefile.dep

6
templatesnotify/Makefile.dep Executable file
View File

@@ -0,0 +1,6 @@
# DO NOT DELETE
notify.o: templatesnotify.h ../core/mount.h ../../ezc/src/ezc.h
notify.o: ../core/notify.h ../templatesnotify/templatesnotify.h
templatesnotify.o: templatesnotify.h ../core/mount.h ../../ezc/src/ezc.h
templatesnotify.o: ../core/misc.h ../core/item.h

1
templatesnotify/Makefile.o.dep Executable file
View File

@@ -0,0 +1 @@
o = notify.o templatesnotify.o

89
templatesnotify/notify.cpp Executable file
View File

@@ -0,0 +1,89 @@
/*
* 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/notify.h"
namespace TemplatesNotifyFunctions
{
void notify_item_added(Info & i)
{
i.result = (notify_msg->notify_code & CMSLU_NOTIFY_ITEM_ADD) != 0;
}
void notify_item_edited(Info & i)
{
i.result = (notify_msg->notify_code & CMSLU_NOTIFY_ITEM_EDIT) != 0;
}
void notify_item_deleted(Info & i)
{
i.result = (notify_msg->notify_code & CMSLU_NOTIFY_ITEM_DELETE) != 0;
}
void notify_dir_added(Info & i)
{
i.result = (notify_msg->notify_code & CMSLU_NOTIFY_DIR_ADD) != 0;
}
void notify_to(Info & i)
{
i.out << notify_msg->email;
}
void notify_mount_is_thread(Info & i)
{
i.result = notify_msg->current_mount_type == Mount::thread;
}
void notify_mount_is_cms(Info & i)
{
i.result = notify_msg->current_mount_type == Mount::cms;
}
void notify_doc_base_url(Info & i)
{
i.out << notify_msg->doc_base_url;
}
void notify_item_dir(Info & i)
{
i.out << notify_msg->item_dir;
}
void notify_item_link(Info & i)
{
i.out << notify_msg->item_link;
}
} // namespace TemplatesNotifyFunctions

View File

@@ -0,0 +1,81 @@
/*
* 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"
namespace TemplatesNotifyFunctions
{
Ezc::Pattern pat_notify_email;
Ezc::Functions functions;
// 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_is_thread", notify_mount_is_thread);
functions.Insert("notify_mount_is_cms", notify_mount_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::Read(const std::string & templates_dir)
{
using namespace TemplatesNotifyFunctions;
pat_notify_email.Directory(templates_dir);
pat_notify_email.ParseFile("notify_email.txt");
CreateFunctions();
notify_msg = 0;
}
void TemplatesNotify::Generate()
{
using namespace TemplatesNotifyFunctions;
notify_str.str("");
if( !notify_msg )
return;
Ezc::Generator generator(notify_str, pat_notify_email, functions);
generator.Generate();
}

View File

@@ -0,0 +1,71 @@
/*
* 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.
*
*/
#ifndef headerfilecmslutemplatestemplatesnotify
#define headerfilecmslutemplatestemplatesnotify
#include <iomanip>
#include <set>
#include <string>
#include "../core/mount.h"
#include "../../ezc/src/ezc.h"
struct NotifyMsg
{
std::string email;
int notify_code;
Mount::Type current_mount_type;
std::string doc_base_url;
std::string item_dir;
std::string item_link;
};
namespace TemplatesNotifyFunctions
{
using Ezc::Info;
extern NotifyMsg * notify_msg;
void notify_item_added(Info & i);
void notify_item_edited(Info & i);
void notify_item_deleted(Info & i);
void notify_dir_added(Info & i);
void notify_to(Info & i);
void notify_mount_is_thread(Info & i);
void notify_mount_is_cms(Info & i);
void notify_doc_base_url(Info & i);
void notify_item_dir(Info & i);
void notify_item_link(Info & i);
} // namespace TemplatesNotifyFunctions
class TemplatesNotify
{
public:
void Read(const std::string & templates_dir);
void Generate();
std::ostringstream notify_str;
private:
void CreateFunctions();
};
#endif