added: new plugin: menu
fixed: System::FollowAllLinks didn't check permissions to a file (only to a simlink or a directory) added: new ezc function: insert_page now we are able to nest pages in pages git-svn-id: svn://ttmath.org/publicrep/winix/trunk@750 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
107
templates/insert.cpp
Executable file
107
templates/insert.cpp
Executable file
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* 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 << "insert page: using " << insert_page_cur << " generator" << 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;
|
||||
|
||||
log << "insert page: " << path << logend;
|
||||
|
||||
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 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
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user