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);
}
Beispiel #2
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);
}
Beispiel #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);
}
Beispiel #4
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']));
}
Beispiel #5
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"));
}
Beispiel #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'));
}
Beispiel #8
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);
}
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);
}
Beispiel #12
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);
}
Beispiel #13
0
 public function filter_after($chain, $controller, $method, $args, $request, $controller_ret)
 {
     $init = \Clips\clips_context('jquery_init');
     if ($init) {
         if (!is_array($init)) {
             $init = array($init);
         }
         $init[] = "if(typeof initialize === 'function') initialize();";
         \Clips\add_init_js('jQuery(function($){' . implode("\n", $init) . '});');
     }
 }
Beispiel #14
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);
}
Beispiel #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 '';
}
Beispiel #16
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);
}
function smarty_function_context($params, $template)
{
    $key = Clips\get_default($params, 'key', null);
    if ($key) {
        $formatter = Clips\get_default($params, 'formatter', null);
        $obj = Clips\clips_context($key);
        if ($formatter) {
            return Clips\format($obj, $formatter);
        }
        return $obj;
    }
    return '';
}
Beispiel #18
0
 public function filter_after($chain, $controller, $method, $args, $request, $controller_ret)
 {
     $css = \Clips\clips_context('css');
     if ($css) {
         if (!is_array($css)) {
             $css = array($css);
         }
         $css = array_map(function ($item) {
             return '<link rel="stylesheet" href="' . \Clips\safe_add_extension($item, 'css') . '">';
         }, $css);
         \Clips\clips_context('css', implode("\n\t\t", $css), false);
     }
 }
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);
}
Beispiel #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);
}
Beispiel #21
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);
}
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));
}
    /**
     * @Clips\Model({"tag", "category","user","cart"})
     * @Clips\Widgets\ListView("people_index")
     * @Clips\Scss("people/index")
     * @Clips\Form('people/index')
     * @Clips\Js("application/static/js/people/people.js")
     */
    public function index()
    {
        $this->title('People Page', true);
        $render_data = array();
        $area = $this->tag->getTagByName('宅生活');
        //		if($area){
        //			$level = $this->tag->getMaxLevel($area->id);
        //			for($i=$area->level+1; $i<=$level;$i++){
        //				$render_data['tag'.$i] = $this->tag->getTagsByLevel($i, $area->id);
        //			}
        //		}
        $p = array('products.category_id' => $this->category->getProductID());
        if (true) {
            $this->request->session('mall_index', $p);
        }
        $data = json_encode($this->tag->getTags($area));
        $js = <<<TEXT
\tvar layer = \$('ul.layer');
\tvar api = \$('#people_index').data('api');
\tvar ds = new Clips.DataSource({$data});
\t\$("#people_index").on('list.init', function(e, list){
\t\tapi.clearSearch(list);
\t});
\tlayer.each(function(){
\t\tnew Clips.Layer(ds, this);
\t});
\tlayer.on('click', 'li.active',  function(e){
\t\tvar li = \$(e.currentTarget);
\t\tvar path = li.data('id');
\t\tvar id = path.split('/');
\t\tid.pop();
\t\tid = id.pop();
\t\tapi.columnSearch(1, id);
//\t\tli.parent().parent().parent().find('h3').hide();
\t});
\tlayer.on('list.tags.init-active', function(e, ul){
\t\t\$(ul.node).parent().addClass('show');
\t});
\tlayer.on('list.tags.refresh', function(e, ul){
\t\t\$(ul.node).parent().removeClass('show');
\t});
\tlayer.on('list.tags.always-active', function(e, ul){
\t\t\$(ul.node).parent().addClass('show');
\t});
TEXT;
        \Clips\clips_context('jquery_init', $js, true);
        return $this->render('people/index', $render_data);
    }
    /**
     * @Clips\Model({"tag", "category","user","cart"})
     * @Clips\Widgets\ListView("coupon_index")
     * @Clips\Scss("coupon/index")
     * @Clips\Form('coupon/index')
     * @Clips\Js("application/static/js/mall/mall.js")
     */
    public function index()
    {
        $this->title('Coupon Page', true);
        $render_data = array();
        $area = $this->tag->getTagByName('券生活');
        if ($area) {
            //			$level = $this->tag->getMaxLevel($area->id);
            //			for($i=$area->level+1; $i<=$level;$i++){
            //				$render_data['tag'.$i] = $this->tag->getTagsByLevel($i, $area->id);
            //			}
        }
        $now = new \DateTime();
        $p = array('products.category_id' => $this->category->getCouponCategoryId());
        $p[] = new \Clips\Libraries\CommonOperator('products.expire_date', $now->format('Y-m-d H:i:s'), '>=');
        $this->request->session('coupon_index', $p);
        $data = json_encode($this->tag->getTags($area));
        $js = <<<TEXT
\tvar layer = \$('ul.layer');
\tvar api = \$('#coupon_index').data('api');
\tvar ds = new Clips.DataSource({$data});
\t\$("#coupon_index").on('list.init', function(e, list){
\t\tapi.clearSearch(list);
\t});
\tlayer.each(function(){
\t\tnew Clips.Layer(ds, this);
\t});
\tlayer.on('click', 'li.active',  function(e){
\t\tvar li = \$(e.currentTarget);
\t\tvar path = li.data('id');
\t\tvar id = path.split('/');
\t\tid.pop();
\t\tid = id.pop();
\t\tapi.columnSearch(1, id);
\t});
\tlayer.on('list.tags.init-active', function(e, ul){
\t\t\$(ul.node).parent().addClass('show');
\t});
\tlayer.on('list.tags.refresh', function(e, ul){
\t\t\$(ul.node).parent().removeClass('show');
\t});
\tlayer.on('list.tags.always-active', function(e, ul){
\t\t\$(ul.node).parent().addClass('show');
\t});
TEXT;
        \Clips\clips_context('jquery_init', $js, true);
        return $this->render('coupon/index');
    }
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);
}
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_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);
}
Beispiel #28
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);
}
Beispiel #29
0
 public function filter_before($chain, $controller, $method, $args, $request)
 {
     $widgets = \Clips\clips_context('widgetsv2');
     if ($widgets) {
         if (!is_array($widgets)) {
             $widgets = array($widgets);
         }
         $name = implode(' ', array_map(function ($item) {
             return get_class($item);
         }, $widgets));
         $name = 'widget_' . md5($name) . '.json';
         $smarty = \Clips\context('smarty');
         if ($this->filecache->exists($name) && \Clips\config('widget_cache')) {
             // Let's use this widget cache
             $cache = unserialize($this->filecache->contents($name));
             if (isset($cache['js'])) {
                 $origin = $this->tool->context('js');
                 if ($origin) {
                     $cache['js'] = array_merge($cache['js'], $origin);
                 }
                 $this->tool->context('js', $cache['js']);
             }
             if (isset($cache['jquery'])) {
                 $jquery = $cache['jquery'];
                 if (!is_array($jquery)) {
                     $jquery = array($jquery);
                 }
                 foreach ($jquery as $j) {
                     $this->tool->context('jquery_init', $j, true);
                 }
             }
             if (isset($cache['css'])) {
                 $origin = $this->tool->context('css');
                 if ($origin) {
                     $cache['css'] = array_merge($cache['css'], $origin);
                 }
                 $this->tool->context('css', $cache['css']);
             }
             if (isset($cache['scss'])) {
                 $origin = $this->tool->context('scss');
                 if ($origin) {
                     $cache['scss'] = array_merge($cache['scss'], $origin);
                 }
                 $this->tool->context('scss', $cache['scss']);
             }
             if (isset($cache['sass_include'])) {
                 $this->sass->addIncludePath($cache['sass_include']);
             }
             if (isset($cache['context'])) {
                 $c = $cache['context'];
                 if (!is_array($c)) {
                     $c = array($c);
                     foreach ($c as $cc) {
                         $this->tool->context($cc, null, true);
                     }
                 }
             }
             if (isset($cache['smarty'])) {
                 if ($smarty) {
                     $smarty->setPluginsDir($cache['smarty']);
                 }
             }
         } else {
             $js = $this->tool->context('js');
             $css = $this->tool->context('css');
             $scss = $this->tool->context('scss');
             $jquery_init = $this->tool->context('jquery_init');
             $this->tool->context_clear('js');
             $this->tool->context_clear('css');
             $this->tool->context_clear('scss');
             $this->tool->context_clear('jquery_init');
             foreach ($widgets as $w) {
                 $w->init_v2();
             }
             // Caching js, css and scss configurations
             $cache = array();
             // Caching smarty's plugins dir
             if ($smarty) {
                 $cache['smarty'] = $smarty->getPluginsDir();
             }
             $js_widget = \Clips\context('js');
             if ($js_widget) {
                 $cache['js'] = $js_widget;
             }
             $css_widget = \Clips\context('css');
             if ($css_widget) {
                 $cache['css'] = $css_widget;
             }
             $jquery = \Clips\context('jquery_init');
             if ($jquery) {
                 $cache['jquery'] = $jquery;
             }
             $cache['sass_include'] = $this->sass->getIncludePaths();
             $scss_widget = \Clips\context('scss');
             if ($scss_widget) {
                 $cache['scss'] = $scss_widget;
             }
             $context = \Clips\context('widget_context');
             if ($context) {
                 if (!is_array($context)) {
                     $context = array($context);
                 }
                 $cache['context'] = array();
                 foreach ($context as $c) {
                     $cache['context'][] = $c;
                 }
             }
             // Save the cache
             $this->filecache->save($name, serialize($cache));
             // Append other js, css and scss to the end
             if ($js) {
                 if (!is_array($js)) {
                     $js = array($js);
                 }
                 foreach ($js as $j) {
                     $this->tool->context('js', $j, true);
                 }
             }
             if ($jquery_init) {
                 foreach ($jquery_init as $j) {
                     $this->tool->context('jquery_init', $j, true);
                 }
             }
             if ($css) {
                 if (!is_array($css)) {
                     $css = array($css);
                 }
                 foreach ($css as $j) {
                     $this->tool->context('css', $j, true);
                 }
             }
             if ($scss) {
                 if (!is_array($scss)) {
                     $scss = array($scss);
                 }
                 foreach ($scss as $j) {
                     $this->tool->context('scss', $j, true);
                 }
             }
         }
     }
 }
Beispiel #30
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')));
        }
    }
}