| 1 |
<?php |
| 2 |
global $post; |
| 3 |
global $maxgalleria; |
| 4 |
|
| 5 |
$video_gallery = $maxgalleria->video_gallery; |
| 6 |
|
| 7 |
$args = array( |
| 8 |
'post_type' => 'attachment', |
| 9 |
'numberposts' => -1, // All of them |
| 10 |
'post_parent' => $post->ID, |
| 11 |
'orderby' => 'menu_order', |
| 12 |
'order' => 'ASC' |
| 13 |
); |
| 14 |
|
| 15 |
$attachments = get_posts($args); |
| 16 |
?> |
| 17 |
|
| 18 |
<script type="text/javascript"> |
| 19 |
jQuery(document).ready(function() { |
| 20 |
// To add the video count in the meta box title |
| 21 |
jQuery("#meta-video-gallery h3.hndle span").html("<?php _e('Gallery', 'maxgalleria') ?> (<?php echo count($attachments) ?> <?php _e('videos', 'maxgalleria') ?>)"); |
| 22 |
|
| 23 |
// Video moving and re-ordering |
| 24 |
jQuery("#gallery-media").dataTable({ bPaginate: false }).rowReordering({ |
| 25 |
fnAlert: function(message) { |
| 26 |
alert(message); |
| 27 |
}, |
| 28 |
fnSuccess: function() { |
| 29 |
reorderVideos(); |
| 30 |
} |
| 31 |
}); |
| 32 |
|
| 33 |
// Need the menu order table cell, but don't need to show it |
| 34 |
jQuery("th.order").css("display", "none"); |
| 35 |
jQuery("td.order").css("display", "none"); |
| 36 |
|
| 37 |
jQuery("#gallery_media_select_button").click(function() { |
| 38 |
post_id = <?php echo $post->ID ?>; |
| 39 |
tb_show("<?php _e('Add Videos', 'maxgalleria') ?>", "<?php echo MAXGALLERIA_PLUGIN_URL ?>/meta/video-add.php?post_id=" + post_id + "&TB_iframe=true"); |
| 40 |
return false; |
| 41 |
}); |
| 42 |
|
| 43 |
jQuery(window).bind("tb_unload", function() { |
| 44 |
reloadPage(); |
| 45 |
}); |
| 46 |
|
| 47 |
jQuery(".maxgalleria-meta .media table td").hover( |
| 48 |
function() { |
| 49 |
jQuery(this).find(".actions").css("visibility", "visible"); |
| 50 |
jQuery(this).siblings().find(".actions").css("visibility", "visible"); |
| 51 |
}, |
| 52 |
function() { |
| 53 |
jQuery(this).find(".actions").css("visibility", "hidden"); |
| 54 |
jQuery(this).siblings().find(".actions").css("visibility", "hidden"); |
| 55 |
} |
| 56 |
); |
| 57 |
|
| 58 |
jQuery("#select-all").click(function() { |
| 59 |
jQuery("input[type='checkbox']").attr("checked", jQuery("#select-all").is(":checked")); |
| 60 |
}); |
| 61 |
|
| 62 |
jQuery("#bulk-action-apply").click(function() { |
| 63 |
var bulk_action = jQuery("#bulk-action-select").val(); |
| 64 |
|
| 65 |
if (bulk_action == "edit") { |
| 66 |
var form_data_array = jQuery("#post").serializeArray(); |
| 67 |
|
| 68 |
var video_ids = ""; |
| 69 |
for (i = 0; i < form_data_array.length; i++) { |
| 70 |
if (form_data_array[i].name == "media-id[]") { |
| 71 |
video_ids += form_data_array[i].value + ","; |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
if (video_ids != "") { |
| 76 |
tb_show("<?php _e('Edit Bulk Videos', 'maxgalleria') ?>", "<?php echo MAXGALLERIA_PLUGIN_URL ?>/meta/video-edit-bulk.php?video_ids=" + video_ids + "&TB_iframe=true"); |
| 77 |
} |
| 78 |
} |
| 79 |
else { |
| 80 |
var form_data = jQuery("#post").serialize(); |
| 81 |
var data_action = ""; |
| 82 |
|
| 83 |
if (bulk_action == "exclude") { data_action = form_data + "&action=exclude_bulk_videos_from_gallery"; } |
| 84 |
if (bulk_action == "include") { data_action = form_data + "&action=include_bulk_videos_in_gallery"; } |
| 85 |
if (bulk_action == "remove") { data_action = form_data + "&action=remove_bulk_videos_from_gallery"; } |
| 86 |
|
| 87 |
if (data_action != "") { |
| 88 |
jQuery.ajax({ |
| 89 |
type: "POST", |
| 90 |
url: "<?php echo admin_url('admin-ajax.php') ?>", |
| 91 |
data: data_action, |
| 92 |
success: function(message) { |
| 93 |
if (message != "") { |
| 94 |
alert(message); |
| 95 |
reloadPage(); |
| 96 |
} |
| 97 |
} |
| 98 |
}); |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
return false; |
| 103 |
}); |
| 104 |
|
| 105 |
jQuery("#list-view").on("click", function(e) { |
| 106 |
e.preventDefault(); |
| 107 |
jQuery("#rows-view").removeClass("active"); |
| 108 |
jQuery("#grid-view").removeClass("active"); |
| 109 |
jQuery(this).addClass("active"); |
| 110 |
jQuery("#gallery-media_wrapper").removeClass("rows videos"); |
| 111 |
jQuery("#gallery-media_wrapper").removeClass("grid"); |
| 112 |
jQuery("#gallery-media_wrapper").addClass("list"); |
| 113 |
jQuery(".maxgalleria-meta .bulk-actions").show(); |
| 114 |
}); |
| 115 |
|
| 116 |
jQuery("#rows-view").on("click", function(e) { |
| 117 |
e.preventDefault(); |
| 118 |
jQuery("#list-view").removeClass("active"); |
| 119 |
jQuery("#grid-view").removeClass("active"); |
| 120 |
jQuery(this).addClass("active"); |
| 121 |
jQuery("#gallery-media_wrapper").removeClass("list"); |
| 122 |
jQuery("#gallery-media_wrapper").removeClass("grid"); |
| 123 |
jQuery("#gallery-media_wrapper").addClass("rows videos"); |
| 124 |
jQuery(".maxgalleria-meta .bulk-actions").show(); |
| 125 |
}); |
| 126 |
|
| 127 |
jQuery("#grid-view").on("click", function(e) { |
| 128 |
e.preventDefault(); |
| 129 |
jQuery("#list-view").removeClass("active"); |
| 130 |
jQuery("#rows-view").removeClass("active"); |
| 131 |
jQuery(this).addClass("active"); |
| 132 |
jQuery("#gallery-media_wrapper").removeClass("list"); |
| 133 |
jQuery("#gallery-media_wrapper").removeClass("rows videos"); |
| 134 |
jQuery("#gallery-media_wrapper").addClass("grid"); |
| 135 |
jQuery(".maxgalleria-meta .bulk-actions").hide(); |
| 136 |
}); |
| 137 |
}); |
| 138 |
|
| 139 |
function viewVideo(video_id) { |
| 140 |
var video = jQuery("#video-" + video_id); |
| 141 |
var iframe_width = parseInt(jQuery(video).find("iframe").attr("width")); |
| 142 |
var iframe_height = parseInt(jQuery(video).find("iframe").attr("height")); |
| 143 |
|
| 144 |
jQuery(video).modal({ |
| 145 |
minWidth: iframe_width + 20, |
| 146 |
minHeight: iframe_height + 20, |
| 147 |
overlayClose: true, |
| 148 |
autoResize: true |
| 149 |
}); |
| 150 |
} |
| 151 |
|
| 152 |
function editVideo(video_id) { |
| 153 |
tb_show("<?php _e('Edit Video', 'maxgalleria') ?>", "<?php echo MAXGALLERIA_PLUGIN_URL ?>/meta/video-edit.php?video_id=" + video_id + "&TB_iframe=true"); |
| 154 |
return false; |
| 155 |
} |
| 156 |
|
| 157 |
function excludeVideo(video_id) { |
| 158 |
var result = confirm("<?php _e('Are you sure you want to exclude this video from the gallery?', 'maxgalleria') ?>"); |
| 159 |
if (result == true) { |
| 160 |
var nonce_value = jQuery("#<?php echo $video_gallery->nonce_video_exclude_single['name'] ?>").val(); |
| 161 |
|
| 162 |
jQuery.ajax({ |
| 163 |
type: "POST", |
| 164 |
url: "<?php echo admin_url('admin-ajax.php') ?>", |
| 165 |
data: { |
| 166 |
action: 'exclude_single_video_from_gallery', |
| 167 |
id: video_id, |
| 168 |
<?php echo $video_gallery->nonce_video_exclude_single['name'] ?>: nonce_value |
| 169 |
}, |
| 170 |
success: function(message) { |
| 171 |
if (message != "") { |
| 172 |
alert(message); |
| 173 |
reloadPage(); |
| 174 |
} |
| 175 |
} |
| 176 |
}); |
| 177 |
|
| 178 |
return false; |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
function includeVideo(video_id) { |
| 183 |
var result = confirm("<?php _e('Are you sure you want to include this video in the gallery?', 'maxgalleria') ?>"); |
| 184 |
if (result == true) { |
| 185 |
var nonce_value = jQuery("#<?php echo $video_gallery->nonce_video_include_single['name'] ?>").val(); |
| 186 |
|
| 187 |
jQuery.ajax({ |
| 188 |
type: "POST", |
| 189 |
url: "<?php echo admin_url('admin-ajax.php') ?>", |
| 190 |
data: { |
| 191 |
action: 'include_single_video_in_gallery', |
| 192 |
id: video_id, |
| 193 |
<?php echo $video_gallery->nonce_video_include_single['name'] ?>: nonce_value |
| 194 |
}, |
| 195 |
success: function(message) { |
| 196 |
if (message != "") { |
| 197 |
alert(message); |
| 198 |
reloadPage(); |
| 199 |
} |
| 200 |
} |
| 201 |
}); |
| 202 |
|
| 203 |
return false; |
| 204 |
} |
| 205 |
} |
| 206 |
|
| 207 |
function removeVideo(video_id) { |
| 208 |
var result = confirm("<?php _e('Are you sure you want to remove this video from the gallery?', 'maxgalleria') ?>"); |
| 209 |
if (result == true) { |
| 210 |
var nonce_value = jQuery("#<?php echo $video_gallery->nonce_video_remove_single['name'] ?>").val(); |
| 211 |
|
| 212 |
jQuery.ajax({ |
| 213 |
type: "POST", |
| 214 |
url: "<?php echo admin_url('admin-ajax.php') ?>", |
| 215 |
data: { |
| 216 |
action: 'remove_single_video_from_gallery', |
| 217 |
id: video_id, |
| 218 |
<?php echo $video_gallery->nonce_video_remove_single['name'] ?>: nonce_value |
| 219 |
}, |
| 220 |
success: function(message) { |
| 221 |
if (message != "") { |
| 222 |
alert(message); |
| 223 |
reloadPage(); |
| 224 |
} |
| 225 |
} |
| 226 |
}); |
| 227 |
|
| 228 |
return false; |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
function reorderVideos() { |
| 233 |
jQuery(".maxgalleria-meta .media table td.order").each(function() { |
| 234 |
jQuery(this).siblings().find(".media-order-input").val(jQuery(this).html()); |
| 235 |
}); |
| 236 |
|
| 237 |
var form_data = jQuery("#post").serialize(); |
| 238 |
|
| 239 |
jQuery.ajax({ |
| 240 |
type: "POST", |
| 241 |
url: "<?php echo admin_url('admin-ajax.php') ?>", |
| 242 |
data: form_data + "&action=reorder_videos" |
| 243 |
}); |
| 244 |
|
| 245 |
return false; |
| 246 |
} |
| 247 |
|
| 248 |
function showAddingVideosNote() { |
| 249 |
jQuery(".maxgalleria-meta .adding-videos-note").show(); |
| 250 |
} |
| 251 |
|
| 252 |
function reloadPage() { |
| 253 |
tb_remove(); |
| 254 |
window.location = "<?php echo admin_url() ?>post.php?post=<?php echo $post->ID ?>&action=edit"; |
| 255 |
} |
| 256 |
</script> |
| 257 |
|
| 258 |
<div class="add-media"> |
| 259 |
<input type="button" class="btn btn-primary" id="gallery_media_select_button" name="gallery_media_select_button" value="<?php _e('Add Videos', 'maxgalleria') ?>" /> |
| 260 |
</div> |
| 261 |
<?php if (count($attachments) > 0) { ?> |
| 262 |
<div class="bulk-actions"> |
| 263 |
<select name="bulk-action-select" id="bulk-action-select"> |
| 264 |
<option value=""><?php _e('Bulk Actions', 'maxgalleria') ?></option> |
| 265 |
<option value="edit"><?php _e('Edit', 'maxgalleria') ?></option> |
| 266 |
<option value="exclude"><?php _e('Exclude', 'maxgalleria') ?></option> |
| 267 |
<option value="include"><?php _e('Include', 'maxgalleria') ?></option> |
| 268 |
<option value="remove"><?php _e('Remove', 'maxgalleria') ?></option> |
| 269 |
</select> |
| 270 |
<input type="button" id="bulk-action-apply" class="button" value="<?php _e('Apply', 'maxgalleria') ?>" /> |
| 271 |
</div> |
| 272 |
<ul class="views"> |
| 273 |
<li><a id="list-view" class="active"><?php _e('List', 'maxgalleria') ?></a></li> |
| 274 |
<li><a id="rows-view"><?php _e('Rows', 'maxgalleria') ?></a></li> |
| 275 |
<li><a id="grid-view"><?php _e('Grid', 'maxgalleria') ?></a></li> |
| 276 |
</ul> |
| 277 |
<?php } ?> |
| 278 |
<div class="clear"></div> |
| 279 |
|
| 280 |
<div class="media"> |
| 281 |
<div class="adding-videos-note alert alert-info"> |
| 282 |
<div class="gif"> |
| 283 |
<img src="<?php echo MAXGALLERIA_PLUGIN_URL ?>/images/loading-small.gif" width="16" height="16" alt="" /> |
| 284 |
</div> |
| 285 |
<div class="text"> |
| 286 |
<h4><?php _e('Adding videos, one moment...', 'maxgalleria') ?></h4> |
| 287 |
</div> |
| 288 |
<div class="clear"></div> |
| 289 |
</div> |
| 290 |
|
| 291 |
<?php if (count($attachments) < 1) { ?> |
| 292 |
<h4><?php _e('No videos have been added to this gallery.', 'maxgalleria') ?></h4> |
| 293 |
<?php } else { ?> |
| 294 |
<table id="gallery-media" cellpadding="0" cellspacing="0"> |
| 295 |
<thead> |
| 296 |
<tr> |
| 297 |
<th class="order"> </th> |
| 298 |
<th class="checkbox"><input type="checkbox" name="select-all" id="select-all" /></th> |
| 299 |
<th> </th> |
| 300 |
<th> </th> |
| 301 |
<th class="reorder"><?php _e('Reorder', 'maxgalleria') ?></th> |
| 302 |
</tr> |
| 303 |
</thead> |
| 304 |
<tbody> |
| 305 |
<?php foreach ($attachments as $attachment) { ?> |
| 306 |
<?php $is_excluded = get_post_meta($attachment->ID, 'maxgallery_attachment_video_exclude', true) ?> |
| 307 |
|
| 308 |
<tr id="<?php echo $attachment->ID ?>"> |
| 309 |
<td class="order"><?php echo $attachment->menu_order ?></td> |
| 310 |
<td class="checkbox"> |
| 311 |
<input type="checkbox" name="media-id[]" id="media-id-<?php echo $attachment->ID ?>" value="<?php echo $attachment->ID ?>" /> |
| 312 |
<input type="hidden" name="media-order[]" id="media-order-<?php echo $attachment->ID ?>" value="<?php echo $attachment->menu_order ?>" class="media-order-input" /> |
| 313 |
<input type="hidden" name="media-order-id[]" id="media-order-id-<?php echo $attachment->ID ?>" value="<?php echo $attachment->ID ?>" /> |
| 314 |
</td> |
| 315 |
<td class="thumb video"> |
| 316 |
<a href="#" onclick="javascript:viewVideo(<?php echo $attachment->ID ?>); return false;"> |
| 317 |
<?php if ($is_excluded == true) { ?> |
| 318 |
<div class="exclude"> |
| 319 |
<?php echo wp_get_attachment_image($attachment->ID, MAXGALLERIA_META_VIDEO_THUMB_SMALL) ?> |
| 320 |
</div> |
| 321 |
<?php } else { ?> |
| 322 |
<?php echo wp_get_attachment_image($attachment->ID, MAXGALLERIA_META_VIDEO_THUMB_SMALL) ?> |
| 323 |
<?php } ?> |
| 324 |
</a> |
| 325 |
<div class="actions"> |
| 326 |
<a href="#" title="<?php _e('Edit', 'maxgalleria') ?>" onclick="javascript:editVideo(<?php echo $attachment->ID ?>); return false;"><?php _e('Edit', 'maxgalleria') ?></a> | |
| 327 |
<a href="#" title="<?php _e('Remove', 'maxgalleria') ?>" onclick="javascript:removeVideo(<?php echo $attachment->ID ?>); return false;"><?php _e('Remove', 'maxgalleria') ?></a> | |
| 328 |
|
| 329 |
<?php if ($is_excluded) { ?> |
| 330 |
<a href="#" title="<?php _e('Include', 'maxgalleria') ?>" onclick="javascript:includeVideo(<?php echo $attachment->ID ?>); return false;"><?php _e('Include', 'maxgalleria') ?></a> |
| 331 |
<?php } else { ?> |
| 332 |
<a href="#" title="<?php _e('Exclude', 'maxgalleria') ?>" onclick="javascript:excludeVideo(<?php echo $attachment->ID ?>); return false;"><?php _e('Exclude', 'maxgalleria') ?></a> |
| 333 |
<?php } ?> |
| 334 |
</div> |
| 335 |
|
| 336 |
<?php |
| 337 |
//$video_url = str_replace('https://', 'http://', get_post_meta($attachment->ID, 'maxgallery_attachment_video_url', true)); |
| 338 |
$video_url = get_post_meta($attachment->ID, 'maxgallery_attachment_video_url', true); |
| 339 |
$enable_related_videos = get_post_meta($attachment->ID, 'maxgallery_attachment_video_enable_related_videos', true); |
| 340 |
$enable_hd_playback = get_post_meta($attachment->ID, 'maxgallery_attachment_video_enable_hd_playback', true); |
| 341 |
|
| 342 |
// Initialize the embed code and then pass it to the filter to be populated |
| 343 |
$embed_code = ''; |
| 344 |
$embed_code = apply_filters(MAXGALLERIA_FILTER_VIDEO_EMBED_CODE, $embed_code, $video_url, $enable_related_videos, $enable_hd_playback); |
| 345 |
|
| 346 |
echo '<div id="video-' . $attachment->ID . '" style="display: none;">'; |
| 347 |
echo ' <div align="center">'; |
| 348 |
echo $embed_code; |
| 349 |
echo ' </div>'; |
| 350 |
echo '</div>'; |
| 351 |
?> |
| 352 |
</td> |
| 353 |
<td class="text"> |
| 354 |
<div class="details"> |
| 355 |
<div class="detail-label"><?php _e('Title', 'maxgalleria') ?>:</div> |
| 356 |
<div class="detail-value title-value"><?php echo $attachment->post_title ?></div> |
| 357 |
<div class="clear"></div> |
| 358 |
|
| 359 |
<div class="detail-label"><?php _e('Alt Text', 'maxgalleria') ?>:</div> |
| 360 |
<div class="detail-value"><?php echo get_post_meta($attachment->ID, '_wp_attachment_image_alt', true) ?></div> |
| 361 |
<div class="clear"></div> |
| 362 |
|
| 363 |
<div class="detail-label"><?php _e('Caption', 'maxgalleria') ?>:</div> |
| 364 |
<div class="detail-value"><?php echo $attachment->post_excerpt ?></div> |
| 365 |
<div class="clear"></div> |
| 366 |
|
| 367 |
<div class="detail-label"><?php _e('Meta', 'maxgalleria') ?>:</div> |
| 368 |
<div class="detail-value"> |
| 369 |
<?php echo $maxgalleria->common->format_seconds_to_time(get_post_meta($attachment->ID, 'maxgallery_attachment_video_seconds', true)) ?> | |
| 370 |
<?php echo date(get_option('date_format'), strtotime($attachment->post_date)) ?> |
| 371 |
</div> |
| 372 |
<div class="clear"></div> |
| 373 |
|
| 374 |
<div class="detail-label"><?php _e('URL', 'maxgalleria') ?>:</div> |
| 375 |
<div class="detail-value"> |
| 376 |
<a href="<?php echo get_post_meta($attachment->ID, 'maxgallery_attachment_video_url', true) ?>" target="_blank"> |
| 377 |
<?php echo get_post_meta($attachment->ID, 'maxgallery_attachment_video_url', true) ?> |
| 378 |
</a> |
| 379 |
</div> |
| 380 |
<div class="clear"></div> |
| 381 |
</div> |
| 382 |
</td> |
| 383 |
<td class="reorder"> |
| 384 |
<div class="reorder-media"> |
| 385 |
</div> |
| 386 |
</td> |
| 387 |
</tr> |
| 388 |
<?php } ?> |
| 389 |
</tbody> |
| 390 |
</table> |
| 391 |
|
| 392 |
<?php wp_nonce_field($video_gallery->nonce_video_exclude_single['action'], $video_gallery->nonce_video_exclude_single['name']) ?> |
| 393 |
<?php wp_nonce_field($video_gallery->nonce_video_exclude_bulk['action'], $video_gallery->nonce_video_exclude_bulk['name']) ?> |
| 394 |
<?php wp_nonce_field($video_gallery->nonce_video_include_single['action'], $video_gallery->nonce_video_include_single['name']) ?> |
| 395 |
<?php wp_nonce_field($video_gallery->nonce_video_include_bulk['action'], $video_gallery->nonce_video_include_bulk['name']) ?> |
| 396 |
<?php wp_nonce_field($video_gallery->nonce_video_remove_single['action'], $video_gallery->nonce_video_remove_single['name']) ?> |
| 397 |
<?php wp_nonce_field($video_gallery->nonce_video_remove_bulk['action'], $video_gallery->nonce_video_remove_bulk['name']) ?> |
| 398 |
<?php wp_nonce_field($video_gallery->nonce_video_reorder['action'], $video_gallery->nonce_video_reorder['name']) ?> |
| 399 |
<?php } ?> |
| 400 |
</div> |