Skip to content

Commit ba8cca8

Browse files
committed
first commit
0 parents  commit ba8cca8

14 files changed

+174
-0
lines changed

Diff for: LICENSE.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2019 Stichting Flarum (Flarum Foundation)
4+
Copyright (c) 2014-2019 Toby Zerner ([email protected])
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

Diff for: README.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## Topic Starter Label
2+
3+
![License](https://img.shields.io/badge/license-MIT-blue.svg)
4+
5+
A [Flarum](http://flarum.org) extension. Extension adds a label to the discussion author
6+
7+
8+
![Topic Starter Label](https://i.imgur.com/yOLYb11.png)
9+
10+
11+
### Installation
12+
13+
```sh
14+
composer require dem13n/topic-starter-label
15+
```
16+
17+
### Updating
18+
19+
```sh
20+
composer update dem13n/topic-starter-label
21+
php flarum cache:clear
22+
```
23+
24+
### Links
25+
26+
- [Packagist](https://packagist.org/packages/dem13n/topic-starter-label)
27+
"# Topic Starter Label"

Diff for: composer.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "dem13n/topic-starter-label",
3+
"description": "Adds a label to the discussion author",
4+
"type": "flarum-extension",
5+
"keywords": ["discussion"],
6+
"license": "MIT",
7+
"authors": [
8+
{
9+
"name": "Dem13n",
10+
"email": "[email protected]"
11+
}
12+
],
13+
"require": {
14+
"flarum/core": "^0.1.0-beta.15"
15+
},
16+
"autoload": {
17+
"psr-4": {
18+
"Dem13n\\Topic\\Starter\\Label\\": "src/"
19+
}
20+
},
21+
"extra": {
22+
"flarum-extension": {
23+
"title": "Topic Starter Label",
24+
"category": "discussion",
25+
"icon": {
26+
"name": "fas fa-crown",
27+
"backgroundColor": "#2B6205",
28+
"color": "#fff"
29+
}
30+
}
31+
}
32+
}

Diff for: extend.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
use Flarum\Extend;
4+
5+
return [
6+
(new Extend\Frontend('forum'))
7+
->js(__DIR__ . '/js/dist/forum.js')
8+
->css(__DIR__ . '/less/forum.less'),
9+
10+
new Extend\Locales(__DIR__ . '/locale'),
11+
];

Diff for: js/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

Diff for: js/dist/forum.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: js/dist/forum.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: js/forum.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* This file is part of Flarum.
3+
*
4+
* (c) Toby Zerner <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
export * from './src/forum';

Diff for: js/package.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"private": true,
3+
"name": "@dem13n/topic-starter-label",
4+
"dependencies": {
5+
"flarum-webpack-config": "0.1.0-beta.10",
6+
"webpack": "^4.43.0",
7+
"webpack-cli": "^3.3.11"
8+
},
9+
"scripts": {
10+
"dev": "webpack --mode development --watch",
11+
"build": "webpack --mode production"
12+
}
13+
}

Diff for: js/src/forum/index.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import {extend} from 'flarum/extend';
2+
import app from 'flarum/app';
3+
import PostUser from 'flarum/components/PostUser';
4+
5+
function checkFP(post) {
6+
const firstPost = post.discussion().firstPost();
7+
if (firstPost) {
8+
return (firstPost.id() !== post.id());
9+
} else {
10+
return true;
11+
}
12+
}
13+
14+
app.initializers.add('dem13n-topic-starter-label', () => {
15+
16+
extend(PostUser.prototype, 'view', function (vnode) {
17+
18+
const routeName = app.current.get('routeName');
19+
20+
if (routeName === 'discussion' || routeName === 'discussion.near') {
21+
22+
const post = this.attrs.post;
23+
const postAuthor = post.user().id();
24+
const discussionAuthor = post.discussion().user().id();
25+
26+
if (!discussionAuthor && !postAuthor) {
27+
return;
28+
}
29+
30+
if (postAuthor === discussionAuthor && checkFP(post)) {
31+
vnode.children.push(
32+
<span className="topicStarter">{app.translator.trans('dem13n.forum.topic_starter')}</span>
33+
);
34+
}
35+
}
36+
});
37+
});

Diff for: js/webpack.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const config = require('flarum-webpack-config');
2+
3+
module.exports = config();

Diff for: less/forum.less

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.topicStarter {
2+
margin-left: 10px;
3+
padding: 1px 10px 3px 10px;
4+
background: @primary-color;
5+
color: white;
6+
border-radius: 4px;
7+
font-size: 14px;
8+
display: inline;
9+
}

Diff for: locale/en.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dem13n:
2+
forum:
3+
topic_starter: Topic starter

Diff for: locale/ru.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dem13n:
2+
forum:
3+
topic_starter: Автор темы

0 commit comments

Comments
 (0)