当前位置: 首页>>代码示例>>PHP>>正文


PHP Filesystem::isSharable方法代码示例

本文整理汇总了PHP中OC\Files\Filesystem::isSharable方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::isSharable方法的具体用法?PHP Filesystem::isSharable怎么用?PHP Filesystem::isSharable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OC\Files\Filesystem的用法示例。


在下文中一共展示了Filesystem::isSharable方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getPermissions

 /**
  * Determine permissions for a given file path
  * @param string $path
  * @return int
  */
 function getPermissions($path)
 {
     // add read permissions
     $permissions = \OCP\PERMISSION_READ;
     // get directory
     $fileInfo = pathinfo($path);
     $dir = $fileInfo['dirname'] . '/';
     // add update permissions
     if (Filesystem::isUpdatable($dir)) {
         $permissions |= \OCP\PERMISSION_UPDATE;
     }
     // add delete permissions
     if (Filesystem::isDeletable($dir)) {
         $permissions |= \OCP\PERMISSION_DELETE;
     }
     // add share permissions
     if (Filesystem::isSharable($dir)) {
         $permissions |= \OCP\PERMISSION_SHARE;
     }
     // return
     return $permissions;
 }
开发者ID:amin-hedayati,项目名称:search_lucene,代码行数:27,代码来源:luceneresult.php

