170 lines
4.4 KiB
C++
170 lines
4.4 KiB
C++
/*
|
|
* 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 "models/itemcontent.h"
|
|
#include "core/crypt.h"
|
|
#include "core/misc.h"
|
|
|
|
|
|
|
|
namespace Winix
|
|
{
|
|
|
|
|
|
|
|
|
|
ItemContent::ItemContent()
|
|
{
|
|
Clear();
|
|
}
|
|
|
|
|
|
|
|
void ItemContent::map_fields()
|
|
{
|
|
int content_raw_type_helper = static_cast<int>(content_raw_type);
|
|
int content_parsed_type_helper = static_cast<int>(content_parsed_type);
|
|
|
|
field(L"id", id, morm::FT::no_insertable | morm::FT::no_updatable | morm::FT::primary_key);
|
|
field(L"references", references);
|
|
field(L"user_id", user_id);
|
|
field(L"group_id", group_id);
|
|
field(L"guest_name", guest_name);
|
|
field(L"modification_user_id", modification_user_id);
|
|
field(L"privileges", privileges);
|
|
field(L"date_creation", date_creation);
|
|
field(L"date_modification", date_modification);
|
|
field(L"link_to", link_to);
|
|
field(L"link_redirect", link_redirect);
|
|
field(L"file_path", file_path);
|
|
field(L"file_fs", file_fs);
|
|
field(L"file_type", file_type);
|
|
field(L"file_has_thumb", file_has_thumb);
|
|
field(L"file_hash", file_hash);
|
|
field(L"file_hash_type", file_hash_type);
|
|
field(L"file_size", file_size);
|
|
field(L"content_raw", content_raw);
|
|
field(L"content_raw_type", content_raw_type_helper);
|
|
field(L"content_parsed", content_parsed);
|
|
field(L"content_parsed_type", content_parsed_type_helper);
|
|
field(L"meta", meta);
|
|
field(L"meta_admin", meta_admin);
|
|
|
|
content_raw_type = static_cast<ContentType>(content_raw_type_helper);
|
|
content_parsed_type = static_cast<ContentType>(content_parsed_type_helper);
|
|
}
|
|
|
|
|
|
void ItemContent::prepare_table()
|
|
{
|
|
table(L"core", L"content");
|
|
}
|
|
|
|
|
|
void ItemContent::after_insert()
|
|
{
|
|
get_last_sequence_for_primary_key(L"core.content_id_seq", id);
|
|
}
|
|
|
|
|
|
// !! IMPROVEME
|
|
// now we have Request::start_time and Request::start_date
|
|
// we can somehow get the current time from the request
|
|
// may setting the date should be completetly removed from here?
|
|
void ItemContent::SetDateToNow()
|
|
{
|
|
date_creation = std::time(0);
|
|
date_modification = date_creation;
|
|
}
|
|
|
|
|
|
void ItemContent::SetDateModifyToNow()
|
|
{
|
|
date_modification = std::time(0);
|
|
}
|
|
|
|
|
|
void ItemContent::Clear()
|
|
{
|
|
id = -1;
|
|
references = 1;
|
|
|
|
user_id = -1;
|
|
group_id = -1;
|
|
guest_name.clear();
|
|
modification_user_id = -1;
|
|
privileges = 0;
|
|
|
|
link_to.clear();
|
|
link_redirect = false;
|
|
|
|
file_path.clear();
|
|
file_fs = -1;
|
|
file_type = WINIX_ITEM_FILETYPE_NONE;
|
|
file_has_thumb = false;
|
|
file_hash.clear();
|
|
file_hash_type = WINIX_CRYPT_HASH_NONE;
|
|
file_size = 0;
|
|
|
|
|
|
content_raw.clear();
|
|
content_raw_type = ct_formatted_text;
|
|
content_parsed.clear();
|
|
content_parsed_type = ct_formatted_text;
|
|
|
|
meta.Clear();
|
|
meta_admin.Clear();
|
|
|
|
SetDateToNow();
|
|
}
|
|
|
|
|
|
/*
|
|
* we're using the HtmlFilter only for those contents
|
|
*
|
|
*/
|
|
bool ItemContent::CanContentBeHtmlFiltered(ItemContent::ContentType ct)
|
|
{
|
|
return ct == ct_text || ct == ct_formatted_text || ct == ct_html || ct == ct_bbcode;
|
|
}
|
|
|
|
bool ItemContent::CanContentBeHtmlFiltered()
|
|
{
|
|
return CanContentBeHtmlFiltered(content_raw_type);
|
|
}
|
|
|
|
|
|
} // namespace Winix
|
|
|