mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-07 02:31:40 +09:00
issue 2622 coding convention in classes
git-svn-id: http://xe-core.googlecode.com/svn/branches/maserati@12218 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
1b2d64a4d7
commit
66e2363b43
6 changed files with 992 additions and 893 deletions
|
|
@ -5,25 +5,26 @@
|
|||
*
|
||||
* @class EditorHandler
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
**/
|
||||
|
||||
class EditorHandler extends Object {
|
||||
|
||||
*/
|
||||
class EditorHandler extends Object
|
||||
{
|
||||
/**
|
||||
* set the xml and other information of the component
|
||||
* @param object $info editor information
|
||||
* @return void
|
||||
**/
|
||||
function setInfo($info) {
|
||||
function setInfo($info)
|
||||
{
|
||||
Context::set('component_info', $info);
|
||||
|
||||
if(!$info->extra_vars) return;
|
||||
|
||||
foreach($info->extra_vars as $key => $val) {
|
||||
foreach($info->extra_vars as $key => $val)
|
||||
{
|
||||
$this->{$key} = trim($val->value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
/* End of file EditorHandler.class.php */
|
||||
/* Location: ./classes/editor/EditorHandler.class.php */
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@
|
|||
* A class to handle extra variables used in posts, member and others
|
||||
*
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
**/
|
||||
class ExtraVar {
|
||||
|
||||
*/
|
||||
class ExtraVar
|
||||
{
|
||||
/**
|
||||
* sequence of module
|
||||
* @var int
|
||||
|
|
@ -23,8 +23,9 @@
|
|||
*
|
||||
* @param int $module_srl Sequence of module
|
||||
* @return ExtraVar
|
||||
**/
|
||||
function &getInstance($module_srl) {
|
||||
*/
|
||||
function &getInstance($module_srl)
|
||||
{
|
||||
return new ExtraVar($module_srl);
|
||||
}
|
||||
|
||||
|
|
@ -33,8 +34,9 @@
|
|||
*
|
||||
* @param int $module_srl Sequence of module
|
||||
* @return void
|
||||
**/
|
||||
function ExtraVar($module_srl) {
|
||||
*/
|
||||
function ExtraVar($module_srl)
|
||||
{
|
||||
$this->module_srl = $module_srl;
|
||||
}
|
||||
|
||||
|
|
@ -43,10 +45,12 @@
|
|||
*
|
||||
* @param object[] $extra_keys Array of extra variable. A value of array is object that contains module_srl, idx, name, default, desc, is_required, search, value, eid.
|
||||
* @return void
|
||||
**/
|
||||
function setExtraVarKeys($extra_keys) {
|
||||
*/
|
||||
function setExtraVarKeys($extra_keys)
|
||||
{
|
||||
if(!is_array($extra_keys) || !count($extra_keys)) return;
|
||||
foreach($extra_keys as $key => $val) {
|
||||
foreach($extra_keys as $key => $val)
|
||||
{
|
||||
$obj = null;
|
||||
$obj = new ExtraItem($val->module_srl, $val->idx, $val->name, $val->type, $val->default, $val->desc, $val->is_required, $val->search, $val->value, $val->eid);
|
||||
$this->keys[$val->idx] = $obj;
|
||||
|
|
@ -57,8 +61,9 @@
|
|||
* Returns an array of ExtraItem
|
||||
*
|
||||
* @return ExtraItem[]
|
||||
**/
|
||||
function getExtraVars() {
|
||||
*/
|
||||
function getExtraVars()
|
||||
{
|
||||
return $this->keys;
|
||||
}
|
||||
}
|
||||
|
|
@ -67,8 +72,9 @@
|
|||
* Each value of the extra vars
|
||||
*
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
**/
|
||||
class ExtraItem {
|
||||
*/
|
||||
class ExtraItem
|
||||
{
|
||||
/**
|
||||
* Sequence of module
|
||||
* @var int
|
||||
|
|
@ -142,8 +148,9 @@
|
|||
* @param string $value Value
|
||||
* @param string $eid Unique id of extra variable in module
|
||||
* @return void
|
||||
**/
|
||||
function ExtraItem($module_srl, $idx, $name, $type = 'text', $default = null, $desc = '', $is_required = 'N', $search = 'N', $value = null, $eid = '') {
|
||||
*/
|
||||
function ExtraItem($module_srl, $idx, $name, $type = 'text', $default = null, $desc = '', $is_required = 'N', $search = 'N', $value = null, $eid = '')
|
||||
{
|
||||
if(!$idx) return;
|
||||
$this->module_srl = $module_srl;
|
||||
$this->idx = $idx;
|
||||
|
|
@ -162,8 +169,9 @@
|
|||
*
|
||||
* @param string $value The value to set
|
||||
* @return void
|
||||
**/
|
||||
function setValue($value) {
|
||||
*/
|
||||
function setValue($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
|
|
@ -173,11 +181,13 @@
|
|||
* @param string $type Type of variable
|
||||
* @param string $value Value
|
||||
* @return string Returns a converted value
|
||||
**/
|
||||
function _getTypeValue($type, $value) {
|
||||
*/
|
||||
function _getTypeValue($type, $value)
|
||||
{
|
||||
$value = trim($value);
|
||||
if(!isset($value)) return;
|
||||
switch($type) {
|
||||
switch($type)
|
||||
{
|
||||
case 'homepage' :
|
||||
if($value && !preg_match('/^([a-z]+):\/\//i',$value)) $value = 'http://'.$value;
|
||||
return htmlspecialchars($value);
|
||||
|
|
@ -223,10 +233,12 @@
|
|||
* Returns a value for HTML
|
||||
*
|
||||
* @return string Returns a value expressed in HTML.
|
||||
**/
|
||||
function getValueHTML() {
|
||||
*/
|
||||
function getValueHTML()
|
||||
{
|
||||
$value = $this->_getTypeValue($this->type, $this->value);
|
||||
switch($this->type) {
|
||||
switch($this->type)
|
||||
{
|
||||
case 'homepage' :
|
||||
return ($value)?(sprintf('<a href="%s" target="_blank">%s</a>', $value, strlen($value)>60?substr($value,0,40).'...'.substr($value,-10):$value)):"";
|
||||
case 'email_address' :
|
||||
|
|
@ -264,8 +276,9 @@
|
|||
* Returns a form based on its type
|
||||
*
|
||||
* @return string Returns a form html.
|
||||
**/
|
||||
function getFormHTML() {
|
||||
*/
|
||||
function getFormHTML()
|
||||
{
|
||||
static $id_num = 1000;
|
||||
|
||||
$type = $this->type;
|
||||
|
|
@ -276,7 +289,8 @@
|
|||
$tmp_id = $column_name.'-'.$id_num++;
|
||||
|
||||
$buff = '';
|
||||
switch($type) {
|
||||
switch($type)
|
||||
{
|
||||
// Homepage
|
||||
case 'homepage' :
|
||||
$buff .= '<input type="text" name="'.$column_name.'" value="'.$value.'" class="homepage" />';
|
||||
|
|
@ -292,7 +306,6 @@
|
|||
'<input type="text" name="'.$column_name.'[]" value="'.$value[1].'" size="4" maxlength="4" class="tel" />'.
|
||||
'<input type="text" name="'.$column_name.'[]" value="'.$value[2].'" size="4" maxlength="4" class="tel" />';
|
||||
break;
|
||||
|
||||
// textarea
|
||||
case 'textarea' :
|
||||
$buff .= '<textarea name="'.$column_name.'" rows="8" cols="42">'.$value.'</textarea>';
|
||||
|
|
@ -300,7 +313,8 @@
|
|||
// multiple choice
|
||||
case 'checkbox' :
|
||||
$buff .= '<ul>';
|
||||
foreach($default as $v) {
|
||||
foreach($default as $v)
|
||||
{
|
||||
if($value && in_array(trim($v), $value)) $checked = ' checked="checked"';
|
||||
else $checked = '';
|
||||
|
||||
|
|
@ -314,18 +328,19 @@
|
|||
// single choice
|
||||
case 'select' :
|
||||
$buff .= '<select name="'.$column_name.'" class="select">';
|
||||
foreach($default as $v) {
|
||||
foreach($default as $v)
|
||||
{
|
||||
if($value && in_array($v,$value)) $selected = ' selected="selected"';
|
||||
else $selected = '';
|
||||
$buff .= '<option value="'.$v.'" '.$selected.'>'.$v.'</option>';
|
||||
}
|
||||
$buff .= '</select>';
|
||||
break;
|
||||
|
||||
// radio
|
||||
case 'radio' :
|
||||
$buff .= '<ul>';
|
||||
foreach($default as $v) {
|
||||
foreach($default as $v)
|
||||
{
|
||||
if($value && in_array($v,$value)) $checked = ' checked="checked"';
|
||||
else $checked = '';
|
||||
|
||||
|
|
@ -394,4 +409,5 @@
|
|||
return $buff;
|
||||
}
|
||||
}
|
||||
?>
|
||||
/* End of file ExtraVar.class.php */
|
||||
/* Location: ./classes/extravar/ExtraVar.class.php */
|
||||
|
|
|
|||
|
|
@ -3,15 +3,17 @@
|
|||
* Contains methods for accessing file system
|
||||
*
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
**/
|
||||
class FileHandler {
|
||||
*/
|
||||
class FileHandler
|
||||
{
|
||||
/**
|
||||
* Changes path of target file, directory into absolute path
|
||||
*
|
||||
* @param string $source path to change into absolute path
|
||||
* @return string Absolute path
|
||||
**/
|
||||
function getRealPath($source) {
|
||||
*/
|
||||
function getRealPath($source)
|
||||
{
|
||||
$temp = explode('/', $source);
|
||||
if($temp[0] == '.') $source = _XE_PATH_.substr($source, 2);
|
||||
return $source;
|
||||
|
|
@ -27,8 +29,9 @@ class FileHandler {
|
|||
* @param string $filter Regex to filter files. If file matches this regex, the file is not copied.
|
||||
* @param string $type If set as 'force'. Even if the file exists in target, the file is copied.
|
||||
* @return void
|
||||
**/
|
||||
function copyDir($source_dir, $target_dir, $filter=null,$type=null){
|
||||
*/
|
||||
function copyDir($source_dir, $target_dir, $filter=null,$type=null)
|
||||
{
|
||||
$source_dir = FileHandler::getRealPath($source_dir);
|
||||
$target_dir = FileHandler::getRealPath($target_dir);
|
||||
if(!is_dir($source_dir)) return false;
|
||||
|
|
@ -39,15 +42,22 @@ class FileHandler {
|
|||
if(substr($target_dir, -1) != '/') $target_dir .= '/';
|
||||
|
||||
$oDir = dir($source_dir);
|
||||
while($file = $oDir->read()) {
|
||||
while($file = $oDir->read())
|
||||
{
|
||||
if(substr($file,0,1)=='.') continue;
|
||||
if($filter && preg_match($filter, $file)) continue;
|
||||
if(is_dir($source_dir.$file)){
|
||||
if(is_dir($source_dir.$file))
|
||||
{
|
||||
FileHandler::copyDir($source_dir.$file,$target_dir.$file,$type);
|
||||
}else{
|
||||
if($type == 'force'){
|
||||
}
|
||||
else
|
||||
{
|
||||
if($type == 'force')
|
||||
{
|
||||
@unlink($target_dir.$file);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!file_exists($target_dir.$file)) @copy($source_dir.$file,$target_dir.$file);
|
||||
}
|
||||
}
|
||||
|
|
@ -61,8 +71,9 @@ class FileHandler {
|
|||
* @param string $target Path of target file
|
||||
* @param string $force Y: overwrite
|
||||
* @return void
|
||||
**/
|
||||
function copyFile($source, $target, $force='Y'){
|
||||
*/
|
||||
function copyFile($source, $target, $force='Y')
|
||||
{
|
||||
setlocale(LC_CTYPE, 'en_US.UTF8', 'ko_KR.UTF8');
|
||||
$source = FileHandler::getRealPath($source);
|
||||
$target_dir = FileHandler::getRealPath(dirname($target));
|
||||
|
|
@ -77,8 +88,9 @@ class FileHandler {
|
|||
*
|
||||
* @param string $file_name Path of target file
|
||||
* @return string The content of the file. If target file does not exist, this function returns nothing.
|
||||
**/
|
||||
function readFile($file_name) {
|
||||
*/
|
||||
function readFile($file_name)
|
||||
{
|
||||
$file_name = FileHandler::getRealPath($file_name);
|
||||
|
||||
if(!file_exists($file_name)) return;
|
||||
|
|
@ -89,8 +101,10 @@ class FileHandler {
|
|||
|
||||
$fp = fopen($file_name, "r");
|
||||
$buff = '';
|
||||
if($fp) {
|
||||
while(!feof($fp) && strlen($buff)<=$filesize) {
|
||||
if($fp)
|
||||
{
|
||||
while(!feof($fp) && strlen($buff)<=$filesize)
|
||||
{
|
||||
$str = fgets($fp, 1024);
|
||||
$buff .= $str;
|
||||
}
|
||||
|
|
@ -106,8 +120,9 @@ class FileHandler {
|
|||
* @param string $buff Content to be writeen
|
||||
* @param string $mode a(append) / w(write)
|
||||
* @return void
|
||||
**/
|
||||
function writeFile($file_name, $buff, $mode = "w") {
|
||||
*/
|
||||
function writeFile($file_name, $buff, $mode = "w")
|
||||
{
|
||||
$file_name = FileHandler::getRealPath($file_name);
|
||||
|
||||
$pathinfo = pathinfo($file_name);
|
||||
|
|
@ -127,8 +142,9 @@ class FileHandler {
|
|||
*
|
||||
* @param string $file_name path of target file
|
||||
* @return bool Returns true on success or false on failure.
|
||||
**/
|
||||
function removeFile($file_name) {
|
||||
*/
|
||||
function removeFile($file_name)
|
||||
{
|
||||
$file_name = FileHandler::getRealPath($file_name);
|
||||
return (file_exists($file_name) && @unlink($file_name));
|
||||
}
|
||||
|
|
@ -141,8 +157,9 @@ class FileHandler {
|
|||
* @param string $source Path of source file
|
||||
* @param string $target Path of target file
|
||||
* @return bool Returns true on success or false on failure.
|
||||
**/
|
||||
function rename($source, $target) {
|
||||
*/
|
||||
function rename($source, $target)
|
||||
{
|
||||
$source = FileHandler::getRealPath($source);
|
||||
$target = FileHandler::getRealPath($target);
|
||||
return @rename($source, $target);
|
||||
|
|
@ -155,7 +172,8 @@ class FileHandler {
|
|||
* @param string $target Path of target file
|
||||
* @return bool Returns true on success or false on failure.
|
||||
*/
|
||||
function moveFile($source, $target) {
|
||||
function moveFile($source, $target)
|
||||
{
|
||||
$source = FileHandler::getRealPath($source);
|
||||
if(!file_exists($source))
|
||||
{
|
||||
|
|
@ -173,8 +191,9 @@ class FileHandler {
|
|||
* @param string $source_dir Path of source directory
|
||||
* @param string $target_dir Path of target directory
|
||||
* @return void
|
||||
**/
|
||||
function moveDir($source_dir, $target_dir) {
|
||||
*/
|
||||
function moveDir($source_dir, $target_dir)
|
||||
{
|
||||
FileHandler::rename($source_dir, $target_dir);
|
||||
}
|
||||
|
||||
|
|
@ -188,15 +207,17 @@ class FileHandler {
|
|||
* @param bool $to_lower If true, file names will be changed into lower case.
|
||||
* @param bool $concat_prefix If true, return file name as absolute path
|
||||
* @return string[] Array of the filenames in the path
|
||||
**/
|
||||
function readDir($path, $filter = '', $to_lower = false, $concat_prefix = false) {
|
||||
*/
|
||||
function readDir($path, $filter = '', $to_lower = false, $concat_prefix = false)
|
||||
{
|
||||
$path = FileHandler::getRealPath($path);
|
||||
|
||||
if(substr($path,-1)!='/') $path .= '/';
|
||||
if(!is_dir($path)) return array();
|
||||
|
||||
$oDir = dir($path);
|
||||
while($file = $oDir->read()) {
|
||||
while($file = $oDir->read())
|
||||
{
|
||||
if(substr($file,0,1)=='.') continue;
|
||||
|
||||
if($filter && !preg_match($filter, $file)) continue;
|
||||
|
|
@ -206,7 +227,8 @@ class FileHandler {
|
|||
if($filter) $file = preg_replace($filter, '$1', $file);
|
||||
else $file = $file;
|
||||
|
||||
if($concat_prefix) {
|
||||
if($concat_prefix)
|
||||
{
|
||||
$file = sprintf('%s%s', str_replace(_XE_PATH_, '', $path), $file);
|
||||
}
|
||||
|
||||
|
|
@ -224,14 +246,17 @@ class FileHandler {
|
|||
*
|
||||
* @param string $path_string Path of target directory
|
||||
* @return bool true if success. It might return nothing when ftp is used and connection to the ftp address failed.
|
||||
**/
|
||||
function makeDir($path_string) {
|
||||
*/
|
||||
function makeDir($path_string)
|
||||
{
|
||||
static $oFtp = null;
|
||||
|
||||
// if safe_mode is on, use FTP
|
||||
if(ini_get('safe_mode')) {
|
||||
if(ini_get('safe_mode'))
|
||||
{
|
||||
$ftp_info = Context::getFTPInfo();
|
||||
if($oFtp == null) {
|
||||
if($oFtp == null)
|
||||
{
|
||||
if(!Context::isFTPRegisted()) return;
|
||||
|
||||
require_once(_XE_PATH_.'libs/ftp.class.php');
|
||||
|
|
@ -239,7 +264,8 @@ class FileHandler {
|
|||
if(!$ftp_info->ftp_host) $ftp_info->ftp_host = "127.0.0.1";
|
||||
if(!$ftp_info->ftp_port) $ftp_info->ftp_port = 21;
|
||||
if(!$oFtp->ftp_connect($ftp_info->ftp_host, $ftp_info->ftp_port)) return;
|
||||
if(!$oFtp->ftp_login($ftp_info->ftp_user, $ftp_info->ftp_password)) {
|
||||
if(!$oFtp->ftp_login($ftp_info->ftp_user, $ftp_info->ftp_password))
|
||||
{
|
||||
$oFtp->ftp_quit();
|
||||
return;
|
||||
}
|
||||
|
|
@ -252,15 +278,20 @@ class FileHandler {
|
|||
$path_list = explode('/', $path_string);
|
||||
|
||||
$path = _XE_PATH_;
|
||||
for($i=0;$i<count($path_list);$i++) {
|
||||
for($i=0;$i<count($path_list);$i++)
|
||||
{
|
||||
if(!$path_list[$i]) continue;
|
||||
$path .= $path_list[$i].'/';
|
||||
$ftp_path .= $path_list[$i].'/';
|
||||
if(!is_dir($path)) {
|
||||
if(ini_get('safe_mode')) {
|
||||
if(!is_dir($path))
|
||||
{
|
||||
if(ini_get('safe_mode'))
|
||||
{
|
||||
$oFtp->ftp_mkdir($ftp_path);
|
||||
$oFtp->ftp_site("CHMOD 777 ".$ftp_path);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
@mkdir($path, 0755);
|
||||
@chmod($path, 0755);
|
||||
}
|
||||
|
|
@ -275,16 +306,22 @@ class FileHandler {
|
|||
*
|
||||
* @param string $path Path of the target directory
|
||||
* @return void
|
||||
**/
|
||||
function removeDir($path) {
|
||||
*/
|
||||
function removeDir($path)
|
||||
{
|
||||
$path = FileHandler::getRealPath($path);
|
||||
if(!is_dir($path)) return;
|
||||
$directory = dir($path);
|
||||
while($entry = $directory->read()) {
|
||||
if ($entry != "." && $entry != "..") {
|
||||
if (is_dir($path."/".$entry)) {
|
||||
while($entry = $directory->read())
|
||||
{
|
||||
if ($entry != "." && $entry != "..")
|
||||
{
|
||||
if (is_dir($path."/".$entry))
|
||||
{
|
||||
FileHandler::removeDir($path."/".$entry);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
@unlink($path."/".$entry);
|
||||
}
|
||||
}
|
||||
|
|
@ -298,14 +335,16 @@ class FileHandler {
|
|||
*
|
||||
* @param string $path Path of the target directory
|
||||
* @return void
|
||||
**/
|
||||
function removeBlankDir($path) {
|
||||
*/
|
||||
function removeBlankDir($path)
|
||||
{
|
||||
$item_cnt = 0;
|
||||
|
||||
$path = FileHandler::getRealPath($path);
|
||||
if(!is_dir($path)) return;
|
||||
$directory = dir($path);
|
||||
while($entry = $directory->read()) {
|
||||
while($entry = $directory->read())
|
||||
{
|
||||
if ($entry == "." || $entry == "..") continue;
|
||||
if (is_dir($path."/".$entry)) $item_cnt = FileHandler::removeBlankDir($path.'/'.$entry);
|
||||
}
|
||||
|
|
@ -322,16 +361,22 @@ class FileHandler {
|
|||
*
|
||||
* @param string $path Path of the target directory
|
||||
* @return void
|
||||
**/
|
||||
function removeFilesInDir($path) {
|
||||
*/
|
||||
function removeFilesInDir($path)
|
||||
{
|
||||
$path = FileHandler::getRealPath($path);
|
||||
if(!is_dir($path)) return;
|
||||
$directory = dir($path);
|
||||
while($entry = $directory->read()) {
|
||||
if ($entry != "." && $entry != "..") {
|
||||
if (is_dir($path."/".$entry)) {
|
||||
while($entry = $directory->read())
|
||||
{
|
||||
if ($entry != "." && $entry != "..")
|
||||
{
|
||||
if (is_dir($path."/".$entry))
|
||||
{
|
||||
FileHandler::removeFilesInDir($path."/".$entry);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
@unlink($path."/".$entry);
|
||||
}
|
||||
}
|
||||
|
|
@ -345,8 +390,9 @@ class FileHandler {
|
|||
* @see FileHandler::returnBytes()
|
||||
* @param int $size Number of the size
|
||||
* @return string File size string
|
||||
**/
|
||||
function filesize($size) {
|
||||
*/
|
||||
function filesize($size)
|
||||
{
|
||||
if(!$size) return '0Byte';
|
||||
if($size === 1) return '1Byte';
|
||||
if($size < 1024) return $size.'Bytes';
|
||||
|
|
@ -368,8 +414,9 @@ class FileHandler {
|
|||
* @param string[] $cookies Cookies key value array.
|
||||
* @param string $post_data Request arguments array for POST method
|
||||
* @return string If success, the content of the target file. Otherwise: none
|
||||
**/
|
||||
function getRemoteResource($url, $body = null, $timeout = 3, $method = 'GET', $content_type = null, $headers = array(), $cookies = array(), $post_data = array()) {
|
||||
*/
|
||||
function getRemoteResource($url, $body = null, $timeout = 3, $method = 'GET', $content_type = null, $headers = array(), $cookies = array(), $post_data = array())
|
||||
{
|
||||
if(version_compare(PHP_VERSION, '5.0.0', '>='))
|
||||
{
|
||||
return include _XE_PATH_ . 'classes/file/getRemoteResourcePHP5.php';
|
||||
|
|
@ -394,31 +441,41 @@ class FileHandler {
|
|||
* @param string[] $cookies Cookies key value array.
|
||||
* @param string $post_data Request arguments array for POST method
|
||||
* @return string If success, the content of the target file. Otherwise: none
|
||||
**/
|
||||
function _getRemoteResource($url, $body = null, $timeout = 3, $method = 'GET', $content_type = null, $headers = array(), $cookies = array(), $post_data = array()) {
|
||||
*/
|
||||
function _getRemoteResource($url, $body = null, $timeout = 3, $method = 'GET', $content_type = null, $headers = array(), $cookies = array(), $post_data = array())
|
||||
{
|
||||
requirePear();
|
||||
require_once('HTTP/Request.php');
|
||||
|
||||
$parsed_url = parse_url(__PROXY_SERVER__);
|
||||
if($parsed_url["host"]) {
|
||||
if($parsed_url["host"])
|
||||
{
|
||||
$oRequest = new HTTP_Request(__PROXY_SERVER__);
|
||||
$oRequest->setMethod('POST');
|
||||
$oRequest->_timeout = $timeout;
|
||||
$oRequest->addPostData('arg', serialize(array('Destination'=>$url, 'method'=>$method, 'body'=>$body, 'content_type'=>$content_type, "headers"=>$headers, "post_data"=>$post_data)));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
$oRequest = new HTTP_Request($url);
|
||||
if(count($headers)) {
|
||||
foreach($headers as $key => $val) {
|
||||
if(count($headers))
|
||||
{
|
||||
foreach($headers as $key => $val)
|
||||
{
|
||||
$oRequest->addHeader($key, $val);
|
||||
}
|
||||
}
|
||||
if($cookies[$host]) {
|
||||
foreach($cookies[$host] as $key => $val) {
|
||||
if($cookies[$host])
|
||||
{
|
||||
foreach($cookies[$host] as $key => $val)
|
||||
{
|
||||
$oRequest->addCookie($key, $val);
|
||||
}
|
||||
}
|
||||
if(count($post_data)) {
|
||||
foreach($post_data as $key => $val) {
|
||||
if(count($post_data))
|
||||
{
|
||||
foreach($post_data as $key => $val)
|
||||
{
|
||||
$oRequest->addPostData($key, $val);
|
||||
}
|
||||
}
|
||||
|
|
@ -435,13 +492,16 @@ class FileHandler {
|
|||
$code = $oRequest->getResponseCode();
|
||||
$header = $oRequest->getResponseHeader();
|
||||
$response = $oRequest->getResponseBody();
|
||||
if($c = $oRequest->getResponseCookies()) {
|
||||
foreach($c as $k => $v) {
|
||||
if($c = $oRequest->getResponseCookies())
|
||||
{
|
||||
foreach($c as $k => $v)
|
||||
{
|
||||
$cookies[$host][$v['name']] = $v['value'];
|
||||
}
|
||||
}
|
||||
|
||||
if($code > 300 && $code < 399 && $header['location']) {
|
||||
if($code > 300 && $code < 399 && $header['location'])
|
||||
{
|
||||
return FileHandler::getRemoteResource($header['location'], $body, $timeout, $method, $content_type, $headers, $cookies, $post_data);
|
||||
}
|
||||
|
||||
|
|
@ -461,8 +521,9 @@ class FileHandler {
|
|||
* @param string $content_type Content type header of HTTP request
|
||||
* @param string[] $headers Headers key vaule array.
|
||||
* @return bool true: success, false: failed
|
||||
**/
|
||||
function getRemoteFile($url, $target_filename, $body = null, $timeout = 3, $method = 'GET', $content_type = null, $headers = array()) {
|
||||
*/
|
||||
function getRemoteFile($url, $target_filename, $body = null, $timeout = 3, $method = 'GET', $content_type = null, $headers = array())
|
||||
{
|
||||
$body = FileHandler::getRemoteResource($url, $body, $timeout, $method, $content_type, $headers);
|
||||
if(!$body) return false;
|
||||
$target_filename = FileHandler::getRealPath($target_filename);
|
||||
|
|
@ -518,8 +579,9 @@ class FileHandler {
|
|||
* @param string $target_type If $target_type is set (gif, jpg, png, bmp), result image will be saved as target type
|
||||
* @param string $thumbnail_type Thumbnail type(crop, ratio)
|
||||
* @return bool true: success, false: failed
|
||||
**/
|
||||
function createImageFile($source_file, $target_file, $resize_width = 0, $resize_height = 0, $target_type = '', $thumbnail_type = 'crop') {
|
||||
*/
|
||||
function createImageFile($source_file, $target_file, $resize_width = 0, $resize_height = 0, $target_type = '', $thumbnail_type = 'crop')
|
||||
{
|
||||
$source_file = FileHandler::getRealPath($source_file);
|
||||
$target_file = FileHandler::getRealPath($target_file);
|
||||
|
||||
|
|
@ -534,7 +596,8 @@ class FileHandler {
|
|||
|
||||
if($width<1 || $height<1) return;
|
||||
|
||||
switch($type) {
|
||||
switch($type)
|
||||
{
|
||||
case '1' :
|
||||
$type = 'gif';
|
||||
break;
|
||||
|
|
@ -559,12 +622,15 @@ class FileHandler {
|
|||
if($resize_height>0 && $height >= $resize_height) $height_per = $resize_height / $height;
|
||||
else $height_per = 1;
|
||||
|
||||
if($thumbnail_type == 'ratio') {
|
||||
if($thumbnail_type == 'ratio')
|
||||
{
|
||||
if($width_per>$height_per) $per = $height_per;
|
||||
else $per = $width_per;
|
||||
$resize_width = $width * $per;
|
||||
$resize_height = $height * $per;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
if($width_per < $height_per) $per = $height_per;
|
||||
else $per = $width_per;
|
||||
}
|
||||
|
|
@ -585,7 +651,8 @@ class FileHandler {
|
|||
imagefilledrectangle($thumb,0,0,$resize_width-1,$resize_height-1,$white);
|
||||
|
||||
// create temporary image having original type
|
||||
switch($type) {
|
||||
switch($type)
|
||||
{
|
||||
case 'gif' :
|
||||
if(!function_exists('imagecreatefromgif')) return false;
|
||||
$source = @imagecreatefromgif($source_file);
|
||||
|
|
@ -615,25 +682,31 @@ class FileHandler {
|
|||
$new_width = (int)($width * $per);
|
||||
$new_height = (int)($height * $per);
|
||||
|
||||
if($thumbnail_type == 'crop') {
|
||||
if($thumbnail_type == 'crop')
|
||||
{
|
||||
$x = (int)($resize_width/2 - $new_width/2);
|
||||
$y = (int)($resize_height/2 - $new_height/2);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
$x = 0;
|
||||
$y = 0;
|
||||
}
|
||||
|
||||
if($source) {
|
||||
if($source)
|
||||
{
|
||||
if(function_exists('imagecopyresampled')) imagecopyresampled($thumb, $source, $x, $y, 0, 0, $new_width, $new_height, $width, $height);
|
||||
else imagecopyresized($thumb, $source, $x, $y, 0, 0, $new_width, $new_height, $width, $height);
|
||||
} else return false;
|
||||
}
|
||||
else return false;
|
||||
|
||||
// create directory
|
||||
$path = dirname($target_file);
|
||||
if(!is_dir($path)) FileHandler::makeDir($path);
|
||||
|
||||
// write into the file
|
||||
switch($target_type) {
|
||||
switch($target_type)
|
||||
{
|
||||
case 'gif' :
|
||||
if(!function_exists('imagegif')) return false;
|
||||
$output = imagegif($thumb, $target_file);
|
||||
|
|
@ -669,8 +742,9 @@ class FileHandler {
|
|||
* @see FileHandler::writeIniFile()
|
||||
* @param string $filename Path of the ini file
|
||||
* @return array ini array (if the target file does not exist, it returns false)
|
||||
**/
|
||||
function readIniFile($filename){
|
||||
*/
|
||||
function readIniFile($filename)
|
||||
{
|
||||
$filename = FileHandler::getRealPath($filename);
|
||||
if(!file_exists($filename)) return false;
|
||||
$arr = parse_ini_file($filename, true);
|
||||
|
|
@ -678,7 +752,6 @@ class FileHandler {
|
|||
else return array();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Write array into ini file
|
||||
*
|
||||
|
|
@ -692,8 +765,9 @@ class FileHandler {
|
|||
* @param string $filename Target ini file name
|
||||
* @param array $arr Array
|
||||
* @return bool if array contains nothing it returns false, otherwise true
|
||||
**/
|
||||
function writeIniFile($filename, $arr){
|
||||
*/
|
||||
function writeIniFile($filename, $arr)
|
||||
{
|
||||
if(count($arr)==0) return false;
|
||||
FileHandler::writeFile($filename, FileHandler::_makeIniBuff($arr));
|
||||
return true;
|
||||
|
|
@ -705,17 +779,23 @@ class FileHandler {
|
|||
* @param array $arr Array
|
||||
* @return string
|
||||
*/
|
||||
function _makeIniBuff($arr){
|
||||
function _makeIniBuff($arr)
|
||||
{
|
||||
$return = '';
|
||||
foreach($arr as $key => $val){
|
||||
foreach($arr as $key => $val)
|
||||
{
|
||||
// section
|
||||
if(is_array($val)){
|
||||
if(is_array($val))
|
||||
{
|
||||
$return .= sprintf("[%s]\n",$key);
|
||||
foreach($val as $k => $v){
|
||||
foreach($val as $k => $v)
|
||||
{
|
||||
$return .= sprintf("%s=\"%s\"\n",$k,$v);
|
||||
}
|
||||
// value
|
||||
}else if(is_string($val) || is_int($val)){
|
||||
}
|
||||
else if(is_string($val) || is_int($val))
|
||||
{
|
||||
$return .= sprintf("%s=\"%s\"\n",$key,$val);
|
||||
}
|
||||
}
|
||||
|
|
@ -730,7 +810,7 @@ class FileHandler {
|
|||
* @param string $filename Target file name
|
||||
* @param string $mode File mode for fopen
|
||||
* @return FileObject File object
|
||||
**/
|
||||
*/
|
||||
function openFile($filename, $mode)
|
||||
{
|
||||
$pathinfo = pathinfo($filename);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
* File abstraction class
|
||||
*
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
**/
|
||||
*/
|
||||
class FileObject extends Object
|
||||
{
|
||||
/**
|
||||
|
|
@ -30,7 +30,7 @@ class FileObject extends Object
|
|||
* @param string $path Path of target file
|
||||
* @param string $mode File open mode
|
||||
* @return void
|
||||
**/
|
||||
*/
|
||||
function FileObject($path, $mode)
|
||||
{
|
||||
if($path != null) $this->Open($path, $mode);
|
||||
|
|
@ -41,7 +41,7 @@ class FileObject extends Object
|
|||
*
|
||||
* @param string $file_name Path of target file
|
||||
* @return void
|
||||
**/
|
||||
*/
|
||||
function append($file_name)
|
||||
{
|
||||
$target = new FileObject($file_name, "r");
|
||||
|
|
@ -57,7 +57,7 @@ class FileObject extends Object
|
|||
* Check current file meets eof
|
||||
*
|
||||
* @return bool true: if eof. false: otherwise
|
||||
**/
|
||||
*/
|
||||
function feof()
|
||||
{
|
||||
return feof($this->fp);
|
||||
|
|
@ -68,7 +68,7 @@ class FileObject extends Object
|
|||
*
|
||||
* @param int $size Size to read
|
||||
* @return string Returns the read string or false on failure.
|
||||
**/
|
||||
*/
|
||||
function read($size = 1024)
|
||||
{
|
||||
return fread($this->fp, $size);
|
||||
|
|
@ -80,7 +80,7 @@ class FileObject extends Object
|
|||
*
|
||||
* @param string $str String to write
|
||||
* @return int Returns the number of bytes written, or false on error.
|
||||
**/
|
||||
*/
|
||||
function write($str)
|
||||
{
|
||||
$len = strlen($str);
|
||||
|
|
@ -119,7 +119,7 @@ class FileObject extends Object
|
|||
* Return current file's path
|
||||
*
|
||||
* @return string Returns the path of current file.
|
||||
**/
|
||||
*/
|
||||
function getPath()
|
||||
{
|
||||
if($this->fp != null)
|
||||
|
|
@ -136,7 +136,7 @@ class FileObject extends Object
|
|||
* Close file
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
*/
|
||||
function close()
|
||||
{
|
||||
if($this->fp != null)
|
||||
|
|
|
|||
|
|
@ -7,3 +7,5 @@ catch(Exception $e)
|
|||
{
|
||||
return NULL;
|
||||
}
|
||||
/* End of file getRemoteResourcePHP5.php */
|
||||
/* Location: ./classes/file/getRemoteResourcePHP5.php */
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* Handle front end files
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
**/
|
||||
*/
|
||||
class FrontEndFileHandler extends Handler
|
||||
{
|
||||
/**
|
||||
|
|
@ -91,7 +91,7 @@
|
|||
* @param string $cdnPrefix CDN url prefix. (http://static.xpressengine.com/core/)
|
||||
* @param string $cdnVersion CDN version string (ardent1)
|
||||
* @return void
|
||||
**/
|
||||
*/
|
||||
function loadFile($args, $useCdn = false, $cdnPrefix = '', $cdnVersion = '')
|
||||
{
|
||||
if (!is_array($args)) $args = array($args);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue