1
0
mirror of https://github.com/dwaxweiler/connector-mobilizon synced 2025-06-05 21:59:25 +02:00

33 Commits

Author SHA1 Message Date
db59e26e65 release version 0.4.0 2021-04-20 21:32:47 +02:00
f5a7e1ed04 update webpack, npm audit fix 2021-04-20 21:21:52 +02:00
f181743ecf add plugin icon 2021-04-20 21:19:18 +02:00
72f2c12343 extract two methods from main file 2021-04-13 21:10:28 +02:00
cf49fb47d6 clean up exports and imports 2021-04-13 20:50:56 +02:00
748649bde3 enable full JS source code coverage 2021-04-13 20:17:07 +02:00
3fd69fc7f6 add changelog entry 2021-04-11 22:48:19 +02:00
540731e28a update dev dependencies 2021-04-11 22:47:49 +02:00
233cdbf8fa show events' location 2021-04-11 22:42:50 +02:00
56d501464e add JS coverage tool 2021-04-09 13:08:29 +02:00
f36e2a6e6a add where caching happens 2021-04-06 08:35:27 +02:00
b8ffbdb835 release version 0.3.0 2021-04-05 18:39:06 +02:00
710103bb10 npm audit fix 2021-04-05 18:26:02 +02:00
c9b04cb2f8 add tests for session-cache, fix a test 2021-04-05 18:23:37 +02:00
12e6adacbf update changelog 2021-04-05 17:57:47 +02:00
08cad477d1 update webpack 2021-04-05 17:57:19 +02:00
0ee1d8cc18 add ESLint 2021-04-05 17:53:47 +02:00
1e4d0c0a09 add few words to description 2021-04-05 17:18:02 +02:00
28245574d8 add 2 min request cache, remove a few unneeded semicolons 2021-04-04 18:03:05 +02:00
214fc50d6d update package json files with donation details 2021-04-04 10:00:02 +02:00
f580b4fb69 add release step of tagging in git 2021-03-28 22:31:16 +02:00
aa8012c8e8 add donation link 2021-03-28 22:28:32 +02:00
8b6e312645 fix name 2021-03-28 22:21:09 +02:00
c28d5ec50e add explanatory sentence and link to WordPress repo 2021-03-28 22:14:29 +02:00
8e9445b60a update dependencies 2021-03-28 22:09:59 +02:00
4dd1084a3f describe release procedure further 2021-03-10 16:40:14 +01:00
4c604c4fc4 release version 0.2.2 2021-03-10 16:22:41 +01:00
db9e9edf00 confirm compatibility with WordPress 5.7 2021-03-10 16:17:29 +01:00
7675e0e2ba updated dependencies 2021-03-10 16:14:37 +01:00
b2f01d46d8 update webpack 2021-01-16 15:25:37 +01:00
e50dc76968 fix whitespace 2021-01-16 15:21:46 +01:00
ac9cca3b26 improve release procedure documentation 2021-01-16 15:21:16 +01:00
1df834cbca fix type of change in changelog 2021-01-15 22:06:57 +01:00
25 changed files with 13684 additions and 706 deletions

31
.eslintrc.json Normal file
View 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"
]
}
}

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
build/
coverage/
node_modules/
vendor/

View File

@ -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
@ -13,10 +17,18 @@
### Release procedure
1. Make sure `changelog.txt` is up-to-date. Use a new version number and copy over the new section into `readme.txt`.
2. Build: `npm run build-prod`
3. Determine minimum PHP version for code and update package.json if needed: `./vendor/bin/phpcompatinfo analyser:run ./source`
4. Make sure screenshots are up-to-date.
2. Update `package.json` with the same version number.
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.
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 JavaScript code coverage with tests: `npm run coverage`
- Run tests: `npm test`
- Delete build folder: `gulp clean`

BIN
assets/icon-128x128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

BIN
assets/icon-256x256.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

16
assets/icon.svg Normal file
View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100%" height="100%" viewBox="0 0 256 256" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
<g transform="matrix(3.1904,0,0,3.1904,-120.199,-271.206)">
<circle cx="37.675" cy="125.127" r="29.385" style="fill:rgb(71,68,103);"/>
</g>
<g transform="matrix(1.26548,0,0,2.29215,-58.5821,-124.97)">
<path d="M120.375,110.363L201.527,106.002L201.527,101.64L221.522,110.363L201.527,119.087L201.527,114.725L120.375,110.363Z" style="fill:rgb(255,213,153);"/>
</g>
<g transform="matrix(1.18916,0.432821,-0.783962,2.15392,28.3042,-121.978)">
<path d="M120.375,110.363L201.527,106.002L201.527,101.64L221.522,110.363L201.527,119.087L201.527,114.725L120.375,110.363Z" style="fill:rgb(255,213,153);"/>
</g>
<g transform="matrix(1.18916,-0.432821,0.783962,2.15392,-144.737,-97.4496)">
<path d="M120.375,110.363L201.527,106.002L201.527,101.64L221.522,110.363L201.527,119.087L201.527,114.725L120.375,110.363Z" style="fill:rgb(255,213,153);"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

