public function get_date_query_form($data = array())
    {
        $data = wp_parse_args($data, array('column' => '', 'key' => '', 'compare' => '', 'value' => ''));
        extract($data);
        return '<tr class="wff_clone_item">' . '<td class="column">' . w4pl_form_child_field_html(array('name' => 'w4pl[date_query][column][]', 'type' => 'select', 'option' => array('post_date' => 'post_date', 'post_date_gmt' => 'post_date_gmt', 'post_modified' => 'post_modified', 'post_modified_gmt' => 'post_modified_gmt', 'comment_date' => 'comment_date', 'comment_date_gmt' => 'comment_date_gmt', 'user_registered' => 'user_registered'), 'value' => $column)) . '</td>' . '<td class="key">' . w4pl_form_child_field_html(array('name' => 'w4pl[date_query][key][]', 'type' => 'select', 'option' => array('after' => 'after', 'before' => 'before', 'year' => 'year', 'month' => 'month', 'monthnum' => 'monthnum', 'week' => 'week', 'w' => 'w', 'dayofyear' => 'dayofyear', 'dayofweek' => 'dayofweek', 'dayofweek_iso' => 'dayofweek_iso', 'hour' => 'hour', 'minute' => 'minute', 'second' => 'second'), 'value' => $key)) . '</td>' . '<td class="compare">' . w4pl_form_child_field_html(array('name' => 'w4pl[date_query][compare][]', 'input_class' => 'w4pl_field_compare', 'type' => 'select', 'option' => self::date_query_compare_options(), 'value' => $compare)) . '</td>' . '<td class="value">' . w4pl_form_child_field_html(array('name' => 'w4pl[date_query][value][]', 'input_class' => 'w4pl_field_value', 'type' => 'text', 'value' => $value)) . '</td>' . '<td class="w4pl_date_query_action_cell">
				<span class="wff_clone_remove_btn button">' . __('Remove', 'w4pl') . '</span>
			</td>' . '
		</tr>';
    }
    public function admin_list_fields($fields, $post_data)
    {
        $list_type = $post_data['list_type'];
        if (!in_array($list_type, array('posts'))) {
            return $fields;
        }
        $post_type = $post_data['post_type'];
        $taxonomies = self::post_type_taxonomies_options($post_type);
        if (empty($taxonomies)) {
            return $fields;
        }
        $html = '<div id="w4pl_field_group_tax_query" class="w4pl_field_group"><div class="w4pl_group_title">Posts: Tax Query</div><div class="w4pl_group_fields">';
        $tax_query_relation = isset($post_data['tax_query']['relation']) && !empty($post_data['tax_query']['relation']) ? $post_data['tax_query']['relation'] : 'OR';
        $html .= '<div class="wffw">';
        $html .= '<table id="w4pl_tax_query_table" class="widefat">
			<thead>
				<tr>
					<th id="w4pl_tax_query_taxonomy_cell_head">Taxonomy</th>
					<th id="w4pl_tax_query_operator_cell_head">Operator</th>
					<th id="w4pl_tax_query_field_cell_head">Field</th>
					<th id="w4pl_tax_query_terms_cell_head">Terms</th>
					<th id="w4pl_tax_query_action_cell_head">Action</th>
				</tr>
			</thead>
		<tbody>';
        if (isset($post_data['tax_query']) && !empty($post_data['tax_query'])) {
            $index = 0;
            foreach ($post_data['tax_query']['taxonomy'] as $i => $taxonomy) {
                $field = isset($post_data['tax_query']['field'][$i]) ? $post_data['tax_query']['field'][$i] : '';
                $operator = isset($post_data['tax_query']['operator'][$i]) ? $post_data['tax_query']['operator'][$i] : '';
                $terms = isset($post_data['tax_query']['terms'][$i]) ? $post_data['tax_query']['terms'][$i] : '';
                if (empty($terms) || empty($operator)) {
                    continue;
                }
                $html .= '
				<tr><td class="w4pl_tax_query_taxonomy_cell">
					' . w4pl_form_child_field_html(array('id' => 'w4pl_tax_query_taxonomy_' . $index, 'name' => 'w4pl[tax_query][taxonomy][' . $index . ']', 'input_class' => 'w4pl_tax_query_taxonomy', 'type' => 'select', 'option' => self::post_type_taxonomies_options($post_type), 'value' => $taxonomy)) . '</td><td class="w4pl_tax_query_operator_cell">' . w4pl_form_child_field_html(array('id' => 'w4pl_tax_query_operator_' . $index, 'name' => 'w4pl[tax_query][operator][' . $index . ']', 'input_class' => 'w4pl_tax_query_operator', 'type' => 'select', 'option' => self::tax_query_operator_options(), 'value' => $operator)) . '</td><td class="w4pl_tax_query_field_cell">' . w4pl_form_child_field_html(array('id' => 'w4pl_tax_query_field_' . $index, 'name' => 'w4pl[tax_query][field][' . $index . ']', 'input_class' => 'w4pl_tax_query_field', 'type' => 'select', 'option' => self::tax_query_field_options(), 'value' => $field)) . '</td><td class="w4pl_tax_query_terms_cell terms" data-pos="' . $index . '">';
                if (!is_array($terms)) {
                    $terms = array($terms);
                }
                $btn_class = '';
                if (in_array($operator, array('IN', 'NOT IN'))) {
                    $btn_class = 'csshide';
                }
                $cindex = 0;
                foreach ($terms as $val) {
                    $html .= '
					<div class="item">
						<input type="text" value="' . esc_attr($val) . '" name="w4pl[tax_query][terms][' . $index . '][]" class="wff wffi_w4pl_tax_query_terms_' . $index . ' wfft_text ">
						<a class="w4pl_tax_query_value_add button" href="#">+</a> 
						<a class="w4pl_tax_query_value_del button" href="#">-</a>
					</div>';
                    ++$cindex;
                }
                $html .= '</td><td class="w4pl_tax_query_action_cell"><a class="w4pl_tax_query_remove_btn" href="#" class="button">Remove</a></td>
				</tr>';
                ++$index;
            }
        }
        $html .= '</tbody>
			</table>';
        $html .= '
		<div id="w4pl_tax_query_value_clone" style="display:none;">
			<div class="item">
				<input type="text" class="wff wfft_text wffi_w4pl_tax_query_value">
				<a class="w4pl_tax_query_value_add button" href="#">+</a> 
				<a class="w4pl_tax_query_value_del button" href="#">-</a>
			</div>
		</div>';
        $html .= '
		<p style="text-align:right;"><a id="w4pl_tax_query_add_btn" href="#" class="button">+ Add</a></p>
		<table id="w4pl_tax_query_clone" style="display:none;">
		<tr><td class="w4pl_tax_query_taxonomy_cell">' . w4pl_form_child_field_html(array('name' => 'w4pl[tax_query][taxonomy][]', 'input_class' => 'w4pl_tax_query_taxonomy', 'type' => 'select', 'option' => self::post_type_taxonomies_options($post_type))) . '</td><td class="w4pl_tax_query_operator_cell">' . w4pl_form_child_field_html(array('name' => 'w4pl[tax_query][operator][]', 'input_class' => 'w4pl_tax_query_operator', 'type' => 'select', 'option' => self::tax_query_operator_options())) . '</td><td class="w4pl_tax_query_field_cell">' . w4pl_form_child_field_html(array('name' => 'w4pl[tax_query][field][]', 'input_class' => 'w4pl_tax_query_field', 'type' => 'select', 'option' => self::tax_query_field_options())) . '</td><td class="w4pl_tax_query_terms_cell terms">' . '<div class="item">
				<input type="text" class="wff wfft_text wffi_w4pl_tax_query_terms">
				<a class="w4pl_tax_query_value_add button" href="#">+</a> 
				<a class="w4pl_tax_query_value_del button" href="#">-</a>
			</div>' . '</td><td class="w4pl_tax_query_action_cell terms"><a class="w4pl_tax_query_remove_btn" href="#" class="button">Remove</a></td>' . '
		</tr></table>';
        $html .= w4pl_form_field_html(array('field_wrap' => false, 'name' => 'w4pl[tax_query][relation]', 'label' => 'Relation', 'type' => 'radio', 'option' => array('OR' => 'OR', 'AND' => 'AND'), 'value' => $tax_query_relation));
        $html .= '</div><!--.wffw-->';
        $html .= '</div><!--.w4pl_group_fields--></div><!--#w4pl_field_group_tax_query-->';
        $fields['tax_query'] = array('position' => '110', 'type' => 'html', 'html' => $html);
        /* ========================================= */
        return $fields;
    }
