diff --git a/astro_functions.php b/astro_functions.php index df7c6d9..4702ade 100644 --- a/astro_functions.php +++ b/astro_functions.php @@ -120,5 +120,12 @@ function sortPlanetsByLongitude(array $planets): array function getSegmentFromLongitude(float $longitude): int { $longitude = normalizeLongitude($longitude); + + // Each zodiac sign = 30° + // 0-30 → 1 + // 30-60 → 2 + // ... + // 330-360 → 12 + return ((int) floor($longitude / 30)) + 1; } \ No newline at end of file diff --git a/ephemeris_engine.php b/ephemeris_engine.php new file mode 100644 index 0000000..f80cb70 --- /dev/null +++ b/ephemeris_engine.php @@ -0,0 +1,128 @@ + false, + 'error' => $curlErr ?: ('Remote API returned HTTP ' . $httpCode), + 'data' => [] + ]; + } + } else { + $context = stream_context_create([ + 'http' => [ + 'timeout' => SWISSEPH_API_TIMEOUT + ] + ]); + + $response = @file_get_contents($url, false, $context); + + if ($response === false) { + return [ + 'success' => false, + 'error' => 'Could not connect to remote Swiss Ephemeris API.', + 'data' => [] + ]; + } + } + + $decoded = json_decode($response, true); + + if (!is_array($decoded)) { + return [ + 'success' => false, + 'error' => 'Invalid JSON received from remote API.', + 'data' => [] + ]; + } + + return [ + 'success' => true, + 'error' => '', + 'data' => $decoded + ]; +} + +function getRealPlanetaryData( + string $date, + string $time, + float $latitude, + float $longitude, + string $timezone = 'Asia/Kathmandu' +): array { + $remote = fetchRemoteSwissephResponse($date, $time, $latitude, $longitude, $timezone); + + if (!$remote['success']) { + return [ + 'planets' => [], + 'ascendant' => null, + 'error' => $remote['error'] + ]; + } + + $data = $remote['data']; + $results = []; + + if (isset($data['planets']) && is_array($data['planets'])) { + foreach ($data['planets'] as $planet) { + if (!is_array($planet) || !isset($planet['key']) || !isset($planet['longitude'])) { + continue; + } + + if (!in_array($planet['key'], PLANET_KEYS, true)) { + continue; + } + + $results[] = [ + 'key' => $planet['key'], + 'longitude' => normalizeLongitude((float)$planet['longitude']) + ]; + } + } + + return [ + 'planets' => $results, + 'ascendant' => isset($data['ascendant']) ? (float)$data['ascendant'] : null, + 'error' => '' + ]; +} \ No newline at end of file diff --git a/index.php b/index.php index 16a1147..109826d 100644 --- a/index.php +++ b/index.php @@ -1,9 +1,9 @@ -
@@ -113,7 +122,6 @@ $positionsInOrder = sortPlanetsByLongitude($samplePlanets); -Ascendant Longitude: = htmlspecialchars((string)round($ascendantLongitude, 6)) ?>
+Ascendant Sign: = htmlspecialchars($ascendantData['sign']) ?>
+Ascendant Degree: = htmlspecialchars($ascendantData['degree']) ?>
+Ascendant Nakshatra: = htmlspecialchars($ascendantData['nakshatra']) ?>
+| Planet | @@ -216,21 +236,22 @@ $positionsInOrder = sortPlanetsByLongitude($samplePlanets);Nakshatra | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| = htmlspecialchars($planet['name']) ?> | += htmlspecialchars($planet['house']) ?> | += htmlspecialchars($planet['sign']) ?> | += htmlspecialchars($planet['degree']) ?> | += htmlspecialchars($planet['nakshatra']) ?> | +|||||
| = htmlspecialchars($planet['name']) ?> | -= htmlspecialchars($planet['house']) ?> | -= htmlspecialchars($planet['sign']) ?> | -= htmlspecialchars($planet['degree']) ?> | -= htmlspecialchars($planet['nakshatra']) ?> | +No planetary data available. | ||||
| Segment | @@ -252,21 +272,22 @@ $positionsInOrder = sortPlanetsByLongitude($samplePlanets);Nakshatra | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| = htmlspecialchars($planet['house']) ?> | += htmlspecialchars($planet['name']) ?> | += htmlspecialchars($planet['sign']) ?> | += htmlspecialchars($planet['degree']) ?> | += htmlspecialchars($planet['nakshatra']) ?> | +|||||
| = htmlspecialchars($planet['house']) ?> | -= htmlspecialchars($planet['name']) ?> | -= htmlspecialchars($planet['sign']) ?> | -= htmlspecialchars($planet['degree']) ?> | -= htmlspecialchars($planet['nakshatra']) ?> | +No ordered planetary data available. | ||||