Exemplo n.º 1
0
 /**
  * Initialization function, similar to __construct()
  *
  * @since 0.60
  *
  * @return	void
  */
 public static function initialize()
 {
     MLATest::$wp_3dot5 = version_compare(get_bloginfo('version'), '3.5.0', '>=') && version_compare(get_bloginfo('version'), '3.5.99', '<=');
     MLATest::$wp_4dot3_plus = version_compare(get_bloginfo('version'), '4.2.99', '>=');
     /*
      * This is the earliest effective place to change error_reporting
      */
     //error_reporting( E_ALL | E_STRICT | E_DEPRECATED | E_USER_DEPRECATED | E_USER_ERROR | E_USER_WARNING );
     //error_reporting( E_ALL | E_STRICT );
     MLA::$original_php_reporting = sprintf('0x%1$04X', error_reporting());
     $php_reporting = trim(MLAOptions::mla_get_option(MLAOptions::MLA_DEBUG_REPLACE_PHP_REPORTING));
     if (!empty($php_reporting)) {
         @error_reporting(0 + $php_reporting);
     }
     /*
      * This is the earliest effective place to localize values in other plugin components
      */
     MLAOptions::mla_localize_option_definitions_array();
     MLASettings::mla_localize_tablist();
     MLA_List_Table::mla_localize_default_columns_array();
     MLA_Upload_List_Table::mla_localize_default_columns_array();
     MLA_Upload_Optional_List_Table::mla_localize_default_columns_array();
     MLA_View_List_Table::mla_localize_default_columns_array();
 }
Exemplo n.º 2
0
 /**
  * Ajax handler to set post_parent for a single attachment
  *
  * Adapted from wp_ajax_inline_save in /wp-admin/includes/ajax-actions.php
  *
  * @since 0.20
  *
  * @return	void	echo HTML <td> innerHTML for updated call or error message, then die()
  */
 public static function mla_set_parent_ajax_action()
 {
     check_ajax_referer(MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME);
     if (empty($_REQUEST['post_ID'])) {
         echo __('ERROR', 'media-library-assistant') . ': ' . __('No post ID found', 'media-library-assistant');
         die;
     } else {
         $post_id = $_REQUEST['post_ID'];
     }
     if (!current_user_can('edit_post', $post_id)) {
         wp_die(__('ERROR', 'media-library-assistant') . ': ' . __('You are not allowed to edit this Attachment.', 'media-library-assistant'));
     }
     if (!class_exists('MLAData')) {
         require_once MLA_PLUGIN_PATH . 'includes/class-mla-data.php';
         MLAData::initialize();
     }
     $results = MLAData::mla_update_single_item($post_id, $_REQUEST);
     if (false !== strpos($results['message'], __('ERROR', 'media-library-assistant'))) {
         wp_die($results['message']);
     }
     $new_item = (object) MLAData::mla_get_attachment_by_id($post_id);
     if (!class_exists('MLA_List_Table')) {
         require_once MLA_PLUGIN_PATH . 'includes/class-mla-list-table.php';
         MLA_List_Table::mla_admin_init_action();
     }
     //	Create an instance of our package class and echo the new HTML
     $MLAListTable = apply_filters('mla_list_table_new_instance', NULL);
     if (is_null($MLAListTable)) {
         $MLAListTable = new MLA_List_Table();
     }
     $MLAListTable->single_row($new_item);
     die;
     // this is required to return a proper result
 }
