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

Documentation generated on Mon, 11 Mar 2019 14:46:18 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.