Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Dem13n committed Jan 18, 2021
0 parents commit ba8cca8
Show file tree
Hide file tree
Showing 14 changed files with 174 additions and 0 deletions.
22 changes: 22 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2019 Stichting Flarum (Flarum Foundation)
Copyright (c) 2014-2019 Toby Zerner ([email protected])

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.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## Topic Starter Label

![License](https://img.shields.io/badge/license-MIT-blue.svg)

A [Flarum](http://flarum.org) extension. Extension adds a label to the discussion author


![Topic Starter Label](https://i.imgur.com/yOLYb11.png)


### Installation

```sh
composer require dem13n/topic-starter-label
```

### Updating

```sh
composer update dem13n/topic-starter-label
php flarum cache:clear
```

### Links

- [Packagist](https://packagist.org/packages/dem13n/topic-starter-label)
"# Topic Starter Label"
32 changes: 32 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "dem13n/topic-starter-label",
"description": "Adds a label to the discussion author",
"type": "flarum-extension",
"keywords": ["discussion"],
"license": "MIT",
"authors": [
{
"name": "Dem13n",
"email": "[email protected]"
}
],
"require": {
"flarum/core": "^0.1.0-beta.15"
},
"autoload": {
"psr-4": {
"Dem13n\\Topic\\Starter\\Label\\": "src/"
}
},
"extra": {
"flarum-extension": {
"title": "Topic Starter Label",
"category": "discussion",
"icon": {
"name": "fas fa-crown",
"backgroundColor": "#2B6205",
"color": "#fff"
}
}
}
}
11 changes: 11 additions & 0 deletions extend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

use Flarum\Extend;

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

new Extend\Locales(__DIR__ . '/locale'),
];
1 change: 1 addition & 0 deletions js/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
2 changes: 2 additions & 0 deletions js/dist/forum.js

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

1 change: 1 addition & 0 deletions js/dist/forum.js.map

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

10 changes: 10 additions & 0 deletions js/forum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

export * from './src/forum';
13 changes: 13 additions & 0 deletions js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"private": true,
"name": "@dem13n/topic-starter-label",
"dependencies": {
"flarum-webpack-config": "0.1.0-beta.10",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11"
},
"scripts": {
"dev": "webpack --mode development --watch",
"build": "webpack --mode production"
}
}
37 changes: 37 additions & 0 deletions js/src/forum/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {extend} from 'flarum/extend';
import app from 'flarum/app';
import PostUser from 'flarum/components/PostUser';

function checkFP(post) {
const firstPost = post.discussion().firstPost();
if (firstPost) {
return (firstPost.id() !== post.id());
} else {
return true;
}
}

app.initializers.add('dem13n-topic-starter-label', () => {

extend(PostUser.prototype, 'view', function (vnode) {

const routeName = app.current.get('routeName');

if (routeName === 'discussion' || routeName === 'discussion.near') {

const post = this.attrs.post;
const postAuthor = post.user().id();
const discussionAuthor = post.discussion().user().id();

if (!discussionAuthor && !postAuthor) {
return;
}

if (postAuthor === discussionAuthor && checkFP(post)) {
vnode.children.push(
<span className="topicStarter">{app.translator.trans('dem13n.forum.topic_starter')}</span>
);
}
}
});
});
3 changes: 3 additions & 0 deletions js/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const config = require('flarum-webpack-config');

module.exports = config();
9 changes: 9 additions & 0 deletions less/forum.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.topicStarter {
margin-left: 10px;
padding: 1px 10px 3px 10px;
background: @primary-color;
color: white;
border-radius: 4px;
font-size: 14px;
display: inline;
}
3 changes: 3 additions & 0 deletions locale/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dem13n:
forum:
topic_starter: Topic starter
3 changes: 3 additions & 0 deletions locale/ru.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dem13n:
forum:
topic_starter: Автор темы

0 comments on commit ba8cca8

Please sign in to comment.