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

1 Commits

Author SHA1 Message Date
db59e26e65 release version 0.4.0 2021-04-20 21:32:47 +02:00
28 changed files with 1442 additions and 1148 deletions

View File

@ -14,9 +14,6 @@
"plugins": [ "plugins": [
"ava" "ava"
], ],
"ignorePatterns": [
"gulpfile.js"
],
"rules": { "rules": {
"indent": [ "indent": [
"error", "error",

View File

@ -1,71 +0,0 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
on:
push:
branches: [ main ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
schedule:
- cron: '39 19 * * 4'
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
steps:
- name: Checkout repository
uses: actions/checkout@v2
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1

View File

@ -1,29 +0,0 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node.js CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build-prod

View File

@ -18,17 +18,14 @@ More details can be found in the [WordPress Plugin Directory](https://wordpress.
### Release procedure ### 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`. 1. Make sure `changelog.txt` is up-to-date. Use a new version number and copy over the new section into `readme.txt`.
2. Update `package.json` with the same version number. 2. Update `package.json` with the same version number.
3. Update the `package-lock.json`: `npm i --package-lock-only` 3. Build: `npm run build-prod`
4. 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. 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. Make sure screenshots are up-to-date. 6. Copy the built plugin into `/trunk` of SVN.
7. Copy the built plugin into `/trunk` of SVN. 7. Create a new tag of the new version: `svn cp trunk tags/<version>`
8. Create a new tag of the new version: `svn cp trunk tags/<version>` 8. Check the version number occurences in both folders.
9. Check the version number occurences in both folders. 9. Commit everything together: `svn ci -m "release version <version>"`
10. Commit everything together to the release SVN: `svn ci -m "release version <version>"` 10. Tag the new version in `git` too.
11. Commit the new version in git with the same message.
12. Tag the new version: `git tag v<version>`
13. Push the new tag to the repository: `git push --tags`
### Other commands ### Other commands
- Run ESLint: `npm run eslint` - Run ESLint: `npm run eslint`

Binary file not shown.

Before

Width:  |  Height:  |  Size: 60 KiB

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 63 KiB

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

After

Width:  |  Height:  |  Size: 7.5 KiB

2059
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
{ {
"name": "connector-mobilizon", "name": "connector-mobilizon",
"version": "0.6.1", "version": "0.4.0",
"description": "Display Mobilizon events in WordPress.", "description": "Display mobilizon events in WordPress.",
"private": true, "private": true,
"scripts": { "scripts": {
"build-dev": "gulp dev", "build-dev": "gulp dev",
@ -20,23 +20,23 @@
}, },
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"graphql": "^15.5.1", "graphql": "^15.5.0",
"graphql-request": "^3.4.0", "graphql-request": "^3.4.0",
"luxon": "^1.28.0", "luxon": "^1.26.0",
"object-hash": "^2.2.0" "object-hash": "^2.1.1"
}, },
"devDependencies": { "devDependencies": {
"ava": "^3.15.0", "ava": "^3.15.0",
"c8": "^7.7.3", "c8": "^7.7.1",
"del": "^6.0.0", "del": "^6.0.0",
"eslint": "^7.30.0", "eslint": "^7.24.0",
"eslint-plugin-ava": "^12.0.0", "eslint-plugin-ava": "^12.0.0",
"esm": "^3.2.25", "esm": "^3.2.25",
"gulp": "^4.0.2", "gulp": "^4.0.2",
"gulp-replace": "^1.1.3", "gulp-replace": "^1.0.0",
"jsdom": "^16.6.0", "jsdom": "^16.5.3",
"webpack": "^5.44.0", "webpack": "^5.34.0",
"webpack-cli": "^4.7.2", "webpack-cli": "^4.6.0",
"webpack-stream": "^6.1.2" "webpack-stream": "^6.1.2"
}, },
"ava": { "ava": {
@ -51,6 +51,6 @@
"niceName": "Connector for Mobilizon", "niceName": "Connector for Mobilizon",
"phpMinimumVersion": 5.4, "phpMinimumVersion": 5.4,
"wordpressMinimumVersion": 5.6, "wordpressMinimumVersion": 5.6,
"wordpressTestedUpToVersion": 5.8 "wordpressTestedUpToVersion": 5.7
} }
} }

View File

@ -1,33 +1,14 @@
### [Unreleased] ### [Unreleased]
#### Added #### Added
- Show events' location if set: `description` and `locality` fields
- Plugin icon
#### Changed #### Changed
- Update dev dependencies eslint, jsdom, webpack
#### Deprecated #### Deprecated
#### Removed #### Removed
#### Fixed #### Fixed
#### Security #### Security
### [0.6.1] - 2021-07-13
#### Changed
- Confirm compatibility with WordPress 5.8
- Update dependencies
### [0.6.0] - 2021-06-02
#### Added
- Optionally display the current offset as short name after the time via the general plugin settings
#### Changed
- Update dependencies
#### Fixed
- Capitalise Mobilizon name in description
### [0.5.0] - 2021-05-06
#### Added
- Localise dates based on the WordPress locale and time zone
#### Changed
- Clearly list features in `readme.txt` description
- Update dev dependencies c8, eslint, gulp-replace, webpack
#### Fixed
- Improve translatability
### [0.4.0] - 2021-04-20 ### [0.4.0] - 2021-04-20
#### Added #### Added
- Show events' location if set: `description` and `locality` fields - Show events' location if set: `description` and `locality` fields

View File

@ -2,42 +2,42 @@ import test from 'ava'
import DateTimeWrapper from './date-time-wrapper' import DateTimeWrapper from './date-time-wrapper'
test('#getShortDate usual date', t => { test('#getShortDate usual date', t => {
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' }) const d = new DateTimeWrapper('2020-12-24T16:45:00Z')
t.is(d.getShortDate(), '24/12/2020') t.is(d.getShortDate(), '24/12/2020')
}) })
test('#get24Time usual time', t => { test('#get24Time usual time', t => {
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' }) const d = new DateTimeWrapper('2020-12-24T16:45:00Z')
t.is(d.get24Time(), '16:45') t.is(d.get24Time(), '17:45')
}) })
test('#equalsDate same date, different time', t => { test('#equalsDate same date, different time', t => {
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' }) const d = new DateTimeWrapper('2020-12-24T16:45:00Z')
const e = new DateTimeWrapper({ text: '2020-12-24T17:46:01Z' }) const e = new DateTimeWrapper('2020-12-24T17:46:01Z')
t.true(d.equalsDate(e)) t.true(d.equalsDate(e))
}) })
test('#equalsDate different date, different time', t => { test('#equalsDate different date, different time', t => {
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' }) const d = new DateTimeWrapper('2020-12-24T16:45:00Z')
const e = new DateTimeWrapper({ text: '2021-11-25T17:46:01Z' }) const e = new DateTimeWrapper('2021-11-25T17:46:01Z')
t.false(d.equalsDate(e)) t.false(d.equalsDate(e))
}) })
test('#equalsDate different day, different time', t => { test('#equalsDate different day, different time', t => {
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' }) const d = new DateTimeWrapper('2020-12-24T16:45:00Z')
const e = new DateTimeWrapper({ text: '2020-12-25T17:46:01Z' }) const e = new DateTimeWrapper('2020-12-25T17:46:01Z')
t.false(d.equalsDate(e)) t.false(d.equalsDate(e))
}) })
test('#equalsDate different month, different time', t => { test('#equalsDate different month, different time', t => {
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' }) const d = new DateTimeWrapper('2020-12-24T16:45:00Z')
const e = new DateTimeWrapper({ text: '2020-11-24T17:46:01Z' }) const e = new DateTimeWrapper('2020-11-24T17:46:01Z')
t.false(d.equalsDate(e)) t.false(d.equalsDate(e))
}) })
test('#equalsDate different year, different time', t => { test('#equalsDate different year, different time', t => {
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' }) const d = new DateTimeWrapper('2020-12-24T16:45:00Z')
const e = new DateTimeWrapper({ text: '2021-12-24T17:46:01Z' }) const e = new DateTimeWrapper('2021-12-24T17:46:01Z')
t.false(d.equalsDate(e)) t.false(d.equalsDate(e))
}) })
@ -51,8 +51,3 @@ test('#getCurrentDatetimeAsString correct format', t => {
t.is(d[19], '.') t.is(d[19], '.')
t.is(d[d.length-3], ':') t.is(d[d.length-3], ':')
}) })
test('#getShortOffsetName usual time', t => {
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' })
t.is(d.getShortOffsetName(), 'UTC')
})

View File

@ -2,18 +2,14 @@ import { DateTime } from 'luxon'
export default class DateTimeWrapper { export default class DateTimeWrapper {
constructor({ locale = 'en-GB', text, timeZone = 'utc' } = {}) { constructor(text) {
this.dateTime = DateTime.fromISO(text, { locale, zone: timeZone }) this.dateTime = DateTime.fromISO(text)
} }
getShortDate() { getShortDate() {
return this.dateTime.toLocaleString(DateTime.DATE_SHORT) return this.dateTime.toLocaleString(DateTime.DATE_SHORT)
} }
getShortOffsetName() {
return this.dateTime.offsetNameShort
}
get24Time() { get24Time() {
return this.dateTime.toLocaleString(DateTime.TIME_24_SIMPLE) return this.dateTime.toLocaleString(DateTime.TIME_24_SIMPLE)
} }
@ -27,6 +23,6 @@ export default class DateTimeWrapper {
} }
static getCurrentDatetimeAsString() { static getCurrentDatetimeAsString() {
return DateTime.now().toString() return DateTime.local().toString()
} }
} }

View File

@ -1,61 +0,0 @@
import test from 'ava'
import { JSDOM } from 'jsdom'
import { displayEvents, displayErrorMessage } from './events-displayer'
let document
test.before(() => {
document = new JSDOM().window.document
})
test.beforeEach(t => {
t.context.list = document.createElement('ul')
t.context.list.setAttribute('data-locale', 'en-GB')
t.context.list.setAttribute('data-maximum', '2')
t.context.list.setAttribute('data-time-zone', 'utc')
const listElement = document.createElement('li')
listElement.setAttribute('style', 'display: none;')
t.context.list.appendChild(listElement)
})
test('#displayEvents one event', t => {
const list = t.context.list
const data = {
events: {
elements: [
{
title: 'a',
url: 'b',
beginsOn: '2021-04-15T10:30:00Z',
endsOn: '2021-04-15T15:30:00Z',
physicalAddress: {
description: 'c',
locality: 'd'
}
}
]
}
}
displayEvents({ data, document, list })
t.is(list.children.length, 2)
t.is(list.children[1].childNodes[0].tagName, 'A')
t.is(list.children[1].childNodes[0].getAttribute('href'), 'b')
t.is(list.children[1].childNodes[0].childNodes[0].nodeValue, 'a')
t.is(list.children[1].childNodes[1].tagName, 'BR')
t.is(list.children[1].childNodes[2].nodeValue, '15/04/2021 10:30 - 15:30')
t.is(list.children[1].childNodes[3].tagName, 'BR')
t.is(list.children[1].childNodes[4].nodeValue, 'c, d')
})
test('#displayErrorMessage no children added', t => {
const list = t.context.list
displayErrorMessage({ data: '', list })
t.is(list.children.length, 1)
})
test('#displayErrorMessage error message display', t => {
const list = t.context.list
displayErrorMessage({ data: '', list })
t.is(list.children[0].style.display, 'block')
})

View File

@ -1,51 +0,0 @@
import Formatter from './formatter'
import { createAnchorElement } from './html-creator'
export function displayEvents({ data, document, list }) {
const locale = list.getAttribute('data-locale')
const maxEventsCount = list.getAttribute('data-maximum')
const timeZone = list.getAttribute('data-time-zone')
const isShortOffsetNameShown = list.hasAttribute('data-is-short-offset-name-shown')
const events = data.events ? data.events.elements : data.group.organizedEvents.elements
const eventsCount = Math.min(maxEventsCount, events.length)
for (let i = 0; i < eventsCount; i++) {
const li = document.createElement('li')
const a = createAnchorElement({ document, text: events[i].title, url: events[i].url })
li.appendChild(a)
const br = document.createElement('br')
li.appendChild(br)
const date = Formatter.formatDate({
locale,
start: events[i].beginsOn,
end: events[i].endsOn,
timeZone,
isShortOffsetNameShown,
})
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)
}
}
export function displayErrorMessage({ data, list }) {
console.error(data)
list.children[0].style.display = 'block'
}

