From 4ded0afd169877be434832fbbd51d74d1b8521d2 Mon Sep 17 00:00:00 2001 From: Dongsheng Cai Date: Mon, 19 Sep 2011 11:53:42 +0800 Subject: [PATCH] MDL-28509 repository : fixed youtube repository search keyword --- repository/youtube/lib.php | 50 ++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/repository/youtube/lib.php b/repository/youtube/lib.php index 30a5f076bbd..cb0020443cf 100644 --- a/repository/youtube/lib.php +++ b/repository/youtube/lib.php @@ -27,11 +27,17 @@ */ class repository_youtube extends repository { + + /** + * Youtube plugin constructor + * @param int $repositoryid + * @param object $context + * @param array $options + */ public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array()) { - $this->keyword = optional_param('youtube_keyword', '', PARAM_RAW); $this->start =1; $this->max = 27; - $this->sort = optional_param('youtube_sort', '', PARAM_TEXT); + $this->sort = optional_param('youtube_sort', 'relevance', PARAM_TEXT); parent::__construct($repositoryid, $context, $options); } @@ -39,13 +45,27 @@ class repository_youtube extends repository { return !empty($this->keyword); } + /** + * Return search results + * @param string $search_text + * @return array + */ public function search($search_text) { + $this->keyword = $search_text; $ret = array(); $ret['nologin'] = true; - $ret['list'] = $this->_get_collection($this->keyword, $this->start, $this->max, $this->sort); + $ret['list'] = $this->_get_collection($search_text, $this->start, $this->max, $this->sort); return $ret; } + /** + * Private method to get youtube search results + * @param string $keyword + * @param int $start + * @param int $max max results + * @param string $sort + * @return array + */ private function _get_collection($keyword, $start, $max, $sort) { $list = array(); $this->feed_url = 'http://gdata.youtube.com/feeds/api/videos?q=' . urlencode($keyword) . '&format=5&start-index=' . $start . '&max-results=' .$max . '&orderby=' . $sort; @@ -75,22 +95,26 @@ class repository_youtube extends repository { return $list; } + /** + * Youtube plugin doesn't support global search + */ public function global_search() { return false; } + public function get_listing($path='', $page = '') { - $ret = array(); - $ret['nologin'] = true; - $ret['list'] = $this->_get_collection($this->keyword, $this->start, $this->max, $this->sort); - return $ret; + return array(); } + /** + * Generate search form + */ public function print_login($ajax = true) { $ret = array(); $search = new stdClass(); $search->type = 'text'; $search->id = 'youtube_search'; - $search->name = 'youtube_keyword'; + $search->name = 's'; $search->label = get_string('search', 'repository_youtube').': '; $sort = new stdClass(); $sort->type = 'select'; @@ -120,9 +144,19 @@ class repository_youtube extends repository { $ret['login_btn_action'] = 'search'; return $ret; } + + /** + * file types supported by youtube plugin + * @return array + */ public function supported_filetypes() { return array('web_video'); } + + /** + * Youtube plugin only return external links + * @return int + */ public function supported_returntypes() { return FILE_EXTERNAL; }