Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
😑 Fixed bug detected in 1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
rodber committed Feb 19, 2019
1 parent f33b7e1 commit c9998cf
Show file tree
Hide file tree
Showing 7 changed files with 1,218 additions and 1,486 deletions.
2 changes: 1 addition & 1 deletion app/app.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
define('G_APP_NAME', 'Chevereto Free');
define('G_APP_VERSION', '1.1.2');
define('G_APP_VERSION', '1.1.3');
define('G_APP_GITHUB_OWNER', 'Chevereto');
define('G_APP_GITHUB_REPO', 'Chevereto-Free');
define('G_APP_GITHUB_REPO_URL', 'https://github.com/' . G_APP_GITHUB_OWNER . '/' . G_APP_GITHUB_REPO);
Expand Down
1 change: 1 addition & 0 deletions app/install/installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@
],
'1.1.1' => NULL,
'1.1.2' => NULL,
'1.1.3' => NULL,
];
// Settings that must be renamed from NAME to NEW NAME and DELETE old NAME
$settings_rename = [];
Expand Down
96 changes: 42 additions & 54 deletions lib/G/G.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@

namespace G;

if (!defined('access') or !access) {
die("This file cannot be directly accessed.");
}
if(!defined('access') or !access) die("This file cannot be directly accessed.");

define('G_VERSION', '1.0.42');

// Error reporting setup
@ini_set('log_errors', true);
@ini_set('log_errors', TRUE);
error_reporting(E_ALL ^ E_NOTICE);

// Set default locale
Expand All @@ -33,7 +31,7 @@
@ini_set('default_charset', 'utf-8');

// Set G\ paths and files
define('G_ROOT_PATH', rtrim(str_replace('\\', '/', dirname(dirname(__DIR__))), '/') . '/');
define('G_ROOT_PATH', rtrim(str_replace('\\','/', dirname(dirname(__DIR__))), '/') . '/');
define('G_ROOT_PATH_RELATIVE', rtrim(dirname($_SERVER['SCRIPT_NAME']), '\/') . '/');
define('G_ROOT_LIB_PATH', G_ROOT_PATH . 'lib/');
define('G_PATH', G_ROOT_LIB_PATH . 'G/');
Expand All @@ -54,100 +52,90 @@

// Include the static app config file
(file_exists(G_APP_PATH . 'settings.php')) ? require_once(G_APP_PATH . 'settings.php') : die("G\: Can't find app/settings.php");
if (headers_sent()) {
die(str_replace('%%FILE%%', 'app/settings.php', G_APP_SETTINGS_FILE_ERROR));
} // Stop on premature headers
if(headers_sent()) die(str_replace('%%FILE%%', 'app/settings.php', G_APP_SETTINGS_FILE_ERROR)); // Stop on premature headers

