chakalos /wp-content/plugins/backupbuddy/pluginbuddy/lib/media_library/media_library.php

Language PHP Lines 222
MD5 Hash b90a425a634d82b253f77d484cae3288 Estimated Cost $1,285 (why?)
Repository https://bitbucket.org/betaimages/chakalos.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<?php
class pb_backupbuddy_medialibrary {
	private $_save_point = '';
	private $_default_options_point = '';
	private $_instance = 0;
	
	function __construct( $save_point, $default_options_point ) {
		$this->_save_point = $save_point;
		$this->_default_options_point = $default_options_point;
		$this->_instance = pb_backupbuddy::random_string();
	}
	
	function display() {
		pb_backupbuddy::load_script( 'jquery-ui-draggable' );
		pb_backupbuddy::load_script( 'jquery-ui-sortable' );
		?>
		<script type="text/javascript">
			jQuery(document).ready(function() {
				
				
				jQuery( '.pb_medialibrary_slot_<?php echo $this->_instance; ?>' ).sortable({
					opacity: 0.6,
					cursor: "move",
					revert: true,
					update: function(e,ui) {
						// Only save changes on drop IN, not pull out phase of the update.  Prevents double firing and pulling out of things too early.
						if (this === ui.item.parent()[0]) {
							var this_placed_item = jQuery(ui.item);
							jQuery(ui.item).removeClass('pb_medialibrary_draggable');
							jQuery(ui.item).addClass('pb_medialibrary_slotitem');
							slot_items = new Array();
							jQuery(this).children('.pb_medialibrary_slotitem').each(function(j) {
								slot_items.push( jQuery(this).attr('rel') );
							});
							
							jQuery('#pb_medialibrary_saving').show();
							
							//alert( slot_items );
							
							jQuery.ajax({
								type: 'POST',
								url: '<?php echo pb_backupbuddy::ajax_url( 'media_library' ); ?>&actionb=save_images_list',
								data: 'items=' + slot_items + '&save_point=<?php echo str_replace( '\'', '\\\'', $this->_save_point ); ?>&default_options_point=<?php echo str_replace( '\'', '\\\'', $this->_default_options_point ); ?>',
								success: function(msg){
									jQuery('#pb_saving').hide();
									//alert( msg );
									//this_placed_item.children('.loop_item_buttons').css({'display':'block'}); // Show settings icon on newly placed slot item.
									/*
									if ( msg.unique_id != 0 ) {
										this_placed_item.attr('id', 'pbloop-' + msg.unique_id);
									}
									*/
									
								}
								// , 'dataType': 'json'
							});
							
						}
					},
					start: function(e,ui) {
						/* New jQuery fix (new slot items do not cause over method to trigger. */
						//jQuery('.loop_slot').css({'background':'transparent'}); /* New jQuery fix. Changing existing slot item keeps its slot bg colored. */
						//jQuery(this).css({'background':'#EAF2FA'});
						jQuery( '.pb_medialibrary_item' ).draggable( 'option', 'revert', false );
					},
					stop: function(e,ui) {
						jQuery(this).css({'background':'transparent'});
						jQuery( '.pb_medialibrary_item' ).draggable( 'option', 'revert', true );
					},
					
					over: function(e,ui) {
						jQuery('.pb_medialibrary_item').css({'background':'transparent'}); /* New jQuery fix. Changing existing slot item keeps its slot bg colored. */
						
						jQuery(this).css({'background':'#EAF2FA'});
						jQuery( '.pb_medialibrary_item' ).draggable( 'option', 'revert', false );
					},
					out: function(e,ui) {
						jQuery(this).css({'background':'transparent'});
						/* jQuery( '.loop_item' ).draggable( 'option', 'revert', true ); New jQuery fix. Prevents revert from double flying. */
					}
				});
				//jQuery( '.pb_medialib_1' ).disableSelection();
				
				
				
				jQuery('.pb_medialibrary_draggable').draggable({
					revert: true,
					opacity: '.9',
					zIndex: 15,
					helper: 'clone',
					appendTo: 'body',
					connectToSortable: '.pb_medialibrary_slot_<?php echo $this->_instance; ?>'
				});
				
				
				
			});
		</script>
		<style type="text/css">
			.pb_medialibrary div {
				display: inline-block;
				height: 150px;
				position: relative;
				cursor: move;
			}
			.pb_medialibrary div img {
				//margin: 3px;
			}
			.pb_medialibrary {
				max-height: 480px;
				overflow: scroll;
			}
			
			
			.pb_medialibrary_item {
				margin: 5px;
				text-align: center;
				line-height: 1.1em;
			}
			
