]> git.mjollnir.org Git - moodle.git/commitdiff
"MDL-17316, non-js file picker added"
authordongsheng <dongsheng>
Mon, 8 Jun 2009 06:25:53 +0000 (06:25 +0000)
committerdongsheng <dongsheng>
Mon, 8 Jun 2009 06:25:53 +0000 (06:25 +0000)
lang/en_utf8/repository.php
lib/form/filemanager.php
repository/alfresco/repository.class.php
repository/filepicker.php [new file with mode: 0755]

index 62a4c0213b9e85a406c628e6500f365647a180b7..eae8f43e63b600122655dfe6975225fefd22a40d 100644 (file)
@@ -1,4 +1,5 @@
 <?php //$Id$
+$string['accessiblefilepicker']='Accessible file picker';
 $string['activerepository'] = 'Active repository plugins';
 $string['add'] = 'Add';
 $string['addplugin'] = 'Add a repository plugin';
index 2c72feee7130e3266a709a041e36451468f9c085..7a9603ff570f54e781ae51ec56801f52c094c862 100644 (file)
@@ -165,6 +165,7 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
         $repo_info = repository_get_client($context, $client_id, $this->_options['filetypes'], $this->_options['returnvalue']);
 
         $html = $this->_get_draftfiles($draftitemid, $client_id);
+        $accessiblefp = get_string('accessiblefilepicker', 'repository');
 
         $str = $this->_getTabs();
         $str .= $html;
@@ -174,6 +175,7 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
 <input value="$draftitemid" name="{$this->_attributes['name']}" type="hidden" />
 <div>
     <input value="$straddfile" onclick="callpicker('$id', '$client_id', '$draftitemid')" type="button" />
+    <a href="{$CFG->httpswwwroot}/repository/filepicker.php?ctx_id={$context->id}&&itemid=$draftitemid" target="_blank">$accessiblefp</a>
 </div>
 EOD;
         if (empty($CFG->filemanagerjsloaded)) {
index 5df7f6d58f6de34dc2c9c85a7450027430e2de2b..cc3d9d512f208115a27fbd6ac091f10b7895c0cb 100755 (executable)
@@ -60,6 +60,14 @@ class repository_alfresco extends repository {
             $ret = array();
             $ret['login'] = array($user_field, $passwd_field);
             return $ret;
+        } else {
+            echo '<table>';
+            echo '<tr><td><label>'.get_string('username', 'repository_alfresco').'</label></td>';
+            echo '<td><input type="text" name="al_username" /></td></tr>';
+            echo '<tr><td><label>'.get_string('password', 'repository_alfresco').'</label></td>';
+            echo '<td><input type="password" name="al_password" /></td></tr>';
+            echo '</table>';
+            echo '<input type="submit" value="Enter" />';
         }
     }
 
