[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 3 $block_name = _("Moon Phases"); 4 5 /** 6 * $Horde: horde/lib/Block/moon.php,v 1.16.10.4 2005/10/18 11:33:39 jan Exp $ 7 * 8 * @package Horde_Block 9 */ 10 class Horde_Block_Horde_moon extends Horde_Block { 11 12 var $_app = 'horde'; 13 14 function _title() 15 { 16 return _("Moon Phases"); 17 } 18 19 function _params() 20 { 21 return array( 22 'phase' => array( 23 'name' => _("Which phases"), 24 'type' => 'enum', 25 'default' => 'current', 26 'values' => array('current' => _("Current 4 Phases"), 27 'next' => _("Next 4 Phases"))), 28 'hemisphere' => array( 29 'name' => _("Hemisphere"), 30 'type' => 'enum', 31 'default' => 'northern', 32 'values' => array('northern' => _("Northern Hemisphere"), 33 'southern' => _("Southern Hemisphere"))), 34 ); 35 } 36 37 function _content() 38 { 39 $phases = $this->_calculateMoonPhases(date('Y')); 40 $now = time(); 41 42 $lastNew = 0; 43 $lastNewStamp = 0; 44 $offset = 0; 45 foreach ($phases as $key => $val) { 46 if ($key < $now && $key > $lastNewStamp && $val == _("New Moon")) { 47 $lastNew = $offset; 48 $lastNewStamp = $key; 49 } 50 $offset++; 51 } 52 53 if (isset($this->_params['phase']) && $this->_params['phase'] == 'next') { 54 $dates = array_slice(array_keys($phases), $lastNew + 4, 4); 55 } else { 56 $dates = array_slice(array_keys($phases), $lastNew, 4); 57 } 58 59 if (isset($this->_params['hemisphere']) && $this->_params['hemisphere'] == 'northern') { 60 $location = _("Northern Hemisphere"); 61 } else { 62 $location = _("Southern Hemisphere"); 63 } 64 65 $html = '<table width="100%" height="100%" cellspacing="0">' . 66 '<tr><td colspan="4" class="control"><strong>' . $location . '</strong></td></tr>' . 67 '<tr height="100%"><td width="25%" align="center">' . 68 Horde::img('block/moon/newmoon.png', _("New Moon")) . 69 '<br />' . strftime('%d %b', $dates[0]) . 70 '</td>'; 71 72 $html .= '<td width="25%" align="center">'; 73 if (isset($this->_params['hemisphere']) && $this->_params['hemisphere'] == 'northern') { 74 $html .= Horde::img('block/moon/lastquarter.png', _("First Quarter")); 75 } else { 76 $html .= Horde::img('block/moon/firstquarter.png', _("First Quarter")); 77 } 78 $html .= '<br />' . strftime('%d %b', $dates[1]) . '</td>'; 79 80 $html .= '<td width="25%" align="center">' . 81 Horde::img('block/moon/fullmoon.png', _("Full Moon")) . 82 '<br />' . strftime('%d %b', $dates[2]) . '</td>'; 83 84 $html .= '<td width="25%" align="center">'; 85 if (isset($this->_params['hemisphere']) && $this->_params['hemisphere'] == 'northern') { 86 $html .= Horde::img('block/moon/firstquarter.png', _("Last Quarter")); 87 } else { 88 $html .= Horde::img('block/moon/lastquarter.png', _("Last Quarter")); 89 } 90 $html .= '<br />' . strftime('%d %b', $dates[3]) . '</td></tr></table>'; 91 92 return $html; 93 } 94 95 /** 96 * Returns an array with all the phases of the moon for a whole 97 * year. 98 * 99 * Based on code from 100 * http://www.zend.com/codex.php?id=830&single=1 by Are Pedersen. 101 * 102 * Converted from Basic by Roger W. Sinnot, Sky & Telescope, March 1985. 103 * Converted from javascript by Are Pedersen 2002 104 * Javascript found at http://www.stellafane.com/moon_phase/moon_phase.htm 105 * 106 * @param integer $year The four digit year to return the moon 107 * phases for. 108 * 109 * @return array The moon phases. 110 */ 111 function _calculateMoonPhases($Y) 112 { 113 $R1 = 3.14159265 / 180; 114 $U = false; 115 $K0 = intval(($Y - 1900) * 12.3685); 116 $T = ($Y - 1899.5) / 100; 117 $T2 = $T * $T; 118 $T3 = $T * $T * $T; 119 $J0 = 2415020 + 29 * $K0; 120 $F0 = 0.0001178 * $T2 - 0.000000155 * $T3; 121 $F0 += (0.75933 + 0.53058868*$K0); 122 $F0 -= (0.000837 * $T + 0.000335 * $T2); 123 $M0 = $K0 * 0.08084821133; 124 $M0 = 360 * ($M0 - intval($M0)) + 359.2242; 125 $M0 -= 0.0000333 * $T2; 126 $M0 -= 0.00000347 * $T3; 127 $M1 = $K0 * 0.07171366128; 128 $M1 = 360 * ($M1 - intval($M1)) + 306.0253; 129 $M1 += 0.0107306 * $T2; 130 $M1 += 0.00001236 * $T3; 131 $B1 = $K0 * 0.08519585128; 132 $B1 = 360 * ($B1 - intval($B1)) + 21.2964; 133 $B1 -= 0.0016528 * $T2; 134 $B1 -= 0.00000239 * $T3; 135 for ($K9 = 0; $K9 <= 28; $K9 = $K9 + 0.5) { 136 $J = $J0 + 14 * $K9; 137 $F = $F0 + 0.765294 * $K9; 138 $K = $K9 / 2; 139 $M5 = ($M0 + $K * 29.10535608) * $R1; 140 $M6 = ($M1 + $K * 385.81691806) * $R1; 141 $B6 = ($B1 + $K * 390.67050646) * $R1; 142 $F -= 0.4068 * sin($M6); 143 $F += (0.1734 - 0.000393 * $T) * sin($M5); 144 $F += 0.0161 * sin(2 * $M6); 145 $F += 0.0104 * sin(2 * $B6); 146 $F -= 0.0074 * sin($M5 - $M6); 147 $F -= 0.0051 * sin($M5 + $M6); 148 $F += 0.0021 * sin(2 * $M5); 149 $F += 0.0010 * sin(2 * $B6 - $M6); 150 151 /* Add 1/2 minute for proper rounding to minutes per Sky & 152 * Tel article. */ 153 $F += 0.5 / 1440; 154 $J += intval($F); 155 $F -= intval($F); 156 157 /* Convert from JD to Calendar Date. */ 158 $julian = $J + round($F); 159 $parts = explode('/', $this->_jdtogregorian($julian)); 160 $stamp = gmmktime(0, 0, 0, $parts[0], $parts[1], $parts[2]); 161 162 /* half K. */ 163 if (($K9 - floor($K9)) > 0) { 164 if ($U) { 165 /* New half. */ 166 $phases[$stamp] = _("First Half"); 167 } else { 168 /* Full half. */ 169 $phases[$stamp] = _("Last Half"); 170 } 171 } else { 172 /* full K. */ 173 if (!$U) { 174 $phases[$stamp] = _("New Moon"); 175 } else { 176 $phases[$stamp] = _("Full Moon"); 177 } 178 $U = !$U; 179 } 180 } 181 182 return $phases; 183 } 184 185 /** 186 * Checks if the jdtogregorian function exists, and if not 187 * calculates the gregorian date manually. 188 * 189 * @param int $julian The julian date 190 * 191 * @return string m/d/Y 192 */ 193 function _jdtogregorian($julian) 194 { 195 if (function_exists('jdtogregorian')) { 196 return jdtogregorian($julian); 197 } else { 198 // From http://php.net/manual/en/function.jdtogregorian.php 199 $julian = $julian - 1721119; 200 $calc1 = 4 * $julian - 1; 201 $year = floor($calc1 / 146097); 202 $julian = floor($calc1 - 146097 * $year); 203 $day = floor($julian / 4); 204 $calc2 = 4 * $day + 3; 205 $julian = floor($calc2 / 1461); 206 $day = $calc2 - 1461 * $julian; 207 $day = floor(($day + 4) / 4); 208 $calc3 = 5 * $day - 3; 209 $month = floor($calc3 / 153); 210 $day = $calc3 - 153 * $month; 211 $day = floor(($day + 5) / 5); 212 $year = 100 * $year + $julian; 213 214 if ($month < 10) { 215 $month = $month + 3; 216 } else { 217 $month = $month - 9; 218 $year = $year + 1; 219 } 220 return "$month/$day/$year"; 221 } 222 } 223 224 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |