/** * 静态方法, 单例统一访问入口 * @return object 返回对象的唯一实例 */ public static function getInstance() { if (is_null(self::$_instance) || !isset(self::$_instance)) { self::$_instance = new self(); } return self::$_instance; }
/** * 获取events数据 */ public function getList($path, $time, $deviceUuid, $pageSize, $currentPage) { $user = $this->user; $userId = $user['id']; $time = $this->getTime($time); if ($path != "") { $path = MiniUtil::joinPath($path); } $total = MiniEvent::getInstance()->getTotal($path, $time, $userId, $deviceUuid); $totalPage = ceil($total / $pageSize); $events = MiniEvent::getInstance()->getByCondition($path, $userId, $time, $deviceUuid, $pageSize, ($currentPage - 1) * $pageSize); $itemList = array(); $data = array(); foreach ($events as $event) { $item = array(); $device = MiniUserDevice::getInstance()->getUserDevice($event['user_device_id']); $item['create_user_id'] = $device['user_id']; $item['file_path'] = MiniUtil::getRelativePath($event['file_path']); $item['action'] = $event['action']; $item['user_name'] = $user['user_name']; $item['user_device_type'] = $device['user_device_type']; if ($device['user_id'] == $userId) { $item['user_self'] = true; } else { $item['user_self'] = false; $user = MiniUser::getInstance()->getById($device['user_id']); $userMetas = MiniUserMeta::getInstance()->getUserMetas($device['user_id']); if (isset($userMetas['nick'])) { $item['user_name'] = $userMetas['nick']; } else { $item['user_name'] = $user['user_name']; } } $item['created_at'] = MiniUtil::formatTime(strtotime($event['created_at'])); $item['user_device_name'] = $device['user_device_name']; $item['context'] = MiniUtil::getRelativePath($event['context']); $item['device_uuid'] = $device['user_device_uuid']; if ($event['action'] == 2) { //判断是否是重命名还是创建 $fromParent = CUtils::pathinfo_utf($event['file_path']); $toParent = CUtils::pathinfo_utf($event['context']); if ($fromParent['dirname'] == $toParent['dirname']) { $item['action'] = MConst::RENAME; } } $itemList[] = $item; } $data['events'] = $itemList; $data['totalPage'] = $totalPage; return $data; }
public function saveSortType($type, $sortOrder) { $user = $this->user; $metas['extend'] = ['file_sort_type' => $type, 'file_sort_order' => $sortOrder]; return MiniUserMeta::getInstance()->create($user, $metas); }
/** * 分页所有用户列表 */ public function ajaxGetAdmins($currentPage, $pageSize) { $criteria = new CDbCriteria(); $criteria->order = "-id"; $items = User::model()->findAll($criteria); $total = User::model()->count($criteria); $arr = array(); foreach ($items as $item) { $metas = MiniUserMeta::getInstance()->getUserMetas($item["id"]); foreach ($metas as $key => $value) { if ($key === "is_admin" && $value === "1") { array_push($arr, $item); } } } array_slice($arr, ($currentPage - 1) * $pageSize, $pageSize); $data = array(); $data['total'] = count($arr); $data['list'] = $this->db2list($arr); if ($total == 0) { return null; } else { return $data; } }
/** * 转换隐藏文件名单状态 */ public function updateFileHideStatus($filePath, $isHide) { $data = array(); $meta = array(); $extends = array(); $userId = $this->user['id']; $userMetaData = MiniUserMeta::getInstance()->getUserMetas($userId); if ($isHide == "true") { if (empty($userMetaData['user_hide_path'])) { array_push($data, $filePath); } else { $data = unserialize($userMetaData['user_hide_path']); array_push($data, $filePath); } } else { $data = unserialize($userMetaData['user_hide_path']); $key = array_search($filePath, $data); unset($data[$key]); } $extends['user_hide_path'] = serialize($data); $meta['extend'] = $extends; MiniUserMeta::getInstance()->create($this->user, $meta); return true; }
/** * 根据用户名+密码查询账号是否在LDAP服务器中 * @param string $userName * @param string $password * @return array|bool */ function getMember($userName, $password) { $ldapWhiteListOpen = MiniOption::getInstance()->getOptionValue('ldap_white_list_open'); $ldapPrimaryKey = MiniOption::getInstance()->getOptionValue('ldap_primary_key'); $ldapNick = MiniOption::getInstance()->getOptionValue('ldap_nick'); if ($ldapWhiteListOpen == 'true') { $user = MiniUser::getInstance()->getUserByName($userName); if (empty($user)) { $this->code = -2; return false; } } $ldapUsrDom = "@" . $this->getHost(); $userName = str_replace($ldapUsrDom, "", $userName); $ldapConn = @ldap_connect($this->host, $this->port); if (!$ldapConn) { $this->code = -1; #服务器无法连接 return false; } @ldap_set_option($ldapConn, LDAP_OPT_PROTOCOL_VERSION, 3); @ldap_set_option($ldapConn, LDAP_OPT_REFERRALS, 0); $user = MiniUser::getInstance()->getUserByName($userName); $userId = $user['user_id']; $userMeta = MiniUserMeta::getInstance()->getUserMetas($userId); $userDn = $userMeta['dn']; $loginResult = @ldap_bind($ldapConn, iconv('utf-8', $this->coding, $userDn), $password); //验证账号与密码 if (!$loginResult) { $this->code = -2; #测试帐号与密码错误 return false; } $dn = $this->filter; $attrItems = array("ou", "sn", "mail", "telephonenumber", $ldapNick, "department"); $query = $ldapPrimaryKey . "=" . $userName; $results = @ldap_search($ldapConn, $dn, $query, $attrItems); $entries = @ldap_get_entries($ldapConn, $results); if ($entries['count'] == 0) { $this->code = -2; #测试帐号与密码错误 return false; } $output = array(); $extend = array(); $extend["nick"] = $userName; $output["user_name"] = $userName; if ($entries['count'] != 0) { $entries = @ldap_get_entries($ldapConn, $results); array_shift($entries); if (count($entries) > 0) { //获得更加详细的信息 $entry = $entries[0]; $phoneInfo = $this->getValue("telephonenumber", $entry); //获得电话号码 if ($phoneInfo != null) { $extend["phone"] = $phoneInfo; } $displayNameInfo = $this->getValue($ldapNick, $entry); //获得昵称与全名 if ($displayNameInfo != null) { $extend["nick"] = $displayNameInfo; } else { $extend["nick"] = $userName; } $mailInfo = $this->getValue("mail", $entry); //获得电子邮件 if ($mailInfo != null) { $extend["email"] = $mailInfo; } if ($this->syncDepartment != 'false') { $department = $this->getValue("dn", $entry); //获得昵称与全名 if ($department != null) { $departmentInfo = $this->getDevelopment($department); if (!empty($departmentInfo)) { $output['departmentData'][0][] = $departmentInfo; $output['departmentData'][0][] = $userName; } } } } } $output["extend"] = $extend; ldap_close($ldapConn); return $output; }
/** * 处理根目录下文件查询 * @param $includeDeleted * @return array */ private function handleRootPath($includeDeleted) { $response = array(); $response["size"] = MUtils::getSizeByLocale($this->locale, 0); $response["bytes"] = 0; $response["path"] = "/"; $response["modified"] = MUtils::formatIntTime(time()); $response["revision"] = 0; $response["rev"] = "0"; $response["root"] = $this->root; $response["is_deleted"] = false; $response["is_dir"] = true; $response["hash"] = ""; $contents = array(); $user = MUserManager::getInstance()->getCurrentUser(); $publicFiles = MiniFile::getInstance()->getPublics(); $groupShareFiles = MiniGroupPrivilege::getInstance()->getAllGroups(); $userShareFiles = MiniUserPrivilege::getInstance()->getAllUserPrivilege($user["id"]); $filePaths = array(); $shareFiles = array_merge($publicFiles, $groupShareFiles, $userShareFiles); $userFiles = MiniFile::getInstance()->getChildrenByFileID($parentFileId = 0, $includeDeleted, $user, $this->userId); $fileData = array_merge($shareFiles, $userFiles); //如果没有文件记录 if (empty($publicFiles) && empty($shareFiles) && empty($userFiles)) { $response["contents"] = $contents; return $response; } foreach ($fileData as $file) { $file = MiniFile::getInstance()->getByPath($file['file_path']); if (!empty($file)) { if ($file['parent_file_id'] == 0 && $file['is_deleted'] == 0 || $file['file_type'] == 2 && $file['user_id'] != $this->userId) { $filePaths[] = $file['file_path']; } } } $filePaths = array_unique($filePaths); $userMetaData = MiniUserMeta::getInstance()->getUserMetas($this->userId); $userHidePaths = ''; if (!empty($userMetaData['user_hide_path'])) { $userHidePaths = unserialize($userMetaData['user_hide_path']); } // 组装子文件数据 foreach ($filePaths as $filePath) { $file = MiniFile::getInstance()->getByFilePath($filePath); $item = array(); $version = MiniVersion::getInstance()->getVersion($file["version_id"]); $mimeType = null; $signature = null; if ($version != NULL) { $mimeType = $version["mime_type"]; $signature = $version["file_signature"]; $file["signature"] = $signature; } $item = $this->assembleResponse($item, $file, $mimeType); if (!empty($item)) { if (in_array($filePath, $userHidePaths)) { $item['is_hide_path'] = true; } else { $item['is_hide_path'] = false; } array_push($contents, $item); } } $response["contents"] = $contents; return $response; }
/** * @param $id * @param $phone * @param $real_name * @param $qq * @param $website * @param $space * @param $memo */ public function updateMoreInformation($id, $phone, $real_name, $qq, $website, $memo) { $metas = MiniUserMeta::getInstance()->getUserMetas($id); $user = MiniUser::getInstance()->getUser($id); foreach ($metas as $key => $value) { if ($key === "space") { $metas["space"] = $metas["space"] / 1024 / 1024; } } $metas['phone'] = $phone; $metas['realname'] = $real_name; $metas['qq'] = $qq; $metas['website'] = $website; $metas['memo'] = $memo; $userMetas = array(); $userMetas['extend'] = $metas; MiniUserMeta::getInstance()->create($user, $userMetas); return true; }