PluginProbe
Photo Engine (Media Organizer & Lightroom) / trunk
Photo Engine (Media Organizer & Lightroom) vtrunk
6.5.5 6.5.4 6.5.3 6.5.2 trunk 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.8.2 0.8.3 0.8.4 0.8.6 0.8.8 1.2.4 1.3.0 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 All 157 releases
wplr-sync / classes / explorer.php

explorer.php in Photo Engine (Media Organizer & Lightroom) trunk, at classes/explorer.php

107 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Meow_WPLR_Sync_Explorer {
4
5 public $screen;
6
7 public function __construct() {
8
9 $mode = get_option( 'wplr_library_show_hierarchy', 'none' );
10
11 // FILTERS IN THE MEDIA LIBRARY
12 //if ( $mode === 'filters' || $mode === 'explorer' ) {
13 add_action( 'pre_get_posts', array( $this, 'media_filters' ) );
14 add_action( 'restrict_manage_posts', array( $this, 'media_dropdown' ) );
15 //}
16
17 // UI WITH HIERARCHY IN THE MEDIA LIBRARY
18 //if ( $mode === 'explorer' ) {
19 add_action( 'admin_head', array( $this, 'admin_head' ) );
20 add_action( 'admin_footer', array( $this, 'admin_footer' ) );
21 // add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
22 //}
23 }
24
25 /*
26 FILTERS IN THE MEDIA LIBRARY
27 */
28
29 function media_filters( $q ) {
30 $col_id = isset( $_GET['col_id'] ) ? (int)$_GET['col_id'] : 0;
31 if ( isset( $_POST['query'] ) && isset( $_POST['query']['col_id'] ) )
32 $col_id = (int)( $_POST['query']['col_id'] );
33 if ( $col_id < 1 ) {
34 return;
35 }
36 global $wplr;
37 $pids = $wplr->get_media_from_collection( $col_id );
38 if ( !empty( $pids ) ) {
39 $q->set( 'post__in', $pids );
40 $q->set( 'orderby', 'post__in' );
41 }
42 else
43 $q->set( 'p', -1 );
44 return $q;
45 }
46
47 function media_dropdown() {
48 if ( !$this->shouldBeOverriden() )
49 return;
50 $wp_parent_folder = null;
51 global $wpdb, $wplr;
52 $tbl_c = $wpdb->prefix . 'lrsync_collections';
53 $collections = $wpdb->get_results( "SELECT * FROM $tbl_c WHERE wp_folder_id IS NULL ORDER BY lr_col_id", OBJECT );
54 $col_id = isset( $_GET['col_id'] ) ? (int)$_GET['col_id'] : 0;
55 echo '<a class="dashicons-before dashicons-camera" style="top: 5px; position: relative; margin: 2px;"></a>
56 <select name="col_id" id="wplr_col_id_selector" class="postform">
57 <option value="-1" selected="selected">All Media</option>';
58 $collections = $wplr->read_collections_recursively();
59 foreach ( $collections as $c ) {
60 echo '<option class="level-' . $c['level'] . '"' .
61 ( $c['is_folder'] ? ' disabled' : '' ) . ' value="' .
62 $c['wp_col_id'] . '" ' . selected( $c['wp_col_id'], $col_id ) . '>' .
63 str_pad( "", $c['level'] * 6 * 3, "&nbsp;" ) . $c['name'] .
64 '</option>';
65 }
66 echo '</select>';
67 }
68
69 /*
70 UI WITH HIERARCHY IN THE MEDIA LIBRARY
71 */
72
73 function admin_head() {
74 if ( !$this->shouldBeOverriden() )
75 return;
76 ob_start( array( $this, "hide_media_gallery" ) );
77 }
78
79 function hide_media_gallery( $buffer ) {
80 if ( !isset( $buffer ) || trim( $buffer ) === '' )
81 return $buffer;
82 $buffer = str_replace( 'id="posts-filter"', 'id="posts-filter" style="display: none;"', $buffer );
83 return $buffer;
84 }
85
86 function admin_footer() {
87 if ( !$this->shouldBeOverriden() )
88 return;
89 @ob_end_flush();
90 }
91
92 function shouldBeOverriden() {
93 $should = false;
94 $screen = get_current_screen();
95
96 if ($screen->base === 'upload') return true;
97
98 if ( isset( $_SERVER['QUERY_STRING'] ) ) {
99 if ( preg_match( '/action=edit/', $_SERVER['QUERY_STRING'] ) )
100 return true;
101 }
102 }
103
104 }
105
106 ?>
107