🐛Removed old links (G\ Library)
This commit is contained in:
parent
b1e0ab8b91
commit
f33b7e1a50
13 changed files with 1492 additions and 1218 deletions
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
define('G_APP_NAME', 'Chevereto Free');
|
||||
define('G_APP_VERSION', '1.1.1');
|
||||
define('G_APP_VERSION', '1.1.2');
|
||||
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);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
/* --------------------------------------------------------------------
|
||||
|
||||
G\ library
|
||||
http://gbackslash.com
|
||||
https://g.chevereto.com
|
||||
|
||||
@author Rodolfo Berrios A. <http://rodolfoberrios.com/>
|
||||
|
||||
|
|
|
@ -253,6 +253,7 @@ try {
|
|||
'listing_viewer' => 1,
|
||||
],
|
||||
'1.1.1' => NULL,
|
||||
'1.1.2' => NULL,
|
||||
];
|
||||
// Settings that must be renamed from NAME to NEW NAME and DELETE old NAME
|
||||
$settings_rename = [];
|
||||
|
|
|
@ -136,7 +136,7 @@ $route = function ($handler) {
|
|||
],
|
||||
'g_version' => [
|
||||
'label' => 'G\\',
|
||||
'content' => '<a href="http://gbackslash.com" target="_blank">G\\ Library '.G\get_version().'</a>'
|
||||
'content' => '<a href="https://g.chevereto.com" target="_blank">G\\ Library '.G\get_version().'</a>'
|
||||
],
|
||||
'php_version' => [
|
||||
'label' => _s('PHP version'),
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<?php if(!defined('access') or !access) die('This file cannot be directly accessed.'); ?>
|
||||
<?php if (!defined('access') or !access) {
|
||||
die('This file cannot be directly accessed.');
|
||||
} ?>
|
||||
<?php G\Render\include_theme_header(); ?>
|
||||
|
||||
<div class="content-width">
|
||||
|
@ -20,7 +22,7 @@
|
|||
|
||||
<h2>More help</h2>
|
||||
|
||||
<p>If you need more help we suggest you to go to <a href="https://goo.gl/WL85Wx">Chevereto</a> support and read the <a href="http://gbackslash.com/docs">G\ Library documentation</a>. View the code of this file will also help you to understand the magic behind this system.</p>
|
||||
<p>If you need more help we suggest you to go to <a href="https://chevereto.com/support">Chevereto support</a> and read the <a href="https://g.chevereto.com/docs">G\ Library documentation</a>. View the code of this file will also help you to understand the magic behind this system.</p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<?php if(!defined('access') or !access) die('This file cannot be directly accessed.'); ?>
|
||||
<?php if (!defined('access') or !access) {
|
||||
die('This file cannot be directly accessed.');
|
||||
} ?>
|
||||
<?php G\Render\include_theme_header(); ?>
|
||||
|
||||
<div class="content-width">
|
||||
|
@ -20,7 +22,7 @@
|
|||
|
||||
<h2>More help</h2>
|
||||
|
||||
<p>If you need more help we suggest you to go to <a href="https://goo.gl/WL85Wx">Chevereto</a> support and read the <a href="http://gbackslash.com/docs">G\ Library documentation</a>. View the code of this file will also help you to understand the magic behind this system.</p>
|
||||
<p>If you need more help we suggest you to go to <a href="https://chevereto.com/support">Chevereto support</a> and read the <a href="https://g.chevereto.com/docs">G\ Library documentation</a>. View the code of this file will also help you to understand the magic behind this system.</p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
|
98
lib/G/G.php
98
lib/G/G.php
|
@ -3,7 +3,7 @@
|
|||
/* --------------------------------------------------------------------
|
||||
|
||||
G\ library
|
||||
http://gbackslash.com
|
||||
https://g.chevereto.com
|
||||
|
||||
@author Rodolfo Berrios A. <http://rodolfoberrios.com/>
|
||||
|
||||
|
@ -16,12 +16,14 @@
|
|||
|
||||
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
|
||||
|
@ -31,7 +33,7 @@ setlocale(LC_ALL, 'en_US.UTF8');
|
|||
@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/');
|
||||
|
@ -52,65 +54,75 @@ define('G_APP_SETTINGS_FILE_ERROR', '<br />There are errors in the <strong>%%FIL
|
|||
|
||||
// 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
|
||||
|
||||
|
@ -118,24 +130,24 @@ define('G_HTTP_PROTOCOL', 'http' . ((((!empty($_SERVER['HTTPS']) && strtolower($
|
|||
$_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
|
||||
|
@ -145,11 +157,11 @@ define("G_APP_LIB_URL", absolute_to_url(G_APP_PATH_LIB));
|
|||
|
||||
// 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));
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -3,7 +3,7 @@
|
|||
/* --------------------------------------------------------------------
|
||||
|
||||
G\ library
|
||||
http://gbackslash.com
|
||||
https://g.chevereto.com
|
||||
|
||||
@author Rodolfo Berrios A. <http://rodolfoberrios.com/>
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -3,7 +3,7 @@
|
|||
/* --------------------------------------------------------------------
|
||||
|
||||
G\ library
|
||||
http://gbackslash.com
|
||||
https://g.chevereto.com
|
||||
|
||||
@author Rodolfo Berrios A. <http://rodolfoberrios.com/>
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
/* --------------------------------------------------------------------
|
||||
|
||||
G\ library
|
||||
http://gbackslash.com
|
||||
https://g.chevereto.com
|
||||
|
||||
@author Rodolfo Berrios A. <http://rodolfoberrios.com/>
|
||||
|
||||
|
@ -310,9 +310,12 @@ namespace G {
|
|||
*/
|
||||
function abbreviate_number($number)
|
||||
{
|
||||
|
||||
// strip any formatting
|
||||
$number = (0+str_replace(',', '', $number));
|
||||
if ($number === null) {
|
||||
$number = 0;
|
||||
} else {
|
||||
// strip any formatting
|
||||
$number = (0+str_replace(',', '', $number));
|
||||
}
|
||||
|
||||
// Not a number, keep it "as is"
|
||||
if (!is_numeric($number) or $number == 0) {
|
||||
|
@ -560,7 +563,7 @@ namespace G {
|
|||
function exception_to_error($e, $die=true)
|
||||
{
|
||||
$internal_code = 500;
|
||||
$internal_error = '<b>'.G_APP_NAME.' error:</b> ' . get_set_status_header_desc($internal_code);
|
||||
$internal_error = '<b>Aw, snap!</b> ' . get_set_status_header_desc($internal_code) . ' - Check your error_log or enable debug_mode = 3 (chevereto.com/docs/debug).';
|
||||
|
||||
set_status_header($internal_code);
|
||||
|
||||
|
@ -816,18 +819,20 @@ namespace G {
|
|||
|
||||
function get_client_ip()
|
||||
{
|
||||
$client_ip = !empty($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : (!empty($_ENV['REMOTE_ADDR']) ? $_ENV['REMOTE_ADDR'] : null);
|
||||
|
||||
if (array_key_exists('HTTP_CF_CONNECTING_IP', $_SERVER) && $_SERVER['HTTP_CF_CONNECTING_IP'] == $_SERVER['REMOTE_ADDR']) {
|
||||
return $_SERVER['HTTP_CF_CONNECTING_IP'];
|
||||
if(isset($_SERVER['G_CLIENT_IP'])) {
|
||||
return $_SERVER['G_CLIENT_IP'];
|
||||
}
|
||||
|
||||
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||||
if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
|
||||
$client_ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
|
||||
} else {
|
||||
$client_ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
|
||||
}
|
||||
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $client_ip != $_SERVER['HTTP_X_FORWARDED_FOR']) {
|
||||
$entries = preg_split('/[\s,]/', $_SERVER['HTTP_X_FORWARDED_FOR'], -1, PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
reset($entries);
|
||||
|
||||
while (list(, $entry) = each($entries)) {
|
||||
foreach ($entries as $entry) {
|
||||
$entry = trim($entry);
|
||||
if (preg_match('/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/', $entry, $ip_list)) {
|
||||
$private_ip = array(
|
||||
|
@ -838,7 +843,6 @@ namespace G {
|
|||
'/^10\..*/');
|
||||
|
||||
$found_ip = preg_replace($private_ip, $client_ip, $ip_list[1]);
|
||||
|
||||
if ($client_ip != $found_ip) { // and !isset($_SERVER['HTTP_CF_CONNECTING_IP']
|
||||
$client_ip = $found_ip;
|
||||
break;
|
||||
|
@ -846,7 +850,7 @@ namespace G {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
$_SERVER['G_CLIENT_IP'] = $client_ip;
|
||||
return $client_ip;
|
||||
}
|
||||
|
||||
|
@ -1129,6 +1133,23 @@ namespace G {
|
|||
return $path;
|
||||
}
|
||||
|
||||
function rrmdir($dir)
|
||||
{
|
||||
if (is_dir($dir)) {
|
||||
$objects = scandir($dir);
|
||||
foreach ($objects as $object) {
|
||||
if ($object != "." && $object != "..") {
|
||||
if (is_dir($dir."/".$object)) {
|
||||
rrmdir($dir."/".$object);
|
||||
} else {
|
||||
unlink($dir."/".$object);
|
||||
}
|
||||
}
|
||||
}
|
||||
rmdir($dir);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a sanitized string, typically for URLs
|
||||
* This function was borrowed from chyrp.net (MIT License)
|
||||
|
@ -1438,7 +1459,7 @@ namespace G {
|
|||
function relative_to_url($filepath, $root_url=null)
|
||||
{
|
||||
if (!check_value($root_url)) {
|
||||
$root_url = G_ROOT_URL;
|
||||
$root_url = get_root_url();
|
||||
}
|
||||
return str_replace(G_ROOT_PATH_RELATIVE, $root_url, forward_slash($filepath));
|
||||
}
|
||||
|
@ -1447,7 +1468,7 @@ namespace G {
|
|||
function url_to_relative($url, $root_url=null)
|
||||
{
|
||||
if (!check_value($root_url)) {
|
||||
$root_url = G_ROOT_URL;
|
||||
$root_url = get_root_url();
|
||||
}
|
||||
return str_replace($root_url, G_ROOT_PATH_RELATIVE, $url);
|
||||
}
|
||||
|
@ -1462,7 +1483,7 @@ namespace G {
|
|||
function absolute_to_url($filepath, $root_url=null)
|
||||
{
|
||||
if (!check_value($root_url)) {
|
||||
$root_url = G_ROOT_URL;
|
||||
$root_url = get_root_url();
|
||||
}
|
||||
if (G_ROOT_PATH === G_ROOT_PATH_RELATIVE) {
|
||||
return $root_url . ltrim($filepath, '/');
|
||||
|
@ -1474,7 +1495,7 @@ namespace G {
|
|||
function url_to_absolute($url, $root_url=null)
|
||||
{
|
||||
if (!check_value($root_url)) {
|
||||
$root_url = G_ROOT_URL;
|
||||
$root_url = get_root_url();
|
||||
}
|
||||
return str_replace($root_url, G_ROOT_PATH, $url);
|
||||
}
|
||||
|
@ -1508,21 +1529,43 @@ namespace G {
|
|||
return get_global('settings')[$key];
|
||||
}
|
||||
|
||||
function get_domain()
|
||||
{
|
||||
return HTTP_HOST;
|
||||
}
|
||||
|
||||
function get_base_url($path='')
|
||||
{
|
||||
$path = sanitize_relative_path($path);
|
||||
$return = G_ROOT_URL . ltrim($path, '/');
|
||||
$return = get_root_url() . ltrim($path, '/');
|
||||
return rtrim($return, '/');
|
||||
}
|
||||
|
||||
function get_current_url()
|
||||
function get_host()
|
||||
{
|
||||
return get_base_url(preg_replace('#'.G_ROOT_PATH_RELATIVE.'#', '', $_SERVER['REQUEST_URI'], 1));
|
||||
return defined('APP_G_HTTP_HOST') ? APP_G_HTTP_HOST : G_HTTP_HOST;
|
||||
}
|
||||
|
||||
function get_root_url()
|
||||
{
|
||||
return defined('APP_G_ROOT_URL') ? APP_G_ROOT_URL : G_ROOT_URL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string Querystring keys to remove (comma separated)
|
||||
*/
|
||||
function get_current_url($safe=true, $removeQs=[])
|
||||
{
|
||||
$request_uri = $_SERVER['REQUEST_URI'];
|
||||
$request_path = rtrim(strtok($request_uri, '?'), '/');
|
||||
if ($_SERVER['QUERY_STRING'] && $removeQs) {
|
||||
parse_str($_SERVER['QUERY_STRING'], $parse);
|
||||
foreach ($removeQs as $v) {
|
||||
unset($parse[$v]);
|
||||
}
|
||||
$querystring = $parse ? http_build_query($parse) : null;
|
||||
$request_uri = $request_path;
|
||||
if ($querystring) {
|
||||
$request_uri .= '/?' . $querystring;
|
||||
}
|
||||
}
|
||||
$path = preg_replace('#'.G_ROOT_PATH_RELATIVE.'#', '', rtrim($request_uri, '/') . '/', 1);
|
||||
return get_base_url($path);
|
||||
}
|
||||
|
||||
function settings_has_db_info()
|
||||
|
@ -1894,9 +1937,26 @@ namespace G {
|
|||
return basename($file);
|
||||
}
|
||||
|
||||
function get_filename_without_extension($file)
|
||||
function get_basename_without_extension($filename)
|
||||
{
|
||||
return preg_replace('/\\.[^.\\s]{2,4}$/', '', basename($file));
|
||||
$extension = pathinfo($filename, PATHINFO_EXTENSION);
|
||||
$filename = basename($filename);
|
||||
return str_replace_last(".$extension", null, $filename);
|
||||
}
|
||||
|
||||
function get_pathname_without_extension($filename)
|
||||
{
|
||||
$extension = pathinfo($filename, PATHINFO_EXTENSION);
|
||||
return str_replace_last(".$extension", null, $filename);
|
||||
}
|
||||
|
||||
function change_pathname_extension($filename, $extension)
|
||||
{
|
||||
$chop = get_pathname_without_extension($filename);
|
||||
if ($chop == $filename) {
|
||||
return $filename;
|
||||
}
|
||||
return "$chop.$extension";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2202,9 +2262,9 @@ namespace G {
|
|||
// https://github.com/Chevereto/Chevereto-Free/pull/35
|
||||
function imagecreatefrombmp($file)
|
||||
{
|
||||
if (function_exists('imagecreatefrombmp')) {
|
||||
return imagecreatefrombmp($file);
|
||||
}
|
||||
// if (function_exists('imagecreatefrombmp')) {
|
||||
// return imagecreatefrombmp($file);
|
||||
// }
|
||||
// version 1.00
|
||||
if (!($fh = fopen($file, 'rb'))) {
|
||||
trigger_error('imagecreatefrombmp: Can not open ' . $file, E_USER_WARNING);
|
||||
|
@ -2525,6 +2585,126 @@ namespace G {
|
|||
return trim(preg_replace('/\s*(?:\*\/|\?>).*/', '', $string));
|
||||
}
|
||||
|
||||
/**
|
||||
* function xml2array
|
||||
*
|
||||
* This function is part of the PHP manual.
|
||||
*
|
||||
* The PHP manual text and comments are covered by the Creative Commons
|
||||
* Attribution 3.0 License, copyright (c) the PHP Documentation Group
|
||||
*
|
||||
* @author k dot antczak at livedata dot pl
|
||||
* @date 2011-04-22 06:08 UTC
|
||||
* @link http://www.php.net/manual/en/ref.simplexml.php#103617
|
||||
* @license http://www.php.net/license/index.php#doc-lic
|
||||
* @license http://creativecommons.org/licenses/by/3.0/
|
||||
* @license CC-BY-3.0 <http://spdx.org/licenses/CC-BY-3.0>
|
||||
*/
|
||||
function xml2array($xmlObject, $out = array())
|
||||
{
|
||||
foreach ((array) $xmlObject as $index => $node) {
|
||||
$out[$index] = (is_object($node)) ? xml2array($node) : $node;
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $domain Pass $_SERVER['SERVER_NAME'] here
|
||||
* @param bool $debug
|
||||
*
|
||||
* @debug bool $debug
|
||||
* @return string
|
||||
*
|
||||
* @link https://gist.github.com/pocesar/5366899
|
||||
*/
|
||||
function get_domain($domain, $debug = false)
|
||||
{
|
||||
$original = $domain = strtolower($domain);
|
||||
if (filter_var($domain, FILTER_VALIDATE_IP)) { return $domain; }
|
||||
$debug ? print('<strong style="color:green">»</strong> Parsing: '.$original) : false;
|
||||
$arr = array_slice(array_filter(explode('.', $domain, 4), function($value){
|
||||
return $value !== 'www';
|
||||
}), 0); //rebuild array indexes
|
||||
if (count($arr) > 2)
|
||||
{
|
||||
$count = count($arr);
|
||||
$_sub = explode('.', $count === 4 ? $arr[3] : $arr[2]);
|
||||
$debug ? print(" (parts count: {$count})") : false;
|
||||
if (count($_sub) === 2) // two level TLD
|
||||
{
|
||||
$removed = array_shift($arr);
|
||||
if ($count === 4) // got a subdomain acting as a domain
|
||||
{
|
||||
$removed = array_shift($arr);
|
||||
}
|
||||
$debug ? print("<br>\n" . '[*] Two level TLD: <strong>' . join('.', $_sub) . '</strong> ') : false;
|
||||
}
|
||||
elseif (count($_sub) === 1) // one level TLD
|
||||
{
|
||||
$removed = array_shift($arr); //remove the subdomain
|
||||
if (strlen($_sub[0]) === 2 && $count === 3) // TLD domain must be 2 letters
|
||||
{
|
||||
array_unshift($arr, $removed);
|
||||
}
|
||||
else
|
||||
{
|
||||
// non country TLD according to IANA
|
||||
$tlds = array(
|
||||
'aero',
|
||||
'arpa',
|
||||
'asia',
|
||||
'biz',
|
||||
'cat',
|
||||
'com',
|
||||
'coop',
|
||||
'edu',
|
||||
'gov',
|
||||
'info',
|
||||
'jobs',
|
||||
'mil',
|
||||
'mobi',
|
||||
'museum',
|
||||
'name',
|
||||
'net',
|
||||
'org',
|
||||
'post',
|
||||
'pro',
|
||||
'tel',
|
||||
'travel',
|
||||
'xxx',
|
||||
);
|
||||
if (count($arr) > 2 && in_array($_sub[0], $tlds) !== false) //special TLD don't have a country
|
||||
{
|
||||
array_shift($arr);
|
||||
}
|
||||
}
|
||||
$debug ? print("<br>\n" .'[*] One level TLD: <strong>'.join('.', $_sub).'</strong> ') : false;
|
||||
}
|
||||
else // more than 3 levels, something is wrong
|
||||
{
|
||||
for ($i = count($_sub); $i > 1; $i--)
|
||||
{
|
||||
$removed = array_shift($arr);
|
||||
}
|
||||
$debug ? print("<br>\n" . '[*] Three level TLD: <strong>' . join('.', $_sub) . '</strong> ') : false;
|
||||
}
|
||||
}
|
||||
elseif (count($arr) === 2)
|
||||
{
|
||||
$arr0 = array_shift($arr);
|
||||
if (strpos(join('.', $arr), '.') === false
|
||||
&& in_array($arr[0], array('localhost','test','invalid')) === false) // not a reserved domain
|
||||
{
|
||||
$debug ? print("<br>\n" .'Seems invalid domain: <strong>'.join('.', $arr).'</strong> re-adding: <strong>'.$arr0.'</strong> ') : false;
|
||||
// seems invalid domain, restore it
|
||||
array_unshift($arr, $arr0);
|
||||
}
|
||||
}
|
||||
$debug ? print("<br>\n".'<strong style="color:gray">«</strong> Done parsing: <span style="color:red">' . $original . '</span> as <span style="color:blue">'. join('.', $arr) ."</span><br>\n") : false;
|
||||
return join('.', $arr);
|
||||
}
|
||||
|
||||
} // G Namespace
|
||||
|
||||
// Global namespace
|
||||
|
@ -2767,5 +2947,4 @@ namespace {
|
|||
return $status === 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,18 +3,19 @@
|
|||
/* --------------------------------------------------------------------
|
||||
|
||||
G\ library
|
||||
http://gbackslash.com
|
||||
https://g.chevereto.com
|
||||
|
||||
@author Rodolfo Berrios A. <http://rodolfoberrios.com/>
|
||||
|
||||
Copyright (c) Rodolfo Berrios <inbox@rodolfoberrios.com> All rights reserved.
|
||||
|
||||
|
||||
Licensed under the MIT license
|
||||
http://opensource.org/licenses/MIT
|
||||
|
||||
|
||||
--------------------------------------------------------------------- */
|
||||
|
||||
namespace G\Render;
|
||||
|
||||
use G;
|
||||
|
||||
/**
|
||||
|
@ -22,34 +23,38 @@ use G;
|
|||
* ---------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
function include_theme_file($filename, $args=[]) {
|
||||
$file = G_APP_PATH_THEME . $filename;
|
||||
$override = G_APP_PATH_THEME . 'overrides/' . $filename;
|
||||
if(!file_exists($file)) {
|
||||
$file .= '.php';
|
||||
$override .= '.php';
|
||||
}
|
||||
if(file_exists($override)) {
|
||||
$file = $override;
|
||||
}
|
||||
if(file_exists($file)) {
|
||||
$GLOBALS['theme_include_args'] = $args;
|
||||
include($file);
|
||||
unset($GLOBALS['theme_include_args']);
|
||||
}
|
||||
function include_theme_file($filename, $args=[])
|
||||
{
|
||||
$file = G_APP_PATH_THEME . $filename;
|
||||
$override = G_APP_PATH_THEME . 'overrides/' . $filename;
|
||||
if (!file_exists($file)) {
|
||||
$file .= '.php';
|
||||
$override .= '.php';
|
||||
}
|
||||
if (file_exists($override)) {
|
||||
$file = $override;
|
||||
}
|
||||
if (file_exists($file)) {
|
||||
$GLOBALS['theme_include_args'] = $args;
|
||||
include($file);
|
||||
unset($GLOBALS['theme_include_args']);
|
||||
}
|
||||
}
|
||||
|
||||
function include_theme_header() {
|
||||
include_theme_file('header');
|
||||
function include_theme_header()
|
||||
{
|
||||
include_theme_file('header');
|
||||
}
|
||||
|
||||
function include_theme_footer() {
|
||||
include_theme_file('footer');
|
||||
function include_theme_footer()
|
||||
{
|
||||
include_theme_file('footer');
|
||||
}
|
||||
|
||||
function get_theme_file_contents($filename) {
|
||||
$file = G_APP_PATH_THEME . $filename;
|
||||
return file_exists($file) ? file_get_contents($file) : null;
|
||||
function get_theme_file_contents($filename)
|
||||
{
|
||||
$file = G_APP_PATH_THEME . $filename;
|
||||
return file_exists($file) ? file_get_contents($file) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,8 +62,9 @@ function get_theme_file_contents($filename) {
|
|||
* ---------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
function get_theme_file_url($string) {
|
||||
return BASE_URL_THEME . $string;
|
||||
function get_theme_file_url($string)
|
||||
{
|
||||
return BASE_URL_THEME . $string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,13 +73,15 @@ function get_theme_file_url($string) {
|
|||
*/
|
||||
|
||||
// Return app lib file url
|
||||
function get_app_lib_file_url($string){
|
||||
return G_APP_LIB_URL . $string;
|
||||
function get_app_lib_file_url($string)
|
||||
{
|
||||
return (defined('APP_G_APP_LIB_URL') ? APP_G_APP_LIB_URL : G_APP_LIB_URL) . $string;
|
||||
}
|
||||
|
||||
// Returns the HTML input with the auth token
|
||||
function get_input_auth_token($name='auth_token') {
|
||||
return '<input type="hidden" name="'.$name.'" value="'.G\Handler::getAuthToken().'">';
|
||||
function get_input_auth_token($name='auth_token')
|
||||
{
|
||||
return '<input type="hidden" name="'.$name.'" value="'. G\Handler::getAuthToken() . '">';
|
||||
}
|
||||
|
||||
|
||||
|
@ -83,80 +91,84 @@ function get_input_auth_token($name='auth_token') {
|
|||
*/
|
||||
|
||||
// Outputs the REST_API array to xml
|
||||
function xml_output($array=array()) {
|
||||
error_reporting(0);
|
||||
//@ini_set('display_errors', false);
|
||||
if(ob_get_level() === 0 and !ob_start('ob_gzhandler')) {
|
||||
ob_start();
|
||||
}
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")."GMT");
|
||||
header("Cache-Control: no-cache, must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Content-Type:text/xml; charset=UTF-8");
|
||||
$out = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
|
||||
$out .= "<response>\n";
|
||||
$out .= " <status_code>$array[status_code]</status_code>\n";
|
||||
$out .= " <status_txt>$array[status_txt]</status_txt>\n";
|
||||
if(count($array["data"])>0) {
|
||||
$out .= " <data>\n";
|
||||
foreach($array["data"] as $key => $value) {
|
||||
$out .= " <$key>$value</$key>\n";
|
||||
}
|
||||
$out .= " </data>\n";
|
||||
}
|
||||
$out .= "</response>";
|
||||
echo $out;
|
||||
function xml_output($array=array())
|
||||
{
|
||||
error_reporting(0);
|
||||
//@ini_set('display_errors', false);
|
||||
if (ob_get_level() === 0 and !ob_start('ob_gzhandler')) {
|
||||
ob_start();
|
||||
}
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")."GMT");
|
||||
header("Cache-Control: no-cache, must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Content-Type:text/xml; charset=UTF-8");
|
||||
$out = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
|
||||
$out .= "<response>\n";
|
||||
$out .= " <status_code>$array[status_code]</status_code>\n";
|
||||
$out .= " <status_txt>$array[status_txt]</status_txt>\n";
|
||||
if (count($array["data"])>0) {
|
||||
$out .= " <data>\n";
|
||||
foreach ($array["data"] as $key => $value) {
|
||||
$out .= " <$key>$value</$key>\n";
|
||||
}
|
||||
$out .= " </data>\n";
|
||||
}
|
||||
$out .= "</response>";
|
||||
echo $out;
|
||||
}
|
||||
|
||||
// Procedural function to output an array to json
|
||||
function json_output($data=[], $callback=NULL) {
|
||||
error_reporting(0);
|
||||
//@ini_set('display_errors', false);
|
||||
if(ob_get_level() === 0 and !ob_start('ob_gzhandler')) ob_start();
|
||||
header('Last-Modified: '.gmdate('D, d M Y H:i:s').'GMT');
|
||||
header('Cache-Control: no-cache, must-revalidate');
|
||||
header('Pragma: no-cache');
|
||||
header('Content-type: application/json; charset=UTF-8');
|
||||
|
||||
// Invalid json request
|
||||
if(!G\check_value($data) || (G\check_value($callback) and preg_match('/\W/', $callback))) {
|
||||
G\set_status_header(400);
|
||||
$json_fail = [
|
||||
'status_code' => 400,
|
||||
'status_txt' => G\get_set_status_header_desc(400),
|
||||
'error' => [
|
||||
'message' => 'no request data present',
|
||||
'code' => NULL
|
||||
]
|
||||
];
|
||||
die(json_encode($json_fail));
|
||||
}
|
||||
|
||||
// Populate missing values
|
||||
if($data['status_code'] && !$data['status_txt']){
|
||||
$data['status_txt'] = G\get_set_status_header_desc($data['status_code']);
|
||||
}
|
||||
|
||||
$json_encode = json_encode($data);
|
||||
|
||||
if(!$json_encode) { // Json failed
|
||||
G\set_status_header(500);
|
||||
$json_fail = [
|
||||
'status_code' => 500,
|
||||
'status_txt' => G\get_set_status_header_desc(500),
|
||||
'error' => [
|
||||
'message' => "data couldn't be encoded into json",
|
||||
'code' => NULL
|
||||
]
|
||||
];
|
||||
die(json_encode($json_fail));
|
||||
}
|
||||
G\set_status_header($data['status_code']);
|
||||
|
||||
if(!is_null($callback)) {
|
||||
print sprintf('%s(%s);', $callback, $json_encode);
|
||||
} else {
|
||||
print $json_encode;
|
||||
}
|
||||
die();
|
||||
}
|
||||
function json_output($data=[], $callback=null)
|
||||
{
|
||||
error_reporting(0);
|
||||
//@ini_set('display_errors', false);
|
||||
if (ob_get_level() === 0 and !ob_start('ob_gzhandler')) {
|
||||
ob_start();
|
||||
}
|
||||
header('Last-Modified: '.gmdate('D, d M Y H:i:s').'GMT');
|
||||
header('Cache-Control: no-cache, must-revalidate');
|
||||
header('Pragma: no-cache');
|
||||
header('Content-type: application/json; charset=UTF-8');
|
||||
|
||||
// Invalid json request
|
||||
if (!G\check_value($data) || (G\check_value($callback) and preg_match('/\W/', $callback))) {
|
||||
G\set_status_header(400);
|
||||
$json_fail = [
|
||||
'status_code' => 400,
|
||||
'status_txt' => G\get_set_status_header_desc(400),
|
||||
'error' => [
|
||||
'message' => 'no request data present',
|
||||
'code' => null
|
||||
]
|
||||
];
|
||||
die(json_encode($json_fail));
|
||||
}
|
||||
|
||||
// Populate missing values
|
||||
if ($data['status_code'] && !$data['status_txt']) {
|
||||
$data['status_txt'] = G\get_set_status_header_desc($data['status_code']);
|
||||
}
|
||||
|
||||
$json_encode = json_encode($data);
|
||||
|
||||
if (!$json_encode) { // Json failed
|
||||
G\set_status_header(500);
|
||||
$json_fail = [
|
||||
'status_code' => 500,
|
||||
'status_txt' => G\get_set_status_header_desc(500),
|
||||
'error' => [
|
||||
'message' => "data couldn't be encoded into json",
|
||||
'code' => null
|
||||
]
|
||||
];
|
||||
die(json_encode($json_fail));
|
||||
}
|
||||
G\set_status_header($data['status_code']);
|
||||
|
||||
if (!is_null($callback)) {
|
||||
print sprintf('%s(%s);', $callback, $json_encode);
|
||||
} else {
|
||||
print $json_encode;
|
||||
}
|
||||
die();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue