use namespace
This commit is contained in:
parent
a41fcf19f6
commit
121b6d8c85
@ -10,15 +10,12 @@ msgstr ""
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
|
||||
|
||||
msgid "LunarPhase: moon phases"
|
||||
msgstr "LunarPhase : phases de la Lune"
|
||||
msgid "Moon phases"
|
||||
msgstr "Phases de la Lune"
|
||||
|
||||
msgid "Display the moon phases"
|
||||
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"
|
||||
msgstr "Afficher la phase actuelle de la Lune"
|
||||
|
||||
|
@ -7,11 +7,39 @@
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
return null;
|
||||
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') && My::phpCompliant();
|
||||
|
||||
return static::$init;
|
||||
}
|
||||
|
||||
require __DIR__ . '/_widgets.php';
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init) {
|
||||
return false;
|
||||
}
|
||||
|
||||
dcCore::app()->addBehavior('initWidgets', [Widgets::class, 'initWidgets']);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -7,16 +7,45 @@
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
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 = My::phpCompliant();
|
||||
|
||||
return static::$init;
|
||||
}
|
||||
|
||||
require __DIR__ . '/_widgets.php';
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init) {
|
||||
return false;
|
||||
}
|
||||
|
||||
dcCore::app()->addBehaviors([
|
||||
// Add public header for lunarphase css
|
||||
dcCore::app()->addBehavior('publicHeadContent', function () {
|
||||
'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;
|
||||
}
|
||||
}
|
||||
|
@ -7,14 +7,16 @@
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
declare(strict_types=1);
|
||||
|
||||
class lunarPhase
|
||||
namespace Dotclear\Plugin\lunarPhase;
|
||||
|
||||
use ArrayObject;
|
||||
|
||||
class LunarPhase
|
||||
{
|
||||
# Astronomical constants.
|
||||
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 synodic = 29.53058868; # synodic month (new Moon to new Moon)
|
||||
|
||||
protected $live;
|
||||
protected $previsions;
|
||||
protected ArrayObject $live;
|
||||
protected ArrayObject $previsions;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@ -49,17 +51,17 @@ class lunarPhase
|
||||
$this->setPrevisions();
|
||||
}
|
||||
|
||||
public function getLive()
|
||||
public function getLive(): ArrayObject
|
||||
{
|
||||
return $this->live;
|
||||
}
|
||||
|
||||
public function getPrevisions()
|
||||
public function getPrevisions(): ArrayObject
|
||||
{
|
||||
return $this->previsions;
|
||||
}
|
||||
|
||||
private function setLive()
|
||||
private function setLive(): void
|
||||
{
|
||||
$day = $this->jTime(time()) - self::epoch;
|
||||
|
||||
@ -104,7 +106,7 @@ class lunarPhase
|
||||
$this->setPhase();
|
||||
}
|
||||
|
||||
private function setPhase()
|
||||
private function setPhase(): void
|
||||
{
|
||||
if ($this->live['age'] >= self::synodic || $this->live['age'] <= self::synodic / 8) {
|
||||
$this->live['id'] = 'new_moon';
|
||||
@ -133,7 +135,7 @@ class lunarPhase
|
||||
}
|
||||
}
|
||||
|
||||
private function setPrevisions()
|
||||
private function setPrevisions(): void
|
||||
{
|
||||
$ts_day = 24 * 60 * 60;
|
||||
$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)));
|
||||
}
|
||||
|
||||
private function toRad($x)
|
||||
private function toRad(float $x): float
|
||||
{
|
||||
return ($x * (M_PI / 180.0));
|
||||
}
|
||||
|
||||
private function toDeg($x)
|
||||
private function toDeg(float $x): float
|
||||
{
|
||||
return ($x * (180.0 / M_PI));
|
||||
}
|
||||
|
||||
private function jTime($t)
|
||||
private function jTime(float $t): float
|
||||
{
|
||||
return ($t / 86400) + 2440587.5;
|
||||
}
|
||||
|
||||
private function kepler($m, $ecc)
|
||||
private function kepler(float $m, float $ecc): float
|
||||
{
|
||||
$delta = null;
|
||||
$EPSILON = 1e-6;
|
||||
|
62
src/My.php
Normal file
62
src/My.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Plugin definitions
|
||||
*/
|
||||
class My
|
||||
{
|
||||
/** @var string Required php version */
|
||||
public const PHP_MIN = '7.4';
|
||||
|
||||
/** @var array 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
|
||||
{
|
||||
return __((string) dcCore::app()->plugins->moduleInfo(self::id(), 'name'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check php version
|
||||
*/
|
||||
public static function phpCompliant(): bool
|
||||
{
|
||||
return version_compare(phpversion(), self::PHP_MIN, '>=');
|
||||
}
|
||||
}
|
@ -7,44 +7,57 @@
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\lunarPhase;
|
||||
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
|
||||
class Prepend extends dcNsProcess
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = My::phpCompliant();
|
||||
|
||||
return static::$init;
|
||||
}
|
||||
|
||||
Clearbricks::lib()->autoload(['lunarPhase' => __DIR__ . '/inc/class.lunarphase.php']);
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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',
|
||||
];
|
||||
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 ($phases as $phase => $image) {
|
||||
echo
|
||||
sprintf(
|
||||
'#sidebar .lunarphase ul li.%s{background:transparent url(%s) no-repeat left 0.2em;padding-left:2em;}',
|
||||
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(basename(__dir__) . '/img/' . $image . '.png')
|
||||
) . "\n";
|
||||
dcCore::app()->blog->getPF(My::id() . '/img/' . $image)
|
||||
);
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -7,23 +7,27 @@
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
declare(strict_types=1);
|
||||
|
||||
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(
|
||||
'lunarphase',
|
||||
__('LunarPhase: moon phases'),
|
||||
['lunarPhaseWidgets','widget'],
|
||||
__('Moon phases'),
|
||||
[self::class, 'parseWidget'],
|
||||
null,
|
||||
__('Display the moon phases')
|
||||
)
|
||||
@ -43,36 +47,33 @@ class lunarPhaseWidgets
|
||||
->addOffline();
|
||||
}
|
||||
|
||||
public static function widget($w)
|
||||
public static function parseWidget(WidgetsElement $w): string
|
||||
{
|
||||
if ($w->offline) {
|
||||
return;
|
||||
if ($w->offline || !$w->checkHomeOnly(dcCore::app()->url->type)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (!$w->checkHomeOnly(dcCore::app()->url->type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$lp = new lunarPhase();
|
||||
$lp = new LunarPhase();
|
||||
|
||||
return $w->renderDiv(
|
||||
$w->content_only,
|
||||
(bool) $w->content_only,
|
||||
'lunarphase ' . $w->class,
|
||||
'',
|
||||
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
|
||||
($w->title ? $w->renderTitle(Html::escapeHTML($w->title)) : '') .
|
||||
self::getLive($w, $lp) .
|
||||
self::getPrevisions($w, $lp)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns "live" part of lunarphase widget
|
||||
* Returns "live" part of lunarphase widget.
|
||||
*
|
||||
* @param WidgetsElement $w Widget instance
|
||||
* @param LunarPhase $lp LunarPhase instance
|
||||
*
|
||||
* @param dcWidget $w dcWidget object
|
||||
* @param lunarPhase $lp lunarPhase object
|
||||
* @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>';
|
||||
$live = $lp->getLive();
|
||||
@ -166,13 +167,14 @@ class lunarPhaseWidgets
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns "previsions" part of lunarphase widget
|
||||
* Returns "previsions" part of lunarphase widget.
|
||||
*
|
||||
* @param WidgetsElement $w Widget instance
|
||||
* @param LunarPhase $lp LunarPhase instance
|
||||
*
|
||||
* @param dcWidget $w dcWidget object
|
||||
* @param lunarPhase $lp lunarPhase object
|
||||
* @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>';
|
||||
$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 mixed $value Value to convert
|
||||
*
|
||||
* @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 = '';
|
||||
$format = dcCore::app()->blog->settings->system->date_format . ' - ';
|
||||
$format .= dcCore::app()->blog->settings->system->time_format;
|
||||
$tz = dcCore::app()->blog->settings->system->blog_timezone;
|
||||
$format = dcCore::app()->blog->settings->get('system')->get('date_format') . ' - ';
|
||||
$format .= dcCore::app()->blog->settings->get('system')->get('time_format');
|
||||
$tz = dcCore::app()->blog->settings->get('system')->get('blog_timezone');
|
||||
|
||||
return match ($type) {
|
||||
'int' => number_format($value, 0),
|
||||
'float' => number_format($value, 2),
|
||||
'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),
|
||||
default => $value,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user