View File

@ -1,8 +1,51 @@
import { displayEvents, displayErrorMessage } from './events-displayer' import Formatter from './formatter'
import * as GraphqlWrapper from './graphql-wrapper' import * as GraphqlWrapper from './graphql-wrapper'
import { createAnchorElement } from './html-creator'
const NAME = '<wordpress-name>' const NAME = '<wordpress-name>'
function displayEvents(data, list) {
const maxEventsCount = list.getAttribute('data-maximum')
const events = data.events ? data.events.elements : data.group.organizedEvents.elements
const eventsCount = Math.min(maxEventsCount, events.length)
for (let i = 0; i < eventsCount; i++) {
const li = document.createElement('li')
const a = createAnchorElement({ text: events[i].title, url: events[i].url })
li.appendChild(a)
const br = document.createElement('br')
li.appendChild(br)
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)
}
}
function displayErrorMessage(data, list) {
console.error(data)
for (let i = 0; i < list.children.length; i++) {
list.children[i].style.display = 'block'
}
}
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
const eventLists = document.getElementsByClassName(NAME + '_events-list') const eventLists = document.getElementsByClassName(NAME + '_events-list')
for (let list of eventLists) { for (let list of eventLists) {
@ -11,12 +54,12 @@ document.addEventListener('DOMContentLoaded', () => {
const groupName = list.getAttribute('data-group-name') const groupName = list.getAttribute('data-group-name')
if (groupName) { if (groupName) {
GraphqlWrapper.getUpcomingEventsByGroupName({ url, limit, groupName }) GraphqlWrapper.getUpcomingEventsByGroupName({ url, limit, groupName })
.then((data) => displayEvents({ data, document, list })) .then((data) => displayEvents(data, list))
.catch((data) => displayErrorMessage({ data, list })) .catch((data) => displayErrorMessage(data, list))
} else { } else {
GraphqlWrapper.getUpcomingEvents({ url, limit }) GraphqlWrapper.getUpcomingEvents({ url, limit })
.then((data) => displayEvents({ data, document, list })) .then((data) => displayEvents(data, list))
.catch((data) => displayErrorMessage({ data, list })) .catch((data) => displayErrorMessage(data, list))
} }
} }
}) })

