Automad
 All Classes Functions Variables Pages
init.php
1 <?php
2 /*
3  * ....
4  * .: '':.
5  * :::: ':..
6  * ::. ''..
7  * .:'.. ..':.:::' . :. '':.
8  * :. '' '' '. ::::.. ..:
9  * ::::. ..':.. .'''::::: .
10  * :::::::.. '..:::: :. :::: :
11  * ::'':::::::. ':::.'':.:::: :
12  * :.. ''::::::....': '':: :
13  * :::::. '::::: : .. '' .
14  * .''::::::::... ':::.'' ..'' :.''''.
15  * :..:::''::::: :::::...:'' :..:
16  * ::::::. ':::: :::::::: ..:: .
17  * ::::::::.:::: :::::::: :'':.:: .''
18  * ::: '::::::::.' ''::::: :.' '': :
19  * ::: :::::::::..' :::: ::...' .
20  * ::: .:::::::::: :::: :::: .:'
21  * '::' ''::::::: :::: : :: :
22  * ':::: :::: :'' .:
23  * :::: :::: ..''
24  * :::: ..:::: .:''
25  * '''' '''''
26  *
27  *
28  * AUTOMAD
29  *
30  * Copyright (c) 2014 by Marc Anton Dahmen
31  * http://marcdahmen.de
32  *
33  * Licensed under the MIT license.
34  * http://automad.org/license
35  */
36 
37 
38 namespace Automad\Core;
39 
40 
41 defined('AUTOMAD') or die('Direct access not permitted!');
42 
43 
44 // Set default timezone if not set.
45 date_default_timezone_set(@date_default_timezone_get());
46 
47 
48 // Autoload core classes and libraries.
49 spl_autoload_register(function($class) {
50 
51  $file = strtolower(str_replace('\\', '/', $class)) . '.php';
52 
53  if (strpos($file, 'automad') === 0) {
54  // Load Automad class.
55  require_once AM_BASE_DIR . '/' . $file;
56  } else {
57  // Load 3rd party library.
58  require_once AM_BASE_DIR . '/automad/lib/' . $file;
59  }
60 
61 });
62 
63 
64 // Load configuration and define constants.
65 require AM_BASE_DIR . '/automad/const.php';
66 
67 
68 // Enable full error reporting, when debugging is enabled.
70 
71 
72 // The cache folder must be writable (resized images), also when caching is disabled!
73 if (!is_writable(AM_BASE_DIR . AM_DIR_CACHE)) {
74  die('The folder "' . AM_DIR_CACHE . '" must be writable by the web server!');
75 }
76 
77 
78 // Split GUI form regular pages.
79 if (AM_REQUEST == AM_PAGE_GUI && AM_PAGE_GUI) {
80 
81  $GUI = new \Automad\GUI\GUI();
82  $output = $GUI->output;
83 
84 } else {
85 
86  // Load page from cache or process template
87  $Cache = new Cache();
88 
89  if ($Cache->pageCacheIsApproved()) {
90 
91  // If cache is up to date and the cached file exists,
92  // just get the page from the cache.
93  $output = $Cache->readPageFromCache();
94 
95  } else {
96 
97  // Else check if the site object cache is ok...
98  if ($Cache->automadObjectCacheIsApproved()) {
99 
100  // If approved, load site from cache...
101  $Automad = $Cache->readAutomadObjectFromCache();
102 
103  } else {
104 
105  // Else create new Automad.
106  $Automad = new Automad();
107  $Cache->writeAutomadObjectToCache($Automad);
108 
109  }
110 
111  // Render template
112  $Template = new Template($Automad);
113  $output = $Template->render();
114 
115  // Save output to cache if page actually exists.
116  if ($Automad->currentPageExists()) {
117 
118  $Cache->writePageToCache($output);
119 
120  } else {
121 
122  Debug::log(AM_REQUEST, 'Page not found! Caching will be skipped!');
123 
124  }
125 
126  // Generate sitemap.xml
127  new Sitemap($Automad->getCollection());
128 
129  }
130 
131 }
132 
133 
134 // If debug is enabled, prepend the logged information to the closing </body> tag and echo the page.
135 echo str_replace('</body>', Debug::getLog() . '</body>', $output);
136 
137 
138 ?>
static log($element, $description= '')
Definition: debug.php:113
static getLog()
Definition: debug.php:88
static errorReporting()
Definition: debug.php:75