Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/repository/dropbox/locallib.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00031 require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
00032 require_once($CFG->libdir.'/oauthlib.php');
00033 
00034 class dropbox extends oauth_helper {
00036     private $mode = 'dropbox';
00038     private $dropbox_api = 'https://api.dropbox.com/1';
00040     private $dropbox_content_api = 'https://api-content.dropbox.com/1';
00041 
00042     function __construct($args) {
00043         parent::__construct($args);
00044     }
00048     public function get_listing($path='/', $token='', $secret='') {
00049         $url = $this->dropbox_api.'/metadata/'.$this->mode.$path;
00050         $content = $this->get($url, array(), $token, $secret);
00051         $data = json_decode($content);
00052         return $data;
00053     }
00054 
00058     public function get_file($filepath, $saveas) {
00059         $info = pathinfo($filepath);
00060         $dirname = $info['dirname'];
00061         $basename = $info['basename'];
00062         $filepath = $dirname . rawurlencode($basename);
00063         if ($dirname != '/') {
00064             $filepath = $dirname . '/' . $basename;
00065             $filepath = str_replace("%2F", "/", rawurlencode($filepath));
00066         }
00067 
00068         $url = $this->dropbox_content_api.'/files/'.$this->mode.$filepath;
00069         $content = $this->get($url, array());
00070         file_put_contents($saveas, $content);
00071         return array('path'=>$saveas, 'url'=>$url);
00072     }
00073 
00074     public function set_mode($mode) {
00075         $this->mode = $mode;
00076     }
00077 }
 All Data Structures Namespaces Files Functions Variables Enumerations