399 lines
7.3 KiB
C++
Executable File
399 lines
7.3 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2008-2010, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#include "templates.h"
|
|
#include "core/misc.h"
|
|
#include "functions/functions.h"
|
|
|
|
|
|
namespace TemplatesFunctions
|
|
{
|
|
|
|
|
|
|
|
void dir(Info & i)
|
|
{
|
|
for(size_t a=0 ; a<request->dir_table.size() ; ++a)
|
|
{
|
|
HtmlEscape(i.out, request->dir_table[a]->url);
|
|
i.out << '/';
|
|
}
|
|
}
|
|
|
|
|
|
void dir_without_slash(Info & i)
|
|
{
|
|
for(size_t a=0 ; a<request->dir_table.size() ; ++a)
|
|
{
|
|
HtmlEscape(i.out, request->dir_table[a]->url);
|
|
|
|
if( a < request->dir_table.size()-1 )
|
|
i.out << '/';
|
|
}
|
|
}
|
|
|
|
|
|
void dir_parent(Info & i)
|
|
{
|
|
if( request->dir_table.empty() )
|
|
return;
|
|
|
|
for(size_t a=0 ; a<request->dir_table.size()-1 ; ++a)
|
|
{
|
|
HtmlEscape(i.out, request->dir_table[a]->url);
|
|
i.out << '/';
|
|
}
|
|
}
|
|
|
|
|
|
void dir_parent_without_slash(Info & i)
|
|
{
|
|
if( request->dir_table.empty() )
|
|
return;
|
|
|
|
for(size_t a=0 ; a<request->dir_table.size()-1 ; ++a)
|
|
{
|
|
HtmlEscape(i.out, request->dir_table[a]->url);
|
|
|
|
if( request->dir_table.size()>=2 && a<request->dir_table.size()-2 )
|
|
i.out << '/';
|
|
}
|
|
}
|
|
|
|
|
|
//!! moze wystarczy sprawdzac tylko ostatni katalog?
|
|
// bo inaczej i tak bylo by 'access denied'
|
|
void dir_can_read_exec(Info & i)
|
|
{
|
|
bool result = true;
|
|
|
|
for(size_t a=0 ; a<request->dir_table.size() ; ++a)
|
|
{
|
|
if( !system->HasReadExecAccess(*request->dir_table[a]) )
|
|
{
|
|
result = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
i.res = result;
|
|
}
|
|
|
|
|
|
void dir_can_write(Info & i)
|
|
{
|
|
i.res = system->HasWriteAccess(*request->dir_table.back());
|
|
}
|
|
|
|
|
|
void dir_can_remove(Info & i)
|
|
{
|
|
bool result = true;
|
|
|
|
|
|
if( request->dir_table.size() == 1 )
|
|
{
|
|
// rm for the root dir
|
|
// only the superuser can do it
|
|
if( !request->session->puser || !request->session->puser->super_user )
|
|
result = false;
|
|
}
|
|
else
|
|
{
|
|
Item * last_but_one_dir = *(--(--request->dir_table.end()));
|
|
|
|
if( !system->HasWriteAccess(*last_but_one_dir) )
|
|
result = false;
|
|
}
|
|
|
|
i.res = result;
|
|
}
|
|
|
|
|
|
void dir_can_use_emacs(Info & i)
|
|
{
|
|
i.res = functions->fun_emacs.HasAccess();
|
|
}
|
|
|
|
|
|
void dir_can_use_mkdir(Info & i)
|
|
{
|
|
i.res = functions->fun_mkdir.HasAccess();
|
|
}
|
|
|
|
|
|
|
|
static std::vector<Item*> dir_childs_table;
|
|
static size_t dir_childs_index;
|
|
// request->id is never 0 and we can start dir_childs_reqid from 0
|
|
static size_t dir_childs_reqid = 0;
|
|
|
|
// is the first directory the parent ('..')
|
|
static bool dir_childs_has_parent;
|
|
|
|
|
|
void dir_childs_tab(Info & i)
|
|
{
|
|
if( dir_childs_reqid != request->id )
|
|
{
|
|
dir_childs_reqid = request->id;
|
|
dir_childs_table.clear();
|
|
dir_childs_has_parent = false;
|
|
|
|
if( !request->dir_table.empty() )
|
|
{
|
|
if( request->dir_table.size() >= 2 && i.par == "with_parent")
|
|
{
|
|
Item * dir_up = request->dir_table[request->dir_table.size()-2];
|
|
dir_childs_table.push_back(dir_up);
|
|
dir_childs_has_parent = true;
|
|
}
|
|
|
|
system->dirs.GetDirChilds(request->dir_table.back()->id, dir_childs_table);
|
|
}
|
|
}
|
|
|
|
dir_childs_index = i.iter;
|
|
i.res = dir_childs_index < dir_childs_table.size();
|
|
}
|
|
|
|
|
|
// is this child a parent ('..')
|
|
void dir_childs_is_parent(Info & i)
|
|
{
|
|
i.res = (dir_childs_has_parent && dir_childs_index == 0);
|
|
}
|
|
|
|
|
|
void dir_childs_tab_url(Info & i)
|
|
{
|
|
if( dir_childs_index < dir_childs_table.size() )
|
|
HtmlEscape(i.out, dir_childs_table[dir_childs_index]->url);
|
|
}
|
|
|
|
|
|
|
|
void dir_childs_tab_privileges(Info & i)
|
|
{
|
|
if( dir_childs_index < dir_childs_table.size() )
|
|
i.out << "0" << std::setbase(8) << dir_childs_table[dir_childs_index]->privileges << std::setbase(10);
|
|
}
|
|
|
|
|
|
void dir_childs_tab_user(Info & i)
|
|
{
|
|
if( dir_childs_index < dir_childs_table.size() )
|
|
{
|
|
long user_id = dir_childs_table[dir_childs_index]->user_id;
|
|
User * puser = system->users.GetUser(user_id);
|
|
|
|
if( puser )
|
|
HtmlEscape(i.out, puser->name);
|
|
else
|
|
{
|
|
i.out << "~";
|
|
|
|
if( !dir_childs_table[dir_childs_index]->guest_name.empty() )
|
|
HtmlEscape(i.out, dir_childs_table[dir_childs_index]->guest_name);
|
|
else
|
|
i.out << "guest"; // !! dodac do konfiga
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void dir_childs_tab_group(Info & i)
|
|
{
|
|
if( dir_childs_index < dir_childs_table.size() )
|
|
{
|
|
long group_id = dir_childs_table[dir_childs_index]->group_id;
|
|
Group * pgroup = system->groups.GetGroup(group_id);
|
|
|
|
if( pgroup )
|
|
HtmlEscape(i.out, pgroup->name);
|
|
else
|
|
i.out << group_id;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static size_t dir_index;
|
|
|
|
|
|
void dir_tab(Info & i)
|
|
{
|
|
dir_index = i.iter;
|
|
i.res = dir_index < request->dir_table.size();
|
|
}
|
|
|
|
|
|
void dir_tab_url(Info & i)
|
|
{
|
|
if( dir_index < request->dir_table.size() )
|
|
HtmlEscape(i.out, request->dir_table[dir_index]->url);
|
|
}
|
|
|
|
|
|
void dir_tab_link(Info & i)
|
|
{
|
|
i.out << config->base_url;
|
|
|
|
for(size_t a = 0 ; a <= dir_index && a < request->dir_table.size() ; ++a)
|
|
{
|
|
HtmlEscape(i.out, request->dir_table[a]->url);
|
|
i.out << '/';
|
|
}
|
|
}
|
|
|
|
|
|
static Item dir_last_default_item;
|
|
static size_t dir_last_default_item_reqid = 0;
|
|
|
|
|
|
|
|
void dir_last_default_item_init()
|
|
{
|
|
if( dir_last_default_item_reqid == request->id )
|
|
return;
|
|
|
|
dir_last_default_item_reqid = request->id;
|
|
|
|
dir_last_default_item.Clear();
|
|
|
|
if( request->dir_table.empty() )
|
|
return;
|
|
|
|
long default_item = request->dir_table.back()->default_item;
|
|
|
|
if( default_item == -1 )
|
|
return;
|
|
|
|
std::vector<Item> item_table; // !! tymczasowo, nie bedzie tego po zmianie interfejsu dla Db
|
|
db->GetItem(item_table, default_item);
|
|
|
|
if( item_table.empty() )
|
|
return;
|
|
|
|
dir_last_default_item = item_table[0];
|
|
}
|
|
|
|
|
|
|
|
void dir_last_default_item_dir(Info & i)
|
|
{
|
|
dir_last_default_item_init();
|
|
|
|
std::string path;
|
|
|
|
if( dir_last_default_item.parent_id != -1 )
|
|
if( system->dirs.MakePath(dir_last_default_item.parent_id, path) )
|
|
HtmlEscape(i.out, path);
|
|
}
|
|
|
|
|
|
void dir_last_default_item_url(Info & i)
|
|
{
|
|
dir_last_default_item_init();
|
|
|
|
HtmlEscape(i.out, dir_last_default_item.url);
|
|
}
|
|
|
|
|
|
void dir_last_subject(Info & i)
|
|
{
|
|
HtmlEscape(i.out, request->dir_table.back()->subject);
|
|
}
|
|
|
|
|
|
void dir_last_info(Info & i)
|
|
{
|
|
if( static_cast<size_t>(locale.GetLang()) >= patterns.size() )
|
|
return;
|
|
|
|
Ezc::Generator gen(i.out, patterns[locale.GetLang()][pat_dir_last_info], ezc_functions);
|
|
gen.Generate();
|
|
}
|
|
|
|
|
|
void dir_last_user(Info & i)
|
|
{
|
|
User * puser = system->users.GetUser(request->dir_table.back()->user_id);
|
|
|
|
if( puser )
|
|
HtmlEscape(i.out, puser->name);
|
|
else
|
|
{
|
|
i.out << "~";
|
|
|
|
if( !request->dir_table.back()->guest_name.empty() )
|
|
HtmlEscape(i.out, request->dir_table.back()->guest_name);
|
|
else
|
|
i.out << "guest"; // !! dodac do konfiga
|
|
}
|
|
}
|
|
|
|
|
|
void dir_last_url(Info & i)
|
|
{
|
|
HtmlEscape(i.out, request->dir_table.back()->url);
|
|
}
|
|
|
|
|
|
void dir_last_url_is(Info & i)
|
|
{
|
|
i.res = request->dir_table.back()->url == i.par;
|
|
}
|
|
|
|
|
|
void dir_last_date_creation(Info & i)
|
|
{
|
|
tm * ptm = &request->dir_table.back()->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 dir_last_date_modification(Info & i)
|
|
{
|
|
tm * ptm = &request->dir_table.back()->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 dir_last_dates_equal(Info & i)
|
|
{
|
|
tm * ptm1 = &request->dir_table.back()->date_creation;
|
|
tm * ptm2 = &request->dir_table.back()->date_modification;
|
|
|
|
i.res = 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;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace TemplatesFunctions
|
|
|
|
|
|
|