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()
This commit is contained in:
@@ -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)
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
96
winixd/models/winixmodel.cpp
Normal file
96
winixd/models/winixmodel.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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) 2021, 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 "winixmodel.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
Config * WinixModel::get_config()
|
||||
{
|
||||
WinixModelConnector * connector = get_winix_model_connector();
|
||||
|
||||
if( connector )
|
||||
{
|
||||
return connector->get_winix_config();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
Request * WinixModel::get_request()
|
||||
{
|
||||
WinixModelConnector * connector = get_winix_model_connector();
|
||||
|
||||
if( connector )
|
||||
{
|
||||
return connector->get_winix_request();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
Log * WinixModel::get_logger()
|
||||
{
|
||||
WinixModelConnector * connector = get_winix_model_connector();
|
||||
|
||||
if( connector )
|
||||
{
|
||||
return connector->get_winix_logger();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
WinixModelConnector * WinixModel::get_winix_model_connector()
|
||||
{
|
||||
if( model_connector )
|
||||
{
|
||||
return dynamic_cast<WinixModelConnector*>(model_connector);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
68
winixd/models/winixmodel.h
Normal file
68
winixd/models/winixmodel.h
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) 2021, 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_models_winixmodel
|
||||
#define headerfile_winix_models_winixmodel
|
||||
|
||||
#include "model.h"
|
||||
#include "core/log.h"
|
||||
#include "winixmodelconnector.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
class Config;
|
||||
class Request;
|
||||
class Log;
|
||||
|
||||
|
||||
class WinixModel : public morm::Model
|
||||
{
|
||||
public:
|
||||
|
||||
Config * get_config();
|
||||
Request * get_request();
|
||||
Log * get_logger();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
WinixModelConnector * get_winix_model_connector();
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
88
winixd/models/winixmodelconnector.cpp
Normal file
88
winixd/models/winixmodelconnector.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) 2021, 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 "winixmodelconnector.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
WinixModelConnector::WinixModelConnector()
|
||||
{
|
||||
config = nullptr;
|
||||
request = nullptr;
|
||||
log = nullptr;
|
||||
}
|
||||
|
||||
|
||||
Config * WinixModelConnector::get_winix_config()
|
||||
{
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
Request * WinixModelConnector::get_winix_request()
|
||||
{
|
||||
return request;
|
||||
}
|
||||
|
||||
|
||||
Log * WinixModelConnector::get_winix_logger()
|
||||
{
|
||||
return log;
|
||||
}
|
||||
|
||||
|
||||
void WinixModelConnector::set_winix_config(Config * config)
|
||||
{
|
||||
this->config = config;
|
||||
}
|
||||
|
||||
|
||||
void WinixModelConnector::set_winix_request(Request * request)
|
||||
{
|
||||
this->request = request;
|
||||
}
|
||||
|
||||
|
||||
void WinixModelConnector::set_winix_logger(Log * log)
|
||||
{
|
||||
this->log = log;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
72
winixd/models/winixmodelconnector.h
Normal file
72
winixd/models/winixmodelconnector.h
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) 2021, 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_models_winixmodelconnector
|
||||
#define headerfile_winix_models_winixmodelconnector
|
||||
|
||||
#include "modelconnector.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
class Config;
|
||||
class Request;
|
||||
class Log;
|
||||
|
||||
class WinixModelConnector : public morm::ModelConnector
|
||||
{
|
||||
public:
|
||||
|
||||
WinixModelConnector();
|
||||
|
||||
Config * get_winix_config();
|
||||
Request * get_winix_request();
|
||||
Log * get_winix_logger();
|
||||
|
||||
void set_winix_config(Config * config);
|
||||
void set_winix_request(Request * request);
|
||||
void set_winix_logger(Log * log);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
Config * config; // one global config
|
||||
Request * request; // each thread worker has its own request (not implemented yet)
|
||||
Log * log; // each thread has its own logger
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user