Simple status box for the sidebar.
[elgg_plugins.git] / amazons3 / lib.php
blob8fada5ced27efc8eb3f974e719cd9e19cee8c9bf
1 <?php
3 global $CFG;
5 function amazons3_pagesetup() {
8 function amazons3_init() {
12 Fill in your bucket name to use S3!
14 Also remember to fill in your key and secret key in s3.class.php.
17 if (empty($CFG->files->amazons3->bucket)) {
18 $CFG->files->amazons3->bucket = "";
22 global $CFG;
23 $CFG->files->default_handler = "amazons3";
24 $CFG->files->handler["amazons3"] = "amazons3_passthru";
26 if (empty($CFG->files->siteid)) {
27 $CFG->files->siteid = $CFG->dbuser;
29 listen_for_event("file","create","amazons3_create");
30 listen_for_event("file","delete","amazons3_delete");
33 function amazons3_upload($originalname, $filePath, $bucket = NULL) {
34 global $CFG;
35 if ($bucket == NULL) {
36 $bucket = $CFG->files->amazons3->bucket;
38 require_once("s3.class.php");
39 $s3transfer = new s3();
40 $result = $s3transfer->getObjects($bucket);
41 if (substr_count($result,"The specified bucket does not exist")) {
42 $s3transfer->putBucket($bucket);
44 if ($data = file_get_contents($filePath)) {
45 $output = $s3transfer->putObject($originalname, $data, $bucket);
46 header("content-type: ".$s3transfer->getResponseContentType());
50 function amazons3_passthru($filename, $bucket = NULL) {
51 global $CFG;
53 $filename = $CFG->files->siteid . "/" . str_replace($CFG->dataroot, "", $filename);
55 if ($bucket == NULL) {
56 $bucket = $CFG->files->amazons3->bucket;
59 require_once($CFG->dirroot . 'lib/filelib.php');
60 $mimetype = mimeinfo('type',$filename);
61 require_once("s3.class.php");
62 $s3transfer = new s3();
63 $metadata = $s3transfer->getObjectInfo($filename, $bucket, NULL, $mimetype);
64 $mimetype = mimeinfo('type',$filename);
65 // header("Content-type: ".$mimetype);
66 return $s3transfer->getObject($filename,$bucket);
69 function amazons3_create($object_type, $event, $object) {
70 global $CFG;
71 amazons3_upload($CFG->files->siteid . "/" . $object->location, $CFG->dataroot . $object->location);
72 @unlink($CFG->dataroot . $object->location);
73 $object->handler = "amazons3";
74 return $object;
77 function amazons3_delete($object_type, $event, $object) {
78 global $CFG;
79 require_once("s3.class.php");
80 $s3transfer = new s3();
81 $s3transfer->deleteObject($CFG->files->siteid . "/" . $object->location, $CFG->files->amazons3->bucket);
82 return $object;