Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/repository/youtube/lib.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00029 class repository_youtube extends repository {
00030 
00037     public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array()) {
00038         $this->start =1;
00039         $this->max = 27;
00040         $this->sort = optional_param('youtube_sort', 'relevance', PARAM_TEXT);
00041         parent::__construct($repositoryid, $context, $options);
00042     }
00043 
00044     public function check_login() {
00045         return !empty($this->keyword);
00046     }
00047 
00053     public function search($search_text) {
00054         $this->keyword = $search_text;
00055         $ret  = array();
00056         $ret['nologin'] = true;
00057         $ret['list'] = $this->_get_collection($search_text, $this->start, $this->max, $this->sort);
00058         return $ret;
00059     }
00060 
00069     private function _get_collection($keyword, $start, $max, $sort) {
00070         $list = array();
00071         $this->feed_url = 'http://gdata.youtube.com/feeds/api/videos?q=' . urlencode($keyword) . '&format=5&start-index=' . $start . '&max-results=' .$max . '&orderby=' . $sort;
00072         $c = new curl(array('cache'=>true, 'module_cache'=>'repository'));
00073         $content = $c->get($this->feed_url);
00074         $xml = simplexml_load_string($content);
00075         $media = $xml->entry->children('http://search.yahoo.com/mrss/');
00076         $links = $xml->children('http://www.w3.org/2005/Atom');
00077         foreach ($xml->entry as $entry) {
00078             $media = $entry->children('http://search.yahoo.com/mrss/');
00079             $title = $media->group->title;
00080             $attrs = $media->group->thumbnail[2]->attributes();
00081             $thumbnail = $attrs['url'];
00082             $arr = explode('/', $entry->id);
00083             $id = $arr[count($arr)-1];
00084             $source = 'http://www.youtube.com/v/' . $id . '#' . $title;
00085             $list[] = array(
00086                 'title'=>(string)$title,
00087                 'thumbnail'=>(string)$attrs['url'],
00088                 'thumbnail_width'=>150,
00089                 'thumbnail_height'=>120,
00090                 'size'=>'',
00091                 'date'=>'',
00092                 'source'=>$source
00093             );
00094         }
00095         return $list;
00096     }
00097 
00101     public function global_search() {
00102         return false;
00103     }
00104 
00105     public function get_listing($path='', $page = '') {
00106         return array();
00107     }
00108 
00112     public function print_login($ajax = true) {
00113         $ret = array();
00114         $search = new stdClass();
00115         $search->type = 'text';
00116         $search->id   = 'youtube_search';
00117         $search->name = 's';
00118         $search->label = get_string('search', 'repository_youtube').': ';
00119         $sort = new stdClass();
00120         $sort->type = 'select';
00121         $sort->options = array(
00122             (object)array(
00123                 'value' => 'relevance',
00124                 'label' => get_string('sortrelevance', 'repository_youtube')
00125             ),
00126             (object)array(
00127                 'value' => 'published',
00128                 'label' => get_string('sortpublished', 'repository_youtube')
00129             ),
00130             (object)array(
00131                 'value' => 'rating',
00132                 'label' => get_string('sortrating', 'repository_youtube')
00133             ),
00134             (object)array(
00135                 'value' => 'viewCount',
00136                 'label' => get_string('sortviewcount', 'repository_youtube')
00137             )
00138         );
00139         $sort->id = 'youtube_sort';
00140         $sort->name = 'youtube_sort';
00141         $sort->label = get_string('sortby', 'repository_youtube').': ';
00142         $ret['login'] = array($search, $sort);
00143         $ret['login_btn_label'] = get_string('search');
00144         $ret['login_btn_action'] = 'search';
00145         return $ret;
00146     }
00147 
00152     public function supported_filetypes() {
00153         return array('web_video');
00154     }
00155 
00160     public function supported_returntypes() {
00161         return FILE_EXTERNAL;
00162     }
00163 }
 All Data Structures Namespaces Files Functions Variables Enumerations