Ejemplo 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
      */
     MLACore::$original_php_log = ini_get('error_log');
     MLACore::$original_php_reporting = sprintf('0x%1$04X', error_reporting());
     $php_reporting = trim(MLACore::mla_get_option(MLACoreOptions::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
      */
     MLACoreOptions::mla_localize_option_definitions_array();
     if (class_exists('MLASettings')) {
         MLASettings::mla_localize_tablist();
     }
     if (class_exists('MLAQuery')) {
         MLAQuery::mla_localize_default_columns_array();
     }
     if (class_exists('MLA_Upload_List_Table')) {
         MLA_Upload_List_Table::mla_localize_default_columns_array();
     }
     if (class_exists('MLA_Upload_Optional_List_Table')) {
         MLA_Upload_Optional_List_Table::mla_localize_default_columns_array();
     }
     if (class_exists('MLA_View_List_Table')) {
         MLA_View_List_Table::mla_localize_default_columns_array();
     }
 }
Ejemplo n.º 2
0
 /**
  * Assemble the in-memory representation of the Upload MIME Types 
  *
  * @since 1.40
  *
  * @param	boolean	Force a reload/recalculation of types
  * @return	boolean	Success (true) or failure (false) of the operation
  */
 private static function _get_upload_mime_templates($force_refresh = false)
 {
     self::_get_core_icon_types();
     self::_get_current_icon_types();
     if (false == $force_refresh && NULL != self::$mla_upload_mime_templates) {
         return true;
     }
     /*
      * Find the WordPress-standard (unfiltered) extensions
      */
     global $wp_filter;
     if (isset($wp_filter['mime_types'])) {
         $save_filters = $wp_filter['mime_types'];
         unset($wp_filter['mime_types']);
         $core_types = wp_get_mime_types();
         $wp_filter['mime_types'] = $save_filters;
     } else {
         $core_types = wp_get_mime_types();
     }
     /*
      * If this is the first time MLA Upload support is invoked, match to the 
      * filter-enhanced extensions, retain anything new as a custom type.
      */
     $custom_types = array();
     $mla_upload_mimes = MLACore::mla_get_option(MLACore::MLA_UPLOAD_MIMES);
     if (is_array($mla_upload_mimes)) {
         $first_time_called = false;
         $custom_types = $mla_upload_mimes['custom'];
     } else {
         $first_time_called = true;
         $mla_upload_mimes = array('custom' => array(), 'disabled' => array(), 'description' => array(), 'icon_type' => array());
         self::$disable_mla_filtering = true;
         foreach (get_allowed_mime_types() as $key => $value) {
             if (!isset($core_types[$key])) {
                 $custom_types[$key] = $value;
             }
         }
         self::$disable_mla_filtering = false;
     }
     /*
      * Explode any entries with multiple extensions
      */
     foreach ($core_types as $key => $value) {
         if (false !== strpos($key, '|')) {
             unset($core_types[$key]);
             $extensions = explode('|', $key);
             foreach ($extensions as $extension) {
                 $core_types[$extension] = $value;
             }
         }
     }
     foreach ($custom_types as $key => $value) {
         if (false !== strpos($key, '|')) {
             unset($custom_types[$key]);
             $extensions = explode('|', $key);
             foreach ($extensions as $extension) {
                 $custom_types[$extension] = $value;
             }
         }
     }
     self::$mla_upload_mime_templates = array();
     self::$mla_upload_mime_highest_ID = 0;
     /*
      * Start with the MLA extensions, initialized to an inactive state
      * Save the descriptions for use in _put_upload_mime_types()
      */
     self::$mla_upload_mime_descriptions = array();
     $template_array = MLAData::mla_load_template('mla-default-mime-types.tpl');
     if (isset($template_array['mla-mime-types'])) {
         $mla_mime_types = preg_split('/[\\r\\n]+/', $template_array['mla-mime-types']);
         foreach ($mla_mime_types as $mla_type) {
             $array = explode(',', $mla_type);
             /* Anthony Martin debug * /
             			if ( 4 > count( $array ) ) {
             				trigger_error( sprintf( 'mla-default-mime-types.tpl $array = "%1$s".', var_export( $array, true ) ), E_USER_WARNING );
             			} // */
             $key = strtolower($array[0]);
             self::$mla_upload_mime_descriptions[$key] = $array[4];
             self::$mla_upload_mime_templates[$key] = array('post_ID' => ++self::$mla_upload_mime_highest_ID, 'mime_type' => $array[1], 'core_type' => '', 'mla_type' => $array[1], 'source' => 'mla', 'standard_source' => 'mla', 'disabled' => true, 'description' => $array[4], 'icon_type' => $array[2], 'wp_icon_type' => $array[2], 'mla_icon_type' => $array[3], 'core_icon_type' => self::mla_get_core_icon_type($array[0]));
             if ('checked' == MLACore::mla_get_option(MLACore::MLA_ENABLE_MLA_ICONS)) {
                 self::$mla_upload_mime_templates[$key]['icon_type'] = self::$mla_upload_mime_templates[$key]['mla_icon_type'];
             }
         }
     }
     /*
      * Add the WordPress-standard (unfiltered) extensions, initialized to an active state
      */
     foreach ($core_types as $key => $value) {
         $key = strtolower($key);
         if (isset(self::$mla_upload_mime_templates[$key])) {
             $post_ID = self::$mla_upload_mime_templates[$key]['post_ID'];
             $mla_type = self::$mla_upload_mime_templates[$key]['mla_type'];
             $description = self::$mla_upload_mime_templates[$key]['description'];
             $icon_type = self::$mla_upload_mime_templates[$key]['icon_type'];
             $wp_icon_type = self::$mla_upload_mime_templates[$key]['wp_icon_type'];
             $mla_icon_type = self::$mla_upload_mime_templates[$key]['mla_icon_type'];
             $core_icon_type = self::$mla_upload_mime_templates[$key]['core_icon_type'];
         } else {
             $post_ID = ++self::$mla_upload_mime_highest_ID;
             $mla_type = '';
             $description = '';
             //				if ( NULL == $icon_type = wp_ext2type( $key ) ) {
             //					$icon_type = 'default';
             //				}
             $icon_type = self::mla_get_core_icon_type($key);
             $wp_icon_type = $icon_type;
             $mla_icon_type = $icon_type;
             $core_icon_type = $icon_type;
             //self::mla_get_core_icon_type( $key );
         }
         self::$mla_upload_mime_templates[$key] = array('post_ID' => $post_ID, 'mime_type' => $value, 'core_type' => $value, 'mla_type' => $mla_type, 'source' => 'core', 'standard_source' => 'core', 'disabled' => false, 'description' => $description, 'icon_type' => $icon_type, 'wp_icon_type' => $wp_icon_type, 'mla_icon_type' => $mla_icon_type, 'core_icon_type' => $core_icon_type);
         if ('checked' == MLACore::mla_get_option(MLACore::MLA_ENABLE_MLA_ICONS)) {
             self::$mla_upload_mime_templates[$key]['icon_type'] = self::$mla_upload_mime_templates[$key]['mla_icon_type'];
         }
     }
     /*
      * Add the user-defined custom types
      */
     foreach ($custom_types as $key => $value) {
         $key = strtolower($key);
         if (isset(self::$mla_upload_mime_templates[$key])) {
             extract(self::$mla_upload_mime_templates[$key]);
             /*
              * Make sure it's really custom
              */
             if ('core' == $source && $value == $core_type || 'mla' == $source && $value == $mla_type) {
                 continue;
             }
         } else {
             // existing type
             $core_type = '';
             $mla_type = '';
             $standard_source = '';
         }
         // brand new type
         if (NULL == ($icon_type = wp_ext2type($key))) {
             $icon_type = 'default';
         }
         self::$mla_upload_mime_templates[$key] = array('post_ID' => ++self::$mla_upload_mime_highest_ID, 'mime_type' => $value, 'core_type' => $core_type, 'mla_type' => $mla_type, 'source' => 'custom', 'standard_source' => $standard_source, 'disabled' => false, 'description' => '', 'icon_type' => $icon_type, 'wp_icon_type' => $icon_type, 'mla_icon_type' => $icon_type, 'core_icon_type' => self::mla_get_core_icon_type($key));
     }
     if ($first_time_called) {
         self::_put_upload_mime_templates();
         return true;
     }
     /*
      * Apply the current settings, if any
      */
     foreach (self::$mla_upload_mime_templates as $key => $value) {
         $default_description = isset(self::$mla_upload_mime_descriptions[$key]) ? self::$mla_upload_mime_descriptions[$key] : '';
         self::$mla_upload_mime_templates[$key]['disabled'] = isset($mla_upload_mimes['disabled'][$key]);
         self::$mla_upload_mime_templates[$key]['description'] = isset($mla_upload_mimes['description'][$key]) ? $mla_upload_mimes['description'][$key] : $default_description;
         if (isset($mla_upload_mimes['icon_type'][$key])) {
             self::$mla_upload_mime_templates[$key]['icon_type'] = $mla_upload_mimes['icon_type'][$key];
         }
     }
     return true;
 }
Ejemplo 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)) {
         /* 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'), 'MLAQuery::_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)), self::mla_get_sortable_columns());
     $current_orderby = MLACore::mla_get_option(MLACore::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 = MLACore::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 {
         MLACore::mla_delete_option(MLACore::MLA_DEFAULT_ORDERBY);
         $current_orderby = MLACore::mla_get_option(MLACore::MLA_DEFAULT_ORDERBY);
     }
     $clean_request = array('m' => 0, 'orderby' => $current_orderby, 'order' => MLACore::mla_get_option(MLACore::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 = MLACore::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 = MLAQuery::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_alt_text_view' => false, 'use_postmeta_view' => false, 'use_orderby_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'];
         MLACore::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_alt_text_view'] = true;
         }
         if (in_array('terms', self::$search_parameters['mla_search_fields'])) {
             self::$search_parameters['mla_search_taxonomies'] = MLACore::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 = MLAQuery::mla_custom_field_option_value($clean_request['orderby']);
         if (isset($option_value['name'])) {
             self::$query_parameters['use_orderby_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; it can have NULL values,
              * so we'll handle it in the JOIN and ORDERBY filters
              */
             case '_wp_attachment_image_alt':
                 self::$query_parameters['use_orderby_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 = MLACore::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' == MLACore::mla_get_option(MLACore::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;
 }
 /**
  * Filter the list of item "Rollover" actions
  *
  * Adds "Quick Translate" to the list of item-level "Rollover" actions.
  *
  * @since 2.11
  *
  * @param	array	$actions	The list of item "Rollover" actions.
  * @param	object	$item		The current Media Library item.
  * @param	string	$column		The List Table column slug.
  *
  * @return	array	updated		"Rollover" actions.
  */
 public static function mla_list_table_build_rollover_actions($actions, $item, $column)
 {
     if ('checked' == MLACore::mla_get_option('quick_translate', false, false, MLA_Polylang::$mla_language_option_definitions)) {
         /*
          * Add the Quick Translate action
          */
         $actions['translate hide-if-no-js'] = '<a class="inlineTranslate" href="#" title="' . __('Translate this item inline', 'media-library-assistant') . '">' . __('Quick Translate', 'media-library-assistant') . '</a>';
     }
     return $actions;
 }
    /**
     * Generate the table navigation above or below the table
     *
     * Adds the list/grid switcher in WP 4.0+
     *
     * @since 2.25
     *
     * @param	string	'top' or 'bottom', i.e., above or below the table rows
     */
    function display_tablenav($which)
    {
        if ('top' === $which) {
            wp_nonce_field('bulk-' . $this->_args['plural']);
        }
        ?>

	<div class="tablenav <?php 
        echo esc_attr($which);
        ?>
">
		<?php 
        if ('top' === $which && MLAQuery::$wp_4dot0_plus && 'checked' == MLACore::mla_get_option(MLACoreOptions::MLA_SCREEN_DISPLAY_SWITCHER)) {
            ?>
		<div class="view-switch media-grid-view-switch" style="float: left"> <a class="view-list current" href="<?php 
            echo admin_url('upload.php?page=' . MLACore::ADMIN_PAGE_SLUG);
            ?>
"> <span class="screen-reader-text">List View</span> </a> <a class="view-grid" href="<?php 
            echo admin_url('upload.php?mode=grid');
            ?>
"> <span class="screen-reader-text">Grid View</span> </a> </div>
		<?php 
        }
        ?>

		<?php 
        if ($this->has_items()) {
            ?>
		<div class="alignleft actions bulkactions">
			<?php 
            $this->bulk_actions($which);
            ?>
		</div>
		<?php 
        }
        $this->extra_tablenav($which);
        $this->pagination($which);
        ?>

		<br class="clear" />
	</div>
<?php 
    }
 /**
  * Filter the MLA_List_Table columns
  *
  * Inserts the language columns just after the item thumbnail column.
  * Defined as static because it is called before the List_Table object is created.
  * Added as a filter when the file is loaded.
  *
  * @since 2.11
  *
  * @param	array	$columns An array of columns.
  *					format: column_slug => Column Label
  *
  * @return	array	updated array of columns.
  */
 public static function mla_list_table_get_columns($columns)
 {
     global $sitepress, $wpdb;
     if (is_null(self::$language_columns) && $sitepress->is_translated_post_type('attachment')) {
         /*
          * Build language management columns
          */
         $show_language = 'checked' == MLACore::mla_get_option('language_column', false, false, MLA_WPML::$mla_language_option_definitions);
         $current_language = $sitepress->get_current_language();
         $languages = $sitepress->get_active_languages();
         $view_status = isset($_REQUEST['status']) ? $_REQUEST['status'] : '';
         if (1 < count($languages) && $view_status != 'trash') {
             $show_translations = 'checked' == MLACore::mla_get_option('translations_column', false, false, MLA_WPML::$mla_language_option_definitions);
         } else {
             $show_translations = false;
         }
         self::$language_columns = array();
         if ($show_language && 'all' == $current_language) {
             self::$language_columns['language'] = __('Language', 'wpml-media');
         }
         if ($show_translations) {
             $language_codes = array();
             foreach ($languages as $language) {
                 if ($current_language != $language['code']) {
                     $language_codes[] = $language['code'];
                 }
             }
             $results = $wpdb->get_results($wpdb->prepare("\n\t\t\t\t\tSELECT f.lang_code, f.flag, f.from_template, l.name\n\t\t\t\t\tFROM {$wpdb->prefix}icl_flags f\n\t\t\t\t\t\tJOIN {$wpdb->prefix}icl_languages_translations l ON f.lang_code = l.language_code\n\t\t\t\t\tWHERE l.display_language_code = %s AND f.lang_code IN(" . wpml_prepare_in($language_codes) . ")", $sitepress->get_admin_language()));
             $wp_upload_dir = wp_upload_dir();
             foreach ($results as $result) {
                 if ($result->from_template) {
                     $flag_path = $wp_upload_dir['baseurl'] . '/flags/';
                 } else {
                     $flag_path = ICL_PLUGIN_URL . '/res/flags/';
                 }
                 $flags[$result->lang_code] = '<img src="' . $flag_path . $result->flag . '" width="18" height="12" alt="' . $result->name . '" title="' . $result->name . '" />';
             }
             $flags_column = '';
             foreach ($languages as $language) {
                 if (isset($flags[$language['code']])) {
                     $flags_column .= $flags[$language['code']];
                 }
             }
             self::$language_columns['icl_translations'] = $flags_column;
         }
         // multi-language not trash
     }
     // add columns
     if (!empty(self::$language_columns)) {
         $end = array_slice($columns, 2);
         $columns = array_slice($columns, 0, 2);
         $columns = array_merge($columns, self::$language_columns, $end);
     }
     return $columns;
 }
Ejemplo n.º 7
0
 /**
  * Evaluate support information for custom field mapping
  *
  * @since 1.10
  *
  * @param	string	array format; 'default_columns' (default), 'default_hidden_columns', 'default_sortable_columns', 'quick_edit' or 'bulk_edit'
  *
  * @return	array	default, hidden, sortable quick_edit or bulk_edit colums in appropriate format
  */
 public static function mla_custom_field_support($support_type = 'default_columns')
 {
     $option_values = MLACore::mla_get_option('custom_field_mapping');
     $results = array();
     $index = 0;
     foreach ($option_values as $key => $value) {
         $slug = 'c_' . $index++;
         // sanitize_title( $key ); Didn't handle HTML in name, e.g., "R><B"
         switch ($support_type) {
             case 'custom_columns':
                 if ($value['mla_column']) {
                     $results[$slug] = $value['name'];
                 }
                 break;
             case 'default_columns':
                 if ($value['mla_column']) {
                     $results[$slug] = esc_html($value['name']);
                 }
                 break;
             case 'default_hidden_columns':
                 if ($value['mla_column']) {
                     $results[] = $slug;
                 }
                 break;
             case 'custom_sortable_columns':
                 if ($value['mla_column']) {
                     // columns without NULL values should sort descending
                     $results[$slug] = array($value['name'], $value['no_null']);
                 }
                 break;
             case 'default_sortable_columns':
                 if ($value['mla_column']) {
                     // columns without NULL values should sort descending
                     $results[$slug] = array($slug, $value['no_null']);
                 }
                 break;
             case 'quick_edit':
                 if ($value['quick_edit']) {
                     $results[$slug] = $value;
                 }
                 break;
             case 'bulk_edit':
                 if ($value['bulk_edit']) {
                     $results[$slug] = $value;
                 }
                 break;
         }
         // switch support_type
     }
     // foreach option_value
     return $results;
 }
 * Harmless declaration to suppress phpDocumentor "No page-level DocBlock" error
 *
 * @global $post
 */
global $post;
if (!empty($_REQUEST['s'])) {
    $search_value = esc_attr(stripslashes(trim($_REQUEST['s'])));
    $search_fields = isset($_REQUEST['mla_search_fields']) ? $_REQUEST['mla_search_fields'] : array();
    $search_connector = $_REQUEST['mla_search_connector'];
} else {
    $search_value = MLACore::mla_get_option(MLACoreOptions::MLA_SEARCH_MEDIA_FILTER_DEFAULTS);
    $search_fields = $search_value['search_fields'];
    $search_connector = $search_value['search_connector'];
    $search_value = '';
}
if ('checked' == MLACore::mla_get_option(MLACoreOptions::MLA_SEARCH_MEDIA_FILTER_SHOW_CONTROLS)) {
    $controls_style = 'style="display: inline;"';
} else {
    $controls_style = 'style="display: none;"';
}
$supported_taxonomies = MLACore::mla_supported_taxonomies('support');
if (empty($supported_taxonomies)) {
    $terms_style = 'style="display: none;"';
    unset($search_fields['terms']);
} else {
    $terms_style = 'style="display: inline;"';
}
?>
<p class="search-box">
<label class="screen-reader-text" for="mla-media-search-input"><?php 
_e('Search Media', 'media-library-assistant');
Ejemplo n.º 9
0
 /**
  * Add rollover actions to a table column
  *
  * @since 1.40
  * 
  * @param	object	An MLA post_mime_type object
  * @param	string	Current column name
  *
  * @return	array	Names and URLs of row-level actions
  */
 private function _build_rollover_actions($item, $column)
 {
     $actions = array();
     /*
      * Compose view arguments
      */
     $view_args = array('page' => MLACore::MLA_SETTINGS_SLUG . '-view', 'mla_tab' => 'view', 'mla_item_slug' => urlencode($item->slug));
     if (isset($_REQUEST['paged'])) {
         $view_args['paged'] = $_REQUEST['paged'];
     }
     if (isset($_REQUEST['order'])) {
         $view_args['order'] = $_REQUEST['order'];
     }
     if (isset($_REQUEST['orderby'])) {
         $view_args['orderby'] = $_REQUEST['orderby'];
     }
     /*
      * Get the standard and custom types
      */
     $mla_types = MLACore::mla_get_option(MLACore::MLA_POST_MIME_TYPES, true);
     if (!is_array($mla_types)) {
         $mla_types = array();
     }
     $custom_types = MLACore::mla_get_option(MLACore::MLA_POST_MIME_TYPES, false, true);
     if (!is_array($custom_types)) {
         $custom_types = array();
     }
     $actions['edit'] = '<a href="' . add_query_arg($view_args, wp_nonce_url('?mla_admin_action=' . MLA::MLA_ADMIN_SINGLE_EDIT_DISPLAY, MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME)) . '" title="' . __('Edit this item', 'media-library-assistant') . '">' . __('Edit', 'media-library-assistant') . '</a>';
     $actions['inline hide-if-no-js'] = '<a class="editinline" href="#" title="' . __('Edit this item inline', 'media-library-assistant') . '">' . __('Quick Edit', 'media-library-assistant') . '</a>';
     if (isset($custom_types[$item->slug])) {
         if (isset($mla_types[$item->slug])) {
             $actions['delete'] = '<a class="delete-tag"' . ' href="' . add_query_arg($view_args, wp_nonce_url('?mla_admin_action=' . MLACore::MLA_ADMIN_SINGLE_DELETE, MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME)) . '" title="' . __('Revert to standard item', 'media-library-assistant') . '">' . __('Revert to Standard', 'media-library-assistant') . '</a>';
         } else {
             $actions['delete'] = '<a class="delete-tag"' . ' href="' . add_query_arg($view_args, wp_nonce_url('?mla_admin_action=' . MLACore::MLA_ADMIN_SINGLE_DELETE, MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME)) . '" title="' . __('Delete this item Permanently', 'media-library-assistant') . '">' . __('Delete Permanently', 'media-library-assistant') . '</a>';
         }
     }
     // custom type
     return $actions;
 }
Ejemplo n.º 10
0
 /**
  * Render the "Assistant" subpage in the Media section, using the list_table package
  *
  * @since 0.1
  *
  * @return	void
  */
 public static function mla_render_admin_page()
 {
     /*
      * WordPress class-wp-list-table.php doesn't look in hidden fields to set
      * the month filter dropdown or sorting parameters
      */
     if (isset($_REQUEST['m'])) {
         $_GET['m'] = $_REQUEST['m'];
     }
     if (isset($_REQUEST['order'])) {
         $_GET['order'] = $_REQUEST['order'];
     }
     if (isset($_REQUEST['orderby'])) {
         $_GET['orderby'] = $_REQUEST['orderby'];
     }
     // bulk_refresh simply refreshes the page, ignoring other bulk actions
     if (!empty($_REQUEST['bulk_refresh'])) {
         unset($_REQUEST['action']);
         unset($_POST['action']);
         unset($_REQUEST['action2']);
         unset($_POST['action2']);
     }
     $bulk_action = self::_current_bulk_action();
     $page_title = MLACore::mla_get_option(MLACore::MLA_SCREEN_PAGE_TITLE);
     if (empty($page_title)) {
         $page_title = MLACore::mla_get_option(MLACore::MLA_SCREEN_PAGE_TITLE, true);
     }
     echo "<div class=\"wrap\">\n";
     echo "<div id=\"icon-upload\" class=\"icon32\"><br/></div>\n";
     echo "<h2>{$page_title}";
     // trailing </h2> is action-specific
     if (!current_user_can('upload_files')) {
         echo ' - ' . __('ERROR', 'media-library-assistant') . "</h2>\n";
         wp_die(__('You do not have permission to manage attachments.', 'media-library-assistant'));
     }
     $page_content = array('message' => '', 'body' => '');
     if (!empty($_REQUEST['mla_admin_message'])) {
         $page_content['message'] = $_REQUEST['mla_admin_message'];
     }
     /*
      * The category taxonomy (edit screens) is a special case because 
      * post_categories_meta_box() changes the input name
      */
     if (!isset($_REQUEST['tax_input'])) {
         $_REQUEST['tax_input'] = array();
     }
     if (isset($_REQUEST['post_category'])) {
         $_REQUEST['tax_input']['category'] = $_REQUEST['post_category'];
         unset($_REQUEST['post_category']);
     }
     /*
      * Process bulk actions that affect an array of items
      */
     if ($bulk_action && $bulk_action != 'none') {
         // bulk_refresh simply refreshes the page, ignoring other bulk actions
         if (empty($_REQUEST['bulk_refresh'])) {
             $item_content = self::mla_process_bulk_action($bulk_action);
             $page_content['message'] .= $item_content['message'] . '<br>';
         }
     }
     // $bulk_action
     if (isset($_REQUEST['clear_filter_by'])) {
         self::mla_clear_filter_by();
     }
     /*
      * Empty the Trash?
      */
     if (isset($_REQUEST['delete_all'])) {
         global $wpdb;
         $ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type=%s AND post_status = %s", 'attachment', 'trash'));
         $delete_count = 0;
         foreach ($ids as $post_id) {
             $item_content = self::_delete_single_item($post_id);
             if (false !== strpos($item_content['message'], __('ERROR', 'media-library-assistant'))) {
                 $page_content['message'] .= $item_content['message'] . '<br>';
             } else {
                 $delete_count++;
             }
         }
         if ($delete_count) {
             /* translators: 1: number of items */
             $page_content['message'] .= sprintf(_nx('%s item deleted.', '%s items deleted.', $delete_count, 'deleted items', 'media-library-assistant'), number_format_i18n($delete_count));
         } else {
             $page_content['message'] .= __('No items deleted.', 'media-library-assistant');
         }
     }
     /*
      * Process row-level actions that affect a single item
      */
     if (!empty($_REQUEST['mla_admin_action'])) {
         check_admin_referer(MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME);
         $page_content = apply_filters('mla_list_table_single_action', NULL, $_REQUEST['mla_admin_action'], isset($_REQUEST['mla_item_ID']) ? $_REQUEST['mla_item_ID'] : 0);
         if (is_null($page_content)) {
             $prevent_default = false;
             $custom_message = '';
         } else {
             $prevent_default = isset($page_content['prevent_default']) ? $page_content['prevent_default'] : false;
             $custom_message = isset($page_content['message']) ? $page_content['message'] : '';
         }
         if (!$prevent_default) {
             switch ($_REQUEST['mla_admin_action']) {
                 case MLACore::MLA_ADMIN_SINGLE_DELETE:
                     $page_content = self::_delete_single_item($_REQUEST['mla_item_ID']);
                     break;
                 case MLACore::MLA_ADMIN_SINGLE_RESTORE:
                     $page_content = self::_restore_single_item($_REQUEST['mla_item_ID']);
                     break;
                 case MLACore::MLA_ADMIN_SINGLE_TRASH:
                     $page_content = self::_trash_single_item($_REQUEST['mla_item_ID']);
                     break;
                 case self::MLA_ADMIN_SET_PARENT:
                     $new_data = array('post_parent' => $_REQUEST['found_post_id']);
                     foreach ($_REQUEST['children'] as $child) {
                         $item_content = MLAData::mla_update_single_item($child, $new_data);
                         $page_content['message'] .= $item_content['message'] . '<br>';
                     }
                     unset($_REQUEST['parent']);
                     unset($_REQUEST['children']);
                     unset($_REQUEST['mla-set-parent-ajax-nonce']);
                     unset($_REQUEST['mla_set_parent_search_text']);
                     unset($_REQUEST['found_post_id']);
                     unset($_REQUEST['mla-set-parent-submit']);
                     break;
                 case self::MLA_ADMIN_TERMS_SEARCH:
                     /*
                      * This will be handled as a database query argument,
                      * but validate the arguments here
                      */
                     $mla_terms_search = isset($_REQUEST['mla_terms_search']) ? $_REQUEST['mla_terms_search'] : array('phrases' => '', 'taxonomies' => array());
                     if (!is_array($mla_terms_search) || empty($mla_terms_search['phrases']) || empty($mla_terms_search['taxonomies'])) {
                         unset($_REQUEST['mla_terms_search']);
                         $page_content = array('message' => __('Empty Terms Search; ignored', 'media-library-assistant'), 'body' => '');
                     } else {
                         unset($_REQUEST['mla_terms_search']['submit']);
                     }
                     break;
                 default:
                     $page_content = apply_filters('mla_list_table_custom_single_action', NULL, $_REQUEST['mla_admin_action'], isset($_REQUEST['mla_item_ID']) ? $_REQUEST['mla_item_ID'] : 0);
                     if (is_null($page_content)) {
                         $page_content = array('message' => sprintf(__('Unknown mla_admin_action - "%1$s"', 'media-library-assistant'), $_REQUEST['mla_admin_action']), 'body' => '');
                     }
                     // Unknown mla_admin_action
             }
             // switch ($_REQUEST['mla_admin_action'])
         }
         // ! $prevent_default
         if (!empty($custom_message)) {
             $page_content['message'] = $custom_message . $page_content['message'];
         }
     }
     // (!empty($_REQUEST['mla_admin_action'])
     if (!empty($page_content['body'])) {
         if (!empty($page_content['message'])) {
             if (false !== strpos($page_content['message'], __('ERROR', 'media-library-assistant'))) {
                 $messages_class = 'mla_errors';
             } else {
                 $messages_class = 'mla_messages';
             }
             echo "  <div class=\"{$messages_class}\"><p>\n";
             echo '    ' . $page_content['message'] . "\n";
             echo "  </p></div>\n";
             // id="message"
         }
         echo $page_content['body'];
     } else {
         /*
          * Display Attachments list
          */
         if (!empty($_REQUEST['heading_suffix'])) {
             echo ' - ' . esc_html($_REQUEST['heading_suffix']) . "</h2>\n";
         } elseif (!empty($_REQUEST['mla_terms_search'])) {
             echo ' - ' . __('term search results for', 'media-library-assistant') . ' "' . esc_html(stripslashes(trim($_REQUEST['mla_terms_search']['phrases']))) . "\"</h2>\n";
         } elseif (!empty($_REQUEST['s'])) {
             if (empty($_REQUEST['mla_search_fields'])) {
                 echo ' - ' . __('post/parent results for', 'media-library-assistant') . ' "' . esc_html(stripslashes(trim($_REQUEST['s']))) . "\"</h2>\n";
             } else {
                 echo ' - ' . __('search results for', 'media-library-assistant') . ' "' . esc_html(stripslashes(trim($_REQUEST['s']))) . "\"</h2>\n";
             }
         } else {
             echo "</h2>\n";
         }
         if (!empty($page_content['message'])) {
             if (false !== strpos($page_content['message'], __('ERROR', 'media-library-assistant'))) {
                 $messages_class = 'mla_errors';
             } else {
                 $messages_class = 'mla_messages';
             }
             echo "  <div class=\"{$messages_class}\"><p>\n";
             echo '    ' . $page_content['message'] . "\n";
             echo "  </p></div>\n";
             // id="message"
         }
         //	Create an instance of our package class...
         $MLAListTable = apply_filters('mla_list_table_new_instance', NULL);
         if (is_null($MLAListTable)) {
             $MLAListTable = new MLA_List_Table();
         }
         //	Fetch, prepare, sort, and filter our data...
         $MLAListTable->prepare_items();
         $MLAListTable->views();
         $view_arguments = MLA_List_Table::mla_submenu_arguments();
         if (isset($view_arguments['lang'])) {
             $form_url = 'upload.php?page=' . MLACore::ADMIN_PAGE_SLUG . '&lang=' . $view_arguments['lang'];
         } else {
             $form_url = 'upload.php?page=' . MLACore::ADMIN_PAGE_SLUG;
         }
         //	 Forms are NOT created automatically, wrap the table in one to use features like bulk actions
         echo '<form action="' . admin_url($form_url) . '" method="post" id="mla-filter">' . "\n";
         /*
          * Include the Search Media box
          */
         require_once MLA_PLUGIN_PATH . 'includes/mla-main-search-box-template.php';
         /*
          * We also need to ensure that the form posts back to our current page and remember all the view arguments
          */
         echo sprintf('<input type="hidden" name="page" value="%1$s" />', $_REQUEST['page']) . "\n";
         foreach ($view_arguments as $key => $value) {
             if ('meta_query' == $key) {
                 $value = stripslashes($_REQUEST['meta_query']);
             }
             /*
              * Search box elements are already set up in the above "search-box"
              * 'lang' has already been added to the form action attribute
              */
             if (in_array($key, array('s', 'mla_search_connector', 'mla_search_fields', 'lang'))) {
                 continue;
             }
             if (is_array($value)) {
                 foreach ($value as $element_key => $element_value) {
                     echo sprintf('<input type="hidden" name="%1$s[%2$s]" value="%3$s" />', $key, $element_key, esc_attr($element_value)) . "\n";
                 }
             } else {
                 echo sprintf('<input type="hidden" name="%1$s" value="%2$s" />', $key, esc_attr($value)) . "\n";
             }
         }
         //	 Now we can render the completed list table
         $MLAListTable->display();
         echo "</form><!-- id=mla-filter -->\n";
         /*
          * Insert the hidden form and table for inline edits (quick & bulk)
          */
         echo self::_build_inline_edit_form($MLAListTable);
         echo "<div id=\"ajax-response\"></div>\n";
         echo "<br class=\"clear\" />\n";
         echo "</div><!-- class=wrap -->\n";
     }
     // display attachments list
 }
 /**
  * Begin an MLA_List_Table bulk action
  *
  * Prepare the thumbnail generation options.
  *
  * @since 2.13
  *
  * @param	array	$item_content	NULL, to indicate no handler.
  * @param	string	$bulk_action	the requested action.
  */
 public static function mla_list_table_begin_bulk_action($item_content, $bulk_action)
 {
     if (self::MLA_GFI_ACTION != $bulk_action) {
         return $item_content;
     }
     self::$bulk_action_options = array();
     $request_options = isset($_REQUEST['mla_thumbnail_options']) ? $_REQUEST['mla_thumbnail_options'] : array();
     $request_options['ghostscript_path'] = MLACore::mla_get_option('ghostscript_path');
     if (empty($request_options['existing_thumbnails'])) {
         $request_options['existing_thumbnails'] = 'keep';
     }
     foreach ($request_options as $key => $value) {
         if (!empty($value)) {
             self::$bulk_action_options[$key] = $value;
         }
     }
     // Convert checkboxes to booleans
     self::$bulk_action_options['best_fit'] = isset($request_options['best_fit']);
     self::$bulk_action_options['clear_filters'] = isset($request_options['clear_filters']);
     // Convert page number to frame
     if (isset(self::$bulk_action_options['page'])) {
         $page = abs(intval(self::$bulk_action_options['page']));
         self::$bulk_action_options['frame'] = 0 < $page ? $page - 1 : 0;
         unset(self::$bulk_action_options['page']);
     }
     return $item_content;
 }
Ejemplo n.º 12
0
 /**
  * Load an HTML template from a file
  *
  * Loads a template to a string or a multi-part template to an array.
  * Multi-part templates are divided by comments of the form <!-- template="key" -->,
  * where "key" becomes the key part of the array.
  *
  * @since 0.1
  *
  * @param	string 	Complete path and/or name of the template file, option name or the raw template
  * @param	string 	Optional type of template source; 'path', 'file' (default), 'option', 'string'
  *
  * @return	string|array|false|NULL
  *			string for files that do not contain template divider comments,
  *			array for files containing template divider comments,
  *			false if file or option does not exist,
  *			NULL if file could not be loaded.
  */
 public static function mla_load_template($source, $type = 'file')
 {
     switch ($type) {
         case 'file':
             /*
              * Look in three places, in this order:
              * 1) Custom templates
              * 2) Language-specific templates
              * 3) Standard templates
              */
             $text_domain = 'media-library-assistant';
             $locale = apply_filters('mla_plugin_locale', get_locale(), $text_domain);
             $path = trailingslashit(WP_LANG_DIR) . $text_domain . '/tpls/' . $locale . '/' . $source;
             if (file_exists($path)) {
                 $source = $path;
             } else {
                 $path = MLA_PLUGIN_PATH . 'languages/tpls/' . $locale . '/' . $source;
                 if (file_exists($path)) {
                     $source = $path;
                 } else {
                     $source = MLA_PLUGIN_PATH . 'tpls/' . $source;
                 }
             }
             // fallthru
         // fallthru
         case 'path':
             if (!file_exists($source)) {
                 return false;
             }
             $template = file_get_contents($source, true);
             if ($template == false) {
                 /* translators: 1: ERROR tag 2: path and file name */
                 error_log(sprintf(_x('%1$s: mla_load_template file "%2$s" not found.', 'error_log', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), var_export($source, true)), 0);
                 return NULL;
             }
             break;
         case 'option':
             $template = MLACore::mla_get_option($source);
             if ($template == false) {
                 return false;
             }
             break;
         case 'string':
             $template = $source;
             if (empty($template)) {
                 return false;
             }
             break;
         default:
             /* translators: 1: ERROR tag 2: path and file name 3: source type, e.g., file, option, string */
             error_log(sprintf(_x('%1$s: mla_load_template file "%2$s" bad source type "%3$s".', 'error_log', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $source, $type), 0);
             return NULL;
     }
     $match_count = preg_match_all('#\\<!-- template=".+" --\\>#', $template, $matches, PREG_OFFSET_CAPTURE);
     if ($match_count == false || $match_count == 0) {
         return $template;
     }
     $matches = array_reverse($matches[0]);
     $template_array = array();
     $current_offset = strlen($template);
     foreach ($matches as $key => $value) {
         $template_key = preg_split('#"#', $value[0]);
         $template_key = $template_key[1];
         $template_value = substr($template, $value[1] + strlen($value[0]), $current_offset - ($value[1] + strlen($value[0])));
         /*
          * Trim exactly one newline sequence from the start of the value
          */
         if (0 === strpos($template_value, "\r\n")) {
             $offset = 2;
         } elseif (0 === strpos($template_value, "\n\r")) {
             $offset = 2;
         } elseif (0 === strpos($template_value, "\n")) {
             $offset = 1;
         } elseif (0 === strpos($template_value, "\r")) {
             $offset = 1;
         } else {
             $offset = 0;
         }
         $template_value = substr($template_value, $offset);
         /*
          * Trim exactly one newline sequence from the end of the value
          */
         $length = strlen($template_value);
         if ($length > 2) {
             $postfix = substr($template_value, $length - 2, 2);
         } else {
             $postfix = $template_value;
         }
         if (0 === strpos($postfix, "\r\n")) {
             $length -= 2;
         } elseif (0 === strpos($postfix, "\n\r")) {
             $length -= 2;
         } elseif (0 === strpos($postfix, "\n")) {
             $length -= 1;
         } elseif (0 === strpos($postfix, "\r")) {
             $length -= 1;
         }
         $template_array[$template_key] = substr($template_value, 0, $length);
         $current_offset = $value[1];
     }
     // foreach $matches
     return $template_array;
 }
Ejemplo n.º 13
0
 /**
  * Serialize option settings and write them to a file
  *
  * Options with a default value, i.e., not stored in the database are NOT written to the file.
  *
  * @since 1.50
  *
  * @return	array	Message(s) reflecting the results of the operation
  */
 private static function _export_settings()
 {
     $message_list = '';
     $settings = array();
     $stored_count = 0;
     /*
      * These are WordPress options, not MLA options
      */
     foreach (array('image_default_align', 'image_default_link_type', 'image_default_size') as $key) {
         $stored_value = get_option($key);
         if (empty($stored_value)) {
             $stored_value = 'default';
         }
         if ('default' !== $stored_value) {
             $settings[$key] = $stored_value;
             $stored_count++;
             $message = "<br>{$key} " . _x('exported', 'message_list', 'media-library-assistant');
         } else {
             $message = "<br>{$key} " . _x('skipped', 'message_list', 'media-library-assistant');
         }
         $message_list .= $message;
     }
     /*
      * Accumulate the settings into an array, then serialize it for writing to the file.
      */
     foreach (MLACore::$mla_option_definitions as $key => $value) {
         $stored_value = MLACore::mla_get_option($key, false, true);
         if (false !== $stored_value) {
             $settings[$key] = $stored_value;
             $stored_count++;
             $message = "<br>{$key} " . _x('exported', 'message_list', 'media-library-assistant');
         } else {
             $message = "<br>{$key} " . _x('skipped', 'message_list', 'media-library-assistant');
         }
         $message_list .= $message;
     }
     $settings = serialize($settings);
     $page_content = array('message' => __('ALL settings exported.', 'media-library-assistant'), 'body' => '');
     /*
      * Make sure the directory exists and is writable, then create the file
      */
     $prefix = defined(MLA_OPTION_PREFIX) ? MLA_OPTION_PREFIX : 'mla_';
     $date = date("Ymd_B");
     $filename = MLA_BACKUP_DIR . "{$prefix}_options_{$date}.txt";
     if (!file_exists(MLA_BACKUP_DIR) && !@mkdir(MLA_BACKUP_DIR)) {
         /* translators: 1: ERROR tag 2: backup directory name */
         $page_content['message'] = sprintf(__('%1$s: The settings directory ( %2$s ) cannot be created.', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), MLA_BACKUP_DIR);
         return $page_content;
     } elseif (!is_writable(MLA_BACKUP_DIR) && !@chmod(MLA_BACKUP_DIR, '0777')) {
         /* translators: 1: ERROR tag 2: backup directory name */
         $page_content['message'] = sprintf(__('%1$s: The settings directory ( %2$s ) is not writable.', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), MLA_BACKUP_DIR);
         return $page_content;
     }
     if (!file_exists(MLA_BACKUP_DIR . 'index.php')) {
         @touch(MLA_BACKUP_DIR . 'index.php');
     }
     $file_handle = @fopen($filename, 'w');
     if (!$file_handle) {
         /* translators: 1: ERROR tag 2: backup file name */
         $page_content['message'] = sprintf(__('%1$s: The settings file ( %2$s ) could not be opened.', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $filename);
         return $page_content;
     }
     if (false === @fwrite($file_handle, $settings)) {
         $error_info = error_get_last();
         /* translators: 1: ERROR tag 2: PHP error information */
         error_log(sprintf(_x('%1$s: _export_settings $error_info = "%2$s".', 'error_log', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), var_export($error_info, true)), 0);
         if (false !== ($tail = strpos($error_info['message'], '</a>]: '))) {
             $php_errormsg = ':<br>' . substr($error_info['message'], $tail + 7);
         } else {
             $php_errormsg = '.';
         }
         /* translators: 1: ERROR tag 2: backup file name 3: error message*/
         $page_content['message'] = sprintf(__('%1$s: Writing the settings file ( %2$s ) "%3$s".', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $filename, $php_errormsg);
     }
     fclose($file_handle);
     /* translators: 1: number of option settings */
     $page_content['message'] = sprintf(__('Settings exported; %1$s settings recorded.', 'media-library-assistant'), $stored_count);
     /*
      * Uncomment this for debugging.
      */
     //$page_content['message'] .= $message_list;
     return $page_content;
 }
 /**
  * Clean up the 'save-attachment-compat' values, removing taxonomy updates MLA already handled
  *
  * @since 1.20
  *
  * @return	void	
  */
 public static function mla_admin_init_action()
 {
     /*
      * Build a list of enhanced taxonomies for later $_REQUEST/$_POST cleansing.
      * Remove "Media Categories" instances, if present.
      */
     $enhanced_taxonomies = 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');
             }
             if ($use_checklist) {
                 if ('checked' == MLACore::mla_get_option(MLACoreOptions::MLA_MEDIA_MODAL_DETAILS_CATEGORY_METABOX)) {
                     $enhanced_taxonomies[] = $key;
                     if (class_exists('Media_Categories') && is_array(Media_Categories::$instances)) {
                         foreach (Media_Categories::$instances as $index => $instance) {
                             if ($instance->taxonomy == $key) {
                                 // unset( Media_Categories::$instances[ $index ] );
                                 Media_Categories::$instances[$index]->taxonomy = 'MLA-has-disabled-this-instance';
                             }
                         }
                     }
                     // class_exists
                 }
                 // checked
             }
             // use_checklist
         }
         // supported
     }
     // foreach taxonomy
 }
Ejemplo n.º 15
0
 /**
  * Render and manage iptc/exif support options
  *
  * @since 1.00
  * @uses $mla_option_templates contains row and table templates
  *
  * @param	string 	'render', 'update', 'delete', or 'reset'
  * @param	string 	option name, e.g., 'iptc_exif_mapping'
  * @param	array 	option parameters
  * @param	array 	Optional. null (default) for 'render' else option data, e.g., $_REQUEST
  *
  * @return	string	HTML table row markup for 'render' else message(s) reflecting the results of the operation.
  */
 public static function mla_iptc_exif_option_handler($action, $key, $value, $args = NULL)
 {
     $current_values = MLACore::mla_get_option('iptc_exif_mapping');
     switch ($action) {
         case 'render':
             switch ($key) {
                 case 'iptc_exif_standard_mapping':
                     $row_template = MLAOptions::$mla_option_templates['iptc-exif-standard-row'];
                     $table_rows = '';
                     foreach ($current_values['standard'] as $row_name => $row_value) {
                         $row_values = array('key' => esc_attr($row_name), 'name_attr' => esc_attr($row_value['name']), 'name' => esc_html($row_value['name']), 'iptc_field_options' => MLAOptions::_compose_iptc_option_list($row_value['iptc_value']), 'exif_size' => MLACoreOptions::MLA_EXIF_SIZE, 'exif_text' => esc_attr($row_value['exif_value']), 'iptc_selected' => '', 'IPTC' => __('IPTC', 'media-library-assistant'), 'exif_selected' => '', 'EXIF' => __('EXIF', 'media-library-assistant'), 'keep_selected' => '', 'Keep' => __('Keep', 'media-library-assistant'), 'replace_selected' => '', 'Replace' => __('Replace', 'media-library-assistant'));
                         if ($row_value['iptc_first']) {
                             $row_values['iptc_selected'] = 'selected="selected"';
                         } else {
                             $row_values['exif_selected'] = 'selected="selected"';
                         }
                         if ($row_value['keep_existing']) {
                             $row_values['keep_selected'] = 'selected="selected"';
                         } else {
                             $row_values['replace_selected'] = 'selected="selected"';
                         }
                         $table_rows .= MLAData::mla_parse_template($row_template, $row_values);
                     }
                     // foreach row
                     $option_values = array('Field Title' => __('Field Title', 'media-library-assistant'), 'IPTC Value' => __('IPTC Value', 'media-library-assistant'), 'EXIF/Template Value' => __('EXIF/Template Value', 'media-library-assistant'), 'Priority' => __('Priority', 'media-library-assistant'), 'Existing Text' => __('Existing Text', 'media-library-assistant'), 'table_rows' => $table_rows, 'help' => $value['help']);
                     return MLAData::mla_parse_template(MLAOptions::$mla_option_templates['iptc-exif-standard-table'], $option_values);
                 case 'iptc_exif_taxonomy_mapping':
                     $row_template = MLAOptions::$mla_option_templates['iptc-exif-taxonomy-row'];
                     $select_template = MLAOptions::$mla_option_templates['iptc-exif-select'];
                     $table_rows = '';
                     $taxonomies = get_taxonomies(array('show_ui' => true), 'objects');
                     foreach ($taxonomies as $row_name => $row_value) {
                         if (!MLACore::mla_taxonomy_support($row_name, 'support')) {
                             continue;
                         }
                         $row_values = array('key' => esc_attr($row_name), 'name' => esc_html($row_value->labels->name), 'hierarchical' => (string) $row_value->hierarchical, 'iptc_field_options' => '', 'exif_size' => MLACoreOptions::MLA_EXIF_SIZE, 'exif_text' => '', 'iptc_selected' => '', 'IPTC' => __('IPTC', 'media-library-assistant'), 'exif_selected' => '', 'EXIF' => __('EXIF', 'media-library-assistant'), 'keep_selected' => '', 'Keep' => __('Keep', 'media-library-assistant'), 'replace_selected' => '', 'Replace' => __('Replace', 'media-library-assistant'), 'delimiters_size' => 4, 'delimiters_text' => '', 'parent_select' => '');
                         if (array_key_exists($row_name, $current_values['taxonomy'])) {
                             $current_value = $current_values['taxonomy'][$row_name];
                             $row_values['iptc_field_options'] = MLAOptions::_compose_iptc_option_list($current_value['iptc_value']);
                             $row_values['exif_text'] = esc_attr($current_value['exif_value']);
                             if ($current_value['iptc_first']) {
                                 $row_values['iptc_selected'] = 'selected="selected"';
                             } else {
                                 $row_values['exif_selected'] = 'selected="selected"';
                             }
                             if ($current_value['keep_existing']) {
                                 $row_values['keep_selected'] = 'selected="selected"';
                             } else {
                                 $row_values['replace_selected'] = 'selected="selected"';
                             }
                             $row_values['delimiters_text'] = $current_value['delimiters'];
                             if ($row_value->hierarchical) {
                                 $parent = isset($current_value['parent']) ? (int) $current_value['parent'] : 0;
                                 $select_values = array('array' => 'taxonomy', 'key' => esc_attr($row_name), 'element' => 'parent', 'options' => MLAOptions::_compose_parent_option_list($row_name, $parent));
                                 $row_values['parent_select'] = MLAData::mla_parse_template($select_template, $select_values);
                             }
                         } else {
                             $row_values['iptc_field_options'] = MLAOptions::_compose_iptc_option_list('none');
                             $row_values['iptc_selected'] = 'selected="selected"';
                             $row_values['keep_selected'] = 'selected="selected"';
                             if ($row_value->hierarchical) {
                                 $select_values = array('array' => 'taxonomy', 'key' => esc_attr($row_name), 'element' => 'parent', 'options' => MLAOptions::_compose_parent_option_list($row_name, 0));
                                 $row_values['parent_select'] = MLAData::mla_parse_template($select_template, $select_values);
                             }
                         }
                         $table_rows .= MLAData::mla_parse_template($row_template, $row_values);
                     }
                     // foreach row
                     $option_values = array('Field Title' => __('Field Title', 'media-library-assistant'), 'IPTC Value' => __('IPTC Value', 'media-library-assistant'), 'EXIF/Template Value' => __('EXIF/Template Value', 'media-library-assistant'), 'Priority' => __('Priority', 'media-library-assistant'), 'Existing Text' => __('Existing Text', 'media-library-assistant'), 'Delimiter(s)' => __('Delimiter(s)', 'media-library-assistant'), 'Parent' => __('Parent', 'media-library-assistant'), 'table_rows' => $table_rows, 'help' => $value['help']);
                     return MLAData::mla_parse_template(MLAOptions::$mla_option_templates['iptc-exif-taxonomy-table'], $option_values);
                 case 'iptc_exif_custom_mapping':
                     if (empty($current_values['custom'])) {
                         $table_rows = MLAData::mla_parse_template(MLAOptions::$mla_option_templates['iptc-exif-custom-empty-row'], array('No Mapping Rules' => __('No Custom Field Mapping Rules Defined', 'media-library-assistant'), 'column_count' => 5));
                     } else {
                         $row_template = MLAOptions::$mla_option_templates['iptc-exif-custom-rule-row'];
                         $table_rows = '';
                         $index = 0;
                     }
                     /*
                      * One row for each existing rule, case insensitive "natural order"
                      */
                     $sorted_keys = array();
                     foreach ($current_values['custom'] as $row_name => $current_value) {
                         $sorted_keys[$current_value['name']] = $current_value['name'];
                     }
                     natcasesort($sorted_keys);
                     $sorted_names = array();
                     foreach ($sorted_keys as $row_name) {
                         $sorted_names[$row_name] = array();
                     }
                     /*
                      * Allow for multiple rules mapping the same name (an old bug)
                      */
                     foreach ($current_values['custom'] as $row_name => $current_value) {
                         $sorted_names[$current_value['name']][] = $row_name;
                     }
                     foreach ($sorted_names as $sorted_keys) {
                         foreach ($sorted_keys as $row_name) {
                             $current_value = $current_values['custom'][$row_name];
                             $row_values = array('column_count' => 5, 'column_count_meta' => 5 - 2, 'index' => $index++, 'key' => esc_attr($row_name), 'name_attr' => esc_attr($current_value['name']), 'name' => esc_html($current_value['name']), 'iptc_field_options' => MLAOptions::_compose_iptc_option_list($current_value['iptc_value']), 'exif_size' => MLACoreOptions::MLA_EXIF_SIZE, 'exif_text' => esc_attr($current_value['exif_value']), 'iptc_selected' => '', 'IPTC' => __('IPTC', 'media-library-assistant'), 'exif_selected' => '', 'EXIF' => __('EXIF', 'media-library-assistant'), 'keep_selected' => '', 'Keep' => __('Keep', 'media-library-assistant'), 'replace_selected' => '', 'Replace' => __('Replace', 'media-library-assistant'), 'Format' => __('Format', 'media-library-assistant'), 'native_format' => '', 'Native' => __('Native', 'media-library-assistant'), 'commas_format' => '', 'Commas' => __('Commas', 'media-library-assistant'), 'raw_format' => '', 'Raw' => __('Raw', 'media-library-assistant'), 'Option' => __('Option', 'media-library-assistant'), 'text_option' => '', 'Text' => __('Text', 'media-library-assistant'), 'single_option' => '', 'Single' => __('Single', 'media-library-assistant'), 'export_option' => '', 'Export' => __('Export', 'media-library-assistant'), 'array_option' => '', 'Array' => __('Array', 'media-library-assistant'), 'multi_option' => '', 'Multi' => __('Multi', 'media-library-assistant'), 'no_null_checked' => '', 'Delete NULL values' => __('Delete NULL values', 'media-library-assistant'), 'Delete Rule' => __('Delete Rule', 'media-library-assistant'), 'Delete Field' => __('Delete Rule AND Field', 'media-library-assistant'), 'Update Rule' => __('Update Rule', 'media-library-assistant'), 'Map All Attachments' => __('Map All Attachments', 'media-library-assistant'));
                             if ($current_value['iptc_first']) {
                                 $row_values['iptc_selected'] = 'selected="selected"';
                             } else {
                                 $row_values['exif_selected'] = 'selected="selected"';
                             }
                             if ($current_value['keep_existing']) {
                                 $row_values['keep_selected'] = 'selected="selected"';
                             } else {
                                 $row_values['replace_selected'] = 'selected="selected"';
                             }
                             switch ($current_value['format']) {
                                 case 'commas':
                                     $row_values['commas_format'] = 'selected="selected"';
                                     break;
                                 case 'raw':
                                     $row_values['raw_format'] = 'selected="selected"';
                                     break;
                                 default:
                                     $row_values['native_format'] = 'selected="selected"';
                             }
                             // format
                             switch ($current_value['option']) {
                                 case 'single':
                                     $row_values['single_option'] = 'selected="selected"';
                                     break;
                                 case 'export':
                                     $row_values['export_option'] = 'selected="selected"';
                                     break;
                                 case 'array':
                                     $row_values['array_option'] = 'selected="selected"';
                                     break;
                                 case 'multi':
                                     $row_values['multi_option'] = 'selected="selected"';
                                     break;
                                 default:
                                     $row_values['text_option'] = 'selected="selected"';
                             }
                             // option
                             if ($current_value['no_null']) {
                                 $row_values['no_null_checked'] = 'checked="checked"';
                             }
                             $table_rows .= MLAData::mla_parse_template($row_template, $row_values);
                         }
                         // foreach current_values key
                     }
                     // foreach sorted_name
                     /*
                      * Add a row for defining a new rule, existing Custom Field
                      */
                     $row_template = MLAOptions::$mla_option_templates['iptc-exif-custom-new-rule-row'];
                     $row_values = array('column_count' => 5, 'column_count_meta' => 5 - 2, 'Add new Rule' => __('Add a new Mapping Rule', 'media-library-assistant'), 'index' => MLACoreOptions::MLA_NEW_CUSTOM_RULE, 'field_name_options' => MLAOptions::_compose_custom_field_option_list('none', $current_values['custom']), 'iptc_field_options' => MLAOptions::_compose_iptc_option_list('none'), 'exif_size' => MLACoreOptions::MLA_EXIF_SIZE, 'exif_text' => '', 'iptc_selected' => 'selected="selected"', 'IPTC' => __('IPTC', 'media-library-assistant'), 'exif_selected' => '', 'EXIF' => __('EXIF', 'media-library-assistant'), 'keep_selected' => 'selected="selected"', 'Keep' => __('Keep', 'media-library-assistant'), 'replace_selected' => '', 'Replace' => __('Replace', 'media-library-assistant'), 'Format' => __('Format', 'media-library-assistant'), 'native_format' => 'selected="selected"', 'Native' => __('Native', 'media-library-assistant'), 'commas_format' => '', 'Commas' => __('Commas', 'media-library-assistant'), 'raw_format' => '', 'Raw' => __('Raw', 'media-library-assistant'), 'Option' => __('Option', 'media-library-assistant'), 'text_option' => '', 'Text' => __('Text', 'media-library-assistant'), 'single_option' => '', 'Single' => __('Single', 'media-library-assistant'), 'export_option' => '', 'Export' => __('Export', 'media-library-assistant'), 'array_option' => '', 'Array' => __('Array', 'media-library-assistant'), 'multi_option' => '', 'Multi' => __('Multi', 'media-library-assistant'), 'no_null_checked' => '', 'Delete NULL values' => __('Delete NULL values', 'media-library-assistant'), 'Add Rule' => __('Add Rule', 'media-library-assistant'), 'Map All Attachments' => __('Add Rule and Map All Attachments', 'media-library-assistant'));
                     $table_rows .= MLAData::mla_parse_template($row_template, $row_values);
                     /*
                      * Add a row for defining a new rule, new Custom Field
                      */
                     $row_template = MLAOptions::$mla_option_templates['iptc-exif-custom-new-field-row'];
                     $row_values = array('column_count' => 5, 'column_count_meta' => 5 - 2, 'Add new Field' => __('Add a new Field and Mapping Rule', 'media-library-assistant'), 'index' => MLACoreOptions::MLA_NEW_CUSTOM_FIELD, 'field_name_size' => '24', 'iptc_field_options' => MLAOptions::_compose_iptc_option_list('none'), 'exif_size' => MLACoreOptions::MLA_EXIF_SIZE, 'exif_text' => '', 'iptc_selected' => 'selected="selected"', 'IPTC' => __('IPTC', 'media-library-assistant'), 'exif_selected' => '', 'EXIF' => __('EXIF', 'media-library-assistant'), 'keep_selected' => 'selected="selected"', 'Keep' => __('Keep', 'media-library-assistant'), 'replace_selected' => '', 'Replace' => __('Replace', 'media-library-assistant'), 'Format' => __('Format', 'media-library-assistant'), 'native_format' => 'selected="selected"', 'Native' => __('Native', 'media-library-assistant'), 'commas_format' => '', 'Commas' => __('Commas', 'media-library-assistant'), 'raw_format' => '', 'Raw' => __('Raw', 'media-library-assistant'), 'Option' => __('Option', 'media-library-assistant'), 'text_option' => '', 'Text' => __('Text', 'media-library-assistant'), 'single_option' => '', 'Single' => __('Single', 'media-library-assistant'), 'export_option' => '', 'Export' => __('Export', 'media-library-assistant'), 'array_option' => '', 'Array' => __('Array', 'media-library-assistant'), 'multi_option' => '', 'Multi' => __('Multi', 'media-library-assistant'), 'no_null_checked' => '', 'Delete NULL values' => __('Delete NULL values', 'media-library-assistant'), 'Add Field' => __('Add Field', 'media-library-assistant'), 'Map All Attachments' => __('Add Field and Map All Attachments', 'media-library-assistant'));
                     $table_rows .= MLAData::mla_parse_template($row_template, $row_values);
                     $option_values = array('Field Title' => __('Field Title', 'media-library-assistant'), 'IPTC Value' => __('IPTC Value', 'media-library-assistant'), 'EXIF/Template Value' => __('EXIF/Template Value', 'media-library-assistant'), 'Priority' => __('Priority', 'media-library-assistant'), 'Existing Text' => __('Existing Text', 'media-library-assistant'), 'table_rows' => $table_rows, 'help' => $value['help']);
                     return MLAData::mla_parse_template(MLAOptions::$mla_option_templates['iptc-exif-custom-table'], $option_values);
                 default:
                     /* translators: 1: ERROR tag 2: option name */
                     return '<br>' . sprintf(__('%1$s: Render unknown custom %2$s.', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $key) . "\r\n";
             }
             // switch $key
         // switch $key
         case 'update':
         case 'delete':
             $settings_changed = false;
             $messages = '';
             switch ($key) {
                 case 'iptc_exif_standard_mapping':
                     $results = MLAOptions::_update_iptc_exif_standard_mapping($current_values, $args);
                     $messages .= $results['message'];
                     $current_values = $results['values'];
                     $settings_changed = $results['changed'];
                     break;
                 case 'iptc_exif_taxonomy_mapping':
                     $results = MLAOptions::_update_iptc_exif_taxonomy_mapping($current_values, $args);
                     $messages .= $results['message'];
                     $current_values = $results['values'];
                     $settings_changed = $results['changed'];
                     break;
                 case 'iptc_exif_custom_mapping':
                     $results = MLAOptions::_update_iptc_exif_custom_mapping($current_values, $args);
                     $messages .= $results['message'];
                     $current_values = $results['values'];
                     $settings_changed = $results['changed'];
                     break;
                 case 'iptc_exif_mapping':
                     $results = MLAOptions::_update_iptc_exif_standard_mapping($current_values, $args);
                     $messages .= $results['message'];
                     $current_values = $results['values'];
                     $settings_changed = $results['changed'];
                     $results = MLAOptions::_update_iptc_exif_taxonomy_mapping($current_values, $args);
                     $messages .= $results['message'];
                     $current_values = $results['values'];
                     $settings_changed |= $results['changed'];
                     $results = MLAOptions::_update_iptc_exif_custom_mapping($current_values, $args);
                     $messages .= $results['message'];
                     $current_values = $results['values'];
                     $settings_changed |= $results['changed'];
                     break;
                 default:
                     /* translators: 1: ERROR tag 2: option name */
                     return '<br>' . sprintf(__('%1$s: Update/delete unknown custom %2$s.', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $key) . "\r\n";
             }
             // switch $key
             if ($settings_changed) {
                 $settings_changed = MLACore::mla_update_option('iptc_exif_mapping', $current_values);
                 if ($settings_changed) {
                     $results = __('IPTC/EXIF mapping settings updated.', 'media-library-assistant') . "\r\n";
                 } else {
                     $results = __('ERROR', 'media-library-assistant') . ': ' . __('IPTC/EXIF settings update failed.', 'media-library-assistant') . "\r\n";
                 }
             } else {
                 $results = __('IPTC/EXIF no mapping changes detected.', 'media-library-assistant') . "\r\n";
             }
             return $results . $messages;
         case 'reset':
             switch ($key) {
                 case 'iptc_exif_standard_mapping':
                     $current_values['standard'] = MLACoreOptions::$mla_option_definitions['iptc_exif_mapping']['std']['standard'];
                     $settings_changed = MLACore::mla_update_option('iptc_exif_mapping', $current_values);
                     if ($settings_changed) {
                         /* translators: 1: field type */
                         return sprintf(__('%1$s settings saved.', 'media-library-assistant'), 'IPTC/EXIF ' . __('Standard field', 'media-library-assistant')) . "\r\n";
                     } else {
                         /* translators: 1: ERROR tag 2: field type */
                         return sprintf(__('%1$s: IPTC/EXIF %2$s settings update failed.', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), __('Standard field', 'media-library-assistant')) . "\r\n";
                     }
                 case 'iptc_exif_taxonomy_mapping':
                     $current_values['taxonomy'] = MLACoreOptions::$mla_option_definitions['iptc_exif_mapping']['std']['taxonomy'];
                     $settings_changed = MLACore::mla_update_option('iptc_exif_mapping', $current_values);
                     if ($settings_changed) {
                         /* translators: 1: field type */
                         return sprintf(__('%1$s settings saved.', 'media-library-assistant'), 'IPTC/EXIF ' . __('Taxonomy term', 'media-library-assistant')) . "\r\n";
                     } else {
                         /* translators: 1: ERROR tag 2: field type */
                         return sprintf(__('%1$s: IPTC/EXIF %2$s settings update failed.', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), __('Taxonomy term', 'media-library-assistant')) . "\r\n";
                     }
                 case 'iptc_exif_custom_mapping':
                     $current_values['custom'] = MLACoreOptions::$mla_option_definitions['iptc_exif_mapping']['std']['custom'];
                     $settings_changed = MLACore::mla_update_option('iptc_exif_mapping', $current_values);
                     if ($settings_changed) {
                         /* translators: 1: field type */
                         return sprintf(__('%1$s settings saved.', 'media-library-assistant'), 'IPTC/EXIF ' . __('Custom field', 'media-library-assistant')) . "\r\n";
                     } else {
                         /* translators: 1: ERROR tag 2: field type */
                         return sprintf(__('%1$s: IPTC/EXIF %2$s settings update failed.', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), __('Custom field', 'media-library-assistant')) . "\r\n";
                     }
                 case 'iptc_exif_mapping':
                     MLACore::mla_delete_option($key);
                     /* translators: 1: option name, e.g., taxonomy_support */
                     return '<br>' . sprintf(__('Reset custom %1$s', 'media-library-assistant'), $key) . "\r\n";
                 default:
                     /* translators: 1: ERROR tag 2: option name, e.g., taxonomy_support */
                     return '<br>' . sprintf(__('%1$s: Reset unknown custom %2$s', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $key) . "\r\n";
             }
             // switch $key
         // switch $key
         default:
             /* translators: 1: ERROR tag 2: option name 3: action, e.g., update, delete, reset */
             return '<br>' . sprintf(__('%1$s: Custom %2$s unknown action "%3$s"', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $key, $action) . "\r\n";
     }
     // switch $action
 }
Ejemplo n.º 16
0
 /**
  * Builds the $mla_galleries or $galleries array
  *
  * @since 0.70
  *
  * @param	string name of the gallery's cache/option variable
  * @param	array by reference to the private static galleries array variable
  * @param	string the shortcode to be searched for and processed
  * @param	boolean true to exclude revisions from the search
  *
  * @return	boolean true if the galleries array is not empty
  */
 private static function _build_mla_galleries($option_name, &$galleries_array, $shortcode, $exclude_revisions)
 {
     global $wpdb, $post;
     if (is_array($galleries_array)) {
         if (!empty($galleries_array)) {
             return true;
         } else {
             return false;
         }
     }
     $option_value = MLACore::mla_get_option($option_name);
     if ('disabled' == $option_value) {
         return false;
     } elseif ('cached' == $option_value) {
         $galleries_array = get_transient(MLA_OPTION_PREFIX . 't_' . $option_name);
         if (is_array($galleries_array)) {
             if (!empty($galleries_array)) {
                 return true;
             } else {
                 return false;
             }
         } else {
             $galleries_array = NULL;
         }
     }
     // cached
     /* 
      * The MLAShortcodes class is only loaded when needed.
      */
     if (!class_exists('MLAShortcodes')) {
         require_once MLA_PLUGIN_PATH . 'includes/class-mla-shortcodes.php';
     }
     /*
      * $galleries_array is null, so build the array
      */
     $galleries_array = array();
     if ($exclude_revisions) {
         $exclude_revisions = "(post_type <> 'revision') AND ";
     } else {
         $exclude_revisions = '';
     }
     if (MLAQuery::$wp_4dot0_plus) {
         $like = $wpdb->esc_like($shortcode);
     } else {
         $like = like_escape($shortcode);
     }
     $results = $wpdb->get_results($wpdb->prepare("\r\n\t\t\t\tSELECT ID, post_type, post_status, post_title, post_content\r\n\t\t\t\tFROM {$wpdb->posts}\r\n\t\t\t\tWHERE {$exclude_revisions}(\r\n\t\t\t\t\tCONVERT(`post_content` USING utf8 )\r\n\t\t\t\t\tLIKE %s)\r\n\t\t\t\t", "%{$like}%"));
     if (empty($results)) {
         return false;
     }
     foreach ($results as $result) {
         $count = preg_match_all("/\\{$shortcode}([^\\]]*)\\]/", $result->post_content, $matches, PREG_PATTERN_ORDER);
         if ($count) {
             $result_id = $result->ID;
             $galleries_array[$result_id]['parent_title'] = $result->post_title;
             $galleries_array[$result_id]['parent_type'] = $result->post_type;
             $galleries_array[$result_id]['parent_status'] = $result->post_status;
             $galleries_array[$result_id]['results'] = array();
             $galleries_array[$result_id]['galleries'] = array();
             $instance = 0;
             foreach ($matches[1] as $index => $match) {
                 /*
                  * Filter out shortcodes that are not an exact match
                  */
                 if (empty($match) || ' ' == substr($match, 0, 1)) {
                     $instance++;
                     /*
                      * Remove trailing "/" from XHTML-style self-closing shortcodes
                      */
                     $galleries_array[$result_id]['galleries'][$instance]['query'] = trim(rtrim($matches[1][$index], '/'));
                     $galleries_array[$result_id]['galleries'][$instance]['results'] = array();
                     $post = $result;
                     // set global variable for mla_gallery_shortcode
                     $attachments = MLAShortcodes::mla_get_shortcode_attachments($result_id, $galleries_array[$result_id]['galleries'][$instance]['query'] . ' cache_results=false update_post_meta_cache=false update_post_term_cache=false where_used_query=this-is-a-where-used-query');
                     if (is_string($attachments)) {
                         /* translators: 1: post_type, 2: post_title, 3: post ID, 4: query string, 5: error message */
                         trigger_error(htmlentities(sprintf(__('(%1$s) %2$s (ID %3$d) query "%4$s" failed, returning "%5$s"', 'media-library-assistant'), $result->post_type, $result->post_title, $result->ID, $galleries_array[$result_id]['galleries'][$instance]['query'], $attachments)), E_USER_WARNING);
                     } elseif (!empty($attachments)) {
                         foreach ($attachments as $attachment) {
                             $galleries_array[$result_id]['results'][$attachment->ID] = $attachment->ID;
                             $galleries_array[$result_id]['galleries'][$instance]['results'][] = $attachment->ID;
                         }
                     }
                 }
                 // exact match
             }
             // foreach $match
         }
         // if $count
     }
     // foreach $result
     /*
      * Maybe cache the results
      */
     if ('cached' == $option_value) {
         set_transient(MLA_OPTION_PREFIX . 't_' . $option_name, $galleries_array, 900);
         // fifteen minutes
     }
     return true;
 }
 /**
  * Load style and markup templates to $mla_custom_templates
  *
  * @since 2.30
  *
  * @return	void
  */
 public static function mla_load_custom_templates()
 {
     if (empty(MLATemplate_Support::$mla_template_definitions)) {
         MLATemplate_Support::mla_localize_template_definitions();
     }
     MLATemplate_Support::$mla_custom_templates = NULL;
     $default_templates = MLACore::mla_load_template('mla-custom-templates.tpl');
     /* 	
      * Load the default templates
      */
     if (is_null($default_templates)) {
         MLACore::mla_debug_add('<strong>mla_debug mla_load_custom_templates()</strong> ' . __('error loading tpls/mla-custom-templates.tpl', 'media-library-assistant'), MLACore::MLA_DEBUG_CATEGORY_ANY);
         return;
     } elseif (!$default_templates) {
         MLACore::mla_debug_add('<strong>mla_debug mla_load_custom_templates()</strong> ' . __('tpls/mla-custom-templates.tpl not found', 'media-library-assistant'), MLACore::MLA_DEBUG_CATEGORY_ANY);
         return;
     }
     /*
      * Record explicit shortcode assignments
      */
     $mla_shortcode_slugs = array();
     foreach ($default_templates as $key => $value) {
         $mla_shortcode_slug = NULL;
         $match_count = preg_match('#\\<!-- mla_shortcode_slug="(.+)" --\\>[\\r\\n]*#', $value, $matches, PREG_OFFSET_CAPTURE);
         if ($match_count == 0) {
             $match_count = preg_match('#mla_shortcode_slug="(.+)"[ \\r\\n]*#', $value, $matches, PREG_OFFSET_CAPTURE);
         }
         if ($match_count > 0) {
             $mla_shortcode_slug = $matches[1][0];
             //error_log( __LINE__ . " default template {$key}, {$mla_shortcode_slug} matches = " . var_export( $matches, true ), 0 );
             $value = substr_replace($value, '', $matches[0][1], strlen($matches[0][0]));
             if (empty($value)) {
                 unset($default_templates[$key]);
                 //error_log( __LINE__ . " unset default template {$key}, {$mla_shortcode_slug}", 0 );
             } else {
                 $default_templates[$key] = $value;
                 //error_log( __LINE__ . " replace default template {$key}, {$mla_shortcode_slug} value = " . MLAData::mla_hex_dump( $value ), 0 );
             }
         }
         if (!empty($mla_shortcode_slug)) {
             $tail = strrpos($key, '-style');
             if (!(false === $tail)) {
                 $mla_shortcode_slugs['style'][substr($key, 0, $tail)] = $mla_shortcode_slug;
             } else {
                 $tail = strrpos($key, '-arguments-markup');
                 if (!(false === $tail)) {
                     $mla_shortcode_slugs['markup'][substr($key, 0, $tail)] = $mla_shortcode_slug;
                 }
             }
         }
     }
     //error_log( __LINE__ . " mla_shortcode_slugs = " . var_export( $mla_shortcode_slugs, true ), 0 );
     /*
      * Find the shortcode and template type for array indices
      */
     foreach ($default_templates as $key => $value) {
         $tail = strrpos($key, '-style');
         if (!(false === $tail)) {
             $name = substr($key, 0, $tail);
             if (isset($mla_shortcode_slugs['style'][$name])) {
                 // Assign to the declared shortcode
                 MLATemplate_Support::$mla_custom_templates['style'][$mla_shortcode_slugs['style'][$name]][$name] = $value;
                 $name = NULL;
             } else {
                 // Guess at the shortcode
                 foreach (MLATemplate_Support::$mla_template_definitions['style'] as $slug => $definition) {
                     if (isset($definition['default_names']) && in_array($name, $definition['default_names'])) {
                         MLATemplate_Support::$mla_custom_templates['style'][$definition['slug']][$name] = $value;
                         $name = NULL;
                         break;
                     }
                 }
             }
             // Can't find the shortcode; assume it's mla_gallery
             if ($name) {
                 MLATemplate_Support::$mla_custom_templates['style']['gallery'][$name] = $value;
             }
             continue;
         }
         $tail = strrpos($key, '-markup');
         if (!(false === $tail)) {
             $name = substr($key, 0, $tail);
             // Look for explicit assignment
             foreach ($mla_shortcode_slugs['markup'] as $root_name => $mla_shortcode_slug) {
                 $root = strpos($name, $root_name);
                 if (0 === $root) {
                     $section_name = substr($name, strlen($root_name) + 1);
                     //error_log( __LINE__ . " assign default template {$key}, to [{$mla_shortcode_slug}][{$root_name}][{$section_name}]", 0 );
                     // Assign to the declared shortcode
                     MLATemplate_Support::$mla_custom_templates['markup'][$mla_shortcode_slug][$root_name][$section_name] = $value;
                     $name = NULL;
                     break;
                 }
             }
             if ($name) {
                 // Guess at the shortcode
                 foreach (MLATemplate_Support::$mla_template_definitions['markup'] as $slug => $definition) {
                     if (isset($definition['default_names'])) {
                         foreach ($definition['default_names'] as $default_name) {
                             $root = strpos($name, $default_name);
                             if (0 === $root) {
                                 foreach ($definition['sections'] as $section_name => $section_value) {
                                     $tail = strrpos($name, '-' . $section_name);
                                     if (!(false === $tail)) {
                                         $name = substr($name, 0, $tail);
                                         MLATemplate_Support::$mla_custom_templates['markup'][$definition['slug']][$name][$section_name] = $value;
                                     }
                                 }
                                 $name = NULL;
                                 break;
                             }
                         }
                     }
                 }
             }
             // Can't find the shortcode; assume it's mla_gallery
             if ($name) {
                 foreach (MLATemplate_Support::$mla_template_definitions['markup']['gallery']['sections'] as $section_name => $section_value) {
                     $tail = strrpos($name, '-' . $section_name);
                     if (!(false === $tail)) {
                         $name = substr($name, 0, $tail);
                         MLATemplate_Support::$mla_custom_templates['markup']['gallery'][$name][$section_name] = $value;
                     }
                 }
             }
         }
     }
     /*
      * Add user-defined Style and Markup templates
      *
      * MLA versions before 2.40 will not have separate 'attributes' and 'content' elements,
      * but version 2.3x must "go both ways" to allow for reversions.
      */
     $templates = MLACore::mla_get_option('style_templates');
     if (is_array($templates)) {
         foreach ($templates as $name => $value) {
             // Check for 2.40+ format
             if (is_array($value)) {
                 $attributes = $value['attributes'];
                 MLATemplate_Support::$mla_custom_templates['style'][$attributes['mla_shortcode_slug']][$name] = $value['content'];
                 continue;
             }
             // Check for explicit assignment
             $match_count = preg_match('#\\<!-- mla_shortcode_slug="(.+)" --\\>[\\r\\n]*#', $value, $matches, PREG_OFFSET_CAPTURE);
             if ($match_count > 0) {
                 //error_log( __LINE__ . " default template {$name} matches = " . var_export( $matches, true ), 0 );
                 $value = substr_replace($value, '', $matches[0][1], strlen($matches[0][0]));
                 //error_log( __LINE__ . " replace default template {$name} value = " . MLAData::mla_hex_dump( $value ), 0 );
                 MLATemplate_Support::$mla_custom_templates['style'][$matches[1][0]][$name] = $value;
                 continue;
             }
             // Guess from content
             foreach (MLATemplate_Support::$mla_template_definitions['style'] as $slug => $definition) {
                 if (false !== strpos($value, '.' . $definition['slug'])) {
                     MLATemplate_Support::$mla_custom_templates['style'][$definition['slug']][$name] = $value;
                     $name = NULL;
                     break;
                 }
             }
             if ($name) {
                 MLATemplate_Support::$mla_custom_templates['style']['gallery'][$name] = $value;
             }
         }
         // foreach $templates
     }
     // is_array
     $templates = MLACore::mla_get_option('markup_templates');
     if (is_array($templates)) {
         foreach ($templates as $name => $value) {
             // Check for 2.40+ format
             if (isset($value['attributes'])) {
                 $attributes = $value['attributes'];
                 unset($value['attributes']);
                 MLATemplate_Support::$mla_custom_templates['markup'][$attributes['mla_shortcode_slug']][$name] = $value['content'];
                 continue;
             }
             // Check for explicit assignment
             if (isset($value['arguments'])) {
                 $match_count = preg_match('#mla_shortcode_slug="(.+)"[ \\r\\n]*#', $value['arguments'], $matches, PREG_OFFSET_CAPTURE);
             } else {
                 $match_count = 0;
             }
             if ($match_count > 0) {
                 //error_log( __LINE__ . " user template {$key} matches = " . var_export( $matches, true ), 0 );
                 $value['arguments'] = substr_replace($value['arguments'], '', $matches[0][1], strlen($matches[0][0]));
                 if (empty($value['arguments'])) {
                     //error_log( __LINE__ . " unset user template {$key}", 0 );
                     unset($value['arguments']);
                 } else {
                     //error_log( __LINE__ . " replace user {$key} value = " . MLAData::mla_hex_dump( $value['arguments'] ), 0 );
                 }
                 MLATemplate_Support::$mla_custom_templates['markup'][$matches[1][0]][$name] = $value;
                 continue;
             }
             // Guess from content
             $full_text = '';
             // for guessing shortcode name
             foreach ($value as $section_name => $section_value) {
                 $full_text .= $section_value;
             }
             foreach (MLATemplate_Support::$mla_template_definitions['markup'] as $slug => $definition) {
                 if (preg_match('#class=[\'\\"]*.*' . $definition['slug'] . '#', $full_text, $matches)) {
                     MLATemplate_Support::$mla_custom_templates['markup'][$definition['slug']][$name] = $value;
                     $name = NULL;
                     break;
                 }
             }
             if ($name) {
                 MLATemplate_Support::$mla_custom_templates['markup']['gallery'][$name] = $value;
             }
         }
         // foreach $templates
     }
     // is_array
     //error_log( __LINE__ . ' mla_load_custom_templates MLATemplate_Support::$mla_custom_templates = ' . var_export( MLATemplate_Support::$mla_custom_templates, true ), 0 );
 }
 /**
  * Ajax handler for Media Manager "Query Attachments" queries 
  *
  * Adapted from wp_ajax_query_attachments in /wp-admin/includes/ajax-actions.php
  *
  * @since 2.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, MLACore::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 = MLACore::mla_get_option(MLACoreOptions::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)), MLAQuery::mla_get_sortable_columns());
         $found_current = false;
         foreach ($default_orderby as $key => $value) {
             if ($option == $value[0]) {
                 $found_current = true;
                 break;
             }
         }
         if (!$found_current) {
             MLACore::mla_delete_option(MLACoreOptions::MLA_DEFAULT_ORDERBY);
             $option = MLACore::mla_get_option(MLACoreOptions::MLA_DEFAULT_ORDERBY);
         }
         $query['orderby'] = $option;
     }
     $option = MLACore::mla_get_option(MLACoreOptions::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 = MLAQuery::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);
 }
Ejemplo n.º 19
0
 /**
  * WordPress Filter for edit taxonomy "Attachments" column,
  * which returns a count of the attachments assigned a given term
  *
  * @since 0.30
  *
  * @param	string	current column value; filled in by earlier filter handlers
  * @param	string	name of the column
  * @param	integer	ID of the term for which the count is desired
  *
  * @return	array	HTML markup for the column content; number of attachments in the category
  *					and alink to retrieve a list of them
  */
 public static function mla_taxonomy_column_filter($current_value, $column_name, $term_id)
 {
     static $taxonomy = NULL, $tax_object = NULL, $count_terms = false, $terms = array();
     /*
      * Do setup tasks once per page load
      */
     if (NULL == $taxonomy) {
         /*
          * Adding or inline-editing a tag is done with AJAX, and there's no current screen object
          */
         if (defined('DOING_AJAX') && DOING_AJAX) {
             $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag';
         } else {
             $screen = get_current_screen();
             $taxonomy = !empty($screen->taxonomy) ? $screen->taxonomy : 'post_tag';
         }
     }
     $filter_content = apply_filters('mla_taxonomy_column', NULL, $current_value, $column_name, $term_id, $taxonomy);
     if (!empty($filter_content)) {
         return $filter_content;
     }
     if ('attachments' !== $column_name) {
         return $current_value;
     }
     /*
      * Do setup tasks once per page load
      */
     if (NULL == $tax_object) {
         /*
          * Adding or inline-editing a tag is done with AJAX, and there's no current screen object
          */
         if (defined('DOING_AJAX') && DOING_AJAX) {
             $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag';
         } else {
             $screen = get_current_screen();
             $taxonomy = !empty($screen->taxonomy) ? $screen->taxonomy : 'post_tag';
         }
         $tax_object = get_taxonomy($taxonomy);
         $count_terms = 'checked' == MLACore::mla_get_option(MLACore::MLA_COUNT_TERM_ATTACHMENTS);
         if ($count_terms) {
             $terms = get_transient(MLA_OPTION_PREFIX . 't_term_counts_' . $taxonomy);
             if (!is_array($terms)) {
                 /* 
                  * The MLAShortcodes class is only loaded when needed.
                  */
                 if (!class_exists('MLAShortcodes')) {
                     require_once MLA_PLUGIN_PATH . 'includes/class-mla-shortcodes.php';
                 }
                 $cloud = MLAShortcodes::mla_get_terms(array('taxonomy' => $taxonomy, 'fields' => 't.term_id, t.name, t.slug, COUNT(p.ID) AS `count`', 'number' => 0, 'no_orderby' => true));
                 unset($cloud['found_rows']);
                 foreach ($cloud as $term) {
                     $terms[$term->term_id] = $term;
                 }
                 set_transient(MLA_OPTION_PREFIX . 't_term_counts_' . $taxonomy, $terms, 300);
                 // five minutes
             }
             // build the array
         }
         // set $terms
     }
     // setup tasks
     if (isset($terms[$term_id])) {
         $term = $terms[$term_id];
         $column_text = number_format_i18n($term->count);
     } else {
         $term = get_term($term_id, $taxonomy);
         if (is_wp_error($term)) {
             /* translators: 1: ERROR tag 2: taxonomy 3: error message */
             error_log(sprintf(_x('%1$s: mla_taxonomy_column_filter( "%2$s" ) - get_term failed: "%3$s"', 'error_log', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $taxonomy, $term->get_error_message()), 0);
             return 0;
         } elseif ($count_terms) {
             $column_text = number_format_i18n(0);
         } else {
             $column_text = __('click to search', 'media-library-assistant');
         }
     }
     return sprintf('<a href="%1$s">%2$s</a>', esc_url(add_query_arg(array('page' => MLACore::ADMIN_PAGE_SLUG, 'mla-tax' => $taxonomy, 'mla-term' => $term->slug, 'heading_suffix' => urlencode($tax_object->label . ':' . $term->name)), 'upload.php')), $column_text);
 }
 /**
  * Registers meta boxes for the Edit Media screen.
  * Declared public because it is an action.
  *
  * @since 0.80
  *
  * @param	string	type of the current post, e.g., 'attachment' (optional, default 'unknown') 
  * @param	object	current post (optional, default (object) array ( 'ID' => 0 ))
  *
  * @return	void
  */
 public static function mla_add_meta_boxes_action($post_type = 'unknown', $post = NULL)
 {
     /*
      * Plugins call this action with varying numbers of arguments!
      */
     if (NULL == $post) {
         $post = (object) array('ID' => 0);
     }
     if ('attachment' != $post_type) {
         return;
     }
     /*
      * Use the mla_checklist_meta_box callback function for MLA supported taxonomies
      */
     global $wp_meta_boxes;
     $screen = convert_to_screen('attachment');
     $page = $screen->id;
     if ('checked' == MLACore::mla_get_option(MLACoreOptions::MLA_EDIT_MEDIA_SEARCH_TAXONOMY)) {
         $taxonomies = get_taxonomies(array('show_ui' => true), 'objects');
         foreach ($taxonomies as $key => $value) {
             if (MLACore::mla_taxonomy_support($key)) {
                 if ($value->hierarchical) {
                     foreach (array_keys($wp_meta_boxes[$page]) as $a_context) {
                         foreach (array('high', 'sorted', 'core', 'default', 'low') as $a_priority) {
                             if (isset($wp_meta_boxes[$page][$a_context][$a_priority][$key . 'div'])) {
                                 $box =& $wp_meta_boxes[$page][$a_context][$a_priority][$key . 'div'];
                                 if ('post_categories_meta_box' == $box['callback']) {
                                     $box['callback'] = 'MLACore::mla_checklist_meta_box';
                                 }
                             }
                             // isset $box
                         }
                         // foreach priority
                     }
                     // foreach context
                 } elseif (MLACore::mla_taxonomy_support($key, 'flat-checklist')) {
                     foreach (array_keys($wp_meta_boxes[$page]) as $a_context) {
                         foreach (array('high', 'sorted', 'core', 'default', 'low') as $a_priority) {
                             if (isset($wp_meta_boxes[$page][$a_context][$a_priority]['tagsdiv-' . $key])) {
                                 $box =& $wp_meta_boxes[$page][$a_context][$a_priority]['tagsdiv-' . $key];
                                 if ('post_tags_meta_box' == $box['callback']) {
                                     $box['callback'] = 'MLACore::mla_checklist_meta_box';
                                 }
                             }
                             // isset $box
                         }
                         // foreach priority
                     }
                     // foreach context
                 }
                 // flat checklist
             }
             // is supported
         }
         // foreach
     }
     // MLA_EDIT_MEDIA_SEARCH_TAXONOMY
     if ('checked' == MLACore::mla_get_option(MLACoreOptions::MLA_EDIT_MEDIA_META_BOXES)) {
         $active_boxes = apply_filters('mla_edit_media_meta_boxes', array('mla-parent-info' => 'mla-parent-info', 'mla-menu-order' => 'mla-menu-order', 'mla-image-metadata' => 'mla-image-metadata', 'mla-featured-in' => 'mla-featured-in', 'mla-inserted-in' => 'mla-inserted-in', 'mla-gallery-in' => 'mla-gallery-in', 'mla-mla-gallery-in' => 'mla-mla-gallery-in'));
         if (isset($active_boxes['mla-parent-info'])) {
             add_meta_box('mla-parent-info', __('Parent Info', 'media-library-assistant'), 'MLAEdit::mla_parent_info_handler', 'attachment', 'normal', 'core');
         }
         if (isset($active_boxes['mla-menu-order'])) {
             add_meta_box('mla-menu-order', __('Menu Order', 'media-library-assistant'), 'MLAEdit::mla_menu_order_handler', 'attachment', 'normal', 'core');
         }
         if (isset($active_boxes['mla-image-metadata'])) {
             $image_metadata = get_metadata('post', $post->ID, '_wp_attachment_metadata', true);
             if (!empty($image_metadata)) {
                 add_meta_box('mla-image-metadata', __('Attachment Metadata', 'media-library-assistant'), 'MLAEdit::mla_image_metadata_handler', 'attachment', 'normal', 'core');
             }
         }
         if (isset($active_boxes['mla-featured-in']) && MLACore::$process_featured_in) {
             add_meta_box('mla-featured-in', __('Featured in', 'media-library-assistant'), 'MLAEdit::mla_featured_in_handler', 'attachment', 'normal', 'core');
         }
         if (isset($active_boxes['mla-inserted-in']) && MLACore::$process_inserted_in) {
             add_meta_box('mla-inserted-in', __('Inserted in', 'media-library-assistant'), 'MLAEdit::mla_inserted_in_handler', 'attachment', 'normal', 'core');
         }
         if (isset($active_boxes['mla-gallery-in']) && MLACore::$process_gallery_in) {
             add_meta_box('mla-gallery-in', __('Gallery in', 'media-library-assistant'), 'MLAEdit::mla_gallery_in_handler', 'attachment', 'normal', 'core');
         }
         if (isset($active_boxes['mla-mla-gallery-in']) && MLACore::$process_mla_gallery_in) {
             add_meta_box('mla-mla-gallery-in', __('MLA Gallery in', 'media-library-assistant'), 'MLAEdit::mla_mla_gallery_in_handler', 'attachment', 'normal', 'core');
         }
     }
 }
 /**
  * Computes image dimensions for scalable graphics, e.g., SVG 
  *
  * @since 2.20
  *
  * @return array 
  */
 private static function _registered_dimensions()
 {
     global $_wp_additional_image_sizes;
     if ('checked' == MLACore::mla_get_option(MLACore::MLA_ENABLE_MLA_ICONS)) {
         $sizes = array('icon' => array(64, 64));
     } else {
         $sizes = array('icon' => array(60, 60));
     }
     foreach (get_intermediate_image_sizes() as $s) {
         $sizes[$s] = array(0, 0);
         if (in_array($s, array('thumbnail', 'medium', 'large'))) {
             $sizes[$s][0] = get_option($s . '_size_w');
             $sizes[$s][1] = get_option($s . '_size_h');
         } else {
             if (isset($_wp_additional_image_sizes) && isset($_wp_additional_image_sizes[$s])) {
                 $sizes[$s] = array($_wp_additional_image_sizes[$s]['width'], $_wp_additional_image_sizes[$s]['height']);
             }
         }
     }
     return $sizes;
 }
Ejemplo n.º 22
0
        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
    }
}
// Class MLA_Ajax
/*
 * Check for Media Manager Enhancements
 */
if ('checked' == MLACore::mla_get_option(MLACore::MLA_MEDIA_MODAL_TOOLBAR) || 'checked' == MLACore::mla_get_option(MLACore::MLA_MEDIA_GRID_TOOLBAR)) {
    require_once MLA_PLUGIN_PATH . 'includes/class-mla-media-modal-ajax.php';
    add_action('init', 'MLAModal_Ajax::initialize', 0x7fffffff);
}
Ejemplo n.º 23
0
 /**
  * Returns HTML markup for one view that can be used with this table
  *
  * @since 1.40
  *
  * @param	string	View slug, key to MLA_POST_MIME_TYPES array 
  * @param	string	Slug for current view 
  * 
  * @return	string | false	HTML for link to display the view, false if count = zero
  */
 private static function _get_view($view_slug, $current_view)
 {
     global $wpdb;
     static $mla_types = NULL, $default_types, $posts_per_type, $post_mime_types, $avail_post_mime_types, $matches, $num_posts, $detached_items;
     /*
      * Calculate the common values once per page load
      */
     if (is_null($mla_types)) {
         $query_types = MLAMime::mla_query_view_items(array('orderby' => 'menu_order'), 0, 0);
         if (!is_array($query_types)) {
             $query_types = array();
         }
         $mla_types = array();
         foreach ($query_types as $value) {
             $mla_types[$value->slug] = $value;
         }
         $default_types = MLACore::mla_get_option(MLACore::MLA_POST_MIME_TYPES, true);
         $posts_per_type = (array) wp_count_attachments();
         $post_mime_types = get_post_mime_types();
         $avail_post_mime_types = self::_avail_mime_types($posts_per_type);
         $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($posts_per_type));
         foreach ($matches as $type => $reals) {
             foreach ($reals as $real) {
                 $num_posts[$type] = isset($num_posts[$type]) ? $num_posts[$type] + $posts_per_type[$real] : $posts_per_type[$real];
             }
         }
         $detached_items = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1");
     }
     $class = $view_slug == $current_view ? ' class="current"' : '';
     $base_url = 'upload.php?page=' . MLACore::ADMIN_PAGE_SLUG;
     /*
      * Handle the special cases: all, detached, attached and trash
      */
     switch ($view_slug) {
         case 'all':
             $total_items = array_sum($posts_per_type) - $posts_per_type['trash'];
             return "<a href='{$base_url}'{$class}>" . sprintf(_nx('All', 'All', $total_items, 'uploaded files', 'media-library-assistant') . ' <span class="count">(%1$s)</span></a>', number_format_i18n($total_items));
         case 'detached':
             if ($detached_items) {
                 $value = $default_types['detached'];
                 $singular = sprintf('%s <span class="count">(%%s)</span>', $value['singular']);
                 $plural = sprintf('%s <span class="count">(%%s)</span>', $value['plural']);
                 return '<a href="' . add_query_arg(array('detached' => '1'), $base_url) . '"' . $class . '>' . sprintf(_nx($singular, $plural, $detached_items, 'detached files', 'media-library-assistant'), number_format_i18n($detached_items)) . '</a>';
             }
             return false;
         case 'attached':
             if ($attached_items = array_sum($posts_per_type) - $posts_per_type['trash'] - $detached_items) {
                 $value = $default_types['attached'];
                 $singular = sprintf('%s <span class="count">(%%s)</span>', $value['singular']);
                 $plural = sprintf('%s <span class="count">(%%s)</span>', $value['plural']);
                 return '<a href="' . add_query_arg(array('detached' => '0'), $base_url) . '"' . $class . '>' . sprintf(_nx($singular, $plural, $attached_items, 'attached files', 'media-library-assistant'), number_format_i18n($attached_items)) . '</a>';
             }
             return false;
         case 'trash':
             if ($posts_per_type['trash']) {
                 $value = $default_types['trash'];
                 $singular = sprintf('%s <span class="count">(%%s)</span>', $value['singular']);
                 $plural = sprintf('%s <span class="count">(%%s)</span>', $value['plural']);
                 return '<a href="' . add_query_arg(array('status' => 'trash'), $base_url) . '"' . $class . '>' . sprintf(_nx($singular, $plural, $posts_per_type['trash'], 'uploaded files', 'media-library-assistant'), number_format_i18n($posts_per_type['trash'])) . '</a>';
             }
             return false;
     }
     // switch special cases
     /*
      * Make sure the slug is in our list
      */
     if (array_key_exists($view_slug, $mla_types)) {
         $mla_type = $mla_types[$view_slug];
     } else {
         return false;
     }
     /*
      * Handle post_mime_types
      */
     if ($mla_type->post_mime_type) {
         if (!empty($num_posts[$view_slug])) {
             return "<a href='" . add_query_arg(array('post_mime_type' => $view_slug), $base_url) . "'{$class}>" . sprintf(translate_nooped_plural($post_mime_types[$view_slug][2], $num_posts[$view_slug], 'media-library-assistant'), number_format_i18n($num_posts[$view_slug])) . '</a>';
         }
         return false;
     }
     /*
      * Handle extended specification types
      */
     if (empty($mla_type->specification)) {
         $query = array('post_mime_type' => $view_slug);
     } else {
         $query = MLACore::mla_prepare_view_query($view_slug, $mla_type->specification);
     }
     $total_items = MLAQuery::mla_count_list_table_items($query);
     if ($total_items) {
         $singular = sprintf('%s <span class="count">(%%s)</span>', $mla_type->singular);
         $plural = sprintf('%s <span class="count">(%%s)</span>', $mla_type->plural);
         $nooped_plural = _n_noop($singular, $plural, 'media-library-assistant');
         if (isset($query['post_mime_type'])) {
             $query['post_mime_type'] = urlencode($query['post_mime_type']);
         } else {
             $query['meta_slug'] = $view_slug;
             $query['meta_query'] = urlencode(serialize($query['meta_query']));
         }
         return "<a href='" . add_query_arg($query, $base_url) . "'{$class}>" . sprintf(translate_nooped_plural($nooped_plural, $total_items, 'media-library-assistant'), number_format_i18n($total_items)) . '</a>';
     }
     return false;
 }