summaryrefslogtreecommitdiff
path: root/www
diff options
context:
space:
mode:
authorroot2014-02-26 17:25:43 +0100
committerroot2014-02-26 17:25:43 +0100
commit0718ff72472754e6116ad58f4ff6bc788f5c3d61 (patch)
tree4d4e243b4f5eb2fb24efb3e975a498d47f25c9f2 /www
parent01e3fb742f09593532e5db5f3c780577c1ca2dec (diff)
downloadrandom-0718ff72472754e6116ad58f4ff6bc788f5c3d61.tar.gz
It works!
Diffstat (limited to 'www')
-rw-r--r--www/youtube.php71
-rw-r--r--www/youtube_functions.php13
2 files changed, 33 insertions, 51 deletions
diff --git a/www/youtube.php b/www/youtube.php
index 01db8d7..062456b 100644
--- a/www/youtube.php
+++ b/www/youtube.php
@@ -1,3 +1,7 @@
+<!Doctype html>
+<body>
+<center>
+
<?php
require("zend_init.php"); //generates the $yt object, API version 2
@@ -7,74 +11,47 @@ function getAndPrintVideoFeed($location, $yt)
{
$videoFeed = $yt->getVideoFeed($location);
- printVideoFeed($videoFeed);
+ $videoID = printVideoFeed($videoFeed);
+ return $videoID;
}
function printVideoFeed($videoFeed)
{
- $count = 1;
- foreach ($videoFeed as $videoEntry) {
- echo "Entry # " . $count . "\n";
- printVideoEntry($videoEntry);
- echo "\n";
- $count++;
- }
+
+ $res_quant = count($videoFeed);
+
+ $video = mt_rand(1, $res_quant);
+
+ $videoId = printVideoEntry($videoFeed[$video]);
+
+ return $videoId;
+
}
function printVideoEntry($videoEntry)
{
- // the videoEntry object contains many helper functions
- // that access the underlying mediaGroup object
- echo 'Video: ' . $videoEntry->getVideoTitle() . "\n <br>";
- /* echo 'Video ID: ' . $videoEntry->getVideoId() . "\n";
- echo 'Updated: ' . $videoEntry->getUpdated() . "\n";
- echo 'Description: ' . $videoEntry->getVideoDescription() . "\n";
- echo 'Category: ' . $videoEntry->getVideoCategory() . "\n";
- echo 'Tags: ' . implode(", ", $videoEntry->getVideoTags()) . "\n";
- echo 'Watch page: ' . $videoEntry->getVideoWatchPageUrl() . "\n";
- echo 'Flash Player Url: ' . $videoEntry->getFlashPlayerUrl() . "\n";
- echo 'Duration: ' . $videoEntry->getVideoDuration() . "\n";
- echo 'View count: ' . $videoEntry->getVideoViewCount() . "\n";
- echo 'Rating: ' . $videoEntry->getVideoRatingInfo() . "\n";
- echo 'Geo Location: ' . $videoEntry->getVideoGeoLocation() . "\n";
- echo 'Recorded on: ' . $videoEntry->getVideoRecorded() . "\n";
- */
-
- // see the paragraph above this function for more information on the
- // 'mediaGroup' object. in the following code, we use the mediaGroup
- // object directly to retrieve its 'Mobile RSTP link' child
- /* foreach ($videoEntry->mediaGroup->content as $content) {
- if ($content->type === "video/3gpp") {
- echo 'Mobile RTSP link: ' . $content->url . "\n";
- }
- }
-
- echo "Thumbnails:\n";
- $videoThumbnails = $videoEntry->getVideoThumbnails();
-
- foreach($videoThumbnails as $videoThumbnail) {
- echo $videoThumbnail['time'] . ' - ' . $videoThumbnail['url'];
- echo ' height=' . $videoThumbnail['height'];
- echo ' width=' . $videoThumbnail['width'] . "\n";
- }
- */
+ $videoId = $videoEntry->getVideoId();
+ return $videoId;
}
$searchstring = searchterm();
-//$location = Zend_Gdata_YouTube::VIDEO_URI;
$location = $yt->newVideoQuery();
$location->setOrderBy('viewCount');
$location->setSafeSearch('none');
$location->setVideoQuery($searchstring);
-getAndPrintVideoFeed($location, $yt);
+$videoID = getAndPrintVideoFeed($location, $yt);
+
+echo "Your youtube Video with the search string: <font color='green'>" . $searchstring . "</font><br> <br>";
+?>
-echo "<br>Searchstring: " . $searchstring;
+<iframe width="560" height="315" src="//www.youtube.com/embed/<? echo $videoID ?>" frameborder="0" allowfullscreen></iframe> <br><br>
+<a href="youtube.php">Get another one!</a>
-// <iframe width="560" height="315" src="//www.youtube.com/embed/" frameborder="0" allowfullscreen></iframe>
+</center>
diff --git a/www/youtube_functions.php b/www/youtube_functions.php
index 15153ec..17a8964 100644
--- a/www/youtube_functions.php
+++ b/www/youtube_functions.php
@@ -23,13 +23,18 @@ function searchterm(){
$table_array = array("english", "german");
$table_count = count("$table_array");
-
- $rows = $db->query("SELECT count(*) as count FROM german;");
+
+ $table=$table_array[0];
+
+ $rows = $db->query("SELECT count(*) as count FROM ". $table . ";");
$row = $rows->fetchArray();
$numRows = $row["count"];
-
- $search_word = mt_rand(1,$numRows);
+
+ $random = mt_rand(1,$numRows);
+ $search_word_db = $db->query("SELECT word FROM " . $table . " WHERE id=" . $random . ";");
+ $search_word_ar = $search_word_db->fetchArray();
+ $search_word = $search_word_ar["word"];
return $search_word;
}