Skip to content

Commit

Permalink
Initial commit for version 1.0.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
scottboms committed Feb 10, 2024
1 parent 2008985 commit 5b6bce1
Show file tree
Hide file tree
Showing 8 changed files with 681 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
Icon
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MIT License
The MIT License (MIT)

Copyright (c) 2024 Scott Boms

Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
48 changes: 46 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,46 @@
# kirby-microseasons
Japanese micro seasons plugin for Kirby.
# Japanese Micro Seasons Plugin for Kirby

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.

## Requirements

- [**Kirby**](https://getkirby.com/) 4.x

## Installation

### [Kirby CLI](https://github.com/getkirby/cli)

kirby plugin:install scottboms/kirby-microseasons

### Git Submodule

$ git submodule add https://github.com/scottboms/kirby-microseasons.git site/plugins/kirby-microseasons

### Copy and Paste

1. [Download](https://github.com/scottboms/kirby-microseasons/archive/master.zip) the contents of this repository as Zip file.
2. Rename the extracted folder to `kirby-microseasons` and copy it into the `site/plugins/` directory in your Kirby project.

## Usage

In any template, drop in the following line to include the output from this plugin in your site.

<?= snippet('microseasons') ?>

## Configuration Options

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).

'scottboms.microseasons' => [
'wrapper' => 'div',
'class' => 'microseasons',
'dateformat' => 'M d, Y'
],

## Disclaimer

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.

## License

[MIT](https://opensource.org/licenses/MIT)
48 changes: 48 additions & 0 deletions classes/Microseasons.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Scottboms\Microseasons;
use Kirby\Toolkit\Date;

class Season {

public static function getAllSeasons(): string {
return __DIR__ . '/../microseasons.json';
}

public static function getSeason($currentDate, $jsonFileUrl): array {
// fetch and decode the JSON data from the external link
$json = file_get_contents($jsonFileUrl);
$seasonsArray = json_decode($json, true);

// convert $currentDate passed to 4-character mmdd format
// since we don't care about the specific year
$timestamp = date("m-d", strtotime($currentDate));

// create $currentSeason to hold an array of data to return
$currentSeason = array();

// check which season the current date falls within
foreach ($seasonsArray as $season) {
$start = $season["start"];
$end = $season["end"];

// adjust the start and end dates to handle year transitions
if ($start > $end) {
if ($timestamp >= $start || $timestamp < $end) {
// convert the date information to dates object
$season["start"] = Date::createFromFormat('m-d', $start);
$season["end"] = Date::createFromFormat('m-d', $end);
return $currentSeason[] = $season; // return the matching season
}
} else {
if ($timestamp >= $start && $timestamp < $end) {
$season["start"] = Date::createFromFormat('m-d', $start);
$season["end"] = Date::createFromFormat('m-d', $end);
return $currentSeason[] = $season; // return the matching season
}
}
}
return $currentSeason; // no match fallback
}

}
27 changes: 27 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "scottboms/microseasons",
"description": "Kirby Micro Seasons plugin",
"type": "kirby-plugin",
"version": "1.0.0",
"homepage": "https://github.com/scottboms/kirby-microseasons",
"authors": [
{
"name": "Scott Boms",
"email": "[email protected]",
"homepage": "https://scottboms.com"
}
],
"license": "MIT",

"keywords": [
"kirby3",
"kirby3-cms",
"kirby3-plugin"
],
"require": {
"getkirby/composer-installer": "^1.1"
},
"extra": {
"installer-name": "kirby-microseasons"
}
}
31 changes: 31 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

//namespace scottboms\kirby-microseasons;

/**
* Kirby Japanese Microseasons Plugin
*
* @version 1.0.0
* @author Scott Boms <[email protected]>
* @copyright Scott Boms <[email protected]>
* @link https://github.com/scottboms/kirby-microseasons
* @license MIT
**/

load([
'scottboms\Microseasons\Season' => __DIR__ . '/classes/Microseasons.php'
]);

use Scottboms\Microseasons\Season;
use Kirby\Toolkit\Date;

Kirby::plugin('scottboms/microseasons', [
'options' => [
'wrapper' => 'div',
'class' => 'microseasons',
'dateformat' => 'M d'
],
'snippets' => [
'microseasons' => __DIR__ . '/snippets/microseasons.php'
]
]);
Loading

0 comments on commit 5b6bce1

Please sign in to comment.