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 | public function __construct($appName, IRequest $request, IConfig $settings, IL10N $l10n, $uid){ |
||
39 | parent::__construct($appName, $request); |
||
40 | $this->uid = $uid; |
||
41 | $this->l10n = $l10n; |
||
42 | $this->settings = $settings; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * @NoAdminRequired |
||
47 | * @NoCSRFRequired |
||
48 | */ |
||
49 | public function index(){ |
||
61 | |||
62 | /** |
||
63 | * @NoAdminRequired |
||
64 | */ |
||
65 | public function create(){ |
||
66 | $view = new View('/' . $this->uid . '/files'); |
||
67 | $dir = $this->settings->getUserValue($this->uid, $this->appName, 'save_path', '/'); |
||
68 | if (!$view->is_dir($dir)){ |
||
69 | $dir = '/'; |
||
70 | } |
||
71 | $path = Helper::getNewFileName($view, $dir . '/New Document.odt'); |
||
72 | |||
73 | $content = ''; |
||
74 | if (class_exists('\OC\Files\Type\TemplateManager')){ |
||
75 | $manager = \OC_Helper::getFileTemplateManager(); |
||
76 | $content = $manager->getTemplate(Storage::MIMETYPE_LIBREOFFICE_WORDPROCESSOR); |
||
77 | } |
||
78 | |||
79 | if (!$content){ |
||
80 | $content = file_get_contents(dirname(__DIR__) . self::ODT_TEMPLATE_PATH); |
||
81 | } |
||
82 | |||
83 | if ($content && $view->file_put_contents($path, $content)){ |
||
84 | $info = $view->getFileInfo($path); |
||
85 | $response = array( |
||
86 | 'status' => 'success', |
||
87 | 'fileid' => $info['fileid'] |
||
88 | ); |
||
89 | } else { |
||
90 | $response = array( |
||
91 | 'status' => 'error', |
||
92 | 'message' => (string) $this->l10n->t('Can\'t create document') |
||
93 | ); |
||
94 | } |
||
95 | 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 | 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(){ |
||
204 | |||
205 | } |
||
206 |