summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHorus32014-02-26 19:48:59 +0100
committerHorus32014-02-26 19:48:59 +0100
commit71da2f74b621c838f835fd04d6f2d737bfceb6b0 (patch)
treee9361dbd2fcdd33cedff84c73add9c6cf892373d
parentf4c30ebad16c0b72aaf122dab4fb193c780e2ac9 (diff)
downloadrandom-71da2f74b621c838f835fd04d6f2d737bfceb6b0.tar.gz
merged into one file
-rw-r--r--www/youtube.php57
-rw-r--r--www/youtube_functions.php40
-rw-r--r--www/zend_init.php8
3 files changed, 47 insertions, 58 deletions
diff --git a/www/youtube.php b/www/youtube.php
index 062456b..311b2c4 100644
--- a/www/youtube.php
+++ b/www/youtube.php
@@ -1,11 +1,41 @@
<!Doctype html>
+<head>
+<title>Random Youtube Video</title>
+</head>
<body>
<center>
<?php
-require("zend_init.php"); //generates the $yt object, API version 2
-require("youtube_functions.php");
+// generates the $youtube object with API version 2
+$clientLibraryPath = "../zend/library";
+$oldPath = set_include_path(get_include_path() . PATH_SEPARATOR . $clientLibraryPath);
+
+require_once 'Zend/Loader.php'; // the Zend dir must be in your include_path
+Zend_Loader::loadClass('Zend_Gdata_YouTube');
+$yt = new Zend_Gdata_YouTube();
+$yt->setMajorProtocolVersion(2);
+
+function searchterm(){
+ $db = new SQLite3("../database/dict.db");
+
+ $table_array = array("english", "german");
+ $table_count = count("$table_array");
+
+ $table=$table_array[0]; // choose the language
+
+ $rows = $db->query("SELECT count(*) as count FROM ". $table . ";");
+ $row = $rows->fetchArray();
+ $numRows = $row["count"];
+
+
+ $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;
+}
function getAndPrintVideoFeed($location, $yt)
{
@@ -34,22 +64,29 @@ function printVideoEntry($videoEntry)
return $videoId;
}
+function start($yt){
+ $searchstring = searchterm();
-$searchstring = searchterm();
+ $location = $yt->newVideoQuery();
+ $location->setOrderBy('viewCount');
+ $location->setSafeSearch('none');
+ $location->setVideoQuery($searchstring);
-$location = $yt->newVideoQuery();
-$location->setOrderBy('viewCount');
-$location->setSafeSearch('none');
-$location->setVideoQuery($searchstring);
-
-$videoID = getAndPrintVideoFeed($location, $yt);
+ $videoID = getAndPrintVideoFeed($location, $yt);
+ if(file_get_contents("https://gdata.youtube.com/feeds/api/videos/" . $videoID . "")){
+ return $videoID;
+ } else {
+ start();
+ }
+}
-echo "Your youtube Video with the search string: <font color='green'>" . $searchstring . "</font><br> <br>";
+$videoID = start($yt);
?>
+A random youtube video! <br>>
<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>
diff --git a/www/youtube_functions.php b/www/youtube_functions.php
deleted file mode 100644
index 17a8964..0000000
--- a/www/youtube_functions.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?
-
-function get_video(){
-
- $youtube_array = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q",
- "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K",
- "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "_", "-", "0", "1", "2", "3", "4",
- "5", "6", "7", "8", "9" );
-
- $length = count($youtube_array);
-
- $string = "";
-
- for ($i=0;$i<4;$i++){
- $index = mt_rand(0,$length-1);
- $string = "$string".$youtube_array[$index];
- }
- return $string;
-}
-
-function searchterm(){
- $db = new SQLite3("../database/dict.db");
-
- $table_array = array("english", "german");
- $table_count = count("$table_array");
-
- $table=$table_array[0];
-
- $rows = $db->query("SELECT count(*) as count FROM ". $table . ";");
- $row = $rows->fetchArray();
- $numRows = $row["count"];
-
-
- $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;
-}
diff --git a/www/zend_init.php b/www/zend_init.php
deleted file mode 100644
index abfad93..0000000
--- a/www/zend_init.php
+++ /dev/null
@@ -1,8 +0,0 @@
-<?
-$clientLibraryPath = "../zend/library";
-$oldPath = set_include_path(get_include_path() . PATH_SEPARATOR . $clientLibraryPath);
-
-require_once 'Zend/Loader.php'; // the Zend dir must be in your include_path
-Zend_Loader::loadClass('Zend_Gdata_YouTube');
-$yt = new Zend_Gdata_YouTube();
-$yt->setMajorProtocolVersion(2);