Services_YouTube
[ class tree: Services_YouTube ] [ index: Services_YouTube ] [ all elements ]

Source for file example.php

Documentation is available at example.php

  1. <?php
  2. error_reporting(E_ALL|E_STRICT);
  3. require_once 'Services/YouTube.php';
  4. define('MAX_COLS'5);
  5.  
  6. define('DEV_ID''YOUR_DEV_ID');
  7.  
  8. function getFeaturedVideos()
  9. {
  10.     $youtube = new Services_YouTube(DEV_ID);
  11.     $response $youtube->listFeatured();
  12.     if (isset($response->error)) {
  13.         throw new Services_YouTube_Exception($response->error->description);
  14.     }
  15.     return $response;
  16. }
  17.  
  18. function getTaggedVideos($tag$page)
  19. {
  20.     if (is_array($tag)) {
  21.         $tag implode(" "$tag);
  22.     }
  23.     $youtube = new Services_YouTube(DEV_ID);
  24.     $response $youtube->listByTag($tag$page25);
  25.     if (isset($response->error)) {
  26.         throw new Services_YouTube_Exception($response->error->description);
  27.     }
  28.     return $response;
  29. }
  30.  
  31. function getVideoTable($response)
  32. {
  33.     $table"<table border='1'>\n";
  34.     foreach ($response->xpath('//video'as $i => $video{
  35.         if ($i MAX_COLS == 0{
  36.             $table .= "<tr>";
  37.         }
  38.  
  39.         $table .= <<<EOF
  40. <td>
  41. <a href='javascript:openVideo("{$video->id}");'>
  42. <img src='{$video->thumbnail_url}' alt='{$video->title}' /></a>
  43. <br/>
  44. <small><a href='javascript:openVideo("{$video->id}");'>{$video->title}</a></small>
  45. </a>
  46. <small>(<a href='{$video->url}'>Details</a>)</small>
  47. </td>
  48. EOF;
  49.  
  50.         if ($i MAX_COLS == MAX_COLS -1{
  51.             $table .= "</tr>";
  52.         }
  53.     }
  54.     $table .= "</table>";
  55.     return $table;
  56. }
  57.  
  58. function output($table)
  59. {
  60.     print <<<EOF
  61. <html>
  62. <head>
  63. <title>Example</title>
  64. <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
  65. <script type="text/javascript" src="javascripts/prototype.js"> </script>
  66. <script type="text/javascript" src="javascripts/effects.js"> </script>
  67. <script type="text/javascript" src="javascripts/window.js"> </script>
  68. <link href="themes/default.css" rel="stylesheet" type="text/css"></link>
  69.  
  70. <script type="text/javascript">
  71. var win;
  72. function openVideo(video_id) {
  73.     if (win == undefined) {
  74.         win = new Window('window_id', {className: "dialog",width:445,height:370,zIndex: 100,resizable: true,title: "Sample window",showEffect:Effect.BlindDown,hideEffect: Effect.SwitchOff,draggable:true});
  75.     }
  76.  
  77.     win.getContent().innerHTML= '<div style="padding:10px"><object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/' + video_id + '"></param><embed src="http://www.youtube.com/v/' + video_id + '" type="application/x-shockwave-flash" width="425" height="350"></embed></object></div>';
  78.  
  79.     win.showCenter();
  80. }
  81. </script>
  82.  
  83. </head>
  84. <body>
  85. <h1>This is sample</h1>
  86. <div>Here is the sample using my dev id.</div>
  87. <a href="http://www.ganchiku.com/playgrounds/example.php">Featured List</a>
  88. <hr />
  89. <div>
  90. <form action="example.php" method="get">
  91. <input type="text" name="tag" size="16" maxlength="255">
  92. <input type="submit" value="GET TAGGED VIDEOS!">
  93. </form>
  94. </div>
  95. <div>
  96. $table
  97. </div>
  98. </body>
  99. </html>
  100. EOF;
  101. }
  102.  
  103. function main()
  104. {
  105.     try {
  106.         if (isset($_REQUEST['tag'])) {
  107.             $videos getTaggedVideos($_REQUEST['tag']1);
  108.         else {
  109.             $videos getFeaturedVideos();
  110.         }
  111.     catch (Services_YouTube_Exception $e{
  112.         print $e;
  113.         print '<hr>';
  114.         print '<div>Here is the sample using my dev id.</div>';
  115.         print '<a href="http://www.ganchiku.com/playgrounds/example.php">Featured List</a>';
  116.         print "error";
  117.         exit;
  118.     }
  119.     $table getVideoTable($videos);
  120.     output($table);
  121. }
  122.  
  123. main();
  124.  
  125. ?>

Documentation generated on Mon, 11 Mar 2019 15:28:16 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.