コード例 #1
0
ファイル: class-mla-ajax.php プロジェクト: jonpetersen/PHTC
 /**
  * Ajax handler to set post_parent for a single attachment
  *
  * Adapted from wp_ajax_inline_save in /wp-admin/includes/ajax-actions.php
  *
  * @since 0.20
  *
  * @return	void	echo HTML <td> innerHTML for updated call or error message, then die()
  */
 public static function mla_set_parent_ajax_action()
 {
     check_ajax_referer(MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME);
     if (empty($_REQUEST['post_ID'])) {
         echo __('ERROR', 'media-library-assistant') . ': ' . __('No post ID found', 'media-library-assistant');
         die;
     } else {
         $post_id = $_REQUEST['post_ID'];
     }
     if (!current_user_can('edit_post', $post_id)) {
         wp_die(__('ERROR', 'media-library-assistant') . ': ' . __('You are not allowed to edit this Attachment.', 'media-library-assistant'));
     }
     if (!class_exists('MLAData')) {
         require_once MLA_PLUGIN_PATH . 'includes/class-mla-data.php';
         MLAData::initialize();
     }
     $results = MLAData::mla_update_single_item($post_id, $_REQUEST);
     if (false !== strpos($results['message'], __('ERROR', 'media-library-assistant'))) {
         wp_die($results['message']);
     }
     $new_item = (object) MLAData::mla_get_attachment_by_id($post_id);
     if (!class_exists('MLA_List_Table')) {
         require_once MLA_PLUGIN_PATH . 'includes/class-mla-list-table.php';
         MLA_List_Table::mla_admin_init_action();
     }
     //	Create an instance of our package class and echo the new HTML
     $MLAListTable = apply_filters('mla_list_table_new_instance', NULL);
     if (is_null($MLAListTable)) {
         $MLAListTable = new MLA_List_Table();
     }
     $MLAListTable->single_row($new_item);
     die;
     // this is required to return a proper result
 }