Exemplo n.º 3
0
 /**
  * Sanitize and expand query arguments from request variables
  *
  * Prepare the arguments for WP_Query.
  * Modeled after wp_edit_attachments_query in wp-admin/post.php
  *
  * @since 0.1
  *
  * @param	array	query parameters from web page, usually found in $_REQUEST
  * @param	int		Optional number of rows (default 0) to skip over to reach desired page
  * @param	int		Optional number of rows on each page (0 = all rows, default)
  *
  * @return	array	revised arguments suitable for WP_Query
  */
 private static function _prepare_list_table_query($raw_request, $offset = 0, $count = 0)
 {
     /*
      * Go through the $raw_request, take only the arguments that are used in the query and
      * sanitize or validate them.
      */
     if (!is_array($raw_request)) {
         error_log('ERROR: _prepare_list_table_query $raw_request = ' . var_export($raw_request, true), 0);
         return null;
     }
     /*
      * 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());
     $current_orderby = MLAOptions::mla_get_option(MLAOptions::MLA_DEFAULT_ORDERBY);
     $found_current = false;
     foreach ($default_orderby as $key => $value) {
         if ($current_orderby == $value[0]) {
             $found_current = true;
             break;
         }
     }
     if (!$found_current) {
         MLAOptions::mla_delete_option(MLAOptions::MLA_DEFAULT_ORDERBY);
         $current_orderby = MLAOptions::mla_get_option(MLAOptions::MLA_DEFAULT_ORDERBY);
     }
     $clean_request = array('m' => 0, 'orderby' => $current_orderby, 'order' => MLAOptions::mla_get_option(MLAOptions::MLA_DEFAULT_ORDER), 'post_type' => 'attachment', 'post_status' => 'inherit', 'mla_search_connector' => 'AND', 'mla_search_fields' => array());
     foreach ($raw_request as $key => $value) {
         switch ($key) {
             /*
              * 'sentence' and 'exact' modify the keyword search ('s')
              * Their value is not important, only their presence.
              */
             case 'sentence':
             case 'exact':
             case 'mla-tax':
             case 'mla-term':
                 $clean_request[$key] = sanitize_key($value);
                 break;
             case 'orderby':
                 if ('none' == $value) {
                     $clean_request[$key] = $value;
                 } else {
                     $sortable_columns = MLA_List_Table::mla_get_sortable_columns();
                     foreach ($sortable_columns as $sort_key => $sort_value) {
                         if ($value == $sort_value[0]) {
                             $clean_request[$key] = $value;
                             break;
                         }
                     }
                     // foreach
                 }
                 break;
                 /*
                  * post__in and post__not_in are used in the Media Modal Ajax queries
                  */
             /*
              * post__in and post__not_in are used in the Media Modal Ajax queries
              */
             case 'post__in':
             case 'post__not_in':
             case 'post_mime_type':
                 $clean_request[$key] = $value;
                 break;
             case 'parent':
             case 'post_parent':
                 $clean_request['post_parent'] = absint($value);
                 break;
                 /*
                  * ['m'] - filter by year and month of post, e.g., 201204
                  */
             /*
              * ['m'] - filter by year and month of post, e.g., 201204
              */
             case 'author':
             case 'm':
                 $clean_request[$key] = absint($value);
                 break;
                 /*
                  * ['mla_filter_term'] - filter by category or tag ID; -1 allowed
                  */
             /*
              * ['mla_filter_term'] - filter by category or tag ID; -1 allowed
              */
             case 'mla_filter_term':
                 $clean_request[$key] = intval($value);
                 break;
             case 'order':
                 switch ($value = strtoupper($value)) {
                     case 'ASC':
                     case 'DESC':
                         $clean_request[$key] = $value;
                         break;
                     default:
                         $clean_request[$key] = 'ASC';
                 }
                 break;
             case 'detached':
                 if ('1' == $value) {
                     $clean_request['detached'] = '1';
                 }
                 break;
             case 'status':
                 if ('trash' == $value) {
                     $clean_request['post_status'] = 'trash';
                 }
                 break;
                 /*
                  * ['s'] - Search Media by one or more keywords
                  * ['mla_search_connector'], ['mla_search_fields'] - Search Media options
                  */
             /*
              * ['s'] - Search Media by one or more keywords
              * ['mla_search_connector'], ['mla_search_fields'] - Search Media options
              */
             case 's':
                 switch (substr($value, 0, 3)) {
                     case '>|<':
                         $clean_request['debug'] = 'console';
                         break;
                     case '<|>':
                         $clean_request['debug'] = 'log';
                         break;
                 }
                 if (isset($clean_request['debug'])) {
                     $value = substr($value, 3);
                 }
                 $value = stripslashes(trim($value));
                 if (!empty($value)) {
                     $clean_request[$key] = $value;
                 }
                 break;
             case 'mla_search_connector':
             case 'mla_search_fields':
                 $clean_request[$key] = $value;
                 break;
             case 'mla-metakey':
             case 'mla-metavalue':
                 $clean_request[$key] = stripslashes($value);
                 break;
             case 'meta_query':
                 if (!empty($value)) {
                     if (is_array($value)) {
                         $clean_request[$key] = $value;
                     } else {
                         $clean_request[$key] = unserialize(stripslashes($value));
                         unset($clean_request[$key]['slug']);
                     }
                     // not array
                 }
                 break;
             default:
                 // ignore anything else in $_REQUEST
         }
         // switch $key
     }
     // foreach $raw_request
     /*
      * Pass query parameters to the filters for _execute_list_table_query
      */
     self::$query_parameters = array('use_postmeta_view' => false, 'orderby' => $clean_request['orderby'], 'order' => $clean_request['order']);
     self::$query_parameters['detached'] = isset($clean_request['detached']);
     /*
      * Matching a meta_value to NULL requires a LEFT JOIN to a view and a special WHERE clause
      * Matching a wildcard pattern requires mainpulating the WHERE clause, too
      */
     if (isset($clean_request['meta_query']['key'])) {
         self::$query_parameters['use_postmeta_view'] = true;
         self::$query_parameters['postmeta_key'] = $clean_request['meta_query']['key'];
         self::$query_parameters['postmeta_value'] = NULL;
         unset($clean_request['meta_query']);
     } elseif (isset($clean_request['meta_query']['patterns'])) {
         self::$query_parameters['patterns'] = $clean_request['meta_query']['patterns'];
         unset($clean_request['meta_query']['patterns']);
     }
     if (isset($clean_request['debug'])) {
         self::$query_parameters['debug'] = $clean_request['debug'];
         unset($clean_request['debug']);
     }
     /*
      * We must patch the WHERE clause if there are leading spaces in the meta_value
      */
     if (isset($clean_request['mla-metavalue']) && ' ' == $clean_request['mla-metavalue'][0]) {
         self::$query_parameters['mla-metavalue'] = $clean_request['mla-metavalue'];
     }
     /*
      * We will handle keyword search in the mla_query_posts_search_filter.
      * There must be at least one search field to do a search.
      */
     if (isset($clean_request['s'])) {
         if (!empty($clean_request['mla_search_fields'])) {
             self::$query_parameters['s'] = $clean_request['s'];
             self::$query_parameters['mla_search_connector'] = $clean_request['mla_search_connector'];
             self::$query_parameters['mla_search_fields'] = $clean_request['mla_search_fields'];
             self::$query_parameters['sentence'] = isset($clean_request['sentence']);
             self::$query_parameters['exact'] = isset($clean_request['exact']);
             if (in_array('alt-text', self::$query_parameters['mla_search_fields'])) {
                 self::$query_parameters['use_postmeta_view'] = true;
             }
             self::$query_parameters['postmeta_key'] = '_wp_attachment_image_alt';
         }
         // !empty
         // unset( $clean_request['s'] ); // WP v3.7 requires this to be present for posts_search filter
         unset($clean_request['mla_search_connector']);
         unset($clean_request['mla_search_fields']);
         unset($clean_request['sentence']);
         unset($clean_request['exact']);
     }
     /*
      * We have to handle custom field/post_meta values here
      * because they need a JOIN clause supplied by WP_Query
      */
     if ('c_' == substr(self::$query_parameters['orderby'], 0, 2)) {
         $option_value = MLAOptions::mla_custom_field_option_value(self::$query_parameters['orderby']);
         if (isset($option_value['name'])) {
             self::$query_parameters['use_postmeta_view'] = true;
             self::$query_parameters['postmeta_key'] = $option_value['name'];
             if (isset($clean_request['orderby'])) {
                 unset($clean_request['orderby']);
             }
             if (isset($clean_request['order'])) {
                 unset($clean_request['order']);
             }
         }
     } else {
         switch (self::$query_parameters['orderby']) {
             /*
              * '_wp_attachment_image_alt' is special; we'll handle it in the JOIN and ORDERBY filters
              */
             case '_wp_attachment_image_alt':
                 self::$query_parameters['use_postmeta_view'] = true;
                 self::$query_parameters['postmeta_key'] = '_wp_attachment_image_alt';
                 if (isset($clean_request['orderby'])) {
                     unset($clean_request['orderby']);
                 }
                 if (isset($clean_request['order'])) {
                     unset($clean_request['order']);
                 }
                 break;
             case '_wp_attached_file':
                 $clean_request['meta_key'] = '_wp_attached_file';
                 $clean_request['orderby'] = 'meta_value';
                 $clean_request['order'] = self::$query_parameters['order'];
                 break;
         }
         // switch $orderby
     }
     /*
      * Ignore incoming paged value; use offset and count instead
      */
     if ((int) $count > 0) {
         $clean_request['offset'] = $offset;
         $clean_request['posts_per_page'] = $count;
     } elseif ((int) $count == -1) {
         $clean_request['posts_per_page'] = $count;
     }
     /*
      * ['mla_filter_term'] - filter by taxonomy
      *
      * cat =  0 is "All Categories", i.e., no filtering
      * cat = -1 is "No Categories"
      */
     if (isset($clean_request['mla_filter_term'])) {
         if ($clean_request['mla_filter_term'] != 0) {
             $tax_filter = MLAOptions::mla_taxonomy_support('', 'filter');
             if ($clean_request['mla_filter_term'] == -1) {
                 $term_list = get_terms($tax_filter, array('fields' => 'ids', 'hide_empty' => false));
                 $clean_request['tax_query'] = array(array('taxonomy' => $tax_filter, 'field' => 'id', 'terms' => $term_list, 'operator' => 'NOT IN'));
             } else {
                 $clean_request['tax_query'] = array(array('taxonomy' => $tax_filter, 'field' => 'id', 'terms' => array((int) $clean_request['mla_filter_term']), 'include_children' => 'checked' == MLAOptions::mla_get_option(MLAOptions::MLA_TAXONOMY_FILTER_INCLUDE_CHILDREN)));
             }
             // mla_filter_term != -1
         }
         // mla_filter_term != 0
         unset($clean_request['mla_filter_term']);
     }
     // isset mla_filter_term
     if (isset($clean_request['mla-tax']) && isset($clean_request['mla-term'])) {
         $clean_request['tax_query'] = array(array('taxonomy' => $clean_request['mla-tax'], 'field' => 'slug', 'terms' => $clean_request['mla-term'], 'include_children' => false));
         unset($clean_request['mla-tax']);
         unset($clean_request['mla-term']);
     }
     // isset mla_tax
     if (isset($clean_request['mla-metakey']) && isset($clean_request['mla-metavalue'])) {
         $clean_request['meta_key'] = $clean_request['mla-metakey'];
         $clean_request['meta_value'] = $clean_request['mla-metavalue'];
         unset($clean_request['mla-metakey']);
         unset($clean_request['mla-metavalue']);
     }
     // isset mla_tax
     return $clean_request;
 }
 /**
  * Ajax handler to Quick Translate a single attachment
  *
  * @since 2.11
  *
  * @return	void	echo HTML <td> innerHTML for updated call or error message, then die()
  */
 public static function quick_translate()
 {
     global $polylang;
     check_ajax_referer(MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME);
     if (empty($_REQUEST['post_ID'])) {
         echo __('ERROR: No post ID found', 'media-library-assistant');
         die;
     } else {
         $post_id = (int) $_REQUEST['post_ID'];
     }
     if (!current_user_can('edit_post', $post_id)) {
         wp_die(__('You are not allowed to edit this Attachment.', 'media-library-assistant'));
     }
     self::_build_existing_terms($post_id);
     /*
      * pll_quick_language is used by the translation status links; edit or add the selected translation
      * inline_lang_choice is the value of the Language dropdown control; change the value of the current item
      */
     if (!empty($_REQUEST['pll_quick_language'])) {
         $new_id = MLA_Polylang::_get_translation($post_id, $_REQUEST['pll_quick_language']);
     } else {
         $new_id = $post_id;
         // Language dropdown in Quick Edit area
         if (isset($_REQUEST['inline_lang_choice'])) {
             $translations = $polylang->model->get_translations('post', $post_id);
             if (!array_key_exists($_REQUEST['inline_lang_choice'], $translations)) {
                 $post = get_post($post_id);
                 // save_post() does a check_admin_referer() security test
                 $_REQUEST['_inline_edit'] = wp_create_nonce('inlineeditnonce');
                 $polylang->filters_post->save_post($post_id, $post, true);
                 if ('checked' == MLAOptions::mla_get_option('term_assignment', false, false, MLA_Polylang::$mla_language_option_definitions)) {
                     // Record new language for Term Assignment and Synchronization
                     if (!empty($_REQUEST['tax_input'])) {
                         // Discard the old translation, which is gone
                         unset(self::$existing_terms[self::$existing_terms['slug']]);
                         self::$existing_terms['slug'] = $_REQUEST['inline_lang_choice'];
                     }
                     self::_build_existing_terms($post_id);
                     self::_build_tax_input($post_id);
                     $tax_inputs = self::_apply_tax_input(0, $_REQUEST['inline_lang_choice']);
                 } else {
                     $tax_inputs = NULL;
                 }
                 if (!empty($tax_inputs)) {
                     MLAData::mla_update_single_item($post_id, array(), $tax_inputs);
                 }
             }
             // change language
         }
     }
     //	Create an instance of our package class and echo the new HTML for all translations
     $translations = $polylang->model->get_translations('post', $post_id);
     $MLAListTable = new MLA_List_Table();
     $new_item = (object) MLAData::mla_get_attachment_by_id($new_id);
     $MLAListTable->single_row($new_item);
     foreach ($translations as $language => $post_id) {
         if ($new_id == $post_id) {
             continue;
         }
         $new_item = (object) MLAData::mla_get_attachment_by_id($post_id);
         $MLAListTable->single_row($new_item);
         echo "\n";
     }
     die;
     // this is required to return a proper result
 }
