mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-02 01:52:10 +09:00
update trunk and tag 1.4.2.0
git-svn-id: http://xe-core.googlecode.com/svn/trunk@7470 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
55e72e3b47
commit
fae67f375d
70 changed files with 7400 additions and 507 deletions
|
|
@ -188,7 +188,7 @@
|
|||
<title xml:lang="ko">회원 가입 적용</title>
|
||||
<title xml:lang="zh-CN">Apply to member signup</title>
|
||||
<title xml:lang="jp">인증 메일 재발송 적용</title>
|
||||
<title xml:lang="zh-TW">인증 메일 재발송 적용</title>
|
||||
<title xml:lang="zh-TW">會員註冊</title>
|
||||
<title xml:lang="en">Apply to member signup</title>
|
||||
<title xml:lang="ru">Apply to member signup</title>
|
||||
<title xml:lang="vi">Apply to member signup</title>
|
||||
|
|
@ -203,7 +203,7 @@
|
|||
<title xml:lang="ko">적용하지 않음</title>
|
||||
<title xml:lang="zh-CN">不启用</title>
|
||||
<title xml:lang="jp">적용하지 않음</title>
|
||||
<title xml:lang="zh-TW">적용하지 않음</title>
|
||||
<title xml:lang="zh-TW">關閉</title>
|
||||
<title xml:lang="en">Not apply</title>
|
||||
<title xml:lang="ru">Not apply</title>
|
||||
<title xml:lang="vi">Không áp dụng</title>
|
||||
|
|
@ -212,7 +212,7 @@
|
|||
<title xml:lang="ko">적용</title>
|
||||
<title xml:lang="zh-CN">启用</title>
|
||||
<title xml:lang="jp">적용</title>
|
||||
<title xml:lang="zh-TW">적용</title>
|
||||
<title xml:lang="zh-TW">開啟</title>
|
||||
<title xml:lang="en">Apply</title>
|
||||
<title xml:lang="ru">Apply</title>
|
||||
<title xml:lang="vi">Áp dụng</title>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<title xml:lang="zh-CN">智能手机XE插件</title>
|
||||
<title xml:lang="vi">SmartPhone XE</title>
|
||||
<title xml:lang="ru">SmartPhone XE</title>
|
||||
<title xml:lang="zh-TW">SmartPhone XE</title>
|
||||
<title xml:lang="zh-TW">智慧型手機</title>
|
||||
<title xml:lang="jp">SmartPhone XE アドオン</title>
|
||||
<description xml:lang="ko">
|
||||
IPhone (touch) 등, smartphone 에서 접속시 최적화된 화면을 보여줍니다.
|
||||
|
|
|
|||
72
classes/cache/CacheApc.class.php
vendored
Normal file
72
classes/cache/CacheApc.class.php
vendored
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
/**
|
||||
* @class CacheApc
|
||||
* @author sol (sol@nhn.com)
|
||||
* @brief APC Handler
|
||||
* @version 0.1
|
||||
*
|
||||
**/
|
||||
|
||||
|
||||
class CacheApc extends CacheBase {
|
||||
var $valid_time = 36000;
|
||||
|
||||
function getInstance($opt=null){
|
||||
if(!$GLOBALS['__CacheApc__']) {
|
||||
$GLOBALS['__CacheApc__'] = new CacheApc();
|
||||
}
|
||||
return $GLOBALS['__CacheApc__'];
|
||||
}
|
||||
|
||||
function CacheApc(){
|
||||
}
|
||||
|
||||
function isSupport(){
|
||||
return function_exists('apc_add');
|
||||
}
|
||||
|
||||
function put($key, $buff, $valid_time = 0){
|
||||
if($valid_time == 0) $valid_time = $this->valid_time;
|
||||
return apc_store(md5(_XE_PATH_.$key), array(time(), $buff), $valid_time);
|
||||
}
|
||||
|
||||
function isValid($key, $modified_time = 0) {
|
||||
$_key = md5(_XE_PATH_.$key);
|
||||
$obj = apc_fetch($_key, $success);
|
||||
if(!$success || !is_array($obj)) return false;
|
||||
unset($obj[1]);
|
||||
|
||||
if($modified_time > 0 && $modified_time > $obj[0]) {
|
||||
$this->_delete($_key);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function get($key, $modified_time = 0) {
|
||||
$_key = md5(_XE_PATH_.$key);
|
||||
$obj = apc_fetch($_key, $success);
|
||||
if(!$success || !is_array($obj)) return false;
|
||||
|
||||
if($modified_time > 0 && $modified_time > $obj[0]) {
|
||||
$this->_delete($_key);
|
||||
return false;
|
||||
}
|
||||
|
||||
return $obj[1];
|
||||
}
|
||||
|
||||
function _delete($_key) {
|
||||
$this->put($_key,null,1);
|
||||
}
|
||||
|
||||
function delete($key) {
|
||||
$this->_delete(md5(_XE_PATH_.$key));
|
||||
}
|
||||
|
||||
function truncate() {
|
||||
apc_clear_cache('user');
|
||||
}
|
||||
}
|
||||
?>
|
||||
95
classes/cache/CacheHandler.class.php
vendored
Normal file
95
classes/cache/CacheHandler.class.php
vendored
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
/**
|
||||
* @class CacheHandler
|
||||
* @author sol (sol@nhn.com)
|
||||
* @brief Cache Handler
|
||||
* @version 0.1
|
||||
*
|
||||
**/
|
||||
|
||||
class CacheHandler extends Handler {
|
||||
|
||||
var $handler = null;
|
||||
|
||||
function &getInstance($target='object') {
|
||||
return new CacheHandler($target);
|
||||
}
|
||||
|
||||
function CacheHandler($target, $info=null) {
|
||||
if(!$info) $info = Context::getDBInfo();
|
||||
if($info){
|
||||
if($target == 'object'){
|
||||
if($info->use_template_cache =='apc') $type = 'apc';
|
||||
else if(substr($info->use_template_cache,0,8)=='memcache'){
|
||||
$type = 'memcache';
|
||||
$url = $info->use_template_cache;
|
||||
}
|
||||
}else if($target == 'template'){
|
||||
if($info->use_template_cache =='apc') $type = 'apc';
|
||||
else if(substr($info->use_template_cache,0,8)=='memcache'){
|
||||
$type = 'memcache';
|
||||
$url = $info->use_template_cache;
|
||||
}
|
||||
}
|
||||
|
||||
if($type){
|
||||
$class = 'Cache' . ucfirst($type);
|
||||
include_once sprintf('%sclasses/cache/%s.class.php', _XE_PATH_, $class);
|
||||
$this->handler = call_user_func(array($class,'getInstance'), $url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function isSupport(){
|
||||
if($this->handler && $this->handler->isSupport()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function get($key, $modified_time = 0){
|
||||
if(!$this->handler) return false;
|
||||
return $this->handler->get($key, $modified_time);
|
||||
}
|
||||
|
||||
function put($key, $obj, $valid_time = 0){
|
||||
if(!$this->handler) return false;
|
||||
return $this->handler->put($key, $obj, $valid_time);
|
||||
}
|
||||
|
||||
function delete($key){
|
||||
if(!$this->handler) return false;
|
||||
return $this->handler->delete($key);
|
||||
}
|
||||
|
||||
function isValid($key, $modified_time){
|
||||
if(!$this->handler) return false;
|
||||
return $this->handler->isValid($key, $modified_time);
|
||||
}
|
||||
|
||||
function truncate(){
|
||||
if(!$this->handler) return false;
|
||||
return $this->handler->truncate();
|
||||
}
|
||||
}
|
||||
|
||||
class CacheBase{
|
||||
function get($key, $modified_time = 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
function put($key, $obj, $valid_time = 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
function isValid($key, $modified_time = 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
function isSupport(){
|
||||
return false;
|
||||
}
|
||||
|
||||
function truncate(){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
?>
|
||||
91
classes/cache/CacheMemcache.class.php
vendored
Normal file
91
classes/cache/CacheMemcache.class.php
vendored
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
/**
|
||||
* @class CacheMemcache
|
||||
* @author sol (sol@nhn.com)
|
||||
* @brief Memcache Handler
|
||||
* @version 0.1
|
||||
*
|
||||
**/
|
||||
|
||||
class CacheMemcache extends CacheBase {
|
||||
|
||||
var $valid_time = 36000;
|
||||
var $Memcache;
|
||||
|
||||
function getInstance($url){
|
||||
if(!$GLOBALS['__CacheMemcache__']) {
|
||||
$GLOBALS['__CacheMemcache__'] = new CacheMemcache($url);
|
||||
}
|
||||
return $GLOBALS['__CacheMemcache__'];
|
||||
}
|
||||
|
||||
function CacheMemcache($url){
|
||||
//$config['url'] = array('memcache://localhost:11211');
|
||||
$config['url'] = is_array($url)?$url:array($url);
|
||||
$this->Memcache = new Memcache;
|
||||
|
||||
foreach($config['url'] as $url) {
|
||||
$info = parse_url($url);
|
||||
$this->Memcache->addServer($info['host'], $info['port']);
|
||||
}
|
||||
}
|
||||
|
||||
function isSupport(){
|
||||
return $this->Memcache->set('xe', 'xe', MEMCACHE_COMPRESSED, 1);
|
||||
}
|
||||
|
||||
function getKey($key){
|
||||
return md5(_XE_PATH_.$key);
|
||||
}
|
||||
|
||||
function put($key, $buff, $valid_time = 0){
|
||||
if($valid_time == 0) $valid_time = $this->valid_time;
|
||||
|
||||
return $this->Memcache->set($this->getKey($key), array(time(), $buff), MEMCACHE_COMPRESSED, $valid_time);
|
||||
}
|
||||
|
||||
function isValid($key, $modified_time = 0) {
|
||||
$_key = $this->getKey($key);
|
||||
|
||||
$obj = $this->Memcache->get($_key);
|
||||
if(!$obj || !is_array($obj)) return false;
|
||||
unset($obj[1]);
|
||||
|
||||
if($modified_time > 0 && $modified_time > $obj[0]) {
|
||||
$this->_delete($_key);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function get($key, $modified_time = 0) {
|
||||
$_key = $this->getKey($key);
|
||||
$obj = $this->Memcache->get($_key);
|
||||
if(!$obj || !is_array($obj)) return false;
|
||||
|
||||
if($modified_time > 0 && $modified_time > $obj[0]) {
|
||||
$this->_delete($_key);
|
||||
return false;
|
||||
}
|
||||
|
||||
unset($obj[0]);
|
||||
|
||||
return $obj[1];
|
||||
}
|
||||
|
||||
function delete($key) {
|
||||
$_key = $this->getKey($key);
|
||||
$this->_delete($_key);
|
||||
}
|
||||
|
||||
function _delete($_key) {
|
||||
$this->Memcache->delete($_key);
|
||||
}
|
||||
|
||||
function truncate() {
|
||||
// not support memcached
|
||||
return false;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -86,8 +86,8 @@
|
|||
}
|
||||
|
||||
Context::set('site_module_info', $site_module_info);
|
||||
if($site_module_info->site_srl && isSiteID($site_module_info->domain)) Context::set('vid', $site_module_info->domain, true);
|
||||
|
||||
if($site_module_info->site_srl && isSiteID($site_module_info->domain)) Context::set('vid', $site_module_info->domain);
|
||||
$this->db_info->lang_type = $site_module_info->default_language;
|
||||
if(!$this->db_info->lang_type) $this->db_info->lang_type = 'en';
|
||||
}
|
||||
|
|
@ -96,7 +96,10 @@
|
|||
$lang_supported = $this->loadLangSelected();
|
||||
|
||||
// Retrieve language type set in user's cookie
|
||||
if($_COOKIE['lang_type']) $this->lang_type = $_COOKIE['lang_type'];
|
||||
if($this->get('l')) {
|
||||
$_COOKIE['lang_type'] = $this->lang_type = $this->get('l');
|
||||
}
|
||||
else if($_COOKIE['lang_type']) $this->lang_type = $_COOKIE['lang_type'];
|
||||
|
||||
// If it's not exists, follow default language type set in db_info
|
||||
if(!$this->lang_type) $this->lang_type = $this->db_info->lang_type;
|
||||
|
|
@ -153,7 +156,7 @@
|
|||
else $this->allow_rewrite = false;
|
||||
|
||||
// add common JS/CSS files
|
||||
$this->addJsFile("./common/js/jquery.js");
|
||||
$this->addJsFile("./common/js/jquery.js", true, '', -100000);
|
||||
$this->addJsFile("./common/js/x.js");
|
||||
$this->addJsFile("./common/js/common.js");
|
||||
$this->addJsFile("./common/js/js_app.js");
|
||||
|
|
@ -163,7 +166,11 @@
|
|||
$this->addCSSFile("./common/css/button.css");
|
||||
|
||||
// for admin page, add admin css
|
||||
if(Context::get('module')=='admin' || strpos(Context::get('act'),'Admin')>0) $this->addCssFile("./modules/admin/tpl/css/admin.css", false);
|
||||
if(Context::get('module')=='admin' || strpos(Context::get('act'),'Admin')>0){
|
||||
$this->addCssFile("./modules/admin/tpl/css/font.css", true, 'all', '',10000);
|
||||
$this->addCssFile("./modules/admin/tpl/css/pagination.css", true, 'all', '', 100001);
|
||||
$this->addCssFile("./modules/admin/tpl/css/admin.css", true, 'all', '', 100002);
|
||||
}
|
||||
|
||||
// set locations for javascript use
|
||||
if($_SERVER['REQUEST_METHOD'] == 'GET') {
|
||||
|
|
@ -1355,8 +1362,8 @@
|
|||
$filename = trim($list[$i]);
|
||||
if(!$filename) continue;
|
||||
if(substr($filename,0,2)=='./') $filename = substr($filename,2);
|
||||
if(preg_match('/\.js$/i',$filename)) $this->_addJsFile($plugin_path.$filename, false, '', null);
|
||||
elseif(preg_match('/\.css$/i',$filename)) $this->_addCSSFile($plugin_path.$filename, false, 'all','', null);
|
||||
if(preg_match('/\.js$/i',$filename)) $this->_addJsFile($plugin_path.$filename, true, '', null);
|
||||
elseif(preg_match('/\.css$/i',$filename)) $this->_addCSSFile($plugin_path.$filename, true, 'all','', null);
|
||||
}
|
||||
|
||||
if(is_dir($plugin_path.'lang')) $this->_loadLang($plugin_path.'lang');
|
||||
|
|
@ -1530,7 +1537,7 @@
|
|||
$xe = _XE_PATH_;
|
||||
$path = strtr($path, "\\", "/");
|
||||
|
||||
$base_url = preg_replace('@^https?://[^/]+/+@', '', Context::getDefaultUrl());
|
||||
$base_url = preg_replace('@^https?://[^/]+/?@', '', Context::getRequestUri());
|
||||
|
||||
$_xe = explode('/', $xe);
|
||||
$_path = explode('/', $path);
|
||||
|
|
|
|||
|
|
@ -167,18 +167,23 @@
|
|||
|
||||
// leave error log if an error occured (if __DEBUG_DB_OUTPUT__ is defined)
|
||||
if($this->isError()) {
|
||||
$site_module_info = Context::get('site_module_info');
|
||||
$log['module'] = $site_module_info->module;
|
||||
$log['act'] = Context::get('act');
|
||||
$log['query_id'] = $this->query_id;
|
||||
$log['time'] = date('Y-m-d H:i:s');
|
||||
$log['result'] = 'Failed';
|
||||
$log['errno'] = $this->errno;
|
||||
$log['errstr'] = $this->errstr;
|
||||
|
||||
if(__DEBUG_DB_OUTPUT__ == 1) {
|
||||
$debug_file = _XE_PATH_."files/_debug_db_query.php";
|
||||
$buff = sprintf("%s\n",print_r($log,true));
|
||||
$buff = array();
|
||||
if(!file_exists($debug_file)) $buff[] = '<?php exit(); ?>';
|
||||
$buff[] = print_r($log, true);
|
||||
|
||||
if($display_line) $buff = "\n<?php\n/*\n====================================\n".$buff."------------------------------------\n*/\n?>\n";
|
||||
|
||||
if(@!$fp = fopen($debug_file,"a")) return;
|
||||
fwrite($fp, $buff);
|
||||
if(@!$fp = fopen($debug_file, "a")) return;
|
||||
fwrite($fp, implode("\n", $buff)."\n\n");
|
||||
fclose($fp);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -239,6 +244,7 @@
|
|||
**/
|
||||
function executeQuery($query_id, $args = NULL) {
|
||||
if(!$query_id) return new Object(-1, 'msg_invalid_queryid');
|
||||
$this->query_id = $query_id;
|
||||
|
||||
$id_args = explode('.', $query_id);
|
||||
if(count($id_args) == 2) {
|
||||
|
|
|
|||
|
|
@ -172,9 +172,27 @@
|
|||
function _fetch($result) {
|
||||
if(!$this->isConnected() || $this->isError() || !$result) return;
|
||||
|
||||
$col_types = cubrid_column_types ($result);
|
||||
$col_names = cubrid_column_names ($result);
|
||||
if (($max = count ($col_types)) == count ($col_names)) {
|
||||
$count = 0;
|
||||
while ($count < $max) {
|
||||
if (preg_match ("/^char/", $col_types[$count]) > 0) {
|
||||
$char_type_fields[] = $col_names[$count];
|
||||
}
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
while($tmp = cubrid_fetch($result, CUBRID_OBJECT)) {
|
||||
if (is_array ($char_type_fields)) {
|
||||
foreach ($char_type_fields as $val) {
|
||||
$tmp->{$val} = rtrim ($tmp->{$val});
|
||||
}
|
||||
}
|
||||
$output[] = $tmp;
|
||||
}
|
||||
unset ($char_type_fields);
|
||||
|
||||
if($result) cubrid_close_request($result);
|
||||
|
||||
|
|
@ -413,7 +431,7 @@
|
|||
foreach($val['condition'] as $v) {
|
||||
if(!isset($v['value'])) continue;
|
||||
if($v['value'] === '') continue;
|
||||
if(!in_array(gettype($v['value']), array('string', 'integer'))) continue;
|
||||
if(!in_array(gettype($v['value']), array('string', 'integer', 'double'))) continue;
|
||||
|
||||
$name = $v['column'];
|
||||
$operation = $v['operation'];
|
||||
|
|
@ -638,7 +656,7 @@
|
|||
}
|
||||
|
||||
$alias = $val['alias'] ? sprintf('"%s"',$val['alias']) : null;
|
||||
if(substr($name,-1) == '*') {
|
||||
if($name == '*') {
|
||||
$column_list[] = $name;
|
||||
} elseif(strpos($name,'.')===false && strpos($name,'(')===false) {
|
||||
$name = sprintf($click_count,$name);
|
||||
|
|
|
|||
|
|
@ -646,7 +646,7 @@
|
|||
foreach($val['condition'] as $v) {
|
||||
if(!isset($v['value'])) continue;
|
||||
if($v['value'] === '') continue;
|
||||
if(!in_array(gettype($v['value']), array('string', 'integer'))) continue;
|
||||
if(!in_array(gettype($v['value']), array('string', 'integer', 'double'))) continue;
|
||||
|
||||
$name = $v['column'];
|
||||
$operation = $v['operation'];
|
||||
|
|
|
|||
|
|
@ -422,7 +422,7 @@
|
|||
foreach($val['condition'] as $v) {
|
||||
if(!isset($v['value'])) continue;
|
||||
if($v['value'] === '') continue;
|
||||
if(!in_array(gettype($v['value']), array('string', 'integer'))) continue;
|
||||
if(!in_array(gettype($v['value']), array('string', 'integer', 'double'))) continue;
|
||||
|
||||
$name = $v['column'];
|
||||
if(preg_match('/^substr\(/i',$name)) $name = preg_replace('/^substr\(/i','substring(',$name);
|
||||
|
|
|
|||
|
|
@ -402,7 +402,7 @@
|
|||
foreach($val['condition'] as $v) {
|
||||
if(!isset($v['value'])) continue;
|
||||
if($v['value'] === '') continue;
|
||||
if(!in_array(gettype($v['value']), array('string', 'integer'))) continue;
|
||||
if(!in_array(gettype($v['value']), array('string', 'integer', 'double'))) continue;
|
||||
|
||||
$name = $v['column'];
|
||||
$operation = $v['operation'];
|
||||
|
|
|
|||
|
|
@ -411,7 +411,7 @@
|
|||
foreach($val['condition'] as $v) {
|
||||
if(!isset($v['value'])) continue;
|
||||
if($v['value'] === '') continue;
|
||||
if(!in_array(gettype($v['value']), array('string', 'integer'))) continue;
|
||||
if(!in_array(gettype($v['value']), array('string', 'integer', 'double'))) continue;
|
||||
|
||||
$name = $v['column'];
|
||||
$operation = $v['operation'];
|
||||
|
|
|
|||
|
|
@ -391,7 +391,7 @@
|
|||
foreach($val['condition'] as $v) {
|
||||
if(!isset($v['value'])) continue;
|
||||
if($v['value'] === '') continue;
|
||||
if(!in_array(gettype($v['value']), array('string', 'integer'))) continue;
|
||||
if(!in_array(gettype($v['value']), array('string', 'integer', 'double'))) continue;
|
||||
|
||||
$name = $v['column'];
|
||||
$operation = $v['operation'];
|
||||
|
|
|
|||
|
|
@ -527,7 +527,7 @@ class DBPostgresql extends DB
|
|||
continue;
|
||||
if ($v['value'] === '')
|
||||
continue;
|
||||
if (!in_array(gettype($v['value']), array('string', 'integer')))
|
||||
if (!in_array(gettype($v['value']), array('string', 'integer', 'double')))
|
||||
continue;
|
||||
|
||||
$name = $v['column'];
|
||||
|
|
|
|||
|
|
@ -383,7 +383,7 @@
|
|||
foreach($val['condition'] as $v) {
|
||||
if(!isset($v['value'])) continue;
|
||||
if($v['value'] === '') continue;
|
||||
if(!in_array(gettype($v['value']), array('string', 'integer'))) continue;
|
||||
if(!in_array(gettype($v['value']), array('string', 'integer', 'double'))) continue;
|
||||
|
||||
$name = $v['column'];
|
||||
$operation = $v['operation'];
|
||||
|
|
|
|||
|
|
@ -413,7 +413,7 @@
|
|||
foreach($val['condition'] as $v) {
|
||||
if(!isset($v['value'])) continue;
|
||||
if($v['value'] === '') continue;
|
||||
if(!in_array(gettype($v['value']), array('string', 'integer'))) continue;
|
||||
if(!in_array(gettype($v['value']), array('string', 'integer', 'double'))) continue;
|
||||
|
||||
$name = $v['column'];
|
||||
$operation = $v['operation'];
|
||||
|
|
|
|||
|
|
@ -32,7 +32,10 @@
|
|||
|
||||
// request method에 따른 컨텐츠 결과물 추출
|
||||
if(Context::get('xeVirtualRequestMethod')=='xml') $output = $this->_toVirtualXmlDoc($oModule);
|
||||
else if(Context::getRequestMethod() == 'XMLRPC') $output = $this->_toXmlDoc($oModule);
|
||||
else if(Context::getRequestMethod() == 'XMLRPC') {
|
||||
if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) $this->gz_enabled = false;
|
||||
$output = $this->_toXmlDoc($oModule);
|
||||
}
|
||||
else if(Context::getRequestMethod() == 'JSON') $output = $this->_toJSON($oModule);
|
||||
else $output = $this->_toHTMLDoc($oModule);
|
||||
|
||||
|
|
|
|||
|
|
@ -200,17 +200,23 @@
|
|||
static $oFtp = null;
|
||||
|
||||
// if safe_mode is on, use FTP
|
||||
if(ini_get('safe_mode') && $oFtp == null) {
|
||||
if(!Context::isFTPRegisted()) return;
|
||||
if(ini_get('safe_mode')) {
|
||||
$ftp_info = Context::getFTPInfo();
|
||||
if($oFtp == null) {
|
||||
if(!Context::isFTPRegisted()) return;
|
||||
|
||||
require_once(_XE_PATH_.'libs/ftp.class.php');
|
||||
$ftp_info = Context::getFTPInfo();
|
||||
$oFtp = new ftp();
|
||||
if(!$oFtp->ftp_connect('localhost')) return;
|
||||
if(!$oFtp->ftp_login($ftp_info->ftp_user, $ftp_info->ftp_password)) {
|
||||
$oFtp->ftp_quit();
|
||||
return;
|
||||
}
|
||||
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(!$oFtp->ftp_login($ftp_info->ftp_user, $ftp_info->ftp_password)) {
|
||||
$oFtp->ftp_quit();
|
||||
return;
|
||||
}
|
||||
}
|
||||
$ftp_path = $ftp_info->ftp_root_path;
|
||||
if(!$ftp_path) $ftp_path = "/";
|
||||
}
|
||||
|
||||
$path_string = str_replace(_XE_PATH_,'',$path_string);
|
||||
|
|
@ -220,10 +226,11 @@
|
|||
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')) {
|
||||
$oFtp->ftp_mkdir($path);
|
||||
$oFtp->ftp_site("CHMOD 777 ".$path);
|
||||
$oFtp->ftp_mkdir($ftp_path);
|
||||
$oFtp->ftp_site("CHMOD 777 ".$ftp_path);
|
||||
} else {
|
||||
@mkdir($path, 0755);
|
||||
@chmod($path, 0755);
|
||||
|
|
@ -325,8 +332,8 @@
|
|||
* @remarks if the target is moved (when return code is 300~399), this function follows the location specified response header.
|
||||
**/
|
||||
function getRemoteResource($url, $body = null, $timeout = 3, $method = 'GET', $content_type = null, $headers = array(), $cookies = array(), $post_data = array()) {
|
||||
set_include_path(_XE_PATH_."libs/PEAR");
|
||||
require_once('PEAR.php');
|
||||
//set_include_path(_XE_PATH_."libs/PEAR");
|
||||
requirePear();
|
||||
require_once('HTTP/Request.php');
|
||||
|
||||
if(__PROXY_SERVER__!==null) {
|
||||
|
|
@ -499,34 +506,36 @@
|
|||
$target_type = strtolower($target_type);
|
||||
|
||||
// create temporary image with target size
|
||||
if(function_exists('imagecreatetruecolor')) $thumb = @imagecreatetruecolor($resize_width, $resize_height);
|
||||
else $thumb = @imagecreate($resize_width, $resize_height);
|
||||
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;
|
||||
$source = @imagecreatefromgif($source_file);
|
||||
$source = imagecreatefromgif($source_file);
|
||||
break;
|
||||
// jpg
|
||||
case 'jpeg' :
|
||||
case 'jpg' :
|
||||
if(!function_exists('imagecreatefromjpeg')) return false;
|
||||
$source = @imagecreatefromjpeg($source_file);
|
||||
$source = imagecreatefromjpeg($source_file);
|
||||
break;
|
||||
// png
|
||||
case 'png' :
|
||||
if(!function_exists('imagecreatefrompng')) return false;
|
||||
$source = @imagecreatefrompng($source_file);
|
||||
$source = imagecreatefrompng($source_file);
|
||||
break;
|
||||
// bmp
|
||||
case 'wbmp' :
|
||||
case 'bmp' :
|
||||
if(!function_exists('imagecreatefromwbmp')) return false;
|
||||
$source = @imagecreatefromwbmp($source_file);
|
||||
$source = imagecreatefromwbmp($source_file);
|
||||
break;
|
||||
default :
|
||||
return;
|
||||
|
|
@ -545,8 +554,8 @@
|
|||
}
|
||||
|
||||
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;
|
||||
|
||||
// create directory
|
||||
|
|
@ -557,26 +566,26 @@
|
|||
switch($target_type) {
|
||||
case 'gif' :
|
||||
if(!function_exists('imagegif')) return false;
|
||||
$output = @imagegif($thumb, $target_file);
|
||||
$output = imagegif($thumb, $target_file);
|
||||
break;
|
||||
case 'jpeg' :
|
||||
case 'jpg' :
|
||||
if(!function_exists('imagejpeg')) return false;
|
||||
$output = @imagejpeg($thumb, $target_file, 100);
|
||||
$output = imagejpeg($thumb, $target_file, 100);
|
||||
break;
|
||||
case 'png' :
|
||||
if(!function_exists('imagepng')) return false;
|
||||
$output = @imagepng($thumb, $target_file, 9);
|
||||
$output = imagepng($thumb, $target_file, 9);
|
||||
break;
|
||||
case 'wbmp' :
|
||||
case 'bmp' :
|
||||
if(!function_exists('imagewbmp')) return false;
|
||||
$output = @imagewbmp($thumb, $target_file, 100);
|
||||
$output = imagewbmp($thumb, $target_file, 100);
|
||||
break;
|
||||
}
|
||||
|
||||
@imagedestroy($thumb);
|
||||
@imagedestroy($source);
|
||||
imagedestroy($thumb);
|
||||
imagedestroy($source);
|
||||
|
||||
if(!$output) return false;
|
||||
@chmod($target_file, 0644);
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
class Optimizer {
|
||||
|
||||
var $cache_path = "./files/cache/optimized/";
|
||||
var $script_file = "./common/script.php?l=%s&t=.%s";
|
||||
|
||||
/**
|
||||
* @brief Constructor which check if a directory, 'optimized' exists in designated path. If not create a new one
|
||||
|
|
@ -37,48 +38,59 @@
|
|||
function getOptimizedFiles($source_files, $type = "js") {
|
||||
if(!is_array($source_files) || !count($source_files)) return;
|
||||
|
||||
// $source_files의 역슬래쉬 경로를 슬래쉬로 변경 (윈도우즈 대비)
|
||||
foreach($source_files as $key => $file){
|
||||
$source_files[$key]['file'] = str_replace("\\","/",$file['file']);
|
||||
}
|
||||
|
||||
// 관리자 설정시 설정이 되어 있지 않으면 패스
|
||||
$db_info = Context::getDBInfo();
|
||||
if($db_info->use_optimizer == 'N') return $this->_getOptimizedRemoved($source_files);
|
||||
|
||||
// 캐시 디렉토리가 없으면 실행하지 않음
|
||||
if(!is_dir($this->cache_path)) return $this->_getOptimizedRemoved($source_files);
|
||||
|
||||
$files = array();
|
||||
$db_info = Context::getDBInfo();
|
||||
if($db_info->use_optimizer == 'N' || !is_dir($this->cache_path)) return $this->_getOptimizedRemoved($source_files);
|
||||
|
||||
if(!count($source_files)) return;
|
||||
foreach($source_files as $file) {
|
||||
if(!$file || !$file['file']) continue;
|
||||
|
||||
$files = array();
|
||||
$hash = "";
|
||||
foreach($source_files as $key => $file) {
|
||||
if($file['file'][0] == '/')
|
||||
{
|
||||
if(!file_exists($_SERVER['DOCUMENT_ROOT'].$file['file'])) continue;
|
||||
}
|
||||
else if(!$file || !$file['file'] || !file_exists($file['file'])) continue;
|
||||
$file['file'] = $source_files[$key]['file'] = str_replace("\\","/",$file['file']);
|
||||
if(empty($file['optimized']) || preg_match('/^https?:\/\//i', $file['file']) ) $files[] = $file;
|
||||
else $targets[] = $file;
|
||||
else{
|
||||
$targets[] = $file;
|
||||
$hash .= $file['file'];
|
||||
}
|
||||
}
|
||||
|
||||
if(!count($targets)) return $this->_getOptimizedRemoved($files);
|
||||
$list_file_hash = md5($hash);
|
||||
$oCacheHandler = &CacheHandler::getInstance('template');
|
||||
if($oCacheHandler->isSupport()){
|
||||
if(!$oCacheHandler->isValid($list_file_hash)){
|
||||
$buff = array();
|
||||
foreach($targets as $file) $buff[] = $file['file'];
|
||||
$oCacheHandler->put($list_file_hash, $buff);
|
||||
}
|
||||
}else{
|
||||
$list_file = FileHandler::getRealPath($this->cache_path . $list_file_hash);
|
||||
|
||||
$optimized_info = $this->getOptimizedInfo($targets);
|
||||
|
||||
$path = sprintf("%s%s", $this->cache_path, $optimized_info[0]);
|
||||
$filename = sprintf("%s.%s.%s.php", $optimized_info[0], $optimized_info[1], $type);
|
||||
|
||||
$this->doOptimizedFile($path, $filename, $targets, $type);
|
||||
|
||||
array_unshift($files, array('file' => $path.'/'.$filename, 'media' => 'all'));
|
||||
if(!file_exists($list_file)){
|
||||
$str = '<?php $f=array();';
|
||||
foreach($targets as $file) $str .= '$f[]="'. $file['file'] . '";';
|
||||
$str .= ' return $f; ?>';
|
||||
|
||||
FileHandler::writeFile($list_file, $str);
|
||||
}
|
||||
}
|
||||
array_unshift($files, array('file' => sprintf($this->script_file, $list_file_hash, $type) , 'media' => 'all'));
|
||||
$files = $this->_getOptimizedRemoved($files);
|
||||
if(!count($files)) return $files;
|
||||
|
||||
$url_info = parse_url(Context::getRequestUri());
|
||||
$abpath = $url_info['path'];
|
||||
|
||||
foreach($files as $key => $val) {
|
||||
$file = $val['file'];
|
||||
|
||||
if(substr($file,0,1)=='/' || strpos($file,'://')!==false) continue;
|
||||
if($file{0} == '/' || strpos($file,'://')!==false) continue;
|
||||
if(substr($file,0,2)=='./') $file = substr($file,2);
|
||||
$file = $abpath.$file;
|
||||
while(strpos($file,'/../')!==false) {
|
||||
|
|
@ -86,184 +98,8 @@
|
|||
}
|
||||
$files[$key]['file'] = $file;
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief retrive a list of files from a given parameter
|
||||
* @param[in] files a list containing files
|
||||
**/
|
||||
function _getOnlyFileList($files) {
|
||||
foreach($files as $key => $val) $files[$key] = $val['file'];
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief method to generate a unique key from list of files along with a last modified date
|
||||
* @param[in] files an array containing file names
|
||||
**/
|
||||
function getOptimizedInfo($files) {
|
||||
// 개별 요소 파일이 갱신되었으면 새로 옵티마이징
|
||||
$count = count($files);
|
||||
$last_modified = 0;
|
||||
for($i=0;$i<$count;$i++) {
|
||||
$mtime = filemtime($files[$i]['file']);
|
||||
if($last_modified < $mtime) $last_modified = $mtime;
|
||||
}
|
||||
|
||||
$buff = implode("\n", $this->_getOnlyFileList($files));
|
||||
|
||||
return array(md5($buff), $last_modified);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief method that check if a valid cache file exits for a given filename. If not create new one.
|
||||
* @param[in] path directory path of the cache files
|
||||
* @param[in] filename a filename for cache files
|
||||
* @param[in] targets
|
||||
* @param[in] type a type of cache file
|
||||
**/
|
||||
function doOptimizedFile($path, $filename, $targets, $type) {
|
||||
// 대상 파일이 있으면 그냥 패스~
|
||||
if(file_exists($path.'/'.$filename)) return;
|
||||
|
||||
// 대상 파일이 없으면 hashed_filename으로 생성된 파일들을 모두 삭제
|
||||
FileHandler::removeFilesInDir($path);
|
||||
|
||||
// 새로 캐시 파일을 생성
|
||||
$this->makeOptimizedFile($path, $filename, $targets, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief method produce a php code to merge css/js files, compress the resultant files and modified the HTML header accordingly.
|
||||
* @param[in] path
|
||||
* @param[in] filename a name of a resultant file
|
||||
* @param[in] targets list of files to be used for the operation
|
||||
* @param[in] type a type of file such as css or js
|
||||
* @return NONE
|
||||
**/
|
||||
function makeOptimizedFile($path, $filename, $targets, $type) {
|
||||
/**
|
||||
* 실제 css나 js의 내용을 합친 것을 구함
|
||||
**/
|
||||
// 대상 파일의 내용을 구해오고 css 파일일 경우 url()내의 경로를 변경
|
||||
$content_filename = substr($filename, 0, -4);
|
||||
$file_object = FileHandler::openFile($path."/".$content_filename, "w");
|
||||
|
||||
if($type == 'css') $file_object->write('@charset "UTF-8";'."\n");
|
||||
foreach($targets as $file) {
|
||||
$str = FileHandler::readFile($file['file']);
|
||||
|
||||
$str = trim(Context::convertEncodingStr($str));
|
||||
|
||||
// css 일경우 background:url() 변경 / media 적용
|
||||
if($type == 'css') {
|
||||
$str = $this->replaceCssPath($file['file'], $str);
|
||||
if($file['media'] != 'all') $str = '@media '.$file['media'].' {'."\n".$str."\n".'}';
|
||||
}
|
||||
$file_object->write($str);
|
||||
$file_object->write("\n");
|
||||
unset($str);
|
||||
}
|
||||
|
||||
$file_object->close();
|
||||
|
||||
/**
|
||||
* 캐시 타임을 제대로 이용하기 위한 헤더 파일 구함
|
||||
**/
|
||||
// 확장자별 content-type 체크
|
||||
if($type == 'css') $content_type = 'text/css';
|
||||
elseif($type == 'js') $content_type = 'text/javascript';
|
||||
|
||||
// 캐시를 위한 처리
|
||||
$unique = crc32($content_filename);
|
||||
$size = filesize($path.'/'.$content_file);
|
||||
$mtime = filemtime($path.'/'.$content_file);
|
||||
|
||||
// js, css 파일을 php를 통해서 출력하고 이 출력시에 헤더값을 조작하여 캐싱과 압축전송이 되도록 함 (IE6는 CSS파일일 경우 gzip압축하지 않음)
|
||||
$header_buff = '<?php
|
||||
$content_filename = "'.$content_filename.'";
|
||||
$mtime = '.$mtime.';
|
||||
$cached = false;
|
||||
$type = "'.$type.'";
|
||||
|
||||
if(isset($_SERVER["HTTP_IF_MODIFIED_SINCE"])) {
|
||||
$time = strtotime(preg_replace("/;.*$/", "", $_SERVER["HTTP_IF_MODIFIED_SINCE"]));
|
||||
if($mtime == $time) {
|
||||
header("HTTP/1.1 304");
|
||||
$cached = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( preg_match("/MSIE 6.0/i",$_SERVER["HTTP_USER_AGENT"]) || strpos($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip")===false || !function_exists("ob_gzhandler") ) {
|
||||
$size = filesize($content_filename);
|
||||
} else {
|
||||
$f = fopen($content_filename,"r");
|
||||
$buff = fread($f, filesize($content_filename));
|
||||
fclose($f);
|
||||
$buff = ob_gzhandler($buff, 5);
|
||||
$size = strlen($buff);
|
||||
header("Content-Encoding: gzip");
|
||||
}
|
||||
|
||||
header("Content-Type: '.$content_type.'; charset=UTF-8");
|
||||
header("Date: '.substr(gmdate('r'), 0, -5).'GMT");
|
||||
header("Expires: '.substr(gmdate('r', strtotime('+1 MONTH')), 0, -5).'GMT");
|
||||
header("Cache-Control: private, max-age=2592000");
|
||||
header("Pragma: cache");
|
||||
header("Last-Modified: '.substr(gmdate('r', $mtime), 0, -5).'GMT");
|
||||
header("ETag: \"'.dechex($unique).'-".dechex($size)."-'.dechex($mtime).'\"");
|
||||
|
||||
if(!$cached) {
|
||||
if(empty($buff)) {
|
||||
$f = fopen($content_filename,"r");
|
||||
fpassthru($f);
|
||||
} else print $buff;
|
||||
}
|
||||
?>';
|
||||
FileHandler::writeFile($path.'/'.$filename, $header_buff);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief method that modify a path for import or background element in a given css file
|
||||
* @param[in] file a file to be modified
|
||||
* @param[in] str a buffer to store resultant content
|
||||
* @return Returns resultant content
|
||||
**/
|
||||
function replaceCssPath($file, $str) {
|
||||
// css 파일의 위치를 구함
|
||||
$this->tmp_css_path = preg_replace("/^\.\//is","",dirname($file))."/";
|
||||
|
||||
// url() 로 되어 있는 css 파일의 경로를 변경
|
||||
$str = preg_replace_callback('/url\(([^\)]*)\)/is', array($this, '_replaceCssPath'), $str);
|
||||
|
||||
// charset 지정 문구를 제거
|
||||
$str = preg_replace('!@charset([^;]*?);!is','',$str);
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief callback method that is responsible for replacing strings in css file with predefined ones.
|
||||
* @param[in] matches a list of strings to be examined and modified if necessary
|
||||
* @return Returns resultant content
|
||||
**/
|
||||
function _replaceCssPath($matches) {
|
||||
static $abpath = null;
|
||||
if(is_null($abpath)) {
|
||||
$url_info = parse_url(Context::getRequestUri());
|
||||
$abpath = $url_info['path'];
|
||||
}
|
||||
$path = str_replace(array('"',"'"),'',$matches[1]);
|
||||
if(substr($path,0,1)=='/' || strpos($path,'://')!==false || strpos($path,'.htc')!==false) return 'url("'.$path.'")';
|
||||
if(substr($path,0,2)=='./') $path = substr($path,2);
|
||||
$target = $abpath.$this->tmp_css_path.$path;
|
||||
while(strpos($target,'/../')!==false) {
|
||||
$target = preg_replace('/\/([^\/]+)\/\.\.\//','/',$target);
|
||||
}
|
||||
|
||||
return 'url("'.$target.'")';
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -55,14 +55,26 @@
|
|||
$this->tpl_path = preg_replace('/^\.\//','',$tpl_path);
|
||||
$this->tpl_file = $tpl_file;
|
||||
|
||||
// get cached compiled file name
|
||||
$compiled_tpl_file = FileHandler::getRealPath($this->_getCompiledFileName($tpl_file));
|
||||
$oCacheHandler = &CacheHandler::getInstance('template');
|
||||
if($oCacheHandler->isSupport()){
|
||||
$cache_key = 'template:' . $tpl_file;
|
||||
$buff = $oCacheHandler->get($cache_key, filemtime(FileHandler::getRealPath($tpl_file)));
|
||||
if(!$buff){
|
||||
$buff = $this->_compileTplFile($tpl_file);
|
||||
$oCacheHandler->put($cache_key, $buff);
|
||||
}
|
||||
|
||||
// compile
|
||||
$buff = $this->_compile($tpl_file, $compiled_tpl_file);
|
||||
$output = $this->_fetch('', $buff, $tpl_path);
|
||||
}else{
|
||||
// get cached compiled file name
|
||||
$compiled_tpl_file = FileHandler::getRealPath($this->_getCompiledFileName($tpl_file));
|
||||
|
||||
// make a result, combining Context and compiled_tpl_file
|
||||
$output = $this->_fetch($compiled_tpl_file, $buff, $tpl_path);
|
||||
// compile
|
||||
$buff = $this->_compile($tpl_file, $compiled_tpl_file);
|
||||
|
||||
// make a result, combining Context and compiled_tpl_file
|
||||
$output = $this->_fetch($compiled_tpl_file, $buff, $tpl_path);
|
||||
}
|
||||
|
||||
if(__DEBUG__==3 ) $GLOBALS['__template_elapsed__'] += getMicroTime() - $start;
|
||||
|
||||
|
|
|
|||
4
common/css/popup.css
Normal file
4
common/css/popup.css
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
@charset "utf-8";
|
||||
|
||||
body { overflow:hidden; }
|
||||
table.colTable { margin:0; }
|
||||
|
|
@ -523,57 +523,36 @@ function zbxe_folder_close(id) {
|
|||
* 팝업의 내용에 맞게 크기를 늘리는 것은... 쉽게 되지는 않음.. ㅡ.ㅜ
|
||||
* popup_layout 에서 window.onload 시 자동 요청됨.
|
||||
**/
|
||||
var _popupHeight = 0;
|
||||
function setFixedPopupSize() {
|
||||
var headerObj = jQuery('#popHeader');
|
||||
var bodyObj = jQuery('#popBody');
|
||||
var $ = jQuery;
|
||||
var $header = $('#popHeader');
|
||||
var $body = $('#popBody');
|
||||
|
||||
if(bodyObj.length) {
|
||||
if(bodyObj.height() > 400) {
|
||||
bodyObj.css({ overflowY:'scroll', overflowX:'hidden', height:400 });
|
||||
}
|
||||
}
|
||||
if ($body.length) {
|
||||
if ($body.height() > 400) {
|
||||
$body.css({ overflow:'auto', overflowX:'hidden', height:400+'px' });
|
||||
}
|
||||
}
|
||||
|
||||
bodyObj.css({paddingRight:30});
|
||||
var $win = $(window);
|
||||
var $pc = $('#popup_content');
|
||||
var w = Math.max($pc[0].offsetWidth, 600);
|
||||
var h = $pc[0].offsetHeight;
|
||||
var dw = $win.width();
|
||||
var dh = $win.height();
|
||||
var _w = 0, _h = 0;
|
||||
|
||||
var w = jQuery("#popup_content").width();
|
||||
w = w< 600 ? 600 : w;
|
||||
var h = jQuery("#popup_content").height();
|
||||
if (w != dw) _w = w - dw;
|
||||
if (h != dh) _h = h - dh;
|
||||
|
||||
if(h != _popupHeight) {
|
||||
_popupHeight = h;
|
||||
if (_w || _h) {
|
||||
window.resizeBy(_w, _h);
|
||||
}
|
||||
|
||||
jQuery('div').each(function() { var ww = jQuery(this).width(); if(jQuery.inArray(this.id, ['waitingforserverresponse', 'fororiginalimagearea', 'fororiginalimageareabg']) == -1) { if(ww > w) w = ww; } });
|
||||
jQuery('table').each(function() { var ww = jQuery(this).width(); if(ww > w) w = ww; });
|
||||
jQuery('form').each(function() { var ww = jQuery(this).width(); if(ww > w) w = ww; });
|
||||
|
||||
jQuery("#popup_content").width(w);
|
||||
jQuery("#popHeader").width(w);
|
||||
jQuery("#popFooter").width(w);
|
||||
|
||||
window.resizeTo(w, h);
|
||||
|
||||
// 윈도우 OS에서는 브라우저별로 미세 조절이 필요
|
||||
var moreW = 0;
|
||||
if(navigator.userAgent.toLowerCase().indexOf('windows') > 0) {
|
||||
if(jQuery.browser.opera) moreW += 9;
|
||||
else if(jQuery.browser.msie) moreW += 10;
|
||||
else if(jQuery.browser.mozilla) moreW += 8;
|
||||
else if(jQuery.browser.safari) {
|
||||
moreW += 4;
|
||||
h -= 12;
|
||||
}
|
||||
}
|
||||
var h1 = jQuery(window).height();
|
||||
if(!/chrome/.test(navigator.userAgent.toLowerCase())) {
|
||||
window.resizeBy(moreW, h-h1+5);
|
||||
} else {
|
||||
window.resizeBy(10,60);
|
||||
}
|
||||
window.scrollTo(0,0);
|
||||
}
|
||||
|
||||
setTimeout(setFixedPopupSize, 300);
|
||||
if (!arguments.callee.executed) {
|
||||
setTimeout(setFixedPopupSize, 300);
|
||||
arguments.callee.executed = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
3
common/js/plugins/qtip/jquery.qtip.min.js
vendored
3
common/js/plugins/qtip/jquery.qtip.min.js
vendored
File diff suppressed because one or more lines are too long
274
common/script.php
Normal file
274
common/script.php
Normal file
|
|
@ -0,0 +1,274 @@
|
|||
<?php
|
||||
/**
|
||||
* @author sol (sol@nhn.com)
|
||||
* @brief css 및 js Optimizer 처리 gateway
|
||||
*
|
||||
**/
|
||||
|
||||
if(!$_GET['t'] || !$_GET['l']) exit;
|
||||
|
||||
// set env
|
||||
$XE_PATH = substr(dirname(__FILE__),0,strlen('common')*-1);
|
||||
define('_XE_PATH_', $XE_PATH);
|
||||
define('__ZBXE__', true);
|
||||
define('__XE_LOADED_CLASS__', true);
|
||||
include _XE_PATH_ . 'config/config.inc.php';
|
||||
|
||||
$dbconfig_file =_XE_PATH_ . 'files/config/db.config.php';
|
||||
if(file_exists($dbconfig_file)){
|
||||
include $dbconfig_file;
|
||||
if($db_info && $db_info->use_template_cache){
|
||||
include _XE_PATH_ . 'classes/handler/Handler.class.php';
|
||||
include _XE_PATH_ . 'classes/cache/CacheHandler.class.php';
|
||||
$oCacheHandler = new CacheHandler('template', $db_info);
|
||||
$cache_support = $oCacheHandler->isSupport();
|
||||
}else{
|
||||
$cache_support = false;
|
||||
}
|
||||
}else{
|
||||
$cache_support = false;
|
||||
}
|
||||
|
||||
$XE_WEB_PATH = substr($XE_PATH,strlen($_SERVER['DOCUMENT_ROOT']));
|
||||
if(substr($XE_WEB_PATH,-1) != "/") $XE_WEB_PATH .= "/";
|
||||
$cache_path = $XE_PATH . 'files/cache/optimized/';
|
||||
$type = $_GET['t'];
|
||||
$list_file = $cache_path . $_GET['l'];
|
||||
|
||||
|
||||
function getRealPath($file){
|
||||
if($file{0}=='.' && $file{1} =='/') $file = _XE_PATH_.substr($file, 2);
|
||||
return $file;
|
||||
}
|
||||
|
||||
function getMtime($file){
|
||||
$file = getRealPath($file);
|
||||
if(file_exists($file)) return filemtime($file);
|
||||
}
|
||||
|
||||
function getMaxMtime($list){
|
||||
$mtime = array();
|
||||
foreach($list as $file) $mtime[] = getMtime($file);
|
||||
return max($mtime);
|
||||
}
|
||||
|
||||
// check
|
||||
if($cache_support){
|
||||
$list = $oCacheHandler->get($_GET['l']);
|
||||
$mtime = getMaxMtime($list);
|
||||
}else{
|
||||
if(!file_exists($list_file)) exit;
|
||||
$list = include($list_file);
|
||||
$mtime = getMaxMtime(array_merge($list,array($list_file)));
|
||||
}
|
||||
if(!is_array($list)) exit;
|
||||
|
||||
// set content-type
|
||||
if($type == '.css'){
|
||||
$content_type = 'text/css';
|
||||
} else if($type == '.js') {
|
||||
$content_type = 'text/javascript';
|
||||
}
|
||||
|
||||
header("Content-Type: ".$content_type."; charset=UTF-8");
|
||||
|
||||
// return 304
|
||||
if (!empty($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
|
||||
$modifiedSince = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
|
||||
if ($modifiedSince && ($modifiedSince == $mtime)) {
|
||||
header('HTTP/1.1 304 Not Modified');
|
||||
header("Connection: close");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
function useContentEncoding(){
|
||||
if( (defined('__OB_GZHANDLER_ENABLE__') && __OB_GZHANDLER_ENABLE__ == 1)
|
||||
&& strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')!==false
|
||||
&& function_exists('ob_gzhandler')
|
||||
&& extension_loaded('zlib')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function getCacheKey($list){
|
||||
$key = 'optimized:' . join('',$list);
|
||||
return $key;
|
||||
}
|
||||
|
||||
function printFileList($list){
|
||||
global $mtime, $cache_support, $oCacheHandler;
|
||||
|
||||
$content_encoding = useContentEncoding();
|
||||
$output = null;
|
||||
|
||||
if($cache_support){
|
||||
$cache_key = getCacheKey($list);
|
||||
$output = $oCacheHandler->get($cache_key, $mtime);
|
||||
}
|
||||
|
||||
if(!$output || trim($output)==''){
|
||||
for($i=0,$c=count($list);$i<$c;$i++){
|
||||
$file = getRealPath($list[$i]);
|
||||
if(file_exists($file)){
|
||||
$output .= file_get_contents($file);
|
||||
$output .= "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($cache_support) $oCacheHandler->put($cache_key, $output);
|
||||
|
||||
if($content_encoding) $output = ob_gzhandler($output, 5);
|
||||
$size = strlen($output);
|
||||
|
||||
if($size > 0){
|
||||
header("Cache-Control: private, max-age=2592000");
|
||||
header("Pragma: cache");
|
||||
header("Connection: close");
|
||||
header("Last-Modified: " . substr(gmdate('r', $mtime), 0, -5). "GMT");
|
||||
header("ETag: \"". md5(join(' ', $list)) .'-'. dechex($mtime) .'-'.dechex($size)."\"");
|
||||
}
|
||||
|
||||
header("Content-Length: ". $size);
|
||||
|
||||
if($content_encoding) header("Content-Encoding: gzip");
|
||||
|
||||
echo($output);
|
||||
}
|
||||
|
||||
function write($file_name, $buff, $mode='w'){
|
||||
$file_name = getRealPath($file_name);
|
||||
if(@!$fp = fopen($file_name,$mode)) return false;
|
||||
fwrite($fp, $buff);
|
||||
fclose($fp);
|
||||
@chmod($file_name, 0644);
|
||||
}
|
||||
|
||||
function read($file_name) {
|
||||
$file_name = 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) {
|
||||
while(!feof($fp) && strlen($buff)<=$filesize) {
|
||||
$str = fgets($fp, 1024);
|
||||
$buff .= $str;
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
return $buff;
|
||||
}
|
||||
|
||||
function makeCacheFileCSS($css_file, $cache_file, $return=false){
|
||||
$str = read($css_file);
|
||||
$str = replaceCssPath($css_file, trim(convertEncodingStr($str)));
|
||||
|
||||
if($return){
|
||||
return $str;
|
||||
}else{
|
||||
write($cache_file, $str."\n");
|
||||
unset($str);
|
||||
}
|
||||
}
|
||||
|
||||
function replaceCssPath($file, $str) {
|
||||
global $tmp_css_path;
|
||||
|
||||
// css 파일의 위치를 구함
|
||||
$tmp_css_path = preg_replace("/^\.\//is","",dirname($file))."/";
|
||||
// url() 로 되어 있는 css 파일의 경로를 변경
|
||||
$str = preg_replace_callback('/url\(([^\)]*)\)/is', '_replaceCssPath', $str);
|
||||
|
||||
// charset 지정 문구를 제거
|
||||
$str = preg_replace('!@charset([^;]*?);!is','',$str);
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
function _replaceCssPath($matches) {
|
||||
global $tmp_css_path, $XE_WEB_PATH;
|
||||
|
||||
$path = str_replace(array('"',"'"),'',$matches[1]);
|
||||
if(substr($path,0,1)=='/' || strpos($path,'://')!==false || strpos($path,'.htc')!==false) return 'url('.$path.')';
|
||||
if(substr($path,0,2)=='./') $path = substr($path,2);
|
||||
$target = $XE_WEB_PATH.$tmp_css_path.$path;
|
||||
while(strpos($target,'/../')!==false) {
|
||||
$target = preg_replace('/\/([^\/]+)\/\.\.\//','/',$target);
|
||||
}
|
||||
|
||||
return 'url('.$target.')';
|
||||
}
|
||||
|
||||
function convertEncodingStr($str) {
|
||||
$charset_list = array(
|
||||
'UTF-8', 'EUC-KR', 'CP949', 'ISO8859-1', 'EUC-JP', 'SHIFT_JIS', 'CP932',
|
||||
'EUC-CN', 'HZ', 'GBK', 'GB18030', 'EUC-TW', 'BIG5', 'CP950', 'BIG5-HKSCS',
|
||||
'ISO2022-CN', 'ISO2022-CN-EXT', 'ISO2022-JP', 'ISO2022-JP-2', 'ISO2022-JP-1',
|
||||
'ISO8859-6', 'ISO8859-8', 'JOHAB', 'ISO2022-KR', 'CP1255', 'CP1256', 'CP862',
|
||||
'ASCII', 'ISO8859-1', 'ISO8850-2', 'ISO8850-3', 'ISO8850-4', 'ISO8850-5',
|
||||
'ISO8850-7', 'ISO8850-9', 'ISO8850-10', 'ISO8850-13', 'ISO8850-14',
|
||||
'ISO8850-15', 'ISO8850-16', 'CP1250', 'CP1251', 'CP1252', 'CP1253', 'CP1254',
|
||||
'CP1257', 'CP850', 'CP866',
|
||||
);
|
||||
|
||||
for($i=0;$i<count($charset_list);$i++) {
|
||||
$charset = $charset_list[$i];
|
||||
if($str){
|
||||
$cstr = iconv($charset,$charset,$str);
|
||||
if($str == $cstr);
|
||||
return $cstr;
|
||||
}
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
if($type == '.js'){
|
||||
printFileList($list);
|
||||
}else if($type == '.css'){
|
||||
|
||||
if($cache_support){
|
||||
foreach($list as $file){
|
||||
$cache_file = $cache_path . md5($file);
|
||||
$css[] = getRealPath($cache_file);
|
||||
}
|
||||
|
||||
$cache_key = getCacheKey($css);
|
||||
$buff = $oCacheHandler->get($cache_key, $mtime);
|
||||
if(!$buff){
|
||||
$buff = '';
|
||||
$css = array();
|
||||
foreach($list as $file){
|
||||
$cache_file = $cache_path . md5($file);
|
||||
$buff .= makeCacheFileCSS($file, getRealPath($cache_file), true);
|
||||
$css[] = getRealPath($cache_file);
|
||||
}
|
||||
|
||||
$oCacheHandler->put($cache_key, $buff);
|
||||
}
|
||||
|
||||
}else{
|
||||
foreach($list as $file){
|
||||
$cache_file = $cache_path . md5($file);
|
||||
$cache_mtime = getMtime($cache_file);
|
||||
$css_mtime = getMtime($file);
|
||||
|
||||
// check modified
|
||||
if($css_mtime > $cache_mtime){
|
||||
makeCacheFileCSS($file, getRealPath($cache_file));
|
||||
}
|
||||
$css[] = getRealPath($cache_file);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
printFileList($css);
|
||||
}
|
||||
?>
|
||||
|
|
@ -7,6 +7,6 @@
|
|||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
xAddEventListener(window, 'load', setFixedPopupSize);
|
||||
jQuery(window).load(setFixedPopupSize);
|
||||
var _isPoped = true;
|
||||
</script>
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
* @brief XE의 전체 버전 표기
|
||||
* 이 파일의 수정이 없더라도 공식 릴리즈시에 수정되어 함께 배포되어야 함
|
||||
**/
|
||||
define('__ZBXE_VERSION__', '1.4.1.1');
|
||||
define('__ZBXE_VERSION__', '1.4.2.0');
|
||||
|
||||
/**
|
||||
* @brief zbXE가 설치된 장소의 base path를 구함
|
||||
|
|
@ -107,11 +107,6 @@
|
|||
require _XE_PATH_.'libs/FirePHPCore/FirePHP.class.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 간단하게 사용하기 위한 함수 정의한 파일 require
|
||||
**/
|
||||
require(_XE_PATH_.'config/func.inc.php');
|
||||
|
||||
/**
|
||||
* @brief Set Timezone as server time
|
||||
**/
|
||||
|
|
@ -120,29 +115,36 @@
|
|||
date_default_timezone_set(@date_default_timezone_get());
|
||||
}
|
||||
|
||||
if(!defined('__XE_LOADED_CLASS__')){
|
||||
/**
|
||||
* @brief 간단하게 사용하기 위한 함수 정의한 파일 require
|
||||
**/
|
||||
require(_XE_PATH_.'config/func.inc.php');
|
||||
|
||||
if(__DEBUG__) define('__StartTime__', getMicroTime());
|
||||
if(__DEBUG__) define('__StartTime__', getMicroTime());
|
||||
|
||||
/**
|
||||
* @brief 기본적인 class 파일 include
|
||||
* @TODO : PHP5 기반으로 바꾸게 되면 _autoload()를 이용할 수 있기에 제거 대상
|
||||
**/
|
||||
if(__DEBUG__) define('__ClassLoadStartTime__', getMicroTime());
|
||||
require(_XE_PATH_.'classes/object/Object.class.php');
|
||||
require(_XE_PATH_.'classes/extravar/Extravar.class.php');
|
||||
require(_XE_PATH_.'classes/handler/Handler.class.php');
|
||||
require(_XE_PATH_.'classes/xml/XmlParser.class.php');
|
||||
require(_XE_PATH_.'classes/xml/XmlJsFilter.class.php');
|
||||
require(_XE_PATH_.'classes/context/Context.class.php');
|
||||
require(_XE_PATH_.'classes/db/DB.class.php');
|
||||
require(_XE_PATH_.'classes/file/FileHandler.class.php');
|
||||
require(_XE_PATH_.'classes/widget/WidgetHandler.class.php');
|
||||
require(_XE_PATH_.'classes/editor/EditorHandler.class.php');
|
||||
require(_XE_PATH_.'classes/module/ModuleObject.class.php');
|
||||
require(_XE_PATH_.'classes/module/ModuleHandler.class.php');
|
||||
require(_XE_PATH_.'classes/display/DisplayHandler.class.php');
|
||||
require(_XE_PATH_.'classes/template/TemplateHandler.class.php');
|
||||
require(_XE_PATH_.'classes/mail/Mail.class.php');
|
||||
require(_XE_PATH_.'classes/page/PageHandler.class.php');
|
||||
if(__DEBUG__) $GLOBALS['__elapsed_class_load__'] = getMicroTime() - __ClassLoadStartTime__;
|
||||
/**
|
||||
* @brief 기본적인 class 파일 include
|
||||
* @TODO : PHP5 기반으로 바꾸게 되면 _autoload()를 이용할 수 있기에 제거 대상
|
||||
**/
|
||||
if(__DEBUG__) define('__ClassLoadStartTime__', getMicroTime());
|
||||
require(_XE_PATH_.'classes/object/Object.class.php');
|
||||
require(_XE_PATH_.'classes/extravar/Extravar.class.php');
|
||||
require(_XE_PATH_.'classes/handler/Handler.class.php');
|
||||
require(_XE_PATH_.'classes/xml/XmlParser.class.php');
|
||||
require(_XE_PATH_.'classes/xml/XmlJsFilter.class.php');
|
||||
require(_XE_PATH_.'classes/cache/CacheHandler.class.php');
|
||||
require(_XE_PATH_.'classes/context/Context.class.php');
|
||||
require(_XE_PATH_.'classes/db/DB.class.php');
|
||||
require(_XE_PATH_.'classes/file/FileHandler.class.php');
|
||||
require(_XE_PATH_.'classes/widget/WidgetHandler.class.php');
|
||||
require(_XE_PATH_.'classes/editor/EditorHandler.class.php');
|
||||
require(_XE_PATH_.'classes/module/ModuleObject.class.php');
|
||||
require(_XE_PATH_.'classes/module/ModuleHandler.class.php');
|
||||
require(_XE_PATH_.'classes/display/DisplayHandler.class.php');
|
||||
require(_XE_PATH_.'classes/template/TemplateHandler.class.php');
|
||||
require(_XE_PATH_.'classes/mail/Mail.class.php');
|
||||
require(_XE_PATH_.'classes/page/PageHandler.class.php');
|
||||
if(__DEBUG__) $GLOBALS['__elapsed_class_load__'] = getMicroTime() - __ClassLoadStartTime__;
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -895,4 +895,17 @@
|
|||
return;
|
||||
}
|
||||
|
||||
function requirePear()
|
||||
{
|
||||
if(version_compare(PHP_VERSION, "5.3.0") < 0)
|
||||
{
|
||||
set_include_path(_XE_PATH_."libs/PEAR");
|
||||
}
|
||||
else
|
||||
{
|
||||
set_include_path(_XE_PATH_."libs/PEAR.1.9");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
55
libs/PEAR.1.9/HTTP/Request.php
Normal file
55
libs/PEAR.1.9/HTTP/Request.php
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
require_once 'HTTP/Request2.php';
|
||||
|
||||
class HTTP_Request extends HTTP_Request2
|
||||
{
|
||||
private $reponse = null;
|
||||
|
||||
public function addHeader($name, $value)
|
||||
{
|
||||
$this->setHeader($name, $value);
|
||||
}
|
||||
|
||||
public function sendRequest($saveBody = true)
|
||||
{
|
||||
$response = $this->send();
|
||||
$this->response = $response;
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function getResponseCode() {
|
||||
if($this->response)
|
||||
{
|
||||
return $this->response->getStatus();
|
||||
}
|
||||
}
|
||||
|
||||
public function getResponseHeader() {
|
||||
if($this->response)
|
||||
{
|
||||
return $this->response->getHeader();
|
||||
}
|
||||
}
|
||||
|
||||
public function getResponseBody() {
|
||||
if($this->response)
|
||||
{
|
||||
return $this->response->getBody();
|
||||
}
|
||||
}
|
||||
|
||||
public function getResponseCookies() {
|
||||
if($this->response)
|
||||
{
|
||||
return $this->response->getCookies();
|
||||
}
|
||||
}
|
||||
|
||||
public function addPostData($name, $value, $preencoded = false)
|
||||
{
|
||||
$this->addPostParameter($name, $value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
861
libs/PEAR.1.9/HTTP/Request2.php
Normal file
861
libs/PEAR.1.9/HTTP/Request2.php
Normal file
|
|
@ -0,0 +1,861 @@
|
|||
<?php
|
||||
/**
|
||||
* Class representing a HTTP request message
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2008, 2009, Alexey Borzov <avb@php.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Request2.php 298246 2010-04-21 10:41:16Z avb $
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* A class representing an URL as per RFC 3986.
|
||||
*/
|
||||
require_once 'Net/URL2.php';
|
||||
|
||||
/**
|
||||
* Exception class for HTTP_Request2 package
|
||||
*/
|
||||
require_once 'HTTP/Request2/Exception.php';
|
||||
|
||||
/**
|
||||
* Class representing a HTTP request message
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 0.5.2
|
||||
* @link http://tools.ietf.org/html/rfc2616#section-5
|
||||
*/
|
||||
class HTTP_Request2 implements SplSubject
|
||||
{
|
||||
/**#@+
|
||||
* Constants for HTTP request methods
|
||||
*
|
||||
* @link http://tools.ietf.org/html/rfc2616#section-5.1.1
|
||||
*/
|
||||
const METHOD_OPTIONS = 'OPTIONS';
|
||||
const METHOD_GET = 'GET';
|
||||
const METHOD_HEAD = 'HEAD';
|
||||
const METHOD_POST = 'POST';
|
||||
const METHOD_PUT = 'PUT';
|
||||
const METHOD_DELETE = 'DELETE';
|
||||
const METHOD_TRACE = 'TRACE';
|
||||
const METHOD_CONNECT = 'CONNECT';
|
||||
/**#@-*/
|
||||
|
||||
/**#@+
|
||||
* Constants for HTTP authentication schemes
|
||||
*
|
||||
* @link http://tools.ietf.org/html/rfc2617
|
||||
*/
|
||||
const AUTH_BASIC = 'basic';
|
||||
const AUTH_DIGEST = 'digest';
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Regular expression used to check for invalid symbols in RFC 2616 tokens
|
||||
* @link http://pear.php.net/bugs/bug.php?id=15630
|
||||
*/
|
||||
const REGEXP_INVALID_TOKEN = '![\x00-\x1f\x7f-\xff()<>@,;:\\\\"/\[\]?={}\s]!';
|
||||
|
||||
/**
|
||||
* Regular expression used to check for invalid symbols in cookie strings
|
||||
* @link http://pear.php.net/bugs/bug.php?id=15630
|
||||
* @link http://web.archive.org/web/20080331104521/http://cgi.netscape.com/newsref/std/cookie_spec.html
|
||||
*/
|
||||
const REGEXP_INVALID_COOKIE = '/[\s,;]/';
|
||||
|
||||
/**
|
||||
* Fileinfo magic database resource
|
||||
* @var resource
|
||||
* @see detectMimeType()
|
||||
*/
|
||||
private static $_fileinfoDb;
|
||||
|
||||
/**
|
||||
* Observers attached to the request (instances of SplObserver)
|
||||
* @var array
|
||||
*/
|
||||
protected $observers = array();
|
||||
|
||||
/**
|
||||
* Request URL
|
||||
* @var Net_URL2
|
||||
*/
|
||||
protected $url;
|
||||
|
||||
/**
|
||||
* Request method
|
||||
* @var string
|
||||
*/
|
||||
protected $method = self::METHOD_GET;
|
||||
|
||||
/**
|
||||
* Authentication data
|
||||
* @var array
|
||||
* @see getAuth()
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* Request headers
|
||||
* @var array
|
||||
*/
|
||||
protected $headers = array();
|
||||
|
||||
/**
|
||||
* Configuration parameters
|
||||
* @var array
|
||||
* @see setConfig()
|
||||
*/
|
||||
protected $config = array(
|
||||
'adapter' => 'HTTP_Request2_Adapter_Socket',
|
||||
'connect_timeout' => 10,
|
||||
'timeout' => 0,
|
||||
'use_brackets' => true,
|
||||
'protocol_version' => '1.1',
|
||||
'buffer_size' => 16384,
|
||||
'store_body' => true,
|
||||
|
||||
'proxy_host' => '',
|
||||
'proxy_port' => '',
|
||||
'proxy_user' => '',
|
||||
'proxy_password' => '',
|
||||
'proxy_auth_scheme' => self::AUTH_BASIC,
|
||||
|
||||
'ssl_verify_peer' => true,
|
||||
'ssl_verify_host' => true,
|
||||
'ssl_cafile' => null,
|
||||
'ssl_capath' => null,
|
||||
'ssl_local_cert' => null,
|
||||
'ssl_passphrase' => null,
|
||||
|
||||
'digest_compat_ie' => false,
|
||||
|
||||
'follow_redirects' => false,
|
||||
'max_redirects' => 5,
|
||||
'strict_redirects' => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Last event in request / response handling, intended for observers
|
||||
* @var array
|
||||
* @see getLastEvent()
|
||||
*/
|
||||
protected $lastEvent = array(
|
||||
'name' => 'start',
|
||||
'data' => null
|
||||
);
|
||||
|
||||
/**
|
||||
* Request body
|
||||
* @var string|resource
|
||||
* @see setBody()
|
||||
*/
|
||||
protected $body = '';
|
||||
|
||||
/**
|
||||
* Array of POST parameters
|
||||
* @var array
|
||||
*/
|
||||
protected $postParams = array();
|
||||
|
||||
/**
|
||||
* Array of file uploads (for multipart/form-data POST requests)
|
||||
* @var array
|
||||
*/
|
||||
protected $uploads = array();
|
||||
|
||||
/**
|
||||
* Adapter used to perform actual HTTP request
|
||||
* @var HTTP_Request2_Adapter
|
||||
*/
|
||||
protected $adapter;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor. Can set request URL, method and configuration array.
|
||||
*
|
||||
* Also sets a default value for User-Agent header.
|
||||
*
|
||||
* @param string|Net_Url2 Request URL
|
||||
* @param string Request method
|
||||
* @param array Configuration for this Request instance
|
||||
*/
|
||||
public function __construct($url = null, $method = self::METHOD_GET, array $config = array())
|
||||
{
|
||||
$this->setConfig($config);
|
||||
if (!empty($url)) {
|
||||
$this->setUrl($url);
|
||||
}
|
||||
if (!empty($method)) {
|
||||
$this->setMethod($method);
|
||||
}
|
||||
$this->setHeader('user-agent', 'HTTP_Request2/0.5.2 ' .
|
||||
'(http://pear.php.net/package/http_request2) ' .
|
||||
'PHP/' . phpversion());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the URL for this request
|
||||
*
|
||||
* If the URL has userinfo part (username & password) these will be removed
|
||||
* and converted to auth data. If the URL does not have a path component,
|
||||
* that will be set to '/'.
|
||||
*
|
||||
* @param string|Net_URL2 Request URL
|
||||
* @return HTTP_Request2
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public function setUrl($url)
|
||||
{
|
||||
if (is_string($url)) {
|
||||
$url = new Net_URL2(
|
||||
$url, array(Net_URL2::OPTION_USE_BRACKETS => $this->config['use_brackets'])
|
||||
);
|
||||
}
|
||||
if (!$url instanceof Net_URL2) {
|
||||
throw new HTTP_Request2_Exception('Parameter is not a valid HTTP URL');
|
||||
}
|
||||
// URL contains username / password?
|
||||
if ($url->getUserinfo()) {
|
||||
$username = $url->getUser();
|
||||
$password = $url->getPassword();
|
||||
$this->setAuth(rawurldecode($username), $password? rawurldecode($password): '');
|
||||
$url->setUserinfo('');
|
||||
}
|
||||
if ('' == $url->getPath()) {
|
||||
$url->setPath('/');
|
||||
}
|
||||
$this->url = $url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the request URL
|
||||
*
|
||||
* @return Net_URL2
|
||||
*/
|
||||
public function getUrl()
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the request method
|
||||
*
|
||||
* @param string
|
||||
* @return HTTP_Request2
|
||||
* @throws HTTP_Request2_Exception if the method name is invalid
|
||||
*/
|
||||
public function setMethod($method)
|
||||
{
|
||||
// Method name should be a token: http://tools.ietf.org/html/rfc2616#section-5.1.1
|
||||
if (preg_match(self::REGEXP_INVALID_TOKEN, $method)) {
|
||||
throw new HTTP_Request2_Exception("Invalid request method '{$method}'");
|
||||
}
|
||||
$this->method = $method;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the request method
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMethod()
|
||||
{
|
||||
return $this->method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the configuration parameter(s)
|
||||
*
|
||||
* The following parameters are available:
|
||||
* <ul>
|
||||
* <li> 'adapter' - adapter to use (string)</li>
|
||||
* <li> 'connect_timeout' - Connection timeout in seconds (integer)</li>
|
||||
* <li> 'timeout' - Total number of seconds a request can take.
|
||||
* Use 0 for no limit, should be greater than
|
||||
* 'connect_timeout' if set (integer)</li>
|
||||
* <li> 'use_brackets' - Whether to append [] to array variable names (bool)</li>
|
||||
* <li> 'protocol_version' - HTTP Version to use, '1.0' or '1.1' (string)</li>
|
||||
* <li> 'buffer_size' - Buffer size to use for reading and writing (int)</li>
|
||||
* <li> 'store_body' - Whether to store response body in response object.
|
||||
* Set to false if receiving a huge response and
|
||||
* using an Observer to save it (boolean)</li>
|
||||
* <li> 'proxy_host' - Proxy server host (string)</li>
|
||||
* <li> 'proxy_port' - Proxy server port (integer)</li>
|
||||
* <li> 'proxy_user' - Proxy auth username (string)</li>
|
||||
* <li> 'proxy_password' - Proxy auth password (string)</li>
|
||||
* <li> 'proxy_auth_scheme' - Proxy auth scheme, one of HTTP_Request2::AUTH_* constants (string)</li>
|
||||
* <li> 'ssl_verify_peer' - Whether to verify peer's SSL certificate (bool)</li>
|
||||
* <li> 'ssl_verify_host' - Whether to check that Common Name in SSL
|
||||
* certificate matches host name (bool)</li>
|
||||
* <li> 'ssl_cafile' - Cerificate Authority file to verify the peer
|
||||
* with (use with 'ssl_verify_peer') (string)</li>
|
||||
* <li> 'ssl_capath' - Directory holding multiple Certificate
|
||||
* Authority files (string)</li>
|
||||
* <li> 'ssl_local_cert' - Name of a file containing local cerificate (string)</li>
|
||||
* <li> 'ssl_passphrase' - Passphrase with which local certificate
|
||||
* was encoded (string)</li>
|
||||
* <li> 'digest_compat_ie' - Whether to imitate behaviour of MSIE 5 and 6
|
||||
* in using URL without query string in digest
|
||||
* authentication (boolean)</li>
|
||||
* <li> 'follow_redirects' - Whether to automatically follow HTTP Redirects (boolean)</li>
|
||||
* <li> 'max_redirects' - Maximum number of redirects to follow (integer)</li>
|
||||
* <li> 'strict_redirects' - Whether to keep request method on redirects via status 301 and
|
||||
* 302 (true, needed for compatibility with RFC 2616)
|
||||
* or switch to GET (false, needed for compatibility with most
|
||||
* browsers) (boolean)</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param string|array configuration parameter name or array
|
||||
* ('parameter name' => 'parameter value')
|
||||
* @param mixed parameter value if $nameOrConfig is not an array
|
||||
* @return HTTP_Request2
|
||||
* @throws HTTP_Request2_Exception If the parameter is unknown
|
||||
*/
|
||||
public function setConfig($nameOrConfig, $value = null)
|
||||
{
|
||||
if (is_array($nameOrConfig)) {
|
||||
foreach ($nameOrConfig as $name => $value) {
|
||||
$this->setConfig($name, $value);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (!array_key_exists($nameOrConfig, $this->config)) {
|
||||
throw new HTTP_Request2_Exception(
|
||||
"Unknown configuration parameter '{$nameOrConfig}'"
|
||||
);
|
||||
}
|
||||
$this->config[$nameOrConfig] = $value;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value(s) of the configuration parameter(s)
|
||||
*
|
||||
* @param string parameter name
|
||||
* @return mixed value of $name parameter, array of all configuration
|
||||
* parameters if $name is not given
|
||||
* @throws HTTP_Request2_Exception If the parameter is unknown
|
||||
*/
|
||||
public function getConfig($name = null)
|
||||
{
|
||||
if (null === $name) {
|
||||
return $this->config;
|
||||
} elseif (!array_key_exists($name, $this->config)) {
|
||||
throw new HTTP_Request2_Exception(
|
||||
"Unknown configuration parameter '{$name}'"
|
||||
);
|
||||
}
|
||||
return $this->config[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the autentification data
|
||||
*
|
||||
* @param string user name
|
||||
* @param string password
|
||||
* @param string authentication scheme
|
||||
* @return HTTP_Request2
|
||||
*/
|
||||
public function setAuth($user, $password = '', $scheme = self::AUTH_BASIC)
|
||||
{
|
||||
if (empty($user)) {
|
||||
$this->auth = null;
|
||||
} else {
|
||||
$this->auth = array(
|
||||
'user' => (string)$user,
|
||||
'password' => (string)$password,
|
||||
'scheme' => $scheme
|
||||
);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the authentication data
|
||||
*
|
||||
* The array has the keys 'user', 'password' and 'scheme', where 'scheme'
|
||||
* is one of the HTTP_Request2::AUTH_* constants.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAuth()
|
||||
{
|
||||
return $this->auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets request header(s)
|
||||
*
|
||||
* The first parameter may be either a full header string 'header: value' or
|
||||
* header name. In the former case $value parameter is ignored, in the latter
|
||||
* the header's value will either be set to $value or the header will be
|
||||
* removed if $value is null. The first parameter can also be an array of
|
||||
* headers, in that case method will be called recursively.
|
||||
*
|
||||
* Note that headers are treated case insensitively as per RFC 2616.
|
||||
*
|
||||
* <code>
|
||||
* $req->setHeader('Foo: Bar'); // sets the value of 'Foo' header to 'Bar'
|
||||
* $req->setHeader('FoO', 'Baz'); // sets the value of 'Foo' header to 'Baz'
|
||||
* $req->setHeader(array('foo' => 'Quux')); // sets the value of 'Foo' header to 'Quux'
|
||||
* $req->setHeader('FOO'); // removes 'Foo' header from request
|
||||
* </code>
|
||||
*
|
||||
* @param string|array header name, header string ('Header: value')
|
||||
* or an array of headers
|
||||
* @param string|null header value, header will be removed if null
|
||||
* @return HTTP_Request2
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public function setHeader($name, $value = null)
|
||||
{
|
||||
if (is_array($name)) {
|
||||
foreach ($name as $k => $v) {
|
||||
if (is_string($k)) {
|
||||
$this->setHeader($k, $v);
|
||||
} else {
|
||||
$this->setHeader($v);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (null === $value && strpos($name, ':')) {
|
||||
list($name, $value) = array_map('trim', explode(':', $name, 2));
|
||||
}
|
||||
// Header name should be a token: http://tools.ietf.org/html/rfc2616#section-4.2
|
||||
if (preg_match(self::REGEXP_INVALID_TOKEN, $name)) {
|
||||
throw new HTTP_Request2_Exception("Invalid header name '{$name}'");
|
||||
}
|
||||
// Header names are case insensitive anyway
|
||||
$name = strtolower($name);
|
||||
if (null === $value) {
|
||||
unset($this->headers[$name]);
|
||||
} else {
|
||||
$this->headers[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the request headers
|
||||
*
|
||||
* The array is of the form ('header name' => 'header value'), header names
|
||||
* are lowercased
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHeaders()
|
||||
{
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a cookie to "Cookie:" header
|
||||
*
|
||||
* @param string cookie name
|
||||
* @param string cookie value
|
||||
* @return HTTP_Request2
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public function addCookie($name, $value)
|
||||
{
|
||||
$cookie = $name . '=' . $value;
|
||||
if (preg_match(self::REGEXP_INVALID_COOKIE, $cookie)) {
|
||||
throw new HTTP_Request2_Exception("Invalid cookie: '{$cookie}'");
|
||||
}
|
||||
$cookies = empty($this->headers['cookie'])? '': $this->headers['cookie'] . '; ';
|
||||
$this->setHeader('cookie', $cookies . $cookie);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the request body
|
||||
*
|
||||
* @param string Either a string with the body or filename containing body
|
||||
* @param bool Whether first parameter is a filename
|
||||
* @return HTTP_Request2
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public function setBody($body, $isFilename = false)
|
||||
{
|
||||
if (!$isFilename) {
|
||||
if (!$body instanceof HTTP_Request2_MultipartBody) {
|
||||
$this->body = (string)$body;
|
||||
} else {
|
||||
$this->body = $body;
|
||||
}
|
||||
} else {
|
||||
if (!($fp = @fopen($body, 'rb'))) {
|
||||
throw new HTTP_Request2_Exception("Cannot open file {$body}");
|
||||
}
|
||||
$this->body = $fp;
|
||||
if (empty($this->headers['content-type'])) {
|
||||
$this->setHeader('content-type', self::detectMimeType($body));
|
||||
}
|
||||
}
|
||||
$this->postParams = $this->uploads = array();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the request body
|
||||
*
|
||||
* @return string|resource|HTTP_Request2_MultipartBody
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
if (self::METHOD_POST == $this->method &&
|
||||
(!empty($this->postParams) || !empty($this->uploads))
|
||||
) {
|
||||
if ('application/x-www-form-urlencoded' == $this->headers['content-type']) {
|
||||
$body = http_build_query($this->postParams, '', '&');
|
||||
if (!$this->getConfig('use_brackets')) {
|
||||
$body = preg_replace('/%5B\d+%5D=/', '=', $body);
|
||||
}
|
||||
// support RFC 3986 by not encoding '~' symbol (request #15368)
|
||||
return str_replace('%7E', '~', $body);
|
||||
|
||||
} elseif ('multipart/form-data' == $this->headers['content-type']) {
|
||||
require_once 'HTTP/Request2/MultipartBody.php';
|
||||
return new HTTP_Request2_MultipartBody(
|
||||
$this->postParams, $this->uploads, $this->getConfig('use_brackets')
|
||||
);
|
||||
}
|
||||
}
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a file to form-based file upload
|
||||
*
|
||||
* Used to emulate file upload via a HTML form. The method also sets
|
||||
* Content-Type of HTTP request to 'multipart/form-data'.
|
||||
*
|
||||
* If you just want to send the contents of a file as the body of HTTP
|
||||
* request you should use setBody() method.
|
||||
*
|
||||
* @param string name of file-upload field
|
||||
* @param mixed full name of local file
|
||||
* @param string filename to send in the request
|
||||
* @param string content-type of file being uploaded
|
||||
* @return HTTP_Request2
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public function addUpload($fieldName, $filename, $sendFilename = null,
|
||||
$contentType = null)
|
||||
{
|
||||
if (!is_array($filename)) {
|
||||
if (!($fp = @fopen($filename, 'rb'))) {
|
||||
throw new HTTP_Request2_Exception("Cannot open file {$filename}");
|
||||
}
|
||||
$this->uploads[$fieldName] = array(
|
||||
'fp' => $fp,
|
||||
'filename' => empty($sendFilename)? basename($filename): $sendFilename,
|
||||
'size' => filesize($filename),
|
||||
'type' => empty($contentType)? self::detectMimeType($filename): $contentType
|
||||
);
|
||||
} else {
|
||||
$fps = $names = $sizes = $types = array();
|
||||
foreach ($filename as $f) {
|
||||
if (!is_array($f)) {
|
||||
$f = array($f);
|
||||
}
|
||||
if (!($fp = @fopen($f[0], 'rb'))) {
|
||||
throw new HTTP_Request2_Exception("Cannot open file {$f[0]}");
|
||||
}
|
||||
$fps[] = $fp;
|
||||
$names[] = empty($f[1])? basename($f[0]): $f[1];
|
||||
$sizes[] = filesize($f[0]);
|
||||
$types[] = empty($f[2])? self::detectMimeType($f[0]): $f[2];
|
||||
}
|
||||
$this->uploads[$fieldName] = array(
|
||||
'fp' => $fps, 'filename' => $names, 'size' => $sizes, 'type' => $types
|
||||
);
|
||||
}
|
||||
if (empty($this->headers['content-type']) ||
|
||||
'application/x-www-form-urlencoded' == $this->headers['content-type']
|
||||
) {
|
||||
$this->setHeader('content-type', 'multipart/form-data');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds POST parameter(s) to the request.
|
||||
*
|
||||
* @param string|array parameter name or array ('name' => 'value')
|
||||
* @param mixed parameter value (can be an array)
|
||||
* @return HTTP_Request2
|
||||
*/
|
||||
public function addPostParameter($name, $value = null)
|
||||
{
|
||||
if (!is_array($name)) {
|
||||
$this->postParams[$name] = $value;
|
||||
} else {
|
||||
foreach ($name as $k => $v) {
|
||||
$this->addPostParameter($k, $v);
|
||||
}
|
||||
}
|
||||
if (empty($this->headers['content-type'])) {
|
||||
$this->setHeader('content-type', 'application/x-www-form-urlencoded');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attaches a new observer
|
||||
*
|
||||
* @param SplObserver
|
||||
*/
|
||||
public function attach(SplObserver $observer)
|
||||
{
|
||||
foreach ($this->observers as $attached) {
|
||||
if ($attached === $observer) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->observers[] = $observer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detaches an existing observer
|
||||
*
|
||||
* @param SplObserver
|
||||
*/
|
||||
public function detach(SplObserver $observer)
|
||||
{
|
||||
foreach ($this->observers as $key => $attached) {
|
||||
if ($attached === $observer) {
|
||||
unset($this->observers[$key]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies all observers
|
||||
*/
|
||||
public function notify()
|
||||
{
|
||||
foreach ($this->observers as $observer) {
|
||||
$observer->update($this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the last event
|
||||
*
|
||||
* Adapters should use this method to set the current state of the request
|
||||
* and notify the observers.
|
||||
*
|
||||
* @param string event name
|
||||
* @param mixed event data
|
||||
*/
|
||||
public function setLastEvent($name, $data = null)
|
||||
{
|
||||
$this->lastEvent = array(
|
||||
'name' => $name,
|
||||
'data' => $data
|
||||
);
|
||||
$this->notify();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last event
|
||||
*
|
||||
* Observers should use this method to access the last change in request.
|
||||
* The following event names are possible:
|
||||
* <ul>
|
||||
* <li>'connect' - after connection to remote server,
|
||||
* data is the destination (string)</li>
|
||||
* <li>'disconnect' - after disconnection from server</li>
|
||||
* <li>'sentHeaders' - after sending the request headers,
|
||||
* data is the headers sent (string)</li>
|
||||
* <li>'sentBodyPart' - after sending a part of the request body,
|
||||
* data is the length of that part (int)</li>
|
||||
* <li>'receivedHeaders' - after receiving the response headers,
|
||||
* data is HTTP_Request2_Response object</li>
|
||||
* <li>'receivedBodyPart' - after receiving a part of the response
|
||||
* body, data is that part (string)</li>
|
||||
* <li>'receivedEncodedBodyPart' - as 'receivedBodyPart', but data is still
|
||||
* encoded by Content-Encoding</li>
|
||||
* <li>'receivedBody' - after receiving the complete response
|
||||
* body, data is HTTP_Request2_Response object</li>
|
||||
* </ul>
|
||||
* Different adapters may not send all the event types. Mock adapter does
|
||||
* not send any events to the observers.
|
||||
*
|
||||
* @return array The array has two keys: 'name' and 'data'
|
||||
*/
|
||||
public function getLastEvent()
|
||||
{
|
||||
return $this->lastEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the adapter used to actually perform the request
|
||||
*
|
||||
* You can pass either an instance of a class implementing HTTP_Request2_Adapter
|
||||
* or a class name. The method will only try to include a file if the class
|
||||
* name starts with HTTP_Request2_Adapter_, it will also try to prepend this
|
||||
* prefix to the class name if it doesn't contain any underscores, so that
|
||||
* <code>
|
||||
* $request->setAdapter('curl');
|
||||
* </code>
|
||||
* will work.
|
||||
*
|
||||
* @param string|HTTP_Request2_Adapter
|
||||
* @return HTTP_Request2
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public function setAdapter($adapter)
|
||||
{
|
||||
if (is_string($adapter)) {
|
||||
if (!class_exists($adapter, false)) {
|
||||
if (false === strpos($adapter, '_')) {
|
||||
$adapter = 'HTTP_Request2_Adapter_' . ucfirst($adapter);
|
||||
}
|
||||
if (preg_match('/^HTTP_Request2_Adapter_([a-zA-Z0-9]+)$/', $adapter)) {
|
||||
include_once str_replace('_', DIRECTORY_SEPARATOR, $adapter) . '.php';
|
||||
}
|
||||
if (!class_exists($adapter, false)) {
|
||||
throw new HTTP_Request2_Exception("Class {$adapter} not found");
|
||||
}
|
||||
}
|
||||
$adapter = new $adapter;
|
||||
}
|
||||
if (!$adapter instanceof HTTP_Request2_Adapter) {
|
||||
throw new HTTP_Request2_Exception('Parameter is not a HTTP request adapter');
|
||||
}
|
||||
$this->adapter = $adapter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the request and returns the response
|
||||
*
|
||||
* @throws HTTP_Request2_Exception
|
||||
* @return HTTP_Request2_Response
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
// Sanity check for URL
|
||||
if (!$this->url instanceof Net_URL2) {
|
||||
throw new HTTP_Request2_Exception('No URL given');
|
||||
} elseif (!$this->url->isAbsolute()) {
|
||||
throw new HTTP_Request2_Exception('Absolute URL required');
|
||||
} elseif (!in_array(strtolower($this->url->getScheme()), array('https', 'http'))) {
|
||||
throw new HTTP_Request2_Exception('Not a HTTP URL');
|
||||
}
|
||||
if (empty($this->adapter)) {
|
||||
$this->setAdapter($this->getConfig('adapter'));
|
||||
}
|
||||
// magic_quotes_runtime may break file uploads and chunked response
|
||||
// processing; see bug #4543. Don't use ini_get() here; see bug #16440.
|
||||
if ($magicQuotes = get_magic_quotes_runtime()) {
|
||||
set_magic_quotes_runtime(false);
|
||||
}
|
||||
// force using single byte encoding if mbstring extension overloads
|
||||
// strlen() and substr(); see bug #1781, bug #10605
|
||||
if (extension_loaded('mbstring') && (2 & ini_get('mbstring.func_overload'))) {
|
||||
$oldEncoding = mb_internal_encoding();
|
||||
mb_internal_encoding('iso-8859-1');
|
||||
}
|
||||
|
||||
try {
|
||||
$response = $this->adapter->sendRequest($this);
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
// cleanup in either case (poor man's "finally" clause)
|
||||
if ($magicQuotes) {
|
||||
set_magic_quotes_runtime(true);
|
||||
}
|
||||
if (!empty($oldEncoding)) {
|
||||
mb_internal_encoding($oldEncoding);
|
||||
}
|
||||
// rethrow the exception
|
||||
if (!empty($e)) {
|
||||
throw $e;
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to detect MIME type of a file
|
||||
*
|
||||
* The method will try to use fileinfo extension if it is available,
|
||||
* deprecated mime_content_type() function in the other case. If neither
|
||||
* works, default 'application/octet-stream' MIME type is returned
|
||||
*
|
||||
* @param string filename
|
||||
* @return string file MIME type
|
||||
*/
|
||||
protected static function detectMimeType($filename)
|
||||
{
|
||||
// finfo extension from PECL available
|
||||
if (function_exists('finfo_open')) {
|
||||
if (!isset(self::$_fileinfoDb)) {
|
||||
self::$_fileinfoDb = @finfo_open(FILEINFO_MIME);
|
||||
}
|
||||
if (self::$_fileinfoDb) {
|
||||
$info = finfo_file(self::$_fileinfoDb, $filename);
|
||||
}
|
||||
}
|
||||
// (deprecated) mime_content_type function available
|
||||
if (empty($info) && function_exists('mime_content_type')) {
|
||||
return mime_content_type($filename);
|
||||
}
|
||||
return empty($info)? 'application/octet-stream': $info;
|
||||
}
|
||||
}
|
||||
?>
|
||||
154
libs/PEAR.1.9/HTTP/Request2/Adapter.php
Normal file
154
libs/PEAR.1.9/HTTP/Request2/Adapter.php
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
<?php
|
||||
/**
|
||||
* Base class for HTTP_Request2 adapters
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2008, 2009, Alexey Borzov <avb@php.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Adapter.php 291118 2009-11-21 17:58:23Z avb $
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class representing a HTTP response
|
||||
*/
|
||||
require_once 'HTTP/Request2/Response.php';
|
||||
|
||||
/**
|
||||
* Base class for HTTP_Request2 adapters
|
||||
*
|
||||
* HTTP_Request2 class itself only defines methods for aggregating the request
|
||||
* data, all actual work of sending the request to the remote server and
|
||||
* receiving its response is performed by adapters.
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 0.5.2
|
||||
*/
|
||||
abstract class HTTP_Request2_Adapter
|
||||
{
|
||||
/**
|
||||
* A list of methods that MUST NOT have a request body, per RFC 2616
|
||||
* @var array
|
||||
*/
|
||||
protected static $bodyDisallowed = array('TRACE');
|
||||
|
||||
/**
|
||||
* Methods having defined semantics for request body
|
||||
*
|
||||
* Content-Length header (indicating that the body follows, section 4.3 of
|
||||
* RFC 2616) will be sent for these methods even if no body was added
|
||||
*
|
||||
* @var array
|
||||
* @link http://pear.php.net/bugs/bug.php?id=12900
|
||||
* @link http://pear.php.net/bugs/bug.php?id=14740
|
||||
*/
|
||||
protected static $bodyRequired = array('POST', 'PUT');
|
||||
|
||||
/**
|
||||
* Request being sent
|
||||
* @var HTTP_Request2
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Request body
|
||||
* @var string|resource|HTTP_Request2_MultipartBody
|
||||
* @see HTTP_Request2::getBody()
|
||||
*/
|
||||
protected $requestBody;
|
||||
|
||||
/**
|
||||
* Length of the request body
|
||||
* @var integer
|
||||
*/
|
||||
protected $contentLength;
|
||||
|
||||
/**
|
||||
* Sends request to the remote server and returns its response
|
||||
*
|
||||
* @param HTTP_Request2
|
||||
* @return HTTP_Request2_Response
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
abstract public function sendRequest(HTTP_Request2 $request);
|
||||
|
||||
/**
|
||||
* Calculates length of the request body, adds proper headers
|
||||
*
|
||||
* @param array associative array of request headers, this method will
|
||||
* add proper 'Content-Length' and 'Content-Type' headers
|
||||
* to this array (or remove them if not needed)
|
||||
*/
|
||||
protected function calculateRequestLength(&$headers)
|
||||
{
|
||||
$this->requestBody = $this->request->getBody();
|
||||
|
||||
if (is_string($this->requestBody)) {
|
||||
$this->contentLength = strlen($this->requestBody);
|
||||
} elseif (is_resource($this->requestBody)) {
|
||||
$stat = fstat($this->requestBody);
|
||||
$this->contentLength = $stat['size'];
|
||||
rewind($this->requestBody);
|
||||
} else {
|
||||
$this->contentLength = $this->requestBody->getLength();
|
||||
$headers['content-type'] = 'multipart/form-data; boundary=' .
|
||||
$this->requestBody->getBoundary();
|
||||
$this->requestBody->rewind();
|
||||
}
|
||||
|
||||
if (in_array($this->request->getMethod(), self::$bodyDisallowed) ||
|
||||
0 == $this->contentLength
|
||||
) {
|
||||
// No body: send a Content-Length header nonetheless (request #12900),
|
||||
// but do that only for methods that require a body (bug #14740)
|
||||
if (in_array($this->request->getMethod(), self::$bodyRequired)) {
|
||||
$headers['content-length'] = 0;
|
||||
} else {
|
||||
unset($headers['content-length']);
|
||||
// if the method doesn't require a body and doesn't have a
|
||||
// body, don't send a Content-Type header. (request #16799)
|
||||
unset($headers['content-type']);
|
||||
}
|
||||
} else {
|
||||
if (empty($headers['content-type'])) {
|
||||
$headers['content-type'] = 'application/x-www-form-urlencoded';
|
||||
}
|
||||
$headers['content-length'] = $this->contentLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
461
libs/PEAR.1.9/HTTP/Request2/Adapter/Curl.php
Normal file
461
libs/PEAR.1.9/HTTP/Request2/Adapter/Curl.php
Normal file
|
|
@ -0,0 +1,461 @@
|
|||
<?php
|
||||
/**
|
||||
* Adapter for HTTP_Request2 wrapping around cURL extension
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2008, 2009, Alexey Borzov <avb@php.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Curl.php 291118 2009-11-21 17:58:23Z avb $
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTTP_Request2 adapters
|
||||
*/
|
||||
require_once 'HTTP/Request2/Adapter.php';
|
||||
|
||||
/**
|
||||
* Adapter for HTTP_Request2 wrapping around cURL extension
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 0.5.2
|
||||
*/
|
||||
class HTTP_Request2_Adapter_Curl extends HTTP_Request2_Adapter
|
||||
{
|
||||
/**
|
||||
* Mapping of header names to cURL options
|
||||
* @var array
|
||||
*/
|
||||
protected static $headerMap = array(
|
||||
'accept-encoding' => CURLOPT_ENCODING,
|
||||
'cookie' => CURLOPT_COOKIE,
|
||||
'referer' => CURLOPT_REFERER,
|
||||
'user-agent' => CURLOPT_USERAGENT
|
||||
);
|
||||
|
||||
/**
|
||||
* Mapping of SSL context options to cURL options
|
||||
* @var array
|
||||
*/
|
||||
protected static $sslContextMap = array(
|
||||
'ssl_verify_peer' => CURLOPT_SSL_VERIFYPEER,
|
||||
'ssl_cafile' => CURLOPT_CAINFO,
|
||||
'ssl_capath' => CURLOPT_CAPATH,
|
||||
'ssl_local_cert' => CURLOPT_SSLCERT,
|
||||
'ssl_passphrase' => CURLOPT_SSLCERTPASSWD
|
||||
);
|
||||
|
||||
/**
|
||||
* Response being received
|
||||
* @var HTTP_Request2_Response
|
||||
*/
|
||||
protected $response;
|
||||
|
||||
/**
|
||||
* Whether 'sentHeaders' event was sent to observers
|
||||
* @var boolean
|
||||
*/
|
||||
protected $eventSentHeaders = false;
|
||||
|
||||
/**
|
||||
* Whether 'receivedHeaders' event was sent to observers
|
||||
* @var boolean
|
||||
*/
|
||||
protected $eventReceivedHeaders = false;
|
||||
|
||||
/**
|
||||
* Position within request body
|
||||
* @var integer
|
||||
* @see callbackReadBody()
|
||||
*/
|
||||
protected $position = 0;
|
||||
|
||||
/**
|
||||
* Information about last transfer, as returned by curl_getinfo()
|
||||
* @var array
|
||||
*/
|
||||
protected $lastInfo;
|
||||
|
||||
/**
|
||||
* Sends request to the remote server and returns its response
|
||||
*
|
||||
* @param HTTP_Request2
|
||||
* @return HTTP_Request2_Response
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public function sendRequest(HTTP_Request2 $request)
|
||||
{
|
||||
if (!extension_loaded('curl')) {
|
||||
throw new HTTP_Request2_Exception('cURL extension not available');
|
||||
}
|
||||
|
||||
$this->request = $request;
|
||||
$this->response = null;
|
||||
$this->position = 0;
|
||||
$this->eventSentHeaders = false;
|
||||
$this->eventReceivedHeaders = false;
|
||||
|
||||
try {
|
||||
if (false === curl_exec($ch = $this->createCurlHandle())) {
|
||||
$errorMessage = 'Error sending request: #' . curl_errno($ch) .
|
||||
' ' . curl_error($ch);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
$this->lastInfo = curl_getinfo($ch);
|
||||
curl_close($ch);
|
||||
|
||||
$response = $this->response;
|
||||
unset($this->request, $this->requestBody, $this->response);
|
||||
|
||||
if (!empty($e)) {
|
||||
throw $e;
|
||||
} elseif (!empty($errorMessage)) {
|
||||
throw new HTTP_Request2_Exception($errorMessage);
|
||||
}
|
||||
|
||||
if (0 < $this->lastInfo['size_download']) {
|
||||
$request->setLastEvent('receivedBody', $response);
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about last transfer
|
||||
*
|
||||
* @return array associative array as returned by curl_getinfo()
|
||||
*/
|
||||
public function getInfo()
|
||||
{
|
||||
return $this->lastInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new cURL handle and populates it with data from the request
|
||||
*
|
||||
* @return resource a cURL handle, as created by curl_init()
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
protected function createCurlHandle()
|
||||
{
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt_array($ch, array(
|
||||
// setup write callbacks
|
||||
CURLOPT_HEADERFUNCTION => array($this, 'callbackWriteHeader'),
|
||||
CURLOPT_WRITEFUNCTION => array($this, 'callbackWriteBody'),
|
||||
// buffer size
|
||||
CURLOPT_BUFFERSIZE => $this->request->getConfig('buffer_size'),
|
||||
// connection timeout
|
||||
CURLOPT_CONNECTTIMEOUT => $this->request->getConfig('connect_timeout'),
|
||||
// save full outgoing headers, in case someone is interested
|
||||
CURLINFO_HEADER_OUT => true,
|
||||
// request url
|
||||
CURLOPT_URL => $this->request->getUrl()->getUrl()
|
||||
));
|
||||
|
||||
// set up redirects
|
||||
if (!$this->request->getConfig('follow_redirects')) {
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
|
||||
} else {
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
curl_setopt($ch, CURLOPT_MAXREDIRS, $this->request->getConfig('max_redirects'));
|
||||
// limit redirects to http(s), works in 5.2.10+
|
||||
if (defined('CURLOPT_REDIR_PROTOCOLS')) {
|
||||
curl_setopt($ch, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
|
||||
}
|
||||
// works sometime after 5.3.0, http://bugs.php.net/bug.php?id=49571
|
||||
if ($this->request->getConfig('strict_redirects') && defined('CURLOPT_POSTREDIR ')) {
|
||||
curl_setopt($ch, CURLOPT_POSTREDIR, 3);
|
||||
}
|
||||
}
|
||||
|
||||
// request timeout
|
||||
if ($timeout = $this->request->getConfig('timeout')) {
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
}
|
||||
|
||||
// set HTTP version
|
||||
switch ($this->request->getConfig('protocol_version')) {
|
||||
case '1.0':
|
||||
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
|
||||
break;
|
||||
case '1.1':
|
||||
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
|
||||
}
|
||||
|
||||
// set request method
|
||||
switch ($this->request->getMethod()) {
|
||||
case HTTP_Request2::METHOD_GET:
|
||||
curl_setopt($ch, CURLOPT_HTTPGET, true);
|
||||
break;
|
||||
case HTTP_Request2::METHOD_POST:
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
break;
|
||||
case HTTP_Request2::METHOD_HEAD:
|
||||
curl_setopt($ch, CURLOPT_NOBODY, true);
|
||||
break;
|
||||
default:
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->request->getMethod());
|
||||
}
|
||||
|
||||
// set proxy, if needed
|
||||
if ($host = $this->request->getConfig('proxy_host')) {
|
||||
if (!($port = $this->request->getConfig('proxy_port'))) {
|
||||
throw new HTTP_Request2_Exception('Proxy port not provided');
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_PROXY, $host . ':' . $port);
|
||||
if ($user = $this->request->getConfig('proxy_user')) {
|
||||
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $user . ':' .
|
||||
$this->request->getConfig('proxy_password'));
|
||||
switch ($this->request->getConfig('proxy_auth_scheme')) {
|
||||
case HTTP_Request2::AUTH_BASIC:
|
||||
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
|
||||
break;
|
||||
case HTTP_Request2::AUTH_DIGEST:
|
||||
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_DIGEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set authentication data
|
||||
if ($auth = $this->request->getAuth()) {
|
||||
curl_setopt($ch, CURLOPT_USERPWD, $auth['user'] . ':' . $auth['password']);
|
||||
switch ($auth['scheme']) {
|
||||
case HTTP_Request2::AUTH_BASIC:
|
||||
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
||||
break;
|
||||
case HTTP_Request2::AUTH_DIGEST:
|
||||
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
|
||||
}
|
||||
}
|
||||
|
||||
// set SSL options
|
||||
if (0 == strcasecmp($this->request->getUrl()->getScheme(), 'https')) {
|
||||
foreach ($this->request->getConfig() as $name => $value) {
|
||||
if ('ssl_verify_host' == $name && null !== $value) {
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $value? 2: 0);
|
||||
} elseif (isset(self::$sslContextMap[$name]) && null !== $value) {
|
||||
curl_setopt($ch, self::$sslContextMap[$name], $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$headers = $this->request->getHeaders();
|
||||
// make cURL automagically send proper header
|
||||
if (!isset($headers['accept-encoding'])) {
|
||||
$headers['accept-encoding'] = '';
|
||||
}
|
||||
|
||||
// set headers having special cURL keys
|
||||
foreach (self::$headerMap as $name => $option) {
|
||||
if (isset($headers[$name])) {
|
||||
curl_setopt($ch, $option, $headers[$name]);
|
||||
unset($headers[$name]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->calculateRequestLength($headers);
|
||||
if (isset($headers['content-length'])) {
|
||||
$this->workaroundPhpBug47204($ch, $headers);
|
||||
}
|
||||
|
||||
// set headers not having special keys
|
||||
$headersFmt = array();
|
||||
foreach ($headers as $name => $value) {
|
||||
$canonicalName = implode('-', array_map('ucfirst', explode('-', $name)));
|
||||
$headersFmt[] = $canonicalName . ': ' . $value;
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headersFmt);
|
||||
|
||||
return $ch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Workaround for PHP bug #47204 that prevents rewinding request body
|
||||
*
|
||||
* The workaround consists of reading the entire request body into memory
|
||||
* and setting it as CURLOPT_POSTFIELDS, so it isn't recommended for large
|
||||
* file uploads, use Socket adapter instead.
|
||||
*
|
||||
* @param resource cURL handle
|
||||
* @param array Request headers
|
||||
*/
|
||||
protected function workaroundPhpBug47204($ch, &$headers)
|
||||
{
|
||||
// no redirects, no digest auth -> probably no rewind needed
|
||||
if (!$this->request->getConfig('follow_redirects')
|
||||
&& (!($auth = $this->request->getAuth())
|
||||
|| HTTP_Request2::AUTH_DIGEST != $auth['scheme'])
|
||||
) {
|
||||
curl_setopt($ch, CURLOPT_READFUNCTION, array($this, 'callbackReadBody'));
|
||||
|
||||
// rewind may be needed, read the whole body into memory
|
||||
} else {
|
||||
if ($this->requestBody instanceof HTTP_Request2_MultipartBody) {
|
||||
$this->requestBody = $this->requestBody->__toString();
|
||||
|
||||
} elseif (is_resource($this->requestBody)) {
|
||||
$fp = $this->requestBody;
|
||||
$this->requestBody = '';
|
||||
while (!feof($fp)) {
|
||||
$this->requestBody .= fread($fp, 16384);
|
||||
}
|
||||
}
|
||||
// curl hangs up if content-length is present
|
||||
unset($headers['content-length']);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->requestBody);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback function called by cURL for reading the request body
|
||||
*
|
||||
* @param resource cURL handle
|
||||
* @param resource file descriptor (not used)
|
||||
* @param integer maximum length of data to return
|
||||
* @return string part of the request body, up to $length bytes
|
||||
*/
|
||||
protected function callbackReadBody($ch, $fd, $length)
|
||||
{
|
||||
if (!$this->eventSentHeaders) {
|
||||
$this->request->setLastEvent(
|
||||
'sentHeaders', curl_getinfo($ch, CURLINFO_HEADER_OUT)
|
||||
);
|
||||
$this->eventSentHeaders = true;
|
||||
}
|
||||
if (in_array($this->request->getMethod(), self::$bodyDisallowed) ||
|
||||
0 == $this->contentLength || $this->position >= $this->contentLength
|
||||
) {
|
||||
return '';
|
||||
}
|
||||
if (is_string($this->requestBody)) {
|
||||
$string = substr($this->requestBody, $this->position, $length);
|
||||
} elseif (is_resource($this->requestBody)) {
|
||||
$string = fread($this->requestBody, $length);
|
||||
} else {
|
||||
$string = $this->requestBody->read($length);
|
||||
}
|
||||
$this->request->setLastEvent('sentBodyPart', strlen($string));
|
||||
$this->position += strlen($string);
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback function called by cURL for saving the response headers
|
||||
*
|
||||
* @param resource cURL handle
|
||||
* @param string response header (with trailing CRLF)
|
||||
* @return integer number of bytes saved
|
||||
* @see HTTP_Request2_Response::parseHeaderLine()
|
||||
*/
|
||||
protected function callbackWriteHeader($ch, $string)
|
||||
{
|
||||
// we may receive a second set of headers if doing e.g. digest auth
|
||||
if ($this->eventReceivedHeaders || !$this->eventSentHeaders) {
|
||||
// don't bother with 100-Continue responses (bug #15785)
|
||||
if (!$this->eventSentHeaders ||
|
||||
$this->response->getStatus() >= 200
|
||||
) {
|
||||
$this->request->setLastEvent(
|
||||
'sentHeaders', curl_getinfo($ch, CURLINFO_HEADER_OUT)
|
||||
);
|
||||
}
|
||||
$upload = curl_getinfo($ch, CURLINFO_SIZE_UPLOAD);
|
||||
// if body wasn't read by a callback, send event with total body size
|
||||
if ($upload > $this->position) {
|
||||
$this->request->setLastEvent(
|
||||
'sentBodyPart', $upload - $this->position
|
||||
);
|
||||
$this->position = $upload;
|
||||
}
|
||||
$this->eventSentHeaders = true;
|
||||
// we'll need a new response object
|
||||
if ($this->eventReceivedHeaders) {
|
||||
$this->eventReceivedHeaders = false;
|
||||
$this->response = null;
|
||||
}
|
||||
}
|
||||
if (empty($this->response)) {
|
||||
$this->response = new HTTP_Request2_Response($string, false);
|
||||
} else {
|
||||
$this->response->parseHeaderLine($string);
|
||||
if ('' == trim($string)) {
|
||||
// don't bother with 100-Continue responses (bug #15785)
|
||||
if (200 <= $this->response->getStatus()) {
|
||||
$this->request->setLastEvent('receivedHeaders', $this->response);
|
||||
}
|
||||
// for versions lower than 5.2.10, check the redirection URL protocol
|
||||
if ($this->request->getConfig('follow_redirects') && !defined('CURLOPT_REDIR_PROTOCOLS')
|
||||
&& $this->response->isRedirect()
|
||||
) {
|
||||
$redirectUrl = new Net_URL2($this->response->getHeader('location'));
|
||||
if ($redirectUrl->isAbsolute()
|
||||
&& !in_array($redirectUrl->getScheme(), array('http', 'https'))
|
||||
) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
$this->eventReceivedHeaders = true;
|
||||
}
|
||||
}
|
||||
return strlen($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback function called by cURL for saving the response body
|
||||
*
|
||||
* @param resource cURL handle (not used)
|
||||
* @param string part of the response body
|
||||
* @return integer number of bytes saved
|
||||
* @see HTTP_Request2_Response::appendBody()
|
||||
*/
|
||||
protected function callbackWriteBody($ch, $string)
|
||||
{
|
||||
// cURL calls WRITEFUNCTION callback without calling HEADERFUNCTION if
|
||||
// response doesn't start with proper HTTP status line (see bug #15716)
|
||||
if (empty($this->response)) {
|
||||
throw new HTTP_Request2_Exception("Malformed response: {$string}");
|
||||
}
|
||||
if ($this->request->getConfig('store_body')) {
|
||||
$this->response->appendBody($string);
|
||||
}
|
||||
$this->request->setLastEvent('receivedBodyPart', $string);
|
||||
return strlen($string);
|
||||
}
|
||||
}
|
||||
?>
|
||||
171
libs/PEAR.1.9/HTTP/Request2/Adapter/Mock.php
Normal file
171
libs/PEAR.1.9/HTTP/Request2/Adapter/Mock.php
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
<?php
|
||||
/**
|
||||
* Mock adapter intended for testing
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2008, 2009, Alexey Borzov <avb@php.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Mock.php 290192 2009-11-03 21:29:32Z avb $
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTTP_Request2 adapters
|
||||
*/
|
||||
require_once 'HTTP/Request2/Adapter.php';
|
||||
|
||||
/**
|
||||
* Mock adapter intended for testing
|
||||
*
|
||||
* Can be used to test applications depending on HTTP_Request2 package without
|
||||
* actually performing any HTTP requests. This adapter will return responses
|
||||
* previously added via addResponse()
|
||||
* <code>
|
||||
* $mock = new HTTP_Request2_Adapter_Mock();
|
||||
* $mock->addResponse("HTTP/1.1 ... ");
|
||||
*
|
||||
* $request = new HTTP_Request2();
|
||||
* $request->setAdapter($mock);
|
||||
*
|
||||
* // This will return the response set above
|
||||
* $response = $req->send();
|
||||
* </code>
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 0.5.2
|
||||
*/
|
||||
class HTTP_Request2_Adapter_Mock extends HTTP_Request2_Adapter
|
||||
{
|
||||
/**
|
||||
* A queue of responses to be returned by sendRequest()
|
||||
* @var array
|
||||
*/
|
||||
protected $responses = array();
|
||||
|
||||
/**
|
||||
* Returns the next response from the queue built by addResponse()
|
||||
*
|
||||
* If the queue is empty it will return default empty response with status 400,
|
||||
* if an Exception object was added to the queue it will be thrown.
|
||||
*
|
||||
* @param HTTP_Request2
|
||||
* @return HTTP_Request2_Response
|
||||
* @throws Exception
|
||||
*/
|
||||
public function sendRequest(HTTP_Request2 $request)
|
||||
{
|
||||
if (count($this->responses) > 0) {
|
||||
$response = array_shift($this->responses);
|
||||
if ($response instanceof HTTP_Request2_Response) {
|
||||
return $response;
|
||||
} else {
|
||||
// rethrow the exception
|
||||
$class = get_class($response);
|
||||
$message = $response->getMessage();
|
||||
$code = $response->getCode();
|
||||
throw new $class($message, $code);
|
||||
}
|
||||
} else {
|
||||
return self::createResponseFromString("HTTP/1.1 400 Bad Request\r\n\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds response to the queue
|
||||
*
|
||||
* @param mixed either a string, a pointer to an open file,
|
||||
* an instance of HTTP_Request2_Response or Exception
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public function addResponse($response)
|
||||
{
|
||||
if (is_string($response)) {
|
||||
$response = self::createResponseFromString($response);
|
||||
} elseif (is_resource($response)) {
|
||||
$response = self::createResponseFromFile($response);
|
||||
} elseif (!$response instanceof HTTP_Request2_Response &&
|
||||
!$response instanceof Exception
|
||||
) {
|
||||
throw new HTTP_Request2_Exception('Parameter is not a valid response');
|
||||
}
|
||||
$this->responses[] = $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new HTTP_Request2_Response object from a string
|
||||
*
|
||||
* @param string
|
||||
* @return HTTP_Request2_Response
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public static function createResponseFromString($str)
|
||||
{
|
||||
$parts = preg_split('!(\r?\n){2}!m', $str, 2);
|
||||
$headerLines = explode("\n", $parts[0]);
|
||||
$response = new HTTP_Request2_Response(array_shift($headerLines));
|
||||
foreach ($headerLines as $headerLine) {
|
||||
$response->parseHeaderLine($headerLine);
|
||||
}
|
||||
$response->parseHeaderLine('');
|
||||
if (isset($parts[1])) {
|
||||
$response->appendBody($parts[1]);
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new HTTP_Request2_Response object from a file
|
||||
*
|
||||
* @param resource file pointer returned by fopen()
|
||||
* @return HTTP_Request2_Response
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public static function createResponseFromFile($fp)
|
||||
{
|
||||
$response = new HTTP_Request2_Response(fgets($fp));
|
||||
do {
|
||||
$headerLine = fgets($fp);
|
||||
$response->parseHeaderLine($headerLine);
|
||||
} while ('' != trim($headerLine));
|
||||
|
||||
while (!feof($fp)) {
|
||||
$response->appendBody(fread($fp, 8192));
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
?>
|
||||
1046
libs/PEAR.1.9/HTTP/Request2/Adapter/Socket.php
Normal file
1046
libs/PEAR.1.9/HTTP/Request2/Adapter/Socket.php
Normal file
File diff suppressed because it is too large
Load diff
62
libs/PEAR.1.9/HTTP/Request2/Exception.php
Normal file
62
libs/PEAR.1.9/HTTP/Request2/Exception.php
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
/**
|
||||
* Exception class for HTTP_Request2 package
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2008, 2009, Alexey Borzov <avb@php.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Exception.php 290192 2009-11-03 21:29:32Z avb $
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for exceptions in PEAR
|
||||
*/
|
||||
require_once 'PEAR/Exception.php';
|
||||
|
||||
/**
|
||||
* Exception class for HTTP_Request2 package
|
||||
*
|
||||
* Such a class is required by the Exception RFC:
|
||||
* http://pear.php.net/pepr/pepr-proposal-show.php?id=132
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @version Release: 0.5.2
|
||||
*/
|
||||
class HTTP_Request2_Exception extends PEAR_Exception
|
||||
{
|
||||
}
|
||||
?>
|
||||
274
libs/PEAR.1.9/HTTP/Request2/MultipartBody.php
Normal file
274
libs/PEAR.1.9/HTTP/Request2/MultipartBody.php
Normal file
|
|
@ -0,0 +1,274 @@
|
|||
<?php
|
||||
/**
|
||||
* Helper class for building multipart/form-data request body
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2008, 2009, Alexey Borzov <avb@php.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: MultipartBody.php 290192 2009-11-03 21:29:32Z avb $
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class for building multipart/form-data request body
|
||||
*
|
||||
* The class helps to reduce memory consumption by streaming large file uploads
|
||||
* from disk, it also allows monitoring of upload progress (see request #7630)
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 0.5.2
|
||||
* @link http://tools.ietf.org/html/rfc1867
|
||||
*/
|
||||
class HTTP_Request2_MultipartBody
|
||||
{
|
||||
/**
|
||||
* MIME boundary
|
||||
* @var string
|
||||
*/
|
||||
private $_boundary;
|
||||
|
||||
/**
|
||||
* Form parameters added via {@link HTTP_Request2::addPostParameter()}
|
||||
* @var array
|
||||
*/
|
||||
private $_params = array();
|
||||
|
||||
/**
|
||||
* File uploads added via {@link HTTP_Request2::addUpload()}
|
||||
* @var array
|
||||
*/
|
||||
private $_uploads = array();
|
||||
|
||||
/**
|
||||
* Header for parts with parameters
|
||||
* @var string
|
||||
*/
|
||||
private $_headerParam = "--%s\r\nContent-Disposition: form-data; name=\"%s\"\r\n\r\n";
|
||||
|
||||
/**
|
||||
* Header for parts with uploads
|
||||
* @var string
|
||||
*/
|
||||
private $_headerUpload = "--%s\r\nContent-Disposition: form-data; name=\"%s\"; filename=\"%s\"\r\nContent-Type: %s\r\n\r\n";
|
||||
|
||||
/**
|
||||
* Current position in parameter and upload arrays
|
||||
*
|
||||
* First number is index of "current" part, second number is position within
|
||||
* "current" part
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_pos = array(0, 0);
|
||||
|
||||
|
||||
/**
|
||||
* Constructor. Sets the arrays with POST data.
|
||||
*
|
||||
* @param array values of form fields set via {@link HTTP_Request2::addPostParameter()}
|
||||
* @param array file uploads set via {@link HTTP_Request2::addUpload()}
|
||||
* @param bool whether to append brackets to array variable names
|
||||
*/
|
||||
public function __construct(array $params, array $uploads, $useBrackets = true)
|
||||
{
|
||||
$this->_params = self::_flattenArray('', $params, $useBrackets);
|
||||
foreach ($uploads as $fieldName => $f) {
|
||||
if (!is_array($f['fp'])) {
|
||||
$this->_uploads[] = $f + array('name' => $fieldName);
|
||||
} else {
|
||||
for ($i = 0; $i < count($f['fp']); $i++) {
|
||||
$upload = array(
|
||||
'name' => ($useBrackets? $fieldName . '[' . $i . ']': $fieldName)
|
||||
);
|
||||
foreach (array('fp', 'filename', 'size', 'type') as $key) {
|
||||
$upload[$key] = $f[$key][$i];
|
||||
}
|
||||
$this->_uploads[] = $upload;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length of the body to use in Content-Length header
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getLength()
|
||||
{
|
||||
$boundaryLength = strlen($this->getBoundary());
|
||||
$headerParamLength = strlen($this->_headerParam) - 4 + $boundaryLength;
|
||||
$headerUploadLength = strlen($this->_headerUpload) - 8 + $boundaryLength;
|
||||
$length = $boundaryLength + 6;
|
||||
foreach ($this->_params as $p) {
|
||||
$length += $headerParamLength + strlen($p[0]) + strlen($p[1]) + 2;
|
||||
}
|
||||
foreach ($this->_uploads as $u) {
|
||||
$length += $headerUploadLength + strlen($u['name']) + strlen($u['type']) +
|
||||
strlen($u['filename']) + $u['size'] + 2;
|
||||
}
|
||||
return $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the boundary to use in Content-Type header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBoundary()
|
||||
{
|
||||
if (empty($this->_boundary)) {
|
||||
$this->_boundary = '--' . md5('PEAR-HTTP_Request2-' . microtime());
|
||||
}
|
||||
return $this->_boundary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns next chunk of request body
|
||||
*
|
||||
* @param integer Amount of bytes to read
|
||||
* @return string Up to $length bytes of data, empty string if at end
|
||||
*/
|
||||
public function read($length)
|
||||
{
|
||||
$ret = '';
|
||||
$boundary = $this->getBoundary();
|
||||
$paramCount = count($this->_params);
|
||||
$uploadCount = count($this->_uploads);
|
||||
while ($length > 0 && $this->_pos[0] <= $paramCount + $uploadCount) {
|
||||
$oldLength = $length;
|
||||
if ($this->_pos[0] < $paramCount) {
|
||||
$param = sprintf($this->_headerParam, $boundary,
|
||||
$this->_params[$this->_pos[0]][0]) .
|
||||
$this->_params[$this->_pos[0]][1] . "\r\n";
|
||||
$ret .= substr($param, $this->_pos[1], $length);
|
||||
$length -= min(strlen($param) - $this->_pos[1], $length);
|
||||
|
||||
} elseif ($this->_pos[0] < $paramCount + $uploadCount) {
|
||||
$pos = $this->_pos[0] - $paramCount;
|
||||
$header = sprintf($this->_headerUpload, $boundary,
|
||||
$this->_uploads[$pos]['name'],
|
||||
$this->_uploads[$pos]['filename'],
|
||||
$this->_uploads[$pos]['type']);
|
||||
if ($this->_pos[1] < strlen($header)) {
|
||||
$ret .= substr($header, $this->_pos[1], $length);
|
||||
$length -= min(strlen($header) - $this->_pos[1], $length);
|
||||
}
|
||||
$filePos = max(0, $this->_pos[1] - strlen($header));
|
||||
if ($length > 0 && $filePos < $this->_uploads[$pos]['size']) {
|
||||
$ret .= fread($this->_uploads[$pos]['fp'], $length);
|
||||
$length -= min($length, $this->_uploads[$pos]['size'] - $filePos);
|
||||
}
|
||||
if ($length > 0) {
|
||||
$start = $this->_pos[1] + ($oldLength - $length) -
|
||||
strlen($header) - $this->_uploads[$pos]['size'];
|
||||
$ret .= substr("\r\n", $start, $length);
|
||||
$length -= min(2 - $start, $length);
|
||||
}
|
||||
|
||||
} else {
|
||||
$closing = '--' . $boundary . "--\r\n";
|
||||
$ret .= substr($closing, $this->_pos[1], $length);
|
||||
$length -= min(strlen($closing) - $this->_pos[1], $length);
|
||||
}
|
||||
if ($length > 0) {
|
||||
$this->_pos = array($this->_pos[0] + 1, 0);
|
||||
} else {
|
||||
$this->_pos[1] += $oldLength;
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current position to the start of the body
|
||||
*
|
||||
* This allows reusing the same body in another request
|
||||
*/
|
||||
public function rewind()
|
||||
{
|
||||
$this->_pos = array(0, 0);
|
||||
foreach ($this->_uploads as $u) {
|
||||
rewind($u['fp']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the body as string
|
||||
*
|
||||
* Note that it reads all file uploads into memory so it is a good idea not
|
||||
* to use this method with large file uploads and rely on read() instead.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$this->rewind();
|
||||
return $this->read($this->getLength());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper function to change the (probably multidimensional) associative array
|
||||
* into the simple one.
|
||||
*
|
||||
* @param string name for item
|
||||
* @param mixed item's values
|
||||
* @param bool whether to append [] to array variables' names
|
||||
* @return array array with the following items: array('item name', 'item value');
|
||||
*/
|
||||
private static function _flattenArray($name, $values, $useBrackets)
|
||||
{
|
||||
if (!is_array($values)) {
|
||||
return array(array($name, $values));
|
||||
} else {
|
||||
$ret = array();
|
||||
foreach ($values as $k => $v) {
|
||||
if (empty($name)) {
|
||||
$newName = $k;
|
||||
} elseif ($useBrackets) {
|
||||
$newName = $name . '[' . $k . ']';
|
||||
} else {
|
||||
$newName = $name;
|
||||
}
|
||||
$ret = array_merge($ret, self::_flattenArray($newName, $v, $useBrackets));
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
215
libs/PEAR.1.9/HTTP/Request2/Observer/Log.php
Normal file
215
libs/PEAR.1.9/HTTP/Request2/Observer/Log.php
Normal file
|
|
@ -0,0 +1,215 @@
|
|||
<?php
|
||||
/**
|
||||
* An observer useful for debugging / testing.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2008, 2009, Alexey Borzov <avb@php.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author David Jean Louis <izi@php.net>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Log.php 293416 2010-01-11 18:06:15Z avb $
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exception class for HTTP_Request2 package
|
||||
*/
|
||||
require_once 'HTTP/Request2/Exception.php';
|
||||
|
||||
/**
|
||||
* A debug observer useful for debugging / testing.
|
||||
*
|
||||
* This observer logs to a log target data corresponding to the various request
|
||||
* and response events, it logs by default to php://output but can be configured
|
||||
* to log to a file or via the PEAR Log package.
|
||||
*
|
||||
* A simple example:
|
||||
* <code>
|
||||
* require_once 'HTTP/Request2.php';
|
||||
* require_once 'HTTP/Request2/Observer/Log.php';
|
||||
*
|
||||
* $request = new HTTP_Request2('http://www.example.com');
|
||||
* $observer = new HTTP_Request2_Observer_Log();
|
||||
* $request->attach($observer);
|
||||
* $request->send();
|
||||
* </code>
|
||||
*
|
||||
* A more complex example with PEAR Log:
|
||||
* <code>
|
||||
* require_once 'HTTP/Request2.php';
|
||||
* require_once 'HTTP/Request2/Observer/Log.php';
|
||||
* require_once 'Log.php';
|
||||
*
|
||||
* $request = new HTTP_Request2('http://www.example.com');
|
||||
* // we want to log with PEAR log
|
||||
* $observer = new HTTP_Request2_Observer_Log(Log::factory('console'));
|
||||
*
|
||||
* // we only want to log received headers
|
||||
* $observer->events = array('receivedHeaders');
|
||||
*
|
||||
* $request->attach($observer);
|
||||
* $request->send();
|
||||
* </code>
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author David Jean Louis <izi@php.net>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version Release: 0.5.2
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
class HTTP_Request2_Observer_Log implements SplObserver
|
||||
{
|
||||
// properties {{{
|
||||
|
||||
/**
|
||||
* The log target, it can be a a resource or a PEAR Log instance.
|
||||
*
|
||||
* @var resource|Log $target
|
||||
*/
|
||||
protected $target = null;
|
||||
|
||||
/**
|
||||
* The events to log.
|
||||
*
|
||||
* @var array $events
|
||||
*/
|
||||
public $events = array(
|
||||
'connect',
|
||||
'sentHeaders',
|
||||
'sentBodyPart',
|
||||
'receivedHeaders',
|
||||
'receivedBody',
|
||||
'disconnect',
|
||||
);
|
||||
|
||||
// }}}
|
||||
// __construct() {{{
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param mixed $target Can be a file path (default: php://output), a resource,
|
||||
* or an instance of the PEAR Log class.
|
||||
* @param array $events Array of events to listen to (default: all events)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($target = 'php://output', array $events = array())
|
||||
{
|
||||
if (!empty($events)) {
|
||||
$this->events = $events;
|
||||
}
|
||||
if (is_resource($target) || $target instanceof Log) {
|
||||
$this->target = $target;
|
||||
} elseif (false === ($this->target = @fopen($target, 'ab'))) {
|
||||
throw new HTTP_Request2_Exception("Unable to open '{$target}'");
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// update() {{{
|
||||
|
||||
/**
|
||||
* Called when the request notifies us of an event.
|
||||
*
|
||||
* @param HTTP_Request2 $subject The HTTP_Request2 instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update(SplSubject $subject)
|
||||
{
|
||||
$event = $subject->getLastEvent();
|
||||
if (!in_array($event['name'], $this->events)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch ($event['name']) {
|
||||
case 'connect':
|
||||
$this->log('* Connected to ' . $event['data']);
|
||||
break;
|
||||
case 'sentHeaders':
|
||||
$headers = explode("\r\n", $event['data']);
|
||||
array_pop($headers);
|
||||
foreach ($headers as $header) {
|
||||
$this->log('> ' . $header);
|
||||
}
|
||||
break;
|
||||
case 'sentBodyPart':
|
||||
$this->log('> ' . $event['data'] . ' byte(s) sent');
|
||||
break;
|
||||
case 'receivedHeaders':
|
||||
$this->log(sprintf('< HTTP/%s %s %s',
|
||||
$event['data']->getVersion(),
|
||||
$event['data']->getStatus(),
|
||||
$event['data']->getReasonPhrase()));
|
||||
$headers = $event['data']->getHeader();
|
||||
foreach ($headers as $key => $val) {
|
||||
$this->log('< ' . $key . ': ' . $val);
|
||||
}
|
||||
$this->log('< ');
|
||||
break;
|
||||
case 'receivedBody':
|
||||
$this->log($event['data']->getBody());
|
||||
break;
|
||||
case 'disconnect':
|
||||
$this->log('* Disconnected');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// log() {{{
|
||||
|
||||
/**
|
||||
* Logs the given message to the configured target.
|
||||
*
|
||||
* @param string $message Message to display
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function log($message)
|
||||
{
|
||||
if ($this->target instanceof Log) {
|
||||
$this->target->debug($message);
|
||||
} elseif (is_resource($this->target)) {
|
||||
fwrite($this->target, $message . "\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
?>
|
||||
559
libs/PEAR.1.9/HTTP/Request2/Response.php
Normal file
559
libs/PEAR.1.9/HTTP/Request2/Response.php
Normal file
|
|
@ -0,0 +1,559 @@
|
|||
<?php
|
||||
/**
|
||||
* Class representing a HTTP response
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2008, 2009, Alexey Borzov <avb@php.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The names of the authors may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Response.php 290520 2009-11-11 20:09:42Z avb $
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exception class for HTTP_Request2 package
|
||||
*/
|
||||
require_once 'HTTP/Request2/Exception.php';
|
||||
|
||||
/**
|
||||
* Class representing a HTTP response
|
||||
*
|
||||
* The class is designed to be used in "streaming" scenario, building the
|
||||
* response as it is being received:
|
||||
* <code>
|
||||
* $statusLine = read_status_line();
|
||||
* $response = new HTTP_Request2_Response($statusLine);
|
||||
* do {
|
||||
* $headerLine = read_header_line();
|
||||
* $response->parseHeaderLine($headerLine);
|
||||
* } while ($headerLine != '');
|
||||
*
|
||||
* while ($chunk = read_body()) {
|
||||
* $response->appendBody($chunk);
|
||||
* }
|
||||
*
|
||||
* var_dump($response->getHeader(), $response->getCookies(), $response->getBody());
|
||||
* </code>
|
||||
*
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 0.5.2
|
||||
* @link http://tools.ietf.org/html/rfc2616#section-6
|
||||
*/
|
||||
class HTTP_Request2_Response
|
||||
{
|
||||
/**
|
||||
* HTTP protocol version (e.g. 1.0, 1.1)
|
||||
* @var string
|
||||
*/
|
||||
protected $version;
|
||||
|
||||
/**
|
||||
* Status code
|
||||
* @var integer
|
||||
* @link http://tools.ietf.org/html/rfc2616#section-6.1.1
|
||||
*/
|
||||
protected $code;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
* @var string
|
||||
* @link http://tools.ietf.org/html/rfc2616#section-6.1.1
|
||||
*/
|
||||
protected $reasonPhrase;
|
||||
|
||||
/**
|
||||
* Associative array of response headers
|
||||
* @var array
|
||||
*/
|
||||
protected $headers = array();
|
||||
|
||||
/**
|
||||
* Cookies set in the response
|
||||
* @var array
|
||||
*/
|
||||
protected $cookies = array();
|
||||
|
||||
/**
|
||||
* Name of last header processed by parseHederLine()
|
||||
*
|
||||
* Used to handle the headers that span multiple lines
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $lastHeader = null;
|
||||
|
||||
/**
|
||||
* Response body
|
||||
* @var string
|
||||
*/
|
||||
protected $body = '';
|
||||
|
||||
/**
|
||||
* Whether the body is still encoded by Content-Encoding
|
||||
*
|
||||
* cURL provides the decoded body to the callback; if we are reading from
|
||||
* socket the body is still gzipped / deflated
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $bodyEncoded;
|
||||
|
||||
/**
|
||||
* Associative array of HTTP status code / reason phrase.
|
||||
*
|
||||
* @var array
|
||||
* @link http://tools.ietf.org/html/rfc2616#section-10
|
||||
*/
|
||||
protected static $phrases = array(
|
||||
|
||||
// 1xx: Informational - Request received, continuing process
|
||||
100 => 'Continue',
|
||||
101 => 'Switching Protocols',
|
||||
|
||||
// 2xx: Success - The action was successfully received, understood and
|
||||
// accepted
|
||||
200 => 'OK',
|
||||
201 => 'Created',
|
||||
202 => 'Accepted',
|
||||
203 => 'Non-Authoritative Information',
|
||||
204 => 'No Content',
|
||||
205 => 'Reset Content',
|
||||
206 => 'Partial Content',
|
||||
|
||||
// 3xx: Redirection - Further action must be taken in order to complete
|
||||
// the request
|
||||
300 => 'Multiple Choices',
|
||||
301 => 'Moved Permanently',
|
||||
302 => 'Found', // 1.1
|
||||
303 => 'See Other',
|
||||
304 => 'Not Modified',
|
||||
305 => 'Use Proxy',
|
||||
307 => 'Temporary Redirect',
|
||||
|
||||
// 4xx: Client Error - The request contains bad syntax or cannot be
|
||||
// fulfilled
|
||||
400 => 'Bad Request',
|
||||
401 => 'Unauthorized',
|
||||
402 => 'Payment Required',
|
||||
403 => 'Forbidden',
|
||||
404 => 'Not Found',
|
||||
405 => 'Method Not Allowed',
|
||||
406 => 'Not Acceptable',
|
||||
407 => 'Proxy Authentication Required',
|
||||
408 => 'Request Timeout',
|
||||
409 => 'Conflict',
|
||||
410 => 'Gone',
|
||||
411 => 'Length Required',
|
||||
412 => 'Precondition Failed',
|
||||
413 => 'Request Entity Too Large',
|
||||
414 => 'Request-URI Too Long',
|
||||
415 => 'Unsupported Media Type',
|
||||
416 => 'Requested Range Not Satisfiable',
|
||||
417 => 'Expectation Failed',
|
||||
|
||||
// 5xx: Server Error - The server failed to fulfill an apparently
|
||||
// valid request
|
||||
500 => 'Internal Server Error',
|
||||
501 => 'Not Implemented',
|
||||
502 => 'Bad Gateway',
|
||||
503 => 'Service Unavailable',
|
||||
504 => 'Gateway Timeout',
|
||||
505 => 'HTTP Version Not Supported',
|
||||
509 => 'Bandwidth Limit Exceeded',
|
||||
|
||||
);
|
||||
|
||||
/**
|
||||
* Constructor, parses the response status line
|
||||
*
|
||||
* @param string Response status line (e.g. "HTTP/1.1 200 OK")
|
||||
* @param bool Whether body is still encoded by Content-Encoding
|
||||
* @throws HTTP_Request2_Exception if status line is invalid according to spec
|
||||
*/
|
||||
public function __construct($statusLine, $bodyEncoded = true)
|
||||
{
|
||||
if (!preg_match('!^HTTP/(\d\.\d) (\d{3})(?: (.+))?!', $statusLine, $m)) {
|
||||
throw new HTTP_Request2_Exception("Malformed response: {$statusLine}");
|
||||
}
|
||||
$this->version = $m[1];
|
||||
$this->code = intval($m[2]);
|
||||
if (!empty($m[3])) {
|
||||
$this->reasonPhrase = trim($m[3]);
|
||||
} elseif (!empty(self::$phrases[$this->code])) {
|
||||
$this->reasonPhrase = self::$phrases[$this->code];
|
||||
}
|
||||
$this->bodyEncoded = (bool)$bodyEncoded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the line from HTTP response filling $headers array
|
||||
*
|
||||
* The method should be called after reading the line from socket or receiving
|
||||
* it into cURL callback. Passing an empty string here indicates the end of
|
||||
* response headers and triggers additional processing, so be sure to pass an
|
||||
* empty string in the end.
|
||||
*
|
||||
* @param string Line from HTTP response
|
||||
*/
|
||||
public function parseHeaderLine($headerLine)
|
||||
{
|
||||
$headerLine = trim($headerLine, "\r\n");
|
||||
|
||||
// empty string signals the end of headers, process the received ones
|
||||
if ('' == $headerLine) {
|
||||
if (!empty($this->headers['set-cookie'])) {
|
||||
$cookies = is_array($this->headers['set-cookie'])?
|
||||
$this->headers['set-cookie']:
|
||||
array($this->headers['set-cookie']);
|
||||
foreach ($cookies as $cookieString) {
|
||||
$this->parseCookie($cookieString);
|
||||
}
|
||||
unset($this->headers['set-cookie']);
|
||||
}
|
||||
foreach (array_keys($this->headers) as $k) {
|
||||
if (is_array($this->headers[$k])) {
|
||||
$this->headers[$k] = implode(', ', $this->headers[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
// string of the form header-name: header value
|
||||
} elseif (preg_match('!^([^\x00-\x1f\x7f-\xff()<>@,;:\\\\"/\[\]?={}\s]+):(.+)$!', $headerLine, $m)) {
|
||||
$name = strtolower($m[1]);
|
||||
$value = trim($m[2]);
|
||||
if (empty($this->headers[$name])) {
|
||||
$this->headers[$name] = $value;
|
||||
} else {
|
||||
if (!is_array($this->headers[$name])) {
|
||||
$this->headers[$name] = array($this->headers[$name]);
|
||||
}
|
||||
$this->headers[$name][] = $value;
|
||||
}
|
||||
$this->lastHeader = $name;
|
||||
|
||||
// continuation of a previous header
|
||||
} elseif (preg_match('!^\s+(.+)$!', $headerLine, $m) && $this->lastHeader) {
|
||||
if (!is_array($this->headers[$this->lastHeader])) {
|
||||
$this->headers[$this->lastHeader] .= ' ' . trim($m[1]);
|
||||
} else {
|
||||
$key = count($this->headers[$this->lastHeader]) - 1;
|
||||
$this->headers[$this->lastHeader][$key] .= ' ' . trim($m[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a Set-Cookie header to fill $cookies array
|
||||
*
|
||||
* @param string value of Set-Cookie header
|
||||
* @link http://web.archive.org/web/20080331104521/http://cgi.netscape.com/newsref/std/cookie_spec.html
|
||||
*/
|
||||
protected function parseCookie($cookieString)
|
||||
{
|
||||
$cookie = array(
|
||||
'expires' => null,
|
||||
'domain' => null,
|
||||
'path' => null,
|
||||
'secure' => false
|
||||
);
|
||||
|
||||
// Only a name=value pair
|
||||
if (!strpos($cookieString, ';')) {
|
||||
$pos = strpos($cookieString, '=');
|
||||
$cookie['name'] = trim(substr($cookieString, 0, $pos));
|
||||
$cookie['value'] = trim(substr($cookieString, $pos + 1));
|
||||
|
||||
// Some optional parameters are supplied
|
||||
} else {
|
||||
$elements = explode(';', $cookieString);
|
||||
$pos = strpos($elements[0], '=');
|
||||
$cookie['name'] = trim(substr($elements[0], 0, $pos));
|
||||
$cookie['value'] = trim(substr($elements[0], $pos + 1));
|
||||
|
||||
for ($i = 1; $i < count($elements); $i++) {
|
||||
if (false === strpos($elements[$i], '=')) {
|
||||
$elName = trim($elements[$i]);
|
||||
$elValue = null;
|
||||
} else {
|
||||
list ($elName, $elValue) = array_map('trim', explode('=', $elements[$i]));
|
||||
}
|
||||
$elName = strtolower($elName);
|
||||
if ('secure' == $elName) {
|
||||
$cookie['secure'] = true;
|
||||
} elseif ('expires' == $elName) {
|
||||
$cookie['expires'] = str_replace('"', '', $elValue);
|
||||
} elseif ('path' == $elName || 'domain' == $elName) {
|
||||
$cookie[$elName] = urldecode($elValue);
|
||||
} else {
|
||||
$cookie[$elName] = $elValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->cookies[] = $cookie;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a string to the response body
|
||||
* @param string
|
||||
*/
|
||||
public function appendBody($bodyChunk)
|
||||
{
|
||||
$this->body .= $bodyChunk;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status code
|
||||
* @return integer
|
||||
*/
|
||||
public function getStatus()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the reason phrase
|
||||
* @return string
|
||||
*/
|
||||
public function getReasonPhrase()
|
||||
{
|
||||
return $this->reasonPhrase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether response is a redirect that can be automatically handled by HTTP_Request2
|
||||
* @return bool
|
||||
*/
|
||||
public function isRedirect()
|
||||
{
|
||||
return in_array($this->code, array(300, 301, 302, 303, 307))
|
||||
&& isset($this->headers['location']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns either the named header or all response headers
|
||||
*
|
||||
* @param string Name of header to return
|
||||
* @return string|array Value of $headerName header (null if header is
|
||||
* not present), array of all response headers if
|
||||
* $headerName is null
|
||||
*/
|
||||
public function getHeader($headerName = null)
|
||||
{
|
||||
if (null === $headerName) {
|
||||
return $this->headers;
|
||||
} else {
|
||||
$headerName = strtolower($headerName);
|
||||
return isset($this->headers[$headerName])? $this->headers[$headerName]: null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns cookies set in response
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCookies()
|
||||
{
|
||||
return $this->cookies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the body of the response
|
||||
*
|
||||
* @return string
|
||||
* @throws HTTP_Request2_Exception if body cannot be decoded
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
if (!$this->bodyEncoded ||
|
||||
!in_array(strtolower($this->getHeader('content-encoding')), array('gzip', 'deflate'))
|
||||
) {
|
||||
return $this->body;
|
||||
|
||||
} else {
|
||||
if (extension_loaded('mbstring') && (2 & ini_get('mbstring.func_overload'))) {
|
||||
$oldEncoding = mb_internal_encoding();
|
||||
mb_internal_encoding('iso-8859-1');
|
||||
}
|
||||
|
||||
try {
|
||||
switch (strtolower($this->getHeader('content-encoding'))) {
|
||||
case 'gzip':
|
||||
$decoded = self::decodeGzip($this->body);
|
||||
break;
|
||||
case 'deflate':
|
||||
$decoded = self::decodeDeflate($this->body);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
|
||||
if (!empty($oldEncoding)) {
|
||||
mb_internal_encoding($oldEncoding);
|
||||
}
|
||||
if (!empty($e)) {
|
||||
throw $e;
|
||||
}
|
||||
return $decoded;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTTP version of the response
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getVersion()
|
||||
{
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes the message-body encoded by gzip
|
||||
*
|
||||
* The real decoding work is done by gzinflate() built-in function, this
|
||||
* method only parses the header and checks data for compliance with
|
||||
* RFC 1952
|
||||
*
|
||||
* @param string gzip-encoded data
|
||||
* @return string decoded data
|
||||
* @throws HTTP_Request2_Exception
|
||||
* @link http://tools.ietf.org/html/rfc1952
|
||||
*/
|
||||
public static function decodeGzip($data)
|
||||
{
|
||||
$length = strlen($data);
|
||||
// If it doesn't look like gzip-encoded data, don't bother
|
||||
if (18 > $length || strcmp(substr($data, 0, 2), "\x1f\x8b")) {
|
||||
return $data;
|
||||
}
|
||||
if (!function_exists('gzinflate')) {
|
||||
throw new HTTP_Request2_Exception('Unable to decode body: gzip extension not available');
|
||||
}
|
||||
$method = ord(substr($data, 2, 1));
|
||||
if (8 != $method) {
|
||||
throw new HTTP_Request2_Exception('Error parsing gzip header: unknown compression method');
|
||||
}
|
||||
$flags = ord(substr($data, 3, 1));
|
||||
if ($flags & 224) {
|
||||
throw new HTTP_Request2_Exception('Error parsing gzip header: reserved bits are set');
|
||||
}
|
||||
|
||||
// header is 10 bytes minimum. may be longer, though.
|
||||
$headerLength = 10;
|
||||
// extra fields, need to skip 'em
|
||||
if ($flags & 4) {
|
||||
if ($length - $headerLength - 2 < 8) {
|
||||
throw new HTTP_Request2_Exception('Error parsing gzip header: data too short');
|
||||
}
|
||||
$extraLength = unpack('v', substr($data, 10, 2));
|
||||
if ($length - $headerLength - 2 - $extraLength[1] < 8) {
|
||||
throw new HTTP_Request2_Exception('Error parsing gzip header: data too short');
|
||||
}
|
||||
$headerLength += $extraLength[1] + 2;
|
||||
}
|
||||
// file name, need to skip that
|
||||
if ($flags & 8) {
|
||||
if ($length - $headerLength - 1 < 8) {
|
||||
throw new HTTP_Request2_Exception('Error parsing gzip header: data too short');
|
||||
}
|
||||
$filenameLength = strpos(substr($data, $headerLength), chr(0));
|
||||
if (false === $filenameLength || $length - $headerLength - $filenameLength - 1 < 8) {
|
||||
throw new HTTP_Request2_Exception('Error parsing gzip header: data too short');
|
||||
}
|
||||
$headerLength += $filenameLength + 1;
|
||||
}
|
||||
// comment, need to skip that also
|
||||
if ($flags & 16) {
|
||||
if ($length - $headerLength - 1 < 8) {
|
||||
throw new HTTP_Request2_Exception('Error parsing gzip header: data too short');
|
||||
}
|
||||
$commentLength = strpos(substr($data, $headerLength), chr(0));
|
||||
if (false === $commentLength || $length - $headerLength - $commentLength - 1 < 8) {
|
||||
throw new HTTP_Request2_Exception('Error parsing gzip header: data too short');
|
||||
}
|
||||
$headerLength += $commentLength + 1;
|
||||
}
|
||||
// have a CRC for header. let's check
|
||||
if ($flags & 2) {
|
||||
if ($length - $headerLength - 2 < 8) {
|
||||
throw new HTTP_Request2_Exception('Error parsing gzip header: data too short');
|
||||
}
|
||||
$crcReal = 0xffff & crc32(substr($data, 0, $headerLength));
|
||||
$crcStored = unpack('v', substr($data, $headerLength, 2));
|
||||
if ($crcReal != $crcStored[1]) {
|
||||
throw new HTTP_Request2_Exception('Header CRC check failed');
|
||||
}
|
||||
$headerLength += 2;
|
||||
}
|
||||
// unpacked data CRC and size at the end of encoded data
|
||||
$tmp = unpack('V2', substr($data, -8));
|
||||
$dataCrc = $tmp[1];
|
||||
$dataSize = $tmp[2];
|
||||
|
||||
// finally, call the gzinflate() function
|
||||
// don't pass $dataSize to gzinflate, see bugs #13135, #14370
|
||||
$unpacked = gzinflate(substr($data, $headerLength, -8));
|
||||
if (false === $unpacked) {
|
||||
throw new HTTP_Request2_Exception('gzinflate() call failed');
|
||||
} elseif ($dataSize != strlen($unpacked)) {
|
||||
throw new HTTP_Request2_Exception('Data size check failed');
|
||||
} elseif ((0xffffffff & $dataCrc) != (0xffffffff & crc32($unpacked))) {
|
||||
throw new HTTP_Request2_Exception('Data CRC check failed');
|
||||
}
|
||||
return $unpacked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes the message-body encoded by deflate
|
||||
*
|
||||
* @param string deflate-encoded data
|
||||
* @return string decoded data
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public static function decodeDeflate($data)
|
||||
{
|
||||
if (!function_exists('gzuncompress')) {
|
||||
throw new HTTP_Request2_Exception('Unable to decode body: gzip extension not available');
|
||||
}
|
||||
// RFC 2616 defines 'deflate' encoding as zlib format from RFC 1950,
|
||||
// while many applications send raw deflate stream from RFC 1951.
|
||||
// We should check for presence of zlib header and use gzuncompress() or
|
||||
// gzinflate() as needed. See bug #15305
|
||||
$header = unpack('n', substr($data, 0, 2));
|
||||
return (0 == $header[1] % 31)? gzuncompress($data): gzinflate($data);
|
||||
}
|
||||
}
|
||||
?>
|
||||
894
libs/PEAR.1.9/Net/URL2.php
Normal file
894
libs/PEAR.1.9/Net/URL2.php
Normal file
|
|
@ -0,0 +1,894 @@
|
|||
<?php
|
||||
/**
|
||||
* Net_URL2, a class representing a URL as per RFC 3986.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2007-2009, Peytz & Co. A/S
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the Net_URL2 nor the names of its contributors may
|
||||
* be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Networking
|
||||
* @package Net_URL2
|
||||
* @author Christian Schmidt <schmidt@php.net>
|
||||
* @copyright 2007-2009 Peytz & Co. A/S
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version CVS: $Id: URL2.php 290036 2009-10-28 19:52:49Z schmidt $
|
||||
* @link http://www.rfc-editor.org/rfc/rfc3986.txt
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents a URL as per RFC 3986.
|
||||
*
|
||||
* @category Networking
|
||||
* @package Net_URL2
|
||||
* @author Christian Schmidt <schmidt@php.net>
|
||||
* @copyright 2007-2009 Peytz & Co. A/S
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/Net_URL2
|
||||
*/
|
||||
class Net_URL2
|
||||
{
|
||||
/**
|
||||
* Do strict parsing in resolve() (see RFC 3986, section 5.2.2). Default
|
||||
* is true.
|
||||
*/
|
||||
const OPTION_STRICT = 'strict';
|
||||
|
||||
/**
|
||||
* Represent arrays in query using PHP's [] notation. Default is true.
|
||||
*/
|
||||
const OPTION_USE_BRACKETS = 'use_brackets';
|
||||
|
||||
/**
|
||||
* URL-encode query variable keys. Default is true.
|
||||
*/
|
||||
const OPTION_ENCODE_KEYS = 'encode_keys';
|
||||
|
||||
/**
|
||||
* Query variable separators when parsing the query string. Every character
|
||||
* is considered a separator. Default is "&".
|
||||
*/
|
||||
const OPTION_SEPARATOR_INPUT = 'input_separator';
|
||||
|
||||
/**
|
||||
* Query variable separator used when generating the query string. Default
|
||||
* is "&".
|
||||
*/
|
||||
const OPTION_SEPARATOR_OUTPUT = 'output_separator';
|
||||
|
||||
/**
|
||||
* Default options corresponds to how PHP handles $_GET.
|
||||
*/
|
||||
private $_options = array(
|
||||
self::OPTION_STRICT => true,
|
||||
self::OPTION_USE_BRACKETS => true,
|
||||
self::OPTION_ENCODE_KEYS => true,
|
||||
self::OPTION_SEPARATOR_INPUT => '&',
|
||||
self::OPTION_SEPARATOR_OUTPUT => '&',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var string|bool
|
||||
*/
|
||||
private $_scheme = false;
|
||||
|
||||
/**
|
||||
* @var string|bool
|
||||
*/
|
||||
private $_userinfo = false;
|
||||
|
||||
/**
|
||||
* @var string|bool
|
||||
*/
|
||||
private $_host = false;
|
||||
|
||||
/**
|
||||
* @var string|bool
|
||||
*/
|
||||
private $_port = false;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $_path = '';
|
||||
|
||||
/**
|
||||
* @var string|bool
|
||||
*/
|
||||
private $_query = false;
|
||||
|
||||
/**
|
||||
* @var string|bool
|
||||
*/
|
||||
private $_fragment = false;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $url an absolute or relative URL
|
||||
* @param array $options an array of OPTION_xxx constants
|
||||
*/
|
||||
public function __construct($url, array $options = array())
|
||||
{
|
||||
foreach ($options as $optionName => $value) {
|
||||
if (array_key_exists($optionName, $this->_options)) {
|
||||
$this->_options[$optionName] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
// The regular expression is copied verbatim from RFC 3986, appendix B.
|
||||
// The expression does not validate the URL but matches any string.
|
||||
preg_match('!^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?!',
|
||||
$url,
|
||||
$matches);
|
||||
|
||||
// "path" is always present (possibly as an empty string); the rest
|
||||
// are optional.
|
||||
$this->_scheme = !empty($matches[1]) ? $matches[2] : false;
|
||||
$this->setAuthority(!empty($matches[3]) ? $matches[4] : false);
|
||||
$this->_path = $matches[5];
|
||||
$this->_query = !empty($matches[6]) ? $matches[7] : false;
|
||||
$this->_fragment = !empty($matches[8]) ? $matches[9] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic Setter.
|
||||
*
|
||||
* This method will magically set the value of a private variable ($var)
|
||||
* with the value passed as the args
|
||||
*
|
||||
* @param string $var The private variable to set.
|
||||
* @param mixed $arg An argument of any type.
|
||||
* @return void
|
||||
*/
|
||||
public function __set($var, $arg)
|
||||
{
|
||||
$method = 'set' . $var;
|
||||
if (method_exists($this, $method)) {
|
||||
$this->$method($arg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic Getter.
|
||||
*
|
||||
* This is the magic get method to retrieve the private variable
|
||||
* that was set by either __set() or it's setter...
|
||||
*
|
||||
* @param string $var The property name to retrieve.
|
||||
* @return mixed $this->$var Either a boolean false if the
|
||||
* property is not set or the value
|
||||
* of the private property.
|
||||
*/
|
||||
public function __get($var)
|
||||
{
|
||||
$method = 'get' . $var;
|
||||
if (method_exists($this, $method)) {
|
||||
return $this->$method();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the scheme, e.g. "http" or "urn", or false if there is no
|
||||
* scheme specified, i.e. if this is a relative URL.
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getScheme()
|
||||
{
|
||||
return $this->_scheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the scheme, e.g. "http" or "urn". Specify false if there is no
|
||||
* scheme specified, i.e. if this is a relative URL.
|
||||
*
|
||||
* @param string|bool $scheme e.g. "http" or "urn", or false if there is no
|
||||
* scheme specified, i.e. if this is a relative
|
||||
* URL
|
||||
*
|
||||
* @return void
|
||||
* @see getScheme()
|
||||
*/
|
||||
public function setScheme($scheme)
|
||||
{
|
||||
$this->_scheme = $scheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user part of the userinfo part (the part preceding the first
|
||||
* ":"), or false if there is no userinfo part.
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getUser()
|
||||
{
|
||||
return $this->_userinfo !== false
|
||||
? preg_replace('@:.*$@', '', $this->_userinfo)
|
||||
: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the password part of the userinfo part (the part after the first
|
||||
* ":"), or false if there is no userinfo part (i.e. the URL does not
|
||||
* contain "@" in front of the hostname) or the userinfo part does not
|
||||
* contain ":".
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getPassword()
|
||||
{
|
||||
return $this->_userinfo !== false
|
||||
? substr(strstr($this->_userinfo, ':'), 1)
|
||||
: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the userinfo part, or false if there is none, i.e. if the
|
||||
* authority part does not contain "@".
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getUserinfo()
|
||||
{
|
||||
return $this->_userinfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the userinfo part. If two arguments are passed, they are combined
|
||||
* in the userinfo part as username ":" password.
|
||||
*
|
||||
* @param string|bool $userinfo userinfo or username
|
||||
* @param string|bool $password optional password, or false
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUserinfo($userinfo, $password = false)
|
||||
{
|
||||
$this->_userinfo = $userinfo;
|
||||
if ($password !== false) {
|
||||
$this->_userinfo .= ':' . $password;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the host part, or false if there is no authority part, e.g.
|
||||
* relative URLs.
|
||||
*
|
||||
* @return string|bool a hostname, an IP address, or false
|
||||
*/
|
||||
public function getHost()
|
||||
{
|
||||
return $this->_host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the host part. Specify false if there is no authority part, e.g.
|
||||
* relative URLs.
|
||||
*
|
||||
* @param string|bool $host a hostname, an IP address, or false
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setHost($host)
|
||||
{
|
||||
$this->_host = $host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the port number, or false if there is no port number specified,
|
||||
* i.e. if the default port is to be used.
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getPort()
|
||||
{
|
||||
return $this->_port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the port number. Specify false if there is no port number specified,
|
||||
* i.e. if the default port is to be used.
|
||||
*
|
||||
* @param string|bool $port a port number, or false
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setPort($port)
|
||||
{
|
||||
$this->_port = $port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the authority part, i.e. [ userinfo "@" ] host [ ":" port ], or
|
||||
* false if there is no authority.
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getAuthority()
|
||||
{
|
||||
if (!$this->_host) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$authority = '';
|
||||
|
||||
if ($this->_userinfo !== false) {
|
||||
$authority .= $this->_userinfo . '@';
|
||||
}
|
||||
|
||||
$authority .= $this->_host;
|
||||
|
||||
if ($this->_port !== false) {
|
||||
$authority .= ':' . $this->_port;
|
||||
}
|
||||
|
||||
return $authority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the authority part, i.e. [ userinfo "@" ] host [ ":" port ]. Specify
|
||||
* false if there is no authority.
|
||||
*
|
||||
* @param string|false $authority a hostname or an IP addresse, possibly
|
||||
* with userinfo prefixed and port number
|
||||
* appended, e.g. "foo:bar@example.org:81".
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setAuthority($authority)
|
||||
{
|
||||
$this->_userinfo = false;
|
||||
$this->_host = false;
|
||||
$this->_port = false;
|
||||
if (preg_match('@^(([^\@]*)\@)?([^:]+)(:(\d*))?$@', $authority, $reg)) {
|
||||
if ($reg[1]) {
|
||||
$this->_userinfo = $reg[2];
|
||||
}
|
||||
|
||||
$this->_host = $reg[3];
|
||||
if (isset($reg[5])) {
|
||||
$this->_port = $reg[5];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path part (possibly an empty string).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPath()
|
||||
{
|
||||
return $this->_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the path part (possibly an empty string).
|
||||
*
|
||||
* @param string $path a path
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setPath($path)
|
||||
{
|
||||
$this->_path = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the query string (excluding the leading "?"), or false if "?"
|
||||
* is not present in the URL.
|
||||
*
|
||||
* @return string|bool
|
||||
* @see self::getQueryVariables()
|
||||
*/
|
||||
public function getQuery()
|
||||
{
|
||||
return $this->_query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the query string (excluding the leading "?"). Specify false if "?"
|
||||
* is not present in the URL.
|
||||
*
|
||||
* @param string|bool $query a query string, e.g. "foo=1&bar=2"
|
||||
*
|
||||
* @return void
|
||||
* @see self::setQueryVariables()
|
||||
*/
|
||||
public function setQuery($query)
|
||||
{
|
||||
$this->_query = $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the fragment name, or false if "#" is not present in the URL.
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getFragment()
|
||||
{
|
||||
return $this->_fragment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the fragment name. Specify false if "#" is not present in the URL.
|
||||
*
|
||||
* @param string|bool $fragment a fragment excluding the leading "#", or
|
||||
* false
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setFragment($fragment)
|
||||
{
|
||||
$this->_fragment = $fragment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the query string like an array as the variables would appear in
|
||||
* $_GET in a PHP script. If the URL does not contain a "?", an empty array
|
||||
* is returned.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getQueryVariables()
|
||||
{
|
||||
$pattern = '/[' .
|
||||
preg_quote($this->getOption(self::OPTION_SEPARATOR_INPUT), '/') .
|
||||
']/';
|
||||
$parts = preg_split($pattern, $this->_query, -1, PREG_SPLIT_NO_EMPTY);
|
||||
$return = array();
|
||||
|
||||
foreach ($parts as $part) {
|
||||
if (strpos($part, '=') !== false) {
|
||||
list($key, $value) = explode('=', $part, 2);
|
||||
} else {
|
||||
$key = $part;
|
||||
$value = null;
|
||||
}
|
||||
|
||||
if ($this->getOption(self::OPTION_ENCODE_KEYS)) {
|
||||
$key = rawurldecode($key);
|
||||
}
|
||||
$value = rawurldecode($value);
|
||||
|
||||
if ($this->getOption(self::OPTION_USE_BRACKETS) &&
|
||||
preg_match('#^(.*)\[([0-9a-z_-]*)\]#i', $key, $matches)) {
|
||||
|
||||
$key = $matches[1];
|
||||
$idx = $matches[2];
|
||||
|
||||
// Ensure is an array
|
||||
if (empty($return[$key]) || !is_array($return[$key])) {
|
||||
$return[$key] = array();
|
||||
}
|
||||
|
||||
// Add data
|
||||
if ($idx === '') {
|
||||
$return[$key][] = $value;
|
||||
} else {
|
||||
$return[$key][$idx] = $value;
|
||||
}
|
||||
} elseif (!$this->getOption(self::OPTION_USE_BRACKETS)
|
||||
&& !empty($return[$key])
|
||||
) {
|
||||
$return[$key] = (array) $return[$key];
|
||||
$return[$key][] = $value;
|
||||
} else {
|
||||
$return[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the query string to the specified variable in the query string.
|
||||
*
|
||||
* @param array $array (name => value) array
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setQueryVariables(array $array)
|
||||
{
|
||||
if (!$array) {
|
||||
$this->_query = false;
|
||||
} else {
|
||||
foreach ($array as $name => $value) {
|
||||
if ($this->getOption(self::OPTION_ENCODE_KEYS)) {
|
||||
$name = self::urlencode($name);
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $k => $v) {
|
||||
$parts[] = $this->getOption(self::OPTION_USE_BRACKETS)
|
||||
? sprintf('%s[%s]=%s', $name, $k, $v)
|
||||
: ($name . '=' . $v);
|
||||
}
|
||||
} elseif (!is_null($value)) {
|
||||
$parts[] = $name . '=' . self::urlencode($value);
|
||||
} else {
|
||||
$parts[] = $name;
|
||||
}
|
||||
}
|
||||
$this->_query = implode($this->getOption(self::OPTION_SEPARATOR_OUTPUT),
|
||||
$parts);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the specified variable in the query string.
|
||||
*
|
||||
* @param string $name variable name
|
||||
* @param mixed $value variable value
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setQueryVariable($name, $value)
|
||||
{
|
||||
$array = $this->getQueryVariables();
|
||||
$array[$name] = $value;
|
||||
$this->setQueryVariables($array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specifed variable from the query string.
|
||||
*
|
||||
* @param string $name a query string variable, e.g. "foo" in "?foo=1"
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetQueryVariable($name)
|
||||
{
|
||||
$array = $this->getQueryVariables();
|
||||
unset($array[$name]);
|
||||
$this->setQueryVariables($array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getURL()
|
||||
{
|
||||
// See RFC 3986, section 5.3
|
||||
$url = "";
|
||||
|
||||
if ($this->_scheme !== false) {
|
||||
$url .= $this->_scheme . ':';
|
||||
}
|
||||
|
||||
$authority = $this->getAuthority();
|
||||
if ($authority !== false) {
|
||||
$url .= '//' . $authority;
|
||||
}
|
||||
$url .= $this->_path;
|
||||
|
||||
if ($this->_query !== false) {
|
||||
$url .= '?' . $this->_query;
|
||||
}
|
||||
|
||||
if ($this->_fragment !== false) {
|
||||
$url .= '#' . $this->_fragment;
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this URL.
|
||||
*
|
||||
* @return string
|
||||
* @see toString()
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getURL();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a normalized string representation of this URL. This is useful
|
||||
* for comparison of URLs.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNormalizedURL()
|
||||
{
|
||||
$url = clone $this;
|
||||
$url->normalize();
|
||||
return $url->getUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a normalized Net_URL2 instance.
|
||||
*
|
||||
* @return Net_URL2
|
||||
*/
|
||||
public function normalize()
|
||||
{
|
||||
// See RFC 3886, section 6
|
||||
|
||||
// Schemes are case-insensitive
|
||||
if ($this->_scheme) {
|
||||
$this->_scheme = strtolower($this->_scheme);
|
||||
}
|
||||
|
||||
// Hostnames are case-insensitive
|
||||
if ($this->_host) {
|
||||
$this->_host = strtolower($this->_host);
|
||||
}
|
||||
|
||||
// Remove default port number for known schemes (RFC 3986, section 6.2.3)
|
||||
if ($this->_port &&
|
||||
$this->_scheme &&
|
||||
$this->_port == getservbyname($this->_scheme, 'tcp')) {
|
||||
|
||||
$this->_port = false;
|
||||
}
|
||||
|
||||
// Normalize case of %XX percentage-encodings (RFC 3986, section 6.2.2.1)
|
||||
foreach (array('_userinfo', '_host', '_path') as $part) {
|
||||
if ($this->$part) {
|
||||
$this->$part = preg_replace('/%[0-9a-f]{2}/ie',
|
||||
'strtoupper("\0")',
|
||||
$this->$part);
|
||||
}
|
||||
}
|
||||
|
||||
// Path segment normalization (RFC 3986, section 6.2.2.3)
|
||||
$this->_path = self::removeDotSegments($this->_path);
|
||||
|
||||
// Scheme based normalization (RFC 3986, section 6.2.3)
|
||||
if ($this->_host && !$this->_path) {
|
||||
$this->_path = '/';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this instance represents an absolute URL.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isAbsolute()
|
||||
{
|
||||
return (bool) $this->_scheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Net_URL2 instance representing an absolute URL relative to
|
||||
* this URL.
|
||||
*
|
||||
* @param Net_URL2|string $reference relative URL
|
||||
*
|
||||
* @return Net_URL2
|
||||
*/
|
||||
public function resolve($reference)
|
||||
{
|
||||
if (!$reference instanceof Net_URL2) {
|
||||
$reference = new self($reference);
|
||||
}
|
||||
if (!$this->isAbsolute()) {
|
||||
throw new Exception('Base-URL must be absolute');
|
||||
}
|
||||
|
||||
// A non-strict parser may ignore a scheme in the reference if it is
|
||||
// identical to the base URI's scheme.
|
||||
if (!$this->getOption(self::OPTION_STRICT) && $reference->_scheme == $this->_scheme) {
|
||||
$reference->_scheme = false;
|
||||
}
|
||||
|
||||
$target = new self('');
|
||||
if ($reference->_scheme !== false) {
|
||||
$target->_scheme = $reference->_scheme;
|
||||
$target->setAuthority($reference->getAuthority());
|
||||
$target->_path = self::removeDotSegments($reference->_path);
|
||||
$target->_query = $reference->_query;
|
||||
} else {
|
||||
$authority = $reference->getAuthority();
|
||||
if ($authority !== false) {
|
||||
$target->setAuthority($authority);
|
||||
$target->_path = self::removeDotSegments($reference->_path);
|
||||
$target->_query = $reference->_query;
|
||||
} else {
|
||||
if ($reference->_path == '') {
|
||||
$target->_path = $this->_path;
|
||||
if ($reference->_query !== false) {
|
||||
$target->_query = $reference->_query;
|
||||
} else {
|
||||
$target->_query = $this->_query;
|
||||
}
|
||||
} else {
|
||||
if (substr($reference->_path, 0, 1) == '/') {
|
||||
$target->_path = self::removeDotSegments($reference->_path);
|
||||
} else {
|
||||
// Merge paths (RFC 3986, section 5.2.3)
|
||||
if ($this->_host !== false && $this->_path == '') {
|
||||
$target->_path = '/' . $this->_path;
|
||||
} else {
|
||||
$i = strrpos($this->_path, '/');
|
||||
if ($i !== false) {
|
||||
$target->_path = substr($this->_path, 0, $i + 1);
|
||||
}
|
||||
$target->_path .= $reference->_path;
|
||||
}
|
||||
$target->_path = self::removeDotSegments($target->_path);
|
||||
}
|
||||
$target->_query = $reference->_query;
|
||||
}
|
||||
$target->setAuthority($this->getAuthority());
|
||||
}
|
||||
$target->_scheme = $this->_scheme;
|
||||
}
|
||||
|
||||
$target->_fragment = $reference->_fragment;
|
||||
|
||||
return $target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes dots as described in RFC 3986, section 5.2.4, e.g.
|
||||
* "/foo/../bar/baz" => "/bar/baz"
|
||||
*
|
||||
* @param string $path a path
|
||||
*
|
||||
* @return string a path
|
||||
*/
|
||||
public static function removeDotSegments($path)
|
||||
{
|
||||
$output = '';
|
||||
|
||||
// Make sure not to be trapped in an infinite loop due to a bug in this
|
||||
// method
|
||||
$j = 0;
|
||||
while ($path && $j++ < 100) {
|
||||
if (substr($path, 0, 2) == './') {
|
||||
// Step 2.A
|
||||
$path = substr($path, 2);
|
||||
} elseif (substr($path, 0, 3) == '../') {
|
||||
// Step 2.A
|
||||
$path = substr($path, 3);
|
||||
} elseif (substr($path, 0, 3) == '/./' || $path == '/.') {
|
||||
// Step 2.B
|
||||
$path = '/' . substr($path, 3);
|
||||
} elseif (substr($path, 0, 4) == '/../' || $path == '/..') {
|
||||
// Step 2.C
|
||||
$path = '/' . substr($path, 4);
|
||||
$i = strrpos($output, '/');
|
||||
$output = $i === false ? '' : substr($output, 0, $i);
|
||||
} elseif ($path == '.' || $path == '..') {
|
||||
// Step 2.D
|
||||
$path = '';
|
||||
} else {
|
||||
// Step 2.E
|
||||
$i = strpos($path, '/');
|
||||
if ($i === 0) {
|
||||
$i = strpos($path, '/', 1);
|
||||
}
|
||||
if ($i === false) {
|
||||
$i = strlen($path);
|
||||
}
|
||||
$output .= substr($path, 0, $i);
|
||||
$path = substr($path, $i);
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Percent-encodes all non-alphanumeric characters except these: _ . - ~
|
||||
* Similar to PHP's rawurlencode(), except that it also encodes ~ in PHP
|
||||
* 5.2.x and earlier.
|
||||
*
|
||||
* @param $raw the string to encode
|
||||
* @return string
|
||||
*/
|
||||
public static function urlencode($string)
|
||||
{
|
||||
$encoded = rawurlencode($string);
|
||||
// This is only necessary in PHP < 5.3.
|
||||
$encoded = str_replace('%7E', '~', $encoded);
|
||||
return $encoded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Net_URL2 instance representing the canonical URL of the
|
||||
* currently executing PHP script.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getCanonical()
|
||||
{
|
||||
if (!isset($_SERVER['REQUEST_METHOD'])) {
|
||||
// ALERT - no current URL
|
||||
throw new Exception('Script was not called through a webserver');
|
||||
}
|
||||
|
||||
// Begin with a relative URL
|
||||
$url = new self($_SERVER['PHP_SELF']);
|
||||
$url->_scheme = isset($_SERVER['HTTPS']) ? 'https' : 'http';
|
||||
$url->_host = $_SERVER['SERVER_NAME'];
|
||||
$port = $_SERVER['SERVER_PORT'];
|
||||
if ($url->_scheme == 'http' && $port != 80 ||
|
||||
$url->_scheme == 'https' && $port != 443) {
|
||||
|
||||
$url->_port = $port;
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the URL used to retrieve the current request.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getRequestedURL()
|
||||
{
|
||||
return self::getRequested()->getUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Net_URL2 instance representing the URL used to retrieve the
|
||||
* current request.
|
||||
*
|
||||
* @return Net_URL2
|
||||
*/
|
||||
public static function getRequested()
|
||||
{
|
||||
if (!isset($_SERVER['REQUEST_METHOD'])) {
|
||||
// ALERT - no current URL
|
||||
throw new Exception('Script was not called through a webserver');
|
||||
}
|
||||
|
||||
// Begin with a relative URL
|
||||
$url = new self($_SERVER['REQUEST_URI']);
|
||||
$url->_scheme = isset($_SERVER['HTTPS']) ? 'https' : 'http';
|
||||
// Set host and possibly port
|
||||
$url->setAuthority($_SERVER['HTTP_HOST']);
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the specified option.
|
||||
*
|
||||
* @param string $optionName The name of the option to retrieve
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function getOption($optionName)
|
||||
{
|
||||
return isset($this->_options[$optionName])
|
||||
? $this->_options[$optionName] : false;
|
||||
}
|
||||
}
|
||||
1137
libs/PEAR.1.9/PEAR.php
Normal file
1137
libs/PEAR.1.9/PEAR.php
Normal file
File diff suppressed because it is too large
Load diff
391
libs/PEAR.1.9/PEAR/Exception.php
Normal file
391
libs/PEAR.1.9/PEAR/Exception.php
Normal file
|
|
@ -0,0 +1,391 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
|
||||
/**
|
||||
* PEAR_Exception
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Tomas V. V. Cox <cox@idecnet.com>
|
||||
* @author Hans Lellelid <hans@velum.net>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Greg Beaver <cellog@php.net>
|
||||
* @copyright 1997-2009 The Authors
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version CVS: $Id: Exception.php 276383 2009-02-24 23:39:37Z dufuz $
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @since File available since Release 1.3.3
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Base PEAR_Exception Class
|
||||
*
|
||||
* 1) Features:
|
||||
*
|
||||
* - Nestable exceptions (throw new PEAR_Exception($msg, $prev_exception))
|
||||
* - Definable triggers, shot when exceptions occur
|
||||
* - Pretty and informative error messages
|
||||
* - Added more context info available (like class, method or cause)
|
||||
* - cause can be a PEAR_Exception or an array of mixed
|
||||
* PEAR_Exceptions/PEAR_ErrorStack warnings
|
||||
* - callbacks for specific exception classes and their children
|
||||
*
|
||||
* 2) Ideas:
|
||||
*
|
||||
* - Maybe a way to define a 'template' for the output
|
||||
*
|
||||
* 3) Inherited properties from PHP Exception Class:
|
||||
*
|
||||
* protected $message
|
||||
* protected $code
|
||||
* protected $line
|
||||
* protected $file
|
||||
* private $trace
|
||||
*
|
||||
* 4) Inherited methods from PHP Exception Class:
|
||||
*
|
||||
* __clone
|
||||
* __construct
|
||||
* getMessage
|
||||
* getCode
|
||||
* getFile
|
||||
* getLine
|
||||
* getTraceSafe
|
||||
* getTraceSafeAsString
|
||||
* __toString
|
||||
*
|
||||
* 5) Usage example
|
||||
*
|
||||
* <code>
|
||||
* require_once 'PEAR/Exception.php';
|
||||
*
|
||||
* class Test {
|
||||
* function foo() {
|
||||
* throw new PEAR_Exception('Error Message', ERROR_CODE);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* function myLogger($pear_exception) {
|
||||
* echo $pear_exception->getMessage();
|
||||
* }
|
||||
* // each time a exception is thrown the 'myLogger' will be called
|
||||
* // (its use is completely optional)
|
||||
* PEAR_Exception::addObserver('myLogger');
|
||||
* $test = new Test;
|
||||
* try {
|
||||
* $test->foo();
|
||||
* } catch (PEAR_Exception $e) {
|
||||
* print $e;
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Tomas V.V.Cox <cox@idecnet.com>
|
||||
* @author Hans Lellelid <hans@velum.net>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Greg Beaver <cellog@php.net>
|
||||
* @copyright 1997-2009 The Authors
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version Release: 1.9.0
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @since Class available since Release 1.3.3
|
||||
*
|
||||
*/
|
||||
class PEAR_Exception extends Exception
|
||||
{
|
||||
const OBSERVER_PRINT = -2;
|
||||
const OBSERVER_TRIGGER = -4;
|
||||
const OBSERVER_DIE = -8;
|
||||
protected $cause;
|
||||
private static $_observers = array();
|
||||
private static $_uniqueid = 0;
|
||||
private $_trace;
|
||||
|
||||
/**
|
||||
* Supported signatures:
|
||||
* - PEAR_Exception(string $message);
|
||||
* - PEAR_Exception(string $message, int $code);
|
||||
* - PEAR_Exception(string $message, Exception $cause);
|
||||
* - PEAR_Exception(string $message, Exception $cause, int $code);
|
||||
* - PEAR_Exception(string $message, PEAR_Error $cause);
|
||||
* - PEAR_Exception(string $message, PEAR_Error $cause, int $code);
|
||||
* - PEAR_Exception(string $message, array $causes);
|
||||
* - PEAR_Exception(string $message, array $causes, int $code);
|
||||
* @param string exception message
|
||||
* @param int|Exception|PEAR_Error|array|null exception cause
|
||||
* @param int|null exception code or null
|
||||
*/
|
||||
public function __construct($message, $p2 = null, $p3 = null)
|
||||
{
|
||||
if (is_int($p2)) {
|
||||
$code = $p2;
|
||||
$this->cause = null;
|
||||
} elseif (is_object($p2) || is_array($p2)) {
|
||||
// using is_object allows both Exception and PEAR_Error
|
||||
if (is_object($p2) && !($p2 instanceof Exception)) {
|
||||
if (!class_exists('PEAR_Error') || !($p2 instanceof PEAR_Error)) {
|
||||
throw new PEAR_Exception('exception cause must be Exception, ' .
|
||||
'array, or PEAR_Error');
|
||||
}
|
||||
}
|
||||
$code = $p3;
|
||||
if (is_array($p2) && isset($p2['message'])) {
|
||||
// fix potential problem of passing in a single warning
|
||||
$p2 = array($p2);
|
||||
}
|
||||
$this->cause = $p2;
|
||||
} else {
|
||||
$code = null;
|
||||
$this->cause = null;
|
||||
}
|
||||
parent::__construct($message, $code);
|
||||
$this->signal();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $callback - A valid php callback, see php func is_callable()
|
||||
* - A PEAR_Exception::OBSERVER_* constant
|
||||
* - An array(const PEAR_Exception::OBSERVER_*,
|
||||
* mixed $options)
|
||||
* @param string $label The name of the observer. Use this if you want
|
||||
* to remove it later with removeObserver()
|
||||
*/
|
||||
public static function addObserver($callback, $label = 'default')
|
||||
{
|
||||
self::$_observers[$label] = $callback;
|
||||
}
|
||||
|
||||
public static function removeObserver($label = 'default')
|
||||
{
|
||||
unset(self::$_observers[$label]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int unique identifier for an observer
|
||||
*/
|
||||
public static function getUniqueId()
|
||||
{
|
||||
return self::$_uniqueid++;
|
||||
}
|
||||
|
||||
private function signal()
|
||||
{
|
||||
foreach (self::$_observers as $func) {
|
||||
if (is_callable($func)) {
|
||||
call_user_func($func, $this);
|
||||
continue;
|
||||
}
|
||||
settype($func, 'array');
|
||||
switch ($func[0]) {
|
||||
case self::OBSERVER_PRINT :
|
||||
$f = (isset($func[1])) ? $func[1] : '%s';
|
||||
printf($f, $this->getMessage());
|
||||
break;
|
||||
case self::OBSERVER_TRIGGER :
|
||||
$f = (isset($func[1])) ? $func[1] : E_USER_NOTICE;
|
||||
trigger_error($this->getMessage(), $f);
|
||||
break;
|
||||
case self::OBSERVER_DIE :
|
||||
$f = (isset($func[1])) ? $func[1] : '%s';
|
||||
die(printf($f, $this->getMessage()));
|
||||
break;
|
||||
default:
|
||||
trigger_error('invalid observer type', E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return specific error information that can be used for more detailed
|
||||
* error messages or translation.
|
||||
*
|
||||
* This method may be overridden in child exception classes in order
|
||||
* to add functionality not present in PEAR_Exception and is a placeholder
|
||||
* to define API
|
||||
*
|
||||
* The returned array must be an associative array of parameter => value like so:
|
||||
* <pre>
|
||||
* array('name' => $name, 'context' => array(...))
|
||||
* </pre>
|
||||
* @return array
|
||||
*/
|
||||
public function getErrorData()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the exception that caused this exception to be thrown
|
||||
* @access public
|
||||
* @return Exception|array The context of the exception
|
||||
*/
|
||||
public function getCause()
|
||||
{
|
||||
return $this->cause;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function must be public to call on caused exceptions
|
||||
* @param array
|
||||
*/
|
||||
public function getCauseMessage(&$causes)
|
||||
{
|
||||
$trace = $this->getTraceSafe();
|
||||
$cause = array('class' => get_class($this),
|
||||
'message' => $this->message,
|
||||
'file' => 'unknown',
|
||||
'line' => 'unknown');
|
||||
if (isset($trace[0])) {
|
||||
if (isset($trace[0]['file'])) {
|
||||
$cause['file'] = $trace[0]['file'];
|
||||
$cause['line'] = $trace[0]['line'];
|
||||
}
|
||||
}
|
||||
$causes[] = $cause;
|
||||
if ($this->cause instanceof PEAR_Exception) {
|
||||
$this->cause->getCauseMessage($causes);
|
||||
} elseif ($this->cause instanceof Exception) {
|
||||
$causes[] = array('class' => get_class($this->cause),
|
||||
'message' => $this->cause->getMessage(),
|
||||
'file' => $this->cause->getFile(),
|
||||
'line' => $this->cause->getLine());
|
||||
} elseif (class_exists('PEAR_Error') && $this->cause instanceof PEAR_Error) {
|
||||
$causes[] = array('class' => get_class($this->cause),
|
||||
'message' => $this->cause->getMessage(),
|
||||
'file' => 'unknown',
|
||||
'line' => 'unknown');
|
||||
} elseif (is_array($this->cause)) {
|
||||
foreach ($this->cause as $cause) {
|
||||
if ($cause instanceof PEAR_Exception) {
|
||||
$cause->getCauseMessage($causes);
|
||||
} elseif ($cause instanceof Exception) {
|
||||
$causes[] = array('class' => get_class($cause),
|
||||
'message' => $cause->getMessage(),
|
||||
'file' => $cause->getFile(),
|
||||
'line' => $cause->getLine());
|
||||
} elseif (class_exists('PEAR_Error') && $cause instanceof PEAR_Error) {
|
||||
$causes[] = array('class' => get_class($cause),
|
||||
'message' => $cause->getMessage(),
|
||||
'file' => 'unknown',
|
||||
'line' => 'unknown');
|
||||
} elseif (is_array($cause) && isset($cause['message'])) {
|
||||
// PEAR_ErrorStack warning
|
||||
$causes[] = array(
|
||||
'class' => $cause['package'],
|
||||
'message' => $cause['message'],
|
||||
'file' => isset($cause['context']['file']) ?
|
||||
$cause['context']['file'] :
|
||||
'unknown',
|
||||
'line' => isset($cause['context']['line']) ?
|
||||
$cause['context']['line'] :
|
||||
'unknown',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getTraceSafe()
|
||||
{
|
||||
if (!isset($this->_trace)) {
|
||||
$this->_trace = $this->getTrace();
|
||||
if (empty($this->_trace)) {
|
||||
$backtrace = debug_backtrace();
|
||||
$this->_trace = array($backtrace[count($backtrace)-1]);
|
||||
}
|
||||
}
|
||||
return $this->_trace;
|
||||
}
|
||||
|
||||
public function getErrorClass()
|
||||
{
|
||||
$trace = $this->getTraceSafe();
|
||||
return $trace[0]['class'];
|
||||
}
|
||||
|
||||
public function getErrorMethod()
|
||||
{
|
||||
$trace = $this->getTraceSafe();
|
||||
return $trace[0]['function'];
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
if (isset($_SERVER['REQUEST_URI'])) {
|
||||
return $this->toHtml();
|
||||
}
|
||||
return $this->toText();
|
||||
}
|
||||
|
||||
public function toHtml()
|
||||
{
|
||||
$trace = $this->getTraceSafe();
|
||||
$causes = array();
|
||||
$this->getCauseMessage($causes);
|
||||
$html = '<table border="1" cellspacing="0">' . "\n";
|
||||
foreach ($causes as $i => $cause) {
|
||||
$html .= '<tr><td colspan="3" bgcolor="#ff9999">'
|
||||
. str_repeat('-', $i) . ' <b>' . $cause['class'] . '</b>: '
|
||||
. htmlspecialchars($cause['message']) . ' in <b>' . $cause['file'] . '</b> '
|
||||
. 'on line <b>' . $cause['line'] . '</b>'
|
||||
. "</td></tr>\n";
|
||||
}
|
||||
$html .= '<tr><td colspan="3" bgcolor="#aaaaaa" align="center"><b>Exception trace</b></td></tr>' . "\n"
|
||||
. '<tr><td align="center" bgcolor="#cccccc" width="20"><b>#</b></td>'
|
||||
. '<td align="center" bgcolor="#cccccc"><b>Function</b></td>'
|
||||
. '<td align="center" bgcolor="#cccccc"><b>Location</b></td></tr>' . "\n";
|
||||
|
||||
foreach ($trace as $k => $v) {
|
||||
$html .= '<tr><td align="center">' . $k . '</td>'
|
||||
. '<td>';
|
||||
if (!empty($v['class'])) {
|
||||
$html .= $v['class'] . $v['type'];
|
||||
}
|
||||
$html .= $v['function'];
|
||||
$args = array();
|
||||
if (!empty($v['args'])) {
|
||||
foreach ($v['args'] as $arg) {
|
||||
if (is_null($arg)) $args[] = 'null';
|
||||
elseif (is_array($arg)) $args[] = 'Array';
|
||||
elseif (is_object($arg)) $args[] = 'Object('.get_class($arg).')';
|
||||
elseif (is_bool($arg)) $args[] = $arg ? 'true' : 'false';
|
||||
elseif (is_int($arg) || is_double($arg)) $args[] = $arg;
|
||||
else {
|
||||
$arg = (string)$arg;
|
||||
$str = htmlspecialchars(substr($arg, 0, 16));
|
||||
if (strlen($arg) > 16) $str .= '…';
|
||||
$args[] = "'" . $str . "'";
|
||||
}
|
||||
}
|
||||
}
|
||||
$html .= '(' . implode(', ',$args) . ')'
|
||||
. '</td>'
|
||||
. '<td>' . (isset($v['file']) ? $v['file'] : 'unknown')
|
||||
. ':' . (isset($v['line']) ? $v['line'] : 'unknown')
|
||||
. '</td></tr>' . "\n";
|
||||
}
|
||||
$html .= '<tr><td align="center">' . ($k+1) . '</td>'
|
||||
. '<td>{main}</td>'
|
||||
. '<td> </td></tr>' . "\n"
|
||||
. '</table>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function toText()
|
||||
{
|
||||
$causes = array();
|
||||
$this->getCauseMessage($causes);
|
||||
$causeMsg = '';
|
||||
foreach ($causes as $i => $cause) {
|
||||
$causeMsg .= str_repeat(' ', $i) . $cause['class'] . ': '
|
||||
. $cause['message'] . ' in ' . $cause['file']
|
||||
. ' on line ' . $cause['line'] . "\n";
|
||||
}
|
||||
return $causeMsg . $this->getTraceAsString();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
33
libs/PEAR.1.9/PEAR5.php
Normal file
33
libs/PEAR.1.9/PEAR5.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
/**
|
||||
* This is only meant for PHP 5 to get rid of certain strict warning
|
||||
* that doesn't get hidden since it's in the shutdown function
|
||||
*/
|
||||
class PEAR5
|
||||
{
|
||||
/**
|
||||
* If you have a class that's mostly/entirely static, and you need static
|
||||
* properties, you can use this method to simulate them. Eg. in your method(s)
|
||||
* do this: $myVar = &PEAR5::getStaticProperty('myclass', 'myVar');
|
||||
* You MUST use a reference, or they will not persist!
|
||||
*
|
||||
* @access public
|
||||
* @param string $class The calling classname, to prevent clashes
|
||||
* @param string $var The variable to retrieve.
|
||||
* @return mixed A reference to the variable. If not set it will be
|
||||
* auto initialised to NULL.
|
||||
*/
|
||||
static function &getStaticProperty($class, $var)
|
||||
{
|
||||
static $properties;
|
||||
if (!isset($properties[$class])) {
|
||||
$properties[$class] = array();
|
||||
}
|
||||
|
||||
if (!array_key_exists($var, $properties[$class])) {
|
||||
$properties[$class][$var] = null;
|
||||
}
|
||||
|
||||
return $properties[$class][$var];
|
||||
}
|
||||
}
|
||||
|
|
@ -44,10 +44,10 @@
|
|||
<th scope="row"><div>{$var->title}</div></th>
|
||||
<td>
|
||||
<!--@if($var->type == 'text')-->
|
||||
<input type="text" name="{$var->name}" value="{$var->value}" class="inputTypeText w400" />
|
||||
<input type="text" name="{$var->name}" id="{$var->name}" value="{htmlspecialchars($var->value)}" class="inputTypeText w400 lang_code" />
|
||||
|
||||
<!--@elseif($var->type == 'textarea')-->
|
||||
<textarea name="{$var->name}" class="inputTypeTextArea">{$var->value}</textarea>
|
||||
<textarea name="{$var->name}" id="{$var->name}" class="inputTypeTextArea lang_code">{htmlspecialchars($var->value)}</textarea>
|
||||
|
||||
<!--@elseif($var->type == 'select')-->
|
||||
<select name="{$var->name}">
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
@charset "utf-8";
|
||||
@import url("./font.css");
|
||||
@import url("./pagination.css");
|
||||
/* NHN > UIT Center > Open UI Technology Team > Jeong Chan Myeong(dece24@nhncorp.com) */
|
||||
|
||||
#xeAdmin {/* background-color:#fff; */}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
<!--#include("_header.html")-->
|
||||
|
||||
<!--%import("../../install/lang")-->
|
||||
<!--%import("../../module/tpl/js/module_admin.js",optimized=false)-->
|
||||
<!--%import("../../session/tpl/js/session.js",optimized=false)-->
|
||||
<!--%import("../../addon/tpl/js/addon.js",optimized=false)-->
|
||||
<!--%import("../../module/tpl/js/module_admin.js")-->
|
||||
<!--%import("../../session/tpl/js/session.js")-->
|
||||
<!--%import("../../addon/tpl/js/addon.js")-->
|
||||
<!--%import("../../addon/tpl/filter/toggle_activate_addon.xml")-->
|
||||
|
||||
<div class="content">
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
$lang->success_installed = "安裝成功";
|
||||
$lang->view_all_package = "全部檢視";
|
||||
$lang->description_ftp_note = "請先將 FTP 設定好,否則無法執行自動安裝功能。";
|
||||
$lang->description_update = "如果您最近不是用自動安裝模組更新或安裝,請點擊更新按鈕更新。";
|
||||
$lang->description_update = "如果您最近不是用自動安裝模組更新或安裝,請按更新按鈕更新。";
|
||||
$lang->install = "安裝";
|
||||
$lang->update = "更新";
|
||||
$lang->current_version = "版本";
|
||||
|
|
@ -28,8 +28,8 @@
|
|||
$lang->description_download = "如果 FTP 無法使用的話,必須要手動下載並解壓縮到目標路徑。(假設目標路徑為 ./modules/board的話,將檔案解壓縮到 ./modules就可以了)";
|
||||
$lang->path = "路徑";
|
||||
$lang->cmd_download = "下載";
|
||||
$lang->view_installed_packages = "已安裝套裝軟體";
|
||||
$lang->view_installed_packages = "已安裝程式";
|
||||
$lang->msg_ftp_password_input = "請輸入 FTP 密碼";
|
||||
$lang->dependant_list = "이 패키지에 의존하는 패키지 목록";
|
||||
$lang->description_uninstall = "패키지를 삭제합니다. 모듈의 경우 모든 데이터가 사라집니다.";
|
||||
$lang->dependant_list = "與此程式相關程式列表";
|
||||
$lang->description_uninstall = "移除模組,所有資料將會被刪除。";
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
<tr>
|
||||
<th><div>{$lang->column_name}</div></th>
|
||||
<td class="wide">
|
||||
<input type="text" name="name" value="{$selected_var->name}" class="inputTypeText w200" id="name" /><a href="{getUrl('','module','module','act','dispModuleAdminLangcode','target','name')}" onclick="popopen(this.href);return false;" class="buttonSet buttonSetting"><span>{$lang->cmd_find_langcode}</span></a>
|
||||
<input type="text" name="name" value="{htmlspecialchars($selected_var->name)}" class="inputTypeText w200" id="name" /><a href="{getUrl('','module','module','act','dispModuleAdminLangcode','target','name')}" onclick="popopen(this.href);return false;" class="buttonSet buttonSetting"><span>{$lang->cmd_find_langcode}</span></a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
$lang->is_stand_by = '等待';
|
||||
$lang->file_list = '檔案清單';
|
||||
$lang->allow_outlink = '外部檔案連結';
|
||||
$lang->allow_outlink_site = '允許的外連網站';
|
||||
$lang->allow_outlink_site = '允許外連的網站';
|
||||
$lang->allow_outlink_format = '允許外連的副檔名';
|
||||
$lang->allowed_filesize = '檔案大小限制';
|
||||
$lang->allowed_attach_size = '上傳限制';
|
||||
|
|
@ -22,11 +22,11 @@
|
|||
$lang->enable_download_group = '允許下載的群組';
|
||||
|
||||
$lang->about_allow_outlink = '是否允許連結外部檔案。(*.wmv, *.mp3等影音檔案除外)';
|
||||
$lang->about_allow_outlink_format = '設定允許外部連結的檔案格式。可以用(,)來區隔多個副檔名。<br />例)hwp,doc,zip,pdf';
|
||||
$lang->about_allow_outlink_site = '可設置允許外部檔案連結的網站名單。當數量太多時,可換行輸入。<br />例)http://www.zeroboard.com';
|
||||
$lang->about_allowed_filesize = '最大單一上傳檔案大小(管理員不受此限制)。';
|
||||
$lang->about_allowed_attach_size = '每個主題最大上傳檔案大小(管理員不受此限制)。';
|
||||
$lang->about_allowed_filetypes = '設定允許上傳的檔案類型。可以用"*.副檔名"來指定或用";"來區隔多個副檔名。<br />例) *.* or *.jpg;*.gif;<br />(管理員不受此限制)';
|
||||
$lang->about_allow_outlink_format = '設定允許外部連結的檔案格式。可以用逗號(,)來區隔多個副檔名。<br />例) hwp, doc, zip, pdf';
|
||||
$lang->about_allow_outlink_site = '可設置允許外部檔案連結的網站名單。當數量太多時,可換行輸入。<br />例) http://www.zeroboard.com';
|
||||
$lang->about_allowed_filesize = '最大單一上傳檔案大小 (管理員不受此限制)。';
|
||||
$lang->about_allowed_attach_size = '每個主題最大上傳檔案大小 (管理員不受此限制)。';
|
||||
$lang->about_allowed_filetypes = '設定允許上傳的檔案類型。可以用"*.副檔名"來指定或用分號";"來區隔多個副檔名。<br />例) *.* or *.jpg; *.gif;<br />(管理員不受此限制)';
|
||||
|
||||
$lang->cmd_delete_checked_file = '刪除所選項目';
|
||||
$lang->cmd_move_to_document = '檢視原始主題';
|
||||
|
|
@ -34,7 +34,7 @@
|
|||
|
||||
$lang->msg_not_permitted_download = '您不具備下載的權限。';
|
||||
$lang->msg_cart_is_null = ' 請選擇要刪除的檔案。';
|
||||
$lang->msg_checked_file_is_deleted = '已刪除%d個檔案!';
|
||||
$lang->msg_checked_file_is_deleted = '已刪除 %d 個檔案!';
|
||||
$lang->msg_exceeds_limit_size = '已超過系統指定的檔案大小!';
|
||||
$lang->msg_file_not_found = '找不到檔案。';
|
||||
|
||||
|
|
@ -42,8 +42,8 @@
|
|||
'filename' => '檔案名稱',
|
||||
'filesize_more' => '檔案大小 (byte, 以上)',
|
||||
'filesize_mega_more' => '檔案大小 (Mb, 以上)',
|
||||
'filesize_less' => '파일크기 (byte, 이하)',
|
||||
'filesize_mega_less' => '파일크기 (Mb, 이하)',
|
||||
'filesize_less' => '檔案大小 (byte, 以下)',
|
||||
'filesize_mega_less' => '檔案大小 (Mb, 以下)',
|
||||
'download_count' => '下載次數 (以上)',
|
||||
'user_id' => '帳號',
|
||||
'user_name' => '姓名',
|
||||
|
|
@ -51,5 +51,5 @@
|
|||
'regdate' => '登錄日期',
|
||||
'ipaddress' => 'IP位址',
|
||||
);
|
||||
$lang->msg_not_allowed_outlink = 'It is not allowed to download files not from this site.';
|
||||
$lang->msg_not_allowed_outlink = '無法從網站下載檔案。';
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -219,12 +219,14 @@
|
|||
}
|
||||
}
|
||||
|
||||
if($module_name =='textyle'){
|
||||
// 발행이 아닌 것들은 저장상태로
|
||||
if($xmlDoc->post->visibility->body != 'syndicated'){
|
||||
$obj->module_srl = $member_info->member_srl;
|
||||
}
|
||||
}
|
||||
if($module_name == 'textyle') {
|
||||
// 발행 상태의 visibility 값
|
||||
$status_published = array('public', 'syndicated');
|
||||
// 발행이 아닌 것들은 저장상태로
|
||||
if(!in_array($xmlDoc->post->visibility->body, $status_published)) {
|
||||
$obj->module_srl = $member_info->member_srl;
|
||||
}
|
||||
}
|
||||
|
||||
// 문서 입력
|
||||
$output = executeQuery('document.insertDocument', $obj);
|
||||
|
|
|
|||
|
|
@ -17,5 +17,6 @@
|
|||
<action name="procInstallAdminSaveLangSelected" type="controller" standalone="true" />
|
||||
<action name="procInstallAdminSaveFTPInfo" type="controller" standalone="true" />
|
||||
<action name="procInstallAdminRemoveFTPInfo" type="controller" standalone="true" />
|
||||
<action name="getInstallFTPList" type="model" standalone="true" />
|
||||
</actions>
|
||||
</module>
|
||||
|
|
|
|||
|
|
@ -74,9 +74,11 @@
|
|||
**/
|
||||
function procInstallFTP() {
|
||||
if(Context::isInstalled()) return new Object(-1, 'msg_already_installed');
|
||||
$ftp_info = Context::gets('ftp_user','ftp_password','ftp_port');
|
||||
$ftp_info = Context::gets('ftp_host', 'ftp_user','ftp_password','ftp_port','ftp_root_path');
|
||||
$ftp_info->ftp_port = (int)$ftp_info->ftp_port;
|
||||
if(!$ftp_info->ftp_port) $ftp_info->ftp_port = 21;
|
||||
if(!$ftp_info->ftp_host) $ftp_info->ftp_host = '127.0.0.1';
|
||||
if(!$ftp_info->ftp_root_path) $ftp_info->ftp_root_path = '/';
|
||||
|
||||
$buff = '<?php if(!defined("__ZBXE__")) exit();'."\n";
|
||||
foreach($ftp_info as $key => $val) {
|
||||
|
|
@ -90,29 +92,29 @@
|
|||
|
||||
require_once(_XE_PATH_.'libs/ftp.class.php');
|
||||
$oFtp = new ftp();
|
||||
if(!$oFtp->ftp_connect('localhost', $ftp_info->ftp_port)) return new Object(-1,'msg_ftp_not_connected');
|
||||
if(!$oFtp->ftp_connect($ftp_info->ftp_host, $ftp_info->ftp_port)) return new Object(-1,'msg_ftp_not_connected');
|
||||
|
||||
if(!$oFtp->ftp_login($ftp_info->ftp_user, $ftp_info->ftp_password)) {
|
||||
$oFtp->ftp_quit();
|
||||
return new Object(-1,'msg_ftp_invalid_auth_info');
|
||||
}
|
||||
|
||||
if(!is_dir(_XE_PATH_.'files') && !$oFtp->ftp_mkdir(_XE_PATH_.'files')) {
|
||||
if(!is_dir(_XE_PATH_.'files') && !$oFtp->ftp_mkdir($ftp_info->ftp_root_path.'files')) {
|
||||
$oFtp->ftp_quit();
|
||||
return new Object(-1,'msg_ftp_mkdir_fail');
|
||||
}
|
||||
|
||||
if(!$oFtp->ftp_site("CHMOD 777 "._XE_PATH_.'files')) {
|
||||
if(!$oFtp->ftp_site("CHMOD 777 ".$ftp_info->ftp_root_path.'files')) {
|
||||
$oFtp->ftp_quit();
|
||||
return new Object(-1,'msg_ftp_chmod_fail');
|
||||
}
|
||||
|
||||
if(!is_dir(_XE_PATH_.'files/config') && !$oFtp->ftp_mkdir(_XE_PATH_.'files/config')) {
|
||||
if(!is_dir(_XE_PATH_.'files/config') && !$oFtp->ftp_mkdir($ftp_info->ftp_root_path.'files/config')) {
|
||||
$oFtp->ftp_quit();
|
||||
return new Object(-1,'msg_ftp_mkdir_fail');
|
||||
}
|
||||
|
||||
if(!$oFtp->ftp_site("CHMOD 777 "._XE_PATH_.'files/config')) {
|
||||
if(!$oFtp->ftp_site("CHMOD 777 ".$ftp_info->ftp_root_path.'files/config')) {
|
||||
$oFtp->ftp_quit();
|
||||
return new Object(-1,'msg_ftp_chmod_fail');
|
||||
}
|
||||
|
|
|
|||
85
modules/install/install.model.php
Normal file
85
modules/install/install.model.php
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
class installModel extends install {
|
||||
function init() {
|
||||
}
|
||||
var $pwd;
|
||||
|
||||
function getSFTPList()
|
||||
{
|
||||
$ftp_info = Context::getRequestVars();
|
||||
if(!$ftp_info->ftp_host)
|
||||
{
|
||||
$ftp_info->ftp_host = "127.0.0.1";
|
||||
}
|
||||
$connection = ssh2_connect($ftp_info->ftp_host, $ftp_info->ftp_port);
|
||||
if(!ssh2_auth_password($connection, $ftp_info->ftp_user, $ftp_info->ftp_password))
|
||||
{
|
||||
return new Object(-1,'msg_ftp_invalid_auth_info');
|
||||
}
|
||||
|
||||
$sftp = ssh2_sftp($connection);
|
||||
$curpwd = "ssh2.sftp://$sftp".$this->pwd;
|
||||
$dh = @opendir($curpwd);
|
||||
if(!$dh) return new Object(-1, 'msg_ftp_invalid_path');
|
||||
$list = array();
|
||||
while(($file = readdir($dh)) !== false) {
|
||||
if(is_dir($curpwd.$file))
|
||||
{
|
||||
$file .= "/";
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$list[] = $file;
|
||||
}
|
||||
closedir($dh);
|
||||
$this->add('list', $list);
|
||||
}
|
||||
|
||||
function getInstallFTPList()
|
||||
{
|
||||
require_once(_XE_PATH_.'libs/ftp.class.php');
|
||||
$ftp_info = Context::getRequestVars();
|
||||
if(!$ftp_info->ftp_user || !$ftp_info->ftp_password)
|
||||
{
|
||||
return new Object(-1, 'msg_ftp_invalid_auth_info');
|
||||
}
|
||||
$this->pwd = $ftp_info->ftp_root_path;
|
||||
if(!$ftp_info->ftp_host)
|
||||
{
|
||||
$ftp_info->ftp_host = "127.0.0.1";
|
||||
}
|
||||
|
||||
if($ftp_info->sftp == 'Y')
|
||||
{
|
||||
return $this->getSFTPList();
|
||||
}
|
||||
|
||||
$oFtp = new ftp();
|
||||
if($oFtp->ftp_connect($ftp_info->ftp_host, $ftp_info->ftp_port)){
|
||||
if($oFtp->ftp_login($ftp_info->ftp_user, $ftp_info->ftp_password)) {
|
||||
$_list = $oFtp->ftp_rawlist($this->pwd);
|
||||
$oFtp->ftp_quit();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Object(-1,'msg_ftp_invalid_auth_info');
|
||||
}
|
||||
}
|
||||
$list = array();
|
||||
|
||||
if($_list){
|
||||
foreach($_list as $k => $v){
|
||||
$src = null;
|
||||
$src->data = $v;
|
||||
$res = Context::convertEncoding($src);
|
||||
$v = $res->data;
|
||||
if(strpos($v,'d') === 0 || strpos($v, '<DIR>')) $list[] = substr(strrchr($v,' '),1) . '/';
|
||||
}
|
||||
}
|
||||
$this->add('list', $list);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -548,4 +548,6 @@ EndOfLicense;
|
|||
$lang->msg_table_is_exists = "Table is already created in the DB.\nConfig file is recreated";
|
||||
$lang->msg_install_completed = "Installation has been completed.\nThank you for choosing XE";
|
||||
$lang->msg_install_failed = "An error has occurred while creating installation file.";
|
||||
|
||||
$lang->ftp_get_list = "Get List";
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -547,4 +547,6 @@ EndOfLicense;
|
|||
$lang->msg_table_is_exists = "La tabla ya ha sido creado en BD.\n Creado nuevamente el archivo de configuración.";
|
||||
$lang->msg_install_completed = "Instalación finalizada.\n Muchas gracias.";
|
||||
$lang->msg_install_failed = "Ha ocurrido un error al crear el archivo de instalación.";
|
||||
|
||||
$lang->ftp_get_list = "Get List";
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -551,4 +551,6 @@ EndOfLicense;
|
|||
$lang->msg_table_is_exists = "La Table est déjà créée dans la Base de Données.\nLe fichier de Configuration est recréé.";
|
||||
$lang->msg_install_completed = "Installation a complété.\nMerci pour choisir XE";
|
||||
$lang->msg_install_failed = "Une erreur a lieu en créant le fichier d\'installation.";
|
||||
|
||||
$lang->ftp_get_list = "Get List";
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -548,4 +548,6 @@ EndOfLicense;
|
|||
$lang->msg_table_is_exists = "既にデータベースにデーブルが作成されています。\nconfigファイルを再作成しました。";
|
||||
$lang->msg_install_completed = "インストールが完了しました。\nありがとうございます。";
|
||||
$lang->msg_install_failed = 'インストールファイルを作成する際にエラーが発生しました。';
|
||||
|
||||
$lang->ftp_get_list = "Get List";
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -550,4 +550,6 @@ EndOfLicense;
|
|||
$lang->msg_table_is_exists = "이미 DB에 테이블이 생성되어 있습니다.\nconfig파일을 재생성하였습니다.";
|
||||
$lang->msg_install_completed = "설치가 완료되었습니다.\n감사합니다.";
|
||||
$lang->msg_install_failed = '설치 파일 생성 시에 오류가 발생하였습니다.';
|
||||
|
||||
$lang->ftp_get_list = '목록 가져오기';
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -550,4 +550,6 @@ EndOfLicense;
|
|||
$lang->msg_table_is_exists = "Таблица существует в базе данных.\nФайл конфигурации создан заново";
|
||||
$lang->msg_install_completed = "Установка завершена.\nСпасибо Вам за выбор XE";
|
||||
$lang->msg_install_failed = "Произошла ошибка при создании файла конфигурации.";
|
||||
|
||||
$lang->ftp_get_list = 'Get List';
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -551,4 +551,6 @@ EndOfLicense;
|
|||
$lang->msg_table_is_exists = "Table đã có sẵn trên Database.\nFile Config đã đuwọc thiết lập lại.";
|
||||
$lang->msg_install_completed = "Đã cài đặt thành công!.\nXin cảm ơn đã sử dụng XE!";
|
||||
$lang->msg_install_failed = "Đã có lỗi xảy ra khi tạo File cài đặt.";
|
||||
|
||||
$lang->ftp_get_list = "Get List";
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -546,4 +546,6 @@ EndOfLicense;
|
|||
$lang->msg_table_is_exists = "已生成数据表。\n重新生成了config文件。";
|
||||
$lang->msg_install_completed = "安装完成。\n非常感谢。";
|
||||
$lang->msg_install_failed = "生成安装文件时发生错误。";
|
||||
|
||||
$lang->ftp_get_list = "Get List";
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -549,4 +549,6 @@ EndOfLicense;
|
|||
$lang->msg_table_is_exists = "已建立資料表。\n重新建立 config 檔案。";
|
||||
$lang->msg_install_completed = "安裝完成。\n非常感謝。";
|
||||
$lang->msg_install_failed = "建立安裝檔案時,發生錯誤。";
|
||||
|
||||
$lang->ftp_get_list = "取得列表";
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
<h2 class="xeAdmin">{$lang->ftp_form_title}</h2>
|
||||
|
||||
<blockquote>{$lang->about_ftp_info}</blockquote>
|
||||
<blockquote>{$lang->msg_safe_mode_ftp_needed}</blockquote>
|
||||
|
||||
<table cellspacing="0" class="tableType7">
|
||||
<col width="100" />
|
||||
|
|
@ -14,17 +14,34 @@
|
|||
|
||||
<!-- FTP 정보 -->
|
||||
<tr>
|
||||
<th rowspan="3" scope="row" class="hr"><label for="radio2">{$lang->ftp}</label></th>
|
||||
<th rowspan="6" scope="row" class="hr"><label for="radio2">{$lang->ftp}</label></th>
|
||||
<th class="second" scope="row"><label for="textfield20">{$lang->ftp_host}</label></th>
|
||||
<td><input type="text" id="textfield20" name="ftp_host" value="127.0.0.1" class="inputTypeText" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="second" scope="row"><label for="textfield21">{$lang->user_id}</label></th>
|
||||
<td><input type="text" id="textfield21" name="ftp_user" value="" class="inputTypeText" /></td>
|
||||
</tr>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="second" scope="row"><label for="textfield22">{$lang->password}</label></th>
|
||||
<td><input id="textfield22" type="password" name="ftp_password" class="inputTypeText" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="second hr" scope="row"><label for="textfield24">{$lang->ftp_port}</label></th>
|
||||
<td class="hr"><input id="textfield24" type="text" name="ftp_port" value="21" class="inputTypeText" /></td>
|
||||
<th class="second" scope="row"><label for="textfield24">{$lang->ftp_port}</label></th>
|
||||
<td><input id="textfield24" type="text" name="ftp_port" value="21" class="inputTypeText" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="second hr" scope="row" rowspan="2"><div>{$lang->msg_ftp_installed_ftp_realpath}<br /><br/>{$lang->msg_ftp_installed_realpath}:<br/> {_XE_PATH_}</div></th>
|
||||
<td>
|
||||
<input type="text" name="ftp_root_path" value="{$ftp_info->ftp_root_path}" class="inputTypeText w400" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="ftplist">
|
||||
<td class="hr">
|
||||
<div>
|
||||
<span class="button blue strong"><input type="button" onclick="getFTPList(); return false;" value="{$lang->ftp_get_list}"></span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
|
|
|||
|
|
@ -36,3 +36,75 @@ function completeInstallCheckFtpInfo(ret_obj) {
|
|||
function completeFtpPath(ret_obj){
|
||||
location.reload();
|
||||
}
|
||||
|
||||
function getFTPList(pwd)
|
||||
{
|
||||
var form = jQuery("#ftp_form").get(0);
|
||||
if(typeof(pwd) != 'undefined')
|
||||
{
|
||||
form.ftp_root_path.value = pwd;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!form.ftp_root_path.value)
|
||||
{
|
||||
if(typeof(form.sftp) != 'undefined' && form.sftp.checked) {
|
||||
form.ftp_root_path.value = xe_root;
|
||||
}
|
||||
else
|
||||
{
|
||||
form.ftp_root_path.value = "/";
|
||||
}
|
||||
}
|
||||
}
|
||||
var params={}, data=jQuery("#ftp_form").serializeArray();
|
||||
jQuery.each(data, function(i, field){ params[field.name] = field.value });
|
||||
exec_xml('install', 'getInstallFTPList', params, completeGetFtpInfo, ['list', 'error', 'message'], params, form);
|
||||
}
|
||||
|
||||
function completeGetFtpInfo(ret_obj)
|
||||
{
|
||||
if(ret_obj['error'] != 0)
|
||||
{
|
||||
alert(ret_obj['error']);
|
||||
alert(ret_obj['message']);
|
||||
return;
|
||||
}
|
||||
var e = jQuery("#ftplist").empty();
|
||||
var list = "";
|
||||
if(!jQuery.isArray(ret_obj['list']['item']))
|
||||
{
|
||||
ret_obj['list']['item'] = [ret_obj['list']['item']];
|
||||
}
|
||||
|
||||
pwd = jQuery("#ftp_form").get(0).ftp_root_path.value;
|
||||
if(pwd != "/")
|
||||
{
|
||||
arr = pwd.split("/");
|
||||
arr.pop();
|
||||
arr.pop();
|
||||
arr.push("");
|
||||
target = arr.join("/");
|
||||
list = list + "<li><a href='#ftpSetup' onclick=\"getFTPList('"+target+"')\">../</a></li>";
|
||||
}
|
||||
|
||||
for(var i=0;i<ret_obj['list']['item'].length;i++)
|
||||
{
|
||||
var v = ret_obj['list']['item'][i];
|
||||
if(v == "../")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if( v == "./")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
list = list + "<li><a href='#ftpSetup' onclick=\"getFTPList('"+pwd+v+"')\">"+v+"</a></li>";
|
||||
}
|
||||
}
|
||||
|
||||
list = "<td><ul>"+list+"</ul></td>";
|
||||
e.append(jQuery(list));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -362,7 +362,7 @@ function Auth_OpenID_detectMathLibrary($exts)
|
|||
// Try to load dynamic modules.
|
||||
if (!$loaded) {
|
||||
foreach ($extension['modules'] as $module) {
|
||||
if (@dl($module . "." . PHP_SHLIB_SUFFIX)) {
|
||||
if (function_exists('dl') && @dl($module . "." . PHP_SHLIB_SUFFIX)) {
|
||||
$loaded = true;
|
||||
break;
|
||||
}
|
||||
|
|
@ -441,4 +441,4 @@ function &Auth_OpenID_getMathLib()
|
|||
return $lib;
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,71 +1,59 @@
|
|||
/* 한국 우편 번호 관련 */
|
||||
function doHideKrZipList(column_name) {
|
||||
var zone_list_obj = xGetElementById('zone_address_list_'+column_name);
|
||||
var zone_search_obj = xGetElementById('zone_address_search_'+column_name);
|
||||
var zone_addr1_obj = xGetElementById('zone_address_1_'+column_name);
|
||||
var addr1_obj = xGetElementById('fo_insert_member')[column_name][0];
|
||||
var field_obj = xGetElementById('fo_insert_member')['_tmp_address_search_'+column_name];
|
||||
var $j = jQuery;
|
||||
$j('#zone_address_list_'+column_name).hide();
|
||||
$j('#zone_address_search_'+column_name).show();
|
||||
$j('#zone_address_1_'+column_name).hide();
|
||||
|
||||
zone_addr1_obj.style.display = 'none';
|
||||
zone_list_obj.style.display = 'none';
|
||||
zone_search_obj.style.display = 'inline';
|
||||
addr1_obj.value = '';
|
||||
field_obj.focus();
|
||||
var form = $j('#fo_insert_member');
|
||||
form.find('select[name=_tmp_address_list_'+column_name+']').focus();
|
||||
form.find('input[name='+column_name+']').eq(0).val('');
|
||||
}
|
||||
|
||||
function doSelectKrZip(column_name) {
|
||||
var zone_list_obj = xGetElementById('zone_address_list_'+column_name);
|
||||
var zone_search_obj = xGetElementById('zone_address_search_'+column_name);
|
||||
var zone_addr1_obj = xGetElementById('zone_address_1_'+column_name);
|
||||
var sel_obj = xGetElementById('fo_insert_member')['_tmp_address_list_'+column_name];
|
||||
var value = sel_obj.options[sel_obj.selectedIndex].value;
|
||||
var addr1_obj = xGetElementById('fo_insert_member')[column_name][0];
|
||||
var addr2_obj = xGetElementById('fo_insert_member')[column_name][1];
|
||||
addr1_obj.value = value;
|
||||
zone_search_obj.style.display = 'none';
|
||||
zone_list_obj.style.display = 'none';
|
||||
zone_addr1_obj.style.display = 'inline';
|
||||
addr2_obj.focus();
|
||||
var $j = jQuery;
|
||||
$j('#zone_address_list_'+column_name).hide();
|
||||
$j('#zone_address_search_'+column_name).hide();
|
||||
$j('#zone_address_1_'+column_name).show();
|
||||
|
||||
var form = $j('#fo_insert_member');
|
||||
var val = form.find('select[name=_tmp_address_list_'+column_name+']').val();
|
||||
var addr = form.find('input[name='+column_name+']');
|
||||
|
||||
addr.eq(0).val(val);
|
||||
addr.eq(1).focus();
|
||||
}
|
||||
|
||||
function doSearchKrZip(column_name) {
|
||||
var field_obj = xGetElementById('fo_insert_member')['_tmp_address_search_'+column_name];
|
||||
var addr = field_obj.value;
|
||||
if(!addr) return;
|
||||
var field = jQuery('#fo_insert_member input[name=_tmp_address_search_'+column_name+']');
|
||||
var _addr = field.val();
|
||||
if(!_addr) return;
|
||||
|
||||
var params = new Array();
|
||||
params['addr'] = addr;
|
||||
params['column_name'] = column_name;
|
||||
var params = {
|
||||
addr : _addr,
|
||||
column_name : column_name
|
||||
};
|
||||
|
||||
var response_tags = new Array('error','message','address_list');
|
||||
exec_xml('krzip', 'getKrzipCodeList', params, completeSearchKrZip, response_tags, params);
|
||||
var response_tags = ['error','message','address_list'];
|
||||
|
||||
exec_xml('krzip', 'getKrzipCodeList', params, completeSearchKrZip, response_tags, params);
|
||||
}
|
||||
|
||||
function completeSearchKrZip(ret_obj, response_tags, callback_args) {
|
||||
if(!ret_obj['address_list']) {
|
||||
alert(alert_msg['address']);
|
||||
return;
|
||||
}
|
||||
var address_list = ret_obj['address_list'].split("\n");
|
||||
var column_name = callback_args['column_name'];
|
||||
if(!ret_obj['address_list']) {
|
||||
alert(alert_msg['address']);
|
||||
return;
|
||||
}
|
||||
|
||||
var zone_list_obj = xGetElementById('zone_address_list_'+column_name);
|
||||
var zone_search_obj = xGetElementById('zone_address_search_'+column_name);
|
||||
var zone_addr1_obj = xGetElementById('zone_address_1_'+column_name);
|
||||
var sel_obj = xGetElementById('fo_insert_member')['_tmp_address_list_'+column_name];
|
||||
var address_list = ret_obj['address_list'].split('\n');
|
||||
var column_name = callback_args['column_name'];
|
||||
|
||||
for(var i=0;i<address_list.length;i++) {
|
||||
var opt = new Option(address_list[i],address_list[i],false,false);
|
||||
sel_obj.options[i] = opt;
|
||||
}
|
||||
var $j = jQuery;
|
||||
|
||||
address_list = $j.map(address_list, function(addr){ return '<option value="'+addr+'">'+addr+'</option>'; });
|
||||
|
||||
for(var i=address_list.length-1;i<sel_obj.options.length;i++) {
|
||||
sel_obj.remove(i);
|
||||
}
|
||||
|
||||
sel_obj.selectedIndex = 0;
|
||||
|
||||
zone_search_obj.style.display = 'none';
|
||||
zone_addr1_obj.style.display = 'none';
|
||||
zone_list_obj.style.display = 'inline';
|
||||
}
|
||||
$j('#zone_address_list_'+column_name).show();
|
||||
$j('#zone_address_search_'+column_name).hide();
|
||||
$j('#zone_address_1_'+column_name).hide();
|
||||
$j('#fo_insert_member select[name=_tmp_address_list_'+column_name+']').html(address_list.join('')).get(0).selectedIndex = 0;
|
||||
}
|
||||
|
|
@ -341,15 +341,14 @@ function completeDeleteMembers(ret_obj) {
|
|||
|
||||
|
||||
function doGorupImageMarkUpdateOrder(id) {
|
||||
var sort = jQuery('#'+id).sortable('toArray');
|
||||
|
||||
var params = [];
|
||||
params['group_image_mark_order'] = [];
|
||||
var sort = jQuery('#'+id).sortable('toArray');
|
||||
var params = { group_image_mark_order : [] };
|
||||
|
||||
jQuery.each(sort, function(i, val) {
|
||||
params['group_image_mark_order'][params['group_image_mark_order'].length] = val.replace('group_srl_', '');
|
||||
params['group_image_mark_order'].push(val.replace('group_srl_', ''));
|
||||
});
|
||||
|
||||
var response_tags = new Array('error','message');
|
||||
var response_tags = ['error','message'];
|
||||
exec_xml('member', 'procMemberAdminGroupImageMarkUpdateOrder', params, completeGroupImageMarkUpdateOrder, response_tags);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,71 +6,44 @@
|
|||
// 입력이 시작된 것과 입력후 정해진 시간동안 내용이 변하였을 경우 서버에 ajax로 체크를 하기 위한 변수 설정
|
||||
var memberCheckObj = { target:null, value:null }
|
||||
|
||||
// onload시에 특정 필드들에 대해 이벤트를 걸어 놓음
|
||||
xAddEventListener(window, 'load', memberSetEvent);
|
||||
// domready시에 특정 필드들에 대해 이벤트를 걸어 놓음
|
||||
jQuery(document).ready(memberSetEvent);
|
||||
|
||||
function memberSetEvent() {
|
||||
var fo_obj = xGetElementById('fo_insert_member');
|
||||
for(var node_name in fo_obj) {
|
||||
var obj = fo_obj[node_name];
|
||||
if(!obj || typeof(obj.nodeName)=="undefined" || obj.nodeName != "INPUT") continue;
|
||||
if(node_name != "user_id" && node_name != "nick_name" && node_name != "email_address") continue;
|
||||
|
||||
xAddEventListener(obj, 'blur', memberCheckValue);
|
||||
}
|
||||
jQuery('#fo_insert_member :input')
|
||||
.filter('[name=user_id],[name=nick_name],[name=email_address]')
|
||||
.blur(memberCheckValue);
|
||||
}
|
||||
|
||||
|
||||
// 실제 서버에 특정 필드의 value check를 요청하고 이상이 있으면 메세지를 뿌려주는 함수
|
||||
function memberCheckValue(evt) {
|
||||
var e = new xEvent(evt);
|
||||
var obj = e.target;
|
||||
function memberCheckValue(event) {
|
||||
var field = event.target;
|
||||
var _name = field.name;
|
||||
var _value = field.value;
|
||||
if(!_name || !_value) return;
|
||||
|
||||
var name = obj.name;
|
||||
var value = obj.value;
|
||||
if(!name || !value) return;
|
||||
var params = new Array();
|
||||
params['name'] = name;
|
||||
params['value'] = value;
|
||||
|
||||
var response_tags = new Array('error','message');
|
||||
|
||||
exec_xml('member','procMemberCheckValue', params, completeMemberCheckValue, response_tags, e);
|
||||
var params = {name:_name, value:_value};
|
||||
var response_tags = ['error','message'];
|
||||
|
||||
exec_xml('member','procMemberCheckValue', params, completeMemberCheckValue, response_tags, field);
|
||||
}
|
||||
|
||||
// 서버에서 응답이 올 경우 이상이 있으면 메세지를 출력
|
||||
function completeMemberCheckValue(ret_obj, response_tags, e) {
|
||||
var obj = e.target;
|
||||
var name = obj.name;
|
||||
|
||||
function completeMemberCheckValue(ret_obj, response_tags, field) {
|
||||
var _id = 'dummy_check'+field.name;
|
||||
var dummy = jQuery('#'+_id);
|
||||
|
||||
if(ret_obj['message']=='success') {
|
||||
var dummy_id = 'dummy_check_'+name;
|
||||
var dummy = xGetElementById(dummy_id);
|
||||
if(dummy) {
|
||||
xInnerHtml(dummy,'');
|
||||
dummy.style.display = 'none';
|
||||
}
|
||||
dummy.html('').hide();
|
||||
return;
|
||||
}
|
||||
|
||||
var dummy_id = 'dummy_check_'+name;
|
||||
var dummy = null;
|
||||
if(! (dummy = xGetElementById(dummy_id)) ) {
|
||||
dummy = xCreateElement('DIV');
|
||||
dummy.id = dummy_id;
|
||||
dummy.className = "checkValue";
|
||||
obj.parentNode.insertBefore(dummy, obj.lastChild);
|
||||
}
|
||||
if (!dummy.length) {
|
||||
dummy = jQuery('<div class="checkValue" />').attr('id', _id).appendTo(field.parentNode);
|
||||
}
|
||||
|
||||
xInnerHtml(dummy, ret_obj['message']);
|
||||
|
||||
dummy.style.display = "block";
|
||||
|
||||
//obj.focus();
|
||||
|
||||
// 3초 정도 후에 정리
|
||||
//setTimeout(function() { removeMemberCheckValueOutput(dummy, obj); }, 3000);
|
||||
dummy.html(ret_obj['message']).show();
|
||||
}
|
||||
|
||||
// 결과 메세지를 정리하는 함수
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<!--%import("js/menu_admin.js")-->
|
||||
<div id="popHeader" class="wide">
|
||||
<!--%import("../../common/css/popup.css")-->
|
||||
|
||||
<div id="popHeader">
|
||||
<h3 class="xeAdmin">{$lang->cmd_search_mid}</h3>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -162,10 +162,12 @@ function completeDeleteLang(ret_obj) {
|
|||
}
|
||||
|
||||
function doFillLangName() {
|
||||
var fo_obj = xGetElementById("menu_fo");
|
||||
var target = fo_obj.target.value;
|
||||
if(window.opener && window.opener.xGetElementById(target)) {
|
||||
var value = window.opener.xGetElementById(target).value;
|
||||
if (/[\?&]name=/i.test(location.search)) return;
|
||||
|
||||
var $form = jQuery("#menu_fo");
|
||||
var target = $form[0].target.value;
|
||||
if(window.opener && window.opener.document.getElementById(target)) {
|
||||
var value = window.opener.document.getElementById(target).value;
|
||||
if(/^\$user_lang->/.test(value)) {
|
||||
var param = new Array();
|
||||
param['name'] = value.replace(/^\$user_lang->/,'');
|
||||
|
|
@ -176,13 +178,13 @@ function doFillLangName() {
|
|||
}
|
||||
|
||||
function completeFillLangName(ret_obj, response_tags) {
|
||||
var name = ret_obj['name'];
|
||||
var name = ret_obj['name'];
|
||||
var langs = ret_obj['langs'];
|
||||
if(typeof(langs)=='undefined') return;
|
||||
var fo_obj = xGetElementById("menu_fo");
|
||||
fo_obj.lang_code.value = name;
|
||||
var $form = jQuery("#menu_fo");
|
||||
$form[0].lang_code.value = name;
|
||||
for(var i in langs) {
|
||||
fo_obj[i].value = langs[i];
|
||||
$form[0][i].value = langs[i];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
<!--%import("./filter/insert_lang.xml")-->
|
||||
<!--%import("./js/module_admin.js")-->
|
||||
<!--%import("../../common/css/popup.css")-->
|
||||
|
||||
<div id="popHeader" class="wide">
|
||||
<div id="popHeader">
|
||||
<h3 class="xeAdmin">{$lang->lang_code}</h3>
|
||||
</div>
|
||||
|
||||
<div id="popBody" style="width:700px;">
|
||||
<table cellspacing="0" class="colTable" style="width:700px;">
|
||||
<div id="popBody">
|
||||
<table cellspacing="0" class="colTable">
|
||||
<col width="50%"/>
|
||||
<col width="50%"/>
|
||||
<tr>
|
||||
|
|
@ -60,5 +61,5 @@
|
|||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
xAddEventListener(window,'load', doFillLangName);
|
||||
jQuery(function(){ doFillLangName() });
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<!--%import("./js/module_admin.js")-->
|
||||
<!--%import("../../common/css/popup.css")-->
|
||||
|
||||
<div id="popHeader" class="wide">
|
||||
<div id="popHeader">
|
||||
<h3 class="xeAdmin">{$lang->module_selector}</h3>
|
||||
</div>
|
||||
|
||||
|
|
@ -74,5 +75,4 @@
|
|||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
Loading…
Add table
Add a link
Reference in a new issue