// TZ failover
$tz = @date_default_timezone_get();
$dtz = @date_default_timezone_set($tz);
if (!$dtz && !@date_default_timezone_set('America/Santiago')) {
die(strtr('Invalid timezone identifier: %i. Configure php.ini with a valid timezone identifier %l', ['%i' => $tz, '%l' => 'http://php.net/manual/en/timezones.php']));
if(!$dtz && !@date_default_timezone_set('America/Santiago')) {
die(strtr('Invalid timezone identifier: %i. Configure php.ini with a valid timezone identifier %l', ['%i' => $tz, '%l' => 'http://php.net/manual/en/timezones.php']));
}

// Session hack
if ($settings['session.save_path']) {
session_save_path($settings['session.save_path']);
if($settings['session.save_path']) {
session_save_path($settings['session.save_path']);
}

// Can work with sessions?
if (!@session_start()) {
die("G\: Sessions are not working on this server (session_start).");
}
if(!@session_start()) die("G\: Sessions are not working on this server (session_start).");

// Is session save path OK? (you won't believe how many people has session issues!)
$session_save_path = @realpath(session_save_path());
if ($session_save_path) { // realpath on this needs pre-webroot directories access
foreach (['write'] as $k) {
$fn = 'is_' . $k . 'able';
if (!$fn($session_save_path)) {
$session_errors[] = $k;
}
}
if (isset($session_errors)) {
die(strtr("G\: Sessions are not working on this server due to missing %s permission on session save path (%f session.save_path).", ['%s' => implode('/', $session_errors), '%f' => $settings['session.save_path'] ? 'app/settings.php' : 'php.ini']));
}
if($session_save_path) { // realpath on this needs pre-webroot directories access
foreach(['write'] as $k) {
$fn = 'is_' . $k . 'able';
if(!$fn($session_save_path)) $session_errors[] = $k;
}
if(isset($session_errors)) die(strtr("G\: Sessions are not working on this server due to missing %s permission on session save path (%f session.save_path).", ['%s' => implode('/', $session_errors), '%f' => $settings['session.save_path'] ? 'app/settings.php' : 'php.ini']));
}

// Are sessions working properly?
$_SESSION['G'] = true;
if (!$_SESSION['G']) {
die("G\: Sessions are not working properly. Check for any conflicting server setting.");
}
$_SESSION['G'] = TRUE;
if(!$_SESSION['G']) die("G\: Sessions are not working properly. Check for any conflicting server setting.");

// Set the starting execution time
define('G_APP_TIME_EXECUTION_START', microtime(true));

// Include G\ core functions
(file_exists(__DIR__ . '/functions.php')) ? require_once(__DIR__ . '/functions.php') : die("G\: Can't find <strong>" . __DIR__ . '/functions.php' . '</strong>. Make sure that this file exists.');
if (file_exists(__DIR__ . '/functions.render.php')) {
require_once(__DIR__ . '/functions.render.php');
if(file_exists(__DIR__ . '/functions.render.php')) {
require_once(__DIR__ . '/functions.render.php');
}

if (isset($settings) && $settings['error_reporting'] === false) {
error_reporting(0);
if(isset($settings) && $settings['error_reporting'] === false) {
error_reporting(0);
}

// Set the default timezone
if (isset($settings['default_timezone']) && is_valid_timezone($settings['default_timezone'])) {
if (!@date_default_timezone_set($settings['default_timezone'])) {
die(strtr("G\: Can't set %s timezone on line %l", ['%s' => $settings['default_timezone'], '%l' => __LINE__ - 1]));
}
if(isset($settings['default_timezone']) && is_valid_timezone($settings['default_timezone'])) {
if(!@date_default_timezone_set($settings['default_timezone'])) {
die(strtr("G\: Can't set %s timezone on line %l", ['%s' => $settings['default_timezone'], '%l' => __LINE__ - 1]));
}
}

// Set the system environment
if (isset($settings['environment'])) {
define('G_APP_ENV', $settings['environment']);
if(isset($settings['environment'])) {
define('G_APP_ENV', $settings['environment']);
}

// Set the HTTP definitions
define('G_HTTP_HOST', $_SERVER['HTTP_HOST']);
define('G_HTTP_PROTOCOL', 'http' . ((((!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') || $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') || $settings['https']) ? 's' : null));
define('G_HTTP_PROTOCOL', 'http' . ((((!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) || $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') || $settings['https']) ? 's' : NULL));

// La cumbia me divierte y mesita

// Fix some $_SERVER vars
$_SERVER['SCRIPT_FILENAME'] = forward_slash($_SERVER['SCRIPT_FILENAME']);
$_SERVER['SCRIPT_NAME'] = forward_slash($_SERVER['SCRIPT_NAME']);
// Fix CloudFlare REMOTE_ADDR
if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
if(isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
}

// Inherit application definitions
if (file_exists(G_APP_PATH . 'app.php')) {
require_once(G_APP_PATH . 'app.php');
if(file_exists(G_APP_PATH . 'app.php')) {
require_once(G_APP_PATH . 'app.php');
}

// Set the DB constants
foreach (['host', 'port', 'name', 'user', 'pass', 'driver', 'pdo_attrs'] as $k) {
define('G_APP_DB_' . strtoupper($k), isset($settings['db_' . $k]) ? (is_array($settings['db_' . $k]) ? serialize($settings['db_' . $k]) : $settings['db_' . $k]) : null);
foreach(['host', 'port', 'name', 'user', 'pass', 'driver', 'pdo_attrs'] as $k) {
define('G_APP_DB_' . strtoupper($k), isset($settings['db_' . $k]) ? (is_array($settings['db_' . $k]) ? serialize($settings['db_' . $k]) : $settings['db_' . $k]) : NULL);
}

// Include app functions
(file_exists(G_APP_FILE_FUNCTIONS)) ? require_once(G_APP_FILE_FUNCTIONS) : die("G\: Can't find <strong>" . G_APP_FILE_FUNCTIONS . '</strong>. Make sure that this file exists.');
if (file_exists(G_APP_FILE_FUNCTIONS_RENDER)) {
require_once(G_APP_FILE_FUNCTIONS_RENDER);
if(file_exists(G_APP_FILE_FUNCTIONS_RENDER)) {
require_once(G_APP_FILE_FUNCTIONS_RENDER);
}

// Set the URLs
Expand All @@ -157,11 +145,11 @@

// Define the app theme
define('G_APP_PATH_THEMES', G_APP_PATH . 'themes/');
if (!file_exists(G_APP_PATH_THEMES)) {
die("G\: Theme path doesn't exists!");
if(!file_exists(G_APP_PATH_THEMES)) {
die("G\: Theme path doesn't exists!");
}

if (isset($settings['theme']) and file_exists(G_APP_PATH_THEMES . $settings['theme'])) {
define('G_APP_PATH_THEME', G_APP_PATH_THEMES . $settings['theme'].'/');
define('BASE_URL_THEME', absolute_to_url(G_APP_PATH_THEME));
}
if(isset($settings['theme']) and file_exists(G_APP_PATH_THEMES . $settings['theme'])) {
define('G_APP_PATH_THEME', G_APP_PATH_THEMES . $settings['theme'].'/');
define('BASE_URL_THEME', absolute_to_url(G_APP_PATH_THEME));
}
Loading

0 comments on commit c9998cf

Please sign in to comment.