70 $this->Database =
get_package(
'database' ,
'last' , __FILE__ );
71 $this->DatabaseAlgorithms =
get_package(
'database::database_algorithms' ,
'last' , __FILE__ );
72 $this->Security =
get_package(
'security' ,
'last' , __FILE__ );
73 $this->SecurityParser =
get_package(
'security::security_parser' ,
'last' , __FILE__ );
74 $this->UserAccess =
get_package(
'user::user_access' ,
'last' , __FILE__ );
116 if( $this->AddLimitations ===
'1 = 1' )
118 $this->AddLimitations = $theAddLimitation;
122 throw(
new Exception(
'"AddLimitations" was already set' ) );
125 catch( Exception $e )
173 function select( $Start =
false , $Limit =
false , $Field =
false , $Order =
false ,
174 $Condition =
'1 = 1' , $Options =
false )
179 if( $Options !==
false && $Options->get_setting(
'category_name' ,
false ) )
181 $Category =
get_package(
'category::category_algorithms' ,
'last' , __FILE__ );
182 $AddCondition =
'AND category IN ( '.implode(
183 ',' , $Category->get_category_ids( $Options->get_setting(
'category_name' ) )
187 $Condition = $this->DatabaseAlgorithms->select_condition(
188 $Start , $Limit , $Field , $Order , $Condition , $this->NativeTable
193 catch( Exception $e )
217 private function compile_print_content( &$Content )
221 $MainContent = $this->Security->get(
get_field( $Content ,
'main_content' ) ,
'unsafe_string' );
223 $PrintContent = $this->Security->get(
get_field( $Content ,
'print_content' ) ,
'unsafe_string' );
225 $Content ,
'print_content_unsafe' ,
226 strlen( $PrintContent ) === 0 ? $MainContent : $PrintContent
229 set_field( $Content ,
'has_print_content' , strlen( $PrintContent ) === 0 ? 0 : 1 );
231 catch( Exception $e )
259 private function compile_selected_content( &$Content )
263 foreach( $Content as $k => $v )
265 $DemoContent = $this->Security->get(
get_field( $v ,
'demo_content' ) ,
'unsafe_string' );
266 set_field( $Content[ $k ] ,
'demo_content_unsafe' , $DemoContent );
267 set_field( $Content[ $k ] ,
'has_demo_content' , strlen( $DemoContent ) );
269 $MainContent = $this->Security->get(
get_field( $v ,
'main_content' ) ,
'unsafe_string' );
270 set_field( $Content[ $k ] ,
'main_content_unsafe' , $MainContent );
271 set_field( $Content[ $k ] ,
'has_main_content' , strlen( $MainContent ) );
273 $this->compile_print_content( $Content[ $k ] );
276 catch( Exception $e )
306 $Content = $this->Database->select(
307 $this->NativeTable.
'.* , umx_category.title AS category_title , user.login AS author_name' ,
308 $this->NativeTable.
' , umx_category , '.$this->UserAccess->NativeTable.
' AS user' ,
309 "author = user.id AND ( $this->AddLimitations ) AND umx_category.id = category AND $Condition"
312 $this->compile_selected_content( $Content );
316 catch( Exception $e )
348 $id = $this->Security->get( $id ,
'integer_list' );
350 return( $this->
unsafe_select( $this->NativeTable.
".id IN ( $id )" ) );
352 catch( Exception $e )
376 function delete( $id )
380 $id = $this->Security->get( $id ,
'integer_list' );
382 $this->Database->delete( $this->NativeTable ,
"( $this->AddLimitations ) AND id IN ( $id )" );
384 catch( Exception $e )
412 private function fetch_create_data( &$Record )
416 $Record = $this->SecurityParser->parse_parameters(
418 'author:integer;title:string;category:integer;demo_content:string;'.
419 'main_content:string;keywords:string;description:string;print_content:string'
423 $this->DatabaseAlgorithms->compile_fields_values(
428 catch( Exception $e )
460 list( $Fields , $Values ) = $this->fetch_create_data( $Record );
462 $id = $this->DatabaseAlgorithms->create( $this->NativeTable , $Fields , $Values );
464 $EventManager =
get_package(
'event_manager' ,
'last' , __FILE__ );
465 $EventManager->trigger_event(
'on_after_create_content' , array(
'id' => $id ) );
469 catch( Exception $e )
501 $CategoryIds = $this->Security->get( $CategoryIds ,
'integer' );
505 'category IN ( '.implode(
',' , $CategoryIds ).
' ) ORDER BY publication_date ASC'
509 catch( Exception $e )
541 $CategoryIds = $this->Security->get( $CategoryIds ,
'integer' );
544 $this->Database->select(
545 'YEAR( publication_date ) AS publication_year , MONTH( publication_date ) AS publication_month'.
546 ' , COUNT( * ) AS publication_count' ,
548 'category IN ( '.implode(
',' , $CategoryIds ).
549 ' ) GROUP BY publication_year , publication_month ORDER BY publication_date ASC'
553 catch( Exception $e )
593 $Year = $this->Security->get( $Year ,
'integer' );
594 $Month = $this->Security->get( $Month ,
'integer' );
595 $CategoryIds = $this->Security->get( $CategoryIds ,
'integer' );
599 "YEAR( publication_date ) = $Year AND MONTH( publication_date ) = $Month AND ".
600 'category IN ( '.implode(
',' , $CategoryIds ).
' ) ORDER BY publication_date ASC'
604 catch( Exception $e )
628 private function compile_record( &$Record )
632 $Record = $this->SecurityParser->parse_parameters(
634 'author:integer;title:string;category:integer;demo_content:string;main_content:string;'.
635 'keywords:string;description:string;print_content:string' ,
'allow_not_set'
638 catch( Exception $e )
670 $id = $this->Security->get( $id ,
'integer_list' );
672 $this->compile_record( $Record );
674 list( $Fields , $Values ) = $this->DatabaseAlgorithms->compile_fields_values( $Record );
676 if( isset( $Fields[ 0 ] ) )
679 $Fields [] =
'modification_date';
680 $Values [] =
'now()';
682 $Condition =
"( $this->AddLimitations ) AND id IN ( $id )";
683 $this->Database->update( $this->NativeTable , $Fields , $Values , $Condition );
684 $this->Database->commit();
687 catch( Exception $e )
715 private function search_fields( $SearchString )
719 $SearchString = $this->Security->get( $SearchString ,
'string' );
722 "id , CONCAT( title , ' ' , demo_content , ' ' , main_content ) AS record_text ,
723 CHAR_LENGTH( CONCAT( title , ' ' , demo_content , ' ' , main_content ) ) - CHAR_LENGTH(
724 REPLACE( CONCAT( title , ' ' , demo_content , ' ' , main_content ) , '$SearchString' , '' )
726 CONCAT( './content_view.html?content_id=' , id ) AS source_page ,
727 title AS source_page_title"
730 catch( Exception $e )
762 function search( $Start , $SearchString )
766 $Start = $this->Security->get( $Start ,
'integer' );
770 $Records = $this->Database->select(
771 $this->search_fields( $SearchString ) , $this->NativeTable ,
772 "( $this->AddLimitations ) ORDER BY relevation DESC LIMIT $Start , 10"
777 catch( Exception $e )