Api Fixed
This commit is contained in:
@@ -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;
|
||||
}
|
||||
128
ephemeris_engine.php
Normal file
128
ephemeris_engine.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
require_once 'astro_functions.php';
|
||||
|
||||
const SWISSEPH_API_BASE_URL = 'http://bibgit.com:8081/api.php';
|
||||
const SWISSEPH_API_TIMEOUT = 20;
|
||||
|
||||
function buildSwissephApiUrl(
|
||||
string $date,
|
||||
string $time,
|
||||
float $latitude,
|
||||
float $longitude,
|
||||
string $timezone = 'Asia/Kathmandu'
|
||||
): string {
|
||||
return SWISSEPH_API_BASE_URL
|
||||
. '?date=' . urlencode($date)
|
||||
. '&time=' . urlencode($time)
|
||||
. '&timezone=' . urlencode($timezone)
|
||||
. '&latitude=' . urlencode((string)$latitude)
|
||||
. '&longitude=' . urlencode((string)$longitude);
|
||||
}
|
||||
|
||||
function fetchRemoteSwissephResponse(
|
||||
string $date,
|
||||
string $time,
|
||||
float $latitude,
|
||||
float $longitude,
|
||||
string $timezone = 'Asia/Kathmandu'
|
||||
): array {
|
||||
$url = buildSwissephApiUrl($date, $time, $latitude, $longitude, $timezone);
|
||||
|
||||
if (function_exists('curl_init')) {
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, SWISSEPH_API_TIMEOUT);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$curlErr = curl_error($ch);
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
if ($response === false || $httpCode !== 200) {
|
||||
return [
|
||||
'success' => 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' => ''
|
||||
];
|
||||
}
|
||||
98
index.php
98
index.php
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
require_once 'constants.php';
|
||||
require_once 'astro_functions.php';
|
||||
require_once 'ephemeris_engine.php';
|
||||
|
||||
$nameMode = NAME_MODE_MODERN;
|
||||
$nameMode=NAME_MODE_VEDIC;
|
||||
$nameMode = NAME_MODE_VEDIC;
|
||||
date_default_timezone_set('Asia/Kathmandu');
|
||||
|
||||
$date = $_GET['date'] ?? '';
|
||||
@@ -28,6 +28,13 @@ $utcDateTime = '';
|
||||
$unixTimestamp = '';
|
||||
$julianDay = '';
|
||||
$decimalHour = '';
|
||||
$apiError = '';
|
||||
|
||||
$samplePlanets = [];
|
||||
$planetsByHierarchy = [];
|
||||
$positionsInOrder = [];
|
||||
$ascendantLongitude = null;
|
||||
$ascendantData = null;
|
||||
|
||||
if (!empty($location) && isset($locationMap[$location])) {
|
||||
$latitude = $locationMap[$location]['latitude'];
|
||||
@@ -79,32 +86,34 @@ if (!empty($date) && !empty($time) && !empty($location) && isset($locationMap[$l
|
||||
$unixTimestamp = $calcData['unix_timestamp'];
|
||||
$julianDay = $calcData['julian_day'];
|
||||
$decimalHour = $calcData['decimal_hour'];
|
||||
}
|
||||
|
||||
/*
|
||||
SAMPLE PLANET DATA
|
||||
house = wheel segment number
|
||||
*/
|
||||
$samplePlanets = [
|
||||
buildPlanetDataFromLongitude('sun', 5.20, $nameMode),
|
||||
buildPlanetDataFromLongitude('moon', 72.13, $nameMode),
|
||||
buildPlanetDataFromLongitude('mars', 78.35, $nameMode),
|
||||
buildPlanetDataFromLongitude('mercury', 32.08, $nameMode),
|
||||
buildPlanetDataFromLongitude('venus', 41.30, $nameMode),
|
||||
buildPlanetDataFromLongitude('jupiter', 129.18, $nameMode),
|
||||
buildPlanetDataFromLongitude('saturn', 22.43, $nameMode),
|
||||
buildPlanetDataFromLongitude('rahu', 304.23, $nameMode),
|
||||
buildPlanetDataFromLongitude('ketu', 124.23, $nameMode)
|
||||
];
|
||||
$realPlanetData = getRealPlanetaryData($date, $time, (float)$latitude, (float)$longitude);
|
||||
$realPlanetLongitudes = $realPlanetData['planets'];
|
||||
$ascendantLongitude = $realPlanetData['ascendant'];
|
||||
$apiError = $realPlanetData['error'];
|
||||
|
||||
if (!empty($realPlanetLongitudes)) {
|
||||
foreach ($realPlanetLongitudes as $planet) {
|
||||
$samplePlanets[] = buildPlanetDataFromLongitude(
|
||||
$planet['key'],
|
||||
$planet['longitude'],
|
||||
$nameMode
|
||||
);
|
||||
}
|
||||
} elseif (empty($apiError)) {
|
||||
$apiError = 'Could not fetch planetary data from remote API.';
|
||||
}
|
||||
|
||||
if ($ascendantLongitude !== null) {
|
||||
$ascendantData = buildPlanetDataFromLongitude('sun', $ascendantLongitude, $nameMode);
|
||||
}
|
||||
}
|
||||
|
||||
$planetsByHierarchy = $samplePlanets;
|
||||
$positionsInOrder = sortPlanetsByLongitude($samplePlanets);
|
||||
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
@@ -113,7 +122,6 @@ $positionsInOrder = sortPlanetsByLongitude($samplePlanets);
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="css.css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="container py-5">
|
||||
@@ -183,8 +191,20 @@ $positionsInOrder = sortPlanetsByLongitude($samplePlanets);
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($ascendantLongitude !== null && $ascendantData !== null): ?>
|
||||
<div class="mt-3">
|
||||
<p><strong>Ascendant Longitude:</strong> <?= htmlspecialchars((string)round($ascendantLongitude, 6)) ?></p>
|
||||
<p><strong>Ascendant Sign:</strong> <?= htmlspecialchars($ascendantData['sign']) ?></p>
|
||||
<p><strong>Ascendant Degree:</strong> <?= htmlspecialchars($ascendantData['degree']) ?></p>
|
||||
<p><strong>Ascendant Nakshatra:</strong> <?= htmlspecialchars($ascendantData['nakshatra']) ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
<?php if (!empty($apiError)): ?>
|
||||
<div class="alert alert-danger mt-3 mb-0">
|
||||
<?= htmlspecialchars($apiError) ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="result-box mt-3">
|
||||
@@ -200,13 +220,13 @@ $positionsInOrder = sortPlanetsByLongitude($samplePlanets);
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row g-4 mt-4">
|
||||
<div class="col-lg-6">
|
||||
<div class="table-box">
|
||||
<h5 class="table-title">Table 1: Positions by Planets</h5>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-dark table-bordered align-middle astro-table mb-0">
|
||||
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Planet</th>
|
||||
@@ -216,11 +236,9 @@ $positionsInOrder = sortPlanetsByLongitude($samplePlanets);
|
||||
<th>Nakshatra</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
|
||||
<?php if (!empty($planetsByHierarchy)): ?>
|
||||
<?php foreach ($planetsByHierarchy as $planet): ?>
|
||||
|
||||
<tr>
|
||||
<td><?= htmlspecialchars($planet['name']) ?></td>
|
||||
<td><?= htmlspecialchars($planet['house']) ?></td>
|
||||
@@ -228,9 +246,12 @@ $positionsInOrder = sortPlanetsByLongitude($samplePlanets);
|
||||
<td><?= htmlspecialchars($planet['degree']) ?></td>
|
||||
<td><?= htmlspecialchars($planet['nakshatra']) ?></td>
|
||||
</tr>
|
||||
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php else: ?>
|
||||
<tr>
|
||||
<td colspan="5">No planetary data available.</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@@ -242,7 +263,6 @@ $positionsInOrder = sortPlanetsByLongitude($samplePlanets);
|
||||
<h5 class="table-title">Table 2: Positions in Order</h5>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-dark table-bordered align-middle astro-table mb-0">
|
||||
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Segment</th>
|
||||
@@ -252,11 +272,9 @@ $positionsInOrder = sortPlanetsByLongitude($samplePlanets);
|
||||
<th>Nakshatra</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
|
||||
<?php if (!empty($positionsInOrder)): ?>
|
||||
<?php foreach ($positionsInOrder as $planet): ?>
|
||||
|
||||
<tr>
|
||||
<td><?= htmlspecialchars($planet['house']) ?></td>
|
||||
<td><?= htmlspecialchars($planet['name']) ?></td>
|
||||
@@ -264,9 +282,12 @@ $positionsInOrder = sortPlanetsByLongitude($samplePlanets);
|
||||
<td><?= htmlspecialchars($planet['degree']) ?></td>
|
||||
<td><?= htmlspecialchars($planet['nakshatra']) ?></td>
|
||||
</tr>
|
||||
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php else: ?>
|
||||
<tr>
|
||||
<td colspan="5">No ordered planetary data available.</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@@ -282,10 +303,9 @@ $positionsInOrder = sortPlanetsByLongitude($samplePlanets);
|
||||
|
||||
<script>
|
||||
const samplePlanets = <?= json_encode($samplePlanets, JSON_UNESCAPED_UNICODE); ?>;
|
||||
const signNames = <?= json_encode(array_values(SIGN_NAMES[$nameMode])); ?>;
|
||||
</script>
|
||||
<script src="js.js"></script>
|
||||
const signNames = <?= json_encode(array_values(SIGN_NAMES[$nameMode]), JSON_UNESCAPED_UNICODE); ?>;
|
||||
</script>
|
||||
<script src="js.js"></script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user