View difference between Paste ID: KRwvSzqP and
SHOW:
|
|
- or go back to the newest paste.
1 | - | |
1 | + | <?php |
2 | ||
3 | ||
4 | function curl_get($url) { | |
5 | $curl = curl_init($url); | |
6 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | |
7 | curl_setopt($curl, CURLOPT_TIMEOUT, 30); | |
8 | $return = curl_exec($curl); | |
9 | curl_close($curl); | |
10 | return $return; | |
11 | } | |
12 | ||
13 | // Get the wordpress custom field value | |
14 | $youtubeid = get_post_meta($post->ID, "youtubeid", true); | |
15 | ||
16 | if($youtubeid !== '') : | |
17 | // define URLS | |
18 | $video_url = 'http://youtube.com/watch?v='.$youtubeid; | |
19 | $oembed_endpoint = 'http://www.youtube.com/oembed'; | |
20 | ||
21 | // request Oembed in XML format and proccess it with curl (the function above) | |
22 | $oembed_url = $oembed_endpoint . '?url=' . rawurlencode($video_url) . '&format=xml'; | |
23 | $oembed = simplexml_load_string(curl_get($oembed_url)); | |
24 | ||
25 | // get size values and embed code | |
26 | $youtubeW = html_entity_decode($oembed->width); | |
27 | $youtubeH = html_entity_decode($oembed->height); | |
28 | $youtube_code = html_entity_decode($oembed->html); | |
29 | ||
30 | // define your video width | |
31 | $column_w = 712; | |
32 | ||
33 | // see the difference between original size and your size | |
34 | $percentResized = ($column_w*1)/$youtubeW; | |
35 | ||
36 | // make the original height proportional to your width | |
37 | $newYoutubeH = $youtubeH*$percentResized; | |
38 | ||
39 | // create size arrays for replacing on the $youtube_code string | |
40 | $W_and_H = array($youtubeW, $youtubeH); | |
41 | $Big_W_and_H = array($column_w, $newYoutubeH); | |
42 | ||
43 | // find the original values and replace them with the resized values | |
44 | $bigEmbed = str_replace($W_and_H, $Big_W_and_H, $youtube_code); | |
45 | ||
46 | // hallo todas las cosas q esten entre comillas en mi bigEmbed code | |
47 | preg_match_all('/"([^"]+)"/', | |
48 | $bigEmbed, | |
49 | $salida, PREG_PATTERN_ORDER); | |
50 | ||
51 | // guardo el valor de la url de youtube | |
52 | $clean_movieParama_value = $salida[1][3] ; | |
53 | ||
54 | //echo $clean_movieParama_value; | |
55 | ||
56 | ||
57 | $urlWithOptions = $clean_movieParama_value . "&rel=1&autoplay=1&color1=0xffffff&color2=0xffffff&border=0&fs=1"; | |
58 | ||
59 | ||
60 | // remplaza url limpia con url con parametros | |
61 | $bigEmbed_withOptions = str_replace($clean_movieParama_value, $urlWithOptions, $bigEmbed); | |
62 | ||
63 | ||
64 | echo $bigEmbed_withOptions; | |
65 | ||
66 | ||
67 | endif; | |
68 | ||
69 | ?> |