Example #1
0
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_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);
}
Example #3
0
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);
}
Example #4
0
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);
}
Example #5
0
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));
}
Example #6
0
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']));
}
Example #7
0
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'));
}
Example #8
0
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"));
}
Example #10
0
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);
}
Example #11
0
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_block_swiper__prevbtn($params, $content = '', $template, &$repeat)
{
    if ($repeat) {
        \Clips\clips_context('indent_level', 1, true);
        return;
    }
    $default = array('class' => 'swiper-button-prev swiper-button-white');
    \Clips\context_pop('indent_level');
    return \Clips\create_tag('div', $params, $default, $content);
}
function smarty_block_slider($params, $content = '', $template, &$repeat)
{
    if ($repeat) {
        \Clips\clips_context('indent_level', 1, true);
        return;
    }
    $default = array('class' => 'slider');
    \Clips\context_pop('indent_level');
    return \Clips\create_tag('div', $params, $default, $content);
}
Example #14
0
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);
}
Example #15
0
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 '';
}
Example #16
0
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')));
}
Example #17
0
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);
}
Example #18
0
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);
}
Example #19
0
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'));
}
Example #20
0
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_swiper__wrapper($params, $content = '', $template, &$repeat)
{
    if ($repeat) {
        \Clips\clips_context('indent_level', 1, true);
        return;
    }
    $default = array('class' => 'swiper-wrapper');
    $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('div', $params, $default, $content);
}
Example #22
0
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));
}
Example #23
0
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);
}
Example #24
0
function smarty_block_states($params, $content = '', $template, &$repeat)
{
    $state = Clips\get_default($params, 'state');
    if ($repeat) {
        if ($state) {
            Clips\context('state', $state, true);
        }
        // Append the state into the state stack
        return;
    }
    if ($state) {
        Clips\context_pop('state');
    }
    Clips\context_pop('matched_state');
    return trim($content);
}
Example #25
0
function smarty_function_input($params, $template)
{
    $default = array('class' => array('form-input', 'form-control'));
    $f = Clips\clips_context('current_field');
    if ($f) {
        $default = $f->getDefault($default);
    }
    $data = Clips\context_pop('current_form_field_data');
    if ($data) {
        $default['value'] = $data;
    }
    $state = Clips\context('current_form_field_state');
    if ($state && $state == 'readonly') {
        $value = Clips\get_default($default, 'value');
        if ($value) {
            return "<span>{$value}</span>";
        }
        return "<span>" . Clips\get_default($params, 'value', '') . "</span>";
    }
    return Clips\create_tag('input', $params, $default);
}
Example #26
0
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);
}
Example #27
0
function smarty_block_alert($params, $content = '', $template, &$repeat)
{
    if ($repeat) {
        \Clips\clips_context('indent_level', 1, true);
        return;
    }
    $show = \Clips\get_default($params, 'show', 'info');
    unset($params['show']);
    $default = array('class' => array('alert', $show));
    $true = true;
    // Add message div
    // Open message div
    smarty_block_div(array('class' => 'alert-message'), $content, $template, $true);
    // Close message div
    $message = smarty_block_div(array('class' => 'alert-message'), $content, $template, $repeat);
    // Open controls
    smarty_block_div(array('class' => 'alert-control'), '', $template, $true);
    // Open close button
    smarty_block_div(array('class' => 'btn', 'alert-for' => 'close'), \Clips\lang('close'), $template, $true);
    // Close close button
    $close_button = smarty_block_div(array('class' => 'btn', 'alert-for' => 'close'), \Clips\lang('close'), $template, $repeat);
    // Close controls
    $controls = smarty_block_div(array('class' => 'alert-control'), $close_button, $template, $repeat);
    $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('div', $params, $default, $message . "\n" . $indent . $controls);
}
function smarty_block_swiper__slide($params, $content = '', $template, &$repeat)
{
    if ($repeat) {
        \Clips\clips_context('indent_level', 1, true);
        return;
    }
    $default = array('class' => 'swiper-slide');
    $dataImage = \Clips\get_default($params, 'data-image', null);
    $paginationImage = \Clips\get_default($params, 'data-pagination-image', null);
    $responsive = \Clips\get_default($params, 'responsive', false);
    $image = '';
    if ($dataImage) {
        if ($responsive == "true") {
            $image = smarty_function_resimg(array('data-image' => $dataImage, 'data-pagination-src' => $paginationImage), $template);
        } else {
            $image = smarty_function_img(array('src' => $dataImage, 'data-pagination-src' => $dataImage), $template);
        }
        unset($params['data-image']);
        unset($params['data-pagination-image']);
        unset($params['responsive']);
    }
    \Clips\context_pop('indent_level');
    return \Clips\create_tag('div', $params, $default, $image . $content);
}
Example #29
0
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')));
        }
    }
}
Example #30
0
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);
}