mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-02 01:52:10 +09:00
Merge branch 'rhymix:master' into master
This commit is contained in:
commit
ef9967fc1d
81 changed files with 923 additions and 726 deletions
|
|
@ -239,6 +239,10 @@ class Cache
|
|||
{
|
||||
if (self::$_driver !== null)
|
||||
{
|
||||
if (self::$_driver instanceof Drivers\Cache\APC && \PHP_SAPI === 'cli')
|
||||
{
|
||||
self::sendClearRequest([$key]);
|
||||
}
|
||||
return self::$_driver->delete(self::getRealKey($key)) ? true : false;
|
||||
}
|
||||
else
|
||||
|
|
@ -323,6 +327,10 @@ class Cache
|
|||
{
|
||||
if (self::$_driver !== null)
|
||||
{
|
||||
if (self::$_driver instanceof Drivers\Cache\APC && \PHP_SAPI === 'cli')
|
||||
{
|
||||
self::sendClearRequest([$group_name . ':*']);
|
||||
}
|
||||
$success = self::$_driver->incr(self::$_prefix . $group_name . '#version', 1) ? true : false;
|
||||
unset(self::$_group_versions[$group_name]);
|
||||
return $success;
|
||||
|
|
@ -344,6 +352,10 @@ class Cache
|
|||
{
|
||||
if (self::$_driver !== null)
|
||||
{
|
||||
if (self::$_driver instanceof Drivers\Cache\APC && \PHP_SAPI === 'cli')
|
||||
{
|
||||
self::sendClearRequest(['*']);
|
||||
}
|
||||
return self::$_driver->clear() ? true : false;
|
||||
}
|
||||
else
|
||||
|
|
@ -396,4 +408,27 @@ class Cache
|
|||
|
||||
return self::$_prefix . $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a web request to clear the cache.
|
||||
*
|
||||
* @param array $keys
|
||||
* @return void
|
||||
*/
|
||||
public static function sendClearRequest(array $keys): void
|
||||
{
|
||||
if (!$keys)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$keystring = implode('|', $keys);
|
||||
$signature = Security::createSignature($keystring);
|
||||
HTTP::post(\Context::getRequestUri(), [
|
||||
'module' => 'module',
|
||||
'act' => 'procModuleClearCache',
|
||||
'keys' => $keys,
|
||||
'signature' => $signature,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,8 +23,19 @@ class Debug
|
|||
protected static $_slow_widgets = array();
|
||||
protected static $_remote_requests = array();
|
||||
protected static $_slow_remote_requests = array();
|
||||
protected static $_session_time = 0;
|
||||
protected static $_query_time = 0;
|
||||
|
||||
/**
|
||||
* Store timers here.
|
||||
*/
|
||||
protected static $_timers = [
|
||||
'query' => 0,
|
||||
'session' => 0,
|
||||
'remote' => 0,
|
||||
'layout' => 0,
|
||||
'widget' => 0,
|
||||
'template' => 0,
|
||||
'trans_content' => 0,
|
||||
];
|
||||
|
||||
/**
|
||||
* Enable log collection.
|
||||
|
|
@ -227,8 +238,10 @@ class Debug
|
|||
self::$_slow_widgets = array();
|
||||
self::$_remote_requests = array();
|
||||
self::$_slow_remote_requests = array();
|
||||
self::$_session_time = 0;
|
||||
self::$_query_time = 0;
|
||||
foreach (self::$_timers as $key => $val)
|
||||
{
|
||||
self::$_timers[$key] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -244,14 +257,22 @@ class Debug
|
|||
}
|
||||
|
||||
/**
|
||||
* Add session start time.
|
||||
* Add time to a timer variable.
|
||||
*
|
||||
* @param float $session_start_time
|
||||
* @param string $type
|
||||
* @param float $time
|
||||
* @return void
|
||||
*/
|
||||
public static function addSessionStartTime(float $session_start_time): void
|
||||
public static function addTime(string $type, float $time): void
|
||||
{
|
||||
self::$_session_time += $session_start_time;
|
||||
if (isset(self::$_timers[$type]))
|
||||
{
|
||||
self::$_timers[$type] += $time;
|
||||
}
|
||||
else
|
||||
{
|
||||
self::$_timers[$type] = $time;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -449,7 +470,7 @@ class Debug
|
|||
}
|
||||
|
||||
// Record query time.
|
||||
self::$_query_time += $query_object->query_time;
|
||||
self::$_timers['query'] += $query_object->query_time;
|
||||
|
||||
// Add the query to the error log if the result wasn't successful.
|
||||
if ($query['result'] === 'error')
|
||||
|
|
@ -560,6 +581,8 @@ class Debug
|
|||
);
|
||||
|
||||
self::$_widgets[] = $widget_object;
|
||||
self::$_timers['widget'] += $widget_object->widget_time;
|
||||
|
||||
if ($widget_object->widget_time && $widget_object->widget_time >= (self::$_config['log_slow_widgets'] ?? 1))
|
||||
{
|
||||
self::$_slow_widgets[] = $widget_object;
|
||||
|
|
@ -597,12 +620,7 @@ class Debug
|
|||
);
|
||||
|
||||
self::$_remote_requests[] = $request_object;
|
||||
|
||||
if (!isset($GLOBALS['__remote_request_elapsed__']))
|
||||
{
|
||||
$GLOBALS['__remote_request_elapsed__'] = 0;
|
||||
}
|
||||
$GLOBALS['__remote_request_elapsed__'] += $request_object->elapsed_time;
|
||||
self::$_timers['remote'] += $request_object->elapsed_time;
|
||||
|
||||
if ($request_object->elapsed_time && is_numeric($request_object->elapsed_time) && $request_object->elapsed_time >= (self::$_config['log_slow_remote_requests'] ?? 1))
|
||||
{
|
||||
|
|
@ -890,15 +908,14 @@ class Debug
|
|||
'memory' => memory_get_peak_usage(),
|
||||
'timing' => (object)array(
|
||||
'total' => sprintf('%0.4f sec', microtime(true) - \RX_MICROTIME),
|
||||
'db_query' => sprintf('%0.4f sec (count: %d)', self::$_query_time, count(self::$_queries)),
|
||||
'db_class' => sprintf('%0.4f sec', max(0, $db->getTotalElapsedTime() - self::$_query_time)),
|
||||
'layout' => sprintf('%0.4f sec', $GLOBALS['__layout_compile_elapsed__'] ?? 0),
|
||||
'widget' => sprintf('%0.4f sec', $GLOBALS['__widget_excute_elapsed__'] ?? 0),
|
||||
'remote' => sprintf('%0.4f sec', $GLOBALS['__remote_request_elapsed__'] ?? 0),
|
||||
'session' => sprintf('%0.4f sec', self::$_session_time),
|
||||
'xmlparse' => sprintf('%0.4f sec', $GLOBALS['__xmlparse_elapsed__'] ?? 0),
|
||||
'template' => sprintf('%0.4f sec (count: %d)', $GLOBALS['__template_elapsed__'] ?? 0, $GLOBALS['__TemplateHandlerCalled__'] ?? 0),
|
||||
'trans' => sprintf('%0.4f sec', $GLOBALS['__trans_content_elapsed__'] ?? 0),
|
||||
'db_query' => sprintf('%0.4f sec (count: %d)', self::$_timers['query'], count(self::$_queries)),
|
||||
'db_class' => sprintf('%0.4f sec', max(0, $db->getTotalElapsedTime() - self::$_timers['query'])),
|
||||
'session' => sprintf('%0.4f sec', self::$_timers['session']),
|
||||
'remote' => sprintf('%0.4f sec', self::$_timers['remote']),
|
||||
'layout' => sprintf('%0.4f sec', self::$_timers['layout']),
|
||||
'widget' => sprintf('%0.4f sec', self::$_timers['widget']),
|
||||
'template' => sprintf('%0.4f sec', self::$_timers['template']),
|
||||
'trans' => sprintf('%0.4f sec', self::$_timers['trans_content']),
|
||||
),
|
||||
'entries' => array_values(self::$_entries),
|
||||
'errors' => array_values(self::$_errors),
|
||||
|
|
|
|||
|
|
@ -324,56 +324,13 @@ class HTTP
|
|||
Debug::addRemoteRequest($log);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
$settings['on_stats'] = function($stats) {
|
||||
Debug::addTime('remote', $stats->getTransferTime());
|
||||
};
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Record a request with the Debug class.
|
||||
*
|
||||
* @param string $url
|
||||
* @param int $status_code
|
||||
* @param float $elapsed_time
|
||||
* @return void
|
||||
*/
|
||||
protected static function _debug(string $url, int $status_code = 0, float $elapsed_time = 0): void
|
||||
{
|
||||
if (!isset($GLOBALS['__remote_request_elapsed__']))
|
||||
{
|
||||
$GLOBALS['__remote_request_elapsed__'] = 0;
|
||||
}
|
||||
$GLOBALS['__remote_request_elapsed__'] += $elapsed_time;
|
||||
|
||||
if (Debug::isEnabledForCurrentUser())
|
||||
{
|
||||
$log = array();
|
||||
$log['url'] = $url;
|
||||
$log['status'] = $status_code;
|
||||
$log['elapsed_time'] = $elapsed_time;
|
||||
$log['called_file'] = $log['called_line'] = $log['called_method'] = null;
|
||||
$log['backtrace'] = [];
|
||||
|
||||
if (in_array('slow_remote_requests', config('debug.display_content')))
|
||||
{
|
||||
$bt = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||
foreach ($bt as $no => $call)
|
||||
{
|
||||
if($call['file'] !== __FILE__ && $call['file'] !== \RX_BASEDIR . 'classes/file/FileHandler.class.php')
|
||||
{
|
||||
$log['called_file'] = $bt[$no]['file'];
|
||||
$log['called_line'] = $bt[$no]['line'];
|
||||
$next = $no + 1;
|
||||
if (isset($bt[$next]))
|
||||
{
|
||||
$log['called_method'] = $bt[$next]['class'].$bt[$next]['type'].$bt[$next]['function'];
|
||||
$log['backtrace'] = array_slice($bt, $next, 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ class Session
|
|||
trigger_error('Session cannot be started', \E_USER_WARNING);
|
||||
return false;
|
||||
}
|
||||
Debug::addSessionStartTime(microtime(true) - $session_start_time);
|
||||
Debug::addTime('session', microtime(true) - $session_start_time);
|
||||
|
||||
// Mark the session as started.
|
||||
self::$_started = true;
|
||||
|
|
|
|||
|
|
@ -378,13 +378,7 @@ class Template
|
|||
$output = $this->execute();
|
||||
|
||||
// Record the time elapsed.
|
||||
$elapsed_time = microtime(true) - $start;
|
||||
if (!isset($GLOBALS['__template_elapsed__']))
|
||||
{
|
||||
$GLOBALS['__template_elapsed__'] = 0;
|
||||
}
|
||||
$GLOBALS['__template_elapsed__'] += $elapsed_time;
|
||||
|
||||
Debug::addTime('template', microtime(true) - $start);
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -738,10 +738,11 @@ class Query extends VariableBase
|
|||
*/
|
||||
public static function quoteName(string $column_name): string
|
||||
{
|
||||
return preg_replace_callback('/[a-z][a-z0-9_.*]*(?!\\()\b/i', function($m) {
|
||||
$exceptions = ['*' => true, 'DISTINCT' => true, 'distinct' => true];
|
||||
return preg_replace_callback('/[a-z][a-z0-9_.*]*(?!\\()\b/i', function($m) use($exceptions) {
|
||||
$columns = explode('.', $m[0]);
|
||||
$columns = array_map(function($str) {
|
||||
return $str === '*' ? $str : ('`' . $str . '`');
|
||||
$columns = array_map(function($str) use($exceptions) {
|
||||
return isset($exceptions[$str]) ? $str : ('`' . $str . '`');
|
||||
}, $columns);
|
||||
return implode('.', $columns);
|
||||
}, $column_name);
|
||||
|
|
|
|||
|
|
@ -138,9 +138,9 @@ class TemplateParser_v2
|
|||
// Apply conversions.
|
||||
$content = $this->_addContextSwitches($content);
|
||||
$content = $this->_removeComments($content);
|
||||
$content = $this->_convertVerbatimSections($content);
|
||||
$content = $this->_convertRelativePaths($content);
|
||||
$content = $this->_convertPHPSections($content);
|
||||
$content = $this->_convertVerbatimSections($content);
|
||||
$content = $this->_convertFragments($content);
|
||||
$content = $this->_convertClassAliases($content);
|
||||
$content = $this->_convertIncludes($content);
|
||||
|
|
@ -872,7 +872,16 @@ class TemplateParser_v2
|
|||
$str = $this->_escapeCurly($str);
|
||||
$str = $this->_convertVariableScope($str);
|
||||
|
||||
// Apply filters.
|
||||
// Process the escape option first.
|
||||
foreach ($filters as $filter)
|
||||
{
|
||||
if (in_array($filter, ['autoescape', 'autolang', 'escape', 'noescape']))
|
||||
{
|
||||
$escape_option = $filter;
|
||||
}
|
||||
}
|
||||
|
||||
// Apply other filters.
|
||||
foreach ($filters as $filter)
|
||||
{
|
||||
// Separate the filter option from the filter name.
|
||||
|
|
@ -891,14 +900,13 @@ class TemplateParser_v2
|
|||
}
|
||||
}
|
||||
|
||||
// Apply each filter.
|
||||
// Apply filters.
|
||||
switch ($filter)
|
||||
{
|
||||
case 'autoescape':
|
||||
case 'autolang':
|
||||
case 'escape':
|
||||
case 'noescape':
|
||||
$escape_option = $filter;
|
||||
break;
|
||||
case 'escapejs':
|
||||
case 'js':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue