function smarty_block_column($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\context('indent_level', 1, true); return; } $keys = array(); $class = array('column'); foreach ($params as $k => $v) { if (strpos($k, 'span') === 0) { // The key begin with layout if ($k == 'span') { $class[] = 'col-xs-' . $v; } else { $data = explode('-', $k); $class[] = 'col-' . $data[1] . '-' . $v; } $keys[] = $k; } } foreach ($keys as $k) { unset($params[$k]); } Clips\context_pop('indent_level'); return Clips\create_tag_with_content('div', $content, $params, array('class' => $class)); }
function smarty_block_navigation($params, $content = '', $template, &$repeat) { if ($repeat) { // Start the navigation ul Clips\clips_context('indent_level', 1, true); return; } $default = array('class' => array('nav')); $f = true; $actions = Clips\get_default($params, 'actions'); if ($actions) { unset($params['actions']); $content = ''; $level = Clips\context('indent_level'); if ($level === null) { $level = 0; } else { $level = count($level); } $indent = ''; for ($i = 0; $i < $level; $i++) { $indent .= "\t"; } foreach ($actions as $action) { // Only if the object is the valid action if (Clips\valid_obj($action, 'Clips\\Interfaces\\Action')) { $content .= _smarty_block_navigation_tree_node($action, $indent, $template, $repeat, Clips\get_default($params, 'item-class', array())); } } } Clips\context_pop('indent_level'); return Clips\create_tag_with_content('ul', $content, $params, $default); }
function smarty_block_dl($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\clips_context('indent_level', 1, true); return; } $items = Clips\get_default($params, 'items', array()); if ($items) { unset($params['items']); $level = Clips\context('indent_level'); if ($level === null) { $level = 0; } else { $level = count($level); } $indent = ''; for ($i = 0; $i < $level; $i++) { $indent .= "\t"; } if (!trim($content)) { $content = '{dt}{$key}{/dt}' . "\n{$indent}" . '{dd}{$value}{/dd}'; } $output = array(); $t = 'string:' . $content; foreach ($items as $key => $value) { $output[] = trim($template->fetch($t, array('key' => $key, 'value' => $value))); } $content = implode("\n{$indent}", $output); } Clips\context_pop('indent_level'); return Clips\create_tag_with_content('dl', $content, $params); }
function smarty_block_button($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\clips_context('indent_level', 1, true); return; } $value = Clips\get_default($params, 'caption'); if ($value) { // We did have value, so the content is the JavaScript $id = Clips\get_default($params, 'id', 'clips_button_' . Clips\sequence('button')); $js = "\$(\"#{$id}\").click(function(){\n\t\t" . trim($content) . "\n\t});"; $content = $value; unset($params['caption']); $params['id'] = $id; Clips\context('jquery_init', $js, true); } // For i18n $bundle_name = Clips\context('current_bundle'); $bundle = Clips\get_default($params, 'bundle', $bundle_name); if ($bundle !== null) { $bundle = Clips\bundle($bundle); $content = $bundle->message($content); } Clips\context_pop('indent_level'); return Clips\create_tag_with_content('button', $content, $params); }
function smarty_block_row($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\context('indent_level', 1, true); $level = Clips\context('indent_level'); $arr = array('level' => count($level), 'index' => 0); $keys = array(); foreach ($params as $k => $v) { if (strpos($k, 'layout') === 0) { // The key begin with layout $keys[] = $k; $arr[$k] = $v; } } foreach ($keys as $k) { unset($params[$k]); } // Push row's information into context stack Clips\context('row', (object) $arr, true); return; } $keys = array(); foreach ($params as $k => $v) { if (strpos($k, 'layout') === 0) { // The key begin with layout $keys[] = $k; } } foreach ($keys as $k) { unset($params[$k]); } Clips\context_pop('row'); Clips\context_pop('indent_level'); return Clips\create_tag_with_content('div', $content, $params, array('class' => 'row')); }
function smarty_block_form($params, $content = '', $template, &$repeat) { if ($repeat) { // Set the current form to the context Clips\clips_context('indent_level', 1, true); $name = Clips\get_default($params, 'name', Clips\default_form_name()); $data = Clips\context('form_' . $name); if ($data) { Clips\context('current_form_data', $data); } Clips\clips_context('current_form', $name); return; } $content .= "\t" . Clips\create_tag('input', array('type' => 'hidden', 'name' => Clips\Form::FORM_FIELD, 'value' => Clips\get_default($params, 'name', 'form'))); $action = Clips\get_default($params, 'action'); if ($action) { if (strpos($action, 'http') !== 0) { $params['action'] = Clips\site_url($action); } } if (Clips\get_default($params, 'upload')) { unset($params['upload']); $params['enctype'] = 'multipart/form-data'; } Clips\context_pop('current_form'); Clips\context_pop('current_form_data'); Clips\context_pop('indent_level'); return Clips\create_tag_with_content('form', $content, $params, array('action' => '#', 'method' => 'post', 'class' => ['clips-form', 'default-form'])); }
function smarty_block_style($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\clips_context('indent_level', 1, true); return; } Clips\context_pop('indent_level'); return Clips\create_tag_with_content('style', $content, $params, array('type' => 'text/css')); }
function smarty_block_b($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\clips_context('indent_level', 1, true); return; } Clips\context_pop('indent_level'); return Clips\create_tag_with_content('b', $content, $params); }
function smarty_block_template($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\clips_context('indent_level', 1, true); return; } Clips\context_pop('indent_level'); return Clips\create_tag_with_content('script', $content, $params, array('type' => "text/x-handlebars-template")); }
function smarty_block_figure($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\clips_context('indent_level', 1, true); return; } $src = Clips\get_default($params, 'src'); $path = Clips\get_default($params, 'path', 'responsive/size'); $resolutions = Clips\get_default($params, 'resolutions'); $img_path = Clips\find_image($src); if (!$img_path) { Clips\error('figure', array('Can\'t find image ' . $src . '!')); return ''; } $size = Clips\image_size($img_path); $size = $size['width']; if ($resolutions) { // If we are using auto resizing, skip the resolutions foreach ($resolutions as $res) { $attr['data-media' . $res] = Clips\site_url('responsive/size/' . (double) $res / 2880 * (double) $size . '/' . $src); } } else { $attr = array('path' => Clips\site_url($path)); } foreach ($params as $key => $value) { if ($key == 'path') { continue; } if (strpos($key, 'media') !== false) { $attr['data-' . $key] = Clips\site_url('responsive/size/' . $value . '/' . $src); } else { $attr[$key] = $value; } } $caption = Clips\create_tag_with_content('figcaption', $content); $image_dir = Clips\config('image_dir'); if ($image_dir) { $image_dir = $image_dir[0]; } else { $image_dir = 'application/static/img/'; } $img = Clips\create_tag('img', array('src' => Clips\static_url(Clips\path_join($image_dir, $src)))); $noscript = Clips\create_tag_with_content('noscript', $img); $level = Clips\context('indent_level'); if ($level === null) { $level = 0; } else { $level = count($level); } $indent = ''; for ($i = 0; $i < $level; $i++) { $indent .= "\t"; } Clips\context_pop('indent_level'); return Clips\create_tag_with_content('figure', $noscript . "\n{$indent}" . $caption, $attr); }
function smarty_block_listview($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\clips_context('indent_level', 1, true); return; } $default = array('class' => array('listview', 'clips-listview')); Clips\context_pop('indent_level'); return Clips\create_tag_with_content('ul', $content, $params, $default); }
function smarty_function_video($params, $template) { $src = Clips\get_default($params, 'src', null); if (!$src) { Clips\error("No src found for this video tag."); return ''; } $src = Clips\create_tag('source', array('src' => $src, 'type' => "application/x-mpegURL")); return Clips\create_tag_with_content('video', $src, $params, array('class' => array('video-js', 'vjs-default-skin'), 'id' => 'video', 'controls')); }
function smarty_block_html($params, $content = '', $template, &$repeat) { $version = Clips\get_default($params, 'version', '5'); Clips\clips_context('html_version', $version); if ($repeat) { Clips\clips_context('indent_level', 1, true); // Enstack indent level return; } $default = array(); switch ($version) { case '4': case '4t': $default['lang'] = 'en'; $pre = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'; break; case '4s': $default['lang'] = 'en'; $pre = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'; break; case '4f': $default['lang'] = 'en'; $pre = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'; break; case 'xhtml': $default['xmlns'] = 'http://www.w3.org/1999/xhtml'; $default['xml:lang'] = 'en'; $pre = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'; break; case 'xhtmlt': $default['xmlns'] = 'http://www.w3.org/1999/xhtml'; $default['xml:lang'] = 'en'; $pre = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'; break; case 'xhtmlf': $default['xmlns'] = 'http://www.w3.org/1999/xhtml'; $default['xml:lang'] = 'en'; $pre = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">'; break; case 'xhtml1.1': $default['xmlns'] = 'http://www.w3.org/1999/xhtml'; $default['xml:lang'] = 'en'; $pre = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'; break; case '5': $default['lang'] = 'en'; $pre = '<!DOCTYPE html>'; break; } if (isset($params['version'])) { unset($params['version']); } Clips\context_pop('indent_level'); return $pre . "\n" . Clips\create_tag_with_content('html', $content, $params, $default); }
function smarty_block_ol($params, $content = '', $template, &$repeat) { if ($repeat) { return; } $content = Clips\process_list_items($params, $content, $template); if (isset($params['items'])) { unset($params['items']); } return Clips\create_tag_with_content('ol', $content, $params); }
function smarty_block_script($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\clips_context('indent_level', 1, true); return; } Clips\context_pop('indent_level'); if ($content) { return Clips\create_tag_with_content('script', trim($content), $params, array('type' => 'text/javascript')); } return ''; }
function smarty_block_jsx($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\context('indent_level', 1, true); return; } // The element tag name that holds the virtual dom $tag = Clips\get_default($params, 'tag', 'div'); $id = Clips\render_jsx($content, Clips\get_default($params, 'id')); Clips\context_pop('indent_level'); return Clips\create_tag_with_content($tag, '', array('id' => $id, 'class' => array('jsx', 'jsx_holder'))); }
function smarty_block_head($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\clips_context('indent_level', 1, true); // Enstack indent level return; } $encoding = Clips\get_default($params, 'encoding', 'UTF-8'); $version = Clips\context('html_version'); $title = Clips\get_default($params, 'title', null); if (!$title) { // If didn't found title on the parameter, try find it in context $title = Clips\context('html_title'); } // Adding metas if (!$version) { $version = 5; } $meta = Clips\context('html_meta'); if (!$meta) { $meta = array(); } switch ($version) { case '4': case '4t': case '4s': case '4f': case 'xhtml': case 'xhtmlt': case 'xhtmlf': case 'xhtml1.1': array_unshift($meta, array('http-equiv' => 'Content-Type', 'content' => 'text/html;charset=' . $encoding)); break; case '5': array_unshift($meta, array('charset' => $encoding)); break; } $pre = array(); foreach ($meta as $m) { $pre[] = Clips\create_tag('meta', $m); } // Adding the title if ($title) { $pre[] = Clips\create_tag_with_content('title', $title); } $pre = "\t" . implode("\n\t\t", $pre); if (isset($params['title'])) { unset($params['title']); } Clips\context_pop('indent_level'); // Pop the stack before output return Clips\create_tag_with_content('head', $pre . $content, $params); }
function smarty_block_ul($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\clips_context('indent_level', 1, true); return; } $content = "\t" . Clips\process_list_items($params, $content, $template); if (isset($params['items'])) { unset($params['items']); } Clips\context_pop('indent_level'); return Clips\create_tag_with_content('ul', $content, $params); }
function smarty_block_markup($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\context('indent_level', 1, true); return; } $tool =& Clips\get_clips_tool(); $flavor = Clips\get_default($params, 'flavor', 'github'); $markup = $tool->library('markup'); $content = $markup->render($content, $flavor); Clips\context_pop('indent_level'); return Clips\create_tag_with_content('div', $content, $params, array('class' => 'markup')); }
function smarty_block_a($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\clips_context('indent_level', 1, true); return; } $uri = Clips\get_default($params, 'uri'); if ($uri) { unset($params['uri']); $params['href'] = Clips\site_url($uri); } Clips\context_pop('indent_level'); return Clips\create_tag_with_content('a', $content, $params); }
function smarty_block_container($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\clips_context('indent_level', 1, true); return; } $fluid = Clips\get_default($params, 'fluid', false); $class = 'container'; if ($fluid) { $class = 'container-fluid'; unset($params['fluid']); } Clips\context_pop('indent_level'); return Clips\create_tag_with_content('div', $content, $params, array('class' => $class)); }
function smarty_block_label($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\clips_context('indent_level', 1, true); return; } Clips\context_pop('indent_level'); $bundle_name = Clips\context('current_bundle'); $bundle = Clips\get_default($params, 'bundle', $bundle_name); if ($bundle !== null) { $bundle = Clips\bundle($bundle); $content = $bundle->message($content); } return Clips\create_tag_with_content('label', $content, $params); }
function smarty_block_textarea($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\clips_context('indent_level', 1, true); return; } $default = array('class' => array('form-input', 'form-control')); $f = Clips\clips_context('current_field'); if ($f) { $default = $f->getDefault($default); } $data = Clips\context('current_form_field_data'); if ($data) { $content = $data; } $state = Clips\context('current_form_field_state'); if ($state && $state == 'readonly') { return "<p>{$content}</p>"; } Clips\context_pop('indent_level'); return Clips\create_tag_with_content('textarea', $content, $params, $default, true); }
function smarty_block_qrcode($params, $content = '', $template, &$repeat) { if ($repeat) { return; } $config = Clips\get_default($params, 'config'); if ($config) { $arr = array(); foreach ($config as $k => $v) { $arr[] = $k . '=' . urlencode($v); } $params['data-pattern'] = 'qr/generate/_(img)?size=_(size)&' . implode('&', $arr); } else { $params['data-pattern'] = 'qr/generate/_(img)?size=_(size)'; } $params['data-image'] = str_replace('%2f', '%252F', str_replace('%2F', '%252F', urlencode($content))); $width = Clips\get_default($params, 'width'); $div = array('class' => 'responsive'); if ($width) { unset($params['width']); $div['style'] = 'width:' . $width . 'px;'; } return Clips\create_tag_with_content('div', smarty_function_img($params, $template), $div); }
function smarty_block_field($params, $content = '', $template, &$repeat) { Clips\require_widget_smarty_plugin('Html', 'div'); Clips\require_widget_smarty_plugin('Html', 'label'); // Global variables $labelClass = Clips\get_default($params, 'label-class', 'form-label'); $inputClass = Clips\get_default($params, 'input-class', 'form-input'); $glyphicon = Clips\get_default($params, 'glyphicon', null); if ($repeat) { // The header part // Init the context Clips\context('indent_level', 1, true); Clips\context('indent_level', 1, true); // Indent for the inner div Clips\context_pop('current_field'); // Remove the last current field // Getting the form $form = Clips\context('form'); if ($form) { // Getting the field $field = Clips\get_default($params, 'field', null); if (!isset($field)) { Clips\show_error('No field configured for the field plugin!'); return; } $f = $form->field($field); if (!isset($f)) { Clips\show_error('No field configuration found for field %s!', $field); return; } // Put the field to context Clips\context('current_field', $f); // Processing the form data $data = Clips\get_default(Clips\context('current_form_data'), $field); if ($data) { Clips\context('current_form_field_data', $data, true); // Update the field's value to data $f->value = $data; } // Processing the states $state = Clips\get_default($params, 'state'); if (!$state) { $state = Clips\field_state($f); } if ($state) { Clips\context('current_form_field_state', $state); } } else { Clips\show_error('No form configuration found for this field!'); } } else { if (Clips\clips_context('current_field')) { Clips\context_pop('indent_level'); $f = Clips\clips_context('current_field'); if (\Clips\get_default($f, 'state') == 'none' || $f->state == 'none') { Clips\context_pop('indent_level'); return ''; } if (\Clips\get_default($params, 'state') == 'hidden' || \Clips\get_default($f, 'hidden') || $f->state == 'hidden') { Clips\context_pop('indent_level'); Clips\require_widget_smarty_plugin('Form', 'input'); return smarty_function_input(array('type' => 'hidden'), $template); } // Now for rendering $ret = array(); // Render the icon if ($glyphicon) { // Add the glyphicon $ret[] = Clips\create_tag_with_content('span', '', array('class' => array('glyphicon', 'glyphicon-' . $glyphicon, 'form-control-feedback')), array(), true); } // Render the label $r = true; smarty_block_label(array(), '', $template, $r); // Skip the label head $r = false; $ret[] = smarty_block_label(array('for' => $f->getId(), 'class' => array($labelClass, 'control-label', isset($f->required) ? 'form_field_required' : '')), $f->label, $template, $r); // Render the input row head $r = true; smarty_block_div(array(), '', $template, $r); // Skip the div head // If no input set, using default input if (trim($content) == '') { Clips\require_widget_smarty_plugin('Form', 'input'); $content = smarty_function_input(array(), $template); } // Close the input div $ret[] = smarty_block_div(array('class' => $inputClass), $content, $template, $repeat); // Added the help block $ret[] = Clips\create_tag_with_content('p', '', array('class' => 'help-block'), array(), true); $level = Clips\context('indent_level'); if ($level === null) { $level = 0; } else { $level = count($level); } $indent = ''; for ($i = 0; $i < $level; $i++) { $indent .= "\t"; } // Altogether Clips\context_pop('indent_level'); CLips\context_pop('current_form_field_data'); CLips\context_pop('current_form_field_state'); return Clips\create_tag_with_content('div', implode("\n{$indent}", $ret), $params, array('class' => array('form-group', 'control-group'))); } } }
function smarty_block_action($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\clips_context('indent_level', 1, true); return; } $default = array('class' => 'action'); $action = Clips\get_default($params, 'action'); if ($action && Clips\valid_obj($action, 'Clips\\Interfaces\\Action')) { $ps = $action->params(); $icon = $action->icon(); $caption = array(); if ($icon) { $caption[] = Clips\create_tag_with_content('i', '', array('class' => $icon)); $caption[] = Clips\create_tag_with_content('span', $action->label()); if ($action->children()) { $caption[] = Clips\create_tag_with_content('i', '', array('class' => array('fa', 'fa-angle-left', 'pull-right'))); } $caption = implode('', $caption); } else { $caption = $action->label(); } if (!isset($params['title'])) { // Add tooltip $params['title'] = $action->label(); } // This is valid action object switch ($action->type()) { case Action::CLIENT: $params['caption'] = $caption; if ($ps) { foreach ($ps as $k => $v) { $params['data-' . $k] = $v; } } $content = $action->content(); break; case Action::HEADER: return $caption; case Action::SERVER: $content = $caption; if ($ps) { $suffix = implode('/', array_map(function ($item) { return urlencode($item); }, $ps)); $params['uri'] = \Clips\path_join($action->content(), $suffix); } else { $params['uri'] = $action->content(); } break; case Action::EXTERNAL: $content = $caption; $suffix = array(); foreach ($ps as $k => $v) { $suffix[] = urlencode($k) . '=' . urlencode($v); } if ($suffix) { $suffix = implode('&', $suffix); $params['href'] = $action->content() . '?' . $suffix; } else { $params['href'] = $action->content(); } break; } unset($params['action']); } $value = Clips\get_default($params, 'caption'); if ($value) { // We did have value, so the content is the JavaScript $id = Clips\get_default($params, 'id', 'clips_action_' . Clips\sequence('action')); $js = "\$(\"#{$id}\").click(function(){\n\t\t" . trim($content) . "\n\t});"; $content = $template->fetch('string:' . $value); unset($params['caption']); $params['id'] = $id; $params['href'] = 'javascript:void(0)'; Clips\context('jquery_init', $js, true); } else { // Check for action uri $uri = Clips\get_default($params, 'uri'); if ($uri) { $params['href'] = Clips\site_url($uri); unset($params['uri']); } if (!isset($params['title'])) { // Add tooltip $params['title'] = trim($content); } } Clips\context_pop('indent_level'); $bundle_name = Clips\context('current_bundle'); $bundle = Clips\get_default($params, 'bundle', $bundle_name); if ($bundle !== null) { $bundle = Clips\bundle($bundle); $content = $bundle->message($content); } return Clips\create_tag_with_content('a', $content, $params, $default); }
function smarty_function_picture($params, $template) { $src = Clips\get_default($params, 'src'); if ($src) { if (preg_match('/_\\([A-Za-z0-9_]+\\)/', $src)) { $is_template = true; } } if (!isset($is_template)) { $path = Clips\get_default($params, 'path', 'responsive/size'); $resolutions = Clips\get_default($params, 'resolutions'); $medias = Clips\get_default($params, 'medias'); $img_path = Clips\find_image($src); if (!$img_path) { Clips\error('picture', array('Can\'t find image ' . $src . '!')); return ''; } $size = Clips\image_size($img_path); $size = $size['width']; $content = array(); $level = Clips\context('indent_level'); if ($level === null) { $level = 0; } else { $level = count($level); } $indent = ''; for ($i = 0; $i < $level; $i++) { $indent .= "\t"; } if ($resolutions || $medias) { if ($resolutions) { // If we are using auto resizing, skip the resolutions unset($params['resolutions']); foreach ($resolutions as $res) { $content[] = "\t" . Clips\create_tag('source', array('src' => Clips\site_url('responsive/size/' . (double) $res / 2880 * (double) $size . '/' . $src), 'media' => '(min-width:' . $res . 'px)')); } } if ($medias) { unset($params['medias']); foreach ($medias as $media => $res) { $content[] = "\t" . Clips\create_tag('source', array('src' => Clips\site_url('responsive/size/' . $res . '/' . $src), 'media' => '(min-width:' . $media . 'px)')); } } } else { $params['path'] = Clips\site_url($path); } $image_dir = Clips\config('image_dir'); if ($image_dir) { $image_dir = $image_dir[0]; } else { $image_dir = 'application/static/img/'; } Clips\clips_context('indent_level', 1, true); $img = Clips\create_tag('img', array('src' => Clips\static_url(Clips\path_join($image_dir, $src)))); $content[] = "\t" . Clips\create_tag_with_content('noscript', $img); Clips\context_pop('indent_level'); } else { $params['data-role'] = 'item-picture'; $params['path'] = Clips\site_url(Clips\get_default($params, 'path', 'responsive/size')); $indent = ''; $content = array(); } return Clips\create_tag_with_content('picture', implode("\n{$indent}", $content), $params); }
function smarty_block_select($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\context('indent_level', 1, true); return; } $options = Clips\get_default($params, 'options', array()); $label = Clips\get_default($params, 'label-field', 'label'); $value = Clips\get_default($params, 'value-field', 'value'); $blank = Clips\get_default($params, 'blank'); $prepend = Clips\get_default($params, 'prepend'); $append = Clips\get_default($params, 'append'); $default = array(); $field = Clips\context('current_field'); if ($field) { $o = $field->getCascadeOptions(); if ($o) { $options = $field->getCascadeOptions(); } } if ($options) { if ($prepend) { $prepend = array_reverse($prepend); foreach ($prepend as $k => $v) { if (is_string($k)) { // This is key => value $d = array(); $d[$label] = $k; $d[$value] = $v; array_unshift($options, (object) $d); } else { if (is_array($v) || is_object($v)) { // This array array_unshift($options, (object) $v); } else { // This is string array_unshift($options, $v); } } } } if ($append) { foreach ($append as $k => $v) { if (is_string($k)) { // This is key => value $d = array(); $d[$label] = $k; $d[$value] = $v; $options[] = (object) $d; } else { if (is_array($v) || is_object($v)) { // This array $options[] = (object) $v; } else { // This is string $options[] = $v; } } } } if ($blank) { if (is_bool($blank)) { $blank = array(); $blank[$label] = '-- Please Select --'; $blank[$value] = '-- Please Select --'; } array_unshift($options, (object) $blank); } $data = Clips\context_pop('current_form_field_data'); if (trim($content)) { $tpl = 'string:' . trim($content); } $content = array(); foreach ($options as $key => $option) { if (isset($tpl)) { // We do have template here $content[] = $template->fetch($tpl, array('option' => $option)); } else { if (is_string($key) && !is_string($option)) { $l = $key; if ($data) { if (is_array($data)) { if (array_search($option, $data) !== false) { $default = array('selected'); } } else { if ($data == $option) { $default = array('selected'); } } } else { $default = array(); } if (is_string($key)) { $default['value'] = $option; } } else { if (is_string($option)) { $l = $option; if ($data) { if (is_array($data)) { if (array_search($option, $data) !== false) { $default = array('selected'); } } else { if ($data == $option) { $default = array('selected'); } } } else { $default = array(); } if (is_string($key)) { $default['value'] = $key; } } else { if (is_array($option)) { $l = $option[$label]; $default = array('value' => $option[$value]); if ($data) { if (is_array($data)) { if (array_search($option[$value], $data) !== false) { $default[] = 'selected'; } } else { if ($data == $option[$value]) { $default[] = 'selected'; } } } } else { if (is_object($option)) { $l = $option->{$label}; $default = array('value' => $option->{$value}); if ($data) { if (is_array($data)) { if (array_search($option->{$value}, $data) !== false) { $default[] = 'selected'; } } else { if ($data == $option->{$value}) { $default[] = 'selected'; } } } } } } } $content[] = Clips\create_tag_with_content('option', $l, $default); } } $level = Clips\context('indent_level'); if ($level === null) { $level = 0; } else { $level = count($level); } $indent = ''; for ($i = 0; $i < $level; $i++) { $indent .= "\t"; } $content = implode("\n{$indent}", $content); unset($params['options']); } $f = Clips\clips_context('current_field'); if ($f) { $default = $f->getDefault($default); } Clips\context_pop('indent_level'); return Clips\create_tag_with_content('select', $content, $params, $default); }
function smarty_function_datatable($params, $template) { $default = array('class' => array('datatable', 'clips-datatable'), 'cellspacing' => '0'); return \Clips\create_tag_with_content('table', '', $params, $default, true); }
function smarty_function_resimg($params, $template) { return Clips\create_tag_with_content('div', smarty_function_img($params, $template), array('class' => 'responsive')); }