PluginProbe
Comments Extra Fields For Post,Pages and CPT / 5.1
Comments Extra Fields For Post,Pages and CPT v5.1
trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 2.2 2.3 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 5.0 5.1 5.2
wp-comment-fields / inc / files.php

files.php in Comments Extra Fields For Post,Pages and CPT 5.1, at inc/files.php

604 lines 20.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Manage file uploads, thumbs and generate links for uploaded files
4 *
5 **/
6 if( ! defined('ABSPATH') ) die('Not Allowed.');
7
8 // Set/create directory and return path
9 function wpcomment_files_setup_get_directory( $sub_dir=false ) {
10
11 $upload_dir = wp_upload_dir ();
12
13 $parent_dir = $upload_dir ['basedir'] . '/' . WPCOMMENT_UPLOAD_DIR_NAME . '/';
14 $thumb_dir = $parent_dir . 'thumbs/';
15
16 if($sub_dir){
17 $sub_dir = $parent_dir . $sub_dir . '/';
18 if(wp_mkdir_p($sub_dir)){
19 return $sub_dir;
20 }
21 }elseif(wp_mkdir_p($parent_dir)){
22 if(wp_mkdir_p($thumb_dir)){
23 return $parent_dir;
24 }
25 }
26 }
27
28
29 // Return upload file dir path
30 function wpcomment_get_dir_path( $sub_dir=false ) {
31
32 $wpcomment_upload_dir = wpcomment_files_setup_get_directory( $sub_dir );
33 return apply_filters('wpcomment_dir_path', $wpcomment_upload_dir);
34 }
35
36 // Return upload file dir url
37 function wpcomment_get_dir_url( $thumb=false, $legacy=false ) {
38
39 $upload_dir = wp_upload_dir ();
40 $return_url = '';
41
42 $dir_name = $legacy ? 'comment_uploads' : WPCOMMENT_UPLOAD_DIR_NAME;
43 if ( $thumb ) {
44 $return_url = $upload_dir ['baseurl'] . '/' . $dir_name . '/thumbs/';
45 } else {
46 $return_url = $upload_dir ['baseurl'] . '/' . $dir_name . '/';
47 }
48
49 return apply_filters('wpcomment_dir_url', set_url_scheme( $return_url ));
50 }
51
52 // Check if given filenameis image
53 function wpcomment_is_file_image( $file_name ){
54
55 $type = strtolower ( substr ( strrchr ( $file_name , '.' ), 1 ) );
56 if (($type == "gif") || ($type == "jpeg") || ($type == "png") || ($type == "pjpeg") || ($type == "jpg"))
57 return true;
58 else
59 return false;
60 }
61
62 // return html for file thumb
63 function wpcomment_create_thumb_for_meta( $field_meta, $file_name, $cropped=false, $size=null) {
64
65 $file_thumb_url = wpcomment_is_file_image($file_name) ? wpcomment_get_dir_url(true) . $file_name : WPCOMMENT_URL.'/images/file.png';
66 $file_dir_path = wpcomment_get_dir_path() . $file_name;
67
68 if( ! file_exists($file_dir_path) ) return '';
69
70 $file_link = wpcomment_get_dir_url() . $file_name;
71
72 $wpcomment_cart_meta_thumb_size = wpcomment_get_thumbs_size();
73
74 $wpcomment_html = '<p class="wpcomment-file-front-wrapper">';
75 $thumb_html = '<img class="wpcomment-file-thumbnail" style="width:'.esc_attr($wpcomment_cart_meta_thumb_size).'" src="'.esc_url($file_thumb_url).'" alt="'.sprintf(__("%s","wpcomment"), $file_name).'">';
76 $wpcomment_html .= '<a href="'.esc_url($file_link).'" class="wpcomment-file-link" itemprop="image" title="'.esc_attr($file_name).'">' . $thumb_html . '</a>';
77 $wpcomment_html .= '<p class="wpcomment-file-title">'.esc_html($field_meta['title']).'</p>';
78 $wpcomment_html .= '</p>';
79
80 return apply_filters('wpcomment_meta_file_thumb', $wpcomment_html, $file_name);
81 }
82
83
84 function wpcomment_upload_file() {
85
86 header ( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
87 header ( "Last-Modified: " . gmdate ( "D, d M Y H:i:s" ) . " GMT" );
88 header ( "Cache-Control: no-store, no-cache, must-revalidate" );
89 header ( "Cache-Control: post-check=0, pre-check=0", false );
90 header ( "Pragma: no-cache" );
91
92 $wpcomment_nonce = $_REQUEST['wpcomment_nonce'];
93 $file_upload_nonce_action = "wpcomment_uploading_file_action";
94 if ( ! wp_verify_nonce( $wpcomment_nonce, $file_upload_nonce_action ) && apply_filters('wpcomment_verify_upload_file', true) ) {
95 $response ['status'] = 'error';
96 $response ['message'] = __ ( 'You cannot upload the file at this time, please refresh the page and try again. Note that your current option choices will be reset.', 'wp-comment-fields' );
97 wp_send_json( $response );
98 }
99
100 // setting up some variables
101 $file_dir_path = wpcomment_get_dir_path();
102 $response = array ();
103 if ($file_dir_path == 'errDirectory') {
104
105 $response ['status'] = 'error';
106 $response ['message'] = __ ( 'Error while creating directory', 'wp-comment-fields' );
107 wp_send_json( $response );
108 }
109
110 $file_name = '';
111
112 if( isset($_REQUEST['name']) && $_REQUEST['name'] != '') {
113 $file_name = sanitize_file_name( $_REQUEST['name'] );
114 }elseif( isset($_REQUEST['_file']) && $_REQUEST['_file'] != '') {
115 $file_name = sanitize_file_name( $_REQUEST['_file'] );
116 }
117
118 $file_name = apply_filters('wpcomment_uploaded_filename', $file_name);
119
120 /* ========== Invalid File type checking ========== */
121 $file_type = wp_check_filetype($file_name);
122 $extension = $file_type['ext'];
123
124
125 $default_restricted = 'php,php4,php5,php6,php7,phtml,exe,shtml';
126 $restricted_type = wpcomment_get_option('wpcomment_restricted_file_type', $default_restricted);
127 $restricted_type = explode(',', $restricted_type);
128
129 if( in_array( strtolower($extension), $restricted_type) ){
130 $response ['status'] = 'error';
131 $response ['message'] = __ ( 'File type not valid - '.$extension, 'wp-comment-fields' );
132 wp_send_json( $response );
133 }
134 /* ========== Invalid File type checking ========== */
135
136 $cleanupTargetDir = true; // Remove old files
137 $maxFileAge = 5 * 3600; // Temp file age in seconds
138
139 // 5 minutes execution time
140 @set_time_limit ( 5 * 60 );
141
142 // Uncomment this one to fake upload time
143 // usleep(5000);
144
145 // Get parameters
146 $chunk = isset ( $_REQUEST ["chunk"] ) ? intval ( $_REQUEST ["chunk"] ) : 0;
147 $chunks = isset ( $_REQUEST ["chunks"] ) ? intval ( $_REQUEST ["chunks"] ) : 0;
148 // $file_name = isset ( $_REQUEST ["name"] ) ? sanitize_file_name($_REQUEST ["name"]) : '';
149
150 $file_path_thumb = $file_dir_path . 'thumbs';
151 $file_name = wp_unique_filename($file_path_thumb, $file_name);
152 $file_name = strtolower($file_name);
153 $file_path = $file_dir_path . $file_name;
154
155 // var_dump($file_path); exit;
156
157 // Make sure the fileName is unique but only if chunking is disabled
158 if ($chunks < 2 && file_exists ( $file_path )) {
159 $ext = strrpos ( $file_name, '.' );
160 $file_name_a = substr ( $file_name, 0, $ext );
161 $file_name_b = substr ( $file_name, $ext );
162
163 $count = 1;
164 while ( file_exists ( $file_dir_path . $file_name_a . '_' . $count . $file_name_b ) )
165 $count ++;
166
167 $file_name = $file_name_a . '_' . $count . $file_name_b;
168 $file_path = $file_dir_path . $file_name;
169 }
170
171 // Remove old temp files
172 if ($cleanupTargetDir && is_dir ( $file_dir_path ) && ($dir = opendir ( $file_dir_path ))) {
173 while ( ($file = readdir ( $dir )) !== false ) {
174 $tmpfilePath = $file_dir_path . $file;
175
176 // Remove temp file if it is older than the max age and is not the current file
177 if (preg_match ( '/\.part$/', $file ) && (filemtime ( $tmpfilePath ) < time () - $maxFileAge) && ($tmpfilePath != "{$file_path}.part")) {
178 @unlink ( $tmpfilePath );
179 }
180 }
181
182 closedir ( $dir );
183 } else
184 die ( '{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}' );
185
186
187
188 // Look for the content type header
189 if (isset ( $_SERVER ["HTTP_CONTENT_TYPE"] ))
190 $contentType = $_SERVER ["HTTP_CONTENT_TYPE"];
191
192 if (isset ( $_SERVER ["CONTENT_TYPE"] ))
193 $contentType = $_SERVER ["CONTENT_TYPE"];
194
195 // Handle non multipart uploads older WebKit versions didn't support multipart in HTML5
196 if (strpos ( $contentType, "multipart" ) !== false) {
197 if (isset ( $_FILES ['file'] ['tmp_name'] ) && is_uploaded_file ( $_FILES ['file'] ['tmp_name'] )) {
198 // Open temp file
199 $out = fopen ( "{$file_path}.part", $chunk == 0 ? "wb" : "ab" );
200 if ($out) {
201 // Read binary input stream and append it to temp file
202 $in = fopen ( sanitize_text_field($_FILES ['file'] ['tmp_name']), "rb" );
203
204 if ($in) {
205 while ( $buff = fread ( $in, 4096 ) )
206 fwrite ( $out, $buff );
207 } else
208 die ( '{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}' );
209 fclose ( $in );
210 fclose ( $out );
211 @unlink ( sanitize_text_field($_FILES ['file'] ['tmp_name']) );
212 } else
213 die ( '{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}' );
214 } else
215 die ( '{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}' );
216 } else {
217 // Open temp file
218 $out = fopen ( "{$file_path}.part", $chunk == 0 ? "wb" : "ab" );
219 if ($out) {
220 // Read binary input stream and append it to temp file
221 $in = fopen ( "php://input", "rb" );
222
223 if ($in) {
224 while ( $buff = fread ( $in, 4096 ) )
225 fwrite ( $out, $buff );
226 } else
227 die ( '{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}' );
228
229 fclose ( $in );
230 fclose ( $out );
231 } else
232 die ( '{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}' );
233 }
234
235 // Check if file has been uploaded
236 if (! $chunks || $chunk == $chunks - 1) {
237 // Strip the temp .part suffix off
238 rename ( "{$file_path}.part", $file_path );
239
240 $data_name = sanitize_key($_REQUEST['data_name']);
241 // $product_id = intval($_REQUEST['product_id']);
242 // $file_meta = wpcomment_get_field_meta_by_dataname($product_id , $data_name );
243 // $comment_meta = wpcomment_get_saved_meta();
244 // wbps_logger_array($comment_meta);
245
246
247 // making thumb if images
248 if( wpcomment_is_file_image($file_name) ) {
249
250 $thumb_size = wpcomment_get_thumbs_size();
251 $thumb_dir_path = wpcomment_create_image_thumb($file_dir_path, $file_name, $thumb_size);
252 if(file_exists($thumb_dir_path)){
253 list($fw, $fh) = getimagesize( $file_path );
254 $response = array(
255 'file_name' => $file_name,
256 'file_w' => $fw,
257 'file_h' => $fh,
258 'nocache' => time(),
259 'file_url' => wpcomment_get_dir_url() . $file_name,
260 'html' => wpcomment_uploaded_file_preview($file_name, $data_name),
261 );
262 }else{
263 $response = array(
264 'file_name' => 'ThumbNotFound',
265 );
266 }
267 }else{
268 $response = array(
269 'file_name' => $file_name,
270 'file_w' => 'na',
271 'file_h' => 'na',
272 'html' => wpcomment_uploaded_file_preview($file_name, $data_name),
273 );
274 }
275 }
276 // Return JSON-RPC response
277 //die ( '{"jsonrpc" : "2.0", "result" : '. json_encode($response) .', "id" : "id"}' );
278 die ( json_encode( apply_filters('wpcomment_file_upload', $response, $file_type, $file_dir_path, $file_name)) );
279 }
280
281 // Deleting file
282 function wpcomment_delete_file() {
283
284 $file_name = sanitize_file_name( $_REQUEST ['file_name'] );
285
286 $wpcomment_nonce = $_REQUEST['wpcomment_nonce'];
287 $file_nonce_action = "wpcomment_deleting_file_action";
288 if ( ! wp_verify_nonce( $wpcomment_nonce, $file_nonce_action ) ) {
289 printf(__("Error while deleting file %s", "wpcomment"), $file_name );
290 die(0);
291 }
292
293 $dir_path = wpcomment_get_dir_path();
294
295 $file_path = $dir_path . $file_name;
296
297 if ( file_exists($file_path) && unlink ( $file_path )) {
298
299 if ( wpcomment_is_file_image($file_name)){
300 $thumb_path = $dir_path . 'thumbs/' . $file_name;
301 if(file_exists($thumb_path))
302 unlink ( $thumb_path );
303
304 $cropped_image_path = $dir_path . 'cropped/' . $file_name;
305 if(file_exists($cropped_image_path))
306 unlink ( $cropped_image_path );
307 }
308
309 // make sure file is removed
310 if( ! file_exists($file_path) ) {
311 _e( 'File removed', 'wp-comment-fields' );
312 } else {
313 printf(__("Error while deleting file %s", "wpcomment"), $file_path );
314 }
315
316
317 } else {
318 printf(__("Error while deleting file %s", "wpcomment"), $file_path );
319 }
320
321 die ( 0 );
322 }
323
324 // Creating thumb for image
325 function wpcomment_create_image_thumb( $file_path, $image_name, $thumb_size ) {
326
327 $thumb_size = intval($thumb_size);
328 $wp_image = wp_get_image_editor ( $file_path . $image_name );
329 $image_destination = $file_path . 'thumbs/' . $image_name;
330 if (! is_wp_error ( $wp_image )) {
331 $wp_image -> resize ( $thumb_size, $thumb_size, true );
332 $wp_image -> save ( $image_destination );
333 }
334
335 return $image_destination;
336 }
337
338 // Get file download url after payment
339 function wpcomment_get_file_download_url( $file_name, $order_id, $product_id ) {
340
341 $base_dir_path = wpcomment_get_dir_path() . $file_name;
342 $confirm_dir = 'confirmed/'.$order_id;
343 $confirmed_dir_path = wpcomment_get_dir_path($confirm_dir);
344 $edits_dir_path = wpcomment_get_dir_path('edits') . $file_name;
345
346 $wpcomment_dir_url = wpcomment_get_dir_url();
347
348 $file_download_url_found = '';
349
350 $file_name = $product_id . '-' . $file_name;
351
352 // Check if file not yet moved to confirm then move it.
353 if( file_exists($base_dir_path) ) {
354 if(rename ( $base_dir_path, $confirmed_dir_path.$file_name)) {
355 $file_download_url_found = $wpcomment_dir_url .'confirmed/' .$order_id .'/' . $file_name;
356 }
357 } else if( file_exists($confirmed_dir_path.$file_name) ) {
358 $file_download_url_found = $wpcomment_dir_url .'confirmed/' .$order_id .'/' . $file_name;
359 } else if( file_exists($edits_dir_path) ) {
360 $file_download_url_found = $wpcomment_dir_url . 'edits/' . $file_name;
361 }
362
363 return apply_filters('wpcomment_file_download_url', $file_download_url_found, $file_name);
364
365 }
366
367 // Generate uploaded file preview
368 function wpcomment_uploaded_file_preview($file_name, $data_name){
369
370 $file_dir_path = wpcomment_get_dir_path();
371 $file_path = $file_dir_path . $file_name;
372
373 if( !file_exists($file_path) ) return '';
374
375 $is_image = wpcomment_is_file_image($file_name);
376
377 $thumb_url = $file_meta = $file_tools = $html = '';
378
379 // $settings = json_decode(stripslashes($settings), true);
380 // wpcomment_pa($settings);
381 $file_id = 'thumb_'.time();
382
383 if($is_image){
384
385 list($fw, $fh) = getimagesize( $file_path );
386 $file_meta = $fw . '(w) x '.$fh.'(h)';
387 $file_meta .= ' - '.__('Size: ', "wpcomment") . wpcomment_get_filesize_in_kb($file_name);
388
389 $thumb_url = wpcomment_get_dir_url( true ) . $file_name . '?nocache='.time();
390
391 //large view
392 $image_url = wpcomment_get_dir_url() . $file_name . '?nocache='.time();
393 $html .= '<div style="display:none" id="u_i_c_big_'.$file_id.'"><p id="thumb-thickbox"><img src="'.$image_url.'" /></p></div>';
394
395 // Loading Modals
396 // $modal_vars = array('file_id' => $file_id, 'image_full'=>$image_url, 'image_title'=>$file_name);
397 // ob_start();
398 // wpcomment_load_template('v10/file-modals.php', $modal_vars);
399 // $html .= ob_get_clean();
400
401 // Tools group
402 $file_tools .= '<div class="btn-group" role="group" aria-label="Tools" style="text-align: center; display: block;">';
403 // $file_tools .= '<a href="#" class="nm-file-tools btn btn-primary u_i_c_tools_del" title="'.__('Remove', "wpcomment").'"><span class="fa fa-times"></span></a>';
404 $file_tools .= '<a href="#" class="nm-file-tools btn btn-primary u_i_c_tools_del" title="'.__('Remove', "wpcomment").'">'.__('Delete', 'wp-comment-fields').'</span></a>';
405
406 if( apply_filters('wpcomment_show_image_popup', false) ) {
407 $file_tools .= '<a href="#" data-toggle="modal" data-target="#modalFile'.esc_attr($file_id).'" class="btn btn-primary"><span class="fa fa-expand"></span></a>';
408 }
409
410
411 $file_tools .= '</div>';
412
413 }else{
414
415 $file_meta .= __('Size: ', "wpcomment") . wpcomment_get_filesize_in_kb($file_name);
416 $thumb_url = WPCOMMENT_URL . '/images/file.png';
417
418 $file_tools .= '<a class="btn btn-primary nm-file-tools u_i_c_tools_del" href="" title="'.__('Remove', "wpcomment").'"><span class="fa fa-times"></span></a>'; //delete icon
419 // $file_tools .= '<a class="btn btn-primary nm-file-tools u_i_c_tools_del" href="" title="'.__('Remove', "wpcomment").'">Delete</a>'; //delete icon
420 }
421
422
423 $short_name = wpcomment_files_trim_name( $file_name );
424
425 // $html .= '<table class="table table-bordered"><tr>';
426 // $html .= '<td style="vertical-align:middle">';
427 $html .='<label style="margin-top: 8px;display: block;text-align: center;">
428 <div class="pre_upload_image collapse_dropdown_id" data-wpcomment-tooltip="wpcomment_tooltip" title="'.$short_name.'">
429
430 <img class="img-thumbnail" style="width:'.esc_attr(wpcomment_get_thumbs_size()).'" data-filename="'.esc_attr($file_name).'" id="'.esc_attr($file_id).'" src="'.esc_url($thumb_url).'" />
431 </div>
432 </label>';
433 $html .= $file_tools;
434
435
436 // $html .= '</tr></table>';
437
438 // $html .= '<td class="nm-imagetools" style="padding-left: 5px; vertical-align:top"><h4>'.$short_name.'</h4><br>';
439 // $html .= '<span class="file-meta">'.$short_name.'</span><br>';
440 // $html .= '</td>';
441
442
443 return apply_filters('wpcomment_file_preview_html', $html, $file_name, $settings);
444 }
445
446 // Trim long filename to short
447 function wpcomment_files_trim_name( $file_name ) {
448
449 $text_length = strlen($file_name);
450
451 // for different language string
452 $string_utf8 = strlen(utf8_decode($file_name));
453
454 $max_chars = apply_filters('wpcomment_trim_file_maxchar', 20);
455
456 if( $text_length > $max_chars && $text_length == $string_utf8 ) {
457 $trimmed_filename = substr_replace($file_name, '...', $max_chars/2, $text_length-$max_chars);
458 } else {
459 $trimmed_filename = $file_name;
460 }
461 return $trimmed_filename;
462 }
463
464
465 // Save cropped image fro dataUrl to image
466 function wpcomment_save_data_url_to_image($data, $file_name) {
467
468 $data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data));
469
470 $dest_cropped = wpcomment_get_dir_path('cropped') . $file_name;
471 file_put_contents( $dest_cropped, $data);
472 }
473
474 // Building options array for croppie
475 function wpcomment_get_croppie_options( $settings ) {
476
477 // wpcomment_pa($settings);
478
479 $cropping_settigs = array();
480 $viewport_type = !empty($settings['viewport_type']) ? $settings['viewport_type'] : 'square';
481
482
483 $viewport_h = !empty($viewport['height']) ? $viewport['height'] : 300;
484 $viewport_w = !empty($viewport['width']) ? $viewport['width'] : 300;
485
486
487
488 $viewport_settings = wpcomment_get_viewport_settings( $settings );
489
490 // view height, width and type
491 $cropping_settigs['viewport'] = $viewport_settings;
492 // $cropping_settigs['viewport_all'] = $settings['options'];
493
494 // Boundary settings
495
496 $boundary = !empty($settings['boundary']) ? $settings['boundary'] : '200,200';
497 $boundary = explode(",", $boundary);
498
499 $boundary_h = $boundary[0];
500 $boundary_w = $boundary[1];
501
502 if( $viewport_type == 'circle' ) { // If circle then set same heigt and width
503 $boundary_w = $boundary_h;
504 }
505
506 // boundary height, width
507 $cropping_settigs['boundary'] = array('height'=>$boundary_h, 'width'=>$boundary_w);
508
509 $enable_exif = ( isset($settings['enable_exif']) && $settings['enable_exif'] == 'on') ? true : false;
510 // exif
511 $cropping_settigs['enableExif'] = $enable_exif;
512
513 $enforce_boundary = ( isset($settings['enforce_boundary']) && $settings['enforce_boundary'] == 'on') ? true : false;
514 // enforce boundary
515 $cropping_settigs['enforceBoundary'] = $enforce_boundary;
516
517 $enable_zoom = ( isset($settings['enable_zoom']) && $settings['enable_zoom'] == 'on') ? true : false;
518 // show zoomer
519 $cropping_settigs['enableZoom'] = $enable_zoom;
520
521 $show_zoomer = ( isset($settings['show_zoomer']) && $settings['show_zoomer'] == 'on') ? true : false;
522 // show zoomer
523 $cropping_settigs['showZoomer'] = $show_zoomer;
524
525
526 return apply_filters('wpcomment_croppie_options', $cropping_settigs, $settings);
527
528 }
529
530 function wpcomment_get_viewport_settings( $settings ) {
531
532 $viewport_type = !empty($settings['viewport_type']) ? $settings['viewport_type'] : 'square';
533
534 $first_viewport_size = array();
535
536 if( isset($settings['options']) ) {
537 foreach($settings['options'] as $option => $viewport) {
538
539 if( ! isset($viewport['width']) ) continue;
540
541 $first_viewport_size['width'] = $viewport['width'];
542 $first_viewport_size['height'] = $viewport['height'];
543 break;
544 }
545 }
546
547
548 $the_viewport = array('width'=>300,'height'=>300);
549 if( !empty($first_viewport_size['width']) && !empty($first_viewport_size['height'])) {
550
551 $the_viewport = array('width'=>$first_viewport_size['width'],'height'=>$first_viewport_size['height']);
552 }
553
554 $the_viewport['type'] = $viewport_type;
555
556 return $the_viewport;
557
558 }
559
560 /*
561 * removing ununsed order files
562 */
563 function wpcomment_files_removed_unused_images(){
564
565 $dir = wpcomment_get_dir_path();
566
567 if(is_dir($dir) && apply_filters('wpcomment_remove_unused_images', true)){
568
569 $dir_handle = opendir($dir);
570 while ($file = readdir($dir_handle)){
571
572 $file_path = $dir.$file;
573 if( is_file ($file_path) ){
574
575 // Get Files Created Date
576 $file_created_date = date ("Y-m-d H:i:s.", filemtime($file_path));
577 $today = date("Y-m-d H:i:s");
578
579 $day_count = wpcomment_files_uploaded_days_count($file_created_date, $today);
580
581 if ($day_count > 7) {
582 @unlink($file_path);
583 }
584 }
585 }
586 }
587
588 closedir($dir_handle);
589 }
590
591 function wpcomment_files_uploaded_days_count($date1, $date2){
592
593 $diff = strtotime($date2) - strtotime($date1);
594
595 return abs(round($diff / 86400));
596 }
597
598 // Return file name with prefix product id
599 function wpcomment_file_get_name($file_name, $product_id, $cart_item=null) {
600
601 $new_file_name = "{$product_id}-{$file_name}";
602 return apply_filters('wpcomment_file_name_prefix', $new_file_name, $file_name, $product_id, $cart_item);
603 }
604