Compare commits

...

10 Commits

16 changed files with 355 additions and 169 deletions

View File

@ -1,3 +1,15 @@
1.7.2 - 2023.06.17
- require dotclear 2.26
- fix require php 8.1
1.7.1 - 2023.05.13
- require dotclear 2.26
- cosmetic cleanup for dc2.26 stable
1.7 - 2023.04.25
- require dotclear 2.26
- use namespace
1.6 - 2022.12.15 1.6 - 2022.12.15
- update to dotclear 2.24 - update to dotclear 2.24

View File

@ -3,7 +3,7 @@
[![Release](https://img.shields.io/github/v/release/JcDenis/lunarPhase)](https://github.com/JcDenis/lunarPhase/releases) [![Release](https://img.shields.io/github/v/release/JcDenis/lunarPhase)](https://github.com/JcDenis/lunarPhase/releases)
[![Date](https://img.shields.io/github/release-date/JcDenis/lunarPhase)](https://github.com/JcDenis/lunarPhase/releases) [![Date](https://img.shields.io/github/release-date/JcDenis/lunarPhase)](https://github.com/JcDenis/lunarPhase/releases)
[![Issues](https://img.shields.io/github/issues/JcDenis/lunarPhase)](https://github.com/JcDenis/lunarPhase/issues) [![Issues](https://img.shields.io/github/issues/JcDenis/lunarPhase)](https://github.com/JcDenis/lunarPhase/issues)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.24-blue.svg)](https://fr.dotclear.org/download) [![Dotclear](https://img.shields.io/badge/dotclear-v2.26-blue.svg)](https://fr.dotclear.org/download)
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/lunarPhase) [![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/lunarPhase)
[![License](https://img.shields.io/github/license/JcDenis/lunarPhase)](https://github.com/JcDenis/lunarPhase/blob/master/LICENSE) [![License](https://img.shields.io/github/license/JcDenis/lunarPhase)](https://github.com/JcDenis/lunarPhase/blob/master/LICENSE)
@ -19,7 +19,8 @@ It shows lunar phases on a widget.
_lunarPhase_ requires: _lunarPhase_ requires:
* content admin permissions to manage widgets * content admin permissions to manage widgets
* Dotclear 2.24 * Dotclear 2.26
* require PHP 8.1+
## USAGE ## USAGE
@ -30,7 +31,7 @@ You should add widget to show lunar phases on your blog.
## LINKS ## LINKS
* License : [GNU GPL v2](https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html) * License : [GNU GPL v2](https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
* Source & contribution : [GitHub Page](https://github.com/JcDenis/lunarPhase) * Source & contribution : [GitHub Page](https://github.com/JcDenis/lunarPhase)
* Packages & details : [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/lunarPhase) * Packages & details : [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/lunarPhase)
* Discuss and help : [Dotclear Forum](http://forum.dotclear.org/viewtopic.php?pid=332971#p332971) * Discuss and help : [Dotclear Forum](http://forum.dotclear.org/viewtopic.php?pid=332971#p332971)

View File

@ -1,17 +0,0 @@
<?php
/**
* @brief lunarPhase, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Tomtom, Pierre Van Glabeke and Contributors
*
* @copyright Jean-Crhistian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
require __DIR__ . '/_widgets.php';

View File

@ -7,23 +7,26 @@
* *
* @author Tomtom, Pierre Van Glabeke and Contributors * @author Tomtom, Pierre Van Glabeke and Contributors
* *
* @copyright Jean-Crhistian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH') || is_null(dcCore::app()->auth)) {
return null; return null;
} }
$this->registerModule( $this->registerModule(
'lunarPhase', 'Moon phases',
'Display the moon phases on a widget', 'Display the moon phases on a widget',
'Tomtom, Pierre Van Glabeke and Contributors', 'Tomtom, Pierre Van Glabeke and Contributors',
'1.6', '1.7.2',
[ [
'requires' => [['core', '2.24']], 'requires' => [
['php', '8.1'],
['core', '2.26'],
],
'permissions' => dcCore::app()->auth->makePermissions([ 'permissions' => dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_USAGE, dcCore::app()->auth::PERMISSION_USAGE,
dcAuth::PERMISSION_CONTENT_ADMIN, dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]), ]),
'type' => 'plugin', 'type' => 'plugin',
'support' => 'http://forum.dotclear.org/viewtopic.php?pid=332971#p332971', 'support' => 'http://forum.dotclear.org/viewtopic.php?pid=332971#p332971',

View File

@ -1,50 +0,0 @@
<?php
/**
* @brief lunarPhase, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Tomtom, Pierre Van Glabeke and Contributors
*
* @copyright Jean-Crhistian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
}
Clearbricks::lib()->autoload(['lunarPhase' => __DIR__ . '/inc/class.lunarphase.php']);
// Register lunarphase CSS URL
dcCore::app()->url->register(
'lunarphase',
'lunarphase.css',
'^lunarphase\.css',
function ($args) {
$phases = [
'new_moon' => 'nm',
'waxing_crescent_moon' => 'wcm1',
'first_quarter_moon' => 'fqm',
'waxing_gibbous_moon' => 'wgm1',
'full_moon' => 'fm',
'waning_gibbous_moon' => 'wgm2',
'last_quarter_moon' => 'tqm',
'waning_crescent_moon' => 'wcm2',
];
header('Content-Type: text/css; charset=UTF-8');
echo "/* lunarphase widget style */\n";
foreach ($phases as $phase => $image) {
echo
sprintf(
'#sidebar .lunarphase ul li.%s{background:transparent url(%s) no-repeat left 0.2em;padding-left:2em;}',
$phase,
dcCore::app()->blog->getPF(basename(__dir__) . '/img/' . $image . '.png')
) . "\n";
}
exit;
}
);

View File

@ -1,22 +0,0 @@
<?php
/**
* @brief lunarPhase, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Tomtom, Pierre Van Glabeke and Contributors
*
* @copyright Jean-Crhistian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
}
require __DIR__ . '/_widgets.php';
// Add public header for lunarphase css
dcCore::app()->addBehavior('publicHeadContent', function () {
echo dcUtils::cssLoad(dcCore::app()->blog->url . dcCore::app()->url->getURLFor('lunarphase'));
});

View File

@ -1,12 +1,12 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<modules xmlns:da="http://dotaddict.org/da/"> <modules xmlns:da="http://dotaddict.org/da/">
<module id="lunarPhase"> <module id="lunarPhase">
<name>lunarPhase</name> <name>Moon phases</name>
<version>1.6</version> <version>1.7.2</version>
<author>Tomtom, Pierre Van Glabeke and Contributors</author> <author>Tomtom, Pierre Van Glabeke and Contributors</author>
<desc>Display the moon phases on a widget</desc> <desc>Display the moon phases on a widget</desc>
<file>https://github.com/JcDenis/lunarPhase/releases/download/v1.6/plugin-lunarPhase.zip</file> <file>https://github.com/JcDenis/lunarPhase/releases/download/v1.7.2/plugin-lunarPhase.zip</file>
<da:dcmin>2.24</da:dcmin> <da:dcmin>2.26</da:dcmin>
<da:details>https://plugins.dotaddict.org/dc2/details/lunarPhase</da:details> <da:details>https://plugins.dotaddict.org/dc2/details/lunarPhase</da:details>
<da:support>http://forum.dotclear.org/viewtopic.php?pid=332971#p332971</da:support> <da:support>http://forum.dotclear.org/viewtopic.php?pid=332971#p332971</da:support>
</module> </module>

View File

@ -0,0 +1,41 @@
<?php
/**
* @package Dotclear
*
* @copyright Olivier Meunier & Association Dotclear
* @copyright GPL-2.0-only
*/
#
# DOT NOT MODIFY THIS FILE !
#
use Dotclear\Helper\L10n;
L10n::$locales['Moon phases'] = 'Phases de la Lune';
L10n::$locales['Display the moon phases'] = 'Afficher les phases de la Lune et autres données';
L10n::$locales['Display actual phase of moon'] = 'Afficher la phase actuelle de la Lune';
L10n::$locales['Display actual illumination of moon'] = 'Afficher le taux d\'illumination actuel de la Lune';
L10n::$locales['Display actual age of moon'] = 'Afficher l\'âge actuel de la Lune';
L10n::$locales['Display actual distance between moon and earth'] = 'Afficher la distance actuelle entre la Terre et la Lune';
L10n::$locales['Display actual distance between moon and sun'] = 'Afficher la distance actuelle entre le Soleil et la Lune';
L10n::$locales['Display actual angle of moon'] = 'Afficher l\'angle actuel de la Lune';
L10n::$locales['Display actual angle of sun'] = 'Afficher l\'angle actuel du Soleil';
L10n::$locales['Display actual parallax of moon'] = 'Afficher la parallaxe actuelle de la Lune';
L10n::$locales['Display all previsions for the next moon phases'] = 'Afficher toutes les prévisions des prochaines lunaisons';
L10n::$locales['Illumination: %s%%'] = 'Illumination : %s%%';
L10n::$locales['Age of moon: %s days'] = 'Age de la Lune : %s jours';
L10n::$locales['Distance to earth: %s km'] = 'Distance à la Terre : %s km';
L10n::$locales['Distance to sun: %s km'] = 'Distance au Soleil : %s km';
L10n::$locales['Angle of moon: %s deg'] = 'Angle de la Lune : %s deg';
L10n::$locales['Angle of sun: %s deg'] = 'Angle du Soleil : %s deg';
L10n::$locales['Parallax: %s deg'] = 'Parallaxe : %s deg';
L10n::$locales['In live'] = 'En direct';
L10n::$locales['Previsions'] = 'Prévisions';
L10n::$locales['New moon'] = 'Nouvelle lune';
L10n::$locales['Waxing crescent moon'] = 'Lune croissante';
L10n::$locales['First quarter moon'] = 'Premier quartier';
L10n::$locales['Waxing gibbous moon'] = 'Lune gibbeuse croissante';
L10n::$locales['Full moon'] = 'Pleine lune';
L10n::$locales['Waning gibbous moon'] = 'Lune gibbeuse décroissante';
L10n::$locales['Last quarter moon'] = 'Dernier quartier';
L10n::$locales['Waning crescent moon'] = 'Lune décroissante';

View File

@ -10,15 +10,12 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n"
msgid "LunarPhase: moon phases" msgid "Moon phases"
msgstr "LunarPhase : phases de la Lune" msgstr "Phases de la Lune"
msgid "Display the moon phases" msgid "Display the moon phases"
msgstr "Afficher les phases de la Lune et autres données" msgstr "Afficher les phases de la Lune et autres données"
msgid "Moon phases"
msgstr "Phases de la Lune"
msgid "Display actual phase of moon" msgid "Display actual phase of moon"
msgstr "Afficher la phase actuelle de la Lune" msgstr "Afficher la phase actuelle de la Lune"

45
src/Backend.php 100644
View File

@ -0,0 +1,45 @@
<?php
/**
* @brief lunarPhase, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Tomtom, Pierre Van Glabeke and Contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
namespace Dotclear\Plugin\lunarPhase;
use dcCore;
use dcNsProcess;
use Dotclear\Helper\Html\Form\{
Checkbox,
Input,
Label,
Para
};
class Backend extends dcNsProcess
{
public static function init(): bool
{
static::$init = defined('DC_CONTEXT_ADMIN');
return static::$init;
}
public static function process(): bool
{
if (!static::$init) {
return false;
}
dcCore::app()->addBehavior('initWidgets', [Widgets::class, 'initWidgets']);
return true;
}
}

51
src/Frontend.php 100644
View File

@ -0,0 +1,51 @@
<?php
/**
* @brief lunarPhase, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Tomtom, Pierre Van Glabeke and Contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
namespace Dotclear\Plugin\lunarPhase;
use dcCore;
use dcNsProcess;
use dcUtils;
class Frontend extends dcNsProcess
{
public static function init(): bool
{
static::$init = defined('DC_RC_PATH');
return static::$init;
}
public static function process(): bool
{
if (!static::$init) {
return false;
}
dcCore::app()->addBehaviors([
// Add public header for lunarphase css
'publicHeadContent' => function (): void {
if (is_null(dcCore::app()->blog)) {
return;
}
echo dcUtils::cssLoad(dcCore::app()->blog->url . dcCore::app()->url->getURLFor('lunarphase'));
},
// Widgets
'initWidgets' => [Widgets::class, 'initWidgets'],
]);
return true;
}
}

View File

@ -7,14 +7,16 @@
* *
* @author Tomtom, Pierre Van Glabeke and Contributors * @author Tomtom, Pierre Van Glabeke and Contributors
* *
* @copyright Jean-Crhistian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { declare(strict_types=1);
return null;
}
class lunarPhase namespace Dotclear\Plugin\lunarPhase;
use ArrayObject;
class LunarPhase
{ {
# Astronomical constants. # Astronomical constants.
public const epoch = 2444238.5; # 1980 January 0.0 public const epoch = 2444238.5; # 1980 January 0.0
@ -37,8 +39,8 @@ class lunarPhase
public const mParallax = 0.9507; # parallax at distance a from Earth public const mParallax = 0.9507; # parallax at distance a from Earth
public const synodic = 29.53058868; # synodic month (new Moon to new Moon) public const synodic = 29.53058868; # synodic month (new Moon to new Moon)
protected $live; protected ArrayObject $live;
protected $previsions; protected ArrayObject $previsions;
public function __construct() public function __construct()
{ {
@ -49,17 +51,17 @@ class lunarPhase
$this->setPrevisions(); $this->setPrevisions();
} }
public function getLive() public function getLive(): ArrayObject
{ {
return $this->live; return $this->live;
} }
public function getPrevisions() public function getPrevisions(): ArrayObject
{ {
return $this->previsions; return $this->previsions;
} }
private function setLive() private function setLive(): void
{ {
$day = $this->jTime(time()) - self::epoch; $day = $this->jTime(time()) - self::epoch;
@ -104,7 +106,7 @@ class lunarPhase
$this->setPhase(); $this->setPhase();
} }
private function setPhase() private function setPhase(): void
{ {
if ($this->live['age'] >= self::synodic || $this->live['age'] <= self::synodic / 8) { if ($this->live['age'] >= self::synodic || $this->live['age'] <= self::synodic / 8) {
$this->live['id'] = 'new_moon'; $this->live['id'] = 'new_moon';
@ -133,7 +135,7 @@ class lunarPhase
} }
} }
private function setPrevisions() private function setPrevisions(): void
{ {
$ts_day = 24 * 60 * 60; $ts_day = 24 * 60 * 60;
$ts_synodic = self::synodic * $ts_day; $ts_synodic = self::synodic * $ts_day;
@ -173,27 +175,27 @@ class lunarPhase
]; ];
} }
private function fixAngle($x) private function fixAngle(float $x): float
{ {
return ($x - 360.0 * (floor($x / 360.0))); return ($x - 360.0 * (floor($x / 360.0)));
} }
private function toRad($x) private function toRad(float $x): float
{ {
return ($x * (M_PI / 180.0)); return ($x * (M_PI / 180.0));
} }
private function toDeg($x) private function toDeg(float $x): float
{ {
return ($x * (180.0 / M_PI)); return ($x * (180.0 / M_PI));
} }
private function jTime($t) private function jTime(float $t): float
{ {
return ($t / 86400) + 2440587.5; return ($t / 86400) + 2440587.5;
} }
private function kepler($m, $ecc) private function kepler(float $m, float $ecc): float
{ {
$delta = null; $delta = null;
$EPSILON = 1e-6; $EPSILON = 1e-6;

61
src/My.php 100644
View File

@ -0,0 +1,61 @@
<?php
/**
* @brief lunarPhase, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Tomtom, Pierre Van Glabeke and Contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
namespace Dotclear\Plugin\lunarPhase;
use dcCore;
/**
* This module definitions.
*/
class My
{
/** @var array<string,string> List of lunar phase => image */
public const LUNAR_PHASES = [
'new_moon' => 'nm.png',
'waxing_crescent_moon' => 'wcm1.png',
'first_quarter_moon' => 'fqm.png',
'waxing_gibbous_moon' => 'wgm1.png',
'full_moon' => 'fm.png',
'waning_gibbous_moon' => 'wgm2.png',
'last_quarter_moon' => 'tqm.png',
'waning_crescent_moon' => 'wcm2.png',
];
/**
* This module id.
*/
public static function id(): string
{
return basename(dirname(__DIR__));
}
/**
* This module name.
*/
public static function name(): string
{
$name = dcCore::app()->plugins->moduleInfo(self::id(), 'name');
return __(is_string($name) ? $name : self::id());
}
/**
* This module path.
*/
public static function path(): string
{
return dirname(__DIR__);
}
}

63
src/Prepend.php 100644
View File

@ -0,0 +1,63 @@
<?php
/**
* @brief lunarPhase, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Tomtom, Pierre Van Glabeke and Contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
namespace Dotclear\Plugin\lunarPhase;
use dcCore;
use dcNsProcess;
class Prepend extends dcNsProcess
{
public static function init(): bool
{
static::$init = defined('DC_RC_PATH');
return static::$init;
}
public static function process(): bool
{
if (!static::$init) {
return false;
}
// Register lunarphase CSS URL
dcCore::app()->url->register(
'lunarphase',
'lunarphase.css',
'^lunarphase\.css',
function (?string $args): void {
// avoid null warning
if (is_null(dcCore::app()->blog)) {
return;
}
header('Content-Type: text/css; charset=UTF-8');
echo "/* lunarphase widget style */\n";
foreach (My::LUNAR_PHASES as $phase => $image) {
echo sprintf(
"#sidebar .lunarphase ul li.%s{background:transparent url(%s) no-repeat left 0.2em;padding-left:2em;}\n",
$phase,
dcCore::app()->blog->getPF(My::id() . '/img/' . $image)
);
}
exit;
}
);
return true;
}
}

View File

@ -7,23 +7,27 @@
* *
* @author Tomtom, Pierre Van Glabeke and Contributors * @author Tomtom, Pierre Van Glabeke and Contributors
* *
* @copyright Jean-Crhistian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { declare(strict_types=1);
return null;
}
dcCore::app()->addBehavior('initWidgets', ['lunarPhaseWidgets','initWidgets']); namespace Dotclear\Plugin\lunarPhase;
class lunarPhaseWidgets use dcCore;
use Dotclear\Helper\Date;
use Dotclear\Helper\Html\Html;
use Dotclear\Plugin\widgets\WidgetsStack;
use Dotclear\Plugin\widgets\WidgetsElement;
class Widgets
{ {
public static function initWidgets($w) public static function initWidgets(WidgetsStack $w): void
{ {
$w->create( $w->create(
'lunarphase', 'lunarphase',
__('LunarPhase: moon phases'), __('Moon phases'),
['lunarPhaseWidgets','widget'], [self::class, 'parseWidget'],
null, null,
__('Display the moon phases') __('Display the moon phases')
) )
@ -43,36 +47,33 @@ class lunarPhaseWidgets
->addOffline(); ->addOffline();
} }
public static function widget($w) public static function parseWidget(WidgetsElement $w): string
{ {
if ($w->offline) { if ($w->offline || !$w->checkHomeOnly(dcCore::app()->url->type)) {
return; return '';
} }
if (!$w->checkHomeOnly(dcCore::app()->url->type)) { $lp = new LunarPhase();
return;
}
$lp = new lunarPhase();
return $w->renderDiv( return $w->renderDiv(
$w->content_only, (bool) $w->content_only,
'lunarphase ' . $w->class, 'lunarphase ' . $w->class,
'', '',
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') . ($w->title ? $w->renderTitle(Html::escapeHTML($w->title)) : '') .
self::getLive($w, $lp) . self::getLive($w, $lp) .
self::getPrevisions($w, $lp) self::getPrevisions($w, $lp)
); );
} }
/** /**
* Returns "live" part of lunarphase widget * Returns "live" part of lunarphase widget.
* *
* @param dcWidget $w dcWidget object * @param WidgetsElement $w Widget instance
* @param lunarPhase $lp lunarPhase object * @param LunarPhase $lp LunarPhase instance
* @return string Live HTML part *
* @return string Live HTML part
*/ */
public static function getLive($w, $lp) public static function getLive(WidgetsElement $w, LunarPhase $lp): string
{ {
$li = '<li class="%2$s">%1$s</li>'; $li = '<li class="%2$s">%1$s</li>';
$live = $lp->getLive(); $live = $lp->getLive();
@ -166,13 +167,14 @@ class lunarPhaseWidgets
} }
/** /**
* Returns "previsions" part of lunarphase widget * Returns "previsions" part of lunarphase widget.
* *
* @param dcWidget $w dcWidget object * @param WidgetsElement $w Widget instance
* @param lunarPhase $lp lunarPhase object * @param LunarPhase $lp LunarPhase instance
* @return string Previsions HTML part *
* @return string Previsions HTML part
*/ */
public static function getPrevisions($w, $lp) public static function getPrevisions(WidgetsElement $w, LunarPhase $lp): string
{ {
$li = '<li class="%s" title="%s">%s</li>'; $li = '<li class="%s" title="%s">%s</li>';
$res = ''; $res = '';
@ -189,24 +191,29 @@ class lunarPhaseWidgets
} }
/** /**
* Returns value passed in argument with a correct format * Returns value passed in argument with a correct format.
* *
* @param string $type Type of convertion * @param string $type Type of convertion
* @param mixed $value Value to convert * @param mixed $value Value to convert
* @return mixed Converted value *
* @return mixed Converted value
*/ */
public static function formatValue($type, $value) public static function formatValue(string $type, mixed $value): mixed
{ {
if (is_null(dcCore::app()->blog)) {
return null;
}
$res = ''; $res = '';
$format = dcCore::app()->blog->settings->system->date_format . ' - '; $format = dcCore::app()->blog->settings->get('system')->get('date_format') . ' - ';
$format .= dcCore::app()->blog->settings->system->time_format; $format .= dcCore::app()->blog->settings->get('system')->get('time_format');
$tz = dcCore::app()->blog->settings->system->blog_timezone; $tz = dcCore::app()->blog->settings->get('system')->get('blog_timezone');
return match ($type) { return match ($type) {
'int' => number_format($value, 0), 'int' => number_format($value, 0),
'float' => number_format($value, 2), 'float' => number_format($value, 2),
'percent' => number_format($value * 100, 0), 'percent' => number_format($value * 100, 0),
'date' => dt::str($format, $value, $tz), 'date' => Date::str($format, (int) $value, $tz),
'deg' => number_format(($value * (180.0 / M_PI)), 2), 'deg' => number_format(($value * (180.0 / M_PI)), 2),
default => $value, default => $value,
}; };

View File

@ -1,8 +0,0 @@
#sidebar .lunarphase ul li.new_moon{background:transparent url(index.php?pf=lunarPhase/img/nm.png) no-repeat left 0.2em;padding-left:2em;}
#sidebar .lunarphase ul li.waxing_crescent_moon{background:transparent url(index.php?pf=lunarPhase/img/wcm1.png) no-repeat left 0.2em;padding-left:2em;}
#sidebar .lunarphase ul li.first_quarter_moon{background:transparent url(index.php?pf=lunarPhase/img/fqm.png) no-repeat left 0.2em;padding-left:2em;}
#sidebar .lunarphase ul li.waxing_gibbous_moon{background:transparent url(index.php?pf=lunarPhase/img/wgm1.png) no-repeat left 0.2em;padding-left:2em;}
#sidebar .lunarphase ul li.full_moon{background:transparent url(index.php?pf=lunarPhase/img/fm.png) no-repeat left 0.2em;padding-left:2em;}
#sidebar .lunarphase ul li.waning_gibbous_moon{background:transparent url(index.php?pf=lunarPhase/img/wgm2.png) no-repeat left 0.2em;padding-left:2em;}
#sidebar .lunarphase ul li.last_quarter_moon{background:transparent url(index.php?pf=lunarPhase/img/tqm.png) no-repeat left 0.2em;padding-left:2em;}
#sidebar .lunarphase ul li.waning_crescent_moon{background:transparent url(index.php?pf=lunarPhase/img/wcm2.png) no-repeat left 0.2em;padding-left:2em;}