-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathsmartideo.php
More file actions
250 lines (215 loc) · 11.4 KB
/
Copy pathsmartideo.php
File metadata and controls
250 lines (215 loc) · 11.4 KB
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<?php
/*
Plugin Name: Smartideo
Plugin URI: https://7yper.com/3639
Description: Smartideo 是为 WordPress 添加对在线视频支持的一款插件(支持手机、平板等设备HTML5播放)。 目前支持YouTube、哔哩哔哩、抖音、腾讯视频、优酷、搜狐视频、56等网站。
Version: 2.9.0
Stable tag: 2.9.0
Author: Fens Liu
Author URI: https://7yper.com/3639
*/
define('SMARTIDEO_VERSION', '2.9.0');
define('SMARTIDEO_URL', plugins_url('', __FILE__));
define('SMARTIDEO_PATH', dirname( __FILE__ ));
$smartideo = new smartideo();
class smartideo{
private $edit = false;
private $width = '100%';
private $height = '500px';
private $option = array();
public function __construct(){
if(is_admin()){
add_action('admin_menu', array($this, 'admin_menu'));
$this->edit = true;
}
$option = get_option('smartideo_option');
if(empty($option)){
$option = array();
}
$this->option = $option;
extract((array)$option);
add_action('wp_enqueue_scripts', array($this, 'smartideo_scripts'));
wp_embed_unregister_handler('youku');
wp_embed_unregister_handler('tudou');
wp_embed_unregister_handler('56com');
wp_embed_unregister_handler('youtube');
// video
wp_embed_register_handler( 'smartideo_youtube',
'#https?://www\.youtube\.com/watch\?v=(?<video_id>[a-zA-Z0-9_=\-]+)#i',
array($this, 'smartideo_embed_handler_youtube') );
wp_embed_register_handler( 'smartideo_b23',
'#https?://b23\.tv/(BV[a-zA-Z0-9]+|av\d+)#i',
array($this, 'smartideo_embed_handler_b23') );
wp_embed_register_handler( 'smartideo_bilibili',
'#https?://www\.bilibili\.com/video/(?:[av|BV]+)(?:(?<video_id1>[a-zA-Z0-9_=\-]+)/(?:index_|\#page=)(?<video_id2>[a-zA-Z0-9_=\-]+)|(?<video_id>[a-zA-Z0-9_=\-]+))#i',
array($this, 'smartideo_embed_handler_bilibili') );
wp_embed_register_handler( 'smartideo_douyin',
'#https?://www\.douyin\.com/(?:[a-z]+\?modal_id=(?<video_id>\d+)|video/(?<video_id2>\d+))#i',
array($this, 'smartideo_embed_handler_douyin') );
wp_embed_register_handler( 'smartideo_youku',
'#https?://v\.youku\.com/(?:v_show/id_(?<video_id1>[a-z0-9_=\-]+)\.html|video\?vid=(?<video_id2>[a-z0-9_=\-]+))#i',
array($this, 'smartideo_embed_handler_youku') );
wp_embed_register_handler( 'smartideo_qq',
'#https?://v\.qq\.com/(?:[a-z0-9_\./]+\?vid=(?<video_id1>[a-z0-9_=\-]+)|(?:[a-z0-9/]+)/(?<video_id2>[a-z0-9_=\-]+)(?:\.html)?)#i',
array($this, 'smartideo_embed_handler_qq') );
wp_embed_register_handler( 'smartideo_sohu',
'#https?://my\.tv\.sohu\.com/(?:pl|us)/(?:\d+)/(?<video_id>\d+)#i',
array($this, 'smartideo_embed_handler_sohu') );
wp_embed_register_handler( 'smartideo_acfun',
'#https?://www\.acfun\.(?:[tv|cn]+)/v/ac(?<video_id>\d+)#i',
array($this, 'smartideo_embed_handler_acfun') );
wp_embed_register_handler( 'smartideo_56',
'#https?://(?:www\.)?56\.com/[a-z0-9]+/(?:play_album\-aid\-[0-9]+_vid\-(?<video_id1>[a-z0-9_=\-]+)|v_(?<video_id2>[a-z0-9_=\-]+))#i',
array($this, 'smartideo_embed_handler_56') );
// music
wp_embed_register_handler( 'smartideo_music163',
'#https?://music\.163\.com/(?:\#/)?song(?:\?id=(?<video_id>\d+)|/(?<video_id2>\d+))?#i',
array($this, 'smartideo_embed_handler_music163') );
wp_embed_register_handler( 'smartideo_musicqq',
'#https?://y\.qq\.com/n/(?:ryqq|yqq)/(?:songDetail|song)/(?<video_id>\d+)(?:\.html)?#i',
array($this, 'smartideo_embed_handler_musicqq') );
}
# video
public function smartideo_embed_handler_youtube( $matches, $attr, $url, $rawattr ) {
$domain = !empty($this->option['youtube_nocookie']) ? 'www.youtube-nocookie.com' : 'www.youtube.com';
$embed = $this->get_iframe("//{$domain}/embed/{$matches['video_id']}", $url);
return apply_filters( 'embed_youtube', $embed, $matches, $attr, $url, $rawattr );
}
public function smartideo_embed_handler_b23( $matches, $attr, $url, $rawattr ) {
$id = $matches['video_id'];
if(is_numeric($id)){
$aid = $id;
$bvid = '';
}else{
$aid = 0;
$bvid = $id;
}
$embed = $this->get_iframe("//player.bilibili.com/player.html?aid={$aid}&bvid={$bvid}&cid=&page=1", $url);
return apply_filters( 'embed_b23', $embed, $matches, $attr, $url, $rawattr );
}
public function smartideo_embed_handler_bilibili( $matches, $attr, $url, $rawattr ) {
$matches['video_id'] = ($matches['video_id1'] == '') ? $matches['video_id'] : $matches['video_id1'];
$page = ($matches['video_id2'] > 1) ? $matches['video_id2'] : 1;
$aid = 0;
$bvid = '';
if(is_numeric($matches['video_id'])){
$aid = $matches['video_id'];
}else{
$bvid = $matches['video_id'];
}
$embed = $this->get_iframe("//player.bilibili.com/player.html?aid={$aid}&bvid={$bvid}&cid=&page={$page}", $url);
return apply_filters( 'embed_bilibili', $embed, $matches, $attr, $url, $rawattr );
}
// 父容器宽度大于750px时,才会匹配横屏播放器
public function smartideo_embed_handler_douyin( $matches, $attr, $url, $rawattr ) {
$vid = !empty($matches['video_id']) ? $matches['video_id'] : $matches['video_id2'];
$embed = $this->get_iframe("//open.douyin.com/player/video?vid={$vid}&autoplay=0", $url);
return apply_filters( 'embed_douyin', $embed, $matches, $attr, $url, $rawattr );
}
public function smartideo_embed_handler_youku( $matches, $attr, $url, $rawattr ) {
$matches['video_id'] = $matches['video_id1'] == '' ? $matches['video_id2'] : $matches['video_id1'];
$embed = $this->get_iframe("//player.youku.com/embed/{$matches['video_id']}", $url);
return apply_filters( 'embed_youku', $embed, $matches, $attr, $url, $rawattr );
}
public function smartideo_embed_handler_qq( $matches, $attr, $url, $rawattr ) {
$matches['video_id'] = $matches['video_id1'] == '' ? $matches['video_id2'] : $matches['video_id1'];
$embed = $this->get_iframe("//v.qq.com/iframe/player.html?vid={$matches['video_id']}&auto=0", $url);
return apply_filters( 'embed_qq', $embed, $matches, $attr, $url, $rawattr );
}
public function smartideo_embed_handler_sohu( $matches, $attr, $url, $rawattr ) {
$embed = $this->get_iframe("//tv.sohu.com/upload/static/share/share_play.html#{$matches['video_id']}_0_0_9001_0", $url);
return apply_filters( 'embed_sohu', $embed, $matches, $attr, $url, $rawattr );
}
public function smartideo_embed_handler_acfun( $matches, $attr, $url, $rawattr ) {
$embed = $this->get_iframe("https://www.acfun.cn/player/ac{$matches['video_id']}", $url);
return apply_filters( 'embed_acfun', $embed, $matches, $attr, $url, $rawattr );
}
public function smartideo_embed_handler_56( $matches, $attr, $url, $rawattr ) {
$matches['video_id'] = $matches['video_id1'] == '' ? $matches['video_id2'] : $matches['video_id1'];
$embed = $this->get_iframe("http://www.56.com/iframe/{$matches['video_id']}", $url);
return apply_filters( 'embed_56', $embed, $matches, $attr, $url, $rawattr );
}
# music
public function smartideo_embed_handler_music163( $matches, $attr, $url, $rawattr ) {
$id = !empty($matches['video_id']) ? $matches['video_id'] : $matches['video_id2'];
$embed = $this->get_iframe("//music.163.com/outchain/player?type=2&id={$id}&auto=0&height=90", $url, '100%', '110px');
return apply_filters( 'embed_music163', $embed, $matches, $attr, $url, $rawattr );
}
public function smartideo_embed_handler_musicqq( $matches, $attr, $url, $rawattr ) {
$embed = $this->get_iframe("//i.y.qq.com/n2/m/outchain/player/index.html?songid={$matches['video_id']}&songtype=0", $url, '100%', '66px');
return apply_filters( 'embed_musicqq', $embed, $matches, $attr, $url, $rawattr );
}
private function get_iframe($url = '', $source = '', $width = '', $height = ''){
// 全局源站播放:将所有嵌入替换为源站链接
if(!empty($this->option['jump_play']) && !$this->edit){
return $this->get_link($source);
}
$html = '';
$html .=
'<div class="smartideo">
<div class="player"' . $this->get_size_style($width, $height) . '>
<iframe src="' . $url . '" width="100%" height="100%" frameborder="0" allowfullscreen="true" scrolling="no" loading="lazy" referrerpolicy="unsafe-url"></iframe>
</div>';
if(isset($this->option['tips_status']) && $this->option['tips_status'] == 1 && !$this->edit){
if(empty($source)){
$source = 'javascript:void(0);';
}
$html .=
'<div class="tips">
<a href="' . $source . '" target="_blank" smartideo-title="' . $this->option['tips_content'] . '" smartideo-title-mobile="' . $this->option['tips_content_mobile'] . '" title="' . $this->option['tips_content'] . '" class="smartideo-tips" rel="nofollow"></a>
</div>';
}
$html .= '</div>';
return $html;
}
private function get_link($url){
$html = '';
$html .=
'<div class="smartideo">
<div class="player"' . $this->get_size_style(0, 0) . '>
<a href="' . $url . '" target="_blank" class="smartideo-play-link"><div class="smartideo-play-button"></div></a>
<p style="color: #999;margin-top: 50px;">暂时无法播放,可回源网站播放</p>
</div>
</div>';
return $html;
}
public function smartideo_scripts(){
wp_enqueue_style('smartideo_css', SMARTIDEO_URL . '/static/smartideo.css', array(), SMARTIDEO_VERSION, 'screen');
wp_enqueue_script('smartideo_js', SMARTIDEO_URL . '/static/smartideo.js', array(), SMARTIDEO_VERSION, true);
}
public function admin_menu(){
add_plugins_page('Smartideo 设置', 'Smartideo 设置', 'manage_options', 'smartideo_settings', array($this, 'admin_settings'));
}
public function admin_settings(){
require_once 'smartideo-admin.php';
new smartideo_admin();
}
private function get_size_style($width, $height){
if(empty($width) || empty($height)){
$width = $height = 0;
if($this->edit){
$width = $this->width;
$height = $this->height;
}else if(isset($this->option['response']) && $this->option['response'] == 0){
if(wp_is_mobile()){
$width = $this->option['width_mobile'];
$height = $this->option['height_mobile'];
}else{
$width = $this->option['width'];
$height = $this->option['height'];
}
}
}
$style = '';
if(!empty($width)){
$style .= "width: {$width};";
}
if(!empty($height)){
$style .= "height: {$height};";
}
if(!empty($style)){
$style = ' style="' . $style . '"';
}
return $style;
}
}