55 $this->CachedMultyFS =
get_package(
'cached_multy_fs' ,
'last' , __FILE__ );;
56 $this->Security =
get_package(
'security' ,
'last' , __FILE__ );
98 if( $this->AddLimitations ===
'1 = 1' )
100 $this->AddLimitations = $theAddLimitation;
104 throw(
new Exception(
'"AddLimitations" was already set' ) );
107 catch( Exception $e )
139 $PageName = $this->Security->get( $PageName ,
'command' );
141 $FileName = dirname( __FILE__ ).
'/data/pa_'.$PageName;
142 if( $this->CachedMultyFS->file_exists( $FileName ) )
144 $RawData = $this->CachedMultyFS->file_get_contents( $FileName ,
'cleaned' );
153 catch( Exception $e )
186 $Appliance = array();
188 $RawData = explode(
"\n" , $RawData );
189 $c = count( $RawData );
191 for( $i = 0 ; $i < $c ; $i++ )
193 $RawDataInfo = explode(
'#' , $RawData[ $i ] );
194 $Appliance [] = array(
195 'package' => @$RawDataInfo[ 0 ] ,
'package_version' => @$RawDataInfo[ 1 ] ,
196 'options' => @$RawDataInfo[ 2 ] ,
'placeholder' => @$RawDataInfo[ 3 ]
200 return( $Appliance );
202 catch( Exception $e )
243 if( strlen( $RawData ) !== 0 )
253 catch( Exception $e )
285 $PageName = $this->Security->get( $PageName ,
'command' );
286 $Packages = $this->Security->get( $Packages ,
'unsafe_string' );
288 $this->CachedMultyFS->file_put_contents( dirname( __FILE__ ).
'/data/pa_'.$PageName , $Packages );
290 catch( Exception $e )
322 private function create_object( &$RawData , $PageName )
326 $RawData = explode(
'#' , $RawData );
328 if( count( $RawData ) <= 3 )
332 if( count( $RawData ) <= 4 )
339 array(
'title' => $RawData[ 0 ] ,
'alias' => $PageName ,
'template' => $RawData[ 1 ] ,
340 'template_version' => $RawData[ 2 ] ,
'options' => $RawData[ 3 ] ,
341 'keywords' => $RawData[ 4 ] ,
'description' => $RawData[ 5 ] )
344 catch( Exception $e )
378 $PageName = $this->Security->get( $PageName ,
'command' );
380 if( $this->CachedMultyFS->file_exists( dirname( __FILE__ ).
'/data/'.$PageName ) )
382 $RawData = $this->CachedMultyFS->file_get_contents( dirname( __FILE__ ).
'/data/'.$PageName );
384 return( $this->create_object( $RawData , $PageName ) );
389 catch( Exception $e )
419 $ListOfPages = array();
420 $MountedStorages = $this->CachedMultyFS->get_mounted_storages();
421 $MountedStorages [] = dirname( __FILE__ ).
'/data';
422 foreach( $MountedStorages as $ms )
424 if( $Handle = @opendir( $ms ) )
426 while(
false !== ( $File = readdir( $Handle ) ) )
428 $Flag = strpos( $File ,
'pa_' ) !== 0 && strpos( $File ,
'index.html' ) !== 0;
430 if( is_file( dirname( __FILE__ ).
'/data/'.$File ) && $Flag )
438 return( $ListOfPages );
440 catch( Exception $e )
472 private function filter_pages( &$ListOfPages , $Limit )
477 $SearchString = $this->Security->get_gp(
'search_string' ,
'string' ,
'' );
479 foreach( $ListOfPages as $i => $l )
481 if( $SearchString !==
'' && !( strpos( $l[
'title' ] , $SearchString ) !==
false ||
482 strpos( $l[
'alias' ] , $SearchString ) !==
false ||
483 strpos( $l[
'template' ] , $SearchString ) !==
false ||
484 strpos( $l[
'template_version' ] , $SearchString ) !==
false ) )
496 catch( Exception $e )
536 function select( $Start , $Limit , $Field =
false , $Order =
false , $Condition =
false )
542 if( $Order !==
false )
544 $SortSign = $Order ===
'ascending' ?
'<' :
'>';
545 $SortFunc = create_function(
546 '$a , $b' ,
"if( \$a[ '$Field' ] == \$b[ '$Field' ] )".
547 "return(0);return( \$a[ '$Field' ] $SortSign \$b[ '$Field' ] ? -1 : 1 );"
549 usort( $ListOfPages , $SortFunc );
552 return( $this->filter_pages( $ListOfPages , $Limit ) );
554 catch( Exception $e )
586 $PageName = $this->Security->get( $PageName ,
'command' );
588 return( $this->CachedMultyFS->file_exists( dirname( __FILE__ ).
"/data/".$PageName ) );
590 catch( Exception $e )
618 private function compile_create_data( &$Record )
622 $Title = $this->Security->get(
get_field( $Record ,
'page_title' ) ,
'string' );
623 $Template = $this->Security->get(
get_field( $Record ,
'page_template' ) ,
'string' );
624 $TemplateVersion =
get_field( $Record ,
'page_template_version' ,
'last' );
625 $TemplateVersion = $this->Security->get( $TemplateVersion ,
'string' );
627 return(
"$Title#$Template#$TemplateVersion#$Settings" );
629 catch( Exception $e )
661 $PageName = $this->Security->get(
get_field( $Record ,
'page_alias' ) ,
'command' );
668 $Page = $this->compile_create_data( $Record );
670 $this->CachedMultyFS->file_put_contents( dirname( __FILE__ ).
"/data/".$PageName , $Page );
671 $this->CachedMultyFS->file_put_contents( dirname( __FILE__ ).
"/data/pa_".$PageName ,
'' );
675 catch( Exception $e )
715 function update( $PageName , $Title , $Template , $TemplateVersion , $PredefinedPackages )
719 $PageName = $this->Security->get( $PageName ,
'command' );
722 $Title = $this->Security->get( $Title ,
'string' );
723 $Template = $this->Security->get( $Template ,
'string' );
724 $TemplateVersion = $this->Security->get( $TemplateVersion ,
'command' );
725 $PredefinedPackages = $this->Security->get( $PredefinedPackages ,
'string' );
727 $Path = dirname( __FILE__ ).
"/data/$PageName";
728 $this->CachedMultyFS->file_put_contents( $Path ,
"$Title#$Template#$TemplateVersion#$Options" );
730 catch( Exception $e )
754 function delete( $PageNames )
758 $PageNames = explode(
',' , $PageNames );
760 foreach( $PageNames as $i => $PageName )
762 $PageName = $this->Security->get( $PageName ,
'command' );
764 @unlink( dirname( __FILE__ ).
'/data/'.$PageName );
765 @unlink( dirname( __FILE__ ).
'/data/pa_'.$PageName );
767 $EventManager =
get_package(
'event_manager' ,
'last' , __FILE__ );
768 $EventManager->trigger_event(
'on_after_delete_page' , array(
'page_name' => $PageName ) );
771 catch( Exception $e )
811 function add_package( $PageName , $PackageName , $PackageVersion , $Params , $PlaceHolder )
815 $PageName = $this->Security->get( $PageName ,
'command' );
817 $CachedFS =
get_package(
'cached_multy_fs' ,
'last' , __FILE__ );
818 $CachedFS->file_put_contents(
819 dirname( __FILE__ ).
'/data/pa_'.$PageName ,
820 $PackageName.
'#'.$PackageVersion.
'#'.$Params.
'#'.$PlaceHolder.
"\r\n" , FILE_APPEND
823 catch( Exception $e )
855 if( is_string( $PageNames ) )
857 $PageNames = explode(
',' , $PageNames );
862 foreach( $PageNames as $i => $PageName )
869 catch( Exception $e )