2010-10-24 01:12:47 +02:00
/*
* This file is a part of Winix
2014-10-04 20:04:03 +02:00
* and is distributed under the 2 - Clause BSD licence .
* Author : Tomasz Sowa < t . sowa @ ttmath . org >
*/
/*
2022-12-19 19:13:45 +01:00
* Copyright ( c ) 2021 - 2022 , Tomasz Sowa
2010-10-24 01:12:47 +02:00
* All rights reserved .
*
2014-10-04 20:04:03 +02:00
* 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 .
*
2010-10-24 01:12:47 +02:00
*/
2021-02-24 01:19:47 +01:00
# include "models/itemcontent.h"
# include "core/crypt.h"
# include "core/misc.h"
2021-06-16 18:07:44 +02:00
# include "templates/misc.h"
2021-07-17 13:56:37 +02:00
# include "html/bbcodeparser.h"
2021-06-18 19:18:13 +02:00
# include "core/request.h"
# include "core/users.h"
# include "core/groups.h"
2010-10-24 01:12:47 +02:00
2014-02-12 17:30:49 +01:00
namespace Winix
{
2010-10-24 01:12:47 +02:00
2021-02-24 01:19:47 +01:00
ItemContent : : ItemContent ( )
2010-10-24 01:12:47 +02:00
{
Clear ( ) ;
}
2021-02-24 01:19:47 +01:00
2021-05-13 03:29:41 +02:00
void ItemContent : : fields ( )
2021-02-24 01:19:47 +01:00
{
int content_raw_type_helper = static_cast < int > ( content_raw_type ) ;
int content_parsed_type_helper = static_cast < int > ( content_parsed_type ) ;
2021-03-11 18:48:18 +01:00
field ( L " id " , id , morm : : FT : : no_insertable | morm : : FT : : no_updatable | morm : : FT : : primary_key ) ;
2021-02-24 01:19:47 +01:00
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 ) ;
2021-09-22 00:23:25 +02:00
field ( L " file_mime_type " , file_mime_type ) ;
2021-02-24 01:19:47 +01:00
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 ) ;
2021-03-11 18:48:18 +01:00
field ( L " meta " , meta ) ;
2021-07-03 01:18:28 +02:00
field ( L " admin_meta " , admin_meta ) ;
2021-02-24 01:19:47 +01:00
2021-06-16 18:07:44 +02:00
field ( L " print_content " , & ItemContent : : print_content ) ;
2021-06-18 19:18:13 +02:00
field ( L " has_static_file " , & ItemContent : : has_static_file ) ;
field ( L " privileges_octal " , & ItemContent : : privileges_octal ) ;
2021-06-20 21:22:08 +02:00
field ( L " has_user " , & ItemContent : : has_user ) ;
field ( L " has_group " , & ItemContent : : has_group ) ;
2021-07-06 21:52:29 +02:00
field ( L " item_users_different " , & ItemContent : : item_users_different ) ;
2021-06-19 23:48:12 +02:00
field ( L " user " , & ItemContent : : user ) ;
field ( L " group " , & ItemContent : : group ) ;
2021-06-18 19:18:13 +02:00
field ( L " type_is " , & ItemContent : : type_is ) ;
field ( L " is_empty " , & ItemContent : : is_empty ) ;
2021-06-16 18:07:44 +02:00
2021-06-18 19:18:13 +02:00
field ( L " file_type_is_none " , & ItemContent : : file_type_is_none ) ;
field ( L " file_type_is_image " , & ItemContent : : file_type_is_image ) ;
field ( L " file_type_is_video " , & ItemContent : : file_type_is_video ) ;
field ( L " file_type_is_sound " , & ItemContent : : file_type_is_sound ) ;
field ( L " has_thumb " , & ItemContent : : has_thumb ) ;
2021-06-19 23:48:12 +02:00
field ( L " display_user_name " , & ItemContent : : display_user_name ) ;
2021-06-18 19:18:13 +02:00
2021-07-03 01:18:28 +02:00
field ( L " is_meta_object " , & ItemContent : : is_meta_object ) ;
field ( L " is_admin_meta_object " , & ItemContent : : is_admin_meta_object ) ;
2021-06-18 19:18:13 +02:00
2021-07-06 21:52:29 +02:00
field ( L " are_dates_equal " , & ItemContent : : are_dates_equal ) ;
field ( L " can_content_be_html_filtered " , & ItemContent : : CanContentBeHtmlFiltered ) ;
field ( L " is_link_to " , & ItemContent : : is_link_to ) ;
field ( L " is_link_redirect " , & ItemContent : : is_link_redirect ) ;
2021-06-18 19:18:13 +02:00
// IMPROVEME prepare a setter functions which tests whether content_raw_type_helper and content_parsed_type_helper are correct values
2021-02-24 01:19:47 +01:00
content_raw_type = static_cast < ContentType > ( content_raw_type_helper ) ;
content_parsed_type = static_cast < ContentType > ( content_parsed_type_helper ) ;
}
2021-05-13 03:29:41 +02:00
void ItemContent : : table ( )
2021-02-24 01:19:47 +01:00
{
2021-05-13 03:29:41 +02:00
table_name ( L " core " , L " content " ) ;
2021-02-24 01:19:47 +01:00
}
void ItemContent : : after_insert ( )
{
2021-03-09 18:16:29 +01:00
get_last_sequence_for_primary_key ( L " core.content_id_seq " , id ) ;
2021-02-24 01:19:47 +01:00
}
// !! IMPROVEME
2012-05-27 20:11:34 +02:00
// now we have Request::start_time and Request::start_date
2012-02-17 06:19:24 +01:00
// we can somehow get the current time from the request
// may setting the date should be completetly removed from here?
2021-02-24 01:19:47 +01:00
void ItemContent : : SetDateToNow ( )
2010-10-24 01:12:47 +02:00
{
2012-05-27 01:04:49 +02:00
date_creation = std : : time ( 0 ) ;
2010-10-24 01:12:47 +02:00
date_modification = date_creation ;
}
2021-02-24 01:19:47 +01:00
void ItemContent : : SetDateModifyToNow ( )
2010-10-24 01:12:47 +02:00
{
2012-05-27 01:04:49 +02:00
date_modification = std : : time ( 0 ) ;
2010-10-24 01:12:47 +02:00
}
2021-02-24 01:19:47 +01:00
void ItemContent : : Clear ( )
2010-10-24 01:12:47 +02:00
{
id = - 1 ;
2021-02-24 01:19:47 +01:00
references = 1 ;
2010-10-24 01:12:47 +02:00
user_id = - 1 ;
group_id = - 1 ;
guest_name . clear ( ) ;
2021-02-24 01:19:47 +01:00
modification_user_id = - 1 ;
privileges = 0 ;
2011-01-05 22:24:11 +01:00
2021-10-13 01:27:14 +02:00
date_creation . Clear ( ) ;
date_modification . Clear ( ) ;
SetDateToNow ( ) ;
2011-01-05 22:24:11 +01:00
link_to . clear ( ) ;
link_redirect = false ;
2010-10-24 01:12:47 +02:00
2010-12-10 22:07:01 +01:00
file_path . clear ( ) ;
file_fs = - 1 ;
file_type = WINIX_ITEM_FILETYPE_NONE ;
2021-10-13 01:27:14 +02:00
file_mime_type . clear ( ) ;
2021-02-24 01:19:47 +01:00
file_has_thumb = false ;
file_hash . clear ( ) ;
file_hash_type = WINIX_CRYPT_HASH_NONE ;
2011-06-24 22:53:21 +02:00
file_size = 0 ;
2021-02-24 01:19:47 +01:00
content_raw . clear ( ) ;
content_raw_type = ct_formatted_text ;
content_parsed . clear ( ) ;
content_parsed_type = ct_formatted_text ;
2021-04-09 17:50:58 +02:00
meta . clear ( ) ;
2021-07-03 01:18:28 +02:00
admin_meta . clear ( ) ;
2010-10-24 01:12:47 +02:00
}
2010-12-10 22:07:01 +01:00
2021-06-16 18:07:44 +02:00
2021-05-14 03:31:29 +02:00
bool ItemContent : : do_migration ( int & current_table_version )
{
bool ok = true ;
ok = ok & & morm : : Model : : do_migration ( current_table_version , 1 , this , & ItemContent : : do_migration_to_1 ) ;
ok = ok & & morm : : Model : : do_migration ( current_table_version , 2 , this , & ItemContent : : do_migration_to_2 ) ;
ok = ok & & morm : : Model : : do_migration ( current_table_version , 3 , this , & ItemContent : : do_migration_to_3 ) ;
2021-07-03 01:18:28 +02:00
ok = ok & & morm : : Model : : do_migration ( current_table_version , 4 , this , & ItemContent : : do_migration_to_4 ) ;
2021-09-22 00:23:25 +02:00
ok = ok & & morm : : Model : : do_migration ( current_table_version , 5 , this , & ItemContent : : do_migration_to_5 ) ;
2022-12-19 19:13:45 +01:00
ok = ok & & morm : : Model : : do_migration ( current_table_version , 6 , this , & ItemContent : : do_migration_to_6 ) ;
2021-05-14 03:31:29 +02:00
return ok ;
}
bool ItemContent : : do_migration_to_1 ( )
{
const char * str = R " sql(
CREATE TABLE core . content (
id serial ,
content text ,
content_type smallint ,
file_path character varying ( 2048 ) ,
file_fs smallint ,
file_type smallint ,
has_thumb smallint ,
ref integer ,
modify_index smallint ,
hash character varying ( 255 ) ,
hash_type smallint ,
file_size bigint
) ;
) sql " ;
db_query ( str ) ;
return true ; // IMPROVEME remove me in the future: this is only for a moment until we do migration on all our sites
}
bool ItemContent : : do_migration_to_2 ( )
{
const char * str = R " sql(
alter table core . content
add column user_id integer ,
add column group_id integer ,
add column guest_name character varying ( 20 ) ,
add column modification_user_id integer ,
add column privileges integer ,
add column date_creation timestamp without time zone ,
add column date_modification timestamp without time zone ,
add column link_to character varying ( 2048 ) ,
add column link_redirect smallint ,
add column meta text ,
add column meta_admin text ,
add column content_parsed text ,
add column content_parsed_type smallint ;
) sql " ;
return db_query ( str ) ;
}
bool ItemContent : : do_migration_to_3 ( )
{
const char * str [ ] = {
" alter table core.content rename column ref to \" references \" ; " ,
" alter table core.content rename column content to content_raw; " ,
" alter table core.content rename column content_type to content_raw_type; " ,
" alter table core.content rename column has_thumb to file_has_thumb; " ,
" alter table core.content rename column hash to file_hash; " ,
" alter table core.content rename column hash_type to file_hash_type; " ,
" alter table core.content drop column modify_index; " ,
" alter table core.content add column file_has_thumb_new boolean; " ,
" update core.content as c1 set file_has_thumb_new = (select case when file_has_thumb <> 0 then true else false end from core.content as c2 where c1.id = c2.id); " ,
" alter table core.content drop column file_has_thumb; " ,
" alter table core.content rename file_has_thumb_new to file_has_thumb; " ,
} ;
size_t len = sizeof ( str ) / sizeof ( const char * ) ;
2021-06-27 23:31:50 +02:00
return db_query ( str , len ) ;
2021-05-14 03:31:29 +02:00
}
2021-07-03 01:18:28 +02:00
bool ItemContent : : do_migration_to_4 ( )
{
const char * str [ ] = {
" alter table core.content rename column meta_admin to admin_meta; " ,
} ;
size_t len = sizeof ( str ) / sizeof ( const char * ) ;
return db_query ( str , len ) ;
}
2021-09-22 00:23:25 +02:00
bool ItemContent : : do_migration_to_5 ( )
{
const char * str = " alter table core.content add column file_mime_type varchar(256) " ;
return db_query ( str ) ;
}
2022-12-19 19:13:45 +01:00
bool ItemContent : : do_migration_to_6 ( )
{
const char * str = " ALTER TABLE core.content ADD CONSTRAINT content_pkey PRIMARY KEY (id); " ;
return db_query ( str ) ;
}
2021-06-18 19:18:13 +02:00
bool ItemContent : : has_access ( const User * current_user , int mask ) const
{
if ( current_user )
{
2021-06-27 23:31:50 +02:00
if ( current_user - > is_super_user )
2021-06-18 19:18:13 +02:00
{
// super user is allowed everything
return true ;
}
if ( user_id ! = - 1 & & current_user - > id = = user_id )
{
// the owner
return ( ( privileges > > 9 ) & mask ) = = mask ;
}
if ( group_id ! = - 1 & & current_user - > IsMemberOf ( group_id ) )
{
// group
return ( ( privileges > > 6 ) & mask ) = = mask ;
}
// others -- others logged users
return ( ( privileges > > 3 ) & mask ) = = mask ;
}
// guests -- not logged users
return ( privileges & mask ) = = mask ;
}
bool ItemContent : : has_read_access ( const User * current_user ) const
{
return has_access ( current_user , 4 ) ; // r
}
bool ItemContent : : has_write_access ( const User * current_user ) const
{
return has_access ( current_user , 2 ) ; // w
}
bool ItemContent : : has_read_write_access ( const User * current_user ) const
{
return has_access ( current_user , 6 ) ; // r+w
}
bool ItemContent : : has_read_exec_access ( const User * current_user ) const
{
2021-06-27 23:31:50 +02:00
if ( current_user & & current_user - > is_super_user )
2021-06-18 19:18:13 +02:00
{
// there must be at least one 'x' (for the root)
// !! CHECK ME: is it applicable to directories too?
return ( privileges & 01111 ) ! = 0 ;
}
return has_access ( current_user , 5 ) ; // r+x
}
bool ItemContent : : has_read_access ( ) const
{
return has_read_access ( get_current_user ( ) ) ;
}
bool ItemContent : : has_write_access ( ) const
{
return has_write_access ( get_current_user ( ) ) ;
}
bool ItemContent : : has_read_write_access ( ) const
{
return has_read_write_access ( get_current_user ( ) ) ;
}
bool ItemContent : : has_read_exec_access ( ) const
{
return has_read_exec_access ( get_current_user ( ) ) ;
}
bool ItemContent : : is_sticky_bit_set ( ) const
{
int mask = 010000 ;
return ( privileges & mask ) = = mask ;
}
/*
* 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 ) ;
}
2021-07-16 18:17:57 +02:00
void ItemContent : : print_content ( HtmlTextStream & out , const pt : : WTextStream & 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 )
{
std : : wstring tmp_string ;
content . to_str ( tmp_string ) ;
TemplatesFunctions : : HtmlEscapeFormTxt ( out , tmp_string ) ;
}
else
if ( content_type = = ItemContent : : ct_bbcode )
{
static std : : wstring out_temp ;
out_temp . clear ( ) ;
out_temp . reserve ( content . size ( ) * 2 ) ;
2021-07-17 13:56:37 +02:00
pt : : BBCODEParser bbcode_parser ; // IMPROVE ME move me to a better place
2021-07-16 18:17:57 +02:00
std : : wstring tmp_string ;
content . to_str ( tmp_string ) ;
2021-10-13 01:27:14 +02:00
bbcode_parser . filter ( tmp_string . c_str ( ) , out_temp ) ;
2021-07-16 18:17:57 +02:00
out < < R ( out_temp ) ;
}
else
{
// ct_html, ct_other
out . get_buffer ( ) . operator < < ( content ) ; // tricky way of putting content without escaping
}
if ( is_html_filter_on & & ! ItemContent : : CanContentBeHtmlFiltered ( content_type ) )
out < < R ( " </nofilter> " ) ;
}
2021-06-18 19:18:13 +02:00
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 ) ;
2021-07-17 13:56:37 +02:00
pt : : BBCODEParser bbcode_parser ; // IMPROVE ME move me to a better place
2021-10-13 01:27:14 +02:00
bbcode_parser . filter ( content . c_str ( ) , out_temp ) ;
2021-06-18 19:18:13 +02:00
out < < R ( out_temp ) ;
}
else
{
// ct_html, ct_other
out < < R ( content ) ;
}
if ( is_html_filter_on & & ! ItemContent : : CanContentBeHtmlFiltered ( content_type ) )
out < < R ( " </nofilter> " ) ;
}
2021-11-26 21:49:21 +01:00
void ItemContent : : print_content ( HtmlTextStream & str )
{
Config * config = get_config ( ) ;
bool is_html_filter_on = ( config & & config - > html_filter ) ;
if ( content_raw_type = = ct_markdown )
{
print_content ( str , content_parsed , content_parsed_type , is_html_filter_on ) ;
}
else
{
print_content ( str , content_raw , content_raw_type , is_html_filter_on ) ;
}
}
2021-06-18 19:18:13 +02:00
void ItemContent : : print_content ( EzcEnv & env )
{
2021-11-26 21:49:21 +01:00
print_content ( env . out ) ;
2021-06-18 19:18:13 +02:00
}
void ItemContent : : has_static_file ( EzcEnv & env )
{
env . res = file_type ! = WINIX_ITEM_FILETYPE_NONE & & ! file_path . empty ( ) ;
}
void ItemContent : : privileges_octal ( EzcEnv & env )
{
env . out < < Toa ( privileges , 8 ) ;
}
2021-06-20 21:22:08 +02:00
bool ItemContent : : has_user ( ) const
{
return user_id ! = - 1 ;
}
bool ItemContent : : has_group ( ) const
{
return group_id ! = - 1 ;
}
2021-07-06 21:52:29 +02:00
bool ItemContent : : item_users_different ( )
{
return user_id ! = modification_user_id ;
}
2021-07-01 23:34:49 +02:00
void ItemContent : : user ( morm : : Wrapper & wrapper )
2021-06-18 19:18:13 +02:00
{
Users * users = get_users ( ) ;
if ( users )
{
User * puser = users - > GetUser ( user_id ) ;
2021-06-19 23:48:12 +02:00
if ( puser )
{
2021-07-01 23:34:49 +02:00
wrapper . model = puser ;
2021-06-19 23:48:12 +02:00
}
2021-06-18 19:18:13 +02:00
}
}
2021-07-01 23:34:49 +02:00
void ItemContent : : group ( morm : : Wrapper & wrapper )
2021-06-18 19:18:13 +02:00
{
Groups * groups = get_groups ( ) ;
if ( groups )
{
Group * pgroup = groups - > GetGroup ( group_id ) ;
if ( pgroup )
2021-06-19 23:48:12 +02:00
{
2021-07-01 23:34:49 +02:00
wrapper . model = pgroup ;
2021-06-19 23:48:12 +02:00
}
2021-06-18 19:18:13 +02:00
}
}
2021-11-26 21:49:21 +01:00
ItemContent : : ContentType ItemContent : : get_content_type_from_str ( const wchar_t * str )
{
struct Type
{
const wchar_t * str ;
ContentType type ;
} ;
static Type types [ ] = {
{ L " 0 " , ct_text } ,
{ L " 1 " , ct_formatted_text } ,
{ L " 2 " , ct_html } ,
{ L " 3 " , ct_bbcode } ,
{ L " 4 " , ct_other } ,
{ L " 5 " , ct_markdown } ,
} ;
size_t len = sizeof ( types ) / sizeof ( Type ) ;
for ( size_t i = 0 ; i < len ; + + i )
{
if ( pt : : is_equal ( types [ i ] . str , str ) )
{
return types [ i ] . type ;
}
}
return ct_other ;
}
ItemContent : : ContentType ItemContent : : get_content_type_from_str ( const std : : wstring & str )
{
return get_content_type_from_str ( str . c_str ( ) ) ;
}
2021-06-27 23:31:50 +02:00
bool ItemContent : : content_type_is ( const std : : wstring & type )
2021-06-18 19:18:13 +02:00
{
2021-06-27 23:31:50 +02:00
if ( content_raw_type = = ItemContent : : ct_text & & type = = L " text " )
return true ;
2021-06-18 19:18:13 +02:00
else
2021-06-27 23:31:50 +02:00
if ( content_raw_type = = ItemContent : : ct_formatted_text & & type = = L " formatted text " )
return true ;
2021-06-18 19:18:13 +02:00
else
2021-06-27 23:31:50 +02:00
if ( content_raw_type = = ItemContent : : ct_html & & type = = L " html " )
return true ;
2021-06-18 19:18:13 +02:00
else
2021-06-27 23:31:50 +02:00
if ( content_raw_type = = ItemContent : : ct_bbcode & & type = = L " bbcode " )
return true ;
2021-06-18 19:18:13 +02:00
else
2021-06-27 23:31:50 +02:00
if ( content_raw_type = = ItemContent : : ct_other & & type = = L " other " )
2021-11-26 21:49:21 +01:00
return true ;
else
if ( content_raw_type = = ItemContent : : ct_markdown & & type = = L " markdown " )
2021-06-27 23:31:50 +02:00
return true ;
return false ;
}
void ItemContent : : type_is ( EzcEnv & env )
{
env . res = content_type_is ( env . par ) ;
2021-06-18 19:18:13 +02:00
}
void ItemContent : : is_empty ( EzcEnv & env )
{
env . res = content_raw . empty ( ) ;
}
void ItemContent : : file_type_is_none ( EzcEnv & env )
{
env . res = file_type = = WINIX_ITEM_FILETYPE_NONE ;
}
/*
* when we change file_type to string the we can return true only for
* those images which can be able to show by a webbrowser
*
*/
void ItemContent : : file_type_is_image ( EzcEnv & env )
{
env . res = file_type = = WINIX_ITEM_FILETYPE_IMAGE ;
}
/*
* similar we can return true only for those videos which can be rendered by a webbrowser
*/
void ItemContent : : file_type_is_video ( EzcEnv & env )
{
env . res = file_type = = WINIX_ITEM_FILETYPE_VIDEO ;
}
void ItemContent : : file_type_is_sound ( EzcEnv & env )
{
//env.res = file_type == WINIX_ITEM_FILETYPE_;
env . res = false ;
}
void ItemContent : : has_thumb ( EzcEnv & env )
{
env . res = file_has_thumb ;
}
2021-06-19 23:48:12 +02:00
void ItemContent : : display_user_name ( EzcEnv & env )
{
Locale * locale = get_locale ( ) ;
if ( user_id ! = - 1 )
{
Users * users = get_users ( ) ;
if ( users )
{
User * user = users - > GetUser ( user_id ) ;
if ( user )
{
user - > display_name ( env ) ;
}
else
{
if ( locale )
locale - > Get ( L " not_existing_user " ) ;
else
env . out < < " not existing user " ;
}
}
}
else
{
// IMPROVEME these should be moved to a better place
env . out < < " ~ " ;
if ( ! guest_name . empty ( ) & & ! IsWhite ( guest_name ) )
{
env . out < < guest_name ;
}
else
{
if ( locale )
env . out < < locale - > Get ( L " display_guest_name " ) ;
else
env . out < < " guest " ;
}
}
}
2021-06-18 19:18:13 +02:00
2021-05-14 03:31:29 +02:00
2021-07-06 21:52:29 +02:00
bool ItemContent : : is_meta_object ( ) const
2021-07-03 01:18:28 +02:00
{
return meta . is_object ( ) ;
}
2021-07-06 21:52:29 +02:00
bool ItemContent : : is_admin_meta_object ( ) const
2021-07-03 01:18:28 +02:00
{
return admin_meta . is_object ( ) ;
}
2021-06-20 21:22:08 +02:00
2021-07-06 21:52:29 +02:00
bool ItemContent : : are_dates_equal ( ) const
{
return date_creation = = date_modification ;
}
bool ItemContent : : is_link_to ( ) const
{
return ! link_to . empty ( ) ;
}
bool ItemContent : : is_link_redirect ( ) const
{
return link_redirect = = 1 ;
}
2014-02-12 17:30:49 +01:00
} // namespace Winix