Item class has been moved to a new directory 'models', a new class has been added: ItemContent
and same fields from Item were moved to ItemContent Item - id - parent_id - type (file, dir, symlink) - url - subject - template (html template) - sort_index - content_id ItemContent - id - ref -> references (renamed) - user_id - modification_user_id - group_id - privileges - date_creation - date_modification - guest_name - link_to - link_redirect - file_path - file_fs - file_type - file_size - has_thumb -> file_has_thumb (renamed) - hash -> file_hash (renamed) - hash_type -> file_hash_type (renamed) - content -> content_raw (renamed) - content_type -> content_raw_type (renamed) - content_parsed - content_parsed_type - meta - ameta -> meta_admin (renamed) - modify_index (removed) WIP: #4
This commit is contained in:
244
winixd/models/itemcontent.h
Normal file
244
winixd/models/itemcontent.h
Normal file
@@ -0,0 +1,244 @@
|
||||
/*
|
||||
* 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_itemcontent
|
||||
#define headerfile_winix_models_itemcontent
|
||||
|
||||
#include <string>
|
||||
#include "space/space.h"
|
||||
#include "date/date.h"
|
||||
#include "model.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
#define WINIX_ITEM_FILETYPE_NONE 0
|
||||
#define WINIX_ITEM_FILETYPE_IMAGE 1
|
||||
#define WINIX_ITEM_FILETYPE_DOCUMENT 2
|
||||
#define WINIX_ITEM_FILETYPE_VIDEO 3
|
||||
#define WINIX_ITEM_FILETYPE_UNKNOWN 10
|
||||
|
||||
|
||||
|
||||
|
||||
class ItemContent : public morm::Model
|
||||
{
|
||||
public:
|
||||
|
||||
/*
|
||||
* may we should add ct_none? and this will be default (set in Clear method)
|
||||
*/
|
||||
enum ContentType
|
||||
{
|
||||
ct_text = 0,
|
||||
ct_formatted_text,
|
||||
ct_html,
|
||||
ct_bbcode,
|
||||
ct_other, // no auto-formatting is applied
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* record id
|
||||
*/
|
||||
long id;
|
||||
|
||||
/*
|
||||
* how many Items references to this
|
||||
*/
|
||||
int references;
|
||||
|
||||
/*
|
||||
* user owner
|
||||
* -1 means the item was created by a not logged in user and in such a case a 'guest_name' field is set
|
||||
*/
|
||||
long user_id;
|
||||
|
||||
/*
|
||||
* group owner
|
||||
*/
|
||||
long group_id;
|
||||
|
||||
/*
|
||||
* a guest name in a case when the item was created by a not logged in user (user_id is -1)
|
||||
*/
|
||||
std::wstring guest_name;
|
||||
|
||||
/*
|
||||
* who has modified the item last
|
||||
* this field is not taken into account when checking permissions
|
||||
*/
|
||||
long modification_user_id;
|
||||
|
||||
/*
|
||||
* privileges, e.g: 0755
|
||||
* IMPROVEME need some info here
|
||||
*/
|
||||
int privileges;
|
||||
|
||||
/*
|
||||
* when the object was created
|
||||
*/
|
||||
PT::Date date_creation;
|
||||
|
||||
/*
|
||||
* when the object was last modified
|
||||
*/
|
||||
PT::Date date_modification;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* name of a link in the case when type is a symlink or a directory
|
||||
*/
|
||||
std::wstring link_to;
|
||||
|
||||
/*
|
||||
* whether or not winix should make a redirect to link_to link
|
||||
* IMPROVE ME should it be 'bool'?
|
||||
*/
|
||||
int link_redirect;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* static file (if exists)
|
||||
* relative file path
|
||||
*/
|
||||
std::wstring file_path;
|
||||
|
||||
/*
|
||||
* file system type where the file was saved
|
||||
*/
|
||||
int file_fs;
|
||||
|
||||
/*
|
||||
* file type (none, image, doc, etc)
|
||||
*/
|
||||
int file_type;
|
||||
|
||||
/*
|
||||
* whether or not we have a thumbnail
|
||||
*/
|
||||
bool file_has_thumb;
|
||||
|
||||
/*
|
||||
* file hash (md4, md5, ...)
|
||||
*/
|
||||
std::wstring file_hash;
|
||||
|
||||
/*
|
||||
* hash type WINIX_CRYPT_HASH_* (see crypt.h)
|
||||
*/
|
||||
int file_hash_type;
|
||||
|
||||
/*
|
||||
* size of the file
|
||||
*/
|
||||
size_t file_size;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* object content as provided by the user
|
||||
*/
|
||||
std::wstring content_raw;
|
||||
|
||||
/*
|
||||
* raw content type
|
||||
*/
|
||||
ContentType content_raw_type;
|
||||
|
||||
/*
|
||||
* parsed object content
|
||||
* IMPROVEME not used in winix yet
|
||||
*/
|
||||
std::wstring content_parsed;
|
||||
|
||||
/*
|
||||
* parsed content type
|
||||
* IMPROVEME not used in winix yet
|
||||
*/
|
||||
ContentType content_parsed_type;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* meta information
|
||||
* additional information in the form af a Space struct
|
||||
*/
|
||||
PT::Space meta;
|
||||
|
||||
/*
|
||||
* admin meta information
|
||||
* additional information available to edit only by an admin
|
||||
*/
|
||||
PT::Space meta_admin;
|
||||
|
||||
|
||||
ItemContent();
|
||||
|
||||
void map_fields();
|
||||
void table_name(PT::TextStream & stream);
|
||||
void after_insert();
|
||||
|
||||
|
||||
void SetDateToNow();
|
||||
void SetDateModifyToNow();
|
||||
|
||||
|
||||
/*
|
||||
* what about clear() from Model?
|
||||
*/
|
||||
void Clear();
|
||||
|
||||
static bool CanContentBeHtmlFiltered(ItemContent::ContentType ct);
|
||||
bool CanContentBeHtmlFiltered();
|
||||
|
||||
|
||||
|
||||
// IMPROVEME move me to morm
|
||||
using morm::Model::field;
|
||||
void field(const wchar_t * db_field_name, PT::Space & space);
|
||||
};
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user