Permalink
Browse files

Merge branch 's13_MDL-28509_youtube_master' of github.com:dongsheng/m…

…oodle
  • Loading branch information...
nebgor committed Sep 19, 2011
2 parents 668dae6 + 4a54e75 commit 9fee890b578240a4e7703638ee64972c27dcd607
Showing with 71 additions and 9 deletions.
  1. +5 −0 repository/youtube/lang/en/repository_youtube.php
  2. +66 −9 repository/youtube/lib.php
@@ -27,3 +27,8 @@
$string['search'] = 'Search videos';
$string['youtube:view'] = 'Use youtube in file picker';
$string['configplugin'] = 'YouTube repository type configuration';
+$string['sortby'] = 'Sort By';
+$string['sortpublished'] = 'Date Published';
+$string['sortrating'] = 'Rating';
+$string['sortrelevance'] = 'Relevance';
+$string['sortviewcount'] = 'View Count';
View
@@ -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 = 'published';
+ $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,31 +95,68 @@ 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').': ';
- $ret['login'] = array($search);
+ $sort = new stdClass();
+ $sort->type = 'select';
+ $sort->options = array(
+ (object)array(
+ 'value' => 'relevance',
+ 'label' => get_string('sortrelevance', 'repository_youtube')
+ ),
+ (object)array(
+ 'value' => 'published',
+ 'label' => get_string('sortpublished', 'repository_youtube')
+ ),
+ (object)array(
+ 'value' => 'rating',
+ 'label' => get_string('sortrating', 'repository_youtube')
+ ),
+ (object)array(
+ 'value' => 'viewCount',
+ 'label' => get_string('sortviewcount', 'repository_youtube')
+ )
+ );
+ $sort->id = 'youtube_sort';
+ $sort->name = 'youtube_sort';
+ $sort->label = get_string('sortby', 'repository_youtube').': ';
+ $ret['login'] = array($search, $sort);
$ret['login_btn_label'] = get_string('search');
$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 9fee890

Please sign in to comment.