/** * compiles specified tpl file and execution result in Context into resultant content * @param string $tpl_path path of the directory containing target template file * @param string $tpl_filename target template file's name * @param string $tpl_file if specified use it as template file's full path * @return string Returns compiled result in case of success, NULL otherwise */ public function compile($tpl_path, $tpl_filename, $tpl_file = '') { // store the starting time for debug information $start = microtime(true); // initiation $this->init($tpl_path, $tpl_filename, $tpl_file); // if target file does not exist exit if (!$this->file || !file_exists($this->file)) { $error_message = "Template not found: {$tpl_path}{$tpl_filename}" . ($tpl_file ? " ({$tpl_file})" : ''); trigger_error($error_message, \E_USER_WARNING); return escape($error_message); } // for backward compatibility if (is_null(self::$rootTpl)) { self::$rootTpl = $this->file; } $latest_mtime = max(filemtime($this->file), $this->handler_mtime); // make compiled file if (!file_exists($this->compiled_file) || filemtime($this->compiled_file) < $latest_mtime) { $buff = $this->parse(); if (Rhymix\Framework\Storage::write($this->compiled_file, $buff) === false) { $tmpfilename = tempnam(sys_get_temp_dir(), 'rx-compiled'); if ($tmpfilename === false || Rhymix\Framework\Storage::write($tmpfilename, $buff) === false) { return 'Fatal Error : Cannot create temporary file. Please check permissions.'; } $this->compiled_file = $tmpfilename; } } Rhymix\Framework\Debug::addFilenameAlias($this->file, $this->compiled_file); $output = $this->_fetch($this->compiled_file); // delete tmpfile if (isset($tmpfilename)) { Rhymix\Framework\Storage::delete($tmpfilename); } if ($__templatehandler_root_tpl == $this->file) { $__templatehandler_root_tpl = null; } // store the ending time for debug information $GLOBALS['__template_elapsed__'] += microtime(true) - $start; return $output; }
/** * Legacy error handler * * @param int $errno * @param string $errstr * @param string $file * @param int $line * @return void */ function handleError($errno, $errstr, $file, $line, $context) { Rhymix\Framework\Debug::addError($errno, $errstr, $file, $line, $context); }
/** * Get debug information. * * @return string */ public function getDebugInfo(&$output = null) { // Check if debugging information has already been printed. if (self::$debug_printed) { return; } else { self::$debug_printed = 1; } // Check if debugging is enabled for this request. if (!config('debug.enabled') || !Rhymix\Framework\Debug::isEnabledForCurrentUser()) { return; } // Do not display debugging information if there is no output. $display_type = config('debug.display_type'); if ($output === null && $display_type !== 'file') { return; } // Print debug information. switch ($display_type) { case 'panel': $data = Rhymix\Framework\Debug::getDebugData(); $display_content = array_fill_keys(config('debug.display_content'), true); if (count($display_content) && !isset($display_content['entries'])) { $data->entries = null; } if (count($display_content) && !isset($display_content['queries'])) { unset($data->queries); } if (count($display_content) && !isset($display_content['slow_queries'])) { unset($data->slow_queries); } if (count($display_content) && !isset($display_content['slow_triggers'])) { unset($data->slow_triggers); } if (count($display_content) && !isset($display_content['slow_widgets'])) { unset($data->slow_widgets); } if (count($display_content) && !isset($display_content['slow_remote_requests'])) { unset($data->slow_remote_requests); } if ($data->entries) { foreach ($data->entries as &$entry) { if (is_scalar($entry->message)) { $entry->message = var_export($entry->message, true); } else { $entry->message = trim(print_r($entry->message, true)); } } } switch (Context::getResponseMethod()) { case 'HTML': $json_options = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE : 0; $panel_script = sprintf('<script src="%s%s?%s"></script>', RX_BASEURL, 'common/js/debug.js', filemtime(RX_BASEDIR . 'common/js/debug.js')); if (isset($_SESSION['_rx_debug_previous'])) { $panel_script .= "\n<script>\nvar rhymix_debug_previous = " . json_encode($_SESSION['_rx_debug_previous'], $json_options) . ";\n</script>"; unset($_SESSION['_rx_debug_previous']); } $panel_script .= "\n<script>\nvar rhymix_debug_content = " . json_encode($data, $json_options) . ";\n</script>"; $body_end_position = strrpos($output, '</body>') ?: strlen($output); $output = substr($output, 0, $body_end_position) . "\n{$panel_script}\n" . substr($output, $body_end_position); return; case 'JSON': if (RX_POST && preg_match('/^proc/', Context::get('act'))) { $data->ajax_module = Context::get('module'); $data->ajax_act = Context::get('act'); $_SESSION['_rx_debug_previous'] = $data; } else { unset($_SESSION['_rx_debug_previous']); } if (preg_match('/^(.+)\\}$/', $output, $matches)) { $output = $matches[1] . ',"_rx_debug":' . json_encode($data) . '}'; } return; default: return; } case 'comment': case 'file': default: if ($display_type === 'comment' && Context::getResponseMethod() !== 'HTML') { return; } ob_start(); $data = Rhymix\Framework\Debug::getDebugData(); $display_content = array_fill_keys(config('debug.display_content'), true); include RX_BASEDIR . 'common/tpl/debug_comment.html'; $content = preg_replace('/\\n{2,}/', "\n\n", trim(ob_get_clean())) . PHP_EOL; if ($display_type === 'file') { $log_filename = config('debug.log_filename') ?: 'files/debug/YYYYMMDD.php'; $log_filename = str_replace(array('YYYY', 'YY', 'MM', 'DD'), array(getInternalDateTime(RX_TIME, 'Y'), getInternalDateTime(RX_TIME, 'y'), getInternalDateTime(RX_TIME, 'm'), getInternalDateTime(RX_TIME, 'd')), $log_filename); $log_filename = RX_BASEDIR . $log_filename; if (!file_exists($log_filename) || !filesize($log_filename)) { $phpheader = '<?php exit; ?>' . "\n"; } else { $phpheader = ''; } FileHandler::writeFile($log_filename, $phpheader . $content . PHP_EOL, 'a'); return ''; } else { return '<!--' . PHP_EOL . $content . PHP_EOL . '-->'; } } }
/** * Return remote file's content via HTTP * * @param string $url The address of the target file * @param string $body HTTP request body * @param int $timeout Connection timeout * @param string $method GET/POST * @param string $content_type Content type header of HTTP request * @param string[] $headers Headers key value array. * @param string[] $cookies Cookies key value array. * @param string $post_data Request arguments array for POST method * @return string If success, the content of the target file. Otherwise: none */ public static function getRemoteResource($url, $body = null, $timeout = 3, $method = 'GET', $content_type = null, $headers = array(), $cookies = array(), $post_data = array(), $request_config = array()) { try { $host = parse_url($url, PHP_URL_HOST); $request_headers = array(); $request_cookies = array(); $request_options = array('timeout' => $timeout); foreach ($headers as $key => $val) { $request_headers[$key] = $val; } if (isset($cookies[$host]) && is_array($cookies[$host])) { foreach ($cookies[$host] as $key => $val) { $request_cookies[] = rawurlencode($key) . '=' . rawurlencode($val); } } if (count($request_cookies)) { $request_headers['Cookie'] = implode('; ', $request_cookies); } foreach ($request_config as $key => $val) { $request_options[$key] = $val; } if ($content_type) { $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; $GLOBALS['__remote_request_elapsed__'] += $elapsed_time; $log = array(); $log['url'] = $url; $log['status'] = $response ? $response->status_code : 0; $log['elapsed_time'] = $elapsed_time; if (config('debug.enabled') && 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); if (count($response->cookies)) { 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; } } else { return NULL; } } catch (Exception $e) { return NULL; } }
/** * set query debug log * @param array $log values set query debug * @return void */ public function setQueryLog($log) { Rhymix\Framework\Debug::addQuery($log); }
/** * @brief Widget name and argument and produce a result and Return the results * Tags used in templateHandler $this-> execute() will be replaced by the code running * * $Javascript_mode is true when editing your page by the code for handling Includes photos */ function execute($widget, $args, $javascript_mode = false, $escaped = true) { // Save for debug run-time widget $start = microtime(true); // urldecode the value of args haejum $object_vars = get_object_vars($args); if (count($object_vars)) { foreach ($object_vars as $key => $val) { if (in_array($key, array('widgetbox_content', 'body', 'class', 'style', 'widget_sequence', 'widget', 'widget_padding_left', 'widget_padding_top', 'widget_padding_bottom', 'widget_padding_right', 'widgetstyle', 'document_srl'))) { continue; } if ($escaped) { $args->{$key} = utf8RawUrlDecode($val); } } } /** * Widgets widgetContent/widgetBox Wanted If you are not content */ $widget_content = ''; if ($widget != 'widgetContent' && $widget != 'widgetBox') { if (!is_dir(sprintf(_XE_PATH_ . 'widgets/%s/', $widget))) { return; } // Hold the contents of the widget parameter $widget_content = $this->getCache($widget, $args); } if ($widget == 'widgetBox') { $widgetbox_content = $args->widgetbox_content; } /** * Wanted specified by the administrator of the widget style */ // Sometimes the wrong code, background-image: url (none) can be heard but none in this case, the request for the url so unconditionally Removed $style = preg_replace('/url\\((.+)(\\/?)none\\)/is', '', $args->style); // Find a style statement that based on the internal margin dropping pre-change $widget_padding_left = $args->widget_padding_left; $widget_padding_right = $args->widget_padding_right; $widget_padding_top = $args->widget_padding_top; $widget_padding_bottom = $args->widget_padding_bottom; $inner_style = sprintf("padding:%dpx %dpx %dpx %dpx !important;", $widget_padding_top, $widget_padding_right, $widget_padding_bottom, $widget_padding_left); /** * Wanted widget output */ $widget_content_header = ''; $widget_content_body = ''; $widget_content_footer = ''; // If general call is given on page styles should return immediately dreamin ' if (!$javascript_mode) { if ($args->id) { $args->id = ' id="' . $args->id . '" '; } switch ($widget) { // If a direct orthogonal addition information case 'widgetContent': if ($args->document_srl) { $oDocumentModel = getModel('document'); $oDocument = $oDocumentModel->getDocument($args->document_srl, false, false, false); $body = $oDocument->getContent(false, false, false, false); } else { $body = base64_decode($args->body); } // Change the editor component $oEditorController = getController('editor'); $body = $oEditorController->transComponent($body); $widget_content_header = sprintf('<div class="xe_content xe-widget-wrapper ' . $args->css_class . '" %sstyle="%s"><div style="%s">', $args->id, $style, $inner_style); $widget_content_body = $body; $widget_content_footer = '</div></div>'; break; // If the widget box; it could // If the widget box; it could case 'widgetBox': $widget_content_header = sprintf('<div class="xe-widget-wrapper ' . $args->css_class . '" %sstyle="%s;"><div style="%s"><div>', $args->id, $style, $inner_style); $widget_content_body = $widgetbox_content; break; // If the General wijetil // If the General wijetil default: $widget_content_header = sprintf('<div class="xe-widget-wrapper ' . $args->css_class . '" %sstyle="%s">', $args->id, $style); $widget_content_body = sprintf('<div style="*zoom:1;%s">%s</div>', $inner_style, $widget_content); $widget_content_footer = '</div>'; break; } // Edit page is called when a widget if you add the code for handling } else { switch ($widget) { // If a direct orthogonal addition information case 'widgetContent': if ($args->document_srl) { $oDocumentModel = getModel('document'); $oDocument = $oDocumentModel->getDocument($args->document_srl, false, false, false); $body = $oDocument->getContent(false, false, false); } else { $body = base64_decode($args->body); } // by args $attribute = array(); if ($args) { foreach ($args as $key => $val) { if (in_array($key, array('class', 'style', 'widget_padding_top', 'widget_padding_right', 'widget_padding_bottom', 'widget_padding_left', 'widget', 'widgetstyle', 'document_srl'))) { continue; } if (strpos($val, '|@|') > 0) { $val = str_replace('|@|', ',', $val); } $attribute[] = sprintf('%s="%s"', $key, htmlspecialchars($val, ENT_COMPAT | ENT_HTML401, 'UTF-8', false)); } } $oWidgetController = getController('widget'); $widget_content_header = sprintf('<div class="xe_content widgetOutput ' . $args->css_class . '" widgetstyle="%s" style="%s" widget_padding_left="%s" widget_padding_right="%s" widget_padding_top="%s" widget_padding_bottom="%s" widget="widgetContent" document_srl="%d" %s>' . '<div class="widgetResize"></div>' . '<div class="widgetResizeLeft"></div>' . '<div class="widgetBorder">' . '<div style="%s">', $args->widgetstyle, $style, $args->widget_padding_left, $args->widget_padding_right, $args->widget_padding_top, $args->widget_padding_bottom, $args->document_srl, implode(' ', $attribute), $inner_style); $widget_content_body = $body; $widget_content_footer = sprintf('</div>' . '</div>' . '<div class="widgetContent" style="display:none;width:1px;height:1px;overflow:hidden;">%s</div>' . '</div>', base64_encode($body)); break; // If the widget box; it could // If the widget box; it could case 'widgetBox': // by args $attribute = array(); if ($args) { foreach ($args as $key => $val) { if (in_array($key, array('class', 'style', 'widget_padding_top', 'widget_padding_right', 'widget_padding_bottom', 'widget_padding_left', 'widget', 'widgetstyle', 'document_srl'))) { continue; } if (!is_numeric($val) && (!is_string($val) || strlen($val) == 0)) { continue; } if (strpos($val, '|@|') > 0) { $val = str_replace('|@|', ',', $val); } $attribute[] = sprintf('%s="%s"', $key, htmlspecialchars($val, ENT_COMPAT | ENT_HTML401, 'UTF-8', false)); } } $widget_content_header = sprintf('<div class="widgetOutput ' . $args->css_class . '" widgetstyle="%s" widget="widgetBox" style="%s;" widget_padding_top="%s" widget_padding_right="%s" widget_padding_bottom="%s" widget_padding_left="%s" %s >' . '<div class="widgetBoxResize"></div>' . '<div class="widgetBoxResizeLeft"></div>' . '<div class="widgetBoxBorder"><div class="nullWidget" style="%s">', $args->widgetstyle, $style, $widget_padding_top, $widget_padding_right, $widget_padding_bottom, $widget_padding_left, implode(' ', $attribute), $inner_style); $widget_content_body = $widgetbox_content; break; // If the General wijetil // If the General wijetil default: // by args $attribute = array(); if ($args) { $allowed_key = array('class', 'style', 'widget_padding_top', 'widget_padding_right', 'widget_padding_bottom', 'widget_padding_left', 'widget'); foreach ($args as $key => $val) { if (in_array($key, $allowed_key)) { continue; } if (!is_numeric($val) && (!is_string($val) || strlen($val) == 0)) { continue; } if (strpos($val, '|@|') > 0) { $val = str_replace('|@|', ',', $val); } $attribute[] = sprintf('%s="%s"', $key, htmlspecialchars($val, ENT_COMPAT | ENT_HTML401, 'UTF-8', false)); } } $widget_content_header = sprintf('<div class="widgetOutput ' . $args->css_class . '" widgetstyle="%s" style="%s" widget_padding_top="%s" widget_padding_right="%s" widget_padding_bottom="%s" widget_padding_left="%s" widget="%s" %s >' . '<div class="widgetResize"></div>' . '<div class="widgetResizeLeft"></div>' . '<div class="widgetBorder">', $args->widgetstyle, $style, $widget_padding_top, $widget_padding_right, $widget_padding_bottom, $widget_padding_left, $widget, implode(' ', $attribute)); $widget_content_body = sprintf('<div style="%s">%s</div>', $inner_style, $widget_content); $widget_content_footer = '</div></div>'; break; } } // Compile the widget style. if ($args->widgetstyle) { $widget_content_body = $this->compileWidgetStyle($args->widgetstyle, $widget, $widget_content_body, $args, $javascript_mode); } $output = $widget_content_header . $widget_content_body . $widget_content_footer; // Debug widget creation time information added to the results $elapsed_time = microtime(true) - $start; $GLOBALS['__widget_excute_elapsed__'] += $elapsed_time; Rhymix\Framework\Debug::addWidget(array('name' => $widget, 'elapsed_time' => $elapsed_time)); // Return result return $output; }
/** * call a trigger * @param string $trigger_name trigger's name to call * @param string $called_position called position * @param object $obj an object as a parameter to trigger * @return Object * */ public static function triggerCall($trigger_name, $called_position, &$obj) { // skip if not installed if (!Context::isInstalled()) { return new Object(); } $oModuleModel = getModel('module'); $triggers = $oModuleModel->getTriggers($trigger_name, $called_position); if (!$triggers) { $triggers = array(); } //store before trigger call time $before_trigger_time = microtime(true); foreach ($triggers as $item) { $module = $item->module; $type = $item->type; $called_method = $item->called_method; // todo why don't we call a normal class object ? $oModule = getModule($module, $type); if (!$oModule || !method_exists($oModule, $called_method)) { continue; } // do not call if module is blacklisted if (Context::isBlacklistedPlugin($oModule->module)) { continue; } $before_each_trigger_time = microtime(true); $output = $oModule->{$called_method}($obj); $after_each_trigger_time = microtime(true); if ($trigger_name !== 'common.flushDebugInfo') { $trigger_target = $module . ($type === 'class' ? '' : $type) . '.' . $called_method; Rhymix\Framework\Debug::addTrigger(array('name' => $trigger_name . '.' . $called_position, 'target' => $trigger_target, 'target_plugin' => $module, 'elapsed_time' => $after_each_trigger_time - $before_each_trigger_time)); } if (is_object($output) && method_exists($output, 'toBool') && !$output->toBool()) { return $output; } unset($oModule); } $trigger_functions = $oModuleModel->getTriggerFunctions($trigger_name, $called_position); foreach ($trigger_functions as $item) { $before_each_trigger_time = microtime(true); $output = $item($obj); $after_each_trigger_time = microtime(true); if ($trigger_name !== 'common.writeSlowlog') { if (is_string($item)) { $trigger_target = $item; } elseif (is_array($item) && count($item)) { if (is_object($item[0])) { $trigger_target = get_class($item[0]) . '.' . strval($item[1]); } else { $trigger_target = implode('.', $item); } } else { $trigger_target = 'closure'; } Rhymix\Framework\Debug::addTrigger(array('name' => $trigger_name . '.' . $called_position, 'target' => $trigger_target, 'target_plugin' => null, 'elapsed_time' => $after_each_trigger_time - $before_each_trigger_time)); } if (is_object($output) && method_exists($output, 'toBool') && !$output->toBool()) { return $output; } } return new Object(); }
$filename .= '.admin'; } $filename .= isset($matches[3]) && $matches[3] ? '.' . strtolower($matches[3]) : '.class'; $filename .= '.php'; } } if ($filename && file_exists($filename)) { include $filename; } }); /** * Also include the Composer autoloader. */ require_once RX_BASEDIR . 'vendor/autoload.php'; /** * Load system configuration. */ Rhymix\Framework\Config::init(); /** * Install the debugger. */ Rhymix\Framework\Debug::registerErrorHandlers(error_reporting()); /** * Set the internal timezone. */ $internal_timezone = Rhymix\Framework\DateTime::getTimezoneNameByOffset(config('locale.internal_timezone')); date_default_timezone_set($internal_timezone); /** * Initialize the cache handler. */ Rhymix\Framework\Cache::init(Rhymix\Framework\Config::get('cache'));