/** * 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; }
/** * Render an HTML checkbox control for the current record. * * @param string $idPrefix Prefix for checkbox HTML ids * * @return string */ public function getCheckbox($idPrefix = '') { static $checkboxCount = 0; $id = $this->driver->getResourceSource() . '|' . $this->driver->getUniqueId(); $context = ['id' => $id, 'count' => $checkboxCount++, 'prefix' => $idPrefix]; return $this->contextHelper->renderInContext('record/checkbox.phtml', $context); }
/** * 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); }
/** * Get the rendered cover plus some useful parameters. * * @param string $context Context of code being generated * @param string $default The default size of the cover * @param string $link The link for the anchor * * @return array */ public function getCoverDetails($context, $default, $link = false) { $details = compact('link', 'context') + ['driver' => $this->driver, 'cover' => false, 'size' => false, 'linkPreview' => $this->getPreviewCoverLinkSetting($context)]; $preferredSize = $this->getCoverSize($context, $default); if (empty($preferredSize)) { // covers disabled entirely $details['html'] = ''; } else { // Find best option if more than one size is defined (e.g. small:medium) foreach (explode(':', $preferredSize) as $size) { if ($details['cover'] = $this->getThumbnail($size)) { $details['size'] = $size; break; } } $details['html'] = $this->contextHelper->renderInContext('record/cover.phtml', $details); } return $details; }
/** * 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); }
/** * Render a cover for the current record. * * @param string $context Context of code being genarated * @param string $default The default size of the cover * @param string $link The link for the anchor * * @return string */ public function getCover($context, $default, $link = false) { if (isset($this->config->Content->coversize) && !$this->config->Content->coversize) { // covers disabled entirely $preferredSize = false; } else { // check for context-specific overrides $preferredSize = isset($this->config->Content->coversize[$context]) ? $this->config->Content->coversize[$context] : $default; } if (empty($preferredSize)) { return ''; } // Find best option if more than one size is defined (e.g. small:medium) $cover = false; // assume invalid until good size found below foreach (explode(':', $preferredSize) as $size) { if ($cover = $this->getThumbnail($size)) { break; } } $driver = $this->driver; // for convenient use in compact() return $this->contextHelper->renderInContext('record/cover.phtml', compact('cover', 'link', 'context', 'driver')); }