/** * Ajax handler for Media Manager "fill compat-attachment-fields" queries * * Prepares an array of (HTML) taxonomy meta boxes with attachment-specific values. * * @since 1.80 * * @return void passes array of results to wp_send_json_success() for JSON encoding and transmission */ public static function mla_fill_compat_fields_action() { if (empty($_REQUEST['query']) || !($requested = $_REQUEST['query'])) { wp_send_json_error(); } if (empty($_REQUEST['id']) || !($post_id = absint($_REQUEST['id']))) { wp_send_json_error(); } if (null == ($post = get_post($post_id))) { wp_send_json_error(); } $results = apply_filters('mla_media_modal_begin_fill_compat_fields', array(), $requested, $post); if (!empty($results)) { wp_send_json_success($results); } /* * Match all supported taxonomies against the requested list */ foreach (get_taxonomies(array('show_ui' => true), 'objects') as $key => $value) { if (MLAOptions::mla_taxonomy_support($key)) { if (is_integer($index = array_search($key, $requested))) { $request = $requested[$index]; } else { continue; } if (!($use_checklist = $value->hierarchical)) { $use_checklist = MLAOptions::mla_taxonomy_support($key, 'flat-checklist'); } if ($use_checklist) { if ('checked' == MLAOptions::mla_get_option(MLAOptions::MLA_MEDIA_MODAL_DETAILS_CATEGORY_METABOX)) { unset($requested[$index]); $label = $value->label; $terms = get_object_term_cache($post_id, $key); if (false === $terms) { $terms = wp_get_object_terms($post_id, $key); wp_cache_add($post_id, $terms, $key . '_relationships'); } if (is_wp_error($terms) || empty($terms)) { $terms = array(); } $list = array(); foreach ($terms as $term) { $list[] = $term->term_id; } // foreach $term sort($list); $list = join(',', $list); /* * Simulate the 'add_meta_boxes' callback */ $box = array('id' => $key . 'div', 'title' => $label, 'callback' => 'MLAEdit::mla_checklist_meta_box', 'args' => array('taxonomy' => $key, 'in_modal' => true)); ob_start(); MLAEdit::mla_checklist_meta_box($post, $box); $row_content = ob_get_clean(); $row = "\t\t<th class='label' valign='top' scope='row' style='width: 99%;'>\n"; $row .= "\t\t<label for='mla-attachments-{$post_id}-{$key}'>\n"; $row .= "\t\t<span title='" . __('Click to toggle', 'media-library-assistant') . "' class='alignleft' style='width: 99%; text-align: left;'>{$label}</span><br class='clear'>\n"; $row .= "\t\t</label></th>\n"; $row .= "\t\t<td class='field' style='width: 99%; display: none'>\n"; $row .= "\t\t<div class='mla-taxonomy-field'>\n"; $row .= "\t\t<input name='attachments[{$post_id}][{$key}]' class='text' id='mla-attachments-{$post_id}-{$key}' type='hidden' value='{$list}'>\n"; $row .= $row_content; $row .= "\t\t</div>\n"; $row .= "\t\t</td>\n"; $results[$key] = $row; } // checked } else { // flat if ('checked' == MLAOptions::mla_get_option(MLAOptions::MLA_MEDIA_MODAL_DETAILS_TAG_METABOX)) { unset($requested[$index]); $label = $value->label; $terms = get_object_term_cache($post_id, $key); if (false === $terms) { $terms = wp_get_object_terms($post_id, $key); wp_cache_add($post_id, $terms, $key . '_relationships'); } if (is_wp_error($terms) || empty($terms)) { $terms = array(); } $list = array(); foreach ($terms as $term) { $list[] = $term->name; } // foreach $term sort($list); $hidden_list = join(',', $list); $row = "\t\t<th class='label' valign='top' scope='row' style='width: 99%;'>\n"; $row .= "\t\t<label for='mla-attachments-{$post_id}-{$key}'>\n"; $row .= "\t\t<span title='" . __('Click to toggle', 'media-library-assistant') . "' class='alignleft' style='width: 99%; text-align: left;'>{$label}</span><br class='clear'>\n"; $row .= "\t\t</label></th>\n"; $row .= "\t\t<td class='field' style='width: 99%; display: none'>\n"; $row .= "\t\t<div class='mla-taxonomy-field'>\n"; $row .= "\t\t<div class='tagsdiv' id='mla-taxonomy-{$key}'>\n"; $row .= "\t\t<div class='jaxtag'>\n"; $row .= "\t\t<div class='nojs-tags hide-if-js'>\n"; $row .= "\t\t<input name='attachments[{$post_id}][{$key}]' class='the-tags' id='mla-attachments-{$post_id}-{$key}' type='hidden' value='{$hidden_list}'>\n"; $row .= "\t\t<input name='mla_tags[{$post_id}][{$key}]' class='server-tags' id='mla-tags-{$post_id}-{$key}' type='hidden' value='{$hidden_list}'>\n"; $row .= "\t\t</div>\n"; // nojs-tags $row .= "\t\t<div class='ajaxtag'>\n"; $row .= "\t\t<label class='screen-reader-text' for='new-tag-{$key}'>" . __('Tags', 'media-library-assistant') . "</label>\n"; /* translators: %s: add new taxonomy label */ $row .= "\t\t<div class='taghint'>" . sprintf(__('Add New %1$s', 'media-library-assistant'), $label) . "</div>\n"; $row .= "\t\t<p>\n"; $row .= "\t\t<input name='newtag[{$key}]' class='newtag form-input-tip' id='new-tag-{$key}' type='text' size='16' value='' autocomplete='off'>\n"; $row .= "\t\t<input class='button tagadd' type='button' value='Add'>\n"; $row .= "\t\t</p>\n"; $row .= "\t\t</div>\n"; // ajaxtag $row .= "\t\t<p class='howto'>Separate tags with commas</p>\n"; $row .= "\t\t</div>\n"; // jaxtag $row .= "\t\t<div class='tagchecklist'>\n"; foreach ($list as $index => $term) { $row .= "\t\t<span><a class='ntdelbutton' id='post_tag-check-num-{$index}'>X</a> {$term}</span>\n"; } $row .= "\t\t</div>\n"; // tagchecklist $row .= "\t\t</div>\n"; // tagsdiv $row .= "\t\t<p><a class='tagcloud-link' id='mla-link-{$key}' href='#titlediv'>" . __('Choose from the most used tags', 'media-library-assistant') . "</a></p>\n"; $row .= "\t\t</div>\n"; // mla-taxonomy-field $row .= "\t\t</td>\n"; $results[$key] = $row; } // checked } // flat } // is supported } // foreach /* * Any left-over requests are for unsupported taxonomies */ foreach ($requested as $key) { $row = "\t\t<tr class='compat-field-{$key} mla-taxonomy-row'>\n"; $row .= "\t\t<th class='label' valign='top' scope='row'>\n"; $row .= "\t\t<label for='mla-attachments-{$post_id}-{$key}'>\n"; $row .= "\t\t<span title='" . __('Click to toggle', 'media-library-assistant') . "' class='alignleft'>{$label}</span><br class='clear'>\n"; $row .= "\t\t</label></th>\n"; $row .= "\t\t<td class='field' style='display: none'>\n"; $row .= "\t\t<div class='mla-taxonomy-field'>\n"; $row .= "\t\t<input name='attachments[{$post_id}][{$key}]' class='text' id='mla-attachments-{$post_id}-{$key}' type='hidden' value=''>\n"; $row .= "\t\t<div id='taxonomy-{$key}' class='categorydiv'>\n"; $row .= __('Not Supported', 'media-library-assistant') . ".\n"; $row .= "\t\t</div>\n"; $row .= "\t\t</div>\n"; $row .= "\t\t</td>\n"; $row .= "\t\t</tr>\n"; $results[$key] = $row; } wp_send_json_success(apply_filters('mla_media_modal_end_fill_compat_fields', $results, $_REQUEST['query'], $requested, $post)); }
/** * Renders the MLA Gallery in meta box on the Edit Media page. * Declared public because it is a callback function. * * @since 0.80 * * @param object current post * * @return void echoes the HTML markup for the meta box content */ public static function mla_mla_gallery_in_handler($post) { if (is_null(self::$mla_references)) { self::$mla_references = MLAQuery::mla_fetch_attachment_references($post->ID, $post->post_parent); } $galleries = ''; if (is_array(self::$mla_references)) { foreach (self::$mla_references['mla_galleries'] as $gallery_id => $gallery) { if ($gallery_id == $post->post_parent) { $parent = __('PARENT', 'media-library-assistant') . ' '; } else { $parent = ''; } $galleries .= sprintf('%1$s (%2$s %3$s), %4$s', $parent, $gallery['post_type'], $gallery_id, $gallery['post_title']) . "\n"; } // foreach $feature } $galleries = apply_filters('mla_mla_gallery_in_meta_box', array('galleries' => $galleries, 'rows' => 5, 'cols' => 80), self::$mla_references, $post); $html = '<label class="screen-reader-text" for="mla_mla_gallery_in">' . __('MLA Gallery in', 'media-library-assistant') . '</label><textarea class="readonly" id="mla_mla_gallery_in" rows="' . absint($galleries['rows']) . '" cols="' . absint($galleries['cols']) . '" readonly="readonly" name="mla_mla_gallery_in" >' . esc_textarea($galleries['galleries']) . "</textarea>\n"; echo apply_filters('mla_mla_gallery_in_meta_box_html', $html, $galleries, self::$mla_references, $post); }
/** * Renders the Gallery in meta box on the Edit Media page. * Declared public because it is a callback function. * * @since 0.80 * * @param object current post * * @return void echoes the HTML markup for the meta box content */ public static function mla_mla_gallery_in_handler($post) { if (is_null(self::$mla_references)) { self::$mla_references = MLAData::mla_fetch_attachment_references($post->ID, $post->post_parent); } $galleries = ''; if (is_array(self::$mla_references)) { foreach (self::$mla_references['mla_galleries'] as $gallery_id => $gallery) { if ($gallery_id == $post->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 $feature } echo '<label class="screen-reader-text" for="mla_mla_gallery_in">MLA Gallery in</label><textarea class="readonly" id="mla_mla_gallery_in" rows="5" cols="80" readonly="readonly" name="mla_mla_gallery_in" >' . esc_textarea($galleries) . "</textarea>\r\n"; }