php if isset _REQUEST isnull exit error_reporting E_ALL E_NOTICE ini_s

  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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
<?php
if(isset($_REQUEST['isnull'])) exit;
@error_reporting( E_ALL ^E_NOTICE );
@ini_set( 'display_errors',true );
@ini_set( 'html_errors',false );
@ini_set( 'error_reporting',E_ALL ^E_NOTICE );
define( 'DATALIFEENGINE',true );
define( 'ROOT_DIR','../..');
define( 'ENGINE_DIR','..');
if (@ini_get( 'safe_mode') == 1)
define( 'FOLDER_PREFIX',"");
else
define( 'FOLDER_PREFIX',date( "Y-m",time() ) );
require_once ENGINE_DIR .'/data/config.php';
if( $config['http_home_url'] == "") {
$config['http_home_url'] = explode( "engine/ajax/xfields.upload.php",$_SERVER['PHP_SELF'] );
$config['http_home_url'] = reset( $config['http_home_url'] );
$config['http_home_url'] = "http://".$_SERVER['HTTP_HOST'] .$config['http_home_url'];
}
require_once ENGINE_DIR .'/classes/mysql.php';
require_once ENGINE_DIR .'/data/dbconfig.php';
require_once ENGINE_DIR .'/modules/functions.php';
if(function_exists('dle_session'))
dle_session();
else
session_start();
require_once ROOT_DIR .'/language/'.$config['langs'] .'/adminpanel.lng';
$config['charset'] = ($lang['charset'] != '') ?$lang['charset'] : $config['charset'];
@header( "Content-type: text/html; charset=".$config['charset'] );
$user_group = get_vars( "usergroup");
if( !$user_group ) {
$user_group = array ();
$db->query( "SELECT * FROM ".USERPREFIX ."_usergroups ORDER BY id ASC");
while ( $row = $db->get_row() ) {
$user_group[$row['id']] = array ();
foreach ( $row as $key =>$value ) {
$user_group[$row['id']][$key] = $value;
}
}
set_vars( "usergroup",$user_group );
$db->free();
}
function AJAXMessage($t) {
global $lang;
return '<span class="error">'.$t.'</span>';
}
$result_type = intval($_REQUEST['type']);
$result_type = 1;
$result_isurl = intval($_REQUEST['x']);
$result_isadm = intval($_REQUEST['a']);
$result_news_id = intval($_REQUEST['newsid']);
$is_xfields_upload = false;
if ($result_type==1) {
require_once ENGINE_DIR .'/inc/xfields.upload.php';
$result_field = $_REQUEST['field'];
$result_option = false;
$xfields = xfieldsload();
foreach($xfields as $id =>$value) {
if (strtolower($value[0])==strtolower($result_field)) {
$result_option = xfield_get_option($value);
break;
}
}
if (is_array($result_option))
$is_xfields_upload = true;
}else
die(AJAXMessage("Hacking attempt!!!"));
if(count($_POST)<1)
die(AJAXMessage($lang['xfieldupload_err_8']));
if ($result_isurl==1 and !is_array($_FILES['userfile']))
$is_xfields_upload = false;
if ($result_isurl==2 and $_REQUEST['value']=='')
$is_xfields_upload = false;
if ($result_isurl==3 and $_REQUEST['value']=='')
$is_xfields_upload = false;
if (!$is_xfields_upload)
die(AJAXMessage($lang['xfieldupload_err_1']));
$is_logged = false;
$member_id = array ();
require_once ENGINE_DIR .'/modules/sitelogin.php';
if( !$is_logged )
$member_id['user_group'] = 5;
$image_field_apped = (isset($_SESSION['n0xfuploas'][$result_option['field']])?$_SESSION['n0xfuploas'][$result_option['field']]:0);
$image_field_multiple = ($result_option['multiple']!=''or $result_option['multiple_max']>0);
$result_author = ($result_news_id>0?$db->super_query( "SELECT autor FROM ".PREFIX ."_post where id = '{$result_news_id}' LIMIT 1"):false);
$result_author = ($result_author?$result_author['autor']:$member_id['name']);
if ($result_isurl==3) {
$result_error = ' '.$lang['xfieldupload_err_3'];
$result_value = xfields_get_hash($_REQUEST['value']);
$result_value = $db->safesql(trim(strip_tags($result_value)));
if($result_value=='')
die(AJAXMessage("Hacking attempt!"));
$result_path = xfieldsGetPath($result_option,$result_value);
if($result_option['result']=='file'and !$result_option['notag']) {
$result_value = intval($result_value);
$row = $db->super_query( "SELECT id, onserver FROM ".PREFIX ."_files where id = '{$result_value}' LIMIT 1");
if($row){
$db->query( "DELETE FROM ".PREFIX ."_files WHERE id='{$row['id']}'");
$result_error = '';
$result_field = '[attachment='.$result_value.']';
@unlink($result_path['ftp'].$row['onserver']);
}
}else
if(($result_option['notag'] and ($result_option['result']=='file') or $result_option['result']=='video'or $result_option['result']=='audio')){
$real_name = basename($result_value);
if($real_name!=''and @file_exists($result_path['ftp'].$real_name)){
if($result_path['bd']!==false) {
$row = $db->super_query( "SELECT id, onserver FROM ".PREFIX ."_files where news_id='{$result_news_id}' and onserver='{$result_path['bd']}{$real_name}' LIMIT 1");
if($row)
$db->query( "DELETE FROM ".PREFIX ."_files WHERE id='{$row['id']}'");
}
$result_error = '';
if($result_option['notag'])
$result_field = $result_value;
else
if($result_option['result']=='video')
$result_field = '[video='.$result_value.']';
else
if($result_option['result']=='audio')
$result_field = '[audio='.$result_value.']';
@unlink($result_path['ftp'].$real_name);
}
}else
if($result_option['result']=='image') {
$real_name = basename($result_value);
if($real_name!=''and @file_exists($result_path['ftp'].$real_name)){
if($result_path['bd']!==false) {
if($result_news_id==0)
$row = $db->super_query( "SELECT id, images FROM ".PREFIX ."_images where news_id = '0' and author = '{$result_author}' LIMIT 1");
else
$row = $db->super_query( "SELECT id, images FROM ".PREFIX ."_images where news_id = '{$result_news_id}' LIMIT 1");
$listimages = (($row and $row['images']!="")?explode("|||",$row['images']):array());
foreach($listimages as $dd)
if(strcasecmp($dd,$result_path['bd'].$real_name)==0) {
unset($listimages[$id]);
$row['images'] = implode( "|||",$listimages );
if(trim($row['images']==''))
$db->query( "DELETE FROM ".PREFIX ."_images where id = '{$row['id']}'");
else
$db->query( "UPDATE ".PREFIX ."_images set images='{$row['images']}' where id = '{$row['id']}'");
break;
}
}
$result_error = '';
if($result_option['notag'])
$result_field = $result_value;
else
if(file_exists($result_path['ftp']."thumbs/".$real_name))
$result_field = '[thumb]'.$result_value.'[/thumb]';
else
$result_field = '[img]'.$result_value.'[/img]';
@unlink($result_path['ftp'].$real_name);
@unlink($result_path['ftp']."thumbs/".$real_name);
}
}
if($result_error=='') {
$image_field_apped--;
}else
die(AJAXMessage($result_error));
}else {
if ($result_option['result']=='image')
$allowed_extensions = array ("gif","jpg","png","jpe","jpeg");
else
if ($result_option['result']=='audio')
$allowed_extensions = array ("mp3");
else
if ($result_option['result']=='video')
$allowed_extensions = array ("avi","mp4","wmv","mpg","flv","m4v","m4a","mov","3gp","f4v");
else
if ($result_option['result']=='file') {
if (isset($user_group[$member_id['user_group']]['files_type']))
$config['files_type'] = $user_group[$member_id['user_group']]['files_type'];
if (isset($result_option['files_type']))
$config['files_type'] = $result_option['files_type'];
$allowed_extensions = explode(',',strtolower($config['files_type']));
}else
$allowed_extensions = array();
$uploadFiles = array();
if ($result_isurl==2) {
$fileurl = str_replace( "\\","/",$_REQUEST['value'] );
$uploadFiles[] = array(
'file'=>$fileurl,
'name'=>basename($fileurl),
'size'=>@filesize_url( $fileurl ),
'error'=>'',
);
}else
if ($result_isurl==1) {
if(is_array($_FILES['userfile']['tmp_name'])){
foreach($_FILES['userfile']['tmp_name'] as $ii =>$dd){
$uploadFiles[] = array(
'file'=>$_FILES['userfile']['tmp_name'][$ii],
'name'=>$_FILES['userfile']['name'][$ii],
'size'=>$_FILES['userfile']['size'][$ii],
'error'=>$_FILES['userfile']['error'][$ii],
);
}
}else {
$uploadFiles[] = array(
'file'=>$_FILES['userfile']['tmp_name'],
'name'=>$_FILES['userfile']['name'],
'size'=>$_FILES['userfile']['size'],
'error'=>$_FILES['userfile']['error'],
);
}
foreach($uploadFiles as &$dd){
if ( $dd['error'] !== UPLOAD_ERR_OK) {
switch ($error_code) {
case UPLOAD_ERR_INI_SIZE:
$dd['error'] = 'PHP Error: The uploaded file exceeds the upload_max_filesize directive in php.ini';break;
case UPLOAD_ERR_FORM_SIZE:
$dd['error'] = 'PHP Error: The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';break;
case UPLOAD_ERR_PARTIAL:
$dd['error'] = 'PHP Error: The uploaded file was only partially uploaded';break;
case UPLOAD_ERR_NO_FILE:
$dd['error'] = 'PHP Error: No file was uploaded';break;
case UPLOAD_ERR_NO_TMP_DIR:
$dd['error'] = 'PHP Error: Missing a PHP temporary folder';break;
case UPLOAD_ERR_CANT_WRITE:
$dd['error'] = 'PHP Error: Failed to write file to disk';break;
case UPLOAD_ERR_EXTENSION:
$dd['error'] = 'PHP Error: File upload stopped by extension';break;
default:
$dd['error'] = 'Unknown upload error';break;
}
}else
$dd['error'] = '';
}
}
if(($image_field_multiple and $image_field_apped>=$result_option['multiple_max']) or (!$image_field_multiple and $image_field_apped>1)) {
$result_error = ' '.$lang['xfieldupload_err_7'];
}else
if(($result_option['result']=='image'and !$user_group[$member_id['user_group']]['allow_image_upload']) or
($result_option['result']!='image'and (!$user_group[$member_id['user_group']]['allow_file_upload'] or $config['files_allow']!="1"))
)
$result_error = ' '.$lang['xfieldupload_err_4'];
else
foreach($uploadFiles as &$dd){
$dd['name'] = totranslit($dd['name']);
$dd['type'] = pathinfo($dd['name']);
$dd['type'] = $dd['type']['extension'];
$zz = $image_field_apped+1;
if(($image_field_multiple and $zz>$result_option['multiple_max']) or (!$image_field_multiple and $zz>1)) {
$dd['error'] = $lang['xfieldupload_err_7'];
}else
if((stripos($dd['name'],".htaccess")!== false))
$dd['error'] = "Hacking attempt! 2";
else
if(!in_array(strtolower($dd['type']),$allowed_extensions))
$dd['error'] = ' '.$lang['xfieldupload_err_5']." \"".strtolower( $dd['type'] )."\" (".implode(', ',$allowed_extensions).")";
else
if($dd['size']>0 and $result_option['result']!='image'and intval($config['max_file_size']) and $dd['size']>($config['max_file_size']*1024))
$dd['error'] = ' '.$lang['files_too_big'];
else
if($dd['size']>0 and $result_option['result']=='image'and intval($config['max_up_size']) and $dd['size']>($config['max_up_size']*1024))
$dd['error'] = ' '.$lang['images_big'];
else {
$dd['path'] = xfieldsGetPath($result_option);
if (!is_array($dd['path'])) {
$dd['error'] = ' '.$dd['path'];
$dd['path'] = false;
}
}
if($dd['error']!='') continue;
$file_prefix = time() +rand( 1,100 );
$dd['name_real'] = $dd['name'];
$dd['name'] = $file_prefix .'_'.$dd['name'];
$dd['file_real'] = $dd['path']['ftp'] .$dd['name'];
if ($result_isurl==1)
@move_uploaded_file( $dd['file'],$dd['file_real'] );
else
if ($result_isurl==2)
@copy( $dd['file'],$dd['file_real'] );
if( @file_exists( $dd['file_real'] ) ) {
@chmod( $dd['file_real'] ,0666 );
$file_size = @filesize( $dd['file_real'] );
if($file_size!=$dd['size']) {
$dd['size'] = $file_size;
if($dd['size']>0 and $result_option['result']!='image'and intval($config['max_file_size']) and $dd['size']>($config['max_file_size']*1024)) {
$dd['error'] = ' '.$lang['files_too_big'];
}else
if($dd['size']>0 and $result_option['result']=='image'and intval($config['max_up_side']) and $dd['size']>($config['max_up_size']*1024)) {
$dd['error'] = ' '.$lang['images_big'];
}
}
}else
$dd['error'] = ' '.$lang['xfieldupload_err_6'];
if($dd['error']!='')
@unlink( $dd['file_real'] );
else
$image_field_apped++;
}
$added_time = time() +($config['date_adjust'] * 60);
$out_fields = array();
$out_fields_input = array();
if ($result_error!='')
$out_fields[] = AJAXMessage($result_error);
else
if ($result_option['result']=='image') {
$inserts = array();
foreach($uploadFiles as &$dd){
if($dd['error']==''and $dd['path']['bd']!==false)
$inserts[] = $dd['path']['bd'].$dd['name'];
}
if(count($inserts)>0) {
if($result_news_id==0)
$row = $db->super_query( "SELECT id, images FROM ".PREFIX ."_images where news_id = '0' and author = '$result_author' LIMIT 1");
else
$row = $db->super_query( "SELECT id, images FROM ".PREFIX ."_images where news_id = '$result_news_id' LIMIT 1");
if(!$row or intval($row['id'])<1) {
$inserts = implode( "|||",$inserts );
$db->query( "INSERT INTO ".PREFIX ."_images (images, author, news_id, date) values ('{$inserts}', '{$result_author}', '{$result_news_id}', '{$added_time}')");
}else {
$listimages = ($row['images']==""?array():explode("|||",$row['images']));
$inserts = array_diff_assoc($inserts,$listimages);
$listimages = array_merge($listimages,$inserts);
$row['images'] = implode( "|||",$listimages );
$db->query( "UPDATE ".PREFIX ."_images set images='{$row['images']}' where id = '{$row['id']}'");
}
}
include_once ENGINE_DIR .'/classes/thumb.class.php';
foreach ($uploadFiles as &$dd) {
if($dd['error']!=''){
$out_fields[] = AJAXMessage($dd['name'].': '.$dd['error']);
continue;
}
$image_url = $dd['path']['http'].$dd['name'];
$is_upload_ftp = ((stripos($dd['path']['ftp'],'ftp://'))!==false);
$result_option_size = (isset($result_option['size'])?$result_option['size']:false);
$image_url_thumb = '';
if (!$result_option['nothumb']) {
if (!$result_option_size) $result_option_size = $config['max_image'];
try {
$thumb = new thumbnail( $dd['file_real'] );
if( $thumb->size_auto( $result_option_size,$config['t_seite'] ) ) {
$thumb->jpeg_quality( $config['jpeg_quality'] );
if( $config['allow_watermark'] == "1") $thumb->insert_watermark( $config['max_watermark'] );
if($is_upload_ftp){
$tmpfilename = tempnam(sys_get_temp_dir(),'xfu');
$thumb->save( $tmpfilename );
@unlink($dd['path']['ftp']."thumbs/".$dd['name']);
copy($tmpfilename,$dd['path']['ftp']."thumbs/".$dd['name']);
@unlink($tmpfilename);
}else{
$thumb->save( $dd['path']['ftp']."thumbs/".$dd['name'] );
}
@chmod( $dd['path']['ftp']."thumbs/".$dd['name'],0666 );
}
}catch (Exception $e) {}
if( @file_exists( $dd['path']['ftp']."thumbs/".$dd['name'] ) )
$image_url_thumb = $dd['path']['http']."thumbs/".$dd['name'];
$result_option_size = $config['max_up_side'];
}else {
if (!$result_option_size) $result_option_size = $config['max_up_side'];
}
if( $config['allow_watermark'] == "yes"or $result_option['size'] ) {
try {
$thumb = new thumbnail( $dd['file_real'] );
$thumb->jpeg_quality( $config['jpeg_quality'] );
if( $result_option_size ) $thumb->size_auto( $result_option_size,$config['t_seite'] );
if( $config['allow_watermark'] == "yes") $thumb->insert_watermark( $config['max_watermark'] );
if($is_upload_ftp){
$tmpfilename = tempnam(sys_get_temp_dir(),'xfu');
$thumb->save( $tmpfilename );
@unlink($dd['file_real']);
copy($tmpfilename,$dd['file_real']);
@unlink($tmpfilename);
}else{
$thumb->save( $dd['file_real'] );
}
}catch (Exception $e) {}
}
if ($result_option['notag']) {
if ($image_url_thumb!='')
$out_field = $image_url_thumb;
else
$out_field = $image_url;
}else {
if ($image_url_thumb!='')
$out_field = "[thumb]".$image_url."[/thumb]";
else
$out_field = "[img]".$image_url."[/img]";
}
$out_fields_input[] = $out_field;
$out_field = xfields_get_exists($result_option,$out_field);
$out_field = (is_array($out_field)?$out_field:array($out_field));
$out_fields = array_merge($out_fields,$out_field);
}
}else
foreach($uploadFiles as &$dd) {
if($dd['error']!='') {
$out_fields[] = AJAXMessage($dd['name'].': '.$dd['error']);
continue;
}
if($dd['path']['bd']!==false){
$db->query( "INSERT INTO ".PREFIX ."_files (news_id, name, onserver, author, date) values ('{$result_news_id}', '{$dd['name_real']}', '{$dd['path']['bd']}{$dd['name']}', '{$result_author}', '{$added_time}')");
$insert_id = $db->insert_id();
}else
$insert_id = '0';
$image_url = $dd['path']['http'].$dd['name'];
if ($result_option['result']=='audio') {
if ($result_option['notag'])
$out_field = $image_url;
else
$out_field = "[audio={$image_url}]";
}else
if ($result_option['result']=='video') {
if ($result_option['notag'])
$out_field = $image_url;
else
$out_field = "[video={$image_url}]";
}else
if ($result_option['result']=='file') {
if ($result_option['notag'])
$out_field = $image_url;
else
$out_field = "[attachment=".$insert_id ."]";
}
$out_fields_input[] = $out_field;
$out_field = xfields_get_exists($result_option,$out_field);
$out_field = (is_array($out_field)?$out_field:array($out_field));
$out_fields = array_merge($out_fields,$out_field);
}
if (count($out_fields)<1)
die(AJAXMessage('Internal error'));
$result_html = (is_array($out_fields)?implode('',$out_fields):$out_fields);
$result_field = (is_array($out_fields_input)?implode(($image_field_multiple?$result_option['multiple']:''),$out_fields_input):$out_fields_input);
}
function json_strip($s){
$s = str_replace('"','\"',$s );
$s = str_replace(array("{","}","\r","\n","\t"),'',$s );
return $s;
}
$_SESSION['n0xfuploas'][$result_option['field']] = $image_field_apped;
$image_allowed_upload = !(($image_field_multiple and $image_field_apped>=$result_option['multiple_max']) or (!$image_field_multiple and $image_field_apped>1));
$result_html = '{"content":"'.json_strip($result_html).'","allowed_upload":"'.($image_allowed_upload?'1':'0').'","field_value":"'.json_strip($result_field).'","filed_delimiter":"'.json_strip($result_option['multiple']).'"}';
$db->close();
$result_html = str_ireplace(array('%7BTHEME%7D','{THEME}'),$config['http_home_url'].'templates/'.$config['skin'],$result_html);
die($result_html);