mirror of
https://github.com/dwaxweiler/connector-mobilizon
synced 2025-06-05 21:59:25 +02:00
Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
4c604c4fc4 | |||
db9e9edf00 | |||
7675e0e2ba | |||
b2f01d46d8 | |||
e50dc76968 | |||
ac9cca3b26 | |||
1df834cbca | |||
23abafe9dc | |||
d49a1a9912 | |||
bb64c9b9bd | |||
4dfeabcb84 | |||
47945372f9 | |||
cd94a764bf | |||
cf5ce6eb76 |
12
README.md
12
README.md
@ -1,4 +1,4 @@
|
|||||||
# Connector Mobilizon
|
# Connector for Mobilizon
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
@ -9,11 +9,15 @@
|
|||||||
|
|
||||||
### Development build
|
### Development build
|
||||||
1. Build: `npm run build-dev`
|
1. Build: `npm run build-dev`
|
||||||
|
2. Make sure to keep `changelog.txt` up-to-date.
|
||||||
|
|
||||||
### Release procedure
|
### Release procedure
|
||||||
1. Build: `npm run build-prod`
|
1. Make sure `changelog.txt` is up-to-date. Use a new version number and copy over the new section into `readme.txt`.
|
||||||
2. Determine minimum PHP version for code and update package.json if needed: `./vendor/bin/phpcompatinfo analyser:run ./source`
|
2. Update `package.json` with the same version number.
|
||||||
3. Make sure screenshots are up-to-date.
|
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.
|
||||||
|
|
||||||
### Other commands
|
### Other commands
|
||||||
- Run tests: `npm test`
|
- Run tests: `npm test`
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 14 KiB |
Binary file not shown.
Before Width: | Height: | Size: 6.0 KiB After Width: | Height: | Size: 7.5 KiB |
387
composer.lock
generated
387
composer.lock
generated
File diff suppressed because it is too large
Load Diff
854
package-lock.json
generated
854
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
14
package.json
14
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "connector-mobilizon",
|
"name": "connector-mobilizon",
|
||||||
"version": "0.1.0",
|
"version": "0.2.2",
|
||||||
"description": "Display mobilizon events in WordPress.",
|
"description": "Display mobilizon events in WordPress.",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -14,7 +14,7 @@
|
|||||||
},
|
},
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"graphql": "^15.4.0",
|
"graphql": "^15.5.0",
|
||||||
"graphql-request": "^3.4.0",
|
"graphql-request": "^3.4.0",
|
||||||
"luxon": "^1.25.0"
|
"luxon": "^1.25.0"
|
||||||
},
|
},
|
||||||
@ -24,10 +24,10 @@
|
|||||||
"esm": "^3.2.25",
|
"esm": "^3.2.25",
|
||||||
"gulp": "^4.0.2",
|
"gulp": "^4.0.2",
|
||||||
"gulp-replace": "^1.0.0",
|
"gulp-replace": "^1.0.0",
|
||||||
"jsdom": "^16.4.0",
|
"jsdom": "^16.5.0",
|
||||||
"webpack": "^5.11.1",
|
"webpack": "^5.24.4",
|
||||||
"webpack-cli": "^4.3.1",
|
"webpack-cli": "^4.5.0",
|
||||||
"webpack-stream": "^6.1.1"
|
"webpack-stream": "^6.1.2"
|
||||||
},
|
},
|
||||||
"ava": {
|
"ava": {
|
||||||
"files": [
|
"files": [
|
||||||
@ -41,6 +41,6 @@
|
|||||||
"niceName": "Connector for Mobilizon",
|
"niceName": "Connector for Mobilizon",
|
||||||
"phpMinimumVersion": 5.4,
|
"phpMinimumVersion": 5.4,
|
||||||
"wordpressMinimumVersion": 5.6,
|
"wordpressMinimumVersion": 5.6,
|
||||||
"wordpressTestedUpToVersion": 5.6
|
"wordpressTestedUpToVersion": 5.7
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
29
source/connector-mobilizon/changelog.txt
Normal file
29
source/connector-mobilizon/changelog.txt
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
### [Unreleased]
|
||||||
|
#### Added
|
||||||
|
#### Changed
|
||||||
|
#### Deprecated
|
||||||
|
#### Removed
|
||||||
|
#### Fixed
|
||||||
|
#### Security
|
||||||
|
|
||||||
|
### [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
|
||||||
|
#### Fixed
|
||||||
|
- Add missing backtick to `readme.txt`
|
||||||
|
|
||||||
|
### [0.2.0] - 2021-01-15
|
||||||
|
#### 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
|
||||||
|
- Use same Markdown style in `README.md` as in other documents
|
||||||
|
|
||||||
|
### [0.1.0] - 2021-01-09
|
||||||
|
initial release
|
@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Plugin Name: <wordpress-nice-name>
|
* Plugin Name: <wordpress-nice-name>
|
||||||
* Author: <wordpress-author-name>
|
* Author: <wordpress-author-name>
|
||||||
* Author URI: <wordpress-author-url>
|
* Author URI: <wordpress-author-url>
|
||||||
* Description: <wordpress-description>
|
* Description: <wordpress-description>
|
||||||
* Version: <wordpress-version>
|
* Version: <wordpress-version>
|
||||||
* Requires at least: <wordpress-minimum-version>
|
* Requires at least: <wordpress-minimum-version>
|
||||||
* Requires PHP: <wordpress-php-minimum-version>
|
* Requires PHP: <wordpress-php-minimum-version>
|
||||||
* License: <wordpress-license>
|
* License: <wordpress-license>
|
||||||
|
@ -40,3 +40,14 @@ test('#equalsDate different year, different time', t => {
|
|||||||
const e = new DateTimeWrapper('2021-12-24T17:46:01Z')
|
const e = new DateTimeWrapper('2021-12-24T17:46:01Z')
|
||||||
t.false(d.equalsDate(e))
|
t.false(d.equalsDate(e))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('#getCurrentDatetimeAsString correct format', t => {
|
||||||
|
const d = DateTimeWrapper.getCurrentDatetimeAsString()
|
||||||
|
t.is(d[4], '-')
|
||||||
|
t.is(d[7], '-')
|
||||||
|
t.is(d[10], 'T')
|
||||||
|
t.is(d[13], ':')
|
||||||
|
t.is(d[16], ':')
|
||||||
|
t.is(d[19], '.')
|
||||||
|
t.is(d[d.length-3], ':')
|
||||||
|
})
|
||||||
|
@ -21,4 +21,8 @@ export class DateTimeWrapper {
|
|||||||
this.dateTime.month === other.dateTime.month &&
|
this.dateTime.month === other.dateTime.month &&
|
||||||
this.dateTime.year === other.dateTime.year
|
this.dateTime.year === other.dateTime.year
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static getCurrentDatetimeAsString() {
|
||||||
|
return DateTime.local().toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,59 +4,56 @@ import * as HtmlCreator from './html-creator'
|
|||||||
|
|
||||||
const NAME = '<wordpress-name>';
|
const NAME = '<wordpress-name>';
|
||||||
|
|
||||||
function displayEvents(data, lists) {
|
function displayEvents(data, list) {
|
||||||
for (let list of lists) {
|
const maxEventsCount = list.getAttribute('data-maximum')
|
||||||
const maxEventsCount = list.getAttribute('data-maximum')
|
const events = data.events ? data.events.elements : data.group.organizedEvents.elements
|
||||||
const events = data.events.elements
|
const eventsCount = Math.min(maxEventsCount, events.length)
|
||||||
const eventsCount = Math.min(maxEventsCount, events.length)
|
for (let i = 0; i < eventsCount; i++) {
|
||||||
for (let i = 0; i < eventsCount; i++) {
|
const li = document.createElement('li')
|
||||||
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)
|
||||||
li.appendChild(a)
|
|
||||||
|
|
||||||
const br = document.createElement('br')
|
const br = document.createElement('br')
|
||||||
li.appendChild(br)
|
li.appendChild(br)
|
||||||
|
|
||||||
const beginsOn = new DateTimeWrapper(events[i].beginsOn)
|
const beginsOn = new DateTimeWrapper(events[i].beginsOn)
|
||||||
const endsOn = new DateTimeWrapper(events[i].endsOn)
|
const endsOn = new DateTimeWrapper(events[i].endsOn)
|
||||||
let dateText = beginsOn.getShortDate()
|
let dateText = beginsOn.getShortDate()
|
||||||
dateText += ' ' + beginsOn.get24Time()
|
dateText += ' ' + beginsOn.get24Time()
|
||||||
dateText += ' - '
|
dateText += ' - '
|
||||||
if (!beginsOn.equalsDate(endsOn)) {
|
if (!beginsOn.equalsDate(endsOn)) {
|
||||||
dateText += endsOn.getShortDate() + ' '
|
dateText += endsOn.getShortDate() + ' '
|
||||||
}
|
|
||||||
dateText += endsOn.get24Time()
|
|
||||||
const textnode = document.createTextNode(dateText);
|
|
||||||
li.appendChild(textnode)
|
|
||||||
|
|
||||||
list.appendChild(li)
|
|
||||||
}
|
}
|
||||||
|
dateText += endsOn.get24Time()
|
||||||
|
const textnode = document.createTextNode(dateText);
|
||||||
|
li.appendChild(textnode)
|
||||||
|
|
||||||
|
list.appendChild(li)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function displayErrorMessage(data, lists) {
|
function displayErrorMessage(data, list) {
|
||||||
console.error(data)
|
console.error(data)
|
||||||
for (let list of lists) {
|
for (let i = 0; i < list.children.length; i++) {
|
||||||
for (let i = 0; i < list.children.length; i++) {
|
list.children[i].style.display = 'block'
|
||||||
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')
|
||||||
if (eventLists.length) {
|
for (let list of eventLists) {
|
||||||
// Currently, the URL is the same for all widgets, so just take the first one.
|
const url = list.getAttribute('data-url') + '/api'
|
||||||
const url = eventLists[0].getAttribute('data-url') + '/api';
|
const limit = list.getAttribute('data-maximum')
|
||||||
|
const groupName = list.getAttribute('data-group-name')
|
||||||
let maxEventsCount = 0
|
if (groupName) {
|
||||||
for (let list of eventLists) {
|
GraphqlWrapper.getUpcomingEventsByGroupName({ url, limit, groupName })
|
||||||
maxEventsCount = Math.max(maxEventsCount, list.getAttribute('data-maximum'))
|
.then((data) => displayEvents(data, list))
|
||||||
|
.catch((data) => displayErrorMessage(data, list))
|
||||||
|
} else {
|
||||||
|
GraphqlWrapper.getUpcomingEvents({ url, limit })
|
||||||
|
.then((data) => displayEvents(data, list))
|
||||||
|
.catch((data) => displayErrorMessage(data, list))
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphqlWrapper.getEvents({ url, limit: maxEventsCount })
|
|
||||||
.then((data) => displayEvents(data, eventLists))
|
|
||||||
.catch((data) => displayErrorMessage(data, eventLists))
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { request, gql } from 'graphql-request'
|
import { request, gql } from 'graphql-request'
|
||||||
|
import { DateTimeWrapper } from './date-time-wrapper'
|
||||||
|
|
||||||
export function getEvents({ url, limit }) {
|
export function getUpcomingEvents({ url, limit }) {
|
||||||
const query = gql`
|
const query = gql`
|
||||||
query {
|
query {
|
||||||
events(limit:${limit}) {
|
events(limit:${limit}) {
|
||||||
@ -17,3 +18,24 @@ export function getEvents({ url, limit }) {
|
|||||||
`
|
`
|
||||||
return request(url, query)
|
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}) {
|
||||||
|
elements {
|
||||||
|
id,
|
||||||
|
title,
|
||||||
|
url,
|
||||||
|
beginsOn,
|
||||||
|
endsOn
|
||||||
|
},
|
||||||
|
total
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
return request(url, query)
|
||||||
|
}
|
||||||
|
@ -20,11 +20,13 @@ class EventsListShortcut {
|
|||||||
$atts_with_overriden_defaults = shortcode_atts(
|
$atts_with_overriden_defaults = shortcode_atts(
|
||||||
array(
|
array(
|
||||||
'events-count' => DEFAULT_EVENTS_COUNT,
|
'events-count' => DEFAULT_EVENTS_COUNT,
|
||||||
|
'group-name' => '',
|
||||||
), $atts
|
), $atts
|
||||||
);
|
);
|
||||||
|
|
||||||
$classNamePrefix = NAME;
|
$classNamePrefix = NAME;
|
||||||
$eventsCount = $atts_with_overriden_defaults['events-count'];
|
$eventsCount = $atts_with_overriden_defaults['events-count'];
|
||||||
|
$groupName = $atts_with_overriden_defaults['group-name'];
|
||||||
$url = Settings::getUrl();
|
$url = Settings::getUrl();
|
||||||
$textDomain = TEXT_DOMAIN;
|
$textDomain = TEXT_DOMAIN;
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ class EventsListWidget extends \WP_Widget {
|
|||||||
|
|
||||||
$classNamePrefix = NAME;
|
$classNamePrefix = NAME;
|
||||||
$eventsCount = $options['eventsCount'];
|
$eventsCount = $options['eventsCount'];
|
||||||
|
$groupName = isset($options['groupName']) ? $options['groupName'] : '';
|
||||||
$url = Settings::getUrl();
|
$url = Settings::getUrl();
|
||||||
$textDomain = TEXT_DOMAIN;
|
$textDomain = TEXT_DOMAIN;
|
||||||
|
|
||||||
@ -38,6 +39,7 @@ class EventsListWidget extends \WP_Widget {
|
|||||||
public function form($options) {
|
public function form($options) {
|
||||||
$title = !empty($options['title']) ? $options['title'] : esc_html__('Events', TEXT_DOMAIN);
|
$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'] : '';
|
||||||
$textDomain = TEXT_DOMAIN;
|
$textDomain = TEXT_DOMAIN;
|
||||||
|
|
||||||
require dirname(__DIR__) . '/view/events-list-widget/form.php';
|
require dirname(__DIR__) . '/view/events-list-widget/form.php';
|
||||||
@ -50,6 +52,7 @@ class EventsListWidget extends \WP_Widget {
|
|||||||
$options = array();
|
$options = array();
|
||||||
$options['title'] = !empty($new_options['title']) ? sanitize_text_field($new_options['title']) : '';
|
$options['title'] = !empty($new_options['title']) ? sanitize_text_field($new_options['title']) : '';
|
||||||
$options['eventsCount'] = !empty($new_options['eventsCount']) ? sanitize_text_field($new_options['eventsCount']) : 5;
|
$options['eventsCount'] = !empty($new_options['eventsCount']) ? sanitize_text_field($new_options['eventsCount']) : 5;
|
||||||
|
$options['groupName'] = !empty($new_options['groupName']) ? sanitize_text_field($new_options['groupName']) : '';
|
||||||
return $options;
|
return $options;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
=== <wordpress-nice-name> ===
|
# <wordpress-nice-name>
|
||||||
Contributors: dwaxweiler
|
Contributors: dwaxweiler
|
||||||
Tags: mobilizon, events
|
Tags: mobilizon, events
|
||||||
Stable tag: <wordpress-version>
|
Stable tag: <wordpress-version>
|
||||||
@ -9,22 +9,43 @@ License: <wordpress-license>
|
|||||||
|
|
||||||
<wordpress-description>
|
<wordpress-description>
|
||||||
|
|
||||||
== Description ==
|
## Description
|
||||||
|
|
||||||
<wordpress-nice-name> allows you to display the upcoming events of one Mobilizon instance.
|
<wordpress-nice-name> allows you to display the upcoming events of [Mobilizon](https://joinmobilizon.org/), which is a federated event listing platform.
|
||||||
[Mobilizon](https://joinmobilizon.org/) is an event listening tool.
|
|
||||||
|
|
||||||
You can display the upcoming events using a widget and everywhere else using a shortcut.
|
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: `[<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"]`
|
||||||
|
|
||||||
== Screenshots ==
|
The source code is available on [Github](https://github.com/dwaxweiler/connector-mobilizon).
|
||||||
|
|
||||||
|
## Screenshots
|
||||||
1. Events list
|
1. Events list
|
||||||
2. General settings
|
2. General settings
|
||||||
3. Widget creation
|
3. Widget creation
|
||||||
4. Shortcut creation
|
4. Shortcut creation
|
||||||
|
|
||||||
== Changelog ==
|
## Changelog
|
||||||
|
|
||||||
= 0.1.0 =
|
### [0.2.2] - 2021-03-10
|
||||||
* initial release
|
#### 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
|
||||||
|
#### Fixed
|
||||||
|
- Add missing backtick to `readme.txt`
|
||||||
|
|
||||||
|
### [0.2.0] - 2021-01-15
|
||||||
|
#### 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
|
||||||
|
- Use same Markdown style in `README.md` as in other documents
|
||||||
|
|
||||||
|
### [0.1.0] - 2021-01-09
|
||||||
|
initial release
|
||||||
|
@ -12,3 +12,7 @@ if (!defined('ABSPATH')) {
|
|||||||
<label for="<?php echo esc_attr($this->get_field_id('eventsCount')); ?>"><?php esc_attr_e('Number of events to show', $textDomain); ?>:</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>
|
||||||
|
<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); ?>">
|
||||||
|
</p>
|
||||||
|
@ -5,7 +5,8 @@ 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-maximum="<?php echo esc_attr($eventsCount); ?>"
|
data-maximum="<?php echo esc_attr($eventsCount); ?>"
|
||||||
data-url="<?php echo esc_attr($url); ?>">
|
data-group-name="<?php echo esc_attr($groupName); ?>">
|
||||||
<li style="display: none;"><?php echo esc_html_e('The events could not be loaded!', $textDomain); ?></li>
|
<li style="display: none;"><?php echo esc_html_e('The events could not be loaded!', $textDomain); ?></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
Reference in New Issue
Block a user