<?php class FileController extends PluginController { function validate_args(&$args, $types = NULL) { reset($args); } /** * The action for editing a file reference. */ public function edit_action($file_ref_id) { $file_id = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], "plugins.php/owncloudplugin/file/edit/") + strlen("plugins.php/owncloudplugin/file/edit/")); if (strpos($file_id, "?") !== false) { $file_id = substr($file_id, 0, strpos($file_id, "?")); } $plugin = PluginManager::getInstance()->getPlugin("OwnCloudPlugin"); $this->file = $plugin->getPreparedFile($file_id); $this->from_plugin = Request::get("from_plugin"); $this->folder = $this->file->getFoldertype(); if (!$this->folder || !$this->folder->isFileEditable($this->file->getId(), $GLOBALS['user']->id)) { throw new AccessDeniedException(); } if (Request::isPost()) { //form was sent CSRFProtection::verifyUnsafeRequest(); $this->errors = []; $this->name = trim(Request::get('name')); $result = $this->folder->editFile( $file_id, $this->name ); if (!($result instanceof FileType)) { $this->errors = array_merge($this->errors, $result); } if ($this->errors) { PageLayout::postError( sprintf( _('Fehler beim Ändern der Datei %s!'), htmlReady($this->file->getFilename()) ), $this->errors ); } else { PageLayout::postSuccess(_('Änderungen gespeichert!')); $this->redirect(URLHelper::getURL("dispatch.php/files/system/".$this->plugin->getPluginId()."/".$this->folder->getId())); } } $this->name = $this->file->getFilename(); $tf = new Flexi_TemplateFactory($GLOBALS['STUDIP_BASE_PATH']."/app/views"); $this->aside_template = $tf->open("file/_file_aside.php"); $this->aside_template->file = $this->file; } /** * This action is responsible for updating a file reference. */ public function update_action($file_ref_id) { $file_id = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], "plugins.php/owncloudplugin/file/update/") + strlen("plugins.php/owncloudplugin/file/update/")); if (strpos($file_id, "?") !== false) { $file_id = substr($file_id, 0, strpos($file_id, "?")); } $plugin = PluginManager::getInstance()->getPlugin(Request::get("from_plugin")); if (!$plugin) { throw new Trails_Exception(404, _('Plugin existiert nicht.')); } $this->file = $plugin->getPreparedFile($file_id); $this->from_plugin = Request::get("from_plugin"); $this->folder = $this->file->getFolderType(); if (!$this->file->isEditable($GLOBALS['user']->id)) { throw new AccessDeniedException(); } $this->errors = []; if (Request::submitted('confirm')) { CSRFProtection::verifyUnsafeRequest(); //Form was sent if (Request::isPost() && is_array($_FILES['file'])) { $this->file->update($_FILES['file']['tmp_name']); if (Request::submitted("update_filename")) { $new_name = ($this->folder->id ? $this->folder->id."/" : "").$_FILES['file']['name']; $this->folder->editFile( $file_id, $new_name ); } } else { $this->errors[] = _('Es wurde keine neue Dateiversion gewählt!'); } if ($this->errors) { PageLayout::postError( sprintf( _('Fehler beim Aktualisieren der Datei %s!'), htmlReady($this->file_ref->name) ), $this->errors ); } else { PageLayout::postSuccess( sprintf( _('Datei %s wurde aktualisiert!'), htmlReady($this->file_ref->name) ) ); } $this->redirect(URLHelper::getURL("dispatch.php/files/system/".$this->plugin->getPluginId()."/".$this->folder->getId())); } } }