-
Notifications
You must be signed in to change notification settings - Fork 1
/
class-sublimevideo-utils.php
111 lines (91 loc) · 3.06 KB
/
class-sublimevideo-utils.php
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
<?php
/**
* This class contains some utility methods for:
* - the settings page,
* - the video setup assistant page,
* - the shortcode generation and transformation,
* - other utility tools.
*/
class SublimeVideoUtils {
// Settings stuff
static function authorize_form($authorize_url) {
global $sublimevideo;
return $sublimevideo->t('authorize_text').sprintf($sublimevideo->t('authorize_form'), $authorize_url);
}
static function video_default_width() {
return (int) ($GLOBALS['content_width'] ? $GLOBALS['content_width'] : (get_option('embed_size_w') ? get_option('embed_size_w') : 500));
}
static function site_with_wildcard_and_path($site) {
global $sublimevideo;
if ($site->main_domain != '') {
$text = "";
if ($site->wildcard) $text .= "(*)";
$text .= $site->main_domain;
if ($site->path != '') $text .= "/".$site->path;
}
else $text = "domain not specified";
return $text;
}
// Video setup assistant stuff
static function images() {
$args = array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'post_mime_type' => 'image',
'numberposts' => 50
);
$posts = get_posts($args);
$images = array();
if ($posts) {
foreach ($posts as $image) {
$metadata = wp_get_attachment_metadata($image->ID);
// Ensure that the image has metadatas (especially including a thumbnail)
if (!empty($metadata) && isset($metadata['file']) && isset($metadata['sizes']) && isset($metadata['sizes']['thumbnail']) && isset($metadata['sizes']['thumbnail']['file'])) {
$images[] = array_merge(array('id' => $image->ID), $metadata);
}
}
}
return json_encode($images);
}
static function guess_type_from_url($url) {
$ext = pathinfo($url, PATHINFO_EXTENSION);
if (preg_match("/mp4|m4v|mov/i", $ext)) return 'mp4';
elseif (preg_match("/webm|og[gv]/i", $ext) ) return 'webm_ogg';
return null;
}
static function videos_urls() {
$args = array(
'post_type' => 'attachment',
'numberposts' => 100,
'post_status' => null,
'post_mime_type' => 'video',
'post_parent' => null
);
$posts = get_posts( $args );
$videos_urls = array('mp4' => array(), 'webm_ogg' => array());
if ($posts) {
foreach ( $posts as $video ) {
$video_url = wp_get_attachment_url($video->ID);
$type = self::guess_type_from_url($video_url);
if ($type) $videos_urls[$type][] = $video_url;
}
}
return $videos_urls;
}
static function options_from_videos_urls($videos_urls, $type) {
$html = "";
$html .= "<option value=''>Choose a video source</option>";
foreach ($videos_urls[$type] as $video_url) {
$html .= "<option value='".$video_url."'>".str_replace(get_option( 'siteurl' )."/wp-content/uploads/", '', $video_url )."</option>";
}
return $html;
}
// Misc stuff
static function non_blank($value) {
return '' != $value;
}
static function strtolower_quoted($value) {
return strtolower("'$value'");
}
}
?>