winix/plugins/thread/templates.cpp

216 lines
4.5 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 "misc.h"
#include "core/request.h"
#include "core/misc.h"
#include "functions/functions.h"
namespace Thread
{
using namespace TemplatesFunctions;
using TemplatesFunctions::system;
extern ThreadInfo thread_info;
extern FunThread fun_thread;
extern CreateThread fun_create_thread;
extern ShowThreads fun_show_threads;
void thread_is(Info & i)
{
i.res = functions->fun_thread.is_thread;
}
static size_t thread_tab_index;
void thread_tab(Info & i)
{
thread_tab_index = i.iter;
i.res = thread_tab_index < functions->fun_thread.thread_tab.size();
}
void thread_tab_url(Info & i)
{
if( thread_tab_index < functions->fun_thread.thread_tab.size() )
{
Item * dir = system->dirs.GetDir( functions->fun_thread.thread_tab[thread_tab_index].dir_id );
if( dir )
{
i.out << dir->url;
}
else
{
i.out << "<!-- unknown directory -->"; // !! do konfiga
}
}
}
void thread_tab_subject(Info & i)
{
if( thread_tab_index < functions->fun_thread.thread_tab.size() )
{
Item * dir = system->dirs.GetDir( functions->fun_thread.thread_tab[thread_tab_index].dir_id );
if( dir )
{
if( !dir->subject.empty() )
i.out << dir->subject;
else
i.out << dir->url;
}
else
{
i.out << "<!-- unknown subject -->"; // !! do konfiga
}
}
}
void thread_tab_answers(Info & i)
{
if( thread_tab_index < functions->fun_thread.thread_tab.size() )
{
long a = functions->fun_thread.thread_tab[thread_tab_index].items;
// the first is created by the author
// we count only the rest
if( a > 0 )
--a;
i.out << a;
}
}
void thread_tab_author(Info & i)
{
bool unknown = true;
if( thread_tab_index < functions->fun_thread.thread_tab.size() )
{
Item * dir = system->dirs.GetDir( functions->fun_thread.thread_tab[thread_tab_index].dir_id );
if( dir )
{
User * puser = system->users.GetUser(dir->user_id);
unknown = false;
if( puser )
i.out << puser->name;
else
{
i.out << "~";
if( !dir->guest_name.empty() )
i.out << dir->guest_name;
else
i.out << "guest"; // !! dodac do konfiga
}
}
}
if( unknown )
{
i.out << "<!-- unknown user -->";
}
}
void thread_tab_last_item_date_modification(Info & i)
{
if( thread_tab_index < functions->fun_thread.thread_tab.size() )
if( functions->fun_thread.thread_tab[thread_tab_index].last_item.id != -1 )
i.out << DateToStr( &functions->fun_thread.thread_tab[thread_tab_index].last_item.date_modification );
}
void thread_tab_last_item_date_modification_nice(Info & i)
{
if( thread_tab_index < functions->fun_thread.thread_tab.size() )
if( functions->fun_thread.thread_tab[thread_tab_index].last_item.id != -1 )
print_date_nice(i, functions->fun_thread.thread_tab[thread_tab_index].last_item.date_modification);
}
void thread_tab_last_item_user(Info & i)
{
if( thread_tab_index < functions->fun_thread.thread_tab.size() )
{
if( functions->fun_thread.thread_tab[thread_tab_index].last_item.id != -1 )
{
User * puser = system->users.GetUser( functions->fun_thread.thread_tab[thread_tab_index].last_item.user_id );
if( puser )
i.out << puser->name;
else
{
i.out << "~";
if( !functions->fun_thread.thread_tab[thread_tab_index].last_item.guest_name.empty() )
i.out << functions->fun_thread.thread_tab[thread_tab_index].last_item.guest_name;
else
i.out << "guest"; // !! dodac do konfiga
}
}
}
}
void thread_can_create(Info & i)
{
i.res = functions->fun_createthread.HasAccess(true);
}
void AddEzcFunctions(PluginInfo & info)
{
using TemplatesFunctions::EzcFun;
EzcFun * fun = reinterpret_cast<EzcFun*>(info.p1);
fun->Insert("thread_is", thread_is);
fun->Insert("thread_tab", thread_tab);
fun->Insert("thread_tab_url", thread_tab_url);
fun->Insert("thread_tab_subject", thread_tab_subject);
fun->Insert("thread_tab_author", thread_tab_author);
fun->Insert("thread_tab_answers", thread_tab_answers);
fun->Insert("thread_tab_last_item_date_modification", thread_tab_last_item_date_modification);
fun->Insert("thread_tab_last_item_date_modification_nice", thread_tab_last_item_date_modification_nice);
fun->Insert("thread_tab_last_item_user", thread_tab_last_item_user);
fun->Insert("thread_can_create", thread_can_create);
}
} // namespace