/**
  * 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');
 }
 /**
  * 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
 }
 /**
  * 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();
 }
Example #4
0
 /**
  * Render the "Assistant" subpage in the Media section, using the list_table package
  *
  * @since 0.1
  *
  * @return	void
  */
 public static function mla_render_admin_page()
 {
     /*
      * WordPress class-wp-list-table.php doesn't look in hidden fields to set
      * the month filter dropdown or sorting parameters
      */
     if (isset($_REQUEST['m'])) {
         $_GET['m'] = $_REQUEST['m'];
     }
     if (isset($_REQUEST['order'])) {
         $_GET['order'] = $_REQUEST['order'];
     }
     if (isset($_REQUEST['orderby'])) {
         $_GET['orderby'] = $_REQUEST['orderby'];
     }
     // bulk_refresh simply refreshes the page, ignoring other bulk actions
     if (!empty($_REQUEST['bulk_refresh'])) {
         unset($_REQUEST['action']);
         unset($_POST['action']);
         unset($_REQUEST['action2']);
         unset($_POST['action2']);
     }
     $bulk_action = self::_current_bulk_action();
     $page_title = MLAOptions::mla_get_option(MLAOptions::MLA_SCREEN_PAGE_TITLE);
     if (empty($page_title)) {
         $page_title = MLAOptions::mla_get_option(MLAOptions::MLA_SCREEN_PAGE_TITLE, true);
     }
     echo "<div class=\"wrap\">\n";
     echo "<div id=\"icon-upload\" class=\"icon32\"><br/></div>\n";
     echo "<h2>{$page_title}";
     // trailing </h2> is action-specific
     if (!current_user_can('upload_files')) {
         echo ' - ' . __('ERROR', 'media-library-assistant') . "</h2>\n";
         wp_die(__('You do not have permission to manage attachments.', 'media-library-assistant'));
     }
     $page_content = array('message' => '', 'body' => '');
     if (!empty($_REQUEST['mla_admin_message'])) {
         $page_content['message'] = $_REQUEST['mla_admin_message'];
     }
     /*
      * The category taxonomy (edit screens) is a special case because 
      * post_categories_meta_box() changes the input name
      */
     if (!isset($_REQUEST['tax_input'])) {
         $_REQUEST['tax_input'] = array();
     }
     if (isset($_REQUEST['post_category'])) {
         $_REQUEST['tax_input']['category'] = $_REQUEST['post_category'];
         unset($_REQUEST['post_category']);
     }
     /*
      * Process bulk actions that affect an array of items
      */
     if ($bulk_action && $bulk_action != 'none') {
         // bulk_refresh simply refreshes the page, ignoring other bulk actions
         if (empty($_REQUEST['bulk_refresh'])) {
             $item_content = self::mla_process_bulk_action($bulk_action);
             $page_content['message'] .= $item_content['message'] . '<br>';
         }
     }
     // $bulk_action
     if (isset($_REQUEST['clear_filter_by'])) {
         self::mla_clear_filter_by();
     }
     /*
      * Empty the Trash?
      */
     if (isset($_REQUEST['delete_all'])) {
         global $wpdb;
         $ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type=%s AND post_status = %s", 'attachment', 'trash'));
         $delete_count = 0;
         foreach ($ids as $post_id) {
             $item_content = self::_delete_single_item($post_id);
             if (false !== strpos($item_content['message'], __('ERROR', 'media-library-assistant'))) {
                 $page_content['message'] .= $item_content['message'] . '<br>';
             } else {
                 $delete_count++;
             }
         }
         if ($delete_count) {
             /* translators: 1: number of items */
             $page_content['message'] .= sprintf(_nx('%s item deleted.', '%s items deleted.', $delete_count, 'deleted items', 'media-library-assistant'), number_format_i18n($delete_count));
         } else {
             $page_content['message'] .= __('No items deleted.', 'media-library-assistant');
         }
     }
     /*
      * Process row-level actions that affect a single item
      */
     if (!empty($_REQUEST['mla_admin_action'])) {
         check_admin_referer(self::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME);
         $page_content = apply_filters('mla_list_table_single_action', NULL, $_REQUEST['mla_admin_action'], isset($_REQUEST['mla_item_ID']) ? $_REQUEST['mla_item_ID'] : 0);
         if (is_null($page_content)) {
             $prevent_default = false;
             $custom_message = '';
         } else {
             $prevent_default = isset($page_content['prevent_default']) ? $page_content['prevent_default'] : false;
             $custom_message = isset($page_content['message']) ? $page_content['message'] : '';
         }
         if (!$prevent_default) {
             switch ($_REQUEST['mla_admin_action']) {
                 case self::MLA_ADMIN_SINGLE_DELETE:
                     $page_content = self::_delete_single_item($_REQUEST['mla_item_ID']);
                     break;
                 case self::MLA_ADMIN_SINGLE_RESTORE:
                     $page_content = self::_restore_single_item($_REQUEST['mla_item_ID']);
                     break;
                 case self::MLA_ADMIN_SINGLE_TRASH:
                     $page_content = self::_trash_single_item($_REQUEST['mla_item_ID']);
                     break;
                 case self::MLA_ADMIN_SET_PARENT:
                     $new_data = array('post_parent' => $_REQUEST['found_post_id']);
                     foreach ($_REQUEST['children'] as $child) {
                         $item_content = MLAData::mla_update_single_item($child, $new_data);
                         $page_content['message'] .= $item_content['message'] . '<br>';
                     }
                     unset($_REQUEST['parent']);
                     unset($_REQUEST['children']);
                     unset($_REQUEST['mla-set-parent-ajax-nonce']);
                     unset($_REQUEST['mla_set_parent_search_text']);
                     unset($_REQUEST['found_post_id']);
                     unset($_REQUEST['mla-set-parent-submit']);
                     break;
                 case self::MLA_ADMIN_TERMS_SEARCH:
                     /*
                      * This will be handled as a database query argument,
                      * but validate the arguments here
                      */
                     $mla_terms_search = isset($_REQUEST['mla_terms_search']) ? $_REQUEST['mla_terms_search'] : array('phrases' => '', 'taxonomies' => array());
                     if (!is_array($mla_terms_search) || empty($mla_terms_search['phrases']) || empty($mla_terms_search['taxonomies'])) {
                         unset($_REQUEST['mla_terms_search']);
                         $page_content = array('message' => __('Empty Terms Search; ignored', 'media-library-assistant'), 'body' => '');
                     } else {
                         unset($_REQUEST['mla_terms_search']['submit']);
                     }
                     break;
                 default:
                     $page_content = apply_filters('mla_list_table_custom_single_action', NULL, $_REQUEST['mla_admin_action'], isset($_REQUEST['mla_item_ID']) ? $_REQUEST['mla_item_ID'] : 0);
                     if (is_null($page_content)) {
                         $page_content = array('message' => sprintf(__('Unknown mla_admin_action - "%1$s"', 'media-library-assistant'), $_REQUEST['mla_admin_action']), 'body' => '');
                     }
                     // Unknown mla_admin_action
             }
             // switch ($_REQUEST['mla_admin_action'])
         }
         // ! $prevent_default
         if (!empty($custom_message)) {
             $page_content['message'] = $custom_message . $page_content['message'];
         }
     }
     // (!empty($_REQUEST['mla_admin_action'])
     if (!empty($page_content['body'])) {
         if (!empty($page_content['message'])) {
             if (false !== strpos($page_content['message'], __('ERROR', 'media-library-assistant'))) {
                 $messages_class = 'mla_errors';
             } else {
                 $messages_class = 'mla_messages';
             }
             echo "  <div class=\"{$messages_class}\"><p>\n";
             echo '    ' . $page_content['message'] . "\n";
             echo "  </p></div>\n";
             // id="message"
         }
         echo $page_content['body'];
     } else {
         /*
          * Display Attachments list
          */
         if (!empty($_REQUEST['heading_suffix'])) {
             echo ' - ' . esc_html($_REQUEST['heading_suffix']) . "</h2>\n";
         } elseif (!empty($_REQUEST['mla_terms_search'])) {
             echo ' - ' . __('term search results for', 'media-library-assistant') . ' "' . esc_html(stripslashes(trim($_REQUEST['mla_terms_search']['phrases']))) . "\"</h2>\n";
         } elseif (!empty($_REQUEST['s'])) {
             if (empty($_REQUEST['mla_search_fields'])) {
                 echo ' - ' . __('post/parent results for', 'media-library-assistant') . ' "' . esc_html(stripslashes(trim($_REQUEST['s']))) . "\"</h2>\n";
             } else {
                 echo ' - ' . __('search results for', 'media-library-assistant') . ' "' . esc_html(stripslashes(trim($_REQUEST['s']))) . "\"</h2>\n";
             }
         } else {
             echo "</h2>\n";
         }
         if (!empty($page_content['message'])) {
             if (false !== strpos($page_content['message'], __('ERROR', 'media-library-assistant'))) {
                 $messages_class = 'mla_errors';
             } else {
                 $messages_class = 'mla_messages';
             }
             echo "  <div class=\"{$messages_class}\"><p>\n";
             echo '    ' . $page_content['message'] . "\n";
             echo "  </p></div>\n";
             // id="message"
         }
         //	Create an instance of our package class...
         $MLAListTable = apply_filters('mla_list_table_new_instance', NULL);
         if (is_null($MLAListTable)) {
             $MLAListTable = new MLA_List_Table();
         }
         //	Fetch, prepare, sort, and filter our data...
         $MLAListTable->prepare_items();
         $MLAListTable->views();
         $view_arguments = MLA_List_Table::mla_submenu_arguments();
         if (isset($view_arguments['lang'])) {
             $form_url = 'upload.php?page=' . self::ADMIN_PAGE_SLUG . '&lang=' . $view_arguments['lang'];
         } else {
             $form_url = 'upload.php?page=' . self::ADMIN_PAGE_SLUG;
         }
         //	 Forms are NOT created automatically, wrap the table in one to use features like bulk actions
         echo '<form action="' . admin_url($form_url) . '" method="post" id="mla-filter">' . "\n";
         /*
          * Include the Search Media box
          */
         require_once MLA_PLUGIN_PATH . 'includes/mla-main-search-box-template.php';
         /*
          * We also need to ensure that the form posts back to our current page and remember all the view arguments
          */
         echo sprintf('<input type="hidden" name="page" value="%1$s" />', $_REQUEST['page']) . "\n";
         foreach ($view_arguments as $key => $value) {
             if ('meta_query' == $key) {
                 $value = stripslashes($_REQUEST['meta_query']);
             }
             /*
              * Search box elements are already set up in the above "search-box"
              * 'lang' has already been added to the form action attribute
              */
             if (in_array($key, array('s', 'mla_search_connector', 'mla_search_fields', 'lang'))) {
                 continue;
             }
             if (is_array($value)) {
                 foreach ($value as $element_key => $element_value) {
                     echo sprintf('<input type="hidden" name="%1$s[%2$s]" value="%3$s" />', $key, $element_key, esc_attr($element_value)) . "\n";
                 }
             } else {
                 echo sprintf('<input type="hidden" name="%1$s" value="%2$s" />', $key, esc_attr($value)) . "\n";
             }
         }
         //	 Now we can render the completed list table
         $MLAListTable->display();
         echo "</form><!-- id=mla-filter -->\n";
         /*
          * Insert the hidden form and table for inline edits (quick & bulk)
          */
         echo self::_build_inline_edit_form($MLAListTable);
         echo "<div id=\"ajax-response\"></div>\n";
         echo "<br class=\"clear\" />\n";
         echo "</div><!-- class=wrap -->\n";
     }
     // display attachments list
 }
 /**
  * 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;
 }
 /**
  * Registers meta boxes for the Edit Media screen.
  * Declared public because it is an action.
  *
  * @since 0.80
  *
  * @param	string	type of the current post, e.g., 'attachment' (optional, default 'unknown') 
  * @param	object	current post (optional, default (object) array ( 'ID' => 0 ))
  *
  * @return	void
  */
 public static function mla_add_meta_boxes_action($post_type = 'unknown', $post = NULL)
 {
     /*
      * Plugins call this action with varying numbers of arguments!
      */
     if (NULL == $post) {
         $post = (object) array('ID' => 0);
     }
     if ('attachment' != $post_type) {
         return;
     }
     /*
      * Use the mla_checklist_meta_box callback function for MLA supported taxonomies
      */
     global $wp_meta_boxes;
     $screen = convert_to_screen('attachment');
     $page = $screen->id;
     if ('checked' == MLAOptions::mla_get_option(MLAOptions::MLA_EDIT_MEDIA_SEARCH_TAXONOMY)) {
         $taxonomies = get_taxonomies(array('show_ui' => true), 'objects');
         foreach ($taxonomies as $key => $value) {
             if (MLAOptions::mla_taxonomy_support($key)) {
                 if ($value->hierarchical) {
                     foreach (array_keys($wp_meta_boxes[$page]) as $a_context) {
                         foreach (array('high', 'sorted', 'core', 'default', 'low') as $a_priority) {
                             if (isset($wp_meta_boxes[$page][$a_context][$a_priority][$key . 'div'])) {
                                 $box =& $wp_meta_boxes[$page][$a_context][$a_priority][$key . 'div'];
                                 if ('post_categories_meta_box' == $box['callback']) {
                                     $box['callback'] = 'MLAEdit::mla_checklist_meta_box';
                                 }
                             }
                             // isset $box
                         }
                         // foreach priority
                     }
                     // foreach context
                 } elseif (MLAOptions::mla_taxonomy_support($key, 'flat-checklist')) {
                     foreach (array_keys($wp_meta_boxes[$page]) as $a_context) {
                         foreach (array('high', 'sorted', 'core', 'default', 'low') as $a_priority) {
                             if (isset($wp_meta_boxes[$page][$a_context][$a_priority]['tagsdiv-' . $key])) {
                                 $box =& $wp_meta_boxes[$page][$a_context][$a_priority]['tagsdiv-' . $key];
                                 if ('post_tags_meta_box' == $box['callback']) {
                                     $box['callback'] = 'MLAEdit::mla_checklist_meta_box';
                                 }
                             }
                             // isset $box
                         }
                         // foreach priority
                     }
                     // foreach context
                 }
                 // flat checklist
             }
             // is supported
         }
         // foreach
     }
     // MLA_EDIT_MEDIA_SEARCH_TAXONOMY
     if ('checked' == MLAOptions::mla_get_option(MLAOptions::MLA_EDIT_MEDIA_META_BOXES)) {
         $active_boxes = apply_filters('mla_edit_media_meta_boxes', array('mla-parent-info' => 'mla-parent-info', 'mla-menu-order' => 'mla-menu-order', 'mla-image-metadata' => 'mla-image-metadata', 'mla-featured-in' => 'mla-featured-in', 'mla-inserted-in' => 'mla-inserted-in', 'mla-gallery-in' => 'mla-gallery-in', 'mla-mla-gallery-in' => 'mla-mla-gallery-in'));
         if (isset($active_boxes['mla-parent-info'])) {
             add_meta_box('mla-parent-info', __('Parent Info', 'media-library-assistant'), 'MLAEdit::mla_parent_info_handler', 'attachment', 'normal', 'core');
         }
         if (isset($active_boxes['mla-menu-order'])) {
             add_meta_box('mla-menu-order', __('Menu Order', 'media-library-assistant'), 'MLAEdit::mla_menu_order_handler', 'attachment', 'normal', 'core');
         }
         if (isset($active_boxes['mla-image-metadata'])) {
             $image_metadata = get_metadata('post', $post->ID, '_wp_attachment_metadata', true);
             if (!empty($image_metadata)) {
                 add_meta_box('mla-image-metadata', __('Attachment Metadata', 'media-library-assistant'), 'MLAEdit::mla_image_metadata_handler', 'attachment', 'normal', 'core');
             }
         }
         if (isset($active_boxes['mla-featured-in']) && MLAOptions::$process_featured_in) {
             add_meta_box('mla-featured-in', __('Featured in', 'media-library-assistant'), 'MLAEdit::mla_featured_in_handler', 'attachment', 'normal', 'core');
         }
         if (isset($active_boxes['mla-inserted-in']) && MLAOptions::$process_inserted_in) {
             add_meta_box('mla-inserted-in', __('Inserted in', 'media-library-assistant'), 'MLAEdit::mla_inserted_in_handler', 'attachment', 'normal', 'core');
         }
         if (isset($active_boxes['mla-gallery-in']) && MLAOptions::$process_gallery_in) {
             add_meta_box('mla-gallery-in', __('Gallery in', 'media-library-assistant'), 'MLAEdit::mla_gallery_in_handler', 'attachment', 'normal', 'core');
         }
         if (isset($active_boxes['mla-mla-gallery-in']) && MLAOptions::$process_mla_gallery_in) {
             add_meta_box('mla-mla-gallery-in', __('MLA Gallery in', 'media-library-assistant'), 'MLAEdit::mla_mla_gallery_in_handler', 'attachment', 'normal', 'core');
         }
     }
 }
 /**
  * Serialize option settings and write them to a file
  *
  * Options with a default value, i.e., not stored in the database are NOT written to the file.
  *
  * @since 1.50
  *
  * @return	array	Message(s) reflecting the results of the operation
  */
 private static function _export_settings()
 {
     $message_list = '';
     $settings = array();
     /*
      * Accumulate the settings into an array, then serialize it for writing to the file.
      */
     $stored_count = 0;
     foreach (MLAOptions::$mla_option_definitions as $key => $value) {
         $stored_value = MLAOptions::mla_get_option($key, false, true);
         if (false !== $stored_value) {
             $settings[$key] = $stored_value;
             $stored_count++;
             $message = "<br>{$key} " . _x('exported', 'message_list', 'media-library-assistant');
         } else {
             $message = "<br>{$key} " . _x('skipped', 'message_list', 'media-library-assistant');
         }
         $message_list .= $message;
     }
     $settings = serialize($settings);
     $page_content = array('message' => __('ALL settings exported.', 'media-library-assistant'), 'body' => '');
     /*
      * Make sure the directory exists and is writable, then create the file
      */
     $prefix = defined(MLA_OPTION_PREFIX) ? MLA_OPTION_PREFIX : 'mla_';
     $date = date("Ymd_B");
     $filename = MLA_BACKUP_DIR . "{$prefix}_options_{$date}.txt";
     if (!file_exists(MLA_BACKUP_DIR) && !@mkdir(MLA_BACKUP_DIR)) {
         /* translators: 1: ERROR tag 2: backup directory name */
         $page_content['message'] = sprintf(__('%1$s: The settings directory ( %2$s ) cannot be created.', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), MLA_BACKUP_DIR);
         return $page_content;
     } elseif (!is_writable(MLA_BACKUP_DIR) && !@chmod(MLA_BACKUP_DIR, '0777')) {
         /* translators: 1: ERROR tag 2: backup directory name */
         $page_content['message'] = sprintf(__('%1$s: The settings directory ( %2$s ) is not writable.', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), MLA_BACKUP_DIR);
         return $page_content;
     }
     if (!file_exists(MLA_BACKUP_DIR . 'index.php')) {
         @touch(MLA_BACKUP_DIR . 'index.php');
     }
     $file_handle = @fopen($filename, 'w');
     if (!$file_handle) {
         /* translators: 1: ERROR tag 2: backup file name */
         $page_content['message'] = sprintf(__('%1$s: The settings file ( %2$s ) could not be opened.', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $filename);
         return $page_content;
     }
     if (false === @fwrite($file_handle, $settings)) {
         $error_info = error_get_last();
         /* translators: 1: ERROR tag 2: PHP error information */
         error_log(sprintf(_x('%1$s: _export_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: Writing the settings file ( %2$s ) "%3$s".', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $filename, $php_errormsg);
     }
     fclose($file_handle);
     /* translators: 1: number of option settings */
     $page_content['message'] = sprintf(__('Settings exported; %1$s settings recorded.', 'media-library-assistant'), $stored_count);
     /*
      * Uncomment this for debugging.
      */
     //$page_content['message'] .= $message_list;
     return $page_content;
 }
 /**
  * Computes image dimensions for scalable graphics, e.g., SVG 
  *
  * @since 1.82
  *
  * @return array 
  */
 private static function _registered_dimensions()
 {
     global $_wp_additional_image_sizes;
     if ('checked' == MLAOptions::mla_get_option(MLAOptions::MLA_ENABLE_MLA_ICONS)) {
         $sizes = array('icon' => array(64, 64));
     } else {
         $sizes = array('icon' => array(60, 60));
     }
     foreach (get_intermediate_image_sizes() as $s) {
         $sizes[$s] = array(0, 0);
         if (in_array($s, array('thumbnail', 'medium', 'large'))) {
             $sizes[$s][0] = get_option($s . '_size_w');
             $sizes[$s][1] = get_option($s . '_size_h');
         } else {
             if (isset($_wp_additional_image_sizes) && isset($_wp_additional_image_sizes[$s])) {
                 $sizes[$s] = array($_wp_additional_image_sizes[$s]['width'], $_wp_additional_image_sizes[$s]['height']);
             }
         }
     }
     return $sizes;
 }
 * Harmless declaration to suppress phpDocumentor "No page-level DocBlock" error
 *
 * @global $post
 */
global $post;
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');
 /**
  * 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);
 }
 /**
  * Supply the content for a custom column
  *
  * @since 0.1
  * 
  * @param	array	A singular attachment (post) object
  * @return	string	HTML markup to be placed inside the column
  */
 function column_icon($item)
 {
     $icon_width = MLAOptions::mla_get_option(MLAOptions::MLA_TABLE_ICON_SIZE);
     if ('checked' == MLAOptions::mla_get_option(MLAOptions::MLA_ENABLE_MLA_ICONS)) {
         if (empty($icon_width)) {
             $icon_width = $icon_height = 64;
         } else {
             $icon_width = $icon_height = absint($icon_width);
         }
     } else {
         if (empty($icon_width)) {
             if (MLATest::$wp_4dot3_plus) {
                 $icon_width = 60;
             } else {
                 $icon_width = 80;
             }
         } else {
             $icon_width = absint($icon_width);
         }
         if (MLATest::$wp_4dot3_plus) {
             $icon_height = $icon_width;
         } else {
             $icon_height = absint(0.75 * (double) $icon_width);
         }
     }
     $dimensions = array($icon_width, $icon_height);
     $thumb = wp_get_attachment_image($item->ID, $dimensions, true, array('class' => 'mla_media_thumbnail'));
     if (in_array($item->post_mime_type, array('image/svg+xml'))) {
         $thumb = preg_replace('/width=\\"[^\\"]*\\"/', sprintf('width="%1$d"', $dimensions[0]), $thumb);
         $thumb = preg_replace('/height=\\"[^\\"]*\\"/', sprintf('height="%1$d"', $dimensions[1]), $thumb);
     }
     if ($this->is_trash || !current_user_can('edit_post', $item->ID)) {
         return $thumb;
     }
     /*
      * Use the WordPress Edit Media screen
      */
     $view_args = self::mla_submenu_arguments();
     if (isset($view_args['lang'])) {
         $edit_url = 'post.php?post=' . $item->ID . '&action=edit&mla_source=edit&lang=' . $view_args['lang'];
     } else {
         $edit_url = 'post.php?post=' . $item->ID . '&action=edit&mla_source=edit';
     }
     return sprintf('<a href="%1$s" title="' . __('Edit', 'media-library-assistant') . ' &#8220;%2$s&#8221;">%3$s</a>', admin_url($edit_url), _draft_or_post_title($item), $thumb);
 }
 /**
  * Ajax handler for Media Manager "Query Attachments" queries 
  *
  * Adapted from wp_ajax_query_attachments in /wp-admin/includes/ajax-actions.php
  *
  * @since 1.20
  *
  * @return	void	passes array of post arrays to wp_send_json_success() for JSON encoding and transmission
  */
 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
      */
     $raw_query = isset($_REQUEST['query']) ? (array) $_REQUEST['query'] : array();
     $query = array_intersect_key($raw_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_terms_search', 'mla_search_value', 's', 'mla_search_fields', 'mla_search_connector')));
     $query = apply_filters('mla_media_modal_query_initial_terms', $query, $raw_query);
     if (isset($query['post_mime_type'])) {
         if ('detached' == $query['post_mime_type']) {
             $query['detached'] = '1';
             unset($query['post_mime_type']);
         } elseif ('attached' == $query['post_mime_type']) {
             $query['detached'] = '0';
             unset($query['post_mime_type']);
         } elseif ('trash' == $query['post_mime_type']) {
             $query['status'] = 'trash';
             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'];
         }
         unset($query['mla_search_value']);
     }
     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';
     if (empty($query['status'])) {
         $query['post_status'] = 'inherit';
         if (current_user_can(get_post_type_object('attachment')->cap->read_private_posts)) {
             $query['post_status'] .= ',private';
         }
     }
     $query = apply_filters('mla_media_modal_query_filtered_terms', $query, $raw_query);
     $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);
 }
 /**
  * Serialize option settings and write them to a file
  *
  * Options with a default value, i.e., not stored in the database are NOT written to the file.
  *
  * @since 1.50
  *
  * @return	array	Message(s) reflecting the results of the operation
  */
 private static function _export_settings()
 {
     $message_list = '';
     $settings = array();
     /*
      * Accumulate the settings into an array, then serialize it for writing to the file.
      */
     $stored_count = 0;
     foreach (MLAOptions::$mla_option_definitions as $key => $value) {
         $stored_value = MLAOptions::mla_get_option($key, false, true);
         if (false !== $stored_value) {
             $settings[$key] = $stored_value;
             $stored_count++;
             $message = "<br>{$key} exported";
         } else {
             $message = "<br>{$key} skipped";
         }
         $message_list .= $message;
     }
     $settings = serialize($settings);
     $page_content = array('message' => 'ALL settings exported.', 'body' => '');
     /*
      * Make sure the directory exists and is writable, then create the file
      */
     $prefix = defined(MLA_OPTION_PREFIX) ? MLA_OPTION_PREFIX : 'mla_';
     $date = date("Ymd_B");
     $filename = MLA_BACKUP_DIR . "{$prefix}_options_{$date}.txt";
     if (!file_exists(MLA_BACKUP_DIR) && !@mkdir(MLA_BACKUP_DIR)) {
         $page_content['message'] = 'ERROR: The settings directory ( ' . MLA_BACKUP_DIR . ' ) cannot be created.';
         return $page_content;
     } elseif (!is_writable(MLA_BACKUP_DIR) && !@chmod(MLA_BACKUP_DIR, '0777')) {
         $page_content['message'] = 'ERROR: The settings directory ( ' . MLA_BACKUP_DIR . ' ) is not writable.';
         return $page_content;
     }
     if (!file_exists(MLA_BACKUP_DIR . 'index.php')) {
         @touch(MLA_BACKUP_DIR . 'index.php');
     }
     $file_pointer = @fopen($filename, 'w');
     if (!$file_pointer) {
         $page_content['message'] = "ERROR: The settings file ( {$filename} ) could not be opened.";
         return $page_content;
     }
     if (false === @fwrite($file_pointer, $settings)) {
         $error_info = error_get_last();
         error_log('ERROR: _export_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: writing the settings file ( {$filename} ){$php_errormsg}";
     }
     fclose($file_pointer);
     $page_content['message'] = "Settings exported; {$stored_count} settings recorded.";
     /*
      * Uncomment this for debugging.
      */
     //$page_content['message'] .= $message_list;
     return $page_content;
 }
 /**
  * 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;
 }
 /**
  * Perform IPTC/EXIF and Custom Field mapping on just-inserted attachment
  *
  * This filter tests the $add_attachment_id variable set by the mla_add_attachment_action
  * to ensure that mapping is only performed for new additions, not metadata updates.
  *
  * @since 1.10
  *
  * @param	array	Attachment metadata for just-inserted attachment
  * @param	integer	ID of just-inserted attachment
  *
  * @return	array	Updated attachment metadata
  */
 public static function mla_update_attachment_metadata_filter($data, $post_id)
 {
     $options = array();
     $options['is_upload'] = self::$add_attachment_id == $post_id;
     self::$add_attachment_id = 0;
     $options['enable_iptc_exif_mapping'] = 'checked' == MLAOptions::mla_get_option('enable_iptc_exif_mapping');
     $options['enable_custom_field_mapping'] = 'checked' == MLAOptions::mla_get_option('enable_custom_field_mapping');
     $options['enable_iptc_exif_update'] = 'checked' == MLAOptions::mla_get_option('enable_iptc_exif_update');
     $options['enable_custom_field_update'] = 'checked' == MLAOptions::mla_get_option('enable_custom_field_update');
     $options = apply_filters('mla_update_attachment_metadata_options', $options, $data, $post_id);
     $data = apply_filters('mla_update_attachment_metadata_prefilter', $data, $post_id, $options);
     if ($options['is_upload']) {
         if ($options['enable_iptc_exif_mapping'] || $options['enable_custom_field_mapping']) {
             do_action('mla_begin_mapping', 'create_metadata', $post_id);
         }
         if ($options['enable_iptc_exif_mapping']) {
             $item = get_post($post_id);
             $updates = MLAOptions::mla_evaluate_iptc_exif_mapping($item, 'iptc_exif_mapping', NULL, $data, true);
             $updates = self::_update_attachment_metadata($updates, $data);
             if (!empty($updates)) {
                 $item_content = MLAData::mla_update_single_item($post_id, $updates);
             }
         }
         if ($options['enable_custom_field_mapping']) {
             $updates = MLAOptions::mla_evaluate_custom_field_mapping($post_id, 'single_attachment_mapping', NULL, $data);
             $updates = self::_update_attachment_metadata($updates, $data);
             if (!empty($updates)) {
                 $item_content = MLAData::mla_update_single_item($post_id, $updates);
             }
         }
         if ($options['enable_iptc_exif_mapping'] || $options['enable_custom_field_mapping']) {
             do_action('mla_end_mapping');
         }
     } else {
         if ($options['enable_iptc_exif_update'] || $options['enable_custom_field_update']) {
             do_action('mla_begin_mapping', 'update_metadata', $post_id);
         }
         if ($options['enable_iptc_exif_update']) {
             $item = get_post($post_id);
             $updates = MLAOptions::mla_evaluate_iptc_exif_mapping($item, 'iptc_exif_mapping', NULL, $data);
             $updates = self::_update_attachment_metadata($updates, $data);
             if (!empty($updates)) {
                 $item_content = MLAData::mla_update_single_item($post_id, $updates);
             }
         }
         if ($options['enable_custom_field_update']) {
             $updates = MLAOptions::mla_evaluate_custom_field_mapping($post_id, 'single_attachment_mapping', NULL, $data);
             $updates = self::_update_attachment_metadata($updates, $data);
             if (!empty($updates)) {
                 $item_content = MLAData::mla_update_single_item($post_id, $updates);
             }
         }
         if ($options['enable_iptc_exif_update'] || $options['enable_custom_field_update']) {
             do_action('mla_end_mapping');
         }
     }
     $data = apply_filters('mla_update_attachment_metadata_postfilter', $data, $post_id, $options);
     return $data;
 }
 /**
  * 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;
 }
Example #17
0
 /**
  * Render the "Assistant" subpage in the Media section, using the list_table package
  *
  * @since 0.1
  *
  * @return	void
  */
 public static function mla_render_admin_page()
 {
     /*
      * WordPress class-wp-list-table.php doesn't look in hidden fields to set
      * the month filter dropdown or sorting parameters
      */
     if (isset($_REQUEST['m'])) {
         $_GET['m'] = $_REQUEST['m'];
     }
     if (isset($_REQUEST['order'])) {
         $_GET['order'] = $_REQUEST['order'];
     }
     if (isset($_REQUEST['orderby'])) {
         $_GET['orderby'] = $_REQUEST['orderby'];
     }
     $bulk_action = self::_current_bulk_action();
     $page_title = MLAOptions::mla_get_option(MLAOptions::MLA_SCREEN_PAGE_TITLE);
     echo "<div class=\"wrap\">\r\n";
     echo "<div id=\"icon-upload\" class=\"icon32\"><br/></div>\r\n";
     echo "<h2>{$page_title}";
     // trailing </h2> is action-specific
     if (!current_user_can('upload_files')) {
         echo " - Error</h2>\r\n";
         wp_die(__('You do not have permission to manage attachments.'));
     }
     $page_content = array('message' => '', 'body' => '');
     /*
      * The category taxonomy (edit screens) is a special case because 
      * post_categories_meta_box() changes the input name
      */
     if (!isset($_REQUEST['tax_input'])) {
         $_REQUEST['tax_input'] = array();
     }
     if (isset($_REQUEST['post_category'])) {
         $_REQUEST['tax_input']['category'] = $_REQUEST['post_category'];
         unset($_REQUEST['post_category']);
     }
     /*
      * Process bulk actions that affect an array of items
      */
     if ($bulk_action && $bulk_action != 'none') {
         if (isset($_REQUEST['cb_attachment'])) {
             foreach ($_REQUEST['cb_attachment'] as $index => $post_id) {
                 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;
                         }
                         /*
                          * Copy the edit form contents to $new_data
                          */
                         $new_data = array();
                         if (isset($_REQUEST['post_parent'])) {
                             if (is_numeric($_REQUEST['post_parent'])) {
                                 $new_data['post_parent'] = $_REQUEST['post_parent'];
                             }
                         }
                         if (isset($_REQUEST['post_author'])) {
                             if (-1 != $_REQUEST['post_author']) {
                                 $new_data['post_author'] = $_REQUEST['post_author'];
                             }
                         }
                         /*
                          * Custom field support
                          */
                         $custom_fields = array();
                         foreach (MLAOptions::mla_custom_field_support('bulk_edit') as $slug => $label) {
                             if (isset($_REQUEST[$slug])) {
                                 if (!empty($_REQUEST[$slug])) {
                                     $custom_fields[$label] = $_REQUEST[$slug];
                                 }
                             }
                         }
                         // foreach
                         if (!empty($custom_fields)) {
                             $new_data['custom_updates'] = $custom_fields;
                         }
                         $item_content = MLAData::mla_update_single_item($post_id, $new_data, $_REQUEST['tax_input'], $_REQUEST['tax_action']);
                         break;
                     case 'restore':
                         $item_content = self::_restore_single_item($post_id);
                         break;
                         //case 'tag':
                     //case 'tag':
                     case 'trash':
                         $item_content = self::_trash_single_item($post_id);
                         break;
                     default:
                         $item_content = array('message' => sprintf('Unknown bulk action %s', $bulk_action), 'body' => '');
                 }
                 // switch $bulk_action
                 $page_content['message'] .= $item_content['message'] . '<br>';
             }
             // foreach cb_attachment
             unset($_REQUEST['post_parent']);
             unset($_REQUEST['post_author']);
             unset($_REQUEST['tax_input']);
             unset($_REQUEST['tax_action']);
             foreach (MLAOptions::mla_custom_field_support('bulk_edit') as $slug => $label) {
                 unset($_REQUEST[$slug]);
             }
             unset($_REQUEST['cb_attachment']);
         } else {
             $page_content['message'] = 'Bulk Action ' . $bulk_action . ' - no items selected.';
         }
         unset($_REQUEST['action']);
         unset($_REQUEST['bulk_edit']);
         unset($_REQUEST['action2']);
     }
     // $bulk_action
     if (isset($_REQUEST['clear_filter_by'])) {
         unset($_REQUEST['heading_suffix']);
         unset($_REQUEST['parent']);
         unset($_REQUEST['author']);
         unset($_REQUEST['mla-tax']);
         unset($_REQUEST['mla-term']);
         unset($_REQUEST['mla-metakey']);
         unset($_REQUEST['mla-metavalue']);
     }
     if (isset($_REQUEST['delete_all'])) {
         global $wpdb;
         $ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type=%s AND post_status = %s", 'attachment', 'trash'));
         $delete_count = 0;
         foreach ($ids as $post_id) {
             $item_content = self::_delete_single_item($post_id);
             if (false !== strpos($item_content['message'], 'ERROR:')) {
                 $page_content['message'] .= $item_content['message'] . '<br>';
             } else {
                 $delete_count++;
             }
         }
         if ($delete_count) {
             $page_content['message'] .= sprintf(_nx('%s item deleted.', '%s items deleted.', $delete_count, 'deleted items'), number_format_i18n($delete_count));
         } else {
             $page_content['message'] .= 'No items deleted.';
         }
     }
     /*
      * Process row-level actions that affect a single item
      */
     if (!empty($_REQUEST['mla_admin_action'])) {
         check_admin_referer(self::MLA_ADMIN_NONCE);
         switch ($_REQUEST['mla_admin_action']) {
             case self::MLA_ADMIN_SINGLE_DELETE:
                 $page_content = self::_delete_single_item($_REQUEST['mla_item_ID']);
                 break;
             case self::MLA_ADMIN_SINGLE_EDIT_DISPLAY:
                 echo " - Edit single item</h2>";
                 $page_content = self::_display_single_item($_REQUEST['mla_item_ID']);
                 break;
             case self::MLA_ADMIN_SINGLE_EDIT_UPDATE:
                 if (!empty($_REQUEST['update'])) {
                     $page_content = MLAData::mla_update_single_item($_REQUEST['mla_item_ID'], $_REQUEST['attachments'][$_REQUEST['mla_item_ID']], $_REQUEST['tax_input']);
                 } elseif (!empty($_REQUEST['map-iptc-exif'])) {
                     $item = get_post($_REQUEST['mla_item_ID']);
                     $updates = MLAOptions::mla_evaluate_iptc_exif_mapping($item, 'iptc_exif_mapping');
                     $page_content = MLAData::mla_update_single_item($_REQUEST['mla_item_ID'], $updates);
                 } else {
                     $page_content = array('message' => 'Item: ' . $_REQUEST['mla_item_ID'] . ' cancelled.', 'body' => '');
                 }
                 break;
             case self::MLA_ADMIN_SINGLE_RESTORE:
                 $page_content = self::_restore_single_item($_REQUEST['mla_item_ID']);
                 break;
             case self::MLA_ADMIN_SINGLE_TRASH:
                 $page_content = self::_trash_single_item($_REQUEST['mla_item_ID']);
                 break;
             default:
                 $page_content = array('message' => sprintf('Unknown mla_admin_action - "%1$s"', $_REQUEST['mla_admin_action']), 'body' => '');
                 break;
         }
         // switch ($_REQUEST['mla_admin_action'])
     }
     // (!empty($_REQUEST['mla_admin_action'])
     if (!empty($page_content['body'])) {
         if (!empty($page_content['message'])) {
             if (false !== strpos($page_content['message'], 'ERROR:')) {
                 $messages_class = 'mla_errors';
             } else {
                 $messages_class = 'mla_messages';
             }
             echo "  <div class=\"{$messages_class}\"><p>\r\n";
             echo '    ' . $page_content['message'] . "\r\n";
             echo "  </p></div>\r\n";
             // id="message"
         }
         echo $page_content['body'];
     } else {
         /*
          * Display Attachments list
          */
         if (!empty($_REQUEST['heading_suffix'])) {
             echo ' - ' . esc_html($_REQUEST['heading_suffix']) . "</h2>\r\n";
         } elseif (!empty($_REQUEST['s']) && !empty($_REQUEST['mla_search_fields'])) {
             echo ' - search results for "' . esc_html(stripslashes(trim($_REQUEST['s']))) . "\"</h2>\r\n";
         } else {
             echo "</h2>\r\n";
         }
         if (!empty($page_content['message'])) {
             if (false !== strpos($page_content['message'], 'ERROR:')) {
                 $messages_class = 'mla_errors';
             } else {
                 $messages_class = 'mla_messages';
             }
             echo "  <div class=\"{$messages_class}\"><p>\r\n";
             echo '    ' . $page_content['message'] . "\r\n";
             echo "  </p></div>\r\n";
             // id="message"
         }
         /*
          * Optional - limit width of the views list
          */
         $view_width = MLAOptions::mla_get_option(MLAOptions::MLA_TABLE_VIEWS_WIDTH);
         if (!empty($view_width)) {
             if (is_numeric($view_width)) {
                 $view_width .= 'px';
             }
             echo "  <style type='text/css'>\r\n";
             echo "    ul.subsubsub {\r\n";
             echo "      width: {$view_width};\r\n";
             echo "      max-width: {$view_width};\r\n";
             echo "    }\r\n";
             echo "  </style>\r\n";
         }
         //	Create an instance of our package class...
         $MLAListTable = new MLA_List_Table();
         //	Fetch, prepare, sort, and filter our data...
         $MLAListTable->prepare_items();
         $MLAListTable->views();
         //	 Forms are NOT created automatically, so you need to wrap the table in one to use features like bulk actions
         //			echo '<form action="' . admin_url( 'upload.php' ) . '" method="get" id="mla-filter">' . "\r\n";
         echo '<form action="' . admin_url('upload.php?page=' . self::ADMIN_PAGE_SLUG) . '" method="post" id="mla-filter">' . "\r\n";
         //			echo '<form action="' . admin_url( 'upload.php?page=' . self::ADMIN_PAGE_SLUG ) . '" method="get" id="mla-filter">' . "\r\n";
         /*
          * Compose the Search Media box
          */
         if (!empty($_REQUEST['s']) && !empty($_REQUEST['mla_search_fields'])) {
             $search_value = esc_attr(stripslashes(trim($_REQUEST['s'])));
             $search_fields = $_REQUEST['mla_search_fields'];
             $search_connector = $_REQUEST['mla_search_connector'];
         } else {
             $search_value = '';
             $search_fields = array('title', 'content');
             $search_connector = 'AND';
         }
         echo '<p class="search-box">' . "\r\n";
         echo '<label class="screen-reader-text" for="media-search-input">Search Media:</label>' . "\r\n";
         echo '<input type="text" size="45"  id="media-search-input" name="s" value="' . $search_value . '" />' . "\r\n";
         echo '<input type="submit" name="mla-search-submit" id="search-submit" class="button" value="Search Media"  /><br>' . "\r\n";
         if ('OR' == $search_connector) {
             echo '<input type="radio" name="mla_search_connector" value="AND" />&nbsp;and&nbsp;' . "\r\n";
             echo '<input type="radio" name="mla_search_connector" checked="checked" value="OR" />&nbsp;or&nbsp;' . "\r\n";
         } else {
             echo '<input type="radio" name="mla_search_connector" checked="checked" value="AND" />&nbsp;and&nbsp;' . "\r\n";
             echo '<input type="radio" name="mla_search_connector" value="OR" />&nbsp;or&nbsp;' . "\r\n";
         }
         if (in_array('title', $search_fields)) {
             echo '<input type="checkbox" name="mla_search_fields[]" id="search-title" checked="checked" value="title" />&nbsp;title&nbsp;' . "\r\n";
         } else {
             echo '<input type="checkbox" name="mla_search_fields[]" id="search-title" value="title" />&nbsp;title&nbsp;' . "\r\n";
         }
         if (in_array('name', $search_fields)) {
             echo '<input type="checkbox" name="mla_search_fields[]" id="search-name" checked="checked" value="name" />&nbsp;name&nbsp;' . "\r\n";
         } else {
             echo '<input type="checkbox" name="mla_search_fields[]" id="search-name" value="name" />&nbsp;name&nbsp;' . "\r\n";
         }
         if (in_array('alt-text', $search_fields)) {
             echo '<input type="checkbox" name="mla_search_fields[]" id="search-alt-text" checked="checked" value="alt-text" />&nbsp;ALT text&nbsp;' . "\r\n";
         } else {
             echo '<input type="checkbox" name="mla_search_fields[]" id="search-alt-text" value="alt-text" />&nbsp;ALT text&nbsp;' . "\r\n";
         }
         if (in_array('excerpt', $search_fields)) {
             echo '<input type="checkbox" name="mla_search_fields[]" id="search-excerpt" checked="checked" value="excerpt" />&nbsp;caption&nbsp;' . "\r\n";
         } else {
             echo '<input type="checkbox" name="mla_search_fields[]" id="search-excerpt" value="excerpt" />&nbsp;caption&nbsp;' . "\r\n";
         }
         if (in_array('content', $search_fields)) {
             echo '<input type="checkbox" name="mla_search_fields[]" id="search-content" checked="checked" value="content" />&nbsp;description&nbsp;' . "\r\n";
         } else {
             echo '<input type="checkbox" name="mla_search_fields[]" id="search-content" value="content" />&nbsp;description&nbsp;' . "\r\n";
         }
         echo '</p>' . "\r\n";
         /*
          * We also need to ensure that the form posts back to our current page and remember all the view arguments
          */
         echo sprintf('<input type="hidden" name="page" value="%1$s" />', $_REQUEST['page']) . "\r\n";
         $view_arguments = MLA_List_Table::mla_submenu_arguments();
         foreach ($view_arguments as $key => $value) {
             if ('meta_query' == $key) {
                 $value = stripslashes($_REQUEST['meta_query']);
             }
             /*
              * Search box elements are already set up in the above "search-box"
              */
             if (in_array($key, array('s', 'mla_search_connector', 'mla_search_fields'))) {
                 continue;
             }
             if (is_array($value)) {
                 foreach ($value as $element_key => $element_value) {
                     echo sprintf('<input type="hidden" name="%1$s[%2$s]" value="%3$s" />', $key, $element_key, esc_attr($element_value)) . "\r\n";
                 }
             } else {
                 echo sprintf('<input type="hidden" name="%1$s" value="%2$s" />', $key, esc_attr($value)) . "\r\n";
             }
         }
         //	 Now we can render the completed list table
         $MLAListTable->display();
         echo "</form><!-- id=mla-filter -->\r\n";
         /*
          * Insert the hidden form and table for inline edits (quick & bulk)
          */
         echo self::_build_inline_edit_form($MLAListTable);
         echo "<div id=\"ajax-response\"></div>\r\n";
         echo "<br class=\"clear\" />\r\n";
         echo "</div><!-- class=wrap -->\r\n";
     }
     // display attachments list
 }
 /**
  * Assemble the in-memory representation of the Upload MIME Types 
  *
  * @since 1.40
  *
  * @param	boolean	Force a reload/recalculation of types
  * @return	boolean	Success (true) or failure (false) of the operation
  */
 private static function _get_upload_mime_templates($force_refresh = false)
 {
     self::_get_core_icon_types();
     self::_get_current_icon_types();
     if (false == $force_refresh && NULL != self::$mla_upload_mime_templates) {
         return true;
     }
     /*
      * Find the WordPress-standard (unfiltered) extensions
      */
     global $wp_filter;
     if (isset($wp_filter['mime_types'])) {
         $save_filters = $wp_filter['mime_types'];
         unset($wp_filter['mime_types']);
         $core_types = wp_get_mime_types();
         $wp_filter['mime_types'] = $save_filters;
     } else {
         $core_types = wp_get_mime_types();
     }
     /*
      * If this is the first time MLA Upload support is invoked, match to the 
      * filter-enhanced extensions, retain anything new as a custom type.
      */
     $custom_types = array();
     $mla_upload_mimes = MLAOptions::mla_get_option(MLAOptions::MLA_UPLOAD_MIMES);
     if (is_array($mla_upload_mimes)) {
         $first_time_called = false;
         $custom_types = $mla_upload_mimes['custom'];
     } else {
         $first_time_called = true;
         $mla_upload_mimes = array('custom' => array(), 'disabled' => array(), 'description' => array(), 'icon_type' => array());
         self::$disable_mla_filtering = true;
         foreach (get_allowed_mime_types() as $key => $value) {
             if (!isset($core_types[$key])) {
                 $custom_types[$key] = $value;
             }
         }
         self::$disable_mla_filtering = false;
     }
     /*
      * Explode any entries with multiple extensions
      */
     foreach ($core_types as $key => $value) {
         if (false !== strpos($key, '|')) {
             unset($core_types[$key]);
             $extensions = explode('|', $key);
             foreach ($extensions as $extension) {
                 $core_types[$extension] = $value;
             }
         }
     }
     foreach ($custom_types as $key => $value) {
         if (false !== strpos($key, '|')) {
             unset($custom_types[$key]);
             $extensions = explode('|', $key);
             foreach ($extensions as $extension) {
                 $custom_types[$extension] = $value;
             }
         }
     }
     self::$mla_upload_mime_templates = array();
     self::$mla_upload_mime_highest_ID = 0;
     /*
      * Start with the MLA extensions, initialized to an inactive state
      * Save the descriptions for use in _put_upload_mime_types()
      */
     self::$mla_upload_mime_descriptions = array();
     $template_array = MLAData::mla_load_template('mla-default-mime-types.tpl');
     if (isset($template_array['mla-mime-types'])) {
         $mla_mime_types = preg_split('/[\\r\\n]+/', $template_array['mla-mime-types']);
         foreach ($mla_mime_types as $mla_type) {
             $array = explode(',', $mla_type);
             /* Anthony Martin debug * /
             			if ( 4 > count( $array ) ) {
             				trigger_error( sprintf( 'mla-default-mime-types.tpl $array = "%1$s".', var_export( $array, true ) ), E_USER_WARNING );
             			} // */
             $key = strtolower($array[0]);
             self::$mla_upload_mime_descriptions[$key] = $array[4];
             self::$mla_upload_mime_templates[$key] = array('post_ID' => ++self::$mla_upload_mime_highest_ID, 'mime_type' => $array[1], 'core_type' => '', 'mla_type' => $array[1], 'source' => 'mla', 'standard_source' => 'mla', 'disabled' => true, 'description' => $array[4], 'icon_type' => $array[2], 'wp_icon_type' => $array[2], 'mla_icon_type' => $array[3], 'core_icon_type' => self::mla_get_core_icon_type($array[0]));
             if ('checked' == MLAOptions::mla_get_option(MLAOptions::MLA_ENABLE_MLA_ICONS)) {
                 self::$mla_upload_mime_templates[$key]['icon_type'] = self::$mla_upload_mime_templates[$key]['mla_icon_type'];
             }
         }
     }
     /*
      * Add the WordPress-standard (unfiltered) extensions, initialized to an active state
      */
     foreach ($core_types as $key => $value) {
         $key = strtolower($key);
         if (isset(self::$mla_upload_mime_templates[$key])) {
             $post_ID = self::$mla_upload_mime_templates[$key]['post_ID'];
             $mla_type = self::$mla_upload_mime_templates[$key]['mla_type'];
             $description = self::$mla_upload_mime_templates[$key]['description'];
             $icon_type = self::$mla_upload_mime_templates[$key]['icon_type'];
             $wp_icon_type = self::$mla_upload_mime_templates[$key]['wp_icon_type'];
             $mla_icon_type = self::$mla_upload_mime_templates[$key]['mla_icon_type'];
             $core_icon_type = self::$mla_upload_mime_templates[$key]['core_icon_type'];
         } else {
             $post_ID = ++self::$mla_upload_mime_highest_ID;
             $mla_type = '';
             $description = '';
             //				if ( NULL == $icon_type = wp_ext2type( $key ) ) {
             //					$icon_type = 'default';
             //				}
             $icon_type = self::mla_get_core_icon_type($key);
             $wp_icon_type = $icon_type;
             $mla_icon_type = $icon_type;
             $core_icon_type = $icon_type;
             //self::mla_get_core_icon_type( $key );
         }
         self::$mla_upload_mime_templates[$key] = array('post_ID' => $post_ID, 'mime_type' => $value, 'core_type' => $value, 'mla_type' => $mla_type, 'source' => 'core', 'standard_source' => 'core', 'disabled' => false, 'description' => $description, 'icon_type' => $icon_type, 'wp_icon_type' => $wp_icon_type, 'mla_icon_type' => $mla_icon_type, 'core_icon_type' => $core_icon_type);
         if ('checked' == MLAOptions::mla_get_option(MLAOptions::MLA_ENABLE_MLA_ICONS)) {
             self::$mla_upload_mime_templates[$key]['icon_type'] = self::$mla_upload_mime_templates[$key]['mla_icon_type'];
         }
     }
     /*
      * Add the user-defined custom types
      */
     foreach ($custom_types as $key => $value) {
         $key = strtolower($key);
         if (isset(self::$mla_upload_mime_templates[$key])) {
             extract(self::$mla_upload_mime_templates[$key]);
             /*
              * Make sure it's really custom
              */
             if ('core' == $source && $value == $core_type || 'mla' == $source && $value == $mla_type) {
                 continue;
             }
         } else {
             // existing type
             $core_type = '';
             $mla_type = '';
             $standard_source = '';
         }
         // brand new type
         if (NULL == ($icon_type = wp_ext2type($key))) {
             $icon_type = 'default';
         }
         self::$mla_upload_mime_templates[$key] = array('post_ID' => ++self::$mla_upload_mime_highest_ID, 'mime_type' => $value, 'core_type' => $core_type, 'mla_type' => $mla_type, 'source' => 'custom', 'standard_source' => $standard_source, 'disabled' => false, 'description' => '', 'icon_type' => $icon_type, 'wp_icon_type' => $icon_type, 'mla_icon_type' => $icon_type, 'core_icon_type' => self::mla_get_core_icon_type($key));
     }
     if ($first_time_called) {
         self::_put_upload_mime_templates();
         return true;
     }
     /*
      * Apply the current settings, if any
      */
     foreach (self::$mla_upload_mime_templates as $key => $value) {
         $default_description = isset(self::$mla_upload_mime_descriptions[$key]) ? self::$mla_upload_mime_descriptions[$key] : '';
         self::$mla_upload_mime_templates[$key]['disabled'] = isset($mla_upload_mimes['disabled'][$key]);
         self::$mla_upload_mime_templates[$key]['description'] = isset($mla_upload_mimes['description'][$key]) ? $mla_upload_mimes['description'][$key] : $default_description;
         if (isset($mla_upload_mimes['icon_type'][$key])) {
             self::$mla_upload_mime_templates[$key]['icon_type'] = $mla_upload_mimes['icon_type'][$key];
         }
     }
     return true;
 }
 /**
  * Perform Custom Field mapping on just-inserted or updated attachment
  *
  * @since 1.10
  *
  * @param	array	Attachment metadata for just-inserted attachment
  * @param	integer	ID of just-inserted attachment
  *
  * @return	void
  */
 public static function mla_update_attachment_metadata_filter($data, $post_id)
 {
     if ('checked' == MLAOptions::mla_get_option('enable_custom_field_mapping')) {
         $updates = MLAOptions::mla_evaluate_custom_field_mapping($post_id, 'single_attachment_mapping', NULL, $data);
         if (!empty($updates)) {
             $item_content = MLAData::mla_update_single_item($post_id, $updates);
         }
     }
     return $data;
 }
 /**
  * Filter the list of item "Rollover" actions
  *
  * Adds "Quick Translate" to the list of item-level "Rollover" actions.
  *
  * @since 2.11
  *
  * @param	array	$actions	The list of item "Rollover" actions.
  * @param	object	$item		The current Media Library item.
  * @param	string	$column		The List Table column slug.
  *
  * @return	array	updated		"Rollover" actions.
  */
 public static function mla_list_table_build_rollover_actions($actions, $item, $column)
 {
     if ('checked' == MLAOptions::mla_get_option('quick_translate', false, false, MLA_Polylang::$mla_language_option_definitions)) {
         /*
          * Add the Quick Translate action
          */
         $actions['translate hide-if-no-js'] = '<a class="inlineTranslate" href="#" title="' . __('Translate this item inline', 'media-library-assistant') . '">' . __('Quick Translate', 'media-library-assistant') . '</a>';
     }
     return $actions;
 }
 /**
  * Generate item thumbnail image tag
  *
  * @since 2.15
  * 
  * @param	object	A singular attachment (post) object
  *
  * @return	string	HTML <img> for thumbnail
  */
 protected function _build_item_thumbnail($item)
 {
     static $thumb = NULL, $item_id = 0;
     if ($item->ID == $item_id) {
         return $thumb;
     } else {
         $item_id = $item->ID;
     }
     $icon_width = MLAOptions::mla_get_option(MLAOptions::MLA_TABLE_ICON_SIZE);
     if ('checked' == MLAOptions::mla_get_option(MLAOptions::MLA_ENABLE_MLA_ICONS)) {
         if (empty($icon_width)) {
             $icon_width = $icon_height = 64;
         } else {
             $icon_width = $icon_height = absint($icon_width);
         }
     } else {
         if (empty($icon_width)) {
             if (MLATest::$wp_4dot3_plus) {
                 $icon_width = 60;
             } else {
                 $icon_width = 80;
             }
         } else {
             $icon_width = absint($icon_width);
         }
         if (MLATest::$wp_4dot3_plus) {
             $icon_height = $icon_width;
         } else {
             $icon_height = absint(0.75 * (double) $icon_width);
         }
     }
     $dimensions = array($icon_width, $icon_height);
     $thumb = wp_get_attachment_image($item->ID, $dimensions, true, array('class' => 'mla_media_thumbnail'));
     if (in_array($item->post_mime_type, array('image/svg+xml'))) {
         $thumb = preg_replace('/width=\\"[^\\"]*\\"/', sprintf('width="%1$d"', $dimensions[0]), $thumb);
         $thumb = preg_replace('/height=\\"[^\\"]*\\"/', sprintf('height="%1$d"', $dimensions[1]), $thumb);
     }
     return $thumb;
 }
 /**
  * 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;
 }
 /**
  * Supply the content for a custom column
  *
  * @since 0.1
  * 
  * @param	array	A singular attachment (post) object
  * @return	string	HTML markup to be placed inside the column
  */
 function column_icon($item)
 {
     if ('checked' == MLAOptions::mla_get_option(MLAOptions::MLA_ENABLE_MLA_ICONS)) {
         $thumb = wp_get_attachment_image($item->ID, array(64, 64), true, array('class' => 'mla_media_thumbnail_64_64'));
     } else {
         $thumb = wp_get_attachment_image($item->ID, array(80, 60), true, array('class' => 'mla_media_thumbnail_80_60'));
     }
     if ($this->is_trash || !current_user_can('edit_post', $item->ID)) {
         return $thumb;
     }
     return sprintf('<a href="%1$s" title="Edit &#8220;%2$s&#8221;">%3$s</a>', get_edit_post_link($item->ID, true), esc_attr($item->post_title), $thumb);
 }
Example #24
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;
 }
 /**
  * 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;
 }