Media Library Assistant - Version 2.40

Version Description

  • New: For WordPress 4.7 and later, the thumbnail generation Bulk Action can generate native thumbnails for items uploaded to the Media Library before updating to WP 4.7.
  • New: The Settings/Media Library Assistant Shortcodes tab has been re-written with a more "WordPress-like" interface.
  • New: Overall admin-mode memory requirements are reduced by 1.66MB, or about 33%, from the previous version.
  • New: The Settings/Media Library Assistant Examples tab has a new "View" rollover action that lets you display the source code for an example plugin.
  • New: The Settings/Media Library Assistant Examples tab has a new "Installed" view that shows all installed example plugins regardless of status.
  • New: For the Media/Assistant submenu table, the "Search Media" feature can search on file name. You may have to adjust the Settings/Media Library Assistant General tab "Search Media Defaults" to make this a default setting.
  • New: The mla-substitution-parameter-hooks-example.php example plugin has been enhanced with a "parent:" prefix that provides access to item's parent post/page values as well as the "parent:permalink". It also includes a new "page:featured" parameter that returns the ID of a post/page Featured Image.
  • New: For all shortcodes, the mla_page_parameter parameter can contain page-level substitution parameters, e.g., mla_page_parameter="p-{+page_ID+}".
  • New: For [mla_term_list], a new mla_multi_select parameter supports multiple select dropdown controls.
  • New: For [mla_gallery], the post_parent parameter can have multiple, comma-separated numeric values.
  • New: For [mla_gallery], a new mla_gallery_the_attachments hook lets you read or change the array of attachments used to populate the gallery display. Four hooks have been added to give more control over the "alternative gallery shortcode" processing.
  • New: The mla-hooks-example.php example plugin now supports multiple taxonomy queries in the my_custom_sql example.
  • New: The woofixit.php example plugin has several new tools. In particular, the "Clear Terms" and "Assign Terms" tools replicate term assignments from WooCommerce products to items used as product images and in product galleries.
  • New: The buddypress-hooks-example.php example plugin uses the new mla_gallery_the_attachments hook to restrict gallery output to "rtMedia" items. It also includes a new rtmedia=gallery parameter that works with the [rtmedia_gallery] shortcode.
  • New: A new example plugin, posts-per-page-example.php, shows how to adjust the number of items per gallery page based on WordPress conditional functions such as is_front_page().
  • New: A new example plugin, mla-multi-search-example.php, adds custom field search(es) to the keyword(s) search and combines the results.
  • New: A new example plugin, get-post-galleries-example.php, supports the WordPress get_post_galleries filter required, for example, by the Dominant Colors Lazy Loading plugin by Manuel Wieser.
  • New: A new example plugin, mla-not-featured-view-example.php, creates a custom Media/Assistant view of items NOT featured in any post/page.
  • New: A new example plugin, mla-regenerate-thumbnails-example.php, integrates the Regenerate Thumbnails plugin by Alex Mills with the Media/Assistant submenu screen.
  • New: A new example plugin, mla-parent-wp-query-example.php, supplies post_parent values from a separateWP_Query for the [mla_gallery] shortcode.
  • New: The mla-ui-elements-example.php example plugin now includes [muie_orderby] and [muie_order] shortcodes that generate "sticky" controls for their respective parameters.
  • New: A new Settings/Media Library Assistant General tab setting, "Show Count Column", lets you add the "Count" column back to the Media/Categories and Media/Tags taxonomy edit screens. This may be useful for WP 4.7's attachment taxonomy support.
  • Fix: When Polylang or WPML is active, language-specific tag cloud terms have been restored.
  • Fix: When Polylang is active, the change language dropdown control in the Bulk Edit area is now processed correctly.
  • Fix: Error messages are no longer written directly to the PHP error log. They now pass through the MLA debug filtering logic.
  • Fix: Harmless PHP 7 incompatibility issues reported by the WP Engine PHP Compatibility Checker plugin have been resolved. The minimum PHP version required by MLA has been updated from 5.2 to 5.4.
  • Fix: The "where-used" processing for "MLA Gallery in" and "Gallery in" ignores pagination parameters to get a complete result, and sorting parameters because they do not affect the results.
  • Fix: For [mla_gallery], the posts_per_archive_page is applied when the gallery is displayed in a post/page for which is_archive() or is_search() is true.
  • Fix: For [mla_gallery], the "Open" template section is no longer required.
  • Fix: For [mla_tag_cloud] and [mla_term_list], URLs with a question mark (?) are now handled correctly for the currentlink_url and currentlink substitution parameters.
  • Fix: Complete plugin support is loaded for WP REST API calls, e.g., from the WP/LR Sync plugin. This enables IPTC/EXIF and Custom Field mapping when adding new Media Library items.
  • Fix: When Polylang is active, new flat taxonomy (e.g. Att, Tags) values can be created in the Quick Edit and Bulk Edit areas as well as the ATTACHMENT DETAILS pane of the Media Manager Modal (popup) Window.
  • Fix: For the Settings/Media Library Assistant Custom Fields and IPTC/EXIF tabs, the mapping progress area now has a "Pause" button to more clearly reflect the ability to pause and resume the mapping operation.
  • Fix: For the Settings/Media Library Assistant Views and Uploads tabs, the "Enable ..." and "Save Changes" elements have been moved to the upper-left part of the screen to make them more obvious and accessible.
  • Fix: For the Media/Assistant submenu table, the "Attached to" column reflects the surrent user's "edit post" and "read post" capabilities for both the item and its parent; conforms to new WP 4.6 restrictions.
  • Fix: A few minor defects in the "Operations on Products, using the Product Image, Product Tags and Att. Tags" section of the "WooCommerce Fixit" example plugin have been corrected.
Download this release

Release Info

Developer dglingren
Plugin Icon 128x128 Media Library Assistant
Version 2.40
Comparing to
See all releases

Code changes from version 2.33 to 2.40

Files changed (66) hide show
  1. css/mla-style-rtl.css +8 -2
  2. css/mla-style.css +8 -2
  3. examples/plugins/alexa-paige-plugin.php +2 -2
  4. examples/plugins/buddypress-hooks-example.php +260 -638
  5. examples/plugins/get-post-galleries-example.php +139 -0
  6. examples/plugins/mla-a-z-cloud-example.php +27 -2
  7. examples/plugins/mla-bulk-edit-remap-example.php +7 -0
  8. examples/plugins/mla-child-term-hooks-example.php +20 -15
  9. examples/plugins/mla-custom-field-search-example.php +23 -4
  10. examples/plugins/mla-custom-view-example.php +5 -1
  11. examples/plugins/mla-hooks-example.php +398 -187
  12. examples/plugins/mla-multi-search-example.php +196 -0
  13. examples/plugins/mla-not-featured-view-example.php +342 -0
  14. examples/plugins/mla-parent-wp-query-example.php +126 -0
  15. examples/plugins/mla-random-galleries-example.php +23 -0
  16. examples/plugins/mla-regenerate-thumbnails-example.php +135 -0
  17. examples/plugins/mla-substitution-parameter-hooks-example.php +93 -25
  18. examples/plugins/mla-tax-query-example.php +16 -4
  19. examples/plugins/mla-ui-elements-example.php +451 -97
  20. examples/plugins/mla-upload-bulk-edit-example.php +9 -1
  21. examples/plugins/posts-per-page-example.php +91 -0
  22. examples/plugins/woofixit.php +827 -148
  23. includes/class-mla-admin-columns-support-deprecated.php +220 -0
  24. includes/class-mla-admin-columns-support.php +25 -128
  25. includes/class-mla-ajax.php +4 -1
  26. includes/class-mla-core-options.php +16 -3
  27. includes/class-mla-core.php +97 -12
  28. includes/class-mla-data-pdf.php +10 -9
  29. includes/class-mla-data-query.php +84 -66
  30. includes/class-mla-data.php +3 -3
  31. includes/class-mla-edit-media.php +5 -5
  32. includes/class-mla-image-processor.php +29 -12
  33. includes/class-mla-list-table.php +34 -11
  34. includes/class-mla-main.php +20 -94
  35. includes/class-mla-media-modal.php +2 -2
  36. includes/class-mla-mime-types.php +256 -8
  37. includes/class-mla-objects.php +5 -2
  38. includes/class-mla-options.php +3 -265
  39. includes/class-mla-polylang-shortcode-support.php +77 -0
  40. includes/class-mla-polylang-support.php +165 -93
  41. includes/class-mla-settings-custom-fields-tab.php +474 -0
  42. includes/{class-mla-example-list-table.php → class-mla-settings-documentation-tab.php} +385 -50
  43. includes/class-mla-settings-iptc-exif-tab.php +660 -0
  44. includes/class-mla-settings-shortcodes-tab.php +2074 -0
  45. includes/class-mla-settings-upload-tab.php +1691 -0
  46. includes/class-mla-settings-view-tab.php +1020 -0
  47. includes/class-mla-settings.php +226 -3049
  48. includes/class-mla-shortcode-support.php +366 -190
  49. includes/class-mla-shortcodes.php +14 -0
  50. includes/class-mla-template-support.php +264 -157
  51. includes/class-mla-thumbnail-generation.php +108 -9
  52. includes/class-mla-upload-list-table.php +0 -794
  53. includes/class-mla-upload-optional-list-table.php +0 -497
  54. includes/class-mla-view-list-table.php +0 -650
  55. includes/class-mla-wpml-shortcode-support.php +94 -0
  56. includes/class-mla-wpml-support.php +4 -71
  57. includes/mla-main-search-box-template.php +4 -4
  58. includes/mla-media-modal-js-template.php +4 -0
  59. includes/mla-plugin-loader.php +28 -31
  60. index.php +2 -2
  61. js/mla-inline-mapping-scripts.js +14 -7
  62. js/mla-inline-mapping-scripts.min.js +325 -1
  63. js/mla-media-modal-scripts.js +7 -0
  64. js/mla-media-modal-scripts.min.js +1 -1
  65. js/mla-settings-shortcodes-tab-scripts.js +83 -0
  66. js/mla-settings-shortcodes-tab-scripts.min.js +0 -0
css/mla-style-rtl.css CHANGED
@@ -335,6 +335,10 @@ div.mla_errors {
335
  * MLA Settings page
336
  */
337
 
 
 
 
 
338
  #wpbody-content .optiontable th {
339
  padding-left: 10px;
340
  }
@@ -345,9 +349,11 @@ div.mla_errors {
345
  border-left: 1px solid
346
  }
347
 
348
- .mla-settings-after-table {
349
- margin-right: 10px;
350
  margin-top: 10px;
 
 
351
  }
352
 
353
  span.submit.mla-settings-submit,
335
  * MLA Settings page
336
  */
337
 
338
+ #donate-button-div {
339
+ margin-top: 5px;
340
+ }
341
+
342
  #wpbody-content .optiontable th {
343
  padding-left: 10px;
344
  }
349
  border-left: 1px solid
350
  }
351
 
352
+ .mla-settings-enable-form {
353
+ margin-right: 0px;
354
  margin-top: 10px;
355
+ padding-bottom: 10px;
356
+ border-bottom:thin solid #888888;
357
  }
358
 
359
  span.submit.mla-settings-submit,
css/mla-style.css CHANGED
@@ -335,6 +335,10 @@ div.mla_errors {
335
  * MLA Settings page
336
  */
337
 
 
 
 
 
338
  #wpbody-content .optiontable th {
339
  padding-right: 10px;
340
  }
@@ -345,9 +349,11 @@ div.mla_errors {
345
  border-right: 1px solid
346
  }
347
 
348
- .mla-settings-after-table {
349
- margin-left: 10px;
350
  margin-top: 10px;
 
 
351
  }
352
 
353
  span.submit.mla-settings-submit,
335
  * MLA Settings page
336
  */
337
 
338
+ #donate-button-div {
339
+ margin-top: 5px;
340
+ }
341
+
342
  #wpbody-content .optiontable th {
343
  padding-right: 10px;
344
  }
349
  border-right: 1px solid
350
  }
351
 
352
+ .mla-settings-enable-form {
353
+ margin-left: 0px;
354
  margin-top: 10px;
355
+ padding-bottom: 10px;
356
+ border-bottom:thin solid #888888;
357
  }
358
 
359
  span.submit.mla-settings-submit,
examples/plugins/alexa-paige-plugin.php CHANGED
@@ -776,7 +776,7 @@ class AlexaPaigePlugin {
776
  $ttids = array();
777
 
778
  // Find taxonomy argument, if present, and collect terms
779
- $taxonomies = get_taxonomies( array( 'object_type' => array( 'attachment' ) ), 'names' );
780
  foreach( $taxonomies as $taxonomy ) {
781
  if ( empty( $my_query_vars[ $taxonomy ] ) ) {
782
  continue;
@@ -964,7 +964,7 @@ class AlexaPaigePlugin {
964
  $ttids = array();
965
 
966
  // Find taxonomy argument, if present, and collect terms
967
- $taxonomies = get_taxonomies( array( 'object_type' => array( 'attachment' ) ), 'names' );
968
  foreach( $taxonomies as $taxonomy ) {
969
  if ( empty( $my_query_vars[ $taxonomy ] ) ) {
970
  continue;
776
  $ttids = array();
777
 
778
  // Find taxonomy argument, if present, and collect terms
779
+ $taxonomies = get_object_taxonomies( 'attachment', 'names' );
780
  foreach( $taxonomies as $taxonomy ) {
781
  if ( empty( $my_query_vars[ $taxonomy ] ) ) {
782
  continue;
964
  $ttids = array();
965
 
966
  // Find taxonomy argument, if present, and collect terms
967
+ $taxonomies = get_object_taxonomies( 'attachment', 'names' );
968
  foreach( $taxonomies as $taxonomy ) {
969
  if ( empty( $my_query_vars[ $taxonomy ] ) ) {
970
  continue;
examples/plugins/buddypress-hooks-example.php CHANGED
@@ -1,24 +1,45 @@
1
  <?php
2
  /**
3
- * Provides an example of hooking the filters provided by the [mla_gallery] shortcode
4
  *
5
- * In this example, the WordPress "attachment/media page" links are replaced by
6
- * "BuddyPress/rtMedia page" links. For audio and video files, an option is provided to
7
- * substitute the "cover_art" thumbnail image for the item Title in the thumbnail_content.
8
  *
9
- * @package MLA Gallery Hooks for BuddyPress & rtMedia Example
10
- * @version 1.05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  */
12
 
13
  /*
14
- Plugin Name: MLA Gallery Hooks for BuddyPress & rtMedia Example
15
  Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
16
- Description: Provides an example of hooking the filters provided by the [mla_gallery] shortcode
17
  Author: David Lingren
18
- Version: 1.05
19
  Author URI: http://fairtradejudaica.org/our-story/staff/
20
 
21
- Copyright 2013, 2014 David Lingren
22
 
23
  This program is free software; you can redistribute it and/or modify
24
  it under the terms of the GNU General Public License as published by
@@ -37,10 +58,7 @@ Copyright 2013, 2014 David Lingren
37
  /**
38
  * Class MLA BuddyPress Hooks Example hooks all of the filters provided by the [mla_gallery] shortcode
39
  *
40
- * Call it anything you want, but give it an unlikely and hopefully unique name. Hiding everything
41
- * else inside a class means this is the only name you have to worry about.
42
- *
43
- * @package MLA Gallery Hooks for BuddyPress & rtMedia Example
44
  * @since 1.00
45
  */
46
  class MLABuddyPressHooksExample {
@@ -48,61 +66,25 @@ class MLABuddyPressHooksExample {
48
  * Initialization function, similar to __construct()
49
  *
50
  * @since 1.00
51
- *
52
- * @return void
53
  */
54
  public static function initialize() {
55
- /*
56
- * The filters are only useful for front-end posts/pages; exit if in the admin section
57
- */
 
 
 
58
  if ( is_admin() )
59
  return;
60
 
61
- /*
62
- * add_filter parameters:
63
- * $tag - name of the hook you're filtering; defined by [mla_gallery]
64
- * $function_to_add - function to be called when [mla_gallery] applies the filter
65
- * $priority - default 10; lower runs earlier, higher runs later
66
- * $accepted_args - number of arguments your function accepts
67
- *
68
- * Comment out the filters you don't need; save them for future use
69
- */
70
- //add_filter( 'mla_gallery_raw_attributes', 'MLABuddyPressHooksExample::mla_gallery_raw_attributes_filter', 10, 1 );
71
- add_filter( 'mla_gallery_attributes', 'MLABuddyPressHooksExample::mla_gallery_attributes_filter', 10, 1 );
72
- //add_filter( 'mla_gallery_initial_content', 'MLABuddyPressHooksExample::mla_gallery_initial_content_filter', 10, 2 );
73
- //add_filter( 'mla_gallery_arguments', 'MLABuddyPressHooksExample::mla_gallery_arguments_filter', 10, 1 );
74
- //add_filter( 'mla_gallery_query_attributes', 'MLABuddyPressHooksExample::mla_gallery_query_attributes_filter', 10, 1 );
75
- //add_filter( 'mla_gallery_query_arguments', 'MLABuddyPressHooksExample::mla_gallery_query_arguments_filter', 10, 1 );
76
- add_action( 'mla_gallery_wp_query_object', 'MLABuddyPressHooksExample::mla_gallery_wp_query_object_action', 10, 1 );
77
- //add_filter( 'mla_gallery_final_content', 'MLABuddyPressHooksExample::mla_gallery_final_content_filter', 10, 1 );
78
-
79
- //add_filter( 'use_mla_gallery_style', 'MLABuddyPressHooksExample::use_mla_gallery_style_filter', 10, 2 );
80
-
81
- //add_filter( 'mla_gallery_style_values', 'MLABuddyPressHooksExample::mla_gallery_style_values_filter', 10, 1 );
82
- //add_filter( 'mla_gallery_style_template', 'MLABuddyPressHooksExample::mla_gallery_style_template_filter', 10, 1 );
83
- //add_filter( 'mla_gallery_style_parse', 'MLABuddyPressHooksExample::mla_gallery_style_parse_filter', 10, 3 );
84
-
85
- //add_filter( 'mla_gallery_open_values', 'MLABuddyPressHooksExample::mla_gallery_open_values_filter', 10, 1 );
86
- //add_filter( 'mla_gallery_open_template', 'MLABuddyPressHooksExample::mla_gallery_open_template_filter', 10, 1 );
87
- //add_filter( 'mla_gallery_open_parse', 'MLABuddyPressHooksExample::mla_gallery_open_parse_filter', 10, 3 );
88
-
89
- //add_filter( 'mla_gallery_style', 'MLABuddyPressHooksExample::mla_gallery_style_filter', 10, 5 );
90
-
91
- //add_filter( 'mla_gallery_row_open_values', 'MLABuddyPressHooksExample::mla_gallery_row_open_values_filter', 10, 1 );
92
- //add_filter( 'mla_gallery_row_open_template', 'MLABuddyPressHooksExample::mla_gallery_row_open_template_filter', 10, 1 );
93
- //add_filter( 'mla_gallery_row_open_parse', 'MLABuddyPressHooksExample::mla_gallery_row_open_parse_filter', 10, 3 );
94
-
95
- add_filter( 'mla_gallery_item_values', 'MLABuddyPressHooksExample::mla_gallery_item_values_filter', 10, 1 );
96
- //add_filter( 'mla_gallery_item_template', 'MLABuddyPressHooksExample::mla_gallery_item_template_filter', 10, 1 );
97
- //add_filter( 'mla_gallery_item_parse', 'MLABuddyPressHooksExample::mla_gallery_item_parse_filter', 10, 3 );
98
-
99
- //add_filter( 'mla_gallery_row_close_values', 'MLABuddyPressHooksExample::mla_gallery_row_close_values_filter', 10, 1 );
100
- //add_filter( 'mla_gallery_row_close_template', 'MLABuddyPressHooksExample::mla_gallery_row_close_template_filter', 10, 1 );
101
- //add_filter( 'mla_gallery_row_close_parse', 'MLABuddyPressHooksExample::mla_gallery_row_close_parse_filter', 10, 3 );
102
-
103
- //add_filter( 'mla_gallery_close_values', 'MLABuddyPressHooksExample::mla_gallery_close_values_filter', 10, 1 );
104
- //add_filter( 'mla_gallery_close_template', 'MLABuddyPressHooksExample::mla_gallery_close_template_filter', 10, 1 );
105
- //add_filter( 'mla_gallery_close_parse', 'MLABuddyPressHooksExample::mla_gallery_close_parse_filter', 10, 3 );
106
  }
107
 
108
  /**
@@ -110,43 +92,10 @@ class MLABuddyPressHooksExample {
110
  *
111
  * @since 1.00
112
  *
113
- * @var array
114
  */
115
  private static $shortcode_attributes = array();
116
-
117
- /**
118
- * MLA Gallery Raw (Display) Attributes
119
- *
120
- * This filter gives you an opportunity to record or modify the arguments passed in to the shortcode
121
- * before they pass through the logic to handle the 'mla_page_parameter' and "request:" prefix processing.
122
- *
123
- * The $shortcode_attributes array is where you will find any of your own parameters that are coded in the
124
- * shortcode, e.g., [mla_gallery my_parameter="my value"].
125
- *
126
- * @since 1.03
127
- *
128
- * @param array the raw shortcode parameters passed in to the shortcode
129
- *
130
- * @return array updated shortcode attributes
131
- */
132
- public static function mla_gallery_raw_attributes_filter( $shortcode_attributes ) {
133
- /*
134
- * Uncomment the error_log statements in any of the filters to see what's passed in
135
- */
136
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_raw_attributes_filter $shortcode_attributes = ' . var_export( $shortcode_attributes, true ), 0 );
137
-
138
- /*
139
- * Note that the global $post; object is available here and in all later filters.
140
- * It contains the post/page on which the [mla_gallery] appears.
141
- * Some [mla_gallery] invocations are not associated with a post/page; these will
142
- * have a substitute $post object with $post->ID == 0.
143
- */
144
- global $post;
145
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_raw_attributes_filter $post->ID = ' . var_export( $post->ID, true ), 0 );
146
-
147
- return $shortcode_attributes;
148
- } // mla_gallery_raw_attributes_filter
149
-
150
  /**
151
  * MLA Gallery (Display) Attributes
152
  *
@@ -158,190 +107,71 @@ class MLABuddyPressHooksExample {
158
  *
159
  * @since 1.00
160
  *
161
- * @param array the shortcode parameters passed in to the shortcode
162
  *
163
- * @return array updated shortcode attributes
164
  */
165
- public static function mla_gallery_attributes_filter( $shortcode_attributes ) {
166
- /*
167
- * Uncomment the error_log statements in any of the filters to see what's passed in
168
- */
169
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_attributes_filter $shortcode_attributes = ' . var_export( $shortcode_attributes, true ), 0 );
 
 
170
 
171
- /*
172
- * Save the attributes for use in the later filters
173
- */
 
 
 
 
 
 
 
 
174
  self::$shortcode_attributes = $shortcode_attributes;
175
 
 
176
  return $shortcode_attributes;
177
- } // mla_gallery_attributes_filter
178
-
179
- /**
180
- * Save the enclosed content
181
- *
182
- * @since 1.02
183
- *
184
- * @var NULL|string
185
- */
186
- private static $shortcode_content = NULL;
187
-
188
- /**
189
- * MLA Gallery Enclosed Content, initial filter
190
- *
191
- * This filter gives you an opportunity to record or modify the content enclosed by the shortcode
192
- * when the [mla_gallery]content[/mla_gallery] form is used.
193
- * This initial filter is called just after the 'mla_gallery_attributes' filter above.
194
- *
195
- * @since 1.02
196
- *
197
- * @param NULL|string content enclosed by the shortcode, if any
198
- * @param array the shortcode parameters passed in to the shortcode
199
- *
200
- * @return array updated shortcode content
201
- */
202
- public static function mla_gallery_initial_content_filter( $shortcode_content, $shortcode_attributes ) {
203
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_initial_content_filter $shortcode_content = ' . var_export( $shortcode_content, true ), 0 );
204
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_initial_content_filter $shortcode_attributes = ' . var_export( $shortcode_attributes, true ), 0 );
205
-
206
- /*
207
- * Save the attributes for use in the later filters
208
- */
209
- self::$shortcode_content = $shortcode_content;
210
-
211
- return $shortcode_content;
212
- } // mla_gallery_initial_content_filter
213
-
214
- /**
215
- * Save the shortcode arguments
216
- *
217
- * @since 1.00
218
- *
219
- * @var array
220
- */
221
- private static $all_display_parameters = array();
222
-
223
- /**
224
- * MLA Gallery (Display) Arguments
225
- *
226
- * This filter gives you an opportunity to record or modify the gallery display arguments
227
- * after the shortcode attributes are merged with the default arguments.
228
- *
229
- * Note that the values in this array are input or default values, not the final computed values
230
- * used for the gallery display. The computed values are in the $style_values, $markup_values and
231
- * $item_values arrays passed to later filters below.
232
- *
233
- * @since 1.00
234
- *
235
- * @param array shortcode arguments merged with gallery display defaults, so every possible parameter is present
236
- *
237
- * @return array updated gallery display arguments
238
- */
239
- public static function mla_gallery_arguments_filter( $all_display_parameters ) {
240
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_arguments_filter $all_display_parameters = ' . var_export( $all_display_parameters, true ), 0 );
241
-
242
- self::$all_display_parameters = $all_display_parameters;
243
- return $all_display_parameters;
244
- } // mla_gallery_arguments_filter
245
-
246
- /**
247
- * Save the query attributes
248
- *
249
- * @since 1.00
250
- *
251
- * @var array
252
- */
253
- private static $query_attributes = array();
254
-
255
- /**
256
- * MLA Gallery Query Attributes
257
- *
258
- * This filter gives you an opportunity to record or modify the arguments passed in to the shortcode
259
- * before they are merged with the default arguments used to select the attachments for the gallery.
260
- *
261
- * The query attributes passed in to this filter are the same as those passed through the
262
- * "MLA Gallery (Display) Attributes" filter above. This filter is provided so you can modify
263
- * the data selection attributes without disturbing the attributes used for gallery display.
264
- *
265
- * @since 1.00
266
- *
267
- * @param array the shortcode parameters passed in to the shortcode
268
- *
269
- * @return array updated shortcode attributes
270
- */
271
- public static function mla_gallery_query_attributes_filter( $query_attributes ) {
272
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_query_attributes_filter $query_attributes = ' . var_export( $query_attributes, true ), 0 );
273
-
274
- self::$query_attributes = $query_attributes;
275
- return $query_attributes;
276
- } // mla_gallery_query_attributes_filter
277
-
278
- /**
279
- * Save the query arguments
280
- *
281
- * @since 1.00
282
- *
283
- * @var array
284
- */
285
- private static $all_query_parameters = array();
286
-
287
- /**
288
- * MLA Gallery Query Arguments
289
- *
290
- * This filter gives you an opportunity to record or modify the attachment query arguments
291
- * after the shortcode attributes are merged with the default arguments.
292
- *
293
- * @since 1.00
294
- *
295
- * @param array shortcode arguments merged with attachment selection defaults, so every possible parameter is present
296
- *
297
- * @return array updated attachment query arguments
298
- */
299
- public static function mla_gallery_query_arguments_filter( $all_query_parameters ) {
300
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_query_arguments_filter $all_query_parameters = ' . var_export( $all_query_parameters, true ), 0 );
301
-
302
- self::$all_query_parameters = $all_query_parameters;
303
-
304
- return $all_query_parameters;
305
- } // mla_gallery_query_arguments_filter
306
 
307
  /**
308
  * Save some of the WP_Query object properties
309
  *
310
  * @since 1.00
311
  *
312
- * @var array
313
  */
314
  private static $wp_query_properties = array();
315
-
316
  /**
317
  * MLA Gallery WP Query Object
318
  *
319
- * This action gives you an opportunity (read-only) to record anything you need from the WP_Query object used
320
- * to select the attachments for gallery display. This is the ONLY point at which the WP_Query object is defined.
321
  *
322
  * @since 1.00
323
  * @uses MLAShortcodes::$mla_gallery_wp_query_object
324
  *
325
- * @param array query arguments passed to WP_Query->query
326
- *
327
- * @return void actions never return anything
328
  */
329
- public static function mla_gallery_wp_query_object_action( $query_arguments ) {
330
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_wp_query_object_action $query_arguments = ' . var_export( $query_arguments, true ), 0 );
331
-
332
  self::$wp_query_properties = array();
333
  self::$wp_query_properties ['post_count'] = MLAShortcodes::$mla_gallery_wp_query_object->post_count;
334
-
335
  if ( empty( self::$shortcode_attributes['buddypress_urls'] ) ) {
336
  return; // Don't need custom URLs
337
  }
338
-
339
  if ( 0 == self::$wp_query_properties ['post_count'] ) {
340
  return; // Empty gallery - nothing to do
341
  }
342
-
343
  global $wpdb;
344
-
345
  // Assemble the WordPress attachment IDs
346
  $post_info = array();
347
  foreach( MLAShortcodes::$mla_gallery_wp_query_object->posts as $value ) {
@@ -355,7 +185,7 @@ class MLABuddyPressHooksExample {
355
  $query[] = "SELECT rtm.id, rtm.media_id, rtm.media_author, rtm.media_type, rtm.cover_art, u.user_nicename FROM {$wpdb->prefix}rt_rtm_media AS rtm";
356
  $query[] = "LEFT JOIN {$wpdb->users} as u";
357
  $query[] = "ON (rtm.media_author = u.ID)";
358
-
359
  $placeholders = array();
360
  foreach ( $post_info as $value ) {
361
  $placeholders[] = '%s';
@@ -373,296 +203,219 @@ class MLABuddyPressHooksExample {
373
  $post_info[ $value->media_id ] = $value;
374
  }
375
  }
376
-
377
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_wp_query_object_action $post_info = ' . var_export( $post_info, true ), 0 );
378
  self::$wp_query_properties ['post_info'] = $post_info;
379
-
380
- /*
381
- * Unlike Filters, Actions never return anything
382
- */
383
- return;
384
- } // mla_gallery_wp_query_object_action
385
-
386
- /**
387
- * MLA Gallery Enclosed Content, final filter
388
- *
389
- * This filter gives you an opportunity to record or modify the content enclosed by the shortcode
390
- * when the [mla_gallery]content[/mla_gallery] form is used.
391
- * This final filter is called just after the WP_query and before control is passed
392
- * to the alternate gallery shortcode.
393
- *
394
- * @since 1.02
395
- *
396
- * @param NULL|string content enclosed by the shortcode, if any
397
- *
398
- * @return array updated shortcode content
399
- */
400
- public static function mla_gallery_final_content_filter( $shortcode_content ) {
401
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_final_content_filter $shortcode_content = ' . var_export( $shortcode_content, true ), 0 );
402
-
403
- return $shortcode_content;
404
- } // mla_gallery_final_content_filter
405
-
406
- /**
407
- * Use MLA Gallery Style
408
- *
409
- * You can use this filter to allow or suppress the inclusion of CSS styles in the
410
- * gallery output. Return 'true' to allow the styles, false to suppress them. You can also
411
- * suppress styles by returning an empty string from the mla_gallery_style_parse_filter below.
412
- *
413
- * @since 1.00
414
- *
415
- * @param boolean true unless the mla_style parameter is "none"
416
- * @param string value of the mla_style parameter
417
- *
418
- * @return boolean true to fetch and parse the style template, false to leave it empty
419
- */
420
- public static function use_mla_gallery_style_filter( $use_style_template, $style_template_name ) {
421
- //error_log( 'MLABuddyPressHooksExample::use_mla_gallery_style_filter $use_style_template = ' . var_export( $use_style_template, true ), 0 );
422
- //error_log( 'MLABuddyPressHooksExample::use_mla_gallery_style_filter $style_template_name = ' . var_export( $style_template_name, true ), 0 );
423
-
424
- /*
425
- * Filters must return the first argument passed in, unchanged or updated
426
- */
427
- return $use_style_template;
428
- } // use_mla_gallery_style_filter
429
-
430
- /**
431
- * MLA Gallery Style Values
432
- *
433
- * The "Values" series of filters gives you a chance to modify the substitution parameter values
434
- * before they are used to complete the associated template (in the corresponding "Parse" filter).
435
- * It is called just before the values are used to parse the associated template.
436
- * You can add, change or delete parameters as needed.
437
- *
438
- * @since 1.00
439
- *
440
- * @param array parameter_name => parameter_value pairs
441
- *
442
- * @return array updated substitution parameter name => value pairs
443
- */
444
- public static function mla_gallery_style_values_filter( $style_values ) {
445
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_style_values_filter $style_values = ' . var_export( $style_values, true ), 0 );
446
-
447
- /*
448
- * You also have access to the PHP Super Globals, e.g., $_REQUEST, $_SERVER
449
- */
450
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_style_values_filter $_REQUEST = ' . var_export( $_REQUEST, true ), 0 );
451
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_style_values_filter $_SERVER[ REQUEST_URI ] = ' . var_export( $_SERVER['REQUEST_URI'], true ), 0 );
452
-
453
- /*
454
- * You can use the WordPress globals like $wp_query, $wpdb and $table_prefix as well.
455
- * Note that $wp_query contains values for the post/page query, NOT the [mla_gallery] query.
456
- */
457
- global $wp_query;
458
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_style_values_filter $wp_query->query = ' . var_export( $wp_query->query, true ), 0 );
459
-
460
- return $style_values;
461
- } // mla_gallery_style_values_filter
462
 
463
  /**
464
- * MLA Gallery Style Template
465
  *
466
- * The "Template" series of filters gives you a chance to modify the template value before
467
- * it is used to generate the HTML markup (in the corresponding "Parse" filter).
468
- * It is called just before the template is used to generate the markup.
469
- * You can modify the template as needed.
470
- *
471
- * @since 1.00
472
  *
473
- * @param string template used to generate the HTML markup
474
  *
475
- * @return string updated template
 
476
  */
477
- public static function mla_gallery_style_template_filter( $style_template ) {
478
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_style_template_filter $style_template = ' . var_export( $style_template, true ), 0 );
479
 
480
- return $style_template;
481
- } // mla_gallery_style_template_filter
 
482
 
483
- /**
484
- * MLA Gallery Style Parse
485
- *
486
- * The "Parse" series of filters gives you a chance to modify or replace the HTML markup
487
- * that will be added to the [mla_gallery] output. It is called just after the values array
488
- * (updated in the corresponding "Values" filter) is combined (parsed) with the template.
489
- * You can modify the HTML markup already prepared or start over with the template and the
490
- * substitution values.
491
- *
492
- * @since 1.00
493
- *
494
- * @param string HTML markup returned by the template parser
495
- * @param string template used to generate the HTML markup
496
- * @param array parameter_name => parameter_value pairs
497
- *
498
- * @return array updated HTML markup for gallery output
499
- */
500
- public static function mla_gallery_style_parse_filter( $html_markup, $style_template, $style_values ) {
501
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_style_parse_filter $html_markup = ' . var_export( $html_markup, true ), 0 );
502
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_style_parse_filter $style_template = ' . var_export( $style_template, true ), 0 );
503
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_style_parse_filter $style_values = ' . var_export( $style_values, true ), 0 );
504
 
505
- return $html_markup;
506
- } // mla_gallery_style_parse_filter
 
507
 
508
- /**
509
- * MLA Gallery Open Values
510
- *
511
- * Note: The $markup_values array is shared among the open, row open, row close and close functions.
512
- * It is also used to initialize the $item_values array.
513
- *
514
- * @since 1.00
515
- *
516
- * @param array parameter_name => parameter_value pairs
517
- *
518
- * @return array updated substitution parameter name => value pairs
519
- */
520
- public static function mla_gallery_open_values_filter( $markup_values ) {
521
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_open_values_filter $markup_values = ' . var_export( $markup_values, true ), 0 );
522
 
523
- return $markup_values;
524
- } // mla_gallery_open_values_filter
525
 
526
  /**
527
- * MLA Gallery Open Template
528
  *
529
- * @since 1.00
 
530
  *
531
- * @param string template used to generate the HTML markup
532
  *
533
- * @return string updated template
534
  */
535
- public static function mla_gallery_open_template_filter( $open_template ) {
536
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_open_template_filter $open_template = ' . var_export( $open_template, true ), 0 );
537
-
538
- return $open_template;
539
- } // mla_gallery_open_template_filter
 
 
 
 
 
 
 
540
 
541
  /**
542
- * MLA Gallery Open Parse
543
  *
544
- * @since 1.00
545
  *
546
- * @param string HTML markup returned by the template parser
547
- * @param string template used to generate the HTML markup
548
- * @param array parameter_name => parameter_value pairs
549
- *
550
- * @return array updated HTML markup for gallery output
551
  */
552
- public static function mla_gallery_open_parse_filter( $html_markup, $open_template, $markup_values ) {
553
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_open_parse_filter $html_markup = ' . var_export( $html_markup, true ), 0 );
554
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_open_parse_filter $open_template = ' . var_export( $open_template, true ), 0 );
555
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_open_parse_filter $markup_values = ' . var_export( $markup_values, true ), 0 );
556
-
557
- return $html_markup;
558
- } // mla_gallery_open_parse_filter
559
 
560
  /**
561
- * MLA Gallery Style
562
  *
563
- * This is an old filter retained for compatibility with earlier MLA versions.
564
- * You will probably find the "Values" and "Parse" filters more useful.
565
  *
566
- * @since 1.00
567
  *
568
- * @param string HTML markup for "gallery style" and "gallery open", combined
569
- * @param array parameter_name => parameter_value pairs for gallery style
570
- * @param array parameter_name => parameter_value pairs for gallery open
571
- * @param string template used to generate the HTML markup for gallery style
572
- * @param string template used to generate the HTML markup for gallery open
573
  *
574
- * @return array updated HTML markup for "gallery style" and "gallery open" output
 
575
  */
576
- public static function mla_gallery_style_filter( $html_markup, $style_values, $open_values, $style_template, $open_template ) {
577
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_style_filter $html_markup = ' . var_export( $html_markup, true ), 0 );
578
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_style_filter $style_values = ' . var_export( $style_values, true ), 0 );
579
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_style_filter $open_values = ' . var_export( $open_values, true ), 0 );
580
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_style_filter $style_template = ' . var_export( $style_template, true ), 0 );
581
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_style_filter $open_template = ' . var_export( $open_template, true ), 0 );
582
 
583
- return $html_markup;
584
- } // mla_gallery_style_filter
 
 
 
 
 
 
 
585
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
586
  /**
587
- * MLA Gallery Row Open Values
588
  *
589
- * @since 1.00
590
- *
591
- * @param array parameter_name => parameter_value pairs
592
- *
593
- * @return array updated substitution parameter name => value pairs
594
  */
595
- public static function mla_gallery_row_open_values_filter( $markup_values ) {
596
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_row_open_values_filter $markup_values = ' . var_export( $markup_values, true ), 0 );
597
-
598
- return $markup_values;
599
- } // mla_gallery_row_open_values_filter
600
-
 
 
 
 
 
601
  /**
602
- * MLA Gallery Row Open Template
603
- *
604
- * @since 1.00
605
- *
606
- * @param string template used to generate the HTML markup
607
- *
608
- * @return string updated template
609
  */
610
- public static function mla_gallery_row_open_template_filter( $row_open_template ) {
611
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_row_open_template_filter $row_open_template = ' . var_export( $row_open_template, true ), 0 );
 
612
 
613
- return $row_open_template;
614
- } // mla_gallery_row_open_template_filter
615
 
616
  /**
617
- * MLA Gallery Row Open Parse
618
- *
619
- * @since 1.00
620
- *
621
- * @param string HTML markup returned by the template parser
622
- * @param string template used to generate the HTML markup
623
- * @param array parameter_name => parameter_value pairs
624
- *
625
- * @return array updated HTML markup for gallery output
626
- */
627
- public static function mla_gallery_row_open_parse_filter( $html_markup, $row_open_template, $markup_values ) {
628
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_row_open_parse_filter $html_markup = ' . var_export( $html_markup, true ), 0 );
629
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_row_open_parse_filter $row_open_template = ' . var_export( $row_open_template, true ), 0 );
630
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_row_open_parse_filter $markup_values = ' . var_export( $markup_values, true ), 0 );
631
-
632
- return $html_markup;
633
- } // mla_gallery_row_open_parse_filter
634
-
635
- /* FROM buddypress-media rt-template-functions.php
636
-
637
- function rtmedia_get_cover_art_src( $id ) {
638
- $model = new RTMediaModel();
639
- $media = $model->get( array( "id" => $id ) );
640
- $cover_art = $media[ 0 ]->cover_art;
641
- if ( $cover_art != "" ){
642
- if ( is_numeric( $cover_art ) ){
643
- $thumbnail_info = wp_get_attachment_image_src( $cover_art, 'full' );
644
-
645
- return $thumbnail_info[ 0 ];
646
- } else {
647
- return $cover_art;
648
- }
649
- } else {
650
- return false;
651
  }
652
- }
653
- */
654
-
655
  /**
656
  * MLA Gallery Item Values
657
  *
658
  * @since 1.00
659
  *
660
- * @param array parameter_name => parameter_value pairs
661
- *
662
- * @return array updated substitution parameter name => value pairs
663
  */
664
- public static function mla_gallery_item_values_filter( $item_values ) {
665
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_item_values_filter $item_values = ' . var_export( $item_values, true ), 0 );
666
 
667
  /*
668
  * We use a shortcode parameter of our own to apply our filters on a gallery-by-gallery basis,
@@ -672,13 +425,15 @@ function rtmedia_get_cover_art_src( $id ) {
672
  if ( ! isset( self::$shortcode_attributes['buddypress_urls'] ) ) {
673
  return $item_values; // leave them unchanged
674
  }
675
-
 
676
  if ( isset( self::$wp_query_properties ['post_info'][ $item_values['attachment_ID'] ] ) ) {
677
  $post_info = self::$wp_query_properties ['post_info'][ $item_values['attachment_ID'] ];
678
  } else {
679
  return $item_values; // no matching rtMedia item
680
  }
681
-
 
682
  $new_url = $item_values['site_url'] . '/members/' . $post_info->user_nicename . '/media/' . $post_info->id . '/';
683
  $new_link = str_replace( $item_values['link_url'], $new_url, $item_values['link'] );
684
 
@@ -699,22 +454,22 @@ function rtmedia_get_cover_art_src( $id ) {
699
  if ( ! empty( $post_info->cover_art ) ) {
700
  if ( is_numeric( $post_info->cover_art ) ){
701
  $thumbnail_info = wp_get_attachment_image_src( $post_info->cover_art, 'thumbnail' );
702
-
703
  if ( false === $thumbnail_info ) {
704
  $thumbnail_info = wp_get_attachment_image_src( $post_info->cover_art, 'full' );
705
  }
706
-
707
  if ( is_array( $thumbnail_info ) ) {
708
  $post_info->cover_art = $thumbnail_info[ 0 ];
709
  } else {
710
  $post_info->cover_art = '';
711
  }
712
  }
713
-
714
  if ( ! empty( $post_info->cover_art ) ) {
715
  $new_thumbnail = '<img width="150" height="150" src="' . $post_info->cover_art . '" class="attachment-thumbnail" alt="' . $item_values['thumbnail_content'] . '" />';
716
  $new_link = str_replace( $item_values['thumbnail_content'] . '</a>', $new_thumbnail . '</a>', $new_link );
717
-
718
  $item_values['thumbnail_content'] = $new_thumbnail;
719
  $item_values['thumbnail_width'] = '150';
720
  $item_values['thumbnail_height'] = '150';
@@ -722,145 +477,12 @@ function rtmedia_get_cover_art_src( $id ) {
722
  }
723
  } // has cover art
724
  } // use cover art
725
-
726
  $item_values['link_url'] = $new_url;
727
  $item_values['link'] = $new_link;
728
-
729
  return $item_values;
730
- } // mla_gallery_item_values_filter
731
-
732
- /**
733
- * MLA Gallery Item Template
734
- *
735
- * @since 1.00
736
- *
737
- * @param string template used to generate the HTML markup
738
- *
739
- * @return string updated template
740
- */
741
- public static function mla_gallery_item_template_filter( $item_template ) {
742
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_item_template_filter $item_template = ' . var_export( $item_template, true ), 0 );
743
-
744
- return $item_template;
745
- } // mla_gallery_item_template_filter
746
-
747
- /**
748
- * MLA Gallery Item Parse
749
- *
750
- * @since 1.00
751
- *
752
- * @param string HTML markup returned by the template parser
753
- * @param string template used to generate the HTML markup
754
- * @param array parameter_name => parameter_value pairs
755
- *
756
- * @return array updated HTML markup for gallery output
757
- */
758
- public static function mla_gallery_item_parse_filter( $html_markup, $item_template, $item_values ) {
759
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_item_parse_filter $html_markup = ' . var_export( $html_markup, true ), 0 );
760
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_item_parse_filter $item_template = ' . var_export( $item_template, true ), 0 );
761
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_item_parse_filter $item_values = ' . var_export( $item_values, true ), 0 );
762
-
763
- return $html_markup;
764
- } // mla_gallery_item_parse_filter
765
-
766
- /**
767
- * MLA Gallery Row Close Values
768
- *
769
- * @since 1.00
770
- *
771
- * @param array parameter_name => parameter_value pairs
772
- *
773
- * @return array updated substitution parameter name => value pairs
774
- */
775
- public static function mla_gallery_row_close_values_filter( $markup_values ) {
776
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_row_close_values_filter $markup_values = ' . var_export( $markup_values, true ), 0 );
777
-
778
- return $markup_values;
779
- } // mla_gallery_row_close_values_filter
780
-
781
- /**
782
- * MLA Gallery Row Close Template
783
- *
784
- * @since 1.00
785
- *
786
- * @param string template used to generate the HTML markup
787
- *
788
- * @return string updated template
789
- */
790
- public static function mla_gallery_row_close_template_filter( $row_close_template ) {
791
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_row_close_template_filter $row_close_template = ' . var_export( $row_close_template, true ), 0 );
792
-
793
- return $row_close_template;
794
- } // mla_gallery_row_close_template_filter
795
-
796
- /**
797
- * MLA Gallery Row Close Parse
798
- *
799
- * @since 1.00
800
- *
801
- * @param string HTML markup returned by the template parser
802
- * @param string template used to generate the HTML markup
803
- * @param array parameter_name => parameter_value pairs
804
- *
805
- * @return array updated HTML markup for gallery output
806
- */
807
- public static function mla_gallery_row_close_parse_filter( $html_markup, $row_close_template, $markup_values ) {
808
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_row_close_parse_filter $html_markup = ' . var_export( $html_markup, true ), 0 );
809
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_row_close_parse_filter $row_close_template = ' . var_export( $row_close_template, true ), 0 );
810
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_row_close_parse_filter $markup_values = ' . var_export( $markup_values, true ), 0 );
811
-
812
- return $html_markup;
813
- } // mla_gallery_row_close_parse_filter
814
-
815
- /**
816
- * MLA Gallery Close Values
817
- *
818
- * @since 1.00
819
- *
820
- * @param array parameter_name => parameter_value pairs
821
- *
822
- * @return array updated substitution parameter name => value pairs
823
- */
824
- public static function mla_gallery_close_values_filter( $markup_values ) {
825
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_close_values_filter $markup_values = ' . var_export( $markup_values, true ), 0 );
826
-
827
- return $markup_values;
828
- } // mla_gallery_close_values_filter
829
-
830
- /**
831
- * MLA Gallery Close Template
832
- *
833
- * @since 1.00
834
- *
835
- * @param string template used to generate the HTML markup
836
- *
837
- * @return string updated template
838
- */
839
- public static function mla_gallery_close_template_filter( $close_template ) {
840
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_close_template_filter $close_template = ' . var_export( $close_template, true ), 0 );
841
-
842
- return $close_template;
843
- } // mla_gallery_close_template_filter
844
-
845
- /**
846
- * MLA Gallery Close Parse
847
- *
848
- * @since 1.00
849
- *
850
- * @param string HTML markup returned by the template parser
851
- * @param string template used to generate the HTML markup
852
- * @param array parameter_name => parameter_value pairs
853
- *
854
- * @return array updated HTML markup for gallery output
855
- */
856
- public static function mla_gallery_close_parse_filter( $html_markup, $close_template, $markup_values ) {
857
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_close_parse_filter $html_markup = ' . var_export( $html_markup, true ), 0 );
858
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_close_parse_filter $close_template = ' . var_export( $close_template, true ), 0 );
859
- //error_log( 'MLABuddyPressHooksExample::mla_gallery_close_parse_filter $markup_values = ' . var_export( $markup_values, true ), 0 );
860
-
861
- return $html_markup;
862
- } // mla_gallery_close_parse_filter
863
-
864
  } // Class MLABuddyPressHooksExample
865
 
866
  /*
1
  <?php
2
  /**
3
+ * Provides [mla_gallery] parameters to filter items, generate rtMedia URLs and substitute cover art
4
  *
5
+ * In this example:
 
 
6
  *
7
+ * 1. The WordPress "attachment/media page" links are replaced by "BuddyPress/rtMedia page"
8
+ * links. For audio and video files, an option is provided to substitute the "cover_art"
9
+ * thumbnail image for the item Title in the thumbnail_content.
10
+ *
11
+ * A custom "buddypress_urls" parameter activates the URL re-write when not empty.
12
+ * If the parameter value is "cover" cover art will be substituted for audio/video
13
+ * icons. For example:
14
+ * [mla_gallery post_parent=all post_mime_type=video buddypress_urls=cover]
15
+ * displays cover art for all Video items in the Media Library.
16
+ *
17
+ * 2. A custom "rtmedia=true" parameter filters the items returned by the [mla_gallery]
18
+ * query and removes any items that do not have an rtMedia ID.
19
+ *
20
+ * 3. A custom "rtmedia=gallery" parameter filters the items returned by the [mla_gallery]
21
+ * query and uses [rtmedia_gallery] to display the items that have an rtMedia ID.
22
+ *
23
+ * This example plugin uses eight of the many filters available in the [mla_gallery] shortcode
24
+ * and illustrates some of the techniques you can use to customize the gallery display.
25
+ *
26
+ * Created for support topic "Overwhelmed. Help my shortcode out? :)"
27
+ * opened on 8/3/2016 by "tweakben".
28
+ * https://wordpress.org/support/topic/overwhelmed-help-my-shortcode-out/
29
+ *
30
+ * @package MLA BuddyPress & rtMedia Example
31
+ * @version 1.06
32
  */
33
 
34
  /*
35
+ Plugin Name: MLA BuddyPress & rtMedia Example
36
  Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
37
+ Description: Provides [mla_gallery] parameters to filter items, generate rtMedia URLs and substitute cover art
38
  Author: David Lingren
39
+ Version: 1.06
40
  Author URI: http://fairtradejudaica.org/our-story/staff/
41
 
42
+ Copyright 2013 - 2016 David Lingren
43
 
44
  This program is free software; you can redistribute it and/or modify
45
  it under the terms of the GNU General Public License as published by
58
  /**
59
  * Class MLA BuddyPress Hooks Example hooks all of the filters provided by the [mla_gallery] shortcode
60
  *
61
+ * @package MLA BuddyPress & rtMedia Example
 
 
 
62
  * @since 1.00
63
  */
64
  class MLABuddyPressHooksExample {
66
  * Initialization function, similar to __construct()
67
  *
68
  * @since 1.00
 
 
69
  */
70
  public static function initialize() {
71
+
72
+ add_filter( 'rtmedia_media_query', 'MLABuddyPressHooksExample::my_modify_media_query', 9, 3 );
73
+ add_filter( 'rtmedia_allowed_query', 'MLABuddyPressHooksExample::my_rtmedia_allowed_attributes_parameter_in_query', 99 );
74
+ add_action( 'rtmedia_before_media_gallery', 'MLABuddyPressHooksExample::my_remove_rtmedia_model_shortcode_query_attributes', 10, 3 );
75
+
76
+ // The filters are only useful for front-end posts/pages; exit if in the admin section
77
  if ( is_admin() )
78
  return;
79
 
80
+ add_filter( 'mla_gallery_attributes', 'MLABuddyPressHooksExample::mla_gallery_attributes', 10, 1 );
81
+ add_action( 'mla_gallery_wp_query_object', 'MLABuddyPressHooksExample::mla_gallery_wp_query_object', 10, 1 );
82
+ add_filter( 'mla_gallery_the_attachments', 'MLABuddyPressHooksExample::mla_gallery_the_attachments', 10, 2 );
83
+ add_filter( 'mla_gallery_alt_shortcode_blacklist', 'MLABuddyPressHooksExample::mla_gallery_alt_shortcode_blacklist', 10, 1 );
84
+ add_filter( 'mla_gallery_alt_shortcode_attributes', 'MLABuddyPressHooksExample::mla_gallery_alt_shortcode_attributes', 10, 1 );
85
+ add_filter( 'mla_gallery_alt_shortcode_ids', 'MLABuddyPressHooksExample::mla_gallery_alt_shortcode_ids', 10, 3 );
86
+
87
+ add_filter( 'mla_gallery_item_values', 'MLABuddyPressHooksExample::mla_gallery_item_values', 10, 1 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  }
89
 
90
  /**
92
  *
93
  * @since 1.00
94
  *
95
+ * @var array
96
  */
97
  private static $shortcode_attributes = array();
98
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  /**
100
  * MLA Gallery (Display) Attributes
101
  *
107
  *
108
  * @since 1.00
109
  *
110
+ * @param array $shortcode_attributes The shortcode parameters passed in to the shortcode
111
  *
112
+ * @return array updated shortcode attributes
113
  */
114
+ public static function mla_gallery_attributes( $shortcode_attributes ) {
115
+ //error_log( 'MLABuddyPressHooksExample::mla_gallery_attributes $shortcode_attributes = ' . var_export( $shortcode_attributes, true ), 0 );
116
+
117
+ // Clean up the parameters we're interested in.
118
+ if ( isset( $shortcode_attributes['buddypress_urls'] ) ) {
119
+ $shortcode_attributes['buddypress_urls'] = strtolower( trim( $shortcode_attributes['buddypress_urls'] ) );
120
+ }
121
 
122
+ if ( isset( $shortcode_attributes['rtmedia'] ) ) {
123
+ $shortcode_attributes['rtmedia'] = strtolower( trim( $shortcode_attributes['rtmedia'] ) );
124
+
125
+ if ( 'gallery' === $shortcode_attributes['rtmedia'] ) {
126
+ $shortcode_attributes['mla_alt_shortcode'] = 'rtmedia_gallery';
127
+ $shortcode_attributes['mla_alt_ids_name'] = 'media_ids';
128
+ $shortcode_attributes['global'] = 'true';
129
+ }
130
+ }
131
+
132
+ // Save the attributes for use in the later filters
133
  self::$shortcode_attributes = $shortcode_attributes;
134
 
135
+ //error_log( __LINE__ . ' MLABuddyPressHooksExample::mla_gallery_attributes $shortcode_attributes = ' . var_export( $shortcode_attributes, true ), 0 );
136
  return $shortcode_attributes;
137
+ } // mla_gallery_attributes
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
 
139
  /**
140
  * Save some of the WP_Query object properties
141
  *
142
  * @since 1.00
143
  *
144
+ * @var array
145
  */
146
  private static $wp_query_properties = array();
147
+
148
  /**
149
  * MLA Gallery WP Query Object
150
  *
151
+ * If the 'buddypress_urls' parameter is present, generate an array of the
152
+ * rtMedia information for the queried items.
153
  *
154
  * @since 1.00
155
  * @uses MLAShortcodes::$mla_gallery_wp_query_object
156
  *
157
+ * @param array $query_arguments The arguments passed to WP_Query->query
 
 
158
  */
159
+ public static function mla_gallery_wp_query_object( $query_arguments ) {
160
+ //error_log( 'MLABuddyPressHooksExample::mla_gallery_wp_query_object $query_arguments = ' . var_export( $query_arguments, true ), 0 );
161
+
162
  self::$wp_query_properties = array();
163
  self::$wp_query_properties ['post_count'] = MLAShortcodes::$mla_gallery_wp_query_object->post_count;
164
+
165
  if ( empty( self::$shortcode_attributes['buddypress_urls'] ) ) {
166
  return; // Don't need custom URLs
167
  }
168
+
169
  if ( 0 == self::$wp_query_properties ['post_count'] ) {
170
  return; // Empty gallery - nothing to do
171
  }
172
+
173
  global $wpdb;
174
+
175
  // Assemble the WordPress attachment IDs
176
  $post_info = array();
177
  foreach( MLAShortcodes::$mla_gallery_wp_query_object->posts as $value ) {
185
  $query[] = "SELECT rtm.id, rtm.media_id, rtm.media_author, rtm.media_type, rtm.cover_art, u.user_nicename FROM {$wpdb->prefix}rt_rtm_media AS rtm";
186
  $query[] = "LEFT JOIN {$wpdb->users} as u";
187
  $query[] = "ON (rtm.media_author = u.ID)";
188
+
189
  $placeholders = array();
190
  foreach ( $post_info as $value ) {
191
  $placeholders[] = '%s';
203
  $post_info[ $value->media_id ] = $value;
204
  }
205
  }
206
+
207
+ //error_log( __LINE__ . ' MLABuddyPressHooksExample::mla_gallery_wp_query_object $post_info = ' . var_export( $post_info, true ), 0 );
208
  self::$wp_query_properties ['post_info'] = $post_info;
209
+ } // mla_gallery_wp_query_object
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
 
211
  /**
212
+ * MLA Gallery The Attachments
213
  *
214
+ * If the 'rtmedia' parameter is present, removes items from the attachments array
215
+ * unless they are in the 'post_info' array of rtMedia items.
 
 
 
 
216
  *
217
+ * @since 1.06
218
  *
219
+ * @param NULL $filtered_attachments initially NULL, indicating no substitution.
220
+ * @param array $attachments WP_Post objects returned by WP_Query->query, passed by reference
221
  */
222
+ public static function mla_gallery_the_attachments( $filtered_attachments, $attachments ) {
223
+ //error_log( 'MLABuddyPressHooksExample::mla_gallery_the_attachments $attachments = ' . var_export( $attachments, true ), 0 );
224
 
225
+ if ( ! ( isset( self::$shortcode_attributes['rtmedia'] ) && in_array( self::$shortcode_attributes['rtmedia'], array( 'gallery', 'true' ) ) ) ) {
226
+ return $filtered_attachments;
227
+ }
228
 
229
+ $found_rows = isset( $attachments['found_rows'] ) ? $attachments['found_rows'] : count( $attachments );
230
+ $changed = false;
231
+ foreach( $attachments as $index => $attachment ) {
232
+ if ( ! is_numeric( $index ) ) {
233
+ continue;
234
+ }
235
+
236
+ if ( isset( self::$wp_query_properties ['post_info'][ $attachment->ID ] ) ) {
237
+ continue;
238
+ }
239
+
240
+ unset( $attachments[ $index ] );
241
+ $found_rows--;
242
+ $changed = true;
243
+ }
 
 
 
 
 
 
244
 
245
+ if ( isset( $attachments['found_rows'] ) ) {
246
+ $attachments['found_rows'] = $found_rows;
247
+ }
248
 
249
+ //error_log( 'MLABuddyPressHooksExample::mla_gallery_the_attachments updated $attachments = ' . var_export( $attachments, true ), 0 );
 
 
 
 
 
 
 
 
 
 
 
 
 
250
 
251
+ return $changed ? $attachments : NULL;
252
+ } // mla_gallery_the_attachments
253
 
254
  /**
255
+ * MLA Gallery Alternate Shortcode Blacklist
256
  *
257
+ * Removes the parameters specific to this example plugin and
258
+ * parameters rtMedia does not allow.
259
  *
260
+ * @since 1.06
261
  *
262
+ * @param array $blacklist parameter_name => parameter_value pairs
263
  */
264
+ public static function mla_gallery_alt_shortcode_blacklist( $blacklist ) {
265
+ $blacklist['buddypress_urls'] = '';
266
+ $blacklist['rtmedia'] = '';
267
+
268
+ $blacklist['columns'] = '';
269
+ $blacklist['size'] = '';
270
+ $blacklist['link'] = '';
271
+ $blacklist['option_all_value'] = '';
272
+ //error_log( __LINE__ . ' mla_gallery_alt_shortcode_blacklist blacklist = ' . var_export( $blacklist, true ), 0 );
273
+
274
+ return $blacklist;
275
+ } // mla_gallery_alt_shortcode_blacklist
276
 
277
  /**
278
+ * MLA Gallery Alternate Shortcode Attributes
279
  *
280
+ * @since 1.06
281
  *
282
+ * @param array $attr parameter_name => parameter_value pairs
 
 
 
 
283
  */
284
+ public static function mla_gallery_alt_shortcode_attributes( $attr ) {
285
+ //error_log( __LINE__ . ' mla_gallery_alt_shortcode_attributes attr = ' . var_export( $attr, true ), 0 );
286
+ //$attr['per_page'] = '1';
287
+
288
+ return $attr;
289
+ } // mla_gallery_alt_shortcode_attributes
 
290
 
291
  /**
292
+ * MLA Gallery Alternate Shortcode IDs
293
  *
294
+ * Extracts item IDs from the attachments array, converts them to rtMedia IDs and
295
+ * returns them for use in the alternative gallery shortcode processing.
296
  *
297
+ * @since 1.06
298
  *
299
+ * @param array $ids empty array, indicating no substitution
300
+ * @param string $ids_name parameter name
301
+ * @param array $attachments WP_Post objects returned by WP_Query->query, passed by reference
 
 
302
  *
303
+ * @return array Substitute array of ID (or other) values to populate the parameter
304
+ * @return string Complete 'ids_name="value,value"' parameter or an empty string to omit parameter
305
  */
306
+ public static function mla_gallery_alt_shortcode_ids( $ids, $ids_name, $attachments ) {
307
+ //error_log( __LINE__ . " mla_gallery_alt_shortcode_ids( $ids_name ) attachments = " . var_export( $attachments, true ), 0 );
308
+
309
+ if ( ! ( isset( self::$shortcode_attributes['rtmedia'] ) && ( 'gallery' === self::$shortcode_attributes['rtmedia'] ) ) ) {
310
+ return $ids;
311
+ }
312
 
313
+ foreach( $attachments as $index => $attachment ) {
314
+ if ( ! is_numeric( $index ) ) {
315
+ continue;
316
+ }
317
+
318
+ if ( isset( self::$wp_query_properties ['post_info'][ $attachment->ID ] ) ) {
319
+ $ids[] = self::$wp_query_properties ['post_info'][ $attachment->ID ]->id;
320
+ }
321
+ }
322
 
323
+ //error_log( __LINE__ . " mla_gallery_alt_shortcode_ids( $ids_name ) ids = " . var_export( $ids, true ), 0 );
324
+ return $ids;
325
+ } // mla_gallery_alt_shortcode_ids
326
+
327
+ /**
328
+ * Modifies the media query. It adds the filter to alter the WHERE parameter of the
329
+ * MySQL query and removes the context_id and context if set ( by the rtMedia plugin )
330
+ *
331
+ * @param array $media_query Refer the `rtmedia_media_query` filter defined in the
332
+ * rtMedia plugin
333
+ * @param array $action_query
334
+ * @param array $query
335
+ *
336
+ * @return array $media_query
337
+ */
338
+ public static function my_modify_media_query( $media_query, $action_query, $query ) {
339
+ //error_log( __LINE__ . ' my_modify_media_query media_query = ' . var_export( $media_query, true ), 0 );
340
+ //error_log( __LINE__ . ' my_modify_media_query action_query = ' . var_export( $action_query, true ), 0 );
341
+ //error_log( __LINE__ . ' my_modify_media_query query = ' . var_export( $query, true ), 0 );
342
+
343
+ global $rtmedia_query, $media_query_clone_ids;
344
+
345
+ // Store the `media_ids` parameter to be used in the rtmedia-model-where-query filter
346
+ $media_query_clone_ids = $media_query;
347
+
348
+ if ( isset( $media_query['media_ids'] ) && '' != $media_query['media_ids'] ) {
349
+
350
+ // Add the filter to modify the where parameter
351
+ add_filter( 'rtmedia-model-where-query', 'MLABuddyPressHooksExample::my_rtmedia_model_shortcode_where_query_attributes', 10, 3 );
352
+
353
+ // unset it, so that it wont affect the other rtmedia_gallery shortcodes on the same page
354
+ unset( $media_query['media_ids'] );
355
+
356
+ // unset from global query so that multiple gallery shortcode can work
357
+ if ( isset( $rtmedia_query->query ) && isset( $rtmedia_query->query['media_ids'] ) ) {
358
+ unset( $rtmedia_query->query['media_ids'] );
359
+ }
360
+
361
+ if ( isset( $media_query['context_id'] ) ) {
362
+ unset( $media_query['context_id'] );
363
+ }
364
+
365
+ if ( isset( $media_query['context'] ) ) {
366
+ unset( $media_query['context'] );
367
+ }
368
+ }
369
+
370
+ return $media_query;
371
+ }
372
+
373
  /**
374
+ * Modify the WHERE parameter
375
  *
376
+ * For the parameter description refer the `rtmedia-model-where-query` filter defined in the
377
+ * rtMedia plugin
 
 
 
378
  */
379
+ public static function my_rtmedia_model_shortcode_where_query_attributes( $where, $table_name, $join ) {
380
+ global $rtmedia_query, $media_query_clone_ids;
381
+
382
+ // Modify the WHERE parameter of the MySQL query
383
+ if ( isset( $media_query_clone_ids['media_ids'] ) && '' != $media_query_clone_ids['media_ids'] ) {
384
+ $where .= " AND $table_name.id IN ( " . $media_query_clone_ids['media_ids'] . ' )';
385
+ }
386
+
387
+ return $where;
388
+ }
389
+
390
  /**
391
+ * Remove `rtmedia-model-where-query` filter once our job is done
392
+ * so that it wont affect the other shortcodes
 
 
 
 
 
393
  */
394
+ public static function my_remove_rtmedia_model_shortcode_query_attributes() {
395
+ remove_filter( 'rtmedia-model-where-query', 'my_rtmedia_model_shortcode_where_query_attributes', 10, 3 );
396
+ }
397
 
 
 
398
 
399
  /**
400
+ * Sets `media_ids` parameter in rtmedia query
401
+ *
402
+ * @param type $param
403
+ *
404
+ * @return array
405
+ */
406
+ public static function my_rtmedia_allowed_attributes_parameter_in_query( $param = array() ) {
407
+ $param[] = 'media_ids';
408
+ return $param;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
409
  }
 
 
 
410
  /**
411
  * MLA Gallery Item Values
412
  *
413
  * @since 1.00
414
  *
415
+ * @param array $item_values parameter_name => parameter_value pairs
 
 
416
  */
417
+ public static function mla_gallery_item_values( $item_values ) {
418
+ //error_log( 'MLABuddyPressHooksExample::mla_gallery_item_values $item_values = ' . var_export( $item_values, true ), 0 );
419
 
420
  /*
421
  * We use a shortcode parameter of our own to apply our filters on a gallery-by-gallery basis,
425
  if ( ! isset( self::$shortcode_attributes['buddypress_urls'] ) ) {
426
  return $item_values; // leave them unchanged
427
  }
428
+
429
+ // post_info holds the rtMedia information about the item
430
  if ( isset( self::$wp_query_properties ['post_info'][ $item_values['attachment_ID'] ] ) ) {
431
  $post_info = self::$wp_query_properties ['post_info'][ $item_values['attachment_ID'] ];
432
  } else {
433
  return $item_values; // no matching rtMedia item
434
  }
435
+
436
+ // Rewrite the URL to reference the rtMedia version of the item
437
  $new_url = $item_values['site_url'] . '/members/' . $post_info->user_nicename . '/media/' . $post_info->id . '/';
438
  $new_link = str_replace( $item_values['link_url'], $new_url, $item_values['link'] );
439
 
454
  if ( ! empty( $post_info->cover_art ) ) {
455
  if ( is_numeric( $post_info->cover_art ) ){
456
  $thumbnail_info = wp_get_attachment_image_src( $post_info->cover_art, 'thumbnail' );
457
+
458
  if ( false === $thumbnail_info ) {
459
  $thumbnail_info = wp_get_attachment_image_src( $post_info->cover_art, 'full' );
460
  }
461
+
462
  if ( is_array( $thumbnail_info ) ) {
463
  $post_info->cover_art = $thumbnail_info[ 0 ];
464
  } else {
465
  $post_info->cover_art = '';
466
  }
467
  }
468
+
469
  if ( ! empty( $post_info->cover_art ) ) {
470
  $new_thumbnail = '<img width="150" height="150" src="' . $post_info->cover_art . '" class="attachment-thumbnail" alt="' . $item_values['thumbnail_content'] . '" />';
471
  $new_link = str_replace( $item_values['thumbnail_content'] . '</a>', $new_thumbnail . '</a>', $new_link );
472
+
473
  $item_values['thumbnail_content'] = $new_thumbnail;
474
  $item_values['thumbnail_width'] = '150';
475
  $item_values['thumbnail_height'] = '150';
477
  }
478
  } // has cover art
479
  } // use cover art
480
+
481
  $item_values['link_url'] = $new_url;
482
  $item_values['link'] = $new_link;
483
+
484
  return $item_values;
485
+ } // mla_gallery_item_values
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
486
  } // Class MLABuddyPressHooksExample
487
 
488
  /*
examples/plugins/get-post-galleries-example.php ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hooks a WordPress filter to supply a list of the items returned from [mla_gallery] shortcodes
4
+ *
5
+ * In this example the WordPress "get_post_galleries()" filter is applied and the post/page content
6
+ * is scanned for any [mla_gallery] shortcodes. If one or more are found they are processed and an
7
+ * array of the items they generate is added to the filter results.
8
+ *
9
+ * NOTE: To compensate for a shortcoming of the WordPress filter, there must be at least one [gallery]
10
+ * shortcode in the post/page content. You can use [gallery ids=0] as a placeholder shortcode to
11
+ * trigger the filter without returning any results to the post/page.
12
+ *
13
+ * The "get_post_galleries()" function is called by, for example, the Dominant Colors Lazy Loading
14
+ * plugin by Manuel Wieser.
15
+ *
16
+ * Created for support topic "Lazy load and masonry layout"
17
+ * opened on 10/18/2016 by "ghislainsc".
18
+ * https://wordpress.org/support/topic/lazy-load-and-masonry-layout/
19
+ *
20
+ * @package Get Post Galleries Example
21
+ * @version 1.00
22
+ */
23
+
24
+ /*
25
+ Plugin Name: Get Post Galleries Example
26
+ Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
27
+ Description: Hooks a WordPress filter to supply a list of the items returned from [mla_gallery] shortcodes
28
+ Author: David Lingren
29
+ Version: 1.00
30
+ Author URI: http://fairtradejudaica.org/our-story/staff/
31
+
32
+ Copyright 2016 David Lingren
33
+
34
+ This program is free software; you can redistribute it and/or modify
35
+ it under the terms of the GNU General Public License as published by
36
+ the Free Software Foundation; either version 2 of the License, or
37
+ (at your option) any later version.
38
+
39
+ This program is distributed in the hope that it will be useful,
40
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
41
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42
+ GNU General Public License for more details.
43
+
44
+ You can get a copy of the GNU General Public License by writing to the
45
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
46
+ */
47
+
48
+ /**
49
+ * Class Get Post Galleries Example hooks a WordPress filter to supply a list of the
50
+ * items returned from [mla_gallery] shortcodes
51
+ *
52
+ * @package Get Post Galleries Example
53
+ * @since 1.00
54
+ */
55
+ class GetPostGalleriesExample {
56
+ /**
57
+ * Initialization function, similar to __construct()
58
+ *
59
+ * @since 1.00
60
+ */
61
+ public static function initialize() {
62
+
63
+ add_filter( 'get_post_galleries', 'GetPostGalleriesExample::get_post_galleries', 10, 2 );
64
+ }
65
+
66
+ /**
67
+ * Get Post Galleries Filter
68
+ *
69
+ * This filter retrieves [mla_gallery] items from the contents of a post
70
+ *
71
+ * @since 1.00
72
+ *
73
+ * @param array $galleries Associative array of all found post galleries.
74
+ * @param WP_Post $post Post object.
75
+ */
76
+ public static function get_post_galleries( $galleries, $current_post ) {
77
+ global $post;
78
+
79
+ $count = preg_match_all( "/\[mla_gallery([^\\]]*)\\]/", $current_post->post_content, $matches, PREG_PATTERN_ORDER );
80
+ if ( $count ) {
81
+ $save_post = $post;
82
+ $post = $current_post; // set global variable for mla_gallery_shortcode(
83
+ add_filter( 'mla_gallery_item_values', 'GetPostGalleriesExample::mla_gallery_item_values', 10, 1 );
84
+
85
+ foreach ( $matches[1] as $index => $match ) {
86
+ // Filter out shortcodes that are not an exact match
87
+ if ( empty( $match ) || ( ' ' == substr( $match, 0, 1 ) ) ) {
88
+ // Remove trailing "/" from XHTML-style self-closing shortcodes
89
+ $query = trim( rtrim( $matches[1][$index], '/' ) );
90
+ self::$item_values = array();
91
+ $results = do_shortcode( '[mla_gallery ' . $query . ' cache_results=false update_post_meta_cache=false update_post_term_cache=false]' );
92
+ $ids = array();
93
+ $src = array();
94
+ foreach( self::$item_values as $ID => $url ) {
95
+ $ids[] = $ID;
96
+ $src[] = $url;
97
+ }
98
+
99
+ if ( !empty( $ids ) ) {
100
+ $galleries[] = array ( 'ids' => implode( ',', $ids ), 'src' => $src, );
101
+ }
102
+ } // exact match
103
+ } // foreach $match
104
+
105
+ remove_filter( 'mla_gallery_item_values', 'GetPostGalleriesExample::mla_gallery_item_values', 10, 1 );
106
+ $post = $save_post;
107
+ } // if $count
108
+
109
+ return $galleries;
110
+ } // get_post_galleries
111
+
112
+ /**
113
+ * Save the item values
114
+ *
115
+ * @since 1.00
116
+ *
117
+ * @var array
118
+ */
119
+ private static $item_values = array();
120
+
121
+ /**
122
+ * Collect the information needed by self::get_post_galleries()
123
+ *
124
+ * @since 1.00
125
+ *
126
+ * @param array $item_values parameter_name => parameter_value pairs
127
+ */
128
+ public static function mla_gallery_item_values( $item_values ) {
129
+ self::$item_values[ $item_values['attachment_ID'] ] = $item_values['thumbnail_url'];
130
+
131
+ return $item_values;
132
+ } // mla_gallery_item_values
133
+ } // Class GetPostGalleriesExample
134
+
135
+ /*
136
+ * Install the filters at an early opportunity
137
+ */
138
+ add_action('init', 'GetPostGalleriesExample::initialize');
139
+ ?>
examples/plugins/mla-a-z-cloud-example.php CHANGED
@@ -1,10 +1,35 @@
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  /*
3
  Plugin Name: MLA A-Z Cloud and Collapse-o-Matic Example
4
  Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
5
  Description: Provides an "A-Z cloud/pagination" and expandable gallery example
6
  Author: David Lingren
7
- Version: 1.00
8
  Author URI: http://fairtradejudaica.org/our-story/staff/
9
 
10
  Copyright 2015 David Lingren
@@ -380,7 +405,7 @@ class MLAAtoZCloudExample {
380
  $ttids = array();
381
 
382
  // Find taxonomy argument, if present, and collect terms
383
- $taxonomies = get_taxonomies( array( 'object_type' => array( 'attachment' ) ), 'names' );
384
  foreach( $taxonomies as $taxonomy ) {
385
  if ( empty( $attr[ $taxonomy ] ) ) {
386
  continue;
1
  <?php
2
+ /**
3
+ * Implements a solution for the alphabetical division and expandable gallery display application features.
4
+ *
5
+ * The example plugin contains two custom shortcodes:
6
+ *
7
+ * 1.[az-cloud] – provides an "A-Z cloud" that tabulates the items starting with each letter of the
8
+ * alphabet and generates links that include a query argument with the selected letter.
9
+ * 2.[az_gallery] – formats a "gallery" list of the items starting with the selected letter. It uses a
10
+ * file naming convention to collect all the "parts" of a particular "item set" and display them as
11
+ * a second-level list. Uses Collapse-o-matic (optionally) to control the display of items.
12
+ *
13
+ * Both shortcodes have parameters to filter by MIME type and/or taxonomy term and to change the
14
+ * HTML tags surrounding the items.
15
+ *
16
+ * This example plugin uses three of the many filters available in the [mla_gallery] shortcode
17
+ * and illustrates some of the techniques you can use to customize the gallery display.
18
+ *
19
+ * Created for support topic "Alphabetical pagination"
20
+ * opened on 5/16/2015 by "kevincowart111".
21
+ * https://wordpress.org/support/topic/alphabetical-pagination-2
22
+ *
23
+ * @package MLA Child Term Hooks Example
24
+ * @version 1.01
25
+ */
26
+
27
  /*
28
  Plugin Name: MLA A-Z Cloud and Collapse-o-Matic Example
29
  Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
30
  Description: Provides an "A-Z cloud/pagination" and expandable gallery example
31
  Author: David Lingren
32
+ Version: 1.01
33
  Author URI: http://fairtradejudaica.org/our-story/staff/
34
 
35
  Copyright 2015 David Lingren
405
  $ttids = array();
406
 
407
  // Find taxonomy argument, if present, and collect terms
408
+ $taxonomies = get_object_taxonomies( 'attachment', 'names' );
409
  foreach( $taxonomies as $taxonomy ) {
410
  if ( empty( $attr[ $taxonomy ] ) ) {
411
  continue;
examples/plugins/mla-bulk-edit-remap-example.php CHANGED
@@ -3,6 +3,13 @@
3
  * Performs IPTC/EXIF and Custom Field mapping at the conclusion of a Bulk Edit action,
4
  * so data sources like "terms:" are properly applied.
5
  *
 
 
 
 
 
 
 
6
  * @package MLA Bulk Edit Remap Example
7
  * @version 1.00
8
  */
3
  * Performs IPTC/EXIF and Custom Field mapping at the conclusion of a Bulk Edit action,
4
  * so data sources like "terms:" are properly applied.
5
  *
6
+ * This example plugin uses two of the "Media/Assistant Submenu Actions and Filters (Hooks)"
7
+ * and illustrates some of the techniques you can use to customize the bulk edit process.
8
+ *
9
+ * Created for support topic "Sorting based on taxonomy terms"
10
+ * opened on 4/30/2016 by "arabesco".
11
+ * https://wordpress.org/support/topic/sorting-based-on-taxonomy-terms/
12
+ *
13
  * @package MLA Bulk Edit Remap Example
14
  * @version 1.00
15
  */
examples/plugins/mla-child-term-hooks-example.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Provides an example of hooking the filters provided by the [mla_gallery] shortcode.
4
  *
5
  * In this example, a term slug within a hiearchical taxonomy (default "galleries" in
6
  * "attachment_category") is given. Each immediate child term is used to select one image
@@ -11,8 +11,12 @@
11
  * This example plugin uses three of the many filters available in the [mla_gallery] shortcode
12
  * and illustrates some of the techniques you can use to customize the gallery display.
13
  *
 
 
 
 
14
  * @package MLA Child Term Hooks Example
15
- * @version 1.00
16
  */
17
 
18
  /*
@@ -20,7 +24,7 @@ Plugin Name: MLA Child Term Hooks Example
20
  Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
21
  Description: Creates a term-specific gallery of images assigned to child terms.
22
  Author: David Lingren
23
- Version: 1.00
24
  Author URI: http://fairtradejudaica.org/our-story/staff/
25
 
26
  Copyright 2014 David Lingren
@@ -70,9 +74,9 @@ class MLAChildTermHooksExample {
70
  * $priority - default 10; lower runs earlier, higher runs later
71
  * $accepted_args - number of arguments your function accepts
72
  */
73
- add_filter( 'mla_gallery_attributes', 'MLAChildTermHooksExample::mla_gallery_attributes_filter', 10, 1 );
74
- add_filter( 'mla_gallery_query_arguments', 'MLAChildTermHooksExample::mla_gallery_query_arguments_filter', 10, 1 );
75
- add_filter( 'mla_gallery_item_values', 'MLAChildTermHooksExample::mla_gallery_item_values_filter', 10, 1 );
76
  }
77
 
78
  /**
@@ -99,13 +103,13 @@ class MLAChildTermHooksExample {
99
  *
100
  * @return array updated shortcode attributes
101
  */
102
- public static function mla_gallery_attributes_filter( $shortcode_attributes ) {
103
  /*
104
  * Save the attributes for use in the later filters
105
  */
106
  self::$shortcode_attributes = $shortcode_attributes;
107
  return $shortcode_attributes;
108
- } // mla_gallery_attributes_filter
109
 
110
  /**
111
  * Save the item => term_slug pairs
@@ -128,7 +132,7 @@ class MLAChildTermHooksExample {
128
  *
129
  * @return array updated attachment query arguments
130
  */
131
- public static function mla_gallery_query_arguments_filter( $all_query_parameters ) {
132
  /*
133
  * This example executes a custom SQL query that cannot be done with the usual
134
  * WordPress WP_Query arguments. The query results are fed back to the [mla_gallery]
@@ -160,7 +164,7 @@ class MLAChildTermHooksExample {
160
  $ttids = array();
161
 
162
  // Find taxonomy argument(s), if present, and collect terms
163
- $taxonomies = get_taxonomies( array( 'object_type' => array( 'attachment' ) ), 'names' );
164
  foreach( $taxonomies as $taxonomy ) {
165
  if ( empty( $my_query_vars[ $taxonomy ] ) ) {
166
  continue;
@@ -253,18 +257,19 @@ class MLAChildTermHooksExample {
253
  } // parameter "my_parent_terms" is present
254
 
255
  return $all_query_parameters;
256
- } // mla_gallery_query_arguments_filter
257
 
258
  /**
259
- * MLA Gallery Item Values
260
- *
 
261
  * @since 1.00
262
  *
263
  * @param array parameter_name => parameter_value pairs
264
  *
265
  * @return array updated substitution parameter name => value pairs
266
  */
267
- public static function mla_gallery_item_values_filter( $item_values ) {
268
  /*
269
  * We use a shortcode parameter of our own to apply our filters on a gallery-by-gallery basis,
270
  * leaving other [mla_gallery] instances untouched. If the "my_parent_terms" parameter is not present,
@@ -299,7 +304,7 @@ class MLAChildTermHooksExample {
299
  $href = $my_page['permalink'] . '?' . $my_page['queryarg'] . '=' . self::$term_slugs[ $item_values['attachment_ID'] ];
300
  $item_values['link'] = '<a href="' . $href . '">' . $item_values['thumbnail_content'] . '</a>';
301
  return $item_values;
302
- } // mla_gallery_item_values_filter
303
  } // Class MLAChildTermHooksExample
304
 
305
  /*
1
  <?php
2
  /**
3
+ * Creates a term-specific gallery of images assigned to child terms.
4
  *
5
  * In this example, a term slug within a hiearchical taxonomy (default "galleries" in
6
  * "attachment_category") is given. Each immediate child term is used to select one image
11
  * This example plugin uses three of the many filters available in the [mla_gallery] shortcode
12
  * and illustrates some of the techniques you can use to customize the gallery display.
13
  *
14
+ * Created for support topic "Automatic hierarchical display for hierarchical taxonomies"
15
+ * opened on 8/14/2014 by "mark-cockfield".
16
+ * https://wordpress.org/support/topic/automatic-hierarchical-display-for-hierarchical-taxonomies
17
+ *
18
  * @package MLA Child Term Hooks Example
19
+ * @version 1.01
20
  */
21
 
22
  /*
24
  Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
25
  Description: Creates a term-specific gallery of images assigned to child terms.
26
  Author: David Lingren
27
+ Version: 1.01
28
  Author URI: http://fairtradejudaica.org/our-story/staff/
29
 
30
  Copyright 2014 David Lingren
74
  * $priority - default 10; lower runs earlier, higher runs later
75
  * $accepted_args - number of arguments your function accepts
76
  */
77
+ add_filter( 'mla_gallery_attributes', 'MLAChildTermHooksExample::mla_gallery_attributes', 10, 1 );
78
+ add_filter( 'mla_gallery_query_arguments', 'MLAChildTermHooksExample::mla_gallery_query_arguments', 10, 1 );
79
+ add_filter( 'mla_gallery_item_values', 'MLAChildTermHooksExample::mla_gallery_item_values', 10, 1 );
80
  }
81
 
82
  /**
103
  *
104
  * @return array updated shortcode attributes
105
  */
106
+ public static function mla_gallery_attributes( $shortcode_attributes ) {
107
  /*
108
  * Save the attributes for use in the later filters
109
  */
110
  self::$shortcode_attributes = $shortcode_attributes;
111
  return $shortcode_attributes;
112
+ } // mla_gallery_attributes
113
 
114
  /**
115
  * Save the item => term_slug pairs
132
  *
133
  * @return array updated attachment query arguments
134
  */
135
+ public static function mla_gallery_query_arguments( $all_query_parameters ) {
136
  /*
137
  * This example executes a custom SQL query that cannot be done with the usual
138
  * WordPress WP_Query arguments. The query results are fed back to the [mla_gallery]
164
  $ttids = array();
165
 
166
  // Find taxonomy argument(s), if present, and collect terms
167
+ $taxonomies = get_object_taxonomies( 'attachment', 'names' );
168
  foreach( $taxonomies as $taxonomy ) {
169
  if ( empty( $my_query_vars[ $taxonomy ] ) ) {
170
  continue;
257
  } // parameter "my_parent_terms" is present
258
 
259
  return $all_query_parameters;
260
+ } // mla_gallery_query_arguments
261
 
262
  /**
263
+ * Generate a link for each gallery item to a separate page that displays a gallery
264
+ * of all images assigned to the term.
265
+ *
266
  * @since 1.00
267
  *
268
  * @param array parameter_name => parameter_value pairs
269
  *
270
  * @return array updated substitution parameter name => value pairs
271
  */
272
+ public static function mla_gallery_item_values( $item_values ) {
273
  /*
274
  * We use a shortcode parameter of our own to apply our filters on a gallery-by-gallery basis,
275
  * leaving other [mla_gallery] instances untouched. If the "my_parent_terms" parameter is not present,
304
  $href = $my_page['permalink'] . '?' . $my_page['queryarg'] . '=' . self::$term_slugs[ $item_values['attachment_ID'] ];
305
  $item_values['link'] = '<a href="' . $href . '">' . $item_values['thumbnail_content'] . '</a>';
306
  return $item_values;
307
+ } // mla_gallery_item_values
308
  } // Class MLAChildTermHooksExample
309
 
310
  /*
examples/plugins/mla-custom-field-search-example.php CHANGED
@@ -2,6 +2,27 @@
2
  /**
3
  * Extends the Media/Assistant "Search Media" box to custom field values
4
  *
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  * @package MLA Custom Field Search Example
6
  * @version 1.04
7
  */
@@ -31,10 +52,8 @@ Copyright 2014 - 2015 David Lingren
31
  */
32
 
33
  /**
34
- * Class MLA Custom Field Search Example hooks one of the filters provided by the MLA_List_Table class
35
- *
36
- * Call it anything you want, but give it an unlikely and hopefully unique name. Hiding everything
37
- * else inside a class means this is the only name you have to worry about.
38
  *
39
  * @package MLA Custom Field Search Example
40
  * @since 1.00
2
  /**
3
  * Extends the Media/Assistant "Search Media" box to custom field values
4
  *
5
+ * In this example, a "custom:" prefix is detected in the Media/Assistant "search media" text
6
+ * box and the search is modified to query a custom field for a specific value, e.g.,
7
+ * "custom:photo reference=123456". You can also search for partial values:
8
+ *
9
+ * - To return all items that have a non-NULL value in the field, simply enter the prefix
10
+ * "custom:" followed by the custom field name, for example, custom:File Size. You can also
11
+ * enter the custom field name and then "=*", e.g., custom:File Size=*.
12
+ * - To return all items that have a NULL value in the field, enter the custom field name and
13
+ * then "=", e.g., custom:File Size=.
14
+ * - To return all items that match one or more values, enter the prefix "custom:" followed by
15
+ * the custom field name and then "=" followed by a list of values. For example, custom:Color=red
16
+ * or custom:Color=red,green,blue. Wildcard specifications are also supported; for example, "*post"
17
+ * to match anything ending in "post" or "th*da*" to match values like "the date" and "this day".
18
+ *
19
+ * This example plugin uses four of the many filters available in the Media/Assistant Submenu
20
+ * and illustrates some of the techniques you can use to customize the submenu table display.
21
+ *
22
+ * Created for support topic "Searching on custom fields"
23
+ * opened on 5/11/2015 by "BFI-WP".
24
+ * https://wordpress.org/support/topic/searching-on-custom-fields/
25
+ *
26
  * @package MLA Custom Field Search Example
27
  * @version 1.04
28
  */
52
  */
53
 
54
  /**
55
+ * Class MLA Custom Field Search Example extends the Media/Assistant "Search Media" box
56
+ * to custom field values
 
 
57
  *
58
  * @package MLA Custom Field Search Example
59
  * @since 1.00
examples/plugins/mla-custom-view-example.php CHANGED
@@ -5,7 +5,11 @@
5
  * This example adds a Media/Assistant submenu table view for items attached to
6
  * non-published parent posts/pages.
7
  *
8
- * @packageMLA Custom View Example
 
 
 
 
9
  * @version 1.01
10
  */
11
 
5
  * This example adds a Media/Assistant submenu table view for items attached to
6
  * non-published parent posts/pages.
7
  *
8
+ * Created for support topic "Filter by post status"
9
+ * opened on 2/24/2015 by "milkchic".
10
+ * https://wordpress.org/support/topic/filter-by-post-status/
11
+ *
12
+ * @package MLA Custom View Example
13
  * @version 1.01
14
  */
15
 
examples/plugins/mla-hooks-example.php CHANGED
@@ -16,7 +16,7 @@
16
  * and illustrates some of the techniques you can use to customize the gallery display.
17
  *
18
  * @package MLA Gallery Hooks Example
19
- * @version 1.08
20
  */
21
 
22
  /*
@@ -24,7 +24,7 @@ Plugin Name: MLA Gallery Hooks Example
24
  Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
25
  Description: Provides examples of hooking the filters provided by the [mla_gallery] shortcode
26
  Author: David Lingren
27
- Version: 1.08
28
  Author URI: http://fairtradejudaica.org/our-story/staff/
29
 
30
  Copyright 2013 - 2016 David Lingren
@@ -76,42 +76,47 @@ class MLAGalleryHooksExample {
76
  *
77
  * Comment out the filters you don't need; save them for future use
78
  */
79
- add_filter( 'mla_gallery_raw_attributes', 'MLAGalleryHooksExample::mla_gallery_raw_attributes_filter', 10, 1 );
80
- add_filter( 'mla_gallery_attributes', 'MLAGalleryHooksExample::mla_gallery_attributes_filter', 10, 1 );
81
- add_filter( 'mla_gallery_initial_content', 'MLAGalleryHooksExample::mla_gallery_initial_content_filter', 10, 2 );
82
- add_filter( 'mla_gallery_arguments', 'MLAGalleryHooksExample::mla_gallery_arguments_filter', 10, 1 );
83
- add_filter( 'mla_gallery_query_attributes', 'MLAGalleryHooksExample::mla_gallery_query_attributes_filter', 10, 1 );
84
- add_filter( 'mla_gallery_query_arguments', 'MLAGalleryHooksExample::mla_gallery_query_arguments_filter', 10, 1 );
85
- add_action( 'mla_gallery_wp_query_object', 'MLAGalleryHooksExample::mla_gallery_wp_query_object_action', 10, 1 );
86
- add_filter( 'mla_gallery_final_content', 'MLAGalleryHooksExample::mla_gallery_final_content_filter', 10, 1 );
87
-
88
- add_filter( 'use_mla_gallery_style', 'MLAGalleryHooksExample::use_mla_gallery_style_filter', 10, 2 );
89
-
90
- add_filter( 'mla_gallery_style_values', 'MLAGalleryHooksExample::mla_gallery_style_values_filter', 10, 1 );
91
- add_filter( 'mla_gallery_style_template', 'MLAGalleryHooksExample::mla_gallery_style_template_filter', 10, 1 );
92
- add_filter( 'mla_gallery_style_parse', 'MLAGalleryHooksExample::mla_gallery_style_parse_filter', 10, 3 );
93
-
94
- add_filter( 'mla_gallery_open_values', 'MLAGalleryHooksExample::mla_gallery_open_values_filter', 10, 1 );
95
- add_filter( 'mla_gallery_open_template', 'MLAGalleryHooksExample::mla_gallery_open_template_filter', 10, 1 );
96
- add_filter( 'mla_gallery_open_parse', 'MLAGalleryHooksExample::mla_gallery_open_parse_filter', 10, 3 );
97
-
98
- add_filter( 'mla_gallery_style', 'MLAGalleryHooksExample::mla_gallery_style_filter', 10, 5 );
99
-
100
- add_filter( 'mla_gallery_row_open_values', 'MLAGalleryHooksExample::mla_gallery_row_open_values_filter', 10, 1 );
101
- add_filter( 'mla_gallery_row_open_template', 'MLAGalleryHooksExample::mla_gallery_row_open_template_filter', 10, 1 );
102
- add_filter( 'mla_gallery_row_open_parse', 'MLAGalleryHooksExample::mla_gallery_row_open_parse_filter', 10, 3 );
103
-
104
- add_filter( 'mla_gallery_item_values', 'MLAGalleryHooksExample::mla_gallery_item_values_filter', 10, 1 );
105
- add_filter( 'mla_gallery_item_template', 'MLAGalleryHooksExample::mla_gallery_item_template_filter', 10, 1 );
106
- add_filter( 'mla_gallery_item_parse', 'MLAGalleryHooksExample::mla_gallery_item_parse_filter', 10, 3 );
107
-
108
- add_filter( 'mla_gallery_row_close_values', 'MLAGalleryHooksExample::mla_gallery_row_close_values_filter', 10, 1 );
109
- add_filter( 'mla_gallery_row_close_template', 'MLAGalleryHooksExample::mla_gallery_row_close_template_filter', 10, 1 );
110
- add_filter( 'mla_gallery_row_close_parse', 'MLAGalleryHooksExample::mla_gallery_row_close_parse_filter', 10, 3 );
111
-
112
- add_filter( 'mla_gallery_close_values', 'MLAGalleryHooksExample::mla_gallery_close_values_filter', 10, 1 );
113
- add_filter( 'mla_gallery_close_template', 'MLAGalleryHooksExample::mla_gallery_close_template_filter', 10, 1 );
114
- add_filter( 'mla_gallery_close_parse', 'MLAGalleryHooksExample::mla_gallery_close_parse_filter', 10, 3 );
 
 
 
 
 
115
  }
116
 
117
  /**
@@ -138,11 +143,11 @@ class MLAGalleryHooksExample {
138
  *
139
  * @return array updated shortcode attributes
140
  */
141
- public static function mla_gallery_raw_attributes_filter( $shortcode_attributes ) {
142
  /*
143
  * Uncomment the error_log statements in any of the filters to see what's passed in
144
  */
145
- //error_log( 'MLAGalleryHooksExample::mla_gallery_raw_attributes_filter $shortcode_attributes = ' . var_export( $shortcode_attributes, true ), 0 );
146
 
147
  /*
148
  * Note that the global $post; object is available here and in all later filters.
@@ -151,7 +156,7 @@ class MLAGalleryHooksExample {
151
  * have a substitute $post object with $post->ID == 0.
152
  */
153
  global $post;
154
- //error_log( 'MLAGalleryHooksExample::mla_gallery_raw_attributes_filter $post->ID = ' . var_export( $post->ID, true ), 0 );
155
 
156
  /*
157
  * For this example, we delete the selected file.
@@ -177,7 +182,7 @@ class MLAGalleryHooksExample {
177
  }
178
 
179
  return $shortcode_attributes;
180
- } // mla_gallery_raw_attributes_filter
181
 
182
  /**
183
  * MLA Gallery (Display) Attributes
@@ -194,19 +199,22 @@ class MLAGalleryHooksExample {
194
  *
195
  * @return array updated shortcode attributes
196
  */
197
- public static function mla_gallery_attributes_filter( $shortcode_attributes ) {
198
  /*
199
  * Uncomment the error_log statements in any of the filters to see what's passed in
200
  */
201
- //error_log( 'MLAGalleryHooksExample::mla_gallery_attributes_filter $shortcode_attributes = ' . var_export( $shortcode_attributes, true ), 0 );
202
 
203
  /*
204
  * Save the attributes for use in the later filters
205
  */
206
  self::$shortcode_attributes = $shortcode_attributes;
207
 
 
 
 
208
  return $shortcode_attributes;
209
- } // mla_gallery_attributes_filter
210
 
211
  /**
212
  * Save the enclosed content
@@ -231,9 +239,9 @@ class MLAGalleryHooksExample {
231
  *
232
  * @return array updated shortcode content
233
  */
234
- public static function mla_gallery_initial_content_filter( $shortcode_content, $shortcode_attributes ) {
235
- //error_log( 'MLAGalleryHooksExample::mla_gallery_initial_content_filter $shortcode_content = ' . var_export( $shortcode_content, true ), 0 );
236
- //error_log( 'MLAGalleryHooksExample::mla_gallery_initial_content_filter $shortcode_attributes = ' . var_export( $shortcode_attributes, true ), 0 );
237
 
238
  /*
239
  * Save the attributes for use in the later filters
@@ -241,7 +249,7 @@ class MLAGalleryHooksExample {
241
  self::$shortcode_content = $shortcode_content;
242
 
243
  return $shortcode_content;
244
- } // mla_gallery_initial_content_filter
245
 
246
  /**
247
  * Save the shortcode arguments
@@ -268,12 +276,12 @@ class MLAGalleryHooksExample {
268
  *
269
  * @return array updated gallery display arguments
270
  */
271
- public static function mla_gallery_arguments_filter( $all_display_parameters ) {
272
- //error_log( 'MLAGalleryHooksExample::mla_gallery_arguments_filter $all_display_parameters = ' . var_export( $all_display_parameters, true ), 0 );
273
 
274
  self::$all_display_parameters = $all_display_parameters;
275
  return $all_display_parameters;
276
- } // mla_gallery_arguments_filter
277
 
278
  /**
279
  * Save the query attributes
@@ -300,12 +308,12 @@ class MLAGalleryHooksExample {
300
  *
301
  * @return array updated shortcode attributes
302
  */
303
- public static function mla_gallery_query_attributes_filter( $query_attributes ) {
304
- //error_log( 'MLAGalleryHooksExample::mla_gallery_query_attributes_filter $query_attributes = ' . var_export( $query_attributes, true ), 0 );
305
 
306
  self::$query_attributes = $query_attributes;
307
  return $query_attributes;
308
- } // mla_gallery_query_attributes_filter
309
 
310
  /**
311
  * Save the query arguments
@@ -328,9 +336,9 @@ class MLAGalleryHooksExample {
328
  *
329
  * @return array updated attachment query arguments
330
  */
331
- public static function mla_gallery_query_arguments_filter( $all_query_parameters ) {
332
- //error_log( 'MLAGalleryHooksExample::mla_gallery_query_arguments_filter $all_query_parameters = ' . var_export( $all_query_parameters, true ), 0 );
333
- //error_log( 'MLAGalleryHooksExample::mla_gallery_query_arguments_filter self::$shortcode_attributes = ' . var_export( self::$shortcode_attributes, true ), 0 );
334
 
335
  self::$all_query_parameters = $all_query_parameters;
336
 
@@ -361,7 +369,7 @@ class MLAGalleryHooksExample {
361
  if ( 0 == $recent_limit ) {
362
  return $all_query_parameters;
363
  }
364
-
365
  $display_limit = isset( $limits[1] ) ? absint( $limits[1] ) : 1;
366
  if ( 0 == $display_limit ) {
367
  $display_limit = 1;
@@ -414,13 +422,18 @@ class MLAGalleryHooksExample {
414
  *
415
  * The queries supported in this example's "my_custom_sql" parameter include:
416
  *
417
- * - one or more taxonomy term lists, with include_children
418
  * - one or more post_parent values
419
  * - one or more post_type values
420
  *
 
 
421
  * The three query parameters are joined with "OR", so items matching any of the three
422
  * parameters will be included. Any combination of the three parameters is accepted.
423
  *
 
 
 
424
  * We use a shortcode parameter of our own to apply this filter on a gallery-by-gallery
425
  * basis, leaving other [mla_gallery] instances untouched. If the "my_custom_sql" parameter
426
  * is not present, we have nothing to do. If the parameter IS present, extract taxonomy,
@@ -443,16 +456,35 @@ class MLAGalleryHooksExample {
443
  $post_parents = array();
444
  $parent_types = array();
445
 
446
- // Find taxonomy argument, if present, and collect terms
447
- $taxonomies = get_taxonomies( array( 'object_type' => array( 'attachment' ) ), 'names' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
448
  foreach( $taxonomies as $taxonomy ) {
449
  if ( empty( $my_query_vars[ $taxonomy ] ) ) {
450
  continue;
451
  }
452
 
453
- // Found the taxonomy; collect the terms
454
- $include_children = isset( $my_query_vars['include_children'] ) && 'true' == strtolower( trim( $my_query_vars['include_children'] ) );
455
-
456
  // Allow for multiple term slug values
457
  $terms = array();
458
  $slugs = explode( ',', $my_query_vars[ $taxonomy ] );
@@ -461,20 +493,24 @@ class MLAGalleryHooksExample {
461
  $terms = array_merge( $terms, get_terms( $taxonomy, $args ) );
462
  }
463
 
 
464
  foreach( $terms as $term ) {
465
  // Index by ttid to remove duplicates
466
  $ttids[ $term->term_taxonomy_id ] = $term->term_taxonomy_id;
467
 
468
- if ( $include_children ) {
469
  $args = array( 'child_of' => $term->term_id, 'hide_empty' => false );
470
- $children = get_terms( 'attachment_category', $args );
471
  foreach( $children as $child ) {
472
- $ttids[] = $child->term_taxonomy_id;
473
  }
474
- } // include_children
475
  } // $term
476
 
477
- break;
 
 
 
478
  }
479
 
480
  if ( isset( $my_query_vars['post_parent'] ) ) {
@@ -498,11 +534,15 @@ class MLAGalleryHooksExample {
498
  $query[] = "ON (p.post_parent = p2.ID)";
499
  }
500
 
501
- if ( ! empty( $ttids ) ) {
502
- $query[] = "LEFT JOIN {$wpdb->term_relationships} as tr";
503
- $query[] = "ON (p.ID = tr.object_id)";
 
 
 
 
504
  }
505
-
506
  // Start with a WHERE clause that doesn't match anything, since OR is the connector
507
  $query[] = 'WHERE ( ( 1=0 )';
508
 
@@ -526,16 +566,40 @@ class MLAGalleryHooksExample {
526
  $query[] = 'OR ( p2.post_type IN (' . join( ',', $placeholders ) . ') )';
527
  }
528
 
529
- if ( ! empty( $ttids ) ) {
530
- $placeholders = array();
531
- foreach ( $ttids as $ttid ) {
532
- $placeholders[] = '%s';
533
- $query_parameters[] = $ttid;
 
 
 
 
 
 
 
 
 
 
 
 
534
  }
535
 
536
- $query[] = 'OR ( tr.term_taxonomy_id IN (' . join( ',', $placeholders ) . ') )';
537
- }
 
 
 
 
 
 
 
 
538
 
 
 
 
 
539
  // Close the WHERE clause
540
  $query[] = ')';
541
 
@@ -543,13 +607,78 @@ class MLAGalleryHooksExample {
543
  $query[] = "AND p.post_type = 'attachment'";
544
  $query[] = "AND p.post_status = 'inherit'";
545
  $query[] = "GROUP BY p.ID";
546
- // ORDER BY clause would go here, if needed
547
 
548
  /*
549
- * Add pagination to our query, then remove it from the query
550
- * that WordPress will process after we're done.
551
  */
552
- $paged = $all_query_parameters['paged'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
553
  if ( empty( $paged ) ) {
554
  $paged = 1;
555
  } elseif ( 'current' == strtolower( $paged ) ) {
@@ -568,7 +697,14 @@ class MLAGalleryHooksExample {
568
  $paged = 1;
569
  }
570
 
571
- $limit = absint( ! empty( $all_query_parameters['posts_per_page'] ) ? $all_query_parameters['posts_per_page'] : $all_query_parameters['numberposts'] );
 
 
 
 
 
 
 
572
  $offset = $limit * ( $paged - 1);
573
  if ( 0 < $offset && 0 < $limit ) {
574
  $query[] = 'LIMIT %d, %d';
@@ -583,10 +719,6 @@ class MLAGalleryHooksExample {
583
  $query_parameters[] = 0x7FFFFFFF; // big number!
584
  }
585
 
586
- $all_query_parameters['paged'] = NULL;
587
- $all_query_parameters['posts_per_page'] = 0;
588
- $all_query_parameters['numberposts'] = 0;
589
-
590
  $query = join(' ', $query);
591
  $ids = $wpdb->get_results( $wpdb->prepare( $query, $query_parameters ) );
592
  if ( is_array( $ids ) ) {
@@ -598,12 +730,10 @@ class MLAGalleryHooksExample {
598
  } else {
599
  $all_query_parameters['include'] = '1'; // return no images
600
  }
601
-
602
- return $all_query_parameters;
603
  } // parameter "my_custom_sql" is present
604
 
605
  return $all_query_parameters;
606
- } // mla_gallery_query_arguments_filter
607
 
608
  /**
609
  * Save some of the WP_Query object properties
@@ -627,29 +757,98 @@ class MLAGalleryHooksExample {
627
  *
628
  * @return void actions never return anything
629
  */
630
- public static function mla_gallery_wp_query_object_action( $query_arguments ) {
631
- //error_log( 'MLAGalleryHooksExample::mla_gallery_wp_query_object_action $query_arguments = ' . var_export( $query_arguments, true ), 0 );
632
 
633
  self::$wp_query_properties = array();
634
  self::$wp_query_properties ['request'] = MLAShortcodes::$mla_gallery_wp_query_object->request;
635
  self::$wp_query_properties ['query_vars'] = MLAShortcodes::$mla_gallery_wp_query_object->query_vars;
636
  self::$wp_query_properties ['post_count'] = MLAShortcodes::$mla_gallery_wp_query_object->post_count;
637
 
638
- //error_log( 'MLAGalleryHooksExample::mla_gallery_wp_query_object_action self::$wp_query_properties = ' . var_export( self::$wp_query_properties, true ), 0 );
639
 
640
  /*
641
  * Unlike Filters, Actions never return anything
642
  */
643
  return;
644
- } // mla_gallery_wp_query_object_action
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
645
 
646
  /**
647
  * MLA Gallery Enclosed Content, final filter
648
  *
649
  * This filter gives you an opportunity to record or modify the content enclosed by the shortcode
650
- * when the [mla_gallery]content[/mla_gallery] form is used.
651
- * This final filter is called just after the WP_query and before control is passed
652
- * to the alternate gallery shortcode.
653
  *
654
  * @since 1.02
655
  *
@@ -657,18 +856,30 @@ class MLAGalleryHooksExample {
657
  *
658
  * @return array updated shortcode content
659
  */
660
- public static function mla_gallery_final_content_filter( $shortcode_content ) {
661
- //error_log( 'MLAGalleryHooksExample::mla_gallery_final_content_filter $shortcode_content = ' . var_export( $shortcode_content, true ), 0 );
662
 
663
  return $shortcode_content;
664
- } // mla_gallery_final_content_filter
 
 
 
 
 
 
 
 
 
 
 
 
665
 
666
  /**
667
  * Use MLA Gallery Style
668
  *
669
  * You can use this filter to allow or suppress the inclusion of CSS styles in the
670
  * gallery output. Return 'true' to allow the styles, false to suppress them. You can also
671
- * suppress styles by returning an empty string from the mla_gallery_style_parse_filter below.
672
  *
673
  * @since 1.00
674
  *
@@ -677,15 +888,15 @@ class MLAGalleryHooksExample {
677
  *
678
  * @return boolean true to fetch and parse the style template, false to leave it empty
679
  */
680
- public static function use_mla_gallery_style_filter( $use_style_template, $style_template_name ) {
681
- //error_log( 'MLAGalleryHooksExample::use_mla_gallery_style_filter $use_style_template = ' . var_export( $use_style_template, true ), 0 );
682
- //error_log( 'MLAGalleryHooksExample::use_mla_gallery_style_filter $style_template_name = ' . var_export( $style_template_name, true ), 0 );
683
 
684
  /*
685
  * Filters must return the first argument passed in, unchanged or updated
686
  */
687
  return $use_style_template;
688
- } // use_mla_gallery_style_filter
689
 
690
  /**
691
  * MLA Gallery Style Values
@@ -701,24 +912,24 @@ class MLAGalleryHooksExample {
701
  *
702
  * @return array updated substitution parameter name => value pairs
703
  */
704
- public static function mla_gallery_style_values_filter( $style_values ) {
705
- //error_log( 'MLAGalleryHooksExample::mla_gallery_style_values_filter $style_values = ' . var_export( $style_values, true ), 0 );
706
 
707
  /*
708
  * You also have access to the PHP Super Globals, e.g., $_REQUEST, $_SERVER
709
  */
710
- //error_log( 'MLAGalleryHooksExample::mla_gallery_style_values_filter $_REQUEST = ' . var_export( $_REQUEST, true ), 0 );
711
- //error_log( 'MLAGalleryHooksExample::mla_gallery_style_values_filter $_SERVER[ REQUEST_URI ] = ' . var_export( $_SERVER['REQUEST_URI'], true ), 0 );
712
 
713
  /*
714
  * You can use the WordPress globals like $wp_query, $wpdb and $table_prefix as well.
715
  * Note that $wp_query contains values for the post/page query, NOT the [mla_gallery] query.
716
  */
717
  global $wp_query;
718
- //error_log( 'MLAGalleryHooksExample::mla_gallery_style_values_filter $wp_query->query = ' . var_export( $wp_query->query, true ), 0 );
719
 
720
  return $style_values;
721
- } // mla_gallery_style_values_filter
722
 
723
  /**
724
  * MLA Gallery Style Template
@@ -734,11 +945,11 @@ class MLAGalleryHooksExample {
734
  *
735
  * @return string updated template
736
  */
737
- public static function mla_gallery_style_template_filter( $style_template ) {
738
- //error_log( 'MLAGalleryHooksExample::mla_gallery_style_template_filter $style_template = ' . var_export( $style_template, true ), 0 );
739
 
740
  return $style_template;
741
- } // mla_gallery_style_template_filter
742
 
743
  /**
744
  * MLA Gallery Style Parse
@@ -757,13 +968,13 @@ class MLAGalleryHooksExample {
757
  *
758
  * @return array updated HTML markup for gallery output
759
  */
760
- public static function mla_gallery_style_parse_filter( $html_markup, $style_template, $style_values ) {
761
- //error_log( 'MLAGalleryHooksExample::mla_gallery_style_parse_filter $html_markup = ' . var_export( $html_markup, true ), 0 );
762
- //error_log( 'MLAGalleryHooksExample::mla_gallery_style_parse_filter $style_template = ' . var_export( $style_template, true ), 0 );
763
- //error_log( 'MLAGalleryHooksExample::mla_gallery_style_parse_filter $style_values = ' . var_export( $style_values, true ), 0 );
764
 
765
  return $html_markup;
766
- } // mla_gallery_style_parse_filter
767
 
768
  /**
769
  * MLA Gallery Open Values
@@ -777,11 +988,11 @@ class MLAGalleryHooksExample {
777
  *
778
  * @return array updated substitution parameter name => value pairs
779
  */
780
- public static function mla_gallery_open_values_filter( $markup_values ) {
781
- //error_log( 'MLAGalleryHooksExample::mla_gallery_open_values_filter $markup_values = ' . var_export( $markup_values, true ), 0 );
782
 
783
  return $markup_values;
784
- } // mla_gallery_open_values_filter
785
 
786
  /**
787
  * MLA Gallery Open Template
@@ -792,8 +1003,8 @@ class MLAGalleryHooksExample {
792
  *
793
  * @return string updated template
794
  */
795
- public static function mla_gallery_open_template_filter( $open_template ) {
796
- //error_log( 'MLAGalleryHooksExample::mla_gallery_open_template_filter $open_template = ' . var_export( $open_template, true ), 0 );
797
 
798
  /*
799
  * Check for a display message
@@ -803,7 +1014,7 @@ class MLAGalleryHooksExample {
803
  }
804
 
805
  return $open_template;
806
- } // mla_gallery_open_template_filter
807
 
808
  /**
809
  * MLA Gallery Open Parse
@@ -816,13 +1027,13 @@ class MLAGalleryHooksExample {
816
  *
817
  * @return array updated HTML markup for gallery output
818
  */
819
- public static function mla_gallery_open_parse_filter( $html_markup, $open_template, $markup_values ) {
820
- //error_log( 'MLAGalleryHooksExample::mla_gallery_open_parse_filter $html_markup = ' . var_export( $html_markup, true ), 0 );
821
- //error_log( 'MLAGalleryHooksExample::mla_gallery_open_parse_filter $open_template = ' . var_export( $open_template, true ), 0 );
822
- //error_log( 'MLAGalleryHooksExample::mla_gallery_open_parse_filter $markup_values = ' . var_export( $markup_values, true ), 0 );
823
 
824
  return $html_markup;
825
- } // mla_gallery_open_parse_filter
826
 
827
  /**
828
  * MLA Gallery Style
@@ -840,15 +1051,15 @@ class MLAGalleryHooksExample {
840
  *
841
  * @return array updated HTML markup for "gallery style" and "gallery open" output
842
  */
843
- public static function mla_gallery_style_filter( $html_markup, $style_values, $open_values, $style_template, $open_template ) {
844
- //error_log( 'MLAGalleryHooksExample::mla_gallery_style_filter $html_markup = ' . var_export( $html_markup, true ), 0 );
845
- //error_log( 'MLAGalleryHooksExample::mla_gallery_style_filter $style_values = ' . var_export( $style_values, true ), 0 );
846
- //error_log( 'MLAGalleryHooksExample::mla_gallery_style_filter $open_values = ' . var_export( $open_values, true ), 0 );
847
- //error_log( 'MLAGalleryHooksExample::mla_gallery_style_filter $style_template = ' . var_export( $style_template, true ), 0 );
848
- //error_log( 'MLAGalleryHooksExample::mla_gallery_style_filter $open_template = ' . var_export( $open_template, true ), 0 );
849
 
850
  return $html_markup;
851
- } // mla_gallery_style_filter
852
 
853
  /**
854
  * MLA Gallery Row Open Values
@@ -859,11 +1070,11 @@ class MLAGalleryHooksExample {
859
  *
860
  * @return array updated substitution parameter name => value pairs
861
  */
862
- public static function mla_gallery_row_open_values_filter( $markup_values ) {
863
- //error_log( 'MLAGalleryHooksExample::mla_gallery_row_open_values_filter $markup_values = ' . var_export( $markup_values, true ), 0 );
864
 
865
  return $markup_values;
866
- } // mla_gallery_row_open_values_filter
867
 
868
  /**
869
  * MLA Gallery Row Open Template
@@ -874,11 +1085,11 @@ class MLAGalleryHooksExample {
874
  *
875
  * @return string updated template
876
  */
877
- public static function mla_gallery_row_open_template_filter( $row_open_template ) {
878
- //error_log( 'MLAGalleryHooksExample::mla_gallery_row_open_template_filter $row_open_template = ' . var_export( $row_open_template, true ), 0 );
879
 
880
  return $row_open_template;
881
- } // mla_gallery_row_open_template_filter
882
 
883
  /**
884
  * MLA Gallery Row Open Parse
@@ -891,13 +1102,13 @@ class MLAGalleryHooksExample {
891
  *
892
  * @return array updated HTML markup for gallery output
893
  */
894
- public static function mla_gallery_row_open_parse_filter( $html_markup, $row_open_template, $markup_values ) {
895
- //error_log( 'MLAGalleryHooksExample::mla_gallery_row_open_parse_filter $html_markup = ' . var_export( $html_markup, true ), 0 );
896
- //error_log( 'MLAGalleryHooksExample::mla_gallery_row_open_parse_filter $row_open_template = ' . var_export( $row_open_template, true ), 0 );
897
- //error_log( 'MLAGalleryHooksExample::mla_gallery_row_open_parse_filter $markup_values = ' . var_export( $markup_values, true ), 0 );
898
 
899
  return $html_markup;
900
- } // mla_gallery_row_open_parse_filter
901
 
902
  /**
903
  * Replace the caption value and update captiontag_content as well
@@ -935,8 +1146,8 @@ class MLAGalleryHooksExample {
935
  *
936
  * @return array updated substitution parameter name => value pairs
937
  */
938
- public static function mla_gallery_item_values_filter( $item_values ) {
939
- //error_log( 'MLAGalleryHooksExample::mla_gallery_item_values_filter $item_values = ' . var_export( $item_values, true ), 0 );
940
 
941
  /*
942
  * We use a shortcode parameter of our own to apply our filters on a gallery-by-gallery basis,
@@ -952,7 +1163,7 @@ class MLAGalleryHooksExample {
952
  $item_values['terms:attachment_category'] = implode( ' ', $object_terms );
953
  $item_values = self::_update_caption( $item_values, implode( ' ', $object_terms ) );
954
 
955
- //error_log( 'MLAGalleryHooksExample::mla_gallery_item_values_filter terms = ' . var_export( $item_values['terms:attachment_category'], true ), 0 );
956
  }
957
 
958
  /*
@@ -1133,7 +1344,7 @@ class MLAGalleryHooksExample {
1133
  */
1134
  $custom_fields = array();
1135
  $post_meta = get_metadata( 'post', $item_values['attachment_ID'] );
1136
- //error_log( 'MLAGalleryHooksExample::mla_gallery_item_values_filter $post_meta = ' . var_export( $post_meta, true ), 0 );
1137
 
1138
  if ( is_array( $post_meta ) ) {
1139
  foreach ( $post_meta as $post_meta_key => $post_meta_value ) {
@@ -1165,7 +1376,7 @@ class MLAGalleryHooksExample {
1165
  $custom_fields[ $post_meta_key ] = $post_meta_value;
1166
  } // foreach $post_meta
1167
  }
1168
- //error_log( 'MLAGalleryHooksExample::mla_gallery_item_values_filter $custom_fields = ' . var_export( $custom_fields, true ), 0 );
1169
 
1170
  /*
1171
  * Don't alter the caption if there are no custom fields to display
@@ -1188,7 +1399,7 @@ class MLAGalleryHooksExample {
1188
  */
1189
  $item_values = self::_update_caption( $item_values, $my_caption );
1190
  return $item_values;
1191
- } // mla_gallery_item_values_filter
1192
 
1193
  /**
1194
  * MLA Gallery Item Template
@@ -1199,11 +1410,11 @@ class MLAGalleryHooksExample {
1199
  *
1200
  * @return string updated template
1201
  */
1202
- public static function mla_gallery_item_template_filter( $item_template ) {
1203
- //error_log( 'MLAGalleryHooksExample::mla_gallery_item_template_filter $item_template = ' . var_export( $item_template, true ), 0 );
1204
 
1205
  return $item_template;
1206
- } // mla_gallery_item_template_filter
1207
 
1208
  /**
1209
  * MLA Gallery Item Parse
@@ -1216,13 +1427,13 @@ class MLAGalleryHooksExample {
1216
  *
1217
  * @return array updated HTML markup for gallery output
1218
  */
1219
- public static function mla_gallery_item_parse_filter( $html_markup, $item_template, $item_values ) {
1220
- //error_log( 'MLAGalleryHooksExample::mla_gallery_item_parse_filter $html_markup = ' . var_export( $html_markup, true ), 0 );
1221
- //error_log( 'MLAGalleryHooksExample::mla_gallery_item_parse_filter $item_template = ' . var_export( $item_template, true ), 0 );
1222
- //error_log( 'MLAGalleryHooksExample::mla_gallery_item_parse_filter $item_values = ' . var_export( $item_values, true ), 0 );
1223
 
1224
  return $html_markup;
1225
- } // mla_gallery_item_parse_filter
1226
 
1227
  /**
1228
  * MLA Gallery Row Close Values
@@ -1233,11 +1444,11 @@ class MLAGalleryHooksExample {
1233
  *
1234
  * @return array updated substitution parameter name => value pairs
1235
  */
1236
- public static function mla_gallery_row_close_values_filter( $markup_values ) {
1237
- //error_log( 'MLAGalleryHooksExample::mla_gallery_row_close_values_filter $markup_values = ' . var_export( $markup_values, true ), 0 );
1238
 
1239
  return $markup_values;
1240
- } // mla_gallery_row_close_values_filter
1241
 
1242
  /**
1243
  * MLA Gallery Row Close Template
@@ -1248,11 +1459,11 @@ class MLAGalleryHooksExample {
1248
  *
1249
  * @return string updated template
1250
  */
1251
- public static function mla_gallery_row_close_template_filter( $row_close_template ) {
1252
- //error_log( 'MLAGalleryHooksExample::mla_gallery_row_close_template_filter $row_close_template = ' . var_export( $row_close_template, true ), 0 );
1253
 
1254
  return $row_close_template;
1255
- } // mla_gallery_row_close_template_filter
1256
 
1257
  /**
1258
  * MLA Gallery Row Close Parse
@@ -1265,13 +1476,13 @@ class MLAGalleryHooksExample {
1265
  *
1266
  * @return array updated HTML markup for gallery output
1267
  */
1268
- public static function mla_gallery_row_close_parse_filter( $html_markup, $row_close_template, $markup_values ) {
1269
- //error_log( 'MLAGalleryHooksExample::mla_gallery_row_close_parse_filter $html_markup = ' . var_export( $html_markup, true ), 0 );
1270
- //error_log( 'MLAGalleryHooksExample::mla_gallery_row_close_parse_filter $row_close_template = ' . var_export( $row_close_template, true ), 0 );
1271
- //error_log( 'MLAGalleryHooksExample::mla_gallery_row_close_parse_filter $markup_values = ' . var_export( $markup_values, true ), 0 );
1272
 
1273
  return $html_markup;
1274
- } // mla_gallery_row_close_parse_filter
1275
 
1276
  /**
1277
  * MLA Gallery Close Values
@@ -1282,11 +1493,11 @@ class MLAGalleryHooksExample {
1282
  *
1283
  * @return array updated substitution parameter name => value pairs
1284
  */
1285
- public static function mla_gallery_close_values_filter( $markup_values ) {
1286
- //error_log( 'MLAGalleryHooksExample::mla_gallery_close_values_filter $markup_values = ' . var_export( $markup_values, true ), 0 );
1287
 
1288
  return $markup_values;
1289
- } // mla_gallery_close_values_filter
1290
 
1291
  /**
1292
  * MLA Gallery Close Template
@@ -1297,11 +1508,11 @@ class MLAGalleryHooksExample {
1297
  *
1298
  * @return string updated template
1299
  */
1300
- public static function mla_gallery_close_template_filter( $close_template ) {
1301
- //error_log( 'MLAGalleryHooksExample::mla_gallery_close_template_filter $close_template = ' . var_export( $close_template, true ), 0 );
1302
 
1303
  return $close_template;
1304
- } // mla_gallery_close_template_filter
1305
 
1306
  /**
1307
  * MLA Gallery Close Parse
@@ -1314,13 +1525,13 @@ class MLAGalleryHooksExample {
1314
  *
1315
  * @return array updated HTML markup for gallery output
1316
  */
1317
- public static function mla_gallery_close_parse_filter( $html_markup, $close_template, $markup_values ) {
1318
- //error_log( 'MLAGalleryHooksExample::mla_gallery_close_parse_filter $html_markup = ' . var_export( $html_markup, true ), 0 );
1319
- //error_log( 'MLAGalleryHooksExample::mla_gallery_close_parse_filter $close_template = ' . var_export( $close_template, true ), 0 );
1320
- //error_log( 'MLAGalleryHooksExample::mla_gallery_close_parse_filter $markup_values = ' . var_export( $markup_values, true ), 0 );
1321
 
1322
  return $html_markup;
1323
- } // mla_gallery_close_parse_filter
1324
 
1325
  } // Class MLAGalleryHooksExample
1326
 
16
  * and illustrates some of the techniques you can use to customize the gallery display.
17
  *
18
  * @package MLA Gallery Hooks Example
19
+ * @version 1.12
20
  */
21
 
22
  /*
24
  Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
25
  Description: Provides examples of hooking the filters provided by the [mla_gallery] shortcode
26
  Author: David Lingren
27
+ Version: 1.12
28
  Author URI: http://fairtradejudaica.org/our-story/staff/
29
 
30
  Copyright 2013 - 2016 David Lingren
76
  *
77
  * Comment out the filters you don't need; save them for future use
78
  */
79
+ add_filter( 'mla_gallery_raw_attributes', 'MLAGalleryHooksExample::mla_gallery_raw_attributes', 10, 1 );
80
+ add_filter( 'mla_gallery_attributes', 'MLAGalleryHooksExample::mla_gallery_attributes', 10, 1 );
81
+ add_filter( 'mla_gallery_initial_content', 'MLAGalleryHooksExample::mla_gallery_initial_content', 10, 2 );
82
+ add_filter( 'mla_gallery_arguments', 'MLAGalleryHooksExample::mla_gallery_arguments', 10, 1 );
83
+ add_filter( 'mla_gallery_query_attributes', 'MLAGalleryHooksExample::mla_gallery_query_attributes', 10, 1 );
84
+ add_filter( 'mla_gallery_query_arguments', 'MLAGalleryHooksExample::mla_gallery_query_arguments', 10, 1 );
85
+ add_action( 'mla_gallery_wp_query_object', 'MLAGalleryHooksExample::mla_gallery_wp_query_object', 10, 1 );
86
+ add_filter( 'mla_gallery_final_content', 'MLAGalleryHooksExample::mla_gallery_final_content', 10, 1 );
87
+ add_filter( 'mla_gallery_the_attachments', 'MLAGalleryHooksExample::mla_gallery_the_attachments', 10, 2 );
88
+ add_filter( 'mla_gallery_alt_shortcode_blacklist', 'MLAGalleryHooksExample::mla_gallery_alt_shortcode_blacklist', 10, 1 );
89
+ add_filter( 'mla_gallery_alt_shortcode_attributes', 'MLAGalleryHooksExample::mla_gallery_alt_shortcode_attributes', 10, 1 );
90
+ add_filter( 'mla_gallery_alt_shortcode_ids', 'MLAGalleryHooksExample::mla_gallery_alt_shortcode_ids', 10, 3 );
91
+ add_action( 'mla_gallery_end_alt_shortcode', 'MLAGalleryHooksExample::mla_gallery_end_alt_shortcode', 10, 0 );
92
+
93
+ add_filter( 'use_mla_gallery_style', 'MLAGalleryHooksExample::use_mla_gallery_style', 10, 2 );
94
+
95
+ add_filter( 'mla_gallery_style_values', 'MLAGalleryHooksExample::mla_gallery_style_values', 10, 1 );
96
+ add_filter( 'mla_gallery_style_template', 'MLAGalleryHooksExample::mla_gallery_style_template', 10, 1 );
97
+ add_filter( 'mla_gallery_style_parse', 'MLAGalleryHooksExample::mla_gallery_style_parse', 10, 3 );
98
+
99
+ add_filter( 'mla_gallery_open_values', 'MLAGalleryHooksExample::mla_gallery_open_values', 10, 1 );
100
+ add_filter( 'mla_gallery_open_template', 'MLAGalleryHooksExample::mla_gallery_open_template', 10, 1 );
101
+ add_filter( 'mla_gallery_open_parse', 'MLAGalleryHooksExample::mla_gallery_open_parse', 10, 3 );
102
+
103
+ add_filter( 'mla_gallery_style', 'MLAGalleryHooksExample::mla_gallery_style', 10, 5 );
104
+
105
+ add_filter( 'mla_gallery_row_open_values', 'MLAGalleryHooksExample::mla_gallery_row_open_values', 10, 1 );
106
+ add_filter( 'mla_gallery_row_open_template', 'MLAGalleryHooksExample::mla_gallery_row_open_template', 10, 1 );
107
+ add_filter( 'mla_gallery_row_open_parse', 'MLAGalleryHooksExample::mla_gallery_row_open_parse', 10, 3 );
108
+
109
+ add_filter( 'mla_gallery_item_values', 'MLAGalleryHooksExample::mla_gallery_item_values', 10, 1 );
110
+ add_filter( 'mla_gallery_item_template', 'MLAGalleryHooksExample::mla_gallery_item_template', 10, 1 );
111
+ add_filter( 'mla_gallery_item_parse', 'MLAGalleryHooksExample::mla_gallery_item_parse', 10, 3 );
112
+
113
+ add_filter( 'mla_gallery_row_close_values', 'MLAGalleryHooksExample::mla_gallery_row_close_values', 10, 1 );
114
+ add_filter( 'mla_gallery_row_close_template', 'MLAGalleryHooksExample::mla_gallery_row_close_template', 10, 1 );
115
+ add_filter( 'mla_gallery_row_close_parse', 'MLAGalleryHooksExample::mla_gallery_row_close_parse', 10, 3 );
116
+
117
+ add_filter( 'mla_gallery_close_values', 'MLAGalleryHooksExample::mla_gallery_close_values', 10, 1 );
118
+ add_filter( 'mla_gallery_close_template', 'MLAGalleryHooksExample::mla_gallery_close_template', 10, 1 );
119
+ add_filter( 'mla_gallery_close_parse', 'MLAGalleryHooksExample::mla_gallery_close_parse', 10, 3 );
120
  }
121
 
122
  /**
143
  *
144
  * @return array updated shortcode attributes
145
  */
146
+ public static function mla_gallery_raw_attributes( $shortcode_attributes ) {
147
  /*
148
  * Uncomment the error_log statements in any of the filters to see what's passed in
149
  */
150
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_raw_attributes $shortcode_attributes = ' . var_export( $shortcode_attributes, true ), 0 );
151
 
152
  /*
153
  * Note that the global $post; object is available here and in all later filters.
156
  * have a substitute $post object with $post->ID == 0.
157
  */
158
  global $post;
159
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_raw_attributes $post->ID = ' . var_export( $post->ID, true ), 0 );
160
 
161
  /*
162
  * For this example, we delete the selected file.
182
  }
183
 
184
  return $shortcode_attributes;
185
+ } // mla_gallery_raw_attributes
186
 
187
  /**
188
  * MLA Gallery (Display) Attributes
199
  *
200
  * @return array updated shortcode attributes
201
  */
202
+ public static function mla_gallery_attributes( $shortcode_attributes ) {
203
  /*
204
  * Uncomment the error_log statements in any of the filters to see what's passed in
205
  */
206
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_attributes $shortcode_attributes = ' . var_export( $shortcode_attributes, true ), 0 );
207
 
208
  /*
209
  * Save the attributes for use in the later filters
210
  */
211
  self::$shortcode_attributes = $shortcode_attributes;
212
 
213
+ unset( $shortcode_attributes['my_custom_sql'] );
214
+ unset( $shortcode_attributes['recent_random_uploads'] );
215
+
216
  return $shortcode_attributes;
217
+ } // mla_gallery_attributes
218
 
219
  /**
220
  * Save the enclosed content
239
  *
240
  * @return array updated shortcode content
241
  */
242
+ public static function mla_gallery_initial_content( $shortcode_content, $shortcode_attributes ) {
243
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_initial_content $shortcode_content = ' . var_export( $shortcode_content, true ), 0 );
244
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_initial_content $shortcode_attributes = ' . var_export( $shortcode_attributes, true ), 0 );
245
 
246
  /*
247
  * Save the attributes for use in the later filters
249
  self::$shortcode_content = $shortcode_content;
250
 
251
  return $shortcode_content;
252
+ } // mla_gallery_initial_content
253
 
254
  /**
255
  * Save the shortcode arguments
276
  *
277
  * @return array updated gallery display arguments
278
  */
279
+ public static function mla_gallery_arguments( $all_display_parameters ) {
280
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_arguments $all_display_parameters = ' . var_export( $all_display_parameters, true ), 0 );
281
 
282
  self::$all_display_parameters = $all_display_parameters;
283
  return $all_display_parameters;
284
+ } // mla_gallery_arguments
285
 
286
  /**
287
  * Save the query attributes
308
  *
309
  * @return array updated shortcode attributes
310
  */
311
+ public static function mla_gallery_query_attributes( $query_attributes ) {
312
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_query_attributes $query_attributes = ' . var_export( $query_attributes, true ), 0 );
313
 
314
  self::$query_attributes = $query_attributes;
315
  return $query_attributes;
316
+ } // mla_gallery_query_attributes
317
 
318
  /**
319
  * Save the query arguments
336
  *
337
  * @return array updated attachment query arguments
338
  */
339
+ public static function mla_gallery_query_arguments( $all_query_parameters ) {
340
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_query_arguments $all_query_parameters = ' . var_export( $all_query_parameters, true ), 0 );
341
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_query_arguments self::$shortcode_attributes = ' . var_export( self::$shortcode_attributes, true ), 0 );
342
 
343
  self::$all_query_parameters = $all_query_parameters;
344
 
369
  if ( 0 == $recent_limit ) {
370
  return $all_query_parameters;
371
  }
372
+
373
  $display_limit = isset( $limits[1] ) ? absint( $limits[1] ) : 1;
374
  if ( 0 == $display_limit ) {
375
  $display_limit = 1;
422
  *
423
  * The queries supported in this example's "my_custom_sql" parameter include:
424
  *
425
+ * - one or more taxonomy term lists, with tax_relation and include_children
426
  * - one or more post_parent values
427
  * - one or more post_type values
428
  *
429
+ * Multiple taxonomy term lists are allowed, joined with tax_relation (AND, OR).
430
+ *
431
  * The three query parameters are joined with "OR", so items matching any of the three
432
  * parameters will be included. Any combination of the three parameters is accepted.
433
  *
434
+ * The "orderby", "order", "posts_per_page", "numberposts" and "paged" parameters may be
435
+ * added to the parameter value.
436
+ *
437
  * We use a shortcode parameter of our own to apply this filter on a gallery-by-gallery
438
  * basis, leaving other [mla_gallery] instances untouched. If the "my_custom_sql" parameter
439
  * is not present, we have nothing to do. If the parameter IS present, extract taxonomy,
456
  $post_parents = array();
457
  $parent_types = array();
458
 
459
+ // Set the taxonomy-related parameters
460
+ $tax_include_children = isset( $my_query_vars['include_children'] ) && 'true' == strtolower( trim( $my_query_vars['include_children'] ) );
461
+
462
+ $tax_relation = 'AND';
463
+ if ( isset( $my_query_vars['tax_relation'] ) ) {
464
+ if ( 'OR' == strtoupper( $my_query_vars['tax_relation'] ) ) {
465
+ $tax_relation = 'OR';
466
+ }
467
+ }
468
+
469
+ // Allow WP_Query synonyms for built-in WordPress taxonomies
470
+ if ( isset( $my_query_vars['tag'] ) ) {
471
+ $my_query_vars['post_tag'] = $my_query_vars['tag'];
472
+ unset( $my_query_vars['tag'] );
473
+ }
474
+
475
+ if ( isset( $my_query_vars['category_name'] ) ) {
476
+ $my_query_vars['category'] = $my_query_vars['category_name'];
477
+ unset( $my_query_vars['category_name'] );
478
+ }
479
+
480
+ // Find taxonomy argument(s), if present, and collect terms
481
+ $tax_queries = array();
482
+ $taxonomies = get_object_taxonomies( 'attachment', 'names' );
483
  foreach( $taxonomies as $taxonomy ) {
484
  if ( empty( $my_query_vars[ $taxonomy ] ) ) {
485
  continue;
486
  }
487
 
 
 
 
488
  // Allow for multiple term slug values
489
  $terms = array();
490
  $slugs = explode( ',', $my_query_vars[ $taxonomy ] );
493
  $terms = array_merge( $terms, get_terms( $taxonomy, $args ) );
494
  }
495
 
496
+ $ttids = array();
497
  foreach( $terms as $term ) {
498
  // Index by ttid to remove duplicates
499
  $ttids[ $term->term_taxonomy_id ] = $term->term_taxonomy_id;
500
 
501
+ if ( $tax_include_children ) {
502
  $args = array( 'child_of' => $term->term_id, 'hide_empty' => false );
503
+ $children = get_terms( $taxonomy, $args );
504
  foreach( $children as $child ) {
505
+ $ttids[ $child->term_taxonomy_id ] = $child->term_taxonomy_id;
506
  }
507
+ } // tax_include_children
508
  } // $term
509
 
510
+ // Allow for multiple taxonomy queries
511
+ if ( !empty( $ttids ) ) {
512
+ $tax_queries[ $taxonomy ] = $ttids;
513
+ }
514
  }
515
 
516
  if ( isset( $my_query_vars['post_parent'] ) ) {
534
  $query[] = "ON (p.post_parent = p2.ID)";
535
  }
536
 
537
+ // Add a separate JOIN for each taxonomy
538
+ if ( count( $tax_queries ) ) {
539
+ foreach ( $tax_queries as $taxonomy => $terms ) {
540
+ $tr = 'tr_' . $taxonomy;
541
+ $query[] = "LEFT JOIN {$wpdb->term_relationships} as $tr";
542
+ $query[] = "ON (p.ID = $tr.object_id)";
543
+ }
544
  }
545
+
546
  // Start with a WHERE clause that doesn't match anything, since OR is the connector
547
  $query[] = 'WHERE ( ( 1=0 )';
548
 
566
  $query[] = 'OR ( p2.post_type IN (' . join( ',', $placeholders ) . ') )';
567
  }
568
 
569
+ // Add taxonomy queries
570
+ if ( 1 < count( $tax_queries ) ) {
571
+ if ( 'AND' === $tax_relation ) {
572
+ $query[] = "OR ( (1=1)";
573
+ } else {
574
+ $query[] = "OR ( (1=0)";
575
+ }
576
+
577
+ foreach ( $tax_queries as $taxonomy => $terms ) {
578
+ $tr = 'tr_' . $taxonomy;
579
+ $placeholders = array();
580
+ foreach ( $terms as $ttid ) {
581
+ $placeholders[] = '%s';
582
+ $query_parameters[] = $ttid;
583
+ }
584
+
585
+ $query[] = "{$tax_relation} ( {$tr}.term_taxonomy_id IN (" . join( ',', $placeholders ) . ') )';
586
  }
587
 
588
+ $query[] = ')';
589
+ } elseif ( count( $tax_queries ) ) {
590
+ // There's only one, but we need both name and terms
591
+ foreach ( $tax_queries as $taxonomy => $terms ) {
592
+ $tr = 'tr_' . $taxonomy;
593
+ $placeholders = array();
594
+ foreach ( $terms as $ttid ) {
595
+ $placeholders[] = '%s';
596
+ $query_parameters[] = $ttid;
597
+ }
598
 
599
+ $query[] = "OR ( {$tr}.term_taxonomy_id IN (" . join( ',', $placeholders ) . ') )';
600
+ }
601
+ }
602
+
603
  // Close the WHERE clause
604
  $query[] = ')';
605
 
607
  $query[] = "AND p.post_type = 'attachment'";
608
  $query[] = "AND p.post_status = 'inherit'";
609
  $query[] = "GROUP BY p.ID";
 
610
 
611
  /*
612
+ * ORDER BY clause
 
613
  */
614
+ if ( ! empty( $my_query_vars['orderby'] ) ) {
615
+ $orderby = strtolower( $my_query_vars['orderby'] );
616
+ } else {
617
+ $orderby = 'none';
618
+ }
619
+ $all_query_parameters['orderby'] = 'post__in';
620
+
621
+ if ( ! empty( $my_query_vars['order'] ) ) {
622
+ $order = strtoupper( $my_query_vars['order'] );
623
+ if ( 'DESC' != $order ) {
624
+ $order = 'ASC';
625
+ }
626
+ } else {
627
+ $order = 'ASC';
628
+ }
629
+ $all_query_parameters['order'] = 'ASC';
630
+
631
+ switch ( $orderby ) {
632
+ case 'id':
633
+ $query[] = 'ORDER BY p.ID ' . $order;
634
+ break;
635
+ case 'author':
636
+ $query[] = 'ORDER BY p.post_author ' . $order;
637
+ break;
638
+ case 'date':
639
+ $query[] = 'ORDER BY p.post_date ' . $order;
640
+ break;
641
+ case 'description':
642
+ case 'content':
643
+ $query[] = 'ORDER BY p.post_content ' . $order;
644
+ break;
645
+ case 'title':
646
+ $query[] = 'ORDER BY p.post_title ' . $order;
647
+ break;
648
+ case 'caption':
649
+ case 'excerpt':
650
+ $query[] = 'ORDER BY p.post_excerpt ' . $order;
651
+ break;
652
+ case 'slug':
653
+ case 'name':
654
+ $query[] = 'ORDER BY p.post_name ' . $order;
655
+ break;
656
+ case 'modified':
657
+ $query[] = 'ORDER BY p.post_modified ' . $order;
658
+ break;
659
+ case 'parent':
660
+ $query[] = 'ORDER BY p.post_parent ' . $order;
661
+ break;
662
+ case 'menu_order':
663
+ $query[] = 'ORDER BY p.menu_order ' . $order;
664
+ break;
665
+ case 'post_mime_type':
666
+ $query[] = 'ORDER BY p.post_mime_type ' . $order;
667
+ break;
668
+ case 'comment_count':
669
+ $query[] = 'ORDER BY p.comment_count ' . $order;
670
+ break;
671
+ case 'rand':
672
+ case 'random':
673
+ $query[] = 'ORDER BY RAND() ' . $order;
674
+ break;
675
+ case 'none':
676
+ default:
677
+ break;
678
+ }
679
+
680
+ // Add pagination to our query
681
+ $paged = isset( $my_query_vars['paged'] ) ? $my_query_vars['paged'] : NULL;
682
  if ( empty( $paged ) ) {
683
  $paged = 1;
684
  } elseif ( 'current' == strtolower( $paged ) ) {
697
  $paged = 1;
698
  }
699
 
700
+ if ( ! empty( $my_query_vars['posts_per_page'] ) ) {
701
+ $limit = absint( $my_query_vars['posts_per_page'] );
702
+ } elseif ( ! empty( $my_query_vars['numberposts'] ) ) {
703
+ $limit = absint( $my_query_vars['numberposts'] );
704
+ } else {
705
+ $limit = 0;
706
+ }
707
+
708
  $offset = $limit * ( $paged - 1);
709
  if ( 0 < $offset && 0 < $limit ) {
710
  $query[] = 'LIMIT %d, %d';
719
  $query_parameters[] = 0x7FFFFFFF; // big number!
720
  }
721
 
 
 
 
 
722
  $query = join(' ', $query);
723
  $ids = $wpdb->get_results( $wpdb->prepare( $query, $query_parameters ) );
724
  if ( is_array( $ids ) ) {
730
  } else {
731
  $all_query_parameters['include'] = '1'; // return no images
732
  }
 
 
733
  } // parameter "my_custom_sql" is present
734
 
735
  return $all_query_parameters;
736
+ } // mla_gallery_query_arguments
737
 
738
  /**
739
  * Save some of the WP_Query object properties
757
  *
758
  * @return void actions never return anything
759
  */
760
+ public static function mla_gallery_wp_query_object( $query_arguments ) {
761
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_wp_query_object $query_arguments = ' . var_export( $query_arguments, true ), 0 );
762
 
763
  self::$wp_query_properties = array();
764
  self::$wp_query_properties ['request'] = MLAShortcodes::$mla_gallery_wp_query_object->request;
765
  self::$wp_query_properties ['query_vars'] = MLAShortcodes::$mla_gallery_wp_query_object->query_vars;
766
  self::$wp_query_properties ['post_count'] = MLAShortcodes::$mla_gallery_wp_query_object->post_count;
767
 
768
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_wp_query_object self::$wp_query_properties = ' . var_export( self::$wp_query_properties, true ), 0 );
769
 
770
  /*
771
  * Unlike Filters, Actions never return anything
772
  */
773
  return;
774
+ } // mla_gallery_wp_query_object
775
+
776
+ /**
777
+ * MLA Gallery The Attachments
778
+ *
779
+ * This filter gives you an opportunity to record or modify the array of items
780
+ * returned by the query.
781
+ *
782
+ * @since 1.09
783
+ *
784
+ * @param NULL $filtered_attachments initially NULL, indicating no substitution.
785
+ * @param array $attachments WP_Post objects returned by WP_Query->query, passed by reference
786
+ */
787
+ public static function mla_gallery_the_attachments( $filtered_attachments, $attachments ) {
788
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_the_attachments $attachments = ' . var_export( $attachments, true ), 0 );
789
+
790
+ return $filtered_attachments;
791
+ }
792
+
793
+ /**
794
+ * MLA Gallery Alternate Shortcode Blacklist
795
+ *
796
+ * This filter gives you an opportunity to record or modify the list of parameters to be
797
+ * removed from those passed to the alternative gallery shortcode.
798
+ *
799
+ * @since 1.09
800
+ *
801
+ * @param array $blacklist parameter_name => parameter_value pairs
802
+ */
803
+ public static function mla_gallery_alt_shortcode_blacklist( $blacklist ) {
804
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_alt_shortcode_blacklist blacklist = ' . var_export( $blacklist, true ), 0 );
805
+
806
+ return $blacklist;
807
+ } // mla_gallery_alt_shortcode_blacklist
808
+
809
+ /**
810
+ * MLA Gallery Alternate Shortcode Attributes
811
+ *
812
+ * This filter gives you an opportunity to record or modify the parameters passed to
813
+ * the alternative gallery shortcode.
814
+ *
815
+ * @since 1.09
816
+ *
817
+ * @param array $attr parameter_name => parameter_value pairs
818
+ */
819
+ public static function mla_gallery_alt_shortcode_attributes( $attr ) {
820
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_alt_shortcode_attributes attr = ' . var_export( $attr, true ), 0 );
821
+
822
+ return $attr;
823
+ } // mla_gallery_alt_shortcode_attributes
824
+
825
+ /**
826
+ * MLA Gallery Alternate Shortcode IDs
827
+ *
828
+ * This filter gives you an opportunity to record or modify the ID values or the entire
829
+ * mla_alt_shortcode_ids parameter passed to the alternative gallery shortcode.
830
+ *
831
+ * @since 1.09
832
+ *
833
+ * @param array $ids empty array, indicating no substitution
834
+ * @param string $ids_name parameter name
835
+ * @param array $attachments WP_Post objects returned by WP_Query->query, passed by reference
836
+ *
837
+ * @return array Substitute array of ID (or other) values to populate the parameter
838
+ * @return string Complete 'ids_name="value,value"' parameter or an empty string to omit parameter
839
+ */
840
+ public static function mla_gallery_alt_shortcode_ids( $ids, $ids_name, $attachments ) {
841
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_alt_shortcode_ids( $ids_name ) attachments = " . var_export( $attachments, true ), 0 );
842
+
843
+ return $ids;
844
+ } // mla_gallery_alt_shortcode_ids
845
 
846
  /**
847
  * MLA Gallery Enclosed Content, final filter
848
  *
849
  * This filter gives you an opportunity to record or modify the content enclosed by the shortcode
850
+ * when the [mla_gallery]content[/mla_gallery] form is used. This final filter is called just after
851
+ * the WP_query and before control is passed to the alternate gallery shortcode.
 
852
  *
853
  * @since 1.02
854
  *
856
  *
857
  * @return array updated shortcode content
858
  */
859
+ public static function mla_gallery_final_content( $shortcode_content ) {
860
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_final_content $shortcode_content = ' . var_export( $shortcode_content, true ), 0 );
861
 
862
  return $shortcode_content;
863
+ } // mla_gallery_final_content
864
+
865
+ /**
866
+ * MLA Gallery End Alternate Shortcode
867
+ *
868
+ * This action is called after the alternative gallery shortcode has been processed,
869
+ * so you can perform cleanup or other final actions.
870
+ *
871
+ * @since 1.09
872
+ */
873
+ public static function mla_gallery_end_alt_shortcode() {
874
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_end_alt_shortcode()', 0 );
875
+ } // mla_gallery_end_alt_shortcode
876
 
877
  /**
878
  * Use MLA Gallery Style
879
  *
880
  * You can use this filter to allow or suppress the inclusion of CSS styles in the
881
  * gallery output. Return 'true' to allow the styles, false to suppress them. You can also
882
+ * suppress styles by returning an empty string from the mla_gallery_style_parse below.
883
  *
884
  * @since 1.00
885
  *
888
  *
889
  * @return boolean true to fetch and parse the style template, false to leave it empty
890
  */
891
+ public static function use_mla_gallery_style( $use_style_template, $style_template_name ) {
892
+ //error_log( 'MLAGalleryHooksExample::use_mla_gallery_style $use_style_template = ' . var_export( $use_style_template, true ), 0 );
893
+ //error_log( 'MLAGalleryHooksExample::use_mla_gallery_style $style_template_name = ' . var_export( $style_template_name, true ), 0 );
894
 
895
  /*
896
  * Filters must return the first argument passed in, unchanged or updated
897
  */
898
  return $use_style_template;
899
+ } // use_mla_gallery_style
900
 
901
  /**
902
  * MLA Gallery Style Values
912
  *
913
  * @return array updated substitution parameter name => value pairs
914
  */
915
+ public static function mla_gallery_style_values( $style_values ) {
916
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_style_values $style_values = ' . var_export( $style_values, true ), 0 );
917
 
918
  /*
919
  * You also have access to the PHP Super Globals, e.g., $_REQUEST, $_SERVER
920
  */
921
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_style_values $_REQUEST = ' . var_export( $_REQUEST, true ), 0 );
922
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_style_values $_SERVER[ REQUEST_URI ] = ' . var_export( $_SERVER['REQUEST_URI'], true ), 0 );
923
 
924
  /*
925
  * You can use the WordPress globals like $wp_query, $wpdb and $table_prefix as well.
926
  * Note that $wp_query contains values for the post/page query, NOT the [mla_gallery] query.
927
  */
928
  global $wp_query;
929
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_style_values $wp_query->query = ' . var_export( $wp_query->query, true ), 0 );
930
 
931
  return $style_values;
932
+ } // mla_gallery_style_values
933
 
934
  /**
935
  * MLA Gallery Style Template
945
  *
946
  * @return string updated template
947
  */
948
+ public static function mla_gallery_style_template( $style_template ) {
949
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_style_template $style_template = ' . var_export( $style_template, true ), 0 );
950
 
951
  return $style_template;
952
+ } // mla_gallery_style_template
953
 
954
  /**
955
  * MLA Gallery Style Parse
968
  *
969
  * @return array updated HTML markup for gallery output
970
  */
971
+ public static function mla_gallery_style_parse( $html_markup, $style_template, $style_values ) {
972
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_style_parse $html_markup = ' . var_export( $html_markup, true ), 0 );
973
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_style_parse $style_template = ' . var_export( $style_template, true ), 0 );
974
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_style_parse $style_values = ' . var_export( $style_values, true ), 0 );
975
 
976
  return $html_markup;
977
+ } // mla_gallery_style_parse
978
 
979
  /**
980
  * MLA Gallery Open Values
988
  *
989
  * @return array updated substitution parameter name => value pairs
990
  */
991
+ public static function mla_gallery_open_values( $markup_values ) {
992
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_open_values $markup_values = ' . var_export( $markup_values, true ), 0 );
993
 
994
  return $markup_values;
995
+ } // mla_gallery_open_values
996
 
997
  /**
998
  * MLA Gallery Open Template
1003
  *
1004
  * @return string updated template
1005
  */
1006
+ public static function mla_gallery_open_template( $open_template ) {
1007
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_open_template $open_template = ' . var_export( $open_template, true ), 0 );
1008
 
1009
  /*
1010
  * Check for a display message
1014
  }
1015
 
1016
  return $open_template;
1017
+ } // mla_gallery_open_template
1018
 
1019
  /**
1020
  * MLA Gallery Open Parse
1027
  *
1028
  * @return array updated HTML markup for gallery output
1029
  */
1030
+ public static function mla_gallery_open_parse( $html_markup, $open_template, $markup_values ) {
1031
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_open_parse $html_markup = ' . var_export( $html_markup, true ), 0 );
1032
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_open_parse $open_template = ' . var_export( $open_template, true ), 0 );
1033
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_open_parse $markup_values = ' . var_export( $markup_values, true ), 0 );
1034
 
1035
  return $html_markup;
1036
+ } // mla_gallery_open_parse
1037
 
1038
  /**
1039
  * MLA Gallery Style
1051
  *
1052
  * @return array updated HTML markup for "gallery style" and "gallery open" output
1053
  */
1054
+ public static function mla_gallery_style( $html_markup, $style_values, $open_values, $style_template, $open_template ) {
1055
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_style $html_markup = ' . var_export( $html_markup, true ), 0 );
1056
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_style $style_values = ' . var_export( $style_values, true ), 0 );
1057
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_style $open_values = ' . var_export( $open_values, true ), 0 );
1058
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_style $style_template = ' . var_export( $style_template, true ), 0 );
1059
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_style $open_template = ' . var_export( $open_template, true ), 0 );
1060
 
1061
  return $html_markup;
1062
+ } // mla_gallery_style
1063
 
1064
  /**
1065
  * MLA Gallery Row Open Values
1070
  *
1071
  * @return array updated substitution parameter name => value pairs
1072
  */
1073
+ public static function mla_gallery_row_open_values( $markup_values ) {
1074
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_row_open_values $markup_values = ' . var_export( $markup_values, true ), 0 );
1075
 
1076
  return $markup_values;
1077
+ } // mla_gallery_row_open_values
1078
 
1079
  /**
1080
  * MLA Gallery Row Open Template
1085
  *
1086
  * @return string updated template
1087
  */
1088
+ public static function mla_gallery_row_open_template( $row_open_template ) {
1089
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_row_open_template $row_open_template = ' . var_export( $row_open_template, true ), 0 );
1090
 
1091
  return $row_open_template;
1092
+ } // mla_gallery_row_open_template
1093
 
1094
  /**
1095
  * MLA Gallery Row Open Parse
1102
  *
1103
  * @return array updated HTML markup for gallery output
1104
  */
1105
+ public static function mla_gallery_row_open_parse( $html_markup, $row_open_template, $markup_values ) {
1106
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_row_open_parse $html_markup = ' . var_export( $html_markup, true ), 0 );
1107
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_row_open_parse $row_open_template = ' . var_export( $row_open_template, true ), 0 );
1108
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_row_open_parse $markup_values = ' . var_export( $markup_values, true ), 0 );
1109
 
1110
  return $html_markup;
1111
+ } // mla_gallery_row_open_parse
1112
 
1113
  /**
1114
  * Replace the caption value and update captiontag_content as well
1146
  *
1147
  * @return array updated substitution parameter name => value pairs
1148
  */
1149
+ public static function mla_gallery_item_values( $item_values ) {
1150
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_item_values $item_values = ' . var_export( $item_values, true ), 0 );
1151
 
1152
  /*
1153
  * We use a shortcode parameter of our own to apply our filters on a gallery-by-gallery basis,
1163
  $item_values['terms:attachment_category'] = implode( ' ', $object_terms );
1164
  $item_values = self::_update_caption( $item_values, implode( ' ', $object_terms ) );
1165
 
1166
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_item_values terms = ' . var_export( $item_values['terms:attachment_category'], true ), 0 );
1167
  }
1168
 
1169
  /*
1344
  */
1345
  $custom_fields = array();
1346
  $post_meta = get_metadata( 'post', $item_values['attachment_ID'] );
1347
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_item_values $post_meta = ' . var_export( $post_meta, true ), 0 );
1348
 
1349
  if ( is_array( $post_meta ) ) {
1350
  foreach ( $post_meta as $post_meta_key => $post_meta_value ) {
1376
  $custom_fields[ $post_meta_key ] = $post_meta_value;
1377
  } // foreach $post_meta
1378
  }
1379
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_item_values $custom_fields = ' . var_export( $custom_fields, true ), 0 );
1380
 
1381
  /*
1382
  * Don't alter the caption if there are no custom fields to display
1399
  */
1400
  $item_values = self::_update_caption( $item_values, $my_caption );
1401
  return $item_values;
1402
+ } // mla_gallery_item_values
1403
 
1404
  /**
1405
  * MLA Gallery Item Template
1410
  *
1411
  * @return string updated template
1412
  */
1413
+ public static function mla_gallery_item_template( $item_template ) {
1414
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_item_template $item_template = ' . var_export( $item_template, true ), 0 );
1415
 
1416
  return $item_template;
1417
+ } // mla_gallery_item_template
1418
 
1419
  /**
1420
  * MLA Gallery Item Parse
1427
  *
1428
  * @return array updated HTML markup for gallery output
1429
  */
1430
+ public static function mla_gallery_item_parse( $html_markup, $item_template, $item_values ) {
1431
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_item_parse $html_markup = ' . var_export( $html_markup, true ), 0 );
1432
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_item_parse $item_template = ' . var_export( $item_template, true ), 0 );
1433
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_item_parse $item_values = ' . var_export( $item_values, true ), 0 );
1434
 
1435
  return $html_markup;
1436
+ } // mla_gallery_item_parse
1437
 
1438
  /**
1439
  * MLA Gallery Row Close Values
1444
  *
1445
  * @return array updated substitution parameter name => value pairs
1446
  */
1447
+ public static function mla_gallery_row_close_values( $markup_values ) {
1448
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_row_close_values $markup_values = ' . var_export( $markup_values, true ), 0 );
1449
 
1450
  return $markup_values;
1451
+ } // mla_gallery_row_close_values
1452
 
1453
  /**
1454
  * MLA Gallery Row Close Template
1459
  *
1460
  * @return string updated template
1461
  */
1462
+ public static function mla_gallery_row_close_template( $row_close_template ) {
1463
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_row_close_template $row_close_template = ' . var_export( $row_close_template, true ), 0 );
1464
 
1465
  return $row_close_template;
1466
+ } // mla_gallery_row_close_template
1467
 
1468
  /**
1469
  * MLA Gallery Row Close Parse
1476
  *
1477
  * @return array updated HTML markup for gallery output
1478
  */
1479
+ public static function mla_gallery_row_close_parse( $html_markup, $row_close_template, $markup_values ) {
1480
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_row_close_parse $html_markup = ' . var_export( $html_markup, true ), 0 );
1481
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_row_close_parse $row_close_template = ' . var_export( $row_close_template, true ), 0 );
1482
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_row_close_parse $markup_values = ' . var_export( $markup_values, true ), 0 );
1483
 
1484
  return $html_markup;
1485
+ } // mla_gallery_row_close_parse
1486
 
1487
  /**
1488
  * MLA Gallery Close Values
1493
  *
1494
  * @return array updated substitution parameter name => value pairs
1495
  */
1496
+ public static function mla_gallery_close_values( $markup_values ) {
1497
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_close_values $markup_values = ' . var_export( $markup_values, true ), 0 );
1498
 
1499
  return $markup_values;
1500
+ } // mla_gallery_close_values
1501
 
1502
  /**
1503
  * MLA Gallery Close Template
1508
  *
1509
  * @return string updated template
1510
  */
1511
+ public static function mla_gallery_close_template( $close_template ) {
1512
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_close_template $close_template = ' . var_export( $close_template, true ), 0 );
1513
 
1514
  return $close_template;
1515
+ } // mla_gallery_close_template
1516
 
1517
  /**
1518
  * MLA Gallery Close Parse
1525
  *
1526
  * @return array updated HTML markup for gallery output
1527
  */
1528
+ public static function mla_gallery_close_parse( $html_markup, $close_template, $markup_values ) {
1529
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_close_parse $html_markup = ' . var_export( $html_markup, true ), 0 );
1530
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_close_parse $close_template = ' . var_export( $close_template, true ), 0 );
1531
+ //error_log( 'MLAGalleryHooksExample::mla_gallery_close_parse $markup_values = ' . var_export( $markup_values, true ), 0 );
1532
 
1533
  return $html_markup;
1534
+ } // mla_gallery_close_parse
1535
 
1536
  } // Class MLAGalleryHooksExample
1537
 
examples/plugins/mla-multi-search-example.php ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Adds custom field search(es) to the [mla_gallery] keyword(s) search results
4
+ *
5
+ * In this example:
6
+ *
7
+ * 1. A custom "multi_search" parameter names one or more "search keys", e.g.
8
+ * multi_search="keyword:,custom:Country,custom:City"
9
+ *
10
+ * 2. Each custom field is queried for a LIKE match with the content of the "s" parameter.
11
+ *
12
+ * 3. Matches from the custom field search(es) are added to any keyword(s) search matches,
13
+ * i.e., all searches are joined by "OR".
14
+ *
15
+ * This example plugin uses two of the many filters available in the [mla_gallery] shortcode
16
+ * and illustrates a technique you can use to customize the gallery display.
17
+ *
18
+ * Created for support topic "Gallery layout with thumbnails"
19
+ * opened on 11/20/2016 by "marineb30".
20
+ * https://wordpress.org/support/topic/gallery-layout-with-thumbnails/
21
+ *
22
+ * @package MLA Multi-search Example
23
+ * @version 1.00
24
+ */
25
+
26
+ /*
27
+ Plugin Name: MLA Multi-search Example
28
+ Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
29
+ Description: Adds custom field search(es) to the [mla_gallery] keyword(s) search results
30
+ Author: David Lingren
31
+ Version: 1.00
32
+ Author URI: http://fairtradejudaica.org/our-story/staff/
33
+
34
+ Copyright 2016 David Lingren
35
+
36
+ This program is free software; you can redistribute it and/or modify
37
+ it under the terms of the GNU General Public License as published by
38
+ the Free Software Foundation; either version 2 of the License, or
39
+ (at your option) any later version.
40
+
41
+ This program is distributed in the hope that it will be useful,
42
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
43
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44
+ GNU General Public License for more details.
45
+
46
+ You can get a copy of the GNU General Public License by writing to the
47
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
48
+ */
49
+
50
+ /**
51
+ * Class MLA Multi-search Example hooks all of the filters provided by the [mla_gallery] shortcode
52
+ *
53
+ * Call it anything you want, but give it an unlikely and hopefully unique name. Hiding everything
54
+ * else inside a class means this is the only name you have to worry about.
55
+ *
56
+ * @package MLA Multi-search Example
57
+ * @since 1.00
58
+ */
59
+ class MLAMultiSearchExample {
60
+ /**
61
+ * Initialization function, similar to __construct()
62
+ *
63
+ * @since 1.00
64
+ *
65
+ * @return void
66
+ */
67
+ public static function initialize() {
68
+ // The filters are only useful for front-end posts/pages; exit if in the admin section
69
+ if ( is_admin() )
70
+ return;
71
+
72
+ add_filter( 'mla_gallery_attributes', 'MLAMultiSearchExample::mla_gallery_attributes', 10, 1 );
73
+ add_filter( 'mla_gallery_query_arguments', 'MLAMultiSearchExample::mla_gallery_query_arguments', 10, 1 );
74
+ }
75
+
76
+ /**
77
+ * Save the shortcode attributes
78
+ *
79
+ * @since 1.00
80
+ *
81
+ * @var array
82
+ */
83
+ private static $shortcode_attributes = array();
84
+
85
+ /**
86
+ * Save the arguments passed in to the shortcode for use in the custom query
87
+ *
88
+ * @since 1.00
89
+ *
90
+ * @param array the shortcode parameters passed in to the shortcode
91
+ */
92
+ public static function mla_gallery_attributes( $shortcode_attributes ) {
93
+ //error_log( 'MLAMultiSearchExample::mla_gallery_attributes $shortcode_attributes = ' . var_export( $shortcode_attributes, true ), 0 );
94
+ // Save the attributes for use in the later filters
95
+ self::$shortcode_attributes = $shortcode_attributes;
96
+ unset( $shortcode_attributes['multi_search'] );
97
+
98
+ return $shortcode_attributes;
99
+ } // mla_gallery_attributes
100
+
101
+ /**
102
+ * Look for the multi_search parameter and process it
103
+ *
104
+ * @since 1.00
105
+ *
106
+ * @param array shortcode arguments merged with attachment selection defaults, so every possible parameter is present
107
+ */
108
+ public static function mla_gallery_query_arguments( $all_query_parameters ) {
109
+ //error_log( 'MLAMultiSearchExample::mla_gallery_query_arguments self::$shortcode_attributes = ' . var_export( self::$shortcode_attributes, true ), 0 );
110
+ //error_log( 'MLAMultiSearchExample::mla_gallery_query_arguments $all_query_parameters = ' . var_export( $all_query_parameters, true ), 0 );
111
+
112
+ /*
113
+ * We use a shortcode parameter of our own to apply this filter on a gallery-by-gallery
114
+ * basis, leaving other [mla_gallery] instances untouched. If the "multi_search" parameter
115
+ * is not present, we have nothing to do. If the parameter IS present, perform one or more
116
+ * searches and combine the results.
117
+ */
118
+ if ( isset( self::$shortcode_attributes['multi_search'] ) ) {
119
+ global $post;
120
+
121
+ $multi_search = self::$shortcode_attributes['multi_search'];
122
+ unset( self::$shortcode_attributes['multi_search'] );
123
+ $attr = self::$shortcode_attributes;
124
+ unset( $attr['s'] );
125
+
126
+ // remove pagination and sort parameters
127
+ if ( isset( $attr['mla_page_parameter'] ) ) {
128
+ unset( $attr[ $attr['mla_page_parameter'] ] );
129
+ }
130
+
131
+ unset( $attr['mla_page_parameter'] );
132
+ unset( $attr['numberposts'] );
133
+ unset( $attr['posts_per_page'] );
134
+ unset( $attr['posts_per_archive_page'] );
135
+ unset( $attr['paged'] );
136
+ unset( $attr['offset'] );
137
+ unset( $attr['mla_paginate_current'] );
138
+ unset( $attr['mla_paginate_total'] );
139
+ $attr['nopaging'] = true;
140
+ $attr['orderby'] = 'none';
141
+
142
+ $results = array();
143
+ $search_value = !empty( self::$shortcode_attributes['s'] ) ? trim( self::$shortcode_attributes['s'] ) : '';
144
+ $search_keys = explode( ',', $multi_search );
145
+
146
+ foreach( $search_keys as $search_key ) {
147
+ $tokens = array_map( 'trim', explode( ':', $search_key ) );
148
+ switch ( $tokens[0] ) {
149
+ case 'keyword':
150
+ $attr['s'] = $search_value;
151
+ $attachments = MLAShortcodes::mla_get_shortcode_attachments( $post->ID, $attr, true );
152
+ unset( $attr['s'] );
153
+ break;
154
+ case 'custom':
155
+ $attr['meta_key'] = $tokens[1];
156
+ $attr['meta_value'] = $search_value;
157
+ $attr['meta_compare'] = 'LIKE';
158
+ $attachments = MLAShortcodes::mla_get_shortcode_attachments( $post->ID, $attr, true );
159
+ unset( $attr['meta_compare'] );
160
+ unset( $attr['meta_value'] );
161
+ unset( $attr['meta_key'] );
162
+ break;
163
+ default:
164
+ $attachments = array();
165
+ } // switch tokens[0]
166
+
167
+ if ( is_string( $attachments ) ) {
168
+ $attachments = array();
169
+ }
170
+
171
+ unset( $attachments['found_rows'] );
172
+ unset( $attachments['max_num_pages'] );
173
+
174
+ foreach ( $attachments as $attachment ) {
175
+ $results[ $attachment->ID ] = $attachment->ID;
176
+ }
177
+ }
178
+
179
+ if ( count( $results ) ) {
180
+ $all_query_parameters['include'] = implode( ',', $results );
181
+ } else {
182
+ $all_query_parameters['include'] = '1';
183
+ }
184
+
185
+ $all_query_parameters['s'] = '';
186
+ } // parameter "multi_search" is present
187
+
188
+ return $all_query_parameters;
189
+ } // mla_gallery_query_arguments
190
+ } // Class MLAMultiSearchExample
191
+
192
+ /*
193
+ * Install the filters at an early opportunity
194
+ */
195
+ add_action('init', 'MLAMultiSearchExample::initialize');
196
+ ?>
examples/plugins/mla-not-featured-view-example.php ADDED
@@ -0,0 +1,342 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Provides an example of hooking the filters provided by the MLA_List_Table class
4
+ *
5
+ * This example adds a Media/Assistant submenu table view for items NOT
6
+ * featured in any posts/pages.
7
+ *
8
+ * Created for support topic "Filter by post status"
9
+ * opened on 2/24/2015 by "milkchic".
10
+ * https://wordpress.org/support/topic/filter-by-post-status/
11
+ *
12
+ * @package MLA Not Featured View Example
13
+ * @version 1.00
14
+ */
15
+
16
+ /*
17
+ Plugin Name:MLA Not Featured View Example
18
+ Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
19
+ Description: Adds a Media/Assistant submenu table view for items NOT featured in any posts/pages.
20
+ Author: David Lingren
21
+ Version: 1.00
22
+ Author URI: http://fairtradejudaica.org/our-story/staff/
23
+
24
+ Copyright 2014 - 2015 David Lingren
25
+
26
+ This program is free software; you can redistribute it and/or modify
27
+ it under the terms of the GNU General Public License as published by
28
+ the Free Software Foundation; either version 2 of the License, or
29
+ (at your option) any later version.
30
+
31
+ This program is distributed in the hope that it will be useful,
32
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
33
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34
+ GNU General Public License for more details.
35
+
36
+ You can get a copy of the GNU General Public License by writing to the
37
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
38
+ */
39
+
40
+ /**
41
+ * Class MLA Not Featured View Example hooks some of the filters provided by the MLA_List_Table class
42
+ *
43
+ * Call it anything you want, but give it an unlikely and hopefully unique name. Hiding everything
44
+ * else inside a class means this is the only name you have to worry about.
45
+ *
46
+ * @packageMLA CustomView Example
47
+ * @since 1.00
48
+ */
49
+ class MLANotFeaturedViewExample {
50
+ /**
51
+ * Initialization function, similar to __construct()
52
+ *
53
+ * @since 1.00
54
+ *
55
+ * @return void
56
+ */
57
+ public static function initialize() {
58
+ /*
59
+ * The remaining filters are only useful for the admin section; exit in the front-end posts/pages
60
+ */
61
+ if ( ! is_admin() ) {
62
+ return;
63
+ }
64
+
65
+ /*
66
+ * add_action and add_filter parameters:
67
+ * $tag - name of the hook you're filtering; defined by [mla_gallery]
68
+ * $function_to_add - function to be called when [mla_gallery] applies the filter
69
+ * $priority - default 10; lower runs earlier, higher runs later
70
+ * $accepted_args - number of arguments your function accepts
71
+ */
72
+
73
+ /*
74
+ * Defined in /wp-admin/includes/class-wp-list-table.php
75
+ */
76
+ add_filter( 'views_media_page_mla-menu', 'MLANotFeaturedViewExample::views_media_page_mla_menu', 10, 1 );
77
+
78
+ /*
79
+ * Defined in /media-library-assistant/includes/class-mla-list-table.php
80
+ */
81
+ add_filter( 'mla_list_table_submenu_arguments', 'MLANotFeaturedViewExample::mla_list_table_submenu_arguments', 10, 2 );
82
+
83
+ add_filter( 'mla_list_table_prepare_items_pagination', 'MLANotFeaturedViewExample::mla_list_table_prepare_items_pagination', 10, 2 );
84
+ add_filter( 'mla_list_table_prepare_items_total_items', 'MLANotFeaturedViewExample::mla_list_table_prepare_items_total_items', 10, 2 );
85
+ add_filter( 'mla_list_table_prepare_items_the_items', 'MLANotFeaturedViewExample::mla_list_table_prepare_items_the_items', 10, 2 );
86
+ }
87
+
88
+ /**
89
+ * Add custom views for the Media/Assistant submenu
90
+ *
91
+ * @since 1.00
92
+ *
93
+ * @param string The slug for the custom view to evaluate
94
+ * @param string The slug for the current custom view, or ''
95
+ *
96
+ * @return mixed HTML for link to display the view, false if count = zero
97
+ */
98
+ private static function _get_view( $view_slug, $current_view ) {
99
+ global $wpdb;
100
+ static $posts_per_view = NULL,
101
+ $view_singular = array (),
102
+ $view_plural = array ();
103
+
104
+ /*
105
+ * Calculate the common values once per page load
106
+ */
107
+ if ( is_null( $posts_per_view ) ) {
108
+ $items = (integer) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} AS item LEFT JOIN ( SELECT DISTINCT sub.meta_value FROM {$wpdb->postmeta} AS sub WHERE ( sub.meta_key = '_thumbnail_id' ) ) AS meta ON item.ID = meta.meta_value WHERE meta.meta_value IS NULL AND item.post_type = 'attachment' AND item.post_status = 'inherit'" );
109
+ $posts_per_view = array( 'notfeatured' => $items );
110
+
111
+ $view_singular = array (
112
+ 'notfeatured' => __( 'Not Featured', 'mla-not-featured-view-example' ),
113
+ );
114
+ $view_plural = array (
115
+ 'notfeatured' => __( 'Not Featured', 'mla-not-featured-view-example' ),
116
+ );
117
+ }
118
+
119
+ /*
120
+ * Make sure the slug is in our list and has posts
121
+ */
122
+ if ( array_key_exists( $view_slug, $posts_per_view ) ) {
123
+ $post_count = $posts_per_view[ $view_slug ];
124
+ $singular = sprintf('%s <span class="count">(%%s)</span>', $view_singular[ $view_slug ] );
125
+ $plural = sprintf('%s <span class="count">(%%s)</span>', $view_plural[ $view_slug ] );
126
+ $nooped_plural = _n_noop( $singular, $plural, 'mla-not-featured-view-example' );
127
+ } else {
128
+ return false;
129
+ }
130
+
131
+ if ( $post_count ) {
132
+ $query = array( 'nfve_view' => $view_slug );
133
+ $base_url = 'upload.php?page=mla-menu';
134
+ $class = ( $view_slug == $current_view ) ? ' class="current"' : '';
135
+
136
+ return "<a href='" . add_query_arg( $query, $base_url ) . "'$class>" . sprintf( translate_nooped_plural( $nooped_plural, $post_count, 'mla-not-featured-view-example' ), number_format_i18n( $post_count ) ) . '</a>';
137
+ }
138
+
139
+ return false;
140
+ }
141
+
142
+ /**
143
+ * Views for media page MLA Menu
144
+ *
145
+ * This filter gives you an opportunity to filter the list of available list table views.
146
+ *
147
+ * @since 1.00
148
+ *
149
+ * @param array $views An array of available list table views.
150
+ * format: view_slug => link to the view, with count
151
+ *
152
+ * @return array updated list table views.
153
+ */
154
+ public static function views_media_page_mla_menu( $views ) {
155
+ // See if the current view is a custom view
156
+ if ( isset( $_REQUEST['nfve_view'] ) ) {
157
+ switch( $_REQUEST['nfve_view'] ) {
158
+ case 'notfeatured':
159
+ $current_view = 'notfeatured';
160
+ break;
161
+ default:
162
+ $current_view = '';
163
+ } // nfve_view
164
+ } else {
165
+ $current_view = '';
166
+ }
167
+
168
+ foreach ( $views as $slug => $view ) {
169
+ // Find/update the current view
170
+ if ( strpos( $view, ' class="current"' ) ) {
171
+ if ( ! empty( $current_view ) ) {
172
+ $views[ $slug ] = str_replace( ' class="current"', '', $view );
173
+ } else {
174
+ $current_view = $slug;
175
+ }
176
+ }
177
+ } // each view
178
+
179
+ $value = self::_get_view( 'notfeatured', $current_view );
180
+ if ( $value ) {
181
+ $views['notfeatured'] = $value;
182
+ }
183
+
184
+ return $views;
185
+ } // views_media_page_mla_menu
186
+
187
+ /**
188
+ * Filter the "sticky" submenu URL parameters
189
+ *
190
+ * This filter gives you an opportunity to filter the URL parameters that will be
191
+ * retained when the submenu page refreshes.
192
+ *
193
+ * @since 1.00
194
+ *
195
+ * @param array $submenu_arguments Current view, pagination and sort parameters.
196
+ * @param object $include_filters True to include "filter-by" parameters, e.g., year/month dropdown.
197
+ *
198
+ * @return array updated submenu_arguments.
199
+ */
200
+ public static function mla_list_table_submenu_arguments( $submenu_arguments, $include_filters ) {
201
+ // If the current view is a custom view, retain it
202
+ if ( isset( $_REQUEST['nfve_view'] ) ) {
203
+ $submenu_arguments['nfve_view'] = $_REQUEST['nfve_view'];
204
+ }
205
+
206
+ return $submenu_arguments;
207
+ } // mla_list_table_submenu_arguments
208
+
209
+ /**
210
+ * Pagination parameters for custom views
211
+ *
212
+ * @since 1.00
213
+ *
214
+ * @var array
215
+ */
216
+ private static $pagination_parameters = array(
217
+ 'per_page' => NULL,
218
+ 'current_page' => NULL,
219
+ );
220
+
221
+ /**
222
+ * Filter the pagination parameters for prepare_items()
223
+ *
224
+ * This filter gives you an opportunity to filter the per_page and current_page
225
+ * parameters used for the prepare_items database query.
226
+ *
227
+ * @since 1.00
228
+ *
229
+ * @param array $pagination Contains 'per_page', 'current_page'.
230
+ * @param object $mla_list_table The MLA_List_Table object, passed by reference.
231
+ *
232
+ * @return array updated pagination array.
233
+ */
234
+ public static function mla_list_table_prepare_items_pagination( $pagination, $mla_list_table ) {
235
+ global $wpdb;
236
+
237
+ /*
238
+ * Save the parameters for the count and items filters
239
+ */
240
+ self::$pagination_parameters = $pagination;
241
+ return $pagination;
242
+ } // mla_list_table_prepare_items_pagination
243
+
244
+ /**
245
+ * Filters all clauses for shortcode queries, pre caching plugins
246
+ *
247
+ * Modifying the query by editing the clauses in this filter ensures that all the other
248
+ * "List Table" parameters are retained, e.g., orderby, month, taxonomy and Search Media.
249
+ *
250
+ * @since 1.00
251
+ *
252
+ * @param array query clauses before modification
253
+ *
254
+ * @return array query clauses after modification (none)
255
+ */
256
+ public static function posts_clauses( $pieces ) {
257
+ global $wpdb;
258
+
259
+ if ( isset( $_REQUEST['nfve_view'] ) ) {
260
+ switch( $_REQUEST['nfve_view'] ) {
261
+ case 'notfeatured':
262
+ $pieces['join'] = " LEFT JOIN ( SELECT DISTINCT sub.meta_value FROM {$wpdb->postmeta} AS sub WHERE ( sub.meta_key = '_thumbnail_id' ) ) AS meta ON {$wpdb->posts}.ID = meta.meta_value" . $pieces['join'];
263
+ $pieces['where'] = " AND meta.meta_value IS NULL" . $pieces['where'];
264
+ break;
265
+ default:
266
+ } // nfve_view
267
+ }
268
+
269
+ return $pieces;
270
+ } // posts_clauses
271
+
272
+ /**
273
+ * Filter the total items count for prepare_items()
274
+ *
275
+ * This filter gives you an opportunity to substitute your own $total_items
276
+ * parameter used for the prepare_items database query.
277
+ *
278
+ * @since 1.00
279
+ *
280
+ * @param integer $total_items NULL, indicating no substitution.
281
+ * @param object $mla_list_table The MLA_List_Table object, passed by reference.
282
+ *
283
+ * @return integer updated total_items.
284
+ */
285
+ public static function mla_list_table_prepare_items_total_items( $total_items, $mla_list_table ) {
286
+ global $wpdb;
287
+
288
+ if ( isset( $_REQUEST['nfve_view'] ) ) {
289
+ switch( $_REQUEST['nfve_view'] ) {
290
+ case 'notfeatured':
291
+ // Defined in /wp-includes/query.php, function get_posts()
292
+ add_filter( 'posts_clauses', 'MLANotFeaturedViewExample::posts_clauses', 10, 1 );
293
+ $current_page = self::$pagination_parameters['current_page'];
294
+ $per_page = self::$pagination_parameters['per_page'];
295
+ $total_items = MLAData::mla_count_list_table_items( $_REQUEST, ( ( $current_page - 1 ) * $per_page ), $per_page );
296
+ remove_filter( 'posts_clauses', 'MLANotFeaturedViewExample::posts_clauses', 10 );
297
+ break;
298
+ default:
299
+ } // nfve_view
300
+ }
301
+
302
+ return $total_items;
303
+ } // mla_list_table_prepare_items_total_items
304
+
305
+ /**
306
+ * Filter the items returned by prepare_items()
307
+ *
308
+ * This filter gives you an opportunity to substitute your own items array
309
+ * in place of the default prepare_items database query.
310
+ *
311
+ * @since 1.00
312
+ *
313
+ * @param array $items NULL, indicating no substitution.
314
+ * @param object $mla_list_table The MLA_List_Table object, passed by reference.
315
+ *
316
+ * @return array updated $items array.
317
+ */
318
+ public static function mla_list_table_prepare_items_the_items( $items, $mla_list_table ) {
319
+ global $wpdb;
320
+
321
+ if ( isset( $_REQUEST['nfve_view'] ) ) {
322
+ switch( $_REQUEST['nfve_view'] ) {
323
+ case 'notfeatured':
324
+ add_filter( 'posts_clauses', 'MLANotFeaturedViewExample::posts_clauses', 10, 1 );
325
+ $current_page = self::$pagination_parameters['current_page'];
326
+ $per_page = self::$pagination_parameters['per_page'];
327
+ $items = MLAData::mla_query_list_table_items( $_REQUEST, ( ( $current_page - 1 ) * $per_page ), $per_page );
328
+ remove_filter( 'posts_clauses', 'MLANotFeaturedViewExample::posts_clauses', 10 );
329
+ break;
330
+ default:
331
+ } // nfve_view
332
+ }
333
+
334
+ return $items;
335
+ } // mla_list_table_prepare_items_the_items
336
+ } // Class MLANotFeaturedViewExample
337
+
338
+ /*
339
+ * Install the filters at an early opportunity
340
+ */
341
+ add_action('init', 'MLANotFeaturedViewExample::initialize');
342
+ ?>
examples/plugins/mla-parent-wp-query-example.php ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Provides an [mla_gallery] parameter to select parent posts/pages with WP_Query
4
+ *
5
+ * In this example, a custom "parent_wp_query" parameter contains WP_Query arguments for
6
+ * parent posts/pages, e.g., " parent_wp_query='category_name=environment' ".
7
+ * The query value generates a list of "post_parent" values for the Media Library items query.
8
+ *
9
+ * You can add most WP_Query parameters to the parent query, e.g.:
10
+ *
11
+ * [mla_gallery parent_wp_query='category_name=environment post_type=post,page numberposts=10']
12
+ *
13
+ * NOTE: To affect the parent query you must add the parameters inside the parent_wp_query value.
14
+ *
15
+ * This example plugin uses one of the many filters available in the [mla_gallery] shortcode
16
+ * and illustrates a technique you can use to customize the gallery display.
17
+ *
18
+ * Created for support topic "Create gallery of all images attached to a list of posts?"
19
+ * opened on 9/4/2016 by "cconstantine".
20
+ * https://wordpress.org/support/topic/create-gallery-of-all-images-attached-to-a-list-of-posts/
21
+ *
22
+ * @package MLA Parent WP_Query Example
23
+ * @version 1.00
24
+ */
25
+
26
+ /*
27
+ Plugin Name: MLA Parent WP_Query Example
28
+ Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
29
+ Description: Selects items attached to parents assigned to a taxonomy term
30
+ Author: David Lingren
31
+ Version: 1.00
32
+ Author URI: http://fairtradejudaica.org/our-story/staff/
33
+
34
+ Copyright 2016 David Lingren
35
+
36
+ This program is free software; you can redistribute it and/or modify
37
+ it under the terms of the GNU General Public License as published by
38
+ the Free Software Foundation; either version 2 of the License, or
39
+ (at your option) any later version.
40
+
41
+ This program is distributed in the hope that it will be useful,
42
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
43
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44
+ GNU General Public License for more details.
45
+
46
+ You can get a copy of the GNU General Public License by writing to the
47
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
48
+ */
49
+
50
+ /**
51
+ * Class MLA Parent WP_Query Example selects post_parent values with a WP_Query
52
+ *
53
+ * @package MLA Parent WP_Query Example
54
+ * @since 1.00
55
+ */
56
+ class MLAParentWPQueryExample {
57
+ /**
58
+ * Initialization function, similar to __construct()
59
+ *
60
+ * @since 1.00
61
+ */
62
+ public static function initialize() {
63
+ // The filters are only useful for front-end posts/pages; exit if in the admin section
64
+ if ( is_admin() )
65
+ return;
66
+
67
+ add_filter( 'mla_gallery_attributes', 'MLAParentWPQueryExample::mla_gallery_attributes_filter', 10, 1 );
68
+ }
69
+
70
+ /**
71
+ * Replace the parent_wp_query value with a list of post_parent values
72
+ *
73
+ * The $shortcode_attributes array is where you will find any of your own parameters that are coded in the
74
+ * shortcode, e.g., [mla_gallery parent_wp_query="category_name=environment"].
75
+ *
76
+ * @since 1.00
77
+ *
78
+ * @param array the shortcode parameters passed in to the shortcode
79
+ */
80
+ public static function mla_gallery_attributes_filter( $shortcode_attributes ) {
81
+ global $wpdb;
82
+
83
+ // ignore shortcodes without the parent_wp_query parameter
84
+ if ( empty( $shortcode_attributes['parent_wp_query'] ) ) {
85
+ return $shortcode_attributes;
86
+ }
87
+
88
+ // Make sure $arguments is an array, even if it's empty
89
+ $arguments = $shortcode_attributes['parent_wp_query'];
90
+ if ( empty( $arguments ) ) {
91
+ $arguments = array();
92
+ } elseif ( is_string( $arguments ) ) {
93
+ $arguments = shortcode_parse_atts( $arguments );
94
+ }
95
+
96
+ // Multi-value post_type and post_status must be arrays
97
+
98
+ if ( isset( $arguments['post_type'] ) ) {
99
+ $arguments['post_type'] = explode( ',', $arguments['post_type'] );
100
+ }
101
+
102
+ if ( isset( $arguments['post_status'] ) ) {
103
+ $arguments['post_status'] = explode( ',', $arguments['post_status'] );
104
+ }
105
+
106
+ $wp_query_object = new WP_Query;
107
+ $parents = $wp_query_object->query( $arguments );
108
+ if ( is_array( $parents ) ) {
109
+ $post_parents = array();
110
+ foreach( $parents as $parent ) {
111
+ $post_parents[] = $parent->ID;
112
+ }
113
+ $shortcode_attributes['post_parent'] = implode( ',', $post_parents );
114
+ }
115
+
116
+ unset( $shortcode_attributes['parent_wp_query'] );
117
+
118
+ return $shortcode_attributes;
119
+ } // mla_gallery_attributes_filter
120
+ } // Class MLAParentWPQueryExample
121
+
122
+ /*
123
+ * Install the filters at an early opportunity
124
+ */
125
+ add_action('init', 'MLAParentWPQueryExample::initialize');
126
+ ?>
examples/plugins/mla-random-galleries-example.php CHANGED
@@ -1,4 +1,27 @@
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  /*
3
  Plugin Name: MLA Random Galleries Example
4
  Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
1
  <?php
2
+ /**
3
+ * Provides an [mla_gallery] parameter to select random items from a collection of Att. Category terms
4
+ *
5
+ * In this example, a custom "random_category" parameter names an Att. Category term.
6
+ * The value is matched to a list of terms in the $gallery_terms array in the plugin source code.
7
+ * If the term is in the list items assigned to the term are returned in random order.
8
+ * The 'numberposts' parameter can be added to limit the number of items returned. For example:
9
+ *
10
+ * [mla_gallery random_category=admin numberposts=1]
11
+ *
12
+ * NOTE: You must enter the name or slug values for your application's terms in the $gallery_terms array below.
13
+ *
14
+ * This example plugin uses one of the many filters available in the [mla_gallery] shortcode
15
+ * and illustrates a technique you can use to customize the gallery display.
16
+ *
17
+ * Created for support topic "multiple calls to a smaller amount"
18
+ * opened on 1/16/2016 by "luigsm".
19
+ * https://wordpress.org/support/topic/multiple-calls-to-a-smaller-amount
20
+ *
21
+ * @package MLA Random Galleries Example
22
+ * @version 1.00
23
+ */
24
+
25
  /*
26
  Plugin Name: MLA Random Galleries Example
27
  Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
examples/plugins/mla-regenerate-thumbnails-example.php ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Adds "Regenerate Thumbnails" actions to rollover actions and Bulk Edit dropdown
4
+ *
5
+ * In this example, the "Regenerate Thumbnails" plugin is detected and if found,
6
+ * "Regenerate Thumbnails" actions are added to the Media/Assistant item rollover
7
+ * actions and the Bulk Edit dropdown controls.
8
+ *
9
+ * This example plugin uses two of the many filters available in the Media/Assistant submenu screen
10
+ * and illustrates a technique you can use to customize the submenu table display.
11
+ *
12
+ * Created for support topic "How to add "Regenerate Thumbnails" plugin action to MLA interface?"
13
+ * opened on 8/27/2016 by "cjab".
14
+ * https://wordpress.org/support/topic/how-to-add-a-regenerate-thumbnails-plugin-action-to-mla-interface
15
+ *
16
+ * @package MLA Regenerate Thumbnails Example
17
+ * @version 1.00
18
+ */
19
+
20
+ /*
21
+ Plugin Name: MLA Regenerate Thumbnails Example
22
+ Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
23
+ Description: Adds "Regenerate Thumbnails" actions to rollover actions and Bulk Edit dropdown
24
+ Author: David Lingren
25
+ Version: 1.00
26
+ Author URI: http://fairtradejudaica.org/our-story/staff/
27
+
28
+ Copyright 2016 David Lingren
29
+
30
+ This program is free software; you can redistribute it and/or modify
31
+ it under the terms of the GNU General Public License as published by
32
+ the Free Software Foundation; either version 2 of the License, or
33
+ (at your option) any later version.
34
+
35
+ This program is distributed in the hope that it will be useful,
36
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
37
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38
+ GNU General Public License for more details.
39
+
40
+ You can get a copy of the GNU General Public License by writing to the
41
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
42
+ */
43
+
44
+ /**
45
+ * Class MLA Regenerate Thumbnails Example supplies random items from a collection of Att. Category terms
46
+ *
47
+ * NOTE: You must enter the name or slug values for your application's terms in the $gallery_terms array below.
48
+ *
49
+ * @package MLA Regenerate Thumbnails Example
50
+ * @since 1.00
51
+ */
52
+ class MLARegenerateThumbnailsExample {
53
+ /**
54
+ * Initialization function, similar to __construct()
55
+ *
56
+ * @since 1.00
57
+ */
58
+ public static function initialize() {
59
+ // The filters are only useful in the admin section
60
+ if ( !is_admin() )
61
+ return;
62
+
63
+ if ( class_exists( 'RegenerateThumbnails' ) ) {
64
+ add_filter( 'mla_list_table_build_rollover_actions', 'MLARegenerateThumbnailsExample::mla_list_table_build_rollover_actions', 10, 3 );
65
+ add_filter( 'mla_list_table_get_bulk_actions', 'MLARegenerateThumbnailsExample::mla_list_table_get_bulk_actions', 10, 1 );
66
+
67
+ // This action must run before any Media/Assistant output is generated
68
+ add_action( 'admin_init', 'MLARegenerateThumbnailsExample::bulk_action_handler', 9 );
69
+ }
70
+ }
71
+
72
+ /**
73
+ * Add Regenerate Thumbnails to the list of item "Rollover" actions
74
+ *
75
+ * @since 1.00
76
+ *
77
+ * @param array $actions The list of item "Rollover" actions.
78
+ * @param object $item The current Media Library item.
79
+ * @param string $column The List Table column slug.
80
+ */
81
+ public static function mla_list_table_build_rollover_actions( $actions, $item, $column ) {
82
+ global $RegenerateThumbnails;
83
+
84
+ // Add a "Regenerate Thumbnails" link to the media row actions
85
+ $actions = $RegenerateThumbnails->add_media_row_action( $actions, $item );
86
+
87
+ return $actions;
88
+ } // mla_list_table_build_rollover_actions
89
+
90
+ /**
91
+ * Add Regenerate Thumbnails to the Bulk Actions dropdown controls
92
+ *
93
+ * @since 1.00
94
+ *
95
+ * @param array $actions An array of bulk actions.
96
+ * Format: 'slug' => 'Label'
97
+ */
98
+ public static function mla_list_table_get_bulk_actions( $actions ) {
99
+ global $RegenerateThumbnails;
100
+
101
+ /*
102
+ * Add new items to the Bulk Actions using Javascript
103
+ * A last minute change to the "bulk_actions-xxxxx" filter
104
+ * in 3.1 made it not possible to add items using that
105
+ */
106
+ $RegenerateThumbnails->add_bulk_actions_via_javascript();
107
+
108
+ return $actions;
109
+ } // mla_list_table_get_bulk_actions
110
+
111
+ /**
112
+ * Process the Bulk Regenerate Thumbnails action
113
+ *
114
+ * @since 1.00
115
+ */
116
+ public static function bulk_action_handler() {
117
+ global $RegenerateThumbnails;
118
+
119
+ // Detect the action and fix up the $_REQUEST variables
120
+ if ( ( isset( $_REQUEST['action'] ) && 'bulk_regenerate_thumbnails' == $_REQUEST['action'] ) ||
121
+ ( isset( $_REQUEST['action2'] ) && 'bulk_regenerate_thumbnails' == $_REQUEST['action2'] ) ) {
122
+ $_REQUEST['media'] = $_REQUEST['cb_attachment'];
123
+ $_REQUEST['_wpnonce'] = wp_create_nonce( 'bulk-media' );
124
+
125
+ // Handles the bulk actions POST; redirects and exits
126
+ $RegenerateThumbnails->bulk_action_handler();
127
+ }
128
+ } // bulk_action_handler
129
+ } // Class MLARegenerateThumbnailsExample
130
+
131
+ /*
132
+ * Install the filters at an early opportunity
133
+ */
134
+ add_action('init', 'MLARegenerateThumbnailsExample::initialize');
135
+ ?>
examples/plugins/mla-substitution-parameter-hooks-example.php CHANGED
@@ -5,6 +5,7 @@
5
  * In this example:
6
  * - a "parent_terms:" prefix accesses taxonomy terms assigned to an item's parent post/page
7
  * - a "page_terms:" prefix accesses taxonomy terms assigned to the current post/page
 
8
  * - an "author:" prefix accesses all of the WP_User properties for an item's author
9
  * - an "conditional:" prefix returns a value when a condition is true, e.g., during the upload process
10
  *
@@ -24,16 +25,20 @@
24
  * opened on 7/19/2016 by "Levy":
25
  * https://wordpress.org/support/topic/how-to-add-a-number-to-the-title-of-images-inserted-in-same-post
26
  *
 
 
 
 
27
  * @package MLA Substitution Parameter Hooks Example
28
- * @version 1.03
29
  */
30
 
31
  /*
32
  Plugin Name: MLA Substitution Parameter Hooks Example
33
  Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
34
- Description: Adds "parent_terms:", "page_terms:", "author:" and "conditional:" Field-level Substitution Parameters
35
  Author: David Lingren
36
- Version: 1.03
37
  Author URI: http://fairtradejudaica.org/our-story/staff/
38
 
39
  Copyright 2016 David Lingren
@@ -246,16 +251,12 @@ class MLASubstitutionParameterExample {
246
  * @param string default option value
247
  */
248
  public static function mla_expand_custom_prefix( $custom_value, $key, $value, $query, $markup_values, $post_id, $keep_existing, $default_option ) {
249
- static $author_cache = array();
250
 
251
  //error_log( __LINE__ . " MLASubstitutionParameterExample::mla_expand_custom_prefix( {$key}, {$post_id}, {$keep_existing}, {$default_option} ) value = " . var_export( $value, true ), 0 );
252
  //error_log( __LINE__ . " MLASubstitutionParameterExample::mla_expand_custom_prefix( {$key}, {$post_id} ) query = " . var_export( $query, true ), 0 );
253
  //error_log( __LINE__ . " MLASubstitutionParameterExample::mla_expand_custom_prefix( {$key}, {$post_id} ) markup_values = " . var_export( $markup_values, true ), 0 );
254
 
255
- if ( 0 == absint( $post_id ) ) {
256
- return $custom_value;
257
- }
258
-
259
  // Look for field/value qualifier
260
  $match_count = preg_match( '/^(.+)\((.+)\)/', $value['value'], $matches );
261
  if ( $match_count ) {
@@ -266,6 +267,33 @@ class MLASubstitutionParameterExample {
266
  $qualifier = '';
267
  }
268
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269
  if ( 'parent_terms' == $value['prefix'] ) {
270
  if ( isset( $markup_values['parent'] ) ) {
271
  $post_parent = absint( $markup_values['parent'] );
@@ -275,36 +303,76 @@ class MLASubstitutionParameterExample {
275
  }
276
 
277
  $custom_value = self::_evaluate_terms( $custom_value, $post_parent, $field, $qualifier, $value['option'] );
278
- } elseif ( 'page_terms' == $value['prefix'] ) {
279
- if ( isset( $markup_values['page_ID'] ) ) {
280
- $post_id = absint( $markup_values['page_ID'] );
281
  } else {
282
- global $post;
 
 
 
 
 
 
283
 
284
- if ( isset( $post ) && !empty( $post->ID ) ) {
285
- $post_id = absint( $post->ID );
 
 
 
 
 
286
  } else {
287
- $post_id = 0;
288
  }
289
  }
290
 
291
- $custom_value = self::_evaluate_terms( $custom_value, $post_id, $field, $qualifier, $value['option'] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
292
  } elseif ( 'author' == $value['prefix'] ) {
293
- if ( isset( $markup_values['page_author'] ) ) {
294
- $page_author = absint( $markup_values['page_author'] );
295
  } else {
296
  $item = get_post( $post_id );
297
- $page_author = absint( $item->post_author );
298
  }
299
 
300
- // $page_author = $markup_values['page_author'];
301
- if ( isset( $author_cache[ $page_author ] ) ) {
302
- $author = $author_cache[ $page_author ];
303
  } else {
304
- $author = new WP_User( $page_author );
305
  //error_log( __LINE__ . " MLASubstitutionParameterExample::mla_expand_custom_prefix( {$key}, {$post_id} ) author = " . var_export( $author, true ), 0 );
306
- if ( $author instanceof WP_User && $author->ID == $page_author ) {
307
- $author_cache[ $page_author ] = $author;
308
  } else {
309
  return $custom_value;
310
  }
5
  * In this example:
6
  * - a "parent_terms:" prefix accesses taxonomy terms assigned to an item's parent post/page
7
  * - a "page_terms:" prefix accesses taxonomy terms assigned to the current post/page
8
+ * - a "parent:" prefix accesses all of the WP_Post properties and the permalink for an item's parent
9
  * - an "author:" prefix accesses all of the WP_User properties for an item's author
10
  * - an "conditional:" prefix returns a value when a condition is true, e.g., during the upload process
11
  *
25
  * opened on 7/19/2016 by "Levy":
26
  * https://wordpress.org/support/topic/how-to-add-a-number-to-the-title-of-images-inserted-in-same-post
27
  *
28
+ * Enhanced for support topic "What are the default values for the markup template?"
29
+ * opened on 9/21/2016 by "cconstantine":
30
+ * https://wordpress.org/support/topic/what-are-the-default-values-for-the-markup-template/
31
+ *
32
  * @package MLA Substitution Parameter Hooks Example
33
+ * @version 1.05
34
  */
35
 
36
  /*
37
  Plugin Name: MLA Substitution Parameter Hooks Example
38
  Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
39
+ Description: Adds "parent_terms:", "page_terms:", "parent:", "author:" and "conditional:" Field-level Substitution Parameters
40
  Author: David Lingren
41
+ Version: 1.05
42
  Author URI: http://fairtradejudaica.org/our-story/staff/
43
 
44
  Copyright 2016 David Lingren
251
  * @param string default option value
252
  */
253
  public static function mla_expand_custom_prefix( $custom_value, $key, $value, $query, $markup_values, $post_id, $keep_existing, $default_option ) {
254
+ static $parent_cache = array(), $author_cache = array();
255
 
256
  //error_log( __LINE__ . " MLASubstitutionParameterExample::mla_expand_custom_prefix( {$key}, {$post_id}, {$keep_existing}, {$default_option} ) value = " . var_export( $value, true ), 0 );
257
  //error_log( __LINE__ . " MLASubstitutionParameterExample::mla_expand_custom_prefix( {$key}, {$post_id} ) query = " . var_export( $query, true ), 0 );
258
  //error_log( __LINE__ . " MLASubstitutionParameterExample::mla_expand_custom_prefix( {$key}, {$post_id} ) markup_values = " . var_export( $markup_values, true ), 0 );
259
 
 
 
 
 
260
  // Look for field/value qualifier
261
  $match_count = preg_match( '/^(.+)\((.+)\)/', $value['value'], $matches );
262
  if ( $match_count ) {
267
  $qualifier = '';
268
  }
269
 
270
+ if ( 'page_terms' == $value['prefix'] ) {
271
+ if ( isset( $markup_values['page_ID'] ) ) {
272
+ $post_id = absint( $markup_values['page_ID'] );
273
+ } else {
274
+ global $post;
275
+
276
+ if ( isset( $post ) && !empty( $post->ID ) ) {
277
+ $post_id = absint( $post->ID );
278
+ } else {
279
+ $post_id = 0;
280
+ }
281
+ }
282
+
283
+ $custom_value = self::_evaluate_terms( $custom_value, $post_id, $field, $qualifier, $value['option'] );
284
+ } elseif ( 'page' == $value['prefix'] ) {
285
+ if ( 'featured' == $value['value'] ) {
286
+ $featured = absint( get_post_thumbnail_id( absint( $markup_values['page_ID'] ) ) );
287
+ if ( 0 < $featured ) {
288
+ $custom_value = (string) $featured;
289
+ }
290
+ }
291
+ }
292
+
293
+ if ( 0 == absint( $post_id ) ) {
294
+ return $custom_value;
295
+ }
296
+
297
  if ( 'parent_terms' == $value['prefix'] ) {
298
  if ( isset( $markup_values['parent'] ) ) {
299
  $post_parent = absint( $markup_values['parent'] );
303
  }
304
 
305
  $custom_value = self::_evaluate_terms( $custom_value, $post_parent, $field, $qualifier, $value['option'] );
306
+ } elseif ( 'parent' == $value['prefix'] ) {
307
+ if ( isset( $markup_values['parent'] ) ) {
308
+ $parent_id = absint( $markup_values['parent'] );
309
  } else {
310
+ $item = get_post( $post_id );
311
+ $parent_id = absint( $item->post_parent );
312
+ }
313
+
314
+ if ( 0 == $parent_id ) {
315
+ return $custom_value;
316
+ }
317
 
318
+ if ( isset( $parent_cache[ $parent_id ] ) ) {
319
+ $parent = $parent_cache[ $parent_id ];
320
+ } else {
321
+ $parent = get_post( $parent_id );
322
+ //error_log( __LINE__ . " MLASubstitutionParameterExample::mla_expand_custom_prefix( {$key}, {$post_id} ) parent = " . var_export( $parent, true ), 0 );
323
+ if ( $parent instanceof WP_Post && $parent->ID == $parent_id ) {
324
+ $parent_cache[ $parent_id ] = $parent;
325
  } else {
326
+ return $custom_value;
327
  }
328
  }
329
 
330
+ if ( property_exists( $parent, $value['value'] ) ) {
331
+ $custom_value = $parent->$value['value'];
332
+ } elseif ( 'permalink' == $value['value'] ) {
333
+ $custom_value = get_permalink( $parent );
334
+ }
335
+
336
+ //error_log( __LINE__ . " MLASubstitutionParameterExample::mla_expand_custom_prefix( {$key}, {$post_id}, {$parent_id} ) custom_value = " . var_export( $custom_value, true ), 0 );
337
+
338
+ if ( is_array( $custom_value ) ) {
339
+ if ( 'single' == $value['option'] || 1 == count( $custom_value ) ) {
340
+ $custom_value = sanitize_text_field( reset( $custom_value ) );
341
+ } elseif ( ( 'export' == $value['option'] ) || ( 'unpack' == $value['option'] ) ) {
342
+ $custom_value = sanitize_text_field( var_export( $custom_value, true ) );
343
+ } else {
344
+ if ( 'array' == $value['option'] ) {
345
+ $new_value = array();
346
+ } else {
347
+ $custom_value = '';
348
+ }
349
+
350
+ foreach ( $custom_value as $element ) {
351
+ $field_value = sanitize_text_field( $element );
352
+
353
+ if ( 'array' == $value['option'] ) {
354
+ $custom_value[] = $field_value;
355
+ } else {
356
+ $custom_value .= strlen( $custom_value ) ? ', ' . $field_value : $field_value;
357
+ }
358
+ }
359
+ }
360
+ }
361
  } elseif ( 'author' == $value['prefix'] ) {
362
+ if ( isset( $markup_values['author_id'] ) ) {
363
+ $item_author = absint( $markup_values['author_id'] );
364
  } else {
365
  $item = get_post( $post_id );
366
+ $item_author = absint( $item->post_author );
367
  }
368
 
369
+ if ( isset( $author_cache[ $item_author ] ) ) {
370
+ $author = $author_cache[ $item_author ];
 
371
  } else {
372
+ $author = new WP_User( $item_author );
373
  //error_log( __LINE__ . " MLASubstitutionParameterExample::mla_expand_custom_prefix( {$key}, {$post_id} ) author = " . var_export( $author, true ), 0 );
374
+ if ( $author instanceof WP_User && $author->ID == $item_author ) {
375
+ $author_cache[ $item_author ] = $author;
376
  } else {
377
  return $custom_value;
378
  }
examples/plugins/mla-tax-query-example.php CHANGED
@@ -14,8 +14,20 @@
14
  * A custom shortcode parameter, "my_custom_sql", activates the logic in this plugin. See the
15
  * "mla_gallery_query_arguments" function for documentation on the parameter.
16
  *
 
 
 
 
 
 
 
 
 
 
 
 
17
  * @package MLA tax query Example
18
- * @version 1.03
19
  */
20
 
21
  /*
@@ -23,7 +35,7 @@ Plugin Name: MLA tax query Example
23
  Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
24
  Description: Replaces the WP_Query tax_query with a more efficient, direct SQL query
25
  Author: David Lingren
26
- Version: 1.03
27
  Author URI: http://fairtradejudaica.org/our-story/staff/
28
 
29
  Copyright 2013 - 2016 David Lingren
@@ -335,7 +347,7 @@ class MLATaxQueryExample {
335
  $ttids = array();
336
 
337
  // Find taxonomy argument, if present, and collect terms
338
- $taxonomies = get_taxonomies( array( 'object_type' => array( 'attachment' ) ), 'names' );
339
  foreach( $taxonomies as $taxonomy ) {
340
  if ( empty( $my_query_vars[ $taxonomy ] ) ) {
341
  continue;
@@ -517,7 +529,7 @@ class MLATaxQueryExample {
517
  $ttids = array();
518
 
519
  // Find taxonomy argument, if present, and collect terms
520
- $taxonomies = get_taxonomies( array( 'object_type' => array( 'attachment' ) ), 'names' );
521
  foreach( $taxonomies as $taxonomy ) {
522
  if ( empty( $my_query_vars[ $taxonomy ] ) ) {
523
  continue;
14
  * A custom shortcode parameter, "my_custom_sql", activates the logic in this plugin. See the
15
  * "mla_gallery_query_arguments" function for documentation on the parameter.
16
  *
17
+ * Created for support topic "Slow queries"
18
+ * opened on 7/4/2014 by "aptharsia".
19
+ * https://wordpress.org/support/topic/slow-queries-1
20
+ *
21
+ * Enhanced for support topic "REALLY Slow Queries........ Help! :)"
22
+ * opened on 8/16/2014 by "alexapaige".
23
+ * https://wordpress.org/support/topic/really-slow-queries-help
24
+ *
25
+ * Enhanced for support topic "MLATaxQuery with keyword search and pagination"
26
+ * opened on 10/15/2015 by "CabinetWorks".
27
+ * https://wordpress.org/support/topic/mlataxquery-with-keyword-search-and-pagination
28
+ *
29
  * @package MLA tax query Example
30
+ * @version 1.04
31
  */
32
 
33
  /*
35
  Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
36
  Description: Replaces the WP_Query tax_query with a more efficient, direct SQL query
37
  Author: David Lingren
38
+ Version: 1.04
39
  Author URI: http://fairtradejudaica.org/our-story/staff/
40
 
41
  Copyright 2013 - 2016 David Lingren
347
  $ttids = array();
348
 
349
  // Find taxonomy argument, if present, and collect terms
350
+ $taxonomies = get_object_taxonomies( 'attachment', 'names' );
351
  foreach( $taxonomies as $taxonomy ) {
352
  if ( empty( $my_query_vars[ $taxonomy ] ) ) {
353
  continue;
529
  $ttids = array();
530
 
531
  // Find taxonomy argument, if present, and collect terms
532
+ $taxonomies = get_object_taxonomies( 'attachment', 'names' );
533
  foreach( $taxonomies as $taxonomy ) {
534
  if ( empty( $my_query_vars[ $taxonomy ] ) ) {
535
  continue;
examples/plugins/mla-ui-elements-example.php CHANGED
@@ -1,30 +1,9 @@
1
  <?php
2
- /*
3
- Plugin Name: MLA UI Elements Example
4
- Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
5
- Description: Provides shortcodes to improve user experience for [mla_term_list], [mla_tag_cloud] and [mla_gallery] shortcodes
6
- Author: David Lingren
7
- Version: 1.02
8
- Author URI: http://fairtradejudaica.org/our-story/staff/
9
-
10
- Copyright 2016 David Lingren
11
-
12
- This program is free software; you can redistribute it and/or modify
13
- it under the terms of the GNU General Public License as published by
14
- the Free Software Foundation; either version 2 of the License, or
15
- (at your option) any later version.
16
-
17
- This program is distributed in the hope that it will be useful,
18
- but WITHOUT ANY WARRANTY; without even the implied warranty of
19
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
- GNU General Public License for more details.
21
-
22
- You can get a copy of the GNU General Public License by writing to the
23
- Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
24
- */
25
-
26
- /*
27
- * User notes
28
  *
29
  * 1. If you add "use_filters=true" to an [mla_term_list] shortcode this plugin will retain the selected
30
  * terms when the page is refreshed and pass them back into the shortcode.
@@ -37,12 +16,15 @@ Copyright 2016 David Lingren
37
  * actions in 2. and will also match the taxonomy_slug to a simple taxonomy query (if present) and
38
  * add that query to the taxonomy queries. If the simple query is 'muie-no-terms', it will be ignored.
39
  *
40
- * 4. Three shortcodes are provided to generate text box controls and retain their settings when the page
41
  * is refreshed or pagination moves to a new page:
42
  *
43
- * [muie_per_page] generates an items per page text box
44
  * [muie_terms_search] generates a terms search text box
45
  * [muie_keyword_search] generates a keyword search text box
 
 
 
 
46
  *
47
  * 5. With a bit of work you can add a tag cloud that works with these filters. Here's an example you can
48
  * adapt for your application:
@@ -54,13 +36,11 @@ Copyright 2016 David Lingren
54
  * </style>
55
  * <span id=mla-tag-cloud>
56
  * <strong>Tag Cloud</strong>
57
- * [mla_tag_cloud taxonomy=attachment_tag number=20 current_item="{+request:current_item+}" mla_link_href="{+page_url+}?current_item={+term_id+}&tax_input{{+query:taxonomy+}}{}={+slug+}&muie_per_page={+template:({+request:muie_per_page+}|5)+}" mla_link_class="{+current_item_class+}"]
58
  * </span>
59
- */
60
-
61
- /**
62
- * Class MLA UI Elements Example provides shortcodes to improve user experience for
63
- * [mla_term_list], [mla_tag_cloud] and [mla_gallery] shortcodes
64
  *
65
  * Created for support topic "How do I provide a front-end search of my media items using Custom Fields?"
66
  * opened on 4/15/2016 by "direys".
@@ -70,10 +50,50 @@ Copyright 2016 David Lingren
70
  * opened on 5/28/2016 by "ghislainsc".
71
  * https://wordpress.org/support/topic/dynamic-search-and-filters
72
  *
73
- * Enhanced for support topic "Limiting search results to attachment tags/'Justifying' gallery grids""
 
 
 
 
74
  * opened on 7/2/2016 by "ceophoetography".
75
  * https://wordpress.org/support/topic/limiting-search-results-to-attachment-tagsjustifying-gallery-grids
76
  *
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  * @package MLA UI Elements Example
78
  * @since 1.00
79
  */
@@ -91,31 +111,52 @@ class MLAUIElementsExample {
91
  add_filter( 'mla_term_list_attributes', 'MLAUIElementsExample::mla_term_list_attributes', 10, 1 );
92
  add_filter( 'mla_gallery_attributes', 'MLAUIElementsExample::mla_gallery_attributes', 10, 1 );
93
 
94
- // Add the custom shortcode for generating the items per page
95
- add_shortcode( 'muie_per_page', 'MLAUIElementsExample::muie_per_page' );
96
-
97
  // Add the custom shortcode for generating "sticky" term search text box
98
  add_shortcode( 'muie_terms_search', 'MLAUIElementsExample::muie_terms_search' );
99
 
100
  // Add the custom shortcode for generating "sticky" keyword search text box
101
  add_shortcode( 'muie_keyword_search', 'MLAUIElementsExample::muie_keyword_search' );
102
 
 
 
 
 
 
 
 
 
 
103
  // Add the custom shortcode for generating assigned terms counts
104
  add_shortcode( 'muie_assigned_items_count', 'MLAUIElementsExample::muie_assigned_items_count' );
105
  }
106
 
107
  /**
108
- * Look for 'muie_filters' that pass the selected parameters from page to page of a paginated gallery
109
  *
110
- * The $shortcode_attributes array is where you will find any of your own parameters that are coded in the
111
- * shortcode, e.g., [mla_term_list use_filters=true].
 
 
 
 
 
 
112
  *
113
  * @since 1.00
114
  *
115
  * @param array the shortcode parameters passed in to the shortcode
116
  */
117
  public static function mla_term_list_attributes( $shortcode_attributes ) {
 
118
 
 
 
 
 
 
 
 
 
119
  // See if this is a "filtered" term list
120
  if ( !empty( $shortcode_attributes['use_filters'] ) && ( 'true' == strtolower( $shortcode_attributes['use_filters'] ) ) ) {
121
  // Pagination links, e.g. Previous or Next, have muie_filters that encode the form parameters
@@ -125,6 +166,15 @@ class MLAUIElementsExample {
125
  if ( !empty( $filters['tax_input'] ) ) {
126
  $_REQUEST['tax_input'] = $filters['tax_input'];
127
  }
 
 
 
 
 
 
 
 
 
128
  }
129
 
130
  // If nothing is set for this taxonomy we're done
@@ -133,35 +183,54 @@ class MLAUIElementsExample {
133
  }
134
 
135
  $terms = $_REQUEST['tax_input'][ $shortcode_attributes['taxonomy'] ];
 
136
 
137
  // Check for a dropdown control with "All Terms" selected
138
- $option_all = array_search( '0', $terms );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  if ( false !== $option_all ) {
140
  unset( $terms[ $option_all ] );
141
  }
142
 
143
  // Pass selected terms to the shortcode
144
  if ( !empty( $terms ) ) {
145
- $shortcode_attributes[ $shortcode_attributes['mla_item_parameter'] ] = implode( ',', $_REQUEST['tax_input'][ $shortcode_attributes['taxonomy'] ] );
 
 
 
 
146
  }
147
 
148
  unset( $shortcode_attributes['use_filters'] );
149
  }
150
 
 
151
  return $shortcode_attributes;
152
  } // mla_term_list_attributes
153
 
154
  /**
155
  * Add the taxonomy query to the shortcode, limit posts_per_page and encode filters for pagination links
156
  *
157
- * The $shortcode_attributes array is where you will find any of your own parameters that are coded in the
158
- * shortcode, e.g., [mla_gallery random_category="abc"].
159
- *
160
  * @since 1.00
161
  *
162
  * @param array the shortcode parameters passed in to the shortcode
163
  */
164
  public static function mla_gallery_attributes( $shortcode_attributes ) {
 
165
  /*
166
  * Only process shortcodes that allow filters
167
  */
@@ -173,16 +242,8 @@ class MLAUIElementsExample {
173
  if ( !empty( $_REQUEST['muie_filters'] ) ) {
174
  $filters = json_decode( trim( stripslashes( $_REQUEST['muie_filters'] ), '"' ), true );
175
 
176
- if ( isset( $filters['muie_terms_search'] ) ) {
177
- $_REQUEST['muie_terms_search'] = $filters['muie_terms_search'];
178
- }
179
-
180
- if ( isset( $filters['muie_keyword_search'] ) ) {
181
- $_REQUEST['muie_keyword_search'] = $filters['muie_keyword_search'];
182
- }
183
-
184
- if ( isset( $filters['tax_input'] ) ) {
185
- $_REQUEST['tax_input'] = $filters['tax_input'];
186
  }
187
  }
188
 
@@ -196,33 +257,54 @@ class MLAUIElementsExample {
196
  $shortcode_attributes['posts_per_page'] = $_REQUEST['muie_per_page'];
197
  }
198
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
  // Add the terms search parameters, if present
200
  if ( !empty( $_REQUEST['muie_terms_search'] ) && is_array( $_REQUEST['muie_terms_search'] ) && !empty( $_REQUEST['muie_terms_search']['mla_terms_phrases'] ) ) {
201
- $muie_terms_search = $_REQUEST['muie_terms_search'];
202
- foreach( $muie_terms_search as $key => $value ) {
203
  if ( !empty( $value ) ) {
204
  $shortcode_attributes[ $key ] = $value;
205
  }
206
  }
207
- } else {
208
- $muie_terms_search = array();
209
  }
210
 
211
  // Add the keyword search parameters, if present
212
  if ( !empty( $_REQUEST['muie_keyword_search'] ) && is_array( $_REQUEST['muie_keyword_search'] ) && !empty( $_REQUEST['muie_keyword_search']['s'] ) ) {
213
- $muie_keyword_search = $_REQUEST['muie_keyword_search'];
214
- foreach( $muie_keyword_search as $key => $value ) {
215
  if ( !empty( $value ) ) {
216
  $shortcode_attributes[ $key ] = $value;
217
  }
218
  }
219
- } else {
220
- $muie_keyword_search = array();
221
  }
222
 
223
  // Add the taxonomy filter(s), if present
224
  $filter_taxonomy = $shortcode_attributes['add_filters_to'];
225
- $tax_input = !empty( $_REQUEST['tax_input'] ) ? $_REQUEST['tax_input'] : array();
 
 
 
 
 
 
 
 
 
226
 
227
  if ( ! ( empty( $shortcode_attributes[ $filter_taxonomy ] ) && empty( $tax_input ) ) ) {
228
  $tax_query = '';
@@ -230,13 +312,44 @@ class MLAUIElementsExample {
230
  // Look for the optional "simple taxonomy query" as an initial filter
231
  if ( !empty( $shortcode_attributes[ $filter_taxonomy ] ) ) {
232
  if ( 'muie-no-terms' !== $shortcode_attributes[ $filter_taxonomy ] ) {
233
- $values = "array( '" . implode( "', '", explode( ',', $shortcode_attributes[ $filter_taxonomy ] ) ) . "' )";
234
- $tax_query .= "array('taxonomy' => '{$filter_taxonomy}' ,'field' => 'slug','terms' => {$values}, 'operator' => 'IN'), ";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
  }
236
 
237
  unset( $shortcode_attributes[ $filter_taxonomy ] );
238
  }
239
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
240
  foreach ( $tax_input as $taxonomy => $terms ) {
241
  // simple taxonomy query overrides tax_input
242
  if ( $taxonomy == $filter_taxonomy ) {
@@ -244,7 +357,12 @@ class MLAUIElementsExample {
244
  }
245
 
246
  // Check for a dropdown control with "All Terms" selected
247
- $option_all = array_search( '0', $terms );
 
 
 
 
 
248
  if ( false !== $option_all ) {
249
  unset( $terms[ $option_all ] );
250
  }
@@ -264,12 +382,12 @@ class MLAUIElementsExample {
264
  $values = "array( '" . implode( "','", $terms ) . "' )";
265
  }
266
 
267
- $tax_query .= "array('taxonomy' => '{$taxonomy}' ,'field' => '{$field}','terms' => {$values}, 'operator' => 'IN'), ";
268
  }
269
  }
270
 
271
  if ( ! empty( $tax_query ) ) {
272
- $shortcode_attributes['tax_query'] = "array( 'relation' => 'AND', " . $tax_query . ')';
273
  }
274
  }
275
 
@@ -278,7 +396,7 @@ class MLAUIElementsExample {
278
  */
279
  if ( !empty( $shortcode_attributes['mla_output'] ) ) {
280
 
281
- $filters = urlencode( json_encode( array( 'tax_input' => $tax_input, 'muie_terms_search' => $muie_terms_search, 'muie_keyword_search' => $muie_keyword_search ) ) );
282
  $shortcode_attributes['mla_link_href'] = '[+new_url+]?[+new_page_text+]&muie_filters=' . $filters;
283
 
284
  if ( !empty( $shortcode_attributes['posts_per_page'] ) ) {
@@ -290,32 +408,6 @@ class MLAUIElementsExample {
290
  return $shortcode_attributes;
291
  } // mla_gallery_attributes
292
 
293
- /**
294
- * Items per page shortcode
295
- *
296
- * This shortcode generates an HTML text box with a default muie_per_page value.
297
- *
298
- * @since 1.00
299
- *
300
- * @param array the shortcode parameters
301
- *
302
- * @return string HTML markup for the generated form
303
- */
304
- public static function muie_per_page( $attr ) {
305
- if ( isset( $attr['numberposts'] ) && ! isset( $attr['posts_per_page'] )) {
306
- $attr['posts_per_page'] = $attr['numberposts'];
307
- unset( $attr['numberposts'] );
308
- }
309
-
310
- if ( !empty( $_REQUEST['muie_per_page'] ) ) {
311
- $posts_per_page = $_REQUEST['muie_per_page'];
312
- } else {
313
- $posts_per_page = isset( $attr['posts_per_page'] ) ? $attr['posts_per_page'] : 6;
314
- }
315
-
316
- return '<input name="muie_per_page" id="muie-per-page" type="text" size="2" value="' . $posts_per_page . '" />';
317
- } // muie_per_page
318
-
319
  /**
320
  * Terms search generator shortcode
321
  *
@@ -458,6 +550,268 @@ class MLAUIElementsExample {
458
  return $return_value;
459
  } // muie_keyword_search
460
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
461
  /**
462
  * Assigned items count shortcode
463
  *
1
  <?php
2
+ /**
3
+ * Provides shortcodes to improve user experience for [mla_term_list],
4
+ * [mla_tag_cloud] and [mla_gallery] shortcodes
5
+ *
6
+ * In this example:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  *
8
  * 1. If you add "use_filters=true" to an [mla_term_list] shortcode this plugin will retain the selected
9
  * terms when the page is refreshed and pass them back into the shortcode.
16
  * actions in 2. and will also match the taxonomy_slug to a simple taxonomy query (if present) and
17
  * add that query to the taxonomy queries. If the simple query is 'muie-no-terms', it will be ignored.
18
  *
19
+ * 4. Shortcodes are provided to generate text box controls and retain their settings when the page
20
  * is refreshed or pagination moves to a new page:
21
  *
 
22
  * [muie_terms_search] generates a terms search text box
23
  * [muie_keyword_search] generates a keyword search text box
24
+ * [muie_orderby] generates an order by dropdown control
25
+ * [muie_order] generates ascending/descending radio buttons
26
+ * [muie_per_page] generates an items per page text box
27
+ * [muie_assigned_items_count] returns the number of items assigned to any term(s) in the selected taxonomy
28
  *
29
  * 5. With a bit of work you can add a tag cloud that works with these filters. Here's an example you can
30
  * adapt for your application:
36
  * </style>
37
  * <span id=mla-tag-cloud>
38
  * <strong>Tag Cloud</strong>
39
+ * [mla_tag_cloud taxonomy=attachment_tag number=20 current_item="{+request:current_item+}" mla_link_href="{+currentlink_url+}&tax_input{{+query:taxonomy+}}{}={+slug+}&muie_per_page={+template:({+request:muie_per_page+}|5)+}" mla_link_class="{+current_item_class+}"]
40
  * </span>
41
+ *
42
+ * This example plugin uses four of the many filters available in the [mla_gallery] shortcode
43
+ * and illustrates some of the techniques you can use to customize the gallery display.
 
 
44
  *
45
  * Created for support topic "How do I provide a front-end search of my media items using Custom Fields?"
46
  * opened on 4/15/2016 by "direys".
50
  * opened on 5/28/2016 by "ghislainsc".
51
  * https://wordpress.org/support/topic/dynamic-search-and-filters
52
  *
53
+ * Enhanced for support topic "Very new to this, need help"
54
+ * opened on 6/15/2016 by "abronk".
55
+ * https://wordpress.org/support/topic/very-new-to-this-need-help/
56
+ *
57
+ * Enhanced for support topic "Limiting search results to attachment tags/'Justifying' gallery grids"
58
  * opened on 7/2/2016 by "ceophoetography".
59
  * https://wordpress.org/support/topic/limiting-search-results-to-attachment-tagsjustifying-gallery-grids
60
  *
61
+ * Enhanced for support topic "Shortcode"
62
+ * opened on 10/18/2016 by "trinitaa".
63
+ * https://wordpress.org/support/topic/shortcode-456/
64
+ *
65
+ * @package MLA UI Elements Example
66
+ * @version 1.05
67
+ */
68
+
69
+ /*
70
+ Plugin Name: MLA UI Elements Example
71
+ Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
72
+ Description: Provides shortcodes to improve user experience for [mla_term_list], [mla_tag_cloud] and [mla_gallery] shortcodes
73
+ Author: David Lingren
74
+ Version: 1.05
75
+ Author URI: http://fairtradejudaica.org/our-story/staff/
76
+
77
+ Copyright 2016 David Lingren
78
+
79
+ This program is free software; you can redistribute it and/or modify
80
+ it under the terms of the GNU General Public License as published by
81
+ the Free Software Foundation; either version 2 of the License, or
82
+ (at your option) any later version.
83
+
84
+ This program is distributed in the hope that it will be useful,
85
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
86
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
87
+ GNU General Public License for more details.
88
+
89
+ You can get a copy of the GNU General Public License by writing to the
90
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
91
+ */
92
+
93
+ /**
94
+ * Class MLA UI Elements Example provides shortcodes to improve user experience for
95
+ * [mla_term_list], [mla_tag_cloud] and [mla_gallery] shortcodes
96
+ *
97
  * @package MLA UI Elements Example
98
  * @since 1.00
99
  */
111
  add_filter( 'mla_term_list_attributes', 'MLAUIElementsExample::mla_term_list_attributes', 10, 1 );
112
  add_filter( 'mla_gallery_attributes', 'MLAUIElementsExample::mla_gallery_attributes', 10, 1 );
113
 
 
 
 
114
  // Add the custom shortcode for generating "sticky" term search text box
115
  add_shortcode( 'muie_terms_search', 'MLAUIElementsExample::muie_terms_search' );
116
 
117
  // Add the custom shortcode for generating "sticky" keyword search text box
118
  add_shortcode( 'muie_keyword_search', 'MLAUIElementsExample::muie_keyword_search' );
119
 
120
+ // Add the custom shortcode for generating the items per page text box
121
+ add_shortcode( 'muie_per_page', 'MLAUIElementsExample::muie_per_page' );
122
+
123
+ // Add the custom shortcode for generating the order by dropdown control
124
+ add_shortcode( 'muie_orderby', 'MLAUIElementsExample::muie_orderby' );
125
+
126
+ // Add the custom shortcode for generating the order radio buttons
127
+ add_shortcode( 'muie_order', 'MLAUIElementsExample::muie_order' );
128
+
129
  // Add the custom shortcode for generating assigned terms counts
130
  add_shortcode( 'muie_assigned_items_count', 'MLAUIElementsExample::muie_assigned_items_count' );
131
  }
132
 
133
  /**
134
+ * Pass term_list_name parameters from [mla_term_list] to [mla_gallery] for muie_filters
135
  *
136
+ * @since 1.05
137
+ *
138
+ * @var array
139
+ */
140
+ private static $term_list_names = array();
141
+
142
+ /**
143
+ * Look for 'muie_filters' that pass the selected parameters from page to page of a paginated gallery
144
  *
145
  * @since 1.00
146
  *
147
  * @param array the shortcode parameters passed in to the shortcode
148
  */
149
  public static function mla_term_list_attributes( $shortcode_attributes ) {
150
+ //error_log( __LINE__ . ' MLAUIElementsExample::mla_term_list_attributes $shortcode_attributes = ' . var_export( $shortcode_attributes, true ), 0 );
151
 
152
+ // Multiple dropdowns for the same taxonomy?
153
+ if ( !empty( $shortcode_attributes['mla_markup'] ) && 'term-list-named' === $shortcode_attributes['mla_markup'] ) {
154
+ $term_list_name = $shortcode_attributes['term_list_name'];
155
+ } else {
156
+ $term_list_name = false;
157
+ }
158
+ //error_log( __LINE__ . ' MLAUIElementsExample::mla_term_list_attributes $term_list_name = ' . var_export( $term_list_name, true ), 0 );
159
+
160
  // See if this is a "filtered" term list
161
  if ( !empty( $shortcode_attributes['use_filters'] ) && ( 'true' == strtolower( $shortcode_attributes['use_filters'] ) ) ) {
162
  // Pagination links, e.g. Previous or Next, have muie_filters that encode the form parameters
166
  if ( !empty( $filters['tax_input'] ) ) {
167
  $_REQUEST['tax_input'] = $filters['tax_input'];
168
  }
169
+
170
+ if ( $term_list_name && !empty( $filters[ $term_list_name ] ) ) {
171
+ $_REQUEST[ $term_list_name ] = $filters[ $term_list_name ];
172
+ }
173
+ }
174
+
175
+ if ( $term_list_name && !empty( $_REQUEST[ $term_list_name ] ) ) {
176
+ $_REQUEST['tax_input'][ $shortcode_attributes['taxonomy'] ][] = $_REQUEST[ $term_list_name ];
177
+ self::$term_list_names[ $term_list_name ] = $_REQUEST[ $term_list_name ];
178
  }
179
 
180
  // If nothing is set for this taxonomy we're done
183
  }
184
 
185
  $terms = $_REQUEST['tax_input'][ $shortcode_attributes['taxonomy'] ];
186
+ //error_log( __LINE__ . ' MLAUIElementsExample::mla_term_list_attributes $terms = ' . var_export( $terms, true ), 0 );
187
 
188
  // Check for a dropdown control with "All Terms" selected
189
+ if ( empty( $shortcode_attributes['option_all_value'] ) ) {
190
+ $option_all = array_search( '0', $terms );
191
+ } else {
192
+ $option_all = array_search( $shortcode_attributes['option_all_value'], $terms );
193
+ }
194
+
195
+ if ( false !== $option_all ) {
196
+ unset( $terms[ $option_all ] );
197
+ }
198
+
199
+ if ( empty( $shortcode_attributes['option_all_text'] ) ) {
200
+ $option_all = array_search( '', $terms );
201
+ } else {
202
+ $option_all = array_search( sanitize_title( $shortcode_attributes['option_all_text'] ), $terms );
203
+ }
204
+
205
  if ( false !== $option_all ) {
206
  unset( $terms[ $option_all ] );
207
  }
208
 
209
  // Pass selected terms to the shortcode
210
  if ( !empty( $terms ) ) {
211
+ if ( $term_list_name && !empty( $_REQUEST[ $term_list_name ] ) ) {
212
+ $shortcode_attributes[ $shortcode_attributes['mla_item_parameter'] ] = $_REQUEST[ $term_list_name ];
213
+ } else {
214
+ $shortcode_attributes[ $shortcode_attributes['mla_item_parameter'] ] = implode( ',', $_REQUEST['tax_input'][ $shortcode_attributes['taxonomy'] ] );
215
+ }
216
  }
217
 
218
  unset( $shortcode_attributes['use_filters'] );
219
  }
220
 
221
+ //error_log( __LINE__ . ' MLAUIElementsExample::mla_term_list_attributes $shortcode_attributes = ' . var_export( $shortcode_attributes, true ), 0 );
222
  return $shortcode_attributes;
223
  } // mla_term_list_attributes
224
 
225
  /**
226
  * Add the taxonomy query to the shortcode, limit posts_per_page and encode filters for pagination links
227
  *
 
 
 
228
  * @since 1.00
229
  *
230
  * @param array the shortcode parameters passed in to the shortcode
231
  */
232
  public static function mla_gallery_attributes( $shortcode_attributes ) {
233
+ //error_log( __LINE__ . ' MLAUIElementsExample::mla_gallery_attributes $shortcode_attributes = ' . var_export( $shortcode_attributes, true ), 0 );
234
  /*
235
  * Only process shortcodes that allow filters
236
  */
242
  if ( !empty( $_REQUEST['muie_filters'] ) ) {
243
  $filters = json_decode( trim( stripslashes( $_REQUEST['muie_filters'] ), '"' ), true );
244
 
245
+ foreach( $filters as $filter_key => $filter_value ) {
246
+ $_REQUEST[ $filter_key ] = $filter_value;
 
 
 
 
 
 
 
 
247
  }
248
  }
249
 
257
  $shortcode_attributes['posts_per_page'] = $_REQUEST['muie_per_page'];
258
  }
259
 
260
+ // Fill these in from $_REQUEST parameters
261
+ $muie_filters = array();
262
+
263
+ // Add the orderby & order parameters
264
+ if ( !empty( $_REQUEST['muie_orderby'] ) ) {
265
+ $muie_filters['muie_orderby'] = $shortcode_attributes['orderby'] = $_REQUEST['muie_orderby'];
266
+ }
267
+
268
+ if ( !empty( $_REQUEST['muie_meta_key'] ) ) {
269
+ $muie_filters['muie_meta_key'] = $shortcode_attributes['meta_key'] = $_REQUEST['muie_meta_key'];
270
+ }
271
+
272
+ if ( !empty( $_REQUEST['muie_order'] ) ) {
273
+ $muie_filters['muie_order'] = $shortcode_attributes['order'] = $_REQUEST['muie_order'];
274
+ }
275
+
276
  // Add the terms search parameters, if present
277
  if ( !empty( $_REQUEST['muie_terms_search'] ) && is_array( $_REQUEST['muie_terms_search'] ) && !empty( $_REQUEST['muie_terms_search']['mla_terms_phrases'] ) ) {
278
+ $muie_filters['muie_terms_search'] = $_REQUEST['muie_terms_search'];
279
+ foreach( $muie_filters['muie_terms_search'] as $key => $value ) {
280
  if ( !empty( $value ) ) {
281
  $shortcode_attributes[ $key ] = $value;
282
  }
283
  }
 
 
284
  }
285
 
286
  // Add the keyword search parameters, if present
287
  if ( !empty( $_REQUEST['muie_keyword_search'] ) && is_array( $_REQUEST['muie_keyword_search'] ) && !empty( $_REQUEST['muie_keyword_search']['s'] ) ) {
288
+ $muie_filters['muie_keyword_search'] = $_REQUEST['muie_keyword_search'];
289
+ foreach( $muie_filters['muie_keyword_search'] as $key => $value ) {
290
  if ( !empty( $value ) ) {
291
  $shortcode_attributes[ $key ] = $value;
292
  }
293
  }
 
 
294
  }
295
 
296
  // Add the taxonomy filter(s), if present
297
  $filter_taxonomy = $shortcode_attributes['add_filters_to'];
298
+ if ( !empty( $_REQUEST['tax_input'] ) ) {
299
+ $muie_filters['tax_input'] = $tax_input = $_REQUEST['tax_input'];
300
+ } else {
301
+ $tax_input = array();
302
+ }
303
+
304
+ // Add the [mla_term_list term_list_name=] parameter(s)
305
+ if ( !empty( self::$term_list_names ) ) {
306
+ $muie_filters = array_merge( $muie_filters, self::$term_list_names );
307
+ }
308
 
309
  if ( ! ( empty( $shortcode_attributes[ $filter_taxonomy ] ) && empty( $tax_input ) ) ) {
310
  $tax_query = '';
312
  // Look for the optional "simple taxonomy query" as an initial filter
313
  if ( !empty( $shortcode_attributes[ $filter_taxonomy ] ) ) {
314
  if ( 'muie-no-terms' !== $shortcode_attributes[ $filter_taxonomy ] ) {
315
+ // Check for a dropdown control with "All Terms" selected
316
+ $terms = explode( ',', $shortcode_attributes[ $filter_taxonomy ] );
317
+ if ( empty( $shortcode_attributes['option_all_value'] ) ) {
318
+ $option_all = array_search( '0', $terms );
319
+ } else {
320
+ $option_all = array_search( $shortcode_attributes['option_all_value'], $terms );
321
+ }
322
+
323
+ if ( false !== $option_all ) {
324
+ unset( $terms[ $option_all ] );
325
+ }
326
+
327
+ if ( !empty( $terms ) ) {
328
+ $values = "array( '" . implode( "', '", $terms ) . "' )";
329
+ $tax_query .= "array('taxonomy' => '{$filter_taxonomy}' ,'field' => 'slug','terms' => {$values}, 'operator' => 'IN'), ";
330
+ }
331
  }
332
 
333
  unset( $shortcode_attributes[ $filter_taxonomy ] );
334
  }
335
 
336
+ // Validate other tax_query parameters or set defaults
337
+ $tax_relation = 'AND';
338
+ if ( isset( $shortcode_attributes['tax_relation'] ) ) {
339
+ $attr_value = strtoupper( $shortcode_attributes['tax_relation'] );
340
+ if ( in_array( $attr_value, array( 'AND', 'OR' ) ) ) {
341
+ $tax_relation = $attr_value;
342
+ }
343
+ }
344
+
345
+ $tax_operator = 'IN';
346
+ if ( isset( $shortcode_attributes['tax_operator'] ) ) {
347
+ $attr_value = strtoupper( $shortcode_attributes['tax_operator'] );
348
+ if ( in_array( $attr_value, array( 'IN', 'NOT IN', 'AND' ) ) ) {
349
+ $tax_operator = $attr_value;
350
+ }
351
+ }
352
+
353
  foreach ( $tax_input as $taxonomy => $terms ) {
354
  // simple taxonomy query overrides tax_input
355
  if ( $taxonomy == $filter_taxonomy ) {
357
  }
358
 
359
  // Check for a dropdown control with "All Terms" selected
360
+ if ( empty( $shortcode_attributes['option_all_value'] ) ) {
361
+ $option_all = array_search( '0', $terms );
362
+ } else {
363
+ $option_all = array_search( $shortcode_attributes['option_all_value'], $terms );
364
+ }
365
+
366
  if ( false !== $option_all ) {
367
  unset( $terms[ $option_all ] );
368
  }
382
  $values = "array( '" . implode( "','", $terms ) . "' )";
383
  }
384
 
385
+ $tax_query .= "array('taxonomy' => '{$taxonomy}' ,'field' => '{$field}','terms' => {$values}, 'operator' => '" . $tax_operator . "'), ";
386
  }
387
  }
388
 
389
  if ( ! empty( $tax_query ) ) {
390
+ $shortcode_attributes['tax_query'] = "array( 'relation' => '" . $tax_relation . "', " . $tax_query . ')';
391
  }
392
  }
393
 
396
  */
397
  if ( !empty( $shortcode_attributes['mla_output'] ) ) {
398
 
399
+ $filters = urlencode( json_encode( $muie_filters ) );
400
  $shortcode_attributes['mla_link_href'] = '[+new_url+]?[+new_page_text+]&muie_filters=' . $filters;
401
 
402
  if ( !empty( $shortcode_attributes['posts_per_page'] ) ) {
408
  return $shortcode_attributes;
409
  } // mla_gallery_attributes
410
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
411
  /**
412
  * Terms search generator shortcode
413
  *
550
  return $return_value;
551
  } // muie_keyword_search
552
 
553
+ /**
554
+ * Items per page shortcode
555
+ *
556
+ * This shortcode generates an HTML text box with a default muie_per_page value.
557
+ *
558
+ * @since 1.00
559
+ *
560
+ * @param array the shortcode parameters
561
+ *
562
+ * @return string HTML markup for the generated form
563
+ */
564
+ public static function muie_per_page( $attr ) {
565
+ if ( isset( $attr['numberposts'] ) && ! isset( $attr['posts_per_page'] )) {
566
+ $attr['posts_per_page'] = $attr['numberposts'];
567
+ unset( $attr['numberposts'] );
568
+ }
569
+
570
+ if ( !empty( $_REQUEST['muie_per_page'] ) ) {
571
+ $posts_per_page = $_REQUEST['muie_per_page'];
572
+ } else {
573
+ $posts_per_page = isset( $attr['posts_per_page'] ) ? $attr['posts_per_page'] : 6;
574
+ }
575
+
576
+ return '<input name="muie_per_page" id="muie-per-page" type="text" size="2" value="' . $posts_per_page . '" />';
577
+ } // muie_per_page
578
+
579
+ /**
580
+ * Order by shortcode
581
+ *
582
+ * This shortcode generates a dropdown control with sort order values.
583
+ *
584
+ * @since 1.03
585
+ *
586
+ * @param array $attr the shortcode parameters
587
+ * @param string $content Optional content for enclosing shortcodes
588
+ *
589
+ * @return string HTML markup for the generated control(s)
590
+ */
591
+ public static function muie_orderby( $attr, $content = NULL ) {
592
+ $default_arguments = array(
593
+ 'shortcode' => 'mla_gallery',
594
+ 'sort_fields' => '',
595
+ 'meta_value_num' => '',
596
+ 'meta_value' => '',
597
+ );
598
+
599
+ // Make sure $attr is an array, even if it's empty
600
+ if ( empty( $attr ) ) {
601
+ $attr = array();
602
+ } elseif ( is_string( $attr ) ) {
603
+ $attr = shortcode_parse_atts( $attr );
604
+ }
605
+
606
+ /*
607
+ * Look for parameters in an enclosing shortcode
608
+ */
609
+ if ( !empty( $content ) ) {
610
+ $content = str_replace( array( '&#8216;', '&#8217;', '&#8221;', '&#8243;', '<br />', '<p>', '</p>', "\r", "\n" ), array( '\'', '\'', '"', '"', ' ', ' ', ' ', ' ', ' ' ), $content );
611
+ $new_attr = shortcode_parse_atts( $content );
612
+ $attr = array_merge( $attr, $new_attr );
613
+ }
614
+
615
+ // Accept only the attributes we need and supply defaults
616
+ $arguments = shortcode_atts( $default_arguments, $attr );
617
+
618
+ switch ( $arguments['shortcode'] ) {
619
+ case 'mla_gallery':
620
+ $allowed_fields = array(
621
+ 'empty' => '- select -',
622
+ 'ID' => 'item ID',
623
+ 'author' => 'Author',
624
+ 'date' => 'Date uploaded',
625
+ 'description' => 'Description',
626
+ 'title' => 'Title',
627
+ 'caption' => 'Caption',
628
+ 'slug' => 'name/slug',
629
+ 'parent' => 'Parent ID',
630
+ 'menu_order' => 'Menu order',
631
+ 'mime_type' => 'MIME type',
632
+ 'none' => 'No order',
633
+ 'rand' => 'Random',
634
+ );
635
+ break;
636
+ case 'mla_tag_cloud':
637
+ case 'mla_term_list':
638
+ $allowed_fields = array(
639
+ 'empty' => '- select -',
640
+ 'count' => 'Assigned items',
641
+ 'id' => 'Term ID',
642
+ 'name' => 'Term name',
643
+ 'slug' => 'Term slug',
644
+ 'none' => 'No order',
645
+ 'random' => 'Random',
646
+ );
647
+ break;
648
+ default:
649
+ $allowed_fields = array();
650
+ }
651
+
652
+ if ( empty( $arguments['sort_fields'] ) ) {
653
+ $sort_fields = $allowed_fields;
654
+ } else {
655
+ $sort_fields = array();
656
+
657
+ if ( 0 === strpos( $arguments['sort_fields'], 'array' ) ) {
658
+ $function = @create_function('', 'return ' . $arguments['sort_fields'] . ';' );
659
+ if ( is_callable( $function ) ) {
660
+ $field_array = $function();
661
+ }
662
+
663
+ if ( is_array( $field_array ) ) {
664
+ $sort_fields = $field_array;
665
+ }
666
+ } else {
667
+ foreach( explode( ',', $arguments['sort_fields'] ) as $field ) {
668
+ if ( array_key_exists( $field, $allowed_fields ) ) {
669
+ $sort_fields[ $field ] = $allowed_fields[ $field ];
670
+ }
671
+ }
672
+ }
673
+ }
674
+
675
+ // Check for custom field sorting
676
+ if ( !empty( $arguments['meta_value_num'] ) ) {
677
+ $custom_key = 'meta_value_num';
678
+ $custom_spec = $arguments['meta_value_num'];
679
+ } elseif ( !empty( $arguments['meta_value'] ) ) {
680
+ $custom_key = 'meta_value';
681
+ $custom_spec = $arguments['meta_value'];
682
+ } else {
683
+ $custom_key = '';
684
+ $custom_spec = '';
685
+ }
686
+
687
+ if ( !empty( $custom_spec ) ) {
688
+ $spec_parts = explode( '=>', $custom_spec );
689
+ $spec_key = trim( $spec_parts[0], ' \'"' );
690
+ $spec_suffix = '';
691
+
692
+ $tail = strrpos( $spec_key, ' DESC' );
693
+ if ( ! ( false === $tail ) ) {
694
+ $spec_key = substr( $spec_key, 0, $tail );
695
+ $spec_suffix = ' DESC';
696
+ } else {
697
+ $tail = strrpos( $spec_key, ' ASC' );
698
+ if ( ! ( false === $tail ) ) {
699
+ $spec_key = substr( $spec_key, 0, $tail );
700
+ $spec_suffix = ' ASC';
701
+ }
702
+ }
703
+
704
+ $spec_label = !empty( $spec_parts[1] ) ? trim( $spec_parts[1], ' \'"' ) : $spec_key;
705
+ $sort_fields[ $custom_key . $spec_suffix ] = $spec_label;
706
+ }
707
+
708
+ if ( empty( $sort_fields ) ) {
709
+ return '';
710
+ }
711
+
712
+ // Unpack filter values encoded for pagination links
713
+ if ( !empty( $_REQUEST['muie_filters'] ) ) {
714
+ $filters = json_decode( trim( stripslashes( $_REQUEST['muie_filters'] ), '"' ), true );
715
+
716
+ if ( isset( $filters['muie_orderby'] ) ) {
717
+ $_REQUEST['muie_orderby'] = $filters['muie_orderby'];
718
+ }
719
+ }
720
+
721
+ if ( !empty( $_REQUEST['muie_orderby'] ) ) {
722
+ $current_value = $_REQUEST['muie_orderby'];
723
+ } else {
724
+ $current_value = '';
725
+ }
726
+
727
+ if ( !empty( $spec_key ) ) {
728
+ $output = '<input name="muie_meta_key" id="muie-meta-key" type="hidden" value="' . $spec_key . '">' . "\n";
729
+ } else {
730
+ $output = '';
731
+ }
732
+
733
+ $output .= '<select name="muie_orderby" id="muie-orderby">' . "\n";
734
+
735
+ foreach ( $sort_fields as $value => $label ) {
736
+ $value = 'empty' === $value ? '' : $value;
737
+
738
+ $selected = ( $current_value === $value ) ? ' selected=selected ' : ' ';
739
+
740
+ $output .= ' <option' . $selected . 'value="' . $value . '">' . $label . "</option>\n";
741
+ }
742
+
743
+ $output .= "</select>\n";
744
+
745
+ return $output;
746
+ } // muie_orderby
747
+
748
+ /**
749
+ * Order (ASC/DESC) shortcode
750
+ *
751
+ * This shortcode generates ascending/descending radio buttons.
752
+ *
753
+ * @since 1.03
754
+ *
755
+ * @param array $attr the shortcode parameters
756
+ * @param string $content Optional content for enclosing shortcodes
757
+ *
758
+ * @return string HTML markup for the generated control(s)
759
+ */
760
+ public static function muie_order( $attr, $content = NULL ) {
761
+ $default_arguments = array(
762
+ 'default_order' => 'ASC',
763
+ 'asc_label' => 'Ascending',
764
+ 'desc_label' => 'Descending',
765
+ );
766
+
767
+ // Make sure $attr is an array, even if it's empty
768
+ if ( empty( $attr ) ) {
769
+ $attr = array();
770
+ } elseif ( is_string( $attr ) ) {
771
+ $attr = shortcode_parse_atts( $attr );
772
+ }
773
+
774
+ /*
775
+ * Look for parameters in an enclosing shortcode
776
+ */
777
+ if ( !empty( $content ) ) {
778
+ $content = str_replace( array( '&#8216;', '&#8217;', '&#8221;', '&#8243;', '<br />', '<p>', '</p>', "\r", "\n" ), array( '\'', '\'', '"', '"', ' ', ' ', ' ', ' ', ' ' ), $content );
779
+ $new_attr = shortcode_parse_atts( $content );
780
+ $attr = array_merge( $attr, $new_attr );
781
+ }
782
+
783
+ // Accept only the attributes we need and supply defaults
784
+ $arguments = shortcode_atts( $default_arguments, $attr );
785
+
786
+ // Unpack filter values encoded for pagination links
787
+ if ( !empty( $_REQUEST['muie_filters'] ) ) {
788
+ $filters = json_decode( trim( stripslashes( $_REQUEST['muie_filters'] ), '"' ), true );
789
+
790
+ if ( isset( $filters['muie_order'] ) ) {
791
+ $_REQUEST['muie_order'] = $filters['muie_order'];
792
+ }
793
+ }
794
+
795
+ if ( !empty( $_REQUEST['muie_order'] ) ) {
796
+ $current_value = $_REQUEST['muie_order'];
797
+ } else {
798
+ $current_value = $arguments['default_order'];
799
+ }
800
+
801
+ if ( 'DESC' === $current_value ) {
802
+ $asc_selected = '';
803
+ $desc_selected = ' checked="checked"';
804
+ } else {
805
+ $asc_selected = ' checked="checked"';
806
+ $desc_selected = '';
807
+ }
808
+
809
+ $output = '<input name="muie_order" id="muie-order-asc" type="radio"' . $asc_selected . ' value="ASC"> ' . $arguments['asc_label'] . '&nbsp;&nbsp;';
810
+ $output .= '<input name="muie_order" id="muie-order-desc" type="radio"' . $desc_selected . ' value="DESC">' . $arguments['desc_label'] . "&nbsp;&nbsp\n";
811
+
812
+ return $output;
813
+ } // muie_order
814
+
815
  /**
816
  * Assigned items count shortcode
817
  *
examples/plugins/mla-upload-bulk-edit-example.php CHANGED
@@ -1,6 +1,14 @@
1
  <?php
2
  /**
3
- * Updates the Title/post_title value entered in the bulk edit area
 
 
 
 
 
 
 
 
4
  *
5
  * @package MLA Upload Bulk Edit Example
6
  * @version 1.00
1
  <?php
2
  /**
3
+ * Updates the Title/post_title value entered in the bulk edit area, adding a
4
+ * sequence number to make the Titles unique
5
+ *
6
+ * This example plugin uses one of the "Media/Assistant Submenu Actions and Filters (Hooks)"
7
+ * and illustrates a technique you can use to customize the bulk edit process.
8
+ *
9
+ * Created for support topic "Counter in title for multiple upload images"
10
+ * opened on 8/5/2015 by "Superbobo75".
11
+ * https://wordpress.org/support/topic/counter-in-title-for-multiple-upload-images/
12
  *
13
  * @package MLA Upload Bulk Edit Example
14
  * @version 1.00
examples/plugins/posts-per-page-example.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Adjusts the [mla_gallery] posts_per_page value based on WordPress conditional functions
4
+ *
5
+ * In this example:
6
+ *
7
+ * A custom "posts_per_front_page" parameter adjusts the number of items generated for posts
8
+ * displayed on the site's front/home page.
9
+ *
10
+ * This example plugin uses one of the many filters available in the [mla_gallery] shortcode
11
+ * and illustrates a technique you can use to customize the gallery display.
12
+ *
13
+ * Created for support topic "dealing with posts_per_page / posts_per_archive_page"
14
+ * opened on 10/10/2016 by "Ernest".
15
+ * https://wordpress.org/support/topic/dealing-with-posts_per_page-posts_per_archive_page/
16
+ *
17
+ * @package Posts Per Page Example
18
+ * @version 1.00
19
+ */
20
+
21
+ /*
22
+ Plugin Name: Posts Per Page Example
23
+ Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
24
+ Description: Adjusts the [mla_gallery] posts_per_page value based on WordPress conditional functions
25
+ Author: David Lingren
26
+ Version: 1.00
27
+ Author URI: http://fairtradejudaica.org/our-story/staff/
28
+
29
+ Copyright 2016 David Lingren
30
+
31
+ This program is free software; you can redistribute it and/or modify
32
+ it under the terms of the GNU General Public License as published by
33
+ the Free Software Foundation; either version 2 of the License, or
34
+ (at your option) any later version.
35
+
36
+ This program is distributed in the hope that it will be useful,
37
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
38
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39
+ GNU General Public License for more details.
40
+
41
+ You can get a copy of the GNU General Public License by writing to the
42
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
43
+ */
44
+
45
+ /**
46
+ * Class Posts Per Page Example adjusts the [mla_gallery] posts_per_page value based on
47
+ * WordPress conditional functions
48
+ *
49
+ * @package Posts Per Page Example
50
+ * @since 1.00
51
+ */
52
+ class PostsPerPageExample {
53
+ /**
54
+ * Initialization function, similar to __construct()
55
+ *
56
+ * @since 1.00
57
+ *
58
+ * @return void
59
+ */
60
+ public static function initialize() {
61
+ // The filters are only useful for front-end posts/pages; exit if in the admin section
62
+ if ( is_admin() )
63
+ return;
64
+
65
+ add_filter( 'mla_gallery_attributes', 'PostsPerPageExample::mla_gallery_attributes', 10, 1 );
66
+ }
67
+
68
+ /**
69
+ * Process the 'posts_per_front_page' custom parameter
70
+ *
71
+ * @since 1.00
72
+ *
73
+ * @param array $shortcode_attributes The parameters passed to the shortcode plus defaults
74
+ */
75
+ public static function mla_gallery_attributes( $shortcode_attributes ) {
76
+ if ( empty( $shortcode_attributes['posts_per_front_page'] ) ) {
77
+ return $shortcode_attributes;
78
+ }
79
+
80
+ if ( is_front_page() ) {
81
+ $shortcode_attributes['posts_per_page'] = $shortcode_attributes['posts_per_front_page'];
82
+ }
83
+
84
+ //error_log( 'PostsPerPageExample::mla_gallery_attributes $shortcode_attributes = ' . var_export( $shortcode_attributes, true ), 0 );
85
+ return $shortcode_attributes;
86
+ } // mla_gallery_attributes
87
+ } // Class PostsPerPageExample
88
+
89
+ // Install the filters at an early opportunity
90
+ add_action('init', 'PostsPerPageExample::initialize');
91
+ ?>
examples/plugins/woofixit.php CHANGED
@@ -1,22 +1,84 @@
1
  <?php
2
  /**
3
- * Corrects Product Image/Product Gallery issues, synchronizes taxonomy terms
 
4
  *
5
- * Adds a Tools/Woo Fixit submenu with buttons to perform the operations.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  *
7
  * @package WooCommerce Fixit
8
- * @version 1.11
9
  */
10
 
11
  /*
12
  Plugin Name: WooCommerce Fixit
13
  Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
14
- Description: Corrects Product Image/Product Gallery issues
15
  Author: David Lingren
16
- Version: 1.11
17
  Author URI: http://fairtradejudaica.org/our-story/staff/
18
 
19
- Copyright 2014 David Lingren
20
 
21
  This program is free software; you can redistribute it and/or modify
22
  it under the terms of the GNU General Public License as published by
@@ -46,7 +108,7 @@ class Woo_Fixit {
46
  *
47
  * @var string
48
  */
49
- const CURRENT_VERSION = '1.11';
50
 
51
  /**
52
  * Slug prefix for registering and enqueueing submenu pages, style sheets and scripts
@@ -57,6 +119,76 @@ class Woo_Fixit {
57
  */
58
  const SLUG_PREFIX = 'woofixit-';
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  /**
61
  * Initialization function, similar to __construct()
62
  *
@@ -65,7 +197,13 @@ class Woo_Fixit {
65
  * @return void
66
  */
67
  public static function initialize() {
68
- add_action( 'admin_init', 'Woo_Fixit::admin_init_action' );
 
 
 
 
 
 
69
  add_action( 'admin_menu', 'Woo_Fixit::admin_menu_action' );
70
  }
71
 
@@ -118,17 +256,33 @@ class Woo_Fixit {
118
  * @return void Echoes HTML markup for the submenu page
119
  */
120
  public static function render_tools_page() {
121
- //error_log( 'Woo_Fixit::render_tools_page() $_REQUEST = ' . var_export( $_REQUEST, true ), 0 );
122
  if ( !current_user_can( 'manage_options' ) ) {
123
  echo "WooCommerce Fixit - Error</h2>\n";
124
  wp_die( 'You do not have permission to manage plugin settings.' );
125
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
 
127
  $setting_actions = array(
128
  'help' => array( 'handler' => '', 'comment' => 'Enter first/last Product ID values above to restrict tool application range. You can find ID values by hovering over the "Name" column in the WooCommerce/Products submenu table.' ),
129
  'warning' => array( 'handler' => '', 'comment' => '<strong>These tools make permanent updates to your database.</strong> Make a backup before you use the tools so you can restore your old values if you don&rsquo;t like the results.' ),
130
 
131
  'c0' => array( 'handler' => '', 'comment' => '<h3>Operations on ALL Media Library Images</h3>' ),
 
132
  'Clear Title' => array( 'handler' => '_clear_title',
133
  'comment' => '<strong>Delete ALL</strong> item Title fields.' ),
134
  'c1' => array( 'handler' => '', 'comment' => '<hr>' ),
@@ -140,31 +294,44 @@ class Woo_Fixit {
140
  'c2' => array( 'handler' => '', 'comment' => '<h3>Operations on Product Image/Product Gallery Images</h3>' ),
141
  'Clear ALT Text' => array( 'handler' => '_clear_alt_text',
142
  'comment' => '<strong>Delete ALL</strong> ALT Text fields for Product Image/Product Gallery items.' ),
 
 
143
  'c3' => array( 'handler' => '', 'comment' => '<hr>' ),
144
- 'Fill ALT Text' => array( 'handler' => '_fill_alt_text',
145
- 'comment' => 'Fill empty ALT Text field with first top-level Product Category.' ),
146
- 'Replace ALT Text' => array( 'handler' => '_replace_alt_text',
147
- 'comment' => '<strong>Replace ALL</strong> ALT Text field with first top-level Product Category.' ),
148
-
149
- 'c4' => array( 'handler' => '', 'comment' => '<h3>Operations on the Featured Image and Product Gallery</h3>' ),
 
 
 
 
 
 
 
 
 
150
  'Remove Feature' => array( 'handler' => '_remove_feature',
151
  'comment' => 'Remove Product/Featured Image from the Product Gallery.' ),
152
  'Restore Feature' => array( 'handler' => '_restore_feature',
153
  'comment' => 'Restore Product/Featured Image to the Product Gallery.' ),
154
  'Reverse Gallery' => array( 'handler' => '_reverse_gallery',
155
  'comment' => 'Reverse the image order in the Product Gallery.' ),
 
 
156
 
157
- 'c5' => array( 'handler' => '', 'comment' => '<h3>Operations on the Product Image and Product Tags Taxonomy</h3>' ),
158
  'Clear Product Tags' => array( 'handler' => '_clear_product_tags',
159
  'comment' => '<strong>Delete ALL</strong> Product Tags assignments where a Product Image exists.' ),
160
  'Fill Product Tags' => array( 'handler' => '_fill_product_tags',
161
  'comment' => 'Fill empty Product Tags assignments from Product Image Att. Tags where a Product Image exists.' ),
162
- 'Add Product Tags' => array( 'handler' => '_fill_product_tags',
163
  'comment' => 'Append Product Tags assignments to <strong>ALL Products</strong> from Product Image Att. Tags where a Product Image exists.' ),
164
  'Replace Product Tags' => array( 'handler' => '_replace_product_tags',
165
  'comment' => '<strong>Replace ALL</strong> Product Tags assignments from Product Image Att. Tags where a Product Image exists.' ),
166
 
167
- 'c6' => array( 'handler' => '', 'comment' => '<h3>Operations on Products, using the Product Image, Product Categories and Att. Tags</h3>' ),
168
  'Clear Product Cats' => array( 'handler' => '_clear_product_categories',
169
  'comment' => '<strong>Delete ALL Products&rsquo;</strong> Product Categories assignments where a Product Image exists.' ),
170
  'Fill Product Cats' => array( 'handler' => '_fill_product_categories',
@@ -174,7 +341,7 @@ class Woo_Fixit {
174
  'Replace Product Cats' => array( 'handler' => '_replace_product_categories',
175
  'comment' => '<strong>Replace ALL</strong> Product Categories assignments from Product Image Att. Tags,<br>where the Product Image Att. Tag matches an existing Product Category.' ),
176
 
177
- 'c7' => array( 'handler' => '', 'comment' => '<h3>Operations on the Att. Categories Taxonomy</h3>' ),
178
  'Clear Att. Cats' => array( 'handler' => '_clear_attachment_categories',
179
  'comment' => '<strong>Delete ALL</strong> Att. Categories assignments.' ),
180
  'Fill Att. Cats' => array( 'handler' => '_fill_attachment_categories',
@@ -183,8 +350,37 @@ class Woo_Fixit {
183
  'comment' => 'Append Att. Categories assignments to <strong>ALL items</strong> from Att. Tags,<br>where the Att. Tag matches an existing Att. Category.' ),
184
  'Replace Att. Cats' => array( 'handler' => '_replace_attachment_categories',
185
  'comment' => '<strong>Replace ALL</strong> Att. Categories assignments from Att. Tags, where the Att. Tag matches an existing Att. Category.' ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  );
187
-
188
  echo '<div class="wrap">' . "\n";
189
  echo "\t\t" . '<div id="icon-tools" class="icon32"><br/></div>' . "\n";
190
  echo "\t\t" . '<h2>WooCommerce Fixit Tools v' . self::CURRENT_VERSION . '</h2>' . "\n";
@@ -194,9 +390,32 @@ class Woo_Fixit {
194
  if( isset( $setting_actions[ $label ] ) ) {
195
  $action = $setting_actions[ $label ]['handler'];
196
  if ( ! empty( $action ) ) {
197
- echo self::$action();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
  } else {
199
- echo "\t\t<br>ERROR: no handler for action: \"{$label}\"\n";
200
  }
201
  } else {
202
  echo "\t\t<br>ERROR: unknown action: \"{$label}\"\n";
@@ -204,30 +423,40 @@ class Woo_Fixit {
204
  }
205
 
206
  echo "\t\t" . '<div style="width:700px">' . "\n";
207
- echo "\t\t" . '<form action="/wp-admin/tools.php?page=' . self::SLUG_PREFIX . 'tools' . '" method="post" class="' . self::SLUG_PREFIX . 'tools-form-class" id="' . self::SLUG_PREFIX . 'tools-form-id">' . "\n";
208
  echo "\t\t" . ' <p class="submit" style="padding-bottom: 0;">' . "\n";
209
  echo "\t\t" . ' <table>' . "\n";
210
 
211
- echo "\t\t" . ' <tr valign="top"><th style="text-align: right;" scope="row">First Product</th><td style="text-align: left;">' . "\n";
212
- echo "\t\t" . ' <input name="' . self::SLUG_PREFIX . 'lower" type="text" size="5" value="">' . "\n";
213
  echo "\t\t" . ' </td></tr>' . "\n";
214
-
215
- echo "\t\t" . ' <tr valign="top"><th style="text-align: right;" scope="row">Last Product</th><td style="text-align: left;">' . "\n";
216
- echo "\t\t" . ' <input name="' . self::SLUG_PREFIX . 'upper" type="text" size="5" value="">' . "\n";
217
  echo "\t\t" . ' </td></tr>' . "\n";
218
-
219
  foreach ( $setting_actions as $label => $action ) {
220
- if ( empty( $action['handler'] ) ) {
221
- echo "\t\t" . ' <tr><td colspan=2 style="padding: 2px 0px;">' . $action['comment'] . "</td></tr>\n";
222
- } else {
223
- echo "\t\t" . ' <tr><td width="150px">' . "\n";
224
- echo "\t\t" . ' <input name="' . self::SLUG_PREFIX . 'action" type="submit" class="button-primary" style="width: 140px;" value="' . $label . '" />&nbsp;&nbsp;' . "\n";
225
- echo "\t\t" . ' </td><td>' . "\n";
226
- echo "\t\t" . ' ' . $action['comment'] . "\n";
227
  echo "\t\t" . ' </td></tr>' . "\n";
 
 
 
 
 
 
 
 
 
 
228
  }
229
  }
230
-
231
  echo "\t\t" . ' </table>' . "\n";
232
  echo "\t\t" . ' </p>' . "\n";
233
  echo "\t\t" . '</form>' . "\n";
@@ -260,39 +489,38 @@ class Woo_Fixit {
260
  *
261
  * @since 1.00
262
  *
263
- * @return void
264
  */
265
- private static function _build_product_attachments() {
266
  global $wpdb;
267
-
268
- $query = sprintf( 'SELECT m.* FROM %1$s as m INNER JOIN %2$s as p ON m.post_id = p.ID WHERE ( p.post_type = \'product\' ) AND ( m.meta_key IN ( \'_product_image_gallery\', \'_thumbnail_id\' ) ) GROUP BY m.post_id, m.meta_id ORDER BY m.post_id', $wpdb->postmeta, $wpdb->posts );
269
- $results = $wpdb->get_results( $query );
270
- //error_log( 'Woo_Fixit::_build_product_attachments() $results = ' . var_export( $results, true ), 0 );
271
-
272
- if ( ! empty( $_REQUEST[ self::SLUG_PREFIX . 'lower' ] ) ) {
273
- $lower_bound = (integer) $_REQUEST[ self::SLUG_PREFIX . 'lower' ];
274
  } else {
275
  $lower_bound = 0;
276
  }
277
 
278
- if ( ! empty( $_REQUEST[ self::SLUG_PREFIX . 'upper' ] ) ) {
279
- $upper_bound = (integer) $_REQUEST[ self::SLUG_PREFIX . 'upper' ];
280
  } elseif ( $lower_bound ) {
281
  $upper_bound = $lower_bound;
282
  } else {
283
  $upper_bound = 0x7FFFFFFF;
284
  }
285
 
 
 
 
 
286
  self::$product_attachments = array();
287
  self::$attachment_products = array();
288
 
289
  foreach ( $results as $result ) {
290
- if ( ( $lower_bound > $result->post_id ) || ( $upper_bound < $result->post_id ) ) {
291
- continue;
 
292
  }
293
-
294
- self::$product_attachments[ $result->post_id ][ $result->meta_key ] = trim( $result->meta_value );
295
-
296
  if ( '_thumbnail_id' == $result->meta_key ) {
297
  $key = (integer) $result->meta_value;
298
  if ( isset( self::$attachment_products[ $key ] ) ) {
@@ -311,8 +539,8 @@ class Woo_Fixit {
311
  }
312
  }
313
  }
314
- //error_log( 'Woo_Fixit::_build_product_attachments() self::$product_attachments = ' . var_export( self::$product_attachments, true ), 0 );
315
- //error_log( 'Woo_Fixit::_build_product_attachments() self::$attachment_products = ' . var_export( self::$attachment_products, true ), 0 );
316
  } // _build_product_attachments
317
 
318
  /**
@@ -324,9 +552,9 @@ class Woo_Fixit {
324
  */
325
  private static function _clear_title() {
326
  global $wpdb;
327
-
328
  $results = $wpdb->query( "UPDATE {$wpdb->posts} SET post_title = '' WHERE post_type = 'attachment'" );
329
- return "<br>_clear_title() performed {$results} update(s).\n";
330
  } // _clear_title
331
 
332
  /**
@@ -338,10 +566,10 @@ class Woo_Fixit {
338
  */
339
  private static function _fill_title() {
340
  global $wpdb;
341
-
342
  $query = sprintf( 'SELECT m.post_id, m.meta_value FROM %1$s as m INNER JOIN %2$s as p ON m.post_id = p.ID WHERE ( p.post_title = \'\' ) AND ( p.post_type = \'attachment\' ) AND ( m.meta_key IN ( \'_wp_attached_file\' ) )', $wpdb->postmeta, $wpdb->posts );
343
  $results = $wpdb->get_results( $query );
344
-
345
  $update_count = 0;
346
  $select_bits = '';
347
  $where_bits = array();
@@ -351,7 +579,7 @@ class Woo_Fixit {
351
  $new_title = str_replace( array( '-', '_', '.' ), ' ', $path_info['filename'] );
352
  $select_bits .= " WHEN ID = {$result->post_id} THEN '{$new_title}'";
353
  $where_bits[] = $result->post_id;
354
-
355
  /*
356
  * Run an update when the chunk is full
357
  */
@@ -365,7 +593,7 @@ class Woo_Fixit {
365
  $chunk_count = 0;
366
  }
367
  }
368
-
369
  /*
370
  * Run a final update if the chunk is partially filled
371
  */
@@ -376,7 +604,7 @@ class Woo_Fixit {
376
  $update_count += $chunk_count;
377
  }
378
 
379
- return "<br>_fill_title() performed {$update_count} update(s).\n";
380
  } // _fill_title
381
 
382
  /**
@@ -388,10 +616,10 @@ class Woo_Fixit {
388
  */
389
  private static function _replace_title() {
390
  global $wpdb;
391
-
392
  $query = sprintf( 'SELECT m.post_id, m.meta_value FROM %1$s as m INNER JOIN %2$s as p ON m.post_id = p.ID WHERE ( p.post_mime_type LIKE \'%3$s\' ) AND ( p.post_type = \'attachment\' ) AND ( m.meta_key IN ( \'_wp_attached_file\' ) )', $wpdb->postmeta, $wpdb->posts, 'image/%' );
393
  $results = $wpdb->get_results( $query );
394
-
395
  $update_count = 0;
396
  $select_bits = '';
397
  $where_bits = array();
@@ -401,7 +629,7 @@ class Woo_Fixit {
401
  $new_title = str_replace( array( '-', '_', '.' ), ' ', $path_info['filename'] );
402
  $select_bits .= " WHEN ID = {$result->post_id} THEN '{$new_title}'";
403
  $where_bits[] = $result->post_id;
404
-
405
  /*
406
  * Run an update when the chunk is full
407
  */
@@ -415,7 +643,7 @@ class Woo_Fixit {
415
  $chunk_count = 0;
416
  }
417
  }
418
-
419
  /*
420
  * Run a final update if the chunk is partially filled
421
  */
@@ -426,7 +654,7 @@ class Woo_Fixit {
426
  $update_count += $chunk_count;
427
  }
428
 
429
- return "<br>_replace_title() performed {$update_count} update(s).\n";
430
  } // _replace_title
431
 
432
  /**
@@ -438,7 +666,7 @@ class Woo_Fixit {
438
  */
439
  private static function _clear_alt_text() {
440
  global $wpdb;
441
-
442
  self::_build_product_attachments();
443
  ksort( self::$attachment_products );
444
  $update_count = 0;
@@ -448,8 +676,8 @@ class Woo_Fixit {
448
  $query_result = $wpdb->query( $delete_query );
449
  $update_count += $query_result;
450
  }
451
-
452
- return "<br>_clear_alt_text() performed {$update_count} delete(s).\n";
453
  } // _clear_alt_text
454
 
455
  /**
@@ -461,13 +689,17 @@ class Woo_Fixit {
461
  */
462
  private static function _fill_alt_text() {
463
  global $wpdb;
464
-
465
  self::_build_product_attachments();
466
  $delete_count = 0;
467
  $insert_count = 0;
468
  foreach ( array_chunk( self::$product_attachments, 25, true ) as $chunk ) {
469
  $terms = wp_get_object_terms( array_keys( $chunk ), 'product_cat', array( 'orderby' => 'name', 'fields' => 'all_with_object_id' ) );
470
 
 
 
 
 
471
  /*
472
  * Build an array of "first product category" names
473
  */
@@ -499,7 +731,7 @@ class Woo_Fixit {
499
  if ( ! empty( $value['_thumbnail_id'] ) ) {
500
  $attachment_values[ $value['_thumbnail_id'] ] = $product_terms[ $key ]['name'];
501
  }
502
-
503
  if ( ! empty( $value['_product_image_gallery'] ) ) {
504
  $ids = explode( ',', $value['_product_image_gallery'] );
505
  foreach( $ids as $id ) {
@@ -522,7 +754,7 @@ class Woo_Fixit {
522
  }
523
  unset( $attachment_values[ (integer) $existing_value->post_id ] );
524
  }
525
-
526
  /*
527
  * Delete empty ALT Text values
528
  */
@@ -532,7 +764,7 @@ class Woo_Fixit {
532
  $query_result = $wpdb->query( $delete_query );
533
  $delete_count += $query_result;
534
  }
535
-
536
  /*
537
  * Insert the new values
538
  */
@@ -543,8 +775,8 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
543
  $insert_count += $query_result;
544
  }
545
  }
546
-
547
- return "<br>_fill_alt_text() performed {$delete_count} delete(s), {$insert_count} inserts(s).\n";
548
  } // _fill_alt_text
549
 
550
  /**
@@ -556,13 +788,17 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
556
  */
557
  private static function _replace_alt_text() {
558
  global $wpdb;
559
-
560
  self::_build_product_attachments();
561
  $delete_count = 0;
562
  $insert_count = 0;
563
  foreach ( array_chunk( self::$product_attachments, 25, true ) as $chunk ) {
564
  $terms = wp_get_object_terms( array_keys( $chunk ), 'product_cat', array( 'orderby' => 'name', 'fields' => 'all_with_object_id' ) );
565
 
 
 
 
 
566
  /*
567
  * Build an array of "first product category" names
568
  */
@@ -590,8 +826,8 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
590
  if ( isset( $value['_thumbnail_id'] ) ) {
591
  $attachment_values[ $value['_thumbnail_id'] ] = $product_terms[ $key ]['name'];
592
  }
593
-
594
- if ( ! empty( $value['_product_image_gallery'] ) ) {
595
  $ids = explode( ',', $value['_product_image_gallery'] );
596
  foreach( $ids as $id ) {
597
  $attachment_values[ $id ] = $product_terms[ $key ]['name'];
@@ -606,7 +842,77 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
606
  $delete_query = "DELETE FROM {$wpdb->postmeta} WHERE ( post_id IN ( {$keys} ) ) AND ( meta_key = '_wp_attachment_image_alt' )";
607
  $query_result = $wpdb->query( $delete_query );
608
  $delete_count += $query_result;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
609
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
610
  /*
611
  * Insert the new values
612
  */
@@ -617,9 +923,181 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
617
  $insert_count += $query_result;
618
  }
619
  }
 
 
 
620
 
621
- return "<br>_replace_alt_text() performed {$delete_count} delete(s), {$insert_count} inserts(s).\n";
622
- } // _replace_alt_text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
623
 
624
  /**
625
  * Remove Product/Featured Image from the Product Gallery
@@ -630,7 +1108,7 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
630
  */
631
  private static function _remove_feature() {
632
  global $wpdb;
633
-
634
  self::_build_product_attachments();
635
 
636
  $update_count = 0;
@@ -641,11 +1119,11 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
641
  if ( empty( $result['_thumbnail_id'] ) ) {
642
  continue;
643
  }
644
-
645
  $feature = (integer) $result['_thumbnail_id'];
646
  $gallery = array();
647
  $feature_found = false;
648
-
649
  if ( ! empty( $result['_product_image_gallery'] ) ) {
650
  foreach ( explode( ',', $result['_product_image_gallery'] ) as $item ) {
651
  if ( $feature == (integer) $item ) {
@@ -655,12 +1133,12 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
655
  }
656
  } // foreach gallery item
657
  }
658
-
659
  if ( $feature_found ) {
660
  $new_gallery = implode( ',', $gallery );
661
  $select_bits .= " WHEN post_id = {$post_id} THEN '{$new_gallery}'";
662
  $where_bits[] = $post_id;
663
-
664
  /*
665
  * Run an update when the chunk is full
666
  */
@@ -675,7 +1153,7 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
675
  }
676
  } // feature removed
677
  } // foreach product
678
-
679
  /*
680
  * Run a final update if the chunk is partially filled
681
  */
@@ -686,7 +1164,7 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
686
  $update_count += $chunk_count;
687
  }
688
 
689
- return "<br>_remove_feature() performed {$update_count} update(s).\n";
690
  } // _remove_feature
691
 
692
  /**
@@ -698,7 +1176,7 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
698
  */
699
  private static function _restore_feature() {
700
  global $wpdb;
701
-
702
  self::_build_product_attachments();
703
 
704
  $update_count = 0;
@@ -709,7 +1187,7 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
709
  if ( empty( $result['_thumbnail_id'] ) ) {
710
  continue;
711
  }
712
-
713
  $feature = (integer) $result['_thumbnail_id'];
714
  $gallery = array();
715
  $feature_found = false;
@@ -722,17 +1200,17 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
722
  }
723
  } // foreach gallery item
724
  }
725
-
726
  if ( ! $feature_found ) {
727
  if ( count( $gallery ) ) {
728
  $new_gallery = implode( ',', $gallery ) . ',' . $feature;
729
  } else {
730
  $new_gallery = (string) $feature;
731
  }
732
-
733
  $select_bits .= " WHEN post_id = {$post_id} THEN '{$new_gallery}'";
734
  $where_bits[] = $post_id;
735
-
736
  /*
737
  * Run an update when the chunk is full
738
  */
@@ -747,7 +1225,7 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
747
  }
748
  } // feature restored
749
  } // foreach product
750
-
751
  /*
752
  * Run a final update if the chunk is partially filled
753
  */
@@ -758,7 +1236,7 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
758
  $update_count += $chunk_count;
759
  }
760
 
761
- return "<br>_restore_feature() performed {$update_count} update(s).\n";
762
  } // _restore_feature
763
 
764
  /**
@@ -770,7 +1248,7 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
770
  */
771
  private static function _reverse_gallery() {
772
  global $wpdb;
773
-
774
  self::_build_product_attachments();
775
 
776
  $update_count = 0;
@@ -783,12 +1261,12 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
783
  } else {
784
  $gallery = explode( ',', $result['_product_image_gallery'] );
785
  }
786
-
787
  if ( 1 < count( $gallery ) ) {
788
  $new_gallery = implode( ',', array_reverse( $gallery ) );
789
  $select_bits .= " WHEN post_id = {$post_id} THEN '{$new_gallery}'";
790
  $where_bits[] = $post_id;
791
-
792
  /*
793
  * Run an update when the chunk is full
794
  */
@@ -803,7 +1281,7 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
803
  }
804
  } // gallery reversed
805
  } // foreach product
806
-
807
  /*
808
  * Run a final update if the chunk is partially filled
809
  */
@@ -814,9 +1292,86 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
814
  $update_count += $chunk_count;
815
  }
816
 
817
- return "<br>_reverse_gallery() performed {$update_count} update(s).\n";
818
  } // _reverse_gallery
819
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
820
  /**
821
  * Delete ALL Products' Product Tags assignments where a Product Image exists
822
  *
@@ -875,7 +1430,7 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
875
  */
876
  private static function _update_product_tags( $action ) {
877
  global $wpdb;
878
-
879
  self::_build_product_attachments();
880
 
881
  $update_count = 0;
@@ -896,7 +1451,7 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
896
  if ( count( $products ) == 0 ) {
897
  continue;
898
  }
899
-
900
  switch ( $action ) {
901
  case 'clear':
902
  case 'fill':
@@ -904,7 +1459,7 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
904
  $ids = implode( ',', array_keys( $products ) );
905
  $query = sprintf( 'SELECT DISTINCT tr.object_id FROM %1$s as tr INNER JOIN %2$s as tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE ( tr.object_id IN ( %3$s ) AND tt.taxonomy = \'product_tag\' ) ', $wpdb->term_relationships, $wpdb->term_taxonomy, $ids );
906
  $assignments = $wpdb->get_col( $query );
907
-
908
  if ( 'clear' == $action ) {
909
  foreach ( $assignments as $assignment ) {
910
  wp_delete_object_term_relationships( $assignment, 'product_tag' );
@@ -913,10 +1468,10 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
913
  } else {
914
  // Find the products that have no assignments
915
  $assignments = array_diff_key( $products, array_flip( $assignments ) );
916
-
917
  foreach ( $assignments as $product_id => $assignment ) {
918
  $attachment_tags = wp_get_object_terms( $assignment, 'attachment_tag', array( 'orderby' => 'none', 'fields' => 'names' ) );
919
-
920
  if ( ! empty( $attachment_tags ) ) {
921
  $term_taxonomy_ids = wp_set_object_terms( $product_id, $attachment_tags, 'product_tag' );
922
  $terms_added += count( $term_taxonomy_ids );
@@ -929,7 +1484,7 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
929
  case 'replace':
930
  foreach ( $products as $product_id => $assignment ) {
931
  $attachment_tags = wp_get_object_terms( $assignment, 'attachment_tag', array( 'orderby' => 'none', 'fields' => 'names' ) );
932
-
933
  if ( 'append' == $action ) {
934
  if ( ! empty( $attachment_tags ) ) {
935
  $old_term_taxonomy_ids = wp_get_object_terms( $product_id, 'product_tag', array( 'orderby' => 'none', 'fields' => 'tt_ids' ) );
@@ -950,7 +1505,7 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
950
  }
951
  } else {
952
  $term_taxonomy_ids = wp_get_object_terms( $product_id, 'product_tag', array( 'orderby' => 'none', 'fields' => 'tt_ids' ) );
953
-
954
  $old_terms = count( $term_taxonomy_ids );
955
  if ( 0 < $old_terms ) {
956
  $terms_removed += $old_terms;
@@ -962,23 +1517,23 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
962
  } // each assignment
963
  } // action
964
  } // each chunk
965
-
966
  switch ( $action ) {
967
  case 'clear':
968
- return "<br>_clear_product_categories() cleared {$update_count} Product(s).\n";
969
  break;
970
  case 'fill':
971
- return "<br>_fill_product_categories() added {$terms_added} term(s) to {$update_count} Product(s).\n";
972
  break;
973
  case 'append':
974
- return "<br>_append_product_categories() added {$terms_added} term(s) to {$update_count} Product(s).\n";
975
  break;
976
  case 'replace':
977
- return "<br>_replace_product_categories() replaced {$terms_added} term(s) in {$update_count} Product(s), and deleted {$terms_removed} term(s) from {$delete_count} Product(s).\n";
978
  }
979
-
980
- return "<br>Unknown _update_product_categories action: {$action}";
981
- } // _update_product_categories
982
 
983
  /**
984
  * Delete ALL Products' Product Categories assignments where a Product Image exists
@@ -1038,7 +1593,7 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
1038
  */
1039
  private static function _update_product_categories( $action ) {
1040
  global $wpdb;
1041
-
1042
  self::_build_product_attachments();
1043
 
1044
  if ( 'clear' != $action ) {
@@ -1066,7 +1621,7 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
1066
  if ( count( $products ) == 0 ) {
1067
  continue;
1068
  }
1069
-
1070
  switch ( $action ) {
1071
  case 'clear':
1072
  case 'fill':
@@ -1074,7 +1629,7 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
1074
  $ids = implode( ',', array_keys( $products ) );
1075
  $query = sprintf( 'SELECT DISTINCT tr.object_id FROM %1$s as tr INNER JOIN %2$s as tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE ( tr.object_id IN ( %3$s ) AND tt.taxonomy = \'product_cat\' ) ', $wpdb->term_relationships, $wpdb->term_taxonomy, $ids );
1076
  $assignments = $wpdb->get_col( $query );
1077
-
1078
  if ( 'clear' == $action ) {
1079
  foreach ( $assignments as $assignment ) {
1080
  wp_delete_object_term_relationships( $assignment, 'product_cat' );
@@ -1083,11 +1638,11 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
1083
  } else {
1084
  // Find the products that have no assignments
1085
  $assignments = array_diff_key( $products, array_flip( $assignments ) );
1086
-
1087
  foreach ( $assignments as $product_id => $assignment ) {
1088
  $attachment_tags = wp_get_object_terms( $assignment, 'attachment_tag', array( 'orderby' => 'none', 'fields' => 'names' ) );
1089
  $common_terms = array_keys( array_intersect( $product_categories, $attachment_tags ) );
1090
-
1091
  if ( ! empty( $common_terms ) ) {
1092
  $term_taxonomy_ids = wp_set_object_terms( $product_id, $common_terms, 'product_cat' );
1093
  $terms_added += count( $term_taxonomy_ids );
@@ -1101,7 +1656,7 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
1101
  foreach ( $products as $product_id => $assignment ) {
1102
  $attachment_tags = wp_get_object_terms( $assignment, 'attachment_tag', array( 'orderby' => 'none', 'fields' => 'names' ) );
1103
  $common_terms = array_keys( array_intersect( $product_categories, $attachment_tags ) );
1104
-
1105
  if ( 'append' == $action ) {
1106
  if ( ! empty( $common_terms ) ) {
1107
  $old_term_taxonomy_ids = wp_get_object_terms( $product_id, 'product_cat', array( 'orderby' => 'none', 'fields' => 'tt_ids' ) );
@@ -1122,7 +1677,7 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
1122
  }
1123
  } else {
1124
  $term_taxonomy_ids = wp_get_object_terms( $product_id, 'product_cat', array( 'orderby' => 'none', 'fields' => 'tt_ids' ) );
1125
-
1126
  $old_terms = count( $term_taxonomy_ids );
1127
  if ( 0 < $old_terms ) {
1128
  $terms_removed += $old_terms;
@@ -1134,22 +1689,22 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
1134
  } // each assignment
1135
  } // action
1136
  } // each chunk
1137
-
1138
  switch ( $action ) {
1139
  case 'clear':
1140
- return "<br>_clear_product_categories() cleared {$update_count} Product(s).\n";
1141
  break;
1142
  case 'fill':
1143
- return "<br>_fill_product_categories() added {$terms_added} term(s) to {$update_count} Product(s).\n";
1144
  break;
1145
  case 'append':
1146
- return "<br>_append_product_categories() added {$terms_added} term(s) to {$update_count} Product(s).\n";
1147
  break;
1148
  case 'replace':
1149
- return "<br>_replace_product_categories() replaced {$terms_added} term(s) in {$update_count} Product(s), and deleted {$terms_removed} term(s) from {$delete_count} Product(s).\n";
1150
  }
1151
-
1152
- return "<br>Unknown _update_product_categories action: {$action}";
1153
  } // _update_product_categories
1154
 
1155
  /**
@@ -1161,11 +1716,11 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
1161
  */
1162
  private static function _clear_attachment_categories() {
1163
  global $wpdb;
1164
-
1165
  $update_count = 0;
1166
  $offset = 0;
1167
  $limit = 25;
1168
-
1169
  do {
1170
  // Select a chunk of attachment IDs
1171
  $query = sprintf( 'SELECT p.ID FROM %1$s as p WHERE ( p.post_type = \'attachment\' ) ORDER BY p.ID LIMIT %2$d, %3$d', $wpdb->posts, $offset, $limit );
@@ -1184,11 +1739,11 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
1184
  } else {
1185
  $results = array();
1186
  }
1187
-
1188
  $offset += $limit;
1189
  } while ( count( $results ) == $limit );
1190
-
1191
- return "<br>_clear_attachment_categories() cleared {$update_count} items(s).\n";
1192
  } // _clear_attachment_categories
1193
 
1194
  /**
@@ -1201,7 +1756,7 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
1201
  */
1202
  private static function _fill_attachment_categories() {
1203
  global $wpdb;
1204
-
1205
  // Get the array of the Att. Category term objects for comparison
1206
  $attachment_categories = get_terms( 'attachment_category', array( 'orderby' => 'none', 'hide_empty' => 0, 'fields' => 'id=>name' ) );
1207
 
@@ -1209,7 +1764,7 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
1209
  $terms_added = 0;
1210
  $offset = 0;
1211
  $limit = 25;
1212
-
1213
  do {
1214
  // Select a chunk of attachment IDs
1215
  $query = sprintf( 'SELECT p.ID FROM %1$s as p WHERE ( p.post_type = \'attachment\' ) ORDER BY p.ID LIMIT %2$d, %3$d', $wpdb->posts, $offset, $limit );
@@ -1220,7 +1775,7 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
1220
  $ids = implode( ',', $results );
1221
  $query = sprintf( 'SELECT DISTINCT tr.object_id FROM %1$s as tr INNER JOIN %2$s as tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE ( tr.object_id IN ( %3$s ) AND tt.taxonomy = \'attachment_category\' ) ', $wpdb->term_relationships, $wpdb->term_taxonomy, $ids );
1222
  $assignments = $wpdb->get_col( $query );
1223
-
1224
  // find the attachments that have no assignments
1225
  $assignments = array_diff( $results, $assignments );
1226
 
@@ -1236,11 +1791,11 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
1236
  } else {
1237
  $results = array();
1238
  }
1239
-
1240
  $offset += $limit;
1241
  } while ( count( $results ) == $limit );
1242
 
1243
- return "<br>_fill_attachment_categories() added {$terms_added} term(s) to {$update_count} item(s).\n";
1244
  } // _fill_attachment_categories
1245
 
1246
  /**
@@ -1253,7 +1808,7 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
1253
  */
1254
  private static function _append_attachment_categories() {
1255
  global $wpdb;
1256
-
1257
  // Get the array of the Att. Category term objects for comparison
1258
  $attachment_categories = get_terms( 'attachment_category', array( 'orderby' => 'none', 'hide_empty' => 0, 'fields' => 'id=>name' ) );
1259
 
@@ -1261,7 +1816,7 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
1261
  $terms_added = 0;
1262
  $offset = 0;
1263
  $limit = 25;
1264
-
1265
  do {
1266
  // Select a chunk of attachment IDs
1267
  $query = sprintf( 'SELECT p.ID FROM %1$s as p WHERE ( p.post_type = \'attachment\' ) ORDER BY p.ID LIMIT %2$d, %3$d', $wpdb->posts, $offset, $limit );
@@ -1272,7 +1827,7 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
1272
  $ids = implode( ',', $results );
1273
  $query = sprintf( 'SELECT DISTINCT tr.object_id FROM %1$s as tr INNER JOIN %2$s as tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE ( tr.object_id IN ( %3$s ) AND tt.taxonomy = \'attachment_tag\' ) ', $wpdb->term_relationships, $wpdb->term_taxonomy, $ids );
1274
  $assignments = $wpdb->get_col( $query );
1275
-
1276
  foreach ( $assignments as $assignment ) {
1277
  $attachment_tags = wp_get_object_terms( $assignment, 'attachment_tag', array( 'orderby' => 'none', 'fields' => 'names' ) );
1278
  $common_terms = array_keys( array_intersect( $attachment_categories, $attachment_tags ) );
@@ -1290,11 +1845,11 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
1290
  } else {
1291
  $results = array();
1292
  }
1293
-
1294
  $offset += $limit;
1295
  } while ( count( $results ) == $limit );
1296
 
1297
- return "<br>_append_attachment_categories() added {$terms_added} term(s) to {$update_count} item(s).\n";
1298
  } // _append_attachment_categories
1299
 
1300
  /**
@@ -1307,7 +1862,7 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
1307
  */
1308
  private static function _replace_attachment_categories() {
1309
  global $wpdb;
1310
-
1311
  // Get the array of the Att. Category term objects for comparison
1312
  $attachment_categories = get_terms( 'attachment_category', array( 'orderby' => 'none', 'hide_empty' => 0, 'fields' => 'id=>name' ) );
1313
 
@@ -1318,7 +1873,7 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
1318
 
1319
  $offset = 0;
1320
  $limit = 25;
1321
-
1322
  do {
1323
  // Select a chunk of attachment IDs
1324
  $query = sprintf( 'SELECT p.ID FROM %1$s as p WHERE ( p.post_type = \'attachment\' ) ORDER BY p.ID LIMIT %2$d, %3$d', $wpdb->posts, $offset, $limit );
@@ -1349,12 +1904,136 @@ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
1349
  } else {
1350
  $results = array();
1351
  }
1352
-
1353
  $offset += $limit;
1354
  } while ( count( $results ) == $limit );
1355
 
1356
- return "<br>_replace_attachment_categories() replaced {$terms_added} term(s) in {$update_count} item(s), and deleted {$terms_removed} term(s) from {$delete_count} item(s).\n";
1357
  } // _replace_attachment_categories
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1358
  } //Woo_Fixit
1359
 
1360
  /*
1
  <?php
2
  /**
3
+ * Adds a Tools/Woo Fixit submenu with buttons to perform a variety of
4
+ * MLA/WooCommerce repair and enhancement operations.
5
  *
6
+ * This example supports several "tools"/operations:
7
+ *
8
+ * - Delete ALL Title fields for Product Image/Product Gallery items.
9
+ * - Fill empty item Title field with re-formatted file name.
10
+ * - Replace ALL item Title fields with re-formatted file name.
11
+ *
12
+ * - Delete ALL ALT Text fields for Product Image/Product Gallery items.
13
+ * - Fill empty ALT Text field with first top-level Product Category.
14
+ * - Replace ALL ALT Text field with first top-level Product Category.
15
+ * - Fill empty ALT Text field with Product Title.
16
+ * - Replace ALL ALT Text field with Product Title.
17
+ * - Fill empty item Title field with Product Title.
18
+ * - Replace ALL item Title field with Product Title.
19
+ *
20
+ * - Remove Product/Featured Image from the Product Gallery.
21
+ * - Restore Product/Featured Image to the Product Gallery.
22
+ * - Reverse the image order in the Product Gallery.
23
+ * - Replace "where_used" information in custom field "Woo Used In".
24
+ *
25
+ * - Delete ALL Product Tags assignments where a Product Image exists.
26
+ * - Fill empty Product Tags assignments from Product Image Att. Tags
27
+ * where a Product Image exists.
28
+ * - Append Product Tags assignments to ALL Products from Product Image
29
+ * Att. Tags where a Product Image exists.
30
+ * - Replace ALL Product Tags assignments from Product Image Att. Tags
31
+ * where a Product Image exists.
32
+ *
33
+ * - Delete ALL Products' Product Categories assignments where a Product Image exists.
34
+ * - Fill empty Product Categories assignments from Product Image Att. Tags,
35
+ * where the Product Image Att. Tag matches an existing Product Category.
36
+ * - Append Product Categories assignments to ALL Products from Product Image
37
+ * Att. Tags, where the Product Image Att. Tag matches an existing Product Category.
38
+ * - Replace ALL Product Categories assignments from Product Image Att. Tags,
39
+ * where the Product Image Att. Tag matches an existing Product Category.
40
+ *
41
+ * - Delete ALL Att. Categories assignments.
42
+ * - Fill empty Att. Categories assignments from Att. Tags, where the
43
+ * Att. Tag matches an existing Att. Category.
44
+ * - Append Att. Categories assignments to ALL items from Att. Tags,
45
+ * where the Att. Tag matches an existing Att. Category.
46
+ * - Replace ALL Att. Categories assignments from Att. Tags, where the
47
+ * Att. Tag matches an existing Att. Category.
48
+ *
49
+ * - Delete product_category and/or product_tag term assignments to Media Library items.
50
+ * - Copy product_category and/or product_tag term assignments to Media Library items
51
+ * for items used as Product Image or in the Product Gallery
52
+ *
53
+ * Created for support topic "Remove first image in all product galleries"
54
+ * opened on 5/23/2014 by "Dana S".
55
+ * https://wordpress.org/support/topic/remove-first-image-in-all-product-galleries/
56
+ *
57
+ * and for support topic "set the product category as alt and title tag for all images"
58
+ * opened on 5/23/2014 by "Dana S".
59
+ * https://wordpress.org/support/topic/set-the-product-category-as-alt-and-title-tag-for-all-images/
60
+ *
61
+ * Enhanced for support topic "Bulk addition of image alt tags to WooCommerce Product Images"
62
+ * opened on 11/18/2015 by "Thrive Internet Marketing".
63
+ * https://wordpress.org/support/topic/bulk-addition-of-image-alt-tags-to-woocommerce-product-images/
64
+ *
65
+ * Enhanced for support topic "Woocommerce product category"
66
+ * opened on 9/17/2015 by "vnp_nl".
67
+ * https://wordpress.org/support/topic/woocommerce-product-category-2/
68
  *
69
  * @package WooCommerce Fixit
70
+ * @version 1.27
71
  */
72
 
73
  /*
74
  Plugin Name: WooCommerce Fixit
75
  Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
76
+ Description: Adds a Tools/Woo Fixit submenu with buttons to perform a variety of MLA/WooCommerce repair and enhancement operations.
77
  Author: David Lingren
78
+ Version: 1.27
79
  Author URI: http://fairtradejudaica.org/our-story/staff/
80
 
81
+ Copyright 2014-2015 David Lingren
82
 
83
  This program is free software; you can redistribute it and/or modify
84
  it under the terms of the GNU General Public License as published by
108
  *
109
  * @var string
110
  */
111
+ const CURRENT_VERSION = '1.27';
112
 
113
  /**
114
  * Slug prefix for registering and enqueueing submenu pages, style sheets and scripts
119
  */
120
  const SLUG_PREFIX = 'woofixit-';
121
 
122
+ /**
123
+ * Lowest product ID to be processed
124
+ *
125
+ * @since 1.26
126
+ *
127
+ * @var string
128
+ */
129
+ private static $first_product = '';
130
+ const INPUT_FIRST_PRODUCT = 'lower';
131
+
132
+ /**
133
+ * Highest product ID to be processed
134
+ *
135
+ * @since 1.26
136
+ *
137
+ * @var string
138
+ */
139
+ private static $last_product = '';
140
+ const INPUT_LAST_PRODUCT = 'upper';
141
+
142
+ /**
143
+ * Process term assignments for Product Category
144
+ *
145
+ * @since 1.26
146
+ *
147
+ * @var boolean
148
+ */
149
+ private static $process_category = true;
150
+ const INPUT_PROCESS_CATEGORY = 'category';
151
+
152
+ /**
153
+ * Process term assignments for Product Tag
154
+ *
155
+ * @since 1.26
156
+ *
157
+ * @var boolean
158
+ */
159
+ private static $process_tag = true;
160
+ const INPUT_PROCESS_TAG = 'tag';
161
+
162
+ /**
163
+ * Chunk (offset) to start term assignments at
164
+ *
165
+ * @since 1.26
166
+ *
167
+ * @var integer
168
+ */
169
+ private static $start_chunk = 1;
170
+ const INPUT_FIRST_CHUNK = 'first';
171
+
172
+ /**
173
+ * Chunk (offset) to stop term assignments at
174
+ *
175
+ * @since 1.26
176
+ *
177
+ * @var integer
178
+ */
179
+ private static $stop_chunk = 999;
180
+ const INPUT_LAST_CHUNK = 'last';
181
+
182
+ /**
183
+ * Chunk size (limit) for term assignment processing
184
+ *
185
+ * @since 1.26
186
+ *
187
+ * @var integer
188
+ */
189
+ private static $chunk_size = 1000;
190
+ const INPUT_CHUNK_SIZE = 'size';
191
+
192
  /**
193
  * Initialization function, similar to __construct()
194
  *
197
  * @return void
198
  */
199
  public static function initialize() {
200
+ /*
201
+ * The filters are only useful in the admin section; exit if in front-end posts/pages
202
+ */
203
+ if ( !is_admin() )
204
+ return;
205
+
206
+ //add_action( 'admin_init', 'Woo_Fixit::admin_init_action' );
207
  add_action( 'admin_menu', 'Woo_Fixit::admin_menu_action' );
208
  }
209
 
256
  * @return void Echoes HTML markup for the submenu page
257
  */
258
  public static function render_tools_page() {
259
+ //error_log( __LINE__ . ' Woo_Fixit::render_tools_page() $_REQUEST = ' . var_export( $_REQUEST, true ), 0 );
260
  if ( !current_user_can( 'manage_options' ) ) {
261
  echo "WooCommerce Fixit - Error</h2>\n";
262
  wp_die( 'You do not have permission to manage plugin settings.' );
263
  }
264
+
265
+ /*
266
+ * Extract relevant query arguments
267
+ */
268
+ self::$first_product = isset( $_REQUEST[ self::SLUG_PREFIX . self::INPUT_FIRST_PRODUCT ] ) ? $_REQUEST[ self::SLUG_PREFIX . self::INPUT_FIRST_PRODUCT ] : '';
269
+ self::$last_product = isset( $_REQUEST[ self::SLUG_PREFIX . self::INPUT_LAST_PRODUCT ] ) ? $_REQUEST[ self::SLUG_PREFIX . self::INPUT_LAST_PRODUCT ] : '';
270
+
271
+ self::$process_category = isset( $_REQUEST[ self::SLUG_PREFIX . self::INPUT_PROCESS_CATEGORY ] ) ? true : false;
272
+ $category_attr = self::$process_category ? ' checked="checked" ' : ' ';
273
+ self::$process_tag = isset( $_REQUEST[ self::SLUG_PREFIX . self::INPUT_PROCESS_TAG ] ) ? true : false;
274
+ $tag_attr = self::$process_tag ? ' checked="checked" ' : ' ';
275
+
276
+ self::$start_chunk = isset( $_REQUEST[ self::SLUG_PREFIX . self::INPUT_FIRST_CHUNK ] ) ? absint( $_REQUEST[ self::SLUG_PREFIX . self::INPUT_FIRST_CHUNK ] ) : self::$start_chunk;
277
+ self::$stop_chunk = isset( $_REQUEST[ self::SLUG_PREFIX . self::INPUT_LAST_CHUNK ] ) ? absint( $_REQUEST[ self::SLUG_PREFIX . self::INPUT_LAST_CHUNK ] ) : self::$stop_chunk;
278
+ self::$chunk_size = isset( $_REQUEST[ self::SLUG_PREFIX . self::INPUT_CHUNK_SIZE ] ) ? absint( $_REQUEST[ self::SLUG_PREFIX . self::INPUT_CHUNK_SIZE ] ) : self::$chunk_size;
279
 
280
  $setting_actions = array(
281
  'help' => array( 'handler' => '', 'comment' => 'Enter first/last Product ID values above to restrict tool application range. You can find ID values by hovering over the "Name" column in the WooCommerce/Products submenu table.' ),
282
  'warning' => array( 'handler' => '', 'comment' => '<strong>These tools make permanent updates to your database.</strong> Make a backup before you use the tools so you can restore your old values if you don&rsquo;t like the results.' ),
283
 
284
  'c0' => array( 'handler' => '', 'comment' => '<h3>Operations on ALL Media Library Images</h3>' ),
285
+ 'warning2' => array( 'handler' => '', 'comment' => 'The tools in this section <strong>are not restricted</strong> by the First &amp; Last Product IDs above. They operate on <strong>ALL</strong> of the items in your Media Library.' ),
286
  'Clear Title' => array( 'handler' => '_clear_title',
287
  'comment' => '<strong>Delete ALL</strong> item Title fields.' ),
288
  'c1' => array( 'handler' => '', 'comment' => '<hr>' ),
294
  'c2' => array( 'handler' => '', 'comment' => '<h3>Operations on Product Image/Product Gallery Images</h3>' ),
295
  'Clear ALT Text' => array( 'handler' => '_clear_alt_text',
296
  'comment' => '<strong>Delete ALL</strong> ALT Text fields for Product Image/Product Gallery items.' ),
297
+ 'Clear Title' => array( 'handler' => '_clear_title',
298
+ 'comment' => '<strong>Delete ALL</strong> Title fields for Product Image/Product Gallery items.' ),
299
  'c3' => array( 'handler' => '', 'comment' => '<hr>' ),
300
+ 'Fill ALT Text (PC)' => array( 'handler' => '_fill_alt_text',
301
+ 'comment' => 'Fill empty ALT Text field with first top-level <strong>Product Category</strong>.' ),
302
+ 'Replace ALT Text (PC)' => array( 'handler' => '_replace_alt_text',
303
+ 'comment' => '<strong>Replace ALL</strong> ALT Text field with first top-level <strong>Product Category</strong>.' ),
304
+ 'c4' => array( 'handler' => '', 'comment' => '<hr>' ),
305
+ 'Fill ALT Text (T)' => array( 'handler' => '_fill_alt_text_t',
306
+ 'comment' => 'Fill empty ALT Text field with <strong>Product Title</strong>.' ),
307
+ 'Replace ALT Text (T)' => array( 'handler' => '_replace_alt_text_t',
308
+ 'comment' => '<strong>Replace ALL</strong> ALT Text field with <strong>Product Title</strong>.' ),
309
+ 'Fill Title (T)' => array( 'handler' => '_fill_title_t',
310
+ 'comment' => 'Fill empty item Title field with <strong>Product Title</strong>.' ),
311
+ 'Replace Title (T)' => array( 'handler' => '_replace_title_t',
312
+ 'comment' => '<strong>Replace ALL</strong> item Title field with <strong>Product Title</strong>.' ),
313
+
314
+ 'c5' => array( 'handler' => '', 'comment' => '<h3>Operations on the Featured Image and Product Gallery</h3>' ),
315
  'Remove Feature' => array( 'handler' => '_remove_feature',
316
  'comment' => 'Remove Product/Featured Image from the Product Gallery.' ),
317
  'Restore Feature' => array( 'handler' => '_restore_feature',
318
  'comment' => 'Restore Product/Featured Image to the Product Gallery.' ),
319
  'Reverse Gallery' => array( 'handler' => '_reverse_gallery',
320
  'comment' => 'Reverse the image order in the Product Gallery.' ),
321
+ 'Where-used' => array( 'handler' => '_where_used',
322
+ 'comment' => 'Replace &quot;where_used&quot; information in custom field &quot;Woo Used In&quot;.' ),
323
 
324
+ 'c6' => array( 'handler' => '', 'comment' => '<h3>Operations on Products, using the Product Image, Product Tags and Att. Tags</h3>' ),
325
  'Clear Product Tags' => array( 'handler' => '_clear_product_tags',
326
  'comment' => '<strong>Delete ALL</strong> Product Tags assignments where a Product Image exists.' ),
327
  'Fill Product Tags' => array( 'handler' => '_fill_product_tags',
328
  'comment' => 'Fill empty Product Tags assignments from Product Image Att. Tags where a Product Image exists.' ),
329
+ 'Add Product Tags' => array( 'handler' => '_append_product_tags',
330
  'comment' => 'Append Product Tags assignments to <strong>ALL Products</strong> from Product Image Att. Tags where a Product Image exists.' ),
331
  'Replace Product Tags' => array( 'handler' => '_replace_product_tags',
332
  'comment' => '<strong>Replace ALL</strong> Product Tags assignments from Product Image Att. Tags where a Product Image exists.' ),
333
 
334
+ 'c7' => array( 'handler' => '', 'comment' => '<h3>Operations on Products, using the Product Image, Product Categories and Att. Tags</h3>' ),
335
  'Clear Product Cats' => array( 'handler' => '_clear_product_categories',
336
  'comment' => '<strong>Delete ALL Products&rsquo;</strong> Product Categories assignments where a Product Image exists.' ),
337
  'Fill Product Cats' => array( 'handler' => '_fill_product_categories',
341
  'Replace Product Cats' => array( 'handler' => '_replace_product_categories',
342
  'comment' => '<strong>Replace ALL</strong> Product Categories assignments from Product Image Att. Tags,<br>where the Product Image Att. Tag matches an existing Product Category.' ),
343
 
344
+ 'c8' => array( 'handler' => '', 'comment' => '<h3>Operations on the Att. Categories Taxonomy</h3>' ),
345
  'Clear Att. Cats' => array( 'handler' => '_clear_attachment_categories',
346
  'comment' => '<strong>Delete ALL</strong> Att. Categories assignments.' ),
347
  'Fill Att. Cats' => array( 'handler' => '_fill_attachment_categories',
350
  'comment' => 'Append Att. Categories assignments to <strong>ALL items</strong> from Att. Tags,<br>where the Att. Tag matches an existing Att. Category.' ),
351
  'Replace Att. Cats' => array( 'handler' => '_replace_attachment_categories',
352
  'comment' => '<strong>Replace ALL</strong> Att. Categories assignments from Att. Tags, where the Att. Tag matches an existing Att. Category.' ),
353
+ 'c9' => array( 'handler' => '', 'comment' => '<h3>Term Assignments for Media Library Items</h3>' ),
354
+ 't0101' => array( 'open' => '<table><tr>' ),
355
+ 't0102' => array( 'continue' => ' <td style="text-align: right; padding-right: 5px" valign="middle"><input name="' . self::SLUG_PREFIX . self::INPUT_PROCESS_CATEGORY . '" type="checkbox"' . $category_attr . 'value="' . self::INPUT_PROCESS_CATEGORY . '"></td>' ),
356
+ 't0103' => array( 'continue' => ' <td style="text-align: left; padding-right: 5px" valign="middle">product_category</td>' ),
357
+ 't0104' => array( 'continue' => ' <td style="text-align: right; padding-right: 5px" valign="middle"><input name="' . self::SLUG_PREFIX . self::INPUT_PROCESS_TAG . '" type="checkbox"' . $tag_attr . 'value="' . self::INPUT_PROCESS_TAG . '"></td>' ),
358
+ 't0105' => array( 'continue' => ' <td style="text-align: left; padding-right: 5px" valign="middle">product_tag</td>' ),
359
+ 't0106' => array( 'continue' => ' <td colspan=2 style="text-align: right; padding-right: 5px" valign="middle">&nbsp;</td>' ),
360
+ 't0107' => array( 'continue' => '</tr><tr>' ),
361
+ 't0108' => array( 'continue' => '<td>&nbsp;</td><td colspan="5">Check a box above to include the taxonomy in the processing.</td>' ),
362
+ 't0109' => array( 'continue' => '</tr><tr style="display: none">' ),
363
+ 't0110' => array( 'continue' => ' <td style="text-align: right; padding-right: 5px" valign="middle">Start Chunk</td>' ),
364
+ 't0111' => array( 'continue' => ' <td style="text-align: left; padding-right: 20px">' ),
365
+ 't0112' => array( 'continue' => ' <input name="' . self::SLUG_PREFIX . self::INPUT_FIRST_CHUNK . '" type="text" size="5" value="' . self::$start_chunk . '">' ),
366
+ 't0113' => array( 'continue' => ' </td>' ),
367
+ 't0114' => array( 'continue' => ' <td style="text-align: right; padding-right: 5px" valign="middle">Stop Chunk</td>' ),
368
+ 't0115' => array( 'continue' => ' <td style="text-align: left;">' ),
369
+ 't0116' => array( 'continue' => ' <input name="' . self::SLUG_PREFIX . self::INPUT_LAST_CHUNK . '" type="text" size="5" value="' . self::$stop_chunk . '">' ),
370
+ 't0117' => array( 'continue' => ' </td>' ),
371
+ 't0118' => array( 'continue' => ' <td style="text-align: right; padding-right: 5px" valign="middle">Chunk Size</td>' ),
372
+ 't0119' => array( 'continue' => ' <td style="text-align: left;">' ),
373
+ 't0120' => array( 'continue' => ' <input name="' . self::SLUG_PREFIX . self::INPUT_CHUNK_SIZE . '" type="text" size="5" value="' . self::$chunk_size . '">' ),
374
+ 't0121' => array( 'continue' => ' </td>' ),
375
+ 't0122' => array( 'continue' => '</tr><tr style="display: none">' ),
376
+ 't0123' => array( 'continue' => '<td>&nbsp;</td><td colspan="5">Enter start and stop chunks to restrict processing range;<br>chunk size is number of proucts/chunk.</td>' ),
377
+ 't0124' => array( 'close' => '</tr></table>&nbsp;<br>' ),
378
+ 'Clear Terms' => array( 'handler' => '_clear_term_assignments',
379
+ 'comment' => '<strong>Delete ALL</strong> product_category and/or product_tag term assignments to Media Library items.' ),
380
+ 'Assign Terms' => array( 'handler' => '_copy_term_assignments',
381
+ 'comment' => 'Copy product_category and/or product_tag term assignments to Media Library items for items used as Product Image or in the Product Gallery.' ),
382
  );
383
+
384
  echo '<div class="wrap">' . "\n";
385
  echo "\t\t" . '<div id="icon-tools" class="icon32"><br/></div>' . "\n";
386
  echo "\t\t" . '<h2>WooCommerce Fixit Tools v' . self::CURRENT_VERSION . '</h2>' . "\n";
390
  if( isset( $setting_actions[ $label ] ) ) {
391
  $action = $setting_actions[ $label ]['handler'];
392
  if ( ! empty( $action ) ) {
393
+ if ( method_exists( 'Woo_Fixit', $action ) ) {
394
+ $message = self::$action();
395
+
396
+ if ( !empty( $message ) ) {
397
+ $is_error = ( false !== strpos( $message, __( 'ERROR', 'media-library-assistant' ) ) );
398
+ if ( $is_error ) {
399
+ $messages_class = 'updated error';
400
+ } else {
401
+ $messages_class = 'updated notice is-dismissible';
402
+ }
403
+
404
+ echo " <div class=\"{$messages_class}\" id=\"message\"><p>\n";
405
+ echo ' ' . $message . "\n";
406
+ echo " </p>\n";
407
+
408
+ if ( !$is_error ) {
409
+ echo " <button class=\"notice-dismiss\" type=\"button\"><span class=\"screen-reader-text\">Dismiss this notice.</span></button>\n";
410
+ }
411
+
412
+ echo " </div>\n";
413
+ }
414
+ } else {
415
+ echo "\t\t<br><strong>ERROR</strong>: handler \"{$action}\" does not exist for action: \"{$label}\"\n";
416
+ }
417
  } else {
418
+ echo "\t\t<br><strong>ERROR</strong>: no handler for action: \"{$label}\"\n";
419
  }
420
  } else {
421
  echo "\t\t<br>ERROR: unknown action: \"{$label}\"\n";
423
  }
424
 
425
  echo "\t\t" . '<div style="width:700px">' . "\n";
426
+ echo "\t\t" . '<form action="' . admin_url( 'tools.php?page=' . self::SLUG_PREFIX . 'tools' ) . '" method="post" class="' . self::SLUG_PREFIX . 'tools-form-class" id="' . self::SLUG_PREFIX . 'tools-form-id">' . "\n";
427
  echo "\t\t" . ' <p class="submit" style="padding-bottom: 0;">' . "\n";
428
  echo "\t\t" . ' <table>' . "\n";
429
 
430
+ echo "\t\t" . ' <tr valign="top"><th valign="middle" style="text-align: right;" scope="row">First Product</th><td style="text-align: left;">' . "\n";
431
+ echo "\t\t" . ' <input name="' . self::SLUG_PREFIX . self::INPUT_FIRST_PRODUCT . '" type="text" size="5" value="' . self::$first_product . '">' . "\n";
432
  echo "\t\t" . ' </td></tr>' . "\n";
433
+
434
+ echo "\t\t" . ' <tr valign="top"><th valign="middle" style="text-align: right;" scope="row">Last Product</th><td style="text-align: left;">' . "\n";
435
+ echo "\t\t" . ' <input name="' . self::SLUG_PREFIX . self::INPUT_LAST_PRODUCT . '" type="text" size="5" value="' . self::$last_product . '">' . "\n";
436
  echo "\t\t" . ' </td></tr>' . "\n";
437
+
438
  foreach ( $setting_actions as $label => $action ) {
439
+ if ( isset( $action['open'] ) ) {
440
+ echo "\t\t" . ' <tr><td colspan=2 style="padding: 2px 0px;">' . "\n";
441
+ echo "\t\t" . ' ' . $action['open'] . "\n";
442
+ } elseif ( isset( $action['continue'] ) ) {
443
+ echo "\t\t" . ' ' . $action['continue'] . "\n";
444
+ } elseif ( isset( $action['close'] ) ) {
445
+ echo "\t\t" . ' ' . $action['close'] . "\n";
446
  echo "\t\t" . ' </td></tr>' . "\n";
447
+ } else {
448
+ if ( empty( $action['handler'] ) ) {
449
+ echo "\t\t" . ' <tr><td colspan=2 style="padding: 2px 0px;">' . $action['comment'] . "</td></tr>\n";
450
+ } else {
451
+ echo "\t\t" . ' <tr><td width="160px">' . "\n";
452
+ echo "\t\t" . ' <input name="' . self::SLUG_PREFIX . 'action" type="submit" class="button-primary" style="width: 150px;" value="' . $label . '" />&nbsp;&nbsp;' . "\n";
453
+ echo "\t\t" . ' </td><td>' . "\n";
454
+ echo "\t\t" . ' ' . $action['comment'] . "\n";
455
+ echo "\t\t" . ' </td></tr>' . "\n";
456
+ }
457
  }
458
  }
459
+
460
  echo "\t\t" . ' </table>' . "\n";
461
  echo "\t\t" . ' </p>' . "\n";
462
  echo "\t\t" . '</form>' . "\n";
489
  *
490
  * @since 1.00
491
  *
492
+ * @param boolean $build_pa Optional. Build the product_attachments array. Default: true.
493
  */
494
+ private static function _build_product_attachments( $build_pa = true ) {
495
  global $wpdb;
496
+
497
+ if ( ! empty( self::$first_product ) ) {
498
+ $lower_bound = (integer) self::$first_product;
 
 
 
 
499
  } else {
500
  $lower_bound = 0;
501
  }
502
 
503
+ if ( ! empty( self::$last_product ) ) {
504
+ $upper_bound = (integer) self::$last_product;
505
  } elseif ( $lower_bound ) {
506
  $upper_bound = $lower_bound;
507
  } else {
508
  $upper_bound = 0x7FFFFFFF;
509
  }
510
 
511
+ $query = sprintf( 'SELECT m.*, p.post_title FROM %1$s as m INNER JOIN %2$s as p ON m.post_id = p.ID WHERE ( p.post_type = \'product\' ) AND ( p.ID >= %3$d ) AND ( p.ID <= %4$d) AND ( m.meta_key IN ( \'_product_image_gallery\', \'_thumbnail_id\' ) ) GROUP BY m.post_id, m.meta_id ORDER BY m.post_id', $wpdb->postmeta, $wpdb->posts, $lower_bound, $upper_bound );
512
+ $results = $wpdb->get_results( $query );
513
+ //error_log( __LINE__ . ' Woo_Fixit::_build_product_attachments() $results = ' . var_export( $results, true ), 0 );
514
+
515
  self::$product_attachments = array();
516
  self::$attachment_products = array();
517
 
518
  foreach ( $results as $result ) {
519
+ if ( $build_pa ) {
520
+ self::$product_attachments[ $result->post_id ]['post_title'] = trim( $result->post_title );
521
+ self::$product_attachments[ $result->post_id ][ $result->meta_key ] = trim( $result->meta_value );
522
  }
523
+
 
 
524
  if ( '_thumbnail_id' == $result->meta_key ) {
525
  $key = (integer) $result->meta_value;
526
  if ( isset( self::$attachment_products[ $key ] ) ) {
539
  }
540
  }
541
  }
542
+ //error_log( __LINE__ . ' Woo_Fixit::_build_product_attachments() self::$product_attachments = ' . var_export( self::$product_attachments, true ), 0 );
543
+ //error_log( __LINE__ . ' Woo_Fixit::_build_product_attachments() self::$attachment_products = ' . var_export( self::$attachment_products, true ), 0 );
544
  } // _build_product_attachments
545
 
546
  /**
552
  */
553
  private static function _clear_title() {
554
  global $wpdb;
555
+
556
  $results = $wpdb->query( "UPDATE {$wpdb->posts} SET post_title = '' WHERE post_type = 'attachment'" );
557
+ return "_clear_title() performed {$results} update(s).\n";
558
  } // _clear_title
559
 
560
  /**
566
  */
567
  private static function _fill_title() {
568
  global $wpdb;
569
+
570
  $query = sprintf( 'SELECT m.post_id, m.meta_value FROM %1$s as m INNER JOIN %2$s as p ON m.post_id = p.ID WHERE ( p.post_title = \'\' ) AND ( p.post_type = \'attachment\' ) AND ( m.meta_key IN ( \'_wp_attached_file\' ) )', $wpdb->postmeta, $wpdb->posts );
571
  $results = $wpdb->get_results( $query );
572
+
573
  $update_count = 0;
574
  $select_bits = '';
575
  $where_bits = array();
579
  $new_title = str_replace( array( '-', '_', '.' ), ' ', $path_info['filename'] );
580
  $select_bits .= " WHEN ID = {$result->post_id} THEN '{$new_title}'";
581
  $where_bits[] = $result->post_id;
582
+
583
  /*
584
  * Run an update when the chunk is full
585
  */
593
  $chunk_count = 0;
594
  }
595
  }
596
+
597
  /*
598
  * Run a final update if the chunk is partially filled
599
  */
604
  $update_count += $chunk_count;
605
  }
606
 
607
+ return "_fill_title() performed {$update_count} update(s).\n";
608
  } // _fill_title
609
 
610
  /**
616
  */
617
  private static function _replace_title() {
618
  global $wpdb;
619
+
620
  $query = sprintf( 'SELECT m.post_id, m.meta_value FROM %1$s as m INNER JOIN %2$s as p ON m.post_id = p.ID WHERE ( p.post_mime_type LIKE \'%3$s\' ) AND ( p.post_type = \'attachment\' ) AND ( m.meta_key IN ( \'_wp_attached_file\' ) )', $wpdb->postmeta, $wpdb->posts, 'image/%' );
621
  $results = $wpdb->get_results( $query );
622
+
623
  $update_count = 0;
624
  $select_bits = '';
625
  $where_bits = array();
629
  $new_title = str_replace( array( '-', '_', '.' ), ' ', $path_info['filename'] );
630
  $select_bits .= " WHEN ID = {$result->post_id} THEN '{$new_title}'";
631
  $where_bits[] = $result->post_id;
632
+
633
  /*
634
  * Run an update when the chunk is full
635
  */
643
  $chunk_count = 0;
644
  }
645
  }
646
+
647
  /*
648
  * Run a final update if the chunk is partially filled
649
  */
654
  $update_count += $chunk_count;
655
  }
656
 
657
+ return "_replace_title() performed {$update_count} update(s).\n";
658
  } // _replace_title
659
 
660
  /**
666
  */
667
  private static function _clear_alt_text() {
668
  global $wpdb;
669
+
670
  self::_build_product_attachments();
671
  ksort( self::$attachment_products );
672
  $update_count = 0;
676
  $query_result = $wpdb->query( $delete_query );
677
  $update_count += $query_result;
678
  }
679
+
680
+ return "_clear_alt_text() performed {$update_count} delete(s).\n";
681
  } // _clear_alt_text
682
 
683
  /**
689
  */
690
  private static function _fill_alt_text() {
691
  global $wpdb;
692
+
693
  self::_build_product_attachments();
694
  $delete_count = 0;
695
  $insert_count = 0;
696
  foreach ( array_chunk( self::$product_attachments, 25, true ) as $chunk ) {
697
  $terms = wp_get_object_terms( array_keys( $chunk ), 'product_cat', array( 'orderby' => 'name', 'fields' => 'all_with_object_id' ) );
698
 
699
+ if ( empty( $terms ) ) {
700
+ continue;
701
+ }
702
+
703
  /*
704
  * Build an array of "first product category" names
705
  */
731
  if ( ! empty( $value['_thumbnail_id'] ) ) {
732
  $attachment_values[ $value['_thumbnail_id'] ] = $product_terms[ $key ]['name'];
733
  }
734
+
735
  if ( ! empty( $value['_product_image_gallery'] ) ) {
736
  $ids = explode( ',', $value['_product_image_gallery'] );
737
  foreach( $ids as $id ) {
754
  }
755
  unset( $attachment_values[ (integer) $existing_value->post_id ] );
756
  }
757
+
758
  /*
759
  * Delete empty ALT Text values
760
  */
764
  $query_result = $wpdb->query( $delete_query );
765
  $delete_count += $query_result;
766
  }
767
+
768
  /*
769
  * Insert the new values
770
  */
775
  $insert_count += $query_result;
776
  }
777
  }
778
+
779
+ return "_fill_alt_text() performed {$delete_count} delete(s), {$insert_count} inserts(s).\n";
780
  } // _fill_alt_text
781
 
782
  /**
788
  */
789
  private static function _replace_alt_text() {
790
  global $wpdb;
791
+
792
  self::_build_product_attachments();
793
  $delete_count = 0;
794
  $insert_count = 0;
795
  foreach ( array_chunk( self::$product_attachments, 25, true ) as $chunk ) {
796
  $terms = wp_get_object_terms( array_keys( $chunk ), 'product_cat', array( 'orderby' => 'name', 'fields' => 'all_with_object_id' ) );
797
 
798
+ if ( empty( $terms ) ) {
799
+ continue;
800
+ }
801
+
802
  /*
803
  * Build an array of "first product category" names
804
  */
826
  if ( isset( $value['_thumbnail_id'] ) ) {
827
  $attachment_values[ $value['_thumbnail_id'] ] = $product_terms[ $key ]['name'];
828
  }
829
+
830
+ if ( isset( $value['_product_image_gallery'] ) ) {
831
  $ids = explode( ',', $value['_product_image_gallery'] );
832
  foreach( $ids as $id ) {
833
  $attachment_values[ $id ] = $product_terms[ $key ]['name'];
842
  $delete_query = "DELETE FROM {$wpdb->postmeta} WHERE ( post_id IN ( {$keys} ) ) AND ( meta_key = '_wp_attachment_image_alt' )";
843
  $query_result = $wpdb->query( $delete_query );
844
  $delete_count += $query_result;
845
+
846
+ /*
847
+ * Insert the new values
848
+ */
849
+ foreach ( $attachment_values as $attachment => $text ) {
850
+ $insert_query = "INSERT INTO {$wpdb->postmeta} ( `post_id`,`meta_key`,`meta_value` )
851
+ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
852
+ $query_result = $wpdb->query( $insert_query );
853
+ $insert_count += $query_result;
854
+ }
855
+ }
856
+
857
+ return "_replace_alt_text() performed {$delete_count} delete(s), {$insert_count} inserts(s).\n";
858
+ } // _replace_alt_text
859
+
860
+ /**
861
+ * Fill empty ALT Text field with Product Title
862
+ *
863
+ * @since 1.20
864
+ *
865
+ * @return string HTML markup for results/messages
866
+ */
867
+ private static function _fill_alt_text_t() {
868
+ global $wpdb;
869
+
870
+ self::_build_product_attachments();
871
+ $delete_count = 0;
872
+ $insert_count = 0;
873
+ foreach ( array_chunk( self::$product_attachments, 25, true ) as $chunk ) {
874
+ /*
875
+ * Assign the Product Title to each attachment
876
+ */
877
+ $attachment_values = array();
878
+ foreach ( $chunk as $key => $value ) {
879
+ if ( ! empty( $value['_thumbnail_id'] ) ) {
880
+ $attachment_values[ $value['_thumbnail_id'] ] = $value['post_title'];
881
+ }
882
+
883
+ if ( ! empty( $value['_product_image_gallery'] ) ) {
884
+ $ids = explode( ',', $value['_product_image_gallery'] );
885
+ foreach( $ids as $id ) {
886
+ $attachment_values[ $id ] = $value['post_title'];
887
+ }
888
+ }
889
+ }
890
 
891
+ /*
892
+ * Find the existing ALT Text values and remove them from the update
893
+ */
894
+ $keys = implode( ',', array_keys( $attachment_values ) );
895
+ $select_query = "SELECT post_id, meta_value FROM {$wpdb->postmeta} WHERE ( post_id IN ( {$keys} ) ) AND ( meta_key = '_wp_attachment_image_alt' )";
896
+ $empty_values = array();
897
+ foreach( $wpdb->get_results( $select_query ) as $existing_value ) {
898
+ $trim = trim( $existing_value->meta_value );
899
+ if ( empty( $trim ) ) {
900
+ $empty_values[] = $existing_value->post_id;
901
+ continue;
902
+ }
903
+ unset( $attachment_values[ (integer) $existing_value->post_id ] );
904
+ }
905
+
906
+ /*
907
+ * Delete empty ALT Text values
908
+ */
909
+ if ( ! empty( $empty_values ) ) {
910
+ $keys = implode( ',', $empty_values );
911
+ $delete_query = "DELETE FROM {$wpdb->postmeta} WHERE ( post_id IN ( {$keys} ) ) AND ( meta_key = '_wp_attachment_image_alt' )";
912
+ $query_result = $wpdb->query( $delete_query );
913
+ $delete_count += $query_result;
914
+ }
915
+
916
  /*
917
  * Insert the new values
918
  */
923
  $insert_count += $query_result;
924
  }
925
  }
926
+
927
+ return "_fill_alt_text_t() performed {$delete_count} delete(s), {$insert_count} inserts(s).\n";
928
+ } // _fill_alt_text_t
929
 
930
+ /**
931
+ * Replace ALL ALT Text field with Product Title
932
+ *
933
+ * @since 1.20
934
+ *
935
+ * @return string HTML markup for results/messages
936
+ */
937
+ private static function _replace_alt_text_t() {
938
+ global $wpdb;
939
+
940
+ self::_build_product_attachments();
941
+ $delete_count = 0;
942
+ $insert_count = 0;
943
+ foreach ( array_chunk( self::$product_attachments, 25, true ) as $chunk ) {
944
+ /*
945
+ * Assign the Product Title to each attachment
946
+ */
947
+ $attachment_values = array();
948
+ foreach ( $chunk as $key => $value ) {
949
+ if ( isset( $value['_thumbnail_id'] ) ) {
950
+ $attachment_values[ $value['_thumbnail_id'] ] = $value['post_title'];
951
+ }
952
+
953
+ if ( isset( $value['_product_image_gallery'] ) ) {
954
+ $ids = explode( ',', $value['_product_image_gallery'] );
955
+ foreach( $ids as $id ) {
956
+ $attachment_values[ $id ] = $value['post_title'];
957
+ }
958
+ }
959
+ }
960
+
961
+ /*
962
+ * Remove the old ALT Text values
963
+ */
964
+ $keys = implode( ',', array_keys( $attachment_values ) );
965
+ $delete_query = "DELETE FROM {$wpdb->postmeta} WHERE ( post_id IN ( {$keys} ) ) AND ( meta_key = '_wp_attachment_image_alt' )";
966
+ $query_result = $wpdb->query( $delete_query );
967
+ $delete_count += $query_result;
968
+
969
+ /*
970
+ * Insert the new values
971
+ */
972
+ foreach ( $attachment_values as $attachment => $text ) {
973
+ $insert_query = "INSERT INTO {$wpdb->postmeta} ( `post_id`,`meta_key`,`meta_value` )
974
+ VALUES ( {$attachment},'_wp_attachment_image_alt','{$text}' )";
975
+ $query_result = $wpdb->query( $insert_query );
976
+ $insert_count += $query_result;
977
+ }
978
+ }
979
+
980
+ return "_replace_alt_text_t() performed {$delete_count} delete(s), {$insert_count} inserts(s).\n";
981
+ } // _replace_alt_text_t
982
+
983
+ /**
984
+ * Fill empty item Title field with Product Title
985
+ *
986
+ * @since 1.20
987
+ *
988
+ * @return string HTML markup for results/messages
989
+ */
990
+ private static function _fill_title_t() {
991
+ global $wpdb;
992
+
993
+ self::_build_product_attachments();
994
+ $update_count = 0;
995
+ foreach ( array_chunk( self::$product_attachments, 25, true ) as $chunk ) {
996
+ /*
997
+ * Assign the Product Title to each attachment
998
+ */
999
+ $attachment_values = array();
1000
+ foreach ( $chunk as $key => $value ) {
1001
+ if ( ! empty( $value['_thumbnail_id'] ) ) {
1002
+ $attachment_values[ $value['_thumbnail_id'] ] = $value['post_title'];
1003
+ }
1004
+
1005
+ if ( ! empty( $value['_product_image_gallery'] ) ) {
1006
+ $ids = explode( ',', $value['_product_image_gallery'] );
1007
+ foreach( $ids as $id ) {
1008
+ $attachment_values[ $id ] = $value['post_title'];
1009
+ }
1010
+ }
1011
+ }
1012
+
1013
+ /*
1014
+ * Find the non-empty Title values and remove them from the update
1015
+ */
1016
+ $keys = implode( ',', array_keys( $attachment_values ) );
1017
+ $select_query = "SELECT ID, post_title FROM {$wpdb->posts} WHERE ( ID IN ( {$keys} ) )";
1018
+ //error_log( __LINE__ . ' Woo_Fixit::_fill_title_t() $select_query = ' . var_export( $select_query, true ), 0 );
1019
+ //error_log( __LINE__ . ' Woo_Fixit::_fill_title_t() get_results = ' . var_export( $wpdb->get_results( $select_query ), true ), 0 );
1020
+ foreach( $wpdb->get_results( $select_query ) as $existing_value ) {
1021
+ $trim = trim( $existing_value->post_title );
1022
+ if ( ! empty( $trim ) ) {
1023
+ unset( $attachment_values[ (integer) $existing_value->ID ] );
1024
+ }
1025
+ }
1026
+
1027
+ /*
1028
+ * Update with new values, if any
1029
+ */
1030
+ if ( empty( $attachment_values ) ) {
1031
+ continue;
1032
+ }
1033
+
1034
+ $select_bits = '';
1035
+ $where_bits = array();
1036
+ foreach ( $attachment_values as $attachment => $text ) {
1037
+ $select_bits .= " WHEN ID = {$attachment} THEN '{$text}'";
1038
+ $where_bits[] = $attachment;
1039
+ }
1040
+
1041
+ $where_bits = implode( ',', $where_bits );
1042
+ $update_query = "UPDATE {$wpdb->posts} SET post_title = CASE{$select_bits} ELSE post_title END WHERE ID IN ( {$where_bits} )";
1043
+ $query_result = $wpdb->query( $update_query );
1044
+ $update_count += absint( $query_result );
1045
+ } // foreach $chunk
1046
+
1047
+ return "_fill_title_t() performed performed {$update_count} update(s).\n";
1048
+ } // _fill_title_t
1049
+
1050
+ /**
1051
+ * Replace ALL item Title field with Product Title
1052
+ *
1053
+ * @since 1.20
1054
+ *
1055
+ * @return string HTML markup for results/messages
1056
+ */
1057
+ private static function _replace_title_t() {
1058
+ global $wpdb;
1059
+
1060
+ self::_build_product_attachments();
1061
+ $update_count = 0;
1062
+ foreach ( array_chunk( self::$product_attachments, 25, true ) as $chunk ) {
1063
+ /*
1064
+ * Assign the Product Title to each attachment
1065
+ */
1066
+ $attachment_values = array();
1067
+ foreach ( $chunk as $key => $value ) {
1068
+ if ( isset( $value['_thumbnail_id'] ) ) {
1069
+ $attachment_values[ $value['_thumbnail_id'] ] = $value['post_title'];
1070
+ }
1071
+
1072
+ if ( isset( $value['_product_image_gallery'] ) ) {
1073
+ $ids = explode( ',', $value['_product_image_gallery'] );
1074
+ foreach( $ids as $id ) {
1075
+ $attachment_values[ $id ] = $value['post_title'];
1076
+ }
1077
+ }
1078
+ }
1079
+
1080
+ /*
1081
+ * Update with new values, if any
1082
+ */
1083
+ if ( empty( $attachment_values ) ) {
1084
+ continue;
1085
+ }
1086
+ $select_bits = '';
1087
+ $where_bits = array();
1088
+ foreach ( $attachment_values as $attachment => $text ) {
1089
+ $select_bits .= " WHEN ID = {$attachment} THEN '{$text}'";
1090
+ $where_bits[] = $attachment;
1091
+ }
1092
+
1093
+ $where_bits = implode( ',', $where_bits );
1094
+ $update_query = "UPDATE {$wpdb->posts} SET post_title = CASE{$select_bits} ELSE post_title END WHERE ID IN ( {$where_bits} )";
1095
+ $query_result = $wpdb->query( $update_query );
1096
+ $update_count += absint( $query_result );
1097
+ } // foreach $chunk
1098
+
1099
+ return "_replace_title_t() performed {$update_count} update(s).\n";
1100
+ } // _replace_title_t
1101
 
1102
  /**
1103
  * Remove Product/Featured Image from the Product Gallery
1108
  */
1109
  private static function _remove_feature() {
1110
  global $wpdb;
1111
+
1112
  self::_build_product_attachments();
1113
 
1114
  $update_count = 0;
1119
  if ( empty( $result['_thumbnail_id'] ) ) {
1120
  continue;
1121
  }
1122
+
1123
  $feature = (integer) $result['_thumbnail_id'];
1124
  $gallery = array();
1125
  $feature_found = false;
1126
+
1127
  if ( ! empty( $result['_product_image_gallery'] ) ) {
1128
  foreach ( explode( ',', $result['_product_image_gallery'] ) as $item ) {
1129
  if ( $feature == (integer) $item ) {
1133
  }
1134
  } // foreach gallery item
1135
  }
1136
+
1137
  if ( $feature_found ) {
1138
  $new_gallery = implode( ',', $gallery );
1139
  $select_bits .= " WHEN post_id = {$post_id} THEN '{$new_gallery}'";
1140
  $where_bits[] = $post_id;
1141
+
1142
  /*
1143
  * Run an update when the chunk is full
1144
  */
1153
  }
1154
  } // feature removed
1155
  } // foreach product
1156
+
1157
  /*
1158
  * Run a final update if the chunk is partially filled
1159
  */
1164
  $update_count += $chunk_count;
1165
  }
1166
 
1167
+ return "_remove_feature() performed {$update_count} update(s).\n";
1168
  } // _remove_feature
1169
 
1170
  /**
1176
  */
1177
  private static function _restore_feature() {
1178
  global $wpdb;
1179
+
1180
  self::_build_product_attachments();
1181
 
1182
  $update_count = 0;
1187
  if ( empty( $result['_thumbnail_id'] ) ) {
1188
  continue;
1189
  }
1190
+
1191
  $feature = (integer) $result['_thumbnail_id'];
1192
  $gallery = array();
1193
  $feature_found = false;
1200
  }
1201
  } // foreach gallery item
1202
  }
1203
+
1204
  if ( ! $feature_found ) {
1205
  if ( count( $gallery ) ) {
1206
  $new_gallery = implode( ',', $gallery ) . ',' . $feature;
1207
  } else {
1208
  $new_gallery = (string) $feature;
1209
  }
1210
+
1211
  $select_bits .= " WHEN post_id = {$post_id} THEN '{$new_gallery}'";
1212
  $where_bits[] = $post_id;
1213
+
1214
  /*
1215
  * Run an update when the chunk is full
1216
  */
1225
  }
1226
  } // feature restored
1227
  } // foreach product
1228
+
1229
  /*
1230
  * Run a final update if the chunk is partially filled
1231
  */
1236
  $update_count += $chunk_count;
1237
  }
1238
 
1239
+ return "_restore_feature() performed {$update_count} update(s).\n";
1240
  } // _restore_feature
1241
 
1242
  /**
1248
  */
1249
  private static function _reverse_gallery() {
1250
  global $wpdb;
1251
+
1252
  self::_build_product_attachments();
1253
 
1254
  $update_count = 0;
1261
  } else {
1262
  $gallery = explode( ',', $result['_product_image_gallery'] );
1263
  }
1264
+
1265
  if ( 1 < count( $gallery ) ) {
1266
  $new_gallery = implode( ',', array_reverse( $gallery ) );
1267
  $select_bits .= " WHEN post_id = {$post_id} THEN '{$new_gallery}'";
1268
  $where_bits[] = $post_id;
1269
+
1270
  /*
1271
  * Run an update when the chunk is full
1272
  */
1281
  }
1282
  } // gallery reversed
1283
  } // foreach product
1284
+
1285
  /*
1286
  * Run a final update if the chunk is partially filled
1287
  */
1292
  $update_count += $chunk_count;
1293
  }
1294
 
1295
+ return "_reverse_gallery() performed {$update_count} update(s).\n";
1296
  } // _reverse_gallery
1297
 
1298
+ /**
1299
+ * Replace "where_used" information in custom field "Woo Used In".
1300
+ *
1301
+ * @since 1.24
1302
+ *
1303
+ * @return string HTML markup for results/messages
1304
+ */
1305
+ private static function _where_used() {
1306
+ global $wpdb;
1307
+
1308
+ $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->postmeta} LEFT JOIN {$wpdb->posts} ON ( {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id ) WHERE {$wpdb->postmeta}.meta_key = '%s' AND {$wpdb->posts}.post_type = 'attachment'", 'Woo Used In' ));
1309
+
1310
+ if ( $delete_count = count( $post_meta_ids ) ) {
1311
+ foreach ( $post_meta_ids as $mid ) {
1312
+ delete_metadata_by_mid( 'post', $mid );
1313
+ }
1314
+ }
1315
+
1316
+ self::_build_product_attachments();
1317
+
1318
+ $insert_count = 0;
1319
+ $thumbnail_count = 0;
1320
+ $gallery_count = 0;
1321
+ foreach( self::$attachment_products as $post_id => $result ) {
1322
+ if ( empty( $result['_thumbnail_id'] ) ) {
1323
+ $thumbnails = array();
1324
+ } else {
1325
+ $thumbnails = $result['_thumbnail_id'];
1326
+ }
1327
+
1328
+ if ( empty( $result['_product_image_gallery'] ) ) {
1329
+ $galleries = array();
1330
+ } else {
1331
+ $galleries = $result['_product_image_gallery'];
1332
+ }
1333
+
1334
+ /*
1335
+ * Compose references
1336
+ */
1337
+ $references = '';
1338
+ $thumbnail_text = '';
1339
+ foreach ( $thumbnails as $thumbnail ) {
1340
+ $thumbnail_text .= sprintf( '(%1$d) %2$s,', $thumbnail, self::$product_attachments[ $thumbnail ]['post_title'] );
1341
+ }
1342
+ if ( !empty( $thumbnail_text ) ) {
1343
+ $references .= 'Thumbnails: ' . $thumbnail_text;
1344
+ }
1345
+
1346
+ $gallery_text = '';
1347
+ foreach ( $galleries as $gallery ) {
1348
+ $gallery_text .= sprintf( '(%1$d) %2$s,', $gallery, self::$product_attachments[ $gallery ]['post_title'] );
1349
+ }
1350
+ if ( !empty( $gallery_text ) ) {
1351
+ if ( !empty( $references ) ) {
1352
+ $references .= '; ';
1353
+ }
1354
+
1355
+ $references .= 'Galleries: ' . $gallery_text;
1356
+ }
1357
+
1358
+ if ( !empty( $references ) ) {
1359
+ $thumbnail_count += count( $thumbnails );
1360
+ $gallery_count += count( $galleries );
1361
+
1362
+ /*
1363
+ * Insert the new values
1364
+ */
1365
+ $insert_query = "INSERT INTO {$wpdb->postmeta} ( `post_id`,`meta_key`,`meta_value` )
1366
+ VALUES ( {$post_id},'Woo Used In','{$references}' )";
1367
+ $query_result = $wpdb->query( $insert_query );
1368
+ $insert_count += $query_result;
1369
+ } // found references
1370
+ } // foreach product
1371
+
1372
+ return "_where_used() deleted {$delete_count} items(s) in &quot;Woo Used In&quot;, then inserted {$insert_count} items(s) with {$thumbnail_count} thumbnail(s) and {$gallery_count} gallery(s).\n";
1373
+ } // _where_used
1374
+
1375
  /**
1376
  * Delete ALL Products' Product Tags assignments where a Product Image exists
1377
  *
1430
  */
1431
  private static function _update_product_tags( $action ) {
1432
  global $wpdb;
1433
+
1434
  self::_build_product_attachments();
1435
 
1436
  $update_count = 0;
1451
  if ( count( $products ) == 0 ) {
1452
  continue;
1453
  }
1454
+
1455
  switch ( $action ) {
1456
  case 'clear':
1457
  case 'fill':
1459
  $ids = implode( ',', array_keys( $products ) );
1460
  $query = sprintf( 'SELECT DISTINCT tr.object_id FROM %1$s as tr INNER JOIN %2$s as tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE ( tr.object_id IN ( %3$s ) AND tt.taxonomy = \'product_tag\' ) ', $wpdb->term_relationships, $wpdb->term_taxonomy, $ids );
1461
  $assignments = $wpdb->get_col( $query );
1462
+
1463
  if ( 'clear' == $action ) {
1464
  foreach ( $assignments as $assignment ) {
1465
  wp_delete_object_term_relationships( $assignment, 'product_tag' );
1468
  } else {
1469
  // Find the products that have no assignments
1470
  $assignments = array_diff_key( $products, array_flip( $assignments ) );
1471
+
1472
  foreach ( $assignments as $product_id => $assignment ) {
1473
  $attachment_tags = wp_get_object_terms( $assignment, 'attachment_tag', array( 'orderby' => 'none', 'fields' => 'names' ) );
1474
+
1475
  if ( ! empty( $attachment_tags ) ) {
1476
  $term_taxonomy_ids = wp_set_object_terms( $product_id, $attachment_tags, 'product_tag' );
1477
  $terms_added += count( $term_taxonomy_ids );
1484
  case 'replace':
1485
  foreach ( $products as $product_id => $assignment ) {
1486
  $attachment_tags = wp_get_object_terms( $assignment, 'attachment_tag', array( 'orderby' => 'none', 'fields' => 'names' ) );
1487
+
1488
  if ( 'append' == $action ) {
1489
  if ( ! empty( $attachment_tags ) ) {
1490
  $old_term_taxonomy_ids = wp_get_object_terms( $product_id, 'product_tag', array( 'orderby' => 'none', 'fields' => 'tt_ids' ) );
1505
  }
1506
  } else {
1507
  $term_taxonomy_ids = wp_get_object_terms( $product_id, 'product_tag', array( 'orderby' => 'none', 'fields' => 'tt_ids' ) );
1508
+
1509
  $old_terms = count( $term_taxonomy_ids );
1510
  if ( 0 < $old_terms ) {
1511
  $terms_removed += $old_terms;
1517
  } // each assignment
1518
  } // action
1519
  } // each chunk
1520
+
1521
  switch ( $action ) {
1522
  case 'clear':
1523
+ return "_clear_product_tags() cleared {$update_count} Product(s).\n";
1524
  break;
1525
  case 'fill':
1526
+ return "_fill_product_tags() added {$terms_added} term(s) to {$update_count} Product(s).\n";
1527
  break;
1528
  case 'append':
1529
+ return "_append_product_tags() added {$terms_added} term(s) to {$update_count} Product(s).\n";
1530
  break;
1531
  case 'replace':
1532
+ return "_replace_product_tags() replaced {$terms_added} term(s) in {$update_count} Product(s), and deleted {$terms_removed} term(s) from {$delete_count} Product(s).\n";
1533
  }
1534
+
1535
+ return "ERROR: Unknown _update_product_tags action: {$action}";
1536
+ } // _update_product_tags
1537
 
1538
  /**
1539
  * Delete ALL Products' Product Categories assignments where a Product Image exists
1593
  */
1594
  private static function _update_product_categories( $action ) {
1595
  global $wpdb;
1596
+
1597
  self::_build_product_attachments();
1598
 
1599
  if ( 'clear' != $action ) {
1621
  if ( count( $products ) == 0 ) {
1622
  continue;
1623
  }
1624
+
1625
  switch ( $action ) {
1626
  case 'clear':
1627
  case 'fill':
1629
  $ids = implode( ',', array_keys( $products ) );
1630
  $query = sprintf( 'SELECT DISTINCT tr.object_id FROM %1$s as tr INNER JOIN %2$s as tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE ( tr.object_id IN ( %3$s ) AND tt.taxonomy = \'product_cat\' ) ', $wpdb->term_relationships, $wpdb->term_taxonomy, $ids );
1631
  $assignments = $wpdb->get_col( $query );
1632
+
1633
  if ( 'clear' == $action ) {
1634
  foreach ( $assignments as $assignment ) {
1635
  wp_delete_object_term_relationships( $assignment, 'product_cat' );
1638
  } else {
1639
  // Find the products that have no assignments
1640
  $assignments = array_diff_key( $products, array_flip( $assignments ) );
1641
+
1642
  foreach ( $assignments as $product_id => $assignment ) {
1643
  $attachment_tags = wp_get_object_terms( $assignment, 'attachment_tag', array( 'orderby' => 'none', 'fields' => 'names' ) );
1644
  $common_terms = array_keys( array_intersect( $product_categories, $attachment_tags ) );
1645
+
1646
  if ( ! empty( $common_terms ) ) {
1647
  $term_taxonomy_ids = wp_set_object_terms( $product_id, $common_terms, 'product_cat' );
1648
  $terms_added += count( $term_taxonomy_ids );
1656
  foreach ( $products as $product_id => $assignment ) {
1657
  $attachment_tags = wp_get_object_terms( $assignment, 'attachment_tag', array( 'orderby' => 'none', 'fields' => 'names' ) );
1658
  $common_terms = array_keys( array_intersect( $product_categories, $attachment_tags ) );
1659
+
1660
  if ( 'append' == $action ) {
1661
  if ( ! empty( $common_terms ) ) {
1662
  $old_term_taxonomy_ids = wp_get_object_terms( $product_id, 'product_cat', array( 'orderby' => 'none', 'fields' => 'tt_ids' ) );
1677
  }
1678
  } else {
1679
  $term_taxonomy_ids = wp_get_object_terms( $product_id, 'product_cat', array( 'orderby' => 'none', 'fields' => 'tt_ids' ) );
1680
+
1681
  $old_terms = count( $term_taxonomy_ids );
1682
  if ( 0 < $old_terms ) {
1683
  $terms_removed += $old_terms;
1689
  } // each assignment
1690
  } // action
1691
  } // each chunk
1692
+
1693
  switch ( $action ) {
1694
  case 'clear':
1695
+ return "_clear_product_categories() cleared {$update_count} Product(s).\n";
1696
  break;
1697
  case 'fill':
1698
+ return "_fill_product_categories() added {$terms_added} term(s) to {$update_count} Product(s).\n";
1699
  break;
1700
  case 'append':
1701
+ return "_append_product_categories() added {$terms_added} term(s) to {$update_count} Product(s).\n";
1702
  break;
1703
  case 'replace':
1704
+ return "_replace_product_categories() replaced {$terms_added} term(s) in {$update_count} Product(s), and deleted {$terms_removed} term(s) from {$delete_count} Product(s).\n";
1705
  }
1706
+
1707
+ return "ERROR: Unknown _update_product_categories action: {$action}";
1708
  } // _update_product_categories
1709
 
1710
  /**
1716
  */
1717
  private static function _clear_attachment_categories() {
1718
  global $wpdb;
1719
+
1720
  $update_count = 0;
1721
  $offset = 0;
1722
  $limit = 25;
1723
+
1724
  do {
1725
  // Select a chunk of attachment IDs
1726
  $query = sprintf( 'SELECT p.ID FROM %1$s as p WHERE ( p.post_type = \'attachment\' ) ORDER BY p.ID LIMIT %2$d, %3$d', $wpdb->posts, $offset, $limit );
1739
  } else {
1740
  $results = array();
1741
  }
1742
+
1743
  $offset += $limit;
1744
  } while ( count( $results ) == $limit );
1745
+
1746
+ return "_clear_attachment_categories() cleared {$update_count} items(s).\n";
1747
  } // _clear_attachment_categories
1748
 
1749
  /**
1756
  */
1757
  private static function _fill_attachment_categories() {
1758
  global $wpdb;
1759
+
1760
  // Get the array of the Att. Category term objects for comparison
1761
  $attachment_categories = get_terms( 'attachment_category', array( 'orderby' => 'none', 'hide_empty' => 0, 'fields' => 'id=>name' ) );
1762
 
1764
  $terms_added = 0;
1765
  $offset = 0;
1766
  $limit = 25;
1767
+
1768
  do {
1769
  // Select a chunk of attachment IDs
1770
  $query = sprintf( 'SELECT p.ID FROM %1$s as p WHERE ( p.post_type = \'attachment\' ) ORDER BY p.ID LIMIT %2$d, %3$d', $wpdb->posts, $offset, $limit );
1775
  $ids = implode( ',', $results );
1776
  $query = sprintf( 'SELECT DISTINCT tr.object_id FROM %1$s as tr INNER JOIN %2$s as tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE ( tr.object_id IN ( %3$s ) AND tt.taxonomy = \'attachment_category\' ) ', $wpdb->term_relationships, $wpdb->term_taxonomy, $ids );
1777
  $assignments = $wpdb->get_col( $query );
1778
+
1779
  // find the attachments that have no assignments
1780
  $assignments = array_diff( $results, $assignments );
1781
 
1791
  } else {
1792
  $results = array();
1793
  }
1794
+
1795
  $offset += $limit;
1796
  } while ( count( $results ) == $limit );
1797
 
1798
+ return "_fill_attachment_categories() added {$terms_added} term(s) to {$update_count} item(s).\n";
1799
  } // _fill_attachment_categories
1800
 
1801
  /**
1808
  */
1809
  private static function _append_attachment_categories() {
1810
  global $wpdb;
1811
+
1812
  // Get the array of the Att. Category term objects for comparison
1813
  $attachment_categories = get_terms( 'attachment_category', array( 'orderby' => 'none', 'hide_empty' => 0, 'fields' => 'id=>name' ) );
1814
 
1816
  $terms_added = 0;
1817
  $offset = 0;
1818
  $limit = 25;
1819
+
1820
  do {
1821
  // Select a chunk of attachment IDs
1822
  $query = sprintf( 'SELECT p.ID FROM %1$s as p WHERE ( p.post_type = \'attachment\' ) ORDER BY p.ID LIMIT %2$d, %3$d', $wpdb->posts, $offset, $limit );
1827
  $ids = implode( ',', $results );
1828
  $query = sprintf( 'SELECT DISTINCT tr.object_id FROM %1$s as tr INNER JOIN %2$s as tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE ( tr.object_id IN ( %3$s ) AND tt.taxonomy = \'attachment_tag\' ) ', $wpdb->term_relationships, $wpdb->term_taxonomy, $ids );
1829
  $assignments = $wpdb->get_col( $query );
1830
+
1831
  foreach ( $assignments as $assignment ) {
1832
  $attachment_tags = wp_get_object_terms( $assignment, 'attachment_tag', array( 'orderby' => 'none', 'fields' => 'names' ) );
1833
  $common_terms = array_keys( array_intersect( $attachment_categories, $attachment_tags ) );
1845
  } else {
1846
  $results = array();
1847
  }
1848
+
1849
  $offset += $limit;
1850
  } while ( count( $results ) == $limit );
1851
 
1852
+ return "_append_attachment_categories() added {$terms_added} term(s) to {$update_count} item(s).\n";
1853
  } // _append_attachment_categories
1854
 
1855
  /**
1862
  */
1863
  private static function _replace_attachment_categories() {
1864
  global $wpdb;
1865
+
1866
  // Get the array of the Att. Category term objects for comparison
1867
  $attachment_categories = get_terms( 'attachment_category', array( 'orderby' => 'none', 'hide_empty' => 0, 'fields' => 'id=>name' ) );
1868
 
1873
 
1874
  $offset = 0;
1875
  $limit = 25;
1876
+
1877
  do {
1878
  // Select a chunk of attachment IDs
1879
  $query = sprintf( 'SELECT p.ID FROM %1$s as p WHERE ( p.post_type = \'attachment\' ) ORDER BY p.ID LIMIT %2$d, %3$d', $wpdb->posts, $offset, $limit );
1904
  } else {
1905
  $results = array();
1906
  }
1907
+
1908
  $offset += $limit;
1909
  } while ( count( $results ) == $limit );
1910
 
1911
+ return "_replace_attachment_categories() replaced {$terms_added} term(s) in {$update_count} item(s), and deleted {$terms_removed} term(s) from {$delete_count} item(s).\n";
1912
  } // _replace_attachment_categories
1913
+
1914
+ /**
1915
+ * Delete ALL product_category and/or product_tag term assignments
1916
+ * for Media Library items.
1917
+ *
1918
+ * @since 1.26
1919
+ *
1920
+ * @return string HTML markup for results/messages
1921
+ */
1922
+ private static function _clear_term_assignments() {
1923
+ self::_build_product_attachments( false );
1924
+
1925
+ $item_count = 0;
1926
+ $cat_count = 0;
1927
+ $cat_removed = 0;
1928
+ $tag_count = 0;
1929
+ $tag_removed = 0;
1930
+
1931
+ foreach ( self::$attachment_products as $ID => $used_in ) {
1932
+ $item_count++;
1933
+
1934
+ if ( self::$process_category ) {
1935
+ $term_taxonomy_ids = wp_get_object_terms( $ID, 'product_cat', array( 'orderby' => 'none', 'fields' => 'tt_ids' ) );
1936
+ $old_terms = count( $term_taxonomy_ids );
1937
+ if ( 0 < $old_terms ) {
1938
+ $cat_removed += $old_terms;
1939
+ $cat_count++;
1940
+ $term_taxonomy_ids = wp_set_object_terms( $ID, NULL, 'product_cat' );
1941
+ }
1942
+ }
1943
+
1944
+ if ( self::$process_tag ) {
1945
+ $term_taxonomy_ids = wp_get_object_terms( $ID, 'product_tag', array( 'orderby' => 'none', 'fields' => 'tt_ids' ) );
1946
+ $old_terms = count( $term_taxonomy_ids );
1947
+ if ( 0 < $old_terms ) {
1948
+ $tag_removed += $old_terms;
1949
+ $tag_count++;
1950
+ $term_taxonomy_ids = wp_set_object_terms( $ID, NULL, 'product_tag' );
1951
+ }
1952
+ }
1953
+ } // foreach ID
1954
+
1955
+ $cat_text = ( 1 == $cat_removed ) ? 'category' : 'categories';
1956
+ $tag_text = ( 1 == $tag_removed ) ? 'tag' : 'tags';
1957
+ return "_clear_term_assignments() processed {$item_count} item(s), deleted {$cat_removed} {$cat_text} from {$cat_count} item(s), and deleted {$tag_removed} {$tag_text} from {$tag_count} item(s).\n";
1958
+ } // _clear_term_assignments
1959
+
1960
+ /**
1961
+ * Append ALL product_category and/or product_tag term assignments
1962
+ * for Media Library items.
1963
+ *
1964
+ * @since 1.26
1965
+ *
1966
+ * @return string HTML markup for results/messages
1967
+ */
1968
+ private static function _copy_term_assignments() {
1969
+ self::_build_product_attachments( false );
1970
+
1971
+ $item_count = 0;
1972
+ $cat_count = 0;
1973
+ $cat_added = 0;
1974
+ $tag_count = 0;
1975
+ $tag_added = 0;
1976
+
1977
+ $current_product_cat = array();
1978
+ $current_product_tag = array();
1979
+
1980
+ foreach ( self::$attachment_products as $ID => $used_in ) {
1981
+ $item_count++;
1982
+
1983
+ if ( self::$process_category ) {
1984
+ $current_product_cat = wp_get_object_terms( $ID, 'product_cat', array( 'orderby' => 'none', 'fields' => 'tt_ids' ) );
1985
+ }
1986
+
1987
+ if ( self::$process_tag ) {
1988
+ $current_product_tag = wp_get_object_terms( $ID, 'product_tag', array( 'orderby' => 'none', 'fields' => 'tt_ids' ) );
1989
+ }
1990
+
1991
+ $new_product_cat = array();
1992
+ $new_product_tag = array();
1993
+
1994
+ foreach ( $used_in as $usage => $products ) {
1995
+ foreach ( $products as $product_id ) {
1996
+ if ( self::$process_category ) {
1997
+ $term_taxonomy_ids = wp_get_object_terms( $product_id, 'product_cat', array( 'orderby' => 'none', 'fields' => 'tt_ids' ) );
1998
+ foreach( $term_taxonomy_ids as $new_cat ) {
1999
+ if ( in_array( $new_cat, $current_product_cat ) ) {
2000
+ continue;
2001
+ }
2002
+
2003
+ $new_product_cat[ $new_cat ] = $new_cat;
2004
+ }
2005
+ }
2006
+
2007
+ if ( self::$process_tag ) {
2008
+ $term_taxonomy_ids = wp_get_object_terms( $product_id, 'product_tag', array( 'orderby' => 'none', 'fields' => 'tt_ids' ) );
2009
+ foreach( $term_taxonomy_ids as $new_tag ) {
2010
+ if ( in_array( $new_tag, $current_product_tag ) ) {
2011
+ continue;
2012
+ }
2013
+
2014
+ $new_product_tag[ $new_tag ] = $new_tag;
2015
+ }
2016
+ }
2017
+ } // foreach product_id
2018
+ } // foreach usage
2019
+
2020
+ if ( 0 < ( $new_terms = count( $new_product_cat ) ) ) {
2021
+ $cat_added += $new_terms;
2022
+ $cat_count++;
2023
+ $term_taxonomy_ids = wp_set_object_terms( $ID, $new_product_cat, 'product_cat', true );
2024
+ }
2025
+
2026
+ if ( 0 < ( $new_terms = count( $new_product_tag ) ) ) {
2027
+ $tag_added += $new_terms;
2028
+ $tag_count++;
2029
+ $term_taxonomy_ids = wp_set_object_terms( $ID, $new_product_tag, 'product_tag', true );
2030
+ }
2031
+ } // foreach ID
2032
+
2033
+ $cat_text = ( 1 == $cat_added ) ? 'category' : 'categories';
2034
+ $tag_text = ( 1 == $tag_added ) ? 'tag' : 'tags';
2035
+ return "_copy_term_assignments() processed {$item_count} item(s), added {$cat_added} {$cat_text} to {$cat_count} item(s), and added {$tag_added} {$tag_text} to {$tag_count} item(s).\n";
2036
+ } // _copy_term_assignments
2037
  } //Woo_Fixit
2038
 
2039
  /*
includes/class-mla-admin-columns-support-deprecated.php ADDED
@@ -0,0 +1,220 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Media Library Assistant Admin Columns (plugin) Support
4
+ *
5
+ * @package Media Library Assistant
6
+ * @since 2.22
7
+ */
8
+ defined( 'ABSPATH' ) or die();
9
+
10
+ /**
11
+ * Class CPAC Storage Model MLA (Media Library Assistant) supports the Admin Columns plugin
12
+ *
13
+ * @package Media Library Assistant
14
+ * @since 2.22
15
+ */
16
+ class CPAC_Deprecated_Storage_Model_MLA extends CPAC_Storage_Model {
17
+ /**
18
+ * Identifies submenu entry in the Admin sidebar, e.g., Media/Assistant in Media
19
+ *
20
+ * @since 2.25
21
+ * @var string
22
+ */
23
+ public $subpage;
24
+
25
+ /**
26
+ * Initializes some properties, installs filters and then
27
+ * calls the parent constructor to set some default configs.
28
+ *
29
+ * @since 2.22
30
+ */
31
+ public function __construct() {
32
+ $this->key = 'mla-media-assistant';
33
+ $this->label = __( 'Media Library Assistant' );
34
+ $this->singular_label = __( 'Assistant' );
35
+ $this->type = 'media';
36
+ $this->meta_type = 'post';
37
+ $this->page = 'upload';
38
+ $this->subpage = MLACore::ADMIN_PAGE_SLUG;
39
+ $this->post_type = 'attachment';
40
+ $this->menu_type = 'other';
41
+
42
+ // Increased the priority to overrule 3th party plugins such as Media Tags
43
+ add_filter( 'manage_media_page_' . MLACore::ADMIN_PAGE_SLUG . '_columns', array( $this, 'add_headings' ), 100 );
44
+ add_filter( 'mla_list_table_column_default', array( $this, 'mla_manage_value' ), 100, 3 );
45
+
46
+ parent::__construct();
47
+ }
48
+
49
+ /**
50
+ * Added in Admin Columns update to v2.4.9
51
+ *
52
+ * @since 2.23
53
+ */
54
+ public function init_manage_columns() {
55
+
56
+ //add_filter( "manage_{$this->page}_columns", array( $this, 'add_headings' ), 100 );
57
+ //add_action( 'manage_comments_custom_column', array( $this, 'manage_value' ), 100, 2 );
58
+ }
59
+
60
+ /**
61
+ * Returns the Media/Assistant submenu table column definitions
62
+ *
63
+ * @since 2.22
64
+ *
65
+ * @return array ( 'column_slug' => 'column_heading' )
66
+ */
67
+ public function get_default_columns() {
68
+ if ( ! class_exists( 'MLAQuery' ) ) {
69
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-data-query.php' );
70
+ MLAQuery::initialize();
71
+ }
72
+
73
+ return apply_filters( 'mla_list_table_get_columns', MLAQuery::$default_columns );
74
+ }
75
+
76
+ /**
77
+ * Returns the Media/Assistant submenu table column slugs/keys
78
+ *
79
+ * @since 2.22
80
+ *
81
+ * @return array ( index => 'column_slug' )
82
+ */
83
+ public function get_default_column_names() {
84
+ if ( ! class_exists( 'MLAQuery' ) ) {
85
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-data-query.php' );
86
+ MLAQuery::initialize();
87
+ }
88
+
89
+ return array_keys( apply_filters( 'mla_list_table_get_columns', MLAQuery::$default_columns ) );
90
+ }
91
+
92
+ /**
93
+ * Returns the custom fields assigned to Media Library items, removing those already present
94
+ * in the Media/Assistant submenu table
95
+ *
96
+ * @since 2.22
97
+ *
98
+ * @return array ( index => array( 0 => 'custom field name' ) )
99
+ */
100
+ public function get_meta() {
101
+ global $wpdb;
102
+
103
+ /*
104
+ * Find all of the custom field names assigned to Media Library items
105
+ */
106
+ $meta = $wpdb->get_results( "SELECT DISTINCT meta_key FROM {$wpdb->postmeta} pm JOIN {$wpdb->posts} p ON pm.post_id = p.ID WHERE p.post_type = 'attachment' ORDER BY 1", ARRAY_N );
107
+
108
+ /*
109
+ * Find the fields already present in the submenu table
110
+ */
111
+ $mla_columns = apply_filters( 'mla_list_table_get_columns', MLAQuery::$default_columns );
112
+ $mla_custom = array();
113
+ foreach ( $mla_columns as $slug => $heading ) {
114
+ if ( 'c_' === substr( $slug, 0, 2 ) ) {
115
+ $mla_custom[] = $heading;
116
+ }
117
+ }
118
+
119
+ /*
120
+ * Remove the fields already present in the submenu table
121
+ */
122
+ foreach ( $meta as $index => $value ) {
123
+ if ( in_array( esc_html( current( $value ) ), $mla_custom ) ) {
124
+ unset( $meta[ $index ] );
125
+ }
126
+ }
127
+
128
+ return $meta;
129
+ }
130
+
131
+ /**
132
+ * Return the content of an Admin Columns custom column
133
+ *
134
+ * @since 2.22
135
+ *
136
+ * @param string $content Current column content (empty string)
137
+ * @param object $item Current Media Library item
138
+ * @param string $column_name Current column slug
139
+ *
140
+ * @return string Column value or NULL if not an Admin Columns custom column
141
+ */
142
+ public function mla_manage_value( $content, $item, $column_name ) {
143
+ $media_id = $item->ID;
144
+
145
+ if ( ! ( $column = $this->get_column_by_name( $column_name ) ) ) {
146
+ return null;
147
+ }
148
+
149
+ $value = $column->get_value( $media_id );
150
+
151
+ // hooks
152
+ $value = apply_filters( "cac/column/value", $value, $media_id, $column, $this->key );
153
+ $value = apply_filters( "cac/column/value/{$this->type}", $value, $media_id, $column, $this->key );
154
+
155
+ return $value;
156
+ }
157
+
158
+ /**
159
+ * Test for current screen = the Media/Assistant submenu screen,
160
+ * For Admin Columns 2.4.9+
161
+ *
162
+ * @since 2.23
163
+ *
164
+ * @return boolean true if the Media/Assistant submenu is the current screen
165
+ */
166
+ public function is_current_screen() {
167
+ $is_current_screen = parent::is_current_screen();
168
+ if ( ! $is_current_screen ) {
169
+ if ( ! empty( $_REQUEST['page'] ) && MLACore::ADMIN_PAGE_SLUG == $_REQUEST['page'] ) {
170
+ $is_current_screen = true;
171
+ }
172
+ }
173
+
174
+ return $is_current_screen;
175
+ }
176
+
177
+ /**
178
+ * Test for current screen = the Media/Assistant submenu screen
179
+ *
180
+ * @since 2.22
181
+ *
182
+ * @return boolean true if the Media/Assistant submenu is the current screen
183
+ */
184
+ public function is_columns_screen() {
185
+ $is_columns_screen = parent::is_columns_screen();
186
+ if ( ! $is_columns_screen ) {
187
+ if ( ! empty( $_REQUEST['page'] ) && MLACore::ADMIN_PAGE_SLUG == $_REQUEST['page'] ) {
188
+ $is_columns_screen = true;
189
+ }
190
+ }
191
+
192
+ return $is_columns_screen;
193
+ }
194
+
195
+ /**
196
+ * Return a link to the Media/Assistant submenu screen
197
+ *
198
+ * @since 2.22
199
+ *
200
+ * @return string Link to the Media/Assistant submenu screen
201
+ */
202
+ protected function get_screen_link() {
203
+ return is_network_admin() ? network_admin_url( $this->page . '.php?page=' . MLACore::ADMIN_PAGE_SLUG ) : admin_url( $this->page . '.php?page=' . MLACore::ADMIN_PAGE_SLUG );
204
+ }
205
+
206
+ /**
207
+ * Return a link to the Media/Assistant submenu Edit columns screen
208
+ *
209
+ * @since 2.22
210
+ *
211
+ * @return string Link to the Media/Assistant submenu Edit columns screen
212
+ */
213
+ public function get_edit_link() {
214
+ return add_query_arg( array(
215
+ 'page' => 'codepress-admin-columns',
216
+ 'cpac_key' => $this->key,
217
+ ), admin_url( 'options-general.php' ) );
218
+ }
219
+ } // class CPAC_Storage_Model_MLA
220
+
includes/class-mla-admin-columns-support.php CHANGED
@@ -13,72 +13,40 @@ defined( 'ABSPATH' ) or die();
13
  * @package Media Library Assistant
14
  * @since 2.22
15
  */
16
- class CPAC_Storage_Model_MLA extends CPAC_Storage_Model {
17
- /**
18
- * Identifies submenu entry in the Admin sidebar, e.g., Media/Assistant in Media
19
- *
20
- * @since 2.25
21
- * @var string
22
- */
23
- public $subpage;
24
 
25
  /**
26
- * Initializes some properties, installs filters and then
27
- * calls the parent constructor to set some default configs.
28
  *
29
  * @since 2.22
30
  */
31
- public function __construct() {
32
- $this->key = 'mla-media-assistant';
33
- $this->label = __( 'Media Library Assistant' );
34
- $this->singular_label = __( 'Assistant' );
35
- $this->type = 'media';
36
- $this->meta_type = 'post';
37
- $this->page = 'upload';
38
- $this->subpage = MLACore::ADMIN_PAGE_SLUG;
39
- $this->post_type = 'attachment';
40
- $this->menu_type = 'other';
41
-
42
- // Increased the priority to overrule 3th party plugins such as Media Tags
43
- add_filter( 'manage_media_page_' . MLACore::ADMIN_PAGE_SLUG . '_columns', array( $this, 'add_headings' ), 100 );
44
- add_filter( 'mla_list_table_column_default', array( $this, 'manage_value' ), 100, 3 );
45
-
46
- parent::__construct();
47
- }
48
 
49
- /**
50
- * Added in Admin Columns update to v2.4.9
51
- *
52
- * @since 2.23
53
- */
54
- public function init_manage_columns() {
55
 
56
- //add_filter( "manage_{$this->page}_columns", array( $this, 'add_headings' ), 100 );
57
- //add_action( 'manage_comments_custom_column', array( $this, 'manage_value' ), 100, 2 );
58
  }
59
 
60
  /**
61
- * Returns the Media/Assistant submenu table column definitions
62
  *
63
  * @since 2.22
64
- *
65
- * @return array ( 'column_slug' => 'column_heading' )
66
  */
67
- public function get_default_columns() {
68
- if ( ! class_exists( 'MLAQuery' ) ) {
69
- require_once( MLA_PLUGIN_PATH . 'includes/class-mla-data-query.php' );
70
- MLAQuery::initialize();
71
- }
72
-
73
- return apply_filters( 'mla_list_table_get_columns', MLAQuery::$default_columns );
74
  }
75
 
76
  /**
77
- * Returns the Media/Assistant submenu table column slugs/keys
78
  *
79
  * @since 2.22
80
  *
81
- * @return array ( index => 'column_slug' )
82
  */
83
  public function get_default_column_names() {
84
  if ( ! class_exists( 'MLAQuery' ) ) {
@@ -95,7 +63,7 @@ class CPAC_Storage_Model_MLA extends CPAC_Storage_Model {
95
  *
96
  * @since 2.22
97
  *
98
- * @return array ( index => array( 0 => 'custom field name' ) )
99
  */
100
  public function get_meta() {
101
  global $wpdb;
@@ -115,7 +83,7 @@ class CPAC_Storage_Model_MLA extends CPAC_Storage_Model {
115
  $mla_custom[] = $heading;
116
  }
117
  }
118
-
119
  /*
120
  * Remove the fields already present in the submenu table
121
  */
@@ -124,7 +92,7 @@ class CPAC_Storage_Model_MLA extends CPAC_Storage_Model {
124
  unset( $meta[ $index ] );
125
  }
126
  }
127
-
128
  return $meta;
129
  }
130
 
@@ -133,86 +101,15 @@ class CPAC_Storage_Model_MLA extends CPAC_Storage_Model {
133
  *
134
  * @since 2.22
135
  *
136
- * @param string $content Current column content (empty string)
137
- * @param object $item Current Media Library item
138
- * @param string $column_name Current column slug
139
  *
140
  * @return string Column value or NULL if not an Admin Columns custom column
141
  */
142
- public function manage_value( $content, $item, $column_name ) {
143
- $media_id = $item->ID;
144
-
145
- if ( ! ( $column = $this->get_column_by_name( $column_name ) ) ) {
146
- return NULL;
147
- }
148
-
149
- $value = $column->get_value( $media_id );
150
-
151
- // hooks
152
- $value = apply_filters( "cac/column/value", $value, $media_id, $column, $this->key );
153
- $value = apply_filters( "cac/column/value/{$this->type}", $value, $media_id, $column, $this->key );
154
-
155
- return $value;
156
- }
157
-
158
- /**
159
- * Test for current screen = the Media/Assistant submenu screen,
160
- * For Admin Columns 2.4.9+
161
- *
162
- * @since 2.23
163
- *
164
- * @return boolean true if the Media/Assistant submenu is the current screen
165
- */
166
- public function is_current_screen() {
167
- $is_current_screen = parent::is_current_screen();
168
- if ( ! $is_current_screen ) {
169
- if ( ! empty( $_REQUEST['page'] ) && MLACore::ADMIN_PAGE_SLUG == $_REQUEST['page'] ) {
170
- $is_current_screen = true;
171
- }
172
- }
173
-
174
- return $is_current_screen;
175
- }
176
-
177
- /**
178
- * Test for current screen = the Media/Assistant submenu screen
179
- *
180
- * @since 2.22
181
- *
182
- * @return boolean true if the Media/Assistant submenu is the current screen
183
- */
184
- public function is_columns_screen() {
185
- $is_columns_screen = parent::is_columns_screen();
186
- if ( ! $is_columns_screen ) {
187
- if ( ! empty( $_REQUEST['page'] ) && MLACore::ADMIN_PAGE_SLUG == $_REQUEST['page'] ) {
188
- $is_columns_screen = true;
189
- }
190
- }
191
-
192
- return $is_columns_screen;
193
- }
194
-
195
- /**
196
- * Return a link to the Media/Assistant submenu screen
197
- *
198
- * @since 2.22
199
- *
200
- * @return string Link to the Media/Assistant submenu screen
201
- */
202
- protected function get_screen_link() {
203
- return is_network_admin() ? network_admin_url( $this->page . '.php?page=' . MLACore::ADMIN_PAGE_SLUG ) : admin_url( $this->page . '.php?page=' . MLACore::ADMIN_PAGE_SLUG );
204
- }
205
 
206
- /**
207
- * Return a link to the Media/Assistant submenu Edit columns screen
208
- *
209
- * @since 2.22
210
- *
211
- * @return string Link to the Media/Assistant submenu Edit columns screen
212
- */
213
- public function get_edit_link() {
214
- return add_query_arg( array( 'page' => 'codepress-admin-columns',
215
- 'cpac_key' => $this->key
216
- ), admin_url( 'options-general.php' ) );
217
  }
218
- } // class CPAC_Storage_Model_MLA
13
  * @package Media Library Assistant
14
  * @since 2.22
15
  */
16
+ class CPAC_Storage_Model_MLA extends AC_StorageModel_Media {
 
 
 
 
 
 
 
17
 
18
  /**
19
+ * Calls the parent function to set some default configs,
20
+ * then initializes some MLA-specific properties.
21
  *
22
  * @since 2.22
23
  */
24
+ public function init() {
25
+ parent::init();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
+ $this->key = 'mla-media-assistant';
28
+ $this->label = __( 'Media Library Assistant' );
29
+ $this->singular_label = __( 'Assistant' );
30
+ $this->screen = 'media_page_' . MLACore::ADMIN_PAGE_SLUG;
31
+ $this->subpage = MLACore::ADMIN_PAGE_SLUG;
 
32
 
 
 
33
  }
34
 
35
  /**
36
+ * Sets an MLA filter to handle custom column display.
37
  *
38
  * @since 2.22
 
 
39
  */
40
+ public function init_manage_value() {
41
+ add_filter( 'mla_list_table_column_default', array( $this, 'mla_manage_value' ), 100, 3 );
 
 
 
 
 
42
  }
43
 
44
  /**
45
+ * Returns the Media/Assistant sub menu table column slugs/keys
46
  *
47
  * @since 2.22
48
  *
49
+ * @return array ( index => 'column_slug' )
50
  */
51
  public function get_default_column_names() {
52
  if ( ! class_exists( 'MLAQuery' ) ) {
63
  *
64
  * @since 2.22
65
  *
66
+ * @return array ( index => array( 0 => 'custom field name' ) )
67
  */
68
  public function get_meta() {
69
  global $wpdb;
83
  $mla_custom[] = $heading;
84
  }
85
  }
86
+
87
  /*
88
  * Remove the fields already present in the submenu table
89
  */
92
  unset( $meta[ $index ] );
93
  }
94
  }
95
+
96
  return $meta;
97
  }
98
 
101
  *
102
  * @since 2.22
103
  *
104
+ * @param string $content Current column content (empty string)
105
+ * @param object $item Current Media Library item
106
+ * @param string $column_name Current column slug
107
  *
108
  * @return string Column value or NULL if not an Admin Columns custom column
109
  */
110
+ public function mla_manage_value( $content, $item, $column_name ) {
111
+ $value = $this->get_display_value_by_column_name( $column_name, $item->ID );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
 
113
+ return $value ? $value : $content;
 
 
 
 
 
 
 
 
 
 
114
  }
115
+ } // class CPAC_Storage_Model_MLA
includes/class-mla-ajax.php CHANGED
@@ -32,7 +32,10 @@ class MLA_Ajax {
32
  */
33
  public static function mla_admin_init_action( ) {
34
  //error_log( __LINE__ . ' DEBUG: MLA_Ajax::mla_admin_init_action $_REQUEST = ' . var_export( $_REQUEST, true ), 0 );
35
- MLACore::mla_debug_add( "MLA_Ajax::mla_admin_init_action \$_REQUEST = " . var_export( $_REQUEST, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
 
 
 
36
 
37
  /*
38
  * If there's no action variable, we have nothing more to do
32
  */
33
  public static function mla_admin_init_action( ) {
34
  //error_log( __LINE__ . ' DEBUG: MLA_Ajax::mla_admin_init_action $_REQUEST = ' . var_export( $_REQUEST, true ), 0 );
35
+ if ( $_REQUEST['action'] !== 'heartbeat' ) {
36
+ //error_log( __LINE__ . ' DEBUG: MLA_Ajax::mla_admin_init_action $_REQUEST = ' . var_export( $_REQUEST, true ), 0 );
37
+ MLACore::mla_debug_add( "MLA_Ajax::mla_admin_init_action \$_REQUEST = " . var_export( $_REQUEST, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
38
+ }
39
 
40
  /*
41
  * If there's no action variable, we have nothing more to do
includes/class-mla-core-options.php CHANGED
@@ -58,6 +58,11 @@ class MLACoreOptions {
58
  */
59
  const MLA_COUNT_TERM_ATTACHMENTS = 'count_term_attachments';
60
 
 
 
 
 
 
61
  /**
62
  * Provides a unique name for the taxonomy support option
63
  */
@@ -465,6 +470,14 @@ class MLACoreOptions {
465
  'std' => 'checked',
466
  'help' => __( 'Check this option to calculate attachments per term in the Attachments Column.', 'media-library-assistant' )),
467
 
 
 
 
 
 
 
 
 
468
  self::MLA_TAXONOMY_SUPPORT =>
469
  array('tab' => 'general',
470
  'help' => __( 'Check the "<strong>Support</strong>" box to add the taxonomy to the Assistant and the Edit Media screen.', 'media-library-assistant' ) . '<br>' .
@@ -476,7 +489,7 @@ class MLACoreOptions {
476
  __( 'You must also check the <strong>"Enable enhanced checklist taxonomies"</strong> box below to enable this feature.', 'media-library-assistant' ) . '<br>' .
477
  __( 'Check the "<strong>Checked On Top</strong>" box to moved checked terms to the top of the checklist-style meta box.', 'media-library-assistant' ) . '<br>' .
478
  __( 'Use the "<strong>List Filter</strong>" option to select the taxonomy (or custom field) on which to filter the Assistant table listing.', 'media-library-assistant' ) . '<br>' .
479
- __( 'To <strong>filter on a custom field</strong>, enter the field name and select ASC (Ascending) ot DESC (Descending) order.', 'media-library-assistant' ),
480
  'std' => array (
481
  'tax_support' => array (
482
  'attachment_category' => 'checked',
@@ -648,7 +661,7 @@ class MLACoreOptions {
648
  'autoload' => true,
649
  'std' => array (
650
  'search_connector' => 'AND',
651
- 'search_fields' => array ( 'title', 'content' ),
652
  ),
653
  'type' => 'custom',
654
  'render' => 'mla_search_option_handler',
@@ -883,7 +896,7 @@ class MLACoreOptions {
883
  'template_header' =>
884
  array('tab' => 'mla_gallery',
885
  'name' => __( 'Default [mla_gallery] Templates and Settings', 'media-library-assistant' ),
886
- 'type' => 'header'),
887
 
888
  'default_tag_cloud_style' =>
889
  array('tab' => '',
58
  */
59
  const MLA_COUNT_TERM_ATTACHMENTS = 'count_term_attachments';
60
 
61
+ /**
62
+ * Provides a unique name for the taxonomy show Count column option
63
+ */
64
+ const MLA_SHOW_COUNT_COLUMN = 'show_count_column';
65
+
66
  /**
67
  * Provides a unique name for the taxonomy support option
68
  */
470
  'std' => 'checked',
471
  'help' => __( 'Check this option to calculate attachments per term in the Attachments Column.', 'media-library-assistant' )),
472
 
473
+ self::MLA_SHOW_COUNT_COLUMN =>
474
+ array('tab' => 'general',
475
+ 'name' => __( 'Show Count Column', 'media-library-assistant' ),
476
+ 'type' => 'checkbox',
477
+ 'autoload' => true,
478
+ 'std' => '',
479
+ 'help' => __( 'Check this option to display the Count column on Categories and Tags taxonomy edit screens.', 'media-library-assistant' )),
480
+
481
  self::MLA_TAXONOMY_SUPPORT =>
482
  array('tab' => 'general',
483
  'help' => __( 'Check the "<strong>Support</strong>" box to add the taxonomy to the Assistant and the Edit Media screen.', 'media-library-assistant' ) . '<br>' .
489
  __( 'You must also check the <strong>"Enable enhanced checklist taxonomies"</strong> box below to enable this feature.', 'media-library-assistant' ) . '<br>' .
490
  __( 'Check the "<strong>Checked On Top</strong>" box to moved checked terms to the top of the checklist-style meta box.', 'media-library-assistant' ) . '<br>' .
491
  __( 'Use the "<strong>List Filter</strong>" option to select the taxonomy (or custom field) on which to filter the Assistant table listing.', 'media-library-assistant' ) . '<br>' .
492
+ __( 'To <strong>filter on a custom field</strong>, enter the field name and select ASC (Ascending) or DESC (Descending) order.', 'media-library-assistant' ),
493
  'std' => array (
494
  'tax_support' => array (
495
  'attachment_category' => 'checked',
661
  'autoload' => true,
662
  'std' => array (
663
  'search_connector' => 'AND',
664
+ 'search_fields' => array ( 'title', 'excerpt', 'content', 'file' ),
665
  ),
666
  'type' => 'custom',
667
  'render' => 'mla_search_option_handler',
896
  'template_header' =>
897
  array('tab' => 'mla_gallery',
898
  'name' => __( 'Default [mla_gallery] Templates and Settings', 'media-library-assistant' ),
899
+ 'type' => 'subheader'),
900
 
901
  'default_tag_cloud_style' =>
902
  array('tab' => '',
includes/class-mla-core.php CHANGED
@@ -21,7 +21,7 @@ class MLACore {
21
  *
22
  * @var string
23
  */
24
- const CURRENT_MLA_VERSION = '2.33';
25
 
26
  /**
27
  * Slug for registering and enqueueing plugin style sheets (moved from class-mla-main.php)
@@ -57,7 +57,7 @@ class MLACore {
57
  *
58
  * @var integer
59
  */
60
- CONST MLA_DEBUG_CATEGORY_ANY = 0x00000001;
61
 
62
  /**
63
  * Constant to log Ajax debug activity
@@ -66,7 +66,7 @@ class MLACore {
66
  *
67
  * @var integer
68
  */
69
- CONST MLA_DEBUG_CATEGORY_AJAX = 0x00000002;
70
 
71
  /**
72
  * Constant to log WPML/Polylang action/filter activity
@@ -75,7 +75,7 @@ class MLACore {
75
  *
76
  * @var integer
77
  */
78
- CONST MLA_DEBUG_CATEGORY_LANGUAGE = 0x00000004;
79
 
80
  /**
81
  * Constant to log Ghostscript/Imagick activity
@@ -84,7 +84,7 @@ class MLACore {
84
  *
85
  * @var integer
86
  */
87
- CONST MLA_DEBUG_CATEGORY_THUMBNAIL = 0x00000008;
88
 
89
  /**
90
  * Slug for adding plugin submenu
@@ -95,6 +95,69 @@ class MLACore {
95
  */
96
  const ADMIN_PAGE_SLUG = 'mla-menu';
97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  /**
99
  * mla_admin_action value for permanently deleting a single item
100
  *
@@ -122,6 +185,24 @@ class MLACore {
122
  */
123
  const MLA_ADMIN_SINGLE_RESTORE = 'single_item_restore';
124
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  /**
126
  * Action name; gives a context for the nonce
127
  *
@@ -333,9 +414,6 @@ class MLACore {
333
  */
334
  require_once( MLA_PLUGIN_PATH . 'includes/class-mla-list-table.php' );
335
 
336
- require_once( MLA_PLUGIN_PATH . 'includes/class-mla-view-list-table.php' );
337
- MLA_View_List_Table::mla_localize_default_columns_array();
338
-
339
  require_once( MLA_PLUGIN_PATH . 'includes/class-mla-media-modal.php' );
340
  MLAModal::initialize();
341
 
@@ -652,7 +730,7 @@ class MLACore {
652
  $template = file_get_contents( $source, true );
653
  if ( $template == false ) {
654
  /* translators: 1: ERROR tag 2: path and file name */
655
- 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 );
656
  return NULL;
657
  }
658
  break;
@@ -670,7 +748,7 @@ class MLACore {
670
  break;
671
  default:
672
  /* translators: 1: ERROR tag 2: path and file name 3: source type, e.g., file, option, string */
673
- 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 );
674
  return NULL;
675
  }
676
 
@@ -1478,8 +1556,15 @@ class MLACore {
1478
  * @param object $cpac CPAC, the root CodePress Admin Columns object
1479
  */
1480
  public static function admin_columns_support( $storage_models, $cpac ) {
1481
- require_once( MLA_PLUGIN_PATH . 'includes/class-mla-admin-columns-support.php' );
1482
- MLACore::$admin_columns_storage_model = new CPAC_Storage_Model_MLA();
 
 
 
 
 
 
 
1483
  /*
1484
  * Put MLA before/after WP Media Library so is_columns_screen() will work
1485
  */
21
  *
22
  * @var string
23
  */
24
+ const CURRENT_MLA_VERSION = '2.40';
25
 
26
  /**
27
  * Slug for registering and enqueueing plugin style sheets (moved from class-mla-main.php)
57
  *
58
  * @var integer
59
  */
60
+ const MLA_DEBUG_CATEGORY_ANY = 0x00000001;
61
 
62
  /**
63
  * Constant to log Ajax debug activity
66
  *
67
  * @var integer
68
  */
69
+ const MLA_DEBUG_CATEGORY_AJAX = 0x00000002;
70
 
71
  /**
72
  * Constant to log WPML/Polylang action/filter activity
75
  *
76
  * @var integer
77
  */
78
+ const MLA_DEBUG_CATEGORY_LANGUAGE = 0x00000004;
79
 
80
  /**
81
  * Constant to log Ghostscript/Imagick activity
84
  *
85
  * @var integer
86
  */
87
+ const MLA_DEBUG_CATEGORY_THUMBNAIL = 0x00000008;
88
 
89
  /**
90
  * Slug for adding plugin submenu
95
  */
96
  const ADMIN_PAGE_SLUG = 'mla-menu';
97
 
98
+ /**
99
+ * mla_admin_action value to display a single item for editing/viewing
100
+ *
101
+ * @since 0.1
102
+ *
103
+ * @var string
104
+ */
105
+ const MLA_ADMIN_SINGLE_EDIT_DISPLAY = 'single_item_edit_display';
106
+
107
+ /**
108
+ * mla_admin_action value to install an example plugin
109
+ *
110
+ * @since 2.40
111
+ *
112
+ * @var string
113
+ */
114
+ const MLA_ADMIN_SINGLE_EDIT_INSTALL = 'single_item_edit_install';
115
+
116
+ /**
117
+ * mla_admin_action value for updating a single item
118
+ *
119
+ * @since 0.1
120
+ *
121
+ * @var string
122
+ */
123
+ const MLA_ADMIN_SINGLE_EDIT_UPDATE = 'single_item_edit_update';
124
+
125
+ /**
126
+ * mla_admin_action value for mapping Custom Field metadata
127
+ *
128
+ * @since 1.10
129
+ *
130
+ * @var string
131
+ */
132
+ const MLA_ADMIN_SINGLE_CUSTOM_FIELD_MAP = 'single_item_custom_field_map';
133
+
134
+ /**
135
+ * mla_admin_action value for mapping IPTC/EXIF metadata
136
+ *
137
+ * @since 1.00
138
+ *
139
+ * @var string
140
+ */
141
+ const MLA_ADMIN_SINGLE_MAP = 'single_item_map';
142
+
143
+ /**
144
+ * mla_admin_action value for setting an item's parent object
145
+ *
146
+ * @since 1.82
147
+ *
148
+ * @var string
149
+ */
150
+ const MLA_ADMIN_SET_PARENT = 'set_parent';
151
+
152
+ /**
153
+ * mla_admin_action value for searching taxonomy terms
154
+ *
155
+ * @since 1.90
156
+ *
157
+ * @var string
158
+ */
159
+ const MLA_ADMIN_TERMS_SEARCH = 'terms_search';
160
+
161
  /**
162
  * mla_admin_action value for permanently deleting a single item
163
  *
185
  */
186
  const MLA_ADMIN_SINGLE_RESTORE = 'single_item_restore';
187
 
188
+ /**
189
+ * mla_admin_action value for copying a single item
190
+ *
191
+ * @since 2.40
192
+ *
193
+ * @var string
194
+ */
195
+ const MLA_ADMIN_SINGLE_COPY = 'single_item_copy';
196
+
197
+ /**
198
+ * mla_admin_action value for copying a single item
199
+ *
200
+ * @since 2.40
201
+ *
202
+ * @var string
203
+ */
204
+ const MLA_ADMIN_SINGLE_ADD = 'single_item_add';
205
+
206
  /**
207
  * Action name; gives a context for the nonce
208
  *
414
  */
415
  require_once( MLA_PLUGIN_PATH . 'includes/class-mla-list-table.php' );
416
 
 
 
 
417
  require_once( MLA_PLUGIN_PATH . 'includes/class-mla-media-modal.php' );
418
  MLAModal::initialize();
419
 
730
  $template = file_get_contents( $source, true );
731
  if ( $template == false ) {
732
  /* translators: 1: ERROR tag 2: path and file name */
733
+ MLACore::mla_debug_add( 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 ) ), MLACore::MLA_DEBUG_CATEGORY_ANY );
734
  return NULL;
735
  }
736
  break;
748
  break;
749
  default:
750
  /* translators: 1: ERROR tag 2: path and file name 3: source type, e.g., file, option, string */
751
+ MLACore::mla_debug_add( 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 ), MLACore::MLA_DEBUG_CATEGORY_ANY );
752
  return NULL;
753
  }
754
 
1556
  * @param object $cpac CPAC, the root CodePress Admin Columns object
1557
  */
1558
  public static function admin_columns_support( $storage_models, $cpac ) {
1559
+ // Check for the correct Storage model
1560
+ if( class_exists( 'AC_StorageModel_Media', false ) ) {
1561
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-admin-columns-support.php' );
1562
+ MLACore::$admin_columns_storage_model = new CPAC_Storage_Model_MLA();
1563
+ } else {
1564
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-admin-columns-support-deprecated.php' );
1565
+ MLACore::$admin_columns_storage_model = new CPAC_Deprecated_Storage_Model_MLA();
1566
+ }
1567
+
1568
  /*
1569
  * Put MLA before/after WP Media Library so is_columns_screen() will work
1570
  */
includes/class-mla-data-pdf.php CHANGED
@@ -213,7 +213,7 @@ class MLAPDF {
213
  $is_stream = true;
214
  } else {
215
  /* translators: 1: ERROR tag 2: index */
216
- error_log( sprintf( _x( '%1$s: _build_pdf_indirect_objects bad value at $index = "%2$d".', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $index ), 0 );
217
  }
218
  } // for each match
219
  }
@@ -514,9 +514,9 @@ class MLAPDF {
514
  $dictionary_end = strpos( $source_string, '>>', $nest );
515
  if ( false === $dictionary_end ) {
516
  /* translators: 1: ERROR tag 2: source offset 3: nest level */
517
- error_log( sprintf( _x( '%1$s: _parse_pdf_dictionary offset = %2$d, nest = %3$d.', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $offset, $nest ), 0 );
518
  /* translators: 1: ERROR tag 2: dictionary excerpt */
519
- error_log( sprintf( _x( '%1$s: _parse_pdf_dictionary no end delimiter dump = %2$s.', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), MLAData::mla_hex_dump( substr( $source_string, $offset, 128 ), 128, 16 ) ), 0 );
520
  return array( '/length' => 0 );
521
  }
522
 
@@ -562,7 +562,7 @@ class MLAPDF {
562
  $dictionary[ $name ]['value'] = $value;
563
  if ( ! isset( $value[0] ) ) {
564
  /* translators: 1: ERROR tag 2: entry name 3: value excerpt */
565
- error_log( sprintf( _x( '%1$s: _parse_pdf_dictionary bad value [ %2$s ] dump = %3$s', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $name, MLAData::mla_hex_dump( $value, 32, 16 ) ), 0 );
566
  continue;
567
  }
568
 
@@ -746,7 +746,7 @@ class MLAPDF {
746
  $match_count = preg_match_all( '/startxref[\x00-\x20]+(\d+)[\x00-\x20]+\%\%EOF/', $tail, $matches, PREG_OFFSET_CAPTURE );
747
  if ( 0 == $match_count ) {
748
  /* translators: 1: ERROR tag 2: path and file */
749
- error_log( sprintf( _x( '%1$s: File "%2$s", startxref not found.', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $path ), 0 );
750
  return array( 'xmp' => $xmp, 'pdf' => $metadata );
751
  }
752
 
@@ -755,10 +755,11 @@ class MLAPDF {
755
  //error_log( __LINE__ . " MLAPDF::mla_extract_pdf_metadata trailer_dictionaries = " . var_export( $trailer_dictionaries, true ), 0 );
756
  if ( is_array( $trailer_dictionaries ) ) {
757
  $info_reference = NULL;
758
- foreach ( $trailer_dictionaries as $trailer_dictionary )
759
- if ( isset( $trailer_dictionary['Info'] ) ) {
760
- $info_reference = $trailer_dictionary['Info'];
761
- break;
 
762
  }
763
  //error_log( __LINE__ . " MLAPDF::mla_extract_pdf_metadata info_reference = " . var_export( $info_reference, true ), 0 );
764
 
213
  $is_stream = true;
214
  } else {
215
  /* translators: 1: ERROR tag 2: index */
216
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: _build_pdf_indirect_objects bad value at $index = "%2$d".', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $index ), MLACore::MLA_DEBUG_CATEGORY_ANY );
217
  }
218
  } // for each match
219
  }
514
  $dictionary_end = strpos( $source_string, '>>', $nest );
515
  if ( false === $dictionary_end ) {
516
  /* translators: 1: ERROR tag 2: source offset 3: nest level */
517
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: _parse_pdf_dictionary offset = %2$d, nest = %3$d.', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $offset, $nest ), MLACore::MLA_DEBUG_CATEGORY_ANY );
518
  /* translators: 1: ERROR tag 2: dictionary excerpt */
519
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: _parse_pdf_dictionary no end delimiter dump = %2$s.', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), MLAData::mla_hex_dump( substr( $source_string, $offset, 128 ), 128, 16 ) ), MLACore::MLA_DEBUG_CATEGORY_ANY );
520
  return array( '/length' => 0 );
521
  }
522
 
562
  $dictionary[ $name ]['value'] = $value;
563
  if ( ! isset( $value[0] ) ) {
564
  /* translators: 1: ERROR tag 2: entry name 3: value excerpt */
565
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: _parse_pdf_dictionary bad value [ %2$s ] dump = %3$s', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $name, MLAData::mla_hex_dump( $value, 32, 16 ) ), MLACore::MLA_DEBUG_CATEGORY_ANY );
566
  continue;
567
  }
568
 
746
  $match_count = preg_match_all( '/startxref[\x00-\x20]+(\d+)[\x00-\x20]+\%\%EOF/', $tail, $matches, PREG_OFFSET_CAPTURE );
747
  if ( 0 == $match_count ) {
748
  /* translators: 1: ERROR tag 2: path and file */
749
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: File "%2$s", startxref not found.', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $path ), MLACore::MLA_DEBUG_CATEGORY_ANY );
750
  return array( 'xmp' => $xmp, 'pdf' => $metadata );
751
  }
752
 
755
  //error_log( __LINE__ . " MLAPDF::mla_extract_pdf_metadata trailer_dictionaries = " . var_export( $trailer_dictionaries, true ), 0 );
756
  if ( is_array( $trailer_dictionaries ) ) {
757
  $info_reference = NULL;
758
+ foreach ( $trailer_dictionaries as $trailer_dictionary ) {
759
+ if ( isset( $trailer_dictionary['Info'] ) ) {
760
+ $info_reference = $trailer_dictionary['Info'];
761
+ break;
762
+ }
763
  }
764
  //error_log( __LINE__ . " MLAPDF::mla_extract_pdf_metadata info_reference = " . var_export( $info_reference, true ), 0 );
765
 
includes/class-mla-data-query.php CHANGED
@@ -24,6 +24,16 @@ class MLAQuery {
24
  */
25
  const MLA_ALT_TEXT_SUBQUERY = 'alt_text_subquery';
26
 
 
 
 
 
 
 
 
 
 
 
27
  /**
28
  * Provides a unique suffix for the custom field "orderby" subquery
29
  *
@@ -42,7 +52,7 @@ class MLAQuery {
42
  *
43
  * @since 2.15
44
  */
45
- const MLA_TABLE_VIEW_SUBQUERY = 'table_view_subquery';
46
 
47
  /**
48
  * WordPress version test for $wpdb->esc_like() Vs esc_sql()
@@ -61,9 +71,9 @@ class MLAQuery {
61
  public static function initialize() {
62
  self::$wp_4dot0_plus = version_compare( get_bloginfo('version'), '4.0', '>=' );
63
 
64
- /*
65
- * Set up the Media/Assistant submenu table column definitions
66
- */
67
  $taxonomies = get_taxonomies( array ( 'show_ui' => true ), 'names' );
68
 
69
  foreach ( $taxonomies as $tax_name ) {
@@ -159,46 +169,6 @@ class MLAQuery {
159
  }
160
  }
161
 
162
- /**
163
- * Builds the $default_columns array with translated source texts.
164
- *
165
- * Called from MLATest::initialize because the $default_columns information
166
- * might be accessed from "front end" posts/pages.
167
- *
168
- * @since 1.71
169
- */
170
- public static function mla_localize_default_columns_array( ) {
171
- /*
172
- * Build the default columns array at runtime to accomodate calls to the
173
- * localization functions
174
- */
175
- self::$default_columns = array(
176
- 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
177
- 'icon' => '',
178
- 'ID_parent' => esc_html( _x( 'ID/Parent', 'list_table_column', 'media-library-assistant' ) ),
179
- 'title_name' => esc_html( _x( 'Title/Name', 'list_table_column', 'media-library-assistant' ) ),
180
- 'post_title' => esc_html( _x( 'Title', 'list_table_column', 'media-library-assistant' ) ),
181
- 'post_name' => esc_html( _x( 'Name', 'list_table_column', 'media-library-assistant' ) ),
182
- 'parent' => esc_html( _x( 'Parent ID', 'list_table_column', 'media-library-assistant' ) ),
183
- 'menu_order' => esc_html( _x( 'Menu Order', 'list_table_column', 'media-library-assistant' ) ),
184
- 'featured' => esc_html( _x( 'Featured in', 'list_table_column', 'media-library-assistant' ) ),
185
- 'inserted' => esc_html( _x( 'Inserted in', 'list_table_column', 'media-library-assistant' ) ),
186
- 'galleries' => esc_html( _x( 'Gallery in', 'list_table_column', 'media-library-assistant' ) ),
187
- 'mla_galleries' => esc_html( _x( 'MLA Gallery in', 'list_table_column', 'media-library-assistant' ) ),
188
- 'alt_text' => esc_html( _x( 'ALT Text', 'list_table_column', 'media-library-assistant' ) ),
189
- 'caption' => esc_html( _x( 'Caption', 'list_table_column', 'media-library-assistant' ) ),
190
- 'description' => esc_html( _x( 'Description', 'list_table_column', 'media-library-assistant' ) ),
191
- 'post_mime_type' => esc_html( _x( 'MIME Type', 'list_table_column', 'media-library-assistant' ) ),
192
- 'file_url' => esc_html( _x( 'File URL', 'list_table_column', 'media-library-assistant' ) ),
193
- 'base_file' => esc_html( _x( 'Base File', 'list_table_column', 'media-library-assistant' ) ),
194
- 'date' => esc_html( _x( 'Date', 'list_table_column', 'media-library-assistant' ) ),
195
- 'modified' => esc_html( _x( 'Last Modified', 'list_table_column', 'media-library-assistant' ) ),
196
- 'author' => esc_html( _x( 'Author', 'list_table_column', 'media-library-assistant' ) ),
197
- 'attached_to' => esc_html( _x( 'Attached to', 'list_table_column', 'media-library-assistant' ) ),
198
- // taxonomy and custom field columns added below
199
- );
200
- }
201
-
202
  /*
203
  * The $default_columns, $default_hidden_columns, and $default_sortable_columns
204
  * arrays define the "Media/Assistant" table columns.
@@ -307,6 +277,45 @@ class MLAQuery {
307
  // sortable custom field columns, if any, added by mla_admin_init_action
308
  );
309
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
310
  /**
311
  * Return the names and display values of the sortable columns
312
  *
@@ -607,8 +616,8 @@ class MLAQuery {
607
  * ['mla_terms_search']['radio_phrases'] => AND/OR
608
  * ['mla_terms_search']['radio_terms'] => AND/OR
609
  * ['s'] => numeric for ID/parent search
610
- * ['mla_search_fields'] => 'content', 'title', 'excerpt', 'alt-text', 'name', 'terms'
611
- * Note: 'alt-text' is not supported in [mla_gallery]
612
  * ['mla_search_connector'] => AND/OR
613
  * ['sentence'] => entire string must match as one "keyword"
614
  * ['exact'] => entire string must match entire field value
@@ -663,7 +672,7 @@ class MLAQuery {
663
  */
664
  if ( ! is_array( $raw_request ) ) {
665
  /* translators: 1: ERROR tag 2: function name 3: non-array value */
666
- 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 );
667
  return NULL;
668
  }
669
 
@@ -790,7 +799,6 @@ class MLAQuery {
790
  $clean_request['mla-metakey'] = MLACore::mla_taxonomy_support('', 'metakey');
791
  $clean_request['mla-metavalue'] = stripslashes( $value );
792
  }
793
- //error_log( __LINE__ . ' _prepare_list_table_query clean_request = ' . var_export( $clean_request, true ), 0 );
794
 
795
  break;
796
  }
@@ -879,7 +887,7 @@ class MLAQuery {
879
  /*
880
  * Pass query and search parameters to the filters for _execute_list_table_query
881
  */
882
- self::$query_parameters = array( 'use_alt_text_subquery' => false, 'use_postmeta_subquery' => false, 'use_orderby_subquery' => false, 'orderby' => $clean_request['orderby'], 'order' => $clean_request['order'] );
883
  self::$query_parameters['detached'] = isset( $clean_request['detached'] ) ? $clean_request['detached'] : NULL;
884
  self::$search_parameters = array( 'debug' => 'none' );
885
 
@@ -888,7 +896,7 @@ class MLAQuery {
888
  * Matching a wildcard pattern requires mainpulating the WHERE clause, too
889
  */
890
  if ( isset( $clean_request['meta_query']['key'] ) ) {
891
- self::$query_parameters['use_postmeta_subquery'] = true;
892
  self::$query_parameters['postmeta_key'] = $clean_request['meta_query']['key'];
893
  self::$query_parameters['postmeta_value'] = NULL;
894
  unset( $clean_request['meta_query'] );
@@ -934,13 +942,17 @@ class MLAQuery {
934
  */
935
  if ( isset( $clean_request['s'] ) ) {
936
  self::$search_parameters['s'] = $clean_request['s'];
937
- 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' ) );
938
  self::$search_parameters['mla_search_connector'] = $clean_request['mla_search_connector'];
939
  self::$search_parameters['sentence'] = isset( $clean_request['sentence'] );
940
  self::$search_parameters['exact'] = isset( $clean_request['exact'] );
941
 
942
  if ( in_array( 'alt-text', self::$search_parameters['mla_search_fields'] ) ) {
943
- self::$query_parameters['use_alt_text_subquery'] = true;
 
 
 
 
944
  }
945
 
946
  if ( in_array( 'terms', self::$search_parameters['mla_search_fields'] ) ) {
@@ -961,7 +973,7 @@ class MLAQuery {
961
  if ( 'c_' == substr( $clean_request['orderby'], 0, 2 ) ) {
962
  $option_value = MLAQuery::mla_custom_field_option_value( $clean_request['orderby'] );
963
  if ( isset( $option_value['name'] ) ) {
964
- self::$query_parameters['use_orderby_subquery'] = true;
965
  self::$query_parameters['orderby_key'] = $option_value['name'];
966
 
967
  if ( isset($clean_request['orderby']) ) {
@@ -979,7 +991,7 @@ class MLAQuery {
979
  * so we'll handle it in the JOIN and ORDERBY filters
980
  */
981
  case '_wp_attachment_image_alt':
982
- self::$query_parameters['use_orderby_subquery'] = true;
983
  self::$query_parameters['orderby_key'] = '_wp_attachment_image_alt';
984
 
985
  if ( isset($clean_request['orderby']) ) {
@@ -1553,6 +1565,12 @@ class MLAQuery {
1553
  $inner_connector = ' OR ';
1554
  }
1555
 
 
 
 
 
 
 
1556
  if ( in_array( 'name', $fields ) ) {
1557
  $inner_clause .= "{$inner_connector}({$wpdb->posts}.post_name LIKE {$sql_term})";
1558
  }
@@ -1752,31 +1770,31 @@ class MLAQuery {
1752
  }
1753
 
1754
  /*
1755
- * ALT Text searches, custom field Table Views and custom field sorts are
1756
- * special; we have to use a subquery to build an intermediate table and
1757
  * modify the JOIN to include posts with no value for the metadata field.
1758
- * Three clauses are used because all three conditions can be present at once.
1759
  */
1760
- if ( self::$query_parameters['use_alt_text_subquery'] ) {
1761
  $sub_query = sprintf( 'SELECT post_id, meta_value FROM %1$s WHERE %1$s.meta_key = \'%2$s\'', $wpdb->postmeta, '_wp_attachment_image_alt' );
1762
  $join_clause .= sprintf( ' LEFT JOIN ( %1$s ) %2$s ON (%3$s.ID = %2$s.post_id)', $sub_query, self::MLA_ALT_TEXT_SUBQUERY, $wpdb->posts );
1763
  }
1764
 
1765
- if ( self::$query_parameters['use_postmeta_subquery'] ) {
 
 
 
 
 
1766
  $sub_query = sprintf( 'SELECT post_id, meta_value FROM %1$s WHERE %1$s.meta_key = \'%2$s\'', $wpdb->postmeta, self::$query_parameters['postmeta_key'] );
1767
  $join_clause .= sprintf( ' LEFT JOIN ( %1$s ) %2$s ON (%3$s.ID = %2$s.post_id)', $sub_query, self::MLA_TABLE_VIEW_SUBQUERY, $wpdb->posts );
1768
  }
1769
 
1770
- if ( self::$query_parameters['use_orderby_subquery'] ) {
1771
  $sub_query = sprintf( 'SELECT post_id, meta_value FROM %1$s WHERE %1$s.meta_key = \'%2$s\'', $wpdb->postmeta, self::$query_parameters['orderby_key'] );
1772
  $join_clause .= sprintf( ' LEFT JOIN ( %1$s ) %2$s ON (%3$s.ID = %2$s.post_id)', $sub_query, self::MLA_ORDERBY_SUBQUERY, $wpdb->posts );
1773
  }
1774
 
1775
- /*
1776
- * Custom field sorts are special; we have to use a subquery to build
1777
- * an intermediate table and modify the JOIN to include posts with
1778
- * no value for this metadata field.
1779
- */
1780
  if ( isset( self::$query_parameters['orderby'] ) ) {
1781
  if ( ( 'c_' == substr( self::$query_parameters['orderby'], 0, 2 ) ) || ( '_wp_attachment_image_alt' == self::$query_parameters['orderby'] ) ) {
1782
  $orderby = self::MLA_ORDERBY_SUBQUERY . '.meta_value';
@@ -1820,7 +1838,7 @@ class MLAQuery {
1820
  public static function mla_query_posts_groupby_filter( $groupby_clause ) {
1821
  global $wpdb;
1822
 
1823
- if ( ( ! empty( self::$query_parameters['use_postmeta_subquery'] ) ) || ( ! empty( self::$query_parameters['use_alt_text_subquery'] ) ) || ( ! empty( self::$query_parameters['use_orderby_subquery'] ) ) || isset( self::$search_parameters['tax_terms_count'] ) ) {
1824
  $groupby_clause = "{$wpdb->posts}.ID";
1825
  }
1826
 
24
  */
25
  const MLA_ALT_TEXT_SUBQUERY = 'alt_text_subquery';
26
 
27
+ /**
28
+ * Provides a unique value for the File Name "Search Media" subquery
29
+ *
30
+ * The subquery is used to filter the Media/Assistant submenu table by
31
+ * File Name with the Search Media text box.
32
+ *
33
+ * @since 0.40
34
+ */
35
+ const MLA_FILE_SUBQUERY = 'file_subquery';
36
+
37
  /**
38
  * Provides a unique suffix for the custom field "orderby" subquery
39
  *
52
  *
53
  * @since 2.15
54
  */
55
+ const MLA_TABLE_VIEW_SUBQUERY = 'use_postmeta_view'; // see mla-custom-field-search-example.php
56
 
57
  /**
58
  * WordPress version test for $wpdb->esc_like() Vs esc_sql()
71
  public static function initialize() {
72
  self::$wp_4dot0_plus = version_compare( get_bloginfo('version'), '4.0', '>=' );
73
 
74
+ self::_localize_default_columns_array();
75
+
76
+ /// Set up the Media/Assistant submenu table column definitions
77
  $taxonomies = get_taxonomies( array ( 'show_ui' => true ), 'names' );
78
 
79
  foreach ( $taxonomies as $tax_name ) {
169
  }
170
  }
171
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  /*
173
  * The $default_columns, $default_hidden_columns, and $default_sortable_columns
174
  * arrays define the "Media/Assistant" table columns.
277
  // sortable custom field columns, if any, added by mla_admin_init_action
278
  );
279
 
280
+ /**
281
+ * Builds the $default_columns array with translated source texts.
282
+ *
283
+ * Called from MLATest::initialize because the $default_columns information
284
+ * might be accessed from "front end" posts/pages.
285
+ *
286
+ * @since 1.71
287
+ */
288
+ private static function _localize_default_columns_array( ) {
289
+ if ( empty( self::$default_columns ) ) {
290
+ // Build the default columns array at runtime to accomodate calls to the localization functions
291
+ self::$default_columns = array(
292
+ 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
293
+ 'icon' => '',
294
+ 'ID_parent' => esc_html( _x( 'ID/Parent', 'list_table_column', 'media-library-assistant' ) ),
295
+ 'title_name' => esc_html( _x( 'Title/Name', 'list_table_column', 'media-library-assistant' ) ),
296
+ 'post_title' => esc_html( _x( 'Title', 'list_table_column', 'media-library-assistant' ) ),
297
+ 'post_name' => esc_html( _x( 'Name', 'list_table_column', 'media-library-assistant' ) ),
298
+ 'parent' => esc_html( _x( 'Parent ID', 'list_table_column', 'media-library-assistant' ) ),
299
+ 'menu_order' => esc_html( _x( 'Menu Order', 'list_table_column', 'media-library-assistant' ) ),
300
+ 'featured' => esc_html( _x( 'Featured in', 'list_table_column', 'media-library-assistant' ) ),
301
+ 'inserted' => esc_html( _x( 'Inserted in', 'list_table_column', 'media-library-assistant' ) ),
302
+ 'galleries' => esc_html( _x( 'Gallery in', 'list_table_column', 'media-library-assistant' ) ),
303
+ 'mla_galleries' => esc_html( _x( 'MLA Gallery in', 'list_table_column', 'media-library-assistant' ) ),
304
+ 'alt_text' => esc_html( _x( 'ALT Text', 'list_table_column', 'media-library-assistant' ) ),
305
+ 'caption' => esc_html( _x( 'Caption', 'list_table_column', 'media-library-assistant' ) ),
306
+ 'description' => esc_html( _x( 'Description', 'list_table_column', 'media-library-assistant' ) ),
307
+ 'post_mime_type' => esc_html( _x( 'MIME Type', 'list_table_column', 'media-library-assistant' ) ),
308
+ 'file_url' => esc_html( _x( 'File URL', 'list_table_column', 'media-library-assistant' ) ),
309
+ 'base_file' => esc_html( _x( 'Base File', 'list_table_column', 'media-library-assistant' ) ),
310
+ 'date' => esc_html( _x( 'Date', 'list_table_column', 'media-library-assistant' ) ),
311
+ 'modified' => esc_html( _x( 'Last Modified', 'list_table_column', 'media-library-assistant' ) ),
312
+ 'author' => esc_html( _x( 'Author', 'list_table_column', 'media-library-assistant' ) ),
313
+ 'attached_to' => esc_html( _x( 'Attached to', 'list_table_column', 'media-library-assistant' ) ),
314
+ // taxonomy and custom field columns added below
315
+ );
316
+ }
317
+ }
318
+
319
  /**
320
  * Return the names and display values of the sortable columns
321
  *
616
  * ['mla_terms_search']['radio_phrases'] => AND/OR
617
  * ['mla_terms_search']['radio_terms'] => AND/OR
618
  * ['s'] => numeric for ID/parent search
619
+ * ['mla_search_fields'] => 'title', 'name', 'alt-text', 'excerpt', 'content', 'file' ,'terms'
620
+ * Note: 'alt-text' and 'file' are not supported in [mla_gallery]
621
  * ['mla_search_connector'] => AND/OR
622
  * ['sentence'] => entire string must match as one "keyword"
623
  * ['exact'] => entire string must match entire field value
672
  */
673
  if ( ! is_array( $raw_request ) ) {
674
  /* translators: 1: ERROR tag 2: function name 3: non-array value */
675
+ MLACore::mla_debug_add( 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 ) ), MLACore::MLA_DEBUG_CATEGORY_ANY );
676
  return NULL;
677
  }
678
 
799
  $clean_request['mla-metakey'] = MLACore::mla_taxonomy_support('', 'metakey');
800
  $clean_request['mla-metavalue'] = stripslashes( $value );
801
  }
 
802
 
803
  break;
804
  }
887
  /*
888
  * Pass query and search parameters to the filters for _execute_list_table_query
889
  */
890
+ self::$query_parameters = array( self::MLA_ALT_TEXT_SUBQUERY => false, self::MLA_FILE_SUBQUERY => false, self::MLA_TABLE_VIEW_SUBQUERY => false, self::MLA_ORDERBY_SUBQUERY => false, 'orderby' => $clean_request['orderby'], 'order' => $clean_request['order'] );
891
  self::$query_parameters['detached'] = isset( $clean_request['detached'] ) ? $clean_request['detached'] : NULL;
892
  self::$search_parameters = array( 'debug' => 'none' );
893
 
896
  * Matching a wildcard pattern requires mainpulating the WHERE clause, too
897
  */
898
  if ( isset( $clean_request['meta_query']['key'] ) ) {
899
+ self::$query_parameters[self::MLA_TABLE_VIEW_SUBQUERY] = true;
900
  self::$query_parameters['postmeta_key'] = $clean_request['meta_query']['key'];
901
  self::$query_parameters['postmeta_value'] = NULL;
902
  unset( $clean_request['meta_query'] );
942
  */
943
  if ( isset( $clean_request['s'] ) ) {
944
  self::$search_parameters['s'] = $clean_request['s'];
945
+ self::$search_parameters['mla_search_fields'] = apply_filters( 'mla_list_table_search_filter_fields', $clean_request['mla_search_fields'], array( 'title', 'name', 'alt-text', 'excerpt', 'content', 'file' ,'terms' ) );
946
  self::$search_parameters['mla_search_connector'] = $clean_request['mla_search_connector'];
947
  self::$search_parameters['sentence'] = isset( $clean_request['sentence'] );
948
  self::$search_parameters['exact'] = isset( $clean_request['exact'] );
949
 
950
  if ( in_array( 'alt-text', self::$search_parameters['mla_search_fields'] ) ) {
951
+ self::$query_parameters[self::MLA_ALT_TEXT_SUBQUERY] = true;
952
+ }
953
+
954
+ if ( in_array( 'file', self::$search_parameters['mla_search_fields'] ) ) {
955
+ self::$query_parameters[self::MLA_FILE_SUBQUERY] = true;
956
  }
957
 
958
  if ( in_array( 'terms', self::$search_parameters['mla_search_fields'] ) ) {
973
  if ( 'c_' == substr( $clean_request['orderby'], 0, 2 ) ) {
974
  $option_value = MLAQuery::mla_custom_field_option_value( $clean_request['orderby'] );
975
  if ( isset( $option_value['name'] ) ) {
976
+ self::$query_parameters[self::MLA_ORDERBY_SUBQUERY] = true;
977
  self::$query_parameters['orderby_key'] = $option_value['name'];
978
 
979
  if ( isset($clean_request['orderby']) ) {
991
  * so we'll handle it in the JOIN and ORDERBY filters
992
  */
993
  case '_wp_attachment_image_alt':
994
+ self::$query_parameters[self::MLA_ORDERBY_SUBQUERY] = true;
995
  self::$query_parameters['orderby_key'] = '_wp_attachment_image_alt';
996
 
997
  if ( isset($clean_request['orderby']) ) {
1565
  $inner_connector = ' OR ';
1566
  }
1567
 
1568
+ if ( in_array( 'file', $fields ) ) {
1569
+ $view_name = self::MLA_FILE_SUBQUERY;
1570
+ $inner_clause .= "{$inner_connector}({$view_name}.meta_value LIKE {$sql_term})";
1571
+ $inner_connector = ' OR ';
1572
+ }
1573
+
1574
  if ( in_array( 'name', $fields ) ) {
1575
  $inner_clause .= "{$inner_connector}({$wpdb->posts}.post_name LIKE {$sql_term})";
1576
  }
1770
  }
1771
 
1772
  /*
1773
+ * ALT Text searches, File Name searches, custom field Table Views and custom field
1774
+ * sorts are special; we have to use a subquery to build an intermediate table and
1775
  * modify the JOIN to include posts with no value for the metadata field.
1776
+ * Four clauses are used because all four conditions can be present at once.
1777
  */
1778
+ if ( self::$query_parameters[self::MLA_ALT_TEXT_SUBQUERY] ) {
1779
  $sub_query = sprintf( 'SELECT post_id, meta_value FROM %1$s WHERE %1$s.meta_key = \'%2$s\'', $wpdb->postmeta, '_wp_attachment_image_alt' );
1780
  $join_clause .= sprintf( ' LEFT JOIN ( %1$s ) %2$s ON (%3$s.ID = %2$s.post_id)', $sub_query, self::MLA_ALT_TEXT_SUBQUERY, $wpdb->posts );
1781
  }
1782
 
1783
+ if ( self::$query_parameters[self::MLA_FILE_SUBQUERY] ) {
1784
+ $sub_query = sprintf( 'SELECT post_id, meta_value FROM %1$s WHERE %1$s.meta_key = \'%2$s\'', $wpdb->postmeta, '_wp_attached_file' );
1785
+ $join_clause .= sprintf( ' LEFT JOIN ( %1$s ) %2$s ON (%3$s.ID = %2$s.post_id)', $sub_query, self::MLA_FILE_SUBQUERY, $wpdb->posts );
1786
+ }
1787
+
1788
+ if ( self::$query_parameters[self::MLA_TABLE_VIEW_SUBQUERY] ) {
1789
  $sub_query = sprintf( 'SELECT post_id, meta_value FROM %1$s WHERE %1$s.meta_key = \'%2$s\'', $wpdb->postmeta, self::$query_parameters['postmeta_key'] );
1790
  $join_clause .= sprintf( ' LEFT JOIN ( %1$s ) %2$s ON (%3$s.ID = %2$s.post_id)', $sub_query, self::MLA_TABLE_VIEW_SUBQUERY, $wpdb->posts );
1791
  }
1792
 
1793
+ if ( self::$query_parameters[self::MLA_ORDERBY_SUBQUERY] ) {
1794
  $sub_query = sprintf( 'SELECT post_id, meta_value FROM %1$s WHERE %1$s.meta_key = \'%2$s\'', $wpdb->postmeta, self::$query_parameters['orderby_key'] );
1795
  $join_clause .= sprintf( ' LEFT JOIN ( %1$s ) %2$s ON (%3$s.ID = %2$s.post_id)', $sub_query, self::MLA_ORDERBY_SUBQUERY, $wpdb->posts );
1796
  }
1797
 
 
 
 
 
 
1798
  if ( isset( self::$query_parameters['orderby'] ) ) {
1799
  if ( ( 'c_' == substr( self::$query_parameters['orderby'], 0, 2 ) ) || ( '_wp_attachment_image_alt' == self::$query_parameters['orderby'] ) ) {
1800
  $orderby = self::MLA_ORDERBY_SUBQUERY . '.meta_value';
1838
  public static function mla_query_posts_groupby_filter( $groupby_clause ) {
1839
  global $wpdb;
1840
 
1841
+ if ( ( ! empty( self::$query_parameters[self::MLA_TABLE_VIEW_SUBQUERY] ) ) || ( ! empty( self::$query_parameters[self::MLA_ALT_TEXT_SUBQUERY] ) ) || ( ! empty( self::$query_parameters[self::MLA_FILE_SUBQUERY] ) ) || ( ! empty( self::$query_parameters[self::MLA_ORDERBY_SUBQUERY] ) ) || isset( self::$search_parameters['tax_terms_count'] ) ) {
1842
  $groupby_clause = "{$wpdb->posts}.ID";
1843
  }
1844
 
includes/class-mla-data.php CHANGED
@@ -694,7 +694,7 @@ class MLAData {
694
  while ( $index < strlen( $argument_string ) ) {
695
  $byte = $argument_string[ $index++ ];
696
  if ( '\\' == $byte ) {
697
- switch ( $source_string[ $index ] ) {
698
  case 'n':
699
  $argument .= chr( 0x0A );
700
  break;
@@ -1373,8 +1373,8 @@ class MLAData {
1373
  * ['mla_terms_search']['radio_phrases'] => AND/OR
1374
  * ['mla_terms_search']['radio_terms'] => AND/OR
1375
  * ['s'] => numeric for ID/parent search
1376
- * ['mla_search_fields'] => 'content', 'title', 'excerpt', 'alt-text', 'name', 'terms'
1377
- * Note: 'alt-text' is not supported in [mla_gallery]
1378
  * ['mla_search_connector'] => AND/OR
1379
  * ['sentence'] => entire string must match as one "keyword"
1380
  * ['exact'] => entire string must match entire field value
694
  while ( $index < strlen( $argument_string ) ) {
695
  $byte = $argument_string[ $index++ ];
696
  if ( '\\' == $byte ) {
697
+ switch ( $argument_string[ $index ] ) {
698
  case 'n':
699
  $argument .= chr( 0x0A );
700
  break;
1373
  * ['mla_terms_search']['radio_phrases'] => AND/OR
1374
  * ['mla_terms_search']['radio_terms'] => AND/OR
1375
  * ['s'] => numeric for ID/parent search
1376
+ * ['mla_search_fields'] => 'title', 'name', 'alt-text', 'excerpt', 'content', 'file' ,'terms'
1377
+ * Note: 'alt-text' and 'file' are not supported in [mla_gallery]
1378
  * ['mla_search_connector'] => AND/OR
1379
  * ['sentence'] => entire string must match as one "keyword"
1380
  * ['exact'] => entire string must match entire field value
includes/class-mla-edit-media.php CHANGED
@@ -313,7 +313,7 @@ class MLAEdit {
313
  $page_template_array = MLACore::mla_load_template( 'mla-add-new-bulk-edit.tpl' );
314
  if ( ! is_array( $page_template_array ) ) {
315
  /* translators: 1: ERROR tag 2: function name 3: non-array value */
316
- error_log( sprintf( _x( '%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'MLAEdit::mla_post_upload_ui', var_export( $page_template_array, true ) ), 0 );
317
  return;
318
  }
319
 
@@ -551,9 +551,9 @@ class MLAEdit {
551
  echo '<input name="mla_source" type="hidden" id="mla_source" value="' . $_REQUEST['mla_source'] . '" />';
552
  }
553
 
554
- echo '<a href="' . add_query_arg( $view_args, wp_nonce_url( 'upload.php?mla_admin_action=' . MLA::MLA_ADMIN_SINGLE_CUSTOM_FIELD_MAP, MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ) ) . '" title="' . __( 'Map Custom Field metadata for this item', 'media-library-assistant' ) . '">' . __( 'Map Custom Field metadata', 'media-library-assistant' ) . '</a><br>';
555
 
556
- echo '<a href="' . add_query_arg( $view_args, wp_nonce_url( 'upload.php?mla_admin_action=' . MLA::MLA_ADMIN_SINGLE_MAP, MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ) ) . '" title="' . __( 'Map IPTC/EXIF metadata for this item', 'media-library-assistant' ) . '">' . __( 'Map IPTC/EXIF metadata', 'media-library-assistant' ) . '</a>';
557
 
558
  echo "</span>\n";
559
  echo "</div><!-- .misc-pub-section -->\n";
@@ -728,7 +728,7 @@ class MLAEdit {
728
  );
729
  } else {
730
  /* translators: 1: ERROR tag 2: function name 3: template key */
731
- error_log( sprintf( _x( '%1$s: %2$s discarding "%3$s"; no title/order', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'mla_edit_add_help_tab', $id ), 0 );
732
  }
733
  }
734
 
@@ -768,7 +768,7 @@ class MLAEdit {
768
  );
769
  } else {
770
  /* translators: 1: ERROR tag 2: function name 3: template key */
771
- error_log( sprintf( _x( '%1$s: %2$s discarding "%3$s"; no title/order', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'mla_edit_add_help_tab', $id ), 0 );
772
  }
773
  }
774
 
313
  $page_template_array = MLACore::mla_load_template( 'mla-add-new-bulk-edit.tpl' );
314
  if ( ! is_array( $page_template_array ) ) {
315
  /* translators: 1: ERROR tag 2: function name 3: non-array value */
316
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'MLAEdit::mla_post_upload_ui', var_export( $page_template_array, true ) ), MLACore::MLA_DEBUG_CATEGORY_ANY );
317
  return;
318
  }
319
 
551
  echo '<input name="mla_source" type="hidden" id="mla_source" value="' . $_REQUEST['mla_source'] . '" />';
552
  }
553
 
554
+ echo '<a href="' . add_query_arg( $view_args, wp_nonce_url( 'upload.php?mla_admin_action=' . MLACore::MLA_ADMIN_SINGLE_CUSTOM_FIELD_MAP, MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ) ) . '" title="' . __( 'Map Custom Field metadata for this item', 'media-library-assistant' ) . '">' . __( 'Map Custom Field metadata', 'media-library-assistant' ) . '</a><br>';
555
 
556
+ echo '<a href="' . add_query_arg( $view_args, wp_nonce_url( 'upload.php?mla_admin_action=' . MLACore::MLA_ADMIN_SINGLE_MAP, MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ) ) . '" title="' . __( 'Map IPTC/EXIF metadata for this item', 'media-library-assistant' ) . '">' . __( 'Map IPTC/EXIF metadata', 'media-library-assistant' ) . '</a>';
557
 
558
  echo "</span>\n";
559
  echo "</div><!-- .misc-pub-section -->\n";
728
  );
729
  } else {
730
  /* translators: 1: ERROR tag 2: function name 3: template key */
731
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: %2$s discarding "%3$s"; no title/order', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'mla_edit_add_help_tab', $id ), MLACore::MLA_DEBUG_CATEGORY_ANY );
732
  }
733
  }
734
 
768
  );
769
  } else {
770
  /* translators: 1: ERROR tag 2: function name 3: template key */
771
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: %2$s discarding "%3$s"; no title/order', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'mla_edit_add_help_tab', $id ), MLACore::MLA_DEBUG_CATEGORY_ANY );
772
  }
773
  }
774
 
includes/class-mla-image-processor.php CHANGED
@@ -100,11 +100,6 @@ class MLAImageProcessor {
100
  /*
101
  * Look for exec() - from http://stackoverflow.com/a/12980534/866618
102
  */
103
- if ( ini_get('safe_mode') ) {
104
- self::_mla_debug_add( 'MLAImageProcessor::_ghostscript_convert safe_mode failure' );
105
- return false;
106
- }
107
-
108
  $blacklist = preg_split( '/,\s*/', ini_get('disable_functions') . ',' . ini_get('suhosin.executor.func.blacklist') );
109
  if ( in_array('exec', $blacklist) ) {
110
  self::_mla_debug_add( 'MLAImageProcessor::_ghostscript_convert blacklist failure' );
@@ -228,6 +223,14 @@ class MLAImageProcessor {
228
  * @return void
229
  */
230
  private static function _prepare_image( $width, $height, $best_fit, $type, $quality ) {
 
 
 
 
 
 
 
 
231
  if ( is_callable( array( self::$image, 'scaleImage' ) ) ) {
232
  if ( 0 < $width && 0 < $height ) {
233
  // Both are set; use them as-is
@@ -242,8 +245,10 @@ class MLAImageProcessor {
242
  self::$image->scaleImage( 0, $height );
243
  }
244
  } else {
245
- // Neither is specified, apply defaults
246
- self::$image->scaleImage( 150, 0 );
 
 
247
  }
248
  }
249
 
@@ -355,6 +360,14 @@ class MLAImageProcessor {
355
  $best_fit = isset( $args['best_fit'] ) ? (boolean) $args['best_fit'] : false;
356
  $ghostscript_path = isset( $args['ghostscript_path'] ) ? $args['ghostscript_path'] : '';
357
 
 
 
 
 
 
 
 
 
358
  /*
359
  * Convert the file to an image format and load it
360
  */
@@ -365,11 +378,11 @@ class MLAImageProcessor {
365
  * this must be called before reading the image, otherwise has no effect -
366
  * "-density {$x_resolution}x{$y_resolution}"
367
  * this is important to give good quality output, otherwise text might be unclear
368
- * default resolution is 72,72
369
  */
370
  self::$image->setResolution( $resolution, $resolution );
371
 
372
- $result = self::_ghostscript_convert( $input_file, $frame, $resolution, $type, $ghostscript_path );
373
 
374
  if ( false === $result ) {
375
  try {
@@ -379,7 +392,7 @@ class MLAImageProcessor {
379
  self::$image->readImage( $input_file . '[0]' );
380
  }
381
 
382
- if ( 'image/jpeg' == $type ) {
383
  $extension = 'JPG';
384
  } else {
385
  $extension = 'PNG';
@@ -397,7 +410,8 @@ class MLAImageProcessor {
397
  }
398
 
399
  /*
400
- * Prepare the output image; resize and flatten, if necessary
 
401
  */
402
  try {
403
  self::_prepare_image( $width, $height, $best_fit, $type, $quality );
@@ -412,6 +426,7 @@ class MLAImageProcessor {
412
  try {
413
  $output_file = wp_tempnam( $input_file );
414
  self::$image->writeImage( $output_file );
 
415
  }
416
  catch ( Exception $e ) {
417
  @unlink( $output_file );
@@ -421,10 +436,12 @@ class MLAImageProcessor {
421
  // array based on $_FILE as seen in PHP file uploads
422
  $results = array(
423
  'name' => basename( $input_file ),
424
- 'type' => $type,
425
  'tmp_name' => $output_file,
426
  'error' => 0,
427
  'size' => filesize( $output_file ),
 
 
428
  );
429
 
430
  return $results;
100
  /*
101
  * Look for exec() - from http://stackoverflow.com/a/12980534/866618
102
  */
 
 
 
 
 
103
  $blacklist = preg_split( '/,\s*/', ini_get('disable_functions') . ',' . ini_get('suhosin.executor.func.blacklist') );
104
  if ( in_array('exec', $blacklist) ) {
105
  self::_mla_debug_add( 'MLAImageProcessor::_ghostscript_convert blacklist failure' );
223
  * @return void
224
  */
225
  private static function _prepare_image( $width, $height, $best_fit, $type, $quality ) {
226
+ //error_log( __LINE__ . " MLAImageProcessor::_prepare_image( {$width}, {$height}, {$best_fit}, {$type}, {$quality} )", 0 );
227
+ if ( 'WordPress' == $type ) {
228
+ $default_width = 0;
229
+ $type = 'image/jpeg';
230
+ } else {
231
+ $default_width = 150;
232
+ }
233
+
234
  if ( is_callable( array( self::$image, 'scaleImage' ) ) ) {
235
  if ( 0 < $width && 0 < $height ) {
236
  // Both are set; use them as-is
245
  self::$image->scaleImage( 0, $height );
246
  }
247
  } else {
248
+ // Neither is specified, apply defaults; ( 0, 0 ) is invalid.
249
+ if ( $default_width ) {
250
+ self::$image->scaleImage( $default_width, 0 );
251
+ }
252
  }
253
  }
254
 
360
  $best_fit = isset( $args['best_fit'] ) ? (boolean) $args['best_fit'] : false;
361
  $ghostscript_path = isset( $args['ghostscript_path'] ) ? $args['ghostscript_path'] : '';
362
 
363
+ // Retain WordPress type for _prepare_image and adjust defaults
364
+ if ( 'WordPress' === $type ) {
365
+ $mime_type = 'image/jpeg';
366
+ $resolution = isset( $args['resolution'] ) ? abs( intval( $args['resolution'] ) ) : 128;
367
+ } else {
368
+ $mime_type = $type;
369
+ }
370
+
371
  /*
372
  * Convert the file to an image format and load it
373
  */
378
  * this must be called before reading the image, otherwise has no effect -
379
  * "-density {$x_resolution}x{$y_resolution}"
380
  * this is important to give good quality output, otherwise text might be unclear
381
+ * default resolution is 72,72 or 128,128 for WordPress thumbnails
382
  */
383
  self::$image->setResolution( $resolution, $resolution );
384
 
385
+ $result = self::_ghostscript_convert( $input_file, $frame, $resolution, $mime_type, $ghostscript_path );
386
 
387
  if ( false === $result ) {
388
  try {
392
  self::$image->readImage( $input_file . '[0]' );
393
  }
394
 
395
+ if ( 'image/jpeg' == $mime_type ) {
396
  $extension = 'JPG';
397
  } else {
398
  $extension = 'PNG';
410
  }
411
 
412
  /*
413
+ * Prepare the output image; resize and flatten, if necessary.
414
+ * $type retains "WordPress" selection
415
  */
416
  try {
417
  self::_prepare_image( $width, $height, $best_fit, $type, $quality );
426
  try {
427
  $output_file = wp_tempnam( $input_file );
428
  self::$image->writeImage( $output_file );
429
+ $dimensions = self::$image->getImageGeometry();
430
  }
431
  catch ( Exception $e ) {
432
  @unlink( $output_file );
436
  // array based on $_FILE as seen in PHP file uploads
437
  $results = array(
438
  'name' => basename( $input_file ),
439
+ 'type' => $mime_type,
440
  'tmp_name' => $output_file,
441
  'error' => 0,
442
  'size' => filesize( $output_file ),
443
+ 'width' => $dimensions['width'],
444
+ 'height' => $dimensions['height'],
445
  );
446
 
447
  return $results;
includes/class-mla-list-table.php CHANGED
@@ -1439,31 +1439,54 @@ class MLA_List_Table extends WP_List_Table {
1439
  */
1440
  function column_attached_to( $item ) {
1441
  if ( isset( $item->parent_title ) ) {
1442
- $parent_title = sprintf( '<a href="%1$s" title="' . __( 'Edit', 'media-library-assistant' ) . ' &#8220;%2$s&#8221;">%3$s</a>', esc_url( add_query_arg( array(
1443
- 'post' => $item->post_parent,
1444
- 'action' => 'edit'
1445
- ), 'post.php' ) ), esc_attr( $item->parent_title ), esc_attr( $item->parent_title ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1446
 
1447
- if ( isset( $item->parent_date ) ) {
1448
- $parent_date = $item->parent_date;
1449
  } else {
1450
  $parent_date = '';
1451
  }
1452
 
1453
- if ( isset( $item->parent_type ) ) {
1454
- $parent_type = '(' . $item->parent_type . ' ' . (string) $item->post_parent . self::_format_post_status( $item->parent_status ) . ')';
1455
  } else {
1456
  $parent_type = '';
1457
  }
1458
 
1459
- $parent = sprintf( '%1$s<br>%2$s<br>%3$s', /*%1$s*/ $parent_title, /*%2$s*/ mysql2date( __( 'Y/m/d', 'media-library-assistant' ), $parent_date ), /*%3$s*/ $parent_type ); // . "<br>\r\n";
1460
  } else {
1461
  $parent = '(' . _x( 'Unattached', 'table_view_singular', 'media-library-assistant' ) . ')';
1462
  }
1463
 
1464
- $set_parent = sprintf( '<a class="hide-if-no-js" id="mla-child-%2$s" onclick="mla.inlineEditAttachment.tableParentOpen( \'%1$s\',\'%2$s\',\'%3$s\' ); return false;" href="#the-list">%4$s</a><br>', /*%1$s*/ $item->post_parent, /*%2$s*/ $item->ID, /*%3$s*/ _draft_or_post_title( $item ), /*%4$s*/ __( 'Set Parent', 'media-library-assistant' ) );
 
 
 
 
1465
 
1466
- return $parent . "<br>\n" . $set_parent . "\n";
1467
  }
1468
 
1469
  /**
1439
  */
1440
  function column_attached_to( $item ) {
1441
  if ( isset( $item->parent_title ) ) {
1442
+ $parent_type = get_post_type_object( $item->parent_type );
1443
+ if ( $parent_type ) {
1444
+ $user_can_edit_parent = $parent_type->show_ui && current_user_can( 'edit_post', $item->post_parent );
1445
+ if ( $parent_type->show_ui ) {
1446
+ $user_can_read_parent = current_user_can( 'read_post', $item->post_parent );
1447
+ } else {
1448
+ $user_can_read_parent = true;
1449
+ }
1450
+ } else {
1451
+ $user_can_edit_parent = false;
1452
+ $user_can_read_parent = false;
1453
+ }
1454
+
1455
+ if ( $user_can_edit_parent ) {
1456
+ $parent_title = sprintf( '<a href="%1$s" title="' . __( 'Edit', 'media-library-assistant' ) . ' &#8220;%2$s&#8221;">%3$s</a>', esc_url( add_query_arg( array(
1457
+ 'post' => $item->post_parent,
1458
+ 'action' => 'edit'
1459
+ ), 'post.php' ) ), esc_attr( $item->parent_title ), esc_attr( $item->parent_title ) );
1460
+ } elseif ( $user_can_read_parent ) {
1461
+ $parent_title = esc_attr( $item->parent_title );
1462
+ } else {
1463
+ $parent_title = __( '(Private post)' );
1464
+ }
1465
 
1466
+ if ( isset( $item->parent_date ) && $user_can_read_parent ) {
1467
+ $parent_date = '<br>' . mysql2date( __( 'Y/m/d', 'media-library-assistant' ), $item->parent_date );
1468
  } else {
1469
  $parent_date = '';
1470
  }
1471
 
1472
+ if ( isset( $item->parent_type ) && $user_can_read_parent ) {
1473
+ $parent_type = '<br>(' . $item->parent_type . ' ' . (string) $item->post_parent . self::_format_post_status( $item->parent_status ) . ')';
1474
  } else {
1475
  $parent_type = '';
1476
  }
1477
 
1478
+ $parent = sprintf( '%1$s%2$s%3$s', /*%1$s*/ $parent_title, /*%2$s*/ $parent_date, /*%3$s*/ $parent_type ); // . "<br>\r\n";
1479
  } else {
1480
  $parent = '(' . _x( 'Unattached', 'table_view_singular', 'media-library-assistant' ) . ')';
1481
  }
1482
 
1483
+ if ( current_user_can( 'edit_post', $item->ID ) ) {
1484
+ $set_parent = "<br>\n" . sprintf( '<a class="hide-if-no-js" id="mla-child-%2$s" onclick="mla.inlineEditAttachment.tableParentOpen( \'%1$s\',\'%2$s\',\'%3$s\' ); return false;" href="#the-list">%4$s</a><br>', /*%1$s*/ $item->post_parent, /*%2$s*/ $item->ID, /*%3$s*/ _draft_or_post_title( $item ), /*%4$s*/ __( 'Set Parent', 'media-library-assistant' ) );
1485
+ } else {
1486
+ $set_parent = '';
1487
+ }
1488
 
1489
+ return $parent . $set_parent . "\n";
1490
  }
1491
 
1492
  /**
includes/class-mla-main.php CHANGED
@@ -21,13 +21,6 @@ if ( !function_exists( 'post_categories_meta_box' ) ) {
21
  * @since 0.1
22
  */
23
  class MLA {
24
-
25
- /*
26
- * Current version number (moved to class-mla-core.php)
27
- * @since 0.1
28
- */
29
- // const CURRENT_MLA_VERSION
30
-
31
  /**
32
  * Current date for Development Version, empty for production versions
33
  *
@@ -37,12 +30,6 @@ class MLA {
37
  */
38
  const MLA_DEVELOPMENT_VERSION = '';
39
 
40
- /**
41
- * Slug for registering and enqueueing plugin style sheets (moved to class-mla-core.php)
42
- * @since 0.1
43
- */
44
- // const STYLESHEET_SLUG
45
-
46
  /**
47
  * Object name for localizing JavaScript - MLA List Table
48
  *
@@ -52,64 +39,6 @@ class MLA {
52
  */
53
  const JAVASCRIPT_INLINE_EDIT_OBJECT = 'mla_inline_edit_vars';
54
 
55
- /**
56
- * mla_admin_action value to display a single item for editing
57
- *
58
- * Used by class-mla-view-list-table.php and class-mla-upload-list-table.php
59
- *
60
- * @since 0.1
61
- *
62
- * @var string
63
- */
64
- const MLA_ADMIN_SINGLE_EDIT_DISPLAY = 'single_item_edit_display';
65
-
66
- /**
67
- * mla_admin_action value for updating a single item
68
- *
69
- * Used by class-mla-view-list-table.php and class-mla-upload-list-table.php
70
- *
71
- * @since 0.1
72
- *
73
- * @var string
74
- */
75
- const MLA_ADMIN_SINGLE_EDIT_UPDATE = 'single_item_edit_update';
76
-
77
- /**
78
- * mla_admin_action value for mapping Custom Field metadata
79
- *
80
- * @since 1.10
81
- *
82
- * @var string
83
- */
84
- const MLA_ADMIN_SINGLE_CUSTOM_FIELD_MAP = 'single_item_custom_field_map';
85
-
86
- /**
87
- * mla_admin_action value for mapping IPTC/EXIF metadata
88
- *
89
- * @since 1.00
90
- *
91
- * @var string
92
- */
93
- const MLA_ADMIN_SINGLE_MAP = 'single_item_map';
94
-
95
- /**
96
- * mla_admin_action value for setting an item's parent object
97
- *
98
- * @since 1.82
99
- *
100
- * @var string
101
- */
102
- const MLA_ADMIN_SET_PARENT = 'set_parent';
103
-
104
- /**
105
- * mla_admin_action value for searching taxonomy terms
106
- *
107
- * @since 1.90
108
- *
109
- * @var string
110
- */
111
- const MLA_ADMIN_TERMS_SEARCH = 'terms_search';
112
-
113
  /**
114
  * Holds screen ids to match help text to corresponding screen
115
  *
@@ -184,10 +113,6 @@ class MLA {
184
  MLA_WPML::initialize();
185
  }
186
  } elseif ( is_object( $polylang ) ) {
187
- if ( class_exists( 'MLAPolylangSupport' ) ) {
188
- self::$mla_language_support_error_messages .= '<li>class MLAPolylangSupport in plugin "MLA Polylang Support"</li>';
189
- }
190
-
191
  if ( class_exists( 'MLA_Polylang' ) ) {
192
  self::$mla_language_support_error_messages .= "<li>class MLA_Polylang</li>";
193
  }
@@ -243,7 +168,7 @@ class MLA {
243
 
244
  if ( apply_filters( 'mla_list_table_admin_action', true, $_REQUEST['mla_admin_action'], ( isset( $_REQUEST['mla_item_ID'] ) ? $_REQUEST['mla_item_ID'] : 0 ) ) ) {
245
  switch ( $_REQUEST['mla_admin_action'] ) {
246
- case self::MLA_ADMIN_SINGLE_CUSTOM_FIELD_MAP:
247
  do_action( 'mla_begin_mapping', 'single_custom', $_REQUEST['mla_item_ID'] );
248
  $updates = MLAOptions::mla_evaluate_custom_field_mapping( $_REQUEST['mla_item_ID'], 'single_attachment_mapping' );
249
  do_action( 'mla_end_mapping' );
@@ -255,7 +180,7 @@ class MLA {
255
  $view_args = isset( $_REQUEST['mla_source'] ) ? array( 'mla_source' => $_REQUEST['mla_source']) : array();
256
  wp_redirect( add_query_arg( $view_args, admin_url( 'post.php' ) . '?post=' . $_REQUEST['mla_item_ID'] . '&action=edit&message=101' ), 302 );
257
  exit;
258
- case self::MLA_ADMIN_SINGLE_MAP:
259
  $item = get_post( $_REQUEST['mla_item_ID'] );
260
  do_action( 'mla_begin_mapping', 'single_iptc_exif', $_REQUEST['mla_item_ID'] );
261
  $updates = MLAOptions::mla_evaluate_iptc_exif_mapping( $item, 'iptc_exif_mapping' );
@@ -680,7 +605,7 @@ class MLA {
680
  );
681
  } else {
682
  /* translators: 1: ERROR tag 2: function name 3: template key */
683
- error_log( sprintf( _x( '%1$s: %2$s discarding "%3$s"; no title/order', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'mla_add_help_tab', $id ), 0 );
684
  }
685
  }
686
 
@@ -973,7 +898,7 @@ class MLA {
973
  */
974
  $tax_inputs = array();
975
  $tax_actions = array();
976
- MLACore::mla_debug_add( "mla_prepare_bulk_edits( {$post_id} ) tax_input = " . var_export( $request['tax_input'], true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
977
 
978
  if ( isset( $request['tax_input'] ) && is_array( $request['tax_input'] ) ) {
979
  foreach ( $request['tax_input'] as $taxonomy => $terms ) {
@@ -983,7 +908,7 @@ class MLA {
983
  $tax_action = 'replace';
984
  }
985
 
986
- MLACore::mla_debug_add( "mla_prepare_bulk_edits( {$post_id}, {$taxonomy}, {$tax_action} ) terms = " . var_export( $terms, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
987
 
988
  /*
989
  * Ignore empty updates
@@ -1037,7 +962,7 @@ class MLA {
1037
  $current_terms[ $new_term->name ] = $new_term->name;
1038
  }
1039
  }
1040
- MLACore::mla_debug_add( "mla_prepare_bulk_edits( {$post_id}, {$taxonomy}, {$tax_action} ) current_terms = " . var_export( $current_terms, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1041
 
1042
  if ( 'add' == $tax_action ) {
1043
  /*
@@ -1078,8 +1003,8 @@ class MLA {
1078
  $do_update = ! empty( $current_terms );
1079
  }
1080
 
1081
- MLACore::mla_debug_add( "mla_prepare_bulk_edits( {$post_id}, {$taxonomy}, {$tax_action} ) do_update = " . var_export( $do_update, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1082
- MLACore::mla_debug_add( "mla_prepare_bulk_edits( {$post_id}, {$taxonomy}, {$tax_action} ) new terms = " . var_export( $terms, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1083
 
1084
  if ( $do_update ) {
1085
  $tax_inputs[ $taxonomy ] = $terms;
@@ -1120,7 +1045,7 @@ class MLA {
1120
  }
1121
 
1122
  $request = apply_filters( 'mla_list_table_bulk_action_initial_request', $request, $bulk_action, $custom_field_map );
1123
- MLACore::mla_debug_add( 'mla_process_bulk_action $request = ' . var_export( $request, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1124
 
1125
  if ( isset( $request['cb_attachment'] ) ) {
1126
  $item_content = apply_filters( 'mla_list_table_begin_bulk_action', NULL, $bulk_action );
@@ -1185,14 +1110,14 @@ class MLA {
1185
  }
1186
 
1187
  $new_data = self::mla_prepare_bulk_edits( $post_id, $request, $custom_field_map );
1188
- MLACore::mla_debug_add( "mla_process_bulk_action( {$post_id} ) new_data = " . var_export( $new_data, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1189
  $tax_input = $new_data['tax_input'];
1190
  $tax_action = $new_data['tax_action'];
1191
  unset( $new_data['tax_input'] );
1192
  unset( $new_data['tax_action'] );
1193
 
1194
  $item_content = MLAData::mla_update_single_item( $post_id, $new_data, $tax_input, $tax_action );
1195
- MLACore::mla_debug_add( "mla_process_bulk_action( {$post_id} ) item_content = " . var_export( $item_content, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1196
  break;
1197
  case 'restore':
1198
  $item_content = self::_restore_single_item( $post_id );
@@ -1286,7 +1211,7 @@ class MLA {
1286
  unset( $_REQUEST['action2'] );
1287
  }
1288
 
1289
- MLACore::mla_debug_add( 'mla_process_bulk_action returning $page_content = ' . var_export( $page_content, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1290
  return $page_content;
1291
  }
1292
 
@@ -1451,7 +1376,7 @@ class MLA {
1451
  case MLACore::MLA_ADMIN_SINGLE_TRASH:
1452
  $page_content = self::_trash_single_item( $_REQUEST['mla_item_ID'] );
1453
  break;
1454
- case self::MLA_ADMIN_SET_PARENT:
1455
  $new_data = array( 'post_parent' => $_REQUEST['found_post_id'] );
1456
 
1457
  foreach( $_REQUEST['children'] as $child ) {
@@ -1466,7 +1391,7 @@ class MLA {
1466
  unset( $_REQUEST['found_post_id'] );
1467
  unset( $_REQUEST['mla-set-parent-submit'] );
1468
  break;
1469
- case self::MLA_ADMIN_TERMS_SEARCH:
1470
  /*
1471
  * This will be handled as a database query argument,
1472
  * but validate the arguments here
@@ -1616,8 +1541,6 @@ class MLA {
1616
  * @return void echo json results or error message, then die()
1617
  */
1618
  private static function _bulk_edit_ajax_handler() {
1619
- MLACore::mla_debug_add( '_bulk_edit_ajax_handler $_REQUEST = ' . var_export( $_REQUEST, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1620
-
1621
  /*
1622
  * The category taxonomy (edit screens) is a special case because
1623
  * post_categories_meta_box() changes the input name
@@ -1763,10 +1686,13 @@ class MLA {
1763
  }
1764
 
1765
  if ( ! $prevent_default ) {
 
1766
  $results = MLAData::mla_update_single_item( $post_id, $_REQUEST, $_REQUEST['tax_input'] );
 
1767
  }
1768
 
1769
  $new_item = (object) MLAData::mla_get_attachment_by_id( $post_id );
 
1770
 
1771
  // Create an instance of our package class and echo the new HTML
1772
  $MLAListTable = apply_filters( 'mla_list_table_new_instance', NULL );
@@ -1831,7 +1757,7 @@ class MLA {
1831
  $set_parent_template = MLACore::mla_load_template( 'admin-set-parent-form.tpl' );
1832
  if ( ! is_array( $set_parent_template ) ) {
1833
  /* translators: 1: ERROR tag 2: function name 3: non-array value */
1834
- 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 );
1835
  return '';
1836
  }
1837
 
@@ -1869,7 +1795,7 @@ class MLA {
1869
 
1870
  $page_values = array(
1871
  'mla_set_parent_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' ) ) ),
1872
- 'mla_set_parent_action' => self::MLA_ADMIN_SET_PARENT,
1873
  'wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
1874
  'mla_set_parent_div' => $set_parent_div,
1875
  );
@@ -1906,7 +1832,7 @@ class MLA {
1906
  $page_template_array = MLACore::mla_load_template( 'admin-inline-edit-form.tpl' );
1907
  if ( ! is_array( $page_template_array ) ) {
1908
  /* translators: 1: ERROR tag 2: function name 3: non-array value */
1909
- 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( $page_template_array, true ) ), 0 );
1910
  return '';
1911
  }
1912
 
21
  * @since 0.1
22
  */
23
  class MLA {
 
 
 
 
 
 
 
24
  /**
25
  * Current date for Development Version, empty for production versions
26
  *
30
  */
31
  const MLA_DEVELOPMENT_VERSION = '';
32
 
 
 
 
 
 
 
33
  /**
34
  * Object name for localizing JavaScript - MLA List Table
35
  *
39
  */
40
  const JAVASCRIPT_INLINE_EDIT_OBJECT = 'mla_inline_edit_vars';
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  /**
43
  * Holds screen ids to match help text to corresponding screen
44
  *
113
  MLA_WPML::initialize();
114
  }
115
  } elseif ( is_object( $polylang ) ) {
 
 
 
 
116
  if ( class_exists( 'MLA_Polylang' ) ) {
117
  self::$mla_language_support_error_messages .= "<li>class MLA_Polylang</li>";
118
  }
168
 
169
  if ( apply_filters( 'mla_list_table_admin_action', true, $_REQUEST['mla_admin_action'], ( isset( $_REQUEST['mla_item_ID'] ) ? $_REQUEST['mla_item_ID'] : 0 ) ) ) {
170
  switch ( $_REQUEST['mla_admin_action'] ) {
171
+ case MLACore::MLA_ADMIN_SINGLE_CUSTOM_FIELD_MAP:
172
  do_action( 'mla_begin_mapping', 'single_custom', $_REQUEST['mla_item_ID'] );
173
  $updates = MLAOptions::mla_evaluate_custom_field_mapping( $_REQUEST['mla_item_ID'], 'single_attachment_mapping' );
174
  do_action( 'mla_end_mapping' );
180
  $view_args = isset( $_REQUEST['mla_source'] ) ? array( 'mla_source' => $_REQUEST['mla_source']) : array();
181
  wp_redirect( add_query_arg( $view_args, admin_url( 'post.php' ) . '?post=' . $_REQUEST['mla_item_ID'] . '&action=edit&message=101' ), 302 );
182
  exit;
183
+ case MLACore::MLA_ADMIN_SINGLE_MAP:
184
  $item = get_post( $_REQUEST['mla_item_ID'] );
185
  do_action( 'mla_begin_mapping', 'single_iptc_exif', $_REQUEST['mla_item_ID'] );
186
  $updates = MLAOptions::mla_evaluate_iptc_exif_mapping( $item, 'iptc_exif_mapping' );
605
  );
606
  } else {
607
  /* translators: 1: ERROR tag 2: function name 3: template key */
608
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: %2$s discarding "%3$s"; no title/order', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'mla_add_help_tab', $id ), MLACore::MLA_DEBUG_CATEGORY_ANY );
609
  }
610
  }
611
 
898
  */
899
  $tax_inputs = array();
900
  $tax_actions = array();
901
+ MLACore::mla_debug_add( __LINE__ . " MLA::mla_prepare_bulk_edits( {$post_id} ) tax_input = " . var_export( $request['tax_input'], true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
902
 
903
  if ( isset( $request['tax_input'] ) && is_array( $request['tax_input'] ) ) {
904
  foreach ( $request['tax_input'] as $taxonomy => $terms ) {
908
  $tax_action = 'replace';
909
  }
910
 
911
+ MLACore::mla_debug_add( __LINE__ . " MLA::mla_prepare_bulk_edits( {$post_id}, {$taxonomy}, {$tax_action} ) terms = " . var_export( $terms, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
912
 
913
  /*
914
  * Ignore empty updates
962
  $current_terms[ $new_term->name ] = $new_term->name;
963
  }
964
  }
965
+ MLACore::mla_debug_add( __LINE__ . " MLA::mla_prepare_bulk_edits( {$post_id}, {$taxonomy}, {$tax_action} ) current_terms = " . var_export( $current_terms, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
966
 
967
  if ( 'add' == $tax_action ) {
968
  /*
1003
  $do_update = ! empty( $current_terms );
1004
  }
1005
 
1006
+ MLACore::mla_debug_add( __LINE__ . " MLA::mla_prepare_bulk_edits( {$post_id}, {$taxonomy}, {$tax_action} ) do_update = " . var_export( $do_update, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1007
+ MLACore::mla_debug_add( __LINE__ . " MLA::mla_prepare_bulk_edits( {$post_id}, {$taxonomy}, {$tax_action} ) new terms = " . var_export( $terms, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1008
 
1009
  if ( $do_update ) {
1010
  $tax_inputs[ $taxonomy ] = $terms;
1045
  }
1046
 
1047
  $request = apply_filters( 'mla_list_table_bulk_action_initial_request', $request, $bulk_action, $custom_field_map );
1048
+ MLACore::mla_debug_add( __LINE__ . " MLA::mla_process_bulk_action request = " . var_export( $request, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1049
 
1050
  if ( isset( $request['cb_attachment'] ) ) {
1051
  $item_content = apply_filters( 'mla_list_table_begin_bulk_action', NULL, $bulk_action );
1110
  }
1111
 
1112
  $new_data = self::mla_prepare_bulk_edits( $post_id, $request, $custom_field_map );
1113
+ MLACore::mla_debug_add( __LINE__ . " MLA::mla_process_bulk_action( {$post_id} ) new_data = " . var_export( $new_data, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1114
  $tax_input = $new_data['tax_input'];
1115
  $tax_action = $new_data['tax_action'];
1116
  unset( $new_data['tax_input'] );
1117
  unset( $new_data['tax_action'] );
1118
 
1119
  $item_content = MLAData::mla_update_single_item( $post_id, $new_data, $tax_input, $tax_action );
1120
+ MLACore::mla_debug_add( __LINE__ . " MLA::mla_process_bulk_action( {$post_id} ) item_content = " . var_export( $item_content, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1121
  break;
1122
  case 'restore':
1123
  $item_content = self::_restore_single_item( $post_id );
1211
  unset( $_REQUEST['action2'] );
1212
  }
1213
 
1214
+ MLACore::mla_debug_add( __LINE__ . " MLA::mla_process_bulk_action returning page_content = " . var_export( $page_content, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1215
  return $page_content;
1216
  }
1217
 
1376
  case MLACore::MLA_ADMIN_SINGLE_TRASH:
1377
  $page_content = self::_trash_single_item( $_REQUEST['mla_item_ID'] );
1378
  break;
1379
+ case MLACore::MLA_ADMIN_SET_PARENT:
1380
  $new_data = array( 'post_parent' => $_REQUEST['found_post_id'] );
1381
 
1382
  foreach( $_REQUEST['children'] as $child ) {
1391
  unset( $_REQUEST['found_post_id'] );
1392
  unset( $_REQUEST['mla-set-parent-submit'] );
1393
  break;
1394
+ case MLACore::MLA_ADMIN_TERMS_SEARCH:
1395
  /*
1396
  * This will be handled as a database query argument,
1397
  * but validate the arguments here
1541
  * @return void echo json results or error message, then die()
1542
  */
1543
  private static function _bulk_edit_ajax_handler() {
 
 
1544
  /*
1545
  * The category taxonomy (edit screens) is a special case because
1546
  * post_categories_meta_box() changes the input name
1686
  }
1687
 
1688
  if ( ! $prevent_default ) {
1689
+ MLACore::mla_debug_add( __LINE__ . " MLA::mla_inline_edit_ajax_action( {$post_id} ) \$_REQUEST = " . var_export( $_REQUEST, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1690
  $results = MLAData::mla_update_single_item( $post_id, $_REQUEST, $_REQUEST['tax_input'] );
1691
+ MLACore::mla_debug_add( __LINE__ . " MLA::mla_inline_edit_ajax_action( {$post_id} ) results = " . var_export( $results, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1692
  }
1693
 
1694
  $new_item = (object) MLAData::mla_get_attachment_by_id( $post_id );
1695
+ MLACore::mla_debug_add( __LINE__ . " MLA::mla_inline_edit_ajax_action( {$post_id} ) new_item = " . var_export( $new_item, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1696
 
1697
  // Create an instance of our package class and echo the new HTML
1698
  $MLAListTable = apply_filters( 'mla_list_table_new_instance', NULL );
1757
  $set_parent_template = MLACore::mla_load_template( 'admin-set-parent-form.tpl' );
1758
  if ( ! is_array( $set_parent_template ) ) {
1759
  /* translators: 1: ERROR tag 2: function name 3: non-array value */
1760
+ MLACore::mla_debug_add( 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 ) ), MLACore::MLA_DEBUG_CATEGORY_ANY );
1761
  return '';
1762
  }
1763
 
1795
 
1796
  $page_values = array(
1797
  'mla_set_parent_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' ) ) ),
1798
+ 'mla_set_parent_action' => MLACore::MLA_ADMIN_SET_PARENT,
1799
  'wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
1800
  'mla_set_parent_div' => $set_parent_div,
1801
  );
1832
  $page_template_array = MLACore::mla_load_template( 'admin-inline-edit-form.tpl' );
1833
  if ( ! is_array( $page_template_array ) ) {
1834
  /* translators: 1: ERROR tag 2: function name 3: non-array value */
1835
+ MLACore::mla_debug_add( 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( $page_template_array, true ) ), MLACore::MLA_DEBUG_CATEGORY_ANY );
1836
  return '';
1837
  }
1838
 
includes/class-mla-media-modal.php CHANGED
@@ -572,7 +572,7 @@ class MLAModal {
572
  $page_template_array = MLACore::mla_load_template( 'admin-terms-search-form.tpl' );
573
  if ( ! is_array( $page_template_array ) ) {
574
  /* translators: 1: ERROR tag 2: function name 3: non-array value */
575
- 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 );
576
  return '';
577
  }
578
 
@@ -620,7 +620,7 @@ class MLAModal {
620
 
621
  $page_values = array(
622
  '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' ) ) ),
623
- 'mla_terms_search_action' => MLA::MLA_ADMIN_TERMS_SEARCH,
624
  'wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
625
  'mla_terms_search_div' => $terms_search_tpl,
626
  );
572
  $page_template_array = MLACore::mla_load_template( 'admin-terms-search-form.tpl' );
573
  if ( ! is_array( $page_template_array ) ) {
574
  /* translators: 1: ERROR tag 2: function name 3: non-array value */
575
+ MLACore::mla_debug_add( 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 ) ), MLACore::MLA_DEBUG_CATEGORY_ANY );
576
  return '';
577
  }
578
 
620
 
621
  $page_values = array(
622
  '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' ) ) ),
623
+ 'mla_terms_search_action' => MLACore::MLA_ADMIN_TERMS_SEARCH,
624
  'wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
625
  'mla_terms_search_div' => $terms_search_tpl,
626
  );
includes/class-mla-mime-types.php CHANGED
@@ -22,6 +22,10 @@ class MLAMime {
22
  * @return void
23
  */
24
  public static function initialize() {
 
 
 
 
25
  // add_filter( 'sanitize_mime_type', 'MLAMime::mla_sanitize_mime_type_filter', 0x7FFFFFFF, 2 );
26
  add_filter( 'ext2type', 'MLAMime::mla_ext2type_filter', 0x7FFFFFFF, 1 );
27
  // add_filter( 'wp_check_filetype_and_ext', 'MLAMime::mla_wp_check_filetype_and_ext_filter', 0x7FFFFFFF, 4 );
@@ -249,7 +253,7 @@ class MLAMime {
249
  * provided by Multisite Super Admins at wp-admin/network/settings.php." Multisite installs must
250
  * respect this restriction, so any list we produce will be passed thru that function if it exists.
251
  *
252
- * This function is defined as public because it's a filter.
253
  *
254
  * @since 1.40
255
  *
@@ -456,6 +460,250 @@ class MLAMime {
456
  return $icon;
457
  } // mla_wp_mime_type_icon_filter
458
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
459
  /**
460
  * Sanitize and expand query arguments from request variables
461
  *
@@ -474,7 +722,7 @@ class MLAMime {
474
  */
475
  if ( ! is_array( $raw_request ) ) {
476
  /* translators: 1: ERROR tag 2: function name 3: non-array value */
477
- error_log( sprintf( _x( '%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'MLAMime::_prepare_view_items_query', var_export( $raw_request, true ) ), 0 );
478
  return NULL;
479
  }
480
 
@@ -490,7 +738,7 @@ class MLAMime {
490
  if ( 'none' == $value ) {
491
  $clean_request[ $key ] = $value;
492
  } else {
493
- $sortable_columns = MLA_View_List_Table::mla_get_sortable_columns();
494
  foreach ($sortable_columns as $sort_key => $sort_value ) {
495
  if ( $value == $sort_value[0] ) {
496
  $clean_request[ $key ] = $value;
@@ -978,7 +1226,7 @@ class MLAMime {
978
  }
979
 
980
  if ( !empty( $specification ) ) {
981
- $result = MLACore::mla_parse_view_specification( $request['specification'] );
982
  if ( isset( $result['error'] ) ) {
983
  $errors .= $result['error'];
984
  }
@@ -1127,7 +1375,7 @@ class MLAMime {
1127
  */
1128
  if ( ! is_array( $raw_request ) ) {
1129
  /* translators: 1: ERROR tag 2: function name 3: non-array value */
1130
- error_log( sprintf( _x( '%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'MLAMime::_prepare_upload_items_query', var_export( $raw_request, true ) ), 0 );
1131
  return NULL;
1132
  }
1133
 
@@ -1147,7 +1395,7 @@ class MLAMime {
1147
  if ( 'none' == $value ) {
1148
  $clean_request[ $key ] = $value;
1149
  } else {
1150
- $sortable_columns = MLA_Upload_List_Table::mla_get_sortable_columns();
1151
  foreach ($sortable_columns as $sort_key => $sort_value ) {
1152
  if ( $value == $sort_value[0] ) {
1153
  $clean_request[ $key ] = $value;
@@ -2327,7 +2575,7 @@ class MLAMime {
2327
  */
2328
  if ( ! is_array( $raw_request ) ) {
2329
  /* translators: 1: ERROR tag 2: function name 3: non-array value */
2330
- error_log( sprintf( _x( '%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'MLAMime::_prepare_optional_upload_items_query', var_export( $raw_request, true ) ), 0 );
2331
  return NULL;
2332
  }
2333
 
@@ -2343,7 +2591,7 @@ class MLAMime {
2343
  if ( 'none' == $value ) {
2344
  $clean_request[ $key ] = $value;
2345
  } else {
2346
- $sortable_columns = MLA_Upload_Optional_List_Table::mla_get_sortable_columns();
2347
  foreach ($sortable_columns as $sort_key => $sort_value ) {
2348
  if ( $value == $sort_value[0] ) {
2349
  $clean_request[ $key ] = $value;
22
  * @return void
23
  */
24
  public static function initialize() {
25
+ self::_localize_default_upload_columns();
26
+ self::_localize_default_upload_optional_columns();
27
+ self::_localize_default_view_columns();
28
+
29
  // add_filter( 'sanitize_mime_type', 'MLAMime::mla_sanitize_mime_type_filter', 0x7FFFFFFF, 2 );
30
  add_filter( 'ext2type', 'MLAMime::mla_ext2type_filter', 0x7FFFFFFF, 1 );
31
  // add_filter( 'wp_check_filetype_and_ext', 'MLAMime::mla_wp_check_filetype_and_ext_filter', 0x7FFFFFFF, 4 );
253
  * provided by Multisite Super Admins at wp-admin/network/settings.php." Multisite installs must
254
  * respect this restriction, so any list we produce will be passed thru that function if it exists.
255
  *
256
+ * Defined as public because it's a filter.
257
  *
258
  * @since 1.40
259
  *
460
  return $icon;
461
  } // mla_wp_mime_type_icon_filter
462
 
463
+ /**
464
+ * Table column definitions, Settings/Uploads tab table
465
+ *
466
+ * This array defines table columns and titles where the key is the column slug (and class)
467
+ * and the value is the column's title text.
468
+ *
469
+ * All of the columns are added to this array by
470
+ * MLAMime::_localize_default_upload_columns.
471
+ *
472
+ * @since 1.40
473
+ *
474
+ * @var array
475
+ */
476
+ public static $default_upload_columns = array();
477
+
478
+ /**
479
+ * Sortable column definitions, Settings/Uploads tab table
480
+ *
481
+ * This array defines the table columns that can be sorted. The array key
482
+ * is the column slug that needs to be sortable, and the value is database column
483
+ * to sort by. Often, the key and value will be the same, but this is not always
484
+ * the case (as the value is a column name from the database, not the list table).
485
+ *
486
+ * The array value also contains a boolean which is 'true' if the data is currently
487
+ * sorted by that column. This is computed each time the table is displayed.
488
+ *
489
+ * @since 1.40
490
+ *
491
+ * @var array
492
+ */
493
+ public static $default_sortable_upload_columns = array(
494
+ 'name' => array('slug',false),
495
+ 'mime_type' => array('mime_type',false),
496
+ 'icon_type' => array('icon_type',false),
497
+ 'source' => array('source',false),
498
+ 'status' => array('disabled',false),
499
+ 'core_type' => array('core_type',false),
500
+ 'mla_type' => array('mla_type',false),
501
+ 'standard_source' => array('standard_source',false),
502
+ 'core_icon_type' => array('core_icon_type',false),
503
+ 'description' => array('description',false)
504
+ );
505
+
506
+ /**
507
+ * Builds the $default_upload_columns array with translated source texts.
508
+ *
509
+ * @since 1.71
510
+ *
511
+ * @return void
512
+ */
513
+ public static function _localize_default_upload_columns( ) {
514
+ /*
515
+ * Build the default columns array at runtime to accomodate calls to the localization functions
516
+ */
517
+ self::$default_upload_columns = array(
518
+ 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
519
+ 'icon' => '',
520
+ 'name' => _x( 'Extension', 'list_table_column', 'media-library-assistant' ),
521
+ 'mime_type' => _x( 'MIME Type', 'list_table_column', 'media-library-assistant' ),
522
+ 'icon_type' => _x( 'Icon Type', 'list_table_column', 'media-library-assistant' ),
523
+ 'source' => _x( 'Source', 'list_table_column', 'media-library-assistant' ),
524
+ 'status' => _x( 'Status', 'list_table_column', 'media-library-assistant' ),
525
+ 'core_type' => _x( 'WordPress Type', 'list_table_column', 'media-library-assistant' ),
526
+ 'mla_type' => _x( 'MLA Type', 'list_table_column', 'media-library-assistant' ),
527
+ 'standard_source' => _x( 'Std. Source', 'list_table_column', 'media-library-assistant' ),
528
+ 'core_icon_type' => _x( 'Std. Icon Type', 'list_table_column', 'media-library-assistant' ),
529
+ 'description' => _x( 'Description', 'list_table_column', 'media-library-assistant' )
530
+ );
531
+ }
532
+
533
+ /**
534
+ * Return the names and display values of the sortable columns
535
+ *
536
+ * @since 1.40
537
+ *
538
+ * @return array name => array( orderby value, heading ) for sortable columns
539
+ */
540
+ private static function _get_sortable_upload_columns( ) {
541
+ $results = array() ;
542
+
543
+ foreach ( self::$default_sortable_upload_columns as $key => $value ) {
544
+ $value[1] = self::$default_upload_columns[ $key ];
545
+ $results[ $key ] = $value;
546
+ }
547
+
548
+ return $results;
549
+ }
550
+
551
+ /**
552
+ * Table column definitions
553
+ *
554
+ * This array defines table columns and titles where the key is the column slug (and class)
555
+ * and the value is the column's title text.
556
+ *
557
+ * All of the columns are added to this array by
558
+ * MLAMime::_localize_default_upload_optional_columns.
559
+ *
560
+ * @since 1.40
561
+ *
562
+ * @var array
563
+ */
564
+ public static $default_upload_optional_columns = array();
565
+
566
+ /**
567
+ * Sortable column definitions
568
+ *
569
+ * This array defines the table columns that can be sorted. The array key
570
+ * is the column slug that needs to be sortable, and the value is database column
571
+ * to sort by. Often, the key and value will be the same, but this is not always
572
+ * the case (as the value is a column name from the database, not the list table).
573
+ *
574
+ * The array value also contains a boolean which is 'true' if the data is currently
575
+ * sorted by that column. This is computed each time the table is displayed.
576
+ *
577
+ * @since 1.40
578
+ *
579
+ * @var array
580
+ */
581
+ public static $default_upload_optional_sortable_columns = array(
582
+ 'name' => array('slug',false),
583
+ 'mime_type' => array('mime_type',false),
584
+ 'core_type' => array('core_type',false),
585
+ 'mla_type' => array('mla_type',false),
586
+ 'description' => array('description',false)
587
+ );
588
+
589
+ /**
590
+ * Builds the $default_upload_optional_columns array with translated source texts.
591
+ *
592
+ * @since 1.71
593
+ *
594
+ * @return void
595
+ */
596
+ private static function _localize_default_upload_optional_columns( ) {
597
+ // Build the default columns array at runtime to accomodate calls to the localization functions
598
+ self::$default_upload_optional_columns = array(
599
+ 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
600
+ 'name' => _x( 'Extension', 'list_table_column', 'media-library-assistant' ),
601
+ 'mime_type' => _x( 'MIME Type', 'list_table_column', 'media-library-assistant' ),
602
+ 'core_type' => _x( 'WordPress Type', 'list_table_column', 'media-library-assistant' ),
603
+ 'mla_type' => _x( 'MLA Type', 'list_table_column', 'media-library-assistant' ),
604
+ 'description' => _x( 'Description', 'list_table_column', 'media-library-assistant' )
605
+ );
606
+ }
607
+
608
+ /**
609
+ * Return the names and display values of the sortable columns
610
+ *
611
+ * @since 1.40
612
+ *
613
+ * @return array name => array( orderby value, heading ) for sortable columns
614
+ */
615
+ private static function _get_sortable_upload_optional_columns( ) {
616
+ $results = array() ;
617
+
618
+ foreach ( self::$default_upload_optional_sortable_columns as $key => $value ) {
619
+ $value[1] = self::$default_upload_optional_columns[ $key ];
620
+ $results[ $key ] = $value;
621
+ }
622
+
623
+ return $results;
624
+ }
625
+
626
+ /**
627
+ * Table column definitions, Settings/Views tab table
628
+ *
629
+ * This array defines table columns and titles where the key is the column slug
630
+ * (and class) and the value is the column's title text.
631
+ *
632
+ * All of the columns are added to this array by
633
+ * MLAMime::_localize_default_view_columns.
634
+ *
635
+ * @since 1.40
636
+ *
637
+ * @var array
638
+ */
639
+ public static $default_view_columns = array();
640
+
641
+ /**
642
+ * Sortable column definitions, Settings/Views tab table
643
+ *
644
+ * This array defines the table columns that can be sorted. The array key
645
+ * is the column slug that needs to be sortable, and the value is database column
646
+ * to sort by. Often, the key and value will be the same, but this is not always
647
+ * the case (as the value is a column name from the database, not the list table).
648
+ *
649
+ * The array value also contains a boolean which is 'true' if the data is currently
650
+ * sorted by that column. This is computed each time the table is displayed.
651
+ *
652
+ * @since 1.40
653
+ *
654
+ * @var array
655
+ */
656
+ public static $default_sortable_view_columns = array(
657
+ 'name' => array('slug',false),
658
+ 'specification' => array('specification',false),
659
+ 'post_mime_type' => array('post_mime_type',false),
660
+ 'table_view' => array('table_view',false),
661
+ 'singular' => array('singular',false),
662
+ 'plural' => array('plural',false),
663
+ 'menu_order' => array('menu_order',false),
664
+ 'description' => array('description',false)
665
+ );
666
+
667
+ /**
668
+ * Builds the $default_view_columns array with translated source texts.
669
+ *
670
+ * @since 1.71
671
+ *
672
+ * @return void
673
+ */
674
+ private static function _localize_default_view_columns( ) {
675
+ // Build the default columns array at runtime to accomodate calls to the localization functions
676
+ self::$default_view_columns = array(
677
+ 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
678
+ 'name' => _x( 'Slug', 'list_table_column', 'media-library-assistant' ),
679
+ 'specification' => _x( 'Specification', 'list_table_column', 'media-library-assistant' ),
680
+ 'post_mime_type' => _x( 'Post Mime', 'list_table_column', 'media-library-assistant' ),
681
+ 'table_view' => _x( 'Table View', 'list_table_column', 'media-library-assistant' ),
682
+ 'singular' => _x( 'Singular Name', 'list_table_column', 'media-library-assistant' ),
683
+ 'plural' => _x( 'Plural Name', 'list_table_column', 'media-library-assistant' ),
684
+ 'menu_order' => _x( 'Order', 'list_table_column', 'media-library-assistant' ),
685
+ 'description' => _x( 'Description', 'list_table_column', 'media-library-assistant' )
686
+ );
687
+ }
688
+
689
+ /**
690
+ * Return the names and display values of the sortable columns
691
+ *
692
+ * @since 1.40
693
+ *
694
+ * @return array name => array( orderby value, heading ) for sortable columns
695
+ */
696
+ private static function _get_sortable_view_columns( ) {
697
+ $results = array() ;
698
+
699
+ foreach ( self::$default_sortable_view_columns as $key => $value ) {
700
+ $value[1] = self::$default_view_columns[ $key ];
701
+ $results[ $key ] = $value;
702
+ }
703
+
704
+ return $results;
705
+ }
706
+
707
  /**
708
  * Sanitize and expand query arguments from request variables
709
  *
722
  */
723
  if ( ! is_array( $raw_request ) ) {
724
  /* translators: 1: ERROR tag 2: function name 3: non-array value */
725
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'MLAMime::_prepare_view_items_query', var_export( $raw_request, true ) ), MLACore::MLA_DEBUG_CATEGORY_ANY );
726
  return NULL;
727
  }
728
 
738
  if ( 'none' == $value ) {
739
  $clean_request[ $key ] = $value;
740
  } else {
741
+ $sortable_columns = self::_get_sortable_view_columns();
742
  foreach ($sortable_columns as $sort_key => $sort_value ) {
743
  if ( $value == $sort_value[0] ) {
744
  $clean_request[ $key ] = $value;
1226
  }
1227
 
1228
  if ( !empty( $specification ) ) {
1229
+ $result = MLACore::mla_parse_view_specification( $specification );
1230
  if ( isset( $result['error'] ) ) {
1231
  $errors .= $result['error'];
1232
  }
1375
  */
1376
  if ( ! is_array( $raw_request ) ) {
1377
  /* translators: 1: ERROR tag 2: function name 3: non-array value */
1378
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'MLAMime::_prepare_upload_items_query', var_export( $raw_request, true ) ), MLACore::MLA_DEBUG_CATEGORY_ANY );
1379
  return NULL;
1380
  }
1381
 
1395
  if ( 'none' == $value ) {
1396
  $clean_request[ $key ] = $value;
1397
  } else {
1398
+ $sortable_columns = self::_get_sortable_upload_columns();
1399
  foreach ($sortable_columns as $sort_key => $sort_value ) {
1400
  if ( $value == $sort_value[0] ) {
1401
  $clean_request[ $key ] = $value;
2575
  */
2576
  if ( ! is_array( $raw_request ) ) {
2577
  /* translators: 1: ERROR tag 2: function name 3: non-array value */
2578
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'MLAMime::_prepare_optional_upload_items_query', var_export( $raw_request, true ) ), MLACore::MLA_DEBUG_CATEGORY_ANY );
2579
  return NULL;
2580
  }
2581
 
2591
  if ( 'none' == $value ) {
2592
  $clean_request[ $key ] = $value;
2593
  } else {
2594
+ $sortable_columns = self::_get_sortable_upload_optional_columns();
2595
  foreach ($sortable_columns as $sort_key => $sort_value ) {
2596
  if ( $value == $sort_value[0] ) {
2597
  $clean_request[ $key ] = $value;
includes/class-mla-objects.php CHANGED
@@ -133,7 +133,10 @@ class MLAObjects {
133
  }
134
 
135
  if ( isset ( $columns[ 'posts' ] ) ) {
136
- unset( $columns[ 'posts' ] );
 
 
 
137
  }
138
 
139
  $columns[ 'attachments' ] = __( 'Attachments', 'media-library-assistant' );
@@ -235,7 +238,7 @@ class MLAObjects {
235
 
236
  if ( is_wp_error( $term ) ) {
237
  /* translators: 1: ERROR tag 2: taxonomy 3: error message */
238
- 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 );
239
  return 0;
240
  } elseif ($count_terms ) {
241
  $column_text = number_format_i18n( 0 );
133
  }
134
 
135
  if ( isset ( $columns[ 'posts' ] ) ) {
136
+ $wp_taxonomy = in_array( $taxonomy, array( 'category', 'post_tag' ) );
137
+ if ( ! ( $wp_taxonomy && ( 'checked' === MLACore::mla_get_option( MLACoreOptions::MLA_SHOW_COUNT_COLUMN ) ) ) ) {
138
+ unset( $columns[ 'posts' ] );
139
+ }
140
  }
141
 
142
  $columns[ 'attachments' ] = __( 'Attachments', 'media-library-assistant' );
238
 
239
  if ( is_wp_error( $term ) ) {
240
  /* translators: 1: ERROR tag 2: taxonomy 3: error message */
241
+ MLACore::mla_debug_add( 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() ), MLACore::MLA_DEBUG_CATEGORY_ANY );
242
  return 0;
243
  } elseif ($count_terms ) {
244
  $column_text = number_format_i18n( 0 );
includes/class-mla-options.php CHANGED
@@ -16,271 +16,6 @@
16
  * @since 1.00
17
  */
18
  class MLAOptions {
19
- /**
20
- * Provides a unique name for the current version option
21
- */
22
- const MLA_VERSION_OPTION = MLACoreOptions::MLA_VERSION_OPTION; // 'current_version';
23
-
24
- /**
25
- * Provides a unique name for the exclude revisions option
26
- */
27
- const MLA_EXCLUDE_REVISIONS = MLACoreOptions::MLA_EXCLUDE_REVISIONS; // 'exclude_revisions';
28
-
29
- /**
30
- * Provides a unique name for a database tuning option
31
- */
32
- const MLA_FEATURED_IN_TUNING = MLACoreOptions::MLA_FEATURED_IN_TUNING; // 'featured_in_tuning';
33
-
34
- /**
35
- * Provides a unique name for a database tuning option
36
- */
37
- const MLA_INSERTED_IN_TUNING = MLACoreOptions::MLA_INSERTED_IN_TUNING; // 'inserted_in_tuning';
38
-
39
- /**
40
- * Provides a unique name for a database tuning option
41
- */
42
- const MLA_GALLERY_IN_TUNING = MLACoreOptions::MLA_GALLERY_IN_TUNING; // 'gallery_in_tuning';
43
-
44
- /**
45
- * Provides a unique name for a database tuning option
46
- */
47
- const MLA_MLA_GALLERY_IN_TUNING = MLACoreOptions::MLA_MLA_GALLERY_IN_TUNING; // 'mla_gallery_in_tuning';
48
-
49
- /**
50
- * Provides a unique name for the taxonomy count Attachments option
51
- */
52
- const MLA_COUNT_TERM_ATTACHMENTS = MLACoreOptions::MLA_COUNT_TERM_ATTACHMENTS; // 'count_term_attachments';
53
-
54
- /**
55
- * Provides a unique name for the taxonomy support option
56
- */
57
- const MLA_TAXONOMY_SUPPORT = MLACoreOptions::MLA_TAXONOMY_SUPPORT; // 'taxonomy_support';
58
-
59
- /**
60
- * Provides a unique name for the admin screen page title option
61
- */
62
- const MLA_SCREEN_PAGE_TITLE = MLACoreOptions::MLA_SCREEN_PAGE_TITLE; // 'admin_screen_page_title';
63
-
64
- /**
65
- * Provides a unique name for the admin screen menu title option
66
- */
67
- const MLA_SCREEN_MENU_TITLE = MLACoreOptions::MLA_SCREEN_MENU_TITLE; // 'admin_screen_menu_title';
68
-
69
- /**
70
- * Provides a unique name for the admin screen menu order option
71
- */
72
- const MLA_SCREEN_ORDER = MLACoreOptions::MLA_SCREEN_ORDER; // 'admin_screen_menu_order';
73
-
74
- /**
75
- * Provides a unique name for the admin screen remove Media/Library option
76
- */
77
- const MLA_SCREEN_DISPLAY_LIBRARY = MLACoreOptions::MLA_SCREEN_DISPLAY_LIBRARY; // 'admin_screen_display_default';
78
-
79
- /**
80
- * Provides a unique name for the default orderby option
81
- */
82
- const MLA_DEFAULT_ORDERBY = MLACoreOptions::MLA_DEFAULT_ORDERBY; // 'default_orderby';
83
-
84
- /**
85
- * Provides a unique name for the default order option
86
- */
87
- const MLA_DEFAULT_ORDER = MLACoreOptions::MLA_DEFAULT_ORDER; // 'default_order';
88
-
89
- /**
90
- * Provides a unique name for the Media/Assistant submenu table views width option
91
- */
92
- const MLA_TABLE_VIEWS_WIDTH = MLACoreOptions::MLA_TABLE_VIEWS_WIDTH; // 'table_views_width';
93
-
94
- /**
95
- * Provides a unique name for the Media/Assistant submenu table thumbnail/icon size option
96
- */
97
- const MLA_TABLE_ICON_SIZE = MLACoreOptions::MLA_TABLE_ICON_SIZE; // 'table_icon_size';
98
-
99
- /**
100
- * Provides a unique name for the Bulk Update and Map All chunk size option
101
- */
102
- const MLA_BULK_CHUNK_SIZE = MLACoreOptions::MLA_BULK_CHUNK_SIZE; // 'bulk_chunk_size';
103
-
104
- /**
105
- * Provides a unique name for the taxonomy filter maximum depth option
106
- */
107
- const MLA_TAXONOMY_FILTER_DEPTH = MLACoreOptions::MLA_TAXONOMY_FILTER_DEPTH; // 'taxonomy_filter_depth';
108
-
109
- /**
110
- * Provides a unique name for the taxonomy filter maximum depth option
111
- */
112
- const MLA_TAXONOMY_FILTER_INCLUDE_CHILDREN = MLACoreOptions::MLA_TAXONOMY_FILTER_INCLUDE_CHILDREN; // 'taxonomy_filter_include_children';
113
-
114
- /**
115
- * Provides a unique name for the display Search Media controls option
116
- */
117
- const MLA_SEARCH_MEDIA_FILTER_SHOW_CONTROLS = MLACoreOptions::MLA_SEARCH_MEDIA_FILTER_SHOW_CONTROLS; // 'search_media_filter_show_controls';
118
-
119
- /**
120
- * Provides a unique name for the display Search Media controls option
121
- */
122
- const MLA_SEARCH_MEDIA_FILTER_DEFAULTS = MLACoreOptions::MLA_SEARCH_MEDIA_FILTER_DEFAULTS; // 'search_media_filter_defaults';
123
-
124
- /**
125
- * Provides a "size" attribute value for the EXIF/Template Value field
126
- */
127
- const MLA_EXIF_SIZE = MLACoreOptions::MLA_EXIF_SIZE; // 30;
128
-
129
- /**
130
- * Provides a unique name for the Custom Field "new rule" key
131
- */
132
- const MLA_NEW_CUSTOM_RULE = MLACoreOptions::MLA_NEW_CUSTOM_RULE; // '__NEW_RULE__';
133
-
134
- /**
135
- * Provides a unique name for the Custom Field "new field" key
136
- */
137
- const MLA_NEW_CUSTOM_FIELD = MLACoreOptions::MLA_NEW_CUSTOM_FIELD; // '__NEW_FIELD__';
138
-
139
- /**
140
- * Provides a unique name for the "searchable taxonomies" option
141
- */
142
- const MLA_EDIT_MEDIA_SEARCH_TAXONOMY = MLACoreOptions::MLA_EDIT_MEDIA_SEARCH_TAXONOMY; // 'edit_media_search_taxonomy';
143
-
144
- /**
145
- * Provides a unique name for the Edit Media additional meta boxes option
146
- */
147
- const MLA_EDIT_MEDIA_META_BOXES = MLACoreOptions::MLA_EDIT_MEDIA_META_BOXES; // 'edit_media_meta_boxes';
148
-
149
- /**
150
- * Provides a unique name for the Media/Add New bulk edit option
151
- */
152
- const MLA_ADD_NEW_BULK_EDIT = MLACoreOptions::MLA_ADD_NEW_BULK_EDIT; // 'add_new_bulk_edit';
153
-
154
- /**
155
- * Provides a unique name for the Media/Add New bulk edit "on top" option
156
- */
157
- const MLA_ADD_NEW_BULK_EDIT_ON_TOP = MLACoreOptions::MLA_ADD_NEW_BULK_EDIT_ON_TOP; // 'add_new_bulk_edit_on_top';
158
-
159
- /**
160
- * Provides a unique name for the Media Grid toolbar option, which
161
- * also controls the ATTACHMENT DETAILS enhancements
162
- */
163
- const MLA_MEDIA_GRID_TOOLBAR = MLACoreOptions::MLA_MEDIA_GRID_TOOLBAR; // 'media_grid_toolbar';
164
-
165
- /**
166
- * Provides a unique name for the Media Manager toolbar option, which
167
- * also controls the ATTACHMENT DETAILS enhancements
168
- */
169
- const MLA_MEDIA_MODAL_TOOLBAR = MLACoreOptions::MLA_MEDIA_MODAL_TOOLBAR; // 'media_modal_toolbar';
170
-
171
- /**
172
- * Provides a unique name for the Media Manager toolbar MIME Types option
173
- */
174
- const MLA_MEDIA_MODAL_MIMETYPES = MLACoreOptions::MLA_MEDIA_MODAL_MIMETYPES; // 'media_modal_mimetypes';
175
-
176
- /**
177
- * Provides a unique name for the Media Manager toolbar Month and Year option
178
- */
179
- const MLA_MEDIA_MODAL_MONTHS = MLACoreOptions::MLA_MEDIA_MODAL_MONTHS; // 'media_modal_months';
180
-
181
- /**
182
- * Provides a unique name for the Media Manager toolbar Taxonomy Terms option
183
- */
184
- const MLA_MEDIA_MODAL_TERMS = MLACoreOptions::MLA_MEDIA_MODAL_TERMS; // 'media_modal_terms';
185
-
186
- /**
187
- * Provides a unique name for the Media Manager toolbar Taxonomy "Terms Search" option
188
- */
189
- const MLA_MEDIA_MODAL_TERMS_SEARCH = MLACoreOptions::MLA_MEDIA_MODAL_TERMS_SEARCH; // 'media_modal_terms_search';
190
-
191
- /**
192
- * Provides a unique name for the Media Manager toolbar Search Box option
193
- */
194
- const MLA_MEDIA_MODAL_SEARCHBOX = MLACoreOptions::MLA_MEDIA_MODAL_SEARCHBOX; // 'media_modal_searchbox';
195
-
196
- /**
197
- * Provides a unique name for the Media Manager toolbar Search Box Controls option
198
- */
199
- const MLA_MEDIA_MODAL_SEARCHBOX_CONTROLS = MLACoreOptions::MLA_MEDIA_MODAL_SEARCHBOX_CONTROLS; // 'media_modal_searchbox_controls';
200
-
201
- /**
202
- * Provides a unique name for the Media Manager Attachment Details searchable taxonomy option
203
- * This option is for hierarchical taxonomies, e.g., "Att. Categories".
204
- */
205
- const MLA_MEDIA_MODAL_DETAILS_CATEGORY_METABOX = MLACoreOptions::MLA_MEDIA_MODAL_DETAILS_CATEGORY_METABOX; // 'media_modal_details_category_metabox';
206
-
207
- /**
208
- * Provides a unique name for the Media Manager Attachment Details searchable taxonomy option
209
- * This option is for flat taxonomies, e.g., "Att. Tags".
210
- */
211
- const MLA_MEDIA_MODAL_DETAILS_TAG_METABOX = MLACoreOptions::MLA_MEDIA_MODAL_DETAILS_TAG_METABOX; // 'media_modal_details_tag_metabox';
212
-
213
- /**
214
- * Provides a unique name for the Media Manager Attachment Details auto-fill option
215
- */
216
- const MLA_MEDIA_MODAL_DETAILS_AUTOFILL = MLACoreOptions::MLA_MEDIA_MODAL_DETAILS_AUTOFILL; // 'media_modal_details_autofill';
217
-
218
- /**
219
- * Provides a unique name for the Media Manager orderby option
220
- */
221
- const MLA_MEDIA_MODAL_ORDERBY = MLACoreOptions::MLA_MEDIA_MODAL_ORDERBY; // 'media_modal_orderby';
222
-
223
- /**
224
- * Provides a unique name for the Media Manager order option
225
- */
226
- const MLA_MEDIA_MODAL_ORDER = MLACoreOptions::MLA_MEDIA_MODAL_ORDER; // 'media_modal_order';
227
-
228
- /**
229
- * Provides a unique name for the Post MIME Types option
230
- */
231
- const MLA_POST_MIME_TYPES = MLACoreOptions::MLA_POST_MIME_TYPES; // 'post_mime_types';
232
-
233
- /**
234
- * Provides a unique name for the Enable Post MIME Types option
235
- */
236
- const MLA_ENABLE_POST_MIME_TYPES = MLACoreOptions::MLA_ENABLE_POST_MIME_TYPES; // 'enable_post_mime_types';
237
-
238
- /**
239
- * Provides a unique name for the Upload MIME Types option
240
- */
241
- const MLA_UPLOAD_MIMES = MLACoreOptions::MLA_UPLOAD_MIMES; // 'upload_mimes';
242
-
243
- /**
244
- * Provides a unique name for the Enable Upload MIME Types option
245
- */
246
- const MLA_ENABLE_UPLOAD_MIMES = MLACoreOptions::MLA_ENABLE_UPLOAD_MIMES; // 'enable_upload_mimes';
247
-
248
- /**
249
- * Provides a unique name for the Enable MLA Icons option
250
- */
251
- const MLA_ENABLE_MLA_ICONS = MLACoreOptions::MLA_ENABLE_MLA_ICONS; // 'enable_mla_icons';
252
-
253
- /**
254
- * Provides a unique name for the Debug display limit option
255
- */
256
- const MLA_DEBUG_DISPLAY_LIMIT = MLACoreOptions::MLA_DEBUG_DISPLAY_LIMIT; // 'debug_display_limit';
257
-
258
- /**
259
- * Provides a unique name for the Debug alternate log file option
260
- */
261
- const MLA_DEBUG_FILE = MLACoreOptions::MLA_DEBUG_FILE; // 'debug_file';
262
-
263
- /**
264
- * Provides a unique name for the Debug replace PHP log file option
265
- */
266
- const MLA_DEBUG_REPLACE_PHP_LOG = MLACoreOptions::MLA_DEBUG_REPLACE_PHP_LOG; // 'debug_replace_php_log';
267
-
268
- /**
269
- * Provides a unique name for the Debug replace PHP error_reporting option
270
- */
271
- const MLA_DEBUG_REPLACE_PHP_REPORTING = MLACoreOptions::MLA_DEBUG_REPLACE_PHP_REPORTING; // 'debug_replace_php_reporting';
272
-
273
- /**
274
- * Provides a unique name for the Debug replace MLA_DEBUG_LEVEL option
275
- */
276
- const MLA_DEBUG_REPLACE_LEVEL = MLACoreOptions::MLA_DEBUG_REPLACE_LEVEL; // 'debug_replace_level';
277
-
278
- /**
279
- * $mla_option_definitions moved to MLACore::
280
- */
281
-
282
- //public static $mla_option_definitions = array ();
283
-
284
  /**
285
  * Initialization function, similar to __construct()
286
  *
@@ -727,6 +462,9 @@ class MLAOptions {
727
  'content_checked' => ( in_array( 'content', $search_fields ) ) ? 'checked="checked"' : '',
728
  'Description' => __( 'Description', 'media-library-assistant' ),
729
 
 
 
 
730
  'terms_checked' => ( in_array( 'terms', $search_fields ) ) ? 'checked="checked"' : '',
731
  'Terms' => __( 'Terms', 'media-library-assistant' ),
732
  'help' => MLACoreOptions::$mla_option_definitions[ MLACoreOptions::MLA_SEARCH_MEDIA_FILTER_DEFAULTS ]['help']
16
  * @since 1.00
17
  */
18
  class MLAOptions {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  /**
20
  * Initialization function, similar to __construct()
21
  *
462
  'content_checked' => ( in_array( 'content', $search_fields ) ) ? 'checked="checked"' : '',
463
  'Description' => __( 'Description', 'media-library-assistant' ),
464
 
465
+ 'file_checked' => ( in_array( 'file', $search_fields ) ) ? 'checked="checked"' : '',
466
+ 'File' => __( 'File', 'media-library-assistant' ),
467
+
468
  'terms_checked' => ( in_array( 'terms', $search_fields ) ) ? 'checked="checked"' : '',
469
  'Terms' => __( 'Terms', 'media-library-assistant' ),
470
  'help' => MLACoreOptions::$mla_option_definitions[ MLACoreOptions::MLA_SEARCH_MEDIA_FILTER_DEFAULTS ]['help']
includes/class-mla-polylang-shortcode-support.php ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Media Library Assistant Polylang Shortcode Support classes
4
+ *
5
+ * This file is conditionally loaded in MLAShortcodes::initialize after a check for Polylang presence.
6
+ *
7
+ * @package Media Library Assistant
8
+ * @since 2.40
9
+ */
10
+
11
+ /**
12
+ * Class MLA (Media Library Assistant) Polylang Shortcdxodes provides front-end support for the
13
+ * Polylang Multilingual plugin
14
+ *
15
+ * @package Media Library Assistant
16
+ * @since 2.40
17
+ */
18
+ class MLA_Polylang_Shortcodes {
19
+ /**
20
+ * Initialization function, similar to __construct()
21
+ *
22
+ * @since 2.40
23
+ *
24
+ * @return void
25
+ */
26
+ public static function initialize() {
27
+ /*
28
+ * Defined in /media-library-assistant/includes/class-mla-shortcode-support.php
29
+ */
30
+ add_filter( 'mla_get_terms_query_arguments', 'MLA_Polylang_Shortcodes::mla_get_terms_query_arguments', 10, 1 );
31
+ add_filter( 'mla_get_terms_clauses', 'MLA_Polylang_Shortcodes::mla_get_terms_clauses', 10, 1 );
32
+ }
33
+
34
+ /**
35
+ * MLA Tag Cloud Query Arguments
36
+ *
37
+ * Saves [mla_tag_cloud] query parameters for use in MLA_Polylang_Shortcodes::mla_get_terms_clauses.
38
+ *
39
+ * @since 2.40
40
+ * @uses MLA_Polylang_Shortcodes::$all_query_parameters
41
+ *
42
+ * @param array shortcode arguments merged with attachment selection defaults
43
+ */
44
+ public static function mla_get_terms_query_arguments( $all_query_parameters ) {
45
+ MLA_Polylang_Shortcodes::$all_query_parameters = $all_query_parameters;
46
+
47
+ return $all_query_parameters;
48
+ } // mla_get_terms_query_arguments
49
+
50
+ /**
51
+ * Save the query arguments
52
+ *
53
+ * @since 2.40
54
+ *
55
+ * @var array
56
+ */
57
+ private static $all_query_parameters = array();
58
+
59
+ /**
60
+ * MLA Tag Cloud Query Clauses
61
+ *
62
+ * Adds language-specific clauses to filter the cloud terms.
63
+ *
64
+ * @since 2.40
65
+ * @uses MLA_Polylang_Shortcodes::$all_query_parameters
66
+ *
67
+ * @param array SQL clauses ( 'fields', 'join', 'where', 'order', 'orderby', 'limits' )
68
+ */
69
+ public static function mla_get_terms_clauses( $clauses ) {
70
+ global $polylang;
71
+
72
+ $clauses = $polylang->filters->terms_clauses($clauses, MLA_Polylang_Shortcodes::$all_query_parameters['taxonomy'], MLA_Polylang_Shortcodes::$all_query_parameters );
73
+
74
+ return $clauses;
75
+ } // mla_get_terms_clauses
76
+ } // Class MLA_Polylang_Shortcodes
77
+ ?>
includes/class-mla-polylang-support.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Media Library Assistant Polylang Support classes
4
  *
5
  * This file is conditionally loaded in MLA::initialize after a check for Polylang presence.
6
  *
@@ -9,7 +9,7 @@
9
  */
10
 
11
  /**
12
- * Class MLA (Media Library Assistant) Polylang provides support for the
13
  * Polylang Multilingual plugin
14
  *
15
  * @package Media Library Assistant
@@ -45,16 +45,10 @@ class MLA_Polylang {
45
  self::$polylang_1dot8_plus = version_compare( POLYLANG_VERSION, '1.7.99', '>' );
46
 
47
  /*
48
- * The remaining filters are only useful for the admin section;
49
  * exit in the front-end posts/pages
50
  */
51
  if ( ! is_admin() ) {
52
- /*
53
- * Defined in /media-library-assistant/includes/class-mla-shortcodes.php
54
- */
55
- add_filter( 'mla_get_terms_query_arguments', 'MLA_Polylang::mla_get_terms_query_arguments', 10, 1 );
56
- add_filter( 'mla_get_terms_clauses', 'MLA_Polylang::mla_get_terms_clauses', 10, 1 );
57
-
58
  return;
59
  }
60
 
@@ -137,52 +131,6 @@ class MLA_Polylang {
137
  add_action( 'pll_translate_media', 'MLA_Polylang::pll_translate_media', 10, 3 );
138
  }
139
 
140
- /**
141
- * MLA Tag Cloud Query Arguments
142
- *
143
- * Saves [mla_tag_cloud] query parameters for use in MLA_Polylang::mla_get_terms_clauses.
144
- *
145
- * @since 2.11
146
- * @uses MLA_Polylang::$all_query_parameters
147
- *
148
- * @param array shortcode arguments merged with attachment selection defaults, so every possible parameter is present
149
- *
150
- * @return array updated attachment query arguments
151
- */
152
- public static function mla_get_terms_query_arguments( $all_query_parameters ) {
153
- MLA_Polylang::$all_query_parameters = $all_query_parameters;
154
-
155
- return $all_query_parameters;
156
- } // mla_get_terms_query_arguments
157
-
158
- /**
159
- * Save the query arguments
160
- *
161
- * @since 2.11
162
- *
163
- * @var array
164
- */
165
- private static $all_query_parameters = array();
166
-
167
- /**
168
- * MLA Tag Cloud Query Clauses
169
- *
170
- * Adds language-specific clauses to filter the cloud terms.
171
- *
172
- * @since 2.11
173
- *
174
- * @param array SQL clauses ( 'fields', 'join', 'where', 'order', 'orderby', 'limits' )
175
- *
176
- * @return array updated SQL clauses
177
- */
178
- public static function mla_get_terms_clauses( $clauses ) {
179
- global $polylang;
180
-
181
- $clauses = $polylang->filters->terms_clauses($clauses, MLA_Polylang::$all_query_parameters['taxonomy'], MLA_Polylang::$all_query_parameters );
182
-
183
- return $clauses;
184
- } // mla_get_terms_clauses
185
-
186
  /**
187
  * Load the plugin's Ajax handler(s)
188
  *
@@ -716,7 +664,90 @@ class MLA_Polylang {
716
  private static $relevant_terms = array();
717
 
718
  /**
719
- * Adds a term and its translations to $relevant_terms
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
720
  *
721
  * @since 2.11
722
  * @uses MLA_Polylang::$relevant_terms
@@ -752,8 +783,11 @@ class MLA_Polylang {
752
 
753
  self::$relevant_terms[ $term->term_taxonomy_id ]['term'] = $term;
754
  self::$relevant_terms[ $term->term_taxonomy_id ]['translations'] = $translations;
 
 
 
755
  }
756
-
757
  return self::$relevant_terms[ $term->term_taxonomy_id ];
758
  } // _add_relevant_term
759
 
@@ -809,22 +843,22 @@ class MLA_Polylang {
809
  if ( ( false === $relevant_term ) && $test_only ) {
810
  return false;
811
  }
 
812
 
813
  /*
814
  * If no match, try to add it and its translations
815
  */
816
  if ( ( false === $relevant_term ) && $candidate = get_term_by( $field, $value, $taxonomy ) ) {
 
817
  $relevant_term = self::_add_relevant_term( $candidate );
 
818
 
819
  foreach ( $relevant_term['translations'] as $translation ) {
820
- if ( get_term_by( 'id', $translation->element_id, $taxonomy, NULL, true ) ) {
821
- continue;
822
- }
823
-
824
  $term_object = get_term_by( 'id', $translation->element_id, $taxonomy );
825
  self::_add_relevant_term( $term_object, $relevant_term['translations'] );
826
  } // translation
827
  } // new term
 
828
 
829
  /*
830
  * Find the language-specific value, if requested
@@ -1034,9 +1068,11 @@ class MLA_Polylang {
1034
  * @param integer $post_id ID of the current post
1035
  * @param array $tax_inputs 'tax_input' request parameter
1036
  * @param array $tax_actions 'tax_action' request parameter
 
1037
  */
1038
- private static function _build_tax_input( $post_id, $tax_inputs = NULL, $tax_actions = NULL ) {
1039
  global $polylang;
 
1040
 
1041
  if ( $post_id == self::$tax_input['tax_input_post_id'] ) {
1042
  return;
@@ -1104,6 +1140,22 @@ class MLA_Polylang {
1104
  foreach ( $term_names as $term_name ) {
1105
  if ( ! empty( $term_name ) ) {
1106
  $relevant_term = self::_get_relevant_term( 'name', $term_name, $taxonomy );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1107
  if ( isset( $relevant_term['translations'] ) ) {
1108
  foreach ( $relevant_term['translations'] as $language => $translation ) {
1109
  if ( $translated_term = self::_get_relevant_term( 'id', $translation->element_id, $taxonomy ) ) {
@@ -1306,8 +1358,7 @@ class MLA_Polylang {
1306
  } // synch_inputs
1307
 
1308
  $post_id = self::$existing_terms[ $language ]['element_id'];
1309
- MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::_apply_synch_input( {$post_id} ) \$language = " . var_export( $language, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1310
- MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::_apply_synch_input( {$post_id} ) \$tax_inputs = " . var_export( $tax_inputs, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1311
  return $tax_inputs;
1312
  } // _apply_synch_input
1313
 
@@ -1356,7 +1407,7 @@ class MLA_Polylang {
1356
  * @param integer $result Zero if the update failed else ID of the item that was updated.
1357
  */
1358
  public static function mla_updated_single_item( $post_id, $result ) {
1359
- MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::mla_updated_single_item( {$post_id}, {$result} )", MLACore::MLA_DEBUG_CATEGORY_LANGUAGE );
1360
 
1361
  if ( self::$existing_terms['element_id'] == $post_id ) {
1362
  /*
@@ -1413,7 +1464,7 @@ class MLA_Polylang {
1413
  if ( ! empty( self::$bulk_edit_request['tax_input'] ) ) {
1414
  $tax_inputs = self::$bulk_edit_request['tax_input'];
1415
  if ( 'checked' == MLACore::mla_get_option( 'term_assignment', false, false, MLA_Polylang::$mla_language_option_definitions ) ) {
1416
- self::_build_tax_input( $post_id, $tax_inputs, self::$bulk_edit_request['tax_action'] );
1417
  $tax_inputs = self::_apply_tax_input( $post_id );
1418
  }
1419
  } else {
@@ -1537,8 +1588,9 @@ class MLA_Polylang {
1537
  } else {
1538
  $tax_inputs = array( $key => implode( ',', $terms ) );
1539
  }
 
1540
 
1541
- self::_build_tax_input( $post_id, $tax_inputs );
1542
  $tax_inputs = self::_apply_tax_input( $post_id );
1543
  $terms = $tax_inputs[ $key ];
1544
  } // term_assignment
@@ -1591,7 +1643,7 @@ class MLA_Polylang {
1591
 
1592
  if ( 'checked' == MLACore::mla_get_option( 'term_assignment', false, false, MLA_Polylang::$mla_language_option_definitions ) ) {
1593
  // Quick Edit calls update_single_item right after this filter
1594
- self::_build_tax_input( $post_id, $_REQUEST['tax_input'] );
1595
  $_REQUEST['tax_input'] = self::_apply_tax_input( $post_id );
1596
  }
1597
 
@@ -1682,7 +1734,7 @@ class MLA_Polylang {
1682
  */
1683
  if ( 'edit' == $bulk_action && ( ! empty( self::$bulk_edit_request['tax_input'] ) ) && ( 'checked' == MLACore::mla_get_option( 'term_assignment', false, false, MLA_Polylang::$mla_language_option_definitions ) ) ) {
1684
  self::_build_existing_terms( $post_id );
1685
- self::_build_tax_input( $post_id, self::$bulk_edit_request['tax_input'], $request['tax_action'] );
1686
  $request['tax_input'] = self::_apply_tax_input( $post_id );
1687
  foreach( self::$bulk_edit_request['tax_action'] as $taxonomy => $action ) {
1688
  // _apply_tax_input changes a remove to a replace
@@ -1730,7 +1782,8 @@ class MLA_Polylang {
1730
  $post = get_post( $post_id );
1731
  // save_post() does a check_admin_referer() security test
1732
  $_REQUEST['_wpnonce'] = wp_create_nonce( 'bulk-posts' );
1733
- $_REQUEST['bulk_edit'] = 'Update';
 
1734
  $polylang->filters_post->save_post( $post_id, $post, true );
1735
 
1736
  if ( $_REQUEST['inline_lang_choice'] != -1 ) {
@@ -1840,11 +1893,12 @@ class MLA_Polylang {
1840
  */
1841
  public static function mla_list_table_inline_values( $item_values ) {
1842
  global $polylang;
1843
-
1844
  // Find the first "language" column slug
 
1845
  $language_column = '';
1846
  foreach ( $polylang->filters_columns->model->get_languages_list() as $language) {
1847
- if ( empty($polylang->filters_columns->curlang) || $language->slug != $polylang->filters_columns->curlang->slug) {
1848
  $language_column = 'language_'.$language->slug;
1849
  break;
1850
  }
@@ -1856,21 +1910,22 @@ class MLA_Polylang {
1856
  $value = ob_get_clean();
1857
  if ( empty( $value ) ) {
1858
  MLACore::mla_debug_add( __LINE__ . ' MLA_Polylang::mla_list_table_inline_values language_column = ' . var_export( $language_column, true ), MLACore::MLA_DEBUG_CATEGORY_ANY );
1859
- MLACore::mla_debug_add( __LINE__ . ' MLA_Polylang::mla_list_table_inline_values $polylang->filters_columns->curlang = ' . var_export( $polylang->filters_columns->curlang, true ), MLACore::MLA_DEBUG_CATEGORY_ANY );
1860
  MLACore::mla_debug_add( __LINE__ . ' MLA_Polylang::mla_list_table_inline_values $polylang->filters_columns->model->get_languages_list() = ' . var_export( $polylang->filters_columns->model->get_languages_list(), true ), MLACore::MLA_DEBUG_CATEGORY_ANY );
 
 
 
 
 
1861
  }
1862
 
1863
- // Strip off <fieldset> and <div> tags around the <input> and <label> tags
1864
- preg_match('/\<input|\<label/', $value, $match_start, PREG_OFFSET_CAPTURE );
1865
- preg_match('/\<\/label[^\>]*\>/', $value, $match_end, PREG_OFFSET_CAPTURE );
1866
- $item_values['custom_fields'] .= substr( $value, $match_start[0][1], ( $match_end[0][1] + strlen( $match_end[0][0] ) ) - $match_start[0][1] );
1867
-
1868
  // Add the Translate links to the Quick Edit values
1869
  if ( array_key_exists( 'Quick Edit', $item_values ) ) {
1870
  $actions = "<input name=\"inline_translations\" type=\"hidden\" value=\"\">\n";
1871
  $actions .= "<input name=\"pll_quick_language\" type=\"hidden\" value=\"\">\n";
1872
  $actions .= "<input name=\"pll_quick_id\" type=\"hidden\" value=\"\">\n";
1873
  $actions .= "<input name=\"lang\" type=\"hidden\" value=\"\">\n";
 
1874
  $actions .= "<label class=\"alignleft\" style=\"clear: both;\">\n<span class=\"title\">Translate</span>\n";
1875
  $actions .= "<table class=\"pll-media-action-table\">\n";
1876
  foreach ($polylang->model->get_languages_list() as $language) {
@@ -1890,11 +1945,13 @@ class MLA_Polylang {
1890
  do_action( 'bulk_edit_custom_box', $language_column, 'attachment' );
1891
  $value = ob_get_clean();
1892
 
1893
- // Strip off <fieldset> and <div> tags around the <input> and <label> tags
1894
- preg_match('/\<input|\<label/', $value, $match_start, PREG_OFFSET_CAPTURE );
1895
- preg_match('/\<\/label[^\>]*\>/', $value, $match_end, PREG_OFFSET_CAPTURE );
1896
- $item_values['bulk_custom_fields'] .= substr( $value, $match_start[0][1], ( $match_end[0][1] + strlen( $match_end[0][0] ) ) - $match_start[0][1] );
1897
-
 
 
1898
  return $item_values;
1899
  } // mla_list_table_inline_values
1900
 
@@ -1920,8 +1977,8 @@ class MLA_Polylang {
1920
  */
1921
  $page_template_array = MLACore::mla_load_template( 'mla-polylang-support.tpl' );
1922
  if ( ! is_array( $page_template_array ) ) {
1923
- error_log( 'ERROR: mla-polylang-support.tpl path = ' . var_export( plugin_dir_path( __FILE__ ) . 'mla-polylang-support.tpl', true ), 0 );
1924
- error_log( 'ERROR: mla-polylang-support.tpl non-array result = ' . var_export( $page_template_array, true ), 0 );
1925
  return $html_markup;
1926
  }
1927
 
@@ -2008,7 +2065,13 @@ class MLA_Polylang {
2008
 
2009
  MLA_Polylang::$language_columns = array();
2010
 
2011
- if ( $show_language && empty( $polylang->curlang ) ) {
 
 
 
 
 
 
2012
  MLA_Polylang::$language_columns[ 'language' ] = __( 'Language', 'media-library-assistant' );
2013
  }
2014
 
@@ -2076,7 +2139,12 @@ class MLA_Polylang {
2076
  $content = is_object( $item_language ) ? $item_language->name : 'none';
2077
  } elseif ('pll_translations' == $column_name ) {
2078
  if ( is_null( $languages ) ) {
2079
- $current_language = $polylang->curlang;
 
 
 
 
 
2080
  $languages = $polylang->model->get_languages_list();
2081
  }
2082
 
@@ -2235,6 +2303,7 @@ class MLA_Polylang {
2235
  $fields[] = 'old_lang';
2236
  $fields[] = 'inline_lang_choice';
2237
  $fields[] = 'inline_translations';
 
2238
 
2239
  return $fields;
2240
  } // mla_list_table_inline_fields
@@ -2271,11 +2340,19 @@ class MLA_Polylang {
2271
  }
2272
 
2273
  $translations = json_encode( $translations );
2274
-
 
 
 
 
 
 
 
2275
  $inline_data .= "\n\t<div class=\"lang\">{$old_lang}</div>";
2276
  $inline_data .= "\n\t<div class=\"old_lang\">{$old_lang}</div>";
2277
  $inline_data .= "\n\t<div class=\"inline_lang_choice\">{$old_lang}</div>";
2278
  $inline_data .= "\n\t<div class=\"inline_translations\">{$translations}</div>";
 
2279
 
2280
  return $inline_data;
2281
  } // mla_list_table_build_inline_data
@@ -2547,9 +2624,4 @@ class MLA_Polylang {
2547
  return $page_content;
2548
  } // _reset_language_settings
2549
  } // Class MLA_Polylang
2550
-
2551
- /*
2552
- * Install the filters at an early opportunity
2553
- */
2554
- add_action('init', 'MLA_Polylang::initialize');
2555
  ?>
1
  <?php
2
  /**
3
+ * Media Library Assistant Polylang Support classes, admin mode.
4
  *
5
  * This file is conditionally loaded in MLA::initialize after a check for Polylang presence.
6
  *
9
  */
10
 
11
  /**
12
+ * Class MLA (Media Library Assistant) Polylang provides admin mode support for the
13
  * Polylang Multilingual plugin
14
  *
15
  * @package Media Library Assistant
45
  self::$polylang_1dot8_plus = version_compare( POLYLANG_VERSION, '1.7.99', '>' );
46
 
47
  /*
48
+ * These filters are only useful for the admin section;
49
  * exit in the front-end posts/pages
50
  */
51
  if ( ! is_admin() ) {
 
 
 
 
 
 
52
  return;
53
  }
54
 
131
  add_action( 'pll_translate_media', 'MLA_Polylang::pll_translate_media', 10, 3 );
132
  }
133
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  /**
135
  * Load the plugin's Ajax handler(s)
136
  *
664
  private static $relevant_terms = array();
665
 
666
  /**
667
+ * Creates a $relevant_term given a name, taxonomy and language
668
+ *
669
+ * @since 2.40
670
+ *
671
+ * @param string $name new term name
672
+ * @param string $taxonomy slug
673
+ * @param string $language code/slug
674
+ */
675
+ private static function _create_relevant_term( $name, $taxonomy, $language ) {
676
+ global $polylang;
677
+ //error_log( __LINE__ . " _create_relevant_term( {$name}, {$taxonomy}, {$language} )", 0 );
678
+ // save_language() does a check_admin_referer() security test
679
+ $_REQUEST['_pll_nonce'] = wp_create_nonce( 'pll_language' );
680
+ $_POST['term_lang_choice'] = $language;
681
+ $_POST['action'] = 'mla';
682
+ $res = wp_insert_term( $name, $taxonomy, array( 'parent' => 0 ) );
683
+ //error_log( __LINE__ . " _create_relevant_term( {$name}, {$taxonomy}, {$language} ) res = " . var_export( $res, true ), 0 );
684
+ if ( ( ! is_wp_error( $res ) ) && isset( $res['term_id'] ) ) {
685
+ if ( self::$polylang_1dot8_plus ) {
686
+ PLL()->model->term->set_language( $res['term_id'], $language );
687
+ } else {
688
+ $polylang->model->set_term_language( $res['term_id'], $language );
689
+ }
690
+ }
691
+ unset( $_POST['term_lang_choice'] );
692
+ unset( $_POST['action'] );
693
+
694
+ // Reload the term with all of its new translations
695
+ return self::_get_relevant_term( 'name', $name, $taxonomy );
696
+ } // _create_relevant_term
697
+
698
+ /**
699
+ * Creates a translation given a $relevant_term and language
700
+ *
701
+ * @since 2.40
702
+ *
703
+ * @param string $relevant_term current term
704
+ * @param string $language code/slug
705
+ */
706
+ private static function _create_relevant_translation( $relevant_term, $language ) {
707
+ global $polylang;
708
+
709
+ $source_term = $relevant_term['term']->term_id;
710
+ $name = $relevant_term['term']->name;
711
+ $taxonomy = $relevant_term['term']->taxonomy;
712
+ //error_log( __LINE__ . " _create_relevant_translation( {$name}, {$taxonomy}, {$language} )", 0 );
713
+
714
+ // save_language() does a check_admin_referer() security test
715
+ $_REQUEST['_pll_nonce'] = wp_create_nonce( 'pll_language' );
716
+ $_POST['term_lang_choice'] = $language;
717
+ $_POST['action'] = 'mla';
718
+ $res = wp_insert_term( $name, $taxonomy, array( 'parent' => 0 ) );
719
+ //error_log( __LINE__ . " _create_relevant_translation( {$name}, {$taxonomy}, {$language} ) res = " . var_export( $res, true ), 0 );
720
+ if ( ( ! is_wp_error( $res ) ) && isset( $res['term_id'] ) ) {
721
+ if ( self::$polylang_1dot8_plus ) {
722
+ PLL()->model->term->set_language( $res['term_id'], $language );
723
+ } else {
724
+ $polylang->model->set_term_language( $res['term_id'], $language );
725
+ }
726
+ }
727
+ unset( $_POST['term_lang_choice'] );
728
+ unset( $_POST['action'] );
729
+
730
+ $translations = array( $language => $res['term_id'] );
731
+ if (isset( $relevant_term['translations'] ) ) {
732
+ foreach( $relevant_term['translations'] as $slug => $translation ) {
733
+ $translations[ $slug ] = $translation->element_id;
734
+ }
735
+ }
736
+
737
+ if ( self::$polylang_1dot8_plus ) {
738
+ PLL()->model->term->save_translations( $source_term, $translations );
739
+ } else {
740
+ $polylang->model->save_translations( 'term', $source_term, $translations );
741
+ }
742
+
743
+ // Reload the term with its new translation
744
+ $term = self::_get_relevant_term( 'id', $res['term_id'], $taxonomy );
745
+ //error_log( __LINE__ . " _create_relevant_translation( {$name}, {$taxonomy}, {$language} ) term = " . var_export( $term, true ), 0 );
746
+ return $term;
747
+ } // _create_relevant_translation
748
+
749
+ /**
750
+ * Adds a term and/or its translations to $relevant_terms
751
  *
752
  * @since 2.11
753
  * @uses MLA_Polylang::$relevant_terms
783
 
784
  self::$relevant_terms[ $term->term_taxonomy_id ]['term'] = $term;
785
  self::$relevant_terms[ $term->term_taxonomy_id ]['translations'] = $translations;
786
+ } elseif ( !empty( $translations ) ) {
787
+ // Translations may have been added in Quick or Bulk Edit
788
+ self::$relevant_terms[ $term->term_taxonomy_id ]['translations'] = $translations;
789
  }
790
+
791
  return self::$relevant_terms[ $term->term_taxonomy_id ];
792
  } // _add_relevant_term
793
 
843
  if ( ( false === $relevant_term ) && $test_only ) {
844
  return false;
845
  }
846
+ //error_log( __LINE__ . " _get_relevant_term( {$field}, {$taxonomy}, {$value} ) relevant_term = " . var_export( $relevant_term, true ), 0 );
847
 
848
  /*
849
  * If no match, try to add it and its translations
850
  */
851
  if ( ( false === $relevant_term ) && $candidate = get_term_by( $field, $value, $taxonomy ) ) {
852
+ //error_log( __LINE__ . " _get_relevant_term( {$field}, {$taxonomy}, {$value} ) candidate = " . var_export( $candidate, true ), 0 );
853
  $relevant_term = self::_add_relevant_term( $candidate );
854
+ //error_log( __LINE__ . " _get_relevant_term( {$field}, {$taxonomy}, {$value} ) relevant_term = " . var_export( $relevant_term, true ), 0 );
855
 
856
  foreach ( $relevant_term['translations'] as $translation ) {
 
 
 
 
857
  $term_object = get_term_by( 'id', $translation->element_id, $taxonomy );
858
  self::_add_relevant_term( $term_object, $relevant_term['translations'] );
859
  } // translation
860
  } // new term
861
+ //error_log( __LINE__ . " _get_relevant_term( {$field}, {$taxonomy}, {$value} ) candidate = " . var_export( $candidate, true ), 0 );
862
 
863
  /*
864
  * Find the language-specific value, if requested
1068
  * @param integer $post_id ID of the current post
1069
  * @param array $tax_inputs 'tax_input' request parameter
1070
  * @param array $tax_actions 'tax_action' request parameter
1071
+ * @param boolean $add_new_names Add term and translations for new names
1072
  */
1073
+ private static function _build_tax_input( $post_id, $tax_inputs = NULL, $tax_actions = NULL, $add_new_names = false ) {
1074
  global $polylang;
1075
+ static $new_names = array();
1076
 
1077
  if ( $post_id == self::$tax_input['tax_input_post_id'] ) {
1078
  return;
1140
  foreach ( $term_names as $term_name ) {
1141
  if ( ! empty( $term_name ) ) {
1142
  $relevant_term = self::_get_relevant_term( 'name', $term_name, $taxonomy );
1143
+ // Add new term or translation if allowed and required
1144
+ if ( $add_new_names ) {
1145
+ if ( false === $relevant_term ) {
1146
+ $relevant_term = self::_create_relevant_term( $term_name, $taxonomy, self::$existing_terms['slug'] );
1147
+ $new_names[ $term_name ][ self::$existing_terms['slug'] ] = $relevant_term['term']->term_id;
1148
+ } else {
1149
+ $language = self::$existing_terms['slug'];
1150
+ //error_log( __LINE__ . " _build_tax_input( {$post_id}, {$term_name}, {$language} ) relevant_term = " . var_export( $relevant_term, true ), 0 );
1151
+ //error_log( __LINE__ . " _build_tax_input( {$post_id}, {$term_name}, {$language} ) new_names = " . var_export( $new_names, true ), 0 );
1152
+ if ( !array_key_exists( self::$existing_terms['slug'], $relevant_term['translations'] ) && isset( $new_names[ $term_name ] ) ) {
1153
+ $relevant_term = self::_create_relevant_translation( $relevant_term, self::$existing_terms['slug'] );
1154
+ $new_names[ $term_name ][ self::$existing_terms['slug'] ] = $relevant_term['term']->term_id;
1155
+ }
1156
+ }
1157
+ }
1158
+
1159
  if ( isset( $relevant_term['translations'] ) ) {
1160
  foreach ( $relevant_term['translations'] as $language => $translation ) {
1161
  if ( $translated_term = self::_get_relevant_term( 'id', $translation->element_id, $taxonomy ) ) {
1358
  } // synch_inputs
1359
 
1360
  $post_id = self::$existing_terms[ $language ]['element_id'];
1361
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::_apply_synch_input( {$post_id}, {$language} ) \$tax_inputs = " . var_export( $tax_inputs, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
 
1362
  return $tax_inputs;
1363
  } // _apply_synch_input
1364
 
1407
  * @param integer $result Zero if the update failed else ID of the item that was updated.
1408
  */
1409
  public static function mla_updated_single_item( $post_id, $result ) {
1410
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::mla_updated_single_item( {$post_id}, {$result} ) exising_terms = " . var_export( self::$existing_terms, true ), MLACore::MLA_DEBUG_CATEGORY_LANGUAGE );
1411
 
1412
  if ( self::$existing_terms['element_id'] == $post_id ) {
1413
  /*
1464
  if ( ! empty( self::$bulk_edit_request['tax_input'] ) ) {
1465
  $tax_inputs = self::$bulk_edit_request['tax_input'];
1466
  if ( 'checked' == MLACore::mla_get_option( 'term_assignment', false, false, MLA_Polylang::$mla_language_option_definitions ) ) {
1467
+ self::_build_tax_input( $post_id, $tax_inputs, self::$bulk_edit_request['tax_action'], true );
1468
  $tax_inputs = self::_apply_tax_input( $post_id );
1469
  }
1470
  } else {
1588
  } else {
1589
  $tax_inputs = array( $key => implode( ',', $terms ) );
1590
  }
1591
+ //error_log( __LINE__ . " MLA_Polylang::mla_media_modal_update_compat_fields_terms = " . var_export( $tax_inputs, true ), 0 );
1592
 
1593
+ self::_build_tax_input( $post_id, $tax_inputs, NULL, true );
1594
  $tax_inputs = self::_apply_tax_input( $post_id );
1595
  $terms = $tax_inputs[ $key ];
1596
  } // term_assignment
1643
 
1644
  if ( 'checked' == MLACore::mla_get_option( 'term_assignment', false, false, MLA_Polylang::$mla_language_option_definitions ) ) {
1645
  // Quick Edit calls update_single_item right after this filter
1646
+ self::_build_tax_input( $post_id, $_REQUEST['tax_input'], NULL, true );
1647
  $_REQUEST['tax_input'] = self::_apply_tax_input( $post_id );
1648
  }
1649
 
1734
  */
1735
  if ( 'edit' == $bulk_action && ( ! empty( self::$bulk_edit_request['tax_input'] ) ) && ( 'checked' == MLACore::mla_get_option( 'term_assignment', false, false, MLA_Polylang::$mla_language_option_definitions ) ) ) {
1736
  self::_build_existing_terms( $post_id );
1737
+ self::_build_tax_input( $post_id, self::$bulk_edit_request['tax_input'], $request['tax_action'], true );
1738
  $request['tax_input'] = self::_apply_tax_input( $post_id );
1739
  foreach( self::$bulk_edit_request['tax_action'] as $taxonomy => $action ) {
1740
  // _apply_tax_input changes a remove to a replace
1782
  $post = get_post( $post_id );
1783
  // save_post() does a check_admin_referer() security test
1784
  $_REQUEST['_wpnonce'] = wp_create_nonce( 'bulk-posts' );
1785
+ // save_post() looks for $_GET['bulk_edit']
1786
+ $_REQUEST['bulk_edit'] = $_GET['bulk_edit'] ='Update';
1787
  $polylang->filters_post->save_post( $post_id, $post, true );
1788
 
1789
  if ( $_REQUEST['inline_lang_choice'] != -1 ) {
1893
  */
1894
  public static function mla_list_table_inline_values( $item_values ) {
1895
  global $polylang;
1896
+
1897
  // Find the first "language" column slug
1898
+ $all_languages = false === $polylang->curlang;
1899
  $language_column = '';
1900
  foreach ( $polylang->filters_columns->model->get_languages_list() as $language) {
1901
+ if ( $all_languages || $language->slug != $polylang->curlang->slug) {
1902
  $language_column = 'language_'.$language->slug;
1903
  break;
1904
  }
1910
  $value = ob_get_clean();
1911
  if ( empty( $value ) ) {
1912
  MLACore::mla_debug_add( __LINE__ . ' MLA_Polylang::mla_list_table_inline_values language_column = ' . var_export( $language_column, true ), MLACore::MLA_DEBUG_CATEGORY_ANY );
1913
+ MLACore::mla_debug_add( __LINE__ . ' MLA_Polylang::mla_list_table_inline_values $polylang->curlang = ' . var_export( $polylang->curlang, true ), MLACore::MLA_DEBUG_CATEGORY_ANY );
1914
  MLACore::mla_debug_add( __LINE__ . ' MLA_Polylang::mla_list_table_inline_values $polylang->filters_columns->model->get_languages_list() = ' . var_export( $polylang->filters_columns->model->get_languages_list(), true ), MLACore::MLA_DEBUG_CATEGORY_ANY );
1915
+ } else {
1916
+ // Strip off <fieldset> and <div> tags around the <input> and <label> tags
1917
+ preg_match('/\<input|\<label/', $value, $match_start, PREG_OFFSET_CAPTURE );
1918
+ preg_match('/\<\/label[^\>]*\>/', $value, $match_end, PREG_OFFSET_CAPTURE );
1919
+ $item_values['custom_fields'] .= substr( $value, $match_start[0][1], ( $match_end[0][1] + strlen( $match_end[0][0] ) ) - $match_start[0][1] );
1920
  }
1921
 
 
 
 
 
 
1922
  // Add the Translate links to the Quick Edit values
1923
  if ( array_key_exists( 'Quick Edit', $item_values ) ) {
1924
  $actions = "<input name=\"inline_translations\" type=\"hidden\" value=\"\">\n";
1925
  $actions .= "<input name=\"pll_quick_language\" type=\"hidden\" value=\"\">\n";
1926
  $actions .= "<input name=\"pll_quick_id\" type=\"hidden\" value=\"\">\n";
1927
  $actions .= "<input name=\"lang\" type=\"hidden\" value=\"\">\n";
1928
+ $actions .= "<input name=\"quick_current_language\" type=\"hidden\" value=\"\">\n";
1929
  $actions .= "<label class=\"alignleft\" style=\"clear: both;\">\n<span class=\"title\">Translate</span>\n";
1930
  $actions .= "<table class=\"pll-media-action-table\">\n";
1931
  foreach ($polylang->model->get_languages_list() as $language) {
1945
  do_action( 'bulk_edit_custom_box', $language_column, 'attachment' );
1946
  $value = ob_get_clean();
1947
 
1948
+ if ( !empty( $value ) ) {
1949
+ // Strip off <fieldset> and <div> tags around the <input> and <label> tags
1950
+ preg_match('/\<input|\<label/', $value, $match_start, PREG_OFFSET_CAPTURE );
1951
+ preg_match('/\<\/label[^\>]*\>/', $value, $match_end, PREG_OFFSET_CAPTURE );
1952
+ $item_values['bulk_custom_fields'] .= substr( $value, $match_start[0][1], ( $match_end[0][1] + strlen( $match_end[0][0] ) ) - $match_start[0][1] );
1953
+ }
1954
+
1955
  return $item_values;
1956
  } // mla_list_table_inline_values
1957
 
1977
  */
1978
  $page_template_array = MLACore::mla_load_template( 'mla-polylang-support.tpl' );
1979
  if ( ! is_array( $page_template_array ) ) {
1980
+ MLACore::mla_debug_add( 'ERROR: mla-polylang-support.tpl path = ' . var_export( plugin_dir_path( __FILE__ ) . 'mla-polylang-support.tpl', true ), MLACore::MLA_DEBUG_CATEGORY_ANY );
1981
+ MLACore::mla_debug_add( 'ERROR: mla-polylang-support.tpl non-array result = ' . var_export( $page_template_array, true ), MLACore::MLA_DEBUG_CATEGORY_ANY );
1982
  return $html_markup;
1983
  }
1984
 
2065
 
2066
  MLA_Polylang::$language_columns = array();
2067
 
2068
+ if ( isset( $_REQUEST['quick_current_language'] ) ) {
2069
+ $current_language = $_REQUEST['quick_current_language'];
2070
+ } else {
2071
+ $current_language = $polylang->curlang;
2072
+ }
2073
+
2074
+ if ( $show_language && empty( $current_language ) ) {
2075
  MLA_Polylang::$language_columns[ 'language' ] = __( 'Language', 'media-library-assistant' );
2076
  }
2077
 
2139
  $content = is_object( $item_language ) ? $item_language->name : 'none';
2140
  } elseif ('pll_translations' == $column_name ) {
2141
  if ( is_null( $languages ) ) {
2142
+ if ( isset( $_REQUEST['quick_current_language'] ) ) {
2143
+ $current_language = $_REQUEST['quick_current_language'];
2144
+ } else {
2145
+ $current_language = $polylang->curlang;
2146
+ }
2147
+
2148
  $languages = $polylang->model->get_languages_list();
2149
  }
2150
 
2303
  $fields[] = 'old_lang';
2304
  $fields[] = 'inline_lang_choice';
2305
  $fields[] = 'inline_translations';
2306
+ $fields[] = 'quick_current_language';
2307
 
2308
  return $fields;
2309
  } // mla_list_table_inline_fields
2340
  }
2341
 
2342
  $translations = json_encode( $translations );
2343
+ if ( isset( $_REQUEST['quick_current_language'] ) ) {
2344
+ $current_language = $_REQUEST['quick_current_language'];
2345
+ } elseif ( $polylang->curlang ) {
2346
+ $current_language = $polylang->curlang->slug;
2347
+ } else {
2348
+ $current_language = '';
2349
+ }
2350
+
2351
  $inline_data .= "\n\t<div class=\"lang\">{$old_lang}</div>";
2352
  $inline_data .= "\n\t<div class=\"old_lang\">{$old_lang}</div>";
2353
  $inline_data .= "\n\t<div class=\"inline_lang_choice\">{$old_lang}</div>";
2354
  $inline_data .= "\n\t<div class=\"inline_translations\">{$translations}</div>";
2355
+ $inline_data .= "\n\t<div class=\"quick_current_language\">{$current_language}</div>";
2356
 
2357
  return $inline_data;
2358
  } // mla_list_table_build_inline_data
2624
  return $page_content;
2625
  } // _reset_language_settings
2626
  } // Class MLA_Polylang
 
 
 
 
 
2627
  ?>
includes/class-mla-settings-custom-fields-tab.php ADDED
@@ -0,0 +1,474 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Manages the Settings/Media Library Assistant Custom Fields tab
4
+ *
5
+ * @package Media Library Assistant
6
+ * @since 2.40
7
+ */
8
+
9
+ /**
10
+ * Class MLA (Media Library Assistant) Settings Custom Fields implements the
11
+ * Settings/Media Library Assistant Custom Fields tab
12
+ *
13
+ * @package Media Library Assistant
14
+ * @since 2.40
15
+ */
16
+ class MLASettings_CustomFields {
17
+ /**
18
+ * Load the tab's Javascript files
19
+ *
20
+ * @since 2.40
21
+ *
22
+ * @param string $page_hook Name of the page being loaded
23
+ */
24
+ public static function mla_admin_enqueue_scripts( $page_hook ) {
25
+ global $wpdb;
26
+
27
+ // Without a tab value that matches ours, there's nothing to do
28
+ if ( empty( $_REQUEST['mla_tab'] ) || 'custom_field' !== $_REQUEST['mla_tab'] ) {
29
+ return;
30
+ }
31
+
32
+ /*
33
+ * Initialize script variables
34
+ */
35
+ $script_variables = array(
36
+ 'error' => __( 'Error while making the changes.', 'media-library-assistant' ),
37
+ 'ntdeltitle' => __( 'Remove From Bulk Edit', 'media-library-assistant' ),
38
+ 'notitle' => '(' . __( 'no slug', 'media-library-assistant' ) . ')',
39
+ 'comma' => _x( ',', 'tag_delimiter', 'media-library-assistant' ),
40
+ 'useSpinnerClass' => false,
41
+ 'ajax_nonce' => wp_create_nonce( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ),
42
+ 'bulkChunkSize' => MLACore::mla_get_option( MLACoreOptions::MLA_BULK_CHUNK_SIZE ),
43
+ 'bulkWaiting' => __( 'Waiting', 'media-library-assistant' ),
44
+ 'bulkRunning' => __( 'Running', 'media-library-assistant' ),
45
+ 'bulkComplete' => __( 'Complete', 'media-library-assistant' ),
46
+ 'bulkUnchanged' => __( 'Unchanged', 'media-library-assistant' ),
47
+ 'bulkSuccess' => __( 'Succeeded', 'media-library-assistant' ),
48
+ 'bulkFailure' => __( 'Failed', 'media-library-assistant' ),
49
+ 'bulkSkip' => __( 'Skipped', 'media-library-assistant' ),
50
+ 'bulkRedone' => __( 'Reprocessed', 'media-library-assistant' ),
51
+ 'bulkPaused' => __( 'PAUSED', 'media-library-assistant' ),
52
+ 'page' => 'mla-settings-menu-custom_field',
53
+ 'mla_tab' => 'custom_field',
54
+ 'screen' => 'settings_page_mla-settings-menu-custom_field',
55
+ 'ajax_action' => MLASettings::JAVASCRIPT_INLINE_MAPPING_CUSTOM_SLUG,
56
+ 'fieldsId' => '#mla-display-settings-custom-field-tab',
57
+ 'totalItems' => $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE `post_type` = 'attachment'" )
58
+ );
59
+
60
+ if ( version_compare( get_bloginfo( 'version' ), '4.2', '>=' ) ) {
61
+ $script_variables['useSpinnerClass'] = true;
62
+ }
63
+
64
+ $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
65
+
66
+ wp_enqueue_script( MLASettings::JAVASCRIPT_INLINE_MAPPING_CUSTOM_SLUG,
67
+ MLA_PLUGIN_URL . "js/mla-inline-mapping-scripts{$suffix}.js",
68
+ array( 'jquery' ), MLACore::CURRENT_MLA_VERSION, false );
69
+
70
+ wp_localize_script( MLASettings::JAVASCRIPT_INLINE_MAPPING_CUSTOM_SLUG,
71
+ MLASettings::JAVASCRIPT_INLINE_MAPPING_OBJECT, $script_variables );
72
+ }
73
+
74
+ /**
75
+ * Save custom field settings to the options table
76
+ *
77
+ * @since 1.10
78
+ * @uses $_REQUEST if passed a NULL parameter
79
+ *
80
+ * @param array | NULL specific custom_field_mapping values
81
+ *
82
+ * @return array Message(s) reflecting the results of the operation
83
+ */
84
+ private static function _save_custom_field_settings( $new_values = NULL ) {
85
+ $message_list = '';
86
+ $option_messages = '';
87
+
88
+ if ( NULL == $new_values ) {
89
+ /*
90
+ * Start with any page-level options
91
+ */
92
+ foreach ( MLACoreOptions::$mla_option_definitions as $key => $value ) {
93
+ if ( 'custom_field' == $value['tab'] ) {
94
+ $option_messages .= MLASettings::mla_update_option_row( $key, $value );
95
+ }
96
+ }
97
+
98
+ /*
99
+ * Add mapping options
100
+ */
101
+ $new_values = ( isset( $_REQUEST['custom_field_mapping'] ) ) ? $_REQUEST['custom_field_mapping'] : array();
102
+ } // NULL
103
+
104
+ /*
105
+ * Uncomment this for debugging.
106
+ */
107
+ // $message_list = $option_messages . '<br>';
108
+
109
+ return array(
110
+ 'message' => $message_list . MLAOptions::mla_custom_field_option_handler( 'update', 'custom_field_mapping', MLACoreOptions::$mla_option_definitions['custom_field_mapping'], $new_values ),
111
+ 'body' => ''
112
+ );
113
+ } // _save_custom_field_settings
114
+
115
+ /**
116
+ * Process custom field settings against all image attachments
117
+ * without saving the settings to the mla_option
118
+ *
119
+ * @since 1.10
120
+ * @uses $_REQUEST if passed a NULL parameter
121
+ *
122
+ * @param array | NULL specific custom_field_mapping values
123
+ * @param integer offset for chunk mapping
124
+ * @param integer length for chunk mapping
125
+ *
126
+ * @return array Message(s) reflecting the results of the operation
127
+ */
128
+ private static function _process_custom_field_mapping( $settings = NULL, $offset = 0, $length = 0 ) {
129
+ global $wpdb;
130
+ if ( NULL == $settings ) {
131
+ $source = 'custom_fields';
132
+ $settings = ( isset( $_REQUEST['custom_field_mapping'] ) ) ? stripslashes_deep( $_REQUEST['custom_field_mapping'] ) : array();
133
+ if ( isset( $settings[ MLACoreOptions::MLA_NEW_CUSTOM_FIELD ] ) ) {
134
+ unset( $settings[ MLACoreOptions::MLA_NEW_CUSTOM_FIELD ] );
135
+ }
136
+ if ( isset( $settings[ MLACoreOptions::MLA_NEW_CUSTOM_RULE ] ) ) {
137
+ unset( $settings[ MLACoreOptions::MLA_NEW_CUSTOM_RULE ] );
138
+ }
139
+ } else {
140
+ $source = 'custom_rule';
141
+ $settings = stripslashes_deep( $settings );
142
+ }
143
+
144
+ if ( empty( $settings ) ) {
145
+ return array(
146
+ 'message' => __( 'ERROR', 'media-library-assistant' ) . ': ' . __( 'No custom field mapping rules to process.', 'media-library-assistant' ),
147
+ 'body' => '' ,
148
+ 'processed' => 0,
149
+ 'unchanged' => 0,
150
+ 'success' => 0
151
+ );
152
+ }
153
+
154
+ if ( $length > 0 ) {
155
+ $limits = "LIMIT {$offset}, {$length}";
156
+ } else {
157
+ $limits = '';
158
+ }
159
+
160
+ $examine_count = 0;
161
+ $update_count = 0;
162
+ $post_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE `post_type` = 'attachment' {$limits}" );
163
+
164
+ do_action( 'mla_begin_mapping', $source, NULL );
165
+ foreach ( $post_ids as $key => $post_id ) {
166
+ $updates = MLAOptions::mla_evaluate_custom_field_mapping( (integer) $post_id, 'custom_field_mapping', $settings );
167
+ $examine_count += 1;
168
+ if ( ! empty( $updates ) && isset( $updates['custom_updates'] ) ) {
169
+ $results = MLAData::mla_update_item_postmeta( (integer) $post_id, $updates['custom_updates'] );
170
+ if ( ! empty( $results ) ) {
171
+ $update_count += 1;
172
+ }
173
+ }
174
+ } // foreach post
175
+ do_action( 'mla_end_mapping' );
176
+
177
+ if ( $update_count ) {
178
+ /* translators: 1: field type 2: examined count 3: updated count */
179
+ $message = sprintf( __( '%1$s mapping completed; %2$d attachment(s) examined, %3$d updated.' ), __( 'Custom field', 'media-library-assistant' ), $examine_count, $update_count ) . "\r\n";
180
+ } else {
181
+ /* translators: 1: field type 2: examined count */
182
+ $message = sprintf( __( '%1$s mapping completed; %2$d attachment(s) examined, no changes detected.' ), __( 'Custom field', 'media-library-assistant' ), $examine_count ) . "\r\n";
183
+ }
184
+
185
+ return array(
186
+ 'message' => $message,
187
+ 'body' => '',
188
+ 'processed' => $examine_count,
189
+ 'unchanged' => $examine_count - $update_count,
190
+ 'success' => $update_count
191
+ );
192
+ } // _process_custom_field_mapping
193
+
194
+ /**
195
+ * Compose the Custom Field tab content for the Settings subpage
196
+ *
197
+ * @since 1.10
198
+ *
199
+ * @return array 'message' => status/error messages, 'body' => tab content
200
+ */
201
+ public static function mla_compose_custom_field_tab( ) {
202
+ /*
203
+ * Check for action or submit buttons.
204
+ * Initialize page messages and content.
205
+ */
206
+ if ( isset( $_REQUEST['custom_field_mapping'] ) && is_array( $_REQUEST['custom_field_mapping'] ) ) {
207
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
208
+
209
+ /*
210
+ * Check for page-level submit buttons to change settings or map attachments.
211
+ * Initialize page messages and content.
212
+ */
213
+ if ( !empty( $_REQUEST['custom-field-options-save'] ) ) {
214
+ $page_content = self::_save_custom_field_settings( );
215
+ } elseif ( !empty( $_REQUEST['custom-field-options-map'] ) ) {
216
+ $page_content = self::_process_custom_field_mapping( );
217
+ } else {
218
+ $page_content = array(
219
+ 'message' => '',
220
+ 'body' => ''
221
+ );
222
+
223
+ /*
224
+ * Check for single-rule action buttons
225
+ */
226
+ foreach ( $_REQUEST['custom_field_mapping'] as $key => $value ) {
227
+ $value = stripslashes_deep( $value );
228
+
229
+ if ( isset( $value['action'] ) ) {
230
+ $settings = array( $key => $value );
231
+ foreach ( $value['action'] as $action => $label ) {
232
+ switch( $action ) {
233
+ case 'delete_field':
234
+ $delete_result = MLASettings::mla_delete_custom_field( $value );
235
+ case 'delete_rule':
236
+ case 'add_rule':
237
+ case 'add_field':
238
+ case 'update_rule':
239
+ $page_content = self::_save_custom_field_settings( $settings );
240
+ if ( isset( $delete_result ) ) {
241
+ $page_content['message'] = $delete_result . $page_content['message'];
242
+ }
243
+ break;
244
+ case 'map_now':
245
+ $page_content = self::_process_custom_field_mapping( $settings );
246
+ break;
247
+ case 'add_rule_map':
248
+ case 'add_field_map':
249
+ $page_content = self::_save_custom_field_settings( $settings );
250
+ if ( false === strpos( $page_content['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
251
+ $current_values = MLACore::mla_get_option( 'custom_field_mapping' );
252
+ $settings = array( $value['name'] => $current_values[$value['name']] );
253
+ $map_content = self::_process_custom_field_mapping( $settings );
254
+ $page_content['message'] .= '<br>&nbsp;<br>' . $map_content['message'];
255
+ }
256
+ break;
257
+ default:
258
+ // ignore everything else
259
+ } //switch action
260
+ } // foreach action
261
+ } /// isset action
262
+ } // foreach rule
263
+ } // specific rule check
264
+ } // isset custom_field_mapping
265
+ else {
266
+ $page_content = array(
267
+ 'message' => '',
268
+ 'body' => ''
269
+ );
270
+ }
271
+
272
+ if ( !empty( $page_content['body'] ) ) {
273
+ return $page_content;
274
+ }
275
+
276
+ $page_template_array = MLACore::mla_load_template( 'admin-display-settings-custom-fields-tab.tpl' );
277
+ if ( ! is_array( $page_template_array ) ) {
278
+ /* translators: 1: ERROR tag 2: function name 3: non-array value */
279
+ $page_content['message'] = sprintf( _x( '%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'MLASettings_CustomFields::mla_compose_custom_field_tab', var_export( $page_template_array, true ) );
280
+ return $page_content;
281
+ }
282
+
283
+ $page_values = array(
284
+ 'Mapping Progress' => __( 'Custom Field Mapping Progress', 'media-library-assistant' ),
285
+ 'DO NOT' => __( 'DO NOT DO THE FOLLOWING (they will cause mapping to fail)', 'media-library-assistant' ),
286
+ 'DO NOT Close' => __( 'Close the window', 'media-library-assistant' ),
287
+ 'DO NOT Reload' => __( 'Reload the page', 'media-library-assistant' ),
288
+ 'DO NOT Click' => __( 'Click the browser&rsquo;s Stop, Back or forward buttons', 'media-library-assistant' ),
289
+ 'Progress' => __( 'Progress', 'media-library-assistant' ),
290
+ 'Pause' => __( 'Pause', 'media-library-assistant' ),
291
+ 'Cancel' => __( 'Cancel', 'media-library-assistant' ),
292
+ 'Resume' => __( 'Resume', 'media-library-assistant' ),
293
+ 'Close' => __( 'Close', 'media-library-assistant' ),
294
+ 'Refresh' => __( 'Refresh', 'media-library-assistant' ),
295
+ 'refresh_href' => '?page=mla-settings-menu-custom_field&mla_tab=custom_field',
296
+ );
297
+
298
+ $progress_div = MLAData::mla_parse_template( $page_template_array['mla-progress-div'], $page_values );
299
+
300
+ $page_values = array(
301
+ 'mla-progress-div' => $progress_div,
302
+ 'Custom Field Options' => __( 'Custom Field and Attachment Metadata Processing Options', 'media-library-assistant' ),
303
+ /* translators: 1: Documentation hyperlink */
304
+ 'In this tab' => sprintf( __( 'In this tab you can define the rules for mapping several types of image metadata to WordPress custom fields. You can also use this screen to define rules for adding or updating fields within the WordPress-supplied "Attachment Metadata", stored in the "_wp_attachment_metadata" custom field. See the %1$s section of the Documentation for details.', 'media-library-assistant' ), '<a href="[+settingsURL+]?page=mla-settings-menu-documentation&amp;mla_tab=documentation#attachment_metadata_mapping" title="' . __( 'Updating Attachment Metadata Documentation', 'media-library-assistant' ) . '">' . __( 'Adding or changing Attachment Metadata', 'media-library-assistant' ) . '</a>' ),
305
+ /* translators: 1: Documentation hyperlink */
306
+ 'You can find' => sprintf( __( 'You can find more information about using the controls in this tab to define mapping rules and apply them in the %1$s section of the Documentation.', 'media-library-assistant' ), '<a href="[+settingsURL+]?page=mla-settings-menu-documentation&amp;mla_tab=documentation#mla_custom_field_mapping" title="' . __( 'Custom Field Options documentation', 'media-library-assistant' ) . '">' . __( 'Custom Field and Attachment Metadata Processing Options', 'media-library-assistant' ) . '</a>' ),
307
+ 'settingsURL' => admin_url('options-general.php'),
308
+ 'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-custom_field&mla_tab=custom_field',
309
+ 'options_list' => '',
310
+ 'Custom field mapping' => __( 'Custom field mapping', 'media-library-assistant' ),
311
+ 'custom_options_list' => '',
312
+ 'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
313
+ 'Map All Rules' => __( 'Map All Rules, All Attachments Now', 'media-library-assistant' ),
314
+ /* translators: 1: "Save Changes" */
315
+ 'Click Save Changes' => sprintf( __( 'Click %1$s to update the "Enable custom field mapping..." checkbox and/or all rule changes and additions at once. <strong>No rule mapping will be performed.</strong>', 'media-library-assistant' ), '<strong>' . __( 'Save Changes', 'media-library-assistant' ) . '</strong>' ),
316
+ /* translators: 1: "Map All Rules..." */
317
+ 'Click Map All' => sprintf( __( 'Click %1$s to apply all the rules at once (rule changes will be applied but not saved).', 'media-library-assistant' ), '<strong>' . __( 'Map All Rules, All Attachments Now', 'media-library-assistant' ) . '</strong>' ),
318
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
319
+ '_wp_http_referer' => wp_referer_field( false )
320
+ );
321
+
322
+ /*
323
+ * Start with any page-level options
324
+ */
325
+ $options_list = '';
326
+ foreach ( MLACoreOptions::$mla_option_definitions as $key => $value ) {
327
+ if ( 'custom_field' == $value['tab'] ) {
328
+ $options_list .= MLASettings::mla_compose_option_row( $key, $value );
329
+ }
330
+ }
331
+
332
+ $page_values['options_list'] = $options_list;
333
+
334
+ /*
335
+ * Add mapping options
336
+ */
337
+ $page_values['custom_options_list'] = MLAOptions::mla_custom_field_option_handler( 'render', 'custom_field_mapping', MLACoreOptions::$mla_option_definitions['custom_field_mapping'] );
338
+
339
+ $page_content['body'] = MLAData::mla_parse_template( $page_template_array['custom-field-tab'], $page_values );
340
+ return $page_content;
341
+ } // mla_compose_custom_field_tab
342
+
343
+ /**
344
+ * Ajax handler for Custom Fields tab inline mapping
345
+ *
346
+ * @since 2.00
347
+ *
348
+ * @return void echo json response object, then die()
349
+ */
350
+ public static function mla_inline_mapping_custom_action() {
351
+ MLACore::mla_debug_add( 'MLASettings_CustomFields::mla_inline_mapping_custom_action $_REQUEST = ' . var_export( $_REQUEST, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
352
+ set_current_screen( $_REQUEST['screen'] );
353
+ check_ajax_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
354
+
355
+ /*
356
+ * Convert the ajax bulk_action back to the older Submit button equivalent
357
+ */
358
+ if ( ! empty( $_REQUEST['bulk_action'] ) ) {
359
+ if ( 'custom-field-options-map' == $_REQUEST['bulk_action'] ) {
360
+ $_REQUEST['custom-field-options-map'] = __( 'Map All Rules, All Attachments Now', 'media-library-assistant' );
361
+ } else {
362
+ $match_count = preg_match( '/custom_field_mapping\[(.*)\]\[(.*)\]\[(.*)\]/', $_REQUEST['bulk_action'], $matches );
363
+ if ( $match_count ) {
364
+ $_REQUEST['custom_field_mapping'][ $matches[1] ][ $matches[2] ][ $matches[3] ] = __( 'Map All Attachments', 'media-library-assistant' );
365
+ }
366
+ }
367
+ }
368
+
369
+ /*
370
+ * Check for action or submit buttons.
371
+ */
372
+
373
+ if ( isset( $_REQUEST['custom_field_mapping'] ) && is_array( $_REQUEST['custom_field_mapping'] ) ) {
374
+ /*
375
+ * Find the current chunk
376
+ */
377
+ $offset = isset( $_REQUEST['offset'] ) ? $_REQUEST['offset'] : 0;
378
+ $length = isset( $_REQUEST['length'] ) ? $_REQUEST['length'] : 0;
379
+
380
+ /*
381
+ * Check for page-level submit button to map attachments.
382
+ */
383
+ if ( !empty( $_REQUEST['custom-field-options-map'] ) ) {
384
+ $page_content = self::_process_custom_field_mapping( NULL, $offset, $length );
385
+ } else {
386
+ $page_content = array(
387
+ 'message' => '',
388
+ 'body' => '',
389
+ 'processed' => 0,
390
+ 'unchanged' => 0,
391
+ 'success' => 0
392
+ );
393
+
394
+ /*
395
+ * Check for single-rule action buttons
396
+ */
397
+ foreach ( $_REQUEST['custom_field_mapping'] as $key => $value ) {
398
+ $value = stripslashes_deep( $value );
399
+
400
+ if ( isset( $value['action'] ) ) {
401
+ $settings = array( $key => $value );
402
+ foreach ( $value['action'] as $action => $label ) {
403
+ switch( $action ) {
404
+ case 'map_now':
405
+ $page_content = self::_process_custom_field_mapping( $settings, $offset, $length );
406
+ break;
407
+ case 'add_rule_map':
408
+ if ( 'none' == $value['name'] ) {
409
+ $page_content['message'] = __( 'Custom field no mapping rule changes detected.', 'media-library-assistant' );
410
+ break;
411
+ }
412
+ // fallthru
413
+ case 'add_field_map':
414
+ if ( '' == $value['name'] ) {
415
+ $page_content['message'] = __( 'Custom field no mapping rule changes detected.', 'media-library-assistant' );
416
+ break;
417
+ }
418
+
419
+ if ( 0 == $offset ) {
420
+ $page_content = self::_save_custom_field_settings( $settings );
421
+ if ( false !== strpos( $page_content['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
422
+ $page_content['processed'] = 0;
423
+ $page_content['unchanged'] = 0;
424
+ $page_content['success'] = 0;
425
+ break;
426
+ }
427
+ }
428
+
429
+ $current_values = MLACore::mla_get_option( 'custom_field_mapping' );
430
+ $settings = array( $value['name'] => $current_values[$value['name']] );
431
+ $map_content = self::_process_custom_field_mapping( $settings, $offset, $length );
432
+ $page_content['message'] .= '<br>&nbsp;<br>' . $map_content['message'];
433
+ $page_content['processed'] = $map_content['processed'];
434
+ $page_content['unchanged'] = $map_content['unchanged'];
435
+ $page_content['success'] = $map_content['success'];
436
+ $page_content['refresh'] = true;
437
+ break;
438
+ default:
439
+ // ignore everything else
440
+ } //switch action
441
+ } // foreach action
442
+ } /// isset action
443
+ } // foreach rule
444
+ } // specific rule check
445
+ } // isset custom_field_mapping
446
+ else {
447
+ $page_content = array(
448
+ 'message' => '',
449
+ 'body' => '',
450
+ 'processed' => 0,
451
+ 'unchanged' => 0,
452
+ 'success' => 0
453
+ );
454
+ }
455
+
456
+ $chunk_results = array(
457
+ 'message' => $page_content['message'],
458
+ 'processed' => $page_content['processed'],
459
+ 'unchanged' => $page_content['unchanged'],
460
+ 'success' => $page_content['success'],
461
+ 'refresh' => isset( $page_content['refresh'] ) && true == $page_content['refresh'],
462
+ );
463
+
464
+ MLACore::mla_debug_add( 'MLASettings::mla_inline_mapping_custom_action $chunk_results = ' . var_export( $chunk_results, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
465
+ wp_send_json_success( $chunk_results );
466
+ } // mla_inline_mapping_custom_action
467
+ } // class MLASettings_CustomFields
468
+
469
+ /*
470
+ * Actions are added here, when the source file is loaded, because the MLA_Example_List_Table
471
+ * object is created too late to be useful.
472
+ */
473
+ add_action( 'admin_enqueue_scripts', 'MLASettings_CustomFields::mla_admin_enqueue_scripts' );
474
+ ?>
includes/{class-mla-example-list-table.php → class-mla-settings-documentation-tab.php} RENAMED
@@ -1,10 +1,317 @@
1
  <?php
2
  /**
3
- * Media Library Assistant extended List Table class for example plugins
4
  *
5
  * @package Media Library Assistant
6
- * @since 2.32
 
 
 
 
 
 
 
 
7
  */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  /*
10
  * The WP_List_Table class isn't automatically available to plugins
@@ -34,13 +341,34 @@ if ( !class_exists( 'WP_Upgrader_Skin' ) ) {
34
  * @since 2.32
35
  */
36
  class MLA_Example_List_Table extends WP_List_Table {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  /**
38
  * Table column definitions
39
  *
40
  * This array defines table columns and titles where the key is the column slug (and class)
41
  * and the value is the column's title text.
42
  *
43
- * All of the columns are added to this array by MLA_Example_List_Table::mla_admin_init_action.
44
  *
45
  * @since 2.32
46
  *
@@ -113,6 +441,20 @@ class MLA_Example_List_Table extends WP_List_Table {
113
  * @return array name => array( orderby value, heading ) for sortable columns
114
  */
115
  public static function mla_get_sortable_columns( ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  $results = array() ;
117
 
118
  foreach ( self::$default_sortable_columns as $key => $value ) {
@@ -154,6 +496,7 @@ class MLA_Example_List_Table extends WP_List_Table {
154
  * @return array list of table columns
155
  */
156
  public static function mla_manage_columns_filter( ) {
 
157
  return self::$default_columns;
158
  }
159
 
@@ -167,19 +510,19 @@ class MLA_Example_List_Table extends WP_List_Table {
167
  *
168
  * @return void
169
  */
170
- public static function mla_localize_default_columns_array( ) {
171
- /*
172
- * Build the default columns array at runtime to accomodate calls to the localization functions
173
- */
174
- self::$default_columns = array(
175
- 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
176
- 'name' => _x( 'Name', 'list_table_column', 'media-library-assistant' ),
177
- 'version' => _x( 'Version', 'list_table_column', 'media-library-assistant' ),
178
- 'installed_version' => _x( 'Installed Version', 'list_table_column', 'media-library-assistant' ),
179
- 'description' => _x( 'Description', 'list_table_column', 'media-library-assistant' ),
180
- 'file' => _x( 'File Name', 'list_table_column', 'media-library-assistant' ),
181
- 'tags' => _x( 'Tags', 'list_table_column', 'media-library-assistant' ),
182
- );
183
  }
184
 
185
  /**
@@ -216,8 +559,8 @@ class MLA_Example_List_Table extends WP_List_Table {
216
  *
217
  * @return void
218
  */
219
- public static function mla_admin_init_action( ) {
220
- //error_log( __LINE__ . ' mla_admin_init_action request = ' . var_export( $_REQUEST, true ), 0 );
221
  if ( isset( $_REQUEST['mla-example-cancel'] ) ) {
222
  unset( $_REQUEST['mla-example-display'] );
223
  }
@@ -229,27 +572,6 @@ class MLA_Example_List_Table extends WP_List_Table {
229
  }
230
  }
231
 
232
- /**
233
- * Calls the parent constructor to set some default values.
234
- *
235
- * @since 2.32
236
- *
237
- * @return void
238
- */
239
- function __construct( ) {
240
- //Set parent defaults
241
- parent::__construct( array(
242
- 'singular' => 'example_plugin', //singular name of the listed records
243
- 'plural' => 'example_plugins', //plural name of the listed records
244
- 'ajax' => false, //does this table support ajax?
245
- 'screen' => 'settings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-example'
246
- ) );
247
-
248
- /*
249
- * NOTE: There is one add_action call at the end of this source file.
250
- */
251
- }
252
-
253
  /**
254
  * Get the name of the default primary column.
255
  *
@@ -334,11 +656,11 @@ class MLA_Example_List_Table extends WP_List_Table {
334
 
335
  if ( empty( $item->installed_version ) ) {
336
  if ( current_user_can( 'install_plugins' ) ) {
337
- $actions['install'] = '<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="' . __( 'Install this plugin', 'media-library-assistant' ) . '">' . __( 'Install', 'media-library-assistant' ) . '</a>';
338
  }
339
  } else {
340
  if ( current_user_can( 'update_plugins' ) ) {
341
- $actions['update'] = '<a href="' . add_query_arg( $view_args, wp_nonce_url( '?mla_admin_action=' . MLA::MLA_ADMIN_SINGLE_EDIT_UPDATE, MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ) ) . '" title="' . __( 'Update this plugin', 'media-library-assistant' ) . '">' . __( 'Update', 'media-library-assistant' ) . '</a>';
342
  }
343
  }
344
 
@@ -351,6 +673,8 @@ class MLA_Example_List_Table extends WP_List_Table {
351
  $actions['download'] = '<a href="' . add_query_arg( $args, wp_nonce_url( 'upload.php', MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ) ) . '" title="' . __( 'Download', 'media-library-assistant' ) . ' &#8220;' . esc_attr( $item->file ) . '&#8221;">' . __( 'Download', 'media-library-assistant' ) . '</a>';
352
  }
353
 
 
 
354
  return $actions;
355
  }
356
 
@@ -486,7 +810,7 @@ class MLA_Example_List_Table extends WP_List_Table {
486
  /**
487
  * Returns HTML markup for one view that can be used with this table
488
  *
489
- * @since 1.40
490
  *
491
  * @param string View slug
492
  * @param array count and labels for the View
@@ -524,7 +848,7 @@ class MLA_Example_List_Table extends WP_List_Table {
524
  * Returns an associative array listing all the views that can be used with this table.
525
  * These are listed across the top of the page and managed by WordPress.
526
  *
527
- * @since 1.40
528
  *
529
  * @return array View information,e.g., array ( id => link )
530
  */
@@ -646,7 +970,7 @@ class MLA_Example_List_Table extends WP_List_Table {
646
  private static function _process_example_plugin( $ID, $update = false ) {
647
  global $wp_filesystem;
648
 
649
- $plugin = MLA_Example_List_Table::_find_example_plugin( $ID );
650
  if ( !$plugin ) {
651
  /* translators: 1: plugin name */
652
  return sprintf( __( 'Example plugin "%1$s" not found', 'media-library-assistant' ), $ID );
@@ -731,7 +1055,7 @@ class MLA_Example_List_Table extends WP_List_Table {
731
  * @return string status/error messages
732
  */
733
  public static function mla_install_example_plugin( $ID ) {
734
- $plugin = MLA_Example_List_Table::_find_example_plugin( $ID );
735
  if ( !$plugin ) {
736
  /* translators: 1: plugin name */
737
  return sprintf( __( 'Example plugin "%1$s" not found', 'media-library-assistant' ), $ID );
@@ -761,7 +1085,7 @@ class MLA_Example_List_Table extends WP_List_Table {
761
  * @return string status/error messages
762
  */
763
  public static function mla_update_example_plugin( $ID ) {
764
- $plugin = MLA_Example_List_Table::_find_example_plugin( $ID );
765
  if ( !$plugin ) {
766
  /* translators: 1: plugin name */
767
  return sprintf( __( 'Example plugin "%1$s" not found', 'media-library-assistant' ), $ID );
@@ -816,7 +1140,7 @@ class MLA_Example_List_Table extends WP_List_Table {
816
  /**
817
  * Assemble the in-memory representation of the Example Plugins
818
  *
819
- * @since 1.40
820
  *
821
  * @param boolean Force a reload/recalculation of types
822
  *
@@ -974,7 +1298,7 @@ class MLA_Example_List_Table extends WP_List_Table {
974
  */
975
  if ( ! is_array( $raw_request ) ) {
976
  /* translators: 1: ERROR tag 2: function name 3: non-array value */
977
- error_log( sprintf( _x( '%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'MLAMime::_prepare_view_items_query', var_export( $raw_request, true ) ), 0 );
978
  return NULL;
979
  }
980
 
@@ -1077,6 +1401,9 @@ class MLA_Example_List_Table extends WP_List_Table {
1077
  }
1078
 
1079
  switch( $view ) {
 
 
 
1080
  case 'active':
1081
  $found = 'Active' === $value['status'];
1082
  break;
@@ -1188,7 +1515,7 @@ class MLA_Example_List_Table extends WP_List_Table {
1188
  *
1189
  * @return mixed MLA example_plugin object if it exists else false
1190
  */
1191
- private static function _find_example_plugin( $ID ) {
1192
  if ( ! self::_get_example_plugin_items() ) {
1193
  return false;
1194
  }
@@ -1253,6 +1580,10 @@ class MLA_Example_List_Table extends WP_List_Table {
1253
  'singular' => _x( 'All', 'table_view_singular', 'media_library-assistant' ),
1254
  'plural' => _x( 'All', 'table_view_plural', 'media_library-assistant' ),
1255
  'count' => 0 ),
 
 
 
 
1256
  'active' => array(
1257
  'singular' => _x( 'Active', 'table_view_singular', 'media_library-assistant' ),
1258
  'plural' => _x( 'Active', 'table_view_plural', 'media_library-assistant' ),
@@ -1277,12 +1608,15 @@ class MLA_Example_List_Table extends WP_List_Table {
1277
  switch ( $value->status ) {
1278
  case 'Active':
1279
  $example_items[ 'active' ]['count']++;
 
1280
  break;
1281
  case 'Inactive':
1282
  $example_items[ 'inactive' ]['count']++;
 
1283
  break;
1284
  case 'Network':
1285
  $example_items[ 'network' ]['count']++;
 
1286
  break;
1287
  default:
1288
  $example_items[ 'uninstalled' ]['count']++;
@@ -1345,5 +1679,6 @@ class MLA_Upgrader_Skin extends WP_Upgrader_Skin {
1345
  * Actions are added here, when the source file is loaded, because the MLA_Example_List_Table
1346
  * object is created too late to be useful.
1347
  */
1348
- add_action( 'admin_init', 'MLA_Example_List_Table::mla_admin_init_action' );
 
1349
  ?>
1
  <?php
2
  /**
3
+ * Manages the Settings/Media Library Assistant Documentation tab
4
  *
5
  * @package Media Library Assistant
6
+ * @since 2.40
7
+ */
8
+
9
+ /**
10
+ * Class MLA (Media Library Assistant) Settings Documentation implements the
11
+ * Settings/Media Library Assistant Documentation tab
12
+ *
13
+ * @package Media Library Assistant
14
+ * @since 2.40
15
  */
16
+ class MLASettings_Documentation {
17
+ /**
18
+ * Slug for localizing and enqueueing JavaScript
19
+ *
20
+ * @since 2.40
21
+ * @var string
22
+ */
23
+ const JAVASCRIPT_DOCUMENTATION_TAB_SLUG = 'mla-documentation-tab-scripts';
24
+
25
+ /**
26
+ * Object name for localizing JavaScript
27
+ *
28
+ * @since 2.40
29
+ * @var string
30
+ */
31
+ const JAVASCRIPT_DOCUMENTATION_TAB_OBJECT = 'mla_documentation_tab_vars';
32
+
33
+ /**
34
+ * Load the tab's Javascript files
35
+ *
36
+ * @since 2.40
37
+ *
38
+ * @param string $page_hook Name of the page being loaded
39
+ */
40
+ public static function mla_admin_enqueue_scripts( $page_hook ) {
41
+ global $wpdb, $wp_locale;
42
+
43
+ // Without a tab value that matches ours, there's nothing to do
44
+ if ( empty( $_REQUEST['mla_tab'] ) || 'documentation' !== $_REQUEST['mla_tab'] ) {
45
+ return;
46
+ }
47
+
48
+ // Initialize script variables
49
+ $script_variables = array(
50
+ );
51
+
52
+ $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
53
+
54
+ wp_enqueue_script( self::JAVASCRIPT_DOCUMENTATION_TAB_SLUG,
55
+ MLA_PLUGIN_URL . "js/mla-settings-shortcodes-tab-scripts{$suffix}.js",
56
+ array( 'jquery' ), MLACore::CURRENT_MLA_VERSION, false );
57
+
58
+ wp_localize_script( self::JAVASCRIPT_DOCUMENTATION_TAB_SLUG,
59
+ self::JAVASCRIPT_DOCUMENTATION_TAB_OBJECT, $script_variables );
60
+ }
61
+
62
+ /**
63
+ * Display (read-only) an Example Plugin
64
+ *
65
+ * @since 2.40
66
+ *
67
+ * @param integer MLA Example Plugin ID
68
+ *
69
+ * @return array 'message' => status/error messages, 'body' => tab content
70
+ */
71
+ private static function _display_example_plugin( $ID ) {
72
+ global $wp_filesystem;
73
+
74
+ $page_content = array(
75
+ 'message' => '',
76
+ 'body' => ''
77
+ );
78
+
79
+ $plugin = MLA_Example_List_Table::mla_find_example_plugin( $ID );
80
+ if ( !$plugin ) {
81
+ /* translators: 1: plugin name */
82
+ $page_content['message'] = sprintf( __( 'Example plugin "%1$s" not found', 'media-library-assistant' ), $ID );
83
+ return $page_content;
84
+ }
85
+
86
+ $source_path = MLA_PLUGIN_PATH . 'examples/plugins/' . $plugin->file;
87
+ $file_contents = @file_get_contents( $source_path, false );
88
+ if ( false === $file_contents ) {
89
+ $error_info = error_get_last();
90
+ if ( false !== ( $tail = strpos( $error_info['message'], '</a>]: ' ) ) ) {
91
+ $php_errormsg = ':<br>' . substr( $error_info['message'], $tail + 7 );
92
+ } else {
93
+ $php_errormsg = '.';
94
+ }
95
+
96
+ /* translators: 1: ERROR tag 2: file type 3: file name 4: error message*/
97
+ $page_content['message'] = sprintf( __( '%1$s: Reading the %2$s file ( %3$s ) "%4$s".', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'plugin', 'media-library-assistant' ), $plugin->file, $php_errormsg );
98
+ $file_contents = '';
99
+ }
100
+
101
+ // Compose tab content
102
+ $page_template_array = MLACore::mla_load_template( 'admin-display-settings-example-tab.tpl' );
103
+ $page_values = array (
104
+ 'View Plugin' => __( 'View Plugin', 'media-library-assistant' ),
105
+ 'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-documentation&mla_tab=documentation&mla-example-search=Search',
106
+ 'plugin_text' => $file_contents,
107
+ 'Close' => __( 'Close', 'media-library-assistant' ),
108
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
109
+ '_wp_http_referer' => wp_referer_field( false )
110
+ );
111
+
112
+ $page_content['body'] = MLAData::mla_parse_template( $page_template_array['view-plugin'], $page_values );
113
+
114
+ return $page_content;
115
+ }
116
+
117
+ /**
118
+ * Compose the Example Plugin tab content for the Settings/Documentation subpage
119
+ *
120
+ * @since 2.32
121
+ *
122
+ * @return array 'message' => status/error messages, 'body' => tab content
123
+ */
124
+ private static function _compose_example_tab() {
125
+ $page_template_array = MLACore::mla_load_template( 'admin-display-settings-example-tab.tpl' );
126
+
127
+ /*
128
+ * Display the Example Plugin Table
129
+ */
130
+ $_SERVER['REQUEST_URI'] = add_query_arg( array( 'mla-example-display' => 'true' ), remove_query_arg( array(
131
+ 'mla_admin_action',
132
+ 'mla_item_slug',
133
+ 'mla_item_ID',
134
+ '_wpnonce',
135
+ '_wp_http_referer',
136
+ 'action',
137
+ 'action2',
138
+ 'cb_attachment',
139
+ 'mla-example-search'
140
+ ), $_SERVER['REQUEST_URI'] ) );
141
+
142
+ // Create an instance of our package class
143
+ $MLAListExampleTable = new MLA_Example_List_Table();
144
+
145
+ // Fetch, prepare, sort, and filter our data
146
+ $MLAListExampleTable->prepare_items();
147
+
148
+ $page_content = array(
149
+ 'message' => '',
150
+ 'body' => ''
151
+ );
152
+
153
+ $page_values = array(
154
+ 'results' => ! empty( $_REQUEST['s'] ) ? ' - ' . __( 'Displaying search results for', 'media-library-assistant' ) . ': "' . $_REQUEST['s'] . '"' : '',
155
+ 'In this tab' => __( 'In this tab you can browse the list of MLA example plugins, install or update them in the Plugins/Installed Plugins area and see which examples you have already installed. <strong>To activate, deactivate or delete</strong> the plugins you must go to the Plugins/Installed Plugins admin submenu.' ),
156
+ /* translators: 1: Documentation hyperlink */
157
+ 'You can find' => sprintf( __( 'You can find more information about using the example plugins in the %1$s section of the Documentation or by clicking the <strong>"Help"</strong> tab in the upper-right corner of this screen.', 'media-library-assistant' ), '<a href="[+settingsURL+]?page=mla-settings-menu-documentation&amp;mla_tab=documentation#mla_example_plugins" title="' . __( 'Example plugin documentation', 'media-library-assistant' ) . '">' . __( 'The Example Plugins', 'media-library-assistant' ) . '</a>' ),
158
+ 'views' => '',
159
+ 'settingsURL' => admin_url('options-general.php'),
160
+ 'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-documentation&mla_tab=documentation',
161
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
162
+ 'Example Plugins' => __( 'Example Plugins', 'media-library-assistant' ),
163
+ 'Search Example Plugins' => __( 'Search Example Plugins', 'media-library-assistant' ),
164
+ 's' => isset( $_REQUEST['s'] ) ? esc_attr( stripslashes( $_REQUEST['s'] ) ) : '',
165
+ 'Search Plugins' => __( 'Search Plugins', 'media-library-assistant' ),
166
+ 'Search help' => __( 'Searches Name, Description, File Name and Tags', 'media-library-assistant' ),
167
+ 'Cancel' => __( 'Cancel', 'media-library-assistant' ),
168
+ );
169
+
170
+ ob_start();
171
+ $MLAListExampleTable->views();
172
+ $page_values['views'] = ob_get_contents();
173
+ ob_end_clean();
174
+
175
+ $page_content['body'] = MLAData::mla_parse_template( $page_template_array['before-example-table'], $page_values );
176
+
177
+ // Now we can render the completed list table
178
+ ob_start();
179
+ $MLAListExampleTable->display();
180
+ $page_content['body'] .= ob_get_contents();
181
+ ob_end_clean();
182
+
183
+ $page_content['body'] .= MLAData::mla_parse_template( $page_template_array['after-example-table'], $page_values );
184
+
185
+ return $page_content;
186
+ }
187
+
188
+ /**
189
+ * Compose the Documentation tab content for the Settings subpage
190
+ *
191
+ * @since 0.80
192
+ * @uses $page_template_array contains tab content template(s)
193
+ *
194
+ * @return array 'message' => status/error messages, 'body' => tab content
195
+ */
196
+ public static function mla_compose_documentation_tab( ) {
197
+ /*
198
+ * Display or Cancel the Example Plugins submenu, if requested
199
+ */
200
+ if ( !empty( $_REQUEST['mla-example-search'] ) ) {
201
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
202
+ $page_content = self::_compose_example_tab();
203
+ } elseif ( !empty( $_REQUEST['mla-example-cancel'] ) ) {
204
+ $page_content = array(
205
+ 'message' => '',
206
+ 'body' => ''
207
+ );
208
+ } elseif ( !empty( $_REQUEST['mla-example-display'] ) ) {
209
+ if ( 'true' != $_REQUEST['mla-example-display'] ) {
210
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
211
+ }
212
+ $page_content = self::_compose_example_tab();
213
+ } else {
214
+ $page_content = array(
215
+ 'message' => '',
216
+ 'body' => ''
217
+ );
218
+ }
219
+
220
+ /*
221
+ * Process bulk actions that affect an array of items
222
+ */
223
+ $bulk_action = MLASettings::mla_current_bulk_action();
224
+ if ( $bulk_action && ( $bulk_action != 'none' ) ) {
225
+ $bulk_message = '';
226
+ if ( isset( $_REQUEST['cb_mla_item_ID'] ) ) {
227
+ foreach ( $_REQUEST['cb_mla_item_ID'] as $ID ) {
228
+ switch ( $bulk_action ) {
229
+ case 'install':
230
+ $item_content = MLA_Example_List_Table::mla_install_example_plugin( $ID );
231
+ break;
232
+ case 'update':
233
+ $item_content = MLA_Example_List_Table::mla_update_example_plugin( $ID );
234
+ break;
235
+ default:
236
+ /* translators: 1: bulk_action, e.g., delete, edit, restore, trash */
237
+ $item_content = sprintf( __( 'Unknown bulk action %1$s', 'media-library-assistant' ), $bulk_action );
238
+ break 2; // Exit the switch and the foreach
239
+ ;
240
+ } // switch ($_REQUEST['mla_admin_action'])
241
+
242
+ $bulk_message .= $item_content . '<br>';
243
+ } // foreach $ID
244
+ } // isset cb_attachment
245
+ else {
246
+ /* translators: 1: action name, e.g., edit */
247
+ $bulk_message = sprintf( __( 'Bulk Action %1$s - no items selected.', 'media-library-assistant' ), $bulk_action );
248
+ }
249
+
250
+ $page_content = self::_compose_example_tab();
251
+ $page_content['message'] = $bulk_message;
252
+ } // $bulk_action
253
+
254
+ /*
255
+ * Process row-level actions that affect a single item
256
+ */
257
+ if ( !empty( $_REQUEST['mla_admin_action'] ) ) {
258
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
259
+ $action_content = array( 'message' => '' );
260
+ if ( empty( $_REQUEST['mla_item_ID'] ) ) {
261
+ /* translators: 1: bulk_action, e.g., single_item_delete, single_item_edit */
262
+ $action_content['message'] = sprintf( __( 'Empty mla_item_ID - "%1$s"', 'media-library-assistant' ), $_REQUEST['mla_admin_action'] );
263
+ } else {
264
+ switch ( $_REQUEST['mla_admin_action'] ) {
265
+ case MLACore::MLA_ADMIN_SINGLE_EDIT_INSTALL:
266
+ $action_content = MLA_Example_List_Table::mla_install_example_plugin( $_REQUEST['mla_item_ID'] );
267
+ break;
268
+ case MLACore::MLA_ADMIN_SINGLE_EDIT_UPDATE:
269
+ $action_content = MLA_Example_List_Table::mla_update_example_plugin( $_REQUEST['mla_item_ID'] );
270
+ break;
271
+ case MLACore::MLA_ADMIN_SINGLE_EDIT_DISPLAY:
272
+ $action_content = MLASettings_Documentation::_display_example_plugin( $_REQUEST['mla_item_ID'] );
273
+ if ( !empty( $action_content['body'] ) ) {
274
+ return $action_content;
275
+ }
276
+
277
+ $action_content = $action_content['message'];
278
+ break;
279
+ default:
280
+ /* translators: 1: bulk_action, e.g., single_item_delete, single_item_edit */
281
+ $action_content = sprintf( __( 'Unknown mla_admin_action - "%1$s"', 'media-library-assistant' ), $_REQUEST['mla_admin_action'] );
282
+ break;
283
+ } // switch ($_REQUEST['mla_admin_action'])
284
+ }
285
+
286
+ $page_content = self::_compose_example_tab();
287
+ $page_content['message'] = $action_content;
288
+ } // (!empty($_REQUEST['mla_admin_action'])
289
+
290
+ if ( !empty( $page_content['body'] ) ) {
291
+ return $page_content;
292
+ }
293
+
294
+ $page_template = MLACore::mla_load_template( 'documentation-settings-tab.tpl' );
295
+ if ( ! is_array( $page_template ) ) {
296
+ /* translators: 1: ERROR tag 2: function name 3: non-array value */
297
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'MLASettings::_compose_documentation_tab', var_export( $page_template, true ) ), MLACore::MLA_DEBUG_CATEGORY_ANY );
298
+ return '';
299
+ }
300
+
301
+ /*
302
+ * Display the Documentation tab
303
+ */
304
+ $page_values = array(
305
+ 'example_url' => wp_nonce_url( '?page=mla-settings-menu-documentation&mla_tab=documentation&mla-example-search=Search', MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ),
306
+ 'translate_url' => MLA_PLUGIN_URL . 'languages/MLA Internationalization Guide.pdf',
307
+ 'phpDocs_url' => MLA_PLUGIN_URL . 'phpDocs/index.html',
308
+ );
309
+
310
+ $page_content['body'] = MLAData::mla_parse_template( $page_template['documentation-tab'], $page_values );
311
+ return $page_content;
312
+ }
313
+
314
+ } // class MLASettings_Documentation
315
 
316
  /*
317
  * The WP_List_Table class isn't automatically available to plugins
341
  * @since 2.32
342
  */
343
  class MLA_Example_List_Table extends WP_List_Table {
344
+ /**
345
+ * Calls the parent constructor to set some default values.
346
+ *
347
+ * @since 2.32
348
+ *
349
+ * @return void
350
+ */
351
+ function __construct( ) {
352
+ //Set parent defaults
353
+ parent::__construct( array(
354
+ 'singular' => 'example_plugin', //singular name of the listed records
355
+ 'plural' => 'example_plugins', //plural name of the listed records
356
+ 'ajax' => false, //does this table support ajax?
357
+ 'screen' => 'settings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-example'
358
+ ) );
359
+
360
+ /*
361
+ * NOTE: There is one add_action call at the end of this source file.
362
+ */
363
+ }
364
+
365
  /**
366
  * Table column definitions
367
  *
368
  * This array defines table columns and titles where the key is the column slug (and class)
369
  * and the value is the column's title text.
370
  *
371
+ * All of the columns are added to this array by MLA_Example_List_Table::_localize_default_columns_array.
372
  *
373
  * @since 2.32
374
  *
441
  * @return array name => array( orderby value, heading ) for sortable columns
442
  */
443
  public static function mla_get_sortable_columns( ) {
444
+ self::_localize_default_columns_array();
445
+ $columns = self::$default_sortable_columns;
446
+
447
+ if ( isset( $_REQUEST['orderby'] ) ) {
448
+ $needle = array( $_REQUEST['orderby'], false );
449
+ $key = array_search( $needle, $columns );
450
+ if ( $key ) {
451
+ $columns[ $key ][ 1 ] = true;
452
+ }
453
+ } else {
454
+ $columns['name'][ 1 ] = true;
455
+ }
456
+
457
+ return $columns;
458
  $results = array() ;
459
 
460
  foreach ( self::$default_sortable_columns as $key => $value ) {
496
  * @return array list of table columns
497
  */
498
  public static function mla_manage_columns_filter( ) {
499
+ self::_localize_default_columns_array();
500
  return self::$default_columns;
501
  }
502
 
510
  *
511
  * @return void
512
  */
513
+ private static function _localize_default_columns_array( ) {
514
+ if ( empty( self::$default_columns ) ) {
515
+ // Build the default columns array at runtime to accomodate calls to the localization functions
516
+ self::$default_columns = array(
517
+ 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
518
+ 'name' => _x( 'Name', 'list_table_column', 'media-library-assistant' ),
519
+ 'version' => _x( 'Current Version', 'list_table_column', 'media-library-assistant' ),
520
+ 'installed_version' => _x( 'Installed Version', 'list_table_column', 'media-library-assistant' ),
521
+ 'description' => _x( 'Description', 'list_table_column', 'media-library-assistant' ),
522
+ 'file' => _x( 'File Name', 'list_table_column', 'media-library-assistant' ),
523
+ 'tags' => _x( 'Tags', 'list_table_column', 'media-library-assistant' ),
524
+ );
525
+ }
526
  }
527
 
528
  /**
559
  *
560
  * @return void
561
  */
562
+ public static function mla_admin_init( ) {
563
+ //error_log( __LINE__ . ' mla_admin_init request = ' . var_export( $_REQUEST, true ), 0 );
564
  if ( isset( $_REQUEST['mla-example-cancel'] ) ) {
565
  unset( $_REQUEST['mla-example-display'] );
566
  }
572
  }
573
  }
574
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
575
  /**
576
  * Get the name of the default primary column.
577
  *
656
 
657
  if ( empty( $item->installed_version ) ) {
658
  if ( current_user_can( 'install_plugins' ) ) {
659
+ $actions['install'] = '<a href="' . add_query_arg( $view_args, wp_nonce_url( '?mla_admin_action=' . MLACore::MLA_ADMIN_SINGLE_EDIT_INSTALL, MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ) ) . '" title="' . __( 'Install this plugin', 'media-library-assistant' ) . '">' . __( 'Install', 'media-library-assistant' ) . '</a>';
660
  }
661
  } else {
662
  if ( current_user_can( 'update_plugins' ) ) {
663
+ $actions['update'] = '<a href="' . add_query_arg( $view_args, wp_nonce_url( '?mla_admin_action=' . MLACore::MLA_ADMIN_SINGLE_EDIT_UPDATE, MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ) ) . '" title="' . __( 'Update this plugin', 'media-library-assistant' ) . '">' . __( 'Update', 'media-library-assistant' ) . '</a>';
664
  }
665
  }
666
 
673
  $actions['download'] = '<a href="' . add_query_arg( $args, wp_nonce_url( 'upload.php', MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ) ) . '" title="' . __( 'Download', 'media-library-assistant' ) . ' &#8220;' . esc_attr( $item->file ) . '&#8221;">' . __( 'Download', 'media-library-assistant' ) . '</a>';
674
  }
675
 
676
+ $actions['view'] = '<a href="' . add_query_arg( $view_args, wp_nonce_url( '?mla_admin_action=' . MLACore::MLA_ADMIN_SINGLE_EDIT_DISPLAY, MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ) ) . '" title="' . __( 'View this item', 'media-library-assistant' ) . '">' . __( 'View', 'media-library-assistant' ) . '</a>';
677
+
678
  return $actions;
679
  }
680
 
810
  /**
811
  * Returns HTML markup for one view that can be used with this table
812
  *
813
+ * @since 2.32
814
  *
815
  * @param string View slug
816
  * @param array count and labels for the View
848
  * Returns an associative array listing all the views that can be used with this table.
849
  * These are listed across the top of the page and managed by WordPress.
850
  *
851
+ * @since 2.32
852
  *
853
  * @return array View information,e.g., array ( id => link )
854
  */
970
  private static function _process_example_plugin( $ID, $update = false ) {
971
  global $wp_filesystem;
972
 
973
+ $plugin = MLA_Example_List_Table::mla_find_example_plugin( $ID );
974
  if ( !$plugin ) {
975
  /* translators: 1: plugin name */
976
  return sprintf( __( 'Example plugin "%1$s" not found', 'media-library-assistant' ), $ID );
1055
  * @return string status/error messages
1056
  */
1057
  public static function mla_install_example_plugin( $ID ) {
1058
+ $plugin = MLA_Example_List_Table::mla_find_example_plugin( $ID );
1059
  if ( !$plugin ) {
1060
  /* translators: 1: plugin name */
1061
  return sprintf( __( 'Example plugin "%1$s" not found', 'media-library-assistant' ), $ID );
1085
  * @return string status/error messages
1086
  */
1087
  public static function mla_update_example_plugin( $ID ) {
1088
+ $plugin = MLA_Example_List_Table::mla_find_example_plugin( $ID );
1089
  if ( !$plugin ) {
1090
  /* translators: 1: plugin name */
1091
  return sprintf( __( 'Example plugin "%1$s" not found', 'media-library-assistant' ), $ID );
1140
  /**
1141
  * Assemble the in-memory representation of the Example Plugins
1142
  *
1143
+ * @since 2.32
1144
  *
1145
  * @param boolean Force a reload/recalculation of types
1146
  *
1298
  */
1299
  if ( ! is_array( $raw_request ) ) {
1300
  /* translators: 1: ERROR tag 2: function name 3: non-array value */
1301
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'MLAMime::_prepare_view_items_query', var_export( $raw_request, true ) ), MLACore::MLA_DEBUG_CATEGORY_ANY );
1302
  return NULL;
1303
  }
1304
 
1401
  }
1402
 
1403
  switch( $view ) {
1404
+ case 'installed':
1405
+ $found = '' !== $value['status'];
1406
+ break;
1407
  case 'active':
1408
  $found = 'Active' === $value['status'];
1409
  break;
1515
  *
1516
  * @return mixed MLA example_plugin object if it exists else false
1517
  */
1518
+ public static function mla_find_example_plugin( $ID ) {
1519
  if ( ! self::_get_example_plugin_items() ) {
1520
  return false;
1521
  }
1580
  'singular' => _x( 'All', 'table_view_singular', 'media_library-assistant' ),
1581
  'plural' => _x( 'All', 'table_view_plural', 'media_library-assistant' ),
1582
  'count' => 0 ),
1583
+ 'installed' => array(
1584
+ 'singular' => _x( 'Installed', 'table_view_singular', 'media_library-assistant' ),
1585
+ 'plural' => _x( 'Installed', 'table_view_plural', 'media_library-assistant' ),
1586
+ 'count' => 0 ),
1587
  'active' => array(
1588
  'singular' => _x( 'Active', 'table_view_singular', 'media_library-assistant' ),
1589
  'plural' => _x( 'Active', 'table_view_plural', 'media_library-assistant' ),
1608
  switch ( $value->status ) {
1609
  case 'Active':
1610
  $example_items[ 'active' ]['count']++;
1611
+ $example_items[ 'installed' ]['count']++;
1612
  break;
1613
  case 'Inactive':
1614
  $example_items[ 'inactive' ]['count']++;
1615
+ $example_items[ 'installed' ]['count']++;
1616
  break;
1617
  case 'Network':
1618
  $example_items[ 'network' ]['count']++;
1619
+ $example_items[ 'installed' ]['count']++;
1620
  break;
1621
  default:
1622
  $example_items[ 'uninstalled' ]['count']++;
1679
  * Actions are added here, when the source file is loaded, because the MLA_Example_List_Table
1680
  * object is created too late to be useful.
1681
  */
1682
+ //add_action( 'admin_enqueue_scripts', 'MLASettings_Documentation::mla_admin_enqueue_scripts' );
1683
+ add_action( 'admin_init', 'MLA_Example_List_Table::mla_admin_init' );
1684
  ?>
includes/class-mla-settings-iptc-exif-tab.php ADDED
@@ -0,0 +1,660 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Manages the Settings/Media Library Assistant IPTC EXIF tab
4
+ *
5
+ * @package Media Library Assistant
6
+ * @since 2.40
7
+ */
8
+
9
+ /**
10
+ * Class MLA (Media Library Assistant) Settings IPTC EXIF implements the
11
+ * Settings/Media Library Assistant IPTC EXIF tab
12
+ *
13
+ * @package Media Library Assistant
14
+ * @since 2.40
15
+ */
16
+ class MLASettings_IPTCEXIF {
17
+ /**
18
+ * Load the tab's Javascript files
19
+ *
20
+ * @since 2.40
21
+ *
22
+ * @param string $page_hook Name of the page being loaded
23
+ */
24
+ public static function mla_admin_enqueue_scripts( $page_hook ) {
25
+ global $wpdb;
26
+
27
+ // Without a tab value that matches ours, there's nothing to do
28
+ if ( empty( $_REQUEST['mla_tab'] ) || 'iptc_exif' !== $_REQUEST['mla_tab'] ) {
29
+ return;
30
+ }
31
+
32
+ /*
33
+ * Initialize script variables
34
+ */
35
+ $script_variables = array(
36
+ 'error' => __( 'Error while making the changes.', 'media-library-assistant' ),
37
+ 'ntdeltitle' => __( 'Remove From Bulk Edit', 'media-library-assistant' ),
38
+ 'notitle' => '(' . __( 'no slug', 'media-library-assistant' ) . ')',
39
+ 'comma' => _x( ',', 'tag_delimiter', 'media-library-assistant' ),
40
+ 'useSpinnerClass' => false,
41
+ 'ajax_nonce' => wp_create_nonce( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ),
42
+ 'bulkChunkSize' => MLACore::mla_get_option( MLACoreOptions::MLA_BULK_CHUNK_SIZE ),
43
+ 'bulkWaiting' => __( 'Waiting', 'media-library-assistant' ),
44
+ 'bulkRunning' => __( 'Running', 'media-library-assistant' ),
45
+ 'bulkComplete' => __( 'Complete', 'media-library-assistant' ),
46
+ 'bulkUnchanged' => __( 'Unchanged', 'media-library-assistant' ),
47
+ 'bulkSuccess' => __( 'Succeeded', 'media-library-assistant' ),
48
+ 'bulkFailure' => __( 'Failed', 'media-library-assistant' ),
49
+ 'bulkSkip' => __( 'Skipped', 'media-library-assistant' ),
50
+ 'bulkRedone' => __( 'Reprocessed', 'media-library-assistant' ),
51
+ 'bulkPaused' => __( 'PAUSED', 'media-library-assistant' ),
52
+
53
+ 'page' => 'mla-settings-menu-iptc_exif',
54
+ 'mla_tab' => 'iptc_exif',
55
+ 'screen' => 'settings_page_mla-settings-menu-iptc_exif',
56
+ 'ajax_action' => MLASettings::JAVASCRIPT_INLINE_MAPPING_IPTC_EXIF_SLUG,
57
+ 'fieldsId' => '#mla-display-settings-iptc-exif-tab',
58
+ 'totalItems' => $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE `post_type` = 'attachment' AND ( `post_mime_type` LIKE 'image/%' OR `post_mime_type` LIKE 'application/%pdf%' )" )
59
+ );
60
+
61
+ if ( version_compare( get_bloginfo( 'version' ), '4.2', '>=' ) ) {
62
+ $script_variables['useSpinnerClass'] = true;
63
+ }
64
+
65
+ $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
66
+
67
+ wp_enqueue_script( MLASettings::JAVASCRIPT_INLINE_MAPPING_IPTC_EXIF_SLUG,
68
+ MLA_PLUGIN_URL . "js/mla-inline-mapping-scripts{$suffix}.js",
69
+ array( 'jquery' ), MLACore::CURRENT_MLA_VERSION, false );
70
+
71
+ wp_localize_script( MLASettings::JAVASCRIPT_INLINE_MAPPING_IPTC_EXIF_SLUG,
72
+ MLASettings::JAVASCRIPT_INLINE_MAPPING_OBJECT, $script_variables );
73
+ }
74
+
75
+ /**
76
+ * Save IPTC/EXIF custom field settings to the options table
77
+ *
78
+ * @since 1.30
79
+ *
80
+ * @param array specific iptc_exif_custom_mapping values
81
+ *
82
+ * @return array Message(s) reflecting the results of the operation
83
+ */
84
+ private static function _save_iptc_exif_custom_settings( $new_values ) {
85
+ return array(
86
+ 'message' => MLAOptions::mla_iptc_exif_option_handler( 'update', 'iptc_exif_custom_mapping', MLACoreOptions::$mla_option_definitions['iptc_exif_mapping'], $new_values ),
87
+ 'body' => ''
88
+ );
89
+ } // _save_iptc_exif_custom_settings
90
+
91
+ /**
92
+ * Save IPTC/EXIF settings to the options table
93
+ *
94
+ * @since 1.00
95
+ *
96
+ * @uses $_REQUEST
97
+ *
98
+ * @return array Message(s) reflecting the results of the operation
99
+ */
100
+ private static function _save_iptc_exif_settings( ) {
101
+ $message_list = '';
102
+ $option_messages = '';
103
+
104
+ /*
105
+ * Start with any page-level options
106
+ */
107
+ foreach ( MLACoreOptions::$mla_option_definitions as $key => $value ) {
108
+ if ( 'iptc_exif' == $value['tab'] ) {
109
+ $option_messages .= MLASettings::mla_update_option_row( $key, $value );
110
+ }
111
+ }
112
+
113
+ /*
114
+ * Uncomment this for debugging.
115
+ */
116
+ //$message_list = $option_messages . '<br>';
117
+
118
+ /*
119
+ * Add mapping options
120
+ */
121
+ $new_values = ( isset( $_REQUEST['iptc_exif_mapping'] ) ) ? $_REQUEST['iptc_exif_mapping'] : array( 'standard' => array(), 'taxonomy' => array(), 'custom' => array() );
122
+
123
+ return array(
124
+ 'message' => $message_list . MLAOptions::mla_iptc_exif_option_handler( 'update', 'iptc_exif_mapping', MLACoreOptions::$mla_option_definitions['iptc_exif_mapping'], $new_values ),
125
+ 'body' => ''
126
+ );
127
+ } // _save_iptc_exif_settings
128
+
129
+ /**
130
+ * Process IPTC/EXIF standard field settings against all image attachments
131
+ * without saving the settings to the mla_option
132
+ *
133
+ * @since 1.00
134
+ *
135
+ * @uses $_REQUEST
136
+ *
137
+ * @param integer offset for chunk mapping
138
+ * @param integer length for chunk mapping
139
+ *
140
+ * @return array Message(s) reflecting the results of the operation
141
+ */
142
+ private static function _process_iptc_exif_standard( $offset = 0, $length = 0 ) {
143
+ if ( ! isset( $_REQUEST['iptc_exif_mapping']['standard'] ) ) {
144
+ return array(
145
+ /* translators: 1: ERROR tag 2: field type */
146
+ 'message' => sprintf( __( '%1$s: No %2$s settings to process.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'Standard field', 'media-library-assistant' ) ),
147
+ 'body' => '',
148
+ 'processed' => 0,
149
+ 'unchanged' => 0,
150
+ 'success' => 0,
151
+ );
152
+ }
153
+
154
+ $examine_count = 0;
155
+ $update_count = 0;
156
+ $query = array( 'orderby' => 'none', 'post_parent' => 'all', 'post_mime_type' => 'image,application/*pdf*' );
157
+
158
+ if ( $length > 0 ) {
159
+ $query['numberposts'] = $length;
160
+ $query['offset'] = $offset;
161
+ }
162
+
163
+ do_action( 'mla_begin_mapping', 'iptc_exif_standard', NULL );
164
+ $posts = MLAShortcodes::mla_get_shortcode_attachments( 0, $query );
165
+
166
+ if ( is_string( $posts ) ) {
167
+ return array(
168
+ 'message' => $posts,
169
+ 'body' => ''
170
+ );
171
+ }
172
+
173
+ foreach ( $posts as $key => $post ) {
174
+ $updates = MLAOptions::mla_evaluate_iptc_exif_mapping( $post, 'iptc_exif_standard_mapping', $_REQUEST['iptc_exif_mapping'] );
175
+
176
+ $examine_count += 1;
177
+ if ( ! empty( $updates ) ) {
178
+ $results = MLAData::mla_update_single_item( $post->ID, $updates );
179
+ if ( stripos( $results['message'], __( 'updated.', 'media-library-assistant' ) ) ) {
180
+ $update_count += 1;
181
+ }
182
+ }
183
+ } // foreach post
184
+ do_action( 'mla_end_mapping' );
185
+
186
+ if ( $update_count ) {
187
+ /* translators: 1: field type 2: examined count 3: updated count */
188
+ $message = sprintf( __( '%1$s mapping completed; %2$d attachment(s) examined, %3$d updated.' ), 'IPTC/EXIF ' . __( 'Standard field', 'media-library-assistant' ), $examine_count, $update_count ) . "\r\n";
189
+ } else {
190
+ /* translators: 1: field type 2: examined count */
191
+ $message = sprintf( __( '%1$s mapping completed; %2$d attachment(s) examined, no changes detected.' ), 'IPTC/EXIF ' . __( 'Standard field', 'media-library-assistant' ), $examine_count ) . "\r\n";
192
+ }
193
+
194
+ return array(
195
+ 'message' => $message,
196
+ 'body' => '',
197
+ 'processed' => $examine_count,
198
+ 'unchanged' => $examine_count - $update_count,
199
+ 'success' => $update_count
200
+ );
201
+ } // _process_iptc_exif_standard
202
+
203
+ /**
204
+ * Process IPTC/EXIF taxonomy term settings against all image attachments
205
+ * without saving the settings to the mla_option
206
+ *
207
+ * @since 1.00
208
+ *
209
+ * @uses $_REQUEST
210
+ *
211
+ * @param integer offset for chunk mapping
212
+ * @param integer length for chunk mapping
213
+ *
214
+ * @return array Message(s) reflecting the results of the operation
215
+ */
216
+ private static function _process_iptc_exif_taxonomy( $offset = 0, $length = 0 ) {
217
+ if ( ! isset( $_REQUEST['iptc_exif_mapping']['taxonomy'] ) ) {
218
+ return array(
219
+ /* translators: 1: ERROR tag 2: field type */
220
+ 'message' => sprintf( __( '%1$s: No %2$s settings to process.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'Taxonomy term', 'media-library-assistant' ) ),
221
+ 'body' => '',
222
+ 'processed' => 0,
223
+ 'unchanged' => 0,
224
+ 'success' => 0,
225
+ );
226
+ }
227
+
228
+ $examine_count = 0;
229
+ $update_count = 0;
230
+ $query = array( 'orderby' => 'none', 'post_parent' => 'all', 'post_mime_type' => 'image,application/*pdf*' );
231
+
232
+ if ( $length > 0 ) {
233
+ $query['numberposts'] = $length;
234
+ $query['offset'] = $offset;
235
+ }
236
+
237
+ do_action( 'mla_begin_mapping', 'iptc_exif_taxonomy', NULL );
238
+ $posts = MLAShortcodes::mla_get_shortcode_attachments( 0, $query );
239
+
240
+ if ( is_string( $posts ) ) {
241
+ return array(
242
+ 'message' => $posts,
243
+ 'body' => ''
244
+ );
245
+ }
246
+
247
+ foreach ( $posts as $key => $post ) {
248
+
249
+ $updates = MLAOptions::mla_evaluate_iptc_exif_mapping( $post, 'iptc_exif_taxonomy_mapping', $_REQUEST['iptc_exif_mapping'] );
250
+
251
+ $examine_count += 1;
252
+ if ( ! empty( $updates ) ) {
253
+ $results = MLAData::mla_update_single_item( $post->ID, array(), $updates['taxonomy_updates']['inputs'], $updates['taxonomy_updates']['actions'] );
254
+ if ( stripos( $results['message'], __( 'updated.', 'media-library-assistant' ) ) ) {
255
+ $update_count += 1;
256
+ }
257
+ }
258
+ } // foreach post
259
+ do_action( 'mla_end_mapping' );
260
+
261
+ if ( $update_count ) {
262
+ /* translators: 1: field type 2: examined count 3: updated count */
263
+ $message = sprintf( __( '%1$s mapping completed; %2$d attachment(s) examined, %3$d updated.' ), 'IPTC/EXIF ' . __( 'Taxonomy term', 'media-library-assistant' ), $examine_count, $update_count ) . "\r\n";
264
+ } else {
265
+ /* translators: 1: field type 2: examined count */
266
+ $message = sprintf( __( '%1$s mapping completed; %2$d attachment(s) examined, no changes detected.' ), 'IPTC/EXIF ' . __( 'Taxonomy term', 'media-library-assistant' ), $examine_count ) . "\r\n";
267
+ }
268
+
269
+ return array(
270
+ 'message' => $message,
271
+ 'body' => '',
272
+ 'processed' => $examine_count,
273
+ 'unchanged' => $examine_count - $update_count,
274
+ 'success' => $update_count
275
+ );
276
+ } // _process_iptc_exif_taxonomy
277
+
278
+ /**
279
+ * Process IPTC/EXIF custom field settings against all image attachments
280
+ * without saving the settings to the mla_option
281
+ *
282
+ * @since 1.00
283
+ *
284
+ * @uses $_REQUEST if passed a NULL parameter
285
+ *
286
+ * @param array | NULL specific iptc_exif_custom_mapping values
287
+ * @param integer offset for chunk mapping
288
+ * @param integer length for chunk mapping
289
+ *
290
+ * @return array Message(s) reflecting the results of the operation
291
+ */
292
+ private static function _process_iptc_exif_custom( $settings = NULL, $offset = 0, $length = 0 ) {
293
+ if ( NULL == $settings ) {
294
+ $source = 'iptc_exif_custom';
295
+ $settings = ( isset( $_REQUEST['iptc_exif_mapping'] ) ) ? stripslashes_deep( $_REQUEST['iptc_exif_mapping'] ) : array();
296
+ if ( isset( $settings['custom'][ MLACoreOptions::MLA_NEW_CUSTOM_FIELD ] ) ) {
297
+ unset( $settings['custom'][ MLACoreOptions::MLA_NEW_CUSTOM_FIELD ] );
298
+ }
299
+ if ( isset( $settings['custom'][ MLACoreOptions::MLA_NEW_CUSTOM_RULE ] ) ) {
300
+ unset( $settings['custom'][ MLACoreOptions::MLA_NEW_CUSTOM_RULE ] );
301
+ }
302
+ } else {
303
+ $source = 'iptc_exif_custom_rule';
304
+ $settings = stripslashes_deep( $settings );
305
+ }
306
+
307
+ if ( empty( $settings['custom'] ) ) {
308
+ return array(
309
+ /* translators: 1: ERROR tag 2: field type */
310
+ 'message' => sprintf( __( '%1$s: No %2$s settings to process.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'Custom field', 'media-library-assistant' ) ),
311
+ 'body' => '',
312
+ 'processed' => 0,
313
+ 'unchanged' => 0,
314
+ 'success' => 0,
315
+ );
316
+ }
317
+
318
+ $examine_count = 0;
319
+ $update_count = 0;
320
+ $query = array( 'orderby' => 'none', 'post_parent' => 'all', 'post_mime_type' => 'image,application/*pdf*' );
321
+
322
+ if ( $length > 0 ) {
323
+ $query['numberposts'] = $length;
324
+ $query['offset'] = $offset;
325
+ }
326
+
327
+ do_action( 'mla_begin_mapping', $source, NULL );
328
+ $posts = MLAShortcodes::mla_get_shortcode_attachments( 0, $query );
329
+
330
+ if ( is_string( $posts ) ) {
331
+ return array(
332
+ 'message' => $posts,
333
+ 'body' => ''
334
+ );
335
+ }
336
+
337
+ foreach ( $posts as $key => $post ) {
338
+ $updates = MLAOptions::mla_evaluate_iptc_exif_mapping( $post, 'iptc_exif_custom_mapping', $settings );
339
+
340
+ $examine_count += 1;
341
+ if ( ! empty( $updates ) ) {
342
+ $results = MLAData::mla_update_single_item( $post->ID, $updates );
343
+ if ( stripos( $results['message'], __( 'updated.', 'media-library-assistant' ) ) ) {
344
+ $update_count += 1;
345
+ }
346
+ }
347
+ } // foreach post
348
+ do_action( 'mla_end_mapping' );
349
+
350
+ if ( $update_count ) {
351
+ /* translators: 1: field type 2: examined count 3: updated count */
352
+ $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";
353
+ } else {
354
+ /* translators: 1: field type 2: examined count */
355
+ $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";
356
+ }
357
+
358
+ return array(
359
+ 'message' => $message,
360
+ 'body' => '',
361
+ 'processed' => $examine_count,
362
+ 'unchanged' => $examine_count - $update_count,
363
+ 'success' => $update_count
364
+ );
365
+ } // _process_iptc_exif_custom
366
+
367
+ /**
368
+ * Compose the IPTC/EXIF tab content for the Settings subpage
369
+ *
370
+ * @since 1.00
371
+ * @uses $page_template_array contains tab content template(s)
372
+ *
373
+ * @return array 'message' => status/error messages, 'body' => tab content
374
+ */
375
+ public static function mla_compose_iptc_exif_tab( ) {
376
+ /*
377
+ * Initialize page messages and content.
378
+ * Check for submit buttons to change or reset settings.
379
+ */
380
+ $page_content = array(
381
+ 'message' => '',
382
+ 'body' => ''
383
+ );
384
+
385
+ if ( isset( $_REQUEST['iptc_exif_mapping'] ) && is_array( $_REQUEST['iptc_exif_mapping'] ) ) {
386
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
387
+
388
+ if ( !empty( $_REQUEST['iptc-exif-options-save'] ) ) {
389
+ $page_content = self::_save_iptc_exif_settings( );
390
+ } elseif ( !empty( $_REQUEST['iptc-exif-options-process-standard'] ) ) {
391
+ $page_content = self::_process_iptc_exif_standard( );
392
+ } elseif ( !empty( $_REQUEST['iptc-exif-options-process-taxonomy'] ) ) {
393
+ $page_content = self::_process_iptc_exif_taxonomy( );
394
+ } elseif ( !empty( $_REQUEST['iptc-exif-options-process-custom'] ) ) {
395
+ $page_content = self::_process_iptc_exif_custom( );
396
+ } else {
397
+ /*
398
+ * Check for single-rule action buttons
399
+ */
400
+ foreach ( $_REQUEST['iptc_exif_mapping']['custom'] as $key => $value ) {
401
+ $value = stripslashes_deep( $value );
402
+
403
+ if ( isset( $value['action'] ) ) {
404
+ $settings = array( 'custom' => array( $key => $value ) );
405
+ foreach ( $value['action'] as $action => $label ) {
406
+ switch( $action ) {
407
+ case 'delete_field':
408
+ $delete_result = MLASettings::mla_delete_custom_field( $value );
409
+ case 'delete_rule':
410
+ case 'add_rule':
411
+ case 'add_field':
412
+ case 'update_rule':
413
+ $page_content = self::_save_iptc_exif_custom_settings( $settings );
414
+ if ( isset( $delete_result ) ) {
415
+ $page_content['message'] = $delete_result . $page_content['message'];
416
+ }
417
+ break;
418
+ case 'map_now':
419
+ $page_content = self::_process_iptc_exif_custom( $settings );
420
+ break;
421
+ case 'add_rule_map':
422
+ case 'add_field_map':
423
+ $page_content = self::_save_iptc_exif_custom_settings( $settings );
424
+ if ( false === strpos( $page_content['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
425
+ $current_values = MLACore::mla_get_option( 'iptc_exif_mapping' );
426
+ $settings = array( 'custom' => array( $value['name'] => $current_values['custom'][$value['name']] ) );
427
+ $map_content = self::_process_iptc_exif_custom( $settings );
428
+ $page_content['message'] .= '<br>&nbsp;<br>' . $map_content['message'];
429
+ }
430
+ break;
431
+ default:
432
+ // ignore everything else
433
+ } //switch action
434
+ } // foreach action
435
+ } /// isset action
436
+ } // foreach rule
437
+ }
438
+
439
+ if ( !empty( $page_content['body'] ) ) {
440
+ return $page_content;
441
+ }
442
+ }
443
+
444
+ $page_template_array = MLACore::mla_load_template( 'admin-display-settings-iptc-exif-tab.tpl' );
445
+ if ( ! is_array( $page_template_array ) ) {
446
+ /* translators: 1: ERROR tag 2: function name 3: non-array value */
447
+ $page_content['message'] = sprintf( _x( '%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'MLASettings_IPTCEXIF::mla_compose_iptc_exif_tab', var_export( $page_template_array, true ) );
448
+ return $page_content;
449
+ }
450
+
451
+ $page_values = array(
452
+ 'Mapping Progress' => __( 'IPTC &amp; EXIF Mapping Progress', 'media-library-assistant' ),
453
+ 'DO NOT' => __( 'DO NOT DO THE FOLLOWING (they will cause mapping to fail)', 'media-library-assistant' ),
454
+ 'DO NOT Close' => __( 'Close the window', 'media-library-assistant' ),
455
+ 'DO NOT Reload' => __( 'Reload the page', 'media-library-assistant' ),
456
+ 'DO NOT Click' => __( 'Click the browser&rsquo;s Stop, Back or forward buttons', 'media-library-assistant' ),
457
+ 'Progress' => __( 'Progress', 'media-library-assistant' ),
458
+ 'Pause' => __( 'Pause', 'media-library-assistant' ),
459
+ 'Cancel' => __( 'Cancel', 'media-library-assistant' ),
460
+ 'Resume' => __( 'Resume', 'media-library-assistant' ),
461
+ 'Close' => __( 'Close', 'media-library-assistant' ),
462
+ 'Refresh' => __( 'Refresh', 'media-library-assistant' ),
463
+ 'refresh_href' => '?page=mla-settings-menu-iptc_exif&mla_tab=iptc_exif',
464
+ );
465
+
466
+ $progress_div = MLAData::mla_parse_template( $page_template_array['mla-progress-div'], $page_values );
467
+
468
+ $page_values = array(
469
+ 'mla-progress-div' => $progress_div,
470
+ 'IPTX/EXIF Options' => __( 'IPTC &amp; EXIF Processing Options', 'media-library-assistant' ),
471
+ 'In this tab' => __( 'In this tab you can define the rules for mapping IPTC (International Press Telecommunications Council) and EXIF (EXchangeable Image File) metadata to WordPress standard attachment fields, taxonomy terms and custom fields. <strong>NOTE:</strong> settings changes will not be made permanent until you click "Save Changes" at the bottom of this page.', 'media-library-assistant' ),
472
+ /* translators: 1: Documentation hyperlink */
473
+ 'You can find' => sprintf( __( 'You can find more information about using the controls in this tab to define mapping rules and apply them in the %1$s section of the Documentation.', 'media-library-assistant' ), '<a href="[+settingsURL+]?page=mla-settings-menu-documentation&amp;mla_tab=documentation#mla_iptc_exif_mapping" title="' . __( 'IPTC/EXIF Options documentation', 'media-library-assistant' ) . '">' . __( 'IPTC &amp; EXIF Processing Options', 'media-library-assistant' ) . '</a>' ),
474
+ 'settingsURL' => admin_url('options-general.php'),
475
+ 'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-iptc_exif&mla_tab=iptc_exif',
476
+ 'options_list' => '',
477
+ 'Standard field mapping' => __( 'Standard field mapping', 'media-library-assistant' ),
478
+ 'Map Standard Fields' => __( 'Map All Attachments, Standard Fields Now', 'media-library-assistant' ),
479
+ 'standard_options_list' => '',
480
+ 'Taxonomy term mapping' => __( 'Taxonomy term mapping', 'media-library-assistant' ),
481
+ 'Map Taxonomy Terms' => __( 'Map All Attachments, Taxonomy Terms Now', 'media-library-assistant' ),
482
+ 'taxonomy_options_list' => '',
483
+ 'Custom field mapping' => __( 'Custom field mapping', 'media-library-assistant' ),
484
+ 'Map Custom Fields' => __( 'Map All Attachments, Custom Fields Now', 'media-library-assistant' ),
485
+ 'custom_options_list' => '',
486
+ 'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
487
+ /* translators: 1: "Save Changes" */
488
+ 'Click Save Changes' => sprintf( __( 'Click %1$s to update the "Enable IPTC/EXIF mapping..." checkbox and/or all rule changes and additions at once. <strong>No rule mapping will be performed.</strong>', 'media-library-assistant' ), '<strong>' . __( 'Save Changes', 'media-library-assistant' ) . '</strong>' ),
489
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
490
+ '_wp_http_referer' => wp_referer_field( false )
491
+ );
492
+
493
+ /*
494
+ * Start with any page-level options
495
+ */
496
+ $options_list = '';
497
+ foreach ( MLACoreOptions::$mla_option_definitions as $key => $value ) {
498
+ if ( 'iptc_exif' == $value['tab'] ) {
499
+ $options_list .= MLASettings::mla_compose_option_row( $key, $value );
500
+ }
501
+ }
502
+
503
+ $page_values['options_list'] = $options_list;
504
+
505
+ /*
506
+ * Add mapping options
507
+ */
508
+ $page_values['standard_options_list'] = MLAOptions::mla_iptc_exif_option_handler( 'render', 'iptc_exif_standard_mapping', MLACoreOptions::$mla_option_definitions['iptc_exif_standard_mapping'] );
509
+
510
+ $page_values['taxonomy_options_list'] = MLAOptions::mla_iptc_exif_option_handler( 'render', 'iptc_exif_taxonomy_mapping', MLACoreOptions::$mla_option_definitions['iptc_exif_taxonomy_mapping'] );
511
+
512
+ $page_values['custom_options_list'] = MLAOptions::mla_iptc_exif_option_handler( 'render', 'iptc_exif_custom_mapping', MLACoreOptions::$mla_option_definitions['iptc_exif_custom_mapping'] );
513
+
514
+ $page_content['body'] = MLAData::mla_parse_template( $page_template_array['iptc-exif-tab'], $page_values );
515
+ return $page_content;
516
+ } // mla_compose_iptc_exif_tab
517
+
518
+ /**
519
+ * Ajax handler for IPTC/EXIF tab inline mapping
520
+ *
521
+ * @since 2.00
522
+ *
523
+ * @return void echo json response object, then die()
524
+ */
525
+ public static function mla_inline_mapping_iptc_exif_action() {
526
+ MLACore::mla_debug_add( 'MLASettings::mla_inline_mapping_iptc_exif_action $_REQUEST = ' . var_export( $_REQUEST, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
527
+ set_current_screen( $_REQUEST['screen'] );
528
+ check_ajax_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
529
+
530
+ /*
531
+ * Convert the ajax bulk_action back to the older Submit button equivalent
532
+ */
533
+ if ( ! empty( $_REQUEST['bulk_action'] ) ) {
534
+ switch ( $_REQUEST['bulk_action'] ) {
535
+ case 'iptc-exif-options-process-standard':
536
+ $_REQUEST['iptc-exif-options-process-standard'] = __( 'Map All Attachments, Standard Fields Now', 'media-library-assistant' );
537
+ break;
538
+ case 'iptc-exif-options-process-taxonomy':
539
+ $_REQUEST['iptc-exif-options-process-taxonomy'] = __( 'Map All Attachments, Taxonomy Terms Now', 'media-library-assistant' );
540
+ break;
541
+ case 'iptc-exif-options-process-custom':
542
+ $_REQUEST['iptc-exif-options-process-custom'] = __( 'Map All Attachments, Custom Fields Now', 'media-library-assistant' );
543
+ break;
544
+ default:
545
+ $match_count = preg_match( '/iptc_exif_mapping\[custom\]\[(.*)\]\[(.*)\]\[(.*)\]/', $_REQUEST['bulk_action'], $matches );
546
+ if ( $match_count ) {
547
+ $_REQUEST['iptc_exif_mapping']['custom'][ $matches[1] ][ $matches[2] ][ $matches[3] ] = __( 'Map All Attachments', 'media-library-assistant' );
548
+ }
549
+ }
550
+ }
551
+
552
+ /*
553
+ * Check for action or submit buttons.
554
+ */
555
+ if ( isset( $_REQUEST['iptc_exif_mapping'] ) && is_array( $_REQUEST['iptc_exif_mapping'] ) ) {
556
+ /*
557
+ * Find the current chunk
558
+ */
559
+ $offset = isset( $_REQUEST['offset'] ) ? $_REQUEST['offset'] : 0;
560
+ $length = isset( $_REQUEST['length'] ) ? $_REQUEST['length'] : 0;
561
+
562
+ /*
563
+ * Check for page-level submit button to map attachments.
564
+ */
565
+ if ( !empty( $_REQUEST['iptc-exif-options-process-standard'] ) ) {
566
+ $page_content = self::_process_iptc_exif_standard( $offset, $length );
567
+ } elseif ( !empty( $_REQUEST['iptc-exif-options-process-taxonomy'] ) ) {
568
+ $page_content = self::_process_iptc_exif_taxonomy( $offset, $length );
569
+ } elseif ( !empty( $_REQUEST['iptc-exif-options-process-custom'] ) ) {
570
+ $page_content = self::_process_iptc_exif_custom( NULL, $offset, $length );
571
+ } else {
572
+ $page_content = array(
573
+ 'message' => '',
574
+ 'body' => '',
575
+ 'processed' => 0,
576
+ 'unchanged' => 0,
577
+ 'success' => 0
578
+ );
579
+
580
+ /*
581
+ * Check for single-rule action buttons
582
+ */
583
+ foreach ( $_REQUEST['iptc_exif_mapping']['custom'] as $key => $value ) {
584
+ $value = stripslashes_deep( $value );
585
+
586
+ if ( isset( $value['action'] ) ) {
587
+ $settings = array( 'custom' => array( $key => $value ) );
588
+ foreach ( $value['action'] as $action => $label ) {
589
+ switch( $action ) {
590
+ case 'map_now':
591
+ $page_content = self::_process_iptc_exif_custom( $settings, $offset, $length );
592
+ break;
593
+ case 'add_rule_map':
594
+ if ( 'none' == $value['name'] ) {
595
+ $page_content['message'] = __( 'IPTC/EXIF no mapping changes detected.', 'media-library-assistant' );
596
+ break;
597
+ }
598
+ // fallthru
599
+ case 'add_field_map':
600
+ if ( '' == $value['name'] ) {
601
+ $page_content['message'] = __( 'IPTC/EXIF no mapping changes detected.', 'media-library-assistant' );
602
+ break;
603
+ }
604
+
605
+ if ( 0 == $offset ) {
606
+ $page_content = self::_save_iptc_exif_custom_settings( $settings );
607
+ if ( false !== strpos( $page_content['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
608
+ $page_content['processed'] = 0;
609
+ $page_content['unchanged'] = 0;
610
+ $page_content['success'] = 0;
611
+ break;
612
+ }
613
+ }
614
+
615
+ $current_values = MLACore::mla_get_option( 'iptc_exif_mapping' );
616
+ $settings = array( 'custom' => array( $value['name'] => $current_values['custom'][$value['name']] ) );
617
+ $map_content = self::_process_iptc_exif_custom( $settings, $offset, $length );
618
+ $page_content['message'] .= '<br>&nbsp;<br>' . $map_content['message'];
619
+ $page_content['processed'] = $map_content['processed'];
620
+ $page_content['unchanged'] = $map_content['unchanged'];
621
+ $page_content['success'] = $map_content['success'];
622
+ $page_content['refresh'] = true;
623
+ break;
624
+ default:
625
+ // ignore everything else
626
+ } //switch action
627
+ } // foreach action
628
+ } /// isset action
629
+ } // foreach rule
630
+ }
631
+ } // isset custom_field_mapping
632
+ else {
633
+ $page_content = array(
634
+ 'message' => '',
635
+ 'body' => '',
636
+ 'processed' => 0,
637
+ 'unchanged' => 0,
638
+ 'success' => 0
639
+ );
640
+ }
641
+
642
+ $chunk_results = array(
643
+ 'message' => $page_content['message'],
644
+ 'processed' => $page_content['processed'],
645
+ 'unchanged' => $page_content['unchanged'],
646
+ 'success' => $page_content['success'],
647
+ 'refresh' => isset( $page_content['refresh'] ) && true == $page_content['refresh'],
648
+ );
649
+
650
+ MLACore::mla_debug_add( 'MLASettings::mla_inline_mapping_iptc_exif_action $chunk_results = ' . var_export( $chunk_results, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
651
+ wp_send_json_success( $chunk_results );
652
+ } // mla_inline_mapping_iptc_exif_action
653
+ } // class MLASettings_IPTCEXIF
654
+
655
+ /*
656
+ * Actions are added here, when the source file is loaded, because the MLA_Example_List_Table
657
+ * object is created too late to be useful.
658
+ */
659
+ add_action( 'admin_enqueue_scripts', 'MLASettings_IPTCEXIF::mla_admin_enqueue_scripts' );
660
+ ?>
includes/class-mla-settings-shortcodes-tab.php ADDED
@@ -0,0 +1,2074 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Manages the Settings/Media Library Assistant Shortcodes tab
4
+ *
5
+ * @package Media Library Assistant
6
+ * @since 2.40
7
+ */
8
+
9
+ /**
10
+ * Class MLA (Media Library Assistant) Settings Shortcodes implements the
11
+ * Settings/Media Library Assistant Shortcodes tab
12
+ *
13
+ * @package Media Library Assistant
14
+ * @since 2.40
15
+ */
16
+ class MLASettings_Shortcodes {
17
+ /**
18
+ * Slug for localizing and enqueueing JavaScript
19
+ *
20
+ * @since 2.40
21
+ * @var string
22
+ */
23
+ const JAVASCRIPT_SHORTCODES_TAB_SLUG = 'mla-shortcodes-tab-scripts';
24
+
25
+ /**
26
+ * Object name for localizing JavaScript
27
+ *
28
+ * @since 2.40
29
+ * @var string
30
+ */
31
+ const JAVASCRIPT_SHORTCODES_TAB_OBJECT = 'mla_shortcodes_tab_vars';
32
+
33
+ /**
34
+ * Load the tab's Javascript files
35
+ *
36
+ * @since 2.40
37
+ *
38
+ * @param string $page_hook Name of the page being loaded
39
+ */
40
+ public static function mla_admin_enqueue_scripts( $page_hook ) {
41
+ global $wpdb, $wp_locale;
42
+
43
+ // Without a tab value that matches ours, there's nothing to do
44
+ if ( empty( $_REQUEST['mla_tab'] ) || 'shortcodes' !== $_REQUEST['mla_tab'] ) {
45
+ return;
46
+ }
47
+
48
+ // Initialize script variables
49
+ $script_variables = array(
50
+ 'definitions' => MLATemplate_Support::$mla_template_definitions,
51
+ );
52
+
53
+ $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
54
+
55
+ wp_enqueue_script( self::JAVASCRIPT_SHORTCODES_TAB_SLUG,
56
+ MLA_PLUGIN_URL . "js/mla-settings-shortcodes-tab-scripts{$suffix}.js",
57
+ array( 'jquery' ), MLACore::CURRENT_MLA_VERSION, false );
58
+
59
+ wp_localize_script( self::JAVASCRIPT_SHORTCODES_TAB_SLUG,
60
+ self::JAVASCRIPT_SHORTCODES_TAB_OBJECT, $script_variables );
61
+ }
62
+
63
+ /**
64
+ * Process a shortcode template add action.
65
+ *
66
+ * @since 2.40
67
+ *
68
+ * @param array $value New template values.
69
+ * @return string Action status/error messages.
70
+ */
71
+ public static function mla_add_template( $value ) {
72
+ $value = stripslashes_deep( $value );
73
+ $value['default'] = false;
74
+ $value['changed'] = true;
75
+ $value['deleted'] = false;
76
+
77
+ if ( 'any' === $value['type'] || 'any' === $value['shortcode'] ) {
78
+ /* translators: 1: ERROR tag 2: template type */
79
+ return sprintf( __( '%1$s: %2$s type or shortcode not specified.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'Template', 'media-library-assistant' ) );
80
+ }
81
+
82
+ $message_list = '';
83
+ $new_name = sanitize_title( $value['name'] );
84
+ $default_name = 'add-template-default-name';
85
+ $label = ( 'style' == $value['type'] ) ? __( 'style template', 'media-library-assistant' ) : __( 'markup template', 'media-library-assistant' );
86
+
87
+ // Handle name validation, check for duplicates
88
+ if ( '' == $new_name ) {
89
+ /* translators: 1: ERROR tag 2: template type 3: old template name */
90
+ $message_list = sprintf( __( '%1$s: Blank %2$s name, reverting to "%3$s".', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $label, $default_name );
91
+ $new_name = $default_name;
92
+ } elseif ( 'blank' == $new_name ) {
93
+ /* translators: 1: ERROR tag 2: template type 3: new template name 4: old template name */
94
+ $message_list = sprintf( __( '%1$s: Reserved %2$s name "%3$s", reverting to "%4$s".', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $label, $new_name, $default_name );
95
+ $new_name = $default_name;
96
+ }
97
+
98
+ if ( MLA_Template_Query::mla_find_shortcode_template_ID( $value['type'], $new_name ) ) {
99
+ // Generate a unique name
100
+ $index = 1;
101
+ while( MLA_Template_Query::mla_find_shortcode_template_ID( $value['type'], $new_name . '-' . $index ) ) {
102
+ $index++;
103
+ }
104
+
105
+ $default_name = $new_name . '-' . $index;
106
+
107
+ if ( strlen( $message_list ) ) {
108
+ $message_list .= '<br>';
109
+ }
110
+
111
+ /* translators: 1: ERROR tag 2: template type 3: new template name 4: old template name */
112
+ $message_list .= sprintf( __( '%1$s: Duplicate new %2$s name "%3$s", reverting to "%4$s".', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $label, $new_name, $default_name );
113
+ $new_name = $default_name;
114
+ } // duplicate name
115
+
116
+ $value['name'] = $new_name;
117
+
118
+ // Find section content
119
+ $sections = array();
120
+ $prefix = $value['type'] . '-' . $value['shortcode'] . '-';
121
+ $allowed_sections = MLATemplate_Support::$mla_template_definitions[ $value['type'] ][ $value['shortcode'] ]['sections'];
122
+ foreach( $value['sections'] as $section_slug => $text ) {
123
+ if ( empty( $text ) || ( false === strpos( $section_slug, $prefix ) ) ) {
124
+ continue;
125
+ }
126
+
127
+ $key = substr( $section_slug, strlen( $prefix ) );
128
+ if ( array_key_exists( $key, $allowed_sections ) ) {
129
+ $sections[ $key ] = $text;
130
+ }
131
+ }
132
+ //error_log( __LINE__ . " mla_add_template sections = " . var_export( $sections, true ), 0 );
133
+
134
+ if ( strlen( $message_list ) ) {
135
+ $message_list .= '<br>';
136
+ }
137
+
138
+ if ( empty( $sections ) ) {
139
+ /* translators: 1: ERROR tag 2: template type 3: new template name */
140
+ $message_list .= sprintf( __( '%1$s: New %2$s "%3$s" has no content; not added.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $label, $new_name );
141
+ } else {
142
+ $value['sections'] = $sections;
143
+ MLA_Template_Query::mla_add_shortcode_template( $value );
144
+ /* translators: 1: field type, 2: new template name */
145
+ $message_list .= sprintf( __( '%1$s "%2$s" added.', 'media-library-assistant' ), __( 'Template', 'media-library-assistant' ), $new_name );
146
+ }
147
+
148
+ return $message_list;
149
+ }
150
+
151
+ /**
152
+ * Process a shortcode template copy action.
153
+ *
154
+ * @since 2.40
155
+ *
156
+ * @param integer $ID Template ID.
157
+ * @return array New template values, action status/error messages.
158
+ */
159
+ public static function mla_copy_template( $ID ) {
160
+ $value = MLA_Template_Query::mla_find_shortcode_template( $ID );
161
+ //error_log( __LINE__ . " mla_copy_template( {$ID} ) value = " . var_export( $value, true ), 0 );
162
+ $old_name = $value['name'];
163
+ $new_name = $old_name . '-copy';
164
+
165
+ if ( MLA_Template_Query::mla_find_shortcode_template_ID( $value['type'], $new_name ) ) {
166
+ $index = 1;
167
+ while( MLA_Template_Query::mla_find_shortcode_template_ID( $value['type'], $new_name . '-' . $index ) ) {
168
+ $index++;
169
+ }
170
+
171
+ $new_name = $new_name . '-' . $index;
172
+ }
173
+
174
+ $value['name'] = $new_name;
175
+ MLA_Template_Query::mla_add_shortcode_template( $value );
176
+
177
+ /* translators: 1: field type, 2: old template name, 3: new template name */
178
+ $value['message'] = sprintf( __( '%1$s "%2$s" copied to "%3$s".', 'media-library-assistant' ), __( 'Template', 'media-library-assistant' ), $old_name, $new_name );
179
+ return $value;
180
+ }
181
+
182
+ /**
183
+ * Process a shortcode template update action.
184
+ *
185
+ * @since 2.40
186
+ *
187
+ * @param array $value New template values.
188
+ * @return string Action status/error messages.
189
+ */
190
+ public static function mla_update_template( $value ) {
191
+ $ID = $value['post_ID'];
192
+ $value = stripslashes_deep( $value );
193
+ //error_log( __LINE__ . " mla_update_template( {$ID} ) value = " . var_export( $value, true ), 0 );
194
+ $old_value = MLA_Template_Query::mla_find_shortcode_template( $ID );
195
+ //error_log( __LINE__ . " mla_update_template( {$ID} ) old_value = " . var_export( $old_value, true ), 0 );
196
+ $template_changed = false;
197
+ $message_list = '';
198
+ $error_list = '';
199
+
200
+ $old_name = $old_value['name'];
201
+ $new_name = sanitize_title( $value['name'] );
202
+ $label = ( 'style' == $value['type'] ) ? __( 'style template name', 'media-library-assistant' ) : __( 'markup template name', 'media-library-assistant' );
203
+
204
+ // Handle name changes, check for duplicates
205
+ if ( '' == $new_name ) {
206
+ /* translators: 1: ERROR tag 2: template type 3: old template name */
207
+ $error_list .= '<br>' . sprintf( __( '%1$s: Blank %2$s, reverting to "%3$s".', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $label, $old_name );
208
+ $new_name = $old_name;
209
+ }
210
+
211
+ if ( $new_name != $old_name ) {
212
+ if ( MLA_Template_Query::mla_find_shortcode_template_ID( $value['type'], $new_name ) ) {
213
+ /* translators: 1: ERROR tag 2: template type 3: new template name 4: old template name */
214
+ $error_list .= '<br>' . sprintf( __( '%1$s: Duplicate new %2$s "%3$s", reverting to "%4$s".', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $label, $new_name, $old_name );
215
+ $new_name = $old_name;
216
+ } elseif ( 'blank' == $new_name ) {
217
+ /* translators: 1: ERROR tag 2: template type 3: new template name 4: old template name */
218
+ $error_list .= '<br>' . sprintf( __( '%1$s: Reserved %2$s "%3$s", reverting to "%4$s".', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $label, $new_name, $old_name );
219
+ $new_name = $old_name;
220
+ } else {
221
+ /* translators: 1: template type 2: old template name 3: new template name */
222
+ $message_list .= '<br>' . sprintf( _x( 'Changing %1$s from "%2$s" to "%3$s"', 'message_list', 'media-library-assistant' ), $label, $old_name, $new_name );
223
+ $template_changed = true;
224
+ }
225
+ } // name changed
226
+
227
+ // Handle section content changes
228
+ foreach( MLATemplate_Support::$mla_template_definitions[ $value['type'] ][ $value['shortcode'] ]['sections'] as $section_name => $definition ) {
229
+ $old_section = isset( $old_value['sections'][ $section_name ] ) ? $old_value['sections'][ $section_name ] : '';
230
+ if ( $value['sections'][ $section_name ] !== $old_section ) {
231
+ $template_changed = true;
232
+ }
233
+
234
+ if ( empty( $value['sections'][ $section_name ] ) ) {
235
+ unset( $value['sections'][ $section_name ] );
236
+ }
237
+ }
238
+
239
+ if ( $template_changed ) {
240
+ $value['default'] = false;
241
+ $value['changed'] = true;
242
+ $value['deleted'] = false;
243
+ MLA_Template_Query::mla_replace_shortcode_template( $value );
244
+ /* translators: 1: field type, 2: new template name */
245
+ $message_list .= sprintf( __( '%1$s "%2$s" updated.', 'media-library-assistant' ), __( 'Template', 'media-library-assistant' ), $new_name ) . "\r\n";
246
+ } else {
247
+ /* translators: 1: field type, 2: template name */
248
+ $message_list .= sprintf( __( '%1$s "%2$s" no changes detected.', 'media-library-assistant' ), __( 'Template', 'media-library-assistant' ), $new_name ) . "\r\n";
249
+ }
250
+
251
+ return $message_list . $error_list;
252
+ }
253
+
254
+ /**
255
+ * Process a shortcode template delete action.
256
+ *
257
+ * @since 2.40
258
+ *
259
+ * @param integer $ID Template ID.
260
+ * @return string Action status/error messages.
261
+ */
262
+ public static function mla_delete_template( $ID ) {
263
+ $value = MLA_Template_Query::mla_find_shortcode_template( $ID );
264
+ //error_log( __LINE__ . " mla_update_template( {$ID} ) value = " . var_export( $value, true ), 0 );
265
+ $value['deleted'] = true;
266
+ MLA_Template_Query::mla_replace_shortcode_template( $value );
267
+ /* translators: 1: field type */
268
+ return sprintf( __( '%1$s "%2$s" deleted.', 'media-library-assistant' ), __( 'Template', 'media-library-assistant' ), $value['name'] ) . "\r\n";
269
+ }
270
+
271
+ /**
272
+ * Save Shortcodes settings to the options table
273
+ *
274
+ * @since 2.40
275
+ *
276
+ * @uses $_REQUEST
277
+ *
278
+ * @return array Message(s) reflecting the results of the operation
279
+ */
280
+ private static function _save_shortcodes_settings( ) {
281
+ $settings_changed = false;
282
+ $message_list = '';
283
+ $error_list = '';
284
+
285
+ // Start with any page-level options
286
+ foreach ( MLACoreOptions::$mla_option_definitions as $key => $value ) {
287
+ if ( 'mla_gallery' == $value['tab'] ) {
288
+ $this_setting_changed = false;
289
+ $old_value = MLACore::mla_get_option( $key );
290
+
291
+ if ( 'select' == $value['type'] ) {
292
+ if ( $old_value != $_REQUEST[ MLA_OPTION_PREFIX . $key ] ) {
293
+ $this_setting_changed = true;
294
+ }
295
+ } elseif ( 'text' == $value['type'] ) {
296
+ if ( '' == $_REQUEST[ MLA_OPTION_PREFIX . $key ] ) {
297
+ $_REQUEST[ MLA_OPTION_PREFIX . $key ] = $value['std'];
298
+ }
299
+
300
+ if ( $old_value != $_REQUEST[ MLA_OPTION_PREFIX . $key ] ) {
301
+ $this_setting_changed = true;
302
+ }
303
+ } elseif ( 'checkbox' == $value['type'] ) {
304
+ if ( isset( $_REQUEST[ MLA_OPTION_PREFIX . $key ] ) ) {
305
+ $this_setting_changed = "checked" != $old_value;
306
+ } else {
307
+ $this_setting_changed = "checked" == $old_value;
308
+ }
309
+ }
310
+
311
+ /*
312
+ * Always update to scrub default settings
313
+ */
314
+ $message = MLASettings::mla_update_option_row( $key, $value );
315
+ if ( $this_setting_changed ) {
316
+ $settings_changed = true;
317
+ $message_list .= $message;
318
+ }
319
+ } // mla_gallery option
320
+ } // foreach mla_options
321
+
322
+ if ( $settings_changed ) {
323
+ /* translators: 1: field type */
324
+ $message = sprintf( __( '%1$s settings saved.', 'media-library-assistant' ), __( 'Shortcodes', 'media-library-assistant' ) ) . "\r\n";
325
+ } else {
326
+ /* translators: 1: field type */
327
+ $message = sprintf( __( '%1$s no changes detected.', 'media-library-assistant' ), __( 'Shortcodes', 'media-library-assistant' ) ) . "\r\n";
328
+ }
329
+
330
+ $page_content = array(
331
+ 'message' => $message . $error_list,
332
+ 'body' => ''
333
+ );
334
+
335
+ /*
336
+ * Uncomment this for debugging.
337
+ */
338
+ // $page_content['message'] .= $message_list;
339
+
340
+ return $page_content;
341
+ } // _save_shortcodes_settings
342
+
343
+ /**
344
+ * Compose the Add Template tab content for the Settings/Shortcodes subpage
345
+ *
346
+ * @since 2.40
347
+ *
348
+ * @param array &$template Display templates.
349
+ * @return array 'message' => status/error messages, 'body' => tab content
350
+ */
351
+ private static function _compose_add_template_tab( &$template ) {
352
+ // Compose the dropdown controls
353
+ $shortcode_options = '';
354
+ foreach( MLATemplate_Support::$mla_template_definitions['style'] as $shortcode => $definition ) {
355
+ $shortcode_options .= "\t\t\t<option value=\"" . $shortcode . '">' . $definition['label'] . "</option>\r\n";
356
+ }
357
+
358
+ $page_values = array (
359
+ 'Select a type' => '&mdash; ' . __( 'select template type', 'media-library-assistant' ) . ' &mdash;',
360
+ 'Select a shortcode' => '&mdash; ' .__( 'select template shortcode', 'media-library-assistant' ) . ' &mdash;',
361
+ 'shortcode_options' => $shortcode_options,
362
+ 'controls_help' => __( 'Select a template type and shortcode to generate the section areas.', 'media-library-assistant' ),
363
+ );
364
+
365
+ $controls = MLAData::mla_parse_template( $template['single-item-controls'], $page_values );
366
+
367
+ // Compose the template sections
368
+ $sections = array();
369
+ foreach( MLATemplate_Support::$mla_template_definitions as $type => $type_definitions ) {
370
+ foreach( $type_definitions as $shortcode => $shortcode_definition ) {
371
+ foreach( $shortcode_definition['sections'] as $section_name => $definition ) {
372
+ $definition['type'] = $type;
373
+ $definition['shortcode'] = $shortcode;
374
+ $definition['slug'] = $section_name;
375
+ $sections[ $type . $shortcode . $definition['order'] ] = $definition;
376
+ }
377
+ }
378
+ }
379
+ ksort( $sections, SORT_REGULAR );
380
+ //error_log( __LINE__ . " _compose_add_template_tab sections = " . var_export( $sections, true ), 0 );
381
+
382
+ $section_list = '';
383
+ foreach ( $sections as $section ) {
384
+ $page_values = array (
385
+ 'class' => 'mla_section mla_' . $section['type'] . ' mla_' . $section['shortcode'],
386
+ 'style' => ' style="display: none"',
387
+ 'section_slug' => $section['type'] . '-' . $section['shortcode'] . '-' . $section['slug'],
388
+ 'section_name' => $section['label'],
389
+ 'section_rows' => $section['rows'],
390
+ 'readonly' => '',
391
+ 'section_value' => '',
392
+ 'section_help' => $section['help'],
393
+ );
394
+
395
+ $section_list .= MLAData::mla_parse_template( $template['single-item-section'], $page_values );
396
+ }
397
+
398
+ $page_values = array(
399
+ 'Edit Template' => __( 'Add Template', 'media-library-assistant' ),
400
+ 'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-shortcodes&mla_tab=shortcodes',
401
+ 'ID' => 0,
402
+ 'type' => 'any',
403
+ 'shortcode' => 'any',
404
+ 'name' => '',
405
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
406
+ 'controls' => $controls,
407
+ 'Name' => __( 'Name', 'media-library-assistant' ),
408
+ 'The name is' => __( 'The name/&#8220;slug&#8221; is the URL-friendly, unique key for the template. It must be all lowercase and contain only letters, numbers and hyphens (-).', 'media-library-assistant' ),
409
+ 'section_list' => $section_list,
410
+ 'cancel' => 'mla-add-template-cancel',
411
+ 'Cancel' => __( 'Cancel', 'media-library-assistant' ),
412
+ 'submit' =>'mla-add-template-submit',
413
+ 'Update' => __( 'Add Template', 'media-library-assistant' ),
414
+ );
415
+
416
+ return array(
417
+ 'message' => '',
418
+ 'body' => MLAData::mla_parse_template( $template['single-item-edit'], $page_values )
419
+ );
420
+ }
421
+
422
+ /**
423
+ * Compose the Edit Template tab content for the Settings/Shortcodes subpage
424
+ *
425
+ * @since 2.40
426
+ *
427
+ * @param array $item Data values for the item.
428
+ * @param array &$template Display templates.
429
+ *
430
+ * @return array 'message' => status/error messages, 'body' => tab content
431
+ */
432
+ private static function _compose_edit_template_tab( $item, &$template ) {
433
+ //error_log( __LINE__ . " _compose_edit_template_tab item = " . var_export( $item, true ), 0 );
434
+ //error_log( __LINE__ . " _compose_edit_template_tab template = " . var_export( $template, true ), 0 );
435
+ $sections = array();
436
+ foreach( MLATemplate_Support::$mla_template_definitions[ $item['type'] ][ $item['shortcode'] ]['sections'] as $section_name => $definition ) {
437
+ $definition['slug'] = $section_name;
438
+ $definition['value'] = isset( $item['sections'][ $section_name ] ) ? $item['sections'][ $section_name ] : '';
439
+ $sections[ $definition['order'] ] = $definition;
440
+ }
441
+ ksort( $sections, SORT_NUMERIC );
442
+
443
+ $section_list = '';
444
+ foreach ( $sections as $section ) {
445
+ $page_values = array (
446
+ 'class' => 'mla_section mla_' . $item['type'] . ' mla_' . $item['shortcode'],
447
+ 'style' => '',
448
+ 'section_slug' => $section['slug'],
449
+ 'section_name' => $section['label'],
450
+ 'section_rows' => $section['rows'],
451
+ 'readonly' => $item['default'] ? 'readonly="readonly"' : '',
452
+ 'section_value' => $section['value'],
453
+ 'section_help' => $section['help'],
454
+ );
455
+
456
+ $section_list .= MLAData::mla_parse_template( $template['single-item-section'], $page_values );
457
+ }
458
+
459
+ // Compose copy_href, for default templates
460
+ $view_args = array(
461
+ 'page' => MLACoreOptions::MLA_SETTINGS_SLUG . '-shortcodes',
462
+ 'mla_tab' => 'shortcodes',
463
+ 'mla_item_ID' => $item['post_ID']
464
+ );
465
+ $copy_href = add_query_arg( $view_args, wp_nonce_url( '?mla_admin_action=' . MLACore::MLA_ADMIN_SINGLE_COPY, MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ) );
466
+
467
+ $page_values = array(
468
+ 'Edit Template' => $item['default'] ? __( 'View Template', 'media-library-assistant' ) : __( 'Edit Template', 'media-library-assistant' ),
469
+ 'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-shortcodes&mla_tab=shortcodes',
470
+ 'ID' => $item['post_ID'],
471
+ 'type' => $item['type'],
472
+ 'shortcode' => $item['shortcode'],
473
+ 'name' => $item['name'],
474
+ 'readonly' => $item['default'] ? 'readonly="readonly"' : '',
475
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
476
+ 'controls' => '', //MLAData::mla_parse_template( $template['single-item-controls'], array() ),
477
+ 'Name' => __( 'Name', 'media-library-assistant' ),
478
+ 'The name is' => __( 'The name/&#8220;slug&#8221; is the URL-friendly, unique key for the template. It must be all lowercase and contain only letters, numbers and hyphens (-).', 'media-library-assistant' ),
479
+ 'section_list' => $section_list,
480
+ 'cancel' => $item['default'] ? 'mla-edit-template-close' : 'mla-edit-template-cancel',
481
+ 'Cancel' => $item['default'] ? __( 'Close', 'media-library-assistant' ) : __( 'Cancel', 'media-library-assistant' ),
482
+ 'submit' => 'mla-edit-template-submit',
483
+ 'submit_style' => $item['default'] ? 'style="display: none"' : '',
484
+ 'Update' => __( 'Update', 'media-library-assistant' ),
485
+ 'copy_style' => $item['default'] ? '' : 'style="display: none"',
486
+ 'copy_href' => $copy_href,
487
+ 'Copy' => __( 'Copy', 'media-library-assistant' ),
488
+ );
489
+
490
+ return array(
491
+ 'message' => '',
492
+ 'body' => MLAData::mla_parse_template( $template['single-item-edit'], $page_values )
493
+ );
494
+ }
495
+
496
+ /**
497
+ * Compose the Shortcodes tab content for the Settings subpage
498
+ *
499
+ * @since 2.40
500
+ *
501
+ * @return array 'message' => status/error messages, 'body' => tab content
502
+ */
503
+ public static function mla_compose_shortcodes_tab( ) {
504
+ $page_content = array( 'message' => '', 'body' => '' );
505
+ $page_template_array = MLACore::mla_load_template( 'admin-display-settings-shortcodes-tab.tpl' );
506
+ if ( ! is_array( $page_template_array ) ) {
507
+ /* translators: 1: ERROR tag 2: function name 3: non-array value */
508
+ $page_content['message'] = sprintf( _x( '%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'MLASettings_Shortcodes::mla_compose_shortcodes_tab', var_export( $page_template_array, true ) );
509
+ return $page_content;
510
+ }
511
+
512
+ // Initialize page messages and content, check for Save Changes, Add/Update/Cancel Template
513
+ if ( !empty( $_REQUEST['mla-shortcodes-options-save'] ) ) {
514
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
515
+ $page_content = self::_save_shortcodes_settings( );
516
+ } elseif ( !empty( $_REQUEST['mla-add-new-template-submit'] ) ) {
517
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
518
+ $page_content = self::_compose_add_template_tab( $page_template_array );
519
+ } elseif ( !empty( $_REQUEST['mla-add-template-submit'] ) ) {
520
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
521
+ $page_content['message'] = MLASettings_Shortcodes::mla_add_template( $_REQUEST['mla_template_item'] );
522
+ MLA_Template_Query::mla_put_shortcode_template_items();
523
+ } elseif ( !empty( $_REQUEST['mla-edit-template-submit'] ) ) {
524
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
525
+ $page_content['message'] = MLASettings_Shortcodes::mla_update_template( $_REQUEST['mla_template_item'] );
526
+ MLA_Template_Query::mla_put_shortcode_template_items();
527
+ } elseif ( !empty( $_REQUEST['mla-add-template-cancel'] ) ) {
528
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
529
+ $page_content['message'] = __( 'Add Template cancelled.', 'media-library-assistant' );
530
+ } elseif ( !empty( $_REQUEST['mla-edit-template-cancel'] ) ) {
531
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
532
+ $page_content['message'] = __( 'Edit Template cancelled.', 'media-library-assistant' );
533
+ }
534
+
535
+ if ( !empty( $page_content['body'] ) ) {
536
+ return $page_content;
537
+ }
538
+
539
+ /*
540
+ * Process bulk actions (delete, copy) that affect an array of items
541
+ */
542
+ $bulk_action = MLASettings::mla_current_bulk_action();
543
+ if ( $bulk_action && ( $bulk_action != 'none' ) ) {
544
+ if ( isset( $_REQUEST['cb_mla_item_ID'] ) ) {
545
+ foreach ( $_REQUEST['cb_mla_item_ID'] as $post_ID ) {
546
+ switch ( $bulk_action ) {
547
+ case 'delete':
548
+ $item_content = MLASettings_Shortcodes::mla_delete_template( $post_ID );
549
+ break;
550
+ case 'copy':
551
+ $content = MLASettings_Shortcodes::mla_copy_template( $post_ID );
552
+ $item_content = $content['message'];
553
+ break;
554
+ default:
555
+ $item_content = array(
556
+ /* translators: 1: bulk_action, e.g., delete, edit, restore, trash */
557
+ 'message' => sprintf( __( 'Unknown bulk action %1$s', 'media-library-assistant' ), $bulk_action ),
558
+ 'body' => ''
559
+ );
560
+ } // switch $bulk_action
561
+
562
+ $page_content['message'] .= $item_content . '<br>';
563
+ } // foreach cb_attachment
564
+
565
+ MLA_Template_Query::mla_put_shortcode_template_items();
566
+ } // isset cb_attachment
567
+ else {
568
+ /* translators: 1: action name, e.g., edit */
569
+ $page_content['message'] = sprintf( __( 'Bulk Action %1$s - no items selected.', 'media-library-assistant' ), $bulk_action );
570
+ }
571
+ } // $bulk_action
572
+
573
+ /*
574
+ * Process row-level actions that affect a single item
575
+ */
576
+ if ( !empty( $_REQUEST['mla_admin_action'] ) ) {
577
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
578
+
579
+ $page_content = array( 'message' => '', 'body' => '' );
580
+
581
+ switch ( $_REQUEST['mla_admin_action'] ) {
582
+ case MLACore::MLA_ADMIN_SINGLE_COPY:
583
+ $content = MLASettings_Shortcodes::mla_copy_template( $_REQUEST['mla_item_ID'] );
584
+ MLA_Template_Query::mla_put_shortcode_template_items();
585
+ $item = MLA_Template_Query::mla_find_shortcode_template_ID( $content['type'], $content['name'] );
586
+ $item = MLA_Template_Query::mla_find_shortcode_template( $item );
587
+ $page_content = self::_compose_edit_template_tab( $item, $page_template_array );
588
+ break;
589
+ case MLACore::MLA_ADMIN_SINGLE_EDIT_DISPLAY:
590
+ $item = MLA_Template_Query::mla_find_shortcode_template( $_REQUEST['mla_item_ID'] );
591
+ $page_content = self::_compose_edit_template_tab( $item, $page_template_array );
592
+ break;
593
+ case MLACore::MLA_ADMIN_SINGLE_DELETE:
594
+ $page_content['message'] = MLASettings_Shortcodes::mla_delete_template( $_REQUEST['mla_item_ID'] );
595
+ MLA_Template_Query::mla_put_shortcode_template_items();
596
+ break;
597
+ default:
598
+ $page_content['message'] = sprintf( __( 'Unknown mla_admin_action - "%1$s"', 'media-library-assistant' ), $_REQUEST['mla_admin_action'] );
599
+ break;
600
+ } // switch ($_REQUEST['mla_admin_action'])
601
+ } // (!empty($_REQUEST['mla_admin_action'])
602
+
603
+ if ( !empty( $page_content['body'] ) ) {
604
+ return $page_content;
605
+ }
606
+
607
+ /*
608
+ * Display the Shortcodes tab and the Template table
609
+ */
610
+ $_SERVER['REQUEST_URI'] = remove_query_arg( array(
611
+ 'mla_admin_action',
612
+ 'mla_template_item',
613
+ 'mla_template_item',
614
+ 'mla_item_ID',
615
+ '_wpnonce',
616
+ '_wp_http_referer',
617
+ 'action',
618
+ 'action2',
619
+ 'cb_mla_item_ID',
620
+ 'mla-edit-template-cancel',
621
+ 'mla-edit-template-submit',
622
+ 'mla-shortcodes-options-save',
623
+ ), $_SERVER['REQUEST_URI'] );
624
+ //error_log( __LINE__ . ' mla_compose_shortcodes_tab REQUEST_URI = ' . var_export( $_SERVER['REQUEST_URI'], true ), 0 );
625
+
626
+ // Create an instance of our package class
627
+ $MLATemplateListTable = new MLA_Template_List_Table();
628
+
629
+ // Fetch, prepare, sort, and filter our data
630
+ $MLATemplateListTable->prepare_items();
631
+
632
+ /*
633
+ * Build default template selection lists
634
+ */
635
+ MLACoreOptions::$mla_option_definitions['default_style']['options'][] = 'none';
636
+ MLACoreOptions::$mla_option_definitions['default_style']['texts'][] = '&mdash; ' . __( 'None', 'media-library-assistant' ) . ' &mdash;';
637
+ MLACoreOptions::$mla_option_definitions['default_style']['options'][] = 'theme';
638
+ MLACoreOptions::$mla_option_definitions['default_style']['texts'][] = '&mdash; ' . __( 'Theme', 'media-library-assistant' ) . ' &mdash;';
639
+
640
+ $templates = MLATemplate_Support::mla_get_style_templates( 'gallery' );
641
+ ksort($templates);
642
+ foreach ($templates as $key => $value ) {
643
+ MLACoreOptions::$mla_option_definitions['default_style']['options'][] = $key;
644
+ MLACoreOptions::$mla_option_definitions['default_style']['texts'][] = $key;
645
+ }
646
+
647
+ $templates = MLATemplate_Support::mla_get_markup_templates( 'gallery' );
648
+ ksort($templates);
649
+ foreach ($templates as $key => $value ) {
650
+ MLACoreOptions::$mla_option_definitions['default_markup']['options'][] = $key;
651
+ MLACoreOptions::$mla_option_definitions['default_markup']['texts'][] = $key;
652
+ }
653
+
654
+ /*
655
+ * Check for MLA Viewer Support requirements,
656
+ * starting with Imagick check
657
+ */
658
+ if ( ! class_exists( 'Imagick' ) ) {
659
+ $not_supported_warning = '<br>&nbsp;&nbsp;' . __( 'Imagick support is not installed.', 'media-library-assistant' );
660
+ } else {
661
+ $not_supported_warning = '';
662
+ }
663
+
664
+ $ghostscript_path = MLACore::mla_get_option( 'ghostscript_path' );
665
+ if ( ! MLAShortcode_Support::mla_ghostscript_present( $ghostscript_path, true ) ) {
666
+ $not_supported_warning .= '<br>&nbsp;&nbsp;' . __( 'Ghostscript support is not installed.', 'media-library-assistant' );
667
+ }
668
+
669
+ if ( ! empty( $not_supported_warning ) ) {
670
+ MLACoreOptions::$mla_option_definitions['enable_mla_viewer']['help'] = '<strong>' . __( 'WARNING:', 'media-library-assistant' ) . __( ' MLA Viewer support may not be available', 'media-library-assistant' ) . ':</strong>' . $not_supported_warning;
671
+ }
672
+
673
+ // Start with any page-level options
674
+ $options_list = '';
675
+ foreach ( MLACoreOptions::$mla_option_definitions as $key => $value ) {
676
+ if ( 'mla_gallery' == $value['tab'] ) {
677
+ $options_list .= MLASettings::mla_compose_option_row( $key, $value );
678
+ }
679
+ }
680
+
681
+ // WPML requires that lang be the first argument after page
682
+ $view_arguments = MLA_Template_List_Table::mla_submenu_arguments();
683
+ $form_language = isset( $view_arguments['lang'] ) ? '&lang=' . $view_arguments['lang'] : '';
684
+ $form_arguments = '?page=mla-settings-menu-shortcodes' . $form_language . '&mla_tab=shortcodes';
685
+
686
+ // We need to remember all the view arguments
687
+ $view_args = '';
688
+ foreach ( $view_arguments as $key => $value ) {
689
+ /*
690
+ * Search box elements are already set up in the above "search-box"
691
+ * 'lang' has already been added to the form action attribute
692
+ */
693
+ if ( in_array( $key, array( 's', 'lang' ) ) ) {
694
+ continue;
695
+ }
696
+
697
+ if ( is_array( $value ) ) {
698
+ foreach ( $value as $element_key => $element_value )
699
+ $view_args .= "\t" . sprintf( '<input type="hidden" name="%1$s[%2$s]" value="%3$s" />', $key, $element_key, esc_attr( $element_value ) ) . "\n";
700
+ } else {
701
+ $view_args .= "\t" . sprintf( '<input type="hidden" name="%1$s" value="%2$s" />', $key, esc_attr( $value ) ) . "\n";
702
+ }
703
+ }
704
+ //error_log( __LINE__ . " view arguments( {$view_args} ) = " . var_export( $view_arguments, true ), 0 );
705
+
706
+ $page_values = array(
707
+ 'MLA Shortcode Options' => __( 'MLA Shortcode Options', 'media-library-assistant' ),
708
+ 'In this tab' => __( 'In this tab you can view the default style and markup templates. You can also define additional templates and use the <code>mla_style</code> and <code>mla_markup</code> parameters to apply them in your [mla_gallery] shortcodes.', 'media-library-assistant' ),
709
+ /* translators: 1: Documentation hyperlink */
710
+ 'You can find' => sprintf( __( 'You can find more information about shortcode templates and how MLA and WordPress use them in the %1$s section of the Documentation or by clicking the <strong>"Help"</strong> tab in the upper-right corner of this screen.', 'media-library-assistant' ), '<a href="[+settingsURL+]?page=mla-settings-menu-documentation&amp;mla_tab=documentation#mla_gallery_templates" title="' . __( 'Style and Markup Templates documentation', 'media-library-assistant' ) . '">' . __( 'Style and Markup Templates', 'media-library-assistant' ) . '</a>' ),
711
+ 'settingsURL' => admin_url('options-general.php'),
712
+ 'form_url' => admin_url( 'options-general.php' ) . $form_arguments,
713
+ 'view_args' => $view_args,
714
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
715
+ '_wp_http_referer' => wp_referer_field( false ),
716
+ 'Add New Template' => __( 'Add New Template', 'media-library-assistant' ),
717
+ 'Search Templates' => __( 'Search Templates', 'media-library-assistant' ),
718
+ 's' => isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '',
719
+ 'results' => ! empty( $_REQUEST['s'] ) ? '<span class="alignright" style="margin-top: .5em; font-weight: bold">' . __( 'Search results for', 'media-library-assistant' ) . ':&nbsp;</span>' : '',
720
+ 'options_list' => $options_list,
721
+ 'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
722
+ );
723
+
724
+ $page_content['body'] = MLAData::mla_parse_template( $page_template_array['before-table'], $page_values );
725
+
726
+ // Now we can render the completed list table
727
+ ob_start();
728
+ $MLATemplateListTable->views();
729
+ $MLATemplateListTable->display();
730
+ $page_content['body'] .= ob_get_contents();
731
+ ob_end_clean();
732
+
733
+ $page_content['body'] .= MLAData::mla_parse_template( $page_template_array['after-table'], $page_values );
734
+
735
+ return $page_content;
736
+ }
737
+ } // class MLASettings_Shortcodes
738
+
739
+ /*
740
+ * The WP_List_Table class isn't automatically available to plugins
741
+ */
742
+ if ( !class_exists( 'WP_List_Table' ) ) {
743
+ require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
744
+ }
745
+
746
+ /**
747
+ * Class MLA (Media Library Assistant) Template List Table displays the
748
+ * shortcode templates submenu table
749
+ *
750
+ * Extends the core WP_List_Table class.
751
+ *
752
+ * @package Media Library Assistant
753
+ * @since 2.40
754
+ */
755
+ class MLA_Template_List_Table extends WP_List_Table {
756
+ /**
757
+ * Calls the parent constructor to set some default values.
758
+ *
759
+ * @since 2.40
760
+ *
761
+ * @return void
762
+ */
763
+ function __construct( ) {
764
+ //Set parent defaults
765
+ parent::__construct( array(
766
+ 'singular' => 'template', //singular name of the listed records
767
+ 'plural' => 'templates', //plural name of the listed records
768
+ 'ajax' => false, //does this table support ajax?
769
+ 'screen' => 'settings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-shortcodes'
770
+ ) );
771
+
772
+ /*
773
+ * NOTE: There is one add_action call at the end of this source file.
774
+ */
775
+ }
776
+
777
+ /**
778
+ * Table column definitions
779
+ *
780
+ * This array defines table columns and titles where the key is the column slug (and class)
781
+ * and the value is the column's title text.
782
+ *
783
+ * All of the columns are added to this array by MLA_Template_List_Table::_localize_default_columns_array.
784
+ *
785
+ * @since 2.40
786
+ * @access private
787
+ * @var array $default_columns {
788
+ * @type string $$column_slug Column title.
789
+ * }
790
+ */
791
+ private static $default_columns = array();
792
+
793
+ /**
794
+ * Default values for hidden columns
795
+ *
796
+ * This array is used when the user-level option is not set, i.e.,
797
+ * the user has not altered the selection of hidden columns.
798
+ *
799
+ * The value on the right-hand side must match the column slug, e.g.,
800
+ * array(0 => 'ID_parent, 1 => 'title_name').
801
+ *
802
+ * @since 2.40
803
+ * @access private
804
+ * @var array $default_hidden_columns {
805
+ * @type string $$index Column slug.
806
+ * }
807
+ */
808
+ private static $default_hidden_columns = array(
809
+ // 'name',
810
+ // 'type',
811
+ // 'shortcode',
812
+ // 'description'
813
+ );
814
+
815
+ /**
816
+ * Sortable column definitions
817
+ *
818
+ * This array defines the table columns that can be sorted. The array key
819
+ * is the column slug that needs to be sortable, and the value is database column
820
+ * to sort by. Often, the key and value will be the same, but this is not always
821
+ * the case (as the value is a column name from the database, not the list table).
822
+ *
823
+ * The array value also contains a boolean which is 'true' if the data is currently
824
+ * sorted by that column. This is computed each time the table is displayed.
825
+ *
826
+ * @since 2.40
827
+ * @access private
828
+ * @var array $default_sortable_columns {
829
+ * @type array $$column_slug {
830
+ * @type string $orderby_name Database column or other sorting slug.
831
+ * @type boolean $descending Optional. True to make the initial orderby DESC.
832
+ * }
833
+ * }
834
+ */
835
+ private static $default_sortable_columns = array(
836
+ 'name' => array('name',false),
837
+ 'type' => array('type',false),
838
+ 'shortcode' => array('shortcode',false),
839
+ 'description' => array('description',false),
840
+ );
841
+
842
+ /**
843
+ * Access the default list of hidden columns
844
+ *
845
+ * @since 2.40
846
+ *
847
+ * @return array default list of hidden columns
848
+ */
849
+ private static function _default_hidden_columns( ) {
850
+ return self::$default_hidden_columns;
851
+ }
852
+
853
+ /**
854
+ * Return the names and display values of the sortable columns
855
+ *
856
+ * @since 2.40
857
+ *
858
+ * @return array name => array( orderby value, heading ) for sortable columns
859
+ */
860
+ public static function mla_get_sortable_columns( ) {
861
+ self::_localize_default_columns_array();
862
+ $results = array() ;
863
+
864
+ foreach ( self::$default_sortable_columns as $key => $value ) {
865
+ $value[1] = self::$default_columns[ $key ];
866
+ $results[ $key ] = $value;
867
+ }
868
+
869
+ return $results;
870
+ }
871
+
872
+ /**
873
+ * Process $_REQUEST, building $submenu_arguments
874
+ *
875
+ * @since 2.40
876
+ *
877
+ * @param boolean $include_filters Optional. Include the "click filter" values in the results. Default true.
878
+ * @return array non-empty view, search, filter and sort arguments
879
+ */
880
+ public static function mla_submenu_arguments( $include_filters = true ) {
881
+ static $submenu_arguments = NULL, $has_filters = NULL;
882
+
883
+ if ( is_array( $submenu_arguments ) && ( $has_filters == $include_filters ) ) {
884
+ return $submenu_arguments;
885
+ }
886
+
887
+ $submenu_arguments = array();
888
+ $has_filters = $include_filters;
889
+
890
+ // View arguments
891
+ if ( isset( $_REQUEST['mla_template_view'] ) ) {
892
+ $submenu_arguments['mla_template_view'] = $_REQUEST['mla_template_view'];
893
+ }
894
+
895
+ // Search box arguments
896
+ if ( !empty( $_REQUEST['s'] ) ) {
897
+ $submenu_arguments['s'] = urlencode( stripslashes( $_REQUEST['s'] ) );
898
+ }
899
+
900
+ // Filter arguments (from table header)
901
+ if ( isset( $_REQUEST['mla_template_status'] ) && ( 'any' != $_REQUEST['mla_template_status'] ) ) {
902
+ $submenu_arguments['mla_template_status'] = $_REQUEST['mla_template_status'];
903
+ }
904
+
905
+ // Sort arguments (from column header)
906
+ if ( isset( $_REQUEST['order'] ) ) {
907
+ $submenu_arguments['order'] = $_REQUEST['order'];
908
+ }
909
+
910
+ if ( isset( $_REQUEST['orderby'] ) ) {
911
+ $submenu_arguments['orderby'] = $_REQUEST['orderby'];
912
+ }
913
+ //error_log( __LINE__ . ' mla_submenu_arguments request = ' . var_export( $submenu_arguments, true ), 0 );
914
+
915
+ return $submenu_arguments;
916
+ }
917
+
918
+ /**
919
+ * Handler for filter 'get_user_option_managesettings_page_mla-settings-menu-examplecolumnshidden'
920
+ *
921
+ * Required because the screen.php get_hidden_columns function only uses
922
+ * the get_user_option result. Set when the file is loaded because the object
923
+ * is not created in time for the call from screen.php.
924
+ *
925
+ * @since 2.40
926
+ *
927
+ * @param mixed false or array with current list of hidden columns, if any
928
+ * @param string 'managesettings_page_mla-settings-menucolumnshidden'
929
+ * @param object WP_User object, if logged in
930
+ *
931
+ * @return array updated list of hidden columns
932
+ */
933
+ public static function mla_manage_hidden_columns_filter( $result, $option, $user_data ) {
934
+ return $result ? $result : self::_default_hidden_columns();
935
+ }
936
+
937
+ /**
938
+ * Handler for filter 'manage_settings_page_mla-settings-menu_columns'
939
+ *
940
+ * This required filter dictates the table's columns and titles. Set when the
941
+ * file is loaded because the list_table object isn't created in time
942
+ * to affect the "screen options" setup.
943
+ *
944
+ * @since 2.40
945
+ *
946
+ * @return array list of table columns
947
+ */
948
+ public static function mla_manage_columns_filter( ) {
949
+ self::_localize_default_columns_array();
950
+ return self::$default_columns;
951
+ }
952
+
953
+ /**
954
+ * Builds the $default_columns array with translated source texts.
955
+ *
956
+ * @since 2.40
957
+ */
958
+ private static function _localize_default_columns_array( ) {
959
+ if ( empty( self::$default_columns ) ) {
960
+ // Build the default columns array at runtime to accomodate calls to the localization functions
961
+ self::$default_columns = array(
962
+ 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
963
+ 'name' => _x( 'Name', 'list_table_column', 'media-library-assistant' ),
964
+ 'type' => _x( 'Type', 'list_table_column', 'media-library-assistant' ),
965
+ 'shortcode' => _x( 'Shortcode', 'list_table_column', 'media-library-assistant' ),
966
+ 'description' => _x( 'Description', 'list_table_column', 'media-library-assistant' ),
967
+ );
968
+ }
969
+ }
970
+
971
+ /**
972
+ * Print optional in-line styles for the Shortcodes submenu table
973
+ *
974
+ * @since 2.40
975
+ */
976
+ public static function mla_admin_print_styles_action() {
977
+ /*
978
+ * Suppress display of the hidden columns selection list (disabled),
979
+ * adjust width of the Type column
980
+ */
981
+ echo " <style type='text/css'>\r\n";
982
+ //echo " form#adv-settings div.metabox-prefs,\r\n";
983
+ //echo " form#adv-settings fieldset.metabox-prefs {\r\n";
984
+ //echo " display: none;\r\n";
985
+ //echo " }\r\n\r\n";
986
+ echo " table.template_plugins th.column-type,\r\n";
987
+ echo " table.template_plugins td.column-type {\r\n";
988
+ echo " width: 8em;\r\n";
989
+ echo " }\r\n";
990
+ echo " </style>\r\n";
991
+ }
992
+
993
+ /**
994
+ * Called in the admin_init action because the list_table object isn't
995
+ * created in time to affect the "screen options" setup.
996
+ *
997
+ * @since 2.40
998
+ *
999
+ * @return void
1000
+ */
1001
+ public static function mla_admin_init( ) {
1002
+ if ( isset( $_REQUEST['mla_tab'] ) && $_REQUEST['mla_tab'] == 'shortcodes' ) {
1003
+ add_filter( 'get_user_option_managesettings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-shortcodescolumnshidden', 'MLA_Template_List_Table::mla_manage_hidden_columns_filter', 10, 3 );
1004
+ add_filter( 'manage_settings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-shortcodes_columns', 'MLA_Template_List_Table::mla_manage_columns_filter', 10, 0 );
1005
+ }
1006
+ }
1007
+
1008
+ /**
1009
+ * Get the name of the default primary column.
1010
+ *
1011
+ * @since 2.40
1012
+ * @access protected
1013
+ *
1014
+ * @return string Name of the default primary column
1015
+ */
1016
+ protected function get_default_primary_column_name() {
1017
+ return 'name';
1018
+ }
1019
+
1020
+ /**
1021
+ * Supply a column value if no column-specific function has been defined
1022
+ *
1023
+ * Called when the parent class can't find a method specifically built for a
1024
+ * given column. All columns should have a specific method, so this function
1025
+ * returns a troubleshooting message.
1026
+ *
1027
+ * @since 2.40
1028
+ *
1029
+ * @param array A singular item (one full row's worth of data)
1030
+ * @param array The name/slug of the column to be processed
1031
+ * @return string Text or HTML to be placed inside the column
1032
+ */
1033
+ function column_default( $item, $column_name ) {
1034
+ //Show the whole array for troubleshooting purposes
1035
+ /* translators: 1: column_name 2: column_values */
1036
+ return sprintf( __( 'column_default: %1$s, %2$s', 'media-library-assistant' ), $column_name, print_r( $item, true ) );
1037
+ }
1038
+
1039
+ /**
1040
+ * Displays checkboxes for using bulk actions. The 'cb' column
1041
+ * is given special treatment when columns are processed.
1042
+ *
1043
+ * @since 2.40
1044
+ *
1045
+ * @param object An MLA shortcode_template object
1046
+ * @return string HTML markup to be placed inside the column
1047
+ */
1048
+ function column_cb( $item ) {
1049
+ return sprintf( '<input type="checkbox" name="cb_mla_item_ID[]" value="%1$s" />',
1050
+ /*%1$s*/ $item->post_ID
1051
+ );
1052
+ }
1053
+
1054
+ /**
1055
+ * Add rollover actions to a table column
1056
+ *
1057
+ * @since 2.40
1058
+ *
1059
+ * @param object An MLA shortcode_template object
1060
+ * @param string Current column name
1061
+ *
1062
+ * @return array Names and URLs of row-level actions
1063
+ */
1064
+ private function _build_rollover_actions( $item, $column ) {
1065
+ $actions = array();
1066
+
1067
+ /*
1068
+ * Compose view arguments
1069
+ */
1070
+
1071
+ $view_args = array_merge( array(
1072
+ 'page' => MLACoreOptions::MLA_SETTINGS_SLUG . '-shortcodes',
1073
+ 'mla_tab' => 'shortcodes',
1074
+ 'mla_item_ID' => urlencode( $item->post_ID )
1075
+ ), MLA_Template_List_Table::mla_submenu_arguments() );
1076
+
1077
+ if ( isset( $_REQUEST['paged'] ) ) {
1078
+ $view_args['paged'] = $_REQUEST['paged'];
1079
+ }
1080
+
1081
+ if ( $item->default ) {
1082
+ $actions['view'] = '<a href="' . add_query_arg( $view_args, wp_nonce_url( '?mla_admin_action=' . MLACore::MLA_ADMIN_SINGLE_EDIT_DISPLAY, MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ) ) . '" title="' . __( 'View this item', 'media-library-assistant' ) . '">' . __( 'View', 'media-library-assistant' ) . '</a>';
1083
+ } else {
1084
+ $actions['edit'] = '<a href="' . add_query_arg( $view_args, wp_nonce_url( '?mla_admin_action=' . MLACore::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>';
1085
+ }
1086
+
1087
+ $actions['copy'] = '<a href="' . add_query_arg( $view_args, wp_nonce_url( '?mla_admin_action=' . MLACore::MLA_ADMIN_SINGLE_COPY, MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ) ) . '" title="' . __( 'Make a copy', 'media-library-assistant' ) . '">' . __( 'Copy', 'media-library-assistant' ) . '</a>';
1088
+
1089
+ if ( ! $item->default ) {
1090
+ $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>';
1091
+ }
1092
+
1093
+ return $actions;
1094
+ }
1095
+
1096
+ /**
1097
+ * Supply the content for the Name column
1098
+ *
1099
+ * @since 2.40
1100
+ *
1101
+ * @param object An MLA shortcode_template object
1102
+ * @return string HTML markup to be placed inside the column
1103
+ */
1104
+ function column_name( $item ) {
1105
+ $row_actions = self::_build_rollover_actions( $item, 'name' );
1106
+ $slug = esc_attr( $item->name );
1107
+ $default = $item->default ? '<br>(' . __( 'default', 'media-library-assistant' ) . ')' : '';
1108
+ return sprintf( '%1$s%2$s<br>%3$s', $slug, $default, $this->row_actions( $row_actions ) );
1109
+ }
1110
+
1111
+ /**
1112
+ * Supply the content for the Type column
1113
+ *
1114
+ * @since 2.40
1115
+ *
1116
+ * @param object An MLA shortcode_template object
1117
+ * @return string HTML markup to be placed inside the column
1118
+ */
1119
+ function column_type( $item ) {
1120
+ return esc_attr( 'style' === $item->type ? _x( 'Style', 'table_view_singular', 'media_library-assistant' ) : _x( 'Markup', 'table_view_singular', 'media_library-assistant' ) );
1121
+ }
1122
+
1123
+ /**
1124
+ * Supply the content for the Shortcode column
1125
+ *
1126
+ * @since 2.40
1127
+ *
1128
+ * @param object An MLA shortcode_template object
1129
+ * @return string HTML markup to be placed inside the column
1130
+ */
1131
+ function column_shortcode( $item ) {
1132
+ return esc_attr( MLATemplate_Support::$mla_template_definitions[ $item->type ][ $item->shortcode ]['label'] );
1133
+ }
1134
+
1135
+ /**
1136
+ * Supply the content for the Description column
1137
+ *
1138
+ * @since 2.40
1139
+ *
1140
+ * @param object An MLA shortcode_template object
1141
+ * @return string HTML markup to be placed inside the column
1142
+ */
1143
+ function column_description( $item ) {
1144
+ if ( isset( $item->sections['description'] ) ) {
1145
+ return esc_attr( $item->sections['description'] );
1146
+ }
1147
+
1148
+ return '';
1149
+ }
1150
+
1151
+ /**
1152
+ * Display the pagination, adding view, search and filter arguments
1153
+ *
1154
+ * @since 2.40
1155
+ *
1156
+ * @param string 'top' | 'bottom'
1157
+ */
1158
+ function pagination( $which ) {
1159
+ $save_uri = $_SERVER['REQUEST_URI'];
1160
+ $_SERVER['REQUEST_URI'] = add_query_arg( MLA_Template_List_Table::mla_submenu_arguments(), $save_uri );
1161
+ parent::pagination( $which );
1162
+ $_SERVER['REQUEST_URI'] = $save_uri;
1163
+ }
1164
+
1165
+ /**
1166
+ * This method dictates the table's columns and titles
1167
+ *
1168
+ * @since 2.40
1169
+ *
1170
+ * @return array Column information: 'slugs'=>'Visible Titles'
1171
+ */
1172
+ function get_columns( ) {
1173
+ return $columns = MLA_Template_List_Table::mla_manage_columns_filter();
1174
+ }
1175
+
1176
+ /**
1177
+ * Returns the list of currently hidden columns from a user option or
1178
+ * from default values if the option is not set
1179
+ *
1180
+ * @since 2.40
1181
+ *
1182
+ * @return array Column information,e.g., array(0 => 'ID_parent, 1 => 'title_name')
1183
+ */
1184
+ function get_hidden_columns( ) {
1185
+ $columns = get_user_option( 'managesettings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-shortcodescolumnshidden' );
1186
+
1187
+ if ( is_array( $columns ) ) {
1188
+ return $columns;
1189
+ }
1190
+
1191
+ return self::_default_hidden_columns();
1192
+ }
1193
+
1194
+ /**
1195
+ * Returns an array where the key is the column that needs to be sortable
1196
+ * and the value is db column to sort by. Also notes the current sort column,
1197
+ * if set.
1198
+ *
1199
+ * @since 2.40
1200
+ *
1201
+ * @return array Sortable column information,e.g.,
1202
+ * 'slugs'=>array('data_values',boolean)
1203
+ */
1204
+ function get_sortable_columns( ) {
1205
+ $columns = self::$default_sortable_columns;
1206
+
1207
+ if ( isset( $_REQUEST['orderby'] ) ) {
1208
+ $needle = array( $_REQUEST['orderby'], false );
1209
+ $key = array_search( $needle, $columns );
1210
+ if ( $key ) {
1211
+ $columns[ $key ][ 1 ] = true;
1212
+ }
1213
+ } else {
1214
+ $columns['name'][ 1 ] = true;
1215
+ }
1216
+
1217
+ return $columns;
1218
+ }
1219
+
1220
+ /**
1221
+ * Print column headers, adding view, search and filter arguments
1222
+ *
1223
+ * @since 2.40
1224
+ *
1225
+ * @param bool $with_id Whether to set the id attribute or not
1226
+ */
1227
+ function print_column_headers( $with_id = true ) {
1228
+ $save_uri = $_SERVER['REQUEST_URI'];
1229
+ $_SERVER['REQUEST_URI'] = add_query_arg( MLA_Template_List_Table::mla_submenu_arguments(), $save_uri );
1230
+ parent::print_column_headers( $with_id );
1231
+ $_SERVER['REQUEST_URI'] = $save_uri;
1232
+ }
1233
+
1234
+ /**
1235
+ * Returns HTML markup for one view that can be used with this table
1236
+ *
1237
+ * @since 2.40
1238
+ *
1239
+ * @param string View slug
1240
+ * @param array count and labels for the View
1241
+ * @param string Slug for current view
1242
+ *
1243
+ * @return string | false HTML for link to display the view, false if count = zero
1244
+ */
1245
+ function _get_view( $view_slug, $template_item, $current_view ) {
1246
+ static $base_url = NULL;
1247
+
1248
+ $class = ( $view_slug == $current_view ) ? ' class="current"' : '';
1249
+
1250
+ /*
1251
+ * Calculate the common values once per page load
1252
+ */
1253
+ if ( is_null( $base_url ) ) {
1254
+ /*
1255
+ * Remember the view filters
1256
+ */
1257
+ $base_url = wp_nonce_url( 'options-general.php?page=' . MLACoreOptions::MLA_SETTINGS_SLUG . '-shortcodes&mla_tab=shortcodes', MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
1258
+
1259
+ if ( isset( $_REQUEST['s'] ) ) {
1260
+ $base_url = add_query_arg( array( 's' => $_REQUEST['s'] ), $base_url );
1261
+ }
1262
+ }
1263
+
1264
+ $singular = sprintf('%s <span class="count">(%%s)</span>', $template_item['singular'] );
1265
+ $plural = sprintf('%s <span class="count">(%%s)</span>', $template_item['plural'] );
1266
+ $nooped_plural = _n_noop( $singular, $plural, 'media-library-assistant' );
1267
+ return "<a href='" . add_query_arg( array( 'mla_template_view' => $view_slug ), $base_url )
1268
+ . "'$class>" . sprintf( translate_nooped_plural( $nooped_plural, $template_item['count'], 'media-library-assistant' ), number_format_i18n( $template_item['count'] ) ) . '</a>';
1269
+ } // _get_view
1270
+
1271
+ /**
1272
+ * Returns an associative array listing all the views that can be used with this table.
1273
+ * These are listed across the top of the page and managed by WordPress.
1274
+ *
1275
+ * @since 2.40
1276
+ *
1277
+ * @return array View information,e.g., array ( id => link )
1278
+ */
1279
+ function get_views( ) {
1280
+ /*
1281
+ * Find current view
1282
+ */
1283
+ $current_view = isset( $_REQUEST['mla_template_view'] ) ? $_REQUEST['mla_template_view'] : 'all';
1284
+
1285
+ /*
1286
+ * Generate the list of views, retaining keyword search criterion
1287
+ */
1288
+ //$s = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
1289
+ $s = '';
1290
+ $template_items = MLA_Template_Query::mla_tabulate_template_items( $s );
1291
+ $view_links = array();
1292
+ foreach ( $template_items as $slug => $item )
1293
+ $view_links[ $slug ] = self::_get_view( $slug, $item, $current_view );
1294
+
1295
+ return $view_links;
1296
+ }
1297
+
1298
+ /**
1299
+ * Get an associative array ( option_name => option_title ) with the list
1300
+ * of bulk actions available on this table.
1301
+ *
1302
+ * @since 2.40
1303
+ *
1304
+ * @return array Contains all the bulk actions: 'slugs'=>'Visible Titles'
1305
+ */
1306
+ function get_bulk_actions( ) {
1307
+ return array(
1308
+ 'delete' => __( 'Delete', 'media-library-assistant' ),
1309
+ 'copy' => __( 'Copy', 'media-library-assistant' ),
1310
+ );
1311
+ }
1312
+
1313
+ /**
1314
+ * Get dropdown box of template status values, i.e., Default/Custom.
1315
+ *
1316
+ * @since 2.40
1317
+ *
1318
+ * @param string $selected Optional. Currently selected status. Default 'all'.
1319
+ * @return string HTML markup for dropdown box.
1320
+ */
1321
+ public static function mla_get_template_status_dropdown( $selected = 'any' ) {
1322
+ $dropdown = '<select name="mla_template_status" class="postform" id="name">' . "\n";
1323
+
1324
+ $selected_attribute = ( $selected == 'any' ) ? ' selected="selected"' : '';
1325
+ $dropdown .= "\t" . sprintf( '<option value="any"%1$s>%2$s</option>', $selected_attribute, _wp_specialchars( __( 'Any Status', 'media-library-assistant' ) ) ) . "\n";
1326
+
1327
+ $selected_attribute = ( $selected == 'default' ) ? ' selected="selected"' : '';
1328
+ $dropdown .= "\t" . sprintf( '<option value="default"%1$s>%2$s</option>', $selected_attribute, _wp_specialchars( __( 'Default', 'media-library-assistant' ) ) ) . "\n";
1329
+
1330
+ $selected_attribute = ( $selected == 'custom' ) ? ' selected="selected"' : '';
1331
+ $dropdown .= "\t" . sprintf( '<option value="custom"%1$s>%2$s</option>', $selected_attribute, _wp_specialchars( __( 'Custom', 'media-library-assistant' ) ) ) . "\n";
1332
+
1333
+ $dropdown .= '</select>';
1334
+
1335
+ return $dropdown;
1336
+ }
1337
+
1338
+ /**
1339
+ * Extra controls to be displayed between bulk actions and pagination
1340
+ *
1341
+ * Modeled after class-wp-posts-list-table.php in wp-admin/includes.
1342
+ *
1343
+ * @since 2.40
1344
+ *
1345
+ * @param string 'top' or 'bottom', i.e., above or below the table rows
1346
+ *
1347
+ * @return void
1348
+ */
1349
+ function extra_tablenav( $which ) {
1350
+ /*
1351
+ * Decide which actions to show
1352
+ */
1353
+ if ( 'top' == $which ) {
1354
+ $actions = array( 'mla_template_status', 'mla_filter' );
1355
+ } else {
1356
+ $actions = array();
1357
+ }
1358
+
1359
+ if ( empty( $actions ) ) {
1360
+ return;
1361
+ }
1362
+
1363
+ echo ( '<div class="alignleft actions">' );
1364
+
1365
+ foreach ( $actions as $action ) {
1366
+ switch ( $action ) {
1367
+ case 'mla_template_status':
1368
+ echo self::mla_get_template_status_dropdown( isset( $_REQUEST['mla_template_status'] ) ? $_REQUEST['mla_template_status'] : 'any' );
1369
+ break;
1370
+ case 'mla_filter':
1371
+ submit_button( __( 'Filter', 'media-library-assistant' ), 'secondary', 'mla_filter', false, array( 'id' => 'template-query-submit' ) );
1372
+ break;
1373
+ default:
1374
+ // ignore anything else
1375
+ }
1376
+ }
1377
+
1378
+ echo ( '</div>' );
1379
+ }
1380
+
1381
+ /**
1382
+ * Prepares the list of items for displaying
1383
+ *
1384
+ * This is where you prepare your data for display. This method will usually
1385
+ * be used to query the database, sort and filter the data, and generally
1386
+ * get it ready to be displayed. At a minimum, we should set $this->items and
1387
+ * $this->set_pagination_args().
1388
+ *
1389
+ * @since 2.40
1390
+ *
1391
+ * @return void
1392
+ */
1393
+ function prepare_items( ) {
1394
+ $this->_column_headers = array(
1395
+ $this->get_columns(),
1396
+ $this->get_hidden_columns(),
1397
+ $this->get_sortable_columns()
1398
+ );
1399
+
1400
+ /*
1401
+ * REQUIRED for pagination.
1402
+ */
1403
+ $total_items = MLA_Template_Query::mla_count_template_items( $_REQUEST );
1404
+ $user = get_current_user_id();
1405
+ $screen = get_current_screen();
1406
+ $option = $screen->get_option( 'per_page', 'option' );
1407
+ if ( is_string( $option ) ) {
1408
+ $per_page = get_user_meta( $user, $option, true );
1409
+ } else {
1410
+ $per_page = 10;
1411
+ }
1412
+
1413
+ if ( empty( $per_page ) || $per_page < 1 ) {
1414
+ $per_page = $screen->get_option( 'per_page', 'default' );
1415
+ }
1416
+
1417
+ /*
1418
+ * REQUIRED. We also have to register our pagination options & calculations.
1419
+ */
1420
+ $this->set_pagination_args( array(
1421
+ 'total_items' => $total_items,
1422
+ 'per_page' => $per_page,
1423
+ 'total_pages' => ceil( $total_items / $per_page )
1424
+ ) );
1425
+
1426
+ $current_page = $this->get_pagenum();
1427
+
1428
+ /*
1429
+ * REQUIRED. Assign sorted and paginated data to the items property, where
1430
+ * it can be used by the rest of the class.
1431
+ */
1432
+ $this->items = MLA_Template_Query::mla_query_template_items( $_REQUEST, ( ( $current_page - 1 ) * $per_page ), $per_page );
1433
+ }
1434
+
1435
+ /**
1436
+ * Generates (echoes) content for a single row of the table
1437
+ *
1438
+ * @since 2.40
1439
+ *
1440
+ * @param object the current item
1441
+ *
1442
+ * @return void Echoes the row HTML
1443
+ */
1444
+ function single_row( $item ) {
1445
+ static $row_class = '';
1446
+ $row_class = ( $row_class == '' ? ' class="alternate"' : '' );
1447
+
1448
+ echo '<tr id="template-' . $item->post_ID . '"' . $row_class . '>';
1449
+ echo parent::single_row_columns( $item );
1450
+ echo '</tr>';
1451
+ }
1452
+ } // class MLA_Template_List_Table
1453
+
1454
+ /**
1455
+ * Class MLA (Media Library Assistant) Template Query implements the
1456
+ * searchable database of shortcode templates
1457
+ *
1458
+ * @package Media Library Assistant
1459
+ * @since 2.40
1460
+ */
1461
+ class MLA_Template_Query {
1462
+
1463
+ /**
1464
+ * Callback to sort array by a 'name' key.
1465
+ *
1466
+ * @since 2.40
1467
+ *
1468
+ * @param array $a The first array.
1469
+ * @param array $b The second array.
1470
+ * @return integer The comparison result.
1471
+ */
1472
+ private static function _sort_uname_callback( $a, $b ) {
1473
+ return strnatcasecmp( $a['name'], $b['name'] );
1474
+ }
1475
+
1476
+ /**
1477
+ * In-memory representation of the template items
1478
+ *
1479
+ * @since 2.40
1480
+ *
1481
+ * @var array $_shortcode_template_items {
1482
+ * Items by ID. Key $$ID is an index number starting with 1.
1483
+ *
1484
+ * @type array $$ID {
1485
+ * Template elements.
1486
+ *
1487
+ * @type integer $post_ID Template ID; equal to $$ID.
1488
+ * @type string $type Template type; style or markup.
1489
+ * @type string $shortcode Shortcode slug this template applies to.
1490
+ * @type boolean $default True if a default template, false if a custom template.
1491
+ * @type string $name Template name/slug.
1492
+ * @type array $sections {
1493
+ * Template content by section. Key $$section_name is the section name/slug.
1494
+ *
1495
+ * @type string $$section_name HTML markup/CSS styles for the template section.
1496
+ * }
1497
+ * @type boolean $changed True if the template has changed since loading.
1498
+ * @type boolean $deleted True if the template has been deleted since loading.
1499
+ * @var array ID => ( post_ID, type, shortcode, default, name, description, changed, deleted )
1500
+ */
1501
+ private static $_shortcode_template_items = NULL;
1502
+
1503
+ /**
1504
+ * Highest existing template ID value
1505
+ *
1506
+ * @since 2.40
1507
+ *
1508
+ * @var integer
1509
+ */
1510
+ private static $_shortcode_template_highest_ID = 0;
1511
+
1512
+ /**
1513
+ * Assemble the in-memory representation of the templates items
1514
+ *
1515
+ * @since 2.40
1516
+ *
1517
+ * @param boolean $force_refresh Optional. Force a reload of items. Default false.
1518
+ * @return boolean Success (true) or failure (false) of the operation
1519
+ */
1520
+ private static function _get_shortcode_template_items( $force_refresh = false ) {
1521
+ if ( false == $force_refresh && NULL != self::$_shortcode_template_items ) {
1522
+ return true;
1523
+ }
1524
+
1525
+ $template_items = array();
1526
+ foreach( MLATemplate_Support::$mla_template_definitions['style'] as $shortcode => $definition ) {
1527
+ $templates = MLATemplate_Support::mla_get_style_templates( $shortcode );
1528
+ foreach( $templates as $template_name => $template ) {
1529
+ $template_items[] = array(
1530
+ 'post_ID' => 0,
1531
+ 'type' => 'style',
1532
+ 'shortcode' => $shortcode,
1533
+ 'default' => in_array( $template_name, $definition['default_names'] ),
1534
+ 'name' => $template_name,
1535
+ 'sections' => $template,
1536
+ 'changed' => false,
1537
+ 'deleted' => false,
1538
+ );
1539
+ }
1540
+ }
1541
+
1542
+ foreach( MLATemplate_Support::$mla_template_definitions['markup'] as $shortcode => $definition ) {
1543
+ $templates = MLATemplate_Support::mla_get_markup_templates( $shortcode );
1544
+ foreach( $templates as $template_name => $template ) {
1545
+ $template_items[] = array(
1546
+ 'post_ID' => 0,
1547
+ 'type' => 'markup',
1548
+ 'shortcode' => $shortcode,
1549
+ 'default' => in_array( $template_name, $definition['default_names'] ),
1550
+ 'name' => $template_name,
1551
+ 'sections' => $template,
1552
+ 'changed' => false,
1553
+ 'deleted' => false,
1554
+ );
1555
+ }
1556
+ }
1557
+
1558
+ uasort( $template_items, 'MLA_Template_Query::_sort_uname_callback' );
1559
+ self::$_shortcode_template_items = array();
1560
+ self::$_shortcode_template_highest_ID = 0;
1561
+
1562
+ // Load and number the entries
1563
+ foreach ( $template_items as $value ) {
1564
+ $ID = ++self::$_shortcode_template_highest_ID;
1565
+ $value['post_ID'] = $ID;
1566
+ self::$_shortcode_template_items[ $ID ] = $value;
1567
+ }
1568
+
1569
+ //error_log( __LINE__ . ' MLA_Template_List_Table::_get_shortcode_template_items _shortcode_template_items = ' . var_export( self::$_shortcode_template_items, true ), 0 );
1570
+ return true;
1571
+ }
1572
+
1573
+ /**
1574
+ * Flush the in-memory representation of the templates items to option values
1575
+ *
1576
+ * @since 2.40
1577
+ */
1578
+ public static function mla_put_shortcode_template_items() {
1579
+ $style_templates = array();
1580
+ $style_changed = false;
1581
+ $markup_templates = array();
1582
+ $markup_changed = false;
1583
+
1584
+ if ( NULL === self::$_shortcode_template_items ) {
1585
+ return;
1586
+ }
1587
+
1588
+ foreach( self::$_shortcode_template_items as $ID => $value ) {
1589
+ //error_log( __LINE__ . " MLA_Template_Query::mla_put_shortcode_template_items( {$ID} ) value = " . var_export( $value, true ), 0 );
1590
+ if ( $value['default'] ) {
1591
+ continue;
1592
+ }
1593
+
1594
+ $new_template = $value['sections'];
1595
+
1596
+ if ( 'style' === $value['type'] ) {
1597
+ if ( $value['deleted'] ) {
1598
+ $style_changed = true;
1599
+ continue;
1600
+ }
1601
+
1602
+ // Encode shortcode assignment in template content
1603
+ $new_template['styles'] = sprintf( "<!-- mla_shortcode_slug=\"%1\$s\" -->\r\n%2\$s", $value['shortcode'], $new_template['styles'] );
1604
+ $style_templates[ $value['name'] ] = $new_template;
1605
+ $style_changed |= $value['changed'];
1606
+ } else {
1607
+ if ( $value['deleted'] ) {
1608
+ $markup_changed = true;
1609
+ continue;
1610
+ }
1611
+
1612
+ // Encode shortcode assignment in template content
1613
+ if ( isset( $new_template['arguments'] ) ) {
1614
+ $new_template['arguments'] = sprintf( "mla_shortcode_slug=\"%1\$s\"\r\n%2\$s", $value['shortcode'], $new_template['arguments'] );
1615
+ } else {
1616
+ $new_template['arguments'] = sprintf( "mla_shortcode_slug=\"%1\$s\"\r\n", $value['shortcode'] );
1617
+ }
1618
+
1619
+ $markup_templates[ $value['name'] ] = $new_template;
1620
+ $markup_changed |= $value['changed'];
1621
+ }
1622
+ }
1623
+
1624
+ if ( $style_changed ) {
1625
+ $results = MLATemplate_Support::mla_put_style_templates( $style_templates );
1626
+ //error_log( __LINE__ . ' MLA_Template_Query::mla_put_shortcode_template_items style_templates = ' . var_export( $style_templates, true ), 0 );
1627
+ }
1628
+
1629
+ if ( $markup_changed ) {
1630
+ $results = MLATemplate_Support::mla_put_markup_templates( $markup_templates );
1631
+ //error_log( __LINE__ . ' MLA_Template_Query::mla_put_shortcode_template_items markup_templates = ' . var_export( $markup_templates, true ), 0 );
1632
+ }
1633
+
1634
+ if ( $style_changed || $markup_changed ) {
1635
+ self::_get_shortcode_template_items( true );
1636
+ }
1637
+ }
1638
+
1639
+ /**
1640
+ * Sanitize and expand query arguments from request variables
1641
+ *
1642
+ * @since 2.40
1643
+ *
1644
+ * @param array query parameters from web page, usually found in $_REQUEST
1645
+ * @param int Optional number of rows (default 0) to skip over to reach desired page
1646
+ * @param int Optional number of rows on each page (0 = all rows, default)
1647
+ *
1648
+ * @return array revised arguments suitable for query
1649
+ */
1650
+ private static function _prepare_template_items_query( $raw_request, $offset = 0, $count = 0 ) {
1651
+ /*
1652
+ * Go through the $raw_request, take only the arguments that are used in the query and
1653
+ * sanitize or validate them.
1654
+ */
1655
+ if ( ! is_array( $raw_request ) ) {
1656
+ /* translators: 1: ERROR tag 2: function name 3: non-array value */
1657
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'MLA_Template_List_Table::_prepare_template_items_query', var_export( $raw_request, true ) ), MLACore::MLA_DEBUG_CATEGORY_ANY );
1658
+ return NULL;
1659
+ }
1660
+
1661
+ $clean_request = array (
1662
+ 'mla_template_view' => 'all',
1663
+ 'mla_template_status' => 'any',
1664
+ 'orderby' => 'name',
1665
+ 'order' => 'ASC',
1666
+ 's' => ''
1667
+ );
1668
+
1669
+ foreach ( $raw_request as $key => $value ) {
1670
+ switch ( $key ) {
1671
+ case 'mla_template_view':
1672
+ case 'mla_template_status':
1673
+ $clean_request[ $key ] = $value;
1674
+ break;
1675
+ case 'orderby':
1676
+ if ( 'none' == $value ) {
1677
+ $clean_request[ $key ] = $value;
1678
+ } else {
1679
+ $sortable_columns = MLA_Template_List_Table::mla_get_sortable_columns();
1680
+ foreach ($sortable_columns as $sort_key => $sort_value ) {
1681
+ if ( $value == $sort_value[0] ) {
1682
+ $clean_request[ $key ] = $value;
1683
+ break;
1684
+ }
1685
+ } // foreach
1686
+ }
1687
+ break;
1688
+ case 'order':
1689
+ switch ( $value = strtoupper ($value ) ) {
1690
+ case 'ASC':
1691
+ case 'DESC':
1692
+ $clean_request[ $key ] = $value;
1693
+ break;
1694
+ default:
1695
+ $clean_request[ $key ] = 'ASC';
1696
+ }
1697
+ break;
1698
+ /*
1699
+ * ['s'] - Search items by one or more keywords
1700
+ */
1701
+ case 's':
1702
+ $clean_request[ $key ] = stripslashes( trim( $value ) );
1703
+ break;
1704
+ default:
1705
+ // ignore anything else in $_REQUEST
1706
+ } // switch $key
1707
+ } // foreach $raw_request
1708
+
1709
+ /*
1710
+ * Ignore incoming paged value; use offset and count instead
1711
+ */
1712
+ if ( ( (int) $count ) > 0 ) {
1713
+ $clean_request['offset'] = $offset;
1714
+ $clean_request['posts_per_page'] = $count;
1715
+ }
1716
+
1717
+ //error_log( __LINE__ . " MLA_Template_List_Table::_prepare_template_items_query( {$offset}, {$count} ) clean_request = " . var_export( $clean_request, true ), 0 );
1718
+ return $clean_request;
1719
+ }
1720
+
1721
+ /**
1722
+ * Query the plugin_examples items
1723
+ *
1724
+ * @since 2.40
1725
+ *
1726
+ * @param array query parameters from web page, usually found in $_REQUEST
1727
+ *
1728
+ * @return array query results; array of MLA post_mime_type objects
1729
+ */
1730
+ private static function _execute_template_items_query( $request ) {
1731
+ if ( ! self::_get_shortcode_template_items() ) {
1732
+ return array ();
1733
+ }
1734
+
1735
+ /*
1736
+ * Sort and filter the list
1737
+ */
1738
+ $keywords = isset( $request['s'] ) ? $request['s'] : '';
1739
+ preg_match_all('/".*?("|$)|((?<=[\t ",+])|^)[^\t ",+]+/', $keywords, $matches);
1740
+ $keywords = array_map( 'MLAQuery::mla_search_terms_tidy', $matches[0]);
1741
+ $view = isset( $request['mla_template_view'] ) ? $request['mla_template_view'] : 'all';
1742
+ $status = isset( $request['mla_template_status'] ) ? $request['mla_template_status'] : 'any';
1743
+ $index = 0;
1744
+ $sorted_items = array();
1745
+
1746
+ foreach ( self::$_shortcode_template_items as $ID => $value ) {
1747
+ if ( ! empty( $keywords ) ) {
1748
+ $found = false;
1749
+ foreach ( $keywords as $keyword ) {
1750
+ $found |= false !== stripos( $value['name'], $keyword );
1751
+ if ( isset( $value['sections']['description'] ) ) {
1752
+ $found |= false !== stripos( $value['sections']['description'], $keyword );
1753
+ }
1754
+ // TODO: Content search
1755
+ }
1756
+
1757
+ if ( ! $found ) {
1758
+ continue;
1759
+ }
1760
+ }
1761
+
1762
+ switch( $view ) {
1763
+ case 'style':
1764
+ $found = 'style' === $value['type'];
1765
+ break;
1766
+ case 'markup':
1767
+ $found = 'markup' === $value['type'];
1768
+ break;
1769
+ case 'gallery':
1770
+ $found = 'gallery' === $value['shortcode'];
1771
+ break;
1772
+ case 'tag-cloud':
1773
+ $found = 'tag-cloud' === $value['shortcode'];
1774
+ break;
1775
+ case 'term-list':
1776
+ $found = 'term-list' === $value['shortcode'];
1777
+ break;
1778
+ default:
1779
+ $found = true;
1780
+ }// $view
1781
+
1782
+ if ( ! $found ) {
1783
+ continue;
1784
+ }
1785
+
1786
+ switch( $status ) {
1787
+ case 'default':
1788
+ $found = $value['default'];
1789
+ break;
1790
+ case 'custom':
1791
+ $found = ! $value['default'];
1792
+ break;
1793
+ default:
1794
+ $found = true;
1795
+ }// $view
1796
+
1797
+ if ( ! $found ) {
1798
+ continue;
1799
+ }
1800
+
1801
+ switch ( $request['orderby'] ) {
1802
+ case 'name':
1803
+ $sorted_items[ ( empty( $value['name'] ) ? chr(1) : $value['name'] ) . $ID ] = (object) $value;
1804
+ break;
1805
+ case 'type':
1806
+ $sorted_items[ ( empty( $value['type'] ) ? chr(1) : $value['type'] ) . $ID ] = (object) $value;
1807
+ break;
1808
+ case 'shortcode':
1809
+ $sorted_items[ ( empty( $value['shortcode'] ) ? chr(1) : $value['shortcode'] ) . $ID ] = (object) $value;
1810
+ break;
1811
+ case 'description':
1812
+ $sorted_items[ ( empty( $value['sections']['description'] ) ? chr(1) : $value['sections']['description'] ) . $ID ] = (object) $value;
1813
+ break;
1814
+ default:
1815
+ $sorted_items[ $slug ] = (object) $value;
1816
+ break;
1817
+ } //orderby
1818
+ }
1819
+ ksort( $sorted_items );
1820
+ //error_log( __LINE__ . " MLA_Template_List_Table::_execute_template_items_query sorted_items = " . var_export( $sorted_items, true ), 0 );
1821
+
1822
+ if ( 'DESC' == $request['order'] ) {
1823
+ $sorted_items = array_reverse( $sorted_items, true );
1824
+ }
1825
+
1826
+ /*
1827
+ * Paginate the sorted list
1828
+ */
1829
+ $results = array();
1830
+ $offset = isset( $request['offset'] ) ? $request['offset'] : 0;
1831
+ $count = isset( $request['posts_per_page'] ) ? $request['posts_per_page'] : -1;
1832
+ foreach ( $sorted_items as $value ) {
1833
+ if ( $offset ) {
1834
+ $offset--;
1835
+ } elseif ( $count-- ) {
1836
+ $results[] = $value;
1837
+ } else {
1838
+ break;
1839
+ }
1840
+ }
1841
+ //error_log( __LINE__ . " MLA_Template_List_Table::_execute_template_items_query results = " . var_export( $results, true ), 0 );
1842
+
1843
+ return $results;
1844
+ }
1845
+
1846
+ /**
1847
+ * Get the total number of MLA shortcode_template objects
1848
+ *
1849
+ * @since 2.40
1850
+ *
1851
+ * @param array Query variables, e.g., from $_REQUEST
1852
+ *
1853
+ * @return integer Number of MLA shortcode_template objects
1854
+ */
1855
+ public static function mla_count_template_items( $request ) {
1856
+ $request = self::_prepare_template_items_query( $request );
1857
+ $results = self::_execute_template_items_query( $request );
1858
+ return count( $results );
1859
+ }
1860
+
1861
+ /**
1862
+ * Retrieve MLA shortcode_template objects for list table display
1863
+ *
1864
+ * @since 2.40
1865
+ *
1866
+ * @param array query parameters from web page, usually found in $_REQUEST
1867
+ * @param int number of rows to skip over to reach desired page
1868
+ * @param int number of rows on each page
1869
+ *
1870
+ * @return array MLA shortcode_template objects
1871
+ */
1872
+ public static function mla_query_template_items( $request, $offset, $count ) {
1873
+ $request = self::_prepare_template_items_query( $request, $offset, $count );
1874
+ //error_log( __LINE__ . ' _query_template_items request = ' . var_export( $request, true ), 0 );
1875
+ $results = self::_execute_template_items_query( $request );
1876
+ return $results;
1877
+ }
1878
+
1879
+ /**
1880
+ * Find a Shortcode Template ID given its type and name
1881
+ *
1882
+ * @since 2.40
1883
+ *
1884
+ * @param string $type MLA Shortcode Template type; style or markup.
1885
+ * @param string $name MLA Shortcode Template name.
1886
+ * @return integer Template ID if the template exists else zero (0).
1887
+ */
1888
+ public static function mla_find_shortcode_template_ID( $type, $name ) {
1889
+ if ( ! self::_get_shortcode_template_items() ) {
1890
+ return false;
1891
+ }
1892
+
1893
+ foreach( self::$_shortcode_template_items as $ID => $template ) {
1894
+ if ( $type == $template['type'] && $name == $template['name'] ) {
1895
+ return $ID;
1896
+ }
1897
+ }
1898
+
1899
+ return 0;
1900
+ }
1901
+
1902
+ /**
1903
+ * Find an Shortcode Template given its ID
1904
+ *
1905
+ * @since 2.40
1906
+ *
1907
+ * @param integer $ID MLA Shortcode Template ID
1908
+ *
1909
+ * @return array MLA shortcode_template array
1910
+ * @return boolean false; MLA shortcode_template does not exist
1911
+ */
1912
+ public static function mla_find_shortcode_template( $ID ) {
1913
+ if ( ! self::_get_shortcode_template_items() ) {
1914
+ return false;
1915
+ }
1916
+
1917
+ if ( isset( self::$_shortcode_template_items[ $ID ] ) ) {
1918
+ return self::$_shortcode_template_items[ $ID ];
1919
+ }
1920
+
1921
+ return false;
1922
+ }
1923
+
1924
+ /**
1925
+ * Update a Shortcode Template field given its ID and key.
1926
+ *
1927
+ * @since 2.40
1928
+ *
1929
+ * @param integer $ID MLA Shortcode Template ID.
1930
+ * @param string $key MLA Shortcode Template property.
1931
+ * @param string $value MLA Shortcode Template new value.
1932
+ * @return boolean true if object exists else false.
1933
+ */
1934
+ public static function mla_update_shortcode_template( $ID, $key, $value ) {
1935
+ if ( ! self::_get_shortcode_template_items() ) {
1936
+ return false;
1937
+ }
1938
+
1939
+ if ( isset( self::$_shortcode_template_items[ $ID ] ) ) {
1940
+ self::$_shortcode_template_items[ $ID ][ $key ] = $value;
1941
+ return true;
1942
+ }
1943
+
1944
+ return false;
1945
+ }
1946
+
1947
+ /**
1948
+ * Replace a Shortcode Template given its value array.
1949
+ *
1950
+ * @since 2.40
1951
+ *
1952
+ * @param array $value MLA Shortcode Template new value.
1953
+ * @return boolean true if object exists else false.
1954
+ */
1955
+ public static function mla_replace_shortcode_template( $value ) {
1956
+ if ( ! self::_get_shortcode_template_items() ) {
1957
+ return false;
1958
+ }
1959
+
1960
+ if ( isset( self::$_shortcode_template_items[ $value['post_ID'] ] ) ) {
1961
+ self::$_shortcode_template_items[ $value['post_ID'] ] = $value;
1962
+ //error_log( __LINE__ . " mla_replace_shortcode_template value = " . var_export( $value, true ), 0 );
1963
+ return true;
1964
+ }
1965
+
1966
+ return false;
1967
+ }
1968
+
1969
+ /**
1970
+ * Insert a Shortcode Template given its value array.
1971
+ *
1972
+ * @since 2.40
1973
+ *
1974
+ * @param array $value MLA Shortcode Template new value.
1975
+ */
1976
+ public static function mla_add_shortcode_template( $value ) {
1977
+ if ( ! self::_get_shortcode_template_items() ) {
1978
+ return false;
1979
+ }
1980
+
1981
+ $value['post_ID'] = ++self::$_shortcode_template_highest_ID;
1982
+ $value['default'] = false;
1983
+ $value['changed'] = true;
1984
+ $value['deleted'] = false;
1985
+
1986
+ self::$_shortcode_template_items[ $value['post_ID'] ] = $value;
1987
+ //error_log( __LINE__ . " mla_add_shortcode_template value = " . var_export( $value, true ), 0 );
1988
+ }
1989
+
1990
+ /**
1991
+ * Tabulate MLA shortcode_template objects by view for list table display
1992
+ *
1993
+ * @since 2.40
1994
+ *
1995
+ * @param string keyword search criterion, optional
1996
+ *
1997
+ * @return array ( 'singular' label, 'plural' label, 'count' of items )
1998
+ */
1999
+ public static function mla_tabulate_template_items( $s = '' ) {
2000
+ if ( empty( $s ) ) {
2001
+ $request = array( 'mla_template_view' => 'all' );
2002
+ } else {
2003
+ $request = array( 's' => $s );
2004
+ }
2005
+
2006
+ $items = self::mla_query_template_items( $request, 0, 0 );
2007
+
2008
+ $template_items = array(
2009
+ 'all' => array(
2010
+ 'singular' => _x( 'All', 'table_view_singular', 'media_library-assistant' ),
2011
+ 'plural' => _x( 'All', 'table_view_plural', 'media_library-assistant' ),
2012
+ 'count' => 0 ),
2013
+ 'style' => array(
2014
+ 'singular' => _x( 'Style', 'table_view_singular', 'media_library-assistant' ),
2015
+ 'plural' => _x( 'Style', 'table_view_plural', 'media_library-assistant' ),
2016
+ 'count' => 0 ),
2017
+ 'markup' => array(
2018
+ 'singular' => _x( 'Markup', 'table_view_singular', 'media_library-assistant' ),
2019
+ 'plural' => _x( 'Markup', 'table_view_plural', 'media_library-assistant' ),
2020
+ 'count' => 0 ),
2021
+ 'gallery' => array(
2022
+ 'singular' => _x( 'Gallery', 'table_view_singular', 'media_library-assistant' ),
2023
+ 'plural' => _x( 'Gallery', 'table_view_plural', 'media_library-assistant' ),
2024
+ 'count' => 0 ),
2025
+ 'tag-cloud' => array(
2026
+ 'singular' => _x( 'Tag Cloud', 'table_view_singular', 'media_library-assistant' ),
2027
+ 'plural' => _x( 'Tag Cloud', 'table_view_plural', 'media_library-assistant' ),
2028
+ 'count' => 0 ),
2029
+ 'term-list' => array(
2030
+ 'singular' => _x( 'Term List', 'table_view_singular', 'media_library-assistant' ),
2031
+ 'plural' => _x( 'Term List', 'table_view_plural', 'media_library-assistant' ),
2032
+ 'count' => 0 ),
2033
+ );
2034
+
2035
+ foreach ( $items as $value ) {
2036
+ $template_items['all']['count']++;
2037
+
2038
+ switch ( $value->type ) {
2039
+ case 'style':
2040
+ $template_items[ 'style' ]['count']++;
2041
+ break;
2042
+ case 'markup':
2043
+ $template_items[ 'markup' ]['count']++;
2044
+ break;
2045
+ default:
2046
+ break;
2047
+ }
2048
+
2049
+ switch ( $value->shortcode ) {
2050
+ case 'gallery':
2051
+ $template_items[ 'gallery' ]['count']++;
2052
+ break;
2053
+ case 'tag-cloud':
2054
+ $template_items[ 'tag-cloud' ]['count']++;
2055
+ break;
2056
+ case 'term-list':
2057
+ $template_items[ 'term-list' ]['count']++;
2058
+ break;
2059
+ default:
2060
+ break;
2061
+ }
2062
+ }
2063
+
2064
+ return $template_items;
2065
+ }
2066
+ } // class MLA_Template_Query
2067
+
2068
+ /*
2069
+ * Actions are added here, when the source file is loaded, because the MLA_Template_List_Table
2070
+ * object is created too late to be useful.
2071
+ */
2072
+ add_action( 'admin_enqueue_scripts', 'MLASettings_Shortcodes::mla_admin_enqueue_scripts' );
2073
+ add_action( 'admin_init', 'MLA_Template_List_Table::mla_admin_init' );
2074
+ ?>
includes/class-mla-settings-upload-tab.php ADDED
@@ -0,0 +1,1691 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Manages the Settings/Media Library Assistant Uploads tab
4
+ *
5
+ * @package Media Library Assistant
6
+ * @since 2.40
7
+ */
8
+
9
+ /**
10
+ * Class MLA (Media Library Assistant) Settings Upload implements the
11
+ * Settings/Media Library Assistant Uploads tab
12
+ *
13
+ * @package Media Library Assistant
14
+ * @since 2.40
15
+ */
16
+ class MLASettings_Upload {
17
+ /**
18
+ * Object name for localizing JavaScript - MLA Upload List Table
19
+ *
20
+ * @since 1.40
21
+ *
22
+ * @var string
23
+ */
24
+ const JAVASCRIPT_INLINE_EDIT_UPLOAD_OBJECT = 'mla_inline_edit_upload_vars';
25
+
26
+ /**
27
+ * Load the tab's Javascript files
28
+ *
29
+ * @since 2.40
30
+ *
31
+ * @param string $page_hook Name of the page being loaded
32
+ */
33
+ public static function mla_admin_enqueue_scripts( $page_hook ) {
34
+ global $wpdb;
35
+
36
+ // Without a tab value that matches ours, there's nothing to do
37
+ if ( empty( $_REQUEST['mla_tab'] ) || 'upload' !== $_REQUEST['mla_tab'] ) {
38
+ return;
39
+ }
40
+
41
+ /*
42
+ * Initialize common script variables
43
+ */
44
+ $script_variables = array(
45
+ 'error' => __( 'Error while making the changes.', 'media-library-assistant' ),
46
+ 'ntdeltitle' => __( 'Remove From Bulk Edit', 'media-library-assistant' ),
47
+ 'notitle' => '(' . __( 'no slug', 'media-library-assistant' ) . ')',
48
+ 'comma' => _x( ',', 'tag_delimiter', 'media-library-assistant' ),
49
+ 'useSpinnerClass' => false,
50
+ 'ajax_nonce' => wp_create_nonce( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ),
51
+ 'fields' => array( 'original_slug', 'slug', 'mime_type', 'icon_type', 'core_type', 'mla_type', 'source', 'standard_source' ),
52
+ 'checkboxes' => array( 'disabled' ),
53
+ 'ajax_action' => MLASettings::JAVASCRIPT_INLINE_EDIT_UPLOAD_SLUG,
54
+ );
55
+
56
+ if ( version_compare( get_bloginfo( 'version' ), '4.2', '>=' ) ) {
57
+ $script_variables['useSpinnerClass'] = true;
58
+ }
59
+
60
+ $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
61
+
62
+ wp_enqueue_script( MLASettings::JAVASCRIPT_INLINE_EDIT_UPLOAD_SLUG,
63
+ MLA_PLUGIN_URL . "js/mla-inline-edit-upload-scripts{$suffix}.js",
64
+ array( 'wp-lists', 'suggest', 'jquery' ), MLACore::CURRENT_MLA_VERSION, false );
65
+
66
+ wp_localize_script( MLASettings::JAVASCRIPT_INLINE_EDIT_UPLOAD_SLUG,
67
+ self::JAVASCRIPT_INLINE_EDIT_UPLOAD_OBJECT, $script_variables );
68
+ }
69
+
70
+ /**
71
+ * Save Upload settings to the options table
72
+ *
73
+ * @since 1.40
74
+ *
75
+ * @uses $_REQUEST
76
+ *
77
+ * @return array Message(s) reflecting the results of the operation
78
+ */
79
+ private static function _save_upload_settings( ) {
80
+ $message_list = '';
81
+
82
+ if ( ! isset( $_REQUEST[ MLA_OPTION_PREFIX . MLACoreOptions::MLA_ENABLE_UPLOAD_MIMES ] ) )
83
+ unset( $_REQUEST[ MLA_OPTION_PREFIX . MLACoreOptions::MLA_ENABLE_MLA_ICONS ] );
84
+
85
+ foreach ( MLACoreOptions::$mla_option_definitions as $key => $value ) {
86
+ if ( 'upload' == $value['tab'] ) {
87
+ $message_list .= MLASettings::mla_update_option_row( $key, $value );
88
+ } // upload option
89
+ } // foreach mla_options
90
+
91
+ $page_content = array(
92
+ 'message' => __( 'Upload MIME Type settings saved.', 'media-library-assistant' ) . "\r\n",
93
+ 'body' => ''
94
+ );
95
+
96
+ /*
97
+ * Uncomment this for debugging.
98
+ */
99
+ // $page_content['message'] .= $message_list;
100
+
101
+ return $page_content;
102
+ } // _save_upload_settings
103
+
104
+ /**
105
+ * Get an HTML select element representing a list of icon types
106
+ *
107
+ * @since 1.40
108
+ *
109
+ * @param array Display template array
110
+ * @param string HTML name attribute value
111
+ * @param string currently selected Icon Type
112
+ *
113
+ * @return string HTML select element or empty string on failure.
114
+ */
115
+ private static function _get_icon_type_dropdown( $templates, $name, $selection = '.none.' ) {
116
+ $option_template = $templates['icon-type-select-option'];
117
+ if ( '.nochange.' == $selection ) {
118
+ $option_values = array (
119
+ 'selected' => 'selected="selected"',
120
+ 'value' => '.none.',
121
+ 'text' => '&mdash; ' . __( 'No Change', 'media-library-assistant' ) . ' &mdash;'
122
+ );
123
+ } else {
124
+ $option_values = array (
125
+ 'selected' => ( '.none.' == $selection ) ? 'selected="selected"' : '',
126
+ 'value' => '.none.',
127
+ 'text' => '&mdash; ' . __( 'None (select a value)', 'media-library-assistant' ) . ' &mdash;'
128
+ );
129
+ }
130
+
131
+ $options = MLAData::mla_parse_template( $option_template, $option_values );
132
+
133
+ $icon_types = MLAMime::mla_get_current_icon_types();
134
+ foreach ( $icon_types as $icon_type ) {
135
+ $option_values = array (
136
+ 'selected' => ( $icon_type == $selection ) ? 'selected="selected"' : '',
137
+ 'value' => $icon_type,
138
+ 'text' => $icon_type
139
+ );
140
+
141
+ $options .= MLAData::mla_parse_template( $option_template, $option_values );
142
+ } // foreach icon_type
143
+
144
+ return MLAData::mla_parse_template( $templates['icon-type-select'], array( 'name' => $name, 'options' => $options ) );
145
+ }
146
+
147
+ /**
148
+ * Compose the Edit Upload type tab content for the Settings subpage
149
+ *
150
+ * @since 1.40
151
+ *
152
+ * @param array data values for the item
153
+ * @param string Display template array
154
+ *
155
+ * @return array 'message' => status/error messages, 'body' => tab content
156
+ */
157
+ private static function _compose_edit_upload_tab( $item, &$templates ) {
158
+ $page_values = array(
159
+ 'Edit Upload MIME' => __( 'Edit Upload MIME Type', 'media-library-assistant' ),
160
+ 'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-upload&mla_tab=upload',
161
+ 'action' => MLACore::MLA_ADMIN_SINGLE_EDIT_UPDATE,
162
+ 'original_slug' => $item['slug'],
163
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
164
+ 'Extension' => __( 'Extension', 'media-library-assistant' ),
165
+ 'The extension is' => __( 'The &#8220;extension&#8221; is the file extension for this type, and a unique key for the item. It must be all lowercase and contain only letters and numbers.', 'media-library-assistant' ),
166
+ 'MIME Type' => __( 'MIME Type', 'media-library-assistant' ),
167
+ 'The MIME Type' => __( 'The MIME Type must be all lowercase and contain only letters, numbers, periods (.), slashes (/) and hyphens (-). It <strong>must be a valid MIME</strong> type, e.g., &#8220;image&#8221; or &#8220;image/jpeg&#8221;.', 'media-library-assistant' ),
168
+ 'Icon Type' => __( 'Icon Type', 'media-library-assistant' ),
169
+ 'icon_types' => self::_get_icon_type_dropdown( $templates, 'mla_upload_item[icon_type]', $item['icon_type'] ),
170
+ 'The Icon Type' => __( 'The Icon Type selects a thumbnail image displayed for non-image file types, such as PDF documents.', 'media-library-assistant' ),
171
+ 'Inactive' => __( 'Inactive', 'media-library-assistant' ),
172
+ 'Check this box' => __( 'Check this box if you want to remove this entry from the list of Upload MIME Types returned by get_allowed_mime_types().', 'media-library-assistant' ),
173
+ 'Description' => __( 'Description', 'media-library-assistant' ),
174
+ 'The description can' => __( 'The description can contain any documentation or notes you need to understand or use the item.', 'media-library-assistant' ),
175
+ 'Update' => __( 'Update', 'media-library-assistant' ),
176
+ 'Cancel' => __( 'Cancel', 'media-library-assistant' ),
177
+ );
178
+
179
+ foreach ( $item as $key => $value ) {
180
+ switch ( $key ) {
181
+ case 'disabled':
182
+ $page_values[ $key ] = $value ? 'checked="checked"' : '';
183
+ break;
184
+ default:
185
+ $page_values[ $key ] = $value;
186
+ }
187
+ }
188
+
189
+ return array(
190
+ 'message' => '',
191
+ 'body' => MLAData::mla_parse_template( $templates['single-item-edit'], $page_values )
192
+ );
193
+ } // _compose_edit_upload_tab
194
+
195
+ /**
196
+ * Compose the Optional File Upload MIME Types tab content for the Settings subpage
197
+ *
198
+ * @since 1.40
199
+ *
200
+ * @param string Display templates
201
+ *
202
+ * @return array 'message' => status/error messages, 'body' => tab content
203
+ */
204
+ private static function _compose_optional_upload_tab( $page_template_array ) {
205
+ /*
206
+ * Display the Optional Upload MIME Types Table
207
+ */
208
+ $_SERVER['REQUEST_URI'] = add_query_arg( array( 'mla-optional-uploads-display' => 'true' ), remove_query_arg( array(
209
+ 'mla_admin_action',
210
+ 'mla_item_slug',
211
+ 'mla_item_ID',
212
+ '_wpnonce',
213
+ '_wp_http_referer',
214
+ 'action',
215
+ 'action2',
216
+ 'cb_attachment',
217
+ 'mla-optional-uploads-search'
218
+ ), $_SERVER['REQUEST_URI'] ) );
219
+
220
+ /*
221
+ * Suppress display of the hidden columns selection list
222
+ */
223
+ echo " <style type='text/css'>\r\n";
224
+ echo " form#adv-settings div.metabox-prefs,\r\n";
225
+ echo " form#adv-settings fieldset.metabox-prefs {\r\n";
226
+ echo " display: none;\r\n";
227
+ echo " }\r\n";
228
+ echo " </style>\r\n";
229
+
230
+ // Create an instance of our package class
231
+ $MLAListUploadTable = new MLA_Upload_Optional_List_Table();
232
+
233
+ // Fetch, prepare, sort, and filter our data
234
+ $MLAListUploadTable->prepare_items();
235
+
236
+ $page_content = array(
237
+ 'message' => '',
238
+ 'body' => ''
239
+ );
240
+
241
+ $page_values = array(
242
+ 'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-upload&mla_tab=upload',
243
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
244
+ 'Known File Extension' => __( 'Known File Extension/MIME Type Associations', 'media-library-assistant' ),
245
+ 'results' => ! empty( $_REQUEST['s'] ) ? '<h2 class="alignleft">' . __( 'Displaying search results for', 'media-library-assistant' ) . ': "' . $_REQUEST['s'] . '"</h2>' : '',
246
+ 'Search Known MIME' => __( 'Search Known MIME Types', 'media-library-assistant' ),
247
+ 's' => isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '',
248
+ 'Search Types' => __( 'Search Types', 'media-library-assistant' ),
249
+ 'To search by' => __( 'To search by extension, use ".", e.g., ".doc"', 'media-library-assistant' ),
250
+ 'Cancel' => __( 'Cancel', 'media-library-assistant' ),
251
+ );
252
+
253
+ $page_content['body'] = MLAData::mla_parse_template( $page_template_array['before-optional-uploads-table'], $page_values );
254
+
255
+ // Now we can render the completed list table
256
+ ob_start();
257
+ // $MLAListUploadTable->views();
258
+ $MLAListUploadTable->display();
259
+ $page_content['body'] .= ob_get_contents();
260
+ ob_end_clean();
261
+
262
+ $page_content['body'] .= MLAData::mla_parse_template( $page_template_array['after-optional-uploads-table'], $page_values );
263
+
264
+ return $page_content;
265
+ } // _compose_optional_upload_tab
266
+
267
+ /**
268
+ * Process an Optional Upload MIME Type selection
269
+ *
270
+ * @since 1.40
271
+ *
272
+ * @param integer MLA Optional Upload MIME Type ID
273
+ *
274
+ * @return array 'message' => status/error messages, 'body' => tab content
275
+ */
276
+ private static function _process_optional_upload_mime( $ID ) {
277
+ $optional_type = MLAMime::mla_get_optional_upload_mime( $ID );
278
+ $optional_type['disabled'] = false;
279
+
280
+ if ( false === $upload_type = MLAMime::mla_get_upload_mime( $optional_type['slug'] ) ) {
281
+ $optional_type['icon_type'] = '.none.';
282
+ return MLAMime::mla_add_upload_mime( $optional_type );
283
+ }
284
+
285
+ $optional_type['original_slug'] = $optional_type['slug'];
286
+ return MLAMime::mla_update_upload_mime( $optional_type );
287
+ } // _process_optional_upload_mime
288
+
289
+ /**
290
+ * Compose the File Upload MIME Types tab content for the Settings subpage
291
+ *
292
+ * @since 1.40
293
+ *
294
+ * @return array 'message' => status/error messages, 'body' => tab content
295
+ */
296
+ public static function mla_compose_upload_tab( ) {
297
+ $page_template_array = MLACore::mla_load_template( 'admin-display-settings-upload-tab.tpl' );
298
+ if ( ! is_array( $page_template_array ) ) {
299
+ /* translators: 1: ERROR tag 2: function name 3: non-array value */
300
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'MLASettings_Upload::mla_compose_upload_tab', var_export( $page_template_array, true ) ), MLACore::MLA_DEBUG_CATEGORY_ANY );
301
+ return '';
302
+ }
303
+
304
+ /*
305
+ * Untangle confusion between searching, canceling and selecting
306
+ * on the Optional Uploads screen
307
+ */
308
+ $bulk_action = MLASettings::mla_current_bulk_action();
309
+ if ( isset( $_REQUEST['mla-optional-uploads-cancel'] ) || $bulk_action && ( $bulk_action == 'select' ) ) {
310
+ unset( $_REQUEST['mla-optional-uploads-search'] );
311
+ unset( $_REQUEST['s'] );
312
+ }
313
+
314
+ /*
315
+ * Convert checkbox values, if present
316
+ */
317
+ if ( isset( $_REQUEST['mla_upload_item'] ) ) {
318
+ $_REQUEST['mla_upload_item']['disabled'] = isset( $_REQUEST['mla_upload_item']['disabled'] );
319
+ }
320
+
321
+ /*
322
+ * Set default values, check for Add New Upload MIME Type button
323
+ */
324
+ $add_form_values = array (
325
+ 'slug' => '',
326
+ 'mime_type' => '',
327
+ 'icon_type' => '.none.',
328
+ 'disabled' => '',
329
+ 'description' => ''
330
+ );
331
+
332
+ if ( !empty( $_REQUEST['mla-upload-options-save'] ) ) {
333
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
334
+ $page_content = self::_save_upload_settings( );
335
+ } elseif ( !empty( $_REQUEST['mla-optional-uploads-search'] ) ) {
336
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
337
+ $page_content = self::_compose_optional_upload_tab( $page_template_array );
338
+ } elseif ( !empty( $_REQUEST['mla-optional-uploads-cancel'] ) ) {
339
+ $page_content = array(
340
+ 'message' => '',
341
+ 'body' => ''
342
+ );
343
+ } elseif ( !empty( $_REQUEST['mla-optional-uploads-display'] ) ) {
344
+ if ( 'true' != $_REQUEST['mla-optional-uploads-display'] ) {
345
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
346
+ unset( $_REQUEST['s'] );
347
+ }
348
+ $page_content = self::_compose_optional_upload_tab( $page_template_array );
349
+ } elseif ( !empty( $_REQUEST['mla-add-upload-submit'] ) ) {
350
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
351
+ $page_content = MLAMime::mla_add_upload_mime( $_REQUEST['mla_upload_item'] );
352
+ if ( false !== strpos( $page_content['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
353
+ $add_form_values = $_REQUEST['mla_upload_item'];
354
+ $add_form_values['disabled'] = $add_form_values['disabled'] ? 'checked="checked"' : '';
355
+ }
356
+ } else {
357
+ $page_content = array(
358
+ 'message' => '',
359
+ 'body' => ''
360
+ );
361
+ }
362
+
363
+ /*
364
+ * Process bulk actions that affect an array of items
365
+ */
366
+ if ( $bulk_action && ( $bulk_action != 'none' ) ) {
367
+ if ( isset( $_REQUEST['cb_mla_item_ID'] ) ) {
368
+ if ( 'select' == $bulk_action ) {
369
+ foreach ( $_REQUEST['cb_mla_item_ID'] as $ID ) {
370
+ $item_content = MLASettings::_process_optional_upload_mime( $ID );
371
+ $page_content['message'] .= $item_content['message'] . '<br>';
372
+ }
373
+ } else {
374
+ /*
375
+ * Convert post-ID to slug; separate loop required because delete changes post_IDs
376
+ */
377
+ $slugs = array();
378
+ foreach ( $_REQUEST['cb_mla_item_ID'] as $post_ID )
379
+ $slugs[] = MLAMime::mla_get_upload_mime_slug( $post_ID );
380
+
381
+ foreach ( $slugs as $slug ) {
382
+ switch ( $bulk_action ) {
383
+ case 'delete':
384
+ $item_content = MLAMime::mla_delete_upload_mime( $slug );
385
+ break;
386
+ case 'edit':
387
+ $request = array( 'slug' => $slug );
388
+ if ( '-1' != $_REQUEST['disabled'] ) {
389
+ $request['disabled'] = '1' == $_REQUEST['disabled'];
390
+ }
391
+ if ( '.none.' != $_REQUEST['icon_type'] ) {
392
+ $request['icon_type'] = $_REQUEST['icon_type'];
393
+ }
394
+ $item_content = MLAMime::mla_update_upload_mime( $request );
395
+ break;
396
+ default:
397
+ $item_content = array(
398
+ /* translators: 1: bulk_action, e.g., delete, edit, restore, trash */
399
+ 'message' => sprintf( __( 'Unknown bulk action %1$s', 'media-library-assistant' ), $bulk_action ),
400
+ 'body' => ''
401
+ );
402
+ } // switch $bulk_action
403
+
404
+ $page_content['message'] .= $item_content['message'] . '<br>';
405
+ } // foreach cb_attachment
406
+ } // != select
407
+ } // isset cb_attachment
408
+ else {
409
+ /* translators: 1: action name, e.g., edit */
410
+ $page_content['message'] = sprintf( __( 'Bulk Action %1$s - no items selected.', 'media-library-assistant' ), $bulk_action );
411
+ }
412
+ } // $bulk_action
413
+
414
+ /*
415
+ * Process row-level actions that affect a single item
416
+ */
417
+ if ( !empty( $_REQUEST['mla_admin_action'] ) ) {
418
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
419
+
420
+ switch ( $_REQUEST['mla_admin_action'] ) {
421
+ case MLACore::MLA_ADMIN_SINGLE_DELETE:
422
+ $page_content = MLAMime::mla_delete_upload_mime( $_REQUEST['mla_item_slug'] );
423
+ break;
424
+ case MLACore::MLA_ADMIN_SINGLE_EDIT_DISPLAY:
425
+ $view = MLAMime::mla_get_upload_mime( $_REQUEST['mla_item_slug'] );
426
+ $page_content = self::_compose_edit_upload_tab( $view, $page_template_array );
427
+ break;
428
+ case MLACore::MLA_ADMIN_SINGLE_EDIT_UPDATE:
429
+ if ( !empty( $_REQUEST['update'] ) ) {
430
+ $page_content = MLAMime::mla_update_upload_mime( $_REQUEST['mla_upload_item'] );
431
+ if ( false !== strpos( $page_content['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
432
+ $message = $page_content['message'];
433
+ $page_content = self::_compose_edit_upload_tab( $_REQUEST['mla_upload_item'], $page_template_array );
434
+ $page_content['message'] = $message;
435
+ }
436
+ } elseif ( !empty( $_REQUEST['mla_item_ID'] ) ) {
437
+ $page_content = self::_process_optional_upload_mime( $_REQUEST['mla_item_ID'] );
438
+ } else {
439
+ $page_content = array(
440
+ /* translators: 1: view name/slug */
441
+ 'message' => sprintf( __( 'Edit view "%1$s" cancelled.', 'media-library-assistant' ), $_REQUEST['mla_upload_item']['original_slug'] ),
442
+ 'body' => ''
443
+ );
444
+ }
445
+ break;
446
+ default:
447
+ $page_content = array(
448
+ /* translators: 1: bulk_action, e.g., single_item_delete, single_item_edit */
449
+ 'message' => sprintf( __( 'Unknown mla_admin_action - "%1$s"', 'media-library-assistant' ), $_REQUEST['mla_admin_action'] ),
450
+ 'body' => ''
451
+ );
452
+ break;
453
+ } // switch ($_REQUEST['mla_admin_action'])
454
+ } // (!empty($_REQUEST['mla_admin_action'])
455
+
456
+ if ( !empty( $page_content['body'] ) ) {
457
+ return $page_content;
458
+ }
459
+
460
+ /*
461
+ * Check for disabled status
462
+ */
463
+ if ( 'checked' != MLACore::mla_get_option( MLACoreOptions::MLA_ENABLE_UPLOAD_MIMES ) ) {
464
+ /*
465
+ * Fill in with any page-level options
466
+ */
467
+ $options_list = '';
468
+ foreach ( MLACoreOptions::$mla_option_definitions as $key => $value ) {
469
+ if ( 'upload' == $value['tab'] ) {
470
+ $options_list .= MLASettings::mla_compose_option_row( $key, $value );
471
+ }
472
+ }
473
+
474
+ $page_values = array(
475
+
476
+ 'Support is disabled' => __( 'Upload MIME Type Support is disabled', 'media-library-assistant' ),
477
+ 'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-upload&mla_tab=upload',
478
+ 'options_list' => $options_list,
479
+ 'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
480
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
481
+ );
482
+
483
+ $page_content['body'] .= MLAData::mla_parse_template( $page_template_array['upload-disabled'], $page_values );
484
+ return $page_content;
485
+ }
486
+
487
+ /*
488
+ * Display the Upload MIME Types Table
489
+ */
490
+ $_SERVER['REQUEST_URI'] = remove_query_arg( array(
491
+ 'mla_admin_action',
492
+ 'mla_item_slug',
493
+ 'mla_item_ID',
494
+ '_wpnonce',
495
+ '_wp_http_referer',
496
+ 'action',
497
+ 'action2',
498
+ 'cb_mla_item_ID',
499
+ 'mla-optional-uploads-search',
500
+ ), $_SERVER['REQUEST_URI'] );
501
+
502
+ // Create an instance of our package class
503
+ $MLAListUploadTable = new MLA_Upload_List_Table();
504
+
505
+ // Fetch, prepare, sort, and filter our data
506
+ $MLAListUploadTable->prepare_items();
507
+
508
+ /*
509
+ * Start with any page-level options
510
+ */
511
+ $options_list = '';
512
+ foreach ( MLACoreOptions::$mla_option_definitions as $key => $value ) {
513
+ if ( 'upload' == $value['tab'] ) {
514
+ $options_list .= MLASettings::mla_compose_option_row( $key, $value );
515
+ }
516
+ }
517
+
518
+ $page_values = array(
519
+ 'File Extension Processing' => __( 'File Extension and MIME Type Processing', 'media-library-assistant' ),
520
+ 'In this tab' => __( 'In this tab you can manage the list of file extension/MIME Type associations, which are used by WordPress to decide what kind of files can be uploaded to the Media Library and to fill in the <strong><em>post_mime_type</em></strong> value. To upload a file, the file extension must be in this list and be active.', 'media-library-assistant' ),
521
+ /* translators: 1: Documentation hyperlink */
522
+ 'You can find' => sprintf( __( 'You can find more information about file extensions, MIME types and how WordPress uses them in the %1$s section of the Documentation or by clicking the <strong>"Help"</strong> tab in the upper-right corner of this screen.', 'media-library-assistant' ), '<a href="[+settingsURL+]?page=mla-settings-menu-documentation&amp;mla_tab=documentation#mla_uploads" title="' . __( 'File Extension Processing documentation', 'media-library-assistant' ) . '">' . __( 'File Extension and MIME Type Processing', 'media-library-assistant' ) . '</a>' ),
523
+ 'settingsURL' => admin_url('options-general.php'),
524
+ 'Search Uploads' => __( 'Search Uploads', 'media-library-assistant' ),
525
+ 'To search by' => __( 'To search by extension, use ".", e.g., ".doc"', 'media-library-assistant' ),
526
+ 'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-upload&mla_tab=upload',
527
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
528
+ 'options_list' => $options_list,
529
+ 'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
530
+ /* translators: %s: add new Upload MIME Type */
531
+ 'Add New Upload' => sprintf( __( 'Add New %1$s', 'media-library-assistant' ), __( 'Upload MIME Type', 'media-library-assistant' ) ),
532
+ 'To search database' => __( 'To search the database of over 1,500 known extension/type associations, click "Search Known Types" below the form.', 'media-library-assistant' ),
533
+ 'Extension' => __( 'Extension', 'media-library-assistant' ),
534
+ 'The extension is' => __( 'The &#8220;extension&#8221; is the file extension for this type, and unique key for the item. It must be all lowercase and contain only letters and numbers.', 'media-library-assistant' ),
535
+ 'MIME Type' => __( 'MIME Type', 'media-library-assistant' ),
536
+ 'The MIME Type' => __( 'The MIME Type must be all lowercase and contain only letters, numbers, periods (.), slashes (/) and hyphens (-). It <strong>must be a valid MIME</strong> type, e.g., &#8220;image&#8221; or &#8220;image/jpeg&#8221;.', 'media-library-assistant' ),
537
+ 'Icon Type' => __( 'Icon Type', 'media-library-assistant' ),
538
+ 'The Icon Type' => __( 'The Icon Type selects a thumbnail image displayed for non-image file types, such as PDF documents.', 'media-library-assistant' ),
539
+ 'Inactive' => __( 'Inactive', 'media-library-assistant' ),
540
+ 'Check this box' => __( 'Check this box if you want to remove this entry from the list of Upload MIME Types returned by get_allowed_mime_types().', 'media-library-assistant' ),
541
+ 'Description' => __( 'Description', 'media-library-assistant' ),
542
+ 'The description can' => __( 'The description can contain any documentation or notes you need to understand or use the item.', 'media-library-assistant' ),
543
+ 'Add Upload MIME' => __( 'Add Upload MIME Type', 'media-library-assistant' ),
544
+ 'search_url' => wp_nonce_url( '?page=mla-settings-menu-upload&mla_tab=upload&mla-optional-uploads-search=Search', MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ),
545
+ 'Search Known Types' => __( 'Search Known Types', 'media-library-assistant' ),
546
+ 'colspan' => $MLAListUploadTable->get_column_count(),
547
+ 'Quick Edit' => __( '<strong>Quick Edit</strong>', 'media-library-assistant' ),
548
+ 'Cancel' => __( 'Cancel', 'media-library-assistant' ),
549
+ 'Update' => __( 'Update', 'media-library-assistant' ),
550
+ 'Bulk Edit' => __( 'Bulk Edit', 'media-library-assistant' ),
551
+ 'Status' => __( 'Status', 'media-library-assistant' ),
552
+ 'No Change' => __( 'No Change', 'media-library-assistant' ),
553
+ 'Active' => __( 'Active', 'media-library-assistant' ),
554
+ 'results' => ! empty( $_REQUEST['s'] ) ? '<h2 class="alignleft">' . __( 'Displaying search results for', 'media-library-assistant' ) . ': "' . $_REQUEST['s'] . '"</h2>' : '',
555
+ 's' => isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '',
556
+ 'icon_types' => self::_get_icon_type_dropdown( $page_template_array, 'mla_upload_item[icon_type]' ),
557
+ 'inline_icon_types' => self::_get_icon_type_dropdown( $page_template_array, 'icon_type' ),
558
+ 'bulk_icon_types' => self::_get_icon_type_dropdown( $page_template_array, 'icon_type', '.nochange.' ),
559
+ );
560
+
561
+ foreach ( $add_form_values as $key => $value ) {
562
+ $page_values[ $key ] = $value;
563
+ }
564
+ $page_content['body'] = MLAData::mla_parse_template( $page_template_array['before-table'], $page_values );
565
+
566
+ // Now we can render the completed list table
567
+ ob_start();
568
+ $MLAListUploadTable->views();
569
+ $MLAListUploadTable->display();
570
+ $page_content['body'] .= ob_get_contents();
571
+ ob_end_clean();
572
+
573
+ $page_content['body'] .= MLAData::mla_parse_template( $page_template_array['after-table'], $page_values );
574
+
575
+ return $page_content;
576
+ } // mla_compose_upload_tab
577
+
578
+ /**
579
+ * Ajax handler for Upload MIME Types inline editing (quick and bulk edit)
580
+ *
581
+ * Adapted from wp_ajax_inline_save in /wp-admin/includes/ajax-actions.php
582
+ *
583
+ * @since 1.40
584
+ *
585
+ * @return void echo HTML <tr> markup for updated row or error message, then die()
586
+ */
587
+ public static function mla_inline_edit_upload_action() {
588
+ set_current_screen( $_REQUEST['screen'] );
589
+
590
+ check_ajax_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
591
+
592
+ if ( empty( $_REQUEST['original_slug'] ) ) {
593
+ echo __( 'ERROR', 'media-library-assistant' ) . ': ' . __( 'No upload slug found', 'media-library-assistant' );
594
+ die();
595
+ }
596
+
597
+ $request = array( 'original_slug' => $_REQUEST['original_slug'] );
598
+ $request['slug'] = $_REQUEST['slug'];
599
+ $request['mime_type'] = $_REQUEST['mime_type'];
600
+ $request['icon_type'] = $_REQUEST['icon_type'];
601
+ $request['disabled'] = isset( $_REQUEST['disabled'] ) && ( '1' == $_REQUEST['disabled'] );
602
+ $results = MLAMime::mla_update_upload_mime( $request );
603
+
604
+ if ( false === strpos( $results['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
605
+ $new_item = (object) MLAMime::mla_get_upload_mime( $_REQUEST['slug'] );
606
+ } else {
607
+ $new_item = (object) MLAMime::mla_get_upload_mime( $_REQUEST['original_slug'] );
608
+ }
609
+ $new_item->post_ID = $_REQUEST['post_ID'];
610
+
611
+ // Create an instance of our package class and echo the new HTML
612
+ $MLAListUploadTable = new MLA_Upload_List_Table();
613
+ $MLAListUploadTable->single_row( $new_item );
614
+ die(); // this is required to return a proper result
615
+ } // mla_inline_edit_upload_action
616
+ } // MLASettings_Upload
617
+
618
+ /*
619
+ * The WP_List_Table class isn't automatically available to plugins
620
+ */
621
+ if ( !class_exists( 'WP_List_Table' ) ) {
622
+ require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
623
+ }
624
+
625
+ /**
626
+ * Class MLA (Media Library Assistant) Upload List Table implements the "Upload"
627
+ * admin settings tab
628
+ *
629
+ * Extends the core WP_List_Table class.
630
+ *
631
+ * @package Media Library Assistant
632
+ * @since 1.40
633
+ */
634
+ class MLA_Upload_List_Table extends WP_List_Table {
635
+ /**
636
+ * Initializes some properties from $_REQUEST variables, then
637
+ * calls the parent constructor to set some default configs.
638
+ *
639
+ * @since 1.40
640
+ *
641
+ * @return void
642
+ */
643
+ function __construct( ) {
644
+ // MLA does not use this
645
+ $this->modes = array(
646
+ 'list' => __( 'List View' ),
647
+ );
648
+
649
+ //Set parent defaults
650
+ parent::__construct( array(
651
+ 'singular' => 'upload_type', //singular name of the listed records
652
+ 'plural' => 'upload_types', //plural name of the listed records
653
+ 'ajax' => true, //does this table support ajax?
654
+ 'screen' => 'settings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-upload'
655
+ ) );
656
+
657
+ // NOTE: There is one add_action call at the end of this source file.
658
+ }
659
+
660
+ /**
661
+ * Default values for hidden columns
662
+ *
663
+ * This array is used when the user-level option is not set, i.e.,
664
+ * the user has not altered the selection of hidden columns.
665
+ *
666
+ * The value on the right-hand side must match the column slug, e.g.,
667
+ * array(0 => 'ID_parent, 1 => 'title_name').
668
+ *
669
+ * @since 1.40
670
+ *
671
+ * @var array
672
+ */
673
+ private static $default_hidden_columns = array(
674
+ // 'name',
675
+ // 'mime_type',
676
+ 'icon_type',
677
+ // 'source',
678
+ // 'status',
679
+ 'core_type',
680
+ 'mla_type',
681
+ 'standard_source',
682
+ 'core_icon_type',
683
+ 'description'
684
+ );
685
+
686
+ /**
687
+ * Access the default list of hidden columns
688
+ *
689
+ * @since 1.40
690
+ *
691
+ * @return array default list of hidden columns
692
+ */
693
+ private static function _default_hidden_columns( ) {
694
+ return self::$default_hidden_columns;
695
+ }
696
+
697
+ /**
698
+ * Handler for filter 'get_user_option_managesettings_page_mla-settings-menu-uploadcolumnshidden'
699
+ *
700
+ * Required because the screen.php get_hidden_columns function only uses
701
+ * the get_user_option result. Set when the file is loaded because the object
702
+ * is not created in time for the call from screen.php.
703
+ *
704
+ * @since 1.40
705
+ *
706
+ * @param mixed false or array with current list of hidden columns, if any
707
+ * @param string 'managesettings_page_mla-settings-menucolumnshidden'
708
+ * @param object WP_User object, if logged in
709
+ *
710
+ * @return array updated list of hidden columns
711
+ */
712
+ public static function mla_manage_hidden_columns_filter( $result, $option, $user_data ) {
713
+ return $result ? $result : self::_default_hidden_columns();
714
+ }
715
+
716
+ /**
717
+ * Handler for filter 'manage_settings_page_mla-settings-menu_columns'
718
+ *
719
+ * This required filter dictates the table's columns and titles. Set when the
720
+ * file is loaded because the list_table object isn't created in time
721
+ * to affect the "screen options" setup.
722
+ *
723
+ * @since 1.40
724
+ *
725
+ * @return array list of table columns
726
+ */
727
+ public static function mla_manage_columns_filter( ) {
728
+ /*
729
+ * For WP 4.3+ icon will be merged with the Extension/name column
730
+ */
731
+ if ( MLATest::$wp_4dot3_plus ) {
732
+ unset( MLAMime::$default_upload_columns['icon'] );
733
+ }
734
+
735
+ return MLAMime::$default_upload_columns;
736
+ }
737
+
738
+ /**
739
+ * Print optional in-lne styles for Uploads submenu table
740
+ *
741
+ * @since 2.14
742
+ */
743
+ public static function mla_admin_print_styles_action() {
744
+ if ( MLATest::$wp_4dot3_plus ) {
745
+ echo "<style type='text/css'>\n";
746
+
747
+ // Any icon_type will do
748
+ $image_info = MLAMime::mla_get_icon_type_size( 'image' );
749
+
750
+ /*
751
+ * Primary column including icon and some margin
752
+ */
753
+ $icon_width = ( $image_info['width'] + 10 ) . 'px';
754
+ $icon_height = ( $image_info['height'] + 5 ) . 'px';
755
+
756
+ echo " table.upload_types td.column-primary {\n";
757
+ echo " position: relative;\n";
758
+ echo " }\n";
759
+ echo " table.upload_types div.upload_types-icon {\n";
760
+ echo " position: absolute;\n";
761
+ echo " top: 8px;\n";
762
+ echo " left: 10px;\n";
763
+ echo " }\n";
764
+ echo " table.upload_types div.upload_types-info {\n";
765
+ echo " margin-left: {$icon_width};\n";
766
+ echo " min-height: {$icon_height};\n";
767
+ echo " }\n";
768
+
769
+ echo "</style>\n";
770
+ }
771
+ }
772
+
773
+ /**
774
+ * Called in the admin_init action because the list_table object isn't
775
+ * created in time to affect the "screen options" setup.
776
+ *
777
+ * @since 1.40
778
+ *
779
+ * @return void
780
+ */
781
+ public static function mla_admin_init( ) {
782
+ if ( isset( $_REQUEST['mla-optional-uploads-display'] ) || isset( $_REQUEST['mla-optional-uploads-search'] ) ) {
783
+ return;
784
+ }
785
+
786
+ if ( isset( $_REQUEST['mla_tab'] ) && $_REQUEST['mla_tab'] == 'upload' ) {
787
+ add_filter( 'get_user_option_managesettings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-uploadcolumnshidden', 'MLA_Upload_list_Table::mla_manage_hidden_columns_filter', 10, 3 );
788
+ add_filter( 'manage_settings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-upload_columns', 'MLA_Upload_list_Table::mla_manage_columns_filter', 10, 0 );
789
+ add_action( 'admin_print_styles', 'MLA_Upload_List_Table::mla_admin_print_styles_action' );
790
+ }
791
+ }
792
+
793
+ /**
794
+ * Checks the current user's permissions
795
+ *
796
+ * @since 2.14
797
+ *
798
+ * @return bool
799
+ */
800
+ public function ajax_user_can() {
801
+ return current_user_can('manage_options');
802
+ }
803
+
804
+ /**
805
+ * Get the name of the default primary column.
806
+ *
807
+ * @since 2.14
808
+ * @access protected
809
+ *
810
+ * @return string Name of the default primary column
811
+ */
812
+ protected function get_default_primary_column_name() {
813
+ return 'name';
814
+ }
815
+
816
+ /**
817
+ * Generate and display row actions links.
818
+ *
819
+ * @since 2.14
820
+ * @access protected
821
+ *
822
+ * @param object $item Attachment being acted upon.
823
+ * @param string $column_name Current column name.
824
+ * @param string $primary Primary column name.
825
+ * @return string Row actions output for media attachments.
826
+ */
827
+ protected function handle_row_actions( $item, $column_name, $primary ) {
828
+ if ( $primary === $column_name ) {
829
+ $actions = $this->row_actions( $this->_build_rollover_actions( $item, $column_name ) );
830
+ $actions .= $this->_build_inline_data( $item );
831
+ return $actions;
832
+ }
833
+
834
+ return '';
835
+ }
836
+
837
+ /**
838
+ * Supply a column value if no column-specific function has been defined
839
+ *
840
+ * Called when the parent class can't find a method specifically built for a
841
+ * given column. All columns should have a specific method, so this function
842
+ * returns a troubleshooting message.
843
+ *
844
+ * @since 1.40
845
+ *
846
+ * @param array A singular item (one full row's worth of data)
847
+ * @param array The name/slug of the column to be processed
848
+ * @return string Text or HTML to be placed inside the column
849
+ */
850
+ function column_default( $item, $column_name ) {
851
+ //Show the whole array for troubleshooting purposes
852
+ /* translators: 1: column_name 2: column_values */
853
+ return sprintf( __( 'column_default: %1$s, %2$s', 'media-library-assistant' ), $column_name, print_r( $item, true ) );
854
+ }
855
+
856
+ /**
857
+ * Displays checkboxes for using bulk actions. The 'cb' column
858
+ * is given special treatment when columns are processed.
859
+ *
860
+ * @since 1.40
861
+ *
862
+ * @param object An MLA upload_type object
863
+ * @return string HTML markup to be placed inside the column
864
+ */
865
+ function column_cb( $item ) {
866
+ return sprintf( '<input type="checkbox" name="cb_mla_item_ID[]" value="%1$s" />',
867
+ /*%1$s*/ $item->post_ID
868
+ );
869
+ }
870
+
871
+ /**
872
+ * Supply the content for a custom column
873
+ *
874
+ * @since 0.1
875
+ *
876
+ * @param array A singular attachment (post) object
877
+ * @return string HTML markup to be placed inside the column
878
+ */
879
+ function column_icon( $item ) {
880
+ return MLAMime::mla_get_icon_type_image( $item->icon_type );
881
+ }
882
+
883
+ /**
884
+ * Add rollover actions to a table column
885
+ *
886
+ * @since 1.40
887
+ *
888
+ * @param object An MLA upload_type object
889
+ * @param string Current column name
890
+ *
891
+ * @return array Names and URLs of row-level actions
892
+ */
893
+ private function _build_rollover_actions( $item, $column ) {
894
+ $actions = array();
895
+
896
+ /*
897
+ * Compose view arguments
898
+ */
899
+
900
+ $view_args = array(
901
+ 'page' => MLACoreOptions::MLA_SETTINGS_SLUG . '-upload',
902
+ 'mla_tab' => 'upload',
903
+ 'mla_item_slug' => urlencode( $item->slug )
904
+ );
905
+
906
+ if ( isset( $_REQUEST['paged'] ) ) {
907
+ $view_args['paged'] = $_REQUEST['paged'];
908
+ }
909
+
910
+ if ( isset( $_REQUEST['order'] ) ) {
911
+ $view_args['order'] = $_REQUEST['order'];
912
+ }
913
+
914
+ if ( isset( $_REQUEST['orderby'] ) ) {
915
+ $view_args['orderby'] = $_REQUEST['orderby'];
916
+ }
917
+
918
+ $actions['edit'] = '<a href="' . add_query_arg( $view_args, wp_nonce_url( '?mla_admin_action=' . MLACore::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>';
919
+
920
+ $actions['inline hide-if-no-js'] = '<a class="editinline" href="#" title="' . __( 'Edit this item inline', 'media-library-assistant' ) . '">' . __( 'Quick Edit', 'media-library-assistant' ) . '</a>';
921
+
922
+ if ( 'custom' == $item->source ) {
923
+ if ( empty( $item->standard_source ) ) {
924
+ $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>';
925
+ } else {
926
+ $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>';
927
+ }
928
+ }
929
+
930
+ return $actions;
931
+ }
932
+
933
+ /**
934
+ * Add hidden fields with the data for use in the inline editor
935
+ *
936
+ * @since 1.40
937
+ *
938
+ * @param object An MLA upload_type object
939
+ *
940
+ * @return string HTML <div> with row data
941
+ */
942
+ private function _build_inline_data( $item ) {
943
+ $inline_data = "\r\n" . '<div class="hidden" id="inline_' . $item->post_ID . "\">\r\n";
944
+ $inline_data .= ' <div class="original_slug">' . esc_attr( $item->slug ) . "</div>\r\n";
945
+ $inline_data .= ' <div class="slug">' . esc_attr( $item->slug ) . "</div>\r\n";
946
+ $inline_data .= ' <div class="mime_type">' . esc_attr( $item->mime_type ) . "</div>\r\n";
947
+ $inline_data .= ' <div class="icon_type">' . esc_attr( $item->icon_type ) . "</div>\r\n";
948
+ $inline_data .= ' <div class="core_type">' . esc_attr( $item->core_type ) . "</div>\r\n";
949
+ $inline_data .= ' <div class="mla_type">' . esc_attr( $item->mla_type ) . "</div>\r\n";
950
+ $inline_data .= ' <div class="source">' . esc_attr( $item->source ) . "</div>\r\n";
951
+ $inline_data .= ' <div class="standard_source">' . esc_attr( $item->standard_source ) . "</div>\r\n";
952
+ $inline_data .= ' <div class="disabled">' . esc_attr( $item->disabled ) . "</div>\r\n";
953
+ $inline_data .= ' <div class="description">' . esc_attr( $item->description ) . "</div>\r\n";
954
+ $inline_data .= ' <div class="wp_icon_type">' . esc_attr( $item->wp_icon_type ) . "</div>\r\n";
955
+ $inline_data .= ' <div class="mla_icon_type">' . esc_attr( $item->mla_icon_type ) . "</div>\r\n";
956
+ $inline_data .= ' <div class="core_icon_type">' . esc_attr( $item->core_icon_type ) . "</div>\r\n";
957
+ $inline_data .= "</div>\r\n";
958
+ return $inline_data;
959
+ }
960
+
961
+ /**
962
+ * Supply the content for a custom column
963
+ *
964
+ * @since 1.40
965
+ *
966
+ * @param object An MLA upload_type object
967
+ * @return string HTML markup to be placed inside the column
968
+ */
969
+ function column_name( $item ) {
970
+ if ( MLATest::$wp_4dot3_plus ) {
971
+ $content = "<div class=\"upload_types-icon\">\n";
972
+ $content .= self::column_icon( $item );
973
+ $content .= "\n</div>\n";
974
+ $content .= '<div class="upload_types-info">' . esc_attr( $item->slug ) . "</div>\n";
975
+ return $content;
976
+ }
977
+
978
+ $row_actions = self::_build_rollover_actions( $item, 'name' );
979
+ $slug = esc_attr( $item->slug );
980
+ return sprintf( '%1$s<br>%2$s%3$s', /*%1$s*/ $slug, /*%2$s*/ $this->row_actions( $row_actions ), /*%3$s*/ $this->_build_inline_data( $item ) );
981
+ }
982
+
983
+ /**
984
+ * Supply the content for a custom column
985
+ *
986
+ * @since 1.40
987
+ *
988
+ * @param object An MLA upload_type object
989
+ * @return string HTML markup to be placed inside the column
990
+ */
991
+ function column_mime_type( $item ) {
992
+ return esc_attr( $item->mime_type );
993
+ }
994
+
995
+ /**
996
+ * Supply the content for a custom column
997
+ *
998
+ * @since 1.40
999
+ *
1000
+ * @param object An MLA upload_type object
1001
+ * @return string HTML markup to be placed inside the column
1002
+ */
1003
+ function column_icon_type( $item ) {
1004
+ return esc_attr( $item->icon_type );
1005
+ }
1006
+
1007
+ /**
1008
+ * Supply the content for a custom column
1009
+ *
1010
+ * @since 1.40
1011
+ *
1012
+ * @param object An MLA upload_type object
1013
+ * @return string HTML markup to be placed inside the column
1014
+ */
1015
+ function column_source( $item ) {
1016
+ return esc_attr( $item->source );
1017
+ }
1018
+
1019
+ /**
1020
+ * Supply the content for a custom column
1021
+ *
1022
+ * @since 1.40
1023
+ *
1024
+ * @param object An MLA upload_type object
1025
+ * @return string HTML markup to be placed inside the column
1026
+ */
1027
+ function column_status( $item ) {
1028
+ if ( $item->disabled ) {
1029
+ return __( 'Inactive', 'media-library-assistant' );
1030
+ } else {
1031
+ return __( 'Active', 'media-library-assistant' );
1032
+ }
1033
+ }
1034
+
1035
+ /**
1036
+ * Supply the content for a custom column
1037
+ *
1038
+ * @since 1.40
1039
+ *
1040
+ * @param object An MLA upload_type object
1041
+ * @return string HTML markup to be placed inside the column
1042
+ */
1043
+ function column_core_type( $item ) {
1044
+ return esc_attr( $item->core_type );
1045
+ }
1046
+
1047
+ /**
1048
+ * Supply the content for a custom column
1049
+ *
1050
+ * @since 1.40
1051
+ *
1052
+ * @param object An MLA upload_type object
1053
+ * @return string HTML markup to be placed inside the column
1054
+ */
1055
+ function column_mla_type( $item ) {
1056
+ return esc_attr( $item->mla_type );
1057
+ }
1058
+
1059
+ /**
1060
+ * Supply the content for a custom column
1061
+ *
1062
+ * @since 1.40
1063
+ *
1064
+ * @param object An MLA upload_type object
1065
+ * @return string HTML markup to be placed inside the column
1066
+ */
1067
+ function column_standard_source( $item ) {
1068
+ return (string) $item->standard_source;
1069
+ }
1070
+
1071
+ /**
1072
+ * Supply the content for a custom column
1073
+ *
1074
+ * @since 1.40
1075
+ *
1076
+ * @param object An MLA upload_type object
1077
+ * @return string HTML markup to be placed inside the column
1078
+ */
1079
+ function column_core_icon_type( $item ) {
1080
+ return esc_attr( $item->core_icon_type );
1081
+ }
1082
+
1083
+ /**
1084
+ * Supply the content for a custom column
1085
+ *
1086
+ * @since 1.40
1087
+ *
1088
+ * @param object An MLA upload_type object
1089
+ * @return string HTML markup to be placed inside the column
1090
+ */
1091
+ function column_description( $item ) {
1092
+ return esc_attr( $item->description );
1093
+ }
1094
+
1095
+ /**
1096
+ * This method dictates the table's columns and titles
1097
+ *
1098
+ * @since 1.40
1099
+ *
1100
+ * @return array Column information: 'slugs'=>'Visible Titles'
1101
+ */
1102
+ function get_columns( ) {
1103
+ return MLA_Upload_list_Table::mla_manage_columns_filter();
1104
+ }
1105
+
1106
+ /**
1107
+ * Returns the list of currently hidden columns from a user option or
1108
+ * from default values if the option is not set
1109
+ *
1110
+ * @since 1.40
1111
+ *
1112
+ * @return array Column information,e.g., array(0 => 'ID_parent, 1 => 'title_name')
1113
+ */
1114
+ function get_hidden_columns( ) {
1115
+ $columns = get_user_option( 'managesettings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-uploadcolumnshidden' );
1116
+
1117
+ if ( is_array( $columns ) ) {
1118
+ return $columns;
1119
+ }
1120
+
1121
+ return self::_default_hidden_columns();
1122
+ }
1123
+
1124
+ /**
1125
+ * Returns an array where the key is the column that needs to be sortable
1126
+ * and the value is db column to sort by. Also notes the current sort column,
1127
+ * if set.
1128
+ *
1129
+ * @since 1.40
1130
+ *
1131
+ * @return array Sortable column information,e.g.,
1132
+ * 'slugs'=>array('data_values',boolean)
1133
+ */
1134
+ function get_sortable_columns( ) {
1135
+ $columns = MLAMime::$default_sortable_upload_columns;
1136
+
1137
+ if ( isset( $_REQUEST['orderby'] ) ) {
1138
+ $needle = array( $_REQUEST['orderby'], false );
1139
+ $key = array_search( $needle, $columns );
1140
+ if ( $key ) {
1141
+ $columns[ $key ][ 1 ] = true;
1142
+ }
1143
+ } else {
1144
+ $columns['name'][ 1 ] = true;
1145
+ }
1146
+
1147
+ return $columns;
1148
+ }
1149
+
1150
+ /**
1151
+ * Returns HTML markup for one view that can be used with this table
1152
+ *
1153
+ * @since 1.40
1154
+ *
1155
+ * @param string View slug
1156
+ * @param array count and labels for the View
1157
+ * @param string Slug for current view
1158
+ *
1159
+ * @return string | false HTML for link to display the view, false if count = zero
1160
+ */
1161
+ function _get_view( $view_slug, $upload_item, $current_view ) {
1162
+ static $base_url = NULL;
1163
+
1164
+ $class = ( $view_slug == $current_view ) ? ' class="current"' : '';
1165
+
1166
+ /*
1167
+ * Calculate the common values once per page load
1168
+ */
1169
+ if ( is_null( $base_url ) ) {
1170
+ /*
1171
+ * Remember the view filters
1172
+ */
1173
+ $base_url = 'options-general.php?page=' . MLACoreOptions::MLA_SETTINGS_SLUG . '-upload&mla_tab=upload';
1174
+
1175
+ if ( isset( $_REQUEST['s'] ) ) {
1176
+ $base_url = add_query_arg( array( 's' => $_REQUEST['s'] ), $base_url );
1177
+ }
1178
+ }
1179
+
1180
+ $singular = sprintf('%s <span class="count">(%%s)</span>', $upload_item['singular'] );
1181
+ $plural = sprintf('%s <span class="count">(%%s)</span>', $upload_item['plural'] );
1182
+ $nooped_plural = _n_noop( $singular, $plural, 'media-library-assistant' );
1183
+ return "<a href='" . add_query_arg( array( 'mla_upload_view' => $view_slug ), $base_url )
1184
+ . "'$class>" . sprintf( translate_nooped_plural( $nooped_plural, $upload_item['count'], 'media-library-assistant' ), number_format_i18n( $upload_item['count'] ) ) . '</a>';
1185
+ } // _get_view
1186
+
1187
+ /**
1188
+ * Returns an associative array listing all the views that can be used with this table.
1189
+ * These are listed across the top of the page and managed by WordPress.
1190
+ *
1191
+ * @since 1.40
1192
+ *
1193
+ * @return array View information,e.g., array ( id => link )
1194
+ */
1195
+ function get_views( ) {
1196
+ // Find current view
1197
+ $current_view = isset( $_REQUEST['mla_upload_view'] ) ? $_REQUEST['mla_upload_view'] : 'all';
1198
+
1199
+ // Generate the list of views, retaining keyword search criterion
1200
+ $s = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
1201
+ $upload_items = MLAMime::mla_tabulate_upload_items( $s );
1202
+ $view_links = array();
1203
+ foreach ( $upload_items as $slug => $item )
1204
+ $view_links[ $slug ] = self::_get_view( $slug, $item, $current_view );
1205
+
1206
+ return $view_links;
1207
+ }
1208
+
1209
+ /**
1210
+ * Get an associative array ( option_name => option_title ) with the list
1211
+ * of bulk actions available on this table.
1212
+ *
1213
+ * @since 1.40
1214
+ *
1215
+ * @return array Contains all the bulk actions: 'slugs'=>'Visible Titles'
1216
+ */
1217
+ function get_bulk_actions( ) {
1218
+ $actions = array();
1219
+
1220
+ $actions['edit'] = __( 'Edit', 'media-library-assistant' );
1221
+ $actions['delete'] = __( 'Delete/Revert Custom', 'media-library-assistant' );
1222
+
1223
+ return $actions;
1224
+ }
1225
+
1226
+ /**
1227
+ * Prepares the list of items for displaying
1228
+ *
1229
+ * This is where you prepare your data for display. This method will usually
1230
+ * be used to query the database, sort and filter the data, and generally
1231
+ * get it ready to be displayed. At a minimum, we should set $this->items and
1232
+ * $this->set_pagination_args().
1233
+ *
1234
+ * @since 1.40
1235
+ *
1236
+ * @return void
1237
+ */
1238
+ function prepare_items( ) {
1239
+ $this->_column_headers = array(
1240
+ $this->get_columns(),
1241
+ $this->get_hidden_columns(),
1242
+ $this->get_sortable_columns()
1243
+ );
1244
+
1245
+ $total_items = MLAMime::mla_count_upload_items( $_REQUEST );
1246
+ $user = get_current_user_id();
1247
+ $screen = get_current_screen();
1248
+ $option = $screen->get_option( 'per_page', 'option' );
1249
+ if ( is_string( $option ) ) {
1250
+ $per_page = get_user_meta( $user, $option, true );
1251
+ } else {
1252
+ $per_page = 10;
1253
+ }
1254
+
1255
+ if ( empty( $per_page ) || $per_page < 1 ) {
1256
+ $per_page = $screen->get_option( 'per_page', 'default' );
1257
+ }
1258
+
1259
+ // Register our pagination options & calculations.
1260
+ $this->set_pagination_args( array(
1261
+ 'total_items' => $total_items,
1262
+ 'per_page' => $per_page,
1263
+ 'total_pages' => ceil( $total_items / $per_page )
1264
+ ) );
1265
+
1266
+ $current_page = $this->get_pagenum();
1267
+
1268
+ // Assign sorted and paginated data to the items property
1269
+ $this->items = MLAMime::mla_query_upload_items( $_REQUEST, ( ( $current_page - 1 ) * $per_page ), $per_page );
1270
+ }
1271
+
1272
+ /**
1273
+ * Generates (echoes) content for a single row of the table
1274
+ *
1275
+ * @since 1.40
1276
+ *
1277
+ * @param object the current item
1278
+ *
1279
+ * @return void Echoes the row HTML
1280
+ */
1281
+ function single_row( $item ) {
1282
+ static $row_class = '';
1283
+ $row_class = ( $row_class == '' ? ' class="alternate"' : '' );
1284
+
1285
+ echo '<tr id="upload-' . $item->post_ID . '"' . $row_class . '>';
1286
+ echo parent::single_row_columns( $item );
1287
+ echo '</tr>';
1288
+ }
1289
+ } // class MLA_Upload_List_Table
1290
+
1291
+ /**
1292
+ * Class MLA (Media Library Assistant) Upload Optional List Table implements the
1293
+ * searchable database of exension/type associations for the "Uploads" admin settings tab
1294
+ *
1295
+ * Extends the core WP_List_Table class.
1296
+ *
1297
+ * @package Media Library Assistant
1298
+ * @since 1.40
1299
+ */
1300
+ class MLA_Upload_Optional_List_Table extends WP_List_Table {
1301
+ /**
1302
+ * Initializes some properties from $_REQUEST variables, then
1303
+ * calls the parent constructor to set some default configs.
1304
+ *
1305
+ * @since 1.40
1306
+ *
1307
+ * @return void
1308
+ */
1309
+ function __construct( ) {
1310
+ //Set parent defaults
1311
+ parent::__construct( array(
1312
+ 'singular' => 'optional_upload_type', //singular name of the listed records
1313
+ 'plural' => 'optional_upload_types', //plural name of the listed records
1314
+ 'ajax' => false, //does this table support ajax?
1315
+ 'screen' => 'settings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-upload'
1316
+ ) );
1317
+
1318
+ /*
1319
+ * NOTE: There is one add_action call at the end of this source file.
1320
+ */
1321
+ }
1322
+
1323
+ /**
1324
+ * Default values for hidden columns
1325
+ *
1326
+ * This array is used when the user-level option is not set, i.e.,
1327
+ * the user has not altered the selection of hidden columns.
1328
+ *
1329
+ * The value on the right-hand side must match the column slug, e.g.,
1330
+ * array(0 => 'ID_parent, 1 => 'title_name').
1331
+ *
1332
+ * @since 1.40
1333
+ *
1334
+ * @var array
1335
+ */
1336
+ private static $default_hidden_columns = array(
1337
+ // 'name',
1338
+ // 'mime_type',
1339
+ // 'core_type',
1340
+ // 'mla_type',
1341
+ // 'description'
1342
+ );
1343
+
1344
+ /**
1345
+ * Access the default list of hidden columns
1346
+ *
1347
+ * @since 1.40
1348
+ *
1349
+ * @return array default list of hidden columns
1350
+ */
1351
+ private static function _default_hidden_columns( ) {
1352
+ return self::$default_hidden_columns;
1353
+ }
1354
+
1355
+ /**
1356
+ * Handler for filter 'get_user_option_managesettings_page_mla-settings-menu-uploadcolumnshidden'
1357
+ *
1358
+ * Required because the screen.php get_hidden_columns function only uses
1359
+ * the get_user_option result. Set when the file is loaded because the object
1360
+ * is not created in time for the call from screen.php.
1361
+ *
1362
+ * @since 1.40
1363
+ *
1364
+ * @param mixed false or array with current list of hidden columns, if any
1365
+ * @param string 'managesettings_page_mla-settings-menucolumnshidden'
1366
+ * @param object WP_User object, if logged in
1367
+ *
1368
+ * @return array updated list of hidden columns
1369
+ */
1370
+ public static function mla_manage_hidden_columns_filter( $result, $option, $user_data ) {
1371
+ return $result ? $result : self::_default_hidden_columns();
1372
+ }
1373
+
1374
+ /**
1375
+ * Handler for filter 'manage_settings_page_mla-settings-menu_columns'
1376
+ *
1377
+ * This required filter dictates the table's columns and titles. Set when the
1378
+ * file is loaded because the list_table object isn't created in time
1379
+ * to affect the "screen options" setup.
1380
+ *
1381
+ * @since 1.40
1382
+ *
1383
+ * @return array list of table columns
1384
+ */
1385
+ public static function mla_manage_columns_filter( ) {
1386
+ return MLAMime::$default_upload_optional_columns;
1387
+ }
1388
+
1389
+ /**
1390
+ * Called in the admin_init action because the list_table object isn't
1391
+ * created in time to affect the "screen options" setup.
1392
+ *
1393
+ * @since 1.40
1394
+ *
1395
+ * @return void
1396
+ */
1397
+ public static function mla_admin_init( ) {
1398
+ if ( isset( $_REQUEST['mla-optional-uploads-display'] ) || isset( $_REQUEST['mla-optional-uploads-search'] ) ) {
1399
+ add_filter( 'get_user_option_managesettings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-uploadcolumnshidden', 'MLA_Upload_Optional_List_Table::mla_manage_hidden_columns_filter', 10, 3 );
1400
+ add_filter( 'manage_settings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-upload_columns', 'MLA_Upload_Optional_List_Table::mla_manage_columns_filter', 10, 0 );
1401
+ }
1402
+ }
1403
+
1404
+ /**
1405
+ * Supply a column value if no column-specific function has been defined
1406
+ *
1407
+ * Called when the parent class can't find a method specifically built for a
1408
+ * given column. All columns should have a specific method, so this function
1409
+ * returns a troubleshooting message.
1410
+ *
1411
+ * @since 1.40
1412
+ *
1413
+ * @param array A singular item (one full row's worth of data)
1414
+ * @param array The name/slug of the column to be processed
1415
+ * @return string Text or HTML to be placed inside the column
1416
+ */
1417
+ function column_default( $item, $column_name ) {
1418
+ //Show the whole array for troubleshooting purposes
1419
+ /* translators: 1: column_name 2: column_values */
1420
+ return sprintf( __( 'column_default: %1$s, %2$s', 'media-library-assistant' ), $column_name, print_r( $item, true ) );
1421
+ }
1422
+
1423
+ /**
1424
+ * Displays checkboxes for using bulk actions. The 'cb' column
1425
+ * is given special treatment when columns are processed.
1426
+ *
1427
+ * @since 1.40
1428
+ *
1429
+ * @param object An MLA post_mime_type object
1430
+ * @return string HTML markup to be placed inside the column
1431
+ */
1432
+ function column_cb( $item ) {
1433
+ return sprintf( '<input type="checkbox" name="cb_mla_item_ID[]" value="%1$s" />',
1434
+ /*%1$s*/ $item->ID
1435
+ );
1436
+ }
1437
+
1438
+ /**
1439
+ * Add rollover actions to a table column
1440
+ *
1441
+ * @since 1.40
1442
+ *
1443
+ * @param object An MLA post_mime_type object
1444
+ * @param string Current column name
1445
+ *
1446
+ * @return array Names and URLs of row-level actions
1447
+ */
1448
+ private function _build_rollover_actions( $item, $column ) {
1449
+ $actions = array();
1450
+
1451
+ /*
1452
+ * Compose view arguments
1453
+ */
1454
+
1455
+ $view_args = array(
1456
+ 'page' => MLACoreOptions::MLA_SETTINGS_SLUG . '-upload',
1457
+ 'mla_tab' => 'upload',
1458
+ 'mla_item_ID' => urlencode( $item->ID )
1459
+ );
1460
+
1461
+ if ( isset( $_REQUEST['paged'] ) ) {
1462
+ $view_args['paged'] = $_REQUEST['paged'];
1463
+ }
1464
+
1465
+ if ( isset( $_REQUEST['order'] ) ) {
1466
+ $view_args['order'] = $_REQUEST['order'];
1467
+ }
1468
+
1469
+ if ( isset( $_REQUEST['orderby'] ) ) {
1470
+ $view_args['orderby'] = $_REQUEST['orderby'];
1471
+ }
1472
+
1473
+ $actions['select'] = '<a href="' . add_query_arg( $view_args, wp_nonce_url( '?mla_admin_action=' . MLACore::MLA_ADMIN_SINGLE_EDIT_UPDATE, MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ) ) . '" title="' . __( 'Select this entry', 'media-library-assistant' ) . '">' . __( 'Select', 'media-library-assistant' ) . '</a>';
1474
+
1475
+ return $actions;
1476
+ }
1477
+
1478
+ /**
1479
+ * Supply the content for a custom column
1480
+ *
1481
+ * @since 1.40
1482
+ *
1483
+ * @param object An MLA post_mime_type object
1484
+ * @return string HTML markup to be placed inside the column
1485
+ */
1486
+ function column_name( $item ) {
1487
+ $row_actions = self::_build_rollover_actions( $item, 'name' );
1488
+ $slug = esc_attr( $item->slug );
1489
+ return sprintf( '%1$s<br>%2$s', /*%1$s*/ $slug, /*%2$s*/ $this->row_actions( $row_actions ) );
1490
+ }
1491
+
1492
+ /**
1493
+ * Supply the content for a custom column
1494
+ *
1495
+ * @since 1.40
1496
+ *
1497
+ * @param object An MLA post_mime_type object
1498
+ * @return string HTML markup to be placed inside the column
1499
+ */
1500
+ function column_mime_type( $item ) {
1501
+ return esc_attr( $item->mime_type );
1502
+ }
1503
+
1504
+ /**
1505
+ * Supply the content for a custom column
1506
+ *
1507
+ * @since 1.40
1508
+ *
1509
+ * @param object An MLA post_mime_type object
1510
+ * @return string HTML markup to be placed inside the column
1511
+ */
1512
+ function column_core_type( $item ) {
1513
+ return esc_attr( $item->core_type );
1514
+ }
1515
+
1516
+ /**
1517
+ * Supply the content for a custom column
1518
+ *
1519
+ * @since 1.40
1520
+ *
1521
+ * @param object An MLA post_mime_type object
1522
+ * @return string HTML markup to be placed inside the column
1523
+ */
1524
+ function column_mla_type( $item ) {
1525
+ return esc_attr( $item->mla_type );
1526
+ }
1527
+
1528
+ /**
1529
+ * Supply the content for a custom column
1530
+ *
1531
+ * @since 1.40
1532
+ *
1533
+ * @param object An MLA post_mime_type object
1534
+ * @return string HTML markup to be placed inside the column
1535
+ */
1536
+ function column_description( $item ) {
1537
+ return esc_attr( $item->description );
1538
+ }
1539
+
1540
+ /**
1541
+ * This method dictates the table's columns and titles
1542
+ *
1543
+ * @since 1.40
1544
+ *
1545
+ * @return array Column information: 'slugs'=>'Visible Titles'
1546
+ */
1547
+ function get_columns( ) {
1548
+ return $columns = MLA_Upload_Optional_List_Table::mla_manage_columns_filter();
1549
+ }
1550
+
1551
+ /**
1552
+ * Returns the list of currently hidden columns from a user option or
1553
+ * from default values if the option is not set
1554
+ *
1555
+ * @since 1.40
1556
+ *
1557
+ * @return array Column information,e.g., array(0 => 'ID_parent, 1 => 'title_name')
1558
+ */
1559
+ function get_hidden_columns( ) {
1560
+ $columns = get_user_option( 'managesettings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-uploadcolumnshidden' );
1561
+
1562
+ if ( is_array( $columns ) ) {
1563
+ return $columns;
1564
+ }
1565
+
1566
+ return self::_default_hidden_columns();
1567
+ }
1568
+
1569
+ /**
1570
+ * Returns an array where the key is the column that needs to be sortable
1571
+ * and the value is db column to sort by. Also notes the current sort column,
1572
+ * if set.
1573
+ *
1574
+ * @since 1.40
1575
+ *
1576
+ * @return array Sortable column information,e.g.,
1577
+ * 'slugs'=>array('data_values',boolean)
1578
+ */
1579
+ function get_sortable_columns( ) {
1580
+ $columns = MLAMime::$default_upload_optional_sortable_columns;
1581
+
1582
+ if ( isset( $_REQUEST['orderby'] ) ) {
1583
+ $needle = array( $_REQUEST['orderby'], false );
1584
+ $key = array_search( $needle, $columns );
1585
+ if ( $key ) {
1586
+ $columns[ $key ][ 1 ] = true;
1587
+ }
1588
+ } else {
1589
+ $columns['name'][ 1 ] = true;
1590
+ }
1591
+
1592
+ return $columns;
1593
+ }
1594
+
1595
+ /**
1596
+ * Get an associative array ( option_name => option_title ) with the list
1597
+ * of bulk actions available on this table.
1598
+ *
1599
+ * @since 1.40
1600
+ *
1601
+ * @return array Contains all the bulk actions: 'slugs'=>'Visible Titles'
1602
+ */
1603
+ function get_bulk_actions( ) {
1604
+ $actions = array();
1605
+
1606
+ $actions['select'] = __( 'Select these entries', 'media-library-assistant' );
1607
+
1608
+ return $actions;
1609
+ }
1610
+
1611
+ /**
1612
+ * Prepares the list of items for displaying
1613
+ *
1614
+ * This is where you prepare your data for display. This method will usually
1615
+ * be used to query the database, sort and filter the data, and generally
1616
+ * get it ready to be displayed. At a minimum, we should set $this->items and
1617
+ * $this->set_pagination_args().
1618
+ *
1619
+ * @since 1.40
1620
+ *
1621
+ * @return void
1622
+ */
1623
+ function prepare_items( ) {
1624
+ $this->_column_headers = array(
1625
+ $this->get_columns(),
1626
+ $this->get_hidden_columns(),
1627
+ $this->get_sortable_columns()
1628
+ );
1629
+
1630
+ /*
1631
+ * REQUIRED for pagination.
1632
+ */
1633
+ $total_items = MLAMime::mla_count_optional_upload_items( $_REQUEST );
1634
+ $user = get_current_user_id();
1635
+ $screen = get_current_screen();
1636
+ $option = $screen->get_option( 'per_page', 'option' );
1637
+ if ( is_string( $option ) ) {
1638
+ $per_page = get_user_meta( $user, $option, true );
1639
+ } else {
1640
+ $per_page = 10;
1641
+ }
1642
+
1643
+ if ( empty( $per_page ) || $per_page < 1 ) {
1644
+ $per_page = $screen->get_option( 'per_page', 'default' );
1645
+ }
1646
+
1647
+ /*
1648
+ * REQUIRED. We also have to register our pagination options & calculations.
1649
+ */
1650
+ $this->set_pagination_args( array(
1651
+ 'total_items' => $total_items,
1652
+ 'per_page' => $per_page,
1653
+ 'total_pages' => ceil( $total_items / $per_page )
1654
+ ) );
1655
+
1656
+ $current_page = $this->get_pagenum();
1657
+
1658
+ /*
1659
+ * REQUIRED. Assign sorted and paginated data to the items property, where
1660
+ * it can be used by the rest of the class.
1661
+ */
1662
+ $this->items = MLAMime::mla_query_optional_upload_items( $_REQUEST, ( ( $current_page - 1 ) * $per_page ), $per_page );
1663
+ }
1664
+
1665
+ /**
1666
+ * Generates (echoes) content for a single row of the table
1667
+ *
1668
+ * @since 1.40
1669
+ *
1670
+ * @param object the current item
1671
+ *
1672
+ * @return void Echoes the row HTML
1673
+ */
1674
+ function single_row( $item ) {
1675
+ static $row_class = '';
1676
+ $row_class = ( $row_class == '' ? ' class="alternate"' : '' );
1677
+
1678
+ echo '<tr id="optional-upload-' . $item->ID . '"' . $row_class . '>';
1679
+ echo parent::single_row_columns( $item );
1680
+ echo '</tr>';
1681
+ }
1682
+ } // class MLA_Upload_Optional_List_Table
1683
+
1684
+ /*
1685
+ * Actions are added here, when the source file is loaded, because the "_list_Table"
1686
+ * objects are created too late to be useful.
1687
+ */
1688
+ add_action( 'admin_enqueue_scripts', 'MLASettings_Upload::mla_admin_enqueue_scripts' );
1689
+ add_action( 'admin_init', 'MLA_Upload_list_Table::mla_admin_init' );
1690
+ add_action( 'admin_init', 'MLA_Upload_Optional_List_Table::mla_admin_init' );
1691
+ ?>
includes/class-mla-settings-view-tab.php ADDED
@@ -0,0 +1,1020 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Manages the Settings/Media Library Assistant Views tab
4
+ *
5
+ * @package Media Library Assistant
6
+ * @since 2.40
7
+ */
8
+
9
+ /**
10
+ * Class MLA (Media Library Assistant) Settings View implements the
11
+ * Settings/Media Library Assistant Views tab
12
+ *
13
+ * @package Media Library Assistant
14
+ * @since 2.40
15
+ */
16
+ class MLASettings_View {
17
+ /**
18
+ * Object name for localizing JavaScript - MLA View List Table
19
+ *
20
+ * @since 1.40
21
+ *
22
+ * @var string
23
+ */
24
+ const JAVASCRIPT_INLINE_EDIT_VIEW_OBJECT = 'mla_inline_edit_view_vars';
25
+
26
+ /**
27
+ * Load the tab's Javascript files
28
+ *
29
+ * @since 2.40
30
+ *
31
+ * @param string $page_hook Name of the page being loaded
32
+ */
33
+ public static function mla_admin_enqueue_scripts( $page_hook ) {
34
+ global $wpdb, $wp_locale;
35
+
36
+ // Without a tab value that matches ours, there's nothing to do
37
+ if ( empty( $_REQUEST['mla_tab'] ) || 'view' !== $_REQUEST['mla_tab'] ) {
38
+ return;
39
+ }
40
+
41
+ /*
42
+ * Initialize common script variables
43
+ */
44
+ $script_variables = array(
45
+ 'error' => __( 'Error while making the changes.', 'media-library-assistant' ),
46
+ 'ntdeltitle' => __( 'Remove From Bulk Edit', 'media-library-assistant' ),
47
+ 'notitle' => '(' . __( 'no slug', 'media-library-assistant' ) . ')',
48
+ 'comma' => _x( ',', 'tag_delimiter', 'media-library-assistant' ),
49
+ 'useSpinnerClass' => false,
50
+ 'ajax_nonce' => wp_create_nonce( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ),
51
+ 'fields' => array( 'original_slug', 'slug', 'singular', 'plural', 'specification', 'menu_order' ),
52
+ 'checkboxes' => array( 'post_mime_type', 'table_view' ),
53
+ 'ajax_action' => MLASettings::JAVASCRIPT_INLINE_EDIT_VIEW_SLUG,
54
+ );
55
+
56
+ if ( version_compare( get_bloginfo( 'version' ), '4.2', '>=' ) ) {
57
+ $script_variables['useSpinnerClass'] = true;
58
+ }
59
+
60
+ $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
61
+
62
+ wp_enqueue_script( MLASettings::JAVASCRIPT_INLINE_EDIT_VIEW_SLUG,
63
+ MLA_PLUGIN_URL . "js/mla-inline-edit-view-scripts{$suffix}.js",
64
+ array( 'wp-lists', 'suggest', 'jquery' ), MLACore::CURRENT_MLA_VERSION, false );
65
+
66
+ wp_localize_script( MLASettings::JAVASCRIPT_INLINE_EDIT_VIEW_SLUG,
67
+ self::JAVASCRIPT_INLINE_EDIT_VIEW_OBJECT, $script_variables );
68
+ }
69
+
70
+ /**
71
+ * Save View settings to the options table
72
+ *
73
+ * @since 1.40
74
+ *
75
+ * @uses $_REQUEST
76
+ *
77
+ * @return array Message(s) reflecting the results of the operation
78
+ */
79
+ private static function _save_view_settings( ) {
80
+ $message_list = '';
81
+
82
+ foreach ( MLACoreOptions::$mla_option_definitions as $key => $value ) {
83
+ if ( 'view' == $value['tab'] ) {
84
+ $message_list .= MLASettings::mla_update_option_row( $key, $value );
85
+ } // view option
86
+ } // foreach mla_options
87
+
88
+ $page_content = array(
89
+ 'message' => __( 'View settings saved.', 'media-library-assistant' ) . "\r\n",
90
+ 'body' => ''
91
+ );
92
+
93
+ /*
94
+ * Uncomment this for debugging.
95
+ */
96
+ // $page_content['message'] .= $message_list;
97
+
98
+ return $page_content;
99
+ } // _save_view_settings
100
+
101
+ /**
102
+ * Compose the Edit View tab content for the Settings subpage
103
+ *
104
+ * @since 1.40
105
+ *
106
+ * @param array data values for the item
107
+ * @param string Display template
108
+ *
109
+ * @return array 'message' => status/error messages, 'body' => tab content
110
+ */
111
+ private static function _compose_edit_view_tab( $view, $template ) {
112
+ $page_values = array(
113
+ 'Edit View' => __( 'Edit View', 'media-library-assistant' ),
114
+ 'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-view&mla_tab=view',
115
+ 'action' => MLACore::MLA_ADMIN_SINGLE_EDIT_UPDATE,
116
+ 'original_slug' => $view['slug'],
117
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
118
+ 'Slug' => __( 'Slug', 'media-library-assistant' ),
119
+ 'The slug is' => __( 'The &#8220;slug&#8221; is the URL-friendly, unique key for the view. It must be all lowercase and contain only letters, numbers, periods (.), slashes (/) and hyphens (-). For &#8220;<strong>Post MIME Type</strong>&#8221; views, the slug is also the MIME type specification and <strong>must be a valid MIME</strong> type, e.g., &#8220;image&#8221; or &#8220;image/jpeg&#8221;.', 'media-library-assistant' ),
120
+ 'Singular Label' => __( 'Singular Label', 'media-library-assistant' ),
121
+ 'Plural Label' => __( 'Plural Label', 'media-library-assistant' ),
122
+ 'The labels' => __( 'The labels, e.g., &#8220;Image&#8221; and &#8220;Images&#8221; are used for column headers and other display purposes.', 'media-library-assistant' ),
123
+ 'Specification' => __( 'Specification', 'media-library-assistant' ),
124
+ 'If the specification' => __( 'If the MIME type specification differs from the slug, enter it here. You may include multiple MIME types, e.g., &#8220;audio,video&#8221; and/or wildcard specs, e.g., &#8220;*/*ms*&#8221;. This field will be ignored if the Post MIME Type box is checked.', 'media-library-assistant' ),
125
+ 'Post MIME Type' => __( 'Post MIME Type', 'media-library-assistant' ),
126
+ 'Check Post MIME' => __( 'Check this box if you want to add this entry to the list of MIME types returned by wp_get_mime_types().', 'media-library-assistant' ),
127
+ 'Table View' => __( 'Table View', 'media-library-assistant' ),
128
+ 'Check Table View' => __( 'Check this box if you want to add this entry to the list of Media/Assistant table views.', 'media-library-assistant' ),
129
+ 'Menu Order' => __( 'Menu Order', 'media-library-assistant' ),
130
+ 'You can choose' => __( 'You can choose your own table view order by entering a number (1 for first, etc.) in this field.', 'media-library-assistant' ),
131
+ 'Description' => __( 'Description', 'media-library-assistant' ),
132
+ 'The description can' => __( 'The description can contain any documentation or notes you need to understand or use the item.', 'media-library-assistant' ),
133
+ 'Update' => __( 'Update', 'media-library-assistant' ),
134
+ 'Cancel' => __( 'Cancel', 'media-library-assistant' ),
135
+ );
136
+
137
+ foreach ( $view as $key => $value ) {
138
+ switch ( $key ) {
139
+ case 'post_mime_type':
140
+ case 'table_view':
141
+ $page_values[ $key ] = $value ? 'checked="checked"' : '';
142
+ break;
143
+ default:
144
+ $page_values[ $key ] = $value;
145
+ }
146
+ }
147
+
148
+ return array(
149
+ 'message' => '',
150
+ 'body' => MLAData::mla_parse_template( $template, $page_values )
151
+ );
152
+ }
153
+
154
+ /**
155
+ * Compose the Post MIME Type Views tab content for the Settings subpage
156
+ *
157
+ * @since 1.40
158
+ *
159
+ * @return array 'message' => status/error messages, 'body' => tab content
160
+ */
161
+ public static function mla_compose_view_tab( ) {
162
+ $page_template_array = MLACore::mla_load_template( 'admin-display-settings-view-tab.tpl' );
163
+ if ( ! is_array( $page_template_array ) ) {
164
+ /* translators: 1: ERROR tag 2: function name 3: non-array value */
165
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'MLASettings_View::mla_compose_view_tab', var_export( $page_template_array, true ) ), MLACore::MLA_DEBUG_CATEGORY_ANY );
166
+ return '';
167
+ }
168
+
169
+ /*
170
+ * Convert checkbox values, if present
171
+ */
172
+ if ( isset( $_REQUEST['mla_view_item'] ) ) {
173
+ $_REQUEST['mla_view_item']['post_mime_type'] = isset( $_REQUEST['mla_view_item']['post_mime_type'] );
174
+ $_REQUEST['mla_view_item']['table_view'] = isset( $_REQUEST['mla_view_item']['table_view'] );
175
+ }
176
+
177
+ /*
178
+ * Set default values, check for Add New Post MIME Type View button
179
+ */
180
+ $add_form_values = array (
181
+ 'slug' => '',
182
+ 'singular' => '',
183
+ 'plural' => '',
184
+ 'specification' => '',
185
+ 'post_mime_type' => 'checked="checked"',
186
+ 'table_view' => 'checked="checked"',
187
+ 'menu_order' => '',
188
+ 'description' => ''
189
+ );
190
+
191
+ if ( !empty( $_REQUEST['mla-view-options-save'] ) ) {
192
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
193
+ $page_content = self::_save_view_settings( );
194
+ } elseif ( !empty( $_REQUEST['mla-add-view-submit'] ) ) {
195
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
196
+ $page_content = MLAMime::mla_add_post_mime_type( $_REQUEST['mla_view_item'] );
197
+ if ( false !== strpos( $page_content['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
198
+ $add_form_values = $_REQUEST['mla_view_item'];
199
+ $add_form_values['post_mime_type'] = $add_form_values['post_mime_type'] ? 'checked="checked"' : '';
200
+ $add_form_values['table_view'] = $add_form_values['table_view'] ? 'checked="checked"' : '';
201
+ }
202
+ } else {
203
+ $page_content = array(
204
+ 'message' => '',
205
+ 'body' => ''
206
+ );
207
+ }
208
+
209
+ /*
210
+ * Process bulk actions that affect an array of items
211
+ */
212
+ $bulk_action = MLASettings::mla_current_bulk_action();
213
+ if ( $bulk_action && ( $bulk_action != 'none' ) ) {
214
+ if ( isset( $_REQUEST['cb_mla_item_ID'] ) ) {
215
+ /*
216
+ * Convert post-ID to slug; separate loop required because delete changes post_IDs
217
+ */
218
+ $slugs = array();
219
+ foreach ( $_REQUEST['cb_mla_item_ID'] as $post_ID )
220
+ $slugs[] = MLAMime::mla_get_post_mime_type_slug( $post_ID );
221
+
222
+ foreach ( $slugs as $slug ) {
223
+ switch ( $bulk_action ) {
224
+ case 'delete':
225
+ $item_content = MLAMime::mla_delete_post_mime_type( $slug );
226
+ break;
227
+ case 'edit':
228
+ $request = array( 'slug' => $slug );
229
+ if ( '-1' != $_REQUEST['post_mime_type'] ) {
230
+ $request['post_mime_type'] = '1' == $_REQUEST['post_mime_type'];
231
+ }
232
+ if ( '-1' != $_REQUEST['table_view'] ) {
233
+ $request['table_view'] = '1' == $_REQUEST['table_view'];
234
+ }
235
+ if ( !empty( $_REQUEST['menu_order'] ) ) {
236
+ $request['menu_order'] = $_REQUEST['menu_order'];
237
+ }
238
+ $item_content = MLAMime::mla_update_post_mime_type( $request );
239
+ break;
240
+ default:
241
+ $item_content = array(
242
+ /* translators: 1: bulk_action, e.g., delete, edit, restore, trash */
243
+ 'message' => sprintf( __( 'Unknown bulk action %1$s', 'media-library-assistant' ), $bulk_action ),
244
+ 'body' => ''
245
+ );
246
+ } // switch $bulk_action
247
+
248
+ $page_content['message'] .= $item_content['message'] . '<br>';
249
+ } // foreach cb_attachment
250
+ } // isset cb_attachment
251
+ else {
252
+ /* translators: 1: action name, e.g., edit */
253
+ $page_content['message'] = sprintf( __( 'Bulk Action %1$s - no items selected.', 'media-library-assistant' ), $bulk_action );
254
+ }
255
+ } // $bulk_action
256
+
257
+ /*
258
+ * Process row-level actions that affect a single item
259
+ */
260
+ if ( !empty( $_REQUEST['mla_admin_action'] ) ) {
261
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
262
+
263
+ switch ( $_REQUEST['mla_admin_action'] ) {
264
+ case MLACore::MLA_ADMIN_SINGLE_DELETE:
265
+ $page_content = MLAMime::mla_delete_post_mime_type( $_REQUEST['mla_item_slug'] );
266
+ break;
267
+ case MLACore::MLA_ADMIN_SINGLE_EDIT_DISPLAY:
268
+ $view = MLAMime::mla_get_post_mime_type( $_REQUEST['mla_item_slug'] );
269
+ $page_content = self::_compose_edit_view_tab( $view, $page_template_array['single-item-edit'] );
270
+ break;
271
+ case MLACore::MLA_ADMIN_SINGLE_EDIT_UPDATE:
272
+ if ( !empty( $_REQUEST['update'] ) ) {
273
+ $page_content = MLAMime::mla_update_post_mime_type( $_REQUEST['mla_view_item'] );
274
+ if ( false !== strpos( $page_content['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
275
+ $message = $page_content['message'];
276
+ $page_content = self::_compose_edit_view_tab( $_REQUEST['mla_view_item'], $page_template_array['single-item-edit'] );
277
+ $page_content['message'] = $message;
278
+ }
279
+ } else {
280
+ $page_content = array(
281
+ /* translators: 1: view name/slug */
282
+ 'message' => sprintf( __( 'Edit view "%1$s" cancelled.', 'media-library-assistant' ), $_REQUEST['mla_view_item']['original_slug'] ),
283
+ 'body' => ''
284
+ );
285
+ }
286
+ break;
287
+ default:
288
+ $page_content = array(
289
+ /* translators: 1: bulk_action, e.g., single_item_delete, single_item_edit */
290
+ 'message' => sprintf( __( 'Unknown mla_admin_action - "%1$s"', 'media-library-assistant' ), $_REQUEST['mla_admin_action'] ),
291
+ 'body' => ''
292
+ );
293
+ break;
294
+ } // switch ($_REQUEST['mla_admin_action'])
295
+ } // (!empty($_REQUEST['mla_admin_action'])
296
+
297
+ if ( !empty( $page_content['body'] ) ) {
298
+ return $page_content;
299
+ }
300
+
301
+ /*
302
+ * Check for disabled status
303
+ */
304
+ if ( 'checked' != MLACore::mla_get_option( MLACoreOptions::MLA_ENABLE_POST_MIME_TYPES ) ) {
305
+ /*
306
+ * Fill in with any page-level options
307
+ */
308
+ $options_list = '';
309
+ foreach ( MLACoreOptions::$mla_option_definitions as $key => $value ) {
310
+ if ( 'view' == $value['tab'] ) {
311
+ $options_list .= MLASettings::mla_compose_option_row( $key, $value );
312
+ }
313
+ }
314
+
315
+ $page_values = array(
316
+ 'Support is disabled' => __( 'View and Post MIME Type Support is disabled', 'media-library-assistant' ),
317
+ 'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-view&mla_tab=view',
318
+ 'options_list' => $options_list,
319
+ 'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
320
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
321
+ );
322
+
323
+ $page_content['body'] .= MLAData::mla_parse_template( $page_template_array['view-disabled'], $page_values );
324
+ return $page_content;
325
+ }
326
+
327
+ /*
328
+ * Display the View Table
329
+ */
330
+ $_SERVER['REQUEST_URI'] = remove_query_arg( array(
331
+ 'mla_admin_action',
332
+ 'mla_item_slug',
333
+ 'mla_item_ID',
334
+ '_wpnonce',
335
+ '_wp_http_referer',
336
+ 'action',
337
+ 'action2',
338
+ 'cb_mla_item_ID',
339
+ 'mla-optional-uploads-search',
340
+ 'mla-optional-uploads-display'
341
+ ), $_SERVER['REQUEST_URI'] );
342
+
343
+ // Create an instance of our package class
344
+ $MLAListViewTable = new MLA_View_List_Table();
345
+
346
+ // Fetch, prepare, sort, and filter our data
347
+ $MLAListViewTable->prepare_items();
348
+
349
+ /*
350
+ * Start with any page-level options
351
+ */
352
+ $options_list = '';
353
+ foreach ( MLACoreOptions::$mla_option_definitions as $key => $value ) {
354
+ if ( 'view' == $value['tab'] ) {
355
+ $options_list .= MLASettings::mla_compose_option_row( $key, $value );
356
+ }
357
+ }
358
+
359
+ $page_values = array(
360
+ 'Library Views Processing' => __( 'Library Views/Post MIME Type Processing', 'media-library-assistant' ),
361
+ 'In this tab' => __( 'In this tab you can manage the list of "Post MIME Types", which are used by WordPress to define the views for the <em><strong>Media/Library</strong></em> screen and the <em><strong>Media Manager/Add Media</strong></em> "media items" drop down list. MLA&rsquo;s <em><strong>Media/Assistant</strong></em> screen uses an enhanced version of the list, <em>Table Views</em>, to support views with multiple MIME Types (e.g., "audio,video") and wildcard specifications (e.g. "*/*ms*").', 'media-library-assistant' ),
362
+ /* translators: 1: Documentation hyperlink */
363
+ 'You can find' => sprintf( __( 'You can find more information about library views, Post MIME types and how MLA and WordPress use them in the %1$s section of the Documentation or by clicking the <strong>"Help"</strong> tab in the upper-right corner of this screen.', 'media-library-assistant' ), '<a href="[+settingsURL+]?page=mla-settings-menu-documentation&amp;mla_tab=documentation#mla_views" title="' . __( 'Library View Processing documentation', 'media-library-assistant' ) . '">' . __( 'Library Views/Post MIME Type Processing', 'media-library-assistant' ) . '</a>' ),
364
+ 'settingsURL' => admin_url('options-general.php'),
365
+ 'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-view&mla_tab=view',
366
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
367
+ 'results' => ! empty( $_REQUEST['s'] ) ? '<h2 class="alignleft">' . __( 'Displaying search results for', 'media-library-assistant' ) . ': "' . $_REQUEST['s'] . '"</h2>' : '',
368
+ 'Search Views' => __( 'Search Views', 'media-library-assistant' ),
369
+ 's' => isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '',
370
+ 'options_list' => $options_list,
371
+ 'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
372
+ /* translators: %s: add new View */
373
+ 'Add New View' => sprintf( __( 'Add New %1$s', 'media-library-assistant' ), __( 'View', 'media-library-assistant' ) ),
374
+ 'Slug' => __( 'Slug', 'media-library-assistant' ),
375
+ 'The slug is' => __( 'The &#8220;slug&#8221; is the URL-friendly, unique key for the view. It must be all lowercase and contain only letters, numbers, periods (.), slashes (/) and hyphens (-). For &#8220;<strong>Post MIME Type</strong>&#8221; views, the slug is also the MIME type specification and <strong>must be a valid MIME</strong> type, e.g., &#8220;image&#8221; or &#8220;image/jpeg&#8221;.', 'media-library-assistant' ),
376
+ 'Singular Label' => __( 'Singular Label', 'media-library-assistant' ),
377
+ 'Plural Label' => __( 'Plural Label', 'media-library-assistant' ),
378
+ 'The labels' => __( 'The labels, e.g., &#8220;Image&#8221; and &#8220;Images&#8221; are used for column headers and other display purposes.', 'media-library-assistant' ),
379
+ 'Specification' => __( 'Specification', 'media-library-assistant' ),
380
+ 'If the specification' => __( 'If the MIME type specification differs from the slug, enter it here. You may include multiple MIME types, e.g., &#8220;audio,video&#8221; and/or wildcard specs, e.g., &#8220;*/*ms*&#8221;. This field will be ignored if the Post MIME Type box is checked.', 'media-library-assistant' ),
381
+ 'Post MIME Type' => __( 'Post MIME Type', 'media-library-assistant' ),
382
+ 'Check Post MIME' => __( 'Check this box if you want to add this entry to the list of MIME types returned by wp_get_mime_types().', 'media-library-assistant' ),
383
+ 'Table View' => __( 'Table View', 'media-library-assistant' ),
384
+ 'Check Table View' => __( 'Check this box if you want to add this entry to the list of Media/Assistant table views.', 'media-library-assistant' ),
385
+ 'Menu Order' => __( 'Menu Order', 'media-library-assistant' ),
386
+ 'You can choose' => __( 'You can choose your own table view order by entering a number (1 for first, etc.) in this field.', 'media-library-assistant' ),
387
+ 'Description' => __( 'Description', 'media-library-assistant' ),
388
+ 'The description can' => __( 'The description can contain any documentation or notes you need to understand or use the item.', 'media-library-assistant' ),
389
+ 'Add View' => __( 'Add View', 'media-library-assistant' ),
390
+ 'colspan' => $MLAListViewTable->get_column_count(),
391
+ 'Quick Edit' => __( '<strong>Quick Edit</strong>', 'media-library-assistant' ),
392
+ 'Cancel' => __( 'Cancel', 'media-library-assistant' ),
393
+ 'Update' => __( 'Update', 'media-library-assistant' ),
394
+ 'Bulk Edit' => __( 'Bulk Edit', 'media-library-assistant' ),
395
+ 'No Change' => __( 'No Change', 'media-library-assistant' ),
396
+ 'No' => __( 'No', 'media-library-assistant' ),
397
+ 'Yes' => __( 'Yes', 'media-library-assistant' ),
398
+ );
399
+
400
+ foreach ( $add_form_values as $key => $value ) {
401
+ $page_values[ $key ] = $value;
402
+ }
403
+ $page_content['body'] = MLAData::mla_parse_template( $page_template_array['before-table'], $page_values );
404
+
405
+ // Now we can render the completed list table
406
+ ob_start();
407
+ $MLAListViewTable->views();
408
+ $MLAListViewTable->display();
409
+ $page_content['body'] .= ob_get_contents();
410
+ ob_end_clean();
411
+
412
+ $page_content['body'] .= MLAData::mla_parse_template( $page_template_array['after-table'], $page_values );
413
+
414
+ return $page_content;
415
+ }
416
+
417
+ /**
418
+ * Ajax handler for Post MIME Types inline editing (quick and bulk edit)
419
+ *
420
+ * Adapted from wp_ajax_inline_save in /wp-admin/includes/ajax-actions.php
421
+ *
422
+ * @since 1.40
423
+ *
424
+ * @return void echo HTML <tr> markup for updated row or error message, then die()
425
+ */
426
+ public static function mla_inline_edit_view_action() {
427
+ set_current_screen( $_REQUEST['screen'] );
428
+
429
+ check_ajax_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
430
+
431
+ if ( empty( $_REQUEST['original_slug'] ) ) {
432
+ echo __( 'ERROR', 'media-library-assistant' ) . ': ' . __( 'No view slug found', 'media-library-assistant' );
433
+ die();
434
+ }
435
+
436
+ $request = array( 'original_slug' => $_REQUEST['original_slug'] );
437
+ $request['slug'] = $_REQUEST['slug'];
438
+ $request['specification'] = $_REQUEST['specification'];
439
+ $request['singular'] = $_REQUEST['singular'];
440
+ $request['plural'] = $_REQUEST['plural'];
441
+ $request['post_mime_type'] = isset( $_REQUEST['post_mime_type'] ) && ( '1' == $_REQUEST['post_mime_type'] );
442
+ $request['table_view'] = isset( $_REQUEST['table_view'] ) && ( '1' == $_REQUEST['table_view'] );
443
+ $request['menu_order'] = $_REQUEST['menu_order'];
444
+ $results = MLAMime::mla_update_post_mime_type( $request );
445
+
446
+ if ( false === strpos( $results['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
447
+ $new_item = (object) MLAMime::mla_get_post_mime_type( $_REQUEST['slug'] );
448
+ } else {
449
+ $new_item = (object) MLAMime::mla_get_post_mime_type( $_REQUEST['original_slug'] );
450
+ }
451
+
452
+ $new_item->post_ID = $_REQUEST['post_ID'];
453
+
454
+ // Create an instance of our package class and echo the new HTML
455
+ $MLAListViewTable = new MLA_View_List_Table();
456
+ $MLAListViewTable->single_row( $new_item );
457
+ die(); // this is required to return a proper result
458
+ }
459
+ } // MLASettings_View
460
+
461
+ /*
462
+ * The WP_List_Table class isn't automatically available to plugins
463
+ */
464
+ if ( !class_exists( 'WP_List_Table' ) ) {
465
+ require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
466
+ }
467
+
468
+ /**
469
+ * Class MLA (Media Library Assistant) View List Table implements the "Views"
470
+ * admin settings submenu table
471
+ *
472
+ * Extends the core WP_List_Table class.
473
+ *
474
+ * @package Media Library Assistant
475
+ * @since 1.40
476
+ */
477
+ class MLA_View_List_Table extends WP_List_Table {
478
+ /**
479
+ * Initializes some properties from $_REQUEST variables, then
480
+ * calls the parent constructor to set some default configs.
481
+ *
482
+ * @since 1.40
483
+ *
484
+ * @return void
485
+ */
486
+ function __construct( ) {
487
+ // MLA does not use this
488
+ $this->modes = array(
489
+ 'list' => __( 'List View' ),
490
+ );
491
+
492
+ //Set parent defaults
493
+ parent::__construct( array(
494
+ 'singular' => 'post_mime_type', //singular name of the listed records
495
+ 'plural' => 'post_mime_types', //plural name of the listed records
496
+ 'ajax' => true, //does this table support ajax?
497
+ 'screen' => 'settings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-view'
498
+ ) );
499
+
500
+ /*
501
+ * NOTE: There is one add_action call at the end of this source file.
502
+ */
503
+ }
504
+
505
+ /**
506
+ * Default values for hidden columns
507
+ *
508
+ * This array is used when the user-level option is not set, i.e.,
509
+ * the user has not altered the selection of hidden columns.
510
+ *
511
+ * The value on the right-hand side must match the column slug, e.g.,
512
+ * array(0 => 'ID_parent, 1 => 'title_name').
513
+ *
514
+ * @since 1.40
515
+ *
516
+ * @var array
517
+ */
518
+ private static $default_hidden_columns = array(
519
+ // 'name',
520
+ // 'specification',
521
+ // 'post_mime_type',
522
+ // 'table_view',
523
+ 'singular',
524
+ // 'plural',
525
+ 'menu_order',
526
+ 'description'
527
+ );
528
+
529
+ /**
530
+ * Access the default list of hidden columns
531
+ *
532
+ * @since 1.40
533
+ *
534
+ * @return array default list of hidden columns
535
+ */
536
+ private static function _default_hidden_columns( ) {
537
+ return self::$default_hidden_columns;
538
+ }
539
+
540
+ /**
541
+ * Handler for filter 'get_user_option_managesettings_page_mla-settings-menu-viewcolumnshidden'
542
+ *
543
+ * Required because the screen.php get_hidden_columns function only uses
544
+ * the get_user_option result. Set when the file is loaded because the object
545
+ * is not created in time for the call from screen.php.
546
+ *
547
+ * @since 1.40
548
+ *
549
+ * @param mixed false or array with current list of hidden columns, if any
550
+ * @param string 'managesettings_page_mla-settings-menucolumnshidden'
551
+ * @param object WP_User object, if logged in
552
+ *
553
+ * @return array updated list of hidden columns
554
+ */
555
+ public static function mla_manage_hidden_columns_filter( $result, $option, $user_data ) {
556
+ return $result ? $result : self::_default_hidden_columns();
557
+ }
558
+
559
+ /**
560
+ * Handler for filter 'manage_settings_page_mla-settings-menu_columns'
561
+ *
562
+ * This required filter dictates the table's columns and titles. Set when the
563
+ * file is loaded because the list_table object isn't created in time
564
+ * to affect the "screen options" setup.
565
+ *
566
+ * @since 1.40
567
+ *
568
+ * @return array list of table columns
569
+ */
570
+ public static function mla_manage_columns_filter( ) {
571
+ return MLAMime::$default_view_columns;
572
+ }
573
+
574
+ /**
575
+ * Called in the admin_init action because the list_table object isn't
576
+ * created in time to affect the "screen options" setup.
577
+ *
578
+ * @since 1.40
579
+ *
580
+ * @return void
581
+ */
582
+ public static function mla_admin_init( ) {
583
+ if ( isset( $_REQUEST['mla_tab'] ) && $_REQUEST['mla_tab'] == 'view' ) {
584
+ add_filter( 'get_user_option_managesettings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-viewcolumnshidden', 'MLA_View_List_Table::mla_manage_hidden_columns_filter', 10, 3 );
585
+ add_filter( 'manage_settings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-view_columns', 'MLA_View_List_Table::mla_manage_columns_filter', 10, 0 );
586
+ }
587
+ }
588
+
589
+ /**
590
+ * Checks the current user's permissions
591
+ *
592
+ * @since 2.14
593
+ *
594
+ * @return bool
595
+ */
596
+ public function ajax_user_can() {
597
+ return current_user_can('manage_options');
598
+ }
599
+
600
+ /**
601
+ * Get the name of the default primary column.
602
+ *
603
+ * @since 2.14
604
+ * @access protected
605
+ *
606
+ * @return string Name of the default primary column
607
+ */
608
+ protected function get_default_primary_column_name() {
609
+ return 'name';
610
+ }
611
+
612
+ /**
613
+ * Generate and display row actions links.
614
+ *
615
+ * @since 2.14
616
+ * @access protected
617
+ *
618
+ * @param object $item Attachment being acted upon.
619
+ * @param string $column_name Current column name.
620
+ * @param string $primary Primary column name.
621
+ * @return string Row actions output for media attachments.
622
+ */
623
+ protected function handle_row_actions( $item, $column_name, $primary ) {
624
+ if ( $primary === $column_name ) {
625
+ $actions = $this->row_actions( $this->_build_rollover_actions( $item, $column_name ) );
626
+ $actions .= $this->_build_inline_data( $item );
627
+ return $actions;
628
+ }
629
+
630
+ return '';
631
+ }
632
+
633
+ /**
634
+ * Supply a column value if no column-specific function has been defined
635
+ *
636
+ * Called when the parent class can't find a method specifically built for a
637
+ * given column. All columns should have a specific method, so this function
638
+ * returns a troubleshooting message.
639
+ *
640
+ * @since 1.40
641
+ *
642
+ * @param array A singular item (one full row's worth of data)
643
+ * @param array The name/slug of the column to be processed
644
+ * @return string Text or HTML to be placed inside the column
645
+ */
646
+ function column_default( $item, $column_name ) {
647
+ //Show the whole array for troubleshooting purposes
648
+ /* translators: 1: column_name 2: column_values */
649
+ return sprintf( __( 'column_default: %1$s, %2$s', 'media-library-assistant' ), $column_name, print_r( $item, true ) );
650
+ }
651
+
652
+ /**
653
+ * Displays checkboxes for using bulk actions. The 'cb' column
654
+ * is given special treatment when columns are processed.
655
+ *
656
+ * @since 1.40
657
+ *
658
+ * @param object An MLA post_mime_type object
659
+ * @return string HTML markup to be placed inside the column
660
+ */
661
+ function column_cb( $item ) {
662
+ return sprintf( '<input type="checkbox" name="cb_mla_item_ID[]" value="%1$s" />',
663
+ /*%1$s*/ $item->post_ID
664
+ );
665
+ }
666
+
667
+ /**
668
+ * Add rollover actions to a table column
669
+ *
670
+ * @since 1.40
671
+ *
672
+ * @param object An MLA post_mime_type object
673
+ * @param string Current column name
674
+ *
675
+ * @return array Names and URLs of row-level actions
676
+ */
677
+ private function _build_rollover_actions( $item, $column ) {
678
+ $actions = array();
679
+
680
+ /*
681
+ * Compose view arguments
682
+ */
683
+
684
+ $view_args = array(
685
+ 'page' => MLACoreOptions::MLA_SETTINGS_SLUG . '-view',
686
+ 'mla_tab' => 'view',
687
+ 'mla_item_slug' => urlencode( $item->slug )
688
+ );
689
+
690
+ if ( isset( $_REQUEST['paged'] ) ) {
691
+ $view_args['paged'] = $_REQUEST['paged'];
692
+ }
693
+
694
+ if ( isset( $_REQUEST['order'] ) ) {
695
+ $view_args['order'] = $_REQUEST['order'];
696
+ }
697
+
698
+ if ( isset( $_REQUEST['orderby'] ) ) {
699
+ $view_args['orderby'] = $_REQUEST['orderby'];
700
+ }
701
+
702
+ /*
703
+ * Get the standard and custom types
704
+ */
705
+ $mla_types = MLACore::mla_get_option( MLACoreOptions::MLA_POST_MIME_TYPES, true );
706
+ if ( ! is_array( $mla_types ) ) {
707
+ $mla_types = array ();
708
+ }
709
+
710
+ $custom_types = MLACore::mla_get_option( MLACoreOptions::MLA_POST_MIME_TYPES, false, true );
711
+ if ( ! is_array( $custom_types ) ) {
712
+ $custom_types = array ();
713
+ }
714
+
715
+ $actions['edit'] = '<a href="' . add_query_arg( $view_args, wp_nonce_url( '?mla_admin_action=' . MLACore::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>';
716
+
717
+ $actions['inline hide-if-no-js'] = '<a class="editinline" href="#" title="' . __( 'Edit this item inline', 'media-library-assistant' ) . '">' . __( 'Quick Edit', 'media-library-assistant' ) . '</a>';
718
+
719
+ if ( isset( $custom_types[ $item->slug ] ) ) {
720
+ if ( isset( $mla_types[ $item->slug ] ) ) {
721
+ $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>';
722
+ } else {
723
+ $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>';
724
+ }
725
+ } // custom type
726
+
727
+ return $actions;
728
+ }
729
+
730
+ /**
731
+ * Add hidden fields with the data for use in the inline editor
732
+ *
733
+ * @since 1.40
734
+ *
735
+ * @param object An MLA post_mime_type object
736
+ *
737
+ * @return string HTML <div> with row data
738
+ */
739
+ private function _build_inline_data( $item ) {
740
+ $inline_data = "\r\n" . '<div class="hidden" id="inline_' . $item->post_ID . "\">\r\n";
741
+ $inline_data .= ' <div class="original_slug">' . esc_attr( $item->slug ) . "</div>\r\n";
742
+ $inline_data .= ' <div class="slug">' . esc_attr( $item->slug ) . "</div>\r\n";
743
+ $inline_data .= ' <div class="singular">' . esc_attr( $item->singular ) . "</div>\r\n";
744
+ $inline_data .= ' <div class="plural">' . esc_attr( $item->plural ) . "</div>\r\n";
745
+ $inline_data .= ' <div class="specification">' . esc_attr( $item->specification ) . "</div>\r\n";
746
+ $inline_data .= ' <div class="post_mime_type">' . esc_attr( $item->post_mime_type ) . "</div>\r\n";
747
+ $inline_data .= ' <div class="table_view">' . esc_attr( $item->table_view ) . "</div>\r\n";
748
+ $inline_data .= ' <div class="menu_order">' . esc_attr( $item->menu_order ) . "</div>\r\n";
749
+ $inline_data .= ' <div class="description">' . esc_attr( $item->description ) . "</div>\r\n";
750
+ $inline_data .= "</div>\r\n";
751
+ return $inline_data;
752
+ }
753
+
754
+ /**
755
+ * Supply the content for a custom column
756
+ *
757
+ * @since 1.40
758
+ *
759
+ * @param object An MLA post_mime_type object
760
+ * @return string HTML markup to be placed inside the column
761
+ */
762
+ function column_name( $item ) {
763
+ if ( MLATest::$wp_4dot3_plus ) {
764
+ return esc_attr( $item->slug );
765
+ }
766
+
767
+ $row_actions = self::_build_rollover_actions( $item, 'name' );
768
+ $slug = esc_attr( $item->slug );
769
+ return sprintf( '%1$s<br>%2$s%3$s', /*%1$s*/ $slug, /*%2$s*/ $this->row_actions( $row_actions ), /*%3$s*/ $this->_build_inline_data( $item ) );
770
+ }
771
+
772
+ /**
773
+ * Supply the content for a custom column
774
+ *
775
+ * @since 1.40
776
+ *
777
+ * @param object An MLA post_mime_type object
778
+ * @return string HTML markup to be placed inside the column
779
+ */
780
+ function column_specification( $item ) {
781
+ return esc_attr( $item->specification );
782
+ }
783
+
784
+ /**
785
+ * Supply the content for a custom column
786
+ *
787
+ * @since 1.40
788
+ *
789
+ * @param object An MLA post_mime_type object
790
+ * @return string HTML markup to be placed inside the column
791
+ */
792
+ function column_post_mime_type( $item ) {
793
+ if ( $item->post_mime_type ) {
794
+ return __( 'Yes', 'media-library-assistant' );
795
+ } else {
796
+ return __( 'No', 'media-library-assistant' );
797
+ }
798
+ }
799
+
800
+ /**
801
+ * Supply the content for a custom column
802
+ *
803
+ * @since 1.40
804
+ *
805
+ * @param object An MLA post_mime_type object
806
+ * @return string HTML markup to be placed inside the column
807
+ */
808
+ function column_table_view( $item ) {
809
+ if ( $item->table_view ) {
810
+ return __( 'Yes', 'media-library-assistant' );
811
+ } else {
812
+ return __( 'No', 'media-library-assistant' );
813
+ }
814
+ }
815
+
816
+ /**
817
+ * Supply the content for a custom column
818
+ *
819
+ * @since 1.40
820
+ *
821
+ * @param object An MLA post_mime_type object
822
+ * @return string HTML markup to be placed inside the column
823
+ */
824
+ function column_singular( $item ) {
825
+ return esc_attr( $item->singular );
826
+ }
827
+
828
+ /**
829
+ * Supply the content for a custom column
830
+ *
831
+ * @since 1.40
832
+ *
833
+ * @param object An MLA post_mime_type object
834
+ * @return string HTML markup to be placed inside the column
835
+ */
836
+ function column_plural( $item ) {
837
+ return esc_attr( $item->plural );
838
+ }
839
+
840
+ /**
841
+ * Supply the content for a custom column
842
+ *
843
+ * @since 1.40
844
+ *
845
+ * @param object An MLA post_mime_type object
846
+ * @return string HTML markup to be placed inside the column
847
+ */
848
+ function column_menu_order( $item ) {
849
+ return (string) $item->menu_order;
850
+ }
851
+
852
+ /**
853
+ * Supply the content for a custom column
854
+ *
855
+ * @since 1.40
856
+ *
857
+ * @param object An MLA post_mime_type object
858
+ * @return string HTML markup to be placed inside the column
859
+ */
860
+ function column_description( $item ) {
861
+ return esc_attr( $item->description );
862
+ }
863
+
864
+ /**
865
+ * This method dictates the table's columns and titles
866
+ *
867
+ * @since 1.40
868
+ *
869
+ * @return array Column information: 'slugs'=>'Visible Titles'
870
+ */
871
+ function get_columns( ) {
872
+ return $columns = MLA_View_List_Table::mla_manage_columns_filter();
873
+ }
874
+
875
+ /**
876
+ * Returns the list of currently hidden columns from a user option or
877
+ * from default values if the option is not set
878
+ *
879
+ * @since 1.40
880
+ *
881
+ * @return array Column information,e.g., array(0 => 'ID_parent, 1 => 'title_name')
882
+ */
883
+ function get_hidden_columns( ) {
884
+ $columns = get_user_option( 'managesettings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-viewcolumnshidden' );
885
+
886
+ if ( is_array( $columns ) ) {
887
+ return $columns;
888
+ }
889
+
890
+ return self::_default_hidden_columns();
891
+ }
892
+
893
+ /**
894
+ * Returns an array where the key is the column that needs to be sortable
895
+ * and the value is db column to sort by. Also notes the current sort column,
896
+ * if set.
897
+ *
898
+ * @since 1.40
899
+ *
900
+ * @return array Sortable column information,e.g.,
901
+ * 'slugs'=>array('data_values',boolean)
902
+ */
903
+ function get_sortable_columns( ) {
904
+ $columns = MLAMime::$default_sortable_view_columns;
905
+
906
+ if ( isset( $_REQUEST['orderby'] ) ) {
907
+ $needle = array( $_REQUEST['orderby'], false );
908
+ $key = array_search( $needle, $columns );
909
+ if ( $key ) {
910
+ $columns[ $key ][ 1 ] = true;
911
+ }
912
+ } else {
913
+ $columns['menu_order'][ 1 ] = true;
914
+ }
915
+
916
+ return $columns;
917
+ }
918
+
919
+ /**
920
+ * Get an associative array ( option_name => option_title ) with the list
921
+ * of bulk actions available on this table.
922
+ *
923
+ * @since 1.40
924
+ *
925
+ * @return array Contains all the bulk actions: 'slugs'=>'Visible Titles'
926
+ */
927
+ function get_bulk_actions( ) {
928
+ $actions = array();
929
+
930
+ $actions['edit'] = __( 'Edit', 'media-library-assistant' );
931
+ $actions['delete'] = __( 'Delete Permanently', 'media-library-assistant' );
932
+
933
+ return $actions;
934
+ }
935
+
936
+ /**
937
+ * Prepares the list of items for displaying
938
+ *
939
+ * This is where you prepare your data for display. This method will usually
940
+ * be used to query the database, sort and filter the data, and generally
941
+ * get it ready to be displayed. At a minimum, we should set $this->items and
942
+ * $this->set_pagination_args().
943
+ *
944
+ * @since 1.40
945
+ *
946
+ * @return void
947
+ */
948
+ function prepare_items( ) {
949
+ $this->_column_headers = array(
950
+ $this->get_columns(),
951
+ $this->get_hidden_columns(),
952
+ $this->get_sortable_columns()
953
+ );
954
+
955
+ /*
956
+ * REQUIRED for pagination.
957
+ */
958
+ $total_items = MLAMime::mla_count_view_items( $_REQUEST );
959
+ $user = get_current_user_id();
960
+ $screen = get_current_screen();
961
+ $option = $screen->get_option( 'per_page', 'option' );
962
+ if ( is_string( $option ) ) {
963
+ $per_page = get_user_meta( $user, $option, true );
964
+ } else {
965
+ $per_page = 10;
966
+ }
967
+
968
+ if ( empty( $per_page ) || $per_page < 1 ) {
969
+ $per_page = $screen->get_option( 'per_page', 'default' );
970
+ }
971
+
972
+ /*
973
+ * REQUIRED. We also have to register our pagination options & calculations.
974
+ */
975
+ $this->set_pagination_args( array(
976
+ 'total_items' => $total_items,
977
+ 'per_page' => $per_page,
978
+ 'total_pages' => ceil( $total_items / $per_page )
979
+ ) );
980
+
981
+ $current_page = $this->get_pagenum();
982
+
983
+ /*
984
+ * REQUIRED. Assign sorted and paginated data to the items property, where
985
+ * it can be used by the rest of the class.
986
+ */
987
+ $this->items = MLAMime::mla_query_view_items( $_REQUEST, ( ( $current_page - 1 ) * $per_page ), $per_page );
988
+ }
989
+
990
+ /**
991
+ * Generates (echoes) content for a single row of the table
992
+ *
993
+ * @since 1.40
994
+ *
995
+ * @param object the current item
996
+ *
997
+ * @return void Echoes the row HTML
998
+ */
999
+ function single_row( $item ) {
1000
+ static $row_class = '';
1001
+ $row_class = ( $row_class == '' ? ' class="alternate"' : '' );
1002
+
1003
+ echo '<tr id="view-' . $item->post_ID . '"' . $row_class . '>';
1004
+ echo parent::single_row_columns( $item );
1005
+ echo '</tr>';
1006
+ }
1007
+ } // class MLA_View_List_Table
1008
+
1009
+ /*
1010
+ * Actions are added here, when the source file is loaded, because the MLA_View_List_Table
1011
+ * object is created too late to be useful.
1012
+ */
1013
+
1014
+ /*
1015
+ * Actions are added here, when the source file is loaded, because the MLA_Template_List_Table
1016
+ * object is created too late to be useful.
1017
+ */
1018
+ add_action( 'admin_enqueue_scripts', 'MLASettings_View::mla_admin_enqueue_scripts' );
1019
+ add_action( 'admin_init', 'MLA_View_List_Table::mla_admin_init' );
1020
+ ?>
includes/class-mla-settings.php CHANGED
@@ -22,15 +22,6 @@ class MLASettings {
22
  */
23
  const JAVASCRIPT_INLINE_EDIT_VIEW_SLUG = 'mla-inline-edit-view-scripts';
24
 
25
- /**
26
- * Object name for localizing JavaScript - MLA View List Table
27
- *
28
- * @since 1.40
29
- *
30
- * @var string
31
- */
32
- const JAVASCRIPT_INLINE_EDIT_VIEW_OBJECT = 'mla_inline_edit_view_vars';
33
-
34
  /**
35
  * Slug for localizing and enqueueing JavaScript - MLA Upload List Table
36
  *
@@ -40,15 +31,6 @@ class MLASettings {
40
  */
41
  const JAVASCRIPT_INLINE_EDIT_UPLOAD_SLUG = 'mla-inline-edit-upload-scripts';
42
 
43
- /**
44
- * Object name for localizing JavaScript - MLA Upload List Table
45
- *
46
- * @since 1.40
47
- *
48
- * @var string
49
- */
50
- const JAVASCRIPT_INLINE_EDIT_UPLOAD_OBJECT = 'mla_inline_edit_upload_vars';
51
-
52
  /**
53
  * Slug for localizing and enqueueing JavaScript - MLA Custom tab
54
  *
@@ -93,6 +75,8 @@ class MLASettings {
93
  * @return void
94
  */
95
  public static function initialize( ) {
 
 
96
  //add_action( 'admin_page_access_denied', 'MLASettings::mla_admin_page_access_denied_action' );
97
  add_action( 'admin_init', 'MLASettings::mla_admin_init_action' );
98
  add_action( 'admin_menu', 'MLASettings::mla_admin_menu_action' );
@@ -100,6 +84,46 @@ class MLASettings {
100
  add_filter( 'set-screen-option', 'MLASettings::mla_set_screen_option_filter', 10, 3 ); // $status, $option, $value
101
  add_filter( 'screen_options_show_screen', 'MLASettings::mla_screen_options_show_screen_filter', 10, 2 ); // $show_screen, $this
102
  self::_version_upgrade();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  }
104
 
105
  /**
@@ -321,10 +345,10 @@ class MLASettings {
321
  * @return void
322
  */
323
  public static function mla_admin_init_action() {
324
- add_action( 'wp_ajax_' . self::JAVASCRIPT_INLINE_EDIT_VIEW_SLUG, 'MLASettings::mla_inline_edit_view_action' );
325
- add_action( 'wp_ajax_' . self::JAVASCRIPT_INLINE_EDIT_UPLOAD_SLUG, 'MLASettings::mla_inline_edit_upload_action' );
326
- add_action( 'wp_ajax_' . self::JAVASCRIPT_INLINE_MAPPING_CUSTOM_SLUG, 'MLASettings::mla_inline_mapping_custom_action' );
327
- add_action( 'wp_ajax_' . self::JAVASCRIPT_INLINE_MAPPING_IPTC_EXIF_SLUG, 'MLASettings::mla_inline_mapping_iptc_exif_action' );
328
  }
329
 
330
  /**
@@ -353,106 +377,6 @@ class MLASettings {
353
  }
354
 
355
  wp_enqueue_style( MLACore::STYLESHEET_SLUG );
356
-
357
- /*
358
- * Initialize common script variables
359
- */
360
- $script_variables = array(
361
- 'error' => __( 'Error while making the changes.', 'media-library-assistant' ),
362
- 'ntdeltitle' => __( 'Remove From Bulk Edit', 'media-library-assistant' ),
363
- 'notitle' => '(' . __( 'no slug', 'media-library-assistant' ) . ')',
364
- 'comma' => _x( ',', 'tag_delimiter', 'media-library-assistant' ),
365
- 'useSpinnerClass' => false,
366
- 'ajax_nonce' => wp_create_nonce( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME )
367
- );
368
-
369
- if ( version_compare( get_bloginfo( 'version' ), '4.2', '>=' ) ) {
370
- $script_variables['useSpinnerClass'] = true;
371
- }
372
-
373
- $mapping_variables = array(
374
- 'bulkChunkSize' => MLACore::mla_get_option( MLACoreOptions::MLA_BULK_CHUNK_SIZE ),
375
- 'bulkWaiting' => __( 'Waiting', 'media-library-assistant' ),
376
- 'bulkRunning' => __( 'Running', 'media-library-assistant' ),
377
- 'bulkComplete' => __( 'Complete', 'media-library-assistant' ),
378
- 'bulkUnchanged' => __( 'Unchanged', 'media-library-assistant' ),
379
- 'bulkSuccess' => __( 'Succeeded', 'media-library-assistant' ),
380
- 'bulkFailure' => __( 'Failed', 'media-library-assistant' ),
381
- 'bulkSkip' => __( 'Skipped', 'media-library-assistant' ),
382
- 'bulkRedone' => __( 'Reprocessed', 'media-library-assistant' ),
383
- 'bulkCanceled' => __( 'CANCELED', 'media-library-assistant' ),
384
- );
385
-
386
-
387
- $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
388
-
389
- /*
390
- * Select tab-specific scripts and variables
391
- */
392
- switch ( $_REQUEST['mla_tab'] ) {
393
- case 'view':
394
- wp_enqueue_script( self::JAVASCRIPT_INLINE_EDIT_VIEW_SLUG,
395
- MLA_PLUGIN_URL . "js/mla-inline-edit-view-scripts{$suffix}.js",
396
- array( 'wp-lists', 'suggest', 'jquery' ), MLACore::CURRENT_MLA_VERSION, false );
397
-
398
- $script_variables['fields'] = array( 'original_slug', 'slug', 'singular', 'plural', 'specification', 'menu_order' );
399
- $script_variables['checkboxes'] = array( 'post_mime_type', 'table_view' );
400
- $script_variables['ajax_action'] = self::JAVASCRIPT_INLINE_EDIT_VIEW_SLUG;
401
-
402
- wp_localize_script( self::JAVASCRIPT_INLINE_EDIT_VIEW_SLUG,
403
- self::JAVASCRIPT_INLINE_EDIT_VIEW_OBJECT, $script_variables );
404
- return;
405
- case 'upload':
406
- wp_enqueue_script( self::JAVASCRIPT_INLINE_EDIT_UPLOAD_SLUG,
407
- MLA_PLUGIN_URL . "js/mla-inline-edit-upload-scripts{$suffix}.js",
408
- array( 'wp-lists', 'suggest', 'jquery' ), MLACore::CURRENT_MLA_VERSION, false );
409
-
410
- $script_variables['fields'] = array( 'original_slug', 'slug', 'mime_type', 'icon_type', 'core_type', 'mla_type', 'source', 'standard_source' );
411
- $script_variables['checkboxes'] = array( 'disabled' );
412
- $script_variables['ajax_action'] = self::JAVASCRIPT_INLINE_EDIT_UPLOAD_SLUG;
413
-
414
- wp_localize_script( self::JAVASCRIPT_INLINE_EDIT_UPLOAD_SLUG,
415
- self::JAVASCRIPT_INLINE_EDIT_UPLOAD_OBJECT, $script_variables );
416
- return;
417
- case 'custom_field':
418
- wp_enqueue_script( self::JAVASCRIPT_INLINE_MAPPING_CUSTOM_SLUG,
419
- MLA_PLUGIN_URL . "js/mla-inline-mapping-scripts{$suffix}.js",
420
- array( 'jquery' ), MLACore::CURRENT_MLA_VERSION, false );
421
-
422
- $tab_variables = array(
423
- 'page' => 'mla-settings-menu-custom_field',
424
- 'mla_tab' => 'custom_field',
425
- 'screen' => 'settings_page_mla-settings-menu-custom_field',
426
- 'ajax_action' => self::JAVASCRIPT_INLINE_MAPPING_CUSTOM_SLUG,
427
- 'fieldsId' => '#mla-display-settings-custom-field-tab',
428
- 'totalItems' => $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE `post_type` = 'attachment'" )
429
- );
430
-
431
- $script_variables = array_merge( $script_variables, $mapping_variables, $tab_variables );
432
-
433
- wp_localize_script( self::JAVASCRIPT_INLINE_MAPPING_CUSTOM_SLUG,
434
- self::JAVASCRIPT_INLINE_MAPPING_OBJECT, $script_variables );
435
- return;
436
- case 'iptc_exif':
437
- wp_enqueue_script( self::JAVASCRIPT_INLINE_MAPPING_IPTC_EXIF_SLUG,
438
- MLA_PLUGIN_URL . "js/mla-inline-mapping-scripts{$suffix}.js",
439
- array( 'jquery' ), MLACore::CURRENT_MLA_VERSION, false );
440
-
441
- $tab_variables = array(
442
- 'page' => 'mla-settings-menu-iptc_exif',
443
- 'mla_tab' => 'iptc_exif',
444
- 'screen' => 'settings_page_mla-settings-menu-iptc_exif',
445
- 'ajax_action' => self::JAVASCRIPT_INLINE_MAPPING_IPTC_EXIF_SLUG,
446
- 'fieldsId' => '#mla-display-settings-iptc-exif-tab',
447
- 'totalItems' => $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE `post_type` = 'attachment' AND ( `post_mime_type` LIKE 'image/%' OR `post_mime_type` LIKE 'application/%pdf%' )" ),
448
- );
449
-
450
- $script_variables = array_merge( $script_variables, $mapping_variables, $tab_variables );
451
-
452
- wp_localize_script( self::JAVASCRIPT_INLINE_MAPPING_IPTC_EXIF_SLUG,
453
- self::JAVASCRIPT_INLINE_MAPPING_OBJECT, $script_variables );
454
- return;
455
- }
456
  }
457
 
458
  /**
@@ -476,7 +400,7 @@ class MLASettings {
476
  $tab = 'general';
477
  }
478
 
479
- $tab = self::mla_get_options_tablist( $tab ) ? '-' . $tab : '-general';
480
  self::$current_page_hook = add_submenu_page( 'options-general.php', __( 'Media Library Assistant', 'media-library-assistant' ) . ' ' . __( 'Settings', 'media-library-assistant' ), __( 'Media Library Assistant', 'media-library-assistant' ), 'manage_options', MLACoreOptions::MLA_SETTINGS_SLUG . $tab, 'MLASettings::mla_render_settings_page' );
481
  add_action( 'load-' . self::$current_page_hook, 'MLASettings::mla_add_menu_options_action' );
482
  add_action( 'load-' . self::$current_page_hook, 'MLASettings::mla_add_help_tab_action' );
@@ -525,6 +449,17 @@ class MLASettings {
525
 
526
  add_screen_option( $option, $args );
527
  } // upload
 
 
 
 
 
 
 
 
 
 
 
528
  elseif ( 'documentation' == $_REQUEST['mla_tab'] ) {
529
  if ( isset( $_REQUEST['mla-example-display'] ) || isset( $_REQUEST['mla-example-search'] ) ) {
530
  $option = 'per_page';
@@ -551,10 +486,9 @@ class MLASettings {
551
  public static function mla_add_help_tab_action( ) {
552
  $screen = get_current_screen();
553
 
554
- /*
555
- * Is this our page and the Views, Uploads or Documentation tab?
556
- */
557
- if ( ! in_array( $screen->id, array( 'settings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-view', 'settings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-upload', 'settings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-documentation' ) ) ) {
558
  return;
559
  }
560
 
@@ -569,7 +503,7 @@ class MLASettings {
569
  $file_suffix = str_replace( '-documentation', '-example', $file_suffix );
570
  } elseif ( isset( $_REQUEST['mla_admin_action'] ) ) {
571
  switch ( $_REQUEST['mla_admin_action'] ) {
572
- case MLA::MLA_ADMIN_SINGLE_EDIT_DISPLAY:
573
  $file_suffix .= '-edit';
574
  break;
575
  } // switch
@@ -605,7 +539,7 @@ class MLASettings {
605
  );
606
  } else {
607
  /* translators: 1: ERROR tag 2: function name 3: template key */
608
- error_log( sprintf( _x( '%1$s: %2$s discarding "%3$s"; no title/order', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'mla_add_help_tab_action', $id ), 0 );
609
  }
610
  }
611
 
@@ -647,356 +581,13 @@ class MLASettings {
647
  * @return string|void New value if this is our option, otherwise nothing
648
  */
649
  public static function mla_set_screen_option_filter( $status, $option, $value ) {
650
- if ( in_array( $option, array ( 'mla_views_per_page', 'mla_uploads_per_page', 'mla_types_per_page', 'mla_example_plugins_per_page' ) ) ) {
651
  return $value;
652
  } elseif ( $status ) {
653
  return $status;
654
  }
655
  }
656
 
657
- /**
658
- * Ajax handler for Post MIME Types inline editing (quick and bulk edit)
659
- *
660
- * Adapted from wp_ajax_inline_save in /wp-admin/includes/ajax-actions.php
661
- *
662
- * @since 1.40
663
- *
664
- * @return void echo HTML <tr> markup for updated row or error message, then die()
665
- */
666
- public static function mla_inline_edit_view_action() {
667
- set_current_screen( $_REQUEST['screen'] );
668
-
669
- check_ajax_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
670
-
671
- if ( empty( $_REQUEST['original_slug'] ) ) {
672
- echo __( 'ERROR', 'media-library-assistant' ) . ': ' . __( 'No view slug found', 'media-library-assistant' );
673
- die();
674
- }
675
-
676
- $request = array( 'original_slug' => $_REQUEST['original_slug'] );
677
- $request['slug'] = $_REQUEST['slug'];
678
- $request['specification'] = $_REQUEST['specification'];
679
- $request['singular'] = $_REQUEST['singular'];
680
- $request['plural'] = $_REQUEST['plural'];
681
- $request['post_mime_type'] = isset( $_REQUEST['post_mime_type'] ) && ( '1' == $_REQUEST['post_mime_type'] );
682
- $request['table_view'] = isset( $_REQUEST['table_view'] ) && ( '1' == $_REQUEST['table_view'] );
683
- $request['menu_order'] = $_REQUEST['menu_order'];
684
- $results = MLAMime::mla_update_post_mime_type( $request );
685
-
686
- if ( false === strpos( $results['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
687
- $new_item = (object) MLAMime::mla_get_post_mime_type( $_REQUEST['slug'] );
688
- } else {
689
- $new_item = (object) MLAMime::mla_get_post_mime_type( $_REQUEST['original_slug'] );
690
- }
691
-
692
- $new_item->post_ID = $_REQUEST['post_ID'];
693
-
694
- // Create an instance of our package class and echo the new HTML
695
- $MLAListViewTable = new MLA_View_List_Table();
696
- $MLAListViewTable->single_row( $new_item );
697
- die(); // this is required to return a proper result
698
- }
699
-
700
- /**
701
- * Ajax handler for Upload MIME Types inline editing (quick and bulk edit)
702
- *
703
- * Adapted from wp_ajax_inline_save in /wp-admin/includes/ajax-actions.php
704
- *
705
- * @since 1.40
706
- *
707
- * @return void echo HTML <tr> markup for updated row or error message, then die()
708
- */
709
- public static function mla_inline_edit_upload_action() {
710
- set_current_screen( $_REQUEST['screen'] );
711
-
712
- check_ajax_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
713
-
714
- if ( empty( $_REQUEST['original_slug'] ) ) {
715
- echo __( 'ERROR', 'media-library-assistant' ) . ': ' . __( 'No upload slug found', 'media-library-assistant' );
716
- die();
717
- }
718
-
719
- $request = array( 'original_slug' => $_REQUEST['original_slug'] );
720
- $request['slug'] = $_REQUEST['slug'];
721
- $request['mime_type'] = $_REQUEST['mime_type'];
722
- $request['icon_type'] = $_REQUEST['icon_type'];
723
- $request['disabled'] = isset( $_REQUEST['disabled'] ) && ( '1' == $_REQUEST['disabled'] );
724
- $results = MLAMime::mla_update_upload_mime( $request );
725
-
726
- if ( false === strpos( $results['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
727
- $new_item = (object) MLAMime::mla_get_upload_mime( $_REQUEST['slug'] );
728
- } else {
729
- $new_item = (object) MLAMime::mla_get_upload_mime( $_REQUEST['original_slug'] );
730
- }
731
- $new_item->post_ID = $_REQUEST['post_ID'];
732
-
733
- // Create an instance of our package class and echo the new HTML
734
- $MLAListUploadTable = new MLA_Upload_List_Table();
735
- $MLAListUploadTable->single_row( $new_item );
736
- die(); // this is required to return a proper result
737
- }
738
-
739
- /**
740
- * Ajax handler for Custom Fields tab inline mapping
741
- *
742
- * @since 2.00
743
- *
744
- * @return void echo json response object, then die()
745
- */
746
- public static function mla_inline_mapping_custom_action() {
747
- MLACore::mla_debug_add( 'MLASettings::mla_inline_mapping_custom_action $_REQUEST = ' . var_export( $_REQUEST, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
748
- set_current_screen( $_REQUEST['screen'] );
749
- check_ajax_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
750
-
751
- /*
752
- * Convert the ajax bulk_action back to the older Submit button equivalent
753
- */
754
- if ( ! empty( $_REQUEST['bulk_action'] ) ) {
755
- if ( 'custom-field-options-map' == $_REQUEST['bulk_action'] ) {
756
- $_REQUEST['custom-field-options-map'] = __( 'Map All Rules, All Attachments Now', 'media-library-assistant' );
757
- } else {
758
- $match_count = preg_match( '/custom_field_mapping\[(.*)\]\[(.*)\]\[(.*)\]/', $_REQUEST['bulk_action'], $matches );
759
- if ( $match_count ) {
760
- $_REQUEST['custom_field_mapping'][ $matches[1] ][ $matches[2] ][ $matches[3] ] = __( 'Map All Attachments', 'media-library-assistant' );
761
- }
762
- }
763
- }
764
-
765
- /*
766
- * Check for action or submit buttons.
767
- */
768
-
769
- if ( isset( $_REQUEST['custom_field_mapping'] ) && is_array( $_REQUEST['custom_field_mapping'] ) ) {
770
- /*
771
- * Find the current chunk
772
- */
773
- $offset = isset( $_REQUEST['offset'] ) ? $_REQUEST['offset'] : 0;
774
- $length = isset( $_REQUEST['length'] ) ? $_REQUEST['length'] : 0;
775
-
776
- /*
777
- * Check for page-level submit button to map attachments.
778
- */
779
- if ( !empty( $_REQUEST['custom-field-options-map'] ) ) {
780
- $page_content = self::_process_custom_field_mapping( NULL, $offset, $length );
781
- } else {
782
- $page_content = array(
783
- 'message' => '',
784
- 'body' => '',
785
- 'processed' => 0,
786
- 'unchanged' => 0,
787
- 'success' => 0
788
- );
789
-
790
- /*
791
- * Check for single-rule action buttons
792
- */
793
- foreach ( $_REQUEST['custom_field_mapping'] as $key => $value ) {
794
- $value = stripslashes_deep( $value );
795
-
796
- if ( isset( $value['action'] ) ) {
797
- $settings = array( $key => $value );
798
- foreach ( $value['action'] as $action => $label ) {
799
- switch( $action ) {
800
- case 'map_now':
801
- $page_content = self::_process_custom_field_mapping( $settings, $offset, $length );
802
- break;
803
- case 'add_rule_map':
804
- if ( 'none' == $value['name'] ) {
805
- $page_content['message'] = __( 'Custom field no mapping rule changes detected.', 'media-library-assistant' );
806
- break;
807
- }
808
- // fallthru
809
- case 'add_field_map':
810
- if ( '' == $value['name'] ) {
811
- $page_content['message'] = __( 'Custom field no mapping rule changes detected.', 'media-library-assistant' );
812
- break;
813
- }
814
-
815
- if ( 0 == $offset ) {
816
- $page_content = self::_save_custom_field_settings( $settings );
817
- if ( false !== strpos( $page_content['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
818
- $page_content['processed'] = 0;
819
- $page_content['unchanged'] = 0;
820
- $page_content['success'] = 0;
821
- break;
822
- }
823
- }
824
-
825
- $current_values = MLACore::mla_get_option( 'custom_field_mapping' );
826
- $settings = array( $value['name'] => $current_values[$value['name']] );
827
- $map_content = self::_process_custom_field_mapping( $settings, $offset, $length );
828
- $page_content['message'] .= '<br>&nbsp;<br>' . $map_content['message'];
829
- $page_content['processed'] = $map_content['processed'];
830
- $page_content['unchanged'] = $map_content['unchanged'];
831
- $page_content['success'] = $map_content['success'];
832
- $page_content['refresh'] = true;
833
- break;
834
- default:
835
- // ignore everything else
836
- } //switch action
837
- } // foreach action
838
- } /// isset action
839
- } // foreach rule
840
- } // specific rule check
841
- } // isset custom_field_mapping
842
- else {
843
- $page_content = array(
844
- 'message' => '',
845
- 'body' => '',
846
- 'processed' => 0,
847
- 'unchanged' => 0,
848
- 'success' => 0
849
- );
850
- }
851
-
852
- $chunk_results = array(
853
- 'message' => $page_content['message'],
854
- 'processed' => $page_content['processed'],
855
- 'unchanged' => $page_content['unchanged'],
856
- 'success' => $page_content['success'],
857
- 'refresh' => isset( $page_content['refresh'] ) && true == $page_content['refresh'],
858
- );
859
-
860
- MLACore::mla_debug_add( 'MLASettings::mla_inline_mapping_custom_action $chunk_results = ' . var_export( $chunk_results, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
861
- wp_send_json_success( $chunk_results );
862
- }
863
-
864
- /**
865
- * Ajax handler for IPTC/EXIF tab inline mapping
866
- *
867
- * @since 2.00
868
- *
869
- * @return void echo json response object, then die()
870
- */
871
- public static function mla_inline_mapping_iptc_exif_action() {
872
- MLACore::mla_debug_add( 'MLASettings::mla_inline_mapping_iptc_exif_action $_REQUEST = ' . var_export( $_REQUEST, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
873
- set_current_screen( $_REQUEST['screen'] );
874
- check_ajax_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
875
-
876
- /*
877
- * Convert the ajax bulk_action back to the older Submit button equivalent
878
- */
879
- if ( ! empty( $_REQUEST['bulk_action'] ) ) {
880
- switch ( $_REQUEST['bulk_action'] ) {
881
- case 'iptc-exif-options-process-standard':
882
- $_REQUEST['iptc-exif-options-process-standard'] = __( 'Map All Attachments, Standard Fields Now', 'media-library-assistant' );
883
- break;
884
- case 'iptc-exif-options-process-taxonomy':
885
- $_REQUEST['iptc-exif-options-process-taxonomy'] = __( 'Map All Attachments, Taxonomy Terms Now', 'media-library-assistant' );
886
- break;
887
- case 'iptc-exif-options-process-custom':
888
- $_REQUEST['iptc-exif-options-process-custom'] = __( 'Map All Attachments, Custom Fields Now', 'media-library-assistant' );
889
- break;
890
- default:
891
- $match_count = preg_match( '/iptc_exif_mapping\[custom\]\[(.*)\]\[(.*)\]\[(.*)\]/', $_REQUEST['bulk_action'], $matches );
892
- if ( $match_count ) {
893
- $_REQUEST['iptc_exif_mapping']['custom'][ $matches[1] ][ $matches[2] ][ $matches[3] ] = __( 'Map All Attachments', 'media-library-assistant' );
894
- }
895
- }
896
- }
897
-
898
- /*
899
- * Check for action or submit buttons.
900
- */
901
- if ( isset( $_REQUEST['iptc_exif_mapping'] ) && is_array( $_REQUEST['iptc_exif_mapping'] ) ) {
902
- /*
903
- * Find the current chunk
904
- */
905
- $offset = isset( $_REQUEST['offset'] ) ? $_REQUEST['offset'] : 0;
906
- $length = isset( $_REQUEST['length'] ) ? $_REQUEST['length'] : 0;
907
-
908
- /*
909
- * Check for page-level submit button to map attachments.
910
- */
911
- if ( !empty( $_REQUEST['iptc-exif-options-process-standard'] ) ) {
912
- $page_content = self::_process_iptc_exif_standard( $offset, $length );
913
- } elseif ( !empty( $_REQUEST['iptc-exif-options-process-taxonomy'] ) ) {
914
- $page_content = self::_process_iptc_exif_taxonomy( $offset, $length );
915
- } elseif ( !empty( $_REQUEST['iptc-exif-options-process-custom'] ) ) {
916
- $page_content = self::_process_iptc_exif_custom( NULL, $offset, $length );
917
- } else {
918
- $page_content = array(
919
- 'message' => '',
920
- 'body' => '',
921
- 'processed' => 0,
922
- 'unchanged' => 0,
923
- 'success' => 0
924
- );
925
-
926
- /*
927
- * Check for single-rule action buttons
928
- */
929
- foreach ( $_REQUEST['iptc_exif_mapping']['custom'] as $key => $value ) {
930
- $value = stripslashes_deep( $value );
931
-
932
- if ( isset( $value['action'] ) ) {
933
- $settings = array( 'custom' => array( $key => $value ) );
934
- foreach ( $value['action'] as $action => $label ) {
935
- switch( $action ) {
936
- case 'map_now':
937
- $page_content = self::_process_iptc_exif_custom( $settings, $offset, $length );
938
- break;
939
- case 'add_rule_map':
940
- if ( 'none' == $value['name'] ) {
941
- $page_content['message'] = __( 'IPTC/EXIF no mapping changes detected.', 'media-library-assistant' );
942
- break;
943
- }
944
- // fallthru
945
- case 'add_field_map':
946
- if ( '' == $value['name'] ) {
947
- $page_content['message'] = __( 'IPTC/EXIF no mapping changes detected.', 'media-library-assistant' );
948
- break;
949
- }
950
-
951
- if ( 0 == $offset ) {
952
- $page_content = self::_save_iptc_exif_custom_settings( $settings );
953
- if ( false !== strpos( $page_content['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
954
- $page_content['processed'] = 0;
955
- $page_content['unchanged'] = 0;
956
- $page_content['success'] = 0;
957
- break;
958
- }
959
- }
960
-
961
- $current_values = MLACore::mla_get_option( 'iptc_exif_mapping' );
962
- $settings = array( 'custom' => array( $value['name'] => $current_values['custom'][$value['name']] ) );
963
- $map_content = self::_process_iptc_exif_custom( $settings, $offset, $length );
964
- $page_content['message'] .= '<br>&nbsp;<br>' . $map_content['message'];
965
- $page_content['processed'] = $map_content['processed'];
966
- $page_content['unchanged'] = $map_content['unchanged'];
967
- $page_content['success'] = $map_content['success'];
968
- $page_content['refresh'] = true;
969
- break;
970
- default:
971
- // ignore everything else
972
- } //switch action
973
- } // foreach action
974
- } /// isset action
975
- } // foreach rule
976
- }
977
- } // isset custom_field_mapping
978
- else {
979
- $page_content = array(
980
- 'message' => '',
981
- 'body' => '',
982
- 'processed' => 0,
983
- 'unchanged' => 0,
984
- 'success' => 0
985
- );
986
- }
987
-
988
- $chunk_results = array(
989
- 'message' => $page_content['message'],
990
- 'processed' => $page_content['processed'],
991
- 'unchanged' => $page_content['unchanged'],
992
- 'success' => $page_content['success'],
993
- 'refresh' => isset( $page_content['refresh'] ) && true == $page_content['refresh'],
994
- );
995
-
996
- MLACore::mla_debug_add( 'MLASettings::mla_inline_mapping_iptc_exif_action $chunk_results = ' . var_export( $chunk_results, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
997
- wp_send_json_success( $chunk_results );
998
- }
999
-
1000
  /**
1001
  * Add the "Settings" link to the MLA entry in the Plugins section
1002
  *
@@ -1008,7 +599,7 @@ class MLASettings {
1008
  * @return array Updated array of links for the Plugin
1009
  */
1010
  public static function mla_add_plugin_settings_link_filter( $links, $file ) {
1011
- if ( $file == 'media-library-assistant/index.php' ) {
1012
  $settings_link = sprintf( '<a href="%s">%s</a>', admin_url( 'options-general.php?page=' . MLACoreOptions::MLA_SETTINGS_SLUG . '-general' ), __( 'Settings', 'media-library-assistant' ) );
1013
  array_unshift( $links, $settings_link );
1014
  }
@@ -1081,7 +672,7 @@ class MLASettings {
1081
  break;
1082
  default:
1083
  /* translators: 1: ERROR tag 2: function name 3: option type, e.g., radio, select, text */
1084
- error_log( sprintf( _x( '%1$s: %2$s unknown type = "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), '_save_settings(1)', var_export( $value, true ) ), 0 );
1085
  } // $value['type']
1086
  } // isset $key
1087
  else {
@@ -1118,7 +709,7 @@ class MLASettings {
1118
  break;
1119
  default:
1120
  /* translators: 1: ERROR tag 2: function name 3: option type, e.g., radio, select, text */
1121
- error_log( sprintf( _x( '%1$s: %2$s unknown type = "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), '_save_settings(2)', var_export( $value, true ) ), 0 );
1122
  } // $value['type']
1123
  } // ! isset $key
1124
 
@@ -1258,7 +849,7 @@ class MLASettings {
1258
  break;
1259
  default:
1260
  /* translators: 1: ERROR tag 2: function name 3: option type, e.g., radio, select, text */
1261
- error_log( sprintf( _x( '%1$s: %2$s unknown type = "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'mla_render_settings_page', var_export( $value, true ) ), 0 );
1262
  } //switch
1263
 
1264
  return '';
@@ -1286,7 +877,7 @@ class MLASettings {
1286
  * render => rendering function for tab messages and content. Usage:
1287
  * $tab_content = ['render']( );
1288
  *
1289
- * The array must be populated at runtime in MLASettings::mla_localize_tablist();
1290
  * localization calls cannot be placed in the "public static" array definition itself.
1291
  *
1292
  * @since 0.80
@@ -1305,15 +896,15 @@ class MLASettings {
1305
  *
1306
  * @return void
1307
  */
1308
- public static function mla_localize_tablist() {
1309
  self::$mla_tablist = array(
1310
  'general' => array( 'title' => __ ( 'General', 'media-library-assistant' ), 'render' => array( 'MLASettings', '_compose_general_tab' ) ),
1311
- 'view' => array( 'title' => __ ( 'Views', 'media-library-assistant' ), 'render' => array( 'MLASettings', '_compose_view_tab' ) ),
1312
- 'upload' => array( 'title' => __ ( 'Uploads', 'media-library-assistant' ), 'render' => array( 'MLASettings', '_compose_upload_tab' ) ),
1313
- 'mla_gallery' => array( 'title' => __ ( 'Shortcodes', 'media-library-assistant' ), 'render' => array( 'MLASettings', '_compose_mla_gallery_tab' ) ),
1314
- 'custom_field' => array( 'title' => __ ( 'Custom Fields', 'media-library-assistant' ), 'render' => array( 'MLASettings', '_compose_custom_field_tab' ) ),
1315
- 'iptc_exif' => array( 'title' => 'IPTC/EXIF', 'render' => array( 'MLASettings', '_compose_iptc_exif_tab' ) ),
1316
- 'documentation' => array( 'title' => __ ( 'Documentation', 'media-library-assistant' ), 'render' => array( 'MLASettings', '_compose_documentation_tab' ) ),
1317
  'debug' => array( 'title' => __ ( 'Debug', 'media-library-assistant' ), 'render' => array( 'MLASettings', '_compose_debug_tab' ) ),
1318
  );
1319
  }
@@ -1327,7 +918,7 @@ class MLASettings {
1327
  *
1328
  * @return array|false The entire tablist ( $tab = NULL ), a single tab entry or false if not found/not allowed
1329
  */
1330
- private static function mla_get_options_tablist( $tab = NULL ) {
1331
  if ( is_string( $tab ) ) {
1332
  if ( isset( self::$mla_tablist[ $tab ] ) ) {
1333
  $results = self::$mla_tablist[ $tab ];
@@ -1362,7 +953,7 @@ class MLASettings {
1362
  private static function _compose_settings_tabs( $active_tab = 'general' ) {
1363
  $tablist_item = self::$page_template_array['tablist-item'];
1364
  $tabs = '';
1365
- foreach ( self::mla_get_options_tablist() as $key => $item ) {
1366
  $item_values = array(
1367
  'data-tab-id' => $key,
1368
  'nav-tab-active' => ( $active_tab == $key ) ? 'nav-tab-active' : '',
@@ -1535,7 +1126,7 @@ class MLASettings {
1535
  *
1536
  * @return string|false The action name or False if no action was selected
1537
  */
1538
- private static function _current_bulk_action( ) {
1539
  $action = false;
1540
 
1541
  if ( isset( $_REQUEST['action'] ) ) {
@@ -1558,1755 +1149,99 @@ class MLASettings {
1558
  }
1559
 
1560
  /**
1561
- * Compose the Edit View tab content for the Settings subpage
 
 
1562
  *
1563
- * @since 1.40
1564
  *
1565
- * @param array data values for the item
1566
- * @param string Display template
1567
- *
1568
- * @return array 'message' => status/error messages, 'body' => tab content
1569
  */
1570
- private static function _compose_edit_view_tab( $view, $template ) {
1571
- $page_values = array(
1572
- 'Edit View' => __( 'Edit View', 'media-library-assistant' ),
1573
- 'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-view&mla_tab=view',
1574
- 'action' => MLA::MLA_ADMIN_SINGLE_EDIT_UPDATE,
1575
- 'original_slug' => $view['slug'],
1576
- '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
1577
- 'Slug' => __( 'Slug', 'media-library-assistant' ),
1578
- 'The slug is' => __( 'The &#8220;slug&#8221; is the URL-friendly, unique key for the view. It must be all lowercase and contain only letters, numbers, periods (.), slashes (/) and hyphens (-). For &#8220;<strong>Post MIME Type</strong>&#8221; views, the slug is also the MIME type specification and <strong>must be a valid MIME</strong> type, e.g., &#8220;image&#8221; or &#8220;image/jpeg&#8221;.', 'media-library-assistant' ),
1579
- 'Singular Label' => __( 'Singular Label', 'media-library-assistant' ),
1580
- 'Plural Label' => __( 'Plural Label', 'media-library-assistant' ),
1581
- 'The labels' => __( 'The labels, e.g., &#8220;Image&#8221; and &#8220;Images&#8221; are used for column headers and other display purposes.', 'media-library-assistant' ),
1582
- 'Specification' => __( 'Specification', 'media-library-assistant' ),
1583
- 'If the specification' => __( 'If the MIME type specification differs from the slug, enter it here. You may include multiple MIME types, e.g., &#8220;audio,video&#8221; and/or wildcard specs, e.g., &#8220;*/*ms*&#8221;. This field will be ignored if the Post MIME Type box is checked.', 'media-library-assistant' ),
1584
- 'Post MIME Type' => __( 'Post MIME Type', 'media-library-assistant' ),
1585
- 'Check Post MIME' => __( 'Check this box if you want to add this entry to the list of MIME types returned by wp_get_mime_types().', 'media-library-assistant' ),
1586
- 'Table View' => __( 'Table View', 'media-library-assistant' ),
1587
- 'Check Table View' => __( 'Check this box if you want to add this entry to the list of Media/Assistant table views.', 'media-library-assistant' ),
1588
- 'Menu Order' => __( 'Menu Order', 'media-library-assistant' ),
1589
- 'You can choose' => __( 'You can choose your own table view order by entering a number (1 for first, etc.) in this field.', 'media-library-assistant' ),
1590
- 'Description' => __( 'Description', 'media-library-assistant' ),
1591
- 'The description can' => __( 'The description can contain any documentation or notes you need to understand or use the item.', 'media-library-assistant' ),
1592
- 'Update' => __( 'Update', 'media-library-assistant' ),
1593
- 'Cancel' => __( 'Cancel', 'media-library-assistant' ),
1594
- );
1595
 
1596
- foreach ( $view as $key => $value ) {
1597
- switch ( $key ) {
1598
- case 'post_mime_type':
1599
- case 'table_view':
1600
- $page_values[ $key ] = $value ? 'checked="checked"' : '';
1601
- break;
1602
- default:
1603
- $page_values[ $key ] = $value;
1604
- }
1605
- }
1606
 
1607
- return array(
1608
- 'message' => '',
1609
- 'body' => MLAData::mla_parse_template( $template, $page_values )
1610
  );
1611
- }
 
 
 
 
 
 
 
1612
 
1613
  /**
1614
- * Compose the Post MIME Type Views tab content for the Settings subpage
1615
  *
1616
- * @since 1.40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1617
  *
1618
  * @return array 'message' => status/error messages, 'body' => tab content
1619
  */
1620
- private static function _compose_view_tab( ) {
1621
- $page_template_array = MLACore::mla_load_template( 'admin-display-settings-view-tab.tpl' );
1622
- if ( ! is_array( $page_template_array ) ) {
1623
- /* translators: 1: ERROR tag 2: function name 3: non-array value */
1624
- error_log( sprintf( _x( '%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'MLASettings::_compose_view_tab', var_export( $page_template_array, true ) ), 0 );
1625
- return '';
1626
- }
1627
 
1628
- /*
1629
- * Convert checkbox values, if present
1630
- */
1631
- if ( isset( $_REQUEST['mla_view_item'] ) ) {
1632
- $_REQUEST['mla_view_item']['post_mime_type'] = isset( $_REQUEST['mla_view_item']['post_mime_type'] );
1633
- $_REQUEST['mla_view_item']['table_view'] = isset( $_REQUEST['mla_view_item']['table_view'] );
1634
- }
1635
 
1636
  /*
1637
- * Set default values, check for Add New Post MIME Type View button
1638
  */
1639
- $add_form_values = array (
1640
- 'slug' => '',
1641
- 'singular' => '',
1642
- 'plural' => '',
1643
- 'specification' => '',
1644
- 'post_mime_type' => 'checked="checked"',
1645
- 'table_view' => 'checked="checked"',
1646
- 'menu_order' => '',
1647
- 'description' => ''
1648
- );
1649
-
1650
- if ( !empty( $_REQUEST['mla-view-options-save'] ) ) {
1651
- check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
1652
- $page_content = self::_save_view_settings( );
1653
- } elseif ( !empty( $_REQUEST['mla-add-view-submit'] ) ) {
1654
  check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
1655
- $page_content = MLAMime::mla_add_post_mime_type( $_REQUEST['mla_view_item'] );
1656
- if ( false !== strpos( $page_content['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
1657
- $add_form_values = $_REQUEST['mla_view_item'];
1658
- $add_form_values['post_mime_type'] = $add_form_values['post_mime_type'] ? 'checked="checked"' : '';
1659
- $add_form_values['table_view'] = $add_form_values['table_view'] ? 'checked="checked"' : '';
1660
- }
1661
- } else {
1662
- $page_content = array(
1663
- 'message' => '',
1664
- 'body' => ''
1665
- );
1666
  }
1667
 
1668
  /*
1669
- * Process bulk actions that affect an array of items
1670
  */
1671
- $bulk_action = self::_current_bulk_action();
1672
- if ( $bulk_action && ( $bulk_action != 'none' ) ) {
1673
- if ( isset( $_REQUEST['cb_mla_item_ID'] ) ) {
1674
- /*
1675
- * Convert post-ID to slug; separate loop required because delete changes post_IDs
1676
- */
1677
- $slugs = array();
1678
- foreach ( $_REQUEST['cb_mla_item_ID'] as $post_ID )
1679
- $slugs[] = MLAMime::mla_get_post_mime_type_slug( $post_ID );
1680
-
1681
- foreach ( $slugs as $slug ) {
1682
- switch ( $bulk_action ) {
1683
- case 'delete':
1684
- $item_content = MLAMime::mla_delete_post_mime_type( $slug );
1685
- break;
1686
- case 'edit':
1687
- $request = array( 'slug' => $slug );
1688
- if ( '-1' != $_REQUEST['post_mime_type'] ) {
1689
- $request['post_mime_type'] = '1' == $_REQUEST['post_mime_type'];
1690
- }
1691
- if ( '-1' != $_REQUEST['table_view'] ) {
1692
- $request['table_view'] = '1' == $_REQUEST['table_view'];
1693
- }
1694
- if ( !empty( $_REQUEST['menu_order'] ) ) {
1695
- $request['menu_order'] = $_REQUEST['menu_order'];
1696
- }
1697
- $item_content = MLAMime::mla_update_post_mime_type( $request );
1698
- break;
1699
- default:
1700
- $item_content = array(
1701
- /* translators: 1: bulk_action, e.g., delete, edit, restore, trash */
1702
- 'message' => sprintf( __( 'Unknown bulk action %1$s', 'media-library-assistant' ), $bulk_action ),
1703
- 'body' => ''
1704
- );
1705
- } // switch $bulk_action
1706
-
1707
- $page_content['message'] .= $item_content['message'] . '<br>';
1708
- } // foreach cb_attachment
1709
- } // isset cb_attachment
1710
- else {
1711
- /* translators: 1: action name, e.g., edit */
1712
- $page_content['message'] = sprintf( __( 'Bulk Action %1$s - no items selected.', 'media-library-assistant' ), $bulk_action );
1713
  }
1714
- } // $bulk_action
 
 
 
 
1715
 
1716
  /*
1717
- * Process row-level actions that affect a single item
1718
- */
1719
- if ( !empty( $_REQUEST['mla_admin_action'] ) ) {
1720
- check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
1721
-
1722
- switch ( $_REQUEST['mla_admin_action'] ) {
1723
- case MLACore::MLA_ADMIN_SINGLE_DELETE:
1724
- $page_content = MLAMime::mla_delete_post_mime_type( $_REQUEST['mla_item_slug'] );
1725
- break;
1726
- case MLA::MLA_ADMIN_SINGLE_EDIT_DISPLAY:
1727
- $view = MLAMime::mla_get_post_mime_type( $_REQUEST['mla_item_slug'] );
1728
- $page_content = self::_compose_edit_view_tab( $view, $page_template_array['single-item-edit'] );
1729
- break;
1730
- case MLA::MLA_ADMIN_SINGLE_EDIT_UPDATE:
1731
- if ( !empty( $_REQUEST['update'] ) ) {
1732
- $page_content = MLAMime::mla_update_post_mime_type( $_REQUEST['mla_view_item'] );
1733
- if ( false !== strpos( $page_content['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
1734
- $message = $page_content['message'];
1735
- $page_content = self::_compose_edit_view_tab( $_REQUEST['mla_view_item'], $page_template_array['single-item-edit'] );
1736
- $page_content['message'] = $message;
1737
- }
1738
- } else {
1739
- $page_content = array(
1740
- /* translators: 1: view name/slug */
1741
- 'message' => sprintf( __( 'Edit view "%1$s" cancelled.', 'media-library-assistant' ), $_REQUEST['mla_view_item']['original_slug'] ),
1742
- 'body' => ''
1743
- );
1744
- }
1745
- break;
1746
- default:
1747
- $page_content = array(
1748
- /* translators: 1: bulk_action, e.g., single_item_delete, single_item_edit */
1749
- 'message' => sprintf( __( 'Unknown mla_admin_action - "%1$s"', 'media-library-assistant' ), $_REQUEST['mla_admin_action'] ),
1750
- 'body' => ''
1751
- );
1752
- break;
1753
- } // switch ($_REQUEST['mla_admin_action'])
1754
- } // (!empty($_REQUEST['mla_admin_action'])
1755
-
1756
- if ( !empty( $page_content['body'] ) ) {
1757
- return $page_content;
1758
- }
1759
-
1760
- /*
1761
- * Check for disabled status
1762
- */
1763
- if ( 'checked' != MLACore::mla_get_option( MLACoreOptions::MLA_ENABLE_POST_MIME_TYPES ) ) {
1764
- /*
1765
- * Fill in with any page-level options
1766
- */
1767
- $options_list = '';
1768
- foreach ( MLACoreOptions::$mla_option_definitions as $key => $value ) {
1769
- if ( 'view' == $value['tab'] ) {
1770
- $options_list .= self::mla_compose_option_row( $key, $value );
1771
- }
1772
- }
1773
-
1774
- $page_values = array(
1775
- 'Support is disabled' => __( 'View and Post MIME Type Support is disabled', 'media-library-assistant' ),
1776
- 'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-view&mla_tab=view',
1777
- 'options_list' => $options_list,
1778
- 'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
1779
- '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
1780
- );
1781
-
1782
- $page_content['body'] .= MLAData::mla_parse_template( $page_template_array['view-disabled'], $page_values );
1783
- return $page_content;
1784
- }
1785
-
1786
- /*
1787
- * Display the View Table
1788
- */
1789
- $_SERVER['REQUEST_URI'] = remove_query_arg( array(
1790
- 'mla_admin_action',
1791
- 'mla_item_slug',
1792
- 'mla_item_ID',
1793
- '_wpnonce',
1794
- '_wp_http_referer',
1795
- 'action',
1796
- 'action2',
1797
- 'cb_mla_item_ID',
1798
- 'mla-optional-uploads-search',
1799
- 'mla-optional-uploads-display'
1800
- ), $_SERVER['REQUEST_URI'] );
1801
-
1802
- // Create an instance of our package class
1803
- $MLAListViewTable = new MLA_View_List_Table();
1804
-
1805
- // Fetch, prepare, sort, and filter our data
1806
- $MLAListViewTable->prepare_items();
1807
- $MLAListViewTable->views();
1808
-
1809
- /*
1810
- * Start with any page-level options
1811
- */
1812
- $options_list = '';
1813
- foreach ( MLACoreOptions::$mla_option_definitions as $key => $value ) {
1814
- if ( 'view' == $value['tab'] ) {
1815
- $options_list .= self::mla_compose_option_row( $key, $value );
1816
- }
1817
- }
1818
-
1819
- $page_values = array(
1820
- 'Library Views Processing' => __( 'Library Views/Post MIME Type Processing', 'media-library-assistant' ),
1821
- 'In this tab' => __( 'In this tab you can manage the list of "Post MIME Types", which are used by WordPress to define the views for the <em><strong>Media/Library</strong></em> screen and the <em><strong>Media Manager/Add Media</strong></em> "media items" drop down list. MLA&rsquo;s <em><strong>Media/Assistant</strong></em> screen uses an enhanced version of the list, <em>Table Views</em>, to support views with multiple MIME Types (e.g., "audio,video") and wildcard specifications (e.g. "*/*ms*").', 'media-library-assistant' ),
1822
- /* translators: 1: Documentation hyperlink */
1823
- 'You can find' => sprintf( __( 'You can find more information about library views, Post MIME types and how MLA and WordPress use them in the %1$s section of the Documentation or by clicking the <strong>"Help"</strong> tab in the upper-right corner of this screen.', 'media-library-assistant' ), '<a href="[+settingsURL+]?page=mla-settings-menu-documentation&amp;mla_tab=documentation#mla_views" title="' . __( 'Library View Processing documentation', 'media-library-assistant' ) . '">' . __( 'Library Views/Post MIME Type Processing', 'media-library-assistant' ) . '</a>' ),
1824
- 'settingsURL' => admin_url('options-general.php'),
1825
- 'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-view&mla_tab=view',
1826
- '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
1827
- 'results' => ! empty( $_REQUEST['s'] ) ? '<h2 class="alignleft">' . __( 'Displaying search results for', 'media-library-assistant' ) . ': "' . $_REQUEST['s'] . '"</h2>' : '',
1828
- 'Search Views' => __( 'Search Views', 'media-library-assistant' ),
1829
- 's' => isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '',
1830
- 'options_list' => $options_list,
1831
- 'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
1832
- /* translators: %s: add new View */
1833
- 'Add New View' => sprintf( __( 'Add New %1$s', 'media-library-assistant' ), __( 'View', 'media-library-assistant' ) ),
1834
- 'Slug' => __( 'Slug', 'media-library-assistant' ),
1835
- 'The slug is' => __( 'The &#8220;slug&#8221; is the URL-friendly, unique key for the view. It must be all lowercase and contain only letters, numbers, periods (.), slashes (/) and hyphens (-). For &#8220;<strong>Post MIME Type</strong>&#8221; views, the slug is also the MIME type specification and <strong>must be a valid MIME</strong> type, e.g., &#8220;image&#8221; or &#8220;image/jpeg&#8221;.', 'media-library-assistant' ),
1836
- 'Singular Label' => __( 'Singular Label', 'media-library-assistant' ),
1837
- 'Plural Label' => __( 'Plural Label', 'media-library-assistant' ),
1838
- 'The labels' => __( 'The labels, e.g., &#8220;Image&#8221; and &#8220;Images&#8221; are used for column headers and other display purposes.', 'media-library-assistant' ),
1839
- 'Specification' => __( 'Specification', 'media-library-assistant' ),
1840
- 'If the specification' => __( 'If the MIME type specification differs from the slug, enter it here. You may include multiple MIME types, e.g., &#8220;audio,video&#8221; and/or wildcard specs, e.g., &#8220;*/*ms*&#8221;. This field will be ignored if the Post MIME Type box is checked.', 'media-library-assistant' ),
1841
- 'Post MIME Type' => __( 'Post MIME Type', 'media-library-assistant' ),
1842
- 'Check Post MIME' => __( 'Check this box if you want to add this entry to the list of MIME types returned by wp_get_mime_types().', 'media-library-assistant' ),
1843
- 'Table View' => __( 'Table View', 'media-library-assistant' ),
1844
- 'Check Table View' => __( 'Check this box if you want to add this entry to the list of Media/Assistant table views.', 'media-library-assistant' ),
1845
- 'Menu Order' => __( 'Menu Order', 'media-library-assistant' ),
1846
- 'You can choose' => __( 'You can choose your own table view order by entering a number (1 for first, etc.) in this field.', 'media-library-assistant' ),
1847
- 'Description' => __( 'Description', 'media-library-assistant' ),
1848
- 'The description can' => __( 'The description can contain any documentation or notes you need to understand or use the item.', 'media-library-assistant' ),
1849
- 'Add View' => __( 'Add View', 'media-library-assistant' ),
1850
- 'colspan' => $MLAListViewTable->get_column_count(),
1851
- 'Quick Edit' => __( '<strong>Quick Edit</strong>', 'media-library-assistant' ),
1852
- 'Cancel' => __( 'Cancel', 'media-library-assistant' ),
1853
- 'Update' => __( 'Update', 'media-library-assistant' ),
1854
- 'Bulk Edit' => __( 'Bulk Edit', 'media-library-assistant' ),
1855
- 'No Change' => __( 'No Change', 'media-library-assistant' ),
1856
- 'No' => __( 'No', 'media-library-assistant' ),
1857
- 'Yes' => __( 'Yes', 'media-library-assistant' ),
1858
- );
1859
-
1860
- foreach ( $add_form_values as $key => $value ) {
1861
- $page_values[ $key ] = $value;
1862
- }
1863
- $page_content['body'] = MLAData::mla_parse_template( $page_template_array['before-table'], $page_values );
1864
-
1865
- // Now we can render the completed list table
1866
- ob_start();
1867
- $MLAListViewTable->display();
1868
- $page_content['body'] .= ob_get_contents();
1869
- ob_end_clean();
1870
-
1871
- $page_content['body'] .= MLAData::mla_parse_template( $page_template_array['after-table'], $page_values );
1872
-
1873
- return $page_content;
1874
- }
1875
-
1876
- /**
1877
- * Get an HTML select element representing a list of icon types
1878
- *
1879
- * @since 1.40
1880
- *
1881
- * @param array Display template array
1882
- * @param string HTML name attribute value
1883
- * @param string currently selected Icon Type
1884
- *
1885
- * @return string HTML select element or empty string on failure.
1886
- */
1887
- public static function mla_get_icon_type_dropdown( $templates, $name, $selection = '.none.' ) {
1888
- $option_template = $templates['icon-type-select-option'];
1889
- if ( '.nochange.' == $selection ) {
1890
- $option_values = array (
1891
- 'selected' => 'selected="selected"',
1892
- 'value' => '.none.',
1893
- 'text' => '&mdash; ' . __( 'No Change', 'media-library-assistant' ) . ' &mdash;'
1894
- );
1895
- } else {
1896
- $option_values = array (
1897
- 'selected' => ( '.none.' == $selection ) ? 'selected="selected"' : '',
1898
- 'value' => '.none.',
1899
- 'text' => '&mdash; ' . __( 'None (select a value)', 'media-library-assistant' ) . ' &mdash;'
1900
- );
1901
- }
1902
-
1903
- $options = MLAData::mla_parse_template( $option_template, $option_values );
1904
-
1905
- $icon_types = MLAMime::mla_get_current_icon_types();
1906
- foreach ( $icon_types as $icon_type ) {
1907
- $option_values = array (
1908
- 'selected' => ( $icon_type == $selection ) ? 'selected="selected"' : '',
1909
- 'value' => $icon_type,
1910
- 'text' => $icon_type
1911
- );
1912
-
1913
- $options .= MLAData::mla_parse_template( $option_template, $option_values );
1914
- } // foreach icon_type
1915
-
1916
- return MLAData::mla_parse_template( $templates['icon-type-select'], array( 'name' => $name, 'options' => $options ) );
1917
- }
1918
-
1919
- /**
1920
- * Compose the Edit Upload type tab content for the Settings subpage
1921
- *
1922
- * @since 1.40
1923
- *
1924
- * @param array data values for the item
1925
- * @param string Display template array
1926
- *
1927
- * @return array 'message' => status/error messages, 'body' => tab content
1928
- */
1929
- private static function _compose_edit_upload_tab( $item, &$templates ) {
1930
- $page_values = array(
1931
- 'Edit Upload MIME' => __( 'Edit Upload MIME Type', 'media-library-assistant' ),
1932
- 'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-upload&mla_tab=upload',
1933
- 'action' => MLA::MLA_ADMIN_SINGLE_EDIT_UPDATE,
1934
- 'original_slug' => $item['slug'],
1935
- '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
1936
- 'Extension' => __( 'Extension', 'media-library-assistant' ),
1937
- 'The extension is' => __( 'The &#8220;extension&#8221; is the file extension for this type, and a unique key for the item. It must be all lowercase and contain only letters and numbers.', 'media-library-assistant' ),
1938
- 'MIME Type' => __( 'MIME Type', 'media-library-assistant' ),
1939
- 'The MIME Type' => __( 'The MIME Type must be all lowercase and contain only letters, numbers, periods (.), slashes (/) and hyphens (-). It <strong>must be a valid MIME</strong> type, e.g., &#8220;image&#8221; or &#8220;image/jpeg&#8221;.', 'media-library-assistant' ),
1940
- 'Icon Type' => __( 'Icon Type', 'media-library-assistant' ),
1941
- 'icon_types' => self::mla_get_icon_type_dropdown( $templates, 'mla_upload_item[icon_type]', $item['icon_type'] ),
1942
- 'The Icon Type' => __( 'The Icon Type selects a thumbnail image displayed for non-image file types, such as PDF documents.', 'media-library-assistant' ),
1943
- 'Inactive' => __( 'Inactive', 'media-library-assistant' ),
1944
- 'Check this box' => __( 'Check this box if you want to remove this entry from the list of Upload MIME Types returned by get_allowed_mime_types().', 'media-library-assistant' ),
1945
- 'Description' => __( 'Description', 'media-library-assistant' ),
1946
- 'The description can' => __( 'The description can contain any documentation or notes you need to understand or use the item.', 'media-library-assistant' ),
1947
- 'Update' => __( 'Update', 'media-library-assistant' ),
1948
- 'Cancel' => __( 'Cancel', 'media-library-assistant' ),
1949
- );
1950
-
1951
- foreach ( $item as $key => $value ) {
1952
- switch ( $key ) {
1953
- case 'disabled':
1954
- $page_values[ $key ] = $value ? 'checked="checked"' : '';
1955
- break;
1956
- default:
1957
- $page_values[ $key ] = $value;
1958
- }
1959
- }
1960
-
1961
- return array(
1962
- 'message' => '',
1963
- 'body' => MLAData::mla_parse_template( $templates['single-item-edit'], $page_values )
1964
- );
1965
- }
1966
-
1967
- /**
1968
- * Compose the Optional File Upload MIME Types tab content for the Settings subpage
1969
- *
1970
- * @since 1.40
1971
- *
1972
- * @param string Display templates
1973
- *
1974
- * @return array 'message' => status/error messages, 'body' => tab content
1975
- */
1976
- private static function _compose_optional_upload_tab( $page_template_array ) {
1977
- /*
1978
- * Display the Optional Upload MIME Types Table
1979
- */
1980
- $_SERVER['REQUEST_URI'] = add_query_arg( array( 'mla-optional-uploads-display' => 'true' ), remove_query_arg( array(
1981
- 'mla_admin_action',
1982
- 'mla_item_slug',
1983
- 'mla_item_ID',
1984
- '_wpnonce',
1985
- '_wp_http_referer',
1986
- 'action',
1987
- 'action2',
1988
- 'cb_attachment',
1989
- 'mla-optional-uploads-search'
1990
- ), $_SERVER['REQUEST_URI'] ) );
1991
-
1992
- /*
1993
- * Suppress display of the hidden columns selection list
1994
- */
1995
- echo " <style type='text/css'>\r\n";
1996
- echo " form#adv-settings div.metabox-prefs,\r\n";
1997
- echo " form#adv-settings fieldset.metabox-prefs {\r\n";
1998
- echo " display: none;\r\n";
1999
- echo " }\r\n";
2000
- echo " </style>\r\n";
2001
-
2002
- // Create an instance of our package class
2003
- $MLAListUploadTable = new MLA_Upload_Optional_List_Table();
2004
-
2005
- // Fetch, prepare, sort, and filter our data
2006
- $MLAListUploadTable->prepare_items();
2007
-
2008
- $page_content = array(
2009
- 'message' => '',
2010
- 'body' => ''
2011
- );
2012
-
2013
- $page_values = array(
2014
- 'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-upload&mla_tab=upload',
2015
- '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
2016
- 'Known File Extension' => __( 'Known File Extension/MIME Type Associations', 'media-library-assistant' ),
2017
- 'results' => ! empty( $_REQUEST['s'] ) ? '<h2 class="alignleft">' . __( 'Displaying search results for', 'media-library-assistant' ) . ': "' . $_REQUEST['s'] . '"</h2>' : '',
2018
- 'Search Known MIME' => __( 'Search Known MIME Types', 'media-library-assistant' ),
2019
- 's' => isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '',
2020
- 'Search Types' => __( 'Search Types', 'media-library-assistant' ),
2021
- 'To search by' => __( 'To search by extension, use ".", e.g., ".doc"', 'media-library-assistant' ),
2022
- 'Cancel' => __( 'Cancel', 'media-library-assistant' ),
2023
- );
2024
-
2025
- $page_content['body'] = MLAData::mla_parse_template( $page_template_array['before-optional-uploads-table'], $page_values );
2026
-
2027
- // Now we can render the completed list table
2028
- ob_start();
2029
- // $MLAListUploadTable->views();
2030
- $MLAListUploadTable->display();
2031
- $page_content['body'] .= ob_get_contents();
2032
- ob_end_clean();
2033
-
2034
- $page_content['body'] .= MLAData::mla_parse_template( $page_template_array['after-optional-uploads-table'], $page_values );
2035
-
2036
- return $page_content;
2037
- }
2038
-
2039
- /**
2040
- * Process an Optional Upload MIME Type selection
2041
- *
2042
- * @since 1.40
2043
- *
2044
- * @param integer MLA Optional Upload MIME Type ID
2045
- *
2046
- * @return array 'message' => status/error messages, 'body' => tab content
2047
- */
2048
- private static function _process_optional_upload_mime( $ID ) {
2049
- $optional_type = MLAMime::mla_get_optional_upload_mime( $ID );
2050
- $optional_type['disabled'] = false;
2051
-
2052
- if ( false === $upload_type = MLAMime::mla_get_upload_mime( $optional_type['slug'] ) ) {
2053
- $optional_type['icon_type'] = '.none.';
2054
- return MLAMime::mla_add_upload_mime( $optional_type );
2055
- }
2056
-
2057
- $optional_type['original_slug'] = $optional_type['slug'];
2058
- return MLAMime::mla_update_upload_mime( $optional_type );
2059
- }
2060
-
2061
- /**
2062
- * Compose the File Upload MIME Types tab content for the Settings subpage
2063
- *
2064
- * @since 1.40
2065
- *
2066
- * @return array 'message' => status/error messages, 'body' => tab content
2067
- */
2068
- private static function _compose_upload_tab( ) {
2069
- $page_template_array = MLACore::mla_load_template( 'admin-display-settings-upload-tab.tpl' );
2070
- if ( ! is_array( $page_template_array ) ) {
2071
- /* translators: 1: ERROR tag 2: function name 3: non-array value */
2072
- error_log( sprintf( _x( '%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'MLASettings::_compose_upload_tab', var_export( $page_template_array, true ) ), 0 );
2073
- return '';
2074
- }
2075
-
2076
- /*
2077
- * Untangle confusion between searching, canceling and selecting on the Optional Uploads screen
2078
- */
2079
- $bulk_action = self::_current_bulk_action();
2080
- if ( isset( $_REQUEST['mla-optional-uploads-cancel'] ) || $bulk_action && ( $bulk_action == 'select' ) ) {
2081
- unset( $_REQUEST['mla-optional-uploads-search'] );
2082
- unset( $_REQUEST['s'] );
2083
- }
2084
-
2085
- /*
2086
- * Convert checkbox values, if present
2087
- */
2088
- if ( isset( $_REQUEST['mla_upload_item'] ) ) {
2089
- $_REQUEST['mla_upload_item']['disabled'] = isset( $_REQUEST['mla_upload_item']['disabled'] );
2090
- }
2091
-
2092
- /*
2093
- * Set default values, check for Add New Upload MIME Type button
2094
- */
2095
- $add_form_values = array (
2096
- 'slug' => '',
2097
- 'mime_type' => '',
2098
- 'icon_type' => '.none.',
2099
- 'disabled' => '',
2100
- 'description' => ''
2101
- );
2102
-
2103
- if ( !empty( $_REQUEST['mla-upload-options-save'] ) ) {
2104
- check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
2105
- $page_content = self::_save_upload_settings( );
2106
- } elseif ( !empty( $_REQUEST['mla-optional-uploads-search'] ) ) {
2107
- check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
2108
- $page_content = self::_compose_optional_upload_tab( $page_template_array );
2109
- } elseif ( !empty( $_REQUEST['mla-optional-uploads-cancel'] ) ) {
2110
- $page_content = array(
2111
- 'message' => '',
2112
- 'body' => ''
2113
- );
2114
- } elseif ( !empty( $_REQUEST['mla-optional-uploads-display'] ) ) {
2115
- if ( 'true' != $_REQUEST['mla-optional-uploads-display'] ) {
2116
- check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
2117
- unset( $_REQUEST['s'] );
2118
- }
2119
- $page_content = self::_compose_optional_upload_tab( $page_template_array );
2120
- } elseif ( !empty( $_REQUEST['mla-add-upload-submit'] ) ) {
2121
- check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
2122
- $page_content = MLAMime::mla_add_upload_mime( $_REQUEST['mla_upload_item'] );
2123
- if ( false !== strpos( $page_content['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
2124
- $add_form_values = $_REQUEST['mla_upload_item'];
2125
- $add_form_values['disabled'] = $add_form_values['disabled'] ? 'checked="checked"' : '';
2126
- }
2127
- } else {
2128
- $page_content = array(
2129
- 'message' => '',
2130
- 'body' => ''
2131
- );
2132
- }
2133
-
2134
- /*
2135
- * Process bulk actions that affect an array of items
2136
- */
2137
- if ( $bulk_action && ( $bulk_action != 'none' ) ) {
2138
- if ( isset( $_REQUEST['cb_mla_item_ID'] ) ) {
2139
- if ( 'select' == $bulk_action ) {
2140
- foreach ( $_REQUEST['cb_mla_item_ID'] as $ID ) {
2141
- $item_content = MLASettings::_process_optional_upload_mime( $ID );
2142
- $page_content['message'] .= $item_content['message'] . '<br>';
2143
- }
2144
- } else {
2145
- /*
2146
- * Convert post-ID to slug; separate loop required because delete changes post_IDs
2147
- */
2148
- $slugs = array();
2149
- foreach ( $_REQUEST['cb_mla_item_ID'] as $post_ID )
2150
- $slugs[] = MLAMime::mla_get_upload_mime_slug( $post_ID );
2151
-
2152
- foreach ( $slugs as $slug ) {
2153
- switch ( $bulk_action ) {
2154
- case 'delete':
2155
- $item_content = MLAMime::mla_delete_upload_mime( $slug );
2156
- break;
2157
- case 'edit':
2158
- $request = array( 'slug' => $slug );
2159
- if ( '-1' != $_REQUEST['disabled'] ) {
2160
- $request['disabled'] = '1' == $_REQUEST['disabled'];
2161
- }
2162
- if ( '.none.' != $_REQUEST['icon_type'] ) {
2163
- $request['icon_type'] = $_REQUEST['icon_type'];
2164
- }
2165
- $item_content = MLAMime::mla_update_upload_mime( $request );
2166
- break;
2167
- default:
2168
- $item_content = array(
2169
- /* translators: 1: bulk_action, e.g., delete, edit, restore, trash */
2170
- 'message' => sprintf( __( 'Unknown bulk action %1$s', 'media-library-assistant' ), $bulk_action ),
2171
- 'body' => ''
2172
- );
2173
- } // switch $bulk_action
2174
-
2175
- $page_content['message'] .= $item_content['message'] . '<br>';
2176
- } // foreach cb_attachment
2177
- } // != select
2178
- } // isset cb_attachment
2179
- else {
2180
- /* translators: 1: action name, e.g., edit */
2181
- $page_content['message'] = sprintf( __( 'Bulk Action %1$s - no items selected.', 'media-library-assistant' ), $bulk_action );
2182
- }
2183
- } // $bulk_action
2184
-
2185
- /*
2186
- * Process row-level actions that affect a single item
2187
- */
2188
- if ( !empty( $_REQUEST['mla_admin_action'] ) ) {
2189
- check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
2190
-
2191
- switch ( $_REQUEST['mla_admin_action'] ) {
2192
- case MLACore::MLA_ADMIN_SINGLE_DELETE:
2193
- $page_content = MLAMime::mla_delete_upload_mime( $_REQUEST['mla_item_slug'] );
2194
- break;
2195
- case MLA::MLA_ADMIN_SINGLE_EDIT_DISPLAY:
2196
- $view = MLAMime::mla_get_upload_mime( $_REQUEST['mla_item_slug'] );
2197
- $page_content = self::_compose_edit_upload_tab( $view, $page_template_array );
2198
- break;
2199
- case MLA::MLA_ADMIN_SINGLE_EDIT_UPDATE:
2200
- if ( !empty( $_REQUEST['update'] ) ) {
2201
- $page_content = MLAMime::mla_update_upload_mime( $_REQUEST['mla_upload_item'] );
2202
- if ( false !== strpos( $page_content['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
2203
- $message = $page_content['message'];
2204
- $page_content = self::_compose_edit_upload_tab( $_REQUEST['mla_upload_item'], $page_template_array );
2205
- $page_content['message'] = $message;
2206
- }
2207
- } elseif ( !empty( $_REQUEST['mla_item_ID'] ) ) {
2208
- $page_content = self::_process_optional_upload_mime( $_REQUEST['mla_item_ID'] );
2209
- } else {
2210
- $page_content = array(
2211
- /* translators: 1: view name/slug */
2212
- 'message' => sprintf( __( 'Edit view "%1$s" cancelled.', 'media-library-assistant' ), $_REQUEST['mla_upload_item']['original_slug'] ),
2213
- 'body' => ''
2214
- );
2215
- }
2216
- break;
2217
- default:
2218
- $page_content = array(
2219
- /* translators: 1: bulk_action, e.g., single_item_delete, single_item_edit */
2220
- 'message' => sprintf( __( 'Unknown mla_admin_action - "%1$s"', 'media-library-assistant' ), $_REQUEST['mla_admin_action'] ),
2221
- 'body' => ''
2222
- );
2223
- break;
2224
- } // switch ($_REQUEST['mla_admin_action'])
2225
- } // (!empty($_REQUEST['mla_admin_action'])
2226
-
2227
- if ( !empty( $page_content['body'] ) ) {
2228
- return $page_content;
2229
- }
2230
-
2231
- /*
2232
- * Check for disabled status
2233
- */
2234
- if ( 'checked' != MLACore::mla_get_option( MLACoreOptions::MLA_ENABLE_UPLOAD_MIMES ) ) {
2235
- /*
2236
- * Fill in with any page-level options
2237
- */
2238
- $options_list = '';
2239
- foreach ( MLACoreOptions::$mla_option_definitions as $key => $value ) {
2240
- if ( 'upload' == $value['tab'] ) {
2241
- $options_list .= self::mla_compose_option_row( $key, $value );
2242
- }
2243
- }
2244
-
2245
- $page_values = array(
2246
- 'Support is disabled' => __( 'Upload MIME Type Support is disabled', 'media-library-assistant' ),
2247
- 'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-upload&mla_tab=upload',
2248
- 'options_list' => $options_list,
2249
- 'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
2250
- '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
2251
- );
2252
-
2253
- $page_content['body'] .= MLAData::mla_parse_template( $page_template_array['upload-disabled'], $page_values );
2254
- return $page_content;
2255
- }
2256
-
2257
- /*
2258
- * Display the Upload MIME Types Table
2259
- */
2260
- $_SERVER['REQUEST_URI'] = remove_query_arg( array(
2261
- 'mla_admin_action',
2262
- 'mla_item_slug',
2263
- 'mla_item_ID',
2264
- '_wpnonce',
2265
- '_wp_http_referer',
2266
- 'action',
2267
- 'action2',
2268
- 'cb_mla_item_ID',
2269
- 'mla-optional-uploads-search',
2270
- ), $_SERVER['REQUEST_URI'] );
2271
-
2272
- // Create an instance of our package class
2273
- $MLAListUploadTable = new MLA_Upload_List_Table();
2274
-
2275
- // Fetch, prepare, sort, and filter our data
2276
- $MLAListUploadTable->prepare_items();
2277
-
2278
- /*
2279
- * Start with any page-level options
2280
- */
2281
- $options_list = '';
2282
- foreach ( MLACoreOptions::$mla_option_definitions as $key => $value ) {
2283
- if ( 'upload' == $value['tab'] ) {
2284
- $options_list .= self::mla_compose_option_row( $key, $value );
2285
- }
2286
- }
2287
-
2288
- $page_values = array(
2289
- 'File Extension Processing' => __( 'File Extension and MIME Type Processing', 'media-library-assistant' ),
2290
- 'In this tab' => __( 'In this tab you can manage the list of file extension/MIME Type associations, which are used by WordPress to decide what kind of files can be uploaded to the Media Library and to fill in the <strong><em>post_mime_type</em></strong> value. To upload a file, the file extension must be in this list and be active.', 'media-library-assistant' ),
2291
- /* translators: 1: Documentation hyperlink */
2292
- 'You can find' => sprintf( __( 'You can find more information about file extensions, MIME types and how WordPress uses them in the %1$s section of the Documentation or by clicking the <strong>"Help"</strong> tab in the upper-right corner of this screen.', 'media-library-assistant' ), '<a href="[+settingsURL+]?page=mla-settings-menu-documentation&amp;mla_tab=documentation#mla_uploads" title="' . __( 'File Extension Processing documentation', 'media-library-assistant' ) . '">' . __( 'File Extension and MIME Type Processing', 'media-library-assistant' ) . '</a>' ),
2293
- 'settingsURL' => admin_url('options-general.php'),
2294
- 'Search Uploads' => __( 'Search Uploads', 'media-library-assistant' ),
2295
- 'To search by' => __( 'To search by extension, use ".", e.g., ".doc"', 'media-library-assistant' ),
2296
- 'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-upload&mla_tab=upload',
2297
- '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
2298
- 'options_list' => $options_list,
2299
- 'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
2300
- /* translators: %s: add new Upload MIME Type */
2301
- 'Add New Upload' => sprintf( __( 'Add New %1$s', 'media-library-assistant' ), __( 'Upload MIME Type', 'media-library-assistant' ) ),
2302
- 'To search database' => __( 'To search the database of over 1,500 known extension/type associations, click "Search Known Types" below the form.', 'media-library-assistant' ),
2303
- 'Extension' => __( 'Extension', 'media-library-assistant' ),
2304
- 'The extension is' => __( 'The &#8220;extension&#8221; is the file extension for this type, and unique key for the item. It must be all lowercase and contain only letters and numbers.', 'media-library-assistant' ),
2305
- 'MIME Type' => __( 'MIME Type', 'media-library-assistant' ),
2306
- 'The MIME Type' => __( 'The MIME Type must be all lowercase and contain only letters, numbers, periods (.), slashes (/) and hyphens (-). It <strong>must be a valid MIME</strong> type, e.g., &#8220;image&#8221; or &#8220;image/jpeg&#8221;.', 'media-library-assistant' ),
2307
- 'Icon Type' => __( 'Icon Type', 'media-library-assistant' ),
2308
- 'The Icon Type' => __( 'The Icon Type selects a thumbnail image displayed for non-image file types, such as PDF documents.', 'media-library-assistant' ),
2309
- 'Inactive' => __( 'Inactive', 'media-library-assistant' ),
2310
- 'Check this box' => __( 'Check this box if you want to remove this entry from the list of Upload MIME Types returned by get_allowed_mime_types().', 'media-library-assistant' ),
2311
- 'Description' => __( 'Description', 'media-library-assistant' ),
2312
- 'The description can' => __( 'The description can contain any documentation or notes you need to understand or use the item.', 'media-library-assistant' ),
2313
- 'Add Upload MIME' => __( 'Add Upload MIME Type', 'media-library-assistant' ),
2314
- 'search_url' => wp_nonce_url( '?page=mla-settings-menu-upload&mla_tab=upload&mla-optional-uploads-search=Search', MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ),
2315
- 'Search Known Types' => __( 'Search Known Types', 'media-library-assistant' ),
2316
- 'colspan' => $MLAListUploadTable->get_column_count(),
2317
- 'Quick Edit' => __( '<strong>Quick Edit</strong>', 'media-library-assistant' ),
2318
- 'Cancel' => __( 'Cancel', 'media-library-assistant' ),
2319
- 'Update' => __( 'Update', 'media-library-assistant' ),
2320
- 'Bulk Edit' => __( 'Bulk Edit', 'media-library-assistant' ),
2321
- 'Status' => __( 'Status', 'media-library-assistant' ),
2322
- 'No Change' => __( 'No Change', 'media-library-assistant' ),
2323
- 'Active' => __( 'Active', 'media-library-assistant' ),
2324
- 'results' => ! empty( $_REQUEST['s'] ) ? '<h2 class="alignleft">' . __( 'Displaying search results for', 'media-library-assistant' ) . ': "' . $_REQUEST['s'] . '"</h2>' : '',
2325
- 's' => isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '',
2326
- 'icon_types' => self::mla_get_icon_type_dropdown( $page_template_array, 'mla_upload_item[icon_type]' ),
2327
- 'inline_icon_types' => self::mla_get_icon_type_dropdown( $page_template_array, 'icon_type' ),
2328
- 'bulk_icon_types' => self::mla_get_icon_type_dropdown( $page_template_array, 'icon_type', '.nochange.' ),
2329
- );
2330
-
2331
- foreach ( $add_form_values as $key => $value ) {
2332
- $page_values[ $key ] = $value;
2333
- }
2334
- $page_content['body'] = MLAData::mla_parse_template( $page_template_array['before-table'], $page_values );
2335
-
2336
- // Now we can render the completed list table
2337
- ob_start();
2338
- $MLAListUploadTable->views();
2339
- $MLAListUploadTable->display();
2340
- $page_content['body'] .= ob_get_contents();
2341
- ob_end_clean();
2342
-
2343
- $page_content['body'] .= MLAData::mla_parse_template( $page_template_array['after-table'], $page_values );
2344
-
2345
- return $page_content;
2346
- }
2347
-
2348
- /**
2349
- * Compose the MLA Gallery tab content for the Settings subpage
2350
- *
2351
- * @since 0.80
2352
- * @uses $page_template_array contains tab content template(s)
2353
- *
2354
- * @return array 'message' => status/error messages, 'body' => tab content
2355
- */
2356
- private static function _compose_mla_gallery_tab( ) {
2357
- /*
2358
- * Check for submit buttons to change or reset settings.
2359
- * Initialize page messages and content.
2360
- */
2361
- if ( !empty( $_REQUEST['mla-gallery-options-save'] ) ) {
2362
- check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
2363
- $page_content = self::_save_gallery_settings( );
2364
- } else {
2365
- $page_content = array(
2366
- 'message' => '',
2367
- 'body' => ''
2368
- );
2369
- }
2370
-
2371
- if ( !empty( $page_content['body'] ) ) {
2372
- return $page_content;
2373
- }
2374
-
2375
- /*
2376
- * Compose shortcode jump table
2377
- */
2378
- $shortcode_jump_rows = '';
2379
- foreach( MLATemplate_Support::$mla_template_definitions['style'] as $shortcode => $definition ) {
2380
- $template_values = array(
2381
- 'shortcode' => $shortcode,
2382
- 'Go to Style Templates' => sprintf( '%1$s [mla_%2$s] %3$s', __( 'Go to', 'media-library-assistant' ), $shortcode, __( 'Style Templates', 'media-library-assistant' ) ),
2383
- 'Go to Markup Templates' => sprintf( '%1$s [mla_%2$s] %3$s', __( 'Go to', 'media-library-assistant' ), $shortcode, __( 'Markup Templates', 'media-library-assistant' ) ),
2384
- );
2385
-
2386
- $shortcode_jump_rows .= MLAData::mla_parse_template( self::$page_template_array['shortcode-jump-row'], $template_values );
2387
- }
2388
-
2389
- $page_values = array(
2390
- 'MLA Shortcode Options' => __( 'MLA Shortcode Options', 'media-library-assistant' ),
2391
- 'Shortcode Jump Rows' => $shortcode_jump_rows,
2392
- 'In this tab' => __( 'In this tab you can view the default style and markup templates. You can also define additional templates and use the <code>mla_style</code> and <code>mla_markup</code> parameters to apply them in your <code>[mla_gallery]</code> shortcodes. <strong>NOTE:</strong> template additions and changes will not be made permanent until you click "Save Changes" at the bottom of this page.', 'media-library-assistant' ),
2393
- 'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-mla_gallery&mla_tab=mla_gallery',
2394
- 'options_list' => '',
2395
- 'Go to Top' => __( 'Go to Top', 'media-library-assistant' ),
2396
- 'Go to Bottom' => __( 'Go to Bottom', 'media-library-assistant' ),
2397
- 'style_sections_list' => '',
2398
- 'markup_sections_list' => '',
2399
- 'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
2400
- '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
2401
- '_wp_http_referer' => wp_referer_field( false )
2402
- );
2403
-
2404
- /*
2405
- * Build default template selection lists
2406
- */
2407
- MLACoreOptions::$mla_option_definitions['default_style']['options'][] = 'none';
2408
- MLACoreOptions::$mla_option_definitions['default_style']['texts'][] = '&mdash; ' . __( 'None', 'media-library-assistant' ) . ' &mdash;';
2409
- MLACoreOptions::$mla_option_definitions['default_style']['options'][] = 'theme';
2410
- MLACoreOptions::$mla_option_definitions['default_style']['texts'][] = '&mdash; ' . __( 'Theme', 'media-library-assistant' ) . ' &mdash;';
2411
-
2412
- $templates = MLATemplate_Support::mla_get_style_templates( 'gallery' );
2413
- ksort($templates);
2414
- foreach ($templates as $key => $value ) {
2415
- MLACoreOptions::$mla_option_definitions['default_style']['options'][] = $key;
2416
- MLACoreOptions::$mla_option_definitions['default_style']['texts'][] = $key;
2417
- }
2418
-
2419
- $templates = MLATemplate_Support::mla_get_markup_templates( 'gallery' );
2420
- ksort($templates);
2421
- foreach ($templates as $key => $value ) {
2422
- MLACoreOptions::$mla_option_definitions['default_markup']['options'][] = $key;
2423
- MLACoreOptions::$mla_option_definitions['default_markup']['texts'][] = $key;
2424
- }
2425
-
2426
- /*
2427
- * Check for MLA Viewer Support requirements,
2428
- * starting with Imagick check
2429
- */
2430
- if ( ! class_exists( 'Imagick' ) ) {
2431
- $not_supported_warning = '<br>&nbsp;&nbsp;' . __( 'Imagick support is not installed.', 'media-library-assistant' );
2432
- } else {
2433
- $not_supported_warning = '';
2434
- }
2435
-
2436
- $ghostscript_path = MLACore::mla_get_option( 'ghostscript_path' );
2437
- if ( ! MLAShortcode_Support::mla_ghostscript_present( $ghostscript_path, true ) ) {
2438
- $not_supported_warning .= '<br>&nbsp;&nbsp;' . __( 'Ghostscript support is not installed.', 'media-library-assistant' );
2439
- }
2440
-
2441
- if ( ! empty( $not_supported_warning ) ) {
2442
- MLACoreOptions::$mla_option_definitions['enable_mla_viewer']['help'] = '<strong>' . __( 'WARNING:', 'media-library-assistant' ) . __( ' MLA Viewer support may not be available', 'media-library-assistant' ) . ':</strong>' . $not_supported_warning;
2443
- }
2444
-
2445
- /*
2446
- * Start with any page-level options
2447
- */
2448
- $options_list = '';
2449
- foreach ( MLACoreOptions::$mla_option_definitions as $key => $value ) {
2450
- if ( 'mla_gallery' == $value['tab'] ) {
2451
- $options_list .= self::mla_compose_option_row( $key, $value );
2452
- }
2453
- }
2454
-
2455
- $page_values['options_list'] = $options_list;
2456
-
2457
- /*
2458
- * Add style templates by shortcode; defaults go first
2459
- */
2460
- $style_sections_list = '';
2461
-
2462
- foreach( MLATemplate_Support::$mla_template_definitions['style'] as $shortcode => $definition ) {
2463
- $templates = MLATemplate_Support::mla_get_style_templates( $definition['slug'] );
2464
- $style_options_list = '';
2465
-
2466
- foreach ( $definition['default_names'] as $default ) {
2467
- if ( !array_key_exists( $default, $templates ) ) {
2468
- continue;
2469
- }
2470
-
2471
- $value =$templates[ $default ];
2472
- if ( ! empty( $value ) ) {
2473
- $template_values = array (
2474
- 'help' => __( 'This default template cannot be altered or deleted, but you can copy the styles.', 'media-library-assistant' )
2475
- );
2476
- $control_cells = MLAData::mla_parse_template( self::$page_template_array['mla-gallery-default'], $template_values );
2477
-
2478
- $template_values = array (
2479
- 'Name' => __( 'Name', 'media-library-assistant' ),
2480
- 'name_name' => "mla_style_templates_name[{$shortcode}][{$default}]",
2481
- 'name_id' => "mla_style_templates_name_{$shortcode}_{$default}",
2482
- 'readonly' => 'readonly="readonly"',
2483
- 'name_text' => $default,
2484
- 'control_cells' => $control_cells,
2485
- 'Styles' => $definition['label'],
2486
- 'value_name' => "mla_style_templates_value[{$shortcode}][{$default}]",
2487
- 'value_id' => "mla_style_templates_value_{$shortcode}_{$default}",
2488
- 'value_text' => esc_textarea( $value ),
2489
- 'value_help' => $definition['help'],
2490
- );
2491
-
2492
- $style_options_list .= MLAData::mla_parse_template( self::$page_template_array['mla-gallery-style'], $template_values );
2493
- } // $value
2494
- } // foreach default
2495
-
2496
- foreach ( $templates as $name => $value ) {
2497
- $slug = sanitize_title( $name );
2498
-
2499
- if ( in_array( $name, $definition['default_names'] ) ) {
2500
- continue; // already handled above
2501
- }
2502
-
2503
- $template_values = array (
2504
- 'name' => "mla_style_templates_delete[{$shortcode}][{$slug}]",
2505
- 'id' => "mla_style_templates_delete_{$shortcode}_{$slug}",
2506
- 'value' => __( 'Delete this template', 'media-library-assistant' ),
2507
- 'help' => __( 'Check the box to delete this template when you press Update at the bottom of the page.', 'media-library-assistant' )
2508
- );
2509
- $control_cells = MLAData::mla_parse_template( self::$page_template_array['mla-gallery-delete'], $template_values );
2510
-
2511
- $template_values = array (
2512
- 'Name' => __( 'Name', 'media-library-assistant' ),
2513
- 'name_name' => "mla_style_templates_name[{$shortcode}][{$slug}]",
2514
- 'name_id' => "mla_style_templates_name_{$shortcode}_{$slug}",
2515
- 'readonly' => '',
2516
- 'name_text' => $slug,
2517
- 'control_cells' => $control_cells,
2518
- 'Styles' => $definition['label'],
2519
- 'value_name' => "mla_style_templates_value[{$shortcode}][{$slug}]",
2520
- 'value_id' => "mla_style_templates_value_{$shortcode}_{$slug}",
2521
- 'value_text' => esc_textarea( $value ),
2522
- 'value_help' => $definition['help'],
2523
- );
2524
-
2525
- $style_options_list .= MLAData::mla_parse_template( self::$page_template_array['mla-gallery-style'], $template_values );
2526
- } // foreach $templates
2527
-
2528
- /*
2529
- * Add blank style template for additions
2530
- */
2531
- if ( ! empty( $value ) ) {
2532
- $template_values = array (
2533
- 'help' => __( 'Fill in a name and styles to add a new template.', 'media-library-assistant' )
2534
- );
2535
- $control_cells = MLAData::mla_parse_template( self::$page_template_array['mla-gallery-default'], $template_values );
2536
-
2537
- $template_values = array (
2538
- 'Name' => __( 'Name', 'media-library-assistant' ),
2539
- 'name_name' => "mla_style_templates_name[{$shortcode}][blank]",
2540
- 'name_id' => "mla_style_templates_name_{$shortcode}_blank",
2541
- 'readonly' => '',
2542
- 'name_text' => '',
2543
- 'control_cells' => $control_cells,
2544
- 'Styles' => $definition['label'],
2545
- 'value_name' => "mla_style_templates_value[{$shortcode}][blank]",
2546
- 'value_id' => "mla_style_templates_value_{$shortcode}_blank",
2547
- 'value_text' => '',
2548
- 'value_help' => $definition['help'],
2549
- );
2550
-
2551
- $style_options_list .= MLAData::mla_parse_template( self::$page_template_array['mla-gallery-style'], $template_values );
2552
- } // $value
2553
-
2554
- /*
2555
- * Compose the Styles section for this shortcode
2556
- */
2557
- $template_values = array (
2558
- 'shortcode' => $shortcode,
2559
- 'template_type' => 'style',
2560
- 'Go to Top' => __( 'Go to Top', 'media-library-assistant' ),
2561
- 'Go to Bottom' => __( 'Go to Bottom', 'media-library-assistant' ),
2562
- 'Templates' => "[mla_{$shortcode}] " . __( 'Style Templates', 'media-library-assistant' ),
2563
- 'templates_list' => $style_options_list,
2564
- );
2565
-
2566
- $style_sections_list .= MLAData::mla_parse_template( self::$page_template_array['templates-list'], $template_values );
2567
- } // $shortcode
2568
-
2569
- $page_values['style_sections_list'] = $style_sections_list;
2570
-
2571
- /*
2572
- * Add markup templates; defaults go first
2573
- */
2574
- $markup_sections_list = '';
2575
-
2576
- foreach( MLATemplate_Support::$mla_template_definitions['markup'] as $shortcode => $definition ) {
2577
- $templates = MLATemplate_Support::mla_get_markup_templates( $definition['slug'] );
2578
- $markup_options_list = '';
2579
-
2580
- $sorted_sections = array();
2581
- foreach( MLATemplate_Support::$mla_template_definitions['markup'][ $shortcode ]['sections'] as $section_slug => $section_definition ) {
2582
- $sorted_sections[ $section_definition['order'] ] = $section_definition;
2583
- $sorted_sections[ $section_definition['order'] ]['slug'] = $section_slug;
2584
- }
2585
- ksort( $sorted_sections, SORT_NUMERIC );
2586
-
2587
- foreach ( $definition['default_names'] as $default ) {
2588
- if ( !array_key_exists( $default, $templates ) ) {
2589
- continue;
2590
- }
2591
-
2592
- $value =$templates[ $default ];
2593
- if ( ! empty( $value ) ) {
2594
- $sections_list = '';
2595
- foreach( $sorted_sections as $section_definition ) {
2596
- $section_slug = $section_definition['slug'];
2597
- $template_values = array (
2598
- 'Label' => $section_definition['label'],
2599
- 'name' => "mla_markup_templates_sections[{$shortcode}][{$default}][{$section_slug}]",
2600
- 'id' => "mla_markup_templates_name_{$shortcode}_{$default}_{$section_slug}",
2601
- 'rows' => $section_definition['rows'],
2602
- 'readonly' => 'readonly="readonly"',
2603
- 'text' => isset( $value[ $section_slug ] ) ? esc_textarea( $value[ $section_slug ] ) : '',
2604
- 'help' => $section_definition['help'],
2605
- );
2606
-
2607
- $sections_list .= MLAData::mla_parse_template( self::$page_template_array['template-section'], $template_values );
2608
- } // $section
2609
-
2610
- $template_values = array (
2611
- 'help' => __( 'This default template cannot be altered or deleted, but you can copy the markup.', 'media-library-assistant' )
2612
- );
2613
- $control_cells = MLAData::mla_parse_template( self::$page_template_array['mla-gallery-default'], $template_values );
2614
-
2615
- $template_values = array (
2616
- 'Name' => __( 'Name', 'media-library-assistant' ),
2617
- 'name_name' => "mla_markup_templates_name[{$shortcode}][{$default}]",
2618
- 'name_id' => "mla_markup_templates_name_{$shortcode}_{$default}",
2619
- 'readonly' => 'readonly="readonly"',
2620
- 'name_text' => $default,
2621
- 'control_cells' => $control_cells,
2622
- 'sections_list' => $sections_list,
2623
- );
2624
-
2625
- $markup_options_list .= MLAData::mla_parse_template( self::$page_template_array['mla-gallery-markup'], $template_values );
2626
- } // $value
2627
- } // foreach default
2628
-
2629
- foreach ( $templates as $name => $value ) {
2630
- $slug = sanitize_title( $name );
2631
-
2632
- if ( in_array( $name, $definition['default_names'] ) ) {
2633
- continue; // already handled above
2634
- }
2635
-
2636
- if ( ! empty( $value ) ) {
2637
- $sections_list = '';
2638
- foreach( $sorted_sections as $section_definition ) {
2639
- $section_slug = $section_definition['slug'];
2640
- $template_values = array (
2641
- 'Label' => $section_definition['label'],
2642
- 'name' => "mla_markup_templates_sections[{$shortcode}][{$name}][{$section_slug}]",
2643
- 'id' => "mla_markup_templates_name_{$shortcode}_{$name}_{$section_slug}",
2644
- 'rows' => $section_definition['rows'],
2645
- 'readonly' => '',
2646
- 'text' => isset( $value[ $section_slug ] ) ? esc_textarea( $value[ $section_slug ] ) : '',
2647
- 'help' => $section_definition['help'],
2648
- );
2649
-
2650
- $sections_list .= MLAData::mla_parse_template( self::$page_template_array['template-section'], $template_values );
2651
- } // $section
2652
-
2653
- $template_values = array (
2654
- 'name' => "mla_markup_templates_delete[{$shortcode}][{$slug}]",
2655
- 'id' => "mla_markup_templates_delete_{$shortcode}_{$slug}",
2656
- 'value' => __( 'Delete this template', 'media-library-assistant' ),
2657
- 'help' => __( 'Check the box to delete this template when you press Update at the bottom of the page.', 'media-library-assistant' )
2658
- );
2659
- $control_cells = MLAData::mla_parse_template( self::$page_template_array['mla-gallery-delete'], $template_values );
2660
-
2661
- $template_values = array (
2662
- 'Name' => __( 'Name', 'media-library-assistant' ),
2663
- 'name_name' => "mla_markup_templates_name[{$shortcode}][{$slug}]",
2664
- 'name_id' => "mla_markup_templates_name_{$shortcode}_{$slug}",
2665
- 'readonly' => '',
2666
- 'name_text' => $slug,
2667
- 'control_cells' => $control_cells,
2668
- 'sections_list' => $sections_list,
2669
- );
2670
-
2671
- $markup_options_list .= MLAData::mla_parse_template( self::$page_template_array['mla-gallery-markup'], $template_values );
2672
- } // $value
2673
- } // foreach $templates
2674
-
2675
- /*
2676
- * Add blank markup template for additions
2677
- */
2678
- if ( ! empty( $value ) ) {
2679
- $template_values = array (
2680
- 'help' => __( 'Fill in a name and markup to add a new template.', 'media-library-assistant' )
2681
- );
2682
- $control_cells = MLAData::mla_parse_template( self::$page_template_array['mla-gallery-default'], $template_values );
2683
-
2684
- $sections_list = '';
2685
- foreach( $sorted_sections as $section_definition ) {
2686
- $section_slug = $section_definition['slug'];
2687
- $template_values = array (
2688
- 'Label' => $section_definition['label'],
2689
- 'name' => "mla_markup_templates_sections[{$shortcode}][blank][{$section_slug}]",
2690
- 'id' => "mla_markup_templates_name_{$shortcode}_blank_{$section_slug}",
2691
- 'rows' => $section_definition['rows'],
2692
- 'readonly' => '',
2693
- 'text' => '',
2694
- 'help' => $section_definition['help'],
2695
- );
2696
-
2697
- $sections_list .= MLAData::mla_parse_template( self::$page_template_array['template-section'], $template_values );
2698
- } // $section
2699
-
2700
- $template_values = array (
2701
- 'Name' => __( 'Name', 'media-library-assistant' ),
2702
- 'name_name' => "mla_markup_templates_name[{$shortcode}][blank]",
2703
- 'name_id' => "mla_markup_templates_name_{$shortcode}_blank",
2704
- 'name_text' => '',
2705
- 'control_cells' => $control_cells,
2706
- 'sections_list' => $sections_list,
2707
- );
2708
-
2709
- $markup_options_list .= MLAData::mla_parse_template( self::$page_template_array['mla-gallery-markup'], $template_values );
2710
- } // $value
2711
-
2712
- /*
2713
- * Compose the Markup section for this shortcode
2714
- */
2715
- $template_values = array (
2716
- 'shortcode' => $shortcode,
2717
- 'template_type' => 'markup',
2718
- 'Go to Top' => __( 'Go to Top', 'media-library-assistant' ),
2719
- 'Go to Bottom' => __( 'Go to Bottom', 'media-library-assistant' ),
2720
- 'Templates' => "[mla_{$shortcode}] " . __( 'Markup Templates', 'media-library-assistant' ),
2721
- 'templates_list' => $markup_options_list,
2722
- );
2723
-
2724
- $markup_sections_list .= MLAData::mla_parse_template( self::$page_template_array['templates-list'], $template_values );
2725
- } // $shortcode
2726
-
2727
- $page_values['markup_sections_list'] = $markup_sections_list;
2728
-
2729
- $page_content['body'] = MLAData::mla_parse_template( self::$page_template_array['mla-gallery-tab'], $page_values );
2730
- return $page_content;
2731
- }
2732
-
2733
- /**
2734
- * Compose the Custom Field tab content for the Settings subpage
2735
- *
2736
- * @since 1.10
2737
- * @uses $page_template_array contains tab content template(s)
2738
- *
2739
- * @return array 'message' => status/error messages, 'body' => tab content
2740
- */
2741
- private static function _compose_custom_field_tab( ) {
2742
- /*
2743
- * Check for action or submit buttons.
2744
- * Initialize page messages and content.
2745
- */
2746
- if ( isset( $_REQUEST['custom_field_mapping'] ) && is_array( $_REQUEST['custom_field_mapping'] ) ) {
2747
- check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
2748
-
2749
- /*
2750
- * Check for page-level submit buttons to change settings or map attachments.
2751
- * Initialize page messages and content.
2752
- */
2753
- if ( !empty( $_REQUEST['custom-field-options-save'] ) ) {
2754
- $page_content = self::_save_custom_field_settings( );
2755
- } elseif ( !empty( $_REQUEST['custom-field-options-map'] ) ) {
2756
- $page_content = self::_process_custom_field_mapping( );
2757
- } else {
2758
- $page_content = array(
2759
- 'message' => '',
2760
- 'body' => ''
2761
- );
2762
-
2763
- /*
2764
- * Check for single-rule action buttons
2765
- */
2766
- foreach ( $_REQUEST['custom_field_mapping'] as $key => $value ) {
2767
- $value = stripslashes_deep( $value );
2768
-
2769
- if ( isset( $value['action'] ) ) {
2770
- $settings = array( $key => $value );
2771
- foreach ( $value['action'] as $action => $label ) {
2772
- switch( $action ) {
2773
- case 'delete_field':
2774
- $delete_result = self::_delete_custom_field( $value );
2775
- case 'delete_rule':
2776
- case 'add_rule':
2777
- case 'add_field':
2778
- case 'update_rule':
2779
- $page_content = self::_save_custom_field_settings( $settings );
2780
- if ( isset( $delete_result ) ) {
2781
- $page_content['message'] = $delete_result . $page_content['message'];
2782
- }
2783
- break;
2784
- case 'map_now':
2785
- $page_content = self::_process_custom_field_mapping( $settings );
2786
- break;
2787
- case 'add_rule_map':
2788
- case 'add_field_map':
2789
- $page_content = self::_save_custom_field_settings( $settings );
2790
- if ( false === strpos( $page_content['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
2791
- $current_values = MLACore::mla_get_option( 'custom_field_mapping' );
2792
- $settings = array( $value['name'] => $current_values[$value['name']] );
2793
- $map_content = self::_process_custom_field_mapping( $settings );
2794
- $page_content['message'] .= '<br>&nbsp;<br>' . $map_content['message'];
2795
- }
2796
- break;
2797
- default:
2798
- // ignore everything else
2799
- } //switch action
2800
- } // foreach action
2801
- } /// isset action
2802
- } // foreach rule
2803
- } // specific rule check
2804
- } // isset custom_field_mapping
2805
- else {
2806
- $page_content = array(
2807
- 'message' => '',
2808
- 'body' => ''
2809
- );
2810
- }
2811
-
2812
- if ( !empty( $page_content['body'] ) ) {
2813
- return $page_content;
2814
- }
2815
-
2816
- $page_values = array(
2817
- 'Mapping Progress' => __( 'Custom Field Mapping Progress', 'media-library-assistant' ),
2818
- 'DO NOT' => __( 'DO NOT DO THE FOLLOWING (they will cause mapping to fail)', 'media-library-assistant' ),
2819
- 'DO NOT Close' => __( 'Close the window', 'media-library-assistant' ),
2820
- 'DO NOT Reload' => __( 'Reload the page', 'media-library-assistant' ),
2821
- 'DO NOT Click' => __( 'Click the browser&rsquo;s Stop, Back or forward buttons', 'media-library-assistant' ),
2822
- 'Progress' => __( 'Progress', 'media-library-assistant' ),
2823
- 'Cancel' => __( 'Cancel', 'media-library-assistant' ),
2824
- 'Resume' => __( 'Resume', 'media-library-assistant' ),
2825
- 'Close' => __( 'Close', 'media-library-assistant' ),
2826
- 'Refresh' => __( 'Refresh', 'media-library-assistant' ),
2827
- 'refresh_href' => '?page=mla-settings-menu-custom_field&mla_tab=custom_field',
2828
- );
2829
-
2830
- $progress_div = MLAData::mla_parse_template( self::$page_template_array['mla-progress-div'], $page_values );
2831
-
2832
- $page_values = array(
2833
- 'mla-progress-div' => $progress_div,
2834
- 'Custom Field Options' => __( 'Custom Field and Attachment Metadata Processing Options', 'media-library-assistant' ),
2835
- /* translators: 1: Documentation hyperlink */
2836
- 'In this tab' => sprintf( __( 'In this tab you can define the rules for mapping several types of image metadata to WordPress custom fields. You can also use this screen to define rules for adding or updating fields within the WordPress-supplied "Attachment Metadata", stored in the "_wp_attachment_metadata" custom field. See the %1$s section of the Documentation for details.', 'media-library-assistant' ), '<a href="[+settingsURL+]?page=mla-settings-menu-documentation&amp;mla_tab=documentation#attachment_metadata_mapping" title="' . __( 'Updating Attachment Metadata Documentation', 'media-library-assistant' ) . '">' . __( 'Adding or changing Attachment Metadata', 'media-library-assistant' ) . '</a>' ),
2837
- /* translators: 1: Documentation hyperlink */
2838
- 'You can find' => sprintf( __( 'You can find more information about using the controls in this tab to define mapping rules and apply them in the %1$s section of the Documentation.', 'media-library-assistant' ), '<a href="[+settingsURL+]?page=mla-settings-menu-documentation&amp;mla_tab=documentation#mla_custom_field_mapping" title="' . __( 'Custom Field Options documentation', 'media-library-assistant' ) . '">' . __( 'Custom Field and Attachment Metadata Processing Options', 'media-library-assistant' ) . '</a>' ),
2839
- 'settingsURL' => admin_url('options-general.php'),
2840
- 'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-custom_field&mla_tab=custom_field',
2841
- 'options_list' => '',
2842
- 'Custom field mapping' => __( 'Custom field mapping', 'media-library-assistant' ),
2843
- 'custom_options_list' => '',
2844
- 'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
2845
- 'Map All Rules' => __( 'Map All Rules, All Attachments Now', 'media-library-assistant' ),
2846
- /* translators: 1: "Save Changes" */
2847
- 'Click Save Changes' => sprintf( __( 'Click %1$s to update the "Enable custom field mapping..." checkbox and/or all rule changes and additions at once. <strong>No rule mapping will be performed.</strong>', 'media-library-assistant' ), '<strong>' . __( 'Save Changes', 'media-library-assistant' ) . '</strong>' ),
2848
- /* translators: 1: "Map All Rules..." */
2849
- 'Click Map All' => sprintf( __( 'Click %1$s to apply all the rules at once (rule changes will be applied but not saved).', 'media-library-assistant' ), '<strong>' . __( 'Map All Rules, All Attachments Now', 'media-library-assistant' ) . '</strong>' ),
2850
- '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
2851
- '_wp_http_referer' => wp_referer_field( false )
2852
- );
2853
-
2854
- /*
2855
- * Start with any page-level options
2856
- */
2857
- $options_list = '';
2858
- foreach ( MLACoreOptions::$mla_option_definitions as $key => $value ) {
2859
- if ( 'custom_field' == $value['tab'] ) {
2860
- $options_list .= self::mla_compose_option_row( $key, $value );
2861
- }
2862
- }
2863
-
2864
- $page_values['options_list'] = $options_list;
2865
-
2866
- /*
2867
- * Add mapping options
2868
- */
2869
- $page_values['custom_options_list'] = MLAOptions::mla_custom_field_option_handler( 'render', 'custom_field_mapping', MLACoreOptions::$mla_option_definitions['custom_field_mapping'] );
2870
-
2871
- $page_content['body'] = MLAData::mla_parse_template( self::$page_template_array['custom-field-tab'], $page_values );
2872
- return $page_content;
2873
- }
2874
-
2875
- /**
2876
- * Compose the IPTC/EXIF tab content for the Settings subpage
2877
- *
2878
- * @since 1.00
2879
- * @uses $page_template_array contains tab content template(s)
2880
- *
2881
- * @return array 'message' => status/error messages, 'body' => tab content
2882
- */
2883
- private static function _compose_iptc_exif_tab( ) {
2884
- /*
2885
- * Initialize page messages and content.
2886
- * Check for submit buttons to change or reset settings.
2887
- */
2888
- $page_content = array(
2889
- 'message' => '',
2890
- 'body' => ''
2891
- );
2892
-
2893
- if ( isset( $_REQUEST['iptc_exif_mapping'] ) && is_array( $_REQUEST['iptc_exif_mapping'] ) ) {
2894
- check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
2895
-
2896
- if ( !empty( $_REQUEST['iptc-exif-options-save'] ) ) {
2897
- $page_content = self::_save_iptc_exif_settings( );
2898
- } elseif ( !empty( $_REQUEST['iptc-exif-options-process-standard'] ) ) {
2899
- $page_content = self::_process_iptc_exif_standard( );
2900
- } elseif ( !empty( $_REQUEST['iptc-exif-options-process-taxonomy'] ) ) {
2901
- $page_content = self::_process_iptc_exif_taxonomy( );
2902
- } elseif ( !empty( $_REQUEST['iptc-exif-options-process-custom'] ) ) {
2903
- $page_content = self::_process_iptc_exif_custom( );
2904
- } else {
2905
- /*
2906
- * Check for single-rule action buttons
2907
- */
2908
- foreach ( $_REQUEST['iptc_exif_mapping']['custom'] as $key => $value ) {
2909
- $value = stripslashes_deep( $value );
2910
-
2911
- if ( isset( $value['action'] ) ) {
2912
- $settings = array( 'custom' => array( $key => $value ) );
2913
- foreach ( $value['action'] as $action => $label ) {
2914
- switch( $action ) {
2915
- case 'delete_field':
2916
- $delete_result = self::_delete_custom_field( $value );
2917
- case 'delete_rule':
2918
- case 'add_rule':
2919
- case 'add_field':
2920
- case 'update_rule':
2921
- $page_content = self::_save_iptc_exif_custom_settings( $settings );
2922
- if ( isset( $delete_result ) ) {
2923
- $page_content['message'] = $delete_result . $page_content['message'];
2924
- }
2925
- break;
2926
- case 'map_now':
2927
- $page_content = self::_process_iptc_exif_custom( $settings );
2928
- break;
2929
- case 'add_rule_map':
2930
- case 'add_field_map':
2931
- $page_content = self::_save_iptc_exif_custom_settings( $settings );
2932
- if ( false === strpos( $page_content['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
2933
- $current_values = MLACore::mla_get_option( 'iptc_exif_mapping' );
2934
- $settings = array( 'custom' => array( $value['name'] => $current_values['custom'][$value['name']] ) );
2935
- $map_content = self::_process_iptc_exif_custom( $settings );
2936
- $page_content['message'] .= '<br>&nbsp;<br>' . $map_content['message'];
2937
- }
2938
- break;
2939
- default:
2940
- // ignore everything else
2941
- } //switch action
2942
- } // foreach action
2943
- } /// isset action
2944
- } // foreach rule
2945
- }
2946
-
2947
- if ( !empty( $page_content['body'] ) ) {
2948
- return $page_content;
2949
- }
2950
- }
2951
-
2952
- $page_values = array(
2953
- 'Mapping Progress' => __( 'IPTC &amp; EXIF Mapping Progress', 'media-library-assistant' ),
2954
- 'DO NOT' => __( 'DO NOT DO THE FOLLOWING (they will cause mapping to fail)', 'media-library-assistant' ),
2955
- 'DO NOT Close' => __( 'Close the window', 'media-library-assistant' ),
2956
- 'DO NOT Reload' => __( 'Reload the page', 'media-library-assistant' ),
2957
- 'DO NOT Click' => __( 'Click the browser&rsquo;s Stop, Back or forward buttons', 'media-library-assistant' ),
2958
- 'Progress' => __( 'Progress', 'media-library-assistant' ),
2959
- 'Cancel' => __( 'Cancel', 'media-library-assistant' ),
2960
- 'Resume' => __( 'Resume', 'media-library-assistant' ),
2961
- 'Close' => __( 'Close', 'media-library-assistant' ),
2962
- 'Refresh' => __( 'Refresh', 'media-library-assistant' ),
2963
- 'refresh_href' => '?page=mla-settings-menu-iptc_exif&mla_tab=iptc_exif',
2964
- );
2965
-
2966
- $progress_div = MLAData::mla_parse_template( self::$page_template_array['mla-progress-div'], $page_values );
2967
-
2968
- $page_values = array(
2969
- 'mla-progress-div' => $progress_div,
2970
- 'IPTX/EXIF Options' => __( 'IPTC &amp; EXIF Processing Options', 'media-library-assistant' ),
2971
- 'In this tab' => __( 'In this tab you can define the rules for mapping IPTC (International Press Telecommunications Council) and EXIF (EXchangeable Image File) metadata to WordPress standard attachment fields, taxonomy terms and custom fields. <strong>NOTE:</strong> settings changes will not be made permanent until you click "Save Changes" at the bottom of this page.', 'media-library-assistant' ),
2972
- /* translators: 1: Documentation hyperlink */
2973
- 'You can find' => sprintf( __( 'You can find more information about using the controls in this tab to define mapping rules and apply them in the %1$s section of the Documentation.', 'media-library-assistant' ), '<a href="[+settingsURL+]?page=mla-settings-menu-documentation&amp;mla_tab=documentation#mla_iptc_exif_mapping" title="' . __( 'IPTC/EXIF Options documentation', 'media-library-assistant' ) . '">' . __( 'IPTC &amp; EXIF Processing Options', 'media-library-assistant' ) . '</a>' ),
2974
- 'settingsURL' => admin_url('options-general.php'),
2975
- 'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-iptc_exif&mla_tab=iptc_exif',
2976
- 'options_list' => '',
2977
- 'Standard field mapping' => __( 'Standard field mapping', 'media-library-assistant' ),
2978
- 'Map Standard Fields' => __( 'Map All Attachments, Standard Fields Now', 'media-library-assistant' ),
2979
- 'standard_options_list' => '',
2980
- 'Taxonomy term mapping' => __( 'Taxonomy term mapping', 'media-library-assistant' ),
2981
- 'Map Taxonomy Terms' => __( 'Map All Attachments, Taxonomy Terms Now', 'media-library-assistant' ),
2982
- 'taxonomy_options_list' => '',
2983
- 'Custom field mapping' => __( 'Custom field mapping', 'media-library-assistant' ),
2984
- 'Map Custom Fields' => __( 'Map All Attachments, Custom Fields Now', 'media-library-assistant' ),
2985
- 'custom_options_list' => '',
2986
- 'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
2987
- /* translators: 1: "Save Changes" */
2988
- 'Click Save Changes' => sprintf( __( 'Click %1$s to update the "Enable IPTC/EXIF mapping..." checkbox and/or all rule changes and additions at once. <strong>No rule mapping will be performed.</strong>', 'media-library-assistant' ), '<strong>' . __( 'Save Changes', 'media-library-assistant' ) . '</strong>' ),
2989
- '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
2990
- '_wp_http_referer' => wp_referer_field( false )
2991
- );
2992
-
2993
- /*
2994
- * Start with any page-level options
2995
- */
2996
- $options_list = '';
2997
- foreach ( MLACoreOptions::$mla_option_definitions as $key => $value ) {
2998
- if ( 'iptc_exif' == $value['tab'] ) {
2999
- $options_list .= self::mla_compose_option_row( $key, $value );
3000
- }
3001
- }
3002
-
3003
- $page_values['options_list'] = $options_list;
3004
-
3005
- /*
3006
- * Add mapping options
3007
- */
3008
- $page_values['standard_options_list'] = MLAOptions::mla_iptc_exif_option_handler( 'render', 'iptc_exif_standard_mapping', MLACoreOptions::$mla_option_definitions['iptc_exif_standard_mapping'] );
3009
-
3010
- $page_values['taxonomy_options_list'] = MLAOptions::mla_iptc_exif_option_handler( 'render', 'iptc_exif_taxonomy_mapping', MLACoreOptions::$mla_option_definitions['iptc_exif_taxonomy_mapping'] );
3011
-
3012
- $page_values['custom_options_list'] = MLAOptions::mla_iptc_exif_option_handler( 'render', 'iptc_exif_custom_mapping', MLACoreOptions::$mla_option_definitions['iptc_exif_custom_mapping'] );
3013
-
3014
- $page_content['body'] = MLAData::mla_parse_template( self::$page_template_array['iptc-exif-tab'], $page_values );
3015
- return $page_content;
3016
- }
3017
-
3018
- /**
3019
- * Compose the Example Plugin tab content for the Settings/Documentation subpage
3020
- *
3021
- * @since 2.32
3022
- *
3023
- * @return array 'message' => status/error messages, 'body' => tab content
3024
- */
3025
- private static function _compose_example_tab() {
3026
- $page_template_array = MLACore::mla_load_template( 'admin-display-settings-example-tab.tpl' );
3027
-
3028
- /*
3029
- * Display the Example Plugin Table
3030
- */
3031
- $_SERVER['REQUEST_URI'] = add_query_arg( array( 'mla-example-display' => 'true' ), remove_query_arg( array(
3032
- 'mla_admin_action',
3033
- 'mla_item_slug',
3034
- 'mla_item_ID',
3035
- '_wpnonce',
3036
- '_wp_http_referer',
3037
- 'action',
3038
- 'action2',
3039
- 'cb_attachment',
3040
- 'mla-example-search'
3041
- ), $_SERVER['REQUEST_URI'] ) );
3042
-
3043
- // Create an instance of our package class
3044
- $MLAListExampleTable = new MLA_Example_List_Table();
3045
-
3046
- // Fetch, prepare, sort, and filter our data
3047
- $MLAListExampleTable->prepare_items();
3048
-
3049
- $page_content = array(
3050
- 'message' => '',
3051
- 'body' => ''
3052
- );
3053
-
3054
- $page_values = array(
3055
- 'results' => ! empty( $_REQUEST['s'] ) ? ' - ' . __( 'Displaying search results for', 'media-library-assistant' ) . ': "' . $_REQUEST['s'] . '"' : '',
3056
- 'In this tab' => __( 'In this tab you can browse the list of MLA example plugins, install or update them in the Plugins/Installed Plugins area and see which examples you have already installed. <strong>To activate, deactivate or delete</strong> the plugins you must go to the Plugins/Installed Plugins admin submenu.' ),
3057
- /* translators: 1: Documentation hyperlink */
3058
- 'You can find' => sprintf( __( 'You can find more information about using the example plugins in the %1$s section of the Documentation or by clicking the <strong>"Help"</strong> tab in the upper-right corner of this screen.', 'media-library-assistant' ), '<a href="[+settingsURL+]?page=mla-settings-menu-documentation&amp;mla_tab=documentation#mla_example_plugins" title="' . __( 'Example plugin documentation', 'media-library-assistant' ) . '">' . __( 'The Example Plugins', 'media-library-assistant' ) . '</a>' ),
3059
- 'views' => '',
3060
- 'settingsURL' => admin_url('options-general.php'),
3061
- 'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-documentation&mla_tab=documentation',
3062
- '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
3063
- 'Example Plugins' => __( 'Example Plugins', 'media-library-assistant' ),
3064
- 'Search Example Plugins' => __( 'Search Example Plugins', 'media-library-assistant' ),
3065
- 's' => isset( $_REQUEST['s'] ) ? esc_attr( stripslashes( $_REQUEST['s'] ) ) : '',
3066
- 'Search Plugins' => __( 'Search Plugins', 'media-library-assistant' ),
3067
- 'Search help' => __( 'Searches Name, Description, File Name and Tags', 'media-library-assistant' ),
3068
- 'Cancel' => __( 'Cancel', 'media-library-assistant' ),
3069
- );
3070
-
3071
- ob_start();
3072
- $MLAListExampleTable->views();
3073
- $page_values['views'] = ob_get_contents();
3074
- ob_end_clean();
3075
-
3076
- $page_content['body'] = MLAData::mla_parse_template( $page_template_array['before-example-table'], $page_values );
3077
-
3078
- // Now we can render the completed list table
3079
- ob_start();
3080
- $MLAListExampleTable->display();
3081
- $page_content['body'] .= ob_get_contents();
3082
- ob_end_clean();
3083
-
3084
- $page_content['body'] .= MLAData::mla_parse_template( $page_template_array['after-example-table'], $page_values );
3085
-
3086
- return $page_content;
3087
- }
3088
-
3089
- /**
3090
- * Compose the Documentation tab content for the Settings subpage
3091
- *
3092
- * @since 0.80
3093
- * @uses $page_template_array contains tab content template(s)
3094
- *
3095
- * @return array 'message' => status/error messages, 'body' => tab content
3096
- */
3097
- private static function _compose_documentation_tab( ) {
3098
- /*
3099
- * Untangle confusion between searching, canceling and selecting on the Example Plugins submenu
3100
- */
3101
- $bulk_action = self::_current_bulk_action();
3102
- if ( isset( $_REQUEST['mla-example-cancel'] ) || $bulk_action && ( $bulk_action == 'install' ) ) {
3103
- unset( $_REQUEST['mla-example-search'] );
3104
- unset( $_REQUEST['s'] );
3105
- }
3106
-
3107
- /*
3108
- * Display or Cancel the Example Plugins submenu, if requested
3109
- */
3110
- if ( !empty( $_REQUEST['mla-example-search'] ) ) {
3111
- check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
3112
- $page_content = self::_compose_example_tab();
3113
- } elseif ( !empty( $_REQUEST['mla-example-cancel'] ) ) {
3114
- $page_content = array(
3115
- 'message' => '',
3116
- 'body' => ''
3117
- );
3118
- } elseif ( !empty( $_REQUEST['mla-example-display'] ) ) {
3119
- if ( 'true' != $_REQUEST['mla-example-display'] ) {
3120
- check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
3121
- //unset( $_REQUEST['s'] );
3122
- }
3123
- $page_content = self::_compose_example_tab();
3124
- } else {
3125
- $page_content = array(
3126
- 'message' => '',
3127
- 'body' => ''
3128
- );
3129
- }
3130
-
3131
- /*
3132
- * Process bulk actions that affect an array of items
3133
- */
3134
- if ( $bulk_action && ( $bulk_action != 'none' ) ) {
3135
- $bulk_message = '';
3136
- if ( isset( $_REQUEST['cb_mla_item_ID'] ) ) {
3137
- foreach ( $_REQUEST['cb_mla_item_ID'] as $ID ) {
3138
- switch ( $bulk_action ) {
3139
- case 'install':
3140
- $item_content = MLA_Example_List_Table::mla_install_example_plugin( $ID );
3141
- break;
3142
- case 'update':
3143
- $item_content = MLA_Example_List_Table::mla_update_example_plugin( $ID );
3144
- break;
3145
- default:
3146
- /* translators: 1: bulk_action, e.g., delete, edit, restore, trash */
3147
- $item_content = sprintf( __( 'Unknown bulk action %1$s', 'media-library-assistant' ), $bulk_action );
3148
- break 2; // Exit the switch and the foreach
3149
- ;
3150
- } // switch ($_REQUEST['mla_admin_action'])
3151
-
3152
- $bulk_message .= $item_content . '<br>';
3153
- } // foreach $ID
3154
- } // isset cb_attachment
3155
- else {
3156
- /* translators: 1: action name, e.g., edit */
3157
- $bulk_message = sprintf( __( 'Bulk Action %1$s - no items selected.', 'media-library-assistant' ), $bulk_action );
3158
- }
3159
-
3160
- $page_content = self::_compose_example_tab();
3161
- $page_content['message'] = $bulk_message;
3162
- } // $bulk_action
3163
-
3164
- /*
3165
- * Process row-level actions that affect a single item
3166
- */
3167
- if ( !empty( $_REQUEST['mla_admin_action'] ) ) {
3168
- check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
3169
- $action_content = array( 'message' => '' );
3170
- if ( empty( $_REQUEST['mla_item_ID'] ) ) {
3171
- /* translators: 1: bulk_action, e.g., single_item_delete, single_item_edit */
3172
- $action_content['message'] = sprintf( __( 'Empty mla_item_ID - "%1$s"', 'media-library-assistant' ), $_REQUEST['mla_admin_action'] );
3173
- } else {
3174
- switch ( $_REQUEST['mla_admin_action'] ) {
3175
- case MLA::MLA_ADMIN_SINGLE_EDIT_DISPLAY:
3176
- $action_content = MLA_Example_List_Table::mla_install_example_plugin( $_REQUEST['mla_item_ID'] );
3177
- break;
3178
- case MLA::MLA_ADMIN_SINGLE_EDIT_UPDATE:
3179
- $action_content = MLA_Example_List_Table::mla_update_example_plugin( $_REQUEST['mla_item_ID'] );
3180
- break;
3181
- default:
3182
- /* translators: 1: bulk_action, e.g., single_item_delete, single_item_edit */
3183
- $action_content = sprintf( __( 'Unknown mla_admin_action - "%1$s"', 'media-library-assistant' ), $_REQUEST['mla_admin_action'] );
3184
- break;
3185
- } // switch ($_REQUEST['mla_admin_action'])
3186
- }
3187
-
3188
- $page_content = self::_compose_example_tab();
3189
- $page_content['message'] = $action_content;
3190
- } // (!empty($_REQUEST['mla_admin_action'])
3191
-
3192
- if ( !empty( $page_content['body'] ) ) {
3193
- return $page_content;
3194
- }
3195
-
3196
- $page_template = MLACore::mla_load_template( 'documentation-settings-tab.tpl' );
3197
- if ( ! is_array( $page_template ) ) {
3198
- /* translators: 1: ERROR tag 2: function name 3: non-array value */
3199
- error_log( sprintf( _x( '%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'MLASettings::_compose_documentation_tab', var_export( $page_template, true ) ), 0 );
3200
- return '';
3201
- }
3202
-
3203
- /*
3204
- * Display the Documentation tab
3205
- */
3206
- $page_values = array(
3207
- 'example_url' => wp_nonce_url( '?page=mla-settings-menu-documentation&mla_tab=documentation&mla-example-search=Search', MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ),
3208
- 'translate_url' => MLA_PLUGIN_URL . 'languages/MLA Internationalization Guide.pdf',
3209
- 'phpDocs_url' => MLA_PLUGIN_URL . 'phpDocs/index.html',
3210
- );
3211
-
3212
- $page_content['body'] = MLAData::mla_parse_template( $page_template['documentation-tab'], $page_values );
3213
- return $page_content;
3214
- }
3215
-
3216
- /**
3217
- * Save Debug settings to the options table
3218
- *
3219
- * @since 2.10
3220
- *
3221
- * @uses $_REQUEST
3222
- *
3223
- * @return array Message(s) reflecting the results of the operation
3224
- */
3225
- private static function _save_debug_settings( ) {
3226
- $message_list = '';
3227
-
3228
- foreach ( MLACoreOptions::$mla_option_definitions as $key => $value ) {
3229
- if ( 'debug' == $value['tab'] ) {
3230
- $message_list .= self::mla_update_option_row( $key, $value );
3231
- } // view option
3232
- } // foreach mla_options
3233
-
3234
- $page_content = array(
3235
- 'message' => __( 'Debug settings saved.', 'media-library-assistant' ) . "\r\n",
3236
- 'body' => ''
3237
- );
3238
-
3239
- /*
3240
- * Uncomment this for debugging.
3241
- */
3242
- // $page_content['message'] .= $message_list;
3243
-
3244
- return $page_content;
3245
- } // _save_debug_settings
3246
-
3247
- /**
3248
- * Compose the Debug tab Debug Settings content for one setting
3249
- *
3250
- * @since 2.14
3251
- *
3252
- * @param string $label Display name for the setting
3253
- * @param string $value Current value for the setting
3254
- *
3255
- * @return string HTML table row markup for the label setting pair
3256
- */
3257
- private static function _compose_settings_row( $label, $value ) {
3258
- $row = '<tr valign="top"><th scope="row" style="text-align:right;">' . "\n";
3259
- $row .= $label . "\n";
3260
- $row .= '</th><td style="text-align:left;">' . "\n";
3261
- $row .= $value . "\n";
3262
- $row .= '</td></tr>' . "\n";
3263
-
3264
- return $row;
3265
- } // _compose_settings_row
3266
-
3267
- /**
3268
- * Compose the Debug tab content for the Settings subpage
3269
- *
3270
- * @since 2.10
3271
- * @uses $page_template_array contains tab content template(s)
3272
- *
3273
- * @return array 'message' => status/error messages, 'body' => tab content
3274
- */
3275
- private static function _compose_debug_tab( ) {
3276
- $page_content = array(
3277
- 'message' => '',
3278
- 'body' => ''
3279
- );
3280
-
3281
- $page_values = array();
3282
-
3283
- /*
3284
- * Saving the options can change the log file name, so do it first
3285
- */
3286
- if ( !empty( $_REQUEST['mla-debug-options-save'] ) ) {
3287
- check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
3288
- $page_content = self::_save_debug_settings();
3289
- }
3290
-
3291
- /*
3292
- * Find the appropriate error log file
3293
- */
3294
- $error_log_name = MLACore::mla_get_option( MLACoreOptions::MLA_DEBUG_FILE );
3295
- if ( empty( $error_log_name ) ) {
3296
- $error_log_name = ini_get( 'error_log' );
3297
- } else {
3298
- $first = substr( $error_log_name, 0, 1 );
3299
- if ( ( '/' != $first ) && ( '\\' != $first ) ) {
3300
- $error_log_name = '/' . $error_log_name;
3301
- }
3302
-
3303
- $error_log_name = WP_CONTENT_DIR . $error_log_name;
3304
- }
3305
-
3306
- $error_log_exists = file_exists ( $error_log_name );
3307
-
3308
- /*
3309
- * Check for other page-level actions
3310
  */
3311
  if ( isset( $_REQUEST['mla_reset_log'] ) && 'true' == $_REQUEST['mla_reset_log'] ) {
3312
  $file_error = false;
@@ -3423,529 +1358,103 @@ class MLASettings {
3423
  $settings_list .= self::_compose_settings_row( 'MLA Reporting', $mla_reporting );
3424
  $settings_list .= self::_compose_settings_row( 'MLA_DEBUG_LEVEL', sprintf( '0x%1$04X', MLA_DEBUG_LEVEL ) );
3425
  $settings_list .= self::_compose_settings_row( 'PHP error_reporting', MLACore::$original_php_reporting );
3426
- $settings_list .= self::_compose_settings_row( 'Old PHP error_log', MLACore::$original_php_log );
3427
- $settings_list .= self::_compose_settings_row( 'New PHP error_log', ini_get( 'error_log' ) );
3428
- $settings_list .= self::_compose_settings_row( 'WP_DEBUG', WP_DEBUG ? 'true' : 'false' );
3429
- $settings_list .= self::_compose_settings_row( 'WP_DEBUG_LOG', WP_DEBUG_LOG ? 'true' : 'false' );
3430
- $settings_list .= self::_compose_settings_row( 'WP_DEBUG_DISPLAY', WP_DEBUG_DISPLAY ? 'true' : 'false' );
3431
- $settings_list .= self::_compose_settings_row( 'WP_CONTENT_DIR', WP_CONTENT_DIR );
3432
-
3433
- /*
3434
- * Compose tab content
3435
- */
3436
- $page_values = array (
3437
- 'Debug Options' => __( 'Debug Options', 'media-library-assistant' ),
3438
- 'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-debug&mla_tab=debug',
3439
- 'options_list' => $options_list,
3440
- 'Debug Settings' => __( 'Debug Settings', 'media-library-assistant' ),
3441
- 'settings_list' => $settings_list,
3442
- 'Error Log' => __( 'Error Log', 'media-library-assistant' ),
3443
- 'Error Log Name' => $error_log_name,
3444
- 'Error Log Size' => number_format( (float) $error_log_size ),
3445
- 'error_log_text' => $error_log_contents,
3446
- 'download_link' => $download_link,
3447
- 'reset_link' => $reset_link,
3448
- 'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
3449
- /* translators: 1: "Save Changes" */
3450
- 'Click Save Changes' => sprintf( __( 'Click %1$s to update the %2$s.', 'media-library-assistant' ), '<strong>' . __( 'Save Changes', 'media-library-assistant' ) . '</strong>', __( 'Debug Options', 'media-library-assistant' ) ),
3451
- '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
3452
- '_wp_http_referer' => wp_referer_field( false )
3453
- );
3454
-
3455
- $page_content['body'] = MLAData::mla_parse_template( self::$page_template_array['debug-tab'], $page_values );
3456
- return $page_content;
3457
- }
3458
-
3459
- /**
3460
- * Render (echo) the "Media Library Assistant" subpage in the Settings section
3461
- *
3462
- * @since 0.1
3463
- *
3464
- * @return void Echoes HTML markup for the Settings subpage
3465
- */
3466
- public static function mla_render_settings_page( ) {
3467
- if ( !current_user_can( 'manage_options' ) ) {
3468
- echo __( 'Media Library Assistant', 'media-library-assistant' ) . ' - ' . __( 'ERROR', 'media-library-assistant' ) . "</h2>\r\n";
3469
- wp_die( __( 'You do not have permission to manage plugin settings.', 'media-library-assistant' ) );
3470
- }
3471
-
3472
- /*
3473
- * Load template array and initialize page-level values.
3474
- */
3475
- $development_version = MLA::MLA_DEVELOPMENT_VERSION;
3476
- $development_version = ( ! empty( $development_version ) ) ? ' (' . $development_version . ')' : '';
3477
- self::$page_template_array = MLACore::mla_load_template( 'admin-display-settings-page.tpl' );
3478
- $current_tab_slug = isset( $_REQUEST['mla_tab'] ) ? $_REQUEST['mla_tab']: 'general';
3479
- $current_tab = self::mla_get_options_tablist( $current_tab_slug );
3480
- $page_values = array(
3481
- 'Support Our Work' => __( 'Support Our Work', 'media-library-assistant' ),
3482
- 'Donate' => __( 'Donate', 'media-library-assistant' ),
3483
- 'version' => 'v' . MLACore::CURRENT_MLA_VERSION,
3484
- 'development' => $development_version,
3485
- 'messages' => '',
3486
- 'tablist' => self::_compose_settings_tabs( $current_tab_slug ),
3487
- 'tab_content' => '',
3488
- 'Media Library Assistant' => __( 'Media Library Assistant', 'media-library-assistant' ),
3489
- 'Settings' => __( 'Settings', 'media-library-assistant' )
3490
- );
3491
-
3492
- /*
3493
- * Compose tab content
3494
- */
3495
- if ( $current_tab ) {
3496
- if ( isset( $current_tab['render'] ) ) {
3497
- $handler = $current_tab['render'];
3498
- $page_content = call_user_func( $handler );
3499
- } else {
3500
- $page_content = array( 'message' => __( 'ERROR', 'media-library-assistant' ) . ': ' . __( 'Cannot render content tab', 'media-library-assistant' ), 'body' => '' );
3501
- }
3502
- } else {
3503
- $page_content = array( 'message' => __( 'ERROR', 'media-library-assistant' ) . ': ' . __( 'Unknown content tab', 'media-library-assistant' ), 'body' => '' );
3504
- }
3505
-
3506
- if ( ! empty( $page_content['message'] ) ) {
3507
- if ( false !== strpos( $page_content['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
3508
- $messages_class = 'mla_errors';
3509
- } else {
3510
- $messages_class = 'mla_messages';
3511
- }
3512
-
3513
- $page_values['messages'] = MLAData::mla_parse_template( self::$page_template_array['messages'], array(
3514
- 'messages' => $page_content['message'],
3515
- 'mla_messages_class' => $messages_class
3516
- ) );
3517
- }
3518
-
3519
- $page_values['tab_content'] = $page_content['body'];
3520
- echo MLAData::mla_parse_template( self::$page_template_array['page'], $page_values );
3521
- } // mla_render_settings_page
3522
-
3523
- /**
3524
- * Save MLA Gallery settings to the options table
3525
- *
3526
- * @since 0.80
3527
- *
3528
- * @uses $_REQUEST
3529
- *
3530
- * @return array Message(s) reflecting the results of the operation
3531
- */
3532
- private static function _save_gallery_settings( ) {
3533
- $settings_changed = false;
3534
- $message_list = '';
3535
- $error_list = '';
3536
-
3537
- /*
3538
- * Start with any page-level options
3539
- */
3540
- foreach ( MLACoreOptions::$mla_option_definitions as $key => $value ) {
3541
- if ( 'mla_gallery' == $value['tab'] ) {
3542
- $this_setting_changed = false;
3543
- $old_value = MLACore::mla_get_option( $key );
3544
-
3545
- if ( 'select' == $value['type'] ) {
3546
- if ( $old_value != $_REQUEST[ MLA_OPTION_PREFIX . $key ] ) {
3547
- $this_setting_changed = true;
3548
- }
3549
- } elseif ( 'text' == $value['type'] ) {
3550
- if ( '' == $_REQUEST[ MLA_OPTION_PREFIX . $key ] ) {
3551
- $_REQUEST[ MLA_OPTION_PREFIX . $key ] = $value['std'];
3552
- }
3553
-
3554
- if ( $old_value != $_REQUEST[ MLA_OPTION_PREFIX . $key ] ) {
3555
- $this_setting_changed = true;
3556
- }
3557
- } elseif ( 'checkbox' == $value['type'] ) {
3558
- if ( isset( $_REQUEST[ MLA_OPTION_PREFIX . $key ] ) ) {
3559
- $this_setting_changed = "checked" != $old_value;
3560
- } else {
3561
- $this_setting_changed = "checked" == $old_value;
3562
- }
3563
- }
3564
-
3565
- /*
3566
- * Always update to scrub default settings
3567
- */
3568
- $message = self::mla_update_option_row( $key, $value );
3569
- if ( $this_setting_changed ) {
3570
- $settings_changed = true;
3571
- $message_list .= $message;
3572
- }
3573
- } // mla_gallery option
3574
- } // foreach mla_options
3575
-
3576
- /*
3577
- * Get the current style contents for comparison
3578
- * $new_names[ shortcode ][ template_name ]
3579
- * $old_templates, $new_templates [ template_name ] - omit shortcode for backwards compatibility
3580
- */
3581
- $old_templates = MLATemplate_Support::mla_get_style_templates();
3582
- $new_templates = array();
3583
- $new_names = $_REQUEST['mla_style_templates_name'];
3584
- $new_values = stripslashes_deep( $_REQUEST['mla_style_templates_value'] );
3585
- $new_deletes = isset( $_REQUEST['mla_style_templates_delete'] ) ? $_REQUEST['mla_style_templates_delete']: array();
3586
-
3587
- /*
3588
- * Build new style template array, noting changes
3589
- */
3590
- $templates_changed = false;
3591
- foreach ( $new_names as $shortcode => $template_names ) {
3592
- $definition = MLATemplate_Support::$mla_template_definitions['style'][ $shortcode ];
3593
-
3594
- foreach ( $template_names as $name => $new_name ) {
3595
- if ( in_array( $name, $definition['default_names'] ) ) {
3596
- continue;
3597
- }
3598
-
3599
- if ( array_key_exists( $shortcode, $new_deletes ) && array_key_exists( $name, $new_deletes[ $shortcode ] ) ) {
3600
- /* translators: 1: template type 2: template name */
3601
- $message_list .= '<br>' . sprintf( _x( 'Deleting %1$s "%2$s".', 'message_list', 'media-library-assistant' ), __( 'Style Template', 'media-library-assistant' ), $name );
3602
- $templates_changed = true;
3603
- continue;
3604
- }
3605
-
3606
- $new_slug = sanitize_title( $new_name );
3607
- if ( 'blank' == $name ) {
3608
- if ( '' == $new_slug ) {
3609
- continue;
3610
- } elseif ( 'blank' == $new_slug ) {
3611
- /* translators: 1: ERROR tag 2: template name 3: template type */
3612
- $error_list .= '<br>' . sprintf( __( '%1$s: Reserved name "%2$s", new %3$s discarded.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $new_slug, __( 'Style Template', 'media-library-assistant' ) );
3613
- continue;
3614
- }
3615
-
3616
- if ( array_key_exists( $new_slug, $old_templates ) ) {
3617
- /* translators: 1: ERROR tag 2: template name 3: template type */
3618
- $error_list .= '<br>' . sprintf( __( '%1$s: Duplicate name "%2$s", new %3$s discarded.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $new_slug, __( 'Style Template', 'media-library-assistant' ) );
3619
- continue;
3620
- } else {
3621
- /* translators: 1: template type 2: template name */
3622
- $message_list .= '<br>' . sprintf( _x( 'Adding new %1$s "%2$s".', 'message_list', 'media-library-assistant' ), __( 'Style Template', 'media-library-assistant' ), $new_slug );
3623
- $templates_changed = true;
3624
- }
3625
- } // 'blank' - reserved name
3626
-
3627
- /*
3628
- * Handle name changes, check for duplicates
3629
- */
3630
- if ( '' == $new_slug ) {
3631
- /* translators: 1: ERROR tag 2: element name 3: old value */
3632
- $error_list .= '<br>' . sprintf( __( '%1$s: Blank %2$s, reverting to "%3$s".', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'style template name', 'media-library-assistant' ), $name );
3633
- $new_slug = $name;
3634
- }
3635
-
3636
- if ( $new_slug != $name ) {
3637
- if ( array_key_exists( $new_slug, $old_templates ) ) {
3638
- /* translators: 1: ERROR tag 2: element name 3: new value 4: old value */
3639
- $error_list .= '<br>' . sprintf( __( '%1$s: Duplicate new %2$s "%3$s", reverting to "%4$s".', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'style template name', 'media-library-assistant' ), $new_slug, $name );
3640
- $new_slug = $name;
3641
- } elseif ( 'blank' == $new_slug ) {
3642
- /* translators: 1: ERROR tag 2: element name 3: new value 4: old value */
3643
- $error_list .= '<br>' . sprintf( __( '%1$s: Reserved %2$s "%3$s", reverting to "%4$s".', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'style template name', 'media-library-assistant' ), $new_slug, $name );
3644
- $new_slug = $name;
3645
- } elseif ( 'blank' != $name ) {
3646
- /* translators: 1: element name 2: old_value 3: new_value */
3647
- $message_list .= '<br>' . sprintf( _x( 'Changing %1$s from "%2$s" to "%3$s"', 'message_list', 'media-library-assistant' ), __( 'style template name', 'media-library-assistant' ), $name, $new_slug );
3648
- $templates_changed = true;
3649
- }
3650
- } // name changed
3651
-
3652
- if ( ( 'blank' != $name ) && ( $new_values[ $shortcode ][ $name ] != $old_templates[ $name ] ) ) {
3653
- /* translators: 1: template type 2: template name */
3654
- $message_list .= '<br>' . sprintf( _x( 'Updating contents of %1$s "%2$s".', 'message_list', 'media-library-assistant' ), __( 'Style Template', 'media-library-assistant' ), $new_slug );
3655
- $templates_changed = true;
3656
- }
3657
-
3658
- /*
3659
- * Encode shortcode assignment in template content
3660
- */
3661
- $new_templates[ $new_slug ] = sprintf( "<!-- mla_shortcode_slug=\"%1\$s\" -->\r\n%2\$s", $definition['slug'], $new_values[ $shortcode ][ $name ] );
3662
- } // foreach $name
3663
- } // each shortcode
3664
-
3665
- if ( $templates_changed ) {
3666
- $settings_changed = true;
3667
- if ( false == MLATemplate_Support::mla_put_style_templates( $new_templates ) ) {
3668
- /* translators: 1: ERROR tag 2: template type */
3669
- $error_list .= '<br>' . sprintf( __( '%1$s: Update of %2$s failed.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'Style Template', 'media-library-assistant' ) );
3670
- }
3671
- }
3672
-
3673
- /*
3674
- * Get the current markup contents for comparison
3675
- */
3676
- $old_templates = MLATemplate_Support::mla_get_markup_templates();
3677
- $new_templates = array();
3678
- $new_names = $_REQUEST['mla_markup_templates_name'];
3679
- $new_deletes = isset( $_REQUEST['mla_markup_templates_delete'] ) ? $_REQUEST['mla_markup_templates_delete']: array();
3680
- $new_values = stripslashes_deep( $_REQUEST['mla_markup_templates_sections'] );
3681
-
3682
- /*
3683
- * Build new markup template array, noting changes
3684
- */
3685
- $templates_changed = false;
3686
- foreach ( $new_names as $shortcode => $template_names ) {
3687
- $definition = MLATemplate_Support::$mla_template_definitions['markup'][ $shortcode ];
3688
-
3689
- foreach ( $template_names as $name => $new_name ) {
3690
- if ( in_array( $name, $definition['default_names'] ) ) {
3691
- continue;
3692
- }
3693
-
3694
- if ( array_key_exists( $shortcode, $new_deletes ) && array_key_exists( $name, $new_deletes[ $shortcode ] ) ) {
3695
- /* translators: 1: template type 2: template name */
3696
- $message_list .= '<br>' . sprintf( _x( 'Deleting %1$s "%2$s".', 'message_list', 'media-library-assistant' ), __( 'markup template', 'media-library-assistant' ), $name );
3697
- $templates_changed = true;
3698
- continue;
3699
- }
3700
-
3701
- $new_slug = sanitize_title( $new_name );
3702
- if ( 'blank' == $name ) {
3703
- if ( '' == $new_slug ) {
3704
- continue;
3705
- }
3706
-
3707
- if ( 'blank' == $new_slug ) {
3708
- /* translators: 1: ERROR tag 2: template name 3: template type */
3709
- $error_list .= '<br>' . sprintf( __( '%1$s: Reserved name "%2$s", new %3$s discarded.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $new_slug, __( 'markup template', 'media-library-assistant' ) );
3710
- continue;
3711
- }
3712
-
3713
- if ( array_key_exists( $new_slug, $old_templates ) ) {
3714
- /* translators: 1: ERROR tag 2: template name 3: template type */
3715
- $error_list .= '<br>' . sprintf( __( '%1$s: Duplicate name "%2$s", new %3$s discarded.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $new_slug, __( 'markup template', 'media-library-assistant' ) );
3716
- continue;
3717
- } else {
3718
- /* translators: 1: template type 2: template name */
3719
- $message_list .= '<br>' . sprintf( _x( 'Adding new %1$s "%2$s".', 'message_list', 'media-library-assistant' ), __( 'markup template', 'media-library-assistant' ), $new_slug );
3720
- $templates_changed = true;
3721
- }
3722
- } // 'blank' - reserved name
3723
-
3724
- /*
3725
- * Handle name changes, check for duplicates
3726
- */
3727
- if ( '' == $new_slug ) {
3728
- /* translators: 1: ERROR tag 2: element name 3: old value */
3729
- $error_list .= '<br>' . sprintf( __( '%1$s: Blank %2$s, reverting to "%3$s".', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'markup template name', 'media-library-assistant' ), $name );
3730
- $new_slug = $name;
3731
- }
3732
-
3733
- if ( $new_slug != $name ) {
3734
- if ( array_key_exists( $new_slug, $old_templates ) ) {
3735
- /* translators: 1: ERROR tag 2: element name 3: new value 4: old value */
3736
- $error_list .= '<br>' . sprintf( __( '%1$s: Duplicate new %2$s "%3$s", reverting to "%4$s".', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'markup template name', 'media-library-assistant' ), $new_slug, $name );
3737
- $new_slug = $name;
3738
- } elseif ( 'blank' == $new_slug ) {
3739
- /* translators: 1: ERROR tag 2: element name 3: new value 4: old value */
3740
- $error_list .= '<br>' . sprintf( __( '%1$s: Reserved %2$s "%3$s", reverting to "%4$s".', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'markup template name', 'media-library-assistant' ), $new_slug, $name );
3741
- $new_slug = $name;
3742
- } elseif ( 'blank' != $name ) {
3743
- /* translators: 1: element name 2: old_value 3: new_value */
3744
- $message_list .= '<br>' . sprintf( _x( 'Changing %1$s from "%2$s" to "%3$s"', 'message_list', 'media-library-assistant' ), __( 'markup template name', 'media-library-assistant' ), $name, $new_slug );
3745
- $templates_changed = true;
3746
- }
3747
- } // name changed
3748
-
3749
- if ( 'blank' != $name ) {
3750
- foreach ( $new_values[ $shortcode ][ $name ] as $section_name => $section_value ) {
3751
- $old_value = isset( $old_templates[ $name ][ $section_name ] ) ? $old_templates[ $name ][ $section_name ] : '';
3752
- if ( $section_value != $old_value ) {
3753
- /* translators: 1: section name, 2: template name */
3754
- $message_list .= '<br>' . sprintf( _x( 'Updating %1$s markup for "%2$s".', 'message_list', 'media-library-assistant' ), $section_name, $new_slug );
3755
- $templates_changed = true;
3756
- }
3757
- }
3758
- } // ! 'blank'
3759
-
3760
- /*
3761
- * Encode shortcode assignment in template content
3762
- */
3763
- if ( isset( $new_values[ $shortcode ][ $name ]['arguments'] ) ) {
3764
- $new_values[ $shortcode ][ $name ]['arguments'] = sprintf( "mla_shortcode_slug=\"%1\$s\"\r\n%2\$s", $definition['slug'], $new_values[ $shortcode ][ $name ]['arguments'] );
3765
- } else {
3766
- $new_values[ $shortcode ][ $name ]['arguments'] = sprintf( "mla_shortcode_slug=\"%1\$s\"\r\n", $definition['slug'] );
3767
- }
3768
-
3769
- foreach ( $new_values[ $shortcode ][ $name ] as $section_name => $section_value ) {
3770
- if ( !empty( $section_value ) ) {
3771
- $new_templates[ $new_slug ][ $section_name ] = $section_value;
3772
- }
3773
- }
3774
- } // foreach $name
3775
- } // foreach $shortcode
3776
-
3777
- if ( $templates_changed ) {
3778
- $settings_changed = true;
3779
- if ( false == MLATemplate_Support::mla_put_markup_templates( $new_templates ) ) {
3780
- /* translators: 1: ERROR tag 2: template type */
3781
- $error_list .= '<br>' . sprintf( __( '%1$s: Update of %2$s failed.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'markup template', 'media-library-assistant' ) );
3782
- }
3783
- }
3784
-
3785
- if ( $settings_changed ) {
3786
- /* translators: 1: field type */
3787
- $message = sprintf( __( '%1$s settings saved.', 'media-library-assistant' ), __( 'Shortcodes', 'media-library-assistant' ) ) . "\r\n";
3788
- } else {
3789
- /* translators: 1: field type */
3790
- $message = sprintf( __( '%1$s no changes detected.', 'media-library-assistant' ), __( 'Shortcodes', 'media-library-assistant' ) ) . "\r\n";
3791
- }
3792
-
3793
- $page_content = array(
3794
- 'message' => $message . $error_list,
3795
- 'body' => ''
3796
- );
3797
-
3798
- /*
3799
- * Uncomment this for debugging.
3800
- */
3801
- // $page_content['message'] .= $message_list;
3802
-
3803
- return $page_content;
3804
- } // _save_gallery_settings
3805
-
3806
- /**
3807
- * Save View settings to the options table
3808
- *
3809
- * @since 1.40
3810
- *
3811
- * @uses $_REQUEST
3812
- *
3813
- * @return array Message(s) reflecting the results of the operation
3814
- */
3815
- private static function _save_view_settings( ) {
3816
- $message_list = '';
3817
-
3818
- foreach ( MLACoreOptions::$mla_option_definitions as $key => $value ) {
3819
- if ( 'view' == $value['tab'] ) {
3820
- $message_list .= self::mla_update_option_row( $key, $value );
3821
- } // view option
3822
- } // foreach mla_options
3823
-
3824
- $page_content = array(
3825
- 'message' => __( 'View settings saved.', 'media-library-assistant' ) . "\r\n",
3826
- 'body' => ''
3827
- );
3828
 
3829
  /*
3830
- * Uncomment this for debugging.
3831
  */
3832
- // $page_content['message'] .= $message_list;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3833
 
 
3834
  return $page_content;
3835
- } // _save_view_settings
3836
 
3837
  /**
3838
- * Save Upload settings to the options table
3839
- *
3840
- * @since 1.40
3841
  *
3842
- * @uses $_REQUEST
3843
  *
3844
- * @return array Message(s) reflecting the results of the operation
3845
  */
3846
- private static function _save_upload_settings( ) {
3847
- $message_list = '';
3848
-
3849
- if ( ! isset( $_REQUEST[ MLA_OPTION_PREFIX . MLACoreOptions::MLA_ENABLE_UPLOAD_MIMES ] ) )
3850
- unset( $_REQUEST[ MLA_OPTION_PREFIX . MLACoreOptions::MLA_ENABLE_MLA_ICONS ] );
3851
-
3852
- foreach ( MLACoreOptions::$mla_option_definitions as $key => $value ) {
3853
- if ( 'upload' == $value['tab'] ) {
3854
- $message_list .= self::mla_update_option_row( $key, $value );
3855
- } // upload option
3856
- } // foreach mla_options
3857
 
3858
- $page_content = array(
3859
- 'message' => __( 'Upload MIME Type settings saved.', 'media-library-assistant' ) . "\r\n",
3860
- 'body' => ''
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3861
  );
 
3862
 
3863
  /*
3864
- * Uncomment this for debugging.
3865
  */
3866
- // $page_content['message'] .= $message_list;
3867
-
3868
- return $page_content;
3869
- } // _save_upload_settings
3870
-
3871
- /**
3872
- * Process custom field settings against all image attachments
3873
- * without saving the settings to the mla_option
3874
- *
3875
- * @since 1.10
3876
- * @uses $_REQUEST if passed a NULL parameter
3877
- *
3878
- * @param array | NULL specific custom_field_mapping values
3879
- * @param integer offset for chunk mapping
3880
- * @param integer length for chunk mapping
3881
- *
3882
- * @return array Message(s) reflecting the results of the operation
3883
- */
3884
- private static function _process_custom_field_mapping( $settings = NULL, $offset = 0, $length = 0 ) {
3885
- global $wpdb;
3886
- if ( NULL == $settings ) {
3887
- $source = 'custom_fields';
3888
- $settings = ( isset( $_REQUEST['custom_field_mapping'] ) ) ? stripslashes_deep( $_REQUEST['custom_field_mapping'] ) : array();
3889
- if ( isset( $settings[ MLACoreOptions::MLA_NEW_CUSTOM_FIELD ] ) ) {
3890
- unset( $settings[ MLACoreOptions::MLA_NEW_CUSTOM_FIELD ] );
3891
- }
3892
- if ( isset( $settings[ MLACoreOptions::MLA_NEW_CUSTOM_RULE ] ) ) {
3893
- unset( $settings[ MLACoreOptions::MLA_NEW_CUSTOM_RULE ] );
3894
  }
3895
  } else {
3896
- $source = 'custom_rule';
3897
- $settings = stripslashes_deep( $settings );
3898
- }
3899
-
3900
- if ( empty( $settings ) ) {
3901
- return array(
3902
- 'message' => __( 'ERROR', 'media-library-assistant' ) . ': ' . __( 'No custom field mapping rules to process.', 'media-library-assistant' ),
3903
- 'body' => '' ,
3904
- 'processed' => 0,
3905
- 'unchanged' => 0,
3906
- 'success' => 0
3907
- );
3908
- }
3909
-
3910
- if ( $length > 0 ) {
3911
- $limits = "LIMIT {$offset}, {$length}";
3912
- } else {
3913
- $limits = '';
3914
  }
3915
 
3916
- $examine_count = 0;
3917
- $update_count = 0;
3918
- $post_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE `post_type` = 'attachment' {$limits}" );
3919
-
3920
- do_action( 'mla_begin_mapping', $source, NULL );
3921
- foreach ( $post_ids as $key => $post_id ) {
3922
- $updates = MLAOptions::mla_evaluate_custom_field_mapping( (integer) $post_id, 'custom_field_mapping', $settings );
3923
- $examine_count += 1;
3924
- if ( ! empty( $updates ) && isset( $updates['custom_updates'] ) ) {
3925
- $results = MLAData::mla_update_item_postmeta( (integer) $post_id, $updates['custom_updates'] );
3926
- if ( ! empty( $results ) ) {
3927
- $update_count += 1;
3928
- }
3929
  }
3930
- } // foreach post
3931
- do_action( 'mla_end_mapping' );
3932
 
3933
- if ( $update_count ) {
3934
- /* translators: 1: field type 2: examined count 3: updated count */
3935
- $message = sprintf( __( '%1$s mapping completed; %2$d attachment(s) examined, %3$d updated.' ), __( 'Custom field', 'media-library-assistant' ), $examine_count, $update_count ) . "\r\n";
3936
- } else {
3937
- /* translators: 1: field type 2: examined count */
3938
- $message = sprintf( __( '%1$s mapping completed; %2$d attachment(s) examined, no changes detected.' ), __( 'Custom field', 'media-library-assistant' ), $examine_count ) . "\r\n";
3939
  }
3940
 
3941
- return array(
3942
- 'message' => $message,
3943
- 'body' => '',
3944
- 'processed' => $examine_count,
3945
- 'unchanged' => $examine_count - $update_count,
3946
- 'success' => $update_count
3947
- );
3948
- } // _process_custom_field_mapping
3949
 
3950
  /**
3951
  * Delete a custom field from the wp_postmeta table
@@ -3956,7 +1465,7 @@ class MLASettings {
3956
  *
3957
  * @return array Message(s) reflecting the results of the operation
3958
  */
3959
- private static function _delete_custom_field( $value ) {
3960
  global $wpdb;
3961
 
3962
  $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->postmeta} LEFT JOIN {$wpdb->posts} ON ( {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id ) WHERE {$wpdb->postmeta}.meta_key = '%s' AND {$wpdb->posts}.post_type = 'attachment'", $value['name'] ));
@@ -3972,339 +1481,7 @@ class MLASettings {
3972
  }
3973
 
3974
  return __( 'No attachments contained this custom field.', 'media-library-assistant' ) . '<br>';
3975
- } // _delete_custom_field
3976
-
3977
- /**
3978
- * Save custom field settings to the options table
3979
- *
3980
- * @since 1.10
3981
- * @uses $_REQUEST if passed a NULL parameter
3982
- *
3983
- * @param array | NULL specific custom_field_mapping values
3984
- *
3985
- * @return array Message(s) reflecting the results of the operation
3986
- */
3987
- private static function _save_custom_field_settings( $new_values = NULL ) {
3988
- $message_list = '';
3989
- $option_messages = '';
3990
-
3991
- if ( NULL == $new_values ) {
3992
- /*
3993
- * Start with any page-level options
3994
- */
3995
- foreach ( MLACoreOptions::$mla_option_definitions as $key => $value ) {
3996
- if ( 'custom_field' == $value['tab'] ) {
3997
- $option_messages .= self::mla_update_option_row( $key, $value );
3998
- }
3999
- }
4000
-
4001
- /*
4002
- * Add mapping options
4003
- */
4004
- $new_values = ( isset( $_REQUEST['custom_field_mapping'] ) ) ? $_REQUEST['custom_field_mapping'] : array();
4005
- } // NULL
4006
-
4007
- /*
4008
- * Uncomment this for debugging.
4009
- */
4010
- // $message_list = $option_messages . '<br>';
4011
-
4012
- return array(
4013
- 'message' => $message_list . MLAOptions::mla_custom_field_option_handler( 'update', 'custom_field_mapping', MLACoreOptions::$mla_option_definitions['custom_field_mapping'], $new_values ),
4014
- 'body' => ''
4015
- );
4016
- } // _save_custom_field_settings
4017
-
4018
- /**
4019
- * Process IPTC/EXIF standard field settings against all image attachments
4020
- * without saving the settings to the mla_option
4021
- *
4022
- * @since 1.00
4023
- *
4024
- * @uses $_REQUEST
4025
- *
4026
- * @param integer offset for chunk mapping
4027
- * @param integer length for chunk mapping
4028
- *
4029
- * @return array Message(s) reflecting the results of the operation
4030
- */
4031
- private static function _process_iptc_exif_standard( $offset = 0, $length = 0 ) {
4032
- if ( ! isset( $_REQUEST['iptc_exif_mapping']['standard'] ) ) {
4033
- return array(
4034
- /* translators: 1: ERROR tag 2: field type */
4035
- 'message' => sprintf( __( '%1$s: No %2$s settings to process.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'Standard field', 'media-library-assistant' ) ),
4036
- 'body' => '',
4037
- 'processed' => 0,
4038
- 'unchanged' => 0,
4039
- 'success' => 0,
4040
- );
4041
- }
4042
-
4043
- $examine_count = 0;
4044
- $update_count = 0;
4045
- $query = array( 'orderby' => 'none', 'post_parent' => 'all', 'post_mime_type' => 'image,application/*pdf*' );
4046
-
4047
- if ( $length > 0 ) {
4048
- $query['numberposts'] = $length;
4049
- $query['offset'] = $offset;
4050
- }
4051
-
4052
- do_action( 'mla_begin_mapping', 'iptc_exif_standard', NULL );
4053
- $posts = MLAShortcodes::mla_get_shortcode_attachments( 0, $query );
4054
-
4055
- if ( is_string( $posts ) ) {
4056
- return array(
4057
- 'message' => $posts,
4058
- 'body' => ''
4059
- );
4060
- }
4061
-
4062
- foreach ( $posts as $key => $post ) {
4063
- $updates = MLAOptions::mla_evaluate_iptc_exif_mapping( $post, 'iptc_exif_standard_mapping', $_REQUEST['iptc_exif_mapping'] );
4064
-
4065
- $examine_count += 1;
4066
- if ( ! empty( $updates ) ) {
4067
- $results = MLAData::mla_update_single_item( $post->ID, $updates );
4068
- if ( stripos( $results['message'], __( 'updated.', 'media-library-assistant' ) ) ) {
4069
- $update_count += 1;
4070
- }
4071
- }
4072
- } // foreach post
4073
- do_action( 'mla_end_mapping' );
4074
-
4075
- if ( $update_count ) {
4076
- /* translators: 1: field type 2: examined count 3: updated count */
4077
- $message = sprintf( __( '%1$s mapping completed; %2$d attachment(s) examined, %3$d updated.' ), 'IPTC/EXIF ' . __( 'Standard field', 'media-library-assistant' ), $examine_count, $update_count ) . "\r\n";
4078
- } else {
4079
- /* translators: 1: field type 2: examined count */
4080
- $message = sprintf( __( '%1$s mapping completed; %2$d attachment(s) examined, no changes detected.' ), 'IPTC/EXIF ' . __( 'Standard field', 'media-library-assistant' ), $examine_count ) . "\r\n";
4081
- }
4082
-
4083
- return array(
4084
- 'message' => $message,
4085
- 'body' => '',
4086
- 'processed' => $examine_count,
4087
- 'unchanged' => $examine_count - $update_count,
4088
- 'success' => $update_count
4089
- );
4090
- } // _process_iptc_exif_standard
4091
-
4092
- /**
4093
- * Process IPTC/EXIF taxonomy term settings against all image attachments
4094
- * without saving the settings to the mla_option
4095
- *
4096
- * @since 1.00
4097
- *
4098
- * @uses $_REQUEST
4099
- *
4100
- * @param integer offset for chunk mapping
4101
- * @param integer length for chunk mapping
4102
- *
4103
- * @return array Message(s) reflecting the results of the operation
4104
- */
4105
- private static function _process_iptc_exif_taxonomy( $offset = 0, $length = 0 ) {
4106
- if ( ! isset( $_REQUEST['iptc_exif_mapping']['taxonomy'] ) ) {
4107
- return array(
4108
- /* translators: 1: ERROR tag 2: field type */
4109
- 'message' => sprintf( __( '%1$s: No %2$s settings to process.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'Taxonomy term', 'media-library-assistant' ) ),
4110
- 'body' => '',
4111
- 'processed' => 0,
4112
- 'unchanged' => 0,
4113
- 'success' => 0,
4114
- );
4115
- }
4116
-
4117
- $examine_count = 0;
4118
- $update_count = 0;
4119
- $query = array( 'orderby' => 'none', 'post_parent' => 'all', 'post_mime_type' => 'image,application/*pdf*' );
4120
-
4121
- if ( $length > 0 ) {
4122
- $query['numberposts'] = $length;
4123
- $query['offset'] = $offset;
4124
- }
4125
-
4126
- do_action( 'mla_begin_mapping', 'iptc_exif_taxonomy', NULL );
4127
- $posts = MLAShortcodes::mla_get_shortcode_attachments( 0, $query );
4128
-
4129
- if ( is_string( $posts ) ) {
4130
- return array(
4131
- 'message' => $posts,
4132
- 'body' => ''
4133
- );
4134
- }
4135
-
4136
- foreach ( $posts as $key => $post ) {
4137
- $updates = MLAOptions::mla_evaluate_iptc_exif_mapping( $post, 'iptc_exif_taxonomy_mapping', $_REQUEST['iptc_exif_mapping'] );
4138
-
4139
- $examine_count += 1;
4140
- if ( ! empty( $updates ) ) {
4141
- $results = MLAData::mla_update_single_item( $post->ID, array(), $updates['taxonomy_updates']['inputs'], $updates['taxonomy_updates']['actions'] );
4142
- if ( stripos( $results['message'], __( 'updated.', 'media-library-assistant' ) ) ) {
4143
- $update_count += 1;
4144
- }
4145
- }
4146
- } // foreach post
4147
- do_action( 'mla_end_mapping' );
4148
-
4149
- if ( $update_count ) {
4150
- /* translators: 1: field type 2: examined count 3: updated count */
4151
- $message = sprintf( __( '%1$s mapping completed; %2$d attachment(s) examined, %3$d updated.' ), 'IPTC/EXIF ' . __( 'Taxonomy term', 'media-library-assistant' ), $examine_count, $update_count ) . "\r\n";
4152
- } else {
4153
- /* translators: 1: field type 2: examined count */
4154
- $message = sprintf( __( '%1$s mapping completed; %2$d attachment(s) examined, no changes detected.' ), 'IPTC/EXIF ' . __( 'Taxonomy term', 'media-library-assistant' ), $examine_count ) . "\r\n";
4155
- }
4156
-
4157
- return array(
4158
- 'message' => $message,
4159
- 'body' => '',
4160
- 'processed' => $examine_count,
4161
- 'unchanged' => $examine_count - $update_count,
4162
- 'success' => $update_count
4163
- );
4164
- } // _process_iptc_exif_taxonomy
4165
-
4166
- /**
4167
- * Process IPTC/EXIF custom field settings against all image attachments
4168
- * without saving the settings to the mla_option
4169
- *
4170
- * @since 1.00
4171
- *
4172
- * @uses $_REQUEST if passed a NULL parameter
4173
- *
4174
- * @param array | NULL specific iptc_exif_custom_mapping values
4175
- * @param integer offset for chunk mapping
4176
- * @param integer length for chunk mapping
4177
- *
4178
- * @return array Message(s) reflecting the results of the operation
4179
- */
4180
- private static function _process_iptc_exif_custom( $settings = NULL, $offset = 0, $length = 0 ) {
4181
- if ( NULL == $settings ) {
4182
- $source = 'iptc_exif_custom';
4183
- $settings = ( isset( $_REQUEST['iptc_exif_mapping'] ) ) ? stripslashes_deep( $_REQUEST['iptc_exif_mapping'] ) : array();
4184
- if ( isset( $settings['custom'][ MLACoreOptions::MLA_NEW_CUSTOM_FIELD ] ) ) {
4185
- unset( $settings['custom'][ MLACoreOptions::MLA_NEW_CUSTOM_FIELD ] );
4186
- }
4187
- if ( isset( $settings['custom'][ MLACoreOptions::MLA_NEW_CUSTOM_RULE ] ) ) {
4188
- unset( $settings['custom'][ MLACoreOptions::MLA_NEW_CUSTOM_RULE ] );
4189
- }
4190
- } else {
4191
- $source = 'iptc_exif_custom_rule';
4192
- $settings = stripslashes_deep( $settings );
4193
- }
4194
-
4195
- if ( empty( $settings['custom'] ) ) {
4196
- return array(
4197
- /* translators: 1: ERROR tag 2: field type */
4198
- 'message' => sprintf( __( '%1$s: No %2$s settings to process.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'Custom field', 'media-library-assistant' ) ),
4199
- 'body' => '',
4200
- 'processed' => 0,
4201
- 'unchanged' => 0,
4202
- 'success' => 0,
4203
- );
4204
- }
4205
-
4206
- $examine_count = 0;
4207
- $update_count = 0;
4208
- $query = array( 'orderby' => 'none', 'post_parent' => 'all', 'post_mime_type' => 'image,application/*pdf*' );
4209
-
4210
- if ( $length > 0 ) {
4211
- $query['numberposts'] = $length;
4212
- $query['offset'] = $offset;
4213
- }
4214
-
4215
- do_action( 'mla_begin_mapping', $source, NULL );
4216
- $posts = MLAShortcodes::mla_get_shortcode_attachments( 0, $query );
4217
-
4218
- if ( is_string( $posts ) ) {
4219
- return array(
4220
- 'message' => $posts,
4221
- 'body' => ''
4222
- );
4223
- }
4224
-
4225
- foreach ( $posts as $key => $post ) {
4226
- $updates = MLAOptions::mla_evaluate_iptc_exif_mapping( $post, 'iptc_exif_custom_mapping', $settings );
4227
-
4228
- $examine_count += 1;
4229
- if ( ! empty( $updates ) ) {
4230
- $results = MLAData::mla_update_single_item( $post->ID, $updates );
4231
- if ( stripos( $results['message'], __( 'updated.', 'media-library-assistant' ) ) ) {
4232
- $update_count += 1;
4233
- }
4234
- }
4235
- } // foreach post
4236
- do_action( 'mla_end_mapping' );
4237
-
4238
- if ( $update_count ) {
4239
- /* translators: 1: field type 2: examined count 3: updated count */
4240
- $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";
4241
- } else {
4242
- /* translators: 1: field type 2: examined count */
4243
- $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";
4244
- }
4245
-
4246
- return array(
4247
- 'message' => $message,
4248
- 'body' => '',
4249
- 'processed' => $examine_count,
4250
- 'unchanged' => $examine_count - $update_count,
4251
- 'success' => $update_count
4252
- );
4253
- } // _process_iptc_exif_custom
4254
-
4255
- /**
4256
- * Save IPTC/EXIF custom field settings to the options table
4257
- *
4258
- * @since 1.30
4259
- *
4260
- * @param array specific iptc_exif_custom_mapping values
4261
- *
4262
- * @return array Message(s) reflecting the results of the operation
4263
- */
4264
- private static function _save_iptc_exif_custom_settings( $new_values ) {
4265
- return array(
4266
- 'message' => MLAOptions::mla_iptc_exif_option_handler( 'update', 'iptc_exif_custom_mapping', MLACoreOptions::$mla_option_definitions['iptc_exif_mapping'], $new_values ),
4267
- 'body' => ''
4268
- );
4269
- } // _save_iptc_exif_custom_settings
4270
-
4271
- /**
4272
- * Save IPTC/EXIF settings to the options table
4273
- *
4274
- * @since 1.00
4275
- *
4276
- * @uses $_REQUEST
4277
- *
4278
- * @return array Message(s) reflecting the results of the operation
4279
- */
4280
- private static function _save_iptc_exif_settings( ) {
4281
- $message_list = '';
4282
- $option_messages = '';
4283
-
4284
- /*
4285
- * Start with any page-level options
4286
- */
4287
- foreach ( MLACoreOptions::$mla_option_definitions as $key => $value ) {
4288
- if ( 'iptc_exif' == $value['tab'] ) {
4289
- $option_messages .= self::mla_update_option_row( $key, $value );
4290
- }
4291
- }
4292
-
4293
- /*
4294
- * Uncomment this for debugging.
4295
- */
4296
- //$message_list = $option_messages . '<br>';
4297
-
4298
- /*
4299
- * Add mapping options
4300
- */
4301
- $new_values = ( isset( $_REQUEST['iptc_exif_mapping'] ) ) ? $_REQUEST['iptc_exif_mapping'] : array( 'standard' => array(), 'taxonomy' => array(), 'custom' => array() );
4302
-
4303
- return array(
4304
- 'message' => $message_list . MLAOptions::mla_iptc_exif_option_handler( 'update', 'iptc_exif_mapping', MLACoreOptions::$mla_option_definitions['iptc_exif_mapping'], $new_values ),
4305
- 'body' => ''
4306
- );
4307
- } // _save_iptc_exif_settings
4308
 
4309
  /**
4310
  * Save General settings to the options table
@@ -4574,7 +1751,7 @@ class MLASettings {
4574
  if (false === @fwrite($file_handle, $settings)) {
4575
  $error_info = error_get_last();
4576
  /* translators: 1: ERROR tag 2: PHP error information */
4577
- 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 );
4578
 
4579
  if ( false !== ( $tail = strpos( $error_info['message'], '</a>]: ' ) ) ) {
4580
  $php_errormsg = ':<br>' . substr( $error_info['message'], $tail + 7 );
@@ -4628,7 +1805,7 @@ class MLASettings {
4628
  if ( false === $settings ) {
4629
  $error_info = error_get_last();
4630
  /* translators: 1: ERROR tag 2: PHP error information */
4631
- error_log( sprintf( _x( '%1$s: _import_settings $error_info = "%2$s".', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), var_export( $error_info, true ) ), 0 );
4632
 
4633
  if ( false !== ( $tail = strpos( $error_info['message'], '</a>]: ' ) ) ) {
4634
  $php_errormsg = ':<br>' . substr( $error_info['message'], $tail + 7 );
22
  */
23
  const JAVASCRIPT_INLINE_EDIT_VIEW_SLUG = 'mla-inline-edit-view-scripts';
24
 
 
 
 
 
 
 
 
 
 
25
  /**
26
  * Slug for localizing and enqueueing JavaScript - MLA Upload List Table
27
  *
31
  */
32
  const JAVASCRIPT_INLINE_EDIT_UPLOAD_SLUG = 'mla-inline-edit-upload-scripts';
33
 
 
 
 
 
 
 
 
 
 
34
  /**
35
  * Slug for localizing and enqueueing JavaScript - MLA Custom tab
36
  *
75
  * @return void
76
  */
77
  public static function initialize( ) {
78
+ MLASettings::_localize_tablist();
79
+
80
  //add_action( 'admin_page_access_denied', 'MLASettings::mla_admin_page_access_denied_action' );
81
  add_action( 'admin_init', 'MLASettings::mla_admin_init_action' );
82
  add_action( 'admin_menu', 'MLASettings::mla_admin_menu_action' );
84
  add_filter( 'set-screen-option', 'MLASettings::mla_set_screen_option_filter', 10, 3 ); // $status, $option, $value
85
  add_filter( 'screen_options_show_screen', 'MLASettings::mla_screen_options_show_screen_filter', 10, 2 ); // $show_screen, $this
86
  self::_version_upgrade();
87
+
88
+ if( defined('DOING_AJAX') && DOING_AJAX && isset( $_REQUEST['action'] ) ) {
89
+ // Ajax handlers
90
+ switch ( $_REQUEST['action'] ) {
91
+ case self::JAVASCRIPT_INLINE_EDIT_UPLOAD_SLUG:
92
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-settings-upload-tab.php' );
93
+ break;
94
+ case self::JAVASCRIPT_INLINE_EDIT_VIEW_SLUG:
95
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-settings-view-tab.php' );
96
+ break;
97
+ case self::JAVASCRIPT_INLINE_MAPPING_CUSTOM_SLUG:
98
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-settings-custom-fields-tab.php' );
99
+ break;
100
+ case self::JAVASCRIPT_INLINE_MAPPING_IPTC_EXIF_SLUG:
101
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-settings-iptc-exif-tab.php' );
102
+ break;
103
+ }
104
+ } elseif ( isset( $_REQUEST['page'] ) && is_string( $_REQUEST['page'] ) && ( 'mla-settings-menu-' == substr( $_REQUEST['page'], 0, 18 ) ) ) {
105
+ // Settings/Media Library Assistant current tab
106
+ switch( substr( $_REQUEST['page'], 18 ) ) {
107
+ case 'upload':
108
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-settings-upload-tab.php' );
109
+ break;
110
+ case 'view':
111
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-settings-view-tab.php' );
112
+ break;
113
+ case 'shortcodes':
114
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-settings-shortcodes-tab.php' );
115
+ break;
116
+ case 'custom_field':
117
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-settings-custom-fields-tab.php' );
118
+ break;
119
+ case 'iptc_exif':
120
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-settings-iptc-exif-tab.php' );
121
+ break;
122
+ case 'documentation':
123
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-settings-documentation-tab.php' );
124
+ break;
125
+ }
126
+ }
127
  }
128
 
129
  /**
345
  * @return void
346
  */
347
  public static function mla_admin_init_action() {
348
+ add_action( 'wp_ajax_' . self::JAVASCRIPT_INLINE_EDIT_VIEW_SLUG, 'MLASettings_View::mla_inline_edit_view_action' );
349
+ add_action( 'wp_ajax_' . self::JAVASCRIPT_INLINE_EDIT_UPLOAD_SLUG, 'MLASettings_Upload::mla_inline_edit_upload_action' );
350
+ add_action( 'wp_ajax_' . self::JAVASCRIPT_INLINE_MAPPING_CUSTOM_SLUG, 'MLASettings_CustomFields::mla_inline_mapping_custom_action' );
351
+ add_action( 'wp_ajax_' . self::JAVASCRIPT_INLINE_MAPPING_IPTC_EXIF_SLUG, 'MLASettings_IPTCEXIF::mla_inline_mapping_iptc_exif_action' );
352
  }
353
 
354
  /**
377
  }
378
 
379
  wp_enqueue_style( MLACore::STYLESHEET_SLUG );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
380
  }
381
 
382
  /**
400
  $tab = 'general';
401
  }
402
 
403
+ $tab = self::_get_options_tablist( $tab ) ? '-' . $tab : '-general';
404
  self::$current_page_hook = add_submenu_page( 'options-general.php', __( 'Media Library Assistant', 'media-library-assistant' ) . ' ' . __( 'Settings', 'media-library-assistant' ), __( 'Media Library Assistant', 'media-library-assistant' ), 'manage_options', MLACoreOptions::MLA_SETTINGS_SLUG . $tab, 'MLASettings::mla_render_settings_page' );
405
  add_action( 'load-' . self::$current_page_hook, 'MLASettings::mla_add_menu_options_action' );
406
  add_action( 'load-' . self::$current_page_hook, 'MLASettings::mla_add_help_tab_action' );
449
 
450
  add_screen_option( $option, $args );
451
  } // upload
452
+ elseif ( 'shortcodes' == $_REQUEST['mla_tab'] ) {
453
+ $option = 'per_page';
454
+
455
+ $args = array(
456
+ 'label' => __( 'Shortcode templates per page', 'media-library-assistant' ),
457
+ 'default' => 10,
458
+ 'option' => 'mla_shortcode_templates_per_page'
459
+ );
460
+
461
+ add_screen_option( $option, $args );
462
+ } // upload
463
  elseif ( 'documentation' == $_REQUEST['mla_tab'] ) {
464
  if ( isset( $_REQUEST['mla-example-display'] ) || isset( $_REQUEST['mla-example-search'] ) ) {
465
  $option = 'per_page';
486
  public static function mla_add_help_tab_action( ) {
487
  $screen = get_current_screen();
488
 
489
+ // Do we have options/help information for this tab?
490
+ $screen_suffix = substr( $screen->id, strlen( 'settings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG ) ) ;
491
+ if ( ! in_array( $screen_suffix, array( '-view', '-upload', '-shortcodes', '-documentation' ) ) ) {
 
492
  return;
493
  }
494
 
503
  $file_suffix = str_replace( '-documentation', '-example', $file_suffix );
504
  } elseif ( isset( $_REQUEST['mla_admin_action'] ) ) {
505
  switch ( $_REQUEST['mla_admin_action'] ) {
506
+ case MLACore::MLA_ADMIN_SINGLE_EDIT_DISPLAY:
507
  $file_suffix .= '-edit';
508
  break;
509
  } // switch
539
  );
540
  } else {
541
  /* translators: 1: ERROR tag 2: function name 3: template key */
542
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: %2$s discarding "%3$s"; no title/order', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'mla_add_help_tab_action', $id ), MLACore::MLA_DEBUG_CATEGORY_ANY );
543
  }
544
  }
545
 
581
  * @return string|void New value if this is our option, otherwise nothing
582
  */
583
  public static function mla_set_screen_option_filter( $status, $option, $value ) {
584
+ if ( in_array( $option, array ( 'mla_views_per_page', 'mla_uploads_per_page', 'mla_types_per_page', 'mla_shortcode_templates_per_page', 'mla_example_plugins_per_page' ) ) ) {
585
  return $value;
586
  } elseif ( $status ) {
587
  return $status;
588
  }
589
  }
590
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
591
  /**
592
  * Add the "Settings" link to the MLA entry in the Plugins section
593
  *
599
  * @return array Updated array of links for the Plugin
600
  */
601
  public static function mla_add_plugin_settings_link_filter( $links, $file ) {
602
+ if ( $file == 'media-library-assistant/index.php' && current_user_can( 'manage_options' ) ) {
603
  $settings_link = sprintf( '<a href="%s">%s</a>', admin_url( 'options-general.php?page=' . MLACoreOptions::MLA_SETTINGS_SLUG . '-general' ), __( 'Settings', 'media-library-assistant' ) );
604
  array_unshift( $links, $settings_link );
605
  }
672
  break;
673
  default:
674
  /* translators: 1: ERROR tag 2: function name 3: option type, e.g., radio, select, text */
675
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: %2$s unknown type = "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), '_save_settings(1)', var_export( $value, true ) ), MLACore::MLA_DEBUG_CATEGORY_ANY );
676
  } // $value['type']
677
  } // isset $key
678
  else {
709
  break;
710
  default:
711
  /* translators: 1: ERROR tag 2: function name 3: option type, e.g., radio, select, text */
712
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: %2$s unknown type = "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), '_save_settings(2)', var_export( $value, true ) ), MLACore::MLA_DEBUG_CATEGORY_ANY );
713
  } // $value['type']
714
  } // ! isset $key
715
 
849
  break;
850
  default:
851
  /* translators: 1: ERROR tag 2: function name 3: option type, e.g., radio, select, text */
852
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: %2$s unknown type = "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'mla_render_settings_page', var_export( $value, true ) ), MLACore::MLA_DEBUG_CATEGORY_ANY );
853
  } //switch
854
 
855
  return '';
877
  * render => rendering function for tab messages and content. Usage:
878
  * $tab_content = ['render']( );
879
  *
880
+ * The array must be populated at runtime in MLASettings::_localize_tablist();
881
  * localization calls cannot be placed in the "public static" array definition itself.
882
  *
883
  * @since 0.80
896
  *
897
  * @return void
898
  */
899
+ private static function _localize_tablist() {
900
  self::$mla_tablist = array(
901
  'general' => array( 'title' => __ ( 'General', 'media-library-assistant' ), 'render' => array( 'MLASettings', '_compose_general_tab' ) ),
902
+ 'view' => array( 'title' => __ ( 'Views', 'media-library-assistant' ), 'render' => array( 'MLASettings_View', 'mla_compose_view_tab' ) ),
903
+ 'upload' => array( 'title' => __ ( 'Uploads', 'media-library-assistant' ), 'render' => array( 'MLASettings_Upload', 'mla_compose_upload_tab' ) ),
904
+ 'shortcodes' => array( 'title' => __ ( 'Shortcodes', 'media-library-assistant' ), 'render' => array( 'MLASettings_Shortcodes', 'mla_compose_shortcodes_tab' ) ),
905
+ 'custom_field' => array( 'title' => __ ( 'Custom Fields', 'media-library-assistant' ), 'render' => array( 'MLASettings_CustomFields', 'mla_compose_custom_field_tab' ) ),
906
+ 'iptc_exif' => array( 'title' => __ ( 'IPTC/EXIF', 'media-library-assistant' ), 'render' => array( 'MLASettings_IPTCEXIF', 'mla_compose_iptc_exif_tab' ) ),
907
+ 'documentation' => array( 'title' => __ ( 'Documentation', 'media-library-assistant' ), 'render' => array( 'MLASettings_Documentation', 'mla_compose_documentation_tab' ) ),
908
  'debug' => array( 'title' => __ ( 'Debug', 'media-library-assistant' ), 'render' => array( 'MLASettings', '_compose_debug_tab' ) ),
909
  );
910
  }
918
  *
919
  * @return array|false The entire tablist ( $tab = NULL ), a single tab entry or false if not found/not allowed
920
  */
921
+ private static function _get_options_tablist( $tab = NULL ) {
922
  if ( is_string( $tab ) ) {
923
  if ( isset( self::$mla_tablist[ $tab ] ) ) {
924
  $results = self::$mla_tablist[ $tab ];
953
  private static function _compose_settings_tabs( $active_tab = 'general' ) {
954
  $tablist_item = self::$page_template_array['tablist-item'];
955
  $tabs = '';
956
+ foreach ( self::_get_options_tablist() as $key => $item ) {
957
  $item_values = array(
958
  'data-tab-id' => $key,
959
  'nav-tab-active' => ( $active_tab == $key ) ? 'nav-tab-active' : '',
1126
  *
1127
  * @return string|false The action name or False if no action was selected
1128
  */
1129
+ public static function mla_current_bulk_action( ) {
1130
  $action = false;
1131
 
1132
  if ( isset( $_REQUEST['action'] ) ) {
1149
  }
1150
 
1151
  /**
1152
+ * Save Debug settings to the options table
1153
+ *
1154
+ * @since 2.10
1155
  *
1156
+ * @uses $_REQUEST
1157
  *
1158
+ * @return array Message(s) reflecting the results of the operation
 
 
 
1159
  */
1160
+ private static function _save_debug_settings( ) {
1161
+ $message_list = '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1162
 
1163
+ foreach ( MLACoreOptions::$mla_option_definitions as $key => $value ) {
1164
+ if ( 'debug' == $value['tab'] ) {
1165
+ $message_list .= self::mla_update_option_row( $key, $value );
1166
+ } // view option
1167
+ } // foreach mla_options
 
 
 
 
 
1168
 
1169
+ $page_content = array(
1170
+ 'message' => __( 'Debug settings saved.', 'media-library-assistant' ) . "\r\n",
1171
+ 'body' => ''
1172
  );
1173
+
1174
+ /*
1175
+ * Uncomment this for debugging.
1176
+ */
1177
+ // $page_content['message'] .= $message_list;
1178
+
1179
+ return $page_content;
1180
+ } // _save_debug_settings
1181
 
1182
  /**
1183
+ * Compose the Debug tab Debug Settings content for one setting
1184
  *
1185
+ * @since 2.14
1186
+ *
1187
+ * @param string $label Display name for the setting
1188
+ * @param string $value Current value for the setting
1189
+ *
1190
+ * @return string HTML table row markup for the label setting pair
1191
+ */
1192
+ private static function _compose_settings_row( $label, $value ) {
1193
+ $row = '<tr valign="top"><th scope="row" style="text-align:right;">' . "\n";
1194
+ $row .= $label . "\n";
1195
+ $row .= '</th><td style="text-align:left;">' . "\n";
1196
+ $row .= $value . "\n";
1197
+ $row .= '</td></tr>' . "\n";
1198
+
1199
+ return $row;
1200
+ } // _compose_settings_row
1201
+
1202
+ /**
1203
+ * Compose the Debug tab content for the Settings subpage
1204
+ *
1205
+ * @since 2.10
1206
+ * @uses $page_template_array contains tab content template(s)
1207
  *
1208
  * @return array 'message' => status/error messages, 'body' => tab content
1209
  */
1210
+ private static function _compose_debug_tab( ) {
1211
+ $page_content = array(
1212
+ 'message' => '',
1213
+ 'body' => ''
1214
+ );
 
 
1215
 
1216
+ $page_values = array();
 
 
 
 
 
 
1217
 
1218
  /*
1219
+ * Saving the options can change the log file name, so do it first
1220
  */
1221
+ if ( !empty( $_REQUEST['mla-debug-options-save'] ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1222
  check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
1223
+ $page_content = self::_save_debug_settings();
 
 
 
 
 
 
 
 
 
 
1224
  }
1225
 
1226
  /*
1227
+ * Find the appropriate error log file
1228
  */
1229
+ $error_log_name = MLACore::mla_get_option( MLACoreOptions::MLA_DEBUG_FILE );
1230
+ if ( empty( $error_log_name ) ) {
1231
+ $error_log_name = ini_get( 'error_log' );
1232
+ } else {
1233
+ $first = substr( $error_log_name, 0, 1 );
1234
+ if ( ( '/' != $first ) && ( '\\' != $first ) ) {
1235
+ $error_log_name = '/' . $error_log_name;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1236
  }
1237
+
1238
+ $error_log_name = WP_CONTENT_DIR . $error_log_name;
1239
+ }
1240
+
1241
+ $error_log_exists = file_exists ( $error_log_name );
1242
 
1243
  /*
1244
+ * Check for other page-level actions
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1245
  */
1246
  if ( isset( $_REQUEST['mla_reset_log'] ) && 'true' == $_REQUEST['mla_reset_log'] ) {
1247
  $file_error = false;
1358
  $settings_list .= self::_compose_settings_row( 'MLA Reporting', $mla_reporting );
1359
  $settings_list .= self::_compose_settings_row( 'MLA_DEBUG_LEVEL', sprintf( '0x%1$04X', MLA_DEBUG_LEVEL ) );
1360
  $settings_list .= self::_compose_settings_row( 'PHP error_reporting', MLACore::$original_php_reporting );
1361
+ $settings_list .= self::_compose_settings_row( 'Old PHP error_log', MLACore::$original_php_log );
1362
+ $settings_list .= self::_compose_settings_row( 'New PHP error_log', ini_get( 'error_log' ) );
1363
+ $settings_list .= self::_compose_settings_row( 'WP_DEBUG', WP_DEBUG ? 'true' : 'false' );
1364
+ $settings_list .= self::_compose_settings_row( 'WP_DEBUG_LOG', WP_DEBUG_LOG ? 'true' : 'false' );
1365
+ $settings_list .= self::_compose_settings_row( 'WP_DEBUG_DISPLAY', WP_DEBUG_DISPLAY ? 'true' : 'false' );
1366
+ $settings_list .= self::_compose_settings_row( 'WP_CONTENT_DIR', WP_CONTENT_DIR );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1367
 
1368
  /*
1369
+ * Compose tab content
1370
  */
1371
+ $page_values = array (
1372
+ 'Debug Options' => __( 'Debug Options', 'media-library-assistant' ),
1373
+ 'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-debug&mla_tab=debug',
1374
+ 'options_list' => $options_list,
1375
+ 'Debug Settings' => __( 'Debug Settings', 'media-library-assistant' ),
1376
+ 'settings_list' => $settings_list,
1377
+ 'Error Log' => __( 'Error Log', 'media-library-assistant' ),
1378
+ 'Error Log Name' => $error_log_name,
1379
+ 'Error Log Size' => number_format( (float) $error_log_size ),
1380
+ 'error_log_text' => $error_log_contents,
1381
+ 'download_link' => $download_link,
1382
+ 'reset_link' => $reset_link,
1383
+ 'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
1384
+ /* translators: 1: "Save Changes" */
1385
+ 'Click Save Changes' => sprintf( __( 'Click %1$s to update the %2$s.', 'media-library-assistant' ), '<strong>' . __( 'Save Changes', 'media-library-assistant' ) . '</strong>', __( 'Debug Options', 'media-library-assistant' ) ),
1386
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
1387
+ '_wp_http_referer' => wp_referer_field( false )
1388
+ );
1389
 
1390
+ $page_content['body'] = MLAData::mla_parse_template( self::$page_template_array['debug-tab'], $page_values );
1391
  return $page_content;
1392
+ }
1393
 
1394
  /**
1395
+ * Render (echo) the "Media Library Assistant" subpage in the Settings section
 
 
1396
  *
1397
+ * @since 0.1
1398
  *
1399
+ * @return void Echoes HTML markup for the Settings subpage
1400
  */
1401
+ public static function mla_render_settings_page( ) {
1402
+ if ( !current_user_can( 'manage_options' ) ) {
1403
+ echo __( 'Media Library Assistant', 'media-library-assistant' ) . ' - ' . __( 'ERROR', 'media-library-assistant' ) . "</h2>\r\n";
1404
+ wp_die( __( 'You do not have permission to manage plugin settings.', 'media-library-assistant' ) );
1405
+ }
 
 
 
 
 
 
1406
 
1407
+ /*
1408
+ * Load template array and initialize page-level values.
1409
+ */
1410
+ $development_version = MLA::MLA_DEVELOPMENT_VERSION;
1411
+ $development_version = ( ! empty( $development_version ) ) ? ' (' . $development_version . ')' : '';
1412
+ self::$page_template_array = MLACore::mla_load_template( 'admin-display-settings-page.tpl' );
1413
+ $current_tab_slug = isset( $_REQUEST['mla_tab'] ) ? $_REQUEST['mla_tab']: 'general';
1414
+ $current_tab = self::_get_options_tablist( $current_tab_slug );
1415
+ $page_values = array(
1416
+ 'Support Our Work' => __( 'Support Our Work', 'media-library-assistant' ),
1417
+ 'Donate' => __( 'Donate', 'media-library-assistant' ),
1418
+ 'version' => 'v' . MLACore::CURRENT_MLA_VERSION,
1419
+ 'development' => $development_version,
1420
+ 'messages' => '',
1421
+ 'tablist' => self::_compose_settings_tabs( $current_tab_slug ),
1422
+ 'tab_content' => '',
1423
+ 'Media Library Assistant' => __( 'Media Library Assistant', 'media-library-assistant' ),
1424
+ 'Settings' => __( 'Settings', 'media-library-assistant' )
1425
  );
1426
+ //error_log( __LINE__ . " mla_render_settings_page( {$current_tab_slug} ) REQUEST = " . var_export( $_REQUEST, true ), 0 );
1427
 
1428
  /*
1429
+ * Compose tab content
1430
  */
1431
+ if ( $current_tab ) {
1432
+ if ( isset( $current_tab['render'] ) ) {
1433
+ $handler = $current_tab['render'];
1434
+ $page_content = call_user_func( $handler );
1435
+ } else {
1436
+ $page_content = array( 'message' => __( 'ERROR', 'media-library-assistant' ) . ': ' . __( 'Cannot render content tab', 'media-library-assistant' ), 'body' => '' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1437
  }
1438
  } else {
1439
+ $page_content = array( 'message' => __( 'ERROR', 'media-library-assistant' ) . ': ' . __( 'Unknown content tab', 'media-library-assistant' ), 'body' => '' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1440
  }
1441
 
1442
+ if ( ! empty( $page_content['message'] ) ) {
1443
+ if ( false !== strpos( $page_content['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
1444
+ $messages_class = 'mla_errors';
1445
+ } else {
1446
+ $messages_class = 'mla_messages';
 
 
 
 
 
 
 
 
1447
  }
 
 
1448
 
1449
+ $page_values['messages'] = MLAData::mla_parse_template( self::$page_template_array['messages'], array(
1450
+ 'messages' => $page_content['message'],
1451
+ 'mla_messages_class' => $messages_class
1452
+ ) );
 
 
1453
  }
1454
 
1455
+ $page_values['tab_content'] = $page_content['body'];
1456
+ echo MLAData::mla_parse_template( self::$page_template_array['page'], $page_values );
1457
+ } // mla_render_settings_page
 
 
 
 
 
1458
 
1459
  /**
1460
  * Delete a custom field from the wp_postmeta table
1465
  *
1466
  * @return array Message(s) reflecting the results of the operation
1467
  */
1468
+ public static function mla_delete_custom_field( $value ) {
1469
  global $wpdb;
1470
 
1471
  $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->postmeta} LEFT JOIN {$wpdb->posts} ON ( {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id ) WHERE {$wpdb->postmeta}.meta_key = '%s' AND {$wpdb->posts}.post_type = 'attachment'", $value['name'] ));
1481
  }
1482
 
1483
  return __( 'No attachments contained this custom field.', 'media-library-assistant' ) . '<br>';
1484
+ } // mla_delete_custom_field
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1485
 
1486
  /**
1487
  * Save General settings to the options table
1751
  if (false === @fwrite($file_handle, $settings)) {
1752
  $error_info = error_get_last();
1753
  /* translators: 1: ERROR tag 2: PHP error information */
1754
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: _export_settings $error_info = "%2$s".', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), var_export( $error_info, true ) ), MLACore::MLA_DEBUG_CATEGORY_ANY );
1755
 
1756
  if ( false !== ( $tail = strpos( $error_info['message'], '</a>]: ' ) ) ) {
1757
  $php_errormsg = ':<br>' . substr( $error_info['message'], $tail + 7 );
1805
  if ( false === $settings ) {
1806
  $error_info = error_get_last();
1807
  /* translators: 1: ERROR tag 2: PHP error information */
1808
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: _import_settings $error_info = "%2$s".', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), var_export( $error_info, true ) ), MLACore::MLA_DEBUG_CATEGORY_ANY );
1809
 
1810
  if ( false !== ( $tail = strpos( $error_info['message'], '</a>]: ' ) ) ) {
1811
  $php_errormsg = ':<br>' . substr( $error_info['message'], $tail + 7 );
includes/class-mla-shortcode-support.php CHANGED
@@ -40,7 +40,8 @@ class MLAShortcode_Support {
40
  *
41
  * @param string Non-standard location to override default search, e.g.,
42
  * 'C:\Program Files (x86)\gs\gs9.15\bin\gswin32c.exe'
43
- * @param boolean Force ghostscript-only tests, used by MLASettings::_compose_mla_gallery_tab()
 
44
  *
45
  * @return boolean true if Ghostscript available else false
46
  */
@@ -82,11 +83,6 @@ class MLAShortcode_Support {
82
  /*
83
  * Look for exec() - from http://stackoverflow.com/a/12980534/866618
84
  */
85
- if ( ini_get('safe_mode') ) {
86
- MLACore::mla_debug_add( '<strong>MLAShortcode_Support::mla_ghostscript_present</strong>, safe_mode', $mla_debug_category );
87
- return $ghostscript_present = false;
88
- }
89
-
90
  $blacklist = preg_split( '/,\s*/', ini_get('disable_functions') . ',' . ini_get('suhosin.executor.func.blacklist') );
91
  if ( in_array('exec', $blacklist) ) {
92
  MLACore::mla_debug_add( '<strong>MLAShortcode_Support::mla_ghostscript_present</strong>, exec in blacklist', $mla_debug_category );
@@ -159,7 +155,7 @@ class MLAShortcode_Support {
159
  * @since 2.20
160
  *
161
  * @param mixed $attr Array or string containing shortcode attributes
162
- * @param string $content Optional content for enclosing shortcodes; might be used with mla_alt_shortcode
163
  *
164
  * @return array clean attributes array
165
  */
@@ -239,6 +235,38 @@ class MLAShortcode_Support {
239
  */
240
  private static $mla_debug = false;
241
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
  /**
243
  * The MLA Gallery shortcode.
244
  *
@@ -249,7 +277,7 @@ class MLAShortcode_Support {
249
  * @since 2.20
250
  *
251
  * @param array $attr Attributes of the shortcode
252
- * @param string $content Optional content for enclosing shortcodes; used with mla_alt_shortcode
253
  *
254
  * @return string HTML content to display gallery.
255
  */
@@ -260,21 +288,40 @@ class MLAShortcode_Support {
260
  * Some do_shortcode callers may not have a specific post in mind
261
  */
262
  if ( ! is_object( $post ) ) {
263
- $post = (object) array(
264
- 'ID' => 0,
265
- 'post_author' => '0',
266
- 'post_date' => '',
267
- 'post_content' => '',
268
- 'post_title' => '',
269
- 'post_excerpt' => '',
270
- 'post_status' => '',
271
- 'post_name' => '',
272
- 'post_modified' => '',
273
- 'guid' => '',
274
- 'post_type' => '',
275
- );
276
  }
277
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
278
  /*
279
  * Make sure $attr is an array, even if it's empty,
280
  * and repair damage caused by link-breaks in the source text
@@ -294,8 +341,11 @@ class MLAShortcode_Support {
294
  if ( ! isset( $attr['mla_page_parameter'] ) ) {
295
  $attr['mla_page_parameter'] = self::$mla_get_shortcode_attachments_parameters['mla_page_parameter'];
296
  }
297
- $mla_page_parameter = $attr['mla_page_parameter'];
298
-
 
 
 
299
  /*
300
  * Special handling of the mla_paginate_current parameter to make
301
  * "MLA pagination" easier. Look for this parameter in $_REQUEST
@@ -391,41 +441,14 @@ class MLAShortcode_Support {
391
  $mla_arguments
392
  );
393
 
394
- // $instance supports multiple galleries in one page/post
395
- static $instance = 0;
396
- $instance++;
397
-
398
- /*
399
- * Some values are already known, and can be used in data selection parameters
400
- */
401
- $upload_dir = wp_upload_dir();
402
- $page_values = array(
403
- 'instance' => $instance,
404
- 'selector' => "mla_gallery-{$instance}",
405
- 'site_url' => site_url(),
406
- 'base_url' => $upload_dir['baseurl'],
407
- 'base_dir' => $upload_dir['basedir'],
408
- 'id' => $post->ID,
409
- 'page_ID' => $post->ID,
410
- 'page_author' => $post->post_author,
411
- 'page_date' => $post->post_date,
412
- 'page_content' => $post->post_content,
413
- 'page_title' => $post->post_title,
414
- 'page_excerpt' => $post->post_excerpt,
415
- 'page_status' => $post->post_status,
416
- 'page_name' => $post->post_name,
417
- 'page_modified' => $post->post_modified,
418
- 'page_parent' => $post->post_parent,
419
- 'page_guid' => $post->guid,
420
- 'page_type' => $post->post_type,
421
- 'page_mime_type' => $post->post_mime_type,
422
- 'page_url' => get_page_link(),
423
- );
424
-
425
  /*
426
  * Apply default arguments set in the markup template
427
  */
428
- $template = isset( $attr['mla_markup'] ) ? $attr['mla_markup'] : $mla_arguments['mla_markup'];
 
 
 
 
429
  $arguments = MLATemplate_Support::mla_fetch_custom_template( $template, 'gallery', 'markup', 'arguments' );
430
  if ( !empty( $arguments ) ) {
431
  $attr = wp_parse_args( $attr, self::_validate_attributes( array(), $arguments ) );
@@ -458,10 +481,25 @@ class MLAShortcode_Support {
458
  $arguments = shortcode_atts( $default_arguments, $attr );
459
  $arguments = apply_filters( 'mla_gallery_arguments', $arguments );
460
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
461
  /*
462
  * Look for "no effect" alternate gallery shortcode to support plugins such as Justified Image Grid
463
  */
464
- if ( is_string( $arguments['mla_alt_shortcode'] ) && ( 'mla_gallery' == $arguments['mla_alt_shortcode'] ) ) {
465
  $arguments['mla_alt_shortcode'] = NULL;
466
  $arguments['mla_alt_ids_name'] = 'ids';
467
  $arguments['mla_alt_ids_value'] = NULL;
@@ -492,7 +530,7 @@ class MLAShortcode_Support {
492
  if ( $is_pagination && ( NULL !== $arguments['mla_paginate_rows'] ) ) {
493
  $attachments['found_rows'] = absint( $arguments['mla_paginate_rows'] );
494
  } else {
495
- $attachments = self::mla_get_shortcode_attachments( $post->ID, $attr, true ); // $is_pagination );
496
  }
497
 
498
  if ( is_string( $attachments ) ) {
@@ -536,14 +574,16 @@ class MLAShortcode_Support {
536
  /*
537
  * Replace data-selection parameters with the "ids" list
538
  */
539
- if ( 'mla_tag_cloud' == $arguments['mla_alt_shortcode'] ) {
540
- $blacklist = self::$mla_get_shortcode_attachments_parameters;
541
- } else {
542
- $blacklist = array_merge( $mla_arguments, self::$mla_get_shortcode_attachments_parameters );
543
  }
 
 
 
544
 
545
  $mla_alt_shortcode_args = '';
546
- foreach ( $attr as $key => $value ) {
547
  if ( array_key_exists( $key, $blacklist ) ) {
548
  continue;
549
  }
@@ -558,16 +598,23 @@ class MLAShortcode_Support {
558
 
559
  /*
560
  * If an alternate value has been specified we must delay alt shortcode execution
 
561
  */
562
  $mla_alt_ids_value = is_null( $arguments['mla_alt_ids_value'] ) ? NULL : str_replace( '{+', '[+', str_replace( '+}', '+]', $arguments['mla_alt_ids_value'] ) );
563
  $mla_alt_shortcode_ids = array();
564
 
565
  if ( is_null( $mla_alt_ids_value ) ) {
566
- foreach ( $attachments as $value ) {
567
- $mla_alt_shortcode_ids[] = $value->ID;
568
- } // foreach $attachments
569
-
570
- $mla_alt_shortcode_ids = $arguments['mla_alt_ids_name'] . '="' . implode( ',', $mla_alt_shortcode_ids ) . '"';
 
 
 
 
 
 
571
 
572
  if ( self::$mla_debug ) {
573
  $output = MLACore::mla_debug_flush();
@@ -580,10 +627,13 @@ class MLAShortcode_Support {
580
  */
581
  $content = apply_filters( 'mla_gallery_final_content', $content );
582
  if ( ! empty( $content ) ) {
583
- return $output . do_shortcode( sprintf( '[%1$s %2$s %3$s]%4$s[/%5$s]', $arguments['mla_alt_shortcode'], $mla_alt_shortcode_ids, $mla_alt_shortcode_args, $content, $arguments['mla_alt_shortcode'] ) );
584
  } else {
585
- return $output . do_shortcode( sprintf( '[%1$s %2$s %3$s]', $arguments['mla_alt_shortcode'], $mla_alt_shortcode_ids, $mla_alt_shortcode_args ) );
586
  }
 
 
 
587
  } // is_null( $mla_alt_ids_value )
588
  } // mla_alt_shortcode
589
 
@@ -741,12 +791,8 @@ class MLAShortcode_Support {
741
  if ( apply_filters( 'use_mla_gallery_style', $use_mla_gallery_style, $style_values['mla_style'] ) ) {
742
  $style_template = MLATemplate_support::mla_fetch_custom_template( $style_values['mla_style'], 'gallery', 'style' );
743
  if ( empty( $style_template ) ) {
744
- $style_values['mla_style'] = $default_arguments['mla_style'];
745
- $style_template = MLATemplate_support::mla_fetch_custom_template( $style_values['mla_style'], 'gallery', 'style' );
746
- if ( empty( $style_template ) ) {
747
- $style_values['mla_style'] = 'default';
748
- $style_template = MLATemplate_support::mla_fetch_custom_template( 'default', 'gallery', 'style' );
749
- }
750
  }
751
 
752
  if ( ! empty ( $style_template ) ) {
@@ -785,14 +831,6 @@ class MLAShortcode_Support {
785
  $markup_values = $style_values;
786
 
787
  $open_template = MLATemplate_support::mla_fetch_custom_template( $markup_values['mla_markup'], 'gallery', 'markup', 'open' );
788
- if ( false === $open_template ) {
789
- $markup_values['mla_markup'] = $default_arguments['mla_markup'];
790
- $open_template = MLATemplate_support::mla_fetch_custom_template( $markup_values['mla_markup'], 'gallery', 'markup', 'open' );
791
- if ( false === $open_template ) {
792
- $markup_values['mla_markup'] = 'default';
793
- $open_template = MLATemplate_support::mla_fetch_custom_template( $markup_values['mla_markup'], 'gallery', 'markup', 'open' );
794
- }
795
- }
796
  if ( empty( $open_template ) ) {
797
  $open_template = '';
798
  }
@@ -1581,7 +1619,7 @@ class MLAShortcode_Support {
1581
  $mla_alt_shortcode_ids = $arguments['mla_alt_ids_name'] . '="' . implode( ',', $mla_alt_shortcode_ids ) . '"';
1582
  $content = apply_filters( 'mla_gallery_final_content', $content );
1583
  if ( ! empty( $content ) ) {
1584
- return $output . do_shortcode( sprintf( '[%1$s %2$s %3$s]%4$s[/%5$s]', $arguments['mla_alt_shortcode'], $mla_alt_shortcode_ids, $mla_alt_shortcode_args, $content, $arguments['mla_alt_shortcode'] ) );
1585
  } else {
1586
  return $output . do_shortcode( sprintf( '[%1$s %2$s %3$s]', $arguments['mla_alt_shortcode'], $mla_alt_shortcode_ids, $mla_alt_shortcode_args ) );
1587
  }
@@ -1626,21 +1664,38 @@ class MLAShortcode_Support {
1626
  * Some do_shortcode callers may not have a specific post in mind
1627
  */
1628
  if ( ! is_object( $post ) ) {
1629
- $post = (object) array(
1630
- 'ID' => 0,
1631
- 'post_author' => '0',
1632
- 'post_date' => '',
1633
- 'post_content' => '',
1634
- 'post_title' => '',
1635
- 'post_excerpt' => '',
1636
- 'post_status' => '',
1637
- 'post_name' => '',
1638
- 'post_modified' => '',
1639
- 'guid' => '',
1640
- 'post_type' => '',
1641
- );
1642
  }
1643
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1644
  /*
1645
  * These are the default parameters for tag cloud display
1646
  */
@@ -1711,7 +1766,9 @@ class MLAShortcode_Support {
1711
  $attr['mla_page_parameter'] = $defaults['mla_page_parameter'];
1712
  }
1713
 
1714
- $mla_page_parameter = $attr['mla_page_parameter'];
 
 
1715
 
1716
  /*
1717
  * Special handling of mla_page_parameter to make
@@ -1724,44 +1781,26 @@ class MLAShortcode_Support {
1724
  }
1725
  }
1726
 
1727
- // $instance supports multiple clouds in one page/post
1728
- static $instance = 0;
1729
- $instance++;
1730
-
1731
- /*
1732
- * Some values are already known, and can be used in data selection parameters
1733
- */
1734
- $upload_dir = wp_upload_dir();
1735
- $page_values = array(
1736
- 'instance' => $instance,
1737
- 'selector' => "mla_tag_cloud-{$instance}",
1738
- 'site_url' => site_url(),
1739
- 'base_url' => $upload_dir['baseurl'],
1740
- 'base_dir' => $upload_dir['basedir'],
1741
- 'id' => $post->ID,
1742
- 'page_ID' => $post->ID,
1743
- 'page_author' => $post->post_author,
1744
- 'page_date' => $post->post_date,
1745
- 'page_content' => $post->post_content,
1746
- 'page_title' => $post->post_title,
1747
- 'page_excerpt' => $post->post_excerpt,
1748
- 'page_status' => $post->post_status,
1749
- 'page_name' => $post->post_name,
1750
- 'page_modified' => $post->post_modified,
1751
- 'page_guid' => $post->guid,
1752
- 'page_type' => $post->post_type,
1753
- 'page_url' => get_page_link(),
1754
- );
1755
-
1756
  /*
1757
  * Determine markup template to get default arguments
1758
  */
1759
  $arguments = shortcode_atts( $defaults, $attr );
1760
  if ( $arguments['mla_markup'] ) {
1761
  $template = $arguments['mla_markup'];
 
 
 
1762
  } else {
 
 
 
 
1763
  $output_parameters = array_map( 'strtolower', array_map( 'trim', explode( ',', $arguments['mla_output'] ) ) );
1764
 
 
 
 
 
1765
  if ( 'grid' == $output_parameters[0] ) {
1766
  $template = MLACore::mla_get_option('default_tag_cloud_markup');
1767
  } elseif ( in_array( $output_parameters[0], array( 'list', 'ulist', 'olist', 'dlist' ) ) ) {
@@ -1852,10 +1891,28 @@ class MLAShortcode_Support {
1852
  }
1853
 
1854
  /*
1855
- * Determine output type and templates
1856
  */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1857
  $output_parameters = array_map( 'strtolower', array_map( 'trim', explode( ',', $arguments['mla_output'] ) ) );
1858
 
 
 
 
 
1859
  if ( $is_grid = 'grid' == $output_parameters[0] ) {
1860
  $default_style = MLACore::mla_get_option('default_tag_cloud_style');
1861
  $default_markup = MLACore::mla_get_option('default_tag_cloud_markup');
@@ -2309,6 +2366,13 @@ class MLAShortcode_Support {
2309
  */
2310
  $tag_links = array();
2311
 
 
 
 
 
 
 
 
2312
  $column_index = 0;
2313
  foreach ( $tags as $key => $tag ) {
2314
  $item_values = $markup_values;
@@ -2336,7 +2400,7 @@ class MLAShortcode_Support {
2336
  $item_values['scaled_count'] = $tag->scaled_count;
2337
  $item_values['font_size'] = str_replace( ',', '.', ( $item_values['smallest'] + ( ( $item_values['scaled_count'] - $item_values['min_scaled_count'] ) * $item_values['font_step'] ) ) );
2338
  $item_values['link_url'] = $tag->link;
2339
- $item_values['currentlink_url'] = sprintf( '%1$s?current_item=%2$d', $item_values['page_url'], $item_values['term_id'] );
2340
  $item_values['editlink_url'] = $tag->edit_link;
2341
  $item_values['termlink_url'] = $tag->term_link;
2342
  // Added in the code below:
@@ -2431,7 +2495,7 @@ class MLAShortcode_Support {
2431
  /*
2432
  * Currentlink, editlink, termlink and thelink
2433
  */
2434
- $item_values['currentlink'] = sprintf( '<a %1$shref="%2$s?current_item=%3$d" title="%4$s" style="%5$s">%6$s</a>', $link_attributes, $item_values['page_url'], $item_values['term_id'], $item_values['rollover_text'], $item_values['link_style'], $item_values['link_text'] );
2435
  $item_values['editlink'] = sprintf( '<a %1$shref="%2$s" title="%3$s" style="%4$s">%5$s</a>', $link_attributes, $item_values['editlink_url'], $item_values['rollover_text'], $item_values['link_style'], $item_values['link_text'] );
2436
  $item_values['termlink'] = sprintf( '<a %1$shref="%2$s" title="%3$s" style="%4$s">%5$s</a>', $link_attributes, $item_values['termlink_url'], $item_values['rollover_text'], $item_values['link_style'], $item_values['link_text'] );
2437
 
@@ -2592,6 +2656,10 @@ class MLAShortcode_Support {
2592
  */
2593
  $output_parameters = array_map( 'strtolower', array_map( 'trim', explode( ',', $arguments['mla_output'] ) ) );
2594
 
 
 
 
 
2595
  $is_list = in_array( $output_parameters[0], array( 'list', 'ulist', 'olist', 'dlist' ) );
2596
  $is_dropdown = 'dropdown' == $output_parameters[0];
2597
  $is_checklist = 'checklist' == $output_parameters[0];
@@ -2676,6 +2744,13 @@ class MLAShortcode_Support {
2676
  }
2677
  } // is_list
2678
 
 
 
 
 
 
 
 
2679
  foreach ( $terms as $key => $term ) {
2680
  $item_values = $markup_values;
2681
 
@@ -2693,7 +2768,7 @@ class MLAShortcode_Support {
2693
  $item_values['parent'] = $term->parent;
2694
  $item_values['count'] = isset ( $term->count ) ? 0 + $term->count : 0;
2695
  $item_values['link_url'] = $term->link;
2696
- $item_values['currentlink_url'] = sprintf( '%1$s?current_item=%2$d', $item_values['page_url'], $item_values['term_id'] );
2697
  $item_values['editlink_url'] = $term->edit_link;
2698
  $item_values['termlink_url'] = $term->term_link;
2699
  $item_values['children'] = '';
@@ -2794,7 +2869,7 @@ class MLAShortcode_Support {
2794
  /*
2795
  * Currentlink, editlink, termlink and thelink TODO - link style
2796
  */
2797
- $item_values['currentlink'] = sprintf( '<a %1$shref="%2$s?%3$s=%4$d" title="%5$s" style="%6$s">%7$s</a>', $link_attributes, $item_values['page_url'], $mla_item_parameter, $item_values['term_id'], $item_values['rollover_text'], '', $item_values['link_text'] );
2798
  $item_values['editlink'] = sprintf( '<a %1$shref="%2$s" title="%3$s" style="%4$s">%5$s</a>', $link_attributes, $item_values['editlink_url'], $item_values['rollover_text'], '', $item_values['link_text'] );
2799
  $item_values['termlink'] = sprintf( '<a %1$shref="%2$s" title="%3$s" style="%4$s">%5$s</a>', $link_attributes, $item_values['termlink_url'], $item_values['rollover_text'], '', $item_values['link_text'] );
2800
 
@@ -2929,21 +3004,38 @@ class MLAShortcode_Support {
2929
  * Some do_shortcode callers may not have a specific post in mind
2930
  */
2931
  if ( ! is_object( $post ) ) {
2932
- $post = (object) array(
2933
- 'ID' => 0,
2934
- 'post_author' => '0',
2935
- 'post_date' => '',
2936
- 'post_content' => '',
2937
- 'post_title' => '',
2938
- 'post_excerpt' => '',
2939
- 'post_status' => '',
2940
- 'post_name' => '',
2941
- 'post_modified' => '',
2942
- 'guid' => '',
2943
- 'post_type' => '',
2944
- );
2945
  }
2946
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2947
  $defaults = array_merge(
2948
  self::$mla_get_terms_parameters,
2949
  array(
@@ -2966,6 +3058,7 @@ class MLAShortcode_Support {
2966
  'itemtag' => 'ul',
2967
  'termtag' => 'li',
2968
  'captiontag' => '',
 
2969
 
2970
  'mla_nolink_text' => '',
2971
  'mla_target' => '',
@@ -2997,7 +3090,9 @@ class MLAShortcode_Support {
2997
  $attr['mla_item_parameter'] = $defaults['mla_item_parameter'];
2998
  }
2999
 
3000
- $mla_item_parameter = $attr['mla_item_parameter'];
 
 
3001
 
3002
  /*
3003
  * Special handling of mla_item_parameter to make
@@ -3010,35 +3105,6 @@ class MLAShortcode_Support {
3010
  }
3011
  }
3012
 
3013
- // $instance supports multiple lists in one page/post
3014
- static $instance = 0;
3015
- $instance++;
3016
-
3017
- /*
3018
- * Some values are already known, and can be used in data selection parameters
3019
- */
3020
- $upload_dir = wp_upload_dir();
3021
- $page_values = array(
3022
- 'instance' => $instance,
3023
- 'selector' => "mla_term_list-{$instance}",
3024
- 'site_url' => site_url(),
3025
- 'base_url' => $upload_dir['baseurl'],
3026
- 'base_dir' => $upload_dir['basedir'],
3027
- 'id' => $post->ID,
3028
- 'page_ID' => $post->ID,
3029
- 'page_author' => $post->post_author,
3030
- 'page_date' => $post->post_date,
3031
- 'page_content' => $post->post_content,
3032
- 'page_title' => $post->post_title,
3033
- 'page_excerpt' => $post->post_excerpt,
3034
- 'page_status' => $post->post_status,
3035
- 'page_name' => $post->post_name,
3036
- 'page_modified' => $post->post_modified,
3037
- 'page_guid' => $post->guid,
3038
- 'page_type' => $post->post_type,
3039
- 'page_url' => get_page_link(),
3040
- );
3041
-
3042
  /*
3043
  * Determine markup template to get default arguments
3044
  */
@@ -3059,9 +3125,20 @@ class MLAShortcode_Support {
3059
 
3060
  if ( $arguments['mla_markup'] ) {
3061
  $template = $arguments['mla_markup'];
 
 
 
3062
  } else {
 
 
 
 
3063
  $output_parameters = array_map( 'strtolower', array_map( 'trim', explode( ',', $arguments['mla_output'] ) ) );
3064
 
 
 
 
 
3065
  if ( in_array( $output_parameters[0], array( 'list', 'ulist', 'olist', 'dlist' ) ) ) {
3066
  if ( ( 'dlist' == $output_parameters[0] ) || ('list' == $output_parameters[0] && 'dd' == $arguments['captiontag'] ) ) {
3067
  $template = 'term-list-dl';
@@ -3157,10 +3234,28 @@ class MLAShortcode_Support {
3157
  }
3158
 
3159
  /*
3160
- * Determine output type and templates
3161
  */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3162
  $output_parameters = array_map( 'strtolower', array_map( 'trim', explode( ',', $arguments['mla_output'] ) ) );
3163
 
 
 
 
 
3164
  if ( $is_list = in_array( $output_parameters[0], array( 'list', 'ulist', 'olist', 'dlist' ) ) ) {
3165
  $default_style = 'term-list';
3166
 
@@ -3203,7 +3298,7 @@ class MLAShortcode_Support {
3203
  if ( $is_dropdown = 'dropdown' == $output_parameters[0] ) {
3204
  $default_style = 'term-list';
3205
  $default_markup = 'term-list-dropdown';
3206
- $arguments['itemtag'] = 'select';
3207
  $arguments['termtag'] = 'option';
3208
 
3209
  if ( NULL == $arguments['mla_style'] ) {
@@ -3229,6 +3324,8 @@ class MLAShortcode_Support {
3229
  }
3230
  }
3231
 
 
 
3232
  $is_hierarchical = !empty( $arguments['hierarchical'] ) && ( 'true' == strtolower( $arguments['hierarchical'] ) );
3233
 
3234
  /*
@@ -3444,6 +3541,7 @@ class MLAShortcode_Support {
3444
  'itemtag' => tag_escape( $arguments['itemtag'] ),
3445
  'termtag' => tag_escape( $arguments['termtag'] ),
3446
  'captiontag' => tag_escape( $arguments['captiontag'] ),
 
3447
  'itemtag_attributes' => '',
3448
  'itemtag_class' => 'term-list term-list-taxonomy-' . implode( '-', $arguments['taxonomy'] ),
3449
  'itemtag_id' => $page_values['selector'],
@@ -4205,6 +4303,22 @@ class MLAShortcode_Support {
4205
  'update_post_term_cache' => NULL,
4206
  );
4207
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4208
  /**
4209
  * Parses shortcode parameters and returns the gallery objects
4210
  *
@@ -4246,6 +4360,20 @@ class MLAShortcode_Support {
4246
  if ( isset( $attr['where_used_query'] ) && ( 'this-is-a-where-used-query' == $attr['where_used_query'] ) ) {
4247
  $where_used_query = true;
4248
  unset( $attr['where_used_query'] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4249
  } else {
4250
  $where_used_query = false;
4251
  }
@@ -4293,6 +4421,7 @@ class MLAShortcode_Support {
4293
  /*
4294
  * Extract taxonomy arguments
4295
  */
 
4296
  $query_arguments = array();
4297
  if ( ! empty( $attr ) ) {
4298
  $all_taxonomies = get_taxonomies( array ( 'show_ui' => true ), 'names' );
@@ -4301,6 +4430,7 @@ class MLAShortcode_Support {
4301
  if ( 'tax_query' == $key ) {
4302
  if ( is_array( $value ) ) {
4303
  $query_arguments[ $key ] = $value;
 
4304
  } else {
4305
  $tax_query = NULL;
4306
  $value = self::_sanitize_query_specification( $value );
@@ -4319,6 +4449,7 @@ class MLAShortcode_Support {
4319
 
4320
  if ( is_array( $tax_query ) ) {
4321
  $query_arguments[ $key ] = $tax_query;
 
4322
  break; // Done - the tax_query overrides all other taxonomy parameters
4323
  } else {
4324
  return '<p>' . __( 'ERROR', 'media-library-assistant' ) . ': ' . __( 'Invalid mla_gallery', 'media-library-assistant' ) . ' tax_query = ' . var_export( $value, true ) . '</p>';
@@ -4364,7 +4495,7 @@ class MLAShortcode_Support {
4364
 
4365
  $tax_include_children = true;
4366
  if ( isset( $attr['tax_include_children'] ) ) {
4367
- if ( 'FALSE' == strtoupper( $attr['tax_include_children'] ) ) {
4368
  $tax_include_children = false;
4369
  }
4370
  }
@@ -4374,16 +4505,31 @@ class MLAShortcode_Support {
4374
  }
4375
 
4376
  $query_arguments['tax_query'] = $tax_query;
 
4377
  } else {
4378
  // exactly one simple query is present
4379
  if ( isset( $simple_tax_queries['category'] ) ) {
4380
  $arguments['category_name'] = $simple_tax_queries['category'];
4381
  } else {
4382
  $query_arguments = $simple_tax_queries;
 
4383
  }
4384
  }
4385
  } // ! empty
4386
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4387
  /*
4388
  * $query_arguments has been initialized in the taxonomy code above.
4389
  */
@@ -4415,6 +4561,12 @@ class MLAShortcode_Support {
4415
  $value = NULL;
4416
  $use_children = false;
4417
  break;
 
 
 
 
 
 
4418
  }
4419
  // fallthru
4420
  case 'id':
@@ -4711,7 +4863,7 @@ class MLAShortcode_Support {
4711
  // ignore anything else
4712
  } // switch $key
4713
  } // foreach $arguments
4714
-
4715
  /*
4716
  * Decide whether to use a "get_children" style query
4717
  */
@@ -4731,6 +4883,20 @@ class MLAShortcode_Support {
4731
  }
4732
  unset( $query_arguments['numberposts'] );
4733
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4734
  /*
4735
  * MLA pagination will override WordPress pagination
4736
  */
@@ -4933,11 +5099,16 @@ class MLAShortcode_Support {
4933
  $return_found_rows = false;
4934
  } else {
4935
  do_action( 'mla_gallery_wp_query_object', $query_arguments );
4936
- }
4937
 
4938
- if ( $return_found_rows ) {
4939
- $attachments['found_rows'] = absint( MLAShortcodes::$mla_gallery_wp_query_object->found_posts );
4940
- $attachments['max_num_pages'] = absint( MLAShortcodes::$mla_gallery_wp_query_object->max_num_pages );
 
 
 
 
 
 
4941
  }
4942
 
4943
  if ( ! empty( MLAQuery::$search_parameters ) ) {
@@ -5037,13 +5208,18 @@ class MLAShortcode_Support {
5037
  }
5038
 
5039
  if ( isset( self::$query_parameters['post_parent'] ) ) {
5040
- switch ( self::$query_parameters['post_parent'] ) {
5041
- case 'any':
5042
- $where_clause .= " AND {$table_prefix}posts.post_parent > 0";
5043
- break;
5044
- case 'none':
5045
- $where_clause .= " AND {$table_prefix}posts.post_parent < 1";
5046
- break;
 
 
 
 
 
5047
  }
5048
  }
5049
 
40
  *
41
  * @param string Non-standard location to override default search, e.g.,
42
  * 'C:\Program Files (x86)\gs\gs9.15\bin\gswin32c.exe'
43
+ * @param boolean Force ghostscript-only tests, used by
44
+ * MLASettings_Shortcodes::mla_compose_shortcodes_tab()
45
  *
46
  * @return boolean true if Ghostscript available else false
47
  */
83
  /*
84
  * Look for exec() - from http://stackoverflow.com/a/12980534/866618
85
  */
 
 
 
 
 
86
  $blacklist = preg_split( '/,\s*/', ini_get('disable_functions') . ',' . ini_get('suhosin.executor.func.blacklist') );
87
  if ( in_array('exec', $blacklist) ) {
88
  MLACore::mla_debug_add( '<strong>MLAShortcode_Support::mla_ghostscript_present</strong>, exec in blacklist', $mla_debug_category );
155
  * @since 2.20
156
  *
157
  * @param mixed $attr Array or string containing shortcode attributes
158
+ * @param string $content Optional content for enclosing shortcodes
159
  *
160
  * @return array clean attributes array
161
  */
235
  */
236
  private static $mla_debug = false;
237
 
238
+ /**
239
+ * Default values when global $post is not set
240
+ *
241
+ * @since 2.40
242
+ *
243
+ * @var array
244
+ */
245
+ private static $empty_post = array(
246
+ 'ID' => 0,
247
+ 'post_author' => 0,
248
+ 'post_date' => '0000-00-00 00:00:00',
249
+ 'post_date_gmt' => '0000-00-00 00:00:00',
250
+ 'post_content' => '',
251
+ 'post_title' => '',
252
+ 'post_excerpt' => '',
253
+ 'post_status' => 'publish',
254
+ 'comment_status' => 'open',
255
+ 'ping_status' => 'open',
256
+ 'post_name' => '',
257
+ 'to_ping' => 'None',
258
+ 'pinged' => 'None',
259
+ 'post_modified' => '0000-00-00 00:00:00',
260
+ 'post_modified_gmt' => '0000-00-00 00:00:00',
261
+ 'post_content_filtered' => 'None',
262
+ 'post_parent' => 0,
263
+ 'guid' => '',
264
+ 'menu_order' => 0,
265
+ 'post_type' => 'post',
266
+ 'post_mime_type' => '',
267
+ 'comment_count' => 0,
268
+ );
269
+
270
  /**
271
  * The MLA Gallery shortcode.
272
  *
277
  * @since 2.20
278
  *
279
  * @param array $attr Attributes of the shortcode
280
+ * @param string $content Optional content for enclosing shortcodes
281
  *
282
  * @return string HTML content to display gallery.
283
  */
288
  * Some do_shortcode callers may not have a specific post in mind
289
  */
290
  if ( ! is_object( $post ) ) {
291
+ $post = (object) self::$empty_post;
 
 
 
 
 
 
 
 
 
 
 
 
292
  }
293
 
294
+ // $instance supports multiple galleries in one page/post
295
+ static $instance = 0;
296
+ $instance++;
297
+
298
+ /*
299
+ * Some values are already known, and can be used in data selection parameters
300
+ */
301
+ $upload_dir = wp_upload_dir();
302
+ $page_values = array(
303
+ 'instance' => $instance,
304
+ 'selector' => "mla_gallery-{$instance}",
305
+ 'site_url' => site_url(),
306
+ 'base_url' => $upload_dir['baseurl'],
307
+ 'base_dir' => $upload_dir['basedir'],
308
+ 'id' => $post->ID,
309
+ 'page_ID' => $post->ID,
310
+ 'page_author' => $post->post_author,
311
+ 'page_date' => $post->post_date,
312
+ 'page_content' => $post->post_content,
313
+ 'page_title' => $post->post_title,
314
+ 'page_excerpt' => $post->post_excerpt,
315
+ 'page_status' => $post->post_status,
316
+ 'page_name' => $post->post_name,
317
+ 'page_modified' => $post->post_modified,
318
+ 'page_parent' => $post->post_parent,
319
+ 'page_guid' => $post->guid,
320
+ 'page_type' => $post->post_type,
321
+ 'page_mime_type' => $post->post_mime_type,
322
+ 'page_url' => get_page_link(),
323
+ );
324
+
325
  /*
326
  * Make sure $attr is an array, even if it's empty,
327
  * and repair damage caused by link-breaks in the source text
341
  if ( ! isset( $attr['mla_page_parameter'] ) ) {
342
  $attr['mla_page_parameter'] = self::$mla_get_shortcode_attachments_parameters['mla_page_parameter'];
343
  }
344
+
345
+ // The mla_page_parameter can contain page_level parameters like {+page_ID+}
346
+ $attr_value = str_replace( '{+', '[+', str_replace( '+}', '+]', $attr['mla_page_parameter'] ) );
347
+ $mla_page_parameter = MLAData::mla_parse_template( $attr_value, $page_values );
348
+
349
  /*
350
  * Special handling of the mla_paginate_current parameter to make
351
  * "MLA pagination" easier. Look for this parameter in $_REQUEST
441
  $mla_arguments
442
  );
443
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
444
  /*
445
  * Apply default arguments set in the markup template
446
  */
447
+ $template = $mla_arguments['mla_markup'];
448
+ if ( isset( $attr['mla_markup'] ) && MLATemplate_Support::mla_fetch_custom_template( $attr['mla_markup'], 'gallery', 'markup', '[exists]' ) ) {
449
+ $template = $attr['mla_markup'];
450
+ }
451
+
452
  $arguments = MLATemplate_Support::mla_fetch_custom_template( $template, 'gallery', 'markup', 'arguments' );
453
  if ( !empty( $arguments ) ) {
454
  $attr = wp_parse_args( $attr, self::_validate_attributes( array(), $arguments ) );
481
  $arguments = shortcode_atts( $default_arguments, $attr );
482
  $arguments = apply_filters( 'mla_gallery_arguments', $arguments );
483
 
484
+ /*
485
+ * Decide which templates to use
486
+ */
487
+ if ( ( 'none' !== $arguments['mla_style'] ) && ( 'theme' !== $arguments['mla_style'] ) ) {
488
+ if ( !MLATemplate_Support::mla_fetch_custom_template( $arguments['mla_style'], 'gallery', 'style', '[exists]' ) ) {
489
+ MLACore::mla_debug_add( '<strong>mla_gallery mla_style</strong> "' . $arguments['mla_style'] . '" ' . __( 'not found', 'media-library-assistant' ), MLACore::MLA_DEBUG_CATEGORY_ANY );
490
+ $arguments['mla_style'] = $default_arguments['mla_style'];
491
+ }
492
+ }
493
+
494
+ if ( !MLATemplate_Support::mla_fetch_custom_template( $arguments['mla_markup'], 'gallery', 'markup', '[exists]' ) ) {
495
+ MLACore::mla_debug_add( '<strong>mla_gallery mla_markup</strong> "' . $arguments['mla_markup'] . '" ' . __( 'not found', 'media-library-assistant' ), MLACore::MLA_DEBUG_CATEGORY_ANY );
496
+ $arguments['mla_markup'] = $default_arguments['mla_markup'];
497
+ }
498
+
499
  /*
500
  * Look for "no effect" alternate gallery shortcode to support plugins such as Justified Image Grid
501
  */
502
+ if ( is_string( $arguments['mla_alt_shortcode'] ) && ( in_array( $arguments['mla_alt_shortcode'], array( 'mla_gallery', 'no' ) ) ) ) {
503
  $arguments['mla_alt_shortcode'] = NULL;
504
  $arguments['mla_alt_ids_name'] = 'ids';
505
  $arguments['mla_alt_ids_value'] = NULL;
530
  if ( $is_pagination && ( NULL !== $arguments['mla_paginate_rows'] ) ) {
531
  $attachments['found_rows'] = absint( $arguments['mla_paginate_rows'] );
532
  } else {
533
+ $attachments = self::mla_get_shortcode_attachments( $post->ID, $attr, true );
534
  }
535
 
536
  if ( is_string( $attachments ) ) {
574
  /*
575
  * Replace data-selection parameters with the "ids" list
576
  */
577
+ $blacklist = array_merge( self::$mla_get_shortcode_attachments_parameters, self::$mla_get_shortcode_dynamic_attachments_parameters );
578
+ if ( 'mla_tag_cloud' !== $arguments['mla_alt_shortcode'] ) {
579
+ $blacklist = array_merge( $mla_arguments, $blacklist );
 
580
  }
581
+
582
+ $blacklist = apply_filters( 'mla_gallery_alt_shortcode_blacklist', $blacklist );
583
+ $alt_attr = apply_filters( 'mla_gallery_alt_shortcode_attributes', $attr );
584
 
585
  $mla_alt_shortcode_args = '';
586
+ foreach ( $alt_attr as $key => $value ) {
587
  if ( array_key_exists( $key, $blacklist ) ) {
588
  continue;
589
  }
598
 
599
  /*
600
  * If an alternate value has been specified we must delay alt shortcode execution
601
+ * and accumulate $mla_alt_shortcode_ids in the template Item section.
602
  */
603
  $mla_alt_ids_value = is_null( $arguments['mla_alt_ids_value'] ) ? NULL : str_replace( '{+', '[+', str_replace( '+}', '+]', $arguments['mla_alt_ids_value'] ) );
604
  $mla_alt_shortcode_ids = array();
605
 
606
  if ( is_null( $mla_alt_ids_value ) ) {
607
+
608
+ $mla_alt_shortcode_ids = apply_filters_ref_array( 'mla_gallery_alt_shortcode_ids', array( $mla_alt_shortcode_ids, $arguments['mla_alt_ids_name'], &$attachments ) );
609
+ if ( is_array( $mla_alt_shortcode_ids ) ) {
610
+ if ( 0 == count( $mla_alt_shortcode_ids ) ) {
611
+ foreach ( $attachments as $value ) {
612
+ $mla_alt_shortcode_ids[] = $value->ID;
613
+ } // foreach $attachments
614
+ }
615
+
616
+ $mla_alt_shortcode_ids = $arguments['mla_alt_ids_name'] . '="' . implode( ',', $mla_alt_shortcode_ids ) . '"';
617
+ }
618
 
619
  if ( self::$mla_debug ) {
620
  $output = MLACore::mla_debug_flush();
627
  */
628
  $content = apply_filters( 'mla_gallery_final_content', $content );
629
  if ( ! empty( $content ) ) {
630
+ $output .= do_shortcode( sprintf( '[%1$s %2$s %3$s]%4$s[/%1$s]', $arguments['mla_alt_shortcode'], $mla_alt_shortcode_ids, $mla_alt_shortcode_args, $content ) );
631
  } else {
632
+ $output .= do_shortcode( sprintf( '[%1$s %2$s %3$s]', $arguments['mla_alt_shortcode'], $mla_alt_shortcode_ids, $mla_alt_shortcode_args ) );
633
  }
634
+
635
+ do_action( 'mla_gallery_end_alt_shortcode' );
636
+ return $output;
637
  } // is_null( $mla_alt_ids_value )
638
  } // mla_alt_shortcode
639
 
791
  if ( apply_filters( 'use_mla_gallery_style', $use_mla_gallery_style, $style_values['mla_style'] ) ) {
792
  $style_template = MLATemplate_support::mla_fetch_custom_template( $style_values['mla_style'], 'gallery', 'style' );
793
  if ( empty( $style_template ) ) {
794
+ $style_values['mla_style'] = 'default';
795
+ $style_template = MLATemplate_support::mla_fetch_custom_template( 'default', 'gallery', 'style' );
 
 
 
 
796
  }
797
 
798
  if ( ! empty ( $style_template ) ) {
831
  $markup_values = $style_values;
832
 
833
  $open_template = MLATemplate_support::mla_fetch_custom_template( $markup_values['mla_markup'], 'gallery', 'markup', 'open' );
 
 
 
 
 
 
 
 
834
  if ( empty( $open_template ) ) {
835
  $open_template = '';
836
  }
1619
  $mla_alt_shortcode_ids = $arguments['mla_alt_ids_name'] . '="' . implode( ',', $mla_alt_shortcode_ids ) . '"';
1620
  $content = apply_filters( 'mla_gallery_final_content', $content );
1621
  if ( ! empty( $content ) ) {
1622
+ return $output . do_shortcode( sprintf( '[%1$s %2$s %3$s]%4$s[/%1$s]', $arguments['mla_alt_shortcode'], $mla_alt_shortcode_ids, $mla_alt_shortcode_args, $content ) );
1623
  } else {
1624
  return $output . do_shortcode( sprintf( '[%1$s %2$s %3$s]', $arguments['mla_alt_shortcode'], $mla_alt_shortcode_ids, $mla_alt_shortcode_args ) );
1625
  }
1664
  * Some do_shortcode callers may not have a specific post in mind
1665
  */
1666
  if ( ! is_object( $post ) ) {
1667
+ $post = (object) self::$empty_post;
 
 
 
 
 
 
 
 
 
 
 
 
1668
  }
1669
 
1670
+ // $instance supports multiple clouds in one page/post
1671
+ static $instance = 0;
1672
+ $instance++;
1673
+
1674
+ /*
1675
+ * Some values are already known, and can be used in data selection parameters
1676
+ */
1677
+ $upload_dir = wp_upload_dir();
1678
+ $page_values = array(
1679
+ 'instance' => $instance,
1680
+ 'selector' => "mla_tag_cloud-{$instance}",
1681
+ 'site_url' => site_url(),
1682
+ 'base_url' => $upload_dir['baseurl'],
1683
+ 'base_dir' => $upload_dir['basedir'],
1684
+ 'id' => $post->ID,
1685
+ 'page_ID' => $post->ID,
1686
+ 'page_author' => $post->post_author,
1687
+ 'page_date' => $post->post_date,
1688
+ 'page_content' => $post->post_content,
1689
+ 'page_title' => $post->post_title,
1690
+ 'page_excerpt' => $post->post_excerpt,
1691
+ 'page_status' => $post->post_status,
1692
+ 'page_name' => $post->post_name,
1693
+ 'page_modified' => $post->post_modified,
1694
+ 'page_guid' => $post->guid,
1695
+ 'page_type' => $post->post_type,
1696
+ 'page_url' => get_page_link(),
1697
+ );
1698
+
1699
  /*
1700
  * These are the default parameters for tag cloud display
1701
  */
1766
  $attr['mla_page_parameter'] = $defaults['mla_page_parameter'];
1767
  }
1768
 
1769
+ // The mla_page_parameter can contain page_level parameters like {+page_ID+}
1770
+ $attr_value = str_replace( '{+', '[+', str_replace( '+}', '+]', $attr['mla_page_parameter'] ) );
1771
+ $mla_page_parameter = MLAData::mla_parse_template( $attr_value, $page_values );
1772
 
1773
  /*
1774
  * Special handling of mla_page_parameter to make
1781
  }
1782
  }
1783
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1784
  /*
1785
  * Determine markup template to get default arguments
1786
  */
1787
  $arguments = shortcode_atts( $defaults, $attr );
1788
  if ( $arguments['mla_markup'] ) {
1789
  $template = $arguments['mla_markup'];
1790
+ if ( ! MLATemplate_Support::mla_fetch_custom_template( $template, 'tag-cloud', 'markup', '[exists]' ) ) {
1791
+ $template = NULL;
1792
+ }
1793
  } else {
1794
+ $template = NULL;
1795
+ }
1796
+
1797
+ if ( empty( $template ) ) {
1798
  $output_parameters = array_map( 'strtolower', array_map( 'trim', explode( ',', $arguments['mla_output'] ) ) );
1799
 
1800
+ if ( !in_array( $output_parameters[0], array( 'flat', 'list', 'ulist', 'olist', 'dlist', 'grid', 'array' ) ) ) {
1801
+ $output_parameters[0] = 'flat';
1802
+ }
1803
+
1804
  if ( 'grid' == $output_parameters[0] ) {
1805
  $template = MLACore::mla_get_option('default_tag_cloud_markup');
1806
  } elseif ( in_array( $output_parameters[0], array( 'list', 'ulist', 'olist', 'dlist' ) ) ) {
1891
  }
1892
 
1893
  /*
1894
+ * Determine templates and output type
1895
  */
1896
+ if ( $arguments['mla_style'] && ( 'none' !== $arguments['mla_style'] ) ) {
1897
+ if ( !MLATemplate_Support::mla_fetch_custom_template( $arguments['mla_style'], 'tag-cloud', 'style', '[exists]' ) ) {
1898
+ MLACore::mla_debug_add( '<strong>mla_tag_cloud mla_style</strong> "' . $arguments['mla_style'] . '" ' . __( 'not found', 'media-library-assistant' ), MLACore::MLA_DEBUG_CATEGORY_ANY );
1899
+ $arguments['mla_style'] = NULL;
1900
+ }
1901
+ }
1902
+
1903
+ if ( $arguments['mla_markup'] ) {
1904
+ if ( !MLATemplate_Support::mla_fetch_custom_template( $arguments['mla_markup'], 'tag-cloud', 'markup', '[exists]' ) ) {
1905
+ MLACore::mla_debug_add( '<strong>mla_tag_cloud mla_markup</strong> "' . $arguments['mla_markup'] . '" ' . __( 'not found', 'media-library-assistant' ), MLACore::MLA_DEBUG_CATEGORY_ANY );
1906
+ $arguments['mla_markup'] = NULL;
1907
+ }
1908
+ }
1909
+
1910
  $output_parameters = array_map( 'strtolower', array_map( 'trim', explode( ',', $arguments['mla_output'] ) ) );
1911
 
1912
+ if ( !in_array( $output_parameters[0], array( 'flat', 'list', 'ulist', 'olist', 'dlist', 'grid', 'array' ) ) ) {
1913
+ $output_parameters[0] = 'flat';
1914
+ }
1915
+
1916
  if ( $is_grid = 'grid' == $output_parameters[0] ) {
1917
  $default_style = MLACore::mla_get_option('default_tag_cloud_style');
1918
  $default_markup = MLACore::mla_get_option('default_tag_cloud_markup');
2366
  */
2367
  $tag_links = array();
2368
 
2369
+ // Find delimiter for currentlink, currentlink_url
2370
+ if ( strpos( $markup_values['page_url'], '?' ) ) {
2371
+ $current_item_delimiter = '&';
2372
+ } else {
2373
+ $current_item_delimiter = '?';
2374
+ }
2375
+
2376
  $column_index = 0;
2377
  foreach ( $tags as $key => $tag ) {
2378
  $item_values = $markup_values;
2400
  $item_values['scaled_count'] = $tag->scaled_count;
2401
  $item_values['font_size'] = str_replace( ',', '.', ( $item_values['smallest'] + ( ( $item_values['scaled_count'] - $item_values['min_scaled_count'] ) * $item_values['font_step'] ) ) );
2402
  $item_values['link_url'] = $tag->link;
2403
+ $item_values['currentlink_url'] = sprintf( '%1$s%2$scurrent_item=%3$d', $item_values['page_url'], $current_item_delimiter, $item_values['term_id'] );
2404
  $item_values['editlink_url'] = $tag->edit_link;
2405
  $item_values['termlink_url'] = $tag->term_link;
2406
  // Added in the code below:
2495
  /*
2496
  * Currentlink, editlink, termlink and thelink
2497
  */
2498
+ $item_values['currentlink'] = sprintf( '<a %1$shref="%2$s%3$scurrent_item=%4$d" title="%5$s" style="%6$s">%7$s</a>', $link_attributes, $item_values['page_url'], $current_item_delimiter, $item_values['term_id'], $item_values['rollover_text'], $item_values['link_style'], $item_values['link_text'] );
2499
  $item_values['editlink'] = sprintf( '<a %1$shref="%2$s" title="%3$s" style="%4$s">%5$s</a>', $link_attributes, $item_values['editlink_url'], $item_values['rollover_text'], $item_values['link_style'], $item_values['link_text'] );
2500
  $item_values['termlink'] = sprintf( '<a %1$shref="%2$s" title="%3$s" style="%4$s">%5$s</a>', $link_attributes, $item_values['termlink_url'], $item_values['rollover_text'], $item_values['link_style'], $item_values['link_text'] );
2501
 
2656
  */
2657
  $output_parameters = array_map( 'strtolower', array_map( 'trim', explode( ',', $arguments['mla_output'] ) ) );
2658
 
2659
+ if ( !in_array( $output_parameters[0], array( 'flat', 'list', 'ulist', 'olist', 'dlist', 'dropdown', 'checklist', 'array' ) ) ) {
2660
+ $output_parameters[0] = 'ulist';
2661
+ }
2662
+
2663
  $is_list = in_array( $output_parameters[0], array( 'list', 'ulist', 'olist', 'dlist' ) );
2664
  $is_dropdown = 'dropdown' == $output_parameters[0];
2665
  $is_checklist = 'checklist' == $output_parameters[0];
2744
  }
2745
  } // is_list
2746
 
2747
+ // Find delimiter for currentlink, currentlink_url
2748
+ if ( strpos( $markup_values['page_url'], '?' ) ) {
2749
+ $current_item_delimiter = '&';
2750
+ } else {
2751
+ $current_item_delimiter = '?';
2752
+ }
2753
+
2754
  foreach ( $terms as $key => $term ) {
2755
  $item_values = $markup_values;
2756
 
2768
  $item_values['parent'] = $term->parent;
2769
  $item_values['count'] = isset ( $term->count ) ? 0 + $term->count : 0;
2770
  $item_values['link_url'] = $term->link;
2771
+ $item_values['currentlink_url'] = sprintf( '%1$s%2$scurrent_item=%3$d', $item_values['page_url'], $current_item_delimiter, $item_values['term_id'] );
2772
  $item_values['editlink_url'] = $term->edit_link;
2773
  $item_values['termlink_url'] = $term->term_link;
2774
  $item_values['children'] = '';
2869
  /*
2870
  * Currentlink, editlink, termlink and thelink TODO - link style
2871
  */
2872
+ $item_values['currentlink'] = sprintf( '<a %1$shref="%2$s%3$s%4$s=%5$d" title="%6$s" style="%7$s">%8$s</a>', $link_attributes, $item_values['page_url'], $current_item_delimiter, $mla_item_parameter, $item_values['term_id'], $item_values['rollover_text'], '', $item_values['link_text'] );
2873
  $item_values['editlink'] = sprintf( '<a %1$shref="%2$s" title="%3$s" style="%4$s">%5$s</a>', $link_attributes, $item_values['editlink_url'], $item_values['rollover_text'], '', $item_values['link_text'] );
2874
  $item_values['termlink'] = sprintf( '<a %1$shref="%2$s" title="%3$s" style="%4$s">%5$s</a>', $link_attributes, $item_values['termlink_url'], $item_values['rollover_text'], '', $item_values['link_text'] );
2875
 
3004
  * Some do_shortcode callers may not have a specific post in mind
3005
  */
3006
  if ( ! is_object( $post ) ) {
3007
+ $post = (object) self::$empty_post;
 
 
 
 
 
 
 
 
 
 
 
 
3008
  }
3009
 
3010
+ // $instance supports multiple lists in one page/post
3011
+ static $instance = 0;
3012
+ $instance++;
3013
+
3014
+ /*
3015
+ * Some values are already known, and can be used in data selection parameters
3016
+ */
3017
+ $upload_dir = wp_upload_dir();
3018
+ $page_values = array(
3019
+ 'instance' => $instance,
3020
+ 'selector' => "mla_term_list-{$instance}",
3021
+ 'site_url' => site_url(),
3022
+ 'base_url' => $upload_dir['baseurl'],
3023
+ 'base_dir' => $upload_dir['basedir'],
3024
+ 'id' => $post->ID,
3025
+ 'page_ID' => $post->ID,
3026
+ 'page_author' => $post->post_author,
3027
+ 'page_date' => $post->post_date,
3028
+ 'page_content' => $post->post_content,
3029
+ 'page_title' => $post->post_title,
3030
+ 'page_excerpt' => $post->post_excerpt,
3031
+ 'page_status' => $post->post_status,
3032
+ 'page_name' => $post->post_name,
3033
+ 'page_modified' => $post->post_modified,
3034
+ 'page_guid' => $post->guid,
3035
+ 'page_type' => $post->post_type,
3036
+ 'page_url' => get_page_link(),
3037
+ );
3038
+
3039
  $defaults = array_merge(
3040
  self::$mla_get_terms_parameters,
3041
  array(
3058
  'itemtag' => 'ul',
3059
  'termtag' => 'li',
3060
  'captiontag' => '',
3061
+ 'mla_multi_select' => '',
3062
 
3063
  'mla_nolink_text' => '',
3064
  'mla_target' => '',
3090
  $attr['mla_item_parameter'] = $defaults['mla_item_parameter'];
3091
  }
3092
 
3093
+ // The mla_item_parameter can contain page_level parameters like {+page_ID+}
3094
+ $attr_value = str_replace( '{+', '[+', str_replace( '+}', '+]', $attr['mla_item_parameter'] ) );
3095
+ $mla_item_parameter = MLAData::mla_parse_template( $attr_value, $page_values );
3096
 
3097
  /*
3098
  * Special handling of mla_item_parameter to make
3105
  }
3106
  }
3107
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3108
  /*
3109
  * Determine markup template to get default arguments
3110
  */
3125
 
3126
  if ( $arguments['mla_markup'] ) {
3127
  $template = $arguments['mla_markup'];
3128
+ if ( ! MLATemplate_Support::mla_fetch_custom_template( $template, 'term-list', 'markup', '[exists]' ) ) {
3129
+ $template = NULL;
3130
+ }
3131
  } else {
3132
+ $template = NULL;
3133
+ }
3134
+
3135
+ if ( empty( $template ) ) {
3136
  $output_parameters = array_map( 'strtolower', array_map( 'trim', explode( ',', $arguments['mla_output'] ) ) );
3137
 
3138
+ if ( !in_array( $output_parameters[0], array( 'flat', 'list', 'ulist', 'olist', 'dlist', 'dropdown', 'checklist', 'array' ) ) ) {
3139
+ $output_parameters[0] = 'ulist';
3140
+ }
3141
+
3142
  if ( in_array( $output_parameters[0], array( 'list', 'ulist', 'olist', 'dlist' ) ) ) {
3143
  if ( ( 'dlist' == $output_parameters[0] ) || ('list' == $output_parameters[0] && 'dd' == $arguments['captiontag'] ) ) {
3144
  $template = 'term-list-dl';
3234
  }
3235
 
3236
  /*
3237
+ * Determine templates and output type
3238
  */
3239
+ if ( $arguments['mla_style'] && ( 'none' !== $arguments['mla_style'] ) ) {
3240
+ if ( !MLATemplate_Support::mla_fetch_custom_template( $arguments['mla_style'], 'term-list', 'style', '[exists]' ) ) {
3241
+ MLACore::mla_debug_add( '<strong>mla_term_list mla_style</strong> "' . $arguments['mla_style'] . '" ' . __( 'not found', 'media-library-assistant' ), MLACore::MLA_DEBUG_CATEGORY_ANY );
3242
+ $arguments['mla_style'] = NULL;
3243
+ }
3244
+ }
3245
+
3246
+ if ( $arguments['mla_markup'] ) {
3247
+ if ( !MLATemplate_Support::mla_fetch_custom_template( $arguments['mla_markup'], 'term-list', 'markup', '[exists]' ) ) {
3248
+ MLACore::mla_debug_add( '<strong>mla_term_list mla_markup</strong> "' . $arguments['mla_markup'] . '" ' . __( 'not found', 'media-library-assistant' ), MLACore::MLA_DEBUG_CATEGORY_ANY );
3249
+ $arguments['mla_markup'] = NULL;
3250
+ }
3251
+ }
3252
+
3253
  $output_parameters = array_map( 'strtolower', array_map( 'trim', explode( ',', $arguments['mla_output'] ) ) );
3254
 
3255
+ if ( !in_array( $output_parameters[0], array( 'flat', 'list', 'ulist', 'olist', 'dlist', 'dropdown', 'checklist', 'array' ) ) ) {
3256
+ $output_parameters[0] = 'ulist';
3257
+ }
3258
+
3259
  if ( $is_list = in_array( $output_parameters[0], array( 'list', 'ulist', 'olist', 'dlist' ) ) ) {
3260
  $default_style = 'term-list';
3261
 
3298
  if ( $is_dropdown = 'dropdown' == $output_parameters[0] ) {
3299
  $default_style = 'term-list';
3300
  $default_markup = 'term-list-dropdown';
3301
+ $arguments['itemtag'] = empty( $attr['itemtag'] ) ? 'select' : $attr['itemtag'];
3302
  $arguments['termtag'] = 'option';
3303
 
3304
  if ( NULL == $arguments['mla_style'] ) {
3324
  }
3325
  }
3326
 
3327
+ $mla_multi_select = !empty( $arguments['mla_multi_select'] ) && ( 'true' == strtolower( $arguments['mla_multi_select'] ) );
3328
+
3329
  $is_hierarchical = !empty( $arguments['hierarchical'] ) && ( 'true' == strtolower( $arguments['hierarchical'] ) );
3330
 
3331
  /*
3541
  'itemtag' => tag_escape( $arguments['itemtag'] ),
3542
  'termtag' => tag_escape( $arguments['termtag'] ),
3543
  'captiontag' => tag_escape( $arguments['captiontag'] ),
3544
+ 'multiple' => $arguments['mla_multi_select'] ? 'multiple' : '',
3545
  'itemtag_attributes' => '',
3546
  'itemtag_class' => 'term-list term-list-taxonomy-' . implode( '-', $arguments['taxonomy'] ),
3547
  'itemtag_id' => $page_values['selector'],
4303
  'update_post_term_cache' => NULL,
4304
  );
4305
 
4306
+ /**
4307
+ * Data selection parameters for the WP_Query in [mla_gallery]
4308
+ *
4309
+ * @since 2.40
4310
+ *
4311
+ * @var array
4312
+ */
4313
+ private static $mla_get_shortcode_dynamic_attachments_parameters = array(
4314
+ // Taxonomy parameters are handled separately
4315
+ // {tax_slug} => 'term' | array ( 'term', 'term', ... )
4316
+ // 'tax_query' => ''
4317
+ // 'tax_relation' => 'OR', 'AND' (default),
4318
+ // 'tax_operator' => 'OR' (default), 'IN', 'NOT IN', 'AND',
4319
+ // 'tax_include_children' => true (default), false
4320
+ );
4321
+
4322
  /**
4323
  * Parses shortcode parameters and returns the gallery objects
4324
  *
4360
  if ( isset( $attr['where_used_query'] ) && ( 'this-is-a-where-used-query' == $attr['where_used_query'] ) ) {
4361
  $where_used_query = true;
4362
  unset( $attr['where_used_query'] );
4363
+
4364
+ // remove pagination parameters to get a complete result
4365
+ $attr['nopaging'] = true;
4366
+ unset( $attr['numberposts'] );
4367
+ unset( $attr['posts_per_page'] );
4368
+ unset( $attr['posts_per_archive_page'] );
4369
+ unset( $attr['paged'] );
4370
+ unset( $attr['offset'] );
4371
+ unset( $attr['mla_paginate_current'] );
4372
+ unset( $attr['mla_page_parameter'] );
4373
+ unset( $attr['mla_paginate_total'] );
4374
+
4375
+ // There's no point in sorting the items
4376
+ $attr['orderby'] = 'none';
4377
  } else {
4378
  $where_used_query = false;
4379
  }
4421
  /*
4422
  * Extract taxonomy arguments
4423
  */
4424
+ self::$mla_get_shortcode_dynamic_attachments_parameters = array();
4425
  $query_arguments = array();
4426
  if ( ! empty( $attr ) ) {
4427
  $all_taxonomies = get_taxonomies( array ( 'show_ui' => true ), 'names' );
4430
  if ( 'tax_query' == $key ) {
4431
  if ( is_array( $value ) ) {
4432
  $query_arguments[ $key ] = $value;
4433
+ self::$mla_get_shortcode_dynamic_attachments_parameters[ $key ] = $value;
4434
  } else {
4435
  $tax_query = NULL;
4436
  $value = self::_sanitize_query_specification( $value );
4449
 
4450
  if ( is_array( $tax_query ) ) {
4451
  $query_arguments[ $key ] = $tax_query;
4452
+ self::$mla_get_shortcode_dynamic_attachments_parameters[ $key ] = $value;
4453
  break; // Done - the tax_query overrides all other taxonomy parameters
4454
  } else {
4455
  return '<p>' . __( 'ERROR', 'media-library-assistant' ) . ': ' . __( 'Invalid mla_gallery', 'media-library-assistant' ) . ' tax_query = ' . var_export( $value, true ) . '</p>';
4495
 
4496
  $tax_include_children = true;
4497
  if ( isset( $attr['tax_include_children'] ) ) {
4498
+ if ( 'false' == strtolower( $attr['tax_include_children'] ) ) {
4499
  $tax_include_children = false;
4500
  }
4501
  }
4505
  }
4506
 
4507
  $query_arguments['tax_query'] = $tax_query;
4508
+ self::$mla_get_shortcode_dynamic_attachments_parameters['tax_query'] = $tax_query;
4509
  } else {
4510
  // exactly one simple query is present
4511
  if ( isset( $simple_tax_queries['category'] ) ) {
4512
  $arguments['category_name'] = $simple_tax_queries['category'];
4513
  } else {
4514
  $query_arguments = $simple_tax_queries;
4515
+ self::$mla_get_shortcode_dynamic_attachments_parameters = $simple_tax_queries;
4516
  }
4517
  }
4518
  } // ! empty
4519
 
4520
+ // Finish building the dynamic parameters
4521
+ if ( isset( $attr['tax_relation'] ) ) {
4522
+ self::$mla_get_shortcode_dynamic_attachments_parameters['tax_relation'] = $attr['tax_relation'];
4523
+ }
4524
+
4525
+ if ( isset( $attr['tax_operator'] ) ) {
4526
+ self::$mla_get_shortcode_dynamic_attachments_parameters['tax_operator'] = $attr['tax_operator'];
4527
+ }
4528
+
4529
+ if ( isset( $attr['tax_include_children'] ) ) {
4530
+ self::$mla_get_shortcode_dynamic_attachments_parameters['tax_include_children'] = $attr['tax_include_children'];
4531
+ }
4532
+
4533
  /*
4534
  * $query_arguments has been initialized in the taxonomy code above.
4535
  */
4561
  $value = NULL;
4562
  $use_children = false;
4563
  break;
4564
+ default:
4565
+ if ( false !== strpos( $value, ',' ) ) {
4566
+ self::$query_parameters['post_parent'] = array_filter( array_map( 'absint', explode( ',', $value ) ) );
4567
+ $value = NULL;
4568
+ $use_children = false;
4569
+ }
4570
  }
4571
  // fallthru
4572
  case 'id':
4863
  // ignore anything else
4864
  } // switch $key
4865
  } // foreach $arguments
4866
+
4867
  /*
4868
  * Decide whether to use a "get_children" style query
4869
  */
4883
  }
4884
  unset( $query_arguments['numberposts'] );
4885
 
4886
+ /*
4887
+ * Apply the archive/search tests here because WP_Query doesn't apply them to galleries within
4888
+ * search results or archive pages.
4889
+ */
4890
+ if ( self::$mla_debug ) {
4891
+ MLACore::mla_debug_add( '<strong>mla_debug is_archive()</strong> = ' . var_export( is_archive(), true ) );
4892
+ MLACore::mla_debug_add( '<strong>mla_debug is_search()</strong> = ' . var_export( is_search(), true ) );
4893
+ }
4894
+
4895
+ if ( isset( $query_arguments['posts_per_archive_page'] ) && ( is_archive() || is_search() ) ) {
4896
+ $query_arguments['posts_per_page'] = $query_arguments['posts_per_archive_page'];
4897
+ }
4898
+ unset( $query_arguments['posts_per_archive_page'] );
4899
+
4900
  /*
4901
  * MLA pagination will override WordPress pagination
4902
  */
5099
  $return_found_rows = false;
5100
  } else {
5101
  do_action( 'mla_gallery_wp_query_object', $query_arguments );
 
5102
 
5103
+ if ( $return_found_rows ) {
5104
+ $attachments['found_rows'] = absint( MLAShortcodes::$mla_gallery_wp_query_object->found_posts );
5105
+ $attachments['max_num_pages'] = absint( MLAShortcodes::$mla_gallery_wp_query_object->max_num_pages );
5106
+ }
5107
+
5108
+ $filtered_attachments = apply_filters_ref_array( 'mla_gallery_the_attachments', array( NULL, &$attachments ) ) ;
5109
+ if ( !is_null( $filtered_attachments ) ) {
5110
+ $attachments = $filtered_attachments;
5111
+ }
5112
  }
5113
 
5114
  if ( ! empty( MLAQuery::$search_parameters ) ) {
5208
  }
5209
 
5210
  if ( isset( self::$query_parameters['post_parent'] ) ) {
5211
+ if ( is_array( self::$query_parameters['post_parent'] ) ) {
5212
+ $parent_list = implode( ',', self::$query_parameters['post_parent'] );
5213
+ $where_clause .= " AND {$table_prefix}posts.post_parent IN ({$parent_list})";
5214
+ } else {
5215
+ switch ( self::$query_parameters['post_parent'] ) {
5216
+ case 'any':
5217
+ $where_clause .= " AND {$table_prefix}posts.post_parent > 0";
5218
+ break;
5219
+ case 'none':
5220
+ $where_clause .= " AND {$table_prefix}posts.post_parent < 1";
5221
+ break;
5222
+ }
5223
  }
5224
  }
5225
 
includes/class-mla-shortcodes.php CHANGED
@@ -22,6 +22,20 @@ class MLAShortcodes {
22
  * @return void
23
  */
24
  public static function initialize() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  add_shortcode( 'mla_gallery', 'MLAShortcodes::mla_gallery_shortcode' );
26
  add_shortcode( 'mla_tag_cloud', 'MLAShortcodes::mla_tag_cloud_shortcode' );
27
  add_shortcode( 'mla_term_list', 'MLAShortcodes::mla_term_list_shortcode' );
22
  * @return void
23
  */
24
  public static function initialize() {
25
+ global $sitepress, $polylang;
26
+
27
+ /*
28
+ * Check for WPML/Polylang presence before loading language support class,
29
+ * then immediately initialize it since we're already in the "init" action.
30
+ */
31
+ if ( is_object( $sitepress ) ) {
32
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-wpml-shortcode-support.php' );
33
+ MLA_WPML_Shortcodes::initialize();
34
+ } elseif ( is_object( $polylang ) ) {
35
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-polylang-shortcode-support.php' );
36
+ MLA_Polylang_Shortcodes::initialize();
37
+ }
38
+
39
  add_shortcode( 'mla_gallery', 'MLAShortcodes::mla_gallery_shortcode' );
40
  add_shortcode( 'mla_tag_cloud', 'MLAShortcodes::mla_tag_cloud_shortcode' );
41
  add_shortcode( 'mla_term_list', 'MLAShortcodes::mla_term_list_shortcode' );
includes/class-mla-template-support.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Media Library Assistant Custom Style/Markup Template handler(s)
4
  *
5
  * @package Media Library Assistant
6
  * @since 2.30
@@ -16,187 +16,259 @@
16
  class MLATemplate_Support {
17
  /**
18
  * $mla_template_definitions defines the structure of the style and markup templates
19
- * and the labels, etc. required to render them in the Settings/Shortcodes tab
20
  *
21
  * The array must be populated at runtime in MLATemplate_Support::mla_localize_template_definitions();
22
  * localization calls cannot be placed in the "public static" array definition itself.
23
  *
24
- * Template types are indexed by 'style'/'markup' and then shortcode name. Each template type is defined by:
25
- * 'slug' => Sanitized version of the shortcode name
26
- * 'default_names' => Names of the default templates
27
- * 'label' => Styles only; label for the template textbox
28
- * 'help' => Styles only; help text displayed below the textbox
29
- * 'sections' => Markup only; array of template section definitions
30
- * 'sections'[] elements:
31
- * 'label' => Label for the section textbox
32
- * 'help' => Help text displayed below the textbox
33
- * 'order' => Where the section appears in the template
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  */
35
 
36
  public static $mla_template_definitions = array ();
37
 
38
  /**
39
- * Localize $mla_option_definitions array
40
  *
41
  * Localization must be done at runtime; these calls cannot be placed in the
42
  * "public static" array definition itself. Called from MLATest::initialize.
43
  *
44
  * @since 2.30
45
  *
46
- * @return void
47
  */
48
  public static function mla_localize_template_definitions() {
49
  self::$mla_template_definitions = array (
50
  'style' => array(
51
  'gallery' => array(
52
- 'slug' => 'gallery',
53
  'default_names' => array( 'default' ),
54
- 'label' => __( 'Styles', 'media-library-assistant' ),
55
- 'help' => __( 'List of substitution parameters, e.g., [+selector+], on Documentation tab.', 'media-library-assistant' ),
 
 
 
 
 
 
 
 
 
 
 
 
56
  ),
57
- 'tag_cloud' => array(
58
- 'slug' => 'tag-cloud',
59
  'default_names' => array( 'tag-cloud' ),
60
- 'label' => __( 'Styles', 'media-library-assistant' ),
61
- 'help' => __( 'List of substitution parameters, e.g., [+selector+], on Documentation tab.', 'media-library-assistant' ),
 
 
 
 
 
 
 
 
 
 
 
 
62
  ),
63
- 'term_list' => array(
64
- 'slug' => 'term-list',
65
  'default_names' => array( 'term-list' ),
66
- 'label' => __( 'Styles', 'media-library-assistant' ),
67
- 'help' => __( 'List of substitution parameters, e.g., [+selector+], on Documentation tab.', 'media-library-assistant' ),
 
 
 
 
 
 
 
 
 
 
 
 
68
  ),
69
  ),
70
  'markup' => array(
71
  'gallery' => array(
72
- 'slug' => 'gallery',
73
  'default_names' => array( 'default' ),
74
  'sections' => array(
 
 
 
 
 
 
75
  'arguments' => array(
76
  'label' => __( 'Arguments', 'media-library-assistant' ),
77
  'rows' => 3,
78
  'help' => __( 'Default shortcode parameter values.', 'media-library-assistant' ),
79
- 'order' => 0,
80
  ),
81
  'row-open' => array(
82
  'label' => __( 'Row', 'media-library-assistant' ) . '&nbsp;' . __( 'Open', 'media-library-assistant' ),
83
  'rows' => 3,
84
  'help' => __( 'Markup for the beginning of each row in the gallery.', 'media-library-assistant' ),
85
- 'order' => 2,
86
  ),
87
  'open' => array(
88
  'label' => __( 'Open', 'media-library-assistant' ),
89
  'rows' => 3,
90
  'help' => __( 'Markup for the beginning of the gallery. List of parameters, e.g., [+selector+], on Documentation tab.', 'media-library-assistant' ),
91
- 'order' => 1,
92
  ),
93
  'item' => array(
94
  'label' => __( 'Item', 'media-library-assistant' ),
95
  'rows' => 6,
96
  'help' => __( 'Markup for each item/cell of the gallery.', 'media-library-assistant' ),
97
- 'order' => 3,
98
  ),
99
  'row-close' => array(
100
  'label' => __( 'Row', 'media-library-assistant' ) . '&nbsp;' . __( 'Close', 'media-library-assistant' ),
101
  'rows' => 3,
102
  'help' => __( 'Markup for the end of each row in the gallery.', 'media-library-assistant' ),
103
- 'order' => 4,
104
  ),
105
  'close' => array(
106
  'label' => __( 'Close', 'media-library-assistant' ),
107
  'rows' => 3,
108
  'help' => __( 'Markup for the end of the gallery.', 'media-library-assistant' ),
109
- 'order' => 5,
110
  ),
111
  ),
112
  ),
113
- 'tag_cloud' => array(
114
- 'slug' => 'tag-cloud',
115
  'default_names' => array( 'tag-cloud', 'tag-cloud-ul', 'tag-cloud-dl' ),
116
  'sections' => array(
 
 
 
 
 
 
117
  'arguments' => array(
118
  'label' => __( 'Arguments', 'media-library-assistant' ),
119
  'rows' => 3,
120
  'help' => __( 'Default shortcode parameter values.', 'media-library-assistant' ),
121
- 'order' => 0,
122
  ),
123
  'row-open' => array(
124
  'label' => __( 'Row', 'media-library-assistant' ) . '&nbsp;' . __( 'Open', 'media-library-assistant' ),
125
  'rows' => 3,
126
  'help' => __( 'Markup for the beginning of each row in the cloud; grid format only.', 'media-library-assistant' ),
127
- 'order' => 2,
128
  ),
129
  'open' => array(
130
  'label' => __( 'Open', 'media-library-assistant' ),
131
  'rows' => 3,
132
  'help' => __( 'Markup for the beginning of the cloud. List of parameters, e.g., [+selector+], on Documentation tab.', 'media-library-assistant' ),
133
- 'order' => 1,
134
  ),
135
  'item' => array(
136
  'label' => __( 'Item', 'media-library-assistant' ),
137
  'rows' => 6,
138
  'help' => __( 'Markup for each item/cell of the cloud.', 'media-library-assistant' ),
139
- 'order' => 3,
140
  ),
141
  'row-close' => array(
142
  'label' => __( 'Row', 'media-library-assistant' ) . '&nbsp;' . __( 'Close', 'media-library-assistant' ),
143
  'rows' => 3,
144
  'help' => __( 'Markup for the end of each row in the cloud; grid format only.', 'media-library-assistant' ),
145
- 'order' => 4,
146
  ),
147
  'close' => array(
148
  'label' => __( 'Close', 'media-library-assistant' ),
149
  'rows' => 3,
150
  'help' => __( 'Markup for the end of the cloud.', 'media-library-assistant' ),
151
- 'order' => 5,
152
  ),
153
  ),
154
  ),
155
- 'term_list' => array(
156
- 'slug' => 'term-list',
157
  'default_names' => array( 'term-list-ul', 'term-list-dl', 'term-list-dropdown', 'term-list-checklist' ),
158
  'sections' => array(
 
 
 
 
 
 
159
  'arguments' => array(
160
  'label' => __( 'Arguments', 'media-library-assistant' ),
161
  'rows' => 3,
162
  'help' => __( 'Default shortcode parameter values.', 'media-library-assistant' ),
163
- 'order' => 0,
164
  ),
165
  'child-open' => array(
166
  'label' => __( 'Child', 'media-library-assistant' ) . '&nbsp;' . __( 'Open', 'media-library-assistant' ),
167
  'rows' => 3,
168
  'help' => __( 'Markup for the beginning of each level in the hierarchy; list format only.', 'media-library-assistant' ),
169
- 'order' => 3,
170
  ),
171
  'child-item' => array(
172
  'label' => __( 'Child', 'media-library-assistant' ) . '&nbsp;' . __( 'Item', 'media-library-assistant' ),
173
  'rows' => 6,
174
  'help' => __( 'Markup for each lower-level item in the hierarchy; list format only.', 'media-library-assistant' ),
175
- 'order' => 4,
176
  ),
177
  'child-close' => array(
178
  'label' => __( 'Child', 'media-library-assistant' ) . '&nbsp;' . __( 'Close', 'media-library-assistant' ),
179
  'rows' => 3,
180
  'help' => __( 'Markup for the end of each level in the hierarchy; list format only.', 'media-library-assistant' ),
181
- 'order' => 5,
182
  ),
183
  'open' => array(
184
  'label' => __( 'Open', 'media-library-assistant' ),
185
  'rows' => 3,
186
  'help' => __( 'Markup for the beginning of the list. List of parameters, e.g., [+selector+], on Documentation tab.', 'media-library-assistant' ),
187
- 'order' => 1,
188
  ),
189
  'item' => array(
190
  'label' => __( 'Item', 'media-library-assistant' ),
191
  'rows' => 6,
192
  'help' => __( 'Markup for each item/cell in the list.', 'media-library-assistant' ),
193
- 'order' => 2,
194
  ),
195
  'close' => array(
196
  'label' => __( 'Close', 'media-library-assistant' ),
197
  'rows' => 3,
198
  'help' => __( 'Markup for the end of the list.', 'media-library-assistant' ),
199
- 'order' => 6,
200
  ),
201
  ),
202
  ),
@@ -206,22 +278,36 @@ class MLATemplate_Support {
206
  }
207
 
208
  /**
209
- * Style and Markup templates
210
- *
211
- * Templates are indexed by 'style'/'markup' and then shortcode name. Each template type is defined by:
212
  *
213
  * @since 2.30
 
 
 
 
 
 
 
 
 
 
 
 
214
  *
215
- * @var array
 
 
 
 
216
  */
217
  private static $mla_custom_templates = NULL;
218
 
219
  /**
220
- * Load style and markup templates to $mla_custom_templates
221
  *
222
  * @since 2.30
223
  *
224
- * @return void
225
  */
226
  public static function mla_load_custom_templates() {
227
  if ( empty( MLATemplate_Support::$mla_template_definitions ) ) {
@@ -231,9 +317,7 @@ class MLATemplate_Support {
231
  MLATemplate_Support::$mla_custom_templates = NULL;
232
  $default_templates = MLACore::mla_load_template( 'mla-custom-templates.tpl' );
233
 
234
- /*
235
- * Load the default templates
236
- */
237
  if ( is_null( $default_templates ) ) {
238
  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 );
239
  return;
@@ -242,12 +326,12 @@ class MLATemplate_Support {
242
  return;
243
  }
244
 
245
- /*
246
- * Record explicit shortcode assignments
247
- */
248
  $mla_shortcode_slugs = array();
 
249
  foreach ( $default_templates as $key => $value ) {
250
  $mla_shortcode_slug = NULL;
 
251
 
252
  $match_count = preg_match( '#\<!-- mla_shortcode_slug="(.+)" --\>[\r\n]*#', $value, $matches, PREG_OFFSET_CAPTURE );
253
  if ( $match_count == 0 ) {
@@ -256,17 +340,34 @@ class MLATemplate_Support {
256
 
257
  if ( $match_count > 0 ) {
258
  $mla_shortcode_slug = $matches[ 1 ][ 0 ];
259
- //error_log( __LINE__ . " default template {$key}, {$mla_shortcode_slug} matches = " . var_export( $matches, true ), 0 );
260
  $value = substr_replace( $value, '', $matches[ 0 ][ 1 ], strlen( $matches[ 0 ][ 0 ] ) );
261
- if ( empty( $value ) ) {
262
- unset( $default_templates[ $key ] );
263
- //error_log( __LINE__ . " unset default template {$key}, {$mla_shortcode_slug}", 0 );
 
 
 
264
  } else {
265
- $default_templates[ $key ] = $value;
266
- //error_log( __LINE__ . " replace default template {$key}, {$mla_shortcode_slug} value = " . MLAData::mla_hex_dump( $value ), 0 );
 
 
267
  }
268
  }
269
 
 
 
 
 
 
 
 
 
 
 
 
 
 
270
  if ( !empty( $mla_shortcode_slug ) ) {
271
  $tail = strrpos( $key, '-style' );
272
  if ( ! ( false === $tail ) ) {
@@ -278,42 +379,48 @@ class MLATemplate_Support {
278
  }
279
  }
280
  }
 
 
 
 
 
 
 
281
  }
282
- //error_log( __LINE__ . " mla_shortcode_slugs = " . var_export( $mla_shortcode_slugs, true ), 0 );
283
 
284
- /*
285
- * Find the shortcode and template type for array indices
286
- */
287
  foreach ( $default_templates as $key => $value ) {
288
  $tail = strrpos( $key, '-style' );
289
  if ( ! ( false === $tail ) ) {
 
 
290
  $name = substr( $key, 0, $tail );
291
-
292
  if ( isset( $mla_shortcode_slugs['style'][ $name ] ) ) {
293
  // Assign to the declared shortcode
294
- MLATemplate_Support::$mla_custom_templates['style'][ $mla_shortcode_slugs['style'][ $name ] ][ $name ] = $value;
295
- $name = NULL;
296
  } else {
297
  // Guess at the shortcode
298
  foreach( MLATemplate_Support::$mla_template_definitions['style'] as $slug => $definition ) {
299
  if ( isset( $definition['default_names'] ) && in_array( $name, $definition['default_names'] ) ) {
300
- MLATemplate_Support::$mla_custom_templates['style'][ $definition['slug'] ][ $name ] = $value;
301
- $name = NULL;
302
  break;
303
  }
304
  }
305
  }
306
 
307
- // Can't find the shortcode; assume it's mla_gallery
308
- if ( $name ) {
309
- MLATemplate_Support::$mla_custom_templates['style']['gallery'][ $name ] = $value;
310
  }
311
 
 
312
  continue;
313
  }
314
 
315
  $tail = strrpos( $key, '-markup' );
316
  if ( ! ( false === $tail ) ) {
 
 
317
  $name = substr( $key, 0, $tail );
318
 
319
  // Look for explicit assignment
@@ -321,7 +428,6 @@ class MLATemplate_Support {
321
  $root = strpos( $name, $root_name );
322
  if ( 0 === $root ) {
323
  $section_name = substr( $name, strlen( $root_name ) + 1 );
324
- //error_log( __LINE__ . " assign default template {$key}, to [{$mla_shortcode_slug}][{$root_name}][{$section_name}]", 0 );
325
  // Assign to the declared shortcode
326
  MLATemplate_Support::$mla_custom_templates['markup'][ $mla_shortcode_slug ][ $root_name ][ $section_name ] = $value;
327
  $name = NULL;
@@ -340,19 +446,19 @@ class MLATemplate_Support {
340
  $tail = strrpos( $name, '-' . $section_name );
341
  if ( ! ( false === $tail ) ) {
342
  $name = substr( $name, 0, $tail );
343
- MLATemplate_Support::$mla_custom_templates['markup'][ $definition['slug'] ][ $name ][ $section_name ] = $value;
344
  }
345
  }
346
 
347
  $name = NULL;
348
  break;
349
- }
350
- }
351
  }
352
- }
353
- }
354
 
355
- // Can't find the shortcode; assume it's mla_gallery
356
  if ( $name ) {
357
  foreach( MLATemplate_Support::$mla_template_definitions['markup']['gallery']['sections'] as $section_name => $section_value ) {
358
  $tail = strrpos( $name, '-' . $section_name );
@@ -362,61 +468,51 @@ class MLATemplate_Support {
362
  }
363
  }
364
  }
365
- }
366
- }
367
 
368
- /*
369
- * Add user-defined Style and Markup templates
370
- *
371
- * MLA versions before 2.40 will not have separate 'attributes' and 'content' elements,
372
- * but version 2.3x must "go both ways" to allow for reversions.
373
- */
374
  $templates = MLACore::mla_get_option( 'style_templates' );
375
  if ( is_array( $templates ) ) {
376
  foreach ( $templates as $name => $value ) {
377
- // Check for 2.40+ format
378
- if ( is_array( $value ) ) {
379
- $attributes = $value['attributes'];
380
- MLATemplate_Support::$mla_custom_templates['style'][ $attributes['mla_shortcode_slug'] ][ $name ] = $value['content'];
381
- continue;
382
- }
383
-
384
- // Check for explicit assignment
385
- $match_count = preg_match( '#\<!-- mla_shortcode_slug="(.+)" --\>[\r\n]*#', $value, $matches, PREG_OFFSET_CAPTURE );
386
  if ( $match_count > 0 ) {
387
- //error_log( __LINE__ . " default template {$name} matches = " . var_export( $matches, true ), 0 );
388
  $value = substr_replace( $value, '', $matches[ 0 ][ 1 ], strlen( $matches[ 0 ][ 0 ] ) );
389
- //error_log( __LINE__ . " replace default template {$name} value = " . MLAData::mla_hex_dump( $value ), 0 );
390
- MLATemplate_Support::$mla_custom_templates['style'][ $matches[ 1 ][ 0 ] ][ $name ] = $value;
391
- continue;
392
  }
393
 
394
- // Guess from content
395
- foreach( MLATemplate_Support::$mla_template_definitions['style'] as $slug => $definition ) {
396
- if ( false !== strpos( $value, '.' . $definition['slug'] ) ) {
397
- MLATemplate_Support::$mla_custom_templates['style'][ $definition['slug'] ][ $name ] = $value;
398
- $name = NULL;
399
- break;
 
 
 
 
 
 
400
  }
401
  }
402
 
403
- if ( $name ) {
404
- MLATemplate_Support::$mla_custom_templates['style']['gallery'][ $name ] = $value;
405
  }
 
 
406
  } // foreach $templates
407
  } // is_array
408
 
 
409
  $templates = MLACore::mla_get_option( 'markup_templates' );
410
  if ( is_array( $templates ) ) {
411
  foreach ( $templates as $name => $value ) {
412
- // Check for 2.40+ format
413
- if ( isset( $value['attributes'] ) ) {
414
- $attributes = $value['attributes'];
415
- unset( $value['attributes'] );
416
- MLATemplate_Support::$mla_custom_templates['markup'][ $attributes['mla_shortcode_slug'] ][ $name ] = $value['content'];
417
- continue;
418
- }
419
-
420
  // Check for explicit assignment
421
  if ( isset( $value['arguments'] ) ) {
422
  $match_count = preg_match( '#mla_shortcode_slug="(.+)"[ \r\n]*#', $value['arguments'], $matches, PREG_OFFSET_CAPTURE );
@@ -425,13 +521,9 @@ class MLATemplate_Support {
425
  }
426
 
427
  if ( $match_count > 0 ) {
428
- //error_log( __LINE__ . " user template {$key} matches = " . var_export( $matches, true ), 0 );
429
  $value['arguments'] = substr_replace( $value['arguments'], '', $matches[ 0 ][ 1 ], strlen( $matches[ 0 ][ 0 ] ) );
430
  if ( empty( $value['arguments'] ) ) {
431
- //error_log( __LINE__ . " unset user template {$key}", 0 );
432
  unset( $value['arguments'] );
433
- } else {
434
- //error_log( __LINE__ . " replace user {$key} value = " . MLAData::mla_hex_dump( $value['arguments'] ), 0 );
435
  }
436
 
437
  MLATemplate_Support::$mla_custom_templates['markup'][ $matches[ 1 ][ 0 ] ][ $name ] = $value;
@@ -445,8 +537,8 @@ class MLATemplate_Support {
445
  }
446
 
447
  foreach( MLATemplate_Support::$mla_template_definitions['markup'] as $slug => $definition ) {
448
- if ( preg_match( '#class=[\'\"]*.*' . $definition['slug'] . '#', $full_text, $matches ) ) {
449
- MLATemplate_Support::$mla_custom_templates['markup'][ $definition['slug'] ][ $name ] = $value;
450
  $name = NULL;
451
  break;
452
  }
@@ -461,16 +553,18 @@ class MLATemplate_Support {
461
  }
462
 
463
  /**
464
- * Fetch style or markup template from $mla_templates
465
  *
466
  * @since 2.30
467
  *
468
- * @param string Template name
469
- * @param string Shortcode slug; 'gallery' (default), 'tag-cloud' or 'term-list'
470
- * @param string Template type; 'style' (default) or 'markup'
471
- * @param string Template section (markup templates); default '[not supplied]'
472
- *
473
- * @return string|boolean|null requested template, false if not found or null if no templates
 
 
474
  */
475
  public static function mla_fetch_custom_template( $key, $shortcode = 'gallery', $type = 'style', $section = '[not supplied]' ) {
476
  //MLACore::mla_debug_add( "<strong>mla_fetch_custom_template( {$key}, {$shortcode}, {$type}, {$section} )</strong> " . __( 'calling parameters', 'media-library-assistant' ), MLACore::MLA_DEBUG_CATEGORY_ANY );
@@ -478,21 +572,24 @@ class MLATemplate_Support {
478
  MLACore::mla_debug_add( '<strong>mla_fetch_custom_template()</strong> ' . __( 'no templates exist', 'media-library-assistant' ), MLACore::MLA_DEBUG_CATEGORY_ANY );
479
  return NULL;
480
  }
 
481
 
482
  if ( array_key_exists( $type, MLATemplate_Support::$mla_custom_templates ) ) {
483
  if ( array_key_exists( $shortcode, MLATemplate_Support::$mla_custom_templates[ $type ] ) ) {
484
  if ( array_key_exists( $key, MLATemplate_Support::$mla_custom_templates[ $type ][ $shortcode ] ) ) {
485
- if ( 'style' == $type ) {
486
- return MLATemplate_Support::$mla_custom_templates['style'][ $shortcode ][ $key ];
487
  }
488
 
489
- if ( array_key_exists( $section, MLATemplate_Support::$mla_custom_templates['markup'][ $shortcode ][ $key ] ) ) {
490
- return MLATemplate_Support::$mla_custom_templates['markup'][ $shortcode ][ $key ][ $section ];
 
 
491
  }
492
-
493
- /*
494
- * No error - not every section is required
495
- */
496
  return false;
497
  }
498
  }
@@ -503,13 +600,12 @@ class MLATemplate_Support {
503
  }
504
 
505
  /**
506
- * Get ALL style templates from $mla_custom_templates, including 'default'
507
  *
508
  * @since 2.30
509
  *
510
- * @param string Shortcode to which the template(s) apply; default ''
511
- *
512
- * @return array|null name => value for all style templates or null if no templates
513
  */
514
  public static function mla_get_style_templates( $shortcode = '' ) {
515
  if ( ! is_array( MLATemplate_Support::$mla_custom_templates ) ) {
@@ -538,11 +634,23 @@ class MLATemplate_Support {
538
  *
539
  * @since 2.30
540
  *
541
- * @param array name => value for all user-defined style templates
542
- * @return boolean true if success, false if failure
543
  */
544
  public static function mla_put_style_templates( $templates ) {
545
- if ( MLACore::mla_update_option( 'style_templates', $templates ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
546
  MLATemplate_Support::mla_load_custom_templates();
547
  return true;
548
  }
@@ -551,13 +659,12 @@ class MLATemplate_Support {
551
  }
552
 
553
  /**
554
- * Get ALL markup templates from $mla_custom_templates, including 'default'
555
  *
556
  * @since 2.30
557
  *
558
- * @param string Shortcode to which the template(s) apply; default 'gallery'
559
- *
560
- * @return array|null name => value for all markup templates or null if no templates
561
  */
562
  public static function mla_get_markup_templates( $shortcode = '' ) {
563
  if ( ! is_array( MLATemplate_Support::$mla_custom_templates ) ) {
@@ -586,8 +693,8 @@ class MLATemplate_Support {
586
  *
587
  * @since 2.30
588
  *
589
- * @param array name => value for all user-defined markup templates
590
- * @return boolean true if success, false if failure
591
  */
592
  public static function mla_put_markup_templates( $templates ) {
593
  if ( MLACore::mla_update_option( 'markup_templates', $templates ) ) {
1
  <?php
2
  /**
3
+ * Media Library Assistant Custom Style/Markup Template handler(s).
4
  *
5
  * @package Media Library Assistant
6
  * @since 2.30
16
  class MLATemplate_Support {
17
  /**
18
  * $mla_template_definitions defines the structure of the style and markup templates
19
+ * and the labels, etc. required to render them in the Settings/Shortcodes tab.
20
  *
21
  * The array must be populated at runtime in MLATemplate_Support::mla_localize_template_definitions();
22
  * localization calls cannot be placed in the "public static" array definition itself.
23
  *
24
+ * @since 2.30
25
+ * @access public
26
+ * @var array $mla_template_definitions {
27
+ * Definitions by type. Key $$type is 'markup' or 'style'.
28
+ *
29
+ * @type array $$type {
30
+ * Definitions by shortcode. Key $$shortcode_slug is 'gallery', 'tag-cloud' or 'term-list'
31
+ *
32
+ * @type array $$shortcode_slug {
33
+ * Templates by name. Key $$template_name is the template name/slug.
34
+ *
35
+ * @type string $label Label for the shortcode.
36
+ * @type array $default_names Names of the default templates.
37
+ * @type array $sections {
38
+ * Template section definitions. Key $$section_name is the section name/slug.
39
+ *
40
+ * @type array $$section_name {
41
+ * Definitions by section.
42
+ *
43
+ * @type string $label Label for the section textbox.
44
+ * @type integer $rows Number of rows for the section textbox.
45
+ * @type string $help Help text displayed below the textbox.
46
+ * @type integer $order Where the section appears in the template.
47
+ * }
48
+ * }
49
+ * }
50
+ * }
51
+ * }
52
  */
53
 
54
  public static $mla_template_definitions = array ();
55
 
56
  /**
57
+ * Localize $mla_option_definitions array.
58
  *
59
  * Localization must be done at runtime; these calls cannot be placed in the
60
  * "public static" array definition itself. Called from MLATest::initialize.
61
  *
62
  * @since 2.30
63
  *
64
+ * @return null
65
  */
66
  public static function mla_localize_template_definitions() {
67
  self::$mla_template_definitions = array (
68
  'style' => array(
69
  'gallery' => array(
70
+ 'label' => _x( 'Gallery', 'table_view_singular', 'media_library-assistant' ),
71
  'default_names' => array( 'default' ),
72
+ 'sections' => array(
73
+ 'description' => array(
74
+ 'label' => __( 'Description', 'media-library-assistant' ),
75
+ 'rows' => 3,
76
+ 'help' => __( 'Notes for the Shortcodes tab submenu table.', 'media-library-assistant' ),
77
+ 'order' => 0,
78
+ ),
79
+ 'styles' => array(
80
+ 'label' => __( 'Styles', 'media-library-assistant' ),
81
+ 'rows' => 10,
82
+ 'help' => __( 'List of substitution parameters, e.g., [+selector+], on Documentation tab.', 'media-library-assistant' ),
83
+ 'order' => 1,
84
+ ),
85
+ ),
86
  ),
87
+ 'tag-cloud' => array(
88
+ 'label' => _x( 'Tag Cloud', 'table_view_singular', 'media_library-assistant' ),
89
  'default_names' => array( 'tag-cloud' ),
90
+ 'sections' => array(
91
+ 'description' => array(
92
+ 'label' => __( 'Description', 'media-library-assistant' ),
93
+ 'rows' => 3,
94
+ 'help' => __( 'Notes for the Shortcodes tab submenu table.', 'media-library-assistant' ),
95
+ 'order' => 0,
96
+ ),
97
+ 'styles' => array(
98
+ 'label' => __( 'Styles', 'media-library-assistant' ),
99
+ 'rows' => 10,
100
+ 'help' => __( 'List of substitution parameters, e.g., [+selector+], on Documentation tab.', 'media-library-assistant' ),
101
+ 'order' => 1,
102
+ ),
103
+ ),
104
  ),
105
+ 'term-list' => array(
106
+ 'label' => _x( 'Term List', 'table_view_singular', 'media_library-assistant' ),
107
  'default_names' => array( 'term-list' ),
108
+ 'sections' => array(
109
+ 'description' => array(
110
+ 'label' => __( 'Description', 'media-library-assistant' ),
111
+ 'rows' => 3,
112
+ 'help' => __( 'Notes for the Shortcodes tab submenu table.', 'media-library-assistant' ),
113
+ 'order' => 0,
114
+ ),
115
+ 'styles' => array(
116
+ 'label' => __( 'Styles', 'media-library-assistant' ),
117
+ 'rows' => 10,
118
+ 'help' => __( 'List of substitution parameters, e.g., [+selector+], on Documentation tab.', 'media-library-assistant' ),
119
+ 'order' => 1,
120
+ ),
121
+ ),
122
  ),
123
  ),
124
  'markup' => array(
125
  'gallery' => array(
126
+ 'label' => _x( 'Gallery', 'table_view_singular', 'media_library-assistant' ),
127
  'default_names' => array( 'default' ),
128
  'sections' => array(
129
+ 'description' => array(
130
+ 'label' => __( 'Description', 'media-library-assistant' ),
131
+ 'rows' => 3,
132
+ 'help' => __( 'Notes for the Shortcodes tab submenu table.', 'media-library-assistant' ),
133
+ 'order' => 0,
134
+ ),
135
  'arguments' => array(
136
  'label' => __( 'Arguments', 'media-library-assistant' ),
137
  'rows' => 3,
138
  'help' => __( 'Default shortcode parameter values.', 'media-library-assistant' ),
139
+ 'order' => 2,
140
  ),
141
  'row-open' => array(
142
  'label' => __( 'Row', 'media-library-assistant' ) . '&nbsp;' . __( 'Open', 'media-library-assistant' ),
143
  'rows' => 3,
144
  'help' => __( 'Markup for the beginning of each row in the gallery.', 'media-library-assistant' ),
145
+ 'order' => 4,
146
  ),
147
  'open' => array(
148
  'label' => __( 'Open', 'media-library-assistant' ),
149
  'rows' => 3,
150
  'help' => __( 'Markup for the beginning of the gallery. List of parameters, e.g., [+selector+], on Documentation tab.', 'media-library-assistant' ),
151
+ 'order' => 3,
152
  ),
153
  'item' => array(
154
  'label' => __( 'Item', 'media-library-assistant' ),
155
  'rows' => 6,
156
  'help' => __( 'Markup for each item/cell of the gallery.', 'media-library-assistant' ),
157
+ 'order' => 5,
158
  ),
159
  'row-close' => array(
160
  'label' => __( 'Row', 'media-library-assistant' ) . '&nbsp;' . __( 'Close', 'media-library-assistant' ),
161
  'rows' => 3,
162
  'help' => __( 'Markup for the end of each row in the gallery.', 'media-library-assistant' ),
163
+ 'order' => 9,
164
  ),
165
  'close' => array(
166
  'label' => __( 'Close', 'media-library-assistant' ),
167
  'rows' => 3,
168
  'help' => __( 'Markup for the end of the gallery.', 'media-library-assistant' ),
169
+ 'order' => 10,
170
  ),
171
  ),
172
  ),
173
+ 'tag-cloud' => array(
174
+ 'label' => _x( 'Tag Cloud', 'table_view_singular', 'media_library-assistant' ),
175
  'default_names' => array( 'tag-cloud', 'tag-cloud-ul', 'tag-cloud-dl' ),
176
  'sections' => array(
177
+ 'description' => array(
178
+ 'label' => __( 'Description', 'media-library-assistant' ),
179
+ 'rows' => 3,
180
+ 'help' => __( 'Notes for the Shortcodes tab submenu table.', 'media-library-assistant' ),
181
+ 'order' => 0,
182
+ ),
183
  'arguments' => array(
184
  'label' => __( 'Arguments', 'media-library-assistant' ),
185
  'rows' => 3,
186
  'help' => __( 'Default shortcode parameter values.', 'media-library-assistant' ),
187
+ 'order' => 2,
188
  ),
189
  'row-open' => array(
190
  'label' => __( 'Row', 'media-library-assistant' ) . '&nbsp;' . __( 'Open', 'media-library-assistant' ),
191
  'rows' => 3,
192
  'help' => __( 'Markup for the beginning of each row in the cloud; grid format only.', 'media-library-assistant' ),
193
+ 'order' => 4,
194
  ),
195
  'open' => array(
196
  'label' => __( 'Open', 'media-library-assistant' ),
197
  'rows' => 3,
198
  'help' => __( 'Markup for the beginning of the cloud. List of parameters, e.g., [+selector+], on Documentation tab.', 'media-library-assistant' ),
199
+ 'order' => 3,
200
  ),
201
  'item' => array(
202
  'label' => __( 'Item', 'media-library-assistant' ),
203
  'rows' => 6,
204
  'help' => __( 'Markup for each item/cell of the cloud.', 'media-library-assistant' ),
205
+ 'order' => 5,
206
  ),
207
  'row-close' => array(
208
  'label' => __( 'Row', 'media-library-assistant' ) . '&nbsp;' . __( 'Close', 'media-library-assistant' ),
209
  'rows' => 3,
210
  'help' => __( 'Markup for the end of each row in the cloud; grid format only.', 'media-library-assistant' ),
211
+ 'order' => 9,
212
  ),
213
  'close' => array(
214
  'label' => __( 'Close', 'media-library-assistant' ),
215
  'rows' => 3,
216
  'help' => __( 'Markup for the end of the cloud.', 'media-library-assistant' ),
217
+ 'order' => 10,
218
  ),
219
  ),
220
  ),
221
+ 'term-list' => array(
222
+ 'label' => _x( 'Term List', 'table_view_singular', 'media_library-assistant' ),
223
  'default_names' => array( 'term-list-ul', 'term-list-dl', 'term-list-dropdown', 'term-list-checklist' ),
224
  'sections' => array(
225
+ 'description' => array(
226
+ 'label' => __( 'Description', 'media-library-assistant' ),
227
+ 'rows' => 3,
228
+ 'help' => __( 'Notes for the Shortcodes tab submenu table.', 'media-library-assistant' ),
229
+ 'order' => 0,
230
+ ),
231
  'arguments' => array(
232
  'label' => __( 'Arguments', 'media-library-assistant' ),
233
  'rows' => 3,
234
  'help' => __( 'Default shortcode parameter values.', 'media-library-assistant' ),
235
+ 'order' => 1,
236
  ),
237
  'child-open' => array(
238
  'label' => __( 'Child', 'media-library-assistant' ) . '&nbsp;' . __( 'Open', 'media-library-assistant' ),
239
  'rows' => 3,
240
  'help' => __( 'Markup for the beginning of each level in the hierarchy; list format only.', 'media-library-assistant' ),
241
+ 'order' => 6,
242
  ),
243
  'child-item' => array(
244
  'label' => __( 'Child', 'media-library-assistant' ) . '&nbsp;' . __( 'Item', 'media-library-assistant' ),
245
  'rows' => 6,
246
  'help' => __( 'Markup for each lower-level item in the hierarchy; list format only.', 'media-library-assistant' ),
247
+ 'order' => 7,
248
  ),
249
  'child-close' => array(
250
  'label' => __( 'Child', 'media-library-assistant' ) . '&nbsp;' . __( 'Close', 'media-library-assistant' ),
251
  'rows' => 3,
252
  'help' => __( 'Markup for the end of each level in the hierarchy; list format only.', 'media-library-assistant' ),
253
+ 'order' => 8,
254
  ),
255
  'open' => array(
256
  'label' => __( 'Open', 'media-library-assistant' ),
257
  'rows' => 3,
258
  'help' => __( 'Markup for the beginning of the list. List of parameters, e.g., [+selector+], on Documentation tab.', 'media-library-assistant' ),
259
+ 'order' => 3,
260
  ),
261
  'item' => array(
262
  'label' => __( 'Item', 'media-library-assistant' ),
263
  'rows' => 6,
264
  'help' => __( 'Markup for each item/cell in the list.', 'media-library-assistant' ),
265
+ 'order' => 5,
266
  ),
267
  'close' => array(
268
  'label' => __( 'Close', 'media-library-assistant' ),
269
  'rows' => 3,
270
  'help' => __( 'Markup for the end of the list.', 'media-library-assistant' ),
271
+ 'order' => 10,
272
  ),
273
  ),
274
  ),
278
  }
279
 
280
  /**
281
+ * Style and Markup templates.
 
 
282
  *
283
  * @since 2.30
284
+ * @access private
285
+ * @var array $mla_custom_templates {
286
+ * Templates by type. Key $$type is 'markup' or 'style'.
287
+ *
288
+ * @type array $$type {
289
+ * Templates by shortcode. Key $$shortcode_slug is 'gallery', 'tag-cloud' or 'term-list'
290
+ *
291
+ * @type array $$shortcode_slug {
292
+ * Templates by name. Key $$template_name is the template name/slug, which must be unique within type.
293
+ *
294
+ * @type array $$template_name {
295
+ * Template content by section. Key $$section_name is the section name/slug.
296
  *
297
+ * @type string $$section_name HTML markup/CSS styles for the template section.
298
+ * }
299
+ * }
300
+ * }
301
+ * }
302
  */
303
  private static $mla_custom_templates = NULL;
304
 
305
  /**
306
+ * Load style and markup templates to $mla_custom_templates.
307
  *
308
  * @since 2.30
309
  *
310
+ * @return null
311
  */
312
  public static function mla_load_custom_templates() {
313
  if ( empty( MLATemplate_Support::$mla_template_definitions ) ) {
317
  MLATemplate_Support::$mla_custom_templates = NULL;
318
  $default_templates = MLACore::mla_load_template( 'mla-custom-templates.tpl' );
319
 
320
+ // Load the default templates
 
 
321
  if ( is_null( $default_templates ) ) {
322
  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 );
323
  return;
326
  return;
327
  }
328
 
329
+ // Record explicit shortcode assignments, extract the style template description "section"
 
 
330
  $mla_shortcode_slugs = array();
331
+ $mla_descriptions = array();
332
  foreach ( $default_templates as $key => $value ) {
333
  $mla_shortcode_slug = NULL;
334
+ $mla_description = NULL;
335
 
336
  $match_count = preg_match( '#\<!-- mla_shortcode_slug="(.+)" --\>[\r\n]*#', $value, $matches, PREG_OFFSET_CAPTURE );
337
  if ( $match_count == 0 ) {
340
 
341
  if ( $match_count > 0 ) {
342
  $mla_shortcode_slug = $matches[ 1 ][ 0 ];
 
343
  $value = substr_replace( $value, '', $matches[ 0 ][ 1 ], strlen( $matches[ 0 ][ 0 ] ) );
344
+ }
345
+
346
+ if ( !empty( $mla_shortcode_slug ) ) {
347
+ $tail = strrpos( $key, '-style' );
348
+ if ( ! ( false === $tail ) ) {
349
+ $mla_shortcode_slugs['style'][ substr( $key, 0, $tail ) ] = $mla_shortcode_slug;
350
  } else {
351
+ $tail = strrpos( $key, '-arguments-markup' );
352
+ if ( ! ( false === $tail ) ) {
353
+ $mla_shortcode_slugs['markup'][ substr( $key, 0, $tail ) ] = $mla_shortcode_slug;
354
+ }
355
  }
356
  }
357
 
358
+ $match_count = preg_match( '#\<!-- mla_description="(.+)" --\>[\r\n]*#', $value, $matches, PREG_OFFSET_CAPTURE );
359
+ if ( $match_count > 0 ) {
360
+ $mla_description = $matches[ 1 ][ 0 ];
361
+ $value = substr_replace( $value, '', $matches[ 0 ][ 1 ], strlen( $matches[ 0 ][ 0 ] ) );
362
+ }
363
+
364
+ if ( empty( $value ) ) {
365
+ unset( $default_templates[ $key ] );
366
+ } else {
367
+ $default_templates[ $key ] = $value;
368
+ //error_log( __LINE__ . " replace default template {$key}, {$mla_shortcode_slug}, {$mla_description} value = " . MLAData::mla_hex_dump( $value ), 0 );
369
+ }
370
+
371
  if ( !empty( $mla_shortcode_slug ) ) {
372
  $tail = strrpos( $key, '-style' );
373
  if ( ! ( false === $tail ) ) {
379
  }
380
  }
381
  }
382
+
383
+ if ( !empty( $mla_description ) ) {
384
+ $tail = strrpos( $key, '-style' );
385
+ if ( ! ( false === $tail ) ) {
386
+ $mla_descriptions['style'][ substr( $key, 0, $tail ) ] = $mla_description;
387
+ }
388
+ }
389
  }
 
390
 
391
+ // Find the shortcode and template type for array indices
 
 
392
  foreach ( $default_templates as $key => $value ) {
393
  $tail = strrpos( $key, '-style' );
394
  if ( ! ( false === $tail ) ) {
395
+ // If we can't find the shortcode; assume it's ]mla_gallery]
396
+ $shortcode = 'gallery';
397
  $name = substr( $key, 0, $tail );
398
+
399
  if ( isset( $mla_shortcode_slugs['style'][ $name ] ) ) {
400
  // Assign to the declared shortcode
401
+ $shortcode = $mla_shortcode_slugs['style'][ $name ];
 
402
  } else {
403
  // Guess at the shortcode
404
  foreach( MLATemplate_Support::$mla_template_definitions['style'] as $slug => $definition ) {
405
  if ( isset( $definition['default_names'] ) && in_array( $name, $definition['default_names'] ) ) {
406
+ $shortcode = $slug;
 
407
  break;
408
  }
409
  }
410
  }
411
 
412
+ if ( isset( $mla_descriptions['style'][ $name ] ) ) {
413
+ MLATemplate_Support::$mla_custom_templates['style'][ $shortcode ][ $name ]['description'] = $mla_descriptions['style'][ $name ];
 
414
  }
415
 
416
+ MLATemplate_Support::$mla_custom_templates['style'][ $shortcode ][ $name ]['styles'] = $value;
417
  continue;
418
  }
419
 
420
  $tail = strrpos( $key, '-markup' );
421
  if ( ! ( false === $tail ) ) {
422
+ // If we can't find the shortcode; assume it's mla_gallery
423
+ $shortcode = 'gallery';
424
  $name = substr( $key, 0, $tail );
425
 
426
  // Look for explicit assignment
428
  $root = strpos( $name, $root_name );
429
  if ( 0 === $root ) {
430
  $section_name = substr( $name, strlen( $root_name ) + 1 );
 
431
  // Assign to the declared shortcode
432
  MLATemplate_Support::$mla_custom_templates['markup'][ $mla_shortcode_slug ][ $root_name ][ $section_name ] = $value;
433
  $name = NULL;
446
  $tail = strrpos( $name, '-' . $section_name );
447
  if ( ! ( false === $tail ) ) {
448
  $name = substr( $name, 0, $tail );
449
+ MLATemplate_Support::$mla_custom_templates['markup'][ $slug ][ $name ][ $section_name ] = $value;
450
  }
451
  }
452
 
453
  $name = NULL;
454
  break;
455
+ } // matched the default name
456
+ } // foreach default name
457
  }
458
+ } // foreach shortcode
459
+ } // Guess the shortcode
460
 
461
+ // Can't find the shortcode; assume it's [mla_gallery]
462
  if ( $name ) {
463
  foreach( MLATemplate_Support::$mla_template_definitions['markup']['gallery']['sections'] as $section_name => $section_value ) {
464
  $tail = strrpos( $name, '-' . $section_name );
468
  }
469
  }
470
  }
471
+ } // default markup template
472
+ } // foreach default template
473
 
474
+ // Add user-defined Style templates
 
 
 
 
 
475
  $templates = MLACore::mla_get_option( 'style_templates' );
476
  if ( is_array( $templates ) ) {
477
  foreach ( $templates as $name => $value ) {
478
+ // If we can't find the shortcode; assume it's [mla_gallery]
479
+ $shortcode = 'gallery';
480
+
481
+ // Extract the description "section"
482
+ $mla_description = NULL;
483
+ $match_count = preg_match( '#\<!-- mla_description="(.+)" --\>[\r\n]*#', $value, $matches, PREG_OFFSET_CAPTURE );
 
 
 
484
  if ( $match_count > 0 ) {
485
+ $mla_description = $matches[ 1 ][ 0 ];
486
  $value = substr_replace( $value, '', $matches[ 0 ][ 1 ], strlen( $matches[ 0 ][ 0 ] ) );
 
 
 
487
  }
488
 
489
+ // Check for explicit shortcode assignment
490
+ $match_count = preg_match( '#\<!-- mla_shortcode_slug="(.+)" --\>[\r\n]*#', $value, $matches, PREG_OFFSET_CAPTURE );
491
+ if ( $match_count > 0 ) {
492
+ $value = substr_replace( $value, '', $matches[ 0 ][ 1 ], strlen( $matches[ 0 ][ 0 ] ) );
493
+ $shortcode = $matches[ 1 ][ 0 ];
494
+ } else {
495
+ // Guess from content
496
+ foreach( MLATemplate_Support::$mla_template_definitions['style'] as $slug => $definition ) {
497
+ if ( false !== strpos( $value, '.' . $slug ) ) {
498
+ $shortcode = $slug;
499
+ break;
500
+ }
501
  }
502
  }
503
 
504
+ if ( !empty( $mla_description ) ) {
505
+ MLATemplate_Support::$mla_custom_templates['style'][ $shortcode ][ $name ]['description'] = $mla_description;
506
  }
507
+
508
+ MLATemplate_Support::$mla_custom_templates['style'][ $shortcode ][ $name ]['styles'] = $value;
509
  } // foreach $templates
510
  } // is_array
511
 
512
+ // Add user-defined Markup templates
513
  $templates = MLACore::mla_get_option( 'markup_templates' );
514
  if ( is_array( $templates ) ) {
515
  foreach ( $templates as $name => $value ) {
 
 
 
 
 
 
 
 
516
  // Check for explicit assignment
517
  if ( isset( $value['arguments'] ) ) {
518
  $match_count = preg_match( '#mla_shortcode_slug="(.+)"[ \r\n]*#', $value['arguments'], $matches, PREG_OFFSET_CAPTURE );
521
  }
522
 
523
  if ( $match_count > 0 ) {
 
524
  $value['arguments'] = substr_replace( $value['arguments'], '', $matches[ 0 ][ 1 ], strlen( $matches[ 0 ][ 0 ] ) );
525
  if ( empty( $value['arguments'] ) ) {
 
526
  unset( $value['arguments'] );
 
 
527
  }
528
 
529
  MLATemplate_Support::$mla_custom_templates['markup'][ $matches[ 1 ][ 0 ] ][ $name ] = $value;
537
  }
538
 
539
  foreach( MLATemplate_Support::$mla_template_definitions['markup'] as $slug => $definition ) {
540
+ if ( preg_match( '#class=[\'\"]*.*' . $slug . '#', $full_text, $matches ) ) {
541
+ MLATemplate_Support::$mla_custom_templates['markup'][ $slug ][ $name ] = $value;
542
  $name = NULL;
543
  break;
544
  }
553
  }
554
 
555
  /**
556
+ * Fetch style or markup template from $mla_templates.
557
  *
558
  * @since 2.30
559
  *
560
+ * @param string $key Template name.
561
+ * @param string $shortcode Optional. Shortcode slug; 'gallery', 'tag-cloud' or 'term-list'. Default 'gallery'.
562
+ * @param string $type Optional. Template type; 'style' or 'markup'. Default 'style'.
563
+ * @param string $section Optional. Template section. Default '[not supplied]'.
564
+ * @return string Requested template section, if it exists.
565
+ * @return boolean false if template section not found,
566
+ * true if section='[exists]' and template exists.
567
+ * @return null If no templates exist.
568
  */
569
  public static function mla_fetch_custom_template( $key, $shortcode = 'gallery', $type = 'style', $section = '[not supplied]' ) {
570
  //MLACore::mla_debug_add( "<strong>mla_fetch_custom_template( {$key}, {$shortcode}, {$type}, {$section} )</strong> " . __( 'calling parameters', 'media-library-assistant' ), MLACore::MLA_DEBUG_CATEGORY_ANY );
572
  MLACore::mla_debug_add( '<strong>mla_fetch_custom_template()</strong> ' . __( 'no templates exist', 'media-library-assistant' ), MLACore::MLA_DEBUG_CATEGORY_ANY );
573
  return NULL;
574
  }
575
+ //error_log( ' mla_fetch_custom_template mla_custom_templates = ' . var_export( MLATemplate_Support::$mla_custom_templates, true ), 0 );
576
 
577
  if ( array_key_exists( $type, MLATemplate_Support::$mla_custom_templates ) ) {
578
  if ( array_key_exists( $shortcode, MLATemplate_Support::$mla_custom_templates[ $type ] ) ) {
579
  if ( array_key_exists( $key, MLATemplate_Support::$mla_custom_templates[ $type ][ $shortcode ] ) ) {
580
+ if ( '[exists]' == $section ) {
581
+ return true;
582
  }
583
 
584
+ if ( array_key_exists( $section, MLATemplate_Support::$mla_custom_templates[ $type ][ $shortcode ][ $key ] ) ) {
585
+ return MLATemplate_Support::$mla_custom_templates[ $type ][ $shortcode ][ $key ][ $section ];
586
+ } elseif ( 'style' == $type && '[not supplied]' == $section ) {
587
+ return MLATemplate_Support::$mla_custom_templates['style'][ $shortcode ][ $key ]['styles'];
588
  }
589
+
590
+ // No error - not every section is required
591
+ return false;
592
+ } elseif ( '[exists]' == $section ) {
593
  return false;
594
  }
595
  }
600
  }
601
 
602
  /**
603
+ * Get ALL style templates from $mla_custom_templates, including default(s).
604
  *
605
  * @since 2.30
606
  *
607
+ * @param string $shortcode Optional. Shortcode to which the template(s) apply. Default ''.
608
+ * @return array|null Array ( name => value ) for all style templates or null if no templates.
 
609
  */
610
  public static function mla_get_style_templates( $shortcode = '' ) {
611
  if ( ! is_array( MLATemplate_Support::$mla_custom_templates ) ) {
634
  *
635
  * @since 2.30
636
  *
637
+ * @param array $templates Array ( name => value ) for all user-defined style templates.
638
+ * @return boolean true if success, false if failure.
639
  */
640
  public static function mla_put_style_templates( $templates ) {
641
+ $new_templates = array();
642
+ foreach ( $templates as $name => $sections ) {
643
+ $styles = $sections['styles'];
644
+
645
+ // Embed description in the styles for backward compatibility
646
+ if ( isset( $sections['description'] ) ) {
647
+ $styles = sprintf( "<!-- mla_description=\"%1\$s\" -->\r\n%2\$s", $sections['description'], $styles );
648
+ }
649
+
650
+ $new_templates[ $name ] = $styles;
651
+ }
652
+
653
+ if ( MLACore::mla_update_option( 'style_templates', $new_templates ) ) {
654
  MLATemplate_Support::mla_load_custom_templates();
655
  return true;
656
  }
659
  }
660
 
661
  /**
662
+ * Get ALL markup templates from $mla_custom_templates, including default(s).
663
  *
664
  * @since 2.30
665
  *
666
+ * @param string $shortcode Optional. Shortcode to which the template(s) apply. Default 'gallery'.
667
+ * @return array|null Array ( name => value ) for all markup templates or null if no templates.
 
668
  */
669
  public static function mla_get_markup_templates( $shortcode = '' ) {
670
  if ( ! is_array( MLATemplate_Support::$mla_custom_templates ) ) {
693
  *
694
  * @since 2.30
695
  *
696
+ * @param array $templates Array ( name => value ) for all user-defined markup templates.
697
+ * @return boolean true if success, false if failure.
698
  */
699
  public static function mla_put_markup_templates( $templates ) {
700
  if ( MLACore::mla_update_option( 'markup_templates', $templates ) ) {
includes/class-mla-thumbnail-generation.php CHANGED
@@ -10,7 +10,7 @@
10
 
11
  /**
12
  * Class MLA (Media Library Assistant) Thumbnails provides support for
13
- * Featured IMage generation
14
  *
15
  * @package Media Library Assistant
16
  * @since 2.13
@@ -195,10 +195,83 @@ class MLA_Thumbnail {
195
  return $item_content;
196
  } // mla_list_table_begin_bulk_action
197
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
  /**
199
  * Process an MLA_List_Table custom bulk action
200
  *
201
- * Creates new items from the "Bulk Translate" list.
202
  *
203
  * @since 2.13
204
  *
@@ -270,9 +343,19 @@ class MLA_Thumbnail {
270
  return array( 'message' => sprintf( __( '%1$s: %2$sthumbnail generation failed', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $item_prefix ) . ' - ' . $results['error'] );
271
  }
272
 
273
- /*
274
- * Adjust the file name for the new item
275
- */
 
 
 
 
 
 
 
 
 
 
276
  $pathinfo = pathinfo( $results['name'] );
277
 
278
  if ( isset( self::$bulk_action_options['suffix'] ) ) {
@@ -319,7 +402,7 @@ class MLA_Thumbnail {
319
  // Make sure that this file is included, as wp_generate_attachment_metadata() depends on it.
320
  require_once( ABSPATH . 'wp-admin/includes/image.php' );
321
 
322
- // Generate the metadata for the attachment, and update the database record.
323
  $item_data = wp_generate_attachment_metadata( $item_id, $results['file']);
324
  wp_update_attachment_metadata( $item_id, $item_data );
325
 
@@ -418,11 +501,24 @@ class MLA_Thumbnail {
418
  */
419
  $page_template_array = MLACore::mla_load_template( 'mla-thumbnail-generation.tpl' );
420
  if ( ! is_array( $page_template_array ) ) {
421
- error_log( 'ERROR: mla-thumbnail-generation.tpl path = ' . var_export( plugin_dir_path( __FILE__ ) . 'mla-thumbnail-generation.tpl', true ), 0 );
422
- error_log( 'ERROR: mla-thumbnail-generation.tpl non-array result = ' . var_export( $page_template_array, true ), 0 );
423
  return $html_markup;
424
  }
425
 
 
 
 
 
 
 
 
 
 
 
 
 
 
426
  $page_values = array(
427
  'colspan' => $item_values['colspan'],
428
  'Generate Thumbnails' => __( 'Generate Thumbnails', 'media-library-assistant' ),
@@ -434,6 +530,10 @@ class MLA_Thumbnail {
434
  'Resolution' => __( 'Resolution', 'media-library-assistant' ),
435
  'Quality' => __( 'Quality', 'media-library-assistant' ),
436
  'Type' => __( 'Type', 'media-library-assistant' ),
 
 
 
 
437
  'Existing Items' => __( 'Existing Items', 'media-library-assistant' ),
438
  'Keep' => __( 'Keep', 'media-library-assistant' ),
439
  'Ignore' => __( 'Ignore', 'media-library-assistant' ),
@@ -444,7 +544,6 @@ class MLA_Thumbnail {
444
  'Options' => __( 'Options', 'media-library-assistant' ),
445
  'Clear Filter-by' => __( 'Clear Filter-by', 'media-library-assistant' ),
446
  'Cancel' => __( 'Cancel', 'media-library-assistant' ),
447
- // 'Generate Thumbnails' => __( 'Generate Thumbnails', 'media-library-assistant' ),
448
  );
449
  $parse_value = MLAData::mla_parse_template( $page_template_array['page'], $page_values );
450
 
10
 
11
  /**
12
  * Class MLA (Media Library Assistant) Thumbnails provides support for
13
+ * Featured Image generation
14
  *
15
  * @package Media Library Assistant
16
  * @since 2.13
195
  return $item_content;
196
  } // mla_list_table_begin_bulk_action
197
 
198
+ /**
199
+ * Generate WordPress-style (4.7+) thumbnail image
200
+ *
201
+ * Adapted from /wp-admin/includes/image.php function wp_generate_attachment_metadata()
202
+ *
203
+ * @since 2.40
204
+ *
205
+ * @param string $post_id ID of the source item
206
+ * @param string $file Source file path and name
207
+ * @param array $args Image file information, based on $_FILE in PHP uploads
208
+ *
209
+ * @return array Sizes specifications for attachment metadata
210
+ */
211
+ private static function _generate_wordpress_thumbnail( $post_id, $file, $args ) {
212
+ // Get the metadata for the original (PDF) attachment.
213
+ $item_data = wp_get_attachment_metadata( $post_id );
214
+
215
+ $fallback_sizes = array(
216
+ 'thumbnail',
217
+ 'medium',
218
+ 'large',
219
+ );
220
+
221
+ // Filters the image sizes generated for non-image mime types.
222
+ $fallback_sizes = apply_filters( 'fallback_intermediate_image_sizes', $fallback_sizes, $item_data );
223
+
224
+ $sizes = array();
225
+ foreach ( $fallback_sizes as $s ) {
226
+ $sizes[$s]['width'] = get_option( "{$s}_size_w" );
227
+ $sizes[$s]['height'] = get_option( "{$s}_size_h" );
228
+
229
+ // Force thumbnails to be soft crops.
230
+ if ( ! 'thumbnail' === $s ) {
231
+ $sizes[$s]['crop'] = get_option( "{$s}_crop" );
232
+ }
233
+ }
234
+
235
+ // Adjust the file name for the new item
236
+ $args['name'] = pathinfo( $args['name'], PATHINFO_FILENAME ) . '.jpg';
237
+
238
+ $overrides = array( 'test_form' => false, 'test_size' => true, 'test_upload' => true, );
239
+
240
+ // Add the thumbnails to the same directory as the original PDF file
241
+ $match_count = preg_match( '#/(\d\d\d\d/\d\d)/#', $file, $matches );
242
+ if ( $match_count ) {
243
+ $subdir = $matches[1];
244
+ } else {
245
+ $subdir = NULL;
246
+ }
247
+
248
+ // move the temporary file into the uploads directory
249
+ $results = wp_handle_sideload( $args, $overrides, $subdir );
250
+
251
+ $editor = wp_get_image_editor( $results['file'] );
252
+ if ( is_wp_error( $editor ) ) {
253
+ return implode( ',', $editor->get_error_messages() );
254
+ }
255
+
256
+ $results = $editor->multi_resize( $sizes );
257
+ $results['full'] = array(
258
+ 'file' => $args['name'],
259
+ 'width' => $args['width'],
260
+ 'height' => $args['height'],
261
+ 'mime-type' => $args['type'],
262
+ );
263
+
264
+ // Update the metadata for the original (PDF) attachment.
265
+ $item_data['sizes'] = $results;
266
+ wp_update_attachment_metadata( $post_id, $item_data );
267
+
268
+ return true;
269
+ } // _generate_wordpress_thumbnail
270
+
271
  /**
272
  * Process an MLA_List_Table custom bulk action
273
  *
274
+ * Creates new items from the "Bulk Thumbnail" list.
275
  *
276
  * @since 2.13
277
  *
343
  return array( 'message' => sprintf( __( '%1$s: %2$sthumbnail generation failed', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $item_prefix ) . ' - ' . $results['error'] );
344
  }
345
 
346
+ if ( 'WordPress' === self::$bulk_action_options['type'] ) {
347
+ $results = self::_generate_wordpress_thumbnail( $post_id, $file, $results );
348
+
349
+ if ( true === $results ) {
350
+ /* translators: 1: Item post ID */
351
+ return array( 'message' => sprintf( __( '%1$sWordPress-style thumbnail generated.', 'media-library-assistant' ), $item_prefix ) );
352
+ }
353
+
354
+ /* translators: 1: ERROR tag 2: Item post ID */
355
+ return array( 'message' => sprintf( __( '%1$s: %2$sthumbnail generation failed', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $item_prefix ) . ' - ' . $results );
356
+ }
357
+
358
+ // Adjust the file name for the new item
359
  $pathinfo = pathinfo( $results['name'] );
360
 
361
  if ( isset( self::$bulk_action_options['suffix'] ) ) {
402
  // Make sure that this file is included, as wp_generate_attachment_metadata() depends on it.
403
  require_once( ABSPATH . 'wp-admin/includes/image.php' );
404
 
405
+ // Update the metadata for the original (PDF) attachment.
406
  $item_data = wp_generate_attachment_metadata( $item_id, $results['file']);
407
  wp_update_attachment_metadata( $item_id, $item_data );
408
 
501
  */
502
  $page_template_array = MLACore::mla_load_template( 'mla-thumbnail-generation.tpl' );
503
  if ( ! is_array( $page_template_array ) ) {
504
+ MLACore::mla_debug_add( 'ERROR: mla-thumbnail-generation.tpl path = ' . var_export( plugin_dir_path( __FILE__ ) . 'mla-thumbnail-generation.tpl', true ), MLACore::MLA_DEBUG_CATEGORY_ANY );
505
+ MLACore::mla_debug_add( 'ERROR: mla-thumbnail-generation.tpl non-array result = ' . var_export( $page_template_array, true ), MLACore::MLA_DEBUG_CATEGORY_ANY );
506
  return $html_markup;
507
  }
508
 
509
+ // WordPress thumbnail generation began in version 4.7
510
+ if ( version_compare( get_bloginfo('version'), '4.6.9', '>' ) ) {
511
+ $wp_style = '';
512
+ $wp_checked = 'checked="checked"';
513
+ $jpg_checked = '';
514
+ $wp_help = __( 'Type &ldquo;WP&rdquo; generates native WordPress thumbnails without creating a separate image item.', 'media-library-assistant' );
515
+ } else {
516
+ $wp_style = 'style="display: none"';
517
+ $wp_checked = '';
518
+ $jpg_checked = 'checked="checked"';
519
+ $wp_help = '';
520
+ }
521
+
522
  $page_values = array(
523
  'colspan' => $item_values['colspan'],
524
  'Generate Thumbnails' => __( 'Generate Thumbnails', 'media-library-assistant' ),
530
  'Resolution' => __( 'Resolution', 'media-library-assistant' ),
531
  'Quality' => __( 'Quality', 'media-library-assistant' ),
532
  'Type' => __( 'Type', 'media-library-assistant' ),
533
+ 'WP Style' => $wp_style,
534
+ 'WP Checked' => $wp_checked,
535
+ 'JPG Checked' => $jpg_checked,
536
+ 'WP Help' => $wp_help,
537
  'Existing Items' => __( 'Existing Items', 'media-library-assistant' ),
538
  'Keep' => __( 'Keep', 'media-library-assistant' ),
539
  'Ignore' => __( 'Ignore', 'media-library-assistant' ),
544
  'Options' => __( 'Options', 'media-library-assistant' ),
545
  'Clear Filter-by' => __( 'Clear Filter-by', 'media-library-assistant' ),
546
  'Cancel' => __( 'Cancel', 'media-library-assistant' ),
 
547
  );
548
  $parse_value = MLAData::mla_parse_template( $page_template_array['page'], $page_values );
549
 
includes/class-mla-upload-list-table.php DELETED
@@ -1,794 +0,0 @@
1
- <?php
2
- /**
3
- * Media Library Assistant extended List Table class
4
- *
5
- * @package Media Library Assistant
6
- * @since 1.40
7
- */
8
-
9
- /*
10
- * The WP_List_Table class isn't automatically available to plugins
11
- */
12
- if ( !class_exists( 'WP_List_Table' ) ) {
13
- require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
14
- }
15
-
16
- /**
17
- * Class MLA (Media Library Assistant) Upload List Table implements the "Upload" admin settings tab
18
- *
19
- * Extends the core WP_List_Table class.
20
- *
21
- * @package Media Library Assistant
22
- * @since 1.40
23
- */
24
- class MLA_Upload_List_Table extends WP_List_Table {
25
- /*
26
- * These arrays define the table columns.
27
- */
28
-
29
- /**
30
- * Table column definitions
31
- *
32
- * This array defines table columns and titles where the key is the column slug (and class)
33
- * and the value is the column's title text.
34
- *
35
- * All of the columns are added to this array by MLA_Upload_List_Table::mla_admin_init_action.
36
- *
37
- * @since 1.40
38
- *
39
- * @var array
40
- */
41
- private static $default_columns = array();
42
-
43
- /**
44
- * Default values for hidden columns
45
- *
46
- * This array is used when the user-level option is not set, i.e.,
47
- * the user has not altered the selection of hidden columns.
48
- *
49
- * The value on the right-hand side must match the column slug, e.g.,
50
- * array(0 => 'ID_parent, 1 => 'title_name').
51
- *
52
- * @since 1.40
53
- *
54
- * @var array
55
- */
56
- private static $default_hidden_columns = array(
57
- // 'name',
58
- // 'mime_type',
59
- 'icon_type',
60
- // 'source',
61
- // 'status',
62
- 'core_type',
63
- 'mla_type',
64
- 'standard_source',
65
- 'core_icon_type',
66
- 'description'
67
- );
68
-
69
- /**
70
- * Sortable column definitions
71
- *
72
- * This array defines the table columns that can be sorted. The array key
73
- * is the column slug that needs to be sortable, and the value is database column
74
- * to sort by. Often, the key and value will be the same, but this is not always
75
- * the case (as the value is a column name from the database, not the list table).
76
- *
77
- * The array value also contains a boolean which is 'true' if the data is currently
78
- * sorted by that column. This is computed each time the table is displayed.
79
- *
80
- * @since 1.40
81
- *
82
- * @var array
83
- */
84
- private static $default_sortable_columns = array(
85
- 'name' => array('slug',false),
86
- 'mime_type' => array('mime_type',false),
87
- 'icon_type' => array('icon_type',false),
88
- 'source' => array('source',false),
89
- 'status' => array('disabled',false),
90
- 'core_type' => array('core_type',false),
91
- 'mla_type' => array('mla_type',false),
92
- 'standard_source' => array('standard_source',false),
93
- 'core_icon_type' => array('core_icon_type',false),
94
- 'description' => array('description',false)
95
- );
96
-
97
- /**
98
- * Access the default list of hidden columns
99
- *
100
- * @since 1.40
101
- *
102
- * @return array default list of hidden columns
103
- */
104
- private static function _default_hidden_columns( ) {
105
- return self::$default_hidden_columns;
106
- }
107
-
108
- /**
109
- * Return the names and display values of the sortable columns
110
- *
111
- * @since 1.40
112
- *
113
- * @return array name => array( orderby value, heading ) for sortable columns
114
- */
115
- public static function mla_get_sortable_columns( ) {
116
- $results = array() ;
117
-
118
- foreach ( self::$default_sortable_columns as $key => $value ) {
119
- $value[1] = self::$default_columns[ $key ];
120
- $results[ $key ] = $value;
121
- }
122
-
123
- return $results;
124
- }
125
-
126
- /**
127
- * Handler for filter 'get_user_option_managesettings_page_mla-settings-menu-uploadcolumnshidden'
128
- *
129
- * Required because the screen.php get_hidden_columns function only uses
130
- * the get_user_option result. Set when the file is loaded because the object
131
- * is not created in time for the call from screen.php.
132
- *
133
- * @since 1.40
134
- *
135
- * @param mixed false or array with current list of hidden columns, if any
136
- * @param string 'managesettings_page_mla-settings-menucolumnshidden'
137
- * @param object WP_User object, if logged in
138
- *
139
- * @return array updated list of hidden columns
140
- */
141
- public static function mla_manage_hidden_columns_filter( $result, $option, $user_data ) {
142
- return $result ? $result : self::_default_hidden_columns();
143
- }
144
-
145
- /**
146
- * Handler for filter 'manage_settings_page_mla-settings-menu_columns'
147
- *
148
- * This required filter dictates the table's columns and titles. Set when the
149
- * file is loaded because the list_table object isn't created in time
150
- * to affect the "screen options" setup.
151
- *
152
- * @since 1.40
153
- *
154
- * @return array list of table columns
155
- */
156
- public static function mla_manage_columns_filter( ) {
157
- /*
158
- * For WP 4.3+ icon will be merged with the Extension/name column
159
- */
160
- if ( MLATest::$wp_4dot3_plus ) {
161
- unset( self::$default_columns['icon'] );
162
- }
163
-
164
- return self::$default_columns;
165
- }
166
-
167
- /**
168
- * Builds the $default_columns array with translated source texts.
169
- *
170
- * Called from MLATest::initialize because the $default_columns information might be
171
- * accessed from "front end" posts/pages.
172
- *
173
- * @since 1.71
174
- *
175
- * @return void
176
- */
177
- public static function mla_localize_default_columns_array( ) {
178
- /*
179
- * Build the default columns array at runtime to accomodate calls to the localization functions
180
- */
181
- self::$default_columns = array(
182
- 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
183
- 'icon' => '',
184
- 'name' => _x( 'Extension', 'list_table_column', 'media-library-assistant' ),
185
- 'mime_type' => _x( 'MIME Type', 'list_table_column', 'media-library-assistant' ),
186
- 'icon_type' => _x( 'Icon Type', 'list_table_column', 'media-library-assistant' ),
187
- 'source' => _x( 'Source', 'list_table_column', 'media-library-assistant' ),
188
- 'status' => _x( 'Status', 'list_table_column', 'media-library-assistant' ),
189
- 'core_type' => _x( 'WordPress Type', 'list_table_column', 'media-library-assistant' ),
190
- 'mla_type' => _x( 'MLA Type', 'list_table_column', 'media-library-assistant' ),
191
- 'standard_source' => _x( 'Std. Source', 'list_table_column', 'media-library-assistant' ),
192
- 'core_icon_type' => _x( 'Std. Icon Type', 'list_table_column', 'media-library-assistant' ),
193
- 'description' => _x( 'Description', 'list_table_column', 'media-library-assistant' )
194
- );
195
- }
196
-
197
- /**
198
- * Print optional in-lne styles for Uploads submenu table
199
- *
200
- * @since 2.14
201
- */
202
- public static function mla_admin_print_styles_action() {
203
- if ( MLATest::$wp_4dot3_plus ) {
204
- echo "<style type='text/css'>\n";
205
-
206
- // Any icon_type will do
207
- $image_info = MLAMime::mla_get_icon_type_size( 'image' );
208
-
209
- /*
210
- * Primary column including icon and some margin
211
- */
212
- $icon_width = ( $image_info['width'] + 10 ) . 'px';
213
- $icon_height = ( $image_info['height'] + 5 ) . 'px';
214
-
215
- echo " table.upload_types td.column-primary {\n";
216
- echo " position: relative;\n";
217
- echo " }\n";
218
- echo " table.upload_types div.upload_types-icon {\n";
219
- echo " position: absolute;\n";
220
- echo " top: 8px;\n";
221
- echo " left: 10px;\n";
222
- echo " }\n";
223
- echo " table.upload_types div.upload_types-info {\n";
224
- echo " margin-left: {$icon_width};\n";
225
- echo " min-height: {$icon_height};\n";
226
- echo " }\n";
227
-
228
- echo "</style>\n";
229
- }
230
- }
231
-
232
- /**
233
- * Called in the admin_init action because the list_table object isn't
234
- * created in time to affect the "screen options" setup.
235
- *
236
- * @since 1.40
237
- *
238
- * @return void
239
- */
240
- public static function mla_admin_init_action( ) {
241
- if ( isset( $_REQUEST['mla-optional-uploads-display'] ) || isset( $_REQUEST['mla-optional-uploads-search'] ) ) {
242
- return;
243
- }
244
-
245
- if ( isset( $_REQUEST['mla_tab'] ) && $_REQUEST['mla_tab'] == 'upload' ) {
246
- add_filter( 'get_user_option_managesettings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-uploadcolumnshidden', 'MLA_Upload_list_Table::mla_manage_hidden_columns_filter', 10, 3 );
247
- add_filter( 'manage_settings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-upload_columns', 'MLA_Upload_list_Table::mla_manage_columns_filter', 10, 0 );
248
- add_action( 'admin_print_styles', 'MLA_Upload_List_Table::mla_admin_print_styles_action' );
249
- }
250
- }
251
-
252
- /**
253
- * Initializes some properties from $_REQUEST variables, then
254
- * calls the parent constructor to set some default configs.
255
- *
256
- * @since 1.40
257
- *
258
- * @return void
259
- */
260
- function __construct( ) {
261
- // MLA does not use this
262
- $this->modes = array(
263
- 'list' => __( 'List View' ),
264
- );
265
-
266
- //Set parent defaults
267
- parent::__construct( array(
268
- 'singular' => 'upload_type', //singular name of the listed records
269
- 'plural' => 'upload_types', //plural name of the listed records
270
- 'ajax' => true, //does this table support ajax?
271
- 'screen' => 'settings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-upload'
272
- ) );
273
-
274
- /*
275
- * NOTE: There is one add_action call at the end of this source file.
276
- */
277
- }
278
-
279
- /**
280
- * Checks the current user's permissions
281
- *
282
- * @since 2.14
283
- *
284
- * @return bool
285
- */
286
- public function ajax_user_can() {
287
- return current_user_can('manage_options');
288
- }
289
-
290
- /**
291
- * Get the name of the default primary column.
292
- *
293
- * @since 2.14
294
- * @access protected
295
- *
296
- * @return string Name of the default primary column
297
- */
298
- protected function get_default_primary_column_name() {
299
- return 'name';
300
- }
301
-
302
- /**
303
- * Generate and display row actions links.
304
- *
305
- * @since 2.14
306
- * @access protected
307
- *
308
- * @param object $item Attachment being acted upon.
309
- * @param string $column_name Current column name.
310
- * @param string $primary Primary column name.
311
- * @return string Row actions output for media attachments.
312
- */
313
- protected function handle_row_actions( $item, $column_name, $primary ) {
314
- if ( $primary === $column_name ) {
315
- $actions = $this->row_actions( $this->_build_rollover_actions( $item, $column_name ) );
316
- $actions .= $this->_build_inline_data( $item );
317
- return $actions;
318
- }
319
-
320
- return '';
321
- }
322
-
323
- /**
324
- * Supply a column value if no column-specific function has been defined
325
- *
326
- * Called when the parent class can't find a method specifically built for a
327
- * given column. All columns should have a specific method, so this function
328
- * returns a troubleshooting message.
329
- *
330
- * @since 1.40
331
- *
332
- * @param array A singular item (one full row's worth of data)
333
- * @param array The name/slug of the column to be processed
334
- * @return string Text or HTML to be placed inside the column
335
- */
336
- function column_default( $item, $column_name ) {
337
- //Show the whole array for troubleshooting purposes
338
- /* translators: 1: column_name 2: column_values */
339
- return sprintf( __( 'column_default: %1$s, %2$s', 'media-library-assistant' ), $column_name, print_r( $item, true ) );
340
- }
341
-
342
- /**
343
- * Displays checkboxes for using bulk actions. The 'cb' column
344
- * is given special treatment when columns are processed.
345
- *
346
- * @since 1.40
347
- *
348
- * @param object An MLA upload_type object
349
- * @return string HTML markup to be placed inside the column
350
- */
351
- function column_cb( $item ) {
352
- return sprintf( '<input type="checkbox" name="cb_mla_item_ID[]" value="%1$s" />',
353
- /*%1$s*/ $item->post_ID
354
- );
355
- }
356
-
357
- /**
358
- * Supply the content for a custom column
359
- *
360
- * @since 0.1
361
- *
362
- * @param array A singular attachment (post) object
363
- * @return string HTML markup to be placed inside the column
364
- */
365
- function column_icon( $item ) {
366
- return MLAMime::mla_get_icon_type_image( $item->icon_type );
367
- }
368
-
369
- /**
370
- * Add rollover actions to a table column
371
- *
372
- * @since 1.40
373
- *
374
- * @param object An MLA upload_type object
375
- * @param string Current column name
376
- *
377
- * @return array Names and URLs of row-level actions
378
- */
379
- private function _build_rollover_actions( $item, $column ) {
380
- $actions = array();
381
-
382
- /*
383
- * Compose view arguments
384
- */
385
-
386
- $view_args = array(
387
- 'page' => MLACoreOptions::MLA_SETTINGS_SLUG . '-upload',
388
- 'mla_tab' => 'upload',
389
- 'mla_item_slug' => urlencode( $item->slug )
390
- );
391
-
392
- if ( isset( $_REQUEST['paged'] ) ) {
393
- $view_args['paged'] = $_REQUEST['paged'];
394
- }
395
-
396
- if ( isset( $_REQUEST['order'] ) ) {
397
- $view_args['order'] = $_REQUEST['order'];
398
- }
399
-
400
- if ( isset( $_REQUEST['orderby'] ) ) {
401
- $view_args['orderby'] = $_REQUEST['orderby'];
402
- }
403
-
404
- $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>';
405
-
406
- $actions['inline hide-if-no-js'] = '<a class="editinline" href="#" title="' . __( 'Edit this item inline', 'media-library-assistant' ) . '">' . __( 'Quick Edit', 'media-library-assistant' ) . '</a>';
407
-
408
- if ( 'custom' == $item->source ) {
409
- if ( empty( $item->standard_source ) ) {
410
- $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>';
411
- } else {
412
- $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>';
413
- }
414
- }
415
-
416
- return $actions;
417
- }
418
-
419
- /**
420
- * Add hidden fields with the data for use in the inline editor
421
- *
422
- * @since 1.40
423
- *
424
- * @param object An MLA upload_type object
425
- *
426
- * @return string HTML <div> with row data
427
- */
428
- private function _build_inline_data( $item ) {
429
- $inline_data = "\r\n" . '<div class="hidden" id="inline_' . $item->post_ID . "\">\r\n";
430
- $inline_data .= ' <div class="original_slug">' . esc_attr( $item->slug ) . "</div>\r\n";
431
- $inline_data .= ' <div class="slug">' . esc_attr( $item->slug ) . "</div>\r\n";
432
- $inline_data .= ' <div class="mime_type">' . esc_attr( $item->mime_type ) . "</div>\r\n";
433
- $inline_data .= ' <div class="icon_type">' . esc_attr( $item->icon_type ) . "</div>\r\n";
434
- $inline_data .= ' <div class="core_type">' . esc_attr( $item->core_type ) . "</div>\r\n";
435
- $inline_data .= ' <div class="mla_type">' . esc_attr( $item->mla_type ) . "</div>\r\n";
436
- $inline_data .= ' <div class="source">' . esc_attr( $item->source ) . "</div>\r\n";
437
- $inline_data .= ' <div class="standard_source">' . esc_attr( $item->standard_source ) . "</div>\r\n";
438
- $inline_data .= ' <div class="disabled">' . esc_attr( $item->disabled ) . "</div>\r\n";
439
- $inline_data .= ' <div class="description">' . esc_attr( $item->description ) . "</div>\r\n";
440
- $inline_data .= ' <div class="wp_icon_type">' . esc_attr( $item->wp_icon_type ) . "</div>\r\n";
441
- $inline_data .= ' <div class="mla_icon_type">' . esc_attr( $item->mla_icon_type ) . "</div>\r\n";
442
- $inline_data .= ' <div class="core_icon_type">' . esc_attr( $item->core_icon_type ) . "</div>\r\n";
443
- $inline_data .= "</div>\r\n";
444
- return $inline_data;
445
- }
446
-
447
- /**
448
- * Supply the content for a custom column
449
- *
450
- * @since 1.40
451
- *
452
- * @param object An MLA upload_type object
453
- * @return string HTML markup to be placed inside the column
454
- */
455
- function column_name( $item ) {
456
- if ( MLATest::$wp_4dot3_plus ) {
457
- $content = "<div class=\"upload_types-icon\">\n";
458
- $content .= self::column_icon( $item );
459
- $content .= "\n</div>\n";
460
- $content .= '<div class="upload_types-info">' . esc_attr( $item->slug ) . "</div>\n";
461
- return $content;
462
- }
463
-
464
- $row_actions = self::_build_rollover_actions( $item, 'name' );
465
- $slug = esc_attr( $item->slug );
466
- return sprintf( '%1$s<br>%2$s%3$s', /*%1$s*/ $slug, /*%2$s*/ $this->row_actions( $row_actions ), /*%3$s*/ $this->_build_inline_data( $item ) );
467
- }
468
-
469
- /**
470
- * Supply the content for a custom column
471
- *
472
- * @since 1.40
473
- *
474
- * @param object An MLA upload_type object
475
- * @return string HTML markup to be placed inside the column
476
- */
477
- function column_mime_type( $item ) {
478
- return esc_attr( $item->mime_type );
479
- }
480
-
481
- /**
482
- * Supply the content for a custom column
483
- *
484
- * @since 1.40
485
- *
486
- * @param object An MLA upload_type object
487
- * @return string HTML markup to be placed inside the column
488
- */
489
- function column_icon_type( $item ) {
490
- return esc_attr( $item->icon_type );
491
- }
492
-
493
- /**
494
- * Supply the content for a custom column
495
- *
496
- * @since 1.40
497
- *
498
- * @param object An MLA upload_type object
499
- * @return string HTML markup to be placed inside the column
500
- */
501
- function column_source( $item ) {
502
- return esc_attr( $item->source );
503
- }
504
-
505
- /**
506
- * Supply the content for a custom column
507
- *
508
- * @since 1.40
509
- *
510
- * @param object An MLA upload_type object
511
- * @return string HTML markup to be placed inside the column
512
- */
513
- function column_status( $item ) {
514
- if ( $item->disabled ) {
515
- return __( 'Inactive', 'media-library-assistant' );
516
- } else {
517
- return __( 'Active', 'media-library-assistant' );
518
- }
519
- }
520
-
521
- /**
522
- * Supply the content for a custom column
523
- *
524
- * @since 1.40
525
- *
526
- * @param object An MLA upload_type object
527
- * @return string HTML markup to be placed inside the column
528
- */
529
- function column_core_type( $item ) {
530
- return esc_attr( $item->core_type );
531
- }
532
-
533
- /**
534
- * Supply the content for a custom column
535
- *
536
- * @since 1.40
537
- *
538
- * @param object An MLA upload_type object
539
- * @return string HTML markup to be placed inside the column
540
- */
541
- function column_mla_type( $item ) {
542
- return esc_attr( $item->mla_type );
543
- }
544
-
545
- /**
546
- * Supply the content for a custom column
547
- *
548
- * @since 1.40
549
- *
550
- * @param object An MLA upload_type object
551
- * @return string HTML markup to be placed inside the column
552
- */
553
- function column_standard_source( $item ) {
554
- return (string) $item->standard_source;
555
- }
556
-
557
- /**
558
- * Supply the content for a custom column
559
- *
560
- * @since 1.40
561
- *
562
- * @param object An MLA upload_type object
563
- * @return string HTML markup to be placed inside the column
564
- */
565
- function column_core_icon_type( $item ) {
566
- return esc_attr( $item->core_icon_type );
567
- }
568
-
569
- /**
570
- * Supply the content for a custom column
571
- *
572
- * @since 1.40
573
- *
574
- * @param object An MLA upload_type object
575
- * @return string HTML markup to be placed inside the column
576
- */
577
- function column_description( $item ) {
578
- return esc_attr( $item->description );
579
- }
580
-
581
- /**
582
- * This method dictates the table's columns and titles
583
- *
584
- * @since 1.40
585
- *
586
- * @return array Column information: 'slugs'=>'Visible Titles'
587
- */
588
- function get_columns( ) {
589
- return MLA_Upload_list_Table::mla_manage_columns_filter();
590
- }
591
-
592
- /**
593
- * Returns the list of currently hidden columns from a user option or
594
- * from default values if the option is not set
595
- *
596
- * @since 1.40
597
- *
598
- * @return array Column information,e.g., array(0 => 'ID_parent, 1 => 'title_name')
599
- */
600
- function get_hidden_columns( ) {
601
- $columns = get_user_option( 'managesettings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-uploadcolumnshidden' );
602
-
603
- if ( is_array( $columns ) ) {
604
- return $columns;
605
- }
606
-
607
- return self::_default_hidden_columns();
608
- }
609
-
610
- /**
611
- * Returns an array where the key is the column that needs to be sortable
612
- * and the value is db column to sort by. Also notes the current sort column,
613
- * if set.
614
- *
615
- * @since 1.40
616
- *
617
- * @return array Sortable column information,e.g.,
618
- * 'slugs'=>array('data_values',boolean)
619
- */
620
- function get_sortable_columns( ) {
621
- $columns = self::$default_sortable_columns;
622
-
623
- if ( isset( $_REQUEST['orderby'] ) ) {
624
- $needle = array( $_REQUEST['orderby'], false );
625
- $key = array_search( $needle, $columns );
626
- if ( $key ) {
627
- $columns[ $key ][ 1 ] = true;
628
- }
629
- } else {
630
- $columns['name'][ 1 ] = true;
631
- }
632
-
633
- return $columns;
634
- }
635
-
636
- /**
637
- * Returns HTML markup for one view that can be used with this table
638
- *
639
- * @since 1.40
640
- *
641
- * @param string View slug
642
- * @param array count and labels for the View
643
- * @param string Slug for current view
644
- *
645
- * @return string | false HTML for link to display the view, false if count = zero
646
- */
647
- function _get_view( $view_slug, $upload_item, $current_view ) {
648
- static $base_url = NULL;
649
-
650
- $class = ( $view_slug == $current_view ) ? ' class="current"' : '';
651
-
652
- /*
653
- * Calculate the common values once per page load
654
- */
655
- if ( is_null( $base_url ) ) {
656
- /*
657
- * Remember the view filters
658
- */
659
- $base_url = 'options-general.php?page=' . MLACoreOptions::MLA_SETTINGS_SLUG . '-upload&mla_tab=upload';
660
-
661
- if ( isset( $_REQUEST['s'] ) ) {
662
- $base_url = add_query_arg( array( 's' => $_REQUEST['s'] ), $base_url );
663
- }
664
- }
665
-
666
- $singular = sprintf('%s <span class="count">(%%s)</span>', $upload_item['singular'] );
667
- $plural = sprintf('%s <span class="count">(%%s)</span>', $upload_item['plural'] );
668
- $nooped_plural = _n_noop( $singular, $plural, 'media-library-assistant' );
669
- return "<a href='" . add_query_arg( array( 'mla_upload_view' => $view_slug ), $base_url )
670
- . "'$class>" . sprintf( translate_nooped_plural( $nooped_plural, $upload_item['count'], 'media-library-assistant' ), number_format_i18n( $upload_item['count'] ) ) . '</a>';
671
- } // _get_view
672
-
673
- /**
674
- * Returns an associative array listing all the views that can be used with this table.
675
- * These are listed across the top of the page and managed by WordPress.
676
- *
677
- * @since 1.40
678
- *
679
- * @return array View information,e.g., array ( id => link )
680
- */
681
- function get_views( ) {
682
- /*
683
- * Find current view
684
- */
685
- $current_view = isset( $_REQUEST['mla_upload_view'] ) ? $_REQUEST['mla_upload_view'] : 'all';
686
-
687
- /*
688
- * Generate the list of views, retaining keyword search criterion
689
- */
690
- $s = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
691
- $upload_items = MLAMime::mla_tabulate_upload_items( $s );
692
- $view_links = array();
693
- foreach ( $upload_items as $slug => $item )
694
- $view_links[ $slug ] = self::_get_view( $slug, $item, $current_view );
695
-
696
- return $view_links;
697
- }
698
-
699
- /**
700
- * Get an associative array ( option_name => option_title ) with the list
701
- * of bulk actions available on this table.
702
- *
703
- * @since 1.40
704
- *
705
- * @return array Contains all the bulk actions: 'slugs'=>'Visible Titles'
706
- */
707
- function get_bulk_actions( ) {
708
- $actions = array();
709
-
710
- $actions['edit'] = __( 'Edit', 'media-library-assistant' );
711
- $actions['delete'] = __( 'Delete/Revert Custom', 'media-library-assistant' );
712
-
713
- return $actions;
714
- }
715
-
716
- /**
717
- * Prepares the list of items for displaying
718
- *
719
- * This is where you prepare your data for display. This method will usually
720
- * be used to query the database, sort and filter the data, and generally
721
- * get it ready to be displayed. At a minimum, we should set $this->items and
722
- * $this->set_pagination_args().
723
- *
724
- * @since 1.40
725
- *
726
- * @return void
727
- */
728
- function prepare_items( ) {
729
- $this->_column_headers = array(
730
- $this->get_columns(),
731
- $this->get_hidden_columns(),
732
- $this->get_sortable_columns()
733
- );
734
-
735
- /*
736
- * REQUIRED for pagination.
737
- */
738
- $total_items = MLAMime::mla_count_upload_items( $_REQUEST );
739
- $user = get_current_user_id();
740
- $screen = get_current_screen();
741
- $option = $screen->get_option( 'per_page', 'option' );
742
- if ( is_string( $option ) ) {
743
- $per_page = get_user_meta( $user, $option, true );
744
- } else {
745
- $per_page = 10;
746
- }
747
-
748
- if ( empty( $per_page ) || $per_page < 1 ) {
749
- $per_page = $screen->get_option( 'per_page', 'default' );
750
- }
751
-
752
- /*
753
- * REQUIRED. We also have to register our pagination options & calculations.
754
- */
755
- $this->set_pagination_args( array(
756
- 'total_items' => $total_items,
757
- 'per_page' => $per_page,
758
- 'total_pages' => ceil( $total_items / $per_page )
759
- ) );
760
-
761
- $current_page = $this->get_pagenum();
762
-
763
- /*
764
- * REQUIRED. Assign sorted and paginated data to the items property, where
765
- * it can be used by the rest of the class.
766
- */
767
- $this->items = MLAMime::mla_query_upload_items( $_REQUEST, ( ( $current_page - 1 ) * $per_page ), $per_page );
768
- }
769
-
770
- /**
771
- * Generates (echoes) content for a single row of the table
772
- *
773
- * @since 1.40
774
- *
775
- * @param object the current item
776
- *
777
- * @return void Echoes the row HTML
778
- */
779
- function single_row( $item ) {
780
- static $row_class = '';
781
- $row_class = ( $row_class == '' ? ' class="alternate"' : '' );
782
-
783
- echo '<tr id="upload-' . $item->post_ID . '"' . $row_class . '>';
784
- echo parent::single_row_columns( $item );
785
- echo '</tr>';
786
- }
787
- } // class MLA_Upload_List_Table
788
-
789
- /*
790
- * Actions are added here, when the source file is loaded, because the MLA_Upload_list_Table
791
- * object is created too late to be useful.
792
- */
793
- add_action( 'admin_init', 'MLA_Upload_list_Table::mla_admin_init_action' );
794
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class-mla-upload-optional-list-table.php DELETED
@@ -1,497 +0,0 @@
1
- <?php
2
- /**
3
- * Media Library Assistant extended List Table class
4
- *
5
- * @package Media Library Assistant
6
- * @since 1.40
7
- */
8
-
9
- /*
10
- * The WP_List_Table class isn't automatically available to plugins
11
- */
12
- if ( !class_exists( 'WP_List_Table' ) ) {
13
- require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
14
- }
15
-
16
- /**
17
- * Class MLA (Media Library Assistant) Upload Optional List Table implements the
18
- * searchable database of exension/type associations for the "Uploads" admin settings tab
19
- *
20
- * Extends the core WP_List_Table class.
21
- *
22
- * @package Media Library Assistant
23
- * @since 1.40
24
- */
25
- class MLA_Upload_Optional_List_Table extends WP_List_Table {
26
- /*
27
- * These arrays define the table columns.
28
- */
29
-
30
- /**
31
- * Table column definitions
32
- *
33
- * This array defines table columns and titles where the key is the column slug (and class)
34
- * and the value is the column's title text.
35
- *
36
- * All of the columns are added to this array by MLA_Upload_Optional_List_Table::mla_admin_init_action.
37
- *
38
- * @since 1.40
39
- *
40
- * @var array
41
- */
42
- private static $default_columns = array();
43
-
44
- /**
45
- * Default values for hidden columns
46
- *
47
- * This array is used when the user-level option is not set, i.e.,
48
- * the user has not altered the selection of hidden columns.
49
- *
50
- * The value on the right-hand side must match the column slug, e.g.,
51
- * array(0 => 'ID_parent, 1 => 'title_name').
52
- *
53
- * @since 1.40
54
- *
55
- * @var array
56
- */
57
- private static $default_hidden_columns = array(
58
- // 'name',
59
- // 'mime_type',
60
- // 'core_type',
61
- // 'mla_type',
62
- // 'description'
63
- );
64
-
65
- /**
66
- * Sortable column definitions
67
- *
68
- * This array defines the table columns that can be sorted. The array key
69
- * is the column slug that needs to be sortable, and the value is database column
70
- * to sort by. Often, the key and value will be the same, but this is not always
71
- * the case (as the value is a column name from the database, not the list table).
72
- *
73
- * The array value also contains a boolean which is 'true' if the data is currently
74
- * sorted by that column. This is computed each time the table is displayed.
75
- *
76
- * @since 1.40
77
- *
78
- * @var array
79
- */
80
- private static $default_sortable_columns = array(
81
- 'name' => array('slug',false),
82
- 'mime_type' => array('mime_type',false),
83
- 'core_type' => array('core_type',false),
84
- 'mla_type' => array('mla_type',false),
85
- 'description' => array('description',false)
86
- );
87
-
88
- /**
89
- * Access the default list of hidden columns
90
- *
91
- * @since 1.40
92
- *
93
- * @return array default list of hidden columns
94
- */
95
- private static function _default_hidden_columns( ) {
96
- return self::$default_hidden_columns;
97
- }
98
-
99
- /**
100
- * Return the names and display values of the sortable columns
101
- *
102
- * @since 1.40
103
- *
104
- * @return array name => array( orderby value, heading ) for sortable columns
105
- */
106
- public static function mla_get_sortable_columns( ) {
107
- $results = array() ;
108
-
109
- foreach ( self::$default_sortable_columns as $key => $value ) {
110
- $value[1] = self::$default_columns[ $key ];
111
- $results[ $key ] = $value;
112
- }
113
-
114
- return $results;
115
- }
116
-
117
- /**
118
- * Handler for filter 'get_user_option_managesettings_page_mla-settings-menu-uploadcolumnshidden'
119
- *
120
- * Required because the screen.php get_hidden_columns function only uses
121
- * the get_user_option result. Set when the file is loaded because the object
122
- * is not created in time for the call from screen.php.
123
- *
124
- * @since 1.40
125
- *
126
- * @param mixed false or array with current list of hidden columns, if any
127
- * @param string 'managesettings_page_mla-settings-menucolumnshidden'
128
- * @param object WP_User object, if logged in
129
- *
130
- * @return array updated list of hidden columns
131
- */
132
- public static function mla_manage_hidden_columns_filter( $result, $option, $user_data ) {
133
- return $result ? $result : self::_default_hidden_columns();
134
- }
135
-
136
- /**
137
- * Handler for filter 'manage_settings_page_mla-settings-menu_columns'
138
- *
139
- * This required filter dictates the table's columns and titles. Set when the
140
- * file is loaded because the list_table object isn't created in time
141
- * to affect the "screen options" setup.
142
- *
143
- * @since 1.40
144
- *
145
- * @return array list of table columns
146
- */
147
- public static function mla_manage_columns_filter( ) {
148
- return self::$default_columns;
149
- }
150
-
151
- /**
152
- * Builds the $default_columns array with translated source texts.
153
- *
154
- * Called from MLATest::initialize because the $default_columns information might be
155
- * accessed from "front end" posts/pages.
156
- *
157
- * @since 1.71
158
- *
159
- * @return void
160
- */
161
- public static function mla_localize_default_columns_array( ) {
162
- /*
163
- * Build the default columns array at runtime to accomodate calls to the localization functions
164
- */
165
- self::$default_columns = array(
166
- 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
167
- 'name' => _x( 'Extension', 'list_table_column', 'media-library-assistant' ),
168
- 'mime_type' => _x( 'MIME Type', 'list_table_column', 'media-library-assistant' ),
169
- 'core_type' => _x( 'WordPress Type', 'list_table_column', 'media-library-assistant' ),
170
- 'mla_type' => _x( 'MLA Type', 'list_table_column', 'media-library-assistant' ),
171
- 'description' => _x( 'Description', 'list_table_column', 'media-library-assistant' )
172
- );
173
- }
174
-
175
- /**
176
- * Called in the admin_init action because the list_table object isn't
177
- * created in time to affect the "screen options" setup.
178
- *
179
- * @since 1.40
180
- *
181
- * @return void
182
- */
183
- public static function mla_admin_init_action( ) {
184
- if ( isset( $_REQUEST['mla-optional-uploads-display'] ) || isset( $_REQUEST['mla-optional-uploads-search'] ) ) {
185
- add_filter( 'get_user_option_managesettings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-uploadcolumnshidden', 'MLA_Upload_Optional_List_Table::mla_manage_hidden_columns_filter', 10, 3 );
186
- add_filter( 'manage_settings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-upload_columns', 'MLA_Upload_Optional_List_Table::mla_manage_columns_filter', 10, 0 );
187
- }
188
- }
189
-
190
- /**
191
- * Initializes some properties from $_REQUEST variables, then
192
- * calls the parent constructor to set some default configs.
193
- *
194
- * @since 1.40
195
- *
196
- * @return void
197
- */
198
- function __construct( ) {
199
- //Set parent defaults
200
- parent::__construct( array(
201
- 'singular' => 'optional_upload_type', //singular name of the listed records
202
- 'plural' => 'optional_upload_types', //plural name of the listed records
203
- 'ajax' => false, //does this table support ajax?
204
- 'screen' => 'settings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-upload'
205
- ) );
206
-
207
- /*
208
- * NOTE: There is one add_action call at the end of this source file.
209
- */
210
- }
211
-
212
- /**
213
- * Supply a column value if no column-specific function has been defined
214
- *
215
- * Called when the parent class can't find a method specifically built for a
216
- * given column. All columns should have a specific method, so this function
217
- * returns a troubleshooting message.
218
- *
219
- * @since 1.40
220
- *
221
- * @param array A singular item (one full row's worth of data)
222
- * @param array The name/slug of the column to be processed
223
- * @return string Text or HTML to be placed inside the column
224
- */
225
- function column_default( $item, $column_name ) {
226
- //Show the whole array for troubleshooting purposes
227
- /* translators: 1: column_name 2: column_values */
228
- return sprintf( __( 'column_default: %1$s, %2$s', 'media-library-assistant' ), $column_name, print_r( $item, true ) );
229
- }
230
-
231
- /**
232
- * Displays checkboxes for using bulk actions. The 'cb' column
233
- * is given special treatment when columns are processed.
234
- *
235
- * @since 1.40
236
- *
237
- * @param object An MLA post_mime_type object
238
- * @return string HTML markup to be placed inside the column
239
- */
240
- function column_cb( $item ) {
241
- return sprintf( '<input type="checkbox" name="cb_mla_item_ID[]" value="%1$s" />',
242
- /*%1$s*/ $item->ID
243
- );
244
- }
245
-
246
- /**
247
- * Add rollover actions to a table column
248
- *
249
- * @since 1.40
250
- *
251
- * @param object An MLA post_mime_type object
252
- * @param string Current column name
253
- *
254
- * @return array Names and URLs of row-level actions
255
- */
256
- private function _build_rollover_actions( $item, $column ) {
257
- $actions = array();
258
-
259
- /*
260
- * Compose view arguments
261
- */
262
-
263
- $view_args = array(
264
- 'page' => MLACoreOptions::MLA_SETTINGS_SLUG . '-upload',
265
- 'mla_tab' => 'upload',
266
- 'mla_item_ID' => urlencode( $item->ID )
267
- );
268
-
269
- if ( isset( $_REQUEST['paged'] ) ) {
270
- $view_args['paged'] = $_REQUEST['paged'];
271
- }
272
-
273
- if ( isset( $_REQUEST['order'] ) ) {
274
- $view_args['order'] = $_REQUEST['order'];
275
- }
276
-
277
- if ( isset( $_REQUEST['orderby'] ) ) {
278
- $view_args['orderby'] = $_REQUEST['orderby'];
279
- }
280
-
281
- $actions['select'] = '<a href="' . add_query_arg( $view_args, wp_nonce_url( '?mla_admin_action=' . MLA::MLA_ADMIN_SINGLE_EDIT_UPDATE, MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ) ) . '" title="' . __( 'Select this entry', 'media-library-assistant' ) . '">' . __( 'Select', 'media-library-assistant' ) . '</a>';
282
-
283
- return $actions;
284
- }
285
-
286
- /**
287
- * Supply the content for a custom column
288
- *
289
- * @since 1.40
290
- *
291
- * @param object An MLA post_mime_type object
292
- * @return string HTML markup to be placed inside the column
293
- */
294
- function column_name( $item ) {
295
- $row_actions = self::_build_rollover_actions( $item, 'name' );
296
- $slug = esc_attr( $item->slug );
297
- return sprintf( '%1$s<br>%2$s', /*%1$s*/ $slug, /*%2$s*/ $this->row_actions( $row_actions ) );
298
- }
299
-
300
- /**
301
- * Supply the content for a custom column
302
- *
303
- * @since 1.40
304
- *
305
- * @param object An MLA post_mime_type object
306
- * @return string HTML markup to be placed inside the column
307
- */
308
- function column_mime_type( $item ) {
309
- return esc_attr( $item->mime_type );
310
- }
311
-
312
- /**
313
- * Supply the content for a custom column
314
- *
315
- * @since 1.40
316
- *
317
- * @param object An MLA post_mime_type object
318
- * @return string HTML markup to be placed inside the column
319
- */
320
- function column_core_type( $item ) {
321
- return esc_attr( $item->core_type );
322
- }
323
-
324
- /**
325
- * Supply the content for a custom column
326
- *
327
- * @since 1.40
328
- *
329
- * @param object An MLA post_mime_type object
330
- * @return string HTML markup to be placed inside the column
331
- */
332
- function column_mla_type( $item ) {
333
- return esc_attr( $item->mla_type );
334
- }
335
-
336
- /**
337
- * Supply the content for a custom column
338
- *
339
- * @since 1.40
340
- *
341
- * @param object An MLA post_mime_type object
342
- * @return string HTML markup to be placed inside the column
343
- */
344
- function column_description( $item ) {
345
- return esc_attr( $item->description );
346
- }
347
-
348
- /**
349
- * This method dictates the table's columns and titles
350
- *
351
- * @since 1.40
352
- *
353
- * @return array Column information: 'slugs'=>'Visible Titles'
354
- */
355
- function get_columns( ) {
356
- return $columns = MLA_Upload_Optional_List_Table::mla_manage_columns_filter();
357
- }
358
-
359
- /**
360
- * Returns the list of currently hidden columns from a user option or
361
- * from default values if the option is not set
362
- *
363
- * @since 1.40
364
- *
365
- * @return array Column information,e.g., array(0 => 'ID_parent, 1 => 'title_name')
366
- */
367
- function get_hidden_columns( ) {
368
- $columns = get_user_option( 'managesettings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-uploadcolumnshidden' );
369
-
370
- if ( is_array( $columns ) ) {
371
- return $columns;
372
- }
373
-
374
- return self::_default_hidden_columns();
375
- }
376
-
377
- /**
378
- * Returns an array where the key is the column that needs to be sortable
379
- * and the value is db column to sort by. Also notes the current sort column,
380
- * if set.
381
- *
382
- * @since 1.40
383
- *
384
- * @return array Sortable column information,e.g.,
385
- * 'slugs'=>array('data_values',boolean)
386
- */
387
- function get_sortable_columns( ) {
388
- $columns = self::$default_sortable_columns;
389
-
390
- if ( isset( $_REQUEST['orderby'] ) ) {
391
- $needle = array( $_REQUEST['orderby'], false );
392
- $key = array_search( $needle, $columns );
393
- if ( $key ) {
394
- $columns[ $key ][ 1 ] = true;
395
- }
396
- } else {
397
- $columns['name'][ 1 ] = true;
398
- }
399
-
400
- return $columns;
401
- }
402
-
403
- /**
404
- * Get an associative array ( option_name => option_title ) with the list
405
- * of bulk actions available on this table.
406
- *
407
- * @since 1.40
408
- *
409
- * @return array Contains all the bulk actions: 'slugs'=>'Visible Titles'
410
- */
411
- function get_bulk_actions( ) {
412
- $actions = array();
413
-
414
- $actions['select'] = __( 'Select these entries', 'media-library-assistant' );
415
-
416
- return $actions;
417
- }
418
-
419
- /**
420
- * Prepares the list of items for displaying
421
- *
422
- * This is where you prepare your data for display. This method will usually
423
- * be used to query the database, sort and filter the data, and generally
424
- * get it ready to be displayed. At a minimum, we should set $this->items and
425
- * $this->set_pagination_args().
426
- *
427
- * @since 1.40
428
- *
429
- * @return void
430
- */
431
- function prepare_items( ) {
432
- $this->_column_headers = array(
433
- $this->get_columns(),
434
- $this->get_hidden_columns(),
435
- $this->get_sortable_columns()
436
- );
437
-
438
- /*
439
- * REQUIRED for pagination.
440
- */
441
- $total_items = MLAMime::mla_count_optional_upload_items( $_REQUEST );
442
- $user = get_current_user_id();
443
- $screen = get_current_screen();
444
- $option = $screen->get_option( 'per_page', 'option' );
445
- if ( is_string( $option ) ) {
446
- $per_page = get_user_meta( $user, $option, true );
447
- } else {
448
- $per_page = 10;
449
- }
450
-
451
- if ( empty( $per_page ) || $per_page < 1 ) {
452
- $per_page = $screen->get_option( 'per_page', 'default' );
453
- }
454
-
455
- /*
456
- * REQUIRED. We also have to register our pagination options & calculations.
457
- */
458
- $this->set_pagination_args( array(
459
- 'total_items' => $total_items,
460
- 'per_page' => $per_page,
461
- 'total_pages' => ceil( $total_items / $per_page )
462
- ) );
463
-
464
- $current_page = $this->get_pagenum();
465
-
466
- /*
467
- * REQUIRED. Assign sorted and paginated data to the items property, where
468
- * it can be used by the rest of the class.
469
- */
470
- $this->items = MLAMime::mla_query_optional_upload_items( $_REQUEST, ( ( $current_page - 1 ) * $per_page ), $per_page );
471
- }
472
-
473
- /**
474
- * Generates (echoes) content for a single row of the table
475
- *
476
- * @since 1.40
477
- *
478
- * @param object the current item
479
- *
480
- * @return void Echoes the row HTML
481
- */
482
- function single_row( $item ) {
483
- static $row_class = '';
484
- $row_class = ( $row_class == '' ? ' class="alternate"' : '' );
485
-
486
- echo '<tr id="optional-upload-' . $item->ID . '"' . $row_class . '>';
487
- echo parent::single_row_columns( $item );
488
- echo '</tr>';
489
- }
490
- } // class MLA_Upload_Optional_List_Table
491
-
492
- /*
493
- * Actions are added here, when the source file is loaded, because the MLA_Upload_Optional_List_Table
494
- * object is created too late to be useful.
495
- */
496
- add_action( 'admin_init', 'MLA_Upload_Optional_List_Table::mla_admin_init_action' );
497
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class-mla-view-list-table.php DELETED
@@ -1,650 +0,0 @@
1
- <?php
2
- /**
3
- * Media Library Assistant extended List Table class
4
- *
5
- * @package Media Library Assistant
6
- * @since 1.40
7
- */
8
-
9
- /*
10
- * The WP_List_Table class isn't automatically available to plugins
11
- */
12
- if ( !class_exists( 'WP_List_Table' ) ) {
13
- require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
14
- }
15
-
16
- /**
17
- * Class MLA (Media Library Assistant) View List Table implements the "Views" admin settings tab
18
- *
19
- * Extends the core WP_List_Table class.
20
- *
21
- * @package Media Library Assistant
22
- * @since 1.40
23
- */
24
- class MLA_View_List_Table extends WP_List_Table {
25
- /*
26
- * These arrays define the table columns.
27
- */
28
-
29
- /**
30
- * Table column definitions
31
- *
32
- * This array defines table columns and titles where the key is the column slug (and class)
33
- * and the value is the column's title text.
34
- *
35
- * All of the columns are added to this array by MLA_View_List_Table::mla_admin_init_action.
36
- *
37
- * @since 1.40
38
- *
39
- * @var array
40
- */
41
- private static $default_columns = array();
42
-
43
- /**
44
- * Default values for hidden columns
45
- *
46
- * This array is used when the user-level option is not set, i.e.,
47
- * the user has not altered the selection of hidden columns.
48
- *
49
- * The value on the right-hand side must match the column slug, e.g.,
50
- * array(0 => 'ID_parent, 1 => 'title_name').
51
- *
52
- * @since 1.40
53
- *
54
- * @var array
55
- */
56
- private static $default_hidden_columns = array(
57
- // 'name',
58
- // 'specification',
59
- // 'post_mime_type',
60
- // 'table_view',
61
- 'singular',
62
- // 'plural',
63
- 'menu_order',
64
- 'description'
65
- );
66
-
67
- /**
68
- * Sortable column definitions
69
- *
70
- * This array defines the table columns that can be sorted. The array key
71
- * is the column slug that needs to be sortable, and the value is database column
72
- * to sort by. Often, the key and value will be the same, but this is not always
73
- * the case (as the value is a column name from the database, not the list table).
74
- *
75
- * The array value also contains a boolean which is 'true' if the data is currently
76
- * sorted by that column. This is computed each time the table is displayed.
77
- *
78
- * @since 1.40
79
- *
80
- * @var array
81
- */
82
- private static $default_sortable_columns = array(
83
- 'name' => array('slug',false),
84
- 'specification' => array('specification',false),
85
- 'post_mime_type' => array('post_mime_type',false),
86
- 'table_view' => array('table_view',false),
87
- 'singular' => array('singular',false),
88
- 'plural' => array('plural',false),
89
- 'menu_order' => array('menu_order',false),
90
- 'description' => array('description',false)
91
- );
92
-
93
- /**
94
- * Access the default list of hidden columns
95
- *
96
- * @since 1.40
97
- *
98
- * @return array default list of hidden columns
99
- */
100
- private static function _default_hidden_columns( ) {
101
- return self::$default_hidden_columns;
102
- }
103
-
104
- /**
105
- * Return the names and display values of the sortable columns
106
- *
107
- * @since 1.40
108
- *
109
- * @return array name => array( orderby value, heading ) for sortable columns
110
- */
111
- public static function mla_get_sortable_columns( ) {
112
- $results = array() ;
113
-
114
- foreach ( self::$default_sortable_columns as $key => $value ) {
115
- $value[1] = self::$default_columns[ $key ];
116
- $results[ $key ] = $value;
117
- }
118
-
119
- return $results;
120
- }
121
-
122
- /**
123
- * Handler for filter 'get_user_option_managesettings_page_mla-settings-menu-viewcolumnshidden'
124
- *
125
- * Required because the screen.php get_hidden_columns function only uses
126
- * the get_user_option result. Set when the file is loaded because the object
127
- * is not created in time for the call from screen.php.
128
- *
129
- * @since 1.40
130
- *
131
- * @param mixed false or array with current list of hidden columns, if any
132
- * @param string 'managesettings_page_mla-settings-menucolumnshidden'
133
- * @param object WP_User object, if logged in
134
- *
135
- * @return array updated list of hidden columns
136
- */
137
- public static function mla_manage_hidden_columns_filter( $result, $option, $user_data ) {
138
- return $result ? $result : self::_default_hidden_columns();
139
- }
140
-
141
- /**
142
- * Handler for filter 'manage_settings_page_mla-settings-menu_columns'
143
- *
144
- * This required filter dictates the table's columns and titles. Set when the
145
- * file is loaded because the list_table object isn't created in time
146
- * to affect the "screen options" setup.
147
- *
148
- * @since 1.40
149
- *
150
- * @return array list of table columns
151
- */
152
- public static function mla_manage_columns_filter( ) {
153
- return self::$default_columns;
154
- }
155
-
156
- /**
157
- * Builds the $default_columns array with translated source texts.
158
- *
159
- * Called from MLATest::initialize because the $default_columns information might be
160
- * accessed from "front end" posts/pages.
161
- *
162
- * @since 1.71
163
- *
164
- * @return void
165
- */
166
- public static function mla_localize_default_columns_array( ) {
167
- /*
168
- * Build the default columns array at runtime to accomodate calls to the localization functions
169
- */
170
- self::$default_columns = array(
171
- 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
172
- 'name' => _x( 'Slug', 'list_table_column', 'media-library-assistant' ),
173
- 'specification' => _x( 'Specification', 'list_table_column', 'media-library-assistant' ),
174
- 'post_mime_type' => _x( 'Post Mime', 'list_table_column', 'media-library-assistant' ),
175
- 'table_view' => _x( 'Table View', 'list_table_column', 'media-library-assistant' ),
176
- 'singular' => _x( 'Singular Name', 'list_table_column', 'media-library-assistant' ),
177
- 'plural' => _x( 'Plural Name', 'list_table_column', 'media-library-assistant' ),
178
- 'menu_order' => _x( 'Order', 'list_table_column', 'media-library-assistant' ),
179
- 'description' => _x( 'Description', 'list_table_column', 'media-library-assistant' )
180
- );
181
- }
182
-
183
- /**
184
- * Called in the admin_init action because the list_table object isn't
185
- * created in time to affect the "screen options" setup.
186
- *
187
- * @since 1.40
188
- *
189
- * @return void
190
- */
191
- public static function mla_admin_init_action( ) {
192
- if ( isset( $_REQUEST['mla_tab'] ) && $_REQUEST['mla_tab'] == 'view' ) {
193
- add_filter( 'get_user_option_managesettings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-viewcolumnshidden', 'MLA_View_List_Table::mla_manage_hidden_columns_filter', 10, 3 );
194
- add_filter( 'manage_settings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-view_columns', 'MLA_View_List_Table::mla_manage_columns_filter', 10, 0 );
195
- }
196
- }
197
-
198
- /**
199
- * Initializes some properties from $_REQUEST variables, then
200
- * calls the parent constructor to set some default configs.
201
- *
202
- * @since 1.40
203
- *
204
- * @return void
205
- */
206
- function __construct( ) {
207
- // MLA does not use this
208
- $this->modes = array(
209
- 'list' => __( 'List View' ),
210
- );
211
-
212
- //Set parent defaults
213
- parent::__construct( array(
214
- 'singular' => 'post_mime_type', //singular name of the listed records
215
- 'plural' => 'post_mime_types', //plural name of the listed records
216
- 'ajax' => true, //does this table support ajax?
217
- 'screen' => 'settings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-view'
218
- ) );
219
-
220
- /*
221
- * NOTE: There is one add_action call at the end of this source file.
222
- */
223
- }
224
-
225
- /**
226
- * Checks the current user's permissions
227
- *
228
- * @since 2.14
229
- *
230
- * @return bool
231
- */
232
- public function ajax_user_can() {
233
- return current_user_can('manage_options');
234
- }
235
-
236
- /**
237
- * Get the name of the default primary column.
238
- *
239
- * @since 2.14
240
- * @access protected
241
- *
242
- * @return string Name of the default primary column
243
- */
244
- protected function get_default_primary_column_name() {
245
- return 'name';
246
- }
247
-
248
- /**
249
- * Generate and display row actions links.
250
- *
251
- * @since 2.14
252
- * @access protected
253
- *
254
- * @param object $item Attachment being acted upon.
255
- * @param string $column_name Current column name.
256
- * @param string $primary Primary column name.
257
- * @return string Row actions output for media attachments.
258
- */
259
- protected function handle_row_actions( $item, $column_name, $primary ) {
260
- if ( $primary === $column_name ) {
261
- $actions = $this->row_actions( $this->_build_rollover_actions( $item, $column_name ) );
262
- $actions .= $this->_build_inline_data( $item );
263
- return $actions;
264
- }
265
-
266
- return '';
267
- }
268
-
269
- /**
270
- * Supply a column value if no column-specific function has been defined
271
- *
272
- * Called when the parent class can't find a method specifically built for a
273
- * given column. All columns should have a specific method, so this function
274
- * returns a troubleshooting message.
275
- *
276
- * @since 1.40
277
- *
278
- * @param array A singular item (one full row's worth of data)
279
- * @param array The name/slug of the column to be processed
280
- * @return string Text or HTML to be placed inside the column
281
- */
282
- function column_default( $item, $column_name ) {
283
- //Show the whole array for troubleshooting purposes
284
- /* translators: 1: column_name 2: column_values */
285
- return sprintf( __( 'column_default: %1$s, %2$s', 'media-library-assistant' ), $column_name, print_r( $item, true ) );
286
- }
287
-
288
- /**
289
- * Displays checkboxes for using bulk actions. The 'cb' column
290
- * is given special treatment when columns are processed.
291
- *
292
- * @since 1.40
293
- *
294
- * @param object An MLA post_mime_type object
295
- * @return string HTML markup to be placed inside the column
296
- */
297
- function column_cb( $item ) {
298
- return sprintf( '<input type="checkbox" name="cb_mla_item_ID[]" value="%1$s" />',
299
- /*%1$s*/ $item->post_ID
300
- );
301
- }
302
-
303
- /**
304
- * Add rollover actions to a table column
305
- *
306
- * @since 1.40
307
- *
308
- * @param object An MLA post_mime_type object
309
- * @param string Current column name
310
- *
311
- * @return array Names and URLs of row-level actions
312
- */
313
- private function _build_rollover_actions( $item, $column ) {
314
- $actions = array();
315
-
316
- /*
317
- * Compose view arguments
318
- */
319
-
320
- $view_args = array(
321
- 'page' => MLACoreOptions::MLA_SETTINGS_SLUG . '-view',
322
- 'mla_tab' => 'view',
323
- 'mla_item_slug' => urlencode( $item->slug )
324
- );
325
-
326
- if ( isset( $_REQUEST['paged'] ) ) {
327
- $view_args['paged'] = $_REQUEST['paged'];
328
- }
329
-
330
- if ( isset( $_REQUEST['order'] ) ) {
331
- $view_args['order'] = $_REQUEST['order'];
332
- }
333
-
334
- if ( isset( $_REQUEST['orderby'] ) ) {
335
- $view_args['orderby'] = $_REQUEST['orderby'];
336
- }
337
-
338
- /*
339
- * Get the standard and custom types
340
- */
341
- $mla_types = MLACore::mla_get_option( MLACoreOptions::MLA_POST_MIME_TYPES, true );
342
- if ( ! is_array( $mla_types ) ) {
343
- $mla_types = array ();
344
- }
345
-
346
- $custom_types = MLACore::mla_get_option( MLACoreOptions::MLA_POST_MIME_TYPES, false, true );
347
- if ( ! is_array( $custom_types ) ) {
348
- $custom_types = array ();
349
- }
350
-
351
- $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>';
352
-
353
- $actions['inline hide-if-no-js'] = '<a class="editinline" href="#" title="' . __( 'Edit this item inline', 'media-library-assistant' ) . '">' . __( 'Quick Edit', 'media-library-assistant' ) . '</a>';
354
-
355
- if ( isset( $custom_types[ $item->slug ] ) ) {
356
- if ( isset( $mla_types[ $item->slug ] ) ) {
357
- $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>';
358
- } else {
359
- $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>';
360
- }
361
- } // custom type
362
-
363
- return $actions;
364
- }
365
-
366
- /**
367
- * Add hidden fields with the data for use in the inline editor
368
- *
369
- * @since 1.40
370
- *
371
- * @param object An MLA post_mime_type object
372
- *
373
- * @return string HTML <div> with row data
374
- */
375
- private function _build_inline_data( $item ) {
376
- $inline_data = "\r\n" . '<div class="hidden" id="inline_' . $item->post_ID . "\">\r\n";
377
- $inline_data .= ' <div class="original_slug">' . esc_attr( $item->slug ) . "</div>\r\n";
378
- $inline_data .= ' <div class="slug">' . esc_attr( $item->slug ) . "</div>\r\n";
379
- $inline_data .= ' <div class="singular">' . esc_attr( $item->singular ) . "</div>\r\n";
380
- $inline_data .= ' <div class="plural">' . esc_attr( $item->plural ) . "</div>\r\n";
381
- $inline_data .= ' <div class="specification">' . esc_attr( $item->specification ) . "</div>\r\n";
382
- $inline_data .= ' <div class="post_mime_type">' . esc_attr( $item->post_mime_type ) . "</div>\r\n";
383
- $inline_data .= ' <div class="table_view">' . esc_attr( $item->table_view ) . "</div>\r\n";
384
- $inline_data .= ' <div class="menu_order">' . esc_attr( $item->menu_order ) . "</div>\r\n";
385
- $inline_data .= ' <div class="description">' . esc_attr( $item->description ) . "</div>\r\n";
386
- $inline_data .= "</div>\r\n";
387
- return $inline_data;
388
- }
389
-
390
- /**
391
- * Supply the content for a custom column
392
- *
393
- * @since 1.40
394
- *
395
- * @param object An MLA post_mime_type object
396
- * @return string HTML markup to be placed inside the column
397
- */
398
- function column_name( $item ) {
399
- if ( MLATest::$wp_4dot3_plus ) {
400
- return esc_attr( $item->slug );
401
- }
402
-
403
- $row_actions = self::_build_rollover_actions( $item, 'name' );
404
- $slug = esc_attr( $item->slug );
405
- return sprintf( '%1$s<br>%2$s%3$s', /*%1$s*/ $slug, /*%2$s*/ $this->row_actions( $row_actions ), /*%3$s*/ $this->_build_inline_data( $item ) );
406
- }
407
-
408
- /**
409
- * Supply the content for a custom column
410
- *
411
- * @since 1.40
412
- *
413
- * @param object An MLA post_mime_type object
414
- * @return string HTML markup to be placed inside the column
415
- */
416
- function column_specification( $item ) {
417
- return esc_attr( $item->specification );
418
- }
419
-
420
- /**
421
- * Supply the content for a custom column
422
- *
423
- * @since 1.40
424
- *
425
- * @param object An MLA post_mime_type object
426
- * @return string HTML markup to be placed inside the column
427
- */
428
- function column_post_mime_type( $item ) {
429
- if ( $item->post_mime_type ) {
430
- return __( 'Yes', 'media-library-assistant' );
431
- } else {
432
- return __( 'No', 'media-library-assistant' );
433
- }
434
- }
435
-
436
- /**
437
- * Supply the content for a custom column
438
- *
439
- * @since 1.40
440
- *
441
- * @param object An MLA post_mime_type object
442
- * @return string HTML markup to be placed inside the column
443
- */
444
- function column_table_view( $item ) {
445
- if ( $item->table_view ) {
446
- return __( 'Yes', 'media-library-assistant' );
447
- } else {
448
- return __( 'No', 'media-library-assistant' );
449
- }
450
- }
451
-
452
- /**
453
- * Supply the content for a custom column
454
- *
455
- * @since 1.40
456
- *
457
- * @param object An MLA post_mime_type object
458
- * @return string HTML markup to be placed inside the column
459
- */
460
- function column_singular( $item ) {
461
- return esc_attr( $item->singular );
462
- }
463
-
464
- /**
465
- * Supply the content for a custom column
466
- *
467
- * @since 1.40
468
- *
469
- * @param object An MLA post_mime_type object
470
- * @return string HTML markup to be placed inside the column
471
- */
472
- function column_plural( $item ) {
473
- return esc_attr( $item->plural );
474
- }
475
-
476
- /**
477
- * Supply the content for a custom column
478
- *
479
- * @since 1.40
480
- *
481
- * @param object An MLA post_mime_type object
482
- * @return string HTML markup to be placed inside the column
483
- */
484
- function column_menu_order( $item ) {
485
- return (string) $item->menu_order;
486
- }
487
-
488
- /**
489
- * Supply the content for a custom column
490
- *
491
- * @since 1.40
492
- *
493
- * @param object An MLA post_mime_type object
494
- * @return string HTML markup to be placed inside the column
495
- */
496
- function column_description( $item ) {
497
- return esc_attr( $item->description );
498
- }
499
-
500
- /**
501
- * This method dictates the table's columns and titles
502
- *
503
- * @since 1.40
504
- *
505
- * @return array Column information: 'slugs'=>'Visible Titles'
506
- */
507
- function get_columns( ) {
508
- return $columns = MLA_View_List_Table::mla_manage_columns_filter();
509
- }
510
-
511
- /**
512
- * Returns the list of currently hidden columns from a user option or
513
- * from default values if the option is not set
514
- *
515
- * @since 1.40
516
- *
517
- * @return array Column information,e.g., array(0 => 'ID_parent, 1 => 'title_name')
518
- */
519
- function get_hidden_columns( ) {
520
- $columns = get_user_option( 'managesettings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG . '-viewcolumnshidden' );
521
-
522
- if ( is_array( $columns ) ) {
523
- return $columns;
524
- }
525
-
526
- return self::_default_hidden_columns();
527
- }
528
-
529
- /**
530
- * Returns an array where the key is the column that needs to be sortable
531
- * and the value is db column to sort by. Also notes the current sort column,
532
- * if set.
533
- *
534
- * @since 1.40
535
- *
536
- * @return array Sortable column information,e.g.,
537
- * 'slugs'=>array('data_values',boolean)
538
- */
539
- function get_sortable_columns( ) {
540
- $columns = self::$default_sortable_columns;
541
-
542
- if ( isset( $_REQUEST['orderby'] ) ) {
543
- $needle = array( $_REQUEST['orderby'], false );
544
- $key = array_search( $needle, $columns );
545
- if ( $key ) {
546
- $columns[ $key ][ 1 ] = true;
547
- }
548
- } else {
549
- $columns['menu_order'][ 1 ] = true;
550
- }
551
-
552
- return $columns;
553
- }
554
-
555
- /**
556
- * Get an associative array ( option_name => option_title ) with the list
557
- * of bulk actions available on this table.
558
- *
559
- * @since 1.40
560
- *
561
- * @return array Contains all the bulk actions: 'slugs'=>'Visible Titles'
562
- */
563
- function get_bulk_actions( ) {
564
- $actions = array();
565
-
566
- $actions['edit'] = __( 'Edit', 'media-library-assistant' );
567
- $actions['delete'] = __( 'Delete Permanently', 'media-library-assistant' );
568
-
569
- return $actions;
570
- }
571
-
572
- /**
573
- * Prepares the list of items for displaying
574
- *
575
- * This is where you prepare your data for display. This method will usually
576
- * be used to query the database, sort and filter the data, and generally
577
- * get it ready to be displayed. At a minimum, we should set $this->items and
578
- * $this->set_pagination_args().
579
- *
580
- * @since 1.40
581
- *
582
- * @return void
583
- */
584
- function prepare_items( ) {
585
- $this->_column_headers = array(
586
- $this->get_columns(),
587
- $this->get_hidden_columns(),
588
- $this->get_sortable_columns()
589
- );
590
-
591
- /*
592
- * REQUIRED for pagination.
593
- */
594
- $total_items = MLAMime::mla_count_view_items( $_REQUEST );
595
- $user = get_current_user_id();
596
- $screen = get_current_screen();
597
- $option = $screen->get_option( 'per_page', 'option' );
598
- if ( is_string( $option ) ) {
599
- $per_page = get_user_meta( $user, $option, true );
600
- } else {
601
- $per_page = 10;
602
- }
603
-
604
- if ( empty( $per_page ) || $per_page < 1 ) {
605
- $per_page = $screen->get_option( 'per_page', 'default' );
606
- }
607
-
608
- /*
609
- * REQUIRED. We also have to register our pagination options & calculations.
610
- */
611
- $this->set_pagination_args( array(
612
- 'total_items' => $total_items,
613
- 'per_page' => $per_page,
614
- 'total_pages' => ceil( $total_items / $per_page )
615
- ) );
616
-
617
- $current_page = $this->get_pagenum();
618
-
619
- /*
620
- * REQUIRED. Assign sorted and paginated data to the items property, where
621
- * it can be used by the rest of the class.
622
- */
623
- $this->items = MLAMime::mla_query_view_items( $_REQUEST, ( ( $current_page - 1 ) * $per_page ), $per_page );
624
- }
625
-
626
- /**
627
- * Generates (echoes) content for a single row of the table
628
- *
629
- * @since 1.40
630
- *
631
- * @param object the current item
632
- *
633
- * @return void Echoes the row HTML
634
- */
635
- function single_row( $item ) {
636
- static $row_class = '';
637
- $row_class = ( $row_class == '' ? ' class="alternate"' : '' );
638
-
639
- echo '<tr id="view-' . $item->post_ID . '"' . $row_class . '>';
640
- echo parent::single_row_columns( $item );
641
- echo '</tr>';
642
- }
643
- } // class MLA_View_List_Table
644
-
645
- /*
646
- * Actions are added here, when the source file is loaded, because the MLA_View_List_Table
647
- * object is created too late to be useful.
648
- */
649
- add_action( 'admin_init', 'MLA_View_List_Table::mla_admin_init_action' );
650
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class-mla-wpml-shortcode-support.php ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Media Library Assistant WPML Shortcode Support classes, front-end mode
4
+ *
5
+ * This file is conditionally loaded in MLAShortcodes::initialize after a check for WPML presence.
6
+ *
7
+ * @package Media Library Assistant
8
+ * @since 2.40
9
+ */
10
+
11
+ /**
12
+ * Class MLA (Media Library Assistant) WPML Shortcodes provides front-end support for the
13
+ * WPML Multilingual CMS family of plugins, including WPML Media
14
+ *
15
+ * @package Media Library Assistant
16
+ * @since 2.40
17
+ */
18
+ class MLA_WPML_Shortcodes {
19
+ /**
20
+ * Initialization function, similar to __construct()
21
+ *
22
+ * This function contains add_action and add_filter calls.
23
+ *
24
+ * @since 2.40
25
+ *
26
+ * @return void
27
+ */
28
+ public static function initialize() {
29
+ /*
30
+ * Defined in /media-library-assistant/includes/class-mla-shortcode-support.php
31
+ */
32
+ add_filter( 'mla_get_terms_query_arguments', 'MLA_WPML_Shortcodes::mla_get_terms_query_arguments', 10, 1 );
33
+ add_filter( 'mla_get_terms_clauses', 'MLA_WPML_Shortcodes::mla_get_terms_clauses', 10, 1 );
34
+ }
35
+
36
+ /**
37
+ * MLA Tag Cloud Query Arguments
38
+ *
39
+ * Saves [mla_tag_cloud] query parameters for use in MLA_WPML_Shortcodes::mla_get_terms_clauses.
40
+ *
41
+ * @since 2.40
42
+ * @uses MLA_WPML_Shortcodes::$all_query_parameters
43
+ *
44
+ * @param array shortcode arguments merged with attachment selection defaults
45
+ */
46
+ public static function mla_get_terms_query_arguments( $all_query_parameters ) {
47
+ self::$all_query_parameters = $all_query_parameters;
48
+
49
+ return $all_query_parameters;
50
+ } // mla_get_terms_query_arguments
51
+
52
+ /**
53
+ * Save the query arguments
54
+ *
55
+ * @since 2.40
56
+ *
57
+ * @var array
58
+ */
59
+ private static $all_query_parameters = array();
60
+
61
+ /**
62
+ * MLA Tag Cloud Query Clauses
63
+ *
64
+ * Adds language-specific clauses to filter the cloud terms.
65
+ *
66
+ * @since 2.11
67
+ * @uses MLA_WPML_Shortcodes::$all_query_parameters
68
+ *
69
+ * @param array SQL clauses ( 'fields', 'join', 'where', 'order', 'orderby', 'limits' )
70
+ */
71
+ public static function mla_get_terms_clauses( $clauses ) {
72
+ global $wpdb, $sitepress;
73
+
74
+ if ( 'all' != ( $current_language = $sitepress->get_current_language() ) ) {
75
+ $clauses['join'] = preg_replace( '/(^.* AS tt ON t.term_id = tt.term_id)/m', '${1}' . ' JOIN `' . $wpdb->prefix . 'icl_translations` AS icl_t ON icl_t.element_id = tt.term_taxonomy_id', $clauses['join'] );
76
+
77
+ $clauses['where'] .= " AND icl_t.language_code = '" . $current_language . "'";
78
+
79
+ if ( is_string( $query_taxonomies = self::$all_query_parameters['taxonomy'] ) ) {
80
+ $query_taxonomies = array ( $query_taxonomies );
81
+ }
82
+
83
+ $taxonomies = array();
84
+ foreach ( $query_taxonomies as $taxonomy) {
85
+ $taxonomies[] = 'tax_' . $taxonomy;
86
+ }
87
+
88
+ $clauses['where'] .= "AND icl_t.element_type IN ( '" . join( "','", $taxonomies ) . "' )";
89
+ }
90
+
91
+ return $clauses;
92
+ } // mla_get_terms_clauses
93
+ } // Class MLA_WPML_Shortcodes
94
+ ?>
includes/class-mla-wpml-support.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Media Library Assistant WPML Support classes
4
  *
5
  * This file is conditionally loaded in MLA::initialize after a check for WPML presence.
6
  *
@@ -9,8 +9,8 @@
9
  */
10
 
11
  /**
12
- * Class MLA (Media Library Assistant) WPML provides support for the WPML Multilingual CMS
13
- * family of plugins, including WPML Media
14
  *
15
  * @package Media Library Assistant
16
  * @since 2.11
@@ -27,15 +27,9 @@ class MLA_WPML {
27
  */
28
  public static function initialize() {
29
  /*
30
- * The remaining filters are only useful for the admin section; exit in the front-end posts/pages
31
  */
32
  if ( ! is_admin() ) {
33
- /*
34
- * Defined in /media-library-assistant/includes/class-mla-shortcodes.php
35
- */
36
- add_filter( 'mla_get_terms_query_arguments', 'MLA_WPML::mla_get_terms_query_arguments', 10, 1 );
37
- add_filter( 'mla_get_terms_clauses', 'MLA_WPML::mla_get_terms_clauses', 10, 1 );
38
-
39
  return;
40
  }
41
 
@@ -100,67 +94,6 @@ class MLA_WPML {
100
  add_action( 'wpml_media_create_duplicate_attachment', 'MLA_WPML::wpml_media_create_duplicate_attachment', 10, 2 );
101
  }
102
 
103
- /**
104
- * MLA Tag Cloud Query Arguments
105
- *
106
- * Saves [mla_tag_cloud] query parameters for use in MLA_WPML::mla_get_terms_clauses.
107
- *
108
- * @since 2.11
109
- * @uses MLA_WPML::$all_query_parameters
110
- *
111
- * @param array shortcode arguments merged with attachment selection defaults, so every possible parameter is present
112
- *
113
- * @return array updated attachment query arguments
114
- */
115
- public static function mla_get_terms_query_arguments( $all_query_parameters ) {
116
- self::$all_query_parameters = $all_query_parameters;
117
-
118
- return $all_query_parameters;
119
- } // mla_get_terms_query_arguments
120
-
121
- /**
122
- * Save the query arguments
123
- *
124
- * @since 2.11
125
- *
126
- * @var array
127
- */
128
- private static $all_query_parameters = array();
129
-
130
- /**
131
- * MLA Tag Cloud Query Clauses
132
- *
133
- * Adds language-specific clauses to filter the cloud terms.
134
- *
135
- * @since 2.11
136
- *
137
- * @param array SQL clauses ( 'fields', 'join', 'where', 'order', 'orderby', 'limits' )
138
- *
139
- * @return array updated SQL clauses
140
- */
141
- public static function mla_get_terms_clauses( $clauses ) {
142
- global $wpdb, $sitepress;
143
-
144
- if ( 'all' != ( $current_language = $sitepress->get_current_language() ) ) {
145
- $clauses['join'] = preg_replace( '/(^.* AS tt ON t.term_id = tt.term_id)/m', '${1}' . ' JOIN `' . $wpdb->prefix . 'icl_translations` AS icl_t ON icl_t.element_id = tt.term_taxonomy_id', $clauses['join'] );
146
-
147
- $clauses['where'] .= " AND icl_t.language_code = '" . $current_language . "'";
148
-
149
- if ( is_string( $query_taxonomies = self::$all_query_parameters['taxonomy'] ) ) {
150
- $query_taxonomies = array ( $query_taxonomies );
151
- }
152
-
153
- $taxonomies = array();
154
- foreach ( $query_taxonomies as $taxonomy) {
155
- $taxonomies[] = 'tax_' . $taxonomy;
156
- }
157
-
158
- $clauses['where'] .= "AND icl_t.element_type IN ( '" . join( "','", $taxonomies ) . "' )";
159
- }
160
-
161
- return $clauses;
162
- } // mla_get_terms_clauses
163
-
164
  /**
165
  * Add the plugin's admin-mode filter/action handlers
166
  *
1
  <?php
2
  /**
3
+ * Media Library Assistant WPML Support classes, admin mode.
4
  *
5
  * This file is conditionally loaded in MLA::initialize after a check for WPML presence.
6
  *
9
  */
10
 
11
  /**
12
+ * Class MLA (Media Library Assistant) WPML provides admin mode support for the
13
+ * WPML Multilingual CMS family of plugins, including WPML Media
14
  *
15
  * @package Media Library Assistant
16
  * @since 2.11
27
  */
28
  public static function initialize() {
29
  /*
30
+ * These filters are only useful for the admin section; exit in the front-end posts/pages
31
  */
32
  if ( ! is_admin() ) {
 
 
 
 
 
 
33
  return;
34
  }
35
 
94
  add_action( 'wpml_media_create_duplicate_attachment', 'MLA_WPML::wpml_media_create_duplicate_attachment', 10, 2 );
95
  }
96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  /**
98
  * Add the plugin's admin-mode filter/action handlers
99
  *
includes/mla-main-search-box-template.php CHANGED
@@ -43,15 +43,15 @@ if ( empty( $supported_taxonomies ) ) {
43
  <input name="s" id="mla-media-search-input" type="text" size="45" value="<?php echo $search_value ?>" />
44
  <input name="mla-search-submit" class="button" id="search-submit" type="submit" value="<?php _e( 'Search Media', 'media-library-assistant' ); ?>" /><br />
45
  <span <?php echo $controls_style ?>>
46
- <input name="mla_search_connector" type="radio" <?php echo ( 'OR' === $search_connector ) ? '' : 'checked="checked"'; ?> value="AND" /><?php _e( 'and', 'media-library-assistant' ); ?>
47
-
48
- <input name="mla_search_connector" type="radio" <?php echo ( 'OR' === $search_connector ) ? 'checked="checked"' : ''; ?> value="OR" /><?php _e( 'or', 'media-library-assistant' ); ?>
49
-
50
  <input name="mla_search_fields[]" id="search-title" type="checkbox" <?php echo ( in_array( 'title', $search_fields ) ) ? 'checked="checked"' : ''; ?> value="title" /><?php _e( 'Title', 'media-library-assistant' )?>&nbsp;
51
  <input name="mla_search_fields[]" id="search-name" type="checkbox" <?php echo ( in_array( 'name', $search_fields ) ) ? 'checked="checked"' : ''; ?> value="name" /><?php _e( 'Name', 'media-library-assistant' )?>&nbsp;
52
  <input name="mla_search_fields[]" id="search-alt-text" type="checkbox" <?php echo ( in_array( 'alt-text', $search_fields ) ) ? 'checked="checked"' : ''; ?> value="alt-text" /><?php _e( 'ALT Text', 'media-library-assistant' )?>&nbsp;
53
  <input name="mla_search_fields[]" id="search-excerpt" type="checkbox" <?php echo ( in_array( 'excerpt', $search_fields ) ) ? 'checked="checked"' : ''; ?> value="excerpt" /><?php _e( 'Caption', 'media-library-assistant' )?>&nbsp;
54
  <input name="mla_search_fields[]" id="search-content" type="checkbox" <?php echo ( in_array( 'content', $search_fields ) ) ? 'checked="checked"' : ''; ?> value="content" /><?php _e( 'Description', 'media-library-assistant' )?>&nbsp;
 
55
  <span <?php echo $terms_style ?>><input name="mla_search_fields[]" id="terms-search" type="checkbox" <?php echo ( in_array( 'terms', $search_fields ) ) ? 'checked="checked"' : ''; ?> value="terms" /><?php _e( 'Terms', 'media-library-assistant' )?></span>
 
 
 
56
  </span>
57
  </p>
43
  <input name="s" id="mla-media-search-input" type="text" size="45" value="<?php echo $search_value ?>" />
44
  <input name="mla-search-submit" class="button" id="search-submit" type="submit" value="<?php _e( 'Search Media', 'media-library-assistant' ); ?>" /><br />
45
  <span <?php echo $controls_style ?>>
 
 
 
 
46
  <input name="mla_search_fields[]" id="search-title" type="checkbox" <?php echo ( in_array( 'title', $search_fields ) ) ? 'checked="checked"' : ''; ?> value="title" /><?php _e( 'Title', 'media-library-assistant' )?>&nbsp;
47
  <input name="mla_search_fields[]" id="search-name" type="checkbox" <?php echo ( in_array( 'name', $search_fields ) ) ? 'checked="checked"' : ''; ?> value="name" /><?php _e( 'Name', 'media-library-assistant' )?>&nbsp;
48
  <input name="mla_search_fields[]" id="search-alt-text" type="checkbox" <?php echo ( in_array( 'alt-text', $search_fields ) ) ? 'checked="checked"' : ''; ?> value="alt-text" /><?php _e( 'ALT Text', 'media-library-assistant' )?>&nbsp;
49
  <input name="mla_search_fields[]" id="search-excerpt" type="checkbox" <?php echo ( in_array( 'excerpt', $search_fields ) ) ? 'checked="checked"' : ''; ?> value="excerpt" /><?php _e( 'Caption', 'media-library-assistant' )?>&nbsp;
50
  <input name="mla_search_fields[]" id="search-content" type="checkbox" <?php echo ( in_array( 'content', $search_fields ) ) ? 'checked="checked"' : ''; ?> value="content" /><?php _e( 'Description', 'media-library-assistant' )?>&nbsp;
51
+ <input name="mla_search_fields[]" id="search-file" type="checkbox" <?php echo ( in_array( 'file', $search_fields ) ) ? 'checked="checked"' : ''; ?> value="file" /><?php _e( 'File', 'media-library-assistant' )?>&nbsp;
52
  <span <?php echo $terms_style ?>><input name="mla_search_fields[]" id="terms-search" type="checkbox" <?php echo ( in_array( 'terms', $search_fields ) ) ? 'checked="checked"' : ''; ?> value="terms" /><?php _e( 'Terms', 'media-library-assistant' )?></span>
53
+ <br />
54
+ <input name="mla_search_connector" type="radio" <?php echo ( 'OR' === $search_connector ) ? '' : 'checked="checked"'; ?> value="AND" /><?php _e( 'and', 'media-library-assistant' ); ?>&nbsp;
55
+ <input name="mla_search_connector" type="radio" <?php echo ( 'OR' === $search_connector ) ? 'checked="checked"' : ''; ?> value="OR" /><?php _e( 'or', 'media-library-assistant' ); ?>
56
  </span>
57
  </p>
includes/mla-media-modal-js-template.php CHANGED
@@ -55,6 +55,10 @@ if ( empty( $supported_taxonomies ) ) {
55
  <li>
56
  <input type="checkbox" name="s[mla_search_content]" id="search-content" value="content" <# if ( -1 != data.searchFields.indexOf( 'content' ) ) { #>checked<# } #> />
57
  <?php _e( 'Description', 'media-library-assistant' ); ?>
 
 
 
 
58
  </li>
59
  <span <?php echo $terms_style ?>>
60
  <li>
55
  <li>
56
  <input type="checkbox" name="s[mla_search_content]" id="search-content" value="content" <# if ( -1 != data.searchFields.indexOf( 'content' ) ) { #>checked<# } #> />
57
  <?php _e( 'Description', 'media-library-assistant' ); ?>
58
+ </li>
59
+ <li>
60
+ <input type="checkbox" name="s[mla_search_file]" id="search-file" value="file" <# if ( -1 != data.searchFields.indexOf( 'file' ) ) { #>checked<# } #> />
61
+ <?php _e( 'File', 'media-library-assistant' ); ?>
62
  </li>
63
  <span <?php echo $terms_style ?>>
64
  <li>
includes/mla-plugin-loader.php CHANGED
@@ -57,7 +57,7 @@ function mla_plugin_loader_reporting_action () {
57
  */
58
  require_once( MLA_PLUGIN_PATH . 'tests/class-mla-tests.php' );
59
 
60
- $mla_plugin_loader_error_messages .= MLATest::min_php_version( '5.2' );
61
  $mla_plugin_loader_error_messages .= MLATest::min_WordPress_version( '3.5.0' );
62
 
63
  if ( ! empty( $mla_plugin_loader_error_messages ) ) {
@@ -77,12 +77,24 @@ if ( ! empty( $mla_plugin_loader_error_messages ) ) {
77
  add_action( 'init', 'MLACore::initialize', 0x7FFFFFFF );
78
 
79
  /*
80
- * Front end posts/pages only need shortcode support; load the interface shims.
81
  */
82
- if( ! ( ( defined('WP_ADMIN') && WP_ADMIN ) || ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST ) ) ) {
83
- require_once( MLA_PLUGIN_PATH . 'includes/class-mla-shortcodes.php' );
84
- add_action( 'init', 'MLAShortcodes::initialize', 0x7FFFFFFF );
85
- return;
 
 
 
 
 
 
 
 
 
 
 
 
86
  }
87
 
88
  if( defined('DOING_AJAX') && DOING_AJAX ) {
@@ -102,13 +114,22 @@ if ( ! empty( $mla_plugin_loader_error_messages ) ) {
102
  $ajax_exceptions = array_merge( $ajax_exceptions, explode( ',', MLA_AJAX_EXCEPTIONS ) );
103
  }
104
 
105
- $ajax_only = true;
106
  if ( isset( $_REQUEST['action'] ) ) {
107
  if ( in_array( $_REQUEST['action'], $ajax_exceptions ) ) {
108
  $ajax_only = false;
109
  }
110
  }
111
 
 
 
 
 
 
 
 
 
 
112
  //Look for WPML flat taxonomy autocomplete
113
  if ( isset( $_GET['action'] ) && ( 'ajax-tag-search' == $_GET['action'] ) ) {
114
  global $sitepress;
@@ -184,29 +205,5 @@ if ( ! empty( $mla_plugin_loader_error_messages ) ) {
184
  * Doesn't need an initialize function; has a constructor.
185
  */
186
  require_once( MLA_PLUGIN_PATH . 'includes/class-mla-list-table.php' );
187
-
188
- /*
189
- * Custom list table package for the Post MIME Type Views.
190
- * Doesn't need an initialize function; has a constructor.
191
- */
192
- require_once( MLA_PLUGIN_PATH . 'includes/class-mla-view-list-table.php' );
193
-
194
- /*
195
- * Custom list table package for the Optional Upload MIME Type Views.
196
- * Doesn't need an initialize function; has a constructor.
197
- */
198
- require_once( MLA_PLUGIN_PATH . 'includes/class-mla-upload-optional-list-table.php' );
199
-
200
- /*
201
- * Custom list table package for the Upload MIME Type Views.
202
- * Doesn't need an initialize function; has a constructor.
203
- */
204
- require_once( MLA_PLUGIN_PATH . 'includes/class-mla-upload-list-table.php' );
205
-
206
- /*
207
- * Custom list table package for the Example Plugin Views.
208
- * Doesn't need an initialize function; has a constructor.
209
- */
210
- require_once( MLA_PLUGIN_PATH . 'includes/class-mla-example-list-table.php' );
211
  }
212
  ?>
57
  */
58
  require_once( MLA_PLUGIN_PATH . 'tests/class-mla-tests.php' );
59
 
60
+ $mla_plugin_loader_error_messages .= MLATest::min_php_version( '5.4' );
61
  $mla_plugin_loader_error_messages .= MLATest::min_WordPress_version( '3.5.0' );
62
 
63
  if ( ! empty( $mla_plugin_loader_error_messages ) ) {
77
  add_action( 'init', 'MLACore::initialize', 0x7FFFFFFF );
78
 
79
  /*
80
+ * Check for XMLPRC, WP REST API and front end requests
81
  */
82
+ if( !( defined('WP_ADMIN') && WP_ADMIN ) ) {
83
+
84
+ // XMLRPC requests need everything loaded to process uploads
85
+ $front_end_only = !( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST );
86
+
87
+ // WP REST API calls need everything loaded to process uploads
88
+ if ( isset( $_SERVER['REQUEST_URI'] ) && 0 === strpos( $_SERVER['REQUEST_URI'], '/wp-json/' ) ) {
89
+ $front_end_only = false; // TODO be more selective
90
+ }
91
+
92
+ // Front end posts/pages only need shortcode support; load the interface shims.
93
+ if ( $front_end_only ) {
94
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-shortcodes.php' );
95
+ add_action( 'init', 'MLAShortcodes::initialize', 0x7FFFFFFF );
96
+ return;
97
+ }
98
  }
99
 
100
  if( defined('DOING_AJAX') && DOING_AJAX ) {
114
  $ajax_exceptions = array_merge( $ajax_exceptions, explode( ',', MLA_AJAX_EXCEPTIONS ) );
115
  }
116
 
117
+ $ajax_only = true;
118
  if ( isset( $_REQUEST['action'] ) ) {
119
  if ( in_array( $_REQUEST['action'], $ajax_exceptions ) ) {
120
  $ajax_only = false;
121
  }
122
  }
123
 
124
+ //Look for multi-lingual terms updates
125
+ if ( 'mla-update-compat-fields' == $_REQUEST['action'] ) {
126
+ global $sitepress;
127
+
128
+ if ( is_object( $sitepress ) || class_exists( 'Polylang' ) ) {
129
+ $ajax_only = false;
130
+ }
131
+ }
132
+
133
  //Look for WPML flat taxonomy autocomplete
134
  if ( isset( $_GET['action'] ) && ( 'ajax-tag-search' == $_GET['action'] ) ) {
135
  global $sitepress;
205
  * Doesn't need an initialize function; has a constructor.
206
  */
207
  require_once( MLA_PLUGIN_PATH . 'includes/class-mla-list-table.php' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
  }
209
  ?>
index.php CHANGED
@@ -6,7 +6,7 @@
6
  * will the rest of the plugin be loaded and run.
7
  *
8
  * @package Media Library Assistant
9
- * @version 2.33
10
  */
11
 
12
  /*
@@ -16,7 +16,7 @@ Description: Enhances the Media Library; powerful [mla_gallery], taxonomy suppor
16
  Author: David Lingren, Fair Trade Judaica
17
  Text Domain: media-library-assistant
18
  Domain Path: /languages
19
- Version: 2.33
20
  Author URI: http://fairtradejudaica.org/our-story/staff/
21
 
22
  Copyright 2011-2016 David Lingren
6
  * will the rest of the plugin be loaded and run.
7
  *
8
  * @package Media Library Assistant
9
+ * @version 2.40
10
  */
11
 
12
  /*
16
  Author: David Lingren, Fair Trade Judaica
17
  Text Domain: media-library-assistant
18
  Domain Path: /languages
19
+ Version: 2.40
20
  Author URI: http://fairtradejudaica.org/our-story/staff/
21
 
22
  Copyright 2011-2016 David Lingren
js/mla-inline-mapping-scripts.js CHANGED
@@ -29,8 +29,8 @@ var jQuery,
29
  init : function(){
30
  var progressDiv = $( '#mla-progress-div' );
31
 
32
- $('#mla-progress-cancel', progressDiv).off( 'click' );
33
- $('#mla-progress-cancel', progressDiv).click( function(){
34
  if ( mla.bulkMap.inProcess ) {
35
  mla.bulkMap.doCancel = true;
36
  return false;
@@ -39,6 +39,11 @@ var jQuery,
39
  }
40
  });
41
 
 
 
 
 
 
42
  $('#mla-progress-resume', progressDiv).off( 'click' );
43
  $('#mla-progress-resume', progressDiv).click( function(){
44
  var totalItems = +mla.settings.totalItems, newOffset = + $( '#mla-progress-offset' ).val();
@@ -62,8 +67,7 @@ var jQuery,
62
  // Clicking "Refresh" submits the form, refreshing the page
63
  $( '#mla-progress-refresh', progressDiv ).off( 'click' );
64
  $( '#mla-progress-refresh', progressDiv ).click( function(){
65
- $( '#mla-progress-refresh' ).prop( 'disabled', true );
66
- $( '#mla-progress-refresh' ).css( 'opacity', '0.5' );
67
  });
68
 
69
  $('#mla-progress-close', progressDiv).off( 'click' );
@@ -136,7 +140,8 @@ var jQuery,
136
  $( '#mla-progress-div' ).show();
137
 
138
  // Disable "Close" until the bulk mapping is complete
139
- $( '#mla-progress-cancel' ).prop( 'disabled', false ).css( 'opacity', '1.0' );
 
140
  $( '#mla-progress-resume' ).hide();
141
  $( '#mla-progress-offset' ).hide();
142
  $( '#mla-progress-refresh' ).hide();
@@ -265,7 +270,9 @@ var jQuery,
265
  }
266
 
267
  if ( mla.bulkMap.doCancel ) {
268
- message.html( mla.settings.bulkCanceled + '. ' + responseMessage ).show();
 
 
269
  $( '#mla-progress-resume' ).show();
270
  $( '#mla-progress-offset' ).val( mla.bulkMap.complete ).show();
271
  } else {
@@ -282,7 +289,7 @@ var jQuery,
282
  $( '#mla-progress-close' ).prop( 'disabled', false ).css( 'opacity', '1.0' );
283
  }
284
 
285
- $( '#mla-progress-cancel' ).prop( 'disabled', true ).css( 'opacity', '0.5' );
286
  mla.bulkMap.inProcess = false;
287
  }).fail( function( jqXHR, status ) {
288
  if ( 200 == jqXHR.status ) {
29
  init : function(){
30
  var progressDiv = $( '#mla-progress-div' );
31
 
32
+ $('#mla-progress-pause', progressDiv).off( 'click' );
33
+ $('#mla-progress-pause', progressDiv).click( function(){
34
  if ( mla.bulkMap.inProcess ) {
35
  mla.bulkMap.doCancel = true;
36
  return false;
39
  }
40
  });
41
 
42
+ $('#mla-progress-cancel', progressDiv).off( 'click' );
43
+ $('#mla-progress-cancel', progressDiv).click( function(){
44
+ return mla.inlineMapAttachment.revert();
45
+ });
46
+
47
  $('#mla-progress-resume', progressDiv).off( 'click' );
48
  $('#mla-progress-resume', progressDiv).click( function(){
49
  var totalItems = +mla.settings.totalItems, newOffset = + $( '#mla-progress-offset' ).val();
67
  // Clicking "Refresh" submits the form, refreshing the page
68
  $( '#mla-progress-refresh', progressDiv ).off( 'click' );
69
  $( '#mla-progress-refresh', progressDiv ).click( function(){
70
+ $( '#mla-progress-refresh' ).prop( 'disabled', true ).css( 'opacity', '0.5' );
 
71
  });
72
 
73
  $('#mla-progress-close', progressDiv).off( 'click' );
140
  $( '#mla-progress-div' ).show();
141
 
142
  // Disable "Close" until the bulk mapping is complete
143
+ $( '#mla-progress-pause' ).prop( 'disabled', false ).css( 'opacity', '1.0' ).show();
144
+ $( '#mla-progress-cancel' ).hide();
145
  $( '#mla-progress-resume' ).hide();
146
  $( '#mla-progress-offset' ).hide();
147
  $( '#mla-progress-refresh' ).hide();
270
  }
271
 
272
  if ( mla.bulkMap.doCancel ) {
273
+ message.html( mla.settings.bulkPaused + '. ' + responseMessage ).show();
274
+ $( '#mla-progress-pause' ).hide();
275
+ $( '#mla-progress-cancel' ).show();
276
  $( '#mla-progress-resume' ).show();
277
  $( '#mla-progress-offset' ).val( mla.bulkMap.complete ).show();
278
  } else {
289
  $( '#mla-progress-close' ).prop( 'disabled', false ).css( 'opacity', '1.0' );
290
  }
291
 
292
+ $( '#mla-progress-pause' ).prop( 'disabled', true ).css( 'opacity', '0.5' );
293
  mla.bulkMap.inProcess = false;
294
  }).fail( function( jqXHR, status ) {
295
  if ( 200 == jqXHR.status ) {
js/mla-inline-mapping-scripts.min.js CHANGED
@@ -1 +1,325 @@
1
- var jQuery,mla_inline_mapping_vars,mla={settings:{},bulkMap:{inProcess:false,doCancel:false},utility:{},inlineMapAttachment:null};(function(a){mla.settings=typeof mla_inline_mapping_vars==="undefined"?{}:mla_inline_mapping_vars;mla_inline_mapping_vars=void 0;mla.inlineMapAttachment={init:function(){var b=a("#mla-progress-div");a("#mla-progress-cancel",b).off("click");a("#mla-progress-cancel",b).click(function(){if(mla.bulkMap.inProcess){mla.bulkMap.doCancel=true;return false}else{return mla.inlineMapAttachment.revert()}});a("#mla-progress-resume",b).off("click");a("#mla-progress-resume",b).click(function(){var c=+mla.settings.totalItems,d=+a("#mla-progress-offset").val();if(c<d){d=c}else{if(0>d){d=0}}if(mla.bulkMap.inProcess){mla.bulkMap.doCancel=true;return false}else{return mla.inlineMapAttachment.bulkMap(mla.bulkMap.targetName,d)}});a("#mla-progress-refresh",b).off("click");a("#mla-progress-refresh",b).click(function(){a("#mla-progress-refresh").prop("disabled",true);a("#mla-progress-refresh").css("opacity","0.5")});a("#mla-progress-close",b).off("click");a("#mla-progress-close",b).click(function(c){if(mla.bulkMap.inProcess){return false}return mla.inlineMapAttachment.revert()});a('input[type="submit"].mla-mapping').click(function(c){c.preventDefault();return mla.inlineMapAttachment.bulkMap(c.target.name,0)})},bulkMap:function(e,b){var d=0,c=0,g=0,f=0,h=0;b=+b;if(0<b){d=typeof mla.bulkMap.complete==="undefined"?0:mla.bulkMap.complete;c=typeof mla.bulkMap.unchanged==="undefined"?0:mla.bulkMap.unchanged;g=typeof mla.bulkMap.success==="undefined"?0:mla.bulkMap.success;f=typeof mla.bulkMap.skip==="undefined"?0:mla.bulkMap.skip;h=typeof mla.bulkMap.redone==="undefined"?0:mla.bulkMap.redone}if(d<b){f+=b-d}else{if(d>b){h+=d-b}}mla.bulkMap={inProcess:false,doCancel:false,chunkSize:+mla.settings.bulkChunkSize,targetName:e,fields:a(mla.settings.fieldsId+" :input").serialize(),offset:b,waiting:mla.settings.totalItems-b,running:0,complete:b,unchanged:c,success:g,skip:f,redone:h,refresh:false};mla.inlineMapAttachment.progressOpen();mla.inlineMapAttachment.bulkPost();return false},progressOpen:function(){this.revert();a("#mla-progress-meter").css("width","0%");a("#mla-progress-meter").html("0%");a("#mla-progress-message").html("");a("#mla-progress-error").html("");a("#mla-progress-div").show();a("#mla-progress-cancel").prop("disabled",false).css("opacity","1.0");a("#mla-progress-resume").hide();a("#mla-progress-offset").hide();a("#mla-progress-refresh").hide();a("#mla-progress-close").prop("disabled",true).css("opacity","0.5").show();a("html, body").animate({scrollTop:0},"fast")},bulkPost:function(){var g,c,f="",e=a("#mla-progress-div p.inline-edit-save .spinner"),d=a("#mla-progress-message"),b=a("#mla-progress-error");if(mla.bulkMap.waiting<mla.bulkMap.chunkSize){c=mla.bulkMap.waiting}else{c=mla.bulkMap.chunkSize}mla.bulkMap.waiting-=c;mla.bulkMap.running=c;g={page:mla.settings.page,mla_tab:mla.settings.mla_tab,screen:mla.settings.screen,action:mla.settings.ajax_action,mla_admin_nonce:mla.settings.ajax_nonce,bulk_action:mla.bulkMap.targetName,offset:mla.bulkMap.complete,length:c};g=a.param(g)+"&"+mla.bulkMap.fields;mla.bulkMap.inProcess=true;percentComplete=Math.floor((100*mla.bulkMap.complete)/mla.settings.totalItems)+"%";a("#mla-progress-meter").css("width",percentComplete);a("#mla-progress-meter").html(percentComplete);if(0<mla.bulkMap.skip){f+=", "+mla.settings.bulkSkip+": "+mla.bulkMap.skip}if(0<mla.bulkMap.redone){f+=", "+mla.settings.bulkRedone+": "+mla.bulkMap.redone}if(mla.settings.useSpinnerClass){e.addClass("is-active")}else{e.show()}f=mla.settings.bulkWaiting+": "+mla.bulkMap.waiting+", "+mla.settings.bulkRunning+": "+mla.bulkMap.running+", "+mla.settings.bulkComplete+": "+mla.bulkMap.complete+f+", "+mla.settings.bulkUnchanged+": "+mla.bulkMap.unchanged+", "+mla.settings.bulkSuccess+": "+mla.bulkMap.success;d.html(f).show();a.ajax(ajaxurl,{type:"POST",data:g,dataType:"json"}).always(function(){if(mla.settings.useSpinnerClass){e.removeClass("is-active")}else{e.hide()}}).done(function(j,i){var k="no response.data",h="";if(j){if(!j.success){if(j.responseData){k=j.data}b.html(JSON.stringify(j));mla.bulkMap.waiting=0}else{if(0==j.data.processed){h=j.data.message;mla.bulkMap.waiting=0}else{mla.bulkMap.complete+=j.data.processed;mla.bulkMap.running=0;mla.bulkMap.unchanged+=j.data.unchanged;mla.bulkMap.success+=j.data.success;if("undefined"!==typeof j.data.refresh){mla.bulkMap.refresh=j.data.refresh}percentComplete=Math.floor((100*mla.bulkMap.complete)/mla.settings.totalItems)+"%";a("#mla-progress-meter").css("width",percentComplete);a("#mla-progress-meter").html(percentComplete);if(0<mla.bulkMap.skip){h+=", "+mla.settings.bulkSkip+": "+mla.bulkMap.skip}if(0<mla.bulkMap.redone){h+=", "+mla.settings.bulkRedone+": "+mla.bulkMap.redone}h=mla.settings.bulkWaiting+": "+mla.bulkMap.waiting+", "+mla.settings.bulkComplete+": "+mla.bulkMap.complete+h+", "+mla.settings.bulkUnchanged+": "+mla.bulkMap.unchanged+", "+mla.settings.bulkSuccess+": "+mla.bulkMap.success}d.html(h).show()}}else{b.html(mla.settings.error);mla.bulkMap.waiting=0}if(mla.bulkMap.doCancel){d.html(mla.settings.bulkCanceled+". "+h).show();a("#mla-progress-resume").show();a("#mla-progress-offset").val(mla.bulkMap.complete).show()}else{if(mla.bulkMap.waiting){mla.inlineMapAttachment.bulkPost();return}}if(mla.bulkMap.refresh){a("#mla-progress-close").hide();a("#mla-progress-refresh").prop("disabled",false).css("opacity","1.0").show()}else{a("#mla-progress-close").prop("disabled",false).css("opacity","1.0")}a("#mla-progress-cancel").prop("disabled",true).css("opacity","0.5");mla.bulkMap.inProcess=false}).fail(function(i,h){if(200==i.status){b.html("("+h+") "+i.responseText)}else{b.html(mla.settings.ajaxFailError+" ("+h+"), jqXHR( "+i.status+", "+i.statusText+", "+i.responseText+")")}})},revert:function(){var b=a("#mla-progress-div");if(b){if(mla.settings.useSpinnerClass){a("p.inline-edit-save .spinner",b).removeClass("is-active")}else{a("p.inline-edit-save .spinner",b).hide()}a(b).hide()}return false}};a(document).ready(function(){mla.inlineMapAttachment.init()})})(jQuery);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* global ajaxurl */
2
+
3
+ var jQuery,
4
+ mla_inline_mapping_vars,
5
+ mla = {
6
+ // Properties
7
+ settings: {},
8
+ bulkMap: {
9
+ inProcess: false,
10
+ doCancel: false
11
+ },
12
+
13
+ // Utility functions
14
+ utility: {
15
+ },
16
+
17
+ // Components
18
+ inlineMapAttachment: null
19
+ };
20
+
21
+ ( function( $ ) {
22
+ /**
23
+ * Localized settings and strings
24
+ */
25
+ mla.settings = typeof mla_inline_mapping_vars === 'undefined' ? {} : mla_inline_mapping_vars;
26
+ mla_inline_mapping_vars = void 0; // delete won't work on Globals
27
+
28
+ mla.inlineMapAttachment = {
29
+ init : function(){
30
+ var progressDiv = $( '#mla-progress-div' );
31
+
32
+ $('#mla-progress-pause', progressDiv).off( 'click' );
33
+ $('#mla-progress-pause', progressDiv).click( function(){
34
+ if ( mla.bulkMap.inProcess ) {
35
+ mla.bulkMap.doCancel = true;
36
+ return false;
37
+ } else {
38
+ return mla.inlineMapAttachment.revert();
39
+ }
40
+ });
41
+
42
+ $('#mla-progress-cancel', progressDiv).off( 'click' );
43
+ $('#mla-progress-cancel', progressDiv).click( function(){
44
+ return mla.inlineMapAttachment.revert();
45
+ });
46
+
47
+ $('#mla-progress-resume', progressDiv).off( 'click' );
48
+ $('#mla-progress-resume', progressDiv).click( function(){
49
+ var totalItems = +mla.settings.totalItems, newOffset = + $( '#mla-progress-offset' ).val();
50
+
51
+ if ( totalItems < newOffset ) {
52
+ newOffset = totalItems;
53
+ } else {
54
+ if ( 0 > newOffset ) {
55
+ newOffset = 0;
56
+ }
57
+ }
58
+
59
+ if ( mla.bulkMap.inProcess ) {
60
+ mla.bulkMap.doCancel = true;
61
+ return false;
62
+ } else {
63
+ return mla.inlineMapAttachment.bulkMap( mla.bulkMap.targetName, newOffset );
64
+ }
65
+ });
66
+
67
+ // Clicking "Refresh" submits the form, refreshing the page
68
+ $( '#mla-progress-refresh', progressDiv ).off( 'click' );
69
+ $( '#mla-progress-refresh', progressDiv ).click( function(){
70
+ $( '#mla-progress-refresh' ).prop( 'disabled', true ).css( 'opacity', '0.5' );
71
+ });
72
+
73
+ $('#mla-progress-close', progressDiv).off( 'click' );
74
+ $('#mla-progress-close', progressDiv).click( function( e ){
75
+ if ( mla.bulkMap.inProcess ) {
76
+ return false;
77
+ }
78
+
79
+ return mla.inlineMapAttachment.revert();
80
+ });
81
+
82
+ // add event handler to the Map All links
83
+ $( 'input[type="submit"].mla-mapping' ).click(function( e ){
84
+ e.preventDefault();
85
+ return mla.inlineMapAttachment.bulkMap( e.target.name, 0 );
86
+ });
87
+ },
88
+
89
+ bulkMap : function( action, initialOffset ) {
90
+ var oldComplete = 0, oldUnchanged = 0, oldSuccess = 0, oldSkip = 0, oldRedone = 0;
91
+
92
+ initialOffset = +initialOffset;
93
+
94
+ if ( 0 < initialOffset ) {
95
+ oldComplete = typeof mla.bulkMap.complete === 'undefined' ? 0 : mla.bulkMap.complete;
96
+ oldUnchanged = typeof mla.bulkMap.unchanged === 'undefined' ? 0 : mla.bulkMap.unchanged;
97
+ oldSuccess = typeof mla.bulkMap.success === 'undefined' ? 0 : mla.bulkMap.success;
98
+ oldSkip = typeof mla.bulkMap.skip === 'undefined' ? 0 : mla.bulkMap.skip;
99
+ oldRedone = typeof mla.bulkMap.redone === 'undefined' ? 0 : mla.bulkMap.redone;
100
+ }
101
+
102
+ // See if we're skipping or re-processing any items
103
+ if ( oldComplete < initialOffset ) {
104
+ oldSkip += initialOffset - oldComplete;
105
+ } else {
106
+ if ( oldComplete > initialOffset ) {
107
+ oldRedone += oldComplete - initialOffset;
108
+ }
109
+ }
110
+
111
+ mla.bulkMap = {
112
+ inProcess: false,
113
+ doCancel: false,
114
+ chunkSize: +mla.settings.bulkChunkSize,
115
+ targetName: action,
116
+ fields: $( mla.settings.fieldsId + ' :input').serialize(),
117
+ offset: initialOffset,
118
+ waiting: mla.settings.totalItems - initialOffset,
119
+ running: 0,
120
+ complete: initialOffset,
121
+ unchanged: oldUnchanged,
122
+ success: oldSuccess,
123
+ skip: oldSkip,
124
+ redone: oldRedone,
125
+ refresh: false
126
+ };
127
+
128
+ mla.inlineMapAttachment.progressOpen();
129
+ mla.inlineMapAttachment.bulkPost();
130
+ return false;
131
+ },
132
+
133
+ progressOpen : function(){
134
+ this.revert();
135
+
136
+ $( '#mla-progress-meter' ).css( 'width', '0%' );
137
+ $( '#mla-progress-meter' ).html('0%');
138
+ $( '#mla-progress-message' ).html('');
139
+ $( '#mla-progress-error' ).html('');
140
+ $( '#mla-progress-div' ).show();
141
+
142
+ // Disable "Close" until the bulk mapping is complete
143
+ $( '#mla-progress-pause' ).prop( 'disabled', false ).css( 'opacity', '1.0' ).show();
144
+ $( '#mla-progress-cancel' ).hide();
145
+ $( '#mla-progress-resume' ).hide();
146
+ $( '#mla-progress-offset' ).hide();
147
+ $( '#mla-progress-refresh' ).hide();
148
+ $( '#mla-progress-close' ).prop( 'disabled', true ).css( 'opacity', '0.5' ).show();
149
+ $( 'html, body' ).animate( { scrollTop: 0 }, 'fast' );
150
+ },
151
+
152
+ bulkPost : function() {
153
+ var params, chunk, statusMessage = '',
154
+ spinner = $('#mla-progress-div p.inline-edit-save .spinner'),
155
+ message = $( '#mla-progress-message' ),
156
+ error = $( '#mla-progress-error' );
157
+
158
+ // Find the number of items to process
159
+ if ( mla.bulkMap.waiting < mla.bulkMap.chunkSize ) {
160
+ chunk = mla.bulkMap.waiting;
161
+ } else {
162
+ chunk = mla.bulkMap.chunkSize;
163
+ }
164
+
165
+ mla.bulkMap.waiting -= chunk;
166
+ mla.bulkMap.running = chunk;
167
+
168
+ params = {
169
+ page: mla.settings.page,
170
+ mla_tab: mla.settings.mla_tab,
171
+ screen: mla.settings.screen,
172
+ action: mla.settings.ajax_action,
173
+ mla_admin_nonce: mla.settings.ajax_nonce,
174
+ bulk_action: mla.bulkMap.targetName,
175
+ offset: mla.bulkMap.complete,
176
+ length: chunk
177
+ };
178
+
179
+ params = $.param( params ) + '&' + mla.bulkMap.fields;
180
+
181
+ // make ajax request
182
+ mla.bulkMap.inProcess = true;
183
+
184
+ percentComplete = Math.floor( ( 100 * mla.bulkMap.complete ) / mla.settings.totalItems ) + '%';
185
+ $( '#mla-progress-meter' ).css( 'width', percentComplete );
186
+ $( '#mla-progress-meter' ).html( percentComplete );
187
+
188
+ if ( 0 < mla.bulkMap.skip ) {
189
+ statusMessage += ', ' + mla.settings.bulkSkip + ': ' + mla.bulkMap.skip;
190
+ }
191
+
192
+ if ( 0 < mla.bulkMap.redone ) {
193
+ statusMessage += ', ' + mla.settings.bulkRedone + ': ' + mla.bulkMap.redone;
194
+ }
195
+
196
+ if ( mla.settings.useSpinnerClass ) {
197
+ spinner.addClass("is-active");
198
+ } else {
199
+ spinner.show();
200
+ }
201
+
202
+ statusMessage = mla.settings.bulkWaiting + ': ' + mla.bulkMap.waiting
203
+ + ', ' + mla.settings.bulkRunning + ': ' + mla.bulkMap.running
204
+ + ', ' + mla.settings.bulkComplete + ': ' + mla.bulkMap.complete
205
+ + statusMessage // skip and redone
206
+ + ', ' + mla.settings.bulkUnchanged + ': ' + mla.bulkMap.unchanged
207
+ + ', ' + mla.settings.bulkSuccess + ': ' + mla.bulkMap.success;
208
+ message.html( statusMessage ).show();
209
+
210
+ $.ajax( ajaxurl, {
211
+ type: 'POST',
212
+ data: params,
213
+ dataType: 'json'
214
+ }).always( function() {
215
+ if ( mla.settings.useSpinnerClass ) {
216
+ spinner.removeClass("is-active");
217
+ } else {
218
+ spinner.hide();
219
+ }
220
+ }).done( function( response, status ) {
221
+ var responseData = 'no response.data', responseMessage = '';
222
+
223
+ if ( response ) {
224
+ if ( ! response.success ) {
225
+ if ( response.responseData ) {
226
+ responseData = response.data;
227
+ }
228
+
229
+ error.html( JSON.stringify( response ) );
230
+ mla.bulkMap.waiting = 0; // Stop
231
+ } else {
232
+ if ( 0 == response.data.processed ) {
233
+ // Something went wrong; we're done
234
+ responseMessage = response.data.message;
235
+ mla.bulkMap.waiting = 0; // Stop
236
+ } else {
237
+ // Move the items from Running to Complete
238
+ mla.bulkMap.complete += response.data.processed;
239
+ mla.bulkMap.running = 0;
240
+ mla.bulkMap.unchanged += response.data.unchanged;
241
+ mla.bulkMap.success += response.data.success;
242
+
243
+ if ( 'undefined' !== typeof response.data.refresh ) {
244
+ mla.bulkMap.refresh = response.data.refresh;
245
+ }
246
+
247
+ percentComplete = Math.floor( ( 100 * mla.bulkMap.complete ) / mla.settings.totalItems ) + '%';
248
+ $( '#mla-progress-meter' ).css( 'width', percentComplete );
249
+ $( '#mla-progress-meter' ).html( percentComplete );
250
+
251
+ if ( 0 < mla.bulkMap.skip ) {
252
+ responseMessage += ', ' + mla.settings.bulkSkip + ': ' + mla.bulkMap.skip;
253
+ }
254
+
255
+ if ( 0 < mla.bulkMap.redone ) {
256
+ responseMessage += ', ' + mla.settings.bulkRedone + ': ' + mla.bulkMap.redone;
257
+ }
258
+
259
+ responseMessage = mla.settings.bulkWaiting + ': ' + mla.bulkMap.waiting
260
+ + ', ' + mla.settings.bulkComplete + ': ' + mla.bulkMap.complete
261
+ + responseMessage // skip and redone
262
+ + ', ' + mla.settings.bulkUnchanged + ': ' + mla.bulkMap.unchanged
263
+ + ', ' + mla.settings.bulkSuccess + ': ' + mla.bulkMap.success;
264
+ }
265
+ message.html( responseMessage ).show();
266
+ }
267
+ } else {
268
+ error.html( mla.settings.error );
269
+ mla.bulkMap.waiting = 0; // Stop
270
+ }
271
+
272
+ if ( mla.bulkMap.doCancel ) {
273
+ message.html( mla.settings.bulkPaused + '. ' + responseMessage ).show();
274
+ $( '#mla-progress-pause' ).hide();
275
+ $( '#mla-progress-cancel' ).show();
276
+ $( '#mla-progress-resume' ).show();
277
+ $( '#mla-progress-offset' ).val( mla.bulkMap.complete ).show();
278
+ } else {
279
+ if ( mla.bulkMap.waiting ) {
280
+ mla.inlineMapAttachment.bulkPost();
281
+ return;
282
+ }
283
+ }
284
+
285
+ if ( mla.bulkMap.refresh ) {
286
+ $( '#mla-progress-close' ).hide();
287
+ $( '#mla-progress-refresh' ).prop( 'disabled', false ).css( 'opacity', '1.0' ).show();
288
+ } else {
289
+ $( '#mla-progress-close' ).prop( 'disabled', false ).css( 'opacity', '1.0' );
290
+ }
291
+
292
+ $( '#mla-progress-pause' ).prop( 'disabled', true ).css( 'opacity', '0.5' );
293
+ mla.bulkMap.inProcess = false;
294
+ }).fail( function( jqXHR, status ) {
295
+ if ( 200 == jqXHR.status ) {
296
+ error.html( '(' + status + ') ' + jqXHR.responseText );
297
+ } else {
298
+ error.html( mla.settings.ajaxFailError + ' (' + status + '), jqXHR( ' + jqXHR.status + ', ' + jqXHR.statusText + ', ' + jqXHR.responseText + ')' );
299
+ }
300
+ });
301
+ },
302
+
303
+ revert : function(){
304
+ var progressDiv = $( '#mla-progress-div' );
305
+
306
+ if ( progressDiv ) {
307
+ if ( mla.settings.useSpinnerClass ) {
308
+ $('p.inline-edit-save .spinner', progressDiv ).removeClass("is-active");
309
+ } else {
310
+ $('p.inline-edit-save .spinner', progressDiv ).hide();
311
+ }
312
+
313
+ // Reset Div content to initial values
314
+
315
+ $( progressDiv ).hide();
316
+ }
317
+
318
+ return false;
319
+ }
320
+ }; // mla.inlineMapAttachment
321
+
322
+ $( document ).ready( function() {
323
+ mla.inlineMapAttachment.init();
324
+ });
325
+ })( jQuery );
js/mla-media-modal-scripts.js CHANGED
@@ -719,6 +719,13 @@ wp.media.view.MlaSearch.on( 'all', MlaSearchOn );
719
  else
720
  mlaModal.settings.query[ state ].searchFields.splice( index, 1 );
721
  break;
 
 
 
 
 
 
 
722
  case 's[mla_search_terms]':
723
  index = mlaModal.settings.query[ state ].searchFields.indexOf( 'terms' );
724
  if ( -1 == index )
719
  else
720
  mlaModal.settings.query[ state ].searchFields.splice( index, 1 );
721
  break;
722
+ case 's[mla_search_file]':
723
+ index = mlaModal.settings.query[ state ].searchFields.indexOf( 'file' );
724
+ if ( -1 == index )
725
+ mlaModal.settings.query[ state ].searchFields.push( 'file' );
726
+ else
727
+ mlaModal.settings.query[ state ].searchFields.splice( index, 1 );
728
+ break;
729
  case 's[mla_search_terms]':
730
  index = mlaModal.settings.query[ state ].searchFields.indexOf( 'terms' );
731
  if ( -1 == index )
js/mla-media-modal-scripts.min.js CHANGED
@@ -1 +1 @@
1
- var wp,wpAjax,ajaxurl,jQuery,_,getUserSetting,setUserSetting,deleteUserSetting,mlaTaxonomy,mlaModal={strings:{},settings:{},initialHTML:{},uploading:false,cid:null,utility:{originalMediaAjax:null,mlaAttachmentsBrowser:null,parseTermsOptions:null,arrayCleanup:null,parseTaxonomyId:null,hookCompatTaxonomies:null,fillCompatTaxonomies:null,supportCompatTaxonomies:null},tagBox:null};(function(d){var c=wp.media.view.AttachmentsBrowser,b=wp.media.view.AttachmentCompat,a=wp.media.model.Selection;mlaModal.strings=typeof wp.media.view.l10n.mla_strings==="undefined"?{}:wp.media.view.l10n.mla_strings;delete wp.media.view.l10n.mla_strings;mlaModal.settings=typeof wp.media.view.settings.mla_settings==="undefined"?{screen:"unknown",enableMediaGrid:false,enableMediaModal:false}:wp.media.view.settings.mla_settings;delete wp.media.view.settings.mla_settings;if(!(mlaModal.settings.enableMediaGrid||mlaModal.settings.enableMediaModal)){return}if(("grid"===mlaModal.settings.screen)&&false===mlaModal.settings.enableMediaGrid){return}if(("modal"===mlaModal.settings.screen)&&false===mlaModal.settings.enableMediaModal){return}mlaModal.settings.pagenow=typeof pagenow==="undefined"?"unknown":pagenow;if(mlaModal.settings.pagenow==="toolset_page_views-editor"){return}mlaModal.utility.originalMediaAjax=wp.media.ajax;wp.media.ajax=function(k,g){var j=mlaModal.settings.state,i,f,h,e;if(_.isObject(k)){g=k}else{g=g||{};g.data=_.extend(g.data||{},{action:k})}if("query-attachments"==g.data.action){i=g.data.query;f=typeof i.s;if("object"==f){h=i.s}else{if("string"==f){h={mla_search_value:i.s}}else{h={mla_search_value:""}}}if("undefined"!=typeof i.post_mime_type){mlaModal.settings.query[j].filterMime=i.post_mime_type}else{mlaModal.settings.query[j].filterMime="all"}if("undefined"!=typeof h.mla_filter_month){mlaModal.settings.query[j].filterMonth=h.mla_filter_month}else{if("undefined"!=typeof i.year){mlaModal.settings.query[j].filterMonth=(100*i.year)+(1*i.monthnum)}else{}}if("undefined"!=typeof h.mla_filter_term){mlaModal.settings.query[j].filterTerm=h.mla_filter_term}if("undefined"!=typeof h.mla_search_value){mlaModal.settings.query[j].searchValue=h.mla_search_value}e={mla_filter_month:mlaModal.settings.query[j].filterMonth,mla_filter_term:mlaModal.settings.query[j].filterTerm,mla_terms_search:mlaModal.settings.query[j].termsSearch,mla_search_clicks:mlaModal.settings.query[j].searchClicks,mla_search_value:mlaModal.settings.query[j].searchValue,mla_search_fields:mlaModal.settings.query[j].searchFields,mla_search_connector:mlaModal.settings.query[j].searchConnector};mlaModal.settings.query[j].termsSearch="";d("#mla-terms-search-input").html("").val("");g.data.query.s=e}return mlaModal.utility.originalMediaAjax.call(this,g)};if(mlaModal.settings.enableMimeTypes){wp.media.view.AttachmentFilters.Mla=wp.media.view.AttachmentFilters.extend({createFilters:function(){var f=this.controller._state,e={};_.each(mlaModal.settings.allMimeTypes||{},function(h,g){if(("grid"===mlaModal.settings.screen)||("trash"!==g)){e[g]={text:h,props:{type:g,uploadedTo:null,orderby:"date",order:"DESC"}}}});e.all={text:wp.media.view.l10n.allMediaItems,props:{type:null,uploadedTo:null,orderby:"date",order:"DESC"},priority:10};if(wp.media.view.settings.post.id){e.uploaded={text:wp.media.view.l10n.uploadedToThisPost,props:{type:null,uploadedTo:wp.media.view.settings.post.id,orderby:"menuOrder",order:"ASC"},priority:20}}this.filters=e;if("undefined"===typeof e[mlaModal.settings.query[f].filterMime]){mlaModal.settings.query[f].filterMime="all"}if(mlaModal.settings.query[f].filterMime!="all"){this.model.set(e[mlaModal.settings.query[f].filterMime].props,{silent:false})}},select:function(){var h=this.controller._state,e=this.model,g=mlaModal.settings.query[h].filterMime,f=e.toJSON();if(false===mlaModal.settings.enableSearchBox){if("string"==typeof f.search){mlaModal.settings.query[h].searchValue=f.search}else{mlaModal.settings.query[h].searchValue=""}}_.find(this.filters,function(j,k){var i=_.all(j.props,function(m,l){return m===(_.isUndefined(f[l])?null:f[l])});if(i){return g=k}});this.$el.val(g)},change:function(){var f=d(this.el).closest("div.media-toolbar"),e=this.filters[this.el.value];if(e){this.model.set(e.props,{silent:true});d("#mla-search-submit",f).click()}}});wp.media.view.AttachmentFilters.MlaUploaded=wp.media.view.AttachmentFilters.extend({createFilters:function(){var f=this.model.get("type"),e=wp.media.view.settings.mimeTypes,i,h=this.controller._state,g={};if(e&&f){i=e[f]}_.each(mlaModal.settings.uploadMimeTypes||{},function(k,j){if(("grid"===mlaModal.settings.screen)||("trash"!==j)){g[j]={text:k,props:{type:j,uploadedTo:null,orderby:"date",order:"DESC"}}}});g.all={text:i||wp.media.view.l10n.allMediaItems,props:{uploadedTo:null,orderby:"date",order:"DESC"},priority:10};g.uploaded={text:wp.media.view.l10n.uploadedToThisPost,props:{type:null,uploadedTo:wp.media.view.settings.post.id,orderby:"menuOrder",order:"ASC"},priority:20};g.unattached={text:wp.media.view.l10n.unattached,props:{uploadedTo:0,orderby:"menuOrder",order:"ASC"},priority:50};this.filters=g;if("undefined"===typeof g[mlaModal.settings.query[h].filterUploaded]){mlaModal.settings.query[h].filterUploaded="all"}if(mlaModal.settings.query[h].filterUploaded!="all"){this.model.set(g[mlaModal.settings.query[h].filterUploaded].props,{silent:false})}},select:function(){var h=this.controller._state,e=this.model,g=mlaModal.settings.query[h].filterMime,f=e.toJSON();if(false===mlaModal.settings.enableSearchBox){if("string"==typeof f.search){mlaModal.settings.query[h].searchValue=f.search}else{mlaModal.settings.query[h].searchValue=""}}_.find(this.filters,function(j,k){var i=_.all(j.props,function(m,l){return m===(_.isUndefined(f[l])?null:f[l])});if(i){return g=k}});this.$el.val(g)},change:function(){var f=d(this.el).closest("div.media-toolbar"),e=this.filters[this.el.value];if(e){this.model.set(e.props,{silent:true});d("#mla-search-submit",f).click()}}})}if(mlaModal.settings.enableMonthsDropdown){wp.media.view.AttachmentFilters.MlaMonths=wp.media.view.AttachmentFilters.extend({className:"attachment-filters",id:"media-attachment-date-filters",createFilters:function(){var f=this.controller._state,e={};_.each(mlaModal.settings.months||{},function(h,g){e[g]={text:h,props:{s:{mla_filter_month:g}}}});this.filters=e;if("undefined"===typeof e[mlaModal.settings.query[f].filterMonth]){mlaModal.settings.query[f].filterMonth=0}if(mlaModal.settings.query[f].filterMonth>0){this.model.set(e[mlaModal.settings.query[f].filterMonth].props,{silent:false})}},select:function(){var h=this.controller._state,e=this.model,g=mlaModal.settings.query[h].filterMonth,f=e.toJSON();if(_.isUndefined(f.s)){f.s={}}if(false===mlaModal.settings.enableSearchBox){if("string"==typeof f.search){mlaModal.settings.query[h].searchValue=f.search}else{mlaModal.settings.query[h].searchValue=""}}if(_.isUndefined(f.s.mla_filter_month)){f.s.mla_filter_month=mlaModal.settings.query[h].filterMonth}else{mlaModal.settings.query[h].filterMonth=f.s.mla_filter_month}_.find(this.filters,function(j,k){var i=_.all(j.props,function(l){return l.mla_filter_month==mlaModal.settings.query[h].filterMonth});if(i){return g=k}});this.$el.val(g)},change:function(){var e=this.filters[this.el.value],f;if(e){f={s:{mla_filter_month:e.props.s.mla_filter_month}};this.model.set(f)}}})}if(mlaModal.settings.enableTermsDropdown){wp.media.view.AttachmentFilters.MlaTerms=wp.media.view.AttachmentFilters.extend({className:"attachment-filters",id:"media-attachment-term-filters",createFilters:function(){var h=this.controller._state,e,f,g={};_.each(mlaModal.settings.termsText||{},function(j,i){if(mlaModal.settings.termsCustom){f=mlaModal.settings.termsValue[i]}else{f=parseInt(mlaModal.settings.termsValue[i])}g[i]={text:j,props:{s:{mla_filter_term:f}}}});this.filters=g;e=_.indexOf(mlaModal.settings.termsValue,mlaModal.settings.query[h].filterTerm);if(e>0){this.model.set(g[e].props,{silent:false})}},select:function(){var h=this.controller._state,e=this.model,g=mlaModal.settings.query[h].filterTerm,f=e.toJSON();if(_.isUndefined(f.s)){f.s={}}if(false===mlaModal.settings.enableSearchBox){if("string"==typeof f.search){mlaModal.settings.query[h].searchValue=f.search}else{mlaModal.settings.query[h].searchValue=""}}if(_.isUndefined(f.s.mla_filter_term)){f.s.mla_filter_term=mlaModal.settings.query[h].filterTerm}else{mlaModal.settings.query[h].filterTerm=f.s.mla_filter_term}_.find(this.filters,function(j,k){var i=_.all(j.props,function(l){return l.mla_filter_term==mlaModal.settings.query[h].filterTerm});if(i){return g=k}});this.$el.val(g)},change:function(){var e=this.filters[this.el.value],f;if(e){f={s:{mla_filter_term:e.props.s.mla_filter_term}};this.model.set(f)}}})}if(mlaModal.settings.enableTermsSearch){wp.media.view.MlaTermsSearch=wp.media.View.extend({tagName:"span",className:"mla-terms-search",template:wp.media.template("mla-terms-search-button"),attributes:{type:"mla-terms-search-button"},events:{change:"termsSearchOpen",click:"termsSearchOpen"},render:function(){this.$el.html(this.template(mlaModal.strings));return this},termsSearchOpen:function(f){var e=d(this.el).closest("div.media-toolbar");if(("click"==f.type)&&("mla_terms_search"===f.target.name)){mlaTaxonomy.termsSearch.open();d("#mla-terms-search-form").off("submit");d("#mla-terms-search-form").submit(function(j){var g,i,h={phrases:"",taxonomies:[]};j.preventDefault();g=d("#mla-terms-search-form").serializeArray();for(i=0;i<g.length;i++){switch(g[i].name){case"mla_terms_search[phrases]":h.phrases=g[i].value;break;case"mla_terms_search[radio_phrases]":h.radio_phrases=g[i].value;break;case"mla_terms_search[radio_terms]":h.radio_terms=g[i].value;break;case"mla_terms_search[taxonomies][]":h.taxonomies[h.taxonomies.length]=g[i].value;break}}mlaModal.settings.query[mlaModal.settings.state].termsSearch=h;d("#mla-search-submit",e).click();return false});d("#mla-terms-search-input").keypress(function(g){if(13==g.which){g.preventDefault();d("#mla-terms-search-submit").click()}})}}})}if(mlaModal.settings.enableSearchBox){wp.media.view.MlaSearch=wp.media.View.extend({tagName:"div",className:"mla-search-box",template:wp.media.template("mla-search-box"),attributes:{type:"mla-search-box"},events:{input:"search",change:"search",click:"search",search:"search",MlaSearch:"search"},initialize:function(){var e=this.controller._state;if("undefined"===typeof mlaModal.settings.query[e]){mlaModal.settings.query[e]=_.clone(mlaModal.settings.query.initial);mlaModal.settings.query[e].searchFields=_.clone(mlaModal.settings.query.initial.searchFields)}},render:function(){var f=this.controller._state,e=_.extend(mlaModal.strings,mlaModal.settings.query[f]);this.$el.html(this.template(e));return this},search:function(g){var h=this.controller._state,e,i,f;if(("input"==g.type)&&("s[mla_search_value]"==g.target.name)){mlaModal.settings.query[h].searchValue=g.target.value;return}if(("click"==g.type)&&("mla_search_submit"!=g.target.name)){return}switch(g.target.name){case"s[mla_search_value]":mlaModal.settings.query[h].searchValue=g.target.value;break;case"mla_search_submit":e={mla_filter_month:mlaModal.settings.query[h].filterMonth,mla_filter_term:mlaModal.settings.query[h].filterTerm,mla_terms_search:mlaModal.settings.query[h].termsSearch,mla_search_clicks:mlaModal.settings.query[h].searchClicks++,mla_search_value:mlaModal.settings.query[h].searchValue,mla_search_fields:mlaModal.settings.query[h].searchFields,mla_search_connector:mlaModal.settings.query[h].searchConnector};this.model.set({s:e});break;case"s[mla_search_connector]":mlaModal.settings.query[h].searchConnector=g.target.value;break;case"s[mla_search_title]":i=mlaModal.settings.query[h].searchFields;f=i.indexOf("title");if(-1==f){i.push("title")}else{i.splice(f,1)}mlaModal.settings.query[h].searchFields=i;break;case"s[mla_search_name]":f=mlaModal.settings.query[h].searchFields.indexOf("name");if(-1==f){mlaModal.settings.query[h].searchFields.push("name")}else{mlaModal.settings.query[h].searchFields.splice(f,1)}break;case"s[mla_search_alt_text]":f=mlaModal.settings.query[h].searchFields.indexOf("alt-text");if(-1==f){mlaModal.settings.query[h].searchFields.push("alt-text")}else{mlaModal.settings.query[h].searchFields.splice(f,1)}break;case"s[mla_search_excerpt]":f=mlaModal.settings.query[h].searchFields.indexOf("excerpt");if(-1==f){mlaModal.settings.query[h].searchFields.push("excerpt")}else{mlaModal.settings.query[h].searchFields.splice(f,1)}break;case"s[mla_search_content]":f=mlaModal.settings.query[h].searchFields.indexOf("content");if(-1==f){mlaModal.settings.query[h].searchFields.push("content")}else{mlaModal.settings.query[h].searchFields.splice(f,1)}break;case"s[mla_search_terms]":f=mlaModal.settings.query[h].searchFields.indexOf("terms");if(-1==f){mlaModal.settings.query[h].searchFields.push("terms")}else{mlaModal.settings.query[h].searchFields.splice(f,1)}break}}})}else{wp.media.view.MlaSearch=wp.media.View.extend({tagName:"span",className:"mla-simulate-search-button",template:wp.media.template("mla-simulate-search-button"),attributes:{type:"mla-simulate-search-button"},events:{click:"simulateSearch"},render:function(){this.$el.html(this.template(mlaModal.strings));return this},simulateSearch:function(){var f=this.controller._state,e={mla_filter_month:mlaModal.settings.query[f].filterMonth,mla_filter_term:mlaModal.settings.query[f].filterTerm,mla_terms_search:mlaModal.settings.query[f].termsSearch,mla_search_clicks:mlaModal.settings.query[f].searchClicks++,mla_search_value:mlaModal.settings.query[f].searchValue,mla_search_fields:mlaModal.settings.query[f].searchFields,mla_search_connector:mlaModal.settings.query[f].searchConnector};this.model.set({s:e})}})}if(mlaModal.settings.enableMimeTypes||mlaModal.settings.enableMonthsDropdown||mlaModal.settings.enableTermsDropdown||mlaModal.settings.enableTermsSearch||mlaModal.settings.enableSearchBox){wp.media.view.AttachmentsBrowser=wp.media.view.AttachmentsBrowser.extend({createToolbar:function(){var e,f=this.controller._state;mlaModal.settings.state=f;mlaModal.settings.$el=this.controller.$el;if("undefined"===typeof mlaModal.settings.query[f]){mlaModal.settings.query[f]=_.clone(mlaModal.settings.query.initial);mlaModal.settings.query[f].searchFields=_.clone(mlaModal.settings.query.initial.searchFields)}c.prototype.createToolbar.apply(this,arguments);mlaModal.utility.mlaAttachmentsBrowser=this;e=this.options.filters;if(typeof window.eml!=="undefined"){d(".media-toolbar",this.$el).css("overflow","hidden")}if(("all"===e)&&mlaModal.settings.enableMimeTypes){this.toolbar.unset("filters",{silent:true});this.toolbar.set("filters",new wp.media.view.AttachmentFilters.Mla({controller:this.controller,model:this.collection.props,priority:-80}).render())}if(("uploaded"===e)&&mlaModal.settings.enableMimeTypes){this.toolbar.unset("filters",{silent:true});this.toolbar.set("filters",new wp.media.view.AttachmentFilters.MlaUploaded({controller:this.controller,model:this.collection.props,priority:-80}).render())}if(this.options.search&&mlaModal.settings.enableMonthsDropdown){this.toolbar.unset("dateFilter",{silent:true});this.toolbar.set("dateFilter",new wp.media.view.AttachmentFilters.MlaMonths({controller:this.controller,model:this.collection.props,priority:-75}).render())}if(this.options.search&&mlaModal.settings.enableTermsDropdown){this.toolbar.set("terms",new wp.media.view.AttachmentFilters.MlaTerms({controller:this.controller,model:this.collection.props,priority:-50}).render())}if(this.options.search&&mlaModal.settings.enableTermsSearch){this.toolbar.set("termsSearch",new wp.media.view.MlaTermsSearch({controller:this.controller,model:this.collection.props,priority:-50}).render())}if(this.options.search){if(mlaModal.settings.enableSearchBox){this.controller.on("content:activate",this.hideDefaultSearch);this.controller.on("edit:activate",this.hideDefaultSearch);this.controller.on("router:render",this.hideDefaultSearch);this.controller.on("uploader:ready",this.hideDefaultSearch);this.toolbar.set("MlaSearch",new wp.media.view.MlaSearch({controller:this.controller,model:this.collection.props,priority:60}).render())}else{this.toolbar.set("MlaSearch",new wp.media.view.MlaSearch({controller:this.controller,model:this.collection.props,priority:70}).render())}}},hideDefaultSearch:function(){var e=d("#media-search-input",mlaModal.settings.$el);if(0===e.length){e=d("div.media-toolbar-primary > input.search",mlaModal.settings.$el)}e.hide()},updateFilters:function(e,f){var g={};if(this.options.search&&mlaModal.settings.enableTermsDropdown&&mlaModal.settings.termsTaxonomy==e){g=mlaModal.utility.parseTermsOptions(f);mlaModal.settings.termsClass=g.termsClass;mlaModal.settings.termsText=g.termsText;mlaModal.settings.termsValue=g.termsValue;this.toolbar.unset("terms",{silent:true});this.toolbar.set("terms",new wp.media.view.AttachmentFilters.MlaTerms({controller:this.controller,model:this.collection.props,priority:-80}).render())}}})}mlaModal.utility.parseTermsOptions=function(k){var j={termsClass:[mlaModal.settings.termsClass[0],mlaModal.settings.termsClass[1]],termsText:[mlaModal.settings.termsText[0],mlaModal.settings.termsText[1]],termsValue:[mlaModal.settings.termsValue[0],mlaModal.settings.termsValue[1]]},g=2,e,f,i=/\<option(( class=\"([^\"]+)\" )|( ))value=((\'([^\']+)\')|(\"([^\"]+)\"))([^\>]*)\>([^\<]*)\<.*/g,h=[];if("object"===typeof k){g=mlaModal.settings.termsValue.length;for(e=2;e<g;e++){h[e]={termsClass:mlaModal.settings.termsClass[e],termsText:mlaModal.settings.termsText[e],termsValue:mlaModal.settings.termsValue[e]};if("undefined"!==typeof k[mlaModal.settings.termsValue[e]]){delete k[mlaModal.settings.termsValue[e]]}}for(f in k){h[e++]={termsClass:"level-0",termsText:k[f],termsValue:f.toString()}}if(g===e){return{termsClass:mlaModal.settings.termsClass,termsText:mlaModal.settings.termsText,termsValue:mlaModal.settings.termsValue}}h.sort(function(m,l){if(m.termsText>l.termsText){return 1}else{if(m.termsText<l.termsText){return -1}else{return 0}}});e=2;for(f in h){j.termsClass[e]=h[f].termsClass;j.termsText[e]=h[f].termsText;j.termsValue[e++]=h[f].termsValue}return j}h=i.exec(k);while(null!==(h=i.exec(k))){j.termsClass[g]=h[3];j.termsValue[g]=("undefined"===typeof h[6])?h[9]:h[7];j.termsText[g++]=h[11].replace("&nbsp;",mlaModal.settings.termsIndent)}return j};mlaModal.utility.arrayCleanup=function(g){var f=[],e=("string"===typeof g);if(e){g=g.split(mlaModal.settings.comma)}jQuery.each(g,function(h,i){i=jQuery.trim(i);if(i&&jQuery.inArray(i,f)==-1){f.push(i)}});f.sort();if(e){f=f.join(mlaModal.settings.comma)}return f};mlaModal.utility.parseTaxonomyId=function(f){var e=f.split("-");e.shift();e.shift();return e.join("-")};mlaModal.tagBox={cleanTags:function(f){var e=mlaModal.settings.comma;if(","!==e){f=f.replace(new RegExp(e,"g"),",")}f=f.replace(/\s*,\s*/g,",").replace(/,+/g,",").replace(/[,\s]+$/,"").replace(/^[,\s]+/,"");if(","!==e){f=f.replace(/,/g,e)}return f},parseTags:function(h){var l=h.id,f=l.split("-check-num-")[1],i=d(h).closest(".tagsdiv"),k=i.find(".the-tags"),e=mlaModal.settings.comma,g=k.val().split(e),j=[];delete g[f];d.each(g,function(m,n){n=d.trim(n);if(n){j.push(n)}});k.val(this.cleanTags(j.join(e)));this.quickClicks(i);return false},quickClicks:function(g){var j=d(".the-tags",g),h=d(".tagchecklist",g),i=d(g).attr("id"),e,f;if(!j.length){return}f=j.prop("disabled");e=j.val().split(mlaModal.settings.comma);h.empty();d.each(e,function(l,n){var m,k;n=d.trim(n);if(!n){return}m=d("<span />").text(n);if(!f){k=d('<a id="'+i+"-check-num-"+l+'" class="ntdelbutton">X</a>');k.click(function(){mlaModal.tagBox.parseTags(this)});m.prepend("&nbsp;").prepend(k)}h.append(m)})},flushTags:function(k,h,g){var m,e,i,n=d(".the-tags",k),j=d("input.newtag",k),l=mlaModal.settings.comma;h=h||false;i=h?d(h).text():j.val();m=n.val();e=m?m+l+i:i;e=mlaModal.utility.arrayCleanup(this.cleanTags(e));n.val(e);this.quickClicks(k);if(!h){j.val("")}if("undefined"==typeof(g)){j.focus()}return false},getCloud:function(f,e){d.post(ajaxurl,{action:"get-tagcloud",tax:e},function(h,g){if(0===h||"success"!=g){h=wpAjax.broken}h=d('<p id="tagcloud-'+e+'" class="the-tagcloud">'+h+"</p>");d("a",h).click(function(){mlaModal.tagBox.flushTags(d(this).closest(".mla-taxonomy-field").children(".tagsdiv"),this);return false});d("#"+f).after(h)})},init:function(i,e,g){var h,f;h=d("#mla-taxonomy-"+e,g);f=d("div.ajaxtag",h);mlaModal.tagBox.quickClicks(h);d("input.tagadd",f).click(function(){mlaModal.tagBox.flushTags(d(this).closest(".tagsdiv"))});d("input.newtag",f).keyup(function(j){if(13==j.which){mlaModal.tagBox.flushTags(h);return false}}).keypress(function(j){if(13==j.which){j.preventDefault();return false}}).each(function(){d(this).suggest(ajaxurl+"?action=ajax-tag-search&tax="+e,{delay:500,resultsClass:"mla_ac_results",selectClass:"mla_ac_over",matchClass:"mla_ac_match",minchars:2,multiple:true,multipleSep:mlaModal.settings.comma+" "})});h.siblings(":first").click(function(){mlaModal.tagBox.getCloud(d("a",this).attr("id"),e);d("a",this).unbind().click(function(){d(this).siblings(".the-tagcloud").toggle();return false});return false});d(".compat-field-"+e+" td",g).on("mouseleave",function(){var m,k=this,j=mlaModal.utility.arrayCleanup(d(".server-tags",k).val()),l=mlaModal.utility.arrayCleanup(d(".the-tags",k).val());if(j===l){return}d(k).css("opacity","0.5");m={id:i};m[e]=l;wp.media.post(mlaModal.settings.ajaxUpdateCompatAction,m).done(function(o){var p,n,q;for(n in o){if("object"===typeof(o[n]["object-terms"])){if(null!==mlaModal.utility.mlaAttachmentsBrowser){mlaModal.utility.mlaAttachmentsBrowser.updateFilters(n,o[n]["object-terms"])}delete o[n]["object-terms"]}for(q in o[n]){d("#"+q,k).replaceWith(o[n][q])}p=d("#mla-taxonomy-"+n,k);mlaModal.tagBox.quickClicks(p)}d(k).css("opacity","1.0")})});h.on("change",function(j){j.stopPropagation();return false});d(".the-tags, .server-tags .newtag",h).on("change",function(j){j.stopPropagation();return false})}};if(mlaModal.settings.enableDetailsCategory||mlaModal.settings.enableDetailsTag){wp.media.view.AttachmentCompat=wp.media.view.AttachmentCompat.extend({initialize:function(){b.prototype.initialize.apply(this,arguments);this.on("ready",function(){mlaModal.utility.hookCompatTaxonomies(this.model.get("id"),this.el)})}})}if(mlaModal.settings.enableDetailsCategory||mlaModal.settings.enableDetailsTag){wp.media.model.Selection=wp.media.model.Selection.extend({initialize:function(){a.prototype.initialize.apply(this,arguments);this.on("selection:reset",function(){mlaModal.cid=null});this.on("selection:unsingle",function(){mlaModal.cid=null});this.on("selection:single",function(e){mlaModal.cid=e.cid});this.on("change:uploading",function(){mlaModal.uploading=true});this.on("change",function(e){var f=false,g;if(mlaModal.uploading&&mlaModal.cid===e.cid){mlaModal.uploading=false;f=true}else{if(false===e.attributes.uploading){g=_.clone(e.changed);delete g.title;delete g.caption;delete g.alt;delete g.description;if(!_.isEmpty(g)){f=true}}}if(true===f){mlaModal.utility.hookCompatTaxonomies(e.get("id"),mlaModal.settings.$el)}})}})}mlaModal.utility.hookCompatTaxonomies=function(h,f){var e,g=null;d(".mla-taxonomy-field .categorydiv",f).each(function(){e=mlaModal.utility.parseTaxonomyId(d(this).attr("id"));if(-1!=mlaModal.settings.enhancedTaxonomies.indexOf(e)){d(".compat-field-"+e+" th",f).click({id:h,currentTaxonomy:e,el:f},function(i){mlaModal.utility.fillCompatTaxonomies(i.data)});d("tr.compat-field-"+e,f).each(function(){if(d(this).hasClass("mla-taxonomy-row")){d(this).show()}else{d(this).remove()}});if(null===g){g=e}}else{d("tr.compat-field-"+e,f).each(function(){if(d(this).hasClass("mla-taxonomy-row")){d(this).remove()}})}});d(".mla-taxonomy-field .tagsdiv",f).each(function(){e=mlaModal.utility.parseTaxonomyId(d(this).attr("id"));if(-1!=mlaModal.settings.enhancedTaxonomies.indexOf(e)){d(".compat-field-"+e+" th",f).click({id:h,currentTaxonomy:e,el:f},function(i){mlaModal.utility.fillCompatTaxonomies(i.data)});d("tr.compat-field-"+e,f).each(function(){if(d(this).hasClass("mla-taxonomy-row")){d(this).show()}else{d(this).remove()}});if(null===g){g=e}}else{d("tr.compat-field-"+e,f).each(function(){if(d(this).hasClass("mla-taxonomy-row")){d(this).remove()}})}});if(mlaModal.settings.enableTermsAutofill&&null!==g){d(".compat-field-"+g+" th",f).click()}};mlaModal.utility.fillCompatTaxonomies=function(i){var f=i.el,h=[],e,g;d(".mla-taxonomy-field .categorydiv",f).each(function(){e=mlaModal.utility.parseTaxonomyId(d(this).attr("id"));h[h.length]=e;g=".compat-field-"+e;if("undefined"===typeof(mlaModal.initialHTML[e])){mlaModal.initialHTML[e]=d(g,f).html()}else{d(g,f).html(mlaModal.initialHTML[e])}d(g+" .categorydiv",f).html(mlaModal.strings.loadingText)});d(".mla-taxonomy-field .tagsdiv",f).each(function(){e=mlaModal.utility.parseTaxonomyId(d(this).attr("id"));h[h.length]=e;g=".compat-field-"+e;if("undefined"===typeof(mlaModal.initialHTML[e])){mlaModal.initialHTML[e]=d(g,f).html()}else{d(g,f).html(mlaModal.initialHTML[e])}d(g+" .tagsdiv",f).html(mlaModal.strings.loadingText)});if(h.length){wp.media.post(mlaModal.settings.ajaxFillCompatAction,{id:i.id,query:h}).done(function(k){var j,l;for(j in k){l=".compat-field-"+j;d(l,f).html(k[j])}mlaModal.utility.supportCompatTaxonomies(i);d(".compat-field-"+i.currentTaxonomy+" td",f).show()})}};mlaModal.utility.supportCompatTaxonomies=function(g){var f=g.id,e=g.el;if(mlaModal.settings.enableDetailsCategory){d(".mla-taxonomy-field .categorydiv",e).each(function(){var j=d(this),h,k,i,n,l,p,o,m;i=mlaModal.utility.parseTaxonomyId(d(this).attr("id"));n=i+"_tab";l="#mla-"+i;p="#mla-new-"+i;o="#mla-search-"+i;m="#mla-attachments-"+f+"-"+i;if(i=="category"){n="cats"}j.find(".category-tabs").show();d(".compat-field-"+i+" th",e).click(function(){d(this).siblings("td").slideToggle()});j.on("mouseleave",function(){var t,q,s=[],r=j.find(l+"-checklist input:checked");r.each(function(){s[s.length]=d(this).val()});s.sort(function(v,u){return v-u});s=s.join(",");q=j.siblings(m).val();if(q===s){return}j.siblings(m).val(s);j.prop("disabled",true);t={id:f};t[i]=s;wp.media.post(mlaModal.settings.ajaxUpdateCompatAction,t).done(function(v){var u,w;for(u in v){for(w in v[u]){j.find("#"+w).html(v[u][w])}}j.find(o).val("");j.find(l+"-searcher").addClass("mla-hidden-children");j.prop("disabled",false)})});j.on('change input[type="checkbox"]',function(q){q.stopPropagation();return false});j.find(l+"-tabs a").click(function(){var q=d(this).attr("href");d(this).parent().addClass("tabs").siblings("li").removeClass("tabs");j.find(l+"-tabs").siblings(".tabs-panel").hide();j.find(q).show();d(this).focus();if("#mla-"+i+"-all"==q){deleteUserSetting(n)}else{setUserSetting(n,"pop")}return false});if(getUserSetting(n)){j.find(l+'-tabs a[href="#mla-'+i+'-pop"]').click()}j.find(l+"-add-toggle").click(function(){j.find(l+"-searcher").addClass("mla-hidden-children");j.find(l+"-adder").toggleClass("mla-hidden-children");j.find(l+'-tabs a[href="#mla-'+i+'-all"]').click();j.find(l+"-checklist li").show();j.find(l+"-checklist-pop li").show();if(false===j.find(l+"-adder").hasClass("mla-hidden-children")){j.find(p).val("").removeClass("form-input-tip");j.find(p).focus()}return false});j.find(p).keypress(function(q){if(13===q.keyCode){q.preventDefault();j.find(l+"-add-submit").click()}});j.find(l+"-add-submit").click(function(){j.find(p).focus()});h=function(q){if(!j.find(p).val()){return false}q.data+="&"+j.find(l+"-checklist :checked").serialize();j.prop("disabled",true);return q};k=function(v,u){var t,q=j.find("#new"+i+"_parent");j.prop("disabled",false);if("undefined"!=u.parsed.responses[0]&&(t=u.parsed.responses[0].supplemental.newcat_parent)){q.before(t);q.remove();if(null!==mlaModal.utility.mlaAttachmentsBrowser){mlaModal.utility.mlaAttachmentsBrowser.updateFilters(i,t)}}};j.find(l+"-checklist").wpList({alt:"",response:"mla-"+i+"-ajax-response",addBefore:h,addAfter:k});j.find(l+"-checklist, "+l+"-checklist-pop").on("click",'li.popular-category > label input[type="checkbox"]',function(){var q=d(this),s=q.is(":checked"),r=q.val();if(r&&q.parents("#mla-taxonomy-"+i).length){d("#in-"+i+"-"+r+", #in-popular-"+i+"-"+r).prop("checked",s)}});d.extend(d.expr[":"],{matchTerms:function(s,r,q,t){return(s.textContent||s.innerText||"").toLowerCase().indexOf((q[3]||"").toLowerCase())>=0}});j.find(o).keypress(function(q){if(13===q.keyCode){q.preventDefault();j.find(o).val("");j.find(l+"-searcher").addClass("mla-hidden-children");j.find(l+"-checklist li").show();j.find(l+"-checklist-pop li").show();return}});j.find(o).keyup(function(s){var u,t,v,r,q;if(13===s.keyCode){s.preventDefault();j.find(l+"-search-toggle").focus();return}u=j.find(o).val();t=j.find(l+"-checklist li");v=j.find(l+"-checklist-pop li");if(0<u.length){t.hide();v.hide()}else{t.show();v.show()}r=j.find(l+"-checklist label:matchTerms('"+u+"')");r.closest("li").find("li").andSelf().show();r.parents(l+"-checklist li").show();q=j.find(l+"-checklist-pop label:matchTerms('"+u+"')");q.closest("li").find("li").andSelf().show();q.parents(l+"-checklist li").show()});j.find(l+"-search-toggle").click(function(){j.find(l+"-adder ").addClass("mla-hidden-children");j.find(l+"-searcher").toggleClass("mla-hidden-children");j.find(l+'-tabs a[href="#mla-'+i+'-all"]').click();j.find(l+"-checklist li").show();j.find(l+"-checklist-pop li").show();if(false===j.find(l+"-searcher").hasClass("mla-hidden-children")){j.find(o).val("").removeClass("form-input-tip");j.find(o).focus()}return false})})}if(mlaModal.settings.enableDetailsTag){d(".mla-taxonomy-field .tagsdiv",e).each(function(){var h=mlaModal.utility.parseTaxonomyId(d(this).attr("id"));d(".compat-field-"+h+" th",e).click(function(){d(this).siblings("td").slideToggle()});mlaModal.tagBox.init(f,h,e)})}}}(jQuery));
1
+ var wp,wpAjax,ajaxurl,jQuery,_,getUserSetting,setUserSetting,deleteUserSetting,mlaTaxonomy,mlaModal={strings:{},settings:{},initialHTML:{},uploading:false,cid:null,utility:{originalMediaAjax:null,mlaAttachmentsBrowser:null,parseTermsOptions:null,arrayCleanup:null,parseTaxonomyId:null,hookCompatTaxonomies:null,fillCompatTaxonomies:null,supportCompatTaxonomies:null},tagBox:null};(function(d){var c=wp.media.view.AttachmentsBrowser,b=wp.media.view.AttachmentCompat,a=wp.media.model.Selection;mlaModal.strings=typeof wp.media.view.l10n.mla_strings==="undefined"?{}:wp.media.view.l10n.mla_strings;delete wp.media.view.l10n.mla_strings;mlaModal.settings=typeof wp.media.view.settings.mla_settings==="undefined"?{screen:"unknown",enableMediaGrid:false,enableMediaModal:false}:wp.media.view.settings.mla_settings;delete wp.media.view.settings.mla_settings;if(!(mlaModal.settings.enableMediaGrid||mlaModal.settings.enableMediaModal)){return}if(("grid"===mlaModal.settings.screen)&&false===mlaModal.settings.enableMediaGrid){return}if(("modal"===mlaModal.settings.screen)&&false===mlaModal.settings.enableMediaModal){return}mlaModal.settings.pagenow=typeof pagenow==="undefined"?"unknown":pagenow;if(mlaModal.settings.pagenow==="toolset_page_views-editor"){return}mlaModal.utility.originalMediaAjax=wp.media.ajax;wp.media.ajax=function(k,g){var j=mlaModal.settings.state,i,f,h,e;if(_.isObject(k)){g=k}else{g=g||{};g.data=_.extend(g.data||{},{action:k})}if("query-attachments"==g.data.action){i=g.data.query;f=typeof i.s;if("object"==f){h=i.s}else{if("string"==f){h={mla_search_value:i.s}}else{h={mla_search_value:""}}}if("undefined"!=typeof i.post_mime_type){mlaModal.settings.query[j].filterMime=i.post_mime_type}else{mlaModal.settings.query[j].filterMime="all"}if("undefined"!=typeof h.mla_filter_month){mlaModal.settings.query[j].filterMonth=h.mla_filter_month}else{if("undefined"!=typeof i.year){mlaModal.settings.query[j].filterMonth=(100*i.year)+(1*i.monthnum)}else{}}if("undefined"!=typeof h.mla_filter_term){mlaModal.settings.query[j].filterTerm=h.mla_filter_term}if("undefined"!=typeof h.mla_search_value){mlaModal.settings.query[j].searchValue=h.mla_search_value}e={mla_filter_month:mlaModal.settings.query[j].filterMonth,mla_filter_term:mlaModal.settings.query[j].filterTerm,mla_terms_search:mlaModal.settings.query[j].termsSearch,mla_search_clicks:mlaModal.settings.query[j].searchClicks,mla_search_value:mlaModal.settings.query[j].searchValue,mla_search_fields:mlaModal.settings.query[j].searchFields,mla_search_connector:mlaModal.settings.query[j].searchConnector};mlaModal.settings.query[j].termsSearch="";d("#mla-terms-search-input").html("").val("");g.data.query.s=e}return mlaModal.utility.originalMediaAjax.call(this,g)};if(mlaModal.settings.enableMimeTypes){wp.media.view.AttachmentFilters.Mla=wp.media.view.AttachmentFilters.extend({createFilters:function(){var f=this.controller._state,e={};_.each(mlaModal.settings.allMimeTypes||{},function(h,g){if(("grid"===mlaModal.settings.screen)||("trash"!==g)){e[g]={text:h,props:{type:g,uploadedTo:null,orderby:"date",order:"DESC"}}}});e.all={text:wp.media.view.l10n.allMediaItems,props:{type:null,uploadedTo:null,orderby:"date",order:"DESC"},priority:10};if(wp.media.view.settings.post.id){e.uploaded={text:wp.media.view.l10n.uploadedToThisPost,props:{type:null,uploadedTo:wp.media.view.settings.post.id,orderby:"menuOrder",order:"ASC"},priority:20}}this.filters=e;if("undefined"===typeof e[mlaModal.settings.query[f].filterMime]){mlaModal.settings.query[f].filterMime="all"}if(mlaModal.settings.query[f].filterMime!="all"){this.model.set(e[mlaModal.settings.query[f].filterMime].props,{silent:false})}},select:function(){var h=this.controller._state,e=this.model,g=mlaModal.settings.query[h].filterMime,f=e.toJSON();if(false===mlaModal.settings.enableSearchBox){if("string"==typeof f.search){mlaModal.settings.query[h].searchValue=f.search}else{mlaModal.settings.query[h].searchValue=""}}_.find(this.filters,function(j,k){var i=_.all(j.props,function(m,l){return m===(_.isUndefined(f[l])?null:f[l])});if(i){return g=k}});this.$el.val(g)},change:function(){var f=d(this.el).closest("div.media-toolbar"),e=this.filters[this.el.value];if(e){this.model.set(e.props,{silent:true});d("#mla-search-submit",f).click()}}});wp.media.view.AttachmentFilters.MlaUploaded=wp.media.view.AttachmentFilters.extend({createFilters:function(){var f=this.model.get("type"),e=wp.media.view.settings.mimeTypes,i,h=this.controller._state,g={};if(e&&f){i=e[f]}_.each(mlaModal.settings.uploadMimeTypes||{},function(k,j){if(("grid"===mlaModal.settings.screen)||("trash"!==j)){g[j]={text:k,props:{type:j,uploadedTo:null,orderby:"date",order:"DESC"}}}});g.all={text:i||wp.media.view.l10n.allMediaItems,props:{uploadedTo:null,orderby:"date",order:"DESC"},priority:10};g.uploaded={text:wp.media.view.l10n.uploadedToThisPost,props:{type:null,uploadedTo:wp.media.view.settings.post.id,orderby:"menuOrder",order:"ASC"},priority:20};g.unattached={text:wp.media.view.l10n.unattached,props:{uploadedTo:0,orderby:"menuOrder",order:"ASC"},priority:50};this.filters=g;if("undefined"===typeof g[mlaModal.settings.query[h].filterUploaded]){mlaModal.settings.query[h].filterUploaded="all"}if(mlaModal.settings.query[h].filterUploaded!="all"){this.model.set(g[mlaModal.settings.query[h].filterUploaded].props,{silent:false})}},select:function(){var h=this.controller._state,e=this.model,g=mlaModal.settings.query[h].filterMime,f=e.toJSON();if(false===mlaModal.settings.enableSearchBox){if("string"==typeof f.search){mlaModal.settings.query[h].searchValue=f.search}else{mlaModal.settings.query[h].searchValue=""}}_.find(this.filters,function(j,k){var i=_.all(j.props,function(m,l){return m===(_.isUndefined(f[l])?null:f[l])});if(i){return g=k}});this.$el.val(g)},change:function(){var f=d(this.el).closest("div.media-toolbar"),e=this.filters[this.el.value];if(e){this.model.set(e.props,{silent:true});d("#mla-search-submit",f).click()}}})}if(mlaModal.settings.enableMonthsDropdown){wp.media.view.AttachmentFilters.MlaMonths=wp.media.view.AttachmentFilters.extend({className:"attachment-filters",id:"media-attachment-date-filters",createFilters:function(){var f=this.controller._state,e={};_.each(mlaModal.settings.months||{},function(h,g){e[g]={text:h,props:{s:{mla_filter_month:g}}}});this.filters=e;if("undefined"===typeof e[mlaModal.settings.query[f].filterMonth]){mlaModal.settings.query[f].filterMonth=0}if(mlaModal.settings.query[f].filterMonth>0){this.model.set(e[mlaModal.settings.query[f].filterMonth].props,{silent:false})}},select:function(){var h=this.controller._state,e=this.model,g=mlaModal.settings.query[h].filterMonth,f=e.toJSON();if(_.isUndefined(f.s)){f.s={}}if(false===mlaModal.settings.enableSearchBox){if("string"==typeof f.search){mlaModal.settings.query[h].searchValue=f.search}else{mlaModal.settings.query[h].searchValue=""}}if(_.isUndefined(f.s.mla_filter_month)){f.s.mla_filter_month=mlaModal.settings.query[h].filterMonth}else{mlaModal.settings.query[h].filterMonth=f.s.mla_filter_month}_.find(this.filters,function(j,k){var i=_.all(j.props,function(l){return l.mla_filter_month==mlaModal.settings.query[h].filterMonth});if(i){return g=k}});this.$el.val(g)},change:function(){var e=this.filters[this.el.value],f;if(e){f={s:{mla_filter_month:e.props.s.mla_filter_month}};this.model.set(f)}}})}if(mlaModal.settings.enableTermsDropdown){wp.media.view.AttachmentFilters.MlaTerms=wp.media.view.AttachmentFilters.extend({className:"attachment-filters",id:"media-attachment-term-filters",createFilters:function(){var h=this.controller._state,e,f,g={};_.each(mlaModal.settings.termsText||{},function(j,i){if(mlaModal.settings.termsCustom){f=mlaModal.settings.termsValue[i]}else{f=parseInt(mlaModal.settings.termsValue[i])}g[i]={text:j,props:{s:{mla_filter_term:f}}}});this.filters=g;e=_.indexOf(mlaModal.settings.termsValue,mlaModal.settings.query[h].filterTerm);if(e>0){this.model.set(g[e].props,{silent:false})}},select:function(){var h=this.controller._state,e=this.model,g=mlaModal.settings.query[h].filterTerm,f=e.toJSON();if(_.isUndefined(f.s)){f.s={}}if(false===mlaModal.settings.enableSearchBox){if("string"==typeof f.search){mlaModal.settings.query[h].searchValue=f.search}else{mlaModal.settings.query[h].searchValue=""}}if(_.isUndefined(f.s.mla_filter_term)){f.s.mla_filter_term=mlaModal.settings.query[h].filterTerm}else{mlaModal.settings.query[h].filterTerm=f.s.mla_filter_term}_.find(this.filters,function(j,k){var i=_.all(j.props,function(l){return l.mla_filter_term==mlaModal.settings.query[h].filterTerm});if(i){return g=k}});this.$el.val(g)},change:function(){var e=this.filters[this.el.value],f;if(e){f={s:{mla_filter_term:e.props.s.mla_filter_term}};this.model.set(f)}}})}if(mlaModal.settings.enableTermsSearch){wp.media.view.MlaTermsSearch=wp.media.View.extend({tagName:"span",className:"mla-terms-search",template:wp.media.template("mla-terms-search-button"),attributes:{type:"mla-terms-search-button"},events:{change:"termsSearchOpen",click:"termsSearchOpen"},render:function(){this.$el.html(this.template(mlaModal.strings));return this},termsSearchOpen:function(f){var e=d(this.el).closest("div.media-toolbar");if(("click"==f.type)&&("mla_terms_search"===f.target.name)){mlaTaxonomy.termsSearch.open();d("#mla-terms-search-form").off("submit");d("#mla-terms-search-form").submit(function(j){var g,i,h={phrases:"",taxonomies:[]};j.preventDefault();g=d("#mla-terms-search-form").serializeArray();for(i=0;i<g.length;i++){switch(g[i].name){case"mla_terms_search[phrases]":h.phrases=g[i].value;break;case"mla_terms_search[radio_phrases]":h.radio_phrases=g[i].value;break;case"mla_terms_search[radio_terms]":h.radio_terms=g[i].value;break;case"mla_terms_search[taxonomies][]":h.taxonomies[h.taxonomies.length]=g[i].value;break}}mlaModal.settings.query[mlaModal.settings.state].termsSearch=h;d("#mla-search-submit",e).click();return false});d("#mla-terms-search-input").keypress(function(g){if(13==g.which){g.preventDefault();d("#mla-terms-search-submit").click()}})}}})}if(mlaModal.settings.enableSearchBox){wp.media.view.MlaSearch=wp.media.View.extend({tagName:"div",className:"mla-search-box",template:wp.media.template("mla-search-box"),attributes:{type:"mla-search-box"},events:{input:"search",change:"search",click:"search",search:"search",MlaSearch:"search"},initialize:function(){var e=this.controller._state;if("undefined"===typeof mlaModal.settings.query[e]){mlaModal.settings.query[e]=_.clone(mlaModal.settings.query.initial);mlaModal.settings.query[e].searchFields=_.clone(mlaModal.settings.query.initial.searchFields)}},render:function(){var f=this.controller._state,e=_.extend(mlaModal.strings,mlaModal.settings.query[f]);this.$el.html(this.template(e));return this},search:function(g){var h=this.controller._state,e,i,f;if(("input"==g.type)&&("s[mla_search_value]"==g.target.name)){mlaModal.settings.query[h].searchValue=g.target.value;return}if(("click"==g.type)&&("mla_search_submit"!=g.target.name)){return}switch(g.target.name){case"s[mla_search_value]":mlaModal.settings.query[h].searchValue=g.target.value;break;case"mla_search_submit":e={mla_filter_month:mlaModal.settings.query[h].filterMonth,mla_filter_term:mlaModal.settings.query[h].filterTerm,mla_terms_search:mlaModal.settings.query[h].termsSearch,mla_search_clicks:mlaModal.settings.query[h].searchClicks++,mla_search_value:mlaModal.settings.query[h].searchValue,mla_search_fields:mlaModal.settings.query[h].searchFields,mla_search_connector:mlaModal.settings.query[h].searchConnector};this.model.set({s:e});break;case"s[mla_search_connector]":mlaModal.settings.query[h].searchConnector=g.target.value;break;case"s[mla_search_title]":i=mlaModal.settings.query[h].searchFields;f=i.indexOf("title");if(-1==f){i.push("title")}else{i.splice(f,1)}mlaModal.settings.query[h].searchFields=i;break;case"s[mla_search_name]":f=mlaModal.settings.query[h].searchFields.indexOf("name");if(-1==f){mlaModal.settings.query[h].searchFields.push("name")}else{mlaModal.settings.query[h].searchFields.splice(f,1)}break;case"s[mla_search_alt_text]":f=mlaModal.settings.query[h].searchFields.indexOf("alt-text");if(-1==f){mlaModal.settings.query[h].searchFields.push("alt-text")}else{mlaModal.settings.query[h].searchFields.splice(f,1)}break;case"s[mla_search_excerpt]":f=mlaModal.settings.query[h].searchFields.indexOf("excerpt");if(-1==f){mlaModal.settings.query[h].searchFields.push("excerpt")}else{mlaModal.settings.query[h].searchFields.splice(f,1)}break;case"s[mla_search_content]":f=mlaModal.settings.query[h].searchFields.indexOf("content");if(-1==f){mlaModal.settings.query[h].searchFields.push("content")}else{mlaModal.settings.query[h].searchFields.splice(f,1)}break;case"s[mla_search_file]":f=mlaModal.settings.query[h].searchFields.indexOf("file");if(-1==f){mlaModal.settings.query[h].searchFields.push("file")}else{mlaModal.settings.query[h].searchFields.splice(f,1)}break;case"s[mla_search_terms]":f=mlaModal.settings.query[h].searchFields.indexOf("terms");if(-1==f){mlaModal.settings.query[h].searchFields.push("terms")}else{mlaModal.settings.query[h].searchFields.splice(f,1)}break}}})}else{wp.media.view.MlaSearch=wp.media.View.extend({tagName:"span",className:"mla-simulate-search-button",template:wp.media.template("mla-simulate-search-button"),attributes:{type:"mla-simulate-search-button"},events:{click:"simulateSearch"},render:function(){this.$el.html(this.template(mlaModal.strings));return this},simulateSearch:function(){var f=this.controller._state,e={mla_filter_month:mlaModal.settings.query[f].filterMonth,mla_filter_term:mlaModal.settings.query[f].filterTerm,mla_terms_search:mlaModal.settings.query[f].termsSearch,mla_search_clicks:mlaModal.settings.query[f].searchClicks++,mla_search_value:mlaModal.settings.query[f].searchValue,mla_search_fields:mlaModal.settings.query[f].searchFields,mla_search_connector:mlaModal.settings.query[f].searchConnector};this.model.set({s:e})}})}if(mlaModal.settings.enableMimeTypes||mlaModal.settings.enableMonthsDropdown||mlaModal.settings.enableTermsDropdown||mlaModal.settings.enableTermsSearch||mlaModal.settings.enableSearchBox){wp.media.view.AttachmentsBrowser=wp.media.view.AttachmentsBrowser.extend({createToolbar:function(){var e,f=this.controller._state;mlaModal.settings.state=f;mlaModal.settings.$el=this.controller.$el;if("undefined"===typeof mlaModal.settings.query[f]){mlaModal.settings.query[f]=_.clone(mlaModal.settings.query.initial);mlaModal.settings.query[f].searchFields=_.clone(mlaModal.settings.query.initial.searchFields)}c.prototype.createToolbar.apply(this,arguments);mlaModal.utility.mlaAttachmentsBrowser=this;e=this.options.filters;if(typeof window.eml!=="undefined"){d(".media-toolbar",this.$el).css("overflow","hidden")}if(("all"===e)&&mlaModal.settings.enableMimeTypes){this.toolbar.unset("filters",{silent:true});this.toolbar.set("filters",new wp.media.view.AttachmentFilters.Mla({controller:this.controller,model:this.collection.props,priority:-80}).render())}if(("uploaded"===e)&&mlaModal.settings.enableMimeTypes){this.toolbar.unset("filters",{silent:true});this.toolbar.set("filters",new wp.media.view.AttachmentFilters.MlaUploaded({controller:this.controller,model:this.collection.props,priority:-80}).render())}if(this.options.search&&mlaModal.settings.enableMonthsDropdown){this.toolbar.unset("dateFilter",{silent:true});this.toolbar.set("dateFilter",new wp.media.view.AttachmentFilters.MlaMonths({controller:this.controller,model:this.collection.props,priority:-75}).render())}if(this.options.search&&mlaModal.settings.enableTermsDropdown){this.toolbar.set("terms",new wp.media.view.AttachmentFilters.MlaTerms({controller:this.controller,model:this.collection.props,priority:-50}).render())}if(this.options.search&&mlaModal.settings.enableTermsSearch){this.toolbar.set("termsSearch",new wp.media.view.MlaTermsSearch({controller:this.controller,model:this.collection.props,priority:-50}).render())}if(this.options.search){if(mlaModal.settings.enableSearchBox){this.controller.on("content:activate",this.hideDefaultSearch);this.controller.on("edit:activate",this.hideDefaultSearch);this.controller.on("router:render",this.hideDefaultSearch);this.controller.on("uploader:ready",this.hideDefaultSearch);this.toolbar.set("MlaSearch",new wp.media.view.MlaSearch({controller:this.controller,model:this.collection.props,priority:60}).render())}else{this.toolbar.set("MlaSearch",new wp.media.view.MlaSearch({controller:this.controller,model:this.collection.props,priority:70}).render())}}},hideDefaultSearch:function(){var e=d("#media-search-input",mlaModal.settings.$el);if(0===e.length){e=d("div.media-toolbar-primary > input.search",mlaModal.settings.$el)}e.hide()},updateFilters:function(e,f){var g={};if(this.options.search&&mlaModal.settings.enableTermsDropdown&&mlaModal.settings.termsTaxonomy==e){g=mlaModal.utility.parseTermsOptions(f);mlaModal.settings.termsClass=g.termsClass;mlaModal.settings.termsText=g.termsText;mlaModal.settings.termsValue=g.termsValue;this.toolbar.unset("terms",{silent:true});this.toolbar.set("terms",new wp.media.view.AttachmentFilters.MlaTerms({controller:this.controller,model:this.collection.props,priority:-80}).render())}}})}mlaModal.utility.parseTermsOptions=function(k){var j={termsClass:[mlaModal.settings.termsClass[0],mlaModal.settings.termsClass[1]],termsText:[mlaModal.settings.termsText[0],mlaModal.settings.termsText[1]],termsValue:[mlaModal.settings.termsValue[0],mlaModal.settings.termsValue[1]]},g=2,e,f,i=/\<option(( class=\"([^\"]+)\" )|( ))value=((\'([^\']+)\')|(\"([^\"]+)\"))([^\>]*)\>([^\<]*)\<.*/g,h=[];if("object"===typeof k){g=mlaModal.settings.termsValue.length;for(e=2;e<g;e++){h[e]={termsClass:mlaModal.settings.termsClass[e],termsText:mlaModal.settings.termsText[e],termsValue:mlaModal.settings.termsValue[e]};if("undefined"!==typeof k[mlaModal.settings.termsValue[e]]){delete k[mlaModal.settings.termsValue[e]]}}for(f in k){h[e++]={termsClass:"level-0",termsText:k[f],termsValue:f.toString()}}if(g===e){return{termsClass:mlaModal.settings.termsClass,termsText:mlaModal.settings.termsText,termsValue:mlaModal.settings.termsValue}}h.sort(function(m,l){if(m.termsText>l.termsText){return 1}else{if(m.termsText<l.termsText){return -1}else{return 0}}});e=2;for(f in h){j.termsClass[e]=h[f].termsClass;j.termsText[e]=h[f].termsText;j.termsValue[e++]=h[f].termsValue}return j}h=i.exec(k);while(null!==(h=i.exec(k))){j.termsClass[g]=h[3];j.termsValue[g]=("undefined"===typeof h[6])?h[9]:h[7];j.termsText[g++]=h[11].replace("&nbsp;",mlaModal.settings.termsIndent)}return j};mlaModal.utility.arrayCleanup=function(g){var f=[],e=("string"===typeof g);if(e){g=g.split(mlaModal.settings.comma)}jQuery.each(g,function(h,i){i=jQuery.trim(i);if(i&&jQuery.inArray(i,f)==-1){f.push(i)}});f.sort();if(e){f=f.join(mlaModal.settings.comma)}return f};mlaModal.utility.parseTaxonomyId=function(f){var e=f.split("-");e.shift();e.shift();return e.join("-")};mlaModal.tagBox={cleanTags:function(f){var e=mlaModal.settings.comma;if(","!==e){f=f.replace(new RegExp(e,"g"),",")}f=f.replace(/\s*,\s*/g,",").replace(/,+/g,",").replace(/[,\s]+$/,"").replace(/^[,\s]+/,"");if(","!==e){f=f.replace(/,/g,e)}return f},parseTags:function(h){var l=h.id,f=l.split("-check-num-")[1],i=d(h).closest(".tagsdiv"),k=i.find(".the-tags"),e=mlaModal.settings.comma,g=k.val().split(e),j=[];delete g[f];d.each(g,function(m,n){n=d.trim(n);if(n){j.push(n)}});k.val(this.cleanTags(j.join(e)));this.quickClicks(i);return false},quickClicks:function(g){var j=d(".the-tags",g),h=d(".tagchecklist",g),i=d(g).attr("id"),e,f;if(!j.length){return}f=j.prop("disabled");e=j.val().split(mlaModal.settings.comma);h.empty();d.each(e,function(l,n){var m,k;n=d.trim(n);if(!n){return}m=d("<span />").text(n);if(!f){k=d('<a id="'+i+"-check-num-"+l+'" class="ntdelbutton">X</a>');k.click(function(){mlaModal.tagBox.parseTags(this)});m.prepend("&nbsp;").prepend(k)}h.append(m)})},flushTags:function(k,h,g){var m,e,i,n=d(".the-tags",k),j=d("input.newtag",k),l=mlaModal.settings.comma;h=h||false;i=h?d(h).text():j.val();m=n.val();e=m?m+l+i:i;e=mlaModal.utility.arrayCleanup(this.cleanTags(e));n.val(e);this.quickClicks(k);if(!h){j.val("")}if("undefined"==typeof(g)){j.focus()}return false},getCloud:function(f,e){d.post(ajaxurl,{action:"get-tagcloud",tax:e},function(h,g){if(0===h||"success"!=g){h=wpAjax.broken}h=d('<p id="tagcloud-'+e+'" class="the-tagcloud">'+h+"</p>");d("a",h).click(function(){mlaModal.tagBox.flushTags(d(this).closest(".mla-taxonomy-field").children(".tagsdiv"),this);return false});d("#"+f).after(h)})},init:function(i,e,g){var h,f;h=d("#mla-taxonomy-"+e,g);f=d("div.ajaxtag",h);mlaModal.tagBox.quickClicks(h);d("input.tagadd",f).click(function(){mlaModal.tagBox.flushTags(d(this).closest(".tagsdiv"))});d("input.newtag",f).keyup(function(j){if(13==j.which){mlaModal.tagBox.flushTags(h);return false}}).keypress(function(j){if(13==j.which){j.preventDefault();return false}}).each(function(){d(this).suggest(ajaxurl+"?action=ajax-tag-search&tax="+e,{delay:500,resultsClass:"mla_ac_results",selectClass:"mla_ac_over",matchClass:"mla_ac_match",minchars:2,multiple:true,multipleSep:mlaModal.settings.comma+" "})});h.siblings(":first").click(function(){mlaModal.tagBox.getCloud(d("a",this).attr("id"),e);d("a",this).unbind().click(function(){d(this).siblings(".the-tagcloud").toggle();return false});return false});d(".compat-field-"+e+" td",g).on("mouseleave",function(){var m,k=this,j=mlaModal.utility.arrayCleanup(d(".server-tags",k).val()),l=mlaModal.utility.arrayCleanup(d(".the-tags",k).val());if(j===l){return}d(k).css("opacity","0.5");m={id:i};m[e]=l;wp.media.post(mlaModal.settings.ajaxUpdateCompatAction,m).done(function(o){var p,n,q;for(n in o){if("object"===typeof(o[n]["object-terms"])){if(null!==mlaModal.utility.mlaAttachmentsBrowser){mlaModal.utility.mlaAttachmentsBrowser.updateFilters(n,o[n]["object-terms"])}delete o[n]["object-terms"]}for(q in o[n]){d("#"+q,k).replaceWith(o[n][q])}p=d("#mla-taxonomy-"+n,k);mlaModal.tagBox.quickClicks(p)}d(k).css("opacity","1.0")})});h.on("change",function(j){j.stopPropagation();return false});d(".the-tags, .server-tags .newtag",h).on("change",function(j){j.stopPropagation();return false})}};if(mlaModal.settings.enableDetailsCategory||mlaModal.settings.enableDetailsTag){wp.media.view.AttachmentCompat=wp.media.view.AttachmentCompat.extend({initialize:function(){b.prototype.initialize.apply(this,arguments);this.on("ready",function(){mlaModal.utility.hookCompatTaxonomies(this.model.get("id"),this.el)})}})}if(mlaModal.settings.enableDetailsCategory||mlaModal.settings.enableDetailsTag){wp.media.model.Selection=wp.media.model.Selection.extend({initialize:function(){a.prototype.initialize.apply(this,arguments);this.on("selection:reset",function(){mlaModal.cid=null});this.on("selection:unsingle",function(){mlaModal.cid=null});this.on("selection:single",function(e){mlaModal.cid=e.cid});this.on("change:uploading",function(){mlaModal.uploading=true});this.on("change",function(e){var f=false,g;if(mlaModal.uploading&&mlaModal.cid===e.cid){mlaModal.uploading=false;f=true}else{if(false===e.attributes.uploading){g=_.clone(e.changed);delete g.title;delete g.caption;delete g.alt;delete g.description;if(!_.isEmpty(g)){f=true}}}if(true===f){mlaModal.utility.hookCompatTaxonomies(e.get("id"),mlaModal.settings.$el)}})}})}mlaModal.utility.hookCompatTaxonomies=function(h,f){var e,g=null;d(".mla-taxonomy-field .categorydiv",f).each(function(){e=mlaModal.utility.parseTaxonomyId(d(this).attr("id"));if(-1!=mlaModal.settings.enhancedTaxonomies.indexOf(e)){d(".compat-field-"+e+" th",f).click({id:h,currentTaxonomy:e,el:f},function(i){mlaModal.utility.fillCompatTaxonomies(i.data)});d("tr.compat-field-"+e,f).each(function(){if(d(this).hasClass("mla-taxonomy-row")){d(this).show()}else{d(this).remove()}});if(null===g){g=e}}else{d("tr.compat-field-"+e,f).each(function(){if(d(this).hasClass("mla-taxonomy-row")){d(this).remove()}})}});d(".mla-taxonomy-field .tagsdiv",f).each(function(){e=mlaModal.utility.parseTaxonomyId(d(this).attr("id"));if(-1!=mlaModal.settings.enhancedTaxonomies.indexOf(e)){d(".compat-field-"+e+" th",f).click({id:h,currentTaxonomy:e,el:f},function(i){mlaModal.utility.fillCompatTaxonomies(i.data)});d("tr.compat-field-"+e,f).each(function(){if(d(this).hasClass("mla-taxonomy-row")){d(this).show()}else{d(this).remove()}});if(null===g){g=e}}else{d("tr.compat-field-"+e,f).each(function(){if(d(this).hasClass("mla-taxonomy-row")){d(this).remove()}})}});if(mlaModal.settings.enableTermsAutofill&&null!==g){d(".compat-field-"+g+" th",f).click()}};mlaModal.utility.fillCompatTaxonomies=function(i){var f=i.el,h=[],e,g;d(".mla-taxonomy-field .categorydiv",f).each(function(){e=mlaModal.utility.parseTaxonomyId(d(this).attr("id"));h[h.length]=e;g=".compat-field-"+e;if("undefined"===typeof(mlaModal.initialHTML[e])){mlaModal.initialHTML[e]=d(g,f).html()}else{d(g,f).html(mlaModal.initialHTML[e])}d(g+" .categorydiv",f).html(mlaModal.strings.loadingText)});d(".mla-taxonomy-field .tagsdiv",f).each(function(){e=mlaModal.utility.parseTaxonomyId(d(this).attr("id"));h[h.length]=e;g=".compat-field-"+e;if("undefined"===typeof(mlaModal.initialHTML[e])){mlaModal.initialHTML[e]=d(g,f).html()}else{d(g,f).html(mlaModal.initialHTML[e])}d(g+" .tagsdiv",f).html(mlaModal.strings.loadingText)});if(h.length){wp.media.post(mlaModal.settings.ajaxFillCompatAction,{id:i.id,query:h}).done(function(k){var j,l;for(j in k){l=".compat-field-"+j;d(l,f).html(k[j])}mlaModal.utility.supportCompatTaxonomies(i);d(".compat-field-"+i.currentTaxonomy+" td",f).show()})}};mlaModal.utility.supportCompatTaxonomies=function(g){var f=g.id,e=g.el;if(mlaModal.settings.enableDetailsCategory){d(".mla-taxonomy-field .categorydiv",e).each(function(){var j=d(this),h,k,i,n,l,p,o,m;i=mlaModal.utility.parseTaxonomyId(d(this).attr("id"));n=i+"_tab";l="#mla-"+i;p="#mla-new-"+i;o="#mla-search-"+i;m="#mla-attachments-"+f+"-"+i;if(i=="category"){n="cats"}j.find(".category-tabs").show();d(".compat-field-"+i+" th",e).click(function(){d(this).siblings("td").slideToggle()});j.on("mouseleave",function(){var t,q,s=[],r=j.find(l+"-checklist input:checked");r.each(function(){s[s.length]=d(this).val()});s.sort(function(v,u){return v-u});s=s.join(",");q=j.siblings(m).val();if(q===s){return}j.siblings(m).val(s);j.prop("disabled",true);t={id:f};t[i]=s;wp.media.post(mlaModal.settings.ajaxUpdateCompatAction,t).done(function(v){var u,w;for(u in v){for(w in v[u]){j.find("#"+w).html(v[u][w])}}j.find(o).val("");j.find(l+"-searcher").addClass("mla-hidden-children");j.prop("disabled",false)})});j.on('change input[type="checkbox"]',function(q){q.stopPropagation();return false});j.find(l+"-tabs a").click(function(){var q=d(this).attr("href");d(this).parent().addClass("tabs").siblings("li").removeClass("tabs");j.find(l+"-tabs").siblings(".tabs-panel").hide();j.find(q).show();d(this).focus();if("#mla-"+i+"-all"==q){deleteUserSetting(n)}else{setUserSetting(n,"pop")}return false});if(getUserSetting(n)){j.find(l+'-tabs a[href="#mla-'+i+'-pop"]').click()}j.find(l+"-add-toggle").click(function(){j.find(l+"-searcher").addClass("mla-hidden-children");j.find(l+"-adder").toggleClass("mla-hidden-children");j.find(l+'-tabs a[href="#mla-'+i+'-all"]').click();j.find(l+"-checklist li").show();j.find(l+"-checklist-pop li").show();if(false===j.find(l+"-adder").hasClass("mla-hidden-children")){j.find(p).val("").removeClass("form-input-tip");j.find(p).focus()}return false});j.find(p).keypress(function(q){if(13===q.keyCode){q.preventDefault();j.find(l+"-add-submit").click()}});j.find(l+"-add-submit").click(function(){j.find(p).focus()});h=function(q){if(!j.find(p).val()){return false}q.data+="&"+j.find(l+"-checklist :checked").serialize();j.prop("disabled",true);return q};k=function(v,u){var t,q=j.find("#new"+i+"_parent");j.prop("disabled",false);if("undefined"!=u.parsed.responses[0]&&(t=u.parsed.responses[0].supplemental.newcat_parent)){q.before(t);q.remove();if(null!==mlaModal.utility.mlaAttachmentsBrowser){mlaModal.utility.mlaAttachmentsBrowser.updateFilters(i,t)}}};j.find(l+"-checklist").wpList({alt:"",response:"mla-"+i+"-ajax-response",addBefore:h,addAfter:k});j.find(l+"-checklist, "+l+"-checklist-pop").on("click",'li.popular-category > label input[type="checkbox"]',function(){var q=d(this),s=q.is(":checked"),r=q.val();if(r&&q.parents("#mla-taxonomy-"+i).length){d("#in-"+i+"-"+r+", #in-popular-"+i+"-"+r).prop("checked",s)}});d.extend(d.expr[":"],{matchTerms:function(s,r,q,t){return(s.textContent||s.innerText||"").toLowerCase().indexOf((q[3]||"").toLowerCase())>=0}});j.find(o).keypress(function(q){if(13===q.keyCode){q.preventDefault();j.find(o).val("");j.find(l+"-searcher").addClass("mla-hidden-children");j.find(l+"-checklist li").show();j.find(l+"-checklist-pop li").show();return}});j.find(o).keyup(function(s){var u,t,v,r,q;if(13===s.keyCode){s.preventDefault();j.find(l+"-search-toggle").focus();return}u=j.find(o).val();t=j.find(l+"-checklist li");v=j.find(l+"-checklist-pop li");if(0<u.length){t.hide();v.hide()}else{t.show();v.show()}r=j.find(l+"-checklist label:matchTerms('"+u+"')");r.closest("li").find("li").andSelf().show();r.parents(l+"-checklist li").show();q=j.find(l+"-checklist-pop label:matchTerms('"+u+"')");q.closest("li").find("li").andSelf().show();q.parents(l+"-checklist li").show()});j.find(l+"-search-toggle").click(function(){j.find(l+"-adder ").addClass("mla-hidden-children");j.find(l+"-searcher").toggleClass("mla-hidden-children");j.find(l+'-tabs a[href="#mla-'+i+'-all"]').click();j.find(l+"-checklist li").show();j.find(l+"-checklist-pop li").show();if(false===j.find(l+"-searcher").hasClass("mla-hidden-children")){j.find(o).val("").removeClass("form-input-tip");j.find(o).focus()}return false})})}if(mlaModal.settings.enableDetailsTag){d(".mla-taxonomy-field .tagsdiv",e).each(function(){var h=mlaModal.utility.parseTaxonomyId(d(this).attr("id"));d(".compat-field-"+h+" th",e).click(function(){d(this).siblings("td").slideToggle()});mlaModal.tagBox.init(f,h,e)})}}}(jQuery));
js/mla-settings-shortcodes-tab-scripts.js ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var jQuery,
2
+ mla_shortcodes_tab_vars,
3
+ mlaShortcodes = {
4
+ // Properties
5
+ // mlaShortcodes.settings.definitions
6
+ // mlaShortcodes.settings.sectionText
7
+ settings: {},
8
+
9
+ // Utility functions
10
+ utility: {
11
+ getId : function( o ) {
12
+ var id = jQuery( o ).closest( 'tr' ).attr( 'id' ),
13
+ parts = id.split( '-' );
14
+ return parts[ parts.length - 1 ];
15
+ }
16
+ },
17
+
18
+ // Components
19
+ addTemplate: null
20
+ };
21
+
22
+ ( function( $ ) {
23
+ // Localized settings and strings
24
+ mlaShortcodes.settings = typeof mla_shortcodes_tab_vars === 'undefined' ? {} : mla_shortcodes_tab_vars;
25
+ mla_shortcodes_tab_vars = void 0; // delete won't work on Globals
26
+ mlaShortcodes.settings.sectionText = [];
27
+
28
+ mlaShortcodes.addTemplate = {
29
+ init : function(){
30
+ var t = this, templateForm = $( '#mla-edit-template' );
31
+
32
+ $( '#mla-template-type, #mla-template-shortcode', templateForm ).change( function( e ){
33
+ var type = $( '#mla-template-type', templateForm ).val(),
34
+ shortcode = $( '#mla-template-shortcode', templateForm ).val();
35
+
36
+ e.preventDefault();
37
+ t.fillSections( type, shortcode, templateForm );
38
+ });
39
+ },
40
+
41
+ fillSections : function( type, shortcode, templateForm ){
42
+ var oldType = $( '#mla-template-item-type', templateForm ).val(),
43
+ oldShortcode = $( '#mla-template-item-shortcode', templateForm ).val(),
44
+ oldClass = '.mla_section.mla_' + oldType + '.mla_' + oldShortcode;
45
+ newClass = '.mla_section.mla_' + type + '.mla_' + shortcode;
46
+
47
+ $( '#mla-template-item-type', templateForm ).val( type ),
48
+ $( '#mla-template-item-shortcode', templateForm ).val( shortcode ),
49
+
50
+ // Remove old sections, saving their values for reuse
51
+ $( oldClass, templateForm ).each( function( index ) {
52
+ var id = $('textarea', this).attr('id'), value = $('textarea', this).val(),
53
+ prefix = 'mla-template-' + oldType + '-' + oldShortcode + '-',
54
+ slug = id.substring( prefix.length );
55
+
56
+ mlaShortcodes.settings.sectionText[ slug ] = value;
57
+ }); // oldClass.each
58
+
59
+ $( '.mla_section', templateForm ).hide();
60
+
61
+ if ( type == 'any' || shortcode == 'any' ) {
62
+ return;
63
+ }
64
+
65
+ // Fill section rows, with any saved values
66
+ $( newClass, templateForm ).each( function( index ) {
67
+ var id = $('textarea', this).attr('id'),
68
+ prefix = 'mla-template-' + type + '-' + shortcode + '-',
69
+ slug = id.substring( prefix.length );
70
+
71
+ if ( typeof mlaShortcodes.settings.sectionText[ slug ] !== 'undefined' ) {
72
+ $('textarea', this).val( mlaShortcodes.settings.sectionText[ slug ] );
73
+ }
74
+ }); // newClass.each
75
+
76
+ $( newClass, templateForm ).show();
77
+ },
78
+ }; // mlaShortcodes.addTemplate
79
+
80
+ $( document ).ready( function() {
81
+ mlaShortcodes.addTemplate.init();
82
+ });
83
+ })( jQuery );
js/mla-settings-shortcodes-tab-scripts.min.js CHANGED
File without changes