/** * Render a help template (or return false if none found). * * @param string $name Template name to render * @param array $context Variables needed for rendering template; these will * be temporarily added to the global view context, then reverted after the * template is rendered (default = empty). * * @return string|bool */ public function render($name, $context = null) { // Set up the needed context in the view: $this->contextHelper->__invoke($this->getView()); $oldContext = $this->contextHelper->apply(null === $context ? [] : $context); // Sanitize the template name to include only alphanumeric characters // or underscores. $safe_topic = preg_replace('/[^\\w]/', '', $name); // Clear warnings $this->warnings = []; try { $tpl = "HelpTranslations/{$this->language}/{$safe_topic}.phtml"; $html = $this->getView()->render($tpl); } catch (RuntimeException $e) { try { // language missing -- try default language $tplFallback = 'HelpTranslations/' . $this->defaultLanguage . '/' . $safe_topic . '.phtml'; $html = $this->getView()->render($tplFallback); $this->warnings[] = 'Sorry, but the help you requested is ' . 'unavailable in your language.'; } catch (RuntimeException $e) { // no translation available at all! $html = false; } } $this->contextHelper->restore($oldContext); return $html; }
/** * Public method to render the OpenURL template * * @return string */ public function renderTemplate() { // Static counter to ensure that each OpenURL gets a unique ID. static $counter = 0; if (null !== $this->config && isset($this->config->url)) { // Trim off any parameters (for legacy compatibility -- default config // used to include extraneous parameters): list($base) = explode('?', $this->config->url); } else { $base = false; } $embed = isset($this->config->embed) && !empty($this->config->embed); if ($embed) { $counter++; } $embedAutoLoad = isset($this->config->embed_auto_load) ? $this->config->embed_auto_load : false; // ini values 'true'/'false' are provided via ini reader as 1/0 // only check embedAutoLoad for area if the current area passed checkContext if (!($embedAutoLoad === "1" || $embedAutoLoad === "0") && !empty($this->area)) { // embedAutoLoad is neither true nor false, so check if it contains an // area string defining where exactly to use autoloading $embedAutoLoad = in_array(strtolower($this->area), array_map('trim', array_map('strtolower', explode(',', $embedAutoLoad)))); } // Build parameters needed to display the control: $params = ['openUrl' => $this->recordDriver->getOpenUrl(), 'openUrlBase' => empty($base) ? false : $base, 'openUrlWindow' => empty($this->config->window_settings) ? false : $this->config->window_settings, 'openUrlGraphic' => empty($this->config->graphic) ? false : $this->config->graphic, 'openUrlGraphicWidth' => empty($this->config->graphic_width) ? false : $this->config->graphic_width, 'openUrlGraphicHeight' => empty($this->config->graphic_height) ? false : $this->config->graphic_height, 'openUrlEmbed' => $embed, 'openUrlEmbedAutoLoad' => $embedAutoLoad, 'openUrlId' => $counter]; // Render the subtemplate: return $this->context->__invoke($this->getView())->renderInContext('Helpers/openurl.phtml', $params); }
/** * Render appropriate UI controls for an OpenURL link. * * @param string $openUrl The OpenURL to display * * @return string */ public function __invoke($openUrl) { // Static counter to ensure that each OpenURL gets a unique ID. static $counter = 0; if (null !== $this->config && isset($this->config->url)) { // Trim off any parameters (for legacy compatibility -- default config // used to include extraneous parameters): list($base) = explode('?', $this->config->url); } else { $base = false; } $embed = isset($this->config->embed) && !empty($this->config->embed); if ($embed) { $counter++; } // Build parameters needed to display the control: $params = ['openUrl' => $openUrl, 'openUrlBase' => empty($base) ? false : $base, 'openUrlWindow' => empty($this->config->window_settings) ? false : $this->config->window_settings, 'openUrlGraphic' => empty($this->config->graphic) ? false : $this->config->graphic, 'openUrlGraphicWidth' => empty($this->config->graphic_width) ? false : $this->config->graphic_width, 'openUrlGraphicHeight' => empty($this->config->graphic_height) ? false : $this->config->graphic_height, 'openUrlEmbed' => $embed, 'openUrlId' => $counter]; // Render the subtemplate: return $this->context->__invoke($this->getView())->renderInContext('Helpers/openurl.phtml', $params); }