mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-28509 repository : fixed youtube repository search keyword
This commit is contained in:
parent
79ba96f75c
commit
4a54e75848
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user