/** * Parse view attributes. * * @param array $out The output array of shortcode attributes. * @param array $pairs The supported attributes and their defaults. * @param array $atts The user defined shortcode attributes. * * @return array */ public static function parse_view($out, $pairs, $atts) { /** * Convert "id" to "view" */ if (isset($atts['id']) && $atts['id']) { $out['view'] = $atts['id']; $out['id'] = null; unset($atts['id']); } // fetch the view $view = wpmtst_get_view($out['view']); /** * Add error attribute for shortcode handler. * * @since 1.21.0 */ if (!$view) { return array_merge(array('view_not_found' => 1), $out); } $view_data = unserialize($view['value']); // ============================================================= // DECENTRALIZE // This is necessary because of the way we use empty attributes; // e.g. random --> random="true" // ============================================================= // ----------------------------------------------------------------- // rule: unset unused defaults that interfere (i.e. dependent rules) // ----------------------------------------------------------------- if ('all' == $view_data['category']) { unset($view_data['category']); } if (!$view_data['id']) { unset($view_data['id']); } if ($view_data['all']) { unset($view_data['count']); } if (!$view_data['pagination']) { unset($view_data['per_page']); } if ('entire' == $view_data['content']) { unset($view_data['length']); } if ('slideshow' == $view_data['mode']) { unset($view_data['id']); // $view_data['no_pause'] = ! $view_data['pause']; } else { unset($view_data['show_for']); unset($view_data['effect_for']); unset($view_data['no_pause']); } // ------------------------------ // rule: extract value from array // ------------------------------ $out[$view_data['mode']] = true; unset($view_data['mode']); $out[$view_data['order']] = true; unset($view_data['order']); $out[$view_data['content']] = true; unset($view_data['content']); // ----------------------------- // merge view onto user settings // ----------------------------- $out = array_merge($out, $view_data); return $out; }
/** * An individual view settings page. * * @since 1.21.0 * * @param string $action * @param null $view_id */ function wpmtst_view_settings($action = '', $view_id = null) { if (('edit' == $action || 'duplicate' == $action) && !$view_id) { return; } global $view, $strong_templates; add_thickbox(); $screen = get_current_screen(); $url = $screen->parent_file; $fields = wpmtst_get_custom_fields(); $all_fields = wpmtst_get_all_fields(); $order_list = wpmtst_get_order_list(); $posts_list = get_posts(array('orderby' => 'post_date', 'order' => 'ASC', 'post_type' => 'wpm-testimonial', 'post_status' => 'publish', 'posts_per_page' => -1, 'suppress_filters' => true)); $category_list = wpmtst_get_category_list(); /** * Show category filter if necessary. * * @since 2.2.0 */ if (count($category_list) > 5) { wp_enqueue_script('wpmtst-view-category-filter-script'); } $pages_list = get_pages(array('sort_order' => 'ASC', 'sort_column' => 'menu_order', 'post_type' => 'page', 'post_status' => 'publish')); $view_options = get_option('wpmtst_view_options'); $default_view = get_option('wpmtst_view_default'); if ('edit' == $action) { $view_array = wpmtst_get_view($view_id); $view = unserialize($view_array['value']); $view_name = $view_array['name']; } elseif ('duplicate' == $action) { $view_array = wpmtst_get_view($view_id); $view = unserialize($view_array['value']); $view_id = 0; $view_name = $view_array['name'] . ' - COPY'; } else { $view_id = 1; $view = $default_view; $view_name = 'new'; } // Deselect title & thumbnail if not in field group $has_title_field = false; $has_thumbnail_field = false; foreach ($all_fields as $key => $field) { if ('post_title' == $field['name']) { $has_title_field = true; } if ('featured_image' == $field['name']) { $has_thumbnail_field = true; } } if (!$has_title_field) { $view['title'] = false; } if (!$has_thumbnail_field) { $view['thumbnail'] = false; } // Select default template if necessary if (!$view['template']) { if ('form' == $view['mode']) { $view['template'] = 'default:form'; } else { $view['template'] = 'default:content'; } } $view['nav'] = explode(',', str_replace(' ', '', $view['nav'])); //$view_cats_array = explode( ',', $view['category'] ); $view_cats_array = apply_filters('wpmtst_l10n_cats', explode(',', $view['category'])); // Assemble list of templates $templates = $strong_templates->get_templates(array('content', 'widget')); $form_templates = $strong_templates->get_templates('form'); $group = strtok($view['template'], ':'); $type = strtok(':'); if ('form' == $type) { $template_found = in_array($view['template'], array_keys($form_templates)); } else { $template_found = in_array($view['template'], array_keys($templates)); } // Get list of image sizes $image_sizes = wpmtst_get_image_sizes(); ?> <h2> <?php 'edit' == $action ? _e('Edit View', 'strong-testimonials') : _e('Add View', 'strong-testimonials'); ?> <a href="<?php echo $url; ?> &page=testimonial-views&action=add" class="add-new-h2">Add New</a> </h2> <p><a href="<?php echo admin_url('edit.php?post_type=wpm-testimonial&page=testimonial-views'); ?> ">Return to list</a></p> <form id="wpmtst-views-form" method="post" action="<?php echo get_admin_url() . 'admin-post.php'; ?> " autocomplete="off"> <?php wp_nonce_field('view_form_submit', 'view_form_nonce', true, true); ?> <input type="hidden" name="action" value="view_<?php echo $action; ?> _form"> <input type="hidden" name="view[id]" value="<?php echo $view_id; ?> "> <input type="hidden" name="view_original_mode" value="<?php echo $view['mode']; ?> "> <input type="hidden" name="view[data][_form_id]" value="<?php echo $view['form_id']; ?> "> <div class="view-info"> <div class="form-view-name"><span class="title">Name:</span><input type="text" id="view-name" class="view-name" name="view[name]" value="<?php echo $view_name; ?> " tabindex="1"></div> </div> <div class="view-info"> <div class="form-view-shortcode"> <span class="title">Shortcode:</span> <?php if ('edit' == $action) { ?> <span class="saved">[testimonial_view id=<?php echo $view_id; ?> ]</span> <?php } else { ?> <span class="unsaved"><?php _ex('will be available after you save this', 'The shortcode for a new View.', 'strong-testimonials'); ?> </span> <?php } ?> </div> </div> <?php include 'views/mode.php'; // TODO Generify both hook and include do_action('wpmtst_view_editor_before_group_select'); include 'views/group-select.php'; do_action('wpmtst_view_editor_before_group_fields'); include 'views/group-fields.php'; do_action('wpmtst_view_editor_before_group_form'); include 'views/group-form.php'; do_action('wpmtst_view_editor_before_group_extra'); include 'views/group-extra.php'; do_action('wpmtst_view_editor_before_group_style'); include 'views/group-style.php'; do_action('wpmtst_view_editor_before_group_general'); include 'views/group-general.php'; do_action('wpmtst_view_editor_after_groups'); ?> <p class="wpmtst-submit"> <?php submit_button('', 'primary', 'submit', false); ?> <?php submit_button(__('Undo Changes', 'strong-testimonials'), 'secondary', 'reset', false); ?> <?php submit_button(__('Restore Defaults', 'strong-testimonials'), 'secondary', 'restore-defaults', false); ?> </p> </form> <?php }