/** * Creates a new subdirectory * * @param string $name * @throws Sabre_DAV_Exception_Forbidden * @return void */ public function createDirectory($name) { if ($name === 'Shared' && empty($this->path)) { throw new \Sabre_DAV_Exception_Forbidden(); } if (!\OC\Files\Filesystem::isCreatable($this->path)) { throw new \Sabre_DAV_Exception_Forbidden(); } $newPath = $this->path . '/' . $name; if (!\OC\Files\Filesystem::mkdir($newPath)) { throw new Sabre_DAV_Exception_Forbidden('Could not create directory ' . $newPath); } }
// information about storage capacities $storageInfo = OC_Helper::getStorageInfo($dir); $maxUploadFilesize = OCP\Util::maxUploadFilesize($dir); $publicUploadEnabled = \OC_Appconfig::getValue('core', 'shareapi_allow_public_upload', 'yes'); // if the encryption app is disabled, than everything is fine (INIT_SUCCESSFUL status code) $encryptionInitStatus = 2; if (OC_App::isEnabled('files_encryption')) { $session = new \OCA\Encryption\Session(new \OC\Files\View('/')); $encryptionInitStatus = $session->getInitialized(); } $trashEnabled = \OCP\App::isEnabled('files_trashbin'); $trashEmpty = true; if ($trashEnabled) { $trashEmpty = \OCA\Files_Trashbin\Trashbin::isEmpty($user); } $isCreatable = \OC\Files\Filesystem::isCreatable($dir . '/'); $fileHeader = (!isset($files) or count($files) > 0); $emptyContent = ($isCreatable and !$fileHeader) or $ajaxLoad; OCP\Util::addscript('files', 'fileactions'); OCP\Util::addscript('files', 'files'); OCP\Util::addscript('files', 'keyboardshortcuts'); $tmpl = new OCP\Template('files', 'index', 'user'); $tmpl->assign('fileList', $list->fetchPage()); $tmpl->assign('breadcrumb', $breadcrumbNav->fetchPage()); $tmpl->assign('dir', $dir); $tmpl->assign('isCreatable', $isCreatable); $tmpl->assign('permissions', $permissions); $tmpl->assign('files', $files); $tmpl->assign('trash', $trashEnabled); $tmpl->assign('trashEmpty', $trashEmpty); $tmpl->assign('uploadMaxFilesize', $maxUploadFilesize);
/** * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem */ public static function isCreatable($path) { return \OC\Files\Filesystem::isCreatable($path); }
/** * Returns the numeric permissions for the given directory. * @param string $dir directory without trailing slash * @return numeric permissions */ public static function getDirPermissions($dir) { $permissions = \OCP\PERMISSION_READ; if (\OC\Files\Filesystem::isCreatable($dir . '/')) { $permissions |= \OCP\PERMISSION_CREATE; } if (\OC\Files\Filesystem::isUpdatable($dir . '/')) { $permissions |= \OCP\PERMISSION_UPDATE; } if (\OC\Files\Filesystem::isDeletable($dir . '/')) { $permissions |= \OCP\PERMISSION_DELETE; } if (\OC\Files\Filesystem::isSharable($dir . '/')) { $permissions |= \OCP\PERMISSION_SHARE; } return $permissions; }
/** * Compile Latex File * * @NoAdminRequired * * @param string $path * @param string $filename * @param string $compiler * @return DataResponse */ public function doCompile($path, $filename, $compiler) { $success = 'success'; $error = 'error'; try { set_time_limit(0); //scanning can take ages // If they've set the compiler to something other than an allowable option.... if (!($compiler === 'xelatex' || $compiler === 'pdflatex' || $compiler === 'latex')) { $compiler = 'latex'; } // The real directory file $workdir = dirname(\OC\Files\Filesystem::getLocalFile(stripslashes($path) . $filename)); $info = pathinfo($filename); $fileext = '.' . $info['extension']; $projectname = trim(basename($filename, $fileext)); $pdffile = $projectname . '.pdf'; $dvifile = $projectname . '.dvi'; $psfile = $projectname . '.ps'; $tocfile = $projectname . '.toc'; $logfile = $projectname . '.log'; $bibfile = $projectname; // Bibtex File is without extension // As we will write pdf/ps file(s) in the $path, we need to known if it's writable if (!\OC\Files\Filesystem::isCreatable(stripslashes($path))) { return new JSONResponse(array('data' => array('message' => 'As you don\'t have write permission in the owner directory, it\'s not possible to create output latex files.', 'output' => '')), Http::STATUS_BAD_REQUEST); } // Command to jump into directory $cd_command = "cd " . str_replace(' ', '\\ ', trim($workdir)); // PDFLatex command preparation if ($compiler == 'xelatex' || $compiler == 'pdflatex') { $latex_command = $compiler . ' ' . $filename; $bibtex_command = 'bibtex ' . $bibfile; } else { $latex_command = "latex -output-directory={$outpath} {$filename} ; cd {$outpath}; dvips {$dvifile} ; ps2pdf {$psfile}"; } $output = "<b>========BEGIN COMPILE========</b>\n{$psfile} \n"; $output .= $cd_command . "\n"; $output .= getcwd() . "\n"; // First Compile $output .= shell_exec($cd_command . " && pwd"); $return = shell_exec($cd_command . " && " . $latex_command); $output .= getcwd() . "\n"; // For BibTeX if ($compiler == 'pdflatex') { // Second compile step with bibtex $return .= shell_exec($cd_command . " && " . $bibtex_command); // compile again after bibtex $return .= shell_exec($cd_command . " && " . $latex_command); } $logfile = $workdir . '/' . $logfile; $log = file_get_contents($logfile); while (preg_match('/Return to get cross-references right/', $log) || preg_match('/No file ' . $tocfile . '/', $log)) { $return .= shell_exec($cd_command . " && " . $this->latex_command); $log = file_get_contents($logfile); } // ! at begining of a line indicate an error! $errors = preg_grep("/^!/", explode("\n", $log)); if (empty($errors) === false) { $log_array = explode("\n", $log); $error = "\n"; foreach ($errors as $line => $msg) { for ($i = $line; $i <= $line + 5; $i++) { $error .= $log_array[$i] . "\n"; } } return new JSONResponse(array('data' => array('message' => $this->l->t('Compile failed with errors') . ' - <br/>', 'output' => nl2br($output . " % " . $latex_command . "\n" . $error)), 'status' => $error), Http::STATUS_OK); } // No PDF File !? if (!file_exists($workdir . '/' . $pdffile)) { return new JSONResponse(array('data' => array('message' => $this->l->t('Compile failed with errors') . ':<br/>', 'output' => nl2br($output . " % " . $latex_command . "\n" . file_get_contents($outpath . '/' . $logfile))), 'status' => $error), Http::STATUS_OK); } $output .= $return; $output .= "\n========END COMPILE==========\n"; $oc_workdir = stripslashes(\OC\Files\Filesystem::getLocalPath($workdir)); $target = \OCP\Files::buildNotExistingFileName($oc_workdir, $pdffile); $target = \OC\Files\Filesystem::normalizePath($target); $meta = \OC\Files\Filesystem::getFileInfo($target); if ($compiler === 'latex') { $target = \OCP\Files::buildNotExistingFileName($oc_workdir, $psfile); $target = \OC\Files\Filesystem::normalizePath($target); $meta = \OC\Files\Filesystem::getFileInfo($target); } return new JSONResponse(array('data' => array('output' => nl2br($output), 'path' => $path, 'pdffile' => $pdffile, 'psfile' => $psfile, 'logfile' => $logfile), 'status' => $success), Http::STATUS_OK); } catch (\Exception $e) { return new DataResponse(['message' => $e], Http::STATUS_BAD_REQUEST); } }
$permissions |= OCP\PERMISSION_DELETE; } if (\OC\Files\Filesystem::isSharable($dir . '/')) { $permissions |= OCP\PERMISSION_SHARE; } if ($needUpgrade) { OCP\Util::addscript('files', 'upgrade'); $tmpl = new OCP\Template('files', 'upgrade', 'user'); $tmpl->printPage(); } else { // information about storage capacities $storageInfo = OC_Helper::getStorageInfo(); $maxUploadFilesize = OCP\Util::maxUploadFilesize($dir); OCP\Util::addscript('files', 'fileactions'); OCP\Util::addscript('files', 'files'); OCP\Util::addscript('files', 'keyboardshortcuts'); $tmpl = new OCP\Template('files', 'index', 'user'); $tmpl->assign('fileList', $list->fetchPage()); $tmpl->assign('breadcrumb', $breadcrumbNav->fetchPage()); $tmpl->assign('dir', \OC\Files\Filesystem::normalizePath($dir)); $tmpl->assign('isCreatable', \OC\Files\Filesystem::isCreatable($dir . '/')); $tmpl->assign('permissions', $permissions); $tmpl->assign('files', $files); $tmpl->assign('trash', \OCP\App::isEnabled('files_trashbin')); $tmpl->assign('uploadMaxFilesize', $maxUploadFilesize); $tmpl->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize)); $tmpl->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true))); $tmpl->assign('usedSpacePercent', (int) $storageInfo['relative']); $tmpl->assign('isPublic', false); $tmpl->printPage(); }