View File

@ -3,22 +3,12 @@ import Formatter from './formatter'
test('#formatDate one date', t => { test('#formatDate one date', t => {
const date = Formatter.formatDate({ start: '2021-04-15T10:30:00Z', end: '2021-04-15T15:30:00Z' }) const date = Formatter.formatDate({ start: '2021-04-15T10:30:00Z', end: '2021-04-15T15:30:00Z' })
t.is(date, '15/04/2021 10:30 - 15:30') t.is(date, '15/04/2021 12:30 - 17:30')
})
test('#formatDate one date with short offset name', t => {
const date = Formatter.formatDate({ start: '2021-04-15T10:30:00Z', end: '2021-04-15T15:30:00Z', isShortOffsetNameShown: true })
t.is(date, '15/04/2021 10:30 - 15:30 (UTC)')
}) })
test('#formatDate two dates', t => { test('#formatDate two dates', t => {
const date = Formatter.formatDate({ start: '2021-04-15T10:30:00Z', end: '2021-04-16T15:30:00Z' }) const date = Formatter.formatDate({ start: '2021-04-15T10:30:00Z', end: '2021-04-16T15:30:00Z' })
t.is(date, '15/04/2021 10:30 - 16/04/2021 15:30') t.is(date, '15/04/2021 12:30 - 16/04/2021 17:30')
})
test('#formatDate two dates with short offset name', t => {
const date = Formatter.formatDate({ start: '2021-04-15T10:30:00Z', end: '2021-04-16T15:30:00Z', isShortOffsetNameShown: true })
t.is(date, '15/04/2021 10:30 (UTC) - 16/04/2021 15:30 (UTC)')
}) })
test('#formatLocation both parameters', t => { test('#formatLocation both parameters', t => {

View File

@ -2,24 +2,16 @@ import DateTimeWrapper from './date-time-wrapper'
export default class Formatter { export default class Formatter {
static formatDate({ locale, timeZone, start, end, isShortOffsetNameShown }) { static formatDate({ start, end }) {
const startDateTime = new DateTimeWrapper({ locale, text: start, timeZone }) const startDateTime = new DateTimeWrapper(start)
const endDateTime = new DateTimeWrapper({ locale, text: end, timeZone }) const endDateTime = new DateTimeWrapper(end)
let dateText = startDateTime.getShortDate() let dateText = startDateTime.getShortDate()
dateText += ' ' + startDateTime.get24Time() dateText += ' ' + startDateTime.get24Time()
dateText += ' - '
if (!startDateTime.equalsDate(endDateTime)) { if (!startDateTime.equalsDate(endDateTime)) {
if (isShortOffsetNameShown) {
dateText += ' (' + startDateTime.getShortOffsetName() + ')'
}
dateText += ' - '
dateText += endDateTime.getShortDate() + ' ' dateText += endDateTime.getShortDate() + ' '
} else {
dateText += ' - '
} }
dateText += endDateTime.get24Time() dateText += endDateTime.get24Time()
if (isShortOffsetNameShown) {
dateText += ' (' + endDateTime.getShortOffsetName() + ')'
}
return dateText return dateText
} }

View File

@ -1,16 +1,14 @@
import test from 'ava' import test from 'ava'
import { JSDOM } from 'jsdom' import { JSDOM } from 'jsdom'
import { createAnchorElement } from './html-creator' import * as HtmlCreator from './html-creator'
let document
test.beforeEach(() => { test.beforeEach(() => {
document = new JSDOM().window.document global.document = new JSDOM().window.document
}) })
test('#createAnchorElement usual parameters', t => { test('#createAnchorElement usual parameters', t => {
const a = createAnchorElement({ document, text: 'a', url: 'b' }) const a = HtmlCreator.createAnchorElement({ text: 'a', url: 'b' })
t.is(a.tagName, 'A') t.is(a.tagName, 'A')
t.is(a.innerHTML, 'a') t.is(a.innerHTML, 'a')
t.is(a.getAttribute('href'), 'b') t.is(a.getAttribute('href'), 'b')

View File

@ -1,4 +1,4 @@
export function createAnchorElement({ document, text, url }) { export function createAnchorElement({ text, url }) {
const a = document.createElement('a') const a = document.createElement('a')
a.setAttribute('href', url) a.setAttribute('href', url)
a.setAttribute('target', '_blank') a.setAttribute('target', '_blank')

View File

@ -9,3 +9,4 @@ if (!defined('ABSPATH')) {
const DEFAULT_EVENTS_COUNT = 5; const DEFAULT_EVENTS_COUNT = 5;
const NAME = '<wordpress-name>'; const NAME = '<wordpress-name>';
const NICE_NAME = '<wordpress-nice-name>'; const NICE_NAME = '<wordpress-nice-name>';
const TEXT_DOMAIN = '<wordpress-name>';

View File

@ -26,11 +26,9 @@ class EventsListShortcut {
$classNamePrefix = NAME; $classNamePrefix = NAME;
$eventsCount = $atts_with_overriden_defaults['events-count']; $eventsCount = $atts_with_overriden_defaults['events-count'];
$locale = str_replace('_', '-', get_locale());
$groupName = $atts_with_overriden_defaults['group-name']; $groupName = $atts_with_overriden_defaults['group-name'];
$url = Settings::getUrl(); $url = Settings::getUrl();
$timeZone = get_option('timezone_string'); $textDomain = TEXT_DOMAIN;
$isShortOffsetNameShown = Settings::isShortOffsetNameShown();
ob_start(); ob_start();
require dirname(__DIR__) . '/view/events-list.php'; require dirname(__DIR__) . '/view/events-list.php';

View File

@ -11,9 +11,9 @@ class EventsListWidget extends \WP_Widget {
public function __construct() { public function __construct() {
parent::__construct( parent::__construct(
NAME . '-events-list', NAME . '-events-list',
NICE_NAME . ' ' . __('Events List', 'connector-mobilizon'), NICE_NAME . ' ' . esc_html__('Events List', TEXT_DOMAIN),
array( array(
'description' => __('A list of the upcoming events of the connected Mobilizon instance.', 'connector-mobilizon'), 'description' => __('A list of the upcoming events of the connected Mobilizon instance.', TEXT_DOMAIN),
), ),
); );
} }
@ -27,11 +27,9 @@ class EventsListWidget extends \WP_Widget {
$classNamePrefix = NAME; $classNamePrefix = NAME;
$eventsCount = $options['eventsCount']; $eventsCount = $options['eventsCount'];
$locale = str_replace('_', '-', get_locale());
$groupName = isset($options['groupName']) ? $options['groupName'] : ''; $groupName = isset($options['groupName']) ? $options['groupName'] : '';
$url = Settings::getUrl(); $url = Settings::getUrl();
$timeZone = get_option('timezone_string'); $textDomain = TEXT_DOMAIN;
$isShortOffsetNameShown = Settings::isShortOffsetNameShown();
require dirname(__DIR__) . '/view/events-list.php'; require dirname(__DIR__) . '/view/events-list.php';
@ -39,9 +37,10 @@ class EventsListWidget extends \WP_Widget {
} }
public function form($options) { public function form($options) {
$title = !empty($options['title']) ? $options['title'] : __('Events', 'connector-mobilizon'); $title = !empty($options['title']) ? $options['title'] : esc_html__('Events', TEXT_DOMAIN);
$eventsCount = !empty($options['eventsCount']) ? $options['eventsCount'] : DEFAULT_EVENTS_COUNT; $eventsCount = !empty($options['eventsCount']) ? $options['eventsCount'] : DEFAULT_EVENTS_COUNT;
$groupName = !empty($options['groupName']) ? $options['groupName'] : ''; $groupName = !empty($options['groupName']) ? $options['groupName'] : '';
$textDomain = TEXT_DOMAIN;
require dirname(__DIR__) . '/view/events-list-widget/form.php'; require dirname(__DIR__) . '/view/events-list-widget/form.php';
} }

View File

@ -9,12 +9,9 @@ if (!defined('ABSPATH')) {
class Settings { class Settings {
private static $DEFAULT_OPTION_URL = 'https://mobilizon.fr'; private static $DEFAULT_OPTION_URL = 'https://mobilizon.fr';
private static $DEFAULT_IS_SHORT_OFFSET_NAME_SHOWN = false;
private static $PAGE_NAME = 'wordpress_mobilizon'; private static $PAGE_NAME = 'wordpress_mobilizon';
private static $OPTIONS_GROUP_NAME = 'wordpress_mobilizon'; private static $OPTIONS_GROUP_NAME = 'wordpress_mobilizon';
private static $OPTION_NAME_IS_SHORT_OFFSET_NAME_SHOWN = 'wordpress_mobilizon_is_short_offset_name_shown';
private static $OPTION_NAME_URL = 'wordpress_mobilizon_url'; private static $OPTION_NAME_URL = 'wordpress_mobilizon_url';
private static $SETTING_FIELD_NAME_IS_SHORT_OFFSET_NAME_SHOWN = 'wordpress_mobilizon_field_is_short_offset_name_shown';
private static $SETTING_FIELD_NAME_URL = 'wordpress_mobilizon_field_url'; private static $SETTING_FIELD_NAME_URL = 'wordpress_mobilizon_field_url';
private static $SETTINGS_SECTION_NAME = 'wordpress_mobilizon_section_general'; private static $SETTINGS_SECTION_NAME = 'wordpress_mobilizon_section_general';
@ -24,10 +21,6 @@ class Settings {
} }
public static function init_settings() { public static function init_settings() {
register_setting(
self::$OPTIONS_GROUP_NAME,
self::$OPTION_NAME_IS_SHORT_OFFSET_NAME_SHOWN
);
register_setting( register_setting(
self::$OPTIONS_GROUP_NAME, self::$OPTIONS_GROUP_NAME,
self::$OPTION_NAME_URL, self::$OPTION_NAME_URL,
@ -36,14 +29,14 @@ class Settings {
add_settings_section( add_settings_section(
self::$SETTINGS_SECTION_NAME, self::$SETTINGS_SECTION_NAME,
__('General Settings', 'connector-mobilizon'), __('General Settings', TEXT_DOMAIN),
'', '',
self::$PAGE_NAME self::$PAGE_NAME
); );
add_settings_field( add_settings_field(
self::$SETTING_FIELD_NAME_URL, self::$SETTING_FIELD_NAME_URL,
__('URL', 'connector-mobilizon'), __('URL', TEXT_DOMAIN),
'MobilizonConnector\Settings::output_field_url', 'MobilizonConnector\Settings::output_field_url',
self::$PAGE_NAME, self::$PAGE_NAME,
self::$SETTINGS_SECTION_NAME, self::$SETTINGS_SECTION_NAME,
@ -51,24 +44,10 @@ class Settings {
'label_for' => self::$SETTING_FIELD_NAME_URL 'label_for' => self::$SETTING_FIELD_NAME_URL
) )
); );
add_settings_field(
self::$SETTING_FIELD_NAME_IS_SHORT_OFFSET_NAME_SHOWN,
__('Display named offset', 'connector-mobilizon'),
'MobilizonConnector\Settings::output_field_is_short_offset_name_shown',
self::$PAGE_NAME,
self::$SETTINGS_SECTION_NAME,
array(
'label_for' => self::$SETTING_FIELD_NAME_IS_SHORT_OFFSET_NAME_SHOWN
)
);
}
public static function output_field_is_short_offset_name_shown($args) {
$isShortOffsetNameShown = self::isShortOffsetNameShown();
require dirname(__DIR__) . '/view/settings/is-short-offset-name-shown-field.php';
} }
public static function output_field_url($args) { public static function output_field_url($args) {
$textDomain = TEXT_DOMAIN;
$url = self::getUrl(); $url = self::getUrl();
require dirname(__DIR__) . '/view/settings/url-field.php'; require dirname(__DIR__) . '/view/settings/url-field.php';
} }
@ -79,7 +58,7 @@ class Settings {
add_settings_error( add_settings_error(
self::$OPTION_NAME_URL, self::$OPTION_NAME_URL,
'wordpress_mobilizon_field_url_error', 'wordpress_mobilizon_field_url_error',
__('The URL is invalid.', 'connector-mobilizon'), __('The URL is invalid.', TEXT_DOMAIN),
'error' 'error'
); );
} }
@ -91,7 +70,7 @@ class Settings {
public static function register_settings_page() { public static function register_settings_page() {
add_options_page( add_options_page(
NICE_NAME . ' ' . __('Settings', 'connector-mobilizon'), NICE_NAME . ' ' . __('Settings', TEXT_DOMAIN),
NICE_NAME, NICE_NAME,
'manage_options', 'manage_options',
NAME . '-settings', NAME . '-settings',
@ -106,21 +85,15 @@ class Settings {
require dirname(__DIR__) . '/view/settings/page.php'; require dirname(__DIR__) . '/view/settings/page.php';
} }
public static function isShortOffsetNameShown() {
return get_option(self::$OPTION_NAME_IS_SHORT_OFFSET_NAME_SHOWN);
}
public static function getUrl() { public static function getUrl() {
return get_option(self::$OPTION_NAME_URL); return get_option(self::$OPTION_NAME_URL);
} }
public static function setDefaultOptions() { public static function setDefaultOptions() {
add_option(self::$OPTION_NAME_IS_SHORT_OFFSET_NAME_SHOWN, self::$DEFAULT_IS_SHORT_OFFSET_NAME_SHOWN);
add_option(self::$OPTION_NAME_URL, self::$DEFAULT_OPTION_URL); add_option(self::$OPTION_NAME_URL, self::$DEFAULT_OPTION_URL);
} }
public static function deleteAllOptions() { public static function deleteAllOptions() {
delete_option(self::$OPTION_NAME_IS_SHORT_OFFSET_NAME_SHOWN);
delete_option(self::$OPTION_NAME_URL); delete_option(self::$OPTION_NAME_URL);
} }

View File

@ -14,18 +14,13 @@ License: <wordpress-license>
<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. <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.
Features You can display the upcoming events using a widget and everywhere else using a shortcut.
- Display events as widget and as shortcut
- Display events' title, date, and location if available
- Cache requests' responses for 2 minutes in the browser's `sessionStorage`
- Configure number of events to show per widget and per shortcut
- Optionally filter events by a specific group per widget and per shortcut
- Set the URL of the Mobilizon instance in the settings
- Toggle adding named offset in brackets after the time in the settings
Shortcut format with limiting the number of events to show to 3 for example: `[<wordpress-name>-events-list events-count=3]` 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"]` 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). The source code is available on [Github](https://github.com/dwaxweiler/connector-mobilizon).
## Screenshots ## Screenshots
@ -36,28 +31,6 @@ The source code is available on [Github](https://github.com/dwaxweiler/connector
## Changelog ## Changelog
### [0.6.1] - 2021-07-13
#### Changed
- Confirm compatibility with WordPress 5.8
- Update dependencies
### [0.6.0] - 2021-06-02
#### Added
- Optionally display the current offset as short name after the time via the general plugin settings
#### Changed
- Update dependencies
#### Fixed
- Capitalise Mobilizon name in description
### [0.5.0] - 2021-05-06
#### Added
- Localise dates based on the WordPress locale and time zone
#### Changed
- Clearly list features in `readme.txt` description
- Update dev dependencies c8, eslint, gulp-replace, webpack
#### Fixed
- Improve translatability
### [0.4.0] - 2021-04-20 ### [0.4.0] - 2021-04-20
#### Added #### Added
- Show events' location if set: `description` and `locality` fields - Show events' location if set: `description` and `locality` fields

View File

@ -5,14 +5,14 @@ if (!defined('ABSPATH')) {
} }
?> ?>
<p> <p>
<label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('Title', 'connector-mobilizon'); ?>:</label> <label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_attr_e('Title', $textDomain); ?>:</label>
<input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($title); ?>"> <input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($title); ?>">
</p> </p>
<p> <p>
<label for="<?php echo esc_attr($this->get_field_id('eventsCount')); ?>"><?php esc_html_e('Number of events to show', 'connector-mobilizon'); ?>:</label> <label for="<?php echo esc_attr($this->get_field_id('eventsCount')); ?>"><?php esc_attr_e('Number of events to show', $textDomain); ?>:</label>
<input class="tiny-text" id="<?php echo esc_attr($this->get_field_id('eventsCount')); ?>" name="<?php echo esc_attr($this->get_field_name('eventsCount')); ?>" type="number" value="<?php echo esc_attr($eventsCount); ?>" min="1"> <input class="tiny-text" id="<?php echo esc_attr($this->get_field_id('eventsCount')); ?>" name="<?php echo esc_attr($this->get_field_name('eventsCount')); ?>" type="number" value="<?php echo esc_attr($eventsCount); ?>" min="1">
</p> </p>
<p> <p>
<label for="<?php echo esc_attr($this->get_field_id('groupName')); ?>"><?php esc_html_e('Group name (optional)', 'connector-mobilizon'); ?>:</label> <label for="<?php echo esc_attr($this->get_field_id('groupName')); ?>"><?php esc_attr_e('Group name (optional)', $textDomain); ?>:</label>
<input class="widefat" id="<?php echo esc_attr($this->get_field_id('groupName')); ?>" name="<?php echo esc_attr($this->get_field_name('groupName')); ?>" type="text" value="<?php echo esc_attr($groupName); ?>"> <input class="widefat" id="<?php echo esc_attr($this->get_field_id('groupName')); ?>" name="<?php echo esc_attr($this->get_field_name('groupName')); ?>" type="text" value="<?php echo esc_attr($groupName); ?>">
</p> </p>

View File

@ -6,10 +6,7 @@ if (!defined('ABSPATH')) {
?> ?>
<ul class="<?php echo esc_attr($classNamePrefix); ?>_events-list" <ul class="<?php echo esc_attr($classNamePrefix); ?>_events-list"
data-url="<?php echo esc_attr($url); ?>" data-url="<?php echo esc_attr($url); ?>"
data-locale="<?php echo esc_attr($locale); ?>"
data-maximum="<?php echo esc_attr($eventsCount); ?>" data-maximum="<?php echo esc_attr($eventsCount); ?>"
data-group-name="<?php echo esc_attr($groupName); ?>" data-group-name="<?php echo esc_attr($groupName); ?>">
data-time-zone="<?php echo esc_attr($timeZone); ?>" <li style="display: none;"><?php echo esc_html_e('The events could not be loaded!', $textDomain); ?></li>
<?php echo $isShortOffsetNameShown ? 'data-is-short-offset-name-shown' : ''; ?>>
<li style="display: none;"><?php esc_html_e('The events could not be loaded!', 'connector-mobilizon'); ?></li>
</ul> </ul>

View File

@ -1,13 +0,0 @@
<?php
// Exit if this file is called directly.
if (!defined('ABSPATH')) {
exit;
}
?>
<input id="<?php echo esc_attr($args['label_for']); ?>"
name="<?php echo esc_attr(self::$OPTION_NAME_IS_SHORT_OFFSET_NAME_SHOWN); ?>"
type="checkbox"
<?php echo $isShortOffsetNameShown == true ? 'checked' : ''; ?>>
<p class="description">
<?php esc_html_e('The time zone of this WordPress installation is used. Whether the current offset should be displayed in brackets after the time, e.g. 10:00 (UTC)', 'connector-mobilizon'); ?>
</p>

View File

@ -10,5 +10,5 @@ if (!defined('ABSPATH')) {
type="url" type="url"
value="<?php echo esc_attr($url); ?>"> value="<?php echo esc_attr($url); ?>">
<p class="description"> <p class="description">
<?php esc_html_e('The URL of the Mobilizon instance whose events you want to list, e.g. https://example.net', 'connector-mobilizon'); ?> <?php esc_html_e('The URL of the Mobilizon instance whose events you want to list, e.g. https://example.net', $textDomain); ?>
</p> </p>