-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodel.storage.php
More file actions
1030 lines (969 loc) · 26.5 KB
/
model.storage.php
File metadata and controls
1030 lines (969 loc) · 26.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
// ABSTRACT CLASS FOR TYPES OF STORAGE
abstract class Storage
{
private $store="";
private $debug=false;
private $kind="";
private $auth1="";
private $auth2="";
private $auth3="";
private $auth4="";
private $auth5="";
public $connected=false;
abstract protected function connect();
// Object Creation/Retrieval Functions
abstract protected function create_object($is_file,$bucket,$objname,$str,$mimetype);
abstract protected function download_object($bucket,$key_url,$target_local_filename);
abstract protected function get_object($bucket,$key_url);
abstract protected function get_object_filesize($bucket_name,$keyname);
// Addressing/Key/Container naming
abstract protected function bucket_syntax();
abstract protected function container_url($bucket);
abstract protected function key_url($bucket_name,$keyname);
// Functions used by all concrete Storage types
public function url_to_key($bucket,$key_url)
{
$keyname=substr($key_url,strlen($this->container_url($bucket))+1);
return $keyname;
}
public function connectcheck($failed)
{
if ($failed)
{
$this->connected=false;
if ($this->debug)
{
echo "Could not select file store named '".htmlspecialchars($this->kind)."'.";
}
return false;
}
else
{
$this->connected=true;
return true;
}
return false;
}
public function _format_bytes($a_bytes)
{
if ($a_bytes < 1024) {
return $a_bytes .' B';
} elseif ($a_bytes < 1048576) {
return round($a_bytes / 1024, 2) .' KiB';
} elseif ($a_bytes < 1073741824) {
return round($a_bytes / 1048576, 2) . ' MiB';
} elseif ($a_bytes < 1099511627776) {
return round($a_bytes / 1073741824, 2) . ' GiB';
} elseif ($a_bytes < 1125899906842624) {
return round($a_bytes / 1099511627776, 2) .' TiB';
} elseif ($a_bytes < 1152921504606846976) {
return round($a_bytes / 1125899906842624, 2) .' PiB';
} elseif ($a_bytes < 1180591620717411303424) {
return round($a_bytes / 1152921504606846976, 2) .' EiB';
} elseif ($a_bytes < 1208925819614629174706176) {
return round($a_bytes / 1180591620717411303424, 2) .' ZiB';
} else {
return round($a_bytes / 1208925819614629174706176, 2) .' YiB';
}
} // end function
} // end abstract class
// CONCRETE STORAGE TYPE: AWS
require_once("api/aws-sdk/sdk.class.php");
class Storage_AWS extends Storage
{
public $region="REGION_US_STANDARD";
function __construct()
{
}
function get_object_filesize($bucket_name,$keyname)
{
return $this->store->get_object_filesize($bucket_name,$keyname,true);
}
function connect()
{
$failed=false;
$s3 = new AmazonS3(array(
'key' => $this->auth1,
'secret' => $this->auth2
)) or $failed=true;
//$s3->disable_ssl_verification();
$this->store=$s3;
if ( strpos($this->region,"-")!==false )
{
$this->store->set_region( "s3-".$this->region.".amazonaws.com" );
}
else
{
$this->store->set_region( constant("AmazonS3::".$this->region) );
}
$this->store->enable_path_style ( true );
return $this->connectcheck($failed);
}
public function bucket_syntax()
{
return "bucket";
}
public function download_object($bucket_name,$keyname,$target_local_filename)
{
$file_resource = fopen($target_local_filename, 'w+');
$response = $this->store->get_object($bucket_name, $keyname, array(
'fileDownload' => $file_resource
));
}
public function key_url($bucket_name,$keyname)
{
$FILE_LOCATION="";
$base_url=$this->container_url($bucket_name);
if ($base_url!==false)
{
$base_url=$base_url."/".$keyname;
$FILE_LOCATION=$base_url;
}
return $FILE_LOCATION;
}
public function container_url($bucket)
{
if ( strpos($this->region,"-")!==false )
{
return "https://s3-".$this->region.".amazonaws.com"."/".$bucket;
}
else
{
return "https://".constant("AmazonS3::".$this->region)."/".$bucket;
}
// no slash on the end of string
}
public function create_object($is_file,$bucket,$objname,$str,$mimetype)
{
$this->store->enable_path_style ( true );
// AWS
if ($is_file)
{
clearstatcache();
if ( filesize($str) > 0)
{
$response = $this->store->create_mpu_object($bucket, $objname, array(
'fileUpload' => $str,
'partSize' => 40*MB,
'contentType' => $mimetype,
'acl' => AmazonS3::ACL_PUBLIC,
'storage' => AmazonS3::STORAGE_STANDARD
));
}
else
{
$response = $this->store->create_object($bucket,$objname,array(
'acl' => AmazonS3::ACL_PUBLIC,
)) or $failed=true;
} // end if (is an empty file or not)
}
else
{
if ( strlen($str)==0)
{
$response = $this->store->create_object($bucket,$objname,array(
'acl' => AmazonS3::ACL_PUBLIC,
)) or $failed=true;
}
else
{
$response=$this->store->create_object($bucket, $objname, array(
'body' => $str,
'contentType' => $mimetype,
'headers' => array(
'Content-Encoding'=>'UTF-8'
),
'acl' => AmazonS3::ACL_PUBLIC
)) or $failed=true;
} // end if (is blank string or not)
} // end if (is file or not)
return $response->isOK();
} // end function
public function get_object($bucket,$key_url)
{
$this->store->enable_path_style ( true );
$keyname=substr($key_url,strlen($this->container_url($bucket))+1);
$response = $this->store->get_object($bucket, $keyname);
if ( $response->isOK() )
{
return $response->body;
}
}
} // end class
// CONCRETE STORAGE TYPE: RACKSPACE
require_once("api/rcf-sdk/cloudfiles.php");
class Storage_Rackspace extends Storage
{
function __construct()
{
}
function get_object_filesize($bucket_name,$keyname)
{
$failed=false;
$keyname=substr($key_url,strlen($this->container_url($bucket))+1);
$cont = $this->store->get_container($bucket) or $failed=true;
if (!$failed)
{
$ret=$cont->get_object($keyname);
return $ret->bytes;
}
return -1;
}
function connect()
{
$failed=false;
try
{
$auth = new CF_Authentication($this->auth1,$this->auth2);
$auth->authenticate();
$conn = new CF_Connection($auth);// or $failed=true;
$this->store=$conn;
}
catch (Exception $e)
{
$failed=true;
}
return $this->connectcheck($failed);
}
public function bucket_syntax()
{
return "container";
}
public function key_url($bucket_name,$keyname)
{
$FILE_LOCATION="";
$base_url=$this->container_url($bucket_name);
if ($base_url!==false)
{
$base_url=$base_url."/".$keyname;
$FILE_LOCATION=$base_url;
}
return $FILE_LOCATION;
}
public function container_url($bucket)
{
// RACKSPACE
// Select container.
$cont = $this->store->get_container($bucket) or $failed=true;
if ($failed)
{
if ($this->debug)
{
echo "Unable to select file storage bucket '".htmlspecialchars($bucket)."'.";
}
return false;
}
if ($cont->cdn_enabled)
{
return $cont->cdn_uri;
}
else
{
if ($this->debug)
{
if ($this->debug)
{
echo "File storage bucket '".htmlspecialchars($bucket)."' needs to have CDN enabled.";
}
return false;
}
else
{
return false;
}
}
} // end function
public function create_object($is_file,$bucket,$objname,$str,$mimetype)
{
// RACKSPACE - send file
// Select container.
$cont = $this->store->get_container($bucket) or $failed=true;
if ($failed)
{
if ($this->debug)
{
echo "Unable to select file storage bucket '".htmlspecialchars($bucket)."'.";
}
return false;
}
//Now lets make a new Object
$obj = $cont->create_object($objname);
$content_to_write_to_rscf="";
if ($is_file)
{
$content_to_write_to_rscf=file_get_contents($str);
}
else
{
$content_to_write_to_rscf=$str;
}
$obj->content_type=$mimetype;
$obj->set_etag(md5($content_to_write_to_rscf));
//Now lets put some stuff into the Object
$written=$obj->write($content_to_write_to_rscf);
return true;
} // end function
public function download_object($bucket_name,$keyname,$target_local_filename)
{
$failed=false;
$cont = $this->store->get_container($bucket_name) or $failed=true;
if (!$failed)
{
$object=$cont->get_object($keyname);
$stream = $object->getContent();
// Cast to string
//$content = (string) $stream;
$stream->rewind();
file_put_contents($target_local_filename, $stream->getStream());
// OR ALT APPROACH: $cdnUrl = $object->getPublicUrl();
return true;
}
return false;
}
public function get_object($bucket,$key_url)
{
$failed=false;
$keyname=substr($key_url,strlen($this->container_url($bucket))+1);
$cont = $this->store->get_container($bucket) or $failed=true;
if (!$failed)
{
$ret=$cont->get_object($keyname);
return $ret->read();
}
return "";
}
} // end class
// CONCRETE STORAGE TYPE: LOCALDISK
class Storage_Localdisk extends Storage
{
public $basefolder="";
function __construct()
{
}
public function get_object_filesize($bucket_name,$keyname)
{
$file_path=$bucket_name."/".$keyname;
$file_size=filesize($file_path);
return $this->_format_bytes($file_size);
}
public function connect()
{
$failed=false;
// nothing to do here yet
$this->store=true;
if ( is_dir($this->basefolder) )
{
}
else if ( is_link($this->basefolder) )
{
if ( is_dir( readlink($this->basefolder) ) )
{
//echo "SYMLINK READ, DIR IS ".readlink($this->basefolder);
}
else
{
echo readlink($this->basefolder);
echo "FOLDER DOES NOT EXIST";
$failed=true;
}
}
else
{
echo "BUCKET NAME: ".$this->basefolder."\n";
echo "DOES NOT EXIST";
$failed=true;
}
return $this->connectcheck($failed);
}
public function bucket_syntax()
{
return "webfolder";
}
public function key_url($bucket_name,$keyname)
{
$FILE_LOCATION="";
$base_url=$this->container_url($bucket_name);
if ($base_url!==false)
{
$base_url=$base_url."/".$keyname;
$FILE_LOCATION=$base_url;
}
return $FILE_LOCATION;
}
public function container_url($bucket)
{
// no slash on the end of string
return $bucket;
}
public function create_object($is_file,$bucket,$objname,$str,$mimetype)
{
// bucket == folder name
// objname == rel path to filename
$bucket = $this->basefolder;
if ( is_dir($bucket) )
{
//$slash="/";
$objname=str_replace("\\","/",$objname);
//$relfolders=explode($slash,$objname);
//unset($relfolders[count($relfolders)-1]);
//$relfolder=implode($slash,$relfolders);
//$relfolder=$bucket."/".$relfolder;
//if ( !is_dir($relfolder) )
//{
//mkdir($relfolder,0770,true);
//}
if ($is_file)
{
$success=copy($str,$bucket."/".$objname);
if (!$success)
{
echo "There was a problem copying the file to the bucket.";
exit;
}
}
else
{
file_put_contents($bucket."/".$objname,$str);
}
return true;
//file_put_contents($bucket.DIRECTORY_SEPARATOR.$objname,$str);
}
else
{
if ($this->debug==false)
{
echo "Unable to select file storage folder '".htmlspecialchars($bucket)."'.";
}
return false;
}
} // end function
public function download_object($bucket_name,$keyname,$target_local_filename)
{
$options = array(
CURLOPT_FILE => $target_local_filename,
CURLOPT_TIMEOUT => 24*60*60, // set this to 24 hours so we dont timeout on big files
CURLOPT_URL => $this->key_url($bucket_name,$keyname),
);
$ch = curl_init();
curl_setopt_array($ch, $options);
curl_exec($ch);
curl_close($ch);
return true;
}
public function get_object($bucket,$key_url)
{
//$keyname=substr($key_url,strlen($this->container_url($bucket))+1);
//$keyname=$bucket."/".$keyname;
$keyname=$key_url;
$contents=file_get_contents($keyname);
/*
$contents="";
try
{
$handle = fopen($keyname, "rb");
if ($handle)
{
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
}
}
catch (Exception $e)
{
return $e->getMessage();
}*/
/*
$contents=file_get_contents($keyname);
if ($contents===FALSE)
{
$handle = fopen($key_url, "rb");
if ($handle)
{
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
}
}*/
return $contents;
}
} // end class
require_once "api/dropbox-php-sdk-1.1.3/lib/Dropbox/autoload.php";
// user has to go to their https://www.dropbox.com/developers/apps and "Create app" in order
// to create dropbox api key
// "Dropbox API app" radio box > "Files and datastores" radio box > "Yes My app only needs access to files it creates." radio box > provide app name "test01" in text box
// CONCRETE STORAGE TYPE: LOCALDISK
use \Dropbox as dbx;
class Storage_Dropbox extends Storage
{
function __construct()
{
}
public function get_object_filesize($folder_name,$keyname)
{
$m=$this->store->getMetadata($this->key_url($folder_name,$keyname));
return $m['bytes'];
}
public function connect()
{
$failed=false;
try
{
$dbxClient = new dbx\Client($this->auth4, "PHP-Example/1.0");
//$accountInfo = $dbxClient->getAccountInfo();
//print_r($accountInfo);
$this->store = $dbxClient;
$m=$this->store->getMetadata( $this->container_url($this->bucket) );
if ( !isset($m['path']) )
{
$res = $this->store->createFolder( $this->container_url($this->bucket) );
if (!$res)
{
$failed=true;
}
}
}
catch (Exception $e)
{
$failed=true;
}
return $this->connectcheck($failed);
}
public function bucket_syntax()
{
return "folder";
}
public function key_url($folder_name,$keyname)
{
return $this->container_url($folder_name)."/".$keyname;
}
public function container_url($folder)
{
return "/".$folder;
}
public function download_object($bucket_name,$keyname,$target_local_filename)
{
}
public function create_object($is_file,$folder,$objname,$str,$mimetype)
{
// http://dropbox.github.io/dropbox-sdk-php/api-docs/v1.1.x/class-Dropbox.Client.html#_uploadFile
if ($is_file)
{
$pathError = dbx\Path::findErrorNonRoot($folder."/".$objname);
if ($pathError !== null) {
fwrite(STDERR, "Invalid <dropbox-path>: $pathError\n");
die;
}
$size = null;
if (\stream_is_local($sourcePath)) {
$size = \filesize($sourcePath);
}
$fp = fopen($objname, "rb");
$metadata = $this->store->uploadFile($this->key_url($folder,$objname), dbx\WriteMode::add(), $fp, $size);
fclose($fp);
//print_r($metadata);
}
else
{
$metadata = $this->store->uploadFileFromString($this->key_url($folder,$objname),dbx\WriteMode::add(),''.$str);
//print_r($metadata);
}
}
public function get_object($bucket,$key_url)
{
$m=$this->store->getMetadata($key_url);
list($tempurl,$dt_modified)=$this->store->createTemporaryDirectLink($key_url);
return file_get_contents($tempurl);
/*
$keyname=substr($key_url,strlen($this->container_url($bucket))+1);
$fd = fopen("./Frog.jpeg", "wb");
$metadata = $this->store->getFile("/Photos/Frog.jpeg", $fd);
fclose($fd);
print_r($metadata);
*/
}
}
include("api/BoxPHPAPI/BoxAPI.class.php");
class Storage_Box extends Storage
{
function __construct()
{
/*
// User details
$box->get_user();
// Get folder details
$box->get_folder_details('FOLDER ID');
// Get folder items list
$box->get_folder_items('FOLDER ID');
// All folders in particular folder
$box->get_folders('FOLDER ID');
// All Files in a particular folder
$box->get_files('FOLDER ID');
// All Web links in a particular folder
$box->get_links('FOLDER ID');
// Get folder collaborators list
$box->get_folder_collaborators('FOLDER ID');
// Create folder
$box->create_folder('FOLDER NAME', 'PARENT FOLDER ID');
// Update folder details
$details['name'] = 'NEW FOLDER NAME';
$box->update_folder('FOLDER ID', $details);
// Share folder
$params['shared_link']['access'] = 'ACCESS TYPE'; //open|company|collaborators
print_r($box->share_folder('FOLDER ID', $params));
// Delete folder
$opts['recursive'] = 'true';
$box->delete_folder('FOLDER ID', $opts);
// Get file details
$box->get_file_details('FILE ID');
// Upload file
$box->put_file('RELATIVE FILE URL', '0');
// Update file details
$details['name'] = 'NEW FILE NAME';
$details['description'] = 'NEW DESCRIPTION FOR THE FILE';
$box->update_file('FILE ID', $details);
// Share file
$params['shared_link']['access'] = 'ACCESS TYPE'; //open|company|collaborators
print_r($box->share_file('File ID', $params));
// Delete file
$box->delete_file('FILE ID');
if (isset($box->error)){
echo $box->error . "\n";
}
*/
}
public function get_object_filesize($folder_name,$keyname)
{
$m=$this->store->getMetadata($this->key_url($folder_name,$keyname));
return $m['bytes'];
}
public function connect()
{
$failed=false;
try
{
$box = new Box_API($this->auth1, $this->auth2, $this->auth3);
// BOX TOKENS EXPIRE AUTOMATICALLY
// ACCESS TOKENS = 1 hr
// REFRESH TOKENS = 60 days
$loaded_token = $box->load_token($this->auth5);
if(!$loaded_token)
{
$failed=true;
}
else
{
if ($loaded_token!==true)
{
// THE TOKEN WAS AUTOMATICALLY UPDATED, NOW WE NEED TO STORE IT SOMEWHERE
}
}
if (!$failed)
{
$this->store = $box;
//$m=$this->store->getMetadata( $this->container_url($this->bucket) );
/*
if ( !isset($m['path']) )
{
$res = $this->store->createFolder( $this->container_url($this->bucket) );
if (!$res)
{
$failed=true;
}
}*/
}
}
catch (Exception $e)
{
$failed=true;
}
return $this->connectcheck($failed);
}
public function bucket_syntax()
{
return "folder";
}
public function key_url($folder_name,$keyname)
{
return $this->container_url($folder_name)."/".$keyname;
}
public function container_url($folder)
{
return "/".$folder;
}
public function download_object($bucket_name,$keyname,$target_local_filename)
{
}
public function create_object($is_file,$folder,$objname,$str,$mimetype)
{
if ($is_file)
{
// Upload file
$box->put_file('RELATIVE FILE URL', '0');
$params['shared_link']['access'] = 'ACCESS TYPE'; //open|company|collaborators
$share_result = $box->share_file('File ID', $params);
}
else
{
}
}
public function get_object($bucket,$key_url)
{
$m=$this->store->getMetadata($key_url);
list($tempurl,$dt_modified)=$this->store->createTemporaryDirectLink($key_url);
return file_get_contents($tempurl);
/*
$keyname=substr($key_url,strlen($this->container_url($bucket))+1);
$fd = fopen("./Frog.jpeg", "wb");
$metadata = $this->store->getFile("/Photos/Frog.jpeg", $fd);
fclose($fd);
print_r($metadata);
*/
}
}
abstract class Storage_Adapter
{
public $storage;
public $kind;
function is_rackspace()
{
if ( strpos($this->kind,"rackspace")!==false || strpos($this->kind,"rscf")!==false || strpos($this->kind,"cloudfiles")!==false || strpos($this->kind,"rcf")!==false )
{
return true;
}
else
{
return false;
}
}
function is_aws()
{
if ( strpos($this->kind,"aws")!==false || strpos($this->kind,"s3")!==false || strpos($this->kind,"amazon")!==false )
{
return true;
}
else
{
return false;
}
}
function is_localdisk()
{
if ( strpos($this->kind,"local")!==FALSE || strpos($this->kind,"hard")!==FALSE || strpos($this->kind,"disk")!==FALSE || strpos($this->kind,"drive")!==FALSE || strpos($this->kind,"folder")!==FALSE )
{
return true;
}
else
{
return false;
}
}
function is_dropbox()
{
if ( strpos($this->kind,"dropbox")!==FALSE || strpos($this->kind,"dropbox")!==FALSE )
{
return true;
}
else
{
return false;
}
}
function is_box()
{
if ( strpos($this->kind,"box")===0 )
{
return true;
}
else
{
return false;
}
}
}
class Post_Storage_Adapter extends Storage_Adapter
{
function __construct($settings)
{
if ( isset($_POST['fstype']) )
{
$this->kind=strtolower($_POST['fstype']);
}
else
{
$this->kind="unknown";
return;
}
if ($this->is_rackspace() )
{
$this->kind="rackspacecloudfiles";
$this->storage = new Storage_Rackspace();
$this->storage->auth1=$_POST['RS-USER-NAME'];
$this->storage->auth2=$_POST['RS-API-KEY'];
$this->storage->bucket=$_POST['RS-CONTAINER-NAME'];
$this->storage->kind=$this->kind;
$this->storage->connect();
}
else if ($this->is_aws() )
{
$this->kind="s3";
$this->storage = new Storage_AWS();
$this->storage->auth1=$_POST['S3-ACCESS-KEY'];
$this->storage->auth2=$_POST['S3-SECRET-KEY'];
$this->storage->bucket=$_POST['S3-BUCKET-NAME'];
$this->storage->kind=$this->kind;
$this->storage->region=$_POST['S3-REGION-NAME'];
$this->storage->connect();
}
else if ($this->is_dropbox() )
{
$this->kind="dropbox";
$this->storage = new Storage_Dropbox();
$this->storage->auth1=$_POST['DROPBOX-CORE-APP-KEY'];
$this->storage->auth2=$_POST['DROPBOX-CORE-APP-SECRET'];
$this->storage->auth3=$_POST['DROPBOX-CORE-AUTH-CODE'];
$this->storage->auth4=$_POST['DROPBOX-CORE-ACCESS-TOKEN'];
$this->storage->bucket=$_POST['DROPBOX-CORE-BUCKET'];
$this->storage->kind=$this->kind;
$this->storage->connect();
}
else if ($this->is_localdisk() )
{
$this->kind="localdisk";
$this->storage = new Storage_Localdisk();
$this->storage->bucket=$_POST['LOCALDISK-WEBFOLDER-NAME'];
$this->storage->basefolder=$_POST['LOCALDISK-FOLDER-NAME'];
$this->storage->kind=$this->kind;
$this->storage->connect();
}
else if ($this->is_box() )
{
$this->kind="box";
$this->storage = new Storage_Box();
$this->storage->auth1=$_POST['BOX-OAUTH2-ID'];
$this->storage->auth2=$_POST['BOX-OAUTH2-SECRET'];
$this->storage->auth3=$_POST['BOX-REDIRECT-URI'];
$this->storage->auth4=$_POST['BOX-AUTH-CODE'];
$this->storage->auth5=$_POST['BOX-TOKEN'];
$this->storage->bucket=$_POST['BOX-FOLDER-NAME'];
$this->storage->kind=$this->kind;
$this->storage->connect();
}
else
{
echo "UNRECOGNIZED STORAGE TYPE ".$this->kind;
$this->storage=false;
exit;
}
}
}
class Settings_Storage_Adapter extends Storage_Adapter
{
function __construct($settings)
{
// settings array
$this->kind=$settings['storage']['@attributes']['value'];
if ($this->is_rackspace() )
{
$this->storage = new Storage_Rackspace();
$this->storage->auth1=$settings[$this->kind]['user-name']['@attributes']['value'];
$this->storage->auth2=$settings[$this->kind]['api-key']['@attributes']['value'];
$this->storage->bucket=$settings[$this->kind]['container']['@attributes']['value'];
$this->storage->kind=$this->kind;
$this->storage->connect();
}
else if ($this->is_aws() )
{
$this->storage = new Storage_AWS();
$this->storage->auth1=$settings[$this->kind]['access-key']['@attributes']['value'];
$this->storage->auth2=$settings[$this->kind]['secret-key']['@attributes']['value'];
$this->storage->bucket=$settings[$this->kind]['bucket']['@attributes']['value'];
$this->storage->kind=$this->kind;
$this->storage->region=$settings[$this->kind]['region']['@attributes']['value'];
$this->storage->connect();
}
else if ($this->is_dropbox() )
{
$this->storage = new Storage_Dropbox();
$this->storage->auth1=$settings[$this->kind]['app-key']['@attributes']['value'];
$this->storage->auth2=$settings[$this->kind]['secret-key']['@attributes']['value'];
$this->storage->auth3=$settings[$this->kind]['auth-code']['@attributes']['value'];
$this->storage->auth4=$settings[$this->kind]['access-key']['@attributes']['value'];
$this->storage->bucket=$settings[$this->kind]['folder']['@attributes']['value'];
$this->storage->kind=$this->kind;
$this->storage->connect();
}
else if ($this->is_localdisk() )
{
$this->storage = new Storage_Localdisk();
$this->storage->bucket=$settings[$this->kind]['webfolder']['@attributes']['value'];
$this->storage->basefolder=$settings[$this->kind]['folder']['@attributes']['value'];
$this->storage->kind=$this->kind;
$this->storage->connect();
}
else
{
echo "UNRECOGNIZED STORAGE TYPE ".$this->kind;
$this->storage=false;
exit;
}
}
} // end class
class MatchEntry_Storage_Adapter extends Storage_Adapter
{
function __construct($settings)
{
if ( isset($settings['fs_type']) )
{
$this->kind=$settings["fs_type"]->value;
}
// settings array
if ($this->is_rackspace() )
{
$this->storage = new Storage_Rackspace();
$this->storage->auth1=$settings["RS-USER-NAME"]->value;
$this->storage->auth2=$settings["RS-API-KEY"]->value;
$this->storage->bucket=$settings["RS-CONTAINER-NAME"]->value;
$this->storage->kind=$settings["fs_type"]->value;
$this->storage->connect();
}
else if ($this->is_aws() )
{
$this->storage = new Storage_AWS();
$this->storage->auth1=$settings["S3-ACCESS-KEY"]->value;
$this->storage->auth2=$settings["S3-SECRET-KEY"]->value;
$this->storage->bucket=$settings["S3-BUCKET-NAME"]->value;
$this->storage->region=$settings["S3-REGION-NAME"]->value;
$this->storage->kind=$settings["fs_type"]->value;
$this->storage->connect();
}
else if ($this->is_dropbox() )