示例#1
0
 /**
  * Retrieve the terms in one or more taxonomies.
  *
  * Compatibility shim for MLAShortcode_Support::mla_get_terms
  *
  * @since 1.60
  *
  * @param	array	taxonomies to search and query parameters
  *
  * @return	array	array of term objects, empty if none found
  */
 public static function mla_get_terms($attr)
 {
     if (!class_exists('MLAShortcode_Support')) {
         require_once MLA_PLUGIN_PATH . 'includes/class-mla-shortcode-support.php';
     }
     return MLAShortcode_Support::mla_get_terms($attr);
 }
 /**
  * Parses shortcode parameters and returns the gallery objects
  *
  * @since 2.20
  *
  * @param int Post ID of the parent
  * @param array Attributes of the shortcode
  * @param boolean true to calculate and return ['found_posts'] as an array element
  *
  * @return array List of attachments returned from WP_Query
  */
 public static function mla_get_shortcode_attachments($post_parent, $attr, $return_found_rows = NULL)
 {
     global $wp_query;
     /*
      * Parameters passed to the where and orderby filter functions
      */
     self::$query_parameters = array();
     /*
      * Parameters passed to the posts_search filter function in MLAData
      */
     MLAQuery::$search_parameters = array('debug' => 'none');
     /*
      * Make sure $attr is an array, even if it's empty
      */
     if (empty($attr)) {
         $attr = array();
     } elseif (is_string($attr)) {
         $attr = shortcode_parse_atts($attr);
     }
     /*
      * The "where used" queries have no $_REQUEST context available to them,
      * so tax_, date_ and meta_query evaluation will fail if they contain "{+request:"
      * parameters. Ignore these errors.
      */
     if (isset($attr['where_used_query']) && 'this-is-a-where-used-query' == $attr['where_used_query']) {
         $where_used_query = true;
         unset($attr['where_used_query']);
     } else {
         $where_used_query = false;
     }
     /*
      * Merge input arguments with defaults, then extract the query arguments.
      *
      * $return_found_rows is used to indicate that the call comes from gallery_shortcode(),
      * which is the only call that supplies it.
      */
     if (!is_null($return_found_rows)) {
         $attr = apply_filters('mla_gallery_query_attributes', $attr);
     }
     $arguments = shortcode_atts(self::$mla_get_shortcode_attachments_parameters, $attr);
     $mla_page_parameter = $arguments['mla_page_parameter'];
     unset($arguments['mla_page_parameter']);
     /*
      * $mla_page_parameter, if set, doesn't make it through the shortcode_atts filter,
      * so we handle it separately
      */
     if (!isset($arguments[$mla_page_parameter])) {
         if (isset($attr[$mla_page_parameter])) {
             $arguments[$mla_page_parameter] = $attr[$mla_page_parameter];
         } else {
             $arguments[$mla_page_parameter] = NULL;
         }
     }
     if (!empty($arguments['ids'])) {
         // 'ids' is explicitly ordered, unless you specify otherwise.
         if (empty($attr['orderby'])) {
             $arguments['orderby'] = 'post__in';
         }
         $arguments['include'] = $arguments['ids'];
     }
     unset($arguments['ids']);
     if (!is_null($return_found_rows)) {
         $arguments = apply_filters('mla_gallery_query_arguments', $arguments);
     }
     /*
      * Extract taxonomy arguments
      */
     $query_arguments = array();
     if (!empty($attr)) {
         $all_taxonomies = get_taxonomies(array('show_ui' => true), 'names');
         $simple_tax_queries = array();
         foreach ($attr as $key => $value) {
             if ('tax_query' == $key) {
                 if (is_array($value)) {
                     $query_arguments[$key] = $value;
                 } else {
                     $tax_query = NULL;
                     $value = self::_sanitize_query_specification($value);
                     /*
                      * Replace invalid queries from "where-used" callers with a harmless equivalent
                      */
                     if ($where_used_query && false !== strpos($value, '{+')) {
                         $value = "array( array( 'taxonomy' => 'none', 'field' => 'slug', 'terms' => 'none' ) )";
                     }
                     $function = @create_function('', 'return ' . $value . ';');
                     if (is_callable($function)) {
                         $tax_query = $function();
                     }
                     if (is_array($tax_query)) {
                         $query_arguments[$key] = $tax_query;
                         break;
                         // Done - the tax_query overrides all other taxonomy parameters
                     } else {
                         return '<p>' . __('ERROR', 'media-library-assistant') . ': ' . __('Invalid mla_gallery', 'media-library-assistant') . ' tax_query = ' . var_export($value, true) . '</p>';
                     }
                 }
                 // not array
             } elseif (array_key_exists($key, $all_taxonomies)) {
                 $simple_tax_queries[$key] = implode(',', array_filter(array_map('trim', explode(',', $value))));
             }
             // array_key_exists
         }
         //foreach $attr
         /*
          * One of five outcomes:
          * 1) An explicit tax_query was found; use it and ignore all other taxonomy parameters
          * 2) No tax query is present; no further processing required
          * 3) Two or more simple tax queries are present; compose a tax_query
          * 4) One simple tax query and (tax_operator or tax_include_children) are present; compose a tax_query
          * 5) One simple tax query is present; use it as-is or convert 'category' to 'category_name'
          */
         if (isset($query_arguments['tax_query']) || empty($simple_tax_queries)) {
             // No further action required
         } elseif (1 < count($simple_tax_queries) || isset($attr['tax_operator']) || isset($attr['tax_include_children'])) {
             // Build a tax_query
             if (1 < count($simple_tax_queries)) {
                 $tax_relation = 'AND';
                 if (isset($attr['tax_relation'])) {
                     if ('OR' == strtoupper($attr['tax_relation'])) {
                         $tax_relation = 'OR';
                     }
                 }
                 $tax_query = array('relation' => $tax_relation);
             } else {
                 $tax_query = array();
             }
             // Validate other tax_query parameters or set defaults
             $tax_operator = 'IN';
             if (isset($attr['tax_operator'])) {
                 $attr_value = strtoupper($attr['tax_operator']);
                 if (in_array($attr_value, array('IN', 'NOT IN', 'AND'))) {
                     $tax_operator = $attr_value;
                 }
             }
             $tax_include_children = true;
             if (isset($attr['tax_include_children'])) {
                 if ('FALSE' == strtoupper($attr['tax_include_children'])) {
                     $tax_include_children = false;
                 }
             }
             foreach ($simple_tax_queries as $key => $value) {
                 $tax_query[] = array('taxonomy' => $key, 'field' => 'slug', 'terms' => explode(',', $value), 'operator' => $tax_operator, 'include_children' => $tax_include_children);
             }
             $query_arguments['tax_query'] = $tax_query;
         } else {
             // exactly one simple query is present
             if (isset($simple_tax_queries['category'])) {
                 $arguments['category_name'] = $simple_tax_queries['category'];
             } else {
                 $query_arguments = $simple_tax_queries;
             }
         }
     }
     // ! empty
     /*
      * $query_arguments has been initialized in the taxonomy code above.
      */
     $is_tax_query = !($use_children = empty($query_arguments));
     foreach ($arguments as $key => $value) {
         /*
          * There are several "fallthru" cases in this switch statement that decide 
          * whether or not to limit the query to children of a specific post.
          */
         $children_ok = true;
         switch ($key) {
             case 'post_parent':
                 switch (strtolower($value)) {
                     case 'all':
                         $value = NULL;
                         $use_children = false;
                         break;
                     case 'any':
                         self::$query_parameters['post_parent'] = 'any';
                         $value = NULL;
                         $use_children = false;
                         break;
                     case 'current':
                         $value = $post_parent;
                         $use_children = true;
                         break;
                     case 'none':
                         self::$query_parameters['post_parent'] = 'none';
                         $value = NULL;
                         $use_children = false;
                         break;
                 }
                 // fallthru
             // fallthru
             case 'id':
                 if (is_numeric($value)) {
                     $query_arguments[$key] = intval($value);
                     if (!$children_ok) {
                         $use_children = false;
                     }
                 }
                 unset($arguments[$key]);
                 break;
             case 'numberposts':
             case 'posts_per_page':
             case 'posts_per_archive_page':
                 if (is_numeric($value)) {
                     $value = intval($value);
                     if (!empty($value)) {
                         $query_arguments[$key] = $value;
                     }
                 }
                 unset($arguments[$key]);
                 break;
             case 'meta_value_num':
                 $children_ok = false;
                 // fallthru
             // fallthru
             case 'offset':
                 if (is_numeric($value)) {
                     $query_arguments[$key] = intval($value);
                     if (!$children_ok) {
                         $use_children = false;
                     }
                 }
                 unset($arguments[$key]);
                 break;
             case 'paged':
                 if ('current' == strtolower($value)) {
                     /*
                      * Note: The query variable 'page' holds the pagenumber for a single paginated
                      * Post or Page that includes the <!--nextpage--> Quicktag in the post content. 
                      */
                     if (get_query_var('page')) {
                         $query_arguments[$key] = get_query_var('page');
                     } else {
                         $query_arguments[$key] = get_query_var('paged') ? get_query_var('paged') : 1;
                     }
                 } elseif (is_numeric($value)) {
                     $query_arguments[$key] = intval($value);
                 } elseif ('' === $value) {
                     $query_arguments[$key] = 1;
                 }
                 unset($arguments[$key]);
                 break;
             case $mla_page_parameter:
             case 'mla_paginate_total':
                 if (is_numeric($value)) {
                     $query_arguments[$key] = intval($value);
                 } elseif ('' === $value) {
                     $query_arguments[$key] = 1;
                 }
                 unset($arguments[$key]);
                 break;
             case 'author':
             case 'cat':
             case 'tag_id':
                 if (!empty($value)) {
                     if (is_array($value)) {
                         $query_arguments[$key] = array_filter($value);
                     } else {
                         $query_arguments[$key] = array_filter(array_map('intval', explode(",", $value)));
                     }
                     if (1 == count($query_arguments[$key])) {
                         $query_arguments[$key] = $query_arguments[$key][0];
                     } else {
                         $query_arguments[$key] = implode(',', $query_arguments[$key]);
                     }
                     $use_children = false;
                 }
                 unset($arguments[$key]);
                 break;
             case 'category__and':
             case 'category__in':
             case 'category__not_in':
             case 'tag__and':
             case 'tag__in':
             case 'tag__not_in':
             case 'include':
                 $children_ok = false;
                 // fallthru
             // fallthru
             case 'exclude':
                 if (!empty($value)) {
                     if (is_array($value)) {
                         $value = array_filter($value);
                     } else {
                         $value = array_filter(array_map('intval', explode(",", $value)));
                     }
                     if (!empty($value)) {
                         $query_arguments[$key] = $value;
                         if (!$children_ok) {
                             $use_children = false;
                         }
                     }
                 }
                 unset($arguments[$key]);
                 break;
             case 'tag_slug__and':
             case 'tag_slug__in':
                 if (!empty($value)) {
                     if (is_array($value)) {
                         $query_arguments[$key] = $value;
                     } else {
                         $query_arguments[$key] = array_filter(array_map('trim', explode(",", $value)));
                     }
                     $use_children = false;
                 }
                 unset($arguments[$key]);
                 break;
             case 'nopaging':
                 // boolean value, default false
                 if (!empty($value) && 'false' != strtolower($value)) {
                     $query_arguments[$key] = true;
                 }
                 unset($arguments[$key]);
                 break;
                 // boolean values, default true
             // boolean values, default true
             case 'cache_results':
             case 'update_post_meta_cache':
             case 'update_post_term_cache':
                 if (!empty($value) && 'true' != strtolower($value)) {
                     $query_arguments[$key] = false;
                 }
                 unset($arguments[$key]);
                 break;
             case 'sentence':
             case 'exact':
                 if (!empty($value) && 'true' == strtolower($value)) {
                     MLAQuery::$search_parameters[$key] = true;
                 } else {
                     MLAQuery::$search_parameters[$key] = false;
                 }
                 unset($arguments[$key]);
                 break;
             case 'mla_search_connector':
             case 'mla_phrase_connector':
             case 'mla_term_connector':
                 if (!empty($value) && 'OR' == strtoupper($value)) {
                     MLAQuery::$search_parameters[$key] = 'OR';
                 } else {
                     MLAQuery::$search_parameters[$key] = 'AND';
                 }
                 unset($arguments[$key]);
                 break;
             case 'mla_terms_phrases':
                 $children_ok = false;
                 // fallthru
             // fallthru
             case 'mla_terms_taxonomies':
             case 'mla_search_fields':
                 if (!empty($value)) {
                     MLAQuery::$search_parameters[$key] = $value;
                     if (!$children_ok) {
                         $use_children = false;
                     }
                 }
                 unset($arguments[$key]);
                 break;
             case 's':
                 MLAQuery::$search_parameters['s'] = trim($value);
                 // fallthru
             // fallthru
             case 'author_name':
             case 'category_name':
             case 'tag':
             case 'meta_key':
             case 'meta_value':
             case 'meta_compare':
                 $children_ok = false;
                 // fallthru
             // fallthru
             case 'post_type':
             case 'post_status':
             case 'post_mime_type':
             case 'orderby':
                 if (!empty($value)) {
                     $query_arguments[$key] = $value;
                     if (!$children_ok) {
                         $use_children = false;
                     }
                 }
                 unset($arguments[$key]);
                 break;
             case 'order':
                 if (!empty($value)) {
                     $value = strtoupper($value);
                     if (in_array($value, array('ASC', 'DESC'))) {
                         $query_arguments[$key] = $value;
                     }
                 }
                 unset($arguments[$key]);
                 break;
             case 'date_query':
                 if (!empty($value)) {
                     if (is_array($value)) {
                         $query_arguments[$key] = $value;
                     } else {
                         $date_query = NULL;
                         $value = self::_sanitize_query_specification($value);
                         /*
                          * Replace invalid queries from "where-used" callers with a harmless equivalent
                          */
                         if ($where_used_query && false !== strpos($value, '{+')) {
                             $value = "array( array( 'key' => 'unlikely', 'value' => 'none or otherwise unlikely' ) )";
                         }
                         $function = @create_function('', 'return ' . $value . ';');
                         if (is_callable($function)) {
                             $date_query = $function();
                         }
                         if (is_array($date_query)) {
                             $query_arguments[$key] = $date_query;
                         } else {
                             return '<p>' . __('ERROR', 'media-library-assistant') . ': ' . __('Invalid mla_gallery', 'media-library-assistant') . ' date_query = ' . var_export($value, true) . '</p>';
                         }
                     }
                     // not array
                     $use_children = false;
                 }
                 unset($arguments[$key]);
                 break;
             case 'meta_query':
                 if (!empty($value)) {
                     if (is_array($value)) {
                         $query_arguments[$key] = $value;
                     } else {
                         $meta_query = NULL;
                         $value = self::_sanitize_query_specification($value);
                         /*
                          * Replace invalid queries from "where-used" callers with a harmless equivalent
                          */
                         if ($where_used_query && false !== strpos($value, '{+')) {
                             $value = "array( array( 'key' => 'unlikely', 'value' => 'none or otherwise unlikely' ) )";
                         }
                         $function = @create_function('', 'return ' . $value . ';');
                         if (is_callable($function)) {
                             $meta_query = $function();
                         }
                         if (is_array($meta_query)) {
                             $query_arguments[$key] = $meta_query;
                         } else {
                             return '<p>' . __('ERROR', 'media-library-assistant') . ': ' . __('Invalid mla_gallery', 'media-library-assistant') . ' meta_query = ' . var_export($value, true) . '</p>';
                         }
                     }
                     // not array
                     $use_children = false;
                 }
                 unset($arguments[$key]);
                 break;
             case 'fields':
                 if (!empty($value)) {
                     $value = strtolower($value);
                     if (in_array($value, array('ids', 'id=>parent'))) {
                         $query_arguments[$key] = $value;
                     }
                 }
                 unset($arguments[$key]);
                 break;
             default:
                 // ignore anything else
         }
         // switch $key
     }
     // foreach $arguments
     /*
      * Decide whether to use a "get_children" style query
      */
     self::$query_parameters['disable_tax_join'] = $is_tax_query && !$use_children;
     if ($use_children && !isset($query_arguments['post_parent'])) {
         if (!isset($query_arguments['id'])) {
             $query_arguments['post_parent'] = $post_parent;
         } else {
             $query_arguments['post_parent'] = $query_arguments['id'];
         }
         unset($query_arguments['id']);
     }
     if (isset($query_arguments['numberposts']) && !isset($query_arguments['posts_per_page'])) {
         $query_arguments['posts_per_page'] = $query_arguments['numberposts'];
     }
     unset($query_arguments['numberposts']);
     /*
      * MLA pagination will override WordPress pagination
      */
     if (isset($query_arguments[$mla_page_parameter])) {
         unset($query_arguments['nopaging']);
         unset($query_arguments['offset']);
         unset($query_arguments['paged']);
         if (isset($query_arguments['mla_paginate_total']) && $query_arguments[$mla_page_parameter] > $query_arguments['mla_paginate_total']) {
             $query_arguments['offset'] = 0x7fffffff;
             // suppress further output
         } else {
             $query_arguments['paged'] = $query_arguments[$mla_page_parameter];
         }
     } else {
         if (isset($query_arguments['posts_per_page']) || isset($query_arguments['posts_per_archive_page']) || isset($query_arguments['paged']) || isset($query_arguments['offset'])) {
             unset($query_arguments['nopaging']);
         }
     }
     unset($query_arguments[$mla_page_parameter]);
     unset($query_arguments['mla_paginate_total']);
     if (isset($query_arguments['post_mime_type']) && 'all' == strtolower($query_arguments['post_mime_type'])) {
         unset($query_arguments['post_mime_type']);
     }
     if (!empty($query_arguments['include'])) {
         $incposts = wp_parse_id_list($query_arguments['include']);
         $query_arguments['posts_per_page'] = count($incposts);
         // only the number of posts included
         $query_arguments['post__in'] = $incposts;
         unset($query_arguments['include']);
     } elseif (!empty($query_arguments['exclude'])) {
         $query_arguments['post__not_in'] = wp_parse_id_list($query_arguments['exclude']);
         unset($query_arguments['exclude']);
     }
     $query_arguments['ignore_sticky_posts'] = true;
     $query_arguments['no_found_rows'] = is_null($return_found_rows) ? true : !$return_found_rows;
     /*
      * We will always handle "orderby" in our filter
      */
     self::$query_parameters['orderby'] = self::_validate_sql_orderby($query_arguments);
     if (false === self::$query_parameters['orderby']) {
         unset(self::$query_parameters['orderby']);
     }
     unset($query_arguments['orderby']);
     unset($query_arguments['order']);
     if (self::$mla_debug) {
         add_filter('posts_clauses', 'MLAShortcode_Support::mla_shortcode_query_posts_clauses_filter', 0x7fffffff, 1);
         add_filter('posts_clauses_request', 'MLAShortcode_Support::mla_shortcode_query_posts_clauses_request_filter', 0x7fffffff, 1);
     }
     add_filter('posts_join', 'MLAShortcode_Support::mla_shortcode_query_posts_join_filter', 0x7fffffff, 1);
     add_filter('posts_where', 'MLAShortcode_Support::mla_shortcode_query_posts_where_filter', 0x7fffffff, 1);
     add_filter('posts_orderby', 'MLAShortcode_Support::mla_shortcode_query_posts_orderby_filter', 0x7fffffff, 1);
     /*
      * Handle the keyword and terms search in the posts_search filter.
      * One or both of 'mla_terms_phrases' and 's' must be present to
      * trigger the search.
      */
     if (empty(MLAQuery::$search_parameters['mla_terms_phrases']) && empty(MLAQuery::$search_parameters['s'])) {
         MLAQuery::$search_parameters = array('debug' => 'none');
     } else {
         /*
          * Convert Terms Search parameters to the filter's requirements.
          * mla_terms_taxonomies is shared with keyword search.
          */
         if (empty(MLAQuery::$search_parameters['mla_terms_taxonomies'])) {
             MLAQuery::$search_parameters['mla_terms_search']['taxonomies'] = MLACore::mla_supported_taxonomies('term-search');
         } else {
             MLAQuery::$search_parameters['mla_terms_search']['taxonomies'] = array_filter(array_map('trim', explode(',', MLAQuery::$search_parameters['mla_terms_taxonomies'])));
         }
         if (!empty(MLAQuery::$search_parameters['mla_terms_phrases'])) {
             MLAQuery::$search_parameters['mla_terms_search']['phrases'] = MLAQuery::$search_parameters['mla_terms_phrases'];
             if (empty(MLAQuery::$search_parameters['mla_phrase_connector'])) {
                 MLAQuery::$search_parameters['mla_terms_search']['radio_phrases'] = 'AND';
             } else {
                 MLAQuery::$search_parameters['mla_terms_search']['radio_phrases'] = MLAQuery::$search_parameters['mla_phrase_connector'];
             }
             if (empty(MLAQuery::$search_parameters['mla_term_connector'])) {
                 MLAQuery::$search_parameters['mla_terms_search']['radio_terms'] = 'OR';
             } else {
                 MLAQuery::$search_parameters['mla_terms_search']['radio_terms'] = MLAQuery::$search_parameters['mla_phrase_connector'];
             }
         }
         unset(MLAQuery::$search_parameters['mla_terms_phrases']);
         unset(MLAQuery::$search_parameters['mla_terms_taxonomies']);
         unset(MLAQuery::$search_parameters['mla_phrase_connector']);
         unset(MLAQuery::$search_parameters['mla_term_connector']);
         if (empty(MLAQuery::$search_parameters['mla_search_fields'])) {
             MLAQuery::$search_parameters['mla_search_fields'] = array('title', 'content');
         } else {
             MLAQuery::$search_parameters['mla_search_fields'] = array_filter(array_map('trim', explode(',', MLAQuery::$search_parameters['mla_search_fields'])));
             MLAQuery::$search_parameters['mla_search_fields'] = array_intersect(array('title', 'content', 'excerpt', 'name', 'terms'), MLAQuery::$search_parameters['mla_search_fields']);
             /*
              * Look for keyword search including 'terms' 
              */
             foreach (MLAQuery::$search_parameters['mla_search_fields'] as $index => $field) {
                 if ('terms' == $field) {
                     if (isset(MLAQuery::$search_parameters['mla_terms_search']['phrases'])) {
                         /*
                          * The Terms Search overrides any terms-based keyword search for now; too complicated.
                          */
                         unset(MLAQuery::$search_parameters['mla_search_fields'][$index]);
                     } else {
                         MLAQuery::$search_parameters['mla_search_taxonomies'] = MLAQuery::$search_parameters['mla_terms_search']['taxonomies'];
                         unset(MLAQuery::$search_parameters['mla_terms_search']['taxonomies']);
                     }
                 }
                 // terms in search fields
             }
         }
         // mla_search_fields present
         if (empty(MLAQuery::$search_parameters['mla_search_connector'])) {
             MLAQuery::$search_parameters['mla_search_connector'] = 'AND';
         }
         if (empty(MLAQuery::$search_parameters['sentence'])) {
             MLAQuery::$search_parameters['sentence'] = false;
         }
         if (empty(MLAQuery::$search_parameters['exact'])) {
             MLAQuery::$search_parameters['exact'] = false;
         }
         MLAQuery::$search_parameters['debug'] = self::$mla_debug ? 'shortcode' : 'none';
         add_filter('posts_search', 'MLAQuery::mla_query_posts_search_filter', 10, 2);
         add_filter('posts_groupby', 'MLAQuery::mla_query_posts_groupby_filter');
     }
     if (self::$mla_debug) {
         global $wp_filter;
         foreach ($wp_filter['posts_where'] as $priority => $filters) {
             $debug_message = '<strong>mla_debug $wp_filter[posts_where]</strong> priority = ' . var_export($priority, true) . '<br />';
             foreach ($filters as $name => $descriptor) {
                 $debug_message .= 'filter name = ' . var_export($name, true) . '<br />';
             }
             MLACore::mla_debug_add($debug_message);
         }
         foreach ($wp_filter['posts_orderby'] as $priority => $filters) {
             $debug_message = '<strong>mla_debug $wp_filter[posts_orderby]</strong> priority = ' . var_export($priority, true) . '<br />';
             foreach ($filters as $name => $descriptor) {
                 $debug_message .= 'filter name = ' . var_export($name, true) . '<br />';
             }
             MLACore::mla_debug_add($debug_message);
         }
     }
     /*
      * Disable Relevanssi - A Better Search, v3.2 by Mikko Saari 
      * relevanssi_prevent_default_request( $request, $query )
      * apply_filters('relevanssi_admin_search_ok', $admin_search_ok, $query );
      */
     if (function_exists('relevanssi_prevent_default_request')) {
         add_filter('relevanssi_admin_search_ok', 'MLAData::mla_query_relevanssi_admin_search_ok_filter');
     }
     if (class_exists('MLA_Polylang')) {
         $query_arguments = apply_filters('mla_get_shortcode_attachments_final_terms', $query_arguments, $return_found_rows);
     }
     MLAShortcodes::$mla_gallery_wp_query_object = new WP_Query();
     $attachments = MLAShortcodes::$mla_gallery_wp_query_object->query($query_arguments);
     /*
      * $return_found_rows is used to indicate that the call comes from gallery_shortcode(),
      * which is the only call that supplies it.
      */
     if (is_null($return_found_rows)) {
         $return_found_rows = false;
     } else {
         do_action('mla_gallery_wp_query_object', $query_arguments);
     }
     if ($return_found_rows) {
         $attachments['found_rows'] = MLAShortcodes::$mla_gallery_wp_query_object->found_posts;
     }
     if (!empty(MLAQuery::$search_parameters)) {
         remove_filter('posts_groupby', 'MLAQuery::mla_query_posts_groupby_filter');
         remove_filter('posts_search', 'MLAQuery::mla_query_posts_search_filter');
     }
     if (function_exists('relevanssi_prevent_default_request')) {
         remove_filter('relevanssi_admin_search_ok', 'MLAData::mla_query_relevanssi_admin_search_ok_filter');
     }
     remove_filter('posts_join', 'MLAShortcode_Support::mla_shortcode_query_posts_join_filter', 0x7fffffff);
     remove_filter('posts_where', 'MLAShortcode_Support::mla_shortcode_query_posts_where_filter', 0x7fffffff);
     remove_filter('posts_orderby', 'MLAShortcode_Support::mla_shortcode_query_posts_orderby_filter', 0x7fffffff);
     if (self::$mla_debug) {
         remove_filter('posts_clauses', 'MLAShortcode_Support::mla_shortcode_query_posts_clauses_filter', 0x7fffffff);
         remove_filter('posts_clauses_request', 'MLAShortcode_Support::mla_shortcode_query_posts_clauses_request_filter', 0x7fffffff);
         MLACore::mla_debug_add('<strong>' . __('mla_debug query', 'media-library-assistant') . '</strong> = ' . var_export($query_arguments, true));
         MLACore::mla_debug_add('<strong>' . __('mla_debug request', 'media-library-assistant') . '</strong> = ' . var_export(MLAShortcodes::$mla_gallery_wp_query_object->request, true));
         MLACore::mla_debug_add('<strong>' . __('mla_debug query_vars', 'media-library-assistant') . '</strong> = ' . var_export(MLAShortcodes::$mla_gallery_wp_query_object->query_vars, true));
         MLACore::mla_debug_add('<strong>' . __('mla_debug post_count', 'media-library-assistant') . '</strong> = ' . var_export(MLAShortcodes::$mla_gallery_wp_query_object->post_count, true));
     }
     MLAShortcodes::$mla_gallery_wp_query_object = NULL;
     return $attachments;
 }
