/* * This file is a part of Winix * and is distributed under the 2-Clause BSD licence. * Author: Tomasz Sowa */ /* * 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 #include "space/space.h" #include "date/date.h" #include "model.h" #include "templates/htmltextstream.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 fields(); void table(); void after_insert(); void SetDateToNow(); void SetDateModifyToNow(); /* * what about clear() from Model? */ void Clear(); static bool CanContentBeHtmlFiltered(ItemContent::ContentType ct); 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 & env); bool do_migration(int & current_table_version); protected: bool do_migration_to_1(); bool do_migration_to_2(); bool do_migration_to_3(); MORM_MEMBER_FIELD(ItemContent) }; } // namespace Winix #endif