Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
db59e26e65 |
@ -3,50 +3,26 @@
|
|||||||
"browser": true,
|
"browser": true,
|
||||||
"es2020": true
|
"es2020": true
|
||||||
},
|
},
|
||||||
"globals": {
|
|
||||||
"MOBILIZON_CONNECTOR": "readonly"
|
|
||||||
},
|
|
||||||
"parser": "@babel/eslint-parser",
|
|
||||||
"extends": [
|
"extends": [
|
||||||
"eslint:recommended",
|
"eslint:recommended",
|
||||||
"plugin:ava/recommended",
|
"plugin:ava/recommended"
|
||||||
"plugin:@wordpress/eslint-plugin/recommended"
|
|
||||||
],
|
],
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
"ecmaVersion": 11,
|
"ecmaVersion": 11,
|
||||||
"requireConfigFile": false,
|
"sourceType": "module"
|
||||||
"sourceType": "module",
|
|
||||||
"babelOptions": {
|
|
||||||
"presets": ["@babel/preset-react"]
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"ava",
|
"ava"
|
||||||
"jsx"
|
|
||||||
],
|
],
|
||||||
"rules": {
|
"rules": {
|
||||||
"import/no-unresolved": [
|
|
||||||
"off"
|
|
||||||
],
|
|
||||||
"indent": [
|
"indent": [
|
||||||
"error",
|
"error",
|
||||||
2
|
2
|
||||||
],
|
],
|
||||||
"no-console": [
|
|
||||||
"error", {
|
|
||||||
"allow": ["error"]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"prettier/prettier": [
|
|
||||||
"off"
|
|
||||||
],
|
|
||||||
"quotes": [
|
"quotes": [
|
||||||
"error",
|
"error",
|
||||||
"single"
|
"single"
|
||||||
],
|
],
|
||||||
"react/jsx-key": [
|
|
||||||
"off"
|
|
||||||
],
|
|
||||||
"semi": [
|
"semi": [
|
||||||
"error",
|
"error",
|
||||||
"never"
|
"never"
|
||||||
|
71
.github/workflows/codeql-analysis.yml
vendored
@ -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: |
|
|
||||||
npm install
|
|
||||||
npm run build-prod
|
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
|
||||||
uses: github/codeql-action/analyze@v1
|
|
23
.github/workflows/qodana-code-quality.yml
vendored
@ -1,23 +0,0 @@
|
|||||||
name: Qodana
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
pull_request:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
- 'releases/*'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
qodana:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
- name: 'Qodana Scan'
|
|
||||||
uses: JetBrains/qodana-action@v2022.3.2
|
|
||||||
env:
|
|
||||||
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}
|
|
||||||
- uses: github/codeql-action/upload-sarif@v2
|
|
||||||
with:
|
|
||||||
sarif_file: ${{ runner.temp }}/qodana/results/qodana.sarif.json
|
|
30
.github/workflows/test.yml
vendored
@ -1,30 +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: [16.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 }}
|
|
||||||
- name: Upgrade NPM
|
|
||||||
run: npm install -g npm
|
|
||||||
- run: npm ci --ignore-scripts
|
|
||||||
- run: npm run build-prod
|
|
1
.gitignore
vendored
@ -1,4 +1,3 @@
|
|||||||
.idea/
|
|
||||||
build/
|
build/
|
||||||
coverage/
|
coverage/
|
||||||
node_modules/
|
node_modules/
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"flags": {
|
|
||||||
"gulpfile": "gulpfile.cjs"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
. "$(dirname "$0")/_/husky.sh"
|
|
||||||
|
|
||||||
npm test
|
|
||||||
npx lint-staged
|
|
@ -1,8 +0,0 @@
|
|||||||
.idea
|
|
||||||
build
|
|
||||||
coverage
|
|
||||||
node_modules
|
|
||||||
vendor
|
|
||||||
.eslintrc.json
|
|
||||||
composer.lock
|
|
||||||
LICENSE.md
|
|
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"semi": false,
|
|
||||||
"singleQuote": true
|
|
||||||
}
|
|
201
LICENSE.md
@ -1,201 +0,0 @@
|
|||||||
Apache License
|
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
|
||||||
the copyright owner that is granting the License.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
|
||||||
other entities that control, are controlled by, or are under common
|
|
||||||
control with that entity. For the purposes of this definition,
|
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
|
||||||
direction or management of such entity, whether by contract or
|
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
|
||||||
exercising permissions granted by this License.
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
|
||||||
including but not limited to software source code, documentation
|
|
||||||
source, and configuration files.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical
|
|
||||||
transformation or translation of a Source form, including but
|
|
||||||
not limited to compiled object code, generated documentation,
|
|
||||||
and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
|
||||||
Object form, made available under the License, as indicated by a
|
|
||||||
copyright notice that is included in or attached to the work
|
|
||||||
(an example is provided in the Appendix below).
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
|
||||||
form, that is based on (or derived from) the Work and for which the
|
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
|
||||||
of this License, Derivative Works shall not include works that remain
|
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
|
||||||
the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including
|
|
||||||
the original version of the Work and any modifications or additions
|
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
|
||||||
means any form of electronic, verbal, or written communication sent
|
|
||||||
to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems,
|
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
|
||||||
excluding communication that is conspicuously marked or otherwise
|
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
|
||||||
subsequently incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
|
||||||
Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
(except as stated in this section) patent license to make, have made,
|
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
||||||
where such license applies only to those patent claims licensable
|
|
||||||
by such Contributor that are necessarily infringed by their
|
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
|
||||||
institute patent litigation against any entity (including a
|
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses
|
|
||||||
granted to You under this License for that Work shall terminate
|
|
||||||
as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
|
||||||
modifications, and in Source or Object form, provided that You
|
|
||||||
meet the following conditions:
|
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or
|
|
||||||
Derivative Works a copy of this License; and
|
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices
|
|
||||||
stating that You changed the files; and
|
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
|
||||||
that You distribute, all copyright, patent, trademark, and
|
|
||||||
attribution notices from the Source form of the Work,
|
|
||||||
excluding those notices that do not pertain to any part of
|
|
||||||
the Derivative Works; and
|
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
|
||||||
distribution, then any Derivative Works that You distribute must
|
|
||||||
include a readable copy of the attribution notices contained
|
|
||||||
within such NOTICE file, excluding those notices that do not
|
|
||||||
pertain to any part of the Derivative Works, in at least one
|
|
||||||
of the following places: within a NOTICE text file distributed
|
|
||||||
as part of the Derivative Works; within the Source form or
|
|
||||||
documentation, if provided along with the Derivative Works; or,
|
|
||||||
within a display generated by the Derivative Works, if and
|
|
||||||
wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and
|
|
||||||
do not modify the License. You may add Your own attribution
|
|
||||||
notices within Derivative Works that You distribute, alongside
|
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
|
||||||
that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and
|
|
||||||
may provide additional or different license terms and conditions
|
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
|
||||||
the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
|
||||||
this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
|
||||||
the terms of any separate license agreement you may have executed
|
|
||||||
with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
|
||||||
except as required for reasonable and customary use in describing the
|
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
implied, including, without limitation, any warranties or conditions
|
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
||||||
appropriateness of using or redistributing the Work and assume any
|
|
||||||
risks associated with Your exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
|
||||||
unless required by applicable law (such as deliberate and grossly
|
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
|
||||||
liable to You for damages, including any direct, indirect, special,
|
|
||||||
incidental, or consequential damages of any character arising as a
|
|
||||||
result of this License or out of the use or inability to use the
|
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
|
||||||
other commercial damages or losses), even if such Contributor
|
|
||||||
has been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
|
||||||
the Work or Derivative Works thereof, You may choose to offer,
|
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
||||||
or other liability obligations and/or rights consistent with this
|
|
||||||
License. However, in accepting such obligations, You may act only
|
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
|
||||||
defend, and hold each Contributor harmless for any liability
|
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
|
||||||
of your accepting any such warranty or additional liability.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
APPENDIX: How to apply the Apache License to your work.
|
|
||||||
|
|
||||||
To apply the Apache License to your work, attach the following
|
|
||||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
||||||
replaced with your own identifying information. (Don't include
|
|
||||||
the brackets!) The text should be enclosed in the appropriate
|
|
||||||
comment syntax for the file format. We also recommend that a
|
|
||||||
file or class name and description of purpose be included on the
|
|
||||||
same "printed page" as the copyright notice for easier
|
|
||||||
identification within third-party archives.
|
|
||||||
|
|
||||||
Copyright [yyyy] [name of copyright owner]
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
36
README.md
@ -4,43 +4,31 @@ Connector for Mobilizon allows you to display the upcoming events of [Mobilizon]
|
|||||||
|
|
||||||
More details can be found in the [WordPress Plugin Directory](https://wordpress.org/plugins/connector-mobilizon/).
|
More details can be found in the [WordPress Plugin Directory](https://wordpress.org/plugins/connector-mobilizon/).
|
||||||
|
|
||||||
The current changelog can be found under [source/changelog.txt](source/changelog.txt).
|
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
### Setup
|
### Setup
|
||||||
|
|
||||||
1. Make sure `npm` and `composer` are installed.
|
1. Make sure `npm` and `composer` are installed.
|
||||||
2. Run: `npm install`
|
2. Run: `npm install`
|
||||||
3. Run: `composer install`
|
3. Run: `php composer.phar install`
|
||||||
|
|
||||||
### 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.
|
2. Make sure to keep `changelog.txt` up-to-date.
|
||||||
|
|
||||||
### 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.
|
2. Update `package.json` with the same version number.
|
||||||
2. Use a new version number and copy over the new section into `readme.txt`.
|
3. Build: `npm run build-prod`
|
||||||
3. Update `package.json` with the same version number.
|
4. Determine minimum PHP version for code and update package.json if needed: `./vendor/bin/phpcompatinfo analyser:run ./source`
|
||||||
4. Update the `package-lock.json`: `npm i --package-lock-only`
|
5. Make sure screenshots are up-to-date.
|
||||||
5. Build: `npm run build-prod`
|
6. Copy the built plugin into `/trunk` of SVN.
|
||||||
6. Make sure screenshots are up-to-date.
|
7. Create a new tag of the new version: `svn cp trunk tags/<version>`
|
||||||
7. Copy the built plugin into `/trunk` of SVN.
|
8. Check the version number occurences in both folders.
|
||||||
8. Create a new tag of the new version: `svn cp trunk tags/<version>`
|
9. Commit everything together: `svn ci -m "release version <version>"`
|
||||||
9. Check the version number occurrences in both folders.
|
10. Tag the new version in `git` too.
|
||||||
10. Commit everything together to the release SVN: `svn ci -m "release version <version>"` Make sure to add new files beforehand.
|
|
||||||
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`
|
||||||
- Run JavaScript code coverage with tests: `npm run coverage`
|
- Run JavaScript code coverage with tests: `npm run coverage`
|
||||||
- Run tests: `npm test`
|
- Run tests: `npm test`
|
||||||
- Delete build folder: `npm run clean`
|
- Delete build folder: `gulp clean`
|
||||||
- Update PHP dependencies: `composer update`
|
|
||||||
- Check for direct PHP dependency updates: `composer outdated --direct`
|
|
||||||
- Format code with prettier: `npm run format`
|
|
||||||
|
Before Width: | Height: | Size: 60 KiB After Width: | Height: | Size: 37 KiB |
Before Width: | Height: | Size: 63 KiB After Width: | Height: | Size: 55 KiB |
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 7.5 KiB |
Before Width: | Height: | Size: 81 KiB |
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"presets": ["@babel/preset-env", "@babel/preset-react"]
|
|
||||||
}
|
|
@ -1 +1,5 @@
|
|||||||
{}
|
{
|
||||||
|
"require": {
|
||||||
|
"bartlett/php-compatinfo": "^5.4"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
2912
composer.lock
generated
50
gulpfile.cjs
@ -1,50 +0,0 @@
|
|||||||
/* eslint-disable no-undef */
|
|
||||||
const { dest, src } = require('gulp')
|
|
||||||
|
|
||||||
const replace = require('gulp-replace')
|
|
||||||
|
|
||||||
const PACKAGE = require('./package.json')
|
|
||||||
|
|
||||||
const FOLDER_BUILD = './build'
|
|
||||||
|
|
||||||
function injectMetadata() {
|
|
||||||
return src(
|
|
||||||
[
|
|
||||||
FOLDER_BUILD + '/front/block-events-loader.js',
|
|
||||||
FOLDER_BUILD + '/front/events-loader.js',
|
|
||||||
FOLDER_BUILD + '/' + PACKAGE.name + '.php',
|
|
||||||
FOLDER_BUILD + '/includes/constants.php',
|
|
||||||
FOLDER_BUILD + '/readme.txt',
|
|
||||||
],
|
|
||||||
{ base: './' }
|
|
||||||
)
|
|
||||||
.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))
|
|
||||||
.pipe(replace('<wordpress-nice-name>', PACKAGE.additionalDetails.niceName))
|
|
||||||
.pipe(
|
|
||||||
replace(
|
|
||||||
'<wordpress-php-minimum-version>',
|
|
||||||
PACKAGE.additionalDetails.phpMinimumVersion
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.pipe(
|
|
||||||
replace(
|
|
||||||
'<wordpress-tested-up-to-version>',
|
|
||||||
PACKAGE.additionalDetails.wordpressTestedUpToVersion
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.pipe(replace('<wordpress-version>', PACKAGE.version))
|
|
||||||
.pipe(dest('.'))
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.inject = injectMetadata
|
|
80
gulpfile.js
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
const { dest, series, src } = require('gulp');
|
||||||
|
|
||||||
|
const del = require('del');
|
||||||
|
const replace = require('gulp-replace');
|
||||||
|
const webpack = require('webpack-stream');
|
||||||
|
|
||||||
|
const PACKAGE = require('./package.json');
|
||||||
|
|
||||||
|
const FOLDER_SOURCE = './source'
|
||||||
|
const FOLDER_BUILD = './build';
|
||||||
|
|
||||||
|
let mode = 'development';
|
||||||
|
|
||||||
|
|
||||||
|
function clean(cb) {
|
||||||
|
del(FOLDER_BUILD);
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
|
||||||
|
const eventsLoaderOutputPath = PACKAGE.name + '/front/events-loader';
|
||||||
|
const eventsLoaderInputPath = FOLDER_SOURCE + '/' + PACKAGE.name + '/front/events-loader.js';
|
||||||
|
|
||||||
|
function bundleFrontend() {
|
||||||
|
return src(FOLDER_SOURCE + '/' + PACKAGE.name + '/front/events-loader.js')
|
||||||
|
.pipe(webpack({
|
||||||
|
mode,
|
||||||
|
entry: {
|
||||||
|
[eventsLoaderOutputPath]: eventsLoaderInputPath,
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
filename: '[name].js',
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
.pipe(dest(FOLDER_BUILD));
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyBackend() {
|
||||||
|
return src([
|
||||||
|
FOLDER_SOURCE + '/**/*.php',
|
||||||
|
FOLDER_SOURCE + '/**/*.txt'
|
||||||
|
])
|
||||||
|
.pipe(dest(FOLDER_BUILD));
|
||||||
|
}
|
||||||
|
|
||||||
|
function injectMetadata() {
|
||||||
|
return src([
|
||||||
|
FOLDER_BUILD + '/' + eventsLoaderOutputPath + '.js',
|
||||||
|
FOLDER_BUILD + '/' + PACKAGE.name + '/' + PACKAGE.name + '.php',
|
||||||
|
FOLDER_BUILD + '/' + PACKAGE.name + '/includes/constants.php',
|
||||||
|
FOLDER_BUILD + '/' + PACKAGE.name + '/readme.txt'
|
||||||
|
], { base: './' })
|
||||||
|
.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))
|
||||||
|
.pipe(replace('<wordpress-nice-name>', PACKAGE.additionalDetails.niceName))
|
||||||
|
.pipe(replace('<wordpress-php-minimum-version>', PACKAGE.additionalDetails.phpMinimumVersion))
|
||||||
|
.pipe(replace('<wordpress-tested-up-to-version>', PACKAGE.additionalDetails.wordpressTestedUpToVersion))
|
||||||
|
.pipe(replace('<wordpress-version>', PACKAGE.version))
|
||||||
|
.pipe(dest('.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.front = bundleFrontend;
|
||||||
|
exports.copy = copyBackend;
|
||||||
|
exports.inject = injectMetadata;
|
||||||
|
|
||||||
|
const build = series(clean, bundleFrontend, copyBackend, injectMetadata);
|
||||||
|
|
||||||
|
const buildDev = series((cb) => { mode = 'development'; cb(); }, build);
|
||||||
|
|
||||||
|
const buildProd = series((cb) => { mode = 'production'; cb(); }, build);
|
||||||
|
|
||||||
|
|
||||||
|
exports.clean = clean;
|
||||||
|
exports.dev = buildDev;
|
||||||
|
exports.default = buildDev;
|
||||||
|
exports.prod = buildProd;
|
23031
package-lock.json
generated
66
package.json
@ -1,17 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "connector-mobilizon",
|
"name": "connector-mobilizon",
|
||||||
"version": "0.11.1",
|
"version": "0.4.0",
|
||||||
"description": "Display Mobilizon events in WordPress.",
|
"description": "Display mobilizon events in WordPress.",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build-dev": "webpack --mode=development && gulp inject",
|
"build-dev": "gulp dev",
|
||||||
"build-prod": "ava && webpack --mode=production && gulp inject",
|
"build-prod": "ava && gulp prod",
|
||||||
"clean": "rimraf -- build",
|
|
||||||
"coverage": "c8 --all --reporter=html --reporter=text --include=source/**/*.js ava",
|
"coverage": "c8 --all --reporter=html --reporter=text --include=source/**/*.js ava",
|
||||||
"eslint": "npx eslint source/**/*.js",
|
"eslint": "npx eslint source/**/*.js",
|
||||||
"format": "npx prettier --write .",
|
|
||||||
"prepare": "husky install",
|
|
||||||
"test": "ava"
|
"test": "ava"
|
||||||
},
|
},
|
||||||
"author": {
|
"author": {
|
||||||
@ -24,49 +20,37 @@
|
|||||||
},
|
},
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"graphql": "16.6.0",
|
"graphql": "^15.5.0",
|
||||||
"graphql-request": "5.2.0",
|
"graphql-request": "^3.4.0",
|
||||||
"luxon": "3.3.0",
|
"luxon": "^1.26.0",
|
||||||
"object-hash": "3.0.0"
|
"object-hash": "^2.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "7.21.3",
|
"ava": "^3.15.0",
|
||||||
"@babel/eslint-parser": "7.21.3",
|
"c8": "^7.7.1",
|
||||||
"@babel/preset-env": "7.20.2",
|
"del": "^6.0.0",
|
||||||
"@babel/preset-react": "7.18.6",
|
"eslint": "^7.24.0",
|
||||||
"@wordpress/eslint-plugin": "14.3.0",
|
"eslint-plugin-ava": "^12.0.0",
|
||||||
"ava": "5.2.0",
|
"esm": "^3.2.25",
|
||||||
"babel-loader": "9.1.2",
|
"gulp": "^4.0.2",
|
||||||
"browser-env": "3.3.0",
|
"gulp-replace": "^1.0.0",
|
||||||
"c8": "7.13.0",
|
"jsdom": "^16.5.3",
|
||||||
"copy-webpack-plugin": "11.0.0",
|
"webpack": "^5.34.0",
|
||||||
"eslint": "8.37.0",
|
"webpack-cli": "^4.6.0",
|
||||||
"eslint-plugin-ava": "14.0.0",
|
"webpack-stream": "^6.1.2"
|
||||||
"eslint-plugin-jsx": "0.1.0",
|
|
||||||
"eslint-plugin-react": "7.32.2",
|
|
||||||
"esm": "3.2.25",
|
|
||||||
"gulp": "4.0.2",
|
|
||||||
"gulp-replace": "1.1.4",
|
|
||||||
"husky": "8.0.3",
|
|
||||||
"lint-staged": "13.2.0",
|
|
||||||
"prettier": "2.8.7",
|
|
||||||
"rimraf": "4.4.1",
|
|
||||||
"webpack": "5.77.0",
|
|
||||||
"webpack-cli": "5.0.1"
|
|
||||||
},
|
},
|
||||||
"ava": {
|
"ava": {
|
||||||
"files": [
|
"files": [
|
||||||
"./source/**/*test.js"
|
"./source/**/*test.js"
|
||||||
|
],
|
||||||
|
"require": [
|
||||||
|
"esm"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"additionalDetails": {
|
"additionalDetails": {
|
||||||
"niceName": "Connector for Mobilizon",
|
"niceName": "Connector for Mobilizon",
|
||||||
"phpMinimumVersion": 7.4,
|
"phpMinimumVersion": 5.4,
|
||||||
"wordpressMinimumVersion": 5.6,
|
"wordpressMinimumVersion": 5.6,
|
||||||
"wordpressTestedUpToVersion": "6.2"
|
"wordpressTestedUpToVersion": 5.7
|
||||||
},
|
|
||||||
"lint-staged": {
|
|
||||||
"source/**/*.js": "eslint",
|
|
||||||
"**/*": "prettier --write --ignore-unknown"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
version: '1.0'
|
|
||||||
linter: jetbrains/qodana-js:2022.3-eap
|
|
@ -1,133 +0,0 @@
|
|||||||
### [Unreleased]
|
|
||||||
#### Added
|
|
||||||
#### Changed
|
|
||||||
#### Deprecated
|
|
||||||
#### Removed
|
|
||||||
#### Fixed
|
|
||||||
#### Security
|
|
||||||
|
|
||||||
### [0.11.1]
|
|
||||||
#### Fixed
|
|
||||||
- Revert minimum PHP version to 7.4 to allow some more time for upgrading PHP
|
|
||||||
|
|
||||||
### [0.11.0]
|
|
||||||
#### Changed
|
|
||||||
- Update dependencies
|
|
||||||
- Confirm compatibility with WordPress 6.2
|
|
||||||
#### Security
|
|
||||||
- Set minimum PHP version to oldest stable 8.0
|
|
||||||
|
|
||||||
### [0.10.1]
|
|
||||||
#### Changed
|
|
||||||
- Confirm compatibility with WordPress 6.1
|
|
||||||
- Update dependencies
|
|
||||||
|
|
||||||
### [0.10.0]
|
|
||||||
#### Added
|
|
||||||
- Add Gutenberg events list block
|
|
||||||
- Show loading indicator during request
|
|
||||||
#### Changed
|
|
||||||
- Set list style type to none and left padding to zero for all occurences
|
|
||||||
- Move shortcut usage description into installation section in `readme.txt`
|
|
||||||
- Update dependencies
|
|
||||||
|
|
||||||
### [0.9.1] - 2020-05-19
|
|
||||||
#### Fixed
|
|
||||||
- Fix WordPress compatibility version number
|
|
||||||
|
|
||||||
### [0.9.0] - 2020-05-19
|
|
||||||
#### Added
|
|
||||||
- Improve explanation of group name filter
|
|
||||||
#### Changed
|
|
||||||
- Update dependencies
|
|
||||||
- Confirm compatibility with WordPress 6.0
|
|
||||||
#### Fixed
|
|
||||||
- Fix displaying error message for the case the group is not found
|
|
||||||
|
|
||||||
### [0.8.0] - 2022-01-09
|
|
||||||
#### Added
|
|
||||||
- Add support for older browsers using babel
|
|
||||||
#### Changed
|
|
||||||
- Confirm compatibility with WordPress 5.9
|
|
||||||
- Update dependencies
|
|
||||||
#### Fixed
|
|
||||||
- Use ES modules correctly
|
|
||||||
- Trim events' location
|
|
||||||
|
|
||||||
### [0.7.0] - 2021-12-23
|
|
||||||
#### Added
|
|
||||||
- Add specific error message for the case the group is not found
|
|
||||||
- Add code formatter prettier
|
|
||||||
#### Changed
|
|
||||||
- Update dependencies
|
|
||||||
- Simplify build process
|
|
||||||
#### Fixed
|
|
||||||
- Fix Invalid DateTime on event end time being null
|
|
||||||
#### Security
|
|
||||||
- Set minimum PHP version to oldest stable 7.4
|
|
||||||
|
|
||||||
### [0.6.2] - 2021-08-24
|
|
||||||
#### Changed
|
|
||||||
- Update dependencies
|
|
||||||
#### Fixed
|
|
||||||
- Fix empty WordPress timezone_string option resulting in Invalid DateTime
|
|
||||||
|
|
||||||
### [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
|
|
||||||
#### 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
|
|
||||||
#### 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,86 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* 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>
|
|
||||||
*/
|
|
||||||
|
|
||||||
require_once __DIR__ . '/includes/constants.php';
|
|
||||||
require_once __DIR__ . '/includes/settings.php';
|
|
||||||
require_once __DIR__ . '/includes/events-list-block.php';
|
|
||||||
require_once __DIR__ . '/includes/events-list-shortcut.php';
|
|
||||||
require_once __DIR__ . '/includes/events-list-widget.php';
|
|
||||||
|
|
||||||
// Exit if this file is called directly.
|
|
||||||
if (!defined('ABSPATH')) {
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
final class Mobilizon_Connector {
|
|
||||||
|
|
||||||
private function __construct() {
|
|
||||||
add_action('init', [$this, 'register_blocks']);
|
|
||||||
add_action('init', [$this, 'register_settings'], 1); // required for register_blocks
|
|
||||||
add_action('init', [$this, 'register_shortcut']);
|
|
||||||
add_action('widgets_init', [$this, 'register_widget']);
|
|
||||||
add_action('wp_enqueue_scripts', [$this, 'register_scripts']);
|
|
||||||
register_activation_hook(__FILE__, [$this, 'enable_activation']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function init() {
|
|
||||||
// Create singleton instance.
|
|
||||||
static $instance = false;
|
|
||||||
if(!$instance) {
|
|
||||||
$instance = new self();
|
|
||||||
}
|
|
||||||
return $instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function enable_activation() {
|
|
||||||
MobilizonConnector\Settings::setDefaultOptions();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function load_settings_globally_before_script($scriptName) {
|
|
||||||
$settings = array(
|
|
||||||
'isShortOffsetNameShown' => MobilizonConnector\Settings::isShortOffsetNameShown(),
|
|
||||||
'locale' => str_replace('_', '-', get_locale()),
|
|
||||||
'timeZone' => wp_timezone_string(),
|
|
||||||
'url' => MobilizonConnector\Settings::getUrl()
|
|
||||||
);
|
|
||||||
wp_add_inline_script($scriptName, 'var MOBILIZON_CONNECTOR = ' . json_encode($settings), 'before');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function register_blocks() {
|
|
||||||
$scriptName = MobilizonConnector\EventsListBlock::initAndReturnScriptName();
|
|
||||||
$this->load_settings_globally_before_script($scriptName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function register_settings() {
|
|
||||||
MobilizonConnector\Settings::init();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function register_scripts() {
|
|
||||||
$name = MobilizonConnector\NAME . '-js';
|
|
||||||
wp_enqueue_script($name, plugins_url('front/events-loader.js', __FILE__ ));
|
|
||||||
$this->load_settings_globally_before_script($name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function register_shortcut() {
|
|
||||||
MobilizonConnector\EventsListShortcut::init();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function register_widget() {
|
|
||||||
register_widget('MobilizonConnector\EventsListWidget');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function mobilizon_connector_run_plugin() {
|
|
||||||
return Mobilizon_Connector::init();
|
|
||||||
}
|
|
||||||
|
|
||||||
mobilizon_connector_run_plugin();
|
|
48
source/connector-mobilizon/changelog.txt
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
### [Unreleased]
|
||||||
|
#### 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
|
||||||
|
#### 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
|
42
source/connector-mobilizon/connector-mobilizon.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* 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>
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once __DIR__ . '/includes/constants.php';
|
||||||
|
require_once __DIR__ . '/includes/settings.php';
|
||||||
|
require_once __DIR__ . '/includes/events-list-shortcut.php';
|
||||||
|
require_once __DIR__ . '/includes/events-list-widget.php';
|
||||||
|
|
||||||
|
// Exit if this file is called directly.
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
function mobilizon_connector_activate() {
|
||||||
|
MobilizonConnector\Settings::setDefaultOptions();
|
||||||
|
}
|
||||||
|
register_activation_hook(__FILE__, 'mobilizon_connector_activate');
|
||||||
|
|
||||||
|
function mobilizon_connector_initialize() {
|
||||||
|
MobilizonConnector\Settings::init();
|
||||||
|
MobilizonConnector\EventsListShortcut::init();
|
||||||
|
}
|
||||||
|
add_action('init', 'mobilizon_connector_initialize');
|
||||||
|
|
||||||
|
function mobilizon_connector_load_scripts() {
|
||||||
|
wp_enqueue_script(MobilizonConnector\NAME . '-js', plugins_url('front/events-loader.js', __FILE__ ));
|
||||||
|
}
|
||||||
|
add_action('wp_enqueue_scripts', 'mobilizon_connector_load_scripts');
|
||||||
|
|
||||||
|
function mobilizon_connector_register_events_list_widget() {
|
||||||
|
register_widget('MobilizonConnector\EventsListWidget');
|
||||||
|
}
|
||||||
|
add_action('widgets_init', 'mobilizon_connector_register_events_list_widget');
|
53
source/connector-mobilizon/front/date-time-wrapper-test.js
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import test from 'ava'
|
||||||
|
import DateTimeWrapper from './date-time-wrapper'
|
||||||
|
|
||||||
|
test('#getShortDate usual date', t => {
|
||||||
|
const d = new DateTimeWrapper('2020-12-24T16:45:00Z')
|
||||||
|
t.is(d.getShortDate(), '24/12/2020')
|
||||||
|
})
|
||||||
|
|
||||||
|
test('#get24Time usual time', t => {
|
||||||
|
const d = new DateTimeWrapper('2020-12-24T16:45:00Z')
|
||||||
|
t.is(d.get24Time(), '17:45')
|
||||||
|
})
|
||||||
|
|
||||||
|
test('#equalsDate same date, different time', t => {
|
||||||
|
const d = new DateTimeWrapper('2020-12-24T16:45:00Z')
|
||||||
|
const e = new DateTimeWrapper('2020-12-24T17:46:01Z')
|
||||||
|
t.true(d.equalsDate(e))
|
||||||
|
})
|
||||||
|
|
||||||
|
test('#equalsDate different date, different time', t => {
|
||||||
|
const d = new DateTimeWrapper('2020-12-24T16:45:00Z')
|
||||||
|
const e = new DateTimeWrapper('2021-11-25T17:46:01Z')
|
||||||
|
t.false(d.equalsDate(e))
|
||||||
|
})
|
||||||
|
|
||||||
|
test('#equalsDate different day, different time', t => {
|
||||||
|
const d = new DateTimeWrapper('2020-12-24T16:45:00Z')
|
||||||
|
const e = new DateTimeWrapper('2020-12-25T17:46:01Z')
|
||||||
|
t.false(d.equalsDate(e))
|
||||||
|
})
|
||||||
|
|
||||||
|
test('#equalsDate different month, different time', t => {
|
||||||
|
const d = new DateTimeWrapper('2020-12-24T16:45:00Z')
|
||||||
|
const e = new DateTimeWrapper('2020-11-24T17:46:01Z')
|
||||||
|
t.false(d.equalsDate(e))
|
||||||
|
})
|
||||||
|
|
||||||
|
test('#equalsDate different year, different time', t => {
|
||||||
|
const d = new DateTimeWrapper('2020-12-24T16:45:00Z')
|
||||||
|
const e = new DateTimeWrapper('2021-12-24T17:46:01Z')
|
||||||
|
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], ':')
|
||||||
|
})
|
@ -1,42 +1,28 @@
|
|||||||
import { DateTime } from 'luxon'
|
import { DateTime } from 'luxon'
|
||||||
|
|
||||||
export default class DateTimeWrapper {
|
export default class DateTimeWrapper {
|
||||||
constructor({ locale = 'en-GB', text, timeZone = 'utc' } = {}) {
|
|
||||||
if (!timeZone) {
|
constructor(text) {
|
||||||
timeZone = 'utc'
|
this.dateTime = DateTime.fromISO(text)
|
||||||
}
|
|
||||||
if (
|
|
||||||
timeZone.includes(':') &&
|
|
||||||
timeZone.substring(0, 3).toUpperCase() !== 'UTC'
|
|
||||||
) {
|
|
||||||
timeZone = 'UTC' + timeZone
|
|
||||||
}
|
|
||||||
this.dateTime = DateTime.fromISO(text, { locale, zone: timeZone })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
equalsDate(other) {
|
equalsDate(other) {
|
||||||
return (
|
return this.dateTime &&
|
||||||
this.dateTime &&
|
|
||||||
other.dateTime &&
|
other.dateTime &&
|
||||||
this.dateTime.day === other.dateTime.day &&
|
this.dateTime.day === other.dateTime.day &&
|
||||||
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() {
|
static getCurrentDatetimeAsString() {
|
||||||
return DateTime.now().toString()
|
return DateTime.local().toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
65
source/connector-mobilizon/front/events-loader.js
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
import Formatter from './formatter'
|
||||||
|
import * as GraphqlWrapper from './graphql-wrapper'
|
||||||
|
import { createAnchorElement } from './html-creator'
|
||||||
|
|
||||||
|
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', () => {
|
||||||
|
const eventLists = document.getElementsByClassName(NAME + '_events-list')
|
||||||
|
for (let list of eventLists) {
|
||||||
|
const url = list.getAttribute('data-url') + '/api'
|
||||||
|
const limit = parseInt(list.getAttribute('data-maximum'))
|
||||||
|
const groupName = list.getAttribute('data-group-name')
|
||||||
|
if (groupName) {
|
||||||
|
GraphqlWrapper.getUpcomingEventsByGroupName({ url, limit, groupName })
|
||||||
|
.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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
27
source/connector-mobilizon/front/formatter-test.js
Normal 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')
|
||||||
|
})
|
31
source/connector-mobilizon/front/formatter.js
Normal 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
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
import SessionCache from './session-cache.js'
|
import SessionCache from './session-cache'
|
||||||
import { request } from 'graphql-request'
|
import { request } from 'graphql-request'
|
||||||
import DateTimeWrapper from './date-time-wrapper.js'
|
import DateTimeWrapper from './date-time-wrapper'
|
||||||
|
|
||||||
export function getUpcomingEvents({ url, limit }) {
|
export function getUpcomingEvents({ url, limit }) {
|
||||||
const query = `
|
const query = `
|
||||||
@ -21,23 +21,19 @@ export function getUpcomingEvents({ url, limit }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
const dataInCache = SessionCache.get(sessionStorage, {
|
const dataInCache = SessionCache.get(sessionStorage, { url, query, variables: { limit }})
|
||||||
url,
|
if (dataInCache !== null)
|
||||||
query,
|
|
||||||
variables: { limit },
|
|
||||||
})
|
|
||||||
if (dataInCache !== null) {
|
|
||||||
return Promise.resolve(dataInCache)
|
return Promise.resolve(dataInCache)
|
||||||
}
|
return request(url, query, { limit })
|
||||||
return request(url, query, { limit }).then((data) => {
|
.then((data) => {
|
||||||
SessionCache.add(sessionStorage, { url, query, variables: { limit } }, data)
|
SessionCache.add(sessionStorage, { url, query, variables: { limit }}, data)
|
||||||
return Promise.resolve(data)
|
return Promise.resolve(data)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getUpcomingEventsByGroupName({ url, limit, groupName }) {
|
export function getUpcomingEventsByGroupName({ url, limit, groupName }) {
|
||||||
const query = `
|
const query = `
|
||||||
query ($afterDatetime: DateTime, $groupName: String!, $limit: Int) {
|
query ($afterDatetime: DateTime, $groupName: String, $limit: Int) {
|
||||||
group(preferredUsername: $groupName) {
|
group(preferredUsername: $groupName) {
|
||||||
organizedEvents(afterDatetime: $afterDatetime, limit: $limit) {
|
organizedEvents(afterDatetime: $afterDatetime, limit: $limit) {
|
||||||
elements {
|
elements {
|
||||||
@ -57,22 +53,12 @@ export function getUpcomingEventsByGroupName({ url, limit, groupName }) {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
const afterDatetime = DateTimeWrapper.getCurrentDatetimeAsString()
|
const afterDatetime = DateTimeWrapper.getCurrentDatetimeAsString()
|
||||||
const dataInCache = SessionCache.get(sessionStorage, {
|
const dataInCache = SessionCache.get(sessionStorage, { url, query, variables: { afterDatetime, groupName, limit }})
|
||||||
url,
|
if (dataInCache !== null)
|
||||||
query,
|
|
||||||
variables: { afterDatetime, groupName, limit },
|
|
||||||
})
|
|
||||||
if (dataInCache !== null) {
|
|
||||||
return Promise.resolve(dataInCache)
|
return Promise.resolve(dataInCache)
|
||||||
}
|
return request(url, query, { afterDatetime, groupName, limit })
|
||||||
return request(url, query, { afterDatetime, groupName, limit }).then(
|
.then((data) => {
|
||||||
(data) => {
|
SessionCache.add(sessionStorage, { url, query, variables: { afterDatetime, groupName, limit }}, data)
|
||||||
SessionCache.add(
|
|
||||||
sessionStorage,
|
|
||||||
{ url, query, variables: { afterDatetime, groupName, limit } },
|
|
||||||
data
|
|
||||||
)
|
|
||||||
return Promise.resolve(data)
|
return Promise.resolve(data)
|
||||||
}
|
})
|
||||||
)
|
|
||||||
}
|
}
|
15
source/connector-mobilizon/front/html-creator-test.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import test from 'ava'
|
||||||
|
import { JSDOM } from 'jsdom'
|
||||||
|
|
||||||
|
import * as HtmlCreator from './html-creator'
|
||||||
|
|
||||||
|
test.beforeEach(() => {
|
||||||
|
global.document = new JSDOM().window.document
|
||||||
|
})
|
||||||
|
|
||||||
|
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')
|
||||||
|
})
|
@ -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')
|
@ -0,0 +1,6 @@
|
|||||||
|
import test from 'ava'
|
||||||
|
import hash from './object-hash-wrapper'
|
||||||
|
|
||||||
|
test('#hash object', t => {
|
||||||
|
t.is(hash({foo: 'bar'}), 'a75c05bdca7d704bdfcd761913e5a4e4636e956b')
|
||||||
|
})
|
@ -1,7 +1,8 @@
|
|||||||
import test from 'ava'
|
import test from 'ava'
|
||||||
import SessionCache from './session-cache.js'
|
import SessionCache from './session-cache'
|
||||||
|
|
||||||
const fakeStorage = {
|
const fakeStorage = {
|
||||||
|
|
||||||
elements: {},
|
elements: {},
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
@ -16,18 +17,18 @@ const fakeStorage = {
|
|||||||
|
|
||||||
setItem(key, value) {
|
setItem(key, value) {
|
||||||
this.elements[key] = value
|
this.elements[key] = value
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
test.afterEach(() => {
|
test.afterEach(() => {
|
||||||
fakeStorage.clear()
|
fakeStorage.clear()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('#add & #get', (t) => {
|
test('#add & #get', t => {
|
||||||
SessionCache.add(fakeStorage, { a: 'b' }, { c: 'd' })
|
SessionCache.add(fakeStorage, { a: 'b' }, { c: 'd' })
|
||||||
t.deepEqual(SessionCache.get(fakeStorage, { a: 'b' }), { c: 'd' })
|
t.deepEqual(SessionCache.get(fakeStorage, { a: 'b' }), { c: 'd' })
|
||||||
})
|
})
|
||||||
|
|
||||||
test('#get no entry', (t) => {
|
test('#get no entry', t => {
|
||||||
t.is(SessionCache.get(fakeStorage, { a: 'bb' }), null)
|
t.is(SessionCache.get(fakeStorage, { a: 'bb' }), null)
|
||||||
})
|
})
|
@ -1,8 +1,9 @@
|
|||||||
import hash from './object-hash-wrapper.js'
|
import hash from './object-hash-wrapper'
|
||||||
|
|
||||||
const MAX_AGE_IN_MS = 120000
|
const MAX_AGE_IN_MS = 120000
|
||||||
|
|
||||||
export default class SessionCache {
|
export default class SessionCache {
|
||||||
|
|
||||||
static add(storage, parameters, data) {
|
static add(storage, parameters, data) {
|
||||||
const key = hash(parameters)
|
const key = hash(parameters)
|
||||||
const timestamp = Date.now()
|
const timestamp = Date.now()
|
||||||
@ -16,11 +17,7 @@ export default class SessionCache {
|
|||||||
static get(storage, parameters) {
|
static get(storage, parameters) {
|
||||||
const key = hash(parameters)
|
const key = hash(parameters)
|
||||||
const value = JSON.parse(storage.getItem(key))
|
const value = JSON.parse(storage.getItem(key))
|
||||||
if (
|
if (value && value.timestamp && value.timestamp > Date.now() - MAX_AGE_IN_MS)
|
||||||
value &&
|
|
||||||
value.timestamp &&
|
|
||||||
value.timestamp > Date.now() - MAX_AGE_IN_MS
|
|
||||||
)
|
|
||||||
return value.data
|
return value.data
|
||||||
return null
|
return null
|
||||||
}
|
}
|
@ -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>';
|
@ -27,6 +27,8 @@ class EventsListShortcut {
|
|||||||
$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'];
|
$groupName = $atts_with_overriden_defaults['group-name'];
|
||||||
|
$url = Settings::getUrl();
|
||||||
|
$textDomain = TEXT_DOMAIN;
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
require dirname(__DIR__) . '/view/events-list.php';
|
require dirname(__DIR__) . '/view/events-list.php';
|
@ -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),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -28,6 +28,8 @@ class EventsListWidget extends \WP_Widget {
|
|||||||
$classNamePrefix = NAME;
|
$classNamePrefix = NAME;
|
||||||
$eventsCount = $options['eventsCount'];
|
$eventsCount = $options['eventsCount'];
|
||||||
$groupName = isset($options['groupName']) ? $options['groupName'] : '';
|
$groupName = isset($options['groupName']) ? $options['groupName'] : '';
|
||||||
|
$url = Settings::getUrl();
|
||||||
|
$textDomain = TEXT_DOMAIN;
|
||||||
|
|
||||||
require dirname(__DIR__) . '/view/events-list.php';
|
require dirname(__DIR__) . '/view/events-list.php';
|
||||||
|
|
||||||
@ -35,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';
|
||||||
}
|
}
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
70
source/connector-mobilizon/readme.txt
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
# <wordpress-nice-name>
|
||||||
|
Contributors: dwaxweiler
|
||||||
|
Donate link: <wordpress-donation-link>
|
||||||
|
Tags: mobilizon, events
|
||||||
|
Stable tag: <wordpress-version>
|
||||||
|
Requires at least: <wordpress-minimum-version>
|
||||||
|
Tested up to: <wordpress-tested-up-to-version>
|
||||||
|
Requires PHP: <wordpress-php-minimum-version>
|
||||||
|
License: <wordpress-license>
|
||||||
|
|
||||||
|
<wordpress-description>
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
<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
|
||||||
|
1. Events list
|
||||||
|
2. General settings
|
||||||
|
3. Widget creation
|
||||||
|
4. Shortcut creation
|
||||||
|
|
||||||
|
## 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
|
||||||
|
#### 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
|
@ -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>
|
12
source/connector-mobilizon/view/events-list.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
// Exit if this file is called directly.
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<ul class="<?php echo esc_attr($classNamePrefix); ?>_events-list"
|
||||||
|
data-url="<?php echo esc_attr($url); ?>"
|
||||||
|
data-maximum="<?php echo esc_attr($eventsCount); ?>"
|
||||||
|
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>
|
||||||
|
</ul>
|
@ -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>
|
@ -1 +0,0 @@
|
|||||||
import './blocks/events-list/index.js'
|
|
@ -1,87 +0,0 @@
|
|||||||
/* eslint-disable @wordpress/i18n-ellipsis */
|
|
||||||
import { loadEventList } from '../../events-loader.js'
|
|
||||||
|
|
||||||
const { InspectorControls, useBlockProps } = wp.blockEditor
|
|
||||||
const { PanelBody } = wp.components
|
|
||||||
const { useEffect } = wp.element
|
|
||||||
const { __ } = wp.i18n
|
|
||||||
|
|
||||||
const NAME = '<wordpress-name>'
|
|
||||||
|
|
||||||
let timer
|
|
||||||
|
|
||||||
export default ({ attributes, setAttributes }) => {
|
|
||||||
const blockProps = useBlockProps({
|
|
||||||
className: NAME + '_events-list',
|
|
||||||
'data-maximum': attributes.eventsCount,
|
|
||||||
'data-group-name': attributes.groupName,
|
|
||||||
})
|
|
||||||
function reloadEventList() {
|
|
||||||
if (timer) {
|
|
||||||
clearTimeout(timer)
|
|
||||||
}
|
|
||||||
timer = setTimeout(() => {
|
|
||||||
const container = document.getElementById(blockProps.id)
|
|
||||||
if (container) {
|
|
||||||
loadEventList(container)
|
|
||||||
}
|
|
||||||
}, 500)
|
|
||||||
}
|
|
||||||
useEffect(() => {
|
|
||||||
reloadEventList()
|
|
||||||
}, [])
|
|
||||||
function updateEventsCount(event) {
|
|
||||||
let newValue = Number(event.target.value)
|
|
||||||
if (newValue < 1) newValue = 1
|
|
||||||
setAttributes({ eventsCount: newValue })
|
|
||||||
reloadEventList()
|
|
||||||
}
|
|
||||||
function updateGroupName(event) {
|
|
||||||
setAttributes({ groupName: event.target.value })
|
|
||||||
reloadEventList()
|
|
||||||
}
|
|
||||||
return [
|
|
||||||
<InspectorControls>
|
|
||||||
<PanelBody title={__('Events List Settings', '<wordpress-name>')}>
|
|
||||||
<label
|
|
||||||
className="components-base-control__label"
|
|
||||||
htmlFor={NAME + '_events-count'}
|
|
||||||
>
|
|
||||||
{__('Number of events to show', '<wordpress-name>')}
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
className="components-text-control__input"
|
|
||||||
type="number"
|
|
||||||
value={attributes.eventsCount}
|
|
||||||
onChange={updateEventsCount}
|
|
||||||
id={NAME + '_events-count'}
|
|
||||||
/>
|
|
||||||
<label
|
|
||||||
className="components-base-control__label"
|
|
||||||
htmlFor={NAME + '_group-name'}
|
|
||||||
>
|
|
||||||
{__('Group name (optional)', '<wordpress-name>')}
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
className="components-text-control__input"
|
|
||||||
type="text"
|
|
||||||
value={attributes.groupName}
|
|
||||||
onChange={updateGroupName}
|
|
||||||
id={NAME + '_group-name'}
|
|
||||||
/>
|
|
||||||
</PanelBody>
|
|
||||||
</InspectorControls>,
|
|
||||||
<div {...blockProps}>
|
|
||||||
<div className="general-error" style={{ display: 'none' }}>
|
|
||||||
{__('The events could not be loaded!', '<wordpress-name>')}
|
|
||||||
</div>
|
|
||||||
<div className="group-not-found" style={{ display: 'none' }}>
|
|
||||||
{__('The group could not be found!', '<wordpress-name>')}
|
|
||||||
</div>
|
|
||||||
<div className="loading-indicator" style={{ display: 'none' }}>
|
|
||||||
{__('Loading...', '<wordpress-name>')}
|
|
||||||
</div>
|
|
||||||
<ul style={{ 'list-style-type': 'none', 'padding-left': 0 }}></ul>
|
|
||||||
</div>,
|
|
||||||
]
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
import edit from './edit.js'
|
|
||||||
|
|
||||||
const { registerBlockType } = wp.blocks
|
|
||||||
|
|
||||||
const NAME = '<wordpress-name>'
|
|
||||||
|
|
||||||
registerBlockType(NAME + '/events-list', { edit })
|
|
@ -1,87 +0,0 @@
|
|||||||
import test from 'ava'
|
|
||||||
import DateTimeWrapper from './date-time-wrapper.js'
|
|
||||||
|
|
||||||
test('#getShortDate usual date', (t) => {
|
|
||||||
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' })
|
|
||||||
t.is(d.getShortDate(), '24/12/2020')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('#getShortDate usual date with timezone string', (t) => {
|
|
||||||
const d = new DateTimeWrapper({
|
|
||||||
text: '2020-12-24T16:45:00Z',
|
|
||||||
timeZone: 'Europe/Rome',
|
|
||||||
})
|
|
||||||
t.is(d.getShortDate(), '24/12/2020')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('#getShortDate usual date with fixed offset', (t) => {
|
|
||||||
const d = new DateTimeWrapper({
|
|
||||||
text: '2020-12-24T16:45:00Z',
|
|
||||||
timeZone: 'UTC+02:00',
|
|
||||||
})
|
|
||||||
t.is(d.getShortDate(), '24/12/2020')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('#getShortDate usual date with fixed offset without UTC prefix', (t) => {
|
|
||||||
const d = new DateTimeWrapper({
|
|
||||||
text: '2020-12-24T16:45:00Z',
|
|
||||||
timeZone: '+02:00',
|
|
||||||
})
|
|
||||||
t.is(d.getShortDate(), '24/12/2020')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('#getShortDate usual date with empty time zone', (t) => {
|
|
||||||
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z', timeZone: '' })
|
|
||||||
t.is(d.getShortDate(), '24/12/2020')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('#get24Time usual time', (t) => {
|
|
||||||
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' })
|
|
||||||
t.is(d.get24Time(), '16:45')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('#equalsDate same date, different time', (t) => {
|
|
||||||
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' })
|
|
||||||
const e = new DateTimeWrapper({ text: '2020-12-24T17:46:01Z' })
|
|
||||||
t.true(d.equalsDate(e))
|
|
||||||
})
|
|
||||||
|
|
||||||
test('#equalsDate different date, different time', (t) => {
|
|
||||||
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' })
|
|
||||||
const e = new DateTimeWrapper({ text: '2021-11-25T17:46:01Z' })
|
|
||||||
t.false(d.equalsDate(e))
|
|
||||||
})
|
|
||||||
|
|
||||||
test('#equalsDate different day, different time', (t) => {
|
|
||||||
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' })
|
|
||||||
const e = new DateTimeWrapper({ text: '2020-12-25T17:46:01Z' })
|
|
||||||
t.false(d.equalsDate(e))
|
|
||||||
})
|
|
||||||
|
|
||||||
test('#equalsDate different month, different time', (t) => {
|
|
||||||
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' })
|
|
||||||
const e = new DateTimeWrapper({ text: '2020-11-24T17:46:01Z' })
|
|
||||||
t.false(d.equalsDate(e))
|
|
||||||
})
|
|
||||||
|
|
||||||
test('#equalsDate different year, different time', (t) => {
|
|
||||||
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' })
|
|
||||||
const e = new DateTimeWrapper({ text: '2021-12-24T17:46:01Z' })
|
|
||||||
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], ':')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('#getShortOffsetName usual time', (t) => {
|
|
||||||
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' })
|
|
||||||
t.is(d.getShortOffsetName(), 'UTC')
|
|
||||||
})
|
|
@ -1,122 +0,0 @@
|
|||||||
import test from 'ava'
|
|
||||||
import browserEnv from 'browser-env'
|
|
||||||
|
|
||||||
import {
|
|
||||||
displayEvents,
|
|
||||||
displayErrorMessage,
|
|
||||||
hideErrorMessages,
|
|
||||||
showLoadingIndicator,
|
|
||||||
} from './events-displayer.js'
|
|
||||||
|
|
||||||
test.before(() => {
|
|
||||||
browserEnv()
|
|
||||||
window.MOBILIZON_CONNECTOR = {
|
|
||||||
locale: 'en-GB',
|
|
||||||
timeZone: 'utc',
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
test.beforeEach((t) => {
|
|
||||||
t.context.container = document.createElement('div')
|
|
||||||
t.context.container.setAttribute('data-maximum', '2')
|
|
||||||
|
|
||||||
const errorMessageGeneral = document.createElement('div')
|
|
||||||
errorMessageGeneral.setAttribute('class', 'general-error')
|
|
||||||
errorMessageGeneral.setAttribute('style', 'display: none;')
|
|
||||||
t.context.container.appendChild(errorMessageGeneral)
|
|
||||||
|
|
||||||
const errorMessageGroupNotFound = document.createElement('div')
|
|
||||||
errorMessageGroupNotFound.setAttribute('class', 'group-not-found')
|
|
||||||
errorMessageGroupNotFound.setAttribute('style', 'display: none;')
|
|
||||||
t.context.container.appendChild(errorMessageGroupNotFound)
|
|
||||||
|
|
||||||
const loadingIndicator = document.createElement('div')
|
|
||||||
loadingIndicator.setAttribute('class', 'loading-indicator')
|
|
||||||
loadingIndicator.setAttribute('style', 'display: none;')
|
|
||||||
t.context.container.appendChild(loadingIndicator)
|
|
||||||
|
|
||||||
const list = document.createElement('ul')
|
|
||||||
t.context.container.appendChild(list)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('#displayEvents one event', (t) => {
|
|
||||||
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',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
const container = t.context.container
|
|
||||||
displayEvents({ data, document, container })
|
|
||||||
const list = container.querySelector('ul')
|
|
||||||
t.is(list.children[0].childNodes[0].tagName, 'A')
|
|
||||||
t.is(list.children[0].childNodes[0].getAttribute('href'), 'b')
|
|
||||||
t.is(list.children[0].childNodes[0].childNodes[0].nodeValue, 'a')
|
|
||||||
t.is(list.children[0].childNodes[1].tagName, 'BR')
|
|
||||||
t.is(list.children[0].childNodes[2].nodeValue, '15/04/2021 10:30 - 15:30')
|
|
||||||
t.is(list.children[0].childNodes[3].tagName, 'BR')
|
|
||||||
t.is(list.children[0].childNodes[4].nodeValue, 'c, d')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('#displayErrorMessage no list entries shown', (t) => {
|
|
||||||
const container = t.context.container
|
|
||||||
displayErrorMessage({ data: '', container })
|
|
||||||
const list = container.querySelector('ul')
|
|
||||||
t.is(list.children.length, 0)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('#displayErrorMessage general error message display', (t) => {
|
|
||||||
const container = t.context.container
|
|
||||||
displayErrorMessage({ data: '', container })
|
|
||||||
t.is(container.querySelector('.general-error').style.display, 'block')
|
|
||||||
t.is(container.querySelector('.group-not-found').style.display, 'none')
|
|
||||||
t.is(container.querySelector('.loading-indicator').style.display, 'none')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('#displayErrorMessage group not found error message display', (t) => {
|
|
||||||
const container = t.context.container
|
|
||||||
const data = {
|
|
||||||
response: {
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
code: 'group_not_found',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
displayErrorMessage({ data, container })
|
|
||||||
t.is(container.querySelector('.general-error').style.display, 'none')
|
|
||||||
t.is(container.querySelector('.group-not-found').style.display, 'block')
|
|
||||||
t.is(container.querySelector('.loading-indicator').style.display, 'none')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('#showLoadingIndicator remove events', (t) => {
|
|
||||||
const container = t.context.container
|
|
||||||
const loadingIndicator = container.querySelector('.loading-indicator')
|
|
||||||
t.is(loadingIndicator.style.display, 'none')
|
|
||||||
showLoadingIndicator(container)
|
|
||||||
t.is(loadingIndicator.style.display, 'block')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('#hideErrorMessages remove events', (t) => {
|
|
||||||
const container = t.context.container
|
|
||||||
const generalErrorMessage = container.querySelector('.general-error')
|
|
||||||
const groupNotFoundErrorMessage = container.querySelector('.group-not-found')
|
|
||||||
generalErrorMessage.style.display = 'block'
|
|
||||||
groupNotFoundErrorMessage.style.display = 'block'
|
|
||||||
t.is(generalErrorMessage.style.display, 'block')
|
|
||||||
t.is(groupNotFoundErrorMessage.style.display, 'block')
|
|
||||||
hideErrorMessages(container)
|
|
||||||
t.is(generalErrorMessage.style.display, 'none')
|
|
||||||
t.is(groupNotFoundErrorMessage.style.display, 'none')
|
|
||||||
})
|
|
@ -1,95 +0,0 @@
|
|||||||
import Formatter from './formatter.js'
|
|
||||||
import { createAnchorElement } from './html-creator.js'
|
|
||||||
|
|
||||||
export function clearEventsList(container) {
|
|
||||||
const list = container.querySelector('ul')
|
|
||||||
list.replaceChildren()
|
|
||||||
}
|
|
||||||
|
|
||||||
export function displayEvents({ data, document, container }) {
|
|
||||||
hideLoadingIndicator(container)
|
|
||||||
|
|
||||||
const isShortOffsetNameShown =
|
|
||||||
window.MOBILIZON_CONNECTOR.isShortOffsetNameShown
|
|
||||||
const locale = window.MOBILIZON_CONNECTOR.locale
|
|
||||||
const maxEventsCount = container.getAttribute('data-maximum')
|
|
||||||
const timeZone = window.MOBILIZON_CONNECTOR.timeZone
|
|
||||||
|
|
||||||
const events = data.events
|
|
||||||
? data.events.elements
|
|
||||||
: data.group.organizedEvents.elements
|
|
||||||
const eventsCount = Math.min(maxEventsCount, events.length)
|
|
||||||
const list = container.querySelector('ul')
|
|
||||||
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, container }) {
|
|
||||||
hideLoadingIndicator(container)
|
|
||||||
if (
|
|
||||||
Object.prototype.hasOwnProperty.call(data, 'response') &&
|
|
||||||
Object.prototype.hasOwnProperty.call(data.response, 'errors') &&
|
|
||||||
data.response.errors.length > 0 &&
|
|
||||||
Object.prototype.hasOwnProperty.call(data.response.errors[0], 'code') &&
|
|
||||||
data.response.errors[0].code === 'group_not_found'
|
|
||||||
) {
|
|
||||||
const message = container.querySelector('.group-not-found')
|
|
||||||
message.style.display = 'block'
|
|
||||||
} else {
|
|
||||||
const message = container.querySelector('.general-error')
|
|
||||||
message.style.display = 'block'
|
|
||||||
console.error(data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function showLoadingIndicator(container) {
|
|
||||||
const indicator = container.querySelector('.loading-indicator')
|
|
||||||
indicator.style.display = 'block'
|
|
||||||
}
|
|
||||||
|
|
||||||
function hideLoadingIndicator(container) {
|
|
||||||
const indicator = container.querySelector('.loading-indicator')
|
|
||||||
indicator.style.display = 'none'
|
|
||||||
}
|
|
||||||
|
|
||||||
export function hideErrorMessages(container) {
|
|
||||||
container.querySelector('.group-not-found').style.display = 'none'
|
|
||||||
container.querySelector('.general-error').style.display = 'none'
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
import {
|
|
||||||
clearEventsList,
|
|
||||||
displayEvents,
|
|
||||||
displayErrorMessage,
|
|
||||||
hideErrorMessages,
|
|
||||||
showLoadingIndicator,
|
|
||||||
} from './events-displayer.js'
|
|
||||||
import * as GraphqlWrapper from './graphql-wrapper.js'
|
|
||||||
|
|
||||||
const NAME = '<wordpress-name>'
|
|
||||||
const URL_SUFFIX = '/api'
|
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', loadEventLists)
|
|
||||||
|
|
||||||
function loadEventLists() {
|
|
||||||
const eventLists = document.getElementsByClassName(NAME + '_events-list')
|
|
||||||
for (const list of eventLists) {
|
|
||||||
loadEventList(list)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function loadEventList(container) {
|
|
||||||
const url = MOBILIZON_CONNECTOR.url + URL_SUFFIX
|
|
||||||
const limit = parseInt(container.getAttribute('data-maximum'))
|
|
||||||
const groupName = container.getAttribute('data-group-name')
|
|
||||||
hideErrorMessages(container)
|
|
||||||
clearEventsList(container)
|
|
||||||
showLoadingIndicator(container)
|
|
||||||
if (groupName) {
|
|
||||||
GraphqlWrapper.getUpcomingEventsByGroupName({ url, limit, groupName })
|
|
||||||
.then((data) => displayEvents({ data, document, container }))
|
|
||||||
.catch((data) => displayErrorMessage({ data, container }))
|
|
||||||
} else {
|
|
||||||
GraphqlWrapper.getUpcomingEvents({ url, limit })
|
|
||||||
.then((data) => displayEvents({ data, document, container }))
|
|
||||||
.catch((data) => displayErrorMessage({ data, container }))
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,73 +0,0 @@
|
|||||||
import test from 'ava'
|
|
||||||
import Formatter from './formatter.js'
|
|
||||||
|
|
||||||
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 10:30 - 15: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) => {
|
|
||||||
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')
|
|
||||||
})
|
|
||||||
|
|
||||||
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 - 16/04/2021 15:30 (UTC)')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('#formatDate second date is null', (t) => {
|
|
||||||
const date = Formatter.formatDate({
|
|
||||||
start: '2021-04-15T10:30:00Z',
|
|
||||||
end: null,
|
|
||||||
})
|
|
||||||
t.is(date, '15/04/2021 10:30')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('#formatDate second date is null with short offset name', (t) => {
|
|
||||||
const date = Formatter.formatDate({
|
|
||||||
start: '2021-04-15T10:30:00Z',
|
|
||||||
end: null,
|
|
||||||
isShortOffsetNameShown: true,
|
|
||||||
})
|
|
||||||
t.is(date, '15/04/2021 10:30 (UTC)')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('#formatLocation both parameters', (t) => {
|
|
||||||
const location = Formatter.formatLocation({ description: 'a', locality: 'b' })
|
|
||||||
t.is(location, 'a, b')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('#formatLocation description only', (t) => {
|
|
||||||
const location = Formatter.formatLocation({ description: 'a' })
|
|
||||||
t.is(location, 'a')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('#formatLocation description with space only', (t) => {
|
|
||||||
const location = Formatter.formatLocation({ description: ' ' })
|
|
||||||
t.is(location, '')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('#formatLocation locality only', (t) => {
|
|
||||||
const location = Formatter.formatLocation({ locality: 'a' })
|
|
||||||
t.is(location, 'a')
|
|
||||||
})
|
|
@ -1,45 +0,0 @@
|
|||||||
import DateTimeWrapper from './date-time-wrapper.js'
|
|
||||||
|
|
||||||
export default class Formatter {
|
|
||||||
static formatDate({ locale, timeZone, start, end, isShortOffsetNameShown }) {
|
|
||||||
const startDateTime = new DateTimeWrapper({
|
|
||||||
locale,
|
|
||||||
text: start,
|
|
||||||
timeZone,
|
|
||||||
})
|
|
||||||
let dateText = startDateTime.getShortDate()
|
|
||||||
dateText += ' ' + startDateTime.get24Time()
|
|
||||||
if (!end && isShortOffsetNameShown) {
|
|
||||||
dateText += ' (' + startDateTime.getShortOffsetName() + ')'
|
|
||||||
}
|
|
||||||
|
|
||||||
if (end) {
|
|
||||||
const endDateTime = new DateTimeWrapper({ locale, text: end, timeZone })
|
|
||||||
if (!startDateTime.equalsDate(endDateTime)) {
|
|
||||||
dateText += ' - '
|
|
||||||
dateText += endDateTime.getShortDate() + ' '
|
|
||||||
} else {
|
|
||||||
dateText += ' - '
|
|
||||||
}
|
|
||||||
dateText += endDateTime.get24Time()
|
|
||||||
if (isShortOffsetNameShown) {
|
|
||||||
dateText += ' (' + endDateTime.getShortOffsetName() + ')'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return dateText
|
|
||||||
}
|
|
||||||
|
|
||||||
static formatLocation({ description, locality }) {
|
|
||||||
let location = ''
|
|
||||||
if (description && description.trim()) {
|
|
||||||
location += description.trim()
|
|
||||||
}
|
|
||||||
if (location && locality) {
|
|
||||||
location += ', '
|
|
||||||
}
|
|
||||||
if (locality) {
|
|
||||||
location += locality
|
|
||||||
}
|
|
||||||
return location
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
import test from 'ava'
|
|
||||||
import browserEnv from 'browser-env'
|
|
||||||
|
|
||||||
import { createAnchorElement } from './html-creator.js'
|
|
||||||
|
|
||||||
test.beforeEach(() => {
|
|
||||||
browserEnv()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('#createAnchorElement usual parameters', (t) => {
|
|
||||||
const a = createAnchorElement({ document, text: 'a', url: 'b' })
|
|
||||||
t.is(a.tagName, 'A')
|
|
||||||
t.is(a.innerHTML, 'a')
|
|
||||||
t.is(a.getAttribute('href'), 'b')
|
|
||||||
})
|
|
@ -1,6 +0,0 @@
|
|||||||
import test from 'ava'
|
|
||||||
import hash from './object-hash-wrapper.js'
|
|
||||||
|
|
||||||
test('#hash object', (t) => {
|
|
||||||
t.is(hash({ foo: 'bar' }), 'a75c05bdca7d704bdfcd761913e5a4e4636e956b')
|
|
||||||
})
|
|
@ -1,53 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace MobilizonConnector;
|
|
||||||
|
|
||||||
// Exit if this file is called directly.
|
|
||||||
if (!defined('ABSPATH')) {
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
class EventsListBlock {
|
|
||||||
|
|
||||||
public static function initAndReturnScriptName(): string {
|
|
||||||
$scriptName = NAME . '-block-starter';
|
|
||||||
wp_register_script($scriptName, plugins_url(NAME . '/front/block-events-loader.js'), [
|
|
||||||
'wp-block-editor',
|
|
||||||
'wp-blocks',
|
|
||||||
'wp-components',
|
|
||||||
'wp-i18n'
|
|
||||||
]);
|
|
||||||
register_block_type(NAME . '/events-list', [
|
|
||||||
'api_version' => 2,
|
|
||||||
'title' => __('Events List', 'connector-mobilizon'),
|
|
||||||
'description' => __('A list of the upcoming events of the connected Mobilizon instance.', 'connector-mobilizon'),
|
|
||||||
'category' => 'widgets',
|
|
||||||
'icon' => 'list-view',
|
|
||||||
'supports' => [
|
|
||||||
'html' => false
|
|
||||||
],
|
|
||||||
'attributes' => [
|
|
||||||
'eventsCount' => [
|
|
||||||
'type' => 'number',
|
|
||||||
'default' => 3,
|
|
||||||
],
|
|
||||||
'groupName' => [
|
|
||||||
'type' => 'string',
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'editor_script' => $scriptName,
|
|
||||||
'render_callback' => 'MobilizonConnector\EventsListBlock::render',
|
|
||||||
]);
|
|
||||||
return $scriptName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function render($block_attributes, $content) {
|
|
||||||
$classNamePrefix = NAME;
|
|
||||||
$eventsCount = $block_attributes['eventsCount'];
|
|
||||||
$groupName = isset($block_attributes['groupName']) ? $block_attributes['groupName'] : '';
|
|
||||||
|
|
||||||
ob_start();
|
|
||||||
require dirname(__DIR__) . '/view/events-list.php';
|
|
||||||
$output = ob_get_clean();
|
|
||||||
return $output;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,168 +0,0 @@
|
|||||||
# <wordpress-nice-name>
|
|
||||||
Contributors: dwaxweiler
|
|
||||||
Donate link: <wordpress-donation-link>
|
|
||||||
Tags: mobilizon, events
|
|
||||||
Stable tag: <wordpress-version>
|
|
||||||
Requires at least: <wordpress-minimum-version>
|
|
||||||
Tested up to: <wordpress-tested-up-to-version>
|
|
||||||
Requires PHP: <wordpress-php-minimum-version>
|
|
||||||
License: <wordpress-license>
|
|
||||||
|
|
||||||
<wordpress-description>
|
|
||||||
|
|
||||||
## Description
|
|
||||||
|
|
||||||
<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
|
|
||||||
- Display events as Gutenberg block, 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 block, per widget and per shortcut
|
|
||||||
- Optionally filter events by a specific group per block, 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
|
|
||||||
|
|
||||||
The source code is available on [Github](https://github.com/dwaxweiler/connector-mobilizon).
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
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"]`
|
|
||||||
You have to use their username, e.g. `@nosliensvivants`, and append the name of their instance if they use a different one, e.g. `@yaam_berlin@mobilize.berlin`.
|
|
||||||
|
|
||||||
## Screenshots
|
|
||||||
1. Events list
|
|
||||||
2. General settings
|
|
||||||
3. Widget creation
|
|
||||||
4. Shortcut creation
|
|
||||||
5. Gutenberg block in editor
|
|
||||||
|
|
||||||
## Changelog
|
|
||||||
|
|
||||||
### [0.11.1]
|
|
||||||
#### Fixed
|
|
||||||
- Revert minimum PHP version to 7.4 to allow some more time for upgrading PHP
|
|
||||||
|
|
||||||
### [0.11.0]
|
|
||||||
#### Changed
|
|
||||||
- Update dependencies
|
|
||||||
- Confirm compatibility with WordPress 6.2
|
|
||||||
#### Security
|
|
||||||
- Set minimum PHP version to oldest stable 8.0
|
|
||||||
|
|
||||||
### [0.10.1]
|
|
||||||
#### Changed
|
|
||||||
- Confirm compatibility with WordPress 6.1
|
|
||||||
- Update dependencies
|
|
||||||
|
|
||||||
### [0.10.0]
|
|
||||||
#### Added
|
|
||||||
- Add Gutenberg events list block
|
|
||||||
- Show loading indicator during request
|
|
||||||
#### Changed
|
|
||||||
- Set list style type to none and left padding to zero for all occurences
|
|
||||||
- Move shortcut usage description into installation section in `readme.txt`
|
|
||||||
- Update dependencies
|
|
||||||
|
|
||||||
### [0.9.1] - 2020-05-19
|
|
||||||
#### Fixed
|
|
||||||
- Fix WordPress compatibility version number
|
|
||||||
|
|
||||||
### [0.9.0] - 2020-05-19
|
|
||||||
#### Added
|
|
||||||
- Improve explanation of group name filter
|
|
||||||
#### Changed
|
|
||||||
- Update dependencies
|
|
||||||
- Confirm compatibility with WordPress 6.0
|
|
||||||
#### Fixed
|
|
||||||
- Fix displaying error message for the case the group is not found
|
|
||||||
|
|
||||||
### [0.8.0] - 2022-01-09
|
|
||||||
#### Added
|
|
||||||
- Add support for older browsers using babel
|
|
||||||
#### Changed
|
|
||||||
- Confirm compatibility with WordPress 5.9
|
|
||||||
- Update dependencies
|
|
||||||
#### Fixed
|
|
||||||
- Use ES modules correctly
|
|
||||||
- Trim events' location
|
|
||||||
|
|
||||||
### [0.7.0] - 2021-12-23
|
|
||||||
#### Added
|
|
||||||
- Add specific error message for the case the group is not found
|
|
||||||
- Add code formatter prettier
|
|
||||||
#### Changed
|
|
||||||
- Update dependencies
|
|
||||||
- Simplify build process
|
|
||||||
#### Fixed
|
|
||||||
- Fix Invalid DateTime on event end time being null
|
|
||||||
#### Security
|
|
||||||
- Set minimum PHP version to oldest stable 7.4
|
|
||||||
|
|
||||||
### [0.6.2] - 2021-08-24
|
|
||||||
#### Changed
|
|
||||||
- Update dependencies
|
|
||||||
#### Fixed
|
|
||||||
- Fix empty WordPress timezone_string option resulting in Invalid DateTime
|
|
||||||
|
|
||||||
### [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
|
|
||||||
#### 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
|
|
||||||
#### 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,14 +0,0 @@
|
|||||||
<?php
|
|
||||||
// Exit if this file is called directly.
|
|
||||||
if (!defined('ABSPATH')) {
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
<div class="<?php echo esc_attr($classNamePrefix); ?>_events-list"
|
|
||||||
data-maximum="<?php echo esc_attr($eventsCount); ?>"
|
|
||||||
data-group-name="<?php echo esc_attr($groupName); ?>">
|
|
||||||
<div class="general-error" style="display: none;"><?php esc_html_e('The events could not be loaded!', 'connector-mobilizon'); ?></div>
|
|
||||||
<div class="group-not-found" style="display: none;"><?php esc_html_e('The group could not be found!', 'connector-mobilizon'); ?></div>
|
|
||||||
<div class="loading-indicator" style="display: none;"><?php esc_html_e('Loading...', 'connector-mobilizon'); ?></div>
|
|
||||||
<ul style="list-style-type: none; padding-left: 0;"></ul>
|
|
||||||
</div>
|
|
@ -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>
|
|
@ -1,47 +0,0 @@
|
|||||||
/* eslint-disable no-undef */
|
|
||||||
const path = require('path')
|
|
||||||
|
|
||||||
const CopyPlugin = require('copy-webpack-plugin')
|
|
||||||
|
|
||||||
const FOLDER_SOURCE = './source'
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
entry: {
|
|
||||||
'block-events-loader': FOLDER_SOURCE + '/front/block-events-loader.js',
|
|
||||||
'events-loader': FOLDER_SOURCE + '/front/events-loader.js',
|
|
||||||
},
|
|
||||||
output: {
|
|
||||||
filename: '[name].js',
|
|
||||||
path: path.resolve(__dirname, 'build/front'),
|
|
||||||
},
|
|
||||||
module: {
|
|
||||||
rules: [
|
|
||||||
{
|
|
||||||
test: /\.m?js$/,
|
|
||||||
exclude: /node_modules/,
|
|
||||||
use: {
|
|
||||||
loader: 'babel-loader',
|
|
||||||
options: {
|
|
||||||
presets: [['@babel/preset-env', { targets: 'defaults' }]],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
new CopyPlugin({
|
|
||||||
patterns: [
|
|
||||||
{
|
|
||||||
context: FOLDER_SOURCE,
|
|
||||||
from: '**/*.php',
|
|
||||||
to: '../',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
context: FOLDER_SOURCE,
|
|
||||||
from: '**/*.txt',
|
|
||||||
to: '../',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
}
|
|