예제 #1
0
function create_shortcode($popup)
{
    global $shortcode;
    if (isset($shortcode) && is_array($shortcode)) {
        $shortcode_param = $shortcode[$popup]['params'];
        $shortcode_code = $shortcode[$popup]['shortcode'];
        $shortcode_output = print_shortcode("\n" . '<div id="old-shortcode" class="hidden">' . $shortcode_code . '</div>');
        $shortcode_output = print_shortcode("\n" . '<div id="shortcode-popup" class="hidden">' . $popup . '</div>');
        foreach ($shortcode_param as $key => $param) {
            $key = 'shortcode_' . $key;
            $row_start = '<tbody>' . "\n";
            $row_start .= '<tr style="height:40px;">' . "\n";
            $row_start .= '<th class="label" style="vertical-align:top;width: 98px;padding-top:10px"><span class="alignleft">' . $param['label'] . '</span></th>' . "\n";
            $row_start .= '<td class="field">' . "\n";
            $row_end = '<span>' . $param['desc'] . '</span>' . "\n";
            $row_end .= '</td>' . "\n";
            $row_end .= '</tr>' . "\n";
            $row_end .= '</tbody>' . "\n";
            switch ($param['type']) {
                case 'text':
                    if (!isset($param['options']['width'])) {
                        $param['options']['width'] = '98px';
                    }
                    $output = $row_start;
                    $output .= '<input type="text" class="popup-input" style="width:' . $param['options']['width'] . '" name="' . $key . '" id="' . $key . '" value="' . $param['std'] . '" />' . "\n";
                    $output .= $row_end;
                    print_shortcode($output);
                    break;
                case 'textarea':
                    if (!isset($param['options']['rows'])) {
                        $param['options']['rows'] = '10';
                    }
                    if (!isset($param['options']['width'])) {
                        $param['options']['width'] = '100%';
                    }
                    $output = $row_start;
                    $output .= '<textarea rows="' . $param['options']['rows'] . '" style="width:' . $param['options']['width'] . '" name="' . $key . '" id="' . $key . '" class="popup-input">' . $param['std'] . '</textarea>' . "\n";
                    $output .= $row_end;
                    print_shortcode($output);
                    break;
                case 'select':
                    $output = $row_start;
                    $output .= '<select name="' . $key . '" id="' . $key . '" class="popup-input">' . "\n";
                    foreach ($param['options'] as $value => $option) {
                        $output .= '<option value="' . $value . '">' . $option . '</option>' . "\n";
                    }
                    $output .= '</select>' . "\n";
                    $output .= $row_end;
                    print_shortcode($output);
                    break;
            }
        }
    }
}
예제 #2
0
function create_shortcode($popup)
{
    global $shortcode;
    if (isset($shortcode) && is_array($shortcode)) {
        $shortcode_param = $shortcode[$popup]['params'];
        $shortcode_code = $shortcode[$popup]['shortcode'];
        if (isset($shortcode[$popup]['params']['repeatable'])) {
            $shortcode_repeatable = $shortcode[$popup]['params']['repeatable'];
        }
        $shortcode_output = print_shortcode("\n" . '<div id="old-shortcode" class="hidden">' . $shortcode_code . '</div>');
        $shortcode_output = print_shortcode("\n" . '<div id="shortcode-popup" class="hidden">' . $popup . '</div>');
        foreach ($shortcode_param as $key => $param) {
            $key = 'shortcode_' . $key;
            if (empty($param['label'])) {
                $param['label'] = '';
            }
            if (empty($param['desc'])) {
                $param['desc'] = '';
            }
            if (empty($param['type'])) {
                $param['type'] = '';
            }
            $row_start = '<tbody style="display:inline-block;width:100%;">' . "\n";
            $row_start .= '<tr style="height:40px;">' . "\n";
            $row_start .= '<th class="label" style="vertical-align:top;width: 98px;padding-top:10px"><span class="alignleft">' . $param['label'] . '</span></th>' . "\n";
            $row_start .= '<td class="field">' . "\n";
            $row_end = '<span>' . $param['desc'] . '</span>' . "\n";
            $row_end .= '</td>' . "\n";
            $row_end .= '</tr>' . "\n";
            $row_end .= '</tbody>' . "\n";
            switch ($param['type']) {
                case 'text':
                    if (!isset($param['options']['width'])) {
                        $param['options']['width'] = '98px';
                    }
                    $output = $row_start;
                    $output .= '<input type="text" class="popup-input" style="width:' . $param['options']['width'] . '" name="' . $key . '" id="' . $key . '" value="' . $param['std'] . '" />' . "\n";
                    $output .= $row_end;
                    print_shortcode($output);
                    break;
                case 'textarea':
                    if (!isset($param['options']['rows'])) {
                        $param['options']['rows'] = '10';
                    }
                    if (!isset($param['options']['width'])) {
                        $param['options']['width'] = '100%';
                    }
                    $output = $row_start;
                    $output .= '<textarea rows="' . $param['options']['rows'] . '" style="width:' . $param['options']['width'] . '" name="' . $key . '" id="' . $key . '" class="popup-input">' . $param['std'] . '</textarea>' . "\n";
                    $output .= $row_end;
                    print_shortcode($output);
                    break;
                case 'select':
                    $output = $row_start;
                    $output .= '<select name="' . $key . '" id="' . $key . '" class="popup-input">' . "\n";
                    foreach ($param['options'] as $value => $option) {
                        $output .= '<option value="' . $value . '">' . $option . '</option>' . "\n";
                    }
                    $output .= '</select>' . "\n";
                    $output .= $row_end;
                    print_shortcode($output);
                    break;
                case 'colorpicker':
                    $output = $row_start;
                    $output .= '<input id="' . $key . '" name="' . $key . '" type="text"  class="colorpicker popup-input" />' . "\n";
                    ?>
                    <script type="text/javascript">
                        jQuery(document).ready(function(){
                            jQuery( '#<?php 
                    echo $key;
                    ?>
' ).wpColorPicker();
                        })
                    </script>
                    <?php 
                    $output .= $row_end;
                    print_shortcode($output);
                    break;
                case 'repeatable':
                    // set child shortcode
                    $repeatable_param = $shortcode_repeatable['params'];
                    $repeatable_shortcode = $shortcode_repeatable['shortcode'];
                    // popup parent form row start
                    $prow_start = '<tbody>' . "\n";
                    $prow_start .= '<tr class="form-row has-child">' . "\n";
                    $prow_start .= '<td style="width:100%">' . "\n";
                    $prow_start .= '<div class="child-clone-rows">' . "\n";
                    // for js use
                    $prow_start .= '<div id="_tz_cshortcode" class="hidden">' . $repeatable_shortcode . '</div>' . "\n";
                    // start the default row
                    $prow_start .= '<div class="child-clone-row">' . "\n";
                    $prow_start .= '<ul class="child-clone-row-form">' . "\n";
                    // add $prow_start to output
                    print_shortcode($prow_start);
                    foreach ($repeatable_param as $one_row => $repeatable_key) {
                        // popup form row start
                        $crow_start = '<li class="child-clone-row-form-row">' . "\n";
                        $crow_start .= '<div class="child-clone-row-label">' . "\n";
                        $crow_start .= '<label>' . $repeatable_key['label'] . '</label>' . "\n";
                        $crow_start .= '</div>' . "\n";
                        $crow_start .= '<div class="child-clone-row-field">' . "\n";
                        // popup form row end
                        $crow_end = '<span class="child-clone-row-desc">' . $repeatable_key['desc'] . '</span>' . "\n";
                        $crow_end .= '</div>' . "\n";
                        $crow_end .= '</li>' . "\n";
                        switch ($repeatable_key['type']) {
                            case 'text':
                                if (!isset($repeatable_key['options']['width'])) {
                                    $repeatable_key['options']['width'] = '98px';
                                }
                                $output = $crow_start;
                                $output .= '<input type="text" class="repeated-popup-input tz-cinput" style="width:' . $repeatable_key['options']['width'] . '" name="' . $one_row . '" id="' . $one_row . '" value="' . $repeatable_key['std'] . '" />' . "\n";
                                $output .= $crow_end;
                                print_shortcode($output);
                                break;
                            case 'textarea':
                                if (!isset($repeatable_key['options']['rows'])) {
                                    $repeatable_key['options']['rows'] = '10';
                                }
                                if (!isset($repeatable_key['options']['width'])) {
                                    $repeatable_key['options']['width'] = '100%';
                                }
                                $output = $crow_start;
                                $output .= '<textarea rows="' . $repeatable_key['options']['rows'] . '" style="width:' . $repeatable_key['options']['width'] . '" name="' . $one_row . '" id="' . $one_row . '" class="tz-cinput repeated-popup-input">' . $repeatable_key['std'] . '</textarea>' . "\n";
                                $output .= $crow_end;
                                print_shortcode($output);
                                break;
                            case 'select':
                                $output = $crow_start;
                                $output .= '<select name="' . $one_row . '" id="' . $one_row . '" class="repeated-popup-input tz-cinput">' . "\n";
                                foreach ($repeatable_key['options'] as $value => $option) {
                                    $output .= '<option value="' . $value . '">' . $option . '</option>' . "\n";
                                }
                                $output .= '</select>' . "\n";
                                $output .= $crow_end;
                                print_shortcode($output);
                                break;
                        }
                    }
                    // popup parent form row end
                    $prow_end = '</ul>' . "\n";
                    // end .child-clone-row-form
                    $prow_end .= '<a href="#" class="child-clone-row-remove">Remove</a>' . "\n";
                    $prow_end .= '</div>' . "\n";
                    // end .child-clone-row
                    $prow_end .= '</div>' . "\n";
                    // end .child-clone-rows
                    $prow_end .= '</td>' . "\n";
                    $prow_end .= '</tr>' . "\n";
                    $prow_end .= '</tbody>' . "\n";
                    // add $prow_end to output
                    print_shortcode($prow_end);
                    break;
            }
        }
        // end foreach param
    }
}