/**
  * Compose the File Upload MIME Types tab content for the Settings subpage
  *
  * @since 1.40
  *
  * @return	array	'message' => status/error messages, 'body' => tab content
  */
 private static function _compose_upload_tab()
 {
     $page_template_array = MLAData::mla_load_template('admin-display-settings-upload-tab.tpl');
     if (!is_array($page_template_array)) {
         /* translators: 1: ERROR tag 2: function name 3: non-array value */
         error_log(sprintf(_x('%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), 'MLASettings::_compose_upload_tab', var_export($page_template_array, true)), 0);
         return '';
     }
     /*
      * Untangle confusion between searching, canceling and selecting on the Optional Uploads screen
      */
     $bulk_action = self::_current_bulk_action();
     if (isset($_REQUEST['mla-optional-uploads-cancel']) || $bulk_action && $bulk_action == 'select') {
         unset($_REQUEST['mla-optional-uploads-search']);
         unset($_REQUEST['s']);
     }
     /*
      * Convert checkbox values, if present
      */
     if (isset($_REQUEST['mla_upload_item'])) {
         $_REQUEST['mla_upload_item']['disabled'] = isset($_REQUEST['mla_upload_item']['disabled']);
     }
     /*
      * Set default values, check for Add New Upload MIME Type button
      */
     $add_form_values = array('slug' => '', 'mime_type' => '', 'icon_type' => '.none.', 'disabled' => '', 'description' => '');
     if (!empty($_REQUEST['mla-upload-options-save'])) {
         check_admin_referer(MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME);
         $page_content = self::_save_upload_settings();
     } elseif (!empty($_REQUEST['mla-optional-uploads-search'])) {
         check_admin_referer(MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME);
         $page_content = self::_compose_optional_upload_tab($page_template_array);
     } elseif (!empty($_REQUEST['mla-optional-uploads-cancel'])) {
         $page_content = array('message' => '', 'body' => '');
     } elseif (!empty($_REQUEST['mla-optional-uploads-display'])) {
         if ('true' != $_REQUEST['mla-optional-uploads-display']) {
             check_admin_referer(MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME);
             unset($_REQUEST['s']);
         }
         $page_content = self::_compose_optional_upload_tab($page_template_array);
     } elseif (!empty($_REQUEST['mla-add-upload-submit'])) {
         check_admin_referer(MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME);
         $page_content = MLAMime::mla_add_upload_mime($_REQUEST['mla_upload_item']);
         if (false !== strpos($page_content['message'], __('ERROR', 'media-library-assistant'))) {
             $add_form_values = $_REQUEST['mla_upload_item'];
             $add_form_values['disabled'] = $add_form_values['disabled'] ? 'checked="checked"' : '';
         }
     } else {
         $page_content = array('message' => '', 'body' => '');
     }
     /*
      * Process bulk actions that affect an array of items
      */
     if ($bulk_action && $bulk_action != 'none') {
         if (isset($_REQUEST['cb_mla_item_ID'])) {
             if ('select' == $bulk_action) {
                 foreach ($_REQUEST['cb_mla_item_ID'] as $ID) {
                     $item_content = MLASettings::_process_optional_upload_mime($ID);
                     $page_content['message'] .= $item_content['message'] . '<br>';
                 }
             } else {
                 /*
                  * Convert post-ID to slug; separate loop required because delete changes post_IDs
                  */
                 $slugs = array();
                 foreach ($_REQUEST['cb_mla_item_ID'] as $post_ID) {
                     $slugs[] = MLAMime::mla_get_upload_mime_slug($post_ID);
                 }
                 foreach ($slugs as $slug) {
                     switch ($bulk_action) {
                         case 'delete':
                             $item_content = MLAMime::mla_delete_upload_mime($slug);
                             break;
                         case 'edit':
                             $request = array('slug' => $slug);
                             if ('-1' != $_REQUEST['disabled']) {
                                 $request['disabled'] = '1' == $_REQUEST['disabled'];
                             }
                             if ('.none.' != $_REQUEST['icon_type']) {
                                 $request['icon_type'] = $_REQUEST['icon_type'];
                             }
                             $item_content = MLAMime::mla_update_upload_mime($request);
                             break;
                         default:
                             $item_content = array('message' => sprintf(__('Unknown bulk action %1$s', 'media-library-assistant'), $bulk_action), 'body' => '');
                     }
                     // switch $bulk_action
                     $page_content['message'] .= $item_content['message'] . '<br>';
                 }
                 // foreach cb_attachment
             }
             // != select
         } else {
             /* translators: 1: action name, e.g., edit */
             $page_content['message'] = sprintf(__('Bulk Action %1$s - no items selected.', 'media-library-assistant'), $bulk_action);
         }
     }
     // $bulk_action
     /*
      * Process row-level actions that affect a single item
      */
     if (!empty($_REQUEST['mla_admin_action'])) {
         check_admin_referer(MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME);
         switch ($_REQUEST['mla_admin_action']) {
             case MLA::MLA_ADMIN_SINGLE_DELETE:
                 $page_content = MLAMime::mla_delete_upload_mime($_REQUEST['mla_item_slug']);
                 break;
             case MLA::MLA_ADMIN_SINGLE_EDIT_DISPLAY:
                 $view = MLAMime::mla_get_upload_mime($_REQUEST['mla_item_slug']);
                 $page_content = self::_compose_edit_upload_tab($view, $page_template_array);
                 break;
             case MLA::MLA_ADMIN_SINGLE_EDIT_UPDATE:
                 if (!empty($_REQUEST['update'])) {
                     $page_content = MLAMime::mla_update_upload_mime($_REQUEST['mla_upload_item']);
                     if (false !== strpos($page_content['message'], __('ERROR', 'media-library-assistant'))) {
                         $message = $page_content['message'];
                         $page_content = self::_compose_edit_upload_tab($_REQUEST['mla_upload_item'], $page_template_array);
                         $page_content['message'] = $message;
                     }
                 } elseif (!empty($_REQUEST['mla_item_ID'])) {
                     $page_content = self::_process_optional_upload_mime($_REQUEST['mla_item_ID']);
                 } else {
                     $page_content = array('message' => sprintf(__('Edit view "%1$s" cancelled.', 'media-library-assistant'), $_REQUEST['mla_upload_item']['original_slug']), 'body' => '');
                 }
                 break;
             default:
                 $page_content = array('message' => sprintf(__('Unknown mla_admin_action - "%1$s"', 'media-library-assistant'), $_REQUEST['mla_admin_action']), 'body' => '');
                 break;
         }
         // switch ($_REQUEST['mla_admin_action'])
     }
     // (!empty($_REQUEST['mla_admin_action'])
     if (!empty($page_content['body'])) {
         return $page_content;
     }
     /*
      * Check for disabled status
      */
     if ('checked' != MLAOptions::mla_get_option(MLAOptions::MLA_ENABLE_UPLOAD_MIMES)) {
         /*
          * Fill in with any page-level options
          */
         $options_list = '';
         foreach (MLAOptions::$mla_option_definitions as $key => $value) {
             if ('upload' == $value['tab']) {
                 $options_list .= self::mla_compose_option_row($key, $value);
             }
         }
         $page_values = array('Support is disabled' => __('Upload MIME Type Support is disabled', 'media-library-assistant'), 'form_url' => admin_url('options-general.php') . '?page=mla-settings-menu-upload&mla_tab=upload', 'options_list' => $options_list, 'Save Changes' => __('Save Changes', 'media-library-assistant'), '_wpnonce' => wp_nonce_field(MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME, true, false));
         $page_content['body'] .= MLAData::mla_parse_template($page_template_array['upload-disabled'], $page_values);
         return $page_content;
     }
     /*
      * Display the Upload MIME Types Table
      */
     $_SERVER['REQUEST_URI'] = remove_query_arg(array('mla_admin_action', 'mla_item_slug', 'mla_item_ID', '_wpnonce', '_wp_http_referer', 'action', 'action2', 'cb_mla_item_ID', 'mla-optional-uploads-search'), $_SERVER['REQUEST_URI']);
     //	Create an instance of our package class
     $MLAListUploadTable = new MLA_Upload_List_Table();
     //	Fetch, prepare, sort, and filter our data
     $MLAListUploadTable->prepare_items();
     /*
      * Start with any page-level options
      */
     $options_list = '';
     foreach (MLAOptions::$mla_option_definitions as $key => $value) {
         if ('upload' == $value['tab']) {
             $options_list .= self::mla_compose_option_row($key, $value);
         }
     }
     $page_values = array('File Extension Processing' => __('File Extension and MIME Type Processing', 'media-library-assistant'), 'In this tab' => __('In this tab you can manage the list of file extension/MIME Type associations, which are used by WordPress to decide what kind of files can be uploaded to the Media Library and to fill in the <strong><em>post_mime_type</em></strong> value. To upload a file, the file extension must be in this list and be active.', 'media-library-assistant'), 'You can find' => sprintf(__('You can find more information about file extensions, MIME types and how WordPress uses them in the %1$s section of the Documentation or by clicking the <strong>"Help"</strong> tab in the upper-right corner of this screen.', 'media-library-assistant'), '<a href="[+settingsURL+]?page=mla-settings-menu-documentation&amp;mla_tab=documentation#mla_uploads" title="' . __('File Extension Processing documentation', 'media-library-assistant') . '">' . __('File Extension and MIME Type Processing', 'media-library-assistant') . '</a>'), 'settingsURL' => admin_url('options-general.php'), 'Search Uploads' => __('Search Uploads', 'media-library-assistant'), 'To search by' => __('To search by extension, use ".", e.g., ".doc"', 'media-library-assistant'), 'form_url' => admin_url('options-general.php') . '?page=mla-settings-menu-upload&mla_tab=upload', '_wpnonce' => wp_nonce_field(MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME, true, false), 'options_list' => $options_list, 'Save Changes' => __('Save Changes', 'media-library-assistant'), 'Add New Upload' => sprintf(__('Add New %1$s', 'media-library-assistant'), __('Upload MIME Type', 'media-library-assistant')), 'To search database' => __('To search the database of over 1,500 known extension/type associations, click "Search Known Types" below the form.', 'media-library-assistant'), 'Extension' => __('Extension', 'media-library-assistant'), 'The extension is' => __('The &#8220;extension&#8221; is the file extension for this type, and unique key for the item. It must be all lowercase and contain only letters and numbers.', 'media-library-assistant'), 'MIME Type' => __('MIME Type', 'media-library-assistant'), 'The MIME Type' => __('The MIME Type must be all lowercase and contain only letters, numbers, periods (.), slashes (/) and hyphens (-). It <strong>must be a valid MIME</strong> type, e.g., &#8220;image&#8221; or &#8220;image/jpeg&#8221;.', 'media-library-assistant'), 'Icon Type' => __('Icon Type', 'media-library-assistant'), 'The Icon Type' => __('The Icon Type selects a thumbnail image displayed for non-image file types, such as PDF documents.', 'media-library-assistant'), 'Inactive' => __('Inactive', 'media-library-assistant'), 'Check this box' => __('Check this box if you want to remove this entry from the list of Upload MIME Types returned by get_allowed_mime_types().', 'media-library-assistant'), 'Description' => __('Description', 'media-library-assistant'), 'The description can' => __('The description can contain any documentation or notes you need to understand or use the item.', 'media-library-assistant'), 'Add Upload MIME' => __('Add Upload MIME Type', 'media-library-assistant'), 'search_url' => wp_nonce_url('?page=mla-settings-menu-upload&mla_tab=upload&mla-optional-uploads-search=Search', MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME), 'Search Known Types' => __('Search Known Types', 'media-library-assistant'), 'colspan' => $MLAListUploadTable->get_column_count(), 'Quick Edit' => __('<strong>Quick Edit</strong>', 'media-library-assistant'), 'Cancel' => __('Cancel', 'media-library-assistant'), 'Update' => __('Update', 'media-library-assistant'), 'Bulk Edit' => __('Bulk Edit', 'media-library-assistant'), 'Status' => __('Status', 'media-library-assistant'), 'No Change' => __('No Change', 'media-library-assistant'), 'Active' => __('Active', 'media-library-assistant'), 'results' => !empty($_REQUEST['s']) ? '<h2 class="alignleft">' . __('Displaying search results for', 'media-library-assistant') . ': "' . $_REQUEST['s'] . '"</h2>' : '', 's' => isset($_REQUEST['s']) ? $_REQUEST['s'] : '', 'icon_types' => self::mla_get_icon_type_dropdown($page_template_array, 'mla_upload_item[icon_type]'), 'inline_icon_types' => self::mla_get_icon_type_dropdown($page_template_array, 'icon_type'), 'bulk_icon_types' => self::mla_get_icon_type_dropdown($page_template_array, 'icon_type', '.nochange.'));
     foreach ($add_form_values as $key => $value) {
         $page_values[$key] = $value;
     }
     $page_content['body'] = MLAData::mla_parse_template($page_template_array['before-table'], $page_values);
     //	 Now we can render the completed list table
     ob_start();
     $MLAListUploadTable->views();
     $MLAListUploadTable->display();
     $page_content['body'] .= ob_get_contents();
     ob_end_clean();
     $page_content['body'] .= MLAData::mla_parse_template($page_template_array['after-table'], $page_values);
     return $page_content;
 }
 /**
  * Compose the File Upload MIME Types tab content for the Settings subpage
  *
  * @since 1.40
  *
  * @return	array	'message' => status/error messages, 'body' => tab content
  */
 private static function _compose_upload_tab()
 {
     $page_template_array = MLAData::mla_load_template(MLA_PLUGIN_PATH . 'tpls/admin-display-settings-upload-tab.tpl');
     if (!array($page_template_array)) {
         error_log('ERROR: MLASettings::_compose_upload_tab $page_template_array = ' . var_export($page_template_array, true), 0);
         return '';
     }
     /*
      * Untangle confusion between searching, canceling and selecting on the Optional Uploads screen
      */
     $bulk_action = self::_current_bulk_action();
     if (isset($_REQUEST['mla-optional-uploads-cancel']) || $bulk_action && $bulk_action == 'select') {
         unset($_REQUEST['mla-optional-uploads-search']);
         unset($_REQUEST['s']);
     }
     /*
      * Convert checkbox values, if present
      */
     if (isset($_REQUEST['mla_upload_item'])) {
         $_REQUEST['mla_upload_item']['disabled'] = isset($_REQUEST['mla_upload_item']['disabled']);
     }
     /*
      * Set default values, check for Add New Post MIME Type View button
      */
     $add_form_values = array('slug' => '', 'mime_type' => '', 'icon_type' => '.none.', 'disabled' => '', 'description' => '');
     if (!empty($_REQUEST['mla-upload-options-save'])) {
         check_admin_referer(MLA::MLA_ADMIN_NONCE, '_wpnonce');
         $page_content = self::_save_upload_settings();
     } elseif (!empty($_REQUEST['mla-optional-uploads-search'])) {
         check_admin_referer(MLA::MLA_ADMIN_NONCE, '_wpnonce');
         $page_content = self::_compose_optional_upload_tab($page_template_array);
     } elseif (!empty($_REQUEST['mla-optional-uploads-cancel'])) {
         $page_content = array('message' => '', 'body' => '');
     } elseif (!empty($_REQUEST['mla-optional-uploads-display'])) {
         if ('true' != $_REQUEST['mla-optional-uploads-display']) {
             check_admin_referer(MLA::MLA_ADMIN_NONCE, '_wpnonce');
             unset($_REQUEST['s']);
         }
         $page_content = self::_compose_optional_upload_tab($page_template_array);
     } elseif (!empty($_REQUEST['mla-add-upload-submit'])) {
         check_admin_referer(MLA::MLA_ADMIN_NONCE, '_wpnonce');
         $page_content = MLAMime::mla_add_upload_mime($_REQUEST['mla_upload_item']);
         if (false !== strpos($page_content['message'], 'ERROR:')) {
             $add_form_values = $_REQUEST['mla_upload_item'];
             $add_form_values['disabled'] = $add_form_values['disabled'] ? 'checked="checked"' : '';
         }
     } else {
         $page_content = array('message' => '', 'body' => '');
     }
     /*
      * Process bulk actions that affect an array of items
      */
     if ($bulk_action && $bulk_action != 'none') {
         if (isset($_REQUEST['cb_mla_item_ID'])) {
             if ('select' == $bulk_action) {
                 foreach ($_REQUEST['cb_mla_item_ID'] as $ID) {
                     $item_content = MLASettings::_process_optional_upload_mime($ID);
                     $page_content['message'] .= $item_content['message'] . '<br>';
                 }
             } else {
                 /*
                  * Convert post-ID to slug; separate loop required because delete changes post_IDs
                  */
                 $slugs = array();
                 foreach ($_REQUEST['cb_mla_item_ID'] as $post_ID) {
                     $slugs[] = MLAMime::mla_get_upload_mime_slug($post_ID);
                 }
                 foreach ($slugs as $slug) {
                     switch ($bulk_action) {
                         case 'delete':
                             $item_content = MLAMime::mla_delete_upload_mime($slug);
                             break;
                         case 'edit':
                             $request = array('slug' => $slug);
                             if ('-1' != $_REQUEST['disabled']) {
                                 $request['disabled'] = '1' == $_REQUEST['disabled'];
                             }
                             if ('.none.' != $_REQUEST['icon_type']) {
                                 $request['icon_type'] = $_REQUEST['icon_type'];
                             }
                             $item_content = MLAMime::mla_update_upload_mime($request);
                             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
             }
             // != select
         } else {
             $page_content['message'] = 'Bulk Action ' . $bulk_action . ' - no items selected.';
         }
     }
     // $bulk_action
     /*
      * Process row-level actions that affect a single item
      */
     if (!empty($_REQUEST['mla_admin_action'])) {
         check_admin_referer(MLA::MLA_ADMIN_NONCE);
         switch ($_REQUEST['mla_admin_action']) {
             case MLA::MLA_ADMIN_SINGLE_DELETE:
                 $page_content = MLAMime::mla_delete_upload_mime($_REQUEST['mla_item_slug']);
                 break;
             case MLA::MLA_ADMIN_SINGLE_EDIT_DISPLAY:
                 $view = MLAMime::mla_get_upload_mime($_REQUEST['mla_item_slug']);
                 $page_content = self::_compose_edit_upload_tab($view, $page_template_array);
                 break;
             case MLA::MLA_ADMIN_SINGLE_EDIT_UPDATE:
                 if (!empty($_REQUEST['update'])) {
                     $page_content = MLAMime::mla_update_upload_mime($_REQUEST['mla_upload_item']);
                     if (false !== strpos($page_content['message'], 'ERROR:')) {
                         $message = $page_content['message'];
                         $page_content = self::_compose_edit_upload_tab($_REQUEST['mla_upload_item'], $page_template_array);
                         $page_content['message'] = $message;
                     }
                 } elseif (!empty($_REQUEST['mla_item_ID'])) {
                     $page_content = self::_process_optional_upload_mime($_REQUEST['mla_item_ID']);
                 } else {
                     $page_content = array('message' => 'Edit view "' . $_REQUEST['mla_upload_item']['original_slug'] . '" cancelled.', 'body' => '');
                 }
                 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'])) {
         return $page_content;
     }
     /*
      * Check for disabled status
      */
     if ('checked' != MLAOptions::mla_get_option(MLAOptions::MLA_ENABLE_UPLOAD_MIMES)) {
         /*
          * Fill in with any page-level options
          */
         $options_list = '';
         foreach (MLAOptions::$mla_option_definitions as $key => $value) {
             if ('upload' == $value['tab']) {
                 $options_list .= self::_compose_option_row($key, $value);
             }
         }
         $page_values = array('settingsURL' => admin_url('options-general.php'), 'options_list' => $options_list, '_wpnonce' => wp_nonce_field(MLA::MLA_ADMIN_NONCE, '_wpnonce', true, false), 'form_url' => admin_url('options-general.php') . '?page=mla-settings-menu-upload&mla_tab=upload');
         $page_content['body'] .= MLAData::mla_parse_template($page_template_array['upload-disabled'], $page_values);
         return $page_content;
     }
     /*
      * Display the Upload MIME Types Table
      */
     $_SERVER['REQUEST_URI'] = remove_query_arg(array('mla_admin_action', 'mla_item_slug', 'mla_item_ID', '_wpnonce', '_wp_http_referer', 'action', 'action2', 'cb_mla_item_ID', 'mla-optional-uploads-search'), $_SERVER['REQUEST_URI']);
     //	Create an instance of our package class
     $MLAListUploadTable = new MLA_Upload_List_Table();
     //	Fetch, prepare, sort, and filter our data
     $MLAListUploadTable->prepare_items();
     /*
      * Start with any page-level options
      */
     $options_list = '';
     foreach (MLAOptions::$mla_option_definitions as $key => $value) {
         if ('upload' == $value['tab']) {
             $options_list .= self::_compose_option_row($key, $value);
         }
     }
     $page_values = array('settingsURL' => admin_url('options-general.php'), 'options_list' => $options_list, 'colspan' => count($MLAListUploadTable->get_columns()), '_wpnonce' => wp_nonce_field(MLA::MLA_ADMIN_NONCE, '_wpnonce', true, false), 'form_url' => admin_url('options-general.php') . '?page=mla-settings-menu-upload&mla_tab=upload', 'results' => !empty($_REQUEST['s']) ? '<h3 style="float:left">Displaying search results for: "' . $_REQUEST['s'] . '"</h3>' : '', 's' => isset($_REQUEST['s']) ? $_REQUEST['s'] : '', 'icon_types' => self::mla_get_icon_type_dropdown($page_template_array, 'mla_upload_item[icon_type]'), 'inline_icon_types' => self::mla_get_icon_type_dropdown($page_template_array, 'icon_type'), 'bulk_icon_types' => self::mla_get_icon_type_dropdown($page_template_array, 'icon_type', '.nochange.'), 'search_url' => wp_nonce_url('?page=mla-settings-menu-upload&mla_tab=upload&mla-optional-uploads-search=Search', MLA::MLA_ADMIN_NONCE));
     foreach ($add_form_values as $key => $value) {
         $page_values[$key] = $value;
     }
     $page_content['body'] = MLAData::mla_parse_template($page_template_array['before-table'], $page_values);
     //	 Now we can render the completed list table
     ob_start();
     $MLAListUploadTable->views();
     $MLAListUploadTable->display();
     $page_content['body'] .= ob_get_contents();
     ob_end_clean();
     $page_content['body'] .= MLAData::mla_parse_template($page_template_array['after-table'], $page_values);
     return $page_content;
 }