| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* File: /helper/e2pdf-filter.php |
| 5 |
* |
| 6 |
* @package E2Pdf |
| 7 |
* @license GPLv3 |
| 8 |
* @link https://e2pdf.com |
| 9 |
*/ |
| 10 |
if (!defined('ABSPATH')) { |
| 11 |
die('Access denied.'); |
| 12 |
} |
| 13 |
|
| 14 |
class Helper_E2pdf_Filter { |
| 15 |
|
| 16 |
// is stream |
| 17 |
public function is_stream($file_path) { |
| 18 |
if (strpos($file_path, '://') > 0) { |
| 19 |
$wrappers = array( |
| 20 |
'phar', |
| 21 |
); |
| 22 |
if (function_exists('stream_get_wrappers')) { |
| 23 |
$wrappers = stream_get_wrappers(); |
| 24 |
} |
| 25 |
|
| 26 |
foreach ($wrappers as $wrapper) { |
| 27 |
if (in_array($wrapper, ['http', 'https', 'file'], true)) { |
| 28 |
continue; |
| 29 |
} |
| 30 |
if (stripos($file_path, $wrapper . '://') === 0) { |
| 31 |
return true; |
| 32 |
} |
| 33 |
} |
| 34 |
} |
| 35 |
return false; |
| 36 |
} |
| 37 |
|
| 38 |
// is downloadable |
| 39 |
public function is_downloadable($file_path) { |
| 40 |
if (!$file_path || !$this->is_downloadable_ext($file_path)) { |
| 41 |
return false; |
| 42 |
} |
| 43 |
return true; |
| 44 |
} |
| 45 |
|
| 46 |
// is downlodable ext |
| 47 |
public function is_downloadable_ext($file_path) { |
| 48 |
$ext = strtolower(pathinfo($file_path, PATHINFO_EXTENSION)); |
| 49 |
$allowed = apply_filters( |
| 50 |
'e2pdf_helper_filter_is_downloadable_allowed_extensions', |
| 51 |
['pdf', 'jpg', 'doc', 'docx'] |
| 52 |
); |
| 53 |
return in_array($ext, $allowed, true); |
| 54 |
} |
| 55 |
|
| 56 |
// filter html tags |
| 57 |
public function filter_html_tags($value) { |
| 58 |
if ($value) { |
| 59 |
$tags = array( |
| 60 |
'script', |
| 61 |
'style', |
| 62 |
); |
| 63 |
foreach ($tags as $tag) { |
| 64 |
$value = preg_replace('#<' . $tag . '(.*?)>(.*?)</' . $tag . '>#is', '', $value); |
| 65 |
} |
| 66 |
} |
| 67 |
return $value; |
| 68 |
} |
| 69 |
} |
| 70 |
|