· 8 years ago · Jul 14, 2018, 06:08 PM
1<?php
2/*
3 * Made by Samerton
4 * https://github.com/NamelessMC/Nameless/
5 * NamelessMC version 2.0.0-pr3
6 *
7 * License: MIT
8 *
9 * Admin core settings page
10 */
11
12// Can the user view the AdminCP?
13if ($user->isLoggedIn()) {
14 if (!$user->canViewACP()) {
15 // No
16 Redirect::to(URL::build('/'));
17 die();
18 } else {
19 // Check the user has re-authenticated
20 if (!$user->isAdmLoggedIn()) {
21 // They haven't, do so now
22 Redirect::to(URL::build('/admin/auth'));
23 die();
24 } else {
25 if (!$user->hasPermission('admincp.core')) {
26 require(ROOT_PATH . '/404.php');
27 die();
28 }
29 }
30 }
31} else {
32 // Not logged in
33 Redirect::to(URL::build('/login'));
34 die();
35}
36
37$page = 'admin';
38$admin_page = 'core';
39
40// Query database for settings
41$current_default_language = $queries->getWhere('settings', array('name', '=', 'language'));
42$current_default_language = $current_default_language[0]->value;
43
44?>
45<!DOCTYPE html>
46<html lang="<?php echo(defined('HTML_LANG') ? HTML_LANG : 'en'); ?>" <?php if (defined('HTML_RTL') && HTML_RTL === true) echo ' dir="rtl"'; ?>>
47<head>
48 <!-- Standard Meta -->
49 <meta charset="<?php echo(defined('LANG_CHARSET') ? LANG_CHARSET : 'utf-8'); ?>">
50 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
51 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
52
53 <?php
54 $title = $language->get('admin', 'admin_cp');
55 require(ROOT_PATH . '/core/templates/admin_header.php');
56 ?>
57
58 <link rel="stylesheet"
59 href="<?php if (defined('CONFIG_PATH')) echo CONFIG_PATH . '/'; else echo '/'; ?>core/assets/plugins/switchery/switchery.min.css">
60 <link rel="stylesheet"
61 href="<?php if (defined('CONFIG_PATH')) echo CONFIG_PATH . '/'; else echo '/'; ?>core/assets/plugins/dropzone/dropzone.min.css">
62 <link rel="stylesheet"
63 href="<?php if (defined('CONFIG_PATH')) echo CONFIG_PATH . '/'; else echo '/'; ?>core/assets/plugins/image-picker/image-picker.css">
64
65 <style type="text/css">
66 .thumbnails li img {
67 width: 60px;
68 }
69 </style>
70
71</head>
72<body>
73<?php require(ROOT_PATH . '/modules/Core/pages/admin/navbar.php'); ?>
74<div class="container">
75 <div class="row">
76 <div class="col-md-3">
77 <?php require(ROOT_PATH . '/modules/Core/pages/admin/sidebar.php'); ?>
78 </div>
79 <div class="col-md-9">
80 <div class="card">
81 <div class="card-block">
82 <h3><?php echo $language->get('admin', 'core'); ?></h3>
83 <?php if (!isset($_GET['view'])) { ?>
84 <div class="table-responsive">
85 <table class="table table-striped">
86 <?php if ($user->hasPermission('admincp.core.general')) { ?>
87 <tr>
88 <td>
89 <a href="<?php echo URL::build('/admin/core/', 'view=general'); ?>"><?php echo $language->get('admin', 'general_settings'); ?></a>
90 </td>
91 </tr>
92 <?php }
93 if ($user->hasPermission('admincp.core.api')) { ?>
94 <tr>
95 <td>
96 <a href="<?php echo URL::build('/admin/api'); ?>"><?php echo $language->get('admin', 'api'); ?></a>
97 </td>
98 </tr>
99 <?php }
100 if ($user->hasPermission('admincp.core.avatars')) { ?>
101 <tr>
102 <td>
103 <a href="<?php echo URL::build('/admin/core/', 'view=avatars'); ?>"><?php echo $language->get('admin', 'avatars'); ?></a>
104 </td>
105 </tr>
106 <?php }
107 if ($user->hasPermission('admincp.core.fields')) { ?>
108 <tr>
109 <td>
110 <a href="<?php echo URL::build('/admin/core/', 'view=profile'); ?>"><?php echo $language->get('admin', 'custom_fields'); ?></a>
111 </td>
112 </tr>
113 <?php }
114 if ($user->hasPermission('admincp.core.debugging')) { ?>
115 <tr>
116 <td>
117 <a href="<?php echo URL::build('/admin/core/', 'view=maintenance'); ?>"><?php echo $language->get('admin', 'debugging_and_maintenance'); ?></a>
118 </td>
119 </tr>
120 <?php }
121 if ($user->hasPermission('admincp.core.emails')) { ?>
122 <tr>
123 <td>
124 <a href="<?php echo URL::build('/admin/core/', 'view=email'); ?>"><?php echo $language->get('admin', 'emails'); ?></a>
125 </td>
126 </tr>
127 <?php }
128 if ($user->hasPermission('admincp.core.navigation')) { ?>
129 <tr>
130 <td>
131 <a href="<?php echo URL::build('/admin/core/', 'view=navigation'); ?>"><?php echo $language->get('admin', 'navigation'); ?></a>
132 </td>
133 </tr>
134 <?php }
135 if ($user->hasPermission('admincp.core.terms')) { ?>
136 <tr>
137 <td>
138 <a href="<?php echo URL::build('/admin/core/', 'view=terms'); ?>"><?php echo $language->get('admin', 'privacy_and_terms'); ?></a>
139 </td>
140 </tr>
141 <?php }
142 if ($user->hasPermission('admincp.core.reactions')) { ?>
143 <tr>
144 <td>
145 <a href="<?php echo URL::build('/admin/core/', 'view=reactions'); ?>"><?php echo $language->get('user', 'reactions'); ?></a>
146 </td>
147 </tr>
148 <?php }
149 if ($user->hasPermission('admincp.core.registration')) { ?>
150 <tr>
151 <td>
152 <a href="<?php echo URL::build('/admin/registration'); ?>"><?php echo $language->get('admin', 'registration'); ?></a>
153 </td>
154 </tr>
155 <?php }
156 if ($user->hasPermission('admincp.core.social_media')) { ?>
157 <tr>
158 <td>
159 <a href="<?php echo URL::build('/admin/core/', 'view=social'); ?>"><?php echo $language->get('admin', 'social_media'); ?></a>
160 </td>
161 </tr>
162 <?php } ?>
163 </table>
164 </div>
165 <?php
166 } else {
167 switch ($_GET['view']) {
168 case 'general':
169 if (!$user->hasPermission('admincp.core.general')) {
170 Redirect::to(URL::build('/admin/core'));
171 die();
172 }
173 if (isset($_GET['do']) && $_GET['do'] == 'installLanguage') {
174 // Install new language
175 $languages = glob('custom' . DIRECTORY_SEPARATOR . 'languages' . DIRECTORY_SEPARATOR . '*', GLOB_ONLYDIR);
176 foreach ($languages as $item) {
177 $folders = explode(DIRECTORY_SEPARATOR, $item);
178
179 // Is it already in the database?
180 $exists = $queries->getWhere('languages', array('name', '=', Output::getClean($folders[2])));
181 if (!count($exists)) {
182 // No, add it now
183 $queries->create('languages', array(
184 'name' => Output::getClean($folders[2])
185 ));
186 }
187 }
188
189 Session::flash('general_language', $language->get('admin', 'installed_languages'));
190 Redirect::to(URL::build('/admin/core/', 'view=general'));
191 die();
192 }
193
194 // Deal with input
195 if (Input::exists()) {
196 if (Token::check(Input::get('token'))) {
197 // Validate input
198 $validate = new Validate();
199
200 $validation = $validate->check($_POST, array(
201 'sitename' => array(
202 'required' => true,
203 'min' => 2,
204 'max' => 64
205 ),
206 'contact_email' => array(
207 'required' => true,
208 'min' => 3,
209 'max' => 255
210 )
211 ));
212
213 if ($validation->passed()) {
214 // Update settings
215 // Sitename
216 $sitename_id = $queries->getWhere('settings', array('name', '=', 'sitename'));
217 $sitename_id = $sitename_id[0]->id;
218
219 $queries->update('settings', $sitename_id, array(
220 'value' => Output::getClean(Input::get('sitename'))
221 ));
222
223 // Update cache
224 $cache->setCache('sitenamecache');
225 $cache->store('sitename', Output::getClean(Input::get('sitename')));
226
227 // Email address
228 $contact_id = $queries->getWhere('settings', array('name', '=', 'incoming_email'));
229 $contact_id = $contact_id[0]->id;
230
231 $queries->update('settings', $contact_id, array(
232 'value' => Output::getClean(Input::get('contact_email'))
233 ));
234
235 // Language
236 // Get current default language
237 $default_language = $queries->getWhere('languages', array('is_default', '=', 1));
238 $default_language = $default_language[0];
239
240 if ($default_language->name != Input::get('language')) {
241 // The default language has been changed
242 $queries->update('languages', $default_language->id, array(
243 'is_default' => 0
244 ));
245
246 $language_id = $queries->getWhere('languages', array('id', '=', Input::get('language')));
247 $language_name = Output::getClean($language_id[0]->name);
248 $language_id = $language_id[0]->id;
249
250 $queries->update('languages', $language_id, array(
251 'is_default' => 1
252 ));
253
254 // Update cache
255 $cache->setCache('languagecache');
256 $cache->store('language', $language_name);
257 }
258
259 // Timezone
260 $timezone_id = $queries->getWhere('settings', array('name', '=', 'timezone'));
261 $timezone_id = $timezone_id[0]->id;
262
263 try {
264 $queries->update('settings', $timezone_id, array(
265 'value' => Output::getClean($_POST['timezone'])
266 ));
267
268 // Cache
269 $cache->setCache('timezone_cache');
270 $cache->store('timezone', Output::getClean($_POST['timezone']));
271
272 } catch (Exception $e) {
273 $errors = array($e->getMessage());
274 }
275
276 // Portal
277 $portal_id = $queries->getWhere('settings', array('name', '=', 'portal'));
278 $portal_id = $portal_id[0]->id;
279
280 if ($_POST['homepage'] == 'portal') {
281 $use_portal = 1;
282 } else $use_portal = 0;
283
284 $queries->update('settings', $portal_id, array(
285 'value' => $use_portal
286 ));
287
288 // Update cache
289 $cache->setCache('portal_cache');
290 $cache->store('portal', $use_portal);
291
292 // Private profile
293 $private_profile_id = $queries->getWhere('settings', array('name', '=', 'private_profile'));
294 $private_profile_id = $private_profile_id[0]->id;
295
296 if ($_POST['privateProfile'])
297 $private_profile = 1;
298 else
299 $private_profile = 0;
300
301 $queries->update('settings', $private_profile_id, array(
302 'value' => $private_profile
303 ));
304
305 // Registration displaynames
306 $displaynames_id = $queries->getWhere('settings', array('name', '=', 'displaynames'));
307 $displaynames_id = $displaynames_id[0]->id;
308
309 $queries->update('settings', $displaynames_id, array(
310 'value' => $_POST['displaynames']
311 ));
312
313 // Post formatting
314 $formatting_id = $queries->getWhere('settings', array('name', '=', 'formatting_type'));
315 $formatting_id = $formatting_id[0]->id;
316
317 $queries->update('settings', $formatting_id, array(
318 'value' => Output::getClean(Input::get('formatting'))
319 ));
320
321 // Update cache
322 $cache->setCache('post_formatting');
323 $cache->store('formatting', Output::getClean(Input::get('formatting')));
324
325 // Friendly URLs
326 if (Input::get('friendlyURL') == 'true') $friendly = true;
327 else $friendly = false;
328
329 if (is_writable(ROOT_PATH . '/' . join(DIRECTORY_SEPARATOR, array('core', 'config.php')))) {
330
331 // Require config
332 if (isset($path) && file_exists($path . 'core/config.php')) {
333 $loadedConfig = json_decode(file_get_contents($path . 'core/config.php'), true);
334 } else {
335 $loadedConfig = json_decode(file_get_contents(ROOT_PATH . '/core/config.php'), true);
336 }
337
338 if (is_array($loadedConfig)) {
339 $GLOBALS['config'] = $loadedConfig;
340 }
341
342 // Make string to input
343 Config::set('core/friendly', $friendly);
344
345 } else $errors = array($language->get('admin', 'config_not_writable'));
346
347 // Force HTTPS?
348 if (Input::get('forceHTTPS') == 'true')
349 $https = 'true';
350 else
351 $https = 'false';
352
353 $force_https_id = $queries->getWhere('settings', array('name', '=', 'force_https'));
354 if (count($force_https_id)) {
355 $force_https_id = $force_https_id[0]->id;
356 $queries->update('settings', $force_https_id, array(
357 'value' => $https
358 ));
359 } else {
360 $queries->create('settings', array(
361 'name' => 'force_https',
362 'value' => $https
363 ));
364 }
365
366 // Force WWW?
367 if (Input::get('forceWWW') == 'true')
368 $www = 'true';
369 else
370 $www = 'false';
371
372 $force_www_id = $queries->getWhere('settings', array('name', '=', 'force_www'));
373 if (count($force_www_id)) {
374 $force_www_id = $force_www_id[0]->id;
375 $queries->update('settings', $force_www_id, array(
376 'value' => $www
377 ));
378 } else {
379 $queries->create('settings', array(
380 'name' => 'force_www',
381 'value' => $www
382 ));
383 }
384
385 /*
386 if(!empty($_POST["allowedProxies"])) {
387 $allowedProxies = $_POST["allowedProxies"];
388 $allowedProxies = str_replace("\r", "", $allowedProxies);
389 $allowedProxies = preg_replace('/\s+/', ' ', $allowedProxies);
390 $allowedProxies = str_replace(" ", "", $allowedProxies);
391
392 Config::set("allowedProxies", $allowedProxies);
393 }else {
394 Config::set("allowedProxies", "");
395 }
396 */
397
398 // Login method
399 $login_method_id = $queries->getWhere('settings', array('name', '=', 'login_method'));
400 $login_method_id = $login_method_id[0]->id;
401
402 $queries->update('settings', $login_method_id, array(
403 'value' => $_POST['login_method']
404 ));
405
406 Log::getInstance()->log(Log::Action('admin/core/general'));
407
408 // Update cache
409 $cache->setCache('force_https_cache');
410 $cache->store('force_https', $https);
411
412 $cache->setCache('force_www_cache');
413 $cache->store('force_www', $www);
414
415 // Redirect in case URL type has changed
416 if (!isset($errors)) {
417 if ($friendly == 'true') {
418 $redirect = URL::build('/admin/core', 'view=general', 'friendly');
419 } else {
420 $redirect = URL::build('/admin/core', 'view=general', 'non-friendly');
421 }
422 Redirect::to($redirect);
423 die();
424 }
425
426 } else $errors = array($language->get('admin', 'missing_sitename'));
427 } else {
428 // Invalid token
429 $errors = array($language->get('general', 'invalid_token'));
430 }
431 }
432 ?>
433 <form action="" method="post">
434 <?php if (Session::exists('general_language')) { ?>
435 <div class="alert alert-success"><?php echo Session::flash('general_language'); ?></div><?php } ?>
436 <?php if (isset($errors)) { ?>
437 <div class="alert alert-danger"><?php foreach ($errors as $error) echo $error; ?></div><?php } ?>
438 <div class="form-group">
439 <?php
440 // Get site name
441 $sitename = $queries->getWhere('settings', array('name', '=', 'sitename'));
442 $sitename = $sitename[0];
443 ?>
444 <label for="inputSitename"><?php echo $language->get('admin', 'sitename'); ?></label>
445 <input type="text" class="form-control" name="sitename" id="inputSitename"
446 value="<?php echo Output::getClean($sitename->value); ?>"/>
447 </div>
448 <div class="form-group">
449 <?php
450 // Get contact email address
451 $contact_email = $queries->getWhere('settings', array('name', '=', 'incoming_email'));
452 $contact_email = $contact_email[0];
453 ?>
454 <label for="inputContactEmail"><?php echo $language->get('admin', 'contact_email_address'); ?></label>
455 <input type="text" class="form-control" name="contact_email"
456 id="inputContactEmail"
457 value="<?php echo Output::getClean($contact_email->value); ?>"/>
458 </div>
459 <div class="form-group">
460 <label for="inputLanguage"><?php echo $language->get('admin', 'default_language'); ?></label>
461 <span class="badge badge-info"><i class="fa fa-question" data-container="body"
462 data-toggle="popover" data-placement="top"
463 title="<?php echo $language->get('general', 'info'); ?>"
464 data-content="<?php echo $language->get('admin', 'default_language_help'); ?>"></i></span>
465 <div class="input-group">
466 <?php
467 // Get languages
468 $languages = $queries->getWhere('languages', array('id', '<>', 0));
469 ?>
470 <select name="language" class="form-control" id="inputLanguage">
471 <?php
472 foreach ($languages as $item) {
473 ?>
474 <option value="<?php echo $item->id; ?>"<?php if ($item->is_default == 1) { ?> selected<?php } ?>><?php echo Output::getClean($item->name); ?></option>
475 <?php
476 }
477 ?>
478 </select>
479 <div class="input-group-btn">
480 <a class="btn btn-secondary"
481 href="<?php echo URL::build('/admin/core/', 'view=general&do=installLanguage'); ?>"><i
482 class="fa fa-plus-circle"></i></a>
483 </div>
484 </div>
485 </div>
486 <div class="form-group">
487 <label for="inputTimezone"><?php echo $language->get('admin', 'default_timezone'); ?></label>
488 <?php
489 // Get timezone setting
490 $timezone = $queries->getWhere('settings', array('name', '=', 'timezone'));
491 $timezone = $timezone[0];
492 ?>
493 <select name="timezone" class="form-control" id="inputTimezone">
494 <?php foreach (Util::listTimezones() as $key => $item) { ?>
495 <option value="<?php echo $key; ?>"<?php if ($timezone->value == $key) { ?> selected<?php } ?>>
496 (<?php echo $item['offset']; ?>) - <?php echo $item['name']; ?>
497 (<?php echo $item['time']; ?>)
498 </option>
499 <?php } ?>
500 </select>
501 </div>
502 <div class="form-group">
503 <label for="inputHomepage"><?php echo $language->get('admin', 'homepage_type'); ?></label>
504 <?php
505 // Get portal setting
506 $portal = $queries->getWhere('settings', array('name', '=', 'portal'));
507 $portal = $portal[0];
508 ?>
509 <select name="homepage" class="form-control" id="inputHomepage">
510 <option value="default"<?php if ($portal->value == 0) { ?> selected<?php } ?>><?php echo $language->get('admin', 'default'); ?></option>
511 <option value="portal"<?php if ($portal->value == 1) { ?> selected<?php } ?>><?php echo $language->get('admin', 'portal'); ?></option>
512 </select>
513 </div>
514 <div class="form-group">
515 <?php
516 // Get post formatting setting
517 $cache->setCache('post_formatting');
518 $formatting = $cache->retrieve('formatting');
519 ?>
520 <label for="inputFormatting"><?php echo $language->get('admin', 'post_formatting_type'); ?></label>
521 <select name="formatting" class="form-control" id="inputFormatting">
522 <option value="html"<?php if ($formatting == 'html') { ?> selected<?php } ?>>
523 HTML
524 </option>
525 <option value="markdown"<?php if ($formatting == 'markdown') { ?> selected<?php } ?>>
526 Markdown
527 </option>
528 </select>
529 </div>
530 <div class="form-group">
531 <?php
532 // Get friendly URL setting
533 $friendly_url = Config::get('core/friendly');
534 ?>
535 <label for="inputFriendlyURL"><?php echo $language->get('admin', 'use_friendly_urls'); ?></label>
536 <span class="badge badge-info"><i class="fa fa-question" data-container="body"
537 data-toggle="popover" data-placement="top"
538 title="<?php echo $language->get('general', 'info'); ?>"
539 data-content="<?php echo $language->get('admin', 'use_friendly_urls_help'); ?>"></i></span>
540 <select name="friendlyURL" class="form-control" id="inputFriendlyURL">
541 <option value="true"<?php if ($friendly_url == true) { ?> selected<?php } ?>><?php echo $language->get('admin', 'enabled'); ?></option>
542 <option value="false"<?php if ($friendly_url == false) { ?> selected<?php } ?>><?php echo $language->get('admin', 'disabled'); ?></option>
543 </select>
544 </div>
545 <div class="form-group">
546 <?php
547 // Get force SSL setting
548 if (defined('FORCE_SSL'))
549 $force_https = true;
550 else
551 $force_https = false;
552 ?>
553 <label for="inputForceHTTPS"><?php echo $language->get('admin', 'force_https'); ?></label>
554 <span class="badge badge-info"><i class="fa fa-question" data-container="body"
555 data-toggle="popover" data-placement="top"
556 title="<?php echo $language->get('general', 'info'); ?>"
557 data-content="<?php echo $language->get('admin', 'force_https_help'); ?>"></i></span>
558 <select name="forceHTTPS" class="form-control" id="inputForceHTTPS">
559 <option value="true"<?php if ($force_https) { ?> selected<?php } ?>><?php echo $language->get('admin', 'enabled'); ?></option>
560 <option value="false"<?php if (!$force_https) { ?> selected<?php } ?>><?php echo $language->get('admin', 'disabled'); ?></option>
561 </select>
562 </div>
563 <div class="form-group">
564 <?php
565 // Get force WWW setting
566 if (defined('FORCE_WWW'))
567 $force_www = true;
568 else
569 $force_www = false;
570 ?>
571 <label for="inputForceWWW"><?php echo $language->get('admin', 'force_www'); ?></label>
572 <select name="forceWWW" class="form-control" id="inputForceWWW">
573 <option value="true"<?php if ($force_www) { ?> selected<?php } ?>><?php echo $language->get('admin', 'enabled'); ?></option>
574 <option value="false"<?php if (!$force_www) { ?> selected<?php } ?>><?php echo $language->get('admin', 'disabled'); ?></option>
575 </select>
576 </div>
577 <div class="form-group">
578 <label for="inputPrivateProfile"><?php echo $language->get('user', 'private_profile'); ?></label>
579 <?php
580 // Get private profile settings
581 $private_profile = $queries->getWhere('settings', array('name', '=', 'private_profile'));
582 $private_profile = $private_profile[0];
583 ?>
584 <select name="privateProfile" class="form-control" id="inputPrivateProfile">
585 <option value="1"<?php if ($private_profile->value == 1) { ?> selected<?php } ?>><?php echo $language->get('admin', 'enabled'); ?></option>
586 <option value="0"<?php if ($private_profile->value == 0) { ?> selected<?php } ?>><?php echo $language->get('admin', 'disabled'); ?></option>
587 </select>
588 </div>
589 <div class="form-group">
590 <label for="inputEnableNicknames"><?php echo $language->get('admin', 'enable_nicknames_on_registration'); ?></label>
591 <?php
592 // Get nickname setting
593 $displaynames = $queries->getWhere('settings', array('name', '=', 'displaynames'));
594 $displaynames = $displaynames[0];
595 ?>
596 <select name="displaynames" class="form-control" id="inputEnableNicknames">
597 <option value="true"<?php if ($displaynames->value == "true") { ?> selected<?php } ?>><?php echo $language->get('admin', 'enabled'); ?></option>
598 <option value="false"<?php if ($displaynames->value == "false") { ?> selected<?php } ?>><?php echo $language->get('admin', 'disabled'); ?></option>
599 </select>
600 </div>
601 <div class="form-group">
602 <label for="inputLoginMethod"><?php echo $language->get('admin', 'login_method'); ?></label>
603 <?php
604 // Get login method
605 $method = $queries->getWhere('settings', array('name', '=', 'login_method'));
606 $method = $method[0];
607 ?>
608 <select name="login_method" class="form-control" id="inputLoginMethod">
609 <option value="email"<?php if ($method->value == "email") { ?> selected<?php } ?>><?php echo $language->get('user', 'email'); ?></option>
610 <option value="username"<?php if ($method->value == "username") { ?> selected<?php } ?>><?php echo $language->get('user', 'username'); ?></option>
611 </select>
612 </div>
613 <!--
614 <div class="form-group">
615 <label for=allowedProxies"><?php echo $language->get('admin', 'allowed_proxies'); ?></label>
616 <?php
617 // Make sure there's a default list
618 $allowedProxies = Config::get("allowedProxies");
619 $allowedProxies = str_replace(",", "\n", $allowedProxies)
620 ?>
621 <textarea class="form-control" placeholder="<?php echo $language->get('admin', 'allowed_proxies_info'); ?>" name="allowedProxies" id="allowedProxies" cols="30" rows="10"><?php
622 echo $allowedProxies;
623 ?></textarea>
624 </div>
625 -->
626 <br/>
627 <input type="hidden" name="token" value="<?php echo Token::get(); ?>">
628 <input type="submit" class="btn btn-primary"
629 value="<?php echo $language->get('general', 'submit'); ?>">
630 </form>
631 <?php
632 break;
633
634 case 'profile':
635 if (!$user->hasPermission('admincp.core.fields')) {
636 Redirect::to(URL::build('/admin/core'));
637 die();
638 }
639 if (!isset($_GET['id']) && !isset($_GET['action'])) {
640 // Custom profile fields
641 $profile_fields = $queries->getWhere('profile_fields', array('id', '<>', 0));
642 ?>
643 <h4 style="display:inline;"><?php echo $language->get('admin', 'custom_fields'); ?></h4>
644 <span class="pull-right">
645 <a class="btn btn-primary"
646 href="<?php echo URL::build('/admin/core/', 'view=profile&action=new'); ?>"><?php echo $language->get('admin', 'new_field'); ?></a>
647 </span>
648 <br/><br/>
649 <?php if (count($profile_fields)) { ?>
650 <table class="table">
651 <thead>
652 <tr>
653 <th><?php echo $language->get('admin', 'field_name'); ?></th>
654 <th><?php echo $language->get('admin', 'type'); ?></th>
655 <th><?php echo $language->get('admin', 'required'); ?></th>
656 <th><?php echo $language->get('admin', 'editable'); ?></th>
657 <th><?php echo $language->get('admin', 'public'); ?></th>
658 </tr>
659 </thead>
660 <tbody>
661 <?php
662 foreach ($profile_fields as $field) {
663 ?>
664 <tr>
665 <td>
666 <a href="<?php echo URL::build('/admin/core/', 'view=profile&id=' . $field->id); ?>"><?php echo Output::getClean($field->name); ?></a>
667 </td>
668 <td><?php
669 switch ($field->type) {
670 case 1:
671 // Text field
672 echo $language->get('admin', 'text');
673 break;
674 case 2:
675 // Textarea
676 echo $language->get('admin', 'textarea');
677 break;
678 case 3:
679 // Date
680 echo $language->get('admin', 'date');
681 break;
682 } ?></td>
683 <td><?php
684 if ($field->required == 1) echo '<i class="fa fa-check-circle-o" aria-hidden="true"></i>';
685 else echo '<i class="fa fa-times-circle-o" aria-hidden="true"></i>';
686 ?></td>
687 <td><?php
688 if ($field->editable == 1) echo '<i class="fa fa-check-circle-o" aria-hidden="true"></i>';
689 else echo '<i class="fa fa-times-circle-o" aria-hidden="true"></i>';
690 ?></td>
691 <td><?php
692 if ($field->public == 1) echo '<i class="fa fa-check-circle-o" aria-hidden="true"></i>';
693 else echo '<i class="fa fa-times-circle-o" aria-hidden="true"></i>';
694 ?></td>
695 </tr>
696 <?php
697 }
698 ?>
699 </tbody>
700 </table>
701 <?php
702 } else {
703 echo '<div class="alert alert-info">' . $language->get('admin', 'no_custom_fields') . '</div>';
704 }
705 } else {
706 if (isset($_GET['action'])) {
707 if ($_GET['action'] == 'new') {
708 // New field
709 if (Input::exists()) {
710 if (Token::check(Input::get('token'))) {
711 // Validate input
712 $validate = new Validate();
713
714 $validation = $validate->check($_POST, array(
715 'name' => array(
716 'required' => true,
717 'min' => 2,
718 'max' => 16
719 ),
720 'type' => array(
721 'required' => true
722 )
723 ));
724
725 if ($validation->passed()) {
726 // Input into database
727 try {
728 // Get whether required/public/editable/forum post options are enabled or not
729 if (isset($_POST['required']) && $_POST['required'] == 'on') $required = 1;
730 else $required = 0;
731
732 if (isset($_POST['public']) && $_POST['public'] == 'on') $public = 1;
733 else $public = 0;
734
735 if (isset($_POST['forum']) && $_POST['forum'] == 'on') $forum_posts = 1;
736 else $forum_posts = 0;
737
738 if (isset($_POST['editable']) && $_POST['editable'] == 'on') $editable = 1;
739 else $editable = 0;
740
741 // Insert into database
742 $queries->create('profile_fields', array(
743 'name' => Output::getClean(Input::get('name')),
744 'type' => Input::get('type'),
745 'public' => $public,
746 'required' => $required,
747 'description' => Output::getClean(Input::get('description')),
748 'forum_posts' => $forum_posts,
749 'editable' => $editable
750 ));
751
752 Log::getInstance()->log(Log::Action('admin/core/profile/new'), Output::getClean(Input::get('name')));
753
754 // Redirect
755 Redirect::to(URL::build('/admin/core/', 'view=profile'));
756 die();
757
758 } catch (Exception $e) {
759 $error = $e->getMessage();
760 }
761
762 } else {
763 // Display errors
764 $error = $language->get('admin', 'profile_field_error');
765 }
766 } else {
767 // Invalid token
768 $error = $language->get('admin', 'invalid_token');
769 }
770 }
771
772 ?>
773 <h4 style="display:inline;"><?php echo $language->get('admin', 'creating_profile_field'); ?></h4>
774 <span class="pull-right">
775 <a class="btn btn-danger"
776 href="<?php echo URL::build('/admin/core/', 'view=profile'); ?>"
777 onclick="return confirm('<?php echo $language->get('general', 'confirm_cancel'); ?>');"><?php echo $language->get('general', 'cancel'); ?></a>
778 </span>
779 <br/><br/>
780 <?php if (isset($error)) echo '<div class="alert alert-danger">' . $error . '</div>'; ?>
781 <form action="" method="post">
782 <div class="form-group">
783 <label for="inputName"><?php echo $language->get('admin', 'field_name'); ?></label>
784 <input type="text" name="name" id="inputName" class="form-control"
785 placeholder="<?php echo $language->get('admin', 'field_name'); ?>">
786 </div>
787
788 <div class="form-group">
789 <label for="inputType"><?php echo $language->get('admin', 'type'); ?></label>
790 <select class="form-control" name="type" id="inputType">
791 <option value="1"><?php echo $language->get('admin', 'text'); ?></option>
792 <option value="2"><?php echo $language->get('admin', 'textarea'); ?></option>
793 <option value="3"><?php echo $language->get('admin', 'date'); ?></option>
794 </select>
795 </div>
796
797 <div class="form-group">
798 <label for="inputDescription"><?php echo $language->get('admin', 'description'); ?></label>
799 <textarea id="inputDescription" name="description"
800 class="form-control"></textarea>
801 </div>
802
803 <div class="form-group">
804 <label for="inputRequired"><?php echo $language->get('admin', 'required'); ?></label>
805 <span class="badge badge-info"><i class="fa fa-question"
806 data-container="body"
807 data-toggle="popover"
808 data-placement="top"
809 title="<?php echo $language->get('general', 'info'); ?>"
810 data-content="<?php echo $language->get('admin', 'profile_field_required_help'); ?>"></i></span>
811 <input type="checkbox" id="inputRequired" name="required"
812 class="js-switch"/>
813 </div>
814
815 <div class="form-group">
816 <label for="inputEditable"><?php echo $language->get('admin', 'editable'); ?></label>
817 <span class="badge badge-info"><i class="fa fa-question"
818 data-container="body"
819 data-toggle="popover"
820 data-placement="top"
821 title="<?php echo $language->get('general', 'info'); ?>"
822 data-content="<?php echo $language->get('admin', 'profile_field_editable_help'); ?>"></i></span>
823 <input type="checkbox" id="inputEditable" name="editable"
824 class="js-switch"/>
825 </div>
826
827 <div class="form-group">
828 <label for="inputPublic"><?php echo $language->get('admin', 'public'); ?></label>
829 <span class="badge badge-info"><i class="fa fa-question"
830 data-container="body"
831 data-toggle="popover"
832 data-placement="top"
833 title="<?php echo $language->get('general', 'info'); ?>"
834 data-content="<?php echo $language->get('admin', 'profile_field_public_help'); ?>"></i></span>
835 <input type="checkbox" id="inputPublic" name="public"
836 class="js-switch"/>
837 </div>
838
839 <div class="form-group">
840 <label for="inputForum"><?php echo $language->get('admin', 'display_field_on_forum'); ?></label>
841 <span class="badge badge-info"><i class="fa fa-question"
842 data-container="body"
843 data-toggle="popover"
844 data-placement="top"
845 title="<?php echo $language->get('general', 'info'); ?>"
846 data-content="<?php echo $language->get('admin', 'profile_field_forum_help'); ?>"></i></span>
847 <input type="checkbox" id="inputForum" name="forum"
848 class="js-switch"/>
849 </div>
850
851 <div class="form-group">
852 <input type="hidden" name="token"
853 value="<?php echo Token::get(); ?>">
854 <input type="submit" class="btn btn-primary"
855 value="<?php echo $language->get('general', 'submit'); ?>">
856 </div>
857 </form>
858 <?php
859 } else if ($_GET['action'] == 'delete') {
860 // Delete field
861 if (isset($_GET['id'])) {
862 $queries->delete('profile_fields', array('id', '=', $_GET['id']));
863 Log::getInstance()->log(Log::Action('admin/core/profile/delete'), Output::getClean($_GET['id']));
864 }
865
866 Redirect::to(URL::build('/admin/core/', 'view=profile'));
867 die();
868 }
869 } else if (isset($_GET['id']) && !isset($_GET['action'])) {
870 // Editing field
871
872 // Ensure field actually exists
873 if (!is_numeric($_GET['id'])) {
874 Redirect::to(URL::build('/admin/core/', 'view=profile'));
875 die();
876 }
877
878 $field = $queries->getWhere('profile_fields', array('id', '=', $_GET['id']));
879 if (!count($field)) {
880 Redirect::to(URL::build('/admin/core/', 'view=profile'));
881 die();
882 }
883
884 $field = $field[0];
885
886 if (Input::exists()) {
887 if (Token::check(Input::get('token'))) {
888 // Validate input
889 $validate = new Validate();
890
891 $validation = $validate->check($_POST, array(
892 'name' => array(
893 'required' => true,
894 'min' => 2,
895 'max' => 16
896 ),
897 'type' => array(
898 'required' => true
899 )
900 ));
901
902 if ($validation->passed()) {
903 // Update database
904 try {
905 // Get whether required/public/editable/forum post options are enabled or not
906 if (isset($_POST['required']) && $_POST['required'] == 'on') $required = 1;
907 else $required = 0;
908
909 if (isset($_POST['public']) && $_POST['public'] == 'on') $public = 1;
910 else $public = 0;
911
912 if (isset($_POST['forum']) && $_POST['forum'] == 'on') $forum_posts = 1;
913 else $forum_posts = 0;
914
915 if (isset($_POST['editable']) && $_POST['editable'] == 'on') $editable = 1;
916 else $editable = 0;
917
918 // Update database
919 $queries->update('profile_fields', $field->id, array(
920 'name' => Output::getClean(Input::get('name')),
921 'type' => Input::get('type'),
922 'public' => $public,
923 'required' => $required,
924 'description' => Output::getClean(Input::get('description')),
925 'forum_posts' => $forum_posts,
926 'editable' => $editable
927 ));
928
929 Log::getInstance()->log(Log::Action('admin/core/profile/update'), Output::getClean(Input::get('name')));
930
931 // Redirect
932 Redirect::to(URL::build('/admin/core/', 'view=profile'));
933 die();
934
935 } catch (Exception $e) {
936 $error = $e->getMessage();
937 }
938 } else {
939 // Error
940 $error = $language->get('admin', 'profile_field_error');
941 }
942
943 } else {
944 $error = $language->get('admin', 'invalid_token');
945 }
946 }
947
948 // Generate form token
949 $token = Token::get();
950
951 ?>
952 <h4 style="display:inline;"><?php echo $language->get('admin', 'editing_profile_field'); ?></h4>
953 <span class="pull-right">
954 <a class="btn btn-warning"
955 href="<?php echo URL::build('/admin/core/', 'view=profile'); ?>"
956 onclick="return confirm('<?php echo $language->get('general', 'confirm_cancel'); ?>');"><?php echo $language->get('general', 'cancel'); ?></a>
957 <a class="btn btn-danger"
958 href="<?php echo URL::build('/admin/core/', 'view=profile&action=delete&id=' . $field->id); ?>"
959 onclick="return confirm('<?php echo $language->get('general', 'confirm_deletion'); ?>');"><?php echo $language->get('general', 'delete'); ?></a>
960 </span>
961 <br/><br/>
962 <?php if (isset($error)) echo '<div class="alert alert-danger">' . $error . '</div>'; ?>
963 <form action="" method="post">
964 <div class="form-group">
965 <label for="inputName"><?php echo $language->get('admin', 'field_name'); ?></label>
966 <input type="text" name="name" id="inputName" class="form-control"
967 placeholder="<?php echo $language->get('admin', 'field_name'); ?>"
968 value="<?php echo Output::getClean($field->name); ?>">
969 </div>
970
971 <div class="form-group">
972 <label for="inputType"><?php echo $language->get('admin', 'type'); ?></label>
973 <select class="form-control" name="type" id="inputType">
974 <option value="1"<?php if ($field->type == 1) echo ' selected'; ?>><?php echo $language->get('admin', 'text'); ?></option>
975 <option value="2"<?php if ($field->type == 2) echo ' selected'; ?>><?php echo $language->get('admin', 'textarea'); ?></option>
976 <option value="3"<?php if ($field->type == 3) echo ' selected'; ?>><?php echo $language->get('admin', 'date'); ?></option>
977 </select>
978 </div>
979
980 <div class="form-group">
981 <label for="inputDescription"><?php echo $language->get('admin', 'description'); ?></label>
982 <textarea id="inputDescription" name="description"
983 class="form-control"><?php echo Output::getPurified($field->description); ?></textarea>
984 </div>
985
986 <div class="form-group">
987 <label for="inputRequired"><?php echo $language->get('admin', 'required'); ?></label>
988 <span class="badge badge-info"><i class="fa fa-question"
989 data-container="body"
990 data-toggle="popover"
991 data-placement="top"
992 title="<?php echo $language->get('general', 'info'); ?>"
993 data-content="<?php echo $language->get('admin', 'profile_field_required_help'); ?>"></i></span>
994 <input type="checkbox" id="inputRequired" name="required"
995 class="js-switch" <?php if ($field->required == 1) echo ' checked'; ?>/>
996 </div>
997
998 <div class="form-group">
999 <label for="inputEditable"><?php echo $language->get('admin', 'editable'); ?></label>
1000 <span class="badge badge-info"><i class="fa fa-question"
1001 data-container="body"
1002 data-toggle="popover"
1003 data-placement="top"
1004 title="<?php echo $language->get('general', 'info'); ?>"
1005 data-content="<?php echo $language->get('admin', 'profile_field_editable_help'); ?>"></i></span>
1006 <input type="checkbox" id="inputEditable" name="editable"
1007 class="js-switch" <?php if ($field->editable == 1) echo ' checked'; ?>/>
1008 </div>
1009
1010 <div class="form-group">
1011 <label for="inputPublic"><?php echo $language->get('admin', 'public'); ?></label>
1012 <span class="badge badge-info"><i class="fa fa-question"
1013 data-container="body"
1014 data-toggle="popover"
1015 data-placement="top"
1016 title="<?php echo $language->get('general', 'info'); ?>"
1017 data-content="<?php echo $language->get('admin', 'profile_field_public_help'); ?>"></i></span>
1018 <input type="checkbox" id="inputPublic" name="public"
1019 class="js-switch" <?php if ($field->public == 1) echo ' checked'; ?>/>
1020 </div>
1021
1022 <div class="form-group">
1023 <label for="inputForum"><?php echo $language->get('admin', 'display_field_on_forum'); ?></label>
1024 <span class="badge badge-info"><i class="fa fa-question"
1025 data-container="body"
1026 data-toggle="popover"
1027 data-placement="top"
1028 title="<?php echo $language->get('general', 'info'); ?>"
1029 data-content="<?php echo $language->get('admin', 'profile_field_forum_help'); ?>"></i></span>
1030 <input type="checkbox" id="inputForum" name="forum"
1031 class="js-switch" <?php if ($field->forum_posts == 1) echo ' checked'; ?>/>
1032 </div>
1033
1034 <div class="form-group">
1035 <input type="hidden" name="token" value="<?php echo $token; ?>">
1036 <input type="submit" class="btn btn-primary"
1037 value="<?php echo $language->get('general', 'submit'); ?>">
1038 </div>
1039 </form>
1040 <?php
1041 }
1042 }
1043 break;
1044
1045 case 'reactions':
1046 if (!$user->hasPermission('admincp.core.reactions')) {
1047 Redirect::to(URL::build('/admin/core'));
1048 die();
1049 }
1050 if (!isset($_GET['id']) && (!isset($_GET['action']))) {
1051 // Get all reactions
1052 $reactions = $queries->getWhere('reactions', array('id', '<>', 0));
1053 ?>
1054 <h4 style="display:inline;"><?php echo $language->get('user', 'reactions'); ?></h4>
1055 <span class="pull-right">
1056 <a class="btn btn-primary"
1057 href="<?php echo URL::build('/admin/core/', 'view=reactions&action=new'); ?>"><?php echo $language->get('admin', 'new_reaction'); ?></a>
1058 </span>
1059 <br/><br/>
1060 <table class="table">
1061 <thead>
1062 <tr>
1063 <th><?php echo $language->get('admin', 'name'); ?></th>
1064 <th><?php echo $language->get('admin', 'icon'); ?></th>
1065 <th><?php echo $language->get('admin', 'type'); ?></th>
1066 <th><?php echo $language->get('admin', 'enabled'); ?></th>
1067 </tr>
1068 </thead>
1069 <tbody>
1070 <?php
1071 if (count($reactions)){
1072 foreach ($reactions
1073
1074 as $reaction){
1075 ?>
1076 <tr>
1077 <td>
1078 <a href="<?php echo URL::build('/admin/core/', 'view=reactions&id=' . $reaction->id); ?>"><?php echo Output::getClean($reaction->name); ?></a>
1079 </td>
1080 <td><?php echo $reaction->html; ?></td>
1081 <td><?php if ($reaction->type == 2) echo $language->get('admin', 'positive'); else if ($reaction->type == 1) echo $language->get('admin', 'neutral'); else echo $language->get('admin', 'negative'); ?></td>
1082 <td><?php if ($reaction->enabled == 1) { ?><i
1083 class="fa fa-check-circle text-success"
1084 aria-hidden="true"></i><?php } else { ?><i
1085 class="fa fa-times-circle text-danger"
1086 aria-hidden="true"></i><?php } ?></td>
1087 <?php
1088 }
1089 }
1090 ?>
1091 </tr>
1092 </tbody>
1093 </table>
1094 <?php
1095 } else {
1096 if (isset($_GET['id']) && !isset($_GET['action'])) {
1097 // Get reaction
1098 $reaction = $queries->getWhere('reactions', array('id', '=', $_GET['id']));
1099 if (!count($reaction)) {
1100 // Reaction doesn't exist
1101 Redirect::to(URL::build('/admin/core/', 'view=reactions'));
1102 die();
1103
1104 } else $reaction = $reaction[0];
1105
1106 // Deal with input
1107 if (Input::exists()) {
1108 if (Token::check(Input::get('token'))) {
1109 // Validate input
1110 $validate = new Validate();
1111 $validation = $validate->check($_POST, array(
1112 'name' => array(
1113 'required' => true,
1114 'min' => 1,
1115 'max' => 16
1116 ),
1117 'html' => array(
1118 'required' => true,
1119 'min' => 1,
1120 'max' => 255
1121 ),
1122 'type' => array(
1123 'required' => true
1124 )
1125 ));
1126
1127 if ($validation->passed()) {
1128 // Check enabled status
1129 if (isset($_POST['enabled']) && $_POST['enabled'] == 'on') $enabled = 1;
1130 else $enabled = 0;
1131
1132 switch (Input::get('type')) {
1133 case 1:
1134 $type = 1;
1135 break;
1136 case 2:
1137 $type = 2;
1138 break;
1139 default:
1140 $type = 0;
1141 break;
1142 }
1143
1144 // Update database
1145 $queries->update('reactions', $_GET['id'], array(
1146 'name' => Output::getClean(Input::get('name')),
1147 'html' => Output::getPurified(htmlspecialchars_decode(Input::get('html'))),
1148 'type' => $type,
1149 'enabled' => $enabled
1150 ));
1151
1152 Log::getInstance()->log(Log::Action('admin/core/reaction/update'), Output::getClean(Input::get('name')));
1153
1154 $reaction = $queries->getWhere('reactions', array('id', '=', $_GET['id']));
1155 $reaction = $reaction[0];
1156 } else {
1157 // Validation error
1158 }
1159 } else {
1160 // Invalid token
1161 }
1162 }
1163 ?>
1164 <h4 style="display:inline;"><?php echo $language->get('admin', 'editing_reaction'); ?></h4>
1165 <span class="pull-right">
1166 <a href="<?php echo URL::build('/admin/core/', 'view=reactions&action=delete&reaction=' . $reaction->id); ?>"
1167 onclick="return confirm('<?php echo $language->get('general', 'confirm_deletion'); ?>');"
1168 class="btn btn-danger"><?php echo $language->get('general', 'delete'); ?></a>
1169 <a href="<?php echo URL::build('/admin/core/', 'view=reactions'); ?>"
1170 class="btn btn-warning"><?php echo $language->get('general', 'cancel'); ?></a>
1171 </span>
1172 <hr/>
1173 <form action="" method="post">
1174 <div class="form-group">
1175 <label for="InputReactionName"><?php echo $language->get('admin', 'name'); ?></label>
1176 <input type="text" class="form-control" name="name"
1177 id="InputReactionName"
1178 placeholder="<?php echo $language->get('admin', 'name'); ?>"
1179 value="<?php echo Output::getClean($reaction->name); ?>">
1180 </div>
1181
1182 <div class="form-group">
1183 <label for="InputReactionHTML"><?php echo $language->get('admin', 'html'); ?></label>
1184 <input type="text" class="form-control" name="html"
1185 id="InputReactionHTML"
1186 placeholder="<?php echo $language->get('admin', 'html'); ?>"
1187 value="<?php echo Output::getClean($reaction->html); ?>">
1188 </div>
1189
1190 <div class="form-group">
1191 <label for="InputReactionType"><?php echo $language->get('admin', 'type'); ?></label>
1192 <select name="type" class="form-control" id="InputReactionType">
1193 <option value="2"<?php if ($reaction->type == 2) echo ' selected'; ?>><?php echo $language->get('admin', 'positive'); ?></option>
1194 <option value="1"<?php if ($reaction->type == 1) echo ' selected'; ?>><?php echo $language->get('admin', 'neutral'); ?></option>
1195 <option value="-1"<?php if ($reaction->type == 0) echo ' selected'; ?>><?php echo $language->get('admin', 'negative'); ?></option>
1196 </select>
1197 </div>
1198
1199 <div class="form-group">
1200 <label for="InputEnabled"><?php echo $language->get('admin', 'enabled'); ?></label>
1201 <input type="checkbox" name="enabled"
1202 class="js-switch"<?php if ($reaction->enabled == 1) echo ' checked'; ?>/>
1203 </div>
1204
1205 <div class="form-group">
1206 <input type="hidden" name="token" value="<?php echo Token::get(); ?>">
1207 <input type="submit"
1208 value="<?php echo $language->get('general', 'submit'); ?>"
1209 class="btn btn-primary">
1210 </div>
1211 </form>
1212 <?php
1213 } else if (isset($_GET['action'])) {
1214 if ($_GET['action'] == 'new') {
1215 // Deal with input
1216 if (Input::exists()) {
1217 if (Token::check(Input::get('token'))) {
1218 // Validate input
1219 $validate = new Validate();
1220 $validation = $validate->check($_POST, array(
1221 'name' => array(
1222 'required' => true,
1223 'min' => 1,
1224 'max' => 16
1225 ),
1226 'html' => array(
1227 'required' => true,
1228 'min' => 1,
1229 'max' => 255
1230 ),
1231 'type' => array(
1232 'required' => true
1233 )
1234 ));
1235
1236 if ($validation->passed()) {
1237 // Check enabled status
1238 if (isset($_POST['enabled']) && $_POST['enabled'] == 'on') $enabled = 1;
1239 else $enabled = 0;
1240
1241 switch (Input::get('type')) {
1242 case 1:
1243 $type = 1;
1244 break;
1245 case 2:
1246 $type = 2;
1247 break;
1248 default:
1249 $type = 0;
1250 break;
1251 }
1252
1253 // Update database
1254 $queries->create('reactions', array(
1255 'name' => Output::getClean(Input::get('name')),
1256 'html' => Output::getPurified(htmlspecialchars_decode(Input::get('html'))),
1257 'type' => $type,
1258 'enabled' => $enabled
1259 ));
1260
1261 Log::getInstance()->log(Log::Action('admin/core/reaction/add'), Output::getClean(Input::get('name')));
1262
1263 Redirect::to(URL::build('/admin/core/', 'view=reactions'));
1264 die();
1265 } else {
1266 // Validation error
1267 }
1268 } else {
1269 // Invalid token
1270 }
1271 }
1272 ?>
1273 <h4 style="display:inline;"><?php echo $language->get('admin', 'creating_reaction'); ?></h4>
1274 <span class="pull-right">
1275 <a href="<?php echo URL::build('/admin/core/', 'view=reactions'); ?>"
1276 class="btn btn-warning"><?php echo $language->get('general', 'cancel'); ?></a>
1277 </span>
1278 <hr/>
1279 <form action="" method="post">
1280 <div class="form-group">
1281 <label for="InputReactionName"><?php echo $language->get('admin', 'name'); ?></label>
1282 <input type="text" class="form-control" name="name"
1283 id="InputReactionName"
1284 placeholder="<?php echo $language->get('admin', 'name'); ?>"
1285 value="<?php echo Output::getClean(Input::get('name')); ?>">
1286 </div>
1287
1288 <div class="form-group">
1289 <label for="InputReactionHTML"><?php echo $language->get('admin', 'html'); ?></label>
1290 <input type="text" class="form-control" name="html"
1291 id="InputReactionHTML"
1292 placeholder="<?php echo $language->get('admin', 'html'); ?>"
1293 value="<?php echo Output::getClean(Input::get('html')); ?>">
1294 </div>
1295
1296 <div class="form-group">
1297 <label for="InputReactionType"><?php echo $language->get('admin', 'type'); ?></label>
1298 <select name="type" class="form-control" id="InputReactionType">
1299 <option value="2"><?php echo $language->get('admin', 'positive'); ?></option>
1300 <option value="1"><?php echo $language->get('admin', 'neutral'); ?></option>
1301 <option value="-1"><?php echo $language->get('admin', 'negative'); ?></option>
1302 </select>
1303 </div>
1304
1305 <div class="form-group">
1306 <label for="InputEnabled"><?php echo $language->get('admin', 'enabled'); ?></label>
1307 <input type="checkbox" name="enabled" class="js-switch"/>
1308 </div>
1309
1310 <div class="form-group">
1311 <input type="hidden" name="token"
1312 value="<?php echo Token::get(); ?>">
1313 <input type="submit"
1314 value="<?php echo $language->get('general', 'submit'); ?>"
1315 class="btn btn-primary">
1316 </div>
1317 </form>
1318 <?php
1319 } else if ($_GET['action'] == 'delete') {
1320 // Check specified reaction exists
1321 if (!isset($_GET['reaction']) || !is_numeric($_GET['reaction'])) {
1322 Redirect::to(URL::build('/admin/core/', 'view=reactions'));
1323 die();
1324 }
1325
1326 // Delete reaction
1327 $queries->delete('reactions', array('id', '=', $_GET['reaction']));
1328
1329 //TODO: Name
1330 Log::getInstance()->log(Log::Action('admin/core/reaction/delete'), $_GET['reaction']);
1331
1332 // Redirect
1333 Redirect::to(URL::build('/admin/core/', 'view=reactions'));
1334 die();
1335 }
1336 }
1337 }
1338 break;
1339
1340 case 'social':
1341 if (!$user->hasPermission('admincp.core.social_media')) {
1342 Redirect::to(URL::build('/admin/core'));
1343 die();
1344 }
1345 // Deal with input
1346 if (Input::exists()) {
1347 if (Token::check(Input::get('token'))) {
1348 // Update database values
1349 // Youtube URL
1350 $youtube_url_id = $queries->getWhere('settings', array('name', '=', 'youtube_url'));
1351 $youtube_url_id = $youtube_url_id[0]->id;
1352
1353 $queries->update('settings', $youtube_url_id, array(
1354 'value' => Output::getClean(Input::get('youtubeurl'))
1355 ));
1356
1357 // Update cache
1358 $cache->setCache('social_media');
1359 $cache->store('youtube', Output::getClean(Input::get('youtubeurl')));
1360
1361 // Twitter URL
1362 $twitter_url_id = $queries->getWhere('settings', array('name', '=', 'twitter_url'));
1363 $twitter_url_id = $twitter_url_id[0]->id;
1364
1365 $queries->update('settings', $twitter_url_id, array(
1366 'value' => Output::getClean(Input::get('twitterurl'))
1367 ));
1368
1369 $cache->store('twitter', Output::getClean(Input::get('twitterurl')));
1370
1371 // Twitter dark theme
1372 $twitter_dark_theme = $queries->getWhere('settings', array('name', '=', 'twitter_style'));
1373 $twitter_dark_theme = $twitter_dark_theme[0]->id;
1374
1375 if (isset($_POST['twitter_dark_theme']) && $_POST['twitter_dark_theme'] == 1) $theme = 'dark';
1376 else $theme = 'light';
1377
1378 $queries->update('settings', $twitter_dark_theme, array(
1379 'value' => $theme
1380 ));
1381
1382 $cache->store('twitter_theme', $theme);
1383
1384 // Discord ID
1385 $discord_id = $queries->getWhere('settings', array('name', '=', 'discord'));
1386 $discord_id = $discord_id[0]->id;
1387
1388 $queries->update('settings', $discord_id, array(
1389 'value' => Output::getClean(Input::get('discordid'))
1390 ));
1391
1392 $cache->store('discord', Output::getClean(Input::get('discordid')));
1393
1394 // Google Plus URL
1395 $gplus_url_id = $queries->getWhere('settings', array('name', '=', 'gplus_url'));
1396 $gplus_url_id = $gplus_url_id[0]->id;
1397
1398 $queries->update('settings', $gplus_url_id, array(
1399 'value' => Output::getClean(Input::get('gplusurl'))
1400 ));
1401
1402 $cache->store('google_plus', Output::getClean(Input::get('gplusurl')));
1403
1404 // Facebook URL
1405 $fb_url_id = $queries->getWhere('settings', array('name', '=', 'fb_url'));
1406 $fb_url_id = $fb_url_id[0]->id;
1407 $queries->update('settings', $fb_url_id, array(
1408 'value' => Output::getClean(Input::get('fburl'))
1409 ));
1410
1411 $cache->store('facebook', Output::getClean(Input::get('fburl')));
1412
1413 // Discord hook
1414 $discord_url_id = $queries->getWhere('settings', array('name', '=', 'discord_url'));
1415 $discord_url_id = $discord_url_id[0]->id;
1416
1417 $queries->update('settings', $discord_url_id, array(
1418 'value' => Output::getClean(Input::get('discord_url'))
1419 ));
1420
1421 $discord_hooks_id = $queries->getWhere('settings', array('name', '=', 'discord_hooks'));
1422 $discord_hooks_id = $discord_hooks_id[0]->id;
1423
1424 if (isset($_POST['discord_hooks']))
1425 $hooks = $_POST['discord_hooks'];
1426 else
1427 $hooks = array();
1428
1429 $queries->update('settings', $discord_hooks_id, array(
1430 'value' => json_encode($hooks)
1431 ));
1432
1433 Log::getInstance()->log(Log::Action('admin/core/social'));
1434
1435 $cache->setCache('discord_hook');
1436 $cache->store('events', $_POST['discord_hooks']);
1437 $cache->store('url', $_POST['discord_url']);
1438
1439 Session::flash('social_media_links', '<div class="alert alert-success">' . $language->get('admin', 'successfully_updated') . '</div>');
1440 } else {
1441 // Invalid token
1442 Session::flash('social_media_links', '<div class="alert alert-danger">' . $language->get('general', 'invalid_token') . '</div>');
1443 }
1444 }
1445
1446 // Show settings for social media links
1447 // Get values from database
1448 $youtube_url = $queries->getWhere('settings', array('name', '=', 'youtube_url'));
1449 $twitter_url = $queries->getWhere('settings', array('name', '=', 'twitter_url'));
1450 $twitter_style = $queries->getWhere('settings', array('name', '=', 'twitter_style'));
1451 $discord = $queries->getWhere('settings', array('name', '=', 'discord'));
1452 $gplus_url = $queries->getWhere('settings', array('name', '=', 'gplus_url'));
1453 $fb_url = $queries->getWhere('settings', array('name', '=', 'fb_url'));
1454 $discord_url = $queries->getWhere('settings', array('name', '=', 'discord_url'));
1455 $discord_hooks = $queries->getWhere('settings', array('name', '=', 'discord_hooks'));
1456 $discord_hooks = json_decode($discord_hooks[0]->value, true);
1457 ?>
1458 <h4><?php echo $language->get('admin', 'social_media'); ?></h4>
1459 <?php
1460 if (Session::exists('social_media_links')) {
1461 echo Session::flash('social_media_links');
1462 }
1463 ?>
1464 <form action="" method="post">
1465 <div class="form-group">
1466 <label for="InputYoutube"><?php echo $language->get('admin', 'youtube_url'); ?></label>
1467 <input type="text" name="youtubeurl" class="form-control" id="InputYoutube"
1468 placeholder="<?php echo $language->get('admin', 'youtube_url'); ?>"
1469 value="<?php echo Output::getClean($youtube_url[0]->value); ?>">
1470 </div>
1471 <div class="form-group">
1472 <label for="InputTwitter"><?php echo $language->get('admin', 'twitter_url'); ?></label>
1473 <input type="text" name="twitterurl" class="form-control" id="InputTwitter"
1474 placeholder="<?php echo $language->get('admin', 'twitter_url'); ?>"
1475 value="<?php echo Output::getClean($twitter_url[0]->value); ?>">
1476 </div>
1477 <div class="form-group">
1478 <label for="InputTwitterStyle"><?php echo $language->get('admin', 'twitter_dark_theme'); ?></label>
1479 <input id="InputTwitterStyle" name="twitter_dark_theme" type="checkbox"
1480 class="js-switch"
1481 value="1" <?php if ($twitter_style[0]->value == 'dark') echo 'checked'; ?>/>
1482 </div>
1483 <div class="form-group">
1484 <label for="InputDiscord"><?php echo $language->get('admin', 'discord_id'); ?></label>
1485 <input type="text" name="discordid" class="form-control" id="InputDiscord"
1486 placeholder="<?php echo $language->get('admin', 'discord_id'); ?>"
1487 value="<?php echo Output::getClean($discord[0]->value); ?>">
1488 </div>
1489 <div class="form-group">
1490 <label for="InputGPlus"><?php echo $language->get('admin', 'google_plus_url'); ?></label>
1491 <input type="text" name="gplusurl" class="form-control" id="InputGPlus"
1492 placeholder="<?php echo $language->get('admin', 'google_plus_url'); ?>"
1493 value="<?php echo Output::getClean($gplus_url[0]->value); ?>">
1494 </div>
1495 <div class="form-group">
1496 <label for="InputFacebook"><?php echo $language->get('admin', 'facebook_url'); ?></label>
1497 <input type="text" name="fburl" class="form-control" id="InputFacebook"
1498 placeholder="<?php echo $language->get('admin', 'facebook_url'); ?>"
1499 value="<?php echo Output::getClean($fb_url[0]->value); ?>">
1500 </div>
1501 <h4><?php echo $language->get('admin', 'discord_hooks'); ?></h4>
1502 <div class="alert alert-info"><?php echo $language->get('admin', 'discord_hooks_info'); ?></div>
1503 <div class="form-group">
1504 <label for="InputDiscordHookURL"><?php echo $language->get('admin', 'discord_hook_url'); ?></label>
1505 <input type="text" class="form-control" name="discord_url"
1506 placeholder="<?php echo $language->get('admin', 'discord_hook_url'); ?>"
1507 value="<?php echo Output::getClean($discord_url[0]->value); ?>"
1508 id="InputDiscordHookURL">
1509 </div>
1510 <div class="form-group">
1511 <label for="InputDiscordHooks"><?php echo $language->get('admin', 'discord_hook_events'); ?></label>
1512 <select multiple class="form-control" name="discord_hooks[]"
1513 id="InputDiscordHooks">
1514 <?php foreach (HookHandler::getHooks() as $hook => $description) { ?>
1515 <option value="<?php echo Output::getClean($hook); ?>"<?php if (in_array(Output::getClean($hook), $discord_hooks)) echo ' selected'; ?>><?php echo Output::getClean($description); ?></option>
1516 <?php } ?>
1517 </select>
1518 </div>
1519 <input type="hidden" name="token" value="<?php echo Token::get(); ?>">
1520 <input type="submit" class="btn btn-primary"
1521 value="<?php echo $language->get('general', 'submit'); ?>">
1522 </form>
1523 <?php
1524 break;
1525
1526 case 'maintenance':
1527 if (!$user->hasPermission('admincp.core.debugging')) {
1528 Redirect::to(URL::build('/admin/core'));
1529 die();
1530 }
1531 // Maintenance mode settings
1532 // Deal with input
1533 if (Input::exists()) {
1534 if (Token::check(Input::get('token'))) {
1535 // Valid token
1536 // Validate message
1537 $validate = new Validate();
1538 $validation = $validate->check($_POST, array(
1539 'message' => array(
1540 'max' => 1024
1541 )
1542 ));
1543
1544 if ($validation->passed()) {
1545 // Update database and cache
1546 // Is debug mode enabled or not?
1547 if (isset($_POST['enable_debugging']) && $_POST['enable_debugging'] == 1) $enabled = 1;
1548 else $enabled = 0;
1549
1550 $debug_id = $queries->getWhere('settings', array('name', '=', 'error_reporting'));
1551 $debug_id = $debug_id[0]->id;
1552 $queries->update('settings', $debug_id, array(
1553 'value' => $enabled
1554 ));
1555
1556 // Cache
1557 $cache->setCache('error_cache');
1558 $cache->store('error_reporting', $enabled);
1559
1560 // Is maintenance enabled or not?
1561 if (isset($_POST['enable_maintenance']) && $_POST['enable_maintenance'] == 1) $enabled = 'true';
1562 else $enabled = 'false';
1563
1564 $maintenance_id = $queries->getWhere('settings', array('name', '=', 'maintenance'));
1565 $maintenance_id = $maintenance_id[0]->id;
1566 $queries->update('settings', $maintenance_id, array(
1567 'value' => $enabled
1568 ));
1569
1570 if (isset($_POST['message']) && !empty($_POST['message'])) $message = Input::get('message');
1571 else $message = 'Maintenance mode is enabled.';
1572
1573 $maintenance_id = $queries->getWhere('settings', array('name', '=', 'maintenance_message'));
1574 $maintenance_id = $maintenance_id[0]->id;
1575 $queries->update('settings', $maintenance_id, array(
1576 'value' => Output::getClean($message)
1577 ));
1578
1579 Log::getInstance()->log(Log::Action('admin/core/maintenance/update'));
1580
1581 // Cache
1582 $cache->setCache('maintenance_cache');
1583 $cache->store('maintenance', array(
1584 'maintenance' => $enabled,
1585 'message' => Output::getClean($message)
1586 ));
1587
1588 // Page load timer
1589 if (isset($_POST['enable_page_load_timer']) && $_POST['enable_page_load_timer'] == 1) $enabled = 1;
1590 else $enabled = 0;
1591
1592 $load_id = $queries->getWhere('settings', array('name', '=', 'page_loading'));
1593 $load_id = $load_id[0]->id;
1594 $queries->update('settings', $load_id, array(
1595 'value' => $enabled
1596 ));
1597
1598 // Cache
1599 $cache->setCache('page_load_cache');
1600 $cache->store('page_load', $enabled);
1601
1602 // Reload to update debugging
1603 Redirect::to(URL::build('/admin/core/', 'view=maintenance'));
1604 die();
1605
1606 } else $error = $language->get('admin', 'maintenance_message_max_1024');
1607 } else {
1608 // Invalid token
1609 $error = $language->get('general', 'invalid_token');
1610 }
1611
1612 // Re-query cache for updated values
1613 $cache->setCache('maintenance_cache');
1614 $maintenance = $cache->retrieve('maintenance');
1615
1616 $cache->setCache('page_load_cache');
1617 if ($cache->isCached('page_load'))
1618 $page_loading = $cache->retrieve('page_load');
1619 else
1620 $page_loading = 0;
1621 }
1622 ?>
1623 <h4 style="display:inline;"><?php echo $language->get('admin', 'debugging_and_maintenance'); ?></h4>
1624 <?php if ($user->hasPermission('admincp.errors')) { ?><span class="pull-right"><a
1625 class="btn btn-primary"
1626 href="<?php echo URL::build('/admin/core/', 'view=errors'); ?>"><?php echo $language->get('admin', 'error_logs'); ?></a>
1627 </span><?php } ?>
1628 <br/><br/>
1629
1630 <form action="" method="post">
1631 <?php if (isset($error)) { ?>
1632 <div class="alert alert-danger"><?php echo $error; ?></div>
1633 <?php } ?>
1634 <div class="form-group">
1635 <label for="InputDebug"><?php echo $language->get('admin', 'enable_debug_mode'); ?></label>
1636 <input id="InputDebug" name="enable_debugging" type="checkbox" class="js-switch"
1637 value="1" <?php if (defined('DEBUGGING')) echo 'checked'; ?>/>
1638 </div>
1639 <div class="form-group">
1640 <label for="InputPageLoad"><?php echo $language->get('admin', 'enable_page_load_timer'); ?></label>
1641 <input id="InputPageLoad" name="enable_page_load_timer" type="checkbox"
1642 class="js-switch"
1643 value="1" <?php if ($page_loading == '1') echo 'checked'; ?>/>
1644 </div>
1645 <div class="form-group">
1646 <label for="InputMaintenance"><?php echo $language->get('admin', 'enable_maintenance_mode'); ?></label>
1647 <input id="InputMaintenance" name="enable_maintenance" type="checkbox"
1648 class="js-switch"
1649 value="1" <?php if (isset($maintenance['maintenance']) && $maintenance['maintenance'] != 'false') echo 'checked'; ?>/>
1650 </div>
1651 <div class="form-group">
1652 <label for="inputMaintenanceMessage"><?php echo $language->get('admin', 'maintenance_mode_message'); ?></label>
1653 <textarea style="width:100%" rows="10" name="message"
1654 id="InputMaintenanceMessage"><?php echo Output::getPurified(htmlspecialchars_decode($maintenance['message'])); ?></textarea>
1655 </div>
1656 <div class="form-group">
1657 <input type="hidden" name="token" value="<?php echo Token::get(); ?>">
1658 <input type="submit" value="<?php echo $language->get('general', 'submit'); ?>"
1659 class="btn btn-primary">
1660 </div>
1661 </form>
1662 <?php
1663 break;
1664
1665 case 'email':
1666 if (!$user->hasPermission('admincp.core.emails')) {
1667 Redirect::to(URL::build('/admin/core'));
1668 die();
1669 }
1670 if (isset($_GET['action'])) {
1671 if ($_GET['action'] == 'errors') {
1672 if (isset($_GET['do'])) {
1673 if ($_GET['do'] == 'purge') {
1674 // Purge all errors
1675 try {
1676 $queries->delete('email_errors', array('id', '<>', 0));
1677 } catch (Exception $e) {
1678 // Error
1679 }
1680
1681 Redirect::to(URL::build('/admin/core/', 'view=email&action=errors'));
1682 die();
1683
1684 } else if ($_GET['do'] == 'delete' && isset($_GET['id']) && is_numeric($_GET['id'])) {
1685 try {
1686 $queries->delete('email_errors', array('id', '=', $_GET['id']));
1687 } catch (Exception $e) {
1688 // Error
1689 }
1690
1691 Redirect::to(URL::build('/admin/core/', 'view=email&action=errors'));
1692 die();
1693
1694 } else if ($_GET['do'] == 'view' && isset($_GET['id']) && is_numeric($_GET['id'])) {
1695 // Check the error exists
1696 $error = $queries->getWhere('email_errors', array('id', '=', $_GET['id']));
1697 if (!count($error)) {
1698 Redirect::to(URL::build('/admin/core/', 'view=email&action=errors'));
1699 die();
1700 }
1701 $error = $error[0];
1702
1703 // Display error
1704 echo '<h4 style="display:inline;">' . $language->get('admin', 'email_errors') . '</h4>';
1705 echo '<span class="pull-right"><a href="' . URL::build('/admin/core/', 'view=email&action=errors') . '" class="btn btn-primary">' . $language->get('general', 'back') . '</a></span>';
1706 ?>
1707 <br/><br/>
1708 <strong><?php echo $language->get('admin', 'viewing_email_error'); ?></strong>
1709 <hr/>
1710 <strong><?php echo $language->get('user', 'username'); ?>
1711 :</strong> <?php echo Output::getClean($user->idToName($error->user_id)); ?>
1712 <br/>
1713 <strong><?php echo $language->get('general', 'date'); ?>
1714 :</strong> <?php echo date('d M Y, H:i', $error->at); ?><br/>
1715 <strong><?php echo $language->get('admin', 'type'); ?>:</strong> <?php
1716 switch ($error->type) {
1717 case 1:
1718 echo $language->get('admin', 'registration_email');
1719 break;
1720 case 2:
1721 echo $language->get('admin', 'contact_email');
1722 break;
1723 case 3:
1724 echo $language->get('admin', 'forgot_password_email');
1725 break;
1726 case 4:
1727 echo $language->get('admin', 'api_registration_email');
1728 break;
1729 default:
1730 echo $language->get('admin', 'unknown');
1731 break;
1732 }
1733 ?><br/><br/>
1734 <div class="card">
1735 <div class="card-block">
1736 <?php echo Output::getPurified($error->content); ?>
1737 </div>
1738 </div>
1739 <hr/>
1740 <h4><?php echo $language->get('general', 'actions'); ?></h4>
1741 <?php
1742 if ($error->type == 1) {
1743 $user_validated = $queries->getWhere('users', array('id', '=', $error->user_id));
1744 if (count($user_validated)) {
1745 $user_validated = $user_validated[0];
1746 if ($user_validated->active == 0) {
1747 ?>
1748 <a href="<?php echo URL::build('/admin/users/', 'user=' . $error->user_id . '&action=validate'); ?>"
1749 class="btn btn-secondary"><?php echo $language->get('admin', 'validate_user'); ?></a>
1750 <?php
1751 }
1752 }
1753 } else if ($error->type == 4) {
1754 $user_error = $queries->getWhere('users', array('id', '=', $error->user_id));
1755 if (count($user_error)) {
1756 $user_error = $user_error[0];
1757 if ($user_error->active == 0 && !is_null($user_error->reset_code)) {
1758 ?>
1759 <div class="alert alert-info"><?php echo str_replace('{x}', rtrim(Util::getSelfURL(), '/') . URL::build('/complete_signup/', 'c=' . Output::getClean($user_error->reset_code)), $language->get('admin', 'link_to_complete_registration')); ?></div>
1760 <?php
1761 }
1762 }
1763 }
1764 ?>
1765 <a href="<?php echo URL::build('/admin/core/', 'view=email&action=errors&do=delete&id=' . $error->id); ?>"
1766 class="btn btn-warning"
1767 onclick="return confirm('<?php echo $language->get('admin', 'confirm_email_error_deletion'); ?>');"><?php echo $language->get('admin', 'delete_email_error'); ?></a>
1768 <?php
1769 } else {
1770 Redirect::to(URL::build('/admin/core/', 'view=email&action=errors'));
1771 die();
1772 }
1773 } else {
1774 // Display all errors
1775 $errors = $queries->orderWhere('email_errors', 'id <> 0', 'at', 'DESC');
1776
1777 // Get page
1778 if (isset($_GET['p'])) {
1779 if (!is_numeric($_GET['p'])) {
1780 Redirect::to(URL::build('/admin/core/', 'view=email&action=errors'));
1781 die();
1782 } else {
1783 if ($_GET['p'] == 1) {
1784 // Avoid bug in pagination class
1785 Redirect::to(URL::build('/admin/core/', 'view=email&action=errors'));
1786 die();
1787 }
1788 $p = $_GET['p'];
1789 }
1790 } else {
1791 $p = 1;
1792 }
1793
1794 // Pagination
1795 $paginator = new Paginator();
1796
1797 $results = $paginator->getLimited($errors, 10, $p, count($errors));
1798 $pagination = $paginator->generate(7, URL::build('/admin/core/', 'view=email&action=errors&'));
1799
1800 echo '<h4 style="display:inline;">' . $language->get('admin', 'email_errors') . '</h4>';
1801 echo '<span class="pull-right"><a href="' . URL::build('/admin/core/', 'view=email') . '" class="btn btn-primary">' . $language->get('general', 'back') . '</a></span>';
1802 ?>
1803 <br/><br/>
1804 <?php if (count($errors)) { ?>
1805 <table class="table table-striped">
1806 <thead>
1807 <tr>
1808 <th><?php echo $language->get('admin', 'type'); ?></th>
1809 <th><?php echo $language->get('general', 'date'); ?></th>
1810 <th><?php echo $language->get('user', 'username'); ?></th>
1811 <th><?php echo $language->get('general', 'actions'); ?></th>
1812 </tr>
1813 </thead>
1814 <tbody>
1815 <?php
1816 for ($n = 0; $n < count($results->data); $n++) {
1817 switch ($results->data[$n]->type) {
1818 case 1:
1819 $type = $language->get('admin', 'registration_email');
1820 break;
1821 case 2:
1822 $type = $language->get('admin', 'contact_email');
1823 break;
1824 case 3:
1825 $type = $language->get('admin', 'forgot_password_email');
1826 break;
1827 default:
1828 $type = $language->get('admin', 'unknown');
1829 break;
1830 }
1831 ?>
1832 <tr>
1833 <td><?php echo $type; ?></td>
1834 <td><?php echo date('d M Y, H:i', $results->data[$n]->at); ?></td>
1835 <td><?php echo Output::getClean($user->idToName($results->data[$n]->user_id)); ?></td>
1836 <td>
1837 <a href="<?php echo URL::build('/admin/core/', 'view=email&action=errors&do=view&id=' . $results->data[$n]->id); ?>"
1838 class="btn btn-info btn-sm"><i
1839 class="fa fa-search fa-fw"></i></a> <a
1840 href="<?php echo URL::build('/admin/core/', 'view=email&action=errors&do=delete&id=' . $results->data[$n]->id); ?>"
1841 class="btn btn-warning btn-sm"
1842 onclick="return confirm('<?php echo $language->get('admin', 'confirm_email_error_deletion'); ?>')"><i
1843 class="fa fa-trash fa-fw"></i></a></td>
1844 </tr>
1845 <?php } ?>
1846 </tbody>
1847 </table>
1848 <?php
1849 echo $pagination;
1850 }
1851 }
1852 } else if ($_GET['action'] == 'test') {
1853 echo '<h4 style="display:inline;">' . $language->get('admin', 'send_test_email') . '</h4>';
1854 echo '<span class="pull-right"><a href="' . URL::build('/admin/core/', 'view=email') . '" class="btn btn-primary">' . $language->get('general', 'back') . '</a></span>';
1855 Log::getInstance()->log(Log::Action('admin/core/email/test'));
1856 if (isset($_GET['do']) && $_GET['do'] == 'send') {
1857 $php_mailer = $queries->getWhere('settings', array('name', '=', 'phpmailer'));
1858 $php_mailer = $php_mailer[0]->value;
1859
1860 if ($php_mailer == '1') {
1861 // PHP Mailer
1862 // HTML to display in message
1863 $path = join(DIRECTORY_SEPARATOR, array(ROOT_PATH, 'custom', 'templates', $template, 'email', 'register.html'));
1864 $html = file_get_contents($path);
1865
1866 $html = SITE_NAME . ' - Test email successful!';;
1867
1868 $email = array(
1869 'to' => array('email' => Output::getClean($user->data()->email), 'name' => Output::getClean($user->data()->nickname)),
1870 'subject' => SITE_NAME . ' - Test Email',
1871 'message' => $html
1872 );
1873
1874 $sent = Email::send($email, 'mailer');
1875
1876 if (isset($sent['error']))
1877 // Error
1878 $error = $sent['error'];
1879
1880 } else {
1881 // PHP mail function
1882 $siteemail = $queries->getWhere('settings', array('name', '=', 'outgoing_email'));
1883 $siteemail = $siteemail[0]->value;
1884
1885 $to = $user->data()->email;
1886 $subject = SITE_NAME . ' - Test Email';
1887
1888 $message = SITE_NAME . ' - Test email successful!';
1889
1890 $headers = 'From: ' . $siteemail . "\r\n" .
1891 'Reply-To: ' . $siteemail . "\r\n" .
1892 'X-Mailer: PHP/' . phpversion() . "\r\n" .
1893 'MIME-Version: 1.0' . "\r\n" .
1894 'Content-type: text/html; charset=UTF-8' . "\r\n";
1895
1896 $email = array(
1897 'to' => $to,
1898 'subject' => $subject,
1899 'message' => $message,
1900 'headers' => $headers
1901 );
1902
1903 $sent = Email::send($email, 'php');
1904
1905 if (isset($sent['error']))
1906 // Error
1907 $error = $sent['error'];
1908 }
1909 echo '<br /><br />';
1910 if (isset($error)) {
1911 ?>
1912 <div class="alert alert-danger">
1913 <strong><?php echo $language->get('admin', 'test_email_error'); ?></strong>
1914 <p><?php echo Output::getClean($error); ?></p></div>
1915 <?php
1916 } else {
1917 ?>
1918 <div class="alert alert-success"><?php echo $language->get('admin', 'test_email_success'); ?></div>
1919 <?php
1920 }
1921 } else {
1922 ?>
1923 <br/><br/>
1924 <div class="alert alert-info"><?php echo str_replace('{x}', Output::getClean($user->data()->email), $language->get('admin', 'send_test_email_info')); ?></div>
1925 <hr/>
1926 <a class="btn btn-primary"
1927 href="<?php echo URL::build('/admin/core/', 'view=email&action=test&do=send'); ?>"><?php echo $language->get('admin', 'send'); ?></a>
1928 <?php
1929 }
1930 }
1931 } else {
1932 // Handle input
1933 if (Input::exists()) {
1934 if (Token::check(Input::get('token'))) {
1935 if (isset($_POST['enable_mailer']) && $_POST['enable_mailer'] == 1)
1936 $mailer = '1';
1937 else
1938 $mailer = '0';
1939
1940 $php_mailer = $queries->getWhere('settings', array('name', '=', 'phpmailer'));
1941 $php_mailer = $php_mailer[0]->id;
1942
1943 $queries->update('settings', $php_mailer, array(
1944 'value' => $mailer
1945 ));
1946
1947 Log::getInstance()->log(Log::Action('admin/core/email/update'));
1948
1949 if (!empty($_POST['email'])) {
1950 $outgoing_email = $queries->getWhere('settings', array('name', '=', 'outgoing_email'));
1951 $outgoing_email = $outgoing_email[0]->id;
1952
1953 $queries->update('settings', $outgoing_email, array(
1954 'value' => Output::getClean($_POST['email'])
1955 ));
1956 }
1957
1958 // Update config
1959 $config_path = 'core' . DIRECTORY_SEPARATOR . 'email.php';
1960 if (file_exists($config_path)) {
1961 if (is_writable($config_path)) {
1962 require(ROOT_PATH . '/core/email.php');
1963 // Build new email config
1964 $config = '<?php' . PHP_EOL .
1965 '$GLOBALS[\'email\'] = array(' . PHP_EOL .
1966 ' \'email\' => \'' . str_replace('\'', '\\\'', (!empty($_POST['email']) ? $_POST['email'] : $GLOBALS['email']['email'])) . '\',' . PHP_EOL .
1967 ' \'username\' => \'' . str_replace('\'', '\\\'', (!empty($_POST['username']) ? $_POST['username'] : $GLOBALS['email']['username'])) . '\',' . PHP_EOL .
1968 ' \'password\' => \'' . str_replace('\'', '\\\'', ((!empty($_POST['password'])) ? $_POST['password'] : $GLOBALS['email']['password'])) . '\',' . PHP_EOL .
1969 ' \'name\' => \'' . str_replace('\'', '\\\'', (!empty($_POST['name']) ? $_POST['name'] : $GLOBALS['email']['name'])) . '\',' . PHP_EOL .
1970 ' \'host\' => \'' . str_replace('\'', '\\\'', (!empty($_POST['host']) ? $_POST['host'] : $GLOBALS['email']['host'])) . '\',' . PHP_EOL .
1971 ' \'port\' => ' . str_replace('\'', '\\\'', (!empty($_POST['port']) ? $_POST['port'] : $GLOBALS['email']['port'])) . ',' . PHP_EOL .
1972 ' \'secure\' => \'' . str_replace('\'', '\\\'', $GLOBALS['email']['secure']) . '\',' . PHP_EOL .
1973 ' \'smtp_auth\' => ' . (($GLOBALS['email']['smtp_auth']) ? 'true' : 'false') . PHP_EOL .
1974 ');';
1975
1976 $file = fopen($config_path, 'w');
1977 fwrite($file, $config);
1978 fclose($file);
1979
1980 } else {
1981 // Permissions incorrect
1982 $error = $language->get('admin', 'unable_to_write_email_config');
1983 }
1984 } else {
1985 // Create one now
1986 if (is_writable(ROOT_PATH . DIRECTORY_SEPARATOR . 'core')) {
1987 // Build new email config
1988 $config = '<?php' . PHP_EOL .
1989 '$GLOBALS[\'email\'] = array(' . PHP_EOL .
1990 ' \'email\' => \'' . str_replace('\'', '\\\'', (!empty($_POST['email']) ? $_POST['email'] : '')) . '\',' . PHP_EOL .
1991 ' \'username\' => \'' . str_replace('\'', '\\\'', (!empty($_POST['username']) ? $_POST['username'] : '')) . '\',' . PHP_EOL .
1992 ' \'password\' => \'' . str_replace('\'', '\\\'', ((!empty($_POST['password'])) ? $_POST['password'] : '')) . '\',' . PHP_EOL .
1993 ' \'name\' => \'' . str_replace('\'', '\\\'', (!empty($_POST['name']) ? $_POST['name'] : '')) . '\',' . PHP_EOL .
1994 ' \'host\' => \'' . str_replace('\'', '\\\'', (!empty($_POST['host']) ? $_POST['host'] : '')) . '\',' . PHP_EOL .
1995 ' \'port\' => \'' . str_replace('\'', '\\\'', (!empty($_POST['port']) ? $_POST['host'] : 587)) . ',' . PHP_EOL .
1996 ' \'secure\' => \'tls\',' . PHP_EOL .
1997 ' \'smtp_auth\' => true' . PHP_EOL .
1998 ');';
1999 $file = fopen($config_path, 'w');
2000 fwrite($file, $config);
2001 fclose($file);
2002 } else {
2003 $error = $language->get('admin', 'unable_to_write_email_config');
2004 }
2005 }
2006
2007 if (!isset($error)) {
2008 // Redirect to refresh config values
2009 Redirect::to(URL::build('/admin/core/', 'view=email'));
2010 die();
2011 }
2012 } else
2013 $error = $language->get('general', 'invalid_token');
2014 }
2015
2016 echo '<h4 style="display:inline;">' . $language->get('admin', 'emails') . '</h4>';
2017 echo '<span class="pull-right"><a class="btn btn-info" href="' . URL::build('/admin/core/', 'view=email&action=test') . '">' . $language->get('admin', 'send_test_email') . '</a> <a href="' . URL::build('/admin/core/', 'view=email&action=errors') . '" class="btn btn-primary">' . $language->get('admin', 'email_errors') . '</a></span>';
2018
2019 if (isset($error))
2020 echo '<div class="alert alert-danger">' . $error . '</div>';
2021
2022 $php_mailer = $queries->getWhere('settings', array('name', '=', 'phpmailer'));
2023 $php_mailer = $php_mailer[0]->value;
2024
2025 $outgoing_email = $queries->getWhere('settings', array('name', '=', 'outgoing_email'));
2026 $outgoing_email = $outgoing_email[0]->value;
2027
2028 require(ROOT_PATH . '/core/email.php');
2029 ?>
2030 <br/><br/>
2031 <form action="" method="post">
2032 <div class="form-group">
2033 <label for="inputMailer"><?php echo $language->get('admin', 'enable_mailer'); ?></label>
2034 <span class="badge badge-info"><i class="fa fa-question-circle"
2035 data-container="body"
2036 data-toggle="popover" data-placement="top"
2037 title="<?php echo $language->get('general', 'info'); ?>"
2038 data-content="<?php echo $language->get('admin', 'enable_mailer_help'); ?>"></i></span>
2039 <input type="hidden" name="enable_mailer" value="0">
2040 <input id="inputMailer" name="enable_mailer" type="checkbox"
2041 class="js-switch"
2042 value="1"<?php if ($php_mailer == '1') { ?> checked<?php } ?> />
2043 </div>
2044 <div class="form-group">
2045 <label for="InputOutgoingEmail"><?php echo $language->get('admin', 'outgoing_email'); ?></label>
2046 <span class="badge badge-info"><i class="fa fa-question-circle"
2047 data-container="body"
2048 data-toggle="popover" data-placement="top"
2049 title="<?php echo $language->get('general', 'info'); ?>"
2050 data-content="<?php echo $language->get('admin', 'outgoing_email_info'); ?>"></i></span>
2051 <input type="text" id="InputOutgoingEmail" name="email"
2052 value="<?php echo Output::getClean($outgoing_email); ?>"
2053 class="form-control">
2054 </div>
2055 <hr/>
2056 <div class="alert alert-info">
2057 <?php echo $language->get('admin', 'mailer_settings_info'); ?>
2058 </div>
2059 <div class="form-group">
2060 <label for="inputUsername"><?php echo $language->get('user', 'username'); ?></label>
2061 <input class="form-control" type="text" name="username"
2062 value="<?php if (!empty($GLOBALS['email']['username'])) echo Output::getClean($GLOBALS['email']['username']); ?>"
2063 id="inputUsername">
2064 </div>
2065 <div class="form-group">
2066 <label for="inputPassword"><?php echo $language->get('user', 'password'); ?></label>
2067 <span class="badge badge-info"><i class="fa fa-question-circle"
2068 data-container="body"
2069 data-toggle="popover" data-placement="top"
2070 title="<?php echo $language->get('general', 'info'); ?>"
2071 data-content="<?php echo $language->get('admin', 'email_password_hidden'); ?>"></i></span>
2072 <input class="form-control" type="password" name="password"
2073 id="inputPassword">
2074 </div>
2075 <div class="form-group">
2076 <label for="inputName"><?php echo $language->get('admin', 'name'); ?></label>
2077 <input class="form-control" type="text" name="name"
2078 value="<?php if (!empty($GLOBALS['email']['name'])) echo Output::getClean($GLOBALS['email']['name']); ?>"
2079 id="inputName">
2080 </div>
2081 <div class="form-group">
2082 <label for="inputHost"><?php echo $language->get('admin', 'host'); ?></label>
2083 <input class="form-control" type="text" name="host"
2084 value="<?php if (!empty($GLOBALS['email']['host'])) echo Output::getClean($GLOBALS['email']['host']); ?>"
2085 id="inputHost">
2086 </div>
2087 <div class="form-group">
2088 <label for="inputPort"><?php echo $language->get('admin', 'email_port'); ?></label>
2089 <input class="form-control" type="text" name="port"
2090 value="<?php if (!empty($GLOBALS['email']['port'])) echo Output::getClean(isset($GLOBALS['email']['port']) ? $GLOBALS['email']['port'] : 587); ?>"
2091 id="inputPort">
2092 </div>
2093 <hr/>
2094 <div class="form-group">
2095 <input type="hidden" name="token" value="<?php echo Token::get(); ?>">
2096 <input type="submit" class="btn btn-primary"
2097 value="<?php echo $language->get('general', 'submit'); ?>">
2098 </div>
2099 </form>
2100 <?php
2101 }
2102
2103 break;
2104
2105 case 'terms':
2106 if (!$user->hasPermission('admincp.core.terms')) {
2107 Redirect::to(URL::build('/admin/core'));
2108 die();
2109 }
2110 if (Input::exists()) {
2111 if (Token::check(Input::get('token'))) {
2112 $validate = new Validate();
2113 $validation = $validate->check($_POST, array(
2114 'privacy' => array(
2115 'required' => true,
2116 'max' => 2048
2117 ),
2118 'terms' => array(
2119 'required' => true,
2120 'max' => 2048
2121 )
2122 ));
2123
2124 if ($validation->passed()) {
2125 try {
2126 $privacy_id = $queries->getWhere('settings', array('name', '=', 'privacy_policy'));
2127 $privacy_id = $privacy_id[0]->id;
2128
2129 $queries->update('settings', $privacy_id, array(
2130 'value' => Input::get('privacy')
2131 ));
2132
2133 $terms_id = $queries->getWhere('settings', array('name', '=', 't_and_c_site'));
2134 $terms_id = $terms_id[0]->id;
2135
2136 $queries->update('settings', $terms_id, array(
2137 'value' => Input::get('terms')
2138 ));
2139
2140 Log::getInstance()->log(Log::Action('admin/core/term'));
2141 $success = $language->get('admin', 'terms_updated');
2142 } catch (Exception $e) {
2143 $error = $e->getMessage();
2144 }
2145 } else
2146 $error = $language->get('admin', 'terms_error');
2147
2148 } else
2149 $error = $language->get('general', 'invalid_token');
2150 }
2151
2152 $site_terms = $queries->getWhere('settings', array('name', '=', 't_and_c_site'));
2153 $site_terms = $site_terms[0]->value;
2154
2155 $site_privacy = $queries->getWhere('settings', array('name', '=', 'privacy_policy'));
2156 $site_privacy = $site_privacy[0]->value;
2157 ?>
2158 <h4><?php echo $language->get('admin', 'privacy_and_terms'); ?></h4>
2159
2160 <form action="" method="post">
2161 <?php if (isset($error)) { ?>
2162 <div class="alert alert-danger"><?php echo $error; ?></div>
2163 <?php } else if (isset($success)) { ?>
2164 <div class="alert alert-success"><?php echo $success; ?></div>
2165 <?php } ?>
2166
2167 <div class="form-group">
2168 <label for="InputPrivacy"><?php echo $language->get('general', 'privacy_policy'); ?></label>
2169 <textarea style="width:100%" rows="10" name="privacy"
2170 id="InputPrivacy"><?php echo Output::getPurified($site_privacy); ?></textarea>
2171 </div>
2172
2173 <div class="form-group">
2174 <label for="InputTerms"><?php echo $language->get('user', 'terms_and_conditions'); ?></label>
2175 <textarea style="width:100%" rows="10" name="terms"
2176 id="InputTerms"><?php echo Output::getPurified($site_terms); ?></textarea>
2177 </div>
2178 <div class="form-group">
2179 <input type="hidden" name="token" value="<?php echo Token::get(); ?>">
2180 <input type="submit" value="<?php echo $language->get('general', 'submit'); ?>"
2181 class="btn btn-primary">
2182 </div>
2183 </form>
2184 <?php
2185 break;
2186
2187 case 'avatars':
2188 if (!$user->hasPermission('admincp.core.avatars')) {
2189 Redirect::to(URL::build('/admin/core'));
2190 die();
2191 }
2192 // Input
2193 if (Input::exists()) {
2194 if (Token::check(Input::get('token'))) {
2195 if (isset($_POST['avatar_source'])) {
2196 // Custom avatars?
2197 if (isset($_POST['custom_avatars']) && $_POST['custom_avatars'] == 1)
2198 $custom_avatars = 1;
2199 else
2200 $custom_avatars = 0;
2201
2202 try {
2203 $custom_avatars_id = $queries->getWhere('settings', array('name', '=', 'user_avatars'));
2204 $custom_avatars_id = $custom_avatars_id[0]->id;
2205 $queries->update('settings', $custom_avatars_id, array('value' => $custom_avatars));
2206
2207 $default_avatar_type = $queries->getWhere('settings', array('name', '=', 'default_avatar_type'));
2208 $default_avatar_type = $default_avatar_type[0]->id;
2209 $queries->update('settings', $default_avatar_type, array('value' => Input::get('default_avatar')));
2210
2211 $mc_avatar_source = $queries->getWhere('settings', array('name', '=', 'avatar_site'));
2212 $mc_avatar_source = $mc_avatar_source[0]->id;
2213 $queries->update('settings', $mc_avatar_source, array('value' => Input::get('avatar_source')));
2214
2215 $mc_avatar_perspective = $queries->getWhere('settings', array('name', '=', 'avatar_type'));
2216 $mc_avatar_perspective = $mc_avatar_perspective[0]->id;
2217 $queries->update('settings', $mc_avatar_perspective, array('value' => Input::get('avatar_perspective')));
2218
2219 $cache->setCache('avatar_settings_cache');
2220 $cache->store('custom_avatars', $custom_avatars);
2221 $cache->store('default_avatar_type', Input::get('default_avatar'));
2222 $cache->store('avatar_source', Input::get('avatar_source'));
2223 $cache->store('avatar_perspective', Input::get('avatar_perspective'));
2224
2225 } catch (Exception $e) {
2226 $error = $e->getMessage();
2227 }
2228 } else if (isset($_POST['avatar'])) {
2229 // Selecting a new default avatar
2230 try {
2231 $default_avatar = $queries->getWhere('settings', array('name', '=', 'custom_default_avatar'));
2232 $default_avatar = $default_avatar[0]->id;
2233 $queries->update('settings', $default_avatar, array('value' => Input::get('avatar')));
2234
2235 $cache->setCache('avatar_settings_cache');
2236 $cache->store('default_avatar_image', Input::get('avatar'));
2237
2238 } catch (Exception $e) {
2239 $error = $e->getMessage();
2240 }
2241 }
2242
2243 Log::getInstance()->log(Log::Action('admin/core/avatar'));
2244
2245 $success = $language->get('admin', 'avatar_settings_updated_successfully');
2246 } else
2247 $error = $language->get('general', 'invalid_token');
2248 }
2249
2250 // Get setting values
2251 $custom_avatars = $queries->getWhere('settings', array('name', '=', 'user_avatars'));
2252 $custom_avatars = $custom_avatars[0]->value;
2253
2254 $default_avatar_type = $queries->getWhere('settings', array('name', '=', 'default_avatar_type'));
2255 $default_avatar_type = $default_avatar_type[0]->value;
2256
2257 $mc_avatar_source = $queries->getWhere('settings', array('name', '=', 'avatar_site'));
2258 $mc_avatar_source = $mc_avatar_source[0]->value;
2259
2260 $mc_avatar_perspective = $queries->getWhere('settings', array('name', '=', 'avatar_type'));
2261 $mc_avatar_perspective = $mc_avatar_perspective[0]->value;
2262 ?>
2263 <h4><?php echo $language->get('admin', 'avatars'); ?></h4>
2264
2265 <?php if (isset($error)) echo '<div class="alert alert-danger">' . $error . '</div>'; ?>
2266 <?php if (isset($success)) echo '<div class="alert alert-success">' . $success . '</div>'; ?>
2267
2268 <form action="" method="post">
2269 <div class="form-group">
2270 <label for="inputCustomAvatars"><?php echo $language->get('admin', 'allow_custom_avatars'); ?></label>
2271 <input type="hidden" name="custom_avatars" value="0">
2272 <input id="inputCustomAvatars" name="custom_avatars" type="checkbox"
2273 class="js-switch"
2274 value="1"<?php if ($custom_avatars == '1') { ?> checked<?php } ?> />
2275 </div>
2276 <div class="form-group">
2277 <label for="inputDefaultAvatar"><?php echo $language->get('admin', 'default_avatar'); ?></label>
2278 <select class="form-control" name="default_avatar" id="inputDefaultAvatar">
2279 <option value="minecraft"<?php if ($default_avatar_type == 'minecraft') echo ' selected'; ?>><?php echo $language->get('admin', 'minecraft_avatar'); ?></option>
2280 <option value="custom"<?php if ($default_avatar_type == 'custom') echo ' selected'; ?>><?php echo $language->get('admin', 'custom_avatar'); ?></option>
2281 </select>
2282 </div>
2283 <div class="form-group">
2284 <label for="inputMinecraftAvatarSource"><?php echo $language->get('admin', 'minecraft_avatar_source'); ?></label>
2285 <select class="form-control" name="avatar_source"
2286 id="inputMinecraftAvatarSource">
2287 <option value="cravatar"<?php if ($mc_avatar_source == 'cravatar') echo ' selected'; ?>>
2288 cravatar.eu
2289 </option>
2290 <option value="crafatar"<?php if ($mc_avatar_source == 'crafatar') echo ' selected'; ?>>
2291 crafatar.com
2292 </option>
2293 <option value="nameless"<?php if ($mc_avatar_source == 'nameless') echo ' selected'; ?>><?php echo $language->get('admin', 'built_in_avatars'); ?></option>
2294 </select>
2295 </div>
2296 <div class="form-group">
2297 <label for="inputAvatarPerspective"><?php echo $language->get('admin', 'minecraft_avatar_perspective'); ?></label>
2298 <select class="form-control" name="avatar_perspective"
2299 id="inputAvatarPerspective">
2300 <option value="face"<?php if ($mc_avatar_perspective == 'avatar' || $mc_avatar_perspective == 'helmavatar') echo ' selected'; ?>><?php echo $language->get('admin', 'face'); ?></option>
2301 <option value="head"<?php if ($mc_avatar_perspective == 'head') echo ' selected'; ?>><?php echo $language->get('admin', 'head'); ?></option>
2302 </select>
2303 </div>
2304 <div class="form-group">
2305 <input type="hidden" name="token" value="<?php echo Token::get(); ?>">
2306 <input type="submit" class="btn btn-primary"
2307 value="<?php echo $language->get('general', 'submit'); ?>">
2308 </div>
2309 </form>
2310 <h5><?php echo $language->get('admin', 'default_avatar'); ?></h5>
2311 <button class="btn btn-primary" data-toggle="modal"
2312 data-target="#uploadModal"><?php echo $language->get('admin', 'upload_new_image'); ?></button>
2313 <br/><br/>
2314
2315 <form action="" method="post" style="display:inline;">
2316 <label for="inputAvatar"><?php echo $language->get('admin', 'select_default_avatar'); ?></label>
2317 <select name="avatar" class="image-picker show-html">
2318 <?php
2319 $image_path = join(DIRECTORY_SEPARATOR, array(ROOT_PATH, 'uploads', 'avatars', 'defaults'));
2320 $images = scandir($image_path);
2321
2322 // Only display jpeg, png, jpg, gif
2323 $allowed_exts = array('gif', 'png', 'jpg', 'jpeg');
2324
2325 foreach ($images as $image) {
2326 $ext = pathinfo($image, PATHINFO_EXTENSION);
2327 if (!in_array($ext, $allowed_exts)) {
2328 continue;
2329 }
2330 $count = 1;
2331 ?>
2332 <option data-img-src="<?php echo((defined('CONFIG_PATH')) ? CONFIG_PATH . '/' : '/'); ?>uploads/avatars/defaults/<?php echo Output::getClean($image); ?>"
2333 value="<?php echo Output::getClean($image); ?>" <?php if ($default_avatar_image == ((defined('CONFIG_PATH')) ? CONFIG_PATH . '/' : '/') . 'uploads/avatars/defaults/' . Output::getClean($image)) echo 'selected'; ?>><?php echo Output::getClean($image); ?></option>
2334 <?php
2335 }
2336 ?>
2337 </select>
2338 <?php if (!isset($count)) echo '<strong>' . $language->get('admin', 'no_avatars_available') . '</strong>'; else { ?>
2339 <div class="form-group">
2340 <input type="hidden" name="token" value="<?php echo Token::get(); ?>">
2341 <input type="submit" class="btn btn-primary"
2342 value="<?php echo $language->get('general', 'submit'); ?>">
2343 </div>
2344 <?php } ?>
2345 </form>
2346
2347 <!-- Modal -->
2348 <div class="modal fade" id="uploadModal" tabindex="-1" role="dialog"
2349 aria-labelledby="uploadModalLabel" aria-hidden="true">
2350 <div class="modal-dialog" role="document">
2351 <div class="modal-content">
2352 <div class="modal-header">
2353 <button type="button" class="close" data-dismiss="modal"
2354 aria-label="Close">
2355 <span aria-hidden="true">×</span>
2356 </button>
2357 <h4 class="modal-title"
2358 id="uploadModalLabel"><?php echo $language->get('admin', 'upload_new_image'); ?></h4>
2359 </div>
2360 <div class="modal-body">
2361 <!-- Upload modal -->
2362 <form action="<?php if (defined('CONFIG_PATH')) echo CONFIG_PATH . '/'; else echo '/'; ?>core/includes/image_upload.php"
2363 class="dropzone" id="upload_avatar_dropzone">
2364 <div class="dz-message" data-dz-message>
2365 <span><?php echo $language->get('admin', 'drag_files_here'); ?></span>
2366 </div>
2367 <input type="hidden" name="token"
2368 value="<?php echo Token::get(); ?>">
2369 <input type="hidden" name="type" value="default_avatar">
2370 </form>
2371 </div>
2372 <div class="modal-footer">
2373 <button type="button" class="btn btn-danger"
2374 onclick="location.reload();"
2375 data-dismiss="modal"><?php echo $language->get('general', 'cancel'); ?></button>
2376 </div>
2377 </div>
2378 </div>
2379 </div>
2380 <?php
2381 break;
2382
2383 case 'navigation':
2384 if (!$user->hasPermission('admincp.core.navigation')) {
2385 Redirect::to(URL::build('/admin/core'));
2386 die();
2387 }
2388 // Maintenance mode settings
2389 // Deal with input
2390 if (Input::exists()) {
2391 if (Token::check(Input::get('token'))) {
2392 // Valid token
2393 // Update cache
2394 $cache->setCache('navbar_order');
2395 if (isset($_POST['inputOrder']) && count($_POST['inputOrder'])) {
2396 foreach ($_POST['inputOrder'] as $key => $item) {
2397 if (is_numeric($item) && $item > 0) {
2398 $cache->store($key . '_order', $item);
2399 }
2400 }
2401 }
2402
2403 // Icons
2404 $cache->setCache('navbar_icons');
2405 if (isset($_POST['inputIcon']) && count($_POST['inputIcon'])) {
2406 foreach ($_POST['inputIcon'] as $key => $item) {
2407 if (is_numeric($key)) {
2408 // Custom page?
2409 $custom_page = $queries->getWhere('custom_pages', array('id', '=', $key));
2410 if (count($custom_page)) {
2411 $queries->update('custom_pages', $key, array(
2412 'icon' => $item
2413 ));
2414 }
2415 }
2416 $cache->store($key . '_icon', $item);
2417 }
2418 }
2419
2420 Log::getInstance()->log(Log::Action('admin/core/nav'));
2421
2422 // Reload to update info
2423 Redirect::to(URL::build('/admin/core/', 'view=navigation'));
2424 die();
2425 } else {
2426 // Invalid token
2427 $error = $language->get('general', 'invalid_token');
2428 }
2429 }
2430 ?>
2431 <h4><?php echo $language->get('admin', 'navigation'); ?></h4>
2432
2433 <form action="" method="post">
2434 <div class="alert alert-info"><?php echo $language->get('admin', 'navbar_order_instructions'); ?>
2435 <hr/><?php echo $language->get('admin', 'navbar_icon_instructions'); ?></div>
2436 <?php
2437 // Display fields for each page
2438 $nav_items = $navigation->returnNav('top');
2439 foreach ($nav_items as $key => $item) {
2440 echo '<strong>' . Output::getClean($item['title']) . '</strong>';
2441 ?>
2442 <div class="form-group">
2443 <label for="input<?php echo Output::getClean($item['title']); ?>"><?php echo $language->get('admin', 'navbar_order'); ?></label>
2444 <input type="number" min="1" class="form-control"
2445 id="input<?php echo Output::getClean($item['title']); ?>"
2446 name="inputOrder[<?php echo((isset($item['custom']) && is_numeric($item['custom'])) ? $item['custom'] : Output::getClean($key)); ?>]"
2447 value="<?php echo Output::getClean($item['order']); ?>">
2448 </div>
2449 <div class="form-group">
2450 <label for="input<?php echo Output::getClean($item['title']); ?>Icon"><?php echo $language->get('admin', 'navbar_icon'); ?></label>
2451 <input type="text" class="form-control"
2452 id="input<?php echo Output::getClean($item['title']); ?>Icon"
2453 name="inputIcon[<?php echo((isset($item['custom']) && is_numeric($item['custom'])) ? $item['custom'] : Output::getClean($key)); ?>]"
2454 value="<?php echo Output::getClean($item['icon']); ?>">
2455 </div>
2456 <?php
2457 if (isset($item['items']) && count($item['items'])) {
2458 echo '<strong>' . Output::getClean($item['title']) . ' » ' . $language->get('admin', 'dropdown_items') . '</strong><br />';
2459 foreach ($item['items'] as $dropdown_key => $dropdown_item) {
2460 echo '<strong>' . Output::getClean($dropdown_item['title']) . '</strong>';
2461 ?>
2462 <!--<div class="form-group">
2463 <label for="input<?php echo Output::getClean($dropdown_item['title']); ?>"><?php echo $language->get('admin', 'navbar_order'); ?></label>
2464 <input type="number" min="1" class="form-control" id="input<?php echo Output::getClean($dropdown_item['title']); ?>" name="inputOrder[<?php echo((isset($dropdown_item['custom']) && is_numeric($dropdown_item['custom'])) ? $dropdown_item['custom'] : Output::getClean($dropdown_key)); ?>]" value="<?php echo Output::getClean($dropdown_item['order']); ?>">
2465 </div>-->
2466 <div class="form-group">
2467 <label for="input<?php echo Output::getClean($dropdown_item['title']); ?>Icon"><?php echo $language->get('admin', 'navbar_icon'); ?></label>
2468 <input type="text" class="form-control"
2469 id="input<?php echo Output::getClean($dropdown_item['title']); ?>Icon"
2470 name="inputIcon[<?php echo((isset($dropdown_item['custom']) && is_numeric($dropdown_item['custom'])) ? $dropdown_item['custom'] : Output::getClean($dropdown_key)); ?>]"
2471 value="<?php echo Output::getClean($dropdown_item['icon']); ?>">
2472 </div>
2473 <?php
2474 }
2475 }
2476 }
2477 ?>
2478 <div class="form-group">
2479 <input type="hidden" name="token" value="<?php echo Token::get(); ?>">
2480 <input type="submit" value="<?php echo $language->get('general', 'submit'); ?>"
2481 class="btn btn-primary">
2482 </div>
2483 </form>
2484 <?php
2485 break;
2486
2487 case 'errors':
2488 if (!$user->hasPermission('admincp.errors')) {
2489 Redirect::to(URL::build('/admin/core'));
2490 die();
2491 }
2492 echo '<h4 style="display:inline;">' . $language->get('admin', 'error_logs') . '</h4><span class="pull-right"><a class="btn btn-primary" href="' . (!isset($_GET['log']) ? URL::build('/admin/core/', 'view=maintenance') : URL::build('/admin/core/', 'view=errors')) . '">' . $language->get('general', 'back') . '</a></span><br /><br />';
2493 if (!isset($_GET['log'])) {
2494 ?>
2495 <div class="table-responsive">
2496 <table class="table table-striped">
2497 <tr>
2498 <td>
2499 <a href="<?php echo URL::build('/admin/core/', 'view=errors&log=fatal'); ?>"><?php echo $language->get('admin', 'fatal_log'); ?></a>
2500 </td>
2501 </tr>
2502 <tr>
2503 <td>
2504 <a href="<?php echo URL::build('/admin/core/', 'view=errors&log=notice'); ?>"><?php echo $language->get('admin', 'notice_log'); ?></a>
2505 </td>
2506 </tr>
2507 <tr>
2508 <td>
2509 <a href="<?php echo URL::build('/admin/core/', 'view=errors&log=warning'); ?>"><?php echo $language->get('admin', 'warning_log'); ?></a>
2510 </td>
2511 </tr>
2512 <tr>
2513 <td>
2514 <a href="<?php echo URL::build('/admin/core/', 'view=errors&log=other'); ?>"><?php echo $language->get('admin', 'other_log'); ?></a>
2515 </td>
2516 </tr>
2517 </table>
2518 </div>
2519 <?php
2520 } else {
2521 if (!in_array($_GET['log'], array('fatal', 'notice', 'warning', 'other'))) {
2522 Redirect::to(URL::build('/admin/core/', 'view=errors'));
2523 die();
2524 }
2525
2526 if (isset($_GET['do']) && $_GET['do'] == 'purge')
2527 file_put_contents(join(DIRECTORY_SEPARATOR, array(ROOT_PATH, 'cache', 'logs', $_GET['log'] . '-log.log')), '');
2528
2529 if (file_exists(join(DIRECTORY_SEPARATOR, array(ROOT_PATH, 'cache', 'logs', $_GET['log'] . '-log.log')))) {
2530 echo '
2531 <style>
2532 .error_log {
2533 width: 100%;
2534 height: 400px;
2535 padding: 0 10px;
2536 -webkit-box-sizing: border-box;
2537 -moz-box-sizing: border-box;
2538 box-sizing: border-box;
2539 overflow-y: scroll;
2540 overflow-x: scroll;
2541 white-space: initial;
2542 background-color: #eceeef;
2543 }
2544 </style>';
2545 echo '<pre class="error_log">';
2546 echo nl2br(Output::getClean(file_get_contents(join(DIRECTORY_SEPARATOR, array(ROOT_PATH, 'cache', 'logs', $_GET['log'] . '-log.log')))));
2547 echo '</pre>';
2548 echo '<hr /><h4>' . $language->get('general', 'actions') . '</h4>';
2549 echo '<a href="' . URL::build('/admin/core/', 'view=errors&log=' . $_GET['log'] . '&do=purge') . '" class="btn btn-warning" onclick="return confirm(\'' . $language->get('admin', 'confirm_purge_errors') . '\');">' . $language->get('admin', 'purge_errors') . '</a>';
2550 } else {
2551 echo '<div class="alert alert-info">' . $language->get('admin', 'log_file_not_found') . '</div>';
2552 }
2553 }
2554 break;
2555
2556 default:
2557 Redirect::to(URL::build('/admin/core'));
2558 die();
2559 break;
2560 }
2561 }
2562 ?>
2563 </div>
2564 </div>
2565 </div>
2566 </div>
2567</div>
2568
2569<?php require(ROOT_PATH . '/modules/Core/pages/admin/footer.php'); ?>
2570<?php require(ROOT_PATH . '/modules/Core/pages/admin/scripts.php'); ?>
2571
2572<script src="<?php if (defined('CONFIG_PATH')) echo CONFIG_PATH . '/'; else echo '/'; ?>core/assets/plugins/switchery/switchery.min.js"></script>
2573
2574<script>
2575 var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch'));
2576 elems.forEach(function (html) {
2577 var switchery = new Switchery(html);
2578 });
2579</script>
2580
2581<?php if (isset($_GET['view']) && ($_GET['view'] == 'maintenance' || $_GET['view'] == 'terms')) { ?>
2582 <script src="<?php if (defined('CONFIG_PATH')) echo CONFIG_PATH . '/'; else echo '/'; ?>core/assets/plugins/emoji/js/emojione.min.js"></script>
2583 <script src="<?php if (defined('CONFIG_PATH')) echo CONFIG_PATH . '/'; else echo '/'; ?>core/assets/plugins/ckeditor/plugins/spoiler/js/spoiler.js"></script>
2584 <script src="<?php if (defined('CONFIG_PATH')) echo CONFIG_PATH . '/'; else echo '/'; ?>core/assets/plugins/ckeditor/ckeditor.js"></script>
2585 <script src="<?php if (defined('CONFIG_PATH')) echo CONFIG_PATH . '/'; else echo '/'; ?>core/assets/plugins/ckeditor/plugins/emojione/dialogs/emojione.json"></script>
2586 <script type="text/javascript">
2587 <?php
2588 if ($_GET['view'] == 'maintenance')
2589 echo Input::createEditor('InputMaintenanceMessage');
2590 else {
2591 echo Input::createEditor('InputPrivacy');
2592 echo Input::createEditor('InputTerms');
2593 }
2594 ?>
2595 </script>
2596<?php } else if (isset($_GET['view']) && $_GET['view'] == 'avatars'){ ?>
2597 <script src="<?php if (defined('CONFIG_PATH')) echo CONFIG_PATH . '/'; else echo '/'; ?>core/assets/plugins/dropzone/dropzone.min.js"></script>
2598 <script src="<?php if (defined('CONFIG_PATH')) echo CONFIG_PATH . '/'; else echo '/'; ?>core/assets/plugins/image-picker/image-picker.min.js"></script>
2599
2600 <script>
2601 // Dropzone options
2602 Dropzone.options.upload_avatar_dropzone = {
2603 maxFilesize: 2,
2604 dictDefaultMessage: "<?php echo $language->get('admin', 'drag_files_here'); ?>",
2605 dictInvalidFileType: "<?php echo $language->get('admin', 'invalid_file_type'); ?>",
2606 dictFileTooBig: "<?php echo $language->get('admin', 'file_too_big'); ?>"
2607 };
2608
2609 $(".image-picker").imagepicker();
2610 </script>
2611<?php } ?>
2612</body>
2613</html>