示例2: shareItem

 /**
  * Share an item with a user, group, or via private link
  * @param string $itemType
  * @param string $itemSource
  * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
  * @param string $shareWith User or group the item is being shared with
  * @param int $permissions CRUDS
  * @param string $itemSourceName
  * @param \DateTime $expirationDate
  * @param bool $passwordChanged
  * @return boolean|string Returns true on success or false on failure, Returns token on success for links
  * @throws \OC\HintException when the share type is remote and the shareWith is invalid
  * @throws \Exception
  */
 public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName = null, \DateTime $expirationDate = null, $passwordChanged = null)
 {
     $backend = self::getBackend($itemType);
     $l = \OC::$server->getL10N('lib');
     if ($backend->isShareTypeAllowed($shareType) === false) {
         $message = 'Sharing %s failed, because the backend does not allow shares from type %i';
         $message_t = $l->t('Sharing %s failed, because the backend does not allow shares from type %i', array($itemSourceName, $shareType));
         \OCP\Util::writeLog('OCP\\Share', sprintf($message, $itemSourceName, $shareType), \OCP\Util::DEBUG);
         throw new \Exception($message_t);
     }
     $uidOwner = \OC_User::getUser();
     $shareWithinGroupOnly = self::shareWithGroupMembersOnly();
     if (is_null($itemSourceName)) {
         $itemSourceName = $itemSource;
     }
     $itemName = $itemSourceName;
     // check if file can be shared
     if ($itemType === 'file' or $itemType === 'folder') {
         $path = \OC\Files\Filesystem::getPath($itemSource);
         $itemName = $path;
         // verify that the file exists before we try to share it
         if (!$path) {
             $message = 'Sharing %s failed, because the file does not exist';
             $message_t = $l->t('Sharing %s failed, because the file does not exist', array($itemSourceName));
             \OCP\Util::writeLog('OCP\\Share', sprintf($message, $itemSourceName), \OCP\Util::DEBUG);
             throw new \Exception($message_t);
         }
         // verify that the user has share permission
         if (!\OC\Files\Filesystem::isSharable($path)) {
             $message = 'You are not allowed to share %s';
             $message_t = $l->t('You are not allowed to share %s', [$path]);
             \OCP\Util::writeLog('OCP\\Share', sprintf($message, $path), \OCP\Util::DEBUG);
             throw new \Exception($message_t);
         }
     }
     //verify that we don't share a folder which already contains a share mount point
     if ($itemType === 'folder') {
         $path = '/' . $uidOwner . '/files' . \OC\Files\Filesystem::getPath($itemSource) . '/';
         $mountManager = \OC\Files\Filesystem::getMountManager();
         $mounts = $mountManager->findIn($path);
         foreach ($mounts as $mount) {
             if ($mount->getStorage()->instanceOfStorage('\\OCA\\Files_Sharing\\ISharedStorage')) {
                 $message = 'Sharing "' . $itemSourceName . '" failed, because it contains files shared with you!';
                 \OCP\Util::writeLog('OCP\\Share', $message, \OCP\Util::DEBUG);
                 throw new \Exception($message);
             }
         }
     }
     // single file shares should never have delete permissions
     if ($itemType === 'file') {
         $permissions = (int) $permissions & ~\OCP\Constants::PERMISSION_DELETE;
     }
     //Validate expirationDate
     if ($expirationDate !== null) {
         try {
             /*
              * Reuse the validateExpireDate.
              * We have to pass time() since the second arg is the time
              * the file was shared, since it is not shared yet we just use
              * the current time.
              */
             $expirationDate = self::validateExpireDate($expirationDate->format('Y-m-d'), time(), $itemType, $itemSource);
         } catch (\Exception $e) {
             throw new \OC\HintException($e->getMessage(), $e->getMessage(), 404);
         }
     }
     // Verify share type and sharing conditions are met
     if ($shareType === self::SHARE_TYPE_USER) {
         if ($shareWith == $uidOwner) {
             $message = 'Sharing %s failed, because you can not share with yourself';
             $message_t = $l->t('Sharing %s failed, because you can not share with yourself', [$itemName]);
             \OCP\Util::writeLog('OCP\\Share', sprintf($message, $itemSourceName), \OCP\Util::DEBUG);
             throw new \Exception($message_t);
         }
         if (!\OC_User::userExists($shareWith)) {
             $message = 'Sharing %s failed, because the user %s does not exist';
             $message_t = $l->t('Sharing %s failed, because the user %s does not exist', array($itemSourceName, $shareWith));
             \OCP\Util::writeLog('OCP\\Share', sprintf($message, $itemSourceName, $shareWith), \OCP\Util::DEBUG);
             throw new \Exception($message_t);
         }
         if ($shareWithinGroupOnly) {
             $inGroup = array_intersect(\OC_Group::getUserGroups($uidOwner), \OC_Group::getUserGroups($shareWith));
             if (empty($inGroup)) {
                 $message = 'Sharing %s failed, because the user ' . '%s is not a member of any groups that %s is a member of';
                 $message_t = $l->t('Sharing %s failed, because the user %s is not a member of any groups that %s is a member of', array($itemName, $shareWith, $uidOwner));
                 \OCP\Util::writeLog('OCP\\Share', sprintf($message, $itemName, $shareWith, $uidOwner), \OCP\Util::DEBUG);
//.........这里部分代码省略.........
开发者ID:evanjt,项目名称:core,代码行数:101,代码来源:share.php

示例3: shareItem

 /**
  * Share an item with a user, group, or via private link
  * @param string $itemType
  * @param string $itemSource
  * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
  * @param string $shareWith User or group the item is being shared with
  * @param int $permissions CRUDS
  * @param string $itemSourceName
  * @param \DateTime $expirationDate
  * @return boolean|string Returns true on success or false on failure, Returns token on success for links
  * @throws \Exception
  */
 public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName = null, \DateTime $expirationDate = null)
 {
     $uidOwner = \OC_User::getUser();
     $shareWithinGroupOnly = self::shareWithGroupMembersOnly();
     $l = \OC_L10N::get('lib');
     if (is_null($itemSourceName)) {
         $itemSourceName = $itemSource;
     }
     // check if file can be shared
     if ($itemType === 'file' or $itemType === 'folder') {
         $path = \OC\Files\Filesystem::getPath($itemSource);
         // verify that the file exists before we try to share it
         if (!$path) {
             $message = 'Sharing %s failed, because the file does not exist';
             $message_t = $l->t('Sharing %s failed, because the file does not exist', array($itemSourceName));
             \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName), \OC_Log::ERROR);
             throw new \Exception($message_t);
         }
         // verify that the user has share permission
         if (!\OC\Files\Filesystem::isSharable($path)) {
             $message = 'You are not allowed to share %s';
             $message_t = $l->t('You are not allowed to share %s', array($itemSourceName));
             \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName), \OC_Log::ERROR);
             throw new \Exception($message_t);
         }
     }
     //verify that we don't share a folder which already contains a share mount point
     if ($itemType === 'folder') {
         $path = '/' . $uidOwner . '/files' . \OC\Files\Filesystem::getPath($itemSource) . '/';
         $mountManager = \OC\Files\Filesystem::getMountManager();
         $mounts = $mountManager->findIn($path);
         foreach ($mounts as $mount) {
             if ($mount->getStorage()->instanceOfStorage('\\OCA\\Files_Sharing\\ISharedStorage')) {
                 $message = 'Sharing "' . $itemSourceName . '" failed, because it contains files shared with you!';
                 \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR);
                 throw new \Exception($message);
             }
         }
     }
     // single file shares should never have delete permissions
     if ($itemType === 'file') {
         $permissions = (int) $permissions & ~\OCP\PERMISSION_DELETE;
     }
     // Verify share type and sharing conditions are met
     if ($shareType === self::SHARE_TYPE_USER) {
         if ($shareWith == $uidOwner) {
             $message = 'Sharing %s failed, because the user %s is the item owner';
             $message_t = $l->t('Sharing %s failed, because the user %s is the item owner', array($itemSourceName, $shareWith));
             \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName, $shareWith), \OC_Log::ERROR);
             throw new \Exception($message_t);
         }
         if (!\OC_User::userExists($shareWith)) {
             $message = 'Sharing %s failed, because the user %s does not exist';
             $message_t = $l->t('Sharing %s failed, because the user %s does not exist', array($itemSourceName, $shareWith));
             \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName, $shareWith), \OC_Log::ERROR);
             throw new \Exception($message_t);
         }
         if ($shareWithinGroupOnly) {
             $inGroup = array_intersect(\OC_Group::getUserGroups($uidOwner), \OC_Group::getUserGroups($shareWith));
             if (empty($inGroup)) {
                 $message = 'Sharing %s failed, because the user ' . '%s is not a member of any groups that %s is a member of';
                 $message_t = $l->t('Sharing %s failed, because the user %s is not a member of any groups that %s is a member of', array($itemSourceName, $shareWith, $uidOwner));
                 \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName, $shareWith, $uidOwner), \OC_Log::ERROR);
                 throw new \Exception($message_t);
             }
         }
         // Check if the item source is already shared with the user, either from the same owner or a different user
         if ($checkExists = self::getItems($itemType, $itemSource, self::$shareTypeUserAndGroups, $shareWith, null, self::FORMAT_NONE, null, 1, true, true)) {
             // Only allow the same share to occur again if it is the same
             // owner and is not a user share, this use case is for increasing
             // permissions for a specific user
             if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) {
                 $message = 'Sharing %s failed, because this item is already shared with %s';
                 $message_t = $l->t('Sharing %s failed, because this item is already shared with %s', array($itemSourceName, $shareWith));
                 \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName, $shareWith), \OC_Log::ERROR);
                 throw new \Exception($message_t);
             }
         }
     } else {
         if ($shareType === self::SHARE_TYPE_GROUP) {
             if (!\OC_Group::groupExists($shareWith)) {
                 $message = 'Sharing %s failed, because the group %s does not exist';
                 $message_t = $l->t('Sharing %s failed, because the group %s does not exist', array($itemSourceName, $shareWith));
                 \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName, $shareWith), \OC_Log::ERROR);
                 throw new \Exception($message_t);
             }
             if ($shareWithinGroupOnly && !\OC_Group::inGroup($uidOwner, $shareWith)) {
                 $message = 'Sharing %s failed, because ' . '%s is not a member of the group %s';
//.........这里部分代码省略.........
开发者ID:WYSAC,项目名称:oregon-owncloud,代码行数:101,代码来源:share.php

示例4: isSharable

 /**
  * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  */
 public static function isSharable($path)
 {
     return \OC\Files\Filesystem::isSharable($path);
 }
开发者ID:omusico,项目名称:isle-web-framework,代码行数:7,代码来源:filesystem.php

示例5: getDirPermissions

 /**
  * 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;
 }
开发者ID:hjimmy,项目名称:owncloud,代码行数:22,代码来源:helper.php

示例6: array

$list->assign('downloadURL', OCP\Util::linkToRoute('download', array('file' => '/')));
$list->assign('disableSharing', false);
$breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', '');
$breadcrumbNav->assign('breadcrumb', $breadcrumb);
$breadcrumbNav->assign('baseURL', OCP\Util::linkTo('files', 'index.php') . '?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;
}
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());
开发者ID:CDN-Sparks,项目名称:owncloud,代码行数:31,代码来源:index.php

示例7: shareLinks

 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  * @SSOCORS
  */
 public function shareLinks($files, $password = null, $expiration = null)
 {
     $shareLinkUrls = array();
     for ($i = 0; $i < sizeof($files); $i++) {
         $type = $files[$i]['type'];
         $id = $files[$i]['id'];
         $name = $files[$i]['name'];
         $permissions = 1;
         $path = \OC\Files\Filesystem::getPath($id);
         if ($path === null) {
             $shareLinkUrls[$i]['name'] = $name;
             $shareLinkUrls[$i]['url'] = null;
             $shareLinkUrls[$i]['id'] = $id;
             $shareLinkUrls[$i]['type'] = $type;
             if ($type == 'file') {
                 $shareLinkUrls[$i]['message'] = self::msg_idNotExist;
             } else {
                 $replacement = '${1}folder${3}';
                 $msg_idNotExist = preg_replace($this->fileTypePattern, $replacement, self::msg_idNotExist);
                 $shareLinkUrls[$i]['message'] = $msg_idNotExist;
             }
             continue;
         }
         if (\OC\Files\Filesystem::filetype($path) !== $type) {
             $shareLinkUrls[$i]['name'] = $name;
             $shareLinkUrls[$i]['url'] = null;
             $shareLinkUrls[$i]['id'] = $id;
             $shareLinkUrls[$i]['type'] = $type;
             $replacement = '${1}\'' . $type . '\'${3}' . $name . '(' . $id . ')';
             $msg_errorType = preg_replace($this->errorTypePattern, $replacement, self::msg_errorType);
             $shareLinkUrls[$i]['message'] = $msg_errorType;
             continue;
         }
         if (!\OC\Files\Filesystem::isSharable($path)) {
             $shareLinkUrls[$i]['name'] = $name;
             $shareLinkUrls[$i]['url'] = null;
             $shareLinkUrls[$i]['id'] = $id;
             $shareLinkUrls[$i]['type'] = $type;
             if ($type == 'file') {
                 $shareLinkUrls[$i]['message'] = self::msg_unreshareable;
             } else {
                 $replacement = '${1}folder${3}';
                 $msg_unreshareable = preg_replace($this->fileTypePattern, $replacement, self::msg_unreshareable);
                 $shareLinkUrls[$i]['message'] = $msg_unreshareable;
             }
             continue;
         }
         if ($type == 'dir') {
             $type = 'folder';
         }
         $passwordChanged = $password !== null;
         $token = \OCP\Share::shareItem($type, $id, $this->shareType, $password, $permissions, $name, !empty($expiration) ? new \DateTime((string) $expiration) : null, $passwordChanged);
         if ($type == 'folder') {
             $type = 'dir';
         }
         $url = self::generateShareLink($token);
         $shareLinkUrls[$i]['name'] = $name;
         $shareLinkUrls[$i]['url'] = $url;
         $shareLinkUrls[$i]['id'] = $id;
         $shareLinkUrls[$i]['type'] = $type;
     }
     json_encode($shareLinkUrls, JSON_PRETTY_PRINT);
     return new DataResponse(array('data' => $shareLinkUrls, 'status' => 'success'));
 }
开发者ID:inwinstack,项目名称:owncloud-singlesignon,代码行数:69,代码来源:collaborationapicontroller.php


注:本文中的OC\Files\Filesystem::isSharable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。