ultimix
startup.php
Go to the documentation of this file.
1 <?php
2 
3  /*
4  * This source code is a part of the Ultimix Project.
5  * It is distributed under BSD licence. All other third side source code (like tinyMCE) is distributed under
6  * it's own licence wich could be found from the corresponding files or sources.
7  * This source code is provided "as is" without any warranties or garanties.
8  *
9  * Have a nice day!
10  *
11  * @url http://ultimix.sorceforge.net
12  *
13  * @author Alexey "gdever" Dodonov
14  */
15 
16  require_once( dirname( __FILE__ ).'/settings.php' );
17  require_once( dirname( __FILE__ ).'/../../packages/core/core.php' );
18 
33  function set_session()
34  {
35  try
36  {
37  $Settings = get_package( 'settings::package_settings' , 'last::last' , __FILE__ );
38  $SessionTimeout = $Settings->get_package_setting(
39  'core_data' , 'last' , 'cf_system' , 'session_timeout' , 600
40  );
41 
42  ini_set( 'session.gc_maxlifetime' , $SessionTimeout );
43  ini_set( 'session.cookie_lifetime' , $SessionTimeout );
44  ini_set( 'session.save_path' , './packages/_core_data/data/session/' );
45  }
46  catch( Exception $e )
47  {
48  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
49  }
50  }
51 
64  function main_setup()
65  {
66  try
67  {
68  $Settings = get_package_object( 'settings::settings' , 'last::last' , __FILE__ );
69  $Settings->load_file( './cf_settings' );
70 
71  $Settings->define(
72  'HTTP_HOST' ,
73  rtrim( 'http://'.$_SERVER[ 'SERVER_NAME' ].dirname( $_SERVER[ 'REQUEST_URI' ].'a' ) , '/\\' )
74  );
75  $Settings->define( 'SERVER_NAME' , $_SERVER[ 'SERVER_NAME' ] );
76  $Settings->define( 'DOMAIN' , $_SERVER[ 'HTTP_HOST' ] );
77  $Settings->set_setting( 'GZIP_TRAFFIC' , $Settings->get_setting( 'GZIP_TRAFFIC' , 'true' ) == 'true' );
78  $Settings->define( 'GZIP_TRAFFIC' );
79  }
80  catch( Exception $e )
81  {
82  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
83  }
84  }
85 
101  {
102  try
103  {
104  set_session();
105 
106  global $StartGenerationTime;
107  $StartGenerationTime = microtime( true );
108 
109  main_setup();
110  }
111  catch( Exception $e )
112  {
113  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
114  }
115  }
116 
131  function start_php_script()
132  {
133  try
134  {
136 
137  // TODO function register_view(function|package->method)
138  // TODO function register_controller(function|package->method)
139  // TODO add markup demo
140  // TODO ... (add multylanguage demo script)
141  // TODO database support (add demo)
142  // TODO caching demo
143 
144  $_GET[ 'page_name' ] = basename( $_SERVER[ 'SCRIPT_NAME' ] , ".php" );
145  }
146  catch( Exception $e )
147  {
148  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
149  }
150  }
151 
166  function index_main()
167  {
168  try
169  {
171 
172  $PageComposer = get_package( 'page::page_composer' , 'last' , __FILE__ );
173 
174  if( isset( $_GET[ 'page_name' ] ) === false )
175  {
176  $_GET[ 'page_name' ] = 'index';
177  }
178 
179  print( $PageComposer->get_page( $_GET[ 'page_name' ] ) );
180  }
181  catch( Exception $e )
182  {
183  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
184  }
185  }
186 
201  function cron_main()
202  {
203  try
204  {
205  main_setup();
206 
207  $Schedule = get_package( 'schedule' , 'last' , __FILE__ );
208 
209  $Schedule->process_tasks();
210  }
211  catch( Exception $e )
212  {
213  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
214  }
215  }
216 
243  function common_error_message_processing( $Visualisation , $e )
244  {
245  try
246  {
247  $ErrorTemplate = file_get_contents( dirname( __FILE__ ).'/../../res/templates/exception.tpl' );
248  $DownloadLinkTemplate = file_get_contents( dirname( __FILE__ ).'/../../res/templates/download_link.tpl' );
249  $ErrorTemplate = str_replace( '{exception_message}' , $e->getMessage() , $ErrorTemplate );
250 
251  if( $Visualisation )
252  {
253  print( str_replace( '{download}' , $DownloadLinkTemplate , $ErrorTemplate ) );
254  }
255 
256  return( $ErrorTemplate );
257  }
258  catch( Exception $e )
259  {
260  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
261  }
262  }
263 
282  function zip_exception( $ErrorMessage )
283  {
284  try
285  {
286  @unlink( dirname( __FILE__ ).'/../../log/exception.last.zip' );
287  $zip = new ZipArchive();
288  $zip->open( dirname( __FILE__ ).'/../../log/exception.last.zip' , ZIPARCHIVE::CREATE );
289  $zip->addFromString( 'exception.html' , str_replace( '{download}' , '' , $ErrorMessage ) );
290  }
291  catch( Exception $e )
292  {
293  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
294  }
295  }
296 
319  function handle_script_error( $Visualisation , $e )
320  {
321  try
322  {
323  global $DEBUG;
324 
325  if( $DEBUG )
326  {
327  $ErrorTemplate = common_error_message_processing( $Visualisation , $e );
328 
329  $Handle = fopen( dirname( __FILE__ ).'/../../log/exception.log' , 'at' );
330  fwrite( $Handle , $e->getMessage().'<hr width="90%">' );
331  fclose( $Handle );
332 
333  $Handle = fopen( dirname( __FILE__ ).'/../../log/exception.last.html' , 'wt' );
334  fwrite( $Handle , str_replace( '{download}' , '' , $ErrorTemplate ) );
335  fclose( $Handle );
336 
337  zip_exception( $ErrorTemplate );
338  }
339  }
340  catch( Exception $e )
341  {
342  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
343  }
344  }
345 
346 ?>