-
Notifications
You must be signed in to change notification settings - Fork 20
/
qa-embed-layer.php
116 lines (104 loc) · 4.38 KB
/
qa-embed-layer.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
<?php
class qa_html_theme_layer extends qa_html_theme_base {
// theme replacement functions
function head_custom()
{
qa_html_theme_base::head_custom();
if(qa_opt('embed_enable_thickbox')) {
$this->output('<script type="text/javascript" src="'.QA_HTML_THEME_LAYER_URLTOROOT.'thickbox.js"></script>');
$this->output('<link rel="stylesheet" href="'.QA_HTML_THEME_LAYER_URLTOROOT.'thickbox.css" type="text/css" media="screen" />');
}
}
function q_view_content($q_view)
{
if (isset($q_view['content'])){
$q_view['content'] = $this->embed_replace($q_view['content']);
}
qa_html_theme_base::q_view_content($q_view);
}
function a_item_content($a_item)
{
if (isset($a_item['content'])) {
$a_item['content'] = $this->embed_replace($a_item['content']);
}
qa_html_theme_base::a_item_content($a_item);
}
function c_item_content($c_item)
{
if (isset($c_item['content'])) {
$c_item['content'] = $this->embed_replace($c_item['content']);
}
qa_html_theme_base::c_item_content($c_item);
}
function embed_replace($text) {
$w = qa_opt('embed_video_width');
$h = qa_opt('embed_video_height');
$w2 = qa_opt('embed_image_width');
$h2 = qa_opt('embed_image_height');
$types = array(
'youtube'=>array(
array(
'https{0,1}:\/\/w{0,3}\.*youtube\.com\/watch\?\S*v=([A-Za-z0-9_-]+)[^< ]*',
'<iframe width="'.$w.'" height="'.$h.'" src="http://www.youtube.com/embed/$1?wmode=transparent" frameborder="0" allowfullscreen></iframe>'
),
array(
'https{0,1}:\/\/w{0,3}\.*youtu\.be\/([A-Za-z0-9_-]+)[^< ]*',
'<iframe width="'.$w.'" height="'.$h.'" src="http://www.youtube.com/embed/$1?wmode=transparent" frameborder="0" allowfullscreen></iframe>'
)
),
'vimeo'=>array(
array(
'https{0,1}:\/\/w{0,3}\.*vimeo\.com\/([0-9]+)[^< ]*',
'<iframe src="http://player.vimeo.com/video/$1?title=0&byline=0&portrait=0&wmode=transparent" width="'.$w.'" height="'.$h.'" frameborder="0"></iframe>')
),
'metacafe'=>array(
array(
'https{0,1}:\/\/w{0,3}\.*metacafe\.com\/watch\/([0-9]+)\/([a-z0-9_]+)[^< ]*',
'<embed flashVars="playerVars=showStats=no|autoPlay=no" src="http://www.metacafe.com/fplayer/$1/$2.swf" width="'.$w.'" height="'.$h.'" wmode="transparent" allowFullScreen="true" allowScriptAccess="always" name="Metacafe_$1" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>'
)
),
'dailymotion'=>array(
array(
'https{0,1}:\/\/w{0,3}\.*dailymotion\.com\/video\/([A-Za-z0-9]+)[^< ]*',
'<iframe frameborder="0" width="'.$w.'" height="'.$h.'" src="http://www.dailymotion.com/embed/video/$1?wmode=transparent"></iframe>'
)
),
'image'=>array(
array(
'(https*:\/\/[-\%_\/.a-zA-Z0-9+]+\.(png|jpg|jpeg|gif|bmp))[^< ]*',
'<img src="$1" style="max-width:'.$w2.'px;max-height:'.$h2.'px" />','img'
)
),
'mp3'=>array(
array(
'(https*:\/\/[-\%_\/.a-zA-Z0-9]+\.mp3)[^< ]*',qa_opt('embed_mp3_player_code'),'mp3'
)
),
'gmap'=>array(
array(
'(https*:\/\/maps.google.com\/?[^< ]+)',
'<iframe width="'.qa_opt('embed_gmap_width').'" height="'.qa_opt('embed_gmap_height').'" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="$1&ie=UTF8&output=embed"></iframe><br /><small><a href="$1&ie=UTF8&output=embed" style="color:#0000FF;text-align:left">View Larger Map</a></small>','gmap'
)
),
);
foreach($types as $t => $ra) {
foreach($ra as $r) {
if( (!isset($r[2]) && !qa_opt('embed_enable')) || (isset($r[2]) && !qa_opt('embed_enable_'.$r[2])) ) continue;
if(isset($r[2]) && @$r[2] == 'img' && qa_opt('embed_enable_thickbox') && preg_match('/MSIE [5-7]/',$_SERVER['HTTP_USER_AGENT']) == 0) {
preg_match_all('/'.$r[0].'/',$text,$imga);
if(!empty($imga)) {
foreach($imga[1] as $img) {
$replace = '<a href="'.$img.'" class="thickbox"><img src="'.$img.'" style="max-width:'.$w2.'px;max-height:'.$h2.'px" /></a>';
$text = preg_replace('|<a[^>]+>'.$img.'</a>|i',$replace,$text);
$text = preg_replace('|(?<![\'"=])'.$img.'|i',$replace,$text);
}
}
continue;
}
$text = preg_replace('/<a[^>]+>'.$r[0].'<\/a>/i',$r[1],$text);
$text = preg_replace('/(?<![\'"=])'.$r[0].'/i',$r[1],$text);
}
}
return $text;
}
}