moved winix directories to winixdsubdirectory
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@1028 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
19
winixd/templates/Makefile
Normal file
19
winixd/templates/Makefile
Normal file
@@ -0,0 +1,19 @@
|
||||
include Makefile.o.dep
|
||||
|
||||
|
||||
all: $(o)
|
||||
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX) -c $(CXXFLAGS) $(CXXWINIXINCLUDEFLAGS) $<
|
||||
|
||||
|
||||
depend:
|
||||
makedepend -Y. $(CXXWINIXINCLUDEFLAGS) -f- *.cpp > Makefile.dep
|
||||
echo -n "o = " > Makefile.o.dep
|
||||
ls -1 *.cpp | xargs -I foo echo -n foo " " | sed -E "s/([^\.]*)\.cpp[ ]/\1\.o/g" >> Makefile.o.dep
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
|
||||
include Makefile.dep
|
2047
winixd/templates/Makefile.dep
Normal file
2047
winixd/templates/Makefile.dep
Normal file
File diff suppressed because it is too large
Load Diff
1
winixd/templates/Makefile.o.dep
Normal file
1
winixd/templates/Makefile.o.dep
Normal file
@@ -0,0 +1 @@
|
||||
o = adduser.o changepatterns.o config.o currentdate.o dir.o doc.o env.o filters.o generic.o htmltextstream.o indexpatterns.o insert.o ipban.o item.o last.o locale.o localefilter.o login.o ls.o man.o misc.o miscspace.o mount.o passwd.o patterncacher.o patterns.o priv.o rebus.o server.o slog.o stat.o sys.o template.o templates.o textextstream.o upload.o uptime.o user.o who.o winix.o
|
63
winixd/templates/adduser.cpp
Normal file
63
winixd/templates/adduser.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <ctime>
|
||||
#include "templates.h"
|
||||
#include "core/request.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
void adduser_last_login(Info & i)
|
||||
{
|
||||
i.out << cur->request->PostVar(L"login");
|
||||
}
|
||||
|
||||
|
||||
void adduser_last_email(Info & i)
|
||||
{
|
||||
i.out << cur->request->PostVar(L"email");
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace Winix
|
||||
|
141
winixd/templates/changepatterns.cpp
Normal file
141
winixd/templates/changepatterns.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "changepatterns.h"
|
||||
#include "core/log.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
void ChangePatterns::SetPatterns(Patterns * ppatterns)
|
||||
{
|
||||
patterns = ppatterns;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ChangePatterns::Add(long mount_dir_id, const std::wstring & old_pattern_name, const std::wstring & new_pattern_name)
|
||||
{
|
||||
Value & value = pat_tab[mount_dir_id];
|
||||
std::pair<Value::iterator, bool> res = value.insert(std::make_pair(old_pattern_name, Template()));
|
||||
|
||||
Template & tmpl = res.first->second;
|
||||
tmpl.to_delete = false;
|
||||
|
||||
if( res.second || new_pattern_name != patterns->GetFileName(tmpl.index) )
|
||||
tmpl.index = patterns->Add(new_pattern_name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Ezc::Pattern * ChangePatterns::Get(long mount_dir_id, const std::wstring & old_pattern_name, size_t locale_index)
|
||||
{
|
||||
PatTab::iterator i = pat_tab.find(mount_dir_id);
|
||||
|
||||
if( i == pat_tab.end() )
|
||||
return 0;
|
||||
|
||||
Value & value = i->second;
|
||||
Value::iterator v = value.find(old_pattern_name);
|
||||
|
||||
if( v == value.end() )
|
||||
return 0;
|
||||
|
||||
Template & tmpl = v->second;
|
||||
|
||||
log << log4 << "ChangePatterns: changing " << old_pattern_name
|
||||
<< " to " << patterns->GetFileName(tmpl.index) << logend;
|
||||
|
||||
return patterns->Get(tmpl.index, locale_index);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ChangePatterns::MarkAllToDelete()
|
||||
{
|
||||
PatTab::iterator i;
|
||||
Value::iterator v;
|
||||
|
||||
for(i=pat_tab.begin() ; i != pat_tab.end() ; ++i)
|
||||
{
|
||||
Value & value = i->second;
|
||||
|
||||
for(v=value.begin() ; v != value.end() ; ++v)
|
||||
v->second.to_delete = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ChangePatterns::DeleteMarked()
|
||||
{
|
||||
PatTab::iterator i;
|
||||
Value::iterator v, next;
|
||||
|
||||
for(i=pat_tab.begin() ; i != pat_tab.end() ; ++i)
|
||||
{
|
||||
Value & value = i->second;
|
||||
|
||||
for(v=value.begin() ; v != value.end() ; )
|
||||
{
|
||||
next = v;
|
||||
++next;
|
||||
|
||||
if( v->second.to_delete )
|
||||
{
|
||||
patterns->Erase(v->second.index);
|
||||
value.erase(v);
|
||||
}
|
||||
|
||||
v = next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ChangePatterns::Clear()
|
||||
{
|
||||
pat_tab.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
106
winixd/templates/changepatterns.h
Normal file
106
winixd/templates/changepatterns.h
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_templates_changepatterns
|
||||
#define headerfile_winix_templates_changepatterns
|
||||
|
||||
#include <map>
|
||||
#include "patterns.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
class ChangePatterns
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
void SetPatterns(Patterns * ppatterns);
|
||||
|
||||
|
||||
/*
|
||||
adding a new pattern
|
||||
if such a pattern exists the method only unmarks the pattern from deleting
|
||||
*/
|
||||
void Add(long mount_dir_id, const std::wstring & old_pattern_name, const std::wstring & new_pattern_name);
|
||||
|
||||
|
||||
/*
|
||||
returning a pattern (if exists)
|
||||
can return a null pointer
|
||||
*/
|
||||
Ezc::Pattern * Get(long mount_dir_id, const std::wstring & old_pattern_name, size_t locale_index);
|
||||
|
||||
|
||||
/*
|
||||
marking all patterns as ready to delete
|
||||
*/
|
||||
void MarkAllToDelete();
|
||||
|
||||
|
||||
/*
|
||||
delete marked patterns
|
||||
if you have called Add() then such a pattern is not deleted
|
||||
*/
|
||||
void DeleteMarked();
|
||||
|
||||
|
||||
/*
|
||||
deleting all patterns
|
||||
*/
|
||||
void Clear();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
Patterns * patterns;
|
||||
|
||||
struct Template
|
||||
{
|
||||
bool to_delete;
|
||||
size_t index; // pattern index in 'patterns' object
|
||||
};
|
||||
|
||||
typedef std::map<std::wstring, Template> Value;
|
||||
typedef std::map<long, Value> PatTab;
|
||||
PatTab pat_tab;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
#endif
|
103
winixd/templates/config.cpp
Normal file
103
winixd/templates/config.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
/*
|
||||
some config options
|
||||
*/
|
||||
|
||||
|
||||
void config_use_ssl(Info & i)
|
||||
{
|
||||
i.res = config->use_ssl;
|
||||
}
|
||||
|
||||
|
||||
void config_use_ssl_static(Info & i)
|
||||
{
|
||||
i.res = config->use_ssl_static;
|
||||
}
|
||||
|
||||
|
||||
void config_use_ssl_common(Info & i)
|
||||
{
|
||||
i.res = config->use_ssl_common;
|
||||
}
|
||||
|
||||
|
||||
void config_url_proto(Info & i)
|
||||
{
|
||||
i.out << config->url_proto;
|
||||
}
|
||||
|
||||
|
||||
void config_url_ssl_proto(Info & i)
|
||||
{
|
||||
i.out << config->url_ssl_proto;
|
||||
}
|
||||
|
||||
|
||||
void config_base_url(Info & i)
|
||||
{
|
||||
i.out << config->base_url;
|
||||
}
|
||||
|
||||
|
||||
void config_base_url_static(Info & i)
|
||||
{
|
||||
i.out << config->base_url_static;
|
||||
}
|
||||
|
||||
|
||||
void config_base_url_common(Info & i)
|
||||
{
|
||||
i.out << config->base_url_common;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
139
winixd/templates/currentdate.cpp
Normal file
139
winixd/templates/currentdate.cpp
Normal file
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2015, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
#include "core/misc.h"
|
||||
#include "functions/functions.h"
|
||||
#include "miscspace.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
|
||||
void current_sec_utc(Info & i)
|
||||
{
|
||||
i.out << cur->request->start_date.sec;
|
||||
}
|
||||
|
||||
void current_min_utc(Info & i)
|
||||
{
|
||||
i.out << cur->request->start_date.min;
|
||||
}
|
||||
|
||||
void current_hour_utc(Info & i)
|
||||
{
|
||||
i.out << cur->request->start_date.hour;
|
||||
}
|
||||
|
||||
|
||||
void current_day_utc(Info & i)
|
||||
{
|
||||
i.out << cur->request->start_date.day;
|
||||
}
|
||||
|
||||
void current_month_utc(Info & i)
|
||||
{
|
||||
i.out << cur->request->start_date.month;
|
||||
}
|
||||
|
||||
void current_year_utc(Info & i)
|
||||
{
|
||||
i.out << cur->request->start_date.year;
|
||||
}
|
||||
|
||||
|
||||
void current_date_utc(Info & i)
|
||||
{
|
||||
i.out << cur->request->start_date;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void current_sec(Info & i)
|
||||
{
|
||||
PT::Date date = system->ToLocal(cur->request->start_date);
|
||||
i.out << date.sec;
|
||||
}
|
||||
|
||||
void current_min(Info & i)
|
||||
{
|
||||
PT::Date date = system->ToLocal(cur->request->start_date);
|
||||
i.out << date.min;
|
||||
}
|
||||
|
||||
void current_hour(Info & i)
|
||||
{
|
||||
PT::Date date = system->ToLocal(cur->request->start_date);
|
||||
i.out << date.hour;
|
||||
}
|
||||
|
||||
|
||||
void current_day(Info & i)
|
||||
{
|
||||
PT::Date date = system->ToLocal(cur->request->start_date);
|
||||
i.out << date.day;
|
||||
}
|
||||
|
||||
void current_month(Info & i)
|
||||
{
|
||||
PT::Date date = system->ToLocal(cur->request->start_date);
|
||||
i.out << date.month;
|
||||
}
|
||||
|
||||
void current_year(Info & i)
|
||||
{
|
||||
PT::Date date = system->ToLocal(cur->request->start_date);
|
||||
i.out << date.year;
|
||||
}
|
||||
|
||||
|
||||
void current_date(Info & i)
|
||||
{
|
||||
PT::Date date = system->ToLocal(cur->request->start_date);
|
||||
i.out << date;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
533
winixd/templates/dir.cpp
Normal file
533
winixd/templates/dir.cpp
Normal file
@@ -0,0 +1,533 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
#include "core/misc.h"
|
||||
#include "functions/functions.h"
|
||||
#include "miscspace.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
|
||||
void dir(Info & i)
|
||||
{
|
||||
for(size_t a=0 ; a<cur->request->dir_tab.size() ; ++a)
|
||||
i.out << cur->request->dir_tab[a]->url << '/';
|
||||
}
|
||||
|
||||
|
||||
void dir_without_slash(Info & i)
|
||||
{
|
||||
for(size_t a=0 ; a<cur->request->dir_tab.size() ; ++a)
|
||||
{
|
||||
i.out << cur->request->dir_tab[a]->url;
|
||||
|
||||
if( a < cur->request->dir_tab.size()-1 )
|
||||
i.out << '/';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void dir_is_root(Info & i)
|
||||
{
|
||||
i.res = cur->request->dir_tab.size() == 1;
|
||||
}
|
||||
|
||||
|
||||
void dir_parent(Info & i)
|
||||
{
|
||||
if( cur->request->dir_tab.empty() )
|
||||
return;
|
||||
|
||||
for(size_t a=0 ; a<cur->request->dir_tab.size()-1 ; ++a)
|
||||
{
|
||||
i.out << cur->request->dir_tab[a]->url << '/';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void dir_parent_without_slash(Info & i)
|
||||
{
|
||||
if( cur->request->dir_tab.empty() )
|
||||
return;
|
||||
|
||||
for(size_t a=0 ; a<cur->request->dir_tab.size()-1 ; ++a)
|
||||
{
|
||||
i.out << cur->request->dir_tab[a]->url;
|
||||
|
||||
if( cur->request->dir_tab.size()>=2 && a<cur->request->dir_tab.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)
|
||||
{
|
||||
i.res = system->HasReadExecAccessToPath(cur->request->dir_tab);
|
||||
}
|
||||
|
||||
// !! zamienic na dir_last_can_write ?
|
||||
void dir_can_write(Info & i)
|
||||
{
|
||||
i.res = system->HasWriteAccess(*cur->request->dir_tab.back());
|
||||
}
|
||||
|
||||
|
||||
void dir_can_remove(Info & i)
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
|
||||
if( cur->request->dir_tab.size() == 1 )
|
||||
{
|
||||
// rm for the root dir
|
||||
// only the superuser can do it
|
||||
if( !cur->session->puser || !cur->session->puser->super_user )
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Item * last_but_one_dir = *(--(--cur->request->dir_tab.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::wstring dir_parents_str;
|
||||
|
||||
|
||||
|
||||
bool dir_is(const std::wstring & par)
|
||||
{
|
||||
dir_parents_str.clear();
|
||||
|
||||
for(size_t a=0 ; a<cur->request->dir_tab.size() ; ++a)
|
||||
{
|
||||
dir_parents_str += cur->request->dir_tab[a]->url;
|
||||
dir_parents_str += '/';
|
||||
}
|
||||
|
||||
if( !par.empty() && par[par.size()-1] != '/' )
|
||||
if( !dir_parents_str.empty() )
|
||||
dir_parents_str.erase(dir_parents_str.size()-1);
|
||||
|
||||
return par == dir_parents_str;
|
||||
}
|
||||
|
||||
|
||||
void dir_is(Info & i)
|
||||
{
|
||||
i.res = dir_is(i.par);
|
||||
}
|
||||
|
||||
|
||||
void dir_is_no(Info & i)
|
||||
{
|
||||
i.res = !dir_is(i.par);
|
||||
}
|
||||
|
||||
|
||||
void dir_has_parents(Info & i)
|
||||
{
|
||||
dir_parents_str.clear();
|
||||
|
||||
for(size_t a=0 ; a<cur->request->dir_tab.size() ; ++a)
|
||||
{
|
||||
dir_parents_str += cur->request->dir_tab[a]->url;
|
||||
dir_parents_str += '/';
|
||||
}
|
||||
|
||||
i.res = IsSubString(i.par, dir_parents_str);
|
||||
}
|
||||
|
||||
|
||||
void dir_level_is(Info & i)
|
||||
{
|
||||
i.res = (cur->request->dir_tab.size() == size_t(Toi(i.par)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static std::vector<Item*> dir_childs_table;
|
||||
static size_t dir_childs_index;
|
||||
// cur->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 != cur->request->id )
|
||||
{
|
||||
dir_childs_reqid = cur->request->id;
|
||||
dir_childs_table.clear();
|
||||
dir_childs_has_parent = false;
|
||||
|
||||
if( !cur->request->dir_tab.empty() )
|
||||
{
|
||||
if( cur->request->dir_tab.size() >= 2 && i.par == L"with_parent")
|
||||
{
|
||||
Item * dir_up = cur->request->dir_tab[cur->request->dir_tab.size()-2];
|
||||
dir_childs_table.push_back(dir_up);
|
||||
dir_childs_has_parent = true;
|
||||
}
|
||||
|
||||
system->dirs.GetDirChilds(cur->request->dir_tab.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() )
|
||||
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" << Toa(dir_childs_table[dir_childs_index]->privileges, 8);
|
||||
}
|
||||
|
||||
|
||||
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 )
|
||||
i.out << puser->name;
|
||||
else
|
||||
{
|
||||
i.out << "~";
|
||||
|
||||
if( !dir_childs_table[dir_childs_index]->guest_name.empty() )
|
||||
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 )
|
||||
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 < cur->request->dir_tab.size();
|
||||
}
|
||||
|
||||
|
||||
void dir_tab_url(Info & i)
|
||||
{
|
||||
if( dir_index < cur->request->dir_tab.size() )
|
||||
i.out << cur->request->dir_tab[dir_index]->url;
|
||||
}
|
||||
|
||||
|
||||
void dir_tab_link(Info & i)
|
||||
{
|
||||
for(size_t a = 0 ; a <= dir_index && a < cur->request->dir_tab.size() ; ++a)
|
||||
{
|
||||
// index zero is a root directory
|
||||
if( a != 0 )
|
||||
i.out << cur->request->dir_tab[a]->url;
|
||||
|
||||
i.out << '/';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void dir_tab_is_root(Info & i)
|
||||
{
|
||||
i.res = (dir_index == 0);
|
||||
}
|
||||
|
||||
|
||||
void dir_tab_subject(Info & i)
|
||||
{
|
||||
if( dir_index < cur->request->dir_tab.size() )
|
||||
i.out << cur->request->dir_tab[dir_index]->subject;
|
||||
}
|
||||
|
||||
|
||||
void dir_last_link_to(Info & i)
|
||||
{
|
||||
i.out << cur->request->dir_tab.back()->link_to;
|
||||
}
|
||||
|
||||
|
||||
void dir_last_is_link_redirect(Info & i)
|
||||
{
|
||||
i.res = cur->request->dir_tab.back()->link_redirect == 1;
|
||||
}
|
||||
|
||||
|
||||
void dir_last_subject(Info & i)
|
||||
{
|
||||
i.out << cur->request->dir_tab.back()->subject;
|
||||
}
|
||||
|
||||
|
||||
void dir_last_user(Info & i)
|
||||
{
|
||||
User * puser = system->users.GetUser(cur->request->dir_tab.back()->user_id);
|
||||
|
||||
if( puser )
|
||||
i.out << puser->name;
|
||||
else
|
||||
{
|
||||
i.out << "~";
|
||||
|
||||
if( !cur->request->dir_tab.back()->guest_name.empty() )
|
||||
i.out << cur->request->dir_tab.back()->guest_name;
|
||||
else
|
||||
i.out << "guest"; // !! dodac do konfiga
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void dir_last_url(Info & i)
|
||||
{
|
||||
i.out << cur->request->dir_tab.back()->url;
|
||||
}
|
||||
|
||||
|
||||
void dir_last_url_is(Info & i)
|
||||
{
|
||||
i.res = cur->request->dir_tab.back()->url == i.par;
|
||||
}
|
||||
|
||||
void dir_last_url_is_no(Info & i)
|
||||
{
|
||||
i.res = cur->request->dir_tab.back()->url != i.par;
|
||||
}
|
||||
|
||||
|
||||
void dir_last_date_creation(Info & i)
|
||||
{
|
||||
PT::Date date = system->ToLocal(cur->request->dir_tab.back()->date_creation);
|
||||
i.out << DateToStr(date.year, date.month, date.day, date.hour, date.min, date.sec);
|
||||
}
|
||||
|
||||
|
||||
void dir_last_date_modification(Info & i)
|
||||
{
|
||||
PT::Date date = system->ToLocal(cur->request->dir_tab.back()->date_modification);
|
||||
i.out << DateToStr(date.year, date.month, date.day, date.hour, date.min, date.sec);
|
||||
}
|
||||
|
||||
|
||||
void dir_last_date_creation_nice(Info & i)
|
||||
{
|
||||
print_date_nice(i, cur->request->dir_tab.back()->date_creation);
|
||||
}
|
||||
|
||||
|
||||
void dir_last_date_modification_nice(Info & i)
|
||||
{
|
||||
print_date_nice(i, cur->request->dir_tab.back()->date_modification);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void dir_last_dates_equal(Info & i)
|
||||
{
|
||||
PT::Date & date1 = cur->request->dir_tab.back()->date_creation;
|
||||
PT::Date & date2 = cur->request->dir_tab.back()->date_modification;
|
||||
|
||||
i.res = date1 == date2;
|
||||
}
|
||||
|
||||
|
||||
void dir_last_users_different(Info & i)
|
||||
{
|
||||
i.res = (cur->request->dir_tab.back()->user_id != cur->request->dir_tab.back()->modification_user_id);
|
||||
}
|
||||
|
||||
|
||||
void dir_last_modification_user(Info & i)
|
||||
{
|
||||
User * puser = system->users.GetUser(cur->request->dir_tab.back()->modification_user_id);
|
||||
print_user_name(i, puser, cur->request->dir_tab.back()->guest_name);
|
||||
}
|
||||
|
||||
|
||||
void dir_last_html_template(Info & i)
|
||||
{
|
||||
i.out << cur->request->dir_tab.back()->html_template;
|
||||
}
|
||||
|
||||
|
||||
void dir_last_has_html_template(Info & i)
|
||||
{
|
||||
i.res = !cur->request->dir_tab.back()->html_template.empty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void dir_last_meta_str(Info & i)
|
||||
{
|
||||
cur->request->dir_tab.back()->meta.Serialize(i.out, true, false);
|
||||
}
|
||||
|
||||
|
||||
void dir_last_meta(Info & i)
|
||||
{
|
||||
space(i, cur->request->dir_tab.back()->meta);
|
||||
}
|
||||
|
||||
|
||||
void dir_last_meta_tab(Info & i)
|
||||
{
|
||||
spaces_tab(i, cur->request->dir_tab.back()->meta);
|
||||
}
|
||||
|
||||
|
||||
void dir_last_meta_tab_value(Info & i)
|
||||
{
|
||||
spaces_tab_value(i, cur->request->dir_tab.back()->meta);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void dir_last_meta_tab_has_next(Info & i)
|
||||
{
|
||||
spaces_tab_has_next(i, cur->request->dir_tab.back()->meta);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void dir_last_admin_meta_str(Info & i)
|
||||
{
|
||||
cur->request->dir_tab.back()->ameta.Serialize(i.out, true, false);
|
||||
}
|
||||
|
||||
|
||||
void dir_last_admin_meta(Info & i)
|
||||
{
|
||||
space(i, cur->request->dir_tab.back()->ameta);
|
||||
}
|
||||
|
||||
|
||||
void dir_last_admin_meta_tab(Info & i)
|
||||
{
|
||||
spaces_tab(i, cur->request->dir_tab.back()->ameta);
|
||||
}
|
||||
|
||||
|
||||
void dir_last_admin_meta_tab_value(Info & i)
|
||||
{
|
||||
spaces_tab_value(i, cur->request->dir_tab.back()->ameta);
|
||||
}
|
||||
|
||||
|
||||
void dir_last_admin_meta_tab_has_next(Info & i)
|
||||
{
|
||||
spaces_tab_has_next(i, cur->request->dir_tab.back()->ameta);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
} // namespace Winix
|
||||
|
204
winixd/templates/doc.cpp
Normal file
204
winixd/templates/doc.cpp
Normal file
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
#include "core/request.h"
|
||||
#include "core/misc.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
static std::wstring doc_proto_str;
|
||||
|
||||
|
||||
|
||||
void doc_title(Info & i)
|
||||
{
|
||||
bool was_dir = false;
|
||||
|
||||
for(size_t a=0 ; a<cur->request->dir_tab.size() ; ++a)
|
||||
{
|
||||
if( !cur->request->dir_tab[a]->subject.empty() )
|
||||
{
|
||||
if( was_dir )
|
||||
i.out << config->title_separator;
|
||||
|
||||
i.out << cur->request->dir_tab[a]->subject;
|
||||
was_dir = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( cur->request->is_item &&
|
||||
!cur->request->item.subject.empty() &&
|
||||
cur->request->item.subject != cur->request->dir_tab.back()->subject
|
||||
)
|
||||
{
|
||||
if( was_dir )
|
||||
i.out << config->title_separator;
|
||||
|
||||
i.out << cur->request->item.subject;
|
||||
was_dir = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void doc_proto(Info & i)
|
||||
{
|
||||
system->PutUrlProto(config->use_ssl, doc_proto_str);
|
||||
i.out << doc_proto_str;
|
||||
}
|
||||
|
||||
|
||||
void doc_proto_static(Info & i)
|
||||
{
|
||||
system->PutUrlProto(config->use_ssl_static, doc_proto_str);
|
||||
i.out << doc_proto_str;
|
||||
}
|
||||
|
||||
|
||||
void doc_proto_common(Info & i)
|
||||
{
|
||||
system->PutUrlProto(config->use_ssl_common, doc_proto_str);
|
||||
i.out << doc_proto_str;
|
||||
}
|
||||
|
||||
|
||||
void doc_base_url(Info & i)
|
||||
{
|
||||
doc_proto(i);
|
||||
|
||||
if( !cur->request->subdomain.empty() )
|
||||
i.out << cur->request->subdomain << '.';
|
||||
|
||||
i.out << config->base_url;
|
||||
}
|
||||
|
||||
|
||||
void doc_base_url_static(Info & i)
|
||||
{
|
||||
doc_proto_static(i);
|
||||
i.out << config->base_url_static;
|
||||
}
|
||||
|
||||
|
||||
void doc_base_url_common(Info & i)
|
||||
{
|
||||
doc_proto_common(i);
|
||||
i.out << config->base_url_common;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void doc_current_url(Info & i)
|
||||
{
|
||||
i.out << cur->request->env_request_uri;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static size_t doc_css_index = 0;
|
||||
|
||||
|
||||
/*
|
||||
cur->session->last_css is set by some javascript wysiwyg editors (ckeditor, tinymce)
|
||||
*/
|
||||
void doc_css_tab(Info & i)
|
||||
{
|
||||
doc_css_index = i.iter;
|
||||
i.res = doc_css_index < cur->session->last_css.size();
|
||||
}
|
||||
|
||||
|
||||
void doc_css_tab_file(Info & i)
|
||||
{
|
||||
if( doc_css_index < cur->session->last_css.size() )
|
||||
i.out << cur->session->last_css[doc_css_index];
|
||||
}
|
||||
|
||||
|
||||
void doc_css_tab_file_is_global(Info & i)
|
||||
{
|
||||
// !! z konfiga wziasc przedrostki
|
||||
|
||||
if( doc_css_index < cur->session->last_css.size() )
|
||||
i.res = IsSubString(L"http://", cur->session->last_css[doc_css_index].c_str()) ||
|
||||
IsSubString(L"https://", cur->session->last_css[doc_css_index].c_str());
|
||||
}
|
||||
|
||||
|
||||
void doc_css_tab_has_next(Info & i)
|
||||
{
|
||||
i.res = (doc_css_index + 1 < cur->session->last_css.size());
|
||||
}
|
||||
|
||||
|
||||
void doc_css_is_empty(Info & i)
|
||||
{
|
||||
i.res = cur->session->last_css.empty();
|
||||
}
|
||||
|
||||
|
||||
void doc_css_is_one(Info & i)
|
||||
{
|
||||
i.res = cur->session->last_css.size() == 1;
|
||||
}
|
||||
|
||||
|
||||
void doc_css_more_than_one(Info & i)
|
||||
{
|
||||
i.res = cur->session->last_css.size() > 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
265
winixd/templates/env.cpp
Normal file
265
winixd/templates/env.cpp
Normal file
@@ -0,0 +1,265 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-2015, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
#include "core/misc.h"
|
||||
#include "functions/functions.h"
|
||||
#include "miscspace.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
|
||||
void env_str(Info & i)
|
||||
{
|
||||
User * puser = cur->session->puser;
|
||||
|
||||
if( puser )
|
||||
puser->env.Serialize(i.out, true, false);
|
||||
}
|
||||
|
||||
|
||||
void env(Info & i)
|
||||
{
|
||||
User * puser = cur->session->puser;
|
||||
|
||||
if( puser )
|
||||
space(i, puser->env);
|
||||
}
|
||||
|
||||
|
||||
void env_tab(Info & i)
|
||||
{
|
||||
User * puser = cur->session->puser;
|
||||
|
||||
if( puser )
|
||||
spaces_tab(i, puser->env);
|
||||
}
|
||||
|
||||
|
||||
void env_tab_value(Info & i)
|
||||
{
|
||||
User * puser = cur->session->puser;
|
||||
|
||||
if( puser )
|
||||
spaces_tab_value(i, puser->env);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void env_tab_has_next(Info & i)
|
||||
{
|
||||
User * puser = cur->session->puser;
|
||||
|
||||
if( puser )
|
||||
spaces_tab_has_next(i, puser->env);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void env_admin_str(Info & i)
|
||||
{
|
||||
User * puser = cur->session->puser;
|
||||
|
||||
if( puser )
|
||||
puser->aenv.Serialize(i.out, true, false);
|
||||
}
|
||||
|
||||
|
||||
void env_admin(Info & i)
|
||||
{
|
||||
User * puser = cur->session->puser;
|
||||
|
||||
if( puser )
|
||||
space(i, puser->aenv);
|
||||
}
|
||||
|
||||
|
||||
void env_admin_tab(Info & i)
|
||||
{
|
||||
User * puser = cur->session->puser;
|
||||
|
||||
if( puser )
|
||||
spaces_tab(i, puser->aenv);
|
||||
}
|
||||
|
||||
|
||||
void env_admin_tab_value(Info & i)
|
||||
{
|
||||
User * puser = cur->session->puser;
|
||||
|
||||
if( puser )
|
||||
spaces_tab_value(i, puser->aenv);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void env_admin_tab_has_next(Info & i)
|
||||
{
|
||||
User * puser = cur->session->puser;
|
||||
|
||||
if( puser )
|
||||
spaces_tab_has_next(i, puser->aenv);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void env_user_admin_env_str(Info & i)
|
||||
{
|
||||
// only an admin is able to see this variables
|
||||
|
||||
if( cur->session->puser && cur->session->puser->super_user )
|
||||
{
|
||||
User * puser = functions->fun_env.GetUser();
|
||||
|
||||
if( puser )
|
||||
i.out << puser->aenv;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void env_user_env_str(Info & i)
|
||||
{
|
||||
User * puser = functions->fun_env.GetUser();
|
||||
|
||||
if( puser )
|
||||
i.out << puser->env;
|
||||
}
|
||||
|
||||
|
||||
void env_user_id(Info & i)
|
||||
{
|
||||
User * puser = functions->fun_env.GetUser();
|
||||
|
||||
if( puser )
|
||||
i.out << puser->id;
|
||||
}
|
||||
|
||||
|
||||
void env_user_name(Info & i)
|
||||
{
|
||||
User * puser = functions->fun_env.GetUser();
|
||||
|
||||
if( puser )
|
||||
i.out << puser->name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static Users::Iterator user_iter;
|
||||
static size_t user_reqid = 0;
|
||||
static size_t user_index; // only information
|
||||
|
||||
|
||||
bool env_user_tab_init()
|
||||
{
|
||||
if( user_reqid != cur->request->id )
|
||||
{
|
||||
user_reqid = cur->request->id;
|
||||
user_iter = system->users.End();
|
||||
}
|
||||
|
||||
return user_iter != system->users.End();
|
||||
}
|
||||
|
||||
|
||||
void env_user_tab(Info & i)
|
||||
{
|
||||
env_user_tab_init();
|
||||
|
||||
if( cur->session->puser && cur->session->puser->super_user )
|
||||
{
|
||||
user_index = i.iter;
|
||||
|
||||
if( i.iter == 0 )
|
||||
user_iter = system->users.Begin();
|
||||
else
|
||||
if( user_iter != system->users.End() )
|
||||
++user_iter;
|
||||
|
||||
i.res = user_iter != system->users.End();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void env_user_tab_id(Info & i)
|
||||
{
|
||||
if( env_user_tab_init() )
|
||||
i.out << user_iter->id;
|
||||
}
|
||||
|
||||
|
||||
void env_user_tab_name(Info & i)
|
||||
{
|
||||
if( env_user_tab_init() )
|
||||
i.out << user_iter->name;
|
||||
}
|
||||
|
||||
|
||||
void env_user_tab_is_current(Info & i)
|
||||
{
|
||||
if( env_user_tab_init() )
|
||||
{
|
||||
User * puser = functions->fun_env.GetUser();
|
||||
|
||||
if( puser )
|
||||
i.res = (user_iter->id == puser->id );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
|
228
winixd/templates/filters.cpp
Normal file
228
winixd/templates/filters.cpp
Normal file
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
#include "core/misc.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
static std::string urlencode_tmp;
|
||||
static std::string qencode_tmp;
|
||||
|
||||
|
||||
void fil_urlencode(Info & i)
|
||||
{
|
||||
UrlEncode(i.in.Str(), urlencode_tmp);
|
||||
i.out << R(urlencode_tmp);
|
||||
}
|
||||
|
||||
|
||||
void fil_qencode(Info & i)
|
||||
{
|
||||
QEncode(i.in.Str(), qencode_tmp);
|
||||
i.out << R(qencode_tmp);
|
||||
}
|
||||
|
||||
|
||||
void fil_capitalize(Info & i)
|
||||
{
|
||||
const std::wstring & str = i.in.Str();
|
||||
|
||||
for(size_t a=0 ; a<str.size() ; ++a)
|
||||
i.out << R(locale.ToCapital(str[a]));
|
||||
}
|
||||
|
||||
|
||||
void fil_tosmall(Info & i)
|
||||
{
|
||||
const std::wstring & str = i.in.Str();
|
||||
|
||||
for(size_t a=0 ; a<str.size() ; ++a)
|
||||
i.out << R(locale.ToSmall(str[a]));
|
||||
}
|
||||
|
||||
|
||||
// a first letter in a sentence will be capitalized
|
||||
void fil_firstup(Info & i)
|
||||
{
|
||||
bool was_dot = true;
|
||||
const std::wstring & str = i.in.Str();
|
||||
|
||||
for(size_t a=0 ; a<str.size() ; ++a)
|
||||
{
|
||||
if( was_dot )
|
||||
{
|
||||
if( str[a]!=' ' && str[a]!='\t' && str[a]!=13 && str[a]!=10 && str[a]!=160 )
|
||||
was_dot = false;
|
||||
|
||||
i.out << R(locale.ToCapital(str[a]));
|
||||
}
|
||||
else
|
||||
{
|
||||
i.out << R(str[a]);
|
||||
}
|
||||
|
||||
if( str[a] == '.' )
|
||||
was_dot = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// a first letter in each word will be capitalized
|
||||
void fil_first_wordup(Info & i)
|
||||
{
|
||||
bool was_white = true;
|
||||
const std::wstring & str = i.in.Str();
|
||||
|
||||
for(size_t a=0 ; a<str.size() ; ++a)
|
||||
{
|
||||
if( was_white )
|
||||
{
|
||||
i.out << R(locale.ToCapital(str[a]));
|
||||
}
|
||||
else
|
||||
{
|
||||
i.out << R(str[a]);
|
||||
}
|
||||
|
||||
was_white = (str[a]==' ' || str[a]=='\t' || str[a]==13 || str[a]==10 || str[a]==160);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool fil_csv_has_colon_or_quote(const std::wstring & str)
|
||||
{
|
||||
for(size_t i=0 ; i<str.size() ; ++i)
|
||||
{
|
||||
if( str[i] == ',' || str[i] == '"' )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void fil_csv_escape(Info & i)
|
||||
{
|
||||
const std::wstring & str = i.in.Str();
|
||||
|
||||
if( fil_csv_has_colon_or_quote(str) )
|
||||
{
|
||||
i.out << R("\"");
|
||||
|
||||
for(size_t a=0 ; a<str.size() ; ++a)
|
||||
{
|
||||
if( str[a] == '"' )
|
||||
i.out << R("\"\"");
|
||||
else
|
||||
i.out << R(str[a]);
|
||||
}
|
||||
|
||||
i.out << R("\"");
|
||||
}
|
||||
else
|
||||
{
|
||||
i.out << R(str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void fil_new_line_to_br(Info & i)
|
||||
{
|
||||
const std::wstring & str = i.in.Str();
|
||||
|
||||
for(size_t a=0 ; a<str.size() ; ++a)
|
||||
{
|
||||
if( str[a] == '\n' )
|
||||
i.out << R("<br>\n");
|
||||
else
|
||||
i.out << R(str[a]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* " -> &#quot;
|
||||
* ' -> ' (' but IE8 has a problem with ')
|
||||
*/
|
||||
void fil_html_quote(Info & i)
|
||||
{
|
||||
const std::wstring & str = i.in.Str();
|
||||
|
||||
for(size_t a=0 ; a<str.size() ; ++a)
|
||||
{
|
||||
if( str[a] == '\"' )
|
||||
i.out << R(""");
|
||||
else
|
||||
if( str[a] == '\'' )
|
||||
i.out << R("'");
|
||||
else
|
||||
i.out << R(str[a]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 10 ->
|
||||
* 13 ->
|
||||
*/
|
||||
void fil_html_newline(Info & i)
|
||||
{
|
||||
const std::wstring & str = i.in.Str();
|
||||
|
||||
for(size_t a=0 ; a<str.size() ; ++a)
|
||||
{
|
||||
if( str[a] == 10 )
|
||||
i.out << R(" ");
|
||||
else
|
||||
if( str[a] == 13 )
|
||||
i.out << R(" ");
|
||||
else
|
||||
i.out << R(str[a]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace Winix
|
||||
|
323
winixd/templates/generic.cpp
Normal file
323
winixd/templates/generic.cpp
Normal file
@@ -0,0 +1,323 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014-2015, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
#include "core/request.h"
|
||||
#include "core/misc.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
|
||||
void ezc_false(Info & i)
|
||||
{
|
||||
i.res = false;
|
||||
}
|
||||
|
||||
|
||||
void ezc_true(Info & i)
|
||||
{
|
||||
i.res = true;
|
||||
}
|
||||
|
||||
|
||||
void ezc_and(Info & i)
|
||||
{
|
||||
if( !i.params.empty() )
|
||||
{
|
||||
i.res = true;
|
||||
|
||||
for(size_t a=0 ; a < i.params.size() ; ++a)
|
||||
{
|
||||
if( !i.params[a].res )
|
||||
{
|
||||
i.res = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ezc_any(Info & i)
|
||||
{
|
||||
ezc_and(i);
|
||||
}
|
||||
|
||||
|
||||
void ezc_or(Info & i)
|
||||
{
|
||||
i.res = false;
|
||||
|
||||
for(size_t a=0 ; a < i.params.size() ; ++a)
|
||||
{
|
||||
if( i.params[a].res )
|
||||
{
|
||||
i.res = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ezc_one(Info & i)
|
||||
{
|
||||
ezc_or(i);
|
||||
}
|
||||
|
||||
|
||||
void ezc_and_not(Info & i)
|
||||
{
|
||||
if( !i.params.empty() )
|
||||
{
|
||||
i.res = true;
|
||||
|
||||
for(size_t a=0 ; a < i.params.size() ; ++a)
|
||||
{
|
||||
if( i.params[a].res )
|
||||
{
|
||||
i.res = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ezc_any_not(Info & i)
|
||||
{
|
||||
ezc_and_not(i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ezc_or_not(Info & i)
|
||||
{
|
||||
i.res = false;
|
||||
|
||||
for(size_t a=0 ; a < i.params.size() ; ++a)
|
||||
{
|
||||
if( !i.params[a].res )
|
||||
{
|
||||
i.res = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ezc_one_not(Info & i)
|
||||
{
|
||||
ezc_or_not(i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ezc_not(Info & i)
|
||||
{
|
||||
if( !i.params.empty() )
|
||||
i.res = !i.params[0].res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* compare strings
|
||||
*/
|
||||
void cmp(Info & i)
|
||||
{
|
||||
if( i.params.size() >= 2 )
|
||||
{
|
||||
i.res = true;
|
||||
|
||||
for(size_t a=0 ; a < i.params.size() - 1 ; ++a)
|
||||
{
|
||||
if( i.params[a].str != i.params[a+1].str )
|
||||
{
|
||||
i.res = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void is(Info & i)
|
||||
{
|
||||
cmp(i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void is_not(Info & i)
|
||||
{
|
||||
cmp(i);
|
||||
i.res = !i.res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void is_empty(Info & i)
|
||||
{
|
||||
i.res = true;
|
||||
|
||||
for(size_t a=0 ; a < i.params.size() ; ++a)
|
||||
{
|
||||
if( !i.params[a].str.empty() )
|
||||
{
|
||||
i.res = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void is_not_empty(Info & i)
|
||||
{
|
||||
is_empty(i);
|
||||
i.res = !i.res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// IMPROVE ME !! may we need such a filter too?
|
||||
void trim(Info & i)
|
||||
{
|
||||
for(size_t a=0 ; a < i.params.size() ; ++a)
|
||||
{
|
||||
// trimming with new lines too
|
||||
TrimWhite(i.params[a].str, true);
|
||||
i.out << R(i.params[a].str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void to_lower(Info & i)
|
||||
{
|
||||
for(size_t a=0 ; a < i.params.size() ; ++a)
|
||||
{
|
||||
for(size_t z=0 ; z < i.params[a].str.size() ; ++z)
|
||||
i.out << R(locale.ToSmall(i.params[a].str[z]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void to_upper(Info & i)
|
||||
{
|
||||
for(size_t a=0 ; a < i.params.size() ; ++a)
|
||||
{
|
||||
for(size_t z=0 ; z < i.params[a].str.size() ; ++z)
|
||||
i.out << R(locale.ToCapital(i.params[a].str[z]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool index_find_last_for_statement(Info & i, size_t & last_for_index)
|
||||
{
|
||||
last_for_index = i.stack_index;
|
||||
|
||||
do
|
||||
{
|
||||
if( i.stack_tab[last_for_index].is_for )
|
||||
return true;
|
||||
}
|
||||
while( last_for_index-- > 0 );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void index(Info & i)
|
||||
{
|
||||
size_t for_index;
|
||||
|
||||
if( !index_find_last_for_statement(i, for_index) )
|
||||
return;
|
||||
|
||||
if( i.params.size() != 1 )
|
||||
{
|
||||
i.out << i.stack_tab[for_index].iter;
|
||||
return;
|
||||
}
|
||||
|
||||
if( i.par == L"odd" )
|
||||
{
|
||||
i.res = (i.stack_tab[for_index].iter & 1) == 1;
|
||||
}
|
||||
else
|
||||
if( i.par == L"even" )
|
||||
{
|
||||
i.res = (i.stack_tab[for_index].iter & 1) == 0;
|
||||
}
|
||||
else
|
||||
if( i.par == L"first" )
|
||||
{
|
||||
i.res = i.stack_tab[for_index].iter == 0;
|
||||
}
|
||||
else
|
||||
if( IsSize(i.par, true) )
|
||||
{
|
||||
|
||||
size_t number = static_cast<size_t>(Tol(SkipWhite(i.par.c_str(), true)));
|
||||
i.res = (i.stack_tab[for_index].iter == number);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void str(Info & i)
|
||||
{
|
||||
for(size_t a=0 ; a < i.params.size() ; ++a)
|
||||
i.out << R(i.params[a].str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace Winix
|
||||
|
607
winixd/templates/htmltextstream.cpp
Normal file
607
winixd/templates/htmltextstream.cpp
Normal file
@@ -0,0 +1,607 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2015, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "htmltextstream.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
HtmlTextStream::HtmlTextStream()
|
||||
{
|
||||
escape = true;
|
||||
}
|
||||
|
||||
|
||||
void HtmlTextStream::Clear()
|
||||
{
|
||||
escape = true;
|
||||
TextStream<std::wstring>::Clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
without escaping
|
||||
*/
|
||||
|
||||
HtmlTextStream & HtmlTextStream::PutChar(char c)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(c);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::PutChar(wchar_t c)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(c);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::PutText(const char * str)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::PutText(const char * str, size_t len)
|
||||
{
|
||||
TextStream<std::wstring>::Write(str, len);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::PutText(const std::string * str)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::PutText(const std::string & str)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::PutText(const wchar_t * str)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::PutText(const std::wstring * str)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::PutText(const std::wstring & str)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(const RawText<const char*> & raw)
|
||||
{
|
||||
return PutText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(const RawText<const wchar_t*> & raw)
|
||||
{
|
||||
return PutText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(RawText<const std::string*> raw)
|
||||
{
|
||||
return PutText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(RawText<const std::wstring*> raw)
|
||||
{
|
||||
return PutText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(RawText<std::string> raw)
|
||||
{
|
||||
return PutText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(RawText<std::wstring> raw)
|
||||
{
|
||||
return PutText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(RawText<char> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(RawText<wchar_t> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(RawText<int> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(RawText<long> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(RawText<unsigned int> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(RawText<unsigned long> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(RawText<double> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(RawText<void*> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(RawText<PT::Space> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(RawText<PT::Date> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::Write(const char * buf, size_t len)
|
||||
{
|
||||
TextStream<std::wstring>::Write(buf, len);
|
||||
return *this;
|
||||
}
|
||||
|
||||
HtmlTextStream & HtmlTextStream::Write(const wchar_t * buf, size_t len)
|
||||
{
|
||||
TextStream<std::wstring>::Write(buf, len);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::write(const char * buf, size_t len)
|
||||
{
|
||||
TextStream<std::wstring>::write(buf, len);
|
||||
return *this;
|
||||
}
|
||||
|
||||
HtmlTextStream & HtmlTextStream::write(const wchar_t * buf, size_t len)
|
||||
{
|
||||
TextStream<std::wstring>::write(buf, len);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
with escaping
|
||||
*/
|
||||
|
||||
|
||||
void HtmlTextStream::Escape(bool escape_characters)
|
||||
{
|
||||
escape = escape_characters;
|
||||
}
|
||||
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::ETextPutChar(char c)
|
||||
{
|
||||
return ETextPutChar(static_cast<wchar_t>(c));
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::ETextPutChar(wchar_t c)
|
||||
{
|
||||
if( c == '<' )
|
||||
buffer += L"<";
|
||||
else
|
||||
if( c == '>' )
|
||||
buffer += L">";
|
||||
else
|
||||
if( c == '&' )
|
||||
buffer += L"&";
|
||||
else
|
||||
if( c == '\"' )
|
||||
buffer += L""";
|
||||
else
|
||||
if( c == '\'' )
|
||||
buffer += L"'"; // (it is "'" but IE8 has a problem with ')
|
||||
else
|
||||
if( c == 10 )
|
||||
buffer += L" ";
|
||||
else
|
||||
if( c == 13 )
|
||||
buffer += L" ";
|
||||
else
|
||||
if( c != 0 ) // !! CHECK ME may it should be changed to something like '�';
|
||||
buffer += c;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::EPutText(const char * str)
|
||||
{
|
||||
PT::UTF8ToWide(str, tmp_string);
|
||||
|
||||
for(size_t i=0 ; i<tmp_string.size() ; ++i)
|
||||
ETextPutChar(tmp_string[i]);
|
||||
|
||||
tmp_string.clear();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::EPutText(const char * str, size_t len)
|
||||
{
|
||||
PT::UTF8ToWide(str, len, tmp_string);
|
||||
|
||||
for(size_t i=0 ; i<tmp_string.size() ; ++i)
|
||||
ETextPutChar(tmp_string[i]);
|
||||
|
||||
tmp_string.clear();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::EPutText(const std::string * str)
|
||||
{
|
||||
return EPutText(*str);
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::EPutText(const std::string & str)
|
||||
{
|
||||
PT::UTF8ToWide(str, tmp_string);
|
||||
|
||||
for(size_t i=0 ; i<tmp_string.size() ; ++i)
|
||||
ETextPutChar(tmp_string[i]);
|
||||
|
||||
tmp_string.clear();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::EPutText(const wchar_t * str)
|
||||
{
|
||||
for( ; *str ; ++str )
|
||||
ETextPutChar(*str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::EPutText(const wchar_t * str, size_t len)
|
||||
{
|
||||
for(size_t i=0 ; i<len ; ++i)
|
||||
ETextPutChar(str[i]);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::EPutText(const std::wstring * str)
|
||||
{
|
||||
return EPutText(str->c_str(), str->size());
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::EPutText(const std::wstring & str)
|
||||
{
|
||||
return EPutText(str.c_str(), str.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(const char * str)
|
||||
{
|
||||
if( escape )
|
||||
EPutText(str);
|
||||
else
|
||||
PutText(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(const std::string * str)
|
||||
{
|
||||
if( escape )
|
||||
EPutText(str);
|
||||
else
|
||||
PutText(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(const std::string & str)
|
||||
{
|
||||
if( escape )
|
||||
EPutText(str);
|
||||
else
|
||||
PutText(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(const wchar_t * str)
|
||||
{
|
||||
if( escape )
|
||||
EPutText(str);
|
||||
else
|
||||
PutText(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(const std::wstring * str)
|
||||
{
|
||||
if( escape )
|
||||
EPutText(str);
|
||||
else
|
||||
PutText(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(const std::wstring & str)
|
||||
{
|
||||
if( escape )
|
||||
EPutText(str);
|
||||
else
|
||||
PutText(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(char v)
|
||||
{
|
||||
if( escape )
|
||||
ETextPutChar(v);
|
||||
else
|
||||
PutChar(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(wchar_t v)
|
||||
{
|
||||
if( escape )
|
||||
ETextPutChar(v);
|
||||
else
|
||||
PutChar(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(int v)
|
||||
{
|
||||
/*
|
||||
* int, long and others don't have to be escaped
|
||||
* (they consist of digits only: '0' - '9' and other characters which
|
||||
* don't have to be escaped)
|
||||
*/
|
||||
TextStream<std::wstring>::operator<<(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(long v)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(unsigned int v)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(unsigned long v)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(double v)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(const void * v)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(const PT::Space & space)
|
||||
{
|
||||
if( escape )
|
||||
{
|
||||
space.Serialize(*this, true, false);
|
||||
|
||||
/*
|
||||
tmp_stream.Clear();
|
||||
// !! IMPROVE ME
|
||||
// we can calculate how many memory is needed beforehand
|
||||
space.Serialize(tmp_stream, true, false);
|
||||
operator<<(tmp_stream.Str());
|
||||
tmp_stream.Clear();
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(space);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(const PT::Date & date)
|
||||
{
|
||||
if( escape )
|
||||
{
|
||||
date.Serialize(*this);
|
||||
|
||||
/*
|
||||
tmp_stream.Clear();
|
||||
// !! IMPROVE ME
|
||||
// we can calculate how many memory is needed beforehand
|
||||
date.Serialize(tmp_stream);
|
||||
operator<<(tmp_stream.Str());
|
||||
tmp_stream.Clear();
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(date);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
|
250
winixd/templates/htmltextstream.h
Normal file
250
winixd/templates/htmltextstream.h
Normal file
@@ -0,0 +1,250 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2015, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_templates_htmltextstream
|
||||
#define headerfile_winix_templates_htmltextstream
|
||||
|
||||
#include <ctime>
|
||||
#include "core/textstream.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
/*
|
||||
HtmlTextStream is used as a buffer for creating a html page
|
||||
By default all operators<< escape its string arguments. If you don't want
|
||||
to escape an argument you should use a helper function R() (raw argument)
|
||||
note: you have to define the function yourself, we do not provide it
|
||||
because such a short name would make a mess in namespaces
|
||||
|
||||
sample:
|
||||
create a helper function R as follows:
|
||||
|
||||
template<class RawType>
|
||||
HtmlTextStream::RawText<RawType> R(const RawType & par)
|
||||
{
|
||||
return HtmlTextStream::RawText<RawType>(par);
|
||||
}
|
||||
|
||||
now you can use HtmlTextStream in an easy way:
|
||||
HtmlTextStream page;
|
||||
std::string key = "some <b>string</b>";
|
||||
page << key << R("<h2>html goes here</h2>");
|
||||
only html tags "<b>" and "</b>" will be correctly escaped
|
||||
|
||||
currently following characters are escaped:
|
||||
< -> <
|
||||
> -> >
|
||||
& ->
|
||||
" -> "
|
||||
' -> ' (it is "'" but IE8 has a problem with ')
|
||||
10 ->
|
||||
13 ->
|
||||
*/
|
||||
class HtmlTextStream : public TextStream<std::wstring>
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
HtmlTextStream();
|
||||
|
||||
|
||||
/*
|
||||
* clearing the buffer and setting 'escape' flag to true
|
||||
*/
|
||||
void Clear();
|
||||
|
||||
|
||||
/*
|
||||
a helper struct to select a proper operator<<
|
||||
(for non-escaping versions of these operators)
|
||||
*/
|
||||
template<class RawType>
|
||||
struct RawText
|
||||
{
|
||||
const RawType & par;
|
||||
|
||||
RawText(const RawText<RawType> & p) : par(p.par) {}
|
||||
RawText(const RawType & p) : par(p) {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
without escaping
|
||||
*/
|
||||
HtmlTextStream & PutChar(char);
|
||||
HtmlTextStream & PutChar(wchar_t);
|
||||
|
||||
HtmlTextStream & PutText(const char *);
|
||||
HtmlTextStream & PutText(const char *, size_t len);
|
||||
HtmlTextStream & PutText(const std::string *);
|
||||
HtmlTextStream & PutText(const std::string &);
|
||||
HtmlTextStream & PutText(const wchar_t * str);
|
||||
HtmlTextStream & PutText(const wchar_t * str, size_t len);
|
||||
HtmlTextStream & PutText(const std::wstring * str);
|
||||
HtmlTextStream & PutText(const std::wstring & str);
|
||||
|
||||
/*
|
||||
we need this template operator for such calling:
|
||||
HtmlTextStream_object << R("some string");
|
||||
"some string" is actually a table (not a pointer)
|
||||
*/
|
||||
template<size_t str_size>
|
||||
HtmlTextStream & operator<<(const RawText<char [str_size]> & raw) { return PutText(raw.par); }
|
||||
|
||||
template<size_t str_size>
|
||||
HtmlTextStream & operator<<(const RawText<wchar_t [str_size]> & raw) { return PutText(raw.par); }
|
||||
|
||||
HtmlTextStream & operator<<(const RawText<const char*> & raw);
|
||||
HtmlTextStream & operator<<(const RawText<const wchar_t*> & raw);
|
||||
HtmlTextStream & operator<<(RawText<const std::string*> raw);
|
||||
HtmlTextStream & operator<<(RawText<const std::wstring*> raw);
|
||||
HtmlTextStream & operator<<(RawText<std::string> raw);
|
||||
HtmlTextStream & operator<<(RawText<std::wstring> raw);
|
||||
|
||||
HtmlTextStream & operator<<(RawText<char> raw);
|
||||
HtmlTextStream & operator<<(RawText<wchar_t> raw);
|
||||
HtmlTextStream & operator<<(RawText<int> raw);
|
||||
HtmlTextStream & operator<<(RawText<long> raw);
|
||||
HtmlTextStream & operator<<(RawText<unsigned int> raw);
|
||||
HtmlTextStream & operator<<(RawText<unsigned long> raw);
|
||||
HtmlTextStream & operator<<(RawText<double> raw);
|
||||
HtmlTextStream & operator<<(RawText<void*> raw);
|
||||
HtmlTextStream & operator<<(RawText<PT::Space> raw);
|
||||
HtmlTextStream & operator<<(RawText<PT::Date> raw);
|
||||
|
||||
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
|
||||
HtmlTextStream & operator<<(RawText<PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> > raw);
|
||||
|
||||
|
||||
|
||||
// 'write' don't escapes too
|
||||
// with these methods you can write a zero character too
|
||||
HtmlTextStream & Write(const char * buf, size_t len);
|
||||
HtmlTextStream & Write(const wchar_t * buf, size_t len);
|
||||
// for compatibility with standard library (Ezc uses it)
|
||||
HtmlTextStream & write(const char * buf, size_t len);
|
||||
HtmlTextStream & write(const wchar_t * buf, size_t len);
|
||||
|
||||
|
||||
/*
|
||||
with escaping
|
||||
*/
|
||||
|
||||
HtmlTextStream & ETextPutChar(char c);
|
||||
HtmlTextStream & ETextPutChar(wchar_t c);
|
||||
|
||||
HtmlTextStream & EPutText(const char * str);
|
||||
HtmlTextStream & EPutText(const char * str, size_t len);
|
||||
HtmlTextStream & EPutText(const std::string * str);
|
||||
HtmlTextStream & EPutText(const std::string & str);
|
||||
HtmlTextStream & EPutText(const wchar_t * str);
|
||||
HtmlTextStream & EPutText(const wchar_t * str, size_t len);
|
||||
HtmlTextStream & EPutText(const std::wstring * str);
|
||||
HtmlTextStream & EPutText(const std::wstring & str);
|
||||
|
||||
/*
|
||||
* by default all operator<< shown below use escaping
|
||||
* but you can turn it off by calling Escape(false)
|
||||
*/
|
||||
void Escape(bool escape_characters);
|
||||
|
||||
HtmlTextStream & operator<<(const char * str);
|
||||
HtmlTextStream & operator<<(const std::string * str);
|
||||
HtmlTextStream & operator<<(const std::string & str);
|
||||
HtmlTextStream & operator<<(const wchar_t * str);
|
||||
HtmlTextStream & operator<<(const std::wstring * str);
|
||||
HtmlTextStream & operator<<(const std::wstring & str);
|
||||
HtmlTextStream & operator<<(char);
|
||||
HtmlTextStream & operator<<(wchar_t);
|
||||
HtmlTextStream & operator<<(int);
|
||||
HtmlTextStream & operator<<(long);
|
||||
HtmlTextStream & operator<<(unsigned int);
|
||||
HtmlTextStream & operator<<(unsigned long);
|
||||
HtmlTextStream & operator<<(double);
|
||||
HtmlTextStream & operator<<(const void *);
|
||||
HtmlTextStream & operator<<(const PT::Space & space);
|
||||
HtmlTextStream & operator<<(const PT::Date & Date);
|
||||
|
||||
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
|
||||
HtmlTextStream & operator<<(const PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> & arg);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
//TextStream<std::wstring> tmp_stream;
|
||||
std::wstring tmp_string;
|
||||
bool escape;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
|
||||
HtmlTextStream & HtmlTextStream::operator<<(RawText<PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> > raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
|
||||
HtmlTextStream & HtmlTextStream::operator<<(const PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> & arg)
|
||||
{
|
||||
typename PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size>::const_iterator i;
|
||||
|
||||
if( escape )
|
||||
{
|
||||
/*
|
||||
* warning: char* (utf-8) string will not be correctly handled here
|
||||
*/
|
||||
for(i=arg.begin() ; i != arg.end() ; ++i)
|
||||
ETextPutChar(*i);
|
||||
}
|
||||
else
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(arg);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
#endif
|
||||
|
118
winixd/templates/indexpatterns.cpp
Normal file
118
winixd/templates/indexpatterns.cpp
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "indexpatterns.h"
|
||||
#include "core/log.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
void IndexPatterns::SetPatterns(Patterns * ppatterns)
|
||||
{
|
||||
patterns = ppatterns;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Ezc::Pattern * IndexPatterns::Get(const std::wstring & file, size_t lang)
|
||||
{
|
||||
Tab::iterator i = tab.find(file);
|
||||
|
||||
if( i == tab.end() )
|
||||
return 0;
|
||||
|
||||
return patterns->Get(i->second.index, lang);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void IndexPatterns::Add(const std::wstring & file)
|
||||
{
|
||||
std::pair<Tab::iterator, bool> res = tab.insert( std::make_pair(file, Template()) );
|
||||
|
||||
Template & tmpl = res.first->second;
|
||||
|
||||
// mark the pattern to not delete
|
||||
tmpl.to_delete = false;
|
||||
|
||||
if( res.second )
|
||||
tmpl.index = patterns->Add(file);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void IndexPatterns::MarkAllToDelete()
|
||||
{
|
||||
Tab::iterator i;
|
||||
|
||||
for(i=tab.begin() ; i!=tab.end() ; ++i)
|
||||
i->second.to_delete = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void IndexPatterns::DeleteMarked()
|
||||
{
|
||||
Tab::iterator i = tab.begin();
|
||||
Tab::iterator next;
|
||||
|
||||
while( i != tab.end() )
|
||||
{
|
||||
next = i;
|
||||
++next;
|
||||
|
||||
if( i->second.to_delete )
|
||||
{
|
||||
patterns->Erase(i->second.index);
|
||||
tab.erase(i);
|
||||
}
|
||||
|
||||
i = next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void IndexPatterns::Clear()
|
||||
{
|
||||
tab.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
106
winixd/templates/indexpatterns.h
Normal file
106
winixd/templates/indexpatterns.h
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_templates_indexpatterns
|
||||
#define headerfile_winix_templates_indexpatterns
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "ezc.h"
|
||||
#include "patterns.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
class IndexPatterns
|
||||
{
|
||||
public:
|
||||
|
||||
void SetPatterns(Patterns * ppatterns);
|
||||
|
||||
|
||||
/*
|
||||
adding a new pattern
|
||||
if such a pattern exists the method only unmarks the pattern from deleting
|
||||
*/
|
||||
void Add(const std::wstring & file);
|
||||
|
||||
|
||||
/*
|
||||
returning a pattern
|
||||
can return null pointer if there is not such a pattern
|
||||
*/
|
||||
Ezc::Pattern * Get(const std::wstring & file, size_t lang);
|
||||
|
||||
|
||||
/*
|
||||
marking all patterns as ready to delete
|
||||
*/
|
||||
void MarkAllToDelete();
|
||||
|
||||
|
||||
/*
|
||||
delete marked patterns
|
||||
if you have called Add(pattern_name) then such a pattern is not deleted
|
||||
*/
|
||||
void DeleteMarked();
|
||||
|
||||
|
||||
/*
|
||||
deleting all patterns
|
||||
*/
|
||||
void Clear();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
Patterns * patterns;
|
||||
|
||||
struct Template
|
||||
{
|
||||
bool to_delete;
|
||||
size_t index;
|
||||
};
|
||||
|
||||
typedef std::map<std::wstring, Template> Tab;
|
||||
Tab tab;
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
#endif
|
135
winixd/templates/insert.cpp
Normal file
135
winixd/templates/insert.cpp
Normal file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
#include "misc.h"
|
||||
#include "core/request.h"
|
||||
#include "core/misc.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
// 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();
|
||||
|
||||
InitGenerator(info.ezc_gen);
|
||||
info.ezc_gen.SetPattern(*pat);
|
||||
info.ezc_gen.Generate(info.run_content);
|
||||
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
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
209
winixd/templates/ipban.cpp
Normal file
209
winixd/templates/ipban.cpp
Normal file
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
#include "core/request.h"
|
||||
#include "core/misc.h"
|
||||
#include "functions/functions.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
void ipban_is_current_ip_banned(Info & i)
|
||||
{
|
||||
if( cur->session->ip_ban )
|
||||
{
|
||||
i.res = cur->session->ip_ban->IsIPBanned();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ipban_current_ip_expires_time(Info & i)
|
||||
{
|
||||
if( cur->session->ip_ban && cur->session->ip_ban->expires != 0 )
|
||||
{
|
||||
PT::Date date = cur->session->ip_ban->expires;
|
||||
i.out << date << " UTC";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ipban_is_login_allowed_from_this_ip(Info & i)
|
||||
{
|
||||
i.res = !functions->fun_login.CannotLoginFromCurrentIP();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static size_t ipban_index;
|
||||
|
||||
|
||||
void ipban_tab(Info & i)
|
||||
{
|
||||
ipban_index = i.iter;
|
||||
i.res = ipban_index < session_manager->BanListSize();
|
||||
}
|
||||
|
||||
|
||||
void ipban_tab_id(Info & i)
|
||||
{
|
||||
if( ipban_index < session_manager->BanListSize() )
|
||||
i.out << ipban_index;
|
||||
}
|
||||
|
||||
|
||||
void ipban_tab_ip(Info & i)
|
||||
{
|
||||
if( ipban_index < session_manager->BanListSize() )
|
||||
{
|
||||
PT::WTextStream buf = IPToStr(session_manager->GetIPBan(ipban_index).ip);
|
||||
i.out << buf;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ipban_tab_incorrect_login(Info & i)
|
||||
{
|
||||
if( ipban_index < session_manager->BanListSize() )
|
||||
i.out << session_manager->GetIPBan(ipban_index).incorrect_login_events;
|
||||
}
|
||||
|
||||
|
||||
void ipban_tab_broken_encoded_cookie(Info & i)
|
||||
{
|
||||
if( ipban_index < session_manager->BanListSize() )
|
||||
i.out << session_manager->GetIPBan(ipban_index).broken_encoded_cookie_events;
|
||||
}
|
||||
|
||||
|
||||
void ipban_tab_session_hijacking(Info & i)
|
||||
{
|
||||
if( ipban_index < session_manager->BanListSize() )
|
||||
i.out << session_manager->GetIPBan(ipban_index).session_hijacking_events;
|
||||
}
|
||||
|
||||
|
||||
void ipban_tab_no_session_cookie(Info & i)
|
||||
{
|
||||
if( ipban_index < session_manager->BanListSize() )
|
||||
i.out << session_manager->GetIPBan(ipban_index).no_session_cookie_events;
|
||||
}
|
||||
|
||||
|
||||
void ipban_tab_ban_level(Info & i)
|
||||
{
|
||||
if( ipban_index < session_manager->BanListSize() )
|
||||
{
|
||||
IPBan & ipban = session_manager->GetIPBan(ipban_index);
|
||||
|
||||
if( ipban.HasFlag(WINIX_IPBAN_FLAG_BAN_LEVEL3) )
|
||||
i.out << "3";
|
||||
else
|
||||
if( ipban.HasFlag(WINIX_IPBAN_FLAG_BAN_LEVEL2) )
|
||||
i.out << "2";
|
||||
else
|
||||
if( ipban.HasFlag(WINIX_IPBAN_FLAG_BAN_LEVEL1) )
|
||||
i.out << "1";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ipban_tab_has_active_flag(Info & i)
|
||||
{
|
||||
if( ipban_index < session_manager->BanListSize() )
|
||||
i.res = session_manager->GetIPBan(ipban_index).HasFlag(WINIX_IPBAN_FLAG_ACTIVE);
|
||||
}
|
||||
|
||||
|
||||
void ipban_tab_expires(Info & i)
|
||||
{
|
||||
if( ipban_index < session_manager->BanListSize() )
|
||||
{
|
||||
IPBan & ipban = session_manager->GetIPBan(ipban_index);
|
||||
|
||||
if( ipban.expires != 0 )
|
||||
{
|
||||
time_t expires_local = system->ToLocal(ipban.expires);
|
||||
PT::Date date(expires_local);
|
||||
i.out << date;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ipban_tab_last_used(Info & i)
|
||||
{
|
||||
if( ipban_index < session_manager->BanListSize() )
|
||||
{
|
||||
IPBan & ipban = session_manager->GetIPBan(ipban_index);
|
||||
|
||||
if( ipban.last_used != 0 )
|
||||
{
|
||||
time_t last_used_local = system->ToLocal(ipban.last_used);
|
||||
PT::Date date(last_used_local);
|
||||
i.out << date;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ipban_tab_is_logging_allowed(Info & i)
|
||||
{
|
||||
if( ipban_index < session_manager->BanListSize() )
|
||||
{
|
||||
IPBan & ipban = session_manager->GetIPBan(ipban_index);
|
||||
i.res = !functions->fun_login.CannotLoginFrom(ipban);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
|
||||
|
885
winixd/templates/item.cpp
Normal file
885
winixd/templates/item.cpp
Normal file
@@ -0,0 +1,885 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
#include "misc.h"
|
||||
#include "core/request.h"
|
||||
#include "core/misc.h"
|
||||
#include "core/bbcodeparser.h"
|
||||
#include "core/textstream.h"
|
||||
#include "miscspace.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
static BBCODEParser bbcode_parser;
|
||||
static HtmlTextStream item_run_content;
|
||||
static EzcGen ezc_generator;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void item_is(Info & i)
|
||||
{
|
||||
i.res = cur->request->is_item;
|
||||
}
|
||||
|
||||
|
||||
void item_no_is(Info & i)
|
||||
{
|
||||
i.res = !cur->request->is_item;
|
||||
}
|
||||
|
||||
|
||||
void item_id(Info & i)
|
||||
{
|
||||
i.out << cur->request->item.id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_subject(Info & i)
|
||||
{
|
||||
i.out << cur->request->item.subject;
|
||||
}
|
||||
|
||||
|
||||
void item_subject_noescape(Info & i)
|
||||
{
|
||||
i.out << R(cur->request->item.subject);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_content(Info & i)
|
||||
{
|
||||
i.out << cur->request->item.content;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_content_noescape(Info & i)
|
||||
{
|
||||
i.out << R(cur->request->item.content);
|
||||
}
|
||||
|
||||
|
||||
void item_content_type_is(Item & item, Info & i)
|
||||
{
|
||||
i.res = false;
|
||||
|
||||
if( item.content_type == Item::ct_text && i.par == L"text" )
|
||||
i.res = true;
|
||||
else
|
||||
if( item.content_type == Item::ct_formatted_text && i.par == L"formatted text" )
|
||||
i.res = true;
|
||||
else
|
||||
if( item.content_type == Item::ct_html && i.par == L"html" )
|
||||
i.res = true;
|
||||
else
|
||||
if( item.content_type == Item::ct_bbcode && i.par == L"bbcode" )
|
||||
i.res = true;
|
||||
else
|
||||
if( item.content_type == Item::ct_raw && i.par == L"raw" )
|
||||
i.res = true;
|
||||
}
|
||||
|
||||
|
||||
void item_content_type_is(Info & i)
|
||||
{
|
||||
item_content_type_is(cur->request->item, i);
|
||||
}
|
||||
|
||||
|
||||
void item_print_content(HtmlTextStream & out, const std::wstring & content, Item::ContentType content_type)
|
||||
{
|
||||
if( content_type == Item::ct_text )
|
||||
{
|
||||
out << content;
|
||||
}
|
||||
else
|
||||
if( content_type == Item::ct_formatted_text )
|
||||
{
|
||||
HtmlEscapeFormTxt(out, content);
|
||||
}
|
||||
else
|
||||
if( content_type == Item::ct_html || content_type == Item::ct_raw )
|
||||
{
|
||||
out << R(content);
|
||||
}
|
||||
else
|
||||
if( content_type == Item::ct_bbcode )
|
||||
{
|
||||
static std::wstring out_temp;
|
||||
out_temp.clear();
|
||||
out_temp.reserve(content.size()*2);
|
||||
|
||||
bbcode_parser.Filter(content.c_str(), out_temp);
|
||||
out << R(out_temp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void item_content_is_empty(Info & i)
|
||||
{
|
||||
i.res = cur->request->item.content.empty();
|
||||
}
|
||||
|
||||
void item_print_content(Info & i)
|
||||
{
|
||||
item_print_content(i.out, cur->request->item.content, cur->request->item.content_type);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_privileges(Info & i)
|
||||
{
|
||||
i.out << Toa(cur->request->item.privileges, 8);
|
||||
}
|
||||
|
||||
|
||||
void item_dir(Info & i)
|
||||
{
|
||||
dir(i);
|
||||
}
|
||||
|
||||
|
||||
void item_url(Info & i)
|
||||
{
|
||||
i.out << cur->request->item.url;
|
||||
}
|
||||
|
||||
|
||||
void item_url_is(Info & i)
|
||||
{
|
||||
if( !cur->request->is_item )
|
||||
return; // default false
|
||||
|
||||
i.res = (cur->request->item.url == i.par);
|
||||
}
|
||||
|
||||
|
||||
void item_url_is_no(Info & i)
|
||||
{
|
||||
if( !cur->request->is_item )
|
||||
i.res = true;
|
||||
else
|
||||
i.res = (cur->request->item.url != i.par);
|
||||
}
|
||||
|
||||
|
||||
void item_link(Info & i)
|
||||
{
|
||||
doc_proto(i);
|
||||
|
||||
if( !cur->request->subdomain.empty() )
|
||||
i.out << cur->request->subdomain << '.';
|
||||
|
||||
i.out << config->base_url;
|
||||
item_dir(i);
|
||||
item_url(i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void item_filetype_is_none(Info & i)
|
||||
{
|
||||
i.res = cur->request->item.file_type == WINIX_ITEM_FILETYPE_NONE;
|
||||
}
|
||||
|
||||
|
||||
void item_filetype_is_image(Info & i)
|
||||
{
|
||||
i.res = cur->request->item.file_type == WINIX_ITEM_FILETYPE_IMAGE;
|
||||
}
|
||||
|
||||
|
||||
void item_has_static_file(Info & i)
|
||||
{
|
||||
i.res = cur->request->item.file_type != WINIX_ITEM_FILETYPE_NONE && !cur->request->item.file_path.empty();
|
||||
}
|
||||
|
||||
|
||||
void item_has_thumb(Info & i)
|
||||
{
|
||||
i.res = cur->request->item.has_thumb;
|
||||
}
|
||||
|
||||
|
||||
void item_can_read(Info & i)
|
||||
{
|
||||
i.res = system->HasReadAccess(cur->request->item);
|
||||
}
|
||||
|
||||
|
||||
void item_can_write(Info & i)
|
||||
{
|
||||
i.res = system->HasWriteAccess(cur->request->item);
|
||||
}
|
||||
|
||||
|
||||
void item_can_remove(Info & i)
|
||||
{
|
||||
// !! tutaj trzeba bedzie cos innego zrobic
|
||||
// zwlaszcza jak dojdzie sticky bit
|
||||
i.res = system->HasWriteAccess(*cur->request->dir_tab.back());
|
||||
}
|
||||
|
||||
|
||||
void item_user(Info & i)
|
||||
{
|
||||
User * puser = system->users.GetUser(cur->request->item.user_id);
|
||||
print_user_name(i, puser, cur->request->item.guest_name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_modification_user(Info & i)
|
||||
{
|
||||
User * puser = system->users.GetUser(cur->request->item.modification_user_id);
|
||||
print_user_name(i, puser, cur->request->item.guest_name);
|
||||
}
|
||||
|
||||
|
||||
void item_users_different(Info & i)
|
||||
{
|
||||
i.res = (cur->request->item.user_id != cur->request->item.modification_user_id);
|
||||
}
|
||||
|
||||
|
||||
void item_date_creation(Info & i)
|
||||
{
|
||||
PT::Date date = system->ToLocal(cur->request->item.date_creation);
|
||||
i.out << DateToStr(date.year, date.month, date.day, date.hour, date.min, date.sec);
|
||||
}
|
||||
|
||||
|
||||
void item_date_modification(Info & i)
|
||||
{
|
||||
PT::Date date = system->ToLocal(cur->request->item.date_modification);
|
||||
i.out << DateToStr(date.year, date.month, date.day, date.hour, date.min, date.sec);
|
||||
}
|
||||
|
||||
|
||||
void item_date_creation_nice(Info & i)
|
||||
{
|
||||
print_date_nice(i, cur->request->item.date_creation);
|
||||
}
|
||||
|
||||
|
||||
void item_date_modification_nice(Info & i)
|
||||
{
|
||||
print_date_nice(i, cur->request->item.date_modification);
|
||||
}
|
||||
|
||||
|
||||
void item_dates_equal(Info & i)
|
||||
{
|
||||
PT::Date & date1 = cur->request->item.date_creation;
|
||||
PT::Date & date2 = cur->request->item.date_modification;
|
||||
|
||||
i.res = date1 == date2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_run(Info & i)
|
||||
{
|
||||
if( !cur->request->is_item )
|
||||
{
|
||||
i.out << "<!-- there is no an item to run -->";
|
||||
return;
|
||||
}
|
||||
|
||||
if( system->HasReadExecAccess(cur->request->item) )
|
||||
{
|
||||
Ezc::Pattern * p = pattern_cacher.GetPattern(cur->request->item);
|
||||
|
||||
item_run_content.Clear();
|
||||
InitGenerator(ezc_generator);
|
||||
ezc_generator.SetPattern(*p);
|
||||
|
||||
if( config->allow_ezc_out_in_executable_items )
|
||||
ezc_generator.Generate(item_run_content, cur->request->out_streams);
|
||||
else
|
||||
ezc_generator.Generate(item_run_content);
|
||||
|
||||
item_print_content(i.out, item_run_content.Str(), cur->request->item.content_type);
|
||||
}
|
||||
else
|
||||
{
|
||||
i.out << "<!-- run: permission denied -->";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void item_guest_name(Info & i)
|
||||
{
|
||||
i.out << cur->request->item.guest_name;
|
||||
}
|
||||
|
||||
|
||||
void item_html_template(Info & i)
|
||||
{
|
||||
i.out << cur->request->item.html_template;
|
||||
}
|
||||
|
||||
|
||||
void item_has_html_template(Info & i)
|
||||
{
|
||||
i.res = !cur->request->item.html_template.empty();
|
||||
}
|
||||
|
||||
|
||||
void item_type_is_dir(Info & i)
|
||||
{
|
||||
i.res = cur->request->item.type == Item::dir;
|
||||
}
|
||||
|
||||
|
||||
void item_type_is_file(Info & i)
|
||||
{
|
||||
i.res = cur->request->item.type == Item::file;
|
||||
}
|
||||
|
||||
|
||||
void item_type_is_symlink(Info & i)
|
||||
{
|
||||
i.res = cur->request->item.type == Item::symlink;
|
||||
}
|
||||
|
||||
|
||||
void item_is_link_to(Info & i)
|
||||
{
|
||||
i.res = !cur->request->item.link_to.empty();
|
||||
}
|
||||
|
||||
|
||||
void item_link_to(Info & i)
|
||||
{
|
||||
i.out << cur->request->item.link_to;
|
||||
}
|
||||
|
||||
|
||||
void item_is_link_redirect(Info & i)
|
||||
{
|
||||
i.res = cur->request->item.link_redirect == 1;
|
||||
}
|
||||
|
||||
void item_file_size(Info & i)
|
||||
{
|
||||
i.res = cur->request->item.file_size;
|
||||
}
|
||||
|
||||
void item_sort(Info & i)
|
||||
{
|
||||
i.out << cur->request->item.sort_index;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_meta_str(Info & i)
|
||||
{
|
||||
cur->request->item.meta.Serialize(i.out, true, false);
|
||||
}
|
||||
|
||||
|
||||
void item_meta(Info & i)
|
||||
{
|
||||
space(i, cur->request->last_item->meta); // !! a new interface (last_item instead of item)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void item_meta_tab(Info & i)
|
||||
{
|
||||
spaces_tab(i, cur->request->last_item->meta);
|
||||
}
|
||||
|
||||
|
||||
void item_meta_tab_value(Info & i)
|
||||
{
|
||||
spaces_tab_value(i, cur->request->last_item->meta);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_meta_tab_has_next(Info & i)
|
||||
{
|
||||
spaces_tab_has_next(i, cur->request->last_item->meta);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void item_admin_meta_str(Info & i)
|
||||
{
|
||||
cur->request->item.ameta.Serialize(i.out, true, false);
|
||||
}
|
||||
|
||||
|
||||
void item_admin_meta(Info & i)
|
||||
{
|
||||
space(i, cur->request->last_item->ameta);
|
||||
}
|
||||
|
||||
|
||||
void item_admin_meta_tab(Info & i)
|
||||
{
|
||||
spaces_tab(i, cur->request->last_item->ameta);
|
||||
}
|
||||
|
||||
|
||||
void item_admin_meta_tab_value(Info & i)
|
||||
{
|
||||
spaces_tab_value(i, cur->request->last_item->ameta);
|
||||
}
|
||||
|
||||
|
||||
void item_admin_meta_tab_has_next(Info & i)
|
||||
{
|
||||
spaces_tab_has_next(i, cur->request->last_item->ameta);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static size_t item_index;
|
||||
|
||||
|
||||
void item_tab(Info & i)
|
||||
{
|
||||
item_index = i.iter;
|
||||
i.res = item_index < cur->request->item_tab.size();
|
||||
}
|
||||
|
||||
|
||||
void item_tab_index(Info & i)
|
||||
{
|
||||
i.out << item_index;
|
||||
}
|
||||
|
||||
|
||||
void item_tab_id(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
i.out << cur->request->item_tab[item_index].id;
|
||||
}
|
||||
|
||||
|
||||
void item_tab_subject(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
i.out << cur->request->item_tab[item_index].subject;
|
||||
}
|
||||
|
||||
void item_tab_subject_noescape(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
i.out << R(cur->request->item_tab[item_index].subject);
|
||||
}
|
||||
|
||||
|
||||
void item_tab_content(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
i.out << cur->request->item_tab[item_index].content;
|
||||
}
|
||||
|
||||
|
||||
void item_tab_content_noescape(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
i.out << R(cur->request->item_tab[item_index].content);
|
||||
}
|
||||
|
||||
|
||||
void item_tab_print_content(Info & i)
|
||||
{
|
||||
if( item_index >= cur->request->item_tab.size() )
|
||||
return;
|
||||
|
||||
std::wstring & content = cur->request->item_tab[item_index].content;
|
||||
Item::ContentType type = cur->request->item_tab[item_index].content_type;
|
||||
|
||||
item_print_content(i.out, content, type);
|
||||
}
|
||||
|
||||
|
||||
void item_tab_privileges(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
i.out << "0" << Toa(cur->request->item_tab[item_index].privileges, 8);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_tab_dir(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
{
|
||||
std::wstring path;
|
||||
|
||||
if( system->dirs.MakePath(cur->request->item_tab[item_index].parent_id, path) )
|
||||
i.out << path;
|
||||
else
|
||||
i.out << "/the path does not exist/"; // !! do konfiga
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void item_tab_url(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
i.out << cur->request->item_tab[item_index].url;
|
||||
}
|
||||
|
||||
|
||||
void item_tab_link(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
{
|
||||
doc_proto(i);
|
||||
|
||||
if( !cur->request->subdomain.empty() )
|
||||
i.out << cur->request->subdomain << '.';
|
||||
|
||||
i.out << config->base_url;
|
||||
item_tab_dir(i);
|
||||
item_tab_url(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void item_tab_filetype_is_none(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
i.res = cur->request->item_tab[item_index].file_type == WINIX_ITEM_FILETYPE_NONE;
|
||||
}
|
||||
|
||||
|
||||
void item_tab_filetype_is_image(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
i.res = cur->request->item_tab[item_index].file_type == WINIX_ITEM_FILETYPE_IMAGE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_tab_can_read(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
{
|
||||
if( system->HasReadAccess(cur->request->item_tab[item_index]) )
|
||||
i.res = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void item_tab_can_write(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
{
|
||||
if( system->HasWriteAccess(cur->request->item_tab[item_index]) )
|
||||
i.res = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void item_tab_user(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
{
|
||||
User * puser = system->users.GetUser(cur->request->item_tab[item_index].user_id);
|
||||
print_user_name(i, puser, cur->request->item_tab[item_index].guest_name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_tab_modification_user(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
{
|
||||
User * puser = system->users.GetUser(cur->request->item_tab[item_index].modification_user_id);
|
||||
print_user_name(i, puser, cur->request->item_tab[item_index].guest_name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_tab_users_different(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
{
|
||||
i.res = (cur->request->item_tab[item_index].user_id != cur->request->item_tab[item_index].modification_user_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_tab_group(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
{
|
||||
long group_id = cur->request->item_tab[item_index].group_id;
|
||||
Group * pgroup = system->groups.GetGroup(group_id);
|
||||
|
||||
if( pgroup )
|
||||
i.out << pgroup->name;
|
||||
else
|
||||
i.out << group_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void item_tab_date_creation(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
{
|
||||
PT::Date date = system->ToLocal(cur->request->item_tab[item_index].date_creation);
|
||||
i.out << DateToStr(date.year, date.month, date.day, date.hour, date.min, date.sec);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void item_tab_date_modification(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
{
|
||||
PT::Date date = system->ToLocal(cur->request->item_tab[item_index].date_modification);
|
||||
i.out << DateToStr(date.year, date.month, date.day, date.hour, date.min, date.sec);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void item_tab_date_creation_nice(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
{
|
||||
print_date_nice(i, cur->request->item_tab[item_index].date_creation);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_tab_date_modification_nice(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
{
|
||||
print_date_nice(i, cur->request->item_tab[item_index].date_modification);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void item_tab_dates_equal(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
{
|
||||
PT::Date & date1 = cur->request->item_tab[item_index].date_creation;
|
||||
PT::Date & date2 = cur->request->item_tab[item_index].date_modification;
|
||||
|
||||
i.res = date1 == date2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void item_tab_run(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
{
|
||||
if( system->HasReadExecAccess(cur->request->item_tab[item_index]) )
|
||||
{
|
||||
Ezc::Pattern * p = pattern_cacher.GetPattern(cur->request->item_tab[item_index]);
|
||||
item_run_content.Clear();
|
||||
InitGenerator(ezc_generator);
|
||||
ezc_generator.SetPattern(*p);
|
||||
|
||||
if( config->allow_ezc_out_in_executable_items )
|
||||
ezc_generator.Generate(item_run_content, cur->request->out_streams);
|
||||
else
|
||||
ezc_generator.Generate(item_run_content);
|
||||
|
||||
item_print_content(i.out, item_run_content.Str(), cur->request->item_tab[item_index].content_type);
|
||||
}
|
||||
else
|
||||
{
|
||||
i.out << "<!-- run: permission denied -->";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void item_tab_can_use_emacs(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
{
|
||||
// !!
|
||||
//i.res = cur->request->CanUseEmacs(cur->request->item_tab[item_index], true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void item_tab_has_static_file(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
{
|
||||
i.res = cur->request->item_tab[item_index].file_type != WINIX_ITEM_FILETYPE_NONE &&
|
||||
!cur->request->item_tab[item_index].file_path.empty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void item_tab_has_thumb(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
i.res = cur->request->item_tab[item_index].has_thumb;
|
||||
}
|
||||
|
||||
|
||||
void item_tab_type_is_dir(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
i.res = cur->request->item_tab[item_index].type == Item::dir;
|
||||
}
|
||||
|
||||
|
||||
void item_tab_type_is_file(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
i.res = cur->request->item_tab[item_index].type == Item::file;
|
||||
}
|
||||
|
||||
|
||||
void item_tab_type_is_symlink(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
i.res = cur->request->item_tab[item_index].type == Item::symlink;
|
||||
}
|
||||
|
||||
|
||||
void item_tab_is_link_to(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
i.res = !cur->request->item_tab[item_index].link_to.empty();
|
||||
}
|
||||
|
||||
|
||||
void item_tab_link_to(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
i.out << cur->request->item_tab[item_index].link_to;
|
||||
}
|
||||
|
||||
|
||||
void item_tab_is_link_redirect(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
i.res = cur->request->item_tab[item_index].link_redirect == 1;
|
||||
}
|
||||
|
||||
|
||||
void item_tab_file_size(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
i.out << cur->request->item_tab[item_index].file_size;
|
||||
}
|
||||
|
||||
void item_tab_sort(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
i.out << cur->request->item_tab[item_index].sort_index;
|
||||
}
|
||||
|
||||
void item_tab_has_next(Info & i)
|
||||
{
|
||||
i.res = item_index + 1 < cur->request->item_tab.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_tab_meta_str(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
cur->request->item_tab[item_index].meta.Serialize(i.out, true, false);
|
||||
}
|
||||
|
||||
|
||||
void item_tab_meta(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
space(i, cur->request->item_tab[item_index].meta);
|
||||
}
|
||||
|
||||
|
||||
void item_tab_meta_tab(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
spaces_tab(i, cur->request->item_tab[item_index].meta);
|
||||
}
|
||||
|
||||
|
||||
void item_tab_meta_tab_value(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
spaces_tab_value(i, cur->request->item_tab[item_index].meta);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_tab_meta_tab_has_next(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
spaces_tab_has_next(i, cur->request->item_tab[item_index].meta);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
|
119
winixd/templates/last.cpp
Normal file
119
winixd/templates/last.cpp
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
#include "../core/lastcontainer.h"
|
||||
#include "../core/request.h"
|
||||
#include "../core/misc.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
static size_t last_reqid = 0;
|
||||
static LastContainer::Iterator last_iterator;
|
||||
|
||||
|
||||
bool last_init()
|
||||
{
|
||||
if( last_reqid != cur->request->id )
|
||||
{
|
||||
last_reqid = cur->request->id;
|
||||
last_iterator = system->users.last.Begin();
|
||||
}
|
||||
|
||||
return last_iterator != system->users.last.End();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void last_tab(Info & i)
|
||||
{
|
||||
last_init();
|
||||
|
||||
if( i.iter != 0 && last_iterator != system->users.last.End() )
|
||||
++last_iterator;
|
||||
|
||||
i.res = last_iterator != system->users.last.End();
|
||||
}
|
||||
|
||||
|
||||
void last_tab_name(Info & i)
|
||||
{
|
||||
if( !last_init() )
|
||||
return;
|
||||
|
||||
i.out << last_iterator->name;
|
||||
}
|
||||
|
||||
|
||||
void last_tab_ip(Info & i)
|
||||
{
|
||||
if( !last_init() )
|
||||
return;
|
||||
|
||||
i.out << IpToStr(last_iterator->ip);
|
||||
}
|
||||
|
||||
|
||||
void last_tab_start(Info & i)
|
||||
{
|
||||
if( !last_init() )
|
||||
return;
|
||||
|
||||
i.out << DateToStr(last_iterator->start);
|
||||
}
|
||||
|
||||
|
||||
void last_tab_end(Info & i)
|
||||
{
|
||||
if( !last_init() )
|
||||
return;
|
||||
|
||||
if( last_iterator->IsLoggedOut() )
|
||||
i.out << DateToStr(last_iterator->end);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
|
875
winixd/templates/locale.cpp
Normal file
875
winixd/templates/locale.cpp
Normal file
@@ -0,0 +1,875 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include "locale.h"
|
||||
#include "core/log.h"
|
||||
#include "core/misc.h"
|
||||
#include "utf8/utf8.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
Locale::Locale()
|
||||
{
|
||||
default_lang = 0;
|
||||
current_lang = 0;
|
||||
}
|
||||
|
||||
|
||||
void Locale::SetLocaleFiles(const std::vector<std::wstring> & files)
|
||||
{
|
||||
locale_files = files;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Locale::SetLocaleMaxId(size_t max_id)
|
||||
{
|
||||
if( max_id > 1000 )
|
||||
{
|
||||
max_id = 1000;
|
||||
log << log1 << "Locale: locale_max_id is too big (changed to 1000)" << logend;
|
||||
}
|
||||
|
||||
size_t old_size = locale_indices.size();
|
||||
locale_indices.resize(max_id + 1);
|
||||
|
||||
for(size_t i=old_size ; i<locale_indices.size() ; ++i)
|
||||
locale_indices[i] = size_t(-1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool Locale::HasLanguage(size_t lang_id)
|
||||
{
|
||||
if( lang_id < locale_indices.size() )
|
||||
return locale_indices[lang_id] < locale_tab.size();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Locale::ReadFile(const char * dir, const char * dir_def, const char * file)
|
||||
{
|
||||
bool read = false;
|
||||
temp_space.Clear();
|
||||
|
||||
if( dir_def && ReadFile(dir_def, file) )
|
||||
read = true;
|
||||
|
||||
if( dir && ReadFile(dir, file) )
|
||||
read = true;
|
||||
|
||||
if( read )
|
||||
AddLocale(file);
|
||||
else
|
||||
log << log1 << "Locale: can't open locale's file: " << file << logend;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Locale::ReadFile(const char * dir, const char * file)
|
||||
{
|
||||
bool read = false;
|
||||
|
||||
file_name = dir;
|
||||
file_name += '/';
|
||||
file_name += file;
|
||||
|
||||
loc_parser.SplitSingle(true);
|
||||
loc_parser.SetSpace(temp_space);
|
||||
|
||||
PT::SpaceParser::Status status = loc_parser.Parse(file_name);
|
||||
|
||||
if( status == PT::SpaceParser::ok )
|
||||
{
|
||||
read = true;
|
||||
log << log3 << "Locale: read locale from: " << file_name << logend;
|
||||
}
|
||||
else
|
||||
if( status == PT::SpaceParser::syntax_error )
|
||||
{
|
||||
log << log1 << "Locale: syntax error in: " << file_name << " in line: " << loc_parser.line << logend;
|
||||
}
|
||||
|
||||
return read;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Locale::AddLocale(const char * file)
|
||||
{
|
||||
std::wstring * id_str = temp_space.GetValue(L"winix_locale_id");
|
||||
|
||||
if( !id_str )
|
||||
{
|
||||
log << log1 << "Locale: winix_locale_id field should be defined in locale file: "
|
||||
<< file << " (skipping)" << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
size_t id = (size_t)Tol(*id_str);
|
||||
|
||||
if( id >= locale_indices.size() )
|
||||
{
|
||||
log << log1 << "Locale: locale identifier is greater than locale_max_id (skipping)" << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
locale_tab.push_back(temp_space);
|
||||
locale_indices[id] = locale_tab.size() - 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Locale::ReadSubstTable(const char * dir, const char * dir_def)
|
||||
{
|
||||
bool read = false;
|
||||
|
||||
subst_url.clear();
|
||||
subst_smalllet.clear();
|
||||
subst_capitallet.clear();
|
||||
subst_sort.clear();
|
||||
|
||||
if( dir_def && ReadSubstTable(dir_def) )
|
||||
read = true;
|
||||
|
||||
if( dir && ReadSubstTable(dir) )
|
||||
read = true;
|
||||
|
||||
if( !read )
|
||||
log << log1 << "Locale: can't open file for characters substitution" << logend;
|
||||
}
|
||||
|
||||
|
||||
bool Locale::ReadSubstTable(const char * dir)
|
||||
{
|
||||
bool read = false;
|
||||
|
||||
file_name = dir;
|
||||
file_name += '/';
|
||||
file_name += "substitute";
|
||||
|
||||
loc_parser.SplitSingle(true);
|
||||
loc_parser.SetSpace(temp_space);
|
||||
|
||||
if( loc_parser.Parse(file_name) == PT::SpaceParser::ok )
|
||||
{
|
||||
read = true;
|
||||
CreateSubstVector(subst_url, temp_space.table_single[L"url_original"], temp_space.table_single[L"url_changeto"]);
|
||||
CreateSubstVector(subst_smalllet, temp_space.table_single[L"smallleters"], temp_space.table_single[L"capitalics"]);
|
||||
CreateSubstVector(subst_capitallet, temp_space.table_single[L"capitalics"], temp_space.table_single[L"smallleters"]);
|
||||
CreateSubstSortVector(subst_sort, temp_space.table[L"sort"]);
|
||||
|
||||
log << log3 << "Locale: read characters substitution tables from: " << file_name << logend;
|
||||
}
|
||||
|
||||
return read;
|
||||
}
|
||||
|
||||
|
||||
void Locale::CreateSubstVector(std::vector<SubstItem> & vect, const std::wstring & tab1, const std::wstring & tab2)
|
||||
{
|
||||
size_t i, min_size = (tab1.size() < tab2.size()) ? tab1.size() : tab2.size();
|
||||
SubstItem s;
|
||||
|
||||
vect.clear();
|
||||
|
||||
if( min_size == 0 )
|
||||
return;
|
||||
|
||||
vect.reserve(min_size);
|
||||
|
||||
for(i=0 ; i<min_size ; ++i)
|
||||
{
|
||||
s.from = tab1[i];
|
||||
s.to = tab2[i];
|
||||
vect.push_back(s);
|
||||
}
|
||||
|
||||
std::sort(vect.begin(), vect.end());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Locale::CreateSubstSortVector(std::vector<SubstItem> & vect, std::vector<std::wstring> & tab)
|
||||
{
|
||||
SubstItem s;
|
||||
|
||||
vect.clear();
|
||||
|
||||
if( tab.empty() )
|
||||
return;
|
||||
|
||||
vect.reserve(tab.size());
|
||||
|
||||
for(size_t i=0 ; i<tab.size() ; ++i)
|
||||
{
|
||||
if( tab[i].size() >= 3 )
|
||||
{
|
||||
s.from = tab[i][0];
|
||||
s.to = tab[i][1];
|
||||
s.index = Toi(&tab[i][2]);
|
||||
|
||||
vect.push_back(s);
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(vect.begin(), vect.end());
|
||||
}
|
||||
|
||||
|
||||
void Locale::Read(const char * dir, const char * dir_def)
|
||||
{
|
||||
locale_tab.clear();
|
||||
|
||||
for(size_t i=0 ; i<locale_indices.size() ; ++i)
|
||||
locale_indices[i] = size_t(-1);
|
||||
|
||||
for(size_t i=0 ; i<locale_files.size() ; ++i)
|
||||
{
|
||||
PT::WideToUTF8(locale_files[i], locale_filea);
|
||||
ReadFile(dir, dir_def, locale_filea.c_str());
|
||||
}
|
||||
|
||||
ReadSubstTable(dir, dir_def);
|
||||
}
|
||||
|
||||
|
||||
void Locale::Read(const std::string & dir, const std::string & dir_def)
|
||||
{
|
||||
if( dir_def.empty() )
|
||||
Read(dir.c_str());
|
||||
else
|
||||
Read(dir.c_str(), dir_def.c_str());
|
||||
}
|
||||
|
||||
|
||||
void Locale::Read(const wchar_t * dir, const wchar_t * dir_def)
|
||||
{
|
||||
PT::WideToUTF8(dir, adir1);
|
||||
|
||||
if( !dir_def )
|
||||
{
|
||||
Read(adir1.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
PT::WideToUTF8(dir_def, adir2);
|
||||
Read(adir1.c_str(), adir2.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Locale::Read(const std::wstring & dir, const std::wstring & dir_def)
|
||||
{
|
||||
if( dir_def.empty() )
|
||||
Read(dir.c_str());
|
||||
else
|
||||
Read(dir.c_str(), dir_def.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Locale::SetCurLang(size_t lang_id)
|
||||
{
|
||||
current_lang = lang_id;
|
||||
}
|
||||
|
||||
|
||||
size_t Locale::GetCurLang() const
|
||||
{
|
||||
return current_lang;
|
||||
}
|
||||
|
||||
|
||||
void Locale::SetDefLang(size_t lang_id)
|
||||
{
|
||||
default_lang = lang_id;
|
||||
}
|
||||
|
||||
|
||||
size_t Locale::GetDefLang() const
|
||||
{
|
||||
return default_lang;
|
||||
}
|
||||
|
||||
|
||||
bool Locale::IsKey(const wchar_t * key, bool try_default_too)
|
||||
{
|
||||
key_str = key;
|
||||
return IsKey(key_str, try_default_too);
|
||||
}
|
||||
|
||||
|
||||
bool Locale::IsKey(const std::wstring & key, bool try_default_too) const
|
||||
{
|
||||
return IsKey(key, current_lang, try_default_too);
|
||||
}
|
||||
|
||||
|
||||
bool Locale::IsKey(const wchar_t * key, size_t lang_id, bool try_default_too)
|
||||
{
|
||||
key_str = key;
|
||||
return IsKey(key_str, lang_id, try_default_too);
|
||||
}
|
||||
|
||||
|
||||
|
||||
const std::wstring * Locale::GetKeyInLanguage(const std::wstring & key, size_t lang_id) const
|
||||
{
|
||||
if( lang_id < locale_indices.size() )
|
||||
{
|
||||
size_t index = locale_indices[lang_id];
|
||||
|
||||
if( index < locale_tab.size() )
|
||||
return locale_tab[index].GetValue(key);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool Locale::IsKey(const std::wstring & key, size_t lang_id, bool try_default_too) const
|
||||
{
|
||||
if( GetKeyInLanguage(key, lang_id) != 0 )
|
||||
return true;
|
||||
|
||||
if( !try_default_too || lang_id == default_lang )
|
||||
return false;
|
||||
|
||||
return GetKeyInLanguage(key, default_lang) != 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const std::wstring & Locale::Get(const wchar_t * key, bool try_default_too)
|
||||
{
|
||||
key_str = key;
|
||||
return Get(key_str, try_default_too);
|
||||
}
|
||||
|
||||
|
||||
const std::wstring & Locale::Get(const std::wstring & key, bool try_default_too) const
|
||||
{
|
||||
return Get(key, current_lang, try_default_too);
|
||||
}
|
||||
|
||||
|
||||
const std::wstring & Locale::Get(const wchar_t * key, size_t lang_id, bool try_default_too)
|
||||
{
|
||||
key_str = key;
|
||||
return Get(key_str, lang_id, try_default_too);
|
||||
}
|
||||
|
||||
|
||||
|
||||
const std::wstring & Locale::Get(const std::wstring & key, size_t lang_id, bool try_default_too) const
|
||||
{
|
||||
const std::wstring * value = GetKeyInLanguage(key, lang_id);
|
||||
|
||||
if( value )
|
||||
return *value;
|
||||
|
||||
if( !try_default_too || lang_id == default_lang )
|
||||
return empty;
|
||||
|
||||
value = GetKeyInLanguage(key, default_lang);
|
||||
|
||||
if( value )
|
||||
return *value;
|
||||
|
||||
return empty;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool Locale::IsList(const wchar_t * key, bool try_default_too)
|
||||
{
|
||||
key_str = key;
|
||||
return IsList(key_str, try_default_too);
|
||||
}
|
||||
|
||||
|
||||
bool Locale::IsList(const std::wstring & key, bool try_default_too) const
|
||||
{
|
||||
return IsList(key, current_lang, try_default_too);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Locale::IsList(const wchar_t * key, size_t lang_id, bool try_default_too)
|
||||
{
|
||||
key_str = key;
|
||||
return IsList(key_str, lang_id, try_default_too);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Locale::IsList(const std::wstring & key, size_t lang_id, bool try_default_too) const
|
||||
{
|
||||
if( GetListInLanguage(key, lang_id) != 0 )
|
||||
return true;
|
||||
|
||||
if( !try_default_too || lang_id == default_lang )
|
||||
return false;
|
||||
|
||||
return GetListInLanguage(key, default_lang) != 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
const std::vector<std::wstring> & Locale::GetList(const wchar_t * key, bool try_default_too)
|
||||
{
|
||||
key_str = key;
|
||||
return GetList(key_str, try_default_too);
|
||||
}
|
||||
|
||||
|
||||
const std::vector<std::wstring> & Locale::GetList(const std::wstring & key, bool try_default_too) const
|
||||
{
|
||||
return GetList(key, current_lang, try_default_too);
|
||||
}
|
||||
|
||||
|
||||
const std::vector<std::wstring> & Locale::GetList(const wchar_t * key, size_t lang_id, bool try_default_too)
|
||||
{
|
||||
key_str = key;
|
||||
return GetList(key_str, lang_id, try_default_too);
|
||||
}
|
||||
|
||||
|
||||
|
||||
const std::vector<std::wstring> * Locale::GetListInLanguage(const std::wstring & key, size_t lang_id) const
|
||||
{
|
||||
if( lang_id < locale_indices.size() )
|
||||
{
|
||||
size_t index = locale_indices[lang_id];
|
||||
|
||||
if( index < locale_tab.size() )
|
||||
{
|
||||
PT::Space::Table::const_iterator i = locale_tab[index].table.find(key);
|
||||
|
||||
if( i != locale_tab[index].table.end() )
|
||||
return &i->second;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
const std::vector<std::wstring> & Locale::GetList(const std::wstring & key,
|
||||
size_t lang_id, bool try_default_too) const
|
||||
{
|
||||
const std::vector<std::wstring> * list = GetListInLanguage(key, lang_id);
|
||||
|
||||
if( list )
|
||||
return *list;
|
||||
|
||||
if( !try_default_too || lang_id == default_lang )
|
||||
return empty_list;
|
||||
|
||||
list = GetListInLanguage(key, default_lang);
|
||||
|
||||
if( list )
|
||||
return *list;
|
||||
|
||||
return empty_list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
size_t Locale::IdToIndex(size_t lang_id)
|
||||
{
|
||||
if( lang_id < locale_indices.size() )
|
||||
return locale_indices[lang_id]; // here can be size(-1) as well
|
||||
|
||||
return size_t(-1);
|
||||
}
|
||||
|
||||
|
||||
size_t Locale::Size() const
|
||||
{
|
||||
return locale_tab.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Locale::IsKeyByIndex(const wchar_t * key, size_t index, bool try_default_too)
|
||||
{
|
||||
key_str = key;
|
||||
return IsKeyByIndex(key_str, index, try_default_too);
|
||||
}
|
||||
|
||||
|
||||
bool Locale::IsKeyByIndex(const std::wstring & key, size_t index, bool try_default_too) const
|
||||
{
|
||||
if( index < locale_tab.size() )
|
||||
{
|
||||
if( locale_tab[index].GetValue(key) != 0 )
|
||||
return true;
|
||||
}
|
||||
|
||||
if( try_default_too )
|
||||
{
|
||||
if( GetKeyInLanguage(key, default_lang) != 0 )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
const std::wstring & Locale::GetByIndex(const wchar_t * key, size_t index, bool try_default_too)
|
||||
{
|
||||
key_str = key;
|
||||
return GetByIndex(key_str, index, try_default_too);
|
||||
}
|
||||
|
||||
|
||||
const std::wstring & Locale::GetByIndex(const std::wstring & key, size_t index,
|
||||
bool try_default_too) const
|
||||
{
|
||||
if( index < locale_tab.size() )
|
||||
{
|
||||
const std::wstring * value = locale_tab[index].GetValue(key);
|
||||
|
||||
if( value )
|
||||
return *value;
|
||||
}
|
||||
|
||||
if( try_default_too )
|
||||
{
|
||||
const std::wstring * value = GetKeyInLanguage(key, default_lang);
|
||||
|
||||
if( value )
|
||||
return *value;
|
||||
}
|
||||
|
||||
return empty;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool Locale::IsListByIndex(const wchar_t * key, size_t index, bool try_default_too)
|
||||
{
|
||||
key_str = key;
|
||||
return IsListByIndex(key_str, index, try_default_too);
|
||||
}
|
||||
|
||||
|
||||
bool Locale::IsListByIndex(const std::wstring & key, size_t index, bool try_default_too) const
|
||||
{
|
||||
if( index < locale_tab.size() )
|
||||
{
|
||||
PT::Space::Table::const_iterator i = locale_tab[index].table.find(key);
|
||||
|
||||
if( i != locale_tab[index].table.end() )
|
||||
return true;
|
||||
}
|
||||
|
||||
if( try_default_too )
|
||||
return GetListInLanguage(key, default_lang) != 0;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const std::vector<std::wstring> & Locale::GetListByIndex(const wchar_t * key,
|
||||
size_t index, bool try_default_too)
|
||||
{
|
||||
key_str = key;
|
||||
return GetListByIndex(key_str, index, try_default_too);
|
||||
}
|
||||
|
||||
|
||||
const std::vector<std::wstring> & Locale::GetListByIndex(const std::wstring & key,
|
||||
size_t index, bool try_default_too) const
|
||||
{
|
||||
if( index < locale_tab.size() )
|
||||
{
|
||||
PT::Space::Table::const_iterator i = locale_tab[index].table.find(key);
|
||||
|
||||
if( i != locale_tab[index].table.end() )
|
||||
return i->second;
|
||||
}
|
||||
|
||||
if( try_default_too )
|
||||
{
|
||||
const std::vector<std::wstring> * value = GetListInLanguage(key, default_lang);
|
||||
|
||||
if( value )
|
||||
return *value;
|
||||
}
|
||||
|
||||
return empty_list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
binary search in vect
|
||||
vect should be sorted by 'from'
|
||||
|
||||
if the 'val' is found in vect[].from then its index is returned (index to vect table)
|
||||
else vect.size() is returned
|
||||
*/
|
||||
size_t Locale::SubstFindIndex(const std::vector<SubstItem> & vect, wchar_t val)
|
||||
{
|
||||
if( vect.empty() )
|
||||
return vect.size();
|
||||
|
||||
size_t o1 = 0;
|
||||
size_t o2 = vect.size() - 1;
|
||||
|
||||
if( val < vect[o1].from )
|
||||
return vect.size();
|
||||
|
||||
if( val == vect[o1].from )
|
||||
return o1;
|
||||
|
||||
if( val > vect[o2].from )
|
||||
return vect.size();
|
||||
|
||||
if( val == vect[o2].from )
|
||||
return o2;
|
||||
|
||||
while( o1 + 1 < o2 )
|
||||
{
|
||||
size_t o = (o1 + o2) / 2;
|
||||
|
||||
if( val == vect[o].from )
|
||||
return o;
|
||||
|
||||
if( val < vect[o].from )
|
||||
o2 = o;
|
||||
else
|
||||
o1 = o;
|
||||
}
|
||||
|
||||
return vect.size();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
binary search in vect
|
||||
vect should be sorted by 'from'
|
||||
|
||||
if the 'val' is found in vect[].from then vect[].to is returned
|
||||
else 'val' is returned
|
||||
*/
|
||||
wchar_t Locale::SubstFind(const std::vector<SubstItem> & vect, wchar_t val)
|
||||
{
|
||||
size_t i = SubstFindIndex(vect, val);
|
||||
|
||||
if( i == vect.size() )
|
||||
{
|
||||
return val;
|
||||
}
|
||||
else
|
||||
{
|
||||
return vect[i].to;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
wchar_t Locale::UrlSubst(wchar_t c)
|
||||
{
|
||||
return SubstFind(subst_url, c);
|
||||
}
|
||||
|
||||
|
||||
void Locale::UrlSubst(std::wstring & str)
|
||||
{
|
||||
for(size_t i=0 ; i<str.size() ; ++i)
|
||||
str[i] = UrlSubst(str[i]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
wchar_t Locale::ToSmall(wchar_t c)
|
||||
{
|
||||
if( c>='A' && c<='Z' )
|
||||
return c - 'A' + 'a';
|
||||
|
||||
return SubstFind(subst_capitallet, c);
|
||||
}
|
||||
|
||||
|
||||
void Locale::ToSmall(std::wstring & str)
|
||||
{
|
||||
for(size_t i=0 ; i<str.size() ; ++i)
|
||||
str[i] = ToSmall(str[i]);
|
||||
}
|
||||
|
||||
|
||||
wchar_t Locale::ToCapital(wchar_t c)
|
||||
{
|
||||
if( c>='a' && c<='z' )
|
||||
return c - 'a' + 'A';
|
||||
|
||||
return SubstFind(subst_smalllet, c);
|
||||
}
|
||||
|
||||
|
||||
void Locale::ToCapital(std::wstring & str)
|
||||
{
|
||||
for(size_t i=0 ; i<str.size() ; ++i)
|
||||
str[i] = ToCapital(str[i]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
comparing lexicographically two characters
|
||||
|
||||
return value:
|
||||
less than 0 if c1 is 'less' than c2
|
||||
zero if they are equal
|
||||
greater than 0 if c1 is 'greater' than c2
|
||||
|
||||
capital letters are treated equaly as small ones
|
||||
but they will appear first (before the small ones)
|
||||
*/
|
||||
int Locale::Compare(wchar_t c1, wchar_t c2)
|
||||
{
|
||||
SubstItem s1, s2;
|
||||
|
||||
s1.from = c1;
|
||||
s1.to = c1;
|
||||
s1.index = 0;
|
||||
|
||||
s2.from = c2;
|
||||
s2.to = c2;
|
||||
s2.index = 0;
|
||||
|
||||
if( !((c1>='a' && c1<='z') || (c1>='A' && c1<='Z')) )
|
||||
{
|
||||
size_t i1 = SubstFindIndex(subst_sort, c1);
|
||||
|
||||
if( i1 < subst_sort.size() )
|
||||
{
|
||||
s1.to = subst_sort[i1].to;
|
||||
s1.index = subst_sort[i1].index;
|
||||
}
|
||||
}
|
||||
|
||||
if( !((c2>='a' && c2<='z') || (c2>='A' && c2<='Z')) )
|
||||
{
|
||||
size_t i2 = SubstFindIndex(subst_sort, c2);
|
||||
|
||||
if( i2 < subst_sort.size() )
|
||||
{
|
||||
s2.to = subst_sort[i2].to;
|
||||
s2.index = subst_sort[i2].index;
|
||||
}
|
||||
}
|
||||
|
||||
wchar_t small1 = ToSmall(s1.to);
|
||||
wchar_t small2 = ToSmall(s2.to);
|
||||
|
||||
if( small1 == small2 )
|
||||
{
|
||||
if( s1.index != s2.index )
|
||||
return s1.index - s2.index;
|
||||
|
||||
// this will sort capital letters at the end (after small ones)
|
||||
return s1.to - s2.to;
|
||||
}
|
||||
|
||||
return small1 - small2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
comparing lexicographically two strings
|
||||
|
||||
return value:
|
||||
less than 0 if str1 is 'less' than str2
|
||||
zero if they are equal
|
||||
greater than 0 if str1 is 'greater' than str2
|
||||
*/
|
||||
int Locale::Compare(const std::wstring & str1, const std::wstring & str2)
|
||||
{
|
||||
size_t i1 = 0;
|
||||
size_t i2 = 0;
|
||||
|
||||
for( ; i1 < str1.size() && i2 < str2.size() ; ++i1, ++i2)
|
||||
{
|
||||
int res = Compare(str1[i1], str2[i2]);
|
||||
|
||||
if( res != 0 )
|
||||
return res;
|
||||
}
|
||||
|
||||
if( str1.size() < str2.size() )
|
||||
return -1;
|
||||
|
||||
if( str1.size() > str2.size() )
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
264
winixd/templates/locale.h
Normal file
264
winixd/templates/locale.h
Normal file
@@ -0,0 +1,264 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_templates_locale
|
||||
#define headerfile_winix_templates_locale
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "space/spaceparser.h"
|
||||
#include "textstream/textstream.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
class Locale
|
||||
{
|
||||
public:
|
||||
|
||||
Locale();
|
||||
|
||||
// locale files
|
||||
// those files will be reading from directories specified in Read() method
|
||||
// default one item: en
|
||||
void SetLocaleFiles(const std::vector<std::wstring> & files);
|
||||
|
||||
// preparing locale_indices table
|
||||
// if you change this values you should reload all locale files
|
||||
void SetLocaleMaxId(size_t max_id);
|
||||
|
||||
// setting/getting current language
|
||||
// default: 0
|
||||
void SetCurLang(size_t lang_id);
|
||||
size_t GetCurLang() const;
|
||||
|
||||
// which language is used instead of if there is no a key in an other language
|
||||
// default: 0
|
||||
void SetDefLang(size_t lang_id);
|
||||
size_t GetDefLang() const;
|
||||
|
||||
// reading locales
|
||||
// you should call SetLocaleFiles() beforehand
|
||||
void Read(const char * dir, const char * dir_def = 0);
|
||||
void Read(const std::string & dir, const std::string & dir_def);
|
||||
void Read(const wchar_t * dir, const wchar_t * dir_def = 0);
|
||||
void Read(const std::wstring & dir, const std::wstring & dir_def);
|
||||
|
||||
// returns true if a language with lang_id exists
|
||||
bool HasLanguage(size_t lang_id);
|
||||
|
||||
// checking whether there is a 'key' in the current language
|
||||
// or in the default language if try_default_too is true
|
||||
bool IsKey(const wchar_t * key, bool try_default_too = true);
|
||||
bool IsKey(const std::wstring & key, bool try_default_too = true) const;
|
||||
|
||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||
bool IsKey(const PT::TextStreamBase<char_type, stack_size, heap_block_size> & key,
|
||||
bool try_default_too = true);
|
||||
|
||||
// checking whether there is a 'key' in the lang_id language
|
||||
// or in the default language if try_default_too is true
|
||||
bool IsKey(const wchar_t * key, size_t lang_id, bool try_default_too = true);
|
||||
bool IsKey(const std::wstring & key, size_t lang_id, bool try_default_too = true) const;
|
||||
|
||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||
bool IsKey(const PT::TextStreamBase<char_type, stack_size, heap_block_size> & key,
|
||||
size_t lang_id, bool try_default_too = true);
|
||||
|
||||
// returning a value for a specific key
|
||||
const std::wstring & Get(const wchar_t * key, bool try_default_too = true);
|
||||
const std::wstring & Get(const wchar_t * key, size_t lang_id, bool try_default_too = true);
|
||||
const std::wstring & Get(const std::wstring & key, bool try_default_too = true) const;
|
||||
const std::wstring & Get(const std::wstring & key, size_t lang_id, bool try_default_too = true) const;
|
||||
|
||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||
const std::wstring & Get(const PT::TextStreamBase<char_type, stack_size, heap_block_size> & key,
|
||||
bool try_default_too = true);
|
||||
|
||||
// lists
|
||||
// current limitation:
|
||||
// we are looking only in 'space.table' so lists with only one item are not found
|
||||
// (SplitSingle(true) was called to the space struct)
|
||||
bool IsList(const wchar_t * key, bool try_default_too = true);
|
||||
bool IsList(const std::wstring & key, bool try_default_too = true) const;
|
||||
bool IsList(const wchar_t * key, size_t lang_id, bool try_default_too = true);
|
||||
bool IsList(const std::wstring & key, size_t lang_id, bool try_default_too = true) const;
|
||||
|
||||
const std::vector<std::wstring> & GetList(const wchar_t * key, bool try_default_too = true);
|
||||
const std::vector<std::wstring> & GetList(const std::wstring & key, bool try_default_too = true) const;
|
||||
const std::vector<std::wstring> & GetList(const wchar_t * key, size_t lang_id, bool try_default_too = true);
|
||||
const std::vector<std::wstring> & GetList(const std::wstring & key, size_t lang_id, bool try_default_too = true) const;
|
||||
|
||||
// converting lang_id to an internal index
|
||||
// returns an index from <0, Size()-1> or size_t(-1) if lang_id is incorrect
|
||||
// it does it in O(1) time
|
||||
size_t IdToIndex(size_t lang_id);
|
||||
|
||||
// returning how many locale files (languages) there are
|
||||
// this is how many files were correctly parsed
|
||||
// this is size of locale_tab table
|
||||
size_t Size() const;
|
||||
|
||||
// accessing by an internal index
|
||||
// internal index is from zero to Size()-1
|
||||
bool IsKeyByIndex(const wchar_t * key, size_t index, bool try_default_too = true);
|
||||
bool IsKeyByIndex(const std::wstring & key, size_t index, bool try_default_too = true) const;
|
||||
const std::wstring & GetByIndex(const wchar_t * key, size_t index, bool try_default_too = true);
|
||||
const std::wstring & GetByIndex(const std::wstring & key, size_t index, bool try_default_too = true) const;
|
||||
|
||||
// lists by an internal index
|
||||
// current limitation:
|
||||
// we are looking only in 'space.table' so lists with only one item are not found
|
||||
// (SplitSingle(true) was called to the space struct)
|
||||
bool IsListByIndex(const wchar_t * key, size_t index, bool try_default_too = true);
|
||||
bool IsListByIndex(const std::wstring & key, size_t index, bool try_default_too = true) const;
|
||||
const std::vector<std::wstring> & GetListByIndex(const wchar_t * key, size_t index,
|
||||
bool try_default_too = true);
|
||||
const std::vector<std::wstring> & GetListByIndex(const std::wstring & key, size_t index,
|
||||
bool try_default_too = true) const;
|
||||
|
||||
|
||||
// url substitution characters
|
||||
wchar_t UrlSubst(wchar_t c);
|
||||
void UrlSubst(std::wstring & str);
|
||||
|
||||
// changing to small/capital letters
|
||||
wchar_t ToSmall(wchar_t c);
|
||||
void ToSmall(std::wstring & str);
|
||||
wchar_t ToCapital(wchar_t c);
|
||||
void ToCapital(std::wstring & str);
|
||||
|
||||
// comparing two characters/strings
|
||||
// return a value less than zero if c1<c2, zero if c1==c2, value greater than 0 if c1>c2
|
||||
int Compare(wchar_t c1, wchar_t c2);
|
||||
int Compare(const std::wstring & str1, const std::wstring & str2);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
// struct to used for substitution
|
||||
struct SubstItem
|
||||
{
|
||||
wchar_t from, to;
|
||||
int index;
|
||||
|
||||
SubstItem() { from = to = 0; index = 0; }
|
||||
bool operator<(const SubstItem & arg) const { return from < arg.from; }
|
||||
};
|
||||
|
||||
void AddLocale(const char * file);
|
||||
void ReadFile(const char * dir, const char * dir_def, const char * file);
|
||||
bool ReadFile(const char * dir, const char * file);
|
||||
void ReadSubstTable(const char * dir, const char * dir_def);
|
||||
bool ReadSubstTable(const char * dir);
|
||||
void CreateSubstVector(std::vector<SubstItem> & vect, const std::wstring & tab1, const std::wstring & tab2);
|
||||
void CreateSubstSortVector(std::vector<SubstItem> & vect, std::vector<std::wstring> & tab);
|
||||
size_t SubstFindIndex(const std::vector<SubstItem> & vect, wchar_t val);
|
||||
wchar_t SubstFind(const std::vector<SubstItem> & vect, wchar_t val);
|
||||
const std::wstring * GetKeyInLanguage(const std::wstring & key, size_t lang_id) const;
|
||||
const std::vector<std::wstring> * GetListInLanguage(const std::wstring & key, size_t lang_id) const;
|
||||
|
||||
|
||||
// locale files
|
||||
std::vector<std::wstring> locale_files;
|
||||
|
||||
// a map from <0, config->locale_max_id> returning an index to
|
||||
// locale_tab table (you should check whether the index is correct)
|
||||
// with this we have O(1) time to find the specified locale
|
||||
// and locale_tab doesn't have to be so large
|
||||
std::vector<size_t> locale_indices;
|
||||
|
||||
// messages vector<via language>
|
||||
std::vector<PT::Space> locale_tab;
|
||||
|
||||
// default locale index (index to locale_indexes)
|
||||
size_t default_lang;
|
||||
|
||||
// current locale index (index to locale_indexes)
|
||||
size_t current_lang;
|
||||
|
||||
// vectors of characters substitution (sort by 'from')
|
||||
std::vector<SubstItem> subst_url; // for url substitution
|
||||
std::vector<SubstItem> subst_smalllet; // changing from small to capital
|
||||
std::vector<SubstItem> subst_capitallet; // changing from capital to small
|
||||
std::vector<SubstItem> subst_sort; // local characters for comparison
|
||||
|
||||
|
||||
PT::Space temp_space;
|
||||
PT::SpaceParser loc_parser;
|
||||
std::string locale_filea;
|
||||
std::string file_name;
|
||||
std::wstring key_str;
|
||||
const std::wstring empty; // used when returning a non existing key from loc_tab (or in LangToFileName)
|
||||
const std::vector<std::wstring> empty_list; // the same as above
|
||||
std::string adir1, adir2;
|
||||
};
|
||||
|
||||
|
||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||
bool Locale::IsKey(const PT::TextStreamBase<char_type, stack_size, heap_block_size> & key,
|
||||
bool try_default_too)
|
||||
{
|
||||
key.to_string(key_str);
|
||||
return IsKey(key_str, try_default_too);
|
||||
}
|
||||
|
||||
|
||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||
bool Locale::IsKey(const PT::TextStreamBase<char_type, stack_size, heap_block_size> & key,
|
||||
size_t lang_id, bool try_default_too)
|
||||
{
|
||||
key.to_string(key_str);
|
||||
return IsKey(key_str, lang_id, try_default_too);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||
const std::wstring & Locale::Get(const PT::TextStreamBase<char_type, stack_size, heap_block_size> & key,
|
||||
bool try_default_too)
|
||||
{
|
||||
key.to_string(key_str);
|
||||
return Get(key_str, try_default_too);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
#endif
|
121
winixd/templates/localefilter.cpp
Normal file
121
winixd/templates/localefilter.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "localefilter.h"
|
||||
#include "../core/misc.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
LocaleFilter::LocaleFilter()
|
||||
{
|
||||
open_mark = '{';
|
||||
closing_mark = '}';
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LocaleFilter::ReadKey()
|
||||
{
|
||||
key.clear();
|
||||
|
||||
for( ; *pchar && *pchar != closing_mark ; ++pchar)
|
||||
key += *pchar;
|
||||
|
||||
// skipping last closing mark (if exists)
|
||||
if( *pchar == closing_mark )
|
||||
++pchar;
|
||||
|
||||
TrimWhite(key);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LocaleFilter::Parse(std::wstring & str)
|
||||
{
|
||||
res.clear();
|
||||
pchar = str.c_str();
|
||||
|
||||
while( *pchar )
|
||||
{
|
||||
if( *pchar == open_mark )
|
||||
{
|
||||
++pchar;
|
||||
ReadKey();
|
||||
res += plocale->GetByIndex(key, lang);
|
||||
}
|
||||
else
|
||||
if( *pchar == '\\' && (*(pchar+1) == open_mark || *(pchar+1) == closing_mark || *(pchar+1) == '\\') )
|
||||
{
|
||||
res += *(pchar+1);
|
||||
pchar += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
res += *pchar;
|
||||
pchar += 1;
|
||||
}
|
||||
}
|
||||
|
||||
str = res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LocaleFilter::FilterText(Ezc::Item & item)
|
||||
{
|
||||
if( !item.text.empty() )
|
||||
Parse(item.text);
|
||||
|
||||
std::vector<Ezc::Item*>::iterator i = item.item_tab.begin();
|
||||
|
||||
for( ; i != item.item_tab.end() ; ++i )
|
||||
FilterText(**i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LocaleFilter::Filter(Ezc::Pattern & pattern, const Locale & locale, size_t lang_index)
|
||||
{
|
||||
plocale = &locale;
|
||||
lang = lang_index;
|
||||
|
||||
FilterText( pattern.item_root );
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
74
winixd/templates/localefilter.h
Normal file
74
winixd/templates/localefilter.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_templates_localefilter
|
||||
#define headerfile_winix_templates_localefilter
|
||||
|
||||
#include "locale.h"
|
||||
#include "ezc.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
class LocaleFilter
|
||||
{
|
||||
public:
|
||||
|
||||
LocaleFilter();
|
||||
|
||||
// lang_index is an internal index from Locale <0, Size()-1>
|
||||
void Filter(Ezc::Pattern & pattern, const Locale & locale, size_t lang_index);
|
||||
|
||||
private:
|
||||
void ReadKey();
|
||||
void FilterText(Ezc::Item & item);
|
||||
void Parse(std::wstring & str);
|
||||
|
||||
wchar_t open_mark; // default '{'
|
||||
wchar_t closing_mark; // default '}'
|
||||
|
||||
const Locale * plocale;
|
||||
size_t lang;
|
||||
std::wstring res;
|
||||
std::wstring key;
|
||||
std::wstring value;
|
||||
const wchar_t * pchar;
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
#endif
|
89
winixd/templates/login.cpp
Normal file
89
winixd/templates/login.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
#include "functions/functions.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
void login_path(Info & i)
|
||||
{
|
||||
if( config->use_ssl )
|
||||
i.out << config->url_ssl_proto;
|
||||
else
|
||||
i.out << config->url_proto;
|
||||
|
||||
if( !cur->request->subdomain.empty() )
|
||||
i.out << cur->request->subdomain << '.';
|
||||
|
||||
i.out << config->base_url;
|
||||
|
||||
if( system->HasReadExecAccessToPath(cur->request->dir_tab) )
|
||||
{
|
||||
dir(i);
|
||||
|
||||
if( cur->request->is_item && system->HasReadAccess(cur->request->item) )
|
||||
i.out << cur->request->item.url << '/';
|
||||
}
|
||||
else
|
||||
{
|
||||
i.out << '/';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void login_should_use_captcha(Info & i)
|
||||
{
|
||||
i.res = functions->fun_login.ShouldUseCaptchaForCurrentIP();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
72
winixd/templates/ls.cpp
Normal file
72
winixd/templates/ls.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
#include "core/request.h"
|
||||
#include "misc.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
static size_t ls_ckeditor_reqid = 0;
|
||||
static int ls_ckeditor_funnum = 0;
|
||||
|
||||
|
||||
|
||||
void ls_ckeditor_funnum_browse(Info & i)
|
||||
{
|
||||
if( ls_ckeditor_reqid != cur->request->id )
|
||||
{
|
||||
ls_ckeditor_reqid = cur->request->id;
|
||||
ls_ckeditor_funnum = Toi(cur->request->ParamValue(L"CKEditorFuncNum"));
|
||||
}
|
||||
|
||||
i.out << ls_ckeditor_funnum;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace Winix
|
||||
|
151
winixd/templates/man.cpp
Normal file
151
winixd/templates/man.cpp
Normal file
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
#include "core/request.h"
|
||||
#include "core/misc.h"
|
||||
#include "functions/functions.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
static Functions::Iterator winixfun_iter;
|
||||
static size_t winixfun_curreq = 0;
|
||||
static Ezc::Stack * winixstack = &empty_stack;
|
||||
|
||||
|
||||
|
||||
bool man_winixfun_tabcheck()
|
||||
{
|
||||
if( winixfun_curreq != cur->request->id )
|
||||
{
|
||||
winixfun_curreq = cur->request->id;
|
||||
winixfun_iter = functions->Begin();
|
||||
}
|
||||
|
||||
return winixfun_iter != functions->End();
|
||||
}
|
||||
|
||||
|
||||
void man_winixfun_tab(Info & i)
|
||||
{
|
||||
man_winixfun_tabcheck();
|
||||
winixstack = &i.stack;
|
||||
|
||||
if( i.iter == 0 )
|
||||
winixfun_iter = functions->Begin();
|
||||
else
|
||||
if( winixfun_iter != functions->End() )
|
||||
++winixfun_iter;
|
||||
|
||||
i.res = winixfun_iter != functions->End();
|
||||
}
|
||||
|
||||
|
||||
void man_winixfun_tab_index(Info & i)
|
||||
{
|
||||
i.out << (winixstack->iter + 1);
|
||||
}
|
||||
|
||||
|
||||
void man_winixfun_tab_name(Info & i)
|
||||
{
|
||||
if( man_winixfun_tabcheck() )
|
||||
i.out << winixfun_iter->first;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static EzcFun::Iterator ezcfun_iter;
|
||||
static size_t ezcfun_curreq = 0;
|
||||
static Ezc::Stack * ezcstack = &empty_stack;
|
||||
|
||||
|
||||
bool man_ezcfun_tabcheck()
|
||||
{
|
||||
if( ezcfun_curreq != cur->request->id )
|
||||
{
|
||||
ezcfun_curreq = cur->request->id;
|
||||
ezcfun_iter = ezc_functions.Begin();
|
||||
}
|
||||
|
||||
return ezcfun_iter != ezc_functions.End();
|
||||
}
|
||||
|
||||
|
||||
void man_ezcfun_tab(Info & i)
|
||||
{
|
||||
man_ezcfun_tabcheck();
|
||||
ezcstack = &i.stack;
|
||||
|
||||
if( i.iter == 0 )
|
||||
ezcfun_iter = ezc_functions.Begin();
|
||||
else
|
||||
if( ezcfun_iter != ezc_functions.End() )
|
||||
++ezcfun_iter;
|
||||
|
||||
i.res = ezcfun_iter != ezc_functions.End();
|
||||
}
|
||||
|
||||
|
||||
void man_ezcfun_tab_index(Info & i)
|
||||
{
|
||||
i.out << (ezcstack->iter + 1);
|
||||
}
|
||||
|
||||
|
||||
void man_ezcfun_tab_name(Info & i)
|
||||
{
|
||||
if( man_ezcfun_tabcheck() )
|
||||
i.out << ezcfun_iter->first;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
|
179
winixd/templates/misc.cpp
Normal file
179
winixd/templates/misc.cpp
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
#include "misc.h"
|
||||
#include "core/misc.h"
|
||||
#include "core/request.h"
|
||||
#include "core/user.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
extern EzcFun ezc_functions;
|
||||
extern Ezc::Blocks ezc_blocks;
|
||||
|
||||
|
||||
|
||||
void HtmlEscapeFormTxt(HtmlTextStream & out, const std::wstring & in)
|
||||
{
|
||||
std::wstring::const_iterator i;
|
||||
int was_enter = 0; // how many enteres there were before
|
||||
|
||||
if( in.empty() )
|
||||
return;
|
||||
|
||||
out << R("<p>"); // !! pozbyc sie wstawianie tego html tutaj (wrzucic w jakis sposob do szablonow)
|
||||
|
||||
// skipping first new line characters
|
||||
for(i = in.begin() ; i != in.end() && (*i==13 || *i==10) ; ++i);
|
||||
|
||||
for( ; i != in.end() ; ++i )
|
||||
{
|
||||
if( *i == 13 ) // skipping stupid characters (\r\n\ in dos mode)
|
||||
continue;
|
||||
|
||||
if( *i == 10 )
|
||||
{
|
||||
++was_enter;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( was_enter == 1 )
|
||||
out << R("<br>\n");
|
||||
else
|
||||
if( was_enter > 1 )
|
||||
out << R("</p>\n<p>");
|
||||
|
||||
was_enter = 0;
|
||||
}
|
||||
|
||||
out << *i;
|
||||
}
|
||||
|
||||
out << R("</p>\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void InitGenerator(EzcGen & gen)
|
||||
{
|
||||
gen.TrimWhite(gen_trim_white);
|
||||
gen.SkipNewLine(gen_skip_new_line);
|
||||
gen.RecognizeSpecialChars(gen_use_special_chars);
|
||||
gen.SetMax(config->ezc_max_elements, config->ezc_max_loop_elements);
|
||||
gen.SetCommentary(config->ezc_error_prefix, config->ezc_error_postfix);
|
||||
|
||||
/*
|
||||
* although we have addresses to blocks and functions cached in patters
|
||||
* we have to provide it here because they will be used for variables
|
||||
* if a variable is an alias e.g. [def variable function]
|
||||
*/
|
||||
gen.SetBlocks(ezc_blocks);
|
||||
gen.SetFunctions(ezc_functions);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void print_hour_min(Info & i, time_t time)
|
||||
{
|
||||
char buffer[100];
|
||||
|
||||
int hours = time / 60 / 60;
|
||||
int mins = (time / 60 - hours * 60);
|
||||
|
||||
sprintf(buffer, "%02d:%02d", hours, mins);
|
||||
i.out << buffer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void print_date_nice(Info & i, const PT::Date & date)
|
||||
{
|
||||
time_t one_day = 60 * 60 * 24;
|
||||
PT::Date ltm = system->ToLocal(date);
|
||||
|
||||
if( date + one_day > cur->request->start_time )
|
||||
i.out << DateToStr(ltm.year, ltm.month, ltm.day, ltm.hour, ltm.min, ltm.sec);
|
||||
else
|
||||
i.out << DateToStr(ltm.year, ltm.month, ltm.day);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// cannot be a const reference at the moment (PT::Space is used)
|
||||
void print_user_name(Info & i, User & user)
|
||||
{
|
||||
std::wstring * dname = user.aenv.GetValue(L"display_name");
|
||||
|
||||
if( dname && !IsWhite(*dname, true) )
|
||||
i.out << *dname;
|
||||
else
|
||||
i.out << user.name;
|
||||
}
|
||||
|
||||
|
||||
void print_user_name(Info & i, User * puser, const std::wstring & guest_name)
|
||||
{
|
||||
if( puser )
|
||||
{
|
||||
print_user_name(i, *puser);
|
||||
}
|
||||
else
|
||||
{
|
||||
i.out << "~";
|
||||
|
||||
if( !guest_name.empty() && !IsWhite(guest_name) )
|
||||
i.out << guest_name;
|
||||
else
|
||||
i.out << locale.Get(L"display_guest_name");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
97
winixd/templates/misc.h
Normal file
97
winixd/templates/misc.h
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_templates_misc
|
||||
#define headerfile_winix_templates_misc
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "localefilter.h"
|
||||
#include "ezc.h"
|
||||
#include "htmltextstream.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
struct User;
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
typedef Ezc::Functions<HtmlTextStream> EzcFun;
|
||||
typedef Ezc::Generator<HtmlTextStream> EzcGen;
|
||||
typedef Ezc::FunInfo<HtmlTextStream> Info;
|
||||
|
||||
template<class RawType>
|
||||
HtmlTextStream::RawText<RawType> R(const RawType & par)
|
||||
{
|
||||
return HtmlTextStream::RawText<RawType>(par);
|
||||
}
|
||||
|
||||
|
||||
void InitGenerator(EzcGen & gen);
|
||||
|
||||
void HtmlEscapeFormTxt(HtmlTextStream & out, const std::wstring & in);
|
||||
|
||||
void print_hour_min(Info & i, time_t time);
|
||||
void print_date_nice(Info & i, const PT::Date & date);
|
||||
|
||||
|
||||
/*
|
||||
print a user name -- it is trying to use 'display_name' from user's admin env
|
||||
if it not find it or if the 'display_name' is all white (consists of all white characters)
|
||||
then the login name is printed
|
||||
*/
|
||||
void print_user_name(Info & i, User & user);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
puser can be null -- in such a case guest_name is used
|
||||
if guest_name is empty then 'display_guest_name' from locales is printed
|
||||
*/
|
||||
void print_user_name(Info & i, User * puser, const std::wstring & guest_name);
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
#endif
|
||||
|
405
winixd/templates/miscspace.cpp
Normal file
405
winixd/templates/miscspace.cpp
Normal file
@@ -0,0 +1,405 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
bool are_spaces_the_same(const std::vector<Ezc::Var> & params, const std::vector<std::wstring> & spaces)
|
||||
{
|
||||
// last value from params is the parameter name (not a space)
|
||||
if( spaces.size() + 1 != params.size() )
|
||||
return false;
|
||||
|
||||
for(size_t i=0 ; i<spaces.size() ; ++i)
|
||||
if( spaces[i] != params[i].str )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void copy_space(const std::vector<Ezc::Var> & params, std::vector<std::wstring> & spaces)
|
||||
{
|
||||
if( !params.empty() )
|
||||
{
|
||||
spaces.resize(params.size() - 1);
|
||||
|
||||
for(size_t i=0 ; i<params.size() - 1 ; ++i)
|
||||
spaces[i] = params[i].str;
|
||||
}
|
||||
else
|
||||
{
|
||||
spaces.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PT::Space * find_space(const std::vector<Ezc::Var> & params, PT::Space & space, size_t level = 0)
|
||||
{
|
||||
if( level + 1 < params.size() )
|
||||
{
|
||||
for(size_t i=0 ; i<space.spaces.size() ; ++i)
|
||||
{
|
||||
if( space.spaces[i]->name == params[level].str )
|
||||
return find_space(params, *space.spaces[i], level+1);
|
||||
}
|
||||
|
||||
// there is no such a space
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return &space;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
struct SpaceInfo
|
||||
{
|
||||
bool inited;
|
||||
PT::Space * last_space;
|
||||
std::vector<std::wstring> spaces;
|
||||
|
||||
SpaceInfo()
|
||||
{
|
||||
inited = false;
|
||||
last_space = 0;
|
||||
}
|
||||
};
|
||||
|
||||
static std::map<PT::Space*, SpaceInfo> spaces_map;
|
||||
static size_t space_reqid = 0;
|
||||
|
||||
|
||||
|
||||
void space_init(const std::vector<Ezc::Var> & params, PT::Space & space, SpaceInfo & space_info)
|
||||
{
|
||||
if( !space_info.inited || !are_spaces_the_same(params, space_info.spaces) )
|
||||
{
|
||||
space_info.inited = true;
|
||||
copy_space(params, space_info.spaces);
|
||||
space_info.last_space = find_space(params, space);
|
||||
}
|
||||
else
|
||||
{
|
||||
// !! temp
|
||||
//log << log1 << "taking space from the cache" << logend;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void space_check_reqid()
|
||||
{
|
||||
if( space_reqid != cur->request->id )
|
||||
{
|
||||
space_reqid = cur->request->id;
|
||||
spaces_map.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void space(Info & i, PT::Space & space)
|
||||
{
|
||||
space_check_reqid();
|
||||
|
||||
if( !i.params.empty() )
|
||||
{
|
||||
SpaceInfo & space_info = spaces_map[&space];
|
||||
space_init(i.params, space, space_info);
|
||||
|
||||
if( space_info.last_space )
|
||||
{
|
||||
const std::wstring & param = i.params.back().str;
|
||||
const std::wstring * value = space_info.last_space->GetValue(param);
|
||||
|
||||
if( value )
|
||||
i.out << *value;
|
||||
// else
|
||||
// log << log1 << "nie ma takiej wartosci" << logend; // only for testing
|
||||
// !! IMPROVE ME
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void space_value_noescape(Info & i, PT::Space & space)
|
||||
{
|
||||
space_check_reqid();
|
||||
|
||||
if( !i.params.empty() )
|
||||
{
|
||||
SpaceInfo & space_info = spaces_map[&space];
|
||||
space_init(i.params, space, space_info);
|
||||
|
||||
if( space_info.last_space )
|
||||
{
|
||||
const std::wstring & param = i.params.back().str;
|
||||
const std::wstring * value = space_info.last_space->GetValue(param);
|
||||
|
||||
if( value )
|
||||
i.out << R(*value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
stack item for [for] statement
|
||||
*/
|
||||
struct SpaceStackItem
|
||||
{
|
||||
// names of the spaces
|
||||
std::vector<std::wstring> spaces;
|
||||
|
||||
// table of values
|
||||
std::vector<std::wstring> values;
|
||||
|
||||
// an index to 'values' which is incremented every each [for]
|
||||
size_t value_index;
|
||||
|
||||
|
||||
SpaceStackItem()
|
||||
{
|
||||
value_index = 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
each Space has its own SpacesTabInfo struct
|
||||
*/
|
||||
struct SpacesTabInfo
|
||||
{
|
||||
// a stack for [for] statements
|
||||
std::vector<SpaceStackItem> stack_tab;
|
||||
|
||||
// current item from 'stack_tab'
|
||||
size_t cur_stack;
|
||||
|
||||
SpacesTabInfo()
|
||||
{
|
||||
cur_stack = 0;
|
||||
}
|
||||
};
|
||||
|
||||
static std::map<PT::Space*, SpacesTabInfo> spaces_tab_info_map;
|
||||
static size_t spaces_tab_reqid = 0;
|
||||
|
||||
|
||||
|
||||
bool spaces_tab_find_stack_item(std::vector<Ezc::Var> & params, SpacesTabInfo & spaces_tab_info)
|
||||
{
|
||||
bool found = false;
|
||||
spaces_tab_info.cur_stack = spaces_tab_info.stack_tab.size();
|
||||
|
||||
for(size_t i=0 ; i<spaces_tab_info.stack_tab.size() ; ++i)
|
||||
{
|
||||
if( are_spaces_the_same(params, spaces_tab_info.stack_tab[i].spaces) )
|
||||
{
|
||||
spaces_tab_info.cur_stack = i;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
void spaces_tab_add_to_stack(std::vector<Ezc::Var> & params, PT::Space & space, SpacesTabInfo & spaces_tab_info)
|
||||
{
|
||||
if( !params.empty() )
|
||||
{
|
||||
// adding a new item at the end (with the default constructor)
|
||||
spaces_tab_info.stack_tab.resize(spaces_tab_info.stack_tab.size() + 1);
|
||||
spaces_tab_info.cur_stack = spaces_tab_info.stack_tab.size() - 1;
|
||||
|
||||
SpaceStackItem & stack_item = spaces_tab_info.stack_tab.back();
|
||||
|
||||
copy_space(params, stack_item.spaces);
|
||||
space.ListText(params.back().str, stack_item.values);
|
||||
stack_item.value_index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void spaces_tab_check_reqid()
|
||||
{
|
||||
if( spaces_tab_reqid != cur->request->id )
|
||||
{
|
||||
spaces_tab_reqid = cur->request->id;
|
||||
spaces_tab_info_map.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void spaces_tab_init(std::vector<Ezc::Var> & params, PT::Space & space, SpacesTabInfo & spaces_tab_info)
|
||||
{
|
||||
PT::Space * child_space = find_space(params, space);
|
||||
|
||||
if( child_space )
|
||||
{
|
||||
if( !spaces_tab_find_stack_item(params, spaces_tab_info) )
|
||||
{
|
||||
// add a new value to the stack
|
||||
spaces_tab_add_to_stack(params, *child_space, spaces_tab_info);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// there is not such a space
|
||||
spaces_tab_info.cur_stack = spaces_tab_info.stack_tab.size();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void spaces_tab(Info & i, PT::Space & space)
|
||||
{
|
||||
spaces_tab_check_reqid();
|
||||
|
||||
if( !i.params.empty() )
|
||||
{
|
||||
SpacesTabInfo & spaces_tab_info = spaces_tab_info_map[&space];
|
||||
spaces_tab_init(i.params, space, spaces_tab_info);
|
||||
|
||||
if( spaces_tab_info.cur_stack < spaces_tab_info.stack_tab.size() )
|
||||
{
|
||||
SpaceStackItem & stack_item = spaces_tab_info.stack_tab[spaces_tab_info.cur_stack];
|
||||
|
||||
// !! CHECK ME there was a change in EZC lately
|
||||
// make sure this still is ok
|
||||
// i.iter is different for each [for] statement (implemented in EZC)
|
||||
// so we don't have to remember it in our stack
|
||||
// for each the same space we have only one item in the stack, e.g.
|
||||
// [for item_meta "space1" "space2" "value"]
|
||||
// [for item_meta "space1" "space2" "value"]
|
||||
// [end]
|
||||
// [end]
|
||||
// above two [for]s use the same item on our stack
|
||||
stack_item.value_index = i.iter;
|
||||
|
||||
i.res = stack_item.value_index < stack_item.values.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void spaces_tab_value_print(HtmlTextStream & out, SpacesTabInfo & spaces_tab_info)
|
||||
{
|
||||
if( spaces_tab_info.cur_stack < spaces_tab_info.stack_tab.size() )
|
||||
{
|
||||
SpaceStackItem & stack_item = spaces_tab_info.stack_tab[spaces_tab_info.cur_stack];
|
||||
out << stack_item.values[stack_item.value_index];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void spaces_tab_value(Info & i, PT::Space & space)
|
||||
{
|
||||
spaces_tab_check_reqid();
|
||||
SpacesTabInfo & spaces_tab_info = spaces_tab_info_map[&space];
|
||||
|
||||
if( i.params.empty() )
|
||||
{
|
||||
// value from last [for ...] statement
|
||||
spaces_tab_value_print(i.out, spaces_tab_info);
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t cur_stack_old = spaces_tab_info.cur_stack;
|
||||
|
||||
if( spaces_tab_find_stack_item(i.params, spaces_tab_info) )
|
||||
spaces_tab_value_print(i.out, spaces_tab_info);
|
||||
|
||||
spaces_tab_info.cur_stack = cur_stack_old;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool spaces_tab_has_next(SpacesTabInfo & spaces_tab_info)
|
||||
{
|
||||
if( spaces_tab_info.cur_stack < spaces_tab_info.stack_tab.size() )
|
||||
{
|
||||
SpaceStackItem & val = spaces_tab_info.stack_tab[spaces_tab_info.cur_stack];
|
||||
return val.value_index + 1 < val.values.size();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void spaces_tab_has_next(Info & i, PT::Space & space)
|
||||
{
|
||||
spaces_tab_check_reqid();
|
||||
SpacesTabInfo & spaces_tab_info = spaces_tab_info_map[&space];
|
||||
|
||||
if( i.params.empty() )
|
||||
{
|
||||
// value from last [for ...] statement
|
||||
i.res = spaces_tab_has_next(spaces_tab_info);
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t cur_stack_old = spaces_tab_info.cur_stack;
|
||||
|
||||
if( spaces_tab_find_stack_item(i.params, spaces_tab_info) )
|
||||
i.res = spaces_tab_has_next(spaces_tab_info);
|
||||
|
||||
spaces_tab_info.cur_stack = cur_stack_old;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
|
62
winixd/templates/miscspace.h
Normal file
62
winixd/templates/miscspace.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
// !! rename to 'space_value'
|
||||
void space(Info & i, PT::Space & space);
|
||||
void space_value_noescape(Info & i, PT::Space & space);
|
||||
|
||||
// !! rename to 'space_value_tab' etc.
|
||||
void spaces_tab(Info & i, PT::Space & space);
|
||||
void spaces_tab_value(Info & i, PT::Space & space);
|
||||
void spaces_tab_has_next(Info & i, PT::Space & space);
|
||||
|
||||
|
||||
// !! add space_tab (iteration through spaces)
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
314
winixd/templates/mount.cpp
Normal file
314
winixd/templates/mount.cpp
Normal file
@@ -0,0 +1,314 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
#include "core/misc.h"
|
||||
#include "core/mounts.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
void mount_type_is(Info & i)
|
||||
{
|
||||
int mount_type_id = system->mounts.FindMountType(i.par);
|
||||
|
||||
if( mount_type_id == -1 )
|
||||
return;
|
||||
|
||||
i.res = (cur->mount->type == mount_type_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void mount_page_arg_is(Info & i)
|
||||
{
|
||||
i.res = cur->mount->IsArg(system->mounts.MountParPage(), i.par);
|
||||
}
|
||||
|
||||
|
||||
void mount_lang_arg(Info & i)
|
||||
{
|
||||
i.out << cur->mount->FirstArg(system->mounts.MountParLang());
|
||||
}
|
||||
|
||||
|
||||
void mount_lang_arg_is(Info & i)
|
||||
{
|
||||
i.res = cur->mount->IsArg(system->mounts.MountParLang(), i.par);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void mount_has_html_template(Info & i)
|
||||
{
|
||||
i.res = cur->mount->param[system->mounts.MountParHtmlTemplate()].defined;
|
||||
}
|
||||
|
||||
|
||||
void mount_first_html_template(Info & i)
|
||||
{
|
||||
Mount::ParamRow & par = cur->mount->param[system->mounts.MountParHtmlTemplate()];
|
||||
|
||||
if( par.defined && !par.arg.empty() )
|
||||
i.out << par.arg[0];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static size_t mount_css_index = 0;
|
||||
|
||||
void mount_css_tab(Info & i)
|
||||
{
|
||||
int parcss = system->mounts.MountParCss();
|
||||
|
||||
|
||||
if( !cur->mount->param[parcss].defined )
|
||||
return;
|
||||
|
||||
mount_css_index = i.iter;
|
||||
i.res = mount_css_index < cur->mount->param[parcss].arg.size();
|
||||
}
|
||||
|
||||
|
||||
void mount_css_tab_file(Info & i)
|
||||
{
|
||||
int parcss = system->mounts.MountParCss();
|
||||
|
||||
if( mount_css_index < cur->mount->param[parcss].arg.size() )
|
||||
i.out << cur->mount->param[parcss].arg[mount_css_index];
|
||||
}
|
||||
|
||||
|
||||
void mount_css_tab_file_is_global(Info & i)
|
||||
{
|
||||
int parcss = system->mounts.MountParCss();
|
||||
|
||||
if( mount_css_index < cur->mount->param[parcss].arg.size() )
|
||||
i.res = IsSubString(L"http://", cur->mount->param[parcss].arg[mount_css_index].c_str()) ||
|
||||
IsSubString(L"https://", cur->mount->param[parcss].arg[mount_css_index].c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void mount_css_tab_has_next(Info & i)
|
||||
{
|
||||
int parcss = system->mounts.MountParCss();
|
||||
|
||||
if( !cur->mount->param[parcss].defined )
|
||||
return;
|
||||
|
||||
i.res = (mount_css_index + 1 < cur->mount->param[parcss].arg.size());
|
||||
}
|
||||
|
||||
|
||||
size_t mount_css_size()
|
||||
{
|
||||
int parcss = system->mounts.MountParCss();
|
||||
|
||||
if( !cur->mount->param[parcss].defined )
|
||||
return 0;
|
||||
|
||||
return cur->mount->param[parcss].arg.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void mount_css_is_empty(Info & i)
|
||||
{
|
||||
i.res = mount_css_size() == 0;
|
||||
}
|
||||
|
||||
|
||||
void mount_css_is_one(Info & i)
|
||||
{
|
||||
i.res = mount_css_size() == 1;
|
||||
}
|
||||
|
||||
|
||||
void mount_css_more_than_one(Info & i)
|
||||
{
|
||||
i.res = mount_css_size() > 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static bool mount_tab_inited = false;
|
||||
static Mounts::MountTab::const_iterator mount_iter;
|
||||
static std::wstring dir_str;
|
||||
|
||||
|
||||
|
||||
void mount_cur_type(Info & i)
|
||||
{
|
||||
i.out << system->mounts.GetMountType(cur->mount->type);
|
||||
}
|
||||
|
||||
|
||||
void mount_cur_dir(Info & i)
|
||||
{
|
||||
Item * pdir = system->dirs.GetDir(cur->mount->dir_id);
|
||||
|
||||
if( pdir && system->dirs.MakePath(pdir->id, dir_str) )
|
||||
i.out << dir_str;
|
||||
}
|
||||
|
||||
|
||||
void mount_cur_fs(Info & i)
|
||||
{
|
||||
i.out << system->mounts.GetMountFs(cur->mount->fs);
|
||||
}
|
||||
|
||||
|
||||
void mount_print_parlist(Info & i, const Mount::Param & param)
|
||||
{
|
||||
bool was_printed = false;
|
||||
|
||||
for(size_t p=0 ; p < param.size() ; ++p)
|
||||
{
|
||||
if( param[p].defined )
|
||||
{
|
||||
if( was_printed )
|
||||
i.out << ", ";
|
||||
|
||||
i.out << system->mounts.GetMountPar(p);
|
||||
was_printed = true;
|
||||
|
||||
if( !param[p].arg.empty() )
|
||||
{
|
||||
i.out << "(";
|
||||
|
||||
for(size_t a=0 ; a < param[p].arg.size() ; ++a)
|
||||
{
|
||||
i.out << param[p].arg[a];
|
||||
|
||||
if( a + 1 < param[p].arg.size() )
|
||||
i.out << ", ";
|
||||
}
|
||||
|
||||
i.out << ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void mount_cur_parlist(Info & i)
|
||||
{
|
||||
mount_print_parlist(i, cur->mount->param);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void mount_tab(Info & i)
|
||||
{
|
||||
const Mounts::MountTab * pmount_tab = system->mounts.GetMountTab();
|
||||
|
||||
if( i.iter == 0 )
|
||||
{
|
||||
mount_iter = pmount_tab->begin();
|
||||
}
|
||||
else
|
||||
{
|
||||
if( mount_iter != pmount_tab->end() )
|
||||
++mount_iter;
|
||||
}
|
||||
|
||||
mount_tab_inited = (mount_iter != pmount_tab->end());
|
||||
i.res = mount_tab_inited;
|
||||
}
|
||||
|
||||
|
||||
void mount_tab_type(Info & i)
|
||||
{
|
||||
if( mount_tab_inited )
|
||||
{
|
||||
i.out << system->mounts.GetMountType(mount_iter->second.type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void mount_tab_dir(Info & i)
|
||||
{
|
||||
if( mount_tab_inited )
|
||||
{
|
||||
Item * pdir = system->dirs.GetDir(mount_iter->second.dir_id);
|
||||
|
||||
if( pdir && system->dirs.MakePath(pdir->id, dir_str) )
|
||||
i.out << dir_str;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void mount_tab_fs(Info & i)
|
||||
{
|
||||
if( mount_tab_inited )
|
||||
{
|
||||
i.out << system->mounts.GetMountFs(mount_iter->second.fs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void mount_tab_parlist(Info & i)
|
||||
{
|
||||
if( !mount_tab_inited )
|
||||
return;
|
||||
|
||||
mount_print_parlist(i, mount_iter->second.param);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
|
76
winixd/templates/passwd.cpp
Normal file
76
winixd/templates/passwd.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2013-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "core/request.h"
|
||||
#include "templates.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
void passwd_resetpass_login(Info & i)
|
||||
{
|
||||
if( cur->request->IsPostVar(L"login") )
|
||||
i.out << cur->request->PostVar(L"login");
|
||||
else
|
||||
i.out << cur->request->ParamValue(L"login");
|
||||
}
|
||||
|
||||
|
||||
void passwd_resetpass_code(Info & i)
|
||||
{
|
||||
if( cur->request->IsPostVar(L"code") )
|
||||
i.out << cur->request->PostVar(L"code");
|
||||
else
|
||||
i.out << cur->request->ParamValue(L"code");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
253
winixd/templates/patterncacher.cpp
Normal file
253
winixd/templates/patterncacher.cpp
Normal file
@@ -0,0 +1,253 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2015, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "patterncacher.h"
|
||||
#include "core/log.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
PatternCacher::PatternCacher()
|
||||
{
|
||||
when_delete_patterns = 13;
|
||||
how_many_delete = 3;
|
||||
ezc_fun = 0;
|
||||
ezc_blocks = 0;
|
||||
ezc_obj = 0;
|
||||
}
|
||||
|
||||
|
||||
void PatternCacher::SetEzcFunctions(TemplatesFunctions::EzcFun * fun)
|
||||
{
|
||||
ezc_fun = fun;
|
||||
}
|
||||
|
||||
|
||||
void PatternCacher::SetEzcBlocks(Ezc::Blocks * blocks)
|
||||
{
|
||||
ezc_blocks = blocks;
|
||||
}
|
||||
|
||||
|
||||
void PatternCacher::SetEzcObjects(Ezc::Objects<HtmlTextStream> * obj)
|
||||
{
|
||||
ezc_obj = obj;
|
||||
}
|
||||
|
||||
|
||||
void PatternCacher::SetEzcCommentary(const std::wstring & start, const std::wstring & end)
|
||||
{
|
||||
pattern_parser.SetCommentary(start, end);
|
||||
}
|
||||
|
||||
void PatternCacher::SetWhenDelete(size_t when_delete, size_t how_many_del)
|
||||
{
|
||||
when_delete_patterns = when_delete;
|
||||
how_many_delete = how_many_del;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PatternCacher::DeleteOldPatterns()
|
||||
{
|
||||
if( pattern_tab.size() < when_delete_patterns )
|
||||
return;
|
||||
|
||||
PatternTab::iterator i;
|
||||
PatternErase pe;
|
||||
size_t erase_index;
|
||||
|
||||
erase_tab.resize(pattern_tab.size());
|
||||
|
||||
for( i=pattern_tab.begin(), erase_index=0 ; i!=pattern_tab.end() ; ++i, ++erase_index)
|
||||
{
|
||||
pe.used = i->second.used;
|
||||
pe.iter = i;
|
||||
|
||||
erase_tab[erase_index] = pe;
|
||||
}
|
||||
|
||||
// sorting through 'used'
|
||||
std::sort(erase_tab.begin(), erase_tab.end());
|
||||
|
||||
for(erase_index = 0 ; erase_index<how_many_delete && erase_index<erase_tab.size() ; ++erase_index)
|
||||
{
|
||||
log << log2 << "PC: deleting ezc pattern from the cache, id: "
|
||||
<< erase_tab[erase_index].iter->second.item_id
|
||||
<< ", item used: " << erase_tab[erase_index].used << " time(s)"
|
||||
<< logend;
|
||||
|
||||
pattern_tab.erase(erase_tab[erase_index].iter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PatternCacher::CreatePattern(const Item & item, Ezc::Pattern & pattern)
|
||||
{
|
||||
/*
|
||||
* we do not set pattern_parser.SetBlocks()
|
||||
* blocks cannot be created in patterns generated from virtual FS
|
||||
* but we can call other blocks (from normal templates)
|
||||
*
|
||||
* pattern_parser.SetCommentary() is set beforehand
|
||||
*/
|
||||
pattern_parser.AllowInclude(false);
|
||||
pattern_parser.DeleteWhiteTextItems(false);
|
||||
pattern_parser.ParseString(item.content, pattern);
|
||||
|
||||
RebuildCache(pattern);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Ezc::Pattern * PatternCacher::AddPattern(const Item & item)
|
||||
{
|
||||
// don't call DeleteOldPatterns() here
|
||||
// because you can delete a pattern which is in use
|
||||
// ezc functions such as: item_run, insert_page etc
|
||||
// are using GetPattern() method which can call this method
|
||||
|
||||
PatternUsed pu;
|
||||
|
||||
CreatePattern(item, pu.pattern);
|
||||
pu.used = 1;
|
||||
pu.item_id = item.id;
|
||||
|
||||
std::pair<PatternTab::iterator, bool> res = pattern_tab.insert( std::make_pair(item.id, pu) );
|
||||
|
||||
log << log2 << "PC: added ezc pattern, item_id: " << item.id << ", url: " << item.url << logend;
|
||||
|
||||
return &(res.first->second.pattern);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Ezc::Pattern * PatternCacher::GetPattern(const Item & item)
|
||||
{
|
||||
PatternTab::iterator i;
|
||||
|
||||
i = pattern_tab.find(item.id);
|
||||
|
||||
if( i == pattern_tab.end() )
|
||||
return AddPattern(item);
|
||||
else
|
||||
{
|
||||
log << log2 << "PC: taking pattern from the cache, id: " << item.id << ", url: " << item.url << logend;
|
||||
++(i->second.used);
|
||||
return &(i->second.pattern);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void PatternCacher::UpdatePattern(const Item & item)
|
||||
{
|
||||
PatternTab::iterator i;
|
||||
|
||||
i = pattern_tab.find(item.id);
|
||||
|
||||
if( i == pattern_tab.end() )
|
||||
return;
|
||||
|
||||
++(i->second.used);
|
||||
CreatePattern(item, i->second.pattern);
|
||||
|
||||
log << log2 << "PC: updated pattern, id: " << item.id << ", url: " << item.url << logend;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PatternCacher::DeletePattern(const Item & item)
|
||||
{
|
||||
PatternTab::iterator i;
|
||||
|
||||
i = pattern_tab.find(item.id);
|
||||
|
||||
if( i == pattern_tab.end() )
|
||||
return;
|
||||
|
||||
log << log2 << "PC: deleted pattern, id: " << item.id << ", url: " << item.url << logend;
|
||||
|
||||
pattern_tab.erase(i);
|
||||
}
|
||||
|
||||
|
||||
size_t PatternCacher::Size()
|
||||
{
|
||||
return pattern_tab.size();
|
||||
}
|
||||
|
||||
|
||||
void PatternCacher::RebuildCache(Ezc::Pattern & pattern)
|
||||
{
|
||||
pattern.ClearCache();
|
||||
|
||||
if( ezc_obj )
|
||||
pattern.CacheObjects(*ezc_obj);
|
||||
|
||||
if( ezc_fun )
|
||||
pattern.CacheFunctions(*ezc_fun);
|
||||
|
||||
if( ezc_blocks )
|
||||
pattern.CacheBlocks(*ezc_blocks);
|
||||
}
|
||||
|
||||
|
||||
void PatternCacher::RebuildCache()
|
||||
{
|
||||
PatternTab::iterator i = pattern_tab.begin();
|
||||
|
||||
for( ; i != pattern_tab.end() ; ++i)
|
||||
RebuildCache(i->second.pattern);
|
||||
}
|
||||
|
||||
|
||||
void PatternCacher::ClearCache()
|
||||
{
|
||||
PatternTab::iterator i = pattern_tab.begin();
|
||||
|
||||
for( ; i != pattern_tab.end() ; ++i)
|
||||
i->second.pattern.ClearCache();
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
160
winixd/templates/patterncacher.h
Normal file
160
winixd/templates/patterncacher.h
Normal file
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2015, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_templates_patterncacher
|
||||
#define headerfile_winix_templates_patterncacher
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "core/item.h"
|
||||
#include "misc.h"
|
||||
#include "ezc.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
class PatternCacher
|
||||
{
|
||||
public:
|
||||
|
||||
PatternCacher();
|
||||
|
||||
// setting when we should delete patterns
|
||||
// we are deleting when we have more (or equal) patterns than 'when_delete'
|
||||
// and then we are deleting 'how_many_del' patterns
|
||||
void SetWhenDelete(size_t when_delete, size_t how_many_del);
|
||||
|
||||
// remembering a pointer to ezc objects
|
||||
// this ezc objects (functions) will be cached in patterns
|
||||
void SetEzcObjects(Ezc::Objects<HtmlTextStream> * obj);
|
||||
|
||||
// remembering a pointer to ezc functions
|
||||
// this functions (pointers to them) will be cached in patterns
|
||||
void SetEzcFunctions(TemplatesFunctions::EzcFun * fun);
|
||||
|
||||
// remembering a pointer to ezc blocks
|
||||
// this blocks (pointers to them) will be cached in patterns
|
||||
void SetEzcBlocks(Ezc::Blocks * blocks);
|
||||
|
||||
// commentary prefix/postfix used in pattern_parser
|
||||
// (when there is an error)
|
||||
void SetEzcCommentary(const std::wstring & start, const std::wstring & end);
|
||||
|
||||
// returning a pattern corresponding to the 'item'
|
||||
Ezc::Pattern * GetPattern(const Item & item);
|
||||
|
||||
// updating the pattern for the item
|
||||
// if there is no such a pattern the method does nothing
|
||||
void UpdatePattern(const Item & item);
|
||||
|
||||
// deleting the pattern for the item
|
||||
// if there is no such a pattern the method does nothing
|
||||
void DeletePattern(const Item & item);
|
||||
|
||||
// deleting some rarely used patters
|
||||
// call it at the end of a request (or at the beginning)
|
||||
void DeleteOldPatterns();
|
||||
|
||||
// size of the current cache in use
|
||||
size_t Size();
|
||||
|
||||
// rebuild cache in all patterns
|
||||
void RebuildCache();
|
||||
|
||||
// clearing all pointers to functions and blocks
|
||||
void ClearCache();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
struct PatternUsed
|
||||
{
|
||||
Ezc::Pattern pattern;
|
||||
int used; // how many times used (incremented by GetPattern and UpdatePattern)
|
||||
int item_id;
|
||||
};
|
||||
|
||||
typedef std::map<long, PatternUsed> PatternTab;
|
||||
PatternTab pattern_tab;
|
||||
|
||||
|
||||
// temporarily struct used during deleting some items from pattern_tab
|
||||
struct PatternErase
|
||||
{
|
||||
PatternTab::iterator iter;
|
||||
int used;
|
||||
|
||||
bool operator<(const PatternErase & p) const { return used < p.used; }
|
||||
};
|
||||
|
||||
// temporarily buffer used during deleting some items from pattern_tab
|
||||
std::vector<PatternErase> erase_tab;
|
||||
|
||||
|
||||
|
||||
void CreatePattern(const Item & item, Ezc::Pattern & pattern);
|
||||
void AddIndexes(const Item & item, size_t pattern_index);
|
||||
Ezc::Pattern * AddPattern(const Item & item);
|
||||
|
||||
|
||||
// the size of pattern_tab when we are deleting some items
|
||||
size_t when_delete_patterns;
|
||||
|
||||
// how many items to delete
|
||||
size_t how_many_delete;
|
||||
|
||||
// can be null
|
||||
TemplatesFunctions::EzcFun * ezc_fun;
|
||||
|
||||
// can be null
|
||||
Ezc::Blocks * ezc_blocks;
|
||||
|
||||
// can be null
|
||||
Ezc::Objects<HtmlTextStream> * ezc_obj;
|
||||
|
||||
// parser for patterns
|
||||
Ezc::PatternParser pattern_parser;
|
||||
|
||||
void RebuildCache(Ezc::Pattern & pattern);
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
#endif
|
255
winixd/templates/patterns.cpp
Normal file
255
winixd/templates/patterns.cpp
Normal file
@@ -0,0 +1,255 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011-2015, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "patterns.h"
|
||||
#include "core/log.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
Patterns::Patterns()
|
||||
{
|
||||
del_white_items = false;
|
||||
ezc_fun = 0;
|
||||
ezc_blocks = 0;
|
||||
ezc_obj = 0;
|
||||
locale = 0;
|
||||
locale_filter = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Patterns::SetDeleteWhiteItems(bool del_white)
|
||||
{
|
||||
del_white_items = del_white;
|
||||
}
|
||||
|
||||
|
||||
void Patterns::SetDirectories(const std::wstring & tmpl_dir, const std::wstring & tmpl_dir_def)
|
||||
{
|
||||
templates_dir = tmpl_dir;
|
||||
templates_dir_def = tmpl_dir_def;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Patterns::SetLocale(Locale * plocale)
|
||||
{
|
||||
locale = plocale;
|
||||
}
|
||||
|
||||
|
||||
void Patterns::SetLocaleFilter(LocaleFilter * plocale_filter)
|
||||
{
|
||||
locale_filter = plocale_filter;
|
||||
}
|
||||
|
||||
|
||||
void Patterns::SetEzcFunctions(TemplatesFunctions::EzcFun * fun)
|
||||
{
|
||||
ezc_fun = fun;
|
||||
}
|
||||
|
||||
|
||||
void Patterns::SetEzcBlocks(Ezc::Blocks * blocks)
|
||||
{
|
||||
ezc_blocks = blocks;
|
||||
}
|
||||
|
||||
|
||||
void Patterns::SetEzcObjects(Ezc::Objects<HtmlTextStream> * obj)
|
||||
{
|
||||
ezc_obj = obj;
|
||||
}
|
||||
|
||||
|
||||
void Patterns::SetEzcCommentary(const std::wstring & start, const std::wstring & end)
|
||||
{
|
||||
pattern_parser.SetCommentary(start, end);
|
||||
}
|
||||
|
||||
|
||||
size_t Patterns::Add(const wchar_t * file_name, bool read_pattern)
|
||||
{
|
||||
for(size_t i=0 ; i<pat_tab.size() ; ++i)
|
||||
{
|
||||
if( pat_tab[i].references > 0 && pat_tab[i].file_name == file_name )
|
||||
{
|
||||
pat_tab[i].references += 1;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
template_temp.to_delete = false;
|
||||
template_temp.file_name = file_name;
|
||||
template_temp.references = 1;
|
||||
template_temp.patterns.clear();
|
||||
pat_tab.push_back(template_temp);
|
||||
|
||||
if( read_pattern )
|
||||
ReadPatterns(pat_tab.back());
|
||||
|
||||
return pat_tab.size()-1;
|
||||
}
|
||||
|
||||
|
||||
size_t Patterns::Add(const std::wstring & file_name, bool read_pattern)
|
||||
{
|
||||
return Add(file_name.c_str(), read_pattern);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Patterns::ReadPatterns(Template & templ)
|
||||
{
|
||||
size_t len = locale->Size();
|
||||
templ.patterns.resize(len);
|
||||
|
||||
/*
|
||||
* pattern_parser.SetCommentary() is set beforehand
|
||||
*/
|
||||
pattern_parser.DeleteWhiteTextItems(del_white_items);
|
||||
pattern_parser.Directory(templates_dir, templates_dir_def);
|
||||
|
||||
if( ezc_blocks )
|
||||
pattern_parser.SetBlocks(*ezc_blocks);
|
||||
|
||||
for(size_t i=0 ; i<len ; ++i)
|
||||
{
|
||||
pattern_parser.ParseFile(templ.file_name, templ.patterns[i]);
|
||||
locale_filter->Filter(templ.patterns[i], *locale, i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// caching should be done after all patterns are read
|
||||
// because patterns can define blocks
|
||||
void Patterns::RebuildCache()
|
||||
{
|
||||
for(size_t a = 0 ; a < pat_tab.size() ; ++a)
|
||||
{
|
||||
for(size_t b = 0 ; b < pat_tab[a].patterns.size() ; ++b)
|
||||
{
|
||||
Ezc::Pattern & pat = pat_tab[a].patterns[b];
|
||||
|
||||
pat.ClearCache();
|
||||
|
||||
if( ezc_obj )
|
||||
pat.CacheObjects(*ezc_obj);
|
||||
|
||||
if( ezc_fun )
|
||||
pat.CacheFunctions(*ezc_fun);
|
||||
|
||||
if( ezc_blocks )
|
||||
pat.CacheBlocks(*ezc_blocks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Ezc::Pattern * Patterns::Get(size_t index, size_t lang_id)
|
||||
{
|
||||
if( index >= pat_tab.size() || pat_tab[index].references == 0 )
|
||||
return 0;
|
||||
|
||||
size_t lang_index = locale->IdToIndex(lang_id);
|
||||
|
||||
if( lang_index >= pat_tab[index].patterns.size() )
|
||||
return 0;
|
||||
|
||||
return &pat_tab[index].patterns[lang_index];
|
||||
}
|
||||
|
||||
|
||||
const std::wstring & Patterns::GetFileName(size_t index)
|
||||
{
|
||||
if( index >= pat_tab.size() || pat_tab[index].references == 0 )
|
||||
return empty_str;
|
||||
|
||||
return pat_tab[index].file_name;
|
||||
}
|
||||
|
||||
|
||||
void Patterns::Reload()
|
||||
{
|
||||
for(size_t i=0 ; i<pat_tab.size() ; ++i)
|
||||
if( pat_tab[i].references > 0 )
|
||||
ReadPatterns(pat_tab[i]);
|
||||
|
||||
RebuildCache();
|
||||
}
|
||||
|
||||
|
||||
void Patterns::Clear()
|
||||
{
|
||||
pat_tab.clear();
|
||||
}
|
||||
|
||||
|
||||
void Patterns::Erase(size_t index)
|
||||
{
|
||||
if( index < pat_tab.size() && pat_tab[index].references > 0 )
|
||||
{
|
||||
pat_tab[index].references -= 1;
|
||||
|
||||
if( pat_tab[index].references == 0 )
|
||||
{
|
||||
log << log3 << "Patterns: removing pattern: " << pat_tab[index].file_name << logend;
|
||||
|
||||
pat_tab[index].file_name.clear();
|
||||
pat_tab[index].patterns.clear();
|
||||
// don't erase pat_tab.erase() here
|
||||
// because indices would be invalidated
|
||||
// those gaps will be cleared when Clear() method is called
|
||||
// normally in reload/templates winix function
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
size_t Patterns::Size()
|
||||
{
|
||||
return pat_tab.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
200
winixd/templates/patterns.h
Normal file
200
winixd/templates/patterns.h
Normal file
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011-2016, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_templates_patterns
|
||||
#define headerfile_winix_templates_patterns
|
||||
|
||||
#include <vector>
|
||||
#include "locale.h"
|
||||
#include "localefilter.h"
|
||||
#include "misc.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
class Patterns
|
||||
{
|
||||
public:
|
||||
|
||||
Patterns();
|
||||
|
||||
void SetDeleteWhiteItems(bool del_white);
|
||||
void SetDirectories(const std::wstring & tmpl_dir, const std::wstring & tmpl_dir_def);
|
||||
|
||||
/*
|
||||
setting locale and locale_filter
|
||||
this method should always be called on the beginning
|
||||
*/
|
||||
void SetLocale(Locale * plocale);
|
||||
void SetLocaleFilter(LocaleFilter * plocale_filter);
|
||||
|
||||
/*
|
||||
remembering a pointer to ezc functions
|
||||
this functions (pointers to them) will be cached in patterns
|
||||
|
||||
this caching will be done when a pattern is read from the hard drive
|
||||
so you have to call this method before
|
||||
*/
|
||||
void SetEzcFunctions(TemplatesFunctions::EzcFun * fun);
|
||||
|
||||
/*
|
||||
remembering a pointer to ezc blocks
|
||||
this blocks (pointers to them) will be cached in patterns
|
||||
|
||||
this caching will be done when a pattern is read from the hard drive
|
||||
so you have to call this method before
|
||||
*/
|
||||
void SetEzcBlocks(Ezc::Blocks * blocks);
|
||||
|
||||
|
||||
/*
|
||||
remembering a pointer to ezc objects
|
||||
*/
|
||||
void SetEzcObjects(Ezc::Objects<HtmlTextStream> * obj);
|
||||
|
||||
|
||||
/*
|
||||
commentary prefix/postfix used in pattern_parser
|
||||
(when there is an error)
|
||||
*/
|
||||
void SetEzcCommentary(const std::wstring & start, const std::wstring & end);
|
||||
|
||||
/*
|
||||
adding a new pattern and returning its index
|
||||
if the pattern already exists the method returns its index only
|
||||
and increment internal reference counter for such pattern
|
||||
|
||||
if read_pattern is false then the pattern is not read,
|
||||
it will be read when you call Reload() method
|
||||
|
||||
after adding some new patterns you have to call RebuildCache() method
|
||||
*/
|
||||
size_t Add(const wchar_t * file_name, bool read_pattern = true);
|
||||
size_t Add(const std::wstring & file_name, bool read_pattern = true);
|
||||
|
||||
|
||||
/*
|
||||
returning a pattern (if exists)
|
||||
if the pattern does not exist return a null pointer
|
||||
*/
|
||||
Ezc::Pattern * Get(size_t index, size_t lang_id);
|
||||
|
||||
|
||||
/*
|
||||
returning a file name of a pattern
|
||||
or an empty string if the pattern does not exist
|
||||
*/
|
||||
const std::wstring & GetFileName(size_t index);
|
||||
|
||||
|
||||
/*
|
||||
deleting all patterns
|
||||
*/
|
||||
void Clear();
|
||||
|
||||
|
||||
/*
|
||||
decrementing internal reference counter and if zero then deletes the pattern
|
||||
*/
|
||||
void Erase(size_t index);
|
||||
|
||||
|
||||
/*
|
||||
reloading all patterns and rebuilding cache
|
||||
*/
|
||||
void Reload();
|
||||
|
||||
|
||||
/*
|
||||
returning how many patterns do we have
|
||||
remember that we have one pattern for each language
|
||||
so the real number of patterns is: locale->Size() * Size()
|
||||
*/
|
||||
size_t Size();
|
||||
|
||||
|
||||
/*
|
||||
* rebuilding the cache for functions and blocks
|
||||
* you should call this method when you Add() new patterns
|
||||
*/
|
||||
void RebuildCache();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
bool del_white_items;
|
||||
std::wstring templates_dir, templates_dir_def;
|
||||
Locale * locale;
|
||||
LocaleFilter * locale_filter;
|
||||
|
||||
// can be null (not set directly)
|
||||
TemplatesFunctions::EzcFun * ezc_fun;
|
||||
|
||||
// can be null
|
||||
Ezc::Blocks * ezc_blocks;
|
||||
|
||||
// can be null
|
||||
Ezc::Objects<HtmlTextStream> * ezc_obj;
|
||||
|
||||
|
||||
|
||||
struct Template
|
||||
{
|
||||
bool to_delete;
|
||||
std::wstring file_name;
|
||||
size_t references; // starts from 1 (zero means the pattern was deleted)
|
||||
// (we do not delete the Template immediately because
|
||||
// indices would be invalidated)
|
||||
std::vector<Ezc::Pattern> patterns; // table[through lang index]
|
||||
};
|
||||
|
||||
typedef std::vector<Template> PatTab;
|
||||
PatTab pat_tab;
|
||||
Template template_temp;
|
||||
|
||||
// non-const for default assignment operator to be created
|
||||
std::wstring empty_str;
|
||||
|
||||
Ezc::PatternParser pattern_parser;
|
||||
|
||||
void ReadPatterns(Template & templ);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
#endif
|
311
winixd/templates/priv.cpp
Normal file
311
winixd/templates/priv.cpp
Normal file
@@ -0,0 +1,311 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
#include "core/request.h"
|
||||
#include "core/misc.h"
|
||||
#include "functions/functions.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
static std::vector<long> priv_user_table;
|
||||
static size_t priv_user_index;
|
||||
static size_t priv_user_reqid = 0;
|
||||
|
||||
|
||||
|
||||
void priv_user_tab_init(Item & item)
|
||||
{
|
||||
priv_user_reqid = cur->request->id;
|
||||
priv_user_table.clear();
|
||||
|
||||
if( !cur->session->puser )
|
||||
{
|
||||
// not logged
|
||||
priv_user_table.push_back(item.user_id);
|
||||
}
|
||||
else
|
||||
if( cur->session->puser->super_user )
|
||||
{
|
||||
// super user is allowed to change to any user
|
||||
for(Users::Iterator i=system->users.Begin() ; i != system->users.End() ; ++i)
|
||||
priv_user_table.push_back(i->id);
|
||||
|
||||
// as well to nobody (-1)
|
||||
priv_user_table.push_back(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// others
|
||||
priv_user_table.push_back(item.user_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void priv_user_tab_init()
|
||||
{
|
||||
if( cur->request->is_item )
|
||||
priv_user_tab_init(cur->request->item);
|
||||
else
|
||||
priv_user_tab_init(*cur->request->dir_tab.back());
|
||||
}
|
||||
|
||||
|
||||
void priv_user_tab(Info & i)
|
||||
{
|
||||
if( priv_user_reqid != cur->request->id )
|
||||
priv_user_tab_init();
|
||||
|
||||
priv_user_index = i.iter;
|
||||
i.res = priv_user_index < priv_user_table.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void priv_user_tab_name(Info & i)
|
||||
{
|
||||
if( priv_user_index < priv_user_table.size() )
|
||||
{
|
||||
long uid = priv_user_table[priv_user_index];
|
||||
|
||||
if( uid != -1 )
|
||||
{
|
||||
User * puser = system->users.GetUser( uid );
|
||||
|
||||
if( puser )
|
||||
i.out << puser->name;
|
||||
else
|
||||
i.out << "user_id: " << uid;
|
||||
}
|
||||
else
|
||||
{
|
||||
i.out << config->priv_no_user;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void priv_user_tab_isdefault(Info & i)
|
||||
{
|
||||
if( priv_user_index < priv_user_table.size() )
|
||||
{
|
||||
long uid = priv_user_table[priv_user_index];
|
||||
|
||||
if( cur->request->is_item )
|
||||
{
|
||||
if( uid == cur->request->item.user_id )
|
||||
i.res = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( uid == cur->request->dir_tab.back()->user_id )
|
||||
i.res = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static std::vector<long> priv_group_table;
|
||||
static size_t priv_group_index;
|
||||
static size_t priv_group_reqid = 0;
|
||||
|
||||
|
||||
|
||||
void priv_group_tab_init(Item & item)
|
||||
{
|
||||
priv_group_reqid = cur->request->id;
|
||||
priv_group_table.clear();
|
||||
|
||||
if( !cur->session->puser )
|
||||
{
|
||||
// not logged
|
||||
priv_group_table.push_back(item.group_id);
|
||||
}
|
||||
else
|
||||
if( cur->session->puser->super_user )
|
||||
{
|
||||
// super user is allowed to change to any group
|
||||
for(Groups::Iterator i=system->groups.Begin() ; i != system->groups.End() ; ++i)
|
||||
priv_group_table.push_back(i->id);
|
||||
|
||||
// as well to nogroup (-1)
|
||||
priv_group_table.push_back(-1);
|
||||
}
|
||||
else
|
||||
if( cur->session->puser->id == item.user_id )
|
||||
{
|
||||
bool was_current_group = false;
|
||||
// owner of the item -- is allowed to change only to a group in which he belongs to
|
||||
for(size_t i=0 ; i<cur->session->puser->groups.size() ; ++i)
|
||||
{
|
||||
priv_group_table.push_back(cur->session->puser->groups[i]);
|
||||
|
||||
if( item.group_id == cur->session->puser->groups[i] )
|
||||
was_current_group = true;
|
||||
}
|
||||
|
||||
// we're showing the item.group_id if it's different
|
||||
if( !was_current_group )
|
||||
priv_group_table.push_back(item.group_id);
|
||||
|
||||
// switching to -1 is allowed too
|
||||
priv_group_table.push_back(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// not the owner and not a super user -- the same as not logged
|
||||
priv_group_table.push_back(item.group_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void priv_group_tab_init()
|
||||
{
|
||||
if( cur->request->is_item )
|
||||
priv_group_tab_init(cur->request->item);
|
||||
else
|
||||
priv_group_tab_init(*cur->request->dir_tab.back());
|
||||
}
|
||||
|
||||
|
||||
void priv_group_tab(Info & i)
|
||||
{
|
||||
if( priv_group_reqid != cur->request->id )
|
||||
priv_group_tab_init();
|
||||
|
||||
priv_group_index = i.iter;
|
||||
i.res = priv_group_index < priv_group_table.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void priv_group_tab_name(Info & i)
|
||||
{
|
||||
if( priv_group_index < priv_group_table.size() )
|
||||
{
|
||||
long gid = priv_group_table[priv_group_index];
|
||||
|
||||
if( gid != -1 )
|
||||
{
|
||||
Group * pgroup = system->groups.GetGroup( gid );
|
||||
|
||||
if( pgroup )
|
||||
i.out << pgroup->name;
|
||||
else
|
||||
i.out << "group_id: " << gid;
|
||||
}
|
||||
else
|
||||
{
|
||||
i.out << config->priv_no_group;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void priv_group_tab_isdefault(Info & i)
|
||||
{
|
||||
if( priv_group_index < priv_group_table.size() )
|
||||
{
|
||||
long gid = priv_group_table[priv_group_index];
|
||||
|
||||
if( cur->request->is_item )
|
||||
{
|
||||
if( gid == cur->request->item.group_id )
|
||||
i.res = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( gid == cur->request->dir_tab.back()->group_id )
|
||||
i.res = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void priv_privileges(Info & i)
|
||||
{
|
||||
if( cur->request->is_item )
|
||||
i.out << Toa(cur->request->item.privileges, 8);
|
||||
else
|
||||
i.out << Toa(cur->request->dir_tab.back()->privileges, 8);
|
||||
}
|
||||
|
||||
|
||||
void priv_privileges_for_files(Info & i)
|
||||
{
|
||||
i.out << Toa(system->NewFilePrivileges(), 8);
|
||||
}
|
||||
|
||||
|
||||
void priv_privileges_for_dirs(Info & i)
|
||||
{
|
||||
i.out << Toa(system->NewDirPrivileges(), 8);
|
||||
}
|
||||
|
||||
|
||||
void priv_show_form_chown(Info & i)
|
||||
{
|
||||
i.res = (cur->request->function == &functions->fun_priv || cur->request->function == &functions->fun_chown);
|
||||
}
|
||||
|
||||
|
||||
void priv_show_form_chmod(Info & i)
|
||||
{
|
||||
i.res = (cur->request->function == &functions->fun_priv || cur->request->function == &functions->fun_chmod);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
} // namespace Winix
|
||||
|
81
winixd/templates/rebus.cpp
Normal file
81
winixd/templates/rebus.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "core/request.h"
|
||||
#include "templates.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
static size_t rebus_reqid = 0;
|
||||
|
||||
|
||||
|
||||
void rebus_init()
|
||||
{
|
||||
if( rebus_reqid != cur->request->id )
|
||||
{
|
||||
cur->session->rebus_item = system->rebus.Rand();
|
||||
cur->session->rebus_checked = false;
|
||||
rebus_reqid = cur->request->id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void rebus_question(Info & i)
|
||||
{
|
||||
rebus_init();
|
||||
|
||||
if( cur->session->rebus_item )
|
||||
i.out << cur->session->rebus_item->question;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
66
winixd/templates/server.cpp
Normal file
66
winixd/templates/server.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2015, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
#include "functions/functions.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
|
||||
void server_mode(Info & i)
|
||||
{
|
||||
i.out << config->server_mode;
|
||||
}
|
||||
|
||||
|
||||
void server_mode_is(Info & i)
|
||||
{
|
||||
i.res = (i.par == config->server_mode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
162
winixd/templates/slog.cpp
Normal file
162
winixd/templates/slog.cpp
Normal file
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "core/slog.h"
|
||||
#include "templates.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
static size_t slog_index = 0;
|
||||
static LogManipulators slog_last_type;
|
||||
|
||||
|
||||
|
||||
bool slog_is()
|
||||
{
|
||||
if( !cur->session )
|
||||
return false;
|
||||
|
||||
return slog_index < cur->session->log_buffer.Size();
|
||||
}
|
||||
|
||||
|
||||
void slog_skipline()
|
||||
{
|
||||
if( !cur->session )
|
||||
return;
|
||||
|
||||
TextStream<std::wstring> & buf = cur->session->log_buffer;
|
||||
|
||||
while( slog_index < buf.Size() && buf[slog_index]!=10 )
|
||||
slog_index += 1;
|
||||
|
||||
if( slog_index < buf.Size() )
|
||||
slog_index += 1; // skipping the '\n'
|
||||
}
|
||||
|
||||
|
||||
void slog_settype()
|
||||
{
|
||||
if( !slog_is() )
|
||||
return;
|
||||
|
||||
TextStream<std::wstring> & buf = cur->session->log_buffer;
|
||||
slog_last_type = static_cast<LogManipulators>(buf[slog_index]);
|
||||
|
||||
switch( slog_last_type )
|
||||
{
|
||||
case loginfo:
|
||||
case logwarning:
|
||||
case logerror:
|
||||
slog_index += 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
slog_last_type = loginfo;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void slog_tab(Info & i)
|
||||
{
|
||||
if( i.iter == 0 )
|
||||
slog_index = 0;
|
||||
else
|
||||
slog_skipline();
|
||||
|
||||
// the type is written as the first character (after '\n' or at the beginning of the string)
|
||||
slog_settype();
|
||||
|
||||
i.res = slog_is();
|
||||
|
||||
if( cur->session && !i.res )
|
||||
cur->session->log_buffer.Clear(); // the session log has been printed
|
||||
}
|
||||
|
||||
|
||||
void slog_tab_is_info(Info & i)
|
||||
{
|
||||
if( !slog_is() )
|
||||
return;
|
||||
|
||||
i.res = (slog_last_type == loginfo);
|
||||
}
|
||||
|
||||
|
||||
void slog_tab_is_warning(Info & i)
|
||||
{
|
||||
if( !slog_is() )
|
||||
return;
|
||||
|
||||
i.res = (slog_last_type == logwarning);
|
||||
}
|
||||
|
||||
|
||||
void slog_tab_is_error(Info & i)
|
||||
{
|
||||
if( !slog_is() )
|
||||
return;
|
||||
|
||||
i.res = (slog_last_type == logerror);
|
||||
}
|
||||
|
||||
|
||||
void slog_tab_print(Info & i)
|
||||
{
|
||||
if( !slog_is() )
|
||||
return;
|
||||
|
||||
TextStream<std::wstring> & buf = cur->session->log_buffer;
|
||||
|
||||
while( slog_index < buf.Size() && buf[slog_index]!=10 )
|
||||
{
|
||||
i.out << buf[slog_index];
|
||||
slog_index += 1;
|
||||
}
|
||||
|
||||
// don't skip the last '\n' here
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
} // namespace Winix
|
||||
|
136
winixd/templates/stat.cpp
Normal file
136
winixd/templates/stat.cpp
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
#include "misc.h"
|
||||
#include "core/request.h"
|
||||
#include "core/misc.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
void stat_item_type_is_file(Info & i)
|
||||
{
|
||||
i.res = cur->request->is_item && cur->request->item.file_type == WINIX_ITEM_FILETYPE_NONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void stat_item_type_is_static_file(Info & i)
|
||||
{
|
||||
i.res = cur->request->is_item && cur->request->item.file_type != WINIX_ITEM_FILETYPE_NONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void stat_item_type_is_dir(Info & i)
|
||||
{
|
||||
i.res = !cur->request->is_item;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void stat_item_inode(Info & i)
|
||||
{
|
||||
i.out << cur->request->last_item->id;
|
||||
}
|
||||
|
||||
|
||||
void stat_item_user(Info & i)
|
||||
{
|
||||
User * puser = system->users.GetUser(cur->request->last_item->user_id);
|
||||
print_user_name(i, puser, cur->request->last_item->guest_name);
|
||||
}
|
||||
|
||||
|
||||
void stat_item_group(Info & i)
|
||||
{
|
||||
long group_id = cur->request->last_item->group_id;
|
||||
Group * pgroup = system->groups.GetGroup(group_id);
|
||||
|
||||
if( pgroup )
|
||||
i.out << pgroup->name;
|
||||
else
|
||||
i.out << group_id;
|
||||
}
|
||||
|
||||
|
||||
void stat_item_privileges(Info & i)
|
||||
{
|
||||
i.out << Toa(cur->request->last_item->privileges, 8);
|
||||
}
|
||||
|
||||
|
||||
void stat_item_date_creation(Info & i)
|
||||
{
|
||||
PT::Date date = system->ToLocal(cur->request->last_item->date_creation);
|
||||
i.out << DateToStr(date.year, date.month, date.day, date.hour, date.min, date.sec);
|
||||
}
|
||||
|
||||
|
||||
void stat_item_date_modification(Info & i)
|
||||
{
|
||||
PT::Date date = system->ToLocal(cur->request->last_item->date_modification);
|
||||
i.out << DateToStr(date.year, date.month, date.day, date.hour, date.min, date.sec);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void stat_item_template(Info & i)
|
||||
{
|
||||
i.out << cur->request->last_item->html_template;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void stat_item_is_template_from_mount_point(Info & i)
|
||||
{
|
||||
i.res = cur->request->last_item->html_template.empty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
|
103
winixd/templates/sys.cpp
Normal file
103
winixd/templates/sys.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
#include "core/request.h"
|
||||
#include "core/version.h"
|
||||
#include "core/plugin.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
void sys_ver_major(Info & i)
|
||||
{
|
||||
i.out << WINIX_VER_MAJOR;
|
||||
}
|
||||
|
||||
|
||||
void sys_ver_minor(Info & i)
|
||||
{
|
||||
i.out << WINIX_VER_MINOR;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void sys_ver_revision(Info & i)
|
||||
{
|
||||
i.out << WINIX_VER_REVISION;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static size_t sys_plugin_index = 0;
|
||||
|
||||
|
||||
void sys_plugin_tab(Info & i)
|
||||
{
|
||||
sys_plugin_index = i.iter;
|
||||
i.res = sys_plugin_index < plugin.GetPlugins()->size();
|
||||
}
|
||||
|
||||
void sys_plugin_tab_has_name(Info & i)
|
||||
{
|
||||
if( sys_plugin_index < plugin.GetPlugins()->size() )
|
||||
i.res = (*plugin.GetPlugins())[sys_plugin_index].plugin_name != 0;
|
||||
}
|
||||
|
||||
void sys_plugin_tab_name(Info & i)
|
||||
{
|
||||
if( sys_plugin_index < plugin.GetPlugins()->size() )
|
||||
{
|
||||
const wchar_t * name = (*plugin.GetPlugins())[sys_plugin_index].plugin_name;
|
||||
|
||||
if( name )
|
||||
i.out << name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
150
winixd/templates/template.cpp
Normal file
150
winixd/templates/template.cpp
Normal file
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "templates.h"
|
||||
#include "core/misc.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
void template_index(Info & i)
|
||||
{
|
||||
i.out << config->templates_index;
|
||||
}
|
||||
|
||||
|
||||
static std::vector<std::wstring> 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::wstring * html_file;
|
||||
|
||||
if( cur->request->is_item )
|
||||
html_file = &cur->request->item.html_template;
|
||||
else
|
||||
html_file = &cur->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);
|
||||
|
||||
Mount::ParamRow & par = system->mounts.pmount->param[system->mounts.MountParHtmlTemplate()];
|
||||
|
||||
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( cur->request->id != temp_req_id )
|
||||
{
|
||||
temp_req_id = cur->request->id;
|
||||
template_init();
|
||||
}
|
||||
|
||||
temp_index = i.iter;
|
||||
i.res = temp_index < temp_tab.size();
|
||||
}
|
||||
|
||||
|
||||
void template_tab_index(Info & i)
|
||||
{
|
||||
i.out << temp_index;
|
||||
}
|
||||
|
||||
|
||||
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() )
|
||||
i.out << temp_tab[temp_index];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace Winix
|
||||
|
1204
winixd/templates/templates.cpp
Normal file
1204
winixd/templates/templates.cpp
Normal file
File diff suppressed because it is too large
Load Diff
712
winixd/templates/templates.h
Normal file
712
winixd/templates/templates.h
Normal file
@@ -0,0 +1,712 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2015, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_templates_templates
|
||||
#define headerfile_winix_templates_templates
|
||||
|
||||
#include <iomanip>
|
||||
#include <set>
|
||||
#include "ezc.h"
|
||||
#include "misc.h"
|
||||
#include "patterncacher.h"
|
||||
#include "indexpatterns.h"
|
||||
#include "locale.h"
|
||||
#include "patterns.h"
|
||||
#include "changepatterns.h"
|
||||
#include "htmltextstream.h"
|
||||
#include "localefilter.h"
|
||||
#include "core/config.h"
|
||||
#include "core/cur.h"
|
||||
#include "core/system.h"
|
||||
#include "core/sessionmanager.h"
|
||||
#include "core/htmlfilter.h"
|
||||
#include "db/db.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
class Functions;
|
||||
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
extern size_t pat_index;
|
||||
extern size_t pat_index_fullscreen;
|
||||
extern size_t pat_err_404;
|
||||
extern size_t pat_err_per_denied;
|
||||
|
||||
extern Patterns patterns;
|
||||
extern IndexPatterns index_patterns;
|
||||
extern ChangePatterns change_patterns;
|
||||
extern PatternCacher pattern_cacher;
|
||||
extern Locale locale;
|
||||
extern EzcFun ezc_functions;
|
||||
extern LocaleFilter locale_filter;
|
||||
extern HTMLFilter html_filter;
|
||||
extern Ezc::Stack empty_stack;
|
||||
|
||||
extern Db * db;
|
||||
extern Cur * cur;
|
||||
extern Config * config;
|
||||
extern System * system;
|
||||
extern Functions * functions;
|
||||
extern SessionManager * session_manager;
|
||||
|
||||
extern bool gen_trim_white;
|
||||
extern bool gen_skip_new_line;
|
||||
extern bool gen_use_special_chars;
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
adduser
|
||||
*/
|
||||
void adduser_last_login(Info & i);
|
||||
void adduser_last_email(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
config
|
||||
*/
|
||||
void config_use_ssl(Info & i);
|
||||
void config_use_ssl_static(Info & i);
|
||||
void config_use_ssl_common(Info & i);
|
||||
void config_url_proto(Info & i);
|
||||
void config_url_ssl_proto(Info & i);
|
||||
void config_base_url(Info & i);
|
||||
void config_base_url_static(Info & i);
|
||||
void config_base_url_common(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
current date
|
||||
*/
|
||||
void current_sec_utc(Info & i);
|
||||
void current_min_utc(Info & i);
|
||||
void current_hour_utc(Info & i);
|
||||
void current_day_utc(Info & i);
|
||||
void current_month_utc(Info & i);
|
||||
void current_year_utc(Info & i);
|
||||
void current_date_utc(Info & i);
|
||||
void current_sec(Info & i);
|
||||
void current_min(Info & i);
|
||||
void current_hour(Info & i);
|
||||
void current_day(Info & i);
|
||||
void current_month(Info & i);
|
||||
void current_year(Info & i);
|
||||
void current_date(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
dir
|
||||
*/
|
||||
void dir(Info & i);
|
||||
void dir_without_slash(Info & i);
|
||||
void dir_is_root(Info & i);
|
||||
void dir_parent(Info & i);
|
||||
void dir_parent_without_slash(Info & i);
|
||||
void dir_can_read_exec(Info & i);
|
||||
void dir_can_write(Info & i);
|
||||
void dir_can_remove(Info & i);
|
||||
void dir_can_use_emacs(Info & i);
|
||||
void dir_can_use_mkdir(Info & i);
|
||||
void dir_is(Info & i);
|
||||
void dir_is_no(Info & i);
|
||||
void dir_has_parents(Info & i);
|
||||
void dir_level_is(Info & i);
|
||||
|
||||
void dir_childs_tab(Info & i);
|
||||
void dir_childs_is_parent(Info & i);
|
||||
void dir_childs_tab_url(Info & i);
|
||||
void dir_childs_tab_privileges(Info & i);
|
||||
void dir_childs_tab_user(Info & i);
|
||||
void dir_childs_tab_group(Info & i);
|
||||
|
||||
void dir_tab(Info & i);
|
||||
void dir_tab_url(Info & i);
|
||||
void dir_tab_link(Info & i);
|
||||
void dir_tab_subject(Info & i);
|
||||
void dir_tab_is_root(Info & i);
|
||||
|
||||
void dir_last_link_to(Info &);
|
||||
void dir_last_is_link_redirect(Info & i);
|
||||
void dir_last_subject(Info & i);
|
||||
void dir_last_user(Info & i);
|
||||
void dir_last_url(Info & i);
|
||||
void dir_last_url_is(Info & i);
|
||||
void dir_last_url_is_no(Info & i);
|
||||
void dir_last_date_creation(Info & i);
|
||||
void dir_last_date_modification(Info & i);
|
||||
void dir_last_date_creation_nice(Info & i);
|
||||
void dir_last_date_modification_nice(Info & i);
|
||||
void dir_last_dates_equal(Info & i);
|
||||
void dir_last_users_different(Info & i);
|
||||
void dir_last_modification_user(Info & i);
|
||||
void dir_last_html_template(Info & i);
|
||||
void dir_last_has_html_template(Info & i);
|
||||
void dir_last_meta_str(Info & i);
|
||||
void dir_last_meta(Info & i);
|
||||
void dir_last_meta_tab(Info & i);
|
||||
void dir_last_meta_tab_value(Info & i);
|
||||
void dir_last_meta_tab_has_next(Info & i);
|
||||
void dir_last_admin_meta_str(Info & i);
|
||||
void dir_last_admin_meta(Info & i);
|
||||
void dir_last_admin_meta_tab(Info & i);
|
||||
void dir_last_admin_meta_tab_value(Info & i);
|
||||
void dir_last_admin_meta_tab_has_next(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
doc
|
||||
*/
|
||||
void doc_title(Info & i);
|
||||
void doc_proto(Info & i);
|
||||
void doc_proto_static(Info & i);
|
||||
void doc_proto_common(Info & i);
|
||||
void doc_base_url(Info & i);
|
||||
void doc_base_url_static(Info & i);
|
||||
void doc_base_url_common(Info & i);
|
||||
void doc_current_url(Info & i);
|
||||
void doc_css_tab(Info & i);
|
||||
void doc_css_tab_file(Info & i);
|
||||
void doc_css_tab_file_is_global(Info & i);
|
||||
void doc_css_tab_has_next(Info & i);
|
||||
void doc_css_is_empty(Info & i);
|
||||
void doc_css_is_one(Info & i);
|
||||
void doc_css_more_than_one(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
env
|
||||
*/
|
||||
void env_str(Info & i);
|
||||
void env(Info & i);
|
||||
void env_tab(Info & i);
|
||||
void env_tab_value(Info & i);
|
||||
void env_tab_has_next(Info & i);
|
||||
void env_admin_str(Info & i);
|
||||
void env_admin(Info & i);
|
||||
void env_admin_tab(Info & i);
|
||||
void env_admin_tab_value(Info & i);
|
||||
void env_admin_tab_has_next(Info & i);
|
||||
void env_user_admin_env_str(Info & i);
|
||||
void env_user_env_str(Info & i);
|
||||
void env_user_id(Info & i);
|
||||
void env_user_name(Info & i);
|
||||
void env_user_tab(Info & i);
|
||||
void env_user_tab_id(Info & i);
|
||||
void env_user_tab_name(Info & i);
|
||||
void env_user_tab_is_current(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
filters
|
||||
*/
|
||||
void fil_urlencode(Info & i);
|
||||
void fil_qencode(Info & i);
|
||||
void fil_capitalize(Info & i);
|
||||
void fil_tosmall(Info & i);
|
||||
void fil_firstup(Info & i);
|
||||
void fil_first_wordup(Info & i);
|
||||
void fil_csv_escape(Info & i);
|
||||
void fil_new_line_to_br(Info & i);
|
||||
void fil_html_quote(Info & i);
|
||||
void fil_html_newline(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
generic functions
|
||||
*/
|
||||
void ezc_false(Info & i);
|
||||
void ezc_true(Info & i);
|
||||
void ezc_and(Info & i);
|
||||
void ezc_any(Info & i);
|
||||
void ezc_or(Info & i);
|
||||
void ezc_one(Info & i);
|
||||
void ezc_and_not(Info & i);
|
||||
void ezc_any_not(Info & i);
|
||||
void ezc_or_not(Info & i);
|
||||
void ezc_one_not(Info & i);
|
||||
void ezc_not(Info & i);
|
||||
void cmp(Info & i);
|
||||
void is(Info & i);
|
||||
void is_not(Info & i);
|
||||
void is_empty(Info & i);
|
||||
void is_not_empty(Info & i);
|
||||
void trim(Info & i);
|
||||
void to_lower(Info & i);
|
||||
void to_upper(Info & i);
|
||||
void index(Info & i);
|
||||
void str(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
insert
|
||||
*/
|
||||
void insert_page(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
ipban
|
||||
*/
|
||||
void ipban_is_current_ip_banned(Info & i);
|
||||
void ipban_current_ip_expires_time(Info & i);
|
||||
void ipban_is_login_allowed_from_this_ip(Info & i);
|
||||
void ipban_tab(Info & i);
|
||||
void ipban_tab_id(Info & i);
|
||||
void ipban_tab_ip(Info & i);
|
||||
void ipban_tab_incorrect_login(Info & i);
|
||||
void ipban_tab_broken_encoded_cookie(Info & i);
|
||||
void ipban_tab_session_hijacking(Info & i);
|
||||
void ipban_tab_no_session_cookie(Info & i);
|
||||
void ipban_tab_ban_level(Info & i);
|
||||
void ipban_tab_has_active_flag(Info & i);
|
||||
void ipban_tab_expires(Info & i);
|
||||
void ipban_tab_last_used(Info & i);
|
||||
void ipban_tab_is_logging_allowed(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
item
|
||||
*/
|
||||
void item_is(Info & i);
|
||||
void item_no_is(Info & i);
|
||||
void item_id(Info & i);
|
||||
void item_subject(Info & i);
|
||||
void item_subject_noescape(Info & i);
|
||||
void item_content(Info & i);
|
||||
void item_content_noescape(Info & i);
|
||||
void item_content_type_is(Item & item, Info & i);
|
||||
void item_content_type_is(Info & i);
|
||||
void item_content_is_empty(Info & i);
|
||||
void item_print_content(HtmlTextStream & out, const std::wstring & content, Item::ContentType content_type);
|
||||
void item_print_content(Info & i);
|
||||
void item_privileges(Info & i);
|
||||
void item_dir(Info & i);
|
||||
void item_url(Info & i);
|
||||
void item_url_is(Info & i);
|
||||
void item_url_is_no(Info & i);
|
||||
void item_link(Info & i);
|
||||
void item_filetype_is_none(Info & i);
|
||||
void item_filetype_is_image(Info & i);
|
||||
void item_has_static_file(Info & i);
|
||||
void item_has_thumb(Info & i);
|
||||
void item_can_read(Info & i);
|
||||
void item_can_write(Info & i);
|
||||
void item_can_remove(Info & i);
|
||||
void item_user(Info & i);
|
||||
void item_modification_user(Info & i);
|
||||
void item_users_different(Info & i);
|
||||
void item_date_creation(Info & i);
|
||||
void item_date_modification(Info & i);
|
||||
void item_date_creation_nice(Info & i);
|
||||
void item_date_modification_nice(Info & i);
|
||||
void item_dates_equal(Info & i);
|
||||
void item_run(Info & i);
|
||||
void item_guest_name(Info & i);
|
||||
void item_html_template(Info & i);
|
||||
void item_has_html_template(Info & i);
|
||||
void item_type_is_dir(Info & i);
|
||||
void item_type_is_file(Info & i);
|
||||
void item_type_is_symlink(Info & i);
|
||||
void item_is_link_to(Info & i);
|
||||
void item_link_to(Info & i);
|
||||
void item_is_link_redirect(Info & i);
|
||||
void item_file_size(Info & i);
|
||||
void item_sort(Info & i);
|
||||
void item_meta_str(Info & i);
|
||||
void item_meta(Info & i);
|
||||
void item_meta_tab(Info & i);
|
||||
void item_meta_tab_value(Info & i);
|
||||
void item_meta_tab_has_next(Info & i);
|
||||
void item_admin_meta_str(Info & i);
|
||||
void item_admin_meta(Info & i);
|
||||
void item_admin_meta_tab(Info & i);
|
||||
void item_admin_meta_tab_value(Info & i);
|
||||
void item_admin_meta_tab_has_next(Info & i);
|
||||
|
||||
void item_tab(Info & i);
|
||||
void item_tab_index(Info & i);
|
||||
void item_tab_id(Info & i);
|
||||
void item_tab_subject(Info & i);
|
||||
void item_tab_subject_noescape(Info & i);
|
||||
void item_tab_content(Info & i);
|
||||
void item_tab_content_noescape(Info & i);
|
||||
void item_tab_print_content(Info & i);
|
||||
void item_tab_privileges(Info & i);
|
||||
void item_tab_dir(Info & i);
|
||||
void item_tab_url(Info & i);
|
||||
void item_tab_link(Info & i);
|
||||
void item_tab_filetype_is_none(Info & i);
|
||||
void item_tab_filetype_is_image(Info & i);
|
||||
void item_tab_can_read(Info & i);
|
||||
void item_tab_can_write(Info & i);
|
||||
void item_tab_user(Info & i);
|
||||
void item_tab_modification_user(Info & i);
|
||||
void item_tab_users_different(Info & i);
|
||||
void item_tab_group(Info & i);
|
||||
void item_tab_date_creation(Info & i);
|
||||
void item_tab_date_modification(Info & i);
|
||||
void item_tab_date_creation_nice(Info & i);
|
||||
void item_tab_date_modification_nice(Info & i);
|
||||
void item_tab_dates_equal(Info & i);
|
||||
void item_tab_run(Info & i);
|
||||
void item_tab_can_use_emacs(Info & i);
|
||||
void item_tab_has_static_file(Info & i);
|
||||
void item_tab_has_thumb(Info & i);
|
||||
void item_tab_type_is_dir(Info & i);
|
||||
void item_tab_type_is_file(Info & i);
|
||||
void item_tab_type_is_symlink(Info & i);
|
||||
void item_tab_is_link_to(Info & i);
|
||||
void item_tab_link_to(Info & i);
|
||||
void item_tab_is_link_redirect(Info & i);
|
||||
void item_tab_file_size(Info & i);
|
||||
void item_tab_sort(Info & i);
|
||||
void item_tab_has_next(Info & i);
|
||||
void item_tab_meta_str(Info & i);
|
||||
void item_tab_meta(Info & i);
|
||||
void item_tab_meta_tab(Info & i);
|
||||
void item_tab_meta_tab_value(Info & i);
|
||||
void item_tab_meta_tab_has_next(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
last
|
||||
*/
|
||||
void last_tab(Info & i);
|
||||
void last_tab_name(Info & i);
|
||||
void last_tab_ip(Info & i);
|
||||
void last_tab_start(Info & i);
|
||||
void last_tab_end(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
login
|
||||
*/
|
||||
void login_path(Info & i);
|
||||
void login_should_use_captcha(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
man
|
||||
*/
|
||||
void man_winixfun_tab(Info & i);
|
||||
void man_winixfun_tab_index(Info & i);
|
||||
void man_winixfun_tab_name(Info & i);
|
||||
void man_ezcfun_tab(Info & i);
|
||||
void man_ezcfun_tab_index(Info & i);
|
||||
void man_ezcfun_tab_name(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
mount
|
||||
*/
|
||||
void mount_type_is(Info & i);
|
||||
void mount_page_arg_is(Info & i);
|
||||
void mount_lang_arg(Info & i);
|
||||
void mount_lang_arg_is(Info & i);
|
||||
void mount_has_html_template(Info & i);
|
||||
void mount_first_html_template(Info & i);
|
||||
void mount_css_tab(Info & i);
|
||||
void mount_css_tab_file(Info & i);
|
||||
void mount_css_tab_file_is_global(Info & i);
|
||||
void mount_css_tab_has_next(Info & i);
|
||||
void mount_css_is_empty(Info & i);
|
||||
void mount_css_is_one(Info & i);
|
||||
void mount_css_more_than_one(Info & i);
|
||||
void mount_cur_type(Info & i);
|
||||
void mount_cur_dir(Info & i);
|
||||
void mount_cur_fs(Info & i);
|
||||
void mount_cur_parlist(Info & i);
|
||||
void mount_tab(Info & i);
|
||||
void mount_tab_type(Info & i);
|
||||
void mount_tab_dir(Info & i);
|
||||
void mount_tab_fs(Info & i);
|
||||
void mount_tab_parlist(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
passwd
|
||||
*/
|
||||
void passwd_resetpass_login(Info & i);
|
||||
void passwd_resetpass_code(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
|
||||
*/
|
||||
void ls_ckeditor_funnum_browse(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
privileges
|
||||
*/
|
||||
void priv_user_tab(Info & i);
|
||||
void priv_user_tab_name(Info & i);
|
||||
void priv_user_tab_isdefault(Info & i);
|
||||
|
||||
void priv_group_tab(Info & i);
|
||||
void priv_group_tab_name(Info & i);
|
||||
void priv_group_tab_isdefault(Info & i);
|
||||
|
||||
void priv_privileges(Info & i);
|
||||
void priv_privileges_for_files(Info & i);
|
||||
void priv_privileges_for_dirs(Info & i);
|
||||
|
||||
void priv_show_form_chown(Info & i);
|
||||
void priv_show_form_chmod(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
pw
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
rebus
|
||||
*/
|
||||
void rebus_question(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
server
|
||||
*/
|
||||
void server_mode(Info & i);
|
||||
void server_mode_is(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
slog
|
||||
*/
|
||||
void slog_tab(Info & i);
|
||||
void slog_tab_is_info(Info & i);
|
||||
void slog_tab_is_warning(Info & i);
|
||||
void slog_tab_is_error(Info & i);
|
||||
void slog_tab_print(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
stat
|
||||
*/
|
||||
void stat_item_type_is_file(Info & i);
|
||||
void stat_item_type_is_static_file(Info & i);
|
||||
void stat_item_type_is_dir(Info & i);
|
||||
void stat_item_inode(Info & i);
|
||||
void stat_item_user(Info & i);
|
||||
void stat_item_group(Info & i);
|
||||
void stat_item_privileges(Info & i);
|
||||
void stat_item_date_creation(Info & i);
|
||||
void stat_item_date_modification(Info & i);
|
||||
void stat_item_template(Info & i);
|
||||
void stat_item_is_template_from_mount_point(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
sys
|
||||
*/
|
||||
void sys_ver_major(Info & i);
|
||||
void sys_ver_minor(Info & i);
|
||||
void sys_ver_revision(Info & i);
|
||||
void sys_plugin_tab(Info & i);
|
||||
void sys_plugin_tab_has_name(Info & i);
|
||||
void sys_plugin_tab_name(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
upload
|
||||
*/
|
||||
void upload_ckeditor_funnum(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
uptime
|
||||
*/
|
||||
void uptime_more_than_one_day(Info & i);
|
||||
void uptime_days(Info & i);
|
||||
void uptime_hours(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
user
|
||||
*/
|
||||
void user_id(Info & i);
|
||||
void user_name(Info & i);
|
||||
void user_logged(Info & i);
|
||||
void user_super_user(Info & i);
|
||||
void user_is_in_group(Info & i);
|
||||
void user_is_in_all_groups(Info & i);
|
||||
void user_can_use_html(Info & i);
|
||||
void user_can_use_bbcode(Info & i);
|
||||
void user_can_use_raw(Info & i);
|
||||
void user_has_correct_time_zone(Info & i);
|
||||
void user_time_zone_name(Info & i);
|
||||
void user_time_zone_id(Info & i);
|
||||
void user_time_zone_offset_hour_min(Info & i);
|
||||
void user_has_correct_locale(Info & i);
|
||||
void user_locale_name(Info & i);
|
||||
void user_locale_id(Info & i);
|
||||
void user_tab(Info & i);
|
||||
void user_tab_index(Info & i);
|
||||
void user_tab_id(Info & i);
|
||||
void user_tab_name(Info & i);
|
||||
void user_tab_is_super_user(Info & i);
|
||||
void user_tab_is_active(Info & i);
|
||||
void user_tab_is_suspended(Info & i);
|
||||
void user_tab_is_blocked(Info & i);
|
||||
void user_tab_is_current(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
template (html templates)
|
||||
*/
|
||||
void template_index(Info & i);
|
||||
void template_tab(Info & i);
|
||||
void template_tab_index(Info & i);
|
||||
void template_tab_isdefault(Info & i);
|
||||
void template_tab_file_name(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
winix
|
||||
*/
|
||||
void winix_account_need_email_verification(Info & i);
|
||||
void winix_cur_time(Info & i);
|
||||
void winix_how_many_sessions(Info & i);
|
||||
void winix_users_logged(Info & i);
|
||||
void winix_function(Info & i);
|
||||
void winix_function_is(Info & i);
|
||||
void winix_function_param_is(Info & i);
|
||||
void winix_function_param_is_not(Info & i);
|
||||
void winix_function_param_value(Info & i);
|
||||
void winix_function_param_value_is(Info & i);
|
||||
void winix_function_param_value_is_not(Info & i);
|
||||
void winix_has_plugin(Info & i);
|
||||
void winix_loadavg_now(Info & i);
|
||||
void winix_loadavg_1(Info & i);
|
||||
void winix_loadavg_5(Info & i);
|
||||
void winix_loadavg_15(Info & i);
|
||||
void winix_req_per_sec_now(Info & i);
|
||||
void winix_req_per_sec_1(Info & i);
|
||||
void winix_req_per_sec_5(Info & i);
|
||||
void winix_req_per_sec_15(Info & i);
|
||||
void winix_show_content_in_full_window(Info & i);
|
||||
void winix_has_postvar(Info & i);
|
||||
void winix_postvar(Info & i);
|
||||
void winix_postvar_value_is(Info & i);
|
||||
void winix_postvar_value_is_not(Info & i);
|
||||
void winix_subdomain(Info & i);
|
||||
void winix_subdomain_is_empty(Info & i);
|
||||
void winix_subdomain_is_not_empty(Info & i);
|
||||
void winix_subdomain_is(Info & i);
|
||||
void winix_tz_tab(Info & i);
|
||||
void winix_tz_tab_id(Info & i);
|
||||
void winix_tz_tab_name(Info & i);
|
||||
void winix_tz_tab_offset_sec(Info & i);
|
||||
void winix_tz_tab_offset_hour_min(Info & i);
|
||||
void winix_locale_tab(Info & i);
|
||||
void winix_locale_tab_id(Info & i);
|
||||
void winix_locale_tab_name(Info & i);
|
||||
|
||||
|
||||
/*
|
||||
who
|
||||
*/
|
||||
void who_tab(Info & i);
|
||||
void who_tab_lp(Info & i);
|
||||
void who_tab_user(Info & i);
|
||||
void who_tab_time(Info & i);
|
||||
void who_tab_last_time(Info & i);
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Templates
|
||||
{
|
||||
public:
|
||||
|
||||
Templates();
|
||||
|
||||
void SetConfig(Config * pconfig);
|
||||
void SetCur(Cur * pcur);
|
||||
void SetDb(Db * pdb);
|
||||
void SetSystem(System * psystem);
|
||||
void SetFunctions(Functions * pfunctions);
|
||||
void SetSessionManager(SessionManager * psession_manager);
|
||||
|
||||
void Init();
|
||||
void ClearAfterRequest();
|
||||
void ReadTemplates();
|
||||
void ReadNewIndexTemplates();
|
||||
void ReadNewChangeTemplates();
|
||||
|
||||
void SetEzcParameters(bool trim_white, bool skip_new_line, bool use_special_chars);
|
||||
|
||||
void Generate();
|
||||
void GenerateRunRaw();
|
||||
void Generate(Ezc::Pattern & pattern);
|
||||
|
||||
private:
|
||||
|
||||
void ReadTemplatesForFunctions();
|
||||
void ReadIndexTemplates();
|
||||
void ReadChangeTemplates();
|
||||
void ReadLocale();
|
||||
void SetHtmlFilter();
|
||||
void CreateFunctions(); // should be called before reading patterns (patterns will cache ezc functions)
|
||||
Ezc::Pattern * SelectIndexPatternFromItemAndMountPoint();
|
||||
Ezc::Pattern * SelectIndexPattern();
|
||||
|
||||
TemplatesFunctions::EzcGen generator;
|
||||
std::wstring temp;
|
||||
std::wstring fun_file;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
#endif
|
504
winixd/templates/textextstream.cpp
Normal file
504
winixd/templates/textextstream.cpp
Normal file
@@ -0,0 +1,504 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "textextstream.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
TexTextStream::TexTextStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
without escaping
|
||||
*/
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::PutChar(char c)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(c);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::PutChar(wchar_t c)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(c);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::PutText(const char * str)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::PutText(const char * str, size_t len)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::PutText(const std::string * str)
|
||||
{
|
||||
return PutText(str->c_str());
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::PutText(const std::string & str)
|
||||
{
|
||||
return PutText(str.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::PutText(const wchar_t * str)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::PutText(const std::wstring * str)
|
||||
{
|
||||
return PutText(str->c_str());
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::PutText(const std::wstring & str)
|
||||
{
|
||||
return PutText(str.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const RawText<const char*> & raw)
|
||||
{
|
||||
return PutText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const RawText<const wchar_t*> & raw)
|
||||
{
|
||||
return PutText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<const std::string*> raw)
|
||||
{
|
||||
return PutText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<const std::wstring*> raw)
|
||||
{
|
||||
return PutText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<std::string> raw)
|
||||
{
|
||||
return PutText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<std::wstring> raw)
|
||||
{
|
||||
return PutText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<char> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<wchar_t> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<int> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<long> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<unsigned int> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<unsigned long> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<double> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<void*> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::Write(const char * buf, size_t len)
|
||||
{
|
||||
TextStream<std::wstring>::Write(buf, len);
|
||||
return *this;
|
||||
}
|
||||
|
||||
TexTextStream & TexTextStream::Write(const wchar_t * buf, size_t len)
|
||||
{
|
||||
TextStream<std::wstring>::Write(buf, len);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::write(const char * buf, size_t len)
|
||||
{
|
||||
TextStream<std::wstring>::write(buf, len);
|
||||
return *this;
|
||||
}
|
||||
|
||||
TexTextStream & TexTextStream::write(const wchar_t * buf, size_t len)
|
||||
{
|
||||
TextStream<std::wstring>::write(buf, len);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
with escaping
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::ETextPutChar(char c)
|
||||
{
|
||||
return ETextPutChar(static_cast<wchar_t>(c));
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::ETextPutChar(wchar_t c)
|
||||
{
|
||||
if( c == '$' )
|
||||
buffer += L"\\$";
|
||||
else
|
||||
if( c == '#' )
|
||||
buffer += L"\\#";
|
||||
else
|
||||
if( c == '%' )
|
||||
buffer += L"\\%";
|
||||
else
|
||||
if( c == '&' )
|
||||
buffer += L"\\&";
|
||||
else
|
||||
if( c == '\\' )
|
||||
buffer += L"$\\backslash$";
|
||||
else
|
||||
if( c == '{' )
|
||||
buffer += L"$\\{$";
|
||||
else
|
||||
if( c == '}' )
|
||||
buffer += L"$\\}$";
|
||||
else
|
||||
if( c == '^' )
|
||||
buffer += L""; // !! IMPROVE ME add \char with specific code
|
||||
else
|
||||
if( c == '_' )
|
||||
buffer += L"\\_";
|
||||
else
|
||||
if( c == '~' )
|
||||
buffer += L""; // !! IMPROVE ME add \char with specific code
|
||||
else
|
||||
if( c == '-' )
|
||||
buffer += L"{-}";
|
||||
else
|
||||
if( c != 0 )
|
||||
buffer += c;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::EPutText(const char * str)
|
||||
{
|
||||
for( ; *str ; ++str )
|
||||
ETextPutChar(*str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::EPutText(const char * str, size_t len)
|
||||
{
|
||||
for(size_t i=0 ; i<len ; ++i)
|
||||
ETextPutChar(str[i]);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::EPutText(const std::string * str)
|
||||
{
|
||||
return EPutText(str->c_str(), str->size());
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::EPutText(const std::string & str)
|
||||
{
|
||||
return EPutText(str.c_str(), str.size());
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::EPutText(const wchar_t * str)
|
||||
{
|
||||
for( ; *str ; ++str )
|
||||
ETextPutChar(*str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::EPutText(const wchar_t * str, size_t len)
|
||||
{
|
||||
for(size_t i=0 ; i<len ; ++i)
|
||||
ETextPutChar(str[i]);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::EPutText(const std::wstring * str)
|
||||
{
|
||||
return EPutText(str->c_str(), str->size());
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::EPutText(const std::wstring & str)
|
||||
{
|
||||
return EPutText(str.c_str(), str.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const char * str)
|
||||
{
|
||||
return EPutText(str);
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const std::string * str)
|
||||
{
|
||||
return EPutText(str);
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const std::string & str)
|
||||
{
|
||||
return EPutText(str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const wchar_t * str)
|
||||
{
|
||||
return EPutText(str);
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const std::wstring * str)
|
||||
{
|
||||
return EPutText(str);
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const std::wstring & str)
|
||||
{
|
||||
return EPutText(str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(char v)
|
||||
{
|
||||
ETextPutChar(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(wchar_t v)
|
||||
{
|
||||
ETextPutChar(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(int v)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(long v)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(unsigned int v)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(unsigned long v)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(double v)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const void * v)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const PT::Space & space)
|
||||
{
|
||||
tmp_stream.Clear();
|
||||
// !! IMPROVE ME
|
||||
// we can calculate how many memory is needed beforehand
|
||||
space.Serialize(tmp_stream, true, false);
|
||||
operator<<(tmp_stream.Str());
|
||||
tmp_stream.Clear();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const PT::Date & date)
|
||||
{
|
||||
tmp_stream.Clear();
|
||||
// !! IMPROVE ME
|
||||
// we can calculate how many memory is needed beforehand
|
||||
date.Serialize(tmp_stream);
|
||||
operator<<(tmp_stream.Str());
|
||||
tmp_stream.Clear();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
216
winixd/templates/textextstream.h
Normal file
216
winixd/templates/textextstream.h
Normal file
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_templates_textextstream
|
||||
#define headerfile_winix_templates_textextstream
|
||||
|
||||
#include <ctime>
|
||||
#include "core/textstream.h"
|
||||
#include "textstream/textstream.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
/*
|
||||
TexTextStream is used as a buffer for creating a TeX input
|
||||
By default all operators<< escape its string arguments. If you don't want
|
||||
to escape an argument you should use a helper function R() (raw argument)
|
||||
note: you have to define the function yourself, we do not provide it
|
||||
because such a short name would make a mess in namespaces
|
||||
|
||||
sample:
|
||||
create a helper function R as follows:
|
||||
|
||||
template<class RawType>
|
||||
TexTextStream::RawText<RawType> R(const RawType & par)
|
||||
{
|
||||
return TexTextStream::RawText<RawType>(par);
|
||||
}
|
||||
|
||||
now you can use TexTextStream in an easy way:
|
||||
TexTextStream page;
|
||||
std::string key = "some text with $# ^{} tex \\ special characters";
|
||||
page << key << R("\\def\\myfun{...}");
|
||||
|
||||
everything in 'key' is property escaped for using with TeX
|
||||
*/
|
||||
class TexTextStream : public TextStream<std::wstring>
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
TexTextStream();
|
||||
|
||||
|
||||
/*
|
||||
a helper struct to select a proper operator<<
|
||||
(for non-escaping versions of these operators)
|
||||
*/
|
||||
template<class RawType>
|
||||
struct RawText
|
||||
{
|
||||
const RawType & par;
|
||||
|
||||
RawText(const RawText<RawType> & p) : par(p.par) {}
|
||||
RawText(const RawType & p) : par(p) {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
without escaping
|
||||
*/
|
||||
TexTextStream & PutChar(char);
|
||||
TexTextStream & PutChar(wchar_t);
|
||||
|
||||
TexTextStream & PutText(const char *);
|
||||
TexTextStream & PutText(const char *, size_t len);
|
||||
TexTextStream & PutText(const std::string *);
|
||||
TexTextStream & PutText(const std::string &);
|
||||
TexTextStream & PutText(const wchar_t * str);
|
||||
TexTextStream & PutText(const wchar_t * str, size_t len);
|
||||
TexTextStream & PutText(const std::wstring * str);
|
||||
TexTextStream & PutText(const std::wstring & str);
|
||||
|
||||
/*
|
||||
we need this template operator for such calling:
|
||||
HtmlTextStream_object << R("some string");
|
||||
"some string" is actually a table (not a pointer)
|
||||
*/
|
||||
template<size_t str_size>
|
||||
TexTextStream & operator<<(const RawText<char [str_size]> & raw) { return PutText(raw.par); }
|
||||
|
||||
template<size_t str_size>
|
||||
TexTextStream & operator<<(const RawText<wchar_t [str_size]> & raw) { return PutText(raw.par); }
|
||||
|
||||
TexTextStream & operator<<(const RawText<const char*> & raw);
|
||||
TexTextStream & operator<<(const RawText<const wchar_t*> & raw);
|
||||
TexTextStream & operator<<(RawText<const std::string*> raw);
|
||||
TexTextStream & operator<<(RawText<const std::wstring*> raw);
|
||||
TexTextStream & operator<<(RawText<std::string> raw);
|
||||
TexTextStream & operator<<(RawText<std::wstring> raw);
|
||||
|
||||
TexTextStream & operator<<(RawText<char> raw);
|
||||
TexTextStream & operator<<(RawText<wchar_t> raw);
|
||||
TexTextStream & operator<<(RawText<int> raw);
|
||||
TexTextStream & operator<<(RawText<long> raw);
|
||||
TexTextStream & operator<<(RawText<unsigned int> raw);
|
||||
TexTextStream & operator<<(RawText<unsigned long> raw);
|
||||
TexTextStream & operator<<(RawText<double> raw);
|
||||
TexTextStream & operator<<(RawText<void*> raw);
|
||||
|
||||
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
|
||||
TexTextStream & operator<<(RawText<PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> > raw);
|
||||
|
||||
|
||||
// 'write' don't escapes too
|
||||
// with these methods you can write a zero character too
|
||||
TexTextStream & Write(const char * buf, size_t len);
|
||||
TexTextStream & Write(const wchar_t * buf, size_t len);
|
||||
// for compatibility with standard library (Ezc uses it)
|
||||
TexTextStream & write(const char * buf, size_t len);
|
||||
TexTextStream & write(const wchar_t * buf, size_t len);
|
||||
|
||||
|
||||
/*
|
||||
with escaping
|
||||
*/
|
||||
|
||||
TexTextStream & ETextPutChar(char c);
|
||||
TexTextStream & ETextPutChar(wchar_t c);
|
||||
|
||||
TexTextStream & EPutText(const char * str);
|
||||
TexTextStream & EPutText(const char * str, size_t len);
|
||||
TexTextStream & EPutText(const std::string * str);
|
||||
TexTextStream & EPutText(const std::string & str);
|
||||
TexTextStream & EPutText(const wchar_t * str);
|
||||
TexTextStream & EPutText(const wchar_t * str, size_t len);
|
||||
TexTextStream & EPutText(const std::wstring * str);
|
||||
TexTextStream & EPutText(const std::wstring & str);
|
||||
|
||||
|
||||
TexTextStream & operator<<(const char * str);
|
||||
TexTextStream & operator<<(const std::string * str);
|
||||
TexTextStream & operator<<(const std::string & str);
|
||||
TexTextStream & operator<<(const wchar_t * str);
|
||||
TexTextStream & operator<<(const std::wstring * str);
|
||||
TexTextStream & operator<<(const std::wstring & str);
|
||||
TexTextStream & operator<<(char);
|
||||
TexTextStream & operator<<(wchar_t);
|
||||
TexTextStream & operator<<(int);
|
||||
TexTextStream & operator<<(long);
|
||||
TexTextStream & operator<<(unsigned int);
|
||||
TexTextStream & operator<<(unsigned long);
|
||||
TexTextStream & operator<<(double);
|
||||
TexTextStream & operator<<(const void *);
|
||||
TexTextStream & operator<<(const PT::Space & space);
|
||||
TexTextStream & operator<<(const PT::Date & Date);
|
||||
|
||||
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
|
||||
TexTextStream & operator<<(const PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> & arg);
|
||||
|
||||
private:
|
||||
|
||||
TextStream<std::wstring> tmp_stream;
|
||||
|
||||
};
|
||||
|
||||
|
||||
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
|
||||
TexTextStream & TexTextStream::operator<<(RawText<PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> > raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
|
||||
TexTextStream & TexTextStream::operator<<(const PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> & arg)
|
||||
{
|
||||
typename PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size>::const_iterator i;
|
||||
|
||||
for(i=arg.begin() ; i != arg.end() ; ++i)
|
||||
ETextPutChar(*i);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
#endif
|
||||
|
68
winixd/templates/upload.cpp
Normal file
68
winixd/templates/upload.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <ctime>
|
||||
#include "core/request.h"
|
||||
#include "templates.h"
|
||||
#include "misc.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
static size_t upload_ckeditor_reqid = 0;
|
||||
static int upload_fun_num = 0;
|
||||
|
||||
|
||||
|
||||
void upload_ckeditor_funnum(Info & i)
|
||||
{
|
||||
if( upload_ckeditor_reqid != cur->request->id )
|
||||
{
|
||||
upload_ckeditor_reqid = cur->request->id;
|
||||
upload_fun_num = Toi(cur->request->ParamValue(L"CKEditorFuncNum"));
|
||||
}
|
||||
|
||||
i.out << upload_fun_num;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace Winix
|
||||
|
88
winixd/templates/uptime.cpp
Normal file
88
winixd/templates/uptime.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <ctime>
|
||||
#include "templates.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
|
||||
void uptime_more_than_one_day(Info & i)
|
||||
{
|
||||
time_t up = time(0) - system->system_start;
|
||||
time_t days = up / 60 / 60 / 24;
|
||||
|
||||
i.res = ( days > 1 );
|
||||
}
|
||||
|
||||
|
||||
void uptime_days(Info & i)
|
||||
{
|
||||
time_t up = time(0) - system->system_start;
|
||||
time_t days = up / 60 / 60 / 24;
|
||||
|
||||
i.out << days;
|
||||
}
|
||||
|
||||
|
||||
void uptime_hours(Info & i)
|
||||
{
|
||||
char buf[50];
|
||||
|
||||
time_t sec = time(0) - system->system_start;
|
||||
time_t min = sec / 60;
|
||||
time_t hour = min / 60;
|
||||
|
||||
if( hour == 0 && min == 0 )
|
||||
sprintf(buf, "%d:%02d:%02d", (int)hour, (int)(min%60), (int)(sec%60));
|
||||
else
|
||||
sprintf(buf, "%d:%02d", (int)hour, (int)(min%60));
|
||||
|
||||
i.out << buf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace Winix
|
||||
|
305
winixd/templates/user.cpp
Normal file
305
winixd/templates/user.cpp
Normal file
@@ -0,0 +1,305 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
#include "core/request.h"
|
||||
#include "core/misc.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
|
||||
void user_logged(Info & i)
|
||||
{
|
||||
i.res = cur->session->puser != 0;
|
||||
}
|
||||
|
||||
|
||||
void user_id(Info & i)
|
||||
{
|
||||
if( cur->session->puser )
|
||||
i.out << cur->session->puser->id;
|
||||
}
|
||||
|
||||
void user_name(Info & i)
|
||||
{
|
||||
if( cur->session->puser )
|
||||
i.out << cur->session->puser->name;
|
||||
}
|
||||
|
||||
|
||||
// should be at least in one group
|
||||
// !! moze lepsza nazwa?
|
||||
void user_is_in_group(Info & i)
|
||||
{
|
||||
if( !cur->session->puser || i.params.empty() )
|
||||
return;
|
||||
|
||||
for(size_t a=0 ; a<i.params.size() ; ++a)
|
||||
{
|
||||
long gid = system->groups.GetGroupId(i.params[a].str);
|
||||
|
||||
if( gid!=-1 && cur->session->puser->IsMemberOf(gid) )
|
||||
{
|
||||
i.res = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// !! IMPROVE ME moze lepsza nazwa?
|
||||
void user_is_in_all_groups(Info & i)
|
||||
{
|
||||
if( !cur->session->puser || i.params.empty() )
|
||||
return;
|
||||
|
||||
for(size_t a=0 ; a<i.params.size() ; ++a)
|
||||
{
|
||||
long gid = system->groups.GetGroupId(i.params[a].str);
|
||||
|
||||
if( gid==-1 || !cur->session->puser->IsMemberOf(gid) )
|
||||
return;
|
||||
}
|
||||
|
||||
i.res = true;
|
||||
}
|
||||
|
||||
|
||||
void user_super_user(Info & i)
|
||||
{
|
||||
if( cur->session->puser && cur->session->puser->super_user )
|
||||
i.res = true;
|
||||
}
|
||||
|
||||
|
||||
void user_can_use_html(Info & i)
|
||||
{
|
||||
if( !cur->session->puser )
|
||||
i.res = false;
|
||||
else
|
||||
i.res = system->CanUseHtml(cur->session->puser->id);
|
||||
}
|
||||
|
||||
|
||||
void user_can_use_bbcode(Info & i)
|
||||
{
|
||||
if( !cur->session->puser )
|
||||
i.res = false;
|
||||
else
|
||||
i.res = system->CanUseBBCode(cur->session->puser->id);
|
||||
}
|
||||
|
||||
|
||||
void user_can_use_raw(Info & i)
|
||||
{
|
||||
if( !cur->session->puser )
|
||||
i.res = false;
|
||||
else
|
||||
i.res = system->CanUseRaw(cur->session->puser->id);
|
||||
}
|
||||
|
||||
|
||||
void user_has_correct_time_zone(Info & i)
|
||||
{
|
||||
if( cur->session->puser )
|
||||
i.res = system->time_zones.HasZone(cur->session->puser->time_zone_id);
|
||||
}
|
||||
|
||||
|
||||
void user_time_zone_name(Info & i)
|
||||
{
|
||||
if( cur->session->puser )
|
||||
{
|
||||
TimeZone * tz = system->time_zones.GetZone(cur->session->puser->time_zone_id);
|
||||
|
||||
if( tz )
|
||||
i.out << locale.Get(tz->name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void user_time_zone_id(Info & i)
|
||||
{
|
||||
if( cur->session->puser )
|
||||
i.out << cur->session->puser->time_zone_id;
|
||||
}
|
||||
|
||||
|
||||
void user_time_zone_offset_hour_min(Info & i)
|
||||
{
|
||||
if( cur->session->puser )
|
||||
{
|
||||
TimeZone * tz = system->time_zones.GetZoneByIndex(cur->session->puser->time_zone_id);
|
||||
|
||||
if( tz )
|
||||
{
|
||||
time_t offset = tz->offset;
|
||||
|
||||
if( offset < 0 )
|
||||
{
|
||||
i.out << '-';
|
||||
offset = -offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
i.out << '+';
|
||||
}
|
||||
|
||||
print_hour_min(i, offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void user_has_correct_locale(Info & i)
|
||||
{
|
||||
if( cur->session->puser )
|
||||
i.res = locale.HasLanguage(cur->session->puser->locale_id);
|
||||
}
|
||||
|
||||
|
||||
void user_locale_name(Info & i)
|
||||
{
|
||||
if( cur->session->puser )
|
||||
i.out << locale.Get(L"locale_name");
|
||||
}
|
||||
|
||||
|
||||
void user_locale_id(Info & i)
|
||||
{
|
||||
if( cur->session->puser )
|
||||
i.out << cur->session->puser->locale_id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static Users::Iterator user_iter;
|
||||
static size_t user_reqid = 0;
|
||||
static size_t user_index; // only information
|
||||
|
||||
|
||||
bool user_tab_init()
|
||||
{
|
||||
if( user_reqid != cur->request->id )
|
||||
{
|
||||
user_reqid = cur->request->id;
|
||||
user_iter = system->users.Begin();
|
||||
}
|
||||
|
||||
return user_iter != system->users.End();
|
||||
}
|
||||
|
||||
|
||||
void user_tab(Info & i)
|
||||
{
|
||||
user_tab_init();
|
||||
user_index = i.iter;
|
||||
|
||||
if( i.iter == 0 )
|
||||
user_iter = system->users.Begin();
|
||||
else
|
||||
if( user_iter != system->users.End() )
|
||||
++user_iter;
|
||||
|
||||
i.res = user_iter != system->users.End();
|
||||
}
|
||||
|
||||
|
||||
void user_tab_index(Info & i)
|
||||
{
|
||||
i.out << (user_index+1);
|
||||
}
|
||||
|
||||
void user_tab_id(Info & i)
|
||||
{
|
||||
if( user_tab_init() )
|
||||
i.out << user_iter->id;
|
||||
}
|
||||
|
||||
|
||||
void user_tab_name(Info & i)
|
||||
{
|
||||
if( user_tab_init() )
|
||||
i.out << user_iter->name;
|
||||
}
|
||||
|
||||
|
||||
void user_tab_is_super_user(Info & i)
|
||||
{
|
||||
if( user_tab_init() )
|
||||
i.res = user_iter->super_user;
|
||||
}
|
||||
|
||||
|
||||
void user_tab_is_active(Info & i)
|
||||
{
|
||||
if( user_tab_init() )
|
||||
i.res = user_iter->status == WINIX_ACCOUNT_READY;
|
||||
}
|
||||
|
||||
void user_tab_is_suspended(Info & i)
|
||||
{
|
||||
if( user_tab_init() )
|
||||
i.res = user_iter->status == WINIX_ACCOUNT_SUSPENDED;
|
||||
}
|
||||
|
||||
void user_tab_is_blocked(Info & i)
|
||||
{
|
||||
if( user_tab_init() )
|
||||
i.res = user_iter->status == WINIX_ACCOUNT_BLOCKED;
|
||||
}
|
||||
|
||||
void user_tab_is_current(Info & i)
|
||||
{
|
||||
if( user_tab_init() && cur->session->puser )
|
||||
i.res = (user_iter->id == cur->session->puser->id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
|
136
winixd/templates/who.cpp
Normal file
136
winixd/templates/who.cpp
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "templates.h"
|
||||
#include "core/request.h"
|
||||
#include "core/misc.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
static size_t who_reqid = 0;
|
||||
|
||||
SessionContainer::Iterator who_iterator;
|
||||
size_t who_lp;
|
||||
|
||||
|
||||
bool who_init()
|
||||
{
|
||||
if( who_reqid != cur->request->id )
|
||||
{
|
||||
who_reqid = cur->request->id;
|
||||
who_iterator = session_manager->SessionBegin();
|
||||
who_lp = 1;
|
||||
}
|
||||
|
||||
return who_iterator != session_manager->SessionEnd();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void who_tab(Info & i)
|
||||
{
|
||||
who_init();
|
||||
|
||||
if( i.iter != 0 && who_iterator != session_manager->SessionEnd() )
|
||||
{
|
||||
++who_iterator;
|
||||
++who_lp;
|
||||
}
|
||||
|
||||
i.res = who_iterator != session_manager->SessionEnd();
|
||||
}
|
||||
|
||||
|
||||
void who_tab_lp(Info & i)
|
||||
{
|
||||
if( !who_init() )
|
||||
return;
|
||||
|
||||
i.out << who_lp;
|
||||
}
|
||||
|
||||
|
||||
void who_tab_user(Info & i)
|
||||
{
|
||||
if( !who_init() )
|
||||
return;
|
||||
|
||||
|
||||
if( who_iterator->puser )
|
||||
i.out << who_iterator->puser->name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void who_tab_time(Info & i)
|
||||
{
|
||||
if( !who_init() )
|
||||
return;
|
||||
|
||||
i.out << DateToStr( 0,
|
||||
who_iterator->start_date.month,
|
||||
who_iterator->start_date.day,
|
||||
who_iterator->start_date.hour,
|
||||
who_iterator->start_date.min,
|
||||
who_iterator->start_date.sec );
|
||||
}
|
||||
|
||||
|
||||
void who_tab_last_time(Info & i)
|
||||
{
|
||||
if( !who_init() )
|
||||
return;
|
||||
|
||||
i.out << DateToStr( 0,
|
||||
who_iterator->last_date.month,
|
||||
who_iterator->last_date.day,
|
||||
who_iterator->last_date.hour,
|
||||
who_iterator->last_date.min,
|
||||
who_iterator->last_date.sec );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
|
385
winixd/templates/winix.cpp
Normal file
385
winixd/templates/winix.cpp
Normal file
@@ -0,0 +1,385 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <ctime>
|
||||
#include "templates.h"
|
||||
#include "core/request.h"
|
||||
#include "core/plugin.h"
|
||||
#include "core/misc.h"
|
||||
#include "functions/functions.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
void winix_account_need_email_verification(Info & i)
|
||||
{
|
||||
i.res = config->account_need_email_verification;
|
||||
}
|
||||
|
||||
|
||||
void winix_cur_time(Info & i)
|
||||
{
|
||||
static char buffer[100];
|
||||
|
||||
PT::Date & date = cur->request->start_date;
|
||||
|
||||
sprintf(buffer, "%02d:%02d:%02d", date.hour, date.min, date.sec);
|
||||
i.out << buffer;
|
||||
}
|
||||
|
||||
|
||||
void winix_how_many_sessions(Info & i)
|
||||
{
|
||||
i.out << session_manager->Size();
|
||||
}
|
||||
|
||||
|
||||
void winix_users_logged(Info & i)
|
||||
{
|
||||
i.out << system->users.HowManyLogged();
|
||||
}
|
||||
|
||||
|
||||
void winix_function(Info & i)
|
||||
{
|
||||
i.out << cur->request->function->fun.url;
|
||||
}
|
||||
|
||||
|
||||
void winix_function_is(Info & i)
|
||||
{
|
||||
if( !cur->request->function )
|
||||
return;
|
||||
|
||||
i.res = (cur->request->function->fun.url == i.par);
|
||||
}
|
||||
|
||||
|
||||
void winix_function_param_is(Info & i)
|
||||
{
|
||||
i.res = cur->request->IsParam(i.par);
|
||||
}
|
||||
|
||||
|
||||
void winix_function_param_is_not(Info & i)
|
||||
{
|
||||
i.res = !cur->request->IsParam(i.par);
|
||||
}
|
||||
|
||||
|
||||
void winix_function_param_value(Info & i)
|
||||
{
|
||||
i.out << cur->request->ParamValue(i.par);
|
||||
}
|
||||
|
||||
|
||||
// first parameter is param_name
|
||||
// second parameter is param_value
|
||||
void winix_function_param_value_is(Info & i)
|
||||
{
|
||||
if( i.params.size() == 2 )
|
||||
i.res = (cur->request->ParamValue(i.params[0].str) == i.params[1].str);
|
||||
}
|
||||
|
||||
|
||||
void winix_function_param_value_is_not(Info & i)
|
||||
{
|
||||
if( i.params.size() == 2 )
|
||||
i.res = (cur->request->ParamValue(i.params[0].str) != i.params[1].str);
|
||||
}
|
||||
|
||||
|
||||
void winix_has_plugin(Info & i)
|
||||
{
|
||||
size_t exist = 0;
|
||||
|
||||
if( i.params.empty() )
|
||||
return;
|
||||
|
||||
for(size_t a=0 ; a<i.params.size() ; ++a)
|
||||
{
|
||||
if( plugin.HasPlugin(i.params[a].str) )
|
||||
++exist;
|
||||
}
|
||||
|
||||
i.res = (exist == i.params.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void winix_loadavg_now(Info & i)
|
||||
{
|
||||
char buf[20];
|
||||
|
||||
sprintf(buf, "%.2f", (double)system->load_avg.LoadAvgNow());
|
||||
i.out << buf;
|
||||
}
|
||||
|
||||
|
||||
void winix_loadavg_1(Info & i)
|
||||
{
|
||||
char buf[20];
|
||||
|
||||
sprintf(buf, "%.2f", (double)system->load_avg.LoadAvg1());
|
||||
i.out << buf;
|
||||
}
|
||||
|
||||
|
||||
void winix_loadavg_5(Info & i)
|
||||
{
|
||||
char buf[20];
|
||||
|
||||
sprintf(buf, "%.2f", (double)system->load_avg.LoadAvg5());
|
||||
i.out << buf;
|
||||
}
|
||||
|
||||
|
||||
void winix_loadavg_15(Info & i)
|
||||
{
|
||||
char buf[20];
|
||||
|
||||
sprintf(buf, "%.2f", (double)system->load_avg.LoadAvg15());
|
||||
i.out << buf;
|
||||
}
|
||||
|
||||
|
||||
void winix_req_per_sec_now(Info & i)
|
||||
{
|
||||
char buf[20];
|
||||
|
||||
sprintf(buf, "%.2f", (double)system->load_avg.ReqPerSecNow());
|
||||
i.out << buf;
|
||||
}
|
||||
|
||||
|
||||
void winix_req_per_sec_1(Info & i)
|
||||
{
|
||||
char buf[20];
|
||||
|
||||
sprintf(buf, "%.2f", (double)system->load_avg.ReqPerSec1());
|
||||
i.out << buf;
|
||||
}
|
||||
|
||||
|
||||
void winix_req_per_sec_5(Info & i)
|
||||
{
|
||||
char buf[20];
|
||||
|
||||
sprintf(buf, "%.2f", (double)system->load_avg.ReqPerSec5());
|
||||
i.out << buf;
|
||||
}
|
||||
|
||||
|
||||
void winix_req_per_sec_15(Info & i)
|
||||
{
|
||||
char buf[20];
|
||||
|
||||
sprintf(buf, "%.2f", (double)system->load_avg.ReqPerSec15());
|
||||
i.out << buf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void winix_show_content_in_full_window(Info & i)
|
||||
{
|
||||
if( cur->request->function )
|
||||
i.res = (cur->request->function == &functions->fun_ckeditor ||
|
||||
cur->request->function == &functions->fun_tinymce ||
|
||||
cur->request->function == &functions->fun_nicedit ||
|
||||
cur->request->function == &functions->fun_vim ||
|
||||
cur->request->function == &functions->fun_emacs ||
|
||||
cur->request->function == &functions->fun_upload );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void winix_has_postvar(Info & i)
|
||||
{
|
||||
i.res = cur->request->IsPostVar(i.par);
|
||||
}
|
||||
|
||||
|
||||
void winix_postvar(Info & i)
|
||||
{
|
||||
i.out << cur->request->PostVar(i.par);
|
||||
}
|
||||
|
||||
|
||||
// first parameter is param_name
|
||||
// second parameter is param_value
|
||||
void winix_postvar_value_is(Info & i)
|
||||
{
|
||||
if( i.params.size() == 2 )
|
||||
i.res = (cur->request->PostVar(i.params[0].str) == i.params[1].str);
|
||||
}
|
||||
|
||||
|
||||
void winix_postvar_value_is_not(Info & i)
|
||||
{
|
||||
if( i.params.size() == 2 )
|
||||
i.res = (cur->request->PostVar(i.params[0].str) != i.params[1].str);
|
||||
}
|
||||
|
||||
|
||||
void winix_subdomain(Info & i)
|
||||
{
|
||||
i.out << cur->request->subdomain;
|
||||
}
|
||||
|
||||
|
||||
void winix_subdomain_is_empty(Info & i)
|
||||
{
|
||||
i.res = cur->request->subdomain.empty();
|
||||
}
|
||||
|
||||
|
||||
void winix_subdomain_is_not_empty(Info & i)
|
||||
{
|
||||
i.res = !cur->request->subdomain.empty();
|
||||
}
|
||||
|
||||
void winix_subdomain_is(Info & i)
|
||||
{
|
||||
i.res = cur->request->subdomain == i.par;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static size_t tz_index;
|
||||
|
||||
void winix_tz_tab(Info & i)
|
||||
{
|
||||
tz_index = i.iter;
|
||||
|
||||
i.res = tz_index < system->time_zones.Size();
|
||||
}
|
||||
|
||||
|
||||
void winix_tz_tab_id(Info & i)
|
||||
{
|
||||
TimeZone * tz = system->time_zones.GetZoneByIndex(tz_index);
|
||||
|
||||
if( tz )
|
||||
i.out << tz->id;
|
||||
}
|
||||
|
||||
|
||||
void winix_tz_tab_name(Info & i)
|
||||
{
|
||||
TimeZone * tz = system->time_zones.GetZoneByIndex(tz_index);
|
||||
|
||||
if( tz )
|
||||
i.out << locale.Get(tz->name);
|
||||
}
|
||||
|
||||
|
||||
void winix_tz_tab_offset_sec(Info & i)
|
||||
{
|
||||
TimeZone * tz = system->time_zones.GetZoneByIndex(tz_index);
|
||||
|
||||
if( tz )
|
||||
i.out << tz->offset;
|
||||
}
|
||||
|
||||
|
||||
void winix_tz_tab_offset_hour_min(Info & i)
|
||||
{
|
||||
TimeZone * tz = system->time_zones.GetZoneByIndex(tz_index);
|
||||
|
||||
if( tz )
|
||||
{
|
||||
time_t offset = tz->offset;
|
||||
|
||||
if( offset < 0 )
|
||||
{
|
||||
i.out << '-';
|
||||
offset = -offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
i.out << '+';
|
||||
}
|
||||
|
||||
print_hour_min(i, offset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static size_t locale_id;
|
||||
|
||||
void winix_locale_tab(Info & i)
|
||||
{
|
||||
locale_id = i.iter;
|
||||
i.res = locale_id < locale.Size();
|
||||
}
|
||||
|
||||
|
||||
void winix_locale_tab_id(Info & i)
|
||||
{
|
||||
if( locale_id < locale.Size() )
|
||||
i.out << Toi(locale.GetByIndex(L"winix_locale_id", locale_id, false));
|
||||
}
|
||||
|
||||
|
||||
void winix_locale_tab_name(Info & i)
|
||||
{
|
||||
if( locale_id < locale.Size() )
|
||||
i.out << locale.GetByIndex(L"locale_name", locale_id, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace Winix
|
||||
|
Reference in New Issue
Block a user