From 009a97ce00db4fe0e524aa337fc1f5f2d848153d Mon Sep 17 00:00:00 2001 From: dongsheng Date: Fri, 19 Jun 2009 07:22:37 +0000 Subject: [PATCH] "MDL-17316, improve non-js filepicker" --- repository/boxnet/repository.class.php | 1 + repository/filepicker.php | 108 +++++++----------- repository/flickr/repository.class.php | 10 +- repository/flickr_public/repository.class.php | 18 +-- 4 files changed, 53 insertions(+), 84 deletions(-) diff --git a/repository/boxnet/repository.class.php b/repository/boxnet/repository.class.php index c718dda493..953c0b0c1c 100755 --- a/repository/boxnet/repository.class.php +++ b/repository/boxnet/repository.class.php @@ -216,6 +216,7 @@ class repository_boxnet extends repository { echo ''; echo ''; echo ''; + echo ''; } } diff --git a/repository/filepicker.php b/repository/filepicker.php index 9edfb39cd6..47379d8918 100755 --- a/repository/filepicker.php +++ b/repository/filepicker.php @@ -32,37 +32,35 @@ $itemid = optional_param('itemid', '', PARAM_INT); $icon = optional_param('icon', '', PARAM_RAW); $action = optional_param('action', '', PARAM_ALPHA); $ctx_id = optional_param('ctx_id', SITEID, PARAM_INT); // context ID -$repo_id = optional_param('repo_id', 1, PARAM_INT); // repository ID +$repo_id = optional_param('repo_id', 0, PARAM_INT); // repository ID $req_path = optional_param('p', '', PARAM_RAW); // path +$page = optional_param('page', '', PARAM_RAW); $callback = optional_param('callback', '', PARAM_CLEANHTML); $search_text = optional_param('s', '', PARAM_CLEANHTML); // init repository plugin $sql = 'SELECT i.name, i.typeid, r.type FROM {repository} r, {repository_instances} i '. 'WHERE i.id=? AND i.typeid=r.id'; -if (!$repository = $DB->get_record_sql($sql, array($repo_id))) { - print_error('invalidrepositoryid', 'repository'); -} else { +if ($repository = $DB->get_record_sql($sql, array($repo_id))) { $type = $repository->type; -} -$url = $CFG->httpswwwroot."/repository/filepicker.php?ctx_id=$ctx_id&itemid=$itemid"; - -if (file_exists($CFG->dirroot.'/repository/'.$type.'/repository.class.php')) { - require_once($CFG->dirroot.'/repository/'.$type.'/repository.class.php'); - $classname = 'repository_' . $type; - try { - $repo = new $classname($repo_id, $ctx_id, array('ajax'=>false, 'name'=>$repository->name, 'client_id'=>$client_id)); - } catch (repository_exception $e){ - print_error('pluginerror', 'repository'); + if (file_exists($CFG->dirroot.'/repository/'.$type.'/repository.class.php')) { + require_once($CFG->dirroot.'/repository/'.$type.'/repository.class.php'); + $classname = 'repository_' . $type; + try { + $repo = new $classname($repo_id, $ctx_id, array('ajax'=>false, 'name'=>$repository->name, 'client_id'=>$client_id)); + } catch (repository_exception $e){ + print_error('pluginerror', 'repository'); + } + } else { + print_error('invalidplugin', 'repository'); } -} else { - print_error('invalidplugin', 'repository'); } -//$context = get_context_instance_by_id($ctx_id); -//$PAGE->set_course($context); +$url = $CFG->httpswwwroot."/repository/filepicker.php?ctx_id=$ctx_id&itemid=$itemid"; +$home_url = $url.'&action=embedded'; switch ($action) { case 'upload': + // The uploaded file has been processed in plugin construct function redirect($url, get_string('uploadsucc','repository')); break; case 'deletedraft': @@ -73,7 +71,7 @@ case 'deletedraft': $fs = get_file_storage(); if ($file = $fs->get_file($contextid, 'user_draft', $itemid, '/', $title)) { if($result = $file->delete()) { - header("Location: $CFG->httpswwwroot/repository/filepicker.php?action=embedded&itemid=$itemid&ctx_id=$ctx_id"); + header("Location: {$home_url}"); } else { print_error('cannotdelete', 'repository'); } @@ -81,10 +79,16 @@ case 'deletedraft': exit; break; case 'search': + echo "
".get_string('back', 'repository')."
"; try { $search_result = $repo->search($search_text); $search_result['search_result'] = true; $search_result['repo_id'] = $repo_id; + + // TODO: need a better solution + print_paging_bar($search_result['total'], $search_result['page']-1, + $search_result['perpage'], "{$url}&action=list&repo_id={$repo_id}&"); + echo ''; foreach ($search_result['list'] as $item) { echo ''; @@ -97,24 +101,15 @@ case 'search': } echo ''; echo ''; - echo ''; - echo ''; + echo ''; } echo '
'; - if (!isset($item['children'])) { - echo '
'; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo '
'; - } else { - echo '
'; - echo ''; - echo ''; - echo '
'; - } - echo '
'; + echo '
'; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo '
'; echo '
'; } catch (repository_exception $e) { @@ -123,9 +118,9 @@ case 'search': case 'list': case 'sign': print_header(); - echo "
".get_string('back', 'repository')."
"; + echo "
".get_string('back', 'repository')."
"; if ($repo->check_login()) { - $list = $repo->get_listing($req_path); + $list = $repo->get_listing($req_path, $page); $dynload = !empty($list['dynload'])?true:false; if (!empty($list['upload'])) { echo '
'; @@ -146,6 +141,13 @@ case 'sign': echo ' / '; } } + if (!empty($list['page'])) { + // TODO: need a better solution + print_paging_bar($list['total'], $list['page']-1, + $list['perpage'], $CFG->httpswwwroot + .'/repository/filepicker.php?action=list&itemid=' + .$itemid.'&ctx_id='.$ctx_id.'&repo_id='.$repo_id.'&', 'page', false, false, 1); + } echo ''; foreach ($list['list'] as $item) { echo ''; @@ -173,9 +175,7 @@ case 'sign': echo ''; } echo ''; - echo ''; - echo ''; + echo ''; } echo '
'; - echo '
'; } @@ -190,33 +190,13 @@ case 'sign': break; case 'download': $filepath = $repo->get_file($file, $title, $itemid); - if (preg_match('#(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)#', $filepath)) { - // youtube plugin return a url instead a file path - $url = $filepath; - echo json_encode(array( - /* File picker need to know this is a link - * in order to attach title to url - */ - 'type'=>'link', - 'client_id'=>$client_id, - 'url'=>$url, - 'id'=>$url, - 'file'=>$url - ) - ); - } else if (is_array($filepath)) { - // file api don't have real file path, so we need more file api specific info for "local" plugin - $fileinfo = $filepath; - $info = array(); - $info['file'] = $fileinfo['title']; - $info['id'] = $itemid; - $info['url'] = $CFG->httpswwwroot.'/draftfile.php/'.$fileinfo['contextid'].'/user_draft/'.$itemid.'/'.$fileinfo['title']; - echo json_encode($info); - } else { + if (!empty($filepath)) { // normal file path name $info = repository::move_to_filepool($filepath, $title, $itemid); //echo json_encode($info); redirect($url, get_string('downloadsucc','repository')); + } else { + print_error('cannotdownload', 'repository'); } break; diff --git a/repository/flickr/repository.class.php b/repository/flickr/repository.class.php index 24eecb957e..0a14a620b4 100755 --- a/repository/flickr/repository.class.php +++ b/repository/flickr/repository.class.php @@ -149,6 +149,8 @@ class repository_flickr extends repository { $ret['manage'] = $photos_url; $ret['list'] = array(); $ret['pages'] = $photos['pages']; + $ret['total'] = $photos['total']; + $ret['perpage'] = $photos['perpage']; if($page <= $ret['pages']) { $ret['page'] = $page; } else { @@ -212,14 +214,6 @@ class repository_flickr extends repository { return $this->build_list($photos, $page); } - /** - * - * @return - */ - public function print_listing() { - return false; - } - /** * * @global $CFG diff --git a/repository/flickr_public/repository.class.php b/repository/flickr_public/repository.class.php index d7ed8d334d..3eda509317 100644 --- a/repository/flickr_public/repository.class.php +++ b/repository/flickr_public/repository.class.php @@ -247,6 +247,8 @@ class repository_flickr_public extends repository { } } $ret = array(); + $ret['total'] = $photos['total']; + $ret['perpage'] = $photos['perpage']; if (empty($photos)) { $ret['list'] = array(); return $ret; @@ -312,14 +314,6 @@ class repository_flickr_public extends repository { return $ret; } - /** - * - * @return - */ - public function print_listing() { - return false; - } - /** * * @return @@ -336,10 +330,10 @@ class repository_flickr_public extends repository { /** * - * @global $CFG - * @param $photo_id - * @param $file - * @return + * @global object $CFG + * @param string $photo_id + * @param string $file + * @return string */ public function get_file($photo_id, $file = '') { global $CFG; -- 2.39.5