コード例 #2
0
 /**
  * Filters taxonomy updates by language for Bulk Edit during Add New Media
  * and the Media/Edit Media screen
  *
  * @since 2.11
  *
  * @param	integer	ID of the current post
  */
 public static function edit_attachment($post_id)
 {
     static $already_updating = 0;
     /*
      * mla_update_single_item eventually calls this action again
      */
     if ($already_updating == $post_id) {
         return;
     } else {
         $already_updating = $post_id;
     }
     /*
      * Check for Bulk Edit during Add New Media
      */
     if (is_array(self::$upload_bulk_edit_args)) {
         if (!empty(self::$upload_bulk_edit_args['tax_input'])) {
             $tax_inputs = self::$upload_bulk_edit_args['tax_input'];
             if ('checked' == MLAOptions::mla_get_option('term_assignment', false, false, MLA_WPML::$mla_language_option_definitions)) {
                 self::_build_tax_input($post_id, $tax_inputs, self::$upload_bulk_edit_args['tax_action']);
                 $tax_inputs = self::_apply_tax_input($post_id);
             }
         } else {
             $tax_inputs = NULL;
         }
         $updates = MLA::mla_prepare_bulk_edits($post_id, self::$upload_bulk_edit_args, self::$upload_bulk_edit_map);
         unset($updates['tax_input']);
         unset($updates['tax_action']);
         MLAData::mla_update_single_item($post_id, $updates, $tax_inputs);
         /*
          * Synchronize the changes to all other translations - NOT NEEDED
          */
         if (false && 'checked' == MLAOptions::mla_get_option('term_synchronization', false, false, MLA_WPML::$mla_language_option_definitions)) {
             foreach (self::$tax_input as $language => $tax_inputs) {
                 /*
                  * Skip 'tax_input_post_id' and the language we've already updated
                  */
                 if (!isset(self::$existing_terms[$language]) || self::$existing_terms['language_code'] == $language) {
                     continue;
                 }
                 // Other translations have no existing terms, so we don't need _apply_synch_input()
                 $translation = self::$existing_terms[$language];
                 $tax_inputs = self::_apply_tax_input($translation['element_id'], $language);
                 $already_updating = $translation['element_id'];
                 // prevent recursion
                 MLAData::mla_update_single_item($translation['element_id'], $updates, $tax_inputs);
                 $already_updating = $post_id;
             }
             // translation
         }
         // do synchronization
         return;
     }
     // Upload New Media Bulk Edit
     /*
      * For the Bulk Edit action on the Media/Assistant screen, only synchronization is needed
      */
     if (!(isset($_REQUEST['bulk_action']) && 'bulk_edit' == $_REQUEST['bulk_action'])) {
         /*
          * The category taxonomy (edit screens) is a special case because 
          * post_categories_meta_box() changes the input name
          */
         if (isset($_REQUEST['tax_input'])) {
             $tax_inputs = $_REQUEST['tax_input'];
         } else {
             $tax_inputs = array();
         }
         if (isset($_REQUEST['post_category'])) {
             $tax_inputs['category'] = $_REQUEST['post_category'];
         }
         if (isset($_REQUEST['tax_action'])) {
             $tax_actions = $_REQUEST['tax_action'];
         } else {
             $tax_actions = NULL;
         }
         if (!empty($tax_inputs) && 'checked' == MLAOptions::mla_get_option('term_assignment', false, false, MLA_WPML::$mla_language_option_definitions)) {
             self::_build_tax_input($post_id, $tax_inputs, $tax_actions);
             $tax_inputs = self::_apply_tax_input($post_id);
         }
         if (!empty($tax_inputs)) {
             MLAData::mla_update_single_item($post_id, array(), $tax_inputs);
         }
     }
     // NOT Bulk Edit
     /*
      * Synchronize the changes to all other translations
      */
     if ('checked' == MLAOptions::mla_get_option('term_synchronization', false, false, MLA_WPML::$mla_language_option_definitions)) {
         /*
          * Update terms because they have changed
          */
         $terms_before = self::_update_existing_terms($post_id);
         // $tax_input is a convenient source of language codes; ignore $tax_inputs
         foreach (self::$tax_input as $language => $tax_inputs) {
             /*
              * Skip 'tax_input_post_id' and the language we've already updated
              */
             if (!isset(self::$existing_terms[$language]) || self::$existing_terms['language_code'] == $language) {
                 continue;
             }
             $tax_inputs = self::_apply_synch_input($language);
             if (!empty($tax_inputs)) {
                 $translation = self::$existing_terms[$language]['element_id'];
                 $already_updating = $translation;
                 // prevent recursion
                 MLAData::mla_update_single_item($translation, array(), $tax_inputs);
                 $already_updating = $post_id;
             }
         }
         // translation
     }
     // do synchronization
 }
コード例 #3
0
 /**
  * Filters taxonomy updates by language for Bulk Edit during Add New Media
  * and the Media/Edit Media screen
  *
  * @since 2.11
  *
  * @param	integer	ID of the current post
  */
 public static function edit_attachment($post_id)
 {
     static $already_updating = 0;
     MLACore::mla_debug_add(__LINE__ . " MLA_WPML::edit_attachment( {$post_id} ) _REQUEST = " . var_export($_REQUEST, true), MLACore::MLA_DEBUG_CATEGORY_LANGUAGE);
     /*
      * mla_update_single_item may call this action again, and
      * nothing should happen while updating duplicate items
      */
     if ($already_updating == $post_id || self::$updating_duplicates) {
         return;
     } else {
         $already_updating = $post_id;
     }
     /*
      * Check for Bulk Edit during Add New Media
      */
     if (!empty($_REQUEST['mlaAddNewBulkEditFormString'])) {
         if (!empty(self::$bulk_edit_request['tax_input'])) {
             $tax_inputs = self::$bulk_edit_request['tax_input'];
             if ('checked' == MLACore::mla_get_option('term_assignment', false, false, MLA_WPML::$mla_language_option_definitions)) {
                 self::_build_tax_input($post_id, $tax_inputs, self::$bulk_edit_request['tax_action']);
                 $tax_inputs = self::_apply_tax_input($post_id);
             }
         } else {
             $tax_inputs = NULL;
         }
         $updates = MLA::mla_prepare_bulk_edits($post_id, self::$bulk_edit_request, self::$bulk_edit_map);
         unset($updates['tax_input']);
         unset($updates['tax_action']);
         MLAData::mla_update_single_item($post_id, $updates, $tax_inputs);
         return;
     }
     // Upload New Media Bulk Edit
     /*
      * For the Bulk Edit action on the Media/Assistant screen, only synchronization is needed
      */
     if (!(isset($_REQUEST['bulk_action']) && 'bulk_edit' == $_REQUEST['bulk_action'])) {
         /*
          * This is the Media/Edit Media screen.
          * The category taxonomy (edit screens) is a special case because 
          * post_categories_meta_box() changes the input name
          */
         if (isset($_REQUEST['tax_input'])) {
             $tax_inputs = $_REQUEST['tax_input'];
         } else {
             $tax_inputs = array();
         }
         if (isset($_REQUEST['post_category'])) {
             $tax_inputs['category'] = $_REQUEST['post_category'];
         }
         if (isset($_REQUEST['tax_action'])) {
             $tax_actions = $_REQUEST['tax_action'];
         } else {
             $tax_actions = NULL;
         }
         if (!empty($tax_inputs) && 'checked' == MLACore::mla_get_option('term_assignment', false, false, MLA_WPML::$mla_language_option_definitions)) {
             self::_build_tax_input($post_id, $tax_inputs, $tax_actions);
             $tax_inputs = self::_apply_tax_input($post_id);
         }
         if (!empty($tax_inputs)) {
             MLAData::mla_update_single_item($post_id, array(), $tax_inputs);
         }
     }
     // Media/Edit Media screen, NOT Bulk Edit
 }
コード例 #4
0
 /**
  * Ajax handler for inline editing
  *
  * Adapted for Quick Edit from wp_ajax_inline_save in /wp-admin/includes/ajax-actions.php
  *
  * @since 0.20
  *
  * @return	void	echo HTML <tr> markup for updated row or error message, then die()
  */
 public static function mla_inline_edit_ajax_action()
 {
     set_current_screen($_REQUEST['screen']);
     check_ajax_referer(self::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME);
     if (!empty($_REQUEST['bulk_action'])) {
         self::_bulk_edit_ajax_handler();
         // calls wp_send_json_success and die()
     }
     if (empty($_REQUEST['post_ID'])) {
         echo __('ERROR', 'media-library-assistant') . ': ' . __('No post ID found', 'media-library-assistant');
         die;
     } else {
         $post_id = $_REQUEST['post_ID'];
     }
     if (!current_user_can('edit_post', $post_id)) {
         wp_die(__('ERROR', 'media-library-assistant') . ': ' . __('You are not allowed to edit this Attachment.', 'media-library-assistant'));
     }
     /*
      * Custom field support
      */
     $custom_fields = array();
     foreach (MLAOptions::mla_custom_field_support('quick_edit') as $slug => $details) {
         if (isset($_REQUEST[$slug])) {
             $value = trim($_REQUEST[$slug]);
             unset($_REQUEST[$slug]);
             if ($details['no_null'] && empty($value)) {
                 $custom_fields[$details['name']] = NULL;
             } else {
                 $custom_fields[$details['name']] = $value;
             }
         }
     }
     if (!empty($custom_fields)) {
         $_REQUEST['custom_updates'] = $custom_fields;
     }
     /*
      * The category taxonomy is a special case because post_categories_meta_box() changes the input name
      */
     if (!isset($_REQUEST['tax_input'])) {
         $_REQUEST['tax_input'] = array();
     }
     if (isset($_REQUEST['post_category'])) {
         $_REQUEST['tax_input']['category'] = $_REQUEST['post_category'];
         unset($_REQUEST['post_category']);
     }
     if (!empty($_REQUEST['tax_input'])) {
         /*
          * Flat taxonomy strings must be cleaned up and duplicates removed
          */
         $tax_output = array();
         foreach ($_REQUEST['tax_input'] as $tax_name => $tax_value) {
             if (!is_array($tax_value)) {
                 $comma = _x(',', 'tag_delimiter', 'media-library-assistant');
                 if (',' != $comma) {
                     $tax_value = str_replace($comma, ',', $tax_value);
                 }
                 $tax_value = preg_replace('#\\s*,\\s*#', ',', $tax_value);
                 $tax_value = preg_replace('#,+#', ',', $tax_value);
                 $tax_value = preg_replace('#[,\\s]+$#', '', $tax_value);
                 $tax_value = preg_replace('#^[,\\s]+#', '', $tax_value);
                 if (',' != $comma) {
                     $tax_value = str_replace(',', $comma, $tax_value);
                 }
                 $tax_array = array();
                 $dedup_array = explode($comma, $tax_value);
                 foreach ($dedup_array as $tax_value) {
                     $tax_array[$tax_value] = $tax_value;
                 }
                 $tax_value = implode($comma, $tax_array);
             }
             // ! array( $tax_value )
             $tax_output[$tax_name] = $tax_value;
         }
         // foreach tax_input
         $_REQUEST['tax_input'] = $tax_output;
     }
     // ! empty( $_REQUEST['tax_input'] )
     $item_content = apply_filters('mla_list_table_inline_action', NULL, $post_id);
     if (is_null($item_content)) {
         $prevent_default = false;
         $custom_message = '';
     } else {
         $prevent_default = isset($item_content['prevent_default']) ? $item_content['prevent_default'] : false;
         $custom_message = isset($item_content['message']) ? $page_content['message'] : '';
     }
     if (!$prevent_default) {
         $results = MLAData::mla_update_single_item($post_id, $_REQUEST, $_REQUEST['tax_input']);
     }
     $new_item = (object) MLAData::mla_get_attachment_by_id($post_id);
     //	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
 }
