SIMON Master Console Rebuild
True command center for SIMON + WEB360
This rebuild gives you a cleaner production spine: interactive tree, live viewer, guarded editor, dynamic graphics, architecture map, and note storage. It is designed to sit beside your existing
console.php
and become the stronger replacement path.
Dashboard
Tree
Viewer
System Map
File Registry
Notes
Files
15,656
Folders
433
Scanned Size
3.90 GB
PHP Files
988
Editable Text Files
12,914
File viewer
guarded to /htdocs
/connlink/test1/ui/serpapi_proxy.php
<?php declare(strict_types=1); header('Content-Type: application/json; charset=utf-8'); header('Cache-Control: no-store, max-age=0'); header('X-Content-Type-Options: nosniff'); function respond(array $payload, int $status = 200): never { http_response_code($status); echo json_encode($payload, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); exit; } if (($_SERVER['REQUEST_METHOD'] ?? 'GET') !== 'GET') { respond(['ok' => false, 'error' => 'GET required'], 405); } $documentRoot = rtrim((string)($_SERVER['DOCUMENT_ROOT'] ?? ''), '/\\'); $configCandidates = array_values(array_unique(array_filter([ $documentRoot !== '' ? $documentRoot . '/private/config.php' : null, $documentRoot !== '' ? dirname($documentRoot) . '/private/config.php' : null, dirname(__DIR__, 3) . '/private/config.php', dirname(__DIR__, 4) . '/private/config.php', ]))); $configPath = ''; foreach ($configCandidates as $candidate) { if (!is_file($candidate)) { continue; } require_once $candidate; $configPath = $candidate; break; } if ($configPath === '') { respond([ 'ok' => false, 'error' => 'Private config file was not found.', 'checked' => $configCandidates, ], 500); } $providerKeys = $GLOBALS['SIMON_PROVIDER_KEYS'] ?? []; if (!is_array($providerKeys)) { $providerKeys = []; } $apiKey = trim((string)($providerKeys['SERPAPI_KEY'] ?? '')); if ($apiKey === '' && defined('SERPAPI_KEY')) { $apiKey = trim((string)SERPAPI_KEY); } if ($apiKey === '' && defined('SERPAPI_API_KEY')) { $apiKey = trim((string)SERPAPI_API_KEY); } if ($apiKey === '' && ($env = getenv('SERPAPI_KEY')) !== false) { $apiKey = trim((string)$env); } if ($apiKey === '' && ($env = getenv('SERPAPI_API_KEY')) !== false) { $apiKey = trim((string)$env); } if ($apiKey === '') { respond([ 'ok' => false, 'error' => 'SERPAPI_KEY was not found in SIMON_PROVIDER_KEYS.', 'config_loaded' => $configPath, 'available_keys' => array_keys($providerKeys), ], 503); } $query = trim((string)($_GET['q'] ?? '')); if ($query === '') { respond(['ok' => false, 'error' => 'Missing q parameter'], 400); } if ((function_exists('mb_strlen') ? mb_strlen($query) : strlen($query)) > 300) { respond(['ok' => false, 'error' => 'Query is too long'], 400); } $num = (int)($_GET['num'] ?? 10); $num = max(1, min(20, $num)); $country = preg_replace('/[^a-z]/i', '', (string)($_GET['gl'] ?? 'us')) ?: 'us'; $language = preg_replace('/[^a-z-]/i', '', (string)($_GET['hl'] ?? 'en')) ?: 'en'; $params = [ 'engine' => 'google', 'q' => $query, 'api_key' => $apiKey, 'num' => $num, 'gl' => strtolower($country), 'hl' => strtolower($language), 'safe' => 'active', 'no_cache' => 'true', ]; $url = 'https://serpapi.com/search.json?' . http_build_query($params, '', '&', PHP_QUERY_RFC3986); $ch = curl_init($url); if ($ch === false) { respond(['ok' => false, 'error' => 'Unable to initialize search request'], 500); } curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_CONNECTTIMEOUT => 8, CURLOPT_TIMEOUT => 22, CURLOPT_USERAGENT => 'SIMON-Search/1.0 (+https://www.gaylordsinclair.com/)', CURLOPT_HTTPHEADER => ['Accept: application/json'], ]); $body = curl_exec($ch); $curlError = curl_error($ch); $status = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($body === false || $curlError !== '') { respond(['ok' => false, 'error' => 'SerpAPI connection failed: ' . $curlError], 502); } $data = json_decode($body, true); if (!is_array($data)) { respond(['ok' => false, 'error' => 'SerpAPI returned invalid JSON'], 502); } if ($status >= 400 || isset($data['error'])) { respond([ 'ok' => false, 'error' => (string)($data['error'] ?? ('SerpAPI HTTP ' . $status)) ], $status >= 400 ? $status : 502); } $results = []; $addResult = static function (array &$target, string $title, string $snippet, string $link, string $type, int $position = 0, string $thumbnail = ''): void { $title = trim($title); $link = trim($link); if ($title === '' || $link === '') { return; } $target[] = [ 'title' => $title, 'snippet' => trim(strip_tags($snippet)), 'url' => $link, 'source' => 'SerpAPI', 'result_type' => $type, 'position' => $position, 'thumbnail' => trim($thumbnail), ]; }; if (isset($data['answer_box']) && is_array($data['answer_box'])) { $answer = $data['answer_box']; $addResult( $results, (string)($answer['title'] ?? $answer['answer'] ?? 'Featured Answer'), (string)($answer['snippet'] ?? $answer['answer'] ?? $answer['result'] ?? ''), (string)($answer['link'] ?? $answer['displayed_link'] ?? ''), 'answer_box', 0, (string)($answer['thumbnail'] ?? $answer['image'] ?? '') ); } if (isset($data['knowledge_graph']) && is_array($data['knowledge_graph'])) { $kg = $data['knowledge_graph']; $addResult( $results, (string)($kg['title'] ?? 'Knowledge Graph'), (string)($kg['description'] ?? $kg['type'] ?? ''), (string)($kg['website'] ?? $kg['source']['link'] ?? ''), 'knowledge_graph', 0, (string)($kg['thumbnail'] ?? $kg['image'] ?? '') ); } foreach (($data['organic_results'] ?? []) as $row) { if (!is_array($row)) { continue; } $addResult( $results, (string)($row['title'] ?? ''), (string)($row['snippet'] ?? $row['snippet_highlighted_words'][0] ?? ''), (string)($row['link'] ?? ''), 'organic', (int)($row['position'] ?? 0), (string)($row['thumbnail'] ?? $row['favicon'] ?? '') ); } foreach (($data['related_questions'] ?? []) as $row) { if (!is_array($row)) { continue; } $addResult( $results, (string)($row['question'] ?? ''), (string)($row['snippet'] ?? ''), (string)($row['link'] ?? ''), 'related_question', 0, (string)($row['thumbnail'] ?? '') ); } // Remove duplicate URLs while preserving the most useful ordering. $seen = []; $deduped = []; foreach ($results as $result) { $key = strtolower(rtrim((string)$result['url'], '/')); if ($key === '' || isset($seen[$key])) { continue; } $seen[$key] = true; $deduped[] = $result; if (count($deduped) >= $num + 6) { break; } } respond([ 'ok' => true, 'provider' => 'SerpAPI', 'query' => $query, 'results' => $deduped, 'search_metadata' => [ 'status' => (string)($data['search_metadata']['status'] ?? 'Success'), 'processed_at' => gmdate('c'), 'total_results' => $data['search_information']['total_results'] ?? null, ], ]);
Save file
Quick jump
open a path
Open