387
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -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))

BIN
icon.afdesign Normal file

Binary file not shown.

13560
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,33 +1,43 @@
{
"name": "connector-mobilizon",
"version": "0.2.1",
"version": "0.4.0",
"description": "Display mobilizon events in WordPress.",
"private": true,
"scripts": {
"build-dev": "gulp dev",
"build-prod": "ava && gulp prod",
"coverage": "c8 --all --reporter=html --reporter=text --include=source/**/*.js ava",
"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.4.0",
"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",
"c8": "^7.7.1",
"del": "^6.0.0",
"eslint": "^7.24.0",
"eslint-plugin-ava": "^12.0.0",
"esm": "^3.2.25",
"gulp": "^4.0.2",
"gulp-replace": "^1.0.0",
"jsdom": "^16.4.0",
"webpack": "^5.11.1",
"webpack-cli": "^4.3.1",
"webpack-stream": "^6.1.1"
"jsdom": "^16.5.3",
"webpack": "^5.34.0",
"webpack-cli": "^4.6.0",
"webpack-stream": "^6.1.2"
},
"ava": {
"files": [
@ -41,6 +51,6 @@
"niceName": "Connector for Mobilizon",
"phpMinimumVersion": 5.4,
"wordpressMinimumVersion": 5.6,
"wordpressTestedUpToVersion": 5.6
"wordpressTestedUpToVersion": 5.7
}
}

View File

@ -1,22 +1,47 @@
### [Unreleased]
Added
Changed
Deprecated
Removed
Fixed
Security
#### Added
- Show events' location if set: `description` and `locality` fields
- Plugin icon
#### Changed
- Update dev dependencies eslint, jsdom, webpack
#### Deprecated
#### Removed
#### Fixed
#### Security
### [0.4.0] - 2021-04-20
#### Added
- Show events' location if set: `description` and `locality` fields
- Plugin icon
#### Changed
- Update dev dependencies eslint, jsdom, webpack
### [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
- Update graphql dependency
- Update dev dependencies jsdom, webpack, webpack-cli, webpack-stream
### [0.2.1] - 2021-01-15
Changed
#### Fixed
- Add missing backtick to `readme.txt`
### [0.2.0] - 2021-01-15
Added
#### Added
- `changelog.txt`
- Changelog maintenance steps to `README.md`
- Link to Github repository in `readme.txt`
- Option to show events of a specific group by indicating its name
Changed
#### Changed
- Use same Markdown style in `README.md` as in other documents
### [0.1.0] - 2021-01-09

View File

@ -1,10 +1,10 @@
<?php
/**
* Plugin Name: <wordpress-nice-name>
* Author: <wordpress-author-name>
* Author URI: <wordpress-author-url>
* Description: <wordpress-description>
* Version: <wordpress-version>
* Plugin Name: <wordpress-nice-name>
* Author: <wordpress-author-name>
* Author URI: <wordpress-author-url>
* Description: <wordpress-description>
* Version: <wordpress-version>
* Requires at least: <wordpress-minimum-version>
* Requires PHP: <wordpress-php-minimum-version>
* License: <wordpress-license>

View File

@ -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')

View File

@ -1,6 +1,6 @@
import { DateTime } from 'luxon';
import { DateTime } from 'luxon'
export class DateTimeWrapper {
export default class DateTimeWrapper {
constructor(text) {
this.dateTime = DateTime.fromISO(text)
@ -23,6 +23,6 @@ export class DateTimeWrapper {
}
static getCurrentDatetimeAsString() {
return DateTime.local().toString();
return DateTime.local().toString()
}
}

View File

@ -1,8 +1,8 @@
import { DateTimeWrapper } from './date-time-wrapper';
import Formatter from './formatter'
import * as GraphqlWrapper from './graphql-wrapper'
import * as HtmlCreator from './html-creator'
import { createAnchorElement } from './html-creator'
const NAME = '<wordpress-name>';
const NAME = '<wordpress-name>'
function displayEvents(data, list) {
const maxEventsCount = list.getAttribute('data-maximum')
@ -11,24 +11,30 @@ 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 = createAnchorElement({ text: events[i].title, url: events[i].url })
li.appendChild(a)
const br = document.createElement('br')
li.appendChild(br)
const beginsOn = new DateTimeWrapper(events[i].beginsOn)
const endsOn = new DateTimeWrapper(events[i].endsOn)
let dateText = beginsOn.getShortDate()
dateText += ' ' + beginsOn.get24Time()
dateText += ' - '
if (!beginsOn.equalsDate(endsOn)) {
dateText += endsOn.getShortDate() + ' '
}
dateText += endsOn.get24Time()
const textnode = document.createTextNode(dateText);
const date = Formatter.formatDate({ start: events[i].beginsOn, end: events[i].endsOn })
const textnode = document.createTextNode(date)
li.appendChild(textnode)
if (events[i].physicalAddress) {
const location = Formatter.formatLocation({
description: events[i].physicalAddress.description,
locality: events[i].physicalAddress.locality
})
if (location) {
const brBeforeLocation = document.createElement('br')
li.appendChild(brBeforeLocation)
const textnodeLocation = document.createTextNode(location)
li.appendChild(textnodeLocation)
}
}
list.appendChild(li)
}
}
@ -44,7 +50,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 })

View File

@ -0,0 +1,27 @@
import test from 'ava'
import Formatter from './formatter'
test('#formatDate one date', t => {
const date = Formatter.formatDate({ start: '2021-04-15T10:30:00Z', end: '2021-04-15T15:30:00Z' })
t.is(date, '15/04/2021 12:30 - 17:30')
})
test('#formatDate two dates', t => {
const date = Formatter.formatDate({ start: '2021-04-15T10:30:00Z', end: '2021-04-16T15:30:00Z' })
t.is(date, '15/04/2021 12:30 - 16/04/2021 17:30')
})
test('#formatLocation both parameters', t => {
const date = Formatter.formatLocation({ description: 'a', locality: 'b' })
t.is(date, 'a, b')
})
test('#formatLocation description only', t => {
const date = Formatter.formatLocation({ description: 'a' })
t.is(date, 'a')
})
test('#formatLocation locality only', t => {
const date = Formatter.formatLocation({ locality: 'a' })
t.is(date, 'a')
})

View File

@ -0,0 +1,31 @@
import DateTimeWrapper from './date-time-wrapper'
export default class Formatter {
static formatDate({ start, end }) {
const startDateTime = new DateTimeWrapper(start)
const endDateTime = new DateTimeWrapper(end)
let dateText = startDateTime.getShortDate()
dateText += ' ' + startDateTime.get24Time()
dateText += ' - '
if (!startDateTime.equalsDate(endDateTime)) {
dateText += endDateTime.getShortDate() + ' '
}
dateText += endDateTime.get24Time()
return dateText
}
static formatLocation({ description, locality }) {
let location = ''
if (description) {
location += description
}
if (location && locality) {
location += ', '
}
if (locality) {
location += locality
}
return location
}
}

View File

@ -1,41 +1,64 @@
import { request, gql } from 'graphql-request'
import { DateTimeWrapper } from './date-time-wrapper'
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,
url,
beginsOn,
endsOn
endsOn,
physicalAddress {
description,
locality
}
},
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,
physicalAddress {
description,
locality
}
},
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)
})
}

View File

@ -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')
})

View File

@ -0,0 +1,6 @@
import test from 'ava'
import hash from './object-hash-wrapper'
test('#hash object', t => {
t.is(hash({foo: 'bar'}), 'a75c05bdca7d704bdfcd761913e5a4e4636e956b')
})

View File

@ -0,0 +1,5 @@
import objectHash from 'object-hash'
export default function hash(object) {
return objectHash(object)
}

View 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)
})

View File

@ -0,0 +1,24 @@
import hash from './object-hash-wrapper'
const MAX_AGE_IN_MS = 120000
export default 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
}
}

View File

@ -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 in the browser's `sessionStorage`.
The source code is available on [Github](https://github.com/dwaxweiler/connector-mobilizon).
## Screenshots
@ -28,17 +31,39 @@ The source code is available on [Github](https://github.com/dwaxweiler/connector
## Changelog
### [0.4.0] - 2021-04-20
#### Added
- Show events' location if set: `description` and `locality` fields
- Plugin icon
#### Changed
- Update dev dependencies eslint, jsdom, webpack
### [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
- Update graphql dependency
- Update dev dependencies jsdom, webpack, webpack-cli, webpack-stream
### [0.2.1] - 2021-01-15
Changed
#### Fixed
- Add missing backtick to `readme.txt`
### [0.2.0] - 2021-01-15
Added
#### Added
- `changelog.txt`
- Changelog maintenance steps to `README.md`
- Link to Github repository in `readme.txt`
- Option to show events of a specific group by indicating its name
Changed
#### Changed
- Use same Markdown style in `README.md` as in other documents
### [0.1.0] - 2021-01-09