Пример #1
0
function bfa_widget_area($args = '')
{
    global $bfa_ata;
    $defaults = array('name' => '', 'cells' => 1, 'align' => 2, 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<div class="widget-title"><h3>', 'after_title' => '</h3></div>');
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    $area_id = strtolower(str_replace(" ", "_", $r['name']));
    # $bfa_widget_areas = get_option('bfa_widget_areas');
    $bfa_widget_areas = $bfa_ata['bfa_widget_areas'];
    // If there are more than 1 cell, use a table, otherwise just a DIV:
    if ($r['cells'] > 1) {
        echo '<table id="' . $area_id . '" class="bfa_widget_area" style="table-layout:fixed;width:100%" cellpadding="0" cellspacing="0" border="0">';
        // If a width was set for any of the widget area cells:
        # if ( strpos($args,'width_') !== FALSE ) {
        // Since 3.6.7
        $colgroup = 'no';
        // If all table cells have the same width, this can be achieved by table-layout:fixed alone, without the colgroup element.
        // Check if any of the cells have a set width
        for ($i = 1; $i <= $r['cells']; $i++) {
            if (array_key_exists('width_' . $i, $r) and !empty($r['width_' . $i])) {
                $colgroup = 'yes';
            }
        }
        if ($colgroup == 'yes') {
            echo "\n<colgroup>";
            for ($i = 1; $i <= $r['cells']; $i++) {
                echo '<col';
                $current_width = "width_" . $i;
                if (isset($r[$current_width])) {
                    if (!preg_match('/(%|px|pX|Px|PX)/', $r[$current_width])) {
                        $r[$current_width] = $r[$current_width] . 'px';
                    }
                    echo ' style="width:' . $r[$current_width] . '"';
                }
                echo ' />';
            }
            echo "</colgroup>";
        }
        echo "<tr>";
        for ($i = 1; $i <= $r['cells']; $i++) {
            $current_name = $r['name'] . ' ' . $i;
            $current_id = $area_id . '_' . $i;
            $current_align = "align_" . $i;
            echo "\n" . '<td id="' . $current_id . '" ';
            if (isset($r[$current_align])) {
                $align_type = $r["{$current_align}"];
            } else {
                $align_type = $r['align'];
            }
            echo bfa_table_cell_align($align_type) . ">";
            // Register widget area
            $this_widget_area = array("name" => $current_name, "before_widget" => $r['before_widget'], "after_widget" => $r['after_widget'], "before_title" => $r['before_title'], "after_title" => $r['after_title']);
            // Display widget area
            dynamic_sidebar("{$current_name}");
            echo "\n</td>";
            $bfa_widget_areas[$current_name] = $this_widget_area;
        }
        echo "\n</tr></table>";
    } else {
        // If only 1 widget cell, use a DIV instead of a table
        echo '<div id="' . $area_id . '" class="bfa_widget_area">';
        // Add new widget area to existing ones
        $this_widget_area = array("name" => $r['name'], "before_widget" => $r['before_widget'], "after_widget" => $r['after_widget'], "before_title" => $r['before_title'], "after_title" => $r['after_title']);
        // Display widget area
        dynamic_sidebar($r['name']);
        echo '</div>';
        $current_name = $r['name'];
        $bfa_widget_areas[$current_name] = $this_widget_area;
    }
    # update_option("bfa_widget_areas", $bfa_widget_areas);
    $bfa_ata['bfa_widget_areas'] = $bfa_widget_areas;
    update_option('bfa_ata4', $bfa_ata);
}
Пример #2
0
function bfa_widget_area($args = '')
{
    $defaults = array('cells' => 1, 'align' => 2, 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<div class="widget-title"><h3>', 'after_title' => '</h3></div>');
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    $area_id = strtolower(str_replace(" ", "_", $r['name']));
    $bfa_widget_areas = get_option('bfa_widget_areas');
    // If there are more than 1 cell, use a table, otherwise just a DIV:
    if ($r['cells'] > 1) {
        echo '<table id="' . $area_id . '" class="bfa_widget_area" style="table-layout:fixed;width:100%" cellpadding="0" cellspacing="0" border="0">';
        // If a width was set for any of the widget area cells:
        if (strpos($args, 'width_') !== FALSE) {
            echo "\n<colgroup>";
            for ($i = 1; $i <= $r['cells']; $i++) {
                echo '<col';
                $current_width = "width_" . $i;
                if ($r[$current_width]) {
                    echo ' style="width:' . $r[$current_width] . 'px"';
                }
                echo ' />';
            }
            echo "</colgroup>";
        }
        echo "<tr>";
        for ($i = 1; $i <= $r['cells']; $i++) {
            $current_name = $r['name'] . ' ' . $i;
            $current_id = $area_id . '_' . $i;
            $current_align = "align_" . $i;
            echo "\n" . '<td id="' . $current_id . '" ';
            if ($r[$current_align]) {
                $align_type = $r["{$current_align}"];
            } else {
                $align_type = $r['align'];
            }
            echo bfa_table_cell_align($align_type) . ">";
            // Register widget area
            $this_widget_area = array("name" => $current_name, "before_widget" => $r['before_widget'], "after_widget" => $r['after_widget'], "before_title" => $r['before_title'], "after_title" => $r['after_title']);
            // Display widget area
            dynamic_sidebar("{$current_name}");
            echo "\n</td>";
            $bfa_widget_areas[$current_name] = $this_widget_area;
        }
        echo "\n</tr></table>";
    } else {
        // If only 1 widget cell, use a DIV instead of a table
        echo '<div id="' . $area_id . '" class="bfa_widget_area">';
        // Add new widget area to existing ones
        $this_widget_area = array("name" => $r['name'], "before_widget" => $r['before_widget'], "after_widget" => $r['after_widget'], "before_title" => $r['before_title'], "after_title" => $r['after_title']);
        // Display widget area
        dynamic_sidebar($r['name']);
        echo '</div>';
        $current_name = $r['name'];
        $bfa_widget_areas[$current_name] = $this_widget_area;
    }
    update_option("bfa_widget_areas", $bfa_widget_areas);
}