1: <?php
2:
3: namespace webfilesframework\core\datasystem\file\system\dropbox;
4:
5: use webfilesframework\core\datasystem\file\system\MFile;
6:
7: 8: 9: 10: 11: 12:
13: class MDropboxFile extends MFile
14: {
15: protected $dropboxAccount;
16: protected $fileMetadata;
17: protected $filePath;
18:
19: 20: 21: 22: 23: 24: 25: 26:
27: public function __construct(MDropboxAccount $account, $filePath, $initMetadata = true)
28: {
29: parent::__construct($filePath);
30:
31: $this->filePath = $filePath;
32: $this->dropboxAccount = $account;
33: if ($initMetadata) {
34: $this->initMetadata();
35: }
36: }
37:
38: public function initMetadata()
39: {
40: $this->fileMetadata = $this->dropboxAccount->getDropboxApi()->metaData($this->filePath);
41: $lastSlash = strrpos($this->fileMetadata['body']->path, '/');
42: $fileName = substr($this->fileMetadata['body']->path, $lastSlash + 1);
43: $this->fileName = $fileName;
44: }
45:
46: public function getContent()
47: {
48: $file = $this->dropboxAccount->getDropboxApi()->getFile($this->filePath);
49: return $file['data'];
50: }
51:
52: public function writeContent($content, $overwrite = false)
53: {
54:
55: }
56:
57: 58: 59: 60:
61: public function upload()
62: {
63:
64: }
65:
66: 67: 68: 69: 70:
71: public function download($overwriteIfExists)
72: {
73: $file = $this->dropboxAccount->getDropboxApi()->getFile($this->filePath);
74:
75: if (!file_exists("." . $this->filePath)) {
76: $fp = fopen("." . $this->filePath, "w");
77: fputs($fp, $file['data']);
78: fclose($fp);
79: }
80: }
81:
82: public function downloadImageAsThumbnail()
83: {
84: $file = $this->dropboxAccount->getDropbox()->thumbnails($this->filePath, 'JPEG', 'l');
85:
86: if (!file_exists("." . $this->filePath)) {
87: $fp = fopen("." . $this->filePath, "w");
88: fputs($fp, $file['data']);
89: fclose($fp);
90: }
91: }
92: }