/** * Renders the content to be inserted at the end of the body section. * The content is rendered using the registered JS code blocks and files. * * @return string the rendered content */ protected function renderBodyEndHtml() { $lines = []; if (!empty($this->cssFiles[self::POS_END])) { $lines[] = implode("\n", $this->cssFiles[self::POS_END]); } if (!empty($this->jsFiles[self::POS_END])) { $lines[] = implode("\n", $this->jsFiles[self::POS_END]); } $scripts = []; if (!empty($this->js[self::POS_END])) { $scripts[] = implode("\n", $this->js[self::POS_END]); } if (!empty($scripts)) { $lines[] = Html::script(implode("\n", $scripts), ['type' => 'text/javascript']); } $lines[] = '</body>'; return empty($lines) ? '' : implode("\n", $lines); }
public function get() { if (empty($this->src)) { if (empty($this->dummy)) { return ''; } $this->src = $this->dummy; } $options = ['class' => $this->_class, 'alt' => $this->template->replace($this->alt), 'title' => $this->title]; $src = $this->imageProvider->get($this->src, $this->w, $this->h); if (!((int) $this->const & ThumbInterface::WITHOUT_WIDTH_HEIGHT)) { $options['width'] = $this->imageProvider->width; $options['height'] = $this->imageProvider->height; } return (int) $this->const & ThumbInterface::OUTPUT_IMG ? Html::img($src, $options) : $src; }
/** * Renders the widget. */ public function run() { if ($this->hasModel() && $this->activeField) { $this->options = $this->activeField->calculateClientInputOption($this->options); $input = ActiveHtml::activeTextInput($this->model, $this->attribute, $this->options); } else { $input = Html::textInput($this->name, $this->value, $this->options); } if ($this->output === self::BASE64) { $src = $this->captcha->getDataUri(); } else { $src = Url::modify([$this->captchaAction, 'v' => uniqid()], Url::ABS); } $image = Html::img($src, $this->imageOptions); echo strtr($this->template, ['{input}' => $input, '{image}' => $image]); }
/** * Get thumb. * * @param string $path src to image * @param array $params params: * * - type: get `src`, `<a>`, `<img>` (default: `<img>`) * - w: width * - h: height * - q: quality * - class: attr `class` * - alt: attr `alt` * - const * - dummy * @param Template $template * @return string * @throws \rock\helpers\InstanceException */ public static function thumb($path, array $params, Template $template) { if (empty($path)) { if (empty($params['dummy'])) { return ''; } $path = $params['dummy']; } $const = Helper::getValue($params['const'], 1, true); /** @var ImageProvider $imageProvider */ $imageProvider = Instance::ensure(isset($params['imageProvider']) ? $params['imageProvider'] : 'imageProvider'); $src = $imageProvider->get($path, Helper::getValue($params['w']), Helper::getValue($params['h'])); if (!($const & ThumbInterface::WITHOUT_WIDTH_HEIGHT)) { $params['width'] = $imageProvider->width; $params['height'] = $imageProvider->height; } unset($params['h'], $params['w'], $params['type'], $params['const']); if (!empty($params['alt'])) { $params['alt'] = $template->replace($params['alt']); } return $const & ThumbInterface::OUTPUT_IMG ? Html::img($src, $params) : $src; }
/** * @inheritdoc */ protected static function normalizeClientOptions($option, $value) { if ($option === 'ng-init' && is_array($value)) { return Html::fromArray($value); } return $value; }
protected function prepareSubmitButton($submit) { if (empty($submit)) { return Html::submitButton(); } $submit = (array) $submit; $submit[1] = isset($submit[1]) ? $submit[1] : []; list($content, $options) = $submit; if (!empty($this->config['clientAction']) && !isset($options['data']['ng-disabled'])) { $options['data']['ng-disabled'] = 'isSend()'; } if (isset($options['wrapperTpl'])) { $wrapper = $options['wrapperTpl']; unset($options['wrapperTpl']); return $this->parseWrapperTpl(Html::submitButton($this->template->replace($content), $options), $wrapper); } return Html::submitButton($this->template->replace($content), $options); }
/** * Generates a hyperlink that links to the sort action to sort by the specified attribute. * Based on the sort direction, the CSS class of the generated hyperlink will be appended * with "asc" or "desc". * @param string $attribute the attribute name by which the data should be sorted by. * @param array $options additional HTML attributes for the hyperlink tag. * There is one special attribute `label` which will be used as the label of the hyperlink. * If this is not set, the label defined in {@see \rock\data\Sort::$attributes} will be used. * If no label is defined, {@see \rock\helpers\Inflector::camel2words()} will be called to get a label. * Note that it will not be HTML-encoded. * @return string the generated hyperlink * @throws DataProviderException if the attribute is unknown */ public function link($attribute, $options = []) { if (!class_exists('\\rock\\template\\Html')) { throw new DataProviderException(DataProviderException::NOT_INSTALL_TEMPLATE); } if (($direction = $this->getAttributeOrder($attribute)) !== null) { $class = $direction === SORT_DESC ? 'desc' : 'asc'; if (isset($options['class'])) { $options['class'] .= ' ' . $class; } else { $options['class'] = $class; } } $url = $this->createUrl($attribute); $options['data-sort'] = $this->createSortParam($attribute); if (isset($options['label'])) { $label = $options['label']; unset($options['label']); } else { if (isset($this->attributes[$attribute]['label'])) { $label = $this->attributes[$attribute]['label']; } else { $label = Inflector::camel2words($attribute); } } return Html::a($label, $url, $options); }