YaWK  24.1
Yet another WebKit
index.php
Go to the documentation of this file.
1 <?php
2 /**
3  * @details <b>Index.php - the main entry point (controller) of the website's frontend</b>
4  *
5  * First of all, the session gets started, error reporting is set, followed by
6  * including all required classes (because its faster than SPLautoload).
7  * Afterwards, a handful of objects will be created:
8  * <ul>
9  * <li>\YAWK\db</li>
10  * <li>\YAWK\template</li>
11  * <li>\YAWK\user</li>
12  * <li>\YAWK\page</li>
13  * <li>\YAWK\controller</li>
14  * <li>\YAWK\stats</li>
15  * </ul>
16  * <p>Those objects are holding all data used by the frontend. Additional
17  * you can use any of that many static methods from other classes. See class
18  * overview for details about how YaWK is organized.</p>
19  *
20  * @author Daniel Retzl <[email protected]>
21  * @copyright 2016 Daniel Retzl http://yawk.website
22  * @license http://www.gnu.org/licenses/gpl-3.0 GNU/GPL 3.0
23  * @version 1.0.0
24  * @link http://yawk.website
25  * @since File available since Release 1.0.0
26  * @brief Index.php - the main entry point (controller) of the website's frontend
27  *
28  */
29 
30 use YAWK\controller;
31 use YAWK\db;
32 use YAWK\page;
34 use YAWK\settings;
35 use YAWK\stats;
36 use YAWK\sys;
37 use YAWK\template;
38 use YAWK\user;
39 
40 session_start();
41 header('Cache-control: private'); // IE 6 FIX
42 error_reporting(E_ALL ^ E_STRICT); // just for development purpose!!!
43 ini_set('display_errors', 1); // DISPLAY ALL ERRORS - DEVELOPMENT ONLY!!!
44 error_reporting(1); // no error reporting
45 /* include core files */
46 require_once('system/classes/db.php'); // database connection
47 require_once('system/classes/settings.php'); // get/set settings from settings db
48 require_once 'system/classes/language.php'; // language class
49 require_once('system/classes/alert.php'); // draw fancy JS-notification alert class
50 require_once('system/classes/email.php'); // email functions
51 require_once('system/classes/user.php'); // all get/set/handle user functions
52 require_once('system/classes/page.php'); // all get/set/handle page functions
53 require_once('system/classes/menu.php'); // all get/set/handle menu functions
54 require_once('system/classes/widget.php'); // all get/set/handle widget functions
55 require_once('system/classes/template.php'); // all template functions, including get/set template settings
56 require_once('system/classes/sys.php'); // basic i/o and helper functions
57 require_once('system/classes/controller.php'); // frontEnd init and filename filter controller
58 require_once('system/classes/stats.php'); // statistics functions
59 /* set database object */
60 if (!isset($db)) {
61  $db = new db();
62 }
63 
64 /* language object */
65 if (empty($lang))
66 { // create new language obj if none exists
67  $language = new YAWK\language();
68  // init language
69  $language->init($db, "frontend");
70  // convert object param to array !important
71  $lang = (array) $language->lang;
72 }
73 
74 /* set template object */
75 if (!isset($template)) {
76  $template = new template();
77 }
78 /* set user object */
79 if (!isset($user)) {
80  $user = new user($db);
81 }
82 /* set page object */
83 if (!isset($page)) {
84  $page = new page();
85  $currentpage = $page;
86 }
87 /* set controller object */
88 if (!isset($controller)) {
89  $controller = new controller();
90 }
91 /* set stats object */
92 if (!isset($stats)) {
93  $stats = new stats();
94  $stats->setStats($db);
95 }
96 // lets go with the frontEnd...
97 // \YAWK\sys::outputObjects($template, $language, $controller, $page, $user, $stats);
98 // \YAWK\controller::frontEndInit($db, $currentpage, $user, $template);
99 if (sys::isOffline($db)) { // backend-users (admins) can see the frontend,
100  // while the site is still offline to guests & no-admins
101  sys::drawOfflineMessage($db);
102  exit;
103 }
104 // check if user wants to register (signUp)
105 if (isset($_GET['signup']) && ($_GET['signup']) == 1) {
106  include('system/plugins/signup/classes/signup.php');
107  $signup = new signup();
108  echo $signup->sayHello($db, $lang);
109 }
110 
111 // URL controller - this loads the properties of each page */
112 if (isset($_GET['include']) && (!empty($_GET['include'])))
113 { // LOGOUT SENT VIA GET (yourdomain.com/logout)
114  if ($_GET['include'] === "logout")
115  { // start logout procedure
116  if ($user->logout($db) === true)
117  { // redirect user to index page
118  sys::setTimeout("index.html", 0);
119  exit;
120  }
121  }
122  // user filled out login form
123  if (isset($_POST['login']))
124  { // check given vars
125  if (isset($_POST['user']) && (isset($_POST['password'])))
126  { // check if user login was successful
127  if ($user->login($db, $_POST['user'], $_POST['password']) === true)
128  { // check if custom redirect url after login is requested
129  if (isset($_POST['loginboxRedirect']) && (!empty($_POST['loginboxRedirect'])))
130  { // redirect to custom url
131  if (isset($_POST['loginboxRedirectTime'])
132  && (!empty($_POST['loginboxRedirectTime'])
133  && (is_numeric($_POST['loginboxRedirectTime']))))
134  { // delay before redirect
135  sys::setTimeout($_POST['loginboxRedirect'], $_POST['loginboxRedirectTime']);
136  }
137  else
138  { // redirect w/o delay
139  sys::setTimeout($_POST['loginboxRedirect'], 0);
140  }
141  }
142  else
143  { // redirect to index page (only in html mode)
144  $_GET['include'] = "index";
145  }
146  }
147  }
148  }
149 
150  // URL is set and not empty - lets go, load properties for given page
151  $page->loadProperties($db, $db->quote($_GET['include']));
152 
153  // more different GET controller actions can be done here...
154 }
155 else
156 { // if no page is given, set index as default page
157  $_GET['include'] = "index";
158  // and load properties for it
159  $page->loadProperties($db, $db->quote($_GET['include']));
160 }
161 if (!empty($_GET['templateID'])){
162  $template->id = $_GET['templateID'];
163 }
164 else {
165 // get global selected template ID
166  $template->id = settings::getSetting($db, "selectedTemplate");
167 }
168 
169 // set template
170 $template->selectedTemplate = $template->id;
171 
172 // set template loading mechanism, depending on state and settings (user is logged in, allowed to override etc...)
173 if (user::isAnybodyThere($db))
174 { // user seems to be logged in...
175  // load template name from {users}
176  $user->loadProperties($db, $_SESSION['username']);
177 
178  // check if user is allowed to overrule selectedTemplate
179  if ($user->overrideTemplate == 1)
180  {
181  // frontendSwitch (dark / light mode)
182  if (isset($_COOKIE["frontendSwitchID"])){
183  $user->templateID = json_decode(stripslashes($_COOKIE['frontendSwitchID']));
184  }
185 
186  // set user template ID to session
187  $_SESSION['userTemplateID'] = $user->templateID;
188 
189  // get template by user templateID
190  $template->name = template::getTemplateNameById($db, $user->templateID);
191  // include page, based on user templateID
192  $tplPath = 'system/templates/'.$template->name.'/index.php';
193 
194  // check if user template is loadable
195  if (is_file($tplPath))
196  { // load properties for user overridden template
197  $template->loadProperties($db, $user->templateID);
198  // load user template
199  include($tplPath);
200  }
201  else
202  { // user template is not loadable
203  die("Unable to include user overriden template ID ".$user->templateID." (".$template->name.") from template path: ".$tplPath." <br>Either database config is faulty or Template ID: (".$user->templateID.") is not correctly installed.");
204  }
205  }
206  else
207  { // DEFAULT (GLOBAL) TEMPLATE
208  // user is not allowed to overrule template, show global default (selectedTemplate) instead.
209 
210  // frontendSwitch (dark / light mode)
211  if (isset($_COOKIE["frontendSwitchID"]))
212  { // set user selected template from dark/light mode frontendSwitch
213  $template->selectedTemplate = json_decode(stripslashes($_COOKIE['frontendSwitchID']));
214  }
215  // get template name and build path
216  $template->name = template::getTemplateNameById($db, $template->selectedTemplate);
217  $tplPath = "system/templates/".$template->name."/index.php";
218  if (is_file($tplPath))
219  { // load properties for default template
220  $template->loadProperties($db, $template->selectedTemplate);
221  // load global default (admin selected template)
222  include($tplPath);
223  }
224  else
225  { // user = logged in, default template not loadable
226  die("Unable to include default template ID ".$user->templateID." (".$template->name.") for logged in user from path: ".$tplPath." <br>Either database config is faulty or selected Template ID: (".$user->templateID.") is not correctly installed.");
227  }
228  }
229 }
230 else
231 { // user is NOT logged in, load default template (selectedTemplate) from settings db
232  // frontendSwitch (dark / light mode)
233  if (isset($_COOKIE["frontendSwitchID"]))
234  { // set user selected template from dark/light mode frontendSwitch
235  $template->selectedTemplate = json_decode(stripslashes($_COOKIE['frontendSwitchID']));
236  }
237 
238  $template->name = template::getTemplateNameById($db, $template->selectedTemplate);
239  $tplPath = "system/templates/".$template->name."/index.php";
240 
241  if (is_file($tplPath))
242  { // load properties for default template
243  $template->loadProperties($db, $template->selectedTemplate);
244  include ($tplPath);
245  }
246  else
247  { // no user logged in, default template not loadable
248  die("Unable to include default template ID ".$template->selectedTemplate." (".$template->name.") for guest user from path: ".$tplPath." <br>Either database config is faulty or selected Template ID: (".$user->templateID.") is not correctly installed.");
249  }
250 }
print $lang['FILEMAN_UPLOAD']
die
Definition: block-user.php:27
Handles the Blog System.
Definition: signup.php:15
The controller function returns filtered filename as string (or null).
Definition: controller.php:15
Mysqli database class; returns db connection object.
Definition: db.php:16
The language class - support multilingual backend.
Definition: language.php:17
The default pages class. Provide all functions to handle static pages.
Definition: page.php:20
Settings class: get and set YaWK system settings.
Definition: settings.php:9
Statistics - get and set user and page stats.
Definition: stats.php:10
The sys class - handles yawk's system core functions.
Definition: sys.php:17
The template controller - get and set template settings.
Definition: template.php:16
The default user class. Provide all functions to handle the user object.
Definition: user.php:17
$tplPath
Definition: index.php:239
exit
print $_GET['id']
Definition: page-edit.php:357
$page
Definition: pages.php:355
$signup
Definition: signup.php:10