示例#3
0
 /**
  * Compose the MLA Gallery tab content for the Settings subpage
  *
  * @since 0.80
  * @uses $page_template_array contains tab content template(s)
  *
  * @return	array	'message' => status/error messages, 'body' => tab content
  */
 private static function _compose_mla_gallery_tab()
 {
     /*
      * Check for submit buttons to change or reset settings.
      * Initialize page messages and content.
      */
     if (!empty($_REQUEST['mla-gallery-options-save'])) {
         check_admin_referer(MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME);
         $page_content = self::_save_gallery_settings();
     } else {
         $page_content = array('message' => '', 'body' => '');
     }
     if (!empty($page_content['body'])) {
         return $page_content;
     }
     $page_values = array('MLA Gallery Options' => __('MLA Gallery Options', 'media-library-assistant'), 'Go to Style Templates' => __('Go to Style Templates', 'media-library-assistant'), 'Go to Markup Templates' => __('Go to Markup Templates', 'media-library-assistant'), 'In this tab' => __('In this tab you can view the default style and markup templates. You can also define additional templates and use the <code>mla_style</code> and <code>mla_markup</code> parameters to apply them in your <code>[mla_gallery]</code> shortcodes. <strong>NOTE:</strong> template additions and changes will not be made permanent until you click "Save Changes" at the bottom of this page.', 'media-library-assistant'), 'form_url' => admin_url('options-general.php') . '?page=mla-settings-menu-mla_gallery&mla_tab=mla_gallery', 'options_list' => '', 'Go to Top' => __('Go to Top', 'media-library-assistant'), 'Style Templates' => __('Style Templates', 'media-library-assistant'), 'style_options_list' => '', 'Markup Templates' => __('Markup Templates', 'media-library-assistant'), 'markup_options_list' => '', 'Save Changes' => __('Save Changes', 'media-library-assistant'), '_wpnonce' => wp_nonce_field(MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false), '_wp_http_referer' => wp_referer_field(false));
     /*
      * Build default template selection lists; leave out the [mla_tag_cloud] templates
      */
     MLACore::$mla_option_definitions['default_style']['options'][] = 'none';
     MLACore::$mla_option_definitions['default_style']['texts'][] = '&mdash; ' . __('None', 'media-library-assistant') . ' &mdash;';
     MLACore::$mla_option_definitions['default_style']['options'][] = 'theme';
     MLACore::$mla_option_definitions['default_style']['texts'][] = '&mdash; ' . __('Theme', 'media-library-assistant') . ' &mdash;';
     $templates = MLAOptions::mla_get_style_templates();
     ksort($templates);
     foreach ($templates as $key => $value) {
         if ('tag-cloud' == $key) {
             continue;
         }
         MLACore::$mla_option_definitions['default_style']['options'][] = $key;
         MLACore::$mla_option_definitions['default_style']['texts'][] = $key;
     }
     $templates = MLAOptions::mla_get_markup_templates();
     ksort($templates);
     foreach ($templates as $key => $value) {
         if (in_array($key, array('tag-cloud', 'tag-cloud-dl', 'tag-cloud-ul'))) {
             continue;
         }
         MLACore::$mla_option_definitions['default_markup']['options'][] = $key;
         MLACore::$mla_option_definitions['default_markup']['texts'][] = $key;
     }
     /*
      * Check for MLA Viewer Support requirements,
      * starting with Imagick check
      */
     if (!class_exists('Imagick')) {
         $not_supported_warning = '<br>&nbsp;&nbsp;' . __('Imagick support is not installed.', 'media-library-assistant');
     } else {
         $not_supported_warning = '';
     }
     $ghostscript_path = MLACore::mla_get_option('ghostscript_path');
     if (!MLAShortcode_Support::mla_ghostscript_present($ghostscript_path, true)) {
         $not_supported_warning .= '<br>&nbsp;&nbsp;' . __('Ghostscript support is not installed.', 'media-library-assistant');
     }
     if (!empty($not_supported_warning)) {
         MLACore::$mla_option_definitions['enable_mla_viewer']['help'] = '<strong>' . __('WARNING:', 'media-library-assistant') . __(' MLA Viewer support may not be available', 'media-library-assistant') . ':</strong>' . $not_supported_warning;
     }
     /*
      * Start with any page-level options
      */
     $options_list = '';
     foreach (MLACore::$mla_option_definitions as $key => $value) {
         if ('mla_gallery' == $value['tab']) {
             $options_list .= self::mla_compose_option_row($key, $value);
         }
     }
     $page_values['options_list'] = $options_list;
     /*
      * Add style templates; defaults go first
      */
     $default_styles = array('default', 'tag-cloud');
     $style_options_list = '';
     $templates = MLAOptions::mla_get_style_templates();
     foreach ($default_styles as $default) {
         $name = $default;
         $value = $templates[$default];
         if (!empty($value)) {
             $template_values = array('help' => __('This default template cannot be altered or deleted, but you can copy the styles.', 'media-library-assistant'));
             $control_cells = MLAData::mla_parse_template(self::$page_template_array['mla-gallery-default'], $template_values);
             $template_values = array('Name' => __('Name', 'media-library-assistant'), 'name_name' => "mla_style_templates_name[{$default}]", 'name_id' => "mla_style_templates_name_{$default}", 'readonly' => 'readonly="readonly"', 'name_text' => $default, 'control_cells' => $control_cells, 'Styles' => __('Styles', 'media-library-assistant'), 'value_name' => "mla_style_templates_value[{$default}]", 'value_id' => "mla_style_templates_value_{$default}", 'value_text' => esc_textarea($value), 'value_help' => __('List of substitution parameters, e.g., [+selector+], on Documentation tab.', 'media-library-assistant'));
             $style_options_list .= MLAData::mla_parse_template(self::$page_template_array['mla-gallery-style'], $template_values);
         }
         // $value
     }
     // foreach default
     foreach ($templates as $name => $value) {
         $slug = sanitize_title($name);
         if (in_array($name, $default_styles)) {
             continue;
             // already handled above
         }
         $template_values = array('name' => 'mla_style_templates_delete[' . $slug . ']', 'id' => 'mla_style_templates_delete_' . $slug, 'value' => __('Delete this template', 'media-library-assistant'), 'help' => __('Check the box to delete this template when you press Update at the bottom of the page.', 'media-library-assistant'));
         $control_cells = MLAData::mla_parse_template(self::$page_template_array['mla-gallery-delete'], $template_values);
         $template_values = array('Name' => __('Name', 'media-library-assistant'), 'name_name' => 'mla_style_templates_name[' . $slug . ']', 'name_id' => 'mla_style_templates_name_' . $slug, 'readonly' => '', 'name_text' => $slug, 'control_cells' => $control_cells, 'Styles' => __('Styles', 'media-library-assistant'), 'value_name' => 'mla_style_templates_value[' . $slug . ']', 'value_id' => 'mla_style_templates_value_' . $slug, 'value_text' => esc_textarea($value), 'value_help' => __('List of substitution parameters, e.g., [+selector+], on Documentation tab.', 'media-library-assistant'));
         $style_options_list .= MLAData::mla_parse_template(self::$page_template_array['mla-gallery-style'], $template_values);
     }
     // foreach $templates
     /*
      * Add blank style template for additions
      */
     if (!empty($value)) {
         $template_values = array('help' => __('Fill in a name and styles to add a new template.', 'media-library-assistant'));
         $control_cells = MLAData::mla_parse_template(self::$page_template_array['mla-gallery-default'], $template_values);
         $template_values = array('Name' => __('Name', 'media-library-assistant'), 'name_name' => 'mla_style_templates_name[blank]', 'name_id' => 'mla_style_templates_name_blank', 'readonly' => '', 'name_text' => '', 'control_cells' => $control_cells, 'Styles' => __('Styles', 'media-library-assistant'), 'value_name' => 'mla_style_templates_value[blank]', 'value_id' => 'mla_style_templates_value_blank', 'value_text' => '', 'value_help' => __('List of substitution parameters, e.g., [+selector+], on Documentation tab.', 'media-library-assistant'));
         $style_options_list .= MLAData::mla_parse_template(self::$page_template_array['mla-gallery-style'], $template_values);
     }
     // $value
     $page_values['style_options_list'] = $style_options_list;
     /*
      * Add markup templates; defaults go first
      */
     $default_markups = array('default', 'tag-cloud', 'tag-cloud-ul', 'tag-cloud-dl');
     $markup_options_list = '';
     $templates = MLAOptions::mla_get_markup_templates();
     foreach ($default_markups as $default) {
         $name = $default;
         $value = $templates[$default];
         if (!empty($value)) {
             $template_values = array('help' => __('This default template cannot be altered or deleted, but you can copy the markup.', 'media-library-assistant'));
             $control_cells = MLAData::mla_parse_template(self::$page_template_array['mla-gallery-default'], $template_values);
             $template_values = array('Name' => __('Name', 'media-library-assistant'), 'name_name' => "mla_markup_templates_name[{$default}]", 'name_id' => "mla_markup_templates_name_{$default}", 'readonly' => 'readonly="readonly"', 'name_text' => $default, 'control_cells' => $control_cells, 'Open' => __('Open', 'media-library-assistant'), 'open_name' => "mla_markup_templates_open[{$default}]", 'open_id' => "mla_markup_templates_open_{$default}", 'open_text' => isset($value['open']) ? esc_textarea($value['open']) : '', 'open_help' => __('Markup for the beginning of the gallery. List of parameters, e.g., [+selector+], on Documentation tab.', 'media-library-assistant'), 'Row' => __('Row', 'media-library-assistant'), 'row_open_name' => "mla_markup_templates_row_open[{$default}]", 'row_open_id' => "mla_markup_templates_row_open_{$default}", 'row_open_text' => isset($value['row-open']) ? esc_textarea($value['row-open']) : '', 'row_open_help' => __('Markup for the beginning of each row in the gallery.', 'media-library-assistant'), 'Item' => __('Item', 'media-library-assistant'), 'item_name' => "mla_markup_templates_item[{$default}]", 'item_id' => "mla_markup_templates_item_{$default}", 'item_text' => isset($value['item']) ? esc_textarea($value['item']) : '', 'item_help' => __('Markup for each item/cell of the gallery.', 'media-library-assistant'), 'Close' => __('Close', 'media-library-assistant'), 'row_close_name' => "mla_markup_templates_row_close[{$default}]", 'row_close_id' => "mla_markup_templates_row_close_{$default}", 'row_close_text' => isset($value['row-close']) ? esc_textarea($value['row-close']) : '', 'row_close_help' => __('Markup for the end of each row in the gallery.', 'media-library-assistant'), 'close_name' => "mla_markup_templates_close[{$default}]", 'close_id' => "mla_markup_templates_close_{$default}", 'close_text' => isset($value['close']) ? esc_textarea($value['close']) : '', 'close_help' => __('Markup for the end of the gallery.', 'media-library-assistant'));
             $markup_options_list .= MLAData::mla_parse_template(self::$page_template_array['mla-gallery-markup'], $template_values);
         }
         // $value
     }
     // foreach default
     foreach ($templates as $name => $value) {
         $slug = sanitize_title($name);
         if (in_array($name, $default_markups)) {
             continue;
             // already handled above
         }
         $template_values = array('name' => 'mla_markup_templates_delete[' . $slug . ']', 'id' => 'mla_markup_templates_delete_' . $slug, 'value' => __('Delete this template', 'media-library-assistant'), 'help' => __('Check the box to delete this template when you press Update at the bottom of the page.', 'media-library-assistant'));
         $control_cells = MLAData::mla_parse_template(self::$page_template_array['mla-gallery-delete'], $template_values);
         $template_values = array('Name' => __('Name', 'media-library-assistant'), 'name_name' => 'mla_markup_templates_name[' . $slug . ']', 'name_id' => 'mla_markup_templates_name_' . $slug, 'readonly' => '', 'name_text' => $slug, 'control_cells' => $control_cells, 'Open' => __('Open', 'media-library-assistant'), 'open_name' => 'mla_markup_templates_open[' . $slug . ']', 'open_id' => 'mla_markup_templates_open_' . $slug, 'open_text' => esc_textarea($value['open']), 'open_help' => __('Markup for the beginning of the gallery. List of parameters, e.g., [+selector+], on Documentation tab.', 'media-library-assistant'), 'Row' => __('Row', 'media-library-assistant'), 'row_open_name' => 'mla_markup_templates_row_open[' . $slug . ']', 'row_open_id' => 'mla_markup_templates_row_open_' . $slug, 'row_open_text' => esc_textarea($value['row-open']), 'row_open_help' => __('Markup for the beginning of each row.', 'media-library-assistant'), 'Item' => __('Item', 'media-library-assistant'), 'item_name' => 'mla_markup_templates_item[' . $slug . ']', 'item_id' => 'mla_markup_templates_item_' . $slug, 'item_text' => esc_textarea($value['item']), 'item_help' => __('Markup for each item/cell.', 'media-library-assistant'), 'Close' => __('Close', 'media-library-assistant'), 'row_close_name' => 'mla_markup_templates_row_close[' . $slug . ']', 'row_close_id' => 'mla_markup_templates_row_close_' . $slug, 'row_close_text' => esc_textarea($value['row-close']), 'row_close_help' => __('Markup for the end of each row.', 'media-library-assistant'), 'close_name' => 'mla_markup_templates_close[' . $slug . ']', 'close_id' => 'mla_markup_templates_close_' . $slug, 'close_text' => esc_textarea($value['close']), 'close_help' => __('Markup for the end of the gallery.', 'media-library-assistant'));
         $markup_options_list .= MLAData::mla_parse_template(self::$page_template_array['mla-gallery-markup'], $template_values);
     }
     // foreach $templates
     /*
      * Add blank markup template for additions
      */
     if (!empty($value)) {
         $template_values = array('help' => __('Fill in a name and markup to add a new template.', 'media-library-assistant'));
         $control_cells = MLAData::mla_parse_template(self::$page_template_array['mla-gallery-default'], $template_values);
         $template_values = array('Name' => __('Name', 'media-library-assistant'), 'name_name' => 'mla_markup_templates_name[blank]', 'name_id' => 'mla_markup_templates_name_blank', 'readonly' => '', 'name_text' => '', 'control_cells' => $control_cells, 'Open' => __('Open', 'media-library-assistant'), 'open_name' => 'mla_markup_templates_open[blank]', 'open_id' => 'mla_markup_templates_open_blank', 'open_text' => '', 'open_help' => __('Markup for the beginning of the gallery. List of parameters, e.g., [+selector+], on Documentation tab.', 'media-library-assistant'), 'Row' => __('Row', 'media-library-assistant'), 'row_open_name' => 'mla_markup_templates_row_open[blank]', 'row_open_id' => 'mla_markup_templates_row_open_blank', 'row_open_text' => '', 'row_open_help' => __('Markup for the beginning of each row in the gallery.', 'media-library-assistant'), 'Item' => __('Item', 'media-library-assistant'), 'item_name' => 'mla_markup_templates_item[blank]', 'item_id' => 'mla_markup_templates_item_blank', 'item_text' => '', 'item_help' => __('Markup for each item/cell of the gallery.', 'media-library-assistant'), 'Close' => __('Close', 'media-library-assistant'), 'row_close_name' => 'mla_markup_templates_row_close[blank]', 'row_close_id' => 'mla_markup_templates_row_close_blank', 'row_close_text' => '', 'row_close_help' => __('Markup for the end of each row in the gallery.', 'media-library-assistant'), 'close_name' => 'mla_markup_templates_close[blank]', 'close_id' => 'mla_markup_templates_close_blank', 'close_text' => '', 'close_help' => __('Markup for the end of the gallery.', 'media-library-assistant'));
         $markup_options_list .= MLAData::mla_parse_template(self::$page_template_array['mla-gallery-markup'], $template_values);
     }
     // $value
     $page_values['markup_options_list'] = $markup_options_list;
     $page_content['body'] = MLAData::mla_parse_template(self::$page_template_array['mla-gallery-tab'], $page_values);
     return $page_content;
 }
示例#4
0
 /**
  * Put user-defined markup templates to $mla_templates and database
  *
  * @since 0.80
  *
  * @param	array	name => value for all user-defined markup templates
  * @return	boolean	true if success, false if failure
  */
 public static function mla_put_markup_templates($templates)
 {
     if (MLACore::mla_update_option('markup_templates', $templates)) {
         MLAShortcode_Support::mla_load_custom_templates();
         return true;
     }
     return false;
 }
 /**
  * Compose the MLA Gallery tab content for the Settings subpage
  *
  * @since 0.80
  * @uses $page_template_array contains tab content template(s)
  *
  * @return	array	'message' => status/error messages, 'body' => tab content
  */
 private static function _compose_mla_gallery_tab()
 {
     /*
      * Check for submit buttons to change or reset settings.
      * Initialize page messages and content.
      */
     if (!empty($_REQUEST['mla-gallery-options-save'])) {
         check_admin_referer(MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME);
         $page_content = self::_save_gallery_settings();
     } else {
         $page_content = array('message' => '', 'body' => '');
     }
     if (!empty($page_content['body'])) {
         return $page_content;
     }
     /*
      * Compose shortcode jump table
      */
     $shortcode_jump_rows = '';
     foreach (MLATemplate_Support::$mla_template_definitions['style'] as $shortcode => $definition) {
         $template_values = array('shortcode' => $shortcode, 'Go to Style Templates' => sprintf('%1$s [mla_%2$s] %3$s', __('Go to', 'media-library-assistant'), $shortcode, __('Style Templates', 'media-library-assistant')), 'Go to Markup Templates' => sprintf('%1$s [mla_%2$s] %3$s', __('Go to', 'media-library-assistant'), $shortcode, __('Markup Templates', 'media-library-assistant')));
         $shortcode_jump_rows .= MLAData::mla_parse_template(self::$page_template_array['shortcode-jump-row'], $template_values);
     }
     $page_values = array('MLA Shortcode Options' => __('MLA Shortcode Options', 'media-library-assistant'), 'Shortcode Jump Rows' => $shortcode_jump_rows, 'In this tab' => __('In this tab you can view the default style and markup templates. You can also define additional templates and use the <code>mla_style</code> and <code>mla_markup</code> parameters to apply them in your <code>[mla_gallery]</code> shortcodes. <strong>NOTE:</strong> template additions and changes will not be made permanent until you click "Save Changes" at the bottom of this page.', 'media-library-assistant'), 'form_url' => admin_url('options-general.php') . '?page=mla-settings-menu-mla_gallery&mla_tab=mla_gallery', 'options_list' => '', 'Go to Top' => __('Go to Top', 'media-library-assistant'), 'Go to Bottom' => __('Go to Bottom', 'media-library-assistant'), 'style_sections_list' => '', 'markup_sections_list' => '', 'Save Changes' => __('Save Changes', 'media-library-assistant'), '_wpnonce' => wp_nonce_field(MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false), '_wp_http_referer' => wp_referer_field(false));
     /*
      * Build default template selection lists
      */
     MLACoreOptions::$mla_option_definitions['default_style']['options'][] = 'none';
     MLACoreOptions::$mla_option_definitions['default_style']['texts'][] = '&mdash; ' . __('None', 'media-library-assistant') . ' &mdash;';
     MLACoreOptions::$mla_option_definitions['default_style']['options'][] = 'theme';
     MLACoreOptions::$mla_option_definitions['default_style']['texts'][] = '&mdash; ' . __('Theme', 'media-library-assistant') . ' &mdash;';
     $templates = MLATemplate_Support::mla_get_style_templates('gallery');
     ksort($templates);
     foreach ($templates as $key => $value) {
         MLACoreOptions::$mla_option_definitions['default_style']['options'][] = $key;
         MLACoreOptions::$mla_option_definitions['default_style']['texts'][] = $key;
     }
     $templates = MLATemplate_Support::mla_get_markup_templates('gallery');
     ksort($templates);
     foreach ($templates as $key => $value) {
         MLACoreOptions::$mla_option_definitions['default_markup']['options'][] = $key;
         MLACoreOptions::$mla_option_definitions['default_markup']['texts'][] = $key;
     }
     /*
      * Check for MLA Viewer Support requirements,
      * starting with Imagick check
      */
     if (!class_exists('Imagick')) {
         $not_supported_warning = '<br>&nbsp;&nbsp;' . __('Imagick support is not installed.', 'media-library-assistant');
     } else {
         $not_supported_warning = '';
     }
     $ghostscript_path = MLACore::mla_get_option('ghostscript_path');
     if (!MLAShortcode_Support::mla_ghostscript_present($ghostscript_path, true)) {
         $not_supported_warning .= '<br>&nbsp;&nbsp;' . __('Ghostscript support is not installed.', 'media-library-assistant');
     }
     if (!empty($not_supported_warning)) {
         MLACoreOptions::$mla_option_definitions['enable_mla_viewer']['help'] = '<strong>' . __('WARNING:', 'media-library-assistant') . __(' MLA Viewer support may not be available', 'media-library-assistant') . ':</strong>' . $not_supported_warning;
     }
     /*
      * Start with any page-level options
      */
     $options_list = '';
     foreach (MLACoreOptions::$mla_option_definitions as $key => $value) {
         if ('mla_gallery' == $value['tab']) {
             $options_list .= self::mla_compose_option_row($key, $value);
         }
     }
     $page_values['options_list'] = $options_list;
     /*
      * Add style templates by shortcode; defaults go first
      */
     $style_sections_list = '';
     foreach (MLATemplate_Support::$mla_template_definitions['style'] as $shortcode => $definition) {
         $templates = MLATemplate_Support::mla_get_style_templates($definition['slug']);
         $style_options_list = '';
         foreach ($definition['default_names'] as $default) {
             if (!array_key_exists($default, $templates)) {
                 continue;
             }
             $value = $templates[$default];
             if (!empty($value)) {
                 $template_values = array('help' => __('This default template cannot be altered or deleted, but you can copy the styles.', 'media-library-assistant'));
                 $control_cells = MLAData::mla_parse_template(self::$page_template_array['mla-gallery-default'], $template_values);
                 $template_values = array('Name' => __('Name', 'media-library-assistant'), 'name_name' => "mla_style_templates_name[{$shortcode}][{$default}]", 'name_id' => "mla_style_templates_name_{$shortcode}_{$default}", 'readonly' => 'readonly="readonly"', 'name_text' => $default, 'control_cells' => $control_cells, 'Styles' => $definition['label'], 'value_name' => "mla_style_templates_value[{$shortcode}][{$default}]", 'value_id' => "mla_style_templates_value_{$shortcode}_{$default}", 'value_text' => esc_textarea($value), 'value_help' => $definition['help']);
                 $style_options_list .= MLAData::mla_parse_template(self::$page_template_array['mla-gallery-style'], $template_values);
             }
             // $value
         }
         // foreach default
         foreach ($templates as $name => $value) {
             $slug = sanitize_title($name);
             if (in_array($name, $definition['default_names'])) {
                 continue;
                 // already handled above
             }
             $template_values = array('name' => "mla_style_templates_delete[{$shortcode}][{$slug}]", 'id' => "mla_style_templates_delete_{$shortcode}_{$slug}", 'value' => __('Delete this template', 'media-library-assistant'), 'help' => __('Check the box to delete this template when you press Update at the bottom of the page.', 'media-library-assistant'));
             $control_cells = MLAData::mla_parse_template(self::$page_template_array['mla-gallery-delete'], $template_values);
             $template_values = array('Name' => __('Name', 'media-library-assistant'), 'name_name' => "mla_style_templates_name[{$shortcode}][{$slug}]", 'name_id' => "mla_style_templates_name_{$shortcode}_{$slug}", 'readonly' => '', 'name_text' => $slug, 'control_cells' => $control_cells, 'Styles' => $definition['label'], 'value_name' => "mla_style_templates_value[{$shortcode}][{$slug}]", 'value_id' => "mla_style_templates_value_{$shortcode}_{$slug}", 'value_text' => esc_textarea($value), 'value_help' => $definition['help']);
             $style_options_list .= MLAData::mla_parse_template(self::$page_template_array['mla-gallery-style'], $template_values);
         }
         // foreach $templates
         /*
          * Add blank style template for additions
          */
         if (!empty($value)) {
             $template_values = array('help' => __('Fill in a name and styles to add a new template.', 'media-library-assistant'));
             $control_cells = MLAData::mla_parse_template(self::$page_template_array['mla-gallery-default'], $template_values);
             $template_values = array('Name' => __('Name', 'media-library-assistant'), 'name_name' => "mla_style_templates_name[{$shortcode}][blank]", 'name_id' => "mla_style_templates_name_{$shortcode}_blank", 'readonly' => '', 'name_text' => '', 'control_cells' => $control_cells, 'Styles' => $definition['label'], 'value_name' => "mla_style_templates_value[{$shortcode}][blank]", 'value_id' => "mla_style_templates_value_{$shortcode}_blank", 'value_text' => '', 'value_help' => $definition['help']);
             $style_options_list .= MLAData::mla_parse_template(self::$page_template_array['mla-gallery-style'], $template_values);
         }
         // $value
         /*
          * Compose the Styles section for this shortcode
          */
         $template_values = array('shortcode' => $shortcode, 'template_type' => 'style', 'Go to Top' => __('Go to Top', 'media-library-assistant'), 'Go to Bottom' => __('Go to Bottom', 'media-library-assistant'), 'Templates' => "[mla_{$shortcode}] " . __('Style Templates', 'media-library-assistant'), 'templates_list' => $style_options_list);
         $style_sections_list .= MLAData::mla_parse_template(self::$page_template_array['templates-list'], $template_values);
     }
     // $shortcode
     $page_values['style_sections_list'] = $style_sections_list;
     /*
      * Add markup templates; defaults go first
      */
     $markup_sections_list = '';
     foreach (MLATemplate_Support::$mla_template_definitions['markup'] as $shortcode => $definition) {
         $templates = MLATemplate_Support::mla_get_markup_templates($definition['slug']);
         $markup_options_list = '';
         $sorted_sections = array();
         foreach (MLATemplate_Support::$mla_template_definitions['markup'][$shortcode]['sections'] as $section_slug => $section_definition) {
             $sorted_sections[$section_definition['order']] = $section_definition;
             $sorted_sections[$section_definition['order']]['slug'] = $section_slug;
         }
         ksort($sorted_sections, SORT_NUMERIC);
         foreach ($definition['default_names'] as $default) {
             if (!array_key_exists($default, $templates)) {
                 continue;
             }
             $value = $templates[$default];
             if (!empty($value)) {
                 $sections_list = '';
                 foreach ($sorted_sections as $section_definition) {
                     $section_slug = $section_definition['slug'];
                     $template_values = array('Label' => $section_definition['label'], 'name' => "mla_markup_templates_sections[{$shortcode}][{$default}][{$section_slug}]", 'id' => "mla_markup_templates_name_{$shortcode}_{$default}_{$section_slug}", 'rows' => $section_definition['rows'], 'readonly' => 'readonly="readonly"', 'text' => isset($value[$section_slug]) ? esc_textarea($value[$section_slug]) : '', 'help' => $section_definition['help']);
                     $sections_list .= MLAData::mla_parse_template(self::$page_template_array['template-section'], $template_values);
                 }
                 // $section
                 $template_values = array('help' => __('This default template cannot be altered or deleted, but you can copy the markup.', 'media-library-assistant'));
                 $control_cells = MLAData::mla_parse_template(self::$page_template_array['mla-gallery-default'], $template_values);
                 $template_values = array('Name' => __('Name', 'media-library-assistant'), 'name_name' => "mla_markup_templates_name[{$shortcode}][{$default}]", 'name_id' => "mla_markup_templates_name_{$shortcode}_{$default}", 'readonly' => 'readonly="readonly"', 'name_text' => $default, 'control_cells' => $control_cells, 'sections_list' => $sections_list);
                 $markup_options_list .= MLAData::mla_parse_template(self::$page_template_array['mla-gallery-markup'], $template_values);
             }
             // $value
         }
         // foreach default
         foreach ($templates as $name => $value) {
             $slug = sanitize_title($name);
             if (in_array($name, $definition['default_names'])) {
                 continue;
                 // already handled above
             }
             if (!empty($value)) {
                 $sections_list = '';
                 foreach ($sorted_sections as $section_definition) {
                     $section_slug = $section_definition['slug'];
                     $template_values = array('Label' => $section_definition['label'], 'name' => "mla_markup_templates_sections[{$shortcode}][{$name}][{$section_slug}]", 'id' => "mla_markup_templates_name_{$shortcode}_{$name}_{$section_slug}", 'rows' => $section_definition['rows'], 'readonly' => '', 'text' => isset($value[$section_slug]) ? esc_textarea($value[$section_slug]) : '', 'help' => $section_definition['help']);
                     $sections_list .= MLAData::mla_parse_template(self::$page_template_array['template-section'], $template_values);
                 }
                 // $section
                 $template_values = array('name' => "mla_markup_templates_delete[{$shortcode}][{$slug}]", 'id' => "mla_markup_templates_delete_{$shortcode}_{$slug}", 'value' => __('Delete this template', 'media-library-assistant'), 'help' => __('Check the box to delete this template when you press Update at the bottom of the page.', 'media-library-assistant'));
                 $control_cells = MLAData::mla_parse_template(self::$page_template_array['mla-gallery-delete'], $template_values);
                 $template_values = array('Name' => __('Name', 'media-library-assistant'), 'name_name' => "mla_markup_templates_name[{$shortcode}][{$slug}]", 'name_id' => "mla_markup_templates_name_{$shortcode}_{$slug}", 'readonly' => '', 'name_text' => $slug, 'control_cells' => $control_cells, 'sections_list' => $sections_list);
                 $markup_options_list .= MLAData::mla_parse_template(self::$page_template_array['mla-gallery-markup'], $template_values);
             }
             // $value
         }
         // foreach $templates
         /*
          * Add blank markup template for additions
          */
         if (!empty($value)) {
             $template_values = array('help' => __('Fill in a name and markup to add a new template.', 'media-library-assistant'));
             $control_cells = MLAData::mla_parse_template(self::$page_template_array['mla-gallery-default'], $template_values);
             $sections_list = '';
             foreach ($sorted_sections as $section_definition) {
                 $section_slug = $section_definition['slug'];
                 $template_values = array('Label' => $section_definition['label'], 'name' => "mla_markup_templates_sections[{$shortcode}][blank][{$section_slug}]", 'id' => "mla_markup_templates_name_{$shortcode}_blank_{$section_slug}", 'rows' => $section_definition['rows'], 'readonly' => '', 'text' => '', 'help' => $section_definition['help']);
                 $sections_list .= MLAData::mla_parse_template(self::$page_template_array['template-section'], $template_values);
             }
             // $section
             $template_values = array('Name' => __('Name', 'media-library-assistant'), 'name_name' => "mla_markup_templates_name[{$shortcode}][blank]", 'name_id' => "mla_markup_templates_name_{$shortcode}_blank", 'name_text' => '', 'control_cells' => $control_cells, 'sections_list' => $sections_list);
             $markup_options_list .= MLAData::mla_parse_template(self::$page_template_array['mla-gallery-markup'], $template_values);
         }
         // $value
         /*
          * Compose the Markup section for this shortcode
          */
         $template_values = array('shortcode' => $shortcode, 'template_type' => 'markup', 'Go to Top' => __('Go to Top', 'media-library-assistant'), 'Go to Bottom' => __('Go to Bottom', 'media-library-assistant'), 'Templates' => "[mla_{$shortcode}] " . __('Markup Templates', 'media-library-assistant'), 'templates_list' => $markup_options_list);
         $markup_sections_list .= MLAData::mla_parse_template(self::$page_template_array['templates-list'], $template_values);
     }
     // $shortcode
     $page_values['markup_sections_list'] = $markup_sections_list;
     $page_content['body'] = MLAData::mla_parse_template(self::$page_template_array['mla-gallery-tab'], $page_values);
     return $page_content;
 }