/** * Process logging data * * @param mixed $data The data to process * @param bool $display Whether to display the data to the user. Otherwise log it. * @param int $level The logging level for this data * @return void */ protected function process($data, $display, $level) { // plugin can return false to stop the default logging method $params = array('level' => $level, 'msg' => $data, 'display' => $display, 'to_screen' => $display); if (!$this->hooks->trigger('debug', 'log', $params, true)) { return; } // Do not want to write to screen before page creation has started. // This is not fool-proof but probably fixes 95% of the cases when logging // results in data sent to the browser before the page is begun. if (!isset($GLOBALS['_ELGG']->pagesetupdone)) { $display = false; } // Do not want to write to JS or CSS pages if ($this->context->contains('js') || $this->context->contains('css')) { $display = false; } // don't display in simplecache requests $path = substr(current_page_url(), strlen(elgg_get_site_url())); if (preg_match('~^(cache|action)/~', $path)) { $display = false; } if ($display == true) { echo '<pre class="elgg-logger-data">'; echo htmlspecialchars(print_r($data, true), ENT_QUOTES, 'UTF-8'); echo '</pre>'; } error_log(print_r($data, true)); }
/** * Process logging data * * @param mixed $data The data to process * @param bool $display Whether to display the data to the user. Otherwise log it. * @param int $level The logging level for this data * @return void */ protected function process($data, $display, $level) { // plugin can return false to stop the default logging method $params = array('level' => $level, 'msg' => $data, 'display' => $display, 'to_screen' => $display); if (!$this->hooks->trigger('debug', 'log', $params, true)) { return; } // Do not want to write to JS or CSS pages if ($this->context->contains('js') || $this->context->contains('css')) { $display = false; } // don't display in simplecache requests $path = substr(current_page_url(), strlen(elgg_get_site_url())); if (preg_match('~^(cache|action|serve-file)/~', $path)) { $display = false; } if ($display == true) { echo '<pre class="elgg-logger-data">'; echo htmlspecialchars(print_r($data, true), ENT_QUOTES, 'UTF-8'); echo '</pre>'; } error_log(print_r($data, true)); }
/** * @access private */ public function renderView($view, array $vars = array(), $bypass = false, $viewtype = '', $issue_missing_notice = true) { if (!is_string($view) || !is_string($viewtype)) { $this->logger->log("View and Viewtype in views must be a strings: {$view}", 'NOTICE'); return ''; } // basic checking for bad paths if (strpos($view, '..') !== false) { return ''; } if (!is_array($vars)) { $this->logger->log("Vars in views must be an array: {$view}", 'ERROR'); $vars = array(); } // Get the current viewtype if ($viewtype === '' || !_elgg_is_valid_viewtype($viewtype)) { $viewtype = elgg_get_viewtype(); } // allow altering $vars $vars_hook_params = ['view' => $view, 'vars' => $vars, 'viewtype' => $viewtype]; $vars = $this->hooks->trigger('view_vars', $view, $vars_hook_params, $vars); $view_orig = $view; // Trigger the pagesetup event if (!isset($this->CONFIG->pagesetupdone) && $this->CONFIG->boot_complete) { $this->CONFIG->pagesetupdone = true; _elgg_services()->events->trigger('pagesetup', 'system'); } // @warning - plugin authors: do not expect user, config, and url to be // set by elgg_view() in the future. Instead, use elgg_get_logged_in_user_entity(), // elgg_get_config(), and elgg_get_site_url() in your views. if (!isset($vars['user'])) { $vars['user'] = $this->getUserWrapper(); } if (!isset($vars['config'])) { if (!$this->config_wrapper) { $warning = 'Do not rely on $vars["config"] or $CONFIG being available in views'; $this->config_wrapper = new \Elgg\DeprecationWrapper($this->CONFIG, $warning, 1.8); } $vars['config'] = $this->config_wrapper; } if (!isset($vars['url'])) { if (!$this->site_url_wrapper) { $warning = 'Do not rely on $vars["url"] being available in views'; $this->site_url_wrapper = new \Elgg\DeprecationWrapper(elgg_get_site_url(), $warning, 1.8); } $vars['url'] = $this->site_url_wrapper; } // full_view is the new preferred key for full view on entities @see elgg_view_entity() // check if full_view is set because that means we've already rewritten it and this is // coming from another view passing $vars directly. if (isset($vars['full']) && !isset($vars['full_view'])) { elgg_deprecated_notice("Use \$vars['full_view'] instead of \$vars['full']", 1.8, 2); $vars['full_view'] = $vars['full']; } if (isset($vars['full_view'])) { $vars['full'] = $vars['full_view']; } // internalname => name (1.8) if (isset($vars['internalname']) && !isset($vars['__ignoreInternalname']) && !isset($vars['name'])) { elgg_deprecated_notice('You should pass $vars[\'name\'] now instead of $vars[\'internalname\']', 1.8, 2); $vars['name'] = $vars['internalname']; } elseif (isset($vars['name'])) { if (!isset($vars['internalname'])) { $vars['__ignoreInternalname'] = ''; } $vars['internalname'] = $vars['name']; } // internalid => id (1.8) if (isset($vars['internalid']) && !isset($vars['__ignoreInternalid']) && !isset($vars['name'])) { elgg_deprecated_notice('You should pass $vars[\'id\'] now instead of $vars[\'internalid\']', 1.8, 2); $vars['id'] = $vars['internalid']; } elseif (isset($vars['id'])) { if (!isset($vars['internalid'])) { $vars['__ignoreInternalid'] = ''; } $vars['internalid'] = $vars['id']; } // If it's been requested, pass off to a template handler instead if ($bypass == false && isset($this->CONFIG->template_handler) && !empty($this->CONFIG->template_handler)) { $template_handler = $this->CONFIG->template_handler; if (is_callable($template_handler)) { return call_user_func($template_handler, $view, $vars); } } // Set up any extensions to the requested view if (isset($this->CONFIG->views->extensions[$view])) { $viewlist = $this->CONFIG->views->extensions[$view]; } else { $viewlist = array(500 => $view); } $content = ''; foreach ($viewlist as $view) { $rendering = $this->renderViewFile($view, $vars, $viewtype, $issue_missing_notice); if ($rendering !== false) { $content .= $rendering; continue; } // attempt to load default view if ($viewtype !== 'default' && $this->doesViewtypeFallback($viewtype)) { $rendering = $this->renderViewFile($view, $vars, 'default', $issue_missing_notice); if ($rendering !== false) { $content .= $rendering; } } } // Plugin hook $params = array('view' => $view_orig, 'vars' => $vars, 'viewtype' => $viewtype); $content = $this->hooks->trigger('view', $view_orig, $params, $content); // backward compatibility with less granular hook will be gone in 2.0 $content_tmp = $this->hooks->trigger('display', 'view', $params, $content); if ($content_tmp !== $content) { $content = $content_tmp; elgg_deprecated_notice('The display:view plugin hook is deprecated by view:view_name', 1.8); } return $content; }