20 if(strlen($source) >= 2 && substr_compare($source,
'./', 0, 2) === 0)
39 function copyDir($source_dir, $target_dir, $filter = null, $type = null)
41 $source_dir = self::getRealPath($source_dir);
42 $target_dir = self::getRealPath($target_dir);
43 if(!is_dir($source_dir))
49 self::makeDir($target_dir);
51 if(substr($source_dir, -1) != DIRECTORY_SEPARATOR)
53 $source_dir .= DIRECTORY_SEPARATOR;
56 if(substr($target_dir, -1) != DIRECTORY_SEPARATOR)
58 $target_dir .= DIRECTORY_SEPARATOR;
61 $oDir = dir($source_dir);
62 while($file = $oDir->read())
69 if($filter && preg_match($filter, $file))
74 if(is_dir($source_dir . $file))
76 self::copyDir($source_dir . $file, $target_dir . $file, $type);
82 @unlink($target_dir . $file);
86 if(!file_exists($target_dir . $file))
88 @copy($source_dir . $file, $target_dir . $file);
106 setlocale(LC_CTYPE,
'en_US.UTF8',
'ko_KR.UTF8');
107 $source = self::getRealPath($source);
108 $target_dir = self::getRealPath(dirname($target));
109 $target = basename($target);
111 self::makeDir($target_dir);
115 @unlink($target_dir . DIRECTORY_SEPARATOR . $target);
118 @copy($source, $target_dir . DIRECTORY_SEPARATOR . $target);
129 if(($filename = self::exists($filename)) === FALSE ||
filesize($filename) < 1)
134 return @file_get_contents($filename);
147 $filename = self::getRealPath($filename);
148 $pathinfo = pathinfo($filename);
149 self::makeDir($pathinfo[
'dirname']);
152 if(strtolower($mode) ==
'a')
154 $flags = FILE_APPEND;
157 @file_put_contents($filename, $buff, $flags|LOCK_EX);
158 @chmod($filename, 0644);
159 self::clearStatCache($filename);
160 self::invalidateOpcache($filename);
171 return (($filename = self::exists($filename)) !== FALSE) && @unlink($filename);
185 return @
rename(self::getRealPath($source), self::getRealPath($target));
197 if(($source = self::exists($source)) !== FALSE)
199 self::removeFile($target);
200 return self::rename($source, $target);
216 self::rename($source_dir, $target_dir);
230 function readDir($path, $filter =
'', $to_lower = FALSE, $concat_prefix = FALSE)
232 $path = self::getRealPath($path);
235 if(substr($path, -1) !=
'/')
245 $files = scandir($path);
246 foreach($files as $file)
248 if($file{0} ==
'.' || ($filter && !preg_match($filter, $file)))
255 $file = strtolower($file);
260 $file = preg_replace($filter,
'$1', $file);
265 $file = sprintf(
'%s%s', str_replace(
_XE_PATH_,
'', $path), $file);
268 $output[] = str_replace(array(
'/\\',
'//'),
'/', $file);
284 if(self::exists($path_string) !== FALSE)
289 if(!ini_get(
'safe_mode'))
291 @mkdir($path_string, 0755, TRUE);
292 @chmod($path_string, 0755);
307 require_once(
_XE_PATH_ .
'libs/ftp.class.php');
309 if(!$ftp_info->ftp_host)
311 $ftp_info->ftp_host =
"127.0.0.1";
313 if(!$ftp_info->ftp_port)
315 $ftp_info->ftp_port = 21;
317 if(!$oFtp->ftp_connect($ftp_info->ftp_host, $ftp_info->ftp_port))
321 if(!$oFtp->ftp_login($ftp_info->ftp_user, $ftp_info->ftp_password))
328 if(!($ftp_path = $ftp_info->ftp_root_path))
330 $ftp_path = DIRECTORY_SEPARATOR;
333 $path_string = str_replace(
_XE_PATH_,
'', $path_string);
334 $path_list = explode(DIRECTORY_SEPARATOR, $path_string);
337 for($i = 0, $c = count($path_list); $i < $c; $i++)
344 $path .= $path_list[$i] . DIRECTORY_SEPARATOR;
345 $ftp_path .= $path_list[$i] . DIRECTORY_SEPARATOR;
348 $oFtp->ftp_mkdir($ftp_path);
349 $oFtp->ftp_site(
"CHMOD 777 " . $ftp_path);
354 return is_dir($path_string);
365 if(($path = self::isDir($path)) === FALSE)
370 if(self::isDir($path))
372 $files = array_diff(scandir($path), array(
'..',
'.'));
374 foreach($files as $file)
376 if(($target = self::getRealPath($path . DIRECTORY_SEPARATOR . $file)) === FALSE)
383 self::removeDir($target);
406 if(($path = self::isDir($path)) === FALSE)
411 $files = array_diff(scandir($path), array(
'..',
'.'));
413 if(count($files) < 1)
419 foreach($files as $file)
421 if(($target = self::isDir($path . DIRECTORY_SEPARATOR . $file)) === FALSE)
426 self::removeBlankDir($target);
440 if(($path = self::getRealPath($path)) === FALSE)
447 $files = array_diff(scandir($path), array(
'..',
'.'));
449 foreach($files as $file)
451 if(($target = self::getRealPath($path . DIRECTORY_SEPARATOR . $file)) === FALSE)
458 self::removeFilesInDir($target);
468 if(self::exists($path)) unlink($path);
494 return $size .
'Bytes';
497 if($size >= 1024 && $size < 1024 * 1024)
499 return sprintf(
"%0.1fKB", $size / 1024);
502 return sprintf(
"%0.2fMB", $size / (1024 * 1024));
520 function getRemoteResource($url, $body = null, $timeout = 3, $method =
'GET', $content_type = null, $headers = array(), $cookies = array(), $post_data = array(), $request_config = array())
522 require_once(
_XE_PATH_ .
'libs/idna_convert/idna_convert.class.php');
524 $url =
$IDN->encode($url);
529 require_once(
'HTTP/Request.php');
531 $parsed_url = parse_url(__PROXY_SERVER__);
532 if($parsed_url[
"host"] && $parsed_url[
"path"])
536 $oRequest->setMethod(
'POST');
537 $oRequest->addPostData(
'arg', serialize(array(
'Destination' => $url,
'method' => $method,
'body' => $body,
'content_type' => $content_type,
"headers" => $headers,
"post_data" => $post_data)));
544 if($parsed_url[
'host'])
546 $request_config[
'proxy_host'] = $parsed_url[
'host'];
547 $request_config[
'proxy_port'] = $parsed_url[
'port'] ? $parsed_url[
'port'] :
'';
548 $request_config[
'proxy_user'] = rawurldecode($parsed_url[
'user'] ? $parsed_url[
'user'] :
'');
549 $request_config[
'proxy_password'] = rawurldecode($parsed_url[
'pass'] ? $parsed_url[
'pass'] :
'');
550 $request_config[
'proxy_type'] = $parsed_url[
'scheme'] ? $parsed_url[
'scheme'] :
'http';
553 if(count($request_config) && method_exists($oRequest,
'setConfig'))
555 foreach($request_config as $key=>$val)
557 if($key ===
'observers')
559 foreach($val as $observer)
561 $oRequest->attach($observer);
566 $oRequest->setConfig($key, $val);
570 if(method_exists($oRequest,
'setConfig'))
572 if(extension_loaded(
'curl'))
574 $oRequest->setConfig(
'adapter',
'curl');
576 elseif(version_compare(PHP_VERSION,
'5.6',
'<'))
578 $oRequest->setConfig(
'ssl_verify_host',
false);
580 if(file_exists(
_XE_PATH_ .
'libs/cacert/cacert.pem'))
582 $oRequest->setConfig(
'ssl_cafile',
_XE_PATH_ .
'libs/cacert/cacert.pem');
586 if(count($headers) > 0)
588 foreach($headers as $key => $val)
590 $oRequest->addHeader($key, $val);
593 $host = parse_url($url, PHP_URL_HOST);
596 foreach($cookies[$host] as $key => $val)
598 $oRequest->addCookie($key, $val);
601 if(count($post_data) > 0)
603 foreach($post_data as $key => $val)
605 $oRequest->addPostData($key, $val);
609 $oRequest->addHeader(
'Content-Type',
'text/html');
611 $oRequest->addHeader(
'Content-Type', $content_type);
612 $oRequest->setMethod($method);
614 $oRequest->setBody($body);
617 if(method_exists($oRequest,
'setConfig'))
619 $oRequest->setConfig(
'timeout', $timeout);
621 elseif(property_exists($oRequest,
'_timeout'))
623 $oRequest->_timeout = $timeout;
626 $oResponse = $oRequest->sendRequest();
628 $code = $oRequest->getResponseCode();
629 $header = $oRequest->getResponseHeader();
630 $response = $oRequest->getResponseBody();
631 if($c = $oRequest->getResponseCookies())
633 foreach($c as $k => $v)
635 $cookies[$host][$v[
'name']] = $v[
'value'];
639 if($code > 300 && $code < 399 && $header[
'location'])
641 return self::getRemoteResource($header[
'location'], $body, $timeout, $method, $content_type, $headers, $cookies, $post_data);
649 if(isset($request_config[
'store_body']) && !$request_config[
'store_body'])
676 function getRemoteFile($url, $target_filename, $body = null, $timeout = 3, $method =
'GET', $content_type = null, $headers = array(), $cookies = array(), $post_data = array(), $request_config = array())
678 $target_filename = self::getRealPath($target_filename);
679 self::writeFile($target_filename,
'');
682 require_once(
'HTTP/Request2/Observer/Download.php');
684 $request_config[
'store_body'] =
false;
688 $result = self::getRemoteResource($url, $body, $timeout, $method, $content_type, $headers, $cookies, $post_data, $request_config);
689 self::clearStatCache($target_filename);
690 self::invalidateOpcache($target_filename);
696 return $result ? TRUE : FALSE;
708 $unit = strtoupper(substr($val, -1));
713 case 'G': $val *= 1024;
714 case 'M': $val *= 1024;
715 case 'K': $val *= 1024;
729 $memoryLimit = self::returnBytes(ini_get(
'memory_limit'));
730 if($memoryLimit == -1)
737 $channels = $imageInfo[
'channels'];
743 $memoryNeeded = round(($imageInfo[0] * $imageInfo[1] * $imageInfo[
'bits'] * $channels / 8 + $K64 ) * $TWEAKFACTOR);
744 $availableMemory = self::returnBytes(ini_get(
'memory_limit')) - memory_get_usage();
745 if($availableMemory < $memoryNeeded)
765 function createImageFile($source_file, $target_file, $resize_width = 0, $resize_height = 0, $target_type =
'', $thumbnail_type =
'crop', $thumbnail_transparent = FALSE)
768 if (($source_file = self::exists($source_file)) === FALSE)
773 $target_file = self::getRealPath($target_file);
781 $resize_height = $resize_width;
785 $imageInfo = getimagesize($source_file);
786 if(!self::checkMemoryLoadImage($imageInfo))
791 list($width, $height, $type, $attrs) = $imageInfo;
792 if($width < 1 || $height < 1)
817 $target_type = $type;
819 $target_type = strtolower($target_type);
822 $width_per = ($resize_width > 0 && $width >= $resize_width) ? $resize_width / $width : 1;
823 $height_per = ($resize_height > 0 && $height >= $resize_height) ? $resize_height / $height : 1;
826 if($thumbnail_type ==
'ratio')
828 $per = ($width_per > $height_per) ? $height_per : $width_per;
829 $resize_width = $width * $per;
830 $resize_height = $height * $per;
834 $per = ($width_per < $height_per) ? $height_per : $width_per;
839 if(function_exists(
'imagecreateTRUEcolor'))
841 $thumb = imagecreateTRUEcolor($resize_width, $resize_height);
843 else if(function_exists(
'imagecreate'))
845 $thumb = imagecreate($resize_width, $resize_height);
853 if(function_exists(
'imagecolorallocatealpha') && $target_type ==
'png' && $thumbnail_transparent)
855 imagefill($thumb, 0, 0, imagecolorallocatealpha($thumb, 0, 0, 0, 127));
857 if(function_exists(
'imagesavealpha'))
859 imagesavealpha($thumb, TRUE);
862 if(function_exists(
'imagealphablending'))
864 imagealphablending($thumb, TRUE);
869 imagefilledrectangle($thumb, 0, 0, $resize_width - 1, $resize_height - 1, imagecolorallocate($thumb, 255, 255, 255));
877 if(function_exists(
'imagecreatefromgif'))
879 $source = @imagecreatefromgif($source_file);
884 if(function_exists(
'imagecreatefromjpeg'))
886 $source = @imagecreatefromjpeg($source_file);
890 if(function_exists(
'imagecreatefrompng'))
892 $source = @imagecreatefrompng($source_file);
897 if(function_exists(
'imagecreatefromwbmp'))
899 $source = @imagecreatefromwbmp($source_file);
906 imagedestroy($thumb);
911 $new_width = (int) ($width * $per);
912 $new_height = (int) ($height * $per);
916 if($thumbnail_type ==
'crop')
918 $x = (int) ($resize_width / 2 - $new_width / 2);
919 $y = (int) ($resize_height / 2 - $new_height / 2);
922 if(function_exists(
'imagecopyresampled'))
924 imagecopyresampled($thumb, $source, $x, $y, 0, 0, $new_width, $new_height, $width, $height);
928 imagecopyresized($thumb, $source, $x, $y, 0, 0, $new_width, $new_height, $width, $height);
932 self::makeDir(dirname($target_file));
939 if(function_exists(
'imagegif'))
941 $output = imagegif($thumb, $target_file);
946 if(function_exists(
'imagejpeg'))
948 $output = imagejpeg($thumb, $target_file, 100);
952 if(function_exists(
'imagepng'))
954 $output = imagepng($thumb, $target_file, 9);
959 if(function_exists(
'imagewbmp'))
961 $output = imagewbmp($thumb, $target_file, 100);
966 imagedestroy($thumb);
967 imagedestroy($source);
973 @chmod($target_file, 0644);
987 if(($filename = self::exists($filename)) === FALSE)
991 $arr = parse_ini_file($filename, TRUE);
992 if(is_array($arr) && count($arr) > 0)
1018 if(!is_array($arr) || count($arr) == 0)
1022 self::writeFile($filename, self::_makeIniBuff($arr));
1035 foreach($arr as $key => $val)
1040 $return[] = sprintf(
"[%s]", $key);
1041 foreach($val as $k => $v)
1043 $return[] = sprintf(
"%s=\"%s\"", $k, $v);
1047 else if(is_object($val))
1053 $return[] = sprintf(
"%s=\"%s\"", $key, $val);
1057 return join(
"\n", $return);
1071 $pathinfo = pathinfo($filename);
1072 self::makeDir($pathinfo[
'dirname']);
1074 require_once(
"FileObject.class.php");
1086 return (is_readable($filename) && (
filesize($filename) > 0));
1097 $filename = self::getRealPath($filename);
1098 return file_exists($filename) ? $filename : FALSE;
1109 $path = self::getRealPath($path);
1110 return is_dir($path) ? $path : FALSE;
1121 $path = self::getRealPath($path);
1122 if(is_dir($path)==FALSE)
1127 $checkFile = $path .
'/_CheckWritableDir';
1129 $fp = fopen($checkFile,
'w');
1130 if(!is_resource($fp))
1136 self::removeFile($checkFile);
1148 if(is_array($target))
1150 array_map(
'self::clearStatCache', $target);
1154 $target = self::getRealPath($target);
1156 if($include && self::isDir($target))
1158 self::clearStatCache(self::readDir($target,
'',
false,
true), $include);
1161 clearstatcache(
true, $target);
1172 static $opcache = null;
1174 if($opcache === null)
1176 $opcache = (function_exists(
'opcache_get_status') && function_exists(
'opcache_invalidate'));
1179 if($opcache ===
false)
1184 if(is_array($target))
1186 array_map(
'self::invalidateOpcache', $target);
1190 if(substr($target, -4) ===
'.php')
1192 opcache_invalidate(self::getRealPath($target), $force);
1194 else if($path = self::isDir($target))
1196 self::invalidateOpcache(self::readDir($path,
'',
false,
true));
checkMemoryLoadImage(&$imageInfo)
moveDir($source_dir, $target_dir)
writeFile($filename, $buff, $mode="w")
static invalidateOpcache($target, $force=true)
moveFile($source, $target)
getRemoteResource($url, $body=null, $timeout=3, $method= 'GET', $content_type=null, $headers=array(), $cookies=array(), $post_data=array(), $request_config=array())
getRemoteFile($url, $target_filename, $body=null, $timeout=3, $method= 'GET', $content_type=null, $headers=array(), $cookies=array(), $post_data=array(), $request_config=array())
writeIniFile($filename, $arr)
copyFile($source, $target, $force= 'Y')
copyDir($source_dir, $target_dir, $filter=null, $type=null)
createImageFile($source_file, $target_file, $resize_width=0, $resize_height=0, $target_type= '', $thumbnail_type= 'crop', $thumbnail_transparent=FALSE)
openFile($filename, $mode)
readDir($path, $filter= '', $to_lower=FALSE, $concat_prefix=FALSE)
static clearStatCache($target, $include=false)