-
Notifications
You must be signed in to change notification settings - Fork 0
/
single-videos.php
149 lines (131 loc) · 6.32 KB
/
single-videos.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
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
<?php get_header();
$post_title = get_the_title($post);
$video_title = get_field('video_title');
$video_permalink = get_the_permalink();
$video_thumbnail = get_field('video_thumbnail');
$featured_languages = get_field('featured_languages');
$video_description = get_field('video_description');
$youtube_link = get_field('youtube_link');
$wikimedia_commons_link = get_field('wikimedia_commons_link');
$video_license = get_field('video_license');
$license_link = get_field('license_link');
$attribution_statement = get_field('attribution');
$public_status = get_field('public_status');
$youtube_publish_date = get_field('youtube_publish_date');
$date = date_create_from_format('Ymd', $youtube_publish_date);
$formatted_date = date_format($date, 'F j, Y');
if (is_array($license_link)) {
$license_link = $license_link[0];
}
// Converts YouTube URL's to embeddable form
// https://stackoverflow.com/a/41910059
function get_youtube_embed_url($url) {
$short_url_regex = '/youtu.be\/([a-zA-Z0-9_-]+)\??/i';
$long_url_regex = '/youtube.com\/((?:embed)|(?:watch))((?:\?v\=)|(?:\/))([a-zA-Z0-9_-]+)/i';
if (preg_match($long_url_regex, $url, $matches)) {
$youtube_id = $matches[count($matches) - 1];
}
if (preg_match($short_url_regex, $url, $matches)) {
$youtube_id = $matches[count($matches) - 1];
}
return 'https://www.youtube.com/embed/' . $youtube_id ;
}
// Gets the URL of the video file from the Wikimedia Commons URL
function get_wikimedia_upload_url($url) {
// https://stackoverflow.com/a/46441957
return str_replace('wiki/', 'wiki/Special:FilePath/', $url);
}
?>
<div class="wt_single-videos">
<div class="wt_single-videos__intro wt_page-intro wt_page-intro--short">
<?php if( $video_title ): ?>
<h1><?php echo $video_title; ?></h1>
<?php else: ?>
<h1><?php echo $post_title; ?></h1>
<?php endif; ?>
</div>
<div class="wt_single-videos__body">
<?php if ( $public_status == 'Removed' || $public_status == 'Private' ): ?>
<p>This video is not publicly available.</p>
<?php else: ?>
<?php if ( $youtube_link != 'No ID' || $wikimedia_commons_link ): ?>
<?php if ( $youtube_link != 'No ID' ): ?>
<!-- Embed YouTube video -->
<div class="wt_single-videos__iframe">
<iframe width="100%" height="100%"
src="<?php echo get_youtube_embed_url($youtube_link); ?>">
</iframe>
</div>
<?php elseif ( $wikimedia_commons_link ): ?>
<!-- Embed Wikimedia video -->
<video width="480" height="270" controls>
<source src="<?php echo get_wikimedia_upload_url($wikimedia_commons_link); ?>" type="video/webm">
Your browser does not support this video.
</video>
<?php endif; ?>
<?php else: ?>
<p>This video is not yet available. <a class="inline" href="http://www.youtube.com/user/wikitongues?sub_confirmation=1">Subscribe on YouTube</a> to know when it's published.</p>
<?php endif; ?>
<?php endif; ?>
<p>
<strong>Published <?php echo $formatted_date; ?></strong>
</p>
<p class="wt_single-videos__description">
<?php echo $video_description; ?>
</p>
<!-- show language names -->
<h3>Featured Languages</h3>
<?php if( $featured_languages ): ?>
<p>
<?php foreach( $featured_languages as $post ):
setup_postdata( $post );
$ISO_code = get_the_title();
$language_name = get_field('standard_name');
$language_url = get_the_permalink(); ?>
<span>
<a href="<?php echo $language_url; ?>">
<?php echo $language_name; ?> [<?php echo $ISO_code; ?>]
</a>
</span>
<?php endforeach; wp_reset_postdata(); ?>
</p>
<?php else: ?>
<p>Sorry, languages aren't loading right now.</p>
<?php endif; ?>
<!-- /show language names -->
<h3>Licensing</h3>
<p>
<a href="<?php echo $license_link; ?>"><?php echo $video_license; ?></a>
</p>
<!-- <?php echo $attribution_statement; ?> -->
</div>
</div>
<div class="pagination">
<a href="<?php bloginfo('url'); ?>/videos">Explore all videos</a> | <a href="<?php bloginfo('url'); ?>/languages">Explore all languages</a>
</div>
<!--
/* ================= *\
* Donate Banner *
\* ================= */ -->
<?php
// define variables for donate CTA at bottom of layout
$donate_banner_header = get_field('donate_banner_header');
$donate_banner_copy = get_field('donate_banner_copy');
$donate_banner_form_embed = get_field('donate_banner_form_embed');
// load donate CTA ?>
<div class="wt_donate-banner banner_element">
<div class="inner-wrap">
<aside class="wt_donate-banner-header">
<h1>For $250, you can help save a language</h1>
<p>
<strong>*</strong> That's just <strong>$20.84 per month</strong>!
</p>
</aside>
<aside class="wt_donate-banner-form">
<script src="https://donorbox.org/widget.js" paypalExpress="false"></script><iframe src="https://donorbox.org/embed/wikitongues?amount=20.84&default_interval=m" height="685px" width="100%" style="max-width:500px; min-width:310px; max-height:none!important" seamless="seamless" name="donorbox" frameborder="0" scrolling="no" allowpaymentrequest></iframe>
</aside>
<div class="clear"></div>
</div>
</div>
</div>
<?php get_footer(); ?>