Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Atualização no youtube_helper #1

Merged
merged 1 commit into from

2 participants

@wfsneto
Collaborator

Agora é possível passar qualquer url do youtube para o helper e foi criado um elemento para deixa a view mais limpa

@brunoziie brunoziie merged commit 11d2a34 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 74 additions and 45 deletions.
  1. +61 −45 app/helpers/youtube_helper.php
  2. +13 −0 app/views/shared/_youtube.htm.php
View
106 app/helpers/youtube_helper.php
@@ -5,56 +5,72 @@
* @license http://www.opensource.org/licenses/mit-license.php
* @copyright Copyright 2008-2009, Spaghetti* Framework http://spaghettiphp.org/
*
+ * Usage on views
+ * <?php
+ * echo $this->element('shared/youtube', array(
+ * 'width' => '970',
+ * 'height' => '475',
+ * 'url_video' => $youtube->getUrl($url_video)
+ * ));
+ * ?>
+ *
*/
class YoutubeHelper extends Helper {
- function thumb($url){
- $arr = explode("watch?v=",$url);
-
- if(count($arr) == 2) {
- $resp = explode("&", $arr[1]);
- if(count($resp) == 0) {
- $link = $arr[1];
- } else {
- $link = $resp[0];
- }
- } else {
- $arr = explode("/v/", $url);
- $resp = explode("&", $arr[1]);
- if(count($resp) == 0) {
- $link = $arr[1];
- } else {
- $link = $resp[0];
- }
- }
-
- return "http://img.youtube.com/vi/" . $link . "/3.jpg";
+ function thumb($url)
+ {
+ return "http://img.youtube.com/vi/" .$this->returnId($url) . "/3.jpg";
}
- function getId($url){
- $arr = explode("watch?v=",$url);
- //$resp = explode("&", $arr[1]);
-
- if(count($arr) == 2) {
- $resp = explode("&", $arr[1]);
- if(count($resp) == 2) {
- $link = $arr[1];
- } else {
- $link = $resp[0];
- }
- } else {
- $arr = explode("/v/", $url);
- $resp = explode("&", $arr[1]);
- if(count($resp) == 0) {
- $link = $arr[1];
- } else {
- $link = $resp[0];
- }
- }
-
- return $link;
+ function getId($url)
+ {
+ return $this->returnId($url);
}
-}
+ function getUrl($url)
+ {
+ return 'http://www.youtube.com/v/' . $this->returnId($url) . '?version=3&amp;hl=pt_BR';
+ }
+
+ private function returnId($url)
+ {
+ $arr = explode("?",$url);
+ $strings = explode("&",$arr[1]);
+ $return = false;
+ foreach ($strings as $key => $string) {
+ $aux = explode('=', $string);
+ $return[$aux[0]] = $aux[1];
+ } # endforeach;
+ $return = $return['v'];
+
+ if ($return) {
+ return $return;
+ } # endif
+ else {
+ $return = false;
+ $arr = explode("/youtu.be/",$url);
+ $aux = explode("/",$arr[1]);
+ $return = $aux[0];
+ } # endelse;
-?>
+ if ($return) {
+ return $return;
+ } # endif
+ else {
+ $return = false;
+ $arr = explode("/www.youtube.com/", $url);
+ $strings = explode("/",$arr[1]);
+ foreach ($strings as $key => $string) {
+ echo "<br>$key => $string";
+
+ if ($string == 'v') {
+ $return = $strings[$key + 1];
+ break;
+ } # endif;
+ } # endforeach;
+ } # endelse;
+
+ return $return;
+ }
+
+}
View
13 app/views/shared/_youtube.htm.php
@@ -0,0 +1,13 @@
+<object width="<?php echo $width ?>" height="<?php echo $height ?>">
+ <param name="movie" value="<?php echo $url_video ?>"></param>
+ <param name="allowFullScreen" value="true"></param>
+ <param name="allowscriptaccess" value="always"></param>
+ <embed
+ src="<?php echo $url_video ?>"
+ type="application/x-shockwave-flash"
+ width="<?php echo $width ?>" height="<?php echo $height ?>"
+ wmode="opaque"
+ allowscriptaccess="always"
+ allowfullscreen="true">
+ </embed>
+</object>
Something went wrong with that request. Please try again.