Esempio n. 1
0
    return;
}
if (!\OC\Files\Filesystem::file_exists($dir . '/')) {
    $result['data'] = array('message' => (string) $l10n->t('The target folder has been moved or deleted.'), 'code' => 'targetnotfound');
    OCP\JSON::error($result);
    exit;
}
$target = $dir . '/' . $fileName;
if (\OC\Files\Filesystem::file_exists($target)) {
    $result['data'] = array('message' => (string) $l10n->t('The name %s is already used in the folder %s. Please choose a different name.', array($fileName, $dir)));
    OCP\JSON::error($result);
    exit;
}
$success = false;
$templateManager = OC_Helper::getFileTemplateManager();
$mimeType = OC_Helper::getMimetypeDetector()->detectPath($target);
$content = $templateManager->getTemplate($mimeType);
try {
    if ($content) {
        $success = \OC\Files\Filesystem::file_put_contents($target, $content);
    } else {
        $success = \OC\Files\Filesystem::touch($target);
    }
} catch (\Exception $e) {
    $result = ['success' => false, 'data' => ['message' => $e->getMessage()]];
    OCP\JSON::error($result);
    exit;
}
if ($success) {
    $meta = \OC\Files\Filesystem::getFileInfo($target);
    OCP\JSON::success(array('data' => \OCA\Files\Helper::formatFileInfo($meta)));
Esempio n. 2
0
 public function touch($path, $mtime = null)
 {
     $path = $this->normalizePath($path);
     if (is_null($mtime)) {
         $mtime = time();
     }
     $metadata = array('timestamp' => $mtime);
     if ($this->file_exists($path)) {
         $object = $this->getContainer()->getPartialObject($path);
         $object->saveMetadata($metadata);
         return true;
     } else {
         $mimeType = \OC_Helper::getMimetypeDetector()->detectPath($path);
         $customHeaders = array('content-type' => $mimeType);
         $metadataHeaders = DataObject::stockHeaders($metadata);
         $allHeaders = $customHeaders + $metadataHeaders;
         $this->getContainer()->uploadObject($path, '', $allHeaders);
         return true;
     }
 }
Esempio n. 3
0
 public function touch($path, $mtime = null)
 {
     $path = $this->normalizePath($path);
     $metadata = array();
     if (!is_null($mtime)) {
         $metadata = array('lastmodified' => $mtime);
     }
     $fileType = $this->filetype($path);
     try {
         if ($fileType !== false) {
             if ($fileType === 'dir' && !$this->isRoot($path)) {
                 $path .= '/';
             }
             $this->getConnection()->copyObject(array('Bucket' => $this->bucket, 'Key' => $this->cleanKey($path), 'Metadata' => $metadata, 'CopySource' => $this->bucket . '/' . $path));
             $this->testTimeout();
         } else {
             $mimeType = \OC_Helper::getMimetypeDetector()->detectPath($path);
             $this->getConnection()->putObject(array('Bucket' => $this->bucket, 'Key' => $this->cleanKey($path), 'Metadata' => $metadata, 'ContentType' => $mimeType));
             $this->testTimeout();
         }
     } catch (S3Exception $e) {
         \OCP\Util::logException('files_external', $e);
         return false;
     }
     return true;
 }
Esempio n. 4
0
 public function touch($path, $mtime = null)
 {
     $path = $this->normalizePath($path);
     $metadata = array();
     if (is_null($mtime)) {
         $mtime = time();
     }
     $metadata = ['lastmodified' => gmdate(\Aws\Common\Enum\DateFormat::RFC1123, $mtime)];
     $fileType = $this->filetype($path);
     try {
         if ($fileType !== false) {
             if ($fileType === 'dir' && !$this->isRoot($path)) {
                 $path .= '/';
             }
             $this->getConnection()->copyObject(['Bucket' => $this->bucket, 'Key' => $this->cleanKey($path), 'Metadata' => $metadata, 'CopySource' => $this->bucket . '/' . $path, 'MetadataDirective' => 'REPLACE']);
             $this->testTimeout();
         } else {
             $mimeType = \OC_Helper::getMimetypeDetector()->detectPath($path);
             $this->getConnection()->putObject(['Bucket' => $this->bucket, 'Key' => $this->cleanKey($path), 'Metadata' => $metadata, 'Body' => '', 'ContentType' => $mimeType, 'MetadataDirective' => 'REPLACE']);
             $this->testTimeout();
         }
     } catch (S3Exception $e) {
         \OCP\Util::logException('files_external', $e);
         return false;
     }
     return true;
 }
Esempio n. 5
0
<?php

/**
 * ownCloud - OwnPad
 *
 * This file is licensed under the Affero General Public License
 * version 3 or later. See the COPYING file.
 *
 * @author Olivier Tétard <*****@*****.**>
 * @copyright Olivier Tétard <*****@*****.**>, 2015
 */
OCP\App::registerAdmin('ownpad', 'settings');
OCP\Util::addscript('ownpad', 'ownpad');
OCP\Util::addStyle('ownpad', 'ownpad');
\OC_Helper::getMimetypeDetector()->registerType("pad", "application/x-ownpad");
\OC_Helper::getMimetypeDetector()->registerType("calc", "application/x-ownpad");