Skip to content

Commit 5b6bce1

Browse files
committed
Initial commit for version 1.0.0.
1 parent 2008985 commit 5b6bce1

File tree

8 files changed

+681
-4
lines changed

8 files changed

+681
-4
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.DS_Store
2+
Icon

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
MIT License
1+
The MIT License (MIT)
22

33
Copyright (c) 2024 Scott Boms
44

@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
21+
SOFTWARE.

README.md

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,46 @@
1-
# kirby-microseasons
2-
Japanese micro seasons plugin for Kirby.
1+
# Japanese Micro Seasons Plugin for Kirby
2+
3+
Output information for one of the [72 Japanese micro season](https://www.nippon.com/en/features/h00124/) based on the current date directly into your Kirby templates and customize using the provided options in your Kirby `config.php` file.
4+
5+
## Requirements
6+
7+
- [**Kirby**](https://getkirby.com/) 4.x
8+
9+
## Installation
10+
11+
### [Kirby CLI](https://github.com/getkirby/cli)
12+
13+
kirby plugin:install scottboms/kirby-microseasons
14+
15+
### Git Submodule
16+
17+
$ git submodule add https://github.com/scottboms/kirby-microseasons.git site/plugins/kirby-microseasons
18+
19+
### Copy and Paste
20+
21+
1. [Download](https://github.com/scottboms/kirby-microseasons/archive/master.zip) the contents of this repository as Zip file.
22+
2. Rename the extracted folder to `kirby-microseasons` and copy it into the `site/plugins/` directory in your Kirby project.
23+
24+
## Usage
25+
26+
In any template, drop in the following line to include the output from this plugin in your site.
27+
28+
<?= snippet('microseasons') ?>
29+
30+
## Configuration Options
31+
32+
If you want to modify the wrapper HTML element, change the wrapper class, or output the date information in a custom format, you can configure this using the included plugin options. Date formatting follows the [available format options from PHP](https://www.php.net/manual/en/function.date.php).
33+
34+
'scottboms.microseasons' => [
35+
'wrapper' => 'div',
36+
'class' => 'microseasons',
37+
'dateformat' => 'M d, Y'
38+
],
39+
40+
## Disclaimer
41+
42+
This plugin is provided "as is" with no guarantee. Use it at your own risk and always test before using it in a production environment. If you identify an issue, typo, etc, please [create a new issue](https://github.com/scottboms/kirby-microseasons/issues/new) so I can investigate.
43+
44+
## License
45+
46+
[MIT](https://opensource.org/licenses/MIT)

classes/Microseasons.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Scottboms\Microseasons;
4+
use Kirby\Toolkit\Date;
5+
6+
class Season {
7+
8+
public static function getAllSeasons(): string {
9+
return __DIR__ . '/../microseasons.json';
10+
}
11+
12+
public static function getSeason($currentDate, $jsonFileUrl): array {
13+
// fetch and decode the JSON data from the external link
14+
$json = file_get_contents($jsonFileUrl);
15+
$seasonsArray = json_decode($json, true);
16+
17+
// convert $currentDate passed to 4-character mmdd format
18+
// since we don't care about the specific year
19+
$timestamp = date("m-d", strtotime($currentDate));
20+
21+
// create $currentSeason to hold an array of data to return
22+
$currentSeason = array();
23+
24+
// check which season the current date falls within
25+
foreach ($seasonsArray as $season) {
26+
$start = $season["start"];
27+
$end = $season["end"];
28+
29+
// adjust the start and end dates to handle year transitions
30+
if ($start > $end) {
31+
if ($timestamp >= $start || $timestamp < $end) {
32+
// convert the date information to dates object
33+
$season["start"] = Date::createFromFormat('m-d', $start);
34+
$season["end"] = Date::createFromFormat('m-d', $end);
35+
return $currentSeason[] = $season; // return the matching season
36+
}
37+
} else {
38+
if ($timestamp >= $start && $timestamp < $end) {
39+
$season["start"] = Date::createFromFormat('m-d', $start);
40+
$season["end"] = Date::createFromFormat('m-d', $end);
41+
return $currentSeason[] = $season; // return the matching season
42+
}
43+
}
44+
}
45+
return $currentSeason; // no match fallback
46+
}
47+
48+
}

composer.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "scottboms/microseasons",
3+
"description": "Kirby Micro Seasons plugin",
4+
"type": "kirby-plugin",
5+
"version": "1.0.0",
6+
"homepage": "https://github.com/scottboms/kirby-microseasons",
7+
"authors": [
8+
{
9+
"name": "Scott Boms",
10+
"email": "[email protected]",
11+
"homepage": "https://scottboms.com"
12+
}
13+
],
14+
"license": "MIT",
15+
16+
"keywords": [
17+
"kirby3",
18+
"kirby3-cms",
19+
"kirby3-plugin"
20+
],
21+
"require": {
22+
"getkirby/composer-installer": "^1.1"
23+
},
24+
"extra": {
25+
"installer-name": "kirby-microseasons"
26+
}
27+
}

index.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
//namespace scottboms\kirby-microseasons;
4+
5+
/**
6+
* Kirby Japanese Microseasons Plugin
7+
*
8+
* @version 1.0.0
9+
* @author Scott Boms <[email protected]>
10+
* @copyright Scott Boms <[email protected]>
11+
* @link https://github.com/scottboms/kirby-microseasons
12+
* @license MIT
13+
**/
14+
15+
load([
16+
'scottboms\Microseasons\Season' => __DIR__ . '/classes/Microseasons.php'
17+
]);
18+
19+
use Scottboms\Microseasons\Season;
20+
use Kirby\Toolkit\Date;
21+
22+
Kirby::plugin('scottboms/microseasons', [
23+
'options' => [
24+
'wrapper' => 'div',
25+
'class' => 'microseasons',
26+
'dateformat' => 'M d'
27+
],
28+
'snippets' => [
29+
'microseasons' => __DIR__ . '/snippets/microseasons.php'
30+
]
31+
]);

0 commit comments

Comments
 (0)