-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_helper.php
More file actions
146 lines (97 loc) · 3.31 KB
/
Copy pathcustom_helper.php
File metadata and controls
146 lines (97 loc) · 3.31 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
<?php
function clear_name($string=null){
if( empty($string) )
return false;
$string = str_replace(' ', '+', $string);
return $string;
}
function get_image_src($path=null){
$img_default = 'media/images/no_cover.jpg';
if( is_null($path) || $path == '' )
return $img_default;
return $path;
}
function get_duration($duration=null){
if( is_null($duration) || $duration == '' )
return '0:00';
return date('i:s', $duration/1000);
}
function get_youtube_url($artist=null, $track=null){
if( is_null($artist) || is_null($track) )
return false;
$artist = clear_name($artist);
$track = clear_name($track);
$url_youtube = 'http://gdata.youtube.com/feeds/api/videos?q='.$artist.'-'.$track.'&start-index=21&max-results=10&v=2';
$xml_utube = file_get_contents($url_youtube);
$xml = simplexml_load_string($xml_utube);
foreach( $xml->entry as $entry ){
return $entry->link[0]['href'];
}
}
function video_image($url, $link=false)
{
$image_url = parse_url($url);
$img_link = null;
if(isset($image_url['host']))
{
if($image_url['host'] == 'www.youtube.com' || $image_url['host'] == 'youtube.com')
{
$array = explode("&", $image_url['query']);
$img_link = "http://img.youtube.com/vi/".substr($array[0], 2)."/default.jpg";
}
else if($image_url['host'] == 'www.vimeo.com' || $image_url['host'] == 'vimeo.com')
{
// Preparando o Cache para os dados do Vimeo devido ao seu tempo demorado de resposta (~ 7seg)
$CI =& get_instance();
$CI->load->driver('cache');
if ( ! $hash = $CI->cache->file->get(url_title($url)))
{
$CI->cache->file->save(
url_title($url),
unserialize(file_get_contents("http://vimeo.com/api/v2/video/".substr($image_url['path'], 1).".php")),
1314000);
}
$img_link = $hash[0]["thumbnail_small"];
}
}
if( $link )
return ($img_link) ? $img_link : '/img/icons/video.png';
else
return ($img_link) ? '<img src="'.$img_link.'" />' : '<img src="/img/icons/video.png" />';
}
function get_id_video($url, $site = 'youtube')
{
$id = 0;
if($site === 'youtube')
{
$url = parse_url($url);
$array = explode("&", $url['query']);
$id = substr($array[0], 2);
}
elseif($site === 'vimeo')
{
$array = explode('vimeo.com/',$url);
$id = $array[1];
}
return $id;
}
function link_to_embed($url, $width=355, $height=250){
$site = (strpos($url, 'youtube')) ? 'youtube' : 'vimeo';
$id = get_id_video($url, $site);
if($id != false){
if($site === 'youtube'){
return '<iframe height="'.$height.'" width="'.$width.'" src="http://www.youtube.com/embed/'.$id.'?wmode=transparent" frameborder="0"></iframe>';
} elseif($site === 'vimeo') {
return '<iframe src="http://player.vimeo.com/video/'.$id.'?title=0&byline=0&portrait=0" width="'.$width.'" height="'.$height.'" frameborder="0"></iframe>';
}
}
}
function prepare_date_mysql($date){
$d = substr($date,0,2);
$m = substr($date,3,2);
$a = substr($date,6,4);
return $a . '/' . $m . '/' . $d;
}
function prepare_date_br($date){
return date('d/m/Y', strtotime($date));
}