2021-11-12 15:23:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2022-06-14 12:52:19 +00:00
|
|
|
* wishthis - Make a wish
|
2021-11-12 15:23:48 +00:00
|
|
|
*
|
|
|
|
* @author Jay Trees <github.jay@grandel.anonaddy.me>
|
|
|
|
*/
|
|
|
|
|
2022-06-09 06:37:52 +00:00
|
|
|
namespace wishthis;
|
|
|
|
|
2022-12-02 09:21:52 +00:00
|
|
|
define('VERSION', '1.0.0');
|
2022-01-27 11:53:39 +00:00
|
|
|
define('ROOT', __DIR__);
|
2022-03-25 13:57:14 +00:00
|
|
|
define('DEFAULT_LOCALE', 'en_GB');
|
2022-09-30 13:41:07 +00:00
|
|
|
define('COOKIE_PERSISTENT', 'wishthis_persistent');
|
2022-01-21 14:55:23 +00:00
|
|
|
|
2022-01-13 15:43:07 +00:00
|
|
|
/**
|
2021-11-12 15:23:48 +00:00
|
|
|
* Include
|
|
|
|
*/
|
2021-11-15 13:21:18 +00:00
|
|
|
require 'vendor/autoload.php';
|
2021-11-12 15:23:48 +00:00
|
|
|
|
2022-06-09 06:37:52 +00:00
|
|
|
$include = new \Grandel\IncludeDirectory(__DIR__ . '/src/functions');
|
|
|
|
|
|
|
|
spl_autoload_register(
|
2023-03-20 13:00:43 +00:00
|
|
|
function (string $absoluteNamespace) {
|
|
|
|
if (__NAMESPACE__ !== substr($absoluteNamespace, 0, strlen(__NAMESPACE__))) {
|
|
|
|
return;
|
2022-06-09 06:37:52 +00:00
|
|
|
}
|
|
|
|
|
2023-04-20 16:06:17 +00:00
|
|
|
$absoluteNamespace = str_replace('\\\\', '/', $absoluteNamespace);
|
|
|
|
|
2023-03-20 13:00:43 +00:00
|
|
|
$filepath = ROOT . '/src/classes/' . $absoluteNamespace . '.php';
|
2022-06-09 06:37:52 +00:00
|
|
|
|
|
|
|
require $filepath;
|
|
|
|
}
|
|
|
|
);
|
2021-11-12 15:23:48 +00:00
|
|
|
|
2022-09-22 14:37:24 +00:00
|
|
|
/**
|
|
|
|
* Config
|
|
|
|
*/
|
|
|
|
$configPath = __DIR__ . '/' . 'src/config/config.php';
|
|
|
|
|
|
|
|
if (file_exists($configPath)) {
|
|
|
|
require $configPath;
|
|
|
|
}
|
|
|
|
|
2022-06-27 08:33:01 +00:00
|
|
|
/**
|
|
|
|
* Session
|
|
|
|
*/
|
2022-09-22 09:35:48 +00:00
|
|
|
session_start(
|
|
|
|
array(
|
2022-09-30 13:41:07 +00:00
|
|
|
'name' => 'wishthis',
|
2022-09-22 09:35:48 +00:00
|
|
|
)
|
|
|
|
);
|
2022-06-27 08:33:01 +00:00
|
|
|
|
2022-11-08 11:38:43 +00:00
|
|
|
if (!isset($_SESSION['user'])) {
|
2022-06-27 08:33:01 +00:00
|
|
|
$_SESSION['user'] = new User();
|
|
|
|
}
|
|
|
|
|
2021-11-14 08:13:01 +00:00
|
|
|
/**
|
|
|
|
* Database
|
|
|
|
*/
|
2021-11-15 11:20:55 +00:00
|
|
|
$database = false;
|
2022-01-14 13:13:07 +00:00
|
|
|
$options = false;
|
2021-11-15 11:20:55 +00:00
|
|
|
|
2021-11-14 08:13:01 +00:00
|
|
|
if (
|
|
|
|
defined('DATABASE_HOST')
|
|
|
|
&& defined('DATABASE_NAME')
|
|
|
|
&& defined('DATABASE_USER')
|
|
|
|
&& defined('DATABASE_PASSWORD')
|
|
|
|
) {
|
2022-06-09 06:37:52 +00:00
|
|
|
$database = new Database(
|
2021-11-14 08:13:01 +00:00
|
|
|
DATABASE_HOST,
|
|
|
|
DATABASE_NAME,
|
|
|
|
DATABASE_USER,
|
|
|
|
DATABASE_PASSWORD
|
|
|
|
);
|
2021-11-15 11:20:55 +00:00
|
|
|
|
2022-01-14 13:13:07 +00:00
|
|
|
/**
|
|
|
|
* Options
|
|
|
|
*/
|
2022-06-09 06:37:52 +00:00
|
|
|
$options = new Options($database);
|
2022-01-14 13:13:07 +00:00
|
|
|
}
|
2022-01-14 09:50:48 +00:00
|
|
|
|
2022-09-30 13:41:07 +00:00
|
|
|
/**
|
|
|
|
* Persistent (stay logged in)
|
|
|
|
*/
|
2022-11-29 11:02:15 +00:00
|
|
|
if (isset($_COOKIE[COOKIE_PERSISTENT]) && $database && !$_SESSION['user']->isLoggedIn()) {
|
|
|
|
$sessions = $database
|
|
|
|
->query(
|
|
|
|
'SELECT *
|
|
|
|
FROM `sessions`
|
2023-01-28 13:25:53 +00:00
|
|
|
WHERE `session` = :session;',
|
|
|
|
array(
|
2023-03-20 13:00:43 +00:00
|
|
|
'session' => $_COOKIE[COOKIE_PERSISTENT],
|
2023-01-28 13:25:53 +00:00
|
|
|
)
|
2022-11-29 11:02:15 +00:00
|
|
|
)
|
|
|
|
->fetchAll();
|
|
|
|
|
|
|
|
if (false !== $sessions) {
|
|
|
|
foreach ($sessions as $session) {
|
|
|
|
$expires = strtotime($session['expires']);
|
|
|
|
|
|
|
|
if (time() < $expires) {
|
|
|
|
$_SESSION['user'] = User::getFromID($session['user']);
|
|
|
|
|
|
|
|
break;
|
2022-11-08 11:42:36 +00:00
|
|
|
}
|
2022-10-31 12:11:35 +00:00
|
|
|
}
|
2022-09-30 13:41:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-22 12:43:54 +00:00
|
|
|
/**
|
|
|
|
* Language
|
|
|
|
*/
|
2022-03-25 09:30:38 +00:00
|
|
|
\Locale::setDefault(DEFAULT_LOCALE);
|
|
|
|
|
2022-03-22 12:43:54 +00:00
|
|
|
/** Determine Locale */
|
2022-03-25 09:30:38 +00:00
|
|
|
$locales = array_filter(
|
2022-03-22 12:43:54 +00:00
|
|
|
array_map(
|
|
|
|
function ($value) {
|
2022-06-08 05:20:55 +00:00
|
|
|
$extension = pathinfo($value, PATHINFO_EXTENSION);
|
|
|
|
$filename = pathinfo($value, PATHINFO_FILENAME);
|
|
|
|
|
2022-06-09 09:56:24 +00:00
|
|
|
if ('po' === $extension) {
|
2022-03-22 12:43:54 +00:00
|
|
|
return pathinfo($value, PATHINFO_FILENAME);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
scandir(ROOT . '/translations')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2022-06-27 08:33:01 +00:00
|
|
|
$locale = isset($_REQUEST['locale']) ? $_REQUEST['locale'] : \Locale::lookup($locales, $_SESSION['user']->getLocale(), false, 'en_GB');
|
2022-03-22 12:43:54 +00:00
|
|
|
|
2022-03-22 13:28:26 +00:00
|
|
|
/**
|
|
|
|
* Wish
|
|
|
|
*/
|
2022-06-09 06:37:52 +00:00
|
|
|
Wish::initialize();
|
2022-03-22 13:28:26 +00:00
|
|
|
|
2022-04-08 13:25:34 +00:00
|
|
|
/**
|
|
|
|
* Pretty URLs
|
|
|
|
*/
|
2022-06-09 06:37:52 +00:00
|
|
|
$url = new URL($_SERVER['REQUEST_URI']);
|
2022-04-11 11:06:56 +00:00
|
|
|
|
2022-01-14 13:13:07 +00:00
|
|
|
/**
|
2022-03-27 08:15:50 +00:00
|
|
|
* Database Update
|
2022-01-14 13:13:07 +00:00
|
|
|
*/
|
2022-06-14 14:27:43 +00:00
|
|
|
if ($options && $options->getOption('isInstalled')) {
|
2022-03-27 08:15:50 +00:00
|
|
|
if (-1 === version_compare($options->version, VERSION)) {
|
|
|
|
$options->setOption('updateAvailable', true);
|
2022-01-14 13:13:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-12 15:23:48 +00:00
|
|
|
/**
|
|
|
|
* Page
|
|
|
|
*/
|
|
|
|
if (!isset($page)) {
|
2022-06-13 13:29:16 +00:00
|
|
|
$page = isset($_GET['page']) ? $_GET['page'] : 'home';
|
2021-11-12 15:23:48 +00:00
|
|
|
}
|
2022-01-26 12:06:36 +00:00
|
|
|
$pagePath = 'src/pages/' . $page . '.php';
|
2021-11-12 15:23:48 +00:00
|
|
|
|
2022-01-14 13:13:07 +00:00
|
|
|
if (file_exists($pagePath)) {
|
|
|
|
require $pagePath;
|
|
|
|
} else {
|
|
|
|
http_response_code(404);
|
|
|
|
?>
|
|
|
|
<h1>Not found</h1>
|
|
|
|
<p>The requested URL was not found on this server.</p>
|
|
|
|
<?php
|
2022-01-18 09:51:40 +00:00
|
|
|
echo $pagePath;
|
2022-01-14 13:13:07 +00:00
|
|
|
die();
|
|
|
|
}
|