wishthis/index.php

167 lines
2.9 KiB
PHP
Raw Normal View History

2021-11-12 15:23:48 +00:00
<?php
/**
* index.php
*
* @author Jay Trees <github.jay@grandel.anonaddy.me>
*/
/**
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
2021-12-12 10:22:40 +00:00
$include = new Grandel\IncludeDirectory(__DIR__ . '/includes/classes');
$include = new Grandel\IncludeDirectory(__DIR__ . '/includes/functions');
2021-11-12 15:23:48 +00:00
/**
2021-11-15 08:45:36 +00:00
* Config
2021-11-12 15:23:48 +00:00
*/
$configPath = __DIR__ . '/' . 'includes/config/config.php';
2021-11-12 15:23:48 +00:00
2021-11-14 08:13:01 +00:00
if (file_exists($configPath)) {
require $configPath;
}
/**
* 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')
) {
$database = new wishthis\Database(
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
*/
$options = new wishthis\Options($database);
}
2022-01-14 09:50:48 +00:00
/**
* Session
*/
session_start();
/**
* API
*/
if (isset($api)) {
return;
}
2021-11-15 11:20:55 +00:00
/**
* Install
*/
2022-01-14 09:53:53 +00:00
if (!$options) {
$page = 'install';
2021-11-12 15:23:48 +00:00
}
2022-01-18 13:37:35 +00:00
/**
* User
*/
if ($options) {
$user = new wishthis\User();
}
2022-01-14 13:13:07 +00:00
/**
* Update
*/
2022-01-21 13:12:15 +00:00
use Github\Client;
$client = new Client();
$release = $client->api('repo')->releases()->latest('grandeljay', 'wishthis');
$tag = $release['tag_name'];
2022-01-21 13:35:32 +00:00
$version = str_replace('v', '', $tag);
2022-01-21 13:12:15 +00:00
2022-01-21 13:38:02 +00:00
$zip_filename = __DIR__ . '/' . $tag . '.zip';
2022-01-21 13:12:15 +00:00
/** Download */
file_put_contents(
2022-01-21 13:38:02 +00:00
$zip_filename,
2022-01-21 13:12:15 +00:00
file_get_contents('https://github.com/grandeljay/wishthis/archive/refs/tags/' . $tag . '.zip')
);
/** Decompress */
$zip = new ZipArchive();
2022-01-21 13:38:02 +00:00
if ($zip->open($zip_filename)) {
2022-01-21 13:12:15 +00:00
$zip->extractTo(__DIR__);
$zip->close();
2022-01-21 13:35:32 +00:00
$directory_wishthis_github = __DIR__ . '/wishthis-' . $version;
foreach (scandir($directory_wishthis_github) as $filename) {
2022-01-21 14:26:00 +00:00
if (in_array($filename, array('.', '..', 'config'))) {
2022-01-21 13:35:32 +00:00
continue;
}
2022-01-21 14:11:05 +00:00
$filepath = __DIR__ . '/' . $filename;
$filepath_github = $directory_wishthis_github . '/' . $filename;
2022-01-21 13:35:32 +00:00
2022-01-21 14:11:05 +00:00
if (is_dir($filepath) && is_dir($filepath_github)) {
2022-01-21 13:49:26 +00:00
delete_directory($filepath);
}
2022-01-21 14:11:05 +00:00
rename($filepath_github, $filepath);
2022-01-21 13:35:32 +00:00
}
2022-01-21 13:12:15 +00:00
}
/** Delete */
2022-01-21 13:38:02 +00:00
unlink($zip_filename);
2022-01-21 13:12:15 +00:00
echo '<pre>';
var_Dump($release);
echo '</pre>';
die();
$releases = json_decode(file_get_contents('https://api.github.com/repos/grandeljay/wishthis/releases'));
$version = $releases[0]->tag_name;
die($version);
2022-01-21 07:15:13 +00:00
define('VERSION', '0.3.0');
2022-01-18 10:38:06 +00:00
2022-01-14 13:13:07 +00:00
if ($options) {
2022-01-18 10:38:06 +00:00
if (-1 === version_compare($options->version, VERSION)) {
2022-01-14 13:13:07 +00:00
$options->updateAvailable = true;
}
}
2022-01-18 11:43:28 +00:00
/**
* Wishlist
*/
if (!isset($_GET['page']) && isset($_GET['wishlist'])) {
$page = 'wishlist';
}
2021-11-12 15:23:48 +00:00
/**
* Page
*/
if (!isset($page)) {
$page = isset($_GET['page']) ? $_GET['page'] : 'home';
}
$pagePath = 'includes/pages/' . $page . '.php';
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();
}