renamed: WinixModel -> WinixModelDeprecated (this class will be removed)

added: WinixModel (models/winixmodel.h|cpp) - a class inheriting from morm::WinixModel, we have methods such as: get_config(), get_logger(), get_request()
       and this class will be a base class for our models
added: WinixModelConnector (models/winixmodelconnector.h|cpp) - a class inheriting from morm::WinixModelConnector
       this connector we are using instead of morm::ModelConnector - there are pointers to winix objects there (config, request, log)
added to Request: Ezc::Models models
removed from TemplatesFunctions: Ezc::Models ezc_models;
changed: ImgCrop winix functions is using its own item_tab vector now (not finished yet)
added: Item::is(), Item::link(), ItemContent::print_content()
master
Tomasz Sowa 2 years ago
parent 9688b1a26a
commit 6dddc5e948

@ -328,6 +328,9 @@ bool App::Init()
model_connector.set_flat_connector(json_connector);
model_connector.set_db_connector(postgresql_connector);
model_connector.set_logger(log);
model_connector.set_winix_config(&config);
model_connector.set_winix_request(&req);
model_connector.set_winix_logger(&log);
if( !TryToMakeDatabaseMigration() )
return false;

@ -54,18 +54,16 @@
#include "cookieparser.h"
#include "postmultiparser.h"
#include "acceptencodingparser.h"
#include "winixrequest.h"
#include "log/log.h"
#include "filelog.h"
#include "models/winixmodelconnector.h"
namespace Winix
{
class App
{
public:
@ -166,13 +164,13 @@ private:
std::string http_header_8bit;
std::wstring empty_response;
morm::ModelConnector model_connector; // main thread model connector, each thread has its own connector
WinixModelConnector model_connector; // main thread model connector, each thread has its own connector
morm::JSONConnector json_connector;
morm::PostgreSQLConnector postgresql_connector;
// objects for main thread
WinixBase winix_base;
WinixModel winix_model;
WinixModelDeprecated winix_model;
WinixSystem winix_system;
WinixRequest winix_request;
// ///////////////////////
@ -184,10 +182,10 @@ private:
// log_buffer for the main thread
pt::WTextStream log_buffer;
// logger only for App object
// logger only for the main thread
Log log;
// file logger, one object for every Log objects
// file logger, one object for all Log objects
FileLog file_log;
bool InitFCGI(char * sock, char * sock_user, char * sock_group);

@ -37,7 +37,7 @@
#include <pthread.h>
#include "synchro.h"
#include "winixmodel.h"
#include "winixmodeldeprecated.h"
@ -47,7 +47,7 @@ namespace Winix
class BaseThread : public WinixModel
class BaseThread : public WinixModelDeprecated
{
public:

@ -61,9 +61,9 @@ void Dirs::SetNotify(Notify * pnotify)
}
void Dirs::set_dependency(WinixModel * winix_model)
void Dirs::set_dependency(WinixModelDeprecated * winix_model)
{
WinixModel::set_dependency(winix_model);
WinixModelDeprecated::set_dependency(winix_model);
dir_tab.set_dependency(winix_model);
}

@ -42,8 +42,8 @@
#include "dircontainer.h"
#include "db/db.h"
#include "request.h"
#include "winixmodel.h"
#include "models/item.h"
#include "winixmodeldeprecated.h"
@ -57,7 +57,7 @@ class Notify;
// (we will support '..' in the future)
class Dirs : public WinixModel
class Dirs : public WinixModelDeprecated
{
public:
@ -68,7 +68,7 @@ public:
void SetDb(Db * pdb);
void SetNotify(Notify * pnotify);
void set_dependency(WinixModel * winix_model);
void set_dependency(WinixModelDeprecated * winix_model);
// these methods return false if there is no such a dir
bool IsDir(long dir_id);

@ -46,9 +46,9 @@ Groups::Groups()
}
void Groups::set_dependency(WinixModel * winix_model)
void Groups::set_dependency(WinixModelDeprecated * winix_model)
{
WinixModel::set_dependency(winix_model);
WinixModelDeprecated::set_dependency(winix_model);
table.set_dependency(winix_model);
}

@ -40,7 +40,7 @@
#include "models/group.h"
#include "ugcontainer.h"
#include "db/db.h"
#include "winixmodel.h"
#include "winixmodeldeprecated.h"
@ -49,7 +49,7 @@ namespace Winix
class Groups : public WinixModel
class Groups : public WinixModelDeprecated
{
typedef UGContainer<Group> Table;
@ -57,7 +57,7 @@ Table table;
public:
void set_dependency(WinixModel * winix_model);
void set_dependency(WinixModelDeprecated * winix_model);
typedef Table::Iterator Iterator;
typedef Table::SizeType SizeType;

@ -36,7 +36,8 @@
#define headerfile_winix_core_httpsimpleparser
#include <string>
#include "winixmodel.h"
#include "winixmodeldeprecated.h"
namespace Winix
@ -44,7 +45,7 @@ namespace Winix
class HttpSimpleParser : public WinixModel
class HttpSimpleParser : public WinixModelDeprecated
{
protected:

@ -37,7 +37,7 @@
#include <vector>
#include "ipban.h"
#include "winixmodel.h"
#include "winixmodeldeprecated.h"
@ -46,7 +46,7 @@ namespace Winix
class IPBanContainer : public WinixModel
class IPBanContainer : public WinixModelDeprecated
{
public:

@ -42,8 +42,8 @@
#include <limits.h>
#include "mount.h"
#include "dirs.h"
#include "winixmodel.h"
#include "models/item.h"
#include "winixmodeldeprecated.h"
@ -52,7 +52,7 @@ namespace Winix
class MountParser : public WinixModel
class MountParser : public WinixModelDeprecated
{
public:

@ -46,7 +46,7 @@
#include "db/db.h"
#include "request.h"
#include "mountparser.h"
#include "winixmodel.h"
#include "winixmodeldeprecated.h"
namespace Winix
@ -55,7 +55,7 @@ namespace Winix
class Mounts : public WinixModel
class Mounts : public WinixModelDeprecated
{
public:

@ -66,7 +66,7 @@ void PluginInfo::set_dependency_for(WinixBase & winix_base)
set_dependency_for(&winix_base);
}
void PluginInfo::set_dependency_for(WinixModel * winix_model)
void PluginInfo::set_dependency_for(WinixModelDeprecated * winix_model)
{
plugin->SetDependencyFor(winix_model);
@ -74,7 +74,7 @@ void PluginInfo::set_dependency_for(WinixModel * winix_model)
// CHECKME what about model_connector here?
}
void PluginInfo::set_dependency_for(WinixModel & winix_model)
void PluginInfo::set_dependency_for(WinixModelDeprecated & winix_model)
{
set_dependency_for(&winix_model);
}
@ -232,7 +232,7 @@ void Plugin::SetDependencyFor(WinixBase * winix_base)
}
void Plugin::SetDependencyFor(WinixModel * winix_model)
void Plugin::SetDependencyFor(WinixModelDeprecated * winix_model)
{
winix_model->set_dependency(winix_request);
}

@ -54,7 +54,7 @@ class Functions;
class Templates;
class SessionManager;
class WinixModel;
class WinixModelDeprecated;
class WinixRequest;
@ -81,7 +81,7 @@ struct Session;
// move me to a different file
// may it should be based on WinixModel?
// may it should be based on WinixModelDeprecated?
struct PluginInfo
{
// these variables are used for some purposes
@ -134,8 +134,8 @@ struct PluginInfo
void set_dependency_for(WinixBase * winix_base);
void set_dependency_for(WinixBase & winix_base);
void set_dependency_for(WinixModel * winix_model);
void set_dependency_for(WinixModel & winix_model);
void set_dependency_for(WinixModelDeprecated * winix_model);
void set_dependency_for(WinixModelDeprecated & winix_model);
void Clear()
{
@ -291,7 +291,7 @@ private:
bool SetDependency(PluginInfo & info);
void SetDependencyFor(WinixBase * winix_base);
void SetDependencyFor(WinixModel * winix_model);
void SetDependencyFor(WinixModelDeprecated * winix_model);
void Lock();
void Unlock();

@ -143,6 +143,7 @@ void Request::Clear()
return_info_only = false;
info.clear();
return_json = false;
models.Clear();
out_bin_stream.clear();
send_bin_stream = false;

@ -48,6 +48,7 @@
#include "space/space.h"
#include "textstream/textstream.h"
#include "outstreams.h"
#include "models.h"
namespace Winix
@ -309,7 +310,8 @@ struct Request
// additional info added when sending the JSON answer
pt::Space info;
// models to return or to render through ezc library
Ezc::Models models;
// if set to true then the standard template system will not be used

@ -42,7 +42,7 @@
#include "session.h"
#include "cur.h"
#include "config.h"
#include "winixmodel.h"
#include "winixmodeldeprecated.h"
@ -52,7 +52,7 @@ namespace Winix
class SessionContainer : public WinixModel
class SessionContainer : public WinixModelDeprecated
{
public:

@ -89,9 +89,9 @@ void SessionManager::SetLastContainer(LastContainer * plast_container)
}
void SessionManager::set_dependency(WinixModel * winix_model)
void SessionManager::set_dependency(WinixModelDeprecated * winix_model)
{
WinixModel::set_dependency(winix_model);
WinixModelDeprecated::set_dependency(winix_model);
session_tab.set_dependency(winix_model);
session_id_manager.set_dependency(winix_model);
}

@ -65,7 +65,7 @@ public:
void SetSystem(System * psystem);
void SetLastContainer(LastContainer * plast_container);
void set_dependency(WinixModel * winix_model);
void set_dependency(WinixModelDeprecated * winix_model);
// can return a null pointer
Session * FindSession(long id);

@ -81,9 +81,9 @@ void System::SetSessionManager(SessionManager * sm)
}
void System::set_dependency(WinixModel * winix_model)
void System::set_dependency(WinixModelDeprecated * winix_model)
{
WinixModel::set_dependency(winix_model);
WinixModelDeprecated::set_dependency(winix_model);
dirs.set_dependency(this);
mounts.set_dependency(this);

@ -64,7 +64,7 @@ class SessionManager;
// file system
class System : WinixModel
class System : WinixModelDeprecated
{
public:
@ -109,7 +109,7 @@ public:
TimeZones time_zones;
using WinixModel::get_model_connector;
using WinixModelDeprecated::get_model_connector;
void SetCur(Cur * pcur);
//void SetConfig(Config * pconfig);
@ -118,7 +118,7 @@ public:
void SetFunctions(Functions * pfunctions);
void SetSessionManager(SessionManager * sm);
void set_dependency(WinixModel * winix_model);
void set_dependency(WinixModelDeprecated * winix_model);
void Init();

@ -74,12 +74,20 @@ public:
typedef typename StringType::value_type CharType;
typedef typename StringType::value_type char_type;
typedef typename StringType::iterator iterator;
typedef typename StringType::const_iterator const_iterator;
void Clear();
void clear(); // utf8 methods call clear(), in the future Clear() will be renamed to clear()
bool Empty() const;
size_t Size() const;
void Reserve(size_t len);
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
const StringType & Str() const;
const CharType * CStr() const;
@ -149,6 +157,12 @@ void TextStream<StringType>::Clear()
buffer.clear();
}
template<class StringType>
void TextStream<StringType>::clear()
{
Clear();
}
template<class StringType>
bool TextStream<StringType>::Empty() const
{
@ -168,6 +182,33 @@ void TextStream<StringType>::Reserve(size_t len)
}
template<class StringType>
TextStream<StringType>::iterator TextStream<StringType>::begin()
{
return buffer.begin();
}
template<class StringType>
TextStream<StringType>::iterator TextStream<StringType>::end()
{
return buffer.end();
}
template<class StringType>
TextStream<StringType>::const_iterator TextStream<StringType>::begin() const
{
return buffer.begin();
}
template<class StringType>
TextStream<StringType>::const_iterator TextStream<StringType>::end() const
{
return buffer.end();
}
template<class StringType>
const StringType & TextStream<StringType>::Str() const
{

@ -95,6 +95,10 @@ void ThreadManager::Add(BaseThread * pbase, const wchar_t * thread_name)
data.postgresql_connector.wait_for_connection();
data.model_connector.set_db_connector(data.postgresql_connector);
data.model_connector.set_flat_connector(data.json_connector);
data.model_connector.set_winix_config(config);
data.model_connector.set_winix_logger(item.object->get_logger());
data.model_connector.set_logger(item.object->get_logger());
//data.model_connector.set_winix_request();
item.object->set_model_connector(&data.model_connector);

@ -40,15 +40,14 @@
#include "basethread.h"
#include "synchro.h"
#include "textstream/textstream.h"
#include "models/winixmodelconnector.h"
namespace Winix
{
class ThreadManager : public WinixModel
class ThreadManager : public WinixModelDeprecated
{
public:
@ -76,7 +75,7 @@ private:
struct ThreadItemData
{
morm::ModelConnector model_connector;
WinixModelConnector model_connector;
morm::JSONConnector json_connector;
morm::PostgreSQLConnector postgresql_connector;

@ -50,9 +50,9 @@ Users::Users()
}
void Users::set_dependency(WinixModel * winix_model)
void Users::set_dependency(WinixModelDeprecated * winix_model)
{
WinixModel::set_dependency(winix_model);
WinixModelDeprecated::set_dependency(winix_model);
table.set_dependency(winix_model);
last.set_dependency(winix_model);
}

@ -41,7 +41,7 @@
#include "lastcontainer.h"
#include "cur.h"
#include "db/db.h"
#include "winixmodel.h"
#include "winixmodeldeprecated.h"
@ -53,13 +53,13 @@ namespace Winix
class SessionManager;
class Users : public WinixModel
class Users : public WinixModelDeprecated
{
typedef UGContainer<User> Table;
public:
void set_dependency(WinixModel * winix_model);
void set_dependency(WinixModelDeprecated * winix_model);
typedef Table::Iterator Iterator;

@ -32,7 +32,7 @@
*
*/
#include "winixmodel.h"
#include "winixmodeldeprecated.h"
namespace Winix
@ -40,44 +40,44 @@ namespace Winix
WinixModel::WinixModel()
WinixModelDeprecated::WinixModelDeprecated()
{
plugin = nullptr;
model_connector = nullptr;
}
WinixModel::~WinixModel()
WinixModelDeprecated::~WinixModelDeprecated()
{
}
void WinixModel::set_plugin(Plugin * plugin)
void WinixModelDeprecated::set_plugin(Plugin * plugin)
{
this->plugin = plugin;
}
void WinixModel::set_model_connector(morm::ModelConnector * model_connector)
void WinixModelDeprecated::set_model_connector(morm::ModelConnector * model_connector)
{
this->model_connector = model_connector;
}
morm::ModelConnector * WinixModel::get_model_connector()
morm::ModelConnector * WinixModelDeprecated::get_model_connector()
{
return model_connector;
}
void WinixModel::set_dependency(WinixBase * winix_base)
void WinixModelDeprecated::set_dependency(WinixBase * winix_base)
{
WinixBase::set_dependency(winix_base);
}
void WinixModel::set_dependency(WinixModel * winix_model)
void WinixModelDeprecated::set_dependency(WinixModelDeprecated * winix_model)
{
WinixBase::set_dependency(winix_model);
model_connector = winix_model->model_connector;
@ -85,7 +85,7 @@ void WinixModel::set_dependency(WinixModel * winix_model)
}
Plugin * WinixModel::get_plugin()
Plugin * WinixModelDeprecated::get_plugin()
{
return plugin;
}

@ -44,12 +44,12 @@ namespace Winix
{
// may rename it to WinixConnector or WinixStorage?
class WinixModel : public WinixBase
class WinixModelDeprecated : public WinixBase
{
public:
WinixModel();
virtual ~WinixModel();
WinixModelDeprecated();
virtual ~WinixModelDeprecated();
void set_model_connector(morm::ModelConnector * model_connector);
morm::ModelConnector * get_model_connector();
@ -57,7 +57,7 @@ public:
void set_plugin(Plugin * plugin);
void set_dependency(WinixBase * winix_base);
void set_dependency(WinixModel * winix_model);
void set_dependency(WinixModelDeprecated * winix_model);
// temporarily for templates, will be removed

@ -79,9 +79,9 @@ void WinixRequest::set_dependency(WinixBase * winix_base)
}
void WinixRequest::set_dependency(WinixModel * winix_model)
void WinixRequest::set_dependency(WinixModelDeprecated * winix_model)
{
WinixModel::set_dependency(winix_model);
WinixModelDeprecated::set_dependency(winix_model);
}

@ -59,7 +59,7 @@ public:
void set_dependency(WinixBase * winix_base);
void set_dependency(WinixModel * winix_model);
void set_dependency(WinixModelDeprecated * winix_model);
void set_dependency(WinixSystem * winix_system);
void set_dependency(WinixRequest * winix_request);

@ -62,15 +62,15 @@ void WinixSystem::set_dependency(WinixBase * winix_base)
}
void WinixSystem::set_dependency(WinixModel * winix_model)
void WinixSystem::set_dependency(WinixModelDeprecated * winix_model)
{
WinixModel::set_dependency(winix_model);
WinixModelDeprecated::set_dependency(winix_model);
}
void WinixSystem::set_dependency(WinixSystem * winix_system)
{
WinixModel::set_dependency(winix_system);
WinixModelDeprecated::set_dependency(winix_system);
system = winix_system->system;
}

@ -35,8 +35,8 @@
#ifndef headerfile_winix_core_winixsystem
#define headerfile_winix_core_winixsystem
#include "core/winixmodel.h"
#include "core/system.h"
#include "winixmodeldeprecated.h"
@ -44,7 +44,7 @@ namespace Winix
{
class WinixSystem : public WinixModel
class WinixSystem : public WinixModelDeprecated
{
public:
@ -54,7 +54,7 @@ public:
void set_system(System * system);
void set_dependency(WinixBase * winix_base);
void set_dependency(WinixModel * winix_model);
void set_dependency(WinixModelDeprecated * winix_model);
void set_dependency(WinixSystem * winix_system);

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2018, Tomasz Sowa
* Copyright (c) 2008-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -67,23 +67,7 @@ void Cat::MakeGet()
}
cur->request->send_as_attachment = cur->request->IsParam(L"attachment");
// temporary for tests
////////////////////////////////////////////////////////////
foo1.subject = L"subject <h2>from</h2> foo1";
foo2.subject = L"subject <strong>from</strong> foo2";
foo1.item_content.content_raw = L"raw content from foo1";
foo2.item_content.content_raw = L"raw content from foo2";
foo1.set_connector(model_connector);
foo2.set_connector(model_connector);
return_model(L"foo1", foo1);
return_model(L"foo2", foo2);
////////////////////////////////////////////////////////////
cur->request->models.Add(L"item", cur->request->item);
}

@ -54,10 +54,6 @@ public:
void MakeGet();
private:
Item foo1;
Item foo2;
};

@ -149,18 +149,6 @@ void FunctionBase::MakeDelete()
void FunctionBase::return_model(const wchar_t * name, morm::Model & model)
{
TemplatesFunctions::ezc_models.Add(name, model);
}
void FunctionBase::return_model(const wchar_t * name, morm::Model * model)
{
TemplatesFunctions::ezc_models.Add(name, model);
}
} // namespace Winix

@ -102,9 +102,6 @@ public:
//void SetSessionManager(SessionManager * pmanager);
virtual void return_model(const wchar_t * name, morm::Model & model);
virtual void return_model(const wchar_t * name, morm::Model * model);
protected:
//Config * config;

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2018, Tomasz Sowa
* Copyright (c) 2008-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -36,10 +36,11 @@
#define headerfile_winix_functions_functionparser
#include <string>
#include "core/winixmodeldeprecated.h"
#include "db/db.h"
#include "core/cur.h"
#include "core/system.h"
#include "core/winixmodel.h"
namespace Winix
@ -49,7 +50,7 @@ namespace Winix
class Functions;
class FunctionParser : public WinixModel
class FunctionParser : public WinixModelDeprecated
{
public:

@ -72,7 +72,7 @@ void ImgCrop::GetDirContent()
morm::Finder<Item> finder(model_connector);
cur->request->item_tab = finder.
item_tab = finder.
select().
where().
eq(L"type", static_cast<int>(Item::file)).
@ -81,7 +81,7 @@ void ImgCrop::GetDirContent()
get_vector();
//db->GetItems(cur->request->item_tab, iq);
system->CheckWriteAccessToItems(cur->request->item_tab);
system->CheckWriteAccessToItems(item_tab);
}
@ -137,7 +137,10 @@ void ImgCrop::MakePost()
void ImgCrop::MakeGet()
{
if( !cur->request->is_item )
{
GetDirContent();
cur->request->models.Add(L"item_tab", item_tab);
}
}

@ -55,9 +55,11 @@ public:
void MakeGet();
void MakePost();
// IMPROVEME add method Clear() or ClearAfterRequest()? and clear item_tab
private:
//DbItemQuery iq;
std::vector<Item> item_tab;
void GetDirContent();

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2010-2018, Tomasz Sowa
* Copyright (c) 2010-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -35,17 +35,17 @@
#ifndef headerfile_winix_functions_privchanger
#define headerfile_winix_functions_privchanger
#include "core/winixmodeldeprecated.h"
#include "core/request.h"
#include "core/system.h"
#include "db/db.h"
#include "core/winixmodel.h"
namespace Winix
{
class PrivChanger : public WinixModel
class PrivChanger : public WinixModelDeprecated
{
public:

@ -1,4 +1,4 @@
[if item_content_type_is "other"][item_print_content][else]
[if item_content_type_is "other"][item.content.print_content][else]
[if false]
[if mount_page_arg_is "subject"][if mount_page_arg_is "info"]<h1 class="withinfo">[else]<h1>[end][item_subject]</h1>[end]
@ -18,7 +18,7 @@
</pre>
</div>
[item_print_content]
[item.content.print_content]
[else]
@ -30,10 +30,10 @@
</pre>
</div>
[item_print_content]
[item.content.print_content]
[else]
[item_print_content]
[item.content.print_content]
[end]
[end]

@ -79,22 +79,22 @@
<tr>
<td data-uk-lightbox="animation: slide">
<a href="[item_tab_link]">
<img src="[item_tab_link][if item_tab_has_thumb]/-/thumb[end]" alt="[item_tab_subject]">
<a href="[item_tab.link]">
<img src="[item_tab.link][if item_tab.has_thumb]/-/thumb[end]" alt="[item_tab.subject]">
</a>
</td>
<td>
[item_tab_url]
[item_tab.url]
</td>
<td>
<ul class="uk-nav uk-width-medium">
<li class="uk-margin-small"><a class="uk-button uk-button-default uk-button-small uk-text-small" href="[item_tab_link]/imgcrop/postredirect:[filter fil_urlencode][doc_base_url][dir]imgcrop[end]">{imgcrop_table_option_crop_image}</a></li>
<li class="uk-margin-small"><a class="uk-button uk-button-default uk-button-small uk-text-small" href="[item_tab_link]/imgcrop/thumb/postredirect:[filter fil_urlencode][doc_base_url][dir]imgcrop[end]">{imgcrop_table_option_crop_thumb}</a></li>
<li class="uk-margin-small"><a class="uk-button uk-button-default uk-button-small uk-text-small" href="[item_tab_link]/imgcrop/newthumb/postredirect:[filter fil_urlencode][doc_base_url][dir]imgcrop[end]">{imgcrop_table_option_create_new_thumb}</a></li>
<li class="uk-margin-small"><a class="uk-button uk-button-default uk-button-small uk-text-small" href="[item_tab.link]/imgcrop/postredirect:[filter fil_urlencode][doc_base_url][dir]imgcrop[end]">{imgcrop_table_option_crop_image}</a></li>
<li class="uk-margin-small"><a class="uk-button uk-button-default uk-button-small uk-text-small" href="[item_tab.link]/imgcrop/thumb/postredirect:[filter fil_urlencode][doc_base_url][dir]imgcrop[end]">{imgcrop_table_option_crop_thumb}</a></li>
<li class="uk-margin-small"><a class="uk-button uk-button-default uk-button-small uk-text-small" href="[item_tab.link]/imgcrop/newthumb/postredirect:[filter fil_urlencode][doc_base_url][dir]imgcrop[end]">{imgcrop_table_option_create_new_thumb}</a></li>
</ul>
</td>

@ -35,6 +35,8 @@
#include "models/item.h"
#include "core/misc.h"
#include "finder.h"
#include "core/request.h"
#include "templates/templates.h"
namespace Winix
@ -65,7 +67,9 @@ void Item::fields()
field(L"sort_index", sort_index);
field(L"content_id", L"content", item_content, morm::FT::foreign_key);
//field(L"my_test_function", my_test_function);
field(L"is", &Item::is);
field(L"link", &Item::link);
// may we should add a method setTypeFromInt(int t)?
type = static_cast<Type>(type_helper);
@ -232,6 +236,73 @@ void Item::propagate_connector()
}
// IMPROVEME move me to a better place
void Item::print_dir(Ezc::FunInfo<HtmlTextStream> & env)
{
Request * req = get_request();
if( req )
{
for(size_t a=0 ; a < req->dir_tab.size() ; ++a)
env.out << req->dir_tab[a]->url << '/';
}
}
// IMPROVEME move me to a better place
void Item::print_dir_without_slash(Ezc::FunInfo<HtmlTextStream> & env)
{
Request * req = get_request();
if( req )
{
for(size_t a=0 ; a < req->dir_tab.size() ; ++a)
{
env.out << req->dir_tab[a]->url;
if( a < req->dir_tab.size()-1 )
env.out << '/';
}
}
}
void Item::is(Ezc::FunInfo<HtmlTextStream> & env)
{
Request * req = get_request();
if( req )
{
env.res = req->is_item;
}
}
void Item::link(Ezc::FunInfo<HtmlTextStream> & env)
{
Config * config = get_config();
Request * req = get_request();
if( config && req )
{
TemplatesFunctions::doc_proto(env);
if( !req->subdomain.empty() )
env.out << req->subdomain << '.';
env.out << config->base_url;
// FIXME this prints cur->request->dir_tab but we should print the directory in which actually there is the item
print_dir(env);
env.out << url;
}
}
@ -366,5 +437,6 @@ bool Item::do_migration_to_4()
}
} // namespace Winix

@ -36,8 +36,8 @@
#define headerfile_winix_models_item
#include <string>
#include "model.h"
#include "models/itemcontent.h"
#include "winixmodel.h"
#include "itemcontent.h"
// temporary
@ -89,7 +89,7 @@ public:
};
class Item : public morm::Model
class Item : public WinixModel
{
public:
@ -184,11 +184,11 @@ public:
void propagate_connector();
// for tests
static void my_test_function(Ezc::FunInfo<HtmlTextStream> & env)
{
env.out << L"hello from function";
}
void print_dir(Ezc::FunInfo<HtmlTextStream> & env);
void print_dir_without_slash(Ezc::FunInfo<HtmlTextStream> & env);
void is(Ezc::FunInfo<HtmlTextStream> & env);
void link(Ezc::FunInfo<HtmlTextStream> & env);
protected:
@ -200,6 +200,7 @@ protected:
bool do_migration_to_3();
bool do_migration_to_4();
MORM_MEMBER_FIELD(Item)
};

@ -35,7 +35,8 @@
#include "models/itemcontent.h"
#include "core/crypt.h"
#include "core/misc.h"
#include "templates/misc.h"
#include "core/bbcodeparser.h"
namespace Winix
@ -81,6 +82,8 @@ void ItemContent::fields()
field(L"meta", meta);
field(L"meta_admin", meta_admin);
field(L"print_content", &ItemContent::print_content);
content_raw_type = static_cast<ContentType>(content_raw_type_helper);
content_parsed_type = static_cast<ContentType>(content_parsed_type_helper);
}
@ -166,6 +169,51 @@ bool ItemContent::CanContentBeHtmlFiltered()
void ItemContent::print_content(HtmlTextStream & out, const std::wstring & content, ItemContent::ContentType content_type, bool is_html_filter_on)
{
using TemplatesFunctions::R;
if( is_html_filter_on && !ItemContent::CanContentBeHtmlFiltered(content_type) )
out << R("<nofilter>");
if( content_type == ItemContent::ct_text )
{
out << content;
}
else
if( content_type == ItemContent::ct_formatted_text )
{
TemplatesFunctions::HtmlEscapeFormTxt(out, content);
}
else
if( content_type == ItemContent::ct_bbcode )
{
static std::wstring out_temp;
out_temp.clear();
out_temp.reserve(content.size()*2);
BBCODEParser bbcode_parser; // IMPROVE ME move me to a better place
bbcode_parser.Filter(content.c_str(), out_temp);
out << R(out_temp);
}
else
{
// ct_html, ct_other
out << R(content);
}
if( is_html_filter_on && !ItemContent::CanContentBeHtmlFiltered(content_type) )
out << R("</nofilter>");
}
void ItemContent::print_content(Ezc::FunInfo<HtmlTextStream> & env)
{
print_content(env.out, content_raw, content_raw_type, true); // IMPROVE ME get the 'true' from the config (config->html_filter)
}
bool ItemContent::do_migration(int & current_table_version)
{
bool ok = true;

@ -39,6 +39,7 @@
#include "space/space.h"
#include "date/date.h"
#include "model.h"
#include "templates/htmltextstream.h"
namespace Winix
@ -230,6 +231,9 @@ public:
bool CanContentBeHtmlFiltered();
static void print_content(HtmlTextStream & out, const std::wstring & content, ItemContent::ContentType content_type, bool is_html_filter_on);
void print_content(Ezc::FunInfo<HtmlTextStream> & env);
bool do_migration(int & current_table_version);
@ -240,6 +244,8 @@ protected:
bool do_migration_to_2();
bool do_migration_to_3();
MORM_MEMBER_FIELD(ItemContent)