Exemplo n.º 5
0
 /**
  * Build the hidden form for the "Set Parent" popup modal window
  *
  * @since 1.90
  *
  * @param	boolean	true to return complete form, false to return mla-set-parent-div
  *
  * @return	string	HTML <form> markup for hidden form
  */
 public static function mla_set_parent_form($return_form = true)
 {
     $set_parent_template = MLAData::mla_load_template('admin-set-parent-form.tpl');
     if (!is_array($set_parent_template)) {
         /* translators: 1: ERROR tag 2: function name 3: non-array value */
         error_log(sprintf(_x('%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), 'MLA::_build_inline_edit_form', var_export($set_parent_template, true)), 0);
         return '';
     }
     $page_values = array('Select Parent' => __('Select Parent', 'media-library-assistant'), 'Search' => __('Search', 'media-library-assistant'), 'post_type_dropdown' => self::_compose_post_type_select($set_parent_template, 'all'), 'For' => __('For', 'media-library-assistant'), 'Previous' => '&laquo;', 'Next' => '&raquo;', 'count' => '50', 'paged' => '1', 'found' => '0', 'Title' => __('Title', 'media-library-assistant'), 'Type' => __('Type', 'media-library-assistant'), 'Date' => __('Date', 'media-library-assistant'), 'Status' => __('Status', 'media-library-assistant'), 'Unattached' => __('Unattached', 'media-library-assistant'), 'mla_find_posts_nonce' => wp_nonce_field('mla_find_posts', 'mla-set-parent-ajax-nonce', false, false));
     ob_start();
     submit_button(__('Cancel', 'media-library-assistant'), 'button-secondary cancel alignleft', 'mla-set-parent-cancel', false);
     $page_values['mla_set_parent_cancel'] = ob_get_clean();
     ob_start();
     submit_button(__('Update', 'media-library-assistant'), 'button-primary alignright', 'mla-set-parent-submit', false);
     $page_values['mla_set_parent_update'] = ob_get_clean();
     $set_parent_div = MLAData::mla_parse_template($set_parent_template['mla-set-parent-div'], $page_values);
     if (!$return_form) {
         return $set_parent_div;
     }
     $page_values = array('mla_set_parent_url' => esc_url(add_query_arg(array_merge(MLA_List_Table::mla_submenu_arguments(false), array('page' => MLA::ADMIN_PAGE_SLUG)), admin_url('upload.php'))), 'mla_set_parent_action' => self::MLA_ADMIN_SET_PARENT, 'wpnonce' => wp_nonce_field(self::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME, true, false), 'mla_set_parent_div' => $set_parent_div);
     $set_parent_form = MLAData::mla_parse_template($set_parent_template['mla-set-parent-form'], $page_values);
     return $set_parent_form;
 }
 /**
  * Build the hidden form for the "Search Terms" popup modal window
  *
  * @since 1.90
  *
  * @return	string	HTML <form> markup for hidden form
  */
 public static function mla_terms_search_form()
 {
     $page_template_array = MLACore::mla_load_template('admin-terms-search-form.tpl');
     if (!is_array($page_template_array)) {
         /* translators: 1: ERROR tag 2: function name 3: non-array value */
         error_log(sprintf(_x('%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), 'MLA::_build_terms_search_form', var_export($page_template_array, true)), 0);
         return '';
     }
     $taxonomies = array();
     foreach (get_object_taxonomies('attachment', 'objects') as $taxonomy) {
         if (MLACore::mla_taxonomy_support($taxonomy->name, 'support')) {
             $taxonomies[] = $taxonomy;
         }
     }
     if (empty($taxonomies)) {
         $page_values = array('Search Terms' => __('Search Terms', 'media-library-assistant'), 'message' => __('There are no taxonomies to search', 'media-library-assistant'));
         $terms_search_tpl = MLAData::mla_parse_template($page_template_array['mla-terms-search-empty-div'], $page_values);
     } else {
         $taxonomy_list = '';
         foreach ($taxonomies as $taxonomy) {
             $page_values = array('taxonomy_checked' => MLACore::mla_taxonomy_support($taxonomy->name, 'term-search') ? 'checked="checked"' : '', 'taxonomy_slug' => $taxonomy->name, 'taxonomy_label' => esc_attr($taxonomy->label));
             $taxonomy_list .= MLAData::mla_parse_template($page_template_array['mla-terms-search-taxonomy'], $page_values);
         }
         $page_values = array('Search Terms' => __('Search Terms', 'media-library-assistant'), 'Search' => __('Search', 'media-library-assistant'), 'phrases_and_checked' => 'checked="checked"', 'All phrases' => __('All phrases', 'media-library-assistant'), 'phrases_or_checked' => '', 'Any phrase' => __('Any phrase', 'media-library-assistant'), 'terms_and_checked' => '', 'All terms' => __('All terms', 'media-library-assistant'), 'terms_or_checked' => 'checked="checked"', 'Any term' => __('Any term', 'media-library-assistant'), 'exact_checked' => '', 'Exact' => __('Exact', 'media-library-assistant'), 'mla_terms_search_taxonomies' => $taxonomy_list);
         $terms_search_tpl = MLAData::mla_parse_template($page_template_array['mla-terms-search-div'], $page_values);
     }
     $page_values = array('mla_terms_search_url' => esc_url(add_query_arg(array_merge(MLA_List_Table::mla_submenu_arguments(false), array('page' => MLACore::ADMIN_PAGE_SLUG)), admin_url('upload.php'))), 'mla_terms_search_action' => MLA::MLA_ADMIN_TERMS_SEARCH, 'wpnonce' => wp_nonce_field(MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false), 'mla_terms_search_div' => $terms_search_tpl);
     $terms_search_tpl = MLAData::mla_parse_template($page_template_array['mla-terms-search-form'], $page_values);
     return $terms_search_tpl;
 }
 /**
  * This method dictates the table's columns and titles
  *
  * @since 0.1
  * 
  * @return	array	Column information: 'slugs'=>'Visible Titles'
  */
 function get_columns()
 {
     return $columns = MLA_List_Table::mla_manage_columns_filter();
 }
 /**
  * Adds support for taxonomy and custom field columns
  *
  * Called in the admin_init action because the list_table object isn't
  * created in time to affect the "screen options" setup.
  *
  * @since 0.30
  */
 public static function mla_admin_init_action()
 {
     $taxonomies = get_taxonomies(array('show_ui' => true), 'names');
     foreach ($taxonomies as $tax_name) {
         if (MLAOptions::mla_taxonomy_support($tax_name)) {
             $tax_object = get_taxonomy($tax_name);
             self::$default_columns['t_' . $tax_name] = esc_html($tax_object->labels->name);
             self::$default_hidden_columns[] = 't_' . $tax_name;
             // self::$default_sortable_columns [] = none at this time
         }
         // supported taxonomy
     }
     // foreach $tax_name
     self::$default_columns = array_merge(self::$default_columns, MLAOptions::mla_custom_field_support('default_columns'));
     self::$default_hidden_columns = array_merge(self::$default_hidden_columns, MLAOptions::mla_custom_field_support('default_hidden_columns'));
     self::$default_sortable_columns = array_merge(self::$default_sortable_columns, MLAOptions::mla_custom_field_support('default_sortable_columns'));
 }
Exemplo n.º 9
0
 /**
  * Ajax handler for inline editing (quick and bulk edit)
  *
  * Adapted from wp_ajax_inline_save in /wp-admin/includes/ajax-actions.php
  *
  * @since 0.20
  *
  * @return	void	echo HTML <tr> markup for updated row or error message, then die()
  */
 public static function mla_inline_edit_action()
 {
     set_current_screen($_REQUEST['screen']);
     check_ajax_referer(self::MLA_ADMIN_NONCE, 'nonce');
     if (empty($_REQUEST['post_ID'])) {
         echo 'Error: no post ID found';
         die;
     } else {
         $post_id = $_REQUEST['post_ID'];
     }
     if (!current_user_can('edit_post', $post_id)) {
         wp_die(__('You are not allowed to edit this Attachment.'));
     }
     /*
      * Custom field support
      */
     $custom_fields = array();
     foreach (MLAOptions::mla_custom_field_support('quick_edit') as $slug => $label) {
         if (isset($_REQUEST[$slug])) {
             $custom_fields[$label] = $_REQUEST[$slug];
             unset($_REQUEST[$slug]);
         }
     }
     if (!empty($custom_fields)) {
         $_REQUEST['custom_updates'] = $custom_fields;
     }
     /*
      * The category taxonomy 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']);
     }
     if (!empty($_REQUEST['tax_input'])) {
         /*
          * Flat taxonomy strings must be cleaned up and duplicates removed
          */
         $tax_output = array();
         $tax_input = $_REQUEST['tax_input'];
         foreach ($tax_input as $tax_name => $tax_value) {
             if (!is_array($tax_value)) {
                 $comma = _x(',', 'tag delimiter');
                 if (',' != $comma) {
                     $tax_value = str_replace($comma, ',', $tax_value);
                 }
                 $tax_value = preg_replace('#\\s*,\\s*#', ',', $tax_value);
                 $tax_value = preg_replace('#,+#', ',', $tax_value);
                 $tax_value = preg_replace('#[,\\s]+$#', '', $tax_value);
                 $tax_value = preg_replace('#^[,\\s]+#', '', $tax_value);
                 if (',' != $comma) {
                     $tax_value = str_replace(',', $comma, $tax_value);
                 }
                 $tax_array = array();
                 $dedup_array = explode($comma, $tax_value);
                 foreach ($dedup_array as $tax_value) {
                     $tax_array[$tax_value] = $tax_value;
                 }
                 $tax_value = implode($comma, $tax_array);
             }
             // ! array( $tax_value )
             $tax_output[$tax_name] = $tax_value;
         }
         // foreach $tax_input
     } else {
         $tax_output = NULL;
     }
     $results = MLAData::mla_update_single_item($post_id, $_REQUEST, $tax_output);
     $new_item = (object) MLAData::mla_get_attachment_by_id($post_id);
     //	Create an instance of our package class and echo the new HTML
     $MLAListTable = new MLA_List_Table();
     $MLAListTable->single_row($new_item);
     die;
     // this is required to return a proper result
 }
Exemplo n.º 10
0
 /**
  * Compose the General tab content for the Settings subpage
  *
  * @since 0.80
  * @uses $page_template_array contains tab content template(s)
  *
  * @return	array	'message' => status/error messages, 'body' => tab content
  */
 private static function _compose_general_tab()
 {
     /*
      * Check for submit buttons to change or reset settings.
      * Initialize page messages and content.
      */
     if (!empty($_REQUEST['mla-general-options-save'])) {
         check_admin_referer(MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME);
         $page_content = self::_save_general_settings();
     } elseif (!empty($_REQUEST['mla-general-options-export'])) {
         check_admin_referer(MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME);
         $page_content = self::_export_settings();
     } elseif (!empty($_REQUEST['mla-general-options-import'])) {
         check_admin_referer(MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME);
         $page_content = self::_import_settings();
     } elseif (!empty($_REQUEST['mla-general-options-reset'])) {
         check_admin_referer(MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME);
         $page_content = self::_reset_general_settings();
     } else {
         $page_content = array('message' => '', 'body' => '');
     }
     if (!empty($page_content['body'])) {
         return $page_content;
     }
     $page_values = array('General Processing Options' => __('General Processing Options', 'media-library-assistant'), 'In this tab' => sprintf(__('In this tab you can find a number of options for controlling the plugin&rsquo;s operation. Scroll down to find options for %1$s, %2$s, %3$s and %4$s. Be sure to click "Save Changes" at the bottom of the tab to save any changes you make.', 'media-library-assistant'), '<strong>' . __('Where-used Reporting', 'media-library-assistant') . '</strong>', '<strong>' . __('Taxonomy Support', 'media-library-assistant') . '</strong>', '<strong>' . __('Media/Assistant Table Defaults', 'media-library-assistant') . '</strong>', '<strong>' . __('Media Manager Enhancements', 'media-library-assistant') . '</strong>'), 'Save Changes' => __('Save Changes', 'media-library-assistant'), 'Export ALL Settings' => __('Export ALL Settings', 'media-library-assistant'), 'Delete General options' => __('Delete General options and restore default settings', 'media-library-assistant'), '_wpnonce' => wp_nonce_field(MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME, true, false), '_wp_http_referer' => wp_referer_field(false), 'Go to Top' => __('Go to Top', 'media-library-assistant'), 'Support Our Work' => __('Support Our Work', 'media-library-assistant'), 'Donate to FTJ' => __('Donate to FTJ', 'media-library-assistant'), 'Donate' => __('Donate', 'media-library-assistant'), 'This plugin was' => sprintf(__('This plugin was inspired by my work on the WordPress web site for our nonprofit, Fair Trade Judaica. If you find the Media Library Assistant plugin useful and would like to support a great cause, consider a %1$s to our work. Thank you!', 'media-library-assistant'), '<a href="http://fairtradejudaica.org/make-a-difference/donate/" title="' . __('Donate to FTJ', 'media-library-assistant') . '" target="_blank" style="font-weight:bold">' . __('tax-deductible donation', 'media-library-assistant') . '</a>'), 'shortcode_list' => '', 'form_url' => admin_url('options-general.php') . '?page=mla-settings-menu-general&mla_tab=general', 'options_list' => '', 'import_settings' => '');
     /*
      * $custom_fields documents the name and description of custom fields
      */
     $custom_fields = array();
     /* 
      * $shortcodes documents the name and description of plugin shortcodes
      */
     $shortcodes = array(array('name' => 'mla_gallery', 'description' => __('enhanced version of the WordPress [gallery] shortcode.', 'media-library-assistant') . sprintf(' %1$s <a href="%2$s">%3$s</a>.', __('For complete documentation', 'media-library-assistant'), admin_url('options-general.php?page=' . self::MLA_SETTINGS_SLUG . '-documentation&amp;mla_tab=documentation#mla_gallery'), __('click here', 'media-library-assistant'))), array('name' => 'mla_tag_cloud', 'description' => __('enhanced version of the WordPress Tag Cloud.', 'media-library-assistant') . sprintf(' %1$s <a href="%2$s">%3$s</a>.', __('For complete documentation', 'media-library-assistant'), admin_url('options-general.php?page=' . self::MLA_SETTINGS_SLUG . '-documentation&amp;mla_tab=documentation#mla_tag_cloud'), __('click here', 'media-library-assistant'))));
     $shortcode_list = '';
     foreach ($shortcodes as $shortcode) {
         $shortcode_values = array('name' => $shortcode['name'], 'description' => $shortcode['description']);
         $shortcode_list .= MLAData::mla_parse_template(self::$page_template_array['shortcode-item'], $shortcode_values);
     }
     if (!empty($shortcode_list)) {
         $shortcode_values = array('shortcode_list' => $shortcode_list, 'Shortcodes made available' => __('Shortcodes made available by this plugin', 'media-library-assistant'));
         $page_values['shortcode_list'] = MLAData::mla_parse_template(self::$page_template_array['shortcode-list'], $shortcode_values);
     }
     /*
      * Fill in the current list of Media/Assistant table sortable columns, sorted by their labels.
      * Make sure the current choice still exists or revert to default.
      */
     $columns = array();
     foreach (MLA_List_Table::mla_get_sortable_columns() as $key => $value) {
         if (!array_key_exists($value[1], $columns)) {
             $columns[$value[1]] = $value[0];
         }
     }
     uksort($columns, 'strnatcasecmp');
     $options = array_merge(array('None' => 'none'), $columns);
     $current = MLAOptions::mla_get_option(MLAOptions::MLA_DEFAULT_ORDERBY);
     MLAOptions::$mla_option_definitions[MLAOptions::MLA_DEFAULT_ORDERBY]['options'] = array();
     MLAOptions::$mla_option_definitions[MLAOptions::MLA_DEFAULT_ORDERBY]['texts'] = array();
     $found_current = false;
     foreach ($options as $key => $value) {
         MLAOptions::$mla_option_definitions[MLAOptions::MLA_DEFAULT_ORDERBY]['options'][] = $value;
         MLAOptions::$mla_option_definitions[MLAOptions::MLA_DEFAULT_ORDERBY]['texts'][] = $key;
         if ($current == $value) {
             $found_current = true;
         }
     }
     if (!$found_current) {
         MLAOptions::mla_delete_option(MLAOptions::MLA_DEFAULT_ORDERBY);
     }
     /*
      * Validate the Media Manager sort order or revert to default
      */
     $options = array_merge(array('&mdash; ' . __('Media Manager Default', 'media-library-assistant') . ' &mdash;' => 'default', 'None' => 'none'), $columns);
     $current = MLAOptions::mla_get_option(MLAOptions::MLA_MEDIA_MODAL_ORDERBY);
     MLAOptions::$mla_option_definitions[MLAOptions::MLA_MEDIA_MODAL_ORDERBY]['options'] = array();
     MLAOptions::$mla_option_definitions[MLAOptions::MLA_MEDIA_MODAL_ORDERBY]['texts'] = array();
     $found_current = false;
     foreach ($options as $key => $value) {
         MLAOptions::$mla_option_definitions[MLAOptions::MLA_MEDIA_MODAL_ORDERBY]['options'][] = $value;
         MLAOptions::$mla_option_definitions[MLAOptions::MLA_MEDIA_MODAL_ORDERBY]['texts'][] = $key;
         if ($current == $value) {
             $found_current = true;
         }
     }
     if (!$found_current) {
         MLAOptions::mla_delete_option(MLAOptions::MLA_MEDIA_MODAL_ORDERBY);
     }
     $options_list = '';
     foreach (MLAOptions::$mla_option_definitions as $key => $value) {
         if ('general' == $value['tab']) {
             $options_list .= self::mla_compose_option_row($key, $value);
         }
     }
     $page_values['options_list'] = $options_list;
     $page_values['import_settings'] = self::_compose_import_settings();
     $page_content['body'] = MLAData::mla_parse_template(self::$page_template_array['general-tab'], $page_values);
     return $page_content;
 }
Exemplo n.º 11
0
 /**
  * Sanitize and expand query arguments from request variables
  *
  * Prepare the arguments for WP_Query.
  * Modeled after wp_edit_attachments_query in wp-admin/post.php
  *
  * @since 0.1
  *
  * @param	array	query parameters from web page, usually found in $_REQUEST
  * @param	int		Optional number of rows (default 0) to skip over to reach desired page
  * @param	int		Optional number of rows on each page (0 = all rows, default)
  *
  * @return	array	revised arguments suitable for WP_Query
  */
 private static function _prepare_list_table_query($raw_request, $offset = 0, $count = 0)
 {
     /*
      * Go through the $raw_request, take only the arguments that are used in the query and
      * sanitize or validate them.
      */
     if (!is_array($raw_request)) {
         /* 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'), 'MLAData::_prepare_list_table_query', var_export($raw_request, true)), 0);
         return null;
     }
     /*
      * 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());
     $current_orderby = MLAOptions::mla_get_option(MLAOptions::MLA_DEFAULT_ORDERBY);
     $found_current = false;
     foreach ($default_orderby as $key => $value) {
         if ($current_orderby == $value[0]) {
             $found_current = true;
             break;
         }
     }
     if ($found_current) {
         /*
          * Custom fields can have HTML reserved characters, which are encoded by
          * mla_get_sortable_columns, so a separate, unencoded list is required.
          */
         $default_orderby = MLAOptions::mla_custom_field_support('custom_sortable_columns');
         foreach ($default_orderby as $sort_key => $sort_value) {
             if ($current_orderby == $sort_key) {
                 $current_orderby = 'c_' . $sort_value[0];
                 break;
             }
         }
         // foreach
     } else {
         MLAOptions::mla_delete_option(MLAOptions::MLA_DEFAULT_ORDERBY);
         $current_orderby = MLAOptions::mla_get_option(MLAOptions::MLA_DEFAULT_ORDERBY);
     }
     $clean_request = array('m' => 0, 'orderby' => $current_orderby, 'order' => MLAOptions::mla_get_option(MLAOptions::MLA_DEFAULT_ORDER), 'post_type' => 'attachment', 'post_status' => 'inherit', 'mla_search_connector' => 'AND', 'mla_search_fields' => array());
     foreach ($raw_request as $key => $value) {
         switch ($key) {
             /*
              * 'sentence' and 'exact' modify the keyword search ('s')
              * Their value is not important, only their presence.
              */
             case 'sentence':
             case 'exact':
             case 'mla-tax':
             case 'mla-term':
                 $clean_request[$key] = sanitize_key($value);
                 break;
             case 'orderby':
                 if (in_array($value, array('none', 'post__in'))) {
                     $clean_request[$key] = $value;
                 } else {
                     $orderby = NULL;
                     /*
                      * Custom fields can have HTML reserved characters, which are encoded by
                      * mla_get_sortable_columns, so a separate, unencoded list is required.
                      */
                     $sortable_columns = MLAOptions::mla_custom_field_support('custom_sortable_columns');
                     foreach ($sortable_columns as $sort_key => $sort_value) {
                         if ($value == $sort_key) {
                             $orderby = 'c_' . $sort_value[0];
                             break;
                         }
                     }
                     // foreach
                     if (NULL === $orderby) {
                         $sortable_columns = MLA_List_Table::mla_get_sortable_columns();
                         foreach ($sortable_columns as $sort_key => $sort_value) {
                             if ($value == $sort_value[0]) {
                                 $orderby = $value;
                                 break;
                             }
                         }
                         // foreach
                     }
                     if (NULL !== $orderby) {
                         $clean_request[$key] = $orderby;
                     }
                 }
                 break;
                 /*
                  * ids allows hooks to supply a persistent list of items
                  */
             /*
              * ids allows hooks to supply a persistent list of items
              */
             case 'ids':
                 if (is_array($value)) {
                     $clean_request['post__in'] = $value;
                 } else {
                     $clean_request['post__in'] = array_map('absint', explode(',', $value));
                 }
                 break;
                 /*
                  * post__in and post__not_in are used in the Media Modal Ajax queries
                  */
             /*
              * post__in and post__not_in are used in the Media Modal Ajax queries
              */
             case 'post__in':
             case 'post__not_in':
             case 'post_mime_type':
                 $clean_request[$key] = $value;
                 break;
             case 'parent':
             case 'post_parent':
                 $clean_request['post_parent'] = absint($value);
                 break;
                 /*
                  * ['m'] - filter by year and month of post, e.g., 201204
                  */
             /*
              * ['m'] - filter by year and month of post, e.g., 201204
              */
             case 'author':
             case 'm':
                 $clean_request[$key] = absint($value);
                 break;
                 /*
                  * ['mla_filter_term'] - filter by category or tag ID; -1 allowed
                  */
             /*
              * ['mla_filter_term'] - filter by category or tag ID; -1 allowed
              */
             case 'mla_filter_term':
                 $clean_request[$key] = intval($value);
                 break;
             case 'order':
                 switch ($value = strtoupper($value)) {
                     case 'ASC':
                     case 'DESC':
                         $clean_request[$key] = $value;
                         break;
                     default:
                         $clean_request[$key] = 'ASC';
                 }
                 break;
             case 'detached':
                 if ('0' == $value || '1' == $value) {
                     $clean_request['detached'] = $value;
                 }
                 break;
             case 'status':
                 if ('trash' == $value) {
                     $clean_request['post_status'] = 'trash';
                 }
                 break;
                 /*
                  * ['s'] - Search Media by one or more keywords
                  * ['mla_search_connector'], ['mla_search_fields'] - Search Media options
                  */
             /*
              * ['s'] - Search Media by one or more keywords
              * ['mla_search_connector'], ['mla_search_fields'] - Search Media options
              */
             case 's':
                 switch (substr($value, 0, 3)) {
                     case '>|<':
                         $clean_request['debug'] = 'console';
                         break;
                     case '<|>':
                         $clean_request['debug'] = 'log';
                         break;
                 }
                 if (isset($clean_request['debug'])) {
                     $value = substr($value, 3);
                 }
                 $value = stripslashes(trim($value));
                 if (!empty($value)) {
                     $clean_request[$key] = $value;
                 }
                 break;
             case 'mla_terms_search':
                 if (!empty($value['phrases']) && !empty($value['taxonomies'])) {
                     $value['phrases'] = stripslashes(trim($value['phrases']));
                     if (!empty($value['phrases'])) {
                         $clean_request[$key] = $value;
                     }
                 }
                 break;
             case 'mla_search_connector':
             case 'mla_search_fields':
                 $clean_request[$key] = $value;
                 break;
             case 'mla-metakey':
             case 'mla-metavalue':
                 $clean_request[$key] = stripslashes($value);
                 break;
             case 'meta_query':
                 if (!empty($value)) {
                     if (is_array($value)) {
                         $clean_request[$key] = $value;
                     } else {
                         $clean_request[$key] = unserialize(stripslashes($value));
                         unset($clean_request[$key]['slug']);
                     }
                     // not array
                 }
                 break;
             default:
                 // ignore anything else in $_REQUEST
         }
         // switch $key
     }
     // foreach $raw_request
     /*
      * Pass query and search parameters to the filters for _execute_list_table_query
      */
     self::$query_parameters = array('use_postmeta_view' => false, 'orderby' => $clean_request['orderby'], 'order' => $clean_request['order']);
     self::$query_parameters['detached'] = isset($clean_request['detached']) ? $clean_request['detached'] : NULL;
     self::$search_parameters = array('debug' => 'none');
     /*
      * Matching a meta_value to NULL requires a LEFT JOIN to a view and a special WHERE clause
      * Matching a wildcard pattern requires mainpulating the WHERE clause, too
      */
     if (isset($clean_request['meta_query']['key'])) {
         self::$query_parameters['use_postmeta_view'] = true;
         self::$query_parameters['postmeta_key'] = $clean_request['meta_query']['key'];
         self::$query_parameters['postmeta_value'] = NULL;
         unset($clean_request['meta_query']);
     } elseif (isset($clean_request['meta_query']['patterns'])) {
         self::$query_parameters['patterns'] = $clean_request['meta_query']['patterns'];
         unset($clean_request['meta_query']['patterns']);
     }
     if (isset($clean_request['debug'])) {
         self::$query_parameters['debug'] = $clean_request['debug'];
         self::$search_parameters['debug'] = $clean_request['debug'];
         MLA::mla_debug_mode($clean_request['debug']);
         unset($clean_request['debug']);
     }
     /*
      * We must patch the WHERE clause if there are leading spaces in the meta_value
      */
     if (isset($clean_request['mla-metavalue']) && 0 < strlen($clean_request['mla-metavalue']) && ' ' == $clean_request['mla-metavalue'][0]) {
         self::$query_parameters['mla-metavalue'] = $clean_request['mla-metavalue'];
     }
     /*
      * We will handle "Terms Search" in the mla_query_posts_search_filter.
      */
     if (isset($clean_request['mla_terms_search'])) {
         self::$search_parameters['mla_terms_search'] = $clean_request['mla_terms_search'];
         /*
          * The Terms Search overrides any terms-based keyword search for now; too complicated.
          */
         if (isset($clean_request['mla_search_fields'])) {
             foreach ($clean_request['mla_search_fields'] as $index => $field) {
                 if ('terms' == $field) {
                     unset($clean_request['mla_search_fields'][$index]);
                 }
             }
         }
     }
     /*
      * We will handle keyword search in the mla_query_posts_search_filter.
      */
     if (isset($clean_request['s'])) {
         self::$search_parameters['s'] = $clean_request['s'];
         self::$search_parameters['mla_search_fields'] = apply_filters('mla_list_table_search_filter_fields', $clean_request['mla_search_fields'], array('content', 'title', 'excerpt', 'alt-text', 'name', 'terms'));
         self::$search_parameters['mla_search_connector'] = $clean_request['mla_search_connector'];
         self::$search_parameters['sentence'] = isset($clean_request['sentence']);
         self::$search_parameters['exact'] = isset($clean_request['exact']);
         if (in_array('alt-text', self::$search_parameters['mla_search_fields'])) {
             self::$query_parameters['use_postmeta_view'] = true;
             self::$query_parameters['postmeta_key'] = '_wp_attachment_image_alt';
         }
         if (in_array('terms', self::$search_parameters['mla_search_fields'])) {
             self::$search_parameters['mla_search_taxonomies'] = MLAOptions::mla_supported_taxonomies('term-search');
         }
         unset($clean_request['s']);
         unset($clean_request['mla_search_connector']);
         unset($clean_request['mla_search_fields']);
         unset($clean_request['sentence']);
         unset($clean_request['exact']);
     }
     /*
      * We have to handle custom field/post_meta values here
      * because they need a JOIN clause supplied by WP_Query
      */
     if ('c_' == substr($clean_request['orderby'], 0, 2)) {
         $option_value = MLAOptions::mla_custom_field_option_value($clean_request['orderby']);
         if (isset($option_value['name'])) {
             self::$query_parameters['use_postmeta_view'] = true;
             self::$query_parameters['postmeta_key'] = $option_value['name'];
             if (isset($clean_request['orderby'])) {
                 unset($clean_request['orderby']);
             }
             if (isset($clean_request['order'])) {
                 unset($clean_request['order']);
             }
         }
     } else {
         // custom field
         switch (self::$query_parameters['orderby']) {
             /*
              * '_wp_attachment_image_alt' is special; we'll handle it in the JOIN and ORDERBY filters
              */
             case '_wp_attachment_image_alt':
                 self::$query_parameters['use_postmeta_view'] = true;
                 self::$query_parameters['postmeta_key'] = '_wp_attachment_image_alt';
                 if (isset($clean_request['orderby'])) {
                     unset($clean_request['orderby']);
                 }
                 if (isset($clean_request['order'])) {
                     unset($clean_request['order']);
                 }
                 break;
             case '_wp_attached_file':
                 $clean_request['meta_key'] = '_wp_attached_file';
                 $clean_request['orderby'] = 'meta_value';
                 $clean_request['order'] = self::$query_parameters['order'];
                 break;
         }
         // switch $orderby
     }
     /*
      * Ignore incoming paged value; use offset and count instead
      */
     if ((int) $count > 0) {
         $clean_request['offset'] = $offset;
         $clean_request['posts_per_page'] = $count;
     } elseif ((int) $count == -1) {
         $clean_request['posts_per_page'] = $count;
     }
     /*
      * ['mla_filter_term'] - filter by taxonomy
      *
      * cat =  0 is "All Categories", i.e., no filtering
      * cat = -1 is "No Categories"
      */
     if (isset($clean_request['mla_filter_term'])) {
         if ($clean_request['mla_filter_term'] != 0) {
             $tax_filter = MLAOptions::mla_taxonomy_support('', 'filter');
             if ($clean_request['mla_filter_term'] == -1) {
                 $term_list = get_terms($tax_filter, array('fields' => 'ids', 'hide_empty' => false));
                 $clean_request['tax_query'] = array(array('taxonomy' => $tax_filter, 'field' => 'id', 'terms' => $term_list, 'operator' => 'NOT IN'));
             } else {
                 // mla_filter_term == -1
                 $clean_request['tax_query'] = array(array('taxonomy' => $tax_filter, 'field' => 'id', 'terms' => array((int) $clean_request['mla_filter_term']), 'include_children' => 'checked' == MLAOptions::mla_get_option(MLAOptions::MLA_TAXONOMY_FILTER_INCLUDE_CHILDREN)));
             }
             // mla_filter_term != -1
         }
         // mla_filter_term != 0
         unset($clean_request['mla_filter_term']);
     }
     // isset mla_filter_term
     if (isset($clean_request['mla-tax']) && isset($clean_request['mla-term'])) {
         $clean_request['tax_query'] = array(array('taxonomy' => $clean_request['mla-tax'], 'field' => 'slug', 'terms' => $clean_request['mla-term'], 'include_children' => false));
         unset($clean_request['mla-tax']);
         unset($clean_request['mla-term']);
     }
     // isset mla_tax
     if (isset($clean_request['mla-metakey']) && isset($clean_request['mla-metavalue'])) {
         $clean_request['meta_key'] = $clean_request['mla-metakey'];
         $clean_request['meta_value'] = $clean_request['mla-metavalue'];
         unset($clean_request['mla-metakey']);
         unset($clean_request['mla-metavalue']);
     }
     // isset mla_tax
     return $clean_request;
 }
Exemplo n.º 12
0
 /**
  * Compose the General tab content for the Settings subpage
  *
  * @since 0.80
  * @uses $page_template_array contains tab content template(s)
  *
  * @return	array	'message' => status/error messages, 'body' => tab content
  */
 private static function _compose_general_tab()
 {
     /*
      * Check for submit buttons to change or reset settings.
      * Initialize page messages and content.
      */
     if (!empty($_REQUEST['mla-general-options-save'])) {
         check_admin_referer(MLA::MLA_ADMIN_NONCE, '_wpnonce');
         $page_content = self::_save_general_settings();
     } elseif (!empty($_REQUEST['mla-general-options-export'])) {
         check_admin_referer(MLA::MLA_ADMIN_NONCE, '_wpnonce');
         $page_content = self::_export_settings();
     } elseif (!empty($_REQUEST['mla-general-options-import'])) {
         check_admin_referer(MLA::MLA_ADMIN_NONCE, '_wpnonce');
         $page_content = self::_import_settings();
     } elseif (!empty($_REQUEST['mla-general-options-reset'])) {
         check_admin_referer(MLA::MLA_ADMIN_NONCE, '_wpnonce');
         $page_content = self::_reset_general_settings();
     } else {
         $page_content = array('message' => '', 'body' => '');
     }
     if (!empty($page_content['body'])) {
         return $page_content;
     }
     $page_values = array('shortcode_list' => '', 'options_list' => '', 'donateURL' => MLA_PLUGIN_URL . 'images/DonateButton.jpg', 'form_url' => admin_url('options-general.php') . '?page=mla-settings-menu-general&mla_tab=general', '_wpnonce' => wp_nonce_field(MLA::MLA_ADMIN_NONCE, '_wpnonce', true, false), '_wp_http_referer' => wp_referer_field(false));
     /*
      * $custom_fields documents the name and description of custom fields
      */
     $custom_fields = array();
     /* 
      * $shortcodes documents the name and description of plugin shortcodes
      */
     $shortcodes = array(array('name' => 'mla_attachment_list', 'description' => 'renders a complete list of all attachments and references to them.'), array('name' => 'mla_gallery', 'description' => 'enhanced version of the WordPress [gallery] shortcode. For complete documentation <a href="' . admin_url('options-general.php?page=' . self::MLA_SETTINGS_SLUG . '-documentation&amp;mla_tab=documentation') . '">click here</a>.'));
     $shortcode_list = '';
     foreach ($shortcodes as $shortcode) {
         $shortcode_values = array('name' => $shortcode['name'], 'description' => $shortcode['description']);
         $shortcode_list .= MLAData::mla_parse_template(self::$page_template_array['shortcode-item'], $shortcode_values);
     }
     if (!empty($shortcode_list)) {
         $shortcode_values = array('shortcode_list' => $shortcode_list);
         $page_values['shortcode_list'] = MLAData::mla_parse_template(self::$page_template_array['shortcode-list'], $shortcode_values);
     }
     /*
      * Fill in the current list of Media/Assistant table sortable columns, sorted by their labels.
      * Make sure the current choice still exists or revert to default.
      */
     $columns = array();
     foreach (MLA_List_Table::mla_get_sortable_columns() as $key => $value) {
         if (!array_key_exists($value[1], $columns)) {
             $columns[$value[1]] = $value[0];
         }
     }
     uksort($columns, 'strnatcasecmp');
     $options = array_merge(array('None' => 'none'), $columns);
     $current = MLAOptions::mla_get_option(MLAOptions::MLA_DEFAULT_ORDERBY);
     MLAOptions::$mla_option_definitions[MLAOptions::MLA_DEFAULT_ORDERBY]['options'] = array();
     MLAOptions::$mla_option_definitions[MLAOptions::MLA_DEFAULT_ORDERBY]['texts'] = array();
     $found_current = false;
     foreach ($options as $key => $value) {
         MLAOptions::$mla_option_definitions[MLAOptions::MLA_DEFAULT_ORDERBY]['options'][] = $value;
         MLAOptions::$mla_option_definitions[MLAOptions::MLA_DEFAULT_ORDERBY]['texts'][] = $key;
         if ($current == $value) {
             $found_current = true;
         }
     }
     if (!$found_current) {
         MLAOptions::mla_delete_option(MLAOptions::MLA_DEFAULT_ORDERBY);
     }
     /*
      * Validate the Media Manager sort order or revert to default
      */
     $options = array_merge(array(' -- Media Manager Default -- ' => 'default', 'None' => 'none'), $columns);
     $current = MLAOptions::mla_get_option(MLAOptions::MLA_MEDIA_MODAL_ORDERBY);
     MLAOptions::$mla_option_definitions[MLAOptions::MLA_MEDIA_MODAL_ORDERBY]['options'] = array();
     MLAOptions::$mla_option_definitions[MLAOptions::MLA_MEDIA_MODAL_ORDERBY]['texts'] = array();
     $found_current = false;
     foreach ($options as $key => $value) {
         MLAOptions::$mla_option_definitions[MLAOptions::MLA_MEDIA_MODAL_ORDERBY]['options'][] = $value;
         MLAOptions::$mla_option_definitions[MLAOptions::MLA_MEDIA_MODAL_ORDERBY]['texts'][] = $key;
         if ($current == $value) {
             $found_current = true;
         }
     }
     if (!$found_current) {
         MLAOptions::mla_delete_option(MLAOptions::MLA_MEDIA_MODAL_ORDERBY);
     }
     $options_list = '';
     foreach (MLAOptions::$mla_option_definitions as $key => $value) {
         if ('general' == $value['tab']) {
             $options_list .= self::_compose_option_row($key, $value);
         }
     }
     $page_values['options_list'] = $options_list;
     $page_values['import_settings'] = self::_compose_import_settings();
     $page_content['body'] = MLAData::mla_parse_template(self::$page_template_array['general-tab'], $page_values);
     return $page_content;
 }
 /**
  * Return terms in all languages when "Activate languages and translations for media"
  * is disabled
  *
  * @since 2.22
  *
  * @param	array	( 'class' => $class_array, 'value' => $value_array, 'text' => $text_array )
  */
 public static function mla_media_modal_terms_options($term_values)
 {
     global $polylang;
     static $in_process = false;
     // Avoid recursion loop
     if ($in_process) {
         return $term_values;
     }
     /*
      * Check Polylang Languages/Settings "Activate languages and translations for media" option
      */
     if (isset($polylang->options['media_support']) && !$polylang->options['media_support']) {
         $in_process = true;
         $dropdown_options = array('pll_get_terms_not_translated' => true);
         $term_values = MLAModal::mla_terms_options(MLA_List_Table::mla_get_taxonomy_filter_dropdown(0, $dropdown_options));
         $in_process = false;
     }
     /*
      * $class_array => HTML class attribute value for each option
      * $value_array => HTML value attribute value for each option
      * $text_array => HTML text content for each option
      */
     return $term_values;
 }
 /**
  * Ajax handler for Media Manager queries 
  *
  * Adapted from wp_ajax_query_attachments in /wp-admin/includes/ajax-actions.php
  *
  * @since 1.20
  *
  * @return	void	echo HTML <tr> markup for updated row or error message, then die()
  */
 public static function mla_query_attachments_action()
 {
     if (!current_user_can('upload_files')) {
         wp_send_json_error();
     }
     /*
      * Pick out and clean up the query terms we can process
      */
     $query = isset($_REQUEST['query']) ? (array) $_REQUEST['query'] : array();
     $query = array_intersect_key($query, array_flip(array('order', 'orderby', 'posts_per_page', 'paged', 'post_mime_type', 'post_parent', 'post__in', 'post__not_in', 'mla_filter_month', 'mla_filter_term', 'mla_search_value', 's', 'mla_search_fields', 'mla_search_connector')));
     if (isset($query['post_mime_type'])) {
         if ('detached' == $query['post_mime_type']) {
             $query['detached'] = '1';
             unset($query['post_mime_type']);
         } else {
             $view = $query['post_mime_type'];
             unset($query['post_mime_type']);
             $query = array_merge($query, MLAMime::mla_prepare_view_query('view', $view));
         }
     }
     /*
      * Convert mla_filter_month back to the WordPress "m" parameter
      */
     if (isset($query['mla_filter_month'])) {
         if ('0' != $query['mla_filter_month']) {
             $query['m'] = $query['mla_filter_month'];
         }
         unset($query['mla_filter_month']);
     }
     /*
      * Process the enhanced search box OR fix up the default search box
      */
     if (isset($query['mla_search_value'])) {
         if (!empty($query['mla_search_value'])) {
             $query['s'] = $query['mla_search_value'];
         }
         //			else
         //				unset( $query['s'] );
         unset($query['mla_search_value']);
     }
     /*		elseif ( ! empty( $query['s'] ) ) {
     			$query['mla_search_fields'] = array( 'title', 'content' );
     			$query['mla_search_connector'] = 'AND';
     		} // */
     if (isset($query['posts_per_page'])) {
         $count = $query['posts_per_page'];
         $offset = $count * (isset($query['paged']) ? $query['paged'] - 1 : 0);
     } else {
         $count = 0;
         $offset = 0;
     }
     /*
      * Check for sorting override
      */
     $option = MLAOptions::mla_get_option(MLAOptions::MLA_MEDIA_MODAL_ORDERBY);
     if ('default' != $option) {
         /*
          * Make sure the current orderby choice still exists or revert to default.
          */
         $default_orderby = array_merge(array('none' => array('none', false)), MLA_List_Table::mla_get_sortable_columns());
         $found_current = false;
         foreach ($default_orderby as $key => $value) {
             if ($option == $value[0]) {
                 $found_current = true;
                 break;
             }
         }
         if (!$found_current) {
             MLAOptions::mla_delete_option(MLAOptions::MLA_DEFAULT_ORDERBY);
             $option = MLAOptions::mla_get_option(MLAOptions::MLA_DEFAULT_ORDERBY);
         }
         $query['orderby'] = $option;
     }
     $option = MLAOptions::mla_get_option(MLAOptions::MLA_MEDIA_MODAL_ORDER);
     if ('default' != $option) {
         $query['order'] = $option;
     }
     $query['post_type'] = 'attachment';
     $query['post_status'] = 'inherit';
     if (current_user_can(get_post_type_object('attachment')->cap->read_private_posts)) {
         $query['post_status'] .= ',private';
     }
     $query = MLAData::mla_query_media_modal_items($query, $offset, $count);
     $posts = array_map('wp_prepare_attachment_for_js', $query->posts);
     $posts = array_filter($posts);
     wp_send_json_success($posts);
 }