This repository was archived by the owner on Dec 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_public.php
More file actions
203 lines (178 loc) · 4.9 KB
/
_public.php
File metadata and controls
203 lines (178 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
# This file is part of lunarPhase, a plugin for Dotclear.
#
# Copyright (c) 2009-2015 Tomtom
# Contributor: Pierre Van Glabeke
#
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { return; }
$core->addBehavior('publicHeadContent',array('lunarPhaseBehaviors','addCss'));
class lunarPhaseBehaviors
{
/**
This function add CSS file in the public header
*/
public static function addCss()
{
global $core;
$url = $core->blog->getQMarkURL().'pf='.basename(dirname(__FILE__)).'/style.css';
echo '<link rel="stylesheet" media="screen" type="text/css" href="'.$url.'" />';
}
}
class lunarPhasePublic
{
/**
Displays lunarphase widget
@param w <b>dcWidget</b> dcWidget object
@return <b>string</b> HTML code of widget
*/
public static function widget($w)
{
global $core;
if ($w->offline)
return;
$lp = new lunarPhase();
if (($w->homeonly == 1 && $core->url->type != 'default') ||
($w->homeonly == 2 && $core->url->type == 'default')) {
return;
}
$res =
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '');
# Get live content
$res .= lunarPhasePublic::getLive($w,$lp);
# Get prevision content
$res .= lunarPhasePublic::getPrevisions($w,$lp);
return $w->renderDiv($w->content_only,'lunarphase '.$w->class,'',$res);
}
/**
Returns "live" part of lunarphase widget
@param w <b>dcWidget</b> dcWidget object
@param lp <b>lunarPhaset</b> lunarPhase object
@return <b>string</b> Live HTML part
*/
public static function getLive($w,$lp)
{
$ul_mask = '<ul>%1$s</ul>';
$li_mask = '<li class="%2$s">%1$s</li>';
$live = $lp->getLive();
$res = '';
# Phase
if ($w->phase) {
$res .= sprintf($li_mask,$live['name'],$live['id']);
}
# Illumination
if ($w->illumination) {
$res .=
sprintf($li_mask,sprintf(__('Illumination: %s%%'),
lunarPhasePublic::formatValue('percent',$live['illumination'])),
'illumination');
}
# Moon's age
if ($w->age) {
$res .=
sprintf($li_mask,sprintf(__('Age of moon: %s days'),
lunarPhasePublic::formatValue('int',$live['age'])),
'age');
}
# Distance from earth
if ($w->dist_to_earth) {
$res .=
sprintf($li_mask,sprintf(__('Distance to earth: %s km'),
lunarPhasePublic::formatValue('int',$live['dist_to_earth'])),
'dist_to_earth');
}
# Distance from sun
if ($w->dist_to_sun) {
$res .=
sprintf($li_mask,sprintf(__('Distance to sun: %s km'),
lunarPhasePublic::formatValue('int',$live['dist_to_sun'])),
'dist_to_sun');
}
# Moon's angle
if ($w->moon_angle) {
$res .=
sprintf($li_mask,sprintf(__('Angle of moon: %s deg'),
lunarPhasePublic::formatValue('deg',$live['moon_angle'])),
'moon_angle');
}
# Sun's angle
if ($w->sun_angle) {
$res .=
sprintf($li_mask,sprintf(__('Angle of sun: %s deg'),
lunarPhasePublic::formatValue('deg',$live['sun_angle'])),
'sun_angle');
}
# Parallax
if ($w->parallax) {
$res .=
sprintf($li_mask,sprintf(__('Parallax: %s deg'),
lunarPhasePublic::formatValue('deg',$live['parallax'])),
'parallax');
}
if (strlen($res) > 0) {
return
'<h3>'.__('In live').'</h3>'.
sprintf($ul_mask,$res,'lunarphase');
}
}
/**
Returns "previsions" part of lunarphase widget
@param w <b>dcWidget</b> dcWidget object
@param lp <b>lunarPhaset</b> lunarPhase object
@return <b>string</b> previsions HTML part
*/
public static function getPrevisions($w,$lp)
{
$ul_mask = '<ul class="%2$s">%1$s</ul>';
$li_mask = '<li class="%2$s" title="%3$s">%1$s</li>';
$res = '';
if ($w->previsions) {
foreach ($lp->getPrevisions() as $k => $v) {
$res .= sprintf($li_mask,lunarPhasePublic::formatValue('date',$v['date']),$k,$v['name']);
}
}
if (strlen($res) > 0) {
return
'<h3>'.__('Previsions').'</h3>'.
sprintf($ul_mask,$res,'lunarphase');
}
}
/**
Returns value passed in argument with a correct format
@param type <b>string</b> Type of convertion
@param value <b>mixed</b> Value to convert
@return <b>mixed</b> Converted value
*/
public static function formatValue($type = '',$value)
{
$res = '';
$format = $GLOBALS['core']->blog->settings->system->date_format.' - ';
$format .= $GLOBALS['core']->blog->settings->system->time_format;
$tz = $GLOBALS['core']->blog->settings->system->blog_timezone;
switch ($type) {
case 'int':
$res = number_format($value,0);
break;
case 'float':
$res = number_format($value,2);
break;
case 'percent':
$res = number_format($value * 100,0);
break;
case 'date':
$res = dt::str($format,$value,$tz);
break;
case 'deg':
$res = number_format(($value * (180.0 / M_PI)),2);
break;
default:
$res = $value;
break;
}
return $res;
}
}