Commit df315f82 by huanghuasheng

添加

parents
Showing with 4831 additions and 0 deletions

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

{
"presets": [
["env", {
"targets": {
"node": "6.10",
"browsers": [
"last 2 versions",
"not ie <= 8"
]
}
}],
"stage-2"
],
"plugins": [
["component", [{
"libraryName": "element-ui",
"styleLibraryName": "theme-chalk"
}]]
]
}
version: 2
jobs:
front_end:
working_directory: ~/plus
docker:
- image: circleci/node:10
steps:
- checkout
- run:
name: "Install Dependencies"
command: "npm install"
- run:
name: "Rebuild node-sass"
command: "npm rebuild node-sass --force"
- run:
name: "Run Production"
command: "npm run production"
back_end:
working_directory: ~/plus
docker:
- image: circleci/php:7.1-jessie-node-browsers
- image: circleci/mysql:5.7-ram
environment:
MYSQL_DATABASE: plus
steps:
- checkout
- restore_cache:
keys:
- dependencies-{{ checksum "composer.json" }}
- run:
name: "Install Dependencies"
command: "composer install"
- save_cache:
key: dependencies-{{ checksum "composer.json" }}
paths:
- vendor
- run:
name: "Generate Keys"
command: "php artisan app:key-generate --env=circleci"
- run:
name: "Run Database Migrate"
command: "php artisan migrate --env=circleci -vvv"
- run:
name: "Run Database Seeder"
command: "php artisan db:seed --env=circleci -vvv"
- run:
name: "Run Tests"
command: "php vendor/bin/phpunit --coverage-clover=coverage.xml"
- run:
name: "Publish Coverage To Codacy"
command: "php vendor/bin/codacycoverage clover coverage.xml"
- run:
name: "Publish Codecov"
command: "bash <(curl -s https://codecov.io/bash)"
workflows:
version: 2
all:
jobs:
- front_end:
filters:
branches:
ignore:
- gh-pages
- docs
# - back_end
---
exclude_paths:
- config
- database
- docs
- packages/*/assets
- packages/*/config
- packages/*/database
- packages/*/resources
- packages/*/routes
- packages/*/tests
- public
- resources
- routes
- storage
- tests
- vendor
.docker
.git
.github
node_modules
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
[*.yml]
indent_size = 2
[*.{js,jsx,vue}]
indent_style = space
indent_size = 2
* text=auto
packages/*/assets/* linguist-vendored
packages/*/resource/* linguist-vendored
public/assets/* linguist-vendored
CHANGELOG.md export-ignore
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at shiweidu@outlook.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
# Contribute
## Introduction
First, thank you for considering contributing to thinksns-plus! It's people like you that make the open source community such a great community! 😊
We welcome any type of contribution, not only code. You can help with
- **QA**: file bug reports, the more details you can give the better (e.g. screenshots with the console open)
- **Marketing**: writing blog posts, howto's, printing stickers, ...
- **Community**: presenting the project at meetups, organizing a dedicated meetup for the local community, ...
- **Code**: take a look at the [open issues](issues). Even if you can't write code, commenting on them, showing that you care about a given issue matters. It helps us triage them.
- **Money**: we welcome financial contributions in full transparency on our [open collective](https://opencollective.com/thinksns-plus).
## Your First Contribution
Working on your first Pull Request? You can learn how from this *free* series, [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github).
## Submitting code
Any code change should be submitted as a pull request. The description should explain what the code does and give steps to execute it. The pull request should also contain tests.
## Code review process
The bigger the pull request, the longer it will take to review and merge. Try to break down large pull requests in smaller chunks that are easier to review and merge.
It is also always helpful to have some context for your pull request. What was the purpose? Why does it matter to you?
## Financial contributions
We also welcome financial contributions in full transparency on our [open collective](https://opencollective.com/thinksns-plus).
Anyone can file an expense. If the expense makes sense for the development of the community, it will be "merged" in the ledger of our open collective by the core contributors and the person who filed the expense will be reimbursed.
## Questions
If you have any questions, create an [issue](issue) (protip: do a quick search first to see if someone else didn't ask the same question before!).
You can also reach us at shiweidu@outlook.com.
## Credits
### Contributors
Thank you to all the people who have already contributed to thinksns-plus!
<a href="https://github.com/slimkit/thinksns-plus/graphs/contributors"><img src="https://opencollective.com/thinksns-plus/contributors.svg?width=890" /></a>
### Backers
Thank you to all our backers! [[Become a backer](https://opencollective.com/thinksns-plus#backer)]
<a href="https://opencollective.com/thinksns-plus#backers" target="_blank"><img src="https://opencollective.com/thinksns-plus/backers.svg?width=890"></a>
### Sponsors
Thank you to all our sponsors! (please ask your company to also support this open source project by [becoming a sponsor](https://opencollective.com/thinksns-plus#sponsor))
<a href="https://opencollective.com/thinksns-plus/sponsor/0/website" target="_blank"><img src="https://opencollective.com/thinksns-plus/sponsor/0/avatar.svg"></a>
<a href="https://opencollective.com/thinksns-plus/sponsor/1/website" target="_blank"><img src="https://opencollective.com/thinksns-plus/sponsor/1/avatar.svg"></a>
<a href="https://opencollective.com/thinksns-plus/sponsor/2/website" target="_blank"><img src="https://opencollective.com/thinksns-plus/sponsor/2/avatar.svg"></a>
<a href="https://opencollective.com/thinksns-plus/sponsor/3/website" target="_blank"><img src="https://opencollective.com/thinksns-plus/sponsor/3/avatar.svg"></a>
<a href="https://opencollective.com/thinksns-plus/sponsor/4/website" target="_blank"><img src="https://opencollective.com/thinksns-plus/sponsor/4/avatar.svg"></a>
<a href="https://opencollective.com/thinksns-plus/sponsor/5/website" target="_blank"><img src="https://opencollective.com/thinksns-plus/sponsor/5/avatar.svg"></a>
<a href="https://opencollective.com/thinksns-plus/sponsor/6/website" target="_blank"><img src="https://opencollective.com/thinksns-plus/sponsor/6/avatar.svg"></a>
<a href="https://opencollective.com/thinksns-plus/sponsor/7/website" target="_blank"><img src="https://opencollective.com/thinksns-plus/sponsor/7/avatar.svg"></a>
<a href="https://opencollective.com/thinksns-plus/sponsor/8/website" target="_blank"><img src="https://opencollective.com/thinksns-plus/sponsor/8/avatar.svg"></a>
<a href="https://opencollective.com/thinksns-plus/sponsor/9/website" target="_blank"><img src="https://opencollective.com/thinksns-plus/sponsor/9/avatar.svg"></a>
<!-- This `CONTRIBUTING.md` is based on @nayafia's template https://github.com/nayafia/contributing-template -->
\ No newline at end of file
---
name: Bug report
about: Create a report to help us improve
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
**Additional context**
Add any other context about the problem here.
---
name: Feature request
about: Suggest an idea for this project
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.
### 这是一个什么 PR ?
- [ ] Bug 修复
- [ ] 需求提交
### 适用于哪个版本?
Plus 的维护策略为短期维护最近发布的三个中版本分支!如果早期存在的 bug 也是在最底端分支修复,功能需求提交直接进入 master 分支或者 PR 专属等待分支!
适合版本为:
### 请描述你的 PR
.idea
.DS_Store
.vscode
.vagrant
.plus.yml
composer.lock
yarn.lock
yarn-error.log
npm-debug.log
jpush.log
/config/component.php
/config/component_routes.php
/config/providers.php
/node_modules
/public/hot
/public/storage
/storage/*.key
/vendor
/resources/views/vendor
/.idea
/.vscode
/nbproject
/.vagrant
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
.env
.phpunit.result.cache
// https://github.com/michael-ciniawsky/postcss-load-config
module.exports = {
"plugins": {
// to edit target browsers: use "browserlist" field in package.json
"autoprefixer": {}
}
}
#
# StyleCI bot config file.
# @link https://styleci.readme.io/docs
#
# 修复等级
# psr1, psr2, symfony, laravel, recommended
# 按照规范严格程度排列。
preset: laravel
# 是否启用危险的修复
# true | false
risky: false
sudo: false
branches:
except:
- gh-pages
language: php
php:
- 7.1.3 # 必须构建最低要求版本
- 7.1
- 7.2
- 7.3
env:
- DB=mysql
- DB=postgres
services:
- mysql
- postgres
cache:
directories:
- $HOME/.composer/cache
before_install:
# Check and create database.
- sh -c "if [ '$DB' = 'postgres' ]; then psql -c 'create database plus;' -U postgres; echo $DB; fi"
- sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'CREATE DATABASE IF NOT EXISTS plus;'; echo $DB; fi"
- php ./scripts/travis-ci-settings.php $DB
install:
- composer install
- php artisan app:key-generate
- php artisan migrate -vvv
- php artisan db:seed -vvv
- php artisan vendor:publish --all -vvv
script: php vendor/bin/phpunit --coverage-clover=coverage.xml
after_script:
- php vendor/bin/codacycoverage clover coverage.xml
- bash <(curl -s https://codecov.io/bash)
jobs:
include:
- stage: Build
name: Build Assets Test
language: node_js
node_js: 6
cache:
directories:
- "node_modules"
services: null
env: null
before_install: null
install: npm install
script: npm run dev
after_script: null
# [2.3.0](https://github.com/slimkit/plus/compare/2.2.3...2.3.0) (2019-03-07)
### Refactor
- 重构消息通知系统
- 重构 SPA 多个页面
## [2.2.3](https://github.com/slimkit/plus/compare/2.2.2...2.2.3) (2019-03-07)
### Bug Fixes
* **动态:** 修复动态热门话题报错 fix [#586](https://github.com/slimkit/plus/issues/586) ([a6b49ae](https://github.com/slimkit/plus/commit/a6b49ae))
* **动态:** 修复动态热门话题报错 fix [#586](https://github.com/slimkit/plus/issues/586) ([69be235](https://github.com/slimkit/plus/commit/69be235))
* **动态:** 修复动态热门话题报错 fix [#586](https://github.com/slimkit/plus/issues/586) ([d47e3dd](https://github.com/slimkit/plus/commit/d47e3dd))
* **Admin:** 修复后台动态管理预览动态图片非原本动态图片 Bug ([da22ac9](https://github.com/slimkit/plus/commit/da22ac9)), closes [#624](https://github.com/slimkit/plus/issues/624)
* **IM:** 修复未使用环信情况下后台更新用户资料永远都会失败问题 ([155005a](https://github.com/slimkit/plus/commit/155005a))
* **News:** 兼容 PC 需要获取置顶用户信息需求 ([cfbc299](https://github.com/slimkit/plus/commit/cfbc299))
* **PC:** 动图识别的问题 ([035520a](https://github.com/slimkit/plus/commit/035520a))
* **PC:** 系统消息类型 ([96a6090](https://github.com/slimkit/plus/commit/96a6090))
* **PC:** 修补消息类型 ([b003e45](https://github.com/slimkit/plus/commit/b003e45))
* **PC:** 修复开源版圈子页面报错的问题 ([b9a65cd](https://github.com/slimkit/plus/commit/b9a65cd))
* **PC:** 修复全局评论时没有自动添加评论的问题 ([26284d0](https://github.com/slimkit/plus/commit/26284d0)), closes [#629](https://github.com/slimkit/plus/issues/629)
* **PC:** 修复帖子的图片 mime 解析错误的问题 ([f3c57b2](https://github.com/slimkit/plus/commit/f3c57b2))
* **PC:** 修复系统消息被拒绝的状态 ([cab0119](https://github.com/slimkit/plus/commit/cab0119))
* **PC:** 在个人主页转发动态时会添加到其他人个人主页时间线中的问题 ([5faf023](https://github.com/slimkit/plus/commit/5faf023)), closes [#628](https://github.com/slimkit/plus/issues/628)
* **SPA:** 参与话题的人数据错误的问题 ([0049580](https://github.com/slimkit/plus/commit/0049580))
* **SPA:** 定位后保存当前位置信息到服务器 ([1eb93c0](https://github.com/slimkit/plus/commit/1eb93c0)), closes [#480](https://github.com/slimkit/plus/issues/480)
* **SPA:** 动图不能播放的问题 ([06bcd3d](https://github.com/slimkit/plus/commit/06bcd3d))
* **SPA:** 发起聊天时跳转到错误的路由的问题 ([9565f01](https://github.com/slimkit/plus/commit/9565f01))
* **SPA:** 解决安卓微信下无法上传图片的问题(hack) ([b390b44](https://github.com/slimkit/plus/commit/b390b44))
* **SPA:** 解决安卓微信下无法上传图片的问题(hack) ([5840826](https://github.com/slimkit/plus/commit/5840826))
* **SPA:** 某些情况下弹起键盘框会导致字体重复的问题 ([72027c0](https://github.com/slimkit/plus/commit/72027c0))
* **SPA:** 容器最大宽度限制 ([2fa7978](https://github.com/slimkit/plus/commit/2fa7978))
* **SPA:** 头像引用路径不正常的问题 ([788002a](https://github.com/slimkit/plus/commit/788002a)), closes [#657](https://github.com/slimkit/plus/issues/657)
* **SPA:** 无时间时显示为 NaN 的问题 ([20fedea](https://github.com/slimkit/plus/commit/20fedea)), closes [#655](https://github.com/slimkit/plus/issues/655)
* **SPA:** 修补消息类型 ([5670f7d](https://github.com/slimkit/plus/commit/5670f7d))
* **SPA:** 修复动态列表出现两次的问题 ([82d2a27](https://github.com/slimkit/plus/commit/82d2a27))
* **SPA:** 修复合并代码后的一些问题 ([5a52f5d](https://github.com/slimkit/plus/commit/5a52f5d))
* **SPA:** 修复获取数据时数量传出10而判断为15的问题 ([673080c](https://github.com/slimkit/plus/commit/673080c))
* **SPA:** 修复如果资讯被打赏则无法显示系统消息的问题 ([77657be](https://github.com/slimkit/plus/commit/77657be)), closes [#654](https://github.com/slimkit/plus/issues/654)
* **SPA:** 修复头像为空时会报错的问题 ([570691a](https://github.com/slimkit/plus/commit/570691a))
* **SPA:** 修复未读消息小红点提示 ([94a7606](https://github.com/slimkit/plus/commit/94a7606)), closes [#529](https://github.com/slimkit/plus/issues/529)
* **SPA:** 修复未读消息小红点提示 ([e69e6e8](https://github.com/slimkit/plus/commit/e69e6e8)), closes [#529](https://github.com/slimkit/plus/issues/529)
* **SPA:** 修复未读消息小红点提示 ([74dd0c1](https://github.com/slimkit/plus/commit/74dd0c1)), closes [#529](https://github.com/slimkit/plus/issues/529)
* **SPA:** 修复系统消息文本不正确的问题 ([a4195d4](https://github.com/slimkit/plus/commit/a4195d4))
* **SPA:** 修复消息错误显示小红点 ([4dc0550](https://github.com/slimkit/plus/commit/4dc0550)), closes [#529](https://github.com/slimkit/plus/issues/529)
* **SPA:** 修复消息错误显示小红点 ([1e56725](https://github.com/slimkit/plus/commit/1e56725)), closes [#529](https://github.com/slimkit/plus/issues/529)
* **SPA:** 修复消息错误显示小红点 ([d8838fb](https://github.com/slimkit/plus/commit/d8838fb)), closes [#529](https://github.com/slimkit/plus/issues/529)
* **SPA:** 修复消息页面含有时间差的问题 ([f451ae0](https://github.com/slimkit/plus/commit/f451ae0))
* **SPA:** 修复在 hash 模式下无法微信登录的问题 ([5b5281c](https://github.com/slimkit/plus/commit/5b5281c))
* **SPA:** 修正动态卡片时间 ([b9ad1fc](https://github.com/slimkit/plus/commit/b9ad1fc))
* **SPA:** 修正动态卡片时间 ([c57333d](https://github.com/slimkit/plus/commit/c57333d))
* **SPA:** 一些翻译问题 ([0db0012](https://github.com/slimkit/plus/commit/0db0012))
* **SPA:** 一些翻译问题 ([af69326](https://github.com/slimkit/plus/commit/af69326))
* **SPA:** 移除多余符号 ([9e7a23b](https://github.com/slimkit/plus/commit/9e7a23b))
* **SPA:** 在每次进入聊天室或发送消息后清空未读聊天数量 ([c6091c0](https://github.com/slimkit/plus/commit/c6091c0))
* **SPA:** 直辖市的定位问题 ([2a9e44b](https://github.com/slimkit/plus/commit/2a9e44b))
* **SPA:** 资讯被打赏时无法正常显示消息预览的问题 ([a0dbd58](https://github.com/slimkit/plus/commit/a0dbd58)), closes [#654](https://github.com/slimkit/plus/issues/654)
* **SPA:** GIF -> Gif ([cbe870a](https://github.com/slimkit/plus/commit/cbe870a)), closes [#644](https://github.com/slimkit/plus/issues/644)
* 签到若未登录,不返回rank字段 ([f00c455](https://github.com/slimkit/plus/commit/f00c455))
* 转发时at用户没有反应的问题 ([9430f5c](https://github.com/slimkit/plus/commit/9430f5c))
* Fixed local CDN gif bepass ([ba50f4d](https://github.com/slimkit/plus/commit/ba50f4d))
### Features
* **动态:** 增加动态话题列表返回关注状态功能 ([0cd3f10](https://github.com/slimkit/plus/commit/0cd3f10))
* **Music:** Add a list songs API ([5342b4f](https://github.com/slimkit/plus/commit/5342b4f))
* **Music:** List api add multiple get ([925b85e](https://github.com/slimkit/plus/commit/925b85e)), closes [#625](https://github.com/slimkit/plus/issues/625)
* **PC:** 增加 ThinkSNS 下载二维码 ([8740301](https://github.com/slimkit/plus/commit/8740301))
* **PC:** 增加右侧在线咨询弹框 ([65f601f](https://github.com/slimkit/plus/commit/65f601f))
* **PC:** GIF 动图按顺序播放 ([0eb45d1](https://github.com/slimkit/plus/commit/0eb45d1))
* **SPA:** GIF 动图播放 ([69c7ac3](https://github.com/slimkit/plus/commit/69c7ac3))
* Add using Tags find users ([6035fdc](https://github.com/slimkit/plus/commit/6035fdc))
* **SPA:** 动态话题 ([157cf3a](https://github.com/slimkit/plus/commit/157cf3a)), closes [#467](https://github.com/slimkit/plus/issues/467)
* **SPA:** 多国语言文本替换 ([e015aec](https://github.com/slimkit/plus/commit/e015aec))
* **SPA:** 好友功能 ([6f53f4c](https://github.com/slimkit/plus/commit/6f53f4c))
* **SPA:** 增加 QQ 在线咨询可选功能 ([284fc35](https://github.com/slimkit/plus/commit/284fc35))
FROM php:7.2-fpm
# install the PHP extensions we need
RUN set -ex; \
pecl channel-update pecl.php.net; \
\
savedAptMark="$(apt-mark showmanual)"; \
\
apt-get update; \
apt-get install -y --no-install-recommends \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng-dev \
libxml2-dev \
libmemcached-dev \
zlib1g-dev \
; \
docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/; \
docker-php-ext-install -j$(nproc) iconv gd; \
docker-php-ext-install \
soap \
pdo_mysql \
zip \
mbstring \
opcache \
; \
pecl install channel://pecl.php.net/mcrypt-1.0.1; \
pecl install memcached; \
docker-php-ext-enable mcrypt; \
docker-php-ext-enable memcached; \
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
apt-mark auto '.*' > /dev/null; \
apt-mark manual $savedAptMark; \
ldd "$(php -r 'echo ini_get("extension_dir");')"/*.so \
| awk '/=>/ { print $3 }' \
| sort -u \
| xargs -r dpkg-query -S \
| cut -d: -f1 \
| sort -u \
| xargs -rt apt-mark manual; \
\
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
rm -rf /var/lib/apt/lists/*
# set recommended PHP.ini settings
# see https://secure.php.net/manual/en/opcache.installation.php
RUN { \
echo 'opcache.memory_consumption=128'; \
echo 'opcache.interned_strings_buffer=8'; \
echo 'opcache.max_accelerated_files=4000'; \
echo 'opcache.revalidate_freq=2'; \
echo 'opcache.fast_shutdown=1'; \
echo 'opcache.enable_cli=1'; \
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
# Install Composer
# see https://getcomposer.org/download/
RUN curl -s http://getcomposer.org/installer | php; \
echo "export PATH=${PATH}:/var/www/vendor/bin" >> ~/.bashrc; \
mv composer.phar /usr/local/bin/composer
## Load Plus(ThinkSNS+)
COPY . /usr/src/plus
RUN set -ex; \
rm -rf /var/www; \
mkdir /var/www; \
chown -R www-data:www-data /usr/src/plus; \
chown -R www-data:www-data /var/www
USER www-data
RUN set -ex; \
composer install \
--no-dev \
--optimize-autoloader \
--classmap-authoritative \
--ignore-platform-reqs \
--working-dir=/usr/src/plus
USER root
COPY docker-entrypoint.sh /usr/local/bin/
RUN set -ex; \
chmod -f +x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["docker-entrypoint.sh"]
WORKDIR /var/www
VOLUME /var/www
CMD ["php-fpm"]
ThinkSNS开源授权许可协议
感谢您选择 ThinkSNS(简称TS),ThinkSNS 专研 10 年致力于为用户提供全面的 SNS
社区软件系统产品源码及开发服务解决方案。
智士软件(北京)有限公司为ThinkSNS系统开发商,依法独立拥有ThinkSNS产品著作权(
中华人民共和国国家版权局著作权登记号 2011SR069454)。
智士软件(北京)有限公司网址为 http://www.zhishisoft.com,ThinkSNS 官方网站
网址为 http://www.thinksns.com。版权所有 (C) 2008-Present,智士软件(北京)
有限公司保留所有权利。
ThinkSNS著作权已在中华人民共和国国家版权局注册,著作权受到法律和国际公约保护。
使用者:无论个人或组织、营利与否、用途如何(包括以学习和研究为目的),均需仔细阅读
本文内容,理解、同意、并遵守本须知的全部条款,方可从官方渠道下载开源代码(视为默认
知悉),免费使用ThinkSNS开源代码。
智士软件(北京)有限公司拥有对本使用须知的最终解释权。
一、许可的权利
1、您可以在完全遵守本使用须知的基础上,将本软件应用于非商业用途、非营利性质
的社区建设,而不必支付软件授权费用;
2、您可以在官方规定的约束和限制范围内修改ThinkSNS开源代码或界面风格以适应您的网站要求;
3、您可以将开源代码部署到您的独立服务器/域名进行非商业用途、非营利性质使用;
4、您拥有使用本软件构建您的社区,站内全部会员资料、文章及相关信息的所有权,并
独立承担与文章内容的相关法律义务;
5、付费获得商业授权之后,您可以将本软件应用于商业用途,同时依据所购买的授权类型
中确定的技术支持期限、技术支持方式和技术支持内容,自购买时刻起,在技术支持期
限内拥有通过指定的方式获得指定范围内的技术支持服务。商业授权用户享有反映和提
出意见的权力,相关意见将被作为首要考虑,但没有一定被采纳的承诺或保证。
二、规定的约束和限制
1、未付费购买官方版本商业/旗舰授权之前,禁止将开源代码用于商业用途(包括但不限于
企业网站、经营性网站、以营利为目或实现营利的网站)。购买商业授权请访问:
http://www.thinksns.com/buy.html 购买服务页面参考相关说明,点击在线咨询,
也可以直接致电授权业务专线17311245680了解费用详情及最新优惠;
2、不得对本软件或与之关联的商业授权进行出租、出售、抵押或发放子许可证;
3、无论用途如何、是否经过修改或美化、修改程度如何,只要使用 ThinkSNS 的整体或任何
部分,未经官方授权许可,禁止清除或修改前端(页面页脚处)/后台配置的 Powered by
ThinkSNS ©2018 ZhishiSoft All Rights Reserved及官网网站、友情链接等版权
信息。否则视为侵权,须依法向官方支付产品原价授权费及50%(授权费)侵权赔偿金;
4、禁止ThinkSNS的整体或任何部分基础上以发展任何衍生版本、修改版本或第三方版本用于
重新分发;
5、如果您未能遵守本使用须知,违反相关约束,您的开源版使用将被终止,所被许可的权利将
被收回,并承担相应法律责任,承担相应罚款罚金。
三、有限担保和免责声明
1、本软件及所附带的文件是作为不提供任何明确的或隐含的赔偿或担保的形式提供的;
2、用户出于自愿而使用本软件,您必须了解使用本软件的风险,在尚未购买产品技术服务之前,
我们不承诺提供任何形式的技术支持、使用担保,也不承担任何因使用本软件而产生问题的
相关责任;
3、智士软件(北京)有限公司不对使用本软件构建的社区中的文章或信息承担责任。
4、有关ThinkSNS商业授权协议与售后服务的详细内容,均由ThinkSNS官方独家提供。
您一旦开始安装ThinkSNS开源代码,即被视为完全理解并接受本须知的各项条款,在享有上述条款授
予的权力的同时,受到相关的约束和限制。协议许可范围以外的行为,将直接违反本授权协议并构成侵
权,我们有权随时终止授权,责令停止损害,并保留追究相关责任的权力。
<img align="right" width="100px" src="https://github.com/slimkit/plus/raw/master/public/plus.png" alt="Plus (ThinkSNS+) Logo">
# Plus (ThinkSNS+)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/8320deaa80b8489f95fcedaae6df079d)](https://www.codacy.com/app/slimkit/plus?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=slimkit/plus&amp;utm_campaign=Badge_Grade)
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/8320deaa80b8489f95fcedaae6df079d)](https://www.codacy.com/app/slimkit/plus?utm_source=github.com&utm_medium=referral&utm_content=slimkit/plus&utm_campaign=Badge_Coverage)
[![StyleCI](https://github.styleci.io/repos/76627423/shield?branch=master)](https://github.styleci.io/repos/76627423)
[![Build Status](https://travis-ci.org/slimkit/plus.svg?branch=master)](https://travis-ci.org/slimkit/plus)
[![QQ Group](https://img.shields.io/badge/QQ%20Group-651240785-red.svg?longCache=true&style=flat-square)](//shang.qq.com/wpa/qunwpa?idkey=01b61bdf8a7efc2a40ab4caab2d14793f340e5fe5d09aa0c2c17f3115a579678)
[Plus (ThinkSNS+)](http://www.thinksns.com) 是使用 [Laravel](https://laravel.com/) 框架开发;一个功能强大、易于开发和动态拓展的社交系统。Plus 是遵循 **PSR 规范** 代码统一,并功能块松耦合。你安装完成 Plus 并不意味着已经成功安装了所有功能,因为 Plus 使用 **模块化**
原则,所以你安装完成后拥有了所有可以被请求的 REST 接口和后台管理面板,你可能还需要安装如下模块:
- 一个对搜索引擎支持良好的大屏 Web 界面 👉 [ThinkSNS Plus PC](https://github.com/zhiyicx/plus-component-pcos)
- 极大程度还原原生 APP 体验的 SPA (Single Page Application) 应用 👉 [ThinkSNS Plus SPA](https://github.com/zhiyicx/plus-component-h5)
- 一个更加强大的大屏 Web 界面应用 (但它是收费的) 👉 [Plus PC](https://github.com/zhiyicx/plus-component-pc)
> 如果你关注 ThinkSNS 所属公司更多开源产品,请看[ThinkSNS 官网](http://www.thinksns.com)
## 特点
Plus 是基于 Laravel 所开发,它拥有下面的几个主要特点:
1. 跟随 Laravel 一同升级,但是我们放弃 LTS 版本,长期的框架不变,虽然会趋于稳定,但是 Plus 是一款长期规划维护的开源项目,随时升级框架以便我们可以尽情的使用新的技术和特性
2. 前后端分离,Plus 安装完成只拥有功能快的 REST 接口部分,可以利用接口开发任何形态的客户端
3. 后台管理面板采用 Vue.js 开发
4. 使用 PHP 7 严格模式,以数据类型来限制开发人员的不规范开发
5. 完全符合 PSR 规范,代码风格选择的是比 PSR-2 更加严格的规范
6. 完善的文档,是的!在开源社区中, 一个开源项目的文档很重要。
## 文档
你可以在我们的文档网站上看到所有文档 👉 [https://slimkit.github.io](https://slimkit.github.io)
它被分为以下几个部分:
- [快速开始 · 安装](https://slimkit.github.io/docs/server-getting-started-installation.html)
- [指南](https://slimkit.github.io/docs/server-guides-package.html)
- [REST API v2](https://slimkit.github.io/docs/api-v2-overview.html)
当然,有一些并不在网站上,而是在 Plus 代码仓库中:
- [贡献指南 & 贡献者感谢名单](https://github.com/slimkit/plus/blob/master/.github/CONTRIBUTING.md)
- [行为守则](https://github.com/slimkit/plus/blob/master/.github/CODE_OF_CONDUCT.md)
## 安装
安装 Plus 是一件非常简单的事情,但是你要先做到以下几点必须:
- PHP 版本必须大于 `7.1.3`
- 你已下载并安装过 `Composer`
- 你拥有一个 `MySQL` 或者 `PostgreSQL` 等数据库
下载程序:
```shell
composer create-project slimkit/plus
```
基本配置:
下载完成后进入程序的 `storage/configure/` 目录,你会看到一个 `plus.yml.example` 文件,复制一份命名为 `plus.yml` 然后打开这份 Yaml 配置文件,进行你数据库等信息的配置。
生成数据表以及默认填充数据:
```shell
php artisan migrate --seed
```
软链公开磁盘并发布静态资产:
```shell
php artisan storage:link
php artisan vendor:publish --all
```
运行 Plus 程序:
```shell
php artisan serve
```
现在你可以访问 `http://127.0.0.1:8000` 查看你安装的 Plus 程序了,但是上述只是一份简单的安装,更加详细或者可以运行在
正式环境的安装指南请参阅 👉 [安装指南](https://slimkit.github.io/docs/server-getting-started-installation.html)
## 交流 & 支持
你可以申请加入官方 QQ 群进行交流,群号 `651240785`
## 贡献
这个仓库的贡献者并不代表只是 Plus 的贡献者,我们也会把 Laravel 的贡献者加入感谢名单,因为他们为 Laravel 所做出的贡献,也使得 Plus 项目更加强大。
感谢所有为 Plus 贡献的人!
<a href="https://github.com/slimkit/plus/graphs/contributors"><img src="https://opencollective.com/plus/contributors.svg?width=890" /></a>
### [行为守则](https://github.com/slimkit/plus/blob/master/.github/CODE_OF_CONDUCT.md)
我们按照开源项目社区的建议,为 Plus 提供了我们期望参与者遵守的行为准则,请 [阅读准则](https://github.com/slimkit/plus/blob/master/.github/CODE_OF_CONDUCT.md) 全文,以便了解哪些行为是我们不会容忍的。
### [贡献指南](https://github.com/slimkit/plus/blob/master/.github/CONTRIBUTING.md)
阅读我们的 [贡献指南](https://github.com/slimkit/plus/blob/master/.github/CONTRIBUTING.md),了解我们的开发过程,
如题提出错误修正或者建议,我们在贡献指南中包含了所有的贡献者名单。
## 赞助
首先,我们有一个特约赞助商 👉 [成都 · 智艺创想](http://www.zhiyicx.com),该赞助商为 Plus 团队提供了一个开发的基础,提供工作场所以及提供商务处理事宜,并且开发了如下商业项目:
- ThinkSNS Plus Android 客户端
- ThinkSNS Plus iOS 客户端
- 一个强大且全面的大屏 Web 界面应用
- 问答模块
- 圈子社群模块
如果你对这些商业模块感兴趣,可以联系 QQ `3298713109` 了解更多细节。
### 赞助商
感谢所有赞助商!(如果你也支持这个项目,[√成为赞助商](https://opencollective.com/plus#sponsor))
<a href="https://opencollective.com/plus/sponsor/0/website" target="_blank"><img src="https://opencollective.com/plus/sponsor/0/avatar.svg"></a>
<a href="https://opencollective.com/plus/sponsor/1/website" target="_blank"><img src="https://opencollective.com/plus/sponsor/1/avatar.svg"></a>
<a href="https://opencollective.com/plus/sponsor/2/website" target="_blank"><img src="https://opencollective.com/plus/sponsor/2/avatar.svg"></a>
<a href="https://opencollective.com/plus/sponsor/3/website" target="_blank"><img src="https://opencollective.com/plus/sponsor/3/avatar.svg"></a>
<a href="https://opencollective.com/plus/sponsor/4/website" target="_blank"><img src="https://opencollective.com/plus/sponsor/4/avatar.svg"></a>
<a href="https://opencollective.com/plus/sponsor/5/website" target="_blank"><img src="https://opencollective.com/plus/sponsor/5/avatar.svg"></a>
<a href="https://opencollective.com/plus/sponsor/6/website" target="_blank"><img src="https://opencollective.com/plus/sponsor/6/avatar.svg"></a>
<a href="https://opencollective.com/plus/sponsor/7/website" target="_blank"><img src="https://opencollective.com/plus/sponsor/7/avatar.svg"></a>
<a href="https://opencollective.com/plus/sponsor/8/website" target="_blank"><img src="https://opencollective.com/plus/sponsor/8/avatar.svg"></a>
<a href="https://opencollective.com/plus/sponsor/9/website" target="_blank"><img src="https://opencollective.com/plus/sponsor/9/avatar.svg"></a>
## 优秀项目推荐
- [PHP CORS](https://github.com/medz/cors) 专为 PHP 开发的“跨域资源共享”中间件,快速解决 PHP 设置跨域问题
- [Notadd](https://github.com/notadd/notadd) 基于 Nest.js 的微服务开发架构,异步高性能应用、AOP(面向切面编程)
## License
Plus 代码采用企业定制许可证发布,请参阅完整的[许可证文本](https://github.com/slimkit/plus/blob/master/LICENSE)
Copyright © 2018 Chengdu [ZhiYiChuangXiang](http://zhiyicx.com) Technology Co., Ltd. All rights reserved.
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Controllers;
use Illuminate\Http\JsonResponse;
use Zhiyi\Plus\API2\Requests\ListAllComments;
use Zhiyi\Plus\Models\Comment as CommentModel;
use Zhiyi\Plus\API2\Resources\Comment as CommentResource;
class Comment extends Controller
{
/**
* List all comments.
* @param \Zhiyi\Plus\API2\Requests\ListAllComments $request
* @param \Zhiyi\Plus\Models\Comment $model
* @return \Illuminate\Http\JsonResponse
*/
public function index(ListAllComments $request, CommentModel $model): JsonResponse
{
// Skip non id where?
$skipNonId = false;
// Get database query `id` direction.
$direction = $request->query('direction', 'desc');
// Query comments.
$comments = $model
// New a database query.
->query()
// 如果存在 `id` 查询字段,进入查新条件构建
// 如果是空字段,则继续,反之设置 `$skipNonId = true` 跳过后面的条件
->when($id = $request->query('id'), function ($query) use ($id, &$skipNonId) {
$id = array_values(array_filter(explode(',', $id)));
if (! $id) {
return $query;
} elseif (count($id) === 1) {
$skipNonId = true;
return $query->where('id', array_pop($id));
}
$skipNonId = true;
return $query->whereIn('id', $id);
})
// 如果传递了数据开始标记,进入查询构建,
// 如果 `$skipNonId` 为 true 则跳过
->when(($index = $request->query('index') && ! $skipNonId), function ($query) use ($index, $direction) {
return $query->where('id', $direction === 'desc' ? '<' : '>', $index);
})
->when(($author = $request->query('author')) && ! $skipNonId, function ($query) use ($author) {
return $query->where('user_id', $author);
})
->when(($forUser = $request->query('for_user')) && ! $skipNonId, function ($query) use ($forUser, $request) {
$forType = $request->query('for_type', 'all');
if ($forType === 'target') {
return $query->where('target_user', $forUser);
} elseif ($forType === 'reply') {
return $query->where('reply_user', $forUser);
}
return $query->where(function ($query) use ($forUser) {
return $query
->where('target_user', $forUser)
->orWhere('reply_user', $forUser);
});
})
->when(($resourceableId = $request->query('resourceable_id')) && ! $skipNonId, function ($query) use ($resourceableId, $request) {
$resourceableId = array_values(array_filter(explode(',', $resourceableId)));
if (! $resourceableId) {
return $query;
}
return $query
->where('commentable_type', $request->query('resourceable_type'))
->whereIn('commentable_id', $resourceableId);
})
->when(! $skipNonId, function ($query) use ($request) {
return $query->limit($request->query('limit', 15));
})
->orderBy('id', $direction)
->get();
return CommentResource::collection($comments)
->toResponse($request)
->setStatusCode(JsonResponse::HTTP_OK);
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class Controller extends \Illuminate\Routing\Controller
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Controllers\Feed;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Carbon;
use function Zhiyi\Plus\setting;
use Illuminate\Http\JsonResponse;
use Illuminate\Database\Eloquent\Model;
use Zhiyi\Plus\API2\Controllers\Controller;
use Zhiyi\Plus\Models\FeedTopic as FeedTopicModel;
use Zhiyi\Plus\API2\Resources\Feed\Topic as TopicResource;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Zhiyi\Plus\API2\Requests\Feed\TopicIndex as IndexRequest;
use Zhiyi\Plus\API2\Requests\Feed\EditTopic as EditTopicRequest;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Zhiyi\Plus\Models\FeedTopicUserLink as FeedTopicUserLinkModel;
use Zhiyi\Plus\API2\Requests\Feed\CreateTopic as CreateTopicRequest;
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
class Topic extends Controller
{
/**
* Create the controller instance.
*/
public function __construct()
{
// Add Auth(api) middleware.
$this
->middleware('auth:api')
->only(['create', 'update']);
// Add DisposeSensitive middleware.
$this
->middleware('sensitive:name,desc')
->only(['create', 'update']);
}
public function listTopicsOnlyHot(Request $request, FeedTopicModel $model): JsonResponse
{
$user = $request->user('api');
$topics = $model
->query()
->whereNotNull('hot_at')
->where('status', FeedTopicModel::REVIEW_PASSED)
->limit(8)
->orderBy('id', 'desc')
->get();
if (($count = $topics->count()) < 8) {
$topics = $topics->merge(
$model->query()
->whereNull('hot_at')
->where('status', FeedTopicModel::REVIEW_PASSED)
->limit(8 - $count)
->orderBy('feeds_count', 'desc')
->get()
->all()
)->values();
}
if ($user) {
$topics->load(['users' => function ($query) use ($user) {
return $query->wherePivot('user_id', $user->id);
}]);
}
return TopicResource::collection($topics)
->response()
->setStatusCode(Response::HTTP_OK /* 200 */);
}
/**
* List topics.
*
* @param \Zhiyi\Plus\Requests\Feed\TopicIndex $request
* @param \Zhiyi\Plus\Models\FeedTopic $model
* @return \Illuminate\Http\JsonResponse
*/
public function index(IndexRequest $request, FeedTopicModel $model): JsonResponse
{
if ($request->query('only') === 'hot') {
return $this->listTopicsOnlyHot($request, $model);
}
$user = $request->user('api');
// Get query data `id` order direction.
// Value: `asc` or `desc`
$direction = $request->query('direction', 'desc');
// Query database data.
$result = $model
->query()
->where('status', FeedTopicModel::REVIEW_PASSED)
// If `$request->query('q')` param exists,
// create "`name` like %?%" SQL where.
->when((bool) ($searchKeyword = $request->query('q', false)), function (EloquentBuilder $query) use ($searchKeyword) {
return $query->where('name', 'like', sprintf('%%%s%%', $searchKeyword));
})
// If `$request->query('index)` param exists,
// using `$direction` create "id ? ?" where
// ?[0] `$direction === asc` is `>`
// ?[0] `$direction === desc` is `<`
->when((bool) ($indexID = $request->query('index', false)), function (EloquentBuilder $query) use ($indexID, $direction) {
return $query->where('id', $direction === 'asc' ? '>' : '<', $indexID);
})
// Set the number of data
->limit($request->query('limit', 15))
// Using `$direction` set `id` direction,
// the `$direction` enum `asc` or `desc`.
->orderBy('id', $direction)
// Run the SQL query, return a collection.
// instanceof \Illuminate\Support\Collection
->get();
if ($user) {
$result->load(['users' => function ($query) use ($user) {
return $query->wherePivot('user_id', $user->id);
}]);
}
// Create the action response.
$response = TopicResource::collection($result)
->response()
->setStatusCode(Response::HTTP_OK /* 200 */);
return $response;
}
/**
* Create an topic.
*
* @param \Zhiyi\Plus\API2\Requests\Feed\CreateTopic $request
* @return \Illuminate\Http\JsonResponse
*/
public function create(CreateTopicRequest $request): JsonResponse
{
// Create feed topic module
$topic = new FeedTopicModel;
foreach ($request->only(['name', 'logo', 'desc']) as $key => $value) {
$topic->{$key} = $value;
}
// Database query `name` used
$exists = $topic
->query()
->where('name', $topic->name)
->exists();
if ($exists) {
throw new UnprocessableEntityHttpException(sprintf('“%s”话题已存在', $topic->name));
}
// Fetch the authentication user model.
$user = $request->user();
// Open a database transaction,
// database commit success return the topic model.
$topic = $user->getConnection()->transaction(function () use ($user, $topic) {
// Set topic creator user ID and
// init default followers count.
$topic->creator_user_id = $user->id;
$topic->followers_count = 1;
$topic->status = setting('feed', 'topic:need-review', false) ? FeedTopicModel::REVIEW_WAITING : FeedTopicModel::REVIEW_PASSED;
$topic->save();
// Attach the creator user follow the topic.
$link = new FeedTopicUserLinkModel();
$link->topic_id = $topic->id;
$link->user_id = $user->id;
$link->following_at = new Carbon();
$link->save();
return $topic;
});
// Headers:
// Status: 201 Created
// Body:
// { "id": $topid->id }
return new JsonResponse(
[
'id' => $topic->id,
'need_review' => setting('feed', 'topic:need-review', false),
],
Response::HTTP_CREATED /* 201 */
);
}
/**
* Edit an topic.
*
* @param \Zhiyi\Plus\API2\Requests\Feed\EditTopic $request
* @param \Zhiyi\Plus\Models\FeedTopic $topic
* @return \Illuminate\Http\Response
*/
public function update(EditTopicRequest $request, FeedTopicModel $topic): Response
{
$this->authorize('update', $topic);
// Create success 204 response
$response = (new Response())->setStatusCode(Response::HTTP_NO_CONTENT /* 204 */);
// If `logo` and `desc` field all is NULL
$data = array_filter($request->only(['name', 'desc', 'logo']));
if (empty($data)) {
return $response;
}
foreach ($data as $key => $value) {
$topic->{$key} = $value;
}
$topic->save();
return $response;
}
/**
* Get a single topic.
*
* @param \Zhiyi\Plus\Models\FeedTopic $topic
* @return \Illuminate\Http\JsonResponse
*/
public function show(FeedTopicModel $topic): JsonResponse
{
if ($topic->status !== FeedTopicModel::REVIEW_PASSED) {
throw new NotFoundHttpException('话题不存在或者还没有通过审核');
}
$topic->participants = $topic
->users()
->newPivotStatement()
->where('topic_id', $topic->id)
->where('user_id', '!=', $topic->creator_user_id)
->orderBy(Model::UPDATED_AT, 'desc')
->limit(3)
->select('user_id')
->get()
->pluck('user_id');
return (new TopicResource($topic))
->response()
->setStatusCode(Response::HTTP_OK /* 200 */);
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Controllers\Feed;
use Carbon\Carbon;
use Illuminate\Http\JsonResponse;
use Zhiyi\Plus\API2\Controllers\Controller;
use Zhiyi\Plus\Models\FeedTopicLink as FeedTopicLinkModel;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Zhiyi\Component\ZhiyiPlus\PlusComponentFeed\Repository\Feed as FeedRepository;
use Zhiyi\Plus\API2\Requests\Feed\ListFeedsForATopic as ListFeedsForATopicRequest;
class TopicFeed extends Controller
{
/**
* The list feeds for a topic action handle.
*/
public function __invoke(ListFeedsForATopicRequest $request, FeedTopicLinkModel $model, FeedRepository $repository, int $topic): JsonResponse
{
$userID = $request->user('api')->id ?? 0;
$direction = $request->query('direction', 'desc');
$links = $model
->query()
->where('topic_id', $topic)
->when((bool) ($index = $request->query('index', false)), function (EloquentBuilder $query) use ($index, $direction): EloquentBuilder {
return $query->where('index', $direction === 'asc' ? '>' : '<', $index);
})
->select('index', 'feed_id')
->orderBy('index', $direction)
->limit($request->query('limit', 15))
->get();
$links->load([
'feed',
'feed.topics' => function ($query) {
return $query->select('id', 'name');
},
'feed.user' => function ($query) {
return $query
->withTrashed()
->with('certification');
},
'feed.pinnedComments' => function ($query) {
return $query->with([
'user',
'user.certification',
])
->where('expires_at', '>', new Carbon)
->orderBy('amount', 'desc')
->orderBy('created_at', 'desc');
},
]);
$feeds = $links->map(function (FeedTopicLinkModel $link) use ($userID, $repository) {
$feed = $link->feed;
$feed->index = $link->index;
$repository->setModel($feed);
$repository->images();
$repository->format($userID);
$repository->previewComments();
$feed->has_collect = $feed->collected($userID);
$feed->has_like = $feed->liked($userID);
return $feed;
});
return new JsonResponse($feeds, JsonResponse::HTTP_OK);
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Controllers\Feed;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Carbon;
use Zhiyi\Plus\API2\Controllers\Controller;
use Zhiyi\Plus\Models\FeedTopic as FeedTopicModel;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class TopicFollow extends Controller
{
/**
* Create the controller instance.
*/
public function __construct()
{
$this->middleware('auth:api');
}
/**
* Follow a topic.
*
* @param \Illuminate\Http\Request $request
* @param \Zhiyi\Plus\Models\FeedTopic $model
* @param int $topicID
* @return \Illuminate\Http\Response
*/
public function follow(Request $request, FeedTopicModel $model, int $topicID): Response
{
// Featch the request authentication user model.
$user = $request->user();
// Database query topic.
$topic = $model
->query()
->where('id', $topicID)
->first();
// If the topic Non-existent, throw a not found exception.
if (! $topic) {
throw new NotFoundHttpException('关注的话题不存在');
}
$link = $topic->users()->wherePivot('user_id', $user->id)->first()->pivot;
if ($link->following_at ?? false) {
return (new Response())->setStatusCode(Response::HTTP_NO_CONTENT /* 204 */);
}
$feedsCount = $topic->feeds()->where('user_id', $user->id)->count();
return $user->getConnection()->transaction(function () use ($topic, $user, $feedsCount, $link): Response {
if ($link) {
$link->following_at = new Carbon;
$link->save();
} else {
$topic->users()->attach($user, [
'following_at' => new Carbon(),
'feeds_count' => $feedsCount,
]);
}
$topic->increment('followers_count', 1);
return (new Response)->setStatusCode(Response::HTTP_NO_CONTENT /* 204 */);
});
}
/**
* Unfollow a topic.
*
* @param \Illuminate\Http\Request $request
* @param \Zhiyi\Plus\Models\FeedTopic $model
* @param int $topicID
* @return \Illuminate\Http\Response
*/
public function unfollow(Request $request, FeedTopicModel $model, int $topicID): Response
{
// Featch the request authentication user model.
$user = $request->user();
// Database query topic.
$topic = $model
->query()
->where('id', $topicID)
->first();
// If the topic Non-existent, throw a not found exception.
if (! $topic) {
throw new NotFoundHttpException('关注的话题不存在');
}
// Create success 204 response
$response = (new Response)->setStatusCode(Response::HTTP_NO_CONTENT /* 204 */);
// If not followed, return 204 response.
$link = $topic->users()->wherePivot('user_id', $user->id)->first()->pivot;
if (! $link || ! ($link->following_at ?? false)) {
return $response;
}
return $user->getConnection()->transaction(function () use ($topic, $response, $user, $link): Response {
if ($topic->followers_count > 0) {
$topic->decrement('followers_count', 1);
}
$link->following_at = null;
$link->save();
return $response;
});
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Controllers\Feed;
use Illuminate\Http\JsonResponse;
use Illuminate\Database\Eloquent\Model;
use Zhiyi\Plus\API2\Controllers\Controller;
use Zhiyi\Plus\Models\FeedTopicUserLink as FeedTopicUserLinkModel;
use Zhiyi\Plus\API2\Requests\Feed\ListParticipantsForATopic as ListParticipantsForATopicRequest;
use Zhiyi\Plus\API2\Resources\Feed\TopicParticipantCollection as TopicParticipantCollectionResponse;
class TopicParticipant extends Controller
{
/**
* List participants for a topic.
*
* @param \Zhiyi\Plus\API2\Requests\Feed\ListParticipantsForATopic $request
* @param \Zhiyi\Plus\Models\FeedTopicUserLink $model
* @param int $topic
* @return \Illuminate\Http\JsonResponse
*/
public function index(ListParticipantsForATopicRequest $request, FeedTopicUserLinkModel $model, int $topic): JsonResponse
{
$result = $model
->query()
->where('topic_id', $topic)
->limit($request->query('limit', 15))
->offset($request->query('offset', 0))
->orderBy(Model::UPDATED_AT, 'desc')
->get();
return (new TopicParticipantCollectionResponse($result))
->response()
->setStatusCode(JsonResponse::HTTP_OK /* 200 */);
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Controllers\Feed;
use Illuminate\Http\Response;
use Zhiyi\Plus\API2\Controllers\Controller;
use Zhiyi\Plus\Models\Report as ReportModel;
use Zhiyi\Plus\Models\FeedTopic as FeedTopicModel;
use Zhiyi\Plus\API2\Requests\Feed\ReportATopic as ReportATopicRequest;
class TopicReport extends Controller
{
/**
* Create the action instance.
*/
public function __construct()
{
$this->middleware('auth:api');
}
/**
* Report a topic.
*
* @param \Zhiyi\Plus\API2\Requests\Feed\ReportATopic $request
* @param \Zhiyi\Plus\Models\FeedTopic $topic
* @return \Illuminate\Http\Response
*/
public function __invoke(ReportATopicRequest $request, FeedTopicModel $topic): Response
{
$report = new ReportModel();
$report->reason = $request->input('message');
$report->user_id = $request->user()->id;
$report->target_user = $topic->creator_user_id;
$report->subject = sprintf('动态话题(%d):%s', $topic->id, $topic->name);
$report->status = 0;
$topic->reports()->save($report);
return (new Response)->setStatusCode(Response::HTTP_NO_CONTENT);
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Controllers;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\DB;
use Zhiyi\Component\ZhiyiPlus\PlusComponentNews\Models\News;
class NewsPostController extends Controller
{
/**
* Create the news posts controller instance.
*/
public function __construct()
{
$this->middleware('auth:api');
}
/**
* Destory a News post.
* @param \Zhiyi\Component\ZhiyiPlus\PlusComponentNews\Models\News $post
* @return mixed
*/
public function destroy(News $post)
{
$this->authorize('delete', $post);
// Database transaction
DB::transaction(function () use ($post) {
$post->pinned()->delete();
$post->applylog()->delete();
$post->reports()->delete();
$post->tags()->detach();
$post->delete();
});
return new Response('', Response::HTTP_NO_CONTENT);
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse;
use Zhiyi\Plus\Utils\DateTimeToIso8601ZuluString;
use Zhiyi\Plus\Notifications\At as AtNotification;
use Zhiyi\Plus\Notifications\Like as LikeNotification;
use Zhiyi\Plus\Notifications\Follow as FollowNotification;
use Zhiyi\Plus\Notifications\System as SystemNotification;
use Zhiyi\Plus\Notifications\Comment as CommentNotification;
use Zhiyi\Plus\API2\Resources\Notification as NotificationResource;
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
class NotificationController extends Controller
{
use DateTimeToIso8601ZuluString;
/**
* Get the notification controller instance.
*/
public function __construct()
{
$this->middleware('auth:api');
}
/**
* Get the request notification type.
* @param \Illuminate\Http\Request $request
* @return string
*/
protected function getQueryType(Request $request, bool $getTypes = false)
{
$type = $request->query('type');
$types = [
'at' => AtNotification::class,
'comment' => CommentNotification::class,
'like' => LikeNotification::class,
'system' => SystemNotification::class,
];
if ($getTypes) {
return $types;
} elseif (array_key_exists($type, $types)) {
return $types[$type];
}
throw new UnprocessableEntityHttpException('type 不合法');
}
/**
* Get the user notifications.
* @param \Illuminate\Http\Request $request
* @return mixed
*/
public function index(Request $request)
{
$notifications = $request->user()
->notifications()
->whereType($this->getQueryType($request))
->paginate(15)
->appends([
'type' => $request->query('type'),
]);
return NotificationResource::collection($notifications);
}
/**
* Set notifications make read at.
* @param \Illuminate\Http\Request $request
* @return mixed
*/
public function update(Request $request)
{
$type = $this->getQueryType($request);
$notifications = $request->user()
->unreadNotifications()
->whereType($type)
->update([
'read_at' => now(),
]);
return new Response('', Response::HTTP_NO_CONTENT);
}
/**
* Clear follow notifications.
* @param \Illuminate\Http\Request $request
* @return mixed
*/
public function clearFollowNotifications(Request $request)
{
$request->user()->notifications()->whereType(FollowNotification::class)->delete();
return new Response('', Response::HTTP_NO_CONTENT);
}
/**
* Get the user notification statistics.
* @param \Illuminate\Http\Request $request
* @return mixed
*/
public function statistics(Request $request)
{
$statistics = [];
foreach ($this->getQueryType($request, true) as $alias => $notificationClassname) {
$badge = $request->user()->unreadNotifications()->whereType($notificationClassname)->count();
if ($notificationClassname === SystemNotification::class) {
$first = $request->user()->notifications(SystemNotification::class)->first();
$statistics[$alias] = [
'badge' => $badge,
];
$statistics[$alias] = array_merge($statistics[$alias], (! $first) ? [] : [
'first' => new NotificationResource($first),
]);
continue;
}
$lastCreatedAt = $this->dateTimeToIso8601ZuluString(
$request->user()->notifications()->whereType($notificationClassname)->first()->created_at ?? null
);
$previewUserNames = $request->user()
->notifications()
->whereType($notificationClassname)
->limit(5)
->get()
->map(function ($notification) {
return $notification->data['sender']['name'];
})
->filter()
->unique()
->values()
->all();
$statistics[$alias] = [
'badge' => $badge,
'last_created_at' => $lastCreatedAt,
'preview_users_names' => $previewUserNames,
];
}
$statistics['follow'] = [
'badge' => $request->user()->unreadNotifications()->whereType(FollowNotification::class)->count(),
];
return new JsonResponse($statistics);
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Controllers\User;
use Illuminate\Http\Request;
use Zhiyi\Plus\API2\Controllers\Controller;
use Zhiyi\Plus\API2\Resources\Ability as AbilityResource;
class AbilityController extends Controller
{
/**
* Create the controller instance.
*/
public function __construct()
{
$this->middleware('auth:api');
}
/**
* List all abilities.
*/
public function __invoke(Request $request)
{
return AbilityResource::collection(
$request->user()->ability()->all()->values()
);
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Controllers\User\Message;
use Illuminate\Http\Response;
use Zhiyi\Plus\API2\Controllers\Controller;
use Zhiyi\Plus\Models\AtMessage as AtMessageModel;
use Zhiyi\Plus\API2\Requests\User\Message\ListAtMessageLine;
use Zhiyi\Plus\API2\Resources\User\Message\AtMessage as AtMessageResource;
class At extends Controller
{
/**
* Create the at message controller instance.
*/
public function __construct()
{
$this->middleware('auth:api');
}
public function __invoke(ListAtMessageLine $request, AtMessageModel $model)
{
$direction = $request->query('direction', 'desc');
$collection = $model
->query()
->when($index = $request->query('index'), function ($query) use ($index, $direction) {
return $query->where('id', $direction === 'asc' ? '>' : '<', $index);
})
->where('user_id', $request->user()->id)
->limit($request->query('limit', 15))
->orderBy('id', $direction)
->get();
// 暂不提供支持,动态付费内容难以处理!代码请不要删除!
// $relationships = array_filter(explode(',', $request->query('load')));
// if ($relationships) {
// $collection->load($relationships);
// }
return AtMessageResource::collection($collection)
->toResponse($request)
->setStatusCode(Response::HTTP_OK);
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Illuminate\Http\JsonResponse;
use Zhiyi\Plus\API2\Resources\UserCountsResource;
use Zhiyi\Plus\Models\UserCount as UserCountModel;
class UserCountsController extends Controller
{
/**
* Create the Controller instance.
*
* @author Seven Du <shiweidu@outlook.com>
*/
public function __construct()
{
$this->middleware('auth:api');
}
/**
* The route controller to callable handle.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\JsonResponse
* @author Seven Du <shiweidu@outlook.com>
*/
public function count(Request $request): JsonResponse
{
$counts = UserCountModel::where('user_id', $request->user()->id)->get();
$counts = $counts->keyBy('type')->map(function ($count) {
return $count->total;
});
return (new UserCountsResource($counts->all()))
->response()
->setStatusCode(200);
}
/**
* 重置某项为度数为0.
* @Author Wayne
* @DateTime 2018-04-16
* @Email qiaobin@zhiyicx.com
* @param Request $request [description]
* @return [type] [description]
*/
public function reset(Request $request)
{
$type = $request->input('type');
if ($type && in_array($type, ['commented', 'liked', 'system', 'group-post-pinned', 'post-comment-pinned', 'feed-comment-pinned', 'news-comment-pinned', 'post-pinned', 'mutual', 'following', 'group-join-pinned'])) {
$type = 'user-'.$type;
}
UserCountModel::where('user_id', $request->user()->id)
->when($type, function ($query) use ($type) {
return $query->where('type', $type);
})
->update([
'total' => 0,
'read_at' => new Carbon(),
]);
return response()->json('', 204);
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Requests\Feed;
use Zhiyi\Plus\API2\Requests\Request;
class CreateTopic extends Request
{
/**
* Get the validator rules.
*
* @return array
*/
public function rules(): array
{
return [
'name' => ['required', 'string', 'max:100'],
'desc' => ['nullable', 'string', 'max:500'],
'logo' => ['nullable', 'string', 'file_storage'],
];
}
/**
* Get the validator error messages.
*
* @return array
*/
public function messages(): array
{
return [
'name.required' => '请输入话题名称',
'name.max' => '话题名称请控制在 100 字以内',
'desc.max' => '话题描述请控制在 500 字以内',
'logo.string' => '话题 Logo 数据非法',
'logo.file_storage' => '话题 Logo 未上传,或使用非法节点',
];
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Requests\Feed;
use Zhiyi\Plus\API2\Requests\Request;
class EditTopic extends Request
{
/**
* Get the validator rules.
*
* @return array
*/
public function rules(): array
{
return [
'logo' => ['nullable', 'string', 'file_storage'],
'desc' => ['nullable', 'string', 'max:500'],
];
}
/**
* Get the validator error messages.
*
* @return array
*/
public function messages(): array
{
return [
'desc.max' => '话题描述请控制在 500 字以内',
'logo.string' => '话题 Logo 数据非法',
'logo.file_storage' => '话题 Logo 未上传,或使用非法节点',
];
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Requests\Feed;
use Zhiyi\Plus\API2\Requests\Request;
class ListFeedsForATopic extends Request
{
/**
* Get the validator rules.
*
* @return array
*/
public function rules(): array
{
return [
'limit' => ['nullable', 'integer', 'min:1'],
'index' => ['nullable', 'integer', 'min:0'],
'direction' => ['nullable', 'string', 'in:asc,desc'],
];
}
/**
* Get the validator error messages.
*
* @return array
*/
public function messages(): array
{
return [
'limit.integer' => '请求数据量必须是整数',
'limit.min' => '请求数据量最少 1 条',
'index.integer' => '请求参数类型非法,index 必须是整数',
'index.min' => 'index 必须是大于 0 的正整数',
'direction.in' => '排序方向值非法,必须是 `asc` 或者 `desc`',
];
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Requests\Feed;
use Zhiyi\Plus\API2\Requests\Request;
class ListParticipantsForATopic extends Request
{
/**
* Get the validator rules.
*
* @return array
*/
public function rules(): array
{
return [
'limit' => ['nullable', 'integer', 'min:1', 'max:100'],
'offset' => ['nullable', 'integer', 'min:0'],
];
}
/**
* Get the validator error messages.
*
* @return array
*/
public function messages(): array
{
return [
'limit.integer' => '请求数据量必须是整数',
'limit.min' => '请求数据量最少 1 条',
'offset.integer' => '请求的数据偏移必须是整数',
'offset.min' => '请求的数据偏移最少 0 条',
];
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Requests\Feed;
use Zhiyi\Plus\API2\Requests\Request;
class ReportATopic extends Request
{
/**
* Get the validator rules.
*
* @return array
*/
public function rules(): array
{
return [
'message' => ['required', 'string', 'max:255'],
];
}
/**
* Get the validator error messages.
*
* @return array
*/
public function messages(): array
{
return [
'message.required' => '请输入举报理由',
'message.max' => '举报理由必须在 255 个字以内',
];
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Requests\Feed;
use Zhiyi\Plus\API2\Requests\Request;
class TopicIndex extends Request
{
/**
* Get the validator rules.
*
* @return array
*/
public function rules(): array
{
return [
'limit' => ['nullable', 'integer', 'min:1', 'max:100'],
'index' => ['nullable', 'integer', 'min:0'],
'direction' => ['nullable', 'in:asc,desc'],
'q' => ['nullable', 'string'],
'only' => ['nullable', 'string', 'in:hot'],
];
}
/**
* Get the validator error messages.
*
* @return array
*/
public function messages(): array
{
return [
'limit.integer' => '请求数据量必须是整数',
'limit.min' => '请求数据量最少 1 条',
'limit.max' => '请求数据量最多 100 条',
'index.integer' => '请求参数类型非法,index 必须是整数',
'index.min' => 'index 必须是大于 0 的正整数',
'direction.in' => '排序方向值非法,必须是 `asc` 或者 `desc`',
'q.string' => '输入的搜索关键词不合法',
'only.in' => 'only 只接受 `hot` 值',
];
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Requests;
class ListAllComments extends Request
{
/**
* The validate rules.
* @return array
*/
public function rules(): array
{
return [
'limit' => 'nullable|integer|min:1|max:100',
'index' => 'nullable|integer|min:0',
'direction' => 'nullable|string|in:asc,desc',
'author' => 'nullable|integer|min:0',
'for_user' => 'nullable|integer|min:0',
'for_type' => 'nullable|string|in:all,target,reply',
'id' => 'nullable|string',
'resourceable_id' => 'nullable|string',
'resourceable_type' => 'required_with:resourceable_id|string',
];
}
/**
* Get the validate error messages.
* @return array
*/
public function messages(): array
{
return [
'limit.integer' => 'limit 只能是正整数',
'limit.min' => '本次请求最少要求获取一条数据',
'limit.max' => '本次请求最多只能获取 100 条数据',
'index.integer' => '位置标记只能是正整数',
'index.min' => '位置标记不能为负数',
'direction.in' => '数据排序方向只允许 `asc` 或者 `desc`',
'author.integer' => '作者只允许用户 ID',
'author.min' => '作者用户 ID 非法',
'for_user.integer' => '接收用户 ID 非法',
'for_user.min' => '接收用户 ID 非法',
'for_type.in' => '接收用户数据类型错误',
];
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Requests;
use Illuminate\Foundation\Http\FormRequest;
class Request extends FormRequest
{
/**
* Get request authorize.
*
* @return bool
*/
public function authorize(): bool
{
return true;
}
/**
* Get custom message from validateor rules.
*
* @return array
*/
public function rules(): array
{
return [];
}
/**
* Get custom messages for validator errors.
*
* @return array
*/
public function messages(): array
{
return [];
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes(): array
{
return [];
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Requests\User\Message;
use Zhiyi\Plus\API2\Requests\Request;
class ListAtMessageLine extends Request
{
/**
* Get the validate rules.
* @return array
*/
public function rules(): array
{
return [
'limit' => 'nullable|integer|min:1|max:100',
'index' => 'nullable|integer|min:0',
'direction' => 'nullable|in:asc,desc',
'load' => 'nullable|string',
];
}
/**
* Get the validate error messages.
* @return array
*/
public function messages(): array
{
return [
'limit.integer' => 'limit 参数非法',
'limit.min' => '最少获取一条数据',
'limit.max' => '最多获取 100 条数据',
'index.integer' => 'index 参数非法',
'inde.min' => 'index 参数不得低于 0',
'direction.in' => '方向只允许 `asc` 或者 `desc`',
];
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class Ability extends JsonResource
{
/**
* The resource to array.
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request): array
{
return [
'name' => $this->name,
'display_name' => $this->display_name,
'description' => $this->description,
];
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Resources;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Resources\Json\JsonResource;
use Zhiyi\Plus\Utils\DateTimeToIso8601ZuluString;
class Comment extends JsonResource
{
use DateTimeToIso8601ZuluString;
/**
* The resource to array.
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request): array
{
return [
'id' => $this->id,
'user_id' => $this->user_id,
'target_user' => $this->target_user,
'reply_user' => $this->when($this->reply_user, $this->reply_user),
'body' => $this->body,
'resourceable' => [
'type' => $this->commentable_type,
'id' => $this->commentable_id,
],
'created_at' => $this->dateTimeToIso8601ZuluString(
$this->{Model::CREATED_AT}
),
];
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Resources\Feed;
use Illuminate\Http\Resources\Json\JsonResource;
class Topic extends JsonResource
{
/**
* The topic resource to array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request): array
{
$user = $request->user('api');
return [
'id' => $this->id,
'name' => $this->name,
'logo' => $this->when($this->logo, function () {
return $this->logo->toArray();
}),
'desc' => $this->when($this->desc, $this->desc),
'creator_user_id' => $this->creator_user_id,
'feeds_count' => $this->feeds_count,
'followers_count' => $this->followers_count,
'has_followed' => $this->when($user, function () use ($user) {
$link = $this->users->firstWhere('id', $user->id)->pivot ?? null;
if ($link && $link->following_at) {
return true;
}
return false;
}),
'participants' => $this->when($this->participants, $this->participants),
];
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Resources\Feed;
use Illuminate\Http\Resources\Json\ResourceCollection;
class TopicParticipantCollection extends ResourceCollection
{
/**
* The collection to array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request): array
{
return $this
->collection
->map(function ($item) use ($request) {
return $this->renderItem($item, $request);
})
->all();
}
/**
* Render the collection item.
*
* @param mixed $item
* @return int
*/
public function renderItem($item): int
{
return $item->user_id;
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
use Zhiyi\Plus\Utils\DateTimeToIso8601ZuluString;
class Notification extends JsonResource
{
use DateTimeToIso8601ZuluString;
/**
* The resource to array.
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request): array
{
return [
'id' => $this->id,
'created_at' => $this->dateTimeToIso8601ZuluString($this->created_at),
'read_at' => $this->dateTimeToIso8601ZuluString($this->read_at),
'data' => $this->data,
];
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Resources\User\Message;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Resources\Json\JsonResource;
use Zhiyi\Plus\Utils\DateTimeToIso8601ZuluString;
class AtMessage extends JsonResource
{
use DateTimeToIso8601ZuluString;
/**
* The resource to array.
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request): array
{
return [
'id' => $this->id,
'user_id' => $this->user_id,
'resourceable' => [
'type' => $this->resourceable_type,
'id' => $this->resourceable_id,
],
$this->mergeWhen($request->query('load'), [
'resource' => ['暂不提供数据支持'],
]),
'created_at' => $this->dateTimeToIso8601ZuluString(
$this->{Model::CREATED_AT}
),
];
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\API2\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class UserCountsResource extends JsonResource
{
/**
* The resource to array.
*
* @param \Illuminate\Http\Request $request
* @return array
* @author Seven Du <shiweidu@outlook.com>
*/
public function toArray($request): array
{
// unused the $request.
unset($request);
return [
'user' => [
'following' => $this['user-following'] ?? 0,
'liked' => $this['user-liked'] ?? 0,
'commented' => $this['user-commented'] ?? 0,
'system' => $this['user-system'] ?? 0,
'news-comment-pinned' => $this['user-news-comment-pinned'] ?? 0,
'feed-comment-pinned' => $this['user-feed-comment-pinned'] ?? 0,
'mutual' => $this['user-mutual'] ?? 0,
'at' => $this['at'] ?? 0,
],
];
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\Admin\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse;
use Zhiyi\Plus\Support\Configuration;
class AboutUsController extends Controller
{
/**
* @return JsonResponse
*/
public function show(): JsonResponse
{
return response()->json(['aboutUs' => config('site.aboutUs')], 200);
}
/**
* @param Request $request
* @param Configuration $config
* @return Response
*/
public function store(Request $request, Configuration $config): Response
{
// dd($request->input('url'));
$config->set('site.aboutUs.url', $request->input('url'));
$config->set('site.aboutUs.content', $request->input('content'));
return response('', 204);
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\Admin\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class Controller extends \Illuminate\Routing\Controller
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\Admin\Controllers\FileStorage;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use function Zhiyi\Plus\setting;
use Illuminate\Http\JsonResponse;
class AliyunOSSFilesystem
{
/**
* Get Aliyun OSS filesystem.
* @return \Illuminate\Http\JsonResponse
*/
public function show(): JsonResponse
{
$configure = setting('file-storage', 'filesystems.aliyun-oss', []);
$result = [
'accessKeyId' => $configure['access-key-id'] ?? null,
'accessKeySecret' => $configure['access-key-secret'] ?? null,
'bucket' => $configure['bucket'] ?? null,
'acl' => $configure['acl'] ?? 'public-read',
'timeout' => $configure['timeout'] ?? 3600,
'domain' => $configure['domain'] ?? null,
'insideDomain' => $configure['inside-domain'] ?? null,
];
return new JsonResponse($result, Response::HTTP_OK);
}
/**
* Update Aliyun OSS filesystem.
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function update(Request $request): Response
{
$request->validate($this->rules(), $this->messages());
$setting = setting('file-storage');
$setting->set('filesystems.aliyun-oss', [
'access-key-id' => $request->input('accessKeyId'),
'access-key-secret' => $request->input('accessKeySecret'),
'bucket' => $request->input('bucket'),
'acl' => $request->input('acl'),
'timeout' => $request->input('timeout'),
'domain' => $request->input('domain'),
'inside-domain' => $request->input('insideDomain'),
]);
return new Response('', Response::HTTP_NO_CONTENT);
}
protected function rules(): array
{
return [
'accessKeyId' => ['required', 'string'],
'accessKeySecret' => ['required', 'string'],
'bucket' => ['required', 'string'],
'acl' => ['required', 'string', 'in:public-read-write,public-read,private'],
'timeout' => ['required', 'integer'],
'domain' => ['required', 'string', 'url'],
'insideDomain' => ['required', 'string', 'url'],
];
}
protected function messages(): array
{
return [];
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\Admin\Controllers\FileStorage;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use function Zhiyi\Plus\setting;
use Illuminate\Http\JsonResponse;
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
class DefaultFilesystem
{
/**
* Get default filesystem.
* @return \Illuminate\Http\JsonResponse
*/
public function show(): JsonResponse
{
$defaultFilesystem = setting('file-storage', 'default-filesystem', 'local');
return new JsonResponse(['filesystem' => $defaultFilesystem], Response::HTTP_OK);
}
/**
* Update default filesystem.
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function update(Request $request): Response
{
$filesystem = $request->input('filesystem');
if (! in_array($filesystem, ['local', 'AliyunOSS'])) {
throw new UnprocessableEntityHttpException('设置的文件系统不合法');
}
$setting = setting('file-storage');
$setting->set('default-filesystem', $filesystem);
return new Response('', Response::HTTP_NO_CONTENT);
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\Admin\Controllers\FileStorage;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use function Zhiyi\Plus\setting;
use Illuminate\Http\JsonResponse;
use Symfony\Component\HttpFoundation\File\UploadedFile;
class FileSize
{
/**
* Get file storage validate size.
* @return \Illuminate\Http\JsonResponse
*/
public function show(): JsonResponse
{
// Get configure.
$configure = (array) setting('file-storage', 'task-create-validate', []);
$result = [
'size' => [
'min' => intval($configure['file-min-size'] ?? 0),
'max' => intval($configure['file-max-size'] ?? 0),
],
'system' => [
'max' => $this->getMaxFilesize(),
],
];
return new JsonResponse($result, Response::HTTP_OK);
}
/**
* Update file storage validate file size.
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function update(Request $request): Response
{
// Get configure.
$setting = setting('file-storage');
$setting->set('task-create-validate', array_merge((array) $setting->get('task-create-validate', []), array_filter([
'file-min-size' => (int) $request->input('size.min', 0),
'file-max-size' => (int) $request->input('size.max', 0),
])));
return new Response('', Response::HTTP_NO_CONTENT);
}
/**
* Returns the maximum size of an uploaded file as configured in php.ini.
*
* @return int The maximum size of an uploaded file in bytes
*/
protected function getMaxFilesize(): int
{
return UploadedFile::getMaxFilesize();
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\Admin\Controllers\FileStorage;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use function Zhiyi\Plus\setting;
use Illuminate\Http\JsonResponse;
class ImageDimension
{
/**
* Show file storage validate image dimension.
* @return \Illuminate\Http\JsonResponse
*/
public function show(): JsonResponse
{
// Get configure.
$configure = setting('file-storage', 'task-create-validate', [
'image-min-width' => 0,
'image-max-width' => 0,
'image-min-height' => 0,
'image-max-height' => 0,
]);
// Packing json result.
$result = [
'width' => [
'min' => intval($configure['image-min-width'] ?? 0),
'max' => intval($configure['image-max-width'] ?? 0),
],
'height' => [
'min' => intval($configure['image-min-height'] ?? 0),
'max' => intval($configure['image-max-height'] ?? 0),
],
];
return new JsonResponse($result, JsonResponse::HTTP_OK);
}
/**
* Update file storage validate image dimension.
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function update(Request $request): Response
{
// Get configure.
$setting = setting('file-storage');
$setting->set('task-create-validate', array_merge((array) $setting->get('task-create-validate', []), array_filter([
'image-min-width' => (int) $request->input('width.min', 0),
'image-max-width' => (int) $request->input('width.max', 0),
'image-min-height' => (int) $request->input('height.min', 0),
'image-max-height' => (int) $request->input('height.max', 0),
])));
return new Response('', Response::HTTP_NO_CONTENT);
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\Admin\Controllers\FileStorage;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use function Zhiyi\Plus\setting;
use Illuminate\Http\JsonResponse;
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
class LocalFilesystem
{
/**
* Get local filesystem.
* @return \Illuminate\Http\JsonResponse
*/
public function show(): JsonResponse
{
$configure = setting('file-storage', 'filesystems.local', []);
$result = [
'disk' => $configure['disk'] ?? 'local',
'timeout' => $configure['timeout'] ?? 3360,
'disks' => array_keys(config('filesystems.disks')),
];
return new JsonResponse($result, Response::HTTP_OK);
}
/**
* Update local filesystem.
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function update(Request $request): Response
{
$disk = $request->input('disk', 'local');
$timeout = (int) $request->input('timeout');
if (! in_array($disk, array_keys(config('filesystems.disks')))) {
throw new UnprocessableEntityHttpException('选择的磁盘不存在!');
}
$setting = setting('file-storage');
$setting->set('filesystems.local', [
'disk' => $disk,
'timeout' => $timeout,
]);
return new Response('', Response::HTTP_NO_CONTENT);
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\Admin\Controllers\FileStorage;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use function Zhiyi\Plus\setting;
use Illuminate\Http\JsonResponse;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeExtensionGuesser;
class MimeType extends MimeTypeExtensionGuesser
{
/**
* Caching MIME types.
* @var array
*/
protected $mimeTypes = [];
/**
* Get file storage validate MIME types.
* @return \Illuminate\Http\JsonResponse
*/
public function show(): JsonResponse
{
// Get configure.
$configure = setting('file-storage', 'task-create-validate', [
'file-mime-types' => [],
]);
$mimeTypes = array_filter($configure['file-mime-types'] ?? []);
$extensions = array_map(function (string $mimeType) {
return $this->guess($mimeType);
}, $mimeTypes);
return new JsonResponse($extensions, Response::HTTP_OK);
}
/**
* Update file storage validate MIME types.
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function update(Request $request): Response
{
$extensions = array_filter((array) $request->input('extensions', []));
$mimeTypes = array_map(function (string $extension) {
return $this->mimeTypeGuess($extension);
}, $extensions);
$mimeTypes = array_unique($mimeTypes);
$setting = setting('file-storage');
$setting->set('task-create-validate', array_merge((array) $setting->get('task-create-validate', []), array_filter([
'file-mime-types' => $mimeTypes,
])));
return new Response('', Response::HTTP_NO_CONTENT);
}
/**
* get extension MIME type.
* @param string $extension
* @return string
*/
protected function mimeTypeGuess(string $extension): ?string
{
$mimeTypes = array_flip($this->defaultExtensions);
$mimeTypes = array_merge($mimeTypes, [
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
]);
return $mimeTypes[$extension] ?? null;
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\Admin\Controllers\FileStorage;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use function Zhiyi\Plus\setting;
use Illuminate\Http\JsonResponse;
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
class PublicChannel
{
/**
* Get public channel settings.
* @return \Illuminate\Http\JsonResponse
*/
public function show(): JsonResponse
{
$configure = setting('file-storage', 'channels.public', []);
$result = [
'filesystem' => $configure['filesystem'] ?? '',
];
return new JsonResponse($result, Response::HTTP_OK);
}
/**
* Update public channel settings.
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function update(Request $request): Response
{
$filesystem = $request->input('filesystem');
if (! in_array($filesystem, ['local', 'AliyunOSS'])) {
throw new UnprocessableEntityHttpException('选择的文件系统不受支持');
}
$setting = setting('file-storage');
$setting->set('channels.public', [
'filesystem' => $filesystem,
]);
return new Response('', Response::HTTP_NO_CONTENT);
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\Admin\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse;
use Zhiyi\Plus\Support\Configuration;
use Zhiyi\Plus\Admin\Requests\UpdateImHelperUserRequest;
class ImHelperUserController extends Controller
{
/**
* Fetch im helper user id.
*
* @return \Illuminate\Http\JsonResponse
* @author Seven Du <shiweidu@outlook.com>
*/
public function fetch(): JsonResponse
{
return response()->json(['user' => config('im.helper-user')], 200);
}
/**
* Update im helper user id.
*
* @param \Zhiyi\Plus\Admin\Requests\UpdateImHelperUserRequest $request
* @param \Zhiyi\Plus\Support\Configuration $config
* @return \Illuminate\Http\Response
* @author Seven Du <shiweidu@outlook.com>
*/
// public function update(UpdateImHelperUserRequest $request, Configuration $config): Response
public function update(Request $request, Configuration $config): Response
{
$config->set('im.helper-user', $request->input('user', ''));
return response('', 204);
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\Admin\Controllers\Setting;
use Illuminate\Http\Response;
use function Zhiyi\Plus\setting;
use Illuminate\Http\JsonResponse;
use Zhiyi\Plus\Admin\Controllers\Controller;
use Zhiyi\Plus\Admin\Requests\SetEasemob as SetEasemobRequest;
class Easemob extends Controller
{
/**
* Get configure.
* @return \Illuminate\Http\JsonResponse
*/
public function getConfigure(): JsonResponse
{
$settings = setting('user', 'vendor:easemob', [
'open' => false,
'appKey' => '',
'clientId' => '',
'clientSecret' => '',
'registerType' => 0,
]);
return new JsonResponse($settings, Response::HTTP_OK);
}
/**
* set configure.
* @param \Zhiyi\Plus\Admin\Requests\SetEasemob $request
* @return \Illuminate\Http\Response
*/
public function setConfigure(SetEasemobRequest $request)
{
setting('user')->set('vendor:easemob', [
'open' => (bool) $request->input('open'),
'appKey' => $request->input('appKey'),
'clientId' => $request->input('clientId'),
'clientSecret' => $request->input('clientSecret'),
'registerType' => (int) $request->input('registerType'),
]);
return new Response('', Response::HTTP_NO_CONTENT);
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\Admin\Controllers\Setting;
use Illuminate\Http\Response;
use function Zhiyi\Plus\setting;
use Illuminate\Http\JsonResponse;
use Zhiyi\Plus\Admin\Controllers\Controller;
use Zhiyi\Plus\Admin\Requests\SetQQConfigure as SetQQConfigureRequest;
class QQ extends Controller
{
/**
* Get configure.
* @return \Illuminate\Http\JsonResponse
*/
public function getConfigure(): JsonResponse
{
$settings = setting('user', 'vendor:qq', [
'appId' => '',
'appKey' => '',
]);
return new JsonResponse($settings, Response::HTTP_OK);
}
/**
* set configure.
* @param \Zhiyi\Plus\Admin\Requests\SetQQConfigure $request
* @return \Illuminate\Http\Response
*/
public function setConfigure(SetQQConfigureRequest $request)
{
setting('user')->set('vendor:qq', [
'appId' => $request->input('appId'),
'appKey' => $request->input('appKey'),
]);
return new Response('', Response::HTTP_NO_CONTENT);
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\Admin\Controllers\Setting;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use function Zhiyi\Plus\setting;
use Illuminate\Http\JsonResponse;
use Zhiyi\Plus\Admin\Controllers\Controller;
class Security extends Controller
{
/**
* Get pay validate password switch.
* @return \Illuminate\Http\JsonResponse
*/
public function payValidateSwitch(): JsonResponse
{
$switch = (bool) setting('pay', 'validate-password', false);
return new JsonResponse(['switch' => $switch], JsonResponse::HTTP_OK);
}
/**
* Change pay validate password switch.
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function changePayValidateSwitch(Request $request): Response
{
$switch = (bool) $request->input('switch', false);
setting('pay')->set('validate-password', $switch);
return new Response('', Response::HTTP_NO_CONTENT);
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\Admin\Controllers\Setting;
use Illuminate\Http\Response;
use function Zhiyi\Plus\setting;
use Illuminate\Http\JsonResponse;
use Zhiyi\Plus\Admin\Controllers\Controller;
use Zhiyi\Plus\Admin\Requests\SetWeChatConfigure as SetWeChatConfigureRequest;
class WeChat extends Controller
{
/**
* Get configure.
* @return \Illuminate\Http\JsonResponse
*/
public function getConfigure(): JsonResponse
{
$settings = setting('user', 'vendor:wechat', [
'appSecret' => '',
'appKey' => '',
]);
return new JsonResponse($settings, Response::HTTP_OK);
}
/**
* set configure.
* @param \Zhiyi\Plus\Admin\Requests\SetWeChatConfigureRequest $request
* @return \Illuminate\Http\Response
*/
public function setConfigure(SetWeChatConfigureRequest $request)
{
setting('user')->set('vendor:wechat', [
'appSecret' => $request->input('appSecret'),
'appKey' => $request->input('appKey'),
]);
return new Response('', Response::HTTP_NO_CONTENT);
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\Admin\Controllers\Setting;
use Illuminate\Http\Response;
use function Zhiyi\Plus\setting;
use Illuminate\Http\JsonResponse;
use Zhiyi\Plus\Admin\Controllers\Controller;
use Zhiyi\Plus\Admin\Requests\SetWeChatMpConfigure as SetWeChatMpConfigureRequest;
class WeChatMp extends Controller
{
/**
* Get configure.
* @return \Illuminate\Http\JsonResponse
*/
public function getConfigure(): JsonResponse
{
$settings = setting('user', 'vendor:wechat-mp', [
'appid' => '',
'secret' => '',
]);
return new JsonResponse($settings, Response::HTTP_OK);
}
/**
* set configure.
* @param \Zhiyi\Plus\Admin\Requests\SetWeChatMpConfigure $request
* @return \Illuminate\Http\Response
*/
public function setConfigure(SetWeChatMpConfigureRequest $request)
{
setting('user')->set('vendor:wechat-mp', [
'appid' => $request->input('appid'),
'secret' => $request->input('secret'),
]);
return new Response('', Response::HTTP_NO_CONTENT);
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\Admin\Controllers\Setting;
use Illuminate\Http\Response;
use function Zhiyi\Plus\setting;
use Illuminate\Http\JsonResponse;
use Zhiyi\Plus\Admin\Controllers\Controller;
use Zhiyi\Plus\Admin\Requests\SetWeiboConfigure as SetWeiboConfigureRequest;
class Weibo extends Controller
{
/**
* Get configure.
* @return \Illuminate\Http\JsonResponse
*/
public function getConfigure(): JsonResponse
{
$settings = setting('user', 'vendor:weibo', [
'secret' => '',
'appId' => '',
]);
return new JsonResponse($settings, Response::HTTP_OK);
}
/**
* set configure.
* @param \Zhiyi\Plus\Admin\Requests\SetWeiboConfigureRequest $request
* @return \Illuminate\Http\Response
*/
public function setConfigure(SetWeiboConfigureRequest $request)
{
setting('user')->set('vendor:weibo', [
'secret' => $request->input('secret'),
'appId' => $request->input('appId'),
]);
return new Response('', Response::HTTP_NO_CONTENT);
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\Admin\Controllers;
use Illuminate\Http\Request;
use Zhiyi\Plus\Models\User as UserModel;
use Zhiyi\Plus\Admin\Resources\TrashedUserResource;
class UserTrashedController extends Controller
{
/**
* List trashed users.
*
* @param \Illuminate\Http\Request $request
* @return mixed
* @author Seven Du <shiweidu@outlook.com>
*/
public function index(Request $request)
{
$limit = (int) $request->query('limit', 15);
$offset = (int) $request->query('offset', 0);
$users = UserModel::onlyTrashed()
->limit($limit)
->offset($offset)
->latest()
->get();
return TrashedUserResource::collection($users)
->response()
->setStatusCode(200);
}
/**
* Restore a trashed user.
*
* @param int $user
* @return mixed
* @author Seven Du <shiweidu@outlook.com>
*/
public function restore(int $user)
{
$user = UserModel::withTrashed()
->where('id', $user)
->first();
if ($user && $user->trashed()) {
$user->restore();
}
return response('', 204);
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\Admin\Requests;
use Illuminate\Foundation\Http\FormRequest;
class SetEasemob extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
* @author Seven Du <shiweidu@outlook.com>
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
* @author Seven Du <shiweidu@outlook.com>
*/
public function rules(): array
{
return [
'open' => 'required|boolean',
'appKey' => 'required|string|regex:/[a-z0-9-_]+#[a-z0-9-_]+/is',
'clientId' => 'required|string',
'clientSecret' => 'required|string',
'registerType' => 'required|integer|in:0,1',
];
}
/**
* Get the validation message that apply to the request.
*
* @return array
* @author Seven Du <shiweidu@outlook.com>
*/
public function messages(): array
{
return [
'appKey.regex' => ':attribute格式错误,请填入使用 `#` 符号分割的正确值',
];
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes(): array
{
return [
'open' => '开关',
'appKey' => 'App Key',
'clientId' => 'Client ID',
'clientSecret' => 'client Secret',
'registerType' => '注册方式',
];
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\Admin\Requests;
use Illuminate\Foundation\Http\FormRequest;
class SetQQConfigure extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
* @author Seven Du <shiweidu@outlook.com>
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
* @author Seven Du <shiweidu@outlook.com>
*/
public function rules(): array
{
return [
'appId' => 'required|string',
'appKey' => 'required|string',
];
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\Admin\Requests;
use Illuminate\Foundation\Http\FormRequest;
class SetWeChatConfigure extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
* @author Seven Du <shiweidu@outlook.com>
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
* @author Seven Du <shiweidu@outlook.com>
*/
public function rules(): array
{
return [
'appSecret' => 'required|string',
'appKey' => 'required|string',
];
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\Admin\Requests;
use Illuminate\Foundation\Http\FormRequest;
class SetWeChatMpConfigure extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
* @author Seven Du <shiweidu@outlook.com>
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
* @author Seven Du <shiweidu@outlook.com>
*/
public function rules(): array
{
return [
'appid' => 'required|string',
'secret' => 'required|string',
];
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\Admin\Requests;
use Illuminate\Foundation\Http\FormRequest;
class SetWeiboConfigure extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
* @author Seven Du <shiweidu@outlook.com>
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
* @author Seven Du <shiweidu@outlook.com>
*/
public function rules(): array
{
return [
'appId' => 'required|string',
'secret' => 'required|string',
];
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\Admin\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UpdateImHelperUserRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
* @author Seven Du <shiweidu@outlook.com>
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
* @author Seven Du <shiweidu@outlook.com>
*/
public function rules(): array
{
return [
'user' => 'required|integer|exists:users,id',
];
}
/**
* Get the validation message that apply to the request.
*
* @return array
* @author Seven Du <shiweidu@outlook.com>
*/
public function messages(): array
{
return [
'user.required' => '请输入助手用户 ID',
'user.integer' => '输入的助手用户 ID 不合法,必须是整数类型',
'user.exists' => '设置的助手用户不存在',
];
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\Admin\Resources;
use Illuminate\Support\Carbon;
use Illuminate\Http\Resources\Json\JsonResource;
class TrashedUserResource extends JsonResource
{
/**
* The resource to array handle.
*
* @param \Illuminate\Http\Request $request
* @return array
* @author Seven Du <shiweidu@outlook.com>
*/
public function toArray($request): array
{
// The $request unused.
unset($request);
return [
'id' => $this->id,
'name' => $this->name,
'email' => $this->email,
'phone' => $this->phone,
'deleted_at' => Carbon::parse($this->deleted_at)->toIso8601ZuluString(),
];
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus;
interface AppInterface
{
// TODO.
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus;
use Illuminate\Foundation\Application as LaravelApplication;
class Application extends LaravelApplication implements AppInterface
{
/**
* The ThinkSNS Plus version.
*
* @var string
*/
const VERSION = '2.3.0';
/**
* Create a new Illuminate application instance.
*
* @param string|null $basePath
* @author Seven Du <shiweidu@outlook.com>
*/
public function __construct($basePath = null)
{
parent::__construct($basePath);
// Load configuration after.
$this->afterBootstrapping(\Illuminate\Foundation\Bootstrap\LoadConfiguration::class, function ($app) {
$app->make(\Zhiyi\Plus\Bootstrap\LoadConfiguration::class)
->handle();
});
// Use environment path.
$this->useEnvironmentPath($this->appConfigurePath());
}
/**
* Get the version number of the Laravel framework.
*
* @return string
* @author Seven Du <shiweidu@outlook.com>
*/
public function getLaravelVersion()
{
return parent::VERSION;
}
/**
* Register the core class aliases in the container.
*
* @return void
*/
public function registerCoreContainerAliases()
{
// Register parent core container aliases.
parent::registerCoreContainerAliases();
// Register the app core container aliased.
foreach ([
'app' => [
static::class,
\Zhiyi\Plus\AppInterface::class,
],
'cdn' => [
\Zhiyi\Plus\Contracts\Cdn\UrlFactory::class,
\Zhiyi\Plus\Cdn\UrlManager::class,
],
'at-message' => [
\Zhiyi\Plus\AtMessage\MessageInterface::class,
\Zhiyi\Plus\AtMessage\Message::class,
],
'at-resource-manager' => [
\Zhiyi\Plus\AtMessage\ResourceManagerInterface::class,
\Zhiyi\Plus\AtMessage\ResourceManager::class,
],
] as $abstract => $aliases) {
foreach ($aliases as $alias) {
$this->alias($abstract, $alias);
}
}
}
/**
* The app configure path.
* @param string $path
* @return string
*/
public function appConfigurePath(string $path = ''): string
{
return $this->basePath().'/storage/configure'.($path ? DIRECTORY_SEPARATOR.$path : '');
}
/**
* Get the app YAML configure filename.
* @return string
*/
public function appYamlConfigureFile(): string
{
return $this->appConfigurePath('plus.yml');
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\AtMessage;
use Zhiyi\Plus\Models\User as UserModel;
trait AtMessageHelperTrait
{
/**
* Send at message.
* @param string $content
* @param \Zhiyi\Plus\Models\User $sender
* @param mixed $resource
* @return void
*/
public function sendAtMessage(string $content, UserModel $sender, $resource): void
{
preg_match_all('/\x{00ad}@((?:[^\/]+?))\x{00ad}/iu', $content, $matches);
if (! is_array($matches[1]) || empty($matches[1])) {
return;
}
$users = UserModel::where(function ($query) use ($matches) {
$query = $query->where('name', 'like', array_pop($matches[1]));
foreach ($matches[1] as $username) {
$query = $query->where('name', 'like', $username);
}
return $query;
})->get();
$message = app(Message::class);
foreach ($users as $user) {
$message->send($sender, $user, $resource);
}
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\AtMessage;
use Zhiyi\Plus\Models\User as UserModel;
use Zhiyi\Plus\Notifications\At as AtNotification;
class Message implements MessageInterface
{
/**
* Resources manager.
* @var \Zhiyi\Plus\AtMessage\ResourceManagerInterface
*/
protected $manager;
/**
* Create the message instance.
* @param \Zhiyi\Plus\AtMessage\ResourceManagerInterface $manager
*/
public function __construct(ResourceManagerInterface $manager)
{
$this->manager = $manager;
}
/**
* The message send handler.
* @param \Zhiyi\Plus\Models\User $sender
* @param \Zhiyi\Plus\Models\User $user
* @param mixed $resource
* @return void
*/
public function send(UserModel $sender, UserModel $user, $resource): void
{
$resource = $this->manager->resource($resource, $sender);
$user->notify(new AtNotification($resource, $sender));
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\AtMessage;
use Zhiyi\Plus\Models\User as UserModel;
interface MessageInterface
{
/**
* Send at message.
* @param \Zhiyi\Plus\Models\User $sender
* @param \Zhiyi\Plus\Models\User $user
* @param mixed $resource
* @return void
*/
public function send(UserModel $sender, UserModel $user, $resource): void;
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\AtMessage;
interface ResourceInterface
{
/**
* Get the resourceable type.
* @return string
*/
public function type(): string;
/**
* Get the resourceable id.
* @return int
*/
public function id(): int;
/**
* Get the resource push message.
* @return string
*/
public function message(): string;
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\AtMessage;
use InvalidArgumentException;
use Zhiyi\Plus\Models\User as UserModel;
class ResourceManager implements ResourceManagerInterface
{
/**
* Resource map.
* @var array
*/
public static $map = [
\Zhiyi\Component\ZhiyiPlus\PlusComponentFeed\Models\Feed::class => Resources\Feed::class,
\Zhiyi\Plus\Models\Comment::class => Resources\Comment::class,
];
/**
* Get resource.
* @param mixed $resource
* @param \Zhiyi\Plus\Models\User $sender
* @return \Zhiyi\Plus\AtMessage\ResourceInterface
* @throws \InvalidArgumentException
*/
public function resource($resource, UserModel $sender): ResourceInterface
{
$className = $this->getClassName($resource);
$resourceClass = static::$map[$className] ?? null;
if (! $resourceClass) {
throw new InvalidArgumentException(sprintf(
'Resource [%s] not supported.', $className
));
}
return new $resourceClass($resource, $sender);
}
/**
* Get resource class name.
* @param mixed $resource
* @return string
*/
public function getClassName($resource): string
{
return get_class($resource);
}
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\AtMessage;
use Zhiyi\Plus\Models\User as UserModel;
interface ResourceManagerInterface
{
/**
* Get resource.
* @param mixed $resource
* @param \Zhiyi\Plus\Models\User $sender
* @return \Zhiyi\Plus\AtMessage\ResourceInterface
*/
public function resource($resource, UserModel $sender): ResourceInterface;
/**
* Get resource class name.
* @param mixed $resource
* @return string
*/
public function getClassName($resource): string;
}
<?php
declare(strict_types=1);
/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2016-Present ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to enterprise private license, that is |
* | bundled with this package in the file LICENSE, and is available |
* | through the world-wide-web at the following url: |
* | https://github.com/slimkit/plus/blob/master/LICENSE |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <master@zhiyicx.com> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/
namespace Zhiyi\Plus\AtMessage\Resources;
use Zhiyi\Plus\Models\User as UserModel;
use Zhiyi\Plus\Types\Models as ModelTypes;
use Zhiyi\Plus\AtMessage\ResourceInterface;
use Zhiyi\Plus\Models\Comment as CommentModel;
class Comment implements ResourceInterface
{
/**
* The comment resource.
* @var \Zhiyi\Plus\Models\Comment
*/
protected $comment;
/**
* The sender.
* @var \Zhiyi\Plus\Models\User
*/
protected $sender;
/**
* Create the resource.
* @param \Zhiyi\Plus\Models\Comment $comment
* @param \Zhiyi\Plus\Models\User $sender
*/
public function __construct(CommentModel $comment, UserModel $sender)
{
$this->comment = $comment;
$this->sender = $sender;
}
/**
* Get the resourceable type.
* @return string
*/
public function type(): string
{
$alise = ModelTypes::$types[CommentModel::class] ?? null;
if (is_null($alise)) {
throw new InvalidArgumentException('不支持的资源');
}
return $alise;
}
/**
* Get the resourceable id.
* @return int
*/
public function id(): int
{
return $this->comment->id;
}
/**
* Get the resourceable push message.
* @return string
*/
public function message(): string
{
return sprintf('%s在评论中@了你', $this->sender->name);
}
}
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment