-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
134 additions
and
153 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
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,5 @@ | ||
import Extend from 'flarum/common/extenders'; | ||
|
||
import { default as commonExtend } from '../common/extend'; | ||
|
||
export default [...commonExtend]; |
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,3 @@ | ||
import Extend from 'flarum/common/extenders'; | ||
|
||
export default []; |
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
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import app from 'flarum/forum/app'; | ||
import { extend, override } from 'flarum/common/extend'; | ||
import IPAddress from 'flarum/common/components/IPAddress'; | ||
import IPInfo from '../models/IPInfo'; | ||
import { getIPData } from '../helpers/IPDataHelper'; | ||
import Tooltip from 'flarum/common/components/Tooltip'; | ||
import Button from 'flarum/common/components/Button'; | ||
import { handleCopyIP } from '../helpers/ClipboardHelper'; | ||
import MapModal from '../components/MapModal'; | ||
|
||
export default function extendIpAddress() { | ||
extend(IPAddress.prototype, 'viewItems', function (items) { | ||
if (!this.ipInfo) { | ||
this.loadIpInfo(); | ||
} | ||
if (this.ipInfo && items.has('ip')) { | ||
items.remove('ip'); | ||
|
||
const { description, threat, image } = getIPData(this.ipInfo); | ||
|
||
items.add( | ||
'ipInfo', | ||
<span className="ip-info"> | ||
{image} | ||
<Tooltip text={`${description} ${threat ? `(${threat})` : ''}`}> | ||
<code>{this.ip}</code> | ||
</Tooltip> | ||
</span>, | ||
100 | ||
); | ||
|
||
items.add( | ||
'copyButton', | ||
<Tooltip text={app.translator.trans('fof-geoip.forum.copy_ip_label')}> | ||
<Button | ||
icon="fas fa-copy" | ||
className="Button Button--icon Button--link" | ||
onclick={handleCopyIP(this.ip)} | ||
aria-label={app.translator.trans('fof-geoip.forum.copy_ip_label')} | ||
/> | ||
</Tooltip>, | ||
95 | ||
); | ||
|
||
items.add( | ||
'infoButton', | ||
<Tooltip text={app.translator.trans('fof-geoip.forum.map_button_label')}> | ||
<Button | ||
icon="fas fa-info-circle" | ||
className="Button Button--icon Button--link" | ||
onclick={(e: Event) => { | ||
e.stopPropagation(); | ||
app.modal.show(MapModal, { ipInfo: this.ipInfo, ipAddr: this.ip }); | ||
}} | ||
aria-label={app.translator.trans('fof-geoip.forum.map_button_label')} | ||
/> | ||
</Tooltip>, | ||
90 | ||
); | ||
} | ||
}); | ||
|
||
override(IPAddress.prototype, 'view', function () { | ||
return <span className="IPAddress IPAddress--enhanced ip-container">{this.viewItems().toArray()}</span>; | ||
}); | ||
|
||
IPAddress.prototype.loadIpInfo = async function () { | ||
if (this.ip.length === 0) return; | ||
const ipInfo = app.store.getBy<IPInfo>('ip_info', 'ip', this.ip) || (await app.store.find<IPInfo>('ip_info', encodeURIComponent(this.ip))); | ||
this.ipInfo = ipInfo; | ||
m.redraw(); | ||
}; | ||
} |
This file was deleted.
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 |
---|---|---|
@@ -1,16 +1,14 @@ | ||
import app from 'flarum/forum/app'; | ||
import extendPostMeta from './extenders/extendPostMeta'; | ||
import extendBanIPModal from './extenders/extendBanIPModal'; | ||
import extendAccessTokensList from './extenders/extendAccessTokensList'; | ||
import extendCommentPost from './extenders/extendCommentPost'; | ||
import extendUserPreferences from './extenders/extendUserPreferences'; | ||
import extendIpAddress from './extenders/extendIpAddress'; | ||
|
||
export { default as extend } from './extend'; | ||
|
||
app.initializers.add('fof/geoip', () => { | ||
extendPostMeta(); | ||
extendBanIPModal(); | ||
extendAccessTokensList(); | ||
extendCommentPost(); | ||
extendUserPreferences(); | ||
extendIpAddress(); | ||
}); |
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
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
Oops, something went wrong.