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 session_start();
30 header('Cache-control: private'); // IE 6 FIX
31 error_reporting(E_ALL ^ E_STRICT); // just for development purpose!!!
32 ini_set('display_errors', 1); // DISPLAY ALL ERRORS - DEVELOPMENT ONLY!!!
33 error_reporting(0); // no error reporting
34 /* include core files */
35 require_once('system/classes/db.php'); // database connection
36 require_once('system/classes/settings.php'); // get/set settings from settings db
37 require_once 'system/classes/language.php'; // language class
38 require_once('system/classes/alert.php'); // draw fancy JS-notification alert class
39 require_once('system/classes/email.php'); // email functions
40 require_once('system/classes/user.php'); // all get/set/handle user functions
41 require_once('system/classes/page.php'); // all get/set/handle page functions
42 require_once('system/classes/menu.php'); // all get/set/handle menu functions
43 require_once('system/classes/widget.php'); // all get/set/handle widget functions
44 require_once('system/classes/template.php'); // all template functions, including get/set template settings
45 require_once('system/classes/sys.php'); // basic i/o and helper functions
46 require_once('system/classes/controller.php'); // frontEnd init and filename filter controller
47 require_once('system/classes/stats.php'); // statistics functions
48 /* set database object */
49 if (!isset($db)) {
50  $db = new \YAWK\db();
51 }
52 
53 /* language object */
54 if (!isset($lang) || (empty($lang)))
55 { // create new language obj if none exists
56  $language = new YAWK\language();
57  // init language
58  $language->init($db, "frontend");
59  // convert object param to array !important
60  $lang = (array) $language->lang;
61 }
62 
63 /* set template object */
64 if (!isset($template)) {
65  $template = new \YAWK\template();
66 }
67 /* set user object */
68 if (!isset($user)) {
69  $user = new \YAWK\user($db);
70 }
71 /* set page object */
72 if (!isset($page)) {
73  $page = new \YAWK\page();
74  $currentpage = $page;
75 }
76 /* set controller object */
77 if (!isset($controller)) {
78  $controller = new \YAWK\controller();
79 }
80 /* set stats object */
81 if (!isset($stats)) {
82  $stats = new \YAWK\stats();
83  $stats->setStats($db);
84 }
85 // lets go with the frontEnd...
86 // \YAWK\sys::outputObjects($template, $language, $controller, $page, $user, $stats);
87 // \YAWK\controller::frontEndInit($db, $currentpage, $user, $template);
88 if (\YAWK\sys::isOffline($db)) { // backend-users (admins) can see the frontend,
89  // while the site is still offline to guests & no-admins
90  \YAWK\sys::drawOfflineMessage($db);
91  exit;
92 }
93 // check if user wants to register (signUp)
94 if (isset($_GET['signup']) && ($_GET['signup']) == 1) {
95  include('system/plugins/signup/classes/signup.php');
96  $signup = new \YAWK\PLUGINS\SIGNUP\signup();
97  echo $signup->sayHello($db);
98 }
99 
100 // URL controller - this loads the properties of each page */
101 if (isset($_GET['include']) && (!empty($_GET['include'])))
102 {
103  // LOGOUT SENT VIA GET (yourdomain.com/logout)
104  if ($_GET['include'] === "logout")
105  { // start logout procedure
106  if ($user->logout($db) === true)
107  { // redirect user to index page
108  \YAWK\sys::setTimeout("index.html", 0);
109  exit;
110  }
111  }
112  // user filled out login form
113  if (isset($_POST['login']))
114  { // check given vars
115  if (isset($_POST['user']) && (isset($_POST['password'])))
116  { // check if user login was successful
117  if ($user->login($db, $_POST['user'], $_POST['password']) === true)
118  { // check if custom redirect url after login is requested
119  if (isset($_POST['loginboxRedirect']) && (!empty($_POST['loginboxRedirect'])))
120  { // redirect to custom url
121  if (isset($_POST['loginboxRedirectTime']) && (!empty($_POST['loginboxRedirectTime']) && (is_numeric($_POST['loginboxRedirectTime']))))
122  { // delay before redirect
123  \YAWK\sys::setTimeout($_POST['loginboxRedirect'], $_POST['loginboxRedirectTime']);
124  }
125  else
126  { // redirect w/o delay
127  \YAWK\sys::setTimeout($_POST['loginboxRedirect'], 0);
128  }
129  }
130  else
131  { // redirect to inded page (only in html mode)
132  $_GET['include'] = "index";
133  }
134  }
135  }
136  }
137 
138  // URL is set and not empty - lets go, load properties for given page
139  $page->loadProperties($db, $db->quote($_GET['include']));
140 
141  // different GET controller actions can be done here...
142 }
143 else
144 { // if no page is given, set index as default page
145  $_GET['include'] = "index";
146  // and load properties for it
147  $page->loadProperties($db, $db->quote($_GET['include']));
148 }
149 
150 // get global selected template ID
151 $template->id = \YAWK\settings::getSetting($db, "selectedTemplate");
152 $template->selectedTemplate = $template->id;
153 // call template controller
154 if (\YAWK\user::isAnybodyThere($db))
155 { // user seems to be logged in...
156  // load template name from {users}
157  $user->loadProperties($db, $_SESSION['username']);
158  // check if user is allowed to overrule selectedTemplate
159  if ($user->overrideTemplate == true)
160  { // set user template ID to session
161  $_SESSION['userTemplateID'] = $user->templateID;
162  // get template by user templateID
163  $template->name = \YAWK\template::getTemplateNameById($db, $user->templateID);
164  // include page, based on user templateID
165  if(!include("system/templates/$template->name/index.php"))
166  { // if template not exists, show selectedTemplate
167  $templateName = \YAWK\template::getTemplateNameById($db, $template->selectedTemplate);
168  include("system/templates/$template->name/index.php");
169  }
170  }
171  else
172  { // user is not allowed to overrule template, show global default (selectedTemplate) instead.
173  $template->name = \YAWK\template::getTemplateNameById($db, $user->templateID);
174  if(!include("system/templates/$template->name/index.php"))
175  {
176  die("Unable to include template. Either database config is faulty or YaWK is not correctly installed.");
177  }
178  }
179 }
180 else
181 { // user is NOT logged in, load default template (selectedTemplate) from settings db
182  $template->name = \YAWK\template::getTemplateNameById($db, $user->templateID);
183  if(!include("system/templates/$template->name/index.php"))
184  {
185  die("Unable to include template. Either database config is faulty or YaWK is not correctly installed.");
186  }
187 }
print $lang['FILEMAN_UPLOAD']
die
Definition: block-user.php:27
The language class - support multilingual backend.
Definition: language.php:17
static getSetting($db, $property)
Get and return value for property from settings database.
Definition: settings.php:470
static setTimeout($location, $wait)
set a timeout and force page reload via JS
Definition: sys.php:864
exit
This class serves methods to create backup from files.
Definition: AdminLTE.php:2
print $_GET['id']
Definition: page-edit.php:357
$page
Definition: pages.php:355
$signup
Definition: signup.php:10