			.pb_medialibrary_imgbox {
				display: inline-block;
				position: relative;
				//margin: 3px;
				cursor: move;
			}
			.pb_medialibrary_settingsbox {
				position: absolute;
				right: 0;
				z-index: 30;
				display: none;
				cursor: pointer;
				background: white;
			}
			.pb_medialibrary_settingsbox_hot {
				color: red;
			}
		</style>
		
		
		
		
		<?php
		pb_backupbuddy::$ui->start_metabox( 'Images in Group <span id="pb_medialibrary_saving" style="display: none;">Saving</span>', true, 'width: 48%; min-width: 400px; float: left;' );
		
		echo '<div class="pb_medialibrary_slot_' . $this->_instance . ' pb_medialibrary">';
		
		$group_images = &pb_backupbuddy::get_group( $this->_save_point );
		foreach( $group_images as $image_index => $image ) {
			$image_dat = wp_get_attachment_image_src( $image['id'], 'thumbnail' );
			echo '<div class="pb_medialibrary_item pb_medialibrary_slotitem" rel="' . $image['id'] . '"><img src="' . $image_dat[0] . '"></div>';
		}
		
		echo '</div>';
		
		pb_backupbuddy::$ui->end_metabox();
		
		
		
		
		pb_backupbuddy::$ui->start_metabox( 'WordPress Media Library', true, 'width: 48%; min-width: 400px; float: right;' );
		?>
		<div class="pb_medialibrary">
		<?php
		global $wpdb;
		$result = mysql_query( "SELECT ID,post_title FROM {$wpdb->prefix}posts WHERE post_type='attachment'" );
		while ( $rs = mysql_fetch_assoc( $result ) ) {
			//echo '<pre>' . print_r( $rs, true ) . '</pre>';
			$image_dat = wp_get_attachment_image_src( $rs['ID'], 'thumbnail' );
			//echo '<pre>' . print_r( \wp_get_attachment_metadata( $rs['ID'] ) , true ) . '</pre>';
			//echo '<pre>' . print_r( $image_dat, true ) . '</pre>';
			echo '<div class="pb_medialibrary_item pb_medialibrary_draggable" rel="' . $rs['ID'] . '"><span class="pb_medialibrary_settingsbox">Settings</span><img class="pb_medialibrary_lazy" data-original="' . $image_dat[0] . '" src="" title="' . $rs['post_title'] . '"></div>';
		}
		unset( $result );
		?>
		</div>
		<?php
		pb_backupbuddy::$ui->end_metabox();
	}
	
	public function ajax( $actionb ) {
		if ( $actionb == 'save_images_list' ) { // User modified the list of images in a group.
			//echo '<pre>' . print_r( pb_backupbuddy::_POST(), true ) . '</pre>';
			$images = explode( ',', pb_backupbuddy::_POST( 'items' ) );
			echo '<pre>' . print_r( $images, true ) . '</pre>';
			
			
			// Prepare savepoint.
			if ( $this->_save_point != '' ) {
				$savepoint_root = $this->_save_point; // . '#';
			} else {
				$savepoint_root = '';
			}
			
			$image_root = &pb_backupbuddy::get_group( $savepoint_root );
			$image_root = array();
			
			
			foreach ( $images as $image_id ) { // Loop through each item in list.
				//echo 'id: ' . $image_id . '<br>';
				$image_defaults = pb_backupbuddy::settings( pb_backupbuddy::_POST( 'default_options_point' ) );
				$image_defaults['id'] = $image_id;
				$image_root[] = $image_defaults;
				/*
				//echo '<pre>' . print_r( $image_defaults, true ) . '</pre>';
				
				// From old save_settings():
				$savepoint_subsection = &pb_backupbuddy::$options;
				$savepoint_levels = explode( '#', $savepoint_root );
				foreach ( $savepoint_levels as $savepoint_level ) {
					$savepoint_subsection = &$savepoint_subsection{$savepoint_level};
				}
				// Apply settings.
				$savepoint_subsection[] = $image_defaults;
				*/
			}
			//echo '<pre>' . print_r( $image_root, true ) . '</pre>';
			pb_backupbuddy::save();
		}
		die();
	}
}
Back to Top