Example #1
0
function pp_pb_widget_styles_dialog_form()
{
    $fields = pp_pb_widget_styling_fields();
    foreach ($fields as $key => $field) {
        echo "<div class='field'>";
        echo "<label>" . esc_html($field['name']) . "</label>";
        echo "<span>";
        switch ($field['type']) {
            case 'color':
                ?>
<input dialog-field="<?php 
                echo $key;
                ?>
" class="widget-<?php 
                echo $key;
                ?>
" type="text" data-style-field-type="color"/>
				<?php 
                break;
            case 'border':
                ?>
<input dialog-field="<?php 
                echo $key;
                ?>
-width" class="widget-<?php 
                echo $key;
                ?>
-width" type="number" min="0" max="100" step="1" value="" /> px
				  <input dialog-field="<?php 
                echo $key;
                ?>
-color" class="widget-<?php 
                echo $key;
                ?>
-color" type="text" data-style-field-type="color" />
				<?php 
                break;
            case 'number':
                ?>
<input dialog-field="<?php 
                echo $key;
                ?>
" class="widget-<?php 
                echo $key;
                ?>
" type="number" min="<?php 
                esc_attr_e($field['min']);
                ?>
" max="<?php 
                esc_attr_e($field['max']);
                ?>
" step="<?php 
                esc_attr_e($field['step']);
                ?>
" value="" /> <?php 
                esc_html_e($field['unit']);
                ?>
				<?php 
                break;
            case 'checkbox':
                ?>
<input dialog-field="<?php 
                echo $key;
                ?>
" class="widget-<?php 
                echo $key;
                ?>
" type="checkbox" value="<?php 
                esc_attr_e($field['value']);
                ?>
" data-style-field-type="checkbox" />
				<?php 
            default:
                break;
        }
        echo "</span>";
        echo '</div>';
    }
}
/**
 * Render the widget.
 *
 * @param string $widget The widget class name.
 * @param array $instance The widget instance
 * @param int $grid The grid number.
 * @param int $cell The cell number.
 * @param int $panel the panel number.
 * @param bool $is_first Is this the first widget in the cell.
 * @param bool $is_last Is this the last widget in the cell.
 * @param bool $post_id
 */
function siteorigin_panels_the_widget($widget, $instance, $widgetStyle, $grid, $cell, $panel, $is_first, $is_last, $post_id = false)
{
    if (!class_exists($widget)) {
        return;
    }
    if (empty($post_id)) {
        $post_id = get_the_ID();
    }
    $panelData = get_post_meta($post_id, 'panels_data', true);
    if (!is_array($panelData)) {
        $panelData = array();
    }
    $the_widget = new $widget();
    $classes = array('panel', 'widget');
    if (!empty($the_widget->id_base)) {
        $classes[] = 'widget_' . $the_widget->id_base . ' ' . $the_widget->id_base;
    }
    if ($is_first) {
        $classes[] = 'panel-first-child';
    }
    if ($is_last) {
        $classes[] = 'panel-last-child';
    }
    $id = 'panel-' . $post_id . '-' . $grid . '-' . $cell . '-' . $panel;
    $styleArray = $widgetStyle;
    $inlineStyle = '';
    $widgetStyleFields = pp_pb_widget_styling_fields();
    $styleWithSelector = '';
    foreach ($widgetStyleFields as $key => $field) {
        if ($field['type'] == 'border') {
            // a border field has 2 settings
            $key1 = $key . '-width';
            $key2 = $key . '-color';
            if (isset($styleArray[$key1]) && $styleArray[$key1] != '') {
                if (!is_array($field['css'])) {
                    $cssArr = array($field['css']);
                } else {
                    $cssArr = $field['css'];
                }
                foreach ($cssArr as $cssProperty) {
                    $inlineStyle .= $cssProperty . '-width: ' . $styleArray[$key1] . 'px; border-style: solid;';
                }
            }
            if (isset($styleArray[$key2]) && $styleArray[$key2] != '') {
                if (!is_array($field['css'])) {
                    $cssArr = array($field['css']);
                } else {
                    $cssArr = $field['css'];
                }
                foreach ($cssArr as $cssProperty) {
                    $inlineStyle .= $cssProperty . '-color: ' . $styleArray[$key2] . ';';
                }
            }
        } else {
            if (isset($styleArray[$key]) && $styleArray[$key] != '') {
                if (!is_array($field['css'])) {
                    $cssArr = array($field['css']);
                } else {
                    $cssArr = $field['css'];
                }
                foreach ($cssArr as $cssProperty) {
                    if (isset($field['unit'])) {
                        $unit = $field['unit'];
                    } else {
                        $unit = '';
                    }
                    if (!isset($field['selector'])) {
                        $inlineStyle .= $cssProperty . ': ' . $styleArray[$key] . $unit . ';';
                    } else {
                        $styleWithSelector .= '#' . $id . ' > ' . $field['selector'] . ' { ' . $cssProperty . ': ' . $styleArray[$key] . $unit . '; }';
                    }
                }
            }
        }
    }
    $the_widget->widget(array('before_widget' => '<div class="' . esc_attr(implode(' ', $classes)) . '" id="' . $id . '" style="' . $inlineStyle . '" >', 'after_widget' => '</div>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>', 'widget_id' => 'widget-' . $grid . '-' . $cell . '-' . $panel), $instance);
    if ($styleWithSelector != '') {
        echo "<style>\n";
        echo str_replace('display', 'display:none;display', $styleWithSelector);
        echo "</style>\n";
    }
    // Add js file for WooTabs widget
    if ($widget == 'Woo_Widget_WooTabs') {
        if (function_exists('woo_widget_tabs_js')) {
            add_action('wp_footer', 'woo_widget_tabs_js');
        }
    }
}