diff --git a/classes/editor/EditorHandler.class.php b/classes/editor/EditorHandler.class.php index f484ccbf5..0920ccd2c 100644 --- a/classes/editor/EditorHandler.class.php +++ b/classes/editor/EditorHandler.class.php @@ -1,4 +1,5 @@ extra_vars) return; + if(!$info->extra_vars) + { + return; + } foreach($info->extra_vars as $key => $val) { diff --git a/classes/extravar/Extravar.class.php b/classes/extravar/Extravar.class.php index 8e1491ee3..8e5a1cdf8 100644 --- a/classes/extravar/Extravar.class.php +++ b/classes/extravar/Extravar.class.php @@ -1,4 +1,5 @@ $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); + $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; } } @@ -66,6 +72,7 @@ class ExtraVar { return $this->keys; } + } /** @@ -75,6 +82,7 @@ class ExtraVar */ class ExtraItem { + /** * Sequence of module * @var int @@ -151,7 +159,11 @@ class ExtraItem */ function ExtraItem($module_srl, $idx, $name, $type = 'text', $default = null, $desc = '', $is_required = 'N', $search = 'N', $value = null, $eid = '') { - if(!$idx) return; + if(!$idx) + { + return; + } + $this->module_srl = $module_srl; $this->idx = $idx; $this->name = $name; @@ -185,47 +197,92 @@ class ExtraItem function _getTypeValue($type, $value) { $value = trim($value); - if(!isset($value)) return; + if(!isset($value)) + { + return; + } + switch($type) { case 'homepage' : - if($value && !preg_match('/^([a-z]+):\/\//i',$value)) $value = 'http://'.$value; + if($value && !preg_match('/^([a-z]+):\/\//i', $value)) + { + $value = 'http://' . $value; + } return htmlspecialchars($value); - break; + case 'tel' : - if(is_array($value)) $values = $value; - elseif(strpos($value,'|@|')!==false) $values = explode('|@|', $value); - elseif(strpos($value,',')!==false) $values = explode(',', $value); + if(is_array($value)) + { + $values = $value; + } + elseif(strpos($value, '|@|') !== FALSE) + { + $values = explode('|@|', $value); + } + elseif(strpos($value, ',') !== FALSE) + { + $values = explode(',', $value); + } + $values[0] = $values[0]; $values[1] = $values[1]; $values[2] = $values[2]; return $values; - break; - break; + case 'checkbox' : case 'radio' : case 'select' : - if(is_array($value)) $values = $value; - elseif(strpos($value,'|@|')!==false) $values = explode('|@|', $value); - elseif(strpos($value,',')!==false) $values = explode(',', $value); - else $values = array($value); - for($i=0;$i_getTypeValue($this->type, $this->value); + switch($this->type) { case 'homepage' : - return ($value)?(sprintf('%s', $value, strlen($value)>60?substr($value,0,40).'...'.substr($value,-10):$value)):""; + return ($value) ? (sprintf('%s', $value, strlen($value) > 60 ? substr($value, 0, 40) . '...' . substr($value, -10) : $value)) : ""; + case 'email_address' : - return ($value)?sprintf('%s', $value, $value):""; - break; + return ($value) ? sprintf('%s', $value, $value) : ""; + case 'tel' : - return sprintf('%s - %s - %s', $value[0],$value[1],$value[2]); - break; + return sprintf('%s - %s - %s', $value[0], $value[1], $value[2]); + case 'textarea' : return nl2br($value); - break; + case 'checkbox' : - if(is_array($value)) return implode(', ',$value); - else return $value; - break; + if(is_array($value)) + { + return implode(', ', $value); + } + else + { + return $value; + } + case 'date' : - return zdate($value,"Y-m-d"); - break; + return zdate($value, "Y-m-d"); + case 'select' : case 'radio' : - if(is_array($value)) return implode(', ',$value); - else return $value; - break; + if(is_array($value)) + { + return implode(', ', $value); + } + else + { + return $value; + } + case 'kr_zip' : - if(is_array($value)) return implode(' ',$value); - else return $value; - break; + if(is_array($value)) + { + return implode(' ', $value); + } + else + { + return $value; + } + // case 'text' : default : return $value; @@ -285,54 +362,66 @@ class ExtraItem $name = $this->name; $value = $this->_getTypeValue($this->type, $this->value); $default = $this->_getTypeValue($this->type, $this->default); - $column_name = 'extra_vars'.$this->idx; - $tmp_id = $column_name.'-'.$id_num++; + $column_name = 'extra_vars' . $this->idx; + $tmp_id = $column_name . '-' . $id_num++; $buff = ''; switch($type) { // Homepage case 'homepage' : - $buff .= ''; + $buff .= ''; break; // Email Address case 'email_address' : - $buff .= ''; + $buff .= ''; break; // Phone Number case 'tel' : $buff .= - ''. - ''. - ''; + '' . + '' . + ''; break; // textarea case 'textarea' : - $buff .= ''; + $buff .= ''; break; // multiple choice case 'checkbox' : $buff .= ''; break; // single choice case 'select' : - $buff .= ''; foreach($default as $v) { - if($value && in_array(trim($v),$value)) $selected = ' selected="selected"'; - else $selected = ''; - $buff .= ''; + if($value && in_array(trim($v), $value)) + { + $selected = ' selected="selected"'; + } + else + { + $selected = ''; + } + $buff .= ''; } $buff .= ''; break; @@ -341,13 +430,19 @@ class ExtraItem $buff .= ''; break; @@ -357,23 +452,23 @@ class ExtraItem Context::loadJavascriptPlugin('ui.datepicker'); $buff .= - ''. - ' '."\n". - ''; + '' . + ' ' . "\n" . + ''; break; // address case "kr_zip" : @@ -381,33 +476,35 @@ class ExtraItem Context::loadJavascriptPlugin('ui.krzip'); $buff .= - '
'. - ''. - ''.Context::getLang('cmd_cancel').''. - '
'. - - ''. - - '
'. - ''. - ''.Context::getLang('cmd_search').''. - '
'. - - ''. - ''; + '
' . + '' . + '' . Context::getLang('cmd_cancel') . '' . + '
' . + '' . + '
' . + '' . + '' . Context::getLang('cmd_search') . '' . + '
' . + '' . + ''; break; // General text default : - $buff .=' '; + $buff .=' '; break; } - if($this->desc) $buff .= '

'.$this->desc.'

'; + if($this->desc) + { + $buff .= '

' . $this->desc . '

'; + } + return $buff; } + } /* End of file ExtraVar.class.php */ /* Location: ./classes/extravar/ExtraVar.class.php */ diff --git a/classes/file/FileHandler.class.php b/classes/file/FileHandler.class.php index cc3e6784d..bca876e0b 100644 --- a/classes/file/FileHandler.class.php +++ b/classes/file/FileHandler.class.php @@ -1,4 +1,5 @@ read()) { - if(substr($file,0,1)=='.') continue; - if($filter && preg_match($filter, $file)) continue; - if(is_dir($source_dir.$file)) + if(substr($file, 0, 1) == '.') { - FileHandler::copyDir($source_dir.$file,$target_dir.$file,$type); + continue; + } + + if($filter && preg_match($filter, $file)) + { + continue; + } + + if(is_dir($source_dir . $file)) + { + FileHandler::copyDir($source_dir . $file, $target_dir . $file, $type); } else { if($type == 'force') { - @unlink($target_dir.$file); + @unlink($target_dir . $file); } else { - if(!file_exists($target_dir.$file)) @copy($source_dir.$file,$target_dir.$file); + if(!file_exists($target_dir . $file)) + { + @copy($source_dir . $file, $target_dir . $file); + } } } } @@ -72,15 +102,24 @@ class FileHandler * @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'); + setlocale(LC_CTYPE, 'en_US.UTF8', 'ko_KR.UTF8'); $source = FileHandler::getRealPath($source); $target_dir = FileHandler::getRealPath(dirname($target)); $target = basename($target); - if(!file_exists($target_dir)) FileHandler::makeDir($target_dir); - if($force=='Y') @unlink($target_dir.'/'.$target); - @copy($source, $target_dir.'/'.$target); + + if(!file_exists($target_dir)) + { + FileHandler::makeDir($target_dir); + } + + if($force == 'Y') + { + @unlink($target_dir . '/' . $target); + } + + @copy($source, $target_dir . '/' . $target); } /** @@ -93,24 +132,18 @@ class FileHandler { $file_name = FileHandler::getRealPath($file_name); - if(!file_exists($file_name)) return; - $filesize = filesize($file_name); - if($filesize<1) return; - - if(function_exists('file_get_contents')) return @file_get_contents($file_name); - - $fp = fopen($file_name, "r"); - $buff = ''; - if($fp) + if(!file_exists($file_name)) { - while(!feof($fp) && strlen($buff)<=$filesize) - { - $str = fgets($fp, 1024); - $buff .= $str; - } - fclose($fp); + return; } - return $buff; + + $filesize = filesize($file_name); + if($filesize < 1) + { + return; + } + + return @file_get_contents($file_name); } /** @@ -127,13 +160,22 @@ class FileHandler $pathinfo = pathinfo($file_name); $path = $pathinfo['dirname']; - if(!is_dir($path)) FileHandler::makeDir($path); + if(!is_dir($path)) + { + FileHandler::makeDir($path); + } $mode = strtolower($mode); - if($mode != "a") $mode = "w"; - if(@!$fp = fopen($file_name,$mode)) return false; - fwrite($fp, $buff); - fclose($fp); + if($mode == 'a') + { + $flags = FILE_APPEND; + } + else + { + $flags = 0; + } + + @file_put_contents($file_name, $buff, $flags); @chmod($file_name, 0644); } @@ -212,20 +254,42 @@ class FileHandler { $path = FileHandler::getRealPath($path); - if(substr($path,-1)!='/') $path .= '/'; - if(!is_dir($path)) return array(); + if(substr($path, -1) != '/') + { + $path .= '/'; + } + + if(!is_dir($path)) + { + return array(); + } $oDir = dir($path); while($file = $oDir->read()) { - if(substr($file,0,1)=='.') continue; + if(substr($file, 0, 1) == '.') + { + continue; + } - if($filter && !preg_match($filter, $file)) continue; + if($filter && !preg_match($filter, $file)) + { + continue; + } - if($to_lower) $file = strtolower($file); + if($to_lower) + { + $file = strtolower($file); + } - if($filter) $file = preg_replace($filter, '$1', $file); - else $file = $file; + if($filter) + { + $file = preg_replace($filter, '$1', $file); + } + else + { + $file = $file; + } if($concat_prefix) { @@ -234,7 +298,11 @@ class FileHandler $output[] = $file; } - if(!$output) return array(); + + if(!$output) + { + return array(); + } return $output; } @@ -257,13 +325,25 @@ class FileHandler $ftp_info = Context::getFTPInfo(); if($oFtp == null) { - if(!Context::isFTPRegisted()) return; + if(!Context::isFTPRegisted()) + { + return; + } - require_once(_XE_PATH_.'libs/ftp.class.php'); + require_once(_XE_PATH_ . 'libs/ftp.class.php'); $oFtp = new ftp(); - 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(!$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)) { $oFtp->ftp_quit(); @@ -271,24 +351,31 @@ class FileHandler } } $ftp_path = $ftp_info->ftp_root_path; - if(!$ftp_path) $ftp_path = "/"; + if(!$ftp_path) + { + $ftp_path = "/"; + } } - $path_string = str_replace(_XE_PATH_,'',$path_string); + $path_string = str_replace(_XE_PATH_, '', $path_string); $path_list = explode('/', $path_string); $path = _XE_PATH_; - for($i=0;$iftp_mkdir($ftp_path); - $oFtp->ftp_site("CHMOD 777 ".$ftp_path); + $oFtp->ftp_site("CHMOD 777 " . $ftp_path); } else { @@ -310,19 +397,23 @@ class FileHandler function removeDir($path) { $path = FileHandler::getRealPath($path); - if(!is_dir($path)) return; + if(!is_dir($path)) + { + return; + } + $directory = dir($path); while($entry = $directory->read()) { - if ($entry != "." && $entry != "..") + if($entry != "." && $entry != "..") { - if (is_dir($path."/".$entry)) + if(is_dir($path . "/" . $entry)) { - FileHandler::removeDir($path."/".$entry); + FileHandler::removeDir($path . "/" . $entry); } else { - @unlink($path."/".$entry); + @unlink($path . "/" . $entry); } } } @@ -341,19 +432,31 @@ class FileHandler $item_cnt = 0; $path = FileHandler::getRealPath($path); - if(!is_dir($path)) return; + if(!is_dir($path)) + { + return; + } + $directory = dir($path); while($entry = $directory->read()) { - if ($entry == "." || $entry == "..") continue; - if (is_dir($path."/".$entry)) $item_cnt = FileHandler::removeBlankDir($path.'/'.$entry); + if($entry == "." || $entry == "..") + { + continue; + } + if(is_dir($path . "/" . $entry)) + { + $item_cnt = FileHandler::removeBlankDir($path . '/' . $entry); + } } $directory->close(); - if($item_cnt < 1) @rmdir($path); + if($item_cnt < 1) + { + @rmdir($path); + } } - /** * Remove files in the target directory * @@ -365,19 +468,23 @@ class FileHandler function removeFilesInDir($path) { $path = FileHandler::getRealPath($path); - if(!is_dir($path)) return; + if(!is_dir($path)) + { + return; + } + $directory = dir($path); while($entry = $directory->read()) { - if ($entry != "." && $entry != "..") + if($entry != "." && $entry != "..") { - if (is_dir($path."/".$entry)) + if(is_dir($path . "/" . $entry)) { - FileHandler::removeFilesInDir($path."/".$entry); + FileHandler::removeFilesInDir($path . "/" . $entry); } else { - @unlink($path."/".$entry); + @unlink($path . "/" . $entry); } } } @@ -393,11 +500,27 @@ class FileHandler */ function filesize($size) { - if(!$size) return '0Byte'; - if($size === 1) return '1Byte'; - if($size < 1024) return $size.'Bytes'; - if($size >= 1024 && $size < 1024*1024) return sprintf("%0.1fKB",$size / 1024); - return sprintf("%0.2fMB",$size / (1024*1024)); + if(!$size) + { + return '0Byte'; + } + + if($size === 1) + { + return '1Byte'; + } + + if($size < 1024) + { + return $size . 'Bytes'; + } + + if($size >= 1024 && $size < 1024 * 1024) + { + return sprintf("%0.1fKB", $size / 1024); + } + + return sprintf("%0.2fMB", $size / (1024 * 1024)); } /** @@ -417,97 +540,81 @@ class FileHandler */ 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', '>=')) + try { - return include _XE_PATH_ . 'classes/file/getRemoteResourcePHP5.php'; - } - else - { - return FileHandler::_getRemoteResource($url, $boyd, $timeout, $mehtod, $conent_type, $headers, $cookies, $post_data); - } - } + requirePear(); + require_once('HTTP/Request.php'); - /** - * Return remote file's content via HTTP - * - * If the target is moved (when return code is 300~399), this function follows the location specified response header. - * - * @param string $url The address of the target file - * @param string $body HTTP request body - * @param int $timeout Connection timeout - * @param string $method GET/POST - * @param string $content_type Content type header of HTTP request - * @param string[] $headers Headers key vaule array. - * @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()) - { - requirePear(); - require_once('HTTP/Request.php'); - - $parsed_url = parse_url(__PROXY_SERVER__); - 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 - { - $oRequest = new HTTP_Request($url); - if(count($headers)) + $parsed_url = parse_url(__PROXY_SERVER__); + if($parsed_url["host"]) { - foreach($headers as $key => $val) + $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 + { + $oRequest = new HTTP_Request($url); + if(count($headers)) { - $oRequest->addHeader($key, $val); + foreach($headers as $key => $val) + { + $oRequest->addHeader($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) + { + $oRequest->addPostData($key, $val); + } + } + if(!$content_type) + $oRequest->addHeader('Content-Type', 'text/html'); + else + $oRequest->addHeader('Content-Type', $content_type); + $oRequest->setMethod($method); + if($body) + $oRequest->setBody($body); + + $oRequest->_timeout = $timeout; + } + + $oResponse = $oRequest->sendRequest(); + + $code = $oRequest->getResponseCode(); + $header = $oRequest->getResponseHeader(); + $response = $oRequest->getResponseBody(); + if($c = $oRequest->getResponseCookies()) + { + foreach($c as $k => $v) + { + $cookies[$host][$v['name']] = $v['value']; } } - if($cookies[$host]) - { - foreach($cookies[$host] as $key => $val) - { - $oRequest->addCookie($key, $val); - } - } - if(count($post_data)) - { - foreach($post_data as $key => $val) - { - $oRequest->addPostData($key, $val); - } - } - if(!$content_type) $oRequest->addHeader('Content-Type', 'text/html'); - else $oRequest->addHeader('Content-Type', $content_type); - $oRequest->setMethod($method); - if($body) $oRequest->setBody($body); - $oRequest->_timeout = $timeout; + if($code > 300 && $code < 399 && $header['location']) + { + return FileHandler::getRemoteResource($header['location'], $body, $timeout, $method, $content_type, $headers, $cookies, $post_data); + } + + if($code != 200) + return; + + return $response; } - - $oResponse = $oRequest->sendRequest(); - - $code = $oRequest->getResponseCode(); - $header = $oRequest->getResponseHeader(); - $response = $oRequest->getResponseBody(); - if($c = $oRequest->getResponseCookies()) + catch(Exception $e) { - foreach($c as $k => $v) - { - $cookies[$host][$v['name']] = $v['value']; - } + return NULL; } - - if($code > 300 && $code < 399 && $header['location']) - { - return FileHandler::getRemoteResource($header['location'], $body, $timeout, $method, $content_type, $headers, $cookies, $post_data); - } - - if($code != 200) return; - - return $response; } /** @@ -525,10 +632,13 @@ class FileHandler 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; + if(!$body) + { + return FALSE; + } $target_filename = FileHandler::getRealPath($target_filename); FileHandler::writeFile($target_filename, $body); - return true; + return TRUE; } /** @@ -542,10 +652,22 @@ class FileHandler { $val = trim($val); $last = strtolower(substr($val, -1)); - if($last == 'g') $val *= 1024*1024*1024; - else if($last == 'm') $val *= 1024*1024; - else if($last == 'k') $val *= 1024; - else $val *= 1; + if($last == 'g') + { + $val *= 1024 * 1024 * 1024; + } + else if($last == 'm') + { + $val *= 1024 * 1024; + } + else if($last == 'k') + { + $val *= 1024; + } + else + { + $val *= 1; + } return $val; } @@ -558,15 +680,25 @@ class FileHandler */ function checkMemoryLoadImage(&$imageInfo) { - if(!function_exists('memory_get_usage')) return true; + if(!function_exists('memory_get_usage')) + { + return TRUE; + } + $K64 = 65536; $TWEAKFACTOR = 2.0; $channels = $imageInfo['channels']; - if(!$channels) $channels = 6; //for png - $memoryNeeded = round( ($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $channels / 8 + $K64 ) * $TWEAKFACTOR ); + if(!$channels) + { + $channels = 6; //for png + } + $memoryNeeded = round(($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $channels / 8 + $K64 ) * $TWEAKFACTOR); $availableMemory = FileHandler::returnBytes(ini_get('memory_limit')) - memory_get_usage(); - if($availableMemory < $memoryNeeded) return false; - return true; + if($availableMemory < $memoryNeeded) + { + return FALSE; + } + return TRUE; } /** @@ -585,16 +717,31 @@ class FileHandler $source_file = FileHandler::getRealPath($source_file); $target_file = FileHandler::getRealPath($target_file); - if(!file_exists($source_file)) return; - if(!$resize_width) $resize_width = 100; - if(!$resize_height) $resize_height = $resize_width; + if(!file_exists($source_file)) + { + return; + } + if(!$resize_width) + { + $resize_width = 100; + } + if(!$resize_height) + { + $resize_height = $resize_width; + } // retrieve source image's information $imageInfo = getimagesize($source_file); - if(!FileHandler::checkMemoryLoadImage($imageInfo)) return false; + if(!FileHandler::checkMemoryLoadImage($imageInfo)) + { + return FALSE; + } list($width, $height, $type, $attrs) = $imageInfo; - if($width<1 || $height<1) return; + if($width < 1 || $height < 1) + { + return; + } switch($type) { @@ -616,62 +763,116 @@ class FileHandler } // if original image is larger than specified size to resize, calculate the ratio - if($resize_width > 0 && $width >= $resize_width) $width_per = $resize_width / $width; - else $width_per = 1; + if($resize_width > 0 && $width >= $resize_width) + { + $width_per = $resize_width / $width; + } + else + { + $width_per = 1; + } - if($resize_height>0 && $height >= $resize_height) $height_per = $resize_height / $height; - else $height_per = 1; + if($resize_height > 0 && $height >= $resize_height) + { + $height_per = $resize_height / $height; + } + else + { + $height_per = 1; + } if($thumbnail_type == 'ratio') { - if($width_per>$height_per) $per = $height_per; - else $per = $width_per; + if($width_per > $height_per) + { + $per = $height_per; + } + else + { + $per = $width_per; + } $resize_width = $width * $per; $resize_height = $height * $per; } else { - if($width_per < $height_per) $per = $height_per; - else $per = $width_per; + if($width_per < $height_per) + { + $per = $height_per; + } + else + { + $per = $width_per; + } } - if(!$per) $per = 1; + if(!$per) + { + $per = 1; + } // get type of target file - if(!$target_type) $target_type = $type; + if(!$target_type) + { + $target_type = $type; + } $target_type = strtolower($target_type); // create temporary image with target size - if(function_exists('imagecreatetruecolor')) $thumb = imagecreatetruecolor($resize_width, $resize_height); - else if(function_exists('imagecreate')) $thumb = imagecreate($resize_width, $resize_height); - else return false; - if(!$thumb) return false; + if(function_exists('imagecreatetruecolor')) + { + $thumb = imagecreatetruecolor($resize_width, $resize_height); + } + else if(function_exists('imagecreate')) + { + $thumb = imagecreate($resize_width, $resize_height); + } + else + { + return FALSE; + } + if(!$thumb) + { + return FALSE; + } - $white = imagecolorallocate($thumb, 255,255,255); - imagefilledrectangle($thumb,0,0,$resize_width-1,$resize_height-1,$white); + $white = imagecolorallocate($thumb, 255, 255, 255); + imagefilledrectangle($thumb, 0, 0, $resize_width - 1, $resize_height - 1, $white); // create temporary image having original type switch($type) { case 'gif' : - if(!function_exists('imagecreatefromgif')) return false; + if(!function_exists('imagecreatefromgif')) + { + return FALSE; + } $source = @imagecreatefromgif($source_file); break; - // jpg + // jpg case 'jpeg' : case 'jpg' : - if(!function_exists('imagecreatefromjpeg')) return false; + if(!function_exists('imagecreatefromjpeg')) + { + return FALSE; + } $source = @imagecreatefromjpeg($source_file); break; - // png + // png case 'png' : - if(!function_exists('imagecreatefrompng')) return false; + if(!function_exists('imagecreatefrompng')) + { + return FALSE; + } $source = @imagecreatefrompng($source_file); break; - // bmp + // bmp case 'wbmp' : case 'bmp' : - if(!function_exists('imagecreatefromwbmp')) return false; + if(!function_exists('imagecreatefromwbmp')) + { + return FALSE; + } $source = @imagecreatefromwbmp($source_file); break; default : @@ -679,13 +880,13 @@ class FileHandler } // resize original image and put it into temporary image - $new_width = (int)($width * $per); - $new_height = (int)($height * $per); + $new_width = (int) ($width * $per); + $new_height = (int) ($height * $per); if($thumbnail_type == 'crop') { - $x = (int)($resize_width/2 - $new_width/2); - $y = (int)($resize_height/2 - $new_height/2); + $x = (int) ($resize_width / 2 - $new_width / 2); + $y = (int) ($resize_height / 2 - $new_height / 2); } else { @@ -695,34 +896,58 @@ class FileHandler 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); + 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); + if(!is_dir($path)) + { + FileHandler::makeDir($path); + } // write into the file switch($target_type) { case 'gif' : - if(!function_exists('imagegif')) return false; + if(!function_exists('imagegif')) + { + return FALSE; + } $output = imagegif($thumb, $target_file); break; case 'jpeg' : case 'jpg' : - if(!function_exists('imagejpeg')) return false; + if(!function_exists('imagejpeg')) + { + return FALSE; + } $output = imagejpeg($thumb, $target_file, 100); break; case 'png' : - if(!function_exists('imagepng')) return false; + if(!function_exists('imagepng')) + { + return FALSE; + } $output = imagepng($thumb, $target_file, 9); break; case 'wbmp' : case 'bmp' : - if(!function_exists('imagewbmp')) return false; + if(!function_exists('imagewbmp')) + { + return FALSE; + } $output = imagewbmp($thumb, $target_file, 100); break; } @@ -730,10 +955,13 @@ class FileHandler imagedestroy($thumb); imagedestroy($source); - if(!$output) return false; + if(!$output) + { + return FALSE; + } @chmod($target_file, 0644); - return true; + return TRUE; } /** @@ -746,20 +974,29 @@ class FileHandler function readIniFile($filename) { $filename = FileHandler::getRealPath($filename); - if(!file_exists($filename)) return false; - $arr = parse_ini_file($filename, true); - if(is_array($arr) && count($arr)>0) return $arr; - else return array(); + if(!file_exists($filename)) + { + return FALSE; + } + $arr = parse_ini_file($filename, TRUE); + if(is_array($arr) && count($arr) > 0) + { + return $arr; + } + else + { + return array(); + } } /** * Write array into ini file * - * $ini['key1'] = 'value1';
- * $ini['key2'] = 'value2';
- * $ini['section']['key1_in_section'] = 'value1_in_section';
- * $ini['section']['key2_in_section'] = 'value2_in_section';
- * FileHandler::writeIniFile('exmple.ini', $ini); + * $ini['key1'] = 'value1';
+ * $ini['key2'] = 'value2';
+ * $ini['section']['key1_in_section'] = 'value1_in_section';
+ * $ini['section']['key2_in_section'] = 'value2_in_section';
+ * FileHandler::writeIniFile('exmple.ini', $ini); * * @see FileHandler::readIniFile() * @param string $filename Target ini file name @@ -768,9 +1005,12 @@ class FileHandler */ function writeIniFile($filename, $arr) { - if(count($arr)==0) return false; + if(count($arr) == 0) + { + return FALSE; + } FileHandler::writeFile($filename, FileHandler::_makeIniBuff($arr)); - return true; + return TRUE; } /** @@ -787,16 +1027,16 @@ class FileHandler // section if(is_array($val)) { - $return .= sprintf("[%s]\n",$key); + $return .= sprintf("[%s]\n", $key); foreach($val as $k => $v) { - $return .= sprintf("%s=\"%s\"\n",$k,$v); + $return .= sprintf("%s=\"%s\"\n", $k, $v); } // value } else if(is_string($val) || is_int($val)) { - $return .= sprintf("%s=\"%s\"\n",$key,$val); + $return .= sprintf("%s=\"%s\"\n", $key, $val); } } return $return; @@ -815,7 +1055,10 @@ class FileHandler { $pathinfo = pathinfo($filename); $path = $pathinfo['dirname']; - if(!is_dir($path)) FileHandler::makeDir($path); + if(!is_dir($path)) + { + FileHandler::makeDir($path); + } require_once("FileObject.class.php"); $file_object = new FileObject($file_name, $mode); @@ -832,7 +1075,7 @@ class FileHandler { return (is_readable($filename) && !!filesize($filename)); } -} +} /* End of file FileHandler.class.php */ /* Location: ./classes/file/FileHandler.class.php */ diff --git a/classes/file/FileObject.class.php b/classes/file/FileObject.class.php index 5e4763ded..728ac579f 100644 --- a/classes/file/FileObject.class.php +++ b/classes/file/FileObject.class.php @@ -1,4 +1,5 @@ Open($path, $mode); + if($path != NULL) + { + $this->Open($path, $mode); + } } /** @@ -74,7 +79,6 @@ class FileObject extends Object return fread($this->fp, $size); } - /** * Write string to current file * @@ -84,8 +88,14 @@ class FileObject extends Object function write($str) { $len = strlen($str); - if(!$str || $len <= 0) return false; - if(!$this->fp) return false; + if(!$str || $len <= 0) + { + return FALSE; + } + if(!$this->fp) + { + return FALSE; + } $written = fwrite($this->fp, $str); return $written; } @@ -101,18 +111,18 @@ class FileObject extends Object */ function open($path, $mode) { - if($this->fp != null) - { + if($this->fp != NULL) + { $this->close(); } $this->fp = fopen($path, $mode); - if(! is_resource($this->fp) ) + if(!is_resource($this->fp)) { - $this->fp = null; - return false; + $this->fp = NULL; + return FALSE; } $this->path = $path; - return true; + return TRUE; } /** @@ -122,13 +132,13 @@ class FileObject extends Object */ function getPath() { - if($this->fp != null) + if($this->fp != NULL) { return $this->path; } else { - return null; + return NULL; } } @@ -139,13 +149,13 @@ class FileObject extends Object */ function close() { - if($this->fp != null) + if($this->fp != NULL) { fclose($this->fp); - $this->fp = null; + $this->fp = NULL; } } -} +} /* End of file FileObject.class.php */ /* Location: ./classes/file/FileObject.class.php */ diff --git a/classes/file/getRemoteResourcePHP5.php b/classes/file/getRemoteResourcePHP5.php deleted file mode 100644 index 3bb21dddb..000000000 --- a/classes/file/getRemoteResourcePHP5.php +++ /dev/null @@ -1,11 +0,0 @@ -