Skip to content

Commit

Permalink
First submission
Browse files Browse the repository at this point in the history
  • Loading branch information
shebaoting committed Sep 1, 2024
0 parents commit 6c0f43e
Show file tree
Hide file tree
Showing 44 changed files with 4,451 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 2

[*.{diff,md}]
trim_trailing_whitespace = false

[*.{php,xml,json}]
indent_size = 4
20 changes: 20 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
**/.gitattributes export-ignore
**/.gitignore export-ignore
**/.gitmodules export-ignore
**/.github export-ignore
**/.travis export-ignore
**/.travis.yml export-ignore
**/.editorconfig export-ignore
**/.styleci.yml export-ignore

**/phpunit.xml export-ignore
**/tests export-ignore

**/js/dist/**/* -diff
**/js/dist/**/* linguist-generated
**/js/dist-typings/**/* -diff
**/js/dist-typings/**/* linguist-generated
**/js/yarn.lock -diff
**/js/package-lock.json -diff

* text=auto eol=lf
11 changes: 11 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Money PHP

on: [workflow_dispatch, push, pull_request]

jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@main
with:
enable_backend_testing: true

backend_directory: .
18 changes: 18 additions & 0 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Money JS

on: [workflow_dispatch, push, pull_request]

jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_frontend.yml@main
with:
enable_bundlewatch: false
enable_prettier: true
enable_typescript: true

frontend_directory: ./js
backend_directory: .
js_package_manager: yarn
main_git_branch: main
secrets:
bundlewatch_github_token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/vendor
composer.lock
composer.phar

.DS_Store
Thumbs.db
tests/.phpunit.result.cache
/tests/integration/tmp
.vagrant
.idea/*
.vscode
js/coverage-ts
14 changes: 14 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
preset: recommended

enabled:
- logical_not_operators_with_successor_space

disabled:
- align_double_arrow
- blank_line_after_opening_tag
- multiline_array_trailing_comma
- new_with_braces
- phpdoc_align
- phpdoc_order
- phpdoc_separation
- phpdoc_types
9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) <year> <copyright holders>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Money

![License](https://img.shields.io/badge/license-MIT-blue.svg) [![Latest Stable Version](https://img.shields.io/packagist/v/shebaoting/money.svg)](https://packagist.org/packages/shebaoting/money) [![Total Downloads](https://img.shields.io/packagist/dt/shebaoting/money.svg)](https://packagist.org/packages/shebaoting/money)

A [Flarum](http://flarum.org) extension. Adds a virtual currency system to the Flarum community, allowing users to earn and spend points.

This extension is modified from [flarum-ext-money by AntoineFr](https://github.com/AntoineFr/flarum-ext-money). It's an excellent extension, and I want to express my gratitude to the original author. I have added some additional features that I needed and have published it here in the hope that you will enjoy it as well.

## Features

1. **All original features**: The extension retains all the functionalities of the original version.

2. **Points Record**: Added a feature to record all points transactions.

3. **Initial Points on Registration**: New users receive a set amount of points upon registration.

4. **Negative Points Deduction**: If points are set to negative, they will be deducted from the user's own account. If the account has insufficient points, the operation cannot be performed.

5. **Points Redistribution**: When points are negative, and the user replies to a discussion, the deducted points will be awarded to the discussion starter.

6. **Like Reward System**: When points are negative, points deducted from liking a post will be awarded to the person who received the like.

## Idea

The design philosophy behind this system is a metaphor for time.

Everything you do here consumes your time. If a task is completed without receiving any meaningful response, it’s as if the task was done in vain. If a person continues to engage in meaningless activities, they are essentially wasting their time.

For a similar concept, I recommend watching the movie _In Time_.

## Contact
You can also contact me if you wish to pay something to develop the flarum extension.
Email: [email protected]

## Installation

Install with composer:

```sh
composer require shebaoting/money:"*"
```

## Updating

```sh
composer update shebaoting/money:"*"
php flarum migrate
php flarum cache:clear
```

## Links

- [Packagist](https://packagist.org/packages/shebaoting/money)
- [GitHub](https://github.com/shebaoting/money)
- [Discuss](https://discuss.flarum.org/d/PUT_DISCUSS_SLUG_HERE)
78 changes: 78 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"name": "shebaoting/money",
"description": "Adds a virtual currency system to the Flarum community, allowing users to earn and spend points.",
"keywords": [
"flarum"
],
"type": "flarum-extension",
"license": "MIT",
"require": {
"flarum/core": "^1.2.0"
},
"authors": [
{
"name": "Shebaoting",
"email": "[email protected]",
"role": "Developer"
}
],
"autoload": {
"psr-4": {
"Shebaoting\\Money\\": "src/"
}
},
"extra": {
"flarum-extension": {
"title": "Money",
"category": "",
"icon": {
"name": "fas fa-money-bill",
"color": "#fff",
"backgroundColor": "#d13e32"
}
},
"flarum-cli": {
"modules": {
"admin": true,
"forum": true,
"js": true,
"jsCommon": true,
"css": true,
"locale": true,
"gitConf": true,
"githubActions": true,
"prettier": true,
"typescript": true,
"bundlewatch": false,
"backendTesting": true,
"editorConfig": true,
"styleci": true
}
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"autoload-dev": {
"psr-4": {
"Shebaoting\\Money\\Tests\\": "tests/"
}
},
"scripts": {
"test": [
"@test:unit",
"@test:integration"
],
"test:unit": "phpunit -c tests/phpunit.unit.xml",
"test:integration": "phpunit -c tests/phpunit.integration.xml",
"test:setup": "@php tests/integration/setup.php"
},
"scripts-descriptions": {
"test": "Runs all tests.",
"test:unit": "Runs all unit tests.",
"test:integration": "Runs all integration tests.",
"test:setup": "Sets up a database for use with integration tests. Execute this only once."
},
"require-dev": {
"flarum/testing": "^1.0.0"
}
}
75 changes: 75 additions & 0 deletions extend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

/*
* This file is part of shebaoting/money.
*
* Copyright (c) 2024 Shebaoting.
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

namespace Shebaoting\Money;

use Flarum\Extend;
use Flarum\Api\Serializer\UserSerializer;
use Flarum\Post\Event\Posted;
use Flarum\Post\Event\Restored as PostRestored;
use Flarum\Post\Event\Hidden as PostHidden;
use Flarum\Post\Event\Deleted as PostDeleted;
use Flarum\Discussion\Event\Started;
use Flarum\Discussion\Event\Restored as DiscussionRestored;
use Flarum\Discussion\Event\Hidden as DiscussionHidden;
use Flarum\Discussion\Event\Deleted as DiscussionDeleted;
use Flarum\User\Event\Saving;
use Flarum\Post\Event\Saving as SavingPost;
use Flarum\Likes\Event\PostWasLiked;
use Flarum\Likes\Event\PostWasUnliked;
use Flarum\Discussion\Event\Saving as SavingDiscussion;
use Flarum\User\Event\Registered;
use Shebaoting\Money\Controller\UserMoneyLogsController;

$extend = [
(new Extend\Frontend('forum'))
->js(__DIR__ . '/js/dist/forum.js')
->css(__DIR__ . '/less/forum.less')
->route('/money-log', 'user.money-log'),

(new Extend\Frontend('admin'))
->js(__DIR__ . '/js/dist/admin.js')
->css(__DIR__ . '/less/admin.less'),

new Extend\Locales(__DIR__ . '/locale'),

(new Extend\ApiSerializer(UserSerializer::class))
->attributes(AddUserMoneyAttributes::class),

(new Extend\Settings())
->serializeToForum('shebaoting-money.moneyname', 'shebaoting-money.moneyname')
->serializeToForum('shebaoting-money.noshowzero', 'shebaoting-money.noshowzero'),

(new Extend\Event())
->listen(SavingPost::class, [Listeners\GiveMoney::class, 'postWillBeSaved'])
->listen(SavingDiscussion::class, [Listeners\GiveMoney::class, 'discussionWillBeSaved'])
->listen(Posted::class, [Listeners\GiveMoney::class, 'postWasPosted'])
->listen(PostRestored::class, [Listeners\GiveMoney::class, 'postWasRestored'])
->listen(PostHidden::class, [Listeners\GiveMoney::class, 'postWasHidden'])
->listen(PostDeleted::class, [Listeners\GiveMoney::class, 'postWasDeleted'])
->listen(Started::class, [Listeners\GiveMoney::class, 'discussionWasStarted'])
->listen(DiscussionRestored::class, [Listeners\GiveMoney::class, 'discussionWasRestored'])
->listen(DiscussionHidden::class, [Listeners\GiveMoney::class, 'discussionWasHidden'])
->listen(DiscussionDeleted::class, [Listeners\GiveMoney::class, 'discussionWasDeleted'])
->listen(Saving::class, [Listeners\GiveMoney::class, 'userWillBeSaved'])
->listen(Registered::class, [Listeners\GiveMoney::class, 'userWasRegistered']),

(new Extend\Routes('api'))
->get('/money-log', 'money.logs', UserMoneyLogsController::class)
];

if (class_exists('Flarum\Likes\Event\PostWasLiked')) {
$extend[] =
(new Extend\Event())
->listen(PostWasLiked::class, [Listeners\GiveMoney::class, 'postWasLiked'])
->listen(PostWasUnliked::class, [Listeners\GiveMoney::class, 'postWasUnliked']);
}
return $extend;
9 changes: 9 additions & 0 deletions js/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

node_modules
2 changes: 2 additions & 0 deletions js/admin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './src/common';
export * from './src/admin';
2 changes: 2 additions & 0 deletions js/dist/admin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6c0f43e

Please sign in to comment.