| 1 |
<?php |
| 2 |
require('../../../../wp-load.php'); |
| 3 |
|
| 4 |
global $maxgalleria; |
| 5 |
$video_gallery = $maxgalleria->video_gallery; |
| 6 |
|
| 7 |
// Get all video media source addons |
| 8 |
$video_addons = array('' => ''); |
| 9 |
$media_source_addons = $maxgalleria->get_media_source_addons(); |
| 10 |
|
| 11 |
foreach ($media_source_addons as $addon) { |
| 12 |
if ($addon['subtype'] == 'video') { |
| 13 |
$video_addons = array_merge($video_addons, array($addon['name'] => $addon['key'])); |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 17 |
// Determine count of video addons |
| 18 |
$video_addons_count = 0; |
| 19 |
foreach ($video_addons as $name => $key) { |
| 20 |
if ($name != '') { |
| 21 |
$video_addons_count++; |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
$gallery = get_post($_GET['post_id']); |
| 26 |
$updated = false; |
| 27 |
|
| 28 |
if ($_POST && check_admin_referer($video_gallery->nonce_video_add['action'], $video_gallery->nonce_video_add['name'])) { |
| 29 |
if (isset($gallery)) { |
| 30 |
if (isset($_POST['video-urls']) && $_POST['video-urls'] != '') { |
| 31 |
$video_urls = explode("\n", $_POST['video-urls']); |
| 32 |
|
| 33 |
do_action(MAXGALLERIA_ACTION_BEFORE_ADD_VIDEOS_TO_GALLERY, $video_urls); |
| 34 |
|
| 35 |
foreach ($video_urls as $video_url) { |
| 36 |
// Use rtrim to remove the \n on the end of the strings |
| 37 |
$video_url = rtrim($video_url); |
| 38 |
|
| 39 |
if ($video_url != '') { |
| 40 |
// Get the data for the video; first initialize the API URL |
| 41 |
// and then pass it to the filter so it can get populated |
| 42 |
$api_url = ''; |
| 43 |
$api_url = apply_filters(MAXGALLERIA_FILTER_VIDEO_API_URL, $api_url, $video_url); |
| 44 |
|
| 45 |
// Continue only if we have an API URL to call |
| 46 |
if ($api_url != '') { |
| 47 |
// Perform a remote GET to get the body of data from |
| 48 |
// the API URL and then decode it into JSON bits |
| 49 |
$response = wp_remote_get($api_url); |
| 50 |
$contents = wp_remote_retrieve_body($response); |
| 51 |
$data = json_decode($contents, true); |
| 52 |
|
| 53 |
// Get the URL of the video thumbnail; first initialize the thumb |
| 54 |
// URL and then pass it to the filter so it can get populated |
| 55 |
$thumb_url = ''; |
| 56 |
$thumb_url = apply_filters(MAXGALLERIA_FILTER_VIDEO_THUMB_URL, $thumb_url, $video_url, $data); |
| 57 |
|
| 58 |
// Now that we have the thumb URL, get its remote contents |
| 59 |
// so we can store it as an attachment for the gallery |
| 60 |
$response = wp_remote_get($thumb_url); |
| 61 |
$contents = wp_remote_retrieve_body($response); |
| 62 |
|
| 63 |
// Upload and get file data |
| 64 |
$upload = wp_upload_bits(basename($thumb_url), null, $contents); |
| 65 |
$guid = $upload['url']; |
| 66 |
$file = $upload['file']; |
| 67 |
$file_type = wp_check_filetype(basename($file), null); |
| 68 |
|
| 69 |
// Set up the video thumb as an attachment; first initialize the |
| 70 |
// attachment and then pass it to the filter so it can get populated |
| 71 |
$attachment = array(); |
| 72 |
$attachment = apply_filters(MAXGALLERIA_FILTER_VIDEO_ATTACHMENT, $attachment, $video_url, $gallery->ID, $guid, $file_type['type'], $data); |
| 73 |
|
| 74 |
// Include image.php so we can call wp_generate_attachment_metadata() |
| 75 |
require_once(ABSPATH . 'wp-admin/includes/image.php'); |
| 76 |
|
| 77 |
// Insert the attachment |
| 78 |
$attachment_id = wp_insert_attachment($attachment, $file, $gallery->ID); |
| 79 |
$attachment_data = wp_generate_attachment_metadata($attachment_id, $file); |
| 80 |
wp_update_attachment_metadata($attachment_id, $attachment_data); |
| 81 |
|
| 82 |
// Save some of the data in the post meta of the attachment |
| 83 |
do_action(MAXGALLERIA_ACTION_VIDEO_ATTACHMENT_POST_META, $attachment_id, $video_url, $thumb_url, $data); |
| 84 |
$updated = true; |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
do_action(MAXGALLERIA_ACTION_AFTER_ADD_VIDEOS_TO_GALLERY, $video_urls); |
| 90 |
} |
| 91 |
} |
| 92 |
} |
| 93 |
?> |
| 94 |
|
| 95 |
<!DOCTYPE html> |
| 96 |
|
| 97 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
| 98 |
|
| 99 |
<head> |
| 100 |
<title><?php _e('Add Videos', 'maxgalleria') ?></title> |
| 101 |
<link rel="stylesheet" type="text/css" media="screen" href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,400,700" /> |
| 102 |
<link rel="stylesheet" type="text/css" media="screen" href="<?php echo MAXGALLERIA_PLUGIN_URL ?>/maxgalleria.css" /> |
| 103 |
<?php $maxgalleria->thickbox_l10n_fix() ?> |
| 104 |
<script type="text/javascript" src="<?php echo admin_url() ?>load-scripts.php?load=jquery-core,thickbox,wp-ajax-response"></script> |
| 105 |
<script type="text/javascript"> |
| 106 |
<?php if ($updated) { ?> |
| 107 |
parent.eval("showAddingVideosNote()"); |
| 108 |
parent.eval("reloadPage()"); |
| 109 |
<?php } ?> |
| 110 |
|
| 111 |
jQuery(document).ready(function() { |
| 112 |
jQuery(".maxgalleria-meta.video-add .actions .loading").css("display", "none"); |
| 113 |
|
| 114 |
jQuery("#save-button").click(function () { |
| 115 |
jQuery(".maxgalleria-meta.video-add .actions .loading").css("display", "inline-block"); |
| 116 |
jQuery("#video-add-form").submit(); |
| 117 |
return false; |
| 118 |
}); |
| 119 |
|
| 120 |
jQuery("#cancel-button").click(function () { |
| 121 |
parent.eval("reloadPage()"); |
| 122 |
}); |
| 123 |
}); |
| 124 |
</script> |
| 125 |
</head> |
| 126 |
|
| 127 |
<body> |
| 128 |
|
| 129 |
<div class="maxgalleria-meta video-add"> |
| 130 |
<?php if ($video_addons_count < 1) { ?> |
| 131 |
<p><?php _e('You do not have any video addons installed.', 'maxgalleria') ?></p> |
| 132 |
<p><?php printf(__('You can get video addons from the %sMaxGalleria website%s.', 'maxgalleria'), '<a href="http://maxgalleria.com/shop/category/addons/" target="_blank">', '</a>') ?></p> |
| 133 |
<div class="actions"> |
| 134 |
<div class="cancel"> |
| 135 |
<input type="button" class="btn" id="cancel-button" value="<?php _e('Close', 'maxgalleria') ?>" /> |
| 136 |
</div> |
| 137 |
</div> |
| 138 |
<?php } else { ?> |
| 139 |
<form id="video-add-form" method="post"> |
| 140 |
<p><?php _e('You can add as many videos to this gallery as you like. Simply enter the URL of each video in the box, and data about each video will be retrieved automatically.', 'maxgalleria') ?></p> |
| 141 |
<p><?php _e('Video URLs from the following sites are currently supported:', 'maxgalleria') ?></p> |
| 142 |
|
| 143 |
<ul class="addons"> |
| 144 |
<?php foreach ($video_addons as $name => $key) { ?> |
| 145 |
<?php if ($name != '') { ?> |
| 146 |
<li><?php echo $name ?></li> |
| 147 |
<?php } ?> |
| 148 |
<?php } ?> |
| 149 |
</ul> |
| 150 |
|
| 151 |
<div class="fields"> |
| 152 |
<div class="field"> |
| 153 |
<div class="field-label"> |
| 154 |
<?php _e('Video URLs', 'maxgalleria') ?> <span><?php _e('Multiple URLs accepted, one per line', 'maxgalleria') ?></span> |
| 155 |
</div> |
| 156 |
<div class="field-value"> |
| 157 |
<textarea name="video-urls"></textarea> |
| 158 |
</div> |
| 159 |
</div> |
| 160 |
</div> |
| 161 |
|
| 162 |
<div class="actions"> |
| 163 |
<div class="save"> |
| 164 |
<input type="button" class="btn btn-primary" id="save-button" value="<?php _e('Add to Gallery', 'maxgalleria') ?>" /> |
| 165 |
</div> |
| 166 |
<div class="cancel"> |
| 167 |
<input type="button" class="btn" id="cancel-button" value="<?php _e('Cancel', 'maxgalleria') ?>" /> |
| 168 |
</div> |
| 169 |
<div class="loading"> |
| 170 |
<div class="gif"> |
| 171 |
<img src="<?php echo MAXGALLERIA_PLUGIN_URL ?>/images/loading-small.gif" width="16" height="16" alt="" /> |
| 172 |
</div> |
| 173 |
<div class="text"> |
| 174 |
<?php _e('Adding media to gallery...', 'maxgalleria') ?> |
| 175 |
</div> |
| 176 |
<div class="clear"></div> |
| 177 |
</div> |
| 178 |
</div> |
| 179 |
|
| 180 |
<?php wp_nonce_field($video_gallery->nonce_video_add['action'], $video_gallery->nonce_video_add['name']) ?> |
| 181 |
</form> |
| 182 |
<?php } ?> |
| 183 |
</div> |
| 184 |
|
| 185 |
</body> |
| 186 |
|
| 187 |
</html> |
| 188 |
|