106 lines
1.9 KiB
C++
Executable File
106 lines
1.9 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2011, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#include "templates.h"
|
|
#include "misc.h"
|
|
#include "core/request.h"
|
|
#include "core/misc.h"
|
|
|
|
|
|
// max 20 nested insert_page ezc functions allowed
|
|
#define WINIX_TEMPLATES_INSERT_PAGE_MAX 20
|
|
|
|
|
|
|
|
namespace TemplatesFunctions
|
|
{
|
|
|
|
struct InsertPageInfo
|
|
{
|
|
std::vector<Item*> dirs;
|
|
Item item;
|
|
EzcGen ezc_gen;
|
|
HtmlTextStream run_content;
|
|
};
|
|
|
|
|
|
static InsertPageInfo insert_page_info[WINIX_TEMPLATES_INSERT_PAGE_MAX];
|
|
size_t insert_page_cur = 0;
|
|
size_t insert_page_reqid = 0;
|
|
|
|
|
|
|
|
void insert_page_run(Info & i)
|
|
{
|
|
InsertPageInfo & info = insert_page_info[insert_page_cur];
|
|
Ezc::Pattern * pat = pattern_cacher.GetPattern(info.item);
|
|
|
|
log << log4 << "Templates: insert_page_run: using generator number: " << insert_page_cur << logend;
|
|
insert_page_cur += 1;
|
|
|
|
info.run_content.Clear();
|
|
info.ezc_gen.Generate(info.run_content, *pat);
|
|
item_print_content(i.out, info.run_content.Str(), info.item.content_type);
|
|
|
|
insert_page_cur -= 1;
|
|
}
|
|
|
|
|
|
|
|
bool insert_page_init(const std::wstring & path)
|
|
{
|
|
if( path.empty() )
|
|
return false;
|
|
|
|
if( insert_page_reqid != cur->request->id )
|
|
{
|
|
insert_page_reqid = cur->request->id;
|
|
insert_page_cur = 0;
|
|
}
|
|
|
|
if( insert_page_cur >= WINIX_TEMPLATES_INSERT_PAGE_MAX )
|
|
{
|
|
log << log1 << "Templates: insert_page: maximum nested insert_page functions exceeded" << logend;
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
void insert_page(Info & i)
|
|
{
|
|
if( !insert_page_init(i.par) )
|
|
return;
|
|
|
|
InsertPageInfo & info = insert_page_info[insert_page_cur];
|
|
|
|
if( system->FollowAllLinks(cur->request->dir_tab, i.par, info.dirs, info.item) == 1 )
|
|
{
|
|
if( system->HasReadExecAccess(info.item) )
|
|
insert_page_run(i);
|
|
else
|
|
if( system->HasReadAccess(info.item) )
|
|
item_print_content(i.out, info.item.content, info.item.content_type);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace TemplatesFunctions
|
|
|
|
|
|
|
|
|
|
|