From d1bfc05ed7401721f4bfdda74a955181fce7e409 Mon Sep 17 00:00:00 2001 From: dongsheng Date: Thu, 25 Jun 2009 04:12:43 +0000 Subject: [PATCH] "MDL-13766, improve search form in file picker, improve error handing" --- repository/flickr_public/repository.class.php | 22 +++++++++++-- repository/lib.php | 3 +- repository/local/repository.class.php | 1 + repository/picasa/repository.class.php | 1 + repository/repository.css | 5 ++- repository/repository.src.js | 31 ++++++++++--------- repository/ws.php | 9 ++++-- 7 files changed, 50 insertions(+), 22 deletions(-) diff --git a/repository/flickr_public/repository.class.php b/repository/flickr_public/repository.class.php index 8aeb95d05c..468535e0c3 100644 --- a/repository/flickr_public/repository.class.php +++ b/repository/flickr_public/repository.class.php @@ -208,6 +208,7 @@ class repository_flickr_public extends repository { */ public function search($search_text) { global $SESSION; + $ret = array(); if (!empty($this->flickr_account)) { $people = $this->flickr->people_findByEmail($this->flickr_account); $this->nsid = $people['nsid']; @@ -218,6 +219,11 @@ class repository_flickr_public extends repository { } if (empty($this->nsid)) { $this->nsid = null; + // user specify a flickr account, but it is not valid + if (!empty($this->flickr_account) or !empty($SESSION->{$this->sess_account})) { + $ret['e'] = get_string('invalidemail', 'repository_flickr_public'); + return $ret; + } } $is_paging = optional_param('search_paging', '', PARAM_RAW); if (!empty($is_paging)) { @@ -270,7 +276,6 @@ class repository_flickr_public extends repository { ) ); } - $ret = array(); $ret['total'] = $photos['total']; $ret['perpage'] = $photos['perpage']; if (empty($photos)) { @@ -326,8 +331,10 @@ class repository_flickr_public extends repository { $format = 'jpg'; } $format = '.'.$format; - // append extensions to the files if (substr($p['title'], strlen($p['title'])-strlen($format)) != $format) { + // append author id + $p['title'] .= '-'.$p['owner']; + // append file extension $p['title'] .= $format; } $ret['list'][] = array('title'=>$p['title'], 'source'=>$p['id'], @@ -375,6 +382,10 @@ class repository_flickr_public extends repository { $c = new curl; $c->download(array(array('url'=>$url, 'file'=>$fp))); + $watermark = get_config('flickr_public', 'watermark'); + if (!empty($watermark)) { + // process watermark + } return $path; } @@ -405,8 +416,13 @@ class repository_flickr_public extends repository { $api_key = ''; } $strrequired = get_string('required'); + + $mform->addElement('checkbox', 'watermark', get_string('watermark', 'repository_flickr_public')); + $mform->addElement('text', 'api_key', get_string('apikey', 'repository_flickr_public'), array('value'=>$api_key,'size' => '40')); $mform->addRule('api_key', $strrequired, 'required', null, 'client'); + + $mform->addElement('static', null, '', get_string('information','repository_flickr_public')); } @@ -415,7 +431,7 @@ class repository_flickr_public extends repository { * @return */ public static function get_type_option_names() { - return array('api_key'); + return array('api_key', 'watermark'); } /** diff --git a/repository/lib.php b/repository/lib.php index c0fc1f93c8..350941fb92 100644 --- a/repository/lib.php +++ b/repository/lib.php @@ -1482,7 +1482,7 @@ abstract class repository { * Show the search screen, if required * @return null */ - public function print_search() { + public function print_search($client_id) { $str = ''; $str .= ''; $str .= ''; @@ -1783,6 +1783,7 @@ function repository_get_client($context, $id = '', $accepted_filetypes = '*', $ $lang['download'] = get_string('downloadsucc', 'repository'); $lang['date'] = get_string('date', 'repository').': '; $lang['error'] = get_string('error', 'repository'); + $lang['emptylist'] = get_string('emptylist', 'repository'); $lang['filenotnull'] = get_string('filenotnull', 'repository'); $lang['federatedsearch'] = get_string('federatedsearch', 'repository'); $lang['help'] = get_string('help'); diff --git a/repository/local/repository.class.php b/repository/local/repository.class.php index d94b03dfa2..5461647c9b 100755 --- a/repository/local/repository.class.php +++ b/repository/local/repository.class.php @@ -49,6 +49,7 @@ class repository_local extends repository { global $CFG, $USER; $ret = array(); $ret['dynload'] = true; + $ret['nosearch'] = true; $list = array(); // list draft files diff --git a/repository/picasa/repository.class.php b/repository/picasa/repository.class.php index c325e41707..629b820f9c 100644 --- a/repository/picasa/repository.class.php +++ b/repository/picasa/repository.class.php @@ -22,6 +22,7 @@ class repository_picasa extends repository { $gauth = new google_authsub(false, $googletoken); // will throw exception if fails google_picasa::set_sesskey($gauth->get_sessiontoken(), $USER->id); } + $this->check_login(); } public function check_login() { diff --git a/repository/repository.css b/repository/repository.css index 71a4c20ef2..75146effcf 100644 --- a/repository/repository.css +++ b/repository/repository.css @@ -66,8 +66,11 @@ .fp-grid p{margin:0;padding:0;background: #FFFFCC} .fp-grid .label{height:48px;text-align:center} .fp-grid span{color:gray} +.fp-error {padding: 2em 0; margin: 3em 5px;text-align:center;background: #FFBBBB} +/* file picker search dialog */ +div.bd{text-align:left} /* TODO: Fix IE6 somehow .yui-skin-sam .yui-panel .hd{} -*/ \ No newline at end of file +*/ diff --git a/repository/repository.src.js b/repository/repository.src.js index ea55965f6c..d802a5b7a2 100644 --- a/repository/repository.src.js +++ b/repository/repository.src.js @@ -263,7 +263,7 @@ repository_client.req_cb = { repo.viewbar.set('disabled', false); var panel = new YAHOO.util.Element('panel-'+data.client_id); if(data && data.e) { - panel.get('element').innerHTML = data.e; + panel.get('element').innerHTML = '
'+data.e+'
'; return; } // save data @@ -339,7 +339,7 @@ repository_client.print_login = function(id, data) { field_id = ' id="'+login[k].id+'"'; } if (login[k].label) { - str += ''+login[k].label+' '; + str += ''+login[k].label+' '; } else { str += ''; } @@ -834,6 +834,9 @@ repository_client.view_as_icons = function(client_id, data) { } count++; } + if (list.length == 0) { + panel.innerHTML = '
'+fp_lang.emptylist+'
'; + } container.appendChild(panel); repository_client.print_footer(client_id); } @@ -1099,23 +1102,23 @@ success: function(o) { var fp = repository_client.fp[data.client_id]; if(el) { el.innerHTML = ''; - } else { - var el = document.createElement('DIV'); - el.id = 'fp-search-dlg'; + el.parentNode.removeChild(el); } - var div1 = document.createElement('DIV'); - div1.className = 'hd'; - div1.innerHTML = fp_lang.searching+"\"" + repository_listing[data.client_id][fp.fs.repo_id].name + '"'; - var div2 = document.createElement('DIV'); - div2.className = 'bd'; + var el = document.createElement('DIV'); + el.id = 'fp-search-dlg'; + var dlg_title = document.createElement('DIV'); + dlg_title.className = 'hd'; + dlg_title.innerHTML = fp_lang.searching+"\"" + repository_listing[data.client_id][fp.fs.repo_id].name + '"'; + var dlg_body = document.createElement('DIV'); + dlg_body.className = 'bd'; var sform = document.createElement('FORM'); sform.method = 'POST'; sform.id = "fp-search-form"; sform.action = moodle_cfg.wwwroot+'/repository/ws.php?action=search'; sform.innerHTML = data['form']; - div2.appendChild(sform); - el.appendChild(div1); - el.appendChild(div2); + dlg_body.appendChild(sform); + el.appendChild(dlg_title); + el.appendChild(dlg_body); document.body.appendChild(el); var dlg_handler = function() { var client_id=dlg_handler.client_id; @@ -1144,7 +1147,7 @@ success: function(o) { handler: dlg_handler, isDefault:true }, - {text:fp_lang.cancel,handler:function(){this.cancel()}} + {text:fp_lang.cancel,handler:function(){this.destroy()}} ] }); dlg.render(); diff --git a/repository/ws.php b/repository/ws.php index 37198f4d94..f711bc8d24 100644 --- a/repository/ws.php +++ b/repository/ws.php @@ -5,6 +5,7 @@ require_once('../config.php'); require_once('../lib/filelib.php'); require_once('lib.php'); + require_login(); /// Parameters $page = optional_param('page', '', PARAM_RAW); // page @@ -120,6 +121,8 @@ // If Moodle is working on HTTPS mode, then we are not allowed to access // parent window, in this case, we need to alert user to refresh the repository // manually. + $strhttpsbug = get_string('cannotaccessparentwin', 'repository'); + $strrefreshnonjs = get_string('refreshnonjsfilepicker', 'repository'); $js =<< @@ -178,7 +181,7 @@ EOD; echo json_encode($logout); break; case 'searchform': - $search_form['form'] = $repo->print_search(); + $search_form['form'] = $repo->print_search($client_id); $search_form['client_id'] = $client_id; echo json_encode($search_form); break; -- 2.39.5