コード例 #5
0
 /**
  * Saves updates from the Edit Media screen.
  * Declared public because it is an action.
  *
  * @since 0.80
  *
  * @param	integer	ID of the current post
  *
  * @return	void
  */
 public static function mla_edit_attachment_action($post_ID)
 {
     $new_data = array();
     if (isset($_REQUEST['mla_post_parent'])) {
         $new_data['post_parent'] = $_REQUEST['mla_post_parent'];
     }
     if (isset($_REQUEST['mla_menu_order'])) {
         $new_data['menu_order'] = $_REQUEST['mla_menu_order'];
     }
     if (!empty($new_data)) {
         MLAData::mla_update_single_item($post_ID, $new_data);
     }
 }
コード例 #6
0
 /**
  * Perform IPTC/EXIF and Custom Field mapping on just-inserted attachment
  *
  * This filter tests the $add_attachment_id variable set by the mla_add_attachment_action
  * to ensure that mapping is only performed for new additions, not metadata updates.
  *
  * @since 1.10
  *
  * @param	array	Attachment metadata for just-inserted attachment
  * @param	integer	ID of just-inserted attachment
  *
  * @return	array	Updated attachment metadata
  */
 public static function mla_update_attachment_metadata_filter($data, $post_id)
 {
     $options = array();
     $options['is_upload'] = MLAOptions::$add_attachment_id == $post_id;
     MLAOptions::$add_attachment_id = 0;
     $options['enable_iptc_exif_mapping'] = 'checked' == MLACore::mla_get_option('enable_iptc_exif_mapping');
     $options['enable_custom_field_mapping'] = 'checked' == MLACore::mla_get_option('enable_custom_field_mapping');
     $options['enable_iptc_exif_update'] = 'checked' == MLACore::mla_get_option('enable_iptc_exif_update');
     $options['enable_custom_field_update'] = 'checked' == MLACore::mla_get_option('enable_custom_field_update');
     $options = apply_filters('mla_update_attachment_metadata_options', $options, $data, $post_id);
     $data = apply_filters('mla_update_attachment_metadata_prefilter', $data, $post_id, $options);
     if ($options['is_upload']) {
         if ($options['enable_iptc_exif_mapping'] || $options['enable_custom_field_mapping']) {
             do_action('mla_begin_mapping', 'create_metadata', $post_id);
         }
         if ($options['enable_iptc_exif_mapping']) {
             $item = get_post($post_id);
             $updates = MLAOptions::mla_evaluate_iptc_exif_mapping($item, 'iptc_exif_mapping', NULL, $data, true);
             $updates = MLAOptions::_update_attachment_metadata($updates, $data);
             if (!empty($updates)) {
                 $item_content = MLAData::mla_update_single_item($post_id, $updates);
             }
         }
         if ($options['enable_custom_field_mapping']) {
             $updates = MLAOptions::mla_evaluate_custom_field_mapping($post_id, 'single_attachment_mapping', NULL, $data);
             $updates = MLAOptions::_update_attachment_metadata($updates, $data);
             if (!empty($updates)) {
                 $item_content = MLAData::mla_update_single_item($post_id, $updates);
             }
         }
         if ($options['enable_iptc_exif_mapping'] || $options['enable_custom_field_mapping']) {
             do_action('mla_end_mapping');
         }
     } else {
         if ($options['enable_iptc_exif_update'] || $options['enable_custom_field_update']) {
             do_action('mla_begin_mapping', 'update_metadata', $post_id);
         }
         if ($options['enable_iptc_exif_update']) {
             $item = get_post($post_id);
             $updates = MLAOptions::mla_evaluate_iptc_exif_mapping($item, 'iptc_exif_mapping', NULL, $data);
             $updates = MLAOptions::_update_attachment_metadata($updates, $data);
             if (!empty($updates)) {
                 $item_content = MLAData::mla_update_single_item($post_id, $updates);
             }
         }
         if ($options['enable_custom_field_update']) {
             $updates = MLAOptions::mla_evaluate_custom_field_mapping($post_id, 'single_attachment_mapping', NULL, $data);
             $updates = MLAOptions::_update_attachment_metadata($updates, $data);
             if (!empty($updates)) {
                 $item_content = MLAData::mla_update_single_item($post_id, $updates);
             }
         }
         if ($options['enable_iptc_exif_update'] || $options['enable_custom_field_update']) {
             do_action('mla_end_mapping');
         }
     }
     $data = apply_filters('mla_update_attachment_metadata_postfilter', $data, $post_id, $options);
     return $data;
 }