Exemple #3
0
    public static function list_options_template($options)
    {
        $options = apply_filters('w4pl/pre_get_options', $options);
        $fields = array();
        // this wrap the whole fields are
        $fields['before_list_options'] = array('position' => '0', 'html' => '<div id="w4pl_list_options">');
        $fields['id'] = array('position' => '1.1', 'option_name' => 'id', 'name' => 'w4pl[id]', 'type' => 'hidden');
        $fields['tab_id'] = array('position' => '1.2', 'option_name' => 'tab_id', 'name' => 'w4pl[tab_id]', 'type' => 'hidden');
        /* Field Group - List Type */
        $fields['before_field_group_type'] = array('position' => '2', 'html' => '<div id="w4pl_field_group_type" class="w4pl_field_group">
								<div class="w4pl_group_title">' . __('List Type', 'w4pl') . '</div>
								<div class="w4pl_group_fields">');
        $fields['list_type'] = array('position' => '3', 'option_name' => 'list_type', 'name' => 'w4pl[list_type]', 'label' => __('List Type', 'w4pl'), 'type' => 'radio', 'option' => self::list_type_options(), 'input_class' => 'w4pl_onchange_lfr');
        $fields['after_field_group_type'] = array('position' => '4', 'html' => '</div><!--.w4pl_group_fields--></div><!--#w4pl_field_group_type-->');
        /* Field Group - Template */
        $fields['before_field_group_template'] = array('position' => '150', 'html' => '<div id="w4pl_field_group_template" class="w4pl_field_group">
				<div class="w4pl_group_title">' . __('Template', 'w4pl') . '</div>
				<div class="w4pl_group_fields">');
        $template_html = '
		<div class="wffw wffwi_w4pl_template wffwt_textarea">
			<p style="margin-top:0px;">
				<a href="#" class="button w4pl_toggler" data-target="#w4pl_template_examples">' . __('Template Example', 'w4pl') . '</a>
				<a href="#" class="button w4pl_toggler" data-target="#w4pl_template_buttons">' . __('Shortcodes', 'w4pl') . '</a>
			</p>
			<div id="w4pl_template_examples" class="csshide">' . "<pre style='width:auto'>\n[groups]\n\t[group_title]\n\t[posts]\n\t\t[post_title]\n\t[/posts]\n[/groups]\n[nav]</pre>" . "<br />without group, a simple template should be like -" . "<pre style='width:auto'>[posts]\n\t[post_title]\n[/posts]\n[nav]</pre>" . '</div>';
        $shortcodes = apply_filters('w4pl/get_shortcodes', array());
        $shortcode_groups = array();
        foreach ($shortcodes as $shortcode => $attr) {
            $group = $attr['group'];
            if (!isset($shortcode_groups[$group]) || !is_array($shortcode_groups[$group])) {
                $shortcode_groups[$group] = array();
            }
            $shortcode_groups[$group][] = $shortcode;
        }
        $template_html .= '<div id="w4pl_template_buttons" class="csshide">';
        foreach ($shortcode_groups as $shortcode_group => $scodes) {
            $template_html .= sprintf(' <div class="w4pl_button_group"><span class="w4pl_button_group_title">%1$s</span>', $shortcode_group);
            foreach ($scodes as $shortcode) {
                $attr = $shortcodes[$shortcode];
                if (isset($attr['code'])) {
                    $code = $attr['code'];
                } else {
                    $code = '[' . $shortcode . ']';
                }
                $template_html .= sprintf(' <a href="#%1$s" data-code="%2$s">%1$s</a>', $shortcode, esc_attr($code));
            }
            $template_html .= '</div>';
        }
        $template_html .= '</div>';
        /*
        $template_html .= '
        <div class="wfflw wfflwi_w4pl_template wfflwt_textarea">
        	<label for="w4pl_template" class="wffl wffli_w4pl_template wfflt_textarea">Template</label>
        </div>';
        */
        $template_html .= w4pl_form_child_field_html(array('id' => 'w4pl_template', 'name' => 'w4pl[template]', 'input_class' => 'wff wffi_w4pl_template wfft_textarea widefat', 'type' => 'textarea', 'default' => apply_filters('w4pl/template_default', ''), 'value' => isset($options['template']) ? $options['template'] : ''));
        $template_html .= '</div>';
        $fields['template1'] = array('position' => '155', 'html' => $template_html);
        $fields['after_field_group_template'] = array('position' => '160', 'html' => '</div><!--.w4pl_group_fields--></div><!--#w4pl_field_group_template-->');
        $fields['after_list_options'] = array('position' => '999', 'type' => 'html', 'html' => '</div><!--after_list_options-->');
        # echo '<pre>'; print_r($fields); echo '</pre>';
        $form_args = array('no_form' => true, 'button_after' => false);
        // let helper class extend/modify this class
        $fields = apply_filters('w4pl/admin_list_fields', $fields, $options);
        // order by position
        uasort($fields, array(get_class(), 'order_by_position'));
        # echo '<pre>'; print_r($fields); echo '</pre>';
        $output = w4pl_form_fields($fields, $options, $form_args);
        // filter the output
        $output = apply_filters('w4pl/list_options_template_html', $output, $fields, $options);
        echo $output;
    }
    public function admin_list_fields($fields, $post_data)
    {
        $list_type = $post_data['list_type'];
        if (!in_array($list_type, array('posts', 'terms.posts'))) {
            return $fields;
        }
        /* Meta Query */
        $html = '<div id="w4pl_field_group_meta_query" class="w4pl_field_group">
			<div class="w4pl_group_title">' . __('Posts: Meta Query', W4PL_TD) . '</div>
			<div class="w4pl_group_fields">';
        $meta_query_relation = isset($post_data['meta_query']['relation']) && !empty($post_data['meta_query']['relation']) ? $post_data['meta_query']['relation'] : 'OR';
        $html .= '<div class="wffw">';
        $html .= '<table id="w4pl_meta_query_table" class="widefat">
			<thead>
				<tr>
					<th id="w4pl_meta_query_key_cell_head">' . __('Key', W4PL_TD) . '</th>
					<th id="w4pl_meta_query_compare_cell_head">' . __('Compare', W4PL_TD) . '</th>
					<th id="w4pl_meta_query_value_cell_head">' . __('Value', W4PL_TD) . '</th>
					<th id="w4pl_meta_query_action_cell_head">' . __('Action', W4PL_TD) . '</th>
				</tr>
			</thead>
			<tbody>';
        if (isset($post_data['meta_query']) && isset($post_data['meta_query']['key']) && is_array($post_data['meta_query']['key']) && !empty($post_data['meta_query']['key'])) {
            $index = 0;
            foreach ($post_data['meta_query']['key'] as $i => $key) {
                $compare = isset($post_data['meta_query']['compare'][$i]) ? $post_data['meta_query']['compare'][$i] : '';
                $value = isset($post_data['meta_query']['value'][$i]) ? $post_data['meta_query']['value'][$i] : '';
                if (empty($key) || empty($compare)) {
                    continue;
                }
                $html .= '
				<tr><td class="w4pl_meta_query_key_cell">
					' . w4pl_form_child_field_html(array('id' => 'w4pl_meta_query_key_' . $index, 'name' => 'w4pl[meta_query][key][' . $index . ']', 'input_class' => 'w4pl_meta_query_key', 'type' => 'text', 'value' => $key)) . '</td><td class="w4pl_meta_query_compare_cell">' . w4pl_form_child_field_html(array('id' => 'w4pl_meta_query_compare_' . $index, 'name' => 'w4pl[meta_query][compare][' . $index . ']', 'input_class' => 'w4pl_meta_query_compare', 'type' => 'select', 'option' => self::meta_query_compare_options(), 'value' => $compare)) . '</td><td class="w4pl_meta_query_value_cell values" data-pos="' . $index . '">';
                if (!is_array($value)) {
                    $value = array($value);
                }
                $cindex = 0;
                foreach ($value as $val) {
                    $html .= '
					<div class="item">
						<input type="text" value="' . esc_attr($val) . '" name="w4pl[meta_query][value][' . $index . '][]" class="wff wffi_w4pl_meta_query_value_' . $index . ' wfft_text ">
						<a class="w4pl_meta_query_value_add button" href="#">+</a> 
						<a class="w4pl_meta_query_value_del button" href="#">-</a>
					</div>';
                    ++$cindex;
                }
                $html .= '</td><td class="w4pl_meta_query_action_cell"><a class="w4pl_meta_query_remove_btn" href="#" class="button">' . __('Remove', W4PL_TD) . '</a></td>
				</tr>';
                ++$index;
            }
        }
        $html .= '</tbody>
			</table>';
        $html .= '
		<div id="w4pl_meta_query_value_clone" style="display:none;">
			<div class="item">
				<input type="text" class="wff wfft_text wffi_w4pl_meta_query_value">
				<a class="w4pl_meta_query_value_add button" href="#">+</a> 
				<a class="w4pl_meta_query_value_del button" href="#">-</a>
			</div>
		</div>';
        $html .= '
		<p style="text-align:right;"><a id="w4pl_meta_query_add_btn" href="#" class="button">' . __('+ Add', W4PL_TD) . '</a></p>
		<table id="w4pl_meta_query_clone" style="display:none;">
		<tr><td class="w4pl_meta_query_key_cell">
			<input type="text" class="wff wffi_w4pl_meta_query_key wfft_text">
			</td><td class="w4pl_meta_query_compare_cell">' . w4pl_form_child_field_html(array('name' => 'w4pl[meta_query][compare][]', 'input_class' => 'w4pl_meta_query_compare', 'type' => 'select', 'option' => self::meta_query_compare_options())) . '</td><td class="w4pl_meta_query_value_cell values">' . '<div class="item">
				<input type="text" class="wff wfft_text wffi_w4pl_meta_query_value">
				<a class="w4pl_meta_query_value_add button" href="#">+</a> 
				<a class="w4pl_meta_query_value_del button" href="#">-</a>
			</div>' . '</td><td class="w4pl_meta_query_action_cell"><a class="w4pl_meta_query_remove_btn" href="#" class="button">' . __('Remove', W4PL_TD) . '</a></td>' . '
		</tr></table>';
        $html .= w4pl_form_field_html(array('field_wrap' => false, 'name' => 'w4pl[meta_query][relation]', 'label' => __('Relation', W4PL_TD), 'type' => 'radio', 'option' => array('OR' => __('OR', W4PL_TD), 'AND' => __('AND', W4PL_TD)), 'value' => $meta_query_relation));
        $html .= '<p class="wffdw2">';
        $html .= '<br />For the value field, you can also use following shortcodes to apply dynamic value:';
        $html .= '<br /><code>[w4pl_date day=+6 hour=-1 format="Y-m-d H:i:s"]</code> - for displaying datetime based on current time';
        $html .= '<br /><code>[w4pl_time day=+6 hour=-1]</code> - for displaying timestamp based on current time';
        $html .= '<br /><br />Note: Above Shortcodes generates times in GMT timezone. To compare time saved in another timezone, use hour attribute. for example: [w4pl_date hour=+6] will generate the time what is identical to GMT+6 timestamp.';
        $html .= '</p>';
        $html .= '</div><!--.wffw-->';
        $html .= '</div><!--.w4pl_group_fields--></div><!--#w4pl_field_group_meta_query-->';
        $fields['meta_query'] = array('position' => '120', 'type' => 'html', 'html' => $html);
        /* ========================================= */
        return $fields;
    }
    public function admin_list_fields($fields, $post_data)
    {
        $list_type = $post_data['list_type'];
        if (!in_array($list_type, array('posts', 'terms.posts'))) {
            return $fields;
        }
        /* Meta Query */
        $html = '<div id="w4pl_field_group_meta_query" class="w4pl_field_group"><div class="w4pl_group_title">Posts: Meta Query</div><div class="w4pl_group_fields">';
        $meta_query_relation = isset($post_data['meta_query']['relation']) && !empty($post_data['meta_query']['relation']) ? $post_data['meta_query']['relation'] : 'OR';
        $html .= '<div class="wffw">';
        $html .= '<table id="w4pl_meta_query_table" class="widefat">
			<thead>
				<tr>
					<th id="w4pl_meta_query_key_cell_head">Key</th>
					<th id="w4pl_meta_query_compare_cell_head">Compare</th>
					<th id="w4pl_meta_query_value_cell_head">Value</th>
					<th id="w4pl_meta_query_action_cell_head">Action</th>
				</tr>
			</thead>
			<tbody>';
        if (isset($post_data['meta_query']) && isset($post_data['meta_query']['key']) && is_array($post_data['meta_query']['key']) && !empty($post_data['meta_query']['key'])) {
            $index = 0;
            foreach ($post_data['meta_query']['key'] as $i => $key) {
                $compare = isset($post_data['meta_query']['compare'][$i]) ? $post_data['meta_query']['compare'][$i] : '';
                $value = isset($post_data['meta_query']['value'][$i]) ? $post_data['meta_query']['value'][$i] : '';
                if (empty($key) || empty($compare)) {
                    continue;
                }
                $html .= '
				<tr><td class="w4pl_meta_query_key_cell">
					' . w4pl_form_child_field_html(array('id' => 'w4pl_meta_query_key_' . $index, 'name' => 'w4pl[meta_query][key][' . $index . ']', 'input_class' => 'w4pl_meta_query_key', 'type' => 'text', 'value' => $key)) . '</td><td class="w4pl_meta_query_compare_cell">' . w4pl_form_child_field_html(array('id' => 'w4pl_meta_query_compare_' . $index, 'name' => 'w4pl[meta_query][compare][' . $index . ']', 'input_class' => 'w4pl_meta_query_compare', 'type' => 'select', 'option' => self::meta_query_compare_options(), 'value' => $compare)) . '</td><td class="w4pl_meta_query_value_cell values" data-pos="' . $index . '">';
                if (!is_array($value)) {
                    $value = array($value);
                }
                $cindex = 0;
                foreach ($value as $val) {
                    $html .= '
					<div class="item">
						<input type="text" value="' . esc_attr($val) . '" name="w4pl[meta_query][value][' . $index . '][]" class="wff wffi_w4pl_meta_query_value_' . $index . ' wfft_text ">
						<a class="w4pl_meta_query_value_add button" href="#">+</a> 
						<a class="w4pl_meta_query_value_del button" href="#">-</a>
					</div>';
                    ++$cindex;
                }
                $html .= '</td><td class="w4pl_meta_query_action_cell"><a class="w4pl_meta_query_remove_btn" href="#" class="button">Remove</a></td>
				</tr>';
                ++$index;
            }
        }
        $html .= '</tbody>
			</table>';
        $html .= '
		<div id="w4pl_meta_query_value_clone" style="display:none;">
			<div class="item">
				<input type="text" class="wff wfft_text wffi_w4pl_meta_query_value">
				<a class="w4pl_meta_query_value_add button" href="#">+</a> 
				<a class="w4pl_meta_query_value_del button" href="#">-</a>
			</div>
		</div>';
        $html .= '
		<p style="text-align:right;"><a id="w4pl_meta_query_add_btn" href="#" class="button">+ Add</a></p>
		<table id="w4pl_meta_query_clone" style="display:none;">
		<tr><td class="w4pl_meta_query_key_cell">
			<input type="text" class="wff wffi_w4pl_meta_query_key wfft_text">
			</td><td class="w4pl_meta_query_compare_cell">' . w4pl_form_child_field_html(array('name' => 'w4pl[meta_query][compare][]', 'input_class' => 'w4pl_meta_query_compare', 'type' => 'select', 'option' => self::meta_query_compare_options())) . '</td><td class="w4pl_meta_query_value_cell values">' . '<div class="item">
				<input type="text" class="wff wfft_text wffi_w4pl_meta_query_value">
				<a class="w4pl_meta_query_value_add button" href="#">+</a> 
				<a class="w4pl_meta_query_value_del button" href="#">-</a>
			</div>' . '</td><td class="w4pl_meta_query_action_cell"><a class="w4pl_meta_query_remove_btn" href="#" class="button">Remove</a></td>' . '
		</tr></table>';
        $html .= w4pl_form_field_html(array('field_wrap' => false, 'name' => 'w4pl[meta_query][relation]', 'label' => 'Relation', 'type' => 'radio', 'option' => array('OR' => 'OR', 'AND' => 'AND'), 'value' => $meta_query_relation));
        $html .= '</div><!--.wffw-->';
        $html .= '</div><!--.w4pl_group_fields--></div><!--#w4pl_field_group_meta_query-->';
        $fields['meta_query'] = array('position' => '120', 'type' => 'html', 'html' => $html);
        /* ========================================= */
        return $fields;
    }