Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/wp-conte.../plugins/wp-file-.../lib/php
File: elFinder.class.php
$result['warning'] = $this->error(self::ERROR_LOCKED, $rm['name']);
[2500] Fix | Delete
break;
[2501] Fix | Delete
}
[2502] Fix | Delete
[2503] Fix | Delete
if (!$volume->rm($target)) {
[2504] Fix | Delete
$result['warning'] = $this->error($volume->error());
[2505] Fix | Delete
break;
[2506] Fix | Delete
}
[2507] Fix | Delete
}
[2508] Fix | Delete
[2509] Fix | Delete
return $result;
[2510] Fix | Delete
}
[2511] Fix | Delete
[2512] Fix | Delete
/**
[2513] Fix | Delete
* Return has subdirs
[2514] Fix | Delete
*
[2515] Fix | Delete
* @param array command arguments
[2516] Fix | Delete
*
[2517] Fix | Delete
* @return array
[2518] Fix | Delete
* @author Dmitry Naoki Sawada
[2519] Fix | Delete
**/
[2520] Fix | Delete
protected function subdirs($args)
[2521] Fix | Delete
{
[2522] Fix | Delete
[2523] Fix | Delete
$result = array('subdirs' => array());
[2524] Fix | Delete
$targets = $args['targets'];
[2525] Fix | Delete
[2526] Fix | Delete
foreach ($targets as $target) {
[2527] Fix | Delete
if (($volume = $this->volume($target)) !== false) {
[2528] Fix | Delete
$result['subdirs'][$target] = $volume->subdirs($target) ? 1 : 0;
[2529] Fix | Delete
}
[2530] Fix | Delete
}
[2531] Fix | Delete
return $result;
[2532] Fix | Delete
}
[2533] Fix | Delete
[2534] Fix | Delete
/**
[2535] Fix | Delete
* Gateway for custom contents editor
[2536] Fix | Delete
*
[2537] Fix | Delete
* @param array $args command arguments
[2538] Fix | Delete
*
[2539] Fix | Delete
* @return array
[2540] Fix | Delete
* @author Naoki Sawada
[2541] Fix | Delete
*/
[2542] Fix | Delete
protected function editor($args = array())
[2543] Fix | Delete
{
[2544] Fix | Delete
/* @var elFinderEditor $editor */
[2545] Fix | Delete
$name = $args['name'];
[2546] Fix | Delete
if (is_array($name)) {
[2547] Fix | Delete
$res = array();
[2548] Fix | Delete
foreach ($name as $c) {
[2549] Fix | Delete
$class = 'elFinderEditor' . $c;
[2550] Fix | Delete
if (class_exists($class)) {
[2551] Fix | Delete
$editor = new $class($this, $args['args']);
[2552] Fix | Delete
$res[$c] = $editor->enabled();
[2553] Fix | Delete
} else {
[2554] Fix | Delete
$res[$c] = 0;
[2555] Fix | Delete
}
[2556] Fix | Delete
}
[2557] Fix | Delete
return $res;
[2558] Fix | Delete
} else {
[2559] Fix | Delete
$class = 'elFinderEditor' . $name;
[2560] Fix | Delete
$method = '';
[2561] Fix | Delete
if (class_exists($class)) {
[2562] Fix | Delete
$editor = new $class($this, $args['args']);
[2563] Fix | Delete
$method = $args['method'];
[2564] Fix | Delete
if ($editor->isAllowedMethod($method) && method_exists($editor, $method)) {
[2565] Fix | Delete
return $editor->$method();
[2566] Fix | Delete
}
[2567] Fix | Delete
}
[2568] Fix | Delete
return array('error', $this->error(self::ERROR_UNKNOWN_CMD, 'editor.' . $name . '.' . $method));
[2569] Fix | Delete
}
[2570] Fix | Delete
}
[2571] Fix | Delete
[2572] Fix | Delete
/**
[2573] Fix | Delete
* Abort current request and make flag file to running check
[2574] Fix | Delete
*
[2575] Fix | Delete
* @param array $args
[2576] Fix | Delete
*
[2577] Fix | Delete
* @return void
[2578] Fix | Delete
*/
[2579] Fix | Delete
protected function abort($args = array())
[2580] Fix | Delete
{
[2581] Fix | Delete
if (!elFinder::$connectionFlagsPath || $_SERVER['REQUEST_METHOD'] === 'HEAD') {
[2582] Fix | Delete
return;
[2583] Fix | Delete
}
[2584] Fix | Delete
$flagFile = elFinder::$connectionFlagsPath . DIRECTORY_SEPARATOR . 'elfreq%s';
[2585] Fix | Delete
if (!empty($args['makeFile'])) {
[2586] Fix | Delete
self::$abortCheckFile = sprintf($flagFile, self::filenameDecontaminate($args['makeFile']));
[2587] Fix | Delete
touch(self::$abortCheckFile);
[2588] Fix | Delete
$GLOBALS['elFinderTempFiles'][self::$abortCheckFile] = true;
[2589] Fix | Delete
return;
[2590] Fix | Delete
}
[2591] Fix | Delete
[2592] Fix | Delete
$file = !empty($args['id']) ? sprintf($flagFile, self::filenameDecontaminate($args['id'])) : self::$abortCheckFile;
[2593] Fix | Delete
$file && is_file($file) && unlink($file);
[2594] Fix | Delete
}
[2595] Fix | Delete
[2596] Fix | Delete
/**
[2597] Fix | Delete
* Validate an URL to prevent SSRF attacks.
[2598] Fix | Delete
*
[2599] Fix | Delete
* To prevent any risk of DNS rebinding, always use the IP address resolved by
[2600] Fix | Delete
* this method, as returned in the array entry `ip`.
[2601] Fix | Delete
*
[2602] Fix | Delete
* @param string $url
[2603] Fix | Delete
*
[2604] Fix | Delete
* @return false|array
[2605] Fix | Delete
*/
[2606] Fix | Delete
protected function validate_address($url)
[2607] Fix | Delete
{
[2608] Fix | Delete
$info = parse_url($url);
[2609] Fix | Delete
$host = trim(strtolower($info['host']), '.');
[2610] Fix | Delete
// do not support IPv6 address
[2611] Fix | Delete
if (preg_match('/^\[.*\]$/', $host)) {
[2612] Fix | Delete
return false;
[2613] Fix | Delete
}
[2614] Fix | Delete
// do not support non dot host
[2615] Fix | Delete
if (strpos($host, '.') === false) {
[2616] Fix | Delete
return false;
[2617] Fix | Delete
}
[2618] Fix | Delete
// do not support URL-encoded host
[2619] Fix | Delete
if (strpos($host, '%') !== false) {
[2620] Fix | Delete
return false;
[2621] Fix | Delete
}
[2622] Fix | Delete
// disallow including "localhost" and "localdomain"
[2623] Fix | Delete
if (preg_match('/\b(?:localhost|localdomain)\b/', $host)) {
[2624] Fix | Delete
return false;
[2625] Fix | Delete
}
[2626] Fix | Delete
// check IPv4 local loopback, private network and link local
[2627] Fix | Delete
$ip = gethostbyname($host);
[2628] Fix | Delete
if (preg_match('/^0x[0-9a-f]+|[0-9]+(?:\.(?:0x[0-9a-f]+|[0-9]+)){1,3}$/', $ip, $m)) {
[2629] Fix | Delete
$long = (int)sprintf('%u', ip2long($ip));
[2630] Fix | Delete
if (!$long) {
[2631] Fix | Delete
return false;
[2632] Fix | Delete
}
[2633] Fix | Delete
$local = (int)sprintf('%u', ip2long('127.255.255.255')) >> 24;
[2634] Fix | Delete
$prv1 = (int)sprintf('%u', ip2long('10.255.255.255')) >> 24;
[2635] Fix | Delete
$prv2 = (int)sprintf('%u', ip2long('172.31.255.255')) >> 20;
[2636] Fix | Delete
$prv3 = (int)sprintf('%u', ip2long('192.168.255.255')) >> 16;
[2637] Fix | Delete
$link = (int)sprintf('%u', ip2long('169.254.255.255')) >> 16;
[2638] Fix | Delete
[2639] Fix | Delete
if (!isset($this->uploadAllowedLanIpClasses['local']) && $long >> 24 === $local) {
[2640] Fix | Delete
return false;
[2641] Fix | Delete
}
[2642] Fix | Delete
if (!isset($this->uploadAllowedLanIpClasses['private_a']) && $long >> 24 === $prv1) {
[2643] Fix | Delete
return false;
[2644] Fix | Delete
}
[2645] Fix | Delete
if (!isset($this->uploadAllowedLanIpClasses['private_b']) && $long >> 20 === $prv2) {
[2646] Fix | Delete
return false;
[2647] Fix | Delete
}
[2648] Fix | Delete
if (!isset($this->uploadAllowedLanIpClasses['private_c']) && $long >> 16 === $prv3) {
[2649] Fix | Delete
return false;
[2650] Fix | Delete
}
[2651] Fix | Delete
if (!isset($this->uploadAllowedLanIpClasses['link']) && $long >> 16 === $link) {
[2652] Fix | Delete
return false;
[2653] Fix | Delete
}
[2654] Fix | Delete
$info['ip'] = long2ip($long);
[2655] Fix | Delete
if (!isset($info['port'])) {
[2656] Fix | Delete
$info['port'] = $info['scheme'] === 'https' ? 443 : 80;
[2657] Fix | Delete
}
[2658] Fix | Delete
if (!isset($info['path'])) {
[2659] Fix | Delete
$info['path'] = '/';
[2660] Fix | Delete
}
[2661] Fix | Delete
return $info;
[2662] Fix | Delete
} else {
[2663] Fix | Delete
return false;
[2664] Fix | Delete
}
[2665] Fix | Delete
}
[2666] Fix | Delete
[2667] Fix | Delete
/**
[2668] Fix | Delete
* Get remote contents
[2669] Fix | Delete
*
[2670] Fix | Delete
* @param string $url target url
[2671] Fix | Delete
* @param int $timeout timeout (sec)
[2672] Fix | Delete
* @param int $redirect_max redirect max count
[2673] Fix | Delete
* @param string $ua
[2674] Fix | Delete
* @param resource $fp
[2675] Fix | Delete
*
[2676] Fix | Delete
* @return string, resource or bool(false)
[2677] Fix | Delete
* @retval string contents
[2678] Fix | Delete
* @retval resource conttents
[2679] Fix | Delete
* @rettval false error
[2680] Fix | Delete
* @author Naoki Sawada
[2681] Fix | Delete
**/
[2682] Fix | Delete
protected function get_remote_contents(&$url, $timeout = 30, $redirect_max = 5, $ua = 'Mozilla/5.0', $fp = null)
[2683] Fix | Delete
{
[2684] Fix | Delete
if (preg_match('~^(?:ht|f)tps?://[-_.!\~*\'()a-z0-9;/?:\@&=+\$,%#\*\[\]]+~i', $url)) {
[2685] Fix | Delete
$info = $this->validate_address($url);
[2686] Fix | Delete
if ($info === false) {
[2687] Fix | Delete
return false;
[2688] Fix | Delete
}
[2689] Fix | Delete
// dose not support 'user' and 'pass' for security reasons
[2690] Fix | Delete
$url = $info['scheme'].'://'.$info['host'].(!empty($info['port'])? (':'.$info['port']) : '').$info['path'].(!empty($info['query'])? ('?'.$info['query']) : '').(!empty($info['fragment'])? ('#'.$info['fragment']) : '');
[2691] Fix | Delete
// check by URL upload filter
[2692] Fix | Delete
if ($this->urlUploadFilter && is_callable($this->urlUploadFilter)) {
[2693] Fix | Delete
if (!call_user_func_array($this->urlUploadFilter, array($url, $this))) {
[2694] Fix | Delete
return false;
[2695] Fix | Delete
}
[2696] Fix | Delete
}
[2697] Fix | Delete
$method = (function_exists('curl_exec')) ? 'curl_get_contents' : 'fsock_get_contents';
[2698] Fix | Delete
return $this->$method($url, $timeout, $redirect_max, $ua, $fp, $info);
[2699] Fix | Delete
}
[2700] Fix | Delete
return false;
[2701] Fix | Delete
}
[2702] Fix | Delete
[2703] Fix | Delete
/**
[2704] Fix | Delete
* Get remote contents with cURL
[2705] Fix | Delete
*
[2706] Fix | Delete
* @param string $url target url
[2707] Fix | Delete
* @param int $timeout timeout (sec)
[2708] Fix | Delete
* @param int $redirect_max redirect max count
[2709] Fix | Delete
* @param string $ua
[2710] Fix | Delete
* @param resource $outfp
[2711] Fix | Delete
*
[2712] Fix | Delete
* @return string, resource or bool(false)
[2713] Fix | Delete
* @retval string contents
[2714] Fix | Delete
* @retval resource conttents
[2715] Fix | Delete
* @retval false error
[2716] Fix | Delete
* @author Naoki Sawada
[2717] Fix | Delete
**/
[2718] Fix | Delete
protected function curl_get_contents(&$url, $timeout, $redirect_max, $ua, $outfp, $info)
[2719] Fix | Delete
{
[2720] Fix | Delete
if ($redirect_max == 0) {
[2721] Fix | Delete
return false;
[2722] Fix | Delete
}
[2723] Fix | Delete
$ch = curl_init();
[2724] Fix | Delete
curl_setopt($ch, CURLOPT_URL, $url);
[2725] Fix | Delete
curl_setopt($ch, CURLOPT_HEADER, false);
[2726] Fix | Delete
if ($outfp) {
[2727] Fix | Delete
curl_setopt($ch, CURLOPT_FILE, $outfp);
[2728] Fix | Delete
} else {
[2729] Fix | Delete
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
[2730] Fix | Delete
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
[2731] Fix | Delete
}
[2732] Fix | Delete
curl_setopt($ch, CURLOPT_LOW_SPEED_LIMIT, 1);
[2733] Fix | Delete
curl_setopt($ch, CURLOPT_LOW_SPEED_TIME, $timeout);
[2734] Fix | Delete
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
[2735] Fix | Delete
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
[2736] Fix | Delete
curl_setopt($ch, CURLOPT_USERAGENT, $ua);
[2737] Fix | Delete
curl_setopt($ch, CURLOPT_RESOLVE, array($info['host'] . ':' . $info['port'] . ':' . $info['ip']));
[2738] Fix | Delete
$result = curl_exec($ch);
[2739] Fix | Delete
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
[2740] Fix | Delete
if ($http_code == 301 || $http_code == 302) {
[2741] Fix | Delete
$new_url = curl_getinfo($ch, CURLINFO_REDIRECT_URL);
[2742] Fix | Delete
$info = $this->validate_address($new_url);
[2743] Fix | Delete
if ($info === false) {
[2744] Fix | Delete
return false;
[2745] Fix | Delete
}
[2746] Fix | Delete
return $this->curl_get_contents($new_url, $timeout, $redirect_max - 1, $ua, $outfp, $info);
[2747] Fix | Delete
}
[2748] Fix | Delete
curl_close($ch);
[2749] Fix | Delete
return $outfp ? $outfp : $result;
[2750] Fix | Delete
}
[2751] Fix | Delete
[2752] Fix | Delete
/**
[2753] Fix | Delete
* Get remote contents with fsockopen()
[2754] Fix | Delete
*
[2755] Fix | Delete
* @param string $url url
[2756] Fix | Delete
* @param int $timeout timeout (sec)
[2757] Fix | Delete
* @param int $redirect_max redirect max count
[2758] Fix | Delete
* @param string $ua
[2759] Fix | Delete
* @param resource $outfp
[2760] Fix | Delete
*
[2761] Fix | Delete
* @return string, resource or bool(false)
[2762] Fix | Delete
* @retval string contents
[2763] Fix | Delete
* @retval resource conttents
[2764] Fix | Delete
* @retval false error
[2765] Fix | Delete
* @throws elFinderAbortException
[2766] Fix | Delete
* @author Naoki Sawada
[2767] Fix | Delete
*/
[2768] Fix | Delete
protected function fsock_get_contents(&$url, $timeout, $redirect_max, $ua, $outfp, $info)
[2769] Fix | Delete
{
[2770] Fix | Delete
$connect_timeout = 3;
[2771] Fix | Delete
$connect_try = 3;
[2772] Fix | Delete
$method = 'GET';
[2773] Fix | Delete
$readsize = 4096;
[2774] Fix | Delete
$ssl = '';
[2775] Fix | Delete
[2776] Fix | Delete
$getSize = null;
[2777] Fix | Delete
$headers = '';
[2778] Fix | Delete
[2779] Fix | Delete
$arr = $info;
[2780] Fix | Delete
if ($arr['scheme'] === 'https') {
[2781] Fix | Delete
$ssl = 'ssl://';
[2782] Fix | Delete
}
[2783] Fix | Delete
[2784] Fix | Delete
// query
[2785] Fix | Delete
$arr['query'] = isset($arr['query']) ? '?' . $arr['query'] : '';
[2786] Fix | Delete
[2787] Fix | Delete
$url_base = $arr['scheme'] . '://' . $info['host'] . ':' . $info['port'];
[2788] Fix | Delete
$url_path = isset($arr['path']) ? $arr['path'] : '/';
[2789] Fix | Delete
$uri = $url_path . $arr['query'];
[2790] Fix | Delete
[2791] Fix | Delete
$query = $method . ' ' . $uri . " HTTP/1.0\r\n";
[2792] Fix | Delete
$query .= "Host: " . $arr['host'] . "\r\n";
[2793] Fix | Delete
$query .= "Accept: */*\r\n";
[2794] Fix | Delete
$query .= "Connection: close\r\n";
[2795] Fix | Delete
if (!empty($ua)) $query .= "User-Agent: " . $ua . "\r\n";
[2796] Fix | Delete
if (!is_null($getSize)) $query .= 'Range: bytes=0-' . ($getSize - 1) . "\r\n";
[2797] Fix | Delete
[2798] Fix | Delete
$query .= $headers;
[2799] Fix | Delete
[2800] Fix | Delete
$query .= "\r\n";
[2801] Fix | Delete
[2802] Fix | Delete
$fp = $connect_try_count = 0;
[2803] Fix | Delete
while (!$fp && $connect_try_count < $connect_try) {
[2804] Fix | Delete
[2805] Fix | Delete
$errno = 0;
[2806] Fix | Delete
$errstr = "";
[2807] Fix | Delete
$fp = fsockopen(
[2808] Fix | Delete
$ssl . $arr['host'],
[2809] Fix | Delete
$arr['port'],
[2810] Fix | Delete
$errno, $errstr, $connect_timeout);
[2811] Fix | Delete
if ($fp) break;
[2812] Fix | Delete
$connect_try_count++;
[2813] Fix | Delete
if (connection_aborted()) {
[2814] Fix | Delete
throw new elFinderAbortException();
[2815] Fix | Delete
}
[2816] Fix | Delete
sleep(1); // wait 1sec
[2817] Fix | Delete
}
[2818] Fix | Delete
[2819] Fix | Delete
if (!$fp) {
[2820] Fix | Delete
return false;
[2821] Fix | Delete
}
[2822] Fix | Delete
[2823] Fix | Delete
$fwrite = 0;
[2824] Fix | Delete
for ($written = 0; $written < strlen($query); $written += $fwrite) {
[2825] Fix | Delete
$fwrite = fwrite($fp, substr($query, $written));
[2826] Fix | Delete
if (!$fwrite) {
[2827] Fix | Delete
break;
[2828] Fix | Delete
}
[2829] Fix | Delete
}
[2830] Fix | Delete
[2831] Fix | Delete
if ($timeout) {
[2832] Fix | Delete
socket_set_timeout($fp, $timeout);
[2833] Fix | Delete
}
[2834] Fix | Delete
[2835] Fix | Delete
$_response = '';
[2836] Fix | Delete
$header = '';
[2837] Fix | Delete
while ($_response !== "\r\n") {
[2838] Fix | Delete
$_response = fgets($fp, $readsize);
[2839] Fix | Delete
$header .= $_response;
[2840] Fix | Delete
};
[2841] Fix | Delete
[2842] Fix | Delete
$rccd = array_pad(explode(' ', $header, 2), 2, ''); // array('HTTP/1.1','200')
[2843] Fix | Delete
$rc = (int)$rccd[1];
[2844] Fix | Delete
[2845] Fix | Delete
$ret = false;
[2846] Fix | Delete
// Redirect
[2847] Fix | Delete
switch ($rc) {
[2848] Fix | Delete
case 307: // Temporary Redirect
[2849] Fix | Delete
case 303: // See Other
[2850] Fix | Delete
case 302: // Moved Temporarily
[2851] Fix | Delete
case 301: // Moved Permanently
[2852] Fix | Delete
$matches = array();
[2853] Fix | Delete
if (preg_match('/^Location: (.+?)(#.+)?$/im', $header, $matches) && --$redirect_max > 0) {
[2854] Fix | Delete
$_url = $url;
[2855] Fix | Delete
$url = trim($matches[1]);
[2856] Fix | Delete
if (!preg_match('/^https?:\//', $url)) { // no scheme
[2857] Fix | Delete
if ($url[0] != '/') { // Relative path
[2858] Fix | Delete
// to Absolute path
[2859] Fix | Delete
$url = substr($url_path, 0, strrpos($url_path, '/')) . '/' . $url;
[2860] Fix | Delete
}
[2861] Fix | Delete
// add sheme,host
[2862] Fix | Delete
$url = $url_base . $url;
[2863] Fix | Delete
}
[2864] Fix | Delete
if ($_url === $url) {
[2865] Fix | Delete
sleep(1);
[2866] Fix | Delete
}
[2867] Fix | Delete
fclose($fp);
[2868] Fix | Delete
$info = $this->validate_address($url);
[2869] Fix | Delete
if ($info === false) {
[2870] Fix | Delete
return false;
[2871] Fix | Delete
}
[2872] Fix | Delete
return $this->fsock_get_contents($url, $timeout, $redirect_max, $ua, $outfp, $info);
[2873] Fix | Delete
}
[2874] Fix | Delete
break;
[2875] Fix | Delete
case 200:
[2876] Fix | Delete
$ret = true;
[2877] Fix | Delete
}
[2878] Fix | Delete
if (!$ret) {
[2879] Fix | Delete
fclose($fp);
[2880] Fix | Delete
return false;
[2881] Fix | Delete
}
[2882] Fix | Delete
[2883] Fix | Delete
$body = '';
[2884] Fix | Delete
if (!$outfp) {
[2885] Fix | Delete
$outfp = fopen('php://temp', 'rwb');
[2886] Fix | Delete
$body = true;
[2887] Fix | Delete
}
[2888] Fix | Delete
while (fwrite($outfp, fread($fp, $readsize))) {
[2889] Fix | Delete
if ($timeout) {
[2890] Fix | Delete
$_status = socket_get_status($fp);
[2891] Fix | Delete
if ($_status['timed_out']) {
[2892] Fix | Delete
fclose($outfp);
[2893] Fix | Delete
fclose($fp);
[2894] Fix | Delete
return false; // Request Time-out
[2895] Fix | Delete
}
[2896] Fix | Delete
}
[2897] Fix | Delete
}
[2898] Fix | Delete
if ($body) {
[2899] Fix | Delete
rewind($outfp);
[2900] Fix | Delete
$body = stream_get_contents($outfp);
[2901] Fix | Delete
fclose($outfp);
[2902] Fix | Delete
$outfp = null;
[2903] Fix | Delete
}
[2904] Fix | Delete
[2905] Fix | Delete
fclose($fp);
[2906] Fix | Delete
[2907] Fix | Delete
return $outfp ? $outfp : $body; // Data
[2908] Fix | Delete
}
[2909] Fix | Delete
[2910] Fix | Delete
/**
[2911] Fix | Delete
* Parse Data URI scheme
[2912] Fix | Delete
*
[2913] Fix | Delete
* @param string $str
[2914] Fix | Delete
* @param array $extTable
[2915] Fix | Delete
* @param array $args
[2916] Fix | Delete
*
[2917] Fix | Delete
* @return array
[2918] Fix | Delete
* @author Naoki Sawada
[2919] Fix | Delete
*/
[2920] Fix | Delete
protected function parse_data_scheme($str, $extTable, $args = null)
[2921] Fix | Delete
{
[2922] Fix | Delete
$data = $name = $mime = '';
[2923] Fix | Delete
// Scheme 'data://' require `allow_url_fopen` and `allow_url_include`
[2924] Fix | Delete
if ($fp = fopen('data://' . substr($str, 5), 'rb')) {
[2925] Fix | Delete
if ($data = stream_get_contents($fp)) {
[2926] Fix | Delete
$meta = stream_get_meta_data($fp);
[2927] Fix | Delete
$mime = $meta['mediatype'];
[2928] Fix | Delete
}
[2929] Fix | Delete
fclose($fp);
[2930] Fix | Delete
} else if (preg_match('~^data:(.+?/.+?)?(?:;charset=.+?)?;base64,~', substr($str, 0, 128), $m)) {
[2931] Fix | Delete
$data = base64_decode(substr($str, strlen($m[0])));
[2932] Fix | Delete
if ($m[1]) {
[2933] Fix | Delete
$mime = $m[1];
[2934] Fix | Delete
}
[2935] Fix | Delete
}
[2936] Fix | Delete
if ($data) {
[2937] Fix | Delete
$ext = ($mime && isset($extTable[$mime])) ? '.' . $extTable[$mime] : '';
[2938] Fix | Delete
// Set name if name eq 'image.png' and $args has 'name' array, e.g. clipboard data
[2939] Fix | Delete
if (is_array($args['name']) && isset($args['name'][0])) {
[2940] Fix | Delete
$name = $args['name'][0];
[2941] Fix | Delete
if ($ext) {
[2942] Fix | Delete
$name = preg_replace('/\.[^.]*$/', '', $name);
[2943] Fix | Delete
}
[2944] Fix | Delete
} else {
[2945] Fix | Delete
$name = substr(md5($data), 0, 8);
[2946] Fix | Delete
}
[2947] Fix | Delete
$name .= $ext;
[2948] Fix | Delete
} else {
[2949] Fix | Delete
$data = $name = '';
[2950] Fix | Delete
}
[2951] Fix | Delete
return array($data, $name);
[2952] Fix | Delete
}
[2953] Fix | Delete
[2954] Fix | Delete
/**
[2955] Fix | Delete
* Detect file MIME Type by local path
[2956] Fix | Delete
*
[2957] Fix | Delete
* @param string $path Local path
[2958] Fix | Delete
*
[2959] Fix | Delete
* @return string file MIME Type
[2960] Fix | Delete
* @author Naoki Sawada
[2961] Fix | Delete
*/
[2962] Fix | Delete
protected function detectMimeType($path)
[2963] Fix | Delete
{
[2964] Fix | Delete
static $type, $finfo;
[2965] Fix | Delete
if (!$type) {
[2966] Fix | Delete
if (class_exists('finfo', false)) {
[2967] Fix | Delete
$tmpFileInfo = explode(';', finfo_file(finfo_open(FILEINFO_MIME), __FILE__));
[2968] Fix | Delete
} else {
[2969] Fix | Delete
$tmpFileInfo = false;
[2970] Fix | Delete
}
[2971] Fix | Delete
$regexp = '/text\/x\-(php|c\+\+)/';
[2972] Fix | Delete
if ($tmpFileInfo && preg_match($regexp, array_shift($tmpFileInfo))) {
[2973] Fix | Delete
$type = 'finfo';
[2974] Fix | Delete
$finfo = finfo_open(FILEINFO_MIME);
[2975] Fix | Delete
} elseif (function_exists('mime_content_type')
[2976] Fix | Delete
&& ($_ctypes = explode(';', mime_content_type(__FILE__)))
[2977] Fix | Delete
&& preg_match($regexp, array_shift($_ctypes))) {
[2978] Fix | Delete
$type = 'mime_content_type';
[2979] Fix | Delete
} elseif (function_exists('getimagesize')) {
[2980] Fix | Delete
$type = 'getimagesize';
[2981] Fix | Delete
} else {
[2982] Fix | Delete
$type = 'none';
[2983] Fix | Delete
}
[2984] Fix | Delete
}
[2985] Fix | Delete
[2986] Fix | Delete
$mime = '';
[2987] Fix | Delete
if ($type === 'finfo') {
[2988] Fix | Delete
$mime = finfo_file($finfo, $path);
[2989] Fix | Delete
} elseif ($type === 'mime_content_type') {
[2990] Fix | Delete
$mime = mime_content_type($path);
[2991] Fix | Delete
} elseif ($type === 'getimagesize') {
[2992] Fix | Delete
if ($img = getimagesize($path)) {
[2993] Fix | Delete
$mime = $img['mime'];
[2994] Fix | Delete
}
[2995] Fix | Delete
}
[2996] Fix | Delete
[2997] Fix | Delete
if ($mime) {
[2998] Fix | Delete
$mime = explode(';', $mime);
[2999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function