diff --git a/repository/filepicker.php b/repository/filepicker.php
new file mode 100755 (executable)
index 0000000..d8cb435
--- /dev/null
@@ -0,0 +1,191 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+require_once('../config.php');
+require_once($CFG->libdir.'/filelib.php');
+require_once('lib.php');
+
+$page        = optional_param('page', '',          PARAM_RAW);    // page
+$client_id   = optional_param('client_id', SITEID, PARAM_RAW);    // client ID
+$env         = optional_param('env', 'filepicker', PARAM_ALPHA);  // opened in editor or moodleform
+$file        = optional_param('file', '',          PARAM_RAW);    // file to download
+$title       = optional_param('title', '',         PARAM_FILE);   // new file name
+$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
+$req_path    = optional_param('p', '',             PARAM_RAW);          // path
+$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))) {
+    $err->e = get_string('invalidrepositoryid', 'repository');
+    die(json_encode($err));
+} else {
+    $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){
+        $err->e = $e->getMessage();
+        die(json_encode($err));
+    }
+} else {
+    $err->e = get_string('invalidplugin', 'repository', $type);
+    die(json_encode($err));
+}
+
+if ($action == '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 {
+        // normal file path name
+        $info = repository::move_to_filepool($filepath, $title, $itemid);
+        //echo json_encode($info);
+        redirect($url, get_string('downloadsucc','repository'));
+    }
+    echo $filepath;
+} else if ($action == 'confirm') {
+    print_header(get_string('download', 'repository'), get_string('download', 'repository'));
+    echo '<img src="'.$icon.'" />';
+    echo '<form method="post"><table>';
+    echo '<tr>';
+    echo '<td><label>'.get_string('filename', 'repository').'</label></td>';
+    echo '<td><input type="text" name="title" value="'.$title.'" /></td>';
+    echo '<td><input type="hidden" name="file" value="'.$file.'" /></td>';
+    echo '<td><input type="hidden" name="action" value="download" /></td>';
+    echo '<td><input type="hidden" name="itemid" value="'.$itemid.'" /></td>';
+    echo '</tr>';
+    echo '</table>';
+    echo '<div>';
+    echo '<input type="submit" value="'.get_string('download', 'repository').'" />';
+    echo '</div>';
+    echo '</form>';
+    print_footer('empty');
+
+} else if ($action == 'list' or $action == 'sign') {
+    $navlinks = array();
+    $navlinks[] = array('name' => 'filepicker', 'link' => $url, 'type' => 'activityinstance');
+    $navlinks[] = array('name' => $repo->get_name());
+
+    $navigation = build_navigation($navlinks);
+    print_header(get_string('accessiblefilepicker', 'repository'), get_string('accessiblefilepicker', 'repository'), $navigation);
+    if ($repo->check_login()) {
+        $list = $repo->get_listing($req_path);
+        $dynload = !empty($list['dynload'])?true:false;
+        if (!empty($list['upload'])) {
+            echo '<form method="post" style="display:inline">';
+            echo '<label>'.$list['upload']['label'].'</label>';
+            echo '<input type="file" name="repo_upload_file" /><br />';
+            echo '<input type="submit" value="Upload" />';
+            echo '</form>';
+        } else {
+            foreach ($list['path'] as $p) {
+                echo '<form method="post" style="display:inline">';
+                echo '<input type="hidden" name="p" value="'.$p['path'].'"';
+                echo '<input type="hidden" name="action" value="list"';
+                echo '<input type="submit" value="'.$p['name'].'" />';
+                echo '</form>';
+                echo ' <strong>/</strong> ';
+            }
+            echo '<table>';
+            foreach ($list['list'] as $item) {
+                echo '<tr>';
+                echo '<td><img src="'.$item['thumbnail'].'" />';
+                echo '</td><td>';
+                if (!empty($item['url'])) {
+                    echo '<a href="'.$item['url'].'" target="_blank">'.$item['title'].'</a>';
+                } else {
+                    echo $item['title'];
+                }
+                echo '</td>';
+                echo '<td>';
+                if (!isset($item['children'])) {
+                    echo '<form method="post">';
+                    echo '<input type="hidden" name="file" value="'.$item['source'].'"/>';
+                    echo '<input type="hidden" name="action" value="confirm"/>';
+                    echo '<input type="hidden" name="title" value="'.$item['title'].'"/>';
+                    echo '<input type="hidden" name="icon" value="'.$item['thumbnail'].'"/>';
+                    echo '<input type="submit" value="Download" />';
+                    echo '</form>';
+                } else {
+                    echo '<form method="post">';
+                    echo '<input type="hidden" name="p" value="'.$item['path'].'"/>';
+                    echo '<input type="submit" value="Enter" />';
+                    echo '</form>';
+                }
+                echo '</td>';
+                echo '<td width="100px" align="center">';
+                echo '</td>';
+                echo '</td></tr>';
+            }
+            echo '</table>';
+        }
+    } else {
+        echo '<form method="post">';
+        $repo->print_login();
+        echo '<input type="hidden" name="action" value="sign" />';
+        echo '<input type="hidden" name="repo_id" value="'.$repo_id.'" />';
+        echo '</form>';
+    }
+    print_footer('empty');
+} else {
+    $user_context = get_context_instance(CONTEXT_USER, $USER->id);
+    $repos = repository::get_instances(array($user_context, get_system_context()), null, true, null, '*', 'ref_id');
+    $navlinks = array();
+    $navlinks[] = array('name' => get_string('accessiblefilepicker', 'repository'), 'link' => $url, 'type' => 'activityinstance');
+    $navigation = build_navigation($navlinks);
+    print_header(get_string('accessiblefilepicker', 'repository'), get_string('accessiblefilepicker', 'repository'), $navigation);
+    echo '<div><ul>';
+    foreach($repos as $repo) {
+        $info = $repo->get_meta();
+        echo '<li><img src="'.$info->icon.'" width="16px" height="16px"/> <a href="'.$url.'&action=list&repo_id='.$info->id.'">'.$info->name.'</a></li>';
+    }
+    echo '</ul></div>';
+    print_footer('empty');
+}
+