-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.php
executable file
·383 lines (357 loc) · 20.5 KB
/
upload.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
<?php
/**
* OE4 File Type Format Generation Example
*
* You may not change or alter any portion of this comment or credits
* of supporting developers from this source code or any supporting source code
* which is considered copyrighted (c) material of the original comment or credit authors.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* @copyright Chronolabs Cooperative http://syd.au.snails.email
* @license ACADEMIC APL 2 (https://sourceforge.net/u/chronolabscoop/wiki/Academic%20Public%20License%2C%20version%202.0/)
* @license GNU GPL 3 (http://www.gnu.org/licenses/gpl.html)
* @package oe4-fonttype
* @since 1.0.1
* @author Dr. Simon Antony Roberts <[email protected]>
* @version 1.0.1
* @description This is part of the font file type OE4 File Format Generation Example
* @link http://internetfounder.wordpress.com
* @link https://github.com/Chronolabs-Cooperative/0E4-FontType-Example
* @link https://sourceforge.net/p/chronolabs-cooperative
* @link https://facebook.com/ChronolabsCoop
* @link https://twitter.com/ChronolabsCoop
*
*/
global $inner, $odds;
define('OE4_NOHTML', true);
require_once __DIR__ . DIRECTORY_SEPARATOR . 'header.php';
error_reporting(E_ERROR);
ini_set('display_errors', true);
set_time_limit(3600*36*9*14*28);
//echo "Processed Upload Form Fine<br/>";
$time = time();
$error = array();
if (isset($inner['field']) || !empty($inner['field'])) {
if (empty($_FILES[$inner['field']]))
$error[] = 'No file uploaded in the correct field name of: "' . $inner['field'] . '"';
elseif (empty($_FILES['logo']))
$error[] = 'No file uploaded in the correct field name of: "logo"';
else {
$formats = cleanWhitespaces(file(__DIR__ . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'font-converted.diz'));
$pass = false;
foreach($formats as $xtension)
{
if (strtolower(substr($_FILES[$inner['field']]['name'], strlen($_FILES[$inner['field']]['name'])- strlen($xtension))) == strtolower($xtension))
if (in_array($xtension, $formats)) {
$filetype = $xtension;
$pass = true;
continue;
}
}
if ($pass == false)
$error[] = 'The file extension type of <strong>'.$_FILES[$inner['field']]['name'].'</strong> is not valid you can only upload the following file types: <em>'.implode("</em> <em>*.", $formats).'</em>!';
$images = cleanWhitespaces(file(__DIR__ . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'images-accepted.diz'));
$pass = false;
foreach($images as $xtension)
{
if (strtolower(substr($_FILES['logo']['name'], strlen($_FILES['logo']['name'])- strlen($xtension))) == strtolower($xtension))
if (in_array($xtension, $images)) {
$imagetype = $xtension;
$pass = true;
continue;
}
}
if ($pass == false)
$error[] = 'The file extension type of <strong>'.$_FILES['logo']['name'].'</strong> is not valid you can only upload the following file types: <em>'.implode("</em> <em>*.", $images).'</em>!';
}
}
if (isset($inner['email']) || !empty($inner['email'])) {
if (!checkEmail($inner['email']))
$error[] = 'Converter\'s organisation Email Address is invalid!';
} else
$error[] = 'No Converter\'s organisation Email Address for Notification specified!';
if (!isset($inner['name']) || empty($inner['name'])) {
$error[] = 'No Converter\'s individual or organisation name not specified in survey scope when selected!';
}
if (!isset($inner['url']) || empty($inner['url'])) {
$error[] = 'No Converter\'s organisation URL not specified in survey scope when selected!';
}
$basepath = constant("OE4_TMP") . DIRECTORY_SEPARATOR . 'oe4';
if (!is_dir($basepath)) {
if (!mkdirSecure($basepath, 0777, true)) {
$error[] = 'Unable to make path: '.$basepath;
}
}
$uploadpath = $basepath . DIRECTORY_SEPARATOR . ($key = md5($inner['email'] . DIRECTORY_SEPARATOR . microtime(true)));
if (!is_dir($uploadpath)) {
if (!mkdirSecure($uploadpath, 0777, true)) {
$error[] = 'Unable to make path: '.$uploadpath;
}
}
$oe4path = $basepath . DIRECTORY_SEPARATOR . ($key . '.oe4');
if (!is_dir($oe4path)) {
if (!mkdirSecure($oe4path, 0777, true)) {
$error[] = 'Unable to make path: ' . $oe4path;
}
}
//echo "Checked for Errors Fine<br/>";
if (!empty($error))
{
redirect(isset($inner['return'])&&!empty($inner['return'])?$inner['return']:'http://'. $_SERVER["HTTP_HOST"], 9, "<center><h1 style='color:rgb(198,0,0);'>Error Has Occured</h1><br/><p>" . implode("<br />", $error) . "</p></center>");
exit(0);
}
$keys = json_decode(file_get_contents(constant("OE4_TMP") . DIRECTORY_SEPARATOR . 'oe4' . DIRECTORY_SEPARATOR . 'keys.json'), true);
$keys[$keyskey = md5(microtime(true))]['key'] = $key;
$file = $uploader = $success = array();
if (!move_uploaded_file($_FILES[$inner['field']]['tmp_name'], $file['font'] = $uploadpath . DIRECTORY_SEPARATOR . ($uploader['font'] = $_FILES[$inner['field']]['name']))) {
redirect(isset($inner['return'])&&!empty($inner['return'])?$inner['return']:'http://'. $_SERVER["HTTP_HOST"], 9, "<center><h1 style='color:rgb(198,0,0);'>Uploading Error Has Occured</h1><br/><p>Fonts API was unable to recieve and store: <strong>".$_FILES[$inner['field']]['name']."</strong>!</p></center>");
exit(0);
} else
$success['font'] = array('unixtime' => time(), 'file' => $_FILES[$inner['field']]['name'], 'mime-type' => $_FILES[$inner['field']]['type']);
if (!move_uploaded_file($_FILES['logo']['tmp_name'], $file['logo'] = $uploadpath . DIRECTORY_SEPARATOR . ($uploader['logo'] = $_FILES['logo']['name']))) {
redirect(isset($inner['return'])&&!empty($inner['return'])?$inner['return']:'http://'. $_SERVER["HTTP_HOST"], 9, "<center><h1 style='color:rgb(198,0,0);'>Uploading Error Has Occured</h1><br/><p>Fonts API was unable to recieve and store: <strong>".$_FILES[$inner['field']]['name']."</strong>!</p></center>");
exit(0);
} else
$success['logo'] = array('unixtime' => time(), 'file' => $_FILES['logo']['name'], 'mime-type' => $_FILES['logo']['type']);
if (!empty($error))
{
redirect(isset($inner['return'])&&!empty($inner['return'])?$inner['return']:'http://'. $_SERVER["HTTP_HOST"], 9, "<center><h1 style='color:rgb(198,0,0);'>Error Has Occured</h1><br/><p>" . implode("<br />", $error) . "</p></center>");
exit(0);
}
@exec("cd " . $uploadpath, $out, $return);
@exec($exe = sprintf(OE4_FONTFORGE . " -script \"%s\" \"%s\"", OE4_CONVERT_PE, $file['font']), $out, $return);
$parts = explode('.', basename($file['font']));
unset($parts[count($parts)-1]);
$fill = implode('.', $parts);
$fontdata = array();
if (file_exists($fontinfo = $uploadpath . DIRECTORY_SEPARATOR . $fill . '.ufo' . DIRECTORY_SEPARATOR . 'fontinfo.plist')) {
//$fontdata = xml2array(file_get_contents($fontinfo), true, 'key');
$fontvalues = xml2array($xml = file_get_contents($fontinfo));
$fontdata['OE4']['Basename'] = $fill;
$fontdata['OE4']['Name'] = $inner['name'];
$fontdata['OE4']['Email'] = $inner['email'];
$fontdata['OE4']['Url'] = $inner['url'];
$fontdata['OE4']['Logo-image']['mime-type'] = $success['mime-type'];
$fontdata['OE4']['Logo-image']['encoding'] = 'base64';
$fontdata['OE4']['Logo-image']['image'] = base64_encode(file_get_contents($file['logo']));
foreach($fontvalues['plist']['dict']['key'] as $id => $fieldkey)
{
if ($ipos = strpos($xml, $needle = " <key>$fieldkey</key>\n "))
{
if ($epos = strpos($xml, $eneedle = "\n", $ipos + strlen($needle) + 1))
{
$scrape = substr($xml, $ipos + strlen($needle), ($epos - ($ipos + strlen($needle) + 1) + 1));
if (strpos($scrape, 'string'))
$fontdata[formatElement($fieldkey)] = str_replace(array("<string>", "</string>"), '', $scrape);
elseif (strpos($scrape, 'integer'))
$fontdata[formatElement($fieldkey)] = str_replace(array("<integer>", "</integer>"), '', $scrape);
elseif (strpos($scrape, 'real'))
$fontdata[formatElement($fieldkey)] = str_replace(array("<real>", "</real>"), '', $scrape);
elseif (strpos($scrape, 'true'))
$fontdata[formatElement($fieldkey)] = true;
elseif (strpos($scrape, 'false'))
$fontdata[formatElement($fieldkey)] = false;
elseif (strpos($scrape, 'array/'))
$fontdata[formatElement($fieldkey)] = array();
elseif (strpos($scrape, 'array')) {
if ($apos = strpos($xml, $aneedle = "\n </array>\n", $epos + strlen($scrape) + 1))
{
$arrayxml = substr($xml, $epos + strlen($scrape), $apos - ($epos + strlen($scrape)));
$arrayxml = str_replace(array('\t', ' ', ' ', '<string>', '</string>', '<integer>', '</integer>', '<real>', '</real>'), '', $arrayxml);
foreach(explode("\n", $arrayxml) as $valuexml)
$fontdata[formatElement($fieldkey)][] = trim($valuexml);
}
}
switch(formatElement($fieldkey))
{
case 'Postscript-Font-Name':
$keys[$keyskey]['unixtime'] = time();
$keys[$keyskey]['name'] = trim(formatName($fontdata[formatElement($fieldkey)]));
writeRawFile(constant("OE4_TMP") . DIRECTORY_SEPARATOR . 'oe4' . DIRECTORY_SEPARATOR . 'keys.json', json_encode($keys));
case 'Family-Name':
case 'Style-Name':
case 'Style-Map-Family-Name':
case 'Style-Map-Style-Name':
case 'Postscript-Full-Name':
$fontdata[formatElement($fieldkey)] = trim(formatName($fontdata[formatElement($fieldkey)]));
break;
}
if (formatElement($fieldkey) == 'Cap-Height') {
$fontdata['Cap-Depth'] = false;
$fontdata['Cap-Scale'] = '0.0';
}
if (formatElement($fieldkey) == 'X-Height') {
$fontdata['Z-Depth'] = '0.0';
$fontdata['X-Pitch'] = '0.0';
$fontdata['Y-Pitch'] = '0.0';
$fontdata['Z-Pitch'] = '0.0';
$fontdata['X-Radius'] = '0.0';
$fontdata['Y-Radius'] = '0.0';
$fontdata['X-Angle'] = '0.0';
$fontdata['Y-Angle'] = '0.0';
}
if (formatElement($fieldkey) == 'Descender') {
$fontdata['Depther'] = false;
$fontdata['Scaler'] = '1.0';
}
if (formatElement($fieldkey) == 'Open-Type-Hhea-Descender') {
$fontdata['Open-Type-Hhea-Depther'] = false;
$fontdata['Open-Type-Hhea-Scaler'] = '0.0';
}
if (formatElement($fieldkey) == 'Open-Type-OS2-Typo-Descender') {
$fontdata['Open-Type-OS2-Typo-Depther'] = false;
$fontdata['Open-Type-OS2-Typo-Scaler'] = '0.0';
}
if (formatElement($fieldkey) == 'Open-Type-OS2-Win-Descent') {
$fontdata['Open-Type-OS2-Win-Depth'] = false;
$fontdata['Open-Type-OS2-Win-Scale'] = '0.0';
}
if (formatElement($fieldkey) == 'Open-Type-OS2-Subscript-Y-Size') {
$fontdata['Open-Type-OS2-Subscript-Z-Size'] = false;
$fontdata['Open-Type-OS2-Subscript-D-Size'] = false;
}
if (formatElement($fieldkey) == 'Open-Type-OS2-Subscript-Y-Offset') {
$fontdata['Open-Type-OS2-Subscript-Z-Offset'] = false;
$fontdata['Open-Type-OS2-Subscript-D-Offset'] = false;
}
if (formatElement($fieldkey) == 'Open-Type-OS2-Superscript-Y-Size') {
$fontdata['Open-Type-OS2-Superscript-Z-Size'] = false;
$fontdata['Open-Type-OS2-Superscript-D-Size'] = false;
}
if (formatElement($fieldkey) == 'Open-Type-OS2-Superscript-Y-Offset') {
$fontdata['Open-Type-OS2-Superscript-Z-Offset'] = false;
$fontdata['Open-Type-OS2-Superscript-D-Offset'] = false;
}
if (formatElement($fieldkey) == 'Postscript-Stem-Snap-V') {
$fontdata['Postscript-Stem-Snap-D'] = array();
}
}
}
}
if (!is_dir($glyphpath = $oe4path . DIRECTORY_SEPARATOR . 'glyphs'))
if (!mkdir($glyphpath, 0777, true)) {
$error[] = 'Unable to make path: ' . $glyphpath;
}
$characters = array();
foreach(getFileListAsArray($glyphsrc = $uploadpath . DIRECTORY_SEPARATOR . $fill . '.ufo' . DIRECTORY_SEPARATOR . 'glyphs') as $glyphfile)
{
$glyph = array();
$glyphvalues = json_decode(json_encode(new SimpleXMLElement($xml = file_get_contents($glyphsrc . DIRECTORY_SEPARATOR . $glyphfile))), true);
foreach($glyphvalues as $gkey => $gvalues)
{
switch ($gkey)
{
case '@attributes':
foreach($gvalues as $fkey => $fvalue)
{
$glyph[formatElement($fkey)] = $fvalue;
}
break;
case 'advance':
foreach($gvalues['@attributes'] as $fkey => $fvalue)
{
$glyph['Advance'][formatElement($fkey)] = $fvalue;
}
unset($gvalues['@attributes']);
foreach($gvalues as $fkey => $fvalue)
{
$glyph['Advance'][formatElement($fkey)] = $fvalue;
}
$glyph['Advance'][formatElement('depth')] = false;
break;
case 'unicode':
foreach($gvalues['@attributes'] as $fkey => $fvalue)
{
$glyph['Unicode'][formatElement($fkey)] = $fvalue;
if (formatElement($fkey)=='Hex')
$characters[] = $hex = $fvalue;
}
unset($gvalues['@attributes']);
foreach($gvalues as $fkey => $fvalue)
{
$glyph['Unicode'][formatElement($fkey)] = $fvalue;
}
break;
case 'outline':
foreach($gvalues['contour'] as $ckey => $cvalue)
{
foreach($cvalue['point'] as $pkey => $pvalue)
{
foreach($pvalue['@attributes'] as $fkey => $fvalue)
{
$glyph['Contour'][$ckey]['Point'][$pkey][formatElement($fkey)] = $fvalue;
if (formatElement($fkey) == 'Y') {
$glyph['Contour'][$ckey]['Point'][$pkey]['Z'] = false;
$glyph['Contour'][$ckey]['Point'][$pkey]['D'] = false;
$glyph['Contour'][$ckey]['Point'][$pkey]['XP'] = '0.0';
$glyph['Contour'][$ckey]['Point'][$pkey]['YP'] = '0.0';
$glyph['Contour'][$ckey]['Point'][$pkey]['ZP'] = '0.0';
$glyph['Contour'][$ckey]['Point'][$pkey]['XR'] = '0.0';
$glyph['Contour'][$ckey]['Point'][$pkey]['YR'] = '0.0';
$glyph['Contour'][$ckey]['Point'][$pkey]['XA'] = '0.0';
$glyph['Contour'][$ckey]['Point'][$pkey]['YA'] = '0.0';
}
}
unset($pvalue['@attributes']);
foreach($pvalue as $fkey => $fvalue)
{
$glyph['Contour'][$ckey]['Point'][$pkey][formatElement($fkey)] = $fvalue;
}
}
}
break;
case 'lib':
foreach($gvalues['dict'] as $ckey => $cvalue)
{
switch($ckey)
{
case "key":
$glyph['Library'][formatElement($ckey)] = $cvalue;
break;
case "dict":
foreach($cvalue['dict'] as $pkey => $pvalue)
{
switch($ckey)
{
case "key":
$glyph['Library']['Dictionary'][formatElement($ckey)][formatElement($pkey)] = $pvalue;
$glyph['Library']['Dictionary'][formatElement($ckey)][formatElement($pkey)][] = 'dhints';
break;
case "array":
foreach($pvalue['array'] as $fkey => $fvalue)
{
foreach($fvalue['dict'] as $dkey => $dvalue)
{
$dvalue['key'][] = 'depth';
$dvalue['key'][] = 'scale';
$dvalue['integer'][] = '0';
$dvalue['integer'][] = '0.0';
$glyph['Library']['Dictionary'][formatElement($ckey)][formatElement($pkey)][formatElement($fkey)]['Dictionary'][formatElement($dkey)] = $dvalue;
}
}
}
}
}
}
break;
}
}
$hex = str_repeat('0', 24 - strlen($hex)) . $hex;
writeRawFile($glyphpath . DIRECTORY_SEPARATOR . $hex . '.json', json_encode($glyph));
}
writeRawFile($oe4path . DIRECTORY_SEPARATOR . 'files.json', json_encode($file));
writeRawFile($oe4path . DIRECTORY_SEPARATOR . 'success.json', json_encode($success));
sort($characters = array_unique($characters));
writeRawFile($oe4path . DIRECTORY_SEPARATOR . 'glyphs.json', json_encode($characters));
if (!isset($fontdata['Version-Major']) && !isset($fontdata['Version-Minor'])) {
$fontdata['Version-Major'] = 1;
$fontdata['Version-Minor'] = 0;
}
writeRawFile($oe4path . DIRECTORY_SEPARATOR . 'fontinfo.json', json_encode($fontdata));
} else
die("File Not Found: $fontinfo");
redirect(isset($inner['return'])&&!empty($inner['return'])?$inner['return']:OE4_URL . '/convert.php?key='.$key, 18, "<center><h1 style='color:rgb(0,198,0);'>Uploading Partially or Completely Successful</h1><br/><div>The following files where uploaded and queued for conversion on the API Successfully:</div><div style='height: auto; clear: both; width: 100%;'><ul style='height: auto; clear: both; width: 100%;'><li style='width: 24%; float: left;'>".implode("</li><li style='width: 24%; float: left;'>", $uploader)."</li></ul></div><br/><div style='clear: both; height: 11px; width: 100%'> </div><p>You will now have to select the conversion options, like licenses, character sets and so on, as well as preview text!</p></center>");
exit(0);
?>