/** * Covert Image to HTML string */ public function getString() { $name = $this->getNameAttributeString(); $this->setAttribute('class', 'photo-picker'); $value = $this->getValue(); $this->removeAttribute('name'); $generator = new Generator(); if (!$this->getSetting('button')) { $this->setSetting('button', 'Insert Image'); } if ($value != "") { $class = $this->mediaProviderClass; $img = new $class(); if ($img instanceof MediaProvider && $img instanceof Model) { /** @var $img MediaProvider */ $img = $img->find($value); $src = $img->getThumbSrc(); $image = "<img src=\"{$src}\" />"; } else { throw new \Exception('Media field requires an Eloquent Model implementing TypeRocket\\MediaProvider'); } } else { $image = ''; } if (empty($image)) { $value = ''; } $html = $generator->newInput('hidden', $name, $value, $this->getAttributes())->getString(); $html .= '<div class="btn-group">'; $html .= $generator->newElement('input', array('type' => 'button', 'class' => 'image-picker-button btn btn-default', 'value' => $this->getSetting('button')))->getString(); $html .= $generator->newElement('input', array('type' => 'button', 'class' => 'image-picker-clear btn btn-default', 'value' => 'Clear'))->getString(); $html .= '</div>'; $html .= $generator->newElement('div', array('class' => 'image-picker-placeholder'), $image)->getString(); return $html; }
/** * Covert Items to HTML string */ public function getString() { $name = $this->getNameAttributeString(); $this->appendStringToAttribute('class', ' items-list'); // $this->attr['class'] = 'items-list'; $items = $this->getValue(); $this->removeAttribute('name'); $generator = new Generator(); if (!$this->getSetting('button')) { $this->setSetting('button', 'Insert Item'); } $list = ''; if (is_array($items)) { foreach ($items as $value) { $sanitize = "\\TypeRocket\\Sanitize::" . $this->getSetting('sanitize', 'attribute'); if (is_callable($sanitize)) { $value = call_user_func($sanitize, $value); } $input = $generator->newInput('text', $name . '[]', $value)->getString(); $remove = '#remove'; $list .= $generator->newElement('li', array('class' => 'item'), '<div class="move glyphicon glyphicon-menu-hamburger"></div><a href="' . $remove . '" class="glyphicon glyphicon-remove remove" title="Remove Item"></a>' . $input)->getString(); } } $this->removeAttribute('id'); $html = $generator->newInput('hidden', $name, '0', $this->getAttributes())->getString(); $html .= '<div class="btn-group">'; $html .= $generator->newElement('input', array('type' => 'button', 'class' => 'items-list-button btn btn-default', 'value' => $this->getSetting('button')))->getString(); $html .= $generator->newElement('input', array('type' => 'button', 'class' => 'items-list-clear btn btn-default', 'value' => 'Clear'))->getString(); $html .= '</div>'; if (is_null($name) && is_string($this->getAttribute('data-name'))) { $name = $this->getAttribute('data-name'); } $html .= $generator->newElement('ul', array('data-name' => $name, 'class' => 'tr-items-list cf'), $list)->getString(); return $html; }
private function getSelectHtml() { $name = $this->getName(); $options = $this->getOptions(); $options = $options ? $options : $this->setOptionsFromFolder()->getOptions(); if ($options) { $generator = new Generator(); $generator->newElement('select', array('data-mxid' => $this->mxid, 'class' => "matrix-select-{$name}", 'data-group' => $this->getForm()->getGroup())); $default = $this->getSetting('default'); foreach ($options as $name => $value) { $attr['value'] = $value; if ($default === $value) { $attr['selected'] = 'selected'; } else { unset($attr['selected']); } $generator->appendInside('option', $attr, $name); } $select = $generator->getString(); } else { $paths = Config::getPaths(); $dir = $paths['matrix_folder'] . '/' . $name; $select = "<div class=\"tr-dev-alert-helper\"><i class=\"icon tr-icon-bug\"></i> Add a files for Matrix <code>{$dir}</code> and add your matrix files to it.</div>"; } return $select; }
/** * Covert Select to HTML string */ public function getString() { $default = $this->getSetting('default'); $this->setAttribute('name', $this->getNameAttributeString()); $option = $this->getValue(); $option = !is_null($option) ? $option : $default; $generator = new Generator(); $generator->newElement('select', $this->getAttributes()); foreach ($this->options as $key => $value) { if (is_array($value)) { $optgroup = new Generator(); $optgroup->newElement('optgroup', ['label' => $key]); foreach ($value as $k => $v) { $attr['value'] = $v; if ($option == $v && isset($option)) { $attr['selected'] = 'selected'; } else { unset($attr['selected']); } $optgroup->appendInside('option', $attr, (string) $k); } $generator->appendInside($optgroup); } else { $attr['value'] = $value; if ($option == $value && isset($option)) { $attr['selected'] = 'selected'; } else { unset($attr['selected']); } $generator->appendInside('option', $attr, (string) $key); } } return $generator->getString(); }
/** * Covert Textarea to HTML string */ public function getString() { $generator = new Generator(); $this->setAttribute('name', $this->getNameAttributeString()); $value = $this->getValue(); $value = $this->sanitize($value, 'textarea'); $max = $this->getMaxlength($value, $this->getAttribute('maxlength')); return $generator->newElement('textarea', $this->getAttributes(), $value)->getString() . $max; }
/** * Get the max length for text type fields * * @param $value * @param $maxLength * * @return string|\TypeRocket\Html\Generator */ public function getMaxlength($value, $maxLength) { if ($maxLength != null && $maxLength > 0) { $left = (int) $maxLength - mb_strlen($value); $max = new Generator(); $max->newElement('p', ['class' => 'tr-maxlength'], 'Characters left: ')->appendInside('span', [], $left); $max = $max->getString(); } else { $max = ''; } return $max; }
/** * Covert Editor to HTML string */ public function getString() { $max = ''; $generator = new Generator(); $this->setAttribute('name', $this->getNameAttributeString()); $value = $this->getValue(); $this->appendStringToAttribute('class', ' typerocket-editor '); $sanitize = "\\TypeRocket\\Sanitize::" . $this->getSetting('sanitize', 'editor'); if (is_callable($sanitize)) { $value = call_user_func($sanitize, $value); } $maxLength = $this->getAttribute('maxlength'); if ($maxLength != null && $maxLength > 0) { $left = (int) $maxLength - strlen(utf8_decode($value)); $max = new Generator(); $max->newElement('p', array('class' => 'tr-maxlength'), 'Characters left: ')->appendInside('span', array(), $left); $max = $max->getString(); } return $generator->newElement('textarea', $this->getAttributes(), $value)->getString() . $max; }
/** * Covert Checkbox to HTML string */ public function getString() { $name = $this->getNameAttributeString(); $this->removeAttribute('name'); $default = $this->getSetting('default'); $option = $this->getValue(); $checkbox = new Generator(); $field = new Generator(); if ($option == '1' || !is_null($option) && $option === $this->getAttribute('value')) { $this->setAttribute('checked', 'checked'); } elseif ($default === true && is_null($option)) { $this->setAttribute('checked', 'checked'); } $checkbox->newInput('checkbox', $name, '1', $this->getAttributes()); $field->newElement('label')->appendInside($checkbox)->appendInside('span', array(), $this->getSetting('text')); if ($default !== false) { $hidden = new Generator(); $field->prependInside($hidden->newInput('hidden', $name, '0')); } return $field->getString(); }