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


PHP Util::linkToPublic方法代码示例

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


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

示例1: createShare

 /**
  * create a new share
  * @param array $params
  * @return \OC_OCS_Result
  */
 public static function createShare($params)
 {
     $path = isset($_POST['path']) ? $_POST['path'] : null;
     if ($path === null) {
         return new \OC_OCS_Result(null, 400, "please specify a file or folder path");
     }
     $itemSource = self::getFileId($path);
     $itemType = self::getItemType($path);
     if ($itemSource === null) {
         return new \OC_OCS_Result(null, 404, "wrong path, file/folder doesn't exist.");
     }
     $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null;
     $shareType = isset($_POST['shareType']) ? (int) $_POST['shareType'] : null;
     switch ($shareType) {
         case \OCP\Share::SHARE_TYPE_USER:
             $permissions = isset($_POST['permissions']) ? (int) $_POST['permissions'] : 31;
             break;
         case \OCP\Share::SHARE_TYPE_GROUP:
             $permissions = isset($_POST['permissions']) ? (int) $_POST['permissions'] : 31;
             break;
         case \OCP\Share::SHARE_TYPE_LINK:
             //allow password protection
             $shareWith = isset($_POST['password']) ? $_POST['password'] : null;
             //check public link share
             $publicUploadEnabled = \OC::$server->getAppConfig()->getValue('core', 'shareapi_allow_public_upload', 'yes');
             if (isset($_POST['publicUpload']) && $publicUploadEnabled !== 'yes') {
                 return new \OC_OCS_Result(null, 403, "public upload disabled by the administrator");
             }
             $publicUpload = isset($_POST['publicUpload']) ? $_POST['publicUpload'] : 'false';
             // read, create, update (7) if public upload is enabled or
             // read (1) if public upload is disabled
             $permissions = $publicUpload === 'true' ? 7 : 1;
             break;
         default:
             return new \OC_OCS_Result(null, 400, "unknown share type");
     }
     try {
         $token = \OCP\Share::shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions);
     } catch (\Exception $e) {
         return new \OC_OCS_Result(null, 403, $e->getMessage());
     }
     if ($token) {
         $data = array();
         $data['id'] = 'unknown';
         $shares = \OCP\Share::getItemShared($itemType, $itemSource);
         if (is_string($token)) {
             //public link share
             foreach ($shares as $share) {
                 if ($share['token'] === $token) {
                     $data['id'] = $share['id'];
                     break;
                 }
             }
             $url = \OCP\Util::linkToPublic('files&t=' . $token);
             $data['url'] = $url;
             // '&' gets encoded to $amp;
             $data['token'] = $token;
         } else {
             foreach ($shares as $share) {
                 if ($share['share_with'] === $shareWith && $share['share_type'] === $shareType) {
                     $data['id'] = $share['id'];
                     break;
                 }
             }
         }
         return new \OC_OCS_Result($data);
     } else {
         return new \OC_OCS_Result(null, 404, "couldn't share file");
     }
 }
开发者ID:heldernl,项目名称:owncloud8-extended,代码行数:75,代码来源:local.php


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