/** * Compose the Post MIME Type Views tab content for the Settings subpage * * @since 1.40 * * @return array 'message' => status/error messages, 'body' => tab content */ private static function _compose_view_tab() { $page_template_array = MLAData::mla_load_template('admin-display-settings-view-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_view_tab', var_export($page_template_array, true)), 0); return ''; } /* * Convert checkbox values, if present */ if (isset($_REQUEST['mla_view_item'])) { $_REQUEST['mla_view_item']['post_mime_type'] = isset($_REQUEST['mla_view_item']['post_mime_type']); $_REQUEST['mla_view_item']['table_view'] = isset($_REQUEST['mla_view_item']['table_view']); } /* * Set default values, check for Add New Post MIME Type View button */ $add_form_values = array('slug' => '', 'singular' => '', 'plural' => '', 'specification' => '', 'post_mime_type' => 'checked="checked"', 'table_view' => 'checked="checked"', 'menu_order' => '', 'description' => ''); if (!empty($_REQUEST['mla-view-options-save'])) { check_admin_referer(MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME); $page_content = self::_save_view_settings(); } elseif (!empty($_REQUEST['mla-add-view-submit'])) { check_admin_referer(MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME); $page_content = MLAMime::mla_add_post_mime_type($_REQUEST['mla_view_item']); if (false !== strpos($page_content['message'], __('ERROR', 'media-library-assistant'))) { $add_form_values = $_REQUEST['mla_view_item']; $add_form_values['post_mime_type'] = $add_form_values['post_mime_type'] ? 'checked="checked"' : ''; $add_form_values['table_view'] = $add_form_values['table_view'] ? 'checked="checked"' : ''; } } else { $page_content = array('message' => '', 'body' => ''); } /* * Process bulk actions that affect an array of items */ $bulk_action = self::_current_bulk_action(); if ($bulk_action && $bulk_action != 'none') { if (isset($_REQUEST['cb_mla_item_ID'])) { /* * 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_post_mime_type_slug($post_ID); } foreach ($slugs as $slug) { switch ($bulk_action) { case 'delete': $item_content = MLAMime::mla_delete_post_mime_type($slug); break; case 'edit': $request = array('slug' => $slug); if ('-1' != $_REQUEST['post_mime_type']) { $request['post_mime_type'] = '1' == $_REQUEST['post_mime_type']; } if ('-1' != $_REQUEST['table_view']) { $request['table_view'] = '1' == $_REQUEST['table_view']; } if (!empty($_REQUEST['menu_order'])) { $request['menu_order'] = $_REQUEST['menu_order']; } $item_content = MLAMime::mla_update_post_mime_type($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 } 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_post_mime_type($_REQUEST['mla_item_slug']); break; case MLA::MLA_ADMIN_SINGLE_EDIT_DISPLAY: $view = MLAMime::mla_get_post_mime_type($_REQUEST['mla_item_slug']); $page_content = self::_compose_edit_view_tab($view, $page_template_array['single-item-edit']); break; case MLA::MLA_ADMIN_SINGLE_EDIT_UPDATE: if (!empty($_REQUEST['update'])) { $page_content = MLAMime::mla_update_post_mime_type($_REQUEST['mla_view_item']); if (false !== strpos($page_content['message'], __('ERROR', 'media-library-assistant'))) { $message = $page_content['message']; $page_content = self::_compose_edit_view_tab($_REQUEST['mla_view_item'], $page_template_array['single-item-edit']); $page_content['message'] = $message; } } else { $page_content = array('message' => sprintf(__('Edit view "%1$s" cancelled.', 'media-library-assistant'), $_REQUEST['mla_view_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_POST_MIME_TYPES)) { /* * Fill in with any page-level options */ $options_list = ''; foreach (MLAOptions::$mla_option_definitions as $key => $value) { if ('view' == $value['tab']) { $options_list .= self::mla_compose_option_row($key, $value); } } $page_values = array('Support is disabled' => __('View and Post MIME Type Support is disabled', 'media-library-assistant'), 'form_url' => admin_url('options-general.php') . '?page=mla-settings-menu-view&mla_tab=view', '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['view-disabled'], $page_values); return $page_content; } /* * Display the View 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', 'mla-optional-uploads-display'), $_SERVER['REQUEST_URI']); // Create an instance of our package class $MLAListViewTable = new MLA_View_List_Table(); // Fetch, prepare, sort, and filter our data $MLAListViewTable->prepare_items(); $MLAListViewTable->views(); /* * Start with any page-level options */ $options_list = ''; foreach (MLAOptions::$mla_option_definitions as $key => $value) { if ('view' == $value['tab']) { $options_list .= self::mla_compose_option_row($key, $value); } } $page_values = array('Library Views Processing' => __('Library Views/Post MIME Type Processing', 'media-library-assistant'), 'In this tab' => __('In this tab you can manage the list of "Post MIME Types", which are used by WordPress to define the views for the <em><strong>Media/Library</strong></em> screen and the <em><strong>Media Manager/Add Media</strong></em> "media items" drop down list. MLA’s <em><strong>Media/Assistant</strong></em> screen uses an enhanced version of the list, <em>Table Views</em>, to support views with multiple MIME Types (e.g., "audio,video") and wildcard specifications (e.g. "*/*ms*").', 'media-library-assistant'), 'You can find' => sprintf(__('You can find more information about library views, Post MIME types and how MLA and WordPress use 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&mla_tab=documentation#mla_views" title="' . __('Library View Processing documentation', 'media-library-assistant') . '">' . __('Library Views/Post MIME Type Processing', 'media-library-assistant') . '</a>'), 'settingsURL' => admin_url('options-general.php'), 'form_url' => admin_url('options-general.php') . '?page=mla-settings-menu-view&mla_tab=view', '_wpnonce' => wp_nonce_field(MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME, true, false), 'results' => !empty($_REQUEST['s']) ? '<h2 class="alignleft">' . __('Displaying search results for', 'media-library-assistant') . ': "' . $_REQUEST['s'] . '"</h2>' : '', 'Search Views' => __('Search Views', 'media-library-assistant'), 's' => isset($_REQUEST['s']) ? $_REQUEST['s'] : '', 'options_list' => $options_list, 'Save Changes' => __('Save Changes', 'media-library-assistant'), 'Add New View' => sprintf(__('Add New %1$s', 'media-library-assistant'), __('View', 'media-library-assistant')), 'Slug' => __('Slug', 'media-library-assistant'), 'The slug is' => __('The “slug” is the URL-friendly, unique key for the view. It must be all lowercase and contain only letters, numbers, periods (.), slashes (/) and hyphens (-). For “<strong>Post MIME Type</strong>” views, the slug is also the MIME type specification and <strong>must be a valid MIME</strong> type, e.g., “image” or “image/jpeg”.', 'media-library-assistant'), 'Singular Label' => __('Singular Label', 'media-library-assistant'), 'Plural Label' => __('Plural Label', 'media-library-assistant'), 'The labels' => __('The labels, e.g., “Image” and “Images” are used for column headers and other display purposes.', 'media-library-assistant'), 'Specification' => __('Specification', 'media-library-assistant'), 'If the specification' => __('If the MIME type specification differs from the slug, enter it here. You may include multiple MIME types, e.g., “audio,video” and/or wildcard specs, e.g., “*/*ms*”. This field will be ignored if the Post MIME Type box is checked.', 'media-library-assistant'), 'Post MIME Type' => __('Post MIME Type', 'media-library-assistant'), 'Check Post MIME' => __('Check this box if you want to add this entry to the list of MIME types returned by wp_get_mime_types().', 'media-library-assistant'), 'Table View' => __('Table View', 'media-library-assistant'), 'Check Table View' => __('Check this box if you want to add this entry to the list of Media/Assistant table views.', 'media-library-assistant'), 'Menu Order' => __('Menu Order', 'media-library-assistant'), 'You can choose' => __('You can choose your own table view order by entering a number (1 for first, etc.) in this field.', '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 View' => __('Add View', 'media-library-assistant'), 'colspan' => $MLAListViewTable->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'), 'No Change' => __('No Change', 'media-library-assistant'), 'No' => __('No', 'media-library-assistant'), 'Yes' => __('Yes', 'media-library-assistant')); 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(); $MLAListViewTable->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 Post MIME Type Views tab content for the Settings subpage * * @since 1.40 * * @return array 'message' => status/error messages, 'body' => tab content */ private static function _compose_view_tab() { $page_template_array = MLAData::mla_load_template(MLA_PLUGIN_PATH . 'tpls/admin-display-settings-view-tab.tpl'); if (!array($page_template_array)) { error_log('ERROR: MLASettings::_compose_view_tab $page_template_array = ' . var_export($page_template_array, true), 0); return ''; } /* * Convert checkbox values, if present */ if (isset($_REQUEST['mla_view_item'])) { $_REQUEST['mla_view_item']['post_mime_type'] = isset($_REQUEST['mla_view_item']['post_mime_type']); $_REQUEST['mla_view_item']['table_view'] = isset($_REQUEST['mla_view_item']['table_view']); } /* * Set default values, check for Add New Post MIME Type View button */ $add_form_values = array('slug' => '', 'singular' => '', 'plural' => '', 'specification' => '', 'post_mime_type' => 'checked="checked"', 'table_view' => 'checked="checked"', 'menu_order' => '', 'description' => ''); if (!empty($_REQUEST['mla-view-options-save'])) { check_admin_referer(MLA::MLA_ADMIN_NONCE, '_wpnonce'); $page_content = self::_save_view_settings(); } elseif (!empty($_REQUEST['mla-add-view-submit'])) { check_admin_referer(MLA::MLA_ADMIN_NONCE, '_wpnonce'); $page_content = MLAMime::mla_add_post_mime_type($_REQUEST['mla_view_item']); if (false !== strpos($page_content['message'], 'ERROR:')) { $add_form_values = $_REQUEST['mla_view_item']; $add_form_values['post_mime_type'] = $add_form_values['post_mime_type'] ? 'checked="checked"' : ''; $add_form_values['table_view'] = $add_form_values['table_view'] ? 'checked="checked"' : ''; } } else { $page_content = array('message' => '', 'body' => ''); } /* * Process bulk actions that affect an array of items */ $bulk_action = self::_current_bulk_action(); if ($bulk_action && $bulk_action != 'none') { if (isset($_REQUEST['cb_mla_item_ID'])) { /* * 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_post_mime_type_slug($post_ID); } foreach ($slugs as $slug) { switch ($bulk_action) { case 'delete': $item_content = MLAMime::mla_delete_post_mime_type($slug); break; case 'edit': $request = array('slug' => $slug); if ('-1' != $_REQUEST['post_mime_type']) { $request['post_mime_type'] = '1' == $_REQUEST['post_mime_type']; } if ('-1' != $_REQUEST['table_view']) { $request['table_view'] = '1' == $_REQUEST['table_view']; } if (!empty($_REQUEST['menu_order'])) { $request['menu_order'] = $_REQUEST['menu_order']; } $item_content = MLAMime::mla_update_post_mime_type($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 } 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_post_mime_type($_REQUEST['mla_item_slug']); break; case MLA::MLA_ADMIN_SINGLE_EDIT_DISPLAY: $view = MLAMime::mla_get_post_mime_type($_REQUEST['mla_item_slug']); $page_content = self::_compose_edit_view_tab($view, $page_template_array['single-item-edit']); break; case MLA::MLA_ADMIN_SINGLE_EDIT_UPDATE: if (!empty($_REQUEST['update'])) { $page_content = MLAMime::mla_update_post_mime_type($_REQUEST['mla_view_item']); if (false !== strpos($page_content['message'], 'ERROR:')) { $message = $page_content['message']; $page_content = self::_compose_edit_view_tab($_REQUEST['mla_view_item'], $page_template_array['single-item-edit']); $page_content['message'] = $message; } } else { $page_content = array('message' => 'Edit view "' . $_REQUEST['mla_view_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_POST_MIME_TYPES)) { /* * Fill in with any page-level options */ $options_list = ''; foreach (MLAOptions::$mla_option_definitions as $key => $value) { if ('view' == $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-view&mla_tab=view'); $page_content['body'] .= MLAData::mla_parse_template($page_template_array['view-disabled'], $page_values); return $page_content; } /* * Display the View 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', 'mla-optional-uploads-display'), $_SERVER['REQUEST_URI']); // Create an instance of our package class $MLAListViewTable = new MLA_View_List_Table(); // Fetch, prepare, sort, and filter our data $MLAListViewTable->prepare_items(); $MLAListViewTable->views(); /* * Start with any page-level options */ $options_list = ''; foreach (MLAOptions::$mla_option_definitions as $key => $value) { if ('view' == $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($MLAListViewTable->get_columns()), '_wpnonce' => wp_nonce_field(MLA::MLA_ADMIN_NONCE, '_wpnonce', true, false), 'form_url' => admin_url('options-general.php') . '?page=mla-settings-menu-view&mla_tab=view', 'results' => !empty($_REQUEST['s']) ? '<h3 style="float:left">Displaying search results for: "' . $_REQUEST['s'] . '"</h3>' : '', 's' => isset($_REQUEST['s']) ? $_REQUEST['s'] : ''); 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(); $MLAListViewTable->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; }