/**
  * Assemble the in-memory representation of the (read-only) Optional Upload MIME Types 
  *
  * @since 1.40
  *
  * @return	boolean	Success (true) or failure (false) of the operation
  */
 private static function _get_optional_upload_mime_templates()
 {
     if (NULL != self::$mla_optional_upload_mime_templates) {
         return true;
     }
     self::$mla_optional_upload_mime_templates = array();
     $template_array = MLAData::mla_load_template('mla-default-mime-types.tpl');
     if (isset($template_array['mla-optional-mime-types'])) {
         $mla_mime_types = preg_split('/[\\r\\n]+/', $template_array['mla-optional-mime-types']);
         $ID = 0;
         foreach ($mla_mime_types as $mla_type) {
             $array = explode(',', $mla_type);
             $slug = $array[0];
             if ($matched_type = self::mla_get_upload_mime($slug)) {
                 $core_type = $matched_type['core_type'];
                 $mla_type = $matched_type['mla_type'];
             } else {
                 $core_type = '';
                 $mla_type = '';
             }
             self::$mla_optional_upload_mime_templates[++$ID] = array('ID' => $ID, 'slug' => $slug, 'mime_type' => $array[1], 'core_type' => $core_type, 'mla_type' => $mla_type, 'description' => $array[2]);
         }
     }
     return true;
 }
 /**
  * Adds settings values to be passed to the Media Manager in /wp-includes/js/media-views.js.
  * Declared public because it is a filter.
  *
  * @since 1.20
  *
  * @param	array	associative array with setting => value pairs
  * @param	object || NULL	current post object, if available
  *
  * @return	array	updated $settings array
  */
 public static function mla_media_view_settings_filter($settings, $post)
 {
     /*
      * If we know what screen we're on we can test our enabling options
      */
     self::$mla_media_modal_settings['screen'] = 'modal';
     if (function_exists('get_current_screen')) {
         $screen = get_current_screen();
         if (is_object($screen) && 'upload' == $screen->base) {
             self::$mla_media_modal_settings['screen'] = 'grid';
         }
     }
     $default_types = MLACore::mla_get_option(MLACoreOptions::MLA_POST_MIME_TYPES, true);
     self::$mla_media_modal_settings['comma'] = _x(',', 'tag_delimiter', 'media-library-assistant');
     self::$mla_media_modal_settings['ajaxNonce'] = wp_create_nonce(MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME);
     self::$mla_media_modal_settings['allMimeTypes'] = MLAMime::mla_pluck_table_views();
     self::$mla_media_modal_settings['allMimeTypes']['detached'] = $default_types['detached']['plural'];
     self::$mla_media_modal_settings['allMimeTypes']['attached'] = $default_types['attached']['plural'];
     /*
      * Trash items are allowed in the Media/Library Grid view
      */
     if (EMPTY_TRASH_DAYS && MEDIA_TRASH) {
         self::$mla_media_modal_settings['allMimeTypes']['trash'] = $default_types['trash']['plural'];
     }
     self::$mla_media_modal_settings['months'] = self::_months_dropdown('attachment');
     self::$mla_media_modal_settings['termsTaxonomy'] = MLACore::mla_taxonomy_support('', 'filter');
     $terms_options = self::mla_terms_options(MLA_List_Table::mla_get_taxonomy_filter_dropdown());
     self::$mla_media_modal_settings['termsClass'] = $terms_options['class'];
     self::$mla_media_modal_settings['termsValue'] = $terms_options['value'];
     self::$mla_media_modal_settings['termsText'] = $terms_options['text'];
     $current_version = get_bloginfo('version');
     if (version_compare($current_version, '3.9', '<') && version_compare($current_version, '3.6', '>=')) {
         self::$mla_media_modal_settings['termsIndent'] = '-';
     }
     self::$mla_media_modal_settings['enableMediaGrid'] = 'checked' == MLACore::mla_get_option(MLACoreOptions::MLA_MEDIA_GRID_TOOLBAR);
     self::$mla_media_modal_settings['enableMediaModal'] = 'checked' == MLACore::mla_get_option(MLACoreOptions::MLA_MEDIA_MODAL_TOOLBAR);
     self::$mla_media_modal_settings['enableDetailsCategory'] = 'checked' == MLACore::mla_get_option(MLACoreOptions::MLA_MEDIA_MODAL_DETAILS_CATEGORY_METABOX);
     self::$mla_media_modal_settings['enableDetailsTag'] = 'checked' == MLACore::mla_get_option(MLACoreOptions::MLA_MEDIA_MODAL_DETAILS_TAG_METABOX);
     self::$mla_media_modal_settings['enableMimeTypes'] = 'checked' == MLACore::mla_get_option(MLACoreOptions::MLA_MEDIA_MODAL_MIMETYPES);
     self::$mla_media_modal_settings['enableMonthsDropdown'] = 'checked' == MLACore::mla_get_option(MLACoreOptions::MLA_MEDIA_MODAL_MONTHS);
     self::$mla_media_modal_settings['enableSearchBox'] = 'checked' == MLACore::mla_get_option(MLACoreOptions::MLA_MEDIA_MODAL_SEARCHBOX);
     self::$mla_media_modal_settings['enableSearchBoxControls'] = 'checked' == MLACore::mla_get_option(MLACoreOptions::MLA_MEDIA_MODAL_SEARCHBOX_CONTROLS);
     $supported_taxonomies = MLACore::mla_supported_taxonomies('support');
     self::$mla_media_modal_settings['enableTermsDropdown'] = 'checked' == MLACore::mla_get_option(MLACoreOptions::MLA_MEDIA_MODAL_TERMS) && !empty($supported_taxonomies);
     self::$mla_media_modal_settings['enableTermsAutofill'] = 'checked' == MLACore::mla_get_option(MLACoreOptions::MLA_MEDIA_MODAL_DETAILS_AUTOFILL) && !empty($supported_taxonomies);
     $supported_taxonomies = MLACore::mla_supported_taxonomies('term-search');
     self::$mla_media_modal_settings['enableTermsSearch'] = 'checked' == MLACore::mla_get_option(MLACoreOptions::MLA_MEDIA_MODAL_TERMS_SEARCH) && !empty($supported_taxonomies);
     /*
      * Compile a list of the enhanced taxonomies
      */
     self::$mla_media_modal_settings['enhancedTaxonomies'] = array();
     foreach (get_taxonomies(array('show_ui' => true), 'objects') as $key => $value) {
         if (MLACore::mla_taxonomy_support($key)) {
             if (!($use_checklist = $value->hierarchical)) {
                 $use_checklist = MLACore::mla_taxonomy_support($key, 'flat-checklist');
             }
             /*
              * Make sure the appropriate MMMW Enhancement option has been checked
              */
             if ($use_checklist) {
                 if ('checked' === MLACore::mla_get_option(MLACoreOptions::MLA_MEDIA_MODAL_DETAILS_CATEGORY_METABOX)) {
                     self::$mla_media_modal_settings['enhancedTaxonomies'][] = $key;
                 }
             } else {
                 if ('checked' === MLACore::mla_get_option(MLACoreOptions::MLA_MEDIA_MODAL_DETAILS_TAG_METABOX)) {
                     self::$mla_media_modal_settings['enhancedTaxonomies'][] = $key;
                 }
             }
         }
         // taxonomy_support
     }
     // each taxonomy
     /*
      * Set and filter the initial values for toolbar controls
      */
     $search_defaults = MLACore::mla_get_option(MLACoreOptions::MLA_SEARCH_MEDIA_FILTER_DEFAULTS);
     $initial_values = array('filterMime' => 'all', 'filterUploaded' => 'all', 'filterMonth' => 0, 'filterTerm' => 0, 'searchConnector' => $search_defaults['search_connector'], 'searchFields' => $search_defaults['search_fields'], 'searchValue' => '');
     $initial_values = apply_filters('mla_media_modal_initial_filters', $initial_values, $post);
     // No supported taxonomies implies no "terms" search
     $supported_taxonomies = MLACore::mla_supported_taxonomies('support');
     if (empty($supported_taxonomies)) {
         $index = array_search('terms', $initial_values['searchFields']);
         if (false !== $index) {
             unset($initial_values['searchFields'][$index]);
         }
     }
     /*
      * Except for filterMime/post_mime_type, these will be passed
      * back to the server in the query['s'] field.
      */
     self::$mla_media_modal_settings['query']['initial']['filterMime'] = $initial_values['filterMime'];
     // post_mime_type 'image'; //
     self::$mla_media_modal_settings['query']['initial']['filterUploaded'] = $initial_values['filterUploaded'];
     // post_mime_type 'image'; //
     self::$mla_media_modal_settings['query']['initial']['filterMonth'] = $initial_values['filterMonth'];
     // mla_filter_month '201404'; //
     self::$mla_media_modal_settings['query']['initial']['filterTerm'] = $initial_values['filterTerm'];
     // mla_filter_term '175'; //
     self::$mla_media_modal_settings['query']['initial']['searchConnector'] = $initial_values['searchConnector'];
     // mla_search_connector 'OR'; //
     self::$mla_media_modal_settings['query']['initial']['searchFields'] = $initial_values['searchFields'];
     // mla_search_fields array( 'excerpt', 'title', 'content' ); //
     self::$mla_media_modal_settings['query']['initial']['searchValue'] = $initial_values['searchValue'];
     // mla_search_value 'col'; //
     //self::$mla_media_modal_settings['query']['initial']['termsSearch'] = $initial_values['termsSearch']; // mla_terms_search
     self::$mla_media_modal_settings['query']['initial']['searchClicks'] = 0;
     // mla_search_clicks, to force transmission
     $settings = array_merge($settings, array('mla_settings' => self::$mla_media_modal_settings));
     return apply_filters('mla_media_modal_settings', $settings, $post);
 }
 /**
  * Prepares the list of items for displaying
  *
  * This is where you prepare your data for display. This method will usually
  * be used to query the database, sort and filter the data, and generally
  * get it ready to be displayed. At a minimum, we should set $this->items and
  * $this->set_pagination_args().
  *
  * @since 1.40
  *
  * @return	void
  */
 function prepare_items()
 {
     $this->_column_headers = array($this->get_columns(), $this->get_hidden_columns(), $this->get_sortable_columns());
     /*
      * REQUIRED for pagination.
      */
     $total_items = MLAMime::mla_count_optional_upload_items($_REQUEST);
     $user = get_current_user_id();
     $screen = get_current_screen();
     $option = $screen->get_option('per_page', 'option');
     if (is_string($option)) {
         $per_page = get_user_meta($user, $option, true);
     } else {
         $per_page = 10;
     }
     if (empty($per_page) || $per_page < 1) {
         $per_page = $screen->get_option('per_page', 'default');
     }
     /*
      * REQUIRED. We also have to register our pagination options & calculations.
      */
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page)));
     $current_page = $this->get_pagenum();
     /*
      * REQUIRED. Assign sorted and paginated data to the items property, where 
      * it can be used by the rest of the class.
      */
     $this->items = MLAMime::mla_query_optional_upload_items($_REQUEST, ($current_page - 1) * $per_page, $per_page);
 }
 /**
  * Returns an associative array listing all the views that can be used with this table.
  * These are listed across the top of the page and managed by WordPress.
  *
  * @since 0.1
  * 
  * @return	array	View information,e.g., array ( id => link )
  */
 function get_views()
 {
     /*
      * Find current view
      */
     if ($this->detached) {
         $current_view = 'unattached';
     } elseif ($this->is_trash) {
         $current_view = 'trash';
     } elseif (empty($_REQUEST['post_mime_type'])) {
         if (isset($_REQUEST['meta_query'])) {
             $query = unserialize(stripslashes($_REQUEST['meta_query']));
             $current_view = $query['slug'];
         } else {
             $current_view = 'all';
         }
     } else {
         $current_view = $_REQUEST['post_mime_type'];
     }
     $mla_types = MLAMime::mla_query_view_items(array('orderby' => 'menu_order'), 0, 0);
     if (!is_array($mla_types)) {
         $mla_types = array();
     }
     /*
      * Filter the list, generate the views
      */
     $view_links = array();
     foreach ($mla_types as $value) {
         if ($value->table_view) {
             if ($current_view == $value->specification) {
                 $current_view = $value->slug;
             }
             if ($link = self::_get_view($value->slug, $current_view)) {
                 $view_links[$value->slug] = $link;
             }
         }
     }
     return $view_links;
 }
 /**
  * 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);
 }
 /**
  * Assemble the in-memory representation of the (read-only) Optional Upload MIME Types 
  *
  * @since 1.40
  *
  * @return	boolean	Success (true) or failure (false) of the operation
  */
 private static function _get_optional_upload_mime_templates()
 {
     if (NULL != self::$mla_optional_upload_mime_templates) {
         return true;
     }
     self::$mla_optional_upload_mime_templates = array();
     $template_array = MLACore::mla_load_template('mla-default-mime-types.tpl');
     if (isset($template_array['mla-optional-mime-types'])) {
         $mla_mime_types = preg_split('/[\\r\\n]+/', $template_array['mla-optional-mime-types']);
         $ID = 0;
         foreach ($mla_mime_types as $mla_type) {
             // Ignore blank lines
             if (empty($mla_type)) {
                 continue;
             }
             $array = explode(',', $mla_type);
             // Bypass damaged entries
             if (3 > count($array)) {
                 MLACore::mla_debug_add(__LINE__ . " _get_upload_mime_templates mla-default-mime-types.tpl section mla-optional-mime-types( {$ID} '{$mla_type}' ) \$array = " . var_export($array, true), MLACore::MLA_DEBUG_CATEGORY_ANY);
                 continue;
             }
             $slug = $array[0];
             if ($matched_type = self::mla_get_upload_mime($slug)) {
                 $core_type = $matched_type['core_type'];
                 $mla_type = $matched_type['mla_type'];
             } else {
                 $core_type = '';
                 $mla_type = '';
             }
             self::$mla_optional_upload_mime_templates[++$ID] = array('ID' => $ID, 'slug' => $slug, 'mime_type' => $array[1], 'core_type' => $core_type, 'mla_type' => $mla_type, 'description' => $array[2]);
         }
     }
     return true;
 }
Exemplo n.º 7
0
 /**
  * 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;
 }
Exemplo n.º 8
0
 /**
  * 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;
 }