1 | <?php |
||
30 | class DocumentController extends Controller{ |
||
31 | |||
32 | private $uid; |
||
33 | private $l10n; |
||
34 | private $settings; |
||
35 | |||
36 | const ODT_TEMPLATE_PATH = '/assets/new.odt'; |
||
37 | |||
38 | 2 | public function __construct($appName, IRequest $request, IConfig $settings, IL10N $l10n, $uid){ |
|
39 | 2 | parent::__construct($appName, $request); |
|
40 | 2 | $this->uid = $uid; |
|
41 | 2 | $this->l10n = $l10n; |
|
42 | 2 | $this->settings = $settings; |
|
43 | 2 | } |
|
44 | |||
45 | /** |
||
46 | * @NoAdminRequired |
||
47 | * @NoCSRFRequired |
||
48 | */ |
||
49 | public function index(){ |
||
61 | |||
62 | /** |
||
63 | * @NoAdminRequired |
||
64 | */ |
||
65 | 1 | public function create(){ |
|
66 | 1 | $view = new View('/' . $this->uid . '/files'); |
|
67 | 1 | $dir = $this->settings->getUserValue($this->uid, $this->appName, 'save_path', '/'); |
|
68 | 1 | if (!$view->is_dir($dir)){ |
|
69 | 1 | $dir = '/'; |
|
70 | 1 | } |
|
71 | 1 | $path = Helper::getNewFileName($view, $dir . '/New Document.odt'); |
|
72 | |||
73 | 1 | $content = ''; |
|
74 | 1 | if (class_exists('\OC\Files\Type\TemplateManager')){ |
|
75 | 1 | $manager = \OC_Helper::getFileTemplateManager(); |
|
76 | 1 | $content = $manager->getTemplate(Storage::MIMETYPE_LIBREOFFICE_WORDPROCESSOR); |
|
77 | 1 | } |
|
78 | |||
79 | 1 | if (!$content){ |
|
80 | $content = file_get_contents(dirname(__DIR__) . self::ODT_TEMPLATE_PATH); |
||
81 | } |
||
82 | |||
83 | 1 | if ($content && $view->file_put_contents($path, $content)){ |
|
84 | 1 | $info = $view->getFileInfo($path); |
|
85 | $response = array( |
||
86 | 1 | 'status' => 'success', |
|
87 | 1 | 'fileid' => $info['fileid'] |
|
88 | 1 | ); |
|
89 | 1 | } else { |
|
90 | $response = array( |
||
91 | 'status' => 'error', |
||
92 | 'message' => (string) $this->l10n->t('Can\'t create document') |
||
93 | ); |
||
94 | } |
||
95 | 1 | return $response; |
|
96 | } |
||
97 | |||
98 | /** |
||
99 | * @NoAdminRequired |
||
100 | * @PublicPage |
||
101 | * Process partial/complete file download |
||
102 | */ |
||
103 | public function serve($esId){ |
||
104 | $session = new Db\Session(); |
||
105 | $session->load($esId); |
||
106 | |||
107 | $filename = $session->getGenesisUrl() ? $session->getGenesisUrl() : ''; |
||
108 | return new DownloadResponse($this->request, $session->getOwner(), $filename); |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * @NoAdminRequired |
||
113 | */ |
||
114 | public function download($path){ |
||
115 | if (!$path){ |
||
116 | $response = new JSONResponse(); |
||
117 | $response->setStatus(Http::STATUS_BAD_REQUEST); |
||
118 | return $response; |
||
119 | } |
||
120 | |||
121 | $fullPath = '/files' . $path; |
||
122 | $fileInfo = \OC\Files\Filesystem::getFileInfo($path); |
||
123 | if ($fileInfo){ |
||
124 | if($fileInfo->getMimeType() !== \OCA\Documents\Filter\Office::NATIVE_MIMETYPE){ |
||
125 | $file = new File($fileInfo->getId()); |
||
126 | $genesis = new Genesis($file); |
||
127 | $fullPath = $genesis->getPath(); |
||
128 | } |
||
129 | } |
||
130 | return new DownloadResponse($this->request, $this->uid, $fullPath); |
||
131 | } |
||
132 | |||
133 | |||
134 | /** |
||
135 | * @NoAdminRequired |
||
136 | */ |
||
137 | 1 | public function rename($fileId){ |
|
161 | |||
162 | /** |
||
163 | * @NoAdminRequired |
||
164 | * lists the documents the user has access to (including shared files, once the code in core has been fixed) |
||
165 | * also adds session and member info for these files |
||
166 | */ |
||
167 | public function listAll(){ |
||
201 | |||
202 | } |
||
203 |