2008-12-30 02:05:03 +01:00
|
|
|
/*
|
|
|
|
* This file is a part of CMSLU -- Content Management System like Unix
|
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
2009-04-21 22:50:55 +02:00
|
|
|
* Copyright (c) 2008-2009, Tomasz Sowa
|
2008-12-30 02:05:03 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "templates.h"
|
2009-04-21 22:50:55 +02:00
|
|
|
#include "../core/data.h"
|
|
|
|
#include "../core/request.h"
|
|
|
|
#include "../core/misc.h"
|
|
|
|
|
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
namespace TemplatesFunctions
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void item_is(Info & i)
|
|
|
|
{
|
|
|
|
i.result = request.is_item;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void item_id(Info & i)
|
|
|
|
{
|
|
|
|
i.out << request.item.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void item_subject(Info & i)
|
|
|
|
{
|
|
|
|
HtmlEscape(i.out, request.item.subject);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_subject_noescape(Info & i)
|
|
|
|
{
|
|
|
|
i.out << request.item.subject;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void item_content(Info & i)
|
|
|
|
{
|
|
|
|
HtmlEscape(i.out, request.item.content);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void item_content_noescape(Info & i)
|
|
|
|
{
|
|
|
|
i.out << request.item.content;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-05 22:29:06 +02:00
|
|
|
void item_print_content(Info & i)
|
|
|
|
{
|
|
|
|
if( request.item.content_type == 0 ) // simple txt
|
|
|
|
{
|
|
|
|
HtmlEscape(i.out, request.item.content);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( request.item.content_type == 1 ) // formatted txt
|
|
|
|
{
|
|
|
|
HtmlEscapeFormTxt(i.out, request.item.content);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( request.item.content_type == 2 ) // html
|
|
|
|
{
|
|
|
|
if( request.CanUseHtml(request.item.user_id) )
|
|
|
|
i.out << request.item.content;
|
|
|
|
else
|
|
|
|
HtmlEscape(i.out, request.item.content);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( request.item.content_type == 3 ) // bbcode
|
|
|
|
{
|
|
|
|
if( request.CanUseBBCode(request.item.user_id) )
|
|
|
|
HtmlEscape(i.out, request.item.content); // tutaj bedzie parsowanie bbcodu i tworzenie odpowiadajacego mu html-a
|
|
|
|
else
|
|
|
|
i.out << request.item.content;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
void item_privileges(Info & i)
|
|
|
|
{
|
|
|
|
i.out << std::setbase(8) << request.item.privileges << std::setbase(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_dir(Info & i)
|
|
|
|
{
|
|
|
|
dir(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_url(Info & i)
|
|
|
|
{
|
|
|
|
HtmlEscape(i.out, request.item.url);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_link(Info & i)
|
|
|
|
{
|
|
|
|
HtmlEscape(i.out, data.base_url);
|
|
|
|
item_dir(i);
|
|
|
|
item_url(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-03-23 00:54:15 +01:00
|
|
|
void item_can_read(Info & i)
|
|
|
|
{
|
|
|
|
if( request.HasReadAccess(request.item) )
|
|
|
|
i.result = true;
|
|
|
|
}
|
|
|
|
|
2009-06-05 22:29:06 +02:00
|
|
|
void item_can_write(Info & i)
|
|
|
|
{
|
|
|
|
if( request.HasWriteAccess(request.item) )
|
|
|
|
i.result = true;
|
|
|
|
}
|
2009-03-23 00:54:15 +01:00
|
|
|
|
|
|
|
void item_info(Info & i)
|
|
|
|
{
|
|
|
|
Ezc::Generator gen(i.out, pat_item_info, functions);
|
|
|
|
gen.Generate();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_user(Info & i)
|
|
|
|
{
|
|
|
|
User * puser = data.users.GetUser(request.item.user_id);
|
|
|
|
|
|
|
|
if( puser )
|
|
|
|
HtmlEscape(i.out, puser->name);
|
|
|
|
else
|
2009-06-07 04:40:27 +02:00
|
|
|
{
|
|
|
|
i.out << "~";
|
|
|
|
|
|
|
|
if( !request.item.guest_name.empty() )
|
|
|
|
HtmlEscape(i.out, request.item.guest_name);
|
|
|
|
else
|
|
|
|
i.out << "guest"; // !! dodac do konfiga
|
|
|
|
}
|
2009-03-23 00:54:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_date_creation(Info & i)
|
|
|
|
{
|
|
|
|
tm * ptm = &request.item.date_creation;
|
|
|
|
|
|
|
|
i.out << DateToStr(ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_date_modification(Info & i)
|
|
|
|
{
|
|
|
|
tm * ptm = &request.item.date_modification;
|
|
|
|
|
|
|
|
i.out << DateToStr(ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_dates_equal(Info & i)
|
|
|
|
{
|
|
|
|
tm * ptm1 = &request.item.date_creation;
|
|
|
|
tm * ptm2 = &request.item.date_modification;
|
|
|
|
|
|
|
|
i.result = ptm1->tm_year == ptm2->tm_year &&
|
|
|
|
ptm1->tm_mon == ptm2->tm_mon &&
|
|
|
|
ptm1->tm_mday == ptm2->tm_mday &&
|
|
|
|
ptm1->tm_hour == ptm2->tm_hour &&
|
|
|
|
ptm1->tm_min == ptm2->tm_min &&
|
|
|
|
ptm1->tm_sec == ptm2->tm_sec;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_run(Info & i)
|
|
|
|
{
|
|
|
|
if( !request.is_item )
|
|
|
|
{
|
|
|
|
i.out << "<!-- there is no an item to run -->";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !request.HasReadExecAccess(request.item) )
|
|
|
|
{
|
|
|
|
i.out << "<!-- run: permission denied -->";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ezc::Pattern * p = pattern_cacher.GetPattern(request.item);
|
|
|
|
Ezc::Generator gen(i.out, *p, functions);
|
|
|
|
gen.Generate();
|
|
|
|
}
|
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2009-11-17 00:36:38 +01:00
|
|
|
void item_guest_name(Info & i)
|
|
|
|
{
|
|
|
|
HtmlEscape(i.out, request.item.guest_name);
|
|
|
|
}
|
2008-12-30 02:05:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void item_old_id(Info & i)
|
|
|
|
{
|
|
|
|
i.out << request.session->item.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_old_subject(Info & i)
|
|
|
|
{
|
|
|
|
HtmlEscape(i.out, request.session->item.subject);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_old_subject_noescape(Info & i)
|
|
|
|
{
|
|
|
|
i.out << request.session->item.subject;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_old_content(Info & i)
|
|
|
|
{
|
|
|
|
HtmlEscape(i.out, request.session->item.content);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_old_content_noescape(Info & i)
|
|
|
|
{
|
|
|
|
i.out << request.session->item.content;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_old_privileges(Info & i)
|
|
|
|
{
|
|
|
|
i.out << std::setbase(8) << request.session->item.privileges << std::setbase(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_old_dir(Info & i)
|
|
|
|
{
|
|
|
|
std::string path;
|
|
|
|
|
|
|
|
if( data.dirs.MakePath(request.session->item.parent_id, path) )
|
|
|
|
HtmlEscape(i.out, path);
|
|
|
|
else
|
|
|
|
i.out << "/the path does not exist/";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_old_url(Info & i)
|
|
|
|
{
|
|
|
|
HtmlEscape(i.out, request.session->item.url);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_old_link(Info & i)
|
|
|
|
{
|
|
|
|
HtmlEscape(i.out, data.base_url);
|
|
|
|
item_old_dir(i);
|
|
|
|
item_old_url(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static size_t item_index;
|
|
|
|
|
|
|
|
|
|
|
|
void item_tab(Info & i)
|
|
|
|
{
|
|
|
|
item_index = i.iter;
|
|
|
|
i.result = item_index < request.item_table.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_tab_id(Info & i)
|
|
|
|
{
|
|
|
|
if( item_index < request.item_table.size() )
|
|
|
|
i.out << request.item_table[item_index].id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_tab_subject(Info & i)
|
|
|
|
{
|
|
|
|
if( item_index < request.item_table.size() )
|
|
|
|
HtmlEscape(i.out, request.item_table[item_index].subject);
|
|
|
|
}
|
|
|
|
|
|
|
|
void item_tab_subject_noescape(Info & i)
|
|
|
|
{
|
|
|
|
if( item_index < request.item_table.size() )
|
|
|
|
i.out << request.item_table[item_index].subject;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_tab_content(Info & i)
|
|
|
|
{
|
|
|
|
if( item_index < request.item_table.size() )
|
|
|
|
HtmlEscape(i.out, request.item_table[item_index].content);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_tab_content_noescape(Info & i)
|
|
|
|
{
|
|
|
|
if( item_index < request.item_table.size() )
|
|
|
|
i.out << request.item_table[item_index].content;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-05 22:29:06 +02:00
|
|
|
void item_tab_print_content(Info & i)
|
|
|
|
{
|
|
|
|
if( item_index >= request.item_table.size() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
int type = request.item_table[item_index].content_type;
|
|
|
|
|
|
|
|
if( type == 0 ) // simple txt
|
|
|
|
{
|
|
|
|
HtmlEscape(i.out, request.item_table[item_index].content);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( type == 1 ) // formatted txt
|
|
|
|
{
|
|
|
|
HtmlEscapeFormTxt(i.out, request.item_table[item_index].content);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( type == 2 ) // html
|
|
|
|
{
|
|
|
|
if( request.CanUseHtml(request.item_table[item_index].user_id) )
|
|
|
|
i.out << request.item_table[item_index].content;
|
|
|
|
else
|
|
|
|
HtmlEscape(i.out, request.item_table[item_index].content);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( type == 3 ) // bbcode
|
|
|
|
{
|
|
|
|
if( request.CanUseBBCode(request.item_table[item_index].user_id) )
|
|
|
|
HtmlEscape(i.out, request.item_table[item_index].content); // tutaj bedzie parsowanie bbcodu i tworzenie odpowiadajacego mu html-a
|
|
|
|
else
|
|
|
|
i.out << request.item_table[item_index].content;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
void item_tab_privileges(Info & i)
|
|
|
|
{
|
|
|
|
if( item_index < request.item_table.size() )
|
|
|
|
i.out << std::setbase(8) << request.item_table[item_index].privileges << std::setbase(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void item_tab_dir(Info & i)
|
|
|
|
{
|
|
|
|
if( item_index < request.item_table.size() )
|
|
|
|
{
|
|
|
|
std::string path;
|
|
|
|
|
|
|
|
if( data.dirs.MakePath(request.item_table[item_index].parent_id, path) )
|
|
|
|
HtmlEscape(i.out, path);
|
|
|
|
else
|
|
|
|
i.out << "/the path does not exist/";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_tab_url(Info & i)
|
|
|
|
{
|
|
|
|
if( item_index < request.item_table.size() )
|
|
|
|
HtmlEscape(i.out, request.item_table[item_index].url);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_tab_link(Info & i)
|
|
|
|
{
|
|
|
|
if( item_index < request.item_table.size() )
|
|
|
|
{
|
|
|
|
HtmlEscape(i.out, data.base_url);
|
|
|
|
item_tab_dir(i);
|
|
|
|
item_tab_url(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-21 01:49:28 +02:00
|
|
|
void item_tab_can_read(Info & i)
|
|
|
|
{
|
|
|
|
if( item_index < request.item_table.size() )
|
|
|
|
{
|
|
|
|
if( request.HasReadAccess(request.item_table[item_index]) )
|
|
|
|
i.result = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void item_tab_info(Info & i)
|
|
|
|
{
|
|
|
|
Ezc::Generator gen(i.out, pat_item_tab_info, functions);
|
|
|
|
gen.Generate();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_tab_user(Info & i)
|
|
|
|
{
|
|
|
|
if( item_index < request.item_table.size() )
|
|
|
|
{
|
|
|
|
User * puser = data.users.GetUser(request.item_table[item_index].user_id);
|
|
|
|
|
|
|
|
if( puser )
|
|
|
|
HtmlEscape(i.out, puser->name);
|
|
|
|
else
|
2009-06-07 04:40:27 +02:00
|
|
|
{
|
|
|
|
i.out << "~";
|
|
|
|
|
|
|
|
if( !request.item_table[item_index].guest_name.empty() )
|
|
|
|
HtmlEscape(i.out, request.item_table[item_index].guest_name);
|
|
|
|
else
|
|
|
|
i.out << "guest"; // !! dodac do konfiga
|
|
|
|
}
|
2009-04-21 01:49:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_tab_date_creation(Info & i)
|
|
|
|
{
|
|
|
|
if( item_index < request.item_table.size() )
|
|
|
|
{
|
|
|
|
tm * ptm = &request.item_table[item_index].date_creation;
|
|
|
|
|
|
|
|
i.out << DateToStr(ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_tab_date_modification(Info & i)
|
|
|
|
{
|
|
|
|
if( item_index < request.item_table.size() )
|
|
|
|
{
|
|
|
|
tm * ptm = &request.item_table[item_index].date_modification;
|
|
|
|
|
|
|
|
i.out << DateToStr(ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_tab_dates_equal(Info & i)
|
|
|
|
{
|
|
|
|
if( item_index < request.item_table.size() )
|
|
|
|
{
|
|
|
|
tm * ptm1 = &request.item_table[item_index].date_creation;
|
|
|
|
tm * ptm2 = &request.item_table[item_index].date_modification;
|
|
|
|
|
|
|
|
i.result = ptm1->tm_year == ptm2->tm_year &&
|
|
|
|
ptm1->tm_mon == ptm2->tm_mon &&
|
|
|
|
ptm1->tm_mday == ptm2->tm_mday &&
|
|
|
|
ptm1->tm_hour == ptm2->tm_hour &&
|
|
|
|
ptm1->tm_min == ptm2->tm_min &&
|
|
|
|
ptm1->tm_sec == ptm2->tm_sec;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void item_tab_run(Info & i)
|
|
|
|
{
|
|
|
|
if( item_index < request.item_table.size() )
|
|
|
|
{
|
|
|
|
if( !request.HasReadExecAccess(request.item) )
|
|
|
|
{
|
|
|
|
i.out << "<!-- run: permission denied -->";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ezc::Pattern * p = pattern_cacher.GetPattern(request.item_table[item_index]);
|
|
|
|
Ezc::Generator gen(i.out, *p, functions);
|
|
|
|
gen.Generate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-01-14 21:11:12 +01:00
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
} // namespace TemplatesFunctions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|