コード例 #7
0
 /**
  * Ajax handler for inline editing (quick and bulk edit)
  *
  * Adapted from wp_ajax_inline_save in /wp-admin/includes/ajax-actions.php
  *
  * @since 0.20
  *
  * @return	void	echo HTML <tr> markup for updated row or error message, then die()
  */
 public static function mla_inline_edit_action()
 {
     set_current_screen($_REQUEST['screen']);
     check_ajax_referer(self::MLA_ADMIN_NONCE, 'nonce');
     if (empty($_REQUEST['post_ID'])) {
         echo 'Error: no post ID found';
         die;
     } else {
         $post_id = $_REQUEST['post_ID'];
     }
     if (!current_user_can('edit_post', $post_id)) {
         wp_die(__('You are not allowed to edit this Attachment.'));
     }
     /*
      * Custom field support
      */
     $custom_fields = array();
     foreach (MLAOptions::mla_custom_field_support('quick_edit') as $slug => $label) {
         if (isset($_REQUEST[$slug])) {
             $custom_fields[$label] = $_REQUEST[$slug];
             unset($_REQUEST[$slug]);
         }
     }
     if (!empty($custom_fields)) {
         $_REQUEST['custom_updates'] = $custom_fields;
     }
     /*
      * The category taxonomy is a special case because post_categories_meta_box() changes the input name
      */
     if (!isset($_REQUEST['tax_input'])) {
         $_REQUEST['tax_input'] = array();
     }
     if (isset($_REQUEST['post_category'])) {
         $_REQUEST['tax_input']['category'] = $_REQUEST['post_category'];
         unset($_REQUEST['post_category']);
     }
     if (!empty($_REQUEST['tax_input'])) {
         /*
          * Flat taxonomy strings must be cleaned up and duplicates removed
          */
         $tax_output = array();
         $tax_input = $_REQUEST['tax_input'];
         foreach ($tax_input as $tax_name => $tax_value) {
             if (!is_array($tax_value)) {
                 $comma = _x(',', 'tag delimiter');
                 if (',' != $comma) {
                     $tax_value = str_replace($comma, ',', $tax_value);
                 }
                 $tax_value = preg_replace('#\\s*,\\s*#', ',', $tax_value);
                 $tax_value = preg_replace('#,+#', ',', $tax_value);
                 $tax_value = preg_replace('#[,\\s]+$#', '', $tax_value);
                 $tax_value = preg_replace('#^[,\\s]+#', '', $tax_value);
                 if (',' != $comma) {
                     $tax_value = str_replace(',', $comma, $tax_value);
                 }
                 $tax_array = array();
                 $dedup_array = explode($comma, $tax_value);
                 foreach ($dedup_array as $tax_value) {
                     $tax_array[$tax_value] = $tax_value;
                 }
                 $tax_value = implode($comma, $tax_array);
             }
             // ! array( $tax_value )
             $tax_output[$tax_name] = $tax_value;
         }
         // foreach $tax_input
     } else {
         $tax_output = NULL;
     }
     $results = MLAData::mla_update_single_item($post_id, $_REQUEST, $tax_output);
     $new_item = (object) MLAData::mla_get_attachment_by_id($post_id);
     //	Create an instance of our package class and echo the new HTML
     $MLAListTable = new MLA_List_Table();
     $MLAListTable->single_row($new_item);
     die;
     // this is required to return a proper result
 }
