Media Library Assistant - Version 2.21

Version Description

  • Fix: A defect in the default "Orderby" setting has been fixed. This defect caused "empty grid", "No media attachments found", "No items found" and "Unknown column" symptoms. Thanks to all who quickly alerted me to the problem.
  • Fix: The "Featured Image" support for non-image Media Library items now respects the size=none parameter to substitute a text value for the thumbnail image.
Download this release

Release Info

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

Code changes from version 2.15 to 2.21

examples/mla-dynamic-references-example.php.txt ADDED
@@ -0,0 +1,650 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Updates custom field(s) "where-used" inserted-in and featured-image when an item is edited
4
+ *
5
+ * @package MLA Dynamic References Example
6
+ * @version 1.03
7
+ */
8
+
9
+ /*
10
+ Plugin Name: MLA Dynamic References Example
11
+ Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
12
+ Description: Updates custom field(s) "where-used" inserted-in and featured-image when an item is edited
13
+ Author: David Lingren
14
+ Version: 1.03
15
+ Author URI: http://fairtradejudaica.org/our-story/staff/
16
+
17
+ Copyright 2014 - 2015 David Lingren
18
+
19
+ This program is free software; you can redistribute it and/or modify
20
+ it under the terms of the GNU General Public License as published by
21
+ the Free Software Foundation; either version 2 of the License, or
22
+ (at your option) any later version.
23
+
24
+ This program is distributed in the hope that it will be useful,
25
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
+ GNU General Public License for more details.
28
+
29
+ You can get a copy of the GNU General Public License by writing to the
30
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
31
+ */
32
+
33
+ /*
34
+ *
35
+ */
36
+
37
+ /**
38
+ * Call it anything you want, but give it an unlikely and hopefully unique name. Hiding everything
39
+ * else inside a class means this is the only name you have to worry about.
40
+ *
41
+ * @package MLA Dynamic References Example
42
+ * @since 1.00
43
+ */
44
+ class MLADynamicReferencesExample {
45
+ /**
46
+ * Names of the custom field(s) to be maintained
47
+ *
48
+ * Enter the name of a custom field in each category you want to maintain.
49
+ * Enter an empty string or comment out each category you don't use.
50
+ *
51
+ * Set 'used_first_feature' and/or 'used_first_insert' to true if you want
52
+ * them to be the default selection in the Media Manager dropdown control.
53
+ *
54
+ * @since 1.00
55
+ *
56
+ * @var array
57
+ */
58
+ private static $field_names = array(
59
+ 'featured' => 'featured',
60
+ 'featured_in' => 'featured_in',
61
+ 'inserted' => 'inserted',
62
+ 'inserted_in' => 'inserted_in',
63
+ 'used' => 'used',
64
+ 'used_in' => 'used_in',
65
+ 'used_first_feature' => true,
66
+ 'used_first_insert' => true,
67
+ );
68
+
69
+ /**
70
+ * WordPress version test for $wpdb->esc_like() Vs esc_sql()
71
+ *
72
+ * @since 1.00
73
+ *
74
+ * @var boolean
75
+ */
76
+ private static $wp_4dot0_plus = true;
77
+
78
+ /**
79
+ * Initialization function, similar to __construct()
80
+ *
81
+ * @since 1.00
82
+ *
83
+ * @return void
84
+ */
85
+ public static function initialize() {
86
+ /*
87
+ * The filter is only needed in the Admin area
88
+ */
89
+ if ( ! is_admin() ) {
90
+ return;
91
+ }
92
+
93
+ self::$wp_4dot0_plus = version_compare( get_bloginfo('version'), '4.0', '>=' );
94
+
95
+ /*
96
+ * Defined in media-library-assistant/includes/class-mla-media-modal.php
97
+ * function mla_media_view_settings_filter
98
+ */
99
+ add_filter( 'mla_media_modal_initial_filters', 'MLADynamicReferencesExample::mla_media_modal_initial_filters', 10, 2 );
100
+ add_filter( 'mla_media_modal_settings', 'MLADynamicReferencesExample::mla_media_modal_settings', 10, 2 );
101
+
102
+ /*
103
+ * Defined in wp-includes/post.php function wp_insert_post
104
+ */
105
+ add_action( 'post_updated', 'MLADynamicReferencesExample::post_updated', 10, 3 );
106
+ add_action( 'wp_insert_post', 'MLADynamicReferencesExample::wp_insert_post', 10, 3 );
107
+
108
+ /*
109
+ * Defined in wp-includes/meta.php
110
+ */
111
+ add_action( 'added_post_meta', 'MLADynamicReferencesExample::added_post_meta', 10, 4 );
112
+
113
+ add_action( 'update_post_meta', 'MLADynamicReferencesExample::update_post_meta', 10, 4 );
114
+ add_action( 'updated_post_meta', 'MLADynamicReferencesExample::updated_post_meta', 10, 4 );
115
+
116
+ add_action( 'delete_post_meta', 'MLADynamicReferencesExample::delete_post_meta', 10, 4 );
117
+ add_action( 'deleted_post_meta', 'MLADynamicReferencesExample::deleted_post_meta', 10, 4 );
118
+ }
119
+
120
+ /**
121
+ * Add the "Available" view to the Set Featured Image dropdown control
122
+ *
123
+ * @since 1.01
124
+ *
125
+ * @param array $initial_values Settings passed to the Media Manager Modal Window scripts.
126
+ * @param WP_Post $post Post object in which the MMMW is embeded.
127
+ */
128
+ public static function mla_media_modal_initial_filters( $initial_values, $post ) {
129
+ //error_log( __LINE__ . " mla_media_modal_settings post = " . var_export( $post, true ), 0 );
130
+
131
+ if ( ! empty( self::$field_names['used'] ) ) {
132
+ if ( self::$field_names['used_first_feature'] && isset( $initial_values['filterUploaded'] ) ) {
133
+ $initial_values['filterUploaded'] = 'custom:' . self::$field_names['used'] . ',null';
134
+ }
135
+
136
+ if ( self::$field_names['used_first_insert'] && isset( $initial_values['filterMime'] ) ) {
137
+ $initial_values['filterMime'] = 'custom:' . self::$field_names['used'] . ',null';
138
+ }
139
+ }
140
+
141
+ //error_log( __LINE__ . " mla_media_modal_settings initial_values = " . var_export( $initial_values, true ), 0 );
142
+ return $initial_values;
143
+ }
144
+
145
+ /**
146
+ * Add the "Available" view to the Set Featured Image dropdown control
147
+ *
148
+ * @since 1.01
149
+ *
150
+ * @param array $settings Settings passed to the Media Manager Modal Window scripts.
151
+ * @param WP_Post $post Post object in which the MMMW is embeded.
152
+ */
153
+ public static function mla_media_modal_settings( $settings, $post ) {
154
+ //error_log( __LINE__ . " mla_media_modal_settings settings = " . var_export( $settings, true ), 0 );
155
+ //error_log( __LINE__ . " mla_media_modal_settings post = " . var_export( $post, true ), 0 );
156
+
157
+ if ( ! empty( self::$field_names['used'] ) ) {
158
+ if ( isset( $settings['mla_settings'] ) && isset( $settings['mla_settings']['uploadMimeTypes'] ) ) {
159
+ $settings['mla_settings']['uploadMimeTypes']['custom:' . self::$field_names['used'] . ',null'] = 'Not Used';
160
+ $settings['mla_settings']['uploadMimeTypes']['custom:' . self::$field_names['used'] . '=*'] = 'Already Used';
161
+ }
162
+ }
163
+ //error_log( __LINE__ . " mla_media_modal_settings settings[mla_settings][uploadMimeTypes] = " . var_export( $settings['mla_settings']['uploadMimeTypes'], true ), 0 );
164
+
165
+ return $settings;
166
+ }
167
+
168
+ /**
169
+ * Analyze before and after content when an existing item is updated
170
+ *
171
+ * @since 1.00
172
+ *
173
+ * @param int $post_ID Post ID.
174
+ * @param WP_Post $post_after Post object following the update.
175
+ * @param WP_Post $post_before Post object before the update.
176
+ */
177
+ public static function post_updated( $post_ID, $post_after, $post_before ) {
178
+ //error_log( __LINE__ . " post_updated( {$post_ID} ) post_after = " . var_export( $post_after, true ), 0 );
179
+ if ( 'trash' == $post_after->post_status ) {
180
+ $after = array();
181
+ } else {
182
+ $after = self::_attachments_in( $post_after->post_content );
183
+ }
184
+
185
+ //error_log( __LINE__ . " post_updated( {$post_ID} ) post_before = " . var_export( $post_before, true ), 0 );
186
+ if ( 'trash' == $post_before->post_status ) {
187
+ $attachments_before = array();
188
+ } else {
189
+ $attachments_before = self::_attachments_in( $post_before->post_content );
190
+ }
191
+
192
+ // Eliminate unchanged attachments
193
+ $attachments_after = array();
194
+ foreach( $after as $ID ) {
195
+ if ( isset( $attachments_before[ $ID ] ) ) {
196
+ unset( $attachments_before[ $ID ] );
197
+ } else {
198
+ $attachments_after[ $ID ] = $ID;
199
+ }
200
+ }
201
+
202
+ self::_update_inserted_in( $attachments_after );
203
+ self::_update_inserted_in( $attachments_before );
204
+
205
+ if ( 'auto-draft' == $post_before->post_status ) {
206
+ if ( $attachment = get_post_meta( $post_ID, '_thumbnail_id', true ) ) {
207
+ self::_update_featured_in( $attachment );
208
+ }
209
+ }
210
+ }
211
+
212
+ /**
213
+ * Analyze post content when a new item is inserted i.e., $update == false
214
+ *
215
+ * @since 1.00
216
+ *
217
+ * @param int $post_ID Post ID.
218
+ * @param WP_Post $post Post object following the update.
219
+ * @param WP_Post $update true if updating, false if inserting.
220
+ */
221
+ public static function wp_insert_post( $post_ID, $post, $update ) {
222
+ //error_log( __LINE__ . " wp_insert_post( {$post_ID}, " . var_export( $update, true ) . " ) post = " . var_export( $post, true ), 0 );
223
+
224
+ if ( $update || in_array( $post->post_status, array( 'inherit', 'auto-draft' ) ) ) {
225
+ return;
226
+ }
227
+
228
+ $attachments = self::_attachments_in( $post->post_content );
229
+ self::_update_inserted_in( $attachments );
230
+ }
231
+
232
+ /**
233
+ * Fires immediately after meta of a specific type is added.
234
+ *
235
+ * @since 1.00
236
+ *
237
+ * @param int $mid The meta ID after successful update.
238
+ * @param int $object_id Object ID.
239
+ * @param string $meta_key Meta key.
240
+ * @param mixed $meta_value Meta value.
241
+ */
242
+ public static function added_post_meta( $mid, $object_id, $meta_key, $_meta_value ) {
243
+ //error_log( __LINE__ . " added_post_meta( {$object_id}, {$meta_key} ) _meta_value = " . var_export( $_meta_value, true ), 0 );
244
+
245
+ if ( '_thumbnail_id' == $meta_key ) {
246
+ self::_update_featured_in( $_meta_value );
247
+ }
248
+ }
249
+
250
+ /**
251
+ * Fires immediately before updating metadata of a specific type.
252
+ *
253
+ * @since 1.00
254
+ *
255
+ * @param int $meta_id ID of the metadata entry to update.
256
+ * @param int $object_id Object ID.
257
+ * @param string $meta_key Meta key.
258
+ * @param mixed $meta_value New meta value.
259
+ */
260
+ public static function update_post_meta( $meta_id, $object_id, $meta_key, $_meta_value ) {
261
+ if ( '_thumbnail_id' == $meta_key ) {
262
+ // $_meta_value contains the NEW value. Must get the old value ourselves.
263
+ self::$old_value = get_post_meta( $object_id, '_thumbnail_id', true );
264
+ //error_log( __LINE__ . " update_post_meta( {$object_id}, {$meta_key} ) old_value = " . var_export( self::$old_value, true ), 0 );
265
+ }
266
+ }
267
+
268
+ /**
269
+ * Featured Image value before update
270
+ *
271
+ * @since 1.00
272
+ *
273
+ * @var integer
274
+ */
275
+ private static $old_value = 0;
276
+
277
+ /**
278
+ * Fires immediately after updating metadata of a specific type.
279
+ *
280
+ * @since 1.00
281
+ *
282
+ * @param int $meta_id ID of updated metadata entry.
283
+ * @param int $object_id Object ID.
284
+ * @param string $meta_key Meta key.
285
+ * @param mixed $meta_value Meta value.
286
+ */
287
+ public static function updated_post_meta( $meta_id, $object_id, $meta_key, $_meta_value ) {
288
+ //error_log( __LINE__ . " updated_post_meta( {$object_id}, {$meta_key} ) _meta_value = " . var_export( $_meta_value, true ), 0 );
289
+
290
+ if ( '_thumbnail_id' == $meta_key ) {
291
+ if ( self::$old_value ) {
292
+ self::_update_featured_in( self::$old_value );
293
+ self::$old_value = 0;
294
+ }
295
+
296
+ self::_update_featured_in( $_meta_value );
297
+ }
298
+ }
299
+
300
+ /**
301
+ * Fires immediately before deleting metadata of a specific type.
302
+ *
303
+ * @since 1.00
304
+ *
305
+ * @param array $meta_ids An array of deleted metadata entry IDs.
306
+ * @param int $object_id Object ID.
307
+ * @param string $meta_key Meta key.
308
+ * @param mixed $meta_value Meta value.
309
+ */
310
+ public static function delete_post_meta( $meta_ids, $object_id, $meta_key, $_meta_value ){
311
+ if ( '_thumbnail_id' == $meta_key ) {
312
+ // $_meta_value contains nothing. Must get the old value ourselves.
313
+ self::$old_value = get_post_meta( $object_id, '_thumbnail_id', true );
314
+ //error_log( __LINE__ . " delete_post_meta( {$object_id}, {$meta_key} ) old_value = " . var_export( self::$old_value, true ), 0 );
315
+ }
316
+ }
317
+
318
+ /**
319
+ * Fires immediately after deleting metadata of a specific type.
320
+ *
321
+ * @since 1.00
322
+ *
323
+ * @param array $meta_ids An array of deleted metadata entry IDs.
324
+ * @param int $object_id Object ID.
325
+ * @param string $meta_key Meta key.
326
+ * @param mixed $meta_value Meta value.
327
+ */
328
+ public static function deleted_post_meta( $meta_ids, $object_id, $meta_key, $_meta_value ){
329
+ //error_log( __LINE__ . " deleted_post_meta( {$object_id}, {$meta_key} ) _meta_value = " . var_export( $_meta_value, true ), 0 );
330
+
331
+ if ( '_thumbnail_id' == $meta_key && self::$old_value ) {
332
+ self::_update_featured_in( self::$old_value );
333
+ self::$old_value = 0;
334
+ }
335
+ }
336
+
337
+ /**
338
+ * Update "Used/Used in" data for one attachment
339
+ *
340
+ * Called from _update_inserted_in and _update_featured_in.
341
+ *
342
+ * @since 1.00
343
+ *
344
+ * @param array $attachments attachment IDs ( ID => ID )
345
+ */
346
+ private static function _update_used_in( $ID, $inserts = NULL, $features = NULL ) {
347
+ //error_log( __LINE__ . " _update_used_in( {$ID} ) inserts = " . var_export( $inserts, true ), 0 );
348
+ //error_log( __LINE__ . " _update_used_in( {$ID} ) features = " . var_export( $features, true ), 0 );
349
+
350
+ if ( empty( self::$field_names['used_in'] ) && empty( self::$field_names['used'] ) ) {
351
+ return;
352
+ }
353
+
354
+ if ( empty( $inserts ) ) {
355
+ $inserts = self::_inserted_in( $ID );
356
+ }
357
+
358
+ if ( empty( $features ) ) {
359
+ $features = self::_featured_in( $ID );
360
+ }
361
+
362
+ $results = array();
363
+ $titles = array();
364
+ foreach ( $features as $post_id => $value ) {
365
+ if ( 'auto-draft' === $value->post_status ) {
366
+ continue;
367
+ }
368
+
369
+ $results[] = sprintf( '%1$s (%2$s %3$d)', $value->post_title, $value->post_type, $post_id );
370
+ $titles[] = $value->post_title;
371
+ }
372
+ $final_results = implode( ',', $results );
373
+ $final_titles = implode( ',', $titles );
374
+
375
+ $results = array();
376
+ $titles = array();
377
+ // $inserts is indexed on file name; need a second level
378
+ foreach ( $inserts as $files ) {
379
+ foreach ( $files as $value ) {
380
+ $results[] = sprintf( '%1$s (%2$s %3$d)', $value->post_title, $value->post_type, $value->ID );
381
+ $titles[] = $value->post_title;
382
+ }
383
+ }
384
+ $final_results = trim( $final_results . implode( ',', $results ) );
385
+ $final_titles = trim( $final_titles . implode( ',', $titles ) );
386
+
387
+ if ( ! empty( self::$field_names['used_in'] ) ) {
388
+ if ( empty( $final_results ) ) {
389
+ delete_metadata( 'post', $ID, self::$field_names['used_in'] );
390
+ } else {
391
+ update_metadata( 'post', $ID, self::$field_names['used_in'], $final_results );
392
+ }
393
+ }
394
+
395
+ if ( ! empty( self::$field_names['used'] ) ) {
396
+ if ( empty( $final_titles ) ) {
397
+ delete_metadata( 'post', $ID, self::$field_names['used'] );
398
+ } else {
399
+ update_metadata( 'post', $ID, self::$field_names['used'], $final_titles );
400
+ }
401
+ }
402
+ }
403
+
404
+ /**
405
+ * Update "Inserted in" data for one or more attachments
406
+ *
407
+ * @since 1.00
408
+ *
409
+ * @param array $attachments attachment IDs ( ID => ID )
410
+ */
411
+ private static function _update_inserted_in( $attachments ) {
412
+ //error_log( __LINE__ . " _update_inserted_in attachments = " . var_export( $attachments, true ), 0 );
413
+
414
+ if ( empty( $attachments ) ) {
415
+ return;
416
+ } elseif ( is_numeric( $attachments ) ) {
417
+ $attachments = absint( $attachments );
418
+ $attachments = array( $attachments => $attachments );
419
+ }
420
+
421
+ foreach ( $attachments as $ID ){
422
+ $inserts = self::_inserted_in( $ID );
423
+
424
+ $results = array();
425
+ $titles = array();
426
+ // $inserts is indexed on file name; need a second level
427
+ foreach ( $inserts as $files ) {
428
+ foreach ( $files as $value ) {
429
+ $results[] = sprintf( '%1$s (%2$s %3$d)', $value->post_title, $value->post_type, $value->ID );
430
+ $titles[] = $value->post_title;
431
+ }
432
+ }
433
+
434
+ if ( ! empty( self::$field_names['inserted_in'] ) ) {
435
+ if ( empty( $results ) ) {
436
+ delete_metadata( 'post', $ID, self::$field_names['inserted_in'] );
437
+ } else {
438
+ update_metadata( 'post', $ID, self::$field_names['inserted_in'], implode( ',', $results ) );
439
+ }
440
+ }
441
+
442
+ if ( ! empty( self::$field_names['inserted'] ) ) {
443
+ if ( empty( $titles ) ) {
444
+ delete_metadata( 'post', $ID, self::$field_names['inserted'] );
445
+ } else {
446
+ update_metadata( 'post', $ID, self::$field_names['inserted'], implode( ',', $titles ) );
447
+ }
448
+ }
449
+
450
+ self::_update_used_in( $ID, $inserts, NULL );
451
+ }
452
+ }
453
+
454
+ /**
455
+ * Update "Featured in" data for one or more attachments
456
+ *
457
+ * @since 1.00
458
+ *
459
+ * @param array $attachments attachment IDs ( ID => ID )
460
+ */
461
+ private static function _update_featured_in( $attachments ) {
462
+ //error_log( __LINE__ . " _update_featured_in attachments = " . var_export( $attachments, true ), 0 );
463
+
464
+ if ( empty( $attachments ) ) {
465
+ return;
466
+ } elseif ( is_numeric( $attachments ) ) {
467
+ $attachments = absint( $attachments );
468
+ $attachments = array( $attachments => $attachments );
469
+ }
470
+
471
+ foreach ( $attachments as $ID ){
472
+ $features = self::_featured_in( $ID );
473
+
474
+ $results = array();
475
+ $titles = array();
476
+ foreach ( $features as $post_id => $value ) {
477
+ if ( 'auto-draft' === $value->post_status ) {
478
+ continue;
479
+ }
480
+
481
+ $results[] = sprintf( '%1$s (%2$s %3$d)', $value->post_title, $value->post_type, $post_id );
482
+ $titles[] = $value->post_title;
483
+ }
484
+
485
+ if ( ! empty( self::$field_names['featured_in'] ) ) {
486
+ if ( empty( $results ) ) {
487
+ delete_metadata( 'post', $ID, self::$field_names['featured_in'] );
488
+ } else {
489
+ update_metadata( 'post', $ID, self::$field_names['featured_in'], implode( ',', $results ) );
490
+ }
491
+ }
492
+
493
+ if ( ! empty( self::$field_names['featured'] ) ) {
494
+ if ( empty( $titles ) ) {
495
+ delete_metadata( 'post', $ID, self::$field_names['featured'] );
496
+ } else {
497
+ update_metadata( 'post', $ID, self::$field_names['featured'], implode( ',', $titles ) );
498
+ }
499
+ }
500
+
501
+ self::_update_used_in( $ID, NULL, $features );
502
+ }
503
+ }
504
+
505
+ /**
506
+ * Find the attachments inserted in post_content
507
+ *
508
+ * @since 1.00
509
+ *
510
+ * @param string $post_content Post/Page contents.
511
+ *
512
+ * @return array Attachment IDs, indexed by ID ( ID => ID ).
513
+ */
514
+ private static function _attachments_in( $post_content ){
515
+ $inserts = array();
516
+ $match_count = preg_match_all( '/\<img.*wp-image-(\d+).*\>/', $post_content, $matches );
517
+ if ( ( $match_count == false ) || ( $match_count == 0 ) ) {
518
+ return $inserts;
519
+ }
520
+ //error_log( __LINE__ . " _attachments_in( {$match_count} ) matches = " . var_export( $matches, true ), 0 );
521
+
522
+ foreach ( $matches[1] as $match ) {
523
+ $ID = absint( $match );
524
+ $inserts[ $ID ] = $ID;
525
+ }
526
+
527
+ //error_log( __LINE__ . " _attachments_in( {$match_count} ) inserts = " . var_export( $inserts, true ), 0 );
528
+ return $inserts;
529
+ }
530
+
531
+ /**
532
+ * Find the "Featured in" information for an attachment
533
+ *
534
+ * @since 1.00
535
+ *
536
+ * @param int $object_id Attachment ID.
537
+ *
538
+ * @return array Featured in information object ( 'ID' =>, 'post_type' =>, 'post_status' =>, 'post_title' => ).
539
+ */
540
+ private static function _featured_in( $object_id ){
541
+ global $wpdb;
542
+
543
+ $results = $wpdb->get_results(
544
+ "
545
+ SELECT p.ID, p.post_type, p.post_status, p.post_title
546
+ FROM {$wpdb->postmeta} AS m INNER JOIN {$wpdb->posts} AS p ON m.post_id = p.ID
547
+ WHERE ( m.meta_key = '_thumbnail_id' )
548
+ AND ( m.meta_value = {$object_id} ) AND (post_type <> 'revision')
549
+ "
550
+ );
551
+
552
+ $features = array();
553
+ foreach ( $results as $result ) {
554
+ $features[ $result->ID ] = $result;
555
+ }
556
+ //error_log( __LINE__ . " _featured_in( {$object_id} ) features = " . var_export( $features, true ), 0 );
557
+
558
+ return $features;
559
+ }
560
+
561
+ /**
562
+ * Find the "Inserted in" information for an attachment
563
+ *
564
+ * @since 1.00
565
+ *
566
+ * @param int $object_id Attachment ID.
567
+ *
568
+ * @return array Inserted in information array( file_name => array( object ( 'ID' =>, 'post_type' =>, 'post_status' =>, 'post_title' =>, ) ) ).
569
+ */
570
+ private static function _inserted_in( $object_id ){
571
+ global $wpdb;
572
+
573
+ $references = array();
574
+ $references['base_file'] = get_post_meta( $object_id, '_wp_attached_file', true );
575
+ $pathinfo = pathinfo($references['base_file']);
576
+ $references['file'] = $pathinfo['basename'];
577
+ if ( ( ! isset( $pathinfo['dirname'] ) ) || '.' == $pathinfo['dirname'] ) {
578
+ $references['path'] = '/';
579
+ } else {
580
+ $references['path'] = $pathinfo['dirname'] . '/';
581
+ }
582
+
583
+ $attachment_metadata = get_post_meta( $object_id, '_wp_attachment_metadata', true );
584
+ $sizes = isset( $attachment_metadata['sizes'] ) ? $attachment_metadata['sizes'] : NULL;
585
+ if ( is_array( $sizes ) ) {
586
+ // Using the name as the array key ensures each name is added only once
587
+ foreach ( $sizes as $size => $size_info ) {
588
+ $size_info['size'] = $size;
589
+ $references['files'][ $references['path'] . $size_info['file'] ] = $size_info;
590
+ }
591
+ }
592
+
593
+ $base_type = wp_check_filetype( $references['file'] );
594
+ $base_reference = array(
595
+ 'file' => $references['file'],
596
+ 'width' => isset( $attachment_metadata['width'] ) ? $attachment_metadata['width'] : 0,
597
+ 'height' => isset( $attachment_metadata['height'] ) ? $attachment_metadata['height'] : 0,
598
+ 'mime_type' => isset( $base_type['type'] ) ? $base_type['type'] : 'unknown',
599
+ 'size' => 'full',
600
+ );
601
+
602
+ $references['files'][ $references['base_file'] ] = $base_reference;
603
+
604
+ $query_parameters = array();
605
+ $query = array();
606
+ $query[] = "SELECT ID, post_type, post_status, post_title, CONVERT(`post_content` USING utf8 ) AS POST_CONTENT FROM {$wpdb->posts} WHERE (post_type <> 'revision') AND ( %s=%s";
607
+ $query_parameters[] = '1'; // for empty file name array
608
+ $query_parameters[] = '0'; // for empty file name array
609
+
610
+ foreach ( $references['files'] as $file => $file_data ) {
611
+ if ( empty( $file ) ) {
612
+ continue;
613
+ }
614
+
615
+ $query[] = 'OR ( POST_CONTENT LIKE %s)';
616
+
617
+ if ( self::$wp_4dot0_plus ) {
618
+ $query_parameters[] = '%' . $wpdb->esc_like( $file ) . '%';
619
+ } else {
620
+ $query_parameters[] = '%' . like_escape( $file ) . '%';
621
+ }
622
+ }
623
+
624
+ $query[] = ')';
625
+ $query = join(' ', $query);
626
+
627
+ $inserts = $wpdb->get_results(
628
+ $wpdb->prepare( $query, $query_parameters )
629
+ );
630
+
631
+ if ( ! empty( $inserts ) ) {
632
+ $references['inserts'][ $pathinfo['filename'] ] = $inserts;
633
+
634
+ foreach ( $inserts as $index => $insert ) {
635
+ unset( $references['inserts'][ $pathinfo['filename'] ][ $index ]->POST_CONTENT );
636
+ } // foreach $insert
637
+ } else {
638
+ $references['inserts'] = array();
639
+ }
640
+ //error_log( __LINE__ . " _inserted_in( {$object_id} ) references = " . var_export( $references, true ), 0 );
641
+
642
+ return $references['inserts'];
643
+ }
644
+ } // Class MLADynamicReferencesExample
645
+
646
+ /*
647
+ * Install the filter at an early opportunity
648
+ */
649
+ add_action('init', 'MLADynamicReferencesExample::initialize');
650
+ ?>
examples/mla-insert-fixit.php.txt ADDED
@@ -0,0 +1,593 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Synchronizes Media Library values to and from post/page inserted images
4
+ *
5
+ * Adds a Tools/Insert Fixit submenu with buttons to perform the operations.
6
+ *
7
+ * @package Insert Fixit
8
+ * @version 1.00
9
+ */
10
+
11
+ /*
12
+ Plugin Name: MLA Insert Fixit
13
+ Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
14
+ Description: Synchronizes Media Library values to and from post/page inserted images
15
+ Author: David Lingren
16
+ Version: 1.00
17
+ Author URI: http://fairtradejudaica.org/our-story/staff/
18
+
19
+ Copyright 2015 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
23
+ the Free Software Foundation; either version 2 of the License, or
24
+ (at your option) any later version.
25
+
26
+ This program is distributed in the hope that it will be useful,
27
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
28
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29
+ GNU General Public License for more details.
30
+
31
+ You can get a copy of the GNU General Public License by writing to the
32
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
33
+ */
34
+
35
+ /**
36
+ * Class Insert Fixit implements a Tools submenu page with several image-fixing tools.
37
+ *
38
+ * @package Insert Fixit
39
+ * @since 1.00
40
+ */
41
+ class Insert_Fixit {
42
+ /**
43
+ * Current version number
44
+ *
45
+ * @since 1.00
46
+ *
47
+ * @var string
48
+ */
49
+ const CURRENT_VERSION = '1.00';
50
+
51
+ /**
52
+ * Slug prefix for registering and enqueueing submenu pages, style sheets and scripts
53
+ *
54
+ * @since 1.00
55
+ *
56
+ * @var string
57
+ */
58
+ const SLUG_PREFIX = 'insertfixit-';
59
+
60
+ /**
61
+ * WordPress version test for $wpdb->esc_like() Vs esc_sql()
62
+ *
63
+ * @since 1.00
64
+ *
65
+ * @var boolean
66
+ */
67
+ private static $wp_4dot0_plus = true;
68
+
69
+ /**
70
+ * Initialization function, similar to __construct()
71
+ *
72
+ * @since 1.00
73
+ *
74
+ * @return void
75
+ */
76
+ public static function initialize() {
77
+ self::$wp_4dot0_plus = version_compare( get_bloginfo('version'), '4.0', '>=' );
78
+
79
+ add_action( 'admin_init', 'Insert_Fixit::admin_init_action' );
80
+ add_action( 'admin_menu', 'Insert_Fixit::admin_menu_action' );
81
+ }
82
+
83
+ /**
84
+ * Admin Init Action
85
+ *
86
+ * @since 1.00
87
+ *
88
+ * @return void
89
+ */
90
+ public static function admin_init_action() {
91
+ }
92
+
93
+ /**
94
+ * Add submenu page in the "Tools" section
95
+ *
96
+ * @since 1.00
97
+ *
98
+ * @return void
99
+ */
100
+ public static function admin_menu_action( ) {
101
+ $current_page_hook = add_submenu_page( 'tools.php', 'Insert Fixit Tools', 'Insert Fixit', 'manage_options', self::SLUG_PREFIX . 'tools', 'Insert_Fixit::render_tools_page' );
102
+ add_filter( 'plugin_action_links', 'Insert_Fixit::add_plugin_links_filter', 10, 2 );
103
+ }
104
+
105
+ /**
106
+ * Add the "Tools" link to the Plugins section entry
107
+ *
108
+ * @since 1.00
109
+ *
110
+ * @param array array of links for the Plugin, e.g., "Activate"
111
+ * @param string Directory and name of the plugin Index file
112
+ *
113
+ * @return array Updated array of links for the Plugin
114
+ */
115
+ public static function add_plugin_links_filter( $links, $file ) {
116
+ if ( $file == 'mla-insert-fixit.php' ) {
117
+ $tools_link = sprintf( '<a href="%s">%s</a>', admin_url( 'tools.php?page=' . self::SLUG_PREFIX . 'tools' ), 'Tools' );
118
+ array_unshift( $links, $tools_link );
119
+ }
120
+
121
+ return $links;
122
+ }
123
+
124
+ /**
125
+ * Render (echo) the "Insert Fixit" submenu in the Tools section
126
+ *
127
+ * @since 1.00
128
+ *
129
+ * @return void Echoes HTML markup for the submenu page
130
+ */
131
+ public static function render_tools_page() {
132
+ error_log( 'Insert_Fixit::render_tools_page() $_REQUEST = ' . var_export( $_REQUEST, true ), 0 );
133
+ if ( !current_user_can( 'manage_options' ) ) {
134
+ echo "Insert Fixit - Error</h2>\n";
135
+ wp_die( 'You do not have permission to manage plugin settings.' );
136
+ }
137
+
138
+ $setting_actions = array(
139
+ 'help' => array( 'handler' => '', 'comment' => '<strong>Enter first and (optional) last ID values above to restrict tool application range</strong>. To operate on one ID, enter just the "First ID". The default is to perform the operation on <strong>all posts/pages</strong>.<br />&nbsp;<br />You can find ID values by hovering over the post/page title in the "Title" column of the All Posts/All Pages submenu tables; look for the number following <code>post=</code>.' ),
140
+ '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.' ),
141
+
142
+ 'c0' => array( 'handler' => '', 'comment' => '<h3>Media Library item to Post/Page inserts</h3>' ),
143
+ 'ALT from Library' => array( 'handler' => '_copy_from_media_library',
144
+ 'comment' => 'Copy ALT Text from Media Library item to Post/Page inserts.' ),
145
+ 'c1' => array( 'handler' => '', 'comment' => '<h3>Post/Page inserts to Media Library item</h3>' ),
146
+ 'ALT to Library' => array( 'handler' => '_copy_to_media_library',
147
+ 'comment' => 'Copy ALT Text from Post/Page inserts to Media Library item' ),
148
+ 'c2' => array( 'handler' => '', 'comment' => '<hr>' ),
149
+ 'c3' => array( 'handler' => '', 'comment' => '<h3>Refresh Caches</h3>' ),
150
+ 'c4' => array( 'handler' => '', 'comment' => 'If you have a large number of posts/pages and/or Media Library items you can use the cache refresh operations to break up processing into smaller steps. Try clicking the "Image Inserts" button, then the "Image Objects" button to build these intermediate data structures and save them in the WOrdPress cache for fifteen minutes. That will make the "Copy" operations above go quicker.<br>&nbsp;' ),
151
+ 'Image Inserts' => array( 'handler' => '_build_image_inserts_cache',
152
+ 'comment' => 'Find all post/page inserts and save in cache for fifteen minutes' ),
153
+ 'Image objects' => array( 'handler' => '_build_image_objects_cache',
154
+ 'comment' => 'Find all image items and save in cache for fifteen minutes' ),
155
+ );
156
+
157
+ echo '<div class="wrap">' . "\n";
158
+ echo "\t\t" . '<div id="icon-tools" class="icon32"><br/></div>' . "\n";
159
+ echo "\t\t" . '<h2>Insert Fixit Tools v' . self::CURRENT_VERSION . '</h2>' . "\n";
160
+
161
+ if ( isset( $_REQUEST[ self::SLUG_PREFIX . 'action' ] ) ) {
162
+ $label = $_REQUEST[ self::SLUG_PREFIX . 'action' ];
163
+ if( isset( $setting_actions[ $label ] ) ) {
164
+ $action = $setting_actions[ $label ]['handler'];
165
+ if ( ! empty( $action ) ) {
166
+ if ( method_exists( 'Insert_Fixit', $action ) ) {
167
+ echo self::$action();
168
+ } else {
169
+ echo "\t\t<br>ERROR: handler does not exist for action: \"{$label}\"\n";
170
+ }
171
+ } else {
172
+ echo "\t\t<br>ERROR: no handler for action: \"{$label}\"\n";
173
+ }
174
+ } else {
175
+ echo "\t\t<br>ERROR: unknown action: \"{$label}\"\n";
176
+ }
177
+ }
178
+
179
+ echo "\t\t" . '<div style="width:700px">' . "\n";
180
+ 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";
181
+ echo "\t\t" . ' <p class="submit" style="padding-bottom: 0;">' . "\n";
182
+ echo "\t\t" . ' <table>' . "\n";
183
+
184
+ echo "\t\t" . ' <tr valign="top">' . "\n";
185
+ echo "\t\t" . ' <td width="24%" style="text-align: right; padding-right: 5px" >First Post/Page ID</td>' . "\n";
186
+ echo "\t\t" . ' <td width="24%" style="text-align: left;">' . "\n";
187
+ echo "\t\t" . ' <input name="' . self::SLUG_PREFIX . 'post_lower" type="text" size="5" value="">' . "\n";
188
+ echo "\t\t" . ' </td>' . "\n";
189
+ echo "\t\t" . ' <td width="24%" style="text-align: right; padding-right: 5px" >First Attachment ID</td>' . "\n";
190
+ echo "\t\t" . ' <td width="24%" style="text-align: left;"><input name="' . self::SLUG_PREFIX . 'attachment_lower" type="text" size="5" value=""></td>' . "\n";
191
+ echo "\t\t" . ' </tr>' . "\n";
192
+
193
+ echo "\t\t" . ' <tr valign="top">' . "\n";
194
+ echo "\t\t" . ' <td width="24%" style="text-align: right; padding-right: 5px" >Last Post/Page ID</td>' . "\n";
195
+ echo "\t\t" . ' <td style="text-align: left;"><input name="' . self::SLUG_PREFIX . 'post_upper" type="text" size="5" value=""></td>' . "\n";
196
+ echo "\t\t" . ' <td width="24%" style="text-align: right; padding-right: 5px" >Last Attachment ID</td>' . "\n";
197
+ echo "\t\t" . ' <td style="text-align: left;"><input name="' . self::SLUG_PREFIX . 'attachment_upper" type="text" size="5" value=""></td>' . "\n";
198
+ echo "\t\t" . ' </tr>' . "\n";
199
+ echo "\t\t" . ' </table>' . "\n";
200
+
201
+ echo "\t\t" . ' <table>' . "\n";
202
+
203
+ foreach ( $setting_actions as $label => $action ) {
204
+ if ( empty( $action['handler'] ) ) {
205
+ echo "\t\t" . ' <tr><td colspan=2 style="padding: 2px 0px;">' . $action['comment'] . "</td></tr>\n";
206
+ } else {
207
+ echo "\t\t" . ' <tr><td width="150px">' . "\n";
208
+ echo "\t\t" . ' <input name="' . self::SLUG_PREFIX . 'action" type="submit" class="button-primary" style="width: 140px;" value="' . $label . '" />&nbsp;&nbsp;' . "\n";
209
+ echo "\t\t" . ' </td><td>' . "\n";
210
+ echo "\t\t" . ' ' . $action['comment'] . "\n";
211
+ echo "\t\t" . ' </td></tr>' . "\n";
212
+ }
213
+ }
214
+
215
+ echo "\t\t" . ' </table>' . "\n";
216
+ echo "\t\t" . ' </p>' . "\n";
217
+ echo "\t\t" . '</form>' . "\n";
218
+ echo "\t\t" . '</div>' . "\n";
219
+ echo "\t\t" . '</div><!-- wrap -->' . "\n";
220
+ }
221
+
222
+ /**
223
+ * Array of post/page IDs giving inserted image URL and ALT Text:
224
+ * ID => array( 'src' => image URL, 'alt' => ALT Text
225
+ *
226
+ * @since 1.00
227
+ *
228
+ * @var array
229
+ */
230
+ private static $image_inserts = array();
231
+
232
+ /**
233
+ * Compile array of image URLs inserted in posts/pages
234
+ *
235
+ * @since 1.00
236
+ *
237
+ * @param boolean $use_cache True to use an existing cache, false to force rebuild
238
+ *
239
+ * @return void
240
+ */
241
+ private static function _build_image_inserts_cache( $use_cache = false ) {
242
+ global $wpdb;
243
+
244
+ if ( $use_cache ) {
245
+ self::$image_inserts = get_transient( self::SLUG_PREFIX . 'image_inserts' );
246
+ if ( is_array( self::$image_inserts ) ) {
247
+ //error_log( __LINE__ . " Insert_Fixit::_build_image_inserts_cache using cached self::\$image_inserts " . var_export( self::$image_inserts, true ), 0 );
248
+ return;
249
+ }
250
+ }
251
+
252
+ $return = delete_transient( self::SLUG_PREFIX . 'image_inserts' );
253
+ //error_log( __LINE__ . " Insert_Fixit::_build_image_inserts_cache delete_transient return = " . var_export( $return, true ), 0 );
254
+
255
+ if ( ! empty( $_REQUEST[ self::SLUG_PREFIX . 'post_lower' ] ) ) {
256
+ $lower_bound = (integer) $_REQUEST[ self::SLUG_PREFIX . 'post_lower' ];
257
+ } else {
258
+ $lower_bound = 0;
259
+ }
260
+
261
+ if ( ! empty( $_REQUEST[ self::SLUG_PREFIX . 'post_upper' ] ) ) {
262
+ $upper_bound = (integer) $_REQUEST[ self::SLUG_PREFIX . 'post_upper' ];
263
+ } elseif ( $lower_bound ) {
264
+ $upper_bound = $lower_bound;
265
+ } else {
266
+ $upper_bound = 0x7FFFFFFF;
267
+ }
268
+
269
+ $query = sprintf( 'SELECT ID, post_content FROM %1$s WHERE ( post_type IN ( \'post\', \'page\' ) AND ( post_status = \'publish\' ) AND ( ID >= %2$d ) AND ( ID <= %3$d ) AND ( post_content LIKE \'%4$s\' ) ) ORDER BY ID', $wpdb->posts, $lower_bound, $upper_bound, '%<img%' );
270
+ $results = $wpdb->get_results( $query );
271
+ //error_log( __LINE__ . ' Insert_Fixit::_build_image_inserts_cache() $results = ' . var_export( $results, true ), 0 );
272
+
273
+ $upload_dir = wp_upload_dir();
274
+ //error_log( __LINE__ . ' Insert_Fixit::_build_image_inserts_cache() $upload_dir = ' . var_export( $upload_dir, true ), 0 );
275
+ $upload_dir = $upload_dir['baseurl'] . '/';
276
+
277
+ $image_inserts = array();
278
+ foreach ( $results as $result ) {
279
+ $match_count = preg_match_all( '/\<img.*src="([^"]*)".*alt="([^"]*)"/', $result->post_content, $matches, PREG_OFFSET_CAPTURE );
280
+ //error_log( __LINE__ . " Insert_Fixit::_build_image_inserts_cache( {$result->ID} ) \$matches = " . var_export( $matches, true ), 0 );
281
+ if ( $match_count ) {
282
+ $image_inserts[ $result->ID ]['content'] = $result->post_content;
283
+
284
+ foreach( $matches[1] as $index => $match ) {
285
+ $file = str_replace( $upload_dir, '', $match[0] );
286
+ $image_inserts[ $result->ID ]['files'][] = $file;
287
+ $image_inserts[ $result->ID ]['inserts'][ $index ] = array( 'src' => $file, 'src_offset' => $match[1] );
288
+ }
289
+
290
+ foreach( $matches[2] as $index => $match ) {
291
+ $image_inserts[ $result->ID ]['inserts'][ $index ]['alt'] = $match[0];
292
+ $image_inserts[ $result->ID ]['inserts'][ $index ]['alt_offset'] = $match[1];
293
+ }
294
+
295
+ $image_inserts[ $result->ID ]['replacements'] = array();
296
+ }
297
+ }
298
+ error_log( __LINE__ . " Insert_Fixit::_build_image_inserts_cache \$image_inserts " . var_export($image_inserts, true ), 0 );
299
+
300
+ $return = set_transient( self::SLUG_PREFIX . 'image_inserts', $image_inserts, 900 ); // fifteen minutes
301
+ //error_log( __LINE__ . " Insert_Fixit::_build_image_inserts_cache set_transient return = " . var_export( $return, true ), 0 );
302
+ self::$image_inserts = $image_inserts;
303
+ return 'Image inserts cache refreshed.';
304
+ } // _build_image_inserts_cache
305
+
306
+ /**
307
+ * Array of post/page IDs giving inserted image URL and ALT Text:
308
+ * ID => array( 'src' => image URL, 'alt' => ALT Text
309
+ *
310
+ * @since 1.00
311
+ *
312
+ * @var array
313
+ */
314
+ private static $image_objects = array();
315
+
316
+ /**
317
+ * Compile array of image URLs inserted in posts/pages
318
+ *
319
+ * @since 1.00
320
+ *
321
+ * @return void
322
+ */
323
+ private static function _build_image_objects_cache( $use_cache = false ) {
324
+ global $wpdb;
325
+
326
+ if ( $use_cache ) {
327
+ self::$image_objects = get_transient( self::SLUG_PREFIX . 'image_objects' );
328
+ if ( is_array( self::$image_objects ) ) {
329
+ //error_log( __LINE__ . " Insert_Fixit::_build_image_objects_cache using cached self::\$image_objects " . var_export( self::$image_objects, true ), 0 );
330
+ return;
331
+ }
332
+ }
333
+
334
+ $return = delete_transient( self::SLUG_PREFIX . 'image_objects' );
335
+ //error_log( __LINE__ . " Insert_Fixit::_build_image_inserts_cache delete_transient return = " . var_export( $return, true ), 0 );
336
+
337
+ if ( ! empty( $_REQUEST[ self::SLUG_PREFIX . 'attachment_lower' ] ) ) {
338
+ $lower_bound = (integer) $_REQUEST[ self::SLUG_PREFIX . 'attachment_lower' ];
339
+ } else {
340
+ $lower_bound = 0;
341
+ }
342
+
343
+ if ( ! empty( $_REQUEST[ self::SLUG_PREFIX . 'attachment_upper' ] ) ) {
344
+ $upper_bound = (integer) $_REQUEST[ self::SLUG_PREFIX . 'attachment_upper' ];
345
+ } elseif ( $lower_bound ) {
346
+ $upper_bound = $lower_bound;
347
+ } else {
348
+ $upper_bound = 0x7FFFFFFF;
349
+ }
350
+
351
+ $where = str_replace( '%', '%%', wp_post_mime_type_where( 'image', '' ) );
352
+ $query = sprintf( 'SELECT ID FROM %1$s WHERE ( ( post_type = \'attachment\' ) %2$s AND ( ID >= %3$d ) AND ( ID <= %4$d ) ) ORDER BY ID', $wpdb->posts, $where, $lower_bound, $upper_bound );
353
+ $results = $wpdb->get_results( $query );
354
+ //error_log( __LINE__ . ' Insert_Fixit::_build_image_objects_cache() $results = ' . var_export( $results, true ), 0 );
355
+
356
+ /*
357
+ * Load the image_inserts array
358
+ */
359
+ self::_build_image_inserts_cache( true );
360
+
361
+ $references = array();
362
+ foreach ( $results as $result ) {
363
+ // assemble the files
364
+ $files = array();
365
+
366
+ $base_file = get_metadata( 'post', $result->ID, '_wp_attached_file', true );
367
+ if ( empty( $base_file ) ) {
368
+ $base_file = '';
369
+ }
370
+
371
+ $pathinfo = pathinfo( $base_file );
372
+ if ( ( ! isset( $pathinfo['dirname'] ) ) || '.' == $pathinfo['dirname'] ) {
373
+ $path = '/';
374
+ } else {
375
+ $path = $pathinfo['dirname'] . '/';
376
+ }
377
+
378
+ $file = $pathinfo['basename'];
379
+
380
+ $attachment_metadata = get_metadata( 'post', $result->ID, '_wp_attachment_metadata', true );
381
+ if ( empty( $attachment_metadata ) ) {
382
+ $attachment_metadata = array();
383
+ }
384
+
385
+ $sizes = isset( $attachment_metadata['sizes'] ) ? $attachment_metadata['sizes'] : NULL;
386
+ if ( ! empty( $sizes ) && is_array( $sizes ) ) {
387
+ /* Using the path and name as the array key ensures each name is added only once */
388
+ foreach ( $sizes as $size => $size_info ) {
389
+ $files[ $path . $size_info['file'] ] = $path . $size_info['file'];
390
+ }
391
+ }
392
+
393
+ if ( ! empty( $base_file ) ) {
394
+ $files[ $base_file ] = $base_file;
395
+ }
396
+ //error_log( __LINE__ . " Insert_Fixit::_array_image_inserts_references( {$attachment->ID} ) files = " . var_export( $files, true ), 0 );
397
+ /*
398
+ * inserts Array of specific files (i.e., sizes) found in one or more posts/pages
399
+ * as an image (<img>). The array key is the path and file name.
400
+ * The array value is the post/page ID
401
+ */
402
+ $inserts = array();
403
+
404
+ foreach( $files as $file ) {
405
+ foreach ( self::$image_inserts as $insert_id => $value ) {
406
+ if ( in_array( $file, $value['files'] ) ) {
407
+ $inserts[ $insert_id ][] = $file;
408
+ }
409
+ } // foreach insert
410
+ } // foreach file
411
+
412
+ if ( ! empty( $inserts ) ) {
413
+ $references[ $result->ID ] = $inserts;
414
+ }
415
+ } // each result
416
+
417
+ $return = set_transient( self::SLUG_PREFIX . 'image_objects', $references, 900 ); // fifteen minutes
418
+ //error_log( __LINE__ . " Insert_Fixit::_build_image_objects_cache set_transient return = " . var_export( $return, true ), 0 );
419
+ error_log( __LINE__ . " Insert_Fixit::_build_image_objects_cache set_transient references = " . var_export( $references, true ), 0 );
420
+ self::$image_objects = $references;
421
+ return 'Image objects cache refreshed.';
422
+ } // _build_image_objects_cache
423
+
424
+ /**
425
+ * Copy ALT Text from Media Library item to Post/Page inserts
426
+ *
427
+ * @since 1.00
428
+ *
429
+ * @return string HTML markup for results/messages
430
+ */
431
+ private static function _copy_from_media_library() {
432
+ global $wpdb;
433
+
434
+ /*
435
+ * Load the image_inserts array
436
+ */
437
+ self::_build_image_inserts_cache( true );
438
+
439
+ /*
440
+ * Load the image_objects array
441
+ */
442
+ self::_build_image_objects_cache( true );
443
+
444
+ // Initialize statistics
445
+ $image_inserts = count( self::$image_inserts );
446
+ $image_objects = count( self::$image_objects );
447
+ $updates = 0;
448
+ $updated_posts = 0;
449
+ $errors = 0;
450
+
451
+ foreach ( self::$image_objects as $attachment_id => $references ) {
452
+ $alt_text = get_metadata( 'post', $attachment_id, '_wp_attachment_image_alt', true );
453
+ if ( empty( $alt_text ) ) {
454
+ $alt_text = '';
455
+ }
456
+
457
+ // Add replacements to each post/page in self::$image_inserts
458
+ foreach ( $references as $post_id => $files ) {
459
+ $inserts = self::$image_inserts[ $post_id ];
460
+ foreach ( $files as $file ) {
461
+ foreach ( $inserts['inserts'] as $insert ) {
462
+ error_log( __LINE__ . " Insert_Fixit::_copy_from_media_library file test '{$file}' == " . var_export( $insert['src'], true ), 0 );
463
+ if ( $file != $insert['src'] ) {
464
+ continue;
465
+ }
466
+
467
+ error_log( __LINE__ . " Insert_Fixit::_copy_from_media_library ALT text test '{$alt_text}' == " . var_export( $insert['alt'], true ), 0 );
468
+ if ( $alt_text == $insert['alt'] ) {
469
+ continue;
470
+ }
471
+
472
+ // Queue replacement
473
+ self::$image_inserts[ $post_id ]['replacements'][ $insert['alt_offset'] ] = array( 'length' => strlen( $insert['alt'] ), 'text' => $alt_text );
474
+ } // foreach file
475
+ } // foreach reference
476
+ } // foreach insert
477
+ } // foreach attachment
478
+
479
+ // Apply replacements
480
+ foreach ( self::$image_inserts as $post_id => $inserts ) {
481
+ $replacements = $inserts['replacements'];
482
+ if ( ! empty( $replacements ) ) {
483
+ krsort( $replacements );
484
+ error_log( __LINE__ . " Insert_Fixit::_copy_from_media_library( {$post_id} ) replacements = " . var_export( $replacements, true ), 0 );
485
+ $post_content = $inserts['content'];
486
+ foreach ( $replacements as $offset => $replacement ) {
487
+ $post_content = substr_replace( $post_content, $replacement['text'], $offset, $replacement['length'] );
488
+ $updates++;
489
+ } // foreach replacement
490
+ error_log( __LINE__ . " Insert_Fixit::_copy_from_media_library( {$post_id} ) new post_content = " . var_export( $post_content, true ), 0 );
491
+ $new_content = array( 'ID' => $post_id, 'post_content' => $post_content );
492
+ $result = wp_update_post( $new_content, true );
493
+ error_log( __LINE__ . " Insert_Fixit::_copy_from_media_library( {$post_id} ) update result = " . var_export( $result, true ), 0 );
494
+ if ( is_wp_error( $result ) ) {
495
+ $errors++;
496
+ }
497
+ $updated_posts++;
498
+ } // has replacements
499
+ } // foreach post/page
500
+
501
+ /*
502
+ * Invalidate the image_inserts cache, since post/page content has changed.
503
+ */
504
+ if ( $updated_posts ) {
505
+ delete_transient( self::SLUG_PREFIX . 'image_inserts' );
506
+ }
507
+
508
+ return "<br>Copy from Library matched {$image_inserts} posts/pages to {$image_objects} attachments and made {$updates} update(s) in {$updated_posts} posts/pages. There were {$errors} error(s).\n";
509
+ } // _copy_from_media_library
510
+
511
+ /**
512
+ * Copy ALT Text from Post/Page inserts to Media Library item
513
+ *
514
+ * @since 1.00
515
+ *
516
+ * @return string HTML markup for results/messages
517
+ */
518
+ private static function _copy_to_media_library() {
519
+ global $wpdb;
520
+
521
+ /*
522
+ * Load the image_inserts array
523
+ */
524
+ self::_build_image_inserts_cache( true );
525
+
526
+ /*
527
+ * Load the image_objects array
528
+ */
529
+ self::_build_image_objects_cache( true );
530
+
531
+ $image_inserts = count( self::$image_inserts );
532
+ $image_objects = count( self::$image_objects );
533
+ $updated_attachments = 0;
534
+ $errors = 0;
535
+
536
+ foreach ( self::$image_objects as $attachment_id => $references ) {
537
+ $alt_text = get_metadata( 'post', $attachment_id, '_wp_attachment_image_alt', true );
538
+ if ( empty( $alt_text ) ) {
539
+ $alt_text = '';
540
+ }
541
+
542
+ // Make sure the most recent changes are the last updates applied
543
+ ksort( $references );
544
+
545
+ // Find most recent replacement
546
+ $replacement = NULL;
547
+ foreach ( $references as $post_id => $files ) {
548
+ $inserts = self::$image_inserts[ $post_id ];
549
+ foreach ( $files as $file ) {
550
+ foreach ( $inserts['inserts'] as $insert ) {
551
+ error_log( __LINE__ . " Insert_Fixit::_copy_to_media_library file test '{$file}' == " . var_export( $insert['src'], true ), 0 );
552
+ if ( $file != $insert['src'] ) {
553
+ continue;
554
+ }
555
+
556
+ error_log( __LINE__ . " Insert_Fixit::_copy_to_media_library ALT text test '{$alt_text}' == " . var_export( $insert['alt'], true ), 0 );
557
+ if ( $alt_text == $insert['alt'] ) {
558
+ continue;
559
+ }
560
+
561
+ // Queue replacement
562
+ $replacement = $insert['alt'];
563
+ } // foreach file
564
+ } // foreach reference
565
+ } // foreach insert
566
+
567
+ // Apply replacement
568
+ if ( ! is_null( $replacement ) ) {
569
+ error_log( __LINE__ . " Insert_Fixit::_copy_to_media_library( {$attachment_id} ) replacement = " . var_export( $replacement, true ), 0 );
570
+ if ( update_metadata( 'post', $attachment_id, '_wp_attachment_image_alt', $replacement ) ) {
571
+ $updated_attachments++;
572
+ } else {
573
+ $errors++;
574
+ }
575
+ }
576
+ } // foreach attachment
577
+
578
+ /*
579
+ * Invalidate the image_objects cache, since Media Library item content has changed.
580
+ */
581
+ if ( $updated_attachments ) {
582
+ delete_transient( self::SLUG_PREFIX . 'image_objects' );
583
+ }
584
+
585
+ return "<br>Copy to Library matched {$image_inserts} posts/pages to {$image_objects} attachments and updated {$updated_attachments} Media Library items. There were {$errors} error(s).\n";
586
+ } // _copy_to_media_library
587
+ } //Insert_Fixit
588
+
589
+ /*
590
+ * Install the submenu at an early opportunity
591
+ */
592
+ add_action('init', 'Insert_Fixit::initialize');
593
+ ?>
examples/mla-list-table-hooks-example.php.txt CHANGED
@@ -3,7 +3,7 @@
3
  * Provides an example of hooking the filters provided by the MLA_List_Table class
4
  *
5
  * @package MLA List Table Hooks Example
6
- * @version 1.06
7
  */
8
 
9
  /*
@@ -11,7 +11,7 @@ Plugin Name: MLA List Table Hooks Example
11
  Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
12
  Description: Provides an example of hooking the filters provided by the MLA_List_Table class
13
  Author: David Lingren
14
- Version: 1.06
15
  Author URI: http://fairtradejudaica.org/our-story/staff/
16
 
17
  Copyright 2014 - 2015 David Lingren
@@ -134,6 +134,13 @@ class MLAListTableHooksExample {
134
 
135
  // 'views_upload' is only applied when WPML is active
136
  add_filter( 'views_upload', 'MLAListTableHooksExample::views_upload', 10, 1 );
 
 
 
 
 
 
 
137
  }
138
 
139
  /**
@@ -1024,6 +1031,55 @@ class MLAListTableHooksExample {
1024
  //error_log( 'MLAListTableHooksExample::views_upload $views = ' . var_export( $views, true ), 0 );
1025
  return $views;
1026
  } // views_upload
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1027
  } // Class MLAListTableHooksExample
1028
 
1029
  /*
3
  * Provides an example of hooking the filters provided by the MLA_List_Table class
4
  *
5
  * @package MLA List Table Hooks Example
6
+ * @version 1.07
7
  */
8
 
9
  /*
11
  Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
12
  Description: Provides an example of hooking the filters provided by the MLA_List_Table class
13
  Author: David Lingren
14
+ Version: 1.07
15
  Author URI: http://fairtradejudaica.org/our-story/staff/
16
 
17
  Copyright 2014 - 2015 David Lingren
134
 
135
  // 'views_upload' is only applied when WPML is active
136
  add_filter( 'views_upload', 'MLAListTableHooksExample::views_upload', 10, 1 );
137
+
138
+ /*
139
+ * Defined in /media-library-assistant/includes/class-mla-edit-media.php
140
+ */
141
+ add_filter( 'mla_upload_bulk_edit_form_values', 'MLAListTableHooksExample::mla_upload_bulk_edit_form_values', 10, 1 );
142
+ add_filter( 'mla_upload_bulk_edit_form_template', 'MLAListTableHooksExample::mla_upload_bulk_edit_form_template', 10, 1 );
143
+ add_filter( 'mla_upload_bulk_edit_form_parse', 'MLAListTableHooksExample::mla_upload_bulk_edit_form_parse', 10, 3 );
144
  }
145
 
146
  /**
1031
  //error_log( 'MLAListTableHooksExample::views_upload $views = ' . var_export( $views, true ), 0 );
1032
  return $views;
1033
  } // views_upload
1034
+
1035
+ /**
1036
+ * MLAEdit bulk edit on upload item values
1037
+ *
1038
+ * This filter gives you a chance to modify and extend the substitution values
1039
+ * for the Bulk Edit on Upload form.
1040
+ *
1041
+ * @since 1.07
1042
+ *
1043
+ * @param array $item_values [ parameter_name => parameter_value ] pairs
1044
+ */
1045
+ public static function mla_upload_bulk_edit_form_values( $item_values ) {
1046
+ //error_log( 'MLAListTableHooksExample::mla_upload_bulk_edit_form_values $item_values = ' . var_export( $item_values, true ), 0 );
1047
+ return $item_values;
1048
+ } // mla_upload_bulk_edit_form_values
1049
+
1050
+ /**
1051
+ * MLAEdit bulk edit on upload template
1052
+ *
1053
+ * This filter gives you a chance to modify and extend the template used
1054
+ * for the Bulk Edit on Upload form.
1055
+ *
1056
+ * @since 1.07
1057
+ *
1058
+ * @param string $item_template Template used to generate the HTML markup
1059
+ */
1060
+ public static function mla_upload_bulk_edit_form_template( $item_template ) {
1061
+ //error_log( 'MLAListTableHooksExample::mla_upload_bulk_edit_form_template $item_template = ' . var_export( $item_template, true ), 0 );
1062
+ return $item_template;
1063
+ } // mla_upload_bulk_edit_form_template
1064
+
1065
+ /**
1066
+ * MLAEdit bulk edit on upload parse
1067
+ *
1068
+ * @since 1.07
1069
+ *
1070
+ * This filter gives you a final chance to modify and extend the HTML
1071
+ * markup used for the Bulk Edit on Upload form.
1072
+ *
1073
+ * @param string $html_markup HTML markup returned by the template parser
1074
+ * @param string $item_template Template used to generate the HTML markup
1075
+ * @param array $item_values [ parameter_name => parameter_value ] pairs
1076
+ */
1077
+ public static function mla_upload_bulk_edit_form_parse( $html_markup, $item_template, $item_values ) {
1078
+ //error_log( 'MLAListTableHooksExample::mla_upload_bulk_edit_form_parse $html_markup = ' . var_export( $html_markup, true ), 0 );
1079
+ //error_log( 'MLAListTableHooksExample::mla_upload_bulk_edit_form_parse $item_template = ' . var_export( $item_template, true ), 0 );
1080
+ //error_log( 'MLAListTableHooksExample::mla_upload_bulk_edit_form_parse $item_values = ' . var_export( $item_values, true ), 0 );
1081
+ return $html_markup;
1082
+ } // mla_upload_bulk_edit_form_parse
1083
  } // Class MLAListTableHooksExample
1084
 
1085
  /*
examples/mla-mapping-hooks-example.php.txt CHANGED
@@ -9,7 +9,7 @@
9
  * a supporting function "_export_this_item" and the "mla_end_mapping" action.
10
  *
11
  * @package MLA Mapping Hooks Example
12
- * @version 1.01
13
  */
14
 
15
  /*
@@ -86,6 +86,7 @@ class MLAMappingHooksExample {
86
  add_filter( 'mla_mapping_custom_value', 'MLAMappingHooksExample::mla_mapping_custom_value_filter', 10, 5 );
87
  add_filter( 'mla_mapping_iptc_value', 'MLAMappingHooksExample::mla_mapping_iptc_value_filter', 10, 5 );
88
  add_filter( 'mla_mapping_exif_value', 'MLAMappingHooksExample::mla_mapping_exif_value_filter', 10, 5 );
 
89
  add_filter( 'mla_mapping_updates', 'MLAMappingHooksExample::mla_mapping_updates_filter', 10, 5 );
90
  add_action( 'mla_end_mapping', 'MLAMappingHooksExample::mla_end_mapping_action', 10, 0 );
91
 
@@ -455,7 +456,7 @@ class MLAMappingHooksExample {
455
  * @param mixed IPTC value returned by the rule
456
  * @param array custom_field_mapping rule
457
  * @param integer post ID to be evaluated
458
- * @param string category/scope to evaluate against: custom_field_mapping or single_attachment_mapping
459
  * @param array attachment_metadata, default NULL
460
  *
461
  * @return array updated rule IPTC value
@@ -497,7 +498,7 @@ class MLAMappingHooksExample {
497
  * @param mixed EXIF/Template value returned by the rule
498
  * @param array custom_field_mapping rule
499
  * @param integer post ID to be evaluated
500
- * @param string category/scope to evaluate against: custom_field_mapping or single_attachment_mapping
501
  * @param array attachment_metadata, default NULL
502
  *
503
  * @return array updated rule EXIF/Template value
@@ -528,6 +529,33 @@ class MLAMappingHooksExample {
528
  return $exif_value;
529
  } // mla_mapping_exif_value_filter
530
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
531
  /**
532
  * MLA Mapping Updates Filter
533
  *
9
  * a supporting function "_export_this_item" and the "mla_end_mapping" action.
10
  *
11
  * @package MLA Mapping Hooks Example
12
+ * @version 1.02
13
  */
14
 
15
  /*
86
  add_filter( 'mla_mapping_custom_value', 'MLAMappingHooksExample::mla_mapping_custom_value_filter', 10, 5 );
87
  add_filter( 'mla_mapping_iptc_value', 'MLAMappingHooksExample::mla_mapping_iptc_value_filter', 10, 5 );
88
  add_filter( 'mla_mapping_exif_value', 'MLAMappingHooksExample::mla_mapping_exif_value_filter', 10, 5 );
89
+ add_filter( 'mla_mapping_new_text', 'MLAMappingHooksExample::mla_mapping_new_text_filter', 10, 5 );
90
  add_filter( 'mla_mapping_updates', 'MLAMappingHooksExample::mla_mapping_updates_filter', 10, 5 );
91
  add_action( 'mla_end_mapping', 'MLAMappingHooksExample::mla_end_mapping_action', 10, 0 );
92
 
456
  * @param mixed IPTC value returned by the rule
457
  * @param array custom_field_mapping rule
458
  * @param integer post ID to be evaluated
459
+ * @param string category/scope to evaluate against: iptc_exif_standard_mapping, iptc_exif_taxonomy_mapping or iptc_exif_custom_mapping
460
  * @param array attachment_metadata, default NULL
461
  *
462
  * @return array updated rule IPTC value
498
  * @param mixed EXIF/Template value returned by the rule
499
  * @param array custom_field_mapping rule
500
  * @param integer post ID to be evaluated
501
+ * @param string category/scope to evaluate against: iptc_exif_standard_mapping, iptc_exif_taxonomy_mapping or iptc_exif_custom_mapping
502
  * @param array attachment_metadata, default NULL
503
  *
504
  * @return array updated rule EXIF/Template value
529
  return $exif_value;
530
  } // mla_mapping_exif_value_filter
531
 
532
+ /**
533
+ * MLA Mapping New Text Filter
534
+ *
535
+ * This filter is called once for each IPTC/EXIF mapping rule, after the selection
536
+ * between the IPTC and EXIF values has been made. You can change the new value
537
+ * produced by the rule.
538
+ *
539
+ * @since 1.02
540
+ *
541
+ * @param mixed string or array value returned by the rule
542
+ * @param array custom_field_mapping rule
543
+ * @param integer post ID to be evaluated
544
+ * @param string category/scope to evaluate against: iptc_exif_standard_mapping, iptc_exif_taxonomy_mapping or iptc_exif_custom_mapping
545
+ * @param array attachment_metadata, default NULL
546
+ *
547
+ * @return array updated rule EXIF/Template value
548
+ */
549
+ public static function mla_mapping_new_text_filter( $new_text, $setting_value, $post_id, $category, $attachment_metadata ) {
550
+ //error_log( 'MLAMappingHooksExample::mla_mapping_new_text_filter $exif_value = ' . var_export( $exif_value, true ), 0 );
551
+ //error_log( 'MLAMappingHooksExample::mla_mapping_new_text_filter $setting_value = ' . var_export( $setting_value, true ), 0 );
552
+ //error_log( 'MLAMappingHooksExample::mla_mapping_new_text_filter $post_id = ' . var_export( $post_id, true ), 0 );
553
+ //error_log( 'MLAMappingHooksExample::mla_mapping_new_text_filter $category = ' . var_export( $category, true ), 0 );
554
+ //error_log( 'MLAMappingHooksExample::mla_mapping_new_text_filter $attachment_metadata = ' . var_export( $attachment_metadata, true ), 0 );
555
+
556
+ return $new_text;
557
+ } // mla_mapping_new_text_filter
558
+
559
  /**
560
  * MLA Mapping Updates Filter
561
  *
examples/mla-unattached-fixit.php.txt ADDED
@@ -0,0 +1,325 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Removes Unattached items from the Media Library
4
+ *
5
+ * Adds a Tools/Unattached Fixit submenu with buttons to perform the operations.
6
+ *
7
+ * @package Unattached Fixit
8
+ * @version 1.01
9
+ */
10
+
11
+ /*
12
+ Plugin Name: MLA Unattached Fixit
13
+ Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
14
+ Description: Removes Unattached items from the Media Library
15
+ Author: David Lingren
16
+ Version: 1.01
17
+ Author URI: http://fairtradejudaica.org/our-story/staff/
18
+
19
+ Copyright 2015 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
23
+ the Free Software Foundation; either version 2 of the License, or
24
+ (at your option) any later version.
25
+
26
+ This program is distributed in the hope that it will be useful,
27
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
28
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29
+ GNU General Public License for more details.
30
+
31
+ You can get a copy of the GNU General Public License by writing to the
32
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
33
+ */
34
+
35
+ /**
36
+ * Class Unattached Fixit implements a Tools submenu page with several image-fixing tools.
37
+ *
38
+ * @package Unattached Fixit
39
+ * @since 1.00
40
+ */
41
+ class Unattached_Fixit {
42
+ /**
43
+ * Current version number
44
+ *
45
+ * @since 1.00
46
+ *
47
+ * @var string
48
+ */
49
+ const CURRENT_VERSION = '1.01';
50
+
51
+ /**
52
+ * Slug prefix for registering and enqueueing submenu pages, style sheets and scripts
53
+ *
54
+ * @since 1.00
55
+ *
56
+ * @var string
57
+ */
58
+ const SLUG_PREFIX = 'unattachfixit-';
59
+
60
+ /**
61
+ * WordPress version test for $wpdb->esc_like() Vs esc_sql()
62
+ *
63
+ * @since 1.00
64
+ *
65
+ * @var boolean
66
+ */
67
+ private static $wp_4dot0_plus = true;
68
+
69
+ /**
70
+ * Initialization function, similar to __construct()
71
+ *
72
+ * @since 1.00
73
+ *
74
+ * @return void
75
+ */
76
+ public static function initialize() {
77
+ self::$wp_4dot0_plus = version_compare( get_bloginfo('version'), '4.0', '>=' );
78
+
79
+ //add_action( 'admin_init', 'Unattached_Fixit::admin_init_action' );
80
+ add_action( 'admin_menu', 'Unattached_Fixit::admin_menu_action' );
81
+ }
82
+
83
+ /**
84
+ * Admin Init Action
85
+ *
86
+ * @since 1.00
87
+ *
88
+ * @return void
89
+ */
90
+ public static function admin_init_action() {
91
+ }
92
+
93
+ /**
94
+ * Add submenu page in the "Tools" section
95
+ *
96
+ * @since 1.00
97
+ *
98
+ * @return void
99
+ */
100
+ public static function admin_menu_action( ) {
101
+ $current_page_hook = add_submenu_page( 'tools.php', 'Unattached Fixit Tools', 'Unattached Fixit', 'manage_options', self::SLUG_PREFIX . 'tools', 'Unattached_Fixit::render_tools_page' );
102
+ add_filter( 'plugin_action_links', 'Unattached_Fixit::add_plugin_links_filter', 10, 2 );
103
+ }
104
+
105
+ /**
106
+ * Add the "Tools" link to the Plugins section entry
107
+ *
108
+ * @since 1.00
109
+ *
110
+ * @param array array of links for the Plugin, e.g., "Activate"
111
+ * @param string Directory and name of the plugin Index file
112
+ *
113
+ * @return array Updated array of links for the Plugin
114
+ */
115
+ public static function add_plugin_links_filter( $links, $file ) {
116
+ if ( $file == 'mla-unattached-fixit.php' ) {
117
+ $tools_link = sprintf( '<a href="%s">%s</a>', admin_url( 'tools.php?page=' . self::SLUG_PREFIX . 'tools' ), 'Tools' );
118
+ array_unshift( $links, $tools_link );
119
+ }
120
+
121
+ return $links;
122
+ }
123
+
124
+ /**
125
+ * Render (echo) the "Unattached Fixit" submenu in the Tools section
126
+ *
127
+ * @since 1.00
128
+ *
129
+ * @return void Echoes HTML markup for the submenu page
130
+ */
131
+ public static function render_tools_page() {
132
+ error_log( 'Unattached_Fixit::render_tools_page() $_REQUEST = ' . var_export( $_REQUEST, true ), 0 );
133
+ if ( !current_user_can( 'manage_options' ) ) {
134
+ echo "Unattached Fixit - Error</h2>\n";
135
+ wp_die( 'You do not have permission to manage plugin settings.' );
136
+ }
137
+
138
+ $setting_actions = array(
139
+ 'help' => array( 'handler' => '', 'comment' => '<strong>Enter first and (optional) last attachment/item ID values above to restrict tool application range</strong>. To operate on one ID, enter just the "First ID". The default is to perform the operation on <strong>all Media Library items</strong>.<br />&nbsp;<br />You can find ID values in the "ID/Parent" column or by by hovering over the thumbnail image in the Media/Assistant submenu table; look for the number following <code>post=</code> in the item&rsquo;s URL.' ),
140
+ '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.' ),
141
+ 'trash' => array( 'handler' => '', 'comment' => 'You can <code>define (&quot;MEDIA_TRASH&quot;, true);</code> in your <code>wp-config.php</code> to activate the WordPress "Trash" feature for attachments.' ),
142
+
143
+ 'c0' => array( 'handler' => '', 'comment' => '<h3>Unattached Media Library item operations</h3>' ),
144
+ 'Trash Unattached' => array( 'handler' => '_trash_unattached_items',
145
+ 'comment' => 'Move unattached items to "media trash".' ),
146
+ 'Delete Unattached' => array( 'handler' => '_delete_unattached_items',
147
+ 'comment' => 'Permanently delete unattached items.' ),
148
+ );
149
+
150
+ /*
151
+ * Conditional display of the "Trash" action
152
+ */
153
+ if ( ! ( defined('MEDIA_TRASH') && MEDIA_TRASH ) ) {
154
+ unset( $setting_actions['Trash Unattached'] );
155
+ }
156
+
157
+ echo '<div class="wrap">' . "\n";
158
+ echo "\t\t" . '<div id="icon-tools" class="icon32"><br/></div>' . "\n";
159
+ echo "\t\t" . '<h2>Unattached Fixit Tools v' . self::CURRENT_VERSION . '</h2>' . "\n";
160
+
161
+ if ( !current_user_can( 'delete_posts' ) ) {
162
+ echo "\t\t<br>ERROR: You are not allowed to delete/trash Media Library items.\n";
163
+ return;
164
+ }
165
+
166
+ if ( isset( $_REQUEST[ self::SLUG_PREFIX . 'action' ] ) ) {
167
+ $label = $_REQUEST[ self::SLUG_PREFIX . 'action' ];
168
+ if( isset( $setting_actions[ $label ] ) ) {
169
+ $action = $setting_actions[ $label ]['handler'];
170
+ if ( ! empty( $action ) ) {
171
+ if ( method_exists( 'Unattached_Fixit', $action ) ) {
172
+ echo self::$action();
173
+ } else {
174
+ echo "\t\t<br>ERROR: handler does not exist for action: \"{$label}\"\n";
175
+ }
176
+ } else {
177
+ echo "\t\t<br>ERROR: no handler for action: \"{$label}\"\n";
178
+ }
179
+ } else {
180
+ echo "\t\t<br>ERROR: unknown action: \"{$label}\"\n";
181
+ }
182
+ }
183
+
184
+ echo "\t\t" . '<div style="width:700px">' . "\n";
185
+ 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";
186
+ echo "\t\t" . ' <p class="submit" style="padding-bottom: 0;">' . "\n";
187
+ echo "\t\t" . ' <table>' . "\n";
188
+
189
+ echo "\t\t" . ' <tr valign="top">' . "\n";
190
+ echo "\t\t" . ' <td width="24%" style="text-align: right; padding-right: 5px" >First Attachment ID</td>' . "\n";
191
+ echo "\t\t" . ' <td width="24%" style="text-align: left;"><input name="' . self::SLUG_PREFIX . 'attachment_lower" type="text" size="5" value=""></td>' . "\n";
192
+ echo "\t\t" . ' </tr>' . "\n";
193
+
194
+ echo "\t\t" . ' <tr valign="top">' . "\n";
195
+ echo "\t\t" . ' <td width="24%" style="text-align: right; padding-right: 5px" >Last Attachment ID</td>' . "\n";
196
+ echo "\t\t" . ' <td style="text-align: left;"><input name="' . self::SLUG_PREFIX . 'attachment_upper" type="text" size="5" value=""></td>' . "\n";
197
+ echo "\t\t" . ' </tr>' . "\n";
198
+
199
+ echo "\t\t" . ' <tr valign="top">' . "\n";
200
+ echo "\t\t" . ' <td width="24%" style="text-align: right; padding-right: 5px" >Attachment Limit</td>' . "\n";
201
+ echo "\t\t" . ' <td style="text-align: left;"><input name="' . self::SLUG_PREFIX . 'attachment_limit" type="text" size="5" value=""></td>' . "\n";
202
+ echo "\t\t" . ' </tr>' . "\n";
203
+
204
+ echo "\t\t" . ' <table>' . "\n";
205
+
206
+ foreach ( $setting_actions as $label => $action ) {
207
+ if ( empty( $action['handler'] ) ) {
208
+ echo "\t\t" . ' <tr><td colspan=2 style="padding: 2px 0px;">' . $action['comment'] . "</td></tr>\n";
209
+ } else {
210
+ echo "\t\t" . ' <tr><td width="150px">' . "\n";
211
+ echo "\t\t" . ' <input name="' . self::SLUG_PREFIX . 'action" type="submit" class="button-primary" style="width: 140px;" value="' . $label . '" />&nbsp;&nbsp;' . "\n";
212
+ echo "\t\t" . ' </td><td>' . "\n";
213
+ echo "\t\t" . ' ' . $action['comment'] . "\n";
214
+ echo "\t\t" . ' </td></tr>' . "\n";
215
+ }
216
+ }
217
+
218
+ echo "\t\t" . ' </table>' . "\n";
219
+ echo "\t\t" . ' </p>' . "\n";
220
+ echo "\t\t" . '</form>' . "\n";
221
+ echo "\t\t" . '</div>' . "\n";
222
+ echo "\t\t" . '</div><!-- wrap -->' . "\n";
223
+ }
224
+
225
+ /**
226
+ * Compile array of attachment ID values for the operation
227
+ *
228
+ * @since 1.00
229
+ *
230
+ * @return array
231
+ */
232
+ private static function _get_attachment_ids() {
233
+ global $wpdb;
234
+
235
+ $range_clause = '';
236
+
237
+ if ( ! empty( $_REQUEST[ self::SLUG_PREFIX . 'attachment_lower' ] ) ) {
238
+ $lower_bound = (integer) $_REQUEST[ self::SLUG_PREFIX . 'attachment_lower' ];
239
+ } else {
240
+ $lower_bound = 0;
241
+ }
242
+
243
+ if ( ! empty( $_REQUEST[ self::SLUG_PREFIX . 'attachment_upper' ] ) ) {
244
+ $upper_bound = (integer) $_REQUEST[ self::SLUG_PREFIX . 'attachment_upper' ];
245
+ $range_clause = '( ID >= ' . $lower_bound . ' ) AND ( ID <= ' . $upper_bound . ' ) AND ';
246
+ } elseif ( $lower_bound ) {
247
+ $range_clause = '( ID = ' . $lower_bound . ' ) AND ';
248
+ }
249
+
250
+ if ( ! empty( $_REQUEST[ self::SLUG_PREFIX . 'attachment_limit' ] ) ) {
251
+ $limit_clause = 'LIMIT ' . (integer) $_REQUEST[ self::SLUG_PREFIX . 'attachment_limit' ];
252
+ } else {
253
+ $limit_clause = '';
254
+ }
255
+
256
+ $query = sprintf( 'SELECT ID FROM %1$s WHERE %2$s( post_type = \'attachment\' ) AND ( post_status = \'inherit\' ) AND ( post_parent = 0 ) ORDER BY ID %3$s', $wpdb->posts, $range_clause, $limit_clause );
257
+ error_log( __LINE__ . ' Unattached_Fixit::_get_attachment_ids() $query = ' . var_export( $query, true ), 0 );
258
+ $results = $wpdb->get_col( $query );
259
+ error_log( __LINE__ . ' Unattached_Fixit::_get_attachment_ids() $results = ' . var_export( $results, true ), 0 );
260
+
261
+ return $results;
262
+ } // _get_attachment_ids
263
+
264
+ /**
265
+ * Move unattached items to "media trash"
266
+ * @since 1.00
267
+ *
268
+ * @return string HTML markup for results/messages
269
+ */
270
+ private static function _trash_unattached_items() {
271
+ /*
272
+ * Compile array of attachment ID values
273
+ */
274
+ $attachment_ids = self::_get_attachment_ids();
275
+
276
+ // Initialize statistics
277
+ $attachment_count = count( $attachment_ids );
278
+ $updates = 0;
279
+ $errors = 0;
280
+
281
+ foreach ( $attachment_ids as $attachment_id ) {
282
+ if ( wp_trash_post( $attachment_id ) ) {
283
+ $updates++;
284
+ } else {
285
+ $errors++;
286
+ }
287
+ } // foreach attachment
288
+
289
+ return "<br>Trash Unattached matched {$attachment_count} attachments and made {$updates} update(s). There were {$errors} error(s).\n";
290
+ } // _trash_unattached_items
291
+
292
+ /**
293
+ * Permanently delete unattached items
294
+ * @since 1.00
295
+ *
296
+ * @return string HTML markup for results/messages
297
+ */
298
+ private static function _delete_unattached_items() {
299
+ /*
300
+ * Compile array of attachment ID values
301
+ */
302
+ $attachment_ids = self::_get_attachment_ids();
303
+
304
+ // Initialize statistics
305
+ $attachment_count = count( $attachment_ids );
306
+ $updates = 0;
307
+ $errors = 0;
308
+
309
+ foreach ( $attachment_ids as $attachment_id ) {
310
+ if ( wp_delete_attachment( $attachment_id, true ) ) {
311
+ $updates++;
312
+ } else {
313
+ $errors++;
314
+ }
315
+ } // foreach attachment
316
+
317
+ return "<br>Delete Unattached matched {$attachment_count} attachments and made {$updates} update(s). There were {$errors} error(s).\n";
318
+ } // _delete_unattached_items
319
+ } //Unattached_Fixit
320
+
321
+ /*
322
+ * Install the submenu at an early opportunity
323
+ */
324
+ add_action('init', 'Unattached_Fixit::initialize');
325
+ ?>
examples/mla-yoast-seo-example.php.txt ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Supports WordPress SEO by Yoast Page Analysis and XMP Sitemap generation
4
+ *
5
+ * @package MLA Yoast SEO Example
6
+ * @version 1.10
7
+ */
8
+
9
+ /*
10
+ Plugin Name: MLA Yoast SEO Example
11
+ Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
12
+ Description: Supports WordPress SEO by Yoast Page Analysis and XMP Sitemap generation
13
+ Author: David Lingren
14
+ Version: 1.10
15
+ Author URI: http://fairtradejudaica.org/our-story/staff/
16
+
17
+ Copyright 2014 - 2015 David Lingren
18
+
19
+ This program is free software; you can redistribute it and/or modify
20
+ it under the terms of the GNU General Public License as published by
21
+ the Free Software Foundation; either version 2 of the License, or
22
+ (at your option) any later version.
23
+
24
+ This program is distributed in the hope that it will be useful,
25
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
+ GNU General Public License for more details.
28
+
29
+ You can get a copy of the GNU General Public License by writing to the
30
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
31
+ */
32
+
33
+ /**
34
+ * Call it anything you want, but give it an unlikely and hopefully unique name. Hiding everything
35
+ * else inside a class means this is the only name you have to worry about.
36
+ *
37
+ * @package MLA Yoast SEO Example
38
+ * @since 1.00
39
+ */
40
+ class MLAYoastSEOExample {
41
+ /**
42
+ * Initialization function, similar to __construct()
43
+ *
44
+ * @since 1.00
45
+ *
46
+ * @return void
47
+ */
48
+ public static function initialize() {
49
+ /*
50
+ * Filter: 'wpseo_sitemap_urlimages' - Allows updates to the list of images in the page/post
51
+ * Filter: 'wpseo_sitemap_entry' - adjusts the entire entry before it gets added to the sitemap
52
+ *
53
+ * Defined/applied in /wordpress-seo/inc/class-sitemaps.php
54
+ */
55
+ add_filter( 'wpseo_sitemap_urlimages', 'MLAYoastSEOExample::wpseo_sitemap_urlimages', 10, 2 );
56
+ //add_filter( 'wpseo_sitemap_entry', 'MLAYoastSEOExample::wpseo_sitemap_entry', 10, 3 );
57
+ }
58
+
59
+ /**
60
+ * Add [mla_gallery] output to 'images' array for SEO analysis
61
+ *
62
+ * @since 1.10
63
+ *
64
+ * @param array $url ( [index] => array( 'src' => URL of image file, 'alt' => ALT Text ) )
65
+ * @param integer $post_id ID of the current post
66
+ */
67
+ public static function wpseo_sitemap_urlimages( $url, $post_id ) {
68
+ global $post;
69
+ //error_log( __LINE__ . " wpseo_sitemap_urlimages( {$post_id} ) initial url = " . var_export( $url, true ), 0 );
70
+
71
+ $post = get_post( $post_id ); // Set the parent post/page; used in [mla_gallery]
72
+ if ( $count = preg_match_all( "/\\[mla_gallery([^\\]]*)\\]/", $post->post_content, $matches ) ) {
73
+ foreach( $matches[0] as $index => $match ) {
74
+ $tail = $matches[1][ $index ];
75
+ /*
76
+ * Only process shortcodes that are an exact match
77
+ */
78
+ if ( empty( $tail ) || ( ' ' == substr( $tail, 0, 1 ) ) ) {
79
+ $the_gallery = do_shortcode( $match );
80
+
81
+ /*
82
+ * If MLA is not active the shortcode is not processed;
83
+ * substitute empty results.
84
+ */
85
+ if ( $the_gallery == $match ) {
86
+ $the_gallery = '';
87
+ }
88
+
89
+ $ref_count = preg_match_all( '/\<img.*src="([^"]*)".*alt="([^"]*)"/', $the_gallery, $references );
90
+ if ( $ref_count ) {
91
+ foreach( $references[1] as $ref_index => $reference ) {
92
+ $url[] = array( 'src' => $reference, 'alt' => $references[2][ $ref_index ] );
93
+ }
94
+ }
95
+
96
+ unset( $ref_count, $references );
97
+ } // exact match
98
+ }
99
+ //error_log( __LINE__ . " wpseo_sitemap_urlimages( {$post_id} ) final url = " . var_export( $url, true ), 0 );
100
+ unset( $count, $matches );
101
+ } // found matche(s)
102
+
103
+ return $url;
104
+ }
105
+
106
+ /**
107
+ * Add [mla_gallery] output to post/page content for SEO anapysis
108
+ *
109
+ * @since 1.00
110
+ *
111
+ * @param string $post_content The Post content string
112
+ * @param object $the_post The post object.
113
+ *
114
+ * @return string Expanded Post content string
115
+ */
116
+ public static function wpseo_sitemap_entry( $url, $post_type, $the_post ) {
117
+ //error_log( __LINE__ . " wpseo_sitemap_entry( {$post_type}, {$the_post->ID} ) initial url = " . var_export( $url, true ), 0 );
118
+ //error_log( __LINE__ . " wpseo_sitemap_entry( {$post_type}, {$the_post->ID} ) the_post = " . var_export( $the_post, true ), 0 );
119
+
120
+ return $url;
121
+ }
122
+ } // Class MLAYoastSEOExample
123
+
124
+ /*
125
+ * Install the filter at an early opportunity
126
+ */
127
+ add_action('init', 'MLAYoastSEOExample::initialize');
128
+ ?>
includes/class-mla-ajax.php ADDED
@@ -0,0 +1,266 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Media Library Assistant Ajax Handlers
4
+ *
5
+ * @package Media Library Assistant
6
+ * @since 2.20
7
+ */
8
+
9
+ /**
10
+ * Class MLA (Media Library Assistant) Ajax contains handlers for simple Ajax requests
11
+ *
12
+ * @package Media Library Assistant
13
+ * @since 2.20
14
+ */
15
+ class MLA_Ajax {
16
+ /**
17
+ * Initialization function, similar to __construct()
18
+ *
19
+ * @since 2.20
20
+ *
21
+ * @return void
22
+ */
23
+ public static function initialize() {
24
+ add_action( 'admin_init', 'MLA_Ajax::mla_admin_init_action' );
25
+ }
26
+
27
+ /**
28
+ * Adds flat checklist taxonomy support to the Media Manager Modal Window.
29
+ * Declared public because it is an action.
30
+ *
31
+ * @since 2.20
32
+ */
33
+ public static function mla_admin_init_action( ) {
34
+ //error_log( 'DEBUG: MLA_Ajax::mla_admin_init_action() $_REQUEST = ' . var_export( $_REQUEST, true ), 0 );
35
+
36
+ /*
37
+ * If there's no action variable, we have nothing more to do
38
+ */
39
+ if ( ! isset( $_POST['action'] ) ) {
40
+ return;
41
+ }
42
+
43
+ /*
44
+ * For flat taxonomies that use the checklist meta box, substitute our own handler
45
+ * for /wp-admin/includes/ajax-actions.php function _wp_ajax_add_hierarchical_term().
46
+ */
47
+ if ( ( defined('DOING_AJAX') && DOING_AJAX ) && ( 'add-' == substr( $_POST['action'], 0, 4 ) ) ) {
48
+ $key = substr( $_POST['action'], 4 );
49
+ if ( MLACore::mla_taxonomy_support( $key, 'flat-checklist' ) ) {
50
+ self::_mla_ajax_add_flat_term( $key );
51
+ /* note: this function sends an Ajax response and then dies; no return */
52
+ }
53
+ }
54
+
55
+ add_action( 'wp_ajax_' . 'mla_find_posts', 'MLA_Ajax::mla_find_posts_ajax_action' );
56
+ add_action( 'wp_ajax_' . MLACore::JAVASCRIPT_INLINE_EDIT_SLUG . '-set-parent', 'MLA_Ajax::mla_set_parent_ajax_action' );
57
+ }
58
+
59
+ /**
60
+ * Add flat taxonomy term from "checklist" meta box on the Media Manager Modal Window
61
+ *
62
+ * Adapted from the WordPress post_categories_meta_box() in /wp-admin/includes/meta-boxes.php.
63
+ *
64
+ * @since 2.20
65
+ *
66
+ * @param string The taxonomy name, from $_POST['action']
67
+ *
68
+ * @return void Sends JSON response with updated HTML for the checklist
69
+ */
70
+ private static function _mla_ajax_add_flat_term( $key ) {
71
+ $taxonomy = get_taxonomy( $key );
72
+ check_ajax_referer( $_POST['action'], '_ajax_nonce-add-' . $key, true );
73
+
74
+ if ( !current_user_can( $taxonomy->cap->edit_terms ) ) {
75
+ wp_die( -1 );
76
+ }
77
+
78
+ $new_names = explode( ',', $_POST[ 'new' . $key ] );
79
+ $new_terms_markup = '';
80
+ foreach( $new_names as $name ) {
81
+ if ( '' === sanitize_title( $name ) ) {
82
+ continue;
83
+ }
84
+
85
+ if ( ! $id = term_exists( $name, $key ) ) {
86
+ $id = wp_insert_term( $name, $key );
87
+ }
88
+
89
+ if ( is_wp_error( $id ) ) {
90
+ continue;
91
+ }
92
+
93
+ if ( is_array( $id ) ) {
94
+ $id = absint( $id['term_id'] );
95
+ } else {
96
+ continue;
97
+ }
98
+ $term = get_term( $id, $key );
99
+ $name = $term->name;
100
+ $new_terms_markup .= "<li id='{$key}-{$id}'><label class='selectit'><input value='{$name}' type='checkbox' name='tax_input[{$key}][]' id='in-{$key}-{$id}' checked='checked' />{$name}</label></li>\n";
101
+ } // foreach new_name
102
+
103
+ $input_new_parent_name = "new{$key}_parent";
104
+ $supplemental = "<input type='hidden' name='{$input_new_parent_name}' id='{$input_new_parent_name}' value='-1' />";
105
+
106
+ $add = array(
107
+ 'what' => $key,
108
+ 'id' => $id,
109
+ 'data' => $new_terms_markup,
110
+ 'position' => -1,
111
+ 'supplemental' => array( 'newcat_parent' => $supplemental )
112
+ );
113
+
114
+ $x = new WP_Ajax_Response( $add );
115
+ $x->send();
116
+ } // _mla_ajax_add_flat_term
117
+
118
+ /**
119
+ * Ajax handler to fetch candidates for the "Set Parent" popup window
120
+ *
121
+ * Adapted from wp_ajax_find_posts in /wp-admin/includes/ajax-actions.php.
122
+ * Adds filters for post type and pagination.
123
+ *
124
+ * @since 1.90
125
+ *
126
+ * @return void passes results to wp_send_json_success() for JSON encoding and transmission
127
+ */
128
+ public static function mla_find_posts_ajax_action() {
129
+ global $wpdb;
130
+
131
+ check_ajax_referer( 'mla_find_posts', MLACore::MLA_ADMIN_NONCE_NAME );
132
+
133
+ $post_types = get_post_types( array( 'public' => true ), 'objects' );
134
+ unset( $post_types['attachment'] );
135
+
136
+ $s = stripslashes( $_REQUEST['mla_set_parent_search_text'] );
137
+ $count = isset( $_REQUEST['mla_set_parent_count'] ) ? $_REQUEST['mla_set_parent_count'] : 50;
138
+ $paged = isset( $_REQUEST['mla_set_parent_paged'] ) ? $_REQUEST['mla_set_parent_paged'] : 1;
139
+
140
+ $args = array(
141
+ 'post_type' => ( 'all' == $_REQUEST['mla_set_parent_post_type'] ) ? array_keys( $post_types ) : $_REQUEST['mla_set_parent_post_type'],
142
+ 'post_status' => 'any',
143
+ 'posts_per_page' => $count,
144
+ 'paged' => $paged,
145
+ );
146
+
147
+ if ( '' !== $s )
148
+ $args['s'] = $s;
149
+
150
+ $posts = get_posts( $args );
151
+
152
+ if ( ( ! $posts ) && $paged > 1 ) {
153
+ $args['paged'] = $paged = 1;
154
+ $posts = get_posts( $args );
155
+ }
156
+
157
+ $found = count( $posts );
158
+
159
+ $html = '<input name="mla_set_parent_count" id="mla-set-parent-count" type="hidden" value="' . $count . "\">\n";
160
+ $html .= '<input name="mla_set_parent_paged" id="mla-set-parent-paged" type="hidden" value="' . $paged . "\">\n";
161
+ $html .= '<input name="mla_set_parent_found" id="mla-set-parent-found" type="hidden" value="' . $found . "\">\n";
162
+
163
+ $html .= '<table class="widefat"><thead><tr><th class="found-radio"><br /></th><th>'.__('Title').'</th><th class="no-break">'.__('Type').'</th><th class="no-break">'.__('Date').'</th><th class="no-break">'.__('Status').'</th></tr></thead><tbody>' . "\n";
164
+ if ( $found ) {
165
+ $alt = '';
166
+ foreach ( $posts as $post ) {
167
+ $title = trim( $post->post_title ) ? $post->post_title : __( '(no title)' );
168
+ $alt = ( 'alternate' == $alt ) ? '' : 'alternate';
169
+
170
+ switch ( $post->post_status ) {
171
+ case 'publish' :
172
+ case 'private' :
173
+ $stat = __('Published');
174
+ break;
175
+ case 'future' :
176
+ $stat = __('Scheduled');
177
+ break;
178
+ case 'pending' :
179
+ $stat = __('Pending Review');
180
+ break;
181
+ case 'draft' :
182
+ $stat = __('Draft');
183
+ break;
184
+ default:
185
+ $stat = sanitize_text_field( $post->post_status );
186
+ }
187
+
188
+ if ( '0000-00-00 00:00:00' == $post->post_date ) {
189
+ $time = '';
190
+ } else {
191
+ /* translators: date format in table columns, see http://php.net/date */
192
+ $time = mysql2date(__('Y/m/d'), $post->post_date);
193
+ }
194
+
195
+ $html .= '<tr class="' . trim( 'found-posts ' . $alt ) . '"><td class="found-radio"><input type="radio" id="found-'.$post->ID.'" name="found_post_id" value="' . esc_attr($post->ID) . '"></td>';
196
+ $html .= '<td><label for="found-'.$post->ID.'">' . esc_html( $title ) . '</label></td><td class="no-break">' . esc_html( $post_types[$post->post_type]->labels->singular_name ) . '</td><td class="no-break">'.esc_html( $time ) . '</td><td class="no-break">' . esc_html( $stat ). ' </td></tr>' . "\n";
197
+ } // foreach post
198
+ } else {
199
+ $html .= '<tr class="' . trim( 'found-posts ' ) . '"><td class="found-radio">&nbsp;</td>';
200
+ $html .= '<td colspan="4">No results found.</td></tr>' . "\n";
201
+ }
202
+
203
+ $html .= "</tbody></table>\n";
204
+
205
+ wp_send_json_success( $html );
206
+ }
207
+
208
+ /**
209
+ * Ajax handler to set post_parent for a single attachment
210
+ *
211
+ * Adapted from wp_ajax_inline_save in /wp-admin/includes/ajax-actions.php
212
+ *
213
+ * @since 0.20
214
+ *
215
+ * @return void echo HTML <td> innerHTML for updated call or error message, then die()
216
+ */
217
+ public static function mla_set_parent_ajax_action() {
218
+ check_ajax_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
219
+
220
+ if ( empty( $_REQUEST['post_ID'] ) ) {
221
+ echo __( 'ERROR', 'media-library-assistant' ) . ': ' . __( 'No post ID found', 'media-library-assistant' );
222
+ die();
223
+ } else {
224
+ $post_id = $_REQUEST['post_ID'];
225
+ }
226
+
227
+ if ( ! current_user_can( 'edit_post', $post_id ) ) {
228
+ wp_die( __( 'ERROR', 'media-library-assistant' ) . ': ' . __( 'You are not allowed to edit this Attachment.', 'media-library-assistant' ) );
229
+ }
230
+
231
+ if ( ! class_exists( 'MLAData' ) ) {
232
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-data.php' );
233
+ MLAData::initialize();
234
+ }
235
+
236
+ $results = MLAData::mla_update_single_item( $post_id, $_REQUEST );
237
+ if ( false !== strpos( $results['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
238
+ wp_die( $results['message'] );
239
+ }
240
+
241
+ $new_item = (object) MLAData::mla_get_attachment_by_id( $post_id );
242
+
243
+ if ( ! class_exists( 'MLA_List_Table' ) ) {
244
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-list-table.php' );
245
+ MLA_List_Table::mla_admin_init_action();
246
+ }
247
+
248
+ // Create an instance of our package class and echo the new HTML
249
+ $MLAListTable = apply_filters( 'mla_list_table_new_instance', NULL );
250
+ if ( is_null( $MLAListTable ) ) {
251
+ $MLAListTable = new MLA_List_Table();
252
+ }
253
+
254
+ $MLAListTable->single_row( $new_item );
255
+ die(); // this is required to return a proper result
256
+ }
257
+ } // Class MLA_Ajax
258
+
259
+ /*
260
+ * Check for Media Manager Enhancements
261
+ */
262
+ if ( ( ( 'checked' == MLACore::mla_get_option( MLACore::MLA_MEDIA_MODAL_TOOLBAR ) ) || ( 'checked' == MLACore::mla_get_option( MLACore::MLA_MEDIA_GRID_TOOLBAR ) ) ) ) {
263
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-media-modal-ajax.php' );
264
+ add_action( 'init', 'MLAModal_Ajax::initialize', 0x7FFFFFFF );
265
+ }
266
+ ?>
includes/class-mla-core.php ADDED
@@ -0,0 +1,2315 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Media Library Assistant Core objects
4
+ *
5
+ * @package Media Library Assistant
6
+ * @since 2.20
7
+ */
8
+ defined( 'ABSPATH' ) or die();
9
+
10
+ /**
11
+ * Class MLA (Media Library Assistant) Core is the minimum support required for all other MLA features
12
+ *
13
+ * @package Media Library Assistant
14
+ * @since 2.20
15
+ */
16
+ class MLACore {
17
+ /**
18
+ * Original PHP error_log path and file
19
+ *
20
+ * @since 2.20
21
+ *
22
+ * @var string
23
+ */
24
+ public static $original_php_log = '?';
25
+
26
+ /**
27
+ * Original PHP error_reporting value
28
+ *
29
+ * @since 2.20
30
+ *
31
+ * @var string
32
+ */
33
+ public static $original_php_reporting = '?';
34
+
35
+ /**
36
+ * Constant to log Ajax debug activity
37
+ *
38
+ * @since 2.13
39
+ *
40
+ * @var integer
41
+ */
42
+ CONST MLA_DEBUG_CATEGORY_AJAX = 0x00000002;
43
+
44
+ /**
45
+ * Constant to log WPML/Polylang action/filter activity
46
+ *
47
+ * @since 2.15
48
+ *
49
+ * @var integer
50
+ */
51
+ CONST MLA_DEBUG_CATEGORY_LANGUAGE = 0x00000004;
52
+
53
+ /**
54
+ * Slug for adding plugin submenu
55
+ *
56
+ * @since 0.1
57
+ *
58
+ * @var string
59
+ */
60
+ const ADMIN_PAGE_SLUG = 'mla-menu';
61
+
62
+ /**
63
+ * mla_admin_action value for permanently deleting a single item
64
+ *
65
+ * @since 0.1
66
+ *
67
+ * @var string
68
+ */
69
+ const MLA_ADMIN_SINGLE_DELETE = 'single_item_delete';
70
+
71
+ /**
72
+ * mla_admin_action value for moving a single item to the trash
73
+ *
74
+ * @since 0.1
75
+ *
76
+ * @var string
77
+ */
78
+ const MLA_ADMIN_SINGLE_TRASH = 'single_item_trash';
79
+
80
+ /**
81
+ * mla_admin_action value for restoring a single item from the trash
82
+ *
83
+ * @since 0.1
84
+ *
85
+ * @var string
86
+ */
87
+ const MLA_ADMIN_SINGLE_RESTORE = 'single_item_restore';
88
+
89
+ /**
90
+ * Action name; gives a context for the nonce
91
+ *
92
+ * @since 0.1
93
+ *
94
+ * @var string
95
+ */
96
+ const MLA_ADMIN_NONCE_ACTION = 'mla_admin_nonce_action';
97
+
98
+ /**
99
+ * Nonce name; uniquely identifies the nonce
100
+ *
101
+ * @since 2.13
102
+ *
103
+ * @var string
104
+ */
105
+ const MLA_ADMIN_NONCE_NAME = 'mla_admin_nonce';
106
+
107
+ /**
108
+ * Slug for localizing and enqueueing JavaScript - MLA List Table
109
+ *
110
+ * @since 0.20
111
+ *
112
+ * @var string
113
+ */
114
+ const JAVASCRIPT_INLINE_EDIT_SLUG = 'mla-inline-edit-scripts';
115
+
116
+ /**
117
+ * Slug for the "query attachments" action - Add Media and related dialogs
118
+ *
119
+ * @since 1.80
120
+ *
121
+ * @var string
122
+ */
123
+ const JAVASCRIPT_QUERY_ATTACHMENTS_ACTION = 'mla-query-attachments';
124
+
125
+ /**
126
+ * Slug for the "fill compat-attachment-fields" action - Add Media and related dialogs
127
+ *
128
+ * @since 1.80
129
+ *
130
+ * @var string
131
+ */
132
+ const JAVASCRIPT_FILL_COMPAT_ACTION = 'mla-fill-compat-fields';
133
+
134
+ /**
135
+ * Slug for the "update compat-attachment-fields" action - Add Media and related dialogs
136
+ *
137
+ * @since 1.80
138
+ *
139
+ * @var string
140
+ */
141
+ const JAVASCRIPT_UPDATE_COMPAT_ACTION = 'mla-update-compat-fields';
142
+
143
+ /**
144
+ * Provides a unique name for the settings page
145
+ *
146
+ * @since 2.20
147
+ *
148
+ * @var string
149
+ */
150
+ const MLA_SETTINGS_SLUG = 'mla-settings-menu';
151
+
152
+ /**
153
+ * Provides a unique name for the current version option
154
+ */
155
+ const MLA_VERSION_OPTION = 'current_version';
156
+
157
+ /**
158
+ * Provides a unique name for the exclude revisions option
159
+ */
160
+ const MLA_EXCLUDE_REVISIONS = 'exclude_revisions';
161
+
162
+ /**
163
+ * Provides a unique name for a database tuning option
164
+ */
165
+ const MLA_FEATURED_IN_TUNING = 'featured_in_tuning';
166
+
167
+ /**
168
+ * Provides a unique name for a database tuning option
169
+ */
170
+ const MLA_INSERTED_IN_TUNING = 'inserted_in_tuning';
171
+
172
+ /**
173
+ * Provides a unique name for a database tuning option
174
+ */
175
+ const MLA_GALLERY_IN_TUNING = 'gallery_in_tuning';
176
+
177
+ /**
178
+ * Provides a unique name for a database tuning option
179
+ */
180
+ const MLA_MLA_GALLERY_IN_TUNING = 'mla_gallery_in_tuning';
181
+
182
+ /**
183
+ * Provides a unique name for the taxonomy count Attachments option
184
+ */
185
+ const MLA_COUNT_TERM_ATTACHMENTS = 'count_term_attachments';
186
+
187
+ /**
188
+ * Provides a unique name for the taxonomy support option
189
+ */
190
+ const MLA_TAXONOMY_SUPPORT = 'taxonomy_support';
191
+
192
+ /**
193
+ * Provides a unique name for the admin screen page title option
194
+ */
195
+ const MLA_SCREEN_PAGE_TITLE = 'admin_screen_page_title';
196
+
197
+ /**
198
+ * Provides a unique name for the admin screen menu title option
199
+ */
200
+ const MLA_SCREEN_MENU_TITLE = 'admin_screen_menu_title';
201
+
202
+ /**
203
+ * Provides a unique name for the admin screen menu order option
204
+ */
205
+ const MLA_SCREEN_ORDER = 'admin_screen_menu_order';
206
+
207
+ /**
208
+ * Provides a unique name for the admin screen remove Media/Library option
209
+ */
210
+ const MLA_SCREEN_DISPLAY_LIBRARY = 'admin_screen_display_default';
211
+
212
+ /**
213
+ * Provides a unique name for the default orderby option
214
+ */
215
+ const MLA_DEFAULT_ORDERBY = 'default_orderby';
216
+
217
+ /**
218
+ * Provides a unique name for the default order option
219
+ */
220
+ const MLA_DEFAULT_ORDER = 'default_order';
221
+
222
+ /**
223
+ * Provides a unique name for the Media/Assistant submenu table views width option
224
+ */
225
+ const MLA_TABLE_VIEWS_WIDTH = 'table_views_width';
226
+
227
+ /**
228
+ * Provides a unique name for the Media/Assistant submenu table thumbnail/icon size option
229
+ */
230
+ const MLA_TABLE_ICON_SIZE = 'table_icon_size';
231
+
232
+ /**
233
+ * Provides a unique name for the Bulk Update and Map All chunk size option
234
+ */
235
+ const MLA_BULK_CHUNK_SIZE = 'bulk_chunk_size';
236
+
237
+ /**
238
+ * Provides a unique name for the taxonomy filter maximum depth option
239
+ */
240
+ const MLA_TAXONOMY_FILTER_DEPTH = 'taxonomy_filter_depth';
241
+
242
+ /**
243
+ * Provides a unique name for the taxonomy filter maximum depth option
244
+ */
245
+ const MLA_TAXONOMY_FILTER_INCLUDE_CHILDREN = 'taxonomy_filter_include_children';
246
+
247
+ /**
248
+ * Provides a unique name for the display Search Media controls option
249
+ */
250
+ const MLA_SEARCH_MEDIA_FILTER_SHOW_CONTROLS = 'search_media_filter_show_controls';
251
+
252
+ /**
253
+ * Provides a unique name for the display Search Media controls option
254
+ */
255
+ const MLA_SEARCH_MEDIA_FILTER_DEFAULTS = 'search_media_filter_defaults';
256
+
257
+ /**
258
+ * Provides a "size" attribute value for the EXIF/Template Value field
259
+ */
260
+ const MLA_EXIF_SIZE = 30;
261
+
262
+ /**
263
+ * Provides a unique name for the Custom Field "new rule" key
264
+ */
265
+ const MLA_NEW_CUSTOM_RULE = '__NEW_RULE__';
266
+
267
+ /**
268
+ * Provides a unique name for the Custom Field "new field" key
269
+ */
270
+ const MLA_NEW_CUSTOM_FIELD = '__NEW_FIELD__';
271
+
272
+ /**
273
+ * Provides a unique name for the "searchable taxonomies" option
274
+ */
275
+ const MLA_EDIT_MEDIA_SEARCH_TAXONOMY = 'edit_media_search_taxonomy';
276
+
277
+ /**
278
+ * Provides a unique name for the Edit Media additional meta boxes option
279
+ */
280
+ const MLA_EDIT_MEDIA_META_BOXES = 'edit_media_meta_boxes';
281
+
282
+ /**
283
+ * Provides a unique name for the Media/Add New bulk edit option
284
+ */
285
+ const MLA_ADD_NEW_BULK_EDIT = 'add_new_bulk_edit';
286
+
287
+ /**
288
+ * Provides a unique name for the Media/Add New bulk edit "on top" option
289
+ */
290
+ const MLA_ADD_NEW_BULK_EDIT_ON_TOP = 'add_new_bulk_edit_on_top';
291
+
292
+ /**
293
+ * Provides a unique name for the Media/Add New bulk edit "Open Automatically" option
294
+ */
295
+ const MLA_ADD_NEW_BULK_EDIT_AUTO_OPEN = 'add_new_bulk_edit_auto_open';
296
+
297
+ /**
298
+ * Provides a unique name for the Media Grid toolbar option, which
299
+ * also controls the ATTACHMENT DETAILS enhancements
300
+ */
301
+ const MLA_MEDIA_GRID_TOOLBAR = 'media_grid_toolbar';
302
+
303
+ /**
304
+ * Provides a unique name for the Media Manager toolbar option, which
305
+ * also controls the ATTACHMENT DETAILS enhancements
306
+ */
307
+ const MLA_MEDIA_MODAL_TOOLBAR = 'media_modal_toolbar';
308
+
309
+ /**
310
+ * Provides a unique name for the Media Manager toolbar MIME Types option
311
+ */
312
+ const MLA_MEDIA_MODAL_MIMETYPES = 'media_modal_mimetypes';
313
+
314
+ /**
315
+ * Provides a unique name for the Media Manager toolbar Month and Year option
316
+ */
317
+ const MLA_MEDIA_MODAL_MONTHS = 'media_modal_months';
318
+
319
+ /**
320
+ * Provides a unique name for the Media Manager toolbar Taxonomy Terms option
321
+ */
322
+ const MLA_MEDIA_MODAL_TERMS = 'media_modal_terms';
323
+
324
+ /**
325
+ * Provides a unique name for the Media Manager toolbar Taxonomy "Terms Search" option
326
+ */
327
+ const MLA_MEDIA_MODAL_TERMS_SEARCH = 'media_modal_terms_search';
328
+
329
+ /**
330
+ * Provides a unique name for the Media Manager toolbar Search Box option
331
+ */
332
+ const MLA_MEDIA_MODAL_SEARCHBOX = 'media_modal_searchbox';
333
+
334
+ /**
335
+ * Provides a unique name for the Media Manager toolbar Search Box Controls option
336
+ */
337
+ const MLA_MEDIA_MODAL_SEARCHBOX_CONTROLS = 'media_modal_searchbox_controls';
338
+
339
+ /**
340
+ * Provides a unique name for the Media Manager Attachment Details searchable taxonomy option
341
+ * This option is for hierarchical taxonomies, e.g., "Att. Categories".
342
+ */
343
+ const MLA_MEDIA_MODAL_DETAILS_CATEGORY_METABOX = 'media_modal_details_category_metabox';
344
+
345
+ /**
346
+ * Provides a unique name for the Media Manager Attachment Details searchable taxonomy option
347
+ * This option is for flat taxonomies, e.g., "Att. Tags".
348
+ */
349
+ const MLA_MEDIA_MODAL_DETAILS_TAG_METABOX = 'media_modal_details_tag_metabox';
350
+
351
+ /**
352
+ * Provides a unique name for the Media Manager Attachment Details auto-fill option
353
+ */
354
+ const MLA_MEDIA_MODAL_DETAILS_AUTOFILL = 'media_modal_details_autofill';
355
+
356
+ /**
357
+ * Provides a unique name for the Media Manager orderby option
358
+ */
359
+ const MLA_MEDIA_MODAL_ORDERBY = 'media_modal_orderby';
360
+
361
+ /**
362
+ * Provides a unique name for the Media Manager order option
363
+ */
364
+ const MLA_MEDIA_MODAL_ORDER = 'media_modal_order';
365
+
366
+ /**
367
+ * Provides a unique name for the Post MIME Types option
368
+ */
369
+ const MLA_POST_MIME_TYPES = 'post_mime_types';
370
+
371
+ /**
372
+ * Provides a unique name for the Enable Post MIME Types option
373
+ */
374
+ const MLA_ENABLE_POST_MIME_TYPES = 'enable_post_mime_types';
375
+
376
+ /**
377
+ * Provides a unique name for the Upload MIME Types option
378
+ */
379
+ const MLA_UPLOAD_MIMES = 'upload_mimes';
380
+
381
+ /**
382
+ * Provides a unique name for the Enable Upload MIME Types option
383
+ */
384
+ const MLA_ENABLE_UPLOAD_MIMES = 'enable_upload_mimes';
385
+
386
+ /**
387
+ * Provides a unique name for the Enable MLA Icons option
388
+ */
389
+ const MLA_ENABLE_MLA_ICONS = 'enable_mla_icons';
390
+
391
+ /**
392
+ * Provides a unique name for the Debug display limit option
393
+ */
394
+ const MLA_DEBUG_DISPLAY_LIMIT = 'debug_display_limit';
395
+
396
+ /**
397
+ * Provides a unique name for the Debug alternate log file option
398
+ */
399
+ const MLA_DEBUG_FILE = 'debug_file';
400
+
401
+ /**
402
+ * Provides a unique name for the Debug replace PHP log file option
403
+ */
404
+ const MLA_DEBUG_REPLACE_PHP_LOG = 'debug_replace_php_log';
405
+
406
+ /**
407
+ * Provides a unique name for the Debug replace PHP error_reporting option
408
+ */
409
+ const MLA_DEBUG_REPLACE_PHP_REPORTING = 'debug_replace_php_reporting';
410
+
411
+ /**
412
+ * Provides a unique name for the Debug replace MLA_DEBUG_LEVEL option
413
+ */
414
+ const MLA_DEBUG_REPLACE_LEVEL = 'debug_replace_level';
415
+
416
+ /**
417
+ * Option setting for "Featured in" reporting
418
+ *
419
+ * This setting is false if the "Featured in" database access setting is "disabled", else true.
420
+ *
421
+ * @since 1.00
422
+ *
423
+ * @var boolean
424
+ */
425
+ public static $process_featured_in = true;
426
+
427
+ /**
428
+ * Option setting for "Inserted in" reporting
429
+ *
430
+ * This setting is false if the "Inserted in" database access setting is "disabled", else true.
431
+ *
432
+ * @since 1.00
433
+ *
434
+ * @var boolean
435
+ */
436
+ public static $process_inserted_in = true;
437
+
438
+ /**
439
+ * Option setting for "Gallery in" reporting
440
+ *
441
+ * This setting is false if the "Gallery in" database access setting is "disabled", else true.
442
+ *
443
+ * @since 1.00
444
+ *
445
+ * @var boolean
446
+ */
447
+ public static $process_gallery_in = true;
448
+
449
+ /**
450
+ * Option setting for "MLA Gallery in" reporting
451
+ *
452
+ * This setting is false if the "MLA Gallery in" database access setting is "disabled", else true.
453
+ *
454
+ * @since 1.00
455
+ *
456
+ * @var boolean
457
+ */
458
+ public static $process_mla_gallery_in = true;
459
+
460
+ /**
461
+ * Initialization function, similar to __construct()
462
+ *
463
+ * @since 1.00
464
+ *
465
+ * @return void
466
+ */
467
+ public static function initialize( ) {
468
+ if ( 'disabled' == MLACore::mla_get_option( MLACore::MLA_FEATURED_IN_TUNING ) ) {
469
+ MLACore::$process_featured_in = false;
470
+ }
471
+
472
+ if ( 'disabled' == MLACore::mla_get_option( MLACore::MLA_INSERTED_IN_TUNING ) ) {
473
+ MLACore::$process_inserted_in = false;
474
+ }
475
+
476
+ if ( 'disabled' == MLACore::mla_get_option( MLACore::MLA_GALLERY_IN_TUNING ) ) {
477
+ MLACore::$process_gallery_in = false;
478
+ }
479
+
480
+ if ( 'disabled' == MLACore::mla_get_option( MLACore::MLA_MLA_GALLERY_IN_TUNING ) ) {
481
+ MLACore::$process_mla_gallery_in = false;
482
+ }
483
+ }
484
+
485
+ /**
486
+ * $mla_option_definitions defines the database options and admin page areas for setting/updating them
487
+ *
488
+ * The array must be populated at runtime in MLAOptions::mla_localize_option_definitions_array();
489
+ * localization calls cannot be placed in the "public static" array definition itself.
490
+ *
491
+ * Each option is defined by an array with the following elements:
492
+ *
493
+ * array key => HTML id/name attribute and option database key (OMIT MLA_OPTION_PREFIX)
494
+ *
495
+ * tab => Settings page tab id for the option
496
+ * name => admin page label or heading text
497
+ * type => 'checkbox', 'header', 'radio', 'select', 'text', 'textarea', 'custom', 'hidden'
498
+ * std => default value
499
+ * help => help text
500
+ * size => text size, default 40
501
+ * cols => textbox columns, default 90
502
+ * rows => textbox rows, default 5
503
+ * options => array of radio or select option values
504
+ * texts => array of radio or select option display texts
505
+ * render => rendering function for 'custom' options. Usage:
506
+ * $options_list .= ['render']( 'render', $key, $value );
507
+ * update => update function for 'custom' options; returns nothing. Usage:
508
+ * $message = ['update']( 'update', $key, $value, $_REQUEST );
509
+ * delete => delete function for 'custom' options; returns nothing. Usage:
510
+ * $message = ['delete']( 'delete', $key, $value, $_REQUEST );
511
+ * reset => reset function for 'custom' options; returns nothing. Usage:
512
+ * $message = ['reset']( 'reset', $key, $value, $_REQUEST );
513
+ */
514
+
515
+ public static $mla_option_definitions = array ();
516
+
517
+ /**
518
+ * Localize $mla_option_definitions array
519
+ *
520
+ * Localization must be done at runtime; these calls cannot be placed in the
521
+ * "public static" array definition itself. Called from MLATest::initialize.
522
+ *
523
+ * @since 2.20
524
+ *
525
+ * @return void
526
+ */
527
+ public static function mla_localize_option_definitions_array() {
528
+ self::$mla_option_definitions = array (
529
+ /*
530
+ * This option records the highest MLA version so-far installed
531
+ */
532
+ self::MLA_VERSION_OPTION =>
533
+ array('tab' => '',
534
+ 'type' => 'hidden',
535
+ 'std' => '0'),
536
+
537
+ /*
538
+ * These checkboxes are no longer used;
539
+ * they are retained for the database version/update check
540
+ */
541
+ 'attachment_category' =>
542
+ array('tab' => '',
543
+ 'name' => __( 'Attachment Categories', 'media-library-assistant' ),
544
+ 'type' => 'hidden', // checkbox',
545
+ 'std' => 'checked',
546
+ 'help' => __( 'Check this option to add support for Attachment Categories.', 'media-library-assistant' )),
547
+
548
+ 'attachment_tag' =>
549
+ array('tab' => '',
550
+ 'name' => __( 'Attachment Tags', 'media-library-assistant' ),
551
+ 'type' => 'hidden', // checkbox',
552
+ 'std' => 'checked',
553
+ 'help' => __( 'Check this option to add support for Attachment Tags.'), 'media-library-assistant' ),
554
+
555
+ 'where_used_header' =>
556
+ array('tab' => 'general',
557
+ 'name' => __( 'Where-used Reporting', 'media-library-assistant' ),
558
+ 'type' => 'header'),
559
+
560
+ self::MLA_EXCLUDE_REVISIONS =>
561
+ array('tab' => 'general',
562
+ 'name' => __( 'Exclude Revisions', 'media-library-assistant' ),
563
+ 'type' => 'checkbox',
564
+ 'std' => 'checked',
565
+ 'help' => __( 'Check this option to exclude revisions from where-used reporting.', 'media-library-assistant' )),
566
+
567
+ 'where_used_subheader' =>
568
+ array('tab' => 'general',
569
+ 'name' => __( 'Where-used database access tuning', 'media-library-assistant' ),
570
+ 'type' => 'subheader'),
571
+
572
+ self::MLA_FEATURED_IN_TUNING =>
573
+ array('tab' => 'general',
574
+ 'name' => __( 'Featured in', 'media-library-assistant' ),
575
+ 'type' => 'select',
576
+ 'std' => 'disabled',
577
+ 'options' => array('enabled', 'disabled'),
578
+ 'texts' => array( __( 'Enabled', 'media-library-assistant' ), __( 'Disabled', 'media-library-assistant' ) ),
579
+ 'help' => __( 'Search database posts and pages for Featured Image attachments.', 'media-library-assistant' )),
580
+
581
+ self::MLA_INSERTED_IN_TUNING =>
582
+ array('tab' => 'general',
583
+ 'name' => __( 'Inserted in', 'media-library-assistant' ),
584
+ 'type' => 'select',
585
+ 'std' => 'disabled',
586
+ 'options' => array('enabled', 'base', 'disabled'),
587
+ 'texts' => array( __( 'Enabled', 'media-library-assistant' ), __( 'Base', 'media-library-assistant' ), __( 'Disabled', 'media-library-assistant' ) ),
588
+ 'help' => __( 'Search database posts and pages for attachments embedded in content.<br>&nbsp;&nbsp;Base = ignore intermediate size suffixes; use path, base name and extension only.', 'media-library-assistant' )),
589
+
590
+ self::MLA_GALLERY_IN_TUNING =>
591
+ array('tab' => 'general',
592
+ 'name' => __( 'Gallery in', 'media-library-assistant' ),
593
+ 'type' => 'select',
594
+ 'std' => 'disabled',
595
+ 'options' => array('dynamic', 'refresh', 'cached', 'disabled'),
596
+ 'texts' => array( __( 'Dynamic', 'media-library-assistant' ), __( 'Refresh', 'media-library-assistant' ), __( 'Cached', 'media-library-assistant' ), __( 'Disabled', 'media-library-assistant' ) ),
597
+ 'help' => __( 'Search database posts and pages for [gallery] shortcode results.<br>&nbsp;&nbsp;Dynamic = once every page load, Cached = once every login, Disabled = never.<br>&nbsp;&nbsp;Refresh = update references, then set to Cached.', 'media-library-assistant' )),
598
+
599
+ self::MLA_MLA_GALLERY_IN_TUNING =>
600
+ array('tab' => 'general',
601
+ 'name' => __( 'MLA Gallery in', 'media-library-assistant' ),
602
+ 'type' => 'select',
603
+ 'std' => 'disabled',
604
+ 'options' => array('dynamic', 'refresh', 'cached', 'disabled'),
605
+ 'texts' => array( __( 'Dynamic', 'media-library-assistant' ), __( 'Refresh', 'media-library-assistant' ), __( 'Cached', 'media-library-assistant' ), __( 'Disabled', 'media-library-assistant' ) ),
606
+ 'help' => __( 'Search database posts and pages for [mla_gallery] shortcode results.<br>&nbsp;&nbsp;Dynamic = once every page load, Cached = once every login, Disabled = never.<br>&nbsp;&nbsp;Refresh = update references, then set to Cached.', 'media-library-assistant' )),
607
+
608
+ 'taxonomy_header' =>
609
+ array('tab' => 'general',
610
+ 'name' => __( 'Taxonomy Support', 'media-library-assistant' ),
611
+ 'type' => 'header'),
612
+
613
+ self::MLA_COUNT_TERM_ATTACHMENTS =>
614
+ array('tab' => 'general',
615
+ 'name' => __( 'Compute Attachments Column', 'media-library-assistant' ),
616
+ 'type' => 'checkbox',
617
+ 'std' => 'checked',
618
+ 'help' => __( 'Check this option to calculate attachments per term in the Attachments Column.', 'media-library-assistant' )),
619
+
620
+ self::MLA_TAXONOMY_SUPPORT =>
621
+ array('tab' => 'general',
622
+ 'help' => __( 'Check the "<strong>Support</strong>" box to add the taxonomy to the Assistant and the Edit Media screen.', 'media-library-assistant' ) . '<br>' .
623
+ __( 'Check the "<strong>Inline Edit</strong>" box to display the taxonomy in the Quick Edit and Bulk Edit areas.', 'media-library-assistant' ) . '<br>' .
624
+ __( 'Check the "<strong>Term Search</strong>" box to add the taxonomy to the "Search Media/Terms" list.', 'media-library-assistant' ) .
625
+ sprintf( ' %1$s <a href="%2$s">%3$s</a>.', __( 'For complete documentation', 'media-library-assistant' ), admin_url( 'options-general.php?page=' . MLACore::MLA_SETTINGS_SLUG . '-documentation&amp;mla_tab=documentation#terms_search' ), __( 'click here', 'media-library-assistant' ) )
626
+ . '<br>' .
627
+ __( 'Check the "<strong>Checklist</strong>" box to enable the checklist-style meta box for a flat taxonomy.', 'media-library-assistant' ) . '&nbsp;' .
628
+ __( 'You must also check the <strong>"Enable enhanced checklist taxonomies"</strong> box below to enable this feature.', 'media-library-assistant' ) . '<br>' .
629
+ __( '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>' .
630
+ __( 'Use the "<strong>List Filter</strong>" option to select the taxonomy on which to filter the Assistant table listing.', 'media-library-assistant' ),
631
+ 'std' => array (
632
+ 'tax_support' => array (
633
+ 'attachment_category' => 'checked',
634
+ 'attachment_tag' => 'checked',
635
+ ),
636
+ 'tax_quick_edit' => array (
637
+ 'attachment_category' => 'checked',
638
+ 'attachment_tag' => 'checked',
639
+ ),
640
+ 'tax_term_search' => array (
641
+ 'attachment_category' => 'checked',
642
+ 'attachment_tag' => 'checked',
643
+ ),
644
+ 'tax_flat_checklist' => array(),
645
+ 'tax_checked_on_top' => NULL, // default "true", handled in mla_initialize_tax_checked_on_top
646
+ 'tax_filter' => 'attachment_category'
647
+ ),
648
+ 'type' => 'custom',
649
+ 'render' => 'mla_taxonomy_option_handler',
650
+ 'update' => 'mla_taxonomy_option_handler',
651
+ 'delete' => 'mla_taxonomy_option_handler',
652
+ 'reset' => 'mla_taxonomy_option_handler'),
653
+
654
+ 'media_assistant_header' =>
655
+ array('tab' => 'general',
656
+ 'name' => __( 'Media/Assistant Screen Options', 'media-library-assistant' ),
657
+ 'type' => 'header'),
658
+
659
+ 'admin_sidebar_subheader' =>
660
+ array('tab' => 'general',
661
+ 'name' => __( 'Admin Menu Options', 'media-library-assistant' ),
662
+ 'type' => 'subheader'),
663
+
664
+ self::MLA_SCREEN_PAGE_TITLE =>
665
+ array('tab' => 'general',
666
+ 'name' => __( 'Page Title', 'media-library-assistant' ),
667
+ 'type' => 'text',
668
+ 'std' => __( 'Media Library Assistant', 'media-library-assistant' ),
669
+ 'size' => 40,
670
+ 'help' => __( 'Enter the title for the Media/Assistant submenu page', 'media-library-assistant' )),
671
+
672
+ self::MLA_SCREEN_MENU_TITLE =>
673
+ array('tab' => 'general',
674
+ 'name' => __( 'Menu Title', 'media-library-assistant' ),
675
+ 'type' => 'text',
676
+ 'std' => __( 'Assistant', 'media-library-assistant' ),
677
+ 'size' => 20,
678
+ 'help' => __( 'Enter the title for the Media/Assistant submenu entry', 'media-library-assistant' )),
679
+
680
+ self::MLA_SCREEN_ORDER =>
681
+ array('tab' => 'general',
682
+ 'name' => __( 'Submenu Order', 'media-library-assistant' ),
683
+ 'type' => 'text',
684
+ 'std' => '0',
685
+ 'size' => 2,
686
+ 'help' => __( 'Enter the position of the Media/Assistant submenu entry.<br>&nbsp;&nbsp;0 = natural order (at bottom),&nbsp;&nbsp;&nbsp;&nbsp;1 - 4 = at top<br>&nbsp;&nbsp;6-9 = after "Library",&nbsp;&nbsp;&nbsp;&nbsp;11-16 = after "Add New"', 'media-library-assistant' )),
687
+
688
+ self::MLA_SCREEN_DISPLAY_LIBRARY =>
689
+ array('tab' => 'general',
690
+ 'name' => __( 'Display Media/Library', 'media-library-assistant' ),
691
+ 'type' => 'checkbox',
692
+ 'std' => 'checked',
693
+ 'help' => __( 'Check/uncheck this option to display/remove the WordPress Media/Library submenu entry.', 'media-library-assistant' )),
694
+
695
+ 'table_defaults_subheader' =>
696
+ array('tab' => 'general',
697
+ 'name' => __( 'Table Defaults', 'media-library-assistant' ),
698
+ 'type' => 'subheader'),
699
+
700
+ self::MLA_DEFAULT_ORDERBY =>
701
+ array('tab' => 'general',
702
+ 'name' => __( 'Order By', 'media-library-assistant' ),
703
+ 'type' => 'select',
704
+ 'std' => 'ID',
705
+ 'options' => array('none', 'ID'),
706
+ 'texts' => array( __( 'None', 'media-library-assistant' ), __( 'ID/Parent', 'media-library-assistant' ) ),
707
+ 'help' => __( 'Select the column for the sort order of the Assistant table listing.', 'media-library-assistant' )),
708
+
709
+ self::MLA_DEFAULT_ORDER =>
710
+ array('tab' => 'general',
711
+ 'name' => __( 'Order', 'media-library-assistant' ),
712
+ 'type' => 'radio',
713
+ 'std' => 'DESC',
714
+ 'options' => array('ASC', 'DESC'),
715
+ 'texts' => array( __( 'Ascending', 'media-library-assistant' ), __( 'Descending', 'media-library-assistant' ) ),
716
+ 'help' => __( 'Choose the sort order.', 'media-library-assistant' )),
717
+
718
+ self::MLA_TABLE_VIEWS_WIDTH =>
719
+ array('tab' => 'general',
720
+ 'name' => __( 'Views Width', 'media-library-assistant' ),
721
+ 'type' => 'text',
722
+ 'std' => '',
723
+ 'size' => 10,
724
+ 'help' => __( 'Enter the width for the views list, in pixels (px) or percent (%)', 'media-library-assistant' )),
725
+
726
+ self::MLA_TABLE_ICON_SIZE =>
727
+ array('tab' => 'general',
728
+ 'name' => __( 'Icon Size', 'media-library-assistant' ),
729
+ 'type' => 'text',
730
+ 'std' => '',
731
+ 'size' => 5,
732
+ 'help' => __( 'Enter the size of the thumbnail/icon images, in pixels', 'media-library-assistant' )),
733
+
734
+ self::MLA_BULK_CHUNK_SIZE =>
735
+ array('tab' => 'general',
736
+ 'name' => __( 'Bulk Chunk Size', 'media-library-assistant' ),
737
+ 'type' => 'text',
738
+ 'std' => '25',
739
+ 'size' => 5,
740
+ 'help' => __( 'Enter the size of the Bulk Edit and Map All processing chunks', 'media-library-assistant' )),
741
+
742
+ 'taxonomy_filter_subheader' =>
743
+ array('tab' => 'general',
744
+ 'name' => __( 'Taxonomy Filter parameters', 'media-library-assistant' ),
745
+ 'type' => 'subheader'),
746
+
747
+ self::MLA_TAXONOMY_FILTER_DEPTH =>
748
+ array('tab' => 'general',
749
+ 'name' => __( 'Maximum Depth', 'media-library-assistant' ),
750
+ 'type' => 'text',
751
+ 'std' => '3',
752
+ 'size' => 2,
753
+ 'help' => __( 'Enter the number of levels displayed for hierarchial taxonomies; enter zero for no limit.', 'media-library-assistant' )),
754
+
755
+ self::MLA_TAXONOMY_FILTER_INCLUDE_CHILDREN =>
756
+ array('tab' => 'general',
757
+ 'name' => __( 'Include Children', 'media-library-assistant' ),
758
+ 'type' => 'checkbox',
759
+ 'std' => 'checked',
760
+ 'help' => __( 'Check/uncheck this option to include/exclude children for hierarchical taxonomies.', 'media-library-assistant' )),
761
+
762
+ 'search_media_subheader' =>
763
+ array('tab' => 'general',
764
+ 'name' => __( 'Search Media Defaults', 'media-library-assistant' ),
765
+ 'type' => 'subheader'),
766
+
767
+ self::MLA_SEARCH_MEDIA_FILTER_SHOW_CONTROLS =>
768
+ array('tab' => 'general',
769
+ 'name' => __( 'Display Search Controls', 'media-library-assistant' ),
770
+ 'type' => 'checkbox',
771
+ 'std' => 'checked',
772
+ 'help' => __( 'Check/uncheck this option to display/hide the and/or connector and search fields controls.', 'media-library-assistant' )),
773
+
774
+ self::MLA_SEARCH_MEDIA_FILTER_DEFAULTS =>
775
+ array('tab' => 'general',
776
+ 'help' => __( 'Use these controls to set defaults for the and/or connector and search fields controls.<br>These defaults will be used for the Search Media boxes on both the Media/Assistant submenu<br>and the Media Manager Modal Window.', 'media-library-assistant' ),
777
+ 'std' => array (
778
+ 'search_connector' => 'AND',
779
+ 'search_fields' => array ( 'title', 'content' ),
780
+ ),
781
+ 'type' => 'custom',
782
+ 'render' => 'mla_search_option_handler',
783
+ 'update' => 'mla_search_option_handler',
784
+ 'delete' => 'mla_search_option_handler',
785
+ 'reset' => 'mla_search_option_handler'),
786
+
787
+ 'edit_media_header' =>
788
+ array('tab' => 'general',
789
+ 'name' => __( 'Media/Edit Media Enhancements', 'media-library-assistant' ),
790
+ 'type' => 'header'),
791
+
792
+ self::MLA_EDIT_MEDIA_SEARCH_TAXONOMY =>
793
+ array('tab' => 'general',
794
+ 'name' => __( 'Enable &quot;enhanced checklist&quot; taxonomies', 'media-library-assistant' ),
795
+ 'type' => 'checkbox',
796
+ 'std' => 'checked',
797
+ 'help' => __( 'Check this option to enable the "? Search" feature for hierarchical taxonomies, e.g., Att. Categories.<br>&nbsp;&nbsp;This option also enables the "checklist-style" support for flat taxonomies, e.g., Att. Tags.', 'media-library-assistant' )),
798
+
799
+ self::MLA_EDIT_MEDIA_META_BOXES =>
800
+ array('tab' => 'general',
801
+ 'name' => __( 'Enable Edit Media additional meta boxes', 'media-library-assistant' ),
802
+ 'type' => 'checkbox',
803
+ 'std' => 'checked',
804
+ 'help' => __( 'Check this option to add "Parent Info", "Menu Order", "Attachment Metadata" and four "where-used" meta boxes to the Edit Media screen.', 'media-library-assistant' ) . '<br>&nbsp;&nbsp;' .
805
+ __( 'You can also use Filters to customize the meta boxes.', 'media-library-assistant' ) .
806
+ sprintf( ' %1$s <a href="%2$s">%3$s</a>.', __( 'For complete documentation', 'media-library-assistant' ), admin_url( 'options-general.php?page=' . MLACore::MLA_SETTINGS_SLUG . '-documentation&amp;mla_tab=documentation#mla_edit_meta_boxes' ), __( 'click here', 'media-library-assistant' ) ) ),
807
+
808
+ 'media_add_new_header' =>
809
+ array('tab' => 'general',
810
+ 'name' => __( 'Media/Add New Enhancements', 'media-library-assistant' ),
811
+ 'type' => 'header'),
812
+
813
+ self::MLA_ADD_NEW_BULK_EDIT =>
814
+ array('tab' => 'general',
815
+ 'name' => __( 'Enable &quot;bulk edit&quot; area', 'media-library-assistant' ),
816
+ 'type' => 'checkbox',
817
+ 'std' => 'checked',
818
+ 'help' => __( 'Check this option to enable the "Bulk Edit area" feature on the Media/Add New screen.', 'media-library-assistant' )),
819
+
820
+ self::MLA_ADD_NEW_BULK_EDIT_ON_TOP =>
821
+ array('tab' => 'general',
822
+ 'name' => __( '&quot;bulk edit&quot; area on top', 'media-library-assistant' ),
823
+ 'type' => 'checkbox',
824
+ 'std' => '',
825
+ 'help' => __( 'Check this option to move the "Bulk Edit area" to the top of the Media/Add New screen.', 'media-library-assistant' )),
826
+
827
+ self::MLA_ADD_NEW_BULK_EDIT_AUTO_OPEN =>
828
+ array('tab' => 'general',
829
+ 'name' => __( '&quot;bulk edit&quot; area initially open', 'media-library-assistant' ),
830
+ 'type' => 'checkbox',
831
+ 'std' => '',
832
+ 'help' => __( 'Check this option to automatically open the "Bulk Edit area" when the Media/Add New screen is displayed.', 'media-library-assistant' )),
833
+
834
+ 'media_modal_header' =>
835
+ array('tab' => 'general',
836
+ 'name' => __( 'Media Manager/Media Grid Enhancements', 'media-library-assistant' ),
837
+ 'type' => 'header'),
838
+
839
+ self::MLA_MEDIA_GRID_TOOLBAR =>
840
+ array('tab' => 'general',
841
+ 'name' => __( 'Enable Media Grid Enhancements', 'media-library-assistant' ),
842
+ 'type' => 'checkbox',
843
+ 'std' => 'checked',
844
+ 'help' => __( 'Check/uncheck this option to enable/disable Media Library Grid View Enhancements.', 'media-library-assistant' )),
845
+
846
+ self::MLA_MEDIA_MODAL_TOOLBAR =>
847
+ array('tab' => 'general',
848
+ 'name' => __( 'Enable Media Manager Enhancements', 'media-library-assistant' ),
849
+ 'type' => 'checkbox',
850
+ 'std' => 'checked',
851
+ 'help' => __( 'Check/uncheck this option to enable/disable Media Manager Modal Window Enhancements.', 'media-library-assistant' )),
852
+
853
+ self::MLA_MEDIA_MODAL_MIMETYPES =>
854
+ array('tab' => 'general',
855
+ 'name' => __( 'Media Manager Enhanced MIME Type filter', 'media-library-assistant' ),
856
+ 'type' => 'checkbox',
857
+ 'std' => 'checked',
858
+ 'help' => __( 'Check this option to filter by more MIME Types, e.g., text, applications.', 'media-library-assistant' )),
859
+
860
+ self::MLA_MEDIA_MODAL_MONTHS =>
861
+ array('tab' => 'general',
862
+ 'name' => __( 'Media Manager Month and Year filter', 'media-library-assistant' ),
863
+ 'type' => 'checkbox',
864
+ 'std' => 'checked',
865
+ 'help' => __( 'Check this option to filter by month and year uploaded.', 'media-library-assistant' )),
866
+
867
+ self::MLA_MEDIA_MODAL_TERMS =>
868
+ array('tab' => 'general',
869
+ 'name' => __( 'Media Manager Category/Tag filter', 'media-library-assistant' ),
870
+ 'type' => 'checkbox',
871
+ 'std' => 'checked',
872
+ 'help' => __( 'Check this option to filter by taxonomy terms.', 'media-library-assistant' )),
873
+
874
+ self::MLA_MEDIA_MODAL_TERMS_SEARCH =>
875
+ array('tab' => 'general',
876
+ 'name' => __( 'Media Manager Terms Search popup', 'media-library-assistant' ),
877
+ 'type' => 'checkbox',
878
+ 'std' => 'checked',
879
+ 'help' => __( 'Check this option to enable the "Terms Search" popup window.', 'media-library-assistant' )),
880
+
881
+ self::MLA_MEDIA_MODAL_SEARCHBOX =>
882
+ array('tab' => 'general',
883
+ 'name' => __( 'Media Manager Enhanced Search Media box', 'media-library-assistant' ),
884
+ 'type' => 'checkbox',
885
+ 'std' => 'checked',
886
+ 'help' => __( 'Check this option to enable search box enhancements.', 'media-library-assistant' )),
887
+
888
+ self::MLA_MEDIA_MODAL_SEARCHBOX_CONTROLS =>
889
+ array('tab' => 'general',
890
+ 'name' => __( 'Media Manager Enhanced Search Media Controls', 'media-library-assistant' ),
891
+ 'type' => 'checkbox',
892
+ 'std' => 'checked',
893
+ 'help' => __( 'Check/uncheck this option to display/hide the and/or connector and search fields controls.', 'media-library-assistant' )),
894
+
895
+ self::MLA_MEDIA_MODAL_DETAILS_CATEGORY_METABOX =>
896
+ array('tab' => 'general',
897
+ 'name' => __( 'Media Manager Checklist meta boxes', 'media-library-assistant' ),
898
+ 'type' => 'checkbox',
899
+ 'std' => 'checked',
900
+ 'help' => __( 'Check this option to enable MLA-enhanced meta boxes in the "ATTACHMENT DETAILS" pane.<br>&nbsp;&nbsp;This option is for any taxonomy that uses a <strong>"checklist-style"</strong> meta box.', 'media-library-assistant' )),
901
+
902
+ self::MLA_MEDIA_MODAL_DETAILS_TAG_METABOX =>
903
+ array('tab' => 'general',
904
+ 'name' => __( 'Media Manager Flat meta boxes', 'media-library-assistant' ),
905
+ 'type' => 'checkbox',
906
+ 'std' => 'checked',
907
+ 'help' => __( 'Check this option to enable MLA-enhanced meta boxes in the "ATTACHMENT DETAILS" pane.<br>&nbsp;&nbsp;This option is for <strong>flat taxonomies</strong>, e.g., "Tags" or "Att. Tags", that do not use the "checklist-style" meta box.', 'media-library-assistant' )),
908
+
909
+ self::MLA_MEDIA_MODAL_DETAILS_AUTOFILL =>
910
+ array('tab' => 'general',
911
+ 'name' => __( 'Media Manager auto-fill meta boxes', 'media-library-assistant' ),
912
+ 'type' => 'checkbox',
913
+ 'std' => '',
914
+ 'help' => __( 'Check this option to automatically fill MLA-enhanced meta boxes in the "ATTACHMENT DETAILS" pane<br>&nbsp;&nbsp;when the item is selected.', 'media-library-assistant' )),
915
+
916
+ self::MLA_MEDIA_MODAL_ORDERBY =>
917
+ array('tab' => '',
918
+ 'name' => __( 'Media Manager Order By', 'media-library-assistant' ),
919
+ 'type' => 'select',
920
+ 'std' => 'default',
921
+ 'options' => array('default', 'none', 'title_name'),
922
+ 'texts' => array('&mdash; ' . __( 'Media Manager Default', 'media-library-assistant' ) . ' &mdash;', __( 'None', 'media-library-assistant' ), __( 'Title/Name', 'media-library-assistant' )),
923
+ 'help' => __( 'If you want to override the Media Manager default,<br>&nbsp;&nbsp;select a column for the sort order of the Media Library listing.', 'media-library-assistant' )),
924
+
925
+ self::MLA_MEDIA_MODAL_ORDER =>
926
+ array('tab' => '',
927
+ 'name' => __( 'Media Manager Order', 'media-library-assistant' ),
928
+ 'type' => 'radio',
929
+ 'std' => 'default',
930
+ 'options' => array('default', 'ASC', 'DESC'),
931
+ 'texts' => array( '&mdash; ' . __( 'Media Manager Default', 'media-library-assistant' ) . ' &mdash;', 'Ascending', 'Descending' ),
932
+ 'help' => __( 'Choose the sort order.', 'media-library-assistant' )),
933
+
934
+ 'attachment_display_settings_subheader' =>
935
+ array('tab' => 'general',
936
+ 'name' => __( 'Attachment Display Settings', 'media-library-assistant' ),
937
+ 'type' => 'subheader'),
938
+
939
+ 'image_default_align' =>
940
+ array('tab' => 'general',
941
+ 'name' => __( 'Alignment', 'media-library-assistant' ),
942
+ /* translators: 1: option name, e.g., Alignment, Link To or Size */
943
+ 'help' => sprintf( __( 'Select a value for the default %1$s option in the Attachment Display Settings.', 'media-library-assistant' ), __( 'Alignment', 'media-library-assistant' ) ),
944
+ 'std' => 'default',
945
+ 'options' => array('default', 'left', 'center', 'right', 'none'),
946
+ 'texts' => array('&mdash; ' . __( 'Media Manager Default', 'media-library-assistant' ) . ' &mdash;', __( 'Left', 'media-library-assistant' ), __( 'Center', 'media-library-assistant' ), __( 'Right', 'media-library-assistant' ), __( 'None', 'media-library-assistant' )),
947
+ 'type' => 'custom',
948
+ 'render' => 'mla_attachment_display_settings_option_handler',
949
+ 'update' => 'mla_attachment_display_settings_option_handler',
950
+ 'delete' => 'mla_attachment_display_settings_option_handler',
951
+ 'reset' => 'mla_attachment_display_settings_option_handler'),
952
+
953
+ 'image_default_link_type' =>
954
+ array('tab' => 'general',
955
+ 'name' => __( 'Link To', 'media-library-assistant' ),
956
+ /* translators: 1: option name, e.g., Alignment, Link To or Size */
957
+ 'help' => sprintf( __( 'Select a value for the default %1$s option in the Attachment Display Settings.', 'media-library-assistant' ), __( 'Link To', 'media-library-assistant' ) ),
958
+ 'std' => 'default',
959
+ 'options' => array('default', 'file', 'post', 'custom', 'none'),
960
+ 'texts' => array('&mdash; ' . __( 'Media Manager Default', 'media-library-assistant' ) . ' &mdash;', __( 'Media File', 'media-library-assistant' ), __( 'Attachment Page', 'media-library-assistant' ), __( 'Custom URL', 'media-library-assistant' ), __( 'None', 'media-library-assistant' )),
961
+ 'type' => 'custom',
962
+ 'render' => 'mla_attachment_display_settings_option_handler',
963
+ 'update' => 'mla_attachment_display_settings_option_handler',
964
+ 'delete' => 'mla_attachment_display_settings_option_handler',
965
+ 'reset' => 'mla_attachment_display_settings_option_handler'),
966
+
967
+ 'image_default_size' =>
968
+ array('tab' => 'general',
969
+ 'name' => __( 'Size', 'media-library-assistant' ),
970
+ /* translators: 1: option name, e.g., Alignment, Link To or Size */
971
+ 'help' => sprintf( __( 'Select a value for the default %1$s option in the Attachment Display Settings.', 'media-library-assistant' ), __( 'Size', 'media-library-assistant' ) ),
972
+ 'std' => 'default',
973
+ 'options' => array('default', 'thumbnail', 'medium', 'large', 'full'),
974
+ 'texts' => array('&mdash; ' . __( 'Media Manager Default', 'media-library-assistant' ) . ' &mdash;', __( 'Thumbnail', 'media-library-assistant' ), __( 'Medium', 'media-library-assistant' ), __( 'Large', 'media-library-assistant' ), __( 'Full Size', 'media-library-assistant' )),
975
+ 'type' => 'custom',
976
+ 'render' => 'mla_attachment_display_settings_option_handler',
977
+ 'update' => 'mla_attachment_display_settings_option_handler',
978
+ 'delete' => 'mla_attachment_display_settings_option_handler',
979
+ 'reset' => 'mla_attachment_display_settings_option_handler'),
980
+
981
+ 'template_header' =>
982
+ array('tab' => 'mla_gallery',
983
+ 'name' => __( 'Default [mla_gallery] Templates and Settings', 'media-library-assistant' ),
984
+ 'type' => 'header'),
985
+
986
+ 'default_tag_cloud_style' =>
987
+ array('tab' => '',
988
+ 'name' => __( 'Style Template', 'media-library-assistant' ),
989
+ 'type' => 'select',
990
+ 'std' => 'tag-cloud',
991
+ 'options' => array(),
992
+ 'texts' => array(),
993
+ /* translators: 1: template type 2: shortcode */
994
+ 'help' => sprintf( __( 'Select the default %1$s for your %2$s shortcodes.', 'media-library-assistant' ), __( 'Style Template', 'media-library-assistant' ), '[mla_tag_cloud]' ) ),
995
+
996
+ 'default_tag_cloud_markup' =>
997
+ array('tab' => '',
998
+ 'name' => __( 'Markup Template', 'media-library-assistant' ),
999
+ 'type' => 'select',
1000
+ 'std' => 'tag-cloud',
1001
+ 'options' => array(),
1002
+ 'texts' => array(),
1003
+ /* translators: 1: template type 2: shortcode */
1004
+ 'help' => sprintf( __( 'Select the default %1$s for your %2$s shortcodes.', 'media-library-assistant' ), __( 'markup template', 'media-library-assistant' ), '[mla_tag_cloud]' ) ),
1005
+
1006
+ 'mla_tag_cloud_columns' =>
1007
+ array('tab' => '',
1008
+ 'name' => __( 'Default columns', 'media-library-assistant' ),
1009
+ 'type' => 'text',
1010
+ 'std' => '3',
1011
+ 'size' => 3,
1012
+ 'help' => __( 'Enter the number of [mla_tag_cloud] columns; must be a positive integer.', 'media-library-assistant' )),
1013
+
1014
+ 'mla_tag_cloud_margin' =>
1015
+ array('tab' => '',
1016
+ 'name' => __( 'Default mla_margin', 'media-library-assistant' ),
1017
+ 'type' => 'text',
1018
+ 'std' => '1.5%',
1019
+ 'size' => 10,
1020
+ 'help' => __( 'Enter the CSS "margin" property value, in length (px, em, pt, etc.), percent (%), "auto" or "inherit".<br>&nbsp;&nbsp;Enter "none" to remove the property entirely.', 'media-library-assistant' )),
1021
+
1022
+ 'mla_tag_cloud_itemwidth' =>
1023
+ array('tab' => '',
1024
+ 'name' => __( 'Default mla_itemwidth', 'media-library-assistant' ),
1025
+ 'type' => 'text',
1026
+ 'std' => 'calculate',
1027
+ 'size' => 10,
1028
+ 'help' => __( 'Enter the CSS "width" property value, in length (px, em, pt, etc.), percent (%), "auto" or "inherit".<br>&nbsp;&nbsp;Enter "calculate" (the default) to calculate the value taking the "margin" value into account.<br>&nbsp;&nbsp;Enter "exact" to calculate the value without considering the "margin" value.<br>&nbsp;&nbsp;Enter "none" to remove the property entirely.', 'media-library-assistant' )),
1029
+
1030
+ 'default_style' =>
1031
+ array('tab' => 'mla_gallery',
1032
+ 'name' => __( 'Style Template', 'media-library-assistant' ),
1033
+ 'type' => 'select',
1034
+ 'std' => 'default',
1035
+ 'options' => array(),
1036
+ 'texts' => array(),
1037
+ /* translators: 1: template type 2: shortcode */
1038
+ 'help' => sprintf( __( 'Select the default %1$s for your %2$s shortcodes.', 'media-library-assistant' ), __( 'Style Template', 'media-library-assistant' ), '[mla_gallery]' ) ),
1039
+
1040
+ 'default_markup' =>
1041
+ array('tab' => 'mla_gallery',
1042
+ 'name' => __( 'Markup Template', 'media-library-assistant' ),
1043
+ 'type' => 'select',
1044
+ 'std' => 'default',
1045
+ 'options' => array(),
1046
+ 'texts' => array(),
1047
+ /* translators: 1: template type 2: shortcode */
1048
+ 'help' => sprintf( __( 'Select the default %1$s for your %2$s shortcodes.', 'media-library-assistant' ), __( 'markup template', 'media-library-assistant' ), '[mla_gallery]' ) ),
1049
+
1050
+ 'mla_gallery_columns' =>
1051
+ array('tab' => 'mla_gallery',
1052
+ 'name' => __( 'Default columns', 'media-library-assistant' ),
1053
+ 'type' => 'text',
1054
+ 'std' => '3',
1055
+ 'size' => 3,
1056
+ 'help' => __( 'Enter the number of [mla_gallery] columns; must be a positive integer.', 'media-library-assistant' )),
1057
+
1058
+ 'mla_gallery_margin' =>
1059
+ array('tab' => 'mla_gallery',
1060
+ 'name' => __( 'Default mla_margin', 'media-library-assistant' ),
1061
+ 'type' => 'text',
1062
+ 'std' => '1.5%',
1063
+ 'size' => 10,
1064
+ 'help' => __( 'Enter the CSS "margin" property value, in length (px, em, pt, etc.), percent (%), "auto" or "inherit".<br>&nbsp;&nbsp;Enter "none" to remove the property entirely.', 'media-library-assistant' )),
1065
+
1066
+ 'mla_gallery_itemwidth' =>
1067
+ array('tab' => 'mla_gallery',
1068
+ 'name' => __( 'Default mla_itemwidth', 'media-library-assistant' ),
1069
+ 'type' => 'text',
1070
+ 'std' => 'calculate',
1071
+ 'size' => 10,
1072
+ 'help' => __( 'Enter the CSS "width" property value, in length (px, em, pt, etc.), percent (%), "auto" or "inherit".<br>&nbsp;&nbsp;Enter "calculate" (the default) to calculate the value taking the "margin" value into account.<br>&nbsp;&nbsp;Enter "exact" to calculate the value without considering the "margin" value.<br>&nbsp;&nbsp;Enter "none" to remove the property entirely.', 'media-library-assistant' )),
1073
+
1074
+ 'mal_viewer_header' =>
1075
+ array('tab' => 'mla_gallery',
1076
+ 'name' => __( 'Thumbnail Substitution Support, mla_viewer', 'media-library-assistant' ),
1077
+ 'type' => 'subheader'),
1078
+
1079
+ 'enable_mla_viewer' =>
1080
+ array('tab' => 'mla_gallery',
1081
+ 'name' => __( 'Enable thumbnail substitution', 'media-library-assistant' ),
1082
+ 'type' => 'checkbox',
1083
+ 'std' => 'checked',
1084
+ 'help' => __( 'Check this option to allow the "mla_viewer" to generate thumbnail images for PDF documents. Thumbnails are generated dynamically, each time the item appears in an [mla_gallery] display.<br>&nbsp;&nbsp;<strong>IMPORTANT: both Ghostscript and Imagick/ImageMagick must be installed for this feature.</strong>', 'media-library-assistant' )),
1085
+
1086
+ 'enable_featured_image' =>
1087
+ array('tab' => 'mla_gallery',
1088
+ 'name' => __( 'Enable Featured Images', 'media-library-assistant' ),
1089
+ 'type' => 'checkbox',
1090
+ 'std' => 'checked',
1091
+ 'help' => __( 'Check this option to extend Featured Image support to all Media Library items. The Featured Image can be used as a thumbnail image for the item in an [mla_gallery] display.', 'media-library-assistant' )),
1092
+
1093
+ 'enable_featured_image_generation' =>
1094
+ array('tab' => 'mla_gallery',
1095
+ 'name' => __( 'Enable Featured Image Generation', 'media-library-assistant' ),
1096
+ 'type' => 'checkbox',
1097
+ 'std' => 'checked',
1098
+ 'help' => __( 'Check this option to enable the "Thumbnail" generation action in the Media/Assistant submenu Bulk Actions dropdown.', 'media-library-assistant' )),
1099
+
1100
+ 'enable_ghostscript_check' =>
1101
+ array('tab' => 'mla_gallery',
1102
+ 'name' => __( 'Enable explicit Ghostscript check', 'media-library-assistant' ),
1103
+ 'type' => 'checkbox',
1104
+ 'std' => 'checked',
1105
+ 'help' => __( 'Check this option to enable the explicit check for Ghostscript support required for thumbnail generation. If your Ghostscript software is in a non-standard location, unchecking this option bypasses the check. Bad things can happen if Ghostscript is missing but Imagick/ImageMagick is present, so leave this option checked unless you know it is safe to turn it off.', 'media-library-assistant' )),
1106
+
1107
+ 'ghostscript_path' =>
1108
+ array('tab' => 'mla_gallery',
1109
+ 'name' => __( 'Ghostscript path', 'media-library-assistant' ),
1110
+ 'type' => 'text',
1111
+ 'std' => '',
1112
+ 'size' => 20,
1113
+ 'help' => __( 'If your &ldquo;gs&rdquo; executable is in a non-standard location, enter the full path and filename here, e.g., &ldquo;/usr/bin/gs&rdquo;. It will override the search for Ghostscript in other places.', 'media-library-assistant' )),
1114
+
1115
+ /*
1116
+ * Managed by mla_get_style_templates and mla_put_style_templates
1117
+ */
1118
+ 'style_templates' =>
1119
+ array('tab' => '',
1120
+ 'type' => 'hidden',
1121
+ 'std' => array()),
1122
+
1123
+ /*
1124
+ * Managed by mla_get_markup_templates and mla_put_markup_templates
1125
+ */
1126
+ 'markup_templates' =>
1127
+ array('tab' => '',
1128
+ 'type' => 'hidden',
1129
+ 'std' => array()),
1130
+
1131
+ 'enable_custom_field_mapping' =>
1132
+ array('tab' => 'custom_field',
1133
+ 'name' => __( 'Enable custom field mapping when adding new media', 'media-library-assistant' ),
1134
+ 'type' => 'checkbox',
1135
+ 'std' => '',
1136
+ 'help' => __( 'Check this option to enable mapping when uploading new media (attachments).<br>&nbsp;&nbsp;Click Save Changes at the bottom of the screen if you change this option.<br>&nbsp;&nbsp;Does NOT affect the operation of the "Map" buttons on the bulk edit, single edit and settings screens.', 'media-library-assistant' )),
1137
+
1138
+ 'enable_custom_field_update' =>
1139
+ array('tab' => 'custom_field',
1140
+ 'name' => __( 'Enable custom field mapping when updating media metadata', 'media-library-assistant' ),
1141
+ 'type' => 'checkbox',
1142
+ 'std' => '',
1143
+ 'help' => __( 'Check this option to enable mapping when media (attachments) metadata is regenerated,<br>&nbsp;&nbsp;e.g., when the Media/Edit Media "Edit Image" functions are used.', 'media-library-assistant' )),
1144
+
1145
+ 'custom_field_mapping' =>
1146
+ array('tab' => '',
1147
+ 'help' => __( 'Update the custom field mapping values above, then click Save Changes to make the updates permanent.<br>You can also make temporary updates and click a Map All Attachments button to apply the rule(s) to all attachments without saving any rule changes.', 'media-library-assistant' ),
1148
+ 'std' => array(),
1149
+ 'type' => 'custom',
1150
+ 'render' => 'mla_custom_field_option_handler',
1151
+ 'update' => 'mla_custom_field_option_handler',
1152
+ 'delete' => 'mla_custom_field_option_handler',
1153
+ 'reset' => 'mla_custom_field_option_handler'),
1154
+
1155
+ 'enable_iptc_exif_mapping' =>
1156
+ array('tab' => 'iptc_exif',
1157
+ 'name' => __( 'Enable IPTC/EXIF Mapping when adding new media', 'media-library-assistant' ),
1158
+ 'type' => 'checkbox',
1159
+ 'std' => '',
1160
+ 'help' => __( 'Check this option to enable mapping when uploading new media (attachments).<br>&nbsp;&nbsp;Does NOT affect the operation of the "Map" buttons on the bulk edit, single edit and settings screens.', 'media-library-assistant' )),
1161
+
1162
+ 'enable_iptc_exif_update' =>
1163
+ array('tab' => 'iptc_exif',
1164
+ 'name' => __( 'Enable IPTC/EXIF Mapping when updating media metadata', 'media-library-assistant' ),
1165
+ 'type' => 'checkbox',
1166
+ 'std' => '',
1167
+ 'help' => __( 'Check this option to enable mapping when media (attachments) metadata is regenerated,<br>&nbsp;&nbsp;e.g., when the Media/Edit Media "Edit Image" functions are used.', 'media-library-assistant' )),
1168
+
1169
+ 'iptc_exif_standard_mapping' =>
1170
+ array('tab' => '',
1171
+ 'help' => __( 'Update the standard field mapping values above, then click <strong>Save Changes</strong> to make the updates permanent.<br>You can also make temporary updates and click <strong>Map All Attachments, Standard Fields Now</strong> to apply the updates to all attachments without saving the rule changes.', 'media-library-assistant' ),
1172
+ 'std' => NULL,
1173
+ 'type' => 'custom',
1174
+ 'render' => 'mla_iptc_exif_option_handler',
1175
+ 'update' => 'mla_iptc_exif_option_handler',
1176
+ 'delete' => 'mla_iptc_exif_option_handler',
1177
+ 'reset' => 'mla_iptc_exif_option_handler'),
1178
+
1179
+ 'iptc_exif_taxonomy_mapping' =>
1180
+ array('tab' => '',
1181
+ 'help' => __( 'Update the taxonomy term mapping values above, then click <strong>Save Changes</strong> or <strong>Map All Attachments, Taxonomy Terms Now</strong>.', 'media-library-assistant' ),
1182
+ 'std' => NULL,
1183
+ 'type' => 'custom',
1184
+ 'render' => 'mla_iptc_exif_option_handler',
1185
+ 'update' => 'mla_iptc_exif_option_handler',
1186
+ 'delete' => 'mla_iptc_exif_option_handler',
1187
+ 'reset' => 'mla_iptc_exif_option_handler'),
1188
+
1189
+ 'iptc_exif_custom_mapping' =>
1190
+ array('tab' => '',
1191
+ 'help' => __( '<strong>Update</strong> individual custom field mapping values above, or make several updates and click <strong>Save Changes</strong> below to apply them all at once.<br>You can also <strong>add a new rule</strong> for an existing field or <strong>add a new field</strong> and rule.<br>You can make temporary updates and click <strong>Map All Attachments, Custom Fields Now</strong> to apply the updates to all attachments without saving the rule changes.', 'media-library-assistant' ),
1192
+ 'std' => NULL,
1193
+ 'type' => 'custom',
1194
+ 'render' => 'mla_iptc_exif_option_handler',
1195
+ 'update' => 'mla_iptc_exif_option_handler',
1196
+ 'delete' => 'mla_iptc_exif_option_handler',
1197
+ 'reset' => 'mla_iptc_exif_option_handler'),
1198
+
1199
+ 'iptc_exif_mapping' =>
1200
+ array('tab' => '',
1201
+ 'help' => __( 'IPTC/EXIF Mapping help', 'media-library-assistant' ),
1202
+ 'std' => array (
1203
+ 'standard' => array (
1204
+ 'post_title' => array (
1205
+ 'name' => __( 'Title', 'media-library-assistant' ),
1206
+ 'iptc_value' => 'none',
1207
+ 'exif_value' => '',
1208
+ 'iptc_first' => true,
1209
+ 'keep_existing' => true
1210
+ ),
1211
+ 'post_name' => array (
1212
+ 'name' => __( 'Name/Slug', 'media-library-assistant' ),
1213
+ 'iptc_value' => 'none',
1214
+ 'exif_value' => '',
1215
+ 'iptc_first' => true,
1216
+ 'keep_existing' => true
1217
+ ),
1218
+ 'image_alt' => array (
1219
+ 'name' => __( 'ALT Text', 'media-library-assistant' ),
1220
+ 'iptc_value' => 'none',
1221
+ 'exif_value' => '',
1222
+ 'iptc_first' => true,
1223
+ 'keep_existing' => true
1224
+ ),
1225
+ 'post_excerpt' => array (
1226
+ 'name' => __( 'Caption', 'media-library-assistant' ),
1227
+ 'iptc_value' => 'none',
1228
+ 'exif_value' => '',
1229
+ 'iptc_first' => true,
1230
+ 'keep_existing' => true
1231
+ ),
1232
+ 'post_content' => array (
1233
+ 'name' => __( 'Description', 'media-library-assistant' ),
1234
+ 'iptc_value' => 'none',
1235
+ 'exif_value' => '',
1236
+ 'iptc_first' => true,
1237
+ 'keep_existing' => true
1238
+ ),
1239
+ ),
1240
+ 'taxonomy' => array (
1241
+ ),
1242
+ 'custom' => array (
1243
+ )
1244
+ ),
1245
+ 'type' => 'custom',
1246
+ 'render' => 'mla_iptc_exif_option_handler',
1247
+ 'update' => 'mla_iptc_exif_option_handler',
1248
+ 'delete' => 'mla_iptc_exif_option_handler',
1249
+ 'reset' => 'mla_iptc_exif_option_handler'),
1250
+
1251
+ self::MLA_ENABLE_POST_MIME_TYPES =>
1252
+ array('tab' => 'view',
1253
+ 'name' => __( 'Enable View and Post MIME Type Support', 'media-library-assistant' ),
1254
+ 'type' => 'checkbox',
1255
+ 'std' => 'checked',
1256
+ 'help' => __( 'Check/uncheck this option to enable/disable Post MIME Type Support, then click <strong>Save Changes</strong> to record the new setting.', 'media-library-assistant' ) ),
1257
+
1258
+ self::MLA_POST_MIME_TYPES =>
1259
+ array('tab' => '',
1260
+ 'type' => 'custom',
1261
+ 'render' => 'mla_post_mime_types_option_handler',
1262
+ 'update' => 'mla_post_mime_types_option_handler',
1263
+ 'delete' => 'mla_post_mime_types_option_handler',
1264
+ 'reset' => 'mla_post_mime_types_option_handler',
1265
+ 'help' => __( 'Post MIME Types help.', 'media-library-assistant' ),
1266
+ 'std' => array(
1267
+ 'all' => array(
1268
+ 'singular' => _x( 'All', 'table_view_singular', 'media-library-assistant' ),
1269
+ 'plural' => _x( 'All', 'table_view_plural', 'media-library-assistant' ),
1270
+ 'specification' => '',
1271
+ 'post_mime_type' => false,
1272
+ 'table_view' => true,
1273
+ 'menu_order' => 0,
1274
+ 'description' => _x( 'Built-in view', 'post_mime_types_description', 'media-library-assistant' )
1275
+ ),
1276
+ 'image' => array(
1277
+ 'singular' => _x( 'Image', 'table_view_singular', 'media-library-assistant' ),
1278
+ 'plural' => _x( 'Images', 'table_view_plural', 'media-library-assistant' ),
1279
+ 'specification' => '',
1280
+ 'post_mime_type' => true,
1281
+ 'table_view' => true,
1282
+ 'menu_order' => 0,
1283
+ 'description' => _x( 'All image subtypes', 'post_mime_types_description', 'media-library-assistant' )
1284
+ ),
1285
+ 'audio' => array(
1286
+ 'singular' => _x( 'Audio', 'table_view_singular', 'media-library-assistant' ),
1287
+ 'plural' => _x( 'Audio', 'table_view_plural', 'media-library-assistant' ),
1288
+ 'specification' => '',
1289
+ 'post_mime_type' => true,
1290
+ 'table_view' => true,
1291
+ 'menu_order' => 0,
1292
+ 'description' => _x( 'All audio subtypes', 'post_mime_types_description', 'media-library-assistant' )
1293
+ ),
1294
+ 'video' => array(
1295
+ 'singular' => _x( 'Video', 'table_view_singular', 'media-library-assistant' ),
1296
+ 'plural' => _x( 'Video', 'table_view_plural', 'media-library-assistant' ),
1297
+ 'specification' => '',
1298
+ 'post_mime_type' => true,
1299
+ 'table_view' => true,
1300
+ 'menu_order' => 0,
1301
+ 'description' => _x( 'All video subtypes', 'post_mime_types_description', 'media-library-assistant' )
1302
+ ),
1303
+ 'text' => array(
1304
+ 'singular' => _x( 'Text', 'table_view_singular', 'media-library-assistant' ),
1305
+ 'plural' => _x( 'Text', 'table_view_plural', 'media-library-assistant' ),
1306
+ 'specification' => '',
1307
+ 'post_mime_type' => true,
1308
+ 'table_view' => true,
1309
+ 'menu_order' => 0,
1310
+ 'description' => _x( 'All text subtypes', 'post_mime_types_description', 'media-library-assistant' )
1311
+ ),
1312
+ 'application' => array(
1313
+ 'singular' => _x( 'Application', 'table_view_singular', 'media-library-assistant' ),
1314
+ 'plural' => _x( 'Applications', 'table_view_plural', 'media-library-assistant' ),
1315
+ 'specification' => '',
1316
+ 'post_mime_type' => true,
1317
+ 'table_view' => true,
1318
+ 'menu_order' => 0,
1319
+ 'description' => _x( 'All application subtypes', 'post_mime_types_description', 'media-library-assistant' )
1320
+ ),
1321
+ 'detached' => array(
1322
+ 'singular' => _x( 'Unattached', 'table_view_singular', 'media-library-assistant' ),
1323
+ 'plural' => _x( 'Unattached', 'table_view_plural', 'media-library-assistant' ),
1324
+ 'specification' => '',
1325
+ 'post_mime_type' => false,
1326
+ 'table_view' => true,
1327
+ 'menu_order' => 0,
1328
+ 'description' => _x( 'Built-in view', 'post_mime_types_description', 'media-library-assistant' )
1329
+ ),
1330
+ 'attached' => array(
1331
+ 'singular' => _x( 'Attached', 'table_view_singular', 'media-library-assistant' ),
1332
+ 'plural' => _x( 'Attached', 'table_view_plural', 'media-library-assistant' ),
1333
+ 'specification' => '',
1334
+ 'post_mime_type' => false,
1335
+ 'table_view' => true,
1336
+ 'menu_order' => 0,
1337
+ 'description' => _x( 'Built-in view', 'post_mime_types_description', 'media-library-assistant' )
1338
+ ),
1339
+ 'trash' => array(
1340
+ 'singular' => _x( 'Trash', 'table_view_singular', 'media-library-assistant' ),
1341
+ 'plural' => _x( 'Trash', 'table_view_plural', 'media-library-assistant' ),
1342
+ 'specification' => '',
1343
+ 'post_mime_type' => false,
1344
+ 'table_view' => true,
1345
+ 'menu_order' => 0,
1346
+ 'description' => _x( 'Built-in view', 'post_mime_types_description', 'media-library-assistant' )
1347
+ )
1348
+ )),
1349
+
1350
+ self::MLA_ENABLE_UPLOAD_MIMES =>
1351
+ array('tab' => 'upload',
1352
+ 'name' => __( 'Enable Upload MIME Type Support', 'media-library-assistant' ),
1353
+ 'type' => 'checkbox',
1354
+ 'std' => 'checked',
1355
+ 'help' => __( 'Check/uncheck this option to enable/disable Upload MIME Type Support, then click <strong>Save Changes</strong> to record the new setting.', 'media-library-assistant' )),
1356
+
1357
+ self::MLA_UPLOAD_MIMES =>
1358
+ array('tab' => '',
1359
+ 'type' => 'custom',
1360
+ 'render' => 'mla_upload_mimes_option_handler',
1361
+ 'update' => 'mla_upload_mimes_option_handler',
1362
+ 'delete' => 'mla_upload_mimes_option_handler',
1363
+ 'reset' => 'mla_upload_mimes_option_handler',
1364
+ 'help' => __( 'Upload MIME Types help.', 'media-library-assistant' ),
1365
+ 'std' => false), // false to detect first-time load; will become an array
1366
+
1367
+ self::MLA_ENABLE_MLA_ICONS =>
1368
+ array('tab' => 'upload',
1369
+ 'name' => __( 'Enable MLA File Type Icons Support', 'media-library-assistant' ),
1370
+ 'type' => 'checkbox',
1371
+ 'std' => 'checked',
1372
+ 'help' => __( 'Check/uncheck this option to enable/disable MLA File Type Icons Support, then click <strong>Save Changes</strong> to record the new setting.', 'media-library-assistant' )),
1373
+
1374
+ self::MLA_DEBUG_DISPLAY_LIMIT =>
1375
+ array('tab' => 'debug',
1376
+ 'name' => __( 'Display Limit', 'media-library-assistant' ),
1377
+ 'type' => 'text',
1378
+ 'std' => '',
1379
+ 'size' => 5,
1380
+ 'help' => __( 'Enter the maximum number of debug log characters to display; enter zero or leave blank for no limit.', 'media-library-assistant' )),
1381
+
1382
+ self::MLA_DEBUG_FILE =>
1383
+ array('tab' => 'debug',
1384
+ 'name' => __( 'Debug File', 'media-library-assistant' ),
1385
+ 'type' => 'text',
1386
+ 'std' => '',
1387
+ 'size' => 60,
1388
+ 'help' => __( 'Enter the name of an alternate, MLA-specific debug log file; leave blank to use the PHP error_log.', 'media-library-assistant' )),
1389
+
1390
+ self::MLA_DEBUG_REPLACE_PHP_LOG =>
1391
+ array('tab' => 'debug',
1392
+ 'name' => __( 'Replace PHP error_log file', 'media-library-assistant' ),
1393
+ 'type' => 'checkbox',
1394
+ 'std' => '',
1395
+ 'help' => __( 'Check this option to replace the PHP error_log file with the MLA Debug File.<br>&nbsp;&nbsp;allows capture of PHP messages in the MLA Debug File.', 'media-library-assistant' )),
1396
+
1397
+ self::MLA_DEBUG_REPLACE_PHP_REPORTING =>
1398
+ array('tab' => 'debug',
1399
+ 'name' => __( 'PHP Reporting', 'media-library-assistant' ),
1400
+ 'type' => 'text',
1401
+ 'std' => '',
1402
+ 'size' => 10,
1403
+ 'help' => __( 'Enter a numeric error_reporting value, e.g., 0x7FFF or 32767; leave blank to use the existing PHP error_reporting value.', 'media-library-assistant' )),
1404
+
1405
+ self::MLA_DEBUG_REPLACE_LEVEL =>
1406
+ array('tab' => 'debug',
1407
+ 'name' => __( 'MLA Reporting', 'media-library-assistant' ),
1408
+ 'type' => 'text',
1409
+ 'std' => '',
1410
+ 'size' => 10,
1411
+ 'help' => __( 'Enter a numeric MLA_DEBUG_LEVEL value, e.g., 0x0003 or 3; leave blank to use the existing MLA_DEBUG_LEVEL value.', 'media-library-assistant' )),
1412
+
1413
+ /* Here are examples of the other option types
1414
+ 'textarea' =>
1415
+ array('tab' => '',
1416
+ 'name' => 'Text Area',
1417
+ 'type' => 'textarea',
1418
+ 'std' => 'default text area',
1419
+ 'cols' => 60,
1420
+ 'rows' => 4,
1421
+ 'help' => __( 'Enter the text area...'),
1422
+ */
1423
+ );
1424
+ }
1425
+
1426
+ /**
1427
+ * Initialize "tax_checked_on_top" => "checked" default for all supported taxonomies
1428
+ *
1429
+ * Called after all taxonomies are registered, e.g., in MLAObjects::_build_taxonomies.
1430
+ *
1431
+ * @sin20 2.02
1432
+ *
1433
+ * @return void
1434
+ */
1435
+ public static function mla_initialize_tax_checked_on_top() {
1436
+ if ( NULL === MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_checked_on_top'] ) {
1437
+ /*
1438
+ * WordPress default is 'checked_ontop' => true
1439
+ * Initialize tax_checked_on_top defaults to true for all supported taxonomies
1440
+ */
1441
+ $checked_on_top = array();
1442
+ $taxonomies = MLACore::mla_supported_taxonomies();
1443
+ foreach ( $taxonomies as $new_key ) {
1444
+ $checked_on_top[ $new_key ] = 'checked';
1445
+ }
1446
+
1447
+ MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_checked_on_top'] = $checked_on_top;
1448
+ }
1449
+ }
1450
+
1451
+ /**
1452
+ * Return the stored value or default value of a defined MLA option
1453
+ *
1454
+ * @since 2.20
1455
+ *
1456
+ * @param string Name of the desired option
1457
+ * @param boolean True to ignore current setting and return default values
1458
+ * @param boolean True to ignore default values and return only stored values
1459
+ * @param array Custom option definitions
1460
+ *
1461
+ *
1462
+ * @return mixed Value(s) for the option or false if the option is not a defined MLA option
1463
+ */
1464
+ public static function mla_get_option( $option, $get_default = false, $get_stored = false, &$option_table = NULL ) {
1465
+ if ( NULL == $option_table ) {
1466
+ if ( empty( self::$mla_option_definitions ) ) {
1467
+ MLACore::mla_localize_option_definitions_array();
1468
+ }
1469
+
1470
+ $option_table =& self::$mla_option_definitions;
1471
+ }
1472
+
1473
+ if ( ! array_key_exists( $option, $option_table ) ) {
1474
+ return false;
1475
+ }
1476
+
1477
+ if ( $get_default ) {
1478
+ if ( array_key_exists( 'std', $option_table[ $option ] ) ) {
1479
+ return $option_table[ $option ]['std'];
1480
+ }
1481
+
1482
+ return false;
1483
+ } // $get_default
1484
+
1485
+ if ( ! $get_stored && array_key_exists( 'std', $option_table[ $option ] ) ) {
1486
+ return get_option( MLA_OPTION_PREFIX . $option, $option_table[ $option ]['std'] );
1487
+ }
1488
+
1489
+ return get_option( MLA_OPTION_PREFIX . $option, false );
1490
+ }
1491
+
1492
+ /**
1493
+ * Add or update the stored value of a defined MLA option
1494
+ *
1495
+ * @since 2.20
1496
+ *
1497
+ * @param string Name of the desired option
1498
+ * @param mixed New value for the desired option
1499
+ * @param array Custom option definitions
1500
+ *
1501
+ * @return boolean True if the value was changed or false if the update failed
1502
+ */
1503
+ public static function mla_update_option( $option, $newvalue, &$option_table = NULL ) {
1504
+ if ( NULL == $option_table ) {
1505
+ if ( empty( self::$mla_option_definitions ) ) {
1506
+ MLACore::mla_localize_option_definitions_array();
1507
+ }
1508
+
1509
+ $option_table =& self::$mla_option_definitions;
1510
+ }
1511
+
1512
+ if ( array_key_exists( $option, $option_table ) ) {
1513
+ return update_option( MLA_OPTION_PREFIX . $option, $newvalue );
1514
+ }
1515
+
1516
+ return false;
1517
+ }
1518
+
1519
+ /**
1520
+ * Delete the stored value of a defined MLA option
1521
+ *
1522
+ * @since 2.20
1523
+ *
1524
+ * @param string Name of the desired option
1525
+ * @param array Custom option definitions
1526
+ *
1527
+ * @return boolean True if the option was deleted, otherwise false
1528
+ */
1529
+ public static function mla_delete_option( $option, &$option_table = NULL ) {
1530
+ if ( NULL == $option_table ) {
1531
+ if ( empty( self::$mla_option_definitions ) ) {
1532
+ MLACore::mla_localize_option_definitions_array();
1533
+ }
1534
+
1535
+ $option_table =& self::$mla_option_definitions;
1536
+ }
1537
+
1538
+ if ( array_key_exists( $option, $option_table ) ) {
1539
+ return delete_option( MLA_OPTION_PREFIX . $option );
1540
+ }
1541
+
1542
+ return false;
1543
+ }
1544
+
1545
+ /**
1546
+ * Determine MLA support for a taxonomy, handling the special case where the
1547
+ * settings are being updated or reset.
1548
+ *
1549
+ * @since 2.20
1550
+ *
1551
+ * @param string Taxonomy name, e.g., attachment_category
1552
+ * @param string Optional. 'support' (default), 'quick-edit' or 'filter'
1553
+ *
1554
+ * @return boolean|string
1555
+ * true if the taxonomy is supported in this way else false.
1556
+ * string if $tax_name is '' and $support_type is 'filter', returns the taxonomy to filter by.
1557
+ */
1558
+ public static function mla_taxonomy_support($tax_name, $support_type = 'support') {
1559
+ $tax_options = MLACore::mla_get_option( MLACore::MLA_TAXONOMY_SUPPORT );
1560
+
1561
+ switch ( $support_type ) {
1562
+ case 'support':
1563
+ if ( !empty( $_REQUEST['mla-general-options-save'] ) ) {
1564
+ return isset( $_REQUEST['tax_support'][ $tax_name ] );
1565
+ } elseif ( !empty( $_REQUEST['mla-general-options-reset'] ) ) {
1566
+ return array_key_exists( $tax_name, MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_support'] );
1567
+ }
1568
+
1569
+ $tax_support = isset( $tax_options['tax_support'] ) ? $tax_options['tax_support'] : MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_support'];
1570
+ return array_key_exists( $tax_name, $tax_support );
1571
+ case 'quick-edit':
1572
+ if ( !empty( $_REQUEST['mla-general-options-save'] ) ) {
1573
+ return isset( $_REQUEST['tax_quick_edit'][ $tax_name ] );
1574
+ } elseif ( !empty( $_REQUEST['mla-general-options-reset'] ) ) {
1575
+ return array_key_exists( $tax_name, MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_quick_edit'] );
1576
+ }
1577
+
1578
+ $tax_quick_edit = isset( $tax_options['tax_quick_edit'] ) ? $tax_options['tax_quick_edit'] : MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_quick_edit'];
1579
+ return array_key_exists( $tax_name, $tax_quick_edit );
1580
+ case 'term-search':
1581
+ if ( !empty( $_REQUEST['mla-general-options-save'] ) ) {
1582
+ return isset( $_REQUEST['tax_term_search'][ $tax_name ] );
1583
+ } elseif ( !empty( $_REQUEST['mla-general-options-reset'] ) ) {
1584
+ return array_key_exists( $tax_name, MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_term_search'] );
1585
+ }
1586
+
1587
+ $tax_term_search = isset( $tax_options['tax_term_search'] ) ? $tax_options['tax_term_search'] : MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_term_search'];
1588
+ return array_key_exists( $tax_name, $tax_term_search );
1589
+ case 'flat-checklist':
1590
+ if ( !empty( $_REQUEST['mla-general-options-save'] ) ) {
1591
+ return isset( $_REQUEST['tax_flat_checklist'][ $tax_name ] );
1592
+ } elseif ( !empty( $_REQUEST['mla-general-options-reset'] ) ) {
1593
+ return array_key_exists( $tax_name, MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_flat_checklist'] );
1594
+ }
1595
+
1596
+ $tax_flat_checklist = isset( $tax_options['tax_flat_checklist'] ) ? $tax_options['tax_flat_checklist'] : MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_flat_checklist'];
1597
+ return array_key_exists( $tax_name, $tax_flat_checklist );
1598
+ case 'checked-on-top':
1599
+ if ( !empty( $_REQUEST['mla-general-options-save'] ) ) {
1600
+ return isset( $_REQUEST['tax_checked_on_top'][ $tax_name ] );
1601
+ } elseif ( !empty( $_REQUEST['mla-general-options-reset'] ) ) {
1602
+ return array_key_exists( $tax_name, MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_checked_on_top'] );
1603
+ }
1604
+
1605
+ $tax_checked_on_top = isset( $tax_options['tax_checked_on_top'] ) ? $tax_options['tax_checked_on_top'] : MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_checked_on_top'];
1606
+ return array_key_exists( $tax_name, $tax_checked_on_top );
1607
+ case 'filter':
1608
+ $tax_filter = isset( $tax_options['tax_filter'] ) ? $tax_options['tax_filter'] : MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_filter'];
1609
+ if ( '' == $tax_name ) {
1610
+ return $tax_filter;
1611
+ }
1612
+
1613
+ if ( !empty( $_REQUEST['mla-general-options-save'] ) ) {
1614
+ $tax_filter = isset( $_REQUEST['tax_filter'] ) ? $_REQUEST['tax_filter'] : '';
1615
+ return ( $tax_name == $tax_filter );
1616
+ } elseif ( !empty( $_REQUEST['mla-general-options-reset'] ) ) {
1617
+ return array_key_exists( $tax_name, MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_filter'] );
1618
+ }
1619
+
1620
+ return ( $tax_name == $tax_filter );
1621
+ default:
1622
+ return false;
1623
+ } // $support_type
1624
+ } // mla_taxonomy_support
1625
+
1626
+ /**
1627
+ * Returns an array of taxonomy names assigned to $support_type
1628
+ *
1629
+ * @since 2.20
1630
+ *
1631
+ * @param string Optional. 'support' (default), 'quick-edit', 'flat-checklist', 'term-search' or 'filter'
1632
+ *
1633
+ * @return array taxonomies assigned to $support_type; can be empty.
1634
+ */
1635
+ public static function mla_supported_taxonomies($support_type = 'support') {
1636
+ $tax_options = MLACore::mla_get_option( MLACore::MLA_TAXONOMY_SUPPORT );
1637
+ switch ( $support_type ) {
1638
+ case 'support':
1639
+ if ( !empty( $_REQUEST['mla-general-options-save'] ) ) {
1640
+ return isset( $_REQUEST['tax_support'] ) ? array_keys( $_REQUEST['tax_support'] ) : array();
1641
+ } elseif ( !empty( $_REQUEST['mla-general-options-reset'] ) ) {
1642
+ return array_keys( MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_support'] );
1643
+ }
1644
+
1645
+ return array_keys( isset( $tax_options['tax_support'] ) ? $tax_options['tax_support'] : MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_support'] );
1646
+ case 'quick-edit':
1647
+ if ( !empty( $_REQUEST['mla-general-options-save'] ) ) {
1648
+ return isset( $_REQUEST['tax_quick_edit'] ) ? array_keys( $_REQUEST['tax_quick_edit'] ) : array();
1649
+ } elseif ( !empty( $_REQUEST['mla-general-options-reset'] ) ) {
1650
+ return array_keys( MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_quick_edit'] );
1651
+ }
1652
+
1653
+ return array_keys( isset( $tax_options['tax_quick_edit'] ) ? $tax_options['tax_quick_edit'] : MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_quick_edit'] );
1654
+ case 'term-search':
1655
+ if ( !empty( $_REQUEST['mla-general-options-save'] ) ) {
1656
+ return isset( $_REQUEST['tax_term_search'] ) ? array_keys( $_REQUEST['tax_term_search'] ) : array();
1657
+ } elseif ( !empty( $_REQUEST['mla-general-options-reset'] ) ) {
1658
+ return array_keys( MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_term_search'] );
1659
+ }
1660
+
1661
+ return array_keys( isset( $tax_options['tax_term_search'] ) ? $tax_options['tax_term_search'] : MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_term_search'] );
1662
+ case 'flat-checklist':
1663
+ if ( !empty( $_REQUEST['mla-general-options-save'] ) ) {
1664
+ return isset( $_REQUEST['tax_flat_checklist'] ) ? array_keys( $_REQUEST['tax_flat_checklist'] ) : array();
1665
+ } elseif ( !empty( $_REQUEST['mla-general-options-reset'] ) ) {
1666
+ return array_keys( MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_flat_checklist'] );
1667
+ }
1668
+
1669
+ return array_keys( isset( $tax_options['tax_flat_checklist'] ) ? $tax_options['tax_flat_checklist'] : MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_flat_checklist'] );
1670
+ case 'checked-on-top':
1671
+ if ( !empty( $_REQUEST['mla-general-options-save'] ) ) {
1672
+ return isset( $_REQUEST['tax_checked_on_top'] ) ? array_keys( $_REQUEST['tax_checked_on_top'] ) : array();
1673
+ } elseif ( !empty( $_REQUEST['mla-general-options-reset'] ) ) {
1674
+ return array_keys( MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_checked_on_top'] );
1675
+ }
1676
+
1677
+ return array_keys( isset( $tax_options['tax_checked_on_top'] ) ? $tax_options['tax_checked_on_top'] : MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_checked_on_top'] );
1678
+ case 'filter':
1679
+ if ( !empty( $_REQUEST['mla-general-options-save'] ) ) {
1680
+ return isset( $_REQUEST['tax_filter'] ) ? (array) $_REQUEST['tax_filter'] : array();
1681
+ } elseif ( !empty( $_REQUEST['mla-general-options-reset'] ) ) {
1682
+ return (array) MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_filter'];
1683
+ }
1684
+
1685
+ return (array) isset( $tax_options['tax_filter'] ) ? $tax_options['tax_filter'] : MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_filter'];
1686
+ default:
1687
+ return array();
1688
+ } // $support_type
1689
+ } // mla_supported_taxonomies
1690
+
1691
+
1692
+ /**
1693
+ * Evaluate support information for custom field mapping
1694
+ *
1695
+ * @since 1.10
1696
+ *
1697
+ * @param string array format; 'default_columns' (default), 'default_hidden_columns', 'default_sortable_columns', 'quick_edit' or 'bulk_edit'
1698
+ *
1699
+ * @return array default, hidden, sortable quick_edit or bulk_edit colums in appropriate format
1700
+ */
1701
+ public static function mla_custom_field_support( $support_type = 'default_columns' ) {
1702
+ $option_values = MLACore::mla_get_option( 'custom_field_mapping' );
1703
+ $results = array();
1704
+ $index = 0;
1705
+
1706
+ foreach ( $option_values as $key => $value ) {
1707
+ $slug = 'c_' . $index++; // sanitize_title( $key ); Didn't handle HTML in name, e.g., "R><B"
1708
+
1709
+ switch( $support_type ) {
1710
+ case 'custom_columns':
1711
+ if ( $value['mla_column'] ) {
1712
+ $results[ $slug ] = $value['name'];
1713
+ }
1714
+ break;
1715
+ case 'default_columns':
1716
+ if ( $value['mla_column'] ) {
1717
+ $results[ $slug ] = esc_html( $value['name'] );
1718
+ }
1719
+ break;
1720
+ case 'default_hidden_columns':
1721
+ if ( $value['mla_column'] ) {
1722
+ $results[] = $slug;
1723
+ }
1724
+ break;
1725
+ case 'custom_sortable_columns':
1726
+ if ( $value['mla_column'] ) {
1727
+ // columns without NULL values should sort descending
1728
+ $results[ $slug ] = array( $value['name'], $value['no_null'] );
1729
+ }
1730
+ break;
1731
+ case 'default_sortable_columns':
1732
+ if ( $value['mla_column'] ) {
1733
+ // columns without NULL values should sort descending
1734
+ $results[ $slug ] = array( $slug, $value['no_null'] );
1735
+ }
1736
+ break;
1737
+ case 'quick_edit':
1738
+ if ( $value['quick_edit'] ) {
1739
+ $results[ $slug ] = $value;
1740
+ }
1741
+ break;
1742
+ case 'bulk_edit':
1743
+ if ( $value['bulk_edit'] ) {
1744
+ $results[ $slug ] = $value;
1745
+ }
1746
+ break;
1747
+ } // switch support_type
1748
+ } // foreach option_value
1749
+
1750
+ return $results;
1751
+ } // mla_custom_field_support
1752
+
1753
+ /**
1754
+ * Convert a Library View/Post MIME Type specification to WP_Query parameters
1755
+ *
1756
+ * @since 1.40
1757
+ *
1758
+ * @param string View slug, unique identifier
1759
+ * @param string A specification, e.g., "custom:Field,null" or "audio,application/vnd.*ms*"
1760
+ *
1761
+ * @return array post_mime_type specification or custom field query
1762
+ */
1763
+ public static function mla_prepare_view_query( $slug, $specification ) {
1764
+ $query = array ( );
1765
+ $specification = self::mla_parse_view_specification( $specification );
1766
+ if ( 'mime' == $specification['prefix'] ) {
1767
+ $query['post_mime_type'] = $specification['value'];
1768
+ } else {
1769
+ $meta_query = array( 'slug' => $slug , 'relation' => 'OR', 'patterns' => array () );
1770
+ switch( $specification['option'] ) {
1771
+ case 'match':
1772
+ $patterns = array_map( 'trim', explode( ',', $specification['value'] ) );
1773
+ foreach ( (array) $patterns as $pattern ) {
1774
+ $pattern = preg_replace( '/\*+/', '%', $pattern );
1775
+ if ( false !== strpos( $pattern, '%' ) ) {
1776
+ /*
1777
+ * Preserve the pattern - it will be used in the "where" filter
1778
+ */
1779
+ $meta_query['patterns'][] = $pattern;
1780
+ $meta_query[] = array( 'key' => $specification['name'], 'value' => $pattern, 'compare' => 'LIKE' );
1781
+ } else {
1782
+ $meta_query[] = array( 'key' => $specification['name'], 'value' => $pattern, 'compare' => '=' );
1783
+ }
1784
+ } // foreach pattern
1785
+
1786
+ if ( empty( $meta_query['patterns'] ) ) {
1787
+ unset( $meta_query['patterns'] );
1788
+ }
1789
+
1790
+ break;
1791
+ case 'null':
1792
+ $meta_query['key'] = $specification['name'];
1793
+ $meta_query['value'] = 'NULL';
1794
+ break;
1795
+ default: // '', 'any'
1796
+ $meta_query[] = array( 'key' => $specification['name'], 'value' => NULL, 'compare' => '!=' );
1797
+ }
1798
+
1799
+ $query['meta_query'] = $meta_query;
1800
+ } // custom field specification
1801
+
1802
+ return $query;
1803
+ }
1804
+
1805
+ /**
1806
+ * Analyze a Library View/Post MIME Type specification, returning an array of the placeholders it contains
1807
+ *
1808
+ * @since 1.40
1809
+ *
1810
+ * @param string|array A specification, e.g., "custom:Field,null" or "audio,application/vnd.*ms*"
1811
+ *
1812
+ * @return array ( ['prefix'] => string, ['name'] => string, ['value'] => string, ['option'] => string, optional ['error'] => string )
1813
+ */
1814
+ public static function mla_parse_view_specification( $specification ) {
1815
+ if ( is_array( $specification ) ) {
1816
+ $specification = @implode( ',', $specification );
1817
+ }
1818
+
1819
+ $result = array( 'prefix' => '', 'name' => '', 'value' => '', 'option' => '' );
1820
+ $match_count = preg_match( '/^(.+):(.+)/', $specification, $matches );
1821
+ if ( 1 == $match_count ) {
1822
+ $result['prefix'] = trim( strtolower( $matches[1] ) );
1823
+ $tail = $matches[2];
1824
+
1825
+ $match_count = preg_match( '/([^,=]+)((,|=)(.*))$/', $tail, $matches );
1826
+ if ( 1 == $match_count ) {
1827
+ $result['name'] = $matches[1];
1828
+
1829
+ if ( ',' == $matches[3] ) {
1830
+ $result['option'] = trim( strtolower( $matches[4] ));
1831
+ } else {
1832
+ if ( empty( $matches[4] ) ) {
1833
+ $result['option'] = 'null';
1834
+ } elseif ( '*' == $matches[4] ) {
1835
+ $result['option'] = 'any';
1836
+ } else {
1837
+ $result['option'] = 'match';
1838
+ $result['value'] = $matches[4];
1839
+ }
1840
+ }
1841
+ } else {
1842
+ $result['option'] = 'any';
1843
+ $result['name'] = $tail;
1844
+ }
1845
+ } else {
1846
+ $result['prefix'] = 'mime';
1847
+ $result['value'] = $specification;
1848
+ }
1849
+
1850
+ /*
1851
+ * Validate the results
1852
+ */
1853
+ if ( 'mime' == $result['prefix'] ) {
1854
+ $mime_types = array_map( 'trim', explode( ',', $result['value'] ) );
1855
+ foreach ( (array) $mime_types as $raw_mime_type ) {
1856
+ $no_wildcards = str_replace( '*', 'X', $raw_mime_type );
1857
+ $clean_mime_type = sanitize_mime_type( $no_wildcards );
1858
+ if ( $clean_mime_type != $no_wildcards ) {
1859
+ /* translators: 1: ERROR tag 2: raw_mime_type */
1860
+ $result['error'] = '<br>' . sprintf( __( '%1$s: Bad specification part "%2$s"', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $raw_mime_type );
1861
+ }
1862
+ } // foreach
1863
+ } elseif ( 'custom' == $result['prefix'] ) {
1864
+ if ( ! in_array( $result['option'], array( '', 'any', 'match', 'null' ) ) ) {
1865
+ /* translators: 1: ERROR tag 2: option, e.g., any, match, null */
1866
+ $result['error'] = '<br>' . sprintf( __( '%1$s: Bad specification option "%2$s"', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $specification['option'] );
1867
+ }
1868
+ } else {
1869
+ /* translators: 1: ERROR tag 2: prefix, e.g., custom */
1870
+ $result['error'] = '<br>' . sprintf( __( '%1$s: Bad specification prefix "%2$s"', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $specification['prefix'] );
1871
+ }
1872
+
1873
+ return $result;
1874
+ }
1875
+
1876
+ /**
1877
+ * Display taxonomy "checklist" form fields
1878
+ *
1879
+ * Adapted from /wp-admin/includes/ajax-actions.php function _wp_ajax_add_hierarchical_term().
1880
+ * Includes the "? Search" area to filter the term checklist by entering part
1881
+ * or all of a word/phrase in the term label.
1882
+ * Output to the Media/Edit Media screen and to the Media Manager Modal Window.
1883
+ *
1884
+ * @since 1.71
1885
+ *
1886
+ * @param object The current post
1887
+ * @param array The meta box parameters
1888
+ *
1889
+ * @return void Echoes HTML for the form fields
1890
+ */
1891
+ public static function mla_checklist_meta_box( $target_post, $box ) {
1892
+ global $post;
1893
+
1894
+ $defaults = array('taxonomy' => 'category', 'in_modal' => false );
1895
+ $post_id = $target_post->ID;
1896
+
1897
+ if ( !isset( $box['args'] ) || !is_array( $box['args'] ) ) {
1898
+ $args = array();
1899
+ } else {
1900
+ $args = $box['args'];
1901
+ }
1902
+
1903
+ extract( wp_parse_args( $args, $defaults ), EXTR_SKIP );
1904
+ $tax = get_taxonomy( $taxonomy );
1905
+ $name = ( $taxonomy == 'category' ) ? 'post_category' : 'tax_input[' . $taxonomy . ']';
1906
+
1907
+ /*
1908
+ * Id and Name attributes in the popup Modal Window must not conflict with
1909
+ * the underlying Edit Post/Page window, so we prefix with "mla-"/"mla_".
1910
+ */
1911
+ if ( $in_modal ) {
1912
+ if ( empty( $post ) ) {
1913
+ $post = $target_post; // for wp_popular_terms_checklist
1914
+ }
1915
+
1916
+ $div_taxonomy_id = "mla-taxonomy-{$taxonomy}";
1917
+ $tabs_ul_id = "mla-{$taxonomy}-tabs";
1918
+ $tab_all_id = "mla-{$taxonomy}-all";
1919
+ $tab_all_ul_id = "mla-{$taxonomy}-checklist";
1920
+ $tab_pop_id = "mla-{$taxonomy}-pop";
1921
+ $tab_pop_ul_id = "mla-{$taxonomy}-checklist-pop";
1922
+ $input_terms_name = "mla_attachments[{$post_id}][{$name}][]";
1923
+ $input_terms_id = "mla-{$name}-id";
1924
+ $div_adder_id = "mla-{$taxonomy}-adder";
1925
+ $div_adder_class = "mla-hidden-children";
1926
+ $link_adder_id = "mla-{$taxonomy}-add-toggle";
1927
+ $link_adder_p_id = "mla-{$taxonomy}-add";
1928
+ $div_search_id = "mla-{$taxonomy}-searcher";
1929
+ $div_search_class = "mla-hidden-children";
1930
+ $link_search_id = "mla-{$taxonomy}-search-toggle";
1931
+ $link_search_p_id = "mla-{$taxonomy}-search";
1932
+ $input_new_name = "new{$taxonomy}";
1933
+ $input_new_id = "mla-new-{$taxonomy}";
1934
+ $input_new_parent_name = "new{$taxonomy}_parent";
1935
+ $input_new_submit_id = "mla-{$taxonomy}-add-submit";
1936
+ $span_new_ajax_id = "mla-{$taxonomy}-ajax-response";
1937
+ $input_search_name = "search-{$taxonomy}";
1938
+ $input_search_id = "mla-search-{$taxonomy}";
1939
+ $span_search_ajax_id = "mla-{$taxonomy}-search-ajax-response";
1940
+ } else {
1941
+ $div_taxonomy_id = "taxonomy-{$taxonomy}";
1942
+ $tabs_ul_id = "{$taxonomy}-tabs";
1943
+ $tab_all_id = "{$taxonomy}-all";
1944
+ $tab_all_ul_id = "{$taxonomy}checklist";
1945
+ $tab_pop_id = "{$taxonomy}-pop";
1946
+ $tab_pop_ul_id = "{$taxonomy}checklist-pop";
1947
+ $input_terms_name = "{$name}[]";
1948
+ $input_terms_id = "{$name}-id";
1949
+ $div_adder_id = "{$taxonomy}-adder";
1950
+ $div_adder_class = "wp-hidden-children";
1951
+ $link_adder_id = "{$taxonomy}-add-toggle";
1952
+ $link_adder_p_id = "{$taxonomy}-add";
1953
+ $div_search_id = "{$taxonomy}-searcher";
1954
+ $div_search_class = "wp-hidden-children";
1955
+ $link_search_id = "{$taxonomy}-search-toggle";
1956
+ $link_search_p_id = "{$taxonomy}-search";
1957
+ $input_new_name = "new{$taxonomy}";
1958
+ $input_new_id = "new{$taxonomy}";
1959
+ $input_new_parent_name = "new{$taxonomy}_parent";
1960
+ $input_new_submit_id = "{$taxonomy}-add-submit";
1961
+ $span_new_ajax_id = "{$taxonomy}-ajax-response";
1962
+ $input_search_name = "search-{$taxonomy}";
1963
+ $input_search_id = "search-{$taxonomy}";
1964
+ $span_search_ajax_id = "{$taxonomy}-search-ajax-response";
1965
+ }
1966
+ ?>
1967
+ <div id="<?php echo $div_taxonomy_id; ?>" class="categorydiv">
1968
+ <ul id="<?php echo $tabs_ul_id; ?>" class="category-tabs">
1969
+ <li class="tabs"><a href="#<?php echo $tab_all_id; ?>"><?php echo $tax->labels->all_items; ?></a></li>
1970
+ <li class="hide-if-no-js"><a href="#<?php echo $tab_pop_id; ?>"><?php _e( 'Most Used' ); ?></a></li>
1971
+ </ul>
1972
+
1973
+ <div id="<?php echo $tab_pop_id; ?>" class="tabs-panel" style="display: none;">
1974
+ <ul id="<?php echo $tab_pop_ul_id; ?>" class="categorychecklist form-no-clear" >
1975
+ <?php $popular_ids = wp_popular_terms_checklist($taxonomy); ?>
1976
+ </ul>
1977
+ </div>
1978
+
1979
+ <div id="<?php echo $tab_all_id; ?>" class="tabs-panel">
1980
+ <?php
1981
+ // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
1982
+ echo "<input type='hidden' name='{$input_terms_name}' id='{$input_terms_id}' value='0' />";
1983
+ ?>
1984
+ <ul id="<?php echo $tab_all_ul_id; ?>" data-wp-lists="list:<?php echo $taxonomy?>" class="categorychecklist form-no-clear">
1985
+ <?php if ( $tax->hierarchical ): ?>
1986
+ <?php wp_terms_checklist($post->ID, array( 'taxonomy' => $taxonomy, 'popular_cats' => $popular_ids, 'checked_ontop'=> MLACore::mla_taxonomy_support( $taxonomy, 'checked-on-top' ) ) ) ?>
1987
+ <?php else: ?>
1988
+ <?php $checklist_walker = new MLA_Checklist_Walker; ?>
1989
+ <?php wp_terms_checklist($post->ID, array( 'taxonomy' => $taxonomy, 'popular_cats' => $popular_ids, 'checked_ontop'=> MLACore::mla_taxonomy_support( $taxonomy, 'checked-on-top' ), 'walker' => $checklist_walker ) ) ?>
1990
+ <?php endif; ?>
1991
+ </ul>
1992
+ </div>
1993
+ <?php if ( current_user_can($tax->cap->edit_terms) ) : ?>
1994
+ <div id="<?php echo $div_adder_id; ?>" class="<?php echo $div_adder_class; ?>">
1995
+ <h4>
1996
+ <a id="<?php echo $link_adder_id; ?>" href="#<?php echo $link_adder_p_id; ?>" class="hide-if-no-js">
1997
+ <?php
1998
+ /* translators: %s: add new taxonomy label */
1999
+ printf( __( '+ %s', 'media-library-assistant' ), $tax->labels->add_new_item );
2000
+ ?>
2001
+ </a>
2002
+ &nbsp;&nbsp;
2003
+ <a id="<?php echo $link_search_id; ?>" href="#<?php echo $link_search_p_id; ?>" class="hide-if-no-js">
2004
+ <?php
2005
+ echo '?&nbsp;' . __( 'Search', 'media-library-assistant' );
2006
+ ?>
2007
+ </a>
2008
+ </h4>
2009
+ <p id="<?php echo $link_adder_p_id; ?>" class="category-add wp-hidden-child">
2010
+ <label class="screen-reader-text" for="<?php echo $input_new_name; ?>"><?php echo $tax->labels->add_new_item; ?></label>
2011
+ <input type="text" name="<?php echo $input_new_name; ?>" id="<?php echo $input_new_id; ?>" class="form-required form-input-tip" value="<?php echo esc_attr( $tax->labels->new_item_name ); ?>" aria-required="true"/>
2012
+
2013
+ <?php if ( $tax->hierarchical ): ?>
2014
+ <label class="screen-reader-text" for="<?php echo $input_new_parent_name; ?>">
2015
+ <?php echo $tax->labels->parent_item_colon; ?>
2016
+ </label>
2017
+ <?php wp_dropdown_categories( array( 'taxonomy' => $taxonomy, 'hide_empty' => 0, 'name' => $input_new_parent_name, 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => '&mdash; ' . $tax->labels->parent_item . ' &mdash;' ) ); ?>
2018
+ <?php else:
2019
+ echo "<input type='hidden' name='{$input_new_parent_name}' id='{$input_new_parent_name}' value='-1' />";
2020
+ endif; ?>
2021
+ <input type="button" id="<?php echo $input_new_submit_id; ?>" data-wp-lists="add:<?php echo $tab_all_ul_id ?>:<?php echo $link_adder_p_id ?>" class="button category-add-submit mla-taxonomy-add-submit" value="<?php echo esc_attr( $tax->labels->add_new_item ); ?>" />
2022
+ <?php wp_nonce_field( 'add-'.$taxonomy, '_ajax_nonce-add-'.$taxonomy, false ); ?>
2023
+ <span id="<?php echo $span_new_ajax_id; ?>"></span>
2024
+ </p>
2025
+ </div>
2026
+ <div id="<?php echo $div_search_id; ?>" class="<?php echo $div_search_class; ?>">
2027
+ <p id="<?php echo $link_search_p_id; ?>" class="category-add wp-hidden-child">
2028
+ <label class="screen-reader-text" for="<?php echo $input_search_name; ?>"><?php echo $tax->labels->search_items; ?></label>
2029
+ <input type="text" name="<?php echo $input_search_name; ?>" id="<?php echo $input_search_id; ?>" class="form-required form-input-tip" value="<?php echo esc_attr( $tax->labels->search_items ); ?>" aria-required="true"/>
2030
+ <?php wp_nonce_field( 'search-'.$taxonomy, '_ajax_nonce-search-'.$taxonomy, false ); ?>
2031
+ <span id="<?php echo $span_search_ajax_id; ?>"></span>
2032
+ </p>
2033
+ </div>
2034
+ <?php endif; ?>
2035
+ </div>
2036
+ <?php
2037
+ } // mla_checklist_meta_box
2038
+
2039
+ /**
2040
+ * Effective MLA Debug Level, from MLA_DEBUG_LEVEL or override option
2041
+ *
2042
+ * @since 2.15
2043
+ *
2044
+ * @var integer
2045
+ */
2046
+ public static $mla_debug_level = 0;
2047
+
2048
+ /**
2049
+ * Accumulates debug messages
2050
+ *
2051
+ * @since 2.12
2052
+ *
2053
+ * @var string
2054
+ */
2055
+ private static $mla_debug_messages = array();
2056
+
2057
+ /**
2058
+ * Debug information collection mode
2059
+ *
2060
+ * Collection mode: 'buffer', 'console', 'log' or 'none' (default).
2061
+ *
2062
+ * @since 2.12
2063
+ *
2064
+ * @var string
2065
+ */
2066
+ private static $mla_debug_mode = 'none';
2067
+
2068
+ /**
2069
+ * Debug information output file for mode = 'log'
2070
+ *
2071
+ * @since 2.14
2072
+ *
2073
+ * @var string
2074
+ */
2075
+ private static $mla_debug_file = NULL;
2076
+
2077
+ /**
2078
+ * Get/Set debug information collection mode
2079
+ *
2080
+ * @since 2.12
2081
+ *
2082
+ * @param string $mode Optional. New collection mode: 'none' (default), 'buffer', 'console' or 'log'
2083
+ *
2084
+ * @return string The previous mode value, i.e., before the update
2085
+ */
2086
+ public static function mla_debug_mode( $mode = false ) {
2087
+ $old_mode = self::$mla_debug_mode;
2088
+
2089
+ if ( $mode && in_array( $mode, array( 'none', 'buffer', 'console', 'log' ) ) ) {
2090
+ self::$mla_debug_mode = $mode;
2091
+ }
2092
+
2093
+ return $old_mode;
2094
+ }
2095
+
2096
+ /**
2097
+ * Get/Set debug information collection output file for mode = 'log'
2098
+ *
2099
+ * Note that WP_CONTENT_DIR will be pre-pended to the value, and a slash
2100
+ * will be added to the front of the value if necessary.
2101
+ *
2102
+ * @since 2.14
2103
+ *
2104
+ * @param string $file Optional. The (optional path and) file name, relative to WP_CONTENT_DIR,
2105
+ * or false/empty string to clear the value.
2106
+ *
2107
+ * @return string The previous file value, i.e., before the update, relative to WP_CONTENT_DIR
2108
+ */
2109
+ public static function mla_debug_file( $file = NULL ) {
2110
+ if ( NULL === $file ) {
2111
+ return self::$mla_debug_file;
2112
+ }
2113
+
2114
+ $old_file = self::$mla_debug_file;
2115
+
2116
+ if ( empty( $file ) ) {
2117
+ self::$mla_debug_file = NULL;
2118
+ } else {
2119
+ $first = substr( $file, 0, 1 );
2120
+ if ( ( '/' != $first ) && ( '\\' != $first ) ) {
2121
+ $file = '/' . $file;
2122
+ }
2123
+
2124
+ self::$mla_debug_file = $file;
2125
+ }
2126
+
2127
+ return $old_file;
2128
+ }
2129
+
2130
+ /**
2131
+ * Get debug information without clearing the buffer
2132
+ *
2133
+ * @since 2.12
2134
+ *
2135
+ * @param string $format Return data type: 'string' (default) or 'array'
2136
+ * @param string $glue Join array elements with '\n' or '<p>' (default)
2137
+ *
2138
+ * @return boolean true if success else false
2139
+ */
2140
+ public static function mla_debug_content( $format = 'string', $glue = '<p>' ) {
2141
+ if ( 'array' == $format ) {
2142
+ return self::$mla_debug_messages;
2143
+ }
2144
+
2145
+ // format == 'string'
2146
+ if ( '<p>' == $glue ) {
2147
+ return '<p>' . implode( '</p><p>', self::$mla_debug_messages ) . '</p>';
2148
+ }
2149
+
2150
+ return implode( "\n", self::$mla_debug_messages ) . "\n";
2151
+ }
2152
+
2153
+ /**
2154
+ * Flush debug information and clear buffer
2155
+ *
2156
+ * @since 2.12
2157
+ *
2158
+ * @param string $destination Destination: 'buffer' (default), 'console', 'log' or 'none'
2159
+ * @param boolean $stop_collecting true (default) to stop, false to continue collection
2160
+ *
2161
+ * @return string debug content if $destination == 'buffer' else empty string
2162
+ */
2163
+ public static function mla_debug_flush( $destination = 'buffer', $stop_collecting = true ) {
2164
+ $results = '';
2165
+
2166
+ switch ( $destination ) {
2167
+ case 'buffer':
2168
+ $results = MLACore::mla_debug_content();
2169
+ break;
2170
+ case 'console':
2171
+ foreach( self::$mla_debug_messages as $message ) {
2172
+ trigger_error( $message, E_USER_WARNING );
2173
+ }
2174
+ break;
2175
+ case 'log':
2176
+ foreach( self::$mla_debug_messages as $message ) {
2177
+ self::_debug_log( $message );
2178
+ }
2179
+ break;
2180
+ }
2181
+
2182
+ self::$mla_debug_messages = array();
2183
+
2184
+ if ( $stop_collecting ) {
2185
+ self::$mla_debug_mode = 'none';
2186
+ }
2187
+
2188
+ return $results;
2189
+ }
2190
+
2191
+ /**
2192
+ * Write a debug message to the appropriate log file
2193
+ *
2194
+ * @since 2.14
2195
+ *
2196
+ * @param string $message Message text
2197
+ */
2198
+ private static function _debug_log( $message ) {
2199
+ if ( ! empty( self::$mla_debug_file ) ) {
2200
+ // 'at' = append mode, text format
2201
+ $file_handle = @fopen( WP_CONTENT_DIR . self::$mla_debug_file, 'at' );
2202
+ if ( $file_handle ) {
2203
+ @fwrite( $file_handle, sprintf( '[%1$s] %2$s%3$s', gmdate( 'd-M-Y H:i:s' ), $message, "\n" ) );
2204
+ @fclose( $file_handle );
2205
+
2206
+ return;
2207
+ }
2208
+ }
2209
+
2210
+ error_log( $message, 0 );
2211
+ }
2212
+
2213
+ /**
2214
+ * Add a debug message to the collection
2215
+ *
2216
+ * @since 2.12
2217
+ *
2218
+ * @param string $message Message text
2219
+ * @param integer $debug_level Optional. Debug category.
2220
+ */
2221
+ public static function mla_debug_add( $message, $debug_level = NULL ) {
2222
+ $mode = self::$mla_debug_mode;
2223
+
2224
+ if ( NULL != $debug_level ) {
2225
+ if ( ( 0 == ( MLACore::$mla_debug_level & 1 ) ) || ( 0 == ( MLACore::$mla_debug_level & $debug_level ) ) ) {
2226
+ return;
2227
+ }
2228
+
2229
+ if ( 'none' == self::$mla_debug_mode ) {
2230
+ $mode = 'log';
2231
+ }
2232
+ }
2233
+
2234
+ switch ( $mode ) {
2235
+ case 'buffer':
2236
+ self::$mla_debug_messages[] = $message;
2237
+ break;
2238
+ case 'console':
2239
+ trigger_error( $message, E_USER_WARNING );
2240
+ break;
2241
+ case 'log':
2242
+ self::_debug_log( $message );
2243
+ break;
2244
+ }
2245
+ }
2246
+ } // Class MLACore
2247
+
2248
+ /**
2249
+ * Class MLA (Media Library Assistant) Checklist Walker replaces term_id with slug in checklist output
2250
+ *
2251
+ * This walker is used to build the meta boxes for flat taxonomies, e.g., Tags, Att. Tags.
2252
+ * Class Walker_Category is defined in /wp-includes/category-template.php.
2253
+ * Class Walker is defined in /wp-includes/class-wp-walker.php.
2254
+ *
2255
+ * @package Media Library Assistant
2256
+ * @since 1.80
2257
+ */
2258
+ class MLA_Checklist_Walker extends Walker_Category {
2259
+ /**
2260
+ * Start the element output.
2261
+ *
2262
+ * @see Walker::start_el()
2263
+ *
2264
+ * @since 1.80
2265
+ *
2266
+ * @param string Passed by reference. Used to append additional content.
2267
+ * @param object Taxonomy data object.
2268
+ * @param int Depth of category in reference to parents. Default 0.
2269
+ * @param array An array of arguments. @see wp_list_categories()
2270
+ * @param int ID of the current category.
2271
+ */
2272
+ function start_el( &$output, $taxonomy_object, $depth = 0, $args = array(), $id = 0 ) {
2273
+ extract($args);
2274
+
2275
+ if ( empty( $taxonomy ) ) {
2276
+ $taxonomy = 'category';
2277
+ }
2278
+
2279
+ if ( 'category' == $taxonomy ) {
2280
+ $name = 'post_category';
2281
+ } else {
2282
+ $name = 'tax_input['.$taxonomy.']';
2283
+ }
2284
+
2285
+ $class = in_array( $taxonomy_object->term_id, $popular_cats ) ? ' class="popular-category"' : '';
2286
+
2287
+ /*
2288
+ * For flat taxonomies, <input> value is $taxonomy_object->name instead of $taxonomy_object->term_id
2289
+ */
2290
+ $output .= "\n<li id='{$taxonomy}-{$taxonomy_object->term_id}'$class>" . '<label class="selectit MLA"><input value="' . $taxonomy_object->name . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $taxonomy_object->term_id . '"' . checked( in_array( $taxonomy_object->term_id, $selected_cats ), true, false ) . disabled( empty( $args['disabled'] ), false, false ) . ' /> ' . esc_html( apply_filters('the_category', $taxonomy_object->name )) . '</label>';
2291
+ }
2292
+
2293
+ /**
2294
+ * Ends the element output, if needed.
2295
+ *
2296
+ * @see Walker::end_el()
2297
+ *
2298
+ * @since 1.80
2299
+ *
2300
+ * @param string $output Passed by reference. Used to append additional content.
2301
+ * @param object $category The current term object.
2302
+ * @param int $depth Depth of the term in reference to parents. Default 0.
2303
+ * @param array $args An array of arguments. @see wp_terms_checklist()
2304
+ */
2305
+ function end_el( &$output, $category, $depth = 0, $args = array() ) {
2306
+ $output .= "</li>\n";
2307
+ }
2308
+ }// Class MLA_Checklist_Walker
2309
+
2310
+ /*
2311
+ * Custom Taxonomies and WordPress objects.
2312
+ */
2313
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-objects.php' );
2314
+ add_action( 'init', 'MLAObjects::initialize', 0x7FFFFFFF );
2315
+ ?>
includes/class-mla-data-pdf.php CHANGED
@@ -229,10 +229,11 @@ class MLAPDF {
229
  * @param string full path and file name
230
  * @param integer The object number
231
  * @param integer The object generation number; default zero (0)
 
232
  *
233
  * @return mixed NULL on failure else array( 'start' => offset in the file, 'length' => object length, 'content' => dictionary contents )
234
  */
235
- private static function _find_pdf_indirect_dictionary( $file_name, $object, $generation = 0 ) {
236
  $chunksize = 16384;
237
  $key = ( $object * 1000 ) + $generation;
238
  if ( isset( self::$pdf_indirect_objects ) && isset( self::$pdf_indirect_objects[ $key ] ) ) {
@@ -243,14 +244,18 @@ class MLAPDF {
243
 
244
  $object_starts = array();
245
  $object_content = file_get_contents( $file_name, true, NULL, $file_offset, $chunksize );
 
246
 
247
  /*
248
  * Match the object header
249
  */
250
  $pattern = sprintf( '!%1$d\\h+%2$d\\h+obj[\\x00-\\x20]*(<<)!', $object, $generation );
 
251
  $match_count = preg_match( $pattern, $object_content, $matches, PREG_OFFSET_CAPTURE );
 
252
  if ( $match_count ) {
253
  $object_starts[] = array( 'offset' => $file_offset, 'start' => $matches[1][1]);
 
254
  $match_count = 0;
255
  }
256
 
@@ -261,9 +266,11 @@ class MLAPDF {
261
  $file_offset += ( $chunksize - 16 );
262
  $object_content = file_get_contents( $file_name, true, NULL, $file_offset, $chunksize );
263
  $match_count = preg_match( $pattern, $object_content, $matches, PREG_OFFSET_CAPTURE );
 
264
 
265
  if ( $match_count ) {
266
  $object_starts[] = array( 'offset' => $file_offset, 'start' => $matches[1][1]);
 
267
  $match_count = 0;
268
  }
269
 
@@ -271,15 +278,28 @@ class MLAPDF {
271
  $file_offset += ( $chunksize - 16 );
272
  $object_content = file_get_contents( $file_name, true, NULL, $file_offset, $chunksize );
273
  $match_count = preg_match( $pattern, $object_content, $matches, PREG_OFFSET_CAPTURE );
 
274
 
275
  if ( $match_count ) {
276
  $object_starts[] = array( 'offset' => $file_offset, 'start' => $matches[1][1]);
 
277
  $match_count = 0;
278
  }
279
  } // while not found
280
  } // if not found
 
281
 
282
- $object_start = array_pop( $object_starts );
 
 
 
 
 
 
 
 
 
 
283
  if ( is_null( $object_start ) ) {
284
  return NULL;
285
  } else {
@@ -312,8 +332,9 @@ class MLAPDF {
312
  }
313
 
314
  if ($match_count) {
315
- $results = array( 'start' => $file_offset + $start, 'length' => ($matches[0][1] + 2) - $start );
316
  $results['content'] = substr( $object_content, $start, $results['length'] );
 
317
  return $results;
318
  } // found trailer
319
 
@@ -616,35 +637,35 @@ class MLAPDF {
616
  */
617
  if ( 'xref' == substr( $tail, $chunk_offset, 4 ) ) {
618
  $xref_length = self::_parse_pdf_xref_section( $file_name, $file_offset + $chunk_offset + 4 );
619
- $chunk_offset += 4 + $xref_length;
 
620
 
621
- if ( $chunk_offset > ( $chunksize - 1024 ) ) {
622
- $file_offset += $chunk_offset;
623
- $tail = file_get_contents( $file_name, true, NULL, $file_offset, $chunksize );
624
- $chunk_offset = 0;
625
  }
 
626
 
627
  $match_count = preg_match( '/[\x00-\x20]*trailer[\x00-\x20]+/', $tail, $matches, PREG_OFFSET_CAPTURE, $chunk_offset );
 
628
  if ( $match_count ) {
629
  $chunk_offset = $matches[0][1] + strlen( $matches[0][0] );
630
- $match_count = preg_match( '/<<(.*)>>/', $tail, $matches, 0, $chunk_offset );
631
-
632
- if ( 0 < $match_count ) {
633
- $dictionary = self::_parse_pdf_dictionary( $matches[0], 0 );
634
 
635
- if ( isset( $dictionary['Prev'] ) ) {
636
- $other_trailers = self::_extract_pdf_trailer( $file_name, $dictionary['Prev']['value'] );
637
- } else {
638
- $other_trailers = NULL;
639
- }
640
 
641
- if ( is_array( $other_trailers ) ) {
642
- $other_trailers = array_merge( $other_trailers, array( $dictionary ) );
643
- return $other_trailers;
644
- } else {
645
- return array( $dictionary );
646
- }
647
- } // found trailer dictionary
648
  } // found 'trailer'
649
  } else { // found 'xref'
650
  /*
@@ -705,12 +726,14 @@ class MLAPDF {
705
  $filesize = filesize( $file_name );
706
  $file_offset = ( $chunksize < $filesize ) ? ( $filesize - $chunksize ) : 0;
707
  $tail = file_get_contents( $file_name, false, NULL, $file_offset );
 
708
 
709
  if ( 0 == $file_offset ) {
710
  $header = substr( $tail, 0, 128 );
711
  } else {
712
  $header = file_get_contents( $file_name, false, NULL, 0, 128 );
713
  }
 
714
 
715
  if ( '%PDF-' == substr( $header, 0, 5 ) ) {
716
  $metadata['PDF_Version'] = substr( $header, 1, 7 );
@@ -729,6 +752,7 @@ class MLAPDF {
729
 
730
  $startxref = (integer) $matches[1][ $match_count - 1 ][0];
731
  $trailer_dictionaries = self::_extract_pdf_trailer( $file_name, $startxref );
 
732
  if ( is_array( $trailer_dictionaries ) ) {
733
  $info_reference = NULL;
734
  foreach ( $trailer_dictionaries as $trailer_dictionary )
@@ -736,11 +760,29 @@ class MLAPDF {
736
  $info_reference = $trailer_dictionary['Info'];
737
  break;
738
  }
 
739
 
740
  if ( isset( $info_reference ) ) {
741
  $info_object = self::_find_pdf_indirect_dictionary( $file_name, $info_reference['object'], $info_reference['generation'] );
 
 
 
 
 
742
  if ( $info_object ) {
 
 
 
 
 
 
 
 
 
 
 
743
  $info_dictionary = self::_parse_pdf_dictionary( $info_object['content'], 0 );
 
744
  unset( $info_dictionary['/length'] );
745
 
746
  foreach ( $info_dictionary as $name => $value ) {
@@ -757,38 +799,56 @@ class MLAPDF {
757
  $metadata[ $name ] = $value['value'];
758
  }
759
  } // each info entry
760
- } // found Info object
 
 
 
 
 
 
 
761
  } // found Info reference
 
762
 
763
  /*
764
  * Look for XMP Metadata
765
  */
766
  $root_reference = NULL;
767
- foreach ( $trailer_dictionaries as $trailer_dictionary )
768
- if ( isset( $trailer_dictionary['Root'] ) ) {
769
- $root_reference = $trailer_dictionary['Root'];
770
- break;
 
 
771
  }
772
-
 
773
  if ( isset( $root_reference ) ) {
774
  $root_object = self::_find_pdf_indirect_dictionary( $file_name, $root_reference['object'], $root_reference['generation'] );
 
775
  if ( $root_object ) {
776
  $root_dictionary = self::_parse_pdf_dictionary( $root_object['content'], 0 );
 
777
  unset( $root_dictionary['/length'] );
778
 
779
  if ( isset( $root_dictionary['Metadata'] ) ) {
780
  $xmp_object = self::_find_pdf_indirect_dictionary( $file_name, $root_dictionary['Metadata']['object'], $root_dictionary['Metadata']['generation'] );
 
781
  $xmp = MLAData::mla_parse_xmp_metadata( $file_name, $xmp_object['start'] + $xmp_object['length'] );
782
 
783
  if ( is_array( $xmp ) ) {
784
  $metadata = array_merge( $metadata, $xmp );
785
  } else {
786
  $xmp = array();
 
 
787
  }
788
  } // found Metadata reference
789
  } // found Root object
790
  } // found Root reference
791
  } // found trailer_dictionaries
 
 
792
 
793
  return array( 'xmp' => $xmp, 'pdf' => $metadata );
794
  }
229
  * @param string full path and file name
230
  * @param integer The object number
231
  * @param integer The object generation number; default zero (0)
232
+ * @param integer The desired object instance (when multiple instances are present); default "highest/latest"
233
  *
234
  * @return mixed NULL on failure else array( 'start' => offset in the file, 'length' => object length, 'content' => dictionary contents )
235
  */
236
+ private static function _find_pdf_indirect_dictionary( $file_name, $object, $generation = 0, $instance = NULL ) {
237
  $chunksize = 16384;
238
  $key = ( $object * 1000 ) + $generation;
239
  if ( isset( self::$pdf_indirect_objects ) && isset( self::$pdf_indirect_objects[ $key ] ) ) {
244
 
245
  $object_starts = array();
246
  $object_content = file_get_contents( $file_name, true, NULL, $file_offset, $chunksize );
247
+ //error_log( __LINE__ . " MLAPDF::_find_pdf_indirect_dictionary( {$file_name}, {$file_offset} ) object_content = \r\n" . MLAData::mla_hex_dump( $object_content ), 0 );
248
 
249
  /*
250
  * Match the object header
251
  */
252
  $pattern = sprintf( '!%1$d\\h+%2$d\\h+obj[\\x00-\\x20]*(<<)!', $object, $generation );
253
+ //error_log( __LINE__ . " MLAPDF::_find_pdf_indirect_dictionary( {$object}, {$generation} ) pattern = " . var_export( $pattern, true ), 0 );
254
  $match_count = preg_match( $pattern, $object_content, $matches, PREG_OFFSET_CAPTURE );
255
+ //error_log( __LINE__ . " MLAPDF::_find_pdf_indirect_dictionary( {$match_count} ) matches = " . var_export( $matches, true ), 0 );
256
  if ( $match_count ) {
257
  $object_starts[] = array( 'offset' => $file_offset, 'start' => $matches[1][1]);
258
+ //error_log( __LINE__ . " MLAPDF::_find_pdf_indirect_dictionary( {$file_offset}, {$matches[1][1]} ) object_content = \r\n" . MLAData::mla_hex_dump( substr( $object_content, $matches[1][1] ), 512 ), 0 );
259
  $match_count = 0;
260
  }
261
 
266
  $file_offset += ( $chunksize - 16 );
267
  $object_content = file_get_contents( $file_name, true, NULL, $file_offset, $chunksize );
268
  $match_count = preg_match( $pattern, $object_content, $matches, PREG_OFFSET_CAPTURE );
269
+ //error_log( __LINE__ . " MLAPDF::_find_pdf_indirect_dictionary( {$match_count} ) matches = " . var_export( $matches, true ), 0 );
270
 
271
  if ( $match_count ) {
272
  $object_starts[] = array( 'offset' => $file_offset, 'start' => $matches[1][1]);
273
+ //error_log( __LINE__ . " MLAPDF::_find_pdf_indirect_dictionary( {$file_offset}, {$matches[1][1]} ) object_content = \r\n" . MLAData::mla_hex_dump( substr( $object_content, $matches[1][1] ), 512 ), 0 );
274
  $match_count = 0;
275
  }
276
 
278
  $file_offset += ( $chunksize - 16 );
279
  $object_content = file_get_contents( $file_name, true, NULL, $file_offset, $chunksize );
280
  $match_count = preg_match( $pattern, $object_content, $matches, PREG_OFFSET_CAPTURE );
281
+ //error_log( __LINE__ . " MLAPDF::_find_pdf_indirect_dictionary( {$match_count} ) matches = " . var_export( $matches, true ), 0 );
282
 
283
  if ( $match_count ) {
284
  $object_starts[] = array( 'offset' => $file_offset, 'start' => $matches[1][1]);
285
+ //error_log( __LINE__ . " MLAPDF::_find_pdf_indirect_dictionary( {$file_offset}, {$matches[1][1]} ) object_content = \r\n" . MLAData::mla_hex_dump( substr( $object_content, $matches[1][1] ), 512 ), 0 );
286
  $match_count = 0;
287
  }
288
  } // while not found
289
  } // if not found
290
+ //error_log( __LINE__ . " MLAPDF::_find_pdf_indirect_dictionary object_starts = " . var_export( $object_starts, true ), 0 );
291
 
292
+ /*
293
+ * Return the highest/latest instance unless a specific instance is requested
294
+ */
295
+ $object_count = count( $object_starts );
296
+ if ( is_null( $instance ) ) {
297
+ $object_start = array_pop( $object_starts );
298
+ } else {
299
+ $instance = absint( $instance );
300
+ $object_start = isset( $object_starts[ $instance ] ) ? $object_starts[ $instance ] : NULL;
301
+ }
302
+
303
  if ( is_null( $object_start ) ) {
304
  return NULL;
305
  } else {
332
  }
333
 
334
  if ($match_count) {
335
+ $results = array( 'count' => $object_count, 'start' => $file_offset + $start, 'length' => ($matches[0][1] + 2) - $start );
336
  $results['content'] = substr( $object_content, $start, $results['length'] );
337
+ //error_log( __LINE__ . " MLAPDF::_find_pdf_indirect_dictionary results = " . var_export( $results, true ), 0 );
338
  return $results;
339
  } // found trailer
340
 
637
  */
638
  if ( 'xref' == substr( $tail, $chunk_offset, 4 ) ) {
639
  $xref_length = self::_parse_pdf_xref_section( $file_name, $file_offset + $chunk_offset + 4 );
640
+ //error_log( __LINE__ . " MLAPDF::_extract_pdf_trailer xref_length = " . var_export( $xref_length, true ), 0 );
641
+ $chunk_offset += 4 + $xref_length;
642
 
643
+ if ( $chunk_offset > ( $chunksize - 1024 ) ) {
644
+ $file_offset += $chunk_offset;
645
+ $tail = file_get_contents( $file_name, true, NULL, $file_offset, $chunksize );
646
+ $chunk_offset = 0;
647
  }
648
+ //error_log( __LINE__ . " MLAPDF::_extract_pdf_trailer( {$file_offset} ) tail = \r\n" . MLAData::mla_hex_dump( $tail, 0, 16, 0 ), 0 );
649
 
650
  $match_count = preg_match( '/[\x00-\x20]*trailer[\x00-\x20]+/', $tail, $matches, PREG_OFFSET_CAPTURE, $chunk_offset );
651
+ //error_log( __LINE__ . " MLAPDF::_extract_pdf_trailer( {$match_count} ) matches = " . var_export( $matches, true ), 0 );
652
  if ( $match_count ) {
653
  $chunk_offset = $matches[0][1] + strlen( $matches[0][0] );
654
+ $dictionary = self::_parse_pdf_dictionary( $tail, $chunk_offset );
655
+ //error_log( __LINE__ . " MLAPDF::_extract_pdf_trailer dictionary = " . var_export( $dictionary, true ), 0 );
 
 
656
 
657
+ if ( isset( $dictionary['Prev'] ) ) {
658
+ $other_trailers = self::_extract_pdf_trailer( $file_name, $dictionary['Prev']['value'] );
659
+ } else {
660
+ $other_trailers = NULL;
661
+ }
662
 
663
+ if ( is_array( $other_trailers ) ) {
664
+ $other_trailers = array_merge( $other_trailers, array( $dictionary ) );
665
+ return $other_trailers;
666
+ } else {
667
+ return array( $dictionary );
668
+ }
 
669
  } // found 'trailer'
670
  } else { // found 'xref'
671
  /*
726
  $filesize = filesize( $file_name );
727
  $file_offset = ( $chunksize < $filesize ) ? ( $filesize - $chunksize ) : 0;
728
  $tail = file_get_contents( $file_name, false, NULL, $file_offset );
729
+ //error_log( __LINE__ . " MLAPDF::mla_extract_pdf_metadata( {$file_name}, {$file_offset} ) tail = \r\n" . MLAData::mla_hex_dump( $tail ), 0 );
730
 
731
  if ( 0 == $file_offset ) {
732
  $header = substr( $tail, 0, 128 );
733
  } else {
734
  $header = file_get_contents( $file_name, false, NULL, 0, 128 );
735
  }
736
+ //error_log( __LINE__ . " MLAPDF::mla_extract_pdf_metadata( {$file_name}, {$file_offset} ) header = \r\n" . MLAData::mla_hex_dump( $header ), 0 );
737
 
738
  if ( '%PDF-' == substr( $header, 0, 5 ) ) {
739
  $metadata['PDF_Version'] = substr( $header, 1, 7 );
752
 
753
  $startxref = (integer) $matches[1][ $match_count - 1 ][0];
754
  $trailer_dictionaries = self::_extract_pdf_trailer( $file_name, $startxref );
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 )
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
 
765
  if ( isset( $info_reference ) ) {
766
  $info_object = self::_find_pdf_indirect_dictionary( $file_name, $info_reference['object'], $info_reference['generation'] );
767
+
768
+ /*
769
+ * Handle single or multiple Info instances
770
+ */
771
+ $info_objects = array();
772
  if ( $info_object ) {
773
+ if ( 1 == $info_object['count'] ) {
774
+ $info_objects[] = $info_object;
775
+ } else {
776
+ for ( $index = 0; $index < $info_object['count']; $index++ ) {
777
+ $info_objects[] = self::_find_pdf_indirect_dictionary( $file_name, $info_reference['object'], $info_reference['generation'], $index );
778
+ }
779
+ }
780
+ }
781
+ //error_log( __LINE__ . " MLAPDF::mla_extract_pdf_metadata info_objects = " . var_export( $info_objects, true ), 0 );
782
+
783
+ foreach( $info_objects as $info_object ) {
784
  $info_dictionary = self::_parse_pdf_dictionary( $info_object['content'], 0 );
785
+ //error_log( __LINE__ . " MLAPDF::mla_extract_pdf_metadata info_dictionary = " . var_export( $info_dictionary, true ), 0 );
786
  unset( $info_dictionary['/length'] );
787
 
788
  foreach ( $info_dictionary as $name => $value ) {
799
  $metadata[ $name ] = $value['value'];
800
  }
801
  } // each info entry
802
+ } // foreach Info object
803
+
804
+ /*
805
+ * Remove spurious "Filter" dictionaries
806
+ */
807
+ unset( $metadata['Filter'] );
808
+ unset( $metadata['Length'] );
809
+ unset( $metadata['Length1'] );
810
  } // found Info reference
811
+ //error_log( __LINE__ . ' MLAPDF::mla_extract_pdf_metadata pdf metadata = ' . var_export( $metadata, true ), 0 );
812
 
813
  /*
814
  * Look for XMP Metadata
815
  */
816
  $root_reference = NULL;
817
+ //error_log( __LINE__ . " MLAPDF::mla_extract_pdf_metadata info_dictionary = " . var_export( $info_dictionary, true ), 0 );
818
+ foreach ( $trailer_dictionaries as $trailer_dictionary ) {
819
+ if ( isset( $trailer_dictionary['Root'] ) ) {
820
+ $root_reference = $trailer_dictionary['Root'];
821
+ break;
822
+ }
823
  }
824
+ //error_log( __LINE__ . " MLAPDF::mla_extract_pdf_metadata root_reference = " . var_export( $root_reference, true ), 0 );
825
+
826
  if ( isset( $root_reference ) ) {
827
  $root_object = self::_find_pdf_indirect_dictionary( $file_name, $root_reference['object'], $root_reference['generation'] );
828
+ //error_log( __LINE__ . " MLAPDF::mla_extract_pdf_metadata root_object = " . var_export( $root_object, true ), 0 );
829
  if ( $root_object ) {
830
  $root_dictionary = self::_parse_pdf_dictionary( $root_object['content'], 0 );
831
+ //error_log( __LINE__ . " MLAPDF::mla_extract_pdf_metadata root_dictionary = " . var_export( $root_dictionary, true ), 0 );
832
  unset( $root_dictionary['/length'] );
833
 
834
  if ( isset( $root_dictionary['Metadata'] ) ) {
835
  $xmp_object = self::_find_pdf_indirect_dictionary( $file_name, $root_dictionary['Metadata']['object'], $root_dictionary['Metadata']['generation'] );
836
+ //error_log( __LINE__ . " MLAPDF::mla_extract_pdf_metadata xmp_object = " . var_export( $xmp_object, true ), 0 );
837
  $xmp = MLAData::mla_parse_xmp_metadata( $file_name, $xmp_object['start'] + $xmp_object['length'] );
838
 
839
  if ( is_array( $xmp ) ) {
840
  $metadata = array_merge( $metadata, $xmp );
841
  } else {
842
  $xmp = array();
843
+ $xmp = MLAData::mla_parse_xmp_metadata( $file_name, 0 );
844
+ //error_log( __LINE__ . ' MLAPDF::mla_extract_pdf_metadata recovered xmp = ' . var_export( $xmp, true ), 0 );
845
  }
846
  } // found Metadata reference
847
  } // found Root object
848
  } // found Root reference
849
  } // found trailer_dictionaries
850
+ //error_log( __LINE__ . ' MLAPDF::mla_extract_pdf_metadata pdf = ' . var_export( $metadata, true ), 0 );
851
+ //error_log( __LINE__ . ' MLAPDF::mla_extract_pdf_metadata xmp = ' . var_export( $xmp, true ), 0 );
852
 
853
  return array( 'xmp' => $xmp, 'pdf' => $metadata );
854
  }
includes/class-mla-data-query.php ADDED
@@ -0,0 +1,1967 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Database query support for MLA Ajax, Shortcode and Admin needs
4
+ *
5
+ * @package Media Library Assistant
6
+ * @since 2.20
7
+ */
8
+
9
+ /**
10
+ * Class MLA (Media Library Assistant) Query provides database query support
11
+ * for MLA Ajax, Shortcode and Admin needs
12
+ *
13
+ * @package Media Library Assistant
14
+ * @since 2.20
15
+ */
16
+ class MLAQuery {
17
+ /**
18
+ * Provides a unique suffix for the ALT Text "Search Media" SQL View
19
+ *
20
+ * The SQL View is used to filter the Media/Assistant submenu table by
21
+ * ALT Text with the Search Media text box.
22
+ *
23
+ * @since 0.40
24
+ */
25
+ const MLA_ALT_TEXT_VIEW_SUFFIX = 'alt_text_view';
26
+
27
+ /**
28
+ * Provides a unique name for the ALT Text "Search Media" SQL View
29
+ *
30
+ * @since 0.40
31
+ *
32
+ * @var array
33
+ */
34
+ private static $mla_alt_text_view = NULL;
35
+
36
+ /**
37
+ * Provides a unique suffix for the custom field "orderby" SQL View
38
+ *
39
+ * The SQL View is used to sort the Media/Assistant submenu table on
40
+ * ALT Text and custom field columns.
41
+ *
42
+ * @since 2.15
43
+ */
44
+ const MLA_ORDERBY_VIEW_SUFFIX = 'orderby_view';
45
+
46
+ /**
47
+ * Provides a unique name for the custom field "orderby" SQL View
48
+ *
49
+ * @since 2.15
50
+ *
51
+ * @var array
52
+ */
53
+ private static $mla_orderby_view = NULL;
54
+
55
+ /**
56
+ * Provides a unique suffix for the "Table View custom:" SQL View
57
+ *
58
+ * The SQL View is used to filter the Media/Assistant submenu table on
59
+ * custom field Table Views.
60
+ *
61
+ * @since 2.15
62
+ */
63
+ const MLA_TABLE_VIEW_CUSTOM_SUFFIX = 'table_view_custom';
64
+
65
+ /**
66
+ * Provides a unique name for the "Table View custom:" SQL View
67
+ *
68
+ * @since 2.15
69
+ *
70
+ * @var array
71
+ */
72
+ private static $mla_table_view_custom = NULL;
73
+
74
+ /**
75
+ * WordPress version test for $wpdb->esc_like() Vs esc_sql()
76
+ *
77
+ * @since 2.13
78
+ *
79
+ * @var boolean
80
+ */
81
+ public static $wp_4dot0_plus = true;
82
+
83
+ /**
84
+ * Initialization function, similar to __construct()
85
+ *
86
+ * @since 0.1
87
+ */
88
+ public static function initialize() {
89
+ global $table_prefix;
90
+
91
+ self::$mla_alt_text_view = $table_prefix . MLA_OPTION_PREFIX . self::MLA_ALT_TEXT_VIEW_SUFFIX;
92
+ self::$mla_orderby_view = $table_prefix . MLA_OPTION_PREFIX . self::MLA_ORDERBY_VIEW_SUFFIX;
93
+ self::$mla_table_view_custom = $table_prefix . MLA_OPTION_PREFIX . self::MLA_TABLE_VIEW_CUSTOM_SUFFIX;
94
+ self::$wp_4dot0_plus = version_compare( get_bloginfo('version'), '4.0', '>=' );
95
+
96
+ /*
97
+ * Set up the Media/Assistant submenu table column definitions
98
+ */
99
+ $taxonomies = get_taxonomies( array ( 'show_ui' => true ), 'names' );
100
+
101
+ foreach ( $taxonomies as $tax_name ) {
102
+ if ( MLACore::mla_taxonomy_support( $tax_name ) ) {
103
+ $tax_object = get_taxonomy( $tax_name );
104
+ self::$default_columns[ 't_' . $tax_name ] = esc_html( $tax_object->labels->name );
105
+ self::$default_hidden_columns [] = 't_' . $tax_name;
106
+ // self::$default_sortable_columns [] = none at this time
107
+ } // supported taxonomy
108
+ } // foreach $tax_name
109
+
110
+ self::$default_columns = array_merge( self::$default_columns, MLACore::mla_custom_field_support( 'default_columns' ) );
111
+ self::$default_hidden_columns = array_merge( self::$default_hidden_columns, MLACore::mla_custom_field_support( 'default_hidden_columns' ) );
112
+ self::$default_sortable_columns = array_merge( self::$default_sortable_columns, MLACore::mla_custom_field_support( 'default_sortable_columns' ) );
113
+ }
114
+
115
+ /**
116
+ * Find Featured Image and inserted image/link references to an attachment
117
+ *
118
+ * Searches all post and page content to see if the attachment is used
119
+ * as a Featured Image or inserted in the post as an image or link.
120
+ *
121
+ * @since 0.1
122
+ *
123
+ * @param int post ID of attachment
124
+ * @param int post ID of attachment's parent, if any
125
+ * @param boolean True to compute references, false to return empty values
126
+ *
127
+ * @return array Reference information; see $references array comments
128
+ */
129
+ public static function mla_fetch_attachment_references( $ID, $parent, $add_references = true ) {
130
+ /*
131
+ * The MLAReferences class is only loaded when needed.
132
+ */
133
+ if ( !class_exists( 'MLAReferences' ) ) {
134
+ if ( -1 === $ID ) {
135
+ return NULL;
136
+ }
137
+
138
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-data-references.php' );
139
+ }
140
+
141
+ return MLAReferences::mla_fetch_attachment_references_handler( $ID, $parent, $add_references );
142
+ }
143
+
144
+ /**
145
+ * Add Featured Image and inserted image/link references to an array of attachments
146
+ *
147
+ * Searches all post and page content to see if the attachmenta are used
148
+ * as a Featured Image or inserted in the post as an image or link.
149
+ *
150
+ * @since 1.94
151
+ *
152
+ * @param array WP_Post objects, passed by reference
153
+ *
154
+ * @return void updates WP_Post objects with new mla_references property
155
+ */
156
+ public static function mla_attachment_array_fetch_references( &$attachments ) {
157
+ /*
158
+ * The MLAReferences class is only loaded when needed.
159
+ */
160
+ if ( !class_exists( 'MLAReferences' ) ) {
161
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-data-references.php' );
162
+ }
163
+
164
+ return MLAReferences::mla_attachment_array_fetch_references_handler( $attachments );
165
+ }
166
+
167
+ /**
168
+ * Invalidates the $mla_galleries or $galleries array and cached values
169
+ *
170
+ * @since 1.00
171
+ *
172
+ * @param string name of the gallery's cache/option variable
173
+ *
174
+ * @return void
175
+ */
176
+ public static function mla_flush_mla_galleries( $option_name ) {
177
+ delete_transient( MLA_OPTION_PREFIX . 't_' . $option_name );
178
+
179
+ /*
180
+ * If MLAReferences isn't loaded there is nothing else to do
181
+ */
182
+ if ( class_exists( 'MLAReferences' ) ) {
183
+ MLAReferences::mla_flush_mla_galleries_handler( $option_name );
184
+ }
185
+ }
186
+
187
+ /**
188
+ * Builds the $default_columns array with translated source texts.
189
+ *
190
+ * Called from MLATest::initialize because the $default_columns information
191
+ * might be accessed from "front end" posts/pages.
192
+ *
193
+ * @since 1.71
194
+ */
195
+ public static function mla_localize_default_columns_array( ) {
196
+ /*
197
+ * Build the default columns array at runtime to accomodate calls to the
198
+ * localization functions
199
+ */
200
+ self::$default_columns = array(
201
+ 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
202
+ 'icon' => '',
203
+ 'ID_parent' => esc_html( _x( 'ID/Parent', 'list_table_column', 'media-library-assistant' ) ),
204
+ 'title_name' => esc_html( _x( 'Title/Name', 'list_table_column', 'media-library-assistant' ) ),
205
+ 'post_title' => esc_html( _x( 'Title', 'list_table_column', 'media-library-assistant' ) ),
206
+ 'post_name' => esc_html( _x( 'Name', 'list_table_column', 'media-library-assistant' ) ),
207
+ 'parent' => esc_html( _x( 'Parent ID', 'list_table_column', 'media-library-assistant' ) ),
208
+ 'menu_order' => esc_html( _x( 'Menu Order', 'list_table_column', 'media-library-assistant' ) ),
209
+ 'featured' => esc_html( _x( 'Featured in', 'list_table_column', 'media-library-assistant' ) ),
210
+ 'inserted' => esc_html( _x( 'Inserted in', 'list_table_column', 'media-library-assistant' ) ),
211
+ 'galleries' => esc_html( _x( 'Gallery in', 'list_table_column', 'media-library-assistant' ) ),
212
+ 'mla_galleries' => esc_html( _x( 'MLA Gallery in', 'list_table_column', 'media-library-assistant' ) ),
213
+ 'alt_text' => esc_html( _x( 'ALT Text', 'list_table_column', 'media-library-assistant' ) ),
214
+ 'caption' => esc_html( _x( 'Caption', 'list_table_column', 'media-library-assistant' ) ),
215
+ 'description' => esc_html( _x( 'Description', 'list_table_column', 'media-library-assistant' ) ),
216
+ 'post_mime_type' => esc_html( _x( 'MIME Type', 'list_table_column', 'media-library-assistant' ) ),
217
+ 'file_url' => esc_html( _x( 'File URL', 'list_table_column', 'media-library-assistant' ) ),
218
+ 'base_file' => esc_html( _x( 'Base File', 'list_table_column', 'media-library-assistant' ) ),
219
+ 'date' => esc_html( _x( 'Date', 'list_table_column', 'media-library-assistant' ) ),
220
+ 'modified' => esc_html( _x( 'Last Modified', 'list_table_column', 'media-library-assistant' ) ),
221
+ 'author' => esc_html( _x( 'Author', 'list_table_column', 'media-library-assistant' ) ),
222
+ 'attached_to' => esc_html( _x( 'Attached to', 'list_table_column', 'media-library-assistant' ) ),
223
+ // taxonomy and custom field columns added below
224
+ );
225
+ }
226
+
227
+ /*
228
+ * The $default_columns, $default_hidden_columns, and $default_sortable_columns
229
+ * arrays define the "Media/Assistant" table columns.
230
+ */
231
+
232
+ /**
233
+ * Table column definitions
234
+ *
235
+ * This array defines table columns and titles where the key is the column slug (and class)
236
+ * and the value is the column's title text. If you need a checkbox for bulk actions,
237
+ * use the special slug "cb".
238
+ *
239
+ * The 'cb' column is treated differently than the rest. If including a checkbox
240
+ * column in your table you must create a column_cb() method. If you don't need
241
+ * bulk actions or checkboxes, simply leave the 'cb' entry out of your array.
242
+ *
243
+ * All of the columns are added to this array by MLA_List_Table::mla_admin_init_action.
244
+ *
245
+ * @since 0.1
246
+ *
247
+ * @var array
248
+ */
249
+ public static $default_columns = array();
250
+
251
+ /**
252
+ * Default values for hidden columns
253
+ *
254
+ * This array is used when the user-level option is not set, i.e.,
255
+ * the user has not altered the selection of hidden columns.
256
+ *
257
+ * The value on the right-hand side must match the column slug, e.g.,
258
+ * array(0 => 'ID_parent, 1 => 'title_name').
259
+ *
260
+ * Taxonomy and custom field columns are added to this array by
261
+ * MLA_List_Table::mla_admin_init_action.
262
+ *
263
+ * @since 0.1
264
+ *
265
+ * @var array
266
+ */
267
+ public static $default_hidden_columns = array(
268
+ // 'ID_parent',
269
+ // 'title_name',
270
+ 'post_title',
271
+ 'post_name',
272
+ 'parent',
273
+ 'menu_order',
274
+ 'featured',
275
+ 'inserted',
276
+ 'galleries',
277
+ 'mla_galleries',
278
+ // 'alt_text',
279
+ // 'caption',
280
+ // 'description',
281
+ 'post_mime_type',
282
+ 'file_url',
283
+ 'base_file',
284
+ // 'date',
285
+ 'modified',
286
+ 'author',
287
+ // 'attached_to',
288
+ // taxonomy columns added by mla_admin_init_action
289
+ // custom field columns added by mla_admin_init_action
290
+ );
291
+
292
+ /**
293
+ * Sortable column definitions
294
+ *
295
+ * This array defines the table columns that can be sorted. The array key
296
+ * is the column slug that needs to be sortable, and the value is database column
297
+ * to sort by. Often, the key and value will be the same, but this is not always
298
+ * the case (as the value is a column name from the database, not the list table).
299
+ *
300
+ * The array value also contains a boolean which is 'true' if the initial sort order
301
+ * for the column is DESC/Descending.
302
+ *
303
+ * Taxonomy and custom field columns are added to this array by
304
+ * MLA_List_Table::mla_admin_init_action.
305
+ *
306
+ * @since 0.1
307
+ *
308
+ * @var array
309
+ */
310
+ public static $default_sortable_columns = array(
311
+ 'ID_parent' => array('ID',true),
312
+ 'title_name' => array('title_name',false),
313
+ 'post_title' => array('post_title',false),
314
+ 'post_name' => array('post_name',false),
315
+ 'parent' => array('post_parent',false),
316
+ 'menu_order' => array('menu_order',false),
317
+ // 'featured' => array('featured',false),
318
+ // 'inserted' => array('inserted',false),
319
+ // 'galleries' => array('galleries',false),
320
+ // 'mla_galleries' => array('mla_galleries',false),
321
+ 'alt_text' => array('_wp_attachment_image_alt',true),
322
+ 'caption' => array('post_excerpt',false),
323
+ 'description' => array('post_content',false),
324
+ 'post_mime_type' => array('post_mime_type',false),
325
+ 'file_url' => array('guid',false),
326
+ 'base_file' => array('_wp_attached_file',false),
327
+ 'date' => array('post_date',true),
328
+ 'modified' => array('post_modified',true),
329
+ 'author' => array('post_author',false),
330
+ 'attached_to' => array('post_parent',false),
331
+ // sortable taxonomy columns, if any, added by mla_admin_init_action
332
+ // sortable custom field columns, if any, added by mla_admin_init_action
333
+ );
334
+
335
+ /**
336
+ * Return the names and display values of the sortable columns
337
+ *
338
+ * @since 0.30
339
+ *
340
+ * @return array name => array( orderby value, heading ) for sortable columns
341
+ */
342
+ public static function mla_get_sortable_columns( ) {
343
+ $results = array() ;
344
+
345
+ foreach ( self::$default_sortable_columns as $key => $value ) {
346
+ $value[1] = self::$default_columns[ $key ];
347
+ $results[ $key ] = $value;
348
+ }
349
+
350
+ return $results;
351
+ }
352
+
353
+ /**
354
+ * Cache the results of mla_count_list_table_items for reuse in mla_query_list_table_items
355
+ *
356
+ * @since 1.40
357
+ *
358
+ * @var array
359
+ */
360
+ private static $mla_list_table_items = NULL;
361
+
362
+ /**
363
+ * Get the total number of attachment posts
364
+ *
365
+ * @since 0.30
366
+ *
367
+ * @param array Query variables, e.g., from $_REQUEST
368
+ * @param int (optional) number of rows to skip over to reach desired page
369
+ * @param int (optional) number of rows on each page
370
+ *
371
+ * @return integer Number of attachment posts
372
+ */
373
+ public static function mla_count_list_table_items( $request, $offset = NULL, $count = NULL ) {
374
+ if ( NULL !== $offset && NULL !== $count ) {
375
+ $request = self::_prepare_list_table_query( $request, $offset, $count );
376
+ $request = apply_filters( 'mla_list_table_query_final_terms', $request );
377
+
378
+ self::$mla_list_table_items = apply_filters( 'mla_list_table_query_custom_items', NULL, $request );
379
+ if ( is_null( self::$mla_list_table_items ) ) {
380
+ self::$mla_list_table_items = self::_execute_list_table_query( $request );
381
+ }
382
+
383
+ return self::$mla_list_table_items->found_posts;
384
+ }
385
+
386
+ $request = self::_prepare_list_table_query( $request );
387
+ $request = apply_filters( 'mla_list_table_query_final_terms', $request );
388
+
389
+ $results = apply_filters( 'mla_list_table_query_custom_items', NULL, $request );
390
+ if ( is_null( $results ) ) {
391
+ $results = self::_execute_list_table_query( $request );
392
+ }
393
+
394
+ self::$mla_list_table_items = NULL;
395
+
396
+ return $results->found_posts;
397
+ }
398
+
399
+ /**
400
+ * Retrieve attachment objects for list table display
401
+ *
402
+ * Supports prepare_items in class-mla-list-table.php.
403
+ * Modeled after wp_edit_attachments_query in wp-admin/post.php
404
+ *
405
+ * @since 0.1
406
+ *
407
+ * @param array query parameters from web page, usually found in $_REQUEST
408
+ * @param int number of rows to skip over to reach desired page
409
+ * @param int number of rows on each page
410
+ *
411
+ * @return array attachment objects (posts) including parent data, meta data and references
412
+ */
413
+ public static function mla_query_list_table_items( $request, $offset, $count ) {
414
+ if ( NULL == self::$mla_list_table_items ) {
415
+ $request = self::_prepare_list_table_query( $request, $offset, $count );
416
+ $request = apply_filters( 'mla_list_table_query_final_terms', $request );
417
+
418
+ self::$mla_list_table_items = apply_filters( 'mla_list_table_query_custom_items', NULL, $request );
419
+ if ( is_null( self::$mla_list_table_items ) ) {
420
+ self::$mla_list_table_items = self::_execute_list_table_query( $request );
421
+ }
422
+ }
423
+
424
+ $attachments = self::$mla_list_table_items->posts;
425
+ foreach ( $attachments as $index => $attachment ) {
426
+ /*
427
+ * Add parent data
428
+ */
429
+ $parent_data = self::mla_fetch_attachment_parent_data( $attachment->post_parent );
430
+ foreach ( $parent_data as $parent_key => $parent_value ) {
431
+ $attachments[ $index ]->$parent_key = $parent_value;
432
+ }
433
+
434
+ /*
435
+ * Add meta data
436
+ */
437
+ $meta_data = self::mla_fetch_attachment_metadata( $attachment->ID );
438
+ foreach ( $meta_data as $meta_key => $meta_value ) {
439
+ $attachments[ $index ]->$meta_key = $meta_value;
440
+ }
441
+ }
442
+
443
+ /*
444
+ * Add references
445
+ */
446
+ self::mla_attachment_array_fetch_references( $attachments );
447
+
448
+ return $attachments;
449
+ }
450
+
451
+ /**
452
+ * Retrieve attachment objects for the WordPress Media Manager
453
+ *
454
+ * Supports month-year and taxonomy-term filters as well as the enhanced search box
455
+ *
456
+ * @since 1.20
457
+ *
458
+ * @param array query parameters from Media Manager
459
+ * @param int number of rows to skip over to reach desired page
460
+ * @param int number of rows on each page
461
+ *
462
+ * @return object WP_Query object with query results
463
+ */
464
+ public static function mla_query_media_modal_items( $request, $offset, $count ) {
465
+ $request = self::_prepare_list_table_query( $request, $offset, $count );
466
+ $request = apply_filters( 'mla_media_modal_query_final_terms', $request );
467
+
468
+ $results = apply_filters( 'mla_media_modal_query_custom_items', NULL, $request );
469
+ return is_null( $results ) ? self::_execute_list_table_query( $request ) : $results;
470
+ }
471
+
472
+ /**
473
+ * Returns information about an attachment's parent, if found
474
+ *
475
+ * @since 0.1
476
+ *
477
+ * @param int post ID of attachment's parent, if any
478
+ *
479
+ * @return array Parent information; post_date, post_title and post_type
480
+ */
481
+ public static function mla_fetch_attachment_parent_data( $parent_id ) {
482
+ static $save_id = -1, $parent_data;
483
+
484
+ if ( $save_id == $parent_id ) {
485
+ return $parent_data;
486
+ } elseif ( $parent_id == -1 ) {
487
+ $save_id = -1;
488
+ return NULL;
489
+ }
490
+
491
+ $parent_data = array();
492
+ if ( $parent_id ) {
493
+ $parent = get_post( $parent_id );
494
+
495
+ if ( isset( $parent->post_name ) ) {
496
+ $parent_data['parent_name'] = $parent->post_name;
497
+ }
498
+
499
+ if ( isset( $parent->post_type ) ) {
500
+ $parent_data['parent_type'] = $parent->post_type;
501
+ }
502
+
503
+ if ( isset( $parent->post_title ) ) {
504
+ $parent_data['parent_title'] = $parent->post_title;
505
+ }
506
+
507
+ if ( isset( $parent->post_date ) ) {
508
+ $parent_data['parent_date'] = $parent->post_date;
509
+ }
510
+
511
+ if ( isset( $parent->post_status ) ) {
512
+ $parent_data['parent_status'] = $parent->post_status;
513
+ }
514
+ }
515
+
516
+ $save_id = $parent_id;
517
+ return $parent_data;
518
+ }
519
+
520
+ /**
521
+ * Fetch and filter meta data for an attachment
522
+ *
523
+ * Returns a filtered array of a post's meta data. Internal values beginning with '_'
524
+ * are stripped out or converted to an 'mla_' equivalent.
525
+ *
526
+ * @since 0.1
527
+ *
528
+ * @param int post ID of attachment
529
+ *
530
+ * @return array Meta data variables
531
+ */
532
+ public static function mla_fetch_attachment_metadata( $post_id ) {
533
+ static $save_id = -1, $results;
534
+
535
+ if ( $save_id == $post_id ) {
536
+ return $results;
537
+ } elseif ( $post_id == -1 ) {
538
+ $save_id = -1;
539
+ return NULL;
540
+ }
541
+
542
+ $attached_file = NULL;
543
+ $results = array();
544
+ $post_meta = get_metadata( 'post', $post_id );
545
+ if ( is_array( $post_meta ) ) {
546
+ foreach ( $post_meta as $post_meta_key => $post_meta_value ) {
547
+ if ( empty( $post_meta_key ) ) {
548
+ continue;
549
+ }
550
+
551
+ if ( '_' == $post_meta_key{0} ) {
552
+ if ( stripos( $post_meta_key, '_wp_attached_file' ) === 0 ) {
553
+ $key = 'mla_wp_attached_file';
554
+ $attached_file = $post_meta_value[0];
555
+ } elseif ( stripos( $post_meta_key, '_wp_attachment_metadata' ) === 0 ) {
556
+ $key = 'mla_wp_attachment_metadata';
557
+ } elseif ( stripos( $post_meta_key, '_wp_attachment_image_alt' ) === 0 ) {
558
+ $key = 'mla_wp_attachment_image_alt';
559
+ } else {
560
+ continue;
561
+ }
562
+ } else {
563
+ if ( stripos( $post_meta_key, 'mla_' ) === 0 ) {
564
+ $key = $post_meta_key;
565
+ } else {
566
+ $key = 'mla_item_' . $post_meta_key;
567
+ }
568
+ }
569
+
570
+ /*
571
+ * At this point, every value is an array; one element per instance of the key.
572
+ * We'll test anyway, just to be sure, then convert single-instance values to a scalar.
573
+ * Metadata array values are serialized for storage in the database.
574
+ */
575
+ if ( is_array( $post_meta_value ) ) {
576
+ if ( count( $post_meta_value ) == 1 ) {
577
+ $post_meta_value = maybe_unserialize( $post_meta_value[0] );
578
+ } else {
579
+ foreach ( $post_meta_value as $single_key => $single_value ) {
580
+ $post_meta_value[ $single_key ] = maybe_unserialize( $single_value );
581
+ }
582
+ }
583
+ }
584
+
585
+ $results[ $key ] = $post_meta_value;
586
+ } // foreach $post_meta
587
+
588
+ if ( ! empty( $attached_file ) ) {
589
+ $last_slash = strrpos( $attached_file, '/' );
590
+ if ( false === $last_slash ) {
591
+ $results['mla_wp_attached_path'] = '';
592
+ $results['mla_wp_attached_filename'] = $attached_file;
593
+ } else {
594
+ $results['mla_wp_attached_path'] = substr( $attached_file, 0, $last_slash + 1 );
595
+ $results['mla_wp_attached_filename'] = substr( $attached_file, $last_slash + 1 );
596
+ }
597
+ } // $attached_file
598
+ } // is_array($post_meta)
599
+
600
+ $save_id = $post_id;
601
+ return $results;
602
+ }
603
+
604
+ /**
605
+ * WP_Query filter "parameters"
606
+ *
607
+ * This array defines parameters for the query's join, where and orderby filters.
608
+ * The parameters are set up in the _prepare_list_table_query function, and
609
+ * any further logic required to translate those values is contained in the filters.
610
+ *
611
+ * Array index values are: use_alt_text_view, use_postmeta_view, use_orderby_view,
612
+ * alt_text_value, postmeta_key, postmeta_value, patterns, detached,
613
+ * orderby, order, mla-metavalue, debug (also in search_parameters)
614
+ *
615
+ * @since 0.30
616
+ *
617
+ * @var array
618
+ */
619
+ public static $query_parameters = array();
620
+
621
+ /**
622
+ * WP_Query 'posts_search' filter "parameters"
623
+ *
624
+ * This array defines parameters for the query's posts_search filter, which uses
625
+ * 'search_string' to add a clause to the query's WHERE clause. It is shared between
626
+ * the list_table-query functions here and the mla_get_shortcode_attachments function
627
+ * in class-mla-shortcodes.php. This array passes the relevant parameters to the filter.
628
+ *
629
+ * Array index values are:
630
+ * ['mla_terms_search']['phrases']
631
+ * ['mla_terms_search']['taxonomies']
632
+ * ['mla_terms_search']['radio_phrases'] => AND/OR
633
+ * ['mla_terms_search']['radio_terms'] => AND/OR
634
+ * ['s'] => numeric for ID/parent search
635
+ * ['mla_search_fields'] => 'content', 'title', 'excerpt', 'alt-text', 'name', 'terms'
636
+ * Note: 'alt-text' is not supported in [mla_gallery]
637
+ * ['mla_search_connector'] => AND/OR
638
+ * ['sentence'] => entire string must match as one "keyword"
639
+ * ['exact'] => entire string must match entire field value
640
+ * ['debug'] => internal element, console/log/shortcode/none
641
+ * ['tax_terms_count'] => internal element, shared with JOIN and GROUP BY filters
642
+ *
643
+ * @since 2.00
644
+ *
645
+ * @var array
646
+ */
647
+ public static $search_parameters = array();
648
+
649
+ /**
650
+ * Fetch custom field option value given a slug
651
+ *
652
+ * @since 1.10
653
+ *
654
+ * @param string slug, e.g., 'c_File Size' for the 'File Size' field
655
+ *
656
+ * @return array option value, e.g., array( 'name' => 'File Size', ... )
657
+ */
658
+ public static function mla_custom_field_option_value( $slug ) {
659
+ $option_values = MLACore::mla_get_option( 'custom_field_mapping' );
660
+
661
+ foreach ( $option_values as $key => $value ) {
662
+ if ( $slug == 'c_' . $value['name'] ) {
663
+ return $value;
664
+ }
665
+ }
666
+
667
+ return array();
668
+ } // mla_custom_field_option_value
669
+
670
+ /**
671
+ * Sanitize and expand query arguments from request variables
672
+ *
673
+ * Prepare the arguments for WP_Query.
674
+ * Modeled after wp_edit_attachments_query in wp-admin/post.php
675
+ *
676
+ * @since 0.1
677
+ *
678
+ * @param array query parameters from web page, usually found in $_REQUEST
679
+ * @param int Optional number of rows (default 0) to skip over to reach desired page
680
+ * @param int Optional number of rows on each page (0 = all rows, default)
681
+ *
682
+ * @return array revised arguments suitable for WP_Query
683
+ */
684
+ private static function _prepare_list_table_query( $raw_request, $offset = 0, $count = 0 ) {
685
+ /*
686
+ * Go through the $raw_request, take only the arguments that are used in the query and
687
+ * sanitize or validate them.
688
+ */
689
+ if ( ! is_array( $raw_request ) ) {
690
+ /* translators: 1: ERROR tag 2: function name 3: non-array value */
691
+ 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 );
692
+ return NULL;
693
+ }
694
+
695
+ /*
696
+ * Make sure the current orderby choice still exists or revert to default.
697
+ */
698
+ $default_orderby = array_merge( array( 'none' => array('none',false) ), self::mla_get_sortable_columns( ) );
699
+ $current_orderby = MLACore::mla_get_option( MLACore::MLA_DEFAULT_ORDERBY );
700
+ $found_current = false;
701
+ foreach ( $default_orderby as $key => $value ) {
702
+ if ( $current_orderby == $value[0] ) {
703
+ $found_current = true;
704
+ break;
705
+ }
706
+ }
707
+
708
+ if ( $found_current ) {
709
+ /*
710
+ * Custom fields can have HTML reserved characters, which are encoded by
711
+ * mla_get_sortable_columns, so a separate, unencoded list is required.
712
+ */
713
+ $default_orderby = MLACore::mla_custom_field_support( 'custom_sortable_columns' );
714
+ foreach ( $default_orderby as $sort_key => $sort_value ) {
715
+ if ( $current_orderby == $sort_key ) {
716
+ $current_orderby = 'c_' . $sort_value[0];
717
+ break;
718
+ }
719
+ } // foreach
720
+ } else {
721
+ MLACore::mla_delete_option( MLACore::MLA_DEFAULT_ORDERBY );
722
+ $current_orderby = MLACore::mla_get_option( MLACore::MLA_DEFAULT_ORDERBY );
723
+ }
724
+
725
+ $clean_request = array (
726
+ 'm' => 0,
727
+ 'orderby' => $current_orderby,
728
+ 'order' => MLACore::mla_get_option( MLACore::MLA_DEFAULT_ORDER ),
729
+ 'post_type' => 'attachment',
730
+ 'post_status' => 'inherit',
731
+ 'mla_search_connector' => 'AND',
732
+ 'mla_search_fields' => array()
733
+ );
734
+
735
+ foreach ( $raw_request as $key => $value ) {
736
+ switch ( $key ) {
737
+ /*
738
+ * 'sentence' and 'exact' modify the keyword search ('s')
739
+ * Their value is not important, only their presence.
740
+ */
741
+ case 'sentence':
742
+ case 'exact':
743
+ case 'mla-tax':
744
+ case 'mla-term':
745
+ $clean_request[ $key ] = sanitize_key( $value );
746
+ break;
747
+ case 'orderby':
748
+ if ( in_array( $value, array( 'none', 'post__in' ) ) ) {
749
+ $clean_request[ $key ] = $value;
750
+ } else {
751
+ $orderby = NULL;
752
+ /*
753
+ * Custom fields can have HTML reserved characters, which are encoded by
754
+ * mla_get_sortable_columns, so a separate, unencoded list is required.
755
+ */
756
+ $sortable_columns = MLACore::mla_custom_field_support( 'custom_sortable_columns' );
757
+ foreach ($sortable_columns as $sort_key => $sort_value ) {
758
+ if ( $value == $sort_key ) {
759
+ $orderby = 'c_' . $sort_value[0];
760
+ break;
761
+ }
762
+ } // foreach
763
+
764
+ if ( NULL === $orderby ) {
765
+ $sortable_columns = MLAQuery::mla_get_sortable_columns();
766
+ foreach ($sortable_columns as $sort_key => $sort_value ) {
767
+ if ( $value == $sort_value[0] ) {
768
+ $orderby = $value;
769
+ break;
770
+ }
771
+ } // foreach
772
+ }
773
+
774
+ if ( NULL !== $orderby ) {
775
+ $clean_request[ $key ] = $orderby;
776
+ }
777
+ }
778
+
779
+ break;
780
+ /*
781
+ * ids allows hooks to supply a persistent list of items
782
+ */
783
+ case 'ids':
784
+ if ( is_array( $value ) ) {
785
+ $clean_request[ 'post__in' ] = $value;
786
+ } else {
787
+ $clean_request[ 'post__in' ] = array_map( 'absint', explode( ',', $value ) );
788
+ }
789
+ break;
790
+ /*
791
+ * post__in and post__not_in are used in the Media Modal Ajax queries
792
+ */
793
+ case 'post__in':
794
+ case 'post__not_in':
795
+ case 'post_mime_type':
796
+ $clean_request[ $key ] = $value;
797
+ break;
798
+ case 'parent':
799
+ case 'post_parent':
800
+ $clean_request[ 'post_parent' ] = absint( $value );
801
+ break;
802
+ /*
803
+ * ['m'] - filter by year and month of post, e.g., 201204
804
+ */
805
+ case 'author':
806
+ case 'm':
807
+ $clean_request[ $key ] = absint( $value );
808
+ break;
809
+ /*
810
+ * ['mla_filter_term'] - filter by category or tag ID; -1 allowed
811
+ */
812
+ case 'mla_filter_term':
813
+ $clean_request[ $key ] = intval( $value );
814
+ break;
815
+ case 'order':
816
+ switch ( $value = strtoupper ($value ) ) {
817
+ case 'ASC':
818
+ case 'DESC':
819
+ $clean_request[ $key ] = $value;
820
+ break;
821
+ default:
822
+ $clean_request[ $key ] = 'ASC';
823
+ }
824
+ break;
825
+ case 'detached':
826
+ if ( ( '0' == $value ) || ( '1' == $value ) ) {
827
+ $clean_request['detached'] = $value;
828
+ }
829
+
830
+ break;
831
+ case 'status':
832
+ if ( 'trash' == $value ) {
833
+ $clean_request['post_status'] = 'trash';
834
+ }
835
+
836
+ break;
837
+ /*
838
+ * ['s'] - Search Media by one or more keywords
839
+ * ['mla_search_connector'], ['mla_search_fields'] - Search Media options
840
+ */
841
+ case 's':
842
+ switch ( substr( $value, 0, 3 ) ) {
843
+ case '>|<':
844
+ $clean_request['debug'] = 'console';
845
+ break;
846
+ case '<|>':
847
+ $clean_request['debug'] = 'log';
848
+ break;
849
+ }
850
+
851
+ if ( isset( $clean_request['debug'] ) ) {
852
+ $value = substr( $value, 3 );
853
+ }
854
+
855
+ $value = stripslashes( trim( $value ) );
856
+
857
+ if ( ! empty( $value ) ) {
858
+ $clean_request[ $key ] = $value;
859
+ }
860
+
861
+ break;
862
+ case 'mla_terms_search':
863
+ if ( ! empty( $value['phrases'] ) && ! empty( $value['taxonomies'] ) ) {
864
+ $value['phrases'] = stripslashes( trim( $value['phrases'] ) );
865
+ if ( ! empty( $value['phrases'] ) ) {
866
+ $clean_request[ $key ] = $value;
867
+ }
868
+ }
869
+ break;
870
+ case 'mla_search_connector':
871
+ case 'mla_search_fields':
872
+ $clean_request[ $key ] = $value;
873
+ break;
874
+ case 'mla-metakey':
875
+ case 'mla-metavalue':
876
+ $clean_request[ $key ] = stripslashes( $value );
877
+ break;
878
+ case 'meta_query':
879
+ if ( ! empty( $value ) ) {
880
+ if ( is_array( $value ) ) {
881
+ $clean_request[ $key ] = $value;
882
+ } else {
883
+ $clean_request[ $key ] = unserialize( stripslashes( $value ) );
884
+ unset( $clean_request[ $key ]['slug'] );
885
+ } // not array
886
+ }
887
+
888
+ break;
889
+ default:
890
+ // ignore anything else in $_REQUEST
891
+ } // switch $key
892
+ } // foreach $raw_request
893
+
894
+ /*
895
+ * Pass query and search parameters to the filters for _execute_list_table_query
896
+ */
897
+ self::$query_parameters = array( 'use_alt_text_view' => false, 'use_postmeta_view' => false, 'use_orderby_view' => false, 'orderby' => $clean_request['orderby'], 'order' => $clean_request['order'] );
898
+ self::$query_parameters['detached'] = isset( $clean_request['detached'] ) ? $clean_request['detached'] : NULL;
899
+ self::$search_parameters = array( 'debug' => 'none' );
900
+
901
+ /*
902
+ * Matching a meta_value to NULL requires a LEFT JOIN to a view and a special WHERE clause
903
+ * Matching a wildcard pattern requires mainpulating the WHERE clause, too
904
+ */
905
+ if ( isset( $clean_request['meta_query']['key'] ) ) {
906
+ self::$query_parameters['use_postmeta_view'] = true;
907
+ self::$query_parameters['postmeta_key'] = $clean_request['meta_query']['key'];
908
+ self::$query_parameters['postmeta_value'] = NULL;
909
+ unset( $clean_request['meta_query'] );
910
+ } elseif ( isset( $clean_request['meta_query']['patterns'] ) ) {
911
+ self::$query_parameters['patterns'] = $clean_request['meta_query']['patterns'];
912
+ unset( $clean_request['meta_query']['patterns'] );
913
+ }
914
+
915
+ if ( isset( $clean_request['debug'] ) ) {
916
+ self::$query_parameters['debug'] = $clean_request['debug'];
917
+ self::$search_parameters['debug'] = $clean_request['debug'];
918
+ MLACore::mla_debug_mode( $clean_request['debug'] );
919
+ unset( $clean_request['debug'] );
920
+ }
921
+
922
+ /*
923
+ * We must patch the WHERE clause if there are leading spaces in the meta_value
924
+ */
925
+ if ( isset( $clean_request['mla-metavalue'] ) && ( 0 < strlen( $clean_request['mla-metavalue'] ) ) && ( ' ' == $clean_request['mla-metavalue'][0] ) ) {
926
+ self::$query_parameters['mla-metavalue'] = $clean_request['mla-metavalue'];
927
+ }
928
+
929
+ /*
930
+ * We will handle "Terms Search" in the mla_query_posts_search_filter.
931
+ */
932
+ if ( isset( $clean_request['mla_terms_search'] ) ) {
933
+ self::$search_parameters['mla_terms_search'] = $clean_request['mla_terms_search'];
934
+
935
+ /*
936
+ * The Terms Search overrides any terms-based keyword search for now; too complicated.
937
+ */
938
+ if ( isset( $clean_request['mla_search_fields'] ) ) {
939
+ foreach ( $clean_request['mla_search_fields'] as $index => $field ) {
940
+ if ( 'terms' == $field ) {
941
+ unset ( $clean_request['mla_search_fields'][ $index ] );
942
+ }
943
+ }
944
+ }
945
+ }
946
+
947
+ /*
948
+ * We will handle keyword search in the mla_query_posts_search_filter.
949
+ */
950
+ if ( isset( $clean_request['s'] ) ) {
951
+ self::$search_parameters['s'] = $clean_request['s'];
952
+ 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' ) );
953
+ self::$search_parameters['mla_search_connector'] = $clean_request['mla_search_connector'];
954
+ self::$search_parameters['sentence'] = isset( $clean_request['sentence'] );
955
+ self::$search_parameters['exact'] = isset( $clean_request['exact'] );
956
+
957
+ if ( in_array( 'alt-text', self::$search_parameters['mla_search_fields'] ) ) {
958
+ self::$query_parameters['use_alt_text_view'] = true;
959
+ }
960
+
961
+ if ( in_array( 'terms', self::$search_parameters['mla_search_fields'] ) ) {
962
+ self::$search_parameters['mla_search_taxonomies'] = MLACore::mla_supported_taxonomies( 'term-search' );
963
+ }
964
+
965
+ unset( $clean_request['s'] );
966
+ unset( $clean_request['mla_search_connector'] );
967
+ unset( $clean_request['mla_search_fields'] );
968
+ unset( $clean_request['sentence'] );
969
+ unset( $clean_request['exact'] );
970
+ }
971
+
972
+ /*
973
+ * We have to handle custom field/post_meta values here
974
+ * because they need a JOIN clause supplied by WP_Query
975
+ */
976
+ if ( 'c_' == substr( $clean_request['orderby'], 0, 2 ) ) {
977
+ $option_value = MLAQuery::mla_custom_field_option_value( $clean_request['orderby'] );
978
+ if ( isset( $option_value['name'] ) ) {
979
+ self::$query_parameters['use_orderby_view'] = true;
980
+ self::$query_parameters['postmeta_key'] = $option_value['name'];
981
+
982
+ if ( isset($clean_request['orderby']) ) {
983
+ unset($clean_request['orderby']);
984
+ }
985
+
986
+ if ( isset($clean_request['order']) ) {
987
+ unset($clean_request['order']);
988
+ }
989
+ }
990
+ } else { // custom field
991
+ switch ( self::$query_parameters['orderby'] ) {
992
+ /*
993
+ * '_wp_attachment_image_alt' is special; it can have NULL values,
994
+ * so we'll handle it in the JOIN and ORDERBY filters
995
+ */
996
+ case '_wp_attachment_image_alt':
997
+ self::$query_parameters['use_orderby_view'] = true;
998
+ self::$query_parameters['postmeta_key'] = '_wp_attachment_image_alt';
999
+
1000
+ if ( isset($clean_request['orderby']) ) {
1001
+ unset($clean_request['orderby']);
1002
+ }
1003
+
1004
+ if ( isset($clean_request['order']) ) {
1005
+ unset($clean_request['order']);
1006
+ }
1007
+
1008
+ break;
1009
+ case '_wp_attached_file':
1010
+ $clean_request['meta_key'] = '_wp_attached_file';
1011
+ $clean_request['orderby'] = 'meta_value';
1012
+ $clean_request['order'] = self::$query_parameters['order'];
1013
+ break;
1014
+ } // switch $orderby
1015
+ }
1016
+
1017
+ /*
1018
+ * Ignore incoming paged value; use offset and count instead
1019
+ */
1020
+ if ( ( (int) $count ) > 0 ) {
1021
+ $clean_request['offset'] = $offset;
1022
+ $clean_request['posts_per_page'] = $count;
1023
+ } elseif ( ( (int) $count ) == -1 ) {
1024
+ $clean_request['posts_per_page'] = $count;
1025
+ }
1026
+
1027
+ /*
1028
+ * ['mla_filter_term'] - filter by taxonomy
1029
+ *
1030
+ * cat = 0 is "All Categories", i.e., no filtering
1031
+ * cat = -1 is "No Categories"
1032
+ */
1033
+ if ( isset( $clean_request['mla_filter_term'] ) ) {
1034
+ if ( $clean_request['mla_filter_term'] != 0 ) {
1035
+ $tax_filter = MLACore::mla_taxonomy_support('', 'filter');
1036
+ if ( $clean_request['mla_filter_term'] == -1 ) {
1037
+ $term_list = get_terms( $tax_filter, array(
1038
+ 'fields' => 'ids',
1039
+ 'hide_empty' => false
1040
+ ) );
1041
+ $clean_request['tax_query'] = array(
1042
+ array(
1043
+ 'taxonomy' => $tax_filter,
1044
+ 'field' => 'id',
1045
+ 'terms' => $term_list,
1046
+ 'operator' => 'NOT IN'
1047
+ )
1048
+ );
1049
+ } else { // mla_filter_term == -1
1050
+ $clean_request['tax_query'] = array(
1051
+ array(
1052
+ 'taxonomy' => $tax_filter,
1053
+ 'field' => 'id',
1054
+ 'terms' => array(
1055
+ (int) $clean_request['mla_filter_term']
1056
+ ),
1057
+ 'include_children' => ( 'checked' == MLACore::mla_get_option( MLACore::MLA_TAXONOMY_FILTER_INCLUDE_CHILDREN ) )
1058
+ )
1059
+ );
1060
+ } // mla_filter_term != -1
1061
+ } // mla_filter_term != 0
1062
+
1063
+ unset( $clean_request['mla_filter_term'] );
1064
+ } // isset mla_filter_term
1065
+
1066
+ if ( isset( $clean_request['mla-tax'] ) && isset( $clean_request['mla-term'] )) {
1067
+ $clean_request['tax_query'] = array(
1068
+ array(
1069
+ 'taxonomy' => $clean_request['mla-tax'],
1070
+ 'field' => 'slug',
1071
+ 'terms' => $clean_request['mla-term'],
1072
+ 'include_children' => false
1073
+ )
1074
+ );
1075
+
1076
+ unset( $clean_request['mla-tax'] );
1077
+ unset( $clean_request['mla-term'] );
1078
+ } // isset mla_tax
1079
+
1080
+ if ( isset( $clean_request['mla-metakey'] ) && isset( $clean_request['mla-metavalue'] ) ) {
1081
+ $clean_request['meta_key'] = $clean_request['mla-metakey'];
1082
+ $clean_request['meta_value'] = $clean_request['mla-metavalue'];
1083
+
1084
+ unset( $clean_request['mla-metakey'] );
1085
+ unset( $clean_request['mla-metavalue'] );
1086
+ } // isset mla_tax
1087
+
1088
+ return $clean_request;
1089
+ }
1090
+
1091
+ /**
1092
+ * Add filters, run query, remove filters
1093
+ *
1094
+ * @since 0.30
1095
+ *
1096
+ * @param array query parameters from web page, usually found in $_REQUEST
1097
+ *
1098
+ * @return object WP_Query object with query results
1099
+ */
1100
+ private static function _execute_list_table_query( $request ) {
1101
+ global $wpdb;
1102
+
1103
+ /*
1104
+ * ALT Text searches, custom field Table Views and custom field sorts are
1105
+ * special; we have to use an SQL VIEW to build an intermediate table and
1106
+ * modify the JOIN to include posts with no value for the metadata field.
1107
+ */
1108
+ if ( self::$query_parameters['use_alt_text_view'] ) {
1109
+ $alt_text_view_name = self::$mla_alt_text_view;
1110
+ $key_name = '_wp_attachment_image_alt';
1111
+ $table_name = $wpdb->postmeta;
1112
+
1113
+ $result = $wpdb->query(
1114
+ "
1115
+ CREATE OR REPLACE VIEW {$alt_text_view_name} AS
1116
+ SELECT post_id, meta_value
1117
+ FROM {$table_name}
1118
+ WHERE {$table_name}.meta_key = '{$key_name}'
1119
+ "
1120
+ );
1121
+ }
1122
+
1123
+ if ( self::$query_parameters['use_postmeta_view'] ) {
1124
+ $postmeta_view_name = self::$mla_table_view_custom;
1125
+ $key_name = self::$query_parameters['postmeta_key'];
1126
+ $table_name = $wpdb->postmeta;
1127
+
1128
+ $result = $wpdb->query(
1129
+ "
1130
+ CREATE OR REPLACE VIEW {$postmeta_view_name} AS
1131
+ SELECT post_id, meta_value
1132
+ FROM {$table_name}
1133
+ WHERE {$table_name}.meta_key = '{$key_name}'
1134
+ "
1135
+ );
1136
+ }
1137
+
1138
+ if ( self::$query_parameters['use_orderby_view'] ) {
1139
+ $orderby_view_name = self::$mla_orderby_view;
1140
+ $key_name = self::$query_parameters['postmeta_key'];
1141
+ $table_name = $wpdb->postmeta;
1142
+
1143
+ $result = $wpdb->query(
1144
+ "
1145
+ CREATE OR REPLACE VIEW {$orderby_view_name} AS
1146
+ SELECT post_id, meta_value
1147
+ FROM {$table_name}
1148
+ WHERE {$table_name}.meta_key = '{$key_name}'
1149
+ "
1150
+ );
1151
+ }
1152
+
1153
+ add_filter( 'posts_search', 'MLAQuery::mla_query_posts_search_filter', 10, 2 ); // $search, &$this
1154
+ add_filter( 'posts_where', 'MLAQuery::mla_query_posts_where_filter' );
1155
+ add_filter( 'posts_join', 'MLAQuery::mla_query_posts_join_filter' );
1156
+ add_filter( 'posts_groupby', 'MLAQuery::mla_query_posts_groupby_filter' );
1157
+ add_filter( 'posts_orderby', 'MLAQuery::mla_query_posts_orderby_filter' );
1158
+
1159
+ /*
1160
+ * Disable Relevanssi - A Better Search, v3.2 by Mikko Saari
1161
+ * relevanssi_prevent_default_request( $request, $query )
1162
+ * apply_filters('relevanssi_admin_search_ok', $admin_search_ok, $query );
1163
+ */
1164
+ if ( function_exists( 'relevanssi_prevent_default_request' ) ) {
1165
+ add_filter( 'relevanssi_admin_search_ok', 'MLAQuery::mla_query_relevanssi_admin_search_ok_filter' );
1166
+ }
1167
+
1168
+ if ( isset( self::$query_parameters['debug'] ) ) {
1169
+ global $wp_filter;
1170
+ $debug_array = array( 'posts_search' => $wp_filter['posts_search'], 'posts_join' => $wp_filter['posts_join'], 'posts_where' => $wp_filter['posts_where'], 'posts_orderby' => $wp_filter['posts_orderby'] );
1171
+
1172
+ /* translators: 1: DEBUG tag 2: query filter details */
1173
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: _execute_list_table_query $wp_filter = "%2$s".', 'error_log', 'media-library-assistant' ), __( 'DEBUG', 'media-library-assistant' ), var_export( $debug_array, true ) ) );
1174
+
1175
+ add_filter( 'posts_clauses', 'MLAQuery::mla_query_posts_clauses_filter', 0x7FFFFFFF, 1 );
1176
+ add_filter( 'posts_clauses_request', 'MLAQuery::mla_query_posts_clauses_request_filter', 0x7FFFFFFF, 1 );
1177
+ } // debug
1178
+
1179
+ $results = new WP_Query( $request );
1180
+
1181
+ if ( isset( self::$query_parameters['debug'] ) ) {
1182
+ remove_filter( 'posts_clauses', 'MLAQuery::mla_query_posts_clauses_filter', 0x7FFFFFFF );
1183
+ remove_filter( 'posts_clauses_request', 'MLAQuery::mla_query_posts_clauses_request_filter', 0x7FFFFFFF );
1184
+
1185
+ $debug_array = array( 'request' => $request, 'query_parameters' => self::$query_parameters, 'post_count' => $results->post_count, 'found_posts' => $results->found_posts );
1186
+
1187
+ /* translators: 1: DEBUG tag 2: query details */
1188
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: _execute_list_table_query WP_Query = "%2$s".', 'error_log', 'media-library-assistant' ), __( 'DEBUG', 'media-library-assistant' ), var_export( $debug_array, true ) ) );
1189
+ /* translators: 1: DEBUG tag 2: SQL statement */
1190
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: _execute_list_table_query SQL_request = "%2$s".', 'error_log', 'media-library-assistant' ), __( 'DEBUG', 'media-library-assistant' ), var_export( $results->request, true ) ) );
1191
+ } // debug
1192
+
1193
+ if ( function_exists( 'relevanssi_prevent_default_request' ) ) {
1194
+ remove_filter( 'relevanssi_admin_search_ok', 'MLAQuery::mla_query_relevanssi_admin_search_ok_filter' );
1195
+ }
1196
+
1197
+ remove_filter( 'posts_orderby', 'MLAQuery::mla_query_posts_orderby_filter' );
1198
+ remove_filter( 'posts_groupby', 'MLAQuery::mla_query_posts_groupby_filter' );
1199
+ remove_filter( 'posts_join', 'MLAQuery::mla_query_posts_join_filter' );
1200
+ remove_filter( 'posts_where', 'MLAQuery::mla_query_posts_where_filter' );
1201
+ remove_filter( 'posts_search', 'MLAQuery::mla_query_posts_search_filter' );
1202
+
1203
+ if ( self::$query_parameters['use_alt_text_view'] ) {
1204
+ $result = $wpdb->query( "DROP VIEW {$alt_text_view_name}" );
1205
+ }
1206
+
1207
+ if ( self::$query_parameters['use_postmeta_view'] ) {
1208
+ $result = $wpdb->query( "DROP VIEW {$postmeta_view_name}" );
1209
+ }
1210
+
1211
+ if ( self::$query_parameters['use_orderby_view'] ) {
1212
+ $result = $wpdb->query( "DROP VIEW {$orderby_view_name}" );
1213
+ }
1214
+
1215
+ return $results;
1216
+ }
1217
+
1218
+ /**
1219
+ * Detects wildcard searches, i.e., containing an asterisk outside quotes
1220
+ *
1221
+ * Defined as public because it's a callback from array_map().
1222
+ *
1223
+ * @since 2.13
1224
+ *
1225
+ * @param string search string
1226
+ *
1227
+ * @return boolean true if wildcard
1228
+ */
1229
+ private static function _wildcard_search_string( $search_string ) {
1230
+ preg_match_all('/".*?("|$)|((?<=[\t ",+])|^)[^\t ",+]+/', $search_string, $matches);
1231
+
1232
+ if ( is_array( $matches ) ) {
1233
+ foreach ( $matches[0] as $term ) {
1234
+ if ( '"' == substr( $term, 0, 1) ) {
1235
+ continue;
1236
+ }
1237
+
1238
+ if ( false !== strpos( $term, '*' ) ) {
1239
+ return true;
1240
+ }
1241
+ }
1242
+ }
1243
+
1244
+ return false;
1245
+ }
1246
+
1247
+ /**
1248
+ * Replaces a WordPress function deprecated in v3.7
1249
+ *
1250
+ * Defined as public because it's a callback from array_map().
1251
+ *
1252
+ * @since 1.51
1253
+ *
1254
+ * @param string search term before modification
1255
+ *
1256
+ * @return string cleaned up search term
1257
+ */
1258
+ public static function mla_search_terms_tidy( $term ) {
1259
+ return trim( $term, "\"'\n\r " );
1260
+ }
1261
+
1262
+ /**
1263
+ * Isolates keyword match results to word boundaries
1264
+ *
1265
+ * Eliminates matches such as "man" in "woman".
1266
+ *
1267
+ * @since 2.11
1268
+ *
1269
+ * @param string the quoted phrase (without enclosing quotes)
1270
+ * @param string the entire term
1271
+ *
1272
+ * @return boolean $needle is a word match within $haystack
1273
+ */
1274
+ private static function _match_quoted_phrase( $needle, $haystack ) {
1275
+ $haystack = strtolower( html_entity_decode( $haystack ) );
1276
+ $needle = strtolower( html_entity_decode( $needle ) );
1277
+
1278
+ // Escape the PCRE meta-characters
1279
+ $safe_needle = '';
1280
+ for ( $index = 0; $index < strlen( $needle ); $index++ ) {
1281
+ $chr = $needle[ $index ];
1282
+ if ( false !== strpos( '\\^$.[]()?*+{}/', $chr ) ) {
1283
+ $safe_needle .= '\\';
1284
+ }
1285
+ $safe_needle .= $chr;
1286
+ }
1287
+
1288
+ $pattern = '/^' . $safe_needle . '$|^' . $safe_needle . '\s+|\s+' . $safe_needle . '\s+|\s+' . $safe_needle . '$/';
1289
+ $match_count = preg_match_all($pattern, $haystack, $matches);
1290
+ return 0 < $match_count;
1291
+ }
1292
+
1293
+ /**
1294
+ * Adds a keyword search to the WHERE clause, if required
1295
+ *
1296
+ * Defined as public because it's a filter.
1297
+ *
1298
+ * @since 0.60
1299
+ *
1300
+ * @param string query clause before modification
1301
+ * @param object WP_Query object
1302
+ *
1303
+ * @return string query clause after keyword search addition
1304
+ */
1305
+ public static function mla_query_posts_search_filter( $search_string, &$query_object ) {
1306
+ global $wpdb;
1307
+
1308
+ $numeric_clause = '';
1309
+ $search_clause = '';
1310
+ $tax_clause = '';
1311
+ $tax_connector = 'AND';
1312
+ $tax_index = 0;
1313
+
1314
+ /*
1315
+ * Process the Terms Search arguments, if present.
1316
+ */
1317
+ if ( isset( self::$search_parameters['mla_terms_search']['phrases'] ) ) {
1318
+ $terms_search_parameters = self::$search_parameters['mla_terms_search'];
1319
+ $terms = array_map( 'trim', explode( ',', $terms_search_parameters['phrases'] ) );
1320
+ if ( 1 < count( $terms ) ) {
1321
+ $terms_connector = '(';
1322
+ } else {
1323
+ $terms_connector = '';
1324
+ }
1325
+
1326
+ foreach ( $terms as $term ) {
1327
+ preg_match_all('/".*?("|$)|\'.*?(\'|$)|((?<=[\t ",+])|^)[^\t ",+]+/', $term, $matches);
1328
+ $phrases = array_map('MLAQuery::mla_search_terms_tidy', $matches[0]);
1329
+
1330
+ /*
1331
+ * Find the quoted phrases for a word-boundary check
1332
+ */
1333
+ $quoted = array();
1334
+ foreach ( $phrases as $index => $phrase ) {
1335
+ $quoted[ $index ] = ( '"' == $matches[1][$index] ) || ( "'" == $matches[2][$index] );
1336
+ }
1337
+
1338
+ $tax_terms = array();
1339
+ $tax_counts = array();
1340
+ foreach ( $phrases as $index => $phrase ) {
1341
+ if ( isset( $terms_search_parameters['exact'] ) ) {
1342
+ $the_terms = array();
1343
+ foreach( $terms_search_parameters['taxonomies'] as $taxonomy ) {
1344
+ // WordPress encodes special characters, e.g., "&" as HTML entities in term names
1345
+ $the_term = get_term_by( 'name', _wp_specialchars( $phrase ), $taxonomy );
1346
+ if ( false !== $the_term ) {
1347
+ $the_terms[] = $the_term;
1348
+ }
1349
+ }
1350
+ } else {
1351
+ $is_wildcard_search = ( ! $quoted[ $index ] ) && self::_wildcard_search_string( $phrase );
1352
+
1353
+ if ( $is_wildcard_search ) {
1354
+ add_filter( 'terms_clauses', 'MLAQuery::mla_query_terms_clauses_filter', 0x7FFFFFFF, 3 );
1355
+ }
1356
+
1357
+ // WordPress encodes special characters, e.g., "&" as HTML entities in term names
1358
+ $the_terms = get_terms( $terms_search_parameters['taxonomies'], array( 'name__like' => _wp_specialchars( $phrase ), 'fields' => 'all', 'hide_empty' => false ) );
1359
+
1360
+ if ( $is_wildcard_search ) {
1361
+ remove_filter( 'terms_clauses', 'MLAQuery::mla_query_terms_clauses_filter', 0x7FFFFFFF );
1362
+ }
1363
+
1364
+ // Invalid taxonomy will return WP_Error object
1365
+ if ( ! is_array( $the_terms ) ) {
1366
+ $the_terms = array();
1367
+ }
1368
+
1369
+ if ( $quoted[ $index ] ) {
1370
+ foreach ( $the_terms as $term_index => $the_term ) {
1371
+ if ( ! self::_match_quoted_phrase( $phrase, $the_term->name ) ) {
1372
+ unset( $the_terms[ $term_index ]);
1373
+ }
1374
+ }
1375
+ } // quoted phrase
1376
+ } // not exact
1377
+
1378
+ foreach( $the_terms as $the_term ) {
1379
+ $tax_terms[ $the_term->taxonomy ][ $the_term->term_id ] = (integer) $the_term->term_taxonomy_id;
1380
+
1381
+ if ( isset( $tax_counts[ $the_term->taxonomy ][ $the_term->term_id ] ) ) {
1382
+ $tax_counts[ $the_term->taxonomy ][ $the_term->term_id ]++;
1383
+ } else {
1384
+ $tax_counts[ $the_term->taxonomy ][ $the_term->term_id ] = 1;
1385
+ }
1386
+ }
1387
+ } // foreach phrase
1388
+
1389
+ /*
1390
+ * For the AND connector, a taxonomy term must have all of the search terms within it
1391
+ */
1392
+ if ( 'AND' == $terms_search_parameters['radio_phrases'] ) {
1393
+ $search_term_count = count( $phrases );
1394
+ foreach ($tax_terms as $taxonomy => $term_ids ) {
1395
+ foreach ( $term_ids as $term_id => $term_taxonomy_id ) {
1396
+ if ( $search_term_count != $tax_counts[ $taxonomy ][ $term_id ] ) {
1397
+ unset( $term_ids[ $term_id ] );
1398
+ }
1399
+ }
1400
+
1401
+ if ( empty( $term_ids ) ) {
1402
+ unset( $tax_terms[ $taxonomy ] );
1403
+ } else {
1404
+ $tax_terms[ $taxonomy ] = $term_ids;
1405
+ }
1406
+ } // foreach taxonomy
1407
+ } // AND (i.e., All phrases)
1408
+
1409
+ if ( ! empty( $tax_terms ) ) {
1410
+ $inner_connector = '';
1411
+
1412
+ $tax_clause .= $terms_connector;
1413
+ foreach( $tax_terms as $tax_term ) {
1414
+ if ( 'AND' == $terms_search_parameters['radio_terms'] ) {
1415
+ $prefix = 'mlatt' . $tax_index++;
1416
+ } else {
1417
+ $prefix = 'mlatt0';
1418
+ $tax_index = 1; // only one JOIN needed for the "Any Term" case
1419
+ }
1420
+
1421
+ $tax_clause .= sprintf( '%1$s %2$s.term_taxonomy_id IN (%3$s)', $inner_connector, $prefix, implode( ',', $tax_term ) );
1422
+ $inner_connector = ' OR';
1423
+ } // foreach tax_term
1424
+
1425
+ $terms_connector = ' ) ' . $terms_search_parameters['radio_terms'] . ' (';
1426
+ } // tax_terms present
1427
+ } // foreach term
1428
+
1429
+ if ( 1 < count( $terms ) && ! empty( $tax_clause ) ) {
1430
+ $tax_clause .= ')';
1431
+ }
1432
+
1433
+ if ( empty( $tax_clause ) ) {
1434
+ $tax_clause = '1=0';
1435
+ } else {
1436
+ self::$search_parameters['tax_terms_count'] = $tax_index;
1437
+ };
1438
+ } // isset mla_terms_search
1439
+
1440
+ /*
1441
+ * Process the keyword search argument, if present.
1442
+ */
1443
+ if ( ! empty( self::$search_parameters['s'] ) ) {
1444
+ // WordPress v3.7 says: there are no line breaks in <input /> fields
1445
+ $keyword_string = stripslashes( str_replace( array( "\r", "\n" ), '', self::$search_parameters['s'] ) );
1446
+ $is_wildcard_search = self::_wildcard_search_string( $keyword_string );
1447
+
1448
+ if ( $is_wildcard_search || self::$search_parameters['sentence'] || self::$search_parameters['exact'] ) {
1449
+ $keyword_array = array( $keyword_string );
1450
+ } else {
1451
+ // v3.6.1 was '/".*?("|$)|((?<=[\r\n\t ",+])|^)[^\r\n\t ",+]+/'
1452
+ preg_match_all('/".*?("|$)|((?<=[\t ",+])|^)[^\t ",+]+/', $keyword_string, $matches);
1453
+ $keyword_array = array_map( 'MLAQuery::mla_search_terms_tidy', $matches[0]);
1454
+ $numeric_array = array_filter( $keyword_array, 'is_numeric' );
1455
+
1456
+ /*
1457
+ * If all the "keywords" are numeric, interpret it/them as the ID(s) of a specific attachment
1458
+ * or the ID(s) of a parent post/page; add it/them to the regular text-based search.
1459
+ */
1460
+ if ( count( $keyword_array ) && count( $keyword_array ) == count( $numeric_array ) ) {
1461
+ $numeric_array = implode( ',', $numeric_array );
1462
+ $numeric_clause = '( ( ' . $wpdb->posts . '.ID IN (' . $numeric_array . ') ) OR ( ' . $wpdb->posts . '.post_parent IN (' . $numeric_array . ') ) ) OR ';
1463
+
1464
+ }
1465
+ }
1466
+
1467
+ $fields = self::$search_parameters['mla_search_fields'];
1468
+ $allow_terms_search = in_array( 'terms', $fields ) && ( ! $is_wildcard_search );
1469
+ $percent = self::$search_parameters['exact'] ? '' : '%';
1470
+ $connector = '';
1471
+
1472
+ if ( empty( $fields ) ) {
1473
+ $search_clause = '1=0';
1474
+ } else {
1475
+ $tax_terms = array();
1476
+ $tax_counts = array();
1477
+ foreach ( $keyword_array as $term ) {
1478
+ if ( $is_wildcard_search ) {
1479
+ /*
1480
+ * Escape any % in the source string
1481
+ */
1482
+ if ( self::$wp_4dot0_plus ) {
1483
+ $sql_term = $wpdb->esc_like( $term );
1484
+ $sql_term = $wpdb->prepare( '%s', $sql_term );
1485
+ } else {
1486
+ $sql_term = "'" . esc_sql( like_escape( $term ) ) . "'";
1487
+ }
1488
+
1489
+ /*
1490
+ * Convert wildcard * to SQL %
1491
+ */
1492
+ $sql_term = str_replace( '*', '%', $sql_term );
1493
+ } else {
1494
+ if ( self::$wp_4dot0_plus ) {
1495
+ $sql_term = $percent . $wpdb->esc_like( $term ) . $percent;
1496
+ $sql_term = $wpdb->prepare( '%s', $sql_term );
1497
+ } else {
1498
+ $sql_term = "'" . $percent . esc_sql( like_escape( $term ) ) . $percent . "'";
1499
+ }
1500
+ }
1501
+
1502
+ $inner_connector = '';
1503
+ $inner_clause = '';
1504
+
1505
+ if ( in_array( 'content', $fields ) ) {
1506
+ $inner_clause .= "{$inner_connector}({$wpdb->posts}.post_content LIKE {$sql_term})";
1507
+ $inner_connector = ' OR ';
1508
+ }
1509
+
1510
+ if ( in_array( 'title', $fields ) ) {
1511
+ $inner_clause .= "{$inner_connector}({$wpdb->posts}.post_title LIKE {$sql_term})";
1512
+ $inner_connector = ' OR ';
1513
+ }
1514
+
1515
+ if ( in_array( 'excerpt', $fields ) ) {
1516
+ $inner_clause .= "{$inner_connector}({$wpdb->posts}.post_excerpt LIKE {$sql_term})";
1517
+ $inner_connector = ' OR ';
1518
+ }
1519
+
1520
+ if ( in_array( 'alt-text', $fields ) ) {
1521
+ $view_name = self::$mla_alt_text_view;
1522
+ $inner_clause .= "{$inner_connector}({$view_name}.meta_value LIKE {$sql_term})";
1523
+ $inner_connector = ' OR ';
1524
+ }
1525
+
1526
+ if ( in_array( 'name', $fields ) ) {
1527
+ $inner_clause .= "{$inner_connector}({$wpdb->posts}.post_name LIKE {$sql_term})";
1528
+ }
1529
+
1530
+ $inner_clause = apply_filters( 'mla_list_table_search_filter_inner_clause', $inner_clause, $inner_connector, $wpdb->posts, $sql_term );
1531
+
1532
+ if ( ! empty($inner_clause) ) {
1533
+ $search_clause .= "{$connector}({$inner_clause})";
1534
+ $connector = ' ' . self::$search_parameters['mla_search_connector'] . ' ';
1535
+ }
1536
+
1537
+ /*
1538
+ * Convert search term text to term_taxonomy_id value(s),
1539
+ * separated by taxonomy.
1540
+ */
1541
+ if ( $allow_terms_search ) {
1542
+ // WordPress encodes special characters, e.g., "&" as HTML entities in term names
1543
+ $the_terms = get_terms( self::$search_parameters['mla_search_taxonomies'], array( 'name__like' => _wp_specialchars( $term ), 'fields' => 'all', 'hide_empty' => false ) );
1544
+ // Invalid taxonomy will return WP_Error object
1545
+ if ( ! is_array( $the_terms ) ) {
1546
+ $the_terms = array();
1547
+ }
1548
+
1549
+ foreach( $the_terms as $the_term ) {
1550
+ $tax_terms[ $the_term->taxonomy ][ $the_term->term_id ] = (integer) $the_term->term_taxonomy_id;
1551
+
1552
+ if ( isset( $tax_counts[ $the_term->taxonomy ][ $the_term->term_id ] ) ) {
1553
+ $tax_counts[ $the_term->taxonomy ][ $the_term->term_id ]++;
1554
+ } else {
1555
+ $tax_counts[ $the_term->taxonomy ][ $the_term->term_id ] = 1;
1556
+ }
1557
+ }
1558
+ } // in_array terms
1559
+ } // foreach term
1560
+
1561
+ if ( $allow_terms_search ) {
1562
+ /*
1563
+ * For the AND connector, a taxonomy term must have all of the search terms within it
1564
+ */
1565
+ if ( 'AND' == self::$search_parameters['mla_search_connector'] ) {
1566
+ $search_term_count = count( $keyword_array );
1567
+ foreach ($tax_terms as $taxonomy => $term_ids ) {
1568
+ foreach ( $term_ids as $term_id => $term_taxonomy_id ) {
1569
+ if ( $search_term_count != $tax_counts[ $taxonomy ][ $term_id ] ) {
1570
+ unset( $term_ids[ $term_id ] );
1571
+ }
1572
+ }
1573
+
1574
+ if ( empty( $term_ids ) ) {
1575
+ unset( $tax_terms[ $taxonomy ] );
1576
+ } else {
1577
+ $tax_terms[ $taxonomy ] = $term_ids;
1578
+ }
1579
+ } // foreach taxonomy
1580
+ } // AND connector
1581
+
1582
+ if ( empty( $tax_terms ) ) {
1583
+ /*
1584
+ * If "Terms" is the only field and no terms are present,
1585
+ * the search must fail.
1586
+ */
1587
+ if ( ( 1 == count( $fields ) ) && ( 'terms' == array_shift( $fields ) ) ) {
1588
+ $tax_clause = '1=0';
1589
+ }
1590
+ } else {
1591
+ $tax_index = 0;
1592
+ $inner_connector = '';
1593
+
1594
+ foreach( $tax_terms as $tax_term ) {
1595
+ $prefix = 'mlatt' . $tax_index++;
1596
+ $tax_clause .= sprintf( '%1$s %2$s.term_taxonomy_id IN (%3$s)', $inner_connector, $prefix, implode( ',', $tax_term ) );
1597
+ $inner_connector = ' OR';
1598
+ } // foreach tax_term
1599
+
1600
+ self::$search_parameters['tax_terms_count'] = $tax_index;
1601
+ $tax_connector = 'OR';
1602
+ } // tax_terms present
1603
+ } // terms in fields
1604
+ } // fields not empty
1605
+ } // isset 's'
1606
+
1607
+ if ( ! empty( $tax_clause ) && ! empty( $search_clause ) ) {
1608
+ $tax_clause = " {$tax_connector} ({$tax_clause} )";
1609
+ }
1610
+
1611
+ if ( ! empty( $search_clause ) || ! empty( $tax_clause ) ) {
1612
+ $search_clause = " AND ( {$numeric_clause}{$search_clause}{$tax_clause} ) ";
1613
+
1614
+ if ( ! is_user_logged_in() ) {
1615
+ $search_clause .= " AND ( {$wpdb->posts}.post_password = '' ) ";
1616
+ }
1617
+ }
1618
+
1619
+ if ( 'none' != self::$search_parameters['debug'] ) {
1620
+ $debug_array['search_string'] = $search_string;
1621
+ $debug_array['search_parameters'] = self::$search_parameters;
1622
+ $debug_array['search_clause'] = $search_clause;
1623
+
1624
+ if ( 'shortcode' == self::$search_parameters['debug'] ) {
1625
+ MLACore::mla_debug_add( '<strong>mla_debug posts_search filter</strong> = ' . var_export( $debug_array, true ) );
1626
+ } else {
1627
+ /* translators: 1: DEBUG tag 2: search filter details */
1628
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: mla_query_posts_search_filter = "%2$s".', 'error_log', 'media-library-assistant' ), __( 'DEBUG', 'media-library-assistant' ), var_export( $debug_array, true ) ) );
1629
+ }
1630
+ } // debug
1631
+
1632
+ return $search_clause;
1633
+ }
1634
+
1635
+ /**
1636
+ * Adds/modifies the WHERE clause for meta values, LIKE patterns and detached items
1637
+ *
1638
+ * Modeled after _edit_attachments_query_helper in wp-admin/post.php.
1639
+ * Defined as public because it's a filter.
1640
+ *
1641
+ * @since 0.1
1642
+ *
1643
+ * @param string query clause before modification
1644
+ *
1645
+ * @return string query clause after modification
1646
+ */
1647
+ public static function mla_query_posts_where_filter( $where_clause ) {
1648
+ global $wpdb;
1649
+
1650
+ if ( isset( self::$query_parameters['debug'] ) ) {
1651
+ $debug_array = array( 'where_string' => $where_clause );
1652
+ }
1653
+
1654
+ /*
1655
+ * WordPress filters meta_value thru trim() - which we must reverse
1656
+ */
1657
+ if ( isset( self::$query_parameters['mla-metavalue'] ) ) {
1658
+ if ( is_array( self::$query_parameters['mla-metavalue'] ) ) {
1659
+ foreach ( self::$query_parameters['mla-metavalue'] as $pattern => $replacement ) {
1660
+ $where_clause = preg_replace( '/(^.*meta_value AS CHAR\) = \')(' . $pattern . '[^\']*)/m', '${1}' . $replacement, $where_clause );
1661
+ }
1662
+ } else {
1663
+ $where_clause = preg_replace( '/(^.*meta_value AS CHAR\) = \')([^\']*)/m', '${1}' . self::$query_parameters['mla-metavalue'], $where_clause );
1664
+ }
1665
+ }
1666
+
1667
+ /*
1668
+ * Matching a NULL meta value
1669
+ */
1670
+ if ( array_key_exists( 'postmeta_value', self::$query_parameters ) && NULL == self::$query_parameters['postmeta_value'] ) {
1671
+ $where_clause .= ' AND ' . self::$mla_table_view_custom . '.meta_value IS NULL';
1672
+ }
1673
+
1674
+ /*
1675
+ * WordPress modifies the LIKE clause - which we must reverse
1676
+ */
1677
+ if ( isset( self::$query_parameters['patterns'] ) ) {
1678
+ foreach ( self::$query_parameters['patterns'] as $pattern ) {
1679
+ $pattern = str_replace( '_', '\\\\_', $pattern );
1680
+ $match_clause = '%' . str_replace( '%', '\\\\%', $pattern ) . '%';
1681
+ $where_clause = str_replace( "LIKE '{$match_clause}'", "LIKE '{$pattern}'", $where_clause );
1682
+ }
1683
+ }
1684
+
1685
+ /*
1686
+ * Unattached items require some help
1687
+ */
1688
+ if ( isset( self::$query_parameters['detached'] ) ) {
1689
+ if ( '1' == self::$query_parameters['detached'] ) {
1690
+ $where_clause .= sprintf( ' AND %1$s.post_parent < 1', $wpdb->posts );
1691
+ } elseif ( '0' == self::$query_parameters['detached'] ) {
1692
+ $where_clause .= sprintf( ' AND %1$s.post_parent > 0', $wpdb->posts );
1693
+ }
1694
+ }
1695
+
1696
+ if ( isset( self::$query_parameters['debug'] ) ) {
1697
+ $debug_array['where_clause'] = $where_clause;
1698
+
1699
+ /* translators: 1: DEBUG tag 2: where filter details */
1700
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: mla_query_posts_where_filter = "%2$s".', 'error_log', 'media-library-assistant' ), __( 'DEBUG', 'media-library-assistant' ), var_export( $debug_array, true ) ) );
1701
+ } // debug
1702
+
1703
+ return $where_clause;
1704
+ }
1705
+
1706
+ /**
1707
+ * Adds a JOIN clause, if required, to handle sorting/searching on custom fields or ALT Text
1708
+ *
1709
+ * Defined as public because it's a filter.
1710
+ *
1711
+ * @since 0.30
1712
+ *
1713
+ * @param string query clause before modification
1714
+ *
1715
+ * @return string query clause after "LEFT JOIN view ON post_id" item modification
1716
+ */
1717
+ public static function mla_query_posts_join_filter( $join_clause ) {
1718
+ global $wpdb;
1719
+
1720
+ if ( isset( self::$query_parameters['debug'] ) ) {
1721
+ $debug_array = array( 'join_string' => $join_clause );
1722
+ }
1723
+
1724
+ /*
1725
+ * ALT Text searches, custom field Table Views and custom field sorts are
1726
+ * special; we have to use an SQL VIEW to build an intermediate table and
1727
+ * modify the JOIN to include posts with no value for this metadata field.
1728
+ */
1729
+ if ( self::$query_parameters['use_alt_text_view'] ) {
1730
+ $join_clause .= sprintf( ' LEFT JOIN %1$s ON (%2$s.ID = %1$s.post_id)', self::$mla_alt_text_view, $wpdb->posts );
1731
+ }
1732
+
1733
+ if ( self::$query_parameters['use_postmeta_view'] ) {
1734
+ $join_clause .= sprintf( ' LEFT JOIN %1$s ON (%2$s.ID = %1$s.post_id)', self::$mla_table_view_custom, $wpdb->posts );
1735
+ }
1736
+
1737
+ if ( self::$query_parameters['use_orderby_view'] ) {
1738
+ $join_clause .= sprintf( ' LEFT JOIN %1$s ON (%2$s.ID = %1$s.post_id)', self::$mla_orderby_view, $wpdb->posts );
1739
+ }
1740
+
1741
+ /*
1742
+ * custom field sorts are special; we have to use an SQL VIEW to
1743
+ * build an intermediate table and modify the JOIN to include posts with
1744
+ * no value for this metadata field.
1745
+ */
1746
+ if ( isset( self::$query_parameters['orderby'] ) ) {
1747
+ if ( ( 'c_' == substr( self::$query_parameters['orderby'], 0, 2 ) ) || ( '_wp_attachment_image_alt' == self::$query_parameters['orderby'] ) ) {
1748
+ $orderby = self::$mla_orderby_view . '.meta_value';
1749
+ }
1750
+ }
1751
+
1752
+ if ( isset( self::$search_parameters['tax_terms_count'] ) ) {
1753
+ $tax_index = 0;
1754
+ $tax_clause = '';
1755
+
1756
+ while ( $tax_index < self::$search_parameters['tax_terms_count'] ) {
1757
+ $prefix = 'mlatt' . $tax_index++;
1758
+ $tax_clause .= sprintf( ' LEFT JOIN %1$s AS %2$s ON (%3$s.ID = %2$s.object_id)', $wpdb->term_relationships, $prefix, $wpdb->posts );
1759
+ }
1760
+
1761
+ $join_clause .= $tax_clause;
1762
+ }
1763
+
1764
+ if ( isset( self::$query_parameters['debug'] ) ) {
1765
+ $debug_array['join_clause'] = $join_clause;
1766
+
1767
+ /* translators: 1: DEBUG tag 2: join filter details */
1768
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: mla_query_posts_join_filter = "%2$s".', 'error_log', 'media-library-assistant' ), __( 'DEBUG', 'media-library-assistant' ), var_export( $debug_array, true ) ) );
1769
+ } // debug
1770
+
1771
+ return $join_clause;
1772
+ }
1773
+
1774
+ /**
1775
+ * Adds a GROUPBY clause, if required
1776
+ *
1777
+ * Taxonomy text queries and postmeta queries can return multiple results for the same ID.
1778
+ * Defined as public because it's a filter.
1779
+ *
1780
+ * @since 1.90
1781
+ *
1782
+ * @param string query clause before modification
1783
+ *
1784
+ * @return string updated query clause
1785
+ */
1786
+ public static function mla_query_posts_groupby_filter( $groupby_clause ) {
1787
+ global $wpdb;
1788
+
1789
+ if ( ( ! empty( self::$query_parameters['use_postmeta_view'] ) ) || ( ! empty( self::$query_parameters['use_alt_text_view'] ) ) || ( ! empty( self::$query_parameters['use_orderby_view'] ) ) || isset( self::$search_parameters['tax_terms_count'] ) ) {
1790
+ $groupby_clause = "{$wpdb->posts}.ID";
1791
+ }
1792
+
1793
+ return $groupby_clause;
1794
+ }
1795
+
1796
+ /**
1797
+ * Adds a ORDERBY clause, if required
1798
+ *
1799
+ * Expands the range of sort options because the logic in WP_Query is limited.
1800
+ * Defined as public because it's a filter.
1801
+ *
1802
+ * @since 0.30
1803
+ *
1804
+ * @param string query clause before modification
1805
+ *
1806
+ * @return string updated query clause
1807
+ */
1808
+ public static function mla_query_posts_orderby_filter( $orderby_clause ) {
1809
+ global $wpdb;
1810
+
1811
+ if ( isset( self::$query_parameters['debug'] ) ) {
1812
+ $debug_array = array( 'orderby_string' => $orderby_clause );
1813
+ }
1814
+
1815
+ if ( isset( self::$query_parameters['orderby'] ) ) {
1816
+ if ( 'c_' == substr( self::$query_parameters['orderby'], 0, 2 ) ) {
1817
+ $orderby = self::$mla_orderby_view . '.meta_value';
1818
+ } /* custom field sort */ else {
1819
+ switch ( self::$query_parameters['orderby'] ) {
1820
+ case 'none':
1821
+ $orderby = '';
1822
+ $orderby_clause = '';
1823
+ break;
1824
+ /*
1825
+ * post__in is passed from Media Manager Modal Window
1826
+ */
1827
+ case 'post__in':
1828
+ return $orderby_clause;
1829
+ /*
1830
+ * There are two columns defined that end up sorting on post_title,
1831
+ * so we can't use the database column to identify the column but
1832
+ * we actually sort on the database column.
1833
+ */
1834
+ case 'title_name':
1835
+ $orderby = $wpdb->posts . '.post_title';
1836
+ break;
1837
+ /*
1838
+ * The _wp_attached_file meta data value is present for all attachments, and the
1839
+ * sorting on the meta data value is handled by WP_Query
1840
+ */
1841
+ case '_wp_attached_file':
1842
+ $orderby = '';
1843
+ break;
1844
+ /*
1845
+ * The _wp_attachment_image_alt value is only present for images, so we have to
1846
+ * use the view we prepared to get attachments with no meta data value
1847
+ */
1848
+ case '_wp_attachment_image_alt':
1849
+ $orderby = self::$mla_orderby_view . '.meta_value';
1850
+ break;
1851
+ default:
1852
+ $orderby = $wpdb->posts . '.' . self::$query_parameters['orderby'];
1853
+ } // $query_parameters['orderby']
1854
+ }
1855
+
1856
+ if ( ! empty( $orderby ) ) {
1857
+ $orderby_clause = $orderby . ' ' . self::$query_parameters['order'];
1858
+ }
1859
+ } // isset
1860
+
1861
+ if ( isset( self::$query_parameters['debug'] ) ) {
1862
+ $debug_array['orderby_clause'] = $orderby_clause;
1863
+
1864
+ /* translators: 1: DEBUG tag 2: orderby details details */
1865
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: mla_query_posts_orderby_filter = "%2$s".', 'error_log', 'media-library-assistant' ), __( 'DEBUG', 'media-library-assistant' ), var_export( $debug_array, true ) ) );
1866
+ } // debug
1867
+
1868
+ return $orderby_clause;
1869
+ }
1870
+
1871
+ /**
1872
+ * Disable Relevanssi - A Better Search, v3.2 by Mikko Saari
1873
+ * Defined as public because it's a filter.
1874
+ *
1875
+ * @since 1.80
1876
+ *
1877
+ * @param boolean Default setting
1878
+ *
1879
+ * @return boolean Updated setting
1880
+ */
1881
+ public static function mla_query_relevanssi_admin_search_ok_filter( $admin_search_ok ) {
1882
+ return false;
1883
+ }
1884
+
1885
+ /**
1886
+ * Filters all clauses for get_terms queries
1887
+ *
1888
+ * Defined as public because it's a filter.
1889
+ *
1890
+ * @since 2.13
1891
+ *
1892
+ * @param array $pieces Terms query SQL clauses.
1893
+ * @param array $taxonomies An array of taxonomies.
1894
+ * @param array $args An array of terms query arguments.
1895
+ */
1896
+ public static function mla_query_terms_clauses_filter( $pieces, $taxonomies, $args ) {
1897
+ global $wpdb;
1898
+
1899
+ if ( empty( $args['name__like'] ) ) {
1900
+ return $pieces;
1901
+ }
1902
+
1903
+ $term = $args['name__like'];
1904
+
1905
+ /*
1906
+ * Escape any % in the source string
1907
+ */
1908
+ if ( self::$wp_4dot0_plus ) {
1909
+ $sql_term = $wpdb->esc_like( $term );
1910
+ $sql_term = $wpdb->prepare( '%s', $sql_term );
1911
+ } else {
1912
+ $sql_term = "'" . esc_sql( like_escape( $term ) ) . "'";
1913
+ }
1914
+
1915
+ /*
1916
+ * Convert wildcard * to SQL %
1917
+ */
1918
+ $sql_term = str_replace( '*', '%', $sql_term );
1919
+
1920
+ /*
1921
+ * Replace the LIKE pattern in the WHERE clause
1922
+ */
1923
+ $match_clause = '%' . str_replace( '%', '\\\\%', $term ) . '%';
1924
+ $pieces['where'] = str_replace( "LIKE '{$match_clause}'", "LIKE {$sql_term}", $pieces['where'] );
1925
+
1926
+ return $pieces;
1927
+ }
1928
+
1929
+ /**
1930
+ * Filters all clauses for shortcode queries, pre caching plugins
1931
+ *
1932
+ * This is for debug purposes only.
1933
+ * Defined as public because it's a filter.
1934
+ *
1935
+ * @since 1.80
1936
+ *
1937
+ * @param array query clauses before modification
1938
+ *
1939
+ * @return array query clauses after modification (none)
1940
+ */
1941
+ public static function mla_query_posts_clauses_filter( $pieces ) {
1942
+ /* translators: 1: DEBUG tag 2: SQL clauses */
1943
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: mla_query_posts_clauses_filter = "%2$s".', 'error_log', 'media-library-assistant' ), __( 'DEBUG', 'media-library-assistant' ), var_export( $pieces, true ) ) );
1944
+
1945
+ return $pieces;
1946
+ }
1947
+
1948
+ /**
1949
+ * Filters all clauses for shortcode queries, post caching plugins
1950
+ *
1951
+ * This is for debug purposes only.
1952
+ * Defined as public because it's a filter.
1953
+ *
1954
+ * @since 1.80
1955
+ *
1956
+ * @param array query clauses before modification
1957
+ *
1958
+ * @return array query clauses after modification (none)
1959
+ */
1960
+ public static function mla_query_posts_clauses_request_filter( $pieces ) {
1961
+ /* translators: 1: DEBUG tag 2: SQL clauses */
1962
+ MLACore::mla_debug_add( sprintf( _x( '%1$s: mla_query_posts_clauses_request_filter = "%2$s".', 'error_log', 'media-library-assistant' ), __( 'DEBUG', 'media-library-assistant' ), var_export( $pieces, true ) ) );
1963
+
1964
+ return $pieces;
1965
+ }
1966
+ } // class MLAQuery
1967
+ ?>
includes/class-mla-data-references.php ADDED
@@ -0,0 +1,901 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Database query support for "where-used" reporting
4
+ *
5
+ * @package Media Library Assistant
6
+ * @since 2.20
7
+ */
8
+
9
+ /**
10
+ * Class MLA (Media Library Assistant) Query provides database query support
11
+ * for "where-used" reporting needs
12
+ *
13
+ * @package Media Library Assistant
14
+ * @since 2.20
15
+ */
16
+ class MLAReferences {
17
+ /**
18
+ * Find Featured Image and inserted image/link references to an attachment
19
+ *
20
+ * Called from MLAQuery::mla_fetch_attachment_references, which handles conditional
21
+ * loading of this file.
22
+ *
23
+ * @since 0.1
24
+ *
25
+ * @param int post ID of attachment
26
+ * @param int post ID of attachment's parent, if any
27
+ * @param boolean True to compute references, false to return empty values
28
+ *
29
+ * @return array Reference information; see $references array comments
30
+ */
31
+ public static function mla_fetch_attachment_references_handler( $ID, $parent, $add_references = true ) {
32
+ global $wpdb;
33
+ static $save_id = -1, $references, $inserted_in_option = NULL;
34
+
35
+ if ( $save_id == $ID ) {
36
+ return $references;
37
+ } elseif ( $ID == -1 ) {
38
+ $save_id = -1;
39
+ return NULL;
40
+ }
41
+
42
+ /*
43
+ * inserted_option 'enabled', 'base' or 'disabled'
44
+ * tested_reference true if any of the four where-used types was processed
45
+ * found_reference true if any where-used array is not empty()
46
+ * found_parent true if $parent matches a where-used post ID
47
+ * is_unattached true if $parent is zero (0)
48
+ * base_file relative path and name of the uploaded file, e.g., 2012/04/image.jpg
49
+ * path path to the file, relative to the "uploads/" directory, e.g., 2012/04/
50
+ * file The name portion of the base file, e.g., image.jpg
51
+ * files base file and any other image size files. Array key is path and file name.
52
+ * Non-image file value is a string containing file name without path
53
+ * Image file value is an array with file name, width and height
54
+ * features Array of objects with the post_type and post_title of each post
55
+ * that has the attachment as a "Featured Image"
56
+ * inserts Array of specific files (i.e., sizes) found in one or more posts/pages
57
+ * as an image (<img>) or link (<a href>). The array key is the path and file name.
58
+ * The array value is an array with the ID, post_type and post_title of each reference
59
+ * mla_galleries Array of objects with the post_type and post_title of each post
60
+ * that was returned by an [mla_gallery] shortcode
61
+ * galleries Array of objects with the post_type and post_title of each post
62
+ * that was returned by a [gallery] shortcode
63
+ * parent_type 'post' or 'page' or the custom post type of the attachment's parent
64
+ * parent_status 'publish', 'private', 'future', 'pending', 'draft'
65
+ * parent_title post_title of the attachment's parent
66
+ * parent_errors UNATTACHED, ORPHAN, BAD/INVALID PARENT
67
+ */
68
+ $references = array(
69
+ 'inserted_option' => '',
70
+ 'tested_reference' => false,
71
+ 'found_reference' => false,
72
+ 'found_parent' => false,
73
+ 'is_unattached' => ( ( (int) $parent ) === 0 ),
74
+ 'base_file' => '',
75
+ 'path' => '',
76
+ 'file' => '',
77
+ 'files' => array(),
78
+ 'features' => array(),
79
+ 'inserts' => array(),
80
+ 'mla_galleries' => array(),
81
+ 'galleries' => array(),
82
+ 'parent_type' => '',
83
+ 'parent_status' => '',
84
+ 'parent_title' => '',
85
+ 'parent_errors' => ''
86
+ );
87
+
88
+ if ( ! $add_references ) {
89
+ return $references;
90
+ }
91
+
92
+ /*
93
+ * Fill in Parent data
94
+ */
95
+ $parent_data = MLAQuery::mla_fetch_attachment_parent_data( $parent );
96
+ if ( isset( $parent_data['parent_type'] ) ) {
97
+ $references['parent_type'] = $parent_data['parent_type'];
98
+ }
99
+
100
+ if ( isset( $parent_data['parent_status'] ) ) {
101
+ $references['parent_status'] = $parent_data['parent_status'];
102
+ }
103
+
104
+ if ( isset( $parent_data['parent_title'] ) ) {
105
+ $references['parent_title'] = $parent_data['parent_title'];
106
+ }
107
+
108
+ $references['base_file'] = get_post_meta( $ID, '_wp_attached_file', true );
109
+ $pathinfo = pathinfo($references['base_file']);
110
+ $references['file'] = $pathinfo['basename'];
111
+ if ( ( ! isset( $pathinfo['dirname'] ) ) || '.' == $pathinfo['dirname'] ) {
112
+ $references['path'] = '/';
113
+ } else {
114
+ $references['path'] = $pathinfo['dirname'] . '/';
115
+ }
116
+
117
+ $attachment_metadata = get_post_meta( $ID, '_wp_attachment_metadata', true );
118
+ $sizes = isset( $attachment_metadata['sizes'] ) ? $attachment_metadata['sizes'] : NULL;
119
+ if ( is_array( $sizes ) ) {
120
+ // Using the name as the array key ensures each name is added only once
121
+ foreach ( $sizes as $size => $size_info ) {
122
+ $size_info['size'] = $size;
123
+ $references['files'][ $references['path'] . $size_info['file'] ] = $size_info;
124
+ }
125
+ }
126
+
127
+ $base_type = wp_check_filetype( $references['file'] );
128
+ $base_reference = array(
129
+ 'file' => $references['file'],
130
+ 'width' => isset( $attachment_metadata['width'] ) ? $attachment_metadata['width'] : 0,
131
+ 'height' => isset( $attachment_metadata['height'] ) ? $attachment_metadata['height'] : 0,
132
+ 'mime_type' => isset( $base_type['type'] ) ? $base_type['type'] : 'unknown',
133
+ 'size' => 'full',
134
+ );
135
+
136
+ $references['files'][ $references['base_file'] ] = $base_reference;
137
+
138
+ /*
139
+ * Process the where-used settings option
140
+ */
141
+ if ('checked' == MLACore::mla_get_option( MLACore::MLA_EXCLUDE_REVISIONS ) ) {
142
+ $exclude_revisions = "(post_type <> 'revision') AND ";
143
+ } else {
144
+ $exclude_revisions = '';
145
+ }
146
+
147
+ /*
148
+ * Accumulate reference test types, e.g., 0 = no tests, 4 = all tests
149
+ */
150
+ $reference_tests = 0;
151
+
152
+ /*
153
+ * Look for the "Featured Image(s)", if enabled
154
+ */
155
+ if ( MLACore::$process_featured_in ) {
156
+ $reference_tests++;
157
+ $features = $wpdb->get_results(
158
+ "
159
+ SELECT post_id
160
+ FROM {$wpdb->postmeta}
161
+ WHERE meta_key = '_thumbnail_id' AND meta_value = {$ID}
162
+ "
163
+ );
164
+
165
+ if ( ! empty( $features ) ) {
166
+ foreach ( $features as $feature ) {
167
+ $feature_results = $wpdb->get_results(
168
+ "
169
+ SELECT ID, post_type, post_status, post_title
170
+ FROM {$wpdb->posts}
171
+ WHERE {$exclude_revisions}(ID = {$feature->post_id})
172
+ "
173
+ );
174
+
175
+ if ( ! empty( $feature_results ) ) {
176
+ $references['found_reference'] = true;
177
+ $references['features'][ $feature->post_id ] = $feature_results[0];
178
+
179
+ if ( $feature->post_id == $parent ) {
180
+ $references['found_parent'] = true;
181
+ }
182
+ } // ! empty
183
+ } // foreach $feature
184
+ }
185
+ } // $process_featured_in
186
+
187
+ /*
188
+ * Look for item(s) inserted in post_content
189
+ */
190
+ $references['inserted_option'] = $inserted_in_option;
191
+ if ( MLACore::$process_inserted_in ) {
192
+ $reference_tests++;
193
+
194
+ if ( NULL == $inserted_in_option ) {
195
+ $inserted_in_option = MLACore::mla_get_option( MLACore::MLA_INSERTED_IN_TUNING );
196
+ $references['inserted_option'] = $inserted_in_option;
197
+ }
198
+
199
+ if ( 'base' == $inserted_in_option ) {
200
+ $query_parameters = array();
201
+ $query = array();
202
+ $query[] = "SELECT ID, post_type, post_status, post_title, CONVERT(`post_content` USING utf8 ) AS POST_CONTENT FROM {$wpdb->posts} WHERE {$exclude_revisions} ( %s=%s";
203
+ $query_parameters[] = '1'; // for empty file name array
204
+ $query_parameters[] = '0'; // for empty file name array
205
+
206
+ foreach ( $references['files'] as $file => $file_data ) {
207
+ if ( empty( $file ) ) {
208
+ continue;
209
+ }
210
+
211
+ $query[] = 'OR ( POST_CONTENT LIKE %s)';
212
+
213
+ if ( MLAQuery::$wp_4dot0_plus ) {
214
+ $query_parameters[] = '%' . $wpdb->esc_like( $file ) . '%';
215
+ } else {
216
+ $query_parameters[] = '%' . like_escape( $file ) . '%';
217
+ }
218
+ }
219
+
220
+ $query[] = ')';
221
+ $query = join(' ', $query);
222
+
223
+ $inserts = $wpdb->get_results(
224
+ $wpdb->prepare( $query, $query_parameters )
225
+ );
226
+
227
+ if ( ! empty( $inserts ) ) {
228
+ $references['found_reference'] = true;
229
+ $references['inserts'][ $pathinfo['filename'] ] = $inserts;
230
+
231
+ foreach ( $inserts as $index => $insert ) {
232
+ unset( $references['inserts'][ $pathinfo['filename'] ][ $index ]->POST_CONTENT );
233
+ if ( $insert->ID == $parent ) {
234
+ $references['found_parent'] = true;
235
+ }
236
+ } // foreach $insert
237
+ } // ! empty
238
+ } else { // process base names
239
+ foreach ( $references['files'] as $file => $file_data ) {
240
+ if ( empty( $file ) ) {
241
+ continue;
242
+ }
243
+
244
+ if ( MLAQuery::$wp_4dot0_plus ) {
245
+ $like = $wpdb->esc_like( $file );
246
+ } else {
247
+ $like = like_escape( $file );
248
+ }
249
+
250
+ $inserts = $wpdb->get_results(
251
+ $wpdb->prepare(
252
+ "SELECT ID, post_type, post_status, post_title FROM {$wpdb->posts}
253
+ WHERE {$exclude_revisions}(CONVERT(`post_content` USING utf8 ) LIKE %s)", "%{$like}%"
254
+ )
255
+ );
256
+
257
+ if ( ! empty( $inserts ) ) {
258
+ $references['found_reference'] = true;
259
+ $references['inserts'][ $file_data['file'] ] = $inserts;
260
+
261
+ foreach ( $inserts as $insert ) {
262
+ if ( $insert->ID == $parent ) {
263
+ $references['found_parent'] = true;
264
+ }
265
+ } // foreach $insert
266
+ } // ! empty
267
+ } // foreach $file
268
+ } // process intermediate sizes
269
+ } // $process_inserted_in
270
+
271
+ /*
272
+ * Look for [mla_gallery] references
273
+ */
274
+ if ( MLACore::$process_mla_gallery_in ) {
275
+ $reference_tests++;
276
+ if ( self::_build_mla_galleries( MLACore::MLA_MLA_GALLERY_IN_TUNING, self::$mla_galleries, '[mla_gallery', $exclude_revisions ) ) {
277
+ $galleries = self::_search_mla_galleries( self::$mla_galleries, $ID );
278
+ if ( ! empty( $galleries ) ) {
279
+ $references['found_reference'] = true;
280
+ $references['mla_galleries'] = $galleries;
281
+
282
+ foreach ( $galleries as $post_id => $gallery ) {
283
+ if ( $post_id == $parent ) {
284
+ $references['found_parent'] = true;
285
+ }
286
+ } // foreach $gallery
287
+ } else { // ! empty
288
+ $references['mla_galleries'] = array();
289
+ }
290
+ }
291
+ } // $process_mla_gallery_in
292
+
293
+ /*
294
+ * Look for [gallery] references
295
+ */
296
+ if ( MLACore::$process_gallery_in ) {
297
+ $reference_tests++;
298
+ if ( self::_build_mla_galleries( MLACore::MLA_GALLERY_IN_TUNING, self::$galleries, '[gallery', $exclude_revisions ) ) {
299
+ $galleries = self::_search_mla_galleries( self::$galleries, $ID );
300
+ if ( ! empty( $galleries ) ) {
301
+ $references['found_reference'] = true;
302
+ $references['galleries'] = $galleries;
303
+
304
+ foreach ( $galleries as $post_id => $gallery ) {
305
+ if ( $post_id == $parent ) {
306
+ $references['found_parent'] = true;
307
+ }
308
+ } // foreach $gallery
309
+ } else { // ! empty
310
+ $references['galleries'] = array();
311
+ }
312
+ }
313
+ } // $process_gallery_in
314
+
315
+ /*
316
+ * Evaluate and summarize reference tests
317
+ */
318
+ $errors = '';
319
+ if ( 0 == $reference_tests ) {
320
+ $references['tested_reference'] = false;
321
+ $errors .= '(' . __( 'NO REFERENCE TESTS', 'media-library-assistant' ) . ')';
322
+ } else {
323
+ $references['tested_reference'] = true;
324
+ $suffix = ( 4 == $reference_tests ) ? '' : '?';
325
+
326
+ if ( !$references['found_reference'] ) {
327
+ $errors .= '(' . sprintf( __( 'ORPHAN', 'media-library-assistant' ) . '%1$s) ', $suffix );
328
+ }
329
+
330
+ if ( !$references['found_parent'] && ! empty( $references['parent_title'] ) ) {
331
+ $errors .= '(' . sprintf( __( 'UNUSED', 'media-library-assistant' ) . '%1$s) ', $suffix );
332
+ }
333
+ }
334
+
335
+ if ( $references['is_unattached'] ) {
336
+ $errors .= '(' . __( 'UNATTACHED', 'media-library-assistant' ) . ')';
337
+ } elseif ( empty( $references['parent_title'] ) ) {
338
+ $errors .= '(' . __( 'INVALID PARENT', 'media-library-assistant' ) . ')';
339
+ }
340
+
341
+ $references['parent_errors'] = trim( $errors );
342
+
343
+ $save_id = $ID;
344
+ $references = apply_filters( 'mla_fetch_attachment_references', $references, $ID, $parent );
345
+ return $references;
346
+ }
347
+
348
+ /**
349
+ * Add Featured Image and inserted image/link references to an array of attachments
350
+ *
351
+ * Called from MLAQuery::mla_fetch_attachment_references, which handles conditional
352
+ * loading of this file.
353
+ *
354
+ * @since 1.94
355
+ *
356
+ * @param array WP_Post objects, passed by reference
357
+ *
358
+ * @return void updates WP_Post objects with new mla_references property
359
+ */
360
+ public static function mla_attachment_array_fetch_references_handler( &$attachments ) {
361
+ global $wpdb;
362
+
363
+ /*
364
+ * See element definitions above
365
+ */
366
+ $initial_references = array(
367
+ 'inserted_option' => '',
368
+ 'tested_reference' => false,
369
+ 'found_reference' => false,
370
+ 'found_parent' => false,
371
+ 'is_unattached' => true,
372
+ 'base_file' => '',
373
+ 'path' => '',
374
+ 'file' => '',
375
+ 'files' => array(),
376
+ 'features' => array(),
377
+ 'inserts' => array(),
378
+ 'mla_galleries' => array(),
379
+ 'galleries' => array(),
380
+ 'parent_type' => '',
381
+ 'parent_status' => '',
382
+ 'parent_title' => '',
383
+ 'parent_errors' => ''
384
+ );
385
+
386
+ $inserted_in_option = MLACore::mla_get_option( MLACore::MLA_INSERTED_IN_TUNING );
387
+ $initial_references['inserted_option'] = $inserted_in_option;
388
+
389
+ /*
390
+ * Make sure there's work to do; otherwise initialize the attachment data and return
391
+ */
392
+ if ( false == ( MLACore::$process_featured_in || MLACore::$process_inserted_in || MLACore::$process_gallery_in || MLACore::$process_mla_gallery_in ) ) {
393
+ foreach ( $attachments as $attachment_index => $attachment ) {
394
+ $attachments[ $attachment_index ]->mla_references = $initial_references;
395
+ }
396
+
397
+ return;
398
+ }
399
+
400
+ /*
401
+ * Collect the raw data for where-used analysis
402
+ */
403
+ $attachment_ids = array();
404
+ $files = array();
405
+ foreach ( $attachments as $index => $attachment ) {
406
+ $attachment_ids[ $index ] = $attachment->ID;
407
+ $references = array( 'files' => array() );
408
+ if ( isset( $attachment->mla_wp_attached_file ) ) {
409
+ $references['base_file'] = $attachment->mla_wp_attached_file;
410
+ } else {
411
+ $references['base_file'] = '';
412
+ }
413
+
414
+ $pathinfo = pathinfo($references['base_file']);
415
+ if ( ( ! isset( $pathinfo['dirname'] ) ) || '.' == $pathinfo['dirname'] ) {
416
+ $references['path'] = '/';
417
+ } else {
418
+ $references['path'] = $pathinfo['dirname'] . '/';
419
+ }
420
+
421
+ $references['file'] = $pathinfo['basename'];
422
+
423
+ if ( isset( $attachment->mla_wp_attachment_metadata ) ) {
424
+ $attachment_metadata = $attachment->mla_wp_attachment_metadata;
425
+ } else {
426
+ $attachment_metadata = '';
427
+ }
428
+
429
+ $sizes = isset( $attachment_metadata['sizes'] ) ? $attachment_metadata['sizes'] : NULL;
430
+ if ( ! empty( $sizes ) && is_array( $sizes ) ) {
431
+ /* Using the path and name as the array key ensures each name is added only once */
432
+ foreach ( $sizes as $size => $size_info ) {
433
+ $size_info['size'] = $size;
434
+ $references['files'][ $references['path'] . $size_info['file'] ] = $size_info;
435
+ }
436
+ }
437
+
438
+ if ( ! empty( $references['base_file'] ) ) {
439
+ $base_type = wp_check_filetype( $references['file'] );
440
+ $base_reference = array(
441
+ 'file' => $references['file'],
442
+ 'width' => isset( $attachment_metadata['width'] ) ? $attachment_metadata['width'] : 0,
443
+ 'height' => isset( $attachment_metadata['height'] ) ? $attachment_metadata['height'] : 0,
444
+ 'mime_type' => ( isset( $base_type['type'] ) && false !== $base_type['type'] ) ? $base_type['type'] : 'unknown',
445
+ 'size' => 'full',
446
+ );
447
+
448
+ $references['files'][ $references['base_file'] ] = $base_reference;
449
+ }
450
+
451
+ $files[ $index ] = $references;
452
+ }
453
+
454
+ if ('checked' == MLACore::mla_get_option( MLACore::MLA_EXCLUDE_REVISIONS ) ) {
455
+ $exclude_revisions = " AND (p.post_type <> 'revision')";
456
+ } else {
457
+ $exclude_revisions = '';
458
+ }
459
+
460
+ $features = array();
461
+ if ( MLACore::$process_featured_in && ! empty( $attachment_ids ) ) {
462
+ $attachment_ids = implode( ',', $attachment_ids );
463
+ $results = $wpdb->get_results(
464
+ "
465
+ SELECT m.meta_value, p.ID, p.post_type, p.post_status, p.post_title
466
+ FROM {$wpdb->postmeta} AS m INNER JOIN {$wpdb->posts} AS p ON m.post_id = p.ID
467
+ WHERE ( m.meta_key = '_thumbnail_id' )
468
+ AND ( m.meta_value IN ( {$attachment_ids} ) ){$exclude_revisions}
469
+ "
470
+ );
471
+
472
+ foreach ( $results as $result ) {
473
+ $features[ $result->meta_value ][ $result->ID ] = (object) array( 'ID' => $result->ID, 'post_title' => $result->post_title, 'post_type' => $result->post_type, 'post_status' => $result->post_status );
474
+ }
475
+ } // $process_featured_in
476
+
477
+ if ( ! empty( $exclude_revisions ) ) {
478
+ $exclude_revisions = " AND (post_type <> 'revision')";
479
+ }
480
+
481
+ if ( MLACore::$process_inserted_in ) {
482
+ $query_parameters = array();
483
+ $query = array();
484
+ $query[] = "SELECT ID, post_type, post_status, post_title, CONVERT(`post_content` USING utf8 ) AS POST_CONTENT FROM {$wpdb->posts} WHERE ( %s=%s";
485
+ // for empty file name array
486
+ $query_parameters[] = '1';
487
+ $query_parameters[] = '0';
488
+
489
+ foreach ( $files as $file ) {
490
+ foreach ( $file['files'] as $base_name => $file_data ) {
491
+ $query[] = 'OR ( POST_CONTENT LIKE %s)';
492
+
493
+ if ( MLAQuery::$wp_4dot0_plus ) {
494
+ $query_parameters[] = '%' . $wpdb->esc_like( $base_name ) . '%';
495
+ } else {
496
+ $query_parameters[] = '%' . like_escape( $base_name ) . '%';
497
+ }
498
+ }
499
+ }
500
+
501
+ $query[] = "){$exclude_revisions}";
502
+ $query = join(' ', $query);
503
+
504
+ $results = $wpdb->get_results(
505
+ $wpdb->prepare( $query, $query_parameters )
506
+ );
507
+
508
+ /*
509
+ * Match each post with inserts back to the attachments
510
+ */
511
+ $inserts = array();
512
+ if ( ! empty( $results ) ) {
513
+ foreach ( $files as $index => $file ) {
514
+ foreach ( $file['files'] as $base_name => $file_data ) {
515
+ foreach ( $results as $result ) {
516
+ if ( false !== strpos( $result->POST_CONTENT, $base_name ) ) {
517
+ $insert = clone $result;
518
+ unset( $insert->POST_CONTENT);
519
+ $insert->file_name = $file_data['file'];
520
+ $inserts[ $index ][] = $insert;
521
+ }
522
+ } // foreach post with inserts
523
+ } // foreach base_name
524
+ } // foreach attachment
525
+ } // results
526
+ } // process_inserted_in
527
+
528
+ if ( MLACore::$process_mla_gallery_in ) {
529
+ $have_mla_galleries = self::_build_mla_galleries( MLACore::MLA_MLA_GALLERY_IN_TUNING, self::$mla_galleries, '[mla_gallery', $exclude_revisions );
530
+ } else {
531
+ $have_mla_galleries = false;
532
+ }
533
+
534
+ if ( MLACore::$process_gallery_in ) {
535
+ $have_galleries = self::_build_mla_galleries( MLACore::MLA_GALLERY_IN_TUNING, self::$galleries, '[gallery', $exclude_revisions );
536
+ } else {
537
+ $have_mla_galleries = false;
538
+ }
539
+
540
+ foreach ( $attachments as $attachment_index => $attachment ) {
541
+ $references = array_merge( $initial_references, $files[ $attachment_index ] );
542
+
543
+ /*
544
+ * Fill in Parent data
545
+ */
546
+ if ( ( (int) $attachment->post_parent ) === 0 ) {
547
+ $references['is_unattached'] = true;
548
+ } else {
549
+ $references['is_unattached'] = false;
550
+
551
+ if ( isset( $attachment->parent_type ) ) {
552
+ $references['parent_type'] = $attachment->parent_type;
553
+ }
554
+
555
+ if ( isset( $attachment->parent_status ) ) {
556
+ $references['parent_status'] = $attachment->parent_status;
557
+ }
558
+
559
+ if ( isset( $attachment->parent_title ) ) {
560
+ $references['parent_title'] = $attachment->parent_title;
561
+ }
562
+ }
563
+
564
+ /*
565
+ * Accumulate reference test types, e.g., 0 = no tests, 4 = all tests
566
+ */
567
+ $reference_tests = 0;
568
+
569
+ /*
570
+ * Look for the "Featured Image(s)", if enabled
571
+ */
572
+ if ( MLACore::$process_featured_in ) {
573
+ $reference_tests++;
574
+ if ( isset( $features[ $attachment->ID ] ) ) {
575
+ foreach ( $features[ $attachment->ID ] as $id => $feature ) {
576
+ $references['found_reference'] = true;
577
+ $references['features'][ $id ] = $feature;
578
+
579
+ if ( $id == $attachment->post_parent ) {
580
+ $references['found_parent'] = true;
581
+ }
582
+ } // foreach $feature
583
+ }
584
+ } // $process_featured_in
585
+
586
+ /*
587
+ * Look for item(s) inserted in post_content
588
+ */
589
+ if ( MLACore::$process_inserted_in ) {
590
+ $reference_tests++;
591
+
592
+ if ( isset( $inserts[ $attachment_index ] ) ) {
593
+ $references['found_reference'] = true;
594
+ foreach( $inserts[ $attachment_index ] as $insert ) {
595
+ $ref_insert = clone $insert;
596
+ unset( $ref_insert->file_name );
597
+
598
+ if ( 'base' == $inserted_in_option ) {
599
+ $ref_key = pathinfo( $references['base_file'], PATHINFO_FILENAME );
600
+ } else {
601
+ $ref_key = $insert->file_name;
602
+ }
603
+
604
+ $references['inserts'][ $ref_key ][ $insert->ID ] = $ref_insert;
605
+ if ( $insert->ID == $attachment->post_parent ) {
606
+ $references['found_parent'] = true;
607
+ }
608
+ } // each insert
609
+ } else {
610
+ $references['inserts'] = array();
611
+ }
612
+ } // $process_inserted_in
613
+
614
+ /*
615
+ * Look for [mla_gallery] references
616
+ */
617
+ if ( MLACore::$process_mla_gallery_in ) {
618
+ $reference_tests++;
619
+ if ( self::_build_mla_galleries( MLACore::MLA_MLA_GALLERY_IN_TUNING, self::$mla_galleries, '[mla_gallery', $exclude_revisions ) ) {
620
+ $galleries = self::_search_mla_galleries( self::$mla_galleries, $attachment->ID );
621
+ if ( ! empty( $galleries ) ) {
622
+ $references['found_reference'] = true;
623
+ $references['mla_galleries'] = $galleries;
624
+
625
+ foreach ( $galleries as $post_id => $gallery ) {
626
+ if ( $post_id == $attachment->post_parent ) {
627
+ $references['found_parent'] = true;
628
+ }
629
+ } // foreach $gallery
630
+ } else { // ! empty
631
+ $references['mla_galleries'] = array();
632
+ }
633
+ }
634
+ } // $process_mla_gallery_in
635
+
636
+ /*
637
+ * Look for [gallery] references
638
+ */
639
+ if ( MLACore::$process_gallery_in ) {
640
+ $reference_tests++;
641
+ if ( self::_build_mla_galleries( MLACore::MLA_GALLERY_IN_TUNING, self::$galleries, '[gallery', $exclude_revisions ) ) {
642
+ $galleries = self::_search_mla_galleries( self::$galleries, $attachment->ID );
643
+ if ( ! empty( $galleries ) ) {
644
+ $references['found_reference'] = true;
645
+ $references['galleries'] = $galleries;
646
+
647
+ foreach ( $galleries as $post_id => $gallery ) {
648
+ if ( $post_id == $attachment->post_parent ) {
649
+ $references['found_parent'] = true;
650
+ }
651
+ } // foreach $gallery
652
+ } else { // ! empty
653
+ $references['galleries'] = array();
654
+ }
655
+ }
656
+ } // $process_gallery_in
657
+
658
+ /*
659
+ * Evaluate and summarize reference tests
660
+ */
661
+ $errors = '';
662
+ if ( 0 == $reference_tests ) {
663
+ $references['tested_reference'] = false;
664
+ $errors .= '(' . __( 'NO REFERENCE TESTS', 'media-library-assistant' ) . ')';
665
+ } else {
666
+ $references['tested_reference'] = true;
667
+ $suffix = ( 4 == $reference_tests ) ? '' : '?';
668
+
669
+ if ( !$references['found_reference'] ) {
670
+ $errors .= '(' . sprintf( __( 'ORPHAN', 'media-library-assistant' ) . '%1$s) ', $suffix );
671
+ }
672
+
673
+ if ( !$references['found_parent'] && ! empty( $references['parent_title'] ) ) {
674
+ $errors .= '(' . sprintf( __( 'UNUSED', 'media-library-assistant' ) . '%1$s) ', $suffix );
675
+ }
676
+ }
677
+
678
+ if ( $references['is_unattached'] ) {
679
+ $errors .= '(' . __( 'UNATTACHED', 'media-library-assistant' ) . ')';
680
+ } elseif ( empty( $references['parent_title'] ) ) {
681
+ $errors .= '(' . __( 'INVALID PARENT', 'media-library-assistant' ) . ')';
682
+ }
683
+
684
+ $references['parent_errors'] = trim( $errors );
685
+ $attachments[ $attachment_index ]->mla_references = apply_filters( 'mla_fetch_attachment_references', $references, $attachment->ID, (int) $attachment->post_parent );
686
+ } // foreach $attachment
687
+ }
688
+
689
+ /**
690
+ * Objects containing [gallery] shortcodes
691
+ *
692
+ * This array contains all of the objects containing one or more [gallery] shortcodes
693
+ * and array(s) of which attachments each [gallery] contains. The arrays are built once
694
+ * each page load and cached for subsequent calls.
695
+ *
696
+ * The outer array is keyed by post_id. It contains an associative array with:
697
+ * ['parent_title'] post_title of the gallery parent,
698
+ * ['parent_type'] 'post' or 'page' or the custom post_type of the gallery parent,
699
+ * ['parent_status'] 'publish', 'private', 'future', 'pending', 'draft'
700
+ * ['results'] array ( ID => ID ) of attachments appearing in ANY of the parent's galleries.
701
+ * ['galleries'] array of [gallery] entries numbered from one (1), containing:
702
+ * galleries[X]['query'] contains a string with the arguments of the [gallery],
703
+ * galleries[X]['results'] contains an array ( ID ) of post_ids for the objects in the gallery.
704
+ *
705
+ * @since 0.70
706
+ *
707
+ * @var array
708
+ */
709
+ private static $galleries = NULL;
710
+
711
+ /**
712
+ * Objects containing [mla_gallery] shortcodes
713
+ *
714
+ * This array contains all of the objects containing one or more [mla_gallery] shortcodes
715
+ * and array(s) of which attachments each [mla_gallery] contains. The arrays are built once
716
+ * each page load and cached for subsequent calls.
717
+ *
718
+ * @since 0.70
719
+ *
720
+ * @var array
721
+ */
722
+ private static $mla_galleries = NULL;
723
+
724
+ /**
725
+ * Invalidates the $mla_galleries or $galleries array and cached values
726
+ *
727
+ * Called from MLAQuery::mla_flush_mla_galleries, which handles conditional
728
+ * loading of this file.
729
+ *
730
+ * @since 1.00
731
+ *
732
+ * @param string name of the gallery's cache/option variable
733
+ *
734
+ * @return void
735
+ */
736
+ public static function mla_flush_mla_galleries_handler( $option_name ) {
737
+ switch ( $option_name ) {
738
+ case MLACore::MLA_GALLERY_IN_TUNING:
739
+ self::$galleries = NULL;
740
+ break;
741
+ case MLACore::MLA_MLA_GALLERY_IN_TUNING:
742
+ self::$mla_galleries = NULL;
743
+ break;
744
+ default:
745
+ // ignore everything else
746
+ } // switch
747
+ }
748
+
749
+ /**
750
+ * Builds the $mla_galleries or $galleries array
751
+ *
752
+ * @since 0.70
753
+ *
754
+ * @param string name of the gallery's cache/option variable
755
+ * @param array by reference to the private static galleries array variable
756
+ * @param string the shortcode to be searched for and processed
757
+ * @param boolean true to exclude revisions from the search
758
+ *
759
+ * @return boolean true if the galleries array is not empty
760
+ */
761
+ private static function _build_mla_galleries( $option_name, &$galleries_array, $shortcode, $exclude_revisions ) {
762
+ global $wpdb, $post;
763
+
764
+ if ( is_array( $galleries_array ) ) {
765
+ if ( ! empty( $galleries_array ) ) {
766
+ return true;
767
+ } else {
768
+ return false;
769
+ }
770
+ }
771
+
772
+ $option_value = MLACore::mla_get_option( $option_name );
773
+ if ( 'disabled' == $option_value ) {
774
+ return false;
775
+ } elseif ( 'cached' == $option_value ) {
776
+ $galleries_array = get_transient( MLA_OPTION_PREFIX . 't_' . $option_name );
777
+ if ( is_array( $galleries_array ) ) {
778
+ if ( ! empty( $galleries_array ) ) {
779
+ return true;
780
+ } else {
781
+ return false;
782
+ }
783
+ } else {
784
+ $galleries_array = NULL;
785
+ }
786
+ } // cached
787
+
788
+ /*
789
+ * The MLAShortcodes class is only loaded when needed.
790
+ */
791
+ if ( !class_exists( 'MLAShortcodes' ) ) {
792
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-shortcodes.php' );
793
+ }
794
+
795
+ /*
796
+ * $galleries_array is null, so build the array
797
+ */
798
+ $galleries_array = array();
799
+
800
+ if ( $exclude_revisions ) {
801
+ $exclude_revisions = "(post_type <> 'revision') AND ";
802
+ } else {
803
+ $exclude_revisions = '';
804
+ }
805
+
806
+ if ( MLAQuery::$wp_4dot0_plus ) {
807
+ $like = $wpdb->esc_like( $shortcode );
808
+ } else {
809
+ $like = like_escape( $shortcode );
810
+ }
811
+
812
+ $results = $wpdb->get_results(
813
+ $wpdb->prepare(
814
+ "
815
+ SELECT ID, post_type, post_status, post_title, post_content
816
+ FROM {$wpdb->posts}
817
+ WHERE {$exclude_revisions}(
818
+ CONVERT(`post_content` USING utf8 )
819
+ LIKE %s)
820
+ ", "%{$like}%"
821
+ )
822
+ );
823
+
824
+ if ( empty( $results ) ) {
825
+ return false;
826
+ }
827
+
828
+ foreach ( $results as $result ) {
829
+ $count = preg_match_all( "/\\{$shortcode}([^\\]]*)\\]/", $result->post_content, $matches, PREG_PATTERN_ORDER );
830
+ if ( $count ) {
831
+ $result_id = $result->ID;
832
+ $galleries_array[ $result_id ]['parent_title'] = $result->post_title;
833
+ $galleries_array[ $result_id ]['parent_type'] = $result->post_type;
834
+ $galleries_array[ $result_id ]['parent_status'] = $result->post_status;
835
+ $galleries_array[ $result_id ]['results'] = array();
836
+ $galleries_array[ $result_id ]['galleries'] = array();
837
+ $instance = 0;
838
+
839
+ foreach ( $matches[1] as $index => $match ) {
840
+ /*
841
+ * Filter out shortcodes that are not an exact match
842
+ */
843
+ if ( empty( $match ) || ( ' ' == substr( $match, 0, 1 ) ) ) {
844
+ $instance++;
845
+ /*
846
+ * Remove trailing "/" from XHTML-style self-closing shortcodes
847
+ */
848
+ $galleries_array[ $result_id ]['galleries'][ $instance ]['query'] = trim( rtrim( $matches[1][$index], '/' ) );
849
+ $galleries_array[ $result_id ]['galleries'][ $instance ]['results'] = array();
850
+ $post = $result; // set global variable for mla_gallery_shortcode
851
+ $attachments = MLAShortcodes::mla_get_shortcode_attachments( $result_id, $galleries_array[ $result_id ]['galleries'][ $instance ]['query'] . ' cache_results=false update_post_meta_cache=false update_post_term_cache=false where_used_query=this-is-a-where-used-query' );
852
+
853
+ if ( is_string( $attachments ) ) {
854
+ /* translators: 1: post_type, 2: post_title, 3: post ID, 4: query string, 5: error message */
855
+ trigger_error( htmlentities( sprintf( __( '(%1$s) %2$s (ID %3$d) query "%4$s" failed, returning "%5$s"', 'media-library-assistant' ), $result->post_type, $result->post_title, $result->ID, $galleries_array[ $result_id ]['galleries'][ $instance ]['query'], $attachments) ), E_USER_WARNING );
856
+ } elseif ( ! empty( $attachments ) ) {
857
+ foreach ( $attachments as $attachment ) {
858
+ $galleries_array[ $result_id ]['results'][ $attachment->ID ] = $attachment->ID;
859
+ $galleries_array[ $result_id ]['galleries'][ $instance ]['results'][] = $attachment->ID;
860
+ }
861
+ }
862
+ } // exact match
863
+ } // foreach $match
864
+ } // if $count
865
+ } // foreach $result
866
+
867
+ /*
868
+ * Maybe cache the results
869
+ */
870
+ if ( 'cached' == $option_value ) {
871
+ set_transient( MLA_OPTION_PREFIX . 't_' . $option_name, $galleries_array, 900 ); // fifteen minutes
872
+ }
873
+
874
+ return true;
875
+ }
876
+
877
+ /**
878
+ * Search the $mla_galleries or $galleries array
879
+ *
880
+ * @since 0.70
881
+ *
882
+ * @param array by reference to the private static galleries array variable
883
+ * @param int the attachment ID to be searched for and processed
884
+ *
885
+ * @return array All posts/pages with one or more galleries that include the attachment.
886
+ * The array key is the parent_post ID; each entry contains post_title and post_type.
887
+ */
888
+ private static function _search_mla_galleries( &$galleries_array, $attachment_id ) {
889
+ $gallery_refs = array();
890
+ if ( ! empty( $galleries_array ) ) {
891
+ foreach ( $galleries_array as $parent_id => $gallery ) {
892
+ if ( in_array( $attachment_id, $gallery['results'] ) ) {
893
+ $gallery_refs[ $parent_id ] = array ( 'ID' => $parent_id, 'post_title' => $gallery['parent_title'], 'post_type' => $gallery['parent_type'], 'post_status' => $gallery['parent_status'] );
894
+ }
895
+ } // foreach gallery
896
+ } // ! empty
897
+
898
+ return $gallery_refs;
899
+ }
900
+ } // class MLAReferences
901
+ ?>
includes/class-mla-data-source.php ADDED
@@ -0,0 +1,811 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Manages access to data sources for custom field mapping and shortcode execution
4
+ *
5
+ * @package Media Library Assistant
6
+ * @since 2.20
7
+ */
8
+
9
+ /**
10
+ * Class MLA (Media Library Assistant) Data Source manages data sources for
11
+ * custom field mapping and shortcode execution
12
+ *
13
+ * @package Media Library Assistant
14
+ * @since 2.20
15
+ */
16
+ class MLAData_Source {
17
+ /**
18
+ * Array of Data Source names for custom field mapping
19
+ *
20
+ * @since 2.20
21
+ *
22
+ * @var array
23
+ */
24
+ public static $custom_field_data_sources = array (
25
+ 'post_id',
26
+ 'post_author',
27
+ 'post_date',
28
+ 'post_date_gmt',
29
+ 'post_content',
30
+ 'post_title',
31
+ 'post_excerpt',
32
+ 'post_status',
33
+ 'comment_status',
34
+ 'ping_status',
35
+ 'post_name',
36
+ 'post_modified',
37
+ 'post_modified_gmt',
38
+ 'post_content_filtered',
39
+ 'parent',
40
+ 'post_parent',
41
+ 'guid',
42
+ 'menu_order',
43
+ 'mime_type',
44
+ 'post_mime_type',
45
+ 'comment_count',
46
+ 'alt_text',
47
+
48
+ 'absolute_path',
49
+ 'absolute_file_name',
50
+ 'base_file',
51
+ 'path',
52
+ 'file_name',
53
+ 'name_only',
54
+ 'extension',
55
+ 'file_size',
56
+ 'upload_date',
57
+
58
+ 'dimensions',
59
+ 'pixels',
60
+ 'width',
61
+ 'height',
62
+ 'orientation',
63
+ 'hwstring_small',
64
+ 'size_keys',
65
+ 'size_names',
66
+ 'size_bytes',
67
+ 'size_pixels',
68
+ 'size_dimensions',
69
+ 'size_name[size]',
70
+ 'size_bytes[size]',
71
+ 'size_pixels[size]',
72
+ 'size_dimensions[size]',
73
+
74
+ 'parent_date',
75
+ 'parent_type',
76
+ 'parent_title',
77
+ 'parent_issues',
78
+ 'reference_issues',
79
+ 'featured_in',
80
+ 'featured_in_title',
81
+ 'inserted_in',
82
+ 'inserted_in_title',
83
+ 'gallery_in',
84
+ 'gallery_in_title',
85
+ 'mla_gallery_in',
86
+ 'mla_gallery_in_title',
87
+
88
+ 'aperture',
89
+ 'credit',
90
+ 'camera',
91
+ 'caption',
92
+ 'created_timestamp',
93
+ 'copyright',
94
+ 'focal_length',
95
+ 'iso',
96
+ 'shutter_speed',
97
+ 'title'
98
+ );
99
+
100
+ /**
101
+ * Identify custom field mapping data source
102
+ *
103
+ * Determines whether a name matches any of the element-level data source dropdown options, i.e.,
104
+ * excludes "template:" and "meta:" values.
105
+ *
106
+ * @since 2.20
107
+ *
108
+ * @param string candidate data source name
109
+ *
110
+ * @return boolean true if candidate name matches a data source
111
+ */
112
+ public static function mla_is_data_source( $candidate_name ) {
113
+ static $intermediate_sizes = NULL;
114
+
115
+ /*
116
+ * The [size] elements are expanded with available image sizes;
117
+ * convert valid sizes back to the generic [size] value to match the list.
118
+ */
119
+ $match_count = preg_match( '/(.+)\[(.+)\]/', $candidate_name, $matches );
120
+ if ( 1 == $match_count ) {
121
+ if ( NULL === $intermediate_sizes ) {
122
+ $intermediate_sizes = get_intermediate_image_sizes();
123
+ }
124
+
125
+ if ( in_array( $matches[2], $intermediate_sizes ) ) {
126
+ $candidate_name = $matches[1] . '[size]';
127
+ } else {
128
+ return false;
129
+ }
130
+ }
131
+
132
+ return in_array( $candidate_name, MLAData_Source::$custom_field_data_sources );
133
+ } // mla_is_data_source
134
+
135
+ /**
136
+ * Get IPTC/EXIF or custom field mapping data source
137
+ *
138
+ * Defined as public so MLA Mapping Hooks clients can call it.
139
+ * Isolates clients from changes to _evaluate_data_source().
140
+ *
141
+ * @since 2.20
142
+ *
143
+ * @param integer post->ID of attachment
144
+ * @param string category/scope to evaluate against: custom_field_mapping or single_attachment_mapping
145
+ * @param array data source specification ( name, *data_source, *keep_existing, *format, mla_column, quick_edit, bulk_edit, *meta_name, *option, no_null )
146
+ * @param array (optional) _wp_attachment_metadata, default NULL (use current postmeta database value)
147
+ *
148
+ * @return string|array data source value
149
+ */
150
+ public static function mla_get_data_source( $post_id, $category, $data_value, $attachment_metadata = NULL ) {
151
+ $default_arguments = array(
152
+ 'data_source' => 'none',
153
+ 'keep_existing' => true,
154
+ 'format' => 'native',
155
+ 'meta_name' => '',
156
+ 'option' => 'text',
157
+ );
158
+ $data_value = shortcode_atts( $default_arguments, $data_value );
159
+
160
+ return MLAData_Source::_evaluate_data_source( $post_id, $category, $data_value, $attachment_metadata = NULL );
161
+ } // mla_get_data_source
162
+
163
+ /**
164
+ * Evaluate file information for custom field mapping
165
+ *
166
+ * @since 2.20
167
+ *
168
+ * @param string absolute path the the uploads base directory
169
+ * @param array _wp_attached_file meta_value array, indexed by post_id
170
+ * @param array _wp_attachment_metadata meta_value array, indexed by post_id
171
+ * @param integer post->ID of attachment
172
+ *
173
+ * @return array absolute_path_raw, absolute_path, absolute_file_name_raw, absolute_file_name, absolute_file, base_file, path, file_name, extension, dimensions, width, height, hwstring_small, array of intermediate sizes
174
+ */
175
+ private static function _evaluate_file_information( $upload_dir, &$wp_attached_files, &$wp_attachment_metadata, $post_id ) {
176
+ $results = array(
177
+ 'absolute_path_raw' => '',
178
+ 'absolute_path' => '',
179
+ 'absolute_file_name_raw' => '',
180
+ 'absolute_file_name' => '',
181
+ 'base_file' => '',
182
+ 'path' => '',
183
+ 'file_name' => '',
184
+ 'name_only' => '',
185
+ 'extension' => '',
186
+ 'width' => '',
187
+ 'height' => '',
188
+ 'orientation' => '',
189
+ 'hwstring_small' => '',
190
+ 'sizes' => array()
191
+ );
192
+
193
+ $base_file = isset( $wp_attached_files[ $post_id ]->meta_value ) ? $wp_attached_files[ $post_id ]->meta_value : '';
194
+ $sizes = array();
195
+
196
+ if ( isset( $wp_attachment_metadata[ $post_id ]->meta_value ) ) {
197
+ $attachment_metadata = @unserialize( $wp_attachment_metadata[ $post_id ]->meta_value );
198
+ if ( ! is_array( $attachment_metadata ) ) {
199
+ $attachment_metadata = array();
200
+ }
201
+ } else {
202
+ $attachment_metadata = array();
203
+ }
204
+
205
+ if ( !empty( $attachment_metadata ) ) {
206
+ if ( isset( $attachment_metadata['image_meta'] ) ) {
207
+ foreach ( $attachment_metadata['image_meta'] as $key => $value )
208
+ $results[ $key ] = $value;
209
+ }
210
+
211
+ $sizes = isset( $attachment_metadata['sizes'] ) ? $attachment_metadata['sizes'] : array();
212
+
213
+ if ( isset( $attachment_metadata['width'] ) ) {
214
+ $results['width'] = $attachment_metadata['width'];
215
+ $width = absint( $results['width'] );
216
+ } else {
217
+ $width = 0;
218
+ }
219
+
220
+ if ( isset( $attachment_metadata['height'] ) ) {
221
+ $results['height'] = $attachment_metadata['height'];
222
+ $height = absint( $results['height'] );
223
+ } else {
224
+ $height = 0;
225
+ }
226
+
227
+ if ( $width && $height ) {
228
+ $results['orientation'] = ( $height > $width ) ? 'portrait' : 'landscape';
229
+ }
230
+
231
+ $results['hwstring_small'] = isset( $attachment_metadata['hwstring_small'] ) ? $attachment_metadata['hwstring_small'] : '';
232
+ }
233
+
234
+ if ( ! empty( $base_file ) ) {
235
+ $pathinfo = pathinfo( $base_file );
236
+ $results['base_file'] = $base_file;
237
+ if ( '.' == $pathinfo['dirname'] ) {
238
+ $results['absolute_path_raw'] = $upload_dir;
239
+ $results['absolute_path'] = wptexturize( str_replace( '\\', '/', $upload_dir ) );
240
+ $results['path'] = '';
241
+ } else {
242
+ $results['absolute_path_raw'] = $upload_dir . $pathinfo['dirname'] . '/';
243
+ $results['absolute_path'] = wptexturize( str_replace( '\\', '/', $results['absolute_path_raw'] ) );
244
+ $results['path'] = wptexturize( $pathinfo['dirname'] . '/' );
245
+ }
246
+
247
+ $results['absolute_file_name_raw'] = $results['absolute_path_raw'] . $pathinfo['basename'];
248
+ $results['absolute_file_name'] = wptexturize( str_replace( '\\', '/', $results['absolute_file_name_raw'] ) );
249
+ $results['file_name'] = wptexturize( $pathinfo['basename'] );
250
+ $results['name_only'] = wptexturize( $pathinfo['filename'] );
251
+ $results['extension'] = wptexturize( $pathinfo['extension'] );
252
+ }
253
+
254
+ $results['sizes'] = $sizes;
255
+ return $results;
256
+ } // _evaluate_file_information
257
+
258
+ /**
259
+ * Evaluate post information for custom field mapping
260
+ *
261
+ * @since 2.20
262
+ *
263
+ * @param integer post->ID of attachment
264
+ * @param string category/scope to evaluate against: custom_field_mapping or single_attachment_mapping
265
+ * @param string data source name ( post_date or post_parent )
266
+ *
267
+ * @return mixed (string)/'' or (integer)/0 depending on $data_source type
268
+ */
269
+ private static function _evaluate_post_information( $post_id, $category, $data_source ) {
270
+ global $wpdb;
271
+ static $post_info = NULL;
272
+
273
+ if ( 0 == $post_id ) {
274
+ $value = NULL;
275
+ } else {
276
+ /*
277
+ * Check for $post_id match
278
+ */
279
+ if ( 'single_attachment_mapping' == $category && ! isset( $post_info[$post_id] ) ) {
280
+ $post_info = NULL;
281
+ }
282
+
283
+ if ( NULL == $post_info ) {
284
+ if ( 'custom_field_mapping' == $category ) {
285
+ $post_info = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} WHERE post_type = 'attachment'", OBJECT_K );
286
+ } else {
287
+ $post_info = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} WHERE ID = '{$post_id}'", OBJECT_K );
288
+ }
289
+ }
290
+
291
+ if ( 'post_id' == $data_source ) {
292
+ $data_source = 'ID';
293
+ }
294
+
295
+ if ( isset( $post_info[$post_id] ) && property_exists( $post_info[$post_id], $data_source ) ) {
296
+ $post_array = (array) $post_info[$post_id];
297
+ $value = $post_array[ $data_source ];
298
+ } else {
299
+ $value = NULL;
300
+ }
301
+ }
302
+
303
+ switch ( $data_source ) {
304
+ case 'ID':
305
+ case 'post_id':
306
+ case 'post_author':
307
+ case 'post_parent':
308
+ case 'menu_order':
309
+ case 'comment_count':
310
+ return ( NULL !== $value ) ? $value : 0;
311
+ default:
312
+ return ( NULL !== $value ) ? $value : '';
313
+ }
314
+
315
+ return false;
316
+ } // _evaluate_post_information
317
+
318
+ /**
319
+ * Evaluate post information for custom field mapping
320
+ *
321
+ * @since 2.20
322
+ *
323
+ * @param array field value(s)
324
+ * @param string format option text|single|export|array|multi
325
+ * @param boolean keep existing value(s) - for 'multi' option
326
+ *
327
+ * @return mixed array for option = array|multi else string
328
+ */
329
+ private static function _evaluate_array_result( $value, $option, $keep_existing ) {
330
+ if ( empty( $value ) ) {
331
+ return '';
332
+ }
333
+
334
+ if ( is_array( $value ) ) {
335
+ if ( 'single' == $option || 1 == count( $value ) ) {
336
+ return current( $value );
337
+ } elseif ( 'export' == $option ) {
338
+ return var_export( $value, true );
339
+ } elseif ( 'text' == $option ) {
340
+ return implode( ',', $value );
341
+ } elseif ( 'multi' == $option ) {
342
+ $value[0x80000000] = $option;
343
+ $value[0x80000001] = $keep_existing;
344
+ return $value;
345
+ }
346
+ }
347
+
348
+ /*
349
+ * $option = array returns the array
350
+ */
351
+ return $value;
352
+ } // _evaluate_array_result
353
+
354
+ /**
355
+ * Evaluate custom field mapping data source
356
+ *
357
+ * @since 2.20
358
+ *
359
+ * @param integer post->ID of attachment
360
+ * @param string category/scope to evaluate against: custom_field_mapping or single_attachment_mapping
361
+ * @param array data source specification ( name, *data_source, *keep_existing, *format, mla_column, quick_edit, bulk_edit, *meta_name, *option, no_null )
362
+ * @param array (optional) _wp_attachment_metadata, default NULL (use current postmeta database value)
363
+ *
364
+ * @return string|array data source value
365
+ */
366
+ private static function _evaluate_data_source( $post_id, $category, $data_value, $attachment_metadata = NULL ) {
367
+ global $wpdb;
368
+ static $upload_dir, $intermediate_sizes = NULL, $wp_attached_files = NULL, $wp_attachment_metadata = NULL;
369
+ static $current_id = 0, $file_info = NULL, $parent_info = NULL, $references = NULL, $alt_text = NULL;
370
+
371
+ if ( 'none' == $data_value['data_source'] ) {
372
+ return '';
373
+ }
374
+
375
+ $data_source = $data_value['data_source'];
376
+
377
+ /*
378
+ * Do this once per page load; cache attachment metadata if mapping all attachments
379
+ */
380
+ if ( NULL == $intermediate_sizes ) {
381
+ $upload_dir = wp_upload_dir();
382
+ $upload_dir = $upload_dir['basedir'] . '/';
383
+ $intermediate_sizes = get_intermediate_image_sizes();
384
+
385
+ if ( 'custom_field_mapping' == $category ) {
386
+ if ( ! $table = _get_meta_table('post') ) {
387
+ $wp_attached_files = array();
388
+ $wp_attachment_metadata = array();
389
+ } else {
390
+ $wp_attachment_metadata = $wpdb->get_results( "SELECT post_id, meta_value FROM {$table} WHERE meta_key = '_wp_attachment_metadata'", OBJECT_K );
391
+ $wp_attached_files = $wpdb->get_results( "SELECT post_id, meta_value FROM {$table} WHERE meta_key = '_wp_attached_file'", OBJECT_K );
392
+ }
393
+ } // custom_field_mapping, i.e., mapping all attachments
394
+ } // first call after page load
395
+
396
+ /*
397
+ * Do this once per post. Simulate SQL results for $wp_attached_files and $wp_attachment_metadata.
398
+ */
399
+ if ( $current_id != $post_id ) {
400
+ $current_id = $post_id;
401
+ $parent_info = NULL;
402
+ $references = NULL;
403
+ $alt_text = NULL;
404
+
405
+ if ( 'single_attachment_mapping' == $category ) {
406
+ $metadata = get_metadata( 'post', $post_id, '_wp_attached_file' );
407
+ if ( isset( $metadata[0] ) ) {
408
+ $wp_attached_files = array( $post_id => (object) array( 'post_id' => $post_id, 'meta_value' => $metadata[0] ) );
409
+ } else {
410
+ $wp_attached_files = array();
411
+ }
412
+
413
+ if ( NULL == $attachment_metadata ) {
414
+ $metadata = get_metadata( 'post', $post_id, '_wp_attachment_metadata' );
415
+ if ( isset( $metadata[0] ) ) {
416
+ $attachment_metadata = $metadata[0];
417
+ }
418
+ }
419
+
420
+ if ( empty( $attachment_metadata ) ) {
421
+ $attachment_metadata = array();
422
+ }
423
+
424
+ $wp_attachment_metadata = array( $post_id => (object) array( 'post_id' => $post_id, 'meta_value' => serialize( $attachment_metadata ) ) );
425
+ }
426
+
427
+ $file_info = MLAData_Source::_evaluate_file_information( $upload_dir, $wp_attached_files, $wp_attachment_metadata, $post_id );
428
+ }
429
+
430
+ $size_info = array( 'file' => '', 'width' => '', 'height' => '' );
431
+ $match_count = preg_match( '/(.+)\[(.+)\]/', $data_source, $matches );
432
+ if ( 1 == $match_count ) {
433
+ $data_source = $matches[1] . '[size]';
434
+ if ( isset( $file_info['sizes'][ $matches[2] ] ) ) {
435
+ $size_info = $file_info['sizes'][ $matches[2] ];
436
+ }
437
+ }
438
+
439
+ $result = '';
440
+
441
+ switch( $data_source ) {
442
+ case 'meta':
443
+ $attachment_metadata = isset( $wp_attachment_metadata[ $post_id ]->meta_value ) ? maybe_unserialize( $wp_attachment_metadata[ $post_id ]->meta_value ) : array();
444
+ $result = MLAData::mla_find_array_element( $data_value['meta_name'], $attachment_metadata, $data_value['option'], $data_value['keep_existing'] );
445
+ break;
446
+ case 'template':
447
+ if ( in_array( $data_value['option'], array ( 'single', 'export', 'array', 'multi' ) ) ) {
448
+ $default_option = 'array';
449
+ } else {
450
+ $default_option = 'text';
451
+ }
452
+
453
+ /*
454
+ * Go through the template and expand the non-prefixed elements
455
+ * as Data Sources
456
+ */
457
+ $item_values = array();
458
+ $placeholders = MLAData::mla_get_template_placeholders( $data_value['meta_name'], $default_option );
459
+ foreach ( $placeholders as $key => $placeholder ) {
460
+ if ( empty( $placeholder['prefix'] ) ) {
461
+ $field_value = $data_value;
462
+ $field_value['data_source'] = $placeholder['value'];
463
+ $field_value['meta_name'] = '';
464
+ $field_value['option'] = $placeholder['option'];
465
+ $field_value = MLAData_Source::_evaluate_data_source( $post_id, $category, $field_value, $attachment_metadata );
466
+ $item_values[ $key ] = MLAData::mla_apply_field_level_format( $field_value, $placeholder );
467
+ } // Data Source
468
+ } // foreach placeholder
469
+
470
+ /*
471
+ * Now expand the template using the above Data Source values
472
+ */
473
+ $template = '[+template:' . $data_value['meta_name'] . '+]';
474
+ $item_values = MLAData::mla_expand_field_level_parameters( $template, NULL, $item_values, $post_id, $data_value['keep_existing'], $default_option );
475
+
476
+ if ( 'array' == $default_option ) {
477
+ $result = MLAData::mla_parse_array_template( $template, $item_values );
478
+ $result = MLAData_Source::_evaluate_array_result( $result, $data_value['option'], $data_value['keep_existing'] );
479
+ } else {
480
+ $result = MLAData::mla_parse_template( $template, $item_values );
481
+ }
482
+ break;
483
+ case 'parent':
484
+ $data_source = 'post_parent';
485
+ /* fallthru */
486
+ case 'ID':
487
+ case 'post_id':
488
+ case 'post_author':
489
+ case 'post_parent':
490
+ case 'menu_order':
491
+ case 'comment_count':
492
+ $result = absint( MLAData_Source::_evaluate_post_information( $post_id, $category, $data_source ) );
493
+ break;
494
+ case 'alt_text':
495
+ if ( NULL == $alt_text ) {
496
+ $metadata = get_metadata( 'post', $post_id, '_wp_attachment_image_alt' );
497
+ if ( is_array( $metadata ) ) {
498
+ if ( count( $metadata ) == 1 ) {
499
+ $alt_text = maybe_unserialize( $metadata[0] );
500
+ } else {
501
+ $alt_text = array();
502
+ foreach ( $metadata as $single_key => $single_value ) {
503
+ $alt_text[ $single_key ] = maybe_unserialize( $single_value );
504
+ }
505
+ }
506
+ }
507
+ }
508
+
509
+ if ( ! empty( $alt_text ) ) {
510
+ $result = MLAData_Source::_evaluate_array_result( $alt_text, $data_value['option'], $data_value['keep_existing'] );
511
+ }
512
+ break;
513
+ case 'mime_type':
514
+ $data_source = 'post_mime_type';
515
+ /* fallthru */
516
+ case 'post_date':
517
+ case 'post_date_gmt':
518
+ case 'post_content':
519
+ case 'post_title':
520
+ case 'post_excerpt':
521
+ case 'post_status':
522
+ case 'comment_status':
523
+ case 'ping_status':
524
+ case 'post_name':
525
+ case 'post_modified':
526
+ case 'post_modified_gmt':
527
+ case 'post_content_filtered':
528
+ case 'guid':
529
+ case 'post_mime_type':
530
+ $result = MLAData_Source::_evaluate_post_information( $post_id, $category, $data_source );
531
+ break;
532
+ case 'absolute_path':
533
+ case 'absolute_file_name':
534
+ case 'base_file':
535
+ case 'path':
536
+ case 'file_name':
537
+ case 'name_only':
538
+ case 'extension':
539
+ case 'width':
540
+ case 'height':
541
+ case 'orientation':
542
+ case 'hwstring_small':
543
+ case 'aperture':
544
+ case 'credit':
545
+ case 'camera':
546
+ case 'caption':
547
+ case 'created_timestamp':
548
+ case 'copyright':
549
+ case 'focal_length':
550
+ case 'iso':
551
+ case 'shutter_speed':
552
+ case 'title':
553
+ if ( isset( $file_info[ $data_source ] ) ) {
554
+ $result = $file_info[ $data_source ];
555
+ }
556
+ break;
557
+ case 'file_size':
558
+ $filesize = @ filesize( $file_info['absolute_file_name_raw'] );
559
+ if ( ! (false === $filesize ) ) {
560
+ $result = $filesize;
561
+ }
562
+ break;
563
+ case 'upload_date':
564
+ $result = MLAData_Source::_evaluate_post_information( $post_id, $category, 'post_date' );
565
+ break;
566
+ case 'dimensions':
567
+ $result = $file_info['width'] . 'x' . $file_info['height'];
568
+ if ( 'x' == $result ) {
569
+ $result = '';
570
+ }
571
+ break;
572
+ case 'pixels':
573
+ $result = absint( (int) $file_info['width'] * (int) $file_info['height'] );
574
+ if ( 0 == $result ) {
575
+ $result = '';
576
+ } else {
577
+ $result = (string) $result;
578
+ }
579
+ break;
580
+ case 'size_keys':
581
+ $result = array();
582
+ foreach ( $file_info['sizes'] as $key => $value )
583
+ $result[] = $key;
584
+
585
+ $result = MLAData_Source::_evaluate_array_result( $result, $data_value['option'], $data_value['keep_existing'] );
586
+ break;
587
+ case 'size_names':
588
+ $result = array();
589
+ foreach ( $file_info['sizes'] as $key => $value )
590
+ $result[] = $value['file'];
591
+
592
+ $result = MLAData_Source::_evaluate_array_result( $result, $data_value['option'], $data_value['keep_existing'] );
593
+ break;
594
+ case 'size_bytes':
595
+ $result = array();
596
+ foreach ( $file_info['sizes'] as $key => $value ) {
597
+ $filesize = @ filesize( $file_info['absolute_path_raw'] . $value['file'] );
598
+ if ( false === $filesize ) {
599
+ $result[] = '?';
600
+ } else {
601
+ switch( $data_value['format'] ) {
602
+ case 'commas':
603
+ if ( is_numeric( $filesize ) ) {
604
+ $filesize = number_format( (float)$filesize );
605
+ }
606
+ break;
607
+ default:
608
+ // no change
609
+ } // format
610
+ $result[] = $filesize;
611
+ }
612
+ }
613
+
614
+ $result = MLAData_Source::_evaluate_array_result( $result, $data_value['option'], $data_value['keep_existing'] );
615
+ break;
616
+ case 'size_pixels':
617
+ $result = array();
618
+ foreach ( $file_info['sizes'] as $key => $value ) {
619
+ $pixels = absint( (int) $value['width'] * (int) $value['height'] );
620
+
621
+ switch( $data_value['format'] ) {
622
+ case 'commas':
623
+ if ( is_numeric( $pixels ) ) {
624
+ $pixels = number_format( (float)$pixels );
625
+ }
626
+ break;
627
+ default:
628
+ // no change
629
+ } // format
630
+ $result[] = $pixels;
631
+ }
632
+
633
+ $result = MLAData_Source::_evaluate_array_result( $result, $data_value['option'], $data_value['keep_existing'] );
634
+ break;
635
+ case 'size_dimensions':
636
+ $result = array();
637
+ foreach ( $file_info['sizes'] as $key => $value ) {
638
+ $result[] = $value['width'] . 'x' . $value['height'];
639
+ }
640
+
641
+ $result = MLAData_Source::_evaluate_array_result( $result, $data_value['option'], $data_value['keep_existing'] );
642
+ break;
643
+ case 'size_name[size]':
644
+ $result = $size_info['file'];
645
+ break;
646
+ case 'size_bytes[size]':
647
+ $result = @ filesize( $file_info['absolute_path_raw'] . $size_info['file'] );
648
+ if ( false === $result ) {
649
+ $result = '?';
650
+ }
651
+ break;
652
+ case 'size_pixels[size]':
653
+ $result = absint( (int) $size_info['width'] * (int) $size_info['height'] );
654
+ break;
655
+ case 'size_dimensions[size]':
656
+ $result = $size_info['width'] . 'x' . $size_info['height'];
657
+ if ( 'x' == $result ) {
658
+ $result = '';
659
+ }
660
+ break;
661
+ case 'parent_date':
662
+ case 'parent_type':
663
+ case 'parent_title':
664
+ if ( is_null( $parent_info ) ) {
665
+ $parent_info = MLAQuery::mla_fetch_attachment_parent_data( MLAData_Source::_evaluate_post_information( $post_id, $category, 'post_parent' ) );
666
+ }
667
+
668
+ if ( isset( $parent_info[ $data_source ] ) ) {
669
+ $result = $parent_info[ $data_source ];
670
+ }
671
+ break;
672
+ case 'parent_issues':
673
+ if ( is_null( $references ) ) {
674
+ $references = MLAQuery::mla_fetch_attachment_references( $post_id, MLAData_Source::_evaluate_post_information( $post_id, $category, 'post_parent' ) );
675
+ }
676
+
677
+ if ( !empty( $references['parent_errors'] ) ) {
678
+ $result = $references['parent_errors'];
679
+ /*
680
+ * Remove (ORPHAN...
681
+ */
682
+ $orphan_certain = '(' . __( 'ORPHAN', 'media-library-assistant' ) . ')';
683
+ $orphan_possible = '(' . __( 'ORPHAN', 'media-library-assistant' ) . '?)';
684
+
685
+ if ( false !== strpos( $result, $orphan_certain ) ) {
686
+ $result = trim( substr( $result, strlen( $orphan_certain ) ) );
687
+ } elseif ( false !== strpos( $result, $orphan_possible ) ) {
688
+ $result = trim( substr( $result, strlen( $orphan_possible ) ) );
689
+ }
690
+ }
691
+ break;
692
+ case 'reference_issues':
693
+ if ( is_null( $references ) ) {
694
+ $references = MLAQuery::mla_fetch_attachment_references( $post_id, MLAData_Source::_evaluate_post_information( $post_id, $category, 'post_parent' ) );
695
+ }
696
+
697
+ if ( !empty( $references['parent_errors'] ) ) {
698
+ $result = $references['parent_errors'];
699
+ }
700
+ break;
701
+ case 'featured_in':
702
+ case 'featured_in_title':
703
+ if ( is_null( $references ) ) {
704
+ $references = MLAQuery::mla_fetch_attachment_references( $post_id, MLAData_Source::_evaluate_post_information( $post_id, $category, 'post_parent' ) );
705
+ }
706
+
707
+ if ( !empty( $references['features'] ) ) {
708
+ $result = array();
709
+ foreach ( $references['features'] as $ID => $value )
710
+ if ( 'featured_in' == $data_source ) {
711
+ $result[] = sprintf( '%1$s (%2$s %3$d)', $value->post_title, $value->post_type, $ID );
712
+ } else {
713
+ $result[] = $value->post_title;
714
+ }
715
+
716
+ $result = MLAData_Source::_evaluate_array_result( $result, $data_value['option'], $data_value['keep_existing'] );
717
+ } else {
718
+ $result = '';
719
+ }
720
+ break;
721
+ case 'inserted_in':
722
+ case 'inserted_in_title':
723
+ if ( is_null( $references ) ) {
724
+ $references = MLAQuery::mla_fetch_attachment_references( $post_id, MLAData_Source::_evaluate_post_information( $post_id, $category, 'post_parent' ) );
725
+ }
726
+
727
+ if ( !empty( $references['inserts'] ) ) {
728
+ $result = array();
729
+ foreach ( $references['inserts'] as $base_file => $inserts )
730
+ foreach ( $inserts as $value )
731
+ if ( 'inserted_in' == $data_source ) {
732
+ $result[] = sprintf( '%1$s (%2$s %3$d)', $value->post_title, $value->post_type, $value->ID );
733
+ } else {
734
+ $result[] = $value->post_title;
735
+ }
736
+
737
+ ksort( $result );
738
+
739
+ $result = MLAData_Source::_evaluate_array_result( $result, $data_value['option'], $data_value['keep_existing'] );
740
+ } else {
741
+ $result = '';
742
+ }
743
+ break;
744
+ case 'gallery_in':
745
+ case 'gallery_in_title':
746
+ if ( is_null( $references ) ) {
747
+ $references = MLAQuery::mla_fetch_attachment_references( $post_id, MLAData_Source::_evaluate_post_information( $post_id, $category, 'post_parent' ) );
748
+ }
749
+
750
+ if ( !empty( $references['galleries'] ) ) {
751
+ $result = array();
752
+ foreach ( $references['galleries'] as $ID => $value )
753
+ if ( 'gallery_in' == $data_source ) {
754
+ $result[] = sprintf( '%1$s (%2$s %3$d)', $value['post_title'], $value['post_type'], $ID );
755
+ } else {
756
+ $result[] = $value['post_title'];
757
+ }
758
+
759
+ $result = MLAData_Source::_evaluate_array_result( $result, $data_value['option'], $data_value['keep_existing'] );
760
+ } else {
761
+ $result = '';
762
+ }
763
+ break;
764
+ case 'mla_gallery_in':
765
+ case 'mla_gallery_in_title':
766
+ if ( is_null( $references ) ) {
767
+ $references = MLAQuery::mla_fetch_attachment_references( $post_id, MLAData_Source::_evaluate_post_information( $post_id, $category, 'post_parent' ) );
768
+ }
769
+
770
+ if ( !empty( $references['mla_galleries'] ) ) {
771
+ $result = array();
772
+ foreach ( $references['mla_galleries'] as $ID => $value )
773
+ if ( 'mla_gallery_in' == $data_source ) {
774
+ $result[] = sprintf( '%1$s (%2$s %3$d)', $value['post_title'], $value['post_type'], $ID );
775
+ } else {
776
+ $result[] = $value['post_title'];
777
+ }
778
+
779
+ $result = MLAData_Source::_evaluate_array_result( $result, $data_value['option'], $data_value['keep_existing'] );
780
+ } else {
781
+ $result = '';
782
+ }
783
+ break;
784
+ default:
785
+ return '';
786
+ } // switch $data_source
787
+
788
+ switch( $data_value['format'] ) {
789
+ case 'raw':
790
+ return $result;
791
+ case 'commas':
792
+ if ( is_numeric( $result ) ) {
793
+ $result = str_pad( number_format( (float)$result ), 15, ' ', STR_PAD_LEFT );
794
+ }
795
+ break;
796
+ case 'native':
797
+ default:
798
+ /*
799
+ * Make some numeric values sortable as strings, make all value non-empty
800
+ */
801
+ if ( in_array( $data_source, array( 'file_size', 'pixels', 'width', 'height' ) ) ) {
802
+ $result = str_pad( $result, 15, ' ', STR_PAD_LEFT );
803
+ } elseif ( empty( $result ) ) {
804
+ $result = ' ';
805
+ }
806
+ } // format
807
+
808
+ return $result;
809
+ } // _evaluate_data_source
810
+ } // class MLAData_Source
811
+ ?>
includes/class-mla-data.php CHANGED
@@ -16,84 +16,14 @@
16
  * @since 0.1
17
  */
18
  class MLAData {
19
- /**
20
- * Provides a unique suffix for the ALT Text "Search Media" SQL View
21
- *
22
- * The SQL View is used to filter the Media/Assistant submenu table by
23
- * ALT Text with the Search Media text box.
24
- *
25
- * @since 0.40
26
- */
27
- const MLA_ALT_TEXT_VIEW_SUFFIX = 'alt_text_view';
28
-
29
- /**
30
- * Provides a unique name for the ALT Text "Search Media" SQL View
31
- *
32
- * @since 0.40
33
- *
34
- * @var array
35
- */
36
- private static $mla_alt_text_view = NULL;
37
-
38
- /**
39
- * Provides a unique suffix for the custom field "orderby" SQL View
40
- *
41
- * The SQL View is used to sort the Media/Assistant submenu table on
42
- * ALT Text and custom field columns.
43
- *
44
- * @since 2.15
45
- */
46
- const MLA_ORDERBY_VIEW_SUFFIX = 'orderby_view';
47
-
48
- /**
49
- * Provides a unique name for the custom field "orderby" SQL View
50
- *
51
- * @since 2.15
52
- *
53
- * @var array
54
- */
55
- private static $mla_orderby_view = NULL;
56
-
57
- /**
58
- * Provides a unique suffix for the "Table View custom:" SQL View
59
- *
60
- * The SQL View is used to filter the Media/Assistant submenu table on
61
- * custom field Table Views.
62
- *
63
- * @since 2.15
64
- */
65
- const MLA_TABLE_VIEW_CUSTOM_SUFFIX = 'table_view_custom';
66
-
67
- /**
68
- * Provides a unique name for the "Table View custom:" SQL View
69
- *
70
- * @since 2.15
71
- *
72
- * @var array
73
- */
74
- private static $mla_table_view_custom = NULL;
75
-
76
- /**
77
- * WordPress version test for $wpdb->esc_like() Vs esc_sql()
78
- *
79
- * @since 2.13
80
- *
81
- * @var boolean
82
- */
83
- private static $wp_4dot0_plus = true;
84
-
85
  /**
86
  * Initialization function, similar to __construct()
87
  *
88
  * @since 0.1
89
  */
90
  public static function initialize() {
91
- global $table_prefix;
92
-
93
- self::$mla_alt_text_view = $table_prefix . MLA_OPTION_PREFIX . self::MLA_ALT_TEXT_VIEW_SUFFIX;
94
- self::$mla_orderby_view = $table_prefix . MLA_OPTION_PREFIX . self::MLA_ORDERBY_VIEW_SUFFIX;
95
- self::$mla_table_view_custom = $table_prefix . MLA_OPTION_PREFIX . self::MLA_TABLE_VIEW_CUSTOM_SUFFIX;
96
- self::$wp_4dot0_plus = version_compare( get_bloginfo('version'), '4.0', '>=' );
97
 
98
  add_action( 'save_post', 'MLAData::mla_save_post_action', 10, 1);
99
  add_action( 'edit_attachment', 'MLAData::mla_save_post_action', 10, 1);
@@ -154,7 +84,7 @@ class MLAData {
154
  }
155
  break;
156
  case 'option':
157
- $template = MLAOptions::mla_get_option( $source );
158
  if ( $template == false ) {
159
  return false;
160
  }
@@ -1168,7 +1098,7 @@ class MLAData {
1168
  if ( 0 < $post_id ) {
1169
  $record = get_metadata( 'post', $post_id, $value['value'], 'single' == $value['option'] );
1170
  if ( empty( $record ) && 'ALL_CUSTOM' == $value['value'] ) {
1171
- $meta_values = self::mla_fetch_attachment_metadata( $post_id );
1172
  $clean_data = array();
1173
  foreach( $meta_values as $meta_key => $meta_value ) {
1174
  if ( 0 !== strpos( $meta_key, 'mla_item_' ) ) {
@@ -1290,14 +1220,14 @@ class MLAData {
1290
  $candidate = str_replace( '{', '[', str_replace( '}', ']', $value['value'] ) );
1291
  $key = str_replace( '{', '[', str_replace( '}', ']', $key ) );
1292
 
1293
- if ( MLAOptions::mla_is_data_source( $candidate ) ) {
1294
  $data_value = array(
1295
  'data_source' => $candidate,
1296
  'keep_existing' => false,
1297
  'format' => 'raw',
1298
  'option' => $value['option'] ); // single, export, text for array values, e.g., alt_text
1299
 
1300
- $markup_values[ $key ] = MLAOptions::mla_get_data_source( $post_id, 'single_attachment_mapping', $data_value );
1301
  } elseif ( isset( $markup_values[ $value['value'] ] ) ) {
1302
  /*
1303
  * A standard element can have a format modifier, e.g., commas, attr
@@ -1444,125 +1374,6 @@ class MLAData {
1444
  return $results;
1445
  }
1446
 
1447
- /**
1448
- * Cache the results of mla_count_list_table_items for reuse in mla_query_list_table_items
1449
- *
1450
- * @since 1.40
1451
- *
1452
- * @var array
1453
- */
1454
- private static $mla_list_table_items = NULL;
1455
-
1456
- /**
1457
- * Get the total number of attachment posts
1458
- *
1459
- * @since 0.30
1460
- *
1461
- * @param array Query variables, e.g., from $_REQUEST
1462
- * @param int (optional) number of rows to skip over to reach desired page
1463
- * @param int (optional) number of rows on each page
1464
- *
1465
- * @return integer Number of attachment posts
1466
- */
1467
- public static function mla_count_list_table_items( $request, $offset = NULL, $count = NULL ) {
1468
- if ( NULL !== $offset && NULL !== $count ) {
1469
- $request = self::_prepare_list_table_query( $request, $offset, $count );
1470
- $request = apply_filters( 'mla_list_table_query_final_terms', $request );
1471
-
1472
- self::$mla_list_table_items = apply_filters( 'mla_list_table_query_custom_items', NULL, $request );
1473
- if ( is_null( self::$mla_list_table_items ) ) {
1474
- self::$mla_list_table_items = self::_execute_list_table_query( $request );
1475
- }
1476
-
1477
- return self::$mla_list_table_items->found_posts;
1478
- }
1479
-
1480
- $request = self::_prepare_list_table_query( $request );
1481
- $request = apply_filters( 'mla_list_table_query_final_terms', $request );
1482
-
1483
- $results = apply_filters( 'mla_list_table_query_custom_items', NULL, $request );
1484
- if ( is_null( $results ) ) {
1485
- $results = self::_execute_list_table_query( $request );
1486
- }
1487
-
1488
- self::$mla_list_table_items = NULL;
1489
-
1490
- return $results->found_posts;
1491
- }
1492
-
1493
- /**
1494
- * Retrieve attachment objects for list table display
1495
- *
1496
- * Supports prepare_items in class-mla-list-table.php.
1497
- * Modeled after wp_edit_attachments_query in wp-admin/post.php
1498
- *
1499
- * @since 0.1
1500
- *
1501
- * @param array query parameters from web page, usually found in $_REQUEST
1502
- * @param int number of rows to skip over to reach desired page
1503
- * @param int number of rows on each page
1504
- *
1505
- * @return array attachment objects (posts) including parent data, meta data and references
1506
- */
1507
- public static function mla_query_list_table_items( $request, $offset, $count ) {
1508
- if ( NULL == self::$mla_list_table_items ) {
1509
- $request = self::_prepare_list_table_query( $request, $offset, $count );
1510
- $request = apply_filters( 'mla_list_table_query_final_terms', $request );
1511
-
1512
- self::$mla_list_table_items = apply_filters( 'mla_list_table_query_custom_items', NULL, $request );
1513
- if ( is_null( self::$mla_list_table_items ) ) {
1514
- self::$mla_list_table_items = self::_execute_list_table_query( $request );
1515
- }
1516
- }
1517
-
1518
- $attachments = self::$mla_list_table_items->posts;
1519
- foreach ( $attachments as $index => $attachment ) {
1520
- /*
1521
- * Add parent data
1522
- */
1523
- $parent_data = self::mla_fetch_attachment_parent_data( $attachment->post_parent );
1524
- foreach ( $parent_data as $parent_key => $parent_value ) {
1525
- $attachments[ $index ]->$parent_key = $parent_value;
1526
- }
1527
-
1528
- /*
1529
- * Add meta data
1530
- */
1531
- $meta_data = self::mla_fetch_attachment_metadata( $attachment->ID );
1532
- foreach ( $meta_data as $meta_key => $meta_value ) {
1533
- $attachments[ $index ]->$meta_key = $meta_value;
1534
- }
1535
- }
1536
-
1537
- /*
1538
- * Add references
1539
- */
1540
- self::mla_attachment_array_fetch_references( $attachments );
1541
-
1542
- return $attachments;
1543
- }
1544
-
1545
- /**
1546
- * Retrieve attachment objects for the WordPress Media Manager
1547
- *
1548
- * Supports month-year and taxonomy-term filters as well as the enhanced search box
1549
- *
1550
- * @since 1.20
1551
- *
1552
- * @param array query parameters from Media Manager
1553
- * @param int number of rows to skip over to reach desired page
1554
- * @param int number of rows on each page
1555
- *
1556
- * @return object WP_Query object with query results
1557
- */
1558
- public static function mla_query_media_modal_items( $request, $offset, $count ) {
1559
- $request = self::_prepare_list_table_query( $request, $offset, $count );
1560
- $request = apply_filters( 'mla_media_modal_query_final_terms', $request );
1561
-
1562
- $results = apply_filters( 'mla_media_modal_query_custom_items', NULL, $request );
1563
- return is_null( $results ) ? self::_execute_list_table_query( $request ) : $results;
1564
- }
1565
-
1566
  /**
1567
  * WP_Query filter "parameters"
1568
  *
@@ -1609,2551 +1420,281 @@ class MLAData {
1609
  public static $search_parameters = array();
1610
 
1611
  /**
1612
- * Sanitize and expand query arguments from request variables
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1613
  *
1614
- * Prepare the arguments for WP_Query.
1615
- * Modeled after wp_edit_attachments_query in wp-admin/post.php
1616
  *
1617
  * @since 0.1
1618
  *
1619
  * @param array query parameters from web page, usually found in $_REQUEST
1620
- * @param int Optional number of rows (default 0) to skip over to reach desired page
1621
- * @param int Optional number of rows on each page (0 = all rows, default)
1622
  *
1623
- * @return array revised arguments suitable for WP_Query
1624
  */
1625
- private static function _prepare_list_table_query( $raw_request, $offset = 0, $count = 0 ) {
1626
- /*
1627
- * Go through the $raw_request, take only the arguments that are used in the query and
1628
- * sanitize or validate them.
1629
- */
1630
- if ( ! is_array( $raw_request ) ) {
1631
- /* translators: 1: ERROR tag 2: function name 3: non-array value */
1632
- error_log( sprintf( _x( '%1$s: %2$s non-array "%3$s"', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), 'MLAData::_prepare_list_table_query', var_export( $raw_request, true ) ), 0 );
1633
- return null;
1634
- }
 
 
 
 
 
 
 
 
 
 
 
1635
 
1636
- /*
1637
- * Make sure the current orderby choice still exists or revert to default.
1638
- */
1639
- $default_orderby = array_merge( array( 'none' => array('none',false) ), MLA_List_Table::mla_get_sortable_columns( ) );
1640
- $current_orderby = MLAOptions::mla_get_option( MLAOptions::MLA_DEFAULT_ORDERBY );
1641
- $found_current = false;
1642
- foreach ( $default_orderby as $key => $value ) {
1643
- if ( $current_orderby == $value[0] ) {
1644
- $found_current = true;
1645
- break;
1646
- }
1647
  }
1648
 
1649
- if ( $found_current ) {
1650
- /*
1651
- * Custom fields can have HTML reserved characters, which are encoded by
1652
- * mla_get_sortable_columns, so a separate, unencoded list is required.
1653
- */
1654
- $default_orderby = MLAOptions::mla_custom_field_support( 'custom_sortable_columns' );
1655
- foreach ( $default_orderby as $sort_key => $sort_value ) {
1656
- if ( $current_orderby == $sort_key ) {
1657
- $current_orderby = 'c_' . $sort_value[0];
1658
- break;
1659
- }
1660
- } // foreach
1661
- } else {
1662
- MLAOptions::mla_delete_option( MLAOptions::MLA_DEFAULT_ORDERBY );
1663
- $current_orderby = MLAOptions::mla_get_option( MLAOptions::MLA_DEFAULT_ORDERBY );
1664
  }
1665
 
1666
- $clean_request = array (
1667
- 'm' => 0,
1668
- 'orderby' => $current_orderby,
1669
- 'order' => MLAOptions::mla_get_option( MLAOptions::MLA_DEFAULT_ORDER ),
1670
- 'post_type' => 'attachment',
1671
- 'post_status' => 'inherit',
1672
- 'mla_search_connector' => 'AND',
1673
- 'mla_search_fields' => array()
1674
- );
1675
-
1676
- foreach ( $raw_request as $key => $value ) {
1677
- switch ( $key ) {
1678
- /*
1679
- * 'sentence' and 'exact' modify the keyword search ('s')
1680
- * Their value is not important, only their presence.
1681
- */
1682
- case 'sentence':
1683
- case 'exact':
1684
- case 'mla-tax':
1685
- case 'mla-term':
1686
- $clean_request[ $key ] = sanitize_key( $value );
1687
- break;
1688
- case 'orderby':
1689
- if ( in_array( $value, array( 'none', 'post__in' ) ) ) {
1690
- $clean_request[ $key ] = $value;
1691
- } else {
1692
- $orderby = NULL;
1693
- /*
1694
- * Custom fields can have HTML reserved characters, which are encoded by
1695
- * mla_get_sortable_columns, so a separate, unencoded list is required.
1696
- */
1697
- $sortable_columns = MLAOptions::mla_custom_field_support( 'custom_sortable_columns' );
1698
- foreach ($sortable_columns as $sort_key => $sort_value ) {
1699
- if ( $value == $sort_key ) {
1700
- $orderby = 'c_' . $sort_value[0];
1701
- break;
1702
- }
1703
- } // foreach
1704
-
1705
- if ( NULL === $orderby ) {
1706
- $sortable_columns = MLA_List_Table::mla_get_sortable_columns();
1707
- foreach ($sortable_columns as $sort_key => $sort_value ) {
1708
- if ( $value == $sort_value[0] ) {
1709
- $orderby = $value;
1710
- break;
1711
- }
1712
- } // foreach
1713
- }
1714
-
1715
- if ( NULL !== $orderby ) {
1716
- $clean_request[ $key ] = $orderby;
1717
- }
1718
- }
1719
-
1720
- break;
1721
- /*
1722
- * ids allows hooks to supply a persistent list of items
1723
- */
1724
- case 'ids':
1725
- if ( is_array( $value ) ) {
1726
- $clean_request[ 'post__in' ] = $value;
1727
- } else {
1728
- $clean_request[ 'post__in' ] = array_map( 'absint', explode( ',', $value ) );
1729
- }
1730
- break;
1731
- /*
1732
- * post__in and post__not_in are used in the Media Modal Ajax queries
1733
- */
1734
- case 'post__in':
1735
- case 'post__not_in':
1736
- case 'post_mime_type':
1737
- $clean_request[ $key ] = $value;
1738
- break;
1739
- case 'parent':
1740
- case 'post_parent':
1741
- $clean_request[ 'post_parent' ] = absint( $value );
1742
- break;
1743
- /*
1744
- * ['m'] - filter by year and month of post, e.g., 201204
1745
- */
1746
- case 'author':
1747
- case 'm':
1748
- $clean_request[ $key ] = absint( $value );
1749
- break;
1750
- /*
1751
- * ['mla_filter_term'] - filter by category or tag ID; -1 allowed
1752
- */
1753
- case 'mla_filter_term':
1754
- $clean_request[ $key ] = intval( $value );
1755
- break;
1756
- case 'order':
1757
- switch ( $value = strtoupper ($value ) ) {
1758
- case 'ASC':
1759
- case 'DESC':
1760
- $clean_request[ $key ] = $value;
1761
- break;
1762
- default:
1763
- $clean_request[ $key ] = 'ASC';
1764
- }
1765
- break;
1766
- case 'detached':
1767
- if ( ( '0' == $value ) || ( '1' == $value ) ) {
1768
- $clean_request['detached'] = $value;
1769
- }
1770
-
1771
- break;
1772
- case 'status':
1773
- if ( 'trash' == $value ) {
1774
- $clean_request['post_status'] = 'trash';
1775
- }
1776
-
1777
- break;
1778
- /*
1779
- * ['s'] - Search Media by one or more keywords
1780
- * ['mla_search_connector'], ['mla_search_fields'] - Search Media options
1781
- */
1782
- case 's':
1783
- switch ( substr( $value, 0, 3 ) ) {
1784
- case '>|<':
1785
- $clean_request['debug'] = 'console';
1786
- break;
1787
- case '<|>':
1788
- $clean_request['debug'] = 'log';
1789
- break;
1790
- }
1791
-
1792
- if ( isset( $clean_request['debug'] ) ) {
1793
- $value = substr( $value, 3 );
1794
- }
1795
-
1796
- $value = stripslashes( trim( $value ) );
1797
-
1798
- if ( ! empty( $value ) ) {
1799
- $clean_request[ $key ] = $value;
1800
- }
1801
-
1802
- break;
1803
- case 'mla_terms_search':
1804
- if ( ! empty( $value['phrases'] ) && ! empty( $value['taxonomies'] ) ) {
1805
- $value['phrases'] = stripslashes( trim( $value['phrases'] ) );
1806
- if ( ! empty( $value['phrases'] ) ) {
1807
- $clean_request[ $key ] = $value;
1808
- }
1809
- }
1810
- break;
1811
- case 'mla_search_connector':
1812
- case 'mla_search_fields':
1813
- $clean_request[ $key ] = $value;
1814
- break;
1815
- case 'mla-metakey':
1816
- case 'mla-metavalue':
1817
- $clean_request[ $key ] = stripslashes( $value );
1818
- break;
1819
- case 'meta_query':
1820
- if ( ! empty( $value ) ) {
1821
- if ( is_array( $value ) ) {
1822
- $clean_request[ $key ] = $value;
1823
- } else {
1824
- $clean_request[ $key ] = unserialize( stripslashes( $value ) );
1825
- unset( $clean_request[ $key ]['slug'] );
1826
- } // not array
1827
- }
1828
 
1829
- break;
1830
- default:
1831
- // ignore anything else in $_REQUEST
1832
- } // switch $key
1833
- } // foreach $raw_request
1834
 
1835
  /*
1836
- * Pass query and search parameters to the filters for _execute_list_table_query
1837
  */
1838
- self::$query_parameters = array( 'use_alt_text_view' => false, 'use_postmeta_view' => false, 'use_orderby_view' => false, 'orderby' => $clean_request['orderby'], 'order' => $clean_request['order'] );
1839
- self::$query_parameters['detached'] = isset( $clean_request['detached'] ) ? $clean_request['detached'] : NULL;
1840
- self::$search_parameters = array( 'debug' => 'none' );
1841
 
1842
  /*
1843
- * Matching a meta_value to NULL requires a LEFT JOIN to a view and a special WHERE clause
1844
- * Matching a wildcard pattern requires mainpulating the WHERE clause, too
1845
  */
1846
- if ( isset( $clean_request['meta_query']['key'] ) ) {
1847
- self::$query_parameters['use_postmeta_view'] = true;
1848
- self::$query_parameters['postmeta_key'] = $clean_request['meta_query']['key'];
1849
- self::$query_parameters['postmeta_value'] = NULL;
1850
- unset( $clean_request['meta_query'] );
1851
- } elseif ( isset( $clean_request['meta_query']['patterns'] ) ) {
1852
- self::$query_parameters['patterns'] = $clean_request['meta_query']['patterns'];
1853
- unset( $clean_request['meta_query']['patterns'] );
1854
- }
1855
-
1856
- if ( isset( $clean_request['debug'] ) ) {
1857
- self::$query_parameters['debug'] = $clean_request['debug'];
1858
- self::$search_parameters['debug'] = $clean_request['debug'];
1859
- MLA::mla_debug_mode( $clean_request['debug'] );
1860
- unset( $clean_request['debug'] );
1861
- }
1862
 
1863
  /*
1864
- * We must patch the WHERE clause if there are leading spaces in the meta_value
1865
- */
1866
- if ( isset( $clean_request['mla-metavalue'] ) && ( 0 < strlen( $clean_request['mla-metavalue'] ) ) && ( ' ' == $clean_request['mla-metavalue'][0] ) ) {
1867
- self::$query_parameters['mla-metavalue'] = $clean_request['mla-metavalue'];
1868
- }
1869
-
1870
- /*
1871
- * We will handle "Terms Search" in the mla_query_posts_search_filter.
1872
- */
1873
- if ( isset( $clean_request['mla_terms_search'] ) ) {
1874
- self::$search_parameters['mla_terms_search'] = $clean_request['mla_terms_search'];
1875
-
1876
- /*
1877
- * The Terms Search overrides any terms-based keyword search for now; too complicated.
1878
- */
1879
- if ( isset( $clean_request['mla_search_fields'] ) ) {
1880
- foreach ( $clean_request['mla_search_fields'] as $index => $field ) {
1881
- if ( 'terms' == $field ) {
1882
- unset ( $clean_request['mla_search_fields'][ $index ] );
1883
- }
1884
- }
1885
- }
1886
- }
1887
-
1888
- /*
1889
- * We will handle keyword search in the mla_query_posts_search_filter.
1890
- */
1891
- if ( isset( $clean_request['s'] ) ) {
1892
- self::$search_parameters['s'] = $clean_request['s'];
1893
- 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' ) );
1894
- self::$search_parameters['mla_search_connector'] = $clean_request['mla_search_connector'];
1895
- self::$search_parameters['sentence'] = isset( $clean_request['sentence'] );
1896
- self::$search_parameters['exact'] = isset( $clean_request['exact'] );
1897
-
1898
- if ( in_array( 'alt-text', self::$search_parameters['mla_search_fields'] ) ) {
1899
- self::$query_parameters['use_alt_text_view'] = true;
1900
- }
1901
-
1902
- if ( in_array( 'terms', self::$search_parameters['mla_search_fields'] ) ) {
1903
- self::$search_parameters['mla_search_taxonomies'] = MLAOptions::mla_supported_taxonomies( 'term-search' );
1904
- }
1905
-
1906
- unset( $clean_request['s'] );
1907
- unset( $clean_request['mla_search_connector'] );
1908
- unset( $clean_request['mla_search_fields'] );
1909
- unset( $clean_request['sentence'] );
1910
- unset( $clean_request['exact'] );
1911
- }
1912
-
1913
- /*
1914
- * We have to handle custom field/post_meta values here
1915
- * because they need a JOIN clause supplied by WP_Query
1916
- */
1917
- if ( 'c_' == substr( $clean_request['orderby'], 0, 2 ) ) {
1918
- $option_value = MLAOptions::mla_custom_field_option_value( $clean_request['orderby'] );
1919
- if ( isset( $option_value['name'] ) ) {
1920
- self::$query_parameters['use_orderby_view'] = true;
1921
- self::$query_parameters['postmeta_key'] = $option_value['name'];
1922
-
1923
- if ( isset($clean_request['orderby']) ) {
1924
- unset($clean_request['orderby']);
1925
- }
1926
-
1927
- if ( isset($clean_request['order']) ) {
1928
- unset($clean_request['order']);
1929
- }
1930
- }
1931
- } else { // custom field
1932
- switch ( self::$query_parameters['orderby'] ) {
1933
- /*
1934
- * '_wp_attachment_image_alt' is special; we'll handle it in the JOIN and ORDERBY filters
1935
- */
1936
- case '_wp_attachment_image_alt':
1937
- self::$query_parameters['use_orderby_view'] = true;
1938
- if ( isset($clean_request['orderby']) ) {
1939
- unset($clean_request['orderby']);
1940
- }
1941
-
1942
- if ( isset($clean_request['order']) ) {
1943
- unset($clean_request['order']);
1944
- }
1945
-
1946
- break;
1947
- case '_wp_attached_file':
1948
- $clean_request['meta_key'] = '_wp_attached_file';
1949
- $clean_request['orderby'] = 'meta_value';
1950
- $clean_request['order'] = self::$query_parameters['order'];
1951
- break;
1952
- } // switch $orderby
1953
- }
1954
-
1955
- /*
1956
- * Ignore incoming paged value; use offset and count instead
1957
- */
1958
- if ( ( (int) $count ) > 0 ) {
1959
- $clean_request['offset'] = $offset;
1960
- $clean_request['posts_per_page'] = $count;
1961
- } elseif ( ( (int) $count ) == -1 ) {
1962
- $clean_request['posts_per_page'] = $count;
1963
- }
1964
-
1965
- /*
1966
- * ['mla_filter_term'] - filter by taxonomy
1967
- *
1968
- * cat = 0 is "All Categories", i.e., no filtering
1969
- * cat = -1 is "No Categories"
1970
- */
1971
- if ( isset( $clean_request['mla_filter_term'] ) ) {
1972
- if ( $clean_request['mla_filter_term'] != 0 ) {
1973
- $tax_filter = MLAOptions::mla_taxonomy_support('', 'filter');
1974
- if ( $clean_request['mla_filter_term'] == -1 ) {
1975
- $term_list = get_terms( $tax_filter, array(
1976
- 'fields' => 'ids',
1977
- 'hide_empty' => false
1978
- ) );
1979
- $clean_request['tax_query'] = array(
1980
- array(
1981
- 'taxonomy' => $tax_filter,
1982
- 'field' => 'id',
1983
- 'terms' => $term_list,
1984
- 'operator' => 'NOT IN'
1985
- )
1986
- );
1987
- } else { // mla_filter_term == -1
1988
- $clean_request['tax_query'] = array(
1989
- array(
1990
- 'taxonomy' => $tax_filter,
1991
- 'field' => 'id',
1992
- 'terms' => array(
1993
- (int) $clean_request['mla_filter_term']
1994
- ),
1995
- 'include_children' => ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_TAXONOMY_FILTER_INCLUDE_CHILDREN ) )
1996
- )
1997
- );
1998
- } // mla_filter_term != -1
1999
- } // mla_filter_term != 0
2000
-
2001
- unset( $clean_request['mla_filter_term'] );
2002
- } // isset mla_filter_term
2003
-
2004
- if ( isset( $clean_request['mla-tax'] ) && isset( $clean_request['mla-term'] )) {
2005
- $clean_request['tax_query'] = array(
2006
- array(
2007
- 'taxonomy' => $clean_request['mla-tax'],
2008
- 'field' => 'slug',
2009
- 'terms' => $clean_request['mla-term'],
2010
- 'include_children' => false
2011
- )
2012
- );
2013
-
2014
- unset( $clean_request['mla-tax'] );
2015
- unset( $clean_request['mla-term'] );
2016
- } // isset mla_tax
2017
-
2018
- if ( isset( $clean_request['mla-metakey'] ) && isset( $clean_request['mla-metavalue'] ) ) {
2019
- $clean_request['meta_key'] = $clean_request['mla-metakey'];
2020
- $clean_request['meta_value'] = $clean_request['mla-metavalue'];
2021
-
2022
- unset( $clean_request['mla-metakey'] );
2023
- unset( $clean_request['mla-metavalue'] );
2024
- } // isset mla_tax
2025
-
2026
- return $clean_request;
2027
- }
2028
-
2029
- /**
2030
- * Add filters, run query, remove filters
2031
- *
2032
- * @since 0.30
2033
- *
2034
- * @param array query parameters from web page, usually found in $_REQUEST
2035
- *
2036
- * @return object WP_Query object with query results
2037
- */
2038
- private static function _execute_list_table_query( $request ) {
2039
- global $wpdb;
2040
-
2041
- /*
2042
- * ALT Text searches, custom field Table Views and custom field sorts are
2043
- * special; we have to use an SQL VIEW to build an intermediate table and
2044
- * modify the JOIN to include posts with no value for the metadata field.
2045
- */
2046
- if ( self::$query_parameters['use_alt_text_view'] ) {
2047
- $alt_text_view_name = self::$mla_alt_text_view;
2048
- $key_name = '_wp_attachment_image_alt';
2049
- $table_name = $wpdb->postmeta;
2050
-
2051
- $result = $wpdb->query(
2052
- "
2053
- CREATE OR REPLACE VIEW {$alt_text_view_name} AS
2054
- SELECT post_id, meta_value
2055
- FROM {$table_name}
2056
- WHERE {$table_name}.meta_key = '{$key_name}'
2057
- "
2058
- );
2059
- }
2060
-
2061
- if ( self::$query_parameters['use_postmeta_view'] ) {
2062
- $postmeta_view_name = self::$mla_table_view_custom;
2063
- $key_name = self::$query_parameters['postmeta_key'];
2064
- $table_name = $wpdb->postmeta;
2065
-
2066
- $result = $wpdb->query(
2067
- "
2068
- CREATE OR REPLACE VIEW {$postmeta_view_name} AS
2069
- SELECT post_id, meta_value
2070
- FROM {$table_name}
2071
- WHERE {$table_name}.meta_key = '{$key_name}'
2072
- "
2073
- );
2074
- }
2075
-
2076
- if ( self::$query_parameters['use_orderby_view'] ) {
2077
- $orderby_view_name = self::$mla_orderby_view;
2078
- $key_name = self::$query_parameters['postmeta_key'];
2079
- $table_name = $wpdb->postmeta;
2080
-
2081
- $result = $wpdb->query(
2082
- "
2083
- CREATE OR REPLACE VIEW {$orderby_view_name} AS
2084
- SELECT post_id, meta_value
2085
- FROM {$table_name}
2086
- WHERE {$table_name}.meta_key = '{$key_name}'
2087
- "
2088
- );
2089
- }
2090
-
2091
- add_filter( 'posts_search', 'MLAData::mla_query_posts_search_filter', 10, 2 ); // $search, &$this
2092
- add_filter( 'posts_where', 'MLAData::mla_query_posts_where_filter' );
2093
- add_filter( 'posts_join', 'MLAData::mla_query_posts_join_filter' );
2094
- add_filter( 'posts_groupby', 'MLAData::mla_query_posts_groupby_filter' );
2095
- add_filter( 'posts_orderby', 'MLAData::mla_query_posts_orderby_filter' );
2096
-
2097
- /*
2098
- * Disable Relevanssi - A Better Search, v3.2 by Mikko Saari
2099
- * relevanssi_prevent_default_request( $request, $query )
2100
- * apply_filters('relevanssi_admin_search_ok', $admin_search_ok, $query );
2101
- */
2102
- if ( function_exists( 'relevanssi_prevent_default_request' ) ) {
2103
- add_filter( 'relevanssi_admin_search_ok', 'MLAData::mla_query_relevanssi_admin_search_ok_filter' );
2104
- }
2105
-
2106
- if ( isset( self::$query_parameters['debug'] ) ) {
2107
- global $wp_filter;
2108
- $debug_array = array( 'posts_search' => $wp_filter['posts_search'], 'posts_join' => $wp_filter['posts_join'], 'posts_where' => $wp_filter['posts_where'], 'posts_orderby' => $wp_filter['posts_orderby'] );
2109
-
2110
- /* translators: 1: DEBUG tag 2: query filter details */
2111
- MLA::mla_debug_add( sprintf( _x( '%1$s: _execute_list_table_query $wp_filter = "%2$s".', 'error_log', 'media-library-assistant' ), __( 'DEBUG', 'media-library-assistant' ), var_export( $debug_array, true ) ) );
2112
-
2113
- add_filter( 'posts_clauses', 'MLAData::mla_query_posts_clauses_filter', 0x7FFFFFFF, 1 );
2114
- add_filter( 'posts_clauses_request', 'MLAData::mla_query_posts_clauses_request_filter', 0x7FFFFFFF, 1 );
2115
- } // debug
2116
-
2117
- $results = new WP_Query( $request );
2118
-
2119
- if ( isset( self::$query_parameters['debug'] ) ) {
2120
- remove_filter( 'posts_clauses', 'MLAData::mla_query_posts_clauses_filter', 0x7FFFFFFF );
2121
- remove_filter( 'posts_clauses_request', 'MLAData::mla_query_posts_clauses_request_filter', 0x7FFFFFFF );
2122
-
2123
- $debug_array = array( 'request' => $request, 'query_parameters' => self::$query_parameters, 'post_count' => $results->post_count, 'found_posts' => $results->found_posts );
2124
-
2125
- /* translators: 1: DEBUG tag 2: query details */
2126
- MLA::mla_debug_add( sprintf( _x( '%1$s: _execute_list_table_query WP_Query = "%2$s".', 'error_log', 'media-library-assistant' ), __( 'DEBUG', 'media-library-assistant' ), var_export( $debug_array, true ) ) );
2127
- /* translators: 1: DEBUG tag 2: SQL statement */
2128
- MLA::mla_debug_add( sprintf( _x( '%1$s: _execute_list_table_query SQL_request = "%2$s".', 'error_log', 'media-library-assistant' ), __( 'DEBUG', 'media-library-assistant' ), var_export( $results->request, true ) ) );
2129
- } // debug
2130
-
2131
- if ( function_exists( 'relevanssi_prevent_default_request' ) ) {
2132
- remove_filter( 'relevanssi_admin_search_ok', 'MLAData::mla_query_relevanssi_admin_search_ok_filter' );
2133
- }
2134
-
2135
- remove_filter( 'posts_orderby', 'MLAData::mla_query_posts_orderby_filter' );
2136
- remove_filter( 'posts_groupby', 'MLAData::mla_query_posts_groupby_filter' );
2137
- remove_filter( 'posts_join', 'MLAData::mla_query_posts_join_filter' );
2138
- remove_filter( 'posts_where', 'MLAData::mla_query_posts_where_filter' );
2139
- remove_filter( 'posts_search', 'MLAData::mla_query_posts_search_filter' );
2140
-
2141
- if ( self::$query_parameters['use_alt_text_view'] ) {
2142
- $result = $wpdb->query( "DROP VIEW {$alt_text_view_name}" );
2143
- }
2144
-
2145
- if ( self::$query_parameters['use_postmeta_view'] ) {
2146
- $result = $wpdb->query( "DROP VIEW {$postmeta_view_name}" );
2147
- }
2148
-
2149
- if ( self::$query_parameters['use_orderby_view'] ) {
2150
- $result = $wpdb->query( "DROP VIEW {$orderby_view_name}" );
2151
- }
2152
-
2153
- return $results;
2154
- }
2155
-
2156
- /**
2157
- * Detects wildcard searches, i.e., containing an asterisk outside quotes
2158
- *
2159
- * Defined as public because it's a callback from array_map().
2160
- *
2161
- * @since 2.13
2162
- *
2163
- * @param string search string
2164
- *
2165
- * @return boolean true if wildcard
2166
- */
2167
- private static function _wildcard_search_string( $search_string ) {
2168
- preg_match_all('/".*?("|$)|((?<=[\t ",+])|^)[^\t ",+]+/', $search_string, $matches);
2169
-
2170
- if ( is_array( $matches ) ) {
2171
- foreach ( $matches[0] as $term ) {
2172
- if ( '"' == substr( $term, 0, 1) ) {
2173
- continue;
2174
- }
2175
-
2176
- if ( false !== strpos( $term, '*' ) ) {
2177
- return true;
2178
- }
2179
- }
2180
- }
2181
-
2182
- return false;
2183
- }
2184
-
2185
- /**
2186
- * Replaces a WordPress function deprecated in v3.7
2187
- *
2188
- * Defined as public because it's a callback from array_map().
2189
- *
2190
- * @since 1.51
2191
- *
2192
- * @param string search term before modification
2193
- *
2194
- * @return string cleaned up search term
2195
- */
2196
- public static function mla_search_terms_tidy( $term ) {
2197
- return trim( $term, "\"'\n\r " );
2198
- }
2199
-
2200
- /**
2201
- * Isolates keyword match results to word boundaries
2202
- *
2203
- * Eliminates matches such as "man" in "woman".
2204
- *
2205
- * @since 2.11
2206
- *
2207
- * @param string the quoted phrase (without enclosing quotes)
2208
- * @param string the entire term
2209
- *
2210
- * @return boolean $needle is a word match within $haystack
2211
- */
2212
- private static function _match_quoted_phrase( $needle, $haystack ) {
2213
- $haystack = strtolower( html_entity_decode( $haystack ) );
2214
- $needle = strtolower( html_entity_decode( $needle ) );
2215
-
2216
- // Escape the PCRE meta-characters
2217
- $safe_needle = '';
2218
- for ( $index = 0; $index < strlen( $needle ); $index++ ) {
2219
- $chr = $needle[ $index ];
2220
- if ( false !== strpos( '\\^$.[]()?*+{}/', $chr ) ) {
2221
- $safe_needle .= '\\';
2222
- }
2223
- $safe_needle .= $chr;
2224
- }
2225
-
2226
- $pattern = '/^' . $safe_needle . '$|^' . $safe_needle . '\s+|\s+' . $safe_needle . '\s+|\s+' . $safe_needle . '$/';
2227
- $match_count = preg_match_all($pattern, $haystack, $matches);
2228
- return 0 < $match_count;
2229
- }
2230
-
2231
- /**
2232
- * Adds a keyword search to the WHERE clause, if required
2233
- *
2234
- * Defined as public because it's a filter.
2235
- *
2236
- * @since 0.60
2237
- *
2238
- * @param string query clause before modification
2239
- * @param object WP_Query object
2240
- *
2241
- * @return string query clause after keyword search addition
2242
- */
2243
- public static function mla_query_posts_search_filter( $search_string, &$query_object ) {
2244
- global $wpdb;
2245
-
2246
- $numeric_clause = '';
2247
- $search_clause = '';
2248
- $tax_clause = '';
2249
- $tax_connector = 'AND';
2250
- $tax_index = 0;
2251
-
2252
- /*
2253
- * Process the Terms Search arguments, if present.
2254
- */
2255
- if ( isset( self::$search_parameters['mla_terms_search']['phrases'] ) ) {
2256
- $terms_search_parameters = self::$search_parameters['mla_terms_search'];
2257
- $terms = array_map( 'trim', explode( ',', $terms_search_parameters['phrases'] ) );
2258
- if ( 1 < count( $terms ) ) {
2259
- $terms_connector = '(';
2260
- } else {
2261
- $terms_connector = '';
2262
- }
2263
-
2264
- foreach ( $terms as $term ) {
2265
- preg_match_all('/".*?("|$)|\'.*?(\'|$)|((?<=[\t ",+])|^)[^\t ",+]+/', $term, $matches);
2266
- $phrases = array_map('MLAData::mla_search_terms_tidy', $matches[0]);
2267
-
2268
- /*
2269
- * Find the quoted phrases for a word-boundary check
2270
- */
2271
- $quoted = array();
2272
- foreach ( $phrases as $index => $phrase ) {
2273
- $quoted[ $index ] = ( '"' == $matches[1][$index] ) || ( "'" == $matches[2][$index] );
2274
- }
2275
-
2276
- $tax_terms = array();
2277
- $tax_counts = array();
2278
- foreach ( $phrases as $index => $phrase ) {
2279
- if ( isset( $terms_search_parameters['exact'] ) ) {
2280
- $the_terms = array();
2281
- foreach( $terms_search_parameters['taxonomies'] as $taxonomy ) {
2282
- // WordPress encodes special characters, e.g., "&" as HTML entities in term names
2283
- $the_term = get_term_by( 'name', _wp_specialchars( $phrase ), $taxonomy );
2284
- if ( false !== $the_term ) {
2285
- $the_terms[] = $the_term;
2286
- }
2287
- }
2288
- } else {
2289
- $is_wildcard_search = ( ! $quoted[ $index ] ) && self::_wildcard_search_string( $phrase );
2290
-
2291
- if ( $is_wildcard_search ) {
2292
- add_filter( 'terms_clauses', 'MLAData::mla_query_terms_clauses_filter', 0x7FFFFFFF, 3 );
2293
- }
2294
-
2295
- // WordPress encodes special characters, e.g., "&" as HTML entities in term names
2296
- $the_terms = get_terms( $terms_search_parameters['taxonomies'], array( 'name__like' => _wp_specialchars( $phrase ), 'fields' => 'all', 'hide_empty' => false ) );
2297
-
2298
- if ( $is_wildcard_search ) {
2299
- remove_filter( 'terms_clauses', 'MLAData::mla_query_terms_clauses_filter', 0x7FFFFFFF );
2300
- }
2301
-
2302
- // Invalid taxonomy will return WP_Error object
2303
- if ( ! is_array( $the_terms ) ) {
2304
- $the_terms = array();
2305
- }
2306
-
2307
- if ( $quoted[ $index ] ) {
2308
- foreach ( $the_terms as $term_index => $the_term ) {
2309
- if ( ! self::_match_quoted_phrase( $phrase, $the_term->name ) ) {
2310
- unset( $the_terms[ $term_index ]);
2311
- }
2312
- }
2313
- } // quoted phrase
2314
- } // not exact
2315
-
2316
- foreach( $the_terms as $the_term ) {
2317
- $tax_terms[ $the_term->taxonomy ][ $the_term->term_id ] = (integer) $the_term->term_taxonomy_id;
2318
-
2319
- if ( isset( $tax_counts[ $the_term->taxonomy ][ $the_term->term_id ] ) ) {
2320
- $tax_counts[ $the_term->taxonomy ][ $the_term->term_id ]++;
2321
- } else {
2322
- $tax_counts[ $the_term->taxonomy ][ $the_term->term_id ] = 1;
2323
- }
2324
- }
2325
- } // foreach phrase
2326
-
2327
- /*
2328
- * For the AND connector, a taxonomy term must have all of the search terms within it
2329
- */
2330
- if ( 'AND' == $terms_search_parameters['radio_phrases'] ) {
2331
- $search_term_count = count( $phrases );
2332
- foreach ($tax_terms as $taxonomy => $term_ids ) {
2333
- foreach ( $term_ids as $term_id => $term_taxonomy_id ) {
2334
- if ( $search_term_count != $tax_counts[ $taxonomy ][ $term_id ] ) {
2335
- unset( $term_ids[ $term_id ] );
2336
- }
2337
- }
2338
-
2339
- if ( empty( $term_ids ) ) {
2340
- unset( $tax_terms[ $taxonomy ] );
2341
- } else {
2342
- $tax_terms[ $taxonomy ] = $term_ids;
2343
- }
2344
- } // foreach taxonomy
2345
- } // AND (i.e., All phrases)
2346
-
2347
- if ( ! empty( $tax_terms ) ) {
2348
- $inner_connector = '';
2349
-
2350
- $tax_clause .= $terms_connector;
2351
- foreach( $tax_terms as $tax_term ) {
2352
- if ( 'AND' == $terms_search_parameters['radio_terms'] ) {
2353
- $prefix = 'mlatt' . $tax_index++;
2354
- } else {
2355
- $prefix = 'mlatt0';
2356
- $tax_index = 1; // only one JOIN needed for the "Any Term" case
2357
- }
2358
-
2359
- $tax_clause .= sprintf( '%1$s %2$s.term_taxonomy_id IN (%3$s)', $inner_connector, $prefix, implode( ',', $tax_term ) );
2360
- $inner_connector = ' OR';
2361
- } // foreach tax_term
2362
-
2363
- $terms_connector = ' ) ' . $terms_search_parameters['radio_terms'] . ' (';
2364
- } // tax_terms present
2365
- } // foreach term
2366
-
2367
- if ( 1 < count( $terms ) && ! empty( $tax_clause ) ) {
2368
- $tax_clause .= ')';
2369
- }
2370
-
2371
- if ( empty( $tax_clause ) ) {
2372
- $tax_clause = '1=0';
2373
- } else {
2374
- self::$search_parameters['tax_terms_count'] = $tax_index;
2375
- };
2376
- } // isset mla_terms_search
2377
-
2378
- /*
2379
- * Process the keyword search argument, if present.
2380
- */
2381
- if ( isset( self::$search_parameters['s'] ) ) {
2382
-
2383
- // WordPress v3.7 says: there are no line breaks in <input /> fields
2384
- $keyword_string = stripslashes( str_replace( array( "\r", "\n" ), '', self::$search_parameters['s'] ) );
2385
- $is_wildcard_search = self::_wildcard_search_string( $keyword_string );
2386
-
2387
- if ( $is_wildcard_search || self::$search_parameters['sentence'] || self::$search_parameters['exact'] ) {
2388
- $keyword_array = array( $keyword_string );
2389
- } else {
2390
- // v3.6.1 was '/".*?("|$)|((?<=[\r\n\t ",+])|^)[^\r\n\t ",+]+/'
2391
- preg_match_all('/".*?("|$)|((?<=[\t ",+])|^)[^\t ",+]+/', $keyword_string, $matches);
2392
- $keyword_array = array_map( 'MLAData::mla_search_terms_tidy', $matches[0]);
2393
- $numeric_array = array_filter( $keyword_array, 'is_numeric' );
2394
-
2395
- /*
2396
- * If all the "keywords" are numeric, interpret it/them as the ID(s) of a specific attachment
2397
- * or the ID(s) of a parent post/page; add it/them to the regular text-based search.
2398
- */
2399
- if ( count( $keyword_array ) == count( $numeric_array ) ) {
2400
- $numeric_array = implode( ',', $numeric_array );
2401
- $numeric_clause = '( ( ' . $wpdb->posts . '.ID IN (' . $numeric_array . ') ) OR ( ' . $wpdb->posts . '.post_parent IN (' . $numeric_array . ') ) ) OR ';
2402
-
2403
- }
2404
- }
2405
-
2406
- $fields = self::$search_parameters['mla_search_fields'];
2407
- $allow_terms_search = in_array( 'terms', $fields ) && ( ! $is_wildcard_search );
2408
- $percent = self::$search_parameters['exact'] ? '' : '%';
2409
- $connector = '';
2410
-
2411
- if ( empty( $fields ) ) {
2412
- $search_clause = '1=0';
2413
- } else {
2414
- $tax_terms = array();
2415
- $tax_counts = array();
2416
- foreach ( $keyword_array as $term ) {
2417
- if ( $is_wildcard_search ) {
2418
- /*
2419
- * Escape any % in the source string
2420
- */
2421
- if ( self::$wp_4dot0_plus ) {
2422
- $sql_term = $wpdb->esc_like( $term );
2423
- $sql_term = $wpdb->prepare( '%s', $sql_term );
2424
- } else {
2425
- $sql_term = "'" . esc_sql( like_escape( $term ) ) . "'";
2426
- }
2427
-
2428
- /*
2429
- * Convert wildcard * to SQL %
2430
- */
2431
- $sql_term = str_replace( '*', '%', $sql_term );
2432
- } else {
2433
- if ( self::$wp_4dot0_plus ) {
2434
- $sql_term = $percent . $wpdb->esc_like( $term ) . $percent;
2435
- $sql_term = $wpdb->prepare( '%s', $sql_term );
2436
- } else {
2437
- $sql_term = "'" . $percent . esc_sql( like_escape( $term ) ) . $percent . "'";
2438
- }
2439
- }
2440
-
2441
- $inner_connector = '';
2442
- $inner_clause = '';
2443
-
2444
- if ( in_array( 'content', $fields ) ) {
2445
- $inner_clause .= "{$inner_connector}({$wpdb->posts}.post_content LIKE {$sql_term})";
2446
- $inner_connector = ' OR ';
2447
- }
2448
-
2449
- if ( in_array( 'title', $fields ) ) {
2450
- $inner_clause .= "{$inner_connector}({$wpdb->posts}.post_title LIKE {$sql_term})";
2451
- $inner_connector = ' OR ';
2452
- }
2453
-
2454
- if ( in_array( 'excerpt', $fields ) ) {
2455
- $inner_clause .= "{$inner_connector}({$wpdb->posts}.post_excerpt LIKE {$sql_term})";
2456
- $inner_connector = ' OR ';
2457
- }
2458
-
2459
- if ( in_array( 'alt-text', $fields ) ) {
2460
- $view_name = self::$mla_alt_text_view;
2461
- $inner_clause .= "{$inner_connector}({$view_name}.meta_value LIKE {$sql_term})";
2462
- $inner_connector = ' OR ';
2463
- }
2464
-
2465
- if ( in_array( 'name', $fields ) ) {
2466
- $inner_clause .= "{$inner_connector}({$wpdb->posts}.post_name LIKE {$sql_term})";
2467
- }
2468
-
2469
- $inner_clause = apply_filters( 'mla_list_table_search_filter_inner_clause', $inner_clause, $inner_connector, $wpdb->posts, $sql_term );
2470
-
2471
- if ( ! empty($inner_clause) ) {
2472
- $search_clause .= "{$connector}({$inner_clause})";
2473
- $connector = ' ' . self::$search_parameters['mla_search_connector'] . ' ';
2474
- }
2475
-
2476
- /*
2477
- * Convert search term text to term_taxonomy_id value(s),
2478
- * separated by taxonomy.
2479
- */
2480
- if ( $allow_terms_search ) {
2481
- // WordPress encodes special characters, e.g., "&" as HTML entities in term names
2482
- $the_terms = get_terms( self::$search_parameters['mla_search_taxonomies'], array( 'name__like' => _wp_specialchars( $term ), 'fields' => 'all', 'hide_empty' => false ) );
2483
- // Invalid taxonomy will return WP_Error object
2484
- if ( ! is_array( $the_terms ) ) {
2485
- $the_terms = array();
2486
- }
2487
-
2488
- foreach( $the_terms as $the_term ) {
2489
- $tax_terms[ $the_term->taxonomy ][ $the_term->term_id ] = (integer) $the_term->term_taxonomy_id;
2490
-
2491
- if ( isset( $tax_counts[ $the_term->taxonomy ][ $the_term->term_id ] ) ) {
2492
- $tax_counts[ $the_term->taxonomy ][ $the_term->term_id ]++;
2493
- } else {
2494
- $tax_counts[ $the_term->taxonomy ][ $the_term->term_id ] = 1;
2495
- }
2496
- }
2497
- } // in_array terms
2498
- } // foreach term
2499
-
2500
- if ( $allow_terms_search ) {
2501
- /*
2502
- * For the AND connector, a taxonomy term must have all of the search terms within it
2503
- */
2504
- if ( 'AND' == self::$search_parameters['mla_search_connector'] ) {
2505
- $search_term_count = count( $keyword_array );
2506
- foreach ($tax_terms as $taxonomy => $term_ids ) {
2507
- foreach ( $term_ids as $term_id => $term_taxonomy_id ) {
2508
- if ( $search_term_count != $tax_counts[ $taxonomy ][ $term_id ] ) {
2509
- unset( $term_ids[ $term_id ] );
2510
- }
2511
- }
2512
-
2513
- if ( empty( $term_ids ) ) {
2514
- unset( $tax_terms[ $taxonomy ] );
2515
- } else {
2516
- $tax_terms[ $taxonomy ] = $term_ids;
2517
- }
2518
- } // foreach taxonomy
2519
- } // AND connector
2520
-
2521
- if ( empty( $tax_terms ) ) {
2522
- /*
2523
- * If "Terms" is the only field and no terms are present,
2524
- * the search must fail.
2525
- */
2526
- if ( ( 1 == count( $fields ) ) && ( 'terms' == array_shift( $fields ) ) ) {
2527
- $tax_clause = '1=0';
2528
- }
2529
- } else {
2530
- $tax_index = 0;
2531
- $inner_connector = '';
2532
-
2533
- foreach( $tax_terms as $tax_term ) {
2534
- $prefix = 'mlatt' . $tax_index++;
2535
- $tax_clause .= sprintf( '%1$s %2$s.term_taxonomy_id IN (%3$s)', $inner_connector, $prefix, implode( ',', $tax_term ) );
2536
- $inner_connector = ' OR';
2537
- } // foreach tax_term
2538
-
2539
- self::$search_parameters['tax_terms_count'] = $tax_index;
2540
- $tax_connector = 'OR';
2541
- } // tax_terms present
2542
- } // terms in fields
2543
- } // fields not empty
2544
- } // isset 's'
2545
-
2546
- if ( ! empty( $tax_clause ) && ! empty( $search_clause ) ) {
2547
- $tax_clause = " {$tax_connector} ({$tax_clause} )";
2548
- }
2549
-
2550
- if ( ! empty( $search_clause ) || ! empty( $tax_clause ) ) {
2551
- $search_clause = " AND ( {$numeric_clause}{$search_clause}{$tax_clause} ) ";
2552
-
2553
- if ( ! is_user_logged_in() ) {
2554
- $search_clause .= " AND ( {$wpdb->posts}.post_password = '' ) ";
2555
- }
2556
- }
2557
-
2558
- if ( 'none' != self::$search_parameters['debug'] ) {
2559
- $debug_array['search_string'] = $search_string;
2560
- $debug_array['search_parameters'] = self::$search_parameters;
2561
- $debug_array['search_clause'] = $search_clause;
2562
-
2563
- if ( 'shortcode' == self::$search_parameters['debug'] ) {
2564
- MLA::mla_debug_add( '<strong>mla_debug posts_search filter</strong> = ' . var_export( $debug_array, true ) );
2565
- } else {
2566
- /* translators: 1: DEBUG tag 2: search filter details */
2567
- MLA::mla_debug_add( sprintf( _x( '%1$s: mla_query_posts_search_filter = "%2$s".', 'error_log', 'media-library-assistant' ), __( 'DEBUG', 'media-library-assistant' ), var_export( $debug_array, true ) ) );
2568
- }
2569
- } // debug
2570
-
2571
- return $search_clause;
2572
- }
2573
-
2574
- /**
2575
- * Adds/modifies the WHERE clause for meta values, LIKE patterns and detached items
2576
- *
2577
- * Modeled after _edit_attachments_query_helper in wp-admin/post.php.
2578
- * Defined as public because it's a filter.
2579
- *
2580
- * @since 0.1
2581
- *
2582
- * @param string query clause before modification
2583
- *
2584
- * @return string query clause after modification
2585
- */
2586
- public static function mla_query_posts_where_filter( $where_clause ) {
2587
- global $wpdb;
2588
-
2589
- if ( isset( self::$query_parameters['debug'] ) ) {
2590
- $debug_array = array( 'where_string' => $where_clause );
2591
- }
2592
-
2593
- /*
2594
- * WordPress filters meta_value thru trim() - which we must reverse
2595
- */
2596
- if ( isset( self::$query_parameters['mla-metavalue'] ) ) {
2597
- if ( is_array( self::$query_parameters['mla-metavalue'] ) ) {
2598
- foreach ( self::$query_parameters['mla-metavalue'] as $pattern => $replacement ) {
2599
- $where_clause = preg_replace( '/(^.*meta_value AS CHAR\) = \')(' . $pattern . '[^\']*)/m', '${1}' . $replacement, $where_clause );
2600
- }
2601
- } else {
2602
- $where_clause = preg_replace( '/(^.*meta_value AS CHAR\) = \')([^\']*)/m', '${1}' . self::$query_parameters['mla-metavalue'], $where_clause );
2603
- }
2604
- }
2605
-
2606
- /*
2607
- * Matching a NULL meta value
2608
- */
2609
- if ( array_key_exists( 'postmeta_value', self::$query_parameters ) && NULL == self::$query_parameters['postmeta_value'] ) {
2610
- $where_clause .= ' AND ' . self::$mla_table_view_custom . '.meta_value IS NULL';
2611
- }
2612
-
2613
- /*
2614
- * WordPress modifies the LIKE clause - which we must reverse
2615
- */
2616
- if ( isset( self::$query_parameters['patterns'] ) ) {
2617
- foreach ( self::$query_parameters['patterns'] as $pattern ) {
2618
- $pattern = str_replace( '_', '\\\\_', $pattern );
2619
- $match_clause = '%' . str_replace( '%', '\\\\%', $pattern ) . '%';
2620
- $where_clause = str_replace( "LIKE '{$match_clause}'", "LIKE '{$pattern}'", $where_clause );
2621
- }
2622
- }
2623
-
2624
- /*
2625
- * Unattached items require some help
2626
- */
2627
- if ( isset( self::$query_parameters['detached'] ) ) {
2628
- if ( '1' == self::$query_parameters['detached'] ) {
2629
- $where_clause .= sprintf( ' AND %1$s.post_parent < 1', $wpdb->posts );
2630
- } elseif ( '0' == self::$query_parameters['detached'] ) {
2631
- $where_clause .= sprintf( ' AND %1$s.post_parent > 0', $wpdb->posts );
2632
- }
2633
- }
2634
-
2635
- if ( isset( self::$query_parameters['debug'] ) ) {
2636
- $debug_array['where_clause'] = $where_clause;
2637
-
2638
- /* translators: 1: DEBUG tag 2: where filter details */
2639
- MLA::mla_debug_add( sprintf( _x( '%1$s: mla_query_posts_where_filter = "%2$s".', 'error_log', 'media-library-assistant' ), __( 'DEBUG', 'media-library-assistant' ), var_export( $debug_array, true ) ) );
2640
- } // debug
2641
-
2642
- return $where_clause;
2643
- }
2644
-
2645
- /**
2646
- * Adds a JOIN clause, if required, to handle sorting/searching on custom fields or ALT Text
2647
- *
2648
- * Defined as public because it's a filter.
2649
- *
2650
- * @since 0.30
2651
- *
2652
- * @param string query clause before modification
2653
- *
2654
- * @return string query clause after "LEFT JOIN view ON post_id" item modification
2655
- */
2656
- public static function mla_query_posts_join_filter( $join_clause ) {
2657
- global $wpdb;
2658
-
2659
- if ( isset( self::$query_parameters['debug'] ) ) {
2660
- $debug_array = array( 'join_string' => $join_clause );
2661
- }
2662
-
2663
- /*
2664
- * ALT Text searches, custom field Table Views and custom field sorts are
2665
- * special; we have to use an SQL VIEW to build an intermediate table and
2666
- * modify the JOIN to include posts with no value for this metadata field.
2667
- */
2668
- if ( self::$query_parameters['use_alt_text_view'] ) {
2669
- $join_clause .= sprintf( ' LEFT JOIN %1$s ON (%2$s.ID = %1$s.post_id)', self::$mla_alt_text_view, $wpdb->posts );
2670
- }
2671
-
2672
- if ( self::$query_parameters['use_postmeta_view'] ) {
2673
- $join_clause .= sprintf( ' LEFT JOIN %1$s ON (%2$s.ID = %1$s.post_id)', self::$mla_table_view_custom, $wpdb->posts );
2674
- }
2675
-
2676
- if ( self::$query_parameters['use_orderby_view'] ) {
2677
- $join_clause .= sprintf( ' LEFT JOIN %1$s ON (%2$s.ID = %1$s.post_id)', self::$mla_orderby_view, $wpdb->posts );
2678
- }
2679
-
2680
- /*
2681
- * custom field sorts are special; we have to use an SQL VIEW to
2682
- * build an intermediate table and modify the JOIN to include posts with
2683
- * no value for this metadata field.
2684
- */
2685
- if ( isset( self::$query_parameters['orderby'] ) ) {
2686
- if ( ( 'c_' == substr( self::$query_parameters['orderby'], 0, 2 ) ) || ( '_wp_attachment_image_alt' == self::$query_parameters['orderby'] ) ) {
2687
- $orderby = self::$mla_orderby_view . '.meta_value';
2688
- }
2689
- }
2690
-
2691
- if ( isset( self::$search_parameters['tax_terms_count'] ) ) {
2692
- $tax_index = 0;
2693
- $tax_clause = '';
2694
-
2695
- while ( $tax_index < self::$search_parameters['tax_terms_count'] ) {
2696
- $prefix = 'mlatt' . $tax_index++;
2697
- $tax_clause .= sprintf( ' LEFT JOIN %1$s AS %2$s ON (%3$s.ID = %2$s.object_id)', $wpdb->term_relationships, $prefix, $wpdb->posts );
2698
- }
2699
-
2700
- $join_clause .= $tax_clause;
2701
- }
2702
-
2703
- if ( isset( self::$query_parameters['debug'] ) ) {
2704
- $debug_array['join_clause'] = $join_clause;
2705
-
2706
- /* translators: 1: DEBUG tag 2: join filter details */
2707
- MLA::mla_debug_add( sprintf( _x( '%1$s: mla_query_posts_join_filter = "%2$s".', 'error_log', 'media-library-assistant' ), __( 'DEBUG', 'media-library-assistant' ), var_export( $debug_array, true ) ) );
2708
- } // debug
2709
-
2710
- return $join_clause;
2711
- }
2712
-
2713
- /**
2714
- * Adds a GROUPBY clause, if required
2715
- *
2716
- * Taxonomy text queries and postmeta queries can return multiple results for the same ID.
2717
- * Defined as public because it's a filter.
2718
- *
2719
- * @since 1.90
2720
- *
2721
- * @param string query clause before modification
2722
- *
2723
- * @return string updated query clause
2724
- */
2725
- public static function mla_query_posts_groupby_filter( $groupby_clause ) {
2726
- global $wpdb;
2727
-
2728
- // if ( ( isset( self::$query_parameters['use_postmeta_view'] ) && self::$query_parameters['use_postmeta_view'] ) || ( isset( self::$query_parameters['use_alt_text_view'] ) && self::$query_parameters['use_alt_text_view'] ) || isset( self::$search_parameters['tax_terms_count'] ) ) {
2729
- if ( ( ! empty( self::$query_parameters['use_postmeta_view'] ) ) || ( ! empty( self::$query_parameters['use_alt_text_view'] ) ) || ( ! empty( self::$query_parameters['use_orderby_view'] ) ) || isset( self::$search_parameters['tax_terms_count'] ) ) {
2730
- $groupby_clause = "{$wpdb->posts}.ID";
2731
- }
2732
-
2733
- return $groupby_clause;
2734
- }
2735
-
2736
- /**
2737
- * Adds a ORDERBY clause, if required
2738
- *
2739
- * Expands the range of sort options because the logic in WP_Query is limited.
2740
- * Defined as public because it's a filter.
2741
- *
2742
- * @since 0.30
2743
- *
2744
- * @param string query clause before modification
2745
- *
2746
- * @return string updated query clause
2747
- */
2748
- public static function mla_query_posts_orderby_filter( $orderby_clause ) {
2749
- global $wpdb;
2750
-
2751
- if ( isset( self::$query_parameters['debug'] ) ) {
2752
- $debug_array = array( 'orderby_string' => $orderby_clause );
2753
- }
2754
-
2755
- if ( isset( self::$query_parameters['orderby'] ) ) {
2756
- if ( 'c_' == substr( self::$query_parameters['orderby'], 0, 2 ) ) {
2757
- $orderby = self::$mla_orderby_view . '.meta_value';
2758
- } /* custom field sort */ else {
2759
- switch ( self::$query_parameters['orderby'] ) {
2760
- case 'none':
2761
- $orderby = '';
2762
- $orderby_clause = '';
2763
- break;
2764
- /*
2765
- * post__in is passed from Media Manager Modal Window
2766
- */
2767
- case 'post__in':
2768
- return $orderby_clause;
2769
- /*
2770
- * There are two columns defined that end up sorting on post_title,
2771
- * so we can't use the database column to identify the column but
2772
- * we actually sort on the database column.
2773
- */
2774
- case 'title_name':
2775
- $orderby = $wpdb->posts . '.post_title';
2776
- break;
2777
- /*
2778
- * The _wp_attached_file meta data value is present for all attachments, and the
2779
- * sorting on the meta data value is handled by WP_Query
2780
- */
2781
- case '_wp_attached_file':
2782
- $orderby = '';
2783
- break;
2784
- /*
2785
- * The _wp_attachment_image_alt value is only present for images, so we have to
2786
- * use the view we prepared to get attachments with no meta data value
2787
- */
2788
- case '_wp_attachment_image_alt':
2789
- $orderby = self::$mla_orderby_view . '.meta_value';
2790
- break;
2791
- default:
2792
- $orderby = $wpdb->posts . '.' . self::$query_parameters['orderby'];
2793
- } // $query_parameters['orderby']
2794
- }
2795
-
2796
- if ( ! empty( $orderby ) ) {
2797
- $orderby_clause = $orderby . ' ' . self::$query_parameters['order'];
2798
- }
2799
- } // isset
2800
-
2801
- if ( isset( self::$query_parameters['debug'] ) ) {
2802
- $debug_array['orderby_clause'] = $orderby_clause;
2803
-
2804
- /* translators: 1: DEBUG tag 2: orderby details details */
2805
- MLA::mla_debug_add( sprintf( _x( '%1$s: mla_query_posts_orderby_filter = "%2$s".', 'error_log', 'media-library-assistant' ), __( 'DEBUG', 'media-library-assistant' ), var_export( $debug_array, true ) ) );
2806
- } // debug
2807
-
2808
- return $orderby_clause;
2809
- }
2810
-
2811
- /**
2812
- * Disable Relevanssi - A Better Search, v3.2 by Mikko Saari
2813
- * Defined as public because it's a filter.
2814
- *
2815
- * @since 1.80
2816
- *
2817
- * @param boolean Default setting
2818
- *
2819
- * @return boolean Updated setting
2820
- */
2821
- public static function mla_query_relevanssi_admin_search_ok_filter( $admin_search_ok ) {
2822
- return false;
2823
- }
2824
-
2825
- /**
2826
- * Filters all clauses for get_terms queries
2827
- *
2828
- * Defined as public because it's a filter.
2829
- *
2830
- * @since 2.13
2831
- *
2832
- * @param array $pieces Terms query SQL clauses.
2833
- * @param array $taxonomies An array of taxonomies.
2834
- * @param array $args An array of terms query arguments.
2835
- */
2836
- public static function mla_query_terms_clauses_filter( $pieces, $taxonomies, $args ) {
2837
- global $wpdb;
2838
-
2839
- if ( empty( $args['name__like'] ) ) {
2840
- return $pieces;
2841
- }
2842
-
2843
- $term = $args['name__like'];
2844
-
2845
- /*
2846
- * Escape any % in the source string
2847
- */
2848
- if ( self::$wp_4dot0_plus ) {
2849
- $sql_term = $wpdb->esc_like( $term );
2850
- $sql_term = $wpdb->prepare( '%s', $sql_term );
2851
- } else {
2852
- $sql_term = "'" . esc_sql( like_escape( $term ) ) . "'";
2853
- }
2854
-
2855
- /*
2856
- * Convert wildcard * to SQL %
2857
- */
2858
- $sql_term = str_replace( '*', '%', $sql_term );
2859
-
2860
- /*
2861
- * Replace the LIKE pattern in the WHERE clause
2862
- */
2863
- $match_clause = '%' . str_replace( '%', '\\\\%', $term ) . '%';
2864
- $pieces['where'] = str_replace( "LIKE '{$match_clause}'", "LIKE {$sql_term}", $pieces['where'] );
2865
-
2866
- return $pieces;
2867
- }
2868
-
2869
- /**
2870
- * Filters all clauses for shortcode queries, pre caching plugins
2871
- *
2872
- * This is for debug purposes only.
2873
- * Defined as public because it's a filter.
2874
- *
2875
- * @since 1.80
2876
- *
2877
- * @param array query clauses before modification
2878
- *
2879
- * @return array query clauses after modification (none)
2880
- */
2881
- public static function mla_query_posts_clauses_filter( $pieces ) {
2882
- /* translators: 1: DEBUG tag 2: SQL clauses */
2883
- MLA::mla_debug_add( sprintf( _x( '%1$s: mla_query_posts_clauses_filter = "%2$s".', 'error_log', 'media-library-assistant' ), __( 'DEBUG', 'media-library-assistant' ), var_export( $pieces, true ) ) );
2884
-
2885
- return $pieces;
2886
- }
2887
-
2888
- /**
2889
- * Filters all clauses for shortcode queries, post caching plugins
2890
- *
2891
- * This is for debug purposes only.
2892
- * Defined as public because it's a filter.
2893
- *
2894
- * @since 1.80
2895
- *
2896
- * @param array query clauses before modification
2897
- *
2898
- * @return array query clauses after modification (none)
2899
- */
2900
- public static function mla_query_posts_clauses_request_filter( $pieces ) {
2901
- /* translators: 1: DEBUG tag 2: SQL clauses */
2902
- MLA::mla_debug_add( sprintf( _x( '%1$s: mla_query_posts_clauses_request_filter = "%2$s".', 'error_log', 'media-library-assistant' ), __( 'DEBUG', 'media-library-assistant' ), var_export( $pieces, true ) ) );
2903
-
2904
- return $pieces;
2905
- }
2906
-
2907
- /**
2908
- * Retrieve an Attachment array given a $post_id
2909
- *
2910
- * The (associative) array will contain every field that can be found in
2911
- * the posts and postmeta tables, and all references to the attachment.
2912
- *
2913
- * @since 0.1
2914
- * @uses $post WordPress global variable
2915
- *
2916
- * @param integer The ID of the attachment post
2917
- * @param boolean True to add references, false to skip references
2918
- *
2919
- * @return NULL|array NULL on failure else associative array
2920
- */
2921
- public static function mla_get_attachment_by_id( $post_id, $add_references = true ) {
2922
- global $post;
2923
- static $save_id = -1, $post_data;
2924
-
2925
- if ( $post_id == $save_id ) {
2926
- return $post_data;
2927
- } elseif ( $post_id == -1 ) {
2928
- $save_id = -1;
2929
- return NULL;
2930
- }
2931
-
2932
- $item = get_post( $post_id );
2933
- if ( empty( $item ) ) {
2934
- /* translators: 1: ERROR tag 2: post ID */
2935
- error_log( sprintf( _x( '%1$s: mla_get_attachment_by_id(%2$d) not found.', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $post_id ), 0 );
2936
- return NULL;
2937
- }
2938
-
2939
- if ( $item->post_type != 'attachment' ) {
2940
- /* translators: 1: ERROR tag 2: post ID 3: post_type */
2941
- error_log( sprintf( _x( '%1$s: mla_get_attachment_by_id(%2$d) wrong post_type "%3$s".', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $post_id, $item->post_type ), 0 );
2942
- return NULL;
2943
- }
2944
-
2945
- $post_data = (array) $item;
2946
- $post = $item;
2947
- setup_postdata( $item );
2948
-
2949
- /*
2950
- * Add parent data
2951
- */
2952
- $post_data = array_merge( $post_data, self::mla_fetch_attachment_parent_data( $post_data['post_parent'] ) );
2953
-
2954
- /*
2955
- * Add meta data
2956
- */
2957
- $post_data = array_merge( $post_data, self::mla_fetch_attachment_metadata( $post_id ) );
2958
-
2959
- /*
2960
- * Add references, if requested, or "empty" references array
2961
- */
2962
- $post_data['mla_references'] = self::mla_fetch_attachment_references( $post_id, $post_data['post_parent'], $add_references );
2963
-
2964
- $save_id = $post_id;
2965
- return $post_data;
2966
- }
2967
-
2968
- /**
2969
- * Returns information about an attachment's parent, if found
2970
- *
2971
- * @since 0.1
2972
- *
2973
- * @param int post ID of attachment's parent, if any
2974
- *
2975
- * @return array Parent information; post_date, post_title and post_type
2976
- */
2977
- public static function mla_fetch_attachment_parent_data( $parent_id ) {
2978
- static $save_id = -1, $parent_data;
2979
-
2980
- if ( $save_id == $parent_id ) {
2981
- return $parent_data;
2982
- } elseif ( $parent_id == -1 ) {
2983
- $save_id = -1;
2984
- return NULL;
2985
- }
2986
-
2987
- $parent_data = array();
2988
- if ( $parent_id ) {
2989
- $parent = get_post( $parent_id );
2990
-
2991
- if ( isset( $parent->post_name ) ) {
2992
- $parent_data['parent_name'] = $parent->post_name;
2993
- }
2994
-
2995
- if ( isset( $parent->post_type ) ) {
2996
- $parent_data['parent_type'] = $parent->post_type;
2997
- }
2998
-
2999
- if ( isset( $parent->post_title ) ) {
3000
- $parent_data['parent_title'] = $parent->post_title;
3001
- }
3002
-
3003
- if ( isset( $parent->post_date ) ) {
3004
- $parent_data['parent_date'] = $parent->post_date;
3005
- }
3006
-
3007
- if ( isset( $parent->post_status ) ) {
3008
- $parent_data['parent_status'] = $parent->post_status;
3009
- }
3010
- }
3011
-
3012
- $save_id = $parent_id;
3013
- return $parent_data;
3014
- }
3015
-
3016
- /**
3017
- * Adds or replaces the value of a key in a possibly nested array structure
3018
- *
3019
- * @since 1.51
3020
- *
3021
- * @param string key value, e.g. array1.array2.element
3022
- * @param mixed replacement value, string or array, by reference
3023
- * @param array PHP nested arrays, by reference
3024
- *
3025
- * @return boolean true if $needle element set, false if not
3026
- */
3027
- private static function _set_array_element( $needle, &$value, &$haystack ) {
3028
- $key_array = explode( '.', $needle );
3029
- $key = array_shift( $key_array );
3030
-
3031
- if ( empty( $key_array ) ) {
3032
- $haystack[ $key ] = $value;
3033
- return true;
3034
- } // lowest level
3035
-
3036
- /*
3037
- * If an intermediate key is not an array, leave it alone and fail.
3038
- * If an intermediate key does not exist, create an empty array for it.
3039
- */
3040
- if ( isset( $haystack[ $key ] ) ) {
3041
- if ( ! is_array( $haystack[ $key ] ) ) {
3042
- return false;
3043
- }
3044
- } else {
3045
- $haystack[ $key ] = array();
3046
- }
3047
-
3048
- return self::_set_array_element( implode( $key_array, '.' ), $value, $haystack[ $key ] );
3049
- }
3050
-
3051
- /**
3052
- * Deletes the value of a key in a possibly nested array structure
3053
- *
3054
- * @since 1.51
3055
- *
3056
- * @param string key value, e.g. array1.array2.element
3057
- * @param array PHP nested arrays, by reference
3058
- *
3059
- * @return boolean true if $needle element found, false if not
3060
- */
3061
- private static function _unset_array_element( $needle, &$haystack ) {
3062
- $key_array = explode( '.', $needle );
3063
- $key = array_shift( $key_array );
3064
-
3065
- if ( empty( $key_array ) ) {
3066
- if ( isset( $haystack[ $key ] ) ) {
3067
- unset( $haystack[ $key ] );
3068
- return true;
3069
- }
3070
-
3071
- return false;
3072
- } // lowest level
3073
-
3074
- if ( isset( $haystack[ $key ] ) ) {
3075
- return self::_unset_array_element( implode( $key_array, '.' ), $haystack[ $key ] );
3076
- }
3077
-
3078
- return false;
3079
- }
3080
-
3081
- /**
3082
- * Finds the value of a key in a possibly nested array structure
3083
- *
3084
- * Used primarily to extract fields from the _wp_attachment_metadata custom field.
3085
- * Also used with the audio/video ID3 metadata exposed in WordPress 3.6 and later.
3086
- *
3087
- * @since 1.30
3088
- *
3089
- * @param string key value, e.g. array1.array2.element
3090
- * @param array PHP nested arrays
3091
- * @param string data option; 'text'|'single'|'export'|'array'|'multi'
3092
- * @param boolean keep existing values - for 'multi' option
3093
- *
3094
- * @return mixed string or array value matching key(.key ...) or ''
3095
- */
3096
- public static function mla_find_array_element( $needle, $haystack, $option, $keep_existing = false ) {
3097
- $key_array = explode( '.', $needle );
3098
- if ( is_array( $key_array ) ) {
3099
- foreach ( $key_array as $key ) {
3100
- /*
3101
- * The '*' key means:
3102
- * 1) needle.* => accept any value, or
3103
- * 2) needle.*.tail => search each sub-array using "tail"
3104
- * and build an array of results.
3105
- */
3106
- if ( '*' == $key ) {
3107
- if ( false !== ( $tail = strpos( $needle, '*.' ) ) ) {
3108
- $tail = substr( $needle, $tail + 2 );
3109
- if ( ! empty( $tail ) ) {
3110
- if ( is_array( $haystack ) ) {
3111
- $results = array();
3112
- foreach ( $haystack as $substack ) {
3113
- $results[] = self::mla_find_array_element( $tail, $substack, $option, $keep_existing );
3114
- }
3115
-
3116
- if ( 1 == count( $results ) ) {
3117
- $haystack = $results[0];
3118
- } else {
3119
- $haystack = $results;
3120
- }
3121
- } else {
3122
- $haystack = '';
3123
- }
3124
- } // found tail
3125
- } // found .*.
3126
-
3127
- break;
3128
- } else {
3129
- if ( is_array( $haystack ) ) {
3130
- if ( isset( $haystack[ $key ] ) ) {
3131
- $haystack = $haystack[ $key ];
3132
- } else {
3133
- $haystack = '';
3134
- }
3135
- } else {
3136
- $haystack = '';
3137
- }
3138
- } // * != key
3139
- } // foreach $key
3140
- } else {
3141
- $haystack = '';
3142
- }
3143
-
3144
- if ( is_array( $haystack ) ) {
3145
- switch ( $option ) {
3146
- case 'single':
3147
- $haystack = current( $haystack );
3148
- break;
3149
- case 'export':
3150
- $haystack = var_export( $haystack, true );
3151
- break;
3152
- case 'unpack':
3153
- if ( is_array( $haystack ) ) {
3154
- $clean_data = array();
3155
- foreach ( $haystack as $key => $value ) {
3156
- if ( is_array( $value ) ) {
3157
- $clean_data[ $key ] = '(ARRAY)';
3158
- } elseif ( is_string( $value ) ) {
3159
- $clean_data[ $key ] = self::_bin_to_utf8( substr( $value, 0, 256 ) );
3160
- } else {
3161
- $clean_data[ $key ] = $value;
3162
- }
3163
- }
3164
-
3165
- $haystack = var_export( $clean_data, true);
3166
- } else {
3167
- $haystack = var_export( $record, true );
3168
- }
3169
- break;
3170
- case 'multi':
3171
- $haystack[0x80000000] = $option;
3172
- $haystack[0x80000001] = $keep_existing;
3173
- // fallthru
3174
- case 'array':
3175
- return $haystack;
3176
- break;
3177
- default:
3178
- $haystack = self::_bin_to_utf8( @implode( ', ', $haystack ) );
3179
- } // $option
3180
- } // is_array
3181
-
3182
- return self::_bin_to_utf8( $haystack );
3183
- } // mla_find_array_element
3184
-
3185
- /**
3186
- * Fetch and filter meta data for an attachment
3187
- *
3188
- * Returns a filtered array of a post's meta data. Internal values beginning with '_'
3189
- * are stripped out or converted to an 'mla_' equivalent.
3190
- *
3191
- * @since 0.1
3192
- *
3193
- * @param int post ID of attachment
3194
- *
3195
- * @return array Meta data variables
3196
- */
3197
- public static function mla_fetch_attachment_metadata( $post_id ) {
3198
- static $save_id = -1, $results;
3199
-
3200
- if ( $save_id == $post_id ) {
3201
- return $results;
3202
- } elseif ( $post_id == -1 ) {
3203
- $save_id = -1;
3204
- return NULL;
3205
- }
3206
-
3207
- $attached_file = NULL;
3208
- $results = array();
3209
- $post_meta = get_metadata( 'post', $post_id );
3210
- if ( is_array( $post_meta ) ) {
3211
- foreach ( $post_meta as $post_meta_key => $post_meta_value ) {
3212
- if ( empty( $post_meta_key ) ) {
3213
- continue;
3214
- }
3215
-
3216
- if ( '_' == $post_meta_key{0} ) {
3217
- if ( stripos( $post_meta_key, '_wp_attached_file' ) === 0 ) {
3218
- $key = 'mla_wp_attached_file';
3219
- $attached_file = $post_meta_value[0];
3220
- } elseif ( stripos( $post_meta_key, '_wp_attachment_metadata' ) === 0 ) {
3221
- $key = 'mla_wp_attachment_metadata';
3222
- } elseif ( stripos( $post_meta_key, '_wp_attachment_image_alt' ) === 0 ) {
3223
- $key = 'mla_wp_attachment_image_alt';
3224
- } else {
3225
- continue;
3226
- }
3227
- } else {
3228
- if ( stripos( $post_meta_key, 'mla_' ) === 0 ) {
3229
- $key = $post_meta_key;
3230
- } else {
3231
- $key = 'mla_item_' . $post_meta_key;
3232
- }
3233
- }
3234
-
3235
- /*
3236
- * At this point, every value is an array; one element per instance of the key.
3237
- * We'll test anyway, just to be sure, then convert single-instance values to a scalar.
3238
- * Metadata array values are serialized for storage in the database.
3239
- */
3240
- if ( is_array( $post_meta_value ) ) {
3241
- if ( count( $post_meta_value ) == 1 ) {
3242
- $post_meta_value = maybe_unserialize( $post_meta_value[0] );
3243
- } else {
3244
- foreach ( $post_meta_value as $single_key => $single_value ) {
3245
- $post_meta_value[ $single_key ] = maybe_unserialize( $single_value );
3246
- }
3247
- }
3248
- }
3249
-
3250
- $results[ $key ] = $post_meta_value;
3251
- } // foreach $post_meta
3252
-
3253
- if ( ! empty( $attached_file ) ) {
3254
- $last_slash = strrpos( $attached_file, '/' );
3255
- if ( false === $last_slash ) {
3256
- $results['mla_wp_attached_path'] = '';
3257
- $results['mla_wp_attached_filename'] = $attached_file;
3258
- } else {
3259
- $results['mla_wp_attached_path'] = substr( $attached_file, 0, $last_slash + 1 );
3260
- $results['mla_wp_attached_filename'] = substr( $attached_file, $last_slash + 1 );
3261
- }
3262
- } // $attached_file
3263
- } // is_array($post_meta)
3264
-
3265
- $save_id = $post_id;
3266
- return $results;
3267
- }
3268
-
3269
- /**
3270
- * Find Featured Image and inserted image/link references to an attachment
3271
- *
3272
- * Searches all post and page content to see if the attachment is used
3273
- * as a Featured Image or inserted in the post as an image or link.
3274
- *
3275
- * @since 0.1
3276
- *
3277
- * @param int post ID of attachment
3278
- * @param int post ID of attachment's parent, if any
3279
- * @param boolean True to compute references, false to return empty values
3280
- *
3281
- * @return array Reference information; see $references array comments
3282
- */
3283
- public static function mla_fetch_attachment_references( $ID, $parent, $add_references = true ) {
3284
- global $wpdb;
3285
- static $save_id = -1, $references, $inserted_in_option = NULL;
3286
-
3287
- if ( $save_id == $ID ) {
3288
- return $references;
3289
- } elseif ( $ID == -1 ) {
3290
- $save_id = -1;
3291
- return NULL;
3292
- }
3293
-
3294
- /*
3295
- * inserted_option 'enabled', 'base' or 'disabled'
3296
- * tested_reference true if any of the four where-used types was processed
3297
- * found_reference true if any where-used array is not empty()
3298
- * found_parent true if $parent matches a where-used post ID
3299
- * is_unattached true if $parent is zero (0)
3300
- * base_file relative path and name of the uploaded file, e.g., 2012/04/image.jpg
3301
- * path path to the file, relative to the "uploads/" directory, e.g., 2012/04/
3302
- * file The name portion of the base file, e.g., image.jpg
3303
- * files base file and any other image size files. Array key is path and file name.
3304
- * Non-image file value is a string containing file name without path
3305
- * Image file value is an array with file name, width and height
3306
- * features Array of objects with the post_type and post_title of each post
3307
- * that has the attachment as a "Featured Image"
3308
- * inserts Array of specific files (i.e., sizes) found in one or more posts/pages
3309
- * as an image (<img>) or link (<a href>). The array key is the path and file name.
3310
- * The array value is an array with the ID, post_type and post_title of each reference
3311
- * mla_galleries Array of objects with the post_type and post_title of each post
3312
- * that was returned by an [mla_gallery] shortcode
3313
- * galleries Array of objects with the post_type and post_title of each post
3314
- * that was returned by a [gallery] shortcode
3315
- * parent_type 'post' or 'page' or the custom post type of the attachment's parent
3316
- * parent_status 'publish', 'private', 'future', 'pending', 'draft'
3317
- * parent_title post_title of the attachment's parent
3318
- * parent_errors UNATTACHED, ORPHAN, BAD/INVALID PARENT
3319
- */
3320
- $references = array(
3321
- 'inserted_option' => '',
3322
- 'tested_reference' => false,
3323
- 'found_reference' => false,
3324
- 'found_parent' => false,
3325
- 'is_unattached' => ( ( (int) $parent ) === 0 ),
3326
- 'base_file' => '',
3327
- 'path' => '',
3328
- 'file' => '',
3329
- 'files' => array(),
3330
- 'features' => array(),
3331
- 'inserts' => array(),
3332
- 'mla_galleries' => array(),
3333
- 'galleries' => array(),
3334
- 'parent_type' => '',
3335
- 'parent_status' => '',
3336
- 'parent_title' => '',
3337
- 'parent_errors' => ''
3338
- );
3339
-
3340
- if ( ! $add_references ) {
3341
- return $references;
3342
- }
3343
-
3344
- /*
3345
- * Fill in Parent data
3346
- */
3347
- $parent_data = self::mla_fetch_attachment_parent_data( $parent );
3348
- if ( isset( $parent_data['parent_type'] ) ) {
3349
- $references['parent_type'] = $parent_data['parent_type'];
3350
- }
3351
-
3352
- if ( isset( $parent_data['parent_status'] ) ) {
3353
- $references['parent_status'] = $parent_data['parent_status'];
3354
- }
3355
-
3356
- if ( isset( $parent_data['parent_title'] ) ) {
3357
- $references['parent_title'] = $parent_data['parent_title'];
3358
- }
3359
-
3360
- $references['base_file'] = get_post_meta( $ID, '_wp_attached_file', true );
3361
- $pathinfo = pathinfo($references['base_file']);
3362
- $references['file'] = $pathinfo['basename'];
3363
- if ( ( ! isset( $pathinfo['dirname'] ) ) || '.' == $pathinfo['dirname'] ) {
3364
- $references['path'] = '/';
3365
- } else {
3366
- $references['path'] = $pathinfo['dirname'] . '/';
3367
- }
3368
-
3369
- $attachment_metadata = get_post_meta( $ID, '_wp_attachment_metadata', true );
3370
- $sizes = isset( $attachment_metadata['sizes'] ) ? $attachment_metadata['sizes'] : NULL;
3371
- if ( is_array( $sizes ) ) {
3372
- // Using the name as the array key ensures each name is added only once
3373
- foreach ( $sizes as $size => $size_info ) {
3374
- $size_info['size'] = $size;
3375
- $references['files'][ $references['path'] . $size_info['file'] ] = $size_info;
3376
- }
3377
- }
3378
-
3379
- $base_type = wp_check_filetype( $references['file'] );
3380
- $base_reference = array(
3381
- 'file' => $references['file'],
3382
- 'width' => isset( $attachment_metadata['width'] ) ? $attachment_metadata['width'] : 0,
3383
- 'height' => isset( $attachment_metadata['height'] ) ? $attachment_metadata['height'] : 0,
3384
- 'mime_type' => isset( $base_type['type'] ) ? $base_type['type'] : 'unknown',
3385
- 'size' => 'full',
3386
- );
3387
-
3388
- $references['files'][ $references['base_file'] ] = $base_reference;
3389
-
3390
- /*
3391
- * Process the where-used settings option
3392
- */
3393
- if ('checked' == MLAOptions::mla_get_option( MLAOptions::MLA_EXCLUDE_REVISIONS ) ) {
3394
- $exclude_revisions = "(post_type <> 'revision') AND ";
3395
- } else {
3396
- $exclude_revisions = '';
3397
- }
3398
-
3399
- /*
3400
- * Accumulate reference test types, e.g., 0 = no tests, 4 = all tests
3401
- */
3402
- $reference_tests = 0;
3403
-
3404
- /*
3405
- * Look for the "Featured Image(s)", if enabled
3406
- */
3407
- if ( MLAOptions::$process_featured_in ) {
3408
- $reference_tests++;
3409
- $features = $wpdb->get_results(
3410
- "
3411
- SELECT post_id
3412
- FROM {$wpdb->postmeta}
3413
- WHERE meta_key = '_thumbnail_id' AND meta_value = {$ID}
3414
- "
3415
- );
3416
-
3417
- if ( ! empty( $features ) ) {
3418
- foreach ( $features as $feature ) {
3419
- $feature_results = $wpdb->get_results(
3420
- "
3421
- SELECT ID, post_type, post_status, post_title
3422
- FROM {$wpdb->posts}
3423
- WHERE {$exclude_revisions}(ID = {$feature->post_id})
3424
- "
3425
- );
3426
-
3427
- if ( ! empty( $feature_results ) ) {
3428
- $references['found_reference'] = true;
3429
- $references['features'][ $feature->post_id ] = $feature_results[0];
3430
-
3431
- if ( $feature->post_id == $parent ) {
3432
- $references['found_parent'] = true;
3433
- }
3434
- } // ! empty
3435
- } // foreach $feature
3436
- }
3437
- } // $process_featured_in
3438
-
3439
- /*
3440
- * Look for item(s) inserted in post_content
3441
- */
3442
- $references['inserted_option'] = $inserted_in_option;
3443
- if ( MLAOptions::$process_inserted_in ) {
3444
- $reference_tests++;
3445
-
3446
- if ( NULL == $inserted_in_option ) {
3447
- $inserted_in_option = MLAOptions::mla_get_option( MLAOptions::MLA_INSERTED_IN_TUNING );
3448
- $references['inserted_option'] = $inserted_in_option;
3449
- }
3450
-
3451
- if ( 'base' == $inserted_in_option ) {
3452
- $query_parameters = array();
3453
- $query = array();
3454
- $query[] = "SELECT ID, post_type, post_status, post_title, CONVERT(`post_content` USING utf8 ) AS POST_CONTENT FROM {$wpdb->posts} WHERE {$exclude_revisions} ( %s=%s";
3455
- $query_parameters[] = '1'; // for empty file name array
3456
- $query_parameters[] = '0'; // for empty file name array
3457
-
3458
- foreach ( $references['files'] as $file => $file_data ) {
3459
- if ( empty( $file ) ) {
3460
- continue;
3461
- }
3462
-
3463
- $query[] = 'OR ( POST_CONTENT LIKE %s)';
3464
-
3465
- if ( self::$wp_4dot0_plus ) {
3466
- $query_parameters[] = '%' . $wpdb->esc_like( $file ) . '%';
3467
- } else {
3468
- $query_parameters[] = '%' . like_escape( $file ) . '%';
3469
- }
3470
- }
3471
-
3472
- $query[] = ')';
3473
- $query = join(' ', $query);
3474
-
3475
- $inserts = $wpdb->get_results(
3476
- $wpdb->prepare( $query, $query_parameters )
3477
- );
3478
-
3479
- if ( ! empty( $inserts ) ) {
3480
- $references['found_reference'] = true;
3481
- $references['inserts'][ $pathinfo['filename'] ] = $inserts;
3482
-
3483
- foreach ( $inserts as $index => $insert ) {
3484
- unset( $references['inserts'][ $pathinfo['filename'] ][ $index ]->POST_CONTENT );
3485
- if ( $insert->ID == $parent ) {
3486
- $references['found_parent'] = true;
3487
- }
3488
- } // foreach $insert
3489
- } // ! empty
3490
- } else { // process base names
3491
- foreach ( $references['files'] as $file => $file_data ) {
3492
- if ( empty( $file ) ) {
3493
- continue;
3494
- }
3495
-
3496
- if ( self::$wp_4dot0_plus ) {
3497
- $like = $wpdb->esc_like( $file );
3498
- } else {
3499
- $like = like_escape( $file );
3500
- }
3501
-
3502
- $inserts = $wpdb->get_results(
3503
- $wpdb->prepare(
3504
- "SELECT ID, post_type, post_status, post_title FROM {$wpdb->posts}
3505
- WHERE {$exclude_revisions}(CONVERT(`post_content` USING utf8 ) LIKE %s)", "%{$like}%"
3506
- )
3507
- );
3508
-
3509
- if ( ! empty( $inserts ) ) {
3510
- $references['found_reference'] = true;
3511
- $references['inserts'][ $file_data['file'] ] = $inserts;
3512
-
3513
- foreach ( $inserts as $insert ) {
3514
- if ( $insert->ID == $parent ) {
3515
- $references['found_parent'] = true;
3516
- }
3517
- } // foreach $insert
3518
- } // ! empty
3519
- } // foreach $file
3520
- } // process intermediate sizes
3521
- } // $process_inserted_in
3522
-
3523
- /*
3524
- * Look for [mla_gallery] references
3525
- */
3526
- if ( MLAOptions::$process_mla_gallery_in ) {
3527
- $reference_tests++;
3528
- if ( self::_build_mla_galleries( MLAOptions::MLA_MLA_GALLERY_IN_TUNING, self::$mla_galleries, '[mla_gallery', $exclude_revisions ) ) {
3529
- $galleries = self::_search_mla_galleries( self::$mla_galleries, $ID );
3530
- if ( ! empty( $galleries ) ) {
3531
- $references['found_reference'] = true;
3532
- $references['mla_galleries'] = $galleries;
3533
-
3534
- foreach ( $galleries as $post_id => $gallery ) {
3535
- if ( $post_id == $parent ) {
3536
- $references['found_parent'] = true;
3537
- }
3538
- } // foreach $gallery
3539
- } else { // ! empty
3540
- $references['mla_galleries'] = array();
3541
- }
3542
- }
3543
- } // $process_mla_gallery_in
3544
-
3545
- /*
3546
- * Look for [gallery] references
3547
- */
3548
- if ( MLAOptions::$process_gallery_in ) {
3549
- $reference_tests++;
3550
- if ( self::_build_mla_galleries( MLAOptions::MLA_GALLERY_IN_TUNING, self::$galleries, '[gallery', $exclude_revisions ) ) {
3551
- $galleries = self::_search_mla_galleries( self::$galleries, $ID );
3552
- if ( ! empty( $galleries ) ) {
3553
- $references['found_reference'] = true;
3554
- $references['galleries'] = $galleries;
3555
-
3556
- foreach ( $galleries as $post_id => $gallery ) {
3557
- if ( $post_id == $parent ) {
3558
- $references['found_parent'] = true;
3559
- }
3560
- } // foreach $gallery
3561
- } else { // ! empty
3562
- $references['galleries'] = array();
3563
- }
3564
- }
3565
- } // $process_gallery_in
3566
-
3567
- /*
3568
- * Evaluate and summarize reference tests
3569
- */
3570
- $errors = '';
3571
- if ( 0 == $reference_tests ) {
3572
- $references['tested_reference'] = false;
3573
- $errors .= '(' . __( 'NO REFERENCE TESTS', 'media-library-assistant' ) . ')';
3574
- } else {
3575
- $references['tested_reference'] = true;
3576
- $suffix = ( 4 == $reference_tests ) ? '' : '?';
3577
-
3578
- if ( !$references['found_reference'] ) {
3579
- $errors .= '(' . sprintf( __( 'ORPHAN', 'media-library-assistant' ) . '%1$s) ', $suffix );
3580
- }
3581
-
3582
- if ( !$references['found_parent'] && ! empty( $references['parent_title'] ) ) {
3583
- $errors .= '(' . sprintf( __( 'UNUSED', 'media-library-assistant' ) . '%1$s) ', $suffix );
3584
- }
3585
- }
3586
-
3587
- if ( $references['is_unattached'] ) {
3588
- $errors .= '(' . __( 'UNATTACHED', 'media-library-assistant' ) . ')';
3589
- } elseif ( empty( $references['parent_title'] ) ) {
3590
- $errors .= '(' . __( 'INVALID PARENT', 'media-library-assistant' ) . ')';
3591
- }
3592
-
3593
- $references['parent_errors'] = trim( $errors );
3594
-
3595
- $save_id = $ID;
3596
- $references = apply_filters( 'mla_fetch_attachment_references', $references, $ID, $parent );
3597
- return $references;
3598
- }
3599
-
3600
- /**
3601
- * Add Featured Image and inserted image/link references to an array of attachments
3602
- *
3603
- * Searches all post and page content to see if the attachmenta are used
3604
- * as a Featured Image or inserted in the post as an image or link.
3605
- *
3606
- * @since 1.94
3607
- *
3608
- * @param array WP_Post objects, passed by reference
3609
- *
3610
- * @return void updates WP_Post objects with new mla_references property
3611
- */
3612
- public static function mla_attachment_array_fetch_references( &$attachments ) {
3613
- global $wpdb;
3614
-
3615
- /*
3616
- * See element definitions above
3617
- */
3618
- $initial_references = array(
3619
- 'inserted_option' => '',
3620
- 'tested_reference' => false,
3621
- 'found_reference' => false,
3622
- 'found_parent' => false,
3623
- 'is_unattached' => true,
3624
- 'base_file' => '',
3625
- 'path' => '',
3626
- 'file' => '',
3627
- 'files' => array(),
3628
- 'features' => array(),
3629
- 'inserts' => array(),
3630
- 'mla_galleries' => array(),
3631
- 'galleries' => array(),
3632
- 'parent_type' => '',
3633
- 'parent_status' => '',
3634
- 'parent_title' => '',
3635
- 'parent_errors' => ''
3636
- );
3637
-
3638
- $inserted_in_option = MLAOptions::mla_get_option( MLAOptions::MLA_INSERTED_IN_TUNING );
3639
- $initial_references['inserted_option'] = $inserted_in_option;
3640
-
3641
- /*
3642
- * Make sure there's work to do; otherwise initialize the attachment data and return
3643
- */
3644
- if ( false == ( MLAOptions::$process_featured_in || MLAOptions::$process_inserted_in || MLAOptions::$process_gallery_in || MLAOptions::$process_mla_gallery_in ) ) {
3645
- foreach ( $attachments as $attachment_index => $attachment ) {
3646
- $attachments[ $attachment_index ]->mla_references = $initial_references;
3647
- }
3648
-
3649
- return;
3650
- }
3651
-
3652
- /*
3653
- * Collect the raw data for where-used analysis
3654
- */
3655
- $attachment_ids = array();
3656
- $files = array();
3657
- foreach ( $attachments as $index => $attachment ) {
3658
- $attachment_ids[ $index ] = $attachment->ID;
3659
- $references = array( 'files' => array() );
3660
- if ( isset( $attachment->mla_wp_attached_file ) ) {
3661
- $references['base_file'] = $attachment->mla_wp_attached_file;
3662
- } else {
3663
- $references['base_file'] = '';
3664
- }
3665
-
3666
- $pathinfo = pathinfo($references['base_file']);
3667
- if ( ( ! isset( $pathinfo['dirname'] ) ) || '.' == $pathinfo['dirname'] ) {
3668
- $references['path'] = '/';
3669
- } else {
3670
- $references['path'] = $pathinfo['dirname'] . '/';
3671
- }
3672
-
3673
- $references['file'] = $pathinfo['basename'];
3674
-
3675
- if ( isset( $attachment->mla_wp_attachment_metadata ) ) {
3676
- $attachment_metadata = $attachment->mla_wp_attachment_metadata;
3677
- } else {
3678
- $attachment_metadata = '';
3679
- }
3680
-
3681
- $sizes = isset( $attachment_metadata['sizes'] ) ? $attachment_metadata['sizes'] : NULL;
3682
- if ( ! empty( $sizes ) && is_array( $sizes ) ) {
3683
- /* Using the path and name as the array key ensures each name is added only once */
3684
- foreach ( $sizes as $size => $size_info ) {
3685
- $size_info['size'] = $size;
3686
- $references['files'][ $references['path'] . $size_info['file'] ] = $size_info;
3687
- }
3688
- }
3689
-
3690
- if ( ! empty( $references['base_file'] ) ) {
3691
- $base_type = wp_check_filetype( $references['file'] );
3692
- $base_reference = array(
3693
- 'file' => $references['file'],
3694
- 'width' => isset( $attachment_metadata['width'] ) ? $attachment_metadata['width'] : 0,
3695
- 'height' => isset( $attachment_metadata['height'] ) ? $attachment_metadata['height'] : 0,
3696
- 'mime_type' => ( isset( $base_type['type'] ) && false !== $base_type['type'] ) ? $base_type['type'] : 'unknown',
3697
- 'size' => 'full',
3698
- );
3699
-
3700
- $references['files'][ $references['base_file'] ] = $base_reference;
3701
- }
3702
-
3703
- $files[ $index ] = $references;
3704
- }
3705
-
3706
- if ('checked' == MLAOptions::mla_get_option( MLAOptions::MLA_EXCLUDE_REVISIONS ) ) {
3707
- $exclude_revisions = " AND (p.post_type <> 'revision')";
3708
- } else {
3709
- $exclude_revisions = '';
3710
- }
3711
-
3712
- $features = array();
3713
- if ( MLAOptions::$process_featured_in && ! empty( $attachment_ids ) ) {
3714
- $attachment_ids = implode( ',', $attachment_ids );
3715
- $results = $wpdb->get_results(
3716
- "
3717
- SELECT m.meta_value, p.ID, p.post_type, p.post_status, p.post_title
3718
- FROM {$wpdb->postmeta} AS m INNER JOIN {$wpdb->posts} AS p ON m.post_id = p.ID
3719
- WHERE ( m.meta_key = '_thumbnail_id' )
3720
- AND ( m.meta_value IN ( {$attachment_ids} ) ){$exclude_revisions}
3721
- "
3722
- );
3723
-
3724
- foreach ( $results as $result ) {
3725
- $features[ $result->meta_value ][ $result->ID ] = (object) array( 'ID' => $result->ID, 'post_title' => $result->post_title, 'post_type' => $result->post_type, 'post_status' => $result->post_status );
3726
- }
3727
- } // $process_featured_in
3728
-
3729
- if ( ! empty( $exclude_revisions ) ) {
3730
- $exclude_revisions = " AND (post_type <> 'revision')";
3731
- }
3732
-
3733
- if ( MLAOptions::$process_inserted_in ) {
3734
- $query_parameters = array();
3735
- $query = array();
3736
- $query[] = "SELECT ID, post_type, post_status, post_title, CONVERT(`post_content` USING utf8 ) AS POST_CONTENT FROM {$wpdb->posts} WHERE ( %s=%s";
3737
- // for empty file name array
3738
- $query_parameters[] = '1';
3739
- $query_parameters[] = '0';
3740
-
3741
- foreach ( $files as $file ) {
3742
- foreach ( $file['files'] as $base_name => $file_data ) {
3743
- $query[] = 'OR ( POST_CONTENT LIKE %s)';
3744
-
3745
- if ( self::$wp_4dot0_plus ) {
3746
- $query_parameters[] = '%' . $wpdb->esc_like( $base_name ) . '%';
3747
- } else {
3748
- $query_parameters[] = '%' . like_escape( $base_name ) . '%';
3749
- }
3750
- }
3751
- }
3752
-
3753
- $query[] = "){$exclude_revisions}";
3754
- $query = join(' ', $query);
3755
-
3756
- $results = $wpdb->get_results(
3757
- $wpdb->prepare( $query, $query_parameters )
3758
- );
3759
-
3760
- /*
3761
- * Match each post with inserts back to the attachments
3762
- */
3763
- $inserts = array();
3764
- if ( ! empty( $results ) ) {
3765
- foreach ( $files as $index => $file ) {
3766
- foreach ( $file['files'] as $base_name => $file_data ) {
3767
- foreach ( $results as $result ) {
3768
- if ( false !== strpos( $result->POST_CONTENT, $base_name ) ) {
3769
- $insert = clone $result;
3770
- unset( $insert->POST_CONTENT);
3771
- $insert->file_name = $file_data['file'];
3772
- $inserts[ $index ][] = $insert;
3773
- }
3774
- } // foreach post with inserts
3775
- } // foreach base_name
3776
- } // foreach attachment
3777
- } // results
3778
- } // process_inserted_in
3779
-
3780
- if ( MLAOptions::$process_mla_gallery_in ) {
3781
- $have_mla_galleries = self::_build_mla_galleries( MLAOptions::MLA_MLA_GALLERY_IN_TUNING, self::$mla_galleries, '[mla_gallery', $exclude_revisions );
3782
- } else {
3783
- $have_mla_galleries = false;
3784
- }
3785
-
3786
- if ( MLAOptions::$process_gallery_in ) {
3787
- $have_galleries = self::_build_mla_galleries( MLAOptions::MLA_GALLERY_IN_TUNING, self::$galleries, '[gallery', $exclude_revisions );
3788
- } else {
3789
- $have_mla_galleries = false;
3790
- }
3791
-
3792
- foreach ( $attachments as $attachment_index => $attachment ) {
3793
- $references = array_merge( $initial_references, $files[ $attachment_index ] );
3794
-
3795
- /*
3796
- * Fill in Parent data
3797
- */
3798
- if ( ( (int) $attachment->post_parent ) === 0 ) {
3799
- $references['is_unattached'] = true;
3800
- } else {
3801
- $references['is_unattached'] = false;
3802
-
3803
- if ( isset( $attachment->parent_type ) ) {
3804
- $references['parent_type'] = $attachment->parent_type;
3805
- }
3806
-
3807
- if ( isset( $attachment->parent_status ) ) {
3808
- $references['parent_status'] = $attachment->parent_status;
3809
- }
3810
-
3811
- if ( isset( $attachment->parent_title ) ) {
3812
- $references['parent_title'] = $attachment->parent_title;
3813
- }
3814
- }
3815
-
3816
- /*
3817
- * Accumulate reference test types, e.g., 0 = no tests, 4 = all tests
3818
- */
3819
- $reference_tests = 0;
3820
-
3821
- /*
3822
- * Look for the "Featured Image(s)", if enabled
3823
- */
3824
- if ( MLAOptions::$process_featured_in ) {
3825
- $reference_tests++;
3826
- if ( isset( $features[ $attachment->ID ] ) ) {
3827
- foreach ( $features[ $attachment->ID ] as $id => $feature ) {
3828
- $references['found_reference'] = true;
3829
- $references['features'][ $id ] = $feature;
3830
-
3831
- if ( $id == $attachment->post_parent ) {
3832
- $references['found_parent'] = true;
3833
- }
3834
- } // foreach $feature
3835
- }
3836
- } // $process_featured_in
3837
-
3838
- /*
3839
- * Look for item(s) inserted in post_content
3840
- */
3841
- if ( MLAOptions::$process_inserted_in ) {
3842
- $reference_tests++;
3843
-
3844
- if ( isset( $inserts[ $attachment_index ] ) ) {
3845
- $references['found_reference'] = true;
3846
- foreach( $inserts[ $attachment_index ] as $insert ) {
3847
- $ref_insert = clone $insert;
3848
- unset( $ref_insert->file_name );
3849
-
3850
- if ( 'base' == $inserted_in_option ) {
3851
- $ref_key = pathinfo( $references['base_file'], PATHINFO_FILENAME );
3852
- } else {
3853
- $ref_key = $insert->file_name;
3854
- }
3855
-
3856
- $references['inserts'][ $ref_key ][ $insert->ID ] = $ref_insert;
3857
- if ( $insert->ID == $attachment->post_parent ) {
3858
- $references['found_parent'] = true;
3859
- }
3860
- } // each insert
3861
- } else {
3862
- $references['inserts'] = array();
3863
- }
3864
- } // $process_inserted_in
3865
-
3866
- /*
3867
- * Look for [mla_gallery] references
3868
- */
3869
- if ( MLAOptions::$process_mla_gallery_in ) {
3870
- $reference_tests++;
3871
- if ( self::_build_mla_galleries( MLAOptions::MLA_MLA_GALLERY_IN_TUNING, self::$mla_galleries, '[mla_gallery', $exclude_revisions ) ) {
3872
- $galleries = self::_search_mla_galleries( self::$mla_galleries, $attachment->ID );
3873
- if ( ! empty( $galleries ) ) {
3874
- $references['found_reference'] = true;
3875
- $references['mla_galleries'] = $galleries;
3876
-
3877
- foreach ( $galleries as $post_id => $gallery ) {
3878
- if ( $post_id == $attachment->post_parent ) {
3879
- $references['found_parent'] = true;
3880
- }
3881
- } // foreach $gallery
3882
- } else { // ! empty
3883
- $references['mla_galleries'] = array();
3884
- }
3885
- }
3886
- } // $process_mla_gallery_in
3887
-
3888
- /*
3889
- * Look for [gallery] references
3890
- */
3891
- if ( MLAOptions::$process_gallery_in ) {
3892
- $reference_tests++;
3893
- if ( self::_build_mla_galleries( MLAOptions::MLA_GALLERY_IN_TUNING, self::$galleries, '[gallery', $exclude_revisions ) ) {
3894
- $galleries = self::_search_mla_galleries( self::$galleries, $attachment->ID );
3895
- if ( ! empty( $galleries ) ) {
3896
- $references['found_reference'] = true;
3897
- $references['galleries'] = $galleries;
3898
-
3899
- foreach ( $galleries as $post_id => $gallery ) {
3900
- if ( $post_id == $attachment->post_parent ) {
3901
- $references['found_parent'] = true;
3902
- }
3903
- } // foreach $gallery
3904
- } else { // ! empty
3905
- $references['galleries'] = array();
3906
- }
3907
- }
3908
- } // $process_gallery_in
3909
-
3910
- /*
3911
- * Evaluate and summarize reference tests
3912
- */
3913
- $errors = '';
3914
- if ( 0 == $reference_tests ) {
3915
- $references['tested_reference'] = false;
3916
- $errors .= '(' . __( 'NO REFERENCE TESTS', 'media-library-assistant' ) . ')';
3917
- } else {
3918
- $references['tested_reference'] = true;
3919
- $suffix = ( 4 == $reference_tests ) ? '' : '?';
3920
-
3921
- if ( !$references['found_reference'] ) {
3922
- $errors .= '(' . sprintf( __( 'ORPHAN', 'media-library-assistant' ) . '%1$s) ', $suffix );
3923
- }
3924
-
3925
- if ( !$references['found_parent'] && ! empty( $references['parent_title'] ) ) {
3926
- $errors .= '(' . sprintf( __( 'UNUSED', 'media-library-assistant' ) . '%1$s) ', $suffix );
3927
- }
3928
- }
3929
-
3930
- if ( $references['is_unattached'] ) {
3931
- $errors .= '(' . __( 'UNATTACHED', 'media-library-assistant' ) . ')';
3932
- } elseif ( empty( $references['parent_title'] ) ) {
3933
- $errors .= '(' . __( 'INVALID PARENT', 'media-library-assistant' ) . ')';
3934
- }
3935
 
3936
- $references['parent_errors'] = trim( $errors );
3937
- $attachments[ $attachment_index ]->mla_references = apply_filters( 'mla_fetch_attachment_references', $references, $attachment->ID, (int) $attachment->post_parent );
3938
- } // foreach $attachment
3939
  }
3940
 
3941
  /**
3942
- * Objects containing [gallery] shortcodes
3943
- *
3944
- * This array contains all of the objects containing one or more [gallery] shortcodes
3945
- * and array(s) of which attachments each [gallery] contains. The arrays are built once
3946
- * each page load and cached for subsequent calls.
3947
  *
3948
- * The outer array is keyed by post_id. It contains an associative array with:
3949
- * ['parent_title'] post_title of the gallery parent,
3950
- * ['parent_type'] 'post' or 'page' or the custom post_type of the gallery parent,
3951
- * ['parent_status'] 'publish', 'private', 'future', 'pending', 'draft'
3952
- * ['results'] array ( ID => ID ) of attachments appearing in ANY of the parent's galleries.
3953
- * ['galleries'] array of [gallery] entries numbered from one (1), containing:
3954
- * galleries[X]['query'] contains a string with the arguments of the [gallery],
3955
- * galleries[X]['results'] contains an array ( ID ) of post_ids for the objects in the gallery.
3956
  *
3957
- * @since 0.70
 
 
3958
  *
3959
- * @var array
3960
  */
3961
- private static $galleries = null;
 
 
3962
 
3963
- /**
3964
- * Objects containing [mla_gallery] shortcodes
3965
- *
3966
- * This array contains all of the objects containing one or more [mla_gallery] shortcodes
3967
- * and array(s) of which attachments each [mla_gallery] contains. The arrays are built once
3968
- * each page load and cached for subsequent calls.
3969
- *
3970
- * @since 0.70
3971
- *
3972
- * @var array
3973
- */
3974
- private static $mla_galleries = null;
3975
 
3976
- /**
3977
- * Invalidates the $mla_galleries or $galleries array and cached values
3978
- *
3979
- * @since 1.00
3980
- *
3981
- * @param string name of the gallery's cache/option variable
3982
- *
3983
- * @return void
3984
- */
3985
- public static function mla_flush_mla_galleries( $option_name ) {
3986
- delete_transient( MLA_OPTION_PREFIX . 't_' . $option_name );
3987
 
3988
- switch ( $option_name ) {
3989
- case MLAOptions::MLA_GALLERY_IN_TUNING:
3990
- self::$galleries = null;
3991
- break;
3992
- case MLAOptions::MLA_MLA_GALLERY_IN_TUNING:
3993
- self::$mla_galleries = null;
3994
- break;
3995
- default:
3996
- // ignore everything else
3997
- } // switch
3998
  }
3999
 
4000
  /**
4001
- * Invalidates $mla_galleries and $galleries arrays and cached values after post, page or attachment updates
4002
  *
4003
- * @since 1.00
4004
  *
4005
- * @param integer ID of post/page/attachment; not used at this time
 
4006
  *
4007
- * @return void
4008
  */
4009
- public static function mla_save_post_action( $post_id ) {
4010
- self::mla_flush_mla_galleries( MLAOptions::MLA_GALLERY_IN_TUNING );
4011
- self::mla_flush_mla_galleries( MLAOptions::MLA_MLA_GALLERY_IN_TUNING );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4012
  }
4013
 
4014
  /**
4015
- * Builds the $mla_galleries or $galleries array
 
 
 
4016
  *
4017
- * @since 0.70
4018
  *
4019
- * @param string name of the gallery's cache/option variable
4020
- * @param array by reference to the private static galleries array variable
4021
- * @param string the shortcode to be searched for and processed
4022
- * @param boolean true to exclude revisions from the search
4023
  *
4024
- * @return boolean true if the galleries array is not empty
4025
  */
4026
- private static function _build_mla_galleries( $option_name, &$galleries_array, $shortcode, $exclude_revisions ) {
4027
- global $wpdb, $post;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4028
 
4029
- if ( is_array( $galleries_array ) ) {
4030
- if ( ! empty( $galleries_array ) ) {
4031
- return true;
4032
- } else {
4033
- return false;
4034
- }
4035
- }
 
 
 
4036
 
4037
- $option_value = MLAOptions::mla_get_option( $option_name );
4038
- if ( 'disabled' == $option_value ) {
4039
- return false;
4040
- } elseif ( 'cached' == $option_value ) {
4041
- $galleries_array = get_transient( MLA_OPTION_PREFIX . 't_' . $option_name );
4042
- if ( is_array( $galleries_array ) ) {
4043
- if ( ! empty( $galleries_array ) ) {
4044
- return true;
4045
  } else {
4046
- return false;
4047
- }
4048
- } else {
4049
- $galleries_array = NULL;
4050
- }
4051
- } // cached
4052
-
4053
- /*
4054
- * $galleries_array is null, so build the array
4055
- */
4056
- $galleries_array = array();
4057
-
4058
- if ( $exclude_revisions ) {
4059
- $exclude_revisions = "(post_type <> 'revision') AND ";
4060
- } else {
4061
- $exclude_revisions = '';
4062
- }
4063
-
4064
- if ( self::$wp_4dot0_plus ) {
4065
- $like = $wpdb->esc_like( $shortcode );
4066
  } else {
4067
- $like = like_escape( $shortcode );
4068
- }
4069
-
4070
- $results = $wpdb->get_results(
4071
- $wpdb->prepare(
4072
- "
4073
- SELECT ID, post_type, post_status, post_title, post_content
4074
- FROM {$wpdb->posts}
4075
- WHERE {$exclude_revisions}(
4076
- CONVERT(`post_content` USING utf8 )
4077
- LIKE %s)
4078
- ", "%{$like}%"
4079
- )
4080
- );
4081
-
4082
- if ( empty( $results ) ) {
4083
- return false;
4084
  }
4085
 
4086
- foreach ( $results as $result ) {
4087
- $count = preg_match_all( "/\\{$shortcode}([^\\]]*)\\]/", $result->post_content, $matches, PREG_PATTERN_ORDER );
4088
- if ( $count ) {
4089
- $result_id = $result->ID;
4090
- $galleries_array[ $result_id ]['parent_title'] = $result->post_title;
4091
- $galleries_array[ $result_id ]['parent_type'] = $result->post_type;
4092
- $galleries_array[ $result_id ]['parent_status'] = $result->post_status;
4093
- $galleries_array[ $result_id ]['results'] = array();
4094
- $galleries_array[ $result_id ]['galleries'] = array();
4095
- $instance = 0;
4096
-
4097
- foreach ( $matches[1] as $index => $match ) {
4098
- /*
4099
- * Filter out shortcodes that are not an exact match
4100
- */
4101
- if ( empty( $match ) || ( ' ' == substr( $match, 0, 1 ) ) ) {
4102
- $instance++;
4103
- /*
4104
- * Remove trailing "/" from XHTML-style self-closing shortcodes
4105
- */
4106
- $galleries_array[ $result_id ]['galleries'][ $instance ]['query'] = trim( rtrim( $matches[1][$index], '/' ) );
4107
- $galleries_array[ $result_id ]['galleries'][ $instance ]['results'] = array();
4108
- $post = $result; // set global variable for mla_gallery_shortcode
4109
- $attachments = MLAShortcodes::mla_get_shortcode_attachments( $result_id, $galleries_array[ $result_id ]['galleries'][ $instance ]['query'] . ' cache_results=false update_post_meta_cache=false update_post_term_cache=false where_used_query=this-is-a-where-used-query' );
4110
-
4111
- if ( is_string( $attachments ) ) {
4112
- /* translators: 1: post_type, 2: post_title, 3: post ID, 4: query string, 5: error message */
4113
- trigger_error( htmlentities( sprintf( __( '(%1$s) %2$s (ID %3$d) query "%4$s" failed, returning "%5$s"', 'media-library-assistant' ), $result->post_type, $result->post_title, $result->ID, $galleries_array[ $result_id ]['galleries'][ $instance ]['query'], $attachments) ), E_USER_WARNING );
4114
- } elseif ( ! empty( $attachments ) ) {
4115
- foreach ( $attachments as $attachment ) {
4116
- $galleries_array[ $result_id ]['results'][ $attachment->ID ] = $attachment->ID;
4117
- $galleries_array[ $result_id ]['galleries'][ $instance ]['results'][] = $attachment->ID;
4118
  }
4119
  }
4120
- } // exact match
4121
- } // foreach $match
4122
- } // if $count
4123
- } // foreach $result
4124
-
4125
- /*
4126
- * Maybe cache the results
4127
- */
4128
- if ( 'cached' == $option_value ) {
4129
- set_transient( MLA_OPTION_PREFIX . 't_' . $option_name, $galleries_array, 900 ); // fifteen minutes
4130
- }
4131
 
4132
- return true;
4133
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4134
 
4135
  /**
4136
- * Search the $mla_galleries or $galleries array
4137
  *
4138
- * @since 0.70
4139
  *
4140
- * @param array by reference to the private static galleries array variable
4141
- * @param int the attachment ID to be searched for and processed
4142
  *
4143
- * @return array All posts/pages with one or more galleries that include the attachment.
4144
- * The array key is the parent_post ID; each entry contains post_title and post_type.
4145
  */
4146
- private static function _search_mla_galleries( &$galleries_array, $attachment_id ) {
4147
- $gallery_refs = array();
4148
- if ( ! empty( $galleries_array ) ) {
4149
- foreach ( $galleries_array as $parent_id => $gallery ) {
4150
- if ( in_array( $attachment_id, $gallery['results'] ) ) {
4151
- $gallery_refs[ $parent_id ] = array ( 'ID' => $parent_id, 'post_title' => $gallery['parent_title'], 'post_type' => $gallery['parent_type'], 'post_status' => $gallery['parent_status'] );
4152
- }
4153
- } // foreach gallery
4154
- } // ! empty
4155
-
4156
- return $gallery_refs;
4157
  }
4158
 
4159
  /**
@@ -4246,6 +1787,36 @@ class MLAData {
4246
  return $results;
4247
  }
4248
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4249
  /**
4250
  * Extract XMP meta data from a file
4251
  *
@@ -4257,6 +1828,7 @@ class MLAData {
4257
  * @return mixed array of metadata values or NULL on failure
4258
  */
4259
  public static function mla_parse_xmp_metadata( $file_name, $file_offset ) {
 
4260
  $chunksize = 16384;
4261
  $xmp_chunk = file_get_contents( $file_name, true, NULL, $file_offset, $chunksize );
4262
 
@@ -4297,11 +1869,16 @@ class MLAData {
4297
  }
4298
 
4299
  $xmp_string = "<?xml version='1.0'?>\n" . substr($xmp_chunk, $start_tag, ( $end_tag + 12 ) - $start_tag );
 
 
 
 
4300
  $xmp_values = array();
4301
  $xml_parser = xml_parser_create('UTF-8');
4302
  if ( xml_parser_set_option( $xml_parser, XML_OPTION_SKIP_WHITE, 0 ) && xml_parser_set_option( $xml_parser, XML_OPTION_CASE_FOLDING, 0 ) ) {
4303
- if (xml_parse_into_struct( $xml_parser, $xmp_string, $xmp_values ) == 0) {
4304
  error_log( __( 'ERROR', 'media-library-assistant' ) . ': ' . _x( 'mla_parse_xmp_metadata xml_parse_into_struct failed.', 'error_log', 'media-library-assistant' ), 0 );
 
4305
  }
4306
  } else {
4307
  error_log( __( 'ERROR', 'media-library-assistant' ) . ': ' . _x( 'mla_parse_xmp_metadata set option failed.', 'error_log', 'media-library-assistant' ), 0 );
@@ -4312,12 +1889,14 @@ class MLAData {
4312
  if ( empty( $xmp_values ) ) {
4313
  return NULL;
4314
  }
 
4315
 
4316
  $levels = array();
4317
  $current_level = 0;
4318
  $results = array();
4319
  $xmlns = array();
4320
- foreach ( $xmp_values as $value ) {
 
4321
  $language = 'x-default';
4322
  $node_attributes = array();
4323
  if ( isset( $value['attributes'] ) ) {
@@ -4361,10 +1940,15 @@ class MLAData {
4361
  case 'close':
4362
  if ( 0 < --$current_level ) {
4363
  $top_level = array_pop( $levels );
 
4364
  if ( 'rdf:li' == $top_level['key'] ) {
4365
  $levels[ $current_level ]['values'][] = $top_level['values'];
4366
  } else {
4367
- $levels[ $current_level ]['values'][ $top_level['key'] ] = $top_level['values'];
 
 
 
 
4368
  }
4369
  }
4370
  break;
@@ -4399,7 +1983,10 @@ class MLAData {
4399
  $levels[ $current_level ]['values'][ $value['tag'] ] = $complete_value;
4400
  }
4401
  } // switch on type
 
4402
  } // foreach value
 
 
4403
 
4404
  /*
4405
  * Parse "namespace:name" names into arrays of simple names
@@ -4429,6 +2016,7 @@ class MLAData {
4429
  }
4430
  } // found namespace
4431
  }
 
4432
 
4433
  /*
4434
  * Try to populate all the PDF-standard keys (except Trapped)
@@ -4442,32 +2030,23 @@ class MLAData {
4442
  * ModDate - The date and time the document was most recently modified
4443
  */
4444
  if ( ! isset( $results['Title'] ) ) {
4445
- if ( isset( $namespace_arrays['dc'] ) && isset( $namespace_arrays['dc']['title'] ) ) {
4446
- if ( is_array( $namespace_arrays['dc']['title'] ) ) {
4447
- $results['Title'] = @implode( ',', $namespace_arrays['dc']['title'] );
4448
- } else {
4449
- $results['Title'] = (string) $namespace_arrays['dc']['title'];
4450
- }
4451
  }
4452
  }
4453
 
4454
  if ( ! isset( $results['Author'] ) ) {
4455
- if ( isset( $namespace_arrays['dc'] ) && isset( $namespace_arrays['dc']['creator'] ) ) {
4456
- if ( is_array( $namespace_arrays['dc']['creator'] ) ) {
4457
- $results['Author'] = @implode( ',', $namespace_arrays['dc']['creator'] );
4458
- } else {
4459
- $results['Author'] = (string) $namespace_arrays['dc']['creator'];
4460
- }
4461
  }
4462
  }
4463
 
4464
  if ( ! isset( $results['Subject'] ) ) {
4465
- if ( isset( $namespace_arrays['dc'] ) && isset( $namespace_arrays['dc']['description'] ) ) {
4466
- if ( is_array( $namespace_arrays['dc']['description'] ) ) {
4467
- $results['Subject'] = @implode( ',', $namespace_arrays['dc']['description'] );
4468
- } else {
4469
- $results['Subject'] = (string) $namespace_arrays['dc']['description'];
4470
- }
4471
  }
4472
  }
4473
 
@@ -4501,13 +2080,13 @@ class MLAData {
4501
  if ( isset( $namespace_arrays['dc'] ) && isset( $namespace_arrays['dc']['subject'] ) ) {
4502
  if ( is_array( $namespace_arrays['dc']['subject'] ) ) {
4503
  foreach ( $namespace_arrays['dc']['subject'] as $term ) {
4504
- $term = trim( $term );
4505
  if ( ! empty( $term ) ) {
4506
  $keywords[ $term ] = $term;
4507
  }
4508
  }
4509
  } elseif ( is_string( $namespace_arrays['dc']['subject'] ) ) {
4510
- $term = trim ( $namespace_arrays['dc']['subject'] );
4511
  if ( ! empty( $term ) ) {
4512
  $keywords[ $term ] = $term;
4513
  }
@@ -4529,28 +2108,40 @@ class MLAData {
4529
  // }
4530
 
4531
  if ( ! isset( $results['Creator'] ) ) {
4532
- if ( isset( $namespace_arrays['xmp'] ) && isset( $namespace_arrays['xmp']['CreatorTool'] ) ) {
4533
- $results['Creator'] = $namespace_arrays['xmp']['CreatorTool'];
4534
- } elseif ( isset( $namespace_arrays['xap'] ) && isset( $namespace_arrays['xap']['CreatorTool'] ) ) {
4535
- $results['Creator'] = $namespace_arrays['xap']['CreatorTool'];
4536
- } elseif ( ! empty( $results['Producer'] ) ) {
4537
- $results['Creator'] = $results['Producer'];
 
 
 
 
4538
  }
4539
  }
4540
 
4541
  if ( ! isset( $results['CreationDate'] ) ) {
4542
- if ( isset( $namespace_arrays['xmp'] ) && isset( $namespace_arrays['xmp']['CreateDate'] ) ) {
4543
- $results['CreationDate'] = $namespace_arrays['xmp']['CreateDate'];
4544
- } elseif ( isset( $namespace_arrays['xap'] ) && isset( $namespace_arrays['xap']['CreateDate'] ) ) {
4545
- $results['CreationDate'] = $namespace_arrays['xap']['CreateDate'];
 
 
 
 
4546
  }
4547
  }
4548
 
4549
  if ( ! isset( $results['ModDate'] ) ) {
4550
- if ( isset( $namespace_arrays['xmp'] ) && isset( $namespace_arrays['xmp']['ModifyDate'] ) ) {
4551
- $results['ModDate'] = $namespace_arrays['xmp']['ModifyDate'];
4552
- } elseif ( isset( $namespace_arrays['xap'] ) && isset( $namespace_arrays['xap']['ModifyDate'] ) ) {
4553
- $results['ModDate'] = $namespace_arrays['xap']['ModifyDate'];
 
 
 
 
4554
  }
4555
  }
4556
 
@@ -5005,19 +2596,21 @@ class MLAData {
5005
 
5006
  if ( 'ALL_IPTC' == $iptc_key ) {
5007
  $clean_data = array();
5008
- foreach ( $item_metadata['mla_iptc_metadata'] as $key => $value ) {
5009
- if ( is_array( $value ) ) {
5010
- foreach ($value as $text_key => $text )
5011
- $value[ $text_key ] = self::_bin_to_utf8( $text );
5012
-
5013
- $clean_data[ $key ] = 'ARRAY(' . implode( ',', $value ) . ')';
5014
- } elseif ( is_string( $value ) ) {
5015
- $clean_data[ $key ] = self::_bin_to_utf8( substr( $value, 0, 256 ) );
5016
- } else {
5017
- $clean_data[ $key ] = self::_bin_to_utf8( $value );
 
 
5018
  }
5019
  }
5020
-
5021
  return var_export( $clean_data, true);
5022
  }
5023
 
@@ -5041,32 +2634,36 @@ class MLAData {
5041
  public static function mla_exif_metadata_value( $exif_key, $item_metadata, $option = 'text', $keep_existing = false ) {
5042
  if ( 'ALL_EXIF' == $exif_key ) {
5043
  $clean_data = array();
5044
- foreach ( $item_metadata['mla_exif_metadata'] as $key => $value ) {
5045
- if ( is_array( $value ) ) {
5046
- $clean_data[ $key ] = '(ARRAY)';
5047
- } elseif ( is_string( $value ) ) {
5048
- $clean_data[ $key ] = self::_bin_to_utf8( substr( $value, 0, 256 ) );
5049
- } else {
5050
- $clean_data[ $key ] = $value;
 
 
5051
  }
5052
  }
5053
 
5054
  return var_export( $clean_data, true);
5055
  } elseif ( 'ALL_IPTC' == $exif_key ) {
5056
  $clean_data = array();
5057
- foreach ( $item_metadata['mla_iptc_metadata'] as $key => $value ) {
5058
- if ( is_array( $value ) ) {
5059
- foreach ($value as $text_key => $text )
5060
- $value[ $text_key ] = self::_bin_to_utf8( $text );
5061
-
5062
- $clean_data[ $key ] = 'ARRAY(' . implode( ',', $value ) . ')';
5063
- } elseif ( is_string( $value ) ) {
5064
- $clean_data[ $key ] = self::_bin_to_utf8( substr( $value, 0, 256 ) );
5065
- } else {
5066
- $clean_data[ $key ] = self::_bin_to_utf8( $value );
 
 
5067
  }
5068
  }
5069
-
5070
  return var_export( $clean_data, true);
5071
  }
5072
 
@@ -5090,16 +2687,18 @@ class MLAData {
5090
  public static function mla_xmp_metadata_value( $xmp_key, $xmp_metadata, $option = 'text', $keep_existing = false ) {
5091
  if ( 'ALL_XMP' == $xmp_key ) {
5092
  $clean_data = array();
5093
- foreach ( $xmp_metadata as $key => $value ) {
5094
- if ( is_array( $value ) ) {
5095
- $clean_data[ $key ] = '(ARRAY)';
5096
- } elseif ( is_string( $value ) ) {
5097
- $clean_data[ $key ] = self::_bin_to_utf8( substr( $value, 0, 256 ) );
5098
- } else {
5099
- $clean_data[ $key ] = $value;
 
 
5100
  }
5101
  }
5102
-
5103
  return var_export( $clean_data, true);
5104
  }
5105
 
@@ -5123,16 +2722,18 @@ class MLAData {
5123
  public static function mla_id3_metadata_value( $id3_key, $id3_metadata, $option, $keep_existing ) {
5124
  if ( 'ALL_ID3' == $id3_key ) {
5125
  $clean_data = array();
5126
- foreach ( $id3_metadata as $key => $value ) {
5127
- if ( is_array( $value ) ) {
5128
- $clean_data[ $key ] = '(ARRAY)';
5129
- } elseif ( is_string( $value ) ) {
5130
- $clean_data[ $key ] = self::_bin_to_utf8( substr( $value, 0, 256 ) );
5131
- } else {
5132
- $clean_data[ $key ] = $value;
 
 
5133
  }
5134
  }
5135
-
5136
  return var_export( $clean_data, true);
5137
  }
5138
 
@@ -5168,16 +2769,18 @@ class MLAData {
5168
  }
5169
  } elseif ( 'ALL_PDF' == $pdf_key ) {
5170
  $clean_data = array();
5171
- foreach ( $item_metadata['mla_pdf_metadata'] as $key => $value ) {
5172
- if ( is_array( $value ) ) {
5173
- $clean_data[ $key ] = '(ARRAY)';
5174
- } elseif ( is_string( $value ) ) {
5175
- $clean_data[ $key ] = self::_bin_to_utf8( substr( $value, 0, 256 ) );
5176
- } else {
5177
- $clean_data[ $key ] = $value;
 
 
5178
  }
5179
  }
5180
-
5181
  $text = var_export( $clean_data, true);
5182
  } // ALL_PDF
5183
 
@@ -5411,6 +3014,10 @@ class MLAData {
5411
 
5412
  if ( ! empty( $path ) ) {
5413
  if ( 'pdf' == strtolower( pathinfo( $path, PATHINFO_EXTENSION ) ) ) {
 
 
 
 
5414
  $pdf_metadata = MLAPDF::mla_extract_pdf_metadata( $path );
5415
  $results['mla_xmp_metadata'] = $pdf_metadata['xmp'];
5416
  $results['mla_pdf_metadata'] = $pdf_metadata['pdf'];
@@ -5829,7 +3436,7 @@ class MLAData {
5829
  * @return string success/failure message(s)
5830
  */
5831
  public static function mla_update_item_postmeta( $post_id, $new_meta ) {
5832
- $post_data = self::mla_fetch_attachment_metadata( $post_id );
5833
  $message = '';
5834
 
5835
  $attachment_meta_values = array();
@@ -6057,7 +3664,7 @@ class MLAData {
6057
  * should not get a value, e.g., text or PDF documents
6058
  */
6059
  case 'bulk_image_alt':
6060
- if ( empty( $post_data[ 'mla_wp_attachment_metadata' ] ) ) {
6061
  break;
6062
  }
6063
  // fallthru
@@ -6254,9 +3861,9 @@ class MLAData {
6254
  } else {
6255
  // invalidate the cached item
6256
  self::mla_get_attachment_by_id( -1 );
6257
- self::mla_fetch_attachment_parent_data( -1 );
6258
- self::mla_fetch_attachment_metadata( -1 );
6259
- self::mla_fetch_attachment_references( -1, 0 );
6260
 
6261
  // See if anything else has changed
6262
  if ( 1 < count( $updates ) ) {
16
  * @since 0.1
17
  */
18
  class MLAData {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  /**
20
  * Initialization function, similar to __construct()
21
  *
22
  * @since 0.1
23
  */
24
  public static function initialize() {
25
+ self::$search_parameters =& MLAQuery::$search_parameters;
26
+ self::$query_parameters =& MLAQuery::$query_parameters;
 
 
 
 
27
 
28
  add_action( 'save_post', 'MLAData::mla_save_post_action', 10, 1);
29
  add_action( 'edit_attachment', 'MLAData::mla_save_post_action', 10, 1);
84
  }
85
  break;
86
  case 'option':
87
+ $template = MLACore::mla_get_option( $source );
88
  if ( $template == false ) {
89
  return false;
90
  }
1098
  if ( 0 < $post_id ) {
1099
  $record = get_metadata( 'post', $post_id, $value['value'], 'single' == $value['option'] );
1100
  if ( empty( $record ) && 'ALL_CUSTOM' == $value['value'] ) {
1101
+ $meta_values = MLAQuery::mla_fetch_attachment_metadata( $post_id );
1102
  $clean_data = array();
1103
  foreach( $meta_values as $meta_key => $meta_value ) {
1104
  if ( 0 !== strpos( $meta_key, 'mla_item_' ) ) {
1220
  $candidate = str_replace( '{', '[', str_replace( '}', ']', $value['value'] ) );
1221
  $key = str_replace( '{', '[', str_replace( '}', ']', $key ) );
1222
 
1223
+ if ( MLAShortcodes::mla_is_data_source( $candidate ) ) {
1224
  $data_value = array(
1225
  'data_source' => $candidate,
1226
  'keep_existing' => false,
1227
  'format' => 'raw',
1228
  'option' => $value['option'] ); // single, export, text for array values, e.g., alt_text
1229
 
1230
+ $markup_values[ $key ] = MLAShortcodes::mla_get_data_source( $post_id, 'single_attachment_mapping', $data_value );
1231
  } elseif ( isset( $markup_values[ $value['value'] ] ) ) {
1232
  /*
1233
  * A standard element can have a format modifier, e.g., commas, attr
1374
  return $results;
1375
  }
1376
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1377
  /**
1378
  * WP_Query filter "parameters"
1379
  *
1420
  public static $search_parameters = array();
1421
 
1422
  /**
1423
+ * Get the total number of attachment posts
1424
+ *
1425
+ * Compatibility shim for MLAQuery::mla_count_list_table_items
1426
+ *
1427
+ * @since 0.30
1428
+ *
1429
+ * @param array Query variables, e.g., from $_REQUEST
1430
+ * @param int (optional) number of rows to skip over to reach desired page
1431
+ * @param int (optional) number of rows on each page
1432
+ *
1433
+ * @return integer Number of attachment posts
1434
+ */
1435
+ public static function mla_count_list_table_items( $request, $offset = NULL, $count = NULL ) {
1436
+ return MLAQuery::mla_count_list_table_items( $request, $offset, $count );
1437
+ }
1438
+
1439
+ /**
1440
+ * Retrieve attachment objects for list table display
1441
  *
1442
+ * Compatibility shim for MLAQuery::mla_query_list_table_items
 
1443
  *
1444
  * @since 0.1
1445
  *
1446
  * @param array query parameters from web page, usually found in $_REQUEST
1447
+ * @param int number of rows to skip over to reach desired page
1448
+ * @param int number of rows on each page
1449
  *
1450
+ * @return array attachment objects (posts) including parent data, meta data and references
1451
  */
1452
+ public static function mla_query_list_table_items( $request, $offset, $count ) {
1453
+ return MLAQuery::mla_query_list_table_items( $request, $offset, $count );
1454
+ }
1455
+
1456
+ /**
1457
+ * Retrieve an Attachment array given a $post_id
1458
+ *
1459
+ * The (associative) array will contain every field that can be found in
1460
+ * the posts and postmeta tables, and all references to the attachment.
1461
+ *
1462
+ * @since 0.1
1463
+ * @uses $post WordPress global variable
1464
+ *
1465
+ * @param integer The ID of the attachment post
1466
+ * @param boolean True to add references, false to skip references
1467
+ *
1468
+ * @return NULL|array NULL on failure else associative array
1469
+ */
1470
+ public static function mla_get_attachment_by_id( $post_id, $add_references = true ) {
1471
+ global $post;
1472
+ static $save_id = -1, $post_data;
1473
 
1474
+ if ( $post_id == $save_id ) {
1475
+ return $post_data;
1476
+ } elseif ( $post_id == -1 ) {
1477
+ $save_id = -1;
1478
+ return NULL;
 
 
 
 
 
 
1479
  }
1480
 
1481
+ $item = get_post( $post_id );
1482
+ if ( empty( $item ) ) {
1483
+ /* translators: 1: ERROR tag 2: post ID */
1484
+ error_log( sprintf( _x( '%1$s: mla_get_attachment_by_id(%2$d) not found.', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $post_id ), 0 );
1485
+ return NULL;
 
 
 
 
 
 
 
 
 
 
1486
  }
1487
 
1488
+ if ( $item->post_type != 'attachment' ) {
1489
+ /* translators: 1: ERROR tag 2: post ID 3: post_type */
1490
+ error_log( sprintf( _x( '%1$s: mla_get_attachment_by_id(%2$d) wrong post_type "%3$s".', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $post_id, $item->post_type ), 0 );
1491
+ return NULL;
1492
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1493
 
1494
+ $post_data = (array) $item;
1495
+ $post = $item;
1496
+ setup_postdata( $item );
 
 
1497
 
1498
  /*
1499
+ * Add parent data
1500
  */
1501
+ $post_data = array_merge( $post_data, MLAQuery::mla_fetch_attachment_parent_data( $post_data['post_parent'] ) );
 
 
1502
 
1503
  /*
1504
+ * Add meta data
 
1505
  */
1506
+ $post_data = array_merge( $post_data, MLAQuery::mla_fetch_attachment_metadata( $post_id ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1507
 
1508
  /*
1509
+ * Add references, if requested, or "empty" references array
1510
+ */
1511
+ $post_data['mla_references'] = MLAQuery::mla_fetch_attachment_references( $post_id, $post_data['post_parent'], $add_references );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1512
 
1513
+ $save_id = $post_id;
1514
+ return $post_data;
 
1515
  }
1516
 
1517
  /**
1518
+ * Adds or replaces the value of a key in a possibly nested array structure
 
 
 
 
1519
  *
1520
+ * @since 1.51
 
 
 
 
 
 
 
1521
  *
1522
+ * @param string key value, e.g. array1.array2.element
1523
+ * @param mixed replacement value, string or array, by reference
1524
+ * @param array PHP nested arrays, by reference
1525
  *
1526
+ * @return boolean true if $needle element set, false if not
1527
  */
1528
+ private static function _set_array_element( $needle, &$value, &$haystack ) {
1529
+ $key_array = explode( '.', $needle );
1530
+ $key = array_shift( $key_array );
1531
 
1532
+ if ( empty( $key_array ) ) {
1533
+ $haystack[ $key ] = $value;
1534
+ return true;
1535
+ } // lowest level
 
 
 
 
 
 
 
 
1536
 
1537
+ /*
1538
+ * If an intermediate key is not an array, leave it alone and fail.
1539
+ * If an intermediate key does not exist, create an empty array for it.
1540
+ */
1541
+ if ( isset( $haystack[ $key ] ) ) {
1542
+ if ( ! is_array( $haystack[ $key ] ) ) {
1543
+ return false;
1544
+ }
1545
+ } else {
1546
+ $haystack[ $key ] = array();
1547
+ }
1548
 
1549
+ return self::_set_array_element( implode( $key_array, '.' ), $value, $haystack[ $key ] );
 
 
 
 
 
 
 
 
 
1550
  }
1551
 
1552
  /**
1553
+ * Deletes the value of a key in a possibly nested array structure
1554
  *
1555
+ * @since 1.51
1556
  *
1557
+ * @param string key value, e.g. array1.array2.element
1558
+ * @param array PHP nested arrays, by reference
1559
  *
1560
+ * @return boolean true if $needle element found, false if not
1561
  */
1562
+ private static function _unset_array_element( $needle, &$haystack ) {
1563
+ $key_array = explode( '.', $needle );
1564
+ $key = array_shift( $key_array );
1565
+
1566
+ if ( empty( $key_array ) ) {
1567
+ if ( isset( $haystack[ $key ] ) ) {
1568
+ unset( $haystack[ $key ] );
1569
+ return true;
1570
+ }
1571
+
1572
+ return false;
1573
+ } // lowest level
1574
+
1575
+ if ( isset( $haystack[ $key ] ) ) {
1576
+ return self::_unset_array_element( implode( $key_array, '.' ), $haystack[ $key ] );
1577
+ }
1578
+
1579
+ return false;
1580
  }
1581
 
1582
  /**
1583
+ * Finds the value of a key in a possibly nested array structure
1584
+ *
1585
+ * Used primarily to extract fields from the _wp_attachment_metadata custom field.
1586
+ * Also used with the audio/video ID3 metadata exposed in WordPress 3.6 and later.
1587
  *
1588
+ * @since 1.30
1589
  *
1590
+ * @param string key value, e.g. array1.array2.element
1591
+ * @param array PHP nested arrays
1592
+ * @param string data option; 'text'|'single'|'export'|'array'|'multi'
1593
+ * @param boolean keep existing values - for 'multi' option
1594
  *
1595
+ * @return mixed string or array value matching key(.key ...) or ''
1596
  */
1597
+ public static function mla_find_array_element( $needle, $haystack, $option, $keep_existing = false ) {
1598
+ $key_array = explode( '.', $needle );
1599
+ if ( is_array( $key_array ) ) {
1600
+ foreach ( $key_array as $key ) {
1601
+ /*
1602
+ * The '*' key means:
1603
+ * 1) needle.* => accept any value, or
1604
+ * 2) needle.*.tail => search each sub-array using "tail"
1605
+ * and build an array of results.
1606
+ */
1607
+ if ( '*' == $key ) {
1608
+ if ( false !== ( $tail = strpos( $needle, '*.' ) ) ) {
1609
+ $tail = substr( $needle, $tail + 2 );
1610
+ if ( ! empty( $tail ) ) {
1611
+ if ( is_array( $haystack ) ) {
1612
+ $results = array();
1613
+ foreach ( $haystack as $substack ) {
1614
+ $results[] = self::mla_find_array_element( $tail, $substack, $option, $keep_existing );
1615
+ }
1616
 
1617
+ if ( 1 == count( $results ) ) {
1618
+ $haystack = $results[0];
1619
+ } else {
1620
+ $haystack = $results;
1621
+ }
1622
+ } else {
1623
+ $haystack = '';
1624
+ }
1625
+ } // found tail
1626
+ } // found .*.
1627
 
1628
+ break;
 
 
 
 
 
 
 
1629
  } else {
1630
+ if ( is_array( $haystack ) ) {
1631
+ if ( isset( $haystack[ $key ] ) ) {
1632
+ $haystack = $haystack[ $key ];
1633
+ } else {
1634
+ $haystack = '';
1635
+ }
1636
+ } else {
1637
+ $haystack = '';
1638
+ }
1639
+ } // * != key
1640
+ } // foreach $key
 
 
 
 
 
 
 
 
 
1641
  } else {
1642
+ $haystack = '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1643
  }
1644
 
1645
+ if ( is_array( $haystack ) ) {
1646
+ switch ( $option ) {
1647
+ case 'single':
1648
+ $haystack = current( $haystack );
1649
+ break;
1650
+ case 'export':
1651
+ $haystack = var_export( $haystack, true );
1652
+ break;
1653
+ case 'unpack':
1654
+ if ( is_array( $haystack ) ) {
1655
+ $clean_data = array();
1656
+ foreach ( $haystack as $key => $value ) {
1657
+ if ( is_array( $value ) ) {
1658
+ $clean_data[ $key ] = '(ARRAY)';
1659
+ } elseif ( is_string( $value ) ) {
1660
+ $clean_data[ $key ] = self::_bin_to_utf8( substr( $value, 0, 256 ) );
1661
+ } else {
1662
+ $clean_data[ $key ] = $value;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1663
  }
1664
  }
 
 
 
 
 
 
 
 
 
 
 
1665
 
1666
+ $haystack = var_export( $clean_data, true);
1667
+ } else {
1668
+ $haystack = var_export( $record, true );
1669
+ }
1670
+ break;
1671
+ case 'multi':
1672
+ $haystack[0x80000000] = $option;
1673
+ $haystack[0x80000001] = $keep_existing;
1674
+ // fallthru
1675
+ case 'array':
1676
+ return $haystack;
1677
+ break;
1678
+ default:
1679
+ $haystack = self::_bin_to_utf8( @implode( ', ', $haystack ) );
1680
+ } // $option
1681
+ } // is_array
1682
+
1683
+ return self::_bin_to_utf8( $haystack );
1684
+ } // mla_find_array_element
1685
 
1686
  /**
1687
+ * Invalidates $mla_galleries and $galleries arrays and cached values after post, page or attachment updates
1688
  *
1689
+ * @since 1.00
1690
  *
1691
+ * @param integer ID of post/page/attachment; not used at this time
 
1692
  *
1693
+ * @return void
 
1694
  */
1695
+ public static function mla_save_post_action( $post_id ) {
1696
+ MLAQuery::mla_flush_mla_galleries( MLACore::MLA_GALLERY_IN_TUNING );
1697
+ MLAQuery::mla_flush_mla_galleries( MLACore::MLA_MLA_GALLERY_IN_TUNING );
 
 
 
 
 
 
 
 
1698
  }
1699
 
1700
  /**
1787
  return $results;
1788
  }
1789
 
1790
+ /**
1791
+ * Search the namespace array for a non-empty value
1792
+ *
1793
+ * @since 2.10
1794
+ *
1795
+ * @param array namespace array
1796
+ * @param string namespace
1797
+ * @param string key
1798
+ *
1799
+ * @return string trimmed value of the key within the namespace
1800
+ */
1801
+ private static function _nonempty_value( &$namespace_array, $namespace, $key ) {
1802
+ $result = '';
1803
+
1804
+ if ( isset( $namespace_array[ $namespace ] ) && isset( $namespace_array[ $namespace ][ $key ] ) ) {
1805
+ if ( is_array( $namespace_array[ $namespace ][ $key ] ) ) {
1806
+ $result = @implode( ',', $namespace_array[ $namespace ][ $key ] );
1807
+ } else {
1808
+ $result = (string) $namespace_array[ $namespace ][ $key ];
1809
+ }
1810
+ }
1811
+
1812
+ $trim_value = trim( $result, " \n\t\r\0\x0B," );
1813
+ if ( empty( $trim_value ) ) {
1814
+ $result = '';
1815
+ }
1816
+
1817
+ return $result;
1818
+ }
1819
+
1820
  /**
1821
  * Extract XMP meta data from a file
1822
  *
1828
  * @return mixed array of metadata values or NULL on failure
1829
  */
1830
  public static function mla_parse_xmp_metadata( $file_name, $file_offset ) {
1831
+ //error_log( __LINE__ . " MLAData::mla_parse_xmp_metadata( {$file_name}, {$file_offset} ) ", 0 );
1832
  $chunksize = 16384;
1833
  $xmp_chunk = file_get_contents( $file_name, true, NULL, $file_offset, $chunksize );
1834
 
1869
  }
1870
 
1871
  $xmp_string = "<?xml version='1.0'?>\n" . substr($xmp_chunk, $start_tag, ( $end_tag + 12 ) - $start_tag );
1872
+ //error_log( __LINE__ . " MLAData::mla_parse_xmp_metadata xmp_string = " . var_export( $xmp_string, true ), 0 );
1873
+ //error_log( __LINE__ . " MLAData::mla_parse_xmp_metadata xmp_string = \r\n" . MLAData::mla_hex_dump( $xmp_string ), 0 );
1874
+ // experimental damage repair for GodsHillPC
1875
+ $xmp_string = str_replace( "\000", '0', $xmp_string );
1876
  $xmp_values = array();
1877
  $xml_parser = xml_parser_create('UTF-8');
1878
  if ( xml_parser_set_option( $xml_parser, XML_OPTION_SKIP_WHITE, 0 ) && xml_parser_set_option( $xml_parser, XML_OPTION_CASE_FOLDING, 0 ) ) {
1879
+ if ( 0 == xml_parse_into_struct( $xml_parser, $xmp_string, $xmp_values ) ) {
1880
  error_log( __( 'ERROR', 'media-library-assistant' ) . ': ' . _x( 'mla_parse_xmp_metadata xml_parse_into_struct failed.', 'error_log', 'media-library-assistant' ), 0 );
1881
+ $xmp_values = array();
1882
  }
1883
  } else {
1884
  error_log( __( 'ERROR', 'media-library-assistant' ) . ': ' . _x( 'mla_parse_xmp_metadata set option failed.', 'error_log', 'media-library-assistant' ), 0 );
1889
  if ( empty( $xmp_values ) ) {
1890
  return NULL;
1891
  }
1892
+ //error_log( __LINE__ . " MLAData::mla_parse_xmp_metadata xmp_values = " . var_export( $xmp_values, true ), 0 );
1893
 
1894
  $levels = array();
1895
  $current_level = 0;
1896
  $results = array();
1897
  $xmlns = array();
1898
+ foreach ( $xmp_values as $index => $value ) {
1899
+ //error_log( __LINE__ . " MLAData::mla_parse_xmp_metadata xmp_values( {$index} ) value = " . var_export( $value, true ), 0 );
1900
  $language = 'x-default';
1901
  $node_attributes = array();
1902
  if ( isset( $value['attributes'] ) ) {
1940
  case 'close':
1941
  if ( 0 < --$current_level ) {
1942
  $top_level = array_pop( $levels );
1943
+ //error_log( __LINE__ . " MLAData::mla_parse_xmp_metadata xmp_values( {$index} ) top_level = " . var_export( $top_level, true ), 0 );
1944
  if ( 'rdf:li' == $top_level['key'] ) {
1945
  $levels[ $current_level ]['values'][] = $top_level['values'];
1946
  } else {
1947
+ if ( isset( $levels[ $current_level ]['values'][ $top_level['key'] ] ) ) {
1948
+ $levels[ $current_level ]['values'][ $top_level['key'] ] = array_merge( $levels[ $current_level ]['values'][ $top_level['key'] ], $top_level['values'] );
1949
+ } else {
1950
+ $levels[ $current_level ]['values'][ $top_level['key'] ] = $top_level['values'];
1951
+ }
1952
  }
1953
  }
1954
  break;
1983
  $levels[ $current_level ]['values'][ $value['tag'] ] = $complete_value;
1984
  }
1985
  } // switch on type
1986
+ //error_log( __LINE__ . " MLAData::mla_parse_xmp_metadata xmp_values( {$index}, {$current_level} ) levels = " . var_export( $levels, true ), 0 );
1987
  } // foreach value
1988
+ //error_log( __LINE__ . " MLAData::mla_parse_xmp_metadata levels = " . var_export( $levels, true ), 0 );
1989
+ //error_log( __LINE__ . " MLAData::mla_parse_xmp_metadata xmlns = " . var_export( $xmlns, true ), 0 );
1990
 
1991
  /*
1992
  * Parse "namespace:name" names into arrays of simple names
2016
  }
2017
  } // found namespace
2018
  }
2019
+ //error_log( __LINE__ . " MLAData::mla_parse_xmp_metadata results = " . var_export( $results, true ), 0 );
2020
 
2021
  /*
2022
  * Try to populate all the PDF-standard keys (except Trapped)
2030
  * ModDate - The date and time the document was most recently modified
2031
  */
2032
  if ( ! isset( $results['Title'] ) ) {
2033
+ $replacement = self::_nonempty_value( $namespace_arrays, 'dc', 'title' );
2034
+ if ( ! empty( $replacement ) ) {
2035
+ $results['Title'] = $replacement;
 
 
 
2036
  }
2037
  }
2038
 
2039
  if ( ! isset( $results['Author'] ) ) {
2040
+ $replacement = self::_nonempty_value( $namespace_arrays, 'dc', 'creator' );
2041
+ if ( ! empty( $replacement ) ) {
2042
+ $results['Author'] = $replacement;
 
 
 
2043
  }
2044
  }
2045
 
2046
  if ( ! isset( $results['Subject'] ) ) {
2047
+ $replacement = self::_nonempty_value( $namespace_arrays, 'dc', 'description' );
2048
+ if ( ! empty( $replacement ) ) {
2049
+ $results['Subject'] = $replacement;
 
 
 
2050
  }
2051
  }
2052
 
2080
  if ( isset( $namespace_arrays['dc'] ) && isset( $namespace_arrays['dc']['subject'] ) ) {
2081
  if ( is_array( $namespace_arrays['dc']['subject'] ) ) {
2082
  foreach ( $namespace_arrays['dc']['subject'] as $term ) {
2083
+ $term = trim( $term, " \n\t\r\0\x0B," );
2084
  if ( ! empty( $term ) ) {
2085
  $keywords[ $term ] = $term;
2086
  }
2087
  }
2088
  } elseif ( is_string( $namespace_arrays['dc']['subject'] ) ) {
2089
+ $term = trim ( $namespace_arrays['dc']['subject'], " \n\t\r\0\x0B," );
2090
  if ( ! empty( $term ) ) {
2091
  $keywords[ $term ] = $term;
2092
  }
2108
  // }
2109
 
2110
  if ( ! isset( $results['Creator'] ) ) {
2111
+ $replacement = self::_nonempty_value( $namespace_arrays, 'xmp', 'CreatorTool' );
2112
+ if ( ! empty( $replacement ) ) {
2113
+ $results['Creator'] = $replacement;
2114
+ } else {
2115
+ $replacement = self::_nonempty_value( $namespace_arrays, 'xap', 'CreatorTool' );
2116
+ if ( ! empty( $replacement ) ) {
2117
+ $results['Creator'] = $replacement;
2118
+ } elseif ( ! empty( $results['Producer'] ) ) {
2119
+ $results['Creator'] = $results['Producer'];
2120
+ }
2121
  }
2122
  }
2123
 
2124
  if ( ! isset( $results['CreationDate'] ) ) {
2125
+ $replacement = self::_nonempty_value( $namespace_arrays, 'xmp', 'CreateDate' );
2126
+ if ( ! empty( $replacement ) ) {
2127
+ $results['CreationDate'] = $replacement;
2128
+ } else {
2129
+ $replacement = self::_nonempty_value( $namespace_arrays, 'xap', 'CreateDate' );
2130
+ if ( ! empty( $replacement ) ) {
2131
+ $results['CreationDate'] = $replacement;
2132
+ }
2133
  }
2134
  }
2135
 
2136
  if ( ! isset( $results['ModDate'] ) ) {
2137
+ $replacement = self::_nonempty_value( $namespace_arrays, 'xmp', 'ModifyDate' );
2138
+ if ( ! empty( $replacement ) ) {
2139
+ $results['ModDate'] = $replacement;
2140
+ } else {
2141
+ $replacement = self::_nonempty_value( $namespace_arrays, 'xap', 'ModifyDate' );
2142
+ if ( ! empty( $replacement ) ) {
2143
+ $results['ModDate'] = $replacement;
2144
+ }
2145
  }
2146
  }
2147
 
2596
 
2597
  if ( 'ALL_IPTC' == $iptc_key ) {
2598
  $clean_data = array();
2599
+ if ( isset( $item_metadata['mla_iptc_metadata'] ) && is_array( $item_metadata['mla_iptc_metadata'] ) ) {
2600
+ foreach ( $item_metadata['mla_iptc_metadata'] as $key => $value ) {
2601
+ if ( is_array( $value ) ) {
2602
+ foreach ($value as $text_key => $text )
2603
+ $value[ $text_key ] = self::_bin_to_utf8( $text );
2604
+
2605
+ $clean_data[ $key ] = 'ARRAY(' . implode( ',', $value ) . ')';
2606
+ } elseif ( is_string( $value ) ) {
2607
+ $clean_data[ $key ] = self::_bin_to_utf8( substr( $value, 0, 256 ) );
2608
+ } else {
2609
+ $clean_data[ $key ] = self::_bin_to_utf8( $value );
2610
+ }
2611
  }
2612
  }
2613
+
2614
  return var_export( $clean_data, true);
2615
  }
2616
 
2634
  public static function mla_exif_metadata_value( $exif_key, $item_metadata, $option = 'text', $keep_existing = false ) {
2635
  if ( 'ALL_EXIF' == $exif_key ) {
2636
  $clean_data = array();
2637
+ if ( isset( $item_metadata['mla_exif_metadata'] ) && is_array( $item_metadata['mla_exif_metadata'] ) ) {
2638
+ foreach ( $item_metadata['mla_exif_metadata'] as $key => $value ) {
2639
+ if ( is_array( $value ) ) {
2640
+ $clean_data[ $key ] = '(ARRAY)';
2641
+ } elseif ( is_string( $value ) ) {
2642
+ $clean_data[ $key ] = self::_bin_to_utf8( substr( $value, 0, 256 ) );
2643
+ } else {
2644
+ $clean_data[ $key ] = $value;
2645
+ }
2646
  }
2647
  }
2648
 
2649
  return var_export( $clean_data, true);
2650
  } elseif ( 'ALL_IPTC' == $exif_key ) {
2651
  $clean_data = array();
2652
+ if ( isset( $item_metadata['mla_iptc_metadata'] ) && is_array( $item_metadata['mla_iptc_metadata'] ) ) {
2653
+ foreach ( $item_metadata['mla_iptc_metadata'] as $key => $value ) {
2654
+ if ( is_array( $value ) ) {
2655
+ foreach ($value as $text_key => $text )
2656
+ $value[ $text_key ] = self::_bin_to_utf8( $text );
2657
+
2658
+ $clean_data[ $key ] = 'ARRAY(' . implode( ',', $value ) . ')';
2659
+ } elseif ( is_string( $value ) ) {
2660
+ $clean_data[ $key ] = self::_bin_to_utf8( substr( $value, 0, 256 ) );
2661
+ } else {
2662
+ $clean_data[ $key ] = self::_bin_to_utf8( $value );
2663
+ }
2664
  }
2665
  }
2666
+
2667
  return var_export( $clean_data, true);
2668
  }
2669
 
2687
  public static function mla_xmp_metadata_value( $xmp_key, $xmp_metadata, $option = 'text', $keep_existing = false ) {
2688
  if ( 'ALL_XMP' == $xmp_key ) {
2689
  $clean_data = array();
2690
+ if ( is_array( $xmp_metadata ) ) {
2691
+ foreach ( $xmp_metadata as $key => $value ) {
2692
+ if ( is_array( $value ) ) {
2693
+ $clean_data[ $key ] = '(ARRAY)';
2694
+ } elseif ( is_string( $value ) ) {
2695
+ $clean_data[ $key ] = self::_bin_to_utf8( substr( $value, 0, 256 ) );
2696
+ } else {
2697
+ $clean_data[ $key ] = $value;
2698
+ }
2699
  }
2700
  }
2701
+
2702
  return var_export( $clean_data, true);
2703
  }
2704
 
2722
  public static function mla_id3_metadata_value( $id3_key, $id3_metadata, $option, $keep_existing ) {
2723
  if ( 'ALL_ID3' == $id3_key ) {
2724
  $clean_data = array();
2725
+ if ( is_array( $id3_metadata ) ) {
2726
+ foreach ( $id3_metadata as $key => $value ) {
2727
+ if ( is_array( $value ) ) {
2728
+ $clean_data[ $key ] = '(ARRAY)';
2729
+ } elseif ( is_string( $value ) ) {
2730
+ $clean_data[ $key ] = self::_bin_to_utf8( substr( $value, 0, 256 ) );
2731
+ } else {
2732
+ $clean_data[ $key ] = $value;
2733
+ }
2734
  }
2735
  }
2736
+
2737
  return var_export( $clean_data, true);
2738
  }
2739
 
2769
  }
2770
  } elseif ( 'ALL_PDF' == $pdf_key ) {
2771
  $clean_data = array();
2772
+ if ( isset( $item_metadata['mla_pdf_metadata'] ) && is_array( $item_metadata['mla_pdf_metadata'] ) ) {
2773
+ foreach ( $item_metadata['mla_pdf_metadata'] as $key => $value ) {
2774
+ if ( is_array( $value ) ) {
2775
+ $clean_data[ $key ] = '(ARRAY)';
2776
+ } elseif ( is_string( $value ) ) {
2777
+ $clean_data[ $key ] = self::_bin_to_utf8( substr( $value, 0, 256 ) );
2778
+ } else {
2779
+ $clean_data[ $key ] = $value;
2780
+ }
2781
  }
2782
  }
2783
+
2784
  $text = var_export( $clean_data, true);
2785
  } // ALL_PDF
2786
 
3014
 
3015
  if ( ! empty( $path ) ) {
3016
  if ( 'pdf' == strtolower( pathinfo( $path, PATHINFO_EXTENSION ) ) ) {
3017
+ if ( !class_exists( 'MLAPDF' ) ) {
3018
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-data-pdf.php' );
3019
+ }
3020
+
3021
  $pdf_metadata = MLAPDF::mla_extract_pdf_metadata( $path );
3022
  $results['mla_xmp_metadata'] = $pdf_metadata['xmp'];
3023
  $results['mla_pdf_metadata'] = $pdf_metadata['pdf'];
3436
  * @return string success/failure message(s)
3437
  */
3438
  public static function mla_update_item_postmeta( $post_id, $new_meta ) {
3439
+ $post_data = MLAQuery::mla_fetch_attachment_metadata( $post_id );
3440
  $message = '';
3441
 
3442
  $attachment_meta_values = array();
3664
  * should not get a value, e.g., text or PDF documents
3665
  */
3666
  case 'bulk_image_alt':
3667
+ if ( 'image/' !== substr( $post_data[ 'post_mime_type' ], 0, 6 ) ) {
3668
  break;
3669
  }
3670
  // fallthru
3861
  } else {
3862
  // invalidate the cached item
3863
  self::mla_get_attachment_by_id( -1 );
3864
+ MLAQuery::mla_fetch_attachment_parent_data( -1 );
3865
+ MLAQuery::mla_fetch_attachment_metadata( -1 );
3866
+ MLAQuery::mla_fetch_attachment_references( -1, 0 );
3867
 
3868
  // See if anything else has changed
3869
  if ( 1 < count( $updates ) ) {
includes/class-mla-edit-media.php CHANGED
@@ -79,10 +79,8 @@ class MLAEdit {
79
  * @return void echoes the HTML markup for the label and value
80
  */
81
  public static function mla_admin_init_action( ) {
82
- //error_log( 'DEBUG: MLAEdit::mla_admin_init_action() $_REQUEST = ' . var_export( $_REQUEST, true ), 0 );
83
-
84
  $edit_media_support = array( 'custom-fields' );
85
- if ( ( 'checked' == MLAOptions::mla_get_option( 'enable_featured_image' ) ) && current_theme_supports( 'post-thumbnails', 'attachment' ) ) {
86
  $edit_media_support[] = 'thumbnail';
87
  }
88
 
@@ -91,16 +89,16 @@ class MLAEdit {
91
  /*
92
  * Check for Media/Add New bulk edit area updates
93
  */
94
- if ( ! empty( $_REQUEST['mlaAddNewBulkEditFormString'] ) && ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_ADD_NEW_BULK_EDIT ) ) ) {
95
  /*
96
  * If any of the mapping rule options is enabled, use the MLA filter so this
97
  * filter is called after mapping rules have run. If none are enabled,
98
  * use the WordPress filter directly.
99
  */
100
- if ( ( 'checked' == MLAOptions::mla_get_option( 'enable_iptc_exif_mapping' ) ) ||
101
- ( 'checked' == MLAOptions::mla_get_option( 'enable_custom_field_mapping' ) ) ||
102
- ( 'checked' == MLAOptions::mla_get_option( 'enable_iptc_exif_update' ) ) ||
103
- ( 'checked' == MLAOptions::mla_get_option( 'enable_custom_field_update' ) ) ) {
104
  // Fires after MLA mapping in wp_update_attachment_metadata() processing.
105
  add_filter( 'mla_update_attachment_metadata_postfilter', 'MLAEdit::mla_update_attachment_metadata_postfilter', 10, 3 );
106
  } else {
@@ -115,18 +113,6 @@ class MLAEdit {
115
  return;
116
  }
117
 
118
- /*
119
- * For flat taxonomies that use the checklist meta box, substitute our own handler
120
- * for /wp-admin/includes/ajax-actions.php function _wp_ajax_add_hierarchical_term().
121
- */
122
- if ( ( defined('DOING_AJAX') && DOING_AJAX ) && ( 'add-' == substr( $_POST['action'], 0, 4 ) ) ) {
123
- $key = substr( $_POST['action'], 4 );
124
- if ( MLAOptions::mla_taxonomy_support( $key, 'flat-checklist' ) ) {
125
- self::_mla_ajax_add_flat_term( $key );
126
- /* note: this function sends an Ajax response and then dies; no return */
127
- }
128
- }
129
-
130
  /*
131
  * For flat taxonomies that use the checklist meta box, convert the term array
132
  * back into a string of slug values.
@@ -170,7 +156,7 @@ class MLAEdit {
170
  /*
171
  * Add New Bulk Edit Area
172
  */
173
- if ( 'media-new.php' == $page_hook && ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_ADD_NEW_BULK_EDIT ) ) ) {
174
  if ( $wp_locale->is_rtl() ) {
175
  wp_register_style( 'mla-add-new-bulk-edit', MLA_PLUGIN_URL . 'css/mla-add-new-bulk-edit-rtl.css', false, MLA::CURRENT_MLA_VERSION );
176
  wp_register_style( 'mla-add-new-bulk-edit' . '-set-parent', MLA_PLUGIN_URL . 'css/mla-style-set-parent-rtl.css', false, MLA::CURRENT_MLA_VERSION );
@@ -193,7 +179,8 @@ class MLAEdit {
193
  'uploadTitle' => __( 'Upload New Media items', 'media-library-assistant' ),
194
  'toggleOpen' => __( 'Open Bulk Edit area', 'media-library-assistant' ),
195
  'toggleClose' => __( 'Close Bulk Edit area', 'media-library-assistant' ),
196
- 'areaOnTop' => ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_ADD_NEW_BULK_EDIT_ON_TOP ) ),
 
197
  'comma' => _x( ',', 'tag_delimiter', 'media-library-assistant' ),
198
  'ajaxFailError' => __( 'An ajax.fail error has occurred. Please reload the page and try again.', 'media-library-assistant' ),
199
  'ajaxDoneError' => __( 'An ajax.done error has occurred. Please reload the page and try again.', 'media-library-assistant' ),
@@ -316,9 +303,9 @@ class MLAEdit {
316
  $hierarchical_taxonomies = array();
317
  $flat_taxonomies = array();
318
  foreach ( $taxonomies as $tax_name => $tax_object ) {
319
- if ( $tax_object->hierarchical && $tax_object->show_ui && MLAOptions::mla_taxonomy_support($tax_name, 'quick-edit') ) {
320
  $hierarchical_taxonomies[$tax_name] = $tax_object;
321
- } elseif ( $tax_object->show_ui && MLAOptions::mla_taxonomy_support($tax_name, 'quick-edit') ) {
322
  $flat_taxonomies[$tax_name] = $tax_object;
323
  }
324
  }
@@ -413,7 +400,7 @@ class MLAEdit {
413
  }
414
 
415
  $custom_fields = '';
416
- foreach (MLAOptions::mla_custom_field_support( 'bulk_edit' ) as $slug => $details ) {
417
  $page_values = array(
418
  'slug' => $slug,
419
  'label' => esc_attr( $details['name'] ),
@@ -446,7 +433,10 @@ class MLAEdit {
446
  'set_parent_form' => $set_parent_form,
447
  );
448
 
449
- echo MLAData::mla_parse_template( $page_template_array['page'], $page_values );
 
 
 
450
  }
451
 
452
  /**
@@ -468,9 +458,10 @@ class MLAEdit {
468
  public static function mla_update_attachment_metadata_postfilter( $data, $post_id, $options = array( 'is_upload' => true ) ) {
469
  if ( ( true == $options['is_upload'] ) && ! empty( $_REQUEST['mlaAddNewBulkEditFormString'] ) ) {
470
  /*
471
- * Clean up the inputs, which have everythng from the enclosing <form>
472
  */
473
  $args = wp_parse_args( stripslashes( urldecode( $_REQUEST['mlaAddNewBulkEditFormString'] ) ) );
 
474
  unset( $args['parent'] );
475
  unset( $args['children'] );
476
  unset( $args['mla-set-parent-ajax-nonce'] );
@@ -543,16 +534,19 @@ class MLAEdit {
543
  echo "</div><!-- .misc-pub-section -->\n";
544
  echo '<div class="misc-pub-section mla-links">' . "\n";
545
 
546
- $view_args = array( 'page' => MLA::ADMIN_PAGE_SLUG, 'mla_item_ID' => $post->ID );
547
  if ( isset( $_REQUEST['mla_source'] ) ) {
548
  $view_args['mla_source'] = $_REQUEST['mla_source'];
549
  }
 
 
 
550
 
551
  echo '<span id="mla_metadata_links" style="font-weight: bold; line-height: 2em">';
552
 
553
- echo '<a href="' . add_query_arg( $view_args, wp_nonce_url( 'upload.php?mla_admin_action=' . MLA::MLA_ADMIN_SINGLE_CUSTOM_FIELD_MAP, MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME ) ) . '" title="' . __( 'Map Custom Field metadata for this item', 'media-library-assistant' ) . '">' . __( 'Map Custom Field metadata', 'media-library-assistant' ) . '</a><br>';
554
 
555
- echo '<a href="' . add_query_arg( $view_args, wp_nonce_url( 'upload.php?mla_admin_action=' . MLA::MLA_ADMIN_SINGLE_MAP, MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME ) ) . '" title="' . __( 'Map IPTC/EXIF metadata for this item', 'media-library-assistant' ) . '">' . __( 'Map IPTC/EXIF metadata', 'media-library-assistant' ) . '</a>';
556
 
557
  echo "</span>\n";
558
  echo "</div><!-- .misc-pub-section -->\n";
@@ -588,28 +582,28 @@ class MLAEdit {
588
  $screen = convert_to_screen( 'attachment' );
589
  $page = $screen->id;
590
 
591
- if ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_EDIT_MEDIA_SEARCH_TAXONOMY ) ) {
592
  $taxonomies = get_taxonomies( array ( 'show_ui' => true ), 'objects' );
593
  foreach ( $taxonomies as $key => $value ) {
594
- if ( MLAOptions::mla_taxonomy_support( $key ) ) {
595
  if ( $value->hierarchical ) {
596
  foreach ( array_keys( $wp_meta_boxes[$page] ) as $a_context ) {
597
  foreach ( array('high', 'sorted', 'core', 'default', 'low') as $a_priority ) {
598
  if ( isset( $wp_meta_boxes[$page][$a_context][$a_priority][ $key . 'div' ] ) ) {
599
  $box = &$wp_meta_boxes[$page][$a_context][$a_priority][ $key . 'div' ];
600
  if ( 'post_categories_meta_box' == $box['callback'] ) {
601
- $box['callback'] = 'MLAEdit::mla_checklist_meta_box';
602
  }
603
  } // isset $box
604
  } // foreach priority
605
  } // foreach context
606
- } /* hierarchical */ elseif ( MLAOptions::mla_taxonomy_support( $key, 'flat-checklist' ) ) {
607
  foreach ( array_keys( $wp_meta_boxes[$page] ) as $a_context ) {
608
  foreach ( array('high', 'sorted', 'core', 'default', 'low') as $a_priority ) {
609
  if ( isset( $wp_meta_boxes[$page][$a_context][$a_priority][ 'tagsdiv-' . $key ] ) ) {
610
  $box = &$wp_meta_boxes[$page][$a_context][$a_priority][ 'tagsdiv-' . $key ];
611
  if ( 'post_tags_meta_box' == $box['callback'] ) {
612
- $box['callback'] = 'MLAEdit::mla_checklist_meta_box';
613
  }
614
  } // isset $box
615
  } // foreach priority
@@ -619,7 +613,7 @@ class MLAEdit {
619
  } // foreach
620
  } // MLA_EDIT_MEDIA_SEARCH_TAXONOMY
621
 
622
- if ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_EDIT_MEDIA_META_BOXES ) ) {
623
  $active_boxes = apply_filters( 'mla_edit_media_meta_boxes', array(
624
  'mla-parent-info' => 'mla-parent-info', 'mla-menu-order' => 'mla-menu-order', 'mla-image-metadata' => 'mla-image-metadata', 'mla-featured-in' => 'mla-featured-in', 'mla-inserted-in' => 'mla-inserted-in', 'mla-gallery-in' => 'mla-gallery-in', 'mla-mla-gallery-in' => 'mla-mla-gallery-in' ) );
625
 
@@ -638,19 +632,19 @@ class MLAEdit {
638
  }
639
  }
640
 
641
- if ( isset( $active_boxes['mla-featured-in'] ) && MLAOptions::$process_featured_in ) {
642
  add_meta_box( 'mla-featured-in', __( 'Featured in', 'media-library-assistant' ), 'MLAEdit::mla_featured_in_handler', 'attachment', 'normal', 'core' );
643
  }
644
 
645
- if ( isset( $active_boxes['mla-inserted-in'] ) && MLAOptions::$process_inserted_in ) {
646
  add_meta_box( 'mla-inserted-in', __( 'Inserted in', 'media-library-assistant' ), 'MLAEdit::mla_inserted_in_handler', 'attachment', 'normal', 'core' );
647
  }
648
 
649
- if ( isset( $active_boxes['mla-gallery-in'] ) && MLAOptions::$process_gallery_in ) {
650
  add_meta_box( 'mla-gallery-in', __( 'Gallery in', 'media-library-assistant' ), 'MLAEdit::mla_gallery_in_handler', 'attachment', 'normal', 'core' );
651
  }
652
 
653
- if ( isset( $active_boxes['mla-mla-gallery-in'] ) && MLAOptions::$process_mla_gallery_in ) {
654
  add_meta_box( 'mla-mla-gallery-in', __( 'MLA Gallery in', 'media-library-assistant' ), 'MLAEdit::mla_mla_gallery_in_handler', 'attachment', 'normal', 'core' );
655
  }
656
  }
@@ -766,7 +760,7 @@ class MLAEdit {
766
  *
767
  * @var array
768
  */
769
- private static $mla_references = null;
770
 
771
  /**
772
  * Renders the Parent Info meta box on the Edit Media page.
@@ -780,7 +774,7 @@ class MLAEdit {
780
  */
781
  public static function mla_parent_info_handler( $post ) {
782
  if ( is_null( self::$mla_references ) ) {
783
- self::$mla_references = MLAData::mla_fetch_attachment_references( $post->ID, $post->post_parent );
784
  }
785
 
786
  if ( is_array( self::$mla_references ) ) {
@@ -845,7 +839,7 @@ class MLAEdit {
845
  * @return void echoes the HTML markup for the meta box content
846
  */
847
  public static function mla_image_metadata_handler( $post ) {
848
- $metadata = MLAData::mla_fetch_attachment_metadata( $post->ID );
849
 
850
  if ( isset( $metadata['mla_wp_attachment_metadata'] ) ) {
851
  $value = var_export( $metadata['mla_wp_attachment_metadata'], true );
@@ -871,7 +865,7 @@ class MLAEdit {
871
  */
872
  public static function mla_featured_in_handler( $post ) {
873
  if ( is_null( self::$mla_references ) ) {
874
- self::$mla_references = MLAData::mla_fetch_attachment_references( $post->ID, $post->post_parent );
875
  }
876
 
877
  $features = '';
@@ -906,7 +900,7 @@ class MLAEdit {
906
  */
907
  public static function mla_inserted_in_handler( $post ) {
908
  if ( is_null( self::$mla_references ) ) {
909
- self::$mla_references = MLAData::mla_fetch_attachment_references( $post->ID, $post->post_parent );
910
  }
911
 
912
  $inserts = '';
@@ -945,7 +939,7 @@ class MLAEdit {
945
  */
946
  public static function mla_gallery_in_handler( $post ) {
947
  if ( is_null( self::$mla_references ) ) {
948
- self::$mla_references = MLAData::mla_fetch_attachment_references( $post->ID, $post->post_parent );
949
  }
950
 
951
  $galleries = '';
@@ -980,7 +974,7 @@ class MLAEdit {
980
  */
981
  public static function mla_mla_gallery_in_handler( $post ) {
982
  if ( is_null( self::$mla_references ) ) {
983
- self::$mla_references = MLAData::mla_fetch_attachment_references( $post->ID, $post->post_parent );
984
  }
985
 
986
  $galleries = '';
@@ -1027,289 +1021,6 @@ class MLAEdit {
1027
  MLAData::mla_update_single_item( $post_ID, $new_data );
1028
  }
1029
  } // mla_edit_attachment_action
1030
-
1031
- /**
1032
- * Add flat taxonomy term from "checklist" meta box on the Media Manager Modal Window
1033
- *
1034
- * Adapted from the WordPress post_categories_meta_box() in /wp-admin/includes/meta-boxes.php.
1035
- *
1036
- * @since 1.80
1037
- *
1038
- * @param string The taxonomy name, from $_POST['action']
1039
- *
1040
- * @return void Sends JSON response with updated HTML for the checklist
1041
- */
1042
- private static function _mla_ajax_add_flat_term( $key ) {
1043
- $taxonomy = get_taxonomy( $key );
1044
- check_ajax_referer( $_POST['action'], '_ajax_nonce-add-' . $key, true );
1045
-
1046
- if ( !current_user_can( $taxonomy->cap->edit_terms ) ) {
1047
- wp_die( -1 );
1048
- }
1049
-
1050
- $new_names = explode( ',', $_POST[ 'new' . $key ] );
1051
- $new_terms_markup = '';
1052
- foreach( $new_names as $name ) {
1053
- if ( '' === sanitize_title( $name ) ) {
1054
- continue;
1055
- }
1056
-
1057
- if ( ! $id = term_exists( $name, $key ) ) {
1058
- $id = wp_insert_term( $name, $key );
1059
- }
1060
-
1061
- if ( is_wp_error( $id ) ) {
1062
- continue;
1063
- }
1064
-
1065
- if ( is_array( $id ) ) {
1066
- $id = absint( $id['term_id'] );
1067
- } else {
1068
- continue;
1069
- }
1070
- $term = get_term( $id, $key );
1071
- $name = $term->name;
1072
- $new_terms_markup .= "<li id='{$key}-{$id}'><label class='selectit'><input value='{$name}' type='checkbox' name='tax_input[{$key}][]' id='in-{$key}-{$id}' checked='checked' />{$name}</label></li>\n";
1073
- } // foreach new_name
1074
-
1075
- $input_new_parent_name = "new{$key}_parent";
1076
- $supplemental = "<input type='hidden' name='{$input_new_parent_name}' id='{$input_new_parent_name}' value='-1' />";
1077
-
1078
- $add = array(
1079
- 'what' => $key,
1080
- 'id' => $id,
1081
- 'data' => $new_terms_markup,
1082
- 'position' => -1,
1083
- 'supplemental' => array( 'newcat_parent' => $supplemental )
1084
- );
1085
-
1086
- $x = new WP_Ajax_Response( $add );
1087
- $x->send();
1088
- } // _mla_ajax_add_flat_term
1089
-
1090
- /**
1091
- * Display taxonomy "checklist" form fields
1092
- *
1093
- * Adapted from /wp-admin/includes/ajax-actions.php function _wp_ajax_add_hierarchical_term().
1094
- * Includes the "? Search" area to filter the term checklist by entering part
1095
- * or all of a word/phrase in the term label.
1096
- * Output to the Media/Edit Media screen and to the Media Manager Modal Window.
1097
- *
1098
- * @since 1.71
1099
- *
1100
- * @param object The current post
1101
- * @param array The meta box parameters
1102
- *
1103
- * @return void Echoes HTML for the form fields
1104
- */
1105
- public static function mla_checklist_meta_box( $target_post, $box ) {
1106
- global $post;
1107
-
1108
- $defaults = array('taxonomy' => 'category', 'in_modal' => false );
1109
- $post_id = $target_post->ID;
1110
-
1111
- if ( !isset( $box['args'] ) || !is_array( $box['args'] ) ) {
1112
- $args = array();
1113
- } else {
1114
- $args = $box['args'];
1115
- }
1116
-
1117
- extract( wp_parse_args( $args, $defaults ), EXTR_SKIP );
1118
- $tax = get_taxonomy( $taxonomy );
1119
- $name = ( $taxonomy == 'category' ) ? 'post_category' : 'tax_input[' . $taxonomy . ']';
1120
-
1121
- /*
1122
- * Id and Name attributes in the popup Modal Window must not conflict with
1123
- * the underlying Edit Post/Page window, so we prefix with "mla-"/"mla_".
1124
- */
1125
- if ( $in_modal ) {
1126
- if ( empty( $post ) ) {
1127
- $post = $target_post; // for wp_popular_terms_checklist
1128
- }
1129
-
1130
- $div_taxonomy_id = "mla-taxonomy-{$taxonomy}";
1131
- $tabs_ul_id = "mla-{$taxonomy}-tabs";
1132
- $tab_all_id = "mla-{$taxonomy}-all";
1133
- $tab_all_ul_id = "mla-{$taxonomy}-checklist";
1134
- $tab_pop_id = "mla-{$taxonomy}-pop";
1135
- $tab_pop_ul_id = "mla-{$taxonomy}-checklist-pop";
1136
- $input_terms_name = "mla_attachments[{$post_id}][{$name}][]";
1137
- $input_terms_id = "mla-{$name}-id";
1138
- $div_adder_id = "mla-{$taxonomy}-adder";
1139
- $div_adder_class = "mla-hidden-children";
1140
- $link_adder_id = "mla-{$taxonomy}-add-toggle";
1141
- $link_adder_p_id = "mla-{$taxonomy}-add";
1142
- $div_search_id = "mla-{$taxonomy}-searcher";
1143
- $div_search_class = "mla-hidden-children";
1144
- $link_search_id = "mla-{$taxonomy}-search-toggle";
1145
- $link_search_p_id = "mla-{$taxonomy}-search";
1146
- $input_new_name = "new{$taxonomy}";
1147
- $input_new_id = "mla-new-{$taxonomy}";
1148
- $input_new_parent_name = "new{$taxonomy}_parent";
1149
- $input_new_submit_id = "mla-{$taxonomy}-add-submit";
1150
- $span_new_ajax_id = "mla-{$taxonomy}-ajax-response";
1151
- $input_search_name = "search-{$taxonomy}";
1152
- $input_search_id = "mla-search-{$taxonomy}";
1153
- $span_search_ajax_id = "mla-{$taxonomy}-search-ajax-response";
1154
- } else {
1155
- $div_taxonomy_id = "taxonomy-{$taxonomy}";
1156
- $tabs_ul_id = "{$taxonomy}-tabs";
1157
- $tab_all_id = "{$taxonomy}-all";
1158
- $tab_all_ul_id = "{$taxonomy}checklist";
1159
- $tab_pop_id = "{$taxonomy}-pop";
1160
- $tab_pop_ul_id = "{$taxonomy}checklist-pop";
1161
- $input_terms_name = "{$name}[]";
1162
- $input_terms_id = "{$name}-id";
1163
- $div_adder_id = "{$taxonomy}-adder";
1164
- $div_adder_class = "wp-hidden-children";
1165
- $link_adder_id = "{$taxonomy}-add-toggle";
1166
- $link_adder_p_id = "{$taxonomy}-add";
1167
- $div_search_id = "{$taxonomy}-searcher";
1168
- $div_search_class = "wp-hidden-children";
1169
- $link_search_id = "{$taxonomy}-search-toggle";
1170
- $link_search_p_id = "{$taxonomy}-search";
1171
- $input_new_name = "new{$taxonomy}";
1172
- $input_new_id = "new{$taxonomy}";
1173
- $input_new_parent_name = "new{$taxonomy}_parent";
1174
- $input_new_submit_id = "{$taxonomy}-add-submit";
1175
- $span_new_ajax_id = "{$taxonomy}-ajax-response";
1176
- $input_search_name = "search-{$taxonomy}";
1177
- $input_search_id = "search-{$taxonomy}";
1178
- $span_search_ajax_id = "{$taxonomy}-search-ajax-response";
1179
- }
1180
- ?>
1181
- <div id="<?php echo $div_taxonomy_id; ?>" class="categorydiv">
1182
- <ul id="<?php echo $tabs_ul_id; ?>" class="category-tabs">
1183
- <li class="tabs"><a href="#<?php echo $tab_all_id; ?>"><?php echo $tax->labels->all_items; ?></a></li>
1184
- <li class="hide-if-no-js"><a href="#<?php echo $tab_pop_id; ?>"><?php _e( 'Most Used' ); ?></a></li>
1185
- </ul>
1186
-
1187
- <div id="<?php echo $tab_pop_id; ?>" class="tabs-panel" style="display: none;">
1188
- <ul id="<?php echo $tab_pop_ul_id; ?>" class="categorychecklist form-no-clear" >
1189
- <?php $popular_ids = wp_popular_terms_checklist($taxonomy); ?>
1190
- </ul>
1191
- </div>
1192
-
1193
- <div id="<?php echo $tab_all_id; ?>" class="tabs-panel">
1194
- <?php
1195
- // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
1196
- echo "<input type='hidden' name='{$input_terms_name}' id='{$input_terms_id}' value='0' />";
1197
- ?>
1198
- <ul id="<?php echo $tab_all_ul_id; ?>" data-wp-lists="list:<?php echo $taxonomy?>" class="categorychecklist form-no-clear">
1199
- <?php if ( $tax->hierarchical ): ?>
1200
- <?php wp_terms_checklist($post->ID, array( 'taxonomy' => $taxonomy, 'popular_cats' => $popular_ids, 'checked_ontop'=> MLAOptions::mla_taxonomy_support( $taxonomy, 'checked-on-top' ) ) ) ?>
1201
- <?php else: ?>
1202
- <?php $checklist_walker = new MLA_Checklist_Walker; ?>
1203
- <?php wp_terms_checklist($post->ID, array( 'taxonomy' => $taxonomy, 'popular_cats' => $popular_ids, 'checked_ontop'=> MLAOptions::mla_taxonomy_support( $taxonomy, 'checked-on-top' ), 'walker' => $checklist_walker ) ) ?>
1204
- <?php endif; ?>
1205
- </ul>
1206
- </div>
1207
- <?php if ( current_user_can($tax->cap->edit_terms) ) : ?>
1208
- <div id="<?php echo $div_adder_id; ?>" class="<?php echo $div_adder_class; ?>">
1209
- <h4>
1210
- <a id="<?php echo $link_adder_id; ?>" href="#<?php echo $link_adder_p_id; ?>" class="hide-if-no-js">
1211
- <?php
1212
- /* translators: %s: add new taxonomy label */
1213
- printf( __( '+ %s', 'media-library-assistant' ), $tax->labels->add_new_item );
1214
- ?>
1215
- </a>
1216
- &nbsp;&nbsp;
1217
- <a id="<?php echo $link_search_id; ?>" href="#<?php echo $link_search_p_id; ?>" class="hide-if-no-js">
1218
- <?php
1219
- echo '?&nbsp;' . __( 'Search', 'media-library-assistant' );
1220
- ?>
1221
- </a>
1222
- </h4>
1223
- <p id="<?php echo $link_adder_p_id; ?>" class="category-add wp-hidden-child">
1224
- <label class="screen-reader-text" for="<?php echo $input_new_name; ?>"><?php echo $tax->labels->add_new_item; ?></label>
1225
- <input type="text" name="<?php echo $input_new_name; ?>" id="<?php echo $input_new_id; ?>" class="form-required form-input-tip" value="<?php echo esc_attr( $tax->labels->new_item_name ); ?>" aria-required="true"/>
1226
-
1227
- <?php if ( $tax->hierarchical ): ?>
1228
- <label class="screen-reader-text" for="<?php echo $input_new_parent_name; ?>">
1229
- <?php echo $tax->labels->parent_item_colon; ?>
1230
- </label>
1231
- <?php wp_dropdown_categories( array( 'taxonomy' => $taxonomy, 'hide_empty' => 0, 'name' => $input_new_parent_name, 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => '&mdash; ' . $tax->labels->parent_item . ' &mdash;' ) ); ?>
1232
- <?php else:
1233
- echo "<input type='hidden' name='{$input_new_parent_name}' id='{$input_new_parent_name}' value='-1' />";
1234
- endif; ?>
1235
- <input type="button" id="<?php echo $input_new_submit_id; ?>" data-wp-lists="add:<?php echo $tab_all_ul_id ?>:<?php echo $link_adder_p_id ?>" class="button category-add-submit mla-taxonomy-add-submit" value="<?php echo esc_attr( $tax->labels->add_new_item ); ?>" />
1236
- <?php wp_nonce_field( 'add-'.$taxonomy, '_ajax_nonce-add-'.$taxonomy, false ); ?>
1237
- <span id="<?php echo $span_new_ajax_id; ?>"></span>
1238
- </p>
1239
- </div>
1240
- <div id="<?php echo $div_search_id; ?>" class="<?php echo $div_search_class; ?>">
1241
- <p id="<?php echo $link_search_p_id; ?>" class="category-add wp-hidden-child">
1242
- <label class="screen-reader-text" for="<?php echo $input_search_name; ?>"><?php echo $tax->labels->search_items; ?></label>
1243
- <input type="text" name="<?php echo $input_search_name; ?>" id="<?php echo $input_search_id; ?>" class="form-required form-input-tip" value="<?php echo esc_attr( $tax->labels->search_items ); ?>" aria-required="true"/>
1244
- <?php wp_nonce_field( 'search-'.$taxonomy, '_ajax_nonce-search-'.$taxonomy, false ); ?>
1245
- <span id="<?php echo $span_search_ajax_id; ?>"></span>
1246
- </p>
1247
- </div>
1248
- <?php endif; ?>
1249
- </div>
1250
- <?php
1251
- } // mla_checklist_meta_box
1252
  } //Class MLAEdit
1253
 
1254
- /**
1255
- * Class MLA (Media Library Assistant) Checklist Walker replaces term_id with slug in checklist output
1256
- *
1257
- * This walker is used to build the meta boxes for flat taxonomies, e.g., Tags, Att. Tags.
1258
- * Class Walker_Category is defined in /wp-includes/category-template.php.
1259
- * Class Walker is defined in /wp-includes/class-wp-walker.php.
1260
- *
1261
- * @package Media Library Assistant
1262
- * @since 1.80
1263
- */
1264
- class MLA_Checklist_Walker extends Walker_Category {
1265
- /**
1266
- * Start the element output.
1267
- *
1268
- * @see Walker::start_el()
1269
- *
1270
- * @since 1.80
1271
- *
1272
- * @param string Passed by reference. Used to append additional content.
1273
- * @param object Taxonomy data object.
1274
- * @param int Depth of category in reference to parents. Default 0.
1275
- * @param array An array of arguments. @see wp_list_categories()
1276
- * @param int ID of the current category.
1277
- */
1278
- function start_el( &$output, $taxonomy_object, $depth = 0, $args = array(), $id = 0 ) {
1279
- extract($args);
1280
-
1281
- if ( empty( $taxonomy ) ) {
1282
- $taxonomy = 'category';
1283
- }
1284
-
1285
- if ( 'category' == $taxonomy ) {
1286
- $name = 'post_category';
1287
- } else {
1288
- $name = 'tax_input['.$taxonomy.']';
1289
- }
1290
-
1291
- $class = in_array( $taxonomy_object->term_id, $popular_cats ) ? ' class="popular-category"' : '';
1292
-
1293
- /*
1294
- * For flat taxonomies, <input> value is $taxonomy_object->name instead of $taxonomy_object->term_id
1295
- */
1296
- $output .= "\n<li id='{$taxonomy}-{$taxonomy_object->term_id}'$class>" . '<label class="selectit MLA"><input value="' . $taxonomy_object->name . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $taxonomy_object->term_id . '"' . checked( in_array( $taxonomy_object->term_id, $selected_cats ), true, false ) . disabled( empty( $args['disabled'] ), false, false ) . ' /> ' . esc_html( apply_filters('the_category', $taxonomy_object->name )) . '</label>';
1297
- }
1298
-
1299
- /**
1300
- * Ends the element output, if needed.
1301
- *
1302
- * @see Walker::end_el()
1303
- *
1304
- * @since 1.80
1305
- *
1306
- * @param string $output Passed by reference. Used to append additional content.
1307
- * @param object $category The current term object.
1308
- * @param int $depth Depth of the term in reference to parents. Default 0.
1309
- * @param array $args An array of arguments. @see wp_terms_checklist()
1310
- */
1311
- function end_el( &$output, $category, $depth = 0, $args = array() ) {
1312
- $output .= "</li>\n";
1313
- }
1314
- }// Class MLA_Checklist_Walker
1315
  ?>
79
  * @return void echoes the HTML markup for the label and value
80
  */
81
  public static function mla_admin_init_action( ) {
 
 
82
  $edit_media_support = array( 'custom-fields' );
83
+ if ( ( 'checked' == MLACore::mla_get_option( 'enable_featured_image' ) ) && current_theme_supports( 'post-thumbnails', 'attachment' ) ) {
84
  $edit_media_support[] = 'thumbnail';
85
  }
86
 
89
  /*
90
  * Check for Media/Add New bulk edit area updates
91
  */
92
+ if ( ! empty( $_REQUEST['mlaAddNewBulkEditFormString'] ) && ( 'checked' == MLACore::mla_get_option( MLACore::MLA_ADD_NEW_BULK_EDIT ) ) ) {
93
  /*
94
  * If any of the mapping rule options is enabled, use the MLA filter so this
95
  * filter is called after mapping rules have run. If none are enabled,
96
  * use the WordPress filter directly.
97
  */
98
+ if ( ( 'checked' == MLACore::mla_get_option( 'enable_iptc_exif_mapping' ) ) ||
99
+ ( 'checked' == MLACore::mla_get_option( 'enable_custom_field_mapping' ) ) ||
100
+ ( 'checked' == MLACore::mla_get_option( 'enable_iptc_exif_update' ) ) ||
101
+ ( 'checked' == MLACore::mla_get_option( 'enable_custom_field_update' ) ) ) {
102
  // Fires after MLA mapping in wp_update_attachment_metadata() processing.
103
  add_filter( 'mla_update_attachment_metadata_postfilter', 'MLAEdit::mla_update_attachment_metadata_postfilter', 10, 3 );
104
  } else {
113
  return;
114
  }
115
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  /*
117
  * For flat taxonomies that use the checklist meta box, convert the term array
118
  * back into a string of slug values.
156
  /*
157
  * Add New Bulk Edit Area
158
  */
159
+ if ( 'media-new.php' == $page_hook && ( 'checked' == MLACore::mla_get_option( MLACore::MLA_ADD_NEW_BULK_EDIT ) ) ) {
160
  if ( $wp_locale->is_rtl() ) {
161
  wp_register_style( 'mla-add-new-bulk-edit', MLA_PLUGIN_URL . 'css/mla-add-new-bulk-edit-rtl.css', false, MLA::CURRENT_MLA_VERSION );
162
  wp_register_style( 'mla-add-new-bulk-edit' . '-set-parent', MLA_PLUGIN_URL . 'css/mla-style-set-parent-rtl.css', false, MLA::CURRENT_MLA_VERSION );
179
  'uploadTitle' => __( 'Upload New Media items', 'media-library-assistant' ),
180
  'toggleOpen' => __( 'Open Bulk Edit area', 'media-library-assistant' ),
181
  'toggleClose' => __( 'Close Bulk Edit area', 'media-library-assistant' ),
182
+ 'areaOnTop' => ( 'checked' == MLACore::mla_get_option( MLACore::MLA_ADD_NEW_BULK_EDIT_ON_TOP ) ),
183
+ 'areaOpen' => ( 'checked' == MLACore::mla_get_option( MLACore::MLA_ADD_NEW_BULK_EDIT_AUTO_OPEN ) ),
184
  'comma' => _x( ',', 'tag_delimiter', 'media-library-assistant' ),
185
  'ajaxFailError' => __( 'An ajax.fail error has occurred. Please reload the page and try again.', 'media-library-assistant' ),
186
  'ajaxDoneError' => __( 'An ajax.done error has occurred. Please reload the page and try again.', 'media-library-assistant' ),
303
  $hierarchical_taxonomies = array();
304
  $flat_taxonomies = array();
305
  foreach ( $taxonomies as $tax_name => $tax_object ) {
306
+ if ( $tax_object->hierarchical && $tax_object->show_ui && MLACore::mla_taxonomy_support($tax_name, 'quick-edit') ) {
307
  $hierarchical_taxonomies[$tax_name] = $tax_object;
308
+ } elseif ( $tax_object->show_ui && MLACore::mla_taxonomy_support($tax_name, 'quick-edit') ) {
309
  $flat_taxonomies[$tax_name] = $tax_object;
310
  }
311
  }
400
  }
401
 
402
  $custom_fields = '';
403
+ foreach (MLACore::mla_custom_field_support( 'bulk_edit' ) as $slug => $details ) {
404
  $page_values = array(
405
  'slug' => $slug,
406
  'label' => esc_attr( $details['name'] ),
433
  'set_parent_form' => $set_parent_form,
434
  );
435
 
436
+ $page_values = apply_filters( 'mla_upload_bulk_edit_form_values', $page_values );
437
+ $page_template = apply_filters( 'mla_upload_bulk_edit_form_template', $page_template_array['page'] );
438
+ $parse_value = MLAData::mla_parse_template( $page_template, $page_values );
439
+ echo apply_filters( 'mla_upload_bulk_edit_form_parse', $parse_value, $page_template, $page_values );
440
  }
441
 
442
  /**
458
  public static function mla_update_attachment_metadata_postfilter( $data, $post_id, $options = array( 'is_upload' => true ) ) {
459
  if ( ( true == $options['is_upload'] ) && ! empty( $_REQUEST['mlaAddNewBulkEditFormString'] ) ) {
460
  /*
461
+ * Clean up the inputs, which have everything from the enclosing <form>
462
  */
463
  $args = wp_parse_args( stripslashes( urldecode( $_REQUEST['mlaAddNewBulkEditFormString'] ) ) );
464
+
465
  unset( $args['parent'] );
466
  unset( $args['children'] );
467
  unset( $args['mla-set-parent-ajax-nonce'] );
534
  echo "</div><!-- .misc-pub-section -->\n";
535
  echo '<div class="misc-pub-section mla-links">' . "\n";
536
 
537
+ $view_args = array( 'page' => MLACore::ADMIN_PAGE_SLUG, 'mla_item_ID' => $post->ID );
538
  if ( isset( $_REQUEST['mla_source'] ) ) {
539
  $view_args['mla_source'] = $_REQUEST['mla_source'];
540
  }
541
+ if ( isset( $_REQUEST['lang'] ) ) {
542
+ $view_args['lang'] = $_REQUEST['lang'];
543
+ }
544
 
545
  echo '<span id="mla_metadata_links" style="font-weight: bold; line-height: 2em">';
546
 
547
+ 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>';
548
 
549
+ 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>';
550
 
551
  echo "</span>\n";
552
  echo "</div><!-- .misc-pub-section -->\n";
582
  $screen = convert_to_screen( 'attachment' );
583
  $page = $screen->id;
584
 
585
+ if ( 'checked' == MLACore::mla_get_option( MLACore::MLA_EDIT_MEDIA_SEARCH_TAXONOMY ) ) {
586
  $taxonomies = get_taxonomies( array ( 'show_ui' => true ), 'objects' );
587
  foreach ( $taxonomies as $key => $value ) {
588
+ if ( MLACore::mla_taxonomy_support( $key ) ) {
589
  if ( $value->hierarchical ) {
590
  foreach ( array_keys( $wp_meta_boxes[$page] ) as $a_context ) {
591
  foreach ( array('high', 'sorted', 'core', 'default', 'low') as $a_priority ) {
592
  if ( isset( $wp_meta_boxes[$page][$a_context][$a_priority][ $key . 'div' ] ) ) {
593
  $box = &$wp_meta_boxes[$page][$a_context][$a_priority][ $key . 'div' ];
594
  if ( 'post_categories_meta_box' == $box['callback'] ) {
595
+ $box['callback'] = 'MLACore::mla_checklist_meta_box';
596
  }
597
  } // isset $box
598
  } // foreach priority
599
  } // foreach context
600
+ } /* hierarchical */ elseif ( MLACore::mla_taxonomy_support( $key, 'flat-checklist' ) ) {
601
  foreach ( array_keys( $wp_meta_boxes[$page] ) as $a_context ) {
602
  foreach ( array('high', 'sorted', 'core', 'default', 'low') as $a_priority ) {
603
  if ( isset( $wp_meta_boxes[$page][$a_context][$a_priority][ 'tagsdiv-' . $key ] ) ) {
604
  $box = &$wp_meta_boxes[$page][$a_context][$a_priority][ 'tagsdiv-' . $key ];
605
  if ( 'post_tags_meta_box' == $box['callback'] ) {
606
+ $box['callback'] = 'MLACore::mla_checklist_meta_box';
607
  }
608
  } // isset $box
609
  } // foreach priority
613
  } // foreach
614
  } // MLA_EDIT_MEDIA_SEARCH_TAXONOMY
615
 
616
+ if ( 'checked' == MLACore::mla_get_option( MLACore::MLA_EDIT_MEDIA_META_BOXES ) ) {
617
  $active_boxes = apply_filters( 'mla_edit_media_meta_boxes', array(
618
  'mla-parent-info' => 'mla-parent-info', 'mla-menu-order' => 'mla-menu-order', 'mla-image-metadata' => 'mla-image-metadata', 'mla-featured-in' => 'mla-featured-in', 'mla-inserted-in' => 'mla-inserted-in', 'mla-gallery-in' => 'mla-gallery-in', 'mla-mla-gallery-in' => 'mla-mla-gallery-in' ) );
619
 
632
  }
633
  }
634
 
635
+ if ( isset( $active_boxes['mla-featured-in'] ) && MLACore::$process_featured_in ) {
636
  add_meta_box( 'mla-featured-in', __( 'Featured in', 'media-library-assistant' ), 'MLAEdit::mla_featured_in_handler', 'attachment', 'normal', 'core' );
637
  }
638
 
639
+ if ( isset( $active_boxes['mla-inserted-in'] ) && MLACore::$process_inserted_in ) {
640
  add_meta_box( 'mla-inserted-in', __( 'Inserted in', 'media-library-assistant' ), 'MLAEdit::mla_inserted_in_handler', 'attachment', 'normal', 'core' );
641
  }
642
 
643
+ if ( isset( $active_boxes['mla-gallery-in'] ) && MLACore::$process_gallery_in ) {
644
  add_meta_box( 'mla-gallery-in', __( 'Gallery in', 'media-library-assistant' ), 'MLAEdit::mla_gallery_in_handler', 'attachment', 'normal', 'core' );
645
  }
646
 
647
+ if ( isset( $active_boxes['mla-mla-gallery-in'] ) && MLACore::$process_mla_gallery_in ) {
648
  add_meta_box( 'mla-mla-gallery-in', __( 'MLA Gallery in', 'media-library-assistant' ), 'MLAEdit::mla_mla_gallery_in_handler', 'attachment', 'normal', 'core' );
649
  }
650
  }
760
  *
761
  * @var array
762
  */
763
+ private static $mla_references = NULL;
764
 
765
  /**
766
  * Renders the Parent Info meta box on the Edit Media page.
774
  */
775
  public static function mla_parent_info_handler( $post ) {
776
  if ( is_null( self::$mla_references ) ) {
777
+ self::$mla_references = MLAQuery::mla_fetch_attachment_references( $post->ID, $post->post_parent );
778
  }
779
 
780
  if ( is_array( self::$mla_references ) ) {
839
  * @return void echoes the HTML markup for the meta box content
840
  */
841
  public static function mla_image_metadata_handler( $post ) {
842
+ $metadata = MLAQuery::mla_fetch_attachment_metadata( $post->ID );
843
 
844
  if ( isset( $metadata['mla_wp_attachment_metadata'] ) ) {
845
  $value = var_export( $metadata['mla_wp_attachment_metadata'], true );
865
  */
866
  public static function mla_featured_in_handler( $post ) {
867
  if ( is_null( self::$mla_references ) ) {
868
+ self::$mla_references = MLAQuery::mla_fetch_attachment_references( $post->ID, $post->post_parent );
869
  }
870
 
871
  $features = '';
900
  */
901
  public static function mla_inserted_in_handler( $post ) {
902
  if ( is_null( self::$mla_references ) ) {
903
+ self::$mla_references = MLAQuery::mla_fetch_attachment_references( $post->ID, $post->post_parent );
904
  }
905
 
906
  $inserts = '';
939
  */
940
  public static function mla_gallery_in_handler( $post ) {
941
  if ( is_null( self::$mla_references ) ) {
942
+ self::$mla_references = MLAQuery::mla_fetch_attachment_references( $post->ID, $post->post_parent );
943
  }
944
 
945
  $galleries = '';
974
  */
975
  public static function mla_mla_gallery_in_handler( $post ) {
976
  if ( is_null( self::$mla_references ) ) {
977
+ self::$mla_references = MLAQuery::mla_fetch_attachment_references( $post->ID, $post->post_parent );
978
  }
979
 
980
  $galleries = '';
1021
  MLAData::mla_update_single_item( $post_ID, $new_data );
1022
  }
1023
  } // mla_edit_attachment_action
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1024
  } //Class MLAEdit
1025
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1026
  ?>
includes/class-mla-image-processor.php CHANGED
@@ -279,7 +279,7 @@ class MLAImageProcessor {
279
  private static function _mla_debug_add( $message ) {
280
  if ( self::$mla_debug ) {
281
  if ( class_exists( 'MLA' ) ) {
282
- MLA::mla_debug_add( $message );
283
  } else {
284
  error_log( $message, 0);
285
  }
279
  private static function _mla_debug_add( $message ) {
280
  if ( self::$mla_debug ) {
281
  if ( class_exists( 'MLA' ) ) {
282
+ MLACore::mla_debug_add( $message );
283
  } else {
284
  error_log( $message, 0);
285
  }
includes/class-mla-list-table.php CHANGED
@@ -90,22 +90,13 @@ class MLA_List_Table extends WP_List_Table {
90
 
91
  /*
92
  * The $default_columns, $default_hidden_columns, and $default_sortable_columns
93
- * arrays define the table columns.
 
94
  */
95
 
96
  /**
97
  * Table column definitions
98
  *
99
- * This array defines table columns and titles where the key is the column slug (and class)
100
- * and the value is the column's title text. If you need a checkbox for bulk actions,
101
- * use the special slug "cb".
102
- *
103
- * The 'cb' column is treated differently than the rest. If including a checkbox
104
- * column in your table you must create a column_cb() method. If you don't need
105
- * bulk actions or checkboxes, simply leave the 'cb' entry out of your array.
106
- *
107
- * All of the columns are added to this array by MLA_List_Table::mla_admin_init_action.
108
- *
109
  * @since 0.1
110
  *
111
  * @var array
@@ -115,86 +106,20 @@ class MLA_List_Table extends WP_List_Table {
115
  /**
116
  * Default values for hidden columns
117
  *
118
- * This array is used when the user-level option is not set, i.e.,
119
- * the user has not altered the selection of hidden columns.
120
- *
121
- * The value on the right-hand side must match the column slug, e.g.,
122
- * array(0 => 'ID_parent, 1 => 'title_name').
123
- *
124
- * Taxonomy and custom field columns are added to this array by
125
- * MLA_List_Table::mla_admin_init_action.
126
- *
127
  * @since 0.1
128
  *
129
  * @var array
130
  */
131
- protected static $default_hidden_columns = array(
132
- // 'ID_parent',
133
- // 'title_name',
134
- 'post_title',
135
- 'post_name',
136
- 'parent',
137
- 'menu_order',
138
- // 'featured',
139
- // 'inserted,
140
- 'galleries',
141
- 'mla_galleries',
142
- 'alt_text',
143
- 'caption',
144
- 'description',
145
- 'post_mime_type',
146
- 'file_url',
147
- 'base_file',
148
- 'date',
149
- 'modified',
150
- 'author',
151
- 'attached_to',
152
- // taxonomy columns added by mla_admin_init_action
153
- // custom field columns added by mla_admin_init_action
154
- );
155
 
156
  /**
157
  * Sortable column definitions
158
  *
159
- * This array defines the table columns that can be sorted. The array key
160
- * is the column slug that needs to be sortable, and the value is database column
161
- * to sort by. Often, the key and value will be the same, but this is not always
162
- * the case (as the value is a column name from the database, not the list table).
163
- *
164
- * The array value also contains a boolean which is 'true' if the initial sort order
165
- * for the column is DESC/Descending.
166
- *
167
- * Taxonomy and custom field columns are added to this array by
168
- * MLA_List_Table::mla_admin_init_action.
169
- *
170
  * @since 0.1
171
  *
172
  * @var array
173
  */
174
- protected static $default_sortable_columns = array(
175
- 'ID_parent' => array('ID',true),
176
- 'title_name' => array('title_name',false),
177
- 'post_title' => array('post_title',false),
178
- 'post_name' => array('post_name',false),
179
- 'parent' => array('post_parent',false),
180
- 'menu_order' => array('menu_order',false),
181
- // 'featured' => array('featured',false),
182
- // 'inserted' => array('inserted',false),
183
- // 'galleries' => array('galleries',false),
184
- // 'mla_galleries' => array('mla_galleries',false),
185
- 'alt_text' => array('_wp_attachment_image_alt',true),
186
- 'caption' => array('post_excerpt',false),
187
- 'description' => array('post_content',false),
188
- 'post_mime_type' => array('post_mime_type',false),
189
- 'file_url' => array('guid',false),
190
- 'base_file' => array('_wp_attached_file',false),
191
- 'date' => array('post_date',true),
192
- 'modified' => array('post_modified',true),
193
- 'author' => array('post_author',false),
194
- 'attached_to' => array('post_parent',false),
195
- // sortable taxonomy columns, if any, added by mla_admin_init_action
196
- // sortable custom field columns, if any, added by mla_admin_init_action
197
- );
198
 
199
  /**
200
  * Get MIME types with one or more attachments for view preparation
@@ -220,46 +145,6 @@ class MLA_List_Table extends WP_List_Table {
220
  return $available;
221
  }
222
 
223
- /**
224
- * Builds the $default_columns array with translated source texts.
225
- *
226
- * Called from MLATest::initialize because the $default_columns information
227
- * might be accessed from "front end" posts/pages.
228
- *
229
- * @since 1.71
230
- */
231
- public static function mla_localize_default_columns_array( ) {
232
- /*
233
- * Build the default columns array at runtime to accomodate calls to the
234
- * localization functions
235
- */
236
- self::$default_columns = array(
237
- 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
238
- 'icon' => '',
239
- 'ID_parent' => esc_html( _x( 'ID/Parent', 'list_table_column', 'media-library-assistant' ) ),
240
- 'title_name' => esc_html( _x( 'Title/Name', 'list_table_column', 'media-library-assistant' ) ),
241
- 'post_title' => esc_html( _x( 'Title', 'list_table_column', 'media-library-assistant' ) ),
242
- 'post_name' => esc_html( _x( 'Name', 'list_table_column', 'media-library-assistant' ) ),
243
- 'parent' => esc_html( _x( 'Parent ID', 'list_table_column', 'media-library-assistant' ) ),
244
- 'menu_order' => esc_html( _x( 'Menu Order', 'list_table_column', 'media-library-assistant' ) ),
245
- 'featured' => esc_html( _x( 'Featured in', 'list_table_column', 'media-library-assistant' ) ),
246
- 'inserted' => esc_html( _x( 'Inserted in', 'list_table_column', 'media-library-assistant' ) ),
247
- 'galleries' => esc_html( _x( 'Gallery in', 'list_table_column', 'media-library-assistant' ) ),
248
- 'mla_galleries' => esc_html( _x( 'MLA Gallery in', 'list_table_column', 'media-library-assistant' ) ),
249
- 'alt_text' => esc_html( _x( 'ALT Text', 'list_table_column', 'media-library-assistant' ) ),
250
- 'caption' => esc_html( _x( 'Caption', 'list_table_column', 'media-library-assistant' ) ),
251
- 'description' => esc_html( _x( 'Description', 'list_table_column', 'media-library-assistant' ) ),
252
- 'post_mime_type' => esc_html( _x( 'MIME Type', 'list_table_column', 'media-library-assistant' ) ),
253
- 'file_url' => esc_html( _x( 'File URL', 'list_table_column', 'media-library-assistant' ) ),
254
- 'base_file' => esc_html( _x( 'Base File', 'list_table_column', 'media-library-assistant' ) ),
255
- 'date' => esc_html( _x( 'Date', 'list_table_column', 'media-library-assistant' ) ),
256
- 'modified' => esc_html( _x( 'Last Modified', 'list_table_column', 'media-library-assistant' ) ),
257
- 'author' => esc_html( _x( 'Author', 'list_table_column', 'media-library-assistant' ) ),
258
- 'attached_to' => esc_html( _x( 'Attached to', 'list_table_column', 'media-library-assistant' ) ),
259
- // taxonomy and custom field columns added below
260
- );
261
- }
262
-
263
  /**
264
  * Get dropdown box of terms to filter by, if available
265
  *
@@ -271,7 +156,7 @@ class MLA_List_Table extends WP_List_Table {
271
  */
272
  public static function mla_get_taxonomy_filter_dropdown( $selected = 0 ) {
273
  $dropdown = '';
274
- $tax_filter = MLAOptions::mla_taxonomy_support('', 'filter');
275
 
276
  if ( ( '' != $tax_filter ) && ( is_object_in_taxonomy( 'attachment', $tax_filter ) ) ) {
277
  $tax_object = get_taxonomy( $tax_filter );
@@ -286,7 +171,7 @@ class MLA_List_Table extends WP_List_Table {
286
  'exclude' => '',
287
  // 'exclude_tree => '',
288
  'echo' => true,
289
- 'depth' => MLAOptions::mla_get_option( MLAOptions::MLA_TAXONOMY_FILTER_DEPTH ),
290
  'tab_index' => 0,
291
  'name' => 'mla_filter_term',
292
  'id' => 'name',
@@ -307,24 +192,6 @@ class MLA_List_Table extends WP_List_Table {
307
  return $dropdown;
308
  }
309
 
310
- /**
311
- * Return the names and display values of the sortable columns
312
- *
313
- * @since 0.30
314
- *
315
- * @return array name => array( orderby value, heading ) for sortable columns
316
- */
317
- public static function mla_get_sortable_columns( ) {
318
- $results = array() ;
319
-
320
- foreach ( self::$default_sortable_columns as $key => $value ) {
321
- $value[1] = self::$default_columns[ $key ];
322
- $results[ $key ] = $value;
323
- }
324
-
325
- return $results;
326
- }
327
-
328
  /**
329
  * Process $_REQUEST, building $submenu_arguments
330
  *
@@ -490,20 +357,9 @@ class MLA_List_Table extends WP_List_Table {
490
  * @since 0.30
491
  */
492
  public static function mla_admin_init_action( ) {
493
- $taxonomies = get_taxonomies( array ( 'show_ui' => true ), 'names' );
494
-
495
- foreach ( $taxonomies as $tax_name ) {
496
- if ( MLAOptions::mla_taxonomy_support( $tax_name ) ) {
497
- $tax_object = get_taxonomy( $tax_name );
498
- self::$default_columns[ 't_' . $tax_name ] = esc_html( $tax_object->labels->name );
499
- self::$default_hidden_columns [] = 't_' . $tax_name;
500
- // self::$default_sortable_columns [] = none at this time
501
- } // supported taxonomy
502
- } // foreach $tax_name
503
-
504
- self::$default_columns = array_merge( self::$default_columns, MLAOptions::mla_custom_field_support( 'default_columns' ) );
505
- self::$default_hidden_columns = array_merge( self::$default_hidden_columns, MLAOptions::mla_custom_field_support( 'default_hidden_columns' ) );
506
- self::$default_sortable_columns = array_merge( self::$default_sortable_columns, MLAOptions::mla_custom_field_support( 'default_sortable_columns' ) );
507
  }
508
 
509
  /**
@@ -527,7 +383,7 @@ class MLA_List_Table extends WP_List_Table {
527
  'singular' => 'attachment', //singular name of the listed records
528
  'plural' => 'attachments', //plural name of the listed records
529
  'ajax' => true, //does this table support ajax?
530
- 'screen' => 'media_page_' . MLA::ADMIN_PAGE_SLUG
531
  ), self::$default_columns );
532
 
533
  $this->currently_hidden = self::get_hidden_columns();
@@ -587,7 +443,7 @@ class MLA_List_Table extends WP_List_Table {
587
  foreach ( $terms as $term ) {
588
  $term_name = esc_html( sanitize_term_field( 'name', $term->name, $term->term_id, $taxonomy, 'display' ) );
589
  $list[] = sprintf( '<a href="%1$s" title="' . __( 'Filter by', 'media-library-assistant' ) . ' &#8220;%2$s&#8221;">%3$s</a>', esc_url( add_query_arg( array_merge( array(
590
- 'page' => MLA::ADMIN_PAGE_SLUG,
591
  'mla-tax' => $taxonomy,
592
  'mla-term' => $term->slug,
593
  'heading_suffix' => urlencode( $tax_object->label . ': ' . $term->name )
@@ -601,7 +457,7 @@ class MLA_List_Table extends WP_List_Table {
601
  } // 't_'
602
  elseif ( 'c_' == substr( $column_name, 0, 2 ) ) {
603
  if ( NULL === $custom_columns ) {
604
- $custom_columns = MLAOptions::mla_custom_field_support( 'custom_columns' );
605
  }
606
 
607
  $values = get_post_meta( $item->ID, $custom_columns[ $column_name ], false );
@@ -620,7 +476,7 @@ class MLA_List_Table extends WP_List_Table {
620
  $list[] = 'array( ' . @implode( ', ', $value ) . ' )';
621
  } else {
622
  $list[] = sprintf( '<a href="%1$s" title="' . __( 'Filter by', 'media-library-assistant' ) . ' &#8220;%2$s&#8221;">%3$s</a>', esc_url( add_query_arg( array_merge( array(
623
- 'page' => MLA::ADMIN_PAGE_SLUG,
624
  'mla-metakey' => urlencode( self::$default_columns[ $column_name ] ),
625
  'mla-metavalue' => urlencode( $value ),
626
  'heading_suffix' => urlencode( self::$default_columns[ $column_name ] . ': ' . $value )
@@ -793,7 +649,7 @@ class MLA_List_Table extends WP_List_Table {
793
  /*
794
  * Build rollover actions
795
  */
796
- $view_args = array_merge( array( 'page' => MLA::ADMIN_PAGE_SLUG, 'mla_item_ID' => $item->ID ),
797
  self::mla_submenu_arguments() );
798
 
799
  if ( isset( $_REQUEST['paged'] ) ) {
@@ -802,7 +658,7 @@ class MLA_List_Table extends WP_List_Table {
802
 
803
  if ( current_user_can( 'edit_post', $item->ID ) ) {
804
  if ( $this->is_trash ) {
805
- $actions['restore'] = '<a class="submitdelete" href="' . add_query_arg( $view_args, wp_nonce_url( '?mla_admin_action=' . MLA::MLA_ADMIN_SINGLE_RESTORE, MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME ) ) . '" title="' . __( 'Restore this item from the Trash', 'media-library-assistant' ) . '">' . __( 'Restore', 'media-library-assistant' ) . '</a>';
806
  } else {
807
  /*
808
  * Use the WordPress Edit Media screen
@@ -820,20 +676,20 @@ class MLA_List_Table extends WP_List_Table {
820
 
821
  if ( current_user_can( 'delete_post', $item->ID ) ) {
822
  if ( !$this->is_trash && EMPTY_TRASH_DAYS && MEDIA_TRASH ) {
823
- $actions['trash'] = '<a class="submitdelete" href="' . add_query_arg( $view_args, wp_nonce_url( '?mla_admin_action=' . MLA::MLA_ADMIN_SINGLE_TRASH, MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME ) ) . '" title="' . __( 'Move this item to the Trash', 'media-library-assistant' ) . '">' . __( 'Move to Trash', 'media-library-assistant' ) . '</a>';
824
  } else {
825
  // If using trash for posts and pages but not for attachments, warn before permanently deleting
826
  $delete_ays = EMPTY_TRASH_DAYS && !MEDIA_TRASH ? ' onclick="return showNotice.warn();"' : '';
827
 
828
- $actions['delete'] = '<a class="submitdelete"' . $delete_ays . ' href="' . add_query_arg( $view_args, wp_nonce_url( '?mla_admin_action=' . MLA::MLA_ADMIN_SINGLE_DELETE, MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME ) ) . '" title="' . __( 'Delete this item Permanently', 'media-library-assistant' ) . '">' . __( 'Delete Permanently', 'media-library-assistant' ) . '</a>';
829
  }
830
  } // delete_post
831
 
832
  if ( current_user_can( 'upload_files' ) ) {
833
  $file = get_attached_file( $item->ID );
834
- $download_args = array( 'page' => MLA::ADMIN_PAGE_SLUG, 'mla_download_file' => urlencode( $file ), 'mla_download_type' => $item->post_mime_type );
835
 
836
- $actions['download'] = '<a href="' . add_query_arg( $download_args, wp_nonce_url( 'upload.php', MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME ) ) . '" title="' . __( 'Download', 'media-library-assistant' ) . ' &#8220;' . $att_title . '&#8221;">' . __( 'Download', 'media-library-assistant' ) . '</a>';
837
  }
838
 
839
  if ( ! $this->is_trash ) {
@@ -866,8 +722,8 @@ class MLA_List_Table extends WP_List_Table {
866
  $item_id = $item->ID;
867
  }
868
 
869
- $icon_width = MLAOptions::mla_get_option( MLAOptions::MLA_TABLE_ICON_SIZE );
870
- if ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_ENABLE_MLA_ICONS ) ) {
871
  if ( empty( $icon_width ) ) {
872
  $icon_width = $icon_height = 64;
873
  } else {
@@ -949,8 +805,8 @@ class MLA_List_Table extends WP_List_Table {
949
  $inline_data .= ' <div class="menu_order">' . $item->menu_order . "</div>\r\n";
950
  $inline_data .= ' <div class="post_author">' . $item->post_author . "</div>\r\n";
951
 
952
- $custom_fields = MLAOptions::mla_custom_field_support( 'quick_edit' );
953
- $custom_fields = array_merge( $custom_fields, MLAOptions::mla_custom_field_support( 'bulk_edit' ) );
954
  foreach ( $custom_fields as $slug => $details ) {
955
  $value = get_metadata( 'post', $item->ID, $details['name'], true );
956
  $inline_data .= ' <div class="' . $slug . '">' . esc_html( $value ) . "</div>\r\n";
@@ -959,7 +815,7 @@ class MLA_List_Table extends WP_List_Table {
959
  $taxonomies = get_object_taxonomies( 'attachment', 'objects' );
960
 
961
  foreach ( $taxonomies as $tax_name => $tax_object ) {
962
- if ( $tax_object->show_ui && MLAOptions::mla_taxonomy_support( $tax_name, 'quick-edit' ) ) {
963
  $terms = get_object_term_cache( $item->ID, $tax_name );
964
  if ( false === $terms ) {
965
  $terms = wp_get_object_terms( $item->ID, $tax_name );
@@ -1053,13 +909,13 @@ class MLA_List_Table extends WP_List_Table {
1053
  $parent_title = sprintf( '%1$d %2$s', $item->post_parent, __( '(no title)', 'media-library-assistant' ) );
1054
  }
1055
 
1056
- $parent = sprintf( '<a href="%1$s" title="' . __( 'Filter by', 'media-library-assistant' ) . ' ' . __( 'Parent ID', 'media-library-assistant' ) . '">(parent:%2$s)</a>', esc_url( add_query_arg( array_merge( array(
1057
- 'page' => MLA::ADMIN_PAGE_SLUG,
1058
  'parent' => $item->post_parent,
1059
  'heading_suffix' => urlencode( __( 'Parent', 'media-library-assistant' ) . ': ' . $parent_title )
1060
  ), self::mla_submenu_arguments( false ) ), 'upload.php' ) ), (string) $item->post_parent );
1061
  } else {// $item->post_parent
1062
- $parent = 'parent:0';
1063
  }
1064
 
1065
  $content = sprintf( '%1$s<br><span style="color:silver">%2$s</span>', /*%1$s*/ $item->ID, /*%2$s*/ $parent );
@@ -1125,7 +981,7 @@ class MLA_List_Table extends WP_List_Table {
1125
  }
1126
 
1127
  return sprintf( '<a href="%1$s" title="' . __( 'Filter by', 'media-library-assistant' ) . ' ' . __( 'Parent ID', 'media-library-assistant' ) . '">%2$s</a>', esc_url( add_query_arg( array_merge( array(
1128
- 'page' => MLA::ADMIN_PAGE_SLUG,
1129
  'parent' => $item->post_parent,
1130
  'heading_suffix' => urlencode( __( 'Parent', 'media-library-assistant' ) . ': ' . $parent_title )
1131
  ), self::mla_submenu_arguments( false ) ), 'upload.php' ) ), (string) $item->post_parent );
@@ -1155,7 +1011,7 @@ class MLA_List_Table extends WP_List_Table {
1155
  * @return string HTML markup to be placed inside the column
1156
  */
1157
  function column_featured( $item ) {
1158
- if ( !MLAOptions::$process_featured_in ) {
1159
  return __( 'Disabled', 'media-library-assistant' );
1160
  }
1161
 
@@ -1200,7 +1056,7 @@ class MLA_List_Table extends WP_List_Table {
1200
  * @return string HTML markup to be placed inside the column
1201
  */
1202
  function column_inserted( $item ) {
1203
- if ( !MLAOptions::$process_inserted_in ) {
1204
  return __( 'Disabled', 'media-library-assistant' );
1205
  }
1206
 
@@ -1250,7 +1106,7 @@ class MLA_List_Table extends WP_List_Table {
1250
  * @return string HTML markup to be placed inside the column
1251
  */
1252
  function column_galleries( $item ) {
1253
- if ( !MLAOptions::$process_gallery_in ) {
1254
  return __( 'Disabled', 'media-library-assistant' );
1255
  }
1256
 
@@ -1295,7 +1151,7 @@ class MLA_List_Table extends WP_List_Table {
1295
  * @return string HTML markup to be placed inside the column
1296
  */
1297
  function column_mla_galleries( $item ) {
1298
- if ( !MLAOptions::$process_mla_gallery_in ) {
1299
  return __( 'Disabled', 'media-library-assistant' );
1300
  }
1301
 
@@ -1348,7 +1204,7 @@ class MLA_List_Table extends WP_List_Table {
1348
  }
1349
 
1350
  return sprintf( '<a href="%1$s" title="' . __( 'Filter by', 'media-library-assistant' ) . ' &#8220;%2$s&#8221;">%3$s</a>', esc_url( add_query_arg( array_merge( array(
1351
- 'page' => MLA::ADMIN_PAGE_SLUG,
1352
  'mla-metakey' => '_wp_attachment_image_alt',
1353
  'mla-metavalue' => urlencode( $alt_text ),
1354
  'heading_suffix' => urlencode( __( 'ALT Text', 'media-library-assistant' ) . ': ' . $alt_text )
@@ -1392,7 +1248,7 @@ class MLA_List_Table extends WP_List_Table {
1392
  */
1393
  function column_post_mime_type( $item ) {
1394
  return sprintf( '<a href="%1$s" title="' . __( 'Filter by', 'media-library-assistant' ) . ' &#8220;%2$s&#8221;">%2$s</a>', esc_url( add_query_arg( array_merge( array(
1395
- 'page' => MLA::ADMIN_PAGE_SLUG,
1396
  'post_mime_type' => urlencode( $item->post_mime_type ),
1397
  'heading_suffix' => urlencode( __( 'MIME Type', 'media-library-assistant' ) . ': ' . $item->post_mime_type )
1398
  ), self::mla_submenu_arguments( false ) ), 'upload.php' ) ), esc_html( $item->post_mime_type ), esc_html( $item->post_mime_type ) );
@@ -1424,7 +1280,7 @@ class MLA_List_Table extends WP_List_Table {
1424
  $base_file = isset( $item->mla_wp_attached_file ) ? $item->mla_wp_attached_file : '';
1425
 
1426
  return sprintf( '<a href="%1$s" title="' . __( 'Filter by', 'media-library-assistant' ) . ' &#8220;%2$s&#8221;">%2$s</a>', esc_url( add_query_arg( array_merge( array(
1427
- 'page' => MLA::ADMIN_PAGE_SLUG,
1428
  'mla-metakey' => urlencode( '_wp_attached_file' ),
1429
  'mla-metavalue' => urlencode( $base_file ),
1430
  'heading_suffix' => urlencode( __( 'Base File', 'media-library-assistant' ) . ': ' . $base_file )
@@ -1508,7 +1364,7 @@ class MLA_List_Table extends WP_List_Table {
1508
 
1509
  if ( isset( $user->data->display_name ) ) {
1510
  return sprintf( '<a href="%s" title="' . __( 'Filter by', 'media-library-assistant' ) . ' ' . __( 'Author', 'media-library-assistant' ) . '">%s</a>', esc_url( add_query_arg( array_merge( array(
1511
- 'page' => MLA::ADMIN_PAGE_SLUG,
1512
  'author' => $item->post_author,
1513
  'heading_suffix' => urlencode( __( 'Author', 'media-library-assistant' ) . ': ' . $user->data->display_name )
1514
  ), self::mla_submenu_arguments( false ) ), 'upload.php' ) ), esc_html( $user->data->display_name ) );
@@ -1588,7 +1444,7 @@ class MLA_List_Table extends WP_List_Table {
1588
  * @return array Column information,e.g., array(0 => 'ID_parent, 1 => 'title_name')
1589
  */
1590
  function get_hidden_columns( ) {
1591
- $columns = get_user_option( 'managemedia_page_' . MLA::ADMIN_PAGE_SLUG . 'columnshidden' );
1592
 
1593
  if ( is_array( $columns ) ) {
1594
  foreach ( $columns as $index => $value ){
@@ -1656,7 +1512,7 @@ class MLA_List_Table extends WP_List_Table {
1656
  */
1657
  private static function _get_view( $view_slug, $current_view ) {
1658
  global $wpdb;
1659
- static $mla_types = NULL, $posts_per_type, $post_mime_types, $avail_post_mime_types, $matches, $num_posts, $detached_items;
1660
 
1661
  /*
1662
  * Calculate the common values once per page load
@@ -1672,6 +1528,7 @@ class MLA_List_Table extends WP_List_Table {
1672
  $mla_types[ $value->slug ] = $value;
1673
  }
1674
 
 
1675
  $posts_per_type = (array) wp_count_attachments();
1676
  $post_mime_types = get_post_mime_types();
1677
  $avail_post_mime_types = self::_avail_mime_types( $posts_per_type );
@@ -1687,10 +1544,10 @@ class MLA_List_Table extends WP_List_Table {
1687
  }
1688
 
1689
  $class = ( $view_slug == $current_view ) ? ' class="current"' : '';
1690
- $base_url = 'upload.php?page=' . MLA::ADMIN_PAGE_SLUG;
1691
 
1692
  /*
1693
- * Handle the special cases: all, unattached and trash
1694
  */
1695
  switch( $view_slug ) {
1696
  case 'all':
@@ -1698,7 +1555,7 @@ class MLA_List_Table extends WP_List_Table {
1698
  return "<a href='{$base_url}'$class>" . sprintf( _nx( 'All', 'All', $total_items, 'uploaded files', 'media-library-assistant' ) . ' <span class="count">(%1$s)</span></a>', number_format_i18n( $total_items ) );
1699
  case 'detached':
1700
  if ( $detached_items ) {
1701
- $value = MLAOptions::$mla_option_definitions[ MLAOptions::MLA_POST_MIME_TYPES ]['std']['detached'];
1702
  $singular = sprintf('%s <span class="count">(%%s)</span>', $value['singular'] );
1703
  $plural = sprintf('%s <span class="count">(%%s)</span>', $value['plural'] );
1704
  return '<a href="' . add_query_arg( array( 'detached' => '1' ), $base_url ) . '"' . $class . '>' . sprintf( _nx( $singular, $plural, $detached_items, 'detached files', 'media-library-assistant' ), number_format_i18n( $detached_items ) ) . '</a>';
@@ -1707,7 +1564,7 @@ class MLA_List_Table extends WP_List_Table {
1707
  return false;
1708
  case 'attached':
1709
  if ( $attached_items = ( array_sum( $posts_per_type ) - $posts_per_type['trash'] ) - $detached_items ) {
1710
- $value = MLAOptions::$mla_option_definitions[ MLAOptions::MLA_POST_MIME_TYPES ]['std']['attached'];
1711
  $singular = sprintf('%s <span class="count">(%%s)</span>', $value['singular'] );
1712
  $plural = sprintf('%s <span class="count">(%%s)</span>', $value['plural'] );
1713
  return '<a href="' . add_query_arg( array( 'detached' => '0' ), $base_url ) . '"' . $class . '>' . sprintf( _nx( $singular, $plural, $attached_items, 'attached files', 'media-library-assistant' ), number_format_i18n( $attached_items ) ) . '</a>';
@@ -1716,7 +1573,7 @@ class MLA_List_Table extends WP_List_Table {
1716
  return false;
1717
  case 'trash':
1718
  if ( $posts_per_type['trash'] ) {
1719
- $value = MLAOptions::$mla_option_definitions[ MLAOptions::MLA_POST_MIME_TYPES ]['std']['trash'];
1720
  $singular = sprintf('%s <span class="count">(%%s)</span>', $value['singular'] );
1721
  $plural = sprintf('%s <span class="count">(%%s)</span>', $value['plural'] );
1722
  return '<a href="' . add_query_arg( array( 'status' => 'trash'
@@ -1753,10 +1610,10 @@ class MLA_List_Table extends WP_List_Table {
1753
  if ( empty( $mla_type->specification ) ) {
1754
  $query = array ( 'post_mime_type' => $view_slug );
1755
  } else {
1756
- $query = MLAMime::mla_prepare_view_query( $view_slug, $mla_type->specification );
1757
  }
1758
 
1759
- $total_items = MLAData::mla_count_list_table_items( $query );
1760
  if ( $total_items ) {
1761
  $singular = sprintf('%s <span class="count">(%%s)</span>', $mla_type->singular );
1762
  $plural = sprintf('%s <span class="count">(%%s)</span>', $mla_type->plural );
@@ -1878,7 +1735,7 @@ class MLA_List_Table extends WP_List_Table {
1878
  'id' => 'post-query-submit'
1879
  ) );
1880
 
1881
- $term_search_taxonomies = MLAOptions::mla_supported_taxonomies('term-search');
1882
  if ( ! empty( $term_search_taxonomies ) ) {
1883
  submit_button( __( 'Terms Search', 'media-library-assistant' ), 'secondary', 'mla_filter', false, array(
1884
  'id' => 'mla-terms-search-open', 'onclick' => 'mlaTaxonomy.termsSearch.open()'
@@ -1933,7 +1790,7 @@ class MLA_List_Table extends WP_List_Table {
1933
  */
1934
  $total_items = apply_filters_ref_array( 'mla_list_table_prepare_items_total_items', array( NULL, &$this ) );
1935
  if ( is_null( $total_items ) ) {
1936
- $total_items = MLAData::mla_count_list_table_items( $_REQUEST, ( ( $current_page - 1 ) * $per_page ), $per_page );
1937
  }
1938
 
1939
  /*
@@ -1947,7 +1804,7 @@ class MLA_List_Table extends WP_List_Table {
1947
 
1948
  $this->items = apply_filters_ref_array( 'mla_list_table_prepare_items_the_items', array( NULL, &$this ) );
1949
  if ( is_null( $this->items ) ) {
1950
- $this->items = MLAData::mla_query_list_table_items( $_REQUEST, ( ( $current_page - 1 ) * $per_page ), $per_page );
1951
  }
1952
 
1953
  do_action_ref_array( 'mla_list_table_prepare_items', array( &$this ) );
@@ -1982,6 +1839,6 @@ class MLA_List_Table extends WP_List_Table {
1982
  */
1983
  add_action( 'admin_init', 'MLA_List_Table::mla_admin_init_action' );
1984
 
1985
- add_filter( 'get_user_option_managemedia_page_' . MLA::ADMIN_PAGE_SLUG . 'columnshidden', 'MLA_List_Table::mla_manage_hidden_columns_filter', 10, 3 );
1986
- add_filter( 'manage_media_page_' . MLA::ADMIN_PAGE_SLUG . '_columns', 'MLA_List_Table::mla_manage_columns_filter', 10, 0 );
1987
  ?>
90
 
91
  /*
92
  * The $default_columns, $default_hidden_columns, and $default_sortable_columns
93
+ * arrays define the "Media/Assistant" table columns. The copies here are Compatibility
94
+ * shims for the real variables in MLAQuery.
95
  */
96
 
97
  /**
98
  * Table column definitions
99
  *
 
 
 
 
 
 
 
 
 
 
100
  * @since 0.1
101
  *
102
  * @var array
106
  /**
107
  * Default values for hidden columns
108
  *
 
 
 
 
 
 
 
 
 
109
  * @since 0.1
110
  *
111
  * @var array
112
  */
113
+ protected static $default_hidden_columns = array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
 
115
  /**
116
  * Sortable column definitions
117
  *
 
 
 
 
 
 
 
 
 
 
 
118
  * @since 0.1
119
  *
120
  * @var array
121
  */
122
+ protected static $default_sortable_columns = array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
 
124
  /**
125
  * Get MIME types with one or more attachments for view preparation
145
  return $available;
146
  }
147
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  /**
149
  * Get dropdown box of terms to filter by, if available
150
  *
156
  */
157
  public static function mla_get_taxonomy_filter_dropdown( $selected = 0 ) {
158
  $dropdown = '';
159
+ $tax_filter = MLACore::mla_taxonomy_support('', 'filter');
160
 
161
  if ( ( '' != $tax_filter ) && ( is_object_in_taxonomy( 'attachment', $tax_filter ) ) ) {
162
  $tax_object = get_taxonomy( $tax_filter );
171
  'exclude' => '',
172
  // 'exclude_tree => '',
173
  'echo' => true,
174
+ 'depth' => MLACore::mla_get_option( MLACore::MLA_TAXONOMY_FILTER_DEPTH ),
175
  'tab_index' => 0,
176
  'name' => 'mla_filter_term',
177
  'id' => 'name',
192
  return $dropdown;
193
  }
194
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  /**
196
  * Process $_REQUEST, building $submenu_arguments
197
  *
357
  * @since 0.30
358
  */
359
  public static function mla_admin_init_action( ) {
360
+ self::$default_columns =& MLAQuery::$default_columns;
361
+ self::$default_hidden_columns =& MLAQuery::$default_hidden_columns;
362
+ self::$default_sortable_columns =& MLAQuery::$default_sortable_columns;
 
 
 
 
 
 
 
 
 
 
 
363
  }
364
 
365
  /**
383
  'singular' => 'attachment', //singular name of the listed records
384
  'plural' => 'attachments', //plural name of the listed records
385
  'ajax' => true, //does this table support ajax?
386
+ 'screen' => 'media_page_' . MLACore::ADMIN_PAGE_SLUG
387
  ), self::$default_columns );
388
 
389
  $this->currently_hidden = self::get_hidden_columns();
443
  foreach ( $terms as $term ) {
444
  $term_name = esc_html( sanitize_term_field( 'name', $term->name, $term->term_id, $taxonomy, 'display' ) );
445
  $list[] = sprintf( '<a href="%1$s" title="' . __( 'Filter by', 'media-library-assistant' ) . ' &#8220;%2$s&#8221;">%3$s</a>', esc_url( add_query_arg( array_merge( array(
446
+ 'page' => MLACore::ADMIN_PAGE_SLUG,
447
  'mla-tax' => $taxonomy,
448
  'mla-term' => $term->slug,
449
  'heading_suffix' => urlencode( $tax_object->label . ': ' . $term->name )
457
  } // 't_'
458
  elseif ( 'c_' == substr( $column_name, 0, 2 ) ) {
459
  if ( NULL === $custom_columns ) {
460
+ $custom_columns = MLACore::mla_custom_field_support( 'custom_columns' );
461
  }
462
 
463
  $values = get_post_meta( $item->ID, $custom_columns[ $column_name ], false );
476
  $list[] = 'array( ' . @implode( ', ', $value ) . ' )';
477
  } else {
478
  $list[] = sprintf( '<a href="%1$s" title="' . __( 'Filter by', 'media-library-assistant' ) . ' &#8220;%2$s&#8221;">%3$s</a>', esc_url( add_query_arg( array_merge( array(
479
+ 'page' => MLACore::ADMIN_PAGE_SLUG,
480
  'mla-metakey' => urlencode( self::$default_columns[ $column_name ] ),
481
  'mla-metavalue' => urlencode( $value ),
482
  'heading_suffix' => urlencode( self::$default_columns[ $column_name ] . ': ' . $value )
649
  /*
650
  * Build rollover actions
651
  */
652
+ $view_args = array_merge( array( 'page' => MLACore::ADMIN_PAGE_SLUG, 'mla_item_ID' => $item->ID ),
653
  self::mla_submenu_arguments() );
654
 
655
  if ( isset( $_REQUEST['paged'] ) ) {
658
 
659
  if ( current_user_can( 'edit_post', $item->ID ) ) {
660
  if ( $this->is_trash ) {
661
+ $actions['restore'] = '<a class="submitdelete" href="' . add_query_arg( $view_args, wp_nonce_url( '?mla_admin_action=' . MLACore::MLA_ADMIN_SINGLE_RESTORE, MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ) ) . '" title="' . __( 'Restore this item from the Trash', 'media-library-assistant' ) . '">' . __( 'Restore', 'media-library-assistant' ) . '</a>';
662
  } else {
663
  /*
664
  * Use the WordPress Edit Media screen
676
 
677
  if ( current_user_can( 'delete_post', $item->ID ) ) {
678
  if ( !$this->is_trash && EMPTY_TRASH_DAYS && MEDIA_TRASH ) {
679
+ $actions['trash'] = '<a class="submitdelete" href="' . add_query_arg( $view_args, wp_nonce_url( '?mla_admin_action=' . MLACore::MLA_ADMIN_SINGLE_TRASH, MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ) ) . '" title="' . __( 'Move this item to the Trash', 'media-library-assistant' ) . '">' . __( 'Move to Trash', 'media-library-assistant' ) . '</a>';
680
  } else {
681
  // If using trash for posts and pages but not for attachments, warn before permanently deleting
682
  $delete_ays = EMPTY_TRASH_DAYS && !MEDIA_TRASH ? ' onclick="return showNotice.warn();"' : '';
683
 
684
+ $actions['delete'] = '<a class="submitdelete"' . $delete_ays . ' 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>';
685
  }
686
  } // delete_post
687
 
688
  if ( current_user_can( 'upload_files' ) ) {
689
  $file = get_attached_file( $item->ID );
690
+ $download_args = array( 'page' => MLACore::ADMIN_PAGE_SLUG, 'mla_download_file' => urlencode( $file ), 'mla_download_type' => $item->post_mime_type );
691
 
692
+ $actions['download'] = '<a href="' . add_query_arg( $download_args, wp_nonce_url( 'upload.php', MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ) ) . '" title="' . __( 'Download', 'media-library-assistant' ) . ' &#8220;' . $att_title . '&#8221;">' . __( 'Download', 'media-library-assistant' ) . '</a>';
693
  }
694
 
695
  if ( ! $this->is_trash ) {
722
  $item_id = $item->ID;
723
  }
724
 
725
+ $icon_width = MLACore::mla_get_option( MLACore::MLA_TABLE_ICON_SIZE );
726
+ if ( 'checked' == MLACore::mla_get_option( MLACore::MLA_ENABLE_MLA_ICONS ) ) {
727
  if ( empty( $icon_width ) ) {
728
  $icon_width = $icon_height = 64;
729
  } else {
805
  $inline_data .= ' <div class="menu_order">' . $item->menu_order . "</div>\r\n";
806
  $inline_data .= ' <div class="post_author">' . $item->post_author . "</div>\r\n";
807
 
808
+ $custom_fields = MLACore::mla_custom_field_support( 'quick_edit' );
809
+ $custom_fields = array_merge( $custom_fields, MLACore::mla_custom_field_support( 'bulk_edit' ) );
810
  foreach ( $custom_fields as $slug => $details ) {
811
  $value = get_metadata( 'post', $item->ID, $details['name'], true );
812
  $inline_data .= ' <div class="' . $slug . '">' . esc_html( $value ) . "</div>\r\n";
815
  $taxonomies = get_object_taxonomies( 'attachment', 'objects' );
816
 
817
  foreach ( $taxonomies as $tax_name => $tax_object ) {
818
+ if ( $tax_object->show_ui && MLACore::mla_taxonomy_support( $tax_name, 'quick-edit' ) ) {
819
  $terms = get_object_term_cache( $item->ID, $tax_name );
820
  if ( false === $terms ) {
821
  $terms = wp_get_object_terms( $item->ID, $tax_name );
909
  $parent_title = sprintf( '%1$d %2$s', $item->post_parent, __( '(no title)', 'media-library-assistant' ) );
910
  }
911
 
912
+ $parent = sprintf( '<a href="%1$s" title="' . __( 'Filter by', 'media-library-assistant' ) . ' ' . __( 'Parent ID', 'media-library-assistant' ) . '">(' . __( 'Parent', 'media-library-assistant' ) . ':%2$s)</a>', esc_url( add_query_arg( array_merge( array(
913
+ 'page' => MLACore::ADMIN_PAGE_SLUG,
914
  'parent' => $item->post_parent,
915
  'heading_suffix' => urlencode( __( 'Parent', 'media-library-assistant' ) . ': ' . $parent_title )
916
  ), self::mla_submenu_arguments( false ) ), 'upload.php' ) ), (string) $item->post_parent );
917
  } else {// $item->post_parent
918
+ $parent = __( 'Parent', 'media-library-assistant' ) . ':0';
919
  }
920
 
921
  $content = sprintf( '%1$s<br><span style="color:silver">%2$s</span>', /*%1$s*/ $item->ID, /*%2$s*/ $parent );
981
  }
982
 
983
  return sprintf( '<a href="%1$s" title="' . __( 'Filter by', 'media-library-assistant' ) . ' ' . __( 'Parent ID', 'media-library-assistant' ) . '">%2$s</a>', esc_url( add_query_arg( array_merge( array(
984
+ 'page' => MLACore::ADMIN_PAGE_SLUG,
985
  'parent' => $item->post_parent,
986
  'heading_suffix' => urlencode( __( 'Parent', 'media-library-assistant' ) . ': ' . $parent_title )
987
  ), self::mla_submenu_arguments( false ) ), 'upload.php' ) ), (string) $item->post_parent );
1011
  * @return string HTML markup to be placed inside the column
1012
  */
1013
  function column_featured( $item ) {
1014
+ if ( !MLACore::$process_featured_in ) {
1015
  return __( 'Disabled', 'media-library-assistant' );
1016
  }
1017
 
1056
  * @return string HTML markup to be placed inside the column
1057
  */
1058
  function column_inserted( $item ) {
1059
+ if ( !MLACore::$process_inserted_in ) {
1060
  return __( 'Disabled', 'media-library-assistant' );
1061
  }
1062
 
1106
  * @return string HTML markup to be placed inside the column
1107
  */
1108
  function column_galleries( $item ) {
1109
+ if ( !MLACore::$process_gallery_in ) {
1110
  return __( 'Disabled', 'media-library-assistant' );
1111
  }
1112
 
1151
  * @return string HTML markup to be placed inside the column
1152
  */
1153
  function column_mla_galleries( $item ) {
1154
+ if ( !MLACore::$process_mla_gallery_in ) {
1155
  return __( 'Disabled', 'media-library-assistant' );
1156
  }
1157
 
1204
  }
1205
 
1206
  return sprintf( '<a href="%1$s" title="' . __( 'Filter by', 'media-library-assistant' ) . ' &#8220;%2$s&#8221;">%3$s</a>', esc_url( add_query_arg( array_merge( array(
1207
+ 'page' => MLACore::ADMIN_PAGE_SLUG,
1208
  'mla-metakey' => '_wp_attachment_image_alt',
1209
  'mla-metavalue' => urlencode( $alt_text ),
1210
  'heading_suffix' => urlencode( __( 'ALT Text', 'media-library-assistant' ) . ': ' . $alt_text )
1248
  */
1249
  function column_post_mime_type( $item ) {
1250
  return sprintf( '<a href="%1$s" title="' . __( 'Filter by', 'media-library-assistant' ) . ' &#8220;%2$s&#8221;">%2$s</a>', esc_url( add_query_arg( array_merge( array(
1251
+ 'page' => MLACore::ADMIN_PAGE_SLUG,
1252
  'post_mime_type' => urlencode( $item->post_mime_type ),
1253
  'heading_suffix' => urlencode( __( 'MIME Type', 'media-library-assistant' ) . ': ' . $item->post_mime_type )
1254
  ), self::mla_submenu_arguments( false ) ), 'upload.php' ) ), esc_html( $item->post_mime_type ), esc_html( $item->post_mime_type ) );
1280
  $base_file = isset( $item->mla_wp_attached_file ) ? $item->mla_wp_attached_file : '';
1281
 
1282
  return sprintf( '<a href="%1$s" title="' . __( 'Filter by', 'media-library-assistant' ) . ' &#8220;%2$s&#8221;">%2$s</a>', esc_url( add_query_arg( array_merge( array(
1283
+ 'page' => MLACore::ADMIN_PAGE_SLUG,
1284
  'mla-metakey' => urlencode( '_wp_attached_file' ),
1285
  'mla-metavalue' => urlencode( $base_file ),
1286
  'heading_suffix' => urlencode( __( 'Base File', 'media-library-assistant' ) . ': ' . $base_file )
1364
 
1365
  if ( isset( $user->data->display_name ) ) {
1366
  return sprintf( '<a href="%s" title="' . __( 'Filter by', 'media-library-assistant' ) . ' ' . __( 'Author', 'media-library-assistant' ) . '">%s</a>', esc_url( add_query_arg( array_merge( array(
1367
+ 'page' => MLACore::ADMIN_PAGE_SLUG,
1368
  'author' => $item->post_author,
1369
  'heading_suffix' => urlencode( __( 'Author', 'media-library-assistant' ) . ': ' . $user->data->display_name )
1370
  ), self::mla_submenu_arguments( false ) ), 'upload.php' ) ), esc_html( $user->data->display_name ) );
1444
  * @return array Column information,e.g., array(0 => 'ID_parent, 1 => 'title_name')
1445
  */
1446
  function get_hidden_columns( ) {
1447
+ $columns = get_user_option( 'managemedia_page_' . MLACore::ADMIN_PAGE_SLUG . 'columnshidden' );
1448
 
1449
  if ( is_array( $columns ) ) {
1450
  foreach ( $columns as $index => $value ){
1512
  */
1513
  private static function _get_view( $view_slug, $current_view ) {
1514
  global $wpdb;
1515
+ static $mla_types = NULL, $default_types, $posts_per_type, $post_mime_types, $avail_post_mime_types, $matches, $num_posts, $detached_items;
1516
 
1517
  /*
1518
  * Calculate the common values once per page load
1528
  $mla_types[ $value->slug ] = $value;
1529
  }
1530
 
1531
+ $default_types = MLACore::mla_get_option( MLACore::MLA_POST_MIME_TYPES, true );
1532
  $posts_per_type = (array) wp_count_attachments();
1533
  $post_mime_types = get_post_mime_types();
1534
  $avail_post_mime_types = self::_avail_mime_types( $posts_per_type );
1544
  }
1545
 
1546
  $class = ( $view_slug == $current_view ) ? ' class="current"' : '';
1547
+ $base_url = 'upload.php?page=' . MLACore::ADMIN_PAGE_SLUG;
1548
 
1549
  /*
1550
+ * Handle the special cases: all, detached, attached and trash
1551
  */
1552
  switch( $view_slug ) {
1553
  case 'all':
1555
  return "<a href='{$base_url}'$class>" . sprintf( _nx( 'All', 'All', $total_items, 'uploaded files', 'media-library-assistant' ) . ' <span class="count">(%1$s)</span></a>', number_format_i18n( $total_items ) );
1556
  case 'detached':
1557
  if ( $detached_items ) {
1558
+ $value = $default_types['detached'];
1559
  $singular = sprintf('%s <span class="count">(%%s)</span>', $value['singular'] );
1560
  $plural = sprintf('%s <span class="count">(%%s)</span>', $value['plural'] );
1561
  return '<a href="' . add_query_arg( array( 'detached' => '1' ), $base_url ) . '"' . $class . '>' . sprintf( _nx( $singular, $plural, $detached_items, 'detached files', 'media-library-assistant' ), number_format_i18n( $detached_items ) ) . '</a>';
1564
  return false;
1565
  case 'attached':
1566
  if ( $attached_items = ( array_sum( $posts_per_type ) - $posts_per_type['trash'] ) - $detached_items ) {
1567
+ $value = $default_types['attached'];
1568
  $singular = sprintf('%s <span class="count">(%%s)</span>', $value['singular'] );
1569
  $plural = sprintf('%s <span class="count">(%%s)</span>', $value['plural'] );
1570
  return '<a href="' . add_query_arg( array( 'detached' => '0' ), $base_url ) . '"' . $class . '>' . sprintf( _nx( $singular, $plural, $attached_items, 'attached files', 'media-library-assistant' ), number_format_i18n( $attached_items ) ) . '</a>';
1573
  return false;
1574
  case 'trash':
1575
  if ( $posts_per_type['trash'] ) {
1576
+ $value = $default_types['trash'];
1577
  $singular = sprintf('%s <span class="count">(%%s)</span>', $value['singular'] );
1578
  $plural = sprintf('%s <span class="count">(%%s)</span>', $value['plural'] );
1579
  return '<a href="' . add_query_arg( array( 'status' => 'trash'
1610
  if ( empty( $mla_type->specification ) ) {
1611
  $query = array ( 'post_mime_type' => $view_slug );
1612
  } else {
1613
+ $query = MLACore::mla_prepare_view_query( $view_slug, $mla_type->specification );
1614
  }
1615
 
1616
+ $total_items = MLAQuery::mla_count_list_table_items( $query );
1617
  if ( $total_items ) {
1618
  $singular = sprintf('%s <span class="count">(%%s)</span>', $mla_type->singular );
1619
  $plural = sprintf('%s <span class="count">(%%s)</span>', $mla_type->plural );
1735
  'id' => 'post-query-submit'
1736
  ) );
1737
 
1738
+ $term_search_taxonomies = MLACore::mla_supported_taxonomies('term-search');
1739
  if ( ! empty( $term_search_taxonomies ) ) {
1740
  submit_button( __( 'Terms Search', 'media-library-assistant' ), 'secondary', 'mla_filter', false, array(
1741
  'id' => 'mla-terms-search-open', 'onclick' => 'mlaTaxonomy.termsSearch.open()'
1790
  */
1791
  $total_items = apply_filters_ref_array( 'mla_list_table_prepare_items_total_items', array( NULL, &$this ) );
1792
  if ( is_null( $total_items ) ) {
1793
+ $total_items = MLAQuery::mla_count_list_table_items( $_REQUEST, ( ( $current_page - 1 ) * $per_page ), $per_page );
1794
  }
1795
 
1796
  /*
1804
 
1805
  $this->items = apply_filters_ref_array( 'mla_list_table_prepare_items_the_items', array( NULL, &$this ) );
1806
  if ( is_null( $this->items ) ) {
1807
+ $this->items = MLAQuery::mla_query_list_table_items( $_REQUEST, ( ( $current_page - 1 ) * $per_page ), $per_page );
1808
  }
1809
 
1810
  do_action_ref_array( 'mla_list_table_prepare_items', array( &$this ) );
1839
  */
1840
  add_action( 'admin_init', 'MLA_List_Table::mla_admin_init_action' );
1841
 
1842
+ add_filter( 'get_user_option_managemedia_page_' . MLACore::ADMIN_PAGE_SLUG . 'columnshidden', 'MLA_List_Table::mla_manage_hidden_columns_filter', 10, 3 );
1843
+ add_filter( 'manage_media_page_' . MLACore::ADMIN_PAGE_SLUG . '_columns', 'MLA_List_Table::mla_manage_columns_filter', 10, 0 );
1844
  ?>
includes/class-mla-main.php CHANGED
@@ -29,7 +29,7 @@ class MLA {
29
  *
30
  * @var string
31
  */
32
- const CURRENT_MLA_VERSION = '2.15';
33
 
34
  /**
35
  * Current date for Development Version, empty for production versions
@@ -49,15 +49,6 @@ class MLA {
49
  */
50
  const STYLESHEET_SLUG = 'mla-style';
51
 
52
- /**
53
- * Slug for localizing and enqueueing JavaScript - MLA List Table
54
- *
55
- * @since 0.20
56
- *
57
- * @var string
58
- */
59
- const JAVASCRIPT_INLINE_EDIT_SLUG = 'mla-inline-edit-scripts';
60
-
61
  /**
62
  * Object name for localizing JavaScript - MLA List Table
63
  *
@@ -67,42 +58,6 @@ class MLA {
67
  */
68
  const JAVASCRIPT_INLINE_EDIT_OBJECT = 'mla_inline_edit_vars';
69
 
70
- /**
71
- * Slug for adding plugin submenu
72
- *
73
- * @since 0.1
74
- *
75
- * @var string
76
- */
77
- const ADMIN_PAGE_SLUG = 'mla-menu';
78
-
79
- /**
80
- * Action name; gives a context for the nonce
81
- *
82
- * @since 0.1
83
- *
84
- * @var string
85
- */
86
- const MLA_ADMIN_NONCE_ACTION = 'mla_admin_nonce_action';
87
-
88
- /**
89
- * Nonce name; uniquely identifies the nonce
90
- *
91
- * @since 2.13
92
- *
93
- * @var string
94
- */
95
- const MLA_ADMIN_NONCE_NAME = 'mla_admin_nonce';
96
-
97
- /**
98
- * mla_admin_action value for permanently deleting a single item
99
- *
100
- * @since 0.1
101
- *
102
- * @var string
103
- */
104
- const MLA_ADMIN_SINGLE_DELETE = 'single_item_delete';
105
-
106
  /**
107
  * mla_admin_action value to display a single item for editing
108
  *
@@ -125,24 +80,6 @@ class MLA {
125
  */
126
  const MLA_ADMIN_SINGLE_EDIT_UPDATE = 'single_item_edit_update';
127
 
128
- /**
129
- * mla_admin_action value for restoring a single item from the trash
130
- *
131
- * @since 0.1
132
- *
133
- * @var string
134
- */
135
- const MLA_ADMIN_SINGLE_RESTORE = 'single_item_restore';
136
-
137
- /**
138
- * mla_admin_action value for moving a single item to the trash
139
- *
140
- * @since 0.1
141
- *
142
- * @var string
143
- */
144
- const MLA_ADMIN_SINGLE_TRASH = 'single_item_trash';
145
-
146
  /**
147
  * mla_admin_action value for mapping Custom Field metadata
148
  *
@@ -222,7 +159,7 @@ class MLA {
222
  public static function initialize( ) {
223
  global $sitepress, $polylang;
224
 
225
- if ( 'checked' == MLAOptions::mla_get_option( 'enable_featured_image_generation' ) ) {
226
  if ( class_exists( 'MLA_Thumbnail' ) ) {
227
  self::$mla_language_support_error_messages .= "<li>class MLA_Thumbnail</li>";
228
  } else {
@@ -278,33 +215,6 @@ class MLA {
278
  add_filter( 'screen_options_show_screen', 'MLA::mla_screen_options_show_screen_filter', 10, 2 ); // $show_screen, $this
279
  }
280
 
281
- /**
282
- * Original PHP error_log path and file
283
- *
284
- * @since 2.15
285
- *
286
- * @var string
287
- */
288
- public static $original_php_log = '?';
289
-
290
- /**
291
- * Original PHP error_reporting value
292
- *
293
- * @since 2.15
294
- *
295
- * @var string
296
- */
297
- public static $original_php_reporting = '?';
298
-
299
- /**
300
- * Effective MLA Debug Level, from MLA_DEBUG_LEVEL or override option
301
- *
302
- * @since 2.15
303
- *
304
- * @var integer
305
- */
306
- public static $mla_debug_level = 0;
307
-
308
  /**
309
  * Load a plugin text domain and alternate debug file
310
  *
@@ -331,7 +241,7 @@ class MLA {
331
  /*
332
  * This must/will be repeated in class-mla-tests.php to reflect translations
333
  */
334
- MLAOptions::mla_localize_option_definitions_array();
335
 
336
  /*
337
  * Do not process debug options unless MLA_DEBUG_LEVEL is set in wp-config.php
@@ -340,15 +250,14 @@ class MLA {
340
  /*
341
  * Set up alternate MLA debug log file
342
  */
343
- self::$original_php_log = ini_get( 'error_log' );
344
- $error_log_name = MLAOptions::mla_get_option( MLAOptions::MLA_DEBUG_FILE );
345
  if ( ! empty( $error_log_name ) ) {
346
- self::mla_debug_file( $error_log_name );
347
 
348
  /*
349
  * Override PHP error_log file
350
  */
351
- if ( 'checked' === MLAOptions::mla_get_option( MLAOptions::MLA_DEBUG_REPLACE_PHP_LOG ) ) {
352
  $result = ini_set('error_log', WP_CONTENT_DIR . self::$mla_debug_file );
353
  }
354
  }
@@ -357,10 +266,10 @@ class MLA {
357
  * PHP error_reporting must be done later in class-mla-tests.php
358
  * Override MLA debug levels
359
  */
360
- self::$mla_debug_level = MLA_DEBUG_LEVEL;
361
- $mla_reporting = trim( MLAOptions::mla_get_option( MLAOptions::MLA_DEBUG_REPLACE_LEVEL ) );
362
  if ( ! empty( $mla_reporting ) ) {
363
- self::$mla_debug_level = ( 0 + $mla_reporting ) | 1;
364
  }
365
  } // MLA_DEBUG_LEVEL & 1
366
  }
@@ -378,7 +287,7 @@ class MLA {
378
  * Process secure file download requests
379
  */
380
  if ( isset( $_REQUEST['mla_download_file'] ) && isset( $_REQUEST['mla_download_type'] ) ) {
381
- check_admin_referer( self::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
382
  self::_process_mla_download_file();
383
  exit();
384
  }
@@ -390,7 +299,7 @@ class MLA {
390
  if ( isset( $_REQUEST['mla-set-parent-ajax-nonce'] ) ) {
391
  check_admin_referer( 'mla_find_posts', 'mla-set-parent-ajax-nonce' );
392
  } else {
393
- check_admin_referer( self::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
394
  }
395
 
396
  if ( apply_filters( 'mla_list_table_admin_action', true, $_REQUEST['mla_admin_action'], ( isset( $_REQUEST['mla_item_ID'] ) ? $_REQUEST['mla_item_ID'] : 0 ) ) ) {
@@ -424,11 +333,9 @@ class MLA {
424
  } // apply_filters mla_list_table_admin_action
425
  } // (!empty($_REQUEST['mla_admin_action'])
426
 
427
- if ( defined('WP_ADMIN') && WP_ADMIN ) {
428
  if ( defined('DOING_AJAX') && DOING_AJAX ) {
429
- add_action( 'wp_ajax_' . self::JAVASCRIPT_INLINE_EDIT_SLUG, 'MLA::mla_inline_edit_ajax_action' );
430
- add_action( 'wp_ajax_' . self::JAVASCRIPT_INLINE_EDIT_SLUG . '-set-parent', 'MLA::mla_set_parent_ajax_action' );
431
- add_action( 'wp_ajax_' . 'mla_find_posts', 'MLA::mla_find_posts_ajax_action' );
432
  }
433
  }
434
  }
@@ -444,7 +351,7 @@ class MLA {
444
  /*
445
  * Optional - limit width of the views list
446
  */
447
- $width_value = MLAOptions::mla_get_option( MLAOptions::MLA_TABLE_VIEWS_WIDTH );
448
  if ( !empty( $width_value ) ) {
449
  if ( is_numeric( $width_value ) ) {
450
  $width_value .= 'px';
@@ -461,8 +368,8 @@ class MLA {
461
  /*
462
  * Optional - change the size of the thumbnail/icon images
463
  */
464
- $icon_value = MLAOptions::mla_get_option( MLAOptions::MLA_TABLE_ICON_SIZE );
465
- if ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_ENABLE_MLA_ICONS ) ) {
466
  if ( empty( $icon_value ) ) {
467
  $icon_value = 64;
468
  } else {
@@ -551,7 +458,7 @@ class MLA {
551
 
552
  $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
553
 
554
- if ( 'checked' != MLAOptions::mla_get_option( MLAOptions::MLA_SCREEN_DISPLAY_LIBRARY ) ) {
555
  wp_register_style( self::STYLESHEET_SLUG . '-nolibrary', MLA_PLUGIN_URL . 'css/mla-nolibrary.css', false, self::CURRENT_MLA_VERSION );
556
  wp_enqueue_style( self::STYLESHEET_SLUG . '-nolibrary' );
557
  }
@@ -562,7 +469,7 @@ class MLA {
562
  return;
563
  }
564
 
565
- if ( 'media_page_' . self::ADMIN_PAGE_SLUG != $page_hook ) {
566
  return;
567
  }
568
 
@@ -582,17 +489,17 @@ class MLA {
582
  wp_register_style( self::STYLESHEET_SLUG . '-set-parent', MLA_PLUGIN_URL . 'css/mla-style-set-parent.css', false, self::CURRENT_MLA_VERSION );
583
  wp_enqueue_style( self::STYLESHEET_SLUG . '-set-parent' );
584
 
585
- wp_enqueue_script( self::JAVASCRIPT_INLINE_EDIT_SLUG, MLA_PLUGIN_URL . "js/mla-inline-edit-scripts{$suffix}.js",
586
  array( 'wp-lists', 'suggest', 'jquery' ), self::CURRENT_MLA_VERSION, false );
587
 
588
- wp_enqueue_script( self::JAVASCRIPT_INLINE_EDIT_SLUG . '-set-parent', MLA_PLUGIN_URL . "js/mla-set-parent-scripts{$suffix}.js",
589
- array( 'wp-lists', 'suggest', 'jquery', self::JAVASCRIPT_INLINE_EDIT_SLUG ), self::CURRENT_MLA_VERSION, false );
590
 
591
  MLAModal::mla_add_terms_search_scripts();
592
 
593
  $fields = array( 'post_title', 'post_name', 'post_excerpt', 'post_content', 'image_alt', 'post_parent', 'post_parent_title', 'menu_order', 'post_author' );
594
- $custom_fields = MLAOptions::mla_custom_field_support( 'quick_edit' );
595
- $custom_fields = array_merge( $custom_fields, MLAOptions::mla_custom_field_support( 'bulk_edit' ) );
596
  foreach ( $custom_fields as $slug => $details ) {
597
  $fields[] = $slug;
598
  }
@@ -613,18 +520,18 @@ class MLA {
613
  'bulkSuccess' => __( 'Succeeded', 'media-library-assistant' ),
614
  'bulkFailure' => __( 'Failed', 'media-library-assistant' ),
615
  'bulkCanceled' => __( 'CANCELED', 'media-library-assistant' ),
616
- 'bulkChunkSize' => MLAOptions::mla_get_option( MLAOptions::MLA_BULK_CHUNK_SIZE ),
617
  'comma' => _x( ',', 'tag_delimiter', 'media-library-assistant' ),
618
  'useSpinnerClass' => false,
619
- 'ajax_action' => self::JAVASCRIPT_INLINE_EDIT_SLUG,
620
- 'ajax_nonce' => wp_create_nonce( self::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME )
621
  );
622
 
623
  if ( version_compare( get_bloginfo( 'version' ), '4.2', '>=' ) ) {
624
  $script_variables['useSpinnerClass'] = true;
625
  }
626
 
627
- wp_localize_script( self::JAVASCRIPT_INLINE_EDIT_SLUG, self::JAVASCRIPT_INLINE_EDIT_OBJECT, $script_variables );
628
  }
629
 
630
  /**
@@ -641,21 +548,21 @@ class MLA {
641
  public static function mla_admin_menu_action( ) {
642
  global $submenu;
643
 
644
- if ( 'checked' != MLAOptions::mla_get_option( MLAOptions::MLA_SCREEN_DISPLAY_LIBRARY ) ) {
645
  add_action( 'load-upload.php', 'MLA::mla_load_media_action' );
646
  }
647
 
648
- $page_title = MLAOptions::mla_get_option( MLAOptions::MLA_SCREEN_PAGE_TITLE );
649
  if ( empty( $page_title ) ) {
650
- $page_title = MLAOptions::mla_get_option( MLAOptions::MLA_SCREEN_PAGE_TITLE, true );
651
  }
652
 
653
- $menu_title = MLAOptions::mla_get_option( MLAOptions::MLA_SCREEN_MENU_TITLE );
654
  if ( empty( $menu_title ) ) {
655
- $menu_title = MLAOptions::mla_get_option( MLAOptions::MLA_SCREEN_MENU_TITLE, true );
656
  }
657
 
658
- $hook = add_submenu_page( 'upload.php', $page_title, $menu_title, 'upload_files', self::ADMIN_PAGE_SLUG, 'MLA::mla_render_admin_page' );
659
  add_action( 'load-' . $hook, 'MLA::mla_add_menu_options' );
660
  add_action( 'load-' . $hook, 'MLA::mla_add_help_tab' );
661
  self::$page_hooks[ $hook ] = $hook;
@@ -679,16 +586,16 @@ class MLA {
679
  /*
680
  * If we are suppressing the Media/Library submenu, force Media/Assistant to come first
681
  */
682
- if ( 'checked' != MLAOptions::mla_get_option( MLAOptions::MLA_SCREEN_DISPLAY_LIBRARY ) ) {
683
  $menu_position = 4;
684
  } else {
685
- $menu_position = (integer) MLAOptions::mla_get_option( MLAOptions::MLA_SCREEN_ORDER );
686
  }
687
 
688
  if ( $menu_position && is_array( $submenu['upload.php'] ) ) {
689
  foreach ( $submenu['upload.php'] as $menu_order => $menu_item ) {
690
- if ( self::ADMIN_PAGE_SLUG == $menu_item[2] ) {
691
- $menu_item[2] = 'upload.php?page=' . self::ADMIN_PAGE_SLUG;
692
  $submenu['upload.php'][$menu_position] = $menu_item;
693
  unset( $submenu['upload.php'][$menu_order] );
694
  ksort( $submenu['upload.php'] );
@@ -708,8 +615,8 @@ class MLA {
708
  * @return void
709
  */
710
  public static function mla_load_media_action( ) {
711
- if ( 'checked' != MLAOptions::mla_get_option( MLAOptions::MLA_SCREEN_DISPLAY_LIBRARY ) ) {
712
- $query_args = '?page=' . self::ADMIN_PAGE_SLUG;
713
 
714
  /*
715
  * Compose a message if returning from the Edit Media screen
@@ -897,23 +804,23 @@ class MLA {
897
  /*
898
  * Make sure the "Assistant" submenu line is bolded if it's the default
899
  */
900
- if ( 'media_page_' . self::ADMIN_PAGE_SLUG == $hook_suffix ) {
901
- $submenu_file = 'upload.php?page=' . self::ADMIN_PAGE_SLUG;
902
  }
903
 
904
  /*
905
  * Make sure the "Assistant" submenu line is bolded if the Media/Library submenu is hidden
906
  */
907
- if ( 'checked' != MLAOptions::mla_get_option( MLAOptions::MLA_SCREEN_DISPLAY_LIBRARY ) &&
908
  'upload.php' == $parent_file && 'upload.php' == $submenu_file ) {
909
- $submenu_file = 'upload.php?page=' . self::ADMIN_PAGE_SLUG;
910
  }
911
 
912
  /*
913
  * Make sure the "Assistant" submenu line is bolded when we go to the Edit Media page
914
  */
915
  if ( isset( $_REQUEST['mla_source'] ) ) {
916
- $submenu_file = 'upload.php?page=' . self::ADMIN_PAGE_SLUG;
917
  }
918
 
919
  return $parent_file;
@@ -1119,7 +1026,7 @@ class MLA {
1119
  */
1120
  $tax_inputs = array();
1121
  $tax_actions = array();
1122
- self::mla_debug_add( "mla_prepare_bulk_edits( {$post_id} ) tax_input = " . var_export( $request['tax_input'], true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
1123
 
1124
  if ( isset( $request['tax_input'] ) && is_array( $request['tax_input'] ) ) {
1125
  foreach ( $request['tax_input'] as $taxonomy => $terms ) {
@@ -1129,7 +1036,7 @@ class MLA {
1129
  $tax_action = 'replace';
1130
  }
1131
 
1132
- self::mla_debug_add( "mla_prepare_bulk_edits( {$post_id}, {$taxonomy}, {$tax_action} ) terms = " . var_export( $terms, true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
1133
 
1134
  /*
1135
  * Ignore empty updates
@@ -1183,7 +1090,7 @@ class MLA {
1183
  $current_terms[ $new_term->name ] = $new_term->name;
1184
  }
1185
  }
1186
- self::mla_debug_add( "mla_prepare_bulk_edits( {$post_id}, {$taxonomy}, {$tax_action} ) current_terms = " . var_export( $current_terms, true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
1187
 
1188
  if ( 'add' == $tax_action ) {
1189
  /*
@@ -1224,8 +1131,8 @@ class MLA {
1224
  $do_update = ! empty( $current_terms );
1225
  }
1226
 
1227
- self::mla_debug_add( "mla_prepare_bulk_edits( {$post_id}, {$taxonomy}, {$tax_action} ) do_update = " . var_export( $do_update, true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
1228
- self::mla_debug_add( "mla_prepare_bulk_edits( {$post_id}, {$taxonomy}, {$tax_action} ) new terms = " . var_export( $terms, true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
1229
 
1230
  if ( $do_update ) {
1231
  $tax_inputs[ $taxonomy ] = $terms;
@@ -1252,7 +1159,7 @@ class MLA {
1252
  */
1253
  public static function mla_process_bulk_action( $bulk_action, $request = NULL ) {
1254
  $page_content = array( 'message' => '', 'body' => '', 'unchanged' => 0, 'success' => 0, 'failure' => 0, 'item_results' => array() );
1255
- $custom_field_map = MLAOptions::mla_custom_field_support( 'bulk_edit' );
1256
 
1257
  /*
1258
  * do_cleanup will remove the bulk edit elements from the $_REQUEST super array.
@@ -1266,7 +1173,7 @@ class MLA {
1266
  }
1267
 
1268
  $request = apply_filters( 'mla_list_table_bulk_action_initial_request', $request, $bulk_action, $custom_field_map );
1269
- self::mla_debug_add( 'mla_process_bulk_action $request = ' . var_export( $request, true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
1270
 
1271
  if ( isset( $request['cb_attachment'] ) ) {
1272
  $item_content = apply_filters( 'mla_list_table_begin_bulk_action', NULL, $bulk_action );
@@ -1331,14 +1238,14 @@ class MLA {
1331
  }
1332
 
1333
  $new_data = self::mla_prepare_bulk_edits( $post_id, $request, $custom_field_map );
1334
- self::mla_debug_add( "mla_process_bulk_action( {$post_id} ) new_data = " . var_export( $new_data, true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
1335
  $tax_input = $new_data['tax_input'];
1336
  $tax_action = $new_data['tax_action'];
1337
  unset( $new_data['tax_input'] );
1338
  unset( $new_data['tax_action'] );
1339
 
1340
  $item_content = MLAData::mla_update_single_item( $post_id, $new_data, $tax_input, $tax_action );
1341
- self::mla_debug_add( "mla_process_bulk_action( {$post_id} ) item_content = " . var_export( $item_content, true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
1342
  break;
1343
  case 'restore':
1344
  $item_content = self::_restore_single_item( $post_id );
@@ -1413,7 +1320,7 @@ class MLA {
1413
  unset( $_REQUEST['tax_input'] );
1414
  unset( $_REQUEST['tax_action'] );
1415
 
1416
- foreach ( MLAOptions::mla_custom_field_support( 'bulk_edit' ) as $slug => $details ) {
1417
  unset( $_REQUEST[ $slug ] );
1418
  }
1419
 
@@ -1493,9 +1400,9 @@ class MLA {
1493
 
1494
  $bulk_action = self::_current_bulk_action();
1495
 
1496
- $page_title = MLAOptions::mla_get_option( MLAOptions::MLA_SCREEN_PAGE_TITLE );
1497
  if ( empty( $page_title ) ) {
1498
- $page_title = MLAOptions::mla_get_option( MLAOptions::MLA_SCREEN_PAGE_TITLE, true );
1499
  }
1500
 
1501
  echo "<div class=\"wrap\">\n";
@@ -1574,7 +1481,7 @@ class MLA {
1574
  * Process row-level actions that affect a single item
1575
  */
1576
  if ( !empty( $_REQUEST['mla_admin_action'] ) ) {
1577
- check_admin_referer( self::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
1578
 
1579
  $page_content = apply_filters( 'mla_list_table_single_action', NULL, $_REQUEST['mla_admin_action'], ( isset( $_REQUEST['mla_item_ID'] ) ? $_REQUEST['mla_item_ID'] : 0 ) );
1580
  if ( is_null( $page_content ) ) {
@@ -1587,13 +1494,13 @@ class MLA {
1587
 
1588
  if ( ! $prevent_default ) {
1589
  switch ( $_REQUEST['mla_admin_action'] ) {
1590
- case self::MLA_ADMIN_SINGLE_DELETE:
1591
  $page_content = self::_delete_single_item( $_REQUEST['mla_item_ID'] );
1592
  break;
1593
- case self::MLA_ADMIN_SINGLE_RESTORE:
1594
  $page_content = self::_restore_single_item( $_REQUEST['mla_item_ID'] );
1595
  break;
1596
- case self::MLA_ADMIN_SINGLE_TRASH:
1597
  $page_content = self::_trash_single_item( $_REQUEST['mla_item_ID'] );
1598
  break;
1599
  case self::MLA_ADMIN_SET_PARENT:
@@ -1700,9 +1607,9 @@ class MLA {
1700
 
1701
  $view_arguments = MLA_List_Table::mla_submenu_arguments();
1702
  if ( isset( $view_arguments['lang'] ) ) {
1703
- $form_url = 'upload.php?page=' . self::ADMIN_PAGE_SLUG . '&lang=' . $view_arguments['lang'];
1704
  } else {
1705
- $form_url = 'upload.php?page=' . self::ADMIN_PAGE_SLUG;
1706
  }
1707
 
1708
  // Forms are NOT created automatically, wrap the table in one to use features like bulk actions
@@ -1753,136 +1660,6 @@ class MLA {
1753
  } // display attachments list
1754
  }
1755
 
1756
- /**
1757
- * Ajax handler to fetch candidates for the "Set Parent" popup window
1758
- *
1759
- * Adapted from wp_ajax_find_posts in /wp-admin/includes/ajax-actions.php.
1760
- * Adds filters for post type and pagination.
1761
- *
1762
- * @since 1.90
1763
- *
1764
- * @return void passes results to wp_send_json_success() for JSON encoding and transmission
1765
- */
1766
- public static function mla_find_posts_ajax_action() {
1767
- global $wpdb;
1768
-
1769
- check_ajax_referer( 'mla_find_posts', MLA::MLA_ADMIN_NONCE_NAME );
1770
-
1771
- $post_types = get_post_types( array( 'public' => true ), 'objects' );
1772
- unset( $post_types['attachment'] );
1773
-
1774
- $s = stripslashes( $_REQUEST['mla_set_parent_search_text'] );
1775
- $count = isset( $_REQUEST['mla_set_parent_count'] ) ? $_REQUEST['mla_set_parent_count'] : 50;
1776
- $paged = isset( $_REQUEST['mla_set_parent_paged'] ) ? $_REQUEST['mla_set_parent_paged'] : 1;
1777
-
1778
- $args = array(
1779
- 'post_type' => ( 'all' == $_REQUEST['mla_set_parent_post_type'] ) ? array_keys( $post_types ) : $_REQUEST['mla_set_parent_post_type'],
1780
- 'post_status' => 'any',
1781
- 'posts_per_page' => $count,
1782
- 'paged' => $paged,
1783
- );
1784
-
1785
- if ( '' !== $s )
1786
- $args['s'] = $s;
1787
-
1788
- $posts = get_posts( $args );
1789
-
1790
- if ( ( ! $posts ) && $paged > 1 ) {
1791
- $args['paged'] = $paged = 1;
1792
- $posts = get_posts( $args );
1793
- }
1794
-
1795
- $found = count( $posts );
1796
-
1797
- $html = '<input name="mla_set_parent_count" id="mla-set-parent-count" type="hidden" value="' . $count . "\">\n";
1798
- $html .= '<input name="mla_set_parent_paged" id="mla-set-parent-paged" type="hidden" value="' . $paged . "\">\n";
1799
- $html .= '<input name="mla_set_parent_found" id="mla-set-parent-found" type="hidden" value="' . $found . "\">\n";
1800
-
1801
- $html .= '<table class="widefat"><thead><tr><th class="found-radio"><br /></th><th>'.__('Title').'</th><th class="no-break">'.__('Type').'</th><th class="no-break">'.__('Date').'</th><th class="no-break">'.__('Status').'</th></tr></thead><tbody>' . "\n";
1802
- if ( $found ) {
1803
- $alt = '';
1804
- foreach ( $posts as $post ) {
1805
- $title = trim( $post->post_title ) ? $post->post_title : __( '(no title)' );
1806
- $alt = ( 'alternate' == $alt ) ? '' : 'alternate';
1807
-
1808
- switch ( $post->post_status ) {
1809
- case 'publish' :
1810
- case 'private' :
1811
- $stat = __('Published');
1812
- break;
1813
- case 'future' :
1814
- $stat = __('Scheduled');
1815
- break;
1816
- case 'pending' :
1817
- $stat = __('Pending Review');
1818
- break;
1819
- case 'draft' :
1820
- $stat = __('Draft');
1821
- break;
1822
- default:
1823
- $stat = sanitize_text_field( $post->post_status );
1824
- }
1825
-
1826
- if ( '0000-00-00 00:00:00' == $post->post_date ) {
1827
- $time = '';
1828
- } else {
1829
- /* translators: date format in table columns, see http://php.net/date */
1830
- $time = mysql2date(__('Y/m/d'), $post->post_date);
1831
- }
1832
-
1833
- $html .= '<tr class="' . trim( 'found-posts ' . $alt ) . '"><td class="found-radio"><input type="radio" id="found-'.$post->ID.'" name="found_post_id" value="' . esc_attr($post->ID) . '"></td>';
1834
- $html .= '<td><label for="found-'.$post->ID.'">' . esc_html( $title ) . '</label></td><td class="no-break">' . esc_html( $post_types[$post->post_type]->labels->singular_name ) . '</td><td class="no-break">'.esc_html( $time ) . '</td><td class="no-break">' . esc_html( $stat ). ' </td></tr>' . "\n";
1835
- } // foreach post
1836
- } else {
1837
- $html .= '<tr class="' . trim( 'found-posts ' ) . '"><td class="found-radio">&nbsp;</td>';
1838
- $html .= '<td colspan="4">No results found.</td></tr>' . "\n";
1839
- }
1840
-
1841
- $html .= "</tbody></table>\n";
1842
-
1843
- wp_send_json_success( $html );
1844
- }
1845
-
1846
- /**
1847
- * Ajax handler to set post_parent for a single attachment
1848
- *
1849
- * Adapted from wp_ajax_inline_save in /wp-admin/includes/ajax-actions.php
1850
- *
1851
- * @since 0.20
1852
- *
1853
- * @return void echo HTML <td> innerHTML for updated call or error message, then die()
1854
- */
1855
- public static function mla_set_parent_ajax_action() {
1856
- check_ajax_referer( self::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
1857
-
1858
- if ( empty( $_REQUEST['post_ID'] ) ) {
1859
- echo __( 'ERROR', 'media-library-assistant' ) . ': ' . __( 'No post ID found', 'media-library-assistant' );
1860
- die();
1861
- } else {
1862
- $post_id = $_REQUEST['post_ID'];
1863
- }
1864
-
1865
- if ( ! current_user_can( 'edit_post', $post_id ) ) {
1866
- wp_die( __( 'ERROR', 'media-library-assistant' ) . ': ' . __( 'You are not allowed to edit this Attachment.', 'media-library-assistant' ) );
1867
- }
1868
-
1869
- $results = MLAData::mla_update_single_item( $post_id, $_REQUEST );
1870
- if ( false !== strpos( $results['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
1871
- wp_die( $results['message'] );
1872
- }
1873
-
1874
- $new_item = (object) MLAData::mla_get_attachment_by_id( $post_id );
1875
-
1876
- // Create an instance of our package class and echo the new HTML
1877
- $MLAListTable = apply_filters( 'mla_list_table_new_instance', NULL );
1878
- if ( is_null( $MLAListTable ) ) {
1879
- $MLAListTable = new MLA_List_Table();
1880
- }
1881
-
1882
- $MLAListTable->single_row( $new_item );
1883
- die(); // this is required to return a proper result
1884
- }
1885
-
1886
  /**
1887
  * Ajax handler for bulk editing and mapping
1888
  *
@@ -1891,7 +1668,7 @@ class MLA {
1891
  * @return void echo json results or error message, then die()
1892
  */
1893
  private static function _bulk_edit_ajax_handler() {
1894
- self::mla_debug_add( '_bulk_edit_ajax_handler $_REQUEST = ' . var_export( $_REQUEST, true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
1895
 
1896
  /*
1897
  * The category taxonomy (edit screens) is a special case because
@@ -1936,7 +1713,7 @@ class MLA {
1936
  public static function mla_inline_edit_ajax_action() {
1937
  set_current_screen( $_REQUEST['screen'] );
1938
 
1939
- check_ajax_referer( self::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
1940
 
1941
  if ( ! empty( $_REQUEST['bulk_action'] ) ) {
1942
  self::_bulk_edit_ajax_handler(); // calls wp_send_json_success and die()
@@ -1957,7 +1734,7 @@ class MLA {
1957
  * Custom field support
1958
  */
1959
  $custom_fields = array();
1960
- foreach ( MLAOptions::mla_custom_field_support( 'quick_edit' ) as $slug => $details ) {
1961
  if ( isset( $_REQUEST[ $slug ] ) ) {
1962
  $value = trim( $_REQUEST[ $slug ] );
1963
  unset ( $_REQUEST[ $slug ] );
@@ -2050,7 +1827,6 @@ class MLA {
2050
  * Compose a Post Type Options list with current selection
2051
  *
2052
  * @since 1.90
2053
- * @uses $mla_option_templates contains row and table templates
2054
  *
2055
  * @param array template parts
2056
  * @param string current selection or 'all' (default)
@@ -2137,9 +1913,9 @@ class MLA {
2137
  }
2138
 
2139
  $page_values = array(
2140
- 'mla_set_parent_url' => esc_url( add_query_arg( array_merge( MLA_List_Table::mla_submenu_arguments( false ), array( 'page' => MLA::ADMIN_PAGE_SLUG ) ), admin_url( 'upload.php' ) ) ),
2141
  'mla_set_parent_action' => self::MLA_ADMIN_SET_PARENT,
2142
- 'wpnonce' => wp_nonce_field( self::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME, true, false ),
2143
  'mla_set_parent_div' => $set_parent_div,
2144
  );
2145
 
@@ -2165,9 +1941,9 @@ class MLA {
2165
  $hierarchical_taxonomies = array();
2166
  $flat_taxonomies = array();
2167
  foreach ( $taxonomies as $tax_name => $tax_object ) {
2168
- if ( $tax_object->hierarchical && $tax_object->show_ui && MLAOptions::mla_taxonomy_support($tax_name, 'quick-edit') ) {
2169
  $hierarchical_taxonomies[$tax_name] = $tax_object;
2170
- } elseif ( $tax_object->show_ui && MLAOptions::mla_taxonomy_support($tax_name, 'quick-edit') ) {
2171
  $flat_taxonomies[$tax_name] = $tax_object;
2172
  }
2173
  }
@@ -2189,7 +1965,7 @@ class MLA {
2189
  }
2190
 
2191
  $custom_fields = '';
2192
- foreach ( MLAOptions::mla_custom_field_support( 'quick_edit' ) as $slug => $details ) {
2193
  $page_values = array(
2194
  'slug' => $slug,
2195
  'label' => esc_attr( $details['name'] ),
@@ -2291,7 +2067,7 @@ class MLA {
2291
  }
2292
 
2293
  $bulk_custom_fields = '';
2294
- foreach ( MLAOptions::mla_custom_field_support( 'bulk_edit' ) as $slug => $details ) {
2295
  $page_values = array(
2296
  'slug' => $slug,
2297
  'label' => esc_attr( $details['name'] ),
@@ -2514,222 +2290,5 @@ class MLA {
2514
  'body' => ''
2515
  );
2516
  }
2517
-
2518
- /**
2519
- * Accumulates debug messages
2520
- *
2521
- * @since 2.12
2522
- *
2523
- * @var string
2524
- */
2525
- private static $mla_debug_messages = array();
2526
-
2527
- /**
2528
- * Debug information collection mode
2529
- *
2530
- * Collection mode: 'buffer', 'console', 'log' or 'none' (default).
2531
- *
2532
- * @since 2.12
2533
- *
2534
- * @var string
2535
- */
2536
- private static $mla_debug_mode = 'none';
2537
-
2538
- /**
2539
- * Get/Set debug information collection mode
2540
- *
2541
- * @since 2.12
2542
- *
2543
- * @param string $mode Optional. New collection mode: 'none' (default), 'buffer', 'console' or 'log'
2544
- *
2545
- * @return string The previous mode value, i.e., before the update
2546
- */
2547
- public static function mla_debug_mode( $mode = false ) {
2548
- $old_mode = self::$mla_debug_mode;
2549
-
2550
- if ( $mode && in_array( $mode, array( 'none', 'buffer', 'console', 'log' ) ) ) {
2551
- self::$mla_debug_mode = $mode;
2552
- }
2553
-
2554
- return $old_mode;
2555
- }
2556
-
2557
- /**
2558
- * Debug information output file for mode = 'log'
2559
- *
2560
- * @since 2.14
2561
- *
2562
- * @var string
2563
- */
2564
- private static $mla_debug_file = NULL;
2565
-
2566
- /**
2567
- * Get/Set debug information collection output file for mode = 'log'
2568
- *
2569
- * Note that WP_CONTENT_DIR will be pre-pended to the value, and a slash
2570
- * will be added to the front of the value if necessary.
2571
- *
2572
- * @since 2.14
2573
- *
2574
- * @param string $file Optional. The (optional path and) file name, relative to WP_CONTENT_DIR,
2575
- * or false/empty string to clear the value.
2576
- *
2577
- * @return string The previous file value, i.e., before the update, relative to WP_CONTENT_DIR
2578
- */
2579
- public static function mla_debug_file( $file = NULL ) {
2580
- if ( NULL === $file ) {
2581
- return self::$mla_debug_file;
2582
- }
2583
-
2584
- $old_file = self::$mla_debug_file;
2585
-
2586
- if ( empty( $file ) ) {
2587
- self::$mla_debug_file = NULL;
2588
- } else {
2589
- $first = substr( $file, 0, 1 );
2590
- if ( ( '/' != $first ) && ( '\\' != $first ) ) {
2591
- $file = '/' . $file;
2592
- }
2593
-
2594
- self::$mla_debug_file = $file;
2595
- }
2596
-
2597
- return $old_file;
2598
- }
2599
-
2600
- /**
2601
- * Get debug information without clearing the buffer
2602
- *
2603
- * @since 2.12
2604
- *
2605
- * @param string $format Return data type: 'string' (default) or 'array'
2606
- * @param string $glue Join array elements with '\n' or '<p>' (default)
2607
- *
2608
- * @return boolean true if success else false
2609
- */
2610
- public static function mla_debug_content( $format = 'string', $glue = '<p>' ) {
2611
- if ( 'array' == $format ) {
2612
- return self::$mla_debug_messages;
2613
- }
2614
-
2615
- // format == 'string'
2616
- if ( '<p>' == $glue ) {
2617
- return '<p>' . implode( '</p><p>', self::$mla_debug_messages ) . '</p>';
2618
- }
2619
-
2620
- return implode( "\n", self::$mla_debug_messages ) . "\n";
2621
- }
2622
-
2623
- /**
2624
- * Flush debug information and clear buffer
2625
- *
2626
- * @since 2.12
2627
- *
2628
- * @param string $destination Destination: 'buffer' (default), 'console', 'log' or 'none'
2629
- * @param boolean $stop_collecting true (default) to stop, false to continue collection
2630
- *
2631
- * @return string debug content if $destination == 'buffer' else empty string
2632
- */
2633
- public static function mla_debug_flush( $destination = 'buffer', $stop_collecting = true ) {
2634
- $results = '';
2635
-
2636
- switch ( $destination ) {
2637
- case 'buffer':
2638
- $results = self::mla_debug_content();
2639
- break;
2640
- case 'console':
2641
- foreach( self::$mla_debug_messages as $message ) {
2642
- trigger_error( $message, E_USER_WARNING );
2643
- }
2644
- break;
2645
- case 'log':
2646
- foreach( self::$mla_debug_messages as $message ) {
2647
- self::_debug_log( $message );
2648
- }
2649
- break;
2650
- }
2651
-
2652
- self::$mla_debug_messages = array();
2653
-
2654
- if ( $stop_collecting ) {
2655
- self::$mla_debug_mode = 'none';
2656
- }
2657
-
2658
- return $results;
2659
- }
2660
-
2661
- /**
2662
- * Write a debug message to the appropriate log file
2663
- *
2664
- * @since 2.14
2665
- *
2666
- * @param string $message Message text
2667
- */
2668
- private static function _debug_log( $message ) {
2669
- if ( ! empty( self::$mla_debug_file ) ) {
2670
- // 'at' = append mode, text format
2671
- $file_handle = @fopen( WP_CONTENT_DIR . self::$mla_debug_file, 'at' );
2672
- if ( $file_handle ) {
2673
- @fwrite( $file_handle, sprintf( '[%1$s] %2$s%3$s', gmdate( 'd-M-Y H:i:s' ), $message, "\n" ) );
2674
- @fclose( $file_handle );
2675
-
2676
- return;
2677
- }
2678
- }
2679
-
2680
- error_log( $message, 0 );
2681
- }
2682
-
2683
- /**
2684
- * Constant to log Ajax debug activity
2685
- *
2686
- * @since 2.13
2687
- *
2688
- * @var integer
2689
- */
2690
- CONST MLA_DEBUG_CATEGORY_AJAX = 0x00000002;
2691
-
2692
- /**
2693
- * Constant to log WPML/Polylang action/filter activity
2694
- *
2695
- * @since 2.15
2696
- *
2697
- * @var integer
2698
- */
2699
- CONST MLA_DEBUG_CATEGORY_LANGUAGE = 0x00000004;
2700
-
2701
- /**
2702
- * Add a debug message to the collection
2703
- *
2704
- * @since 2.12
2705
- *
2706
- * @param string $message Message text
2707
- * @param integer $debug_level Optional. Debug category.
2708
- */
2709
- public static function mla_debug_add( $message, $debug_level = NULL ) {
2710
- $mode = self::$mla_debug_mode;
2711
-
2712
- if ( NULL != $debug_level ) {
2713
- if ( ( 0 == ( self::$mla_debug_level & 1 ) ) || ( 0 == ( self::$mla_debug_level & $debug_level ) ) ) {
2714
- return;
2715
- }
2716
-
2717
- if ( 'none' == self::$mla_debug_mode ) {
2718
- $mode = 'log';
2719
- }
2720
- }
2721
-
2722
- switch ( $mode ) {
2723
- case 'buffer':
2724
- self::$mla_debug_messages[] = $message;
2725
- break;
2726
- case 'console':
2727
- trigger_error( $message, E_USER_WARNING );
2728
- break;
2729
- case 'log':
2730
- self::_debug_log( $message );
2731
- break;
2732
- }
2733
- }
2734
  } // class MLA
2735
  ?>
29
  *
30
  * @var string
31
  */
32
+ const CURRENT_MLA_VERSION = '2.21';
33
 
34
  /**
35
  * Current date for Development Version, empty for production versions
49
  */
50
  const STYLESHEET_SLUG = 'mla-style';
51
 
 
 
 
 
 
 
 
 
 
52
  /**
53
  * Object name for localizing JavaScript - MLA List Table
54
  *
58
  */
59
  const JAVASCRIPT_INLINE_EDIT_OBJECT = 'mla_inline_edit_vars';
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  /**
62
  * mla_admin_action value to display a single item for editing
63
  *
80
  */
81
  const MLA_ADMIN_SINGLE_EDIT_UPDATE = 'single_item_edit_update';
82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  /**
84
  * mla_admin_action value for mapping Custom Field metadata
85
  *
159
  public static function initialize( ) {
160
  global $sitepress, $polylang;
161
 
162
+ if ( 'checked' == MLACore::mla_get_option( 'enable_featured_image_generation' ) ) {
163
  if ( class_exists( 'MLA_Thumbnail' ) ) {
164
  self::$mla_language_support_error_messages .= "<li>class MLA_Thumbnail</li>";
165
  } else {
215
  add_filter( 'screen_options_show_screen', 'MLA::mla_screen_options_show_screen_filter', 10, 2 ); // $show_screen, $this
216
  }
217
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
  /**
219
  * Load a plugin text domain and alternate debug file
220
  *
241
  /*
242
  * This must/will be repeated in class-mla-tests.php to reflect translations
243
  */
244
+ MLACore::mla_localize_option_definitions_array();
245
 
246
  /*
247
  * Do not process debug options unless MLA_DEBUG_LEVEL is set in wp-config.php
250
  /*
251
  * Set up alternate MLA debug log file
252
  */
253
+ $error_log_name = MLACore::mla_get_option( MLACore::MLA_DEBUG_FILE );
 
254
  if ( ! empty( $error_log_name ) ) {
255
+ MLACore::mla_debug_file( $error_log_name );
256
 
257
  /*
258
  * Override PHP error_log file
259
  */
260
+ if ( 'checked' === MLACore::mla_get_option( MLACore::MLA_DEBUG_REPLACE_PHP_LOG ) ) {
261
  $result = ini_set('error_log', WP_CONTENT_DIR . self::$mla_debug_file );
262
  }
263
  }
266
  * PHP error_reporting must be done later in class-mla-tests.php
267
  * Override MLA debug levels
268
  */
269
+ MLACore::$mla_debug_level = MLA_DEBUG_LEVEL;
270
+ $mla_reporting = trim( MLACore::mla_get_option( MLACore::MLA_DEBUG_REPLACE_LEVEL ) );
271
  if ( ! empty( $mla_reporting ) ) {
272
+ MLACore::$mla_debug_level = ( 0 + $mla_reporting ) | 1;
273
  }
274
  } // MLA_DEBUG_LEVEL & 1
275
  }
287
  * Process secure file download requests
288
  */
289
  if ( isset( $_REQUEST['mla_download_file'] ) && isset( $_REQUEST['mla_download_type'] ) ) {
290
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
291
  self::_process_mla_download_file();
292
  exit();
293
  }
299
  if ( isset( $_REQUEST['mla-set-parent-ajax-nonce'] ) ) {
300
  check_admin_referer( 'mla_find_posts', 'mla-set-parent-ajax-nonce' );
301
  } else {
302
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
303
  }
304
 
305
  if ( apply_filters( 'mla_list_table_admin_action', true, $_REQUEST['mla_admin_action'], ( isset( $_REQUEST['mla_item_ID'] ) ? $_REQUEST['mla_item_ID'] : 0 ) ) ) {
333
  } // apply_filters mla_list_table_admin_action
334
  } // (!empty($_REQUEST['mla_admin_action'])
335
 
336
+ if ( is_admin() ) {
337
  if ( defined('DOING_AJAX') && DOING_AJAX ) {
338
+ add_action( 'wp_ajax_' . MLACore::JAVASCRIPT_INLINE_EDIT_SLUG, 'MLA::mla_inline_edit_ajax_action' );
 
 
339
  }
340
  }
341
  }
351
  /*
352
  * Optional - limit width of the views list
353
  */
354
+ $width_value = MLACore::mla_get_option( MLACore::MLA_TABLE_VIEWS_WIDTH );
355
  if ( !empty( $width_value ) ) {
356
  if ( is_numeric( $width_value ) ) {
357
  $width_value .= 'px';
368
  /*
369
  * Optional - change the size of the thumbnail/icon images
370
  */
371
+ $icon_value = MLACore::mla_get_option( MLACore::MLA_TABLE_ICON_SIZE );
372
+ if ( 'checked' == MLACore::mla_get_option( MLACore::MLA_ENABLE_MLA_ICONS ) ) {
373
  if ( empty( $icon_value ) ) {
374
  $icon_value = 64;
375
  } else {
458
 
459
  $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
460
 
461
+ if ( 'checked' != MLACore::mla_get_option( MLACore::MLA_SCREEN_DISPLAY_LIBRARY ) ) {
462
  wp_register_style( self::STYLESHEET_SLUG . '-nolibrary', MLA_PLUGIN_URL . 'css/mla-nolibrary.css', false, self::CURRENT_MLA_VERSION );
463
  wp_enqueue_style( self::STYLESHEET_SLUG . '-nolibrary' );
464
  }
469
  return;
470
  }
471
 
472
+ if ( 'media_page_' . MLACore::ADMIN_PAGE_SLUG != $page_hook ) {
473
  return;
474
  }
475
 
489
  wp_register_style( self::STYLESHEET_SLUG . '-set-parent', MLA_PLUGIN_URL . 'css/mla-style-set-parent.css', false, self::CURRENT_MLA_VERSION );
490
  wp_enqueue_style( self::STYLESHEET_SLUG . '-set-parent' );
491
 
492
+ wp_enqueue_script( MLACore::JAVASCRIPT_INLINE_EDIT_SLUG, MLA_PLUGIN_URL . "js/mla-inline-edit-scripts{$suffix}.js",
493
  array( 'wp-lists', 'suggest', 'jquery' ), self::CURRENT_MLA_VERSION, false );
494
 
495
+ wp_enqueue_script( MLACore::JAVASCRIPT_INLINE_EDIT_SLUG . '-set-parent', MLA_PLUGIN_URL . "js/mla-set-parent-scripts{$suffix}.js",
496
+ array( 'wp-lists', 'suggest', 'jquery', MLACore::JAVASCRIPT_INLINE_EDIT_SLUG ), self::CURRENT_MLA_VERSION, false );
497
 
498
  MLAModal::mla_add_terms_search_scripts();
499
 
500
  $fields = array( 'post_title', 'post_name', 'post_excerpt', 'post_content', 'image_alt', 'post_parent', 'post_parent_title', 'menu_order', 'post_author' );
501
+ $custom_fields = MLACore::mla_custom_field_support( 'quick_edit' );
502
+ $custom_fields = array_merge( $custom_fields, MLACore::mla_custom_field_support( 'bulk_edit' ) );
503
  foreach ( $custom_fields as $slug => $details ) {
504
  $fields[] = $slug;
505
  }
520
  'bulkSuccess' => __( 'Succeeded', 'media-library-assistant' ),
521
  'bulkFailure' => __( 'Failed', 'media-library-assistant' ),
522
  'bulkCanceled' => __( 'CANCELED', 'media-library-assistant' ),
523
+ 'bulkChunkSize' => MLACore::mla_get_option( MLACore::MLA_BULK_CHUNK_SIZE ),
524
  'comma' => _x( ',', 'tag_delimiter', 'media-library-assistant' ),
525
  'useSpinnerClass' => false,
526
+ 'ajax_action' => MLACore::JAVASCRIPT_INLINE_EDIT_SLUG,
527
+ 'ajax_nonce' => wp_create_nonce( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME )
528
  );
529
 
530
  if ( version_compare( get_bloginfo( 'version' ), '4.2', '>=' ) ) {
531
  $script_variables['useSpinnerClass'] = true;
532
  }
533
 
534
+ wp_localize_script( MLACore::JAVASCRIPT_INLINE_EDIT_SLUG, self::JAVASCRIPT_INLINE_EDIT_OBJECT, $script_variables );
535
  }
536
 
537
  /**
548
  public static function mla_admin_menu_action( ) {
549
  global $submenu;
550
 
551
+ if ( 'checked' != MLACore::mla_get_option( MLACore::MLA_SCREEN_DISPLAY_LIBRARY ) ) {
552
  add_action( 'load-upload.php', 'MLA::mla_load_media_action' );
553
  }
554
 
555
+ $page_title = MLACore::mla_get_option( MLACore::MLA_SCREEN_PAGE_TITLE );
556
  if ( empty( $page_title ) ) {
557
+ $page_title = MLACore::mla_get_option( MLACore::MLA_SCREEN_PAGE_TITLE, true );
558
  }
559
 
560
+ $menu_title = MLACore::mla_get_option( MLACore::MLA_SCREEN_MENU_TITLE );
561
  if ( empty( $menu_title ) ) {
562
+ $menu_title = MLACore::mla_get_option( MLACore::MLA_SCREEN_MENU_TITLE, true );
563
  }
564
 
565
+ $hook = add_submenu_page( 'upload.php', $page_title, $menu_title, 'upload_files', MLACore::ADMIN_PAGE_SLUG, 'MLA::mla_render_admin_page' );
566
  add_action( 'load-' . $hook, 'MLA::mla_add_menu_options' );
567
  add_action( 'load-' . $hook, 'MLA::mla_add_help_tab' );
568
  self::$page_hooks[ $hook ] = $hook;
586
  /*
587
  * If we are suppressing the Media/Library submenu, force Media/Assistant to come first
588
  */
589
+ if ( 'checked' != MLACore::mla_get_option( MLACore::MLA_SCREEN_DISPLAY_LIBRARY ) ) {
590
  $menu_position = 4;
591
  } else {
592
+ $menu_position = (integer) MLACore::mla_get_option( MLACore::MLA_SCREEN_ORDER );
593
  }
594
 
595
  if ( $menu_position && is_array( $submenu['upload.php'] ) ) {
596
  foreach ( $submenu['upload.php'] as $menu_order => $menu_item ) {
597
+ if ( MLACore::ADMIN_PAGE_SLUG == $menu_item[2] ) {
598
+ $menu_item[2] = 'upload.php?page=' . MLACore::ADMIN_PAGE_SLUG;
599
  $submenu['upload.php'][$menu_position] = $menu_item;
600
  unset( $submenu['upload.php'][$menu_order] );
601
  ksort( $submenu['upload.php'] );
615
  * @return void
616
  */
617
  public static function mla_load_media_action( ) {
618
+ if ( 'checked' != MLACore::mla_get_option( MLACore::MLA_SCREEN_DISPLAY_LIBRARY ) ) {
619
+ $query_args = '?page=' . MLACore::ADMIN_PAGE_SLUG;
620
 
621
  /*
622
  * Compose a message if returning from the Edit Media screen
804
  /*
805
  * Make sure the "Assistant" submenu line is bolded if it's the default
806
  */
807
+ if ( 'media_page_' . MLACore::ADMIN_PAGE_SLUG == $hook_suffix ) {
808
+ $submenu_file = 'upload.php?page=' . MLACore::ADMIN_PAGE_SLUG;
809
  }
810
 
811
  /*
812
  * Make sure the "Assistant" submenu line is bolded if the Media/Library submenu is hidden
813
  */
814
+ if ( 'checked' != MLACore::mla_get_option( MLACore::MLA_SCREEN_DISPLAY_LIBRARY ) &&
815
  'upload.php' == $parent_file && 'upload.php' == $submenu_file ) {
816
+ $submenu_file = 'upload.php?page=' . MLACore::ADMIN_PAGE_SLUG;
817
  }
818
 
819
  /*
820
  * Make sure the "Assistant" submenu line is bolded when we go to the Edit Media page
821
  */
822
  if ( isset( $_REQUEST['mla_source'] ) ) {
823
+ $submenu_file = 'upload.php?page=' . MLACore::ADMIN_PAGE_SLUG;
824
  }
825
 
826
  return $parent_file;
1026
  */
1027
  $tax_inputs = array();
1028
  $tax_actions = array();
1029
+ MLACore::mla_debug_add( "mla_prepare_bulk_edits( {$post_id} ) tax_input = " . var_export( $request['tax_input'], true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1030
 
1031
  if ( isset( $request['tax_input'] ) && is_array( $request['tax_input'] ) ) {
1032
  foreach ( $request['tax_input'] as $taxonomy => $terms ) {
1036
  $tax_action = 'replace';
1037
  }
1038
 
1039
+ MLACore::mla_debug_add( "mla_prepare_bulk_edits( {$post_id}, {$taxonomy}, {$tax_action} ) terms = " . var_export( $terms, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1040
 
1041
  /*
1042
  * Ignore empty updates
1090
  $current_terms[ $new_term->name ] = $new_term->name;
1091
  }
1092
  }
1093
+ 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 );
1094
 
1095
  if ( 'add' == $tax_action ) {
1096
  /*
1131
  $do_update = ! empty( $current_terms );
1132
  }
1133
 
1134
+ 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 );
1135
+ MLACore::mla_debug_add( "mla_prepare_bulk_edits( {$post_id}, {$taxonomy}, {$tax_action} ) new terms = " . var_export( $terms, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1136
 
1137
  if ( $do_update ) {
1138
  $tax_inputs[ $taxonomy ] = $terms;
1159
  */
1160
  public static function mla_process_bulk_action( $bulk_action, $request = NULL ) {
1161
  $page_content = array( 'message' => '', 'body' => '', 'unchanged' => 0, 'success' => 0, 'failure' => 0, 'item_results' => array() );
1162
+ $custom_field_map = MLACore::mla_custom_field_support( 'bulk_edit' );
1163
 
1164
  /*
1165
  * do_cleanup will remove the bulk edit elements from the $_REQUEST super array.
1173
  }
1174
 
1175
  $request = apply_filters( 'mla_list_table_bulk_action_initial_request', $request, $bulk_action, $custom_field_map );
1176
+ MLACore::mla_debug_add( 'mla_process_bulk_action $request = ' . var_export( $request, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1177
 
1178
  if ( isset( $request['cb_attachment'] ) ) {
1179
  $item_content = apply_filters( 'mla_list_table_begin_bulk_action', NULL, $bulk_action );
1238
  }
1239
 
1240
  $new_data = self::mla_prepare_bulk_edits( $post_id, $request, $custom_field_map );
1241
+ MLACore::mla_debug_add( "mla_process_bulk_action( {$post_id} ) new_data = " . var_export( $new_data, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1242
  $tax_input = $new_data['tax_input'];
1243
  $tax_action = $new_data['tax_action'];
1244
  unset( $new_data['tax_input'] );
1245
  unset( $new_data['tax_action'] );
1246
 
1247
  $item_content = MLAData::mla_update_single_item( $post_id, $new_data, $tax_input, $tax_action );
1248
+ MLACore::mla_debug_add( "mla_process_bulk_action( {$post_id} ) item_content = " . var_export( $item_content, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1249
  break;
1250
  case 'restore':
1251
  $item_content = self::_restore_single_item( $post_id );
1320
  unset( $_REQUEST['tax_input'] );
1321
  unset( $_REQUEST['tax_action'] );
1322
 
1323
+ foreach ( MLACore::mla_custom_field_support( 'bulk_edit' ) as $slug => $details ) {
1324
  unset( $_REQUEST[ $slug ] );
1325
  }
1326
 
1400
 
1401
  $bulk_action = self::_current_bulk_action();
1402
 
1403
+ $page_title = MLACore::mla_get_option( MLACore::MLA_SCREEN_PAGE_TITLE );
1404
  if ( empty( $page_title ) ) {
1405
+ $page_title = MLACore::mla_get_option( MLACore::MLA_SCREEN_PAGE_TITLE, true );
1406
  }
1407
 
1408
  echo "<div class=\"wrap\">\n";
1481
  * Process row-level actions that affect a single item
1482
  */
1483
  if ( !empty( $_REQUEST['mla_admin_action'] ) ) {
1484
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
1485
 
1486
  $page_content = apply_filters( 'mla_list_table_single_action', NULL, $_REQUEST['mla_admin_action'], ( isset( $_REQUEST['mla_item_ID'] ) ? $_REQUEST['mla_item_ID'] : 0 ) );
1487
  if ( is_null( $page_content ) ) {
1494
 
1495
  if ( ! $prevent_default ) {
1496
  switch ( $_REQUEST['mla_admin_action'] ) {
1497
+ case MLACore::MLA_ADMIN_SINGLE_DELETE:
1498
  $page_content = self::_delete_single_item( $_REQUEST['mla_item_ID'] );
1499
  break;
1500
+ case MLACore::MLA_ADMIN_SINGLE_RESTORE:
1501
  $page_content = self::_restore_single_item( $_REQUEST['mla_item_ID'] );
1502
  break;
1503
+ case MLACore::MLA_ADMIN_SINGLE_TRASH:
1504
  $page_content = self::_trash_single_item( $_REQUEST['mla_item_ID'] );
1505
  break;
1506
  case self::MLA_ADMIN_SET_PARENT:
1607
 
1608
  $view_arguments = MLA_List_Table::mla_submenu_arguments();
1609
  if ( isset( $view_arguments['lang'] ) ) {
1610
+ $form_url = 'upload.php?page=' . MLACore::ADMIN_PAGE_SLUG . '&lang=' . $view_arguments['lang'];
1611
  } else {
1612
+ $form_url = 'upload.php?page=' . MLACore::ADMIN_PAGE_SLUG;
1613
  }
1614
 
1615
  // Forms are NOT created automatically, wrap the table in one to use features like bulk actions
1660
  } // display attachments list
1661
  }
1662
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1663
  /**
1664
  * Ajax handler for bulk editing and mapping
1665
  *
1668
  * @return void echo json results or error message, then die()
1669
  */
1670
  private static function _bulk_edit_ajax_handler() {
1671
+ MLACore::mla_debug_add( '_bulk_edit_ajax_handler $_REQUEST = ' . var_export( $_REQUEST, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1672
 
1673
  /*
1674
  * The category taxonomy (edit screens) is a special case because
1713
  public static function mla_inline_edit_ajax_action() {
1714
  set_current_screen( $_REQUEST['screen'] );
1715
 
1716
+ check_ajax_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
1717
 
1718
  if ( ! empty( $_REQUEST['bulk_action'] ) ) {
1719
  self::_bulk_edit_ajax_handler(); // calls wp_send_json_success and die()
1734
  * Custom field support
1735
  */
1736
  $custom_fields = array();
1737
+ foreach ( MLACore::mla_custom_field_support( 'quick_edit' ) as $slug => $details ) {
1738
  if ( isset( $_REQUEST[ $slug ] ) ) {
1739
  $value = trim( $_REQUEST[ $slug ] );
1740
  unset ( $_REQUEST[ $slug ] );
1827
  * Compose a Post Type Options list with current selection
1828
  *
1829
  * @since 1.90
 
1830
  *
1831
  * @param array template parts
1832
  * @param string current selection or 'all' (default)
1913
  }
1914
 
1915
  $page_values = array(
1916
+ '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' ) ) ),
1917
  'mla_set_parent_action' => self::MLA_ADMIN_SET_PARENT,
1918
+ 'wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
1919
  'mla_set_parent_div' => $set_parent_div,
1920
  );
1921
 
1941
  $hierarchical_taxonomies = array();
1942
  $flat_taxonomies = array();
1943
  foreach ( $taxonomies as $tax_name => $tax_object ) {
1944
+ if ( $tax_object->hierarchical && $tax_object->show_ui && MLACore::mla_taxonomy_support($tax_name, 'quick-edit') ) {
1945
  $hierarchical_taxonomies[$tax_name] = $tax_object;
1946
+ } elseif ( $tax_object->show_ui && MLACore::mla_taxonomy_support($tax_name, 'quick-edit') ) {
1947
  $flat_taxonomies[$tax_name] = $tax_object;
1948
  }
1949
  }
1965
  }
1966
 
1967
  $custom_fields = '';
1968
+ foreach ( MLACore::mla_custom_field_support( 'quick_edit' ) as $slug => $details ) {
1969
  $page_values = array(
1970
  'slug' => $slug,
1971
  'label' => esc_attr( $details['name'] ),
2067
  }
2068
 
2069
  $bulk_custom_fields = '';
2070
+ foreach ( MLACore::mla_custom_field_support( 'bulk_edit' ) as $slug => $details ) {
2071
  $page_values = array(
2072
  'slug' => $slug,
2073
  'label' => esc_attr( $details['name'] ),
2290
  'body' => ''
2291
  );
2292
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2293
  } // class MLA
2294
  ?>
includes/class-mla-media-modal-ajax.php ADDED
@@ -0,0 +1,716 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Media Library Assistant Ajax Handlers for Media Manager enhancements
4
+ *
5
+ * @package Media Library Assistant
6
+ * @since 2.20
7
+ */
8
+
9
+ /**
10
+ * Class MLA (Media Library Assistant) Modal Ajax contains handlers for the WordPress 3.5+ Media Manager
11
+ *
12
+ * @package Media Library Assistant
13
+ * @since 2.20
14
+ */
15
+ class MLAModal_Ajax {
16
+ /**
17
+ * Initialization function, similar to __construct()
18
+ *
19
+ * @since 2.20
20
+ *
21
+ * @return void
22
+ */
23
+ public static function initialize() {
24
+ add_action( 'admin_init', 'MLAModal_Ajax::mla_admin_init_action' );
25
+
26
+ add_action( 'wp_ajax_' . MLACore::JAVASCRIPT_QUERY_ATTACHMENTS_ACTION, 'MLAModal_Ajax::mla_query_attachments_action' );
27
+ add_action( 'wp_ajax_' . MLACore::JAVASCRIPT_FILL_COMPAT_ACTION, 'MLAModal_Ajax::mla_fill_compat_fields_action' );
28
+ add_action( 'wp_ajax_' . MLACore::JAVASCRIPT_UPDATE_COMPAT_ACTION, 'MLAModal_Ajax::mla_update_compat_fields_action' );
29
+
30
+ /*
31
+ * For each media item found by "query_attachments", these filters are called:
32
+ *
33
+ * In /wp-admin/includes/media.php, functions get_media_item() and get_compat_media_markup()
34
+ * contain "apply_filters( 'get_media_item_args', $args );", documented as:
35
+ * "Filter the arguments used to retrieve an image for the edit image form."
36
+ *
37
+ * In /wp-admin/includes/media.php, functions get_attachment_fields_to_edit()
38
+ * and get_compat_media_markup() contain
39
+ * "$form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post );",
40
+ * documented as: "Filter the attachment fields to edit."
41
+ */
42
+ add_filter( 'get_media_item_args', 'MLAModal_Ajax::mla_get_media_item_args_filter', 10, 1 );
43
+ add_filter( 'attachment_fields_to_edit', 'MLAModal_Ajax::mla_attachment_fields_to_edit_filter', 0x7FFFFFFF, 2 );
44
+ }
45
+
46
+ /**
47
+ * Adjust ajax handler for Media Manager queries
48
+ *
49
+ * Replace 'query-attachments' with our own handler if the request is coming from the "Assistant" tab.
50
+ * Clean up the 'save-attachment-compat' values, removing the taxonomy updates MLS already handled.
51
+ *
52
+ * @since 2.20
53
+ *
54
+ * @return void
55
+ */
56
+ public static function mla_admin_init_action() {
57
+ //error_log( __LINE__ . ' DEBUG: class MLAModal_Ajax::mla_admin_init_action $_POST = ' . var_export( $_POST, true ), 0 );
58
+ //cause_an_error();
59
+ //$cause_notice = $screen->bad_property;
60
+ //trigger_error( 'mla_print_media_templates_action', E_USER_WARNING );
61
+ //error_log( 'DEBUG: xdebug_get_function_stack = ' . var_export( xdebug_get_function_stack(), true), 0 );
62
+ /*
63
+ * If there's no action variable, we have nothing to do
64
+ */
65
+ if ( ! isset( $_POST['action'] ) ) {
66
+ return;
67
+ }
68
+
69
+ /*
70
+ * Build a list of enhanced taxonomies for later $_REQUEST/$_POST cleansing.
71
+ * Remove "Media Categories" instances, if present.
72
+ */
73
+ $enhanced_taxonomies = array();
74
+ foreach ( get_taxonomies( array ( 'show_ui' => true ), 'objects' ) as $key => $value ) {
75
+ if ( MLACore::mla_taxonomy_support( $key ) ) {
76
+ if ( ! $use_checklist = $value->hierarchical ) {
77
+ $use_checklist = MLACore::mla_taxonomy_support( $key, 'flat-checklist' );
78
+ }
79
+
80
+ if ( $use_checklist ) {
81
+ if ( 'checked' == MLACore::mla_get_option( MLACore::MLA_MEDIA_MODAL_DETAILS_CATEGORY_METABOX ) ) {
82
+ $enhanced_taxonomies[] = $key;
83
+
84
+ if ( class_exists( 'Media_Categories' ) && is_array( Media_Categories::$instances ) ) {
85
+ foreach( Media_Categories::$instances as $index => $instance ) {
86
+ if ( $instance->taxonomy == $key ) {
87
+ // unset( Media_Categories::$instances[ $index ] );
88
+ Media_Categories::$instances[ $index ]->taxonomy = 'MLA-has-disabled-this-instance';
89
+ }
90
+ }
91
+ } // class_exists
92
+ } // checked
93
+ } // use_checklist
94
+ } // supported
95
+ } // foreach taxonomy
96
+
97
+ /*
98
+ * The 'query-attachments' action fills the Modal Window thumbnail pane with media items.
99
+ * If the 's' value is an array, the MLA Enhanced elements are present; unpack the arguments
100
+ * and substitute our handler for the WordPress default handler.
101
+ */
102
+ if ( ( $_POST['action'] == 'query-attachments' ) && isset( $_POST['query']['s'] ) && is_array( $_POST['query']['s'] ) ){
103
+ foreach ( $_POST['query']['s'] as $key => $value ) {
104
+ $_POST['query'][ $key ] = $value;
105
+ $_REQUEST['query'][ $key ] = $value;
106
+ }
107
+
108
+ unset( $_POST['query']['s'] );
109
+ unset( $_REQUEST['query']['s'] );
110
+ $_POST['action'] = MLACore::JAVASCRIPT_QUERY_ATTACHMENTS_ACTION;
111
+ $_REQUEST['action'] = MLACore::JAVASCRIPT_QUERY_ATTACHMENTS_ACTION;
112
+ return;
113
+ } // query-attachments
114
+
115
+ /*
116
+ * The 'save-attachment-compat' action updates taxonomy and custom field
117
+ * values for an item. Remove any MLA-enhanced taxonomy data from the
118
+ * incoming data. The other taxonomies will be processed by
119
+ * /wp-admin/includes/ajax-actions.php, function wp_ajax_save_attachment_compat().
120
+ */
121
+ if ( ( $_POST['action'] == 'save-attachment-compat' ) ){
122
+ if ( empty( $_REQUEST['id'] ) || ! $id = absint( $_REQUEST['id'] ) ) {
123
+ wp_send_json_error();
124
+ }
125
+
126
+ if ( empty( $_REQUEST['attachments'] ) || empty( $_REQUEST['attachments'][ $id ] ) ) {
127
+ wp_send_json_error();
128
+ }
129
+
130
+ /*
131
+ * Media Categories uses this
132
+ */
133
+ if ( isset( $_REQUEST['category-filter'] ) ) {
134
+ unset( $_REQUEST['category-filter'] );
135
+ unset( $_POST['category-filter'] );
136
+ }
137
+
138
+ if ( isset( $_REQUEST['mla_attachments'] ) ) {
139
+ unset( $_REQUEST['mla_attachments'] );
140
+ unset( $_POST['mla_attachments'] );
141
+ }
142
+
143
+ if ( isset( $_REQUEST['tax_input'] ) ) {
144
+ unset( $_REQUEST['tax_input'] );
145
+ unset( $_POST['tax_input'] );
146
+ }
147
+
148
+ foreach( $enhanced_taxonomies as $taxonomy ) {
149
+ if ( isset( $_REQUEST['attachments'][ $id ][ $taxonomy ] ) ) {
150
+ unset( $_REQUEST['attachments'][ $id ][ $taxonomy ] );
151
+ unset( $_POST['attachments'][ $id ][ $taxonomy ] );
152
+ }
153
+
154
+ if ( isset( $_REQUEST[ $taxonomy ] ) ) {
155
+ unset( $_REQUEST[ $taxonomy ] );
156
+ unset( $_POST[ $taxonomy ] );
157
+ }
158
+
159
+ if ( ( 'category' == $taxonomy ) && isset( $_REQUEST['post_category'] ) ) {
160
+ unset( $_REQUEST['post_category'] );
161
+ unset( $_POST['post_category'] );
162
+ }
163
+
164
+ if ( isset( $_REQUEST[ 'new' . $taxonomy ] ) ) {
165
+ unset( $_REQUEST[ 'new' . $taxonomy ] );
166
+ unset( $_POST[ 'new' . $taxonomy ] );
167
+ unset( $_REQUEST[ 'new' . $taxonomy . '_parent' ] );
168
+ unset( $_POST[ 'new' . $taxonomy . '_parent' ] );
169
+ unset( $_REQUEST[ '_ajax_nonce-add-' . $taxonomy ] );
170
+ unset( $_POST[ '_ajax_nonce-add-' . $taxonomy ] );
171
+ }
172
+
173
+ if ( isset( $_REQUEST[ 'search-' . $taxonomy ] ) ) {
174
+ unset( $_REQUEST[ 'search-' . $taxonomy ] );
175
+ unset( $_POST[ 'search-' . $taxonomy ] );
176
+ unset( $_REQUEST[ '_ajax_nonce-search-' . $taxonomy ] );
177
+ unset( $_POST[ '_ajax_nonce-search-' . $taxonomy ] );
178
+ }
179
+ } // foreach taxonomy
180
+ } // save-attachment-compat
181
+ } // mla_admin_init_action
182
+
183
+ /**
184
+ * Saves the get_media_item_args array for the attachment_fields_to_edit filter
185
+ *
186
+ * Declared public because it is a filter.
187
+ *
188
+ * @since 1.71
189
+ *
190
+ * @param array arguments for the get_media_item function in /wp-admin/includes/media.php
191
+ *
192
+ * @return array arguments for the get_media_item function (unchanged)
193
+ */
194
+ public static function mla_get_media_item_args_filter( $args ) {
195
+ self::$media_item_args = $args;
196
+ return $args;
197
+ } // mla_get_media_item_args_filter
198
+
199
+ /**
200
+ * The get_media_item_args array
201
+ *
202
+ * @since 1.71
203
+ *
204
+ * @var array ( 'errors' => array of strings, 'in_modal => boolean )
205
+ */
206
+ private static $media_item_args = array( 'errors' => NULL, 'in_modal' => false );
207
+
208
+ /**
209
+ * Add/change custom fields to the Edit Media screen and Modal Window
210
+ *
211
+ * Called from /wp-admin/includes/media.php, function get_compat_media_markup();
212
+ * If "get_media_item_args"['in_modal'] => false ) its the Edit Media screen.
213
+ * If "get_media_item_args"['in_modal'] => true ) its the Media Manager Modal Window.
214
+ * For the Modal Window, $form_fields contains all the "compat-attachment-fields"
215
+ * including the taxonomies, which we want to enhance.
216
+ * Declared public because it is a filter.
217
+ *
218
+ * @since 1.71
219
+ *
220
+ * @param array descriptors for the "compat-attachment-fields"
221
+ * @param object the post to be edited
222
+ *
223
+ * @return array updated descriptors for the "compat-attachment-fields"
224
+ */
225
+ public static function mla_attachment_fields_to_edit_filter( $form_fields, $post ) {
226
+ $id = $post->ID;
227
+
228
+ /*
229
+ * This logic is only required for the MLA-enhanced Media Manager Modal Window.
230
+ * For the non-Modal Media/Edit Media screen, the MLAEdit::mla_add_meta_boxes_action
231
+ * function changes the default meta box to the MLA searchable meta box.
232
+ */
233
+ if ( isset( self::$media_item_args['in_modal'] ) && self::$media_item_args['in_modal'] ) {
234
+ foreach ( get_taxonomies( array ( 'show_ui' => true ), 'objects' ) as $key => $value ) {
235
+ if ( MLACore::mla_taxonomy_support( $key ) ) {
236
+ if ( isset( $form_fields[ $key ] ) ) {
237
+ $field = $form_fields[ $key ];
238
+ } else {
239
+ continue;
240
+ }
241
+
242
+ if ( ! $use_checklist = $value->hierarchical ) {
243
+ $use_checklist = MLACore::mla_taxonomy_support( $key, 'flat-checklist' );
244
+ }
245
+
246
+ /*
247
+ * Make sure the appropriate MMMW Enhancement option has been checked
248
+ */
249
+ if ( $use_checklist ) {
250
+ if ( 'checked' !== MLACore::mla_get_option( MLACore::MLA_MEDIA_MODAL_DETAILS_CATEGORY_METABOX ) ) {
251
+ continue;
252
+ }
253
+ } else {
254
+ if ( 'checked' !== MLACore::mla_get_option( MLACore::MLA_MEDIA_MODAL_DETAILS_TAG_METABOX ) ) {
255
+ continue;
256
+ }
257
+ }
258
+
259
+ /*
260
+ * Remove "Media Categories" meta box, if present.
261
+ */
262
+ if ( isset( $form_fields[ $key . '_metabox' ] ) ) {
263
+ unset( $form_fields[ $key . '_metabox' ] );
264
+ }
265
+
266
+ /*
267
+ * Simulate the default MMMW text box with a hidden field;
268
+ * use term names for flat taxonomies and term_ids for hierarchical.
269
+ */
270
+ $post_id = $post->ID;
271
+ $label = $field['labels']->name;
272
+ $terms = get_object_term_cache( $post_id, $key );
273
+
274
+ if ( false === $terms ) {
275
+ $terms = wp_get_object_terms( $post_id, $key );
276
+ wp_cache_add( $post_id, $terms, $key . '_relationships' );
277
+ }
278
+
279
+ if ( is_wp_error( $terms ) || empty( $terms ) ) {
280
+ $terms = array();
281
+ }
282
+
283
+ $list = array();
284
+ foreach ( $terms as $term ) {
285
+ if ( $value->hierarchical ) {
286
+ $list[] = $term->term_id;
287
+ } else {
288
+ $list[] = $term->name;
289
+ }
290
+ } // foreach $term
291
+
292
+ sort( $list );
293
+ $list = join( ',', $list );
294
+ $class = ( $value->hierarchical ) ? 'categorydiv' : 'tagsdiv';
295
+
296
+ $row = "\t\t<tr class='compat-field-{$key} mla-taxonomy-row' style='display: none'>\n";
297
+ $row .= "\t\t<th class='label' valign='top' scope='row'>\n";
298
+ $row .= "\t\t<label for='mla-attachments-{$post_id}-{$key}'>\n";
299
+ $row .= "\t\t<span title='" . __( 'Click to toggle', 'media-library-assistant' ) . "' class='alignleft'>{$label}</span><br class='clear'>\n";
300
+ $row .= "\t\t</label></th>\n";
301
+ $row .= "\t\t<td class='field'>\n";
302
+ $row .= "\t\t<div class='mla-taxonomy-field'>\n";
303
+ $row .= "\t\t<input name='mla_attachments[{$post_id}][{$key}]' class='text' id='mla-attachments-{$post_id}-{$key}' type='hidden' value='{$list}'>\n";
304
+ $row .= "\t\t<div id='mla-taxonomy-{$key}' class='{$class}'>\n";
305
+ $row .= '&lt;- ' . __( 'Click to toggle', 'media-library-assistant' ) . "\n";
306
+ $row .= "\t\t</div>\n";
307
+ $row .= "\t\t</div>\n";
308
+ $row .= "\t\t</td>\n";
309
+ $row .= "\t\t</tr>\n";
310
+ //$form_fields[ $key ] = array( 'tr' => $row );
311
+ $form_fields[ 'mla-' . $key ] = array( 'tr' => $row );
312
+ } // is supported
313
+ } // foreach
314
+
315
+ $form_fields = apply_filters( 'mla_media_modal_form_fields', $form_fields, $post );
316
+ } // in_modal
317
+
318
+ self::$media_item_args = array( 'errors' => NULL, 'in_modal' => false );
319
+ return $form_fields;
320
+ } // mla_attachment_fields_to_edit_filter
321
+
322
+ /**
323
+ * Ajax handler for Media Manager "fill compat-attachment-fields" queries
324
+ *
325
+ * Prepares an array of (HTML) taxonomy meta boxes with attachment-specific values.
326
+ *
327
+ * @since 2.20
328
+ *
329
+ * @return void passes array of results to wp_send_json_success() for JSON encoding and transmission
330
+ */
331
+ public static function mla_fill_compat_fields_action() {
332
+ if ( empty( $_REQUEST['query'] ) || ! $requested = $_REQUEST['query'] ) {
333
+ wp_send_json_error();
334
+ }
335
+
336
+ if ( empty( $_REQUEST['id'] ) || ! $post_id = absint( $_REQUEST['id'] ) ) {
337
+ wp_send_json_error();
338
+ }
339
+
340
+ if ( NULL == ( $post = get_post( $post_id ) ) ) {
341
+ wp_send_json_error();
342
+ }
343
+
344
+ $results = apply_filters( 'mla_media_modal_begin_fill_compat_fields', array(), $requested, $post );
345
+ if ( ! empty( $results ) ) {
346
+ wp_send_json_success( $results );
347
+ }
348
+
349
+ /*
350
+ * Match all supported taxonomies against the requested list
351
+ */
352
+ foreach ( get_taxonomies( array ( 'show_ui' => true ), 'objects' ) as $key => $value ) {
353
+ if ( MLACore::mla_taxonomy_support( $key ) ) {
354
+ if ( is_integer( $index = array_search( $key, $requested ) ) ) {
355
+ $request = $requested[ $index ];
356
+ } else {
357
+ continue;
358
+ }
359
+
360
+ if ( ! $use_checklist = $value->hierarchical ) {
361
+ $use_checklist = MLACore::mla_taxonomy_support( $key, 'flat-checklist' );
362
+ }
363
+
364
+ if ( $use_checklist ) {
365
+ if ( 'checked' == MLACore::mla_get_option( MLACore::MLA_MEDIA_MODAL_DETAILS_CATEGORY_METABOX ) ) {
366
+ unset( $requested[ $index ] );
367
+ $label = $value->label;
368
+ $terms = get_object_term_cache( $post_id, $key );
369
+
370
+ if ( false === $terms ) {
371
+ $terms = wp_get_object_terms( $post_id, $key );
372
+ wp_cache_add( $post_id, $terms, $key . '_relationships' );
373
+ }
374
+
375
+ if ( is_wp_error( $terms ) || empty( $terms ) ) {
376
+ $terms = array();
377
+ }
378
+
379
+ $list = array();
380
+ foreach ( $terms as $term ) {
381
+ $list[] = $term->term_id;
382
+ } // foreach $term
383
+
384
+ sort( $list );
385
+ $list = join( ',', $list );
386
+
387
+ /*
388
+ * Simulate the 'add_meta_boxes' callback
389
+ */
390
+ $box = array (
391
+ 'id' => $key . 'div',
392
+ 'title' => $label,
393
+ 'callback' => 'MLACore::mla_checklist_meta_box',
394
+ 'args' => array ( 'taxonomy' => $key, 'in_modal' => true ),
395
+
396
+ );
397
+
398
+ ob_start();
399
+ MLACore::mla_checklist_meta_box( $post, $box );
400
+ $row_content = ob_get_clean();
401
+
402
+ $row = "\t\t<th class='label' valign='top' scope='row' style='width: 99%;'>\n";
403
+ $row .= "\t\t<label for='mla-attachments-{$post_id}-{$key}'>\n";
404
+ $row .= "\t\t<span title='" . __( 'Click to toggle', 'media-library-assistant' ) . "' class='alignleft' style='width: 99%; text-align: left;'>{$label}</span><br class='clear'>\n";
405
+ $row .= "\t\t</label></th>\n";
406
+ $row .= "\t\t<td class='field' style='width: 99%; display: none'>\n";
407
+ $row .= "\t\t<div class='mla-taxonomy-field'>\n";
408
+ $row .= "\t\t<input name='attachments[{$post_id}][{$key}]' class='text' id='mla-attachments-{$post_id}-{$key}' type='hidden' value='{$list}'>\n";
409
+ $row .= $row_content;
410
+ $row .= "\t\t</div>\n";
411
+ $row .= "\t\t</td>\n";
412
+ $results[ $key ] = $row;
413
+ } // checked
414
+ } /* use_checklist */ else { // flat
415
+ if ( 'checked' == MLACore::mla_get_option( MLACore::MLA_MEDIA_MODAL_DETAILS_TAG_METABOX ) ) {
416
+ unset( $requested[ $index ] );
417
+ $label = $value->label;
418
+ $terms = get_object_term_cache( $post_id, $key );
419
+
420
+ if ( false === $terms ) {
421
+ $terms = wp_get_object_terms( $post_id, $key );
422
+ wp_cache_add( $post_id, $terms, $key . '_relationships' );
423
+ }
424
+
425
+ if ( is_wp_error( $terms ) || empty( $terms ) ) {
426
+ $terms = array();
427
+ }
428
+
429
+ $list = array();
430
+ foreach ( $terms as $term ) {
431
+ $list[] = $term->name;
432
+ } // foreach $term
433
+
434
+ sort( $list );
435
+ $hidden_list = join( ',', $list );
436
+
437
+ $row = "\t\t<th class='label' valign='top' scope='row' style='width: 99%;'>\n";
438
+ $row .= "\t\t<label for='mla-attachments-{$post_id}-{$key}'>\n";
439
+ $row .= "\t\t<span title='" . __( 'Click to toggle', 'media-library-assistant' ) . "' class='alignleft' style='width: 99%; text-align: left;'>{$label}</span><br class='clear'>\n";
440
+ $row .= "\t\t</label></th>\n";
441
+ $row .= "\t\t<td class='field' style='width: 99%; display: none'>\n";
442
+ $row .= "\t\t<div class='mla-taxonomy-field'>\n";
443
+ $row .= "\t\t<div class='tagsdiv' id='mla-taxonomy-{$key}'>\n";
444
+ $row .= "\t\t<div class='jaxtag'>\n";
445
+ $row .= "\t\t<div class='nojs-tags hide-if-js'>\n";
446
+ $row .= "\t\t<input name='attachments[{$post_id}][{$key}]' class='the-tags' id='mla-attachments-{$post_id}-{$key}' type='hidden' value='{$hidden_list}'>\n";
447
+ $row .= "\t\t<input name='mla_tags[{$post_id}][{$key}]' class='server-tags' id='mla-tags-{$post_id}-{$key}' type='hidden' value='{$hidden_list}'>\n";
448
+ $row .= "\t\t</div>\n"; // nojs-tags
449
+ $row .= "\t\t<div class='ajaxtag'>\n";
450
+ $row .= "\t\t<label class='screen-reader-text' for='new-tag-{$key}'>" . __( 'Tags', 'media-library-assistant' ) . "</label>\n";
451
+ /* translators: %s: add new taxonomy label */
452
+ $row .= "\t\t<div class='taghint'>" . sprintf( __( 'Add New %1$s', 'media-library-assistant' ), $label ) . "</div>\n";
453
+ $row .= "\t\t<p>\n";
454
+ $row .= "\t\t<input name='newtag[{$key}]' class='newtag form-input-tip' id='new-tag-{$key}' type='text' size='16' value='' autocomplete='off'>\n";
455
+ $row .= "\t\t<input class='button tagadd' type='button' value='Add'>\n";
456
+ $row .= "\t\t</p>\n";
457
+ $row .= "\t\t</div>\n"; // ajaxtag
458
+ $row .= "\t\t<p class='howto'>Separate tags with commas</p>\n";
459
+ $row .= "\t\t</div>\n"; // jaxtag
460
+ $row .= "\t\t<div class='tagchecklist'>\n";
461
+
462
+ foreach ( $list as $index => $term ) {
463
+ $row .= "\t\t<span><a class='ntdelbutton' id='post_tag-check-num-{$index}'>X</a>&nbsp;{$term}</span>\n";
464
+ }
465
+
466
+ $row .= "\t\t</div>\n"; // tagchecklist
467
+ $row .= "\t\t</div>\n"; // tagsdiv
468
+ $row .= "\t\t<p><a class='tagcloud-link' id='mla-link-{$key}' href='#titlediv'>" . __( 'Choose from the most used tags', 'media-library-assistant' ) . "</a></p>\n";
469
+ $row .= "\t\t</div>\n"; // mla-taxonomy-field
470
+ $row .= "\t\t</td>\n";
471
+ $results[ $key ] = $row;
472
+ } // checked
473
+ } // flat
474
+ } // is supported
475
+ } // foreach
476
+
477
+ /*
478
+ * Any left-over requests are for unsupported taxonomies
479
+ */
480
+ foreach( $requested as $key ) {
481
+ $row = "\t\t<tr class='compat-field-{$key} mla-taxonomy-row'>\n";
482
+ $row .= "\t\t<th class='label' valign='top' scope='row'>\n";
483
+ $row .= "\t\t<label for='mla-attachments-{$post_id}-{$key}'>\n";
484
+ $row .= "\t\t<span title='" . __( 'Click to toggle', 'media-library-assistant' ) . "' class='alignleft'>{$label}</span><br class='clear'>\n";
485
+ $row .= "\t\t</label></th>\n";
486
+ $row .= "\t\t<td class='field' style='display: none'>\n";
487
+ $row .= "\t\t<div class='mla-taxonomy-field'>\n";
488
+ $row .= "\t\t<input name='attachments[{$post_id}][{$key}]' class='text' id='mla-attachments-{$post_id}-{$key}' type='hidden' value=''>\n";
489
+ $row .= "\t\t<div id='taxonomy-{$key}' class='categorydiv'>\n";
490
+ $row .= __( 'Not Supported', 'media-library-assistant' ) . ".\n";
491
+ $row .= "\t\t</div>\n";
492
+ $row .= "\t\t</div>\n";
493
+ $row .= "\t\t</td>\n";
494
+ $row .= "\t\t</tr>\n";
495
+ $results[ $key ] = $row;
496
+ }
497
+
498
+ wp_send_json_success( apply_filters( 'mla_media_modal_end_fill_compat_fields', $results, $_REQUEST['query'], $requested, $post ) );
499
+ } // mla_fill_compat_fields_action
500
+
501
+ /**
502
+ * Ajax handler for Media Manager "update compat-attachment-fields" queries
503
+ *
504
+ * Updates one (or more) supported taxonomy and returns updated checkbox or tag/term lists
505
+ *
506
+ * @since 2.20
507
+ *
508
+ * @return void passes array of results to wp_send_json_success() for JSON encoding and transmission
509
+ */
510
+ public static function mla_update_compat_fields_action() {
511
+ global $post;
512
+
513
+ if ( empty( $_REQUEST['id'] ) || ! $post_id = absint( $_REQUEST['id'] ) ) {
514
+ wp_send_json_error();
515
+ }
516
+
517
+ if ( empty( $post ) ) {
518
+ $post = get_post( $post_id ); // for filters and wp_popular_terms_checklist
519
+ }
520
+
521
+ do_action( 'mla_media_modal_begin_update_compat_fields', $post );
522
+
523
+ $taxonomies = array();
524
+ $results = array();
525
+
526
+ foreach ( get_taxonomies( array ( 'show_ui' => true ), 'objects' ) as $key => $value ) {
527
+ if ( isset( $_REQUEST[ $key ] ) && MLACore::mla_taxonomy_support( $key ) ) {
528
+ $taxonomies[ $key ] = $value;
529
+
530
+ if ( ! $use_checklist = $value->hierarchical ) {
531
+ $use_checklist = MLACore::mla_taxonomy_support( $key, 'flat-checklist' );
532
+ }
533
+
534
+ if ( $value->hierarchical ) {
535
+ $terms = array_map( 'absint', preg_split( '/,+/', $_REQUEST[ $key ] ) );
536
+ } else {
537
+ $terms = array_map( 'trim', preg_split( '/,+/', $_REQUEST[ $key ] ) );
538
+ }
539
+
540
+ $terms = apply_filters( 'mla_media_modal_update_compat_fields_terms', $terms, $key, $value, $post_id );
541
+
542
+ if ( is_array( $terms ) ) {
543
+ wp_set_object_terms( $post_id, $terms, $key, false );
544
+ delete_transient( MLA_OPTION_PREFIX . 't_term_counts_' . $key );
545
+ }
546
+
547
+ if ( $use_checklist ) {
548
+ ob_start();
549
+ $popular_ids = wp_popular_terms_checklist( $key );
550
+ $results[$key]["mla-{$key}-checklist-pop"] = ob_get_clean();
551
+
552
+ ob_start();
553
+
554
+ if ( $value->hierarchical ) {
555
+ wp_terms_checklist( $post_id, array( 'taxonomy' => $key, 'popular_cats' => $popular_ids ) );
556
+ } else {
557
+ $checklist_walker = new MLA_Checklist_Walker;
558
+ wp_terms_checklist( $post_id, array( 'taxonomy' => $key, 'popular_cats' => $popular_ids, 'walker' => $checklist_walker ) );
559
+ }
560
+
561
+ $results[$key]["mla-{$key}-checklist"] = ob_get_clean();
562
+ } else {
563
+ $terms = get_object_term_cache( $post_id, $key );
564
+
565
+ if ( false === $terms ) {
566
+ $terms = wp_get_object_terms( $post_id, $key );
567
+ wp_cache_add( $post_id, $terms, $key . '_relationships' );
568
+ }
569
+
570
+ if ( is_wp_error( $terms ) || empty( $terms ) ) {
571
+ $terms = array();
572
+ }
573
+
574
+ $list = array();
575
+ $object_terms = array();
576
+ foreach ( $terms as $term ) {
577
+ $list[] = $term->name;
578
+ $object_terms[ $term->term_id ] = $term->name;
579
+ } // foreach $term
580
+
581
+ sort( $list );
582
+ $hidden_list = join( ',', $list );
583
+
584
+ $results[$key]["object-terms"] = $object_terms;
585
+ $results[$key]["mla-attachments-{$post_id}-{$key}"] = "\t\t<input name='attachments[{$post_id}][{$key}]' class='the-tags' id='mla-attachments-{$post_id}-{$key}' type='hidden' value='{$hidden_list}'>\n";
586
+ $results[$key]["mla-tags-{$post_id}-{$key}"] = "\t\t<input name='mla_tags[{$post_id}][{$key}]' class='server-tags' id='mla-tags-{$post_id}-{$key}' type='hidden' value='{$hidden_list}'>\n";
587
+ }
588
+ } // set and supported
589
+ } // foreach taxonomy
590
+
591
+ wp_send_json_success( apply_filters( 'mla_media_modal_end_update_compat_fields', $results, $taxonomies, $post ) );
592
+ } // mla_update_compat_fields_action
593
+
594
+ /**
595
+ * Ajax handler for Media Manager "Query Attachments" queries
596
+ *
597
+ * Adapted from wp_ajax_query_attachments in /wp-admin/includes/ajax-actions.php
598
+ *
599
+ * @since 2.20
600
+ *
601
+ * @return void passes array of post arrays to wp_send_json_success() for JSON encoding and transmission
602
+ */
603
+ public static function mla_query_attachments_action() {
604
+ if ( ! current_user_can( 'upload_files' ) ) {
605
+ wp_send_json_error();
606
+ }
607
+
608
+ /*
609
+ * Pick out and clean up the query terms we can process
610
+ */
611
+ $raw_query = isset( $_REQUEST['query'] ) ? (array) $_REQUEST['query'] : array();
612
+ $query = array_intersect_key( $raw_query, array_flip( array(
613
+ 'order', 'orderby', 'posts_per_page', 'paged', 'post_mime_type',
614
+ 'post_parent', 'post__in', 'post__not_in',
615
+ 'mla_filter_month', 'mla_filter_term', 'mla_terms_search',
616
+ 'mla_search_value', 's', 'mla_search_fields', 'mla_search_connector'
617
+ ) ) );
618
+
619
+ $query = apply_filters( 'mla_media_modal_query_initial_terms', $query, $raw_query );
620
+
621
+ if ( isset( $query['post_mime_type'] ) ) {
622
+ if ( 'detached' == $query['post_mime_type'] ) {
623
+ $query['detached'] = '1';
624
+ unset( $query['post_mime_type'] );
625
+ } elseif ( 'attached' == $query['post_mime_type'] ) {
626
+ $query['detached'] = '0';
627
+ unset( $query['post_mime_type'] );
628
+ } elseif ( 'trash' == $query['post_mime_type'] ) {
629
+ $query['status'] = 'trash';
630
+ unset( $query['post_mime_type'] );
631
+ } else {
632
+ $view = $query['post_mime_type'];
633
+ unset( $query['post_mime_type'] );
634
+ $query = array_merge( $query, MLACore::mla_prepare_view_query( 'view', $view ) );
635
+ }
636
+ }
637
+
638
+ /*
639
+ * Convert mla_filter_month back to the WordPress "m" parameter
640
+ */
641
+ if ( isset( $query['mla_filter_month'] ) ) {
642
+ if ( '0' != $query['mla_filter_month'] ) {
643
+ $query['m'] = $query['mla_filter_month'];
644
+ }
645
+
646
+ unset( $query['mla_filter_month'] );
647
+ }
648
+
649
+ /*
650
+ * Process the enhanced search box OR fix up the default search box
651
+ */
652
+ if ( isset( $query['mla_search_value'] ) ) {
653
+ if ( ! empty( $query['mla_search_value'] ) ) {
654
+ $query['s'] = $query['mla_search_value'];
655
+ }
656
+
657
+ unset( $query['mla_search_value'] );
658
+ }
659
+
660
+ if ( isset( $query['posts_per_page'] ) ) {
661
+ $count = $query['posts_per_page'];
662
+ $offset = $count * (isset( $query['paged'] ) ? $query['paged'] - 1 : 0);
663
+ } else {
664
+ $count = 0;
665
+ $offset = 0;
666
+ }
667
+
668
+ /*
669
+ * Check for sorting override
670
+ */
671
+ $option = MLACore::mla_get_option( MLACore::MLA_MEDIA_MODAL_ORDERBY );
672
+ if ( 'default' != $option ) {
673
+ /*
674
+ * Make sure the current orderby choice still exists or revert to default.
675
+ */
676
+ $default_orderby = array_merge( array( 'none' => array('none',false) ), MLAQuery::mla_get_sortable_columns( ) );
677
+ $found_current = false;
678
+ foreach ($default_orderby as $key => $value ) {
679
+ if ( $option == $value[0] ) {
680
+ $found_current = true;
681
+ break;
682
+ }
683
+ }
684
+
685
+ if ( ! $found_current ) {
686
+ MLACore::mla_delete_option( MLACore::MLA_DEFAULT_ORDERBY );
687
+ $option = MLACore::mla_get_option( MLACore::MLA_DEFAULT_ORDERBY );
688
+ }
689
+
690
+ $query['orderby'] = $option;
691
+ }
692
+
693
+ $option = MLACore::mla_get_option( MLACore::MLA_MEDIA_MODAL_ORDER );
694
+ if ( 'default' != $option ) {
695
+ $query['order'] = $option;
696
+ }
697
+
698
+ $query['post_type'] = 'attachment';
699
+
700
+ if ( empty( $query['status'] ) ) {
701
+ $query['post_status'] = 'inherit';
702
+ if ( current_user_can( get_post_type_object( 'attachment' )->cap->read_private_posts ) ) {
703
+ $query['post_status'] .= ',private';
704
+ }
705
+ }
706
+
707
+ $query = apply_filters( 'mla_media_modal_query_filtered_terms', $query, $raw_query );
708
+
709
+ $query = MLAQuery::mla_query_media_modal_items( $query, $offset, $count );
710
+ $posts = array_map( 'wp_prepare_attachment_for_js', $query->posts );
711
+ $posts = array_filter( $posts );
712
+
713
+ wp_send_json_success( $posts );
714
+ }
715
+ } //Class MLAModal_Ajax
716
+ ?>
includes/class-mla-media-modal.php CHANGED
@@ -49,33 +49,6 @@ class MLAModal {
49
  */
50
  const JAVASCRIPT_TERMS_SEARCH_OBJECT = 'mla_terms_search_vars';
51
 
52
- /**
53
- * Slug for the "query attachments" action - Add Media and related dialogs
54
- *
55
- * @since 1.80
56
- *
57
- * @var string
58
- */
59
- const JAVASCRIPT_QUERY_ATTACHMENTS_ACTION = 'mla-query-attachments';
60
-
61
- /**
62
- * Slug for the "fill compat-attachment-fields" action - Add Media and related dialogs
63
- *
64
- * @since 1.80
65
- *
66
- * @var string
67
- */
68
- const JAVASCRIPT_FILL_COMPAT_ACTION = 'mla-fill-compat-fields';
69
-
70
- /**
71
- * Slug for the "update compat-attachment-fields" action - Add Media and related dialogs
72
- *
73
- * @since 1.80
74
- *
75
- * @var string
76
- */
77
- const JAVASCRIPT_UPDATE_COMPAT_ACTION = 'mla-update-compat-fields';
78
-
79
  /**
80
  * Initialization function, similar to __construct()
81
  *
@@ -97,174 +70,17 @@ class MLAModal {
97
  *
98
  * Finally wp_enqueue_media() contains:
99
  * do_action( 'wp_enqueue_media' );
100
- *
101
- * For each media item found by "query_attachments", these filters are called:
102
- *
103
- * In /wp-admin/includes/media.php, functions get_media_item() and get_compat_media_markup()
104
- * contain "apply_filters( 'get_media_item_args', $args );", documented as:
105
- * "Filter the arguments used to retrieve an image for the edit image form."
106
- *
107
- * In /wp-admin/includes/media.php, functions get_attachment_fields_to_edit()
108
- * and get_compat_media_markup() contain
109
- * "$form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post );",
110
- * documented as: "Filter the attachment fields to edit."
111
  */
112
 
113
- if ( ( ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_MODAL_TOOLBAR ) ) || ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_GRID_TOOLBAR ) ) ) ) {
114
- add_filter( 'get_media_item_args', 'MLAModal::mla_get_media_item_args_filter', 10, 1 );
115
- add_filter( 'attachment_fields_to_edit', 'MLAModal::mla_attachment_fields_to_edit_filter', 0x7FFFFFFF, 2 );
116
-
117
  add_filter( 'media_view_settings', 'MLAModal::mla_media_view_settings_filter', 10, 2 );
118
  add_filter( 'media_view_strings', 'MLAModal::mla_media_view_strings_filter', 10, 2 );
119
  add_action( 'wp_enqueue_media', 'MLAModal::mla_wp_enqueue_media_action', 10, 0 );
120
  add_action( 'print_media_templates', 'MLAModal::mla_print_media_templates_action', 10, 0 );
121
  add_action( 'admin_init', 'MLAModal::mla_admin_init_action' );
122
-
123
- add_action( 'wp_ajax_' . self::JAVASCRIPT_QUERY_ATTACHMENTS_ACTION, 'MLAModal::mla_query_attachments_action' );
124
- add_action( 'wp_ajax_' . self::JAVASCRIPT_FILL_COMPAT_ACTION, 'MLAModal::mla_fill_compat_fields_action' );
125
- add_action( 'wp_ajax_' . self::JAVASCRIPT_UPDATE_COMPAT_ACTION, 'MLAModal::mla_update_compat_fields_action' );
126
  } // Media Modal support enabled
127
  }
128
 
129
- /**
130
- * Saves the get_media_item_args array for the attachment_fields_to_edit filter
131
- *
132
- * Declared public because it is a filter.
133
- *
134
- * @since 1.71
135
- *
136
- * @param array arguments for the get_media_item function in /wp-admin/includes/media.php
137
- *
138
- * @return array arguments for the get_media_item function (unchanged)
139
- */
140
- public static function mla_get_media_item_args_filter( $args ) {
141
- self::$media_item_args = $args;
142
- return $args;
143
- } // mla_get_media_item_args_filter
144
-
145
- /**
146
- * The get_media_item_args array
147
- *
148
- * @since 1.71
149
- *
150
- * @var array ( 'errors' => array of strings, 'in_modal => boolean )
151
- */
152
- private static $media_item_args = array( 'errors' => null, 'in_modal' => false );
153
-
154
- /**
155
- * Add/change custom fields to the Edit Media screen and Modal Window
156
- *
157
- * Called from /wp-admin/includes/media.php, function get_compat_media_markup();
158
- * If "get_media_item_args"['in_modal'] => false ) its the Edit Media screen.
159
- * If "get_media_item_args"['in_modal'] => true ) its the Media Manager Modal Window.
160
- * For the Modal Window, $form_fields contains all the "compat-attachment-fields"
161
- * including the taxonomies, which we want to enhance.
162
- * Declared public because it is a filter.
163
- *
164
- * @since 1.71
165
- *
166
- * @param array descriptors for the "compat-attachment-fields"
167
- * @param object the post to be edited
168
- *
169
- * @return array updated descriptors for the "compat-attachment-fields"
170
- */
171
- public static function mla_attachment_fields_to_edit_filter( $form_fields, $post ) {
172
- $id = $post->ID;
173
-
174
- /*
175
- * This logic is only required for the MLA-enhanced Media Manager Modal Window.
176
- * For the non-Modal Media/Edit Media screen, the MLAEdit::mla_add_meta_boxes_action
177
- * function changes the default meta box to the MLA searchable meta box.
178
- */
179
- if ( isset( self::$media_item_args['in_modal'] ) && self::$media_item_args['in_modal'] ) {
180
- foreach ( get_taxonomies( array ( 'show_ui' => true ), 'objects' ) as $key => $value ) {
181
- if ( MLAOptions::mla_taxonomy_support( $key ) ) {
182
- if ( isset( $form_fields[ $key ] ) ) {
183
- $field = $form_fields[ $key ];
184
- } else {
185
- continue;
186
- }
187
-
188
- if ( ! $use_checklist = $value->hierarchical ) {
189
- $use_checklist = MLAOptions::mla_taxonomy_support( $key, 'flat-checklist' );
190
- }
191
-
192
- /*
193
- * Make sure the appropriate MMMW Enhancement option has been checked
194
- */
195
- if ( $use_checklist ) {
196
- if ( 'checked' !== MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_MODAL_DETAILS_CATEGORY_METABOX ) ) {
197
- continue;
198
- }
199
- } else {
200
- if ( 'checked' !== MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_MODAL_DETAILS_TAG_METABOX ) ) {
201
- continue;
202
- }
203
- }
204
-
205
- /*
206
- * Remove "Media Categories" meta box, if present.
207
- */
208
- if ( isset( $form_fields[ $key . '_metabox' ] ) ) {
209
- unset( $form_fields[ $key . '_metabox' ] );
210
- }
211
-
212
- /*
213
- * Simulate the default MMMW text box with a hidden field;
214
- * use term names for flat taxonomies and term_ids for hierarchical.
215
- */
216
- $post_id = $post->ID;
217
- $label = $field['labels']->name;
218
- $terms = get_object_term_cache( $post_id, $key );
219
-
220
- if ( false === $terms ) {
221
- $terms = wp_get_object_terms( $post_id, $key );
222
- wp_cache_add( $post_id, $terms, $key . '_relationships' );
223
- }
224
-
225
- if ( is_wp_error( $terms ) || empty( $terms ) ) {
226
- $terms = array();
227
- }
228
-
229
- $list = array();
230
- foreach ( $terms as $term ) {
231
- if ( $value->hierarchical ) {
232
- $list[] = $term->term_id;
233
- } else {
234
- $list[] = $term->name;
235
- }
236
- } // foreach $term
237
-
238
- sort( $list );
239
- $list = join( ',', $list );
240
- $class = ( $value->hierarchical ) ? 'categorydiv' : 'tagsdiv';
241
-
242
- $row = "\t\t<tr class='compat-field-{$key} mla-taxonomy-row' style='display: none'>\n";
243
- $row .= "\t\t<th class='label' valign='top' scope='row'>\n";
244
- $row .= "\t\t<label for='mla-attachments-{$post_id}-{$key}'>\n";
245
- $row .= "\t\t<span title='" . __( 'Click to toggle', 'media-library-assistant' ) . "' class='alignleft'>{$label}</span><br class='clear'>\n";
246
- $row .= "\t\t</label></th>\n";
247
- $row .= "\t\t<td class='field'>\n";
248
- $row .= "\t\t<div class='mla-taxonomy-field'>\n";
249
- $row .= "\t\t<input name='mla_attachments[{$post_id}][{$key}]' class='text' id='mla-attachments-{$post_id}-{$key}' type='hidden' value='{$list}'>\n";
250
- $row .= "\t\t<div id='mla-taxonomy-{$key}' class='{$class}'>\n";
251
- $row .= '&lt;- ' . __( 'Click to toggle', 'media-library-assistant' ) . "\n";
252
- $row .= "\t\t</div>\n";
253
- $row .= "\t\t</div>\n";
254
- $row .= "\t\t</td>\n";
255
- $row .= "\t\t</tr>\n";
256
- //$form_fields[ $key ] = array( 'tr' => $row );
257
- $form_fields[ 'mla-' . $key ] = array( 'tr' => $row );
258
- } // is supported
259
- } // foreach
260
-
261
- $form_fields = apply_filters( 'mla_media_modal_form_fields', $form_fields, $post );
262
- } // in_modal
263
-
264
- self::$media_item_args = array( 'errors' => null, 'in_modal' => false );
265
- return $form_fields;
266
- } // mla_attachment_fields_to_edit_filter
267
-
268
  /**
269
  * Display a monthly dropdown for filtering items
270
  *
@@ -356,9 +172,9 @@ class MLAModal {
356
  'state' => 'initial',
357
  'comma' => ',',
358
  'ajaxNonce' => '',
359
- 'ajaxFillCompatAction' => self::JAVASCRIPT_FILL_COMPAT_ACTION,
360
- 'ajaxQueryAttachmentsAction' => self::JAVASCRIPT_QUERY_ATTACHMENTS_ACTION,
361
- 'ajaxUpdateCompatAction' => self::JAVASCRIPT_UPDATE_COMPAT_ACTION,
362
  'enableDetailsCategory' => false,
363
  'enableDetailsTag' => false,
364
  'enableMimeTypes' => false,
@@ -413,22 +229,23 @@ class MLAModal {
413
  }
414
  }
415
 
 
416
  self::$mla_media_modal_settings['comma'] = _x( ',', 'tag_delimiter', 'media-library-assistant' );
417
- self::$mla_media_modal_settings['ajaxNonce'] = wp_create_nonce( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
418
  self::$mla_media_modal_settings['allMimeTypes'] = MLAMime::mla_pluck_table_views();
419
- self::$mla_media_modal_settings['allMimeTypes']['detached'] = MLAOptions::$mla_option_definitions[ MLAOptions::MLA_POST_MIME_TYPES ]['std']['detached']['plural'];
420
- self::$mla_media_modal_settings['allMimeTypes']['attached'] = MLAOptions::$mla_option_definitions[ MLAOptions::MLA_POST_MIME_TYPES ]['std']['attached']['plural'];
421
 
422
  /*
423
  * Trash items are allowed in the Media/Library Grid view
424
  */
425
  if ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) {
426
- self::$mla_media_modal_settings['allMimeTypes']['trash'] = MLAOptions::$mla_option_definitions[ MLAOptions::MLA_POST_MIME_TYPES ]['std']['trash']['plural'];
427
  }
428
 
429
  self::$mla_media_modal_settings['months'] = self::_months_dropdown('attachment');
430
 
431
- self::$mla_media_modal_settings['termsTaxonomy'] = MLAOptions::mla_taxonomy_support('', 'filter');
432
  $terms_options = self::_terms_options( MLA_List_Table::mla_get_taxonomy_filter_dropdown() );
433
  self::$mla_media_modal_settings['termsClass'] = $terms_options['class'];
434
  self::$mla_media_modal_settings['termsValue'] = $terms_options['value'];
@@ -439,41 +256,41 @@ class MLAModal {
439
  self::$mla_media_modal_settings['termsIndent'] = '-';
440
  }
441
 
442
- self::$mla_media_modal_settings['enableMediaGrid'] = ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_GRID_TOOLBAR ) );
443
- self::$mla_media_modal_settings['enableMediaModal'] = ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_MODAL_TOOLBAR ) );
444
- self::$mla_media_modal_settings['enableDetailsCategory'] = ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_MODAL_DETAILS_CATEGORY_METABOX ) );
445
- self::$mla_media_modal_settings['enableDetailsTag'] = ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_MODAL_DETAILS_TAG_METABOX ) );
446
- self::$mla_media_modal_settings['enableMimeTypes'] = ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_MODAL_MIMETYPES ) );
447
- self::$mla_media_modal_settings['enableMonthsDropdown'] = ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_MODAL_MONTHS ) );
448
- self::$mla_media_modal_settings['enableSearchBox'] = ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_MODAL_SEARCHBOX ) );
449
- self::$mla_media_modal_settings['enableSearchBoxControls'] = ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_MODAL_SEARCHBOX_CONTROLS ) );
450
 
451
- $supported_taxonomies = MLAOptions::mla_supported_taxonomies('support');
452
- self::$mla_media_modal_settings['enableTermsDropdown'] = ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_MODAL_TERMS ) ) && ( ! empty( $supported_taxonomies ) );
453
- self::$mla_media_modal_settings['enableTermsAutofill'] = ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_MODAL_DETAILS_AUTOFILL ) ) && ( ! empty( $supported_taxonomies ) );
454
 
455
- $supported_taxonomies = MLAOptions::mla_supported_taxonomies('term-search');
456
- self::$mla_media_modal_settings['enableTermsSearch'] = ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_MODAL_TERMS_SEARCH ) ) && ( ! empty( $supported_taxonomies ) );
457
 
458
  /*
459
  * Compile a list of the enhanced taxonomies
460
  */
461
  self::$mla_media_modal_settings['enhancedTaxonomies'] = array();
462
  foreach ( get_taxonomies( array ( 'show_ui' => true ), 'objects' ) as $key => $value ) {
463
- if ( MLAOptions::mla_taxonomy_support( $key ) ) {
464
  if ( ! $use_checklist = $value->hierarchical ) {
465
- $use_checklist = MLAOptions::mla_taxonomy_support( $key, 'flat-checklist' );
466
  }
467
 
468
  /*
469
  * Make sure the appropriate MMMW Enhancement option has been checked
470
  */
471
  if ( $use_checklist ) {
472
- if ( 'checked' === MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_MODAL_DETAILS_CATEGORY_METABOX ) ) {
473
  self::$mla_media_modal_settings['enhancedTaxonomies'][] = $key;
474
  }
475
  } else {
476
- if ( 'checked' === MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_MODAL_DETAILS_TAG_METABOX ) ) {
477
  self::$mla_media_modal_settings['enhancedTaxonomies'][] = $key;
478
  }
479
  }
@@ -483,7 +300,7 @@ class MLAModal {
483
  /*
484
  * Set and filter the initial values for toolbar controls
485
  */
486
- $search_defaults = MLAOptions::mla_get_option( MLAOptions::MLA_SEARCH_MEDIA_FILTER_DEFAULTS );
487
  $initial_values = array(
488
  'filterMime' => 'all',
489
  'filterUploaded' => 'all',
@@ -498,7 +315,7 @@ class MLAModal {
498
  $initial_values = apply_filters( 'mla_media_modal_initial_filters', $initial_values, $post );
499
 
500
  // No supported taxonomies implies no "terms" search
501
- $supported_taxonomies = MLAOptions::mla_supported_taxonomies('support');
502
  if ( empty( $supported_taxonomies ) ) {
503
  $index = array_search( 'terms', $initial_values['searchFields'] );
504
  if ( false !== $index ) {
@@ -539,7 +356,7 @@ class MLAModal {
539
  $mla_strings = array(
540
  'searchBoxPlaceholder' => __( 'Search Box', 'media-library-assistant' ),
541
  'loadingText' => __( 'Loading...', 'media-library-assistant' ),
542
- 'searchBoxControlsStyle' => ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_MODAL_SEARCHBOX_CONTROLS ) ) ? 'display: inline;' : 'display: none;',
543
  );
544
 
545
  $strings = array_merge( $strings, array( 'mla_strings' => $mla_strings ) );
@@ -565,10 +382,10 @@ class MLAModal {
565
 
566
  if ( is_object( $screen ) ) {
567
  if ( 'upload' == $screen->base ) {
568
- if ( 'checked' != MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_GRID_TOOLBAR ) ) {
569
  return;
570
  }
571
- } elseif ( 'checked' != MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_MODAL_TOOLBAR ) ) {
572
  return;
573
  }
574
  }
@@ -586,7 +403,7 @@ class MLAModal {
586
 
587
  wp_enqueue_script( self::JAVASCRIPT_MEDIA_MODAL_SLUG, MLA_PLUGIN_URL . "js/mla-media-modal-scripts{$suffix}.js", array( 'media-views', 'wp-lists', 'suggest' ), MLA::CURRENT_MLA_VERSION, false );
588
 
589
- if ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_MODAL_TERMS_SEARCH ) ) {
590
  MLAModal::mla_add_terms_search_scripts();
591
  }
592
  } // mla_wp_enqueue_media_action
@@ -607,10 +424,10 @@ class MLAModal {
607
  $screen = get_current_screen();
608
 
609
  if ( 'upload' == $screen->base ) {
610
- if ( 'checked' != MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_GRID_TOOLBAR ) ) {
611
  return;
612
  }
613
- } elseif ( 'checked' != MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_MODAL_TOOLBAR ) ) {
614
  return;
615
  }
616
  } else {
@@ -626,10 +443,7 @@ class MLAModal {
626
  } // mla_print_media_templates_action
627
 
628
  /**
629
- * Adjust ajax handler for Media Manager queries
630
- *
631
- * Replace 'query-attachments' with our own handler if the request is coming from the "Assistant" tab.
632
- * Clean up the 'save-attachment-compat' values, removing the taxonomy updates MLS already handled.
633
  *
634
  * @since 1.20
635
  *
@@ -642,13 +456,13 @@ class MLAModal {
642
  */
643
  $enhanced_taxonomies = array();
644
  foreach ( get_taxonomies( array ( 'show_ui' => true ), 'objects' ) as $key => $value ) {
645
- if ( MLAOptions::mla_taxonomy_support( $key ) ) {
646
  if ( ! $use_checklist = $value->hierarchical ) {
647
- $use_checklist = MLAOptions::mla_taxonomy_support( $key, 'flat-checklist' );
648
  }
649
 
650
  if ( $use_checklist ) {
651
- if ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_MODAL_DETAILS_CATEGORY_METABOX ) ) {
652
  $enhanced_taxonomies[] = $key;
653
 
654
  if ( class_exists( 'Media_Categories' ) && is_array( Media_Categories::$instances ) ) {
@@ -663,502 +477,8 @@ class MLAModal {
663
  } // use_checklist
664
  } // supported
665
  } // foreach taxonomy
666
-
667
- if ( ( defined('WP_ADMIN') && WP_ADMIN ) && ( defined('DOING_AJAX') && DOING_AJAX ) ) {
668
- //error_log( 'DEBUG: mla_admin_init_action $_POST = ' . var_export( $_POST, true ), 0 );
669
- //cause_an_error();
670
- //$cause_notice = $screen->bad_property;
671
- //trigger_error( 'mla_print_media_templates_action', E_USER_WARNING );
672
- //error_log( 'DEBUG: xdebug_get_function_stack = ' . var_export( xdebug_get_function_stack(), true), 0 );
673
-
674
- /*
675
- * If there's no action variable, we have nothing to do
676
- */
677
- if ( ! isset( $_POST['action'] ) ) {
678
- return;
679
- }
680
-
681
- /*
682
- * The 'query-attachments' action fills the Modal Window thumbnail pane with media items.
683
- * If the 's' value is an array, the MLA Enhanced elements are present; unpack the arguments
684
- * and substitute our handler for the WordPress default handler.
685
- */
686
- if ( ( $_POST['action'] == 'query-attachments' ) && isset( $_POST['query']['s'] ) && is_array( $_POST['query']['s'] ) ){
687
- foreach ( $_POST['query']['s'] as $key => $value ) {
688
- $_POST['query'][ $key ] = $value;
689
- $_REQUEST['query'][ $key ] = $value;
690
- }
691
-
692
- unset( $_POST['query']['s'] );
693
- unset( $_REQUEST['query']['s'] );
694
- $_POST['action'] = self::JAVASCRIPT_QUERY_ATTACHMENTS_ACTION;
695
- $_REQUEST['action'] = self::JAVASCRIPT_QUERY_ATTACHMENTS_ACTION;
696
- return;
697
- } // query-attachments
698
-
699
- /*
700
- * The 'save-attachment-compat' action updates taxonomy and custom field
701
- * values for an item. Remove any MLA-enhanced taxonomy data from the
702
- * incoming data. The other taxonomies will be processed by
703
- * /wp-admin/includes/ajax-actions.php, function wp_ajax_save_attachment_compat().
704
- */
705
- if ( ( $_POST['action'] == 'save-attachment-compat' ) ){
706
- if ( empty( $_REQUEST['id'] ) || ! $id = absint( $_REQUEST['id'] ) ) {
707
- wp_send_json_error();
708
- }
709
-
710
- if ( empty( $_REQUEST['attachments'] ) || empty( $_REQUEST['attachments'][ $id ] ) ) {
711
- wp_send_json_error();
712
- }
713
-
714
- /*
715
- * Media Categories uses this
716
- */
717
- if ( isset( $_REQUEST['category-filter'] ) ) {
718
- unset( $_REQUEST['category-filter'] );
719
- unset( $_POST['category-filter'] );
720
- }
721
-
722
- if ( isset( $_REQUEST['mla_attachments'] ) ) {
723
- unset( $_REQUEST['mla_attachments'] );
724
- unset( $_POST['mla_attachments'] );
725
- }
726
-
727
- if ( isset( $_REQUEST['tax_input'] ) ) {
728
- unset( $_REQUEST['tax_input'] );
729
- unset( $_POST['tax_input'] );
730
- }
731
-
732
- foreach( $enhanced_taxonomies as $taxonomy ) {
733
- if ( isset( $_REQUEST['attachments'][ $id ][ $taxonomy ] ) ) {
734
- unset( $_REQUEST['attachments'][ $id ][ $taxonomy ] );
735
- unset( $_POST['attachments'][ $id ][ $taxonomy ] );
736
- }
737
-
738
- if ( isset( $_REQUEST[ $taxonomy ] ) ) {
739
- unset( $_REQUEST[ $taxonomy ] );
740
- unset( $_POST[ $taxonomy ] );
741
- }
742
-
743
- if ( ( 'category' == $taxonomy ) && isset( $_REQUEST['post_category'] ) ) {
744
- unset( $_REQUEST['post_category'] );
745
- unset( $_POST['post_category'] );
746
- }
747
-
748
- if ( isset( $_REQUEST[ 'new' . $taxonomy ] ) ) {
749
- unset( $_REQUEST[ 'new' . $taxonomy ] );
750
- unset( $_POST[ 'new' . $taxonomy ] );
751
- unset( $_REQUEST[ 'new' . $taxonomy . '_parent' ] );
752
- unset( $_POST[ 'new' . $taxonomy . '_parent' ] );
753
- unset( $_REQUEST[ '_ajax_nonce-add-' . $taxonomy ] );
754
- unset( $_POST[ '_ajax_nonce-add-' . $taxonomy ] );
755
- }
756
-
757
- if ( isset( $_REQUEST[ 'search-' . $taxonomy ] ) ) {
758
- unset( $_REQUEST[ 'search-' . $taxonomy ] );
759
- unset( $_POST[ 'search-' . $taxonomy ] );
760
- unset( $_REQUEST[ '_ajax_nonce-search-' . $taxonomy ] );
761
- unset( $_POST[ '_ajax_nonce-search-' . $taxonomy ] );
762
- }
763
- } // foreach taxonomy
764
- } // save-attachment-compat
765
- }
766
  } // mla_admin_init_action
767
 
768
- /**
769
- * Ajax handler for Media Manager "fill compat-attachment-fields" queries
770
- *
771
- * Prepares an array of (HTML) taxonomy meta boxes with attachment-specific values.
772
- *
773
- * @since 1.80
774
- *
775
- * @return void passes array of results to wp_send_json_success() for JSON encoding and transmission
776
- */
777
- public static function mla_fill_compat_fields_action() {
778
- if ( empty( $_REQUEST['query'] ) || ! $requested = $_REQUEST['query'] ) {
779
- wp_send_json_error();
780
- }
781
-
782
- if ( empty( $_REQUEST['id'] ) || ! $post_id = absint( $_REQUEST['id'] ) ) {
783
- wp_send_json_error();
784
- }
785
-
786
- if ( null == ( $post = get_post( $post_id ) ) ) {
787
- wp_send_json_error();
788
- }
789
-
790
- $results = apply_filters( 'mla_media_modal_begin_fill_compat_fields', array(), $requested, $post );
791
- if ( ! empty( $results ) ) {
792
- wp_send_json_success( $results );
793
- }
794
-
795
- /*
796
- * Match all supported taxonomies against the requested list
797
- */
798
- foreach ( get_taxonomies( array ( 'show_ui' => true ), 'objects' ) as $key => $value ) {
799
- if ( MLAOptions::mla_taxonomy_support( $key ) ) {
800
- if ( is_integer( $index = array_search( $key, $requested ) ) ) {
801
- $request = $requested[ $index ];
802
- } else {
803
- continue;
804
- }
805
-
806
- if ( ! $use_checklist = $value->hierarchical ) {
807
- $use_checklist = MLAOptions::mla_taxonomy_support( $key, 'flat-checklist' );
808
- }
809
-
810
- if ( $use_checklist ) {
811
- if ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_MODAL_DETAILS_CATEGORY_METABOX ) ) {
812
- unset( $requested[ $index ] );
813
- $label = $value->label;
814
- $terms = get_object_term_cache( $post_id, $key );
815
-
816
- if ( false === $terms ) {
817
- $terms = wp_get_object_terms( $post_id, $key );
818
- wp_cache_add( $post_id, $terms, $key . '_relationships' );
819
- }
820
-
821
- if ( is_wp_error( $terms ) || empty( $terms ) ) {
822
- $terms = array();
823
- }
824
-
825
- $list = array();
826
- foreach ( $terms as $term ) {
827
- $list[] = $term->term_id;
828
- } // foreach $term
829
-
830
- sort( $list );
831
- $list = join( ',', $list );
832
-
833
- /*
834
- * Simulate the 'add_meta_boxes' callback
835
- */
836
- $box = array (
837
- 'id' => $key . 'div',
838
- 'title' => $label,
839
- 'callback' => 'MLAEdit::mla_checklist_meta_box',
840
- 'args' => array ( 'taxonomy' => $key, 'in_modal' => true ),
841
-
842
- );
843
-
844
- ob_start();
845
- MLAEdit::mla_checklist_meta_box( $post, $box );
846
- $row_content = ob_get_clean();
847
-
848
- $row = "\t\t<th class='label' valign='top' scope='row' style='width: 99%;'>\n";
849
- $row .= "\t\t<label for='mla-attachments-{$post_id}-{$key}'>\n";
850
- $row .= "\t\t<span title='" . __( 'Click to toggle', 'media-library-assistant' ) . "' class='alignleft' style='width: 99%; text-align: left;'>{$label}</span><br class='clear'>\n";
851
- $row .= "\t\t</label></th>\n";
852
- $row .= "\t\t<td class='field' style='width: 99%; display: none'>\n";
853
- $row .= "\t\t<div class='mla-taxonomy-field'>\n";
854
- $row .= "\t\t<input name='attachments[{$post_id}][{$key}]' class='text' id='mla-attachments-{$post_id}-{$key}' type='hidden' value='{$list}'>\n";
855
- $row .= $row_content;
856
- $row .= "\t\t</div>\n";
857
- $row .= "\t\t</td>\n";
858
- $results[ $key ] = $row;
859
- } // checked
860
- } /* use_checklist */ else { // flat
861
- if ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_MODAL_DETAILS_TAG_METABOX ) ) {
862
- unset( $requested[ $index ] );
863
- $label = $value->label;
864
- $terms = get_object_term_cache( $post_id, $key );
865
-
866
- if ( false === $terms ) {
867
- $terms = wp_get_object_terms( $post_id, $key );
868
- wp_cache_add( $post_id, $terms, $key . '_relationships' );
869
- }
870
-
871
- if ( is_wp_error( $terms ) || empty( $terms ) ) {
872
- $terms = array();
873
- }
874
-
875
- $list = array();
876
- foreach ( $terms as $term ) {
877
- $list[] = $term->name;
878
- } // foreach $term
879
-
880
- sort( $list );
881
- $hidden_list = join( ',', $list );
882
-
883
- $row = "\t\t<th class='label' valign='top' scope='row' style='width: 99%;'>\n";
884
- $row .= "\t\t<label for='mla-attachments-{$post_id}-{$key}'>\n";
885
- $row .= "\t\t<span title='" . __( 'Click to toggle', 'media-library-assistant' ) . "' class='alignleft' style='width: 99%; text-align: left;'>{$label}</span><br class='clear'>\n";
886
- $row .= "\t\t</label></th>\n";
887
- $row .= "\t\t<td class='field' style='width: 99%; display: none'>\n";
888
- $row .= "\t\t<div class='mla-taxonomy-field'>\n";
889
- $row .= "\t\t<div class='tagsdiv' id='mla-taxonomy-{$key}'>\n";
890
- $row .= "\t\t<div class='jaxtag'>\n";
891
- $row .= "\t\t<div class='nojs-tags hide-if-js'>\n";
892
- $row .= "\t\t<input name='attachments[{$post_id}][{$key}]' class='the-tags' id='mla-attachments-{$post_id}-{$key}' type='hidden' value='{$hidden_list}'>\n";
893
- $row .= "\t\t<input name='mla_tags[{$post_id}][{$key}]' class='server-tags' id='mla-tags-{$post_id}-{$key}' type='hidden' value='{$hidden_list}'>\n";
894
- $row .= "\t\t</div>\n"; // nojs-tags
895
- $row .= "\t\t<div class='ajaxtag'>\n";
896
- $row .= "\t\t<label class='screen-reader-text' for='new-tag-{$key}'>" . __( 'Tags', 'media-library-assistant' ) . "</label>\n";
897
- /* translators: %s: add new taxonomy label */
898
- $row .= "\t\t<div class='taghint'>" . sprintf( __( 'Add New %1$s', 'media-library-assistant' ), $label ) . "</div>\n";
899
- $row .= "\t\t<p>\n";
900
- $row .= "\t\t<input name='newtag[{$key}]' class='newtag form-input-tip' id='new-tag-{$key}' type='text' size='16' value='' autocomplete='off'>\n";
901
- $row .= "\t\t<input class='button tagadd' type='button' value='Add'>\n";
902
- $row .= "\t\t</p>\n";
903
- $row .= "\t\t</div>\n"; // ajaxtag
904
- $row .= "\t\t<p class='howto'>Separate tags with commas</p>\n";
905
- $row .= "\t\t</div>\n"; // jaxtag
906
- $row .= "\t\t<div class='tagchecklist'>\n";
907
-
908
- foreach ( $list as $index => $term ) {
909
- $row .= "\t\t<span><a class='ntdelbutton' id='post_tag-check-num-{$index}'>X</a>&nbsp;{$term}</span>\n";
910
- }
911
-
912
- $row .= "\t\t</div>\n"; // tagchecklist
913
- $row .= "\t\t</div>\n"; // tagsdiv
914
- $row .= "\t\t<p><a class='tagcloud-link' id='mla-link-{$key}' href='#titlediv'>" . __( 'Choose from the most used tags', 'media-library-assistant' ) . "</a></p>\n";
915
- $row .= "\t\t</div>\n"; // mla-taxonomy-field
916
- $row .= "\t\t</td>\n";
917
- $results[ $key ] = $row;
918
- } // checked
919
- } // flat
920
- } // is supported
921
- } // foreach
922
-
923
- /*
924
- * Any left-over requests are for unsupported taxonomies
925
- */
926
- foreach( $requested as $key ) {
927
- $row = "\t\t<tr class='compat-field-{$key} mla-taxonomy-row'>\n";
928
- $row .= "\t\t<th class='label' valign='top' scope='row'>\n";
929
- $row .= "\t\t<label for='mla-attachments-{$post_id}-{$key}'>\n";
930
- $row .= "\t\t<span title='" . __( 'Click to toggle', 'media-library-assistant' ) . "' class='alignleft'>{$label}</span><br class='clear'>\n";
931
- $row .= "\t\t</label></th>\n";
932
- $row .= "\t\t<td class='field' style='display: none'>\n";
933
- $row .= "\t\t<div class='mla-taxonomy-field'>\n";
934
- $row .= "\t\t<input name='attachments[{$post_id}][{$key}]' class='text' id='mla-attachments-{$post_id}-{$key}' type='hidden' value=''>\n";
935
- $row .= "\t\t<div id='taxonomy-{$key}' class='categorydiv'>\n";
936
- $row .= __( 'Not Supported', 'media-library-assistant' ) . ".\n";
937
- $row .= "\t\t</div>\n";
938
- $row .= "\t\t</div>\n";
939
- $row .= "\t\t</td>\n";
940
- $row .= "\t\t</tr>\n";
941
- $results[ $key ] = $row;
942
- }
943
-
944
- wp_send_json_success( apply_filters( 'mla_media_modal_end_fill_compat_fields', $results, $_REQUEST['query'], $requested, $post ) );
945
- } // mla_fill_compat_fields_action
946
-
947
- /**
948
- * Ajax handler for Media Manager "update compat-attachment-fields" queries
949
- *
950
- * Updates one (or more) supported taxonomy and returns updated checkbox or tag/term lists
951
- *
952
- * @since 1.80
953
- *
954
- * @return void passes array of results to wp_send_json_success() for JSON encoding and transmission
955
- */
956
- public static function mla_update_compat_fields_action() {
957
- global $post;
958
-
959
- if ( empty( $_REQUEST['id'] ) || ! $post_id = absint( $_REQUEST['id'] ) ) {
960
- wp_send_json_error();
961
- }
962
-
963
- if ( empty( $post ) ) {
964
- $post = get_post( $post_id ); // for filters and wp_popular_terms_checklist
965
- }
966
-
967
- do_action( 'mla_media_modal_begin_update_compat_fields', $post );
968
-
969
- $taxonomies = array();
970
- $results = array();
971
-
972
- foreach ( get_taxonomies( array ( 'show_ui' => true ), 'objects' ) as $key => $value ) {
973
- if ( isset( $_REQUEST[ $key ] ) && MLAOptions::mla_taxonomy_support( $key ) ) {
974
- $taxonomies[ $key ] = $value;
975
-
976
- if ( ! $use_checklist = $value->hierarchical ) {
977
- $use_checklist = MLAOptions::mla_taxonomy_support( $key, 'flat-checklist' );
978
- }
979
-
980
- if ( $value->hierarchical ) {
981
- $terms = array_map( 'absint', preg_split( '/,+/', $_REQUEST[ $key ] ) );
982
- } else {
983
- $terms = array_map( 'trim', preg_split( '/,+/', $_REQUEST[ $key ] ) );
984
- }
985
-
986
- $terms = apply_filters( 'mla_media_modal_update_compat_fields_terms', $terms, $key, $value, $post_id );
987
-
988
- if ( is_array( $terms ) ) {
989
- wp_set_object_terms( $post_id, $terms, $key, false );
990
- delete_transient( MLA_OPTION_PREFIX . 't_term_counts_' . $key );
991
- }
992
-
993
- if ( $use_checklist ) {
994
- ob_start();
995
- $popular_ids = wp_popular_terms_checklist( $key );
996
- $results[$key]["mla-{$key}-checklist-pop"] = ob_get_clean();
997
-
998
- ob_start();
999
-
1000
- if ( $value->hierarchical ) {
1001
- wp_terms_checklist( $post_id, array( 'taxonomy' => $key, 'popular_cats' => $popular_ids ) );
1002
- } else {
1003
- $checklist_walker = new MLA_Checklist_Walker;
1004
- wp_terms_checklist( $post_id, array( 'taxonomy' => $key, 'popular_cats' => $popular_ids, 'walker' => $checklist_walker ) );
1005
- }
1006
-
1007
- $results[$key]["mla-{$key}-checklist"] = ob_get_clean();
1008
- } else {
1009
- $terms = get_object_term_cache( $post_id, $key );
1010
-
1011
- if ( false === $terms ) {
1012
- $terms = wp_get_object_terms( $post_id, $key );
1013
- wp_cache_add( $post_id, $terms, $key . '_relationships' );
1014
- }
1015
-
1016
- if ( is_wp_error( $terms ) || empty( $terms ) ) {
1017
- $terms = array();
1018
- }
1019
-
1020
- $list = array();
1021
- $object_terms = array();
1022
- foreach ( $terms as $term ) {
1023
- $list[] = $term->name;
1024
- $object_terms[ $term->term_id ] = $term->name;
1025
- } // foreach $term
1026
-
1027
- sort( $list );
1028
- $hidden_list = join( ',', $list );
1029
-
1030
- $results[$key]["object-terms"] = $object_terms;
1031
- $results[$key]["mla-attachments-{$post_id}-{$key}"] = "\t\t<input name='attachments[{$post_id}][{$key}]' class='the-tags' id='mla-attachments-{$post_id}-{$key}' type='hidden' value='{$hidden_list}'>\n";
1032
- $results[$key]["mla-tags-{$post_id}-{$key}"] = "\t\t<input name='mla_tags[{$post_id}][{$key}]' class='server-tags' id='mla-tags-{$post_id}-{$key}' type='hidden' value='{$hidden_list}'>\n";
1033
- }
1034
- } // set and supported
1035
- } // foreach taxonomy
1036
-
1037
- wp_send_json_success( apply_filters( 'mla_media_modal_end_update_compat_fields', $results, $taxonomies, $post ) );
1038
- } // mla_update_compat_fields_action
1039
-
1040
- /**
1041
- * Ajax handler for Media Manager "Query Attachments" queries
1042
- *
1043
- * Adapted from wp_ajax_query_attachments in /wp-admin/includes/ajax-actions.php
1044
- *
1045
- * @since 1.20
1046
- *
1047
- * @return void passes array of post arrays to wp_send_json_success() for JSON encoding and transmission
1048
- */
1049
- public static function mla_query_attachments_action() {
1050
- if ( ! current_user_can( 'upload_files' ) ) {
1051
- wp_send_json_error();
1052
- }
1053
-
1054
- /*
1055
- * Pick out and clean up the query terms we can process
1056
- */
1057
- $raw_query = isset( $_REQUEST['query'] ) ? (array) $_REQUEST['query'] : array();
1058
- $query = array_intersect_key( $raw_query, array_flip( array(
1059
- 'order', 'orderby', 'posts_per_page', 'paged', 'post_mime_type',
1060
- 'post_parent', 'post__in', 'post__not_in',
1061
- 'mla_filter_month', 'mla_filter_term', 'mla_terms_search',
1062
- 'mla_search_value', 's', 'mla_search_fields', 'mla_search_connector'
1063
- ) ) );
1064
-
1065
- $query = apply_filters( 'mla_media_modal_query_initial_terms', $query, $raw_query );
1066
-
1067
- if ( isset( $query['post_mime_type'] ) ) {
1068
- if ( 'detached' == $query['post_mime_type'] ) {
1069
- $query['detached'] = '1';
1070
- unset( $query['post_mime_type'] );
1071
- } elseif ( 'attached' == $query['post_mime_type'] ) {
1072
- $query['detached'] = '0';
1073
- unset( $query['post_mime_type'] );
1074
- } elseif ( 'trash' == $query['post_mime_type'] ) {
1075
- $query['status'] = 'trash';
1076
- unset( $query['post_mime_type'] );
1077
- } else {
1078
- $view = $query['post_mime_type'];
1079
- unset( $query['post_mime_type'] );
1080
- $query = array_merge( $query, MLAMime::mla_prepare_view_query( 'view', $view ) );
1081
- }
1082
- }
1083
-
1084
- /*
1085
- * Convert mla_filter_month back to the WordPress "m" parameter
1086
- */
1087
- if ( isset( $query['mla_filter_month'] ) ) {
1088
- if ( '0' != $query['mla_filter_month'] ) {
1089
- $query['m'] = $query['mla_filter_month'];
1090
- }
1091
-
1092
- unset( $query['mla_filter_month'] );
1093
- }
1094
-
1095
- /*
1096
- * Process the enhanced search box OR fix up the default search box
1097
- */
1098
- if ( isset( $query['mla_search_value'] ) ) {
1099
- if ( ! empty( $query['mla_search_value'] ) ) {
1100
- $query['s'] = $query['mla_search_value'];
1101
- }
1102
-
1103
- unset( $query['mla_search_value'] );
1104
- }
1105
-
1106
- if ( isset( $query['posts_per_page'] ) ) {
1107
- $count = $query['posts_per_page'];
1108
- $offset = $count * (isset( $query['paged'] ) ? $query['paged'] - 1 : 0);
1109
- } else {
1110
- $count = 0;
1111
- $offset = 0;
1112
- }
1113
-
1114
- /*
1115
- * Check for sorting override
1116
- */
1117
- $option = MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_MODAL_ORDERBY );
1118
- if ( 'default' != $option ) {
1119
- /*
1120
- * Make sure the current orderby choice still exists or revert to default.
1121
- */
1122
- $default_orderby = array_merge( array( 'none' => array('none',false) ), MLA_List_Table::mla_get_sortable_columns( ) );
1123
- $found_current = false;
1124
- foreach ($default_orderby as $key => $value ) {
1125
- if ( $option == $value[0] ) {
1126
- $found_current = true;
1127
- break;
1128
- }
1129
- }
1130
-
1131
- if ( ! $found_current ) {
1132
- MLAOptions::mla_delete_option( MLAOptions::MLA_DEFAULT_ORDERBY );
1133
- $option = MLAOptions::mla_get_option( MLAOptions::MLA_DEFAULT_ORDERBY );
1134
- }
1135
-
1136
- $query['orderby'] = $option;
1137
- }
1138
-
1139
- $option = MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_MODAL_ORDER );
1140
- if ( 'default' != $option ) {
1141
- $query['order'] = $option;
1142
- }
1143
-
1144
- $query['post_type'] = 'attachment';
1145
-
1146
- if ( empty( $query['status'] ) ) {
1147
- $query['post_status'] = 'inherit';
1148
- if ( current_user_can( get_post_type_object( 'attachment' )->cap->read_private_posts ) ) {
1149
- $query['post_status'] .= ',private';
1150
- }
1151
- }
1152
-
1153
- $query = apply_filters( 'mla_media_modal_query_filtered_terms', $query, $raw_query );
1154
-
1155
- $query = MLAData::mla_query_media_modal_items( $query, $offset, $count );
1156
- $posts = array_map( 'wp_prepare_attachment_for_js', $query->posts );
1157
- $posts = array_filter( $posts );
1158
-
1159
- wp_send_json_success( $posts );
1160
- }
1161
-
1162
  /**
1163
  * Add the styles and scripts for the "Search Terms" popup modal window,
1164
  * but only once per page load
@@ -1182,7 +502,7 @@ class MLAModal {
1182
 
1183
  wp_enqueue_style( MLA::STYLESHEET_SLUG . '-terms-search' );
1184
 
1185
- wp_enqueue_script( MLA::JAVASCRIPT_INLINE_EDIT_SLUG . '-terms-search', MLA_PLUGIN_URL . "js/mla-terms-search-scripts{$suffix}.js",
1186
  array( 'jquery' ), MLA::CURRENT_MLA_VERSION, false );
1187
 
1188
  $script_variables = array(
@@ -1198,7 +518,7 @@ class MLAModal {
1198
  $script_variables['useSpinnerClass'] = true;
1199
  }
1200
 
1201
- wp_localize_script( MLA::JAVASCRIPT_INLINE_EDIT_SLUG . '-terms-search', self::JAVASCRIPT_TERMS_SEARCH_OBJECT, $script_variables );
1202
 
1203
  /*
1204
  * Insert the hidden form for the Search Terms popup window
@@ -1254,7 +574,7 @@ class MLAModal {
1254
 
1255
  $taxonomies = array();
1256
  foreach( get_object_taxonomies( 'attachment', 'objects' ) as $taxonomy ) {
1257
- if ( MLAOptions::mla_taxonomy_support( $taxonomy->name, 'support' ) ) {
1258
  $taxonomies[] = $taxonomy;
1259
  }
1260
  }
@@ -1269,7 +589,7 @@ class MLAModal {
1269
  $taxonomy_list = '';
1270
  foreach ( $taxonomies as $taxonomy ) {
1271
  $page_values = array(
1272
- 'taxonomy_checked' => MLAOptions::mla_taxonomy_support( $taxonomy->name, 'term-search' ) ? 'checked="checked"' : '',
1273
  'taxonomy_slug' => $taxonomy->name,
1274
  'taxonomy_label' => esc_attr( $taxonomy->label ),
1275
  );
@@ -1295,9 +615,9 @@ class MLAModal {
1295
  }
1296
 
1297
  $page_values = array(
1298
- 'mla_terms_search_url' => esc_url( add_query_arg( array_merge( MLA_List_Table::mla_submenu_arguments( false ), array( 'page' => MLA::ADMIN_PAGE_SLUG ) ), admin_url( 'upload.php' ) ) ),
1299
  'mla_terms_search_action' => MLA::MLA_ADMIN_TERMS_SEARCH,
1300
- 'wpnonce' => wp_nonce_field( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME, true, false ),
1301
  'mla_terms_search_div' => $terms_search_tpl,
1302
  );
1303
  $terms_search_tpl = MLAData::mla_parse_template( $page_template_array['mla-terms-search-form'], $page_values );
49
  */
50
  const JAVASCRIPT_TERMS_SEARCH_OBJECT = 'mla_terms_search_vars';
51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  /**
53
  * Initialization function, similar to __construct()
54
  *
70
  *
71
  * Finally wp_enqueue_media() contains:
72
  * do_action( 'wp_enqueue_media' );
 
 
 
 
 
 
 
 
 
 
 
73
  */
74
 
75
+ if ( ( ( 'checked' == MLACore::mla_get_option( MLACore::MLA_MEDIA_MODAL_TOOLBAR ) ) || ( 'checked' == MLACore::mla_get_option( MLACore::MLA_MEDIA_GRID_TOOLBAR ) ) ) ) {
 
 
 
76
  add_filter( 'media_view_settings', 'MLAModal::mla_media_view_settings_filter', 10, 2 );
77
  add_filter( 'media_view_strings', 'MLAModal::mla_media_view_strings_filter', 10, 2 );
78
  add_action( 'wp_enqueue_media', 'MLAModal::mla_wp_enqueue_media_action', 10, 0 );
79
  add_action( 'print_media_templates', 'MLAModal::mla_print_media_templates_action', 10, 0 );
80
  add_action( 'admin_init', 'MLAModal::mla_admin_init_action' );
 
 
 
 
81
  } // Media Modal support enabled
82
  }
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  /**
85
  * Display a monthly dropdown for filtering items
86
  *
172
  'state' => 'initial',
173
  'comma' => ',',
174
  'ajaxNonce' => '',
175
+ 'ajaxFillCompatAction' => MLACore::JAVASCRIPT_FILL_COMPAT_ACTION,
176
+ 'ajaxQueryAttachmentsAction' => MLACore::JAVASCRIPT_QUERY_ATTACHMENTS_ACTION,
177
+ 'ajaxUpdateCompatAction' => MLACore::JAVASCRIPT_UPDATE_COMPAT_ACTION,
178
  'enableDetailsCategory' => false,
179
  'enableDetailsTag' => false,
180
  'enableMimeTypes' => false,
229
  }
230
  }
231
 
232
+ $default_types = MLACore::mla_get_option( MLACore::MLA_POST_MIME_TYPES, true );
233
  self::$mla_media_modal_settings['comma'] = _x( ',', 'tag_delimiter', 'media-library-assistant' );
234
+ self::$mla_media_modal_settings['ajaxNonce'] = wp_create_nonce( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
235
  self::$mla_media_modal_settings['allMimeTypes'] = MLAMime::mla_pluck_table_views();
236
+ self::$mla_media_modal_settings['allMimeTypes']['detached'] = $default_types['detached']['plural'];
237
+ self::$mla_media_modal_settings['allMimeTypes']['attached'] = $default_types['attached']['plural'];
238
 
239
  /*
240
  * Trash items are allowed in the Media/Library Grid view
241
  */
242
  if ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) {
243
+ self::$mla_media_modal_settings['allMimeTypes']['trash'] = $default_types['trash']['plural'];
244
  }
245
 
246
  self::$mla_media_modal_settings['months'] = self::_months_dropdown('attachment');
247
 
248
+ self::$mla_media_modal_settings['termsTaxonomy'] = MLACore::mla_taxonomy_support('', 'filter');
249
  $terms_options = self::_terms_options( MLA_List_Table::mla_get_taxonomy_filter_dropdown() );
250
  self::$mla_media_modal_settings['termsClass'] = $terms_options['class'];
251
  self::$mla_media_modal_settings['termsValue'] = $terms_options['value'];
256
  self::$mla_media_modal_settings['termsIndent'] = '-';
257
  }
258
 
259
+ self::$mla_media_modal_settings['enableMediaGrid'] = ( 'checked' == MLACore::mla_get_option( MLACore::MLA_MEDIA_GRID_TOOLBAR ) );
260
+ self::$mla_media_modal_settings['enableMediaModal'] = ( 'checked' == MLACore::mla_get_option( MLACore::MLA_MEDIA_MODAL_TOOLBAR ) );
261
+ self::$mla_media_modal_settings['enableDetailsCategory'] = ( 'checked' == MLACore::mla_get_option( MLACore::MLA_MEDIA_MODAL_DETAILS_CATEGORY_METABOX ) );
262
+ self::$mla_media_modal_settings['enableDetailsTag'] = ( 'checked' == MLACore::mla_get_option( MLACore::MLA_MEDIA_MODAL_DETAILS_TAG_METABOX ) );
263
+ self::$mla_media_modal_settings['enableMimeTypes'] = ( 'checked' == MLACore::mla_get_option( MLACore::MLA_MEDIA_MODAL_MIMETYPES ) );
264
+ self::$mla_media_modal_settings['enableMonthsDropdown'] = ( 'checked' == MLACore::mla_get_option( MLACore::MLA_MEDIA_MODAL_MONTHS ) );
265
+ self::$mla_media_modal_settings['enableSearchBox'] = ( 'checked' == MLACore::mla_get_option( MLACore::MLA_MEDIA_MODAL_SEARCHBOX ) );
266
+ self::$mla_media_modal_settings['enableSearchBoxControls'] = ( 'checked' == MLACore::mla_get_option( MLACore::MLA_MEDIA_MODAL_SEARCHBOX_CONTROLS ) );
267
 
268
+ $supported_taxonomies = MLACore::mla_supported_taxonomies('support');
269
+ self::$mla_media_modal_settings['enableTermsDropdown'] = ( 'checked' == MLACore::mla_get_option( MLACore::MLA_MEDIA_MODAL_TERMS ) ) && ( ! empty( $supported_taxonomies ) );
270
+ self::$mla_media_modal_settings['enableTermsAutofill'] = ( 'checked' == MLACore::mla_get_option( MLACore::MLA_MEDIA_MODAL_DETAILS_AUTOFILL ) ) && ( ! empty( $supported_taxonomies ) );
271
 
272
+ $supported_taxonomies = MLACore::mla_supported_taxonomies('term-search');
273
+ self::$mla_media_modal_settings['enableTermsSearch'] = ( 'checked' == MLACore::mla_get_option( MLACore::MLA_MEDIA_MODAL_TERMS_SEARCH ) ) && ( ! empty( $supported_taxonomies ) );
274
 
275
  /*
276
  * Compile a list of the enhanced taxonomies
277
  */
278
  self::$mla_media_modal_settings['enhancedTaxonomies'] = array();
279
  foreach ( get_taxonomies( array ( 'show_ui' => true ), 'objects' ) as $key => $value ) {
280
+ if ( MLACore::mla_taxonomy_support( $key ) ) {
281
  if ( ! $use_checklist = $value->hierarchical ) {
282
+ $use_checklist = MLACore::mla_taxonomy_support( $key, 'flat-checklist' );
283
  }
284
 
285
  /*
286
  * Make sure the appropriate MMMW Enhancement option has been checked
287
  */
288
  if ( $use_checklist ) {
289
+ if ( 'checked' === MLACore::mla_get_option( MLACore::MLA_MEDIA_MODAL_DETAILS_CATEGORY_METABOX ) ) {
290
  self::$mla_media_modal_settings['enhancedTaxonomies'][] = $key;
291
  }
292
  } else {
293
+ if ( 'checked' === MLACore::mla_get_option( MLACore::MLA_MEDIA_MODAL_DETAILS_TAG_METABOX ) ) {
294
  self::$mla_media_modal_settings['enhancedTaxonomies'][] = $key;
295
  }
296
  }
300
  /*
301
  * Set and filter the initial values for toolbar controls
302
  */
303
+ $search_defaults = MLACore::mla_get_option( MLACore::MLA_SEARCH_MEDIA_FILTER_DEFAULTS );
304
  $initial_values = array(
305
  'filterMime' => 'all',
306
  'filterUploaded' => 'all',
315
  $initial_values = apply_filters( 'mla_media_modal_initial_filters', $initial_values, $post );
316
 
317
  // No supported taxonomies implies no "terms" search
318
+ $supported_taxonomies = MLACore::mla_supported_taxonomies('support');
319
  if ( empty( $supported_taxonomies ) ) {
320
  $index = array_search( 'terms', $initial_values['searchFields'] );
321
  if ( false !== $index ) {
356
  $mla_strings = array(
357
  'searchBoxPlaceholder' => __( 'Search Box', 'media-library-assistant' ),
358
  'loadingText' => __( 'Loading...', 'media-library-assistant' ),
359
+ 'searchBoxControlsStyle' => ( 'checked' == MLACore::mla_get_option( MLACore::MLA_MEDIA_MODAL_SEARCHBOX_CONTROLS ) ) ? 'display: inline;' : 'display: none;',
360
  );
361
 
362
  $strings = array_merge( $strings, array( 'mla_strings' => $mla_strings ) );
382
 
383
  if ( is_object( $screen ) ) {
384
  if ( 'upload' == $screen->base ) {
385
+ if ( 'checked' != MLACore::mla_get_option( MLACore::MLA_MEDIA_GRID_TOOLBAR ) ) {
386
  return;
387
  }
388
+ } elseif ( 'checked' != MLACore::mla_get_option( MLACore::MLA_MEDIA_MODAL_TOOLBAR ) ) {
389
  return;
390
  }
391
  }
403
 
404
  wp_enqueue_script( self::JAVASCRIPT_MEDIA_MODAL_SLUG, MLA_PLUGIN_URL . "js/mla-media-modal-scripts{$suffix}.js", array( 'media-views', 'wp-lists', 'suggest' ), MLA::CURRENT_MLA_VERSION, false );
405
 
406
+ if ( 'checked' == MLACore::mla_get_option( MLACore::MLA_MEDIA_MODAL_TERMS_SEARCH ) ) {
407
  MLAModal::mla_add_terms_search_scripts();
408
  }
409
  } // mla_wp_enqueue_media_action
424
  $screen = get_current_screen();
425
 
426
  if ( 'upload' == $screen->base ) {
427
+ if ( 'checked' != MLACore::mla_get_option( MLACore::MLA_MEDIA_GRID_TOOLBAR ) ) {
428
  return;
429
  }
430
+ } elseif ( 'checked' != MLACore::mla_get_option( MLACore::MLA_MEDIA_MODAL_TOOLBAR ) ) {
431
  return;
432
  }
433
  } else {
443
  } // mla_print_media_templates_action
444
 
445
  /**
446
+ * Clean up the 'save-attachment-compat' values, removing taxonomy updates MLA already handled
 
 
 
447
  *
448
  * @since 1.20
449
  *
456
  */
457
  $enhanced_taxonomies = array();
458
  foreach ( get_taxonomies( array ( 'show_ui' => true ), 'objects' ) as $key => $value ) {
459
+ if ( MLACore::mla_taxonomy_support( $key ) ) {
460
  if ( ! $use_checklist = $value->hierarchical ) {
461
+ $use_checklist = MLACore::mla_taxonomy_support( $key, 'flat-checklist' );
462
  }
463
 
464
  if ( $use_checklist ) {
465
+ if ( 'checked' == MLACore::mla_get_option( MLACore::MLA_MEDIA_MODAL_DETAILS_CATEGORY_METABOX ) ) {
466
  $enhanced_taxonomies[] = $key;
467
 
468
  if ( class_exists( 'Media_Categories' ) && is_array( Media_Categories::$instances ) ) {
477
  } // use_checklist
478
  } // supported
479
  } // foreach taxonomy
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
480
  } // mla_admin_init_action
481
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
482
  /**
483
  * Add the styles and scripts for the "Search Terms" popup modal window,
484
  * but only once per page load
502
 
503
  wp_enqueue_style( MLA::STYLESHEET_SLUG . '-terms-search' );
504
 
505
+ wp_enqueue_script( MLACore::JAVASCRIPT_INLINE_EDIT_SLUG . '-terms-search', MLA_PLUGIN_URL . "js/mla-terms-search-scripts{$suffix}.js",
506
  array( 'jquery' ), MLA::CURRENT_MLA_VERSION, false );
507
 
508
  $script_variables = array(
518
  $script_variables['useSpinnerClass'] = true;
519
  }
520
 
521
+ wp_localize_script( MLACore::JAVASCRIPT_INLINE_EDIT_SLUG . '-terms-search', self::JAVASCRIPT_TERMS_SEARCH_OBJECT, $script_variables );
522
 
523
  /*
524
  * Insert the hidden form for the Search Terms popup window
574
 
575
  $taxonomies = array();
576
  foreach( get_object_taxonomies( 'attachment', 'objects' ) as $taxonomy ) {
577
+ if ( MLACore::mla_taxonomy_support( $taxonomy->name, 'support' ) ) {
578
  $taxonomies[] = $taxonomy;
579
  }
580
  }
589
  $taxonomy_list = '';
590
  foreach ( $taxonomies as $taxonomy ) {
591
  $page_values = array(
592
+ 'taxonomy_checked' => MLACore::mla_taxonomy_support( $taxonomy->name, 'term-search' ) ? 'checked="checked"' : '',
593
  'taxonomy_slug' => $taxonomy->name,
594
  'taxonomy_label' => esc_attr( $taxonomy->label ),
595
  );
615
  }
616
 
617
  $page_values = array(
618
+ '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' ) ) ),
619
  'mla_terms_search_action' => MLA::MLA_ADMIN_TERMS_SEARCH,
620
+ 'wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
621
  'mla_terms_search_div' => $terms_search_tpl,
622
  );
623
  $terms_search_tpl = MLAData::mla_parse_template( $page_template_array['mla-terms-search-form'], $page_values );
includes/class-mla-mime-types.php CHANGED
@@ -26,7 +26,7 @@ class MLAMime {
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 );
28
 
29
- if ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_ENABLE_UPLOAD_MIMES ) ) {
30
  if ( function_exists('wp_get_mime_types') ) {
31
  add_filter( 'mime_types', 'MLAMime::mla_mime_types_filter', 0x7FFFFFFF, 1 );
32
  }
@@ -34,7 +34,7 @@ class MLAMime {
34
  add_filter( 'upload_mimes', 'MLAMime::mla_upload_mimes_filter', 0x7FFFFFFF, 2 );
35
  }
36
 
37
- if ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_ENABLE_POST_MIME_TYPES ) ) {
38
  add_filter( 'post_mime_types', 'MLAMime::mla_post_mime_types_filter', 0x7FFFFFFF, 1 );
39
  }
40
 
@@ -126,7 +126,7 @@ class MLAMime {
126
  $items = self::mla_query_upload_items( array( 'mla_upload_view' => 'active' ), 0, 0 );
127
  $pairs = array();
128
  foreach ( $items as $value )
129
- if ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_ENABLE_MLA_ICONS ) ) {
130
  $pairs[ $value->slug ] = $value->icon_type;
131
  } else {
132
  $pairs[ $value->slug ] = $value->wp_icon_type;
@@ -393,7 +393,7 @@ class MLAMime {
393
  public static function mla_icon_dir_filter( $path ) {
394
  global $wp_filter;
395
 
396
- if ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_ENABLE_MLA_ICONS ) ) {
397
  return MLA_PLUGIN_PATH . 'images/crystal';
398
  }
399
 
@@ -415,7 +415,7 @@ class MLAMime {
415
  public static function mla_icon_dir_uri_filter( $uri ) {
416
  global $wp_filter;
417
 
418
- if ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_ENABLE_MLA_ICONS ) ) {
419
  return MLA_PLUGIN_URL . 'images/crystal';
420
  }
421
 
@@ -437,7 +437,7 @@ class MLAMime {
437
  public static function mla_icon_dirs_filter( $path_uri_array ) {
438
  global $wp_filter;
439
 
440
- if ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_ENABLE_MLA_ICONS ) ) {
441
  $path_uri_array [ MLA_PLUGIN_PATH . 'images/crystal' ] = MLA_PLUGIN_URL . 'images/crystal';
442
  }
443
 
@@ -730,7 +730,7 @@ class MLAMime {
730
  /*
731
  * Start with MLA standard types
732
  */
733
- $mla_types = MLAOptions::mla_get_option( MLAOptions::MLA_POST_MIME_TYPES, true );
734
  if ( ! is_array( $mla_types ) ) {
735
  $mla_types = array ();
736
  }
@@ -740,7 +740,7 @@ class MLAMime {
740
  * filter-enhanced extensions, retain anything new as a custom type.
741
  * Otherwise, add the current MLA custom types.
742
  */
743
- $custom_types = MLAOptions::mla_get_option( MLAOptions::MLA_POST_MIME_TYPES, false, true );
744
 
745
  if ( is_array( $custom_types ) ) {
746
  $mla_types = array_merge( $mla_types, $custom_types );
@@ -791,7 +791,7 @@ class MLAMime {
791
  private static function _put_post_mime_templates() {
792
  $mla_post_mimes = array ();
793
 
794
- $mla_types = MLAOptions::mla_get_option( MLAOptions::MLA_POST_MIME_TYPES, true );
795
 
796
  foreach ( self::$mla_post_mime_templates as $slug => $value ) {
797
  unset( $value['post_ID'] );
@@ -802,13 +802,15 @@ class MLAMime {
802
  $mla_post_mimes[ $slug ] = $value;
803
  }
804
 
805
- MLAOptions::mla_update_option( MLAOptions::MLA_POST_MIME_TYPES, $mla_post_mimes );
806
  return true;
807
  }
808
 
809
  /**
810
  * Convert a Library View/Post MIME Type specification to WP_Query parameters
811
  *
 
 
812
  * @since 1.40
813
  *
814
  * @param string View slug, unique identifier
@@ -817,50 +819,14 @@ class MLAMime {
817
  * @return array post_mime_type specification or custom field query
818
  */
819
  public static function mla_prepare_view_query( $slug, $specification ) {
820
- $query = array ( );
821
- $specification = self::mla_parse_view_specification( $specification );
822
- if ( 'mime' == $specification['prefix'] ) {
823
- $query['post_mime_type'] = $specification['value'];
824
- } else {
825
- $meta_query = array( 'slug' => $slug , 'relation' => 'OR', 'patterns' => array () );
826
- switch( $specification['option'] ) {
827
- case 'match':
828
- $patterns = array_map( 'trim', explode( ',', $specification['value'] ) );
829
- foreach ( (array) $patterns as $pattern ) {
830
- $pattern = preg_replace( '/\*+/', '%', $pattern );
831
- if ( false !== strpos( $pattern, '%' ) ) {
832
- /*
833
- * Preserve the pattern - it will be used in the "where" filter
834
- */
835
- $meta_query['patterns'][] = $pattern;
836
- $meta_query[] = array( 'key' => $specification['name'], 'value' => $pattern, 'compare' => 'LIKE' );
837
- } else {
838
- $meta_query[] = array( 'key' => $specification['name'], 'value' => $pattern, 'compare' => '=' );
839
- }
840
- } // foreach pattern
841
-
842
- if ( empty( $meta_query['patterns'] ) ) {
843
- unset( $meta_query['patterns'] );
844
- }
845
-
846
- break;
847
- case 'null':
848
- $meta_query['key'] = $specification['name'];
849
- $meta_query['value'] = 'NULL';
850
- break;
851
- default: // '', 'any'
852
- $meta_query[] = array( 'key' => $specification['name'], 'value' => NULL, 'compare' => '!=' );
853
- }
854
-
855
- $query['meta_query'] = $meta_query;
856
- } // custom field specification
857
-
858
- return $query;
859
  }
860
 
861
  /**
862
  * Analyze a Library View/Post MIME Type specification, returning an array of the placeholders it contains
863
  *
 
 
864
  * @since 1.40
865
  *
866
  * @param string|array A specification, e.g., "custom:Field,null" or "audio,application/vnd.*ms*"
@@ -868,65 +834,7 @@ class MLAMime {
868
  * @return array ( ['prefix'] => string, ['name'] => string, ['value'] => string, ['option'] => string, optional ['error'] => string )
869
  */
870
  public static function mla_parse_view_specification( $specification ) {
871
- if ( is_array( $specification ) ) {
872
- $specification = @implode( ',', $specification );
873
- }
874
-
875
- $result = array( 'prefix' => '', 'name' => '', 'value' => '', 'option' => '' );
876
- $match_count = preg_match( '/^(.+):(.+)/', $specification, $matches );
877
- if ( 1 == $match_count ) {
878
- $result['prefix'] = trim( strtolower( $matches[1] ) );
879
- $tail = $matches[2];
880
-
881
- $match_count = preg_match( '/([^,=]+)((,|=)(.*))$/', $tail, $matches );
882
- if ( 1 == $match_count ) {
883
- $result['name'] = $matches[1];
884
-
885
- if ( ',' == $matches[3] ) {
886
- $result['option'] = trim( strtolower( $matches[4] ));
887
- } else {
888
- if ( empty( $matches[4] ) ) {
889
- $result['option'] = 'null';
890
- } elseif ( '*' == $matches[4] ) {
891
- $result['option'] = 'any';
892
- } else {
893
- $result['option'] = 'match';
894
- $result['value'] = $matches[4];
895
- }
896
- }
897
- } else {
898
- $result['option'] = 'any';
899
- $result['name'] = $tail;
900
- }
901
- } else {
902
- $result['prefix'] = 'mime';
903
- $result['value'] = $specification;
904
- }
905
-
906
- /*
907
- * Validate the results
908
- */
909
- if ( 'mime' == $result['prefix'] ) {
910
- $mime_types = array_map( 'trim', explode( ',', $result['value'] ) );
911
- foreach ( (array) $mime_types as $raw_mime_type ) {
912
- $no_wildcards = str_replace( '*', 'X', $raw_mime_type );
913
- $clean_mime_type = sanitize_mime_type( $no_wildcards );
914
- if ( $clean_mime_type != $no_wildcards ) {
915
- /* translators: 1: ERROR tag 2: raw_mime_type */
916
- $result['error'] = '<br>' . sprintf( __( '%1$s: Bad specification part "%2$s"', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $raw_mime_type );
917
- }
918
- } // foreach
919
- } elseif ( 'custom' == $result['prefix'] ) {
920
- if ( ! in_array( $result['option'], array( '', 'any', 'match', 'null' ) ) ) {
921
- /* translators: 1: ERROR tag 2: option, e.g., any, match, null */
922
- $result['error'] = '<br>' . sprintf( __( '%1$s: Bad specification option "%2$s"', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $specification['option'] );
923
- }
924
- } else {
925
- /* translators: 1: ERROR tag 2: prefix, e.g., custom */
926
- $result['error'] = '<br>' . sprintf( __( '%1$s: Bad specification prefix "%2$s"', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $specification['prefix'] );
927
- }
928
-
929
- return $result;
930
  }
931
 
932
  /**
@@ -975,7 +883,7 @@ class MLAMime {
975
  * Validate specification, if present
976
  */
977
  if ( !empty( $request['specification'] ) ) {
978
- $specification = self::mla_parse_view_specification( $request['specification'] );
979
  if ( isset( $specification['error'] ) ) {
980
  $errors .= $specification['error'];
981
  }
@@ -1076,7 +984,7 @@ class MLAMime {
1076
  }
1077
 
1078
  if ( !empty( $specification ) ) {
1079
- $result = self::mla_parse_view_specification( $request['specification'] );
1080
  if ( isset( $result['error'] ) ) {
1081
  $errors .= $result['error'];
1082
  }
@@ -1765,7 +1673,7 @@ class MLAMime {
1765
  * filter-enhanced extensions, retain anything new as a custom type.
1766
  */
1767
  $custom_types = array();
1768
- $mla_upload_mimes = MLAOptions::mla_get_option( MLAOptions::MLA_UPLOAD_MIMES );
1769
  if ( is_array( $mla_upload_mimes ) ) {
1770
  $first_time_called = false;
1771
  $custom_types = $mla_upload_mimes['custom'];
@@ -1837,7 +1745,7 @@ class MLAMime {
1837
  'core_icon_type' => self::mla_get_core_icon_type( $array[0] )
1838
  );
1839
 
1840
- if ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_ENABLE_MLA_ICONS ) ) {
1841
  self::$mla_upload_mime_templates[ $key ]['icon_type'] = self::$mla_upload_mime_templates[ $key ]['mla_icon_type'];
1842
  }
1843
  }
@@ -1886,7 +1794,7 @@ class MLAMime {
1886
  'core_icon_type' => $core_icon_type
1887
  );
1888
 
1889
- if ( 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_ENABLE_MLA_ICONS ) ) {
1890
  self::$mla_upload_mime_templates[ $key ]['icon_type'] = self::$mla_upload_mime_templates[ $key ]['mla_icon_type'];
1891
  }
1892
  }
@@ -1979,7 +1887,7 @@ class MLAMime {
1979
  }
1980
  }
1981
 
1982
- MLAOptions::mla_update_option( MLAOptions::MLA_UPLOAD_MIMES, $mla_upload_mimes );
1983
  return true;
1984
  }
1985
 
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 );
28
 
29
+ if ( 'checked' == MLACore::mla_get_option( MLACore::MLA_ENABLE_UPLOAD_MIMES ) ) {
30
  if ( function_exists('wp_get_mime_types') ) {
31
  add_filter( 'mime_types', 'MLAMime::mla_mime_types_filter', 0x7FFFFFFF, 1 );
32
  }
34
  add_filter( 'upload_mimes', 'MLAMime::mla_upload_mimes_filter', 0x7FFFFFFF, 2 );
35
  }
36
 
37
+ if ( 'checked' == MLACore::mla_get_option( MLACore::MLA_ENABLE_POST_MIME_TYPES ) ) {
38
  add_filter( 'post_mime_types', 'MLAMime::mla_post_mime_types_filter', 0x7FFFFFFF, 1 );
39
  }
40
 
126
  $items = self::mla_query_upload_items( array( 'mla_upload_view' => 'active' ), 0, 0 );
127
  $pairs = array();
128
  foreach ( $items as $value )
129
+ if ( 'checked' == MLACore::mla_get_option( MLACore::MLA_ENABLE_MLA_ICONS ) ) {
130
  $pairs[ $value->slug ] = $value->icon_type;
131
  } else {
132
  $pairs[ $value->slug ] = $value->wp_icon_type;
393
  public static function mla_icon_dir_filter( $path ) {
394
  global $wp_filter;
395
 
396
+ if ( 'checked' == MLACore::mla_get_option( MLACore::MLA_ENABLE_MLA_ICONS ) ) {
397
  return MLA_PLUGIN_PATH . 'images/crystal';
398
  }
399
 
415
  public static function mla_icon_dir_uri_filter( $uri ) {
416
  global $wp_filter;
417
 
418
+ if ( 'checked' == MLACore::mla_get_option( MLACore::MLA_ENABLE_MLA_ICONS ) ) {
419
  return MLA_PLUGIN_URL . 'images/crystal';
420
  }
421
 
437
  public static function mla_icon_dirs_filter( $path_uri_array ) {
438
  global $wp_filter;
439
 
440
+ if ( 'checked' == MLACore::mla_get_option( MLACore::MLA_ENABLE_MLA_ICONS ) ) {
441
  $path_uri_array [ MLA_PLUGIN_PATH . 'images/crystal' ] = MLA_PLUGIN_URL . 'images/crystal';
442
  }
443
 
730
  /*
731
  * Start with MLA standard types
732
  */
733
+ $mla_types = MLACore::mla_get_option( MLACore::MLA_POST_MIME_TYPES, true );
734
  if ( ! is_array( $mla_types ) ) {
735
  $mla_types = array ();
736
  }
740
  * filter-enhanced extensions, retain anything new as a custom type.
741
  * Otherwise, add the current MLA custom types.
742
  */
743
+ $custom_types = MLACore::mla_get_option( MLACore::MLA_POST_MIME_TYPES, false, true );
744
 
745
  if ( is_array( $custom_types ) ) {
746
  $mla_types = array_merge( $mla_types, $custom_types );
791
  private static function _put_post_mime_templates() {
792
  $mla_post_mimes = array ();
793
 
794
+ $mla_types = MLACore::mla_get_option( MLACore::MLA_POST_MIME_TYPES, true );
795
 
796
  foreach ( self::$mla_post_mime_templates as $slug => $value ) {
797
  unset( $value['post_ID'] );
802
  $mla_post_mimes[ $slug ] = $value;
803
  }
804
 
805
+ MLACore::mla_update_option( MLACore::MLA_POST_MIME_TYPES, $mla_post_mimes );
806
  return true;
807
  }
808
 
809
  /**
810
  * Convert a Library View/Post MIME Type specification to WP_Query parameters
811
  *
812
+ * Compatibility shim for MLACore::mla_prepare_view_query
813
+ *
814
  * @since 1.40
815
  *
816
  * @param string View slug, unique identifier
819
  * @return array post_mime_type specification or custom field query
820
  */
821
  public static function mla_prepare_view_query( $slug, $specification ) {
822
+ return MLACore::mla_prepare_view_query( $slug, $specification );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
823
  }
824
 
825
  /**
826
  * Analyze a Library View/Post MIME Type specification, returning an array of the placeholders it contains
827
  *
828
+ * Compatibility shim for MLACore::mla_parse_view_specification
829
+ *
830
  * @since 1.40
831
  *
832
  * @param string|array A specification, e.g., "custom:Field,null" or "audio,application/vnd.*ms*"
834
  * @return array ( ['prefix'] => string, ['name'] => string, ['value'] => string, ['option'] => string, optional ['error'] => string )
835
  */
836
  public static function mla_parse_view_specification( $specification ) {
837
+ return MLACore::mla_parse_view_specification( $specification );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
838
  }
839
 
840
  /**
883
  * Validate specification, if present
884
  */
885
  if ( !empty( $request['specification'] ) ) {
886
+ $specification = MLACore::mla_parse_view_specification( $request['specification'] );
887
  if ( isset( $specification['error'] ) ) {
888
  $errors .= $specification['error'];
889
  }
984
  }
985
 
986
  if ( !empty( $specification ) ) {
987
+ $result = MLACore::mla_parse_view_specification( $request['specification'] );
988
  if ( isset( $result['error'] ) ) {
989
  $errors .= $result['error'];
990
  }
1673
  * filter-enhanced extensions, retain anything new as a custom type.
1674
  */
1675
  $custom_types = array();
1676
+ $mla_upload_mimes = MLACore::mla_get_option( MLACore::MLA_UPLOAD_MIMES );
1677
  if ( is_array( $mla_upload_mimes ) ) {
1678
  $first_time_called = false;
1679
  $custom_types = $mla_upload_mimes['custom'];
1745
  'core_icon_type' => self::mla_get_core_icon_type( $array[0] )
1746
  );
1747
 
1748
+ if ( 'checked' == MLACore::mla_get_option( MLACore::MLA_ENABLE_MLA_ICONS ) ) {
1749
  self::$mla_upload_mime_templates[ $key ]['icon_type'] = self::$mla_upload_mime_templates[ $key ]['mla_icon_type'];
1750
  }
1751
  }
1794
  'core_icon_type' => $core_icon_type
1795
  );
1796
 
1797
+ if ( 'checked' == MLACore::mla_get_option( MLACore::MLA_ENABLE_MLA_ICONS ) ) {
1798
  self::$mla_upload_mime_templates[ $key ]['icon_type'] = self::$mla_upload_mime_templates[ $key ]['mla_icon_type'];
1799
  }
1800
  }
1887
  }
1888
  }
1889
 
1890
+ MLACore::mla_update_option( MLACore::MLA_UPLOAD_MIMES, $mla_upload_mimes );
1891
  return true;
1892
  }
1893
 
includes/class-mla-objects.php CHANGED
@@ -32,7 +32,7 @@ class MLAObjects {
32
  * @return void
33
  */
34
  private static function _build_taxonomies( ) {
35
- if ( MLAOptions::mla_taxonomy_support('attachment_category') ) {
36
  $labels = array(
37
  'name' => _x( 'Att. Categories', 'taxonomy_name_plural', 'media-library-assistant' ),
38
  'singular_name' => _x( 'Att. Category', 'taxonomy_name_singular', 'media-library-assistant' ),
@@ -62,7 +62,7 @@ class MLAObjects {
62
  );
63
  }
64
 
65
- if ( MLAOptions::mla_taxonomy_support('attachment_tag') ) {
66
  $labels = array(
67
  'name' => _x( 'Att. Tags', 'taxonomy_name_plural', 'media-library-assistant' ),
68
  'singular_name' => _x( 'Att. Tag', 'taxonomy_name_singular', 'media-library-assistant' ),
@@ -93,10 +93,10 @@ class MLAObjects {
93
  );
94
  }
95
 
96
- MLAOptions::mla_initialize_tax_checked_on_top();
97
  $taxonomies = get_taxonomies( array ( 'show_ui' => true ), 'names' );
98
  foreach ( $taxonomies as $tax_name ) {
99
- if ( MLAOptions::mla_taxonomy_support( $tax_name ) ) {
100
  register_taxonomy_for_object_type( $tax_name, 'attachment');
101
  add_filter( "manage_edit-{$tax_name}_columns", 'MLAObjects::mla_taxonomy_get_columns_filter', 0x7FFFFFFF, 1 ); // $columns
102
  add_filter( "manage_{$tax_name}_custom_column", 'MLAObjects::mla_taxonomy_column_filter', 0x7FFFFFFF, 3 ); // $place_holder, $column_name, $tag->term_id
@@ -199,11 +199,18 @@ class MLAObjects {
199
 
200
  $tax_object = get_taxonomy( $taxonomy );
201
 
202
- $count_terms = 'checked' == MLAOptions::mla_get_option( MLAOptions::MLA_COUNT_TERM_ATTACHMENTS );
203
  if ( $count_terms ) {
204
  $terms = get_transient( MLA_OPTION_PREFIX . 't_term_counts_' . $taxonomy );
205
 
206
  if ( ! is_array( $terms ) ) {
 
 
 
 
 
 
 
207
  $cloud = MLAShortcodes::mla_get_terms( array(
208
  'taxonomy' => $taxonomy,
209
  'fields' => 't.term_id, t.name, t.slug, COUNT(p.ID) AS `count`',
@@ -239,7 +246,7 @@ class MLAObjects {
239
  }
240
 
241
  return sprintf( '<a href="%1$s">%2$s</a>', esc_url( add_query_arg(
242
- array( 'page' => MLA::ADMIN_PAGE_SLUG, 'mla-tax' => $taxonomy, 'mla-term' => $term->slug, 'heading_suffix' => urlencode( $tax_object->label . ':' . $term->name ) ), 'upload.php' ) ), $column_text );
243
  }
244
  } //Class MLAObjects
245
 
32
  * @return void
33
  */
34
  private static function _build_taxonomies( ) {
35
+ if ( MLACore::mla_taxonomy_support('attachment_category') ) {
36
  $labels = array(
37
  'name' => _x( 'Att. Categories', 'taxonomy_name_plural', 'media-library-assistant' ),
38
  'singular_name' => _x( 'Att. Category', 'taxonomy_name_singular', 'media-library-assistant' ),
62
  );
63
  }
64
 
65
+ if ( MLACore::mla_taxonomy_support('attachment_tag') ) {
66
  $labels = array(
67
  'name' => _x( 'Att. Tags', 'taxonomy_name_plural', 'media-library-assistant' ),
68
  'singular_name' => _x( 'Att. Tag', 'taxonomy_name_singular', 'media-library-assistant' ),
93
  );
94
  }
95
 
96
+ MLACore::mla_initialize_tax_checked_on_top();
97
  $taxonomies = get_taxonomies( array ( 'show_ui' => true ), 'names' );
98
  foreach ( $taxonomies as $tax_name ) {
99
+ if ( MLACore::mla_taxonomy_support( $tax_name ) ) {
100
  register_taxonomy_for_object_type( $tax_name, 'attachment');
101
  add_filter( "manage_edit-{$tax_name}_columns", 'MLAObjects::mla_taxonomy_get_columns_filter', 0x7FFFFFFF, 1 ); // $columns
102
  add_filter( "manage_{$tax_name}_custom_column", 'MLAObjects::mla_taxonomy_column_filter', 0x7FFFFFFF, 3 ); // $place_holder, $column_name, $tag->term_id
199
 
200
  $tax_object = get_taxonomy( $taxonomy );
201
 
202
+ $count_terms = 'checked' == MLACore::mla_get_option( MLACore::MLA_COUNT_TERM_ATTACHMENTS );
203
  if ( $count_terms ) {
204
  $terms = get_transient( MLA_OPTION_PREFIX . 't_term_counts_' . $taxonomy );
205
 
206
  if ( ! is_array( $terms ) ) {
207
+ /*
208
+ * The MLAShortcodes class is only loaded when needed.
209
+ */
210
+ if ( !class_exists( 'MLAShortcodes' ) ) {
211
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-shortcodes.php' );
212
+ }
213
+
214
  $cloud = MLAShortcodes::mla_get_terms( array(
215
  'taxonomy' => $taxonomy,
216
  'fields' => 't.term_id, t.name, t.slug, COUNT(p.ID) AS `count`',
246
  }
247
 
248
  return sprintf( '<a href="%1$s">%2$s</a>', esc_url( add_query_arg(
249
+ array( 'page' => MLACore::ADMIN_PAGE_SLUG, 'mla-tax' => $taxonomy, 'mla-term' => $term->slug, 'heading_suffix' => urlencode( $tax_object->label . ':' . $term->name ) ), 'upload.php' ) ), $column_text );
250
  }
251
  } //Class MLAObjects
252
 
includes/class-mla-options.php CHANGED
@@ -19,337 +19,267 @@ class MLAOptions {
19
  /**
20
  * Provides a unique name for the current version option
21
  */
22
- const MLA_VERSION_OPTION = 'current_version';
23
 
24
  /**
25
  * Provides a unique name for the exclude revisions option
26
  */
27
- const MLA_EXCLUDE_REVISIONS = 'exclude_revisions';
28
 
29
  /**
30
  * Provides a unique name for a database tuning option
31
  */
32
- const 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 = 'inserted_in_tuning';
38
 
39
  /**
40
  * Provides a unique name for a database tuning option
41
  */
42
- const 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 = 'mla_gallery_in_tuning';
48
 
49
  /**
50
  * Provides a unique name for the taxonomy count Attachments option
51
  */
52
- const 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 = 'taxonomy_support';
58
 
59
  /**
60
  * Provides a unique name for the admin screen page title option
61
  */
62
- const 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 = 'admin_screen_menu_title';
68
 
69
  /**
70
  * Provides a unique name for the admin screen menu order option
71
  */
72
- const 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 = 'admin_screen_display_default';
78
 
79
  /**
80
  * Provides a unique name for the default orderby option
81
  */
82
- const MLA_DEFAULT_ORDERBY = 'default_orderby';
83
 
84
  /**
85
  * Provides a unique name for the default order option
86
  */
87
- const 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 = '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 = '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 = 'bulk_chunk_size';
103
 
104
  /**
105
  * Provides a unique name for the taxonomy filter maximum depth option
106
  */
107
- const 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 = '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 = '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 = 'search_media_filter_defaults';
123
 
124
  /**
125
  * Provides a "size" attribute value for the EXIF/Template Value field
126
  */
127
- const 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 = '__NEW_RULE__';
133
 
134
  /**
135
  * Provides a unique name for the Custom Field "new field" key
136
  */
137
- const 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 = '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 = '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 = '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 = '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 = '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 = '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 = '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 = '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 = '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 = '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 = '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 = '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 = '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 = '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 = 'media_modal_details_autofill';
217
 
218
  /**
219
  * Provides a unique name for the Media Manager orderby option
220
  */
221
- const 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 = 'media_modal_order';
227
 
228
  /**
229
  * Provides a unique name for the Post MIME Types option
230
  */
231
- const 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 = 'enable_post_mime_types';
237
 
238
  /**
239
  * Provides a unique name for the Upload MIME Types option
240
  */
241
- const 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 = 'enable_upload_mimes';
247
 
248
  /**
249
  * Provides a unique name for the Enable MLA Icons option
250
  */
251
- const 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 = 'debug_display_limit';
257
 
258
  /**
259
  * Provides a unique name for the Debug alternate log file option
260
  */
261
- const 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 = '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 = '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 = 'debug_replace_level';
277
 
278
  /**
279
- * Option setting for "Featured in" reporting
280
- *
281
- * This setting is false if the "Featured in" database access setting is "disabled", else true.
282
- *
283
- * @since 1.00
284
- *
285
- * @var boolean
286
- */
287
- public static $process_featured_in = true;
288
-
289
- /**
290
- * Option setting for "Inserted in" reporting
291
- *
292
- * This setting is false if the "Inserted in" database access setting is "disabled", else true.
293
- *
294
- * @since 1.00
295
- *
296
- * @var boolean
297
- */
298
- public static $process_inserted_in = true;
299
-
300
- /**
301
- * Option setting for "Gallery in" reporting
302
- *
303
- * This setting is false if the "Gallery in" database access setting is "disabled", else true.
304
- *
305
- * @since 1.00
306
- *
307
- * @var boolean
308
- */
309
- public static $process_gallery_in = true;
310
-
311
- /**
312
- * Option setting for "MLA Gallery in" reporting
313
- *
314
- * This setting is false if the "MLA Gallery in" database access setting is "disabled", else true.
315
- *
316
- * @since 1.00
317
- *
318
- * @var boolean
319
- */
320
- public static $process_mla_gallery_in = true;
321
-
322
- /**
323
- * $mla_option_definitions defines the database options and admin page areas for setting/updating them
324
- *
325
- * The array must be populated at runtime in MLAOptions::mla_localize_option_definitions_array();
326
- * localization calls cannot be placed in the "public static" array definition itself.
327
- *
328
- * Each option is defined by an array with the following elements:
329
- *
330
- * array key => HTML id/name attribute and option database key (OMIT MLA_OPTION_PREFIX)
331
- *
332
- * tab => Settings page tab id for the option
333
- * name => admin page label or heading text
334
- * type => 'checkbox', 'header', 'radio', 'select', 'text', 'textarea', 'custom', 'hidden'
335
- * std => default value
336
- * help => help text
337
- * size => text size, default 40
338
- * cols => textbox columns, default 90
339
- * rows => textbox rows, default 5
340
- * options => array of radio or select option values
341
- * texts => array of radio or select option display texts
342
- * render => rendering function for 'custom' options. Usage:
343
- * $options_list .= ['render']( 'render', $key, $value );
344
- * update => update function for 'custom' options; returns nothing. Usage:
345
- * $message = ['update']( 'update', $key, $value, $_REQUEST );
346
- * delete => delete function for 'custom' options; returns nothing. Usage:
347
- * $message = ['delete']( 'delete', $key, $value, $_REQUEST );
348
- * reset => reset function for 'custom' options; returns nothing. Usage:
349
- * $message = ['reset']( 'reset', $key, $value, $_REQUEST );
350
  */
351
 
352
- public static $mla_option_definitions = array ();
353
 
354
  /**
355
  * Initialization function, similar to __construct()
@@ -359,28 +289,12 @@ class MLAOptions {
359
  * @return void
360
  */
361
  public static function initialize( ) {
362
- self::_load_option_templates();
363
-
364
- if ( 'disabled' == self::mla_get_option( self::MLA_FEATURED_IN_TUNING ) ) {
365
- self::$process_featured_in = false;
366
- }
367
-
368
- if ( 'disabled' == self::mla_get_option( self::MLA_INSERTED_IN_TUNING ) ) {
369
- self::$process_inserted_in = false;
370
- }
371
-
372
- if ( 'disabled' == self::mla_get_option( self::MLA_GALLERY_IN_TUNING ) ) {
373
- self::$process_gallery_in = false;
374
- }
375
-
376
- if ( 'disabled' == self::mla_get_option( self::MLA_MLA_GALLERY_IN_TUNING ) ) {
377
- self::$process_mla_gallery_in = false;
378
- }
379
 
380
- if ( ( 'checked' == MLAOptions::mla_get_option( 'enable_iptc_exif_mapping' ) ) ||
381
- ( 'checked' == MLAOptions::mla_get_option( 'enable_custom_field_mapping' ) ) ||
382
- ( 'checked' == MLAOptions::mla_get_option( 'enable_iptc_exif_update' ) ) ||
383
- ( 'checked' == MLAOptions::mla_get_option( 'enable_custom_field_update' ) ) ) {
384
  add_filter( 'wp_handle_upload_prefilter', 'MLAOptions::mla_wp_handle_upload_prefilter_filter', 1, 1 );
385
  add_filter( 'wp_handle_upload', 'MLAOptions::mla_wp_handle_upload_filter', 1, 1 );
386
 
@@ -396,7 +310,7 @@ class MLAOptions {
396
  *
397
  * @var array
398
  */
399
- private static $mla_option_templates = null;
400
 
401
  /**
402
  * Load style and markup templates to $mla_templates
@@ -406,40 +320,19 @@ class MLAOptions {
406
  * @return void
407
  */
408
  private static function _load_option_templates() {
409
- self::$mla_option_templates = MLAData::mla_load_template( 'mla-option-templates.tpl' );
410
 
411
  /*
412
  * Load the default templates
413
  */
414
- if ( is_null( self::$mla_option_templates ) ) {
415
- MLA::mla_debug_add( '<strong>mla_debug _load_option_templates()</strong> ' . __( 'error loading tpls/mla-option-templates.tpl', 'media-library-assistant' ) );
416
  return;
417
- } elseif ( !self::$mla_option_templates ) {
418
- MLA::mla_debug_add( '<strong>mla_debug _load_option_templates()</strong> ' . __( 'tpls/mla-option-templates.tpl not found', 'media-library-assistant' ) );
419
- $mla_option_templates = null;
420
  return;
421
  }
422
-
423
- /*
424
- * Add user-defined Style and Markup templates
425
- */
426
- $templates = self::mla_get_option( 'style_templates' );
427
- if ( is_array( $templates ) ) {
428
- foreach ( $templates as $name => $value ) {
429
- self::$mla_option_templates[ $name . '-style' ] = $value;
430
- } // foreach $templates
431
- } // is_array
432
-
433
- $templates = self::mla_get_option( 'markup_templates' );
434
- if ( is_array( $templates ) ) {
435
- foreach ( $templates as $name => $value ) {
436
- self::$mla_option_templates[ $name . '-open-markup' ] = $value['open'];
437
- self::$mla_option_templates[ $name . '-row-open-markup' ] = $value['row-open'];
438
- self::$mla_option_templates[ $name . '-item-markup' ] = $value['item'];
439
- self::$mla_option_templates[ $name . '-row-close-markup' ] = $value['row-close'];
440
- self::$mla_option_templates[ $name . '-close-markup' ] = $value['close'];
441
- } // foreach $templates
442
- } // is_array
443
  }
444
 
445
  /**
@@ -453,945 +346,7 @@ class MLAOptions {
453
  * @return void
454
  */
455
  public static function mla_localize_option_definitions_array() {
456
- self::$mla_option_definitions = array (
457
- /*
458
- * This option records the highest MLA version so-far installed
459
- */
460
- self::MLA_VERSION_OPTION =>
461
- array('tab' => '',
462
- 'type' => 'hidden',
463
- 'std' => '0'),
464
-
465
- /*
466
- * These checkboxes are no longer used;
467
- * they are retained for the database version/update check
468
- */
469
- 'attachment_category' =>
470
- array('tab' => '',
471
- 'name' => __( 'Attachment Categories', 'media-library-assistant' ),
472
- 'type' => 'hidden', // checkbox',
473
- 'std' => 'checked',
474
- 'help' => __( 'Check this option to add support for Attachment Categories.', 'media-library-assistant' )),
475
-
476
- 'attachment_tag' =>
477
- array('tab' => '',
478
- 'name' => __( 'Attachment Tags', 'media-library-assistant' ),
479
- 'type' => 'hidden', // checkbox',
480
- 'std' => 'checked',
481
- 'help' => __( 'Check this option to add support for Attachment Tags.'), 'media-library-assistant' ),
482
-
483
- 'where_used_header' =>
484
- array('tab' => 'general',
485
- 'name' => __( 'Where-used Reporting', 'media-library-assistant' ),
486
- 'type' => 'header'),
487
-
488
- self::MLA_EXCLUDE_REVISIONS =>
489
- array('tab' => 'general',
490
- 'name' => __( 'Exclude Revisions', 'media-library-assistant' ),
491
- 'type' => 'checkbox',
492
- 'std' => 'checked',
493
- 'help' => __( 'Check this option to exclude revisions from where-used reporting.', 'media-library-assistant' )),
494
-
495
- 'where_used_subheader' =>
496
- array('tab' => 'general',
497
- 'name' => __( 'Where-used database access tuning', 'media-library-assistant' ),
498
- 'type' => 'subheader'),
499
-
500
- self::MLA_FEATURED_IN_TUNING =>
501
- array('tab' => 'general',
502
- 'name' => __( 'Featured in', 'media-library-assistant' ),
503
- 'type' => 'select',
504
- 'std' => 'enabled',
505
- 'options' => array('enabled', 'disabled'),
506
- 'texts' => array( __( 'Enabled', 'media-library-assistant' ), __( 'Disabled', 'media-library-assistant' ) ),
507
- 'help' => __( 'Search database posts and pages for Featured Image attachments.', 'media-library-assistant' )),
508
-
509
- self::MLA_INSERTED_IN_TUNING =>
510
- array('tab' => 'general',
511
- 'name' => __( 'Inserted in', 'media-library-assistant' ),
512
- 'type' => 'select',
513
- 'std' => 'base',
514
- 'options' => array('enabled', 'base', 'disabled'),
515
- 'texts' => array( __( 'Enabled', 'media-library-assistant' ), __( 'Base', 'media-library-assistant' ), __( 'Disabled', 'media-library-assistant' ) ),
516
- 'help' => __( 'Search database posts and pages for attachments embedded in content.<br>&nbsp;&nbsp;Base = ignore intermediate size suffixes; use path, base name and extension only.', 'media-library-assistant' )),
517
-
518
- self::MLA_GALLERY_IN_TUNING =>
519
- array('tab' => 'general',
520
- 'name' => __( 'Gallery in', 'media-library-assistant' ),
521
- 'type' => 'select',
522
- 'std' => 'cached',
523
- 'options' => array('dynamic', 'refresh', 'cached', 'disabled'),
524
- 'texts' => array( __( 'Dynamic', 'media-library-assistant' ), __( 'Refresh', 'media-library-assistant' ), __( 'Cached', 'media-library-assistant' ), __( 'Disabled', 'media-library-assistant' ) ),
525
- 'help' => __( 'Search database posts and pages for [gallery] shortcode results.<br>&nbsp;&nbsp;Dynamic = once every page load, Cached = once every login, Disabled = never.<br>&nbsp;&nbsp;Refresh = update references, then set to Cached.', 'media-library-assistant' )),
526
-
527
- self::MLA_MLA_GALLERY_IN_TUNING =>
528
- array('tab' => 'general',
529
- 'name' => __( 'MLA Gallery in', 'media-library-assistant' ),
530
- 'type' => 'select',
531
- 'std' => 'cached',
532
- 'options' => array('dynamic', 'refresh', 'cached', 'disabled'),
533
- 'texts' => array( __( 'Dynamic', 'media-library-assistant' ), __( 'Refresh', 'media-library-assistant' ), __( 'Cached', 'media-library-assistant' ), __( 'Disabled', 'media-library-assistant' ) ),
534
- 'help' => __( 'Search database posts and pages for [mla_gallery] shortcode results.<br>&nbsp;&nbsp;Dynamic = once every page load, Cached = once every login, Disabled = never.<br>&nbsp;&nbsp;Refresh = update references, then set to Cached.', 'media-library-assistant' )),
535
-
536
- 'taxonomy_header' =>
537
- array('tab' => 'general',
538
- 'name' => __( 'Taxonomy Support', 'media-library-assistant' ),
539
- 'type' => 'header'),
540
-
541
- self::MLA_COUNT_TERM_ATTACHMENTS =>
542
- array('tab' => 'general',
543
- 'name' => __( 'Compute Attachments Column', 'media-library-assistant' ),
544
- 'type' => 'checkbox',
545
- 'std' => 'checked',
546
- 'help' => __( 'Check this option to calculate attachments per term in the Attachments Column.', 'media-library-assistant' )),
547
-
548
- self::MLA_TAXONOMY_SUPPORT =>
549
- array('tab' => 'general',
550
- 'help' => __( 'Check the "<strong>Support</strong>" box to add the taxonomy to the Assistant and the Edit Media screen.', 'media-library-assistant' ) . '<br>' .
551
- __( 'Check the "<strong>Inline Edit</strong>" box to display the taxonomy in the Quick Edit and Bulk Edit areas.', 'media-library-assistant' ) . '<br>' .
552
- __( 'Check the "<strong>Term Search</strong>" box to add the taxonomy to the "Search Media/Terms" list.', 'media-library-assistant' ) .
553
- sprintf( ' %1$s <a href="%2$s">%3$s</a>.', __( 'For complete documentation', 'media-library-assistant' ), admin_url( 'options-general.php?page=' . MLASettings::MLA_SETTINGS_SLUG . '-documentation&amp;mla_tab=documentation#terms_search' ), __( 'click here', 'media-library-assistant' ) )
554
- . '<br>' .
555
- __( 'Check the "<strong>Checklist</strong>" box to enable the checklist-style meta box for a flat taxonomy.', 'media-library-assistant' ) . '&nbsp;' .
556
- __( 'You must also check the <strong>"Enable enhanced checklist taxonomies"</strong> box below to enable this feature.', 'media-library-assistant' ) . '<br>' .
557
- __( '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>' .
558
- __( 'Use the "<strong>List Filter</strong>" option to select the taxonomy on which to filter the Assistant table listing.', 'media-library-assistant' ),
559
- 'std' => array (
560
- 'tax_support' => array (
561
- 'attachment_category' => 'checked',
562
- 'attachment_tag' => 'checked',
563
- ),
564
- 'tax_quick_edit' => array (
565
- 'attachment_category' => 'checked',
566
- 'attachment_tag' => 'checked',
567
- ),
568
- 'tax_term_search' => array (
569
- 'attachment_category' => 'checked',
570
- 'attachment_tag' => 'checked',
571
- ),
572
- 'tax_flat_checklist' => array(),
573
- 'tax_checked_on_top' => NULL, // default "true", handled in mla_initialize_tax_checked_on_top
574
- 'tax_filter' => 'attachment_category'
575
- ),
576
- 'type' => 'custom',
577
- 'render' => 'mla_taxonomy_option_handler',
578
- 'update' => 'mla_taxonomy_option_handler',
579
- 'delete' => 'mla_taxonomy_option_handler',
580
- 'reset' => 'mla_taxonomy_option_handler'),
581
-
582
- 'media_assistant_header' =>
583
- array('tab' => 'general',
584
- 'name' => __( 'Media/Assistant Screen Options', 'media-library-assistant' ),
585
- 'type' => 'header'),
586
-
587
- 'admin_sidebar_subheader' =>
588
- array('tab' => 'general',
589
- 'name' => __( 'Admin Menu Options', 'media-library-assistant' ),
590
- 'type' => 'subheader'),
591
-
592
- self::MLA_SCREEN_PAGE_TITLE =>
593
- array('tab' => 'general',
594
- 'name' => __( 'Page Title', 'media-library-assistant' ),
595
- 'type' => 'text',
596
- 'std' => __( 'Media Library Assistant', 'media-library-assistant' ),
597
- 'size' => 40,
598
- 'help' => __( 'Enter the title for the Media/Assistant submenu page', 'media-library-assistant' )),
599
-
600
- self::MLA_SCREEN_MENU_TITLE =>
601
- array('tab' => 'general',
602
- 'name' => __( 'Menu Title', 'media-library-assistant' ),
603
- 'type' => 'text',
604
- 'std' => __( 'Assistant', 'media-library-assistant' ),
605
- 'size' => 20,
606
- 'help' => __( 'Enter the title for the Media/Assistant submenu entry', 'media-library-assistant' )),
607
-
608
- self::MLA_SCREEN_ORDER =>
609
- array('tab' => 'general',
610
- 'name' => __( 'Submenu Order', 'media-library-assistant' ),
611
- 'type' => 'text',
612
- 'std' => '0',
613
- 'size' => 2,
614
- 'help' => __( 'Enter the position of the Media/Assistant submenu entry.<br>&nbsp;&nbsp;0 = natural order (at bottom),&nbsp;&nbsp;&nbsp;&nbsp;1 - 4 = at top<br>&nbsp;&nbsp;6-9 = after "Library",&nbsp;&nbsp;&nbsp;&nbsp;11-16 = after "Add New"', 'media-library-assistant' )),
615
-
616
- self::MLA_SCREEN_DISPLAY_LIBRARY =>
617
- array('tab' => 'general',
618
- 'name' => __( 'Display Media/Library', 'media-library-assistant' ),
619
- 'type' => 'checkbox',
620
- 'std' => 'checked',
621
- 'help' => __( 'Check/uncheck this option to display/remove the WordPress Media/Library submenu entry.', 'media-library-assistant' )),
622
-
623
- 'table_defaults_subheader' =>
624
- array('tab' => 'general',
625
- 'name' => __( 'Table Defaults', 'media-library-assistant' ),
626
- 'type' => 'subheader'),
627
-
628
- self::MLA_DEFAULT_ORDERBY =>
629
- array('tab' => 'general',
630
- 'name' => __( 'Order By', 'media-library-assistant' ),
631
- 'type' => 'select',
632
- 'std' => 'title_name',
633
- 'options' => array('none', 'title_name'),
634
- 'texts' => array( __( 'None', 'media-library-assistant' ), __( 'Title/Name', 'media-library-assistant' ) ),
635
- 'help' => __( 'Select the column for the sort order of the Assistant table listing.', 'media-library-assistant' )),
636
-
637
- self::MLA_DEFAULT_ORDER =>
638
- array('tab' => 'general',
639
- 'name' => __( 'Order', 'media-library-assistant' ),
640
- 'type' => 'radio',
641
- 'std' => 'ASC',
642
- 'options' => array('ASC', 'DESC'),
643
- 'texts' => array( __( 'Ascending', 'media-library-assistant' ), __( 'Descending', 'media-library-assistant' ) ),
644
- 'help' => __( 'Choose the sort order.', 'media-library-assistant' )),
645
-
646
- self::MLA_TABLE_VIEWS_WIDTH =>
647
- array('tab' => 'general',
648
- 'name' => __( 'Views Width', 'media-library-assistant' ),
649
- 'type' => 'text',
650
- 'std' => '',
651
- 'size' => 10,
652
- 'help' => __( 'Enter the width for the views list, in pixels (px) or percent (%)', 'media-library-assistant' )),
653
-
654
- self::MLA_TABLE_ICON_SIZE =>
655
- array('tab' => 'general',
656
- 'name' => __( 'Icon Size', 'media-library-assistant' ),
657
- 'type' => 'text',
658
- 'std' => '',
659
- 'size' => 5,
660
- 'help' => __( 'Enter the size of the thumbnail/icon images, in pixels', 'media-library-assistant' )),
661
-
662
- self::MLA_BULK_CHUNK_SIZE =>
663
- array('tab' => 'general',
664
- 'name' => __( 'Bulk Chunk Size', 'media-library-assistant' ),
665
- 'type' => 'text',
666
- 'std' => '25',
667
- 'size' => 5,
668
- 'help' => __( 'Enter the size of the Bulk Edit and Map All processing chunks', 'media-library-assistant' )),
669
-
670
- 'taxonomy_filter_subheader' =>
671
- array('tab' => 'general',
672
- 'name' => __( 'Taxonomy Filter parameters', 'media-library-assistant' ),
673
- 'type' => 'subheader'),
674
-
675
- self::MLA_TAXONOMY_FILTER_DEPTH =>
676
- array('tab' => 'general',
677
- 'name' => __( 'Maximum Depth', 'media-library-assistant' ),
678
- 'type' => 'text',
679
- 'std' => '3',
680
- 'size' => 2,
681
- 'help' => __( 'Enter the number of levels displayed for hierarchial taxonomies; enter zero for no limit.', 'media-library-assistant' )),
682
-
683
- self::MLA_TAXONOMY_FILTER_INCLUDE_CHILDREN =>
684
- array('tab' => 'general',
685
- 'name' => __( 'Include Children', 'media-library-assistant' ),
686
- 'type' => 'checkbox',
687
- 'std' => 'checked',
688
- 'help' => __( 'Check/uncheck this option to include/exclude children for hierarchical taxonomies.', 'media-library-assistant' )),
689
-
690
- 'search_media_subheader' =>
691
- array('tab' => 'general',
692
- 'name' => __( 'Search Media Defaults', 'media-library-assistant' ),
693
- 'type' => 'subheader'),
694
-
695
- self::MLA_SEARCH_MEDIA_FILTER_SHOW_CONTROLS =>
696
- array('tab' => 'general',
697
- 'name' => __( 'Display Search Controls', 'media-library-assistant' ),
698
- 'type' => 'checkbox',
699
- 'std' => 'checked',
700
- 'help' => __( 'Check/uncheck this option to display/hide the and/or connector and search fields controls.', 'media-library-assistant' )),
701
-
702
- self::MLA_SEARCH_MEDIA_FILTER_DEFAULTS =>
703
- array('tab' => 'general',
704
- 'help' => __( 'Use these controls to set defaults for the and/or connector and search fields controls.<br>These defaults will be used for the Search Media boxes on both the Media/Assistant submenu<br>and the Media Manager Modal Window.', 'media-library-assistant' ),
705
- 'std' => array (
706
- 'search_connector' => 'AND',
707
- 'search_fields' => array ( 'title', 'content' ),
708
- ),
709
- 'type' => 'custom',
710
- 'render' => 'mla_search_option_handler',
711
- 'update' => 'mla_search_option_handler',
712
- 'delete' => 'mla_search_option_handler',
713
- 'reset' => 'mla_search_option_handler'),
714
-
715
- 'edit_media_header' =>
716
- array('tab' => 'general',
717
- 'name' => __( 'Media/Edit Media Enhancements', 'media-library-assistant' ),
718
- 'type' => 'header'),
719
-
720
- self::MLA_EDIT_MEDIA_SEARCH_TAXONOMY =>
721
- array('tab' => 'general',
722
- 'name' => __( 'Enable &quot;enhanced checklist&quot; taxonomies', 'media-library-assistant' ),
723
- 'type' => 'checkbox',
724
- 'std' => 'checked',
725
- 'help' => __( 'Check this option to enable the "? Search" feature for hierarchical taxonomies, e.g., Att. Categories.<br>&nbsp;&nbsp;This option also enables the "checklist-style" support for flat taxonomies, e.g., Att. Tags.', 'media-library-assistant' )),
726
-
727
- self::MLA_EDIT_MEDIA_META_BOXES =>
728
- array('tab' => 'general',
729
- 'name' => __( 'Enable Edit Media additional meta boxes', 'media-library-assistant' ),
730
- 'type' => 'checkbox',
731
- 'std' => 'checked',
732
- 'help' => __( 'Check this option to add "Parent Info", "Menu Order", "Attachment Metadata" and four "where-used" meta boxes to the Edit Media screen.', 'media-library-assistant' ) . '<br>&nbsp;&nbsp;' .
733
- __( 'You can also use Filters to customize the meta boxes.', 'media-library-assistant' ) .
734
- sprintf( ' %1$s <a href="%2$s">%3$s</a>.', __( 'For complete documentation', 'media-library-assistant' ), admin_url( 'options-general.php?page=' . MLASettings::MLA_SETTINGS_SLUG . '-documentation&amp;mla_tab=documentation#mla_edit_meta_boxes' ), __( 'click here', 'media-library-assistant' ) ) ),
735
-
736
- 'media_add_new_header' =>
737
- array('tab' => 'general',
738
- 'name' => __( 'Media/Add New Enhancements', 'media-library-assistant' ),
739
- 'type' => 'header'),
740
-
741
- self::MLA_ADD_NEW_BULK_EDIT =>
742
- array('tab' => 'general',
743
- 'name' => __( 'Enable &quot;bulk edit&quot; area', 'media-library-assistant' ),
744
- 'type' => 'checkbox',
745
- 'std' => 'checked',
746
- 'help' => __( 'Check this option to enable the "Bulk Edit area" feature on the Media/Add New screen.', 'media-library-assistant' )),
747
-
748
- self::MLA_ADD_NEW_BULK_EDIT_ON_TOP =>
749
- array('tab' => 'general',
750
- 'name' => __( '&quot;bulk edit&quot; area on top', 'media-library-assistant' ),
751
- 'type' => 'checkbox',
752
- 'std' => '',
753
- 'help' => __( 'Check this option to move the "Bulk Edit area" to the top of the Media/Add New screen.', 'media-library-assistant' )),
754
-
755
- 'media_modal_header' =>
756
- array('tab' => 'general',
757
- 'name' => __( 'Media Manager/Media Grid Enhancements', 'media-library-assistant' ),
758
- 'type' => 'header'),
759
-
760
- self::MLA_MEDIA_GRID_TOOLBAR =>
761
- array('tab' => 'general',
762
- 'name' => __( 'Enable Media Grid Enhancements', 'media-library-assistant' ),
763
- 'type' => 'checkbox',
764
- 'std' => 'checked',
765
- 'help' => __( 'Check/uncheck this option to enable/disable Media Library Grid View Enhancements.', 'media-library-assistant' )),
766
-
767
- self::MLA_MEDIA_MODAL_TOOLBAR =>
768
- array('tab' => 'general',
769
- 'name' => __( 'Enable Media Manager Enhancements', 'media-library-assistant' ),
770
- 'type' => 'checkbox',
771
- 'std' => 'checked',
772
- 'help' => __( 'Check/uncheck this option to enable/disable Media Manager Modal Window Enhancements.', 'media-library-assistant' )),
773
-
774
- self::MLA_MEDIA_MODAL_MIMETYPES =>
775
- array('tab' => 'general',
776
- 'name' => __( 'Media Manager Enhanced MIME Type filter', 'media-library-assistant' ),
777
- 'type' => 'checkbox',
778
- 'std' => 'checked',
779
- 'help' => __( 'Check this option to filter by more MIME Types, e.g., text, applications.', 'media-library-assistant' )),
780
-
781
- self::MLA_MEDIA_MODAL_MONTHS =>
782
- array('tab' => 'general',
783
- 'name' => __( 'Media Manager Month and Year filter', 'media-library-assistant' ),
784
- 'type' => 'checkbox',
785
- 'std' => 'checked',
786
- 'help' => __( 'Check this option to filter by month and year uploaded.', 'media-library-assistant' )),
787
-
788
- self::MLA_MEDIA_MODAL_TERMS =>
789
- array('tab' => 'general',
790
- 'name' => __( 'Media Manager Category/Tag filter', 'media-library-assistant' ),
791
- 'type' => 'checkbox',
792
- 'std' => 'checked',
793
- 'help' => __( 'Check this option to filter by taxonomy terms.', 'media-library-assistant' )),
794
-
795
- self::MLA_MEDIA_MODAL_TERMS_SEARCH =>
796
- array('tab' => 'general',
797
- 'name' => __( 'Media Manager Terms Search popup', 'media-library-assistant' ),
798
- 'type' => 'checkbox',
799
- 'std' => 'checked',
800
- 'help' => __( 'Check this option to enable the "Terms Search" popup window.', 'media-library-assistant' )),
801
-
802
- self::MLA_MEDIA_MODAL_SEARCHBOX =>
803
- array('tab' => 'general',
804
- 'name' => __( 'Media Manager Enhanced Search Media box', 'media-library-assistant' ),
805
- 'type' => 'checkbox',
806
- 'std' => 'checked',
807
- 'help' => __( 'Check this option to enable search box enhancements.', 'media-library-assistant' )),
808
-
809
- self::MLA_MEDIA_MODAL_SEARCHBOX_CONTROLS =>
810
- array('tab' => 'general',
811
- 'name' => __( 'Media Manager Enhanced Search Media Controls', 'media-library-assistant' ),
812
- 'type' => 'checkbox',
813
- 'std' => 'checked',
814
- 'help' => __( 'Check/uncheck this option to display/hide the and/or connector and search fields controls.', 'media-library-assistant' )),
815
-
816
- self::MLA_MEDIA_MODAL_DETAILS_CATEGORY_METABOX =>
817
- array('tab' => 'general',
818
- 'name' => __( 'Media Manager Checklist meta boxes', 'media-library-assistant' ),
819
- 'type' => 'checkbox',
820
- 'std' => 'checked',
821
- 'help' => __( 'Check this option to enable MLA-enhanced meta boxes in the "ATTACHMENT DETAILS" pane.<br>&nbsp;&nbsp;This option is for any taxonomy that uses a <strong>"checklist-style"</strong> meta box.', 'media-library-assistant' )),
822
-
823
- self::MLA_MEDIA_MODAL_DETAILS_TAG_METABOX =>
824
- array('tab' => 'general',
825
- 'name' => __( 'Media Manager Flat meta boxes', 'media-library-assistant' ),
826
- 'type' => 'checkbox',
827
- 'std' => 'checked',
828
- 'help' => __( 'Check this option to enable MLA-enhanced meta boxes in the "ATTACHMENT DETAILS" pane.<br>&nbsp;&nbsp;This option is for <strong>flat taxonomies</strong>, e.g., "Tags" or "Att. Tags", that do not use the "checklist-style" meta box.', 'media-library-assistant' )),
829
-
830
- self::MLA_MEDIA_MODAL_DETAILS_AUTOFILL =>
831
- array('tab' => 'general',
832
- 'name' => __( 'Media Manager auto-fill meta boxes', 'media-library-assistant' ),
833
- 'type' => 'checkbox',
834
- 'std' => '',
835
- 'help' => __( 'Check this option to automatically fill MLA-enhanced meta boxes in the "ATTACHMENT DETAILS" pane<br>&nbsp;&nbsp;when the item is selected.', 'media-library-assistant' )),
836
-
837
- self::MLA_MEDIA_MODAL_ORDERBY =>
838
- array('tab' => '',
839
- 'name' => __( 'Media Manager Order By', 'media-library-assistant' ),
840
- 'type' => 'select',
841
- 'std' => 'default',
842
- 'options' => array('default', 'none', 'title_name'),
843
- 'texts' => array('&mdash; ' . __( 'Media Manager Default', 'media-library-assistant' ) . ' &mdash;', __( 'None', 'media-library-assistant' ), __( 'Title/Name', 'media-library-assistant' )),
844
- 'help' => __( 'If you want to override the Media Manager default,<br>&nbsp;&nbsp;select a column for the sort order of the Media Library listing.', 'media-library-assistant' )),
845
-
846
- self::MLA_MEDIA_MODAL_ORDER =>
847
- array('tab' => '',
848
- 'name' => __( 'Media Manager Order', 'media-library-assistant' ),
849
- 'type' => 'radio',
850
- 'std' => 'default',
851
- 'options' => array('default', 'ASC', 'DESC'),
852
- 'texts' => array( '&mdash; ' . __( 'Media Manager Default', 'media-library-assistant' ) . ' &mdash;', 'Ascending', 'Descending' ),
853
- 'help' => __( 'Choose the sort order.', 'media-library-assistant' )),
854
-
855
- 'attachment_display_settings_subheader' =>
856
- array('tab' => 'general',
857
- 'name' => __( 'Attachment Display Settings', 'media-library-assistant' ),
858
- 'type' => 'subheader'),
859
-
860
- 'image_default_align' =>
861
- array('tab' => 'general',
862
- 'name' => __( 'Alignment', 'media-library-assistant' ),
863
- /* translators: 1: option name, e.g., Alignment, Link To or Size */
864
- 'help' => sprintf( __( 'Select a value for the default %1$s option in the Attachment Display Settings.', 'media-library-assistant' ), __( 'Alignment', 'media-library-assistant' ) ),
865
- 'std' => 'default',
866
- 'options' => array('default', 'left', 'center', 'right', 'none'),
867
- 'texts' => array('&mdash; ' . __( 'Media Manager Default', 'media-library-assistant' ) . ' &mdash;', __( 'Left', 'media-library-assistant' ), __( 'Center', 'media-library-assistant' ), __( 'Right', 'media-library-assistant' ), __( 'None', 'media-library-assistant' )),
868
- 'type' => 'custom',
869
- 'render' => 'mla_attachment_display_settings_option_handler',
870
- 'update' => 'mla_attachment_display_settings_option_handler',
871
- 'delete' => 'mla_attachment_display_settings_option_handler',
872
- 'reset' => 'mla_attachment_display_settings_option_handler'),
873
-
874
- 'image_default_link_type' =>
875
- array('tab' => 'general',
876
- 'name' => __( 'Link To', 'media-library-assistant' ),
877
- /* translators: 1: option name, e.g., Alignment, Link To or Size */
878
- 'help' => sprintf( __( 'Select a value for the default %1$s option in the Attachment Display Settings.', 'media-library-assistant' ), __( 'Link To', 'media-library-assistant' ) ),
879
- 'std' => 'default',
880
- 'options' => array('default', 'file', 'post', 'custom', 'none'),
881
- 'texts' => array('&mdash; ' . __( 'Media Manager Default', 'media-library-assistant' ) . ' &mdash;', __( 'Media File', 'media-library-assistant' ), __( 'Attachment Page', 'media-library-assistant' ), __( 'Custom URL', 'media-library-assistant' ), __( 'None', 'media-library-assistant' )),
882
- 'type' => 'custom',
883
- 'render' => 'mla_attachment_display_settings_option_handler',
884
- 'update' => 'mla_attachment_display_settings_option_handler',
885
- 'delete' => 'mla_attachment_display_settings_option_handler',
886
- 'reset' => 'mla_attachment_display_settings_option_handler'),
887
-
888
- 'image_default_size' =>
889
- array('tab' => 'general',
890
- 'name' => __( 'Size', 'media-library-assistant' ),
891
- /* translators: 1: option name, e.g., Alignment, Link To or Size */
892
- 'help' => sprintf( __( 'Select a value for the default %1$s option in the Attachment Display Settings.', 'media-library-assistant' ), __( 'Size', 'media-library-assistant' ) ),
893
- 'std' => 'default',
894
- 'options' => array('default', 'thumbnail', 'medium', 'large', 'full'),
895
- 'texts' => array('&mdash; ' . __( 'Media Manager Default', 'media-library-assistant' ) . ' &mdash;', __( 'Thumbnail', 'media-library-assistant' ), __( 'Medium', 'media-library-assistant' ), __( 'Large', 'media-library-assistant' ), __( 'Full Size', 'media-library-assistant' )),
896
- 'type' => 'custom',
897
- 'render' => 'mla_attachment_display_settings_option_handler',
898
- 'update' => 'mla_attachment_display_settings_option_handler',
899
- 'delete' => 'mla_attachment_display_settings_option_handler',
900
- 'reset' => 'mla_attachment_display_settings_option_handler'),
901
-
902
- 'template_header' =>
903
- array('tab' => 'mla_gallery',
904
- 'name' => __( 'Default [mla_gallery] Templates and Settings', 'media-library-assistant' ),
905
- 'type' => 'header'),
906
-
907
- 'default_tag_cloud_style' =>
908
- array('tab' => '',
909
- 'name' => __( 'Style Template', 'media-library-assistant' ),
910
- 'type' => 'select',
911
- 'std' => 'tag-cloud',
912
- 'options' => array(),
913
- 'texts' => array(),
914
- /* translators: 1: template type 2: shortcode */
915
- 'help' => sprintf( __( 'Select the default %1$s for your %2$s shortcodes.', 'media-library-assistant' ), __( 'Style Template', 'media-library-assistant' ), '[mla_tag_cloud]' ) ),
916
-
917
- 'default_tag_cloud_markup' =>
918
- array('tab' => '',
919
- 'name' => __( 'Markup Template', 'media-library-assistant' ),
920
- 'type' => 'select',
921
- 'std' => 'tag-cloud',
922
- 'options' => array(),
923
- 'texts' => array(),
924
- /* translators: 1: template type 2: shortcode */
925
- 'help' => sprintf( __( 'Select the default %1$s for your %2$s shortcodes.', 'media-library-assistant' ), __( 'markup template', 'media-library-assistant' ), '[mla_tag_cloud]' ) ),
926
-
927
- 'mla_tag_cloud_columns' =>
928
- array('tab' => '',
929
- 'name' => __( 'Default columns', 'media-library-assistant' ),
930
- 'type' => 'text',
931
- 'std' => '3',
932
- 'size' => 3,
933
- 'help' => __( 'Enter the number of [mla_tag_cloud] columns; must be a positive integer.', 'media-library-assistant' )),
934
-
935
- 'mla_tag_cloud_margin' =>
936
- array('tab' => '',
937
- 'name' => __( 'Default mla_margin', 'media-library-assistant' ),
938
- 'type' => 'text',
939
- 'std' => '1.5%',
940
- 'size' => 10,
941
- 'help' => __( 'Enter the CSS "margin" property value, in length (px, em, pt, etc.), percent (%), "auto" or "inherit".<br>&nbsp;&nbsp;Enter "none" to remove the property entirely.', 'media-library-assistant' )),
942
-
943
- 'mla_tag_cloud_itemwidth' =>
944
- array('tab' => '',
945
- 'name' => __( 'Default mla_itemwidth', 'media-library-assistant' ),
946
- 'type' => 'text',
947
- 'std' => 'calculate',
948
- 'size' => 10,
949
- 'help' => __( 'Enter the CSS "width" property value, in length (px, em, pt, etc.), percent (%), "auto" or "inherit".<br>&nbsp;&nbsp;Enter "calculate" (the default) to calculate the value taking the "margin" value into account.<br>&nbsp;&nbsp;Enter "exact" to calculate the value without considering the "margin" value.<br>&nbsp;&nbsp;Enter "none" to remove the property entirely.', 'media-library-assistant' )),
950
-
951
- 'default_style' =>
952
- array('tab' => 'mla_gallery',
953
- 'name' => __( 'Style Template', 'media-library-assistant' ),
954
- 'type' => 'select',
955
- 'std' => 'default',
956
- 'options' => array(),
957
- 'texts' => array(),
958
- /* translators: 1: template type 2: shortcode */
959
- 'help' => sprintf( __( 'Select the default %1$s for your %2$s shortcodes.', 'media-library-assistant' ), __( 'Style Template', 'media-library-assistant' ), '[mla_gallery]' ) ),
960
-
961
- 'default_markup' =>
962
- array('tab' => 'mla_gallery',
963
- 'name' => __( 'Markup Template', 'media-library-assistant' ),
964
- 'type' => 'select',
965
- 'std' => 'default',
966
- 'options' => array(),
967
- 'texts' => array(),
968
- /* translators: 1: template type 2: shortcode */
969
- 'help' => sprintf( __( 'Select the default %1$s for your %2$s shortcodes.', 'media-library-assistant' ), __( 'markup template', 'media-library-assistant' ), '[mla_gallery]' ) ),
970
-
971
- 'mla_gallery_columns' =>
972
- array('tab' => 'mla_gallery',
973
- 'name' => __( 'Default columns', 'media-library-assistant' ),
974
- 'type' => 'text',
975
- 'std' => '3',
976
- 'size' => 3,
977
- 'help' => __( 'Enter the number of [mla_gallery] columns; must be a positive integer.', 'media-library-assistant' )),
978
-
979
- 'mla_gallery_margin' =>
980
- array('tab' => 'mla_gallery',
981
- 'name' => __( 'Default mla_margin', 'media-library-assistant' ),
982
- 'type' => 'text',
983
- 'std' => '1.5%',
984
- 'size' => 10,
985
- 'help' => __( 'Enter the CSS "margin" property value, in length (px, em, pt, etc.), percent (%), "auto" or "inherit".<br>&nbsp;&nbsp;Enter "none" to remove the property entirely.', 'media-library-assistant' )),
986
-
987
- 'mla_gallery_itemwidth' =>
988
- array('tab' => 'mla_gallery',
989
- 'name' => __( 'Default mla_itemwidth', 'media-library-assistant' ),
990
- 'type' => 'text',
991
- 'std' => 'calculate',
992
- 'size' => 10,
993
- 'help' => __( 'Enter the CSS "width" property value, in length (px, em, pt, etc.), percent (%), "auto" or "inherit".<br>&nbsp;&nbsp;Enter "calculate" (the default) to calculate the value taking the "margin" value into account.<br>&nbsp;&nbsp;Enter "exact" to calculate the value without considering the "margin" value.<br>&nbsp;&nbsp;Enter "none" to remove the property entirely.', 'media-library-assistant' )),
994
-
995
- 'mal_viewer_header' =>
996
- array('tab' => 'mla_gallery',
997
- 'name' => __( 'Thumbnail Substitution Support, mla_viewer', 'media-library-assistant' ),
998
- 'type' => 'subheader'),
999
-
1000
- 'enable_mla_viewer' =>
1001
- array('tab' => 'mla_gallery',
1002
- 'name' => __( 'Enable thumbnail substitution', 'media-library-assistant' ),
1003
- 'type' => 'checkbox',
1004
- 'std' => 'checked',
1005
- 'help' => __( 'Check this option to allow the "mla_viewer" to generate thumbnail images for PDF documents. Thumbnails are generated dynamically, each time the item appears in an [mla_gallery] display.<br>&nbsp;&nbsp;<strong>IMPORTANT: both Ghostscript and Imagick/ImageMagick must be installed for this feature.</strong>', 'media-library-assistant' )),
1006
-
1007
- 'enable_featured_image' =>
1008
- array('tab' => 'mla_gallery',
1009
- 'name' => __( 'Enable Featured Images', 'media-library-assistant' ),
1010
- 'type' => 'checkbox',
1011
- 'std' => 'checked',
1012
- 'help' => __( 'Check this option to extend Featured Image support to all Media Library items. The Featured Image can be used as a thumbnail image for the item in an [mla_gallery] display.', 'media-library-assistant' )),
1013
-
1014
- 'enable_featured_image_generation' =>
1015
- array('tab' => 'mla_gallery',
1016
- 'name' => __( 'Enable Featured Image Generation', 'media-library-assistant' ),
1017
- 'type' => 'checkbox',
1018
- 'std' => 'checked',
1019
- 'help' => __( 'Check this option to enable the "Thumbnail" generation action in the Media/Assistant submenu Bulk Actions dropdown.', 'media-library-assistant' )),
1020
-
1021
- 'enable_ghostscript_check' =>
1022
- array('tab' => 'mla_gallery',
1023
- 'name' => __( 'Enable explicit Ghostscript check', 'media-library-assistant' ),
1024
- 'type' => 'checkbox',
1025
- 'std' => 'checked',
1026
- 'help' => __( 'Check this option to enable the explicit check for Ghostscript support required for thumbnail generation. If your Ghostscript software is in a non-standard location, unchecking this option bypasses the check. Bad things can happen if Ghostscript is missing but Imagick/ImageMagick is present, so leave this option checked unless you know it is safe to turn it off.', 'media-library-assistant' )),
1027
-
1028
- 'ghostscript_path' =>
1029
- array('tab' => 'mla_gallery',
1030
- 'name' => __( 'Ghostscript path', 'media-library-assistant' ),
1031
- 'type' => 'text',
1032
- 'std' => '',
1033
- 'size' => 20,
1034
- 'help' => __( 'If your &ldquo;gs&rdquo; executable is in a non-standard location, enter the full path and filename here, e.g., &ldquo;/usr/bin/gs&rdquo;. It will override the search for Ghostscript in other places.', 'media-library-assistant' )),
1035
-
1036
- /*
1037
- * Managed by mla_get_style_templates and mla_put_style_templates
1038
- */
1039
- 'style_templates' =>
1040
- array('tab' => '',
1041
- 'type' => 'hidden',
1042
- 'std' => array()),
1043
-
1044
- /*
1045
- * Managed by mla_get_markup_templates and mla_put_markup_templates
1046
- */
1047
- 'markup_templates' =>
1048
- array('tab' => '',
1049
- 'type' => 'hidden',
1050
- 'std' => array()),
1051
-
1052
- 'enable_custom_field_mapping' =>
1053
- array('tab' => 'custom_field',
1054
- 'name' => __( 'Enable custom field mapping when adding new media', 'media-library-assistant' ),
1055
- 'type' => 'checkbox',
1056
- 'std' => '',
1057
- 'help' => __( 'Check this option to enable mapping when uploading new media (attachments).<br>&nbsp;&nbsp;Click Save Changes at the bottom of the screen if you change this option.<br>&nbsp;&nbsp;Does NOT affect the operation of the "Map" buttons on the bulk edit, single edit and settings screens.', 'media-library-assistant' )),
1058
-
1059
- 'enable_custom_field_update' =>
1060
- array('tab' => 'custom_field',
1061
- 'name' => __( 'Enable custom field mapping when updating media metadata', 'media-library-assistant' ),
1062
- 'type' => 'checkbox',
1063
- 'std' => '',
1064
- 'help' => __( 'Check this option to enable mapping when media (attachments) metadata is regenerated,<br>&nbsp;&nbsp;e.g., when the Media/Edit Media "Edit Image" functions are used.', 'media-library-assistant' )),
1065
-
1066
- 'custom_field_mapping' =>
1067
- array('tab' => '',
1068
- 'help' => __( 'Update the custom field mapping values above, then click Save Changes to make the updates permanent.<br>You can also make temporary updates and click a Map All Attachments button to apply the rule(s) to all attachments without saving any rule changes.', 'media-library-assistant' ),
1069
- 'std' => array(),
1070
- 'type' => 'custom',
1071
- 'render' => 'mla_custom_field_option_handler',
1072
- 'update' => 'mla_custom_field_option_handler',
1073
- 'delete' => 'mla_custom_field_option_handler',
1074
- 'reset' => 'mla_custom_field_option_handler'),
1075
-
1076
- 'enable_iptc_exif_mapping' =>
1077
- array('tab' => 'iptc_exif',
1078
- 'name' => __( 'Enable IPTC/EXIF Mapping when adding new media', 'media-library-assistant' ),
1079
- 'type' => 'checkbox',
1080
- 'std' => '',
1081
- 'help' => __( 'Check this option to enable mapping when uploading new media (attachments).<br>&nbsp;&nbsp;Does NOT affect the operation of the "Map" buttons on the bulk edit, single edit and settings screens.', 'media-library-assistant' )),
1082
-
1083
- 'enable_iptc_exif_update' =>
1084
- array('tab' => 'iptc_exif',
1085
- 'name' => __( 'Enable IPTC/EXIF Mapping when updating media metadata', 'media-library-assistant' ),
1086
- 'type' => 'checkbox',
1087
- 'std' => '',
1088
- 'help' => __( 'Check this option to enable mapping when media (attachments) metadata is regenerated,<br>&nbsp;&nbsp;e.g., when the Media/Edit Media "Edit Image" functions are used.', 'media-library-assistant' )),
1089
-
1090
- 'iptc_exif_standard_mapping' =>
1091
- array('tab' => '',
1092
- 'help' => __( 'Update the standard field mapping values above, then click <strong>Save Changes</strong> to make the updates permanent.<br>You can also make temporary updates and click <strong>Map All Attachments, Standard Fields Now</strong> to apply the updates to all attachments without saving the rule changes.', 'media-library-assistant' ),
1093
- 'std' => NULL,
1094
- 'type' => 'custom',
1095
- 'render' => 'mla_iptc_exif_option_handler',
1096
- 'update' => 'mla_iptc_exif_option_handler',
1097
- 'delete' => 'mla_iptc_exif_option_handler',
1098
- 'reset' => 'mla_iptc_exif_option_handler'),
1099
-
1100
- 'iptc_exif_taxonomy_mapping' =>
1101
- array('tab' => '',
1102
- 'help' => __( 'Update the taxonomy term mapping values above, then click <strong>Save Changes</strong> or <strong>Map All Attachments, Taxonomy Terms Now</strong>.', 'media-library-assistant' ),
1103
- 'std' => NULL,
1104
- 'type' => 'custom',
1105
- 'render' => 'mla_iptc_exif_option_handler',
1106
- 'update' => 'mla_iptc_exif_option_handler',
1107
- 'delete' => 'mla_iptc_exif_option_handler',
1108
- 'reset' => 'mla_iptc_exif_option_handler'),
1109
-
1110
- 'iptc_exif_custom_mapping' =>
1111
- array('tab' => '',
1112
- 'help' => __( '<strong>Update</strong> individual custom field mapping values above, or make several updates and click <strong>Save Changes</strong> below to apply them all at once.<br>You can also <strong>add a new rule</strong> for an existing field or <strong>add a new field</strong> and rule.<br>You can make temporary updates and click <strong>Map All Attachments, Custom Fields Now</strong> to apply the updates to all attachments without saving the rule changes.', 'media-library-assistant' ),
1113
- 'std' => NULL,
1114
- 'type' => 'custom',
1115
- 'render' => 'mla_iptc_exif_option_handler',
1116
- 'update' => 'mla_iptc_exif_option_handler',
1117
- 'delete' => 'mla_iptc_exif_option_handler',
1118
- 'reset' => 'mla_iptc_exif_option_handler'),
1119
-
1120
- 'iptc_exif_mapping' =>
1121
- array('tab' => '',
1122
- 'help' => __( 'IPTC/EXIF Mapping help', 'media-library-assistant' ),
1123
- 'std' => array (
1124
- 'standard' => array (
1125
- 'post_title' => array (
1126
- 'name' => __( 'Title', 'media-library-assistant' ),
1127
- 'iptc_value' => 'none',
1128
- 'exif_value' => '',
1129
- 'iptc_first' => true,
1130
- 'keep_existing' => true
1131
- ),
1132
- 'post_name' => array (
1133
- 'name' => __( 'Name/Slug', 'media-library-assistant' ),
1134
- 'iptc_value' => 'none',
1135
- 'exif_value' => '',
1136
- 'iptc_first' => true,
1137
- 'keep_existing' => true
1138
- ),
1139
- 'image_alt' => array (
1140
- 'name' => __( 'ALT Text', 'media-library-assistant' ),
1141
- 'iptc_value' => 'none',
1142
- 'exif_value' => '',
1143
- 'iptc_first' => true,
1144
- 'keep_existing' => true
1145
- ),
1146
- 'post_excerpt' => array (
1147
- 'name' => __( 'Caption', 'media-library-assistant' ),
1148
- 'iptc_value' => 'none',
1149
- 'exif_value' => '',
1150
- 'iptc_first' => true,
1151
- 'keep_existing' => true
1152
- ),
1153
- 'post_content' => array (
1154
- 'name' => __( 'Description', 'media-library-assistant' ),
1155
- 'iptc_value' => 'none',
1156
- 'exif_value' => '',
1157
- 'iptc_first' => true,
1158
- 'keep_existing' => true
1159
- ),
1160
- ),
1161
- 'taxonomy' => array (
1162
- ),
1163
- 'custom' => array (
1164
- )
1165
- ),
1166
- 'type' => 'custom',
1167
- 'render' => 'mla_iptc_exif_option_handler',
1168
- 'update' => 'mla_iptc_exif_option_handler',
1169
- 'delete' => 'mla_iptc_exif_option_handler',
1170
- 'reset' => 'mla_iptc_exif_option_handler'),
1171
-
1172
- self::MLA_ENABLE_POST_MIME_TYPES =>
1173
- array('tab' => 'view',
1174
- 'name' => __( 'Enable View and Post MIME Type Support', 'media-library-assistant' ),
1175
- 'type' => 'checkbox',
1176
- 'std' => 'checked',
1177
- 'help' => __( 'Check/uncheck this option to enable/disable Post MIME Type Support, then click <strong>Save Changes</strong> to record the new setting.', 'media-library-assistant' ) ),
1178
-
1179
- self::MLA_POST_MIME_TYPES =>
1180
- array('tab' => '',
1181
- 'type' => 'custom',
1182
- 'render' => 'mla_post_mime_types_option_handler',
1183
- 'update' => 'mla_post_mime_types_option_handler',
1184
- 'delete' => 'mla_post_mime_types_option_handler',
1185
- 'reset' => 'mla_post_mime_types_option_handler',
1186
- 'help' => __( 'Post MIME Types help.', 'media-library-assistant' ),
1187
- 'std' => array(
1188
- 'all' => array(
1189
- 'singular' => _x( 'All', 'table_view_singular', 'media-library-assistant' ),
1190
- 'plural' => _x( 'All', 'table_view_plural', 'media-library-assistant' ),
1191
- 'specification' => '',
1192
- 'post_mime_type' => false,
1193
- 'table_view' => true,
1194
- 'menu_order' => 0,
1195
- 'description' => _x( 'Built-in view', 'post_mime_types_description', 'media-library-assistant' )
1196
- ),
1197
- 'image' => array(
1198
- 'singular' => _x( 'Image', 'table_view_singular', 'media-library-assistant' ),
1199
- 'plural' => _x( 'Images', 'table_view_plural', 'media-library-assistant' ),
1200
- 'specification' => '',
1201
- 'post_mime_type' => true,
1202
- 'table_view' => true,
1203
- 'menu_order' => 0,
1204
- 'description' => _x( 'All image subtypes', 'post_mime_types_description', 'media-library-assistant' )
1205
- ),
1206
- 'audio' => array(
1207
- 'singular' => _x( 'Audio', 'table_view_singular', 'media-library-assistant' ),
1208
- 'plural' => _x( 'Audio', 'table_view_plural', 'media-library-assistant' ),
1209
- 'specification' => '',
1210
- 'post_mime_type' => true,
1211
- 'table_view' => true,
1212
- 'menu_order' => 0,
1213
- 'description' => _x( 'All audio subtypes', 'post_mime_types_description', 'media-library-assistant' )
1214
- ),
1215
- 'video' => array(
1216
- 'singular' => _x( 'Video', 'table_view_singular', 'media-library-assistant' ),
1217
- 'plural' => _x( 'Video', 'table_view_plural', 'media-library-assistant' ),
1218
- 'specification' => '',
1219
- 'post_mime_type' => true,
1220
- 'table_view' => true,
1221
- 'menu_order' => 0,
1222
- 'description' => _x( 'All video subtypes', 'post_mime_types_description', 'media-library-assistant' )
1223
- ),
1224
- 'text' => array(
1225
- 'singular' => _x( 'Text', 'table_view_singular', 'media-library-assistant' ),
1226
- 'plural' => _x( 'Text', 'table_view_plural', 'media-library-assistant' ),
1227
- 'specification' => '',
1228
- 'post_mime_type' => true,
1229
- 'table_view' => true,
1230
- 'menu_order' => 0,
1231
- 'description' => _x( 'All text subtypes', 'post_mime_types_description', 'media-library-assistant' )
1232
- ),
1233
- 'application' => array(
1234
- 'singular' => _x( 'Application', 'table_view_singular', 'media-library-assistant' ),
1235
- 'plural' => _x( 'Applications', 'table_view_plural', 'media-library-assistant' ),
1236
- 'specification' => '',
1237
- 'post_mime_type' => true,
1238
- 'table_view' => true,
1239
- 'menu_order' => 0,
1240
- 'description' => _x( 'All application subtypes', 'post_mime_types_description', 'media-library-assistant' )
1241
- ),
1242
- 'detached' => array(
1243
- 'singular' => _x( 'Unattached', 'table_view_singular', 'media-library-assistant' ),
1244
- 'plural' => _x( 'Unattached', 'table_view_plural', 'media-library-assistant' ),
1245
- 'specification' => '',
1246
- 'post_mime_type' => false,
1247
- 'table_view' => true,
1248
- 'menu_order' => 0,
1249
- 'description' => _x( 'Built-in view', 'post_mime_types_description', 'media-library-assistant' )
1250
- ),
1251
- 'attached' => array(
1252
- 'singular' => _x( 'Attached', 'table_view_singular', 'media-library-assistant' ),
1253
- 'plural' => _x( 'Attached', 'table_view_plural', 'media-library-assistant' ),
1254
- 'specification' => '',
1255
- 'post_mime_type' => false,
1256
- 'table_view' => true,
1257
- 'menu_order' => 0,
1258
- 'description' => _x( 'Built-in view', 'post_mime_types_description', 'media-library-assistant' )
1259
- ),
1260
- 'trash' => array(
1261
- 'singular' => _x( 'Trash', 'table_view_singular', 'media-library-assistant' ),
1262
- 'plural' => _x( 'Trash', 'table_view_plural', 'media-library-assistant' ),
1263
- 'specification' => '',
1264
- 'post_mime_type' => false,
1265
- 'table_view' => true,
1266
- 'menu_order' => 0,
1267
- 'description' => _x( 'Built-in view', 'post_mime_types_description', 'media-library-assistant' )
1268
- )
1269
- )),
1270
-
1271
- self::MLA_ENABLE_UPLOAD_MIMES =>
1272
- array('tab' => 'upload',
1273
- 'name' => __( 'Enable Upload MIME Type Support', 'media-library-assistant' ),
1274
- 'type' => 'checkbox',
1275
- 'std' => 'checked',
1276
- 'help' => __( 'Check/uncheck this option to enable/disable Upload MIME Type Support, then click <strong>Save Changes</strong> to record the new setting.', 'media-library-assistant' )),
1277
-
1278
- self::MLA_UPLOAD_MIMES =>
1279
- array('tab' => '',
1280
- 'type' => 'custom',
1281
- 'render' => 'mla_upload_mimes_option_handler',
1282
- 'update' => 'mla_upload_mimes_option_handler',
1283
- 'delete' => 'mla_upload_mimes_option_handler',
1284
- 'reset' => 'mla_upload_mimes_option_handler',
1285
- 'help' => __( 'Upload MIME Types help.', 'media-library-assistant' ),
1286
- 'std' => false), // false to detect first-time load; will become an array
1287
-
1288
- self::MLA_ENABLE_MLA_ICONS =>
1289
- array('tab' => 'upload',
1290
- 'name' => __( 'Enable MLA File Type Icons Support', 'media-library-assistant' ),
1291
- 'type' => 'checkbox',
1292
- 'std' => 'checked',
1293
- 'help' => __( 'Check/uncheck this option to enable/disable MLA File Type Icons Support, then click <strong>Save Changes</strong> to record the new setting.', 'media-library-assistant' )),
1294
-
1295
- self::MLA_DEBUG_DISPLAY_LIMIT =>
1296
- array('tab' => 'debug',
1297
- 'name' => __( 'Display Limit', 'media-library-assistant' ),
1298
- 'type' => 'text',
1299
- 'std' => '',
1300
- 'size' => 5,
1301
- 'help' => __( 'Enter the maximum number of debug log characters to display; enter zero or leave blank for no limit.', 'media-library-assistant' )),
1302
-
1303
- self::MLA_DEBUG_FILE =>
1304
- array('tab' => 'debug',
1305
- 'name' => __( 'Debug File', 'media-library-assistant' ),
1306
- 'type' => 'text',
1307
- 'std' => '',
1308
- 'size' => 60,
1309
- 'help' => __( 'Enter the name of an alternate, MLA-specific debug log file; leave blank to use the PHP error_log.', 'media-library-assistant' )),
1310
-
1311
- self::MLA_DEBUG_REPLACE_PHP_LOG =>
1312
- array('tab' => 'debug',
1313
- 'name' => __( 'Replace PHP error_log file', 'media-library-assistant' ),
1314
- 'type' => 'checkbox',
1315
- 'std' => '',
1316
- 'help' => __( 'Check this option to replace the PHP error_log file with the MLA Debug File.<br>&nbsp;&nbsp;allows capture of PHP messages in the MLA Debug File.', 'media-library-assistant' )),
1317
-
1318
- self::MLA_DEBUG_REPLACE_PHP_REPORTING =>
1319
- array('tab' => 'debug',
1320
- 'name' => __( 'PHP Reporting', 'media-library-assistant' ),
1321
- 'type' => 'text',
1322
- 'std' => '',
1323
- 'size' => 10,
1324
- 'help' => __( 'Enter a numeric error_reporting value, e.g., 0x7FFF or 32767; leave blank to use the existing PHP error_reporting value.', 'media-library-assistant' )),
1325
-
1326
- self::MLA_DEBUG_REPLACE_LEVEL =>
1327
- array('tab' => 'debug',
1328
- 'name' => __( 'MLA Reporting', 'media-library-assistant' ),
1329
- 'type' => 'text',
1330
- 'std' => '',
1331
- 'size' => 10,
1332
- 'help' => __( 'Enter a numeric MLA_DEBUG_LEVEL value, e.g., 0x0003 or 3; leave blank to use the existing MLA_DEBUG_LEVEL value.', 'media-library-assistant' )),
1333
-
1334
- /* Here are examples of the other option types
1335
- 'textarea' =>
1336
- array('tab' => '',
1337
- 'name' => 'Text Area',
1338
- 'type' => 'textarea',
1339
- 'std' => 'default text area',
1340
- 'cols' => 60,
1341
- 'rows' => 4,
1342
- 'help' => __( 'Enter the text area...'),
1343
- */
1344
- );
1345
- }
1346
-
1347
- /**
1348
- * Initialize "tax_checked_on_top" => "checked" default for all supported taxonomies
1349
- *
1350
- * Called after all taxonomies are registered, e.g., in MLAObjects::_build_taxonomies.
1351
- *
1352
- * @since 2.02
1353
- *
1354
- * @return void
1355
- */
1356
- public static function mla_initialize_tax_checked_on_top() {
1357
- if ( NULL === self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_checked_on_top'] ) {
1358
- /*
1359
- * WordPress default is 'checked_ontop' => true
1360
- * Initialize tax_checked_on_top defaults to true for all supported taxonomies
1361
- */
1362
- $checked_on_top = array();
1363
- $taxonomies = self::mla_supported_taxonomies();
1364
- foreach ( $taxonomies as $new_key ) {
1365
- $checked_on_top[ $new_key ] = 'checked';
1366
- }
1367
-
1368
- self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_checked_on_top'] = $checked_on_top;
1369
- }
1370
- }
1371
-
1372
- /**
1373
- * Fetch style or markup template from $mla_templates
1374
- *
1375
- * @since 0.80
1376
- *
1377
- * @param string Template name
1378
- * @param string Template type; 'style' (default) or 'markup'
1379
- *
1380
- * @return string|boolean|null requested template, false if not found or null if no templates
1381
- */
1382
- public static function mla_fetch_gallery_template( $key, $type = 'style' ) {
1383
- if ( ! is_array( self::$mla_option_templates ) ) {
1384
- MLA::mla_debug_add( '<strong>mla_debug mla_fetch_gallery_template()</strong> ' . __( 'no templates exist', 'media-library-assistant' ) );
1385
- return null;
1386
- }
1387
-
1388
- $array_key = $key . '-' . $type;
1389
- if ( array_key_exists( $array_key, self::$mla_option_templates ) ) {
1390
- return self::$mla_option_templates[ $array_key ];
1391
- } else {
1392
- MLA::mla_debug_add( "<strong>mla_fetch_gallery_template( {$key}, {$type} )</strong> " . __( 'not found', 'media-library-assistant' ) );
1393
- return false;
1394
- }
1395
  }
1396
 
1397
  /**
@@ -1402,13 +357,13 @@ class MLAOptions {
1402
  * @return array|null name => value for all style templates or null if no templates
1403
  */
1404
  public static function mla_get_style_templates() {
1405
- if ( ! is_array( self::$mla_option_templates ) ) {
1406
- MLA::mla_debug_add( '<strong>mla_debug mla_get_style_templates()</strong> ' . __( 'no templates exist', 'media-library-assistant' ) );
1407
- return null;
1408
  }
1409
 
1410
  $templates = array();
1411
- foreach ( self::$mla_option_templates as $key => $value ) {
1412
  $tail = strrpos( $key, '-style' );
1413
  if ( ! ( false === $tail ) ) {
1414
  $name = substr( $key, 0, $tail );
@@ -1428,8 +383,8 @@ class MLAOptions {
1428
  * @return boolean true if success, false if failure
1429
  */
1430
  public static function mla_put_style_templates( $templates ) {
1431
- if ( self::mla_update_option( 'style_templates', $templates ) ) {
1432
- self::_load_option_templates();
1433
  return true;
1434
  }
1435
 
@@ -1444,13 +399,13 @@ class MLAOptions {
1444
  * @return array|null name => value for all markup templates or null if no templates
1445
  */
1446
  public static function mla_get_markup_templates() {
1447
- if ( ! is_array( self::$mla_option_templates ) ) {
1448
- MLA::mla_debug_add( '<strong>mla_debug mla_get_markup_templates()</strong> ' . __( 'no templates exist', 'media-library-assistant' ) );
1449
- return null;
1450
  }
1451
 
1452
  $templates = array();
1453
- foreach ( self::$mla_option_templates as $key => $value ) {
1454
  // Note order: -row-open must precede -open!
1455
  $tail = strrpos( $key, '-row-open-markup' );
1456
  if ( ! ( false === $tail ) ) {
@@ -1499,8 +454,8 @@ class MLAOptions {
1499
  * @return boolean true if success, false if failure
1500
  */
1501
  public static function mla_put_markup_templates( $templates ) {
1502
- if ( self::mla_update_option( 'markup_templates', $templates ) ) {
1503
- self::_load_option_templates();
1504
  return true;
1505
  }
1506
 
@@ -1510,6 +465,8 @@ class MLAOptions {
1510
  /**
1511
  * Return the stored value or default value of a defined MLA option
1512
  *
 
 
1513
  * @since 0.1
1514
  *
1515
  * @param string Name of the desired option
@@ -1521,32 +478,14 @@ class MLAOptions {
1521
  * @return mixed Value(s) for the option or false if the option is not a defined MLA option
1522
  */
1523
  public static function mla_get_option( $option, $get_default = false, $get_stored = false, $option_table = NULL ) {
1524
- if ( NULL == $option_table ) {
1525
- $option_table = self::$mla_option_definitions;
1526
- }
1527
-
1528
- if ( ! array_key_exists( $option, $option_table ) ) {
1529
- return false;
1530
- }
1531
-
1532
- if ( $get_default ) {
1533
- if ( array_key_exists( 'std', $option_table[ $option ] ) ) {
1534
- return $option_table[ $option ]['std'];
1535
- }
1536
-
1537
- return false;
1538
- } // $get_default
1539
-
1540
- if ( ! $get_stored && array_key_exists( 'std', $option_table[ $option ] ) ) {
1541
- return get_option( MLA_OPTION_PREFIX . $option, $option_table[ $option ]['std'] );
1542
- }
1543
-
1544
- return get_option( MLA_OPTION_PREFIX . $option, false );
1545
  }
1546
 
1547
  /**
1548
  * Add or update the stored value of a defined MLA option
1549
  *
 
 
1550
  * @since 0.1
1551
  *
1552
  * @param string Name of the desired option
@@ -1556,20 +495,14 @@ class MLAOptions {
1556
  * @return boolean True if the value was changed or false if the update failed
1557
  */
1558
  public static function mla_update_option( $option, $newvalue, $option_table = NULL ) {
1559
- if ( NULL == $option_table ) {
1560
- $option_table = self::$mla_option_definitions;
1561
- }
1562
-
1563
- if ( array_key_exists( $option, $option_table ) ) {
1564
- return update_option( MLA_OPTION_PREFIX . $option, $newvalue );
1565
- }
1566
-
1567
- return false;
1568
  }
1569
 
1570
  /**
1571
  * Delete the stored value of a defined MLA option
1572
  *
 
 
1573
  * @since 0.1
1574
  *
1575
  * @param string Name of the desired option
@@ -1578,21 +511,15 @@ class MLAOptions {
1578
  * @return boolean True if the option was deleted, otherwise false
1579
  */
1580
  public static function mla_delete_option( $option, $option_table = NULL ) {
1581
- if ( NULL == $option_table ) {
1582
- $option_table = self::$mla_option_definitions;
1583
- }
1584
-
1585
- if ( array_key_exists( $option, $option_table ) ) {
1586
- return delete_option( MLA_OPTION_PREFIX . $option );
1587
- }
1588
-
1589
- return false;
1590
  }
1591
 
1592
  /**
1593
  * Determine MLA support for a taxonomy, handling the special case where the
1594
  * settings are being updated or reset.
1595
  *
 
 
1596
  * @since 0.30
1597
  *
1598
  * @param string Taxonomy name, e.g., attachment_category
@@ -1602,77 +529,15 @@ class MLAOptions {
1602
  * true if the taxonomy is supported in this way else false.
1603
  * string if $tax_name is '' and $support_type is 'filter', returns the taxonomy to filter by.
1604
  */
1605
- public static function mla_taxonomy_support($tax_name, $support_type = 'support') {
1606
- $tax_options = MLAOptions::mla_get_option( self::MLA_TAXONOMY_SUPPORT );
1607
-
1608
- switch ( $support_type ) {
1609
- case 'support':
1610
- if ( !empty( $_REQUEST['mla-general-options-save'] ) ) {
1611
- return isset( $_REQUEST['tax_support'][ $tax_name ] );
1612
- } elseif ( !empty( $_REQUEST['mla-general-options-reset'] ) ) {
1613
- return array_key_exists( $tax_name, self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_support'] );
1614
- }
1615
-
1616
- $tax_support = isset( $tax_options['tax_support'] ) ? $tax_options['tax_support'] : self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_support'];
1617
- return array_key_exists( $tax_name, $tax_support );
1618
- case 'quick-edit':
1619
- if ( !empty( $_REQUEST['mla-general-options-save'] ) ) {
1620
- return isset( $_REQUEST['tax_quick_edit'][ $tax_name ] );
1621
- } elseif ( !empty( $_REQUEST['mla-general-options-reset'] ) ) {
1622
- return array_key_exists( $tax_name, self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_quick_edit'] );
1623
- }
1624
-
1625
- $tax_quick_edit = isset( $tax_options['tax_quick_edit'] ) ? $tax_options['tax_quick_edit'] : self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_quick_edit'];
1626
- return array_key_exists( $tax_name, $tax_quick_edit );
1627
- case 'term-search':
1628
- if ( !empty( $_REQUEST['mla-general-options-save'] ) ) {
1629
- return isset( $_REQUEST['tax_term_search'][ $tax_name ] );
1630
- } elseif ( !empty( $_REQUEST['mla-general-options-reset'] ) ) {
1631
- return array_key_exists( $tax_name, self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_term_search'] );
1632
- }
1633
-
1634
- $tax_term_search = isset( $tax_options['tax_term_search'] ) ? $tax_options['tax_term_search'] : self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_term_search'];
1635
- return array_key_exists( $tax_name, $tax_term_search );
1636
- case 'flat-checklist':
1637
- if ( !empty( $_REQUEST['mla-general-options-save'] ) ) {
1638
- return isset( $_REQUEST['tax_flat_checklist'][ $tax_name ] );
1639
- } elseif ( !empty( $_REQUEST['mla-general-options-reset'] ) ) {
1640
- return array_key_exists( $tax_name, self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_flat_checklist'] );
1641
- }
1642
-
1643
- $tax_flat_checklist = isset( $tax_options['tax_flat_checklist'] ) ? $tax_options['tax_flat_checklist'] : self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_flat_checklist'];
1644
- return array_key_exists( $tax_name, $tax_flat_checklist );
1645
- case 'checked-on-top':
1646
- if ( !empty( $_REQUEST['mla-general-options-save'] ) ) {
1647
- return isset( $_REQUEST['tax_checked_on_top'][ $tax_name ] );
1648
- } elseif ( !empty( $_REQUEST['mla-general-options-reset'] ) ) {
1649
- return array_key_exists( $tax_name, self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_checked_on_top'] );
1650
- }
1651
-
1652
- $tax_checked_on_top = isset( $tax_options['tax_checked_on_top'] ) ? $tax_options['tax_checked_on_top'] : self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_checked_on_top'];
1653
- return array_key_exists( $tax_name, $tax_checked_on_top );
1654
- case 'filter':
1655
- $tax_filter = isset( $tax_options['tax_filter'] ) ? $tax_options['tax_filter'] : self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_filter'];
1656
- if ( '' == $tax_name ) {
1657
- return $tax_filter;
1658
- }
1659
-
1660
- if ( !empty( $_REQUEST['mla-general-options-save'] ) ) {
1661
- $tax_filter = isset( $_REQUEST['tax_filter'] ) ? $_REQUEST['tax_filter'] : '';
1662
- return ( $tax_name == $tax_filter );
1663
- } elseif ( !empty( $_REQUEST['mla-general-options-reset'] ) ) {
1664
- return array_key_exists( $tax_name, self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_filter'] );
1665
- }
1666
-
1667
- return ( $tax_name == $tax_filter );
1668
- default:
1669
- return false;
1670
- } // $support_type
1671
  } // mla_taxonomy_support
1672
 
1673
  /**
1674
  * Returns an array of taxonomy names assigned to $support_type
1675
  *
 
 
1676
  * @since 1.90
1677
  *
1678
  * @param string Optional. 'support' (default), 'quick-edit', 'flat-checklist', 'term-search' or 'filter'
@@ -1680,59 +545,7 @@ class MLAOptions {
1680
  * @return array taxonomies assigned to $support_type; can be empty.
1681
  */
1682
  public static function mla_supported_taxonomies($support_type = 'support') {
1683
- $tax_options = MLAOptions::mla_get_option( self::MLA_TAXONOMY_SUPPORT );
1684
- switch ( $support_type ) {
1685
- case 'support':
1686
- if ( !empty( $_REQUEST['mla-general-options-save'] ) ) {
1687
- return isset( $_REQUEST['tax_support'] ) ? array_keys( $_REQUEST['tax_support'] ) : array();
1688
- } elseif ( !empty( $_REQUEST['mla-general-options-reset'] ) ) {
1689
- return array_keys( self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_support'] );
1690
- }
1691
-
1692
- return array_keys( isset( $tax_options['tax_support'] ) ? $tax_options['tax_support'] : self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_support'] );
1693
- case 'quick-edit':
1694
- if ( !empty( $_REQUEST['mla-general-options-save'] ) ) {
1695
- return isset( $_REQUEST['tax_quick_edit'] ) ? array_keys( $_REQUEST['tax_quick_edit'] ) : array();
1696
- } elseif ( !empty( $_REQUEST['mla-general-options-reset'] ) ) {
1697
- return array_keys( self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_quick_edit'] );
1698
- }
1699
-
1700
- return array_keys( isset( $tax_options['tax_quick_edit'] ) ? $tax_options['tax_quick_edit'] : self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_quick_edit'] );
1701
- case 'term-search':
1702
- if ( !empty( $_REQUEST['mla-general-options-save'] ) ) {
1703
- return isset( $_REQUEST['tax_term_search'] ) ? array_keys( $_REQUEST['tax_term_search'] ) : array();
1704
- } elseif ( !empty( $_REQUEST['mla-general-options-reset'] ) ) {
1705
- return array_keys( self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_term_search'] );
1706
- }
1707
-
1708
- return array_keys( isset( $tax_options['tax_term_search'] ) ? $tax_options['tax_term_search'] : self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_term_search'] );
1709
- case 'flat-checklist':
1710
- if ( !empty( $_REQUEST['mla-general-options-save'] ) ) {
1711
- return isset( $_REQUEST['tax_flat_checklist'] ) ? array_keys( $_REQUEST['tax_flat_checklist'] ) : array();
1712
- } elseif ( !empty( $_REQUEST['mla-general-options-reset'] ) ) {
1713
- return array_keys( self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_flat_checklist'] );
1714
- }
1715
-
1716
- return array_keys( isset( $tax_options['tax_flat_checklist'] ) ? $tax_options['tax_flat_checklist'] : self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_flat_checklist'] );
1717
- case 'checked-on-top':
1718
- if ( !empty( $_REQUEST['mla-general-options-save'] ) ) {
1719
- return isset( $_REQUEST['tax_checked_on_top'] ) ? array_keys( $_REQUEST['tax_checked_on_top'] ) : array();
1720
- } elseif ( !empty( $_REQUEST['mla-general-options-reset'] ) ) {
1721
- return array_keys( self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_checked_on_top'] );
1722
- }
1723
-
1724
- return array_keys( isset( $tax_options['tax_checked_on_top'] ) ? $tax_options['tax_checked_on_top'] : self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_checked_on_top'] );
1725
- case 'filter':
1726
- if ( !empty( $_REQUEST['mla-general-options-save'] ) ) {
1727
- return isset( $_REQUEST['tax_filter'] ) ? (array) $_REQUEST['tax_filter'] : array();
1728
- } elseif ( !empty( $_REQUEST['mla-general-options-reset'] ) ) {
1729
- return (array) self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_filter'];
1730
- }
1731
-
1732
- return (array) isset( $tax_options['tax_filter'] ) ? $tax_options['tax_filter'] : self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_filter'];
1733
- default:
1734
- return array();
1735
- } // $support_type
1736
  } // mla_supported_taxonomies
1737
 
1738
  /**
@@ -1748,7 +561,7 @@ class MLAOptions {
1748
  *
1749
  * @return string HTML table row markup for 'render' else message(s) reflecting the results of the operation.
1750
  */
1751
- public static function mla_attachment_display_settings_option_handler( $action, $key, $value, $args = null ) {
1752
  switch ( $action ) {
1753
  case 'render':
1754
  $current_value = get_option( $key );
@@ -1812,17 +625,17 @@ class MLAOptions {
1812
  *
1813
  * @return string HTML table row markup for 'render' else message(s) reflecting the results of the operation.
1814
  */
1815
- public static function mla_taxonomy_option_handler( $action, $key, $value, $args = null ) {
1816
  switch ( $action ) {
1817
  case 'render':
1818
  $taxonomies = get_taxonomies( array ( 'show_ui' => true ), 'objects' );
1819
- $current_values = self::mla_get_option( $key );
1820
- $tax_support = isset( $current_values['tax_support'] ) ? $current_values['tax_support'] : self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_support'];
1821
- $tax_quick_edit = isset( $current_values['tax_quick_edit'] ) ? $current_values['tax_quick_edit'] : self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_quick_edit'];
1822
- $tax_term_search = isset( $current_values['tax_term_search'] ) ? $current_values['tax_term_search'] : self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_term_search'];
1823
- $tax_flat_checklist = isset( $current_values['tax_flat_checklist'] ) ? $current_values['tax_flat_checklist'] : self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_flat_checklist'];
1824
- $tax_checked_on_top = isset( $current_values['tax_checked_on_top'] ) ? $current_values['tax_checked_on_top'] : self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_checked_on_top'];
1825
- $tax_filter = isset( $current_values['tax_filter'] ) ? $current_values['tax_filter'] : self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_filter'];
1826
 
1827
  /*
1828
  * Always display our own taxonomies, even if not registered.
@@ -1859,7 +672,7 @@ class MLAOptions {
1859
  }
1860
  }
1861
 
1862
- $taxonomy_row = self::$mla_option_templates['taxonomy-row'];
1863
  $row = '';
1864
 
1865
  foreach ( $taxonomies as $tax_name => $tax_object ) {
@@ -1897,15 +710,15 @@ class MLAOptions {
1897
  'help' => $value['help']
1898
  );
1899
 
1900
- return MLAData::mla_parse_template( self::$mla_option_templates['taxonomy-table'], $option_values );
1901
  case 'update':
1902
  case 'delete':
1903
- $tax_support = isset( $args['tax_support'] ) ? $args['tax_support'] : self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_support'];
1904
- $tax_quick_edit = isset( $args['tax_quick_edit'] ) ? $args['tax_quick_edit'] : self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_quick_edit'];
1905
- $tax_term_search = isset( $args['tax_term_search'] ) ? $args['tax_term_search'] : self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_term_search'];
1906
- $tax_flat_checklist = isset( $args['tax_flat_checklist'] ) ? $args['tax_flat_checklist'] : self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_flat_checklist'];
1907
- $tax_checked_on_top = isset( $args['tax_checked_on_top'] ) ? $args['tax_checked_on_top'] : self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_checked_on_top'];
1908
- $tax_filter = isset( $args['tax_filter'] ) ? $args['tax_filter'] : self::$mla_option_definitions[ self::MLA_TAXONOMY_SUPPORT ]['std']['tax_filter'];
1909
 
1910
  $msg = '';
1911
 
@@ -1958,7 +771,7 @@ class MLAOptions {
1958
  'tax_filter' => $tax_filter
1959
  );
1960
 
1961
- self::mla_update_option( $key, $value );
1962
 
1963
  if ( empty( $msg ) ) {
1964
  /* translators: 1: option name, e.g., taxonomy_support */
@@ -1967,7 +780,7 @@ class MLAOptions {
1967
 
1968
  return $msg;
1969
  case 'reset':
1970
- self::mla_delete_option( $key );
1971
  /* translators: 1: option name, e.g., taxonomy_support */
1972
  return '<br>' . sprintf( __( 'Reset custom %1$s', 'media-library-assistant' ), $key ) . "\r\n";
1973
  default:
@@ -1989,12 +802,12 @@ class MLAOptions {
1989
  *
1990
  * @return string HTML table row markup for 'render' else message(s) reflecting the results of the operation.
1991
  */
1992
- public static function mla_search_option_handler( $action, $key, $value, $args = null ) {
1993
  switch ( $action ) {
1994
  case 'render':
1995
- $current_values = self::mla_get_option( $key );
1996
- $search_connector = isset( $current_values['search_connector'] ) ? $current_values['search_connector'] : self::$mla_option_definitions[ self::MLA_SEARCH_MEDIA_FILTER_DEFAULTS ]['std']['search_connector'];
1997
- $search_fields = isset( $current_values['search_fields'] ) ? $current_values['search_fields'] : self::$mla_option_definitions[ self::MLA_SEARCH_MEDIA_FILTER_DEFAULTS ]['std']['search_fields'];
1998
 
1999
  $option_values = array (
2000
  'and_checked' => ( 'AND' == $search_connector ) ? 'checked="checked"' : '',
@@ -2018,14 +831,14 @@ class MLAOptions {
2018
 
2019
  'terms_checked' => ( in_array( 'terms', $search_fields ) ) ? 'checked="checked"' : '',
2020
  'Terms' => __( 'Terms', 'media-library-assistant' ),
2021
- 'help' => self::$mla_option_definitions[ self::MLA_SEARCH_MEDIA_FILTER_DEFAULTS ]['help']
2022
  );
2023
 
2024
- return MLAData::mla_parse_template( self::$mla_option_templates['search-table'], $option_values );
2025
  case 'update':
2026
  case 'delete':
2027
- $search_connector = isset( $args['search_connector'] ) ? $args['search_connector'] : self::$mla_option_definitions[ self::MLA_SEARCH_MEDIA_FILTER_DEFAULTS ]['std']['search_connector'];
2028
- $search_fields = isset( $args['search_fields'] ) ? $args['search_fields'] : self::$mla_option_definitions[ self::MLA_SEARCH_MEDIA_FILTER_DEFAULTS ]['std']['search_fields'];
2029
 
2030
  $msg = '';
2031
 
@@ -2034,7 +847,7 @@ class MLAOptions {
2034
  'search_fields' => $search_fields,
2035
  );
2036
 
2037
- self::mla_update_option( $key, $value );
2038
 
2039
  if ( empty( $msg ) ) {
2040
  /* translators: 1: option name, e.g., taxonomy_support */
@@ -2043,7 +856,7 @@ class MLAOptions {
2043
 
2044
  return $msg;
2045
  case 'reset':
2046
- self::mla_delete_option( $key );
2047
  /* translators: 1: option name, e.g., taxonomy_support */
2048
  return '<br>' . sprintf( __( 'Reset custom %1$s', 'media-library-assistant' ), $key ) . "\r\n";
2049
  default:
@@ -2136,7 +949,7 @@ class MLAOptions {
2136
  * @return void
2137
  */
2138
  public static function mla_add_attachment_action( $post_ID ) {
2139
- self::$add_attachment_id = $post_ID;
2140
  do_action('mla_add_attachment', $post_ID);
2141
  } // mla_add_attachment_action
2142
 
@@ -2188,13 +1001,13 @@ class MLAOptions {
2188
  */
2189
  public static function mla_update_attachment_metadata_filter( $data, $post_id ) {
2190
  $options = array ();
2191
- $options['is_upload'] = self::$add_attachment_id == $post_id;
2192
- self::$add_attachment_id = 0;
2193
 
2194
- $options['enable_iptc_exif_mapping'] = 'checked' == MLAOptions::mla_get_option( 'enable_iptc_exif_mapping' );
2195
- $options['enable_custom_field_mapping'] = 'checked' == MLAOptions::mla_get_option( 'enable_custom_field_mapping' );
2196
- $options['enable_iptc_exif_update'] = 'checked' == MLAOptions::mla_get_option( 'enable_iptc_exif_update' );
2197
- $options['enable_custom_field_update'] = 'checked' == MLAOptions::mla_get_option( 'enable_custom_field_update' );
2198
 
2199
  $options = apply_filters( 'mla_update_attachment_metadata_options', $options, $data, $post_id );
2200
  $data = apply_filters( 'mla_update_attachment_metadata_prefilter', $data, $post_id, $options );
@@ -2207,7 +1020,7 @@ class MLAOptions {
2207
  if ( $options['enable_iptc_exif_mapping'] ) {
2208
  $item = get_post( $post_id );
2209
  $updates = MLAOptions::mla_evaluate_iptc_exif_mapping( $item, 'iptc_exif_mapping', NULL, $data, true );
2210
- $updates = self::_update_attachment_metadata( $updates, $data );
2211
 
2212
  if ( !empty( $updates ) ) {
2213
  $item_content = MLAData::mla_update_single_item( $post_id, $updates );
@@ -2216,7 +1029,7 @@ class MLAOptions {
2216
 
2217
  if ( $options['enable_custom_field_mapping'] ) {
2218
  $updates = MLAOptions::mla_evaluate_custom_field_mapping( $post_id, 'single_attachment_mapping', NULL, $data );
2219
- $updates = self::_update_attachment_metadata( $updates, $data );
2220
 
2221
  if ( !empty( $updates ) ) {
2222
  $item_content = MLAData::mla_update_single_item( $post_id, $updates );
@@ -2234,7 +1047,7 @@ class MLAOptions {
2234
  if ( $options['enable_iptc_exif_update'] ) {
2235
  $item = get_post( $post_id );
2236
  $updates = MLAOptions::mla_evaluate_iptc_exif_mapping( $item, 'iptc_exif_mapping', NULL, $data );
2237
- $updates = self::_update_attachment_metadata( $updates, $data );
2238
 
2239
  if ( !empty( $updates ) ) {
2240
  $item_content = MLAData::mla_update_single_item( $post_id, $updates );
@@ -2243,7 +1056,7 @@ class MLAOptions {
2243
 
2244
  if ( $options['enable_custom_field_update'] ) {
2245
  $updates = MLAOptions::mla_evaluate_custom_field_mapping( $post_id, 'single_attachment_mapping', NULL, $data );
2246
- $updates = self::_update_attachment_metadata( $updates, $data );
2247
 
2248
  if ( !empty( $updates ) ) {
2249
  $item_content = MLAData::mla_update_single_item( $post_id, $updates );
@@ -2260,283 +1073,9 @@ class MLAOptions {
2260
  } // mla_update_attachment_metadata_filter
2261
 
2262
  /**
2263
- * Fetch custom field option value given a slug
2264
- *
2265
- * @since 1.10
2266
- *
2267
- * @param string slug, e.g., 'c_File Size' for the 'File Size' field
2268
- *
2269
- * @return array option value, e.g., array( 'name' => 'File Size', ... )
2270
- */
2271
- public static function mla_custom_field_option_value( $slug ) {
2272
- $option_values = self::mla_get_option( 'custom_field_mapping' );
2273
-
2274
- foreach ( $option_values as $key => $value ) {
2275
- if ( $slug == 'c_' . $value['name'] ) {
2276
- return $value;
2277
- }
2278
- }
2279
-
2280
- return array();
2281
- } // mla_custom_field_option_value
2282
-
2283
- /**
2284
- * Evaluate file information for custom field mapping
2285
- *
2286
- * @since 1.10
2287
  *
2288
- * @param string array format; 'default_columns' (default), 'default_hidden_columns', 'default_sortable_columns', 'quick_edit' or 'bulk_edit'
2289
- *
2290
- * @return array default, hidden, sortable quick_edit or bulk_edit colums in appropriate format
2291
- */
2292
- public static function mla_custom_field_support( $support_type = 'default_columns' ) {
2293
- $option_values = self::mla_get_option( 'custom_field_mapping' );
2294
- $results = array();
2295
- $index = 0;
2296
-
2297
- foreach ( $option_values as $key => $value ) {
2298
- $slug = 'c_' . $index++; // sanitize_title( $key ); Didn't handle HTML in name, e.g., "R><B"
2299
-
2300
- switch( $support_type ) {
2301
- case 'custom_columns':
2302
- if ( $value['mla_column'] ) {
2303
- $results[ $slug ] = $value['name'];
2304
- }
2305
- break;
2306
- case 'default_columns':
2307
- if ( $value['mla_column'] ) {
2308
- $results[ $slug ] = esc_html( $value['name'] );
2309
- }
2310
- break;
2311
- case 'default_hidden_columns':
2312
- if ( $value['mla_column'] ) {
2313
- $results[] = $slug;
2314
- }
2315
- break;
2316
- case 'custom_sortable_columns':
2317
- if ( $value['mla_column'] ) {
2318
- // columns without NULL values should sort descending
2319
- $results[ $slug ] = array( $value['name'], $value['no_null'] );
2320
- }
2321
- break;
2322
- case 'default_sortable_columns':
2323
- if ( $value['mla_column'] ) {
2324
- // columns without NULL values should sort descending
2325
- $results[ $slug ] = array( $slug, $value['no_null'] );
2326
- }
2327
- break;
2328
- case 'quick_edit':
2329
- if ( $value['quick_edit'] ) {
2330
- $results[ $slug ] = $value;
2331
- }
2332
- break;
2333
- case 'bulk_edit':
2334
- if ( $value['bulk_edit'] ) {
2335
- $results[ $slug ] = $value;
2336
- }
2337
- break;
2338
- } // switch support_type
2339
- } // foreach option_value
2340
-
2341
- return $results;
2342
- } // mla_custom_field_support
2343
-
2344
- /**
2345
- * Evaluate file information for custom field mapping
2346
- *
2347
- * @since 1.10
2348
- *
2349
- * @param string absolute path the the uploads base directory
2350
- * @param array _wp_attached_file meta_value array, indexed by post_id
2351
- * @param array _wp_attachment_metadata meta_value array, indexed by post_id
2352
- * @param integer post->ID of attachment
2353
- *
2354
- * @return array absolute_path_raw, absolute_path, absolute_file_name_raw, absolute_file_name, absolute_file, base_file, path, file_name, extension, dimensions, width, height, hwstring_small, array of intermediate sizes
2355
- */
2356
- private static function _evaluate_file_information( $upload_dir, &$wp_attached_files, &$wp_attachment_metadata, $post_id ) {
2357
- $results = array(
2358
- 'absolute_path_raw' => '',
2359
- 'absolute_path' => '',
2360
- 'absolute_file_name_raw' => '',
2361
- 'absolute_file_name' => '',
2362
- 'base_file' => '',
2363
- 'path' => '',
2364
- 'file_name' => '',
2365
- 'name_only' => '',
2366
- 'extension' => '',
2367
- 'width' => '',
2368
- 'height' => '',
2369
- 'orientation' => '',
2370
- 'hwstring_small' => '',
2371
- 'sizes' => array()
2372
- );
2373
-
2374
- $base_file = isset( $wp_attached_files[ $post_id ]->meta_value ) ? $wp_attached_files[ $post_id ]->meta_value : '';
2375
- $sizes = array();
2376
-
2377
- if ( isset( $wp_attachment_metadata[ $post_id ]->meta_value ) ) {
2378
- $attachment_metadata = @unserialize( $wp_attachment_metadata[ $post_id ]->meta_value );
2379
- if ( ! is_array( $attachment_metadata ) ) {
2380
- $attachment_metadata = array();
2381
- }
2382
- } else {
2383
- $attachment_metadata = array();
2384
- }
2385
-
2386
- if ( !empty( $attachment_metadata ) ) {
2387
- if ( isset( $attachment_metadata['image_meta'] ) ) {
2388
- foreach ( $attachment_metadata['image_meta'] as $key => $value )
2389
- $results[ $key ] = $value;
2390
- }
2391
-
2392
- $sizes = isset( $attachment_metadata['sizes'] ) ? $attachment_metadata['sizes'] : array();
2393
-
2394
- if ( isset( $attachment_metadata['width'] ) ) {
2395
- $results['width'] = $attachment_metadata['width'];
2396
- $width = absint( $results['width'] );
2397
- } else {
2398
- $width = 0;
2399
- }
2400
-
2401
- if ( isset( $attachment_metadata['height'] ) ) {
2402
- $results['height'] = $attachment_metadata['height'];
2403
- $height = absint( $results['height'] );
2404
- } else {
2405
- $height = 0;
2406
- }
2407
-
2408
- if ( $width && $height ) {
2409
- $results['orientation'] = ( $height > $width ) ? 'portrait' : 'landscape';
2410
- }
2411
-
2412
- $results['hwstring_small'] = isset( $attachment_metadata['hwstring_small'] ) ? $attachment_metadata['hwstring_small'] : '';
2413
- }
2414
-
2415
- if ( ! empty( $base_file ) ) {
2416
- $pathinfo = pathinfo( $base_file );
2417
- $results['base_file'] = $base_file;
2418
- if ( '.' == $pathinfo['dirname'] ) {
2419
- $results['absolute_path_raw'] = $upload_dir;
2420
- $results['absolute_path'] = wptexturize( str_replace( '\\', '/', $upload_dir ) );
2421
- $results['path'] = '';
2422
- } else {
2423
- $results['absolute_path_raw'] = $upload_dir . $pathinfo['dirname'] . '/';
2424
- $results['absolute_path'] = wptexturize( str_replace( '\\', '/', $results['absolute_path_raw'] ) );
2425
- $results['path'] = wptexturize( $pathinfo['dirname'] . '/' );
2426
- }
2427
-
2428
- $results['absolute_file_name_raw'] = $results['absolute_path_raw'] . $pathinfo['basename'];
2429
- $results['absolute_file_name'] = wptexturize( str_replace( '\\', '/', $results['absolute_file_name_raw'] ) );
2430
- $results['file_name'] = wptexturize( $pathinfo['basename'] );
2431
- $results['name_only'] = wptexturize( $pathinfo['filename'] );
2432
- $results['extension'] = wptexturize( $pathinfo['extension'] );
2433
- }
2434
-
2435
- $results['sizes'] = $sizes;
2436
- return $results;
2437
- } // _evaluate_file_information
2438
-
2439
- /**
2440
- * Evaluate post information for custom field mapping
2441
- *
2442
- * @since 1.40
2443
- *
2444
- * @param integer post->ID of attachment
2445
- * @param string category/scope to evaluate against: custom_field_mapping or single_attachment_mapping
2446
- * @param string data source name ( post_date or post_parent )
2447
- *
2448
- * @return mixed (string)/'' or (integer)/0 depending on $data_source type
2449
- */
2450
- private static function _evaluate_post_information( $post_id, $category, $data_source ) {
2451
- global $wpdb;
2452
- static $post_info = NULL;
2453
-
2454
- if ( 0 == $post_id ) {
2455
- $value = NULL;
2456
- } else {
2457
- /*
2458
- * Check for $post_id match
2459
- */
2460
- if ( 'single_attachment_mapping' == $category && ! isset( $post_info[$post_id] ) ) {
2461
- $post_info = NULL;
2462
- }
2463
-
2464
- if ( NULL == $post_info ) {
2465
- if ( 'custom_field_mapping' == $category ) {
2466
- $post_info = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} WHERE post_type = 'attachment'", OBJECT_K );
2467
- } else {
2468
- $post_info = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} WHERE ID = '{$post_id}'", OBJECT_K );
2469
- }
2470
- }
2471
-
2472
- if ( 'post_id' == $data_source ) {
2473
- $data_source = 'ID';
2474
- }
2475
-
2476
- if ( isset( $post_info[$post_id] ) && property_exists( $post_info[$post_id], $data_source ) ) {
2477
- $post_array = (array) $post_info[$post_id];
2478
- $value = $post_array[ $data_source ];
2479
- } else {
2480
- $value = NULL;
2481
- }
2482
- }
2483
-
2484
- switch ( $data_source ) {
2485
- case 'ID':
2486
- case 'post_id':
2487
- case 'post_author':
2488
- case 'post_parent':
2489
- case 'menu_order':
2490
- case 'comment_count':
2491
- return ( NULL !== $value ) ? $value : 0;
2492
- default:
2493
- return ( NULL !== $value ) ? $value : '';
2494
- }
2495
-
2496
- return false;
2497
- } // _evaluate_post_information
2498
-
2499
- /**
2500
- * Evaluate post information for custom field mapping
2501
- *
2502
- * @since 1.40
2503
- *
2504
- * @param array field value(s)
2505
- * @param string format option text|single|export|array|multi
2506
- * @param boolean keep existing value(s) - for 'multi' option
2507
- *
2508
- * @return mixed array for option = array|multi else string
2509
- */
2510
- private static function _evaluate_array_result( $value, $option, $keep_existing ) {
2511
- if ( empty( $value ) ) {
2512
- return '';
2513
- }
2514
-
2515
- if ( is_array( $value ) ) {
2516
- if ( 'single' == $option || 1 == count( $value ) ) {
2517
- return current( $value );
2518
- } elseif ( 'export' == $option ) {
2519
- return var_export( $value, true );
2520
- } elseif ( 'text' == $option ) {
2521
- return implode( ',', $value );
2522
- } elseif ( 'multi' == $option ) {
2523
- $value[0x80000000] = $option;
2524
- $value[0x80000001] = $keep_existing;
2525
- return $value;
2526
- }
2527
- }
2528
-
2529
- /*
2530
- * $option = array returns the array
2531
- */
2532
- return $value;
2533
- } // _evaluate_array_result
2534
-
2535
- /**
2536
- * Get IPTC/EXIF or custom field mapping data source
2537
- *
2538
- * Defined as public so MLA Mapping Hooks clients can call it.
2539
- * Isolates clients from changes to _evaluate_data_source().
2540
  *
2541
  * @since 1.70
2542
  *
@@ -2548,23 +1087,17 @@ class MLAOptions {
2548
  * @return string|array data source value
2549
  */
2550
  public static function mla_get_data_source( $post_id, $category, $data_value, $attachment_metadata = NULL ) {
2551
- $default_arguments = array(
2552
- 'data_source' => 'none',
2553
- 'keep_existing' => true,
2554
- 'format' => 'native',
2555
- 'meta_name' => '',
2556
- 'option' => 'text',
2557
- );
2558
- $data_value = shortcode_atts( $default_arguments, $data_value );
2559
 
2560
- return self::_evaluate_data_source( $post_id, $category, $data_value, $attachment_metadata = NULL );
2561
  } // mla_get_data_source
2562
 
2563
  /**
2564
- * Identify custom field mapping data source
2565
  *
2566
- * Determines whether a name matches any of the element-level data source dropdown options, i.e.,
2567
- * excludes "template:" and "meta:" values.
2568
  *
2569
  * @since 1.80
2570
  *
@@ -2573,484 +1106,12 @@ class MLAOptions {
2573
  * @return boolean true if candidate name matches a data source
2574
  */
2575
  public static function mla_is_data_source( $candidate_name ) {
2576
- static $intermediate_sizes = NULL;
2577
-
2578
- /*
2579
- * The [size] elements are expanded with available image sizes;
2580
- * convert valid sizes back to the generic [size] value to match the list.
2581
- */
2582
- $match_count = preg_match( '/(.+)\[(.+)\]/', $candidate_name, $matches );
2583
- if ( 1 == $match_count ) {
2584
- if ( NULL === $intermediate_sizes ) {
2585
- $intermediate_sizes = get_intermediate_image_sizes();
2586
- }
2587
-
2588
- if ( in_array( $matches[2], $intermediate_sizes ) ) {
2589
- $candidate_name = $matches[1] . '[size]';
2590
- } else {
2591
- return false;
2592
- }
2593
  }
2594
 
2595
- return in_array( $candidate_name, self::$custom_field_data_sources );
2596
- } // mla_is_data_source
2597
-
2598
- /**
2599
- * Evaluate custom field mapping data source
2600
- *
2601
- * @since 1.10
2602
- *
2603
- * @param integer post->ID of attachment
2604
- * @param string category/scope to evaluate against: custom_field_mapping or single_attachment_mapping
2605
- * @param array data source specification ( name, *data_source, *keep_existing, *format, mla_column, quick_edit, bulk_edit, *meta_name, *option, no_null )
2606
- * @param array (optional) _wp_attachment_metadata, default NULL (use current postmeta database value)
2607
- *
2608
- * @return string|array data source value
2609
- */
2610
- private static function _evaluate_data_source( $post_id, $category, $data_value, $attachment_metadata = NULL ) {
2611
- global $wpdb;
2612
- static $upload_dir, $intermediate_sizes = NULL, $wp_attached_files = NULL, $wp_attachment_metadata = NULL;
2613
- static $current_id = 0, $file_info = NULL, $parent_info = NULL, $references = NULL, $alt_text = NULL;
2614
-
2615
- if ( 'none' == $data_value['data_source'] ) {
2616
- return '';
2617
- }
2618
-
2619
- $data_source = $data_value['data_source'];
2620
-
2621
- /*
2622
- * Do this once per page load; cache attachment metadata if mapping all attachments
2623
- */
2624
- if ( NULL == $intermediate_sizes ) {
2625
- $upload_dir = wp_upload_dir();
2626
- $upload_dir = $upload_dir['basedir'] . '/';
2627
- $intermediate_sizes = get_intermediate_image_sizes();
2628
-
2629
- if ( 'custom_field_mapping' == $category ) {
2630
- if ( ! $table = _get_meta_table('post') ) {
2631
- $wp_attached_files = array();
2632
- $wp_attachment_metadata = array();
2633
- } else {
2634
- $wp_attachment_metadata = $wpdb->get_results( "SELECT post_id, meta_value FROM {$table} WHERE meta_key = '_wp_attachment_metadata'", OBJECT_K );
2635
- $wp_attached_files = $wpdb->get_results( "SELECT post_id, meta_value FROM {$table} WHERE meta_key = '_wp_attached_file'", OBJECT_K );
2636
- }
2637
- } // custom_field_mapping, i.e., mapping all attachments
2638
- } // first call after page load
2639
-
2640
- /*
2641
- * Do this once per post. Simulate SQL results for $wp_attached_files and $wp_attachment_metadata.
2642
- */
2643
- if ( $current_id != $post_id ) {
2644
- $current_id = $post_id;
2645
- $parent_info = NULL;
2646
- $references = NULL;
2647
- $alt_text = NULL;
2648
-
2649
- if ( 'single_attachment_mapping' == $category ) {
2650
- $metadata = get_metadata( 'post', $post_id, '_wp_attached_file' );
2651
- if ( isset( $metadata[0] ) ) {
2652
- $wp_attached_files = array( $post_id => (object) array( 'post_id' => $post_id, 'meta_value' => $metadata[0] ) );
2653
- } else {
2654
- $wp_attached_files = array();
2655
- }
2656
-
2657
- if ( NULL == $attachment_metadata ) {
2658
- $metadata = get_metadata( 'post', $post_id, '_wp_attachment_metadata' );
2659
- if ( isset( $metadata[0] ) ) {
2660
- $attachment_metadata = $metadata[0];
2661
- }
2662
- }
2663
-
2664
- if ( empty( $attachment_metadata ) ) {
2665
- $attachment_metadata = array();
2666
- }
2667
-
2668
- $wp_attachment_metadata = array( $post_id => (object) array( 'post_id' => $post_id, 'meta_value' => serialize( $attachment_metadata ) ) );
2669
- }
2670
-
2671
- $file_info = self::_evaluate_file_information( $upload_dir, $wp_attached_files, $wp_attachment_metadata, $post_id );
2672
- }
2673
-
2674
- $size_info = array( 'file' => '', 'width' => '', 'height' => '' );
2675
- $match_count = preg_match( '/(.+)\[(.+)\]/', $data_source, $matches );
2676
- if ( 1 == $match_count ) {
2677
- $data_source = $matches[1] . '[size]';
2678
- if ( isset( $file_info['sizes'][ $matches[2] ] ) ) {
2679
- $size_info = $file_info['sizes'][ $matches[2] ];
2680
- }
2681
- }
2682
-
2683
- $result = '';
2684
-
2685
- switch( $data_source ) {
2686
- case 'meta':
2687
- $attachment_metadata = isset( $wp_attachment_metadata[ $post_id ]->meta_value ) ? maybe_unserialize( $wp_attachment_metadata[ $post_id ]->meta_value ) : array();
2688
- $result = MLAData::mla_find_array_element( $data_value['meta_name'], $attachment_metadata, $data_value['option'], $data_value['keep_existing'] );
2689
- break;
2690
- case 'template':
2691
- if ( in_array( $data_value['option'], array ( 'single', 'export', 'array', 'multi' ) ) ) {
2692
- $default_option = 'array';
2693
- } else {
2694
- $default_option = 'text';
2695
- }
2696
-
2697
- /*
2698
- * Go through the template and expand the non-prefixed elements
2699
- * as Data Sources
2700
- */
2701
- $item_values = array();
2702
- $placeholders = MLAData::mla_get_template_placeholders( $data_value['meta_name'], $default_option );
2703
- foreach ( $placeholders as $key => $placeholder ) {
2704
- if ( empty( $placeholder['prefix'] ) ) {
2705
- $field_value = $data_value;
2706
- $field_value['data_source'] = $placeholder['value'];
2707
- $field_value['meta_name'] = '';
2708
- $field_value['option'] = $placeholder['option'];
2709
- $field_value = self::_evaluate_data_source( $post_id, $category, $field_value, $attachment_metadata );
2710
- $item_values[ $key ] = MLAData::mla_apply_field_level_format( $field_value, $placeholder );
2711
- } // Data Source
2712
- } // foreach placeholder
2713
-
2714
- /*
2715
- * Now expand the template using the above Data Source values
2716
- */
2717
- $template = '[+template:' . $data_value['meta_name'] . '+]';
2718
- $item_values = MLAData::mla_expand_field_level_parameters( $template, NULL, $item_values, $post_id, $data_value['keep_existing'], $default_option );
2719
-
2720
- if ( 'array' == $default_option ) {
2721
- $result = MLAData::mla_parse_array_template( $template, $item_values );
2722
- $result = self::_evaluate_array_result( $result, $data_value['option'], $data_value['keep_existing'] );
2723
- } else {
2724
- $result = MLAData::mla_parse_template( $template, $item_values );
2725
- }
2726
- break;
2727
- case 'parent':
2728
- $data_source = 'post_parent';
2729
- /* fallthru */
2730
- case 'ID':
2731
- case 'post_id':
2732
- case 'post_author':
2733
- case 'post_parent':
2734
- case 'menu_order':
2735
- case 'comment_count':
2736
- $result = absint( self::_evaluate_post_information( $post_id, $category, $data_source ) );
2737
- break;
2738
- case 'alt_text':
2739
- if ( NULL == $alt_text ) {
2740
- $metadata = get_metadata( 'post', $post_id, '_wp_attachment_image_alt' );
2741
- if ( is_array( $metadata ) ) {
2742
- if ( count( $metadata ) == 1 ) {
2743
- $alt_text = maybe_unserialize( $metadata[0] );
2744
- } else {
2745
- $alt_text = array();
2746
- foreach ( $metadata as $single_key => $single_value ) {
2747
- $alt_text[ $single_key ] = maybe_unserialize( $single_value );
2748
- }
2749
- }
2750
- }
2751
- }
2752
-
2753
- if ( ! empty( $alt_text ) ) {
2754
- $result = self::_evaluate_array_result( $alt_text, $data_value['option'], $data_value['keep_existing'] );
2755
- }
2756
- break;
2757
- case 'mime_type':
2758
- $data_source = 'post_mime_type';
2759
- /* fallthru */
2760
- case 'post_date':
2761
- case 'post_date_gmt':
2762
- case 'post_content':
2763
- case 'post_title':
2764
- case 'post_excerpt':
2765
- case 'post_status':
2766
- case 'comment_status':
2767
- case 'ping_status':
2768
- case 'post_name':
2769
- case 'post_modified':
2770
- case 'post_modified_gmt':
2771
- case 'post_content_filtered':
2772
- case 'guid':
2773
- case 'post_mime_type':
2774
- $result = self::_evaluate_post_information( $post_id, $category, $data_source );
2775
- break;
2776
- case 'absolute_path':
2777
- case 'absolute_file_name':
2778
- case 'base_file':
2779
- case 'path':
2780
- case 'file_name':
2781
- case 'name_only':
2782
- case 'extension':
2783
- case 'width':
2784
- case 'height':
2785
- case 'orientation':
2786
- case 'hwstring_small':
2787
- case 'aperture':
2788
- case 'credit':
2789
- case 'camera':
2790
- case 'caption':
2791
- case 'created_timestamp':
2792
- case 'copyright':
2793
- case 'focal_length':
2794
- case 'iso':
2795
- case 'shutter_speed':
2796
- case 'title':
2797
- if ( isset( $file_info[ $data_source ] ) ) {
2798
- $result = $file_info[ $data_source ];
2799
- }
2800
- break;
2801
- case 'file_size':
2802
- $filesize = @ filesize( $file_info['absolute_file_name_raw'] );
2803
- if ( ! (false === $filesize ) ) {
2804
- $result = $filesize;
2805
- }
2806
- break;
2807
- case 'upload_date':
2808
- $result = self::_evaluate_post_information( $post_id, $category, 'post_date' );
2809
- break;
2810
- case 'dimensions':
2811
- $result = $file_info['width'] . 'x' . $file_info['height'];
2812
- if ( 'x' == $result ) {
2813
- $result = '';
2814
- }
2815
- break;
2816
- case 'pixels':
2817
- $result = absint( (int) $file_info['width'] * (int) $file_info['height'] );
2818
- if ( 0 == $result ) {
2819
- $result = '';
2820
- } else {
2821
- $result = (string) $result;
2822
- }
2823
- break;
2824
- case 'size_keys':
2825
- $result = array();
2826
- foreach ( $file_info['sizes'] as $key => $value )
2827
- $result[] = $key;
2828
-
2829
- $result = self::_evaluate_array_result( $result, $data_value['option'], $data_value['keep_existing'] );
2830
- break;
2831
- case 'size_names':
2832
- $result = array();
2833
- foreach ( $file_info['sizes'] as $key => $value )
2834
- $result[] = $value['file'];
2835
-
2836
- $result = self::_evaluate_array_result( $result, $data_value['option'], $data_value['keep_existing'] );
2837
- break;
2838
- case 'size_bytes':
2839
- $result = array();
2840
- foreach ( $file_info['sizes'] as $key => $value ) {
2841
- $filesize = @ filesize( $file_info['absolute_path_raw'] . $value['file'] );
2842
- if ( false === $filesize ) {
2843
- $result[] = '?';
2844
- } else {
2845
- switch( $data_value['format'] ) {
2846
- case 'commas':
2847
- if ( is_numeric( $filesize ) ) {
2848
- $filesize = number_format( (float)$filesize );
2849
- }
2850
- break;
2851
- default:
2852
- // no change
2853
- } // format
2854
- $result[] = $filesize;
2855
- }
2856
- }
2857
-
2858
- $result = self::_evaluate_array_result( $result, $data_value['option'], $data_value['keep_existing'] );
2859
- break;
2860
- case 'size_pixels':
2861
- $result = array();
2862
- foreach ( $file_info['sizes'] as $key => $value ) {
2863
- $pixels = absint( (int) $value['width'] * (int) $value['height'] );
2864
-
2865
- switch( $data_value['format'] ) {
2866
- case 'commas':
2867
- if ( is_numeric( $pixels ) ) {
2868
- $pixels = number_format( (float)$pixels );
2869
- }
2870
- break;
2871
- default:
2872
- // no change
2873
- } // format
2874
- $result[] = $pixels;
2875
- }
2876
-
2877
- $result = self::_evaluate_array_result( $result, $data_value['option'], $data_value['keep_existing'] );
2878
- break;
2879
- case 'size_dimensions':
2880
- $result = array();
2881
- foreach ( $file_info['sizes'] as $key => $value ) {
2882
- $result[] = $value['width'] . 'x' . $value['height'];
2883
- }
2884
-
2885
- $result = self::_evaluate_array_result( $result, $data_value['option'], $data_value['keep_existing'] );
2886
- break;
2887
- case 'size_name[size]':
2888
- $result = $size_info['file'];
2889
- break;
2890
- case 'size_bytes[size]':
2891
- $result = @ filesize( $file_info['absolute_path_raw'] . $size_info['file'] );
2892
- if ( false === $result ) {
2893
- $result = '?';
2894
- }
2895
- break;
2896
- case 'size_pixels[size]':
2897
- $result = absint( (int) $size_info['width'] * (int) $size_info['height'] );
2898
- break;
2899
- case 'size_dimensions[size]':
2900
- $result = $size_info['width'] . 'x' . $size_info['height'];
2901
- if ( 'x' == $result ) {
2902
- $result = '';
2903
- }
2904
- break;
2905
- case 'parent_date':
2906
- case 'parent_type':
2907
- case 'parent_title':
2908
- if ( is_null( $parent_info ) ) {
2909
- $parent_info = MLAData::mla_fetch_attachment_parent_data( self::_evaluate_post_information( $post_id, $category, 'post_parent' ) );
2910
- }
2911
-
2912
- if ( isset( $parent_info[ $data_source ] ) ) {
2913
- $result = $parent_info[ $data_source ];
2914
- }
2915
- break;
2916
- case 'parent_issues':
2917
- if ( is_null( $references ) ) {
2918
- $references = MLAData::mla_fetch_attachment_references( $post_id, self::_evaluate_post_information( $post_id, $category, 'post_parent' ) );
2919
- }
2920
-
2921
- if ( !empty( $references['parent_errors'] ) ) {
2922
- $result = $references['parent_errors'];
2923
- /*
2924
- * Remove (ORPHAN...
2925
- */
2926
- $orphan_certain = '(' . __( 'ORPHAN', 'media-library-assistant' ) . ')';
2927
- $orphan_possible = '(' . __( 'ORPHAN', 'media-library-assistant' ) . '?)';
2928
-
2929
- if ( false !== strpos( $result, $orphan_certain ) ) {
2930
- $result = trim( substr( $result, strlen( $orphan_certain ) ) );
2931
- } elseif ( false !== strpos( $result, $orphan_possible ) ) {
2932
- $result = trim( substr( $result, strlen( $orphan_possible ) ) );
2933
- }
2934
- }
2935
- break;
2936
- case 'reference_issues':
2937
- if ( is_null( $references ) ) {
2938
- $references = MLAData::mla_fetch_attachment_references( $post_id, self::_evaluate_post_information( $post_id, $category, 'post_parent' ) );
2939
- }
2940
-
2941
- if ( !empty( $references['parent_errors'] ) ) {
2942
- $result = $references['parent_errors'];
2943
- }
2944
- break;
2945
- case 'featured_in':
2946
- case 'featured_in_title':
2947
- if ( is_null( $references ) ) {
2948
- $references = MLAData::mla_fetch_attachment_references( $post_id, self::_evaluate_post_information( $post_id, $category, 'post_parent' ) );
2949
- }
2950
-
2951
- if ( !empty( $references['features'] ) ) {
2952
- $result = array();
2953
- foreach ( $references['features'] as $ID => $value )
2954
- if ( 'featured_in' == $data_source ) {
2955
- $result[] = sprintf( '%1$s (%2$s %3$d)', $value->post_title, $value->post_type, $ID );
2956
- } else {
2957
- $result[] = $value->post_title;
2958
- }
2959
-
2960
- $result = self::_evaluate_array_result( $result, $data_value['option'], $data_value['keep_existing'] );
2961
- } else {
2962
- $result = '';
2963
- }
2964
- break;
2965
- case 'inserted_in':
2966
- case 'inserted_in_title':
2967
- if ( is_null( $references ) ) {
2968
- $references = MLAData::mla_fetch_attachment_references( $post_id, self::_evaluate_post_information( $post_id, $category, 'post_parent' ) );
2969
- }
2970
-
2971
- if ( !empty( $references['inserts'] ) ) {
2972
- $result = array();
2973
- foreach ( $references['inserts'] as $base_file => $inserts )
2974
- foreach ( $inserts as $value )
2975
- if ( 'inserted_in' == $data_source ) {
2976
- $result[] = sprintf( '%1$s (%2$s %3$d)', $value->post_title, $value->post_type, $value->ID );
2977
- } else {
2978
- $result[] = $value->post_title;
2979
- }
2980
-
2981
- ksort( $result );
2982
-
2983
- $result = self::_evaluate_array_result( $result, $data_value['option'], $data_value['keep_existing'] );
2984
- } else {
2985
- $result = '';
2986
- }
2987
- break;
2988
- case 'gallery_in':
2989
- case 'gallery_in_title':
2990
- if ( is_null( $references ) ) {
2991
- $references = MLAData::mla_fetch_attachment_references( $post_id, self::_evaluate_post_information( $post_id, $category, 'post_parent' ) );
2992
- }
2993
-
2994
- if ( !empty( $references['galleries'] ) ) {
2995
- $result = array();
2996
- foreach ( $references['galleries'] as $ID => $value )
2997
- if ( 'gallery_in' == $data_source ) {
2998
- $result[] = sprintf( '%1$s (%2$s %3$d)', $value['post_title'], $value['post_type'], $ID );
2999
- } else {
3000
- $result[] = $value['post_title'];
3001
- }
3002
-
3003
- $result = self::_evaluate_array_result( $result, $data_value['option'], $data_value['keep_existing'] );
3004
- } else {
3005
- $result = '';
3006
- }
3007
- break;
3008
- case 'mla_gallery_in':
3009
- case 'mla_gallery_in_title':
3010
- if ( is_null( $references ) ) {
3011
- $references = MLAData::mla_fetch_attachment_references( $post_id, self::_evaluate_post_information( $post_id, $category, 'post_parent' ) );
3012
- }
3013
-
3014
- if ( !empty( $references['mla_galleries'] ) ) {
3015
- $result = array();
3016
- foreach ( $references['mla_galleries'] as $ID => $value )
3017
- if ( 'mla_gallery_in' == $data_source ) {
3018
- $result[] = sprintf( '%1$s (%2$s %3$d)', $value['post_title'], $value['post_type'], $ID );
3019
- } else {
3020
- $result[] = $value['post_title'];
3021
- }
3022
-
3023
- $result = self::_evaluate_array_result( $result, $data_value['option'], $data_value['keep_existing'] );
3024
- } else {
3025
- $result = '';
3026
- }
3027
- break;
3028
- default:
3029
- return '';
3030
- } // switch $data_source
3031
-
3032
- switch( $data_value['format'] ) {
3033
- case 'raw':
3034
- return $result;
3035
- case 'commas':
3036
- if ( is_numeric( $result ) ) {
3037
- $result = str_pad( number_format( (float)$result ), 15, ' ', STR_PAD_LEFT );
3038
- }
3039
- break;
3040
- case 'native':
3041
- default:
3042
- /*
3043
- * Make some numeric values sortable as strings, make all value non-empty
3044
- */
3045
- if ( in_array( $data_source, array( 'file_size', 'pixels', 'width', 'height' ) ) ) {
3046
- $result = str_pad( $result, 15, ' ', STR_PAD_LEFT );
3047
- } elseif ( empty( $result ) ) {
3048
- $result = ' ';
3049
- }
3050
- } // format
3051
-
3052
- return $result;
3053
- } // _evaluate_data_source
3054
 
3055
  /**
3056
  * Evaluate custom field mapping updates for a post
@@ -3066,7 +1127,7 @@ class MLAOptions {
3066
  */
3067
  public static function mla_evaluate_custom_field_mapping( $post_id, $category, $settings = NULL, $attachment_metadata = NULL ) {
3068
  if ( NULL == $settings ) {
3069
- $settings = self::mla_get_option( 'custom_field_mapping' );
3070
  }
3071
 
3072
  $settings = apply_filters( 'mla_mapping_settings', $settings, $post_id, $category, $attachment_metadata );
@@ -3087,7 +1148,7 @@ class MLAOptions {
3087
  continue;
3088
  }
3089
 
3090
- $new_text = self::_evaluate_data_source( $post_id, $category, $setting_value, $attachment_metadata );
3091
  $new_text = apply_filters( 'mla_mapping_custom_value', $new_text, $setting_key, $post_id, $category, $attachment_metadata );
3092
 
3093
  if ( 'multi' == $setting_value['option'] ) {
@@ -3167,7 +1228,7 @@ class MLAOptions {
3167
  /*
3168
  * Add the "None" option to the front of the list
3169
  */
3170
- $option_template = self::$mla_option_templates['custom-field-select-option'];
3171
  $option_values = array (
3172
  'selected' => ( 'none' == $selection ) ? 'selected="selected"' : '',
3173
  'value' => 'none',
@@ -3183,7 +1244,7 @@ class MLAOptions {
3183
  $blacklist_names[] = $value['name'];
3184
  }
3185
 
3186
- $custom_field_names = self::_get_custom_field_names();
3187
  foreach ( $custom_field_names as $value ) {
3188
  if ( in_array( $value, $blacklist_names ) ) {
3189
  continue;
@@ -3201,89 +1262,6 @@ class MLAOptions {
3201
  return $custom_field_options;
3202
  } // _compose_custom_field_option_list
3203
 
3204
- /**
3205
- * Array of Data Source names for custom field mapping
3206
- *
3207
- * @since 1.10
3208
- *
3209
- * @var array
3210
- */
3211
- private static $custom_field_data_sources = array (
3212
- 'post_id',
3213
- 'post_author',
3214
- 'post_date',
3215
- 'post_date_gmt',
3216
- 'post_content',
3217
- 'post_title',
3218
- 'post_excerpt',
3219
- 'post_status',
3220
- 'comment_status',
3221
- 'ping_status',
3222
- 'post_name',
3223
- 'post_modified',
3224
- 'post_modified_gmt',
3225
- 'post_content_filtered',
3226
- 'parent',
3227
- 'post_parent',
3228
- 'guid',
3229
- 'menu_order',
3230
- 'mime_type',
3231
- 'post_mime_type',
3232
- 'comment_count',
3233
- 'alt_text',
3234
-
3235
- 'absolute_path',
3236
- 'absolute_file_name',
3237
- 'base_file',
3238
- 'path',
3239
- 'file_name',
3240
- 'name_only',
3241
- 'extension',
3242
- 'file_size',
3243
- 'upload_date',
3244
-
3245
- 'dimensions',
3246
- 'pixels',
3247
- 'width',
3248
- 'height',
3249
- 'orientation',
3250
- 'hwstring_small',
3251
- 'size_keys',
3252
- 'size_names',
3253
- 'size_bytes',
3254
- 'size_pixels',
3255
- 'size_dimensions',
3256
- 'size_name[size]',
3257
- 'size_bytes[size]',
3258
- 'size_pixels[size]',
3259
- 'size_dimensions[size]',
3260
-
3261
- 'parent_date',
3262
- 'parent_type',
3263
- 'parent_title',
3264
- 'parent_issues',
3265
- 'reference_issues',
3266
- 'featured_in',
3267
- 'featured_in_title',
3268
- 'inserted_in',
3269
- 'inserted_in_title',
3270
- 'gallery_in',
3271
- 'gallery_in_title',
3272
- 'mla_gallery_in',
3273
- 'mla_gallery_in_title',
3274
-
3275
- 'aperture',
3276
- 'credit',
3277
- 'camera',
3278
- 'caption',
3279
- 'created_timestamp',
3280
- 'copyright',
3281
- 'focal_length',
3282
- 'iso',
3283
- 'shutter_speed',
3284
- 'title'
3285
- );
3286
-
3287
  /**
3288
  * Compose a (Custom Field) Data Source Options list with current selection
3289
  *
@@ -3295,7 +1273,7 @@ class MLAOptions {
3295
  * @return string HTML markup with select field options
3296
  */
3297
  private static function _compose_data_source_option_list( $selection = 'none' ) {
3298
- $option_template = self::$mla_option_templates['custom-field-select-option'];
3299
 
3300
  $option_values = array (
3301
  'selected' => ( 'none' == $selection ) ? 'selected="selected"' : '',
@@ -3318,8 +1296,12 @@ class MLAOptions {
3318
  );
3319
  $custom_field_options .= MLAData::mla_parse_template( $option_template, $option_values );
3320
 
 
 
 
 
3321
  $intermediate_sizes = get_intermediate_image_sizes();
3322
- foreach ( self::$custom_field_data_sources as $value ) {
3323
  $size_pos = strpos( $value, '[size]' );
3324
  if ( $size_pos ) {
3325
  $root_value = substr( $value, 0, $size_pos );
@@ -3362,7 +1344,7 @@ class MLAOptions {
3362
  $error_list = '';
3363
  $message_list = '';
3364
  $settings_changed = false;
3365
- $custom_field_names = self::_get_custom_field_names();
3366
  $new_values = stripslashes_deep( $new_values );
3367
 
3368
  foreach ( $new_values as $the_key => $new_value ) {
@@ -3375,7 +1357,7 @@ class MLAOptions {
3375
  /*
3376
  * Check for the addition of a new rule or field
3377
  */
3378
- if ( self::MLA_NEW_CUSTOM_FIELD === $the_key ) {
3379
  if ( empty( $new_key ) ) {
3380
  continue;
3381
  }
@@ -3389,7 +1371,7 @@ class MLAOptions {
3389
  /* translators: 1: custom field name */
3390
  $message_list .= '<br>' . sprintf( __( 'Adding new field %1$s.', 'media-library-assistant' ), esc_html( $new_key ) ) . "\r\n";
3391
  $any_setting_changed = true;
3392
- } elseif ( self::MLA_NEW_CUSTOM_RULE === $the_key ) {
3393
  if ( 'none' == $new_key ) {
3394
  continue;
3395
  }
@@ -3567,18 +1549,18 @@ class MLAOptions {
3567
  *
3568
  * @return string HTML table row markup for 'render' else message(s) reflecting the results of the operation.
3569
  */
3570
- public static function mla_custom_field_option_handler( $action, $key, $value, $args = null ) {
3571
- $current_values = self::mla_get_option( 'custom_field_mapping' );
3572
 
3573
  switch ( $action ) {
3574
  case 'render':
3575
  if (empty( $current_values ) ) {
3576
- $table_rows = MLAData::mla_parse_template( self::$mla_option_templates['custom-field-empty-row'],
3577
  array(
3578
  'No Mapping Rules' => __( 'No Custom Field Mapping Rules Defined', 'media-library-assistant' ),
3579
  'column_count' => 7 ) );
3580
  } else {
3581
- $row_template = self::$mla_option_templates['custom-field-rule-row'];
3582
  $table_rows = '';
3583
  $index = 0;
3584
  }
@@ -3614,7 +1596,7 @@ class MLAOptions {
3614
  'key' => esc_attr( $row_name ),
3615
  'name_attr' => esc_attr( $row_name ),
3616
  'name' => esc_html( $row_name ),
3617
- 'data_source_options' => self::_compose_data_source_option_list( $current_value['data_source'] ),
3618
  'keep_selected' => '',
3619
  'Keep' => __( 'Keep', 'media-library-assistant' ),
3620
  'replace_selected' => '',
@@ -3706,14 +1688,14 @@ class MLAOptions {
3706
  /*
3707
  * Add a row for defining a new Custom Rule
3708
  */
3709
- $row_template = self::$mla_option_templates['custom-field-new-rule-row'];
3710
  $row_values = array (
3711
  'column_count' => 7,
3712
  'column_count_meta' => (7 - 2),
3713
  'Add new Rule' => __( 'Add a new Mapping Rule', 'media-library-assistant' ),
3714
- 'index' => self::MLA_NEW_CUSTOM_RULE,
3715
- 'field_name_options' => self::_compose_custom_field_option_list( 'none', $current_values ),
3716
- 'data_source_options' => self::_compose_data_source_option_list( 'none' ),
3717
  'keep_selected' => '',
3718
  'Keep' => __( 'Keep', 'media-library-assistant' ),
3719
  'replace_selected' => 'selected="selected"',
@@ -3750,14 +1732,14 @@ class MLAOptions {
3750
  /*
3751
  * Add a row for defining a new Custom Field
3752
  */
3753
- $row_template = self::$mla_option_templates['custom-field-new-field-row'];
3754
  $row_values = array (
3755
  'column_count' => 7,
3756
  'column_count_meta' => (7 - 2),
3757
  'Add new Field' => __( 'Add a new Field and Mapping Rule', 'media-library-assistant' ),
3758
- 'index' => self::MLA_NEW_CUSTOM_FIELD,
3759
  'field_name_size' => '24',
3760
- 'data_source_options' => self::_compose_data_source_option_list( 'none' ),
3761
  'keep_selected' => '',
3762
  'Keep' => __( 'Keep', 'media-library-assistant' ),
3763
  'replace_selected' => 'selected="selected"',
@@ -3803,19 +1785,19 @@ class MLAOptions {
3803
  'help' => $value['help']
3804
  );
3805
 
3806
- return MLAData::mla_parse_template( self::$mla_option_templates['custom-field-table'], $option_values );
3807
  case 'update':
3808
  case 'delete':
3809
  $settings_changed = false;
3810
  $messages = '';
3811
 
3812
- $results = self::_update_custom_field_mapping( $current_values, $args );
3813
  $messages .= $results['message'];
3814
  $current_values = $results['values'];
3815
  $settings_changed = $results['changed'];
3816
 
3817
  if ( $settings_changed ) {
3818
- $settings_changed = MLAOptions::mla_update_option( 'custom_field_mapping', $current_values );
3819
  if ( $settings_changed ) {
3820
  $results = __( 'Custom field mapping rules updated.', 'media-library-assistant' ) . "\r\n";
3821
  } else {
@@ -3827,8 +1809,8 @@ class MLAOptions {
3827
 
3828
  return $results . $messages;
3829
  case 'reset':
3830
- $current_values = self::$mla_option_definitions['custom_field_mapping']['std'];
3831
- $settings_changed = MLAOptions::mla_update_option( 'custom_field_mapping', $current_values );
3832
  if ( $settings_changed ) {
3833
  return __( 'Custom field mapping settings saved.', 'media-library-assistant' ) . "\r\n";
3834
  } else {
@@ -3908,7 +1890,7 @@ class MLAOptions {
3908
  $data_source_category = $update_all ? 'single_attachment_mapping' : 'custom_field_mapping';
3909
 
3910
  if ( NULL == $settings ) {
3911
- $settings = self::mla_get_option( 'iptc_exif_mapping' );
3912
  }
3913
 
3914
  $settings = apply_filters( 'mla_mapping_settings', $settings, $post->ID, $category, $attachment_metadata );
@@ -3939,7 +1921,7 @@ class MLAOptions {
3939
  'format' => 'native',
3940
  'option' => 'text' );
3941
 
3942
- $exif_value = self::_evaluate_data_source( $post->ID, $data_source_category, $data_value, $attachment_metadata );
3943
  if ( ' ' == $exif_value ) {
3944
  $exif_value = '';
3945
  }
@@ -3965,6 +1947,8 @@ class MLAOptions {
3965
  }
3966
  }
3967
 
 
 
3968
  if ( is_array( $new_text ) ) {
3969
  $new_text = implode( ',', $new_text );
3970
  }
@@ -4020,6 +2004,10 @@ class MLAOptions {
4020
  $tax_actions = array();
4021
 
4022
  foreach ( $settings['taxonomy'] as $setting_key => $setting_value ) {
 
 
 
 
4023
  /*
4024
  * Convert checkbox value(s)
4025
  */
@@ -4047,7 +2035,7 @@ class MLAOptions {
4047
  'format' => 'native',
4048
  'option' => 'array' );
4049
 
4050
- $exif_value = self::_evaluate_data_source( $post->ID, $data_source_category, $data_value, $attachment_metadata );
4051
  if ( ' ' == $exif_value ) {
4052
  $exif_value = '';
4053
  }
@@ -4111,6 +2099,8 @@ class MLAOptions {
4111
  $new_text = array_unique( $new_terms );
4112
  } // foreach $delimiter
4113
 
 
 
4114
  if ( empty( $new_text ) ) {
4115
  continue;
4116
  }
@@ -4141,7 +2131,7 @@ class MLAOptions {
4141
  */
4142
  $new_terms = array();
4143
  foreach ( $new_text as $new_term ) {
4144
- if ( 0 < $new_term = self::_get_term_id( $new_term, $tax_parent, $setting_key, $post_terms ) ) {
4145
  $new_terms[] = $new_term;
4146
  }
4147
  } // foreach new_term
@@ -4212,7 +2202,7 @@ class MLAOptions {
4212
  'format' => $setting_value['format'],
4213
  'option' => $setting_value['option'] );
4214
 
4215
- $iptc_value = self::_evaluate_data_source( $post->ID, $data_source_category, $data_value, $attachment_metadata );
4216
  if ( ' ' == $iptc_value ) {
4217
  $iptc_value = '';
4218
  }
@@ -4235,7 +2225,7 @@ class MLAOptions {
4235
  $data_value['meta_name'] = '([+exif:' . $exif_value . '+])';
4236
  }
4237
 
4238
- $exif_value = self::_evaluate_data_source( $post->ID, $data_source_category, $data_value, $attachment_metadata );
4239
  if ( ' ' == $exif_value ) {
4240
  $exif_value = '';
4241
  }
@@ -4257,6 +2247,8 @@ class MLAOptions {
4257
  }
4258
  }
4259
 
 
 
4260
  if ( $setting_value['keep_existing'] ) {
4261
  if ( 'meta:' == substr( $setting_name, 0, 5 ) ) {
4262
  $meta_key = substr( $setting_name, 5 );
@@ -4308,7 +2300,7 @@ class MLAOptions {
4308
  * @return string HTML markup with select field options
4309
  */
4310
  private static function _compose_iptc_option_list( $selection = 'none' ) {
4311
- $option_template = self::$mla_option_templates['iptc-exif-select-option'];
4312
  $option_values = array (
4313
  'selected' => ( 'none' == $selection ) ? 'selected="selected"' : '',
4314
  'value' => 'none',
@@ -4405,7 +2397,7 @@ class MLAOptions {
4405
  /*
4406
  * Field Title can change as a result of localization
4407
  */
4408
- $new_value['name'] = self::$mla_option_definitions['iptc_exif_mapping']['std']['standard'][ $new_key ]['name'];
4409
 
4410
  if ( $old_values['name'] != $new_value['name'] ) {
4411
  $any_setting_changed = true;
@@ -4465,7 +2457,7 @@ class MLAOptions {
4465
  /*
4466
  * Uncomment this for debugging.
4467
  */
4468
- // $error_list .= $message_list;
4469
 
4470
  return array( 'message' => $error_list, 'values' => $current_values, 'changed' => $settings_changed );
4471
  } // _update_iptc_exif_standard_mapping
@@ -4600,7 +2592,7 @@ class MLAOptions {
4600
  $error_list = '';
4601
  $message_list = '';
4602
  $settings_changed = false;
4603
- $custom_field_names = self::_get_custom_field_names();
4604
  $new_values = stripslashes_deep( $new_values );
4605
 
4606
  foreach ( $new_values['custom'] as $the_key => $new_value ) {
@@ -4613,7 +2605,7 @@ class MLAOptions {
4613
  /*
4614
  * Check for the addition of a new field or new rule
4615
  */
4616
- if ( self::MLA_NEW_CUSTOM_FIELD === $the_key ) {
4617
  if ( empty( $new_key ) ) {
4618
  continue;
4619
  }
@@ -4627,7 +2619,7 @@ class MLAOptions {
4627
  /* translators: 1: custom field name */
4628
  $message_list .= '<br>' . sprintf( __( 'Adding new field %1$s.', 'media-library-assistant' ), esc_html( $new_key ) ) . "\r\n";
4629
  $any_setting_changed = true;
4630
- } elseif ( self::MLA_NEW_CUSTOM_RULE === $the_key ) {
4631
  if ( 'none' == $new_key ) {
4632
  continue;
4633
  }
@@ -4763,8 +2755,8 @@ class MLAOptions {
4763
  private static function _get_custom_field_names( ) {
4764
  global $wpdb;
4765
 
4766
- $custom_field_mapping = self::mla_get_option( 'custom_field_mapping' );
4767
- $iptc_exif_mapping = self::mla_get_option( 'iptc_exif_mapping' );
4768
  $iptc_exif_mapping = $iptc_exif_mapping['custom'];
4769
 
4770
  $limit = (int) apply_filters( 'postmeta_form_limit', 100 );
@@ -4809,15 +2801,15 @@ class MLAOptions {
4809
  *
4810
  * @return string HTML table row markup for 'render' else message(s) reflecting the results of the operation.
4811
  */
4812
- public static function mla_iptc_exif_option_handler( $action, $key, $value, $args = null ) {
4813
- $current_values = self::mla_get_option( 'iptc_exif_mapping' );
4814
 
4815
  switch ( $action ) {
4816
  case 'render':
4817
 
4818
  switch ( $key ) {
4819
  case 'iptc_exif_standard_mapping':
4820
- $row_template = self::$mla_option_templates['iptc-exif-standard-row'];
4821
  $table_rows = '';
4822
 
4823
  foreach ( $current_values['standard'] as $row_name => $row_value ) {
@@ -4825,8 +2817,8 @@ class MLAOptions {
4825
  'key' => esc_attr( $row_name ),
4826
  'name_attr' => esc_attr( $row_value['name'] ),
4827
  'name' => esc_html( $row_value['name'] ),
4828
- 'iptc_field_options' => self::_compose_iptc_option_list( $row_value['iptc_value'] ),
4829
- 'exif_size' => self::MLA_EXIF_SIZE,
4830
  'exif_text' => esc_attr( $row_value['exif_value'] ),
4831
  'iptc_selected' => '',
4832
  'IPTC' => __( 'IPTC', 'media-library-assistant' ),
@@ -4863,20 +2855,24 @@ class MLAOptions {
4863
  'help' => $value['help']
4864
  );
4865
 
4866
- return MLAData::mla_parse_template( self::$mla_option_templates['iptc-exif-standard-table'], $option_values );
4867
  case 'iptc_exif_taxonomy_mapping':
4868
- $row_template = self::$mla_option_templates['iptc-exif-taxonomy-row'];
4869
- $select_template = self::$mla_option_templates['iptc-exif-select'];
4870
  $table_rows = '';
4871
  $taxonomies = get_taxonomies( array ( 'show_ui' => true ), 'objects' );
4872
 
4873
  foreach ( $taxonomies as $row_name => $row_value ) {
 
 
 
 
4874
  $row_values = array (
4875
  'key' => esc_attr( $row_name ),
4876
  'name' => esc_html( $row_value->labels->name ),
4877
  'hierarchical' => (string) $row_value->hierarchical,
4878
  'iptc_field_options' => '',
4879
- 'exif_size' => self::MLA_EXIF_SIZE,
4880
  'exif_text' => '',
4881
  'iptc_selected' => '',
4882
  'IPTC' => __( 'IPTC', 'media-library-assistant' ),
@@ -4893,7 +2889,7 @@ class MLAOptions {
4893
 
4894
  if ( array_key_exists( $row_name, $current_values['taxonomy'] ) ) {
4895
  $current_value = $current_values['taxonomy'][ $row_name ];
4896
- $row_values['iptc_field_options'] = self::_compose_iptc_option_list( $current_value['iptc_value'] );
4897
  $row_values['exif_text'] = esc_attr( $current_value['exif_value'] );
4898
 
4899
  if ( $current_value['iptc_first'] ) {
@@ -4916,12 +2912,12 @@ class MLAOptions {
4916
  'array' => 'taxonomy',
4917
  'key' => esc_attr( $row_name ),
4918
  'element' => 'parent',
4919
- 'options' => self::_compose_parent_option_list( $row_name, $parent )
4920
  );
4921
  $row_values['parent_select'] = MLAData::mla_parse_template( $select_template, $select_values );
4922
  }
4923
  } else {
4924
- $row_values['iptc_field_options'] = self::_compose_iptc_option_list( 'none' );
4925
  $row_values['iptc_selected'] = 'selected="selected"';
4926
  $row_values['keep_selected'] = 'selected="selected"';
4927
 
@@ -4930,7 +2926,7 @@ class MLAOptions {
4930
  'array' => 'taxonomy',
4931
  'key' => esc_attr( $row_name ),
4932
  'element' => 'parent',
4933
- 'options' => self::_compose_parent_option_list( $row_name, 0 )
4934
  );
4935
  $row_values['parent_select'] = MLAData::mla_parse_template( $select_template, $select_values );
4936
  }
@@ -4951,15 +2947,15 @@ class MLAOptions {
4951
  'help' => $value['help']
4952
  );
4953
 
4954
- return MLAData::mla_parse_template( self::$mla_option_templates['iptc-exif-taxonomy-table'], $option_values );
4955
  case 'iptc_exif_custom_mapping':
4956
  if ( empty( $current_values['custom'] ) ) {
4957
- $table_rows = MLAData::mla_parse_template( self::$mla_option_templates['iptc-exif-custom-empty-row'],
4958
  array(
4959
  'No Mapping Rules' => __( 'No Custom Field Mapping Rules Defined', 'media-library-assistant' ),
4960
  'column_count' => 5 ) );
4961
  } else {
4962
- $row_template = self::$mla_option_templates['iptc-exif-custom-rule-row'];
4963
  $table_rows = '';
4964
  $index = 0;
4965
  }
@@ -4995,8 +2991,8 @@ class MLAOptions {
4995
  'key' => esc_attr( $row_name ),
4996
  'name_attr' => esc_attr( $current_value['name'] ),
4997
  'name' => esc_html( $current_value['name'] ),
4998
- 'iptc_field_options' => self::_compose_iptc_option_list( $current_value['iptc_value'] ),
4999
- 'exif_size' => self::MLA_EXIF_SIZE,
5000
  'exif_text' => esc_attr( $current_value['exif_value'] ),
5001
  'iptc_selected' => '',
5002
  'IPTC' => __( 'IPTC', 'media-library-assistant' ),
@@ -5083,15 +3079,15 @@ class MLAOptions {
5083
  /*
5084
  * Add a row for defining a new rule, existing Custom Field
5085
  */
5086
- $row_template = self::$mla_option_templates['iptc-exif-custom-new-rule-row'];
5087
  $row_values = array (
5088
  'column_count' => 5 ,
5089
  'column_count_meta' => (5 - 2),
5090
  'Add new Rule' => __( 'Add a new Mapping Rule', 'media-library-assistant' ),
5091
- 'index' => self::MLA_NEW_CUSTOM_RULE,
5092
- 'field_name_options' => self::_compose_custom_field_option_list( 'none', $current_values['custom'] ),
5093
- 'iptc_field_options' => self::_compose_iptc_option_list( 'none' ),
5094
- 'exif_size' => self::MLA_EXIF_SIZE,
5095
  'exif_text' => '',
5096
  'iptc_selected' => 'selected="selected"',
5097
  'IPTC' => __( 'IPTC', 'media-library-assistant' ),
@@ -5129,15 +3125,15 @@ class MLAOptions {
5129
  /*
5130
  * Add a row for defining a new rule, new Custom Field
5131
  */
5132
- $row_template = self::$mla_option_templates['iptc-exif-custom-new-field-row'];
5133
  $row_values = array (
5134
  'column_count' => 5 ,
5135
  'column_count_meta' => (5 - 2),
5136
  'Add new Field' => __( 'Add a new Field and Mapping Rule', 'media-library-assistant' ),
5137
- 'index' => self::MLA_NEW_CUSTOM_FIELD,
5138
  'field_name_size' => '24',
5139
- 'iptc_field_options' => self::_compose_iptc_option_list( 'none' ),
5140
- 'exif_size' => self::MLA_EXIF_SIZE,
5141
  'exif_text' => '',
5142
  'iptc_selected' => 'selected="selected"',
5143
  'IPTC' => __( 'IPTC', 'media-library-assistant' ),
@@ -5182,7 +3178,7 @@ class MLAOptions {
5182
  'help' => $value['help']
5183
  );
5184
 
5185
- return MLAData::mla_parse_template( self::$mla_option_templates['iptc-exif-custom-table'], $option_values );
5186
  default:
5187
  /* translators: 1: ERROR tag 2: option name */
5188
  return '<br>' . sprintf( __( '%1$s: Render unknown custom %2$s.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $key ) . "\r\n";
@@ -5194,35 +3190,35 @@ class MLAOptions {
5194
 
5195
  switch ( $key ) {
5196
  case 'iptc_exif_standard_mapping':
5197
- $results = self::_update_iptc_exif_standard_mapping( $current_values, $args );
5198
  $messages .= $results['message'];
5199
  $current_values = $results['values'];
5200
  $settings_changed = $results['changed'];
5201
  break;
5202
  case 'iptc_exif_taxonomy_mapping':
5203
- $results = self::_update_iptc_exif_taxonomy_mapping( $current_values, $args );
5204
  $messages .= $results['message'];
5205
  $current_values = $results['values'];
5206
  $settings_changed = $results['changed'];
5207
  break;
5208
  case 'iptc_exif_custom_mapping':
5209
- $results = self::_update_iptc_exif_custom_mapping( $current_values, $args );
5210
  $messages .= $results['message'];
5211
  $current_values = $results['values'];
5212
  $settings_changed = $results['changed'];
5213
  break;
5214
  case 'iptc_exif_mapping':
5215
- $results = self::_update_iptc_exif_standard_mapping( $current_values, $args );
5216
  $messages .= $results['message'];
5217
  $current_values = $results['values'];
5218
  $settings_changed = $results['changed'];
5219
 
5220
- $results = self::_update_iptc_exif_taxonomy_mapping( $current_values, $args );
5221
  $messages .= $results['message'];
5222
  $current_values = $results['values'];
5223
  $settings_changed |= $results['changed'];
5224
 
5225
- $results = self::_update_iptc_exif_custom_mapping( $current_values, $args );
5226
  $messages .= $results['message'];
5227
  $current_values = $results['values'];
5228
  $settings_changed |= $results['changed'];
@@ -5233,7 +3229,7 @@ class MLAOptions {
5233
  } // switch $key
5234
 
5235
  if ( $settings_changed ) {
5236
- $settings_changed = MLAOptions::mla_update_option( 'iptc_exif_mapping', $current_values );
5237
  if ( $settings_changed ) {
5238
  $results = __( 'IPTC/EXIF mapping settings updated.', 'media-library-assistant' ) . "\r\n";
5239
  } else {
@@ -5247,8 +3243,8 @@ class MLAOptions {
5247
  case 'reset':
5248
  switch ( $key ) {
5249
  case 'iptc_exif_standard_mapping':
5250
- $current_values['standard'] = self::$mla_option_definitions['iptc_exif_mapping']['std']['standard'];
5251
- $settings_changed = MLAOptions::mla_update_option( 'iptc_exif_mapping', $current_values );
5252
  if ( $settings_changed ) {
5253
  /* translators: 1: field type */
5254
  return sprintf( __( '%1$s settings saved.', 'media-library-assistant' ), 'IPTC/EXIF ' . __( 'Standard field', 'media-library-assistant' ) ) . "\r\n";
@@ -5257,8 +3253,8 @@ class MLAOptions {
5257
  return sprintf( __( '%1$s: IPTC/EXIF %2$s settings update failed.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'Standard field', 'media-library-assistant' ) ) . "\r\n";
5258
  }
5259
  case 'iptc_exif_taxonomy_mapping':
5260
- $current_values['taxonomy'] = self::$mla_option_definitions['iptc_exif_mapping']['std']['taxonomy'];
5261
- $settings_changed = MLAOptions::mla_update_option( 'iptc_exif_mapping', $current_values );
5262
  if ( $settings_changed ) {
5263
  /* translators: 1: field type */
5264
  return sprintf( __( '%1$s settings saved.', 'media-library-assistant' ), 'IPTC/EXIF ' . __( 'Taxonomy term', 'media-library-assistant' ) ) . "\r\n";
@@ -5267,8 +3263,8 @@ class MLAOptions {
5267
  return sprintf( __( '%1$s: IPTC/EXIF %2$s settings update failed.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'Taxonomy term', 'media-library-assistant' ) ) . "\r\n";
5268
  }
5269
  case 'iptc_exif_custom_mapping':
5270
- $current_values['custom'] = self::$mla_option_definitions['iptc_exif_mapping']['std']['custom'];
5271
- $settings_changed = MLAOptions::mla_update_option( 'iptc_exif_mapping', $current_values );
5272
  if ( $settings_changed ) {
5273
  /* translators: 1: field type */
5274
  return sprintf( __( '%1$s settings saved.', 'media-library-assistant' ), 'IPTC/EXIF ' . __( 'Custom field', 'media-library-assistant' ) ) . "\r\n";
@@ -5277,7 +3273,7 @@ class MLAOptions {
5277
  return sprintf( __( '%1$s: IPTC/EXIF %2$s settings update failed.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'Custom field', 'media-library-assistant' ) ) . "\r\n";
5278
  }
5279
  case 'iptc_exif_mapping':
5280
- self::mla_delete_option( $key );
5281
  /* translators: 1: option name, e.g., taxonomy_support */
5282
  return '<br>' . sprintf( __( 'Reset custom %1$s', 'media-library-assistant' ), $key ) . "\r\n";
5283
  default:
19
  /**
20
  * Provides a unique name for the current version option
21
  */
22
+ const MLA_VERSION_OPTION = MLACore::MLA_VERSION_OPTION; // 'current_version';
23
 
24
  /**
25
  * Provides a unique name for the exclude revisions option
26
  */
27
+ const MLA_EXCLUDE_REVISIONS = MLACore::MLA_EXCLUDE_REVISIONS; // 'exclude_revisions';
28
 
29
  /**
30
  * Provides a unique name for a database tuning option
31
  */
32
+ const MLA_FEATURED_IN_TUNING = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::MLA_DEFAULT_ORDERBY; // 'default_orderby';
83
 
84
  /**
85
  * Provides a unique name for the default order option
86
  */
87
+ const MLA_DEFAULT_ORDER = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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 = MLACore::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()
289
  * @return void
290
  */
291
  public static function initialize( ) {
292
+ MLAOptions::_load_option_templates();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
293
 
294
+ if ( ( 'checked' == MLACore::mla_get_option( 'enable_iptc_exif_mapping' ) ) ||
295
+ ( 'checked' == MLACore::mla_get_option( 'enable_custom_field_mapping' ) ) ||
296
+ ( 'checked' == MLACore::mla_get_option( 'enable_iptc_exif_update' ) ) ||
297
+ ( 'checked' == MLACore::mla_get_option( 'enable_custom_field_update' ) ) ) {
298
  add_filter( 'wp_handle_upload_prefilter', 'MLAOptions::mla_wp_handle_upload_prefilter_filter', 1, 1 );
299
  add_filter( 'wp_handle_upload', 'MLAOptions::mla_wp_handle_upload_filter', 1, 1 );
300
 
310
  *
311
  * @var array
312
  */
313
+ private static $mla_option_templates = NULL;
314
 
315
  /**
316
  * Load style and markup templates to $mla_templates
320
  * @return void
321
  */
322
  private static function _load_option_templates() {
323
+ MLAOptions::$mla_option_templates = MLAData::mla_load_template( 'mla-option-templates.tpl' );
324
 
325
  /*
326
  * Load the default templates
327
  */
328
+ if ( is_null( MLAOptions::$mla_option_templates ) ) {
329
+ MLACore::mla_debug_add( '<strong>mla_debug _load_option_templates()</strong> ' . __( 'error loading tpls/mla-option-templates.tpl', 'media-library-assistant' ) );
330
  return;
331
+ } elseif ( !MLAOptions::$mla_option_templates ) {
332
+ MLACore::mla_debug_add( '<strong>mla_debug _load_option_templates()</strong> ' . __( 'tpls/mla-option-templates.tpl not found', 'media-library-assistant' ) );
333
+ MLAOptions::$mla_option_templates = NULL;
334
  return;
335
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
336
  }
337
 
338
  /**
346
  * @return void
347
  */
348
  public static function mla_localize_option_definitions_array() {
349
+ MLACore::mla_localize_option_definitions_array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
  }
351
 
352
  /**
357
  * @return array|null name => value for all style templates or null if no templates
358
  */
359
  public static function mla_get_style_templates() {
360
+ if ( ! is_array( MLAShortcode_Support::$mla_custom_templates ) ) {
361
+ MLACore::mla_debug_add( '<strong>mla_debug mla_get_style_templates()</strong> ' . __( 'no templates exist', 'media-library-assistant' ) );
362
+ return NULL;
363
  }
364
 
365
  $templates = array();
366
+ foreach ( MLAShortcode_Support::$mla_custom_templates as $key => $value ) {
367
  $tail = strrpos( $key, '-style' );
368
  if ( ! ( false === $tail ) ) {
369
  $name = substr( $key, 0, $tail );
383
  * @return boolean true if success, false if failure
384
  */
385
  public static function mla_put_style_templates( $templates ) {
386
+ if ( MLACore::mla_update_option( 'style_templates', $templates ) ) {
387
+ MLAShortcode_Support::mla_load_custom_templates();
388
  return true;
389
  }
390
 
399
  * @return array|null name => value for all markup templates or null if no templates
400
  */
401
  public static function mla_get_markup_templates() {
402
+ if ( ! is_array( MLAShortcode_Support::$mla_custom_templates ) ) {
403
+ MLACore::mla_debug_add( '<strong>mla_debug mla_get_markup_templates()</strong> ' . __( 'no templates exist', 'media-library-assistant' ) );
404
+ return NULL;
405
  }
406
 
407
  $templates = array();
408
+ foreach ( MLAShortcode_Support::$mla_custom_templates as $key => $value ) {
409
  // Note order: -row-open must precede -open!
410
  $tail = strrpos( $key, '-row-open-markup' );
411
  if ( ! ( false === $tail ) ) {
454
  * @return boolean true if success, false if failure
455
  */
456
  public static function mla_put_markup_templates( $templates ) {
457
+ if ( MLACore::mla_update_option( 'markup_templates', $templates ) ) {
458
+ MLAShortcode_Support::mla_load_custom_templates();
459
  return true;
460
  }
461
 
465
  /**
466
  * Return the stored value or default value of a defined MLA option
467
  *
468
+ * Compatibility shim for MLACore::mla_get_option
469
+ *
470
  * @since 0.1
471
  *
472
  * @param string Name of the desired option
478
  * @return mixed Value(s) for the option or false if the option is not a defined MLA option
479
  */
480
  public static function mla_get_option( $option, $get_default = false, $get_stored = false, $option_table = NULL ) {
481
+ return MLACore::mla_get_option( $option, $get_default, $get_stored, $option_table );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
482
  }
483
 
484
  /**
485
  * Add or update the stored value of a defined MLA option
486
  *
487
+ * Compatibility shim for MLACore::mla_update_option
488
+ *
489
  * @since 0.1
490
  *
491
  * @param string Name of the desired option
495
  * @return boolean True if the value was changed or false if the update failed
496
  */
497
  public static function mla_update_option( $option, $newvalue, $option_table = NULL ) {
498
+ return MLACore::mla_update_option( $option, $newvalue, $option_table );
 
 
 
 
 
 
 
 
499
  }
500
 
501
  /**
502
  * Delete the stored value of a defined MLA option
503
  *
504
+ * Compatibility shim for MLACore::mla_delete_option
505
+ *
506
  * @since 0.1
507
  *
508
  * @param string Name of the desired option
511
  * @return boolean True if the option was deleted, otherwise false
512
  */
513
  public static function mla_delete_option( $option, $option_table = NULL ) {
514
+ return MLACore::mla_delete_option( $option, $option_table );
 
 
 
 
 
 
 
 
515
  }
516
 
517
  /**
518
  * Determine MLA support for a taxonomy, handling the special case where the
519
  * settings are being updated or reset.
520
  *
521
+ * Compatibility shim for MLACore::mla_taxonomy_support
522
+ *
523
  * @since 0.30
524
  *
525
  * @param string Taxonomy name, e.g., attachment_category
529
  * true if the taxonomy is supported in this way else false.
530
  * string if $tax_name is '' and $support_type is 'filter', returns the taxonomy to filter by.
531
  */
532
+ public static function mla_taxonomy_support( $tax_name, $support_type = 'support' ) {
533
+ return MLACore::mla_taxonomy_support( $tax_name, $support_type );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
534
  } // mla_taxonomy_support
535
 
536
  /**
537
  * Returns an array of taxonomy names assigned to $support_type
538
  *
539
+ * Compatibility shim for MLACore::mla_taxonomy_support
540
+ *
541
  * @since 1.90
542
  *
543
  * @param string Optional. 'support' (default), 'quick-edit', 'flat-checklist', 'term-search' or 'filter'
545
  * @return array taxonomies assigned to $support_type; can be empty.
546
  */
547
  public static function mla_supported_taxonomies($support_type = 'support') {
548
+ return MLACore::mla_supported_taxonomies( $tax_name, $support_type );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
549
  } // mla_supported_taxonomies
550
 
551
  /**
561
  *
562
  * @return string HTML table row markup for 'render' else message(s) reflecting the results of the operation.
563
  */
564
+ public static function mla_attachment_display_settings_option_handler( $action, $key, $value, $args = NULL ) {
565
  switch ( $action ) {
566
  case 'render':
567
  $current_value = get_option( $key );
625
  *
626
  * @return string HTML table row markup for 'render' else message(s) reflecting the results of the operation.
627
  */
628
+ public static function mla_taxonomy_option_handler( $action, $key, $value, $args = NULL ) {
629
  switch ( $action ) {
630
  case 'render':
631
  $taxonomies = get_taxonomies( array ( 'show_ui' => true ), 'objects' );
632
+ $current_values = MLACore::mla_get_option( $key );
633
+ $tax_support = isset( $current_values['tax_support'] ) ? $current_values['tax_support'] : MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_support'];
634
+ $tax_quick_edit = isset( $current_values['tax_quick_edit'] ) ? $current_values['tax_quick_edit'] : MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_quick_edit'];
635
+ $tax_term_search = isset( $current_values['tax_term_search'] ) ? $current_values['tax_term_search'] : MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_term_search'];
636
+ $tax_flat_checklist = isset( $current_values['tax_flat_checklist'] ) ? $current_values['tax_flat_checklist'] : MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_flat_checklist'];
637
+ $tax_checked_on_top = isset( $current_values['tax_checked_on_top'] ) ? $current_values['tax_checked_on_top'] : MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_checked_on_top'];
638
+ $tax_filter = isset( $current_values['tax_filter'] ) ? $current_values['tax_filter'] : MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_filter'];
639
 
640
  /*
641
  * Always display our own taxonomies, even if not registered.
672
  }
673
  }
674
 
675
+ $taxonomy_row = MLAOptions::$mla_option_templates['taxonomy-row'];
676
  $row = '';
677
 
678
  foreach ( $taxonomies as $tax_name => $tax_object ) {
710
  'help' => $value['help']
711
  );
712
 
713
+ return MLAData::mla_parse_template( MLAOptions::$mla_option_templates['taxonomy-table'], $option_values );
714
  case 'update':
715
  case 'delete':
716
+ $tax_support = isset( $args['tax_support'] ) ? $args['tax_support'] : MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_support'];
717
+ $tax_quick_edit = isset( $args['tax_quick_edit'] ) ? $args['tax_quick_edit'] : MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_quick_edit'];
718
+ $tax_term_search = isset( $args['tax_term_search'] ) ? $args['tax_term_search'] : MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_term_search'];
719
+ $tax_flat_checklist = isset( $args['tax_flat_checklist'] ) ? $args['tax_flat_checklist'] : MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_flat_checklist'];
720
+ $tax_checked_on_top = isset( $args['tax_checked_on_top'] ) ? $args['tax_checked_on_top'] : MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_checked_on_top'];
721
+ $tax_filter = isset( $args['tax_filter'] ) ? $args['tax_filter'] : MLACore::$mla_option_definitions[ MLACore::MLA_TAXONOMY_SUPPORT ]['std']['tax_filter'];
722
 
723
  $msg = '';
724
 
771
  'tax_filter' => $tax_filter
772
  );
773
 
774
+ MLACore::mla_update_option( $key, $value );
775
 
776
  if ( empty( $msg ) ) {
777
  /* translators: 1: option name, e.g., taxonomy_support */
780
 
781
  return $msg;
782
  case 'reset':
783
+ MLACore::mla_delete_option( $key );
784
  /* translators: 1: option name, e.g., taxonomy_support */
785
  return '<br>' . sprintf( __( 'Reset custom %1$s', 'media-library-assistant' ), $key ) . "\r\n";
786
  default:
802
  *
803
  * @return string HTML table row markup for 'render' else message(s) reflecting the results of the operation.
804
  */
805
+ public static function mla_search_option_handler( $action, $key, $value, $args = NULL ) {
806
  switch ( $action ) {
807
  case 'render':
808
+ $current_values = MLACore::mla_get_option( $key );
809
+ $search_connector = isset( $current_values['search_connector'] ) ? $current_values['search_connector'] : MLACore::$mla_option_definitions[ MLACore::MLA_SEARCH_MEDIA_FILTER_DEFAULTS ]['std']['search_connector'];
810
+ $search_fields = isset( $current_values['search_fields'] ) ? $current_values['search_fields'] : MLACore::$mla_option_definitions[ MLACore::MLA_SEARCH_MEDIA_FILTER_DEFAULTS ]['std']['search_fields'];
811
 
812
  $option_values = array (
813
  'and_checked' => ( 'AND' == $search_connector ) ? 'checked="checked"' : '',
831
 
832
  'terms_checked' => ( in_array( 'terms', $search_fields ) ) ? 'checked="checked"' : '',
833
  'Terms' => __( 'Terms', 'media-library-assistant' ),
834
+ 'help' => MLACore::$mla_option_definitions[ MLACore::MLA_SEARCH_MEDIA_FILTER_DEFAULTS ]['help']
835
  );
836
 
837
+ return MLAData::mla_parse_template( MLAOptions::$mla_option_templates['search-table'], $option_values );
838
  case 'update':
839
  case 'delete':
840
+ $search_connector = isset( $args['search_connector'] ) ? $args['search_connector'] : MLACore::$mla_option_definitions[ MLACore::MLA_SEARCH_MEDIA_FILTER_DEFAULTS ]['std']['search_connector'];
841
+ $search_fields = isset( $args['search_fields'] ) ? $args['search_fields'] : MLACore::$mla_option_definitions[ MLACore::MLA_SEARCH_MEDIA_FILTER_DEFAULTS ]['std']['search_fields'];
842
 
843
  $msg = '';
844
 
847
  'search_fields' => $search_fields,
848
  );
849
 
850
+ MLACore::mla_update_option( $key, $value );
851
 
852
  if ( empty( $msg ) ) {
853
  /* translators: 1: option name, e.g., taxonomy_support */
856
 
857
  return $msg;
858
  case 'reset':
859
+ MLACore::mla_delete_option( $key );
860
  /* translators: 1: option name, e.g., taxonomy_support */
861
  return '<br>' . sprintf( __( 'Reset custom %1$s', 'media-library-assistant' ), $key ) . "\r\n";
862
  default:
949
  * @return void
950
  */
951
  public static function mla_add_attachment_action( $post_ID ) {
952
+ MLAOptions::$add_attachment_id = $post_ID;
953
  do_action('mla_add_attachment', $post_ID);
954
  } // mla_add_attachment_action
955
 
1001
  */
1002
  public static function mla_update_attachment_metadata_filter( $data, $post_id ) {
1003
  $options = array ();
1004
+ $options['is_upload'] = MLAOptions::$add_attachment_id == $post_id;
1005
+ MLAOptions::$add_attachment_id = 0;
1006
 
1007
+ $options['enable_iptc_exif_mapping'] = 'checked' == MLACore::mla_get_option( 'enable_iptc_exif_mapping' );
1008
+ $options['enable_custom_field_mapping'] = 'checked' == MLACore::mla_get_option( 'enable_custom_field_mapping' );
1009
+ $options['enable_iptc_exif_update'] = 'checked' == MLACore::mla_get_option( 'enable_iptc_exif_update' );
1010
+ $options['enable_custom_field_update'] = 'checked' == MLACore::mla_get_option( 'enable_custom_field_update' );
1011
 
1012
  $options = apply_filters( 'mla_update_attachment_metadata_options', $options, $data, $post_id );
1013
  $data = apply_filters( 'mla_update_attachment_metadata_prefilter', $data, $post_id, $options );
1020
  if ( $options['enable_iptc_exif_mapping'] ) {
1021
  $item = get_post( $post_id );
1022
  $updates = MLAOptions::mla_evaluate_iptc_exif_mapping( $item, 'iptc_exif_mapping', NULL, $data, true );
1023
+ $updates = MLAOptions::_update_attachment_metadata( $updates, $data );
1024
 
1025
  if ( !empty( $updates ) ) {
1026
  $item_content = MLAData::mla_update_single_item( $post_id, $updates );
1029
 
1030
  if ( $options['enable_custom_field_mapping'] ) {
1031
  $updates = MLAOptions::mla_evaluate_custom_field_mapping( $post_id, 'single_attachment_mapping', NULL, $data );
1032
+ $updates = MLAOptions::_update_attachment_metadata( $updates, $data );
1033
 
1034
  if ( !empty( $updates ) ) {
1035
  $item_content = MLAData::mla_update_single_item( $post_id, $updates );
1047
  if ( $options['enable_iptc_exif_update'] ) {
1048
  $item = get_post( $post_id );
1049
  $updates = MLAOptions::mla_evaluate_iptc_exif_mapping( $item, 'iptc_exif_mapping', NULL, $data );
1050
+ $updates = MLAOptions::_update_attachment_metadata( $updates, $data );
1051
 
1052
  if ( !empty( $updates ) ) {
1053
  $item_content = MLAData::mla_update_single_item( $post_id, $updates );
1056
 
1057
  if ( $options['enable_custom_field_update'] ) {
1058
  $updates = MLAOptions::mla_evaluate_custom_field_mapping( $post_id, 'single_attachment_mapping', NULL, $data );
1059
+ $updates = MLAOptions::_update_attachment_metadata( $updates, $data );
1060
 
1061
  if ( !empty( $updates ) ) {
1062
  $item_content = MLAData::mla_update_single_item( $post_id, $updates );
1073
  } // mla_update_attachment_metadata_filter
1074
 
1075
  /**
1076
+ * Get IPTC/EXIF or custom field mapping data source; WP_ADMIN mode
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1077
  *
1078
+ * Compatibility shim for MLAData_Source::mla_get_data_source.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1079
  *
1080
  * @since 1.70
1081
  *
1087
  * @return string|array data source value
1088
  */
1089
  public static function mla_get_data_source( $post_id, $category, $data_value, $attachment_metadata = NULL ) {
1090
+ if ( !class_exists( 'MLAData_Source' ) ) {
1091
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-data-source.php' );
1092
+ }
 
 
 
 
 
1093
 
1094
+ return MLAData_Source::mla_get_data_source( $post_id, $category, $data_value, $attachment_metadata );
1095
  } // mla_get_data_source
1096
 
1097
  /**
1098
+ * Identify custom field mapping data source; WP_ADMIN mode
1099
  *
1100
+ * Compatibility shim for MLAData_Source::mla_is_data_source.
 
1101
  *
1102
  * @since 1.80
1103
  *
1106
  * @return boolean true if candidate name matches a data source
1107
  */
1108
  public static function mla_is_data_source( $candidate_name ) {
1109
+ if ( !class_exists( 'MLAData_Source' ) ) {
1110
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-data-source.php' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1111
  }
1112
 
1113
+ return MLAData_Source::mla_is_data_source( $candidate_name );
1114
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1115
 
1116
  /**
1117
  * Evaluate custom field mapping updates for a post
1127
  */
1128
  public static function mla_evaluate_custom_field_mapping( $post_id, $category, $settings = NULL, $attachment_metadata = NULL ) {
1129
  if ( NULL == $settings ) {
1130
+ $settings = MLACore::mla_get_option( 'custom_field_mapping' );
1131
  }
1132
 
1133
  $settings = apply_filters( 'mla_mapping_settings', $settings, $post_id, $category, $attachment_metadata );
1148
  continue;
1149
  }
1150
 
1151
+ $new_text = MLAOptions::mla_get_data_source( $post_id, $category, $setting_value, $attachment_metadata );
1152
  $new_text = apply_filters( 'mla_mapping_custom_value', $new_text, $setting_key, $post_id, $category, $attachment_metadata );
1153
 
1154
  if ( 'multi' == $setting_value['option'] ) {
1228
  /*
1229
  * Add the "None" option to the front of the list
1230
  */
1231
+ $option_template = MLAOptions::$mla_option_templates['custom-field-select-option'];
1232
  $option_values = array (
1233
  'selected' => ( 'none' == $selection ) ? 'selected="selected"' : '',
1234
  'value' => 'none',
1244
  $blacklist_names[] = $value['name'];
1245
  }
1246
 
1247
+ $custom_field_names = MLAOptions::_get_custom_field_names();
1248
  foreach ( $custom_field_names as $value ) {
1249
  if ( in_array( $value, $blacklist_names ) ) {
1250
  continue;
1262
  return $custom_field_options;
1263
  } // _compose_custom_field_option_list
1264
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1265
  /**
1266
  * Compose a (Custom Field) Data Source Options list with current selection
1267
  *
1273
  * @return string HTML markup with select field options
1274
  */
1275
  private static function _compose_data_source_option_list( $selection = 'none' ) {
1276
+ $option_template = MLAOptions::$mla_option_templates['custom-field-select-option'];
1277
 
1278
  $option_values = array (
1279
  'selected' => ( 'none' == $selection ) ? 'selected="selected"' : '',
1296
  );
1297
  $custom_field_options .= MLAData::mla_parse_template( $option_template, $option_values );
1298
 
1299
+ if ( !class_exists( 'MLAData_Source' ) ) {
1300
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-data-source.php' );
1301
+ }
1302
+
1303
  $intermediate_sizes = get_intermediate_image_sizes();
1304
+ foreach ( MLAData_Source::$custom_field_data_sources as $value ) {
1305
  $size_pos = strpos( $value, '[size]' );
1306
  if ( $size_pos ) {
1307
  $root_value = substr( $value, 0, $size_pos );
1344
  $error_list = '';
1345
  $message_list = '';
1346
  $settings_changed = false;
1347
+ $custom_field_names = MLAOptions::_get_custom_field_names();
1348
  $new_values = stripslashes_deep( $new_values );
1349
 
1350
  foreach ( $new_values as $the_key => $new_value ) {
1357
  /*
1358
  * Check for the addition of a new rule or field
1359
  */
1360
+ if ( MLACore::MLA_NEW_CUSTOM_FIELD === $the_key ) {
1361
  if ( empty( $new_key ) ) {
1362
  continue;
1363
  }
1371
  /* translators: 1: custom field name */
1372
  $message_list .= '<br>' . sprintf( __( 'Adding new field %1$s.', 'media-library-assistant' ), esc_html( $new_key ) ) . "\r\n";
1373
  $any_setting_changed = true;
1374
+ } elseif ( MLACore::MLA_NEW_CUSTOM_RULE === $the_key ) {
1375
  if ( 'none' == $new_key ) {
1376
  continue;
1377
  }
1549
  *
1550
  * @return string HTML table row markup for 'render' else message(s) reflecting the results of the operation.
1551
  */
1552
+ public static function mla_custom_field_option_handler( $action, $key, $value, $args = NULL ) {
1553
+ $current_values = MLACore::mla_get_option( 'custom_field_mapping' );
1554
 
1555
  switch ( $action ) {
1556
  case 'render':
1557
  if (empty( $current_values ) ) {
1558
+ $table_rows = MLAData::mla_parse_template( MLAOptions::$mla_option_templates['custom-field-empty-row'],
1559
  array(
1560
  'No Mapping Rules' => __( 'No Custom Field Mapping Rules Defined', 'media-library-assistant' ),
1561
  'column_count' => 7 ) );
1562
  } else {
1563
+ $row_template = MLAOptions::$mla_option_templates['custom-field-rule-row'];
1564
  $table_rows = '';
1565
  $index = 0;
1566
  }
1596
  'key' => esc_attr( $row_name ),
1597
  'name_attr' => esc_attr( $row_name ),
1598
  'name' => esc_html( $row_name ),
1599
+ 'data_source_options' => MLAOptions::_compose_data_source_option_list( $current_value['data_source'] ),
1600
  'keep_selected' => '',
1601
  'Keep' => __( 'Keep', 'media-library-assistant' ),
1602
  'replace_selected' => '',
1688
  /*
1689
  * Add a row for defining a new Custom Rule
1690
  */
1691
+ $row_template = MLAOptions::$mla_option_templates['custom-field-new-rule-row'];
1692
  $row_values = array (
1693
  'column_count' => 7,
1694
  'column_count_meta' => (7 - 2),
1695
  'Add new Rule' => __( 'Add a new Mapping Rule', 'media-library-assistant' ),
1696
+ 'index' => MLACore::MLA_NEW_CUSTOM_RULE,
1697
+ 'field_name_options' => MLAOptions::_compose_custom_field_option_list( 'none', $current_values ),
1698
+ 'data_source_options' => MLAOptions::_compose_data_source_option_list( 'none' ),
1699
  'keep_selected' => '',
1700
  'Keep' => __( 'Keep', 'media-library-assistant' ),
1701
  'replace_selected' => 'selected="selected"',
1732
  /*
1733
  * Add a row for defining a new Custom Field
1734
  */
1735
+ $row_template = MLAOptions::$mla_option_templates['custom-field-new-field-row'];
1736
  $row_values = array (
1737
  'column_count' => 7,
1738
  'column_count_meta' => (7 - 2),
1739
  'Add new Field' => __( 'Add a new Field and Mapping Rule', 'media-library-assistant' ),
1740
+ 'index' => MLACore::MLA_NEW_CUSTOM_FIELD,
1741
  'field_name_size' => '24',
1742
+ 'data_source_options' => MLAOptions::_compose_data_source_option_list( 'none' ),
1743
  'keep_selected' => '',
1744
  'Keep' => __( 'Keep', 'media-library-assistant' ),
1745
  'replace_selected' => 'selected="selected"',
1785
  'help' => $value['help']
1786
  );
1787
 
1788
+ return MLAData::mla_parse_template( MLAOptions::$mla_option_templates['custom-field-table'], $option_values );
1789
  case 'update':
1790
  case 'delete':
1791
  $settings_changed = false;
1792
  $messages = '';
1793
 
1794
+ $results = MLAOptions::_update_custom_field_mapping( $current_values, $args );
1795
  $messages .= $results['message'];
1796
  $current_values = $results['values'];
1797
  $settings_changed = $results['changed'];
1798
 
1799
  if ( $settings_changed ) {
1800
+ $settings_changed = MLACore::mla_update_option( 'custom_field_mapping', $current_values );
1801
  if ( $settings_changed ) {
1802
  $results = __( 'Custom field mapping rules updated.', 'media-library-assistant' ) . "\r\n";
1803
  } else {
1809
 
1810
  return $results . $messages;
1811
  case 'reset':
1812
+ $current_values = MLACore::$mla_option_definitions['custom_field_mapping']['std'];
1813
+ $settings_changed = MLACore::mla_update_option( 'custom_field_mapping', $current_values );
1814
  if ( $settings_changed ) {
1815
  return __( 'Custom field mapping settings saved.', 'media-library-assistant' ) . "\r\n";
1816
  } else {
1890
  $data_source_category = $update_all ? 'single_attachment_mapping' : 'custom_field_mapping';
1891
 
1892
  if ( NULL == $settings ) {
1893
+ $settings = MLACore::mla_get_option( 'iptc_exif_mapping' );
1894
  }
1895
 
1896
  $settings = apply_filters( 'mla_mapping_settings', $settings, $post->ID, $category, $attachment_metadata );
1921
  'format' => 'native',
1922
  'option' => 'text' );
1923
 
1924
+ $exif_value = MLAOptions::mla_get_data_source( $post->ID, $data_source_category, $data_value, $attachment_metadata );
1925
  if ( ' ' == $exif_value ) {
1926
  $exif_value = '';
1927
  }
1947
  }
1948
  }
1949
 
1950
+ $new_text = apply_filters( 'mla_mapping_new_text', $new_text, $setting_key, $post->ID, 'iptc_exif_standard_mapping', $attachment_metadata );
1951
+
1952
  if ( is_array( $new_text ) ) {
1953
  $new_text = implode( ',', $new_text );
1954
  }
2004
  $tax_actions = array();
2005
 
2006
  foreach ( $settings['taxonomy'] as $setting_key => $setting_value ) {
2007
+ if ( ! MLACore::mla_taxonomy_support($setting_key, 'support') ) {
2008
+ continue;
2009
+ }
2010
+
2011
  /*
2012
  * Convert checkbox value(s)
2013
  */
2035
  'format' => 'native',
2036
  'option' => 'array' );
2037
 
2038
+ $exif_value = MLAOptions::mla_get_data_source( $post->ID, $data_source_category, $data_value, $attachment_metadata );
2039
  if ( ' ' == $exif_value ) {
2040
  $exif_value = '';
2041
  }
2099
  $new_text = array_unique( $new_terms );
2100
  } // foreach $delimiter
2101
 
2102
+ $new_text = apply_filters( 'mla_mapping_new_text', $new_text, $setting_key, $post->ID, 'iptc_exif_taxonomy_mapping', $attachment_metadata );
2103
+
2104
  if ( empty( $new_text ) ) {
2105
  continue;
2106
  }
2131
  */
2132
  $new_terms = array();
2133
  foreach ( $new_text as $new_term ) {
2134
+ if ( 0 < $new_term = MLAOptions::_get_term_id( $new_term, $tax_parent, $setting_key, $post_terms ) ) {
2135
  $new_terms[] = $new_term;
2136
  }
2137
  } // foreach new_term
2202
  'format' => $setting_value['format'],
2203
  'option' => $setting_value['option'] );
2204
 
2205
+ $iptc_value = MLAOptions::mla_get_data_source( $post->ID, $data_source_category, $data_value, $attachment_metadata );
2206
  if ( ' ' == $iptc_value ) {
2207
  $iptc_value = '';
2208
  }
2225
  $data_value['meta_name'] = '([+exif:' . $exif_value . '+])';
2226
  }
2227
 
2228
+ $exif_value = MLAOptions::mla_get_data_source( $post->ID, $data_source_category, $data_value, $attachment_metadata );
2229
  if ( ' ' == $exif_value ) {
2230
  $exif_value = '';
2231
  }
2247
  }
2248
  }
2249
 
2250
+ $new_text = apply_filters( 'mla_mapping_new_text', $new_text, $setting_key, $post->ID, 'iptc_exif_custom_mapping', $attachment_metadata );
2251
+
2252
  if ( $setting_value['keep_existing'] ) {
2253
  if ( 'meta:' == substr( $setting_name, 0, 5 ) ) {
2254
  $meta_key = substr( $setting_name, 5 );
2300
  * @return string HTML markup with select field options
2301
  */
2302
  private static function _compose_iptc_option_list( $selection = 'none' ) {
2303
+ $option_template = MLAOptions::$mla_option_templates['iptc-exif-select-option'];
2304
  $option_values = array (
2305
  'selected' => ( 'none' == $selection ) ? 'selected="selected"' : '',
2306
  'value' => 'none',
2397
  /*
2398
  * Field Title can change as a result of localization
2399
  */
2400
+ $new_value['name'] = MLACore::$mla_option_definitions['iptc_exif_mapping']['std']['standard'][ $new_key ]['name'];
2401
 
2402
  if ( $old_values['name'] != $new_value['name'] ) {
2403
  $any_setting_changed = true;
2457
  /*
2458
  * Uncomment this for debugging.
2459
  */
2460
+ // $error_list .= $message_list;
2461
 
2462
  return array( 'message' => $error_list, 'values' => $current_values, 'changed' => $settings_changed );
2463
  } // _update_iptc_exif_standard_mapping
2592
  $error_list = '';
2593
  $message_list = '';
2594
  $settings_changed = false;
2595
+ $custom_field_names = MLAOptions::_get_custom_field_names();
2596
  $new_values = stripslashes_deep( $new_values );
2597
 
2598
  foreach ( $new_values['custom'] as $the_key => $new_value ) {
2605
  /*
2606
  * Check for the addition of a new field or new rule
2607
  */
2608
+ if ( MLACore::MLA_NEW_CUSTOM_FIELD === $the_key ) {
2609
  if ( empty( $new_key ) ) {
2610
  continue;
2611
  }
2619
  /* translators: 1: custom field name */
2620
  $message_list .= '<br>' . sprintf( __( 'Adding new field %1$s.', 'media-library-assistant' ), esc_html( $new_key ) ) . "\r\n";
2621
  $any_setting_changed = true;
2622
+ } elseif ( MLACore::MLA_NEW_CUSTOM_RULE === $the_key ) {
2623
  if ( 'none' == $new_key ) {
2624
  continue;
2625
  }
2755
  private static function _get_custom_field_names( ) {
2756
  global $wpdb;
2757
 
2758
+ $custom_field_mapping = MLACore::mla_get_option( 'custom_field_mapping' );
2759
+ $iptc_exif_mapping = MLACore::mla_get_option( 'iptc_exif_mapping' );
2760
  $iptc_exif_mapping = $iptc_exif_mapping['custom'];
2761
 
2762
  $limit = (int) apply_filters( 'postmeta_form_limit', 100 );
2801
  *
2802
  * @return string HTML table row markup for 'render' else message(s) reflecting the results of the operation.
2803
  */
2804
+ public static function mla_iptc_exif_option_handler( $action, $key, $value, $args = NULL ) {
2805
+ $current_values = MLACore::mla_get_option( 'iptc_exif_mapping' );
2806
 
2807
  switch ( $action ) {
2808
  case 'render':
2809
 
2810
  switch ( $key ) {
2811
  case 'iptc_exif_standard_mapping':
2812
+ $row_template = MLAOptions::$mla_option_templates['iptc-exif-standard-row'];
2813
  $table_rows = '';
2814
 
2815
  foreach ( $current_values['standard'] as $row_name => $row_value ) {
2817
  'key' => esc_attr( $row_name ),
2818
  'name_attr' => esc_attr( $row_value['name'] ),
2819
  'name' => esc_html( $row_value['name'] ),
2820
+ 'iptc_field_options' => MLAOptions::_compose_iptc_option_list( $row_value['iptc_value'] ),
2821
+ 'exif_size' => MLACore::MLA_EXIF_SIZE,
2822
  'exif_text' => esc_attr( $row_value['exif_value'] ),
2823
  'iptc_selected' => '',
2824
  'IPTC' => __( 'IPTC', 'media-library-assistant' ),
2855
  'help' => $value['help']
2856
  );
2857
 
2858
+ return MLAData::mla_parse_template( MLAOptions::$mla_option_templates['iptc-exif-standard-table'], $option_values );
2859
  case 'iptc_exif_taxonomy_mapping':
2860
+ $row_template = MLAOptions::$mla_option_templates['iptc-exif-taxonomy-row'];
2861
+ $select_template = MLAOptions::$mla_option_templates['iptc-exif-select'];
2862
  $table_rows = '';
2863
  $taxonomies = get_taxonomies( array ( 'show_ui' => true ), 'objects' );
2864
 
2865
  foreach ( $taxonomies as $row_name => $row_value ) {
2866
+ if ( ! MLACore::mla_taxonomy_support($row_name, 'support') ) {
2867
+ continue;
2868
+ }
2869
+
2870
  $row_values = array (
2871
  'key' => esc_attr( $row_name ),
2872
  'name' => esc_html( $row_value->labels->name ),
2873
  'hierarchical' => (string) $row_value->hierarchical,
2874
  'iptc_field_options' => '',
2875
+ 'exif_size' => MLACore::MLA_EXIF_SIZE,
2876
  'exif_text' => '',
2877
  'iptc_selected' => '',
2878
  'IPTC' => __( 'IPTC', 'media-library-assistant' ),
2889
 
2890
  if ( array_key_exists( $row_name, $current_values['taxonomy'] ) ) {
2891
  $current_value = $current_values['taxonomy'][ $row_name ];
2892
+ $row_values['iptc_field_options'] = MLAOptions::_compose_iptc_option_list( $current_value['iptc_value'] );
2893
  $row_values['exif_text'] = esc_attr( $current_value['exif_value'] );
2894
 
2895
  if ( $current_value['iptc_first'] ) {
2912
  'array' => 'taxonomy',
2913
  'key' => esc_attr( $row_name ),
2914
  'element' => 'parent',
2915
+ 'options' => MLAOptions::_compose_parent_option_list( $row_name, $parent )
2916
  );
2917
  $row_values['parent_select'] = MLAData::mla_parse_template( $select_template, $select_values );
2918
  }
2919
  } else {
2920
+ $row_values['iptc_field_options'] = MLAOptions::_compose_iptc_option_list( 'none' );
2921
  $row_values['iptc_selected'] = 'selected="selected"';
2922
  $row_values['keep_selected'] = 'selected="selected"';
2923
 
2926
  'array' => 'taxonomy',
2927
  'key' => esc_attr( $row_name ),
2928
  'element' => 'parent',
2929
+ 'options' => MLAOptions::_compose_parent_option_list( $row_name, 0 )
2930
  );
2931
  $row_values['parent_select'] = MLAData::mla_parse_template( $select_template, $select_values );
2932
  }
2947
  'help' => $value['help']
2948
  );
2949
 
2950
+ return MLAData::mla_parse_template( MLAOptions::$mla_option_templates['iptc-exif-taxonomy-table'], $option_values );
2951
  case 'iptc_exif_custom_mapping':
2952
  if ( empty( $current_values['custom'] ) ) {
2953
+ $table_rows = MLAData::mla_parse_template( MLAOptions::$mla_option_templates['iptc-exif-custom-empty-row'],
2954
  array(
2955
  'No Mapping Rules' => __( 'No Custom Field Mapping Rules Defined', 'media-library-assistant' ),
2956
  'column_count' => 5 ) );
2957
  } else {
2958
+ $row_template = MLAOptions::$mla_option_templates['iptc-exif-custom-rule-row'];
2959
  $table_rows = '';
2960
  $index = 0;
2961
  }
2991
  'key' => esc_attr( $row_name ),
2992
  'name_attr' => esc_attr( $current_value['name'] ),
2993
  'name' => esc_html( $current_value['name'] ),
2994
+ 'iptc_field_options' => MLAOptions::_compose_iptc_option_list( $current_value['iptc_value'] ),
2995
+ 'exif_size' => MLACore::MLA_EXIF_SIZE,
2996
  'exif_text' => esc_attr( $current_value['exif_value'] ),
2997
  'iptc_selected' => '',
2998
  'IPTC' => __( 'IPTC', 'media-library-assistant' ),
3079
  /*
3080
  * Add a row for defining a new rule, existing Custom Field
3081
  */
3082
+ $row_template = MLAOptions::$mla_option_templates['iptc-exif-custom-new-rule-row'];
3083
  $row_values = array (
3084
  'column_count' => 5 ,
3085
  'column_count_meta' => (5 - 2),
3086
  'Add new Rule' => __( 'Add a new Mapping Rule', 'media-library-assistant' ),
3087
+ 'index' => MLACore::MLA_NEW_CUSTOM_RULE,
3088
+ 'field_name_options' => MLAOptions::_compose_custom_field_option_list( 'none', $current_values['custom'] ),
3089
+ 'iptc_field_options' => MLAOptions::_compose_iptc_option_list( 'none' ),
3090
+ 'exif_size' => MLACore::MLA_EXIF_SIZE,
3091
  'exif_text' => '',
3092
  'iptc_selected' => 'selected="selected"',
3093
  'IPTC' => __( 'IPTC', 'media-library-assistant' ),
3125
  /*
3126
  * Add a row for defining a new rule, new Custom Field
3127
  */
3128
+ $row_template = MLAOptions::$mla_option_templates['iptc-exif-custom-new-field-row'];
3129
  $row_values = array (
3130
  'column_count' => 5 ,
3131
  'column_count_meta' => (5 - 2),
3132
  'Add new Field' => __( 'Add a new Field and Mapping Rule', 'media-library-assistant' ),
3133
+ 'index' => MLACore::MLA_NEW_CUSTOM_FIELD,
3134
  'field_name_size' => '24',
3135
+ 'iptc_field_options' => MLAOptions::_compose_iptc_option_list( 'none' ),
3136
+ 'exif_size' => MLACore::MLA_EXIF_SIZE,
3137
  'exif_text' => '',
3138
  'iptc_selected' => 'selected="selected"',
3139
  'IPTC' => __( 'IPTC', 'media-library-assistant' ),
3178
  'help' => $value['help']
3179
  );
3180
 
3181
+ return MLAData::mla_parse_template( MLAOptions::$mla_option_templates['iptc-exif-custom-table'], $option_values );
3182
  default:
3183
  /* translators: 1: ERROR tag 2: option name */
3184
  return '<br>' . sprintf( __( '%1$s: Render unknown custom %2$s.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $key ) . "\r\n";
3190
 
3191
  switch ( $key ) {
3192
  case 'iptc_exif_standard_mapping':
3193
+ $results = MLAOptions::_update_iptc_exif_standard_mapping( $current_values, $args );
3194
  $messages .= $results['message'];
3195
  $current_values = $results['values'];
3196
  $settings_changed = $results['changed'];
3197
  break;
3198
  case 'iptc_exif_taxonomy_mapping':
3199
+ $results = MLAOptions::_update_iptc_exif_taxonomy_mapping( $current_values, $args );
3200
  $messages .= $results['message'];
3201
  $current_values = $results['values'];
3202
  $settings_changed = $results['changed'];
3203
  break;
3204
  case 'iptc_exif_custom_mapping':
3205
+ $results = MLAOptions::_update_iptc_exif_custom_mapping( $current_values, $args );
3206
  $messages .= $results['message'];
3207
  $current_values = $results['values'];
3208
  $settings_changed = $results['changed'];
3209
  break;
3210
  case 'iptc_exif_mapping':
3211
+ $results = MLAOptions::_update_iptc_exif_standard_mapping( $current_values, $args );
3212
  $messages .= $results['message'];
3213
  $current_values = $results['values'];
3214
  $settings_changed = $results['changed'];
3215
 
3216
+ $results = MLAOptions::_update_iptc_exif_taxonomy_mapping( $current_values, $args );
3217
  $messages .= $results['message'];
3218
  $current_values = $results['values'];
3219
  $settings_changed |= $results['changed'];
3220
 
3221
+ $results = MLAOptions::_update_iptc_exif_custom_mapping( $current_values, $args );
3222
  $messages .= $results['message'];
3223
  $current_values = $results['values'];
3224
  $settings_changed |= $results['changed'];
3229
  } // switch $key
3230
 
3231
  if ( $settings_changed ) {
3232
+ $settings_changed = MLACore::mla_update_option( 'iptc_exif_mapping', $current_values );
3233
  if ( $settings_changed ) {
3234
  $results = __( 'IPTC/EXIF mapping settings updated.', 'media-library-assistant' ) . "\r\n";
3235
  } else {
3243
  case 'reset':
3244
  switch ( $key ) {
3245
  case 'iptc_exif_standard_mapping':
3246
+ $current_values['standard'] = MLACore::$mla_option_definitions['iptc_exif_mapping']['std']['standard'];
3247
+ $settings_changed = MLACore::mla_update_option( 'iptc_exif_mapping', $current_values );
3248
  if ( $settings_changed ) {
3249
  /* translators: 1: field type */
3250
  return sprintf( __( '%1$s settings saved.', 'media-library-assistant' ), 'IPTC/EXIF ' . __( 'Standard field', 'media-library-assistant' ) ) . "\r\n";
3253
  return sprintf( __( '%1$s: IPTC/EXIF %2$s settings update failed.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'Standard field', 'media-library-assistant' ) ) . "\r\n";
3254
  }
3255
  case 'iptc_exif_taxonomy_mapping':
3256
+ $current_values['taxonomy'] = MLACore::$mla_option_definitions['iptc_exif_mapping']['std']['taxonomy'];
3257
+ $settings_changed = MLACore::mla_update_option( 'iptc_exif_mapping', $current_values );
3258
  if ( $settings_changed ) {
3259
  /* translators: 1: field type */
3260
  return sprintf( __( '%1$s settings saved.', 'media-library-assistant' ), 'IPTC/EXIF ' . __( 'Taxonomy term', 'media-library-assistant' ) ) . "\r\n";
3263
  return sprintf( __( '%1$s: IPTC/EXIF %2$s settings update failed.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'Taxonomy term', 'media-library-assistant' ) ) . "\r\n";
3264
  }
3265
  case 'iptc_exif_custom_mapping':
3266
+ $current_values['custom'] = MLACore::$mla_option_definitions['iptc_exif_mapping']['std']['custom'];
3267
+ $settings_changed = MLACore::mla_update_option( 'iptc_exif_mapping', $current_values );
3268
  if ( $settings_changed ) {
3269
  /* translators: 1: field type */
3270
  return sprintf( __( '%1$s settings saved.', 'media-library-assistant' ), 'IPTC/EXIF ' . __( 'Custom field', 'media-library-assistant' ) ) . "\r\n";
3273
  return sprintf( __( '%1$s: IPTC/EXIF %2$s settings update failed.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'Custom field', 'media-library-assistant' ) ) . "\r\n";
3274
  }
3275
  case 'iptc_exif_mapping':
3276
+ MLACore::mla_delete_option( $key );
3277
  /* translators: 1: option name, e.g., taxonomy_support */
3278
  return '<br>' . sprintf( __( 'Reset custom %1$s', 'media-library-assistant' ), $key ) . "\r\n";
3279
  default:
includes/class-mla-polylang-support.php CHANGED
@@ -58,14 +58,14 @@ class MLA_Polylang {
58
  add_action( 'admin_enqueue_scripts', 'MLA_Polylang::admin_enqueue_scripts', 10, 1 );
59
 
60
  /*
61
- * Defined in wp-includes/post.php function wp_insert_post
62
  */
63
- add_action( 'edit_attachment', 'MLA_Polylang::edit_attachment', 10, 1 );
64
 
65
  /*
66
- * Defined in wp-admin/includes/post.php function edit_post
67
  */
68
- add_filter( 'attachment_fields_to_save', 'MLA_Polylang::attachment_fields_to_save', 10, 2 );
69
 
70
  /*
71
  * Defined in /media-library-assistant/includes/class-mla-data.php
@@ -115,6 +115,9 @@ class MLA_Polylang {
115
  * Defined in /media-library-assistant/includes/class-mla-settings.php
116
  */
117
  add_filter( 'mla_get_options_tablist', 'MLA_Polylang::mla_get_options_tablist', 10, 3 );
 
 
 
118
 
119
  /*
120
  * Defined in /polylang/admin/admin-filters-media.php
@@ -179,11 +182,11 @@ class MLA_Polylang {
179
  /*
180
  * Add styles for the language management column
181
  */
182
- if ( isset( $_REQUEST['page'] ) && ( MLA::ADMIN_PAGE_SLUG == $_REQUEST['page'] ) ) {
183
  add_action( 'admin_print_styles', 'MLA_Polylang::mla_list_table_add_pll_styles' );
184
  }
185
 
186
- if ( ( defined('WP_ADMIN') && WP_ADMIN ) && ( defined('DOING_AJAX') && DOING_AJAX ) ) {
187
  add_action( 'wp_ajax_' . 'mla-polylang-quick-translate', 'MLA_Polylang::quick_translate' );
188
  }
189
 
@@ -230,13 +233,13 @@ class MLA_Polylang {
230
  * function translate_media()
231
  */
232
  $post = get_post( $post_id );
233
- $post->ID = null; // will force the creation
234
  $post->post_parent = ( $post->post_parent && $tr_parent = $polylang->model->get_translation( 'post', $post->post_parent, $new_language ) ) ? $tr_parent : 0;
235
  $new_id = wp_insert_attachment( $post );
236
  add_post_meta( $new_id, '_wp_attachment_metadata', get_post_meta( $post_id, '_wp_attachment_metadata', true ) );
237
  add_post_meta( $new_id, '_wp_attached_file', get_post_meta( $post_id, '_wp_attached_file', true ) );
238
 
239
- if ( 'checked' == MLAOptions::mla_get_option( 'term_synchronization', false, false, MLA_Polylang::$mla_language_option_definitions ) ) {
240
  self::_build_existing_terms( $post_id );
241
  self::_build_tax_input( $post_id );
242
  $tax_inputs = self::_apply_tax_input( 0, $new_language );
@@ -274,7 +277,7 @@ class MLA_Polylang {
274
  public static function quick_translate() {
275
  global $polylang;
276
 
277
- check_ajax_referer( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
278
 
279
  if ( empty( $_REQUEST['post_ID'] ) ) {
280
  echo __( 'ERROR: No post ID found', 'media-library-assistant' );
@@ -308,7 +311,7 @@ class MLA_Polylang {
308
  $_REQUEST['_inline_edit'] = wp_create_nonce( 'inlineeditnonce' );
309
  $polylang->filters_post->save_post( $post_id, $post, true );
310
 
311
- if ( 'checked' == MLAOptions::mla_get_option( 'term_assignment', false, false, MLA_Polylang::$mla_language_option_definitions ) ) {
312
  // Record new language for Term Assignment and Synchronization
313
  if ( ! empty( $_REQUEST['tax_input'] ) ) {
314
  // Discard the old translation, which is gone
@@ -386,7 +389,7 @@ class MLA_Polylang {
386
  'comma' => _x( ',', 'tag_delimiter', 'media-library-assistant' ),
387
  'useSpinnerClass' => false,
388
  'ajax_action' => MLA_Polylang::MLA_PLL_QUICK_TRANSLATE,
389
- 'ajax_nonce' => wp_create_nonce( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME )
390
  );
391
 
392
  if ( version_compare( get_bloginfo( 'version' ), '4.2', '>=' ) ) {
@@ -418,7 +421,7 @@ class MLA_Polylang {
418
  global $polylang;
419
  static $already_adding = 0;
420
 
421
- MLA::mla_debug_add( __LINE__ . " MLA_Polylang::pll_translate_media( {$duplicated_attachment_id} ) translations = " . var_export( $translations, true ), MLA::MLA_DEBUG_CATEGORY_LANGUAGE );
422
 
423
  if ( $already_adding == $duplicated_attachment_id ) {
424
  return;
@@ -431,7 +434,7 @@ class MLA_Polylang {
431
  self::$duplicate_attachments [ $duplicated_attachment_id ] = $language_code;
432
 
433
  if ( isset( $_REQUEST['action'] ) && 'translate_media' == $_REQUEST['action'] ) {
434
- if ( 'checked' == MLAOptions::mla_get_option( 'term_synchronization', false, false, MLA_Polylang::$mla_language_option_definitions ) ) {
435
  // Clone the existing common terms to the new translation
436
  self::_build_existing_terms( $attachment_id );
437
  self::_build_tax_input( $attachment_id );
@@ -449,6 +452,224 @@ class MLA_Polylang {
449
  } // translate_media
450
  } // pll_translate_media
451
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
452
  /**
453
  * Taxonomy terms and translations
454
  *
@@ -615,17 +836,17 @@ class MLA_Polylang {
615
  }
616
 
617
  $language_details = $polylang->model->get_post_language( $post_id );
618
- MLA::mla_debug_add( "MLA_Polylang::_build_existing_terms( {$post_id} ) \$polylang->model->get_post_language = " . var_export( $language_details, true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
619
 
620
  if ( is_object( $language_details ) ) {
621
  $language_details = (array) $language_details;
622
  } else {
623
- MLA::mla_debug_add( "MLA_Polylang::_build_existing_terms( {$post_id} ) pll_default_language() = " . var_export( pll_default_language(), true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
624
  $language_details = (array) $polylang->model->get_language( pll_default_language() );
625
- MLA::mla_debug_add( "MLA_Polylang::_build_existing_terms( {$post_id} ) \$polylang->model->get_language( pll_default_language() ) = " . var_export( $language_details, true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
626
  }
627
 
628
- MLA::mla_debug_add( "MLA_Polylang::_build_existing_terms( {$post_id} ) \$polylang->model->get_translations() = " . var_export( $polylang->model->get_translations( 'post', $post_id ), true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
629
  $translations = array();
630
  foreach ( $polylang->model->get_translations( 'post', $post_id ) as $language_code => $translation ) {
631
  $translations[ $language_code ] = array( 'element_id' => $translation );
@@ -668,8 +889,8 @@ class MLA_Polylang {
668
  } // translation
669
  } // term
670
 
671
- MLA::mla_debug_add( "MLA_Polylang::_build_existing_terms( {$post_id} ) self::\$existing_terms = " . var_export( self::$existing_terms, true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
672
- MLA::mla_debug_add( "MLA_Polylang::_build_existing_terms( {$post_id} ) self::\$relevant_terms = " . var_export( self::$relevant_terms, true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
673
  return;
674
  }
675
 
@@ -690,8 +911,8 @@ class MLA_Polylang {
690
  */
691
  private static function _update_existing_terms( $post_id ) {
692
  global $polylang;
693
- MLA::mla_debug_add( "MLA_Polylang::_update_existing_terms( {$post_id} ) initial self::\$existing_terms = " . var_export( self::$existing_terms, true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
694
- MLA::mla_debug_add( "MLA_Polylang::_update_existing_terms( {$post_id} ) initial self::\$relevant_terms = " . var_export( self::$relevant_terms, true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
695
 
696
  if ( $post_id != self::$existing_terms['element_id'] ) {
697
  return false;
@@ -738,8 +959,8 @@ class MLA_Polylang {
738
  } // translation
739
  } // term
740
 
741
- MLA::mla_debug_add( "MLA_Polylang::_update_existing_terms( {$post_id} ) final self::\$existing_terms = " . var_export( self::$existing_terms, true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
742
- MLA::mla_debug_add( "MLA_Polylang::_update_existing_terms( {$post_id} ) final self::\$relevant_terms = " . var_export( self::$relevant_terms, true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
743
  return $terms_before;
744
  }
745
 
@@ -790,7 +1011,6 @@ class MLA_Polylang {
790
  $terms = isset( $translation[ $taxonomy_name ] ) ? $translation[ $taxonomy_name ] : array();
791
  if ( ! empty( $terms ) ) {
792
  $no_terms = false;
793
- $taxonomy = get_taxonomy( $taxonomy_name );
794
  $input_terms = array();
795
  foreach ( $terms as $term ) {
796
  $input_terms[] = $term->term_id;
@@ -882,8 +1102,8 @@ class MLA_Polylang {
882
 
883
  } // foreach taxonomy
884
 
885
- MLA::mla_debug_add( "MLA_Polylang::_build_tax_input( {$post_id} ) self::\$tax_input = " . var_export( self::$tax_input, true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
886
- MLA::mla_debug_add( "MLA_Polylang::_build_tax_input( {$post_id} ) self::\$relevant_terms = " . var_export( self::$relevant_terms, true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
887
  } // _build_tax_input
888
 
889
  /**
@@ -910,8 +1130,8 @@ class MLA_Polylang {
910
  }
911
  }
912
 
913
- MLA::mla_debug_add( "MLA_Polylang::_apply_tax_input( {$post_id} ) \$post_language = " . var_export( $post_language, true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
914
- MLA::mla_debug_add( "MLA_Polylang::_apply_tax_input( {$post_id} ) self::\$tax_input[ \$post_language ] = " . var_export( self::$tax_input[ $post_language ], true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
915
  return self::$tax_input[ $post_language ];
916
  } // _apply_tax_input
917
 
@@ -963,7 +1183,7 @@ class MLA_Polylang {
963
  foreach( self::$existing_terms[ $language ][ $taxonomy ] as $ttid => $term ) {
964
  $source_term = self::_get_relevant_term( 'term_taxonomy_id', $ttid, $taxonomy );
965
  if ( isset( $source_term['translations'][ $source_language ] ) ) {
966
- $dest_term = self::_get_relevant_term( 'id', $source_term['translations'][ $language ]->element_id, $taxonomy );
967
  $old_terms[ $taxonomy ][ $dest_term['term']->term_taxonomy_id ] = $dest_term['term'];
968
  }
969
  }
@@ -1035,8 +1255,8 @@ class MLA_Polylang {
1035
  } // synch_inputs
1036
 
1037
  $post_id = self::$existing_terms[ $language ]['element_id'];
1038
- MLA::mla_debug_add( "MLA_Polylang::_apply_synch_input( {$post_id} ) \$language = " . var_export( $language, true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
1039
- MLA::mla_debug_add( "MLA_Polylang::_apply_synch_input( {$post_id} ) \$tax_inputs = " . var_export( $tax_inputs, true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
1040
  return $tax_inputs;
1041
  } // _apply_synch_input
1042
 
@@ -1051,7 +1271,7 @@ class MLA_Polylang {
1051
  * @return array $tax_inputs for Term Synchronization
1052
  */
1053
  private static function _apply_term_synchronization( $post_id ) {
1054
- if ( 'checked' == MLAOptions::mla_get_option( 'term_synchronization', false, false, MLA_Polylang::$mla_language_option_definitions ) ) {
1055
 
1056
  /*
1057
  * Update terms because they have changed
@@ -1085,7 +1305,7 @@ class MLA_Polylang {
1085
  * @param integer $result Zero if the update failed else ID of the item that was updated.
1086
  */
1087
  public static function mla_updated_single_item( $post_id, $result ) {
1088
- MLA::mla_debug_add( __LINE__ . " MLA_Polylang::mla_updated_single_item( {$post_id}, {$result} )", MLA::MLA_DEBUG_CATEGORY_LANGUAGE );
1089
 
1090
  if ( self::$existing_terms['element_id'] == $post_id ) {
1091
  /*
@@ -1104,7 +1324,7 @@ class MLA_Polylang {
1104
  * @param array $attachment An array of attachment metadata.
1105
  */
1106
  public static function attachment_fields_to_save( $post, $attachment ) {
1107
- MLA::mla_debug_add( __LINE__ . " MLA_Polylang::attachment_fields_to_save post = " . var_export( $post, true ), MLA::MLA_DEBUG_CATEGORY_LANGUAGE );
1108
 
1109
  if ( 'editpost' == $post['action'] && 'attachment' == $post['post_type'] ) {
1110
  self::_build_existing_terms( $post['post_ID'] );
@@ -1124,7 +1344,7 @@ class MLA_Polylang {
1124
  public static function edit_attachment( $post_id ) {
1125
  static $already_updating = 0;
1126
 
1127
- MLA::mla_debug_add( __LINE__ . " MLA_Polylang::edit_attachment( {$post_id} ) _REQUEST = " . var_export( $_REQUEST, true ), MLA::MLA_DEBUG_CATEGORY_LANGUAGE );
1128
 
1129
  /*
1130
  * mla_update_single_item may call this action again
@@ -1141,7 +1361,7 @@ class MLA_Polylang {
1141
  if ( ! empty( $_REQUEST['mlaAddNewBulkEditFormString'] ) ) {
1142
  if ( ! empty( self::$bulk_edit_request['tax_input'] ) ) {
1143
  $tax_inputs = self::$bulk_edit_request['tax_input'];
1144
- if ( 'checked' == MLAOptions::mla_get_option( 'term_assignment', false, false, MLA_Polylang::$mla_language_option_definitions ) ) {
1145
  self::_build_tax_input( $post_id, $tax_inputs, self::$bulk_edit_request['tax_action'] );
1146
  $tax_inputs = self::_apply_tax_input( $post_id );
1147
  }
@@ -1183,7 +1403,7 @@ class MLA_Polylang {
1183
  $tax_actions = NULL;
1184
  }
1185
 
1186
- if ( ( ! empty( $tax_inputs ) ) && ( 'checked' == MLAOptions::mla_get_option( 'term_assignment', false, false, MLA_Polylang::$mla_language_option_definitions ) ) ) {
1187
  self::_build_tax_input( $post_id, $tax_inputs, $tax_actions );
1188
  $tax_inputs = self::_apply_tax_input( $post_id );
1189
  }
@@ -1205,7 +1425,7 @@ class MLA_Polylang {
1205
  public static function mla_media_modal_begin_update_compat_fields( $post ) {
1206
  $post_id = $post->ID;
1207
 
1208
- MLA::mla_debug_add( __LINE__ . " MLA_Polylang::mla_media_modal_begin_update_compat_fields( {$post_id} ) post = " . var_export( $post, true ), MLA::MLA_DEBUG_CATEGORY_LANGUAGE );
1209
 
1210
  // Accumulate for possible term_assignment or term_synchronization
1211
  self::_build_existing_terms( $post_id );
@@ -1223,16 +1443,15 @@ class MLA_Polylang {
1223
  * @param integer current post ID
1224
  */
1225
  public static function mla_media_modal_update_compat_fields_terms( $terms, $key, $value, $post_id ) {
1226
- MLA::mla_debug_add( __LINE__ . " MLA_Polylang::mla_media_modal_update_compat_fields_terms( {$key}, {$post_id} ) terms = " . var_export( $terms, true ), MLA::MLA_DEBUG_CATEGORY_LANGUAGE );
1227
 
1228
- // Accumulate for possible term_assignment or term_synchronization
1229
- if ( $value->hierarchical ) {
1230
- $tax_inputs = array( $key => $terms );
1231
- } else {
1232
- $tax_inputs = array( $key => implode( ',', $terms ) );
1233
- }
1234
 
1235
- if ( 'checked' == MLAOptions::mla_get_option( 'term_assignment', false, false, MLA_Polylang::$mla_language_option_definitions ) ) {
1236
  self::_build_tax_input( $post_id, $tax_inputs );
1237
  $tax_inputs = self::_apply_tax_input( $post_id );
1238
  $terms = $tax_inputs[ $key ];
@@ -1252,7 +1471,7 @@ class MLA_Polylang {
1252
  * @param object current post object
1253
  */
1254
  public static function mla_media_modal_end_update_compat_fields( $results, $taxonomies, $post ) {
1255
- MLA::mla_debug_add( __LINE__ . " MLA_Polylang::mla_media_modal_end_update_compat_fields( {$post->ID} ) taxonomies = " . var_export( $taxonomies, true ), MLA::MLA_DEBUG_CATEGORY_LANGUAGE );
1256
 
1257
  /*
1258
  * Synchronize the changes to all other translations
@@ -1278,15 +1497,19 @@ class MLA_Polylang {
1278
  public static function mla_list_table_inline_action( $item_content, $post_id ) {
1279
  global $polylang;
1280
 
1281
- MLA::mla_debug_add( __LINE__ . " MLA_Polylang::mla_list_table_inline_action( {$post_id} )", MLA::MLA_DEBUG_CATEGORY_LANGUAGE );
1282
 
1283
  self::_build_existing_terms( $post_id );
1284
  if ( isset( $_REQUEST['action'] ) && 'mla-inline-edit-scripts' === $_REQUEST['action'] && isset( $_REQUEST['tax_input'] ) ) {
1285
- MLA::mla_debug_add( "MLA_Polylang::mla_list_table_inline_action( {$post_id} ) Quick Edit initial \$_REQUEST['tax_input'] = " . var_export( $_REQUEST['tax_input'], true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
1286
- // Quick Edit calls update_single_item right after this filter
1287
- self::_build_tax_input( $post_id, $_REQUEST['tax_input'] );
1288
- $_REQUEST['tax_input'] = self::_apply_tax_input( $post_id );
1289
- MLA::mla_debug_add( "MLA_Polylang::mla_list_table_inline_action( {$post_id} ) Quick Edit final \$_REQUEST['tax_input'] = " . var_export( $_REQUEST['tax_input'], true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
 
 
 
 
1290
  }
1291
 
1292
  // Language dropdown in Quick Edit area
@@ -1300,7 +1523,7 @@ class MLA_Polylang {
1300
  $polylang->filters_post->save_post( $post_id, $post, true );
1301
 
1302
  // Record new language for Term Assignment and Synchronization
1303
- if ( ( ! empty( $_REQUEST['tax_input'] ) ) && ( 'checked' == MLAOptions::mla_get_option( 'term_assignment', false, false, MLA_Polylang::$mla_language_option_definitions ) ) ) {
1304
  // Discard the old translation, which is gone
1305
  unset( self::$existing_terms[ self::$existing_terms['slug'] ] );
1306
  self::$existing_terms['slug'] = $_REQUEST['inline_lang_choice'];
@@ -1323,7 +1546,7 @@ class MLA_Polylang {
1323
  * @return array updated bulk action request parameters
1324
  */
1325
  public static function mla_list_table_bulk_action_initial_request( $request, $bulk_action, $custom_field_map ) {
1326
- MLA::mla_debug_add( __LINE__ . " MLA_Polylang::mla_list_table_bulk_action_initial_request( {$bulk_action} ) request = " . var_export( $request, true ), MLA::MLA_DEBUG_CATEGORY_LANGUAGE );
1327
 
1328
  self::$bulk_edit_request = $request;
1329
  self::$bulk_edit_map = $custom_field_map;
@@ -1362,12 +1585,12 @@ class MLA_Polylang {
1362
  * @return array updated bulk action request parameters
1363
  */
1364
  public static function mla_list_table_bulk_action_item_request( $request, $bulk_action, $post_id, $custom_field_map ) {
1365
- MLA::mla_debug_add( __LINE__ . " MLA_Polylang::mla_list_table_bulk_action_item_request( {$post_id} ) request = " . var_export( $request, true ), MLA::MLA_DEBUG_CATEGORY_LANGUAGE );
1366
 
1367
  /*
1368
  * Note that $request may be modified by previous items, so we must return to the initial vlues
1369
  */
1370
- if ( 'edit' == $bulk_action && ( ! empty( self::$bulk_edit_request['tax_input'] ) ) && ( 'checked' == MLAOptions::mla_get_option( 'term_assignment', false, false, MLA_Polylang::$mla_language_option_definitions ) ) ) {
1371
  self::_build_existing_terms( $post_id );
1372
  self::_build_tax_input( $post_id, self::$bulk_edit_request['tax_input'], $request['tax_action'] );
1373
  $request['tax_input'] = self::_apply_tax_input( $post_id );
@@ -1380,15 +1603,15 @@ class MLA_Polylang {
1380
  }
1381
 
1382
  if ( isset( $request['tax_input'] ) ) {
1383
- MLA::mla_debug_add( "MLA_Polylang::bulk_action_item_request( {$bulk_action}, {$post_id} ) \$request['tax_input'] = " . var_export( $request['tax_input'], true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
1384
  } else {
1385
- MLA::mla_debug_add( "MLA_Polylang::bulk_action_item_request( {$bulk_action}, {$post_id} ) \$request['tax_input'] NOT SET", MLA::MLA_DEBUG_CATEGORY_AJAX );
1386
  }
1387
 
1388
  if ( isset( $request['tax_action'] ) ) {
1389
- MLA::mla_debug_add( "MLA_Polylang::bulk_action_item_request( {$bulk_action}, {$post_id} ) \$request['tax_action'] = " . var_export( $request['tax_action'], true ), MLA::MLA_DEBUG_CATEGORY_AJAX );
1390
  } else {
1391
- MLA::mla_debug_add( "MLA_Polylang::bulk_action_item_request( {$bulk_action}, {$post_id} ) \$request['tax_action'] NOT SET", MLA::MLA_DEBUG_CATEGORY_AJAX );
1392
  }
1393
 
1394
  return $request;
@@ -1410,7 +1633,7 @@ class MLA_Polylang {
1410
  public static function mla_list_table_bulk_action( $item_content, $bulk_action, $post_id ) {
1411
  global $polylang;
1412
 
1413
- MLA::mla_debug_add( __LINE__ . " MLA_Polylang::mla_list_table_bulk_action( {$bulk_action}, {$post_id} )", MLA::MLA_DEBUG_CATEGORY_LANGUAGE );
1414
 
1415
  // Language dropdown in Bulk Edit area
1416
  if ( isset( $_POST['inline_lang_choice'] ) && ( '-1' != $_POST['inline_lang_choice'] ) ) {
@@ -1452,7 +1675,7 @@ class MLA_Polylang {
1452
  public static function mla_list_table_custom_bulk_action( $item_content, $bulk_action, $post_id ) {
1453
  global $polylang;
1454
 
1455
- MLA::mla_debug_add( __LINE__ . " MLA_Polylang::mla_list_table_bulk_action_item_request( {$bulk_action}, {$post_id} )", MLA::MLA_DEBUG_CATEGORY_LANGUAGE );
1456
 
1457
  if ( 'pll-translate' == $bulk_action ) {
1458
  $translations = array();
@@ -1506,7 +1729,7 @@ class MLA_Polylang {
1506
  * @return array updated array of actions.
1507
  */
1508
  public static function mla_list_table_get_bulk_actions( $actions ) {
1509
- if ( 'checked' == MLAOptions::mla_get_option( 'bulk_translate', false, false, MLA_Polylang::$mla_language_option_definitions ) ) {
1510
  $actions['pll-translate'] = __( 'Translate', 'media-library-assistant' );
1511
  }
1512
  return $actions;
@@ -1677,12 +1900,12 @@ class MLA_Polylang {
1677
  /*
1678
  * Build language management columns
1679
  */
1680
- $show_language = 'checked' == MLAOptions::mla_get_option( 'language_column', false, false, MLA_Polylang::$mla_language_option_definitions );
1681
 
1682
  $languages = count( $polylang->model->get_languages_list() );
1683
  $view_status = isset( $_REQUEST['status'] ) ? $_REQUEST['status'] : '';
1684
  if ( 1 < $languages && $view_status != 'trash' ) {
1685
- $show_translations = 'checked' == MLAOptions::mla_get_option( 'translations_column', false, false, MLA_Polylang::$mla_language_option_definitions );
1686
  } else {
1687
  $show_translations = false;
1688
  }
@@ -1761,7 +1984,7 @@ class MLA_Polylang {
1761
  // don't add the column for the filtered language
1762
  if ( empty($current_language) || $language->slug != $current_language->slug ) {
1763
  // Polylang post_column() function applies this test for 'inline-save' before updating "language"
1764
- $inline = defined('DOING_AJAX') && isset($_POST['inline_lang_choice']) && in_array( $_REQUEST['action'], array( MLA_Polylang::MLA_PLL_QUICK_TRANSLATE, MLA::JAVASCRIPT_INLINE_EDIT_SLUG ) );
1765
 
1766
  if ( $inline ) {
1767
  $save_action = $_REQUEST['action'];
@@ -1885,7 +2108,7 @@ class MLA_Polylang {
1885
  * @return array updated "Rollover" actions.
1886
  */
1887
  public static function mla_list_table_build_rollover_actions( $actions, $item, $column ) {
1888
- if ( 'checked' == MLAOptions::mla_get_option( 'quick_translate', false, false, MLA_Polylang::$mla_language_option_definitions ) ) {
1889
  /*
1890
  * Add the Quick Translate action
1891
  */
@@ -2063,6 +2286,13 @@ class MLA_Polylang {
2063
  'type' => 'checkbox',
2064
  'std' => 'checked',
2065
  'help' => __( 'Check this option to synchronize common terms among all item translations.'), 'media-library-assistant' ),
 
 
 
 
 
 
 
2066
  );
2067
  }
2068
 
@@ -2084,10 +2314,10 @@ class MLA_Polylang {
2084
  * Initialize page messages and content.
2085
  */
2086
  if ( !empty( $_REQUEST['mla-language-options-save'] ) ) {
2087
- check_admin_referer( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
2088
  $page_content = MLA_Polylang::_save_language_settings( );
2089
  } elseif ( !empty( $_REQUEST['mla-language-options-reset'] ) ) {
2090
- check_admin_referer( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
2091
  $page_content = MLA_Polylang::_reset_language_settings( );
2092
  } else {
2093
  $page_content = array(
@@ -2106,10 +2336,11 @@ class MLA_Polylang {
2106
  'In this tab' => sprintf( __( 'In this tab you can find a number of options for controlling Polylang-specific operations. Scroll down to find options for %1$s and %2$s. Be sure to click "Save Changes" at the bottom of the tab to save any changes you make.', 'media-library-assistant' ), '<strong>' . __( 'Media/Assistant submenu table', 'media-library-assistant' ) . '</strong>', '<strong>' . __( 'Term Management', 'media-library-assistant' ) . '</strong>' ),
2107
  /* translators: 1: Documentation hyperlink */
2108
  'You can find' => sprintf( __( 'You can find more information about multilingual features in the %1$s section of the Documentation.', 'media-library-assistant' ), '<a href="[+settingsURL+]?page=mla-settings-menu-documentation&amp;mla_tab=documentation#mla_language_tab" title="' . __( 'Language Options documentation', 'media-library-assistant' ) . '">' . __( 'WPML &amp; Polylang Multilingual Support; the MLA Language Tab', 'media-library-assistant' ) . '</a>' ),
 
2109
  'settingsURL' => admin_url('options-general.php'),
2110
  'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
2111
  'Delete Language options' => __( 'Delete Language options and restore default settings', 'media-library-assistant' ),
2112
- '_wpnonce' => wp_nonce_field( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME, true, false ),
2113
  '_wp_http_referer' => wp_referer_field( false ),
2114
  'Go to Top' => __( 'Go to Top', 'media-library-assistant' ),
2115
  'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-language&mla_tab=language',
@@ -2177,7 +2408,7 @@ class MLA_Polylang {
2177
  } elseif ( ('header' == $value['type']) || ('hidden' == $value['type']) ) {
2178
  $message = '';
2179
  } else {
2180
- MLAOptions::mla_delete_option( $key, MLA_Polylang::$mla_language_option_definitions );
2181
  /* translators: 1: option name */
2182
  $message = '<br>' . sprintf( _x( 'delete_option "%1$s"', 'message_list', 'media-library-assistant'), $key );
2183
  }
58
  add_action( 'admin_enqueue_scripts', 'MLA_Polylang::admin_enqueue_scripts', 10, 1 );
59
 
60
  /*
61
+ * Defined in wp-admin/includes/post.php function edit_post
62
  */
63
+ add_filter( 'attachment_fields_to_save', 'MLA_Polylang::attachment_fields_to_save', 10, 2 );
64
 
65
  /*
66
+ * Defined in wp-includes/post.php function wp_insert_post
67
  */
68
+ add_action( 'edit_attachment', 'MLA_Polylang::edit_attachment', 10, 1 );
69
 
70
  /*
71
  * Defined in /media-library-assistant/includes/class-mla-data.php
115
  * Defined in /media-library-assistant/includes/class-mla-settings.php
116
  */
117
  add_filter( 'mla_get_options_tablist', 'MLA_Polylang::mla_get_options_tablist', 10, 3 );
118
+ add_action( 'mla_begin_mapping', 'MLA_Polylang::mla_begin_mapping', 10, 2 );
119
+ add_filter( 'mla_mapping_new_text', 'MLA_Polylang::mla_mapping_new_text', 10, 5 );
120
+ add_action( 'mla_end_mapping', 'MLA_Polylang::mla_end_mapping', 10, 0 );
121
 
122
  /*
123
  * Defined in /polylang/admin/admin-filters-media.php
182
  /*
183
  * Add styles for the language management column
184
  */
185
+ if ( isset( $_REQUEST['page'] ) && ( MLACore::ADMIN_PAGE_SLUG == $_REQUEST['page'] ) ) {
186
  add_action( 'admin_print_styles', 'MLA_Polylang::mla_list_table_add_pll_styles' );
187
  }
188
 
189
+ if ( defined('DOING_AJAX') && DOING_AJAX ) {
190
  add_action( 'wp_ajax_' . 'mla-polylang-quick-translate', 'MLA_Polylang::quick_translate' );
191
  }
192
 
233
  * function translate_media()
234
  */
235
  $post = get_post( $post_id );
236
+ $post->ID = NULL; // will force the creation
237
  $post->post_parent = ( $post->post_parent && $tr_parent = $polylang->model->get_translation( 'post', $post->post_parent, $new_language ) ) ? $tr_parent : 0;
238
  $new_id = wp_insert_attachment( $post );
239
  add_post_meta( $new_id, '_wp_attachment_metadata', get_post_meta( $post_id, '_wp_attachment_metadata', true ) );
240
  add_post_meta( $new_id, '_wp_attached_file', get_post_meta( $post_id, '_wp_attached_file', true ) );
241
 
242
+ if ( 'checked' == MLACore::mla_get_option( 'term_synchronization', false, false, MLA_Polylang::$mla_language_option_definitions ) ) {
243
  self::_build_existing_terms( $post_id );
244
  self::_build_tax_input( $post_id );
245
  $tax_inputs = self::_apply_tax_input( 0, $new_language );
277
  public static function quick_translate() {
278
  global $polylang;
279
 
280
+ check_ajax_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
281
 
282
  if ( empty( $_REQUEST['post_ID'] ) ) {
283
  echo __( 'ERROR: No post ID found', 'media-library-assistant' );
311
  $_REQUEST['_inline_edit'] = wp_create_nonce( 'inlineeditnonce' );
312
  $polylang->filters_post->save_post( $post_id, $post, true );
313
 
314
+ if ( 'checked' == MLACore::mla_get_option( 'term_assignment', false, false, MLA_Polylang::$mla_language_option_definitions ) ) {
315
  // Record new language for Term Assignment and Synchronization
316
  if ( ! empty( $_REQUEST['tax_input'] ) ) {
317
  // Discard the old translation, which is gone
389
  'comma' => _x( ',', 'tag_delimiter', 'media-library-assistant' ),
390
  'useSpinnerClass' => false,
391
  'ajax_action' => MLA_Polylang::MLA_PLL_QUICK_TRANSLATE,
392
+ 'ajax_nonce' => wp_create_nonce( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME )
393
  );
394
 
395
  if ( version_compare( get_bloginfo( 'version' ), '4.2', '>=' ) ) {
421
  global $polylang;
422
  static $already_adding = 0;
423
 
424
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::pll_translate_media( {$duplicated_attachment_id} ) translations = " . var_export( $translations, true ), MLACore::MLA_DEBUG_CATEGORY_LANGUAGE );
425
 
426
  if ( $already_adding == $duplicated_attachment_id ) {
427
  return;
434
  self::$duplicate_attachments [ $duplicated_attachment_id ] = $language_code;
435
 
436
  if ( isset( $_REQUEST['action'] ) && 'translate_media' == $_REQUEST['action'] ) {
437
+ if ( 'checked' == MLACore::mla_get_option( 'term_synchronization', false, false, MLA_Polylang::$mla_language_option_definitions ) ) {
438
  // Clone the existing common terms to the new translation
439
  self::_build_existing_terms( $attachment_id );
440
  self::_build_tax_input( $attachment_id );
452
  } // translate_media
453
  } // pll_translate_media
454
 
455
+ /**
456
+ * Force "All languages" mode for IPTC/EXIF mapping, which uses mla_get_shortcode_attachments
457
+ *
458
+ * @since 2.20
459
+ *
460
+ * @param array Arguments for mla_get_shortcode_attachments
461
+ * @param boolean true to calculate and return ['found_posts'] as an array element
462
+ */
463
+ public static function mla_get_shortcode_attachments_final_terms( $arguments, $return_found_rows ) {
464
+ $arguments['lang'] = 'all';
465
+ //error_log( __LINE__ . ' MLA_Polylang::mla_get_shortcode_attachments_final_terms $arguments = ' . var_export( $arguments, true ), 0 );
466
+ return $arguments;
467
+ }
468
+
469
+ /**
470
+ * Force "All languages" mode for IPTC/EXIF mapping, which uses mla_get_shortcode_attachments
471
+ *
472
+ * @since 2.20
473
+ *
474
+ * @param string what kind of mapping action is starting:
475
+ * single_custom, single_iptc_exif, bulk_custom, bulk_iptc_exif,
476
+ * create_metadata, update_metadata, custom_fields, custom_rule,
477
+ * iptc_exif_standard, iptc_exif_taxonomy, iptc_exif_custom,
478
+ * iptc_exif_custom_rule
479
+ * @param mixed Attachment ID or NULL, depending on scope
480
+ */
481
+ public static function mla_begin_mapping( $source, $post_id = NULL ) {
482
+ //error_log( __LINE__ . " mla_begin_mapping( {$source} ) ", 0 );
483
+ if ( in_array( $source, array( 'create_metadata', 'single_iptc_exif', 'iptc_exif_standard', 'iptc_exif_taxonomy', 'iptc_exif_custom', 'iptc_exif_custom_rule' ) ) ) {
484
+ add_filter( 'mla_get_shortcode_attachments_final_terms', 'MLA_Polylang::mla_get_shortcode_attachments_final_terms', 10, 2 );
485
+ add_filter( 'mla_mapping_rule', 'MLA_Polylang::mla_mapping_rule', 10, 4 );
486
+ }
487
+ } // mla_begin_mapping
488
+
489
+ /**
490
+ * Saves the current mapping rule for term creation
491
+ *
492
+ * @since 2.20
493
+ *
494
+ * @param array mapping rule
495
+ * @param integer post ID to be evaluated
496
+ * @param string category/scope to evaluate against: iptc_exif_standard_mapping, iptc_exif_taxonomy_mapping or iptc_exif_custom_mapping
497
+ * @param array attachment_metadata, default NULL
498
+ */
499
+ public static function mla_mapping_rule( $setting_value, $post_id, $category, $attachment_metadata ) {
500
+ return self::$current_mapping_rule = $setting_value;
501
+ } // mla_mapping_rule
502
+
503
+ /**
504
+ * Current mapping rule for term creation
505
+ *
506
+ * @since 2.20
507
+ *
508
+ * @var array mapping rule
509
+ */
510
+ private static $current_mapping_rule = array();
511
+
512
+ /**
513
+ * Manages the creation of new taxonomy terms from metadata values
514
+ *
515
+ * @since 2.20
516
+ *
517
+ * @param mixed string or array value returned by the rule
518
+ * @param string field name or taxonomy name
519
+ * @param integer post ID to be evaluated
520
+ * @param string category/scope to evaluate against: iptc_exif_standard_mapping, iptc_exif_taxonomy_mapping or iptc_exif_custom_mapping
521
+ * @param array attachment_metadata, default NULL
522
+ *
523
+ * @return array updated rule EXIF/Template value
524
+ */
525
+ public static function mla_mapping_new_text( $new_text, $setting_key, $post_id, $category, $attachment_metadata ) {
526
+ global $polylang;
527
+ static $replicate = NULL, $current_language, $taxonomies, $other_languages, $parent_term;
528
+
529
+ if ( 'iptc_exif_taxonomy_mapping' !== $category ) {
530
+ return $new_text;
531
+ }
532
+
533
+ if ( is_null( $replicate ) ) {
534
+ $replicate = ( 'checked' == MLACore::mla_get_option( 'term_mapping_replication', false, false, MLA_Polylang::$mla_language_option_definitions ) );
535
+ //error_log( __LINE__ . ' MLA_Polylang::mla_mapping_new_text $replicate = ' . var_export( $replicate, true ), 0 );
536
+
537
+ if ( $polylang->curlang ) {
538
+ $current_language = $polylang->curlang->slug;
539
+ } else {
540
+ $current_language = pll_default_language();
541
+ }
542
+ //error_log( __LINE__ . ' MLA_Polylang::mla_mapping_new_text $current_language = ' . var_export( $current_language, true ), 0 );
543
+ $taxonomies = array();
544
+ foreach( $polylang->model->get_translated_taxonomies() as $taxonomy ) {
545
+ if ( MLACore::mla_taxonomy_support($taxonomy, 'support') ) {
546
+ $taxonomies[ $taxonomy ] = $taxonomy;
547
+ }
548
+ }
549
+ //error_log( __LINE__ . ' MLA_Polylang::mla_mapping_new_text $category = ' . var_export( $category, true ), 0 );
550
+ //error_log( __LINE__ . ' MLA_Polylang::mla_mapping_new_text $taxonomies = ' . var_export( $taxonomies, true ), 0 );
551
+
552
+ $other_languages = array();
553
+ foreach( $polylang->model->get_languages_list() as $item_language ) {
554
+ if ( $current_language !== $item_language->slug ) {
555
+ $other_languages[ $item_language->slug ] = $item_language;
556
+ }
557
+ }
558
+ //error_log( __LINE__ . ' MLA_Polylang::mla_mapping_new_text $other_languages = ' . var_export( $other_languages, true ), 0 );
559
+ }
560
+
561
+ if ( ( ! empty( $new_text ) ) && in_array( $setting_key, $taxonomies ) ) {
562
+ //error_log( __LINE__ . ' MLA_Polylang::mla_mapping_new_text mapping rule = ' . var_export( self::$current_mapping_rule, true ), 0 );
563
+ //error_log( __LINE__ . ' MLA_Polylang::mla_mapping_new_text $new_text = ' . var_export( $new_text, true ), 0 );
564
+ //error_log( __LINE__ . ' MLA_Polylang::mla_mapping_new_text $setting_key = ' . var_export( $setting_key, true ), 0 );
565
+ //error_log( __LINE__ . ' MLA_Polylang::mla_mapping_new_text $post_id = ' . var_export( $post_id, true ), 0 );
566
+ //error_log( __LINE__ . ' MLA_Polylang::mla_mapping_new_text $attachment_metadata = ' . var_export( $attachment_metadata, true ), 0 );
567
+ $language_details = $polylang->model->get_post_language( $post_id );
568
+ $item_language = $language_details->slug;
569
+ //error_log( __LINE__ . ' MLA_Polylang::mla_mapping_new_text $language_details = ' . var_export( $language_details, true ), 0 );
570
+
571
+ /*
572
+ * Find the parent term and its translations
573
+ */
574
+ if ( isset( self::$current_mapping_rule['parent'] ) ) {
575
+ if ( $parent_term = absint( self::$current_mapping_rule['parent'] ) ) {
576
+ $parent_term = self::_get_relevant_term( 'id', $parent_term, $setting_key );
577
+ }
578
+ } else {
579
+ $parent_term = 0;
580
+ }
581
+
582
+ //error_log( __LINE__ . ' MLA_Polylang::mla_mapping_new_text $parent_term = ' . var_export( $parent_term, true ), 0 );
583
+
584
+ $new_terms = array();
585
+ foreach( $new_text as $new_name ) {
586
+ $relevant_term = self::_get_relevant_term( 'name', $new_name, $setting_key );
587
+ //error_log( __LINE__ . ' MLA_Polylang::mla_mapping_new_text $relevant_term = ' . var_export( $relevant_term, true ), 0 );
588
+
589
+ if ( $relevant_term ) {
590
+ if ( isset( $relevant_term['translations'][ $item_language ] ) ) {
591
+ $new_terms[] = absint( $relevant_term['translations'][ $item_language ]->element_id );
592
+ }
593
+ } else {
594
+ /*
595
+ * Always create the new term in the current language
596
+ */
597
+ if ( $parent_term && isset( $parent_term['translations'][ $current_language ] ) ) {
598
+ $parent = $parent_term['translations'][ $current_language ]->element_id;
599
+ } else {
600
+ $parent = 0;
601
+ }
602
+ //error_log( __LINE__ . ' MLA_Polylang::mla_mapping_new_text $parent = ' . var_export( $parent, true ), 0 );
603
+
604
+ $res = wp_insert_term( $new_name, $setting_key, array( 'parent' => $parent ) );
605
+ //error_log( __LINE__ . ' MLA_Polylang::mla_mapping_new_text $res = ' . var_export( $res, true ), 0 );
606
+ if ( ( ! is_wp_error( $res ) ) && isset( $res['term_id'] ) ) {
607
+ $polylang->model->set_term_language( $res['term_id'], $current_language );
608
+ }
609
+
610
+ /*
611
+ * Add translations in the other languages?
612
+ */
613
+ if ( $replicate ) {
614
+ $source_term = $res['term_id'];
615
+ $translations = array();
616
+ foreach( $other_languages as $language => $language_details ) {
617
+ if ( $parent_term && isset( $parent_term['translations'][ $language ] ) ) {
618
+ $parent = $parent_term['translations'][ $language ]->element_id;
619
+ } else {
620
+ $parent = 0;
621
+ }
622
+ //error_log( __LINE__ . ' MLA_Polylang::mla_mapping_new_text $parent = ' . var_export( $parent, true ), 0 );
623
+
624
+ // save_language() does a check_admin_referer() security test
625
+ $_REQUEST['_pll_nonce'] = wp_create_nonce( 'pll_language' );
626
+ $_POST['term_lang_choice'] = $language;
627
+ $_POST['action'] = 'mla';
628
+ $res = wp_insert_term( $new_name, $setting_key, array( 'parent' => $parent ) );
629
+ //error_log( __LINE__ . ' MLA_Polylang::mla_mapping_new_text $res = ' . var_export( $res, true ), 0 );
630
+ if ( ( ! is_wp_error( $res ) ) && isset( $res['term_id'] ) ) {
631
+ $polylang->model->set_term_language( $res['term_id'], $language );
632
+ $translations[ $language ] = $res['term_id'];
633
+ }
634
+ }
635
+
636
+ unset( $_POST['term_lang_choice'] );
637
+ unset( $_POST['action'] );
638
+
639
+ if ( ! empty( $translations ) ) {
640
+ $polylang->model->save_translations( 'term', $source_term, $translations);
641
+ }
642
+ } // replicate
643
+
644
+ /*
645
+ * Reload the term with all of its new translations
646
+ */
647
+ $relevant_term = self::_get_relevant_term( 'name', $new_name, $setting_key );
648
+ //error_log( __LINE__ . ' MLA_Polylang::mla_mapping_new_text $relevant_term = ' . var_export( $relevant_term, true ), 0 );
649
+ if ( isset( $relevant_term['translations'][ $item_language ] ) ) {
650
+ $new_terms[] = absint( $relevant_term['translations'][ $item_language ]->element_id );
651
+ }
652
+ } // new term
653
+ } // foreach new_name
654
+
655
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::mla_mapping_new_text( {$setting_key}, {$post_id} ) \$new_terms = " . var_export( $new_terms, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
656
+ return $new_terms;
657
+ } // translated taxonomy
658
+
659
+ return $new_text;
660
+ } // mla_mapping_new_text
661
+
662
+ /**
663
+ * Remove "All languages" filter
664
+ *
665
+ * @since 2.20
666
+ *
667
+ * @return void
668
+ */
669
+ public static function mla_end_mapping() {
670
+ remove_filter( 'mla_get_shortcode_attachments_final_terms', 'MLA_Polylang::mla_get_shortcode_attachments_final_terms' );
671
+ } // mla_end_mapping
672
+
673
  /**
674
  * Taxonomy terms and translations
675
  *
836
  }
837
 
838
  $language_details = $polylang->model->get_post_language( $post_id );
839
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::_build_existing_terms( {$post_id} ) \$polylang->model->get_post_language = " . var_export( $language_details, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
840
 
841
  if ( is_object( $language_details ) ) {
842
  $language_details = (array) $language_details;
843
  } else {
844
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::_build_existing_terms( {$post_id} ) pll_default_language() = " . var_export( pll_default_language(), true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
845
  $language_details = (array) $polylang->model->get_language( pll_default_language() );
846
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::_build_existing_terms( {$post_id} ) \$polylang->model->get_language( pll_default_language() ) = " . var_export( $language_details, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
847
  }
848
 
849
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::_build_existing_terms( {$post_id} ) \$polylang->model->get_translations() = " . var_export( $polylang->model->get_translations( 'post', $post_id ), true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
850
  $translations = array();
851
  foreach ( $polylang->model->get_translations( 'post', $post_id ) as $language_code => $translation ) {
852
  $translations[ $language_code ] = array( 'element_id' => $translation );
889
  } // translation
890
  } // term
891
 
892
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::_build_existing_terms( {$post_id} ) self::\$existing_terms = " . var_export( self::$existing_terms, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
893
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::_build_existing_terms( {$post_id} ) self::\$relevant_terms = " . var_export( self::$relevant_terms, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
894
  return;
895
  }
896
 
911
  */
912
  private static function _update_existing_terms( $post_id ) {
913
  global $polylang;
914
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::_update_existing_terms( {$post_id} ) initial self::\$existing_terms = " . var_export( self::$existing_terms, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
915
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::_update_existing_terms( {$post_id} ) initial self::\$relevant_terms = " . var_export( self::$relevant_terms, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
916
 
917
  if ( $post_id != self::$existing_terms['element_id'] ) {
918
  return false;
959
  } // translation
960
  } // term
961
 
962
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::_update_existing_terms( {$post_id} ) final self::\$existing_terms = " . var_export( self::$existing_terms, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
963
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::_update_existing_terms( {$post_id} ) final self::\$relevant_terms = " . var_export( self::$relevant_terms, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
964
  return $terms_before;
965
  }
966
 
1011
  $terms = isset( $translation[ $taxonomy_name ] ) ? $translation[ $taxonomy_name ] : array();
1012
  if ( ! empty( $terms ) ) {
1013
  $no_terms = false;
 
1014
  $input_terms = array();
1015
  foreach ( $terms as $term ) {
1016
  $input_terms[] = $term->term_id;
1102
 
1103
  } // foreach taxonomy
1104
 
1105
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::_build_tax_input( {$post_id} ) self::\$tax_input = " . var_export( self::$tax_input, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1106
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::_build_tax_input( {$post_id} ) self::\$relevant_terms = " . var_export( self::$relevant_terms, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1107
  } // _build_tax_input
1108
 
1109
  /**
1130
  }
1131
  }
1132
 
1133
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::_apply_tax_input( {$post_id} ) \$post_language = " . var_export( $post_language, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1134
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::_apply_tax_input( {$post_id} ) self::\$tax_input[ \$post_language ] = " . var_export( self::$tax_input[ $post_language ], true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1135
  return self::$tax_input[ $post_language ];
1136
  } // _apply_tax_input
1137
 
1183
  foreach( self::$existing_terms[ $language ][ $taxonomy ] as $ttid => $term ) {
1184
  $source_term = self::_get_relevant_term( 'term_taxonomy_id', $ttid, $taxonomy );
1185
  if ( isset( $source_term['translations'][ $source_language ] ) ) {
1186
+ $dest_term = self::_get_relevant_term( 'id', $source_term['translations'][ $source_language ]->element_id, $taxonomy );
1187
  $old_terms[ $taxonomy ][ $dest_term['term']->term_taxonomy_id ] = $dest_term['term'];
1188
  }
1189
  }
1255
  } // synch_inputs
1256
 
1257
  $post_id = self::$existing_terms[ $language ]['element_id'];
1258
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::_apply_synch_input( {$post_id} ) \$language = " . var_export( $language, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1259
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::_apply_synch_input( {$post_id} ) \$tax_inputs = " . var_export( $tax_inputs, true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1260
  return $tax_inputs;
1261
  } // _apply_synch_input
1262
 
1271
  * @return array $tax_inputs for Term Synchronization
1272
  */
1273
  private static function _apply_term_synchronization( $post_id ) {
1274
+ if ( 'checked' == MLACore::mla_get_option( 'term_synchronization', false, false, MLA_Polylang::$mla_language_option_definitions ) ) {
1275
 
1276
  /*
1277
  * Update terms because they have changed
1305
  * @param integer $result Zero if the update failed else ID of the item that was updated.
1306
  */
1307
  public static function mla_updated_single_item( $post_id, $result ) {
1308
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::mla_updated_single_item( {$post_id}, {$result} )", MLACore::MLA_DEBUG_CATEGORY_LANGUAGE );
1309
 
1310
  if ( self::$existing_terms['element_id'] == $post_id ) {
1311
  /*
1324
  * @param array $attachment An array of attachment metadata.
1325
  */
1326
  public static function attachment_fields_to_save( $post, $attachment ) {
1327
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::attachment_fields_to_save post = " . var_export( $post, true ), MLACore::MLA_DEBUG_CATEGORY_LANGUAGE );
1328
 
1329
  if ( 'editpost' == $post['action'] && 'attachment' == $post['post_type'] ) {
1330
  self::_build_existing_terms( $post['post_ID'] );
1344
  public static function edit_attachment( $post_id ) {
1345
  static $already_updating = 0;
1346
 
1347
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::edit_attachment( {$post_id} ) _REQUEST = " . var_export( $_REQUEST, true ), MLACore::MLA_DEBUG_CATEGORY_LANGUAGE );
1348
 
1349
  /*
1350
  * mla_update_single_item may call this action again
1361
  if ( ! empty( $_REQUEST['mlaAddNewBulkEditFormString'] ) ) {
1362
  if ( ! empty( self::$bulk_edit_request['tax_input'] ) ) {
1363
  $tax_inputs = self::$bulk_edit_request['tax_input'];
1364
+ if ( 'checked' == MLACore::mla_get_option( 'term_assignment', false, false, MLA_Polylang::$mla_language_option_definitions ) ) {
1365
  self::_build_tax_input( $post_id, $tax_inputs, self::$bulk_edit_request['tax_action'] );
1366
  $tax_inputs = self::_apply_tax_input( $post_id );
1367
  }
1403
  $tax_actions = NULL;
1404
  }
1405
 
1406
+ if ( ( ! empty( $tax_inputs ) ) && ( 'checked' == MLACore::mla_get_option( 'term_assignment', false, false, MLA_Polylang::$mla_language_option_definitions ) ) ) {
1407
  self::_build_tax_input( $post_id, $tax_inputs, $tax_actions );
1408
  $tax_inputs = self::_apply_tax_input( $post_id );
1409
  }
1425
  public static function mla_media_modal_begin_update_compat_fields( $post ) {
1426
  $post_id = $post->ID;
1427
 
1428
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::mla_media_modal_begin_update_compat_fields( {$post_id} ) post = " . var_export( $post, true ), MLACore::MLA_DEBUG_CATEGORY_LANGUAGE );
1429
 
1430
  // Accumulate for possible term_assignment or term_synchronization
1431
  self::_build_existing_terms( $post_id );
1443
  * @param integer current post ID
1444
  */
1445
  public static function mla_media_modal_update_compat_fields_terms( $terms, $key, $value, $post_id ) {
1446
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::mla_media_modal_update_compat_fields_terms( {$key}, {$post_id} ) terms = " . var_export( $terms, true ), MLACore::MLA_DEBUG_CATEGORY_LANGUAGE );
1447
 
1448
+ if ( 'checked' == MLACore::mla_get_option( 'term_assignment', false, false, MLA_Polylang::$mla_language_option_definitions ) ) {
1449
+ if ( $value->hierarchical ) {
1450
+ $tax_inputs = array( $key => $terms );
1451
+ } else {
1452
+ $tax_inputs = array( $key => implode( ',', $terms ) );
1453
+ }
1454
 
 
1455
  self::_build_tax_input( $post_id, $tax_inputs );
1456
  $tax_inputs = self::_apply_tax_input( $post_id );
1457
  $terms = $tax_inputs[ $key ];
1471
  * @param object current post object
1472
  */
1473
  public static function mla_media_modal_end_update_compat_fields( $results, $taxonomies, $post ) {
1474
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::mla_media_modal_end_update_compat_fields( {$post->ID} ) taxonomies = " . var_export( $taxonomies, true ), MLACore::MLA_DEBUG_CATEGORY_LANGUAGE );
1475
 
1476
  /*
1477
  * Synchronize the changes to all other translations
1497
  public static function mla_list_table_inline_action( $item_content, $post_id ) {
1498
  global $polylang;
1499
 
1500
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::mla_list_table_inline_action( {$post_id} )", MLACore::MLA_DEBUG_CATEGORY_LANGUAGE );
1501
 
1502
  self::_build_existing_terms( $post_id );
1503
  if ( isset( $_REQUEST['action'] ) && 'mla-inline-edit-scripts' === $_REQUEST['action'] && isset( $_REQUEST['tax_input'] ) ) {
1504
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::mla_list_table_inline_action( {$post_id} ) Quick Edit initial \$_REQUEST['tax_input'] = " . var_export( $_REQUEST['tax_input'], true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1505
+
1506
+ if ( 'checked' == MLACore::mla_get_option( 'term_assignment', false, false, MLA_Polylang::$mla_language_option_definitions ) ) {
1507
+ // Quick Edit calls update_single_item right after this filter
1508
+ self::_build_tax_input( $post_id, $_REQUEST['tax_input'] );
1509
+ $_REQUEST['tax_input'] = self::_apply_tax_input( $post_id );
1510
+ }
1511
+
1512
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::mla_list_table_inline_action( {$post_id} ) Quick Edit final \$_REQUEST['tax_input'] = " . var_export( $_REQUEST['tax_input'], true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1513
  }
1514
 
1515
  // Language dropdown in Quick Edit area
1523
  $polylang->filters_post->save_post( $post_id, $post, true );
1524
 
1525
  // Record new language for Term Assignment and Synchronization
1526
+ if ( ( ! empty( $_REQUEST['tax_input'] ) ) && ( 'checked' == MLACore::mla_get_option( 'term_assignment', false, false, MLA_Polylang::$mla_language_option_definitions ) ) ) {
1527
  // Discard the old translation, which is gone
1528
  unset( self::$existing_terms[ self::$existing_terms['slug'] ] );
1529
  self::$existing_terms['slug'] = $_REQUEST['inline_lang_choice'];
1546
  * @return array updated bulk action request parameters
1547
  */
1548
  public static function mla_list_table_bulk_action_initial_request( $request, $bulk_action, $custom_field_map ) {
1549
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::mla_list_table_bulk_action_initial_request( {$bulk_action} ) request = " . var_export( $request, true ), MLACore::MLA_DEBUG_CATEGORY_LANGUAGE );
1550
 
1551
  self::$bulk_edit_request = $request;
1552
  self::$bulk_edit_map = $custom_field_map;
1585
  * @return array updated bulk action request parameters
1586
  */
1587
  public static function mla_list_table_bulk_action_item_request( $request, $bulk_action, $post_id, $custom_field_map ) {
1588
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::mla_list_table_bulk_action_item_request( {$post_id} ) request = " . var_export( $request, true ), MLACore::MLA_DEBUG_CATEGORY_LANGUAGE );
1589
 
1590
  /*
1591
  * Note that $request may be modified by previous items, so we must return to the initial vlues
1592
  */
1593
+ 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 ) ) ) {
1594
  self::_build_existing_terms( $post_id );
1595
  self::_build_tax_input( $post_id, self::$bulk_edit_request['tax_input'], $request['tax_action'] );
1596
  $request['tax_input'] = self::_apply_tax_input( $post_id );
1603
  }
1604
 
1605
  if ( isset( $request['tax_input'] ) ) {
1606
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::bulk_action_item_request( {$bulk_action}, {$post_id} ) \$request['tax_input'] = " . var_export( $request['tax_input'], true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1607
  } else {
1608
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::bulk_action_item_request( {$bulk_action}, {$post_id} ) \$request['tax_input'] NOT SET", MLACore::MLA_DEBUG_CATEGORY_AJAX );
1609
  }
1610
 
1611
  if ( isset( $request['tax_action'] ) ) {
1612
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::bulk_action_item_request( {$bulk_action}, {$post_id} ) \$request['tax_action'] = " . var_export( $request['tax_action'], true ), MLACore::MLA_DEBUG_CATEGORY_AJAX );
1613
  } else {
1614
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::bulk_action_item_request( {$bulk_action}, {$post_id} ) \$request['tax_action'] NOT SET", MLACore::MLA_DEBUG_CATEGORY_AJAX );
1615
  }
1616
 
1617
  return $request;
1633
  public static function mla_list_table_bulk_action( $item_content, $bulk_action, $post_id ) {
1634
  global $polylang;
1635
 
1636
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::mla_list_table_bulk_action( {$bulk_action}, {$post_id} )", MLACore::MLA_DEBUG_CATEGORY_LANGUAGE );
1637
 
1638
  // Language dropdown in Bulk Edit area
1639
  if ( isset( $_POST['inline_lang_choice'] ) && ( '-1' != $_POST['inline_lang_choice'] ) ) {
1675
  public static function mla_list_table_custom_bulk_action( $item_content, $bulk_action, $post_id ) {
1676
  global $polylang;
1677
 
1678
+ MLACore::mla_debug_add( __LINE__ . " MLA_Polylang::mla_list_table_bulk_action_item_request( {$bulk_action}, {$post_id} )", MLACore::MLA_DEBUG_CATEGORY_LANGUAGE );
1679
 
1680
  if ( 'pll-translate' == $bulk_action ) {
1681
  $translations = array();
1729
  * @return array updated array of actions.
1730
  */
1731
  public static function mla_list_table_get_bulk_actions( $actions ) {
1732
+ if ( 'checked' == MLACore::mla_get_option( 'bulk_translate', false, false, MLA_Polylang::$mla_language_option_definitions ) ) {
1733
  $actions['pll-translate'] = __( 'Translate', 'media-library-assistant' );
1734
  }
1735
  return $actions;
1900
  /*
1901
  * Build language management columns
1902
  */
1903
+ $show_language = 'checked' == MLACore::mla_get_option( 'language_column', false, false, MLA_Polylang::$mla_language_option_definitions );
1904
 
1905
  $languages = count( $polylang->model->get_languages_list() );
1906
  $view_status = isset( $_REQUEST['status'] ) ? $_REQUEST['status'] : '';
1907
  if ( 1 < $languages && $view_status != 'trash' ) {
1908
+ $show_translations = 'checked' == MLACore::mla_get_option( 'translations_column', false, false, MLA_Polylang::$mla_language_option_definitions );
1909
  } else {
1910
  $show_translations = false;
1911
  }
1984
  // don't add the column for the filtered language
1985
  if ( empty($current_language) || $language->slug != $current_language->slug ) {
1986
  // Polylang post_column() function applies this test for 'inline-save' before updating "language"
1987
+ $inline = defined('DOING_AJAX') && isset($_POST['inline_lang_choice']) && in_array( $_REQUEST['action'], array( MLA_Polylang::MLA_PLL_QUICK_TRANSLATE, MLACore::JAVASCRIPT_INLINE_EDIT_SLUG ) );
1988
 
1989
  if ( $inline ) {
1990
  $save_action = $_REQUEST['action'];
2108
  * @return array updated "Rollover" actions.
2109
  */
2110
  public static function mla_list_table_build_rollover_actions( $actions, $item, $column ) {
2111
+ if ( 'checked' == MLACore::mla_get_option( 'quick_translate', false, false, MLA_Polylang::$mla_language_option_definitions ) ) {
2112
  /*
2113
  * Add the Quick Translate action
2114
  */
2286
  'type' => 'checkbox',
2287
  'std' => 'checked',
2288
  'help' => __( 'Check this option to synchronize common terms among all item translations.'), 'media-library-assistant' ),
2289
+
2290
+ 'term_mapping_replication' =>
2291
+ array('tab' => 'language',
2292
+ 'name' => __( 'Term Mapping Replication', 'media-library-assistant' ),
2293
+ 'type' => 'checkbox',
2294
+ 'std' => 'checked',
2295
+ 'help' => __( 'When mapping IPTC/EXIF metadata to taxonomy terms, make them available in all languages.'), 'media-library-assistant' ),
2296
  );
2297
  }
2298
 
2314
  * Initialize page messages and content.
2315
  */
2316
  if ( !empty( $_REQUEST['mla-language-options-save'] ) ) {
2317
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
2318
  $page_content = MLA_Polylang::_save_language_settings( );
2319
  } elseif ( !empty( $_REQUEST['mla-language-options-reset'] ) ) {
2320
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
2321
  $page_content = MLA_Polylang::_reset_language_settings( );
2322
  } else {
2323
  $page_content = array(
2336
  'In this tab' => sprintf( __( 'In this tab you can find a number of options for controlling Polylang-specific operations. Scroll down to find options for %1$s and %2$s. Be sure to click "Save Changes" at the bottom of the tab to save any changes you make.', 'media-library-assistant' ), '<strong>' . __( 'Media/Assistant submenu table', 'media-library-assistant' ) . '</strong>', '<strong>' . __( 'Term Management', 'media-library-assistant' ) . '</strong>' ),
2337
  /* translators: 1: Documentation hyperlink */
2338
  'You can find' => sprintf( __( 'You can find more information about multilingual features in the %1$s section of the Documentation.', 'media-library-assistant' ), '<a href="[+settingsURL+]?page=mla-settings-menu-documentation&amp;mla_tab=documentation#mla_language_tab" title="' . __( 'Language Options documentation', 'media-library-assistant' ) . '">' . __( 'WPML &amp; Polylang Multilingual Support; the MLA Language Tab', 'media-library-assistant' ) . '</a>' ),
2339
+ 'WPML Status' => '',
2340
  'settingsURL' => admin_url('options-general.php'),
2341
  'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
2342
  'Delete Language options' => __( 'Delete Language options and restore default settings', 'media-library-assistant' ),
2343
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
2344
  '_wp_http_referer' => wp_referer_field( false ),
2345
  'Go to Top' => __( 'Go to Top', 'media-library-assistant' ),
2346
  'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-language&mla_tab=language',
2408
  } elseif ( ('header' == $value['type']) || ('hidden' == $value['type']) ) {
2409
  $message = '';
2410
  } else {
2411
+ MLACore::mla_delete_option( $key, MLA_Polylang::$mla_language_option_definitions );
2412
  /* translators: 1: option name */
2413
  $message = '<br>' . sprintf( _x( 'delete_option "%1$s"', 'message_list', 'media-library-assistant'), $key );
2414
  }
includes/class-mla-settings.php CHANGED
@@ -76,15 +76,6 @@ class MLASettings {
76
  */
77
  const JAVASCRIPT_INLINE_MAPPING_OBJECT = 'mla_inline_mapping_vars';
78
 
79
- /**
80
- * Provides a unique name for the settings page
81
- *
82
- * @since 0.1
83
- *
84
- * @var string
85
- */
86
- const MLA_SETTINGS_SLUG = 'mla-settings-menu';
87
-
88
  /**
89
  * Holds screen id to match help text to corresponding screen
90
  *
@@ -119,17 +110,17 @@ class MLASettings {
119
  * @return void
120
  */
121
  private static function _version_upgrade( ) {
122
- $current_version = MLAOptions::mla_get_option( MLAOptions::MLA_VERSION_OPTION );
123
 
124
  if ( version_compare( '.30', $current_version, '>' ) ) {
125
  /*
126
  * Convert attachment_category and _tag to taxonomy_support;
127
  * change the default if either option is unchecked
128
  */
129
- $category_option = MLAOptions::mla_get_option( 'attachment_category' );
130
- $tag_option = MLAOptions::mla_get_option( 'attachment_tag' );
131
  if ( ! ( ( 'checked' == $category_option ) && ( 'checked' == $tag_option ) ) ) {
132
- $tax_option = MLAOptions::mla_get_option( MLAOptions::MLA_TAXONOMY_SUPPORT );
133
  if ( 'checked' != $category_option ) {
134
  if ( isset( $tax_option['tax_support']['attachment_category'] ) ) {
135
  unset( $tax_option['tax_support']['attachment_category'] );
@@ -142,11 +133,11 @@ class MLASettings {
142
  }
143
  }
144
 
145
- MLAOptions::mla_taxonomy_option_handler( 'update', 'taxonomy_support', MLAOptions::$mla_option_definitions['taxonomy_support'], $tax_option );
146
  } // one or both options unchecked
147
 
148
- MLAOptions::mla_delete_option( 'attachment_category' );
149
- MLAOptions::mla_delete_option( 'attachment_tag' );
150
  } // version is less than .30
151
 
152
  if ( version_compare( '1.13', $current_version, '>' ) ) {
@@ -155,13 +146,13 @@ class MLASettings {
155
  */
156
  $new_values = array();
157
 
158
- foreach ( MLAOptions::mla_get_option( 'custom_field_mapping' ) as $key => $value ) {
159
  $value['quick_edit'] = ( isset( $value['quick_edit'] ) && $value['quick_edit'] ) ? true : false;
160
  $value['bulk_edit'] = ( isset( $value['bulk_edit'] ) && $value['bulk_edit'] ) ? true : false;
161
  $new_values[ $key ] = $value;
162
  }
163
 
164
- MLAOptions::mla_update_option( 'custom_field_mapping', $new_values );
165
  } // version is less than 1.13
166
 
167
  if ( version_compare( '1.30', $current_version, '>' ) ) {
@@ -170,14 +161,14 @@ class MLASettings {
170
  */
171
  $new_values = array();
172
 
173
- foreach ( MLAOptions::mla_get_option( 'custom_field_mapping' ) as $key => $value ) {
174
  $value['meta_name'] = isset( $value['meta_name'] ) ? $value['meta_name'] : '';
175
  $value['meta_single'] = ( isset( $value['meta_single'] ) && $value['meta_single'] ) ? true : false;
176
  $value['meta_export'] = ( isset( $value['meta_export'] ) && $value['meta_export'] ) ? true : false;
177
  $new_values[ $key ] = $value;
178
  }
179
 
180
- MLAOptions::mla_update_option( 'custom_field_mapping', $new_values );
181
  } // version is less than 1.30
182
 
183
  if ( version_compare( '1.40', $current_version, '>' ) ) {
@@ -186,7 +177,7 @@ class MLASettings {
186
  */
187
  $new_values = array();
188
 
189
- foreach ( MLAOptions::mla_get_option( 'custom_field_mapping' ) as $key => $value ) {
190
  $value['no_null'] = ( isset( $value['no_null'] ) && $value['no_null'] ) ? true : false;
191
 
192
  if ( isset( $value['meta_single'] ) && $value['meta_single'] ) {
@@ -203,14 +194,14 @@ class MLASettings {
203
  $new_values[ $key ] = $value;
204
  }
205
 
206
- MLAOptions::mla_update_option( 'custom_field_mapping', $new_values );
207
  } // version is less than 1.40
208
 
209
  if ( version_compare( '1.60', $current_version, '>' ) ) {
210
  /*
211
  * Add delimiters values to taxonomy mapping rules
212
  */
213
- $option_value = MLAOptions::mla_get_option( 'iptc_exif_mapping' );
214
  $new_values = array();
215
 
216
  foreach ( $option_value['taxonomy'] as $key => $value ) {
@@ -219,7 +210,7 @@ class MLASettings {
219
  }
220
 
221
  $option_value['taxonomy'] = $new_values;
222
- MLAOptions::mla_update_option( 'iptc_exif_mapping', $option_value );
223
  } // version is less than 1.60
224
 
225
  if ( version_compare( '1.72', $current_version, '>' ) ) {
@@ -233,7 +224,7 @@ class MLASettings {
233
  /*
234
  * Add format, option and no_null to IPTC/EXIF custom mapping rules
235
  */
236
- $option_value = MLAOptions::mla_get_option( 'iptc_exif_mapping' );
237
  $new_values = array();
238
 
239
  foreach ( $option_value['custom'] as $key => $value ) {
@@ -244,43 +235,30 @@ class MLASettings {
244
  }
245
 
246
  $option_value['custom'] = $new_values;
247
- MLAOptions::mla_update_option( 'iptc_exif_mapping', $option_value );
248
  } // version is less than 2.13
249
 
250
- MLAOptions::mla_update_option( MLAOptions::MLA_VERSION_OPTION, MLA::CURRENT_MLA_VERSION );
251
  }
252
 
253
  /**
254
  * Perform one-time actions on plugin activation
255
  *
256
- * Adds a view to the database to support sorting the listing on 'ALT Text'.
257
- *
258
  * @since 0.40
259
  *
260
  * @return void
261
  */
262
  public static function mla_activation_hook( ) {
263
- // self::_create_alt_text_view(); DELETED v1.10, NO LONGER REQUIRED
264
  }
265
 
266
  /**
267
  * Perform one-time actions on plugin deactivation
268
  *
269
- * Removes (if present) a view from the database that supports sorting the listing on 'ALT Text'.
270
- *
271
  * @since 0.40
272
  *
273
  * @return void
274
  */
275
  public static function mla_deactivation_hook( ) {
276
- global $wpdb, $table_prefix;
277
-
278
- $view_name = $table_prefix . MLA_OPTION_PREFIX . MLAData::MLA_ALT_TEXT_VIEW_SUFFIX;
279
- $result = $wpdb->query( "SHOW TABLES LIKE '{$view_name}'" );
280
-
281
- if ( $result) {
282
- $result = $wpdb->query( "DROP VIEW {$view_name}" );
283
- }
284
  }
285
 
286
  /**
@@ -358,12 +336,12 @@ class MLASettings {
358
  * Initialize common script variables
359
  */
360
  $script_variables = array(
361
- 'error' => __( 'Error while saving 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( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME )
367
  );
368
 
369
  if ( version_compare( get_bloginfo( 'version' ), '4.2', '>=' ) ) {
@@ -371,10 +349,7 @@ class MLASettings {
371
  }
372
 
373
  $mapping_variables = array(
374
- 'page' => 'mla-settings-menu-custom_field',
375
- 'mla_tab' => 'custom_field',
376
- 'screen' => 'settings_page_mla-settings-menu-custom_field',
377
- 'bulkChunkSize' => MLAOptions::mla_get_option( MLAOptions::MLA_BULK_CHUNK_SIZE ),
378
  'bulkWaiting' => __( 'Waiting', 'media-library-assistant' ),
379
  'bulkRunning' => __( 'Running', 'media-library-assistant' ),
380
  'bulkComplete' => __( 'Complete', 'media-library-assistant' ),
@@ -422,10 +397,16 @@ class MLASettings {
422
  MLA_PLUGIN_URL . "js/mla-inline-mapping-scripts{$suffix}.js",
423
  array( 'jquery' ), MLA::CURRENT_MLA_VERSION, false );
424
 
425
- $script_variables = array_merge( $script_variables, $mapping_variables );
426
- $script_variables['ajax_action'] = self::JAVASCRIPT_INLINE_MAPPING_CUSTOM_SLUG;
427
- $script_variables['fieldsId'] = '#mla-display-settings-custom-field-tab';
428
- $script_variables['totalItems'] = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE `post_type` = 'attachment'" );
 
 
 
 
 
 
429
 
430
  wp_localize_script( self::JAVASCRIPT_INLINE_MAPPING_CUSTOM_SLUG,
431
  self::JAVASCRIPT_INLINE_MAPPING_OBJECT, $script_variables );
@@ -435,10 +416,16 @@ class MLASettings {
435
  MLA_PLUGIN_URL . "js/mla-inline-mapping-scripts{$suffix}.js",
436
  array( 'jquery' ), MLA::CURRENT_MLA_VERSION, false );
437
 
438
- $script_variables = array_merge( $script_variables, $mapping_variables );
439
- $script_variables['ajax_action'] = self::JAVASCRIPT_INLINE_MAPPING_IPTC_EXIF_SLUG;
440
- $script_variables['fieldsId'] = '#mla-display-settings-iptc-exif-tab';
441
- $script_variables['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%' )" );
 
 
 
 
 
 
442
 
443
  wp_localize_script( self::JAVASCRIPT_INLINE_MAPPING_IPTC_EXIF_SLUG,
444
  self::JAVASCRIPT_INLINE_MAPPING_OBJECT, $script_variables );
@@ -468,7 +455,7 @@ class MLASettings {
468
  }
469
 
470
  $tab = self::mla_get_options_tablist( $tab ) ? '-' . $tab : '-general';
471
- 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', self::MLA_SETTINGS_SLUG . $tab, 'MLASettings::mla_render_settings_page' );
472
  add_action( 'load-' . self::$current_page_hook, 'MLASettings::mla_add_menu_options_action' );
473
  add_action( 'load-' . self::$current_page_hook, 'MLASettings::mla_add_help_tab_action' );
474
  add_filter( 'plugin_action_links', 'MLASettings::mla_add_plugin_settings_link_filter', 10, 2 );
@@ -532,7 +519,7 @@ class MLASettings {
532
  /*
533
  * Is this our page and the Views or Uploads tab?
534
  */
535
- if ( ! in_array( $screen->id, array( 'settings_page_' . self::MLA_SETTINGS_SLUG . '-view', 'settings_page_' . self::MLA_SETTINGS_SLUG . '-upload' ) ) ) {
536
  return;
537
  }
538
 
@@ -642,7 +629,7 @@ class MLASettings {
642
  public static function mla_inline_edit_view_action() {
643
  set_current_screen( $_REQUEST['screen'] );
644
 
645
- check_ajax_referer( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
646
 
647
  if ( empty( $_REQUEST['original_slug'] ) ) {
648
  echo __( 'ERROR', 'media-library-assistant' ) . ': ' . __( 'No view slug found', 'media-library-assistant' );
@@ -685,7 +672,7 @@ class MLASettings {
685
  public static function mla_inline_edit_upload_action() {
686
  set_current_screen( $_REQUEST['screen'] );
687
 
688
- check_ajax_referer( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
689
 
690
  if ( empty( $_REQUEST['original_slug'] ) ) {
691
  echo __( 'ERROR', 'media-library-assistant' ) . ': ' . __( 'No upload slug found', 'media-library-assistant' );
@@ -721,7 +708,7 @@ class MLASettings {
721
  */
722
  public static function mla_inline_mapping_custom_action() {
723
  set_current_screen( $_REQUEST['screen'] );
724
- check_ajax_referer( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
725
 
726
  /*
727
  * Convert the ajax bulk_action back to the older Submit button equivalent
@@ -797,7 +784,7 @@ class MLASettings {
797
  }
798
  }
799
 
800
- $current_values = MLAOptions::mla_get_option( 'custom_field_mapping' );
801
  $settings = array( $value['name'] => $current_values[$value['name']] );
802
  $map_content = self::_process_custom_field_mapping( $settings, $offset, $length );
803
  $page_content['message'] .= '<br>&nbsp;<br>' . $map_content['message'];
@@ -844,7 +831,7 @@ class MLASettings {
844
  */
845
  public static function mla_inline_mapping_iptc_exif_action() {
846
  set_current_screen( $_REQUEST['screen'] );
847
- check_ajax_referer( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
848
 
849
  /*
850
  * Convert the ajax bulk_action back to the older Submit button equivalent
@@ -931,7 +918,7 @@ class MLASettings {
931
  }
932
  }
933
 
934
- $current_values = MLAOptions::mla_get_option( 'iptc_exif_mapping' );
935
  $settings = array( 'custom' => array( $value['name'] => $current_values['custom'][$value['name']] ) );
936
  $map_content = self::_process_iptc_exif_custom( $settings, $offset, $length );
937
  $page_content['message'] .= '<br>&nbsp;<br>' . $map_content['message'];
@@ -981,7 +968,7 @@ class MLASettings {
981
  */
982
  public static function mla_add_plugin_settings_link_filter( $links, $file ) {
983
  if ( $file == 'media-library-assistant/index.php' ) {
984
- $settings_link = sprintf( '<a href="%s">%s</a>', admin_url( 'options-general.php?page=' . self::MLA_SETTINGS_SLUG . '-general' ), __( 'Settings', 'media-library-assistant' ) );
985
  array_unshift( $links, $settings_link );
986
  }
987
 
@@ -1005,23 +992,23 @@ class MLASettings {
1005
  $message = '<br>update_option(' . $key . ")\r\n";
1006
  switch ( $value['type'] ) {
1007
  case 'checkbox':
1008
- MLAOptions::mla_update_option( $key, 'checked', $option_table );
1009
  break;
1010
  case 'header':
1011
  case 'subheader':
1012
  $message = '';
1013
  break;
1014
  case 'radio':
1015
- MLAOptions::mla_update_option( $key, $_REQUEST[ MLA_OPTION_PREFIX . $key ], $option_table );
1016
  break;
1017
  case 'select':
1018
- MLAOptions::mla_update_option( $key, $_REQUEST[ MLA_OPTION_PREFIX . $key ], $option_table );
1019
  break;
1020
  case 'text':
1021
- MLAOptions::mla_update_option( $key, stripslashes( trim( $_REQUEST[ MLA_OPTION_PREFIX . $key ], $option_table ) ) );
1022
  break;
1023
  case 'textarea':
1024
- MLAOptions::mla_update_option( $key, stripslashes( trim( $_REQUEST[ MLA_OPTION_PREFIX . $key ], $option_table ) ) );
1025
  break;
1026
  case 'custom':
1027
  $message = MLAOptions::$value['update']( 'update', $key, $value, $_REQUEST );
@@ -1038,23 +1025,23 @@ class MLASettings {
1038
  switch ( $value['type'] ) {
1039
  case 'checkbox':
1040
  $message = '<br>uncheck_option(' . $key . ')';
1041
- MLAOptions::mla_update_option( $key, 'unchecked', $option_table );
1042
  break;
1043
  case 'header':
1044
  case 'subheader':
1045
  $message = '';
1046
  break;
1047
  case 'radio':
1048
- MLAOptions::mla_delete_option( $key, $option_table );
1049
  break;
1050
  case 'select':
1051
- MLAOptions::mla_delete_option( $key, $option_table );
1052
  break;
1053
  case 'text':
1054
- MLAOptions::mla_delete_option( $key, $option_table );
1055
  break;
1056
  case 'textarea':
1057
- MLAOptions::mla_delete_option( $key, $option_table );
1058
  break;
1059
  case 'custom':
1060
  $message = MLAOptions::$value['delete']( 'delete', $key, $value, $_REQUEST );
@@ -1092,7 +1079,7 @@ class MLASettings {
1092
  'help' => $value['help']
1093
  );
1094
 
1095
- if ( 'checked' == MLAOptions::mla_get_option( $key, false, false, $option_table ) ) {
1096
  $option_values['checked'] = 'checked="checked"';
1097
  }
1098
 
@@ -1116,7 +1103,7 @@ class MLASettings {
1116
  'value' => $value['texts'][$optid]
1117
  );
1118
 
1119
- if ( $option == MLAOptions::mla_get_option( $key, false, false, $option_table ) ) {
1120
  $option_values['checked'] = 'checked="checked"';
1121
  }
1122
 
@@ -1139,7 +1126,7 @@ class MLASettings {
1139
  'text' => $value['texts'][$optid]
1140
  );
1141
 
1142
- if ( $option == MLAOptions::mla_get_option( $key, false, false, $option_table ) ) {
1143
  $option_values['selected'] = 'selected="selected"';
1144
  }
1145
 
@@ -1167,7 +1154,7 @@ class MLASettings {
1167
  $option_values['size'] = $value['size'];
1168
  }
1169
 
1170
- $option_values['text'] = MLAOptions::mla_get_option( $key, false, false, $option_table );
1171
 
1172
  return MLAData::mla_parse_template( self::$page_template_array['text'], $option_values );
1173
  case 'textarea':
@@ -1189,7 +1176,7 @@ class MLASettings {
1189
  $option_values['rows'] = $value['rows'];
1190
  }
1191
 
1192
- $option_values['text'] = stripslashes( MLAOptions::mla_get_option( $key, false, false, $option_table ) );
1193
 
1194
  return MLAData::mla_parse_template( self::$page_template_array['textarea'], $option_values );
1195
  case 'custom':
@@ -1218,7 +1205,7 @@ class MLASettings {
1218
  *
1219
  * @var array
1220
  */
1221
- public static $page_template_array = null;
1222
 
1223
  /**
1224
  * Definitions for Settings page tab ids, titles and handlers
@@ -1310,7 +1297,7 @@ class MLASettings {
1310
  $item_values = array(
1311
  'data-tab-id' => $key,
1312
  'nav-tab-active' => ( $active_tab == $key ) ? 'nav-tab-active' : '',
1313
- 'settings-page' => self::MLA_SETTINGS_SLUG . '-' . $key,
1314
  'title' => $item['title']
1315
  );
1316
 
@@ -1335,16 +1322,16 @@ class MLASettings {
1335
  * Initialize page messages and content.
1336
  */
1337
  if ( !empty( $_REQUEST['mla-general-options-save'] ) ) {
1338
- check_admin_referer( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
1339
  $page_content = self::_save_general_settings( );
1340
  } elseif ( !empty( $_REQUEST['mla-general-options-export'] ) ) {
1341
- check_admin_referer( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
1342
  $page_content = self::_export_settings( );
1343
  } elseif ( !empty( $_REQUEST['mla-general-options-import'] ) ) {
1344
- check_admin_referer( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
1345
  $page_content = self::_import_settings( );
1346
  } elseif ( !empty( $_REQUEST['mla-general-options-reset'] ) ) {
1347
- check_admin_referer( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
1348
  $page_content = self::_reset_general_settings( );
1349
  } else {
1350
  $page_content = array(
@@ -1364,7 +1351,7 @@ class MLASettings {
1364
  'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
1365
  'Export ALL Settings' => __( 'Export ALL Settings', 'media-library-assistant' ),
1366
  'Delete General options' => __( 'Delete General options and restore default settings', 'media-library-assistant' ),
1367
- '_wpnonce' => wp_nonce_field( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME, true, false ),
1368
  '_wp_http_referer' => wp_referer_field( false ),
1369
  'Go to Top' => __( 'Go to Top', 'media-library-assistant' ),
1370
  'Support Our Work' => __( 'Support Our Work', 'media-library-assistant' ),
@@ -1391,8 +1378,8 @@ class MLASettings {
1391
  $shortcodes = array(
1392
  // array("name" => "shortcode", "description" => "This shortcode...")
1393
  // array( 'name' => 'mla_attachment_list', 'description' => __( 'renders a complete list of all attachments and references to them.', 'media-library-assistant' ) ),
1394
- array( 'name' => 'mla_gallery', 'description' => __( 'enhanced version of the WordPress [gallery] shortcode.', 'media-library-assistant' ) . sprintf( ' %1$s <a href="%2$s">%3$s</a>.', __( 'For complete documentation', 'media-library-assistant' ), admin_url( 'options-general.php?page=' . self::MLA_SETTINGS_SLUG . '-documentation&amp;mla_tab=documentation#mla_gallery' ), __( 'click here', 'media-library-assistant' ) ) ),
1395
- array( 'name' => 'mla_tag_cloud', 'description' => __( 'enhanced version of the WordPress Tag Cloud.', 'media-library-assistant' ) . sprintf( ' %1$s <a href="%2$s">%3$s</a>.', __( 'For complete documentation', 'media-library-assistant' ), admin_url( 'options-general.php?page=' . self::MLA_SETTINGS_SLUG . '-documentation&amp;mla_tab=documentation#mla_tag_cloud' ), __( 'click here', 'media-library-assistant' ) ) )
1396
  );
1397
 
1398
  $shortcode_list = '';
@@ -1414,7 +1401,7 @@ class MLASettings {
1414
  * Make sure the current choice still exists or revert to default.
1415
  */
1416
  $columns = array();
1417
- foreach ( MLA_List_Table::mla_get_sortable_columns( ) as $key => $value ) {
1418
  if ( ! array_key_exists( $value[1], $columns ) ) {
1419
  $columns[ $value[1] ] = $value[0];
1420
  }
@@ -1422,44 +1409,44 @@ class MLASettings {
1422
 
1423
  uksort( $columns, 'strnatcasecmp' );
1424
  $options = array_merge( array('None' => 'none'), $columns );
1425
- $current = MLAOptions::mla_get_option( MLAOptions::MLA_DEFAULT_ORDERBY );
1426
- MLAOptions::$mla_option_definitions[MLAOptions::MLA_DEFAULT_ORDERBY]['options'] = array();
1427
- MLAOptions::$mla_option_definitions[MLAOptions::MLA_DEFAULT_ORDERBY]['texts'] = array();
1428
  $found_current = false;
1429
  foreach ($options as $key => $value ) {
1430
- MLAOptions::$mla_option_definitions[MLAOptions::MLA_DEFAULT_ORDERBY]['options'][] = $value;
1431
- MLAOptions::$mla_option_definitions[MLAOptions::MLA_DEFAULT_ORDERBY]['texts'][] = $key;
1432
  if ( $current == $value ) {
1433
  $found_current = true;
1434
  }
1435
  }
1436
 
1437
  if ( ! $found_current ) {
1438
- MLAOptions::mla_delete_option( MLAOptions::MLA_DEFAULT_ORDERBY );
1439
  }
1440
 
1441
  /*
1442
  * Validate the Media Manager sort order or revert to default
1443
  */
1444
  $options = array_merge( array('&mdash; ' . __( 'Media Manager Default', 'media-library-assistant' ) . ' &mdash;' => 'default', 'None' => 'none'), $columns );
1445
- $current = MLAOptions::mla_get_option( MLAOptions::MLA_MEDIA_MODAL_ORDERBY );
1446
- MLAOptions::$mla_option_definitions[MLAOptions::MLA_MEDIA_MODAL_ORDERBY]['options'] = array();
1447
- MLAOptions::$mla_option_definitions[MLAOptions::MLA_MEDIA_MODAL_ORDERBY]['texts'] = array();
1448
  $found_current = false;
1449
  foreach ($options as $key => $value ) {
1450
- MLAOptions::$mla_option_definitions[MLAOptions::MLA_MEDIA_MODAL_ORDERBY]['options'][] = $value;
1451
- MLAOptions::$mla_option_definitions[MLAOptions::MLA_MEDIA_MODAL_ORDERBY]['texts'][] = $key;
1452
  if ( $current == $value ) {
1453
  $found_current = true;
1454
  }
1455
  }
1456
 
1457
  if ( ! $found_current ) {
1458
- MLAOptions::mla_delete_option( MLAOptions::MLA_MEDIA_MODAL_ORDERBY );
1459
  }
1460
 
1461
  $options_list = '';
1462
- foreach ( MLAOptions::$mla_option_definitions as $key => $value ) {
1463
  if ( 'general' == $value['tab'] ) {
1464
  $options_list .= self::mla_compose_option_row( $key, $value );
1465
  }
@@ -1516,7 +1503,7 @@ class MLASettings {
1516
  'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-view&mla_tab=view',
1517
  'action' => MLA::MLA_ADMIN_SINGLE_EDIT_UPDATE,
1518
  'original_slug' => $view['slug'],
1519
- '_wpnonce' => wp_nonce_field( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME, true, false ),
1520
  'Slug' => __( 'Slug', 'media-library-assistant' ),
1521
  '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' ),
1522
  'Singular Label' => __( 'Singular Label', 'media-library-assistant' ),
@@ -1591,10 +1578,10 @@ class MLASettings {
1591
  );
1592
 
1593
  if ( !empty( $_REQUEST['mla-view-options-save'] ) ) {
1594
- check_admin_referer( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
1595
  $page_content = self::_save_view_settings( );
1596
  } elseif ( !empty( $_REQUEST['mla-add-view-submit'] ) ) {
1597
- check_admin_referer( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
1598
  $page_content = MLAMime::mla_add_post_mime_type( $_REQUEST['mla_view_item'] );
1599
  if ( false !== strpos( $page_content['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
1600
  $add_form_values = $_REQUEST['mla_view_item'];
@@ -1660,10 +1647,10 @@ class MLASettings {
1660
  * Process row-level actions that affect a single item
1661
  */
1662
  if ( !empty( $_REQUEST['mla_admin_action'] ) ) {
1663
- check_admin_referer( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
1664
 
1665
  switch ( $_REQUEST['mla_admin_action'] ) {
1666
- case MLA::MLA_ADMIN_SINGLE_DELETE:
1667
  $page_content = MLAMime::mla_delete_post_mime_type( $_REQUEST['mla_item_slug'] );
1668
  break;
1669
  case MLA::MLA_ADMIN_SINGLE_EDIT_DISPLAY:
@@ -1703,12 +1690,12 @@ class MLASettings {
1703
  /*
1704
  * Check for disabled status
1705
  */
1706
- if ( 'checked' != MLAOptions::mla_get_option( MLAOptions::MLA_ENABLE_POST_MIME_TYPES ) ) {
1707
  /*
1708
  * Fill in with any page-level options
1709
  */
1710
  $options_list = '';
1711
- foreach ( MLAOptions::$mla_option_definitions as $key => $value ) {
1712
  if ( 'view' == $value['tab'] ) {
1713
  $options_list .= self::mla_compose_option_row( $key, $value );
1714
  }
@@ -1719,7 +1706,7 @@ class MLASettings {
1719
  'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-view&mla_tab=view',
1720
  'options_list' => $options_list,
1721
  'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
1722
- '_wpnonce' => wp_nonce_field( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME, true, false ),
1723
  );
1724
 
1725
  $page_content['body'] .= MLAData::mla_parse_template( $page_template_array['view-disabled'], $page_values );
@@ -1753,7 +1740,7 @@ class MLASettings {
1753
  * Start with any page-level options
1754
  */
1755
  $options_list = '';
1756
- foreach ( MLAOptions::$mla_option_definitions as $key => $value ) {
1757
  if ( 'view' == $value['tab'] ) {
1758
  $options_list .= self::mla_compose_option_row( $key, $value );
1759
  }
@@ -1766,7 +1753,7 @@ class MLASettings {
1766
  '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>' ),
1767
  'settingsURL' => admin_url('options-general.php'),
1768
  'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-view&mla_tab=view',
1769
- '_wpnonce' => wp_nonce_field( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME, true, false ),
1770
  'results' => ! empty( $_REQUEST['s'] ) ? '<h2 class="alignleft">' . __( 'Displaying search results for', 'media-library-assistant' ) . ': "' . $_REQUEST['s'] . '"</h2>' : '',
1771
  'Search Views' => __( 'Search Views', 'media-library-assistant' ),
1772
  's' => isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '',
@@ -1875,7 +1862,7 @@ class MLASettings {
1875
  'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-upload&mla_tab=upload',
1876
  'action' => MLA::MLA_ADMIN_SINGLE_EDIT_UPDATE,
1877
  'original_slug' => $item['slug'],
1878
- '_wpnonce' => wp_nonce_field( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME, true, false ),
1879
  'Extension' => __( 'Extension', 'media-library-assistant' ),
1880
  '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' ),
1881
  'MIME Type' => __( 'MIME Type', 'media-library-assistant' ),
@@ -1954,7 +1941,7 @@ class MLASettings {
1954
 
1955
  $page_values = array(
1956
  'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-upload&mla_tab=upload',
1957
- '_wpnonce' => wp_nonce_field( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME, true, false ),
1958
  'Known File Extension' => __( 'Known File Extension/MIME Type Associations', 'media-library-assistant' ),
1959
  'results' => ! empty( $_REQUEST['s'] ) ? '<h2 class="alignleft">' . __( 'Displaying search results for', 'media-library-assistant' ) . ': "' . $_REQUEST['s'] . '"</h2>' : '',
1960
  'Search Known MIME' => __( 'Search Known MIME Types', 'media-library-assistant' ),
@@ -2042,10 +2029,10 @@ class MLASettings {
2042
  );
2043
 
2044
  if ( !empty( $_REQUEST['mla-upload-options-save'] ) ) {
2045
- check_admin_referer( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
2046
  $page_content = self::_save_upload_settings( );
2047
  } elseif ( !empty( $_REQUEST['mla-optional-uploads-search'] ) ) {
2048
- check_admin_referer( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
2049
  $page_content = self::_compose_optional_upload_tab( $page_template_array );
2050
  } elseif ( !empty( $_REQUEST['mla-optional-uploads-cancel'] ) ) {
2051
  $page_content = array(
@@ -2054,12 +2041,12 @@ class MLASettings {
2054
  );
2055
  } elseif ( !empty( $_REQUEST['mla-optional-uploads-display'] ) ) {
2056
  if ( 'true' != $_REQUEST['mla-optional-uploads-display'] ) {
2057
- check_admin_referer( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
2058
  unset( $_REQUEST['s'] );
2059
  }
2060
  $page_content = self::_compose_optional_upload_tab( $page_template_array );
2061
  } elseif ( !empty( $_REQUEST['mla-add-upload-submit'] ) ) {
2062
- check_admin_referer( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
2063
  $page_content = MLAMime::mla_add_upload_mime( $_REQUEST['mla_upload_item'] );
2064
  if ( false !== strpos( $page_content['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
2065
  $add_form_values = $_REQUEST['mla_upload_item'];
@@ -2127,10 +2114,10 @@ class MLASettings {
2127
  * Process row-level actions that affect a single item
2128
  */
2129
  if ( !empty( $_REQUEST['mla_admin_action'] ) ) {
2130
- check_admin_referer( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
2131
 
2132
  switch ( $_REQUEST['mla_admin_action'] ) {
2133
- case MLA::MLA_ADMIN_SINGLE_DELETE:
2134
  $page_content = MLAMime::mla_delete_upload_mime( $_REQUEST['mla_item_slug'] );
2135
  break;
2136
  case MLA::MLA_ADMIN_SINGLE_EDIT_DISPLAY:
@@ -2172,12 +2159,12 @@ class MLASettings {
2172
  /*
2173
  * Check for disabled status
2174
  */
2175
- if ( 'checked' != MLAOptions::mla_get_option( MLAOptions::MLA_ENABLE_UPLOAD_MIMES ) ) {
2176
  /*
2177
  * Fill in with any page-level options
2178
  */
2179
  $options_list = '';
2180
- foreach ( MLAOptions::$mla_option_definitions as $key => $value ) {
2181
  if ( 'upload' == $value['tab'] ) {
2182
  $options_list .= self::mla_compose_option_row( $key, $value );
2183
  }
@@ -2188,7 +2175,7 @@ class MLASettings {
2188
  'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-upload&mla_tab=upload',
2189
  'options_list' => $options_list,
2190
  'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
2191
- '_wpnonce' => wp_nonce_field( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME, true, false ),
2192
  );
2193
 
2194
  $page_content['body'] .= MLAData::mla_parse_template( $page_template_array['upload-disabled'], $page_values );
@@ -2220,7 +2207,7 @@ class MLASettings {
2220
  * Start with any page-level options
2221
  */
2222
  $options_list = '';
2223
- foreach ( MLAOptions::$mla_option_definitions as $key => $value ) {
2224
  if ( 'upload' == $value['tab'] ) {
2225
  $options_list .= self::mla_compose_option_row( $key, $value );
2226
  }
@@ -2235,7 +2222,7 @@ class MLASettings {
2235
  'Search Uploads' => __( 'Search Uploads', 'media-library-assistant' ),
2236
  'To search by' => __( 'To search by extension, use ".", e.g., ".doc"', 'media-library-assistant' ),
2237
  'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-upload&mla_tab=upload',
2238
- '_wpnonce' => wp_nonce_field( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME, true, false ),
2239
  'options_list' => $options_list,
2240
  'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
2241
  /* translators: %s: add new Upload MIME Type */
@@ -2252,7 +2239,7 @@ class MLASettings {
2252
  'Description' => __( 'Description', 'media-library-assistant' ),
2253
  'The description can' => __( 'The description can contain any documentation or notes you need to understand or use the item.', 'media-library-assistant' ),
2254
  'Add Upload MIME' => __( 'Add Upload MIME Type', 'media-library-assistant' ),
2255
- 'search_url' => wp_nonce_url( '?page=mla-settings-menu-upload&mla_tab=upload&mla-optional-uploads-search=Search', MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME ),
2256
  'Search Known Types' => __( 'Search Known Types', 'media-library-assistant' ),
2257
  'colspan' => $MLAListUploadTable->get_column_count(),
2258
  'Quick Edit' => __( '<strong>Quick Edit</strong>', 'media-library-assistant' ),
@@ -2300,11 +2287,11 @@ class MLASettings {
2300
  * Initialize page messages and content.
2301
  */
2302
  if ( !empty( $_REQUEST['mla-gallery-options-save'] ) ) {
2303
- check_admin_referer( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
2304
  $page_content = self::_save_gallery_settings( );
2305
  } else {
2306
  $page_content = array(
2307
- 'message' => '',
2308
  'body' => ''
2309
  );
2310
  }
@@ -2326,17 +2313,17 @@ class MLASettings {
2326
  'Markup Templates' => __( 'Markup Templates', 'media-library-assistant' ),
2327
  'markup_options_list' => '',
2328
  'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
2329
- '_wpnonce' => wp_nonce_field( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME, true, false ),
2330
  '_wp_http_referer' => wp_referer_field( false )
2331
  );
2332
 
2333
  /*
2334
  * Build default template selection lists; leave out the [mla_tag_cloud] templates
2335
  */
2336
- MLAOptions::$mla_option_definitions['default_style']['options'][] = 'none';
2337
- MLAOptions::$mla_option_definitions['default_style']['texts'][] = '&mdash; ' . __( 'None', 'media-library-assistant' ) . ' &mdash;';
2338
- MLAOptions::$mla_option_definitions['default_style']['options'][] = 'theme';
2339
- MLAOptions::$mla_option_definitions['default_style']['texts'][] = '&mdash; ' . __( 'Theme', 'media-library-assistant' ) . ' &mdash;';
2340
 
2341
  $templates = MLAOptions::mla_get_style_templates();
2342
  ksort($templates);
@@ -2345,8 +2332,8 @@ class MLASettings {
2345
  continue;
2346
  }
2347
 
2348
- MLAOptions::$mla_option_definitions['default_style']['options'][] = $key;
2349
- MLAOptions::$mla_option_definitions['default_style']['texts'][] = $key;
2350
  }
2351
 
2352
  $templates = MLAOptions::mla_get_markup_templates();
@@ -2356,8 +2343,8 @@ class MLASettings {
2356
  continue;
2357
  }
2358
 
2359
- MLAOptions::$mla_option_definitions['default_markup']['options'][] = $key;
2360
- MLAOptions::$mla_option_definitions['default_markup']['texts'][] = $key;
2361
  }
2362
 
2363
  /*
@@ -2370,20 +2357,20 @@ class MLASettings {
2370
  $not_supported_warning = '';
2371
  }
2372
 
2373
- $ghostscript_path = MLAOptions::mla_get_option( 'ghostscript_path' );
2374
- if ( ! MLAShortcodes::mla_ghostscript_present( $ghostscript_path, true ) ) {
2375
  $not_supported_warning .= '<br>&nbsp;&nbsp;' . __( 'Ghostscript support is not installed.', 'media-library-assistant' );
2376
  }
2377
 
2378
  if ( ! empty( $not_supported_warning ) ) {
2379
- MLAOptions::$mla_option_definitions['enable_mla_viewer']['help'] = '<strong>' . __( 'WARNING: MLA Viewer support may not be available', 'media-library-assistant' ) . ':</strong>' . $not_supported_warning;
2380
  }
2381
 
2382
  /*
2383
  * Start with any page-level options
2384
  */
2385
  $options_list = '';
2386
- foreach ( MLAOptions::$mla_option_definitions as $key => $value ) {
2387
  if ( 'mla_gallery' == $value['tab'] ) {
2388
  $options_list .= self::mla_compose_option_row( $key, $value );
2389
  }
@@ -2670,7 +2657,7 @@ class MLASettings {
2670
  * Initialize page messages and content.
2671
  */
2672
  if ( isset( $_REQUEST['custom_field_mapping'] ) && is_array( $_REQUEST['custom_field_mapping'] ) ) {
2673
- check_admin_referer( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
2674
 
2675
  /*
2676
  * Check for page-level submit buttons to change settings or map attachments.
@@ -2682,7 +2669,7 @@ class MLASettings {
2682
  $page_content = self::_process_custom_field_mapping( );
2683
  } else {
2684
  $page_content = array(
2685
- 'message' => '',
2686
  'body' => ''
2687
  );
2688
 
@@ -2714,7 +2701,7 @@ class MLASettings {
2714
  case 'add_field_map':
2715
  $page_content = self::_save_custom_field_settings( $settings );
2716
  if ( false === strpos( $page_content['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
2717
- $current_values = MLAOptions::mla_get_option( 'custom_field_mapping' );
2718
  $settings = array( $value['name'] => $current_values[$value['name']] );
2719
  $map_content = self::_process_custom_field_mapping( $settings );
2720
  $page_content['message'] .= '<br>&nbsp;<br>' . $map_content['message'];
@@ -2730,7 +2717,7 @@ class MLASettings {
2730
  } // isset custom_field_mapping
2731
  else {
2732
  $page_content = array(
2733
- 'message' => '',
2734
  'body' => ''
2735
  );
2736
  }
@@ -2773,7 +2760,7 @@ class MLASettings {
2773
  '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>' ),
2774
  /* translators: 1: "Map All Rules..." */
2775
  '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>' ),
2776
- '_wpnonce' => wp_nonce_field( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME, true, false ),
2777
  '_wp_http_referer' => wp_referer_field( false )
2778
  );
2779
 
@@ -2781,7 +2768,7 @@ class MLASettings {
2781
  * Start with any page-level options
2782
  */
2783
  $options_list = '';
2784
- foreach ( MLAOptions::$mla_option_definitions as $key => $value ) {
2785
  if ( 'custom_field' == $value['tab'] ) {
2786
  $options_list .= self::mla_compose_option_row( $key, $value );
2787
  }
@@ -2792,7 +2779,7 @@ class MLASettings {
2792
  /*
2793
  * Add mapping options
2794
  */
2795
- $page_values['custom_options_list'] = MLAOptions::mla_custom_field_option_handler( 'render', 'custom_field_mapping', MLAOptions::$mla_option_definitions['custom_field_mapping'] );
2796
 
2797
  $page_content['body'] = MLAData::mla_parse_template( self::$page_template_array['custom-field-tab'], $page_values );
2798
  return $page_content;
@@ -2817,7 +2804,7 @@ class MLASettings {
2817
  );
2818
 
2819
  if ( isset( $_REQUEST['iptc_exif_mapping'] ) && is_array( $_REQUEST['iptc_exif_mapping'] ) ) {
2820
- check_admin_referer( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
2821
 
2822
  if ( !empty( $_REQUEST['iptc-exif-options-save'] ) ) {
2823
  $page_content = self::_save_iptc_exif_settings( );
@@ -2856,7 +2843,7 @@ class MLASettings {
2856
  case 'add_field_map':
2857
  $page_content = self::_save_iptc_exif_custom_settings( $settings );
2858
  if ( false === strpos( $page_content['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
2859
- $current_values = MLAOptions::mla_get_option( 'iptc_exif_mapping' );
2860
  $settings = array( 'custom' => array( $value['name'] => $current_values['custom'][$value['name']] ) );
2861
  $map_content = self::_process_iptc_exif_custom( $settings );
2862
  $page_content['message'] .= '<br>&nbsp;<br>' . $map_content['message'];
@@ -2912,7 +2899,7 @@ class MLASettings {
2912
  'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
2913
  /* translators: 1: "Save Changes" */
2914
  '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>' ),
2915
- '_wpnonce' => wp_nonce_field( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME, true, false ),
2916
  '_wp_http_referer' => wp_referer_field( false )
2917
  );
2918
 
@@ -2920,7 +2907,7 @@ class MLASettings {
2920
  * Start with any page-level options
2921
  */
2922
  $options_list = '';
2923
- foreach ( MLAOptions::$mla_option_definitions as $key => $value ) {
2924
  if ( 'iptc_exif' == $value['tab'] ) {
2925
  $options_list .= self::mla_compose_option_row( $key, $value );
2926
  }
@@ -2931,11 +2918,11 @@ class MLASettings {
2931
  /*
2932
  * Add mapping options
2933
  */
2934
- $page_values['standard_options_list'] = MLAOptions::mla_iptc_exif_option_handler( 'render', 'iptc_exif_standard_mapping', MLAOptions::$mla_option_definitions['iptc_exif_standard_mapping'] );
2935
 
2936
- $page_values['taxonomy_options_list'] = MLAOptions::mla_iptc_exif_option_handler( 'render', 'iptc_exif_taxonomy_mapping', MLAOptions::$mla_option_definitions['iptc_exif_taxonomy_mapping'] );
2937
 
2938
- $page_values['custom_options_list'] = MLAOptions::mla_iptc_exif_option_handler( 'render', 'iptc_exif_custom_mapping', MLAOptions::$mla_option_definitions['iptc_exif_custom_mapping'] );
2939
 
2940
  $page_content['body'] = MLAData::mla_parse_template( self::$page_template_array['iptc-exif-tab'], $page_values );
2941
  return $page_content;
@@ -2975,7 +2962,7 @@ class MLASettings {
2975
  private static function _save_debug_settings( ) {
2976
  $message_list = '';
2977
 
2978
- foreach ( MLAOptions::$mla_option_definitions as $key => $value ) {
2979
  if ( 'debug' == $value['tab'] ) {
2980
  $message_list .= self::mla_update_option_row( $key, $value );
2981
  } // view option
@@ -3034,14 +3021,14 @@ class MLASettings {
3034
  * Saving the options can change the log file name, so do it first
3035
  */
3036
  if ( !empty( $_REQUEST['mla-debug-options-save'] ) ) {
3037
- check_admin_referer( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME );
3038
  $page_content = self::_save_debug_settings();
3039
  }
3040
 
3041
  /*
3042
  * Find the appropriate error log file
3043
  */
3044
- $error_log_name = MLAOptions::mla_get_option( MLAOptions::MLA_DEBUG_FILE );
3045
  if ( empty( $error_log_name ) ) {
3046
  $error_log_name = ini_get( 'error_log' );
3047
  } else {
@@ -3088,7 +3075,7 @@ class MLASettings {
3088
  * Start with any page-level options
3089
  */
3090
  $options_list = '';
3091
- foreach ( MLAOptions::$mla_option_definitions as $key => $value ) {
3092
  if ( 'debug' == $value['tab'] ) {
3093
  $options_list .= self::mla_compose_option_row( $key, $value );
3094
  }
@@ -3097,17 +3084,17 @@ class MLASettings {
3097
  /*
3098
  * Gather Debug Settings
3099
  */
3100
- $display_limit = MLAOptions::mla_get_option( MLAOptions::MLA_DEBUG_DISPLAY_LIMIT );
3101
- $debug_file = MLAOptions::mla_get_option( MLAOptions::MLA_DEBUG_FILE );
3102
- $replace_php = MLAOptions::mla_get_option( MLAOptions::MLA_DEBUG_REPLACE_PHP_LOG );
3103
- $php_reporting = MLAOptions::mla_get_option( MLAOptions::MLA_DEBUG_REPLACE_PHP_REPORTING );
3104
- $mla_reporting = MLAOptions::mla_get_option( MLAOptions::MLA_DEBUG_REPLACE_LEVEL );
3105
 
3106
  if ( $error_log_exists ) {
3107
  /*
3108
  * Add debug content
3109
  */
3110
- $display_limit = absint( MLAOptions::mla_get_option( MLAOptions::MLA_DEBUG_DISPLAY_LIMIT ) );
3111
  $error_log_size = filesize( $error_log_name );
3112
 
3113
  if ( 0 < $display_limit ) {
@@ -3149,11 +3136,11 @@ class MLASettings {
3149
  if ( current_user_can( 'upload_files' ) ) {
3150
  if ( $error_log_exists ) {
3151
  $args = array(
3152
- 'page' => MLA::ADMIN_PAGE_SLUG,
3153
  'mla_download_file' => urlencode( $error_log_name ),
3154
  'mla_download_type' => 'text/plain'
3155
  );
3156
- $download_link = '<a class="button-secondary" href="' . add_query_arg( $args, wp_nonce_url( 'upload.php', MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME ) ) . '" title="' . __( 'Download', 'media-library-assistant' ) . ' &#8220;' . __( 'Error Log', 'media-library-assistant' ) . '&#8221;">' . __( 'Download', 'media-library-assistant' ) . '</a>';
3157
  } else {
3158
  $download_link = '';
3159
  }
@@ -3163,7 +3150,7 @@ class MLASettings {
3163
  'mla_tab' => 'debug',
3164
  'mla_reset_log' => 'true'
3165
  );
3166
- $reset_link = '<a class="button-secondary" href="' . add_query_arg( $args, wp_nonce_url( 'options-general.php', MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME ) ) . '" title="' . __( 'Reset', 'media-library-assistant' ) . ' &#8220;' . __( 'Error Log', 'media-library-assistant' ) . '&#8221;">' . __( 'Reset', 'media-library-assistant' ) . '</a>';
3167
  }
3168
 
3169
  $settings_list = self::_compose_settings_row( 'Display Limit', $display_limit );
@@ -3172,8 +3159,8 @@ class MLASettings {
3172
  $settings_list .= self::_compose_settings_row( 'PHP Reporting', $php_reporting );
3173
  $settings_list .= self::_compose_settings_row( 'MLA Reporting', $mla_reporting );
3174
  $settings_list .= self::_compose_settings_row( 'MLA_DEBUG_LEVEL', sprintf( '0x%1$04X', MLA_DEBUG_LEVEL ) );
3175
- $settings_list .= self::_compose_settings_row( 'PHP error_reporting', MLA::$original_php_reporting );
3176
- $settings_list .= self::_compose_settings_row( 'Old PHP error_log', MLA::$original_php_log );
3177
  $settings_list .= self::_compose_settings_row( 'New PHP error_log', ini_get( 'error_log' ) );
3178
  $settings_list .= self::_compose_settings_row( 'WP_DEBUG', WP_DEBUG ? 'true' : 'false' );
3179
  $settings_list .= self::_compose_settings_row( 'WP_DEBUG_LOG', WP_DEBUG_LOG ? 'true' : 'false' );
@@ -3198,7 +3185,7 @@ class MLASettings {
3198
  'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
3199
  /* translators: 1: "Save Changes" */
3200
  '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' ) ),
3201
- '_wpnonce' => wp_nonce_field( MLA::MLA_ADMIN_NONCE_ACTION, MLA::MLA_ADMIN_NONCE_NAME, true, false ),
3202
  '_wp_http_referer' => wp_referer_field( false )
3203
  );
3204
 
@@ -3287,10 +3274,10 @@ class MLASettings {
3287
  /*
3288
  * Start with any page-level options
3289
  */
3290
- foreach ( MLAOptions::$mla_option_definitions as $key => $value ) {
3291
  if ( 'mla_gallery' == $value['tab'] ) {
3292
  if ( 'select' == $value['type'] ) {
3293
- $old_value = MLAOptions::mla_get_option( $key );
3294
  if ( $old_value != $_REQUEST[ MLA_OPTION_PREFIX . $key ] ) {
3295
  $settings_changed = true;
3296
  $message_list .= self::mla_update_option_row( $key, $value );
@@ -3300,13 +3287,13 @@ class MLASettings {
3300
  $_REQUEST[ MLA_OPTION_PREFIX . $key ] = $value['std'];
3301
  }
3302
 
3303
- $old_value = MLAOptions::mla_get_option( $key );
3304
  if ( $old_value != $_REQUEST[ MLA_OPTION_PREFIX . $key ] ) {
3305
  $settings_changed = true;
3306
  $message_list .= self::mla_update_option_row( $key, $value );
3307
  }
3308
  } elseif ( 'checkbox' == $value['type'] ) {
3309
- $old_value = MLAOptions::mla_get_option( $key );
3310
  if ( isset( $_REQUEST[ MLA_OPTION_PREFIX . $key ] ) ) {
3311
  $checkbox_changed = "checked" != $old_value;
3312
  } else {
@@ -3560,7 +3547,7 @@ class MLASettings {
3560
  private static function _save_view_settings( ) {
3561
  $message_list = '';
3562
 
3563
- foreach ( MLAOptions::$mla_option_definitions as $key => $value ) {
3564
  if ( 'view' == $value['tab'] ) {
3565
  $message_list .= self::mla_update_option_row( $key, $value );
3566
  } // view option
@@ -3591,10 +3578,10 @@ class MLASettings {
3591
  private static function _save_upload_settings( ) {
3592
  $message_list = '';
3593
 
3594
- if ( ! isset( $_REQUEST[ MLA_OPTION_PREFIX . MLAOptions::MLA_ENABLE_UPLOAD_MIMES ] ) )
3595
- unset( $_REQUEST[ MLA_OPTION_PREFIX . MLAOptions::MLA_ENABLE_MLA_ICONS ] );
3596
 
3597
- foreach ( MLAOptions::$mla_option_definitions as $key => $value ) {
3598
  if ( 'upload' == $value['tab'] ) {
3599
  $message_list .= self::mla_update_option_row( $key, $value );
3600
  } // upload option
@@ -3631,11 +3618,11 @@ class MLASettings {
3631
  if ( NULL == $settings ) {
3632
  $source = 'custom_fields';
3633
  $settings = ( isset( $_REQUEST['custom_field_mapping'] ) ) ? stripslashes_deep( $_REQUEST['custom_field_mapping'] ) : array();
3634
- if ( isset( $settings[ MLAOptions::MLA_NEW_CUSTOM_FIELD ] ) ) {
3635
- unset( $settings[ MLAOptions::MLA_NEW_CUSTOM_FIELD ] );
3636
  }
3637
- if ( isset( $settings[ MLAOptions::MLA_NEW_CUSTOM_RULE ] ) ) {
3638
- unset( $settings[ MLAOptions::MLA_NEW_CUSTOM_RULE ] );
3639
  }
3640
  } else {
3641
  $source = 'custom_rule';
@@ -3645,7 +3632,10 @@ class MLASettings {
3645
  if ( empty( $settings ) ) {
3646
  return array(
3647
  'message' => __( 'ERROR', 'media-library-assistant' ) . ': ' . __( 'No custom field mapping rules to process.', 'media-library-assistant' ),
3648
- 'body' => ''
 
 
 
3649
  );
3650
  }
3651
 
@@ -3734,7 +3724,7 @@ class MLASettings {
3734
  /*
3735
  * Start with any page-level options
3736
  */
3737
- foreach ( MLAOptions::$mla_option_definitions as $key => $value ) {
3738
  if ( 'custom_field' == $value['tab'] ) {
3739
  $option_messages .= self::mla_update_option_row( $key, $value );
3740
  }
@@ -3752,7 +3742,7 @@ class MLASettings {
3752
  // $message_list = $option_messages . '<br>';
3753
 
3754
  return array(
3755
- 'message' => $message_list . MLAOptions::mla_custom_field_option_handler( 'update', 'custom_field_mapping', MLAOptions::$mla_option_definitions['custom_field_mapping'], $new_values ),
3756
  'body' => ''
3757
  );
3758
  } // _save_custom_field_settings
@@ -3775,7 +3765,10 @@ class MLASettings {
3775
  return array(
3776
  /* translators: 1: ERROR tag 2: field type */
3777
  'message' => sprintf( __( '%1$s: No %2$s settings to process.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'Standard field', 'media-library-assistant' ) ),
3778
- 'body' => ''
 
 
 
3779
  );
3780
  }
3781
 
@@ -3788,6 +3781,7 @@ class MLASettings {
3788
  $query['offset'] = $offset;
3789
  }
3790
 
 
3791
  $posts = MLAShortcodes::mla_get_shortcode_attachments( 0, $query );
3792
 
3793
  if ( is_string( $posts ) ) {
@@ -3797,7 +3791,6 @@ class MLASettings {
3797
  );
3798
  }
3799
 
3800
- do_action( 'mla_begin_mapping', 'iptc_exif_standard', NULL );
3801
  foreach ( $posts as $key => $post ) {
3802
  $updates = MLAOptions::mla_evaluate_iptc_exif_mapping( $post, 'iptc_exif_standard_mapping', $_REQUEST['iptc_exif_mapping'] );
3803
 
@@ -3846,7 +3839,10 @@ class MLASettings {
3846
  return array(
3847
  /* translators: 1: ERROR tag 2: field type */
3848
  'message' => sprintf( __( '%1$s: No %2$s settings to process.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'Taxonomy term', 'media-library-assistant' ) ),
3849
- 'body' => ''
 
 
 
3850
  );
3851
  }
3852
 
@@ -3859,6 +3855,7 @@ class MLASettings {
3859
  $query['offset'] = $offset;
3860
  }
3861
 
 
3862
  $posts = MLAShortcodes::mla_get_shortcode_attachments( 0, $query );
3863
 
3864
  if ( is_string( $posts ) ) {
@@ -3868,7 +3865,6 @@ class MLASettings {
3868
  );
3869
  }
3870
 
3871
- do_action( 'mla_begin_mapping', 'iptc_exif_taxonomy', NULL );
3872
  foreach ( $posts as $key => $post ) {
3873
  $updates = MLAOptions::mla_evaluate_iptc_exif_mapping( $post, 'iptc_exif_taxonomy_mapping', $_REQUEST['iptc_exif_mapping'] );
3874
 
@@ -3917,11 +3913,11 @@ class MLASettings {
3917
  if ( NULL == $settings ) {
3918
  $source = 'iptc_exif_custom';
3919
  $settings = ( isset( $_REQUEST['iptc_exif_mapping'] ) ) ? stripslashes_deep( $_REQUEST['iptc_exif_mapping'] ) : array();
3920
- if ( isset( $settings['custom'][ MLAOptions::MLA_NEW_CUSTOM_FIELD ] ) ) {
3921
- unset( $settings['custom'][ MLAOptions::MLA_NEW_CUSTOM_FIELD ] );
3922
  }
3923
- if ( isset( $settings['custom'][ MLAOptions::MLA_NEW_CUSTOM_RULE ] ) ) {
3924
- unset( $settings['custom'][ MLAOptions::MLA_NEW_CUSTOM_RULE ] );
3925
  }
3926
  } else {
3927
  $source = 'iptc_exif_custom_rule';
@@ -3932,7 +3928,10 @@ class MLASettings {
3932
  return array(
3933
  /* translators: 1: ERROR tag 2: field type */
3934
  'message' => sprintf( __( '%1$s: No %2$s settings to process.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'Custom field', 'media-library-assistant' ) ),
3935
- 'body' => ''
 
 
 
3936
  );
3937
  }
3938
 
@@ -3945,6 +3944,7 @@ class MLASettings {
3945
  $query['offset'] = $offset;
3946
  }
3947
 
 
3948
  $posts = MLAShortcodes::mla_get_shortcode_attachments( 0, $query );
3949
 
3950
  if ( is_string( $posts ) ) {
@@ -3954,7 +3954,6 @@ class MLASettings {
3954
  );
3955
  }
3956
 
3957
- do_action( 'mla_begin_mapping', $source, NULL );
3958
  foreach ( $posts as $key => $post ) {
3959
  $updates = MLAOptions::mla_evaluate_iptc_exif_mapping( $post, 'iptc_exif_custom_mapping', $settings );
3960
 
@@ -3996,7 +3995,7 @@ class MLASettings {
3996
  */
3997
  private static function _save_iptc_exif_custom_settings( $new_values ) {
3998
  return array(
3999
- 'message' => MLAOptions::mla_iptc_exif_option_handler( 'update', 'iptc_exif_custom_mapping', MLAOptions::$mla_option_definitions['iptc_exif_mapping'], $new_values ),
4000
  'body' => ''
4001
  );
4002
  } // _save_iptc_exif_custom_settings
@@ -4017,7 +4016,7 @@ class MLASettings {
4017
  /*
4018
  * Start with any page-level options
4019
  */
4020
- foreach ( MLAOptions::$mla_option_definitions as $key => $value ) {
4021
  if ( 'iptc_exif' == $value['tab'] ) {
4022
  $option_messages .= self::mla_update_option_row( $key, $value );
4023
  }
@@ -4034,7 +4033,7 @@ class MLASettings {
4034
  $new_values = ( isset( $_REQUEST['iptc_exif_mapping'] ) ) ? $_REQUEST['iptc_exif_mapping'] : array( 'standard' => array(), 'taxonomy' => array(), 'custom' => array() );
4035
 
4036
  return array(
4037
- 'message' => $message_list . MLAOptions::mla_iptc_exif_option_handler( 'update', 'iptc_exif_mapping', MLAOptions::$mla_option_definitions['iptc_exif_mapping'], $new_values ),
4038
  'body' => ''
4039
  );
4040
  } // _save_iptc_exif_settings
@@ -4051,36 +4050,36 @@ class MLASettings {
4051
  private static function _save_general_settings( ) {
4052
  $message_list = '';
4053
 
4054
- foreach ( MLAOptions::$mla_option_definitions as $key => $value ) {
4055
  if ( 'general' == $value['tab'] ) {
4056
  switch ( $key ) {
4057
- case MLAOptions::MLA_FEATURED_IN_TUNING:
4058
- MLAOptions::$process_featured_in = ( 'disabled' != $_REQUEST[ MLA_OPTION_PREFIX . $key ] );
4059
  break;
4060
- case MLAOptions::MLA_INSERTED_IN_TUNING:
4061
- MLAOptions::$process_inserted_in = ( 'disabled' != $_REQUEST[ MLA_OPTION_PREFIX . $key ] );
4062
  break;
4063
- case MLAOptions::MLA_GALLERY_IN_TUNING:
4064
- MLAOptions::$process_gallery_in = ( 'disabled' != $_REQUEST[ MLA_OPTION_PREFIX . $key ] );
4065
 
4066
  if ( 'refresh' == $_REQUEST[ MLA_OPTION_PREFIX . $key ] ) {
4067
- MLAData::mla_flush_mla_galleries( MLAOptions::MLA_GALLERY_IN_TUNING );
4068
  /* translators: 1: reference type, e.g., Gallery in */
4069
  $message_list .= "<br>" . sprintf( _x( '%1$s - references updated.', 'message_list', 'media-library-assistant' ), __( 'Gallery in', 'media-library-assistant' ) ) . "\r\n";
4070
  $_REQUEST[ MLA_OPTION_PREFIX . $key ] = 'cached';
4071
  }
4072
  break;
4073
- case MLAOptions::MLA_MLA_GALLERY_IN_TUNING:
4074
- MLAOptions::$process_mla_gallery_in = ( 'disabled' != $_REQUEST[ MLA_OPTION_PREFIX . $key ] );
4075
 
4076
  if ( 'refresh' == $_REQUEST[ MLA_OPTION_PREFIX . $key ] ) {
4077
- MLAData::mla_flush_mla_galleries( MLAOptions::MLA_MLA_GALLERY_IN_TUNING );
4078
  /* translators: 1: reference type, e.g., Gallery in */
4079
  $message_list .= "<br>" . sprintf( _x( '%1$s - references updated.', 'message_list', 'media-library-assistant' ), __( 'MLA Gallery in', 'media-library-assistant' ) ) . "\r\n";
4080
  $_REQUEST[ MLA_OPTION_PREFIX . $key ] = 'cached';
4081
  }
4082
  break;
4083
- case MLAOptions::MLA_TAXONOMY_SUPPORT:
4084
  /*
4085
  * Replace missing "checkbox" arguments with empty arrays,
4086
  * denoting that all of the boxes are unchecked.
@@ -4101,7 +4100,7 @@ class MLASettings {
4101
  $_REQUEST['tax_checked_on_top'] = array();
4102
  }
4103
  break;
4104
- case MLAOptions::MLA_SEARCH_MEDIA_FILTER_DEFAULTS:
4105
  /*
4106
  * Replace missing "checkbox" arguments with empty arrays,
4107
  * denoting that all of the boxes are unchecked.
@@ -4141,14 +4140,14 @@ class MLASettings {
4141
  private static function _reset_general_settings( ) {
4142
  $message_list = '';
4143
 
4144
- foreach ( MLAOptions::$mla_option_definitions as $key => $value ) {
4145
  if ( 'general' == $value['tab'] ) {
4146
  if ( 'custom' == $value['type'] && isset( $value['reset'] ) ) {
4147
  $message = MLAOptions::$value['reset']( 'reset', $key, $value, $_REQUEST );
4148
  } elseif ( ('header' == $value['type']) || ('hidden' == $value['type']) ) {
4149
  $message = '';
4150
  } else {
4151
- MLAOptions::mla_delete_option( $key );
4152
  /* translators: 1: option name */
4153
  $message = '<br>' . sprintf( _x( 'delete_option "%1$s"', 'message_list', 'media-library-assistant'), $key );
4154
  }
@@ -4235,13 +4234,33 @@ class MLASettings {
4235
  private static function _export_settings( ) {
4236
  $message_list = '';
4237
  $settings = array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4238
 
4239
  /*
4240
  * Accumulate the settings into an array, then serialize it for writing to the file.
4241
  */
4242
- $stored_count = 0;
4243
- foreach ( MLAOptions::$mla_option_definitions as $key => $value ) {
4244
- $stored_value = MLAOptions::mla_get_option( $key, false, true );
4245
  if ( false !== $stored_value ) {
4246
  $settings[ $key ] = $stored_value;
4247
  $stored_count++;
@@ -4358,7 +4377,32 @@ class MLASettings {
4358
  $updated_count = 0;
4359
  $unchanged_count = 0;
4360
  foreach ( $settings as $key => $value ) {
4361
- if ( MLAOptions::mla_update_option( $key, $value ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4362
  $updated_count++;
4363
  $message_list .= "<br>{$key} " . _x( 'updated', 'message_list', 'media-library-assistant' );
4364
  } else {
76
  */
77
  const JAVASCRIPT_INLINE_MAPPING_OBJECT = 'mla_inline_mapping_vars';
78
 
 
 
 
 
 
 
 
 
 
79
  /**
80
  * Holds screen id to match help text to corresponding screen
81
  *
110
  * @return void
111
  */
112
  private static function _version_upgrade( ) {
113
+ $current_version = MLACore::mla_get_option( MLACore::MLA_VERSION_OPTION );
114
 
115
  if ( version_compare( '.30', $current_version, '>' ) ) {
116
  /*
117
  * Convert attachment_category and _tag to taxonomy_support;
118
  * change the default if either option is unchecked
119
  */
120
+ $category_option = MLACore::mla_get_option( 'attachment_category' );
121
+ $tag_option = MLACore::mla_get_option( 'attachment_tag' );
122
  if ( ! ( ( 'checked' == $category_option ) && ( 'checked' == $tag_option ) ) ) {
123
+ $tax_option = MLACore::mla_get_option( MLACore::MLA_TAXONOMY_SUPPORT );
124
  if ( 'checked' != $category_option ) {
125
  if ( isset( $tax_option['tax_support']['attachment_category'] ) ) {
126
  unset( $tax_option['tax_support']['attachment_category'] );
133
  }
134
  }
135
 
136
+ MLAOptions::mla_taxonomy_option_handler( 'update', 'taxonomy_support', MLACore::$mla_option_definitions['taxonomy_support'], $tax_option );
137
  } // one or both options unchecked
138
 
139
+ MLACore::mla_delete_option( 'attachment_category' );
140
+ MLACore::mla_delete_option( 'attachment_tag' );
141
  } // version is less than .30
142
 
143
  if ( version_compare( '1.13', $current_version, '>' ) ) {
146
  */
147
  $new_values = array();
148
 
149
+ foreach ( MLACore::mla_get_option( 'custom_field_mapping' ) as $key => $value ) {
150
  $value['quick_edit'] = ( isset( $value['quick_edit'] ) && $value['quick_edit'] ) ? true : false;
151
  $value['bulk_edit'] = ( isset( $value['bulk_edit'] ) && $value['bulk_edit'] ) ? true : false;
152
  $new_values[ $key ] = $value;
153
  }
154
 
155
+ MLACore::mla_update_option( 'custom_field_mapping', $new_values );
156
  } // version is less than 1.13
157
 
158
  if ( version_compare( '1.30', $current_version, '>' ) ) {
161
  */
162
  $new_values = array();
163
 
164
+ foreach ( MLACore::mla_get_option( 'custom_field_mapping' ) as $key => $value ) {
165
  $value['meta_name'] = isset( $value['meta_name'] ) ? $value['meta_name'] : '';
166
  $value['meta_single'] = ( isset( $value['meta_single'] ) && $value['meta_single'] ) ? true : false;
167
  $value['meta_export'] = ( isset( $value['meta_export'] ) && $value['meta_export'] ) ? true : false;
168
  $new_values[ $key ] = $value;
169
  }
170
 
171
+ MLACore::mla_update_option( 'custom_field_mapping', $new_values );
172
  } // version is less than 1.30
173
 
174
  if ( version_compare( '1.40', $current_version, '>' ) ) {
177
  */
178
  $new_values = array();
179
 
180
+ foreach ( MLACore::mla_get_option( 'custom_field_mapping' ) as $key => $value ) {
181
  $value['no_null'] = ( isset( $value['no_null'] ) && $value['no_null'] ) ? true : false;
182
 
183
  if ( isset( $value['meta_single'] ) && $value['meta_single'] ) {
194
  $new_values[ $key ] = $value;
195
  }
196
 
197
+ MLACore::mla_update_option( 'custom_field_mapping', $new_values );
198
  } // version is less than 1.40
199
 
200
  if ( version_compare( '1.60', $current_version, '>' ) ) {
201
  /*
202
  * Add delimiters values to taxonomy mapping rules
203
  */
204
+ $option_value = MLACore::mla_get_option( 'iptc_exif_mapping' );
205
  $new_values = array();
206
 
207
  foreach ( $option_value['taxonomy'] as $key => $value ) {
210
  }
211
 
212
  $option_value['taxonomy'] = $new_values;
213
+ MLACore::mla_update_option( 'iptc_exif_mapping', $option_value );
214
  } // version is less than 1.60
215
 
216
  if ( version_compare( '1.72', $current_version, '>' ) ) {
224
  /*
225
  * Add format, option and no_null to IPTC/EXIF custom mapping rules
226
  */
227
+ $option_value = MLACore::mla_get_option( 'iptc_exif_mapping' );
228
  $new_values = array();
229
 
230
  foreach ( $option_value['custom'] as $key => $value ) {
235
  }
236
 
237
  $option_value['custom'] = $new_values;
238
+ MLACore::mla_update_option( 'iptc_exif_mapping', $option_value );
239
  } // version is less than 2.13
240
 
241
+ MLACore::mla_update_option( MLACore::MLA_VERSION_OPTION, MLA::CURRENT_MLA_VERSION );
242
  }
243
 
244
  /**
245
  * Perform one-time actions on plugin activation
246
  *
 
 
247
  * @since 0.40
248
  *
249
  * @return void
250
  */
251
  public static function mla_activation_hook( ) {
 
252
  }
253
 
254
  /**
255
  * Perform one-time actions on plugin deactivation
256
  *
 
 
257
  * @since 0.40
258
  *
259
  * @return void
260
  */
261
  public static function mla_deactivation_hook( ) {
 
 
 
 
 
 
 
 
262
  }
263
 
264
  /**
336
  * Initialize common script variables
337
  */
338
  $script_variables = array(
339
+ 'error' => __( 'Error while making the changes.', 'media-library-assistant' ),
340
  'ntdeltitle' => __( 'Remove From Bulk Edit', 'media-library-assistant' ),
341
  'notitle' => '(' . __( 'no slug', 'media-library-assistant' ) . ')',
342
  'comma' => _x( ',', 'tag_delimiter', 'media-library-assistant' ),
343
  'useSpinnerClass' => false,
344
+ 'ajax_nonce' => wp_create_nonce( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME )
345
  );
346
 
347
  if ( version_compare( get_bloginfo( 'version' ), '4.2', '>=' ) ) {
349
  }
350
 
351
  $mapping_variables = array(
352
+ 'bulkChunkSize' => MLACore::mla_get_option( MLACore::MLA_BULK_CHUNK_SIZE ),
 
 
 
353
  'bulkWaiting' => __( 'Waiting', 'media-library-assistant' ),
354
  'bulkRunning' => __( 'Running', 'media-library-assistant' ),
355
  'bulkComplete' => __( 'Complete', 'media-library-assistant' ),
397
  MLA_PLUGIN_URL . "js/mla-inline-mapping-scripts{$suffix}.js",
398
  array( 'jquery' ), MLA::CURRENT_MLA_VERSION, false );
399
 
400
+ $tab_variables = array(
401
+ 'page' => 'mla-settings-menu-custom_field',
402
+ 'mla_tab' => 'custom_field',
403
+ 'screen' => 'settings_page_mla-settings-menu-custom_field',
404
+ 'ajax_action' => self::JAVASCRIPT_INLINE_MAPPING_CUSTOM_SLUG,
405
+ 'fieldsId' => '#mla-display-settings-custom-field-tab',
406
+ 'totalItems' => $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE `post_type` = 'attachment'" )
407
+ );
408
+
409
+ $script_variables = array_merge( $script_variables, $mapping_variables, $tab_variables );
410
 
411
  wp_localize_script( self::JAVASCRIPT_INLINE_MAPPING_CUSTOM_SLUG,
412
  self::JAVASCRIPT_INLINE_MAPPING_OBJECT, $script_variables );
416
  MLA_PLUGIN_URL . "js/mla-inline-mapping-scripts{$suffix}.js",
417
  array( 'jquery' ), MLA::CURRENT_MLA_VERSION, false );
418
 
419
+ $tab_variables = array(
420
+ 'page' => 'mla-settings-menu-iptc_exif',
421
+ 'mla_tab' => 'iptc_exif',
422
+ 'screen' => 'settings_page_mla-settings-menu-iptc_exif',
423
+ 'ajax_action' => self::JAVASCRIPT_INLINE_MAPPING_IPTC_EXIF_SLUG,
424
+ 'fieldsId' => '#mla-display-settings-iptc-exif-tab',
425
+ '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%' )" ),
426
+ );
427
+
428
+ $script_variables = array_merge( $script_variables, $mapping_variables, $tab_variables );
429
 
430
  wp_localize_script( self::JAVASCRIPT_INLINE_MAPPING_IPTC_EXIF_SLUG,
431
  self::JAVASCRIPT_INLINE_MAPPING_OBJECT, $script_variables );
455
  }
456
 
457
  $tab = self::mla_get_options_tablist( $tab ) ? '-' . $tab : '-general';
458
+ 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', MLACore::MLA_SETTINGS_SLUG . $tab, 'MLASettings::mla_render_settings_page' );
459
  add_action( 'load-' . self::$current_page_hook, 'MLASettings::mla_add_menu_options_action' );
460
  add_action( 'load-' . self::$current_page_hook, 'MLASettings::mla_add_help_tab_action' );
461
  add_filter( 'plugin_action_links', 'MLASettings::mla_add_plugin_settings_link_filter', 10, 2 );
519
  /*
520
  * Is this our page and the Views or Uploads tab?
521
  */
522
+ if ( ! in_array( $screen->id, array( 'settings_page_' . MLACore::MLA_SETTINGS_SLUG . '-view', 'settings_page_' . MLACore::MLA_SETTINGS_SLUG . '-upload' ) ) ) {
523
  return;
524
  }
525
 
629
  public static function mla_inline_edit_view_action() {
630
  set_current_screen( $_REQUEST['screen'] );
631
 
632
+ check_ajax_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
633
 
634
  if ( empty( $_REQUEST['original_slug'] ) ) {
635
  echo __( 'ERROR', 'media-library-assistant' ) . ': ' . __( 'No view slug found', 'media-library-assistant' );
672
  public static function mla_inline_edit_upload_action() {
673
  set_current_screen( $_REQUEST['screen'] );
674
 
675
+ check_ajax_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
676
 
677
  if ( empty( $_REQUEST['original_slug'] ) ) {
678
  echo __( 'ERROR', 'media-library-assistant' ) . ': ' . __( 'No upload slug found', 'media-library-assistant' );
708
  */
709
  public static function mla_inline_mapping_custom_action() {
710
  set_current_screen( $_REQUEST['screen'] );
711
+ check_ajax_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
712
 
713
  /*
714
  * Convert the ajax bulk_action back to the older Submit button equivalent
784
  }
785
  }
786
 
787
+ $current_values = MLACore::mla_get_option( 'custom_field_mapping' );
788
  $settings = array( $value['name'] => $current_values[$value['name']] );
789
  $map_content = self::_process_custom_field_mapping( $settings, $offset, $length );
790
  $page_content['message'] .= '<br>&nbsp;<br>' . $map_content['message'];
831
  */
832
  public static function mla_inline_mapping_iptc_exif_action() {
833
  set_current_screen( $_REQUEST['screen'] );
834
+ check_ajax_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
835
 
836
  /*
837
  * Convert the ajax bulk_action back to the older Submit button equivalent
918
  }
919
  }
920
 
921
+ $current_values = MLACore::mla_get_option( 'iptc_exif_mapping' );
922
  $settings = array( 'custom' => array( $value['name'] => $current_values['custom'][$value['name']] ) );
923
  $map_content = self::_process_iptc_exif_custom( $settings, $offset, $length );
924
  $page_content['message'] .= '<br>&nbsp;<br>' . $map_content['message'];
968
  */
969
  public static function mla_add_plugin_settings_link_filter( $links, $file ) {
970
  if ( $file == 'media-library-assistant/index.php' ) {
971
+ $settings_link = sprintf( '<a href="%s">%s</a>', admin_url( 'options-general.php?page=' . MLACore::MLA_SETTINGS_SLUG . '-general' ), __( 'Settings', 'media-library-assistant' ) );
972
  array_unshift( $links, $settings_link );
973
  }
974
 
992
  $message = '<br>update_option(' . $key . ")\r\n";
993
  switch ( $value['type'] ) {
994
  case 'checkbox':
995
+ MLACore::mla_update_option( $key, 'checked', $option_table );
996
  break;
997
  case 'header':
998
  case 'subheader':
999
  $message = '';
1000
  break;
1001
  case 'radio':
1002
+ MLACore::mla_update_option( $key, $_REQUEST[ MLA_OPTION_PREFIX . $key ], $option_table );
1003
  break;
1004
  case 'select':
1005
+ MLACore::mla_update_option( $key, $_REQUEST[ MLA_OPTION_PREFIX . $key ], $option_table );
1006
  break;
1007
  case 'text':
1008
+ MLACore::mla_update_option( $key, stripslashes( trim( $_REQUEST[ MLA_OPTION_PREFIX . $key ], $option_table ) ) );
1009
  break;
1010
  case 'textarea':
1011
+ MLACore::mla_update_option( $key, stripslashes( trim( $_REQUEST[ MLA_OPTION_PREFIX . $key ], $option_table ) ) );
1012
  break;
1013
  case 'custom':
1014
  $message = MLAOptions::$value['update']( 'update', $key, $value, $_REQUEST );
1025
  switch ( $value['type'] ) {
1026
  case 'checkbox':
1027
  $message = '<br>uncheck_option(' . $key . ')';
1028
+ MLACore::mla_update_option( $key, 'unchecked', $option_table );
1029
  break;
1030
  case 'header':
1031
  case 'subheader':
1032
  $message = '';
1033
  break;
1034
  case 'radio':
1035
+ MLACore::mla_delete_option( $key, $option_table );
1036
  break;
1037
  case 'select':
1038
+ MLACore::mla_delete_option( $key, $option_table );
1039
  break;
1040
  case 'text':
1041
+ MLACore::mla_delete_option( $key, $option_table );
1042
  break;
1043
  case 'textarea':
1044
+ MLACore::mla_delete_option( $key, $option_table );
1045
  break;
1046
  case 'custom':
1047
  $message = MLAOptions::$value['delete']( 'delete', $key, $value, $_REQUEST );
1079
  'help' => $value['help']
1080
  );
1081
 
1082
+ if ( 'checked' == MLACore::mla_get_option( $key, false, false, $option_table ) ) {
1083
  $option_values['checked'] = 'checked="checked"';
1084
  }
1085
 
1103
  'value' => $value['texts'][$optid]
1104
  );
1105
 
1106
+ if ( $option == MLACore::mla_get_option( $key, false, false, $option_table ) ) {
1107
  $option_values['checked'] = 'checked="checked"';
1108
  }
1109
 
1126
  'text' => $value['texts'][$optid]
1127
  );
1128
 
1129
+ if ( $option == MLACore::mla_get_option( $key, false, false, $option_table ) ) {
1130
  $option_values['selected'] = 'selected="selected"';
1131
  }
1132
 
1154
  $option_values['size'] = $value['size'];
1155
  }
1156
 
1157
+ $option_values['text'] = MLACore::mla_get_option( $key, false, false, $option_table );
1158
 
1159
  return MLAData::mla_parse_template( self::$page_template_array['text'], $option_values );
1160
  case 'textarea':
1176
  $option_values['rows'] = $value['rows'];
1177
  }
1178
 
1179
+ $option_values['text'] = stripslashes( MLACore::mla_get_option( $key, false, false, $option_table ) );
1180
 
1181
  return MLAData::mla_parse_template( self::$page_template_array['textarea'], $option_values );
1182
  case 'custom':
1205
  *
1206
  * @var array
1207
  */
1208
+ public static $page_template_array = NULL;
1209
 
1210
  /**
1211
  * Definitions for Settings page tab ids, titles and handlers
1297
  $item_values = array(
1298
  'data-tab-id' => $key,
1299
  'nav-tab-active' => ( $active_tab == $key ) ? 'nav-tab-active' : '',
1300
+ 'settings-page' => MLACore::MLA_SETTINGS_SLUG . '-' . $key,
1301
  'title' => $item['title']
1302
  );
1303
 
1322
  * Initialize page messages and content.
1323
  */
1324
  if ( !empty( $_REQUEST['mla-general-options-save'] ) ) {
1325
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
1326
  $page_content = self::_save_general_settings( );
1327
  } elseif ( !empty( $_REQUEST['mla-general-options-export'] ) ) {
1328
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
1329
  $page_content = self::_export_settings( );
1330
  } elseif ( !empty( $_REQUEST['mla-general-options-import'] ) ) {
1331
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
1332
  $page_content = self::_import_settings( );
1333
  } elseif ( !empty( $_REQUEST['mla-general-options-reset'] ) ) {
1334
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
1335
  $page_content = self::_reset_general_settings( );
1336
  } else {
1337
  $page_content = array(
1351
  'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
1352
  'Export ALL Settings' => __( 'Export ALL Settings', 'media-library-assistant' ),
1353
  'Delete General options' => __( 'Delete General options and restore default settings', 'media-library-assistant' ),
1354
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
1355
  '_wp_http_referer' => wp_referer_field( false ),
1356
  'Go to Top' => __( 'Go to Top', 'media-library-assistant' ),
1357
  'Support Our Work' => __( 'Support Our Work', 'media-library-assistant' ),
1378
  $shortcodes = array(
1379
  // array("name" => "shortcode", "description" => "This shortcode...")
1380
  // array( 'name' => 'mla_attachment_list', 'description' => __( 'renders a complete list of all attachments and references to them.', 'media-library-assistant' ) ),
1381
+ array( 'name' => 'mla_gallery', 'description' => __( 'enhanced version of the WordPress [gallery] shortcode.', 'media-library-assistant' ) . sprintf( ' %1$s <a href="%2$s">%3$s</a>.', __( 'For complete documentation', 'media-library-assistant' ), admin_url( 'options-general.php?page=' . MLACore::MLA_SETTINGS_SLUG . '-documentation&amp;mla_tab=documentation#mla_gallery' ), __( 'click here', 'media-library-assistant' ) ) ),
1382
+ array( 'name' => 'mla_tag_cloud', 'description' => __( 'enhanced version of the WordPress Tag Cloud.', 'media-library-assistant' ) . sprintf( ' %1$s <a href="%2$s">%3$s</a>.', __( 'For complete documentation', 'media-library-assistant' ), admin_url( 'options-general.php?page=' . MLACore::MLA_SETTINGS_SLUG . '-documentation&amp;mla_tab=documentation#mla_tag_cloud' ), __( 'click here', 'media-library-assistant' ) ) )
1383
  );
1384
 
1385
  $shortcode_list = '';
1401
  * Make sure the current choice still exists or revert to default.
1402
  */
1403
  $columns = array();
1404
+ foreach ( MLAQuery::mla_get_sortable_columns( ) as $key => $value ) {
1405
  if ( ! array_key_exists( $value[1], $columns ) ) {
1406
  $columns[ $value[1] ] = $value[0];
1407
  }
1409
 
1410
  uksort( $columns, 'strnatcasecmp' );
1411
  $options = array_merge( array('None' => 'none'), $columns );
1412
+ $current = MLACore::mla_get_option( MLACore::MLA_DEFAULT_ORDERBY );
1413
+ MLACore::$mla_option_definitions[MLACore::MLA_DEFAULT_ORDERBY]['options'] = array();
1414
+ MLACore::$mla_option_definitions[MLACore::MLA_DEFAULT_ORDERBY]['texts'] = array();
1415
  $found_current = false;
1416
  foreach ($options as $key => $value ) {
1417
+ MLACore::$mla_option_definitions[MLACore::MLA_DEFAULT_ORDERBY]['options'][] = $value;
1418
+ MLACore::$mla_option_definitions[MLACore::MLA_DEFAULT_ORDERBY]['texts'][] = $key;
1419
  if ( $current == $value ) {
1420
  $found_current = true;
1421
  }
1422
  }
1423
 
1424
  if ( ! $found_current ) {
1425
+ MLACore::mla_delete_option( MLACore::MLA_DEFAULT_ORDERBY );
1426
  }
1427
 
1428
  /*
1429
  * Validate the Media Manager sort order or revert to default
1430
  */
1431
  $options = array_merge( array('&mdash; ' . __( 'Media Manager Default', 'media-library-assistant' ) . ' &mdash;' => 'default', 'None' => 'none'), $columns );
1432
+ $current = MLACore::mla_get_option( MLACore::MLA_MEDIA_MODAL_ORDERBY );
1433
+ MLACore::$mla_option_definitions[MLACore::MLA_MEDIA_MODAL_ORDERBY]['options'] = array();
1434
+ MLACore::$mla_option_definitions[MLACore::MLA_MEDIA_MODAL_ORDERBY]['texts'] = array();
1435
  $found_current = false;
1436
  foreach ($options as $key => $value ) {
1437
+ MLACore::$mla_option_definitions[MLACore::MLA_MEDIA_MODAL_ORDERBY]['options'][] = $value;
1438
+ MLACore::$mla_option_definitions[MLACore::MLA_MEDIA_MODAL_ORDERBY]['texts'][] = $key;
1439
  if ( $current == $value ) {
1440
  $found_current = true;
1441
  }
1442
  }
1443
 
1444
  if ( ! $found_current ) {
1445
+ MLACore::mla_delete_option( MLACore::MLA_MEDIA_MODAL_ORDERBY );
1446
  }
1447
 
1448
  $options_list = '';
1449
+ foreach ( MLACore::$mla_option_definitions as $key => $value ) {
1450
  if ( 'general' == $value['tab'] ) {
1451
  $options_list .= self::mla_compose_option_row( $key, $value );
1452
  }
1503
  'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-view&mla_tab=view',
1504
  'action' => MLA::MLA_ADMIN_SINGLE_EDIT_UPDATE,
1505
  'original_slug' => $view['slug'],
1506
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
1507
  'Slug' => __( 'Slug', 'media-library-assistant' ),
1508
  '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' ),
1509
  'Singular Label' => __( 'Singular Label', 'media-library-assistant' ),
1578
  );
1579
 
1580
  if ( !empty( $_REQUEST['mla-view-options-save'] ) ) {
1581
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
1582
  $page_content = self::_save_view_settings( );
1583
  } elseif ( !empty( $_REQUEST['mla-add-view-submit'] ) ) {
1584
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
1585
  $page_content = MLAMime::mla_add_post_mime_type( $_REQUEST['mla_view_item'] );
1586
  if ( false !== strpos( $page_content['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
1587
  $add_form_values = $_REQUEST['mla_view_item'];
1647
  * Process row-level actions that affect a single item
1648
  */
1649
  if ( !empty( $_REQUEST['mla_admin_action'] ) ) {
1650
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
1651
 
1652
  switch ( $_REQUEST['mla_admin_action'] ) {
1653
+ case MLACore::MLA_ADMIN_SINGLE_DELETE:
1654
  $page_content = MLAMime::mla_delete_post_mime_type( $_REQUEST['mla_item_slug'] );
1655
  break;
1656
  case MLA::MLA_ADMIN_SINGLE_EDIT_DISPLAY:
1690
  /*
1691
  * Check for disabled status
1692
  */
1693
+ if ( 'checked' != MLACore::mla_get_option( MLACore::MLA_ENABLE_POST_MIME_TYPES ) ) {
1694
  /*
1695
  * Fill in with any page-level options
1696
  */
1697
  $options_list = '';
1698
+ foreach ( MLACore::$mla_option_definitions as $key => $value ) {
1699
  if ( 'view' == $value['tab'] ) {
1700
  $options_list .= self::mla_compose_option_row( $key, $value );
1701
  }
1706
  'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-view&mla_tab=view',
1707
  'options_list' => $options_list,
1708
  'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
1709
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
1710
  );
1711
 
1712
  $page_content['body'] .= MLAData::mla_parse_template( $page_template_array['view-disabled'], $page_values );
1740
  * Start with any page-level options
1741
  */
1742
  $options_list = '';
1743
+ foreach ( MLACore::$mla_option_definitions as $key => $value ) {
1744
  if ( 'view' == $value['tab'] ) {
1745
  $options_list .= self::mla_compose_option_row( $key, $value );
1746
  }
1753
  '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>' ),
1754
  'settingsURL' => admin_url('options-general.php'),
1755
  'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-view&mla_tab=view',
1756
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
1757
  'results' => ! empty( $_REQUEST['s'] ) ? '<h2 class="alignleft">' . __( 'Displaying search results for', 'media-library-assistant' ) . ': "' . $_REQUEST['s'] . '"</h2>' : '',
1758
  'Search Views' => __( 'Search Views', 'media-library-assistant' ),
1759
  's' => isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '',
1862
  'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-upload&mla_tab=upload',
1863
  'action' => MLA::MLA_ADMIN_SINGLE_EDIT_UPDATE,
1864
  'original_slug' => $item['slug'],
1865
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
1866
  'Extension' => __( 'Extension', 'media-library-assistant' ),
1867
  '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' ),
1868
  'MIME Type' => __( 'MIME Type', 'media-library-assistant' ),
1941
 
1942
  $page_values = array(
1943
  'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-upload&mla_tab=upload',
1944
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
1945
  'Known File Extension' => __( 'Known File Extension/MIME Type Associations', 'media-library-assistant' ),
1946
  'results' => ! empty( $_REQUEST['s'] ) ? '<h2 class="alignleft">' . __( 'Displaying search results for', 'media-library-assistant' ) . ': "' . $_REQUEST['s'] . '"</h2>' : '',
1947
  'Search Known MIME' => __( 'Search Known MIME Types', 'media-library-assistant' ),
2029
  );
2030
 
2031
  if ( !empty( $_REQUEST['mla-upload-options-save'] ) ) {
2032
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
2033
  $page_content = self::_save_upload_settings( );
2034
  } elseif ( !empty( $_REQUEST['mla-optional-uploads-search'] ) ) {
2035
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
2036
  $page_content = self::_compose_optional_upload_tab( $page_template_array );
2037
  } elseif ( !empty( $_REQUEST['mla-optional-uploads-cancel'] ) ) {
2038
  $page_content = array(
2041
  );
2042
  } elseif ( !empty( $_REQUEST['mla-optional-uploads-display'] ) ) {
2043
  if ( 'true' != $_REQUEST['mla-optional-uploads-display'] ) {
2044
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
2045
  unset( $_REQUEST['s'] );
2046
  }
2047
  $page_content = self::_compose_optional_upload_tab( $page_template_array );
2048
  } elseif ( !empty( $_REQUEST['mla-add-upload-submit'] ) ) {
2049
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
2050
  $page_content = MLAMime::mla_add_upload_mime( $_REQUEST['mla_upload_item'] );
2051
  if ( false !== strpos( $page_content['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
2052
  $add_form_values = $_REQUEST['mla_upload_item'];
2114
  * Process row-level actions that affect a single item
2115
  */
2116
  if ( !empty( $_REQUEST['mla_admin_action'] ) ) {
2117
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
2118
 
2119
  switch ( $_REQUEST['mla_admin_action'] ) {
2120
+ case MLACore::MLA_ADMIN_SINGLE_DELETE:
2121
  $page_content = MLAMime::mla_delete_upload_mime( $_REQUEST['mla_item_slug'] );
2122
  break;
2123
  case MLA::MLA_ADMIN_SINGLE_EDIT_DISPLAY:
2159
  /*
2160
  * Check for disabled status
2161
  */
2162
+ if ( 'checked' != MLACore::mla_get_option( MLACore::MLA_ENABLE_UPLOAD_MIMES ) ) {
2163
  /*
2164
  * Fill in with any page-level options
2165
  */
2166
  $options_list = '';
2167
+ foreach ( MLACore::$mla_option_definitions as $key => $value ) {
2168
  if ( 'upload' == $value['tab'] ) {
2169
  $options_list .= self::mla_compose_option_row( $key, $value );
2170
  }
2175
  'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-upload&mla_tab=upload',
2176
  'options_list' => $options_list,
2177
  'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
2178
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
2179
  );
2180
 
2181
  $page_content['body'] .= MLAData::mla_parse_template( $page_template_array['upload-disabled'], $page_values );
2207
  * Start with any page-level options
2208
  */
2209
  $options_list = '';
2210
+ foreach ( MLACore::$mla_option_definitions as $key => $value ) {
2211
  if ( 'upload' == $value['tab'] ) {
2212
  $options_list .= self::mla_compose_option_row( $key, $value );
2213
  }
2222
  'Search Uploads' => __( 'Search Uploads', 'media-library-assistant' ),
2223
  'To search by' => __( 'To search by extension, use ".", e.g., ".doc"', 'media-library-assistant' ),
2224
  'form_url' => admin_url( 'options-general.php' ) . '?page=mla-settings-menu-upload&mla_tab=upload',
2225
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
2226
  'options_list' => $options_list,
2227
  'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
2228
  /* translators: %s: add new Upload MIME Type */
2239
  'Description' => __( 'Description', 'media-library-assistant' ),
2240
  'The description can' => __( 'The description can contain any documentation or notes you need to understand or use the item.', 'media-library-assistant' ),
2241
  'Add Upload MIME' => __( 'Add Upload MIME Type', 'media-library-assistant' ),
2242
+ '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 ),
2243
  'Search Known Types' => __( 'Search Known Types', 'media-library-assistant' ),
2244
  'colspan' => $MLAListUploadTable->get_column_count(),
2245
  'Quick Edit' => __( '<strong>Quick Edit</strong>', 'media-library-assistant' ),
2287
  * Initialize page messages and content.
2288
  */
2289
  if ( !empty( $_REQUEST['mla-gallery-options-save'] ) ) {
2290
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
2291
  $page_content = self::_save_gallery_settings( );
2292
  } else {
2293
  $page_content = array(
2294
+ 'message' => '',
2295
  'body' => ''
2296
  );
2297
  }
2313
  'Markup Templates' => __( 'Markup Templates', 'media-library-assistant' ),
2314
  'markup_options_list' => '',
2315
  'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
2316
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
2317
  '_wp_http_referer' => wp_referer_field( false )
2318
  );
2319
 
2320
  /*
2321
  * Build default template selection lists; leave out the [mla_tag_cloud] templates
2322
  */
2323
+ MLACore::$mla_option_definitions['default_style']['options'][] = 'none';
2324
+ MLACore::$mla_option_definitions['default_style']['texts'][] = '&mdash; ' . __( 'None', 'media-library-assistant' ) . ' &mdash;';
2325
+ MLACore::$mla_option_definitions['default_style']['options'][] = 'theme';
2326
+ MLACore::$mla_option_definitions['default_style']['texts'][] = '&mdash; ' . __( 'Theme', 'media-library-assistant' ) . ' &mdash;';
2327
 
2328
  $templates = MLAOptions::mla_get_style_templates();
2329
  ksort($templates);
2332
  continue;
2333
  }
2334
 
2335
+ MLACore::$mla_option_definitions['default_style']['options'][] = $key;
2336
+ MLACore::$mla_option_definitions['default_style']['texts'][] = $key;
2337
  }
2338
 
2339
  $templates = MLAOptions::mla_get_markup_templates();
2343
  continue;
2344
  }
2345
 
2346
+ MLACore::$mla_option_definitions['default_markup']['options'][] = $key;
2347
+ MLACore::$mla_option_definitions['default_markup']['texts'][] = $key;
2348
  }
2349
 
2350
  /*
2357
  $not_supported_warning = '';
2358
  }
2359
 
2360
+ $ghostscript_path = MLACore::mla_get_option( 'ghostscript_path' );
2361
+ if ( ! MLAShortcode_Support::mla_ghostscript_present( $ghostscript_path, true ) ) {
2362
  $not_supported_warning .= '<br>&nbsp;&nbsp;' . __( 'Ghostscript support is not installed.', 'media-library-assistant' );
2363
  }
2364
 
2365
  if ( ! empty( $not_supported_warning ) ) {
2366
+ MLACore::$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;
2367
  }
2368
 
2369
  /*
2370
  * Start with any page-level options
2371
  */
2372
  $options_list = '';
2373
+ foreach ( MLACore::$mla_option_definitions as $key => $value ) {
2374
  if ( 'mla_gallery' == $value['tab'] ) {
2375
  $options_list .= self::mla_compose_option_row( $key, $value );
2376
  }
2657
  * Initialize page messages and content.
2658
  */
2659
  if ( isset( $_REQUEST['custom_field_mapping'] ) && is_array( $_REQUEST['custom_field_mapping'] ) ) {
2660
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
2661
 
2662
  /*
2663
  * Check for page-level submit buttons to change settings or map attachments.
2669
  $page_content = self::_process_custom_field_mapping( );
2670
  } else {
2671
  $page_content = array(
2672
+ 'message' => '',
2673
  'body' => ''
2674
  );
2675
 
2701
  case 'add_field_map':
2702
  $page_content = self::_save_custom_field_settings( $settings );
2703
  if ( false === strpos( $page_content['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
2704
+ $current_values = MLACore::mla_get_option( 'custom_field_mapping' );
2705
  $settings = array( $value['name'] => $current_values[$value['name']] );
2706
  $map_content = self::_process_custom_field_mapping( $settings );
2707
  $page_content['message'] .= '<br>&nbsp;<br>' . $map_content['message'];
2717
  } // isset custom_field_mapping
2718
  else {
2719
  $page_content = array(
2720
+ 'message' => '',
2721
  'body' => ''
2722
  );
2723
  }
2760
  '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>' ),
2761
  /* translators: 1: "Map All Rules..." */
2762
  '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>' ),
2763
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
2764
  '_wp_http_referer' => wp_referer_field( false )
2765
  );
2766
 
2768
  * Start with any page-level options
2769
  */
2770
  $options_list = '';
2771
+ foreach ( MLACore::$mla_option_definitions as $key => $value ) {
2772
  if ( 'custom_field' == $value['tab'] ) {
2773
  $options_list .= self::mla_compose_option_row( $key, $value );
2774
  }
2779
  /*
2780
  * Add mapping options
2781
  */
2782
+ $page_values['custom_options_list'] = MLAOptions::mla_custom_field_option_handler( 'render', 'custom_field_mapping', MLACore::$mla_option_definitions['custom_field_mapping'] );
2783
 
2784
  $page_content['body'] = MLAData::mla_parse_template( self::$page_template_array['custom-field-tab'], $page_values );
2785
  return $page_content;
2804
  );
2805
 
2806
  if ( isset( $_REQUEST['iptc_exif_mapping'] ) && is_array( $_REQUEST['iptc_exif_mapping'] ) ) {
2807
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
2808
 
2809
  if ( !empty( $_REQUEST['iptc-exif-options-save'] ) ) {
2810
  $page_content = self::_save_iptc_exif_settings( );
2843
  case 'add_field_map':
2844
  $page_content = self::_save_iptc_exif_custom_settings( $settings );
2845
  if ( false === strpos( $page_content['message'], __( 'ERROR', 'media-library-assistant' ) ) ) {
2846
+ $current_values = MLACore::mla_get_option( 'iptc_exif_mapping' );
2847
  $settings = array( 'custom' => array( $value['name'] => $current_values['custom'][$value['name']] ) );
2848
  $map_content = self::_process_iptc_exif_custom( $settings );
2849
  $page_content['message'] .= '<br>&nbsp;<br>' . $map_content['message'];
2899
  'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
2900
  /* translators: 1: "Save Changes" */
2901
  '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>' ),
2902
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
2903
  '_wp_http_referer' => wp_referer_field( false )
2904
  );
2905
 
2907
  * Start with any page-level options
2908
  */
2909
  $options_list = '';
2910
+ foreach ( MLACore::$mla_option_definitions as $key => $value ) {
2911
  if ( 'iptc_exif' == $value['tab'] ) {
2912
  $options_list .= self::mla_compose_option_row( $key, $value );
2913
  }
2918
  /*
2919
  * Add mapping options
2920
  */
2921
+ $page_values['standard_options_list'] = MLAOptions::mla_iptc_exif_option_handler( 'render', 'iptc_exif_standard_mapping', MLACore::$mla_option_definitions['iptc_exif_standard_mapping'] );
2922
 
2923
+ $page_values['taxonomy_options_list'] = MLAOptions::mla_iptc_exif_option_handler( 'render', 'iptc_exif_taxonomy_mapping', MLACore::$mla_option_definitions['iptc_exif_taxonomy_mapping'] );
2924
 
2925
+ $page_values['custom_options_list'] = MLAOptions::mla_iptc_exif_option_handler( 'render', 'iptc_exif_custom_mapping', MLACore::$mla_option_definitions['iptc_exif_custom_mapping'] );
2926
 
2927
  $page_content['body'] = MLAData::mla_parse_template( self::$page_template_array['iptc-exif-tab'], $page_values );
2928
  return $page_content;
2962
  private static function _save_debug_settings( ) {
2963
  $message_list = '';
2964
 
2965
+ foreach ( MLACore::$mla_option_definitions as $key => $value ) {
2966
  if ( 'debug' == $value['tab'] ) {
2967
  $message_list .= self::mla_update_option_row( $key, $value );
2968
  } // view option
3021
  * Saving the options can change the log file name, so do it first
3022
  */
3023
  if ( !empty( $_REQUEST['mla-debug-options-save'] ) ) {
3024
+ check_admin_referer( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME );
3025
  $page_content = self::_save_debug_settings();
3026
  }
3027
 
3028
  /*
3029
  * Find the appropriate error log file
3030
  */
3031
+ $error_log_name = MLACore::mla_get_option( MLACore::MLA_DEBUG_FILE );
3032
  if ( empty( $error_log_name ) ) {
3033
  $error_log_name = ini_get( 'error_log' );
3034
  } else {
3075
  * Start with any page-level options
3076
  */
3077
  $options_list = '';
3078
+ foreach ( MLACore::$mla_option_definitions as $key => $value ) {
3079
  if ( 'debug' == $value['tab'] ) {
3080
  $options_list .= self::mla_compose_option_row( $key, $value );
3081
  }
3084
  /*
3085
  * Gather Debug Settings
3086
  */
3087
+ $display_limit = MLACore::mla_get_option( MLACore::MLA_DEBUG_DISPLAY_LIMIT );
3088
+ $debug_file = MLACore::mla_get_option( MLACore::MLA_DEBUG_FILE );
3089
+ $replace_php = MLACore::mla_get_option( MLACore::MLA_DEBUG_REPLACE_PHP_LOG );
3090
+ $php_reporting = MLACore::mla_get_option( MLACore::MLA_DEBUG_REPLACE_PHP_REPORTING );
3091
+ $mla_reporting = MLACore::mla_get_option( MLACore::MLA_DEBUG_REPLACE_LEVEL );
3092
 
3093
  if ( $error_log_exists ) {
3094
  /*
3095
  * Add debug content
3096
  */
3097
+ $display_limit = absint( MLACore::mla_get_option( MLACore::MLA_DEBUG_DISPLAY_LIMIT ) );
3098
  $error_log_size = filesize( $error_log_name );
3099
 
3100
  if ( 0 < $display_limit ) {
3136
  if ( current_user_can( 'upload_files' ) ) {
3137
  if ( $error_log_exists ) {
3138
  $args = array(
3139
+ 'page' => MLACore::ADMIN_PAGE_SLUG,
3140
  'mla_download_file' => urlencode( $error_log_name ),
3141
  'mla_download_type' => 'text/plain'
3142
  );
3143
+ $download_link = '<a class="button-secondary" 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;' . __( 'Error Log', 'media-library-assistant' ) . '&#8221;">' . __( 'Download', 'media-library-assistant' ) . '</a>';
3144
  } else {
3145
  $download_link = '';
3146
  }
3150
  'mla_tab' => 'debug',
3151
  'mla_reset_log' => 'true'
3152
  );
3153
+ $reset_link = '<a class="button-secondary" href="' . add_query_arg( $args, wp_nonce_url( 'options-general.php', MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ) ) . '" title="' . __( 'Reset', 'media-library-assistant' ) . ' &#8220;' . __( 'Error Log', 'media-library-assistant' ) . '&#8221;">' . __( 'Reset', 'media-library-assistant' ) . '</a>';
3154
  }
3155
 
3156
  $settings_list = self::_compose_settings_row( 'Display Limit', $display_limit );
3159
  $settings_list .= self::_compose_settings_row( 'PHP Reporting', $php_reporting );
3160
  $settings_list .= self::_compose_settings_row( 'MLA Reporting', $mla_reporting );
3161
  $settings_list .= self::_compose_settings_row( 'MLA_DEBUG_LEVEL', sprintf( '0x%1$04X', MLA_DEBUG_LEVEL ) );
3162
+ $settings_list .= self::_compose_settings_row( 'PHP error_reporting', MLACore::$original_php_reporting );
3163
+ $settings_list .= self::_compose_settings_row( 'Old PHP error_log', MLACore::$original_php_log );
3164
  $settings_list .= self::_compose_settings_row( 'New PHP error_log', ini_get( 'error_log' ) );
3165
  $settings_list .= self::_compose_settings_row( 'WP_DEBUG', WP_DEBUG ? 'true' : 'false' );
3166
  $settings_list .= self::_compose_settings_row( 'WP_DEBUG_LOG', WP_DEBUG_LOG ? 'true' : 'false' );
3185
  'Save Changes' => __( 'Save Changes', 'media-library-assistant' ),
3186
  /* translators: 1: "Save Changes" */
3187
  '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' ) ),
3188
+ '_wpnonce' => wp_nonce_field( MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME, true, false ),
3189
  '_wp_http_referer' => wp_referer_field( false )
3190
  );
3191
 
3274
  /*
3275
  * Start with any page-level options
3276
  */
3277
+ foreach ( MLACore::$mla_option_definitions as $key => $value ) {
3278
  if ( 'mla_gallery' == $value['tab'] ) {
3279
  if ( 'select' == $value['type'] ) {
3280
+ $old_value = MLACore::mla_get_option( $key );
3281
  if ( $old_value != $_REQUEST[ MLA_OPTION_PREFIX . $key ] ) {
3282
  $settings_changed = true;
3283
  $message_list .= self::mla_update_option_row( $key, $value );
3287
  $_REQUEST[ MLA_OPTION_PREFIX . $key ] = $value['std'];
3288
  }
3289
 
3290
+ $old_value = MLACore::mla_get_option( $key );
3291
  if ( $old_value != $_REQUEST[ MLA_OPTION_PREFIX . $key ] ) {
3292
  $settings_changed = true;
3293
  $message_list .= self::mla_update_option_row( $key, $value );
3294
  }
3295
  } elseif ( 'checkbox' == $value['type'] ) {
3296
+ $old_value = MLACore::mla_get_option( $key );
3297
  if ( isset( $_REQUEST[ MLA_OPTION_PREFIX . $key ] ) ) {
3298
  $checkbox_changed = "checked" != $old_value;
3299
  } else {
3547
  private static function _save_view_settings( ) {
3548
  $message_list = '';
3549
 
3550
+ foreach ( MLACore::$mla_option_definitions as $key => $value ) {
3551
  if ( 'view' == $value['tab'] ) {
3552
  $message_list .= self::mla_update_option_row( $key, $value );
3553
  } // view option
3578
  private static function _save_upload_settings( ) {
3579
  $message_list = '';
3580
 
3581
+ if ( ! isset( $_REQUEST[ MLA_OPTION_PREFIX . MLACore::MLA_ENABLE_UPLOAD_MIMES ] ) )
3582
+ unset( $_REQUEST[ MLA_OPTION_PREFIX . MLACore::MLA_ENABLE_MLA_ICONS ] );
3583
 
3584
+ foreach ( MLACore::$mla_option_definitions as $key => $value ) {
3585
  if ( 'upload' == $value['tab'] ) {
3586
  $message_list .= self::mla_update_option_row( $key, $value );
3587
  } // upload option
3618
  if ( NULL == $settings ) {
3619
  $source = 'custom_fields';
3620
  $settings = ( isset( $_REQUEST['custom_field_mapping'] ) ) ? stripslashes_deep( $_REQUEST['custom_field_mapping'] ) : array();
3621
+ if ( isset( $settings[ MLACore::MLA_NEW_CUSTOM_FIELD ] ) ) {
3622
+ unset( $settings[ MLACore::MLA_NEW_CUSTOM_FIELD ] );
3623
  }
3624
+ if ( isset( $settings[ MLACore::MLA_NEW_CUSTOM_RULE ] ) ) {
3625
+ unset( $settings[ MLACore::MLA_NEW_CUSTOM_RULE ] );
3626
  }
3627
  } else {
3628
  $source = 'custom_rule';
3632
  if ( empty( $settings ) ) {
3633
  return array(
3634
  'message' => __( 'ERROR', 'media-library-assistant' ) . ': ' . __( 'No custom field mapping rules to process.', 'media-library-assistant' ),
3635
+ 'body' => '' ,
3636
+ 'processed' => 0,
3637
+ 'unchanged' => 0,
3638
+ 'success' => 0
3639
  );
3640
  }
3641
 
3724
  /*
3725
  * Start with any page-level options
3726
  */
3727
+ foreach ( MLACore::$mla_option_definitions as $key => $value ) {
3728
  if ( 'custom_field' == $value['tab'] ) {
3729
  $option_messages .= self::mla_update_option_row( $key, $value );
3730
  }
3742
  // $message_list = $option_messages . '<br>';
3743
 
3744
  return array(
3745
+ 'message' => $message_list . MLAOptions::mla_custom_field_option_handler( 'update', 'custom_field_mapping', MLACore::$mla_option_definitions['custom_field_mapping'], $new_values ),
3746
  'body' => ''
3747
  );
3748
  } // _save_custom_field_settings
3765
  return array(
3766
  /* translators: 1: ERROR tag 2: field type */
3767
  'message' => sprintf( __( '%1$s: No %2$s settings to process.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'Standard field', 'media-library-assistant' ) ),
3768
+ 'body' => '',
3769
+ 'processed' => 0,
3770
+ 'unchanged' => 0,
3771
+ 'success' => 0,
3772
  );
3773
  }
3774
 
3781
  $query['offset'] = $offset;
3782
  }
3783
 
3784
+ do_action( 'mla_begin_mapping', 'iptc_exif_standard', NULL );
3785
  $posts = MLAShortcodes::mla_get_shortcode_attachments( 0, $query );
3786
 
3787
  if ( is_string( $posts ) ) {
3791
  );
3792
  }
3793
 
 
3794
  foreach ( $posts as $key => $post ) {
3795
  $updates = MLAOptions::mla_evaluate_iptc_exif_mapping( $post, 'iptc_exif_standard_mapping', $_REQUEST['iptc_exif_mapping'] );
3796
 
3839
  return array(
3840
  /* translators: 1: ERROR tag 2: field type */
3841
  'message' => sprintf( __( '%1$s: No %2$s settings to process.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'Taxonomy term', 'media-library-assistant' ) ),
3842
+ 'body' => '',
3843
+ 'processed' => 0,
3844
+ 'unchanged' => 0,
3845
+ 'success' => 0,
3846
  );
3847
  }
3848
 
3855
  $query['offset'] = $offset;
3856
  }
3857
 
3858
+ do_action( 'mla_begin_mapping', 'iptc_exif_taxonomy', NULL );
3859
  $posts = MLAShortcodes::mla_get_shortcode_attachments( 0, $query );
3860
 
3861
  if ( is_string( $posts ) ) {
3865
  );
3866
  }
3867
 
 
3868
  foreach ( $posts as $key => $post ) {
3869
  $updates = MLAOptions::mla_evaluate_iptc_exif_mapping( $post, 'iptc_exif_taxonomy_mapping', $_REQUEST['iptc_exif_mapping'] );
3870
 
3913
  if ( NULL == $settings ) {
3914
  $source = 'iptc_exif_custom';
3915
  $settings = ( isset( $_REQUEST['iptc_exif_mapping'] ) ) ? stripslashes_deep( $_REQUEST['iptc_exif_mapping'] ) : array();
3916
+ if ( isset( $settings['custom'][ MLACore::MLA_NEW_CUSTOM_FIELD ] ) ) {
3917
+ unset( $settings['custom'][ MLACore::MLA_NEW_CUSTOM_FIELD ] );
3918
  }
3919
+ if ( isset( $settings['custom'][ MLACore::MLA_NEW_CUSTOM_RULE ] ) ) {
3920
+ unset( $settings['custom'][ MLACore::MLA_NEW_CUSTOM_RULE ] );
3921
  }
3922
  } else {
3923
  $source = 'iptc_exif_custom_rule';
3928
  return array(
3929
  /* translators: 1: ERROR tag 2: field type */
3930
  'message' => sprintf( __( '%1$s: No %2$s settings to process.', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), __( 'Custom field', 'media-library-assistant' ) ),
3931
+ 'body' => '',
3932
+ 'processed' => 0,
3933
+ 'unchanged' => 0,
3934
+ 'success' => 0,
3935
  );
3936
  }
3937
 
3944
  $query['offset'] = $offset;
3945
  }
3946
 
3947
+ do_action( 'mla_begin_mapping', $source, NULL );
3948
  $posts = MLAShortcodes::mla_get_shortcode_attachments( 0, $query );
3949
 
3950
  if ( is_string( $posts ) ) {
3954
  );
3955
  }
3956
 
 
3957
  foreach ( $posts as $key => $post ) {
3958
  $updates = MLAOptions::mla_evaluate_iptc_exif_mapping( $post, 'iptc_exif_custom_mapping', $settings );
3959
 
3995
  */
3996
  private static function _save_iptc_exif_custom_settings( $new_values ) {
3997
  return array(
3998
+ 'message' => MLAOptions::mla_iptc_exif_option_handler( 'update', 'iptc_exif_custom_mapping', MLACore::$mla_option_definitions['iptc_exif_mapping'], $new_values ),
3999
  'body' => ''
4000
  );
4001
  } // _save_iptc_exif_custom_settings
4016
  /*
4017
  * Start with any page-level options
4018
  */
4019
+ foreach ( MLACore::$mla_option_definitions as $key => $value ) {
4020
  if ( 'iptc_exif' == $value['tab'] ) {
4021
  $option_messages .= self::mla_update_option_row( $key, $value );
4022
  }
4033
  $new_values = ( isset( $_REQUEST['iptc_exif_mapping'] ) ) ? $_REQUEST['iptc_exif_mapping'] : array( 'standard' => array(), 'taxonomy' => array(), 'custom' => array() );
4034
 
4035
  return array(
4036
+ 'message' => $message_list . MLAOptions::mla_iptc_exif_option_handler( 'update', 'iptc_exif_mapping', MLACore::$mla_option_definitions['iptc_exif_mapping'], $new_values ),
4037
  'body' => ''
4038
  );
4039
  } // _save_iptc_exif_settings
4050
  private static function _save_general_settings( ) {
4051
  $message_list = '';
4052
 
4053
+ foreach ( MLACore::$mla_option_definitions as $key => $value ) {
4054
  if ( 'general' == $value['tab'] ) {
4055
  switch ( $key ) {
4056
+ case MLACore::MLA_FEATURED_IN_TUNING:
4057
+ MLACore::$process_featured_in = ( 'disabled' != $_REQUEST[ MLA_OPTION_PREFIX . $key ] );
4058
  break;
4059
+ case MLACore::MLA_INSERTED_IN_TUNING:
4060
+ MLACore::$process_inserted_in = ( 'disabled' != $_REQUEST[ MLA_OPTION_PREFIX . $key ] );
4061
  break;
4062
+ case MLACore::MLA_GALLERY_IN_TUNING:
4063
+ MLACore::$process_gallery_in = ( 'disabled' != $_REQUEST[ MLA_OPTION_PREFIX . $key ] );
4064
 
4065
  if ( 'refresh' == $_REQUEST[ MLA_OPTION_PREFIX . $key ] ) {
4066
+ MLAQuery::mla_flush_mla_galleries( MLACore::MLA_GALLERY_IN_TUNING );
4067
  /* translators: 1: reference type, e.g., Gallery in */
4068
  $message_list .= "<br>" . sprintf( _x( '%1$s - references updated.', 'message_list', 'media-library-assistant' ), __( 'Gallery in', 'media-library-assistant' ) ) . "\r\n";
4069
  $_REQUEST[ MLA_OPTION_PREFIX . $key ] = 'cached';
4070
  }
4071
  break;
4072
+ case MLACore::MLA_MLA_GALLERY_IN_TUNING:
4073
+ MLACore::$process_mla_gallery_in = ( 'disabled' != $_REQUEST[ MLA_OPTION_PREFIX . $key ] );
4074
 
4075
  if ( 'refresh' == $_REQUEST[ MLA_OPTION_PREFIX . $key ] ) {
4076
+ MLAQuery::mla_flush_mla_galleries( MLACore::MLA_MLA_GALLERY_IN_TUNING );
4077
  /* translators: 1: reference type, e.g., Gallery in */
4078
  $message_list .= "<br>" . sprintf( _x( '%1$s - references updated.', 'message_list', 'media-library-assistant' ), __( 'MLA Gallery in', 'media-library-assistant' ) ) . "\r\n";
4079
  $_REQUEST[ MLA_OPTION_PREFIX . $key ] = 'cached';
4080
  }
4081
  break;
4082
+ case MLACore::MLA_TAXONOMY_SUPPORT:
4083
  /*
4084
  * Replace missing "checkbox" arguments with empty arrays,
4085
  * denoting that all of the boxes are unchecked.
4100
  $_REQUEST['tax_checked_on_top'] = array();
4101
  }
4102
  break;
4103
+ case MLACore::MLA_SEARCH_MEDIA_FILTER_DEFAULTS:
4104
  /*
4105
  * Replace missing "checkbox" arguments with empty arrays,
4106
  * denoting that all of the boxes are unchecked.
4140
  private static function _reset_general_settings( ) {
4141
  $message_list = '';
4142
 
4143
+ foreach ( MLACore::$mla_option_definitions as $key => $value ) {
4144
  if ( 'general' == $value['tab'] ) {
4145
  if ( 'custom' == $value['type'] && isset( $value['reset'] ) ) {
4146
  $message = MLAOptions::$value['reset']( 'reset', $key, $value, $_REQUEST );
4147
  } elseif ( ('header' == $value['type']) || ('hidden' == $value['type']) ) {
4148
  $message = '';
4149
  } else {
4150
+ MLACore::mla_delete_option( $key );
4151
  /* translators: 1: option name */
4152
  $message = '<br>' . sprintf( _x( 'delete_option "%1$s"', 'message_list', 'media-library-assistant'), $key );
4153
  }
4234
  private static function _export_settings( ) {
4235
  $message_list = '';
4236
  $settings = array();
4237
+ $stored_count = 0;
4238
+
4239
+ /*
4240
+ * These are WordPress options, not MLA options
4241
+ */
4242
+ foreach( array( 'image_default_align', 'image_default_link_type', 'image_default_size' ) as $key ) {
4243
+ $stored_value = get_option( $key );
4244
+ if ( empty( $stored_value ) ) {
4245
+ $stored_value = 'default';
4246
+ }
4247
+
4248
+ if ( 'default' !== $stored_value ) {
4249
+ $settings[ $key ] = $stored_value;
4250
+ $stored_count++;
4251
+ $message = "<br>{$key} " . _x( 'exported', 'message_list', 'media-library-assistant' );
4252
+ } else {
4253
+ $message = "<br>{$key} " . _x( 'skipped', 'message_list', 'media-library-assistant' );
4254
+ }
4255
+
4256
+ $message_list .= $message;
4257
+ }
4258
 
4259
  /*
4260
  * Accumulate the settings into an array, then serialize it for writing to the file.
4261
  */
4262
+ foreach ( MLACore::$mla_option_definitions as $key => $value ) {
4263
+ $stored_value = MLACore::mla_get_option( $key, false, true );
 
4264
  if ( false !== $stored_value ) {
4265
  $settings[ $key ] = $stored_value;
4266
  $stored_count++;
4377
  $updated_count = 0;
4378
  $unchanged_count = 0;
4379
  foreach ( $settings as $key => $value ) {
4380
+ /*
4381
+ * These are WordPress options, not MLA options
4382
+ */
4383
+ if ( in_array( $key, array( 'image_default_align', 'image_default_link_type', 'image_default_size' ) ) ) {
4384
+ $stored_value = get_option( $key );
4385
+ if ( empty( $stored_value ) ) {
4386
+ $stored_value = 'default';
4387
+ }
4388
+
4389
+ if ( $stored_value !== $value ) {
4390
+ $updated_count++;
4391
+ $message_list .= "<br>{$key} " . _x( 'updated', 'message_list', 'media-library-assistant' );
4392
+ } else {
4393
+ $unchanged_count++;
4394
+ $message_list .= "<br>{$key} " . _x( 'unchanged', 'message_list', 'media-library-assistant' );
4395
+ }
4396
+
4397
+ if ( 'default' === $value ) {
4398
+ $value = '';
4399
+ }
4400
+
4401
+ update_option( $key, $value );
4402
+ continue;
4403
+ }
4404
+
4405
+ if ( MLACore::mla_update_option( $key, $value ) ) {
4406
  $updated_count++;
4407
  $message_list .= "<br>{$key} " . _x( 'updated', 'message_list', 'media-library-assistant' );
4408
  } else {
includes/class-mla-shortcode-support.php ADDED
@@ -0,0 +1,4369 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Media Library Assistant Shortcode handler(s)
4
+ *
5
+ * @package Media Library Assistant
6
+ * @since 2.20
7
+ */
8
+
9
+ /*
10
+ * The MLA database access functions aren't available to "front end" posts/pages
11
+ */
12
+ if ( !class_exists( 'MLAQuery' ) ) {
13
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-data-query.php' );
14
+ MLAQuery::initialize();
15
+ }
16
+
17
+ if ( !class_exists( 'MLAData' ) ) {
18
+ require_once( MLA_PLUGIN_PATH . 'includes/class-mla-data.php' );
19
+ MLAData::initialize();
20
+ }
21
+
22
+ /**
23
+ * Class MLA (Media Library Assistant) Shortcode Support provides the functions that
24
+ * implement the [mla_gallery] and [mla_tag_cloud] shortcodes. It also implements the
25
+ * mla_get_shortcode_attachments() and mla_get_terms() database access functions.
26
+ *
27
+ * @package Media Library Assistant
28
+ * @since 2.20
29
+ */
30
+ class MLAShortcode_Support {
31
+ /**
32
+ * Style and Markup templates
33
+ *
34
+ * @since 2.20
35
+ *
36
+ * @var array
37
+ */
38
+ public static $mla_custom_templates = NULL;
39
+
40
+ /**
41
+ * Load style and markup templates to $mla_custom_templates
42
+ *
43
+ * @since 2.20
44
+ *
45
+ * @return void
46
+ */
47
+ public static function mla_load_custom_templates() {
48
+ MLAShortcode_Support::$mla_custom_templates = MLAData::mla_load_template( 'mla-custom-templates.tpl' );
49
+
50
+ /*
51
+ * Load the default templates
52
+ */
53
+ if ( is_null( MLAShortcode_Support::$mla_custom_templates ) ) {
54
+ MLACore::mla_debug_add( '<strong>mla_debug _load_option_templates()</strong> ' . __( 'error loading tpls/mla-option-templates.tpl', 'media-library-assistant' ) );
55
+ return;
56
+ } elseif ( !MLAShortcode_Support::$mla_custom_templates ) {
57
+ MLACore::mla_debug_add( '<strong>mla_debug _load_option_templates()</strong> ' . __( 'tpls/mla-option-templates.tpl not found', 'media-library-assistant' ) );
58
+ MLAShortcode_Support::$mla_custom_templates = NULL;
59
+ return;
60
+ }
61
+
62
+ /*
63
+ * Add user-defined Style and Markup templates
64
+ */
65
+ $templates = MLACore::mla_get_option( 'style_templates' );
66
+ if ( is_array( $templates ) ) {
67
+ foreach ( $templates as $name => $value ) {
68
+ MLAShortcode_Support::$mla_custom_templates[ $name . '-style' ] = $value;
69
+ } // foreach $templates
70
+ } // is_array
71
+
72
+ $templates = MLACore::mla_get_option( 'markup_templates' );
73
+ if ( is_array( $templates ) ) {
74
+ foreach ( $templates as $name => $value ) {
75
+ MLAShortcode_Support::$mla_custom_templates[ $name . '-open-markup' ] = $value['open'];
76
+ MLAShortcode_Support::$mla_custom_templates[ $name . '-row-open-markup' ] = $value['row-open'];
77
+ MLAShortcode_Support::$mla_custom_templates[ $name . '-item-markup' ] = $value['item'];
78
+ MLAShortcode_Support::$mla_custom_templates[ $name . '-row-close-markup' ] = $value['row-close'];
79
+ MLAShortcode_Support::$mla_custom_templates[ $name . '-close-markup' ] = $value['close'];
80
+ } // foreach $templates
81
+ } // is_array
82
+ }
83
+
84
+ /**
85
+ * Fetch style or markup template from $mla_templates
86
+ *
87
+ * @since 2.20
88
+ *
89
+ * @param string Template name
90
+ * @param string Template type; 'style' (default) or 'markup'
91
+ *
92
+ * @return string|boolean|null requested template, false if not found or null if no templates
93
+ */
94
+ public static function mla_fetch_gallery_template( $key, $type = 'style' ) {
95
+ if ( ! is_array( MLAShortcode_Support::$mla_custom_templates ) ) {
96
+ MLACore::mla_debug_add( '<strong>mla_fetch_gallery_template()</strong> ' . __( 'no templates exist', 'media-library-assistant' ) );
97
+ return NULL;
98
+ }
99
+
100
+ $array_key = $key . '-' . $type;
101
+ if ( array_key_exists( $array_key, MLAShortcode_Support::$mla_custom_templates ) ) {
102
+ return MLAShortcode_Support::$mla_custom_templates[ $array_key ];
103
+ } else {
104
+ MLACore::mla_debug_add( "<strong>mla_fetch_gallery_template( {$key}, {$type} )</strong> " . __( 'not found', 'media-library-assistant' ) );
105
+ return false;
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Verify the presence of Ghostscript for mla_viewer
111
+ *
112
+ * @since 2.20
113
+ *
114
+ * @param string Non-standard location to override default search, e.g.,
115
+ * 'C:\Program Files (x86)\gs\gs9.15\bin\gswin32c.exe'
116
+ * @param boolean Force ghostscript-only tests, used by MLASettings::_compose_mla_gallery_tab()
117
+ *
118
+ * @return boolean true if Ghostscript available else false
119
+ */
120
+ public static function mla_ghostscript_present( $explicit_path = '', $ghostscript_only = false ) {
121
+ static $ghostscript_present = NULL;
122
+
123
+ if ( ! $ghostscript_only ) {
124
+ if ( isset( $ghostscript_present ) ) {
125
+ MLACore::mla_debug_add( '<strong>_ghostscript_present</strong>, ghostscript_present = ' . var_export( $ghostscript_present, true ) );
126
+ return $ghostscript_present;
127
+ }
128
+
129
+ if ( 'checked' != MLACore::mla_get_option( 'enable_ghostscript_check' ) ) {
130
+ MLACore::mla_debug_add( '<strong>_ghostscript_present</strong>, disabled' );
131
+ return $ghostscript_present = true;
132
+ }
133
+
134
+ /*
135
+ * Imagick must be installed as well
136
+ */
137
+ if ( ! class_exists( 'Imagick' ) ) {
138
+ MLACore::mla_debug_add( '<strong>_ghostscript_present</strong>, Imagick missing' );
139
+ return $ghostscript_present = false;
140
+ }
141
+ } // not ghostscript_only
142
+
143
+ /*
144
+ * Look for exec() - from http://stackoverflow.com/a/12980534/866618
145
+ */
146
+ if ( ini_get('safe_mode') ) {
147
+ MLACore::mla_debug_add( '<strong>_ghostscript_present</strong>, safe_mode' );
148
+ return $ghostscript_present = false;
149
+ }
150
+
151
+ $blacklist = preg_split( '/,\s*/', ini_get('disable_functions') . ',' . ini_get('suhosin.executor.func.blacklist') );
152
+ if ( in_array('exec', $blacklist) ) {
153
+ MLACore::mla_debug_add( '<strong>_ghostscript_present</strong>, exec in blacklist' );
154
+ return $ghostscript_present = false;
155
+ }
156
+
157
+ if ( 'WIN' === strtoupper( substr( PHP_OS, 0, 3) ) ) {
158
+ if ( ! empty( $explicit_path ) ) {
159
+ $return = exec( 'dir /o:n/s/b "' . $explicit_path . '"' );
160
+ MLACore::mla_debug_add( '<strong>_ghostscript_present</strong>, WIN explicit path = ' . var_export( $return, true ) );
161
+ if ( ! empty( $return ) ) {
162
+ return $ghostscript_present = true;
163
+ } else {
164
+ return $ghostscript_present = false;
165
+ }
166
+ }
167
+
168
+ $return = getenv('GSC');
169
+ if ( ! empty( $return ) ) {
170
+ return $ghostscript_present = true;
171
+ }
172
+
173
+ $return = exec('where gswin*c.exe');
174
+ if ( ! empty( $return ) ) {
175
+ return $ghostscript_present = true;
176
+ }
177
+
178
+ $return = exec('dir /o:n/s/b "C:\Program Files\gs\*gswin*c.exe"');
179
+ if ( ! empty( $return ) ) {
180
+ return $ghostscript_present = true;
181
+ }
182
+
183
+ $return = exec('dir /o:n/s/b "C:\Program Files (x86)\gs\*gswin32c.exe"');
184
+ if ( ! empty( $return ) ) {
185
+ return $ghostscript_present = true;
186
+ }
187
+
188
+ MLACore::mla_debug_add( '<strong>_ghostscript_present</strong>, WIN detection failed' );
189
+ return $ghostscript_present = false;
190
+ } // Windows platform
191
+
192
+ if ( ! empty( $explicit_path ) ) {
193
+ exec( 'test -e ' . $explicit_path, $dummy, $ghostscript_path );
194
+ MLACore::mla_debug_add( '<strong>_ghostscript_present</strong>, explicit path = ' . var_export( $explicit_path, true ) . ', ghostscript_path = ' . var_export( $ghostscript_path, true ) );
195
+ return ( $explicit_path === $ghostscript_path );
196
+ }
197
+
198
+ $return = exec('which gs');
199
+ if ( ! empty( $return ) ) {
200
+ return $ghostscript_present = true;
201
+ }
202
+
203
+ $test_path = '/usr/bin/gs';
204
+ exec('test -e ' . $test_path, $dummy, $ghostscript_path);
205
+ MLACore::mla_debug_add( '<strong>_ghostscript_present</strong>, test_path = ' . var_export( $test_path, true ) . ', ghostscript_path = ' . var_export( $ghostscript_path, true ) );
206
+ return $ghostscript_present = ( $test_path === $ghostscript_path );
207
+ }
208
+
209
+ /**
210
+ * Make sure $attr is an array and repair line-break damage
211
+ *
212
+ * @since 2.20
213
+ *
214
+ * @param mixed array or string containing shortcode attributes
215
+ *
216
+ * @return array clean attributes array
217
+ */
218
+ private static function _validate_attributes( $attr ) {
219
+ if ( empty( $attr ) ) {
220
+ $attr = array();
221
+ } elseif ( is_string( $attr ) ) {
222
+ $attr = shortcode_parse_atts( $attr );
223
+ }
224
+
225
+ // Numeric keys indicate parse errors
226
+ $is_valid = true;
227
+ foreach ( $attr as $key => $value ) {
228
+ if ( is_numeric( $key ) ) {
229
+ $is_valid = false;
230
+ break;
231
+ }
232
+ }
233
+
234
+ if ( $is_valid ) {
235
+ return $attr;
236
+ }
237
+
238
+ /*
239
+ * Found an error, e.g., line break(s) among the atttributes.
240
+ * Try to reconstruct the input string without them.
241
+ */
242
+ $new_attr = '';
243
+ foreach ( $attr as $key => $value ) {
244
+ $break_tag = strpos( $value, '<br' );
245
+ if ( ( false !== $break_tag ) && ( ($break_tag + 3) == strlen( $value ) ) ) {
246
+ $value = substr( $value, 0, ( strlen( $value ) - 3) );
247
+ }
248
+
249
+ if ( is_numeric( $key ) ) {
250
+ if ( '/>' !== $value ) {
251
+ $new_attr .= $value . ' ';
252
+ }
253
+ } else {
254
+ $delimiter = ( false === strpos( $value, '"' ) ) ? '"' : "'";
255
+ $new_attr .= $key . '=' . $delimiter . $value . $delimiter . ' ';
256
+ }
257
+ }
258
+
259
+ return shortcode_parse_atts( $new_attr );
260
+ }
261
+
262
+ /**
263
+ * Turn debug collection and display on or off
264
+ *
265
+ * @since 2.20
266
+ *
267
+ * @var boolean
268
+ */
269
+ private static $mla_debug = false;
270
+
271
+ /**
272
+ * The MLA Gallery shortcode.
273
+ *
274
+ * This is a superset of the WordPress Gallery shortcode for displaying images on a post,
275
+ * page or custom post type. It is adapted from /wp-includes/media.php gallery_shortcode.
276
+ * Enhancements include many additional selection parameters and full taxonomy support.
277
+ *
278
+ * @since 2.20
279
+ *
280
+ * @param array Attributes of the shortcode
281
+ * @param string Optional content for enclosing shortcodes; used with mla_alt_shortcode
282
+ *
283
+ * @return string HTML content to display gallery.
284
+ */
285
+ public static function mla_gallery_shortcode( $attr, $content = NULL ) {
286
+ global $post;
287
+
288
+ /*
289
+ * Some do_shortcode callers may not have a specific post in mind
290
+ */
291
+ if ( ! is_object( $post ) ) {
292
+ $post = (object) array( 'ID' => 0 );
293
+ }
294
+
295
+ /*
296
+ * Make sure $attr is an array, even if it's empty,
297
+ * and repair damage caused by link-breaks in the source text
298
+ */
299
+ $attr = self::_validate_attributes( $attr );
300
+
301
+ /*
302
+ * Filter the attributes before $mla_page_parameter and "request:" prefix processing.
303
+ */
304
+
305
+ $attr = apply_filters( 'mla_gallery_raw_attributes', $attr );
306
+
307
+ /*
308
+ * The mla_paginate_current parameter can be changed to support multiple galleries per page.
309
+ */
310
+ if ( ! isset( $attr['mla_page_parameter'] ) ) {
311
+ $attr['mla_page_parameter'] = self::$mla_get_shortcode_attachments_parameters['mla_page_parameter'];
312
+ }
313
+
314
+ $mla_page_parameter = $attr['mla_page_parameter'];
315
+
316
+ /*
317
+ * Special handling of the mla_paginate_current parameter to make
318
+ * "MLA pagination" easier. Look for this parameter in $_REQUEST
319
+ * if it's not present in the shortcode itself.
320
+ */
321
+ if ( ! isset( $attr[ $mla_page_parameter ] ) ) {
322
+ if ( isset( $_REQUEST[ $mla_page_parameter ] ) ) {
323
+ $attr[ $mla_page_parameter ] = $_REQUEST[ $mla_page_parameter ];
324
+ }
325
+ }
326
+
327
+ /*
328
+ * These are the parameters for gallery display
329
+ */
330
+ $mla_item_specific_arguments = array(
331
+ 'mla_link_attributes' => '',
332
+ 'mla_link_class' => '',
333
+ 'mla_link_href' => '',
334
+ 'mla_link_text' => '',
335
+ 'mla_nolink_text' => '',
336
+ 'mla_rollover_text' => '',
337
+ 'mla_image_class' => '',
338
+ 'mla_image_alt' => '',
339
+ 'mla_image_attributes' => '',
340
+ 'mla_caption' => ''
341
+ );
342
+
343
+ $mla_arguments = array_merge( array(
344
+ 'mla_output' => 'gallery',
345
+ 'mla_style' => MLACore::mla_get_option('default_style'),
346
+ 'mla_markup' => MLACore::mla_get_option('default_markup'),
347
+ 'mla_float' => is_rtl() ? 'right' : 'left',
348
+ 'mla_itemwidth' => MLACore::mla_get_option('mla_gallery_itemwidth'),
349
+ 'mla_margin' => MLACore::mla_get_option('mla_gallery_margin'),
350
+ 'mla_target' => '',
351
+ 'mla_debug' => false,
352
+
353
+ 'mla_viewer' => false,
354
+ 'mla_single_thread' => false,
355
+ 'mla_viewer_extensions' => 'ai,eps,pdf,ps',
356
+ 'mla_viewer_limit' => '0',
357
+ 'mla_viewer_width' => '0',
358
+ 'mla_viewer_height' => '0',
359
+ 'mla_viewer_best_fit' => NULL,
360
+ 'mla_viewer_page' => '1',
361
+ 'mla_viewer_resolution' => '0',
362
+ 'mla_viewer_quality' => '0',
363
+ 'mla_viewer_type' => '',
364
+
365
+ 'mla_alt_shortcode' => NULL,
366
+ 'mla_alt_ids_name' => 'ids',
367
+
368
+ // paginatation arguments defined in $mla_get_shortcode_attachments_parameters
369
+ // 'mla_page_parameter' => 'mla_paginate_current', handled in code with $mla_page_parameter
370
+ // 'mla_paginate_current' => NULL,
371
+ // 'mla_paginate_total' => NULL,
372
+ // 'id' => NULL,
373
+
374
+ 'mla_end_size'=> 1,
375
+ 'mla_mid_size' => 2,
376
+ 'mla_prev_text' => '&laquo; ' . __( 'Previous', 'media-library-assistant' ),
377
+ 'mla_next_text' => __( 'Next', 'media-library-assistant' ) . ' &raquo;',
378
+ 'mla_paginate_type' => 'plain',
379
+ 'mla_paginate_rows' => NULL ),
380
+ $mla_item_specific_arguments
381
+ );
382
+
383
+ $html5 = current_theme_supports( 'html5', 'gallery' );
384
+ $default_arguments = array_merge( array(
385
+ 'size' => 'thumbnail', // or 'medium', 'large', 'full' or registered size
386
+ 'itemtag' => $html5 ? 'figure' : 'dl',
387
+ 'icontag' => $html5 ? 'div' : 'dt',
388
+ 'captiontag' => $html5 ? 'figcaption' : 'dd',
389
+ 'columns' => MLACore::mla_get_option('mla_gallery_columns'),
390
+ 'link' => 'permalink', // or 'post' or file' or a registered size
391
+ // Photonic-specific
392
+ 'id' => NULL,
393
+ 'style' => NULL,
394
+ 'type' => 'default', // also used by WordPress.com Jetpack!
395
+ 'thumb_width' => 75,
396
+ 'thumb_height' => 75,
397
+ 'thumbnail_size' => 'thumbnail',
398
+ 'slide_size' => 'large',
399
+ 'slideshow_height' => 500,
400
+ 'fx' => 'fade',
401
+ 'timeout' => 4000,
402
+ 'speed' => 1000,
403
+ 'pause' => NULL),
404
+ $mla_arguments
405
+ );
406
+
407
+ // $instance supports multiple galleries in one page/post
408
+ static $instance = 0;
409
+ $instance++;
410
+
411
+ /*
412
+ * Some values are already known, and can be used in data selection parameters
413
+ */
414
+ $upload_dir = wp_upload_dir();
415
+ $page_values = array(
416
+ 'instance' => $instance,
417
+ 'selector' => "mla_gallery-{$instance}",
418
+ 'site_url' => site_url(),
419
+ 'base_url' => $upload_dir['baseurl'],
420
+ 'base_dir' => $upload_dir['basedir'],
421
+ 'id' => $post->ID,
422
+ 'page_ID' => $post->ID,
423
+ 'page_author' => $post->post_author,
424
+ 'page_date' => $post->post_date,
425
+ 'page_content' => $post->post_content,
426
+ 'page_title' => $post->post_title,
427
+ 'page_excerpt' => $post->post_excerpt,
428
+ 'page_status' => $post->post_status,
429
+ 'page_name' => $post->post_name,
430
+ 'page_modified' => $post->post_modified,
431
+ 'page_guid' => $post->guid,
432
+ 'page_type' => $post->post_type,
433
+ 'page_url' => get_page_link(),
434
+ );
435
+
436
+ /*
437
+ * Look for page-level and 'request:' substitution parameters,
438
+ * which can be added to any input parameter
439
+ */
440
+ foreach ( $attr as $attr_key => $attr_value ) {
441
+ /*
442
+ * attachment-specific Gallery Display Content parameters must be evaluated
443
+ * later, when all of the information is available.
444
+ */
445
+ if ( array_key_exists( $attr_key, $mla_item_specific_arguments ) ) {
446
+ continue;
447
+ }
448
+
449
+ $attr_value = str_replace( '{+', '[+', str_replace( '+}', '+]', $attr_value ) );
450
+ $replacement_values = MLAData::mla_expand_field_level_parameters( $attr_value, NULL, $page_values );
451
+ $attr[ $attr_key ] = MLAData::mla_parse_template( $attr_value, $replacement_values );
452
+ }
453
+
454
+ /*
455
+ * Merge gallery arguments with defaults, pass the query arguments on to mla_get_shortcode_attachments.
456
+ */
457
+
458
+ $attr = apply_filters( 'mla_gallery_attributes', $attr );
459
+ $content = apply_filters( 'mla_gallery_initial_content', $content, $attr );
460
+ $arguments = shortcode_atts( $default_arguments, $attr );
461
+ $arguments = apply_filters( 'mla_gallery_arguments', $arguments );
462
+
463
+ self::$mla_debug = ( ! empty( $arguments['mla_debug'] ) ) ? trim( strtolower( $arguments['mla_debug'] ) ) : false;
464
+ if ( self::$mla_debug ) {
465
+ if ( 'true' == self::$mla_debug ) {
466
+ MLACore::mla_debug_mode( 'buffer' );
467
+ } elseif ( 'log' == self::$mla_debug ) {
468
+ MLACore::mla_debug_mode( 'log' );
469
+ } else {
470
+ self::$mla_debug = false;
471
+ }
472
+ }
473
+
474
+ /*
475
+ * Determine output type
476
+ */
477
+ $output_parameters = array_map( 'strtolower', array_map( 'trim', explode( ',', $arguments['mla_output'] ) ) );
478
+ $is_gallery = 'gallery' == $output_parameters[0];
479
+ $is_pagination = in_array( $output_parameters[0], array( 'previous_page', 'next_page', 'paginate_links' ) );
480
+
481
+ if ( $is_pagination && ( NULL !== $arguments['mla_paginate_rows'] ) ) {
482
+ $attachments['found_rows'] = absint( $arguments['mla_paginate_rows'] );
483
+ } else {
484
+ $attachments = self::mla_get_shortcode_attachments( $post->ID, $attr, $is_pagination );
485
+ }
486
+
487
+ if ( is_string( $attachments ) ) {
488
+ return $attachments;
489
+ }
490
+
491
+ if ( empty($attachments) ) {
492
+ if ( self::$mla_debug ) {
493
+ MLACore::mla_debug_add( '<strong>' . __( 'mla_debug empty gallery', 'media-library-assistant' ) . '</strong>, query = ' . var_export( $attr, true ) );
494
+ $output = MLACore::mla_debug_flush();
495
+ } else {
496
+ $output = '';
497
+ }
498
+
499
+ $output .= $arguments['mla_nolink_text'];
500
+ return $output;
501
+ } // empty $attachments
502
+
503
+ /*
504
+ * Look for user-specified alternate gallery shortcode
505
+ */
506
+ if ( is_string( $arguments['mla_alt_shortcode'] ) ) {
507
+ /*
508
+ * Replace data-selection parameters with the "ids" list
509
+ */
510
+ if ( 'mla_tag_cloud' == $arguments['mla_alt_shortcode'] ) {
511
+ $blacklist = self::$mla_get_shortcode_attachments_parameters;
512
+ } else {
513
+ $blacklist = array_merge( $mla_arguments, self::$mla_get_shortcode_attachments_parameters );
514
+ }
515
+
516
+ $new_args = '';
517
+ foreach ( $attr as $key => $value ) {
518
+ if ( array_key_exists( $key, $blacklist ) ) {
519
+ continue;
520
+ }
521
+
522
+ $slashed = addcslashes( $value, chr(0).chr(7).chr(8)."\f\n\r\t\v\"\\\$" );
523
+ if ( ( false !== strpos( $value, ' ' ) ) || ( false !== strpos( $value, '\'' ) ) || ( $slashed != $value ) ) {
524
+ $value = '"' . $slashed . '"';
525
+ }
526
+
527
+ $new_args .= empty( $new_args ) ? $key . '=' . $value : ' ' . $key . '=' . $value;
528
+ } // foreach $attr
529
+
530
+ $new_ids = '';
531
+ foreach ( $attachments as $value ) {
532
+ $new_ids .= empty( $new_ids ) ? (string) $value->ID : ',' . $value->ID;
533
+ } // foreach $attachments
534
+
535
+ $new_ids = $arguments['mla_alt_ids_name'] . '="' . $new_ids . '"';
536
+
537
+ if ( self::$mla_debug ) {
538
+ $output = MLACore::mla_debug_flush();
539
+ } else {
540
+ $output = '';
541
+ }
542
+
543
+ /*
544
+ * Execute the alternate gallery shortcode with the new parameters
545
+ */
546
+ $content = apply_filters( 'mla_gallery_final_content', $content );
547
+ if ( ! empty( $content ) ) {
548
+ return $output . do_shortcode( sprintf( '[%1$s %2$s %3$s]%4$s[/%5$s]', $arguments['mla_alt_shortcode'], $new_ids, $new_args, $content, $arguments['mla_alt_shortcode'] ) );
549
+ } else {
550
+ return $output . do_shortcode( sprintf( '[%1$s %2$s %3$s]', $arguments['mla_alt_shortcode'], $new_ids, $new_args ) );
551
+ }
552
+ } // mla_alt_shortcode
553
+
554
+ /*
555
+ * Look for Photonic-enhanced gallery
556
+ */
557
+ global $photonic;
558
+
559
+ if ( is_object( $photonic ) && ! empty( $arguments['style'] ) ) {
560
+ if ( 'default' != strtolower( $arguments['type'] ) ) {
561
+ return '<p>' . __( '<strong>Photonic-enhanced [mla_gallery]</strong> type must be <strong>default</strong>, query = ', 'media-library-assistant' ) . var_export( $attr, true ) . '</p>';
562
+ }
563
+
564
+ $images = array();
565
+ foreach ($attachments as $key => $val) {
566
+ $images[$val->ID] = $attachments[$key];
567
+ }
568
+
569
+ if ( isset( $arguments['pause'] ) && ( 'false' == $arguments['pause'] ) ) {
570
+ $arguments['pause'] = NULL;
571
+ }
572
+
573
+ $output = $photonic->build_gallery( $images, $arguments['style'], $arguments );
574
+ return $output;
575
+ }
576
+
577
+ $size = $size_class = $arguments['size'];
578
+ if ( 'icon' == strtolower( $size) ) {
579
+ if ( 'checked' == MLACore::mla_get_option( MLACore::MLA_ENABLE_MLA_ICONS ) ) {
580
+ $size = array( 64, 64 );
581
+ } else {
582
+ $size = array( 60, 60 );
583
+ }
584
+
585
+ $show_icon = true;
586
+ } else {
587
+ $show_icon = false;
588
+ }
589
+
590
+ /*
591
+ * Feeds such as RSS, Atom or RDF do not require styled and formatted output
592
+ */
593
+ if ( is_feed() ) {
594
+ $output = "\n";
595
+ foreach ( $attachments as $att_id => $attachment )
596
+ $output .= wp_get_attachment_link($att_id, $size, true) . "\n";
597
+ return $output;
598
+ }
599
+
600
+ /*
601
+ * Check for Imagick thumbnail generation arguments
602
+ */
603
+ if ( 'checked' == MLACore::mla_get_option( 'enable_mla_viewer' ) ) {
604
+ if ( ! empty( $arguments['mla_viewer'] ) && ( 'single' == strtolower( $arguments['mla_viewer'] ) ) ) {
605
+ $arguments['mla_single_thread'] = true;
606
+ $arguments['mla_viewer'] = 'true';
607
+ }
608
+
609
+ $arguments['mla_viewer'] = !empty( $arguments['mla_viewer'] ) && ( 'true' == strtolower( $arguments['mla_viewer'] ) );
610
+ } else {
611
+ $arguments['mla_viewer'] = false;
612
+ }
613
+
614
+ if ( $arguments['mla_viewer'] ) {
615
+ /*
616
+ * Test for Ghostscript here so debug messages can be recorded
617
+ */
618
+ $ghostscript_path = MLACore::mla_get_option( 'ghostscript_path' );
619
+ if ( self::mla_ghostscript_present( $ghostscript_path ) ) {
620
+ $arguments['mla_viewer_extensions'] = array_filter( array_map( 'trim', explode( ',', $arguments['mla_viewer_extensions'] ) ) );
621
+ } else {
622
+ $arguments['mla_viewer_extensions'] = array();
623
+ }
624
+
625
+ // convert limit (in MB) to float
626
+ $arguments['mla_viewer_limit'] = abs( 0.0 + $arguments['mla_viewer_limit'] );
627
+
628
+ $arguments['mla_viewer_width'] = absint( $arguments['mla_viewer_width'] );
629
+ $arguments['mla_viewer_height'] = absint( $arguments['mla_viewer_height'] );
630
+ $arguments['mla_viewer_page'] = absint( $arguments['mla_viewer_page'] );
631
+
632
+ if ( isset( $arguments['mla_viewer_best_fit'] ) ) {
633
+ $arguments['mla_viewer_best_fit'] = 'true' == strtolower( $arguments['mla_viewer_best_fit'] );
634
+ }
635
+
636
+ $arguments['mla_viewer_resolution'] = absint( $arguments['mla_viewer_resolution'] );
637
+ $arguments['mla_viewer_quality'] = absint( $arguments['mla_viewer_quality'] );
638
+ }
639
+
640
+ /*
641
+ * The default MLA style template includes "margin: 1.5%" to put a bit of
642
+ * minimum space between the columns. "mla_margin" can be used to change
643
+ * this. "mla_itemwidth" can be used with "columns=0" to achieve a "responsive"
644
+ * layout.
645
+ */
646
+
647
+ $columns = absint( $arguments['columns'] );
648
+ $margin_string = strtolower( trim( $arguments['mla_margin'] ) );
649
+
650
+ if ( is_numeric( $margin_string ) && ( 0 != $margin_string) ) {
651
+ $margin_string .= '%'; // Legacy values are always in percent
652
+ }
653
+
654
+ if ( '%' == substr( $margin_string, -1 ) ) {
655
+ $margin_percent = (float) substr( $margin_string, 0, strlen( $margin_string ) - 1 );
656
+ } else {
657
+ $margin_percent = 0;
658
+ }
659
+
660
+ $width_string = strtolower( trim( $arguments['mla_itemwidth'] ) );
661
+ if ( 'none' != $width_string ) {
662
+ switch ( $width_string ) {
663
+ case 'exact':
664
+ $margin_percent = 0;
665
+ // fallthru
666
+ case 'calculate':
667
+ $width_string = $columns > 0 ? (floor(1000/$columns)/10) - ( 2.0 * $margin_percent ) : 100 - ( 2.0 * $margin_percent );
668
+ // fallthru
669
+ default:
670
+ if ( is_numeric( $width_string ) && ( 0 != $width_string) ) {
671
+ $width_string .= '%'; // Legacy values are always in percent
672
+ }
673
+ }
674
+ } // $use_width
675
+
676
+ $float = strtolower( $arguments['mla_float'] );
677
+ if ( ! in_array( $float, array( 'left', 'none', 'right' ) ) ) {
678
+ $float = is_rtl() ? 'right' : 'left';
679
+ }
680
+
681
+ $style_values = array_merge( $page_values, array(
682
+ 'mla_style' => $arguments['mla_style'],
683
+ 'mla_markup' => $arguments['mla_markup'],
684
+ 'itemtag' => tag_escape( $arguments['itemtag'] ),
685
+ 'icontag' => tag_escape( $arguments['icontag'] ),
686
+ 'captiontag' => tag_escape( $arguments['captiontag'] ),
687
+ 'columns' => $columns,
688
+ 'itemwidth' => $width_string,
689
+ 'margin' => $margin_string,
690
+ 'float' => $float,
691
+ 'size_class' => sanitize_html_class( $size_class )
692
+ ) );
693
+
694
+ $style_template = $gallery_style = '';
695
+
696
+ if ( 'theme' == strtolower( $style_values['mla_style'] ) ) {
697
+ $use_mla_gallery_style = apply_filters( 'use_default_gallery_style', ! $html5 );
698
+ } else {
699
+ $use_mla_gallery_style = ( 'none' != strtolower( $style_values['mla_style'] ) );
700
+ }
701
+
702
+ if ( apply_filters( 'use_mla_gallery_style', $use_mla_gallery_style, $style_values['mla_style'] ) ) {
703
+ $style_template = MLAShortcode_support::mla_fetch_gallery_template( $style_values['mla_style'], 'style' );
704
+ if ( empty( $style_template ) ) {
705
+ $style_values['mla_style'] = $default_arguments['mla_style'];
706
+ $style_template = MLAShortcode_support::mla_fetch_gallery_template( $style_values['mla_style'], 'style' );
707
+ if ( empty( $style_template ) ) {
708
+ $style_values['mla_style'] = 'default';
709
+ $style_template = MLAShortcode_support::mla_fetch_gallery_template( 'default', 'style' );
710
+ }
711
+ }
712
+
713
+ if ( ! empty ( $style_template ) ) {
714
+ /*
715
+ * Look for 'query' and 'request' substitution parameters
716
+ */
717
+ $style_values = MLAData::mla_expand_field_level_parameters( $style_template, $attr, $style_values );
718
+
719
+ /*
720
+ * Clean up the template to resolve width or margin == 'none'
721
+ */
722
+ if ( 'none' == $margin_string ) {
723
+ $style_values['margin'] = '0';
724
+ $style_template = preg_replace( '/margin:[\s]*\[\+margin\+\][\%]*[\;]*/', '', $style_template );
725
+ }
726
+
727
+ if ( 'none' == $width_string ) {
728
+ $style_values['itemwidth'] = 'auto';
729
+ $style_template = preg_replace( '/width:[\s]*\[\+itemwidth\+\][\%]*[\;]*/', '', $style_template );
730
+ }
731
+
732
+ $style_values = apply_filters( 'mla_gallery_style_values', $style_values );
733
+ $style_template = apply_filters( 'mla_gallery_style_template', $style_template );
734
+ $gallery_style = MLAData::mla_parse_template( $style_template, $style_values );
735
+ $gallery_style = apply_filters( 'mla_gallery_style_parse', $gallery_style, $style_template, $style_values );
736
+
737
+ /*
738
+ * Clean up the styles to resolve extra "%" suffixes on width or margin (pre v1.42 values)
739
+ */
740
+ $preg_pattern = array( '/([margin|width]:[^\%]*)\%\%/', '/([margin|width]:.*)auto\%/', '/([margin|width]:.*)inherit\%/' );
741
+ $preg_replacement = array( '${1}%', '${1}auto', '${1}inherit', );
742
+ $gallery_style = preg_replace( $preg_pattern, $preg_replacement, $gallery_style );
743
+ } // !empty template
744
+ } // use_mla_gallery_style
745
+
746
+ $markup_values = $style_values;
747
+
748
+ $open_template = MLAShortcode_support::mla_fetch_gallery_template( $markup_values['mla_markup'] . '-open', 'markup' );
749
+ if ( false === $open_template ) {
750
+ $markup_values['mla_markup'] = $default_arguments['mla_markup'];
751
+ $open_template = MLAShortcode_support::mla_fetch_gallery_template( $markup_values['mla_markup'] . '-open', 'markup' );
752
+ if ( false === $open_template ) {
753
+ $markup_values['mla_markup'] = 'default';
754
+ $open_template = MLAShortcode_support::mla_fetch_gallery_template( $markup_values['mla_markup'] . '-open', 'markup' );
755
+ }
756
+ }
757
+ if ( empty( $open_template ) ) {
758
+ $open_template = '';
759
+ }
760
+
761
+ /*
762
+ * Emulate [gallery] handling of row open markup for the default template only
763
+ */
764
+ if ( $html5 && ( 'default' == $markup_values['mla_markup'] ) ) {
765
+ $row_open_template = '';
766
+ } else{
767
+ $row_open_template = MLAShortcode_support::mla_fetch_gallery_template( $markup_values['mla_markup'] . '-row-open', 'markup' );
768
+
769
+ if ( empty( $row_open_template ) ) {
770
+ $row_open_template = '';
771
+ }
772
+ }
773
+
774
+ $item_template = MLAShortcode_support::mla_fetch_gallery_template( $markup_values['mla_markup'] . '-item', 'markup' );
775
+ if ( empty( $item_template ) ) {
776
+ $item_template = '';
777
+ }
778
+
779
+ /*
780
+ * Emulate [gallery] handling of row close markup for the default template only
781
+ */
782
+ if ( $html5 && ( 'default' == $markup_values['mla_markup'] ) ) {
783
+ $row_close_template = '';
784
+ } else{
785
+ $row_close_template = MLAShortcode_support::mla_fetch_gallery_template( $markup_values['mla_markup'] . '-row-close', 'markup' );
786
+
787
+ if ( empty( $row_close_template ) ) {
788
+ $row_close_template = '';
789
+ }
790
+ }
791
+
792
+ $close_template = MLAShortcode_support::mla_fetch_gallery_template( $markup_values['mla_markup'] . '-close', 'markup' );
793
+ if ( empty( $close_template ) ) {
794
+ $close_template = '';
795
+ }
796
+
797
+ /*
798
+ * Look for gallery-level markup substitution parameters
799
+ */
800
+ $new_text = $open_template . $row_open_template . $row_close_template . $close_template;
801
+
802
+ $markup_values = MLAData::mla_expand_field_level_parameters( $new_text, $attr, $markup_values );
803
+ if ( self::$mla_debug ) {
804
+ $output = MLACore::mla_debug_flush();
805
+ } else {
806
+ $output = '';
807
+ }
808
+
809
+ if ($is_gallery ) {
810
+ $markup_values = apply_filters( 'mla_gallery_open_values', $markup_values );
811
+
812
+ $open_template = apply_filters( 'mla_gallery_open_template', $open_template );
813
+ if ( empty( $open_template ) ) {
814
+ $gallery_open = '';
815
+ } else {
816
+ $gallery_open = MLAData::mla_parse_template( $open_template, $markup_values );
817
+ }
818
+
819
+ $gallery_open = apply_filters( 'mla_gallery_open_parse', $gallery_open, $open_template, $markup_values );
820
+ $output .= apply_filters( 'mla_gallery_style', $gallery_style . $gallery_open, $style_values, $markup_values, $style_template, $open_template );
821
+ } else {
822
+ if ( ! isset( $attachments['found_rows'] ) ) {
823
+ $attachments['found_rows'] = 0;
824
+ }
825
+
826
+ /*
827
+ * Handle 'previous_page', 'next_page', and 'paginate_links'
828
+ */
829
+ $pagination_result = self::_process_pagination_output_types( $output_parameters, $markup_values, $arguments, $attr, $attachments['found_rows'], $output );
830
+ if ( false !== $pagination_result ) {
831
+ return $pagination_result;
832
+ }
833
+
834
+ unset( $attachments['found_rows'] );
835
+ }
836
+
837
+ /*
838
+ * For "previous_link", "current_link" and "next_link",
839
+ * discard all of the $attachments except the appropriate choice
840
+ */
841
+ if ( ! $is_gallery ) {
842
+ $link_type = $output_parameters[0];
843
+
844
+ if ( ! in_array( $link_type, array ( 'previous_link', 'current_link', 'next_link' ) ) ) {
845
+ return ''; // unknown output type
846
+ }
847
+
848
+ $is_wrap = isset( $output_parameters[1] ) && 'wrap' == $output_parameters[1];
849
+ $current_id = empty( $arguments['id'] ) ? $markup_values['id'] : $arguments['id'];
850
+
851
+ foreach ( $attachments as $id => $attachment ) {
852
+ if ( $attachment->ID == $current_id ) {
853
+ break;
854
+ }
855
+ }
856
+
857
+ switch ( $link_type ) {
858
+ case 'previous_link':
859
+ $target_id = $id - 1;
860
+ break;
861
+ case 'next_link':
862
+ $target_id = $id + 1;
863
+ break;
864
+ case 'current_link':
865
+ default:
866
+ $target_id = $id;
867
+ } // link_type
868
+
869
+ $target = NULL;
870
+ if ( isset( $attachments[ $target_id ] ) ) {
871
+ $target = $attachments[ $target_id ];
872
+ } elseif ( $is_wrap ) {
873
+ switch ( $link_type ) {
874
+ case 'previous_link':
875
+ $target = array_pop( $attachments );
876
+ break;
877
+ case 'next_link':
878
+ $target = array_shift( $attachments );
879
+ } // link_type
880
+ } // is_wrap
881
+
882
+ if ( isset( $target ) ) {
883
+ $attachments = array( $target );
884
+ } elseif ( ! empty( $arguments['mla_nolink_text'] ) ) {
885
+ return self::_process_shortcode_parameter( $arguments['mla_nolink_text'], $markup_values ) . '</a>';
886
+ } else {
887
+ return '';
888
+ }
889
+ } else { // ! is_gallery
890
+ $link_type= '';
891
+ }
892
+
893
+ $column_index = 0;
894
+ foreach ( $attachments as $id => $attachment ) {
895
+ $item_values = $markup_values;
896
+
897
+ /*
898
+ * fill in item-specific elements
899
+ */
900
+ $item_values['index'] = (string) 1 + $column_index;
901
+
902
+ $item_values['excerpt'] = wptexturize( $attachment->post_excerpt );
903
+ $item_values['attachment_ID'] = $attachment->ID;
904
+ $item_values['mime_type'] = $attachment->post_mime_type;
905
+ $item_values['menu_order'] = $attachment->menu_order;
906
+ $item_values['date'] = $attachment->post_date;
907
+ $item_values['modified'] = $attachment->post_modified;
908
+ $item_values['parent'] = $attachment->post_parent;
909
+ $item_values['parent_name'] = '';
910
+ $item_values['parent_type'] = '';
911
+ $item_values['parent_title'] = '(' . __( 'Unattached', 'media-library-assistant' ) . ')';
912
+ $item_values['parent_date'] = '';
913
+ $item_values['parent_permalink'] = '';
914
+ $item_values['title'] = wptexturize( $attachment->post_title );
915
+ $item_values['slug'] = wptexturize( $attachment->post_name );
916
+ $item_values['width'] = '';
917
+ $item_values['height'] = '';
918
+ $item_values['orientation'] = '';
919
+ $item_values['image_meta'] = '';
920
+ $item_values['image_alt'] = '';
921
+ $item_values['base_file'] = '';
922
+ $item_values['path'] = '';
923
+ $item_values['file'] = '';
924
+ $item_values['description'] = wptexturize( $attachment->post_content );
925
+ $item_values['file_url'] = wptexturize( $attachment->guid );
926
+ $item_values['author_id'] = $attachment->post_author;
927
+ $item_values['caption'] = '';
928
+ $item_values['captiontag_content'] = '';
929
+
930
+ $user = get_user_by( 'id', $attachment->post_author );
931
+ if ( isset( $user->data->display_name ) ) {
932
+ $item_values['author'] = wptexturize( $user->data->display_name );
933
+ } else {
934
+ $item_values['author'] = __( 'unknown', 'media-library-assistant' );
935
+ }
936
+
937
+ $post_meta = MLAQuery::mla_fetch_attachment_metadata( $attachment->ID );
938
+ $base_file = $post_meta['mla_wp_attached_file'];
939
+ $sizes = isset( $post_meta['mla_wp_attachment_metadata']['sizes'] ) ? $post_meta['mla_wp_attachment_metadata']['sizes'] : array();
940
+
941
+ if ( !empty( $post_meta['mla_wp_attachment_metadata']['width'] ) ) {
942
+ $item_values['width'] = $post_meta['mla_wp_attachment_metadata']['width'];
943
+ $width = absint( $item_values['width'] );
944
+ } else {
945
+ $width = 0;
946
+ }
947
+
948
+ if ( !empty( $post_meta['mla_wp_attachment_metadata']['height'] ) ) {
949
+ $item_values['height'] = $post_meta['mla_wp_attachment_metadata']['height'];
950
+ $height = absint( $item_values['height'] );
951
+ } else {
952
+ $height = 0;
953
+ }
954
+
955
+ if ( $width && $height ) {
956
+ $item_values['orientation'] = ( $height > $width ) ? 'portrait' : 'landscape';
957
+ }
958
+
959
+ if ( !empty( $post_meta['mla_wp_attachment_metadata']['image_meta'] ) ) {
960
+ $item_values['image_meta'] = wptexturize( var_export( $post_meta['mla_wp_attachment_metadata']['image_meta'], true ) );
961
+ }
962
+
963
+ if ( !empty( $post_meta['mla_wp_attachment_image_alt'] ) ) {
964
+ if ( is_array( $post_meta['mla_wp_attachment_image_alt'] ) ) {
965
+ $item_values['image_alt'] = wptexturize( $post_meta['mla_wp_attachment_image_alt'][0] );
966
+ } else {
967
+ $item_values['image_alt'] = wptexturize( $post_meta['mla_wp_attachment_image_alt'] );
968
+ }
969
+ }
970
+
971
+ if ( ! empty( $base_file ) ) {
972
+ $last_slash = strrpos( $base_file, '/' );
973
+ if ( false === $last_slash ) {
974
+ $file_name = $base_file;
975
+ $item_values['base_file'] = wptexturize( $base_file );
976
+ $item_values['file'] = wptexturize( $base_file );
977
+ } else {
978
+ $file_name = substr( $base_file, $last_slash + 1 );
979
+ $item_values['base_file'] = wptexturize( $base_file );
980
+ $item_values['path'] = wptexturize( substr( $base_file, 0, $last_slash + 1 ) );
981
+ $item_values['file'] = wptexturize( $file_name );
982
+ }
983
+ } else {
984
+ $file_name = '';
985
+ }
986
+
987
+ if ( 0 < $attachment->post_parent ) {
988
+ $parent_info = MLAQuery::mla_fetch_attachment_parent_data( $attachment->post_parent );
989
+ if ( isset( $parent_info['parent_name'] ) ) {
990
+ $item_values['parent_name'] = $parent_info['parent_name'];
991
+ }
992
+
993
+ if ( isset( $parent_info['parent_type'] ) ) {
994
+ $item_values['parent_type'] = wptexturize( $parent_info['parent_type'] );
995
+ }
996
+
997
+ if ( isset( $parent_info['parent_title'] ) ) {
998
+ $item_values['parent_title'] = wptexturize( $parent_info['parent_title'] );
999
+ }
1000
+
1001
+ if ( isset( $parent_info['parent_date'] ) ) {
1002
+ $item_values['parent_date'] = wptexturize( $parent_info['parent_date'] );
1003
+ }
1004
+
1005
+ $permalink = get_permalink( $attachment->post_parent );
1006
+ if ( false !== $permalink ) {
1007
+ $item_values['parent_permalink'] = $permalink;
1008
+ }
1009
+ } // has parent
1010
+
1011
+ /*
1012
+ * Add attachment-specific field-level substitution parameters
1013
+ */
1014
+ $new_text = isset( $item_template ) ? $item_template : '';
1015
+ foreach( $mla_item_specific_arguments as $index => $value ) {
1016
+ $new_text .= str_replace( '{+', '[+', str_replace( '+}', '+]', $arguments[ $index ] ) );
1017
+ }
1018
+ $item_values = MLAData::mla_expand_field_level_parameters( $new_text, $attr, $item_values, $attachment->ID );
1019
+
1020
+ if ( $item_values['captiontag'] ) {
1021
+ $item_values['caption'] = wptexturize( $attachment->post_excerpt );
1022
+ if ( ! empty( $arguments['mla_caption'] ) ) {
1023
+ $item_values['caption'] = wptexturize( self::_process_shortcode_parameter( $arguments['mla_caption'], $item_values ) );
1024
+ }
1025
+ } else {
1026
+ $item_values['caption'] = '';
1027
+ }
1028
+
1029
+ if ( ! empty( $arguments['mla_link_text'] ) ) {
1030
+ $link_text = self::_process_shortcode_parameter( $arguments['mla_link_text'], $item_values );
1031
+ } else {
1032
+ $link_text = false;
1033
+ }
1034
+
1035
+ /*
1036
+ * As of WP 3.7, this function returns "<a href='$url'>$link_text</a>", where
1037
+ * $link_text can be an image thumbnail or a text link. The "title=" attribute
1038
+ * was dropped. The function is defined in /wp-includes/post-template.php.
1039
+ *
1040
+ * As of WP 4.1, this function has an additional optional parameter, an "Array or
1041
+ * string of attributes", used in the [gallery] shortcode to tie the link to a
1042
+ * caption with 'aria-describedby'. The caption has a matching 'id' attribute
1043
+ * "$selector-#id". See below for the MLA equivalent processing.
1044
+ */
1045
+ $item_values['pagelink'] = wp_get_attachment_link($attachment->ID, $size, true, $show_icon, $link_text);
1046
+ $item_values['filelink'] = wp_get_attachment_link($attachment->ID, $size, false, $show_icon, $link_text);
1047
+
1048
+ if ( in_array( $attachment->post_mime_type, array( 'image/svg+xml' ) ) ) {
1049
+ $registered_dimensions = self::_registered_dimensions();
1050
+ if ( isset( $registered_dimensions[ $size_class ] ) ) {
1051
+ $dimensions = $registered_dimensions[ $size_class ];
1052
+ } else {
1053
+ $dimensions = $registered_dimensions['thumbnail'];
1054
+ }
1055
+
1056
+ $thumb = preg_replace( '/width=\"[^\"]*\"/', sprintf( 'width="%1$d"', $dimensions[1] ), $item_values['pagelink'] );
1057
+ $item_values['pagelink'] = preg_replace( '/height=\"[^\"]*\"/', sprintf( 'height="%1$d"', $dimensions[0] ), $thumb );
1058
+ $thumb = preg_replace( '/width=\"[^\"]*\"/', sprintf( 'width="%1$d"', $dimensions[1] ), $item_values['filelink'] );
1059
+ $item_values['filelink'] = preg_replace( '/height=\"[^\"]*\"/', sprintf( 'height="%1$d"', $dimensions[0] ), $thumb );
1060
+ } // SVG thumbnail
1061
+
1062
+ /*
1063
+ * Apply the Gallery Display Content parameters.
1064
+ * Note that $link_attributes and $rollover_text
1065
+ * are used in the Google Viewer code below
1066
+ */
1067
+ $link_attributes = '';
1068
+ if ( ! empty( $arguments['mla_rollover_text'] ) ) {
1069
+ $rollover_text = esc_attr( self::_process_shortcode_parameter( $arguments['mla_rollover_text'], $item_values ) );
1070
+
1071
+ /*
1072
+ * The "title=" attribute was removed in WP 3.7+, but look for it anyway.
1073
+ * If it's not there, add the "title=" value to the link attributes.
1074
+ */
1075
+ if ( false === strpos( $item_values['pagelink'], ' title=' ) ) {
1076
+ $link_attributes .= 'title="' . $rollover_text . '" ';
1077
+ }else {
1078
+ /*
1079
+ * Replace single- and double-quote delimited values
1080
+ */
1081
+ $item_values['pagelink'] = preg_replace('# title=\'([^\']*)\'#', " title='{$rollover_text}'", $item_values['pagelink'] );
1082
+ $item_values['pagelink'] = preg_replace('# title=\"([^\"]*)\"#', " title=\"{$rollover_text}\"", $item_values['pagelink'] );
1083
+ $item_values['filelink'] = preg_replace('# title=\'([^\']*)\'#', " title='{$rollover_text}'", $item_values['filelink'] );
1084
+ $item_values['filelink'] = preg_replace('# title=\"([^\"]*)\"#', " title=\"{$rollover_text}\"", $item_values['filelink'] );
1085
+ }
1086
+ } else {
1087
+ $rollover_text = esc_attr( $item_values['title'] );
1088
+ }
1089
+
1090
+ if ( ! empty( $arguments['mla_target'] ) ) {
1091
+ $link_attributes .= 'target="' . $arguments['mla_target'] . '" ';
1092
+ }
1093
+
1094
+ if ( ! empty( $arguments['mla_link_attributes'] ) ) {
1095
+ $link_attributes .= self::_process_shortcode_parameter( $arguments['mla_link_attributes'], $item_values ) . ' ';
1096
+ }
1097
+
1098
+ if ( ! empty( $arguments['mla_link_class'] ) ) {
1099
+ $link_attributes .= 'class="' . self::_process_shortcode_parameter( $arguments['mla_link_class'], $item_values ) . '" ';
1100
+ }
1101
+
1102
+ if ( ! empty( $link_attributes ) ) {
1103
+ $item_values['pagelink'] = str_replace( '<a href=', '<a ' . $link_attributes . 'href=', $item_values['pagelink'] );
1104
+ $item_values['filelink'] = str_replace( '<a href=', '<a ' . $link_attributes . 'href=', $item_values['filelink'] );
1105
+ }
1106
+
1107
+ /*
1108
+ * Process the <img> tag, if present
1109
+ * Note that $image_attributes, $image_class and $image_alt
1110
+ * are used in the Google Viewer code below
1111
+ */
1112
+ if ( ! empty( $arguments['mla_image_attributes'] ) ) {
1113
+ $image_attributes = self::_process_shortcode_parameter( $arguments['mla_image_attributes'], $item_values ) . ' ';
1114
+ } else {
1115
+ $image_attributes = '';
1116
+ }
1117
+
1118
+ /*
1119
+ * WordPress 4.1 ties the <img> tag to the caption with 'aria-describedby'
1120
+ * has a matching 'id' attribute "$selector-#id".
1121
+ */
1122
+ if ( trim( $item_values['caption'] ) && ( false === strpos( $image_attributes, 'aria-describedby=' ) ) && ( 'default' == $item_values['mla_markup'] ) ) {
1123
+ $image_attributes .= 'aria-describedby="' . $item_values['selector'] . '-' . $item_values['attachment_ID'] . '" ';
1124
+ }
1125
+
1126
+ if ( ! empty( $arguments['mla_image_class'] ) ) {
1127
+ $image_class = esc_attr( self::_process_shortcode_parameter( $arguments['mla_image_class'], $item_values ) );
1128
+ } else {
1129
+ $image_class = '';
1130
+ }
1131
+
1132
+ if ( ! empty( $arguments['mla_image_alt'] ) ) {
1133
+ $image_alt = esc_attr( self::_process_shortcode_parameter( $arguments['mla_image_alt'], $item_values ) );
1134
+ } else {
1135
+ $image_alt = '';
1136
+ }
1137
+
1138
+ /*
1139
+ * Look for alt= and class= attributes in $image_attributes. If found,
1140
+ * they override and completely replace the corresponding values.
1141
+ */
1142
+ $class_replace = false;
1143
+ if ( ! empty( $image_attributes ) ) {
1144
+ $match_count = preg_match( '#alt=(([\'\"])([^\']+?)\2)#', $image_attributes, $matches, PREG_OFFSET_CAPTURE );
1145
+ if ( 1 === $match_count ) {
1146
+ $image_alt = $matches[3][0];
1147
+ $image_attributes = substr_replace( $image_attributes, '', $matches[0][1], strlen( $matches[0][0] ) );
1148
+ }
1149
+
1150
+ $match_count = preg_match( '#class=(([\'\"])([^\']+?)\2)#', $image_attributes, $matches, PREG_OFFSET_CAPTURE );
1151
+ if ( 1 === $match_count ) {
1152
+ $class_replace = true;
1153
+ $image_class = $matches[3][0];
1154
+ $image_attributes = substr_replace( $image_attributes, '', $matches[0][1], strlen( $matches[0][0] ) );
1155
+ }
1156
+
1157
+ $image_attributes = trim( $image_attributes );
1158
+ if ( ! empty( $image_attributes ) ) {
1159
+ $image_attributes .= ' ';
1160
+ }
1161
+ }
1162
+
1163
+ if ( false !== strpos( $item_values['pagelink'], '<img ' ) ) {
1164
+ if ( ! empty( $image_attributes ) ) {
1165
+ $item_values['pagelink'] = str_replace( '<img ', '<img ' . $image_attributes, $item_values['pagelink'] );
1166
+ $item_values['filelink'] = str_replace( '<img ', '<img ' . $image_attributes, $item_values['filelink'] );
1167
+ }
1168
+
1169
+ /*
1170
+ * Extract existing class values and add to them
1171
+ */
1172
+ if ( ! empty( $image_class ) ) {
1173
+ $match_count = preg_match_all( '# class=\"([^\"]+)\" #', $item_values['pagelink'], $matches, PREG_OFFSET_CAPTURE );
1174
+ if ( ! ( $class_replace || ( $match_count == false ) || ( $match_count == 0 ) ) ) {
1175
+ $class = $matches[1][0][0] . ' ' . $image_class;
1176
+ } else {
1177
+ $class = $image_class;
1178
+ }
1179
+
1180
+ $item_values['pagelink'] = preg_replace('# class=\"([^\"]*)\"#', " class=\"{$class}\"", $item_values['pagelink'] );
1181
+ $item_values['filelink'] = preg_replace('# class=\"([^\"]*)\"#', " class=\"{$class}\"", $item_values['filelink'] );
1182
+ }
1183
+
1184
+ if ( ! empty( $image_alt ) ) {
1185
+ $item_values['pagelink'] = preg_replace('# alt=\"([^\"]*)\"#', " alt=\"{$image_alt}\"", $item_values['pagelink'] );
1186
+ $item_values['filelink'] = preg_replace('# alt=\"([^\"]*)\"#', " alt=\"{$image_alt}\"", $item_values['filelink'] );
1187
+ }
1188
+ } // process <img> tag
1189
+
1190
+ switch ( $arguments['link'] ) {
1191
+ case 'permalink':
1192
+ case 'post':
1193
+ $item_values['link'] = $item_values['pagelink'];
1194
+ break;
1195
+ case 'file':
1196
+ case 'full':
1197
+ $item_values['link'] = $item_values['filelink'];
1198
+ break;
1199
+ default:
1200
+ $item_values['link'] = $item_values['filelink'];
1201
+
1202
+ /*
1203
+ * Check for link to specific (registered) file size
1204
+ */
1205
+ if ( array_key_exists( $arguments['link'], $sizes ) ) {
1206
+ $target_file = $sizes[ $arguments['link'] ]['file'];
1207
+ $item_values['link'] = str_replace( $file_name, $target_file, $item_values['filelink'] );
1208
+ }
1209
+ } // switch 'link'
1210
+
1211
+ /*
1212
+ * Extract target and thumbnail fields
1213
+ */
1214
+ $match_count = preg_match_all( '#href=\'([^\']+)\'#', $item_values['pagelink'], $matches, PREG_OFFSET_CAPTURE );
1215
+ if ( ! ( ( $match_count == false ) || ( $match_count == 0 ) ) ) {
1216
+ $item_values['pagelink_url'] = $matches[1][0][0];
1217
+ } else {
1218
+ $item_values['pagelink_url'] = '';
1219
+ }
1220
+
1221
+ $match_count = preg_match_all( '#href=\'([^\']+)\'#', $item_values['filelink'], $matches, PREG_OFFSET_CAPTURE );
1222
+ if ( ! ( ( $match_count == false ) || ( $match_count == 0 ) ) ) {
1223
+ $item_values['filelink_url'] = $matches[1][0][0];
1224
+ } else {
1225
+ $item_values['filelink_url'] = '';
1226
+ }
1227
+
1228
+ $match_count = preg_match_all( '#href=\'([^\']+)\'#', $item_values['link'], $matches, PREG_OFFSET_CAPTURE );
1229
+ if ( ! ( ( $match_count == false ) || ( $match_count == 0 ) ) ) {
1230
+ $item_values['link_url'] = $matches[1][0][0];
1231
+ } else {
1232
+ $item_values['link_url'] = '';
1233
+ }
1234
+
1235
+ /*
1236
+ * Override the link value; leave filelink and pagelink unchanged
1237
+ * Note that $link_href is used in the Google Viewer code below
1238
+ */
1239
+ if ( ! empty( $arguments['mla_link_href'] ) ) {
1240
+ $link_href = self::_process_shortcode_parameter( $arguments['mla_link_href'], $item_values );
1241
+
1242
+ /*
1243
+ * Replace single- and double-quote delimited values
1244
+ */
1245
+ $item_values['link'] = preg_replace('# href=\'([^\']*)\'#', " href='{$link_href}'", $item_values['link'] );
1246
+ $item_values['link'] = preg_replace('# href=\"([^\"]*)\"#', " href=\"{$link_href}\"", $item_values['link'] );
1247
+ } else {
1248
+ $link_href = '';
1249
+ }
1250
+
1251
+ $match_count = preg_match_all( '#(\<a [^\>]+\>)(.*)\</a\>#', $item_values['link'], $matches, PREG_OFFSET_CAPTURE );
1252
+ if ( ! ( ( $match_count == false ) || ( $match_count == 0 ) ) ) {
1253
+ $link_tag = $matches[1][0][0];
1254
+ $item_values['thumbnail_content'] = $matches[2][0][0];
1255
+ } else {
1256
+ $item_values['thumbnail_content'] = '';
1257
+ }
1258
+
1259
+ $match_count = preg_match_all( '# width=\"([^\"]+)\" height=\"([^\"]+)\" src=\"([^\"]+)\" #', $item_values['link'], $matches, PREG_OFFSET_CAPTURE );
1260
+ if ( ! ( ( $match_count == false ) || ( $match_count == 0 ) ) ) {
1261
+ $item_values['thumbnail_width'] = $matches[1][0][0];
1262
+ $item_values['thumbnail_height'] = $matches[2][0][0];
1263
+ $item_values['thumbnail_url'] = $matches[3][0][0];
1264
+ } else {
1265
+ $item_values['thumbnail_width'] = '';
1266
+ $item_values['thumbnail_height'] = '';
1267
+ $item_values['thumbnail_url'] = '';
1268
+
1269
+ if ( ( 'none' !== $arguments['size'] ) && ( 'checked' == MLACore::mla_get_option( 'enable_featured_image' ) ) ) {
1270
+ /*
1271
+ * Look for the "Featured Image" as an alternate thumbnail for PDFs, etc.
1272
+ */
1273
+ $feature = get_the_post_thumbnail( $attachment->ID, $size, array( 'class' => 'attachment-thumbnail' ) );
1274
+ if ( ! empty( $feature ) ) {
1275
+ $match_count = preg_match_all( '# width=\"([^\"]+)\" height=\"([^\"]+)\" src=\"([^\"]+)\" #', $feature, $matches, PREG_OFFSET_CAPTURE );
1276
+ if ( ! ( ( $match_count == false ) || ( $match_count == 0 ) ) ) {
1277
+ $item_values['link'] = $link_tag . $feature . '</a>';
1278
+ $item_values['thumbnail_content'] = $feature;
1279
+ $item_values['thumbnail_width'] = $matches[1][0][0];
1280
+ $item_values['thumbnail_height'] = $matches[2][0][0];
1281
+ $item_values['thumbnail_url'] = $matches[3][0][0];
1282
+ }
1283
+ }
1284
+ } // enable_featured_image
1285
+ }
1286
+
1287
+ /*
1288
+ * Now that we have thumbnail_content we can check for 'span' and 'none'
1289
+ */
1290
+ if ( 'none' == $arguments['link'] ) {
1291
+ $item_values['link'] = $item_values['thumbnail_content'];
1292
+ } elseif ( 'span' == $arguments['link'] ) {
1293
+ $item_values['link'] = sprintf( '<span %1$s>%2$s</span>', $link_attributes, $item_values['thumbnail_content'] );
1294
+ }
1295
+
1296
+ /*
1297
+ * Check for Imagick thumbnail generation, uses above-defined
1298
+ * $link_attributes (includes target), $rollover_text, $link_href (link only),
1299
+ * $image_attributes, $image_class, $image_alt
1300
+ */
1301
+ if ( $arguments['mla_viewer'] && empty( $item_values['thumbnail_url'] ) ) {
1302
+ /*
1303
+ * Check for a match on file extension
1304
+ */
1305
+ $last_dot = strrpos( $item_values['file'], '.' );
1306
+ if ( !( false === $last_dot) ) {
1307
+ $extension = substr( $item_values['file'], $last_dot + 1 );
1308
+ if ( in_array( $extension, $arguments['mla_viewer_extensions'] ) ) {
1309
+ /*
1310
+ * Default to an icon if thumbnail generation is not available
1311
+ */
1312
+ $icon_url = wp_mime_type_icon( $attachment->ID );
1313
+ $upload_dir = wp_upload_dir();
1314
+ $args = array(
1315
+ 'page' => MLACore::ADMIN_PAGE_SLUG,
1316
+ 'mla_stream_file' => urlencode( $upload_dir['basedir'] . '/' . $item_values['base_file'] ),
1317
+ );
1318
+
1319
+ if ( 'log' == $arguments['mla_debug'] ) {
1320
+ $args['mla_debug'] = 'log';
1321
+ }
1322
+
1323
+ if ( $arguments['mla_single_thread'] ) {
1324
+ $args['mla_single_thread'] = 'true';
1325
+ }
1326
+
1327
+ if ( $arguments['mla_viewer_width'] ) {
1328
+ $args['mla_stream_width'] = $arguments['mla_viewer_width'];
1329
+ }
1330
+
1331
+ if ( $arguments['mla_viewer_height'] ) {
1332
+ $args['mla_stream_height'] = $arguments['mla_viewer_height'];
1333
+ }
1334
+
1335
+ if ( isset( $arguments['mla_viewer_best_fit'] ) ) {
1336
+ $args['mla_stream_fit'] = $arguments['mla_viewer_best_fit'] ? '1' : '0';
1337
+ }
1338
+
1339
+ /*
1340
+ * Non-standard location, if not empty. Write the value to a file that can be
1341
+ * found by the stand-alone (no WordPress) image stream processor.
1342
+ */
1343
+ $ghostscript_path = MLACore::mla_get_option( 'ghostscript_path' );
1344
+ if ( ! empty( $ghostscript_path ) ) {
1345
+ if ( false !== @file_put_contents( dirname( __FILE__ ) . '/' . 'mla-ghostscript-path.txt', $ghostscript_path ) ) {
1346
+ $args['mla_ghostscript_path'] = 'custom';
1347
+ }
1348
+ }
1349
+
1350
+ if ( self::mla_ghostscript_present( $ghostscript_path ) ) {
1351
+ /*
1352
+ * Optional upper limit (in MB) on file size
1353
+ */
1354
+ if ( $limit = ( 1024 * 1024 ) * $arguments['mla_viewer_limit'] ) {
1355
+ $file_size = 0 + @filesize( $item_values['base_dir'] . '/' . $item_values['base_file'] );
1356
+ if ( ( 0 < $file_size ) && ( $file_size > $limit ) ) {
1357
+ $file_size = 0;
1358
+ }
1359
+ } else {
1360
+ $file_size = 1;
1361
+ }
1362
+
1363
+ /*
1364
+ * Generate "real" thumbnail
1365
+ */
1366
+ if ( $file_size ) {
1367
+ $frame = ( 0 < $arguments['mla_viewer_page'] ) ? $arguments['mla_viewer_page'] - 1 : 0;
1368
+ if ( $frame ) {
1369
+ $args['mla_stream_frame'] = $frame;
1370
+ }
1371
+
1372
+ if ( $arguments['mla_viewer_resolution'] ) {
1373
+ $args['mla_stream_resolution'] = $arguments['mla_viewer_resolution'];
1374
+ }
1375
+
1376
+ if ( $arguments['mla_viewer_quality'] ) {
1377
+ $args['mla_stream_quality'] = $arguments['mla_viewer_quality'];
1378
+ }
1379
+
1380
+ if ( ! empty( $arguments['mla_viewer_type'] ) ) {
1381
+ $args['mla_stream_type'] = $arguments['mla_viewer_type'];
1382
+ }
1383
+
1384
+ /*
1385
+ * For efficiency, image streaming is done outside WordPress
1386
+ */
1387
+ $icon_url = add_query_arg( $args, wp_nonce_url( MLA_PLUGIN_URL . 'includes/mla-stream-image.php', MLACore::MLA_ADMIN_NONCE_ACTION, MLACore::MLA_ADMIN_NONCE_NAME ) );
1388
+ }
1389
+ }
1390
+
1391
+ /*
1392
+ * <img> tag (thumbnail_text)
1393
+ */
1394
+ if ( ! empty( $image_class ) ) {
1395
+ $image_class = ' class="' . $image_class . '"';
1396
+ }
1397
+
1398
+ if ( ! empty( $image_alt ) ) {
1399
+ $image_alt = ' alt="' . $image_alt . '"';
1400
+ } elseif ( ! empty( $item_values['caption'] ) ) {
1401
+ $image_alt = ' alt="' . $item_values['caption'] . '"';
1402
+ }
1403
+
1404
+ $item_values['thumbnail_content'] = sprintf( '<img %1$ssrc="%2$s"%3$s%4$s>', $image_attributes, $icon_url, $image_class, $image_alt );
1405
+
1406
+ /*
1407
+ * Filelink, pagelink and link.
1408
+ * The "title=" attribute is in $link_attributes for WP 3.7+.
1409
+ */
1410
+ if ( false === strpos( $link_attributes, 'title=' ) ) {
1411
+ $item_values['pagelink'] = sprintf( '<a %1$shref="%2$s" title="%3$s">%4$s</a>', $link_attributes, $item_values['pagelink_url'], $rollover_text, $item_values['thumbnail_content'] );
1412
+ $item_values['filelink'] = sprintf( '<a %1$shref="%2$s" title="%3$s">%4$s</a>', $link_attributes, $item_values['filelink_url'], $rollover_text, $item_values['thumbnail_content'] );
1413
+ } else {
1414
+ $item_values['pagelink'] = sprintf( '<a %1$shref="%2$s">%3$s</a>', $link_attributes, $item_values['pagelink_url'], $item_values['thumbnail_content'] );
1415
+ $item_values['filelink'] = sprintf( '<a %1$shref="%2$s">%3$s</a>', $link_attributes, $item_values['filelink_url'], $item_values['thumbnail_content'] );
1416
+ }
1417
+ if ( ! empty( $link_href ) ) {
1418
+ $item_values['link'] = sprintf( '<a %1$shref="%2$s" title="%3$s">%4$s</a>', $link_attributes, $link_href, $rollover_text, $item_values['thumbnail_content'] );
1419
+ } elseif ( 'permalink' == $arguments['link'] ) {
1420
+ $item_values['link'] = $item_values['pagelink'];
1421
+ } elseif ( 'file' == $arguments['link'] ) {
1422
+ $item_values['link'] = $item_values['filelink'];
1423
+ } elseif ( 'span' == $arguments['link'] ) {
1424
+ $item_values['link'] = sprintf( '<a %1$s>%2$s</a>', $link_attributes, $item_values['thumbnail_content'] );
1425
+ } else {
1426
+ $item_values['link'] = $item_values['thumbnail_content'];
1427
+ }
1428
+ } // viewer extension
1429
+ } // has extension
1430
+ } // mla_viewer
1431
+
1432
+ if ( $is_gallery ) {
1433
+ /*
1434
+ * Start of row markup
1435
+ */
1436
+ if ( $markup_values['columns'] > 0 && $column_index % $markup_values['columns'] == 0 ) {
1437
+ $markup_values = apply_filters( 'mla_gallery_row_open_values', $markup_values );
1438
+ $row_open_template = apply_filters( 'mla_gallery_row_open_template', $row_open_template );
1439
+ $parse_value = MLAData::mla_parse_template( $row_open_template, $markup_values );
1440
+ $output .= apply_filters( 'mla_gallery_row_open_parse', $parse_value, $row_open_template, $markup_values );
1441
+ }
1442
+
1443
+ /*
1444
+ * item markup
1445
+ */
1446
+ $column_index++;
1447
+ if ( $item_values['columns'] > 0 && $column_index % $item_values['columns'] == 0 ) {
1448
+ $item_values['last_in_row'] = 'last_in_row';
1449
+ } else {
1450
+ $item_values['last_in_row'] = '';
1451
+ }
1452
+
1453
+ /*
1454
+ * Conditional caption tag to replicate WP 4.1+,
1455
+ * now used in the default markup template.
1456
+ */
1457
+ if ( $item_values['captiontag'] && trim( $item_values['caption'] ) ) {
1458
+ $item_values['captiontag_content'] = '<' . $item_values['captiontag'] . " class='wp-caption-text gallery-caption' id='" . $item_values['selector'] . '-' . $item_values['attachment_ID'] . "'>\n\t\t" . $item_values['caption'] . "\n\t</" . $item_values['captiontag'] . ">\n";
1459
+ } else {
1460
+ $item_values['captiontag_content'] = '';
1461
+ }
1462
+
1463
+ $item_values = apply_filters( 'mla_gallery_item_values', $item_values );
1464
+ $item_template = apply_filters( 'mla_gallery_item_template', $item_template );
1465
+ $parse_value = MLAData::mla_parse_template( $item_template, $item_values );
1466
+ $output .= apply_filters( 'mla_gallery_item_parse', $parse_value, $item_template, $item_values );
1467
+
1468
+ /*
1469
+ * End of row markup
1470
+ */
1471
+ if ( $markup_values['columns'] > 0 && $column_index % $markup_values['columns'] == 0 ) {
1472
+ $markup_values = apply_filters( 'mla_gallery_row_close_values', $markup_values );
1473
+ $row_close_template = apply_filters( 'mla_gallery_row_close_template', $row_close_template );
1474
+ $parse_value = MLAData::mla_parse_template( $row_close_template, $markup_values );
1475
+ $output .= apply_filters( 'mla_gallery_row_close_parse', $parse_value, $row_close_template, $markup_values );
1476
+ }
1477
+ } // is_gallery
1478
+ elseif ( ! empty( $link_type ) ) {
1479
+ return $item_values['link'];
1480
+ }
1481
+ } // foreach attachment
1482
+
1483
+ if ($is_gallery ) {
1484
+ /*
1485
+ * Close out partial row
1486
+ */
1487
+ if ( ! ($markup_values['columns'] > 0 && $column_index % $markup_values['columns'] == 0 ) ) {
1488
+ $markup_values = apply_filters( 'mla_gallery_row_close_values', $markup_values );
1489
+ $row_close_template = apply_filters( 'mla_gallery_row_close_template', $row_close_template );
1490
+ $parse_value = MLAData::mla_parse_template( $row_close_template, $markup_values );
1491
+ $output .= apply_filters( 'mla_gallery_row_close_parse', $parse_value, $row_close_template, $markup_values );
1492
+ }
1493
+
1494
+ $markup_values = apply_filters( 'mla_gallery_close_values', $markup_values );
1495
+ $close_template = apply_filters( 'mla_gallery_close_template', $close_template );
1496
+ $parse_value = MLAData::mla_parse_template( $close_template, $markup_values );
1497
+ $output .= apply_filters( 'mla_gallery_close_parse', $parse_value, $close_template, $markup_values );
1498
+ } // is_gallery
1499
+
1500
+ return $output;
1501
+ }
1502
+
1503
+ /**
1504
+ * The MLA Tag Cloud support function.
1505
+ *
1506
+ * This is an alternative to the WordPress wp_tag_cloud function, with additional
1507
+ * options to customize the hyperlink behind each term.
1508
+ *
1509
+ * @since 2.20
1510
+ *
1511
+ * @param array $attr Attributes of the shortcode.
1512
+ *
1513
+ * @return string HTML content to display the tag cloud.
1514
+ */
1515
+ public static function mla_tag_cloud( $attr ) {
1516
+ global $post;
1517
+
1518
+ /*
1519
+ * These are the default parameters for tag cloud display
1520
+ */
1521
+ $mla_item_specific_arguments = array(
1522
+ 'mla_link_attributes' => '',
1523
+ 'mla_link_class' => '',
1524
+ 'mla_link_style' => '',
1525
+ 'mla_link_href' => '',
1526
+ 'mla_link_text' => '',
1527
+ 'mla_nolink_text' => '',
1528
+ 'mla_rollover_text' => '',
1529
+ 'mla_caption' => ''
1530
+ );
1531
+
1532
+ $mla_arguments = array_merge( array(
1533
+ 'mla_output' => 'flat',
1534
+ 'mla_style' => NULL,
1535
+ 'mla_markup' => NULL,
1536
+ 'mla_float' => is_rtl() ? 'right' : 'left',
1537
+ 'mla_itemwidth' => MLACore::mla_get_option('mla_tag_cloud_itemwidth'),
1538
+ 'mla_margin' => MLACore::mla_get_option('mla_tag_cloud_margin'),
1539
+ 'mla_target' => '',
1540
+ 'mla_debug' => false,
1541
+
1542
+ // Pagination parameters
1543
+ 'term_id' => NULL,
1544
+ 'mla_end_size'=> 1,
1545
+ 'mla_mid_size' => 2,
1546
+ 'mla_prev_text' => '&laquo; ' . __( 'Previous', 'media-library-assistant' ),
1547
+ 'mla_next_text' => __( 'Next', 'media-library-assistant' ) . ' &raquo;',
1548
+ 'mla_page_parameter' => 'mla_cloud_current',
1549
+ 'mla_cloud_current' => NULL,
1550
+ 'mla_paginate_total' => NULL,
1551
+ 'mla_paginate_type' => 'plain'),
1552
+ $mla_item_specific_arguments
1553
+ );
1554
+
1555
+ $defaults = array_merge(
1556
+ self::$mla_get_terms_parameters,
1557
+ array(
1558
+ 'smallest' => 8,
1559
+ 'largest' => 22,
1560
+ 'unit' => 'pt',
1561
+ 'separator' => "\n",
1562
+ 'single_text' => '%d item',
1563
+ 'multiple_text' => '%d items',
1564
+
1565
+ 'echo' => false,
1566
+ 'link' => 'view',
1567
+ 'current_item' => '',
1568
+ 'current_item_class' => 'mla_current_item',
1569
+
1570
+ 'itemtag' => 'ul',
1571
+ 'termtag' => 'li',
1572
+ 'captiontag' => '',
1573
+ 'columns' => MLACore::mla_get_option('mla_tag_cloud_columns')
1574
+ ),
1575
+ $mla_arguments
1576
+ );
1577
+
1578
+ /*
1579
+ * The mla_paginate_current parameter can be changed to support multiple galleries per page.
1580
+ */
1581
+ if ( ! isset( $attr['mla_page_parameter'] ) ) {
1582
+ $attr['mla_page_parameter'] = $defaults['mla_page_parameter'];
1583
+ }
1584
+
1585
+ $mla_page_parameter = $attr['mla_page_parameter'];
1586
+
1587
+ /*
1588
+ * Special handling of mla_page_parameter to make
1589
+ * "MLA pagination" easier. Look for this parameter in $_REQUEST
1590
+ * if it's not present in the shortcode itself.
1591
+ */
1592
+ if ( ! isset( $attr[ $mla_page_parameter ] ) ) {
1593
+ if ( isset( $_REQUEST[ $mla_page_parameter ] ) ) {
1594
+ $attr[ $mla_page_parameter ] = $_REQUEST[ $mla_page_parameter ];
1595
+ }
1596
+ }
1597
+
1598
+ // $instance supports multiple clouds in one page/post
1599
+ static $instance = 0;
1600
+ $instance++;
1601
+
1602
+ /*
1603
+ * Some values are already known, and can be used in data selection parameters
1604
+ */
1605
+ $upload_dir = wp_upload_dir();
1606
+ $page_values = array(
1607
+ 'instance' => $instance,
1608
+ 'selector' => "mla_tag_cloud-{$instance}",
1609
+ 'site_url' => site_url(),
1610
+ 'base_url' => $upload_dir['baseurl'],
1611
+ 'base_dir' => $upload_dir['basedir'],
1612
+ 'id' => $post->ID,
1613
+ 'page_ID' => $post->ID,
1614
+ 'page_author' => $post->post_author,
1615
+ 'page_date' => $post->post_date,
1616
+ 'page_content' => $post->post_content,
1617
+ 'page_title' => $post->post_title,
1618
+ 'page_excerpt' => $post->post_excerpt,
1619
+ 'page_status' => $post->post_status,
1620
+ 'page_name' => $post->post_name,
1621
+ 'page_modified' => $post->post_modified,
1622
+ 'page_guid' => $post->guid,
1623
+ 'page_type' => $post->post_type,
1624
+ 'page_url' => get_page_link(),
1625
+ );
1626
+
1627
+ /*
1628
+ * Look for 'request' substitution parameters,
1629
+ * which can be added to any input parameter
1630
+ */
1631
+ foreach ( $attr as $attr_key => $attr_value ) {
1632
+ /*
1633
+ * item-specific Display Content parameters must be evaluated
1634
+ * later, when all of the information is available.
1635
+ */
1636
+ if ( array_key_exists( $attr_key, $mla_item_specific_arguments ) ) {
1637
+ continue;
1638
+ }
1639
+
1640
+ $attr_value = str_replace( '{+', '[+', str_replace( '+}', '+]', $attr_value ) );
1641
+ $replacement_values = MLAData::mla_expand_field_level_parameters( $attr_value, NULL, $page_values );
1642
+ $attr[ $attr_key ] = MLAData::mla_parse_template( $attr_value, $replacement_values );
1643
+ }
1644
+
1645
+ $attr = apply_filters( 'mla_tag_cloud_attributes', $attr );
1646
+ $arguments = shortcode_atts( $defaults, $attr );
1647
+
1648
+ /*
1649
+ * $mla_page_parameter, if non-default, doesn't make it through the shortcode_atts filter,
1650
+ * so we handle it separately
1651
+ */
1652
+ if ( ! isset( $arguments[ $mla_page_parameter ] ) ) {
1653
+ if ( isset( $attr[ $mla_page_parameter ] ) ) {
1654
+ $arguments[ $mla_page_parameter ] = $attr[ $mla_page_parameter ];
1655
+ } else {
1656
+ $arguments[ $mla_page_parameter ] = $defaults['mla_cloud_current'];
1657
+
1658
+ }
1659
+ }
1660
+
1661
+ /*
1662
+ * Process the pagination parameter, if present
1663
+ */
1664
+ if ( isset( $arguments[ $mla_page_parameter ] ) ) {
1665
+ $arguments['offset'] = $arguments['limit'] * ( $arguments[ $mla_page_parameter ] - 1);
1666
+ }
1667
+
1668
+ /*
1669
+ * Clean up the current_item to separate term_id from slug
1670
+ */
1671
+ if ( ! empty( $arguments['current_item'] ) && ctype_digit( $arguments['current_item'] ) ) {
1672
+ $arguments['current_item'] = absint( $arguments['current_item'] );
1673
+ }
1674
+
1675
+ $arguments = apply_filters( 'mla_tag_cloud_arguments', $arguments );
1676
+
1677
+ self::$mla_debug = ( ! empty( $arguments['mla_debug'] ) ) ? trim( strtolower( $arguments['mla_debug'] ) ) : false;
1678
+ if ( self::$mla_debug ) {
1679
+ if ( 'true' == self::$mla_debug ) {
1680
+ MLACore::mla_debug_mode( 'buffer' );
1681
+ } elseif ( 'log' == self::$mla_debug ) {
1682
+ MLACore::mla_debug_mode( 'log' );
1683
+ } else {
1684
+ self::$mla_debug = false;
1685
+ }
1686
+ }
1687
+
1688
+ if ( self::$mla_debug ) {
1689
+ MLACore::mla_debug_add( '<strong>' . __( 'mla_debug attributes', 'media-library-assistant' ) . '</strong> = ' . var_export( $attr, true ) );
1690
+ MLACore::mla_debug_add( '<strong>' . __( 'mla_debug arguments', 'media-library-assistant' ) . '</strong> = ' . var_export( $arguments, true ) );
1691
+ }
1692
+
1693
+ /*
1694
+ * Determine output type and templates
1695
+ */
1696
+ $output_parameters = array_map( 'strtolower', array_map( 'trim', explode( ',', $arguments['mla_output'] ) ) );
1697
+
1698
+ if ( $is_grid = 'grid' == $output_parameters[0] ) {
1699
+ $default_style = MLACore::mla_get_option('default_tag_cloud_style');
1700
+ $default_markup = MLACore::mla_get_option('default_tag_cloud_markup');
1701
+
1702
+ if ( NULL == $arguments['mla_style'] ) {
1703
+ $arguments['mla_style'] = $default_style;
1704
+ }
1705
+
1706
+ if ( NULL == $arguments['mla_markup'] ) {
1707
+ $arguments['mla_markup'] = $default_markup;
1708
+ $arguments['itemtag'] = 'dl';
1709
+ $arguments['termtag'] = 'dt';
1710
+ $arguments['captiontag'] = 'dd';
1711
+ }
1712
+ }
1713
+
1714
+ if ( $is_list = 'list' == $output_parameters[0] ) {
1715
+ $default_style = 'none';
1716
+ if ( empty( $arguments['captiontag'] ) ) {
1717
+ $default_markup = 'tag-cloud-ul';
1718
+ } else {
1719
+ $default_markup = 'tag-cloud-dl';
1720
+
1721
+ if ( 'dd' == $arguments['captiontag'] ) {
1722
+ $arguments['itemtag'] = 'dl';
1723
+ $arguments['termtag'] = 'dt';
1724
+ }
1725
+ }
1726
+
1727
+ if ( NULL == $arguments['mla_style'] ) {
1728
+ $arguments['mla_style'] = $default_style;
1729
+ }
1730
+
1731
+ if ( NULL == $arguments['mla_markup'] ) {
1732
+ $arguments['mla_markup'] = $default_markup;
1733
+ }
1734
+ }
1735
+
1736
+ $is_pagination = in_array( $output_parameters[0], array( 'previous_link', 'current_link', 'next_link', 'previous_page', 'next_page', 'paginate_links' ) );
1737
+
1738
+ /*
1739
+ * Convert lists to arrays
1740
+ */
1741
+ if ( is_string( $arguments['taxonomy'] ) ) {
1742
+ $arguments['taxonomy'] = explode( ',', $arguments['taxonomy'] );
1743
+ }
1744
+
1745
+ if ( is_string( $arguments['post_type'] ) ) {
1746
+ $arguments['post_type'] = explode( ',', $arguments['post_type'] );
1747
+ }
1748
+
1749
+ if ( is_string( $arguments['post_status'] ) ) {
1750
+ $arguments['post_status'] = explode( ',', $arguments['post_status'] );
1751
+ }
1752
+
1753
+ $tags = self::mla_get_terms( $arguments );
1754
+
1755
+ if ( self::$mla_debug ) {
1756
+ $cloud = MLACore::mla_debug_flush();
1757
+ } else {
1758
+ $cloud = '';
1759
+ }
1760
+
1761
+ /*
1762
+ * Invalid taxonomy names return WP_Error
1763
+ */
1764
+ if ( is_wp_error( $tags ) ) {
1765
+ $cloud .= '<strong>' . __( 'ERROR', 'media-library-assistant' ) . ': ' . $tags->get_error_message() . '</strong>, ' . $tags->get_error_data( $tags->get_error_code() );
1766
+
1767
+ if ( 'array' == $arguments['mla_output'] ) {
1768
+ return array( $cloud );
1769
+ }
1770
+
1771
+ if ( empty($arguments['echo']) ) {
1772
+ return $cloud;
1773
+ }
1774
+
1775
+ echo $cloud;
1776
+ return;
1777
+ }
1778
+
1779
+ if ( empty( $tags ) ) {
1780
+ if ( self::$mla_debug ) {
1781
+ MLACore::mla_debug_add( '<strong>' . __( 'mla_debug empty cloud', 'media-library-assistant' ) . '</strong>, query = ' . var_export( $arguments, true ) );
1782
+ $cloud = MLACore::mla_debug_flush();
1783
+ }
1784
+
1785
+ $cloud .= $arguments['mla_nolink_text'];
1786
+ if ( 'array' == $arguments['mla_output'] ) {
1787
+ return array( $cloud );
1788
+ }
1789
+
1790
+ if ( empty($arguments['echo']) ) {
1791
+ return $cloud;
1792
+ }
1793
+
1794
+ echo $cloud;
1795
+ return;
1796
+ }
1797
+
1798
+ /*
1799
+ * Fill in the item_specific link properties, calculate cloud parameters
1800
+ */
1801
+ if ( isset( $tags['found_rows'] ) ) {
1802
+ $found_rows = $tags['found_rows'];
1803
+ unset( $tags['found_rows'] );
1804
+ } else {
1805
+ $found_rows = count( $tags );
1806
+ }
1807
+
1808
+ $min_count = 0x7FFFFFFF;
1809
+ $max_count = 0;
1810
+ $min_scaled_count = 0x7FFFFFFF;
1811
+ $max_scaled_count = 0;
1812
+ foreach ( $tags as $key => $tag ) {
1813
+ $tag_count = isset ( $tag->count ) ? $tag->count : 0;
1814
+ $tag->scaled_count = apply_filters( 'mla_tag_cloud_scale', round(log10($tag_count + 1) * 100), $attr, $arguments, $tag );
1815
+
1816
+ if ( $tag_count < $min_count ) {
1817
+ $min_count = $tag_count;
1818
+ }
1819
+
1820
+ if ( $tag_count > $max_count ) {
1821
+ $max_count = $tag_count;
1822
+ }
1823
+
1824
+ if ( $tag->scaled_count < $min_scaled_count ) {
1825
+ $min_scaled_count = $tag->scaled_count;
1826
+ }
1827
+
1828
+ if ( $tag->scaled_count > $max_scaled_count ) {
1829
+ $max_scaled_count = $tag->scaled_count;
1830
+ }
1831
+
1832
+ $link = get_edit_tag_link( $tag->term_id, $tag->taxonomy );
1833
+ if ( ! is_wp_error( $link ) ) {
1834
+ $tags[ $key ]->edit_link = $link;
1835
+ $link = get_term_link( intval($tag->term_id), $tag->taxonomy );
1836
+ $tags[ $key ]->term_link = $link;
1837
+ }
1838
+
1839
+ if ( is_wp_error( $link ) ) {
1840
+ $cloud = '<strong>' . __( 'ERROR', 'media-library-assistant' ) . ': ' . $link->get_error_message() . '</strong>, ' . $link->get_error_data( $link->get_error_code() );
1841
+
1842
+ if ( 'array' == $arguments['mla_output'] ) {
1843
+ return array( $cloud );
1844
+ }
1845
+
1846
+ if ( empty($arguments['echo']) ) {
1847
+ return $cloud;
1848
+ }
1849
+
1850
+ echo $cloud;
1851
+ return;
1852
+ }
1853
+
1854
+ if ( 'edit' == $arguments['link'] ) {
1855
+ $tags[ $key ]->link = $tags[ $key ]->edit_link;
1856
+ } else {
1857
+ $tags[ $key ]->link = $tags[ $key ]->term_link;
1858
+ }
1859
+ } // foreach tag
1860
+
1861
+ /*
1862
+ * The default MLA style template includes "margin: 1.5%" to put a bit of
1863
+ * minimum space between the columns. "mla_margin" can be used to change
1864
+ * this. "mla_itemwidth" can be used with "columns=0" to achieve a
1865
+ * "responsive" layout.
1866
+ */
1867
+
1868
+ $columns = absint( $arguments['columns'] );
1869
+ $margin_string = strtolower( trim( $arguments['mla_margin'] ) );
1870
+
1871
+ if ( is_numeric( $margin_string ) && ( 0 != $margin_string) ) {
1872
+ $margin_string .= '%'; // Legacy values are always in percent
1873
+ }
1874
+
1875
+ if ( '%' == substr( $margin_string, -1 ) ) {
1876
+ $margin_percent = (float) substr( $margin_string, 0, strlen( $margin_string ) - 1 );
1877
+ } else {
1878
+ $margin_percent = 0;
1879
+ }
1880
+
1881
+ $width_string = strtolower( trim( $arguments['mla_itemwidth'] ) );
1882
+ if ( 'none' != $width_string ) {
1883
+ switch ( $width_string ) {
1884
+ case 'exact':
1885
+ $margin_percent = 0;
1886
+ // fallthru
1887
+ case 'calculate':
1888
+ $width_string = $columns > 0 ? (floor(1000/$columns)/10) - ( 2.0 * $margin_percent ) : 100 - ( 2.0 * $margin_percent );
1889
+ // fallthru
1890
+ default:
1891
+ if ( is_numeric( $width_string ) && ( 0 != $width_string) ) {
1892
+ $width_string .= '%'; // Legacy values are always in percent
1893
+ }
1894
+ }
1895
+ } // $use_width
1896
+
1897
+ $float = strtolower( $arguments['mla_float'] );
1898
+ if ( ! in_array( $float, array( 'left', 'none', 'right' ) ) ) {
1899
+ $float = is_rtl() ? 'right' : 'left';
1900
+ }
1901
+
1902
+ /*
1903
+ * Calculate cloud parameters
1904
+ */
1905
+ $spread = $max_scaled_count - $min_scaled_count;
1906
+ if ( $spread <= 0 ) {
1907
+ $spread = 1;
1908
+ }
1909
+
1910
+ $font_spread = $arguments['largest'] - $arguments['smallest'];
1911
+ if ( $font_spread < 0 ) {
1912
+ $font_spread = 1;
1913
+ }
1914
+
1915
+ $font_step = $font_spread / $spread;
1916
+
1917
+ $style_values = array_merge( $page_values, array(
1918
+ 'mla_output' => $arguments['mla_output'],
1919
+ 'mla_style' => $arguments['mla_style'],
1920
+ 'mla_markup' => $arguments['mla_markup'],
1921
+ 'taxonomy' => implode( '-', $arguments['taxonomy'] ),
1922
+ 'current_item' => $arguments['current_item'],
1923
+ 'itemtag' => tag_escape( $arguments['itemtag'] ),
1924
+ 'termtag' => tag_escape( $arguments['termtag'] ),
1925
+ 'captiontag' => tag_escape( $arguments['captiontag'] ),
1926
+ 'columns' => $columns,
1927
+ 'itemwidth' => $width_string,
1928
+ 'margin' => $margin_string,
1929
+ 'float' => $float,
1930
+ 'found_rows' => $found_rows,
1931
+ 'min_count' => $min_count,
1932
+ 'max_count' => $max_count,
1933
+ 'min_scaled_count' => $min_scaled_count,
1934
+ 'max_scaled_count' => $max_scaled_count,
1935
+ 'spread' => $spread,
1936
+ 'smallest' => $arguments['smallest'],
1937
+ 'largest' => $arguments['largest'],
1938
+ 'unit' => $arguments['unit'],
1939
+ 'font_spread' => $font_spread,
1940
+ 'font_step' => $font_step,
1941
+ 'separator' => $arguments['separator'],
1942
+ 'single_text' => $arguments['single_text'],
1943
+ 'multiple_text' => $arguments['multiple_text'],
1944
+ 'echo' => $arguments['echo'],
1945
+ 'link' => $arguments['link']
1946
+ ) );
1947
+
1948
+ $style_template = $gallery_style = '';
1949
+ $use_mla_tag_cloud_style = ( $is_grid || $is_list ) && ( 'none' != strtolower( $style_values['mla_style'] ) );
1950
+ if ( apply_filters( 'use_mla_tag_cloud_style', $use_mla_tag_cloud_style, $style_values['mla_style'] ) ) {
1951
+ $style_template = MLAShortcode_support::mla_fetch_gallery_template( $style_values['mla_style'], 'style' );
1952
+ if ( empty( $style_template ) ) {
1953
+ $style_values['mla_style'] = $default_style;
1954
+ $style_template = MLAShortcode_support::mla_fetch_gallery_template( $default_style, 'style' );
1955
+ }
1956
+
1957
+ if ( ! empty ( $style_template ) ) {
1958
+ /*
1959
+ * Look for 'query' and 'request' substitution parameters
1960
+ */
1961
+ $style_values = MLAData::mla_expand_field_level_parameters( $style_template, $attr, $style_values );
1962
+
1963
+ /*
1964
+ * Clean up the template to resolve width or margin == 'none'
1965
+ */
1966
+ if ( 'none' == $margin_string ) {
1967
+ $style_values['margin'] = '0';
1968
+ $style_template = preg_replace( '/margin:[\s]*\[\+margin\+\][\%]*[\;]*/', '', $style_template );
1969
+ }
1970
+
1971
+ if ( 'none' == $width_string ) {
1972
+ $style_values['itemwidth'] = 'auto';
1973
+ $style_template = preg_replace( '/width:[\s]*\[\+itemwidth\+\][\%]*[\;]*/', '', $style_template );
1974
+ }
1975
+
1976
+ $style_values = apply_filters( 'mla_tag_cloud_style_values', $style_values );
1977
+ $style_template = apply_filters( 'mla_tag_cloud_style_template', $style_template );
1978
+ $gallery_style = MLAData::mla_parse_template( $style_template, $style_values );
1979
+ $gallery_style = apply_filters( 'mla_tag_cloud_style_parse', $gallery_style, $style_template, $style_values );
1980
+ } // !empty template
1981
+ } // use_mla_tag_cloud_style
1982
+
1983
+ $markup_values = $style_values;
1984
+
1985
+ if ( $is_grid || $is_list ) {
1986
+ $open_template = MLAShortcode_support::mla_fetch_gallery_template( $markup_values['mla_markup'] . '-open', 'markup' );
1987
+ if ( false === $open_template ) {
1988
+ $markup_values['mla_markup'] = $default_markup;
1989
+ $open_template = MLAShortcode_support::mla_fetch_gallery_template( $default_markup, 'markup' );
1990
+ }
1991
+
1992
+ if ( empty( $open_template ) ) {
1993
+ $open_template = '';
1994
+ }
1995
+
1996
+ if ( $is_grid ) {
1997
+ $row_open_template = MLAShortcode_support::mla_fetch_gallery_template( $markup_values['mla_markup'] . '-row-open', 'markup' );
1998
+ if ( empty( $row_open_template ) ) {
1999
+ $row_open_template = '';
2000
+ }
2001
+ } else {
2002
+ $row_open_template = '';
2003
+ }
2004
+
2005
+ $item_template = MLAShortcode_support::mla_fetch_gallery_template( $markup_values['mla_markup'] . '-item', 'markup' );
2006
+ if ( empty( $item_template ) ) {
2007
+ $item_template = '';
2008
+ }
2009
+
2010
+ if ( $is_grid ) {
2011
+ $row_close_template = MLAShortcode_support::mla_fetch_gallery_template( $markup_values['mla_markup'] . '-row-close', 'markup' );
2012
+ if ( empty( $row_close_template ) ) {
2013
+ $row_close_template = '';
2014
+ }
2015
+ } else {
2016
+ $row_close_template = '';
2017
+ }
2018
+
2019
+ $close_template = MLAShortcode_support::mla_fetch_gallery_template( $markup_values['mla_markup'] . '-close', 'markup' );
2020
+ if ( empty( $close_template ) ) {
2021
+ $close_template = '';
2022
+ }
2023
+
2024
+ /*
2025
+ * Look for gallery-level markup substitution parameters
2026
+ */
2027
+ $new_text = $open_template . $row_open_template . $row_close_template . $close_template;
2028
+ $markup_values = MLAData::mla_expand_field_level_parameters( $new_text, $attr, $markup_values );
2029
+
2030
+ $markup_values = apply_filters( 'mla_tag_cloud_open_values', $markup_values );
2031
+ $open_template = apply_filters( 'mla_tag_cloud_open_template', $open_template );
2032
+ if ( empty( $open_template ) ) {
2033
+ $gallery_open = '';
2034
+ } else {
2035
+ $gallery_open = MLAData::mla_parse_template( $open_template, $markup_values );
2036
+ }
2037
+
2038
+ $gallery_open = apply_filters( 'mla_tag_cloud_open_parse', $gallery_open, $open_template, $markup_values );
2039
+ $cloud .= $gallery_style . $gallery_open;
2040
+ } // is_grid || is_list
2041
+ elseif ( $is_pagination ) {
2042
+ /*
2043
+ * Handle 'previous_page', 'next_page', and 'paginate_links'
2044
+ */
2045
+ if ( isset( $attr['limit'] ) ) {
2046
+ $attr['posts_per_page'] = $attr['limit'];
2047
+ }
2048
+
2049
+ $pagination_result = self::_process_pagination_output_types( $output_parameters, $markup_values, $arguments, $attr, $found_rows );
2050
+ if ( false !== $pagination_result ) {
2051
+ return $pagination_result;
2052
+ }
2053
+
2054
+ /*
2055
+ * For "previous_link", "current_link" and "next_link", discard all of the $tags except the appropriate choice
2056
+ */
2057
+ $link_type = $output_parameters[0];
2058
+
2059
+ if ( ! in_array( $link_type, array ( 'previous_link', 'current_link', 'next_link' ) ) ) {
2060
+ return ''; // unknown output type
2061
+ }
2062
+
2063
+ $is_wrap = isset( $output_parameters[1] ) && 'wrap' == $output_parameters[1];
2064
+ if ( empty( $arguments['term_id'] ) ) {
2065
+ $target_id = -2; // won't match anything
2066
+ } else {
2067
+ $current_id = $arguments['term_id'];
2068
+
2069
+ foreach ( $tags as $id => $tag ) {
2070
+ if ( $tag->term_id == $current_id ) {
2071
+ break;
2072
+ }
2073
+ }
2074
+
2075
+ switch ( $link_type ) {
2076
+ case 'previous_link':
2077
+ $target_id = $id - 1;
2078
+ break;
2079
+ case 'next_link':
2080
+ $target_id = $id + 1;
2081
+ break;
2082
+ case 'current_link':
2083
+ default:
2084
+ $target_id = $id;
2085
+ } // link_type
2086
+ }
2087
+
2088
+ $target = NULL;
2089
+ if ( isset( $tags[ $target_id ] ) ) {
2090
+ $target = $tags[ $target_id ];
2091
+ } elseif ( $is_wrap ) {
2092
+ switch ( $link_type ) {
2093
+ case 'previous_link':
2094
+ $target = array_pop( $tags );
2095
+ break;
2096
+ case 'next_link':
2097
+ $target = array_shift( $tags );
2098
+ } // link_type
2099
+ } // is_wrap
2100
+
2101
+ if ( isset( $target ) ) {
2102
+ $tags = array( $target );
2103
+ } elseif ( ! empty( $arguments['mla_nolink_text'] ) ) {
2104
+ return self::_process_shortcode_parameter( $arguments['mla_nolink_text'], $markup_values ) . '</a>';
2105
+ } else {
2106
+ return '';
2107
+ }
2108
+ } // is_pagination
2109
+
2110
+ /*
2111
+ * Accumulate links for flat and array output
2112
+ */
2113
+ $tag_links = array();
2114
+
2115
+ $column_index = 0;
2116
+ foreach ( $tags as $key => $tag ) {
2117
+ $item_values = $markup_values;
2118
+
2119
+ /*
2120
+ * fill in item-specific elements
2121
+ */
2122
+ $item_values['index'] = (string) 1 + $column_index;
2123
+ if ( $item_values['columns'] > 0 && ( 1 + $column_index ) % $item_values['columns'] == 0 ) {
2124
+ $item_values['last_in_row'] = 'last_in_row';
2125
+ } else {
2126
+ $item_values['last_in_row'] = '';
2127
+ }
2128
+
2129
+ $item_values['key'] = $key;
2130
+ $item_values['term_id'] = $tag->term_id;
2131
+ $item_values['name'] = wptexturize( $tag->name );
2132
+ $item_values['slug'] = wptexturize( $tag->slug );
2133
+ $item_values['term_group'] = $tag->term_group;
2134
+ $item_values['term_taxonomy_id'] = $tag->term_taxonomy_id;
2135
+ $item_values['taxonomy'] = wptexturize( $tag->taxonomy );
2136
+ $item_values['current_item_class'] = '';
2137
+ $item_values['description'] = wptexturize( $tag->description );
2138
+ $item_values['parent'] = $tag->parent;
2139
+ $item_values['count'] = isset ( $tag->count ) ? $tag->count : 0;
2140
+ $item_values['scaled_count'] = $tag->scaled_count;
2141
+ $item_values['font_size'] = str_replace( ',', '.', ( $item_values['smallest'] + ( ( $item_values['scaled_count'] - $item_values['min_scaled_count'] ) * $item_values['font_step'] ) ) );
2142
+ $item_values['link_url'] = $tag->link;
2143
+ $item_values['editlink_url'] = $tag->edit_link;
2144
+ $item_values['termlink_url'] = $tag->term_link;
2145
+ // Added in the code below:
2146
+ // 'caption', 'link_attributes', 'current_item_class', 'rollover_text', 'link_style', 'link_text', 'editlink', 'termlink', 'thelink'
2147
+
2148
+ if ( ! empty( $arguments['current_item'] ) ) {
2149
+ if ( is_integer( $arguments['current_item'] ) ) {
2150
+ if ( $arguments['current_item'] == $tag->term_id ) {
2151
+ $item_values['current_item_class'] = $arguments['current_item_class'];
2152
+ }
2153
+ } else {
2154
+ if ( $arguments['current_item'] == $tag->slug ) {
2155
+ $item_values['current_item_class'] = $arguments['current_item_class'];
2156
+ }
2157
+ }
2158
+ }
2159
+
2160
+ /*
2161
+ * Add item_specific field-level substitution parameters
2162
+ */
2163
+ $new_text = isset( $item_template ) ? $item_template : '';
2164
+ foreach( $mla_item_specific_arguments as $index => $value ) {
2165
+ $new_text .= str_replace( '{+', '[+', str_replace( '+}', '+]', $arguments[ $index ] ) );
2166
+ }
2167
+
2168
+ $item_values = MLAData::mla_expand_field_level_parameters( $new_text, $attr, $item_values );
2169
+
2170
+ if ( $item_values['captiontag'] ) {
2171
+ $item_values['caption'] = wptexturize( $tag->description );
2172
+ if ( ! empty( $arguments['mla_caption'] ) ) {
2173
+ $item_values['caption'] = wptexturize( self::_process_shortcode_parameter( $arguments['mla_caption'], $item_values ) );
2174
+ }
2175
+ } else {
2176
+ $item_values['caption'] = '';
2177
+ }
2178
+
2179
+ if ( ! empty( $arguments['mla_link_text'] ) ) {
2180
+ $link_text = self::_process_shortcode_parameter( $arguments['mla_link_text'], $item_values );
2181
+ } else {
2182
+ $link_text = false;
2183
+ }
2184
+
2185
+ /*
2186
+ * Apply the Display Content parameters.
2187
+ */
2188
+ if ( ! empty( $arguments['mla_target'] ) ) {
2189
+ $link_attributes = 'target="' . $arguments['mla_target'] . '" ';
2190
+ } else {
2191
+ $link_attributes = '';
2192
+ }
2193
+
2194
+ if ( ! empty( $arguments['mla_link_attributes'] ) ) {
2195
+ $link_attributes .= self::_process_shortcode_parameter( $arguments['mla_link_attributes'], $item_values ) . ' ';
2196
+ }
2197
+
2198
+ if ( ! empty( $arguments['mla_link_class'] ) ) {
2199
+ $link_attributes .= 'class="' . self::_process_shortcode_parameter( $arguments['mla_link_class'], $item_values ) . '" ';
2200
+ }
2201
+
2202
+ $item_values['link_attributes'] = $link_attributes;
2203
+
2204
+ $item_values['rollover_text'] = sprintf( _n( $item_values['single_text'], $item_values['multiple_text'], $item_values['count'], 'media-library-assistant' ), number_format_i18n( $item_values['count'] ) );
2205
+ if ( ! empty( $arguments['mla_rollover_text'] ) ) {
2206
+ $item_values['rollover_text'] = esc_attr( self::_process_shortcode_parameter( $arguments['mla_rollover_text'], $item_values ) );
2207
+ }
2208
+
2209
+ if ( ! empty( $arguments['mla_link_href'] ) ) {
2210
+ $link_href = self::_process_shortcode_parameter( $arguments['mla_link_href'], $item_values );
2211
+ $item_values['link_url'] = $link_href;
2212
+ } else {
2213
+ $link_href = '';
2214
+ }
2215
+
2216
+ if ( ! empty( $arguments['mla_link_style'] ) ) {
2217
+ $item_values['link_style'] = esc_attr( self::_process_shortcode_parameter( $arguments['mla_link_style'], $item_values ) );
2218
+ } else {
2219
+ $item_values['link_style'] = 'font-size: ' . $item_values['font_size'] . $item_values['unit'];
2220
+ }
2221
+
2222
+ if ( ! empty( $arguments['mla_link_text'] ) ) {
2223
+ $item_values['link_text'] = esc_attr( self::_process_shortcode_parameter( $arguments['mla_link_text'], $item_values ) );
2224
+ } else {
2225
+ $item_values['link_text'] = $item_values['name'];
2226
+ }
2227
+
2228
+ /*
2229
+ * Editlink, termlink and thelink
2230
+ */
2231
+ $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'] );
2232
+ $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'] );
2233
+
2234
+ if ( ! empty( $link_href ) ) {
2235
+ $item_values['thelink'] = sprintf( '<a %1$shref="%2$s" title="%3$s" style="%4$s">%5$s</a>', $link_attributes, $link_href, $item_values['rollover_text'], $item_values['link_style'], $item_values['link_text'] );
2236
+ } elseif ( 'edit' == $arguments['link'] ) {
2237
+ $item_values['thelink'] = $item_values['editlink'];
2238
+ } elseif ( 'view' == $arguments['link'] ) {
2239
+ $item_values['thelink'] = $item_values['termlink'];
2240
+ } elseif ( 'span' == $arguments['link'] ) {
2241
+ $item_values['thelink'] = sprintf( '<span %1$sstyle="%2$s">%3$s</a>', $link_attributes, $item_values['link_style'], $item_values['link_text'] );
2242
+ } else {
2243
+ $item_values['thelink'] = $item_values['link_text'];
2244
+ }
2245
+
2246
+ if ( $is_grid || $is_list ) {
2247
+ /*
2248
+ * Start of row markup
2249
+ */
2250
+ if ( $is_grid && ( $markup_values['columns'] > 0 && $column_index % $markup_values['columns'] == 0 ) ) {
2251
+ $markup_values = apply_filters( 'mla_tag_cloud_row_open_values', $markup_values );
2252
+ $row_open_template = apply_filters( 'mla_tag_cloud_row_open_template', $row_open_template );
2253
+ $parse_value = MLAData::mla_parse_template( $row_open_template, $markup_values );
2254
+ $cloud .= apply_filters( 'mla_tag_cloud_row_open_parse', $parse_value, $row_open_template, $markup_values );
2255
+ }
2256
+
2257
+ /*
2258
+ * item markup
2259
+ */
2260
+ $column_index++;
2261
+ $item_values = apply_filters( 'mla_tag_cloud_item_values', $item_values );
2262
+ $item_template = apply_filters( 'mla_tag_cloud_item_template', $item_template );
2263
+ $parse_value = MLAData::mla_parse_template( $item_template, $item_values );
2264
+ $cloud .= apply_filters( 'mla_tag_cloud_item_parse', $parse_value, $item_template, $item_values );
2265
+
2266
+ /*
2267
+ * End of row markup
2268
+ */
2269
+ if ( $is_grid && ( $markup_values['columns'] > 0 && $column_index % $markup_values['columns'] == 0 ) ) {
2270
+ $markup_values = apply_filters( 'mla_tag_cloud_row_close_values', $markup_values );
2271
+ $row_close_template = apply_filters( 'mla_tag_cloud_row_close_template', $row_close_template );
2272
+ $parse_value = MLAData::mla_parse_template( $row_close_template, $markup_values );
2273
+ $cloud .= apply_filters( 'mla_tag_cloud_row_close_parse', $parse_value, $row_close_template, $markup_values );
2274
+ }
2275
+ } // is_grid || is_list
2276
+ elseif ( $is_pagination ) {
2277
+ return $item_values['thelink'];
2278
+ } else {
2279
+ $column_index++;
2280
+ $item_values = apply_filters( 'mla_tag_cloud_item_values', $item_values );
2281
+ $tag_links[] = apply_filters( 'mla_tag_cloud_item_parse', $item_values['thelink'], NULL, $item_values );
2282
+ }
2283
+ } // foreach tag
2284
+
2285
+ if ($is_grid || $is_list ) {
2286
+ /*
2287
+ * Close out partial row
2288
+ */
2289
+ if ( $is_grid && ( ! ($markup_values['columns'] > 0 && $column_index % $markup_values['columns'] == 0 ) ) ) {
2290
+ $markup_values = apply_filters( 'mla_tag_cloud_row_close_values', $markup_values );
2291
+ $row_close_template = apply_filters( 'mla_tag_cloud_row_close_template', $row_close_template );
2292
+ $parse_value = MLAData::mla_parse_template( $row_close_template, $markup_values );
2293
+ $cloud .= apply_filters( 'mla_tag_cloud_row_close_parse', $parse_value, $row_close_template, $markup_values );
2294
+ }
2295
+
2296
+ $markup_values = apply_filters( 'mla_tag_cloud_close_values', $markup_values );
2297
+ $close_template = apply_filters( 'mla_tag_cloud_close_template', $close_template );
2298
+ $parse_value = MLAData::mla_parse_template( $close_template, $markup_values );
2299
+ $cloud .= apply_filters( 'mla_tag_cloud_close_parse', $parse_value, $close_template, $markup_values );
2300
+ } // is_grid || is_list
2301
+ else {
2302
+ switch ( $markup_values['mla_output'] ) {
2303
+ case 'array' :
2304
+ $cloud =& $tag_links;
2305
+ break;
2306
+ case 'flat' :
2307
+ default :
2308
+ $cloud .= join( $markup_values['separator'], $tag_links );
2309
+ break;
2310
+ } // switch format
2311
+ }
2312
+
2313
+ //$cloud = wp_generate_tag_cloud( $tags, $arguments );
2314
+
2315
+ if ( 'array' == $arguments['mla_output'] || empty($arguments['echo']) ) {
2316
+ return $cloud;
2317
+ }
2318
+
2319
+ echo $cloud;
2320
+ }
2321
+
2322
+ /**
2323
+ * The MLA Tag Cloud shortcode.
2324
+ *
2325
+ * This is an interface to the mla_tag_cloud function.
2326
+ *
2327
+ * @since 2.20
2328
+ *
2329
+ * @param array $attr Attributes of the shortcode.
2330
+ *
2331
+ * @return string HTML content to display the tag cloud.
2332
+ */
2333
+ public static function mla_tag_cloud_shortcode( $attr ) {
2334
+ /*
2335
+ * Make sure $attr is an array, even if it's empty,
2336
+ * and repair damage caused by link-breaks in the source text
2337
+ */
2338
+ $attr = self::_validate_attributes( $attr );
2339
+
2340
+ /*
2341
+ * The 'array' format makes no sense in a shortcode
2342
+ */
2343
+ if ( isset( $attr['mla_output'] ) && 'array' == $attr['mla_output'] ) {
2344
+ $attr['mla_output'] = 'flat';
2345
+ }
2346
+
2347
+ /*
2348
+ * A shortcode must return its content to the caller, so "echo" makes no sense
2349
+ */
2350
+ $attr['echo'] = false;
2351
+
2352
+ return self::mla_tag_cloud( $attr );
2353
+ }
2354
+
2355
+ /**
2356
+ * Computes image dimensions for scalable graphics, e.g., SVG
2357
+ *
2358
+ * @since 2.20
2359
+ *
2360
+ * @return array
2361
+ */
2362
+ private static function _registered_dimensions() {
2363
+ global $_wp_additional_image_sizes;
2364
+
2365
+ if ( 'checked' == MLACore::mla_get_option( MLACore::MLA_ENABLE_MLA_ICONS ) ) {
2366
+ $sizes = array( 'icon' => array( 64, 64 ) );
2367
+ } else {
2368
+ $sizes = array( 'icon' => array( 60, 60 ) );
2369
+ }
2370
+
2371
+ foreach( get_intermediate_image_sizes() as $s ) {
2372
+ $sizes[ $s ] = array( 0, 0 );
2373
+
2374
+ if( in_array( $s, array( 'thumbnail', 'medium', 'large' ) ) ) {
2375
+ $sizes[ $s ][0] = get_option( $s . '_size_w' );
2376
+ $sizes[ $s ][1] = get_option( $s . '_size_h' );
2377
+ } else {
2378
+ if( isset( $_wp_additional_image_sizes ) && isset( $_wp_additional_image_sizes[ $s ] ) ) {
2379
+ $sizes[ $s ] = array( $_wp_additional_image_sizes[ $s ]['width'], $_wp_additional_image_sizes[ $s ]['height'], );
2380
+ }
2381
+ }
2382
+ }
2383
+
2384
+ return $sizes;
2385
+ }
2386
+
2387
+ /**
2388
+ * Handles brace/bracket escaping and parses template for a shortcode parameter
2389
+ *
2390
+ * @since 2.20
2391
+ *
2392
+ * @param string raw shortcode parameter, e.g., "text {+field+} {brackets} \\{braces\\}"
2393
+ * @param string template substitution values, e.g., ('instance' => '1', ... )
2394
+ *
2395
+ * @return string parameter with brackets, braces, substitution parameters and templates processed
2396
+ */
2397
+ private static function _process_shortcode_parameter( $text, $markup_values ) {
2398
+ $new_text = str_replace( '{', '[', str_replace( '}', ']', $text ) );
2399
+ $new_text = str_replace( '\[', '{', str_replace( '\]', '}', $new_text ) );
2400
+ return MLAData::mla_parse_template( $new_text, $markup_values );
2401
+ }
2402
+
2403
+ /**
2404
+ * Handles pagnation output types 'previous_page', 'next_page', and 'paginate_links'
2405
+ *
2406
+ * @since 2.20
2407
+ *
2408
+ * @param array value(s) for mla_output_type parameter
2409
+ * @param string template substitution values, e.g., ('instance' => '1', ... )
2410
+ * @param string merged default and passed shortcode parameter values
2411
+ * @param integer number of attachments in the gallery, without pagination
2412
+ * @param string output text so far, may include debug values
2413
+ *
2414
+ * @return mixed false or string with HTML for pagination output types
2415
+ */
2416
+ private static function _paginate_links( $output_parameters, $markup_values, $arguments, $found_rows, $output = '' ) {
2417
+ if ( 2 > $markup_values['last_page'] ) {
2418
+ return '';
2419
+ }
2420
+
2421
+ $show_all = $prev_next = false;
2422
+
2423
+ if ( isset ( $output_parameters[1] ) ) {
2424
+ switch ( $output_parameters[1] ) {
2425
+ case 'show_all':
2426
+ $show_all = true;
2427
+ break;
2428
+ case 'prev_next':
2429
+ $prev_next = true;
2430
+ }
2431
+ }
2432
+
2433
+ $mla_page_parameter = $arguments['mla_page_parameter'];
2434
+ $current_page = $markup_values['current_page'];
2435
+ $last_page = $markup_values['last_page'];
2436
+ $end_size = absint( $arguments['mla_end_size'] );
2437
+ $mid_size = absint( $arguments['mla_mid_size'] );
2438
+ $posts_per_page = $markup_values['posts_per_page'];
2439
+
2440
+ $new_target = ( ! empty( $arguments['mla_target'] ) ) ? 'target="' . $arguments['mla_target'] . '" ' : '';
2441
+
2442
+ /*
2443
+ * these will add to the default classes
2444
+ */
2445
+ $new_class = ( ! empty( $arguments['mla_link_class'] ) ) ? ' ' . esc_attr( self::_process_shortcode_parameter( $arguments['mla_link_class'], $markup_values ) ) : '';
2446
+
2447
+ $new_attributes = ( ! empty( $arguments['mla_link_attributes'] ) ) ? esc_attr( self::_process_shortcode_parameter( $arguments['mla_link_attributes'], $markup_values ) ) . ' ' : '';
2448
+
2449
+ //$new_base = ( ! empty( $arguments['mla_link_href'] ) ) ? esc_attr( self::_process_shortcode_parameter( $arguments['mla_link_href'], $markup_values ) ) : $markup_values['new_url'];
2450
+ $new_base = ( ! empty( $arguments['mla_link_href'] ) ) ? self::_process_shortcode_parameter( $arguments['mla_link_href'], $markup_values ) : $markup_values['new_url'];
2451
+
2452
+ /*
2453
+ * Build the array of page links
2454
+ */
2455
+ $page_links = array();
2456
+ $dots = false;
2457
+
2458
+ if ( $prev_next && $current_page && 1 < $current_page ) {
2459
+ $markup_values['new_page'] = $current_page - 1;
2460
+ $new_title = ( ! empty( $arguments['mla_rollover_text'] ) ) ? 'title="' . esc_attr( self::_process_shortcode_parameter( $arguments['mla_rollover_text'], $markup_values ) ) . '" ' : '';
2461
+ $new_url = remove_query_arg( $mla_page_parameter, $new_base );
2462
+ $new_url = add_query_arg( array( $mla_page_parameter => $current_page - 1 ), $new_url );
2463
+ $prev_text = ( ! empty( $arguments['mla_prev_text'] ) ) ? esc_attr( self::_process_shortcode_parameter( $arguments['mla_prev_text'], $markup_values ) ) : '&laquo; ' . __( 'Previous', 'media-library-assistant' );
2464
+ $page_links[] = sprintf( '<a %1$sclass="prev page-numbers%2$s" %3$s%4$shref="%5$s">%6$s</a>',
2465
+ /* %1$s */ $new_target,
2466
+ /* %2$s */ $new_class,
2467
+ /* %3$s */ $new_attributes,
2468
+ /* %4$s */ $new_title,
2469
+ /* %5$s */ $new_url,
2470
+ /* %6$s */ $prev_text );
2471
+ }
2472
+
2473
+ for ( $new_page = 1; $new_page <= $last_page; $new_page++ ) {
2474
+ $new_page_display = number_format_i18n( $new_page );
2475
+ $markup_values['new_page'] = $new_page;
2476
+ $new_title = ( ! empty( $arguments['mla_rollover_text'] ) ) ? 'title="' . esc_attr( self::_process_shortcode_parameter( $arguments['mla_rollover_text'], $markup_values ) ) . '" ' : '';
2477
+
2478
+ if ( $new_page == $current_page ) {
2479
+ // build current page span
2480
+ $page_links[] = sprintf( '<span class="page-numbers current%1$s">%2$s</span>',
2481
+ /* %1$s */ $new_class,
2482
+ /* %2$s */ $new_page_display );
2483
+ $dots = true;
2484
+ } else {
2485
+ if ( $show_all || ( $new_page <= $end_size || ( $current_page && $new_page >= $current_page - $mid_size && $new_page <= $current_page + $mid_size ) || $new_page > $last_page - $end_size ) ) {
2486
+ // build link
2487
+ $new_url = remove_query_arg( $mla_page_parameter, $new_base );
2488
+ $new_url = add_query_arg( array( $mla_page_parameter => $new_page ), $new_url );
2489
+ $page_links[] = sprintf( '<a %1$sclass="page-numbers%2$s" %3$s%4$shref="%5$s">%6$s</a>',
2490
+ /* %1$s */ $new_target,
2491
+ /* %2$s */ $new_class,
2492
+ /* %3$s */ $new_attributes,
2493
+ /* %4$s */ $new_title,
2494
+ /* %5$s */ $new_url,
2495
+ /* %6$s */ $new_page_display );
2496
+ $dots = true;
2497
+ } elseif ( $dots && ! $show_all ) {
2498
+ // build link
2499
+ $page_links[] = sprintf( '<span class="page-numbers dots%1$s">&hellip;</span>',
2500
+ /* %1$s */ $new_class );
2501
+ $dots = false;
2502
+ }
2503
+ } // ! current
2504
+ } // for $new_page
2505
+
2506
+ if ( $prev_next && $current_page && ( $current_page < $last_page || -1 == $last_page ) ) {
2507
+ // build next link
2508
+ $markup_values['new_page'] = $current_page + 1;
2509
+ $new_title = ( ! empty( $arguments['mla_rollover_text'] ) ) ? 'title="' . esc_attr( self::_process_shortcode_parameter( $arguments['mla_rollover_text'], $markup_values ) ) . '" ' : '';
2510
+ $new_url = remove_query_arg( $mla_page_parameter, $new_base );
2511
+ $new_url = add_query_arg( array( $mla_page_parameter => $current_page + 1 ), $new_url );
2512
+ $next_text = ( ! empty( $arguments['mla_next_text'] ) ) ? esc_attr( self::_process_shortcode_parameter( $arguments['mla_next_text'], $markup_values ) ) : __( 'Next', 'media-library-assistant' ) . ' &raquo;';
2513
+ $page_links[] = sprintf( '<a %1$sclass="next page-numbers%2$s" %3$s%4$shref="%5$s">%6$s</a>',
2514
+ /* %1$s */ $new_target,
2515
+ /* %2$s */ $new_class,
2516
+ /* %3$s */ $new_attributes,
2517
+ /* %4$s */ $new_title,
2518
+ /* %5$s */ $new_url,
2519
+ /* %6$s */ $next_text );
2520
+ }
2521
+
2522
+ switch ( strtolower( trim( $arguments['mla_paginate_type'] ) ) ) {
2523
+ case 'list':
2524
+ $results = "<ul class='page-numbers'>\n\t<li>";
2525
+ $results .= join("</li>\n\t<li>", $page_links);
2526
+ $results .= "</li>\n</ul>\n";
2527
+ break;
2528
+ case 'plain':
2529
+ default:
2530
+ $results = join("\n", $page_links);
2531
+ } // mla_paginate_type
2532
+
2533
+ return $output . $results;
2534
+ }
2535
+
2536
+ /**
2537
+ * Handles pagnation output types 'previous_page', 'next_page', and 'paginate_links'
2538
+ *
2539
+ * @since 2.20
2540
+ *
2541
+ * @param array value(s) for mla_output_type parameter
2542
+ * @param string template substitution values, e.g., ('instance' => '1', ... )
2543
+ * @param string merged default and passed shortcode parameter values
2544
+ * @param string raw passed shortcode parameter values
2545
+ * @param integer number of attachments in the gallery, without pagination
2546
+ * @param string output text so far, may include debug values
2547
+ *
2548
+ * @return mixed false or string with HTML for pagination output types
2549
+ */
2550
+ private static function _process_pagination_output_types( $output_parameters, $markup_values, $arguments, $attr, $found_rows, $output = '' ) {
2551
+ if ( ! in_array( $output_parameters[0], array( 'previous_page', 'next_page', 'paginate_links' ) ) ) {
2552
+ return false;
2553
+ }
2554
+
2555
+ /*
2556
+ * Add data selection parameters to gallery-specific and mla_gallery-specific parameters
2557
+ */
2558
+ $arguments = array_merge( $arguments, shortcode_atts( self::$mla_get_shortcode_attachments_parameters, $attr ) );
2559
+ $posts_per_page = absint( $arguments['posts_per_page'] );
2560
+ $mla_page_parameter = $arguments['mla_page_parameter'];
2561
+
2562
+ /*
2563
+ * $mla_page_parameter, if set, doesn't make it through the shortcode_atts filter,
2564
+ * so we handle it separately
2565
+ */
2566
+ if ( ! isset( $arguments[ $mla_page_parameter ] ) ) {
2567
+ if ( isset( $attr[ $mla_page_parameter ] ) ) {
2568
+ $arguments[ $mla_page_parameter ] = $attr[ $mla_page_parameter ];
2569
+ } else {
2570
+ $arguments[ $mla_page_parameter ] = '';
2571
+ }
2572
+ }
2573
+
2574
+ if ( 0 == $posts_per_page ) {
2575
+ $posts_per_page = absint( $arguments['numberposts'] );
2576
+ }
2577
+
2578
+ if ( 0 == $posts_per_page ) {
2579
+ $posts_per_page = absint( get_option('posts_per_page') );
2580
+ }
2581
+
2582
+ if ( 0 < $posts_per_page ) {
2583
+ $max_page = floor( $found_rows / $posts_per_page );
2584
+ if ( $max_page < ( $found_rows / $posts_per_page ) ) {
2585
+ $max_page++;
2586
+ }
2587
+ } else {
2588
+ $max_page = 1;
2589
+ }
2590
+
2591
+ if ( isset( $arguments['mla_paginate_total'] ) && $max_page > absint( $arguments['mla_paginate_total'] ) ) {
2592
+ $max_page = absint( $arguments['mla_paginate_total'] );
2593
+ }
2594
+
2595
+ if ( isset( $arguments[ $mla_page_parameter ] ) ) {
2596
+ $paged = absint( $arguments[ $mla_page_parameter ] );
2597
+ } else {
2598
+ $paged = absint( $arguments['paged'] );
2599
+ }
2600
+
2601
+ if ( 0 == $paged ) {
2602
+ $paged = 1;
2603
+ }
2604
+
2605
+ if ( $max_page < $paged ) {
2606
+ $paged = $max_page;
2607
+ }
2608
+
2609
+ switch ( $output_parameters[0] ) {
2610
+ case 'previous_page':
2611
+ if ( 1 < $paged ) {
2612
+ $new_page = $paged - 1;
2613
+ } else {
2614
+ $new_page = 0;
2615
+
2616
+ if ( isset ( $output_parameters[1] ) ) {
2617
+ switch ( $output_parameters[1] ) {
2618
+ case 'wrap':
2619
+ $new_page = $max_page;
2620
+ break;
2621
+ case 'first':
2622
+ $new_page = 1;
2623
+ }
2624
+ }
2625
+ }
2626
+
2627
+ break;
2628
+ case 'next_page':
2629
+ if ( $paged < $max_page ) {
2630
+ $new_page = $paged + 1;
2631
+ } else {
2632
+ $new_page = 0;
2633
+
2634
+ if ( isset ( $output_parameters[1] ) ) {
2635
+ switch ( $output_parameters[1] ) {
2636
+ case 'last':
2637
+ $new_page = $max_page;
2638
+ break;
2639
+ case 'wrap':
2640
+ $new_page = 1;
2641
+ }
2642
+ }
2643
+ }
2644
+
2645
+ break;
2646
+ case 'paginate_links':
2647
+ $new_page = 0;
2648
+ }
2649
+
2650
+ $markup_values['current_page'] = $paged;
2651
+ $markup_values['new_page'] = $new_page;
2652
+ $markup_values['last_page'] = $max_page;
2653
+ $markup_values['posts_per_page'] = $posts_per_page;
2654
+ $markup_values['found_rows'] = $found_rows;
2655
+
2656
+ if ( $paged ) {
2657
+ $markup_values['current_offset'] = ( $paged - 1 ) * $posts_per_page;
2658
+ } else {
2659
+ $markup_values['current_offset'] = 0;
2660
+ }
2661
+
2662
+ if ( $new_page ) {
2663
+ $markup_values['new_offset'] = ( $new_page - 1 ) * $posts_per_page;
2664
+ } else {
2665
+ $markup_values['new_offset'] = 0;
2666
+ }
2667
+
2668
+ $markup_values['current_page_text'] = 'mla_paginate_current="[+current_page+]"';
2669
+ $markup_values['new_page_text'] = 'mla_paginate_current="[+new_page+]"';
2670
+ $markup_values['last_page_text'] = 'mla_paginate_total="[+last_page+]"';
2671
+ $markup_values['posts_per_page_text'] = 'posts_per_page="[+posts_per_page+]"';
2672
+
2673
+ if ( 'HTTPS' == substr( $_SERVER["SERVER_PROTOCOL"], 0, 5 ) ) {
2674
+ $markup_values['scheme'] = 'https://';
2675
+ } else {
2676
+ $markup_values['scheme'] = 'http://';
2677
+ }
2678
+
2679
+ $markup_values['http_host'] = $_SERVER['HTTP_HOST'];
2680
+
2681
+ if ( 0 < $new_page ) {
2682
+ $new_uri = remove_query_arg( $mla_page_parameter, $_SERVER['REQUEST_URI'] );
2683
+ $markup_values['request_uri'] = add_query_arg( array( $mla_page_parameter => $new_page ), $new_uri );
2684
+ } else {
2685
+ $markup_values['request_uri'] = $_SERVER['REQUEST_URI'];
2686
+ }
2687
+
2688
+ $markup_values['new_url'] = set_url_scheme( $markup_values['scheme'] . $markup_values['http_host'] . $markup_values['request_uri'] );
2689
+
2690
+ /*
2691
+ * Expand pagination-specific Gallery Display Content parameters,
2692
+ * which can contain request: and query: arguments.
2693
+ */
2694
+ $pagination_arguments = array( 'mla_nolink_text', 'mla_link_class', 'mla_rollover_text', 'mla_link_attributes', 'mla_link_href', 'mla_link_text', 'mla_prev_text', 'mla_next_text' );
2695
+
2696
+ $new_text = '';
2697
+ foreach( $pagination_arguments as $value ) {
2698
+ $new_text .= str_replace( '{+', '[+', str_replace( '+}', '+]', $arguments[ $value ] ) );
2699
+ }
2700
+
2701
+ $markup_values = MLAData::mla_expand_field_level_parameters( $new_text, $attr, $markup_values );
2702
+
2703
+ /*
2704
+ * Build the new link, applying Gallery Display Content parameters
2705
+ */
2706
+ if ( 'paginate_links' == $output_parameters[0] ) {
2707
+ return self::_paginate_links( $output_parameters, $markup_values, $arguments, $found_rows, $output );
2708
+ }
2709
+
2710
+ if ( 0 == $new_page ) {
2711
+ if ( ! empty( $arguments['mla_nolink_text'] ) ) {
2712
+ return self::_process_shortcode_parameter( $arguments['mla_nolink_text'], $markup_values );
2713
+ } else {
2714
+ return '';
2715
+ }
2716
+ }
2717
+
2718
+ $new_link = '<a ';
2719
+
2720
+ if ( ! empty( $arguments['mla_target'] ) ) {
2721
+ $new_link .= 'target="' . $arguments['mla_target'] . '" ';
2722
+ }
2723
+
2724
+ if ( ! empty( $arguments['mla_link_class'] ) ) {
2725
+ $new_link .= 'class="' . esc_attr( self::_process_shortcode_parameter( $arguments['mla_link_class'], $markup_values ) ) . '" ';
2726
+ }
2727
+
2728
+ if ( ! empty( $arguments['mla_rollover_text'] ) ) {
2729
+ $new_link .= 'title="' . esc_attr( self::_process_shortcode_parameter( $arguments['mla_rollover_text'], $markup_values ) ) . '" ';
2730
+ }
2731
+
2732
+ if ( ! empty( $arguments['mla_link_attributes'] ) ) {
2733
+ $new_link .= esc_attr( self::_process_shortcode_parameter( $arguments['mla_link_attributes'], $markup_values ) ) . ' ';
2734
+ }
2735
+
2736
+ if ( ! empty( $arguments['mla_link_href'] ) ) {
2737
+ //$new_link .= 'href="' . esc_attr( self::_process_shortcode_parameter( $arguments['mla_link_href'], $markup_values ) ) . '" >';
2738
+ $new_link .= 'href="' . self::_process_shortcode_parameter( $arguments['mla_link_href'], $markup_values ) . '" >';
2739
+ } else {
2740
+ $new_link .= 'href="' . $markup_values['new_url'] . '" >';
2741
+ }
2742
+
2743
+ if ( ! empty( $arguments['mla_link_text'] ) ) {
2744
+ $new_link .= self::_process_shortcode_parameter( $arguments['mla_link_text'], $markup_values ) . '</a>';
2745
+ } else {
2746
+ if ( 'previous_page' == $output_parameters[0] ) {
2747
+ if ( isset( $arguments['mla_prev_text'] ) ) {
2748
+ $new_text = esc_attr( self::_process_shortcode_parameter( $arguments['mla_prev_text'], $markup_values ) );
2749
+ } else {
2750
+ $new_text = '&laquo; ' . __( 'Previous', 'media-library-assistant' );
2751
+ }
2752
+ } else {
2753
+ if ( isset( $arguments['mla_next_text'] ) ) {
2754
+ $new_text = esc_attr( self::_process_shortcode_parameter( $arguments['mla_next_text'], $markup_values ) );
2755
+ } else {
2756
+ $new_text = __( 'Next', 'media-library-assistant' ) . ' &raquo;';
2757
+ }
2758
+ }
2759
+
2760
+ $new_link .= $new_text . '</a>';
2761
+ }
2762
+
2763
+ return $new_link;
2764
+ }
2765
+
2766
+ /**
2767
+ * WP_Query filter "parameters"
2768
+ *
2769
+ * This array defines parameters for the query's join, where and orderby filters.
2770
+ * The parameters are set up in the mla_get_shortcode_attachments function, and
2771
+ * any further logic required to translate those values is contained in the filter.
2772
+ *
2773
+ * Array index values are: orderby, post_parent
2774
+ *
2775
+ * @since 2.20
2776
+ *
2777
+ * @var array
2778
+ */
2779
+ private static $query_parameters = array();
2780
+
2781
+ /**
2782
+ * Cleans up damage caused by the Visual Editor to the tax_query and meta_query specifications
2783
+ *
2784
+ * @since 2.20
2785
+ *
2786
+ * @param string query specification; PHP nested arrays
2787
+ *
2788
+ * @return string query specification with HTML escape sequences and line breaks removed
2789
+ */
2790
+ private static function _sanitize_query_specification( $specification ) {
2791
+ $specification = wp_specialchars_decode( $specification );
2792
+ $specification = str_replace( array( '<br>', '<br />', '<p>', '</p>', "\r", "\n" ), ' ', $specification );
2793
+ return $specification;
2794
+ }
2795
+
2796
+ /**
2797
+ * Translates query parameters to a valid SQL order by clause.
2798
+ *
2799
+ * Accepts one or more valid columns, with or without ASC/DESC.
2800
+ * Enhanced version of /wp-includes/formatting.php function sanitize_sql_orderby().
2801
+ *
2802
+ * @since 2.20
2803
+ *
2804
+ * @param array Validated query parameters; 'order', 'orderby', 'meta_key', 'post__in'.
2805
+ * @param string Optional. Database table prefix; can be empty. Default taken from $wpdb->posts.
2806
+ * @param array Optional. Field names (keys) and database column equivalents (values). Defaults from [mla_gallery].
2807
+ * @param array Optional. Field names (values) that require a BINARY prefix to preserve case order. Default array()
2808
+ * @return string|bool Returns the orderby clause if present, false otherwise.
2809
+ */
2810
+ private static function _validate_sql_orderby( $query_parameters, $table_prefix = NULL, $allowed_keys = NULL, $binary_keys = array() ){
2811
+ global $wpdb;
2812
+
2813
+ $results = array ();
2814
+ $order = isset( $query_parameters['order'] ) ? ' ' . $query_parameters['order'] : '';
2815
+ $orderby = isset( $query_parameters['orderby'] ) ? $query_parameters['orderby'] : '';
2816
+ $meta_key = isset( $query_parameters['meta_key'] ) ? $query_parameters['meta_key'] : '';
2817
+
2818
+ if ( is_null( $table_prefix ) ) {
2819
+ $table_prefix = $wpdb->posts . '.';
2820
+ }
2821
+
2822
+ if ( is_null( $allowed_keys ) ) {
2823
+ $allowed_keys = array(
2824
+ 'empty_orderby_default' => 'post_date',
2825
+ 'explicit_orderby_field' => 'post__in',
2826
+ 'explicit_orderby_column' => 'ID',
2827
+ 'ID' => 'ID',
2828
+ 'author' => 'post_author',
2829
+ 'date' => 'post_date',
2830
+ 'description' => 'post_content',
2831
+ 'content' => 'post_content',
2832
+ 'title' => 'post_title',
2833
+ 'caption' => 'post_excerpt',
2834
+ 'excerpt' => 'post_excerpt',
2835
+ 'slug' => 'post_name',
2836
+ 'name' => 'post_name',
2837
+ 'modified' => 'post_modified',
2838
+ 'parent' => 'post_parent',
2839
+ 'menu_order' => 'menu_order',
2840
+ 'mime_type' => 'post_mime_type',
2841
+ 'comment_count' => 'post_content',
2842
+ 'rand' => 'RAND()',
2843
+ );
2844
+ }
2845
+
2846
+ if ( empty( $orderby ) ) {
2847
+ if ( ! empty( $allowed_keys['empty_orderby_default'] ) ) {
2848
+ return $table_prefix . $allowed_keys['empty_orderby_default'] . " {$order}";
2849
+ } else {
2850
+ return "{$table_prefix}post_date {$order}";
2851
+ }
2852
+ } elseif ( 'none' == $orderby ) {
2853
+ return '';
2854
+ } elseif ( ! empty( $allowed_keys['explicit_orderby_field'] ) ) {
2855
+ $explicit_field = $allowed_keys['explicit_orderby_field'];
2856
+ if ( $orderby == $explicit_field ) {
2857
+ if ( ! empty( $query_parameters[ $explicit_field ] ) ) {
2858
+ $explicit_order = implode(',', array_map( 'absint', $query_parameters[ $explicit_field ] ) );
2859
+
2860
+ if ( ! empty( $explicit_order ) ) {
2861
+ $explicit_column = $allowed_keys['explicit_orderby_column'];
2862
+ return "FIELD( {$table_prefix}{$explicit_column}, {$explicit_order} )";
2863
+ } else {
2864
+ return '';
2865
+ }
2866
+ }
2867
+ }
2868
+ }
2869
+
2870
+ if ( ! empty( $meta_key ) ) {
2871
+ $allowed_keys[ $meta_key ] = "$wpdb->postmeta.meta_value";
2872
+ $allowed_keys['meta_value'] = "$wpdb->postmeta.meta_value";
2873
+ $allowed_keys['meta_value_num'] = "$wpdb->postmeta.meta_value+0";
2874
+ }
2875
+
2876
+ $obmatches = preg_split('/\s*,\s*/', trim($query_parameters['orderby']));
2877
+ foreach ( $obmatches as $index => $value ) {
2878
+ $count = preg_match('/([a-z0-9_]+)(\s+(ASC|DESC))?/i', $value, $matches);
2879
+
2880
+ if ( $count && ( $value == $matches[0] ) && array_key_exists( $matches[1], $allowed_keys ) ) {
2881
+ if ( ( 'rand' == $matches[1] ) || ( 'random' == $matches[1] ) ){
2882
+ $results[] = 'RAND()';
2883
+ } else {
2884
+ switch ( $matches[1] ) {
2885
+ case $meta_key:
2886
+ case 'meta_value':
2887
+ $matches[1] = "$wpdb->postmeta.meta_value";
2888
+ break;
2889
+ case 'meta_value_num':
2890
+ $matches[1] = "$wpdb->postmeta.meta_value+0";
2891
+ break;
2892
+ default:
2893
+ if ( in_array( $matches[1], $binary_keys ) ) {
2894
+ $matches[1] = 'BINARY ' . $table_prefix . $allowed_keys[ $matches[1] ];
2895
+ } else {
2896
+ $matches[1] = $table_prefix . $allowed_keys[ $matches[1] ];
2897
+ }
2898
+ } // switch $matches[1]
2899
+
2900
+ $results[] = isset( $matches[2] ) ? $matches[1] . $matches[2] : $matches[1] . $order;
2901
+ } // not 'rand'
2902
+ } // valid column specification
2903
+ } // foreach $obmatches
2904
+
2905
+ $orderby = implode( ', ', $results );
2906
+ if ( empty( $orderby ) ) {
2907
+ return false;
2908
+ }
2909
+
2910
+ return $orderby;
2911
+ }
2912
+
2913
+ /**
2914
+ * Data selection parameters for the WP_Query in [mla_gallery]
2915
+ *
2916
+ * @since 2.20
2917
+ *
2918
+ * @var array
2919
+ */
2920
+ private static $mla_get_shortcode_attachments_parameters = array(
2921
+ 'order' => 'ASC', // or 'DESC' or 'RAND'
2922
+ 'orderby' => 'menu_order,ID',
2923
+ 'id' => NULL,
2924
+ 'ids' => array(),
2925
+ 'include' => array(),
2926
+ 'exclude' => array(),
2927
+ // MLA extensions, from WP_Query
2928
+ // Force 'get_children' style query
2929
+ 'post_parent' => NULL, // post/page ID, 'none', 'any', 'current' or 'all'
2930
+ // Author
2931
+ 'author' => NULL,
2932
+ 'author_name' => '',
2933
+ // Category
2934
+ 'cat' => 0,
2935
+ 'category_name' => '',
2936
+ 'category__and' => array(),
2937
+ 'category__in' => array(),
2938
+ 'category__not_in' => array(),
2939
+ // Tag
2940
+ 'tag' => '',
2941
+ 'tag_id' => 0,
2942
+ 'tag__and' => array(),
2943
+ 'tag__in' => array(),
2944
+ 'tag__not_in' => array(),
2945
+ 'tag_slug__and' => array(),
2946
+ 'tag_slug__in' => array(),
2947
+ // Taxonomy parameters are handled separately
2948
+ // {tax_slug} => 'term' | array ( 'term', 'term', ... )
2949
+ // 'tax_query' => ''
2950
+ // 'tax_relation' => 'OR', 'AND' (default),
2951
+ // 'tax_operator' => 'OR' (default), 'IN', 'NOT IN', 'AND',
2952
+ // 'tax_include_children' => true (default), false
2953
+ // Post
2954
+ 'post_type' => 'attachment',
2955
+ 'post_status' => 'inherit',
2956
+ 'post_mime_type' => 'image',
2957
+ // Pagination - no default for most of these
2958
+ 'nopaging' => true,
2959
+ 'numberposts' => 0,
2960
+ 'posts_per_page' => 0,
2961
+ 'posts_per_archive_page' => 0,
2962
+ 'paged' => NULL, // page number or 'current'
2963
+ 'offset' => NULL,
2964
+ 'mla_page_parameter' => 'mla_paginate_current',
2965
+ 'mla_paginate_current' => NULL,
2966
+ 'mla_paginate_total' => NULL,
2967
+ // Date and Time Queries
2968
+ 'date_query' => '',
2969
+ // Custom Field
2970
+ 'meta_key' => '',
2971
+ 'meta_value' => '',
2972
+ 'meta_value_num' => NULL,
2973
+ 'meta_compare' => '',
2974
+ 'meta_query' => '',
2975
+ // Terms Search
2976
+ 'mla_terms_phrases' => '',
2977
+ 'mla_terms_taxonomies' => '',
2978
+ 'mla_phrase_connector' => '',
2979
+ 'mla_term_connector' => '',
2980
+ // Search
2981
+ 's' => '',
2982
+ 'mla_search_fields' => '',
2983
+ 'mla_search_connector' => '',
2984
+ 'sentence' => '',
2985
+ 'exact' => '',
2986
+ // Returned fields, for support topic "Adding 'fields' to function mla_get_shortcode_attachments" by leoloso
2987
+ 'fields' => '',
2988
+ // Caching parameters, for support topic "Lag in attachment categories" by Ruriko
2989
+ 'cache_results' => NULL,
2990
+ 'update_post_meta_cache' => NULL,
2991
+ 'update_post_term_cache' => NULL,
2992
+ );
2993
+
2994
+ /**
2995
+ * Parses shortcode parameters and returns the gallery objects
2996
+ *
2997
+ * @since 2.20
2998
+ *
2999
+ * @param int Post ID of the parent
3000
+ * @param array Attributes of the shortcode
3001
+ * @param boolean true to calculate and return ['found_posts'] as an array element
3002
+ *
3003
+ * @return array List of attachments returned from WP_Query
3004
+ */
3005
+ public static function mla_get_shortcode_attachments( $post_parent, $attr, $return_found_rows = NULL ) {
3006
+ global $wp_query;
3007
+
3008
+ /*
3009
+ * Parameters passed to the where and orderby filter functions
3010
+ */
3011
+ self::$query_parameters = array();
3012
+
3013
+ /*
3014
+ * Parameters passed to the posts_search filter function in MLAData
3015
+ */
3016
+ MLAQuery::$search_parameters = array( 'debug' => 'none' );
3017
+
3018
+ /*
3019
+ * Make sure $attr is an array, even if it's empty
3020
+ */
3021
+ if ( empty( $attr ) ) {
3022
+ $attr = array();
3023
+ } elseif ( is_string( $attr ) ) {
3024
+ $attr = shortcode_parse_atts( $attr );
3025
+ }
3026
+
3027
+ /*
3028
+ * The "where used" queries have no $_REQUEST context available to them,
3029
+ * so tax_, date_ and meta_query evaluation will fail if they contain "{+request:"
3030
+ * parameters. Ignore these errors.
3031
+ */
3032
+ if ( isset( $attr['where_used_query'] ) && ( 'this-is-a-where-used-query' == $attr['where_used_query'] ) ) {
3033
+ $where_used_query = true;
3034
+ unset( $attr['where_used_query'] );
3035
+ } else {
3036
+ $where_used_query = false;
3037
+ }
3038
+
3039
+ /*
3040
+ * Merge input arguments with defaults, then extract the query arguments.
3041
+ *
3042
+ * $return_found_rows is used to indicate that the call comes from gallery_shortcode(),
3043
+ * which is the only call that supplies it.
3044
+ */
3045
+ if ( ! is_null( $return_found_rows ) ) {
3046
+ $attr = apply_filters( 'mla_gallery_query_attributes', $attr );
3047
+ }
3048
+
3049
+ $arguments = shortcode_atts( self::$mla_get_shortcode_attachments_parameters, $attr );
3050
+ $mla_page_parameter = $arguments['mla_page_parameter'];
3051
+ unset( $arguments['mla_page_parameter'] );
3052
+
3053
+ /*
3054
+ * $mla_page_parameter, if set, doesn't make it through the shortcode_atts filter,
3055
+ * so we handle it separately
3056
+ */
3057
+ if ( ! isset( $arguments[ $mla_page_parameter ] ) ) {
3058
+ if ( isset( $attr[ $mla_page_parameter ] ) ) {
3059
+ $arguments[ $mla_page_parameter ] = $attr[ $mla_page_parameter ];
3060
+ } else {
3061
+ $arguments[ $mla_page_parameter ] = NULL;
3062
+ }
3063
+ }
3064
+
3065
+ if ( !empty( $arguments['ids'] ) ) {
3066
+ // 'ids' is explicitly ordered, unless you specify otherwise.
3067
+ if ( empty( $attr['orderby'] ) ) {
3068
+ $arguments['orderby'] = 'post__in';
3069
+ }
3070
+
3071
+ $arguments['include'] = $arguments['ids'];
3072
+ }
3073
+ unset( $arguments['ids'] );
3074
+
3075
+ if ( ! is_null( $return_found_rows ) ) {
3076
+ $arguments = apply_filters( 'mla_gallery_query_arguments', $arguments );
3077
+ }
3078
+
3079
+ /*
3080
+ * Extract taxonomy arguments
3081
+ */
3082
+ $query_arguments = array();
3083
+ if ( ! empty( $attr ) ) {
3084
+ $all_taxonomies = get_taxonomies( array ( 'show_ui' => true ), 'names' );
3085
+ $simple_tax_queries = array();
3086
+ foreach ( $attr as $key => $value ) {
3087
+ if ( 'tax_query' == $key ) {
3088
+ if ( is_array( $value ) ) {
3089
+ $query_arguments[ $key ] = $value;
3090
+ } else {
3091
+ $tax_query = NULL;
3092
+ $value = self::_sanitize_query_specification( $value );
3093
+
3094
+ /*
3095
+ * Replace invalid queries from "where-used" callers with a harmless equivalent
3096
+ */
3097
+ if ( $where_used_query && ( false !== strpos( $value, '{+' ) ) ) {
3098
+ $value = "array( array( 'taxonomy' => 'none', 'field' => 'slug', 'terms' => 'none' ) )";
3099
+ }
3100
+
3101
+ $function = @create_function('', 'return ' . $value . ';' );
3102
+ if ( is_callable( $function ) ) {
3103
+ $tax_query = $function();
3104
+ }
3105
+
3106
+ if ( is_array( $tax_query ) ) {
3107
+ $query_arguments[ $key ] = $tax_query;
3108
+ break; // Done - the tax_query overrides all other taxonomy parameters
3109
+ } else {
3110
+ return '<p>' . __( 'ERROR', 'media-library-assistant' ) . ': ' . __( 'Invalid mla_gallery', 'media-library-assistant' ) . ' tax_query = ' . var_export( $value, true ) . '</p>';
3111
+ }
3112
+ } // not array
3113
+ } /* tax_query */ elseif ( array_key_exists( $key, $all_taxonomies ) ) {
3114
+ $simple_tax_queries[ $key ] = implode(',', array_filter( array_map( 'trim', explode( ',', $value ) ) ) );
3115
+ } // array_key_exists
3116
+ } //foreach $attr
3117
+
3118
+ /*
3119
+ * One of five outcomes:
3120
+ * 1) An explicit tax_query was found; use it and ignore all other taxonomy parameters
3121
+ * 2) No tax query is present; no further processing required
3122
+ * 3) Two or more simple tax queries are present; compose a tax_query
3123
+ * 4) One simple tax query and (tax_operator or tax_include_children) are present; compose a tax_query
3124
+ * 5) One simple tax query is present; use it as-is or convert 'category' to 'category_name'
3125
+ */
3126
+ if ( isset( $query_arguments['tax_query'] ) || empty( $simple_tax_queries ) ) {
3127
+ // No further action required
3128
+ } elseif ( ( 1 < count( $simple_tax_queries ) ) || isset( $attr['tax_operator'] ) || isset( $attr['tax_include_children'] ) ) {
3129
+ // Build a tax_query
3130
+ if ( 1 < count( $simple_tax_queries ) ) {
3131
+ $tax_relation = 'AND';
3132
+ if ( isset( $attr['tax_relation'] ) ) {
3133
+ if ( 'OR' == strtoupper( $attr['tax_relation'] ) ) {
3134
+ $tax_relation = 'OR';
3135
+ }
3136
+ }
3137
+ $tax_query = array ('relation' => $tax_relation );
3138
+ } else {
3139
+ $tax_query = array ();
3140
+ }
3141
+
3142
+ // Validate other tax_query parameters or set defaults
3143
+ $tax_operator = 'IN';
3144
+ if ( isset( $attr['tax_operator'] ) ) {
3145
+ $attr_value = strtoupper( $attr['tax_operator'] );
3146
+ if ( in_array( $attr_value, array( 'IN', 'NOT IN', 'AND' ) ) ) {
3147
+ $tax_operator = $attr_value;
3148
+ }
3149
+ }
3150
+
3151
+ $tax_include_children = true;
3152
+ if ( isset( $attr['tax_include_children'] ) ) {
3153
+ if ( 'FALSE' == strtoupper( $attr['tax_include_children'] ) ) {
3154
+ $tax_include_children = false;
3155
+ }
3156
+ }
3157
+
3158
+ foreach( $simple_tax_queries as $key => $value ) {
3159
+ $tax_query[] = array( 'taxonomy' => $key, 'field' => 'slug', 'terms' => explode( ',', $value ), 'operator' => $tax_operator, 'include_children' => $tax_include_children );
3160
+ }
3161
+
3162
+ $query_arguments['tax_query'] = $tax_query;
3163
+ } else {
3164
+ // exactly one simple query is present
3165
+ if ( isset( $simple_tax_queries['category'] ) ) {
3166
+ $arguments['category_name'] = $simple_tax_queries['category'];
3167
+ } else {
3168
+ $query_arguments = $simple_tax_queries;
3169
+ }
3170
+ }
3171
+ } // ! empty
3172
+
3173
+ /*
3174
+ * $query_arguments has been initialized in the taxonomy code above.
3175
+ */
3176
+ $is_tax_query = ! ($use_children = empty( $query_arguments ));
3177
+ foreach ($arguments as $key => $value ) {
3178
+ /*
3179
+ * There are several "fallthru" cases in this switch statement that decide
3180
+ * whether or not to limit the query to children of a specific post.
3181
+ */
3182
+ $children_ok = true;
3183
+ switch ( $key ) {
3184
+ case 'post_parent':
3185
+ switch ( strtolower( $value ) ) {
3186
+ case 'all':
3187
+ $value = NULL;
3188
+ $use_children = false;
3189
+ break;
3190
+ case 'any':
3191
+ self::$query_parameters['post_parent'] = 'any';
3192
+ $value = NULL;
3193
+ $use_children = false;
3194
+ break;
3195
+ case 'current':
3196
+ $value = $post_parent;
3197
+ $use_children = true;
3198
+ break;
3199
+ case 'none':
3200
+ self::$query_parameters['post_parent'] = 'none';
3201
+ $value = NULL;
3202
+ $use_children = false;
3203
+ break;
3204
+ }
3205
+ // fallthru
3206
+ case 'id':
3207
+ if ( is_numeric( $value ) ) {
3208
+ $query_arguments[ $key ] = intval( $value );
3209
+ if ( ! $children_ok ) {
3210
+ $use_children = false;
3211
+ }
3212
+ }
3213
+ unset( $arguments[ $key ] );
3214
+ break;
3215
+ case 'numberposts':
3216
+ case 'posts_per_page':
3217
+ case 'posts_per_archive_page':
3218
+ if ( is_numeric( $value ) ) {
3219
+ $value = intval( $value );
3220
+ if ( ! empty( $value ) ) {
3221
+ $query_arguments[ $key ] = $value;
3222
+ }
3223
+ }
3224
+ unset( $arguments[ $key ] );
3225
+ break;
3226
+ case 'meta_value_num':
3227
+ $children_ok = false;
3228
+ // fallthru
3229
+ case 'offset':
3230
+ if ( is_numeric( $value ) ) {
3231
+ $query_arguments[ $key ] = intval( $value );
3232
+ if ( ! $children_ok ) {
3233
+ $use_children = false;
3234
+ }
3235
+ }
3236
+ unset( $arguments[ $key ] );
3237
+ break;
3238
+ case 'paged':
3239
+ if ( 'current' == strtolower( $value ) ) {
3240
+ /*
3241
+ * Note: The query variable 'page' holds the pagenumber for a single paginated
3242
+ * Post or Page that includes the <!--nextpage--> Quicktag in the post content.
3243
+ */
3244
+ if ( get_query_var('page') ) {
3245
+ $query_arguments[ $key ] = get_query_var('page');
3246
+ } else {
3247
+ $query_arguments[ $key ] = (get_query_var('paged')) ? get_query_var('paged') : 1;
3248
+ }
3249
+ } elseif ( is_numeric( $value ) ) {
3250
+ $query_arguments[ $key ] = intval( $value );
3251
+ } elseif ( '' === $value ) {
3252
+ $query_arguments[ $key ] = 1;
3253
+ }
3254
+
3255
+ unset( $arguments[ $key ] );
3256
+ break;
3257
+ case $mla_page_parameter :
3258
+ case 'mla_paginate_total':
3259
+ if ( is_numeric( $value ) ) {
3260
+ $query_arguments[ $key ] = intval( $value );
3261
+ } elseif ( '' === $value ) {
3262
+ $query_arguments[ $key ] = 1;
3263
+ }
3264
+
3265
+ unset( $arguments[ $key ] );
3266
+ break;
3267
+ case 'author':
3268
+ case 'cat':
3269
+ case 'tag_id':
3270
+ if ( ! empty( $value ) ) {
3271
+ if ( is_array( $value ) ) {
3272
+ $query_arguments[ $key ] = array_filter( $value );
3273
+ } else {
3274
+ $query_arguments[ $key ] = array_filter( array_map( 'intval', explode( ",", $value ) ) );
3275
+ }
3276
+
3277
+ if ( 1 == count( $query_arguments[ $key ] ) ) {
3278
+ $query_arguments[ $key ] = $query_arguments[ $key ][0];
3279
+ } else {
3280
+ $query_arguments[ $key ] = implode(',', $query_arguments[ $key ] );
3281
+ }
3282
+
3283
+ $use_children = false;
3284
+ }
3285
+ unset( $arguments[ $key ] );
3286
+ break;
3287
+ case 'category__and':
3288
+ case 'category__in':
3289
+ case 'category__not_in':
3290
+ case 'tag__and':
3291
+ case 'tag__in':
3292
+ case 'tag__not_in':
3293
+ case 'include':
3294
+ $children_ok = false;
3295
+ // fallthru
3296
+ case 'exclude':
3297
+ if ( ! empty( $value ) ) {
3298
+ if ( is_array( $value ) ) {
3299
+ $value = array_filter( $value );
3300
+ } else {
3301
+ $value = array_filter( array_map( 'intval', explode( ",", $value ) ) );
3302
+ }
3303
+
3304
+ if ( ! empty( $value ) ) {
3305
+ $query_arguments[ $key ] = $value;
3306
+
3307
+ if ( ! $children_ok ) {
3308
+ $use_children = false;
3309
+ }
3310
+ }
3311
+ }
3312
+ unset( $arguments[ $key ] );
3313
+ break;
3314
+ case 'tag_slug__and':
3315
+ case 'tag_slug__in':
3316
+ if ( ! empty( $value ) ) {
3317
+ if ( is_array( $value ) ) {
3318
+ $query_arguments[ $key ] = $value;
3319
+ } else {
3320
+ $query_arguments[ $key ] = array_filter( array_map( 'trim', explode( ",", $value ) ) );
3321
+ }
3322
+
3323
+ $use_children = false;
3324
+ }
3325
+ unset( $arguments[ $key ] );
3326
+ break;
3327
+ case 'nopaging': // boolean value, default false
3328
+ if ( ! empty( $value ) && ( 'false' != strtolower( $value ) ) ) {
3329
+ $query_arguments[ $key ] = true;
3330
+ }
3331
+
3332
+ unset( $arguments[ $key ] );
3333
+ break;
3334
+ // boolean values, default true
3335
+ case 'cache_results':
3336
+ case 'update_post_meta_cache':
3337
+ case 'update_post_term_cache':
3338
+ if ( ! empty( $value ) && ( 'true' != strtolower( $value ) ) ) {
3339
+ $query_arguments[ $key ] = false;
3340
+ }
3341
+
3342
+ unset( $arguments[ $key ] );
3343
+ break;
3344
+ case 'sentence':
3345
+ case 'exact':
3346
+ if ( ! empty( $value ) && ( 'true' == strtolower( $value ) ) ) {
3347
+ MLAQuery::$search_parameters[ $key ] = true;
3348
+ } else {
3349
+ MLAQuery::$search_parameters[ $key ] = false;
3350
+ }
3351
+
3352
+ unset( $arguments[ $key ] );
3353
+ break;
3354
+ case 'mla_search_connector':
3355
+ case 'mla_phrase_connector':
3356
+ case 'mla_term_connector':
3357
+ if ( ! empty( $value ) && ( 'OR' == strtoupper( $value ) ) ) {
3358
+ MLAQuery::$search_parameters[ $key ] = 'OR';
3359
+ } else {
3360
+ MLAQuery::$search_parameters[ $key ] = 'AND';
3361
+ }
3362
+
3363
+ unset( $arguments[ $key ] );
3364
+ break;
3365
+ case 'mla_terms_phrases':
3366
+ $children_ok = false;
3367
+ // fallthru
3368
+ case 'mla_terms_taxonomies':
3369
+ case 'mla_search_fields':
3370
+ if ( ! empty( $value ) ) {
3371
+ MLAQuery::$search_parameters[ $key ] = $value;
3372
+
3373
+ if ( ! $children_ok ) {
3374
+ $use_children = false;
3375
+ }
3376
+ }
3377
+
3378
+ unset( $arguments[ $key ] );
3379
+ break;
3380
+ case 's':
3381
+ MLAQuery::$search_parameters['s'] = trim( $value );
3382
+ // fallthru
3383
+ case 'author_name':
3384
+ case 'category_name':
3385
+ case 'tag':
3386
+ case 'meta_key':
3387
+ case 'meta_value':
3388
+ case 'meta_compare':
3389
+ $children_ok = false;
3390
+ // fallthru
3391
+ case 'post_type':
3392
+ case 'post_status':
3393
+ case 'post_mime_type':
3394
+ case 'orderby':
3395
+ if ( ! empty( $value ) ) {
3396
+ $query_arguments[ $key ] = $value;
3397
+
3398
+ if ( ! $children_ok ) {
3399
+ $use_children = false;
3400
+ }
3401
+ }
3402
+
3403
+ unset( $arguments[ $key ] );
3404
+ break;
3405
+ case 'order':
3406
+ if ( ! empty( $value ) ) {
3407
+ $value = strtoupper( $value );
3408
+ if ( in_array( $value, array( 'ASC', 'DESC' ) ) ) {
3409
+ $query_arguments[ $key ] = $value;
3410
+ }
3411
+ }
3412
+
3413
+ unset( $arguments[ $key ] );
3414
+ break;
3415
+ case 'date_query':
3416
+ if ( ! empty( $value ) ) {
3417
+ if ( is_array( $value ) ) {
3418
+ $query_arguments[ $key ] = $value;
3419
+ } else {
3420
+ $date_query = NULL;
3421
+ $value = self::_sanitize_query_specification( $value );
3422
+
3423
+ /*
3424
+ * Replace invalid queries from "where-used" callers with a harmless equivalent
3425
+ */
3426
+ if ( $where_used_query && ( false !== strpos( $value, '{+' ) ) ) {
3427
+ $value = "array( array( 'key' => 'unlikely', 'value' => 'none or otherwise unlikely' ) )";
3428
+ }
3429
+
3430
+ $function = @create_function('', 'return ' . $value . ';' );
3431
+ if ( is_callable( $function ) ) {
3432
+ $date_query = $function();
3433
+ }
3434
+
3435
+ if ( is_array( $date_query ) ) {
3436
+ $query_arguments[ $key ] = $date_query;
3437
+ } else {
3438
+ return '<p>' . __( 'ERROR', 'media-library-assistant' ) . ': ' . __( 'Invalid mla_gallery', 'media-library-assistant' ) . ' date_query = ' . var_export( $value, true ) . '</p>';
3439
+ }
3440
+ } // not array
3441
+
3442
+ $use_children = false;
3443
+ }
3444
+ unset( $arguments[ $key ] );
3445
+ break;
3446
+ case 'meta_query':
3447
+ if ( ! empty( $value ) ) {
3448
+ if ( is_array( $value ) ) {
3449
+ $query_arguments[ $key ] = $value;
3450
+ } else {
3451
+ $meta_query = NULL;
3452
+ $value = self::_sanitize_query_specification( $value );
3453
+
3454
+ /*
3455
+ * Replace invalid queries from "where-used" callers with a harmless equivalent
3456
+ */
3457
+ if ( $where_used_query && ( false !== strpos( $value, '{+' ) ) ) {
3458
+ $value = "array( array( 'key' => 'unlikely', 'value' => 'none or otherwise unlikely' ) )";
3459
+ }
3460
+
3461
+ $function = @create_function('', 'return ' . $value . ';' );
3462
+ if ( is_callable( $function ) ) {
3463
+ $meta_query = $function();
3464
+ }
3465
+
3466
+ if ( is_array( $meta_query ) ) {
3467
+ $query_arguments[ $key ] = $meta_query;
3468
+ } else {
3469
+ return '<p>' . __( 'ERROR', 'media-library-assistant' ) . ': ' . __( 'Invalid mla_gallery', 'media-library-assistant' ) . ' meta_query = ' . var_export( $value, true ) . '</p>';
3470
+ }
3471
+ } // not array
3472
+
3473
+ $use_children = false;
3474
+ }
3475
+ unset( $arguments[ $key ] );
3476
+ break;
3477
+ case 'fields':
3478
+ if ( ! empty( $value ) ) {
3479
+ $value = strtolower( $value );
3480
+ if ( in_array( $value, array( 'ids', 'id=>parent' ) ) ) {
3481
+ $query_arguments[ $key ] = $value;
3482
+ }
3483
+ }
3484
+
3485
+ unset( $arguments[ $key ] );
3486
+ break;
3487
+ default:
3488
+ // ignore anything else
3489
+ } // switch $key
3490
+ } // foreach $arguments
3491
+
3492
+ /*
3493
+ * Decide whether to use a "get_children" style query
3494
+ */
3495
+ self::$query_parameters['disable_tax_join'] = $is_tax_query && ! $use_children;
3496
+ if ( $use_children && ! isset( $query_arguments['post_parent'] ) ) {
3497
+ if ( ! isset( $query_arguments['id'] ) ) {
3498
+ $query_arguments['post_parent'] = $post_parent;
3499
+ } else {
3500
+ $query_arguments['post_parent'] = $query_arguments['id'];
3501
+ }
3502
+
3503
+ unset( $query_arguments['id'] );
3504
+ }
3505
+
3506
+ if ( isset( $query_arguments['numberposts'] ) && ! isset( $query_arguments['posts_per_page'] )) {
3507
+ $query_arguments['posts_per_page'] = $query_arguments['numberposts'];
3508
+ }
3509
+ unset( $query_arguments['numberposts'] );
3510
+
3511
+ /*
3512
+ * MLA pagination will override WordPress pagination
3513
+ */
3514
+ if ( isset( $query_arguments[ $mla_page_parameter ] ) ) {
3515
+ unset( $query_arguments['nopaging'] );
3516
+ unset( $query_arguments['offset'] );
3517
+ unset( $query_arguments['paged'] );
3518
+
3519
+ if ( isset( $query_arguments['mla_paginate_total'] ) && ( $query_arguments[ $mla_page_parameter ] > $query_arguments['mla_paginate_total'] ) ) {
3520
+ $query_arguments['offset'] = 0x7FFFFFFF; // suppress further output
3521
+ } else {
3522
+ $query_arguments['paged'] = $query_arguments[ $mla_page_parameter ];
3523
+ }
3524
+ } else {
3525
+ if ( isset( $query_arguments['posts_per_page'] ) || isset( $query_arguments['posts_per_archive_page'] ) ||
3526
+ isset( $query_arguments['paged'] ) || isset( $query_arguments['offset'] ) ) {
3527
+ unset( $query_arguments['nopaging'] );
3528
+ }
3529
+ }
3530
+ unset( $query_arguments[ $mla_page_parameter ] );
3531
+ unset( $query_arguments['mla_paginate_total'] );
3532
+
3533
+ if ( isset( $query_arguments['post_mime_type'] ) && ('all' == strtolower( $query_arguments['post_mime_type'] ) ) ) {
3534
+ unset( $query_arguments['post_mime_type'] );
3535
+ }
3536
+
3537
+ if ( ! empty($query_arguments['include']) ) {
3538
+ $incposts = wp_parse_id_list( $query_arguments['include'] );
3539
+ $query_arguments['posts_per_page'] = count($incposts); // only the number of posts included
3540
+ $query_arguments['post__in'] = $incposts;
3541
+ unset( $query_arguments['include'] );
3542
+ } elseif ( ! empty($query_arguments['exclude']) ) {
3543
+ $query_arguments['post__not_in'] = wp_parse_id_list( $query_arguments['exclude'] );
3544
+ unset( $query_arguments['exclude'] );
3545
+ }
3546
+
3547
+ $query_arguments['ignore_sticky_posts'] = true;
3548
+ $query_arguments['no_found_rows'] = is_null( $return_found_rows ) ? true : ! $return_found_rows;
3549
+
3550
+ /*
3551
+ * We will always handle "orderby" in our filter
3552
+ */
3553
+ self::$query_parameters['orderby'] = self::_validate_sql_orderby( $query_arguments );
3554
+ if ( false === self::$query_parameters['orderby'] ) {
3555
+ unset( self::$query_parameters['orderby'] );
3556
+ }
3557
+
3558
+ unset( $query_arguments['orderby'] );
3559
+ unset( $query_arguments['order'] );
3560
+
3561
+ if ( self::$mla_debug ) {
3562
+ add_filter( 'posts_clauses', 'MLAShortcode_Support::mla_shortcode_query_posts_clauses_filter', 0x7FFFFFFF, 1 );
3563
+ add_filter( 'posts_clauses_request', 'MLAShortcode_Support::mla_shortcode_query_posts_clauses_request_filter', 0x7FFFFFFF, 1 );
3564
+ }
3565
+
3566
+ add_filter( 'posts_join', 'MLAShortcode_Support::mla_shortcode_query_posts_join_filter', 0x7FFFFFFF, 1 );
3567
+ add_filter( 'posts_where', 'MLAShortcode_Support::mla_shortcode_query_posts_where_filter', 0x7FFFFFFF, 1 );
3568
+ add_filter( 'posts_orderby', 'MLAShortcode_Support::mla_shortcode_query_posts_orderby_filter', 0x7FFFFFFF, 1 );
3569
+
3570
+ /*
3571
+ * Handle the keyword and terms search in the posts_search filter.
3572
+ * One or both of 'mla_terms_phrases' and 's' must be present to
3573
+ * trigger the search.
3574
+ */
3575
+ if ( empty( MLAQuery::$search_parameters['mla_terms_phrases'] ) && empty( MLAQuery::$search_parameters['s'] ) ) {
3576
+ MLAQuery::$search_parameters = array( 'debug' => 'none' );
3577
+ } else {
3578
+ /*
3579
+ * Convert Terms Search parameters to the filter's requirements.
3580
+ * mla_terms_taxonomies is shared with keyword search.
3581
+ */
3582
+ if ( empty( MLAQuery::$search_parameters['mla_terms_taxonomies'] ) ) {
3583
+ MLAQuery::$search_parameters['mla_terms_search']['taxonomies'] = MLACore::mla_supported_taxonomies( 'term-search' );
3584
+ } else {
3585
+ MLAQuery::$search_parameters['mla_terms_search']['taxonomies'] = array_filter( array_map( 'trim', explode( ',', MLAQuery::$search_parameters['mla_terms_taxonomies'] ) ) );
3586
+ }
3587
+
3588
+ if ( ! empty( MLAQuery::$search_parameters['mla_terms_phrases'] ) ) {
3589
+ MLAQuery::$search_parameters['mla_terms_search']['phrases'] = MLAQuery::$search_parameters['mla_terms_phrases'];
3590
+
3591
+ if ( empty( MLAQuery::$search_parameters['mla_phrase_connector'] ) ) {
3592
+ MLAQuery::$search_parameters['mla_terms_search']['radio_phrases'] = 'AND';
3593
+ } else {
3594
+ MLAQuery::$search_parameters['mla_terms_search']['radio_phrases'] = MLAQuery::$search_parameters['mla_phrase_connector'];
3595
+ }
3596
+
3597
+ if ( empty( MLAQuery::$search_parameters['mla_term_connector'] ) ) {
3598
+ MLAQuery::$search_parameters['mla_terms_search']['radio_terms'] = 'OR';
3599
+ } else {
3600
+ MLAQuery::$search_parameters['mla_terms_search']['radio_terms'] = MLAQuery::$search_parameters['mla_phrase_connector'];
3601
+ }
3602
+ }
3603
+
3604
+ unset( MLAQuery::$search_parameters['mla_terms_phrases'] );
3605
+ unset( MLAQuery::$search_parameters['mla_terms_taxonomies'] );
3606
+ unset( MLAQuery::$search_parameters['mla_phrase_connector'] );
3607
+ unset( MLAQuery::$search_parameters['mla_term_connector'] );
3608
+
3609
+ if ( empty( MLAQuery::$search_parameters['mla_search_fields'] ) ) {
3610
+ MLAQuery::$search_parameters['mla_search_fields'] = array( 'title', 'content' );
3611
+ } else {
3612
+ MLAQuery::$search_parameters['mla_search_fields'] = array_filter( array_map( 'trim', explode( ',', MLAQuery::$search_parameters['mla_search_fields'] ) ) );
3613
+ MLAQuery::$search_parameters['mla_search_fields'] = array_intersect( array( 'title', 'content', 'excerpt', 'name', 'terms' ), MLAQuery::$search_parameters['mla_search_fields'] );
3614
+
3615
+ /*
3616
+ * Look for keyword search including 'terms'
3617
+ */
3618
+ foreach ( MLAQuery::$search_parameters['mla_search_fields'] as $index => $field ) {
3619
+ if ( 'terms' == $field ) {
3620
+ if ( isset( MLAQuery::$search_parameters['mla_terms_search']['phrases'] ) ) {
3621
+ /*
3622
+ * The Terms Search overrides any terms-based keyword search for now; too complicated.
3623
+ */
3624
+ unset ( MLAQuery::$search_parameters['mla_search_fields'][ $index ] );
3625
+ } else {
3626
+ MLAQuery::$search_parameters['mla_search_taxonomies'] = MLAQuery::$search_parameters['mla_terms_search']['taxonomies'];
3627
+ unset( MLAQuery::$search_parameters['mla_terms_search']['taxonomies'] );
3628
+ }
3629
+ } // terms in search fields
3630
+ }
3631
+ } // mla_search_fields present
3632
+
3633
+ if ( empty( MLAQuery::$search_parameters['mla_search_connector'] ) ) {
3634
+ MLAQuery::$search_parameters['mla_search_connector'] = 'AND';
3635
+ }
3636
+
3637
+ if ( empty( MLAQuery::$search_parameters['sentence'] ) ) {
3638
+ MLAQuery::$search_parameters['sentence'] = false;
3639
+ }
3640
+
3641
+ if ( empty( MLAQuery::$search_parameters['exact'] ) ) {
3642
+ MLAQuery::$search_parameters['exact'] = false;
3643
+ }
3644
+
3645
+ MLAQuery::$search_parameters['debug'] = self::$mla_debug ? 'shortcode' : 'none';
3646
+
3647
+ add_filter( 'posts_search', 'MLAQuery::mla_query_posts_search_filter', 10, 2 );
3648
+ add_filter( 'posts_groupby', 'MLAQuery::mla_query_posts_groupby_filter' );
3649
+ }
3650
+
3651
+ if ( self::$mla_debug ) {
3652
+ global $wp_filter;
3653
+
3654
+ foreach( $wp_filter['posts_where'] as $priority => $filters ) {
3655
+ $debug_message = '<strong>mla_debug $wp_filter[posts_where]</strong> priority = ' . var_export( $priority, true ) . '<br />';
3656
+ foreach ( $filters as $name => $descriptor ) {
3657
+ $debug_message .= 'filter name = ' . var_export( $name, true ) . '<br />';
3658
+ }
3659
+ MLACore::mla_debug_add( $debug_message );
3660
+ }
3661
+
3662
+ foreach( $wp_filter['posts_orderby'] as $priority => $filters ) {
3663
+ $debug_message = '<strong>mla_debug $wp_filter[posts_orderby]</strong> priority = ' . var_export( $priority, true ) . '<br />';
3664
+ foreach ( $filters as $name => $descriptor ) {
3665
+ $debug_message .= 'filter name = ' . var_export( $name, true ) . '<br />';
3666
+ }
3667
+ MLACore::mla_debug_add( $debug_message );
3668
+ }
3669
+ }
3670
+
3671
+ /*
3672
+ * Disable Relevanssi - A Better Search, v3.2 by Mikko Saari
3673
+ * relevanssi_prevent_default_request( $request, $query )
3674
+ * apply_filters('relevanssi_admin_search_ok', $admin_search_ok, $query );
3675
+ */
3676
+ if ( function_exists( 'relevanssi_prevent_default_request' ) ) {
3677
+ add_filter( 'relevanssi_admin_search_ok', 'MLAData::mla_query_relevanssi_admin_search_ok_filter' );
3678
+ }
3679
+
3680
+ if ( class_exists( 'MLA_Polylang' ) ) {
3681
+ $query_arguments = apply_filters( 'mla_get_shortcode_attachments_final_terms', $query_arguments, $return_found_rows );
3682
+ }
3683
+
3684
+ MLAShortcodes::$mla_gallery_wp_query_object = new WP_Query;
3685
+ $attachments = MLAShortcodes::$mla_gallery_wp_query_object->query( $query_arguments );
3686
+
3687
+ /*
3688
+ * $return_found_rows is used to indicate that the call comes from gallery_shortcode(),
3689
+ * which is the only call that supplies it.
3690
+ */
3691
+ if ( is_null( $return_found_rows ) ) {
3692
+ $return_found_rows = false;
3693
+ } else {
3694
+ do_action( 'mla_gallery_wp_query_object', $query_arguments );
3695
+ }
3696
+
3697
+ if ( $return_found_rows ) {
3698
+ $attachments['found_rows'] = MLAShortcodes::$mla_gallery_wp_query_object->found_posts;
3699
+ }
3700
+
3701
+ if ( ! empty( MLAQuery::$search_parameters ) ) {
3702
+ remove_filter( 'posts_groupby', 'MLAQuery::mla_query_posts_groupby_filter' );
3703
+ remove_filter( 'posts_search', 'MLAQuery::mla_query_posts_search_filter' );
3704
+ }
3705
+
3706
+ if ( function_exists( 'relevanssi_prevent_default_request' ) ) {
3707
+ remove_filter( 'relevanssi_admin_search_ok', 'MLAData::mla_query_relevanssi_admin_search_ok_filter' );
3708
+ }
3709
+
3710
+ remove_filter( 'posts_join', 'MLAShortcode_Support::mla_shortcode_query_posts_join_filter', 0x7FFFFFFF );
3711
+ remove_filter( 'posts_where', 'MLAShortcode_Support::mla_shortcode_query_posts_where_filter', 0x7FFFFFFF );
3712
+ remove_filter( 'posts_orderby', 'MLAShortcode_Support::mla_shortcode_query_posts_orderby_filter', 0x7FFFFFFF );
3713
+
3714
+ if ( self::$mla_debug ) {
3715
+ remove_filter( 'posts_clauses', 'MLAShortcode_Support::mla_shortcode_query_posts_clauses_filter', 0x7FFFFFFF );
3716
+ remove_filter( 'posts_clauses_request', 'MLAShortcode_Support::mla_shortcode_query_posts_clauses_request_filter', 0x7FFFFFFF );
3717
+
3718
+ MLACore::mla_debug_add( '<strong>' . __( 'mla_debug query', 'media-library-assistant' ) . '</strong> = ' . var_export( $query_arguments, true ) );
3719
+ MLACore::mla_debug_add( '<strong>' . __( 'mla_debug request', 'media-library-assistant' ) . '</strong> = ' . var_export( MLAShortcodes::$mla_gallery_wp_query_object->request, true ) );
3720
+ MLACore::mla_debug_add( '<strong>' . __( 'mla_debug query_vars', 'media-library-assistant' ) . '</strong> = ' . var_export( MLAShortcodes::$mla_gallery_wp_query_object->query_vars, true ) );
3721
+ MLACore::mla_debug_add( '<strong>' . __( 'mla_debug post_count', 'media-library-assistant' ) . '</strong> = ' . var_export( MLAShortcodes::$mla_gallery_wp_query_object->post_count, true ) );
3722
+ }
3723
+
3724
+ MLAShortcodes::$mla_gallery_wp_query_object = NULL;
3725
+ return $attachments;
3726
+ }
3727
+
3728
+ /**
3729
+ * Filters the JOIN clause for shortcode queries
3730
+ *
3731
+ * Defined as public because it's a filter.
3732
+ *
3733
+ * @since 2.20
3734
+ *
3735
+ * @param string query clause before modification
3736
+ *
3737
+ * @return string query clause after item modification
3738
+ */
3739
+ public static function mla_shortcode_query_posts_join_filter( $join_clause ) {
3740
+ global $wpdb;
3741
+
3742
+ /*
3743
+ * Set for taxonomy queries unless post_parent=current. If true, we must disable
3744
+ * the LEFT JOIN clause that get_posts() adds to taxonomy queries.
3745
+ * We leave the clause in because the WHERE clauses refer to "p2.".
3746
+ */
3747
+ if ( self::$query_parameters['disable_tax_join'] ) {
3748
+ $join_clause = str_replace( " LEFT JOIN {$wpdb->posts} AS p2 ON ({$wpdb->posts}.post_parent = p2.ID) ", " LEFT JOIN {$wpdb->posts} AS p2 ON (p2.ID = p2.ID) ", $join_clause );
3749
+ }
3750
+
3751
+ /*
3752
+ * These joins support the 'terms' search_field
3753
+ */
3754
+ if ( isset( MLAQuery::$search_parameters['tax_terms_count'] ) ) {
3755
+ $tax_index = 0;
3756
+ $tax_clause = '';
3757
+
3758
+ while ( $tax_index < MLAQuery::$search_parameters['tax_terms_count'] ) {
3759
+ $prefix = 'mlatt' . $tax_index++;
3760
+ $tax_clause .= sprintf( ' INNER JOIN %1$s AS %2$s ON (%3$s.ID = %2$s.object_id)', $wpdb->term_relationships, $prefix, $wpdb->posts );
3761
+ }
3762
+
3763
+ $join_clause .= $tax_clause;
3764
+ }
3765
+
3766
+
3767
+ return $join_clause;
3768
+ }
3769
+
3770
+ /**
3771
+ * Filters the WHERE clause for shortcode queries
3772
+ *
3773
+ * Captures debug information. Adds whitespace to the post_type = 'attachment'
3774
+ * phrase to circumvent subsequent Role Scoper modification of the clause.
3775
+ * Handles post_parent "any" and "none" cases.
3776
+ * Defined as public because it's a filter.
3777
+ *
3778
+ * @since 2.20
3779
+ *
3780
+ * @param string query clause before modification
3781
+ *
3782
+ * @return string query clause after modification
3783
+ */
3784
+ public static function mla_shortcode_query_posts_where_filter( $where_clause ) {
3785
+ global $table_prefix;
3786
+
3787
+ if ( self::$mla_debug ) {
3788
+ $old_clause = $where_clause;
3789
+ MLACore::mla_debug_add( '<strong>' . __( 'mla_debug WHERE filter', 'media-library-assistant' ) . '</strong> = ' . var_export( $where_clause, true ) );
3790
+ }
3791
+
3792
+ if ( strpos( $where_clause, "post_type = 'attachment'" ) ) {
3793
+ $where_clause = str_replace( "post_type = 'attachment'", "post_type = 'attachment'", $where_clause );
3794
+ }
3795
+
3796
+ if ( isset( self::$query_parameters['post_parent'] ) ) {
3797
+ switch ( self::$query_parameters['post_parent'] ) {
3798
+ case 'any':
3799
+ $where_clause .= " AND {$table_prefix}posts.post_parent > 0";
3800
+ break;
3801
+ case 'none':
3802
+ $where_clause .= " AND {$table_prefix}posts.post_parent < 1";
3803
+ break;
3804
+ }
3805
+ }
3806
+
3807
+ if ( self::$mla_debug && ( $old_clause != $where_clause ) ) {
3808
+ MLACore::mla_debug_add( '<strong>' . __( 'mla_debug modified WHERE filter', 'media-library-assistant' ) . '</strong> = ' . var_export( $where_clause, true ) );
3809
+ }
3810
+
3811
+ return $where_clause;
3812
+ }
3813
+
3814
+ /**
3815
+ * Filters the ORDERBY clause for shortcode queries
3816
+ *