/**
  * Build the hidden form for the "Search Terms" popup modal window
  *
  * @since 1.90
  *
  * @return	string	HTML <form> markup for hidden form
  */
 public static function mla_terms_search_form()
 {
     $page_template_array = MLACore::mla_load_template('admin-terms-search-form.tpl');
     if (!is_array($page_template_array)) {
         /* translators: 1: ERROR tag 2: function name 3: non-array value */
         error_log(sprintf(_x('%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), 'MLA::_build_terms_search_form', var_export($page_template_array, true)), 0);
         return '';
     }
     $taxonomies = array();
     foreach (get_object_taxonomies('attachment', 'objects') as $taxonomy) {
         if (MLACore::mla_taxonomy_support($taxonomy->name, 'support')) {
             $taxonomies[] = $taxonomy;
         }
     }
     if (empty($taxonomies)) {
         $page_values = array('Search Terms' => __('Search Terms', 'media-library-assistant'), 'message' => __('There are no taxonomies to search', 'media-library-assistant'));
         $terms_search_tpl = MLAData::mla_parse_template($page_template_array['mla-terms-search-empty-div'], $page_values);
     } else {
         $taxonomy_list = '';
         foreach ($taxonomies as $taxonomy) {
             $page_values = array('taxonomy_checked' => MLACore::mla_taxonomy_support($taxonomy->name, 'term-search') ? 'checked="checked"' : '', 'taxonomy_slug' => $taxonomy->name, 'taxonomy_label' => esc_attr($taxonomy->label));
             $taxonomy_list .= MLAData::mla_parse_template($page_template_array['mla-terms-search-taxonomy'], $page_values);
         }
         $page_values = array('Search Terms' => __('Search Terms', 'media-library-assistant'), 'Search' => __('Search', 'media-library-assistant'), 'phrases_and_checked' => 'checked="checked"', 'All phrases' => __('All phrases', 'media-library-assistant'), 'phrases_or_checked' => '', 'Any phrase' => __('Any phrase', 'media-library-assistant'), 'terms_and_checked' => '', 'All terms' => __('All terms', 'media-library-assistant'), 'terms_or_checked' => 'checked="checked"', 'Any term' => __('Any term', 'media-library-assistant'), 'exact_checked' => '', 'Exact' => __('Exact', 'media-library-assistant'), 'mla_terms_search_taxonomies' => $taxonomy_list);
         $terms_search_tpl = MLAData::mla_parse_template($page_template_array['mla-terms-search-div'], $page_values);
     }
     $page_values = array('mla_terms_search_url' => esc_url(add_query_arg(array_merge(MLA_List_Table::mla_submenu_arguments(false), array('page' => MLACore::ADMIN_PAGE_SLUG)), admin_url('upload.php'))), 'mla_terms_search_action' => MLA::MLA_ADMIN_TERMS_SEARCH, 'wpnonce' => wp_nonce_field(MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false), 'mla_terms_search_div' => $terms_search_tpl);
     $terms_search_tpl = MLAData::mla_parse_template($page_template_array['mla-terms-search-form'], $page_values);
     return $terms_search_tpl;
 }
Exemplo n.º 2
0
 /**
  * Build the hidden form for the "Set Parent" popup modal window
  *
  * @since 1.90
  *
  * @param	boolean	true to return complete form, false to return mla-set-parent-div
  *
  * @return	string	HTML <form> markup for hidden form
  */
 public static function mla_set_parent_form($return_form = true)
 {
     $set_parent_template = MLAData::mla_load_template('admin-set-parent-form.tpl');
     if (!is_array($set_parent_template)) {
         /* translators: 1: ERROR tag 2: function name 3: non-array value */
         error_log(sprintf(_x('%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), 'MLA::_build_inline_edit_form', var_export($set_parent_template, true)), 0);
         return '';
     }
     $page_values = array('Select Parent' => __('Select Parent', 'media-library-assistant'), 'Search' => __('Search', 'media-library-assistant'), 'post_type_dropdown' => self::_compose_post_type_select($set_parent_template, 'all'), 'For' => __('For', 'media-library-assistant'), 'Previous' => '&laquo;', 'Next' => '&raquo;', 'count' => '50', 'paged' => '1', 'found' => '0', 'Title' => __('Title', 'media-library-assistant'), 'Type' => __('Type', 'media-library-assistant'), 'Date' => __('Date', 'media-library-assistant'), 'Status' => __('Status', 'media-library-assistant'), 'Unattached' => __('Unattached', 'media-library-assistant'), 'mla_find_posts_nonce' => wp_nonce_field('mla_find_posts', 'mla-set-parent-ajax-nonce', false, false));
     ob_start();
     submit_button(__('Cancel', 'media-library-assistant'), 'button-secondary cancel alignleft', 'mla-set-parent-cancel', false);
     $page_values['mla_set_parent_cancel'] = ob_get_clean();
     ob_start();
     submit_button(__('Update', 'media-library-assistant'), 'button-primary alignright', 'mla-set-parent-submit', false);
     $page_values['mla_set_parent_update'] = ob_get_clean();
     $set_parent_div = MLAData::mla_parse_template($set_parent_template['mla-set-parent-div'], $page_values);
     if (!$return_form) {
         return $set_parent_div;
     }
     $page_values = array('mla_set_parent_url' => esc_url(add_query_arg(array_merge(MLA_List_Table::mla_submenu_arguments(false), array('page' => MLA::ADMIN_PAGE_SLUG)), admin_url('upload.php'))), 'mla_set_parent_action' => self::MLA_ADMIN_SET_PARENT, 'wpnonce' => wp_nonce_field(self::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME, true, false), 'mla_set_parent_div' => $set_parent_div);
     $set_parent_form = MLAData::mla_parse_template($set_parent_template['mla-set-parent-form'], $page_values);
     return $set_parent_form;
 }
Exemplo n.º 3
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_action = self::_current_bulk_action();
     $page_title = MLAOptions::mla_get_option(MLAOptions::MLA_SCREEN_PAGE_TITLE);
     echo "<div class=\"wrap\">\r\n";
     echo "<div id=\"icon-upload\" class=\"icon32\"><br/></div>\r\n";
     echo "<h2>{$page_title}";
     // trailing </h2> is action-specific
     if (!current_user_can('upload_files')) {
         echo " - Error</h2>\r\n";
         wp_die(__('You do not have permission to manage attachments.'));
     }
     $page_content = array('message' => '', 'body' => '');
     /*
      * 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') {
         if (isset($_REQUEST['cb_attachment'])) {
             foreach ($_REQUEST['cb_attachment'] as $index => $post_id) {
                 switch ($bulk_action) {
                     case 'delete':
                         $item_content = self::_delete_single_item($post_id);
                         break;
                     case 'edit':
                         if (!empty($_REQUEST['bulk_custom_field_map'])) {
                             $updates = MLAOptions::mla_evaluate_custom_field_mapping($post_id, 'single_attachment_mapping');
                             $item_content = MLAData::mla_update_single_item($post_id, $updates);
                             break;
                         }
                         if (!empty($_REQUEST['bulk_map'])) {
                             $item = get_post($post_id);
                             $updates = MLAOptions::mla_evaluate_iptc_exif_mapping($item, 'iptc_exif_mapping');
                             $item_content = MLAData::mla_update_single_item($post_id, $updates);
                             break;
                         }
                         /*
                          * Copy the edit form contents to $new_data
                          */
                         $new_data = array();
                         if (isset($_REQUEST['post_parent'])) {
                             if (is_numeric($_REQUEST['post_parent'])) {
                                 $new_data['post_parent'] = $_REQUEST['post_parent'];
                             }
                         }
                         if (isset($_REQUEST['post_author'])) {
                             if (-1 != $_REQUEST['post_author']) {
                                 $new_data['post_author'] = $_REQUEST['post_author'];
                             }
                         }
                         /*
                          * Custom field support
                          */
                         $custom_fields = array();
                         foreach (MLAOptions::mla_custom_field_support('bulk_edit') as $slug => $label) {
                             if (isset($_REQUEST[$slug])) {
                                 if (!empty($_REQUEST[$slug])) {
                                     $custom_fields[$label] = $_REQUEST[$slug];
                                 }
                             }
                         }
                         // foreach
                         if (!empty($custom_fields)) {
                             $new_data['custom_updates'] = $custom_fields;
                         }
                         $item_content = MLAData::mla_update_single_item($post_id, $new_data, $_REQUEST['tax_input'], $_REQUEST['tax_action']);
                         break;
                     case 'restore':
                         $item_content = self::_restore_single_item($post_id);
                         break;
                         //case 'tag':
                     //case 'tag':
                     case 'trash':
                         $item_content = self::_trash_single_item($post_id);
                         break;
                     default:
                         $item_content = array('message' => sprintf('Unknown bulk action %s', $bulk_action), 'body' => '');
                 }
                 // switch $bulk_action
                 $page_content['message'] .= $item_content['message'] . '<br>';
             }
             // foreach cb_attachment
             unset($_REQUEST['post_parent']);
             unset($_REQUEST['post_author']);
             unset($_REQUEST['tax_input']);
             unset($_REQUEST['tax_action']);
             foreach (MLAOptions::mla_custom_field_support('bulk_edit') as $slug => $label) {
                 unset($_REQUEST[$slug]);
             }
             unset($_REQUEST['cb_attachment']);
         } else {
             $page_content['message'] = 'Bulk Action ' . $bulk_action . ' - no items selected.';
         }
         unset($_REQUEST['action']);
         unset($_REQUEST['bulk_edit']);
         unset($_REQUEST['action2']);
     }
     // $bulk_action
     if (isset($_REQUEST['clear_filter_by'])) {
         unset($_REQUEST['heading_suffix']);
         unset($_REQUEST['parent']);
         unset($_REQUEST['author']);
         unset($_REQUEST['mla-tax']);
         unset($_REQUEST['mla-term']);
         unset($_REQUEST['mla-metakey']);
         unset($_REQUEST['mla-metavalue']);
     }
     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:')) {
                 $page_content['message'] .= $item_content['message'] . '<br>';
             } else {
                 $delete_count++;
             }
         }
         if ($delete_count) {
             $page_content['message'] .= sprintf(_nx('%s item deleted.', '%s items deleted.', $delete_count, 'deleted items'), number_format_i18n($delete_count));
         } else {
             $page_content['message'] .= 'No items deleted.';
         }
     }
     /*
      * Process row-level actions that affect a single item
      */
     if (!empty($_REQUEST['mla_admin_action'])) {
         check_admin_referer(self::MLA_ADMIN_NONCE);
         switch ($_REQUEST['mla_admin_action']) {
             case self::MLA_ADMIN_SINGLE_DELETE:
                 $page_content = self::_delete_single_item($_REQUEST['mla_item_ID']);
                 break;
             case self::MLA_ADMIN_SINGLE_EDIT_DISPLAY:
                 echo " - Edit single item</h2>";
                 $page_content = self::_display_single_item($_REQUEST['mla_item_ID']);
                 break;
             case self::MLA_ADMIN_SINGLE_EDIT_UPDATE:
                 if (!empty($_REQUEST['update'])) {
                     $page_content = MLAData::mla_update_single_item($_REQUEST['mla_item_ID'], $_REQUEST['attachments'][$_REQUEST['mla_item_ID']], $_REQUEST['tax_input']);
                 } elseif (!empty($_REQUEST['map-iptc-exif'])) {
                     $item = get_post($_REQUEST['mla_item_ID']);
                     $updates = MLAOptions::mla_evaluate_iptc_exif_mapping($item, 'iptc_exif_mapping');
                     $page_content = MLAData::mla_update_single_item($_REQUEST['mla_item_ID'], $updates);
                 } else {
                     $page_content = array('message' => 'Item: ' . $_REQUEST['mla_item_ID'] . ' cancelled.', 'body' => '');
                 }
                 break;
             case self::MLA_ADMIN_SINGLE_RESTORE:
                 $page_content = self::_restore_single_item($_REQUEST['mla_item_ID']);
                 break;
             case self::MLA_ADMIN_SINGLE_TRASH:
                 $page_content = self::_trash_single_item($_REQUEST['mla_item_ID']);
                 break;
             default:
                 $page_content = array('message' => sprintf('Unknown mla_admin_action - "%1$s"', $_REQUEST['mla_admin_action']), 'body' => '');
                 break;
         }
         // switch ($_REQUEST['mla_admin_action'])
     }
     // (!empty($_REQUEST['mla_admin_action'])
     if (!empty($page_content['body'])) {
         if (!empty($page_content['message'])) {
             if (false !== strpos($page_content['message'], 'ERROR:')) {
                 $messages_class = 'mla_errors';
             } else {
                 $messages_class = 'mla_messages';
             }
             echo "  <div class=\"{$messages_class}\"><p>\r\n";
             echo '    ' . $page_content['message'] . "\r\n";
             echo "  </p></div>\r\n";
             // id="message"
         }
         echo $page_content['body'];
     } else {
         /*
          * Display Attachments list
          */
         if (!empty($_REQUEST['heading_suffix'])) {
             echo ' - ' . esc_html($_REQUEST['heading_suffix']) . "</h2>\r\n";
         } elseif (!empty($_REQUEST['s']) && !empty($_REQUEST['mla_search_fields'])) {
             echo ' - search results for "' . esc_html(stripslashes(trim($_REQUEST['s']))) . "\"</h2>\r\n";
         } else {
             echo "</h2>\r\n";
         }
         if (!empty($page_content['message'])) {
             if (false !== strpos($page_content['message'], 'ERROR:')) {
                 $messages_class = 'mla_errors';
             } else {
                 $messages_class = 'mla_messages';
             }
             echo "  <div class=\"{$messages_class}\"><p>\r\n";
             echo '    ' . $page_content['message'] . "\r\n";
             echo "  </p></div>\r\n";
             // id="message"
         }
         /*
          * Optional - limit width of the views list
          */
         $view_width = MLAOptions::mla_get_option(MLAOptions::MLA_TABLE_VIEWS_WIDTH);
         if (!empty($view_width)) {
             if (is_numeric($view_width)) {
                 $view_width .= 'px';
             }
             echo "  <style type='text/css'>\r\n";
             echo "    ul.subsubsub {\r\n";
             echo "      width: {$view_width};\r\n";
             echo "      max-width: {$view_width};\r\n";
             echo "    }\r\n";
             echo "  </style>\r\n";
         }
         //	Create an instance of our package class...
         $MLAListTable = new MLA_List_Table();
         //	Fetch, prepare, sort, and filter our data...
         $MLAListTable->prepare_items();
         $MLAListTable->views();
         //	 Forms are NOT created automatically, so you need to wrap the table in one to use features like bulk actions
         //			echo '<form action="' . admin_url( 'upload.php' ) . '" method="get" id="mla-filter">' . "\r\n";
         echo '<form action="' . admin_url('upload.php?page=' . self::ADMIN_PAGE_SLUG) . '" method="post" id="mla-filter">' . "\r\n";
         //			echo '<form action="' . admin_url( 'upload.php?page=' . self::ADMIN_PAGE_SLUG ) . '" method="get" id="mla-filter">' . "\r\n";
         /*
          * Compose the Search Media box
          */
         if (!empty($_REQUEST['s']) && !empty($_REQUEST['mla_search_fields'])) {
             $search_value = esc_attr(stripslashes(trim($_REQUEST['s'])));
             $search_fields = $_REQUEST['mla_search_fields'];
             $search_connector = $_REQUEST['mla_search_connector'];
         } else {
             $search_value = '';
             $search_fields = array('title', 'content');
             $search_connector = 'AND';
         }
         echo '<p class="search-box">' . "\r\n";
         echo '<label class="screen-reader-text" for="media-search-input">Search Media:</label>' . "\r\n";
         echo '<input type="text" size="45"  id="media-search-input" name="s" value="' . $search_value . '" />' . "\r\n";
         echo '<input type="submit" name="mla-search-submit" id="search-submit" class="button" value="Search Media"  /><br>' . "\r\n";
         if ('OR' == $search_connector) {
             echo '<input type="radio" name="mla_search_connector" value="AND" />&nbsp;and&nbsp;' . "\r\n";
             echo '<input type="radio" name="mla_search_connector" checked="checked" value="OR" />&nbsp;or&nbsp;' . "\r\n";
         } else {
             echo '<input type="radio" name="mla_search_connector" checked="checked" value="AND" />&nbsp;and&nbsp;' . "\r\n";
             echo '<input type="radio" name="mla_search_connector" value="OR" />&nbsp;or&nbsp;' . "\r\n";
         }
         if (in_array('title', $search_fields)) {
             echo '<input type="checkbox" name="mla_search_fields[]" id="search-title" checked="checked" value="title" />&nbsp;title&nbsp;' . "\r\n";
         } else {
             echo '<input type="checkbox" name="mla_search_fields[]" id="search-title" value="title" />&nbsp;title&nbsp;' . "\r\n";
         }
         if (in_array('name', $search_fields)) {
             echo '<input type="checkbox" name="mla_search_fields[]" id="search-name" checked="checked" value="name" />&nbsp;name&nbsp;' . "\r\n";
         } else {
             echo '<input type="checkbox" name="mla_search_fields[]" id="search-name" value="name" />&nbsp;name&nbsp;' . "\r\n";
         }
         if (in_array('alt-text', $search_fields)) {
             echo '<input type="checkbox" name="mla_search_fields[]" id="search-alt-text" checked="checked" value="alt-text" />&nbsp;ALT text&nbsp;' . "\r\n";
         } else {
             echo '<input type="checkbox" name="mla_search_fields[]" id="search-alt-text" value="alt-text" />&nbsp;ALT text&nbsp;' . "\r\n";
         }
         if (in_array('excerpt', $search_fields)) {
             echo '<input type="checkbox" name="mla_search_fields[]" id="search-excerpt" checked="checked" value="excerpt" />&nbsp;caption&nbsp;' . "\r\n";
         } else {
             echo '<input type="checkbox" name="mla_search_fields[]" id="search-excerpt" value="excerpt" />&nbsp;caption&nbsp;' . "\r\n";
         }
         if (in_array('content', $search_fields)) {
             echo '<input type="checkbox" name="mla_search_fields[]" id="search-content" checked="checked" value="content" />&nbsp;description&nbsp;' . "\r\n";
         } else {
             echo '<input type="checkbox" name="mla_search_fields[]" id="search-content" value="content" />&nbsp;description&nbsp;' . "\r\n";
         }
         echo '</p>' . "\r\n";
         /*
          * 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']) . "\r\n";
         $view_arguments = MLA_List_Table::mla_submenu_arguments();
         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"
              */
             if (in_array($key, array('s', 'mla_search_connector', 'mla_search_fields'))) {
                 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)) . "\r\n";
                 }
             } else {
                 echo sprintf('<input type="hidden" name="%1$s" value="%2$s" />', $key, esc_attr($value)) . "\r\n";
             }
         }
         //	 Now we can render the completed list table
         $MLAListTable->display();
         echo "</form><!-- id=mla-filter -->\r\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>\r\n";
         echo "<br class=\"clear\" />\r\n";
         echo "</div><!-- class=wrap -->\r\n";
     }
     // display attachments list
 }