mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-04 01:01:41 +09:00
Merge branch 'develop' into fix-debug
This commit is contained in:
commit
cecc20cc8e
165 changed files with 3331 additions and 7053 deletions
|
|
@ -915,25 +915,28 @@ class Context
|
|||
/**
|
||||
* Convert strings of variables in $source_object into UTF-8
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @param object $source_obj Conatins strings to convert
|
||||
* @return object converted object
|
||||
*/
|
||||
public static function convertEncoding($source_obj)
|
||||
{
|
||||
$charset_list = array(
|
||||
'UTF-8', 'EUC-KR', 'CP949', 'ISO8859-1', 'EUC-JP', 'SHIFT_JIS',
|
||||
'CP932', 'EUC-CN', 'HZ', 'GBK', 'GB18030', 'EUC-TW', 'BIG5',
|
||||
'UTF-8', 'CP949', 'EUC-KR', 'ISO8859-1', 'EUC-JP', 'SHIFT_JIS',
|
||||
'CP932', 'EUC-CN', 'GBK', 'GB18030', 'EUC-TW', 'BIG5',
|
||||
'CP950', 'BIG5-HKSCS', 'ISO8859-6', 'ISO8859-8', 'JOHAB', 'CP1255',
|
||||
'CP1256', 'CP862', 'ASCII', 'ISO8859-1', 'CP1250', 'CP1251',
|
||||
'CP1252', 'CP1253', 'CP1254', 'CP1257', 'CP850', 'CP866'
|
||||
);
|
||||
|
||||
$flag = true;
|
||||
$obj = clone $source_obj;
|
||||
|
||||
foreach($charset_list as $charset)
|
||||
{
|
||||
array_walk($obj,'Context::checkConvertFlag',$charset);
|
||||
$flag = self::checkConvertFlag($flag = TRUE);
|
||||
$flag = self::checkConvertFlag($flag);
|
||||
if($flag)
|
||||
{
|
||||
if($charset == 'UTF-8')
|
||||
|
|
@ -950,6 +953,8 @@ class Context
|
|||
/**
|
||||
* Check flag
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @param mixed $val
|
||||
* @param string $key
|
||||
* @param mixed $charset charset
|
||||
|
|
@ -977,6 +982,8 @@ class Context
|
|||
/**
|
||||
* Convert array type variables into UTF-8
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @param mixed $val
|
||||
* @param string $key
|
||||
* @param string $charset character set
|
||||
|
|
@ -998,6 +1005,8 @@ class Context
|
|||
/**
|
||||
* Convert strings into UTF-8
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @param string $str String to convert
|
||||
* @return string converted string
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -276,127 +276,89 @@ class FileHandler
|
|||
* @param string[] $headers Headers key value array.
|
||||
* @param string[] $cookies Cookies key value array.
|
||||
* @param string $post_data Request arguments array for POST method
|
||||
* @param array $settings Any additional settings
|
||||
* @return string If success, the content of the target file. Otherwise: none
|
||||
*/
|
||||
public static function getRemoteResource($url, $body = null, $timeout = 3, $method = 'GET', $content_type = null, $headers = array(), $cookies = array(), $post_data = array(), $request_config = array())
|
||||
public static function getRemoteResource($url, $body = null, $timeout = 3, $method = 'GET', $content_type = null, $headers = array(), $cookies = array(), $post_data = array(), $settings = array())
|
||||
{
|
||||
try
|
||||
// This method converts erroneously escaped ampersands. The HTTP class doesn't.
|
||||
$url = str_replace('&', '&', $url);
|
||||
|
||||
// Convert backward-compatible parameters to a format accepted by the HTTP class.
|
||||
$converted_headers = [];
|
||||
$converted_cookies = [];
|
||||
$converted_settings = ['timeout' => $timeout];
|
||||
|
||||
// Add headers.
|
||||
foreach ($headers as $key => $val)
|
||||
{
|
||||
$host = parse_url($url, PHP_URL_HOST);
|
||||
$request_headers = array();
|
||||
$request_cookies = array();
|
||||
$request_options = array(
|
||||
'verify' => \RX_BASEDIR . 'common/vendor/composer/ca-bundle/res/cacert.pem',
|
||||
'timeout' => $timeout,
|
||||
);
|
||||
$converted_headers[strval($key)] = strval($val);
|
||||
}
|
||||
|
||||
foreach($headers as $key => $val)
|
||||
// Add cookies.
|
||||
$host = parse_url($url, PHP_URL_HOST);
|
||||
if (isset($cookies[$host]) && is_array($cookies[$host]))
|
||||
{
|
||||
foreach($cookies[$host] as $key => $val)
|
||||
{
|
||||
$request_headers[$key] = $val;
|
||||
$converted_cookies[strval($key)] = strval($val);
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($cookies[$host]) && is_array($cookies[$host]))
|
||||
// Add the request body and its content type.
|
||||
if ($content_type)
|
||||
{
|
||||
$converted_headers['Content-Type'] = $content_type;
|
||||
}
|
||||
|
||||
// Add other settings, converting old format to the new format as necessary.
|
||||
foreach ($settings as $key => $val)
|
||||
{
|
||||
if ($key === 'filename')
|
||||
{
|
||||
foreach($cookies[$host] as $key => $val)
|
||||
{
|
||||
$request_cookies[] = rawurlencode($key) . '=' . rawurlencode($val);
|
||||
}
|
||||
$converted_settings['sink'] = $val;
|
||||
}
|
||||
if(count($request_cookies))
|
||||
elseif ($key === 'follow_redirects')
|
||||
{
|
||||
$request_headers['Cookie'] = implode('; ', $request_cookies);
|
||||
$converted_settings['allow_redirects'] = true;
|
||||
}
|
||||
|
||||
foreach($request_config as $key => $val)
|
||||
elseif ($key === 'redirects' && $val > 0)
|
||||
{
|
||||
$request_options[$key] = $val;
|
||||
$converted_settings['allow_redirects'] = ['max' => intval($val)];
|
||||
}
|
||||
|
||||
if($content_type)
|
||||
elseif ($key === 'useragent')
|
||||
{
|
||||
$request_headers['Content-Type'] = $content_type;
|
||||
}
|
||||
|
||||
if(defined('__PROXY_SERVER__'))
|
||||
{
|
||||
$proxy = parse_url(__PROXY_SERVER__);
|
||||
if($proxy["host"])
|
||||
{
|
||||
$request_options['proxy'] = array($proxy['host'] . ($proxy['port'] ? (':' . $proxy['port']) : ''));
|
||||
if($proxy['user'] && $proxy['pass'])
|
||||
{
|
||||
$request_options['proxy'][] = $proxy['user'];
|
||||
$request_options['proxy'][] = $proxy['pass'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$url = str_replace('&', '&', $url);
|
||||
$start_time = microtime(true);
|
||||
$response = Requests::request($url, $request_headers, $body ?: $post_data, $method, $request_options);
|
||||
$elapsed_time = microtime(true) - $start_time;
|
||||
if (!isset($GLOBALS['__remote_request_elapsed__']))
|
||||
{
|
||||
$GLOBALS['__remote_request_elapsed__'] = 0;
|
||||
}
|
||||
$GLOBALS['__remote_request_elapsed__'] += $elapsed_time;
|
||||
|
||||
$log = array();
|
||||
$log['url'] = $url;
|
||||
$log['status'] = $response ? $response->status_code : 0;
|
||||
$log['elapsed_time'] = $elapsed_time;
|
||||
|
||||
if (Rhymix\Framework\Debug::isEnabledForCurrentUser())
|
||||
{
|
||||
if (in_array('slow_remote_requests', config('debug.display_content')))
|
||||
{
|
||||
$bt = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||
foreach($bt as $no => $call)
|
||||
{
|
||||
if(strncasecmp($call['function'], 'getRemote', 9) === 0)
|
||||
{
|
||||
$call_no = $no + 1;
|
||||
$log['called_file'] = $bt[$call_no]['file'];
|
||||
$log['called_line'] = $bt[$call_no]['line'];
|
||||
$call_no++;
|
||||
$log['called_method'] = $bt[$call_no]['class'].$bt[$call_no]['type'].$bt[$call_no]['function'];
|
||||
$log['backtrace'] = array_slice($bt, $call_no, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$log['called_file'] = $log['called_line'] = $log['called_method'] = null;
|
||||
$log['backtrace'] = array();
|
||||
}
|
||||
Rhymix\Framework\Debug::addRemoteRequest($log);
|
||||
}
|
||||
|
||||
foreach($response->cookies as $cookie)
|
||||
{
|
||||
$cookies[$host][$cookie->name] = $cookie->value;
|
||||
}
|
||||
|
||||
if($response->success)
|
||||
{
|
||||
if (isset($request_config['filename']))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $response->body;
|
||||
}
|
||||
$converted_headers['User-Agent'] = $val;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
$converted_settings[$key] = $val;
|
||||
}
|
||||
}
|
||||
catch(Exception $e)
|
||||
|
||||
// Pass to HTTP::request(), using Guzzle behind the scenes.
|
||||
$response = \Rhymix\Framework\HTTP::request($url, strval($method),
|
||||
$body ?: $post_data,
|
||||
$converted_headers,
|
||||
$converted_cookies,
|
||||
$converted_settings
|
||||
);
|
||||
|
||||
// Return the response body.
|
||||
if ($response->getStatusCode() === 200)
|
||||
{
|
||||
return NULL;
|
||||
if (isset($converted_settings['sink']))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $response->getBody()->getContents();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -420,7 +382,7 @@ class FileHandler
|
|||
return false;
|
||||
}
|
||||
|
||||
$request_config['filename'] = $target_filename;
|
||||
$request_config['sink'] = $target_filename;
|
||||
$success = self::getRemoteResource($url, $body, $timeout, $method, $content_type, $headers, $cookies, $post_data, $request_config);
|
||||
return $success ? true : false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ class ModuleHandler extends Handler
|
|||
$this->is_mobile = Mobile::isFromMobilePhone();
|
||||
if($entry = Context::get('entry'))
|
||||
{
|
||||
$this->entry = Context::convertEncodingStr($entry);
|
||||
$this->entry = escape($entry, false);
|
||||
}
|
||||
if(!$this->module && $this->mid === 'admin')
|
||||
{
|
||||
|
|
@ -733,7 +733,12 @@ class ModuleHandler extends Handler
|
|||
/**
|
||||
* Check the value of $document_srl. This method is called during init().
|
||||
*
|
||||
* @return object|false
|
||||
* This method returns:
|
||||
* - Module info object if the document can be shown in the module,
|
||||
* - null if the document can be shown but the module is unspecified,
|
||||
* - false if we should redirect to another module.
|
||||
*
|
||||
* @return object|null|false
|
||||
*/
|
||||
protected function _checkDocumentSrl()
|
||||
{
|
||||
|
|
@ -745,7 +750,7 @@ class ModuleHandler extends Handler
|
|||
if(!$this->mid || $this->mid !== $module_info->mid)
|
||||
{
|
||||
// If the document is notice-all, preserve the current mid.
|
||||
if($module_info->is_notice === 'A')
|
||||
if($module_info->is_notice === 'A' && !empty($this->mid))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
|
@ -944,7 +949,15 @@ class ModuleHandler extends Handler
|
|||
}
|
||||
|
||||
self::_setInputErrorToContext();
|
||||
$oMessageObject = MessageView::getInstance();
|
||||
|
||||
if (Mobile::isFromMobilePhone())
|
||||
{
|
||||
$oMessageObject = MessageMobile::getInstance();
|
||||
}
|
||||
else
|
||||
{
|
||||
$oMessageObject = MessageView::getInstance();
|
||||
}
|
||||
$oMessageObject->setError($error);
|
||||
$oMessageObject->setMessage($message);
|
||||
$oMessageObject->setHttpStatusCode($status_code ?: 403);
|
||||
|
|
|
|||
|
|
@ -228,7 +228,8 @@ class ModuleObject extends BaseObject
|
|||
}
|
||||
catch (Rhymix\Framework\Exception $e)
|
||||
{
|
||||
$this->stop($e->getMessage());
|
||||
$this->stop($e->getMessage(), -2);
|
||||
$this->add('rx_error_location', $e->getFile() . ':' . $e->getLine());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -418,10 +419,11 @@ class ModuleObject extends BaseObject
|
|||
/**
|
||||
* Stop processing this module instance.
|
||||
*
|
||||
* @param string $msg_code an error code
|
||||
* @param string $msg_code
|
||||
* @param int $error_code
|
||||
* @return ModuleObject $this
|
||||
*/
|
||||
public function stop($msg_code)
|
||||
public function stop($msg_code, $error_code = -1)
|
||||
{
|
||||
if($this->stop_proc !== true)
|
||||
{
|
||||
|
|
@ -429,7 +431,7 @@ class ModuleObject extends BaseObject
|
|||
$this->stop_proc = true;
|
||||
|
||||
// Error handling
|
||||
$this->setError(-1);
|
||||
$this->setError($error_code ?: -1);
|
||||
$this->setMessage($msg_code);
|
||||
|
||||
// Get backtrace
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue