Ejemplo n.º 1
0
 /**
  * 是否能被共享
  * @param array $sharePaths    - 数组,有包含user_id的path组成
  * @param string $path         - 包含user_id的path
  * @return bool
  */
 public function canShared($sharePaths, $path)
 {
     $paths = CUtils::assemblyPaths($path);
     $keys = array_keys($paths);
     if (count($keys) > 0) {
         unset($paths[$keys[0]]);
     }
     //
     // 检查path,如果存在于$paths中则父目录存在共享
     //
     foreach ($sharePaths as $k => $sharePath) {
         if (isset($paths[$sharePath])) {
             return false;
         }
     }
     //
     // 检查子目录是否存在共享,如果存在则返回false
     //
     $path .= '/';
     foreach ($sharePaths as $k => $sharePath) {
         if (strpos($sharePath, $path) === 0) {
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  *
  * 根据id检查是否是共享目录
  */
 public function handlerCheckById($userId, $id)
 {
     $this->stop = 0;
     $file = MiniFile::getInstance()->getById($id);
     if ($file === NULL) {
         return false;
     }
     $this->tmp_file = $file;
     $paths = CUtils::assemblyPaths($file['file_path']);
     $keys = array_keys($paths);
     // 去掉 /{user_id}
     if (count($keys) > 0) {
         unset($paths[$keys[0]]);
     }
     $access = new SharesAccessFilter();
     $sharePaths = $access->handleGetAllSharesFolder($userId);
     $sharedPath = '';
     foreach ($sharePaths as $sharePath) {
         if (isset($paths[$sharePath])) {
             $sharedPath = $sharePath;
         }
     }
     $meta = MiniFileMeta::getInstance()->getFileMeta($sharedPath, 'shared_folders');
     if ($meta === NULL) {
         return false;
     }
     $meta_value = unserialize($meta['meta_value']);
     $slaves = $meta_value['slaves'];
     if ($userId === $meta_value['master']) {
         return $file;
     }
     if (!isset($slaves[$userId])) {
         return false;
     }
     $this->_file = UserFile::model()->findByAttributes(array('file_path' => $slaves[$userId]));
     if ($file['file_type'] == 3 || $file['file_type'] == 4) {
         $file = UserFile::model()->findByAttributes(array('file_path' => $meta_value['path']));
         $this->stop = $file['parent_file_id'];
     } elseif ($file['file_type'] == 2) {
         $this->stop = $file['parent_file_id'];
     } else {
         $share = UserFile::model()->findByAttributes(array('file_path' => $meta_value['path']));
         if ($share) {
             $this->stop = $share['parent_file_id'];
         }
     }
     return $file;
 }