2010-08-13 22:04:57 +02:00
|
|
|
/*
|
|
|
|
* This file is a part of Winix
|
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008-2010, Tomasz Sowa
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include "templates.h"
|
|
|
|
#include "core/misc.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace TemplatesFunctions
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
void template_index(Info & i)
|
|
|
|
{
|
|
|
|
HtmlEscape(i.out, config->templates_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static std::vector<std::string> temp_tab;
|
|
|
|
static size_t temp_req_id = 0;
|
|
|
|
static size_t temp_def;
|
|
|
|
static size_t temp_index;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void template_set_def()
|
|
|
|
{
|
|
|
|
temp_def = (size_t)-1; // none
|
|
|
|
const std::string * html_file;
|
|
|
|
|
|
|
|
if( request->is_item )
|
|
|
|
html_file = &request->item.html_template;
|
|
|
|
else
|
|
|
|
html_file = &request->dir_tab.back()->html_template;
|
|
|
|
|
|
|
|
|
|
|
|
if( html_file->empty() )
|
|
|
|
{
|
|
|
|
// the first default item should be selected (that first in html source with value="")
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for(size_t i=0 ; i<temp_tab.size() ; ++i)
|
|
|
|
{
|
|
|
|
if( temp_tab[i] == *html_file )
|
|
|
|
{
|
|
|
|
temp_def = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void template_init()
|
|
|
|
{
|
|
|
|
// the first item in the html template is an empty string
|
|
|
|
// added in the html template
|
|
|
|
temp_tab.clear();
|
|
|
|
temp_tab.push_back(config->templates_index);
|
|
|
|
|
2010-09-13 01:33:27 +02:00
|
|
|
Mount::ParamRow & par = system->mounts.pmount->param[system->mounts.MountParHtmlTemplate()];
|
2010-08-13 22:04:57 +02:00
|
|
|
|
|
|
|
if( par.defined )
|
|
|
|
{
|
|
|
|
size_t len = par.arg.size();
|
|
|
|
|
|
|
|
for(size_t i=0 ; i<len ; ++i)
|
|
|
|
temp_tab.push_back(par.arg[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
template_set_def();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void template_tab(Info & i)
|
|
|
|
{
|
|
|
|
if( request->id != temp_req_id )
|
|
|
|
{
|
|
|
|
temp_req_id = request->id;
|
|
|
|
template_init();
|
|
|
|
}
|
|
|
|
|
|
|
|
temp_index = i.iter;
|
|
|
|
i.res = temp_index < temp_tab.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-14 16:45:25 +02:00
|
|
|
void template_tab_index(Info & i)
|
|
|
|
{
|
|
|
|
i.out << temp_index;
|
|
|
|
}
|
|
|
|
|
2010-08-13 22:04:57 +02:00
|
|
|
|
|
|
|
void template_tab_isdefault(Info & i)
|
|
|
|
{
|
|
|
|
if( temp_index < temp_tab.size() )
|
|
|
|
i.res = (temp_index == temp_def);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void template_tab_file_name(Info & i)
|
|
|
|
{
|
|
|
|
if( temp_index < temp_tab.size() )
|
|
|
|
HtmlEscape(i.out, temp_tab[temp_index]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace
|