Пример #1
0
<?php

// Exit if accessed directly
if (!defined('ABSPATH')) {
    exit;
}
global $woo_vou_model, $post;
$model = $woo_vou_model;
$prefix = WOO_VOU_META_PREFIX;
$bg_style = woo_vou_meta_value(array('id' => $prefix . 'pdf_bg_style', 'type' => 'radio'));
$pdf_view = woo_vou_meta_value(array('id' => $prefix . 'pdf_view', 'type' => 'select'));
$bg_pattern_css = $bg_image_css = $pdf_size_css = 'woo-vou-meta-display-none';
if ($bg_style == 'color') {
    //Check background style is color
} else {
    if ($bg_style == 'image') {
        //Check background style is image
        $bg_image_css = '';
    } else {
        //Check background style is pattern
        $bg_pattern_css = '';
    }
}
//if( $pdf_view == 'port' ) {
$pdf_size_css = '';
//}
//Get pdf sizes
$pdf_sizes = woo_vou_get_pdf_sizes_select();
wp_nonce_field(WOO_VOU_PLUGIN_BASENAME, 'at_woo_vou_meta_box_nonce');
woo_vou_content_begin();
// voucher background image option
 /**
  * Add Repeater Block
  *
  * Handles to add repeater block
  *
  * @package WooCommerce - PDF Vouchers
  * @since   1.0.0
  */
 function woo_vou_add_repeater_block($args, $echo = true)
 {
     global $post, $woo_vou_model;
     $new_field = array('type' => 'repeater', 'id' => $args['id'], 'name' => 'Reapeater Field', 'fields' => array());
     $field = array_merge($new_field, $args);
     $meta = woo_vou_meta_value($field);
     $html = '';
     $html .= '<p class="form-field ' . $field['id'] . '_field woo_vou_repeater"><label style="display:block;" for="' . $field['id'] . '">' . $field['label'] . '</label>';
     $html .= "<div class='woo-vou-meta-repeat' id='{$field['id']}'>";
     if (!empty($meta) && count($meta) > 0) {
         $row = '';
         for ($i = 0; $i < count($meta); $i++) {
             $row .= "\t<div class='woo-vou-meta-repater-block'>\n\t\t\t\t\t\t\t\t<table class='repeater-table form-table'>\n\t\t\t\t\t\t\t\t\t<tbody>";
             for ($k = 0; $k < count($field['fields']); $k++) {
                 $row .= '<p class="form-field ' . $field['fields'][$k]['id'] . '_field"><label style="display:block;" for="' . $field['fields'][$k]['id'] . '">' . $field['fields'][$k]['label'] . '</label>';
                 $row .= "<input type='text' name='{$field['fields'][$k]['id']}[]' class='woo-vou-meta-text regular-text woo-vou-repeater-text' value='{$woo_vou_model->woo_vou_escape_attr($meta[$i][$field['fields'][$k]['id']])}'/>";
                 if (!empty($field['fields'][$k]['description'])) {
                     $row .= '<span class="description">' . wp_kses_post($field['fields'][$k]['description']) . '</span>';
                 }
                 $row .= '</p>';
             }
             $row .= "\t\t\t</tbody>\n\t\t\t\t\t\t\t\t</table>";
             if ($i > 0) {
                 $showremove = "style='display:block;'";
             } else {
                 $showremove = "style='display:none;'";
             }
             $row .= "\t<img id='remove-{$args['id']}' class='woo-vou-repeater-remove' {$showremove} title='" . __('Remove', 'woovoucher') . "' alt='" . __('Remove', 'woovoucher') . "' src='" . WOO_VOU_META_URL . "/images/remove.png'>";
             $row .= "\t\t</div><!--.woo-vou-meta-repater-block-->";
         }
         $html .= $row;
     } else {
         $row = '';
         $row .= "\t<div class='woo-vou-meta-repater-block'>\n\t\t\t\t\t\t\t\t<table class='repeater-table form-table'>\n\t\t\t\t\t\t\t\t\t<tbody>";
         for ($i = 0; $i < count($field['fields']); $i++) {
             $row .= '<p class="form-field ' . $field['fields'][$i]['id'] . '_field"><label style="display:block;" for="' . $field['fields'][$i]['id'] . '">' . $field['fields'][$i]['label'] . '</label>';
             $row .= "\t<input type='text' name='{$field['fields'][$i]['id']}[]' class='woo-vou-meta-text regular-text woo-vou-repeater-text'/>";
             if (!empty($field['fields'][$i]['description'])) {
                 $row .= '<span class="description">' . wp_kses_post($field['fields'][$i]['description']) . '</span>';
             }
             $row .= '</p>';
         }
         $row .= "\t\t</tbody>\n\t\t\t\t\t\t\t</table>";
         $row .= "\t<img id='remove-{$args['id']}' class='woo-vou-repeater-remove' style='display:none;' title='" . __('Remove', 'woovoucher') . "' alt='" . __('Remove', 'woovoucher') . "' src='" . WOO_VOU_META_URL . "/images/remove.png'>";
         $row .= "\t\t</div><!--.woo-vou-meta-repater-block-->";
         $html .= $row;
     }
     $html .= "\t<img id='add-{$args['id']}' class='woo-vou-repeater-add' title='" . __('Add', 'woovoucher') . "' alt='" . __('Add', 'woovoucher') . "' src='" . WOO_VOU_META_URL . "/images/add.png'>";
     $html .= "\t</div><!--.woo-vou-meta-repeat-->";
     if (isset($field['description']) && $field['description']) {
         $html .= '<span class="description">' . $field['description'] . '</span>';
     }
     $html .= '</p>';
     if ($echo) {
         echo $html;
     } else {
         return $html;
     }
 }
/**
 * Show Background Pattern Field
 *
 * @param string $field 
 * @param string $meta 
 * @since 1.0
 * @access public
 */
function woo_vou_add_bg_pattern($args, $echo = true)
{
    $html = '';
    $new_field = array('type' => 'text', 'name' => 'Background Pattern Field');
    $field = array_merge($new_field, $args);
    $all_background_patterns = isset($field['options']) ? $field['options'] : array();
    $default_meta = isset($field['default']) ? $field['default'] : '';
    $meta = woo_vou_meta_value($field);
    $meta = !empty($meta) ? $meta : $default_meta;
    $html .= woo_vou_show_field_begin($field);
    if (!empty($all_background_patterns)) {
        // Check pattern options are not empty
        foreach ($all_background_patterns as $pattern) {
            $background_pattern_css = $meta == $pattern ? 'woo-vou-meta-bg-pattern-selected' : '';
            $html .= '<img class="woo-vou-meta-bg-patterns ' . $background_pattern_css . '" id="woo_vou_meta_img_' . $pattern . '" src="' . WOO_VOU_IMG_URL . '/patterns/' . $pattern . '.png' . '" data-pattern="' . $pattern . '" alt="' . ucwords($pattern) . '" title="' . ucwords($pattern) . '" />';
        }
    }
    $html .= '<input class="woo-vou-meta-bg-patterns-opt" type="hidden" id="' . $field['id'] . '" name="' . $field['id'] . '" value="' . $meta . '" />';
    $html .= woo_vou_show_field_end($field);
    if ($echo) {
        echo $html;
    } else {
        return $html;
    }
}