mirror of
https://github.com/dwaxweiler/connector-mobilizon
synced 2025-06-05 21:59:25 +02:00
Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
e21c86f2e4 | |||
5bcc03f9d1 | |||
460ea7894d | |||
8caceeaf76 | |||
0c40efd565 | |||
e91ca97e88 | |||
df2feceaaa | |||
bcd1f5247d | |||
e2d34032cd | |||
9708203f3c | |||
370e0d9e46 | |||
9412b9cb90 | |||
72045a31b0 | |||
0edad986d3 | |||
a543a25a8a |
4053
package-lock.json
generated
4053
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
30
package.json
30
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "connector-mobilizon",
|
"name": "connector-mobilizon",
|
||||||
"version": "1.1.0",
|
"version": "1.3.0",
|
||||||
"description": "Display Mobilizon events in WordPress.",
|
"description": "Display Mobilizon events in WordPress.",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
@ -25,31 +25,31 @@
|
|||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"graphql": "16.9.0",
|
"graphql": "16.9.0",
|
||||||
"luxon": "3.4.4"
|
"luxon": "3.5.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "7.24.9",
|
"@babel/core": "7.26.0",
|
||||||
"@babel/eslint-parser": "7.24.8",
|
"@babel/eslint-parser": "7.25.9",
|
||||||
"@babel/preset-env": "7.24.8",
|
"@babel/preset-env": "7.26.0",
|
||||||
"@babel/preset-react": "7.24.7",
|
"@babel/preset-react": "7.25.9",
|
||||||
"@wordpress/eslint-plugin": "20.0.0",
|
"@wordpress/eslint-plugin": "21.4.0",
|
||||||
"ava": "6.1.3",
|
"ava": "6.2.0",
|
||||||
"babel-loader": "9.1.3",
|
"babel-loader": "9.2.1",
|
||||||
"browser-env": "3.3.0",
|
"browser-env": "3.3.0",
|
||||||
"c8": "10.1.2",
|
"c8": "10.1.2",
|
||||||
"copy-webpack-plugin": "12.0.2",
|
"copy-webpack-plugin": "12.0.2",
|
||||||
"eslint": "8.57.0",
|
"eslint": "8.57.0",
|
||||||
"eslint-plugin-ava": "14.0.0",
|
"eslint-plugin-ava": "14.0.0",
|
||||||
"eslint-plugin-jsx": "0.1.0",
|
"eslint-plugin-jsx": "0.1.0",
|
||||||
"eslint-plugin-react": "7.34.4",
|
"eslint-plugin-react": "7.37.2",
|
||||||
"esm": "3.2.25",
|
"esm": "3.2.25",
|
||||||
"gulp": "5.0.0",
|
"gulp": "5.0.0",
|
||||||
"gulp-replace": "1.1.4",
|
"gulp-replace": "1.1.4",
|
||||||
"husky": "9.1.1",
|
"husky": "9.1.6",
|
||||||
"lint-staged": "15.2.7",
|
"lint-staged": "15.2.10",
|
||||||
"prettier": "3.3.3",
|
"prettier": "3.3.3",
|
||||||
"rimraf": "5.0.9",
|
"rimraf": "5.0.10",
|
||||||
"webpack": "5.93.0",
|
"webpack": "5.96.1",
|
||||||
"webpack-cli": "5.1.4"
|
"webpack-cli": "5.1.4"
|
||||||
},
|
},
|
||||||
"ava": {
|
"ava": {
|
||||||
@ -61,7 +61,7 @@
|
|||||||
"niceName": "Connector for Mobilizon",
|
"niceName": "Connector for Mobilizon",
|
||||||
"phpMinimumVersion": 7.4,
|
"phpMinimumVersion": 7.4,
|
||||||
"wordpressMinimumVersion": 5.6,
|
"wordpressMinimumVersion": 5.6,
|
||||||
"wordpressTestedUpToVersion": "6.6"
|
"wordpressTestedUpToVersion": "6.7"
|
||||||
},
|
},
|
||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
"source/**/*.js": "eslint",
|
"source/**/*.js": "eslint",
|
||||||
|
@ -6,6 +6,24 @@
|
|||||||
#### Fixed
|
#### Fixed
|
||||||
#### Security
|
#### Security
|
||||||
|
|
||||||
|
### [1.3.0]
|
||||||
|
#### Added
|
||||||
|
- Comment for translators what placeholder will contain
|
||||||
|
#### Changed
|
||||||
|
- Confirm compatibility with WordPress 6.7
|
||||||
|
- Load block script only in footer to reduce waiting time
|
||||||
|
- Update dependencies
|
||||||
|
#### Fixed
|
||||||
|
- Mark event-related data as non-translatable within plugin
|
||||||
|
- Add version number to script registration to break browser caching
|
||||||
|
- Handle location being null
|
||||||
|
|
||||||
|
### [1.2.0]
|
||||||
|
#### Added
|
||||||
|
- Display event picture if available
|
||||||
|
#### Changed
|
||||||
|
- Update dependencies
|
||||||
|
|
||||||
### [1.1.0]
|
### [1.1.0]
|
||||||
#### Added
|
#### Added
|
||||||
- Add some spacing between event items
|
- Add some spacing between event items
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import Formatter from './formatter.js'
|
import Formatter from './formatter.js'
|
||||||
import { createAnchorElement } from './html-creator.js'
|
import { createAnchorElement, createImageElement } from './html-creator.js'
|
||||||
|
|
||||||
export function clearEventsList(container) {
|
export function clearEventsList(container) {
|
||||||
const list = container.querySelector('ul')
|
const list = container.querySelector('ul')
|
||||||
@ -18,6 +18,19 @@ export function displayEvents({ events, document, container, maxEventsCount }) {
|
|||||||
const list = container.querySelector('ul')
|
const list = container.querySelector('ul')
|
||||||
for (let i = 0; i < eventsCount; i++) {
|
for (let i = 0; i < eventsCount; i++) {
|
||||||
const li = document.createElement('li')
|
const li = document.createElement('li')
|
||||||
|
li.style.lineHeight = '150%'
|
||||||
|
li.style.marginTop = '20px'
|
||||||
|
|
||||||
|
if (events[i].picture) {
|
||||||
|
const img = createImageElement({
|
||||||
|
document,
|
||||||
|
alt: events[i].picture.alt ? events[i].picture.alt : '',
|
||||||
|
src: events[i].picture.base64 ? events[i].picture.base64 : '',
|
||||||
|
})
|
||||||
|
img.style.display = 'block'
|
||||||
|
img.style.maxWidth = '100%'
|
||||||
|
li.appendChild(img)
|
||||||
|
}
|
||||||
|
|
||||||
const a = createAnchorElement({
|
const a = createAnchorElement({
|
||||||
document,
|
document,
|
||||||
|
@ -5,3 +5,10 @@ export function createAnchorElement({ document, text, url }) {
|
|||||||
a.innerHTML = text
|
a.innerHTML = text
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createImageElement({ document, alt, src }) {
|
||||||
|
const img = document.createElement('img')
|
||||||
|
img.setAttribute('alt', alt)
|
||||||
|
img.setAttribute('src', src)
|
||||||
|
return img
|
||||||
|
}
|
||||||
|
@ -10,7 +10,7 @@ class EventsListBlock {
|
|||||||
'wp-blocks',
|
'wp-blocks',
|
||||||
'wp-components',
|
'wp-components',
|
||||||
'wp-i18n'
|
'wp-i18n'
|
||||||
]);
|
], '<wordpress-version>', array('in_footer' => true));
|
||||||
register_block_type(NAME . '/events-list', [
|
register_block_type(NAME . '/events-list', [
|
||||||
'api_version' => 2,
|
'api_version' => 2,
|
||||||
'title' => __('Events List', 'connector-mobilizon'),
|
'title' => __('Events List', 'connector-mobilizon'),
|
||||||
|
@ -26,7 +26,7 @@ final class Formatter
|
|||||||
return $dateText;
|
return $dateText;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function format_location(string $description, string $locality): string {
|
public static function format_location(string $description, ?string $locality): string {
|
||||||
$location = '';
|
$location = '';
|
||||||
if ($description && trim($description)) {
|
if ($description && trim($description)) {
|
||||||
$location .= trim($description);
|
$location .= trim($description);
|
||||||
|
@ -40,6 +40,11 @@ final class GraphQlClient {
|
|||||||
physicalAddress {
|
physicalAddress {
|
||||||
description,
|
description,
|
||||||
locality
|
locality
|
||||||
|
},
|
||||||
|
picture {
|
||||||
|
alt,
|
||||||
|
contentType,
|
||||||
|
url
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
total
|
total
|
||||||
@ -57,6 +62,17 @@ final class GraphQlClient {
|
|||||||
self::checkData($data);
|
self::checkData($data);
|
||||||
|
|
||||||
$events = $data['data']['events']['elements'];
|
$events = $data['data']['events']['elements'];
|
||||||
|
foreach ($events as &$event) {
|
||||||
|
if ($event['picture']) {
|
||||||
|
$picture_response = self::download_image($event['picture']['url']);
|
||||||
|
if ($picture_response !== false) {
|
||||||
|
$picture_encoded = 'data:' . $event['picture']['contentType'] . ';base64,' . base64_encode($picture_response);
|
||||||
|
$event['picture']['base64'] = $picture_encoded;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unset($event);
|
||||||
|
}
|
||||||
|
|
||||||
EventsCache::set(['url' => $url, 'query' => $query, 'limit' => $limit], $events);
|
EventsCache::set(['url' => $url, 'query' => $query, 'limit' => $limit], $events);
|
||||||
return $events;
|
return $events;
|
||||||
}
|
}
|
||||||
@ -75,6 +91,11 @@ final class GraphQlClient {
|
|||||||
physicalAddress {
|
physicalAddress {
|
||||||
description,
|
description,
|
||||||
locality
|
locality
|
||||||
|
},
|
||||||
|
picture {
|
||||||
|
alt,
|
||||||
|
contentType,
|
||||||
|
url
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
total
|
total
|
||||||
@ -95,6 +116,18 @@ final class GraphQlClient {
|
|||||||
self::checkData($data);
|
self::checkData($data);
|
||||||
|
|
||||||
$events = $data['data']['group']['organizedEvents']['elements'];
|
$events = $data['data']['group']['organizedEvents']['elements'];
|
||||||
|
|
||||||
|
foreach ($events as &$event) {
|
||||||
|
if ($event['picture']) {
|
||||||
|
$picture_response = self::download_image($event['picture']['url']);
|
||||||
|
if ($picture_response !== false) {
|
||||||
|
$picture_encoded = 'data:' . $event['picture']['contentType'] . ';base64,' . base64_encode($picture_response);
|
||||||
|
$event['picture']['base64'] = $picture_encoded;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unset($event);
|
||||||
|
}
|
||||||
|
|
||||||
EventsCache::set(['url' => $url, 'query' => $query, 'afterDatetime' => $afterDatetime, 'groupName' => $groupName, 'limit' => $limit], $events);
|
EventsCache::set(['url' => $url, 'query' => $query, 'afterDatetime' => $afterDatetime, 'groupName' => $groupName, 'limit' => $limit], $events);
|
||||||
return $events;
|
return $events;
|
||||||
}
|
}
|
||||||
@ -110,4 +143,28 @@ final class GraphQlClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function download_image($url) {
|
||||||
|
// Initialize curl handle
|
||||||
|
$ch = curl_init($url);
|
||||||
|
|
||||||
|
// Set curl options
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_TIMEOUT, 60); // Set timeout to 60 seconds (adjust as needed)
|
||||||
|
|
||||||
|
// Execute the request
|
||||||
|
$image_data = curl_exec($ch);
|
||||||
|
|
||||||
|
// Check for errors
|
||||||
|
if (curl_errno($ch)) {
|
||||||
|
print_r(curl_error($ch));
|
||||||
|
throw new \Error('Error: ' . curl_error($ch));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close curl handle
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
return $image_data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,24 @@ You have to use their username, e.g. `@nosliensvivants`, and append the name of
|
|||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
|
### [1.3.0]
|
||||||
|
#### Added
|
||||||
|
- Comment for translators what placeholder will contain
|
||||||
|
#### Changed
|
||||||
|
- Confirm compatibility with WordPress 6.7
|
||||||
|
- Load block script only in footer to reduce waiting time
|
||||||
|
- Update dependencies
|
||||||
|
#### Fixed
|
||||||
|
- Mark event-related data as non-translatable within plugin
|
||||||
|
- Add version number to script registration to break browser caching
|
||||||
|
- Handle location being null
|
||||||
|
|
||||||
|
### [1.2.0]
|
||||||
|
#### Added
|
||||||
|
- Display event picture if available
|
||||||
|
#### Changed
|
||||||
|
- Update dependencies
|
||||||
|
|
||||||
### [1.1.0]
|
### [1.1.0]
|
||||||
#### Added
|
#### Added
|
||||||
- Add some spacing between event items
|
- Add some spacing between event items
|
||||||
|
@ -7,5 +7,8 @@ if (!defined('ABSPATH')) {
|
|||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<div class="<?php echo esc_attr($classNamePrefix); ?>_events-list">
|
<div class="<?php echo esc_attr($classNamePrefix); ?>_events-list">
|
||||||
<?php echo esc_html(sprintf(__('The group "%s" could not be found!', 'connector-mobilizon'), $groupName)); ?>
|
<?php
|
||||||
|
/* translators: %s is replaced with the name of the group. */
|
||||||
|
echo esc_html(sprintf(__('The group "%s" could not be found!', 'connector-mobilizon'), $groupName));
|
||||||
|
?>
|
||||||
</div>
|
</div>
|
||||||
|
@ -8,14 +8,17 @@ if (!defined('ABSPATH')) {
|
|||||||
?>
|
?>
|
||||||
<div class="<?php echo esc_attr($classNamePrefix); ?>_events-list">
|
<div class="<?php echo esc_attr($classNamePrefix); ?>_events-list">
|
||||||
<ul style="list-style-type: none; padding-left: 0;">
|
<ul style="list-style-type: none; padding-left: 0;">
|
||||||
<?php foreach($events as $event) { ?>
|
<?php foreach ($events as $event) { ?>
|
||||||
<li style="margin-top: 10px;">
|
<li style="line-height: 150%; margin-top: 20px;">
|
||||||
<a href="<?php echo esc_attr($event['url']); ?>"><?php echo esc_html_e($event['title']); ?></a>
|
<?php if (isset($event['picture'])) { ?>
|
||||||
|
<img alt="<?php echo esc_attr($event['picture']['alt']); ?>" src="<?php echo esc_attr($event['picture']['base64']); ?>" style="display: block; max-width: 100%;">
|
||||||
|
<?php } ?>
|
||||||
|
<a href="<?php echo esc_attr($event['url']); ?>"><?php echo esc_html($event['title']); ?></a>
|
||||||
<br>
|
<br>
|
||||||
<?php echo esc_html_e(Formatter::format_date($locale, $timeZone, $event['beginsOn'], $event['endsOn'], $isShortOffsetNameShown)); ?>
|
<?php echo esc_html(Formatter::format_date($locale, $timeZone, $event['beginsOn'], $event['endsOn'], $isShortOffsetNameShown)); ?>
|
||||||
<?php if (isset($event['physicalAddress'])) { ?>
|
<?php if (isset($event['physicalAddress'])) { ?>
|
||||||
<br>
|
<br>
|
||||||
<?php echo esc_html_e(Formatter::format_location($event['physicalAddress']['description'], $event['physicalAddress']['locality'])) ?>
|
<?php echo esc_html(Formatter::format_location($event['physicalAddress']['description'], $event['physicalAddress']['locality'])) ?>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</li>
|
</li>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
@ -42,6 +42,10 @@ final class FormatterTest extends PHPUnit\Framework\TestCase
|
|||||||
$this->assertSame('a', Formatter::format_location('a', ''));
|
$this->assertSame('a', Formatter::format_location('a', ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testLocationFormatDescriptionOnlyWithNull(): void {
|
||||||
|
$this->assertSame('a', Formatter::format_location('a', null));
|
||||||
|
}
|
||||||
|
|
||||||
public function testLocationFormatDescriptionWithSpaceOnly(): void {
|
public function testLocationFormatDescriptionWithSpaceOnly(): void {
|
||||||
$this->assertSame('', Formatter::format_location(' ', ''));
|
$this->assertSame('', Formatter::format_location(' ', ''));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user