Permalink
Browse files

MDL-28509 repository : fixed youtube repository search keyword

  • Loading branch information...
1 parent c865e54 commit 54b3f856259d519b6939c50f7d68b871865daba1 @dcai dcai committed Sep 19, 2011
Showing with 42 additions and 8 deletions.
  1. +42 −8 repository/youtube/lib.php
@@ -27,25 +27,45 @@
*/
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);
}
public function check_login() {
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 @@ private function _get_collection($keyword, $start, $max, $sort) {
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 @@ public function print_login($ajax = true) {
$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;
}

0 comments on commit 54b3f85

Please sign in to comment.