コード例 #8
0
 /**
  * Process IPTC/EXIF custom field settings against all image attachments
  * without saving the settings to the mla_option
  *
  * @since 1.00
  *
  * @uses $_REQUEST if passed a NULL parameter
  *
  * @param	array | NULL	specific iptc_exif_custom_mapping values 
  * @param	integer			offset for chunk mapping 
  * @param	integer			length for chunk mapping
  *
  * @return	array	Message(s) reflecting the results of the operation
  */
 private static function _process_iptc_exif_custom($settings = NULL, $offset = 0, $length = 0)
 {
     if (NULL == $settings) {
         $source = 'iptc_exif_custom';
         $settings = isset($_REQUEST['iptc_exif_mapping']) ? stripslashes_deep($_REQUEST['iptc_exif_mapping']) : array();
         if (isset($settings['custom'][MLAOptions::MLA_NEW_CUSTOM_FIELD])) {
             unset($settings['custom'][MLAOptions::MLA_NEW_CUSTOM_FIELD]);
         }
         if (isset($settings['custom'][MLAOptions::MLA_NEW_CUSTOM_RULE])) {
             unset($settings['custom'][MLAOptions::MLA_NEW_CUSTOM_RULE]);
         }
     } else {
         $source = 'iptc_exif_custom_rule';
         $settings = stripslashes_deep($settings);
     }
     if (empty($settings['custom'])) {
         return array('message' => sprintf(__('%1$s: No %2$s settings to process.', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), __('Custom field', 'media-library-assistant')), 'body' => '');
     }
     $examine_count = 0;
     $update_count = 0;
     $query = array('orderby' => 'none', 'post_parent' => 'all', 'post_mime_type' => 'image,application/*pdf*');
     if ($length > 0) {
         $query['numberposts'] = $length;
         $query['offset'] = $offset;
     }
     $posts = MLAShortcodes::mla_get_shortcode_attachments(0, $query);
     if (is_string($posts)) {
         return array('message' => $posts, 'body' => '');
     }
     do_action('mla_begin_mapping', $source, NULL);
     foreach ($posts as $key => $post) {
         $updates = MLAOptions::mla_evaluate_iptc_exif_mapping($post, 'iptc_exif_custom_mapping', $settings);
         $examine_count += 1;
         if (!empty($updates)) {
             $results = MLAData::mla_update_single_item($post->ID, $updates);
             if (stripos($results['message'], __('updated.', 'media-library-assistant'))) {
                 $update_count += 1;
             }
         }
     }
     // foreach post
     do_action('mla_end_mapping');
     if ($update_count) {
         /* translators: 1: field type 2: examined count 3: updated count */
         $message = sprintf(__('%1$s mapping completed; %2$d attachment(s) examined, %3$d updated.'), 'IPTC/EXIF ' . __('Custom field', 'media-library-assistant'), $examine_count, $update_count) . "\r\n";
     } else {
         /* translators: 1: field type 2: examined count */
         $message = sprintf(__('%1$s mapping completed; %2$d attachment(s) examined, no changes detected.'), 'IPTC/EXIF ' . __('Custom field', 'media-library-assistant'), $examine_count) . "\r\n";
     }
     return array('message' => $message, 'body' => '', 'processed' => $examine_count, 'unchanged' => $examine_count - $update_count, 'success' => $update_count);
 }
コード例 #9
0
 /**
  * Process IPTC/EXIF custom field settings against all image attachments
  * without saving the settings to the mla_option
  *
  * @since 1.00
  *
  * @uses $_REQUEST if passed a NULL parameter
  *
  * @param	array | NULL	specific iptc_exif_custom_mapping values 
  *
  * @return	array	Message(s) reflecting the results of the operation
  */
 private static function _process_iptc_exif_custom($settings = NULL)
 {
     if (NULL == $settings) {
         $settings = isset($_REQUEST['iptc_exif_mapping']) ? $_REQUEST['iptc_exif_mapping'] : array();
         if (isset($settings['custom'][MLAOptions::MLA_NEW_CUSTOM_FIELD])) {
             unset($settings['custom'][MLAOptions::MLA_NEW_CUSTOM_FIELD]);
         }
         if (isset($settings['custom'][MLAOptions::MLA_NEW_CUSTOM_RULE])) {
             unset($settings['custom'][MLAOptions::MLA_NEW_CUSTOM_RULE]);
         }
     }
     if (empty($settings['custom'])) {
         return array('message' => 'ERROR: No custom field settings to process.', 'body' => '');
     }
     $examine_count = 0;
     $update_count = 0;
     //		$query = array( 'orderby' => 'none', 'post_parent' => 'all' ); // , 'post_mime_type' => 'image' );
     //		$query = array( 'orderby' => 'none', 'post_parent' => 'all', 'post_mime_type' => 'application/*pdf*' );
     $query = array('orderby' => 'none', 'post_parent' => 'all', 'post_mime_type' => 'image,application/*pdf*');
     $posts = MLAShortcodes::mla_get_shortcode_attachments(0, $query);
     if (is_string($posts)) {
         return array('message' => $posts, 'body' => '');
     }
     foreach ($posts as $key => $post) {
         $updates = MLAOptions::mla_evaluate_iptc_exif_mapping($post, 'iptc_exif_custom_mapping', $settings);
         $examine_count += 1;
         if (!empty($updates)) {
             $results = MLAData::mla_update_single_item($post->ID, $updates);
             if (stripos($results['message'], 'updated.')) {
                 $update_count += 1;
             }
         }
     }
     // foreach post
     if ($update_count) {
         $message = "IPTC/EXIF custom field mapping completed; {$examine_count} attachment(s) examined, {$update_count} updated.\r\n";
     } else {
         $message = "IPTC/EXIF custom field mapping completed; {$examine_count} attachment(s) examined, no changes detected.\r\n";
     }
     return array('message' => $message, 'body' => '');
 }
コード例 #10
0
 /**
  * Perform Custom Field mapping on just-inserted or updated attachment
  *
  * @since 1.10
  *
  * @param	array	Attachment metadata for just-inserted attachment
  * @param	integer	ID of just-inserted attachment
  *
  * @return	void
  */
 public static function mla_update_attachment_metadata_filter($data, $post_id)
 {
     if ('checked' == MLAOptions::mla_get_option('enable_custom_field_mapping')) {
         $updates = MLAOptions::mla_evaluate_custom_field_mapping($post_id, 'single_attachment_mapping', NULL, $data);
         if (!empty($updates)) {
             $item_content = MLAData::mla_update_single_item($post_id, $updates);
         }
     }
     return $data;
 }