-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from v17development/dev
Update
- Loading branch information
Showing
10 changed files
with
375 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import Modal from 'flarum/components/Modal'; | ||
import Button from 'flarum/components/Button'; | ||
import saveSettings from 'flarum/utils/saveSettings'; | ||
import Stream from 'flarum/utils/Stream'; | ||
|
||
export default class DoFollowListModal extends Modal { | ||
oninit(vnode) { | ||
super.oninit(vnode); | ||
|
||
this.domainDoFollowList = []; | ||
|
||
this.baseUrl = app.forum.data.attributes.baseUrl.replace("http://", "").replace("https", ""); | ||
this.domainDoFollowList = typeof app.data.settings.seo_dofollow_domains === "undefined" ? Stream([]) : Stream(JSON.parse(app.data.settings.seo_dofollow_domains)); | ||
|
||
this.startValue = this.domainDoFollowList; | ||
|
||
this.newDomain = Stream(""); | ||
|
||
this.hasChanges = false; | ||
this.loading = false; | ||
} | ||
|
||
title() { | ||
return 'Do-follow list'; | ||
} | ||
|
||
content() { | ||
return ( | ||
<div> | ||
<div className="Modal-body"> | ||
<p>Enter the <b>hostnames</b> of the domains you want to add to the do-follow list.</p> | ||
|
||
<p>The domain you use for your Flarum instance is added to the list by default.</p> | ||
|
||
<p style={{ marginBottom: '15px' }}> | ||
<a href={"https://community.v17.dev/knowledgebase/36"} target={"_blank"}>Learn more</a> about the do-follow list. | ||
</p> | ||
|
||
<div className={"FlarumSEO-DoFollowList"}> | ||
<input type="text" value={this.baseUrl} readonly className={"FormControl"} /> | ||
<Button className={"Button"} icon={"fas fa-times"} disabled /> | ||
</div> | ||
|
||
{this.domainDoFollowList().map((domain, key) => { | ||
return ( | ||
<div className={"FlarumSEO-DoFollowList"}> | ||
<input type="text" value={domain} onkeyup={(e) => this.updateDomain(key, e.target.value)} className={"FormControl"} /> | ||
<Button className={"Button"} icon={"fas fa-times"} onclick={() => this.removeDomain(key)} /> | ||
</div> | ||
) | ||
})} | ||
|
||
<div className={"FlarumSEO-DoFollowList"}> | ||
<input type="text" bidi={this.newDomain} placeholder={"Allow a domain"} onkeydown={(e) => { | ||
if(e.keyCode === 13 && this.newDomain() !== '') { | ||
e.preventDefault(); | ||
this.addDomain(); | ||
} | ||
}} className={"FormControl"} /> | ||
<Button className={`Button ${this.newDomain() !== '' ? 'Button--primary' : ''}`} icon={"fas fa-plus"} onclick={this.addDomain.bind(this)} /> | ||
</div> | ||
</div> | ||
<div style="padding: 25px 30px; text-align: center;"> | ||
<Button | ||
type="submit" | ||
className="Button Button--primary" | ||
loading={this.loading}> | ||
{this.hasChanges ? 'Save changes' : 'Close'} | ||
</Button> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
/** | ||
* Add new domain to the list | ||
*/ | ||
addDomain() { | ||
// Check if the domain is already present | ||
if(this.domainDoFollowList().indexOf(this.newDomain()) >= 0) { | ||
alert("This domain is already present in your do-follow list."); | ||
|
||
this.newDomain(""); | ||
return; | ||
} | ||
|
||
let updatedData = [...this.domainDoFollowList()]; | ||
|
||
updatedData.push(this.newDomain()); | ||
|
||
this.domainDoFollowList(updatedData); | ||
|
||
// Reset domain | ||
this.newDomain(""); | ||
|
||
// Update the hasChanges | ||
this.hasChanges = true; | ||
} | ||
|
||
/** | ||
* Remove domain from the list | ||
* | ||
* @param {number} key | ||
*/ | ||
removeDomain(key) { | ||
let updatedData = [...this.domainDoFollowList()]; | ||
|
||
updatedData.splice(key, 1); | ||
|
||
this.domainDoFollowList(updatedData); | ||
|
||
// Update the hasChanges | ||
this.hasChanges = true; | ||
} | ||
|
||
/** | ||
* Update domain | ||
* | ||
* @param {*} e | ||
*/ | ||
updateDomain(key, value) { | ||
let updatedData = [...this.domainDoFollowList()]; | ||
updatedData[key] = value; | ||
|
||
this.domainDoFollowList(updatedData); | ||
|
||
// Update the hasChanges | ||
this.hasChanges = true; | ||
} | ||
|
||
// Close or save setting | ||
onsubmit(e) { | ||
if(!this.hasChanges) { | ||
this.hide(); | ||
return; | ||
} | ||
|
||
this.loading = true; | ||
|
||
let data = {}; | ||
data.seo_dofollow_domains = JSON.stringify(this.domainDoFollowList().filter(val => val !== "")); | ||
|
||
saveSettings(data).then( | ||
this.onsaved.bind(this) | ||
); | ||
} | ||
|
||
onsaved() { | ||
this.hide(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace V17Development\FlarumSeo; | ||
|
||
use Flarum\Foundation\Application; | ||
use s9e\TextFormatter\Configurator; | ||
use Psr\Http\Message\ServerRequestInterface as Request; | ||
|
||
class ConfigureLinks | ||
{ | ||
public function __invoke(Configurator $configurator) | ||
{ | ||
$configurator->templateNormalizer->append( | ||
function (\DOMElement $template) | ||
{ | ||
foreach ($template->getElementsByTagName('a') as $a) | ||
{ | ||
$a->setAttribute('rel', "{@rel}"); | ||
$a->setAttribute('target', "{@target}"); | ||
} | ||
} | ||
); | ||
} | ||
} |
Oops, something went wrong.