mirror of
https://github.com/dwaxweiler/connector-mobilizon
synced 2025-06-05 21:59:25 +02:00
Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
b8ffbdb835 | |||
710103bb10 | |||
c9b04cb2f8 | |||
12e6adacbf | |||
08cad477d1 | |||
0ee1d8cc18 | |||
1e4d0c0a09 | |||
28245574d8 | |||
214fc50d6d | |||
f580b4fb69 | |||
aa8012c8e8 | |||
8b6e312645 | |||
c28d5ec50e | |||
8e9445b60a | |||
4dd1084a3f |
31
.eslintrc.json
Normal file
31
.eslintrc.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"env": {
|
||||
"browser": true,
|
||||
"es2020": true
|
||||
},
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:ava/recommended"
|
||||
],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 11,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"plugins": [
|
||||
"ava"
|
||||
],
|
||||
"rules": {
|
||||
"indent": [
|
||||
"error",
|
||||
2
|
||||
],
|
||||
"quotes": [
|
||||
"error",
|
||||
"single"
|
||||
],
|
||||
"semi": [
|
||||
"error",
|
||||
"never"
|
||||
]
|
||||
}
|
||||
}
|
11
README.md
11
README.md
@ -1,5 +1,9 @@
|
||||
# Connector for Mobilizon
|
||||
|
||||
Connector for Mobilizon allows you to display the upcoming events of [Mobilizon](https://joinmobilizon.org/), which is a federated event listing platform, on your WordPress website.
|
||||
|
||||
More details can be found in the [WordPress Plugin Directory](https://wordpress.org/plugins/connector-mobilizon/).
|
||||
|
||||
## Development
|
||||
|
||||
### Setup
|
||||
@ -17,8 +21,13 @@
|
||||
3. Build: `npm run build-prod`
|
||||
4. Determine minimum PHP version for code and update package.json if needed: `./vendor/bin/phpcompatinfo analyser:run ./source`
|
||||
5. Make sure screenshots are up-to-date.
|
||||
6. Copy the built plugin into `/trunk` of SVN. Also creatte a new tag of the new version. Check the version number occurences in both folders. Commit everything together.
|
||||
6. Copy the built plugin into `/trunk` of SVN.
|
||||
7. Create a new tag of the new version: `svn cp trunk tags/<version>`
|
||||
8. Check the version number occurences in both folders.
|
||||
9. Commit everything together: `svn ci -m "release version <version>"`
|
||||
10. Tag the new version in `git` too.
|
||||
|
||||
### Other commands
|
||||
- Run ESLint: `npm run eslint`
|
||||
- Run tests: `npm test`
|
||||
- Delete build folder: `gulp clean`
|
||||
|
@ -32,7 +32,7 @@ function bundleFrontend() {
|
||||
},
|
||||
}))
|
||||
.pipe(dest(FOLDER_BUILD));
|
||||
}
|
||||
}
|
||||
|
||||
function copyBackend() {
|
||||
return src([
|
||||
@ -52,6 +52,7 @@ function injectMetadata() {
|
||||
.pipe(replace('<wordpress-author-name>', PACKAGE.author.name))
|
||||
.pipe(replace('<wordpress-author-url>', PACKAGE.author.url))
|
||||
.pipe(replace('<wordpress-description>', PACKAGE.description))
|
||||
.pipe(replace('<wordpress-donation-link>', PACKAGE.funding.url))
|
||||
.pipe(replace('<wordpress-license>', PACKAGE.license))
|
||||
.pipe(replace('<wordpress-minimum-version>', PACKAGE.additionalDetails.wordpressMinimumVersion))
|
||||
.pipe(replace('<wordpress-name>', PACKAGE.name))
|
||||
|
12401
package-lock.json
generated
12401
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
18
package.json
18
package.json
@ -1,32 +1,40 @@
|
||||
{
|
||||
"name": "connector-mobilizon",
|
||||
"version": "0.2.2",
|
||||
"version": "0.3.0",
|
||||
"description": "Display mobilizon events in WordPress.",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build-dev": "gulp dev",
|
||||
"build-prod": "ava && gulp prod",
|
||||
"eslint": "npx eslint source/**/*.js",
|
||||
"test": "ava"
|
||||
},
|
||||
"author": {
|
||||
"name": "Daniel Waxweiler",
|
||||
"url": "https://www.danielwaxweiler.net/"
|
||||
},
|
||||
"funding": {
|
||||
"type": "individual",
|
||||
"url": "https://paypal.me/dwaxweiler"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"graphql": "^15.5.0",
|
||||
"graphql-request": "^3.4.0",
|
||||
"luxon": "^1.25.0"
|
||||
"luxon": "^1.26.0",
|
||||
"object-hash": "^2.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^3.15.0",
|
||||
"del": "^6.0.0",
|
||||
"eslint": "^7.23.0",
|
||||
"eslint-plugin-ava": "^12.0.0",
|
||||
"esm": "^3.2.25",
|
||||
"gulp": "^4.0.2",
|
||||
"gulp-replace": "^1.0.0",
|
||||
"jsdom": "^16.5.0",
|
||||
"webpack": "^5.24.4",
|
||||
"webpack-cli": "^4.5.0",
|
||||
"jsdom": "^16.5.2",
|
||||
"webpack": "^5.30.0",
|
||||
"webpack-cli": "^4.6.0",
|
||||
"webpack-stream": "^6.1.2"
|
||||
},
|
||||
"ava": {
|
||||
|
@ -6,6 +6,15 @@
|
||||
#### Fixed
|
||||
#### Security
|
||||
|
||||
### [0.3.0] - 2021-04-05
|
||||
#### Added
|
||||
- Donation link to WordPress Plugin Directory sidebar and to `package.json`
|
||||
- Cache requests for 2 minutes
|
||||
- Set up ESLint static code analysis
|
||||
#### Changed
|
||||
- Update luxon dependency
|
||||
- Update dev dependencies jsdom, webpack, webpack-cli
|
||||
|
||||
### [0.2.2] - 2021-03-10
|
||||
#### Changed
|
||||
- Confirm compatibility with WordPress 5.7
|
||||
|
@ -1,5 +1,5 @@
|
||||
import test from 'ava';
|
||||
import { DateTimeWrapper } from './date-time-wrapper';
|
||||
import test from 'ava'
|
||||
import { DateTimeWrapper } from './date-time-wrapper'
|
||||
|
||||
test('#getShortDate usual date', t => {
|
||||
const d = new DateTimeWrapper('2020-12-24T16:45:00Z')
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { DateTime } from 'luxon';
|
||||
import { DateTime } from 'luxon'
|
||||
|
||||
export class DateTimeWrapper {
|
||||
|
||||
@ -23,6 +23,6 @@ export class DateTimeWrapper {
|
||||
}
|
||||
|
||||
static getCurrentDatetimeAsString() {
|
||||
return DateTime.local().toString();
|
||||
return DateTime.local().toString()
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { DateTimeWrapper } from './date-time-wrapper';
|
||||
import { DateTimeWrapper } from './date-time-wrapper'
|
||||
import * as GraphqlWrapper from './graphql-wrapper'
|
||||
import * as HtmlCreator from './html-creator'
|
||||
|
||||
const NAME = '<wordpress-name>';
|
||||
const NAME = '<wordpress-name>'
|
||||
|
||||
function displayEvents(data, list) {
|
||||
const maxEventsCount = list.getAttribute('data-maximum')
|
||||
@ -11,7 +11,7 @@ function displayEvents(data, list) {
|
||||
for (let i = 0; i < eventsCount; i++) {
|
||||
const li = document.createElement('li')
|
||||
|
||||
const a = HtmlCreator.createAnchorElement({ text: events[i].title, url: events[i].url });
|
||||
const a = HtmlCreator.createAnchorElement({ text: events[i].title, url: events[i].url })
|
||||
li.appendChild(a)
|
||||
|
||||
const br = document.createElement('br')
|
||||
@ -23,10 +23,10 @@ function displayEvents(data, list) {
|
||||
dateText += ' ' + beginsOn.get24Time()
|
||||
dateText += ' - '
|
||||
if (!beginsOn.equalsDate(endsOn)) {
|
||||
dateText += endsOn.getShortDate() + ' '
|
||||
dateText += endsOn.getShortDate() + ' '
|
||||
}
|
||||
dateText += endsOn.get24Time()
|
||||
const textnode = document.createTextNode(dateText);
|
||||
const textnode = document.createTextNode(dateText)
|
||||
li.appendChild(textnode)
|
||||
|
||||
list.appendChild(li)
|
||||
@ -44,7 +44,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const eventLists = document.getElementsByClassName(NAME + '_events-list')
|
||||
for (let list of eventLists) {
|
||||
const url = list.getAttribute('data-url') + '/api'
|
||||
const limit = list.getAttribute('data-maximum')
|
||||
const limit = parseInt(list.getAttribute('data-maximum'))
|
||||
const groupName = list.getAttribute('data-group-name')
|
||||
if (groupName) {
|
||||
GraphqlWrapper.getUpcomingEventsByGroupName({ url, limit, groupName })
|
||||
|
@ -1,30 +1,11 @@
|
||||
import { request, gql } from 'graphql-request'
|
||||
import { SessionCache } from './session-cache'
|
||||
import { request } from 'graphql-request'
|
||||
import { DateTimeWrapper } from './date-time-wrapper'
|
||||
|
||||
export function getUpcomingEvents({ url, limit }) {
|
||||
const query = gql`
|
||||
query {
|
||||
events(limit:${limit}) {
|
||||
elements {
|
||||
id,
|
||||
title,
|
||||
url,
|
||||
beginsOn,
|
||||
endsOn
|
||||
},
|
||||
total
|
||||
}
|
||||
}
|
||||
`
|
||||
return request(url, query)
|
||||
}
|
||||
|
||||
export function getUpcomingEventsByGroupName({ url, limit, groupName }) {
|
||||
const afterDatetime = DateTimeWrapper.getCurrentDatetimeAsString();
|
||||
const query = gql`
|
||||
query {
|
||||
group(preferredUsername:"${groupName}") {
|
||||
organizedEvents(afterDatetime:"${afterDatetime}", limit:${limit}) {
|
||||
const query = `
|
||||
query ($limit: Int) {
|
||||
events(limit: $limit) {
|
||||
elements {
|
||||
id,
|
||||
title,
|
||||
@ -35,7 +16,41 @@ export function getUpcomingEventsByGroupName({ url, limit, groupName }) {
|
||||
total
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
return request(url, query)
|
||||
const dataInCache = SessionCache.get(sessionStorage, { url, query, variables: { limit }})
|
||||
if (dataInCache !== null)
|
||||
return Promise.resolve(dataInCache)
|
||||
return request(url, query, { limit })
|
||||
.then((data) => {
|
||||
SessionCache.add(sessionStorage, { url, query, variables: { limit }}, data)
|
||||
return Promise.resolve(data)
|
||||
})
|
||||
}
|
||||
|
||||
export function getUpcomingEventsByGroupName({ url, limit, groupName }) {
|
||||
const query = `
|
||||
query ($afterDatetime: DateTime, $groupName: String, $limit: Int) {
|
||||
group(preferredUsername: $groupName) {
|
||||
organizedEvents(afterDatetime: $afterDatetime, limit: $limit) {
|
||||
elements {
|
||||
id,
|
||||
title,
|
||||
url,
|
||||
beginsOn,
|
||||
endsOn
|
||||
},
|
||||
total
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
const afterDatetime = DateTimeWrapper.getCurrentDatetimeAsString()
|
||||
const dataInCache = SessionCache.get(sessionStorage, { url, query, variables: { afterDatetime, groupName, limit }})
|
||||
if (dataInCache !== null)
|
||||
return Promise.resolve(dataInCache)
|
||||
return request(url, query, { afterDatetime, groupName, limit })
|
||||
.then((data) => {
|
||||
SessionCache.add(sessionStorage, { url, query, variables: { afterDatetime, groupName, limit }}, data)
|
||||
return Promise.resolve(data)
|
||||
})
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
import test from 'ava';
|
||||
import { JSDOM } from 'jsdom';
|
||||
import test from 'ava'
|
||||
import { JSDOM } from 'jsdom'
|
||||
|
||||
import * as HtmlCreator from './html-creator';
|
||||
import * as HtmlCreator from './html-creator'
|
||||
|
||||
test.beforeEach(() => {
|
||||
global.document = new JSDOM().window.document
|
||||
})
|
||||
|
||||
test('createAnchorElement() usual parameters', t => {
|
||||
test('#createAnchorElement usual parameters', t => {
|
||||
const a = HtmlCreator.createAnchorElement({ text: 'a', url: 'b' })
|
||||
t.is(a.tagName, 'A')
|
||||
t.is(a.innerHTML, 'a')
|
||||
t.is(a.getAttribute('href'), 'b')
|
||||
t.is(a.getAttribute('href'), 'b')
|
||||
})
|
||||
|
@ -0,0 +1,6 @@
|
||||
import test from 'ava'
|
||||
import hash from './object-hash-wrapper'
|
||||
|
||||
test('#hash object', t => {
|
||||
t.is(hash({foo: 'bar'}), 'a75c05bdca7d704bdfcd761913e5a4e4636e956b')
|
||||
})
|
5
source/connector-mobilizon/front/object-hash-wrapper.js
Normal file
5
source/connector-mobilizon/front/object-hash-wrapper.js
Normal file
@ -0,0 +1,5 @@
|
||||
import objectHash from 'object-hash'
|
||||
|
||||
export default function hash(object) {
|
||||
return objectHash(object)
|
||||
}
|
34
source/connector-mobilizon/front/session-cache-test.js
Normal file
34
source/connector-mobilizon/front/session-cache-test.js
Normal file
@ -0,0 +1,34 @@
|
||||
import test from 'ava'
|
||||
import { SessionCache } from './session-cache'
|
||||
|
||||
const fakeStorage = {
|
||||
|
||||
elements: {},
|
||||
|
||||
clear() {
|
||||
this.elements = {}
|
||||
},
|
||||
|
||||
getItem(key) {
|
||||
const value = this.elements[key]
|
||||
if (value === undefined) return null
|
||||
return value
|
||||
},
|
||||
|
||||
setItem(key, value) {
|
||||
this.elements[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
test.afterEach(() => {
|
||||
fakeStorage.clear()
|
||||
})
|
||||
|
||||
test('#add & #get', t => {
|
||||
SessionCache.add(fakeStorage, { a: 'b' }, { c: 'd' })
|
||||
t.deepEqual(SessionCache.get(fakeStorage, { a: 'b' }), { c: 'd' })
|
||||
})
|
||||
|
||||
test('#get no entry', t => {
|
||||
t.is(SessionCache.get(fakeStorage, { a: 'bb' }), null)
|
||||
})
|
24
source/connector-mobilizon/front/session-cache.js
Normal file
24
source/connector-mobilizon/front/session-cache.js
Normal file
@ -0,0 +1,24 @@
|
||||
import hash from './object-hash-wrapper'
|
||||
|
||||
const MAX_AGE_IN_MS = 120000
|
||||
|
||||
export class SessionCache {
|
||||
|
||||
static add(storage, parameters, data) {
|
||||
const key = hash(parameters)
|
||||
const timestamp = Date.now()
|
||||
const value = {
|
||||
data,
|
||||
timestamp,
|
||||
}
|
||||
storage.setItem(key, JSON.stringify(value))
|
||||
}
|
||||
|
||||
static get(storage, parameters) {
|
||||
const key = hash(parameters)
|
||||
const value = JSON.parse(storage.getItem(key))
|
||||
if (value && value.timestamp && value.timestamp > Date.now() - MAX_AGE_IN_MS)
|
||||
return value.data
|
||||
return null
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
# <wordpress-nice-name>
|
||||
Contributors: dwaxweiler
|
||||
Donate link: <wordpress-donation-link>
|
||||
Tags: mobilizon, events
|
||||
Stable tag: <wordpress-version>
|
||||
Requires at least: <wordpress-minimum-version>
|
||||
@ -11,13 +12,15 @@ License: <wordpress-license>
|
||||
|
||||
## Description
|
||||
|
||||
<wordpress-nice-name> allows you to display the upcoming events of [Mobilizon](https://joinmobilizon.org/), which is a federated event listing platform.
|
||||
<wordpress-nice-name> allows you to display the upcoming events of [Mobilizon](https://joinmobilizon.org/), which is a federated event listing platform, on your WordPress website.
|
||||
|
||||
You can display the upcoming events using a widget and everywhere else using a shortcut.
|
||||
|
||||
Shortcut format with limiting the number of events to show to 3 for example: `[<wordpress-name>-events-list events-count=3]`
|
||||
Optionally, you can only show the events of a specific group by indicatings its name: `[<wordpress-name>-events-list events-count=3 group-name="mygroup"]`
|
||||
|
||||
The requests' responses are cached for 2 minutes.
|
||||
|
||||
The source code is available on [Github](https://github.com/dwaxweiler/connector-mobilizon).
|
||||
|
||||
## Screenshots
|
||||
@ -28,6 +31,15 @@ The source code is available on [Github](https://github.com/dwaxweiler/connector
|
||||
|
||||
## Changelog
|
||||
|
||||
### [0.3.0] - 2021-04-05
|
||||
#### Added
|
||||
- Donation link to WordPress Plugin Directory sidebar and to `package.json`
|
||||
- Cache requests for 2 minutes
|
||||
- Set up ESLint static code analysis
|
||||
#### Changed
|
||||
- Update luxon dependency
|
||||
- Update dev dependencies jsdom, webpack, webpack-cli
|
||||
|
||||
### [0.2.2] - 2021-03-10
|
||||
#### Changed
|
||||
- Confirm compatibility with WordPress 5.7
|
||||
|
Reference in New Issue
Block a user