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){ |
|
44 | |||
45 | /** |
||
46 | * @NoAdminRequired |
||
47 | * @NoCSRFRequired |
||
48 | */ |
||
49 | public function index(){ |
||
50 | \OC::$server->getNavigationManager()->setActiveEntry( 'documents_index' ); |
||
51 | $maxUploadFilesize = \OCP\Util::maxUploadFilesize("/"); |
||
52 | return new TemplateResponse('documents', 'documents', [ |
||
53 | 'enable_previews' => $this->settings->getSystemValue('enable_previews', true), |
||
54 | 'useUnstable' => $this->settings->getAppValue('documents', 'unstable', 'false'), |
||
55 | 'savePath' => $this->settings->getUserValue($this->uid, 'documents', 'save_path', '/'), |
||
56 | 'uploadMaxFilesize' => $maxUploadFilesize, |
||
57 | 'uploadMaxHumanFilesize' => \OCP\Util::humanFileSize($maxUploadFilesize), |
||
58 | 'allowShareWithLink' => $this->settings->getAppValue('core', 'shareapi_allow_links', 'yes'), |
||
59 | ]); |
||
60 | } |
||
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 | } |
||
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 | } |
||
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 | ); |
||
89 | } 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){ |
||
110 | |||
111 | /** |
||
112 | * @NoAdminRequired |
||
113 | */ |
||
114 | public function download($path){ |
||
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 |