예제 #1
0
 /**
  * Ajax handler to set post_parent for a single attachment
  *
  * Adapted from wp_ajax_inline_save in /wp-admin/includes/ajax-actions.php
  *
  * @since 0.20
  *
  * @return	void	echo HTML <td> innerHTML for updated call or error message, then die()
  */
 public static function mla_set_parent_ajax_action()
 {
     check_ajax_referer(MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME);
     if (empty($_REQUEST['post_ID'])) {
         echo __('ERROR', 'media-library-assistant') . ': ' . __('No post ID found', 'media-library-assistant');
         die;
     } else {
         $post_id = $_REQUEST['post_ID'];
     }
     if (!current_user_can('edit_post', $post_id)) {
         wp_die(__('ERROR', 'media-library-assistant') . ': ' . __('You are not allowed to edit this Attachment.', 'media-library-assistant'));
     }
     if (!class_exists('MLAData')) {
         require_once MLA_PLUGIN_PATH . 'includes/class-mla-data.php';
         MLAData::initialize();
     }
     $results = MLAData::mla_update_single_item($post_id, $_REQUEST);
     if (false !== strpos($results['message'], __('ERROR', 'media-library-assistant'))) {
         wp_die($results['message']);
     }
     $new_item = (object) MLAData::mla_get_attachment_by_id($post_id);
     if (!class_exists('MLA_List_Table')) {
         require_once MLA_PLUGIN_PATH . 'includes/class-mla-list-table.php';
         MLA_List_Table::mla_admin_init_action();
     }
     //	Create an instance of our package class and echo the new HTML
     $MLAListTable = apply_filters('mla_list_table_new_instance', NULL);
     if (is_null($MLAListTable)) {
         $MLAListTable = new MLA_List_Table();
     }
     $MLAListTable->single_row($new_item);
     die;
     // this is required to return a proper result
 }
예제 #2
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
 }
 /**
  * Ajax handler to Quick Translate a single attachment
  *
  * @since 2.11
  *
  * @return	void	echo HTML <td> innerHTML for updated call or error message, then die()
  */
 public static function quick_translate()
 {
     global $polylang;
     check_ajax_referer(MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME);
     if (empty($_REQUEST['post_ID'])) {
         echo __('ERROR: No post ID found', 'media-library-assistant');
         die;
     } else {
         $post_id = (int) $_REQUEST['post_ID'];
     }
     if (!current_user_can('edit_post', $post_id)) {
         wp_die(__('You are not allowed to edit this Attachment.', 'media-library-assistant'));
     }
     self::_build_existing_terms($post_id);
     /*
      * pll_quick_language is used by the translation status links; edit or add the selected translation
      * inline_lang_choice is the value of the Language dropdown control; change the value of the current item
      */
     if (!empty($_REQUEST['pll_quick_language'])) {
         $new_id = MLA_Polylang::_get_translation($post_id, $_REQUEST['pll_quick_language']);
     } else {
         $new_id = $post_id;
         // Language dropdown in Quick Edit area
         if (isset($_REQUEST['inline_lang_choice'])) {
             $translations = $polylang->model->get_translations('post', $post_id);
             if (!array_key_exists($_REQUEST['inline_lang_choice'], $translations)) {
                 $post = get_post($post_id);
                 // save_post() does a check_admin_referer() security test
                 $_REQUEST['_inline_edit'] = wp_create_nonce('inlineeditnonce');
                 $polylang->filters_post->save_post($post_id, $post, true);
                 if ('checked' == MLAOptions::mla_get_option('term_assignment', false, false, MLA_Polylang::$mla_language_option_definitions)) {
                     // Record new language for Term Assignment and Synchronization
                     if (!empty($_REQUEST['tax_input'])) {
                         // Discard the old translation, which is gone
                         unset(self::$existing_terms[self::$existing_terms['slug']]);
                         self::$existing_terms['slug'] = $_REQUEST['inline_lang_choice'];
                     }
                     self::_build_existing_terms($post_id);
                     self::_build_tax_input($post_id);
                     $tax_inputs = self::_apply_tax_input(0, $_REQUEST['inline_lang_choice']);
                 } else {
                     $tax_inputs = NULL;
                 }
                 if (!empty($tax_inputs)) {
                     MLAData::mla_update_single_item($post_id, array(), $tax_inputs);
                 }
             }
             // change language
         }
     }
     //	Create an instance of our package class and echo the new HTML for all translations
     $translations = $polylang->model->get_translations('post', $post_id);
     $MLAListTable = new MLA_List_Table();
     $new_item = (object) MLAData::mla_get_attachment_by_id($new_id);
     $MLAListTable->single_row($new_item);
     foreach ($translations as $language => $post_id) {
         if ($new_id == $post_id) {
             continue;
         }
         $new_item = (object) MLAData::mla_get_attachment_by_id($post_id);
         $MLAListTable->single_row($new_item);
         echo "\n";
     }
     die;
     // this is required to return a proper result
 }
예제 #4
0
 /**
  * Display a single item sub page; prepare the form to 
  * change the meta data for a single attachment.
  * 
  * This function is not used in WordPress 3.5 and later.
  *
  * @since 0.1
  * 
  * @param	int		The WordPress Post ID of the attachment item
  *
  * @return	array	message and/or HTML content
  */
 private static function _display_single_item($post_id)
 {
     global $post;
     /*
      * This function sets the global $post
      */
     $post_data = MLAData::mla_get_attachment_by_id($post_id);
     if (!isset($post_data)) {
         return array('message' => 'ERROR: Could not retrieve Attachment.', 'body' => '');
     }
     if (!current_user_can('edit_post', $post_id)) {
         return array('message' => 'You are not allowed to edit this Attachment.', 'body' => '');
     }
     if (!empty($post_data['mla_wp_attachment_metadata'])) {
         $page_template_array = MLAData::mla_load_template(MLA_PLUGIN_PATH . 'tpls/admin-display-single-image.tpl');
         $width = isset($post_data['mla_wp_attachment_metadata']['width']) ? $post_data['mla_wp_attachment_metadata']['width'] : '';
         $height = isset($post_data['mla_wp_attachment_metadata']['height']) ? $post_data['mla_wp_attachment_metadata']['height'] : '';
         $image_meta = var_export($post_data['mla_wp_attachment_metadata'], true);
         if (!isset($post_data['mla_wp_attachment_image_alt'])) {
             $post_data['mla_wp_attachment_image_alt'] = '';
         }
     } else {
         $page_template_array = MLAData::mla_load_template(MLA_PLUGIN_PATH . 'tpls/admin-display-single-document.tpl');
         $width = '';
         $height = '';
         $image_meta = '';
     }
     if (array($page_template_array)) {
         $page_template = $page_template_array['page'];
         $authors_template = $page_template_array['authors'];
         $postbox_template = $page_template_array['postbox'];
     } else {
         error_log("ERROR: MLA::_display_single_item \$page_template_array = " . var_export($page_template_array, true), 0);
         $page_template = $page_template_array;
         $authors_template = '';
         $postbox_template = '';
     }
     if (empty($post_data['mla_references']['parent_title'])) {
         $parent_info = $post_data['mla_references']['parent_errors'];
     } else {
         $parent_info = sprintf('(%1$s) %2$s %3$s', $post_data['mla_references']['parent_type'], $post_data['mla_references']['parent_title'], $post_data['mla_references']['parent_errors']);
     }
     if ($authors = self::_authors_dropdown($post_data['post_author'], 'attachments[' . $post_data['ID'] . '][post_author]')) {
         $args = array('ID' => $post_data['ID'], 'authors' => $authors);
         $authors = MLAData::mla_parse_template($authors_template, $args);
     } else {
         $authors = '';
     }
     if (MLAOptions::$process_featured_in) {
         $features = '';
         foreach ($post_data['mla_references']['features'] as $feature_id => $feature) {
             if ($feature_id == $post_data['post_parent']) {
                 $parent = 'PARENT ';
             } else {
                 $parent = '';
             }
             $features .= sprintf('%1$s (%2$s %3$s), %4$s', $parent, $feature->post_type, $feature_id, $feature->post_title) . "\r\n";
         }
         // foreach $feature
     } else {
         $features = 'disabled';
     }
     if (MLAOptions::$process_inserted_in) {
         $inserts = '';
         foreach ($post_data['mla_references']['inserts'] as $file => $insert_array) {
             $inserts .= $file . "\r\n";
             foreach ($insert_array as $insert) {
                 if ($insert->ID == $post_data['post_parent']) {
                     $parent = '  PARENT ';
                 } else {
                     $parent = '  ';
                 }
                 $inserts .= sprintf('%1$s (%2$s %3$s), %4$s', $parent, $insert->post_type, $insert->ID, $insert->post_title) . "\r\n";
             }
             // foreach $insert
         }
         // foreach $file
     } else {
         $inserts = 'disabled';
     }
     if (MLAOptions::$process_gallery_in) {
         $galleries = '';
         foreach ($post_data['mla_references']['galleries'] as $gallery_id => $gallery) {
             if ($gallery_id == $post_data['post_parent']) {
                 $parent = 'PARENT ';
             } else {
                 $parent = '';
             }
             $galleries .= sprintf('%1$s (%2$s %3$s), %4$s', $parent, $gallery['post_type'], $gallery_id, $gallery['post_title']) . "\r\n";
         }
         // foreach $gallery
     } else {
         $galleries = 'disabled';
     }
     if (MLAOptions::$process_mla_gallery_in) {
         $mla_galleries = '';
         foreach ($post_data['mla_references']['mla_galleries'] as $gallery_id => $gallery) {
             if ($gallery_id == $post_data['post_parent']) {
                 $parent = 'PARENT ';
             } else {
                 $parent = '';
             }
             $mla_galleries .= sprintf('%1$s (%2$s %3$s), %4$s', $parent, $gallery['post_type'], $gallery_id, $gallery['post_title']) . "\r\n";
         }
         // foreach $gallery
     } else {
         $mla_galleries = 'disabled';
     }
     /*
      * WordPress doesn't look in hidden fields to set the month filter dropdown or sorting parameters
      */
     if (isset($_REQUEST['m'])) {
         $url_args = '&m=' . $_REQUEST['m'];
     } else {
         $url_args = '';
     }
     if (isset($_REQUEST['post_mime_type'])) {
         $url_args .= '&post_mime_type=' . $_REQUEST['post_mime_type'];
     }
     if (isset($_REQUEST['order'])) {
         $url_args .= '&order=' . $_REQUEST['order'];
     }
     if (isset($_REQUEST['orderby'])) {
         $url_args .= '&orderby=' . $_REQUEST['orderby'];
     }
     /*
      * Add the current view arguments
      */
     if (isset($_REQUEST['detached'])) {
         $view_args = '<input type="hidden" name="detached" value="' . $_REQUEST['detached'] . "\" />\r\n";
     } elseif (isset($_REQUEST['status'])) {
         $view_args = '<input type="hidden" name="status" value="' . $_REQUEST['status'] . "\" />\r\n";
     } else {
         $view_args = '';
     }
     if (isset($_REQUEST['paged'])) {
         $view_args .= sprintf('<input type="hidden" name="paged" value="%1$s" />', $_REQUEST['paged']) . "\r\n";
     }
     $side_info_column = '';
     $taxonomies = get_object_taxonomies('attachment', 'objects');
     foreach ($taxonomies as $tax_name => $tax_object) {
         ob_start();
         if ($tax_object->hierarchical && $tax_object->show_ui) {
             $box = array('id' => $tax_name . 'div', 'title' => esc_html($tax_object->labels->name), 'callback' => 'categories_meta_box', 'args' => array('taxonomy' => $tax_name), 'inside_html' => '');
             post_categories_meta_box($post, $box);
         } elseif ($tax_object->show_ui) {
             $box = array('id' => 'tagsdiv-' . $tax_name, 'title' => esc_html($tax_object->labels->name), 'callback' => 'post_tags_meta_box', 'args' => array('taxonomy' => $tax_name), 'inside_html' => '');
             post_tags_meta_box($post, $box);
         }
         $box['inside_html'] = ob_get_contents();
         ob_end_clean();
         $side_info_column .= MLAData::mla_parse_template($postbox_template, $box);
     }
     $page_values = array('ID' => $post_data['ID'], 'post_mime_type' => $post_data['post_mime_type'], 'menu_order' => $post_data['menu_order'], 'post_date' => $post_data['post_date'], 'post_modified' => $post_data['post_modified'], 'post_parent' => $post_data['post_parent'], 'menu_order' => $post_data['menu_order'], 'attachment_icon' => wp_get_attachment_image($post_id, array(160, 120), true), 'file_name' => esc_html($post_data['mla_references']['file']), 'width' => $width, 'height' => $height, 'post_title_attr' => esc_attr($post_data['post_title']), 'post_name_attr' => esc_attr($post_data['post_name']), 'image_alt_attr' => '', 'post_excerpt_attr' => esc_attr($post_data['post_excerpt']), 'post_content' => esc_textarea($post_data['post_content']), 'image_meta' => esc_textarea($image_meta), 'parent_info' => esc_attr($parent_info), 'guid_attr' => esc_attr($post_data['guid']), 'authors' => $authors, 'features' => esc_textarea($features), 'inserts' => esc_textarea($inserts), 'galleries' => esc_textarea($galleries), 'mla_galleries' => esc_textarea($mla_galleries), 'mla_admin_action' => self::MLA_ADMIN_SINGLE_EDIT_UPDATE, 'form_url' => admin_url('upload.php') . '?page=' . self::ADMIN_PAGE_SLUG . $url_args, 'view_args' => $view_args, 'wpnonce' => wp_nonce_field(self::MLA_ADMIN_NONCE, '_wpnonce', true, false), 'side_info_column' => $side_info_column);
     if (!empty($post_data['mla_wp_attachment_image_alt'])) {
         $page_values['image_alt_attr'] = esc_attr($post_data['mla_wp_attachment_image_alt']);
     }
     return array('message' => '', 'body' => MLAData::mla_parse_template($page_template, $page_values));
 }