-
-
Notifications
You must be signed in to change notification settings - Fork 214
/
thumb.php
executable file
·181 lines (138 loc) · 4.3 KB
/
thumb.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2010 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* On-the-fly thumbnail generator
*
* $URL$
* $Id$
*/
/**
* @package e107
* @subpackage core
* @author secretr
*
*
* On-the-fly thumbnail generator
*/
const e107_INIT = true;
function thumbExceptionHandler(Throwable $e)
{
http_response_code(500);
echo "Fatal Thumbnail Error\n";
$message = sprintf(
"Exception: %s, File: %s, Line: %d, Trace: %s",
$e->getMessage(),
$e->getFile(),
$e->getLine(),
$e->getTraceAsString()
);
var_dump($message);
error_log($message);
}
function thumbErrorHandler($errno, $errstr, $errfile, $errline)
{
switch($errno)
{
case E_USER_ERROR:
echo "<b>My ERROR</b> [$errno] $errstr<br />\n";
echo " Fatal error on line $errline in file $errfile";
echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
echo "Aborting...<br />\n";
thumbExceptionHandler(new Exception);
exit(1);
break;
default:
}
}
set_exception_handler('thumbExceptionHandler'); // disable to troubleshoot.
set_error_handler("thumbErrorHandler"); // disable to troubleshoot.
// error_reporting(0); // suppress all errors or image will be corrupted.
ini_set('gd.jpeg_ignore_warning', 1);
//require_once './e107_handlers/benchmark.php';
//$bench = new e_benchmark();
//$bench->start();
/**
* Class e_thumbpage
* @todo Simplify all this, e.g. e107::getInstance()->initMinimal($path_to_e107_config);
*/
class e_thumbpage
{
function __construct()
{
$self = realpath(__DIR__);
$e_ROOT = $self."/";
if ((substr($e_ROOT,-1) !== '/') && (substr($e_ROOT,-1) !== '\\') )
{
$e_ROOT .= DIRECTORY_SEPARATOR; // Should function correctly on both windows and Linux now.
}
define('e_ROOT', $e_ROOT);
$mySQLdefaultdb = '';
$HANDLERS_DIRECTORY = '';
$mySQLprefix = '';
// Config
$config = include($self.DIRECTORY_SEPARATOR.'e107_config.php');
// support early include feature
if(!empty($CLASS2_INCLUDE))
{
require_once(realpath(__DIR__ .'/'.$CLASS2_INCLUDE));
}
ob_end_clean(); // Precaution - clearout utf-8 BOM or any other garbage in e107_config.php
if(empty($HANDLERS_DIRECTORY))
{
$HANDLERS_DIRECTORY = 'e107_handlers/'; // quick fix for CLI Unit test.
}
$tmp = $self.DIRECTORY_SEPARATOR.$HANDLERS_DIRECTORY;
//Core functions - now API independent
require($tmp.DIRECTORY_SEPARATOR.'core_functions.php');
//e107 class
require($tmp.DIRECTORY_SEPARATOR.'e107_class.php');
if(empty($config['paths'])) // old e107_config.php format.
{
$dirNames = ['ADMIN_DIRECTORY', 'FILES_DIRECTORY', 'IMAGES_DIRECTORY', 'THEMES_DIRECTORY', 'PLUGINS_DIRECTORY', 'HANDLERS_DIRECTORY', 'LANGUAGES_DIRECTORY', 'HELP_DIRECTORY', 'DOWNLOADS_DIRECTORY','UPLOADS_DIRECTORY','SYSTEM_DIRECTORY', 'MEDIA_DIRECTORY','CACHE_DIRECTORY','LOGS_DIRECTORY', 'CORE_DIRECTORY', 'WEB_DIRECTORY'];
$e107_paths = [];
foreach ($dirNames as $name)
{
if (isset($$name))
{
$e107_paths[$name] = $$name;
}
}
$legacy_sql_info = compact('mySQLserver', 'mySQLuser', 'mySQLpassword', 'mySQLdefaultdb', 'mySQLprefix');
$sql_info = array_combine(array_map(function($k) {
return str_replace('mySQL', '', $k);
}, array_keys($legacy_sql_info)),
$legacy_sql_info
);
}
else // New e107_config.php format. v2.4+
{
$e107_paths = $config['paths'];
$sql_info = $config['database'];
$E107_CONFIG = $config['other'] ?? [];
}
$e107 = e107::getInstance()->initCore($e107_paths, e_ROOT, $sql_info, varset($E107_CONFIG, array()));
// basic Admin area detection - required for proper path parsing
define('ADMIN', strpos(e_SELF, (e107::getFolder('admin')) != false || strpos(e_PAGE, 'admin') !== false));
// Next function call maintains behavior identical to before; might not be needed
// See https://github.com/e107inc/e107/issues/3033
$e107->set_urls_deferred();
$pref = e107::getPref();
require_once(e_HANDLER."e_thumbnail_class.php");
$thm = new e_thumbnail;
$thm->init($pref);
if(!$thm->checkSrc())
{
die('Bad URL');
}
$thm->sendImage();
}
}
new e_thumbpage;
// Check your e_LOG folder
//$bench->end()->logResult('thumb.php', $_GET['src'].' - no cache');
exit;