Files
winix/templates/insert.cpp
Tomasz Sowa 4d87359aca added: Export plugin (not finished yet)
added:   ThreadManager
         all threads are connected to the ThreadManager
         they are started/stopped by the manager
changed: FunctionParser
         now we are parsing directly what is in URI
         (we were using GetParser beforehand)
         we are able to recognize ordinary URI scheme (with '?' and '#' characters)
         sample:
         http://domain.com/dir1/dir2/item/function?par1=val2&par2=val2#htmlanchor
         is the same as:
         http://domain.com/dir1/dir2/item/function/par1:val2/par2:val2#htmlanchor
         'htmlanchor' is put in Request::anchor field,
         and the default function can be used like this:
         http://domain.com/dir1/dir2/item?par1=val2&par2=val2#htmlanchor
         but there is not an equivalent in winix form
         e.g. http://domain.com/dir1/dir2/item/par1:val2/par2:val2#htmlanchor
         because 'par1:val2' would be treated as a function name
removed: GetParser
         now we don't have Request::get_tab structure
removed: CKEditorGetParser
         it is not needed now



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@752 e52654a7-88a9-db11-a3e9-0013d4bc506e
2011-07-28 22:18:10 +00:00

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