/**
  * Adds Custom Field support to the Edit Media screen.
  * Declared public because it is an action.
  *
  * @since 0.80
  *
  * @return	void	echoes the HTML markup for the label and value
  */
 public static function mla_admin_init_action()
 {
     static $mc_att_category_metabox = array();
     /*
      * Enable the enhanced "Media Categories" searchable metaboxes for hiearchical taxonomies
      */
     if (class_exists('Media_Categories') && ('checked' == MLAOptions::mla_get_option(MLAOptions::MLA_MEDIA_MODAL_DETAILS_CATEGORY_METABOX) || 'checked' == MLAOptions::mla_get_option(MLAOptions::MLA_MEDIA_MODAL_DETAILS_TAG_METABOX))) {
         $taxonomies = get_taxonomies(array('show_ui' => true), 'objects');
         foreach ($taxonomies as $key => $value) {
             if (MLAOptions::mla_taxonomy_support($key)) {
                 if ($value->hierarchical) {
                     if ('checked' == MLAOptions::mla_get_option(MLAOptions::MLA_MEDIA_MODAL_DETAILS_CATEGORY_METABOX)) {
                         $mc_att_category_metabox[] = new Media_Categories($key);
                     }
                 } else {
                     if ('checked' == MLAOptions::mla_get_option(MLAOptions::MLA_MEDIA_MODAL_DETAILS_TAG_METABOX)) {
                         $mc_att_category_metabox[] = new Media_Categories($key);
                     }
                 }
                 // flat
             }
             // is supported
         }
         // foreach
     }
     // class_exists
     add_post_type_support('attachment', 'custom-fields');
 }
Ejemplo n.º 2
0
 /**
  * Registers Attachment Categories and Attachment Tags custom taxonomies, adds taxonomy-related filters
  *
  * @since 0.1
  *
  * @return	void
  */
 private static function _build_taxonomies()
 {
     if (MLAOptions::mla_taxonomy_support('attachment_category')) {
         $labels = array('name' => _x('Att. Categories', 'taxonomy general name'), 'singular_name' => _x('Att. Category', 'taxonomy singular name'), 'search_items' => __('Search Att. Categories'), 'all_items' => __('All Att. Categories'), 'parent_item' => __('Parent Att. Category'), 'parent_item_colon' => __('Parent Att. Category:'), 'edit_item' => __('Edit Att. Category'), 'update_item' => __('Update Att. Category'), 'add_new_item' => __('Add New Att. Category'), 'new_item_name' => __('New Att. Category Name'), 'menu_name' => __('Att. Category'));
         register_taxonomy('attachment_category', array('attachment'), array('hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'query_var' => true, 'rewrite' => true));
     }
     if (MLAOptions::mla_taxonomy_support('attachment_tag')) {
         $labels = array('name' => _x('Att. Tags', 'taxonomy general name'), 'singular_name' => _x('Att. Tag', 'taxonomy singular name'), 'search_items' => __('Search Att. Tags'), 'all_items' => __('All Att. Tags'), 'parent_item' => __('Parent Att. Tag'), 'parent_item_colon' => __('Parent Att. Tag:'), 'edit_item' => __('Edit Att. Tag'), 'update_item' => __('Update Att. Tag'), 'add_new_item' => __('Add New Att. Tag'), 'new_item_name' => __('New Att. Tag Name'), 'menu_name' => __('Att. Tag'));
         register_taxonomy('attachment_tag', array('attachment'), array('hierarchical' => false, 'labels' => $labels, 'show_ui' => true, 'update_count_callback' => '_update_post_term_count', 'query_var' => true, 'rewrite' => true));
     }
     $taxonomies = get_taxonomies(array('show_ui' => true), 'names');
     foreach ($taxonomies as $tax_name) {
         if (MLAOptions::mla_taxonomy_support($tax_name)) {
             register_taxonomy_for_object_type($tax_name, 'attachment');
             if ('checked' == MLAOptions::mla_get_option('attachments_column')) {
                 add_filter("manage_edit-{$tax_name}_columns", 'MLAObjects::mla_taxonomy_get_columns_filter', 10, 1);
                 // $columns
                 add_filter("manage_{$tax_name}_custom_column", 'MLAObjects::mla_taxonomy_column_filter', 10, 3);
                 // $place_holder, $column_name, $tag->term_id
             }
             // option is checked
         }
         // taxonomy support
     }
     // foreach
 }
Ejemplo n.º 3
0
 /**
  * Initialization function, similar to __construct()
  *
  * @since 0.60
  *
  * @return	void
  */
 public static function initialize()
 {
     MLATest::$wp_3dot5 = version_compare(get_bloginfo('version'), '3.5.0', '>=') && version_compare(get_bloginfo('version'), '3.5.99', '<=');
     MLATest::$wp_4dot3_plus = version_compare(get_bloginfo('version'), '4.2.99', '>=');
     /*
      * This is the earliest effective place to change error_reporting
      */
     //error_reporting( E_ALL | E_STRICT | E_DEPRECATED | E_USER_DEPRECATED | E_USER_ERROR | E_USER_WARNING );
     //error_reporting( E_ALL | E_STRICT );
     MLA::$original_php_reporting = sprintf('0x%1$04X', error_reporting());
     $php_reporting = trim(MLAOptions::mla_get_option(MLAOptions::MLA_DEBUG_REPLACE_PHP_REPORTING));
     if (!empty($php_reporting)) {
         @error_reporting(0 + $php_reporting);
     }
     /*
      * This is the earliest effective place to localize values in other plugin components
      */
     MLAOptions::mla_localize_option_definitions_array();
     MLASettings::mla_localize_tablist();
     MLA_List_Table::mla_localize_default_columns_array();
     MLA_Upload_List_Table::mla_localize_default_columns_array();
     MLA_Upload_Optional_List_Table::mla_localize_default_columns_array();
     MLA_View_List_Table::mla_localize_default_columns_array();
 }
 /**
  * Parses shortcode parameters and returns the gallery objects
  *
  * @since .50
  *
  * @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
      */
     MLAData::$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;
         }
     }
     /*
     		 * 'RAND' is not documented in the codex, but is present in the code.
     		 * CODE REMOVED in WordPress 4.1
     		 * /
     		if ( 'RAND' == strtoupper( $arguments['order'] ) ) {
     			$arguments['orderby'] = 'none';
     			unset( $arguments['order'] );
     		} // */
     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)) {
                     MLAData::$search_parameters[$key] = true;
                 } else {
                     MLAData::$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)) {
                     MLAData::$search_parameters[$key] = 'OR';
                 } else {
                     MLAData::$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)) {
                     MLAData::$search_parameters[$key] = $value;
                     if (!$children_ok) {
                         $use_children = false;
                     }
                 }
                 unset($arguments[$key]);
                 break;
             case 's':
                 MLAData::$search_parameters['s'] = $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', 'MLAShortcodes::mla_shortcode_query_posts_clauses_filter', 0x7fffffff, 1);
         add_filter('posts_clauses_request', 'MLAShortcodes::mla_shortcode_query_posts_clauses_request_filter', 0x7fffffff, 1);
     }
     add_filter('posts_join', 'MLAShortcodes::mla_shortcode_query_posts_join_filter', 0x7fffffff, 1);
     add_filter('posts_where', 'MLAShortcodes::mla_shortcode_query_posts_where_filter', 0x7fffffff, 1);
     add_filter('posts_orderby', 'MLAShortcodes::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(MLAData::$search_parameters['mla_terms_phrases']) && empty(MLAData::$search_parameters['s'])) {
         MLAData::$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(MLAData::$search_parameters['mla_terms_taxonomies'])) {
             MLAData::$search_parameters['mla_terms_search']['taxonomies'] = MLAOptions::mla_supported_taxonomies('term-search');
         } else {
             MLAData::$search_parameters['mla_terms_search']['taxonomies'] = array_filter(array_map('trim', explode(',', MLAData::$search_parameters['mla_terms_taxonomies'])));
         }
         if (!empty(MLAData::$search_parameters['mla_terms_phrases'])) {
             MLAData::$search_parameters['mla_terms_search']['phrases'] = MLAData::$search_parameters['mla_terms_phrases'];
             if (empty(MLAData::$search_parameters['mla_phrase_connector'])) {
                 MLAData::$search_parameters['mla_terms_search']['radio_phrases'] = 'AND';
             } else {
                 MLAData::$search_parameters['mla_terms_search']['radio_phrases'] = MLAData::$search_parameters['mla_phrase_connector'];
             }
             if (empty(MLAData::$search_parameters['mla_term_connector'])) {
                 MLAData::$search_parameters['mla_terms_search']['radio_terms'] = 'OR';
             } else {
                 MLAData::$search_parameters['mla_terms_search']['radio_terms'] = MLAData::$search_parameters['mla_phrase_connector'];
             }
         }
         unset(MLAData::$search_parameters['mla_terms_phrases']);
         unset(MLAData::$search_parameters['mla_terms_taxonomies']);
         unset(MLAData::$search_parameters['mla_phrase_connector']);
         unset(MLAData::$search_parameters['mla_term_connector']);
         if (empty(MLAData::$search_parameters['mla_search_fields'])) {
             MLAData::$search_parameters['mla_search_fields'] = array('title', 'content');
         } else {
             MLAData::$search_parameters['mla_search_fields'] = array_filter(array_map('trim', explode(',', MLAData::$search_parameters['mla_search_fields'])));
             MLAData::$search_parameters['mla_search_fields'] = array_intersect(array('title', 'content', 'excerpt', 'name', 'terms'), MLAData::$search_parameters['mla_search_fields']);
             /*
              * Look for keyword search including 'terms' 
              */
             foreach (MLAData::$search_parameters['mla_search_fields'] as $index => $field) {
                 if ('terms' == $field) {
                     if (isset(MLAData::$search_parameters['mla_terms_search']['phrases'])) {
                         /*
                          * The Terms Search overrides any terms-based keyword search for now; too complicated.
                          */
                         unset(MLAData::$search_parameters['mla_search_fields'][$index]);
                     } else {
                         MLAData::$search_parameters['mla_search_taxonomies'] = MLAData::$search_parameters['mla_terms_search']['taxonomies'];
                         unset(MLAData::$search_parameters['mla_terms_search']['taxonomies']);
                     }
                 }
                 // terms in search fields
             }
         }
         // mla_search_fields present
         if (empty(MLAData::$search_parameters['mla_search_connector'])) {
             MLAData::$search_parameters['mla_search_connector'] = 'AND';
         }
         if (empty(MLAData::$search_parameters['sentence'])) {
             MLAData::$search_parameters['sentence'] = false;
         }
         if (empty(MLAData::$search_parameters['exact'])) {
             MLAData::$search_parameters['exact'] = false;
         }
         MLAData::$search_parameters['debug'] = self::$mla_debug ? 'shortcode' : 'none';
         add_filter('posts_search', 'MLAData::mla_query_posts_search_filter', 10, 2);
         add_filter('posts_groupby', 'MLAData::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 />';
             }
             MLA::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 />';
             }
             MLA::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');
     }
     self::$mla_gallery_wp_query_object = new WP_Query();
     $attachments = self::$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'] = self::$mla_gallery_wp_query_object->found_posts;
     }
     if (!empty(MLAData::$search_parameters)) {
         remove_filter('posts_search', 'MLAData::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', 'MLAShortcodes::mla_shortcode_query_posts_join_filter', 0x7fffffff);
     remove_filter('posts_where', 'MLAShortcodes::mla_shortcode_query_posts_where_filter', 0x7fffffff);
     remove_filter('posts_orderby', 'MLAShortcodes::mla_shortcode_query_posts_orderby_filter', 0x7fffffff);
     if (self::$mla_debug) {
         remove_filter('posts_clauses', 'MLAShortcodes::mla_shortcode_query_posts_clauses_filter', 0x7fffffff);
         remove_filter('posts_clauses_request', 'MLAShortcodes::mla_shortcode_query_posts_clauses_request_filter', 0x7fffffff);
         MLA::mla_debug_add('<strong>' . __('mla_debug query', 'media-library-assistant') . '</strong> = ' . var_export($query_arguments, true));
         MLA::mla_debug_add('<strong>' . __('mla_debug request', 'media-library-assistant') . '</strong> = ' . var_export(self::$mla_gallery_wp_query_object->request, true));
         MLA::mla_debug_add('<strong>' . __('mla_debug query_vars', 'media-library-assistant') . '</strong> = ' . var_export(self::$mla_gallery_wp_query_object->query_vars, true));
         MLA::mla_debug_add('<strong>' . __('mla_debug post_count', 'media-library-assistant') . '</strong> = ' . var_export(self::$mla_gallery_wp_query_object->post_count, true));
     }
     self::$mla_gallery_wp_query_object = NULL;
     return $attachments;
 }
 /**
  * Add hidden fields with the data for use in the inline editor
  *
  * @since 0.20
  * 
  * @param	object	A singular attachment (post) object
  *
  * @return	string	HTML <div> with row data
  */
 private function _build_inline_data($item)
 {
     $inline_data = "\r\n" . '<div class="hidden" id="inline_' . $item->ID . "\">\r\n";
     $inline_data .= '	<div class="post_title">' . esc_attr($item->post_title) . "</div>\r\n";
     $inline_data .= '	<div class="post_name">' . esc_attr($item->post_name) . "</div>\r\n";
     $inline_data .= '	<div class="post_excerpt">' . esc_attr($item->post_excerpt) . "</div>\r\n";
     $inline_data .= '	<div class="post_content">' . esc_attr($item->post_content) . "</div>\r\n";
     if (!empty($item->mla_wp_attachment_metadata)) {
         if (isset($item->mla_wp_attachment_image_alt)) {
             $inline_data .= '	<div class="image_alt">' . esc_attr($item->mla_wp_attachment_image_alt) . "</div>\r\n";
         } else {
             $inline_data .= '	<div class="image_alt">' . "</div>\r\n";
         }
     }
     $inline_data .= '	<div class="post_parent">' . $item->post_parent . "</div>\r\n";
     $inline_data .= '	<div class="menu_order">' . $item->menu_order . "</div>\r\n";
     $inline_data .= '	<div class="post_author">' . $item->post_author . "</div>\r\n";
     $custom_fields = MLAOptions::mla_custom_field_support('quick_edit');
     $custom_fields = array_merge($custom_fields, MLAOptions::mla_custom_field_support('bulk_edit'));
     foreach ($custom_fields as $slug => $label) {
         $value = get_metadata('post', $item->ID, $label, true);
         $inline_data .= '	<div class="' . $slug . '">' . esc_html($value) . "</div>\r\n";
     }
     $taxonomies = get_object_taxonomies('attachment', 'objects');
     foreach ($taxonomies as $tax_name => $tax_object) {
         if ($tax_object->hierarchical && $tax_object->show_ui && MLAOptions::mla_taxonomy_support($tax_name, 'quick-edit')) {
             $inline_data .= '	<div class="mla_category" id="' . $tax_name . '_' . $item->ID . '">' . implode(',', wp_get_object_terms($item->ID, $tax_name, array('fields' => 'ids'))) . "</div>\r\n";
         } elseif ($tax_object->show_ui && MLAOptions::mla_taxonomy_support($tax_name, 'quick-edit')) {
             $inline_data .= '	<div class="mla_tags" id="' . $tax_name . '_' . $item->ID . '">' . esc_html(str_replace(',', ', ', get_terms_to_edit($item->ID, $tax_name))) . "</div>\r\n";
         }
     }
     $inline_data .= "</div>\r\n";
     return $inline_data;
 }
Ejemplo n.º 6
0
 /**
  * Extra controls to be displayed between bulk actions and pagination
  *
  * Modeled after class-wp-posts-list-table.php in wp-admin/includes.
  *
  * @since 0.1
  * 
  * @param	string	'top' or 'bottom', i.e., above or below the table rows
  *
  * @return	array	Contains all the bulk actions: 'slugs'=>'Visible Titles'
  */
 function extra_tablenav($which)
 {
     echo '<div class="alignleft actions">';
     if ('top' == $which) {
         $this->months_dropdown('attachment');
         echo self::mla_get_taxonomy_filter_dropdown(isset($_REQUEST['mla_filter_term']) ? $_REQUEST['mla_filter_term'] : 0);
         submit_button(__('Filter', 'media-library-assistant'), 'secondary', 'mla_filter', false, array('id' => 'post-query-submit'));
         $term_search_taxonomies = MLAOptions::mla_supported_taxonomies('term-search');
         if (!empty($term_search_taxonomies)) {
             submit_button(__('Terms Search', 'media-library-assistant'), 'secondary', 'mla_filter', false, array('id' => 'mla-terms-search-open', 'onclick' => 'mlaTaxonomy.termsSearch.open()'));
         }
     }
     if (self::mla_submenu_arguments(true) != self::mla_submenu_arguments(false)) {
         submit_button(__('Clear Filter-by', 'media-library-assistant'), 'button apply', 'clear_filter_by', false);
     }
     if ($this->is_trash && current_user_can('edit_others_posts')) {
         submit_button(__('Empty Trash', 'media-library-assistant'), 'button apply', 'delete_all', false);
     }
     echo '</div>';
 }
Ejemplo n.º 7
0
 /**
  * Builds the $mla_galleries or $galleries array
  *
  * @since 0.70
  *
  * @param	string name of the gallery's cache/option variable
  * @param	array by reference to the private static galleries array variable
  * @param	string the shortcode to be searched for and processed
  * @param	boolean true to exclude revisions from the search
  *
  * @return	boolean true if the galleries array is not empty
  */
 private static function _build_mla_galleries($option_name, &$galleries_array, $shortcode, $exclude_revisions)
 {
     global $wpdb, $post;
     if (is_array($galleries_array)) {
         if (!empty($galleries_array)) {
             return true;
         } else {
             return false;
         }
     }
     $option_value = MLAOptions::mla_get_option($option_name);
     if ('disabled' == $option_value) {
         return false;
     } elseif ('cached' == $option_value) {
         $galleries_array = get_transient(MLA_OPTION_PREFIX . 't_' . $option_name);
         if (is_array($galleries_array)) {
             if (!empty($galleries_array)) {
                 return true;
             } else {
                 return false;
             }
         } else {
             $galleries_array = NULL;
         }
     }
     // cached
     /*
      * $galleries_array is null, so build the array
      */
     $galleries_array = array();
     if ($exclude_revisions) {
         $exclude_revisions = "(post_type <> 'revision') AND ";
     } else {
         $exclude_revisions = '';
     }
     $like = like_escape($shortcode);
     $results = $wpdb->get_results($wpdb->prepare("\r\n\t\t\t\tSELECT ID, post_type, post_title, post_content\r\n\t\t\t\tFROM {$wpdb->posts}\r\n\t\t\t\tWHERE {$exclude_revisions}(\r\n\t\t\t\t\tCONVERT(`post_content` USING utf8 )\r\n\t\t\t\t\tLIKE %s)\r\n\t\t\t\t", "%{$like}%"));
     if (empty($results)) {
         return false;
     }
     foreach ($results as $result) {
         $count = preg_match_all("/\\{$shortcode}([^\\]]*)\\]/", $result->post_content, $matches, PREG_PATTERN_ORDER);
         if ($count) {
             $result_id = $result->ID;
             $galleries_array[$result_id]['parent_title'] = $result->post_title;
             $galleries_array[$result_id]['parent_type'] = $result->post_type;
             $galleries_array[$result_id]['results'] = array();
             $galleries_array[$result_id]['galleries'] = array();
             $instance = 0;
             foreach ($matches[1] as $index => $match) {
                 /*
                  * Filter out shortcodes that are not an exact match
                  */
                 if (empty($match) || ' ' == substr($match, 0, 1)) {
                     $instance++;
                     $galleries_array[$result_id]['galleries'][$instance]['query'] = trim($matches[1][$index]);
                     $galleries_array[$result_id]['galleries'][$instance]['results'] = array();
                     $post = $result;
                     // set global variable for mla_gallery_shortcode
                     $attachments = MLAShortcodes::mla_get_shortcode_attachments($result_id, $galleries_array[$result_id]['galleries'][$instance]['query']);
                     if (is_string($attachments)) {
                         trigger_error(htmlentities(sprintf('(%1$s) %2$s (ID %3$d) query "%4$s" failed, returning "%5$s"', $result->post_type, $result->post_title, $result->ID, $galleries_array[$result_id]['galleries'][$instance]['query'], $attachments)), E_USER_WARNING);
                     } elseif (!empty($attachments)) {
                         foreach ($attachments as $attachment) {
                             $galleries_array[$result_id]['results'][$attachment->ID] = $attachment->ID;
                             $galleries_array[$result_id]['galleries'][$instance]['results'][] = $attachment->ID;
                         }
                     }
                     // foreach $attachment
                 }
                 // exact match
             }
             // foreach $match
         }
         // if $count
     }
     // foreach $result
     /*
      * Maybe cache the results
      */
     if ('cached' == $option_value) {
         set_transient(MLA_OPTION_PREFIX . 't_' . $option_name, $galleries_array, 900);
         // fifteen minutes
     }
     return true;
 }
Ejemplo n.º 8
0
 /**
  * Render and manage iptc/exif support options
  *
  * @since 1.00
  * @uses $mla_option_templates contains row and table templates
  *
  * @param	string 	'render', 'update', 'delete', or 'reset'
  * @param	string 	option name, e.g., 'iptc_exif_mapping'
  * @param	array 	option parameters
  * @param	array 	Optional. null (default) for 'render' else option data, e.g., $_REQUEST
  *
  * @return	string	HTML table row markup for 'render' else message(s) reflecting the results of the operation.
  */
 public static function mla_iptc_exif_option_handler($action, $key, $value, $args = null)
 {
     $current_values = self::mla_get_option('iptc_exif_mapping');
     switch ($action) {
         case 'render':
             switch ($key) {
                 case 'iptc_exif_standard_mapping':
                     $row_template = self::$mla_option_templates['iptc-exif-standard-row'];
                     $table_rows = '';
                     foreach ($current_values['standard'] as $row_name => $row_value) {
                         $row_values = array('key' => $row_name, 'name' => $row_value['name'], 'iptc_field_options' => self::_compose_iptc_option_list($row_value['iptc_value']), 'exif_size' => self::MLA_EXIF_SIZE, 'exif_text' => $row_value['exif_value'], 'iptc_selected' => '', 'exif_selected' => '', 'keep_selected' => '', 'replace_selected' => '');
                         if ($row_value['iptc_first']) {
                             $row_values['iptc_selected'] = 'selected="selected"';
                         } else {
                             $row_values['exif_selected'] = 'selected="selected"';
                         }
                         if ($row_value['keep_existing']) {
                             $row_values['keep_selected'] = 'selected="selected"';
                         } else {
                             $row_values['replace_selected'] = 'selected="selected"';
                         }
                         $table_rows .= MLAData::mla_parse_template($row_template, $row_values);
                     }
                     // foreach row
                     $option_values = array('table_rows' => $table_rows, 'help' => $value['help']);
                     return MLAData::mla_parse_template(self::$mla_option_templates['iptc-exif-standard-table'], $option_values);
                 case 'iptc_exif_taxonomy_mapping':
                     $row_template = self::$mla_option_templates['iptc-exif-taxonomy-row'];
                     $select_template = self::$mla_option_templates['iptc-exif-select'];
                     $table_rows = '';
                     $taxonomies = get_taxonomies(array('show_ui' => true), 'objects');
                     foreach ($taxonomies as $row_name => $row_value) {
                         $row_values = array('key' => $row_name, 'name' => esc_html($row_value->labels->name), 'hierarchical' => (string) $row_value->hierarchical, 'iptc_field_options' => '', 'exif_size' => self::MLA_EXIF_SIZE, 'exif_text' => '', 'iptc_selected' => '', 'exif_selected' => '', 'keep_selected' => '', 'replace_selected' => '', 'parent_select' => '');
                         if (array_key_exists($row_name, $current_values['taxonomy'])) {
                             $current_value = $current_values['taxonomy'][$row_name];
                             $row_values['iptc_field_options'] = self::_compose_iptc_option_list($current_value['iptc_value']);
                             $row_values['exif_text'] = $current_value['exif_value'];
                             if ($current_value['iptc_first']) {
                                 $row_values['iptc_selected'] = 'selected="selected"';
                             } else {
                                 $row_values['exif_selected'] = 'selected="selected"';
                             }
                             if ($current_value['keep_existing']) {
                                 $row_values['keep_selected'] = 'selected="selected"';
                             } else {
                                 $row_values['replace_selected'] = 'selected="selected"';
                             }
                             if ($row_value->hierarchical) {
                                 $parent = isset($current_value['parent']) ? (int) $current_value['parent'] : 0;
                                 $select_values = array('array' => 'taxonomy', 'key' => $row_name, 'element' => 'parent', 'options' => self::_compose_parent_option_list($row_name, $parent));
                                 $row_values['parent_select'] = MLAData::mla_parse_template($select_template, $select_values);
                             }
                         } else {
                             $row_values['iptc_field_options'] = self::_compose_iptc_option_list('none');
                             $row_values['iptc_selected'] = 'selected="selected"';
                             $row_values['keep_selected'] = 'selected="selected"';
                             if ($row_value->hierarchical) {
                                 $select_values = array('array' => 'taxonomy', 'key' => $row_name, 'element' => 'parent', 'options' => self::_compose_parent_option_list($row_name, 0));
                                 $row_values['parent_select'] = MLAData::mla_parse_template($select_template, $select_values);
                             }
                         }
                         $table_rows .= MLAData::mla_parse_template($row_template, $row_values);
                     }
                     // foreach row
                     $option_values = array('table_rows' => $table_rows, 'help' => $value['help']);
                     return MLAData::mla_parse_template(self::$mla_option_templates['iptc-exif-taxonomy-table'], $option_values);
                 case 'iptc_exif_custom_mapping':
                     if (empty($current_values['custom'])) {
                         $table_rows = MLAData::mla_parse_template(self::$mla_option_templates['iptc-exif-custom-empty-row'], array('column_count' => 5));
                     } else {
                         $row_template = self::$mla_option_templates['iptc-exif-custom-rule-row'];
                         $table_rows = '';
                     }
                     /*
                      * One row for each existing rule
                      */
                     ksort($current_values['custom']);
                     foreach ($current_values['custom'] as $row_name => $current_value) {
                         $row_values = array('column_count' => 5, 'key' => $row_name, 'name' => $row_name, 'iptc_field_options' => '', 'exif_size' => self::MLA_EXIF_SIZE, 'exif_text' => '', 'iptc_selected' => '', 'exif_selected' => '', 'keep_selected' => '', 'replace_selected' => '');
                         $row_values['iptc_field_options'] = self::_compose_iptc_option_list($current_value['iptc_value']);
                         $row_values['exif_text'] = $current_value['exif_value'];
                         if ($current_value['iptc_first']) {
                             $row_values['iptc_selected'] = 'selected="selected"';
                         } else {
                             $row_values['exif_selected'] = 'selected="selected"';
                         }
                         if ($current_value['keep_existing']) {
                             $row_values['keep_selected'] = 'selected="selected"';
                         } else {
                             $row_values['replace_selected'] = 'selected="selected"';
                         }
                         $table_rows .= MLAData::mla_parse_template($row_template, $row_values);
                     }
                     // foreach existing rule
                     /*
                      * Add a row for defining a new rule, existing Custom Field
                      */
                     $row_template = self::$mla_option_templates['iptc-exif-custom-new-rule-row'];
                     $row_values = array('column_count' => 5, 'key' => self::MLA_NEW_CUSTOM_RULE, 'field_name_options' => self::_compose_custom_field_option_list('none', $current_values['custom']), 'iptc_field_options' => self::_compose_iptc_option_list('none'), 'exif_size' => self::MLA_EXIF_SIZE, 'exif_text' => '', 'iptc_selected' => 'selected="selected"', 'exif_selected' => '', 'keep_selected' => 'selected="selected"', 'replace_selected' => '');
                     $table_rows .= MLAData::mla_parse_template($row_template, $row_values);
                     /*
                      * Add a row for defining a new rule, new Custom Field
                      */
                     $row_template = self::$mla_option_templates['iptc-exif-custom-new-field-row'];
                     $row_values = array('column_count' => 5, 'key' => self::MLA_NEW_CUSTOM_FIELD, 'field_name_size' => '24', 'iptc_field_options' => self::_compose_iptc_option_list('none'), 'exif_size' => self::MLA_EXIF_SIZE, 'exif_text' => '', 'iptc_selected' => 'selected="selected"', 'exif_selected' => '', 'keep_selected' => 'selected="selected"', 'replace_selected' => '');
                     $table_rows .= MLAData::mla_parse_template($row_template, $row_values);
                     $option_values = array('table_rows' => $table_rows, 'help' => $value['help']);
                     return MLAData::mla_parse_template(self::$mla_option_templates['iptc-exif-custom-table'], $option_values);
                 default:
                     return "<br>ERROR: Render unknown custom {$key}\r\n";
             }
             // switch $key
         // switch $key
         case 'update':
         case 'delete':
             $settings_changed = false;
             $messages = '';
             switch ($key) {
                 case 'iptc_exif_standard_mapping':
                     $results = self::_update_iptc_exif_standard_mapping($current_values, $args);
                     $messages .= $results['message'];
                     $current_values = $results['values'];
                     $settings_changed = $results['changed'];
                     break;
                 case 'iptc_exif_taxonomy_mapping':
                     $results = self::_update_iptc_exif_taxonomy_mapping($current_values, $args);
                     $messages .= $results['message'];
                     $current_values = $results['values'];
                     $settings_changed = $results['changed'];
                     break;
                 case 'iptc_exif_custom_mapping':
                     $results = self::_update_iptc_exif_custom_mapping($current_values, $args);
                     $messages .= $results['message'];
                     $current_values = $results['values'];
                     $settings_changed = $results['changed'];
                     break;
                 case 'iptc_exif_mapping':
                     $results = self::_update_iptc_exif_standard_mapping($current_values, $args);
                     $messages .= $results['message'];
                     $current_values = $results['values'];
                     $settings_changed = $results['changed'];
                     $results = self::_update_iptc_exif_taxonomy_mapping($current_values, $args);
                     $messages .= $results['message'];
                     $current_values = $results['values'];
                     $settings_changed |= $results['changed'];
                     $results = self::_update_iptc_exif_custom_mapping($current_values, $args);
                     $messages .= $results['message'];
                     $current_values = $results['values'];
                     $settings_changed |= $results['changed'];
                     break;
                 default:
                     return "<br>ERROR: Update/delete unknown custom {$key}\r\n";
             }
             // switch $key
             if ($settings_changed) {
                 $settings_changed = MLAOptions::mla_update_option('iptc_exif_mapping', $current_values);
                 if ($settings_changed) {
                     $results = "IPTC/EXIF mapping settings updated.\r\n";
                 } else {
                     $results = "ERROR: IPTC/EXIF settings update failed.\r\n";
                 }
             } else {
                 $results = "IPTC/EXIF no mapping changes detected.\r\n";
             }
             return $results . $messages;
         case 'reset':
             switch ($key) {
                 case 'iptc_exif_standard_mapping':
                     $current_values['standard'] = self::$mla_option_definitions['iptc_exif_mapping']['std']['standard'];
                     $settings_changed = MLAOptions::mla_update_option('iptc_exif_mapping', $current_values);
                     if ($settings_changed) {
                         return "IPTC/EXIF Standard field settings saved.\r\n";
                     } else {
                         return "ERROR: IPTC/EXIF Standard field settings update failed.\r\n";
                     }
                 case 'iptc_exif_taxonomy_mapping':
                     $current_values['taxonomy'] = self::$mla_option_definitions['iptc_exif_mapping']['std']['taxonomy'];
                     $settings_changed = MLAOptions::mla_update_option('iptc_exif_mapping', $current_values);
                     if ($settings_changed) {
                         return "IPTC/EXIF Taxonomy term settings saved.\r\n";
                     } else {
                         return "ERROR: IPTC/EXIF Taxonomy term settings update failed.\r\n";
                     }
                 case 'iptc_exif_custom_mapping':
                     $current_values['custom'] = self::$mla_option_definitions['iptc_exif_mapping']['std']['custom'];
                     $settings_changed = MLAOptions::mla_update_option('iptc_exif_mapping', $current_values);
                     if ($settings_changed) {
                         return "IPTC/EXIF Custom field settings saved.\r\n";
                     } else {
                         return "ERROR: IPTC/EXIF Custom field settings reset failed.\r\n";
                     }
                 case 'iptc_exif_mapping':
                     self::mla_delete_option($key);
                     return "<br>Reset custom {$key}\r\n";
                 default:
                     return "<br>ERROR: Reset unknown custom {$key}\r\n";
             }
             // switch $key
         // switch $key
         default:
             return "<br>ERROR: Custom {$key} unknown action: {$action}\r\n";
     }
     // switch $action
 }
 /**
  * Filter the MLA_List_Table columns
  *
  * Inserts the language columns just after the item thumbnail column.
  * Defined as static because it is called before the List_Table object is created.
  * Added as a filter when the file is loaded.
  *
  * @since 2.11
  *
  * @param	array	$columns An array of columns.
  *					format: column_slug => Column Label
  *
  * @return	array	updated array of columns.
  */
 public static function mla_list_table_get_columns($columns)
 {
     global $sitepress, $wpdb;
     if (is_null(self::$language_columns) && $sitepress->is_translated_post_type('attachment')) {
         /*
          * Build language management columns
          */
         $show_language = 'checked' == MLAOptions::mla_get_option('language_column', false, false, MLA_WPML::$mla_language_option_definitions);
         $current_language = $sitepress->get_current_language();
         $languages = $sitepress->get_active_languages();
         $view_status = isset($_REQUEST['status']) ? $_REQUEST['status'] : '';
         if (1 < count($languages) && $view_status != 'trash') {
             $show_translations = 'checked' == MLAOptions::mla_get_option('translations_column', false, false, MLA_WPML::$mla_language_option_definitions);
         } else {
             $show_translations = false;
         }
         self::$language_columns = array();
         if ($show_language && 'all' == $current_language) {
             self::$language_columns['language'] = __('Language', 'wpml-media');
         }
         if ($show_translations) {
             $language_codes = array();
             foreach ($languages as $language) {
                 if ($current_language != $language['code']) {
                     $language_codes[] = $language['code'];
                 }
             }
             $results = $wpdb->get_results($wpdb->prepare("\r\r\n\t\t\t\t\tSELECT f.lang_code, f.flag, f.from_template, l.name\r\r\n\t\t\t\t\tFROM {$wpdb->prefix}icl_flags f\r\r\n\t\t\t\t\t\tJOIN {$wpdb->prefix}icl_languages_translations l ON f.lang_code = l.language_code\r\r\n\t\t\t\t\tWHERE l.display_language_code = %s AND f.lang_code IN(" . wpml_prepare_in($language_codes) . ")", $sitepress->get_admin_language()));
             $wp_upload_dir = wp_upload_dir();
             foreach ($results as $result) {
                 if ($result->from_template) {
                     $flag_path = $wp_upload_dir['baseurl'] . '/flags/';
                 } else {
                     $flag_path = ICL_PLUGIN_URL . '/res/flags/';
                 }
                 $flags[$result->lang_code] = '<img src="' . $flag_path . $result->flag . '" width="18" height="12" alt="' . $result->name . '" title="' . $result->name . '" />';
             }
             $flags_column = '';
             foreach ($languages as $language) {
                 if (isset($flags[$language['code']])) {
                     $flags_column .= $flags[$language['code']];
                 }
             }
             self::$language_columns['icl_translations'] = $flags_column;
         }
         // multi-language not trash
     }
     // add columns
     if (!empty(self::$language_columns)) {
         $end = array_slice($columns, 2);
         $columns = array_slice($columns, 0, 2);
         $columns = array_merge($columns, self::$language_columns, $end);
     }
     return $columns;
 }
Ejemplo n.º 10
0
 /**
  * Process bulk action for one or more attachments
  *
  * @since 2.00
  *
  * @param	string	Bulk action slug: delete, edit, restore, trash, custom action
  * @param	array	Form elements, e.g., from $_REQUEST
  *
  * @return	array	messages and page content: ( 'message', 'body', 'unchanged', 'success', 'failure', 'item_results' )
  */
 public static function mla_process_bulk_action($bulk_action, $request = NULL)
 {
     $page_content = array('message' => '', 'body' => '', 'unchanged' => 0, 'success' => 0, 'failure' => 0, 'item_results' => array());
     $custom_field_map = MLACore::mla_custom_field_support('bulk_edit');
     /*
      * do_cleanup will remove the bulk edit elements from the $_REQUEST super array.
      * It is passed in the $request so it can be filtered.
      */
     if (NULL == $request) {
         $request = $_REQUEST;
         $request['mla_bulk_action_do_cleanup'] = true;
     } else {
         $request['mla_bulk_action_do_cleanup'] = false;
     }
     $request = apply_filters('mla_list_table_bulk_action_initial_request', $request, $bulk_action, $custom_field_map);
     MLACore::mla_debug_add('mla_process_bulk_action $request = ' . var_export($request, true), MLACore::MLA_DEBUG_CATEGORY_AJAX);
     if (isset($request['cb_attachment'])) {
         $item_content = apply_filters('mla_list_table_begin_bulk_action', NULL, $bulk_action);
         if (is_null($item_content)) {
             $prevent_default = false;
         } else {
             $prevent_default = isset($item_content['prevent_default']) ? $item_content['prevent_default'] : false;
         }
         if ($prevent_default) {
             if (isset($item_content['message'])) {
                 $page_content['message'] = $item_content['message'];
             }
             if (isset($item_content['body'])) {
                 $page_content['body'] = $item_content['body'];
             }
             return $page_content;
         }
         if (!empty($request['bulk_custom_field_map'])) {
             do_action('mla_begin_mapping', 'bulk_custom', NULL);
         } elseif (!empty($request['bulk_map'])) {
             do_action('mla_begin_mapping', 'bulk_iptc_exif', NULL);
         }
         foreach ($request['cb_attachment'] as $index => $post_id) {
             if (!current_user_can('edit_post', $post_id)) {
                 $page_content['message'] .= __('ERROR', 'media-library-assistant') . ': ' . __('You are not allowed to edit Attachment: ', 'media-library-assistant') . $post_id . '<br>';
                 continue;
             }
             $request = apply_filters('mla_list_table_bulk_action_item_request', $request, $bulk_action, $post_id, $custom_field_map);
             $item_content = apply_filters('mla_list_table_bulk_action', NULL, $bulk_action, $post_id);
             if (is_null($item_content)) {
                 $prevent_default = false;
                 $custom_message = '';
             } else {
                 $prevent_default = isset($item_content['prevent_default']) ? $item_content['prevent_default'] : false;
                 $custom_message = isset($item_content['message']) ? $item_content['message'] : '';
             }
             if (!$prevent_default) {
                 switch ($bulk_action) {
                     case 'delete':
                         $item_content = self::_delete_single_item($post_id);
                         break;
                     case 'edit':
                         if (!empty($request['bulk_custom_field_map'])) {
                             $updates = MLAOptions::mla_evaluate_custom_field_mapping($post_id, 'single_attachment_mapping');
                             $item_content = MLAData::mla_update_single_item($post_id, $updates);
                             break;
                         }
                         if (!empty($request['bulk_map'])) {
                             $item = get_post($post_id);
                             $updates = MLAOptions::mla_evaluate_iptc_exif_mapping($item, 'iptc_exif_mapping');
                             $item_content = MLAData::mla_update_single_item($post_id, $updates);
                             break;
                         }
                         $new_data = self::mla_prepare_bulk_edits($post_id, $request, $custom_field_map);
                         MLACore::mla_debug_add("mla_process_bulk_action( {$post_id} ) new_data = " . var_export($new_data, true), MLACore::MLA_DEBUG_CATEGORY_AJAX);
                         $tax_input = $new_data['tax_input'];
                         $tax_action = $new_data['tax_action'];
                         unset($new_data['tax_input']);
                         unset($new_data['tax_action']);
                         $item_content = MLAData::mla_update_single_item($post_id, $new_data, $tax_input, $tax_action);
                         MLACore::mla_debug_add("mla_process_bulk_action( {$post_id} ) item_content = " . var_export($item_content, true), MLACore::MLA_DEBUG_CATEGORY_AJAX);
                         break;
                     case 'restore':
                         $item_content = self::_restore_single_item($post_id);
                         break;
                     case 'trash':
                         $item_content = self::_trash_single_item($post_id);
                         break;
                     default:
                         $item_content = apply_filters('mla_list_table_custom_bulk_action', NULL, $bulk_action, $post_id);
                         if (is_null($item_content)) {
                             $prevent_default = false;
                             /* translators: 1: ERROR tag 2: bulk action */
                             $custom_message = sprintf(__('%1$s: Unknown bulk action %2$s', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $bulk_action);
                         } else {
                             $prevent_default = isset($item_content['prevent_default']) ? $item_content['prevent_default'] : false;
                         }
                 }
                 // switch $bulk_action
             }
             // ! $prevent_default
             // Custom action can set $prevent_default, so test again.
             if (!$prevent_default) {
                 if (!empty($custom_message)) {
                     $no_changes = sprintf(__('Item %1$d, no changes detected.', 'media-library-assistant'), $post_id);
                     if ($no_changes == $item_content['message']) {
                         $item_content['message'] = $custom_message;
                     } else {
                         $item_content['message'] = $custom_message . '<br>' . $item_content['message'];
                     }
                 }
                 $page_content['item_results'][$post_id] = array('result' => 'unknown', 'message' => $item_content['message']);
                 if (!empty($item_content['message'])) {
                     $page_content['message'] .= $item_content['message'] . '<br>';
                     if (false !== strpos($item_content['message'], __('no changes detected', 'media-library-assistant'))) {
                         $page_content['unchanged'] += 1;
                         $page_content['item_results'][$post_id]['result'] = 'unchanged';
                     } elseif (false !== strpos($item_content['message'], __('ERROR', 'media-library-assistant'))) {
                         $page_content['failure'] += 1;
                         $page_content['item_results'][$post_id]['result'] = 'failure';
                     } else {
                         $page_content['success'] += 1;
                         $page_content['item_results'][$post_id]['result'] = 'success';
                     }
                 }
             }
             // ! $prevent_default
         }
         // foreach cb_attachment
         if (!empty($request['bulk_custom_field_map']) || !empty($request['bulk_map'])) {
             do_action('mla_end_mapping');
         }
         $item_content = apply_filters('mla_list_table_end_bulk_action', NULL, $bulk_action);
         if (isset($item_content['message'])) {
             $page_content['message'] .= $item_content['message'];
         }
         if (isset($item_content['body'])) {
             $page_content['body'] = $item_content['body'];
         }
         if ($request['mla_bulk_action_do_cleanup']) {
             unset($_REQUEST['post_title']);
             unset($_REQUEST['post_excerpt']);
             unset($_REQUEST['post_content']);
             unset($_REQUEST['image_alt']);
             unset($_REQUEST['comment_status']);
             unset($_REQUEST['ping_status']);
             unset($_REQUEST['post_parent']);
             unset($_REQUEST['post_author']);
             unset($_REQUEST['tax_input']);
             unset($_REQUEST['tax_action']);
             foreach (MLACore::mla_custom_field_support('bulk_edit') as $slug => $details) {
                 unset($_REQUEST[$slug]);
             }
             unset($_REQUEST['cb_attachment']);
         }
     } else {
         // isset cb_attachment
         /* translators: 1: action name, e.g., edit */
         $page_content['message'] = sprintf(__('Bulk Action %1$s - no items selected.', 'media-library-assistant'), $bulk_action);
     }
     if ($request['mla_bulk_action_do_cleanup']) {
         unset($_REQUEST['action']);
         unset($_REQUEST['bulk_custom_field_map']);
         unset($_REQUEST['bulk_map']);
         unset($_REQUEST['bulk_edit']);
         unset($_REQUEST['action2']);
     }
     return $page_content;
 }
Ejemplo n.º 11
0
 /**
  * Build the hidden row templates for inline editing (quick and bulk edit)
  *
  * inspired by inline_edit() in wp-admin\includes\class-wp-posts-list-table.php.
  *
  * @since 0.20
  *
  * @param	object	MLA List Table object
  *
  * @return	string	HTML <form> markup for hidden rows
  */
 private static function _build_inline_edit_form($MLAListTable)
 {
     $taxonomies = get_object_taxonomies('attachment', 'objects');
     $hierarchical_taxonomies = array();
     $flat_taxonomies = array();
     foreach ($taxonomies as $tax_name => $tax_object) {
         if ($tax_object->hierarchical && $tax_object->show_ui && MLAOptions::mla_taxonomy_support($tax_name, 'quick-edit')) {
             $hierarchical_taxonomies[$tax_name] = $tax_object;
         } elseif ($tax_object->show_ui && MLAOptions::mla_taxonomy_support($tax_name, 'quick-edit')) {
             $flat_taxonomies[$tax_name] = $tax_object;
         }
     }
     $page_template_array = MLAData::mla_load_template('admin-inline-edit-form.tpl');
     if (!is_array($page_template_array)) {
         /* translators: 1: ERROR tag 2: function name 3: non-array value */
         error_log(sprintf(_x('%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), 'MLA::_build_inline_edit_form', var_export($page_template_array, true)), 0);
         return '';
     }
     if ($authors = self::mla_authors_dropdown()) {
         $authors_dropdown = '              <label class="inline-edit-author">' . "\n";
         $authors_dropdown .= '                <span class="title">' . __('Author', 'media-library-assistant') . '</span>' . "\n";
         $authors_dropdown .= $authors . "\n";
         $authors_dropdown .= '              </label>' . "\n";
     } else {
         $authors_dropdown = '';
     }
     $custom_fields = '';
     foreach (MLAOptions::mla_custom_field_support('quick_edit') as $slug => $details) {
         $page_values = array('slug' => $slug, 'label' => esc_attr($details['name']));
         $custom_fields .= MLAData::mla_parse_template($page_template_array['custom_field'], $page_values);
     }
     /*
      * The middle column contains the hierarchical taxonomies, e.g., Attachment Category
      */
     $quick_middle_column = '';
     $bulk_middle_column = '';
     if (count($hierarchical_taxonomies)) {
         $quick_category_blocks = '';
         $bulk_category_blocks = '';
         foreach ($hierarchical_taxonomies as $tax_name => $tax_object) {
             if (current_user_can($tax_object->cap->assign_terms)) {
                 ob_start();
                 wp_terms_checklist(NULL, array('taxonomy' => $tax_name));
                 $tax_checklist = ob_get_contents();
                 ob_end_clean();
                 $page_values = array('tax_html' => esc_html($tax_object->labels->name), 'more' => __('more', 'media-library-assistant'), 'less' => __('less', 'media-library-assistant'), 'tax_attr' => esc_attr($tax_name), 'tax_checklist' => $tax_checklist, 'Add' => __('Add', 'media-library-assistant'), 'Remove' => __('Remove', 'media-library-assistant'), 'Replace' => __('Replace', 'media-library-assistant'));
                 $category_block = MLAData::mla_parse_template($page_template_array['category_block'], $page_values);
                 $taxonomy_options = MLAData::mla_parse_template($page_template_array['taxonomy_options'], $page_values);
                 $quick_category_blocks .= $category_block;
                 $bulk_category_blocks .= $category_block . $taxonomy_options;
             }
             // current_user_can
         }
         // foreach $hierarchical_taxonomies
         $page_values = array('category_blocks' => $quick_category_blocks);
         $quick_middle_column = MLAData::mla_parse_template($page_template_array['category_fieldset'], $page_values);
         $page_values = array('category_blocks' => $bulk_category_blocks);
         $bulk_middle_column = MLAData::mla_parse_template($page_template_array['category_fieldset'], $page_values);
     }
     // count( $hierarchical_taxonomies )
     /*
      * The right-hand column contains the flat taxonomies, e.g., Attachment Tag
      */
     $quick_right_column = '';
     $bulk_right_column = '';
     if (count($flat_taxonomies)) {
         $quick_tag_blocks = '';
         $bulk_tag_blocks = '';
         foreach ($flat_taxonomies as $tax_name => $tax_object) {
             if (current_user_can($tax_object->cap->assign_terms)) {
                 $page_values = array('tax_html' => esc_html($tax_object->labels->name), 'tax_attr' => esc_attr($tax_name), 'Add' => __('Add', 'media-library-assistant'), 'Remove' => __('Remove', 'media-library-assistant'), 'Replace' => __('Replace', 'media-library-assistant'));
                 $tag_block = MLAData::mla_parse_template($page_template_array['tag_block'], $page_values);
                 $taxonomy_options = MLAData::mla_parse_template($page_template_array['taxonomy_options'], $page_values);
                 $quick_tag_blocks .= $tag_block;
                 $bulk_tag_blocks .= $tag_block . $taxonomy_options;
             }
             // current_user_can
         }
         // foreach $flat_taxonomies
         $page_values = array('tag_blocks' => $quick_tag_blocks);
         $quick_right_column = MLAData::mla_parse_template($page_template_array['tag_fieldset'], $page_values);
         $page_values = array('tag_blocks' => $bulk_tag_blocks);
         $bulk_right_column = MLAData::mla_parse_template($page_template_array['tag_fieldset'], $page_values);
     }
     // count( $flat_taxonomies )
     if ($authors = self::mla_authors_dropdown(-1)) {
         $bulk_authors_dropdown = '              <label class="inline-edit-author alignright">' . "\n";
         $bulk_authors_dropdown .= '                <span class="title">' . __('Author', 'media-library-assistant') . '</span>' . "\n";
         $bulk_authors_dropdown .= $authors . "\n";
         $bulk_authors_dropdown .= '              </label>' . "\n";
     } else {
         $bulk_authors_dropdown = '';
     }
     $bulk_custom_fields = '';
     foreach (MLAOptions::mla_custom_field_support('bulk_edit') as $slug => $details) {
         $page_values = array('slug' => $slug, 'label' => esc_attr($details['name']));
         $bulk_custom_fields .= MLAData::mla_parse_template($page_template_array['custom_field'], $page_values);
     }
     $set_parent_form = MLA::mla_set_parent_form();
     $page_values = array('colspan' => $MLAListTable->get_column_count(), 'Quick Edit' => __('Quick Edit', 'media-library-assistant'), 'Title' => __('Title', 'media-library-assistant'), 'Name/Slug' => __('Name/Slug', 'media-library-assistant'), 'Caption' => __('Caption', 'media-library-assistant'), 'Description' => __('Description', 'media-library-assistant'), 'ALT Text' => __('ALT Text', 'media-library-assistant'), 'Parent ID' => __('Parent ID', 'media-library-assistant'), 'Select' => __('Select', 'media-library-assistant'), 'Menu Order' => __('Menu Order', 'media-library-assistant'), 'authors' => $authors_dropdown, 'custom_fields' => $custom_fields, 'quick_middle_column' => $quick_middle_column, 'quick_right_column' => $quick_right_column, 'Cancel' => __('Cancel', 'media-library-assistant'), 'Reset' => __('Reset', 'media-library-assistant'), 'Update' => __('Update', 'media-library-assistant'), 'Bulk Edit' => __('Bulk Edit', 'media-library-assistant'), 'bulk_middle_column' => $bulk_middle_column, 'bulk_right_column' => $bulk_right_column, 'bulk_authors' => $bulk_authors_dropdown, 'Comments' => __('Comments', 'media-library-assistant'), 'Pings' => __('Pings', 'media-library-assistant'), 'No Change' => __('No Change', 'media-library-assistant'), 'Allow' => __('Allow', 'media-library-assistant'), 'Do not allow' => __('Do not allow', 'media-library-assistant'), 'bulk_custom_fields' => $bulk_custom_fields, 'Map IPTC/EXIF metadata' => __('Map IPTC/EXIF metadata', 'media-library-assistant'), 'Map Custom Field metadata' => __('Map Custom Field metadata', 'media-library-assistant'), 'Bulk Waiting' => __('Waiting', 'media-library-assistant'), 'Bulk Running' => __('In-process', 'media-library-assistant'), 'Bulk Complete' => __('Complete', 'media-library-assistant'), 'Refresh' => __('Refresh', 'media-library-assistant'), 'set_parent_form' => $set_parent_form);
     $page_values = apply_filters('mla_list_table_inline_values', $page_values);
     $page_template = apply_filters('mla_list_table_inline_template', $page_template_array['page']);
     $parse_value = MLAData::mla_parse_template($page_template, $page_values);
     return apply_filters('mla_list_table_inline_parse', $parse_value, $page_template, $page_values);
 }
Ejemplo n.º 12
0
 /**
  * Build the hidden row templates for inline editing (quick and bulk edit)
  *
  * inspired by inline_edit() in wp-admin\includes\class-wp-posts-list-table.php.
  *
  * @since 0.20
  *
  * @param	object	MLA List Table object
  *
  * @return	string	HTML <form> markup for hidden rows
  */
 private static function _build_inline_edit_form($MLAListTable)
 {
     $taxonomies = get_object_taxonomies('attachment', 'objects');
     $hierarchical_taxonomies = array();
     $flat_taxonomies = array();
     foreach ($taxonomies as $tax_name => $tax_object) {
         if ($tax_object->hierarchical && $tax_object->show_ui && MLAOptions::mla_taxonomy_support($tax_name, 'quick-edit')) {
             $hierarchical_taxonomies[$tax_name] = $tax_object;
         } elseif ($tax_object->show_ui && MLAOptions::mla_taxonomy_support($tax_name, 'quick-edit')) {
             $flat_taxonomies[$tax_name] = $tax_object;
         }
     }
     $page_template_array = MLAData::mla_load_template(MLA_PLUGIN_PATH . 'tpls/admin-inline-edit-form.tpl');
     if (!array($page_template_array)) {
         error_log("ERROR: MLA::_build_inline_edit_form \$page_template_array = " . var_export($page_template_array, true), 0);
         return '';
     }
     if ($authors = self::_authors_dropdown()) {
         $authors_dropdown = '              <label class="inline-edit-author">' . "\r\n";
         $authors_dropdown .= '                <span class="title">' . __('Author') . '</span>' . "\r\n";
         $authors_dropdown .= $authors . "\r\n";
         $authors_dropdown .= '              </label>' . "\r\n";
     } else {
         $authors_dropdown = '';
     }
     $custom_fields = '';
     foreach (MLAOptions::mla_custom_field_support('quick_edit') as $slug => $label) {
         $page_values = array('slug' => $slug, 'label' => esc_attr($label));
         $custom_fields .= MLAData::mla_parse_template($page_template_array['custom_field'], $page_values);
     }
     /*
      * The middle column contains the hierarchical taxonomies, e.g., Attachment Category
      */
     $quick_middle_column = '';
     $bulk_middle_column = '';
     if (count($hierarchical_taxonomies)) {
         $quick_category_blocks = '';
         $bulk_category_blocks = '';
         foreach ($hierarchical_taxonomies as $tax_name => $tax_object) {
             if (current_user_can($tax_object->cap->assign_terms)) {
                 ob_start();
                 wp_terms_checklist(NULL, array('taxonomy' => $tax_name));
                 $tax_checklist = ob_get_contents();
                 ob_end_clean();
                 $page_values = array('tax_html' => esc_html($tax_object->labels->name), 'tax_attr' => esc_attr($tax_name), 'tax_checklist' => $tax_checklist);
                 $category_block = MLAData::mla_parse_template($page_template_array['category_block'], $page_values);
                 $taxonomy_options = MLAData::mla_parse_template($page_template_array['taxonomy_options'], $page_values);
                 $quick_category_blocks .= $category_block;
                 $bulk_category_blocks .= $category_block . $taxonomy_options;
             }
             // current_user_can
         }
         // foreach $hierarchical_taxonomies
         $page_values = array('category_blocks' => $quick_category_blocks);
         $quick_middle_column = MLAData::mla_parse_template($page_template_array['category_fieldset'], $page_values);
         $page_values = array('category_blocks' => $bulk_category_blocks);
         $bulk_middle_column = MLAData::mla_parse_template($page_template_array['category_fieldset'], $page_values);
     }
     // count( $hierarchical_taxonomies )
     /*
      * The right-hand column contains the flat taxonomies, e.g., Attachment Tag
      */
     $quick_right_column = '';
     $bulk_right_column = '';
     if (count($flat_taxonomies)) {
         $quick_tag_blocks = '';
         $bulk_tag_blocks = '';
         foreach ($flat_taxonomies as $tax_name => $tax_object) {
             if (current_user_can($tax_object->cap->assign_terms)) {
                 $page_values = array('tax_html' => esc_html($tax_object->labels->name), 'tax_attr' => esc_attr($tax_name));
                 $tag_block = MLAData::mla_parse_template($page_template_array['tag_block'], $page_values);
                 $taxonomy_options = MLAData::mla_parse_template($page_template_array['taxonomy_options'], $page_values);
                 $quick_tag_blocks .= $tag_block;
                 $bulk_tag_blocks .= $tag_block . $taxonomy_options;
             }
             // current_user_can
         }
         // foreach $flat_taxonomies
         $page_values = array('tag_blocks' => $quick_tag_blocks);
         $quick_right_column = MLAData::mla_parse_template($page_template_array['tag_fieldset'], $page_values);
         $page_values = array('tag_blocks' => $bulk_tag_blocks);
         $bulk_right_column = MLAData::mla_parse_template($page_template_array['tag_fieldset'], $page_values);
     }
     // count( $flat_taxonomies )
     if ($authors = self::_authors_dropdown(-1)) {
         $bulk_authors_dropdown = '              <label class="inline-edit-author">' . "\r\n";
         $bulk_authors_dropdown .= '                <span class="title">' . __('Author') . '</span>' . "\r\n";
         $bulk_authors_dropdown .= $authors . "\r\n";
         $bulk_authors_dropdown .= '              </label>' . "\r\n";
     } else {
         $bulk_authors_dropdown = '';
     }
     $bulk_custom_fields = '';
     foreach (MLAOptions::mla_custom_field_support('bulk_edit') as $slug => $label) {
         $page_values = array('slug' => $slug, 'label' => esc_attr($label));
         $bulk_custom_fields .= MLAData::mla_parse_template($page_template_array['custom_field'], $page_values);
     }
     $page_values = array('colspan' => count($MLAListTable->get_columns()), 'authors' => $authors_dropdown, 'custom_fields' => $custom_fields, 'quick_middle_column' => $quick_middle_column, 'quick_right_column' => $quick_right_column, 'bulk_middle_column' => $bulk_middle_column, 'bulk_right_column' => $bulk_right_column, 'bulk_authors' => $bulk_authors_dropdown, 'bulk_custom_fields' => $bulk_custom_fields);
     $page_template = MLAData::mla_parse_template($page_template_array['page'], $page_values);
     return $page_template;
 }
Ejemplo n.º 13
0
 /**
  * The MLA Gallery shortcode.
  *
  * This is a superset of the WordPress Gallery shortcode for displaying images on a post,
  * page or custom post type. It is adapted from /wp-includes/media.php gallery_shortcode.
  * Enhancements include many additional selection parameters and full taxonomy support.
  *
  * @since .50
  *
  * @param array $attr Attributes of the shortcode.
  *
  * @return string HTML content to display gallery.
  */
 public static function mla_gallery_shortcode($attr)
 {
     global $post;
     /*
      * Some do_shortcode callers may not have a specific post in mind
      */
     if (!is_object($post)) {
         $post = (object) array('ID' => 0);
     }
     /*
      * 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 mla_paginate_current parameter can be changed to support multiple galleries per page.
      */
     if (!isset($attr['mla_page_parameter'])) {
         $attr['mla_page_parameter'] = 'mla_paginate_current';
     }
     $mla_page_parameter = $attr['mla_page_parameter'];
     /*
      * Special handling of the mla_paginate_current parameter to make
      * "MLA pagination" easier. Look for this parameter in $_REQUEST
      * if it's not present in the shortcode itself.
      */
     if (!isset($attr[$mla_page_parameter])) {
         if (isset($_REQUEST[$mla_page_parameter])) {
             $attr[$mla_page_parameter] = $_REQUEST[$mla_page_parameter];
         }
     }
     //			else
     //				$attr[ $mla_page_parameter ] = '';
     /*
      * These are the parameters for gallery display
      */
     $mla_arguments = array('mla_output' => 'gallery', 'mla_style' => MLAOptions::mla_get_option('default_style'), 'mla_markup' => MLAOptions::mla_get_option('default_markup'), 'mla_float' => is_rtl() ? 'right' : 'left', 'mla_itemwidth' => MLAOptions::mla_get_option('mla_gallery_itemwidth'), 'mla_margin' => MLAOptions::mla_get_option('mla_gallery_margin'), 'mla_link_attributes' => '', 'mla_link_class' => '', 'mla_link_href' => '', 'mla_link_text' => '', 'mla_nolink_text' => '', 'mla_rollover_text' => '', 'mla_image_class' => '', 'mla_image_alt' => '', 'mla_image_attributes' => '', 'mla_caption' => '', 'mla_target' => '', 'mla_debug' => false, 'mla_viewer' => false, 'mla_viewer_extensions' => 'doc,xls,ppt,pdf,txt', 'mla_viewer_page' => '1', 'mla_viewer_width' => '150', 'mla_alt_shortcode' => NULL, 'mla_alt_ids_name' => 'ids', 'mla_end_size' => 1, 'mla_mid_size' => 2, 'mla_prev_text' => '&laquo; Previous', 'mla_next_text' => 'Next &raquo;', 'mla_paginate_type' => 'plain');
     $default_arguments = array_merge(array('size' => 'thumbnail', 'itemtag' => 'dl', 'icontag' => 'dt', 'captiontag' => 'dd', 'columns' => MLAOptions::mla_get_option('mla_gallery_columns'), 'link' => 'permalink', 'id' => NULL, 'style' => NULL, 'type' => 'default', 'thumb_width' => 75, 'thumb_height' => 75, 'thumbnail_size' => 'thumbnail', 'slide_size' => 'large', 'slideshow_height' => 500, 'fx' => 'fade', 'timeout' => 4000, 'speed' => 1000, 'pause' => NULL), $mla_arguments);
     /*
      * Look for 'request' substitution parameters,
      * which can be added to any input parameter
      */
     foreach ($attr as $attr_key => $attr_value) {
         /*
          * attachment-specific Gallery Display Content parameters must be evaluated
          * later, when all of the information is available.
          */
         if (in_array($attr_key, array('mla_link_attributes', 'mla_link_class', 'mla_link_href', 'mla_link_text', 'mla_nolink_text', 'mla_rollover_text', 'mla_image_class', 'mla_image_alt', 'mla_image_attributes', 'mla_caption'))) {
             continue;
         }
         $attr_value = str_replace('{+', '[+', str_replace('+}', '+]', $attr_value));
         $replacement_values = MLAData::mla_expand_field_level_parameters($attr_value);
         if (!empty($replacement_values)) {
             $attr[$attr_key] = MLAData::mla_parse_template($attr_value, $replacement_values);
         }
     }
     /*
      * Merge gallery arguments with defaults, pass the query arguments on to mla_get_shortcode_attachments.
      */
     $attr = apply_filters('mla_gallery_attributes', $attr);
     $arguments = shortcode_atts($default_arguments, $attr);
     $arguments = apply_filters('mla_gallery_arguments', $arguments);
     self::$mla_debug = !empty($arguments['mla_debug']) && 'true' == strtolower($arguments['mla_debug']);
     /*
      * Determine output type
      */
     $output_parameters = array_map('strtolower', array_map('trim', explode(',', $arguments['mla_output'])));
     $is_gallery = 'gallery' == $output_parameters[0];
     $is_pagination = in_array($output_parameters[0], array('previous_page', 'next_page', 'paginate_links'));
     $attachments = self::mla_get_shortcode_attachments($post->ID, $attr, $is_pagination);
     if (is_string($attachments)) {
         return $attachments;
     }
     if (empty($attachments)) {
         if (self::$mla_debug) {
             $output = '<p><strong>mla_debug empty gallery</strong>, query = ' . var_export($attr, true) . '</p>';
             $output .= self::$mla_debug_messages;
             self::$mla_debug_messages = '';
         } else {
             $output = '';
         }
         $output .= $arguments['mla_nolink_text'];
         return $output;
     }
     // empty $attachments
     /*
      * Look for user-specified alternate gallery shortcode
      */
     if (is_string($arguments['mla_alt_shortcode'])) {
         /*
          * Replace data-selection parameters with the "ids" list
          */
         $blacklist = array_merge($mla_arguments, self::$data_selection_parameters);
         $new_args = '';
         foreach ($attr as $key => $value) {
             if (array_key_exists($key, $blacklist)) {
                 continue;
             }
             $slashed = addcslashes($value, chr(0) . chr(7) . chr(8) . "\f\n\r\t\v\"\\\$");
             if (false !== strpos($value, ' ') || false !== strpos($value, '\'') || $slashed != $value) {
                 $value = '"' . $slashed . '"';
             }
             $new_args .= empty($new_args) ? $key . '=' . $value : ' ' . $key . '=' . $value;
         }
         // foreach $attr
         $new_ids = '';
         foreach ($attachments as $value) {
             $new_ids .= empty($new_ids) ? (string) $value->ID : ',' . $value->ID;
         }
         // foreach $attachments
         $new_ids = $arguments['mla_alt_ids_name'] . '="' . $new_ids . '"';
         if (self::$mla_debug) {
             $output = self::$mla_debug_messages;
             self::$mla_debug_messages = '';
         } else {
             $output = '';
         }
         /*
          * Execute the alternate gallery shortcode with the new parameters
          */
         return $output . do_shortcode(sprintf('[%1$s %2$s %3$s]', $arguments['mla_alt_shortcode'], $new_ids, $new_args));
     }
     // mla_alt_shortcode
     /*
      * Look for Photonic-enhanced gallery
      */
     global $photonic;
     if (is_object($photonic) && !empty($arguments['style'])) {
         if ('default' != strtolower($arguments['type'])) {
             return '<p><strong>Photonic-enhanced [mla_gallery]</strong> type must be <strong>default</strong>, query = ' . var_export($attr, true) . '</p>';
         }
         $images = array();
         foreach ($attachments as $key => $val) {
             $images[$val->ID] = $attachments[$key];
         }
         if (isset($arguments['pause']) && 'false' == $arguments['pause']) {
             $arguments['pause'] = NULL;
         }
         $output = $photonic->build_gallery($images, $arguments['style'], $arguments);
         return $output;
     }
     $size = $size_class = $arguments['size'];
     if ('icon' == strtolower($size)) {
         if ('checked' == MLAOptions::mla_get_option(MLAOptions::MLA_ENABLE_MLA_ICONS)) {
             $size = array(64, 64);
         } else {
             $size = array(60, 60);
         }
         $show_icon = true;
     } else {
         $show_icon = false;
     }
     /*
      * Feeds such as RSS, Atom or RDF do not require styled and formatted output
      */
     if (is_feed()) {
         $output = "\n";
         foreach ($attachments as $att_id => $attachment) {
             $output .= wp_get_attachment_link($att_id, $size, true) . "\n";
         }
         return $output;
     }
     /*
      * Check for Google File Viewer arguments
      */
     $arguments['mla_viewer'] = !empty($arguments['mla_viewer']) && 'true' == strtolower($arguments['mla_viewer']);
     if ($arguments['mla_viewer']) {
         $arguments['mla_viewer_extensions'] = array_filter(array_map('trim', explode(',', $arguments['mla_viewer_extensions'])));
         $arguments['mla_viewer_page'] = absint($arguments['mla_viewer_page']);
         $arguments['mla_viewer_width'] = absint($arguments['mla_viewer_width']);
     }
     // $instance supports multiple galleries in one page/post
     static $instance = 0;
     $instance++;
     /*
      * The default MLA style template includes "margin: 1.5%" to put a bit of
      * minimum space between the columns. "mla_margin" can be used to change
      * this. "mla_itemwidth" can be used with "columns=0" to achieve a "responsive"
      * layout.
      */
     $columns = absint($arguments['columns']);
     $margin_string = strtolower(trim($arguments['mla_margin']));
     if (is_numeric($margin_string) && 0 != $margin_string) {
         $margin_string .= '%';
     }
     // Legacy values are always in percent
     if ('%' == substr($margin_string, -1)) {
         $margin_percent = (double) substr($margin_string, 0, strlen($margin_string) - 1);
     } else {
         $margin_percent = 0;
     }
     $width_string = strtolower(trim($arguments['mla_itemwidth']));
     if ('none' != $width_string) {
         switch ($width_string) {
             case 'exact':
                 $margin_percent = 0;
                 /* fallthru */
             /* fallthru */
             case 'calculate':
                 $width_string = $columns > 0 ? floor(1000 / $columns) / 10 - 2.0 * $margin_percent : 100 - 2.0 * $margin_percent;
                 /* fallthru */
             /* fallthru */
             default:
                 if (is_numeric($width_string) && 0 != $width_string) {
                     $width_string .= '%';
                 }
                 // Legacy values are always in percent
         }
     }
     // $use_width
     $float = strtolower($arguments['mla_float']);
     if (!in_array($float, array('left', 'none', 'right'))) {
         $float = is_rtl() ? 'right' : 'left';
     }
     $style_values = array('mla_style' => $arguments['mla_style'], 'mla_markup' => $arguments['mla_markup'], 'instance' => $instance, 'id' => $post->ID, 'itemtag' => tag_escape($arguments['itemtag']), 'icontag' => tag_escape($arguments['icontag']), 'captiontag' => tag_escape($arguments['captiontag']), 'columns' => $columns, 'itemwidth' => $width_string, 'margin' => $margin_string, 'float' => $float, 'selector' => "mla_gallery-{$instance}", 'size_class' => sanitize_html_class($size_class));
     $style_template = $gallery_style = '';
     $use_mla_gallery_style = 'none' != strtolower($style_values['mla_style']);
     if (apply_filters('use_mla_gallery_style', $use_mla_gallery_style, $style_values['mla_style'])) {
         $style_template = MLAOptions::mla_fetch_gallery_template($style_values['mla_style'], 'style');
         if (empty($style_template)) {
             $style_values['mla_style'] = 'default';
             $style_template = MLAOptions::mla_fetch_gallery_template('default', 'style');
         }
         if (!empty($style_template)) {
             /*
              * Look for 'query' and 'request' substitution parameters
              */
             $style_values = MLAData::mla_expand_field_level_parameters($style_template, $attr, $style_values);
             /*
              * Clean up the template to resolve width or margin == 'none'
              */
             if ('none' == $margin_string) {
                 $style_values['margin'] = '0';
                 $style_template = preg_replace('/margin:[\\s]*\\[\\+margin\\+\\][\\%]*[\\;]*/', '', $style_template);
             }
             if ('none' == $width_string) {
                 $style_values['itemwidth'] = 'auto';
                 $style_template = preg_replace('/width:[\\s]*\\[\\+itemwidth\\+\\][\\%]*[\\;]*/', '', $style_template);
             }
             $style_values = apply_filters('mla_gallery_style_values', $style_values);
             $style_template = apply_filters('mla_gallery_style_template', $style_template);
             $gallery_style = MLAData::mla_parse_template($style_template, $style_values);
             $gallery_style = apply_filters('mla_gallery_style_parse', $gallery_style, $style_template, $style_values);
             /*
              * Clean up the styles to resolve extra "%" suffixes on width or margin (pre v1.42 values)
              */
             $preg_pattern = array('/([margin|width]:[^\\%]*)\\%\\%/', '/([margin|width]:.*)auto\\%/', '/([margin|width]:.*)inherit\\%/');
             $preg_replacement = array('${1}%', '${1}auto', '${1}inherit');
             $gallery_style = preg_replace($preg_pattern, $preg_replacement, $gallery_style);
         }
         // !empty template
     }
     // use_mla_gallery_style
     $upload_dir = wp_upload_dir();
     $markup_values = $style_values;
     $markup_values['site_url'] = site_url();
     $markup_values['base_url'] = $upload_dir['baseurl'];
     $markup_values['base_dir'] = $upload_dir['basedir'];
     $open_template = MLAOptions::mla_fetch_gallery_template($markup_values['mla_markup'] . '-open', 'markup');
     if (false === $open_template) {
         $markup_values['mla_markup'] = 'default';
         $open_template = MLAOptions::mla_fetch_gallery_template('default-open', 'markup');
     }
     if (empty($open_template)) {
         $open_template = '';
     }
     $row_open_template = MLAOptions::mla_fetch_gallery_template($markup_values['mla_markup'] . '-row-open', 'markup');
     if (empty($row_open_template)) {
         $row_open_template = '';
     }
     $item_template = MLAOptions::mla_fetch_gallery_template($markup_values['mla_markup'] . '-item', 'markup');
     if (empty($item_template)) {
         $item_template = '';
     }
     $row_close_template = MLAOptions::mla_fetch_gallery_template($markup_values['mla_markup'] . '-row-close', 'markup');
     if (empty($row_close_template)) {
         $row_close_template = '';
     }
     $close_template = MLAOptions::mla_fetch_gallery_template($markup_values['mla_markup'] . '-close', 'markup');
     if (empty($close_template)) {
         $close_template = '';
     }
     /*
      * Look for gallery-level markup substitution parameters
      */
     $new_text = $open_template . $row_open_template . $row_close_template . $close_template;
     $markup_values = MLAData::mla_expand_field_level_parameters($new_text, $attr, $markup_values);
     if (self::$mla_debug) {
         $output = self::$mla_debug_messages;
         self::$mla_debug_messages = '';
     } else {
         $output = '';
     }
     if ($is_gallery) {
         $markup_values = apply_filters('mla_gallery_open_values', $markup_values);
         $open_template = apply_filters('mla_gallery_open_template', $open_template);
         if (empty($open_template)) {
             $gallery_div = '';
         } else {
             $gallery_div = MLAData::mla_parse_template($open_template, $markup_values);
         }
         $gallery_div = apply_filters('mla_gallery_open_parse', $gallery_div, $open_template, $markup_values);
         $output .= apply_filters('mla_gallery_style', $gallery_style . $gallery_div, $style_values, $markup_values, $style_template, $open_template);
     } else {
         if (!isset($attachments['found_rows'])) {
             $attachments['found_rows'] = 0;
         }
         /*
          * Handle 'previous_page', 'next_page', and 'paginate_links'
          */
         $pagination_result = self::_process_pagination_output_types($output_parameters, $markup_values, $arguments, $attr, $attachments['found_rows'], $output);
         if (false !== $pagination_result) {
             return $pagination_result;
         }
         unset($attachments['found_rows']);
     }
     /*
      * For "previous_link" and "next_link", discard all of the $attachments except the appropriate choice
      */
     if (!$is_gallery) {
         $is_previous = 'previous_link' == $output_parameters[0];
         $is_next = 'next_link' == $output_parameters[0];
         if (!($is_previous || $is_next)) {
             return '';
         }
         // unknown outtput type
         $is_wrap = isset($output_parameters[1]) && 'wrap' == $output_parameters[1];
         $current_id = empty($arguments['id']) ? $markup_values['id'] : $arguments['id'];
         foreach ($attachments as $id => $attachment) {
             if ($attachment->ID == $current_id) {
                 break;
             }
         }
         $target_id = $is_previous ? $id - 1 : $id + 1;
         if (isset($attachments[$target_id])) {
             $attachments = array($attachments[$target_id]);
         } elseif ($is_wrap) {
             if ($is_next) {
                 $attachments = array(array_shift($attachments));
             } else {
                 $attachments = array(array_pop($attachments));
             }
         } elseif (!empty($arguments['mla_nolink_text'])) {
             return self::_process_shortcode_parameter($arguments['mla_nolink_text'], $markup_values) . '</a>';
         } else {
             return '';
         }
     }
     // ! is_gallery
     $column_index = 0;
     foreach ($attachments as $id => $attachment) {
         $item_values = $markup_values;
         /*
          * fill in item-specific elements
          */
         $item_values['index'] = (string) 1 + $column_index;
         $item_values['excerpt'] = wptexturize($attachment->post_excerpt);
         $item_values['attachment_ID'] = $attachment->ID;
         $item_values['mime_type'] = $attachment->post_mime_type;
         $item_values['menu_order'] = $attachment->menu_order;
         $item_values['date'] = $attachment->post_date;
         $item_values['modified'] = $attachment->post_modified;
         $item_values['parent'] = $attachment->post_parent;
         $item_values['parent_title'] = '(unattached)';
         $item_values['parent_type'] = '';
         $item_values['parent_date'] = '';
         $item_values['title'] = wptexturize($attachment->post_title);
         $item_values['slug'] = wptexturize($attachment->post_name);
         $item_values['width'] = '';
         $item_values['height'] = '';
         $item_values['image_meta'] = '';
         $item_values['image_alt'] = '';
         $item_values['base_file'] = '';
         $item_values['path'] = '';
         $item_values['file'] = '';
         $item_values['description'] = wptexturize($attachment->post_content);
         $item_values['file_url'] = wptexturize($attachment->guid);
         $item_values['author_id'] = $attachment->post_author;
         $user = get_user_by('id', $attachment->post_author);
         if (isset($user->data->display_name)) {
             $item_values['author'] = wptexturize($user->data->display_name);
         } else {
             $item_values['author'] = 'unknown';
         }
         $post_meta = MLAData::mla_fetch_attachment_metadata($attachment->ID);
         $base_file = $post_meta['mla_wp_attached_file'];
         $sizes = isset($post_meta['mla_wp_attachment_metadata']['sizes']) ? $post_meta['mla_wp_attachment_metadata']['sizes'] : array();
         if (!empty($post_meta['mla_wp_attachment_metadata']['width'])) {
             $item_values['width'] = $post_meta['mla_wp_attachment_metadata']['width'];
         }
         if (!empty($post_meta['mla_wp_attachment_metadata']['height'])) {
             $item_values['height'] = $post_meta['mla_wp_attachment_metadata']['height'];
         }
         if (!empty($post_meta['mla_wp_attachment_metadata']['image_meta'])) {
             $item_values['image_meta'] = wptexturize(var_export($post_meta['mla_wp_attachment_metadata']['image_meta'], true));
         }
         if (!empty($post_meta['mla_wp_attachment_image_alt'])) {
             $item_values['image_alt'] = wptexturize($post_meta['mla_wp_attachment_image_alt']);
         }
         if (!empty($base_file)) {
             $last_slash = strrpos($base_file, '/');
             if (false === $last_slash) {
                 $file_name = $base_file;
                 $item_values['base_file'] = wptexturize($base_file);
                 $item_values['file'] = wptexturize($base_file);
             } else {
                 $file_name = substr($base_file, $last_slash + 1);
                 $item_values['base_file'] = wptexturize($base_file);
                 $item_values['path'] = wptexturize(substr($base_file, 0, $last_slash + 1));
                 $item_values['file'] = wptexturize($file_name);
             }
         } else {
             $file_name = '';
         }
         $parent_info = MLAData::mla_fetch_attachment_parent_data($attachment->post_parent);
         if (isset($parent_info['parent_title'])) {
             $item_values['parent_title'] = wptexturize($parent_info['parent_title']);
         }
         if (isset($parent_info['parent_date'])) {
             $item_values['parent_date'] = wptexturize($parent_info['parent_date']);
         }
         if (isset($parent_info['parent_type'])) {
             $item_values['parent_type'] = wptexturize($parent_info['parent_type']);
         }
         /*
          * Add attachment-specific field-level substitution parameters
          */
         $new_text = $item_template . str_replace('{+', '[+', str_replace('+}', '+]', $arguments['mla_link_attributes'] . $arguments['mla_link_class'] . $arguments['mla_link_href'] . $arguments['mla_link_text'] . $arguments['mla_nolink_text'] . $arguments['mla_rollover_text'] . $arguments['mla_image_class'] . $arguments['mla_image_alt'] . $arguments['mla_image_attributes'] . $arguments['mla_caption']));
         $item_values = MLAData::mla_expand_field_level_parameters($new_text, $attr, $item_values, $attachment->ID);
         if ($item_values['captiontag']) {
             $item_values['caption'] = wptexturize($attachment->post_excerpt);
             if (!empty($arguments['mla_caption'])) {
                 $item_values['caption'] = wptexturize(self::_process_shortcode_parameter($arguments['mla_caption'], $item_values));
             }
         } else {
             $item_values['caption'] = '';
         }
         if (!empty($arguments['mla_link_text'])) {
             $link_text = self::_process_shortcode_parameter($arguments['mla_link_text'], $item_values);
         } else {
             $link_text = false;
         }
         $item_values['pagelink'] = wp_get_attachment_link($attachment->ID, $size, true, $show_icon, $link_text);
         $item_values['filelink'] = wp_get_attachment_link($attachment->ID, $size, false, $show_icon, $link_text);
         /*
          * Apply the Gallery Display Content parameters.
          * Note that $link_attributes and $rollover_text
          * are used in the Google Viewer code below
          */
         if (!empty($arguments['mla_target'])) {
             $link_attributes = 'target="' . $arguments['mla_target'] . '" ';
         } else {
             $link_attributes = '';
         }
         if (!empty($arguments['mla_link_attributes'])) {
             $link_attributes .= self::_process_shortcode_parameter($arguments['mla_link_attributes'], $item_values) . ' ';
         }
         if (!empty($arguments['mla_link_class'])) {
             $link_attributes .= 'class="' . self::_process_shortcode_parameter($arguments['mla_link_class'], $item_values) . '" ';
         }
         if (!empty($link_attributes)) {
             $item_values['pagelink'] = str_replace('<a href=', '<a ' . $link_attributes . 'href=', $item_values['pagelink']);
             $item_values['filelink'] = str_replace('<a href=', '<a ' . $link_attributes . 'href=', $item_values['filelink']);
         }
         if (!empty($arguments['mla_rollover_text'])) {
             $rollover_text = esc_attr(self::_process_shortcode_parameter($arguments['mla_rollover_text'], $item_values));
             /*
              * Replace single- and double-quote delimited values
              */
             $item_values['pagelink'] = preg_replace('# title=\'([^\']*)\'#', " title='{$rollover_text}'", $item_values['pagelink']);
             $item_values['pagelink'] = preg_replace('# title=\\"([^\\"]*)\\"#', " title=\"{$rollover_text}\"", $item_values['pagelink']);
             $item_values['filelink'] = preg_replace('# title=\'([^\']*)\'#', " title='{$rollover_text}'", $item_values['filelink']);
             $item_values['filelink'] = preg_replace('# title=\\"([^\\"]*)\\"#', " title=\"{$rollover_text}\"", $item_values['filelink']);
         } else {
             $rollover_text = $item_values['title'];
         }
         /*
          * Process the <img> tag, if present
          * Note that $image_attributes, $image_class and $image_alt
          * are used in the Google Viewer code below
          */
         if (!empty($arguments['mla_image_attributes'])) {
             $image_attributes = self::_process_shortcode_parameter($arguments['mla_image_attributes'], $item_values) . ' ';
         } else {
             $image_attributes = '';
         }
         if (!empty($arguments['mla_image_class'])) {
             $image_class = esc_attr(self::_process_shortcode_parameter($arguments['mla_image_class'], $item_values));
         } else {
             $image_class = '';
         }
         if (!empty($arguments['mla_image_alt'])) {
             $image_alt = esc_attr(self::_process_shortcode_parameter($arguments['mla_image_alt'], $item_values));
         } else {
             $image_alt = '';
         }
         if (false !== strpos($item_values['pagelink'], '<img ')) {
             if (!empty($image_attributes)) {
                 $item_values['pagelink'] = str_replace('<img ', '<img ' . $image_attributes, $item_values['pagelink']);
                 $item_values['filelink'] = str_replace('<img ', '<img ' . $image_attributes, $item_values['filelink']);
             }
             /*
              * Extract existing class values and add to them
              */
             if (!empty($image_class)) {
                 $match_count = preg_match_all('# class=\\"([^\\"]+)\\" #', $item_values['pagelink'], $matches, PREG_OFFSET_CAPTURE);
                 if (!($match_count == false || $match_count == 0)) {
                     $class = $matches[1][0][0] . ' ' . $image_class;
                 } else {
                     $class = $image_class;
                 }
                 $item_values['pagelink'] = preg_replace('# class=\\"([^\\"]*)\\"#', " class=\"{$class}\"", $item_values['pagelink']);
                 $item_values['filelink'] = preg_replace('# class=\\"([^\\"]*)\\"#', " class=\"{$class}\"", $item_values['filelink']);
             }
             if (!empty($image_alt)) {
                 $item_values['pagelink'] = preg_replace('# alt=\\"([^\\"]*)\\"#', " alt=\"{$image_alt}\"", $item_values['pagelink']);
                 $item_values['filelink'] = preg_replace('# alt=\\"([^\\"]*)\\"#', " alt=\"{$image_alt}\"", $item_values['filelink']);
             }
         }
         // process <img> tag
         switch ($arguments['link']) {
             case 'permalink':
             case 'post':
                 $item_values['link'] = $item_values['pagelink'];
                 break;
             case 'file':
             case 'full':
                 $item_values['link'] = $item_values['filelink'];
                 break;
             default:
                 $item_values['link'] = $item_values['filelink'];
                 /*
                  * Check for link to specific (registered) file size
                  */
                 if (array_key_exists($arguments['link'], $sizes)) {
                     $target_file = $sizes[$arguments['link']]['file'];
                     $item_values['link'] = str_replace($file_name, $target_file, $item_values['filelink']);
                 }
         }
         // switch 'link'
         /*
          * Extract target and thumbnail fields
          */
         $match_count = preg_match_all('#href=\'([^\']+)\'#', $item_values['pagelink'], $matches, PREG_OFFSET_CAPTURE);
         if (!($match_count == false || $match_count == 0)) {
             $item_values['pagelink_url'] = $matches[1][0][0];
         } else {
             $item_values['pagelink_url'] = '';
         }
         $match_count = preg_match_all('#href=\'([^\']+)\'#', $item_values['filelink'], $matches, PREG_OFFSET_CAPTURE);
         if (!($match_count == false || $match_count == 0)) {
             $item_values['filelink_url'] = $matches[1][0][0];
         } else {
             $item_values['filelink_url'] = '';
         }
         $match_count = preg_match_all('#href=\'([^\']+)\'#', $item_values['link'], $matches, PREG_OFFSET_CAPTURE);
         if (!($match_count == false || $match_count == 0)) {
             $item_values['link_url'] = $matches[1][0][0];
         } else {
             $item_values['link_url'] = '';
         }
         /*
          * Override the link value; leave filelink and pagelink unchanged
          * Note that $link_href is used in the Google Viewer code below
          */
         if (!empty($arguments['mla_link_href'])) {
             $link_href = self::_process_shortcode_parameter($arguments['mla_link_href'], $item_values);
             /*
              * Replace single- and double-quote delimited values
              */
             $item_values['link'] = preg_replace('# href=\'([^\']*)\'#', " href='{$link_href}'", $item_values['link']);
             $item_values['link'] = preg_replace('# href=\\"([^\\"]*)\\"#', " href=\"{$link_href}\"", $item_values['link']);
         } else {
             $link_href = '';
         }
         $match_count = preg_match_all('#\\<a [^\\>]+\\>(.*)\\</a\\>#', $item_values['link'], $matches, PREG_OFFSET_CAPTURE);
         if (!($match_count == false || $match_count == 0)) {
             $item_values['thumbnail_content'] = $matches[1][0][0];
         } else {
             $item_values['thumbnail_content'] = '';
         }
         $match_count = preg_match_all('# width=\\"([^\\"]+)\\" height=\\"([^\\"]+)\\" src=\\"([^\\"]+)\\" #', $item_values['link'], $matches, PREG_OFFSET_CAPTURE);
         if (!($match_count == false || $match_count == 0)) {
             $item_values['thumbnail_width'] = $matches[1][0][0];
             $item_values['thumbnail_height'] = $matches[2][0][0];
             $item_values['thumbnail_url'] = $matches[3][0][0];
         } else {
             $item_values['thumbnail_width'] = '';
             $item_values['thumbnail_height'] = '';
             $item_values['thumbnail_url'] = '';
         }
         /*
          * Check for Google file viewer substitution, uses above-defined
          * $link_attributes (includes target), $rollover_text, $link_href (link only),
          * $image_attributes, $image_class, $image_alt
          */
         if ($arguments['mla_viewer'] && empty($item_values['thumbnail_url'])) {
             $last_dot = strrpos($item_values['file'], '.');
             if (!(false === $last_dot)) {
                 $extension = substr($item_values['file'], $last_dot + 1);
                 if (in_array($extension, $arguments['mla_viewer_extensions'])) {
                     /*
                      * <img> tag (thumbnail_text)
                      */
                     if (!empty($image_class)) {
                         $image_class = ' class="' . $image_class . '"';
                     }
                     if (!empty($image_alt)) {
                         $image_alt = ' alt="' . $image_alt . '"';
                     } elseif (!empty($item_values['caption'])) {
                         $image_alt = ' alt="' . $item_values['caption'] . '"';
                     }
                     $item_values['thumbnail_content'] = sprintf('<img %1$ssrc="http://docs.google.com/viewer?url=%2$s&a=bi&pagenumber=%3$d&w=%4$d"%5$s%6$s>', $image_attributes, $item_values['filelink_url'], $arguments['mla_viewer_page'], $arguments['mla_viewer_width'], $image_class, $image_alt);
                     /*
                      * Filelink, pagelink and link
                      */
                     $item_values['pagelink'] = sprintf('<a %1$shref="%2$s" title="%3$s">%4$s</a>', $link_attributes, $item_values['pagelink_url'], $rollover_text, $item_values['thumbnail_content']);
                     $item_values['filelink'] = sprintf('<a %1$shref="%2$s" title="%3$s">%4$s</a>', $link_attributes, $item_values['filelink_url'], $rollover_text, $item_values['thumbnail_content']);
                     if (!empty($link_href)) {
                         $item_values['link'] = sprintf('<a %1$shref="%2$s" title="%3$s">%4$s</a>', $link_attributes, $link_href, $rollover_text, $item_values['thumbnail_content']);
                     } elseif ('permalink' == $arguments['link']) {
                         $item_values['link'] = $item_values['pagelink'];
                     } else {
                         $item_values['link'] = $item_values['filelink'];
                     }
                 }
                 // viewer extension
             }
             // has extension
         }
         // mla_viewer
         if ($is_gallery) {
             /*
              * Start of row markup
              */
             if ($markup_values['columns'] > 0 && $column_index % $markup_values['columns'] == 0) {
                 $markup_values = apply_filters('mla_gallery_row_open_values', $markup_values);
                 $row_open_template = apply_filters('mla_gallery_row_open_template', $row_open_template);
                 $parse_value = MLAData::mla_parse_template($row_open_template, $markup_values);
                 $output .= apply_filters('mla_gallery_row_open_parse', $parse_value, $row_open_template, $markup_values);
             }
             /*
              * item markup
              */
             $column_index++;
             if ($item_values['columns'] > 0 && $column_index % $item_values['columns'] == 0) {
                 $item_values['last_in_row'] = 'last_in_row';
             } else {
                 $item_values['last_in_row'] = '';
             }
             $item_values = apply_filters('mla_gallery_item_values', $item_values);
             $item_template = apply_filters('mla_gallery_item_template', $item_template);
             $parse_value = MLAData::mla_parse_template($item_template, $item_values);
             $output .= apply_filters('mla_gallery_item_parse', $parse_value, $item_template, $item_values);
             /*
              * End of row markup
              */
             if ($markup_values['columns'] > 0 && $column_index % $markup_values['columns'] == 0) {
                 $markup_values = apply_filters('mla_gallery_row_close_values', $markup_values);
                 $row_close_template = apply_filters('mla_gallery_row_close_template', $row_close_template);
                 $parse_value = MLAData::mla_parse_template($row_close_template, $markup_values);
                 $output .= apply_filters('mla_gallery_row_close_parse', $parse_value, $row_close_template, $markup_values);
             }
         } elseif ($is_previous || $is_next) {
             return $item_values['link'];
         }
     }
     // foreach attachment
     if ($is_gallery) {
         /*
          * Close out partial row
          */
         if (!($markup_values['columns'] > 0 && $column_index % $markup_values['columns'] == 0)) {
             $markup_values = apply_filters('mla_gallery_row_close_values', $markup_values);
             $row_close_template = apply_filters('mla_gallery_row_close_template', $row_close_template);
             $parse_value = MLAData::mla_parse_template($row_close_template, $markup_values);
             $output .= apply_filters('mla_gallery_row_close_parse', $parse_value, $row_close_template, $markup_values);
         }
         $markup_values = apply_filters('mla_gallery_close_values', $markup_values);
         $close_template = apply_filters('mla_gallery_close_template', $close_template);
         $parse_value = MLAData::mla_parse_template($close_template, $markup_values);
         $output .= apply_filters('mla_gallery_close_parse', $parse_value, $close_template, $markup_values);
     }
     // is_gallery
     return $output;
 }
Ejemplo n.º 14
0
 /**
  * Read a serialized file of option settings and write them to the database
  *
  * @since 1.50
  *
  * @return	array	Message(s) reflecting the results of the operation
  */
 private static function _import_settings()
 {
     $page_content = array('message' => __('No settings imported.', 'media-library-assistant'), 'body' => '');
     $message_list = '';
     if (isset($_REQUEST['mla-import-settings-file'])) {
         $filename = $_REQUEST['mla-import-settings-file'];
         if ('none' != $filename) {
             $filename = MLA_BACKUP_DIR . $filename;
         } else {
             $page_content['message'] = __('Please select an import settings file from the dropdown list.', 'media-library-assistant');
             return $page_content;
         }
     } else {
         $page_content['message'] = __('ERROR', 'media-library-assistant') . ': ' . __('The import settings dropdown selection is missing.', 'media-library-assistant');
         return $page_content;
     }
     $settings = @file_get_contents($filename, false);
     if (false === $settings) {
         $error_info = error_get_last();
         /* translators: 1: ERROR tag 2: PHP error information */
         error_log(sprintf(_x('%1$s: _import_settings $error_info = "%2$s".', 'error_log', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), var_export($error_info, true)), 0);
         if (false !== ($tail = strpos($error_info['message'], '</a>]: '))) {
             $php_errormsg = ':<br>' . substr($error_info['message'], $tail + 7);
         } else {
             $php_errormsg = '.';
         }
         /* translators: 1: ERROR tag 2: backup file name 3: error message*/
         $page_content['message'] = sprintf(__('%1$s: Reading the settings file ( %2$s ) "%3$s".', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $filename, $php_errormsg);
         return $page_content;
     }
     $settings = unserialize($settings);
     $updated_count = 0;
     $unchanged_count = 0;
     foreach ($settings as $key => $value) {
         if (MLAOptions::mla_update_option($key, $value)) {
             $updated_count++;
             $message_list .= "<br>{$key} " . _x('updated', 'message_list', 'media-library-assistant');
         } else {
             $unchanged_count++;
             $message_list .= "<br>{$key} " . _x('unchanged', 'message_list', 'media-library-assistant');
         }
     }
     /* translators: 1: number of option settings updated 2: number of option settings unchanged */
     $page_content['message'] = sprintf(__('Settings imported; %1$s updated, %2$s unchanged.', 'media-library-assistant'), $updated_count, $unchanged_count);
     /*
      * Uncomment this for debugging.
      */
     //$page_content['message'] .= $message_list;
     return $page_content;
 }
Ejemplo n.º 15
0
 /**
  * Builds the $mla_galleries or $galleries array
  *
  * @since 0.70
  *
  * @param	string name of the gallery's cache/option variable
  * @param	array by reference to the private static galleries array variable
  * @param	string the shortcode to be searched for and processed
  * @param	boolean true to exclude revisions from the search
  *
  * @return	boolean true if the galleries array is not empty
  */
 private static function _build_mla_galleries($option_name, &$galleries_array, $shortcode, $exclude_revisions)
 {
     global $wpdb, $post;
     if (is_array($galleries_array)) {
         if (!empty($galleries_array)) {
             return true;
         } else {
             return false;
         }
     }
     $option_value = MLAOptions::mla_get_option($option_name);
     if ('disabled' == $option_value) {
         return false;
     } elseif ('cached' == $option_value) {
         $galleries_array = get_transient(MLA_OPTION_PREFIX . 't_' . $option_name);
         if (is_array($galleries_array)) {
             if (!empty($galleries_array)) {
                 return true;
             } else {
                 return false;
             }
         } else {
             $galleries_array = NULL;
         }
     }
     // cached
     /*
      * $galleries_array is null, so build the array
      */
     $galleries_array = array();
     if ($exclude_revisions) {
         $exclude_revisions = "(post_type <> 'revision') AND ";
     } else {
         $exclude_revisions = '';
     }
     if (self::$wp_4dot0_plus) {
         $like = $wpdb->esc_like($shortcode);
     } else {
         $like = like_escape($shortcode);
     }
     $results = $wpdb->get_results($wpdb->prepare("\r\r\n\t\t\t\tSELECT ID, post_type, post_status, post_title, post_content\r\r\n\t\t\t\tFROM {$wpdb->posts}\r\r\n\t\t\t\tWHERE {$exclude_revisions}(\r\r\n\t\t\t\t\tCONVERT(`post_content` USING utf8 )\r\r\n\t\t\t\t\tLIKE %s)\r\r\n\t\t\t\t", "%{$like}%"));
     if (empty($results)) {
         return false;
     }
     foreach ($results as $result) {
         $count = preg_match_all("/\\{$shortcode}([^\\]]*)\\]/", $result->post_content, $matches, PREG_PATTERN_ORDER);
         if ($count) {
             $result_id = $result->ID;
             $galleries_array[$result_id]['parent_title'] = $result->post_title;
             $galleries_array[$result_id]['parent_type'] = $result->post_type;
             $galleries_array[$result_id]['parent_status'] = $result->post_status;
             $galleries_array[$result_id]['results'] = array();
             $galleries_array[$result_id]['galleries'] = array();
             $instance = 0;
             foreach ($matches[1] as $index => $match) {
                 /*
                  * Filter out shortcodes that are not an exact match
                  */
                 if (empty($match) || ' ' == substr($match, 0, 1)) {
                     $instance++;
                     /*
                      * Remove trailing "/" from XHTML-style self-closing shortcodes
                      */
                     $galleries_array[$result_id]['galleries'][$instance]['query'] = trim(rtrim($matches[1][$index], '/'));
                     $galleries_array[$result_id]['galleries'][$instance]['results'] = array();
                     $post = $result;
                     // set global variable for mla_gallery_shortcode
                     $attachments = MLAShortcodes::mla_get_shortcode_attachments($result_id, $galleries_array[$result_id]['galleries'][$instance]['query'] . ' cache_results=false update_post_meta_cache=false update_post_term_cache=false where_used_query=this-is-a-where-used-query');
                     if (is_string($attachments)) {
                         /* translators: 1: post_type, 2: post_title, 3: post ID, 4: query string, 5: error message */
                         trigger_error(htmlentities(sprintf(__('(%1$s) %2$s (ID %3$d) query "%4$s" failed, returning "%5$s"', 'media-library-assistant'), $result->post_type, $result->post_title, $result->ID, $galleries_array[$result_id]['galleries'][$instance]['query'], $attachments)), E_USER_WARNING);
                     } elseif (!empty($attachments)) {
                         foreach ($attachments as $attachment) {
                             $galleries_array[$result_id]['results'][$attachment->ID] = $attachment->ID;
                             $galleries_array[$result_id]['galleries'][$instance]['results'][] = $attachment->ID;
                         }
                     }
                 }
                 // exact match
             }
             // foreach $match
         }
         // if $count
     }
     // foreach $result
     /*
      * Maybe cache the results
      */
     if ('cached' == $option_value) {
         set_transient(MLA_OPTION_PREFIX . 't_' . $option_name, $galleries_array, 900);
         // fifteen minutes
     }
     return true;
 }
Ejemplo n.º 16
0
 /**
  * Read a serialized file of option settings and write them to the database
  *
  * @since 1.50
  *
  * @return	array	Message(s) reflecting the results of the operation
  */
 private static function _import_settings()
 {
     $page_content = array('message' => 'No settings imported.', 'body' => '');
     $message_list = '';
     if (isset($_REQUEST['mla-import-settings-file'])) {
         $filename = $_REQUEST['mla-import-settings-file'];
         if ('none' != $filename) {
             $filename = MLA_BACKUP_DIR . $filename;
         } else {
             $page_content['message'] = 'Please select an import settings file from the dropdown list.';
             return $page_content;
         }
     } else {
         $page_content['message'] = "ERROR: The import settings dropdown selection is missing.";
         return $page_content;
     }
     $settings = @file_get_contents($filename, false);
     if (false === $settings) {
         $error_info = error_get_last();
         error_log('ERROR: _import_settings $error_info = ' . var_export($error_info, true), 0);
         if (false !== ($tail = strpos($error_info['message'], '</a>]: '))) {
             $php_errormsg = ':<br>' . substr($error_info['message'], $tail + 7);
         } else {
             $php_errormsg = '.';
         }
         $page_content['message'] = "ERROR: reading the settings file ( {$filename} ){$php_errormsg}";
         return $page_content;
     }
     $settings = unserialize($settings);
     $updated_count = 0;
     $unchanged_count = 0;
     foreach ($settings as $key => $value) {
         if (MLAOptions::mla_update_option($key, $value)) {
             $updated_count++;
             $message_list .= "<br>{$key} updated";
         } else {
             $unchanged_count++;
             $message_list .= "<br>{$key} unchanged";
         }
     }
     $page_content['message'] = "Settings imported; {$updated_count} updated, {$unchanged_count} unchanged.";
     /*
      * Uncomment this for debugging.
      */
     //$page_content['message'] .= $message_list;
     return $page_content;
 }
 /**
  * Begin an MLA_List_Table bulk action
  *
  * Prepare the thumbnail generation options.
  *
  * @since 2.13
  *
  * @param	array	$item_content	NULL, to indicate no handler.
  * @param	string	$bulk_action	the requested action.
  */
 public static function mla_list_table_begin_bulk_action($item_content, $bulk_action)
 {
     if (self::MLA_GFI_ACTION != $bulk_action) {
         return $item_content;
     }
     self::$bulk_action_options = array();
     $request_options = isset($_REQUEST['mla_thumbnail_options']) ? $_REQUEST['mla_thumbnail_options'] : array();
     $request_options['ghostscript_path'] = MLAOptions::mla_get_option('ghostscript_path');
     if (empty($request_options['existing_thumbnails'])) {
         $request_options['existing_thumbnails'] = 'keep';
     }
     foreach ($request_options as $key => $value) {
         if (!empty($value)) {
             self::$bulk_action_options[$key] = $value;
         }
     }
     // Convert checkboxes to booleans
     self::$bulk_action_options['best_fit'] = isset($request_options['best_fit']);
     self::$bulk_action_options['clear_filters'] = isset($request_options['clear_filters']);
     // Convert page number to frame
     if (isset(self::$bulk_action_options['page'])) {
         $page = abs(intval(self::$bulk_action_options['page']));
         self::$bulk_action_options['frame'] = 0 < $page ? $page - 1 : 0;
         unset(self::$bulk_action_options['page']);
     }
     return $item_content;
 }
 /**
  * Delete saved settings, restoring default values
  *
  * @since 2.11
  *
  * @return	array	Message(s) reflecting the results of the operation
  */
 private static function _reset_language_settings()
 {
     $message_list = '';
     foreach (MLA_Polylang::$mla_language_option_definitions as $key => $value) {
         if ('language' == $value['tab']) {
             if ('custom' == $value['type'] && isset($value['reset'])) {
                 $message = MLA_Polylang::$value['reset']('reset', $key, $value, $_REQUEST);
             } elseif ('header' == $value['type'] || 'hidden' == $value['type']) {
                 $message = '';
             } else {
                 MLAOptions::mla_delete_option($key, MLA_Polylang::$mla_language_option_definitions);
                 /* translators: 1: option name */
                 $message = '<br>' . sprintf(_x('delete_option "%1$s"', 'message_list', 'media-library-assistant'), $key);
             }
             $message_list .= $message;
         }
     }
     $page_content = array('message' => __('Language settings reset to default values.', 'media-library-assistant') . "\n", 'body' => '');
     /*
      * Uncomment this for debugging.
      */
     //$page_content['message'] .= $message_list;
     return $page_content;
 }
Ejemplo n.º 19
0
    /**
     * Display taxonomy "checklist" form fields
     *
     * Adapted from /wp-admin/includes/ajax-actions.php function _wp_ajax_add_hierarchical_term().
     * Includes the "? Search" area to filter the term checklist by entering part
     * or all of a word/phrase in the term label.
     * Output to the Media/Edit Media screen and to the Media Manager Modal Window.
     *
     * @since 1.71
     *
     * @param object The current post
     * @param array The meta box parameters
     *
     * @return void Echoes HTML for the form fields
     */
    public static function mla_checklist_meta_box($target_post, $box)
    {
        global $post;
        $defaults = array('taxonomy' => 'category', 'in_modal' => false);
        $post_id = $target_post->ID;
        if (!isset($box['args']) || !is_array($box['args'])) {
            $args = array();
        } else {
            $args = $box['args'];
        }
        extract(wp_parse_args($args, $defaults), EXTR_SKIP);
        $tax = get_taxonomy($taxonomy);
        $name = $taxonomy == 'category' ? 'post_category' : 'tax_input[' . $taxonomy . ']';
        /*
         * Id and Name attributes in the popup Modal Window must not conflict with
         * the underlying Edit Post/Page window, so we prefix with "mla-"/"mla_".
         */
        if ($in_modal) {
            if (empty($post)) {
                $post = $target_post;
                // for wp_popular_terms_checklist
            }
            $div_taxonomy_id = "mla-taxonomy-{$taxonomy}";
            $tabs_ul_id = "mla-{$taxonomy}-tabs";
            $tab_all_id = "mla-{$taxonomy}-all";
            $tab_all_ul_id = "mla-{$taxonomy}-checklist";
            $tab_pop_id = "mla-{$taxonomy}-pop";
            $tab_pop_ul_id = "mla-{$taxonomy}-checklist-pop";
            $input_terms_name = "mla_attachments[{$post_id}][{$name}][]";
            $input_terms_id = "mla-{$name}-id";
            $div_adder_id = "mla-{$taxonomy}-adder";
            $div_adder_class = "mla-hidden-children";
            $link_adder_id = "mla-{$taxonomy}-add-toggle";
            $link_adder_p_id = "mla-{$taxonomy}-add";
            $div_search_id = "mla-{$taxonomy}-searcher";
            $div_search_class = "mla-hidden-children";
            $link_search_id = "mla-{$taxonomy}-search-toggle";
            $link_search_p_id = "mla-{$taxonomy}-search";
            $input_new_name = "new{$taxonomy}";
            $input_new_id = "mla-new-{$taxonomy}";
            $input_new_parent_name = "new{$taxonomy}_parent";
            $input_new_submit_id = "mla-{$taxonomy}-add-submit";
            $span_new_ajax_id = "mla-{$taxonomy}-ajax-response";
            $input_search_name = "search-{$taxonomy}";
            $input_search_id = "mla-search-{$taxonomy}";
            $span_search_ajax_id = "mla-{$taxonomy}-search-ajax-response";
        } else {
            $div_taxonomy_id = "taxonomy-{$taxonomy}";
            $tabs_ul_id = "{$taxonomy}-tabs";
            $tab_all_id = "{$taxonomy}-all";
            $tab_all_ul_id = "{$taxonomy}checklist";
            $tab_pop_id = "{$taxonomy}-pop";
            $tab_pop_ul_id = "{$taxonomy}checklist-pop";
            $input_terms_name = "{$name}[]";
            $input_terms_id = "{$name}-id";
            $div_adder_id = "{$taxonomy}-adder";
            $div_adder_class = "wp-hidden-children";
            $link_adder_id = "{$taxonomy}-add-toggle";
            $link_adder_p_id = "{$taxonomy}-add";
            $div_search_id = "{$taxonomy}-searcher";
            $div_search_class = "wp-hidden-children";
            $link_search_id = "{$taxonomy}-search-toggle";
            $link_search_p_id = "{$taxonomy}-search";
            $input_new_name = "new{$taxonomy}";
            $input_new_id = "new{$taxonomy}";
            $input_new_parent_name = "new{$taxonomy}_parent";
            $input_new_submit_id = "{$taxonomy}-add-submit";
            $span_new_ajax_id = "{$taxonomy}-ajax-response";
            $input_search_name = "search-{$taxonomy}";
            $input_search_id = "search-{$taxonomy}";
            $span_search_ajax_id = "{$taxonomy}-search-ajax-response";
        }
        ?>
		<div id="<?php 
        echo $div_taxonomy_id;
        ?>
" class="categorydiv">
			<ul id="<?php 
        echo $tabs_ul_id;
        ?>
" class="category-tabs">
				<li class="tabs"><a href="#<?php 
        echo $tab_all_id;
        ?>
"><?php 
        echo $tax->labels->all_items;
        ?>
</a></li>
				<li class="hide-if-no-js"><a href="#<?php 
        echo $tab_pop_id;
        ?>
"><?php 
        _e('Most Used');
        ?>
</a></li>
			</ul>

			<div id="<?php 
        echo $tab_pop_id;
        ?>
" class="tabs-panel" style="display: none;">
				<ul id="<?php 
        echo $tab_pop_ul_id;
        ?>
" class="categorychecklist form-no-clear" >
					<?php 
        $popular_ids = wp_popular_terms_checklist($taxonomy);
        ?>
				</ul>
			</div>

			<div id="<?php 
        echo $tab_all_id;
        ?>
" class="tabs-panel">
				<?php 
        // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
        echo "<input type='hidden' name='{$input_terms_name}' id='{$input_terms_id}' value='0' />";
        ?>
				<ul id="<?php 
        echo $tab_all_ul_id;
        ?>
" data-wp-lists="list:<?php 
        echo $taxonomy;
        ?>
" class="categorychecklist form-no-clear">
					<?php 
        if ($tax->hierarchical) {
            ?>
					<?php 
            wp_terms_checklist($post->ID, array('taxonomy' => $taxonomy, 'popular_cats' => $popular_ids, 'checked_ontop' => MLAOptions::mla_taxonomy_support($taxonomy, 'checked-on-top')));
            ?>
					<?php 
        } else {
            ?>
                    <?php 
            $checklist_walker = new MLA_Checklist_Walker();
            ?>
					<?php 
            wp_terms_checklist($post->ID, array('taxonomy' => $taxonomy, 'popular_cats' => $popular_ids, 'checked_ontop' => MLAOptions::mla_taxonomy_support($taxonomy, 'checked-on-top'), 'walker' => $checklist_walker));
            ?>
					<?php 
        }
        ?>
				</ul>
			</div>
		<?php 
        if (current_user_can($tax->cap->edit_terms)) {
            ?>
				<div id="<?php 
            echo $div_adder_id;
            ?>
" class="<?php 
            echo $div_adder_class;
            ?>
">
					<h4>
						<a id="<?php 
            echo $link_adder_id;
            ?>
" href="#<?php 
            echo $link_adder_p_id;
            ?>
" class="hide-if-no-js">
							<?php 
            /* translators: %s: add new taxonomy label */
            printf(__('+ %s', 'media-library-assistant'), $tax->labels->add_new_item);
            ?>
						</a>
						&nbsp;&nbsp;
						<a id="<?php 
            echo $link_search_id;
            ?>
" href="#<?php 
            echo $link_search_p_id;
            ?>
" class="hide-if-no-js">
							<?php 
            echo '?&nbsp;' . __('Search', 'media-library-assistant');
            ?>
						</a>
					</h4>
					<p id="<?php 
            echo $link_adder_p_id;
            ?>
" class="category-add wp-hidden-child">
						<label class="screen-reader-text" for="<?php 
            echo $input_new_name;
            ?>
"><?php 
            echo $tax->labels->add_new_item;
            ?>
</label>
						<input type="text" name="<?php 
            echo $input_new_name;
            ?>
" id="<?php 
            echo $input_new_id;
            ?>
" class="form-required form-input-tip" value="<?php 
            echo esc_attr($tax->labels->new_item_name);
            ?>
" aria-required="true"/>

						<?php 
            if ($tax->hierarchical) {
                ?>
						<label class="screen-reader-text" for="<?php 
                echo $input_new_parent_name;
                ?>
">
							<?php 
                echo $tax->labels->parent_item_colon;
                ?>
						</label>
						<?php 
                wp_dropdown_categories(array('taxonomy' => $taxonomy, 'hide_empty' => 0, 'name' => $input_new_parent_name, 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => '&mdash; ' . $tax->labels->parent_item . ' &mdash;'));
                ?>
						<?php 
            } else {
                echo "<input type='hidden' name='{$input_new_parent_name}' id='{$input_new_parent_name}' value='-1' />";
            }
            ?>
						<input type="button" id="<?php 
            echo $input_new_submit_id;
            ?>
" data-wp-lists="add:<?php 
            echo $tab_all_ul_id;
            ?>
:<?php 
            echo $link_adder_p_id;
            ?>
" class="button category-add-submit mla-taxonomy-add-submit" value="<?php 
            echo esc_attr($tax->labels->add_new_item);
            ?>
" />
						<?php 
            wp_nonce_field('add-' . $taxonomy, '_ajax_nonce-add-' . $taxonomy, false);
            ?>
						<span id="<?php 
            echo $span_new_ajax_id;
            ?>
"></span>
					</p>
				</div>
				<div id="<?php 
            echo $div_search_id;
            ?>
" class="<?php 
            echo $div_search_class;
            ?>
">
					<p id="<?php 
            echo $link_search_p_id;
            ?>
" class="category-add wp-hidden-child">
						<label class="screen-reader-text" for="<?php 
            echo $input_search_name;
            ?>
"><?php 
            echo $tax->labels->search_items;
            ?>
</label>
						<input type="text" name="<?php 
            echo $input_search_name;
            ?>
" id="<?php 
            echo $input_search_id;
            ?>
" class="form-required form-input-tip" value="<?php 
            echo esc_attr($tax->labels->search_items);
            ?>
" aria-required="true"/>
						<?php 
            wp_nonce_field('search-' . $taxonomy, '_ajax_nonce-search-' . $taxonomy, false);
            ?>
						<span id="<?php 
            echo $span_search_ajax_id;
            ?>
"></span>
					</p>
				</div>
			<?php 
        }
        ?>
		</div>
		<?php 
    }
Ejemplo n.º 20
0
 /**
  * Save IPTC/EXIF settings to the options table
  *
  * @since 1.00
  *
  * @uses $_REQUEST
  *
  * @return	array	Message(s) reflecting the results of the operation
  */
 private static function _save_iptc_exif_settings()
 {
     $message_list = '';
     $option_messages = '';
     /*
      * Start with any page-level options
      */
     foreach (MLACore::$mla_option_definitions as $key => $value) {
         if ('iptc_exif' == $value['tab']) {
             $option_messages .= self::mla_update_option_row($key, $value);
         }
     }
     /*
      * Uncomment this for debugging.
      */
     // $message_list = $option_messages . '<br>';
     /*
      * Add mapping options
      */
     $new_values = isset($_REQUEST['iptc_exif_mapping']) ? $_REQUEST['iptc_exif_mapping'] : array('standard' => array(), 'taxonomy' => array(), 'custom' => array());
     return array('message' => $message_list . MLAOptions::mla_iptc_exif_option_handler('update', 'iptc_exif_mapping', MLACore::$mla_option_definitions['iptc_exif_mapping'], $new_values), 'body' => '');
 }
Ejemplo n.º 21
0
 /**
  * Store the options portion of the Upload MIME Types 
  *
  * @since 1.40
  *
  * @return	boolean	Success (true) or failure (false) of the operation
  */
 private static function _put_upload_mime_templates()
 {
     $mla_upload_mimes = array('custom' => array(), 'disabled' => array(), 'description' => array(), 'icon_type' => array());
     foreach (self::$mla_upload_mime_templates as $key => $value) {
         if ('custom' == $value['source']) {
             $mla_upload_mimes['custom'][$key] = $value['mime_type'];
         }
         if ($value['disabled']) {
             $mla_upload_mimes['disabled'][$key] = true;
         }
         $description = trim($value['description']);
         if (!empty($description) && $description != self::$mla_upload_mime_descriptions[$key]) {
             $mla_upload_mimes['description'][$key] = $description;
         }
         if ($value['icon_type'] != $value['core_icon_type']) {
             $mla_upload_mimes['icon_type'][$key] = $value['icon_type'];
         }
     }
     MLAOptions::mla_update_option(MLAOptions::MLA_UPLOAD_MIMES, $mla_upload_mimes);
     return true;
 }
 /**
  * Add rollover actions to a table column
  *
  * @since 1.40
  * 
  * @param	object	An MLA post_mime_type object
  * @param	string	Current column name
  *
  * @return	array	Names and URLs of row-level actions
  */
 private function _build_rollover_actions($item, $column)
 {
     $actions = array();
     /*
      * Compose view arguments
      */
     $view_args = array('page' => MLASettings::MLA_SETTINGS_SLUG . '-view', 'mla_tab' => 'view', 'mla_item_slug' => urlencode($item->slug));
     if (isset($_REQUEST['paged'])) {
         $view_args['paged'] = $_REQUEST['paged'];
     }
     if (isset($_REQUEST['order'])) {
         $view_args['order'] = $_REQUEST['order'];
     }
     if (isset($_REQUEST['orderby'])) {
         $view_args['orderby'] = $_REQUEST['orderby'];
     }
     /*
      * Get the standard and custom types
      */
     $mla_types = MLAOptions::mla_get_option(MLAOptions::MLA_POST_MIME_TYPES, true);
     if (!is_array($mla_types)) {
         $mla_types = array();
     }
     $custom_types = MLAOptions::mla_get_option(MLAOptions::MLA_POST_MIME_TYPES, false, true);
     if (!is_array($custom_types)) {
         $custom_types = array();
     }
     $actions['edit'] = '<a href="' . add_query_arg($view_args, wp_nonce_url('?mla_admin_action=' . MLA::MLA_ADMIN_SINGLE_EDIT_DISPLAY, MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME)) . '" title="' . __('Edit this item', 'media-library-assistant') . '">' . __('Edit', 'media-library-assistant') . '</a>';
     $actions['inline hide-if-no-js'] = '<a class="editinline" href="#" title="' . __('Edit this item inline', 'media-library-assistant') . '">' . __('Quick Edit', 'media-library-assistant') . '</a>';
     if (isset($custom_types[$item->slug])) {
         if (isset($mla_types[$item->slug])) {
             $actions['delete'] = '<a class="delete-tag"' . ' href="' . add_query_arg($view_args, wp_nonce_url('?mla_admin_action=' . MLA::MLA_ADMIN_SINGLE_DELETE, MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME)) . '" title="' . __('Revert to standard item', 'media-library-assistant') . '">' . __('Revert to Standard', 'media-library-assistant') . '</a>';
         } else {
             $actions['delete'] = '<a class="delete-tag"' . ' href="' . add_query_arg($view_args, wp_nonce_url('?mla_admin_action=' . MLA::MLA_ADMIN_SINGLE_DELETE, MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME)) . '" title="' . __('Delete this item Permanently', 'media-library-assistant') . '">' . __('Delete Permanently', 'media-library-assistant') . '</a>';
         }
     }
     // custom type
     return $actions;
 }
if (!empty($_REQUEST['s'])) {
    $search_value = esc_attr(stripslashes(trim($_REQUEST['s'])));
    $search_fields = isset($_REQUEST['mla_search_fields']) ? $_REQUEST['mla_search_fields'] : array();
    $search_connector = $_REQUEST['mla_search_connector'];
} else {
    $search_value = MLAOptions::mla_get_option(MLAOptions::MLA_SEARCH_MEDIA_FILTER_DEFAULTS);
    $search_fields = $search_value['search_fields'];
    $search_connector = $search_value['search_connector'];
    $search_value = '';
}
if ('checked' == MLAOptions::mla_get_option(MLAOptions::MLA_SEARCH_MEDIA_FILTER_SHOW_CONTROLS)) {
    $controls_style = 'style="display: inline;"';
} else {
    $controls_style = 'style="display: none;"';
}
$supported_taxonomies = MLAOptions::mla_supported_taxonomies('support');
if (empty($supported_taxonomies)) {
    $terms_style = 'style="display: none;"';
    unset($search_fields['terms']);
} else {
    $terms_style = 'style="display: inline;"';
}
?>
<p class="search-box">
<label class="screen-reader-text" for="mla-media-search-input"><?php 
_e('Search Media', 'media-library-assistant');
?>
</label>
<input name="s" id="mla-media-search-input" type="text" size="45" value="<?php 
echo $search_value;
?>
Ejemplo n.º 24
0
 /**
  * Render and manage iptc/exif support options
  *
  * @since 1.00
  * @uses $mla_option_templates contains row and table templates
  *
  * @param	string 	'render', 'update', 'delete', or 'reset'
  * @param	string 	option name, e.g., 'iptc_exif_mapping'
  * @param	array 	option parameters
  * @param	array 	Optional. null (default) for 'render' else option data, e.g., $_REQUEST
  *
  * @return	string	HTML table row markup for 'render' else message(s) reflecting the results of the operation.
  */
 public static function mla_iptc_exif_option_handler($action, $key, $value, $args = NULL)
 {
     $current_values = MLACore::mla_get_option('iptc_exif_mapping');
     switch ($action) {
         case 'render':
             switch ($key) {
                 case 'iptc_exif_standard_mapping':
                     $row_template = MLAOptions::$mla_option_templates['iptc-exif-standard-row'];
                     $table_rows = '';
                     foreach ($current_values['standard'] as $row_name => $row_value) {
                         $row_values = array('key' => esc_attr($row_name), 'name_attr' => esc_attr($row_value['name']), 'name' => esc_html($row_value['name']), 'iptc_field_options' => MLAOptions::_compose_iptc_option_list($row_value['iptc_value']), 'exif_size' => MLACoreOptions::MLA_EXIF_SIZE, 'exif_text' => esc_attr($row_value['exif_value']), 'iptc_selected' => '', 'IPTC' => __('IPTC', 'media-library-assistant'), 'exif_selected' => '', 'EXIF' => __('EXIF', 'media-library-assistant'), 'keep_selected' => '', 'Keep' => __('Keep', 'media-library-assistant'), 'replace_selected' => '', 'Replace' => __('Replace', 'media-library-assistant'));
                         if ($row_value['iptc_first']) {
                             $row_values['iptc_selected'] = 'selected="selected"';
                         } else {
                             $row_values['exif_selected'] = 'selected="selected"';
                         }
                         if ($row_value['keep_existing']) {
                             $row_values['keep_selected'] = 'selected="selected"';
                         } else {
                             $row_values['replace_selected'] = 'selected="selected"';
                         }
                         $table_rows .= MLAData::mla_parse_template($row_template, $row_values);
                     }
                     // foreach row
                     $option_values = array('Field Title' => __('Field Title', 'media-library-assistant'), 'IPTC Value' => __('IPTC Value', 'media-library-assistant'), 'EXIF/Template Value' => __('EXIF/Template Value', 'media-library-assistant'), 'Priority' => __('Priority', 'media-library-assistant'), 'Existing Text' => __('Existing Text', 'media-library-assistant'), 'table_rows' => $table_rows, 'help' => $value['help']);
                     return MLAData::mla_parse_template(MLAOptions::$mla_option_templates['iptc-exif-standard-table'], $option_values);
                 case 'iptc_exif_taxonomy_mapping':
                     $row_template = MLAOptions::$mla_option_templates['iptc-exif-taxonomy-row'];
                     $select_template = MLAOptions::$mla_option_templates['iptc-exif-select'];
                     $table_rows = '';
                     $taxonomies = get_taxonomies(array('show_ui' => true), 'objects');
                     foreach ($taxonomies as $row_name => $row_value) {
                         if (!MLACore::mla_taxonomy_support($row_name, 'support')) {
                             continue;
                         }
                         $row_values = array('key' => esc_attr($row_name), 'name' => esc_html($row_value->labels->name), 'hierarchical' => (string) $row_value->hierarchical, 'iptc_field_options' => '', 'exif_size' => MLACoreOptions::MLA_EXIF_SIZE, 'exif_text' => '', 'iptc_selected' => '', 'IPTC' => __('IPTC', 'media-library-assistant'), 'exif_selected' => '', 'EXIF' => __('EXIF', 'media-library-assistant'), 'keep_selected' => '', 'Keep' => __('Keep', 'media-library-assistant'), 'replace_selected' => '', 'Replace' => __('Replace', 'media-library-assistant'), 'delimiters_size' => 4, 'delimiters_text' => '', 'parent_select' => '');
                         if (array_key_exists($row_name, $current_values['taxonomy'])) {
                             $current_value = $current_values['taxonomy'][$row_name];
                             $row_values['iptc_field_options'] = MLAOptions::_compose_iptc_option_list($current_value['iptc_value']);
                             $row_values['exif_text'] = esc_attr($current_value['exif_value']);
                             if ($current_value['iptc_first']) {
                                 $row_values['iptc_selected'] = 'selected="selected"';
                             } else {
                                 $row_values['exif_selected'] = 'selected="selected"';
                             }
                             if ($current_value['keep_existing']) {
                                 $row_values['keep_selected'] = 'selected="selected"';
                             } else {
                                 $row_values['replace_selected'] = 'selected="selected"';
                             }
                             $row_values['delimiters_text'] = $current_value['delimiters'];
                             if ($row_value->hierarchical) {
                                 $parent = isset($current_value['parent']) ? (int) $current_value['parent'] : 0;
                                 $select_values = array('array' => 'taxonomy', 'key' => esc_attr($row_name), 'element' => 'parent', 'options' => MLAOptions::_compose_parent_option_list($row_name, $parent));
                                 $row_values['parent_select'] = MLAData::mla_parse_template($select_template, $select_values);
                             }
                         } else {
                             $row_values['iptc_field_options'] = MLAOptions::_compose_iptc_option_list('none');
                             $row_values['iptc_selected'] = 'selected="selected"';
                             $row_values['keep_selected'] = 'selected="selected"';
                             if ($row_value->hierarchical) {
                                 $select_values = array('array' => 'taxonomy', 'key' => esc_attr($row_name), 'element' => 'parent', 'options' => MLAOptions::_compose_parent_option_list($row_name, 0));
                                 $row_values['parent_select'] = MLAData::mla_parse_template($select_template, $select_values);
                             }
                         }
                         $table_rows .= MLAData::mla_parse_template($row_template, $row_values);
                     }
                     // foreach row
                     $option_values = array('Field Title' => __('Field Title', 'media-library-assistant'), 'IPTC Value' => __('IPTC Value', 'media-library-assistant'), 'EXIF/Template Value' => __('EXIF/Template Value', 'media-library-assistant'), 'Priority' => __('Priority', 'media-library-assistant'), 'Existing Text' => __('Existing Text', 'media-library-assistant'), 'Delimiter(s)' => __('Delimiter(s)', 'media-library-assistant'), 'Parent' => __('Parent', 'media-library-assistant'), 'table_rows' => $table_rows, 'help' => $value['help']);
                     return MLAData::mla_parse_template(MLAOptions::$mla_option_templates['iptc-exif-taxonomy-table'], $option_values);
                 case 'iptc_exif_custom_mapping':
                     if (empty($current_values['custom'])) {
                         $table_rows = MLAData::mla_parse_template(MLAOptions::$mla_option_templates['iptc-exif-custom-empty-row'], array('No Mapping Rules' => __('No Custom Field Mapping Rules Defined', 'media-library-assistant'), 'column_count' => 5));
                     } else {
                         $row_template = MLAOptions::$mla_option_templates['iptc-exif-custom-rule-row'];
                         $table_rows = '';
                         $index = 0;
                     }
                     /*
                      * One row for each existing rule, case insensitive "natural order"
                      */
                     $sorted_keys = array();
                     foreach ($current_values['custom'] as $row_name => $current_value) {
                         $sorted_keys[$current_value['name']] = $current_value['name'];
                     }
                     natcasesort($sorted_keys);
                     $sorted_names = array();
                     foreach ($sorted_keys as $row_name) {
                         $sorted_names[$row_name] = array();
                     }
                     /*
                      * Allow for multiple rules mapping the same name (an old bug)
                      */
                     foreach ($current_values['custom'] as $row_name => $current_value) {
                         $sorted_names[$current_value['name']][] = $row_name;
                     }
                     foreach ($sorted_names as $sorted_keys) {
                         foreach ($sorted_keys as $row_name) {
                             $current_value = $current_values['custom'][$row_name];
                             $row_values = array('column_count' => 5, 'column_count_meta' => 5 - 2, 'index' => $index++, 'key' => esc_attr($row_name), 'name_attr' => esc_attr($current_value['name']), 'name' => esc_html($current_value['name']), 'iptc_field_options' => MLAOptions::_compose_iptc_option_list($current_value['iptc_value']), 'exif_size' => MLACoreOptions::MLA_EXIF_SIZE, 'exif_text' => esc_attr($current_value['exif_value']), 'iptc_selected' => '', 'IPTC' => __('IPTC', 'media-library-assistant'), 'exif_selected' => '', 'EXIF' => __('EXIF', 'media-library-assistant'), 'keep_selected' => '', 'Keep' => __('Keep', 'media-library-assistant'), 'replace_selected' => '', 'Replace' => __('Replace', 'media-library-assistant'), 'Format' => __('Format', 'media-library-assistant'), 'native_format' => '', 'Native' => __('Native', 'media-library-assistant'), 'commas_format' => '', 'Commas' => __('Commas', 'media-library-assistant'), 'raw_format' => '', 'Raw' => __('Raw', 'media-library-assistant'), 'Option' => __('Option', 'media-library-assistant'), 'text_option' => '', 'Text' => __('Text', 'media-library-assistant'), 'single_option' => '', 'Single' => __('Single', 'media-library-assistant'), 'export_option' => '', 'Export' => __('Export', 'media-library-assistant'), 'array_option' => '', 'Array' => __('Array', 'media-library-assistant'), 'multi_option' => '', 'Multi' => __('Multi', 'media-library-assistant'), 'no_null_checked' => '', 'Delete NULL values' => __('Delete NULL values', 'media-library-assistant'), 'Delete Rule' => __('Delete Rule', 'media-library-assistant'), 'Delete Field' => __('Delete Rule AND Field', 'media-library-assistant'), 'Update Rule' => __('Update Rule', 'media-library-assistant'), 'Map All Attachments' => __('Map All Attachments', 'media-library-assistant'));
                             if ($current_value['iptc_first']) {
                                 $row_values['iptc_selected'] = 'selected="selected"';
                             } else {
                                 $row_values['exif_selected'] = 'selected="selected"';
                             }
                             if ($current_value['keep_existing']) {
                                 $row_values['keep_selected'] = 'selected="selected"';
                             } else {
                                 $row_values['replace_selected'] = 'selected="selected"';
                             }
                             switch ($current_value['format']) {
                                 case 'commas':
                                     $row_values['commas_format'] = 'selected="selected"';
                                     break;
                                 case 'raw':
                                     $row_values['raw_format'] = 'selected="selected"';
                                     break;
                                 default:
                                     $row_values['native_format'] = 'selected="selected"';
                             }
                             // format
                             switch ($current_value['option']) {
                                 case 'single':
                                     $row_values['single_option'] = 'selected="selected"';
                                     break;
                                 case 'export':
                                     $row_values['export_option'] = 'selected="selected"';
                                     break;
                                 case 'array':
                                     $row_values['array_option'] = 'selected="selected"';
                                     break;
                                 case 'multi':
                                     $row_values['multi_option'] = 'selected="selected"';
                                     break;
                                 default:
                                     $row_values['text_option'] = 'selected="selected"';
                             }
                             // option
                             if ($current_value['no_null']) {
                                 $row_values['no_null_checked'] = 'checked="checked"';
                             }
                             $table_rows .= MLAData::mla_parse_template($row_template, $row_values);
                         }
                         // foreach current_values key
                     }
                     // foreach sorted_name
                     /*
                      * Add a row for defining a new rule, existing Custom Field
                      */
                     $row_template = MLAOptions::$mla_option_templates['iptc-exif-custom-new-rule-row'];
                     $row_values = array('column_count' => 5, 'column_count_meta' => 5 - 2, 'Add new Rule' => __('Add a new Mapping Rule', 'media-library-assistant'), 'index' => MLACoreOptions::MLA_NEW_CUSTOM_RULE, 'field_name_options' => MLAOptions::_compose_custom_field_option_list('none', $current_values['custom']), 'iptc_field_options' => MLAOptions::_compose_iptc_option_list('none'), 'exif_size' => MLACoreOptions::MLA_EXIF_SIZE, 'exif_text' => '', 'iptc_selected' => 'selected="selected"', 'IPTC' => __('IPTC', 'media-library-assistant'), 'exif_selected' => '', 'EXIF' => __('EXIF', 'media-library-assistant'), 'keep_selected' => 'selected="selected"', 'Keep' => __('Keep', 'media-library-assistant'), 'replace_selected' => '', 'Replace' => __('Replace', 'media-library-assistant'), 'Format' => __('Format', 'media-library-assistant'), 'native_format' => 'selected="selected"', 'Native' => __('Native', 'media-library-assistant'), 'commas_format' => '', 'Commas' => __('Commas', 'media-library-assistant'), 'raw_format' => '', 'Raw' => __('Raw', 'media-library-assistant'), 'Option' => __('Option', 'media-library-assistant'), 'text_option' => '', 'Text' => __('Text', 'media-library-assistant'), 'single_option' => '', 'Single' => __('Single', 'media-library-assistant'), 'export_option' => '', 'Export' => __('Export', 'media-library-assistant'), 'array_option' => '', 'Array' => __('Array', 'media-library-assistant'), 'multi_option' => '', 'Multi' => __('Multi', 'media-library-assistant'), 'no_null_checked' => '', 'Delete NULL values' => __('Delete NULL values', 'media-library-assistant'), 'Add Rule' => __('Add Rule', 'media-library-assistant'), 'Map All Attachments' => __('Add Rule and Map All Attachments', 'media-library-assistant'));
                     $table_rows .= MLAData::mla_parse_template($row_template, $row_values);
                     /*
                      * Add a row for defining a new rule, new Custom Field
                      */
                     $row_template = MLAOptions::$mla_option_templates['iptc-exif-custom-new-field-row'];
                     $row_values = array('column_count' => 5, 'column_count_meta' => 5 - 2, 'Add new Field' => __('Add a new Field and Mapping Rule', 'media-library-assistant'), 'index' => MLACoreOptions::MLA_NEW_CUSTOM_FIELD, 'field_name_size' => '24', 'iptc_field_options' => MLAOptions::_compose_iptc_option_list('none'), 'exif_size' => MLACoreOptions::MLA_EXIF_SIZE, 'exif_text' => '', 'iptc_selected' => 'selected="selected"', 'IPTC' => __('IPTC', 'media-library-assistant'), 'exif_selected' => '', 'EXIF' => __('EXIF', 'media-library-assistant'), 'keep_selected' => 'selected="selected"', 'Keep' => __('Keep', 'media-library-assistant'), 'replace_selected' => '', 'Replace' => __('Replace', 'media-library-assistant'), 'Format' => __('Format', 'media-library-assistant'), 'native_format' => 'selected="selected"', 'Native' => __('Native', 'media-library-assistant'), 'commas_format' => '', 'Commas' => __('Commas', 'media-library-assistant'), 'raw_format' => '', 'Raw' => __('Raw', 'media-library-assistant'), 'Option' => __('Option', 'media-library-assistant'), 'text_option' => '', 'Text' => __('Text', 'media-library-assistant'), 'single_option' => '', 'Single' => __('Single', 'media-library-assistant'), 'export_option' => '', 'Export' => __('Export', 'media-library-assistant'), 'array_option' => '', 'Array' => __('Array', 'media-library-assistant'), 'multi_option' => '', 'Multi' => __('Multi', 'media-library-assistant'), 'no_null_checked' => '', 'Delete NULL values' => __('Delete NULL values', 'media-library-assistant'), 'Add Field' => __('Add Field', 'media-library-assistant'), 'Map All Attachments' => __('Add Field and Map All Attachments', 'media-library-assistant'));
                     $table_rows .= MLAData::mla_parse_template($row_template, $row_values);
                     $option_values = array('Field Title' => __('Field Title', 'media-library-assistant'), 'IPTC Value' => __('IPTC Value', 'media-library-assistant'), 'EXIF/Template Value' => __('EXIF/Template Value', 'media-library-assistant'), 'Priority' => __('Priority', 'media-library-assistant'), 'Existing Text' => __('Existing Text', 'media-library-assistant'), 'table_rows' => $table_rows, 'help' => $value['help']);
                     return MLAData::mla_parse_template(MLAOptions::$mla_option_templates['iptc-exif-custom-table'], $option_values);
                 default:
                     /* translators: 1: ERROR tag 2: option name */
                     return '<br>' . sprintf(__('%1$s: Render unknown custom %2$s.', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $key) . "\r\n";
             }
             // switch $key
         // switch $key
         case 'update':
         case 'delete':
             $settings_changed = false;
             $messages = '';
             switch ($key) {
                 case 'iptc_exif_standard_mapping':
                     $results = MLAOptions::_update_iptc_exif_standard_mapping($current_values, $args);
                     $messages .= $results['message'];
                     $current_values = $results['values'];
                     $settings_changed = $results['changed'];
                     break;
                 case 'iptc_exif_taxonomy_mapping':
                     $results = MLAOptions::_update_iptc_exif_taxonomy_mapping($current_values, $args);
                     $messages .= $results['message'];
                     $current_values = $results['values'];
                     $settings_changed = $results['changed'];
                     break;
                 case 'iptc_exif_custom_mapping':
                     $results = MLAOptions::_update_iptc_exif_custom_mapping($current_values, $args);
                     $messages .= $results['message'];
                     $current_values = $results['values'];
                     $settings_changed = $results['changed'];
                     break;
                 case 'iptc_exif_mapping':
                     $results = MLAOptions::_update_iptc_exif_standard_mapping($current_values, $args);
                     $messages .= $results['message'];
                     $current_values = $results['values'];
                     $settings_changed = $results['changed'];
                     $results = MLAOptions::_update_iptc_exif_taxonomy_mapping($current_values, $args);
                     $messages .= $results['message'];
                     $current_values = $results['values'];
                     $settings_changed |= $results['changed'];
                     $results = MLAOptions::_update_iptc_exif_custom_mapping($current_values, $args);
                     $messages .= $results['message'];
                     $current_values = $results['values'];
                     $settings_changed |= $results['changed'];
                     break;
                 default:
                     /* translators: 1: ERROR tag 2: option name */
                     return '<br>' . sprintf(__('%1$s: Update/delete unknown custom %2$s.', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $key) . "\r\n";
             }
             // switch $key
             if ($settings_changed) {
                 $settings_changed = MLACore::mla_update_option('iptc_exif_mapping', $current_values);
                 if ($settings_changed) {
                     $results = __('IPTC/EXIF mapping settings updated.', 'media-library-assistant') . "\r\n";
                 } else {
                     $results = __('ERROR', 'media-library-assistant') . ': ' . __('IPTC/EXIF settings update failed.', 'media-library-assistant') . "\r\n";
                 }
             } else {
                 $results = __('IPTC/EXIF no mapping changes detected.', 'media-library-assistant') . "\r\n";
             }
             return $results . $messages;
         case 'reset':
             switch ($key) {
                 case 'iptc_exif_standard_mapping':
                     $current_values['standard'] = MLACoreOptions::$mla_option_definitions['iptc_exif_mapping']['std']['standard'];
                     $settings_changed = MLACore::mla_update_option('iptc_exif_mapping', $current_values);
                     if ($settings_changed) {
                         /* translators: 1: field type */
                         return sprintf(__('%1$s settings saved.', 'media-library-assistant'), 'IPTC/EXIF ' . __('Standard field', 'media-library-assistant')) . "\r\n";
                     } else {
                         /* translators: 1: ERROR tag 2: field type */
                         return sprintf(__('%1$s: IPTC/EXIF %2$s settings update failed.', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), __('Standard field', 'media-library-assistant')) . "\r\n";
                     }
                 case 'iptc_exif_taxonomy_mapping':
                     $current_values['taxonomy'] = MLACoreOptions::$mla_option_definitions['iptc_exif_mapping']['std']['taxonomy'];
                     $settings_changed = MLACore::mla_update_option('iptc_exif_mapping', $current_values);
                     if ($settings_changed) {
                         /* translators: 1: field type */
                         return sprintf(__('%1$s settings saved.', 'media-library-assistant'), 'IPTC/EXIF ' . __('Taxonomy term', 'media-library-assistant')) . "\r\n";
                     } else {
                         /* translators: 1: ERROR tag 2: field type */
                         return sprintf(__('%1$s: IPTC/EXIF %2$s settings update failed.', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), __('Taxonomy term', 'media-library-assistant')) . "\r\n";
                     }
                 case 'iptc_exif_custom_mapping':
                     $current_values['custom'] = MLACoreOptions::$mla_option_definitions['iptc_exif_mapping']['std']['custom'];
                     $settings_changed = MLACore::mla_update_option('iptc_exif_mapping', $current_values);
                     if ($settings_changed) {
                         /* translators: 1: field type */
                         return sprintf(__('%1$s settings saved.', 'media-library-assistant'), 'IPTC/EXIF ' . __('Custom field', 'media-library-assistant')) . "\r\n";
                     } else {
                         /* translators: 1: ERROR tag 2: field type */
                         return sprintf(__('%1$s: IPTC/EXIF %2$s settings update failed.', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), __('Custom field', 'media-library-assistant')) . "\r\n";
                     }
                 case 'iptc_exif_mapping':
                     MLACore::mla_delete_option($key);
                     /* translators: 1: option name, e.g., taxonomy_support */
                     return '<br>' . sprintf(__('Reset custom %1$s', 'media-library-assistant'), $key) . "\r\n";
                 default:
                     /* translators: 1: ERROR tag 2: option name, e.g., taxonomy_support */
                     return '<br>' . sprintf(__('%1$s: Reset unknown custom %2$s', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $key) . "\r\n";
             }
             // switch $key
         // switch $key
         default:
             /* translators: 1: ERROR tag 2: option name 3: action, e.g., update, delete, reset */
             return '<br>' . sprintf(__('%1$s: Custom %2$s unknown action "%3$s"', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $key, $action) . "\r\n";
     }
     // switch $action
 }
 /**
  * WordPress Filter for edit taxonomy "Attachments" column,
  * which returns a count of the attachments assigned a given term
  *
  * @since 0.30
  *
  * @param	string	current column value; always ''
  * @param	array	name of the column
  * @param	array	ID of the term for which the count is desired
  *
  * @return	array	HTML markup for the column content; number of attachments in the category
  *					and alink to retrieve a list of them
  */
 public static function mla_taxonomy_column_filter($place_holder, $column_name, $term_id)
 {
     static $taxonomy = NULL, $tax_object = NULL, $count_terms = false, $terms = array();
     /*
      * Do these setup tasks once per page load
      */
     if (NULL == $taxonomy) {
         /*
          * Adding or inline-editing a tag is done with AJAX, and there's no current screen object
          */
         if (defined('DOING_AJAX') && DOING_AJAX) {
             $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag';
         } else {
             $screen = get_current_screen();
             $taxonomy = !empty($screen->taxonomy) ? $screen->taxonomy : 'post_tag';
         }
         $tax_object = get_taxonomy($taxonomy);
         $count_terms = 'checked' == MLAOptions::mla_get_option(MLAOptions::MLA_COUNT_TERM_ATTACHMENTS);
         if ($count_terms) {
             $terms = get_transient(MLA_OPTION_PREFIX . 't_term_counts_' . $taxonomy);
             if (!is_array($terms)) {
                 $cloud = MLAShortcodes::mla_get_terms(array('taxonomy' => $taxonomy, 'fields' => 't.term_id, t.name, t.slug, COUNT(p.ID) AS `count`', 'number' => 0, 'no_orderby' => true));
                 unset($cloud['found_rows']);
                 foreach ($cloud as $term) {
                     $terms[$term->term_id] = $term;
                 }
                 set_transient(MLA_OPTION_PREFIX . 't_term_counts_' . $taxonomy, $terms, 300);
                 // five minutes
             }
             // build the array
         }
         // set $terms
     }
     // setup tasks
     if (isset($terms[$term_id])) {
         $term = $terms[$term_id];
         $column_text = number_format_i18n($term->count);
     } else {
         $term = get_term($term_id, $taxonomy);
         if (is_wp_error($term)) {
             /* translators: 1: ERROR tag 2: taxonomy 3: error message */
             error_log(sprintf(_x('%1$s: mla_taxonomy_column_filter( "%2$s" ) - get_term failed: "%3$s"', 'error_log', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $taxonomy, $term->get_error_message()), 0);
             return 0;
         } elseif ($count_terms) {
             $column_text = number_format_i18n(0);
         } else {
             $column_text = __('click to search', 'media-library-assistant');
         }
     }
     return sprintf('<a href="%1$s">%2$s</a>', esc_url(add_query_arg(array('page' => MLA::ADMIN_PAGE_SLUG, 'mla-tax' => $taxonomy, 'mla-term' => $term->slug, 'heading_suffix' => urlencode($tax_object->label . ':' . $term->name)), 'upload.php')), $column_text);
 }
Ejemplo n.º 26
0
 /**
  * Build the hidden form for the "Search Terms" popup modal window
  *
  * @since 1.90
  *
  * @return	string	HTML <form> markup for hidden form
  */
 public static function mla_terms_search_form()
 {
     $page_template_array = MLAData::mla_load_template('admin-terms-search-form.tpl');
     if (!is_array($page_template_array)) {
         /* translators: 1: ERROR tag 2: function name 3: non-array value */
         error_log(sprintf(_x('%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), 'MLA::_build_terms_search_form', var_export($page_template_array, true)), 0);
         return '';
     }
     $taxonomies = array();
     foreach (get_object_taxonomies('attachment', 'objects') as $taxonomy) {
         if (MLAOptions::mla_taxonomy_support($taxonomy->name, 'support')) {
             $taxonomies[] = $taxonomy;
         }
     }
     if (empty($taxonomies)) {
         $page_values = array('Search Terms' => __('Search Terms', 'media-library-assistant'), 'message' => __('There are no taxonomies to search', 'media-library-assistant'));
         $terms_search_tpl = MLAData::mla_parse_template($page_template_array['mla-terms-search-empty-div'], $page_values);
     } else {
         $taxonomy_list = '';
         foreach ($taxonomies as $taxonomy) {
             $page_values = array('taxonomy_checked' => MLAOptions::mla_taxonomy_support($taxonomy->name, 'term-search') ? 'checked="checked"' : '', 'taxonomy_slug' => $taxonomy->name, 'taxonomy_label' => esc_attr($taxonomy->label));
             $taxonomy_list .= MLAData::mla_parse_template($page_template_array['mla-terms-search-taxonomy'], $page_values);
         }
         $page_values = array('Search Terms' => __('Search Terms', 'media-library-assistant'), 'Search' => __('Search', 'media-library-assistant'), 'phrases_and_checked' => 'checked="checked"', 'All phrases' => __('All phrases', 'media-library-assistant'), 'phrases_or_checked' => '', 'Any phrase' => __('Any phrase', 'media-library-assistant'), 'terms_and_checked' => '', 'All terms' => __('All terms', 'media-library-assistant'), 'terms_or_checked' => 'checked="checked"', 'Any term' => __('Any term', 'media-library-assistant'), 'exact_checked' => '', 'Exact' => __('Exact', 'media-library-assistant'), 'mla_terms_search_taxonomies' => $taxonomy_list);
         $terms_search_tpl = MLAData::mla_parse_template($page_template_array['mla-terms-search-div'], $page_values);
     }
     $page_values = array('mla_terms_search_url' => esc_url(add_query_arg(array_merge(MLA_List_Table::mla_submenu_arguments(false), array('page' => MLA::ADMIN_PAGE_SLUG)), admin_url('upload.php'))), 'mla_terms_search_action' => MLA::MLA_ADMIN_TERMS_SEARCH, 'wpnonce' => wp_nonce_field(MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME, true, false), 'mla_terms_search_div' => $terms_search_tpl);
     $terms_search_tpl = MLAData::mla_parse_template($page_template_array['mla-terms-search-form'], $page_values);
     return $terms_search_tpl;
 }
 /**
  * Copy attachment metadata to duplicated items
  *
  * This filter is called AFTER MLA mapping rules are applied during
  * wp_update_attachment_metadata() processing. The postfilter gives you
  * an opportunity to record or update the metadata after the mapping.
  *
  * @since 2.20
  *
  * @param	array	attachment metadata
  * @param	integer	The Post ID of the new/updated attachment
  * @param	array	Processing options, e.g., 'is_upload'
  *
  * @return	array	updated attachment metadata
  */
 public static function mla_update_attachment_metadata_postfilter($data, $post_id, $options)
 {
     $uploading = var_export(!empty($options['is_upload']), true);
     $duplicating = var_export(self::$updating_duplicates, true);
     MLACore::mla_debug_add(__LINE__ . " MLA_WPML::mla_update_attachment_metadata_postfilter( {$post_id}, {$uploading}, {$duplicating} ) data = " . var_export($data, true), MLACore::MLA_DEBUG_CATEGORY_LANGUAGE);
     if (!empty($options['is_upload']) && !self::$updating_duplicates) {
         /*
          * If always_translate_media is set there will be translations present
          * that have no attachment metadata and have not been mapped.
          */
         if (!empty(self::$duplicate_attachments)) {
             self::$updating_duplicates = true;
             foreach (self::$duplicate_attachments as $id => $language) {
                 $meta = get_post_meta($id, '_wp_attachment_metadata', true);
                 MLACore::mla_debug_add(__LINE__ . " MLA_WPML::mla_update_attachment_metadata_postfilter( {$id}, {$language} ) attachment_metadata = " . var_export($meta, true), MLACore::MLA_DEBUG_CATEGORY_LANGUAGE);
                 if (is_array($meta)) {
                     continue;
                 }
                 /*
                  * update_post_meta is required twice; first to set it for mapping rules,
                  * second to repair the damage done by WPML synchronize_attachment_metadata
                  */
                 update_post_meta($id, '_wp_attachment_metadata', $data);
                 MLAOptions::mla_add_attachment_action($id);
                 MLAOptions::mla_update_attachment_metadata_filter($data, $id);
                 update_post_meta($id, '_wp_attachment_metadata', $data);
                 $meta = get_post_meta($id, '_wp_attachment_metadata', false);
                 MLACore::mla_debug_add(__LINE__ . " MLA_WPML::mla_update_attachment_metadata_postfilter( {$id}, {$language} ) attachment_metadata = " . var_export($meta, true), MLACore::MLA_DEBUG_CATEGORY_LANGUAGE);
             }
             self::$updating_duplicates = false;
         }
     }
     return $data;
 }
 /**
  * Ajax handler for Media Manager queries 
  *
  * Adapted from wp_ajax_query_attachments in /wp-admin/includes/ajax-actions.php
  *
  * @since 1.20
  *
  * @return	void	echo HTML <tr> markup for updated row or error message, then die()
  */
 public static function mla_query_attachments_action()
 {
     if (!current_user_can('upload_files')) {
         wp_send_json_error();
     }
     /*
      * Pick out and clean up the query terms we can process
      */
     $query = isset($_REQUEST['query']) ? (array) $_REQUEST['query'] : array();
     $query = array_intersect_key($query, array_flip(array('order', 'orderby', 'posts_per_page', 'paged', 'post_mime_type', 'post_parent', 'post__in', 'post__not_in', 'mla_filter_month', 'mla_filter_term', 'mla_search_value', 's', 'mla_search_fields', 'mla_search_connector')));
     if (isset($query['post_mime_type'])) {
         if ('detached' == $query['post_mime_type']) {
             $query['detached'] = '1';
             unset($query['post_mime_type']);
         } else {
             $view = $query['post_mime_type'];
             unset($query['post_mime_type']);
             $query = array_merge($query, MLAMime::mla_prepare_view_query('view', $view));
         }
     }
     /*
      * Convert mla_filter_month back to the WordPress "m" parameter
      */
     if (isset($query['mla_filter_month'])) {
         if ('0' != $query['mla_filter_month']) {
             $query['m'] = $query['mla_filter_month'];
         }
         unset($query['mla_filter_month']);
     }
     /*
      * Process the enhanced search box OR fix up the default search box
      */
     if (isset($query['mla_search_value'])) {
         if (!empty($query['mla_search_value'])) {
             $query['s'] = $query['mla_search_value'];
         }
         //			else
         //				unset( $query['s'] );
         unset($query['mla_search_value']);
     }
     /*		elseif ( ! empty( $query['s'] ) ) {
     			$query['mla_search_fields'] = array( 'title', 'content' );
     			$query['mla_search_connector'] = 'AND';
     		} // */
     if (isset($query['posts_per_page'])) {
         $count = $query['posts_per_page'];
         $offset = $count * (isset($query['paged']) ? $query['paged'] - 1 : 0);
     } else {
         $count = 0;
         $offset = 0;
     }
     /*
      * Check for sorting override
      */
     $option = MLAOptions::mla_get_option(MLAOptions::MLA_MEDIA_MODAL_ORDERBY);
     if ('default' != $option) {
         /*
          * Make sure the current orderby choice still exists or revert to default.
          */
         $default_orderby = array_merge(array('none' => array('none', false)), MLA_List_Table::mla_get_sortable_columns());
         $found_current = false;
         foreach ($default_orderby as $key => $value) {
             if ($option == $value[0]) {
                 $found_current = true;
                 break;
             }
         }
         if (!$found_current) {
             MLAOptions::mla_delete_option(MLAOptions::MLA_DEFAULT_ORDERBY);
             $option = MLAOptions::mla_get_option(MLAOptions::MLA_DEFAULT_ORDERBY);
         }
         $query['orderby'] = $option;
     }
     $option = MLAOptions::mla_get_option(MLAOptions::MLA_MEDIA_MODAL_ORDER);
     if ('default' != $option) {
         $query['order'] = $option;
     }
     $query['post_type'] = 'attachment';
     $query['post_status'] = 'inherit';
     if (current_user_can(get_post_type_object('attachment')->cap->read_private_posts)) {
         $query['post_status'] .= ',private';
     }
     $query = MLAData::mla_query_media_modal_items($query, $offset, $count);
     $posts = array_map('wp_prepare_attachment_for_js', $query->posts);
     $posts = array_filter($posts);
     wp_send_json_success($posts);
 }