-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
317 lines (258 loc) · 12.6 KB
/
Copy pathindex.php
File metadata and controls
317 lines (258 loc) · 12.6 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<?php
set_time_limit(60); // Limite de temps d'exécution du script
require 'vendor/autoload.php';
require_once 'openai_api.php';
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
$googleApiKey = $_ENV['GOOGLE_API_KEY'];
$googleSearchEngineId = $_ENV['GOOGLE_SEARCH_ENGINE_ID'];
function rechercheGoogle($query, $start = 1) {
$apiKey = $_ENV['GOOGLE_API_KEY'];
$searchEngineId = $_ENV['GOOGLE_SEARCH_ENGINE_ID'];
$url = "https://www.googleapis.com/customsearch/v1?key=" . $apiKey . "&cx=" . $searchEngineId . "&q=" . urlencode($query) . "&start=" . $start . "&num=10";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60); // Limite de temps pour la requête
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode != 200) {
error_log("Google API returned HTTP code $httpCode for query: $query");
curl_close($ch);
return [];
}
if (curl_errno($ch)) {
error_log("cURL error: " . curl_error($ch));
curl_close($ch);
return [];
}
curl_close($ch);
return json_decode($response, true);
}
function rechercheGoogleImages($query, $start = 1) {
$apiKey = $_ENV['GOOGLE_API_KEY'];
$searchEngineId = $_ENV['GOOGLE_SEARCH_ENGINE_ID'];
$url = "https://www.googleapis.com/customsearch/v1?key=" . $apiKey . "&cx=" . $searchEngineId . "&q=" . urlencode($query) . "&start=" . $start . "&num=10&searchType=image";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60); // Limite de temps pour la requête
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode != 200) {
error_log("Google API returned HTTP code $httpCode for query: $query");
curl_close($ch);
return [];
}
if (curl_errno($ch)) {
error_log("cURL error: " . curl_error($ch));
curl_close($ch);
return [];
}
curl_close($ch);
return json_decode($response, true);
}
function getFaviconUrl($siteUrl) {
return "https://www.google.com/s2/favicons?domain=" . urlencode($siteUrl);
}
$keyConcepts = '';
$resultatsImages = [];
$afficherTexteIntro = true;
$afficherImageIntro = true;
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['recherche'])) {
$afficherTexteIntro = false;
$afficherImageIntro = false;
$recherche = $_POST['recherche'];
$typeRecherche = $_POST['typeRecherche'] ?? 'simple';
if ($typeRecherche == 'ia') {
// Traitement de la recherche avec l'IA
$messages = [
["role" => "system", "content" => "Listez directement jusqu'à 4 mots-clés pertinents issus de la requête de l'utilisateur, sans explications ni commentaires. Afin d'orienter efficacement une recherche Google, incluez jusqu'à 2 mots-clés principaux directement extraits de la requête pour garantir que la réponse reste centrée sur le sujet demandé. Complétez avec 2 mots-clés supplémentaires pertinents et en lien direct avec la requête initiale, enrichissant ainsi celle-ci de votre esprit de déduction."],
["role" => "user", "content" => $recherche]
];
try {
$response = $openAI->queryGPT($messages);
if (!$response || !isset($response['choices'][0]['message']['content'])) {
throw new Exception('Aucune réponse de l\'IA');
}
$keyConcepts = $response['choices'][0]['message']['content'];
} catch(Exception $e) {
error_log("Erreur OpenAI : " . $e->getMessage());
echo "<p>Erreur lors de la récupération des résultats de l'IA. Veuillez réessayer plus tard.</p>";
}
} else {
// Traitement de la recherche simple
$keyConcepts = $recherche; // Utiliser directement la requête utilisateur
}
try {
$resultatsGoogle = rechercheGoogle($keyConcepts, 1);
$resultatsImages = rechercheGoogleImages($keyConcepts, 1);
if (empty($resultatsGoogle['items']) && empty($resultatsImages['items'])) {
$afficherTexteIntro = true;
$afficherImageIntro = true;
}
} catch(Exception $e) {
error_log("Erreur lors de la recherche Google : " . $e->getMessage());
echo "<p>Erreur lors de la récupération des résultats de recherche Google. Veuillez réessayer plus tard.</p>";
}
}
function displayTextIntro() {
global $afficherTexteIntro;
if ($afficherTexteIntro) {
echo "<div id='introText'>
<h2>Explorez une nouvelle dimension de la recherche avec Equal-Exchange et cherchez AUTREMENT</h2>
<p>Notre moteur de recherche révolutionnaire analyse vos requêtes avec l'intelligence d'OpenAI pour des résultats Google affinés.</p>
<p>Cherchez, posez vos questions, et découvrez des réponses pertinentes là où les recherches traditionnelles atteignent leurs limites.</p>
<p>Rejoignez-nous dans cette aventure novatrice pour une recherche sur Internet plus intuitive et efficace.</p>
</div>";
}
}
function displayImageIntro() {
global $afficherImageIntro;
if ($afficherImageIntro) {
echo "<div id='introImage'>";
echo "<img src='logo_large.png' alt='Logo Equal-Exchange'>";
echo "</div>";
}
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="index.css">
<link rel="shortcut icon" href="logo_EQEX.ico" type="image/x-icon" />
<meta property="og:image" content="https://equal-exchange.com/logo_large.png"/>
<meta name="theme-color" content="#FFFFFF">
<meta name="description" content="Equal-Exchange : moteur de recherche innovant alliant OpenAI et Google pour une expérience de recherche intuitive et efficace.">
<meta name="keywords" content="recherche assistée par IA, optimisation de recherche par IA, moteur de recherche hybride, technologie de recherche avancée, recherche intelligente sur internet, moteur de recherche révolutionnaire, intégration OpenAI Google, recherche web nouvelle génération, système de recherche intuitif, pertinence accrue en recherche web, analyse IA des requêtes, expérience de recherche améliorée, filtrage IA de recherches Google, innovation en recherche web">
<meta name="author" content="Victor DUPREZ - Equal-Exchange">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6308308780527097"
crossorigin="anonymous"></script>
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@iqualexchange">
<meta name="twitter:title" content="Equal-Exchange - La recherche innovante">
<meta name="twitter:description" content="Découvrez une nouvelle manière de rechercher avec l'intelligence artificielle d'OpenAI et Google.">
<meta name="twitter:image" content="https://equal-exchange.com/logo_large.png">
<link rel="canonical" href="https://www.equal-exchange.com/index.php">
<link rel="manifest" href="manifest.json">
<title>Equal-Exchange : Moteur de Recherche Innovant avec IA</title>
</head>
<body>
<div id="loadingIndicator" style="display: none;">
<img src="loading.gif" alt="Chargement..."/>
</div>
<header>
<article class="invest-section">
<p>Envie d'investir dans Equal-Exchange ? <a href="https://trade.kanga.exchange/market/EQEX-ETH" target="_blank">En savoir plus sur les tokens EQEX</a>.</p>
</article>
<h1>Equal-Exchange</h1>
<p>Version bêta</p>
<a href="register.php"><h3>instription</h3></a>
<a href="login.html"><h3>connexion</h3></a>
</header>
<main>
<div class="tab">
<button onclick="openTab('textResults')">Résultats Texte</button>
<button onclick="openTab('imageResults')">Résultats Image</button>
</div>
<section>
<form action="index.php" method="post">
<input type="text" name="recherche" placeholder="Rechercher...">
<div>
<input type="radio" id="rechercheSimple" name="typeRecherche" value="simple">
<label class="radio-label" for="rechercheSimple">Recherche Simple</label>
<input type="radio" id="rechercheIA" name="typeRecherche" value="ia" checked>
<label class="radio-label" for="rechercheIA">Recherche avec IA</label>
</div>
<button type="submit">Rechercher</button>
</form>
</section>
<section id="textResults" class="tabContent">
<?php
if ($afficherTexteIntro) {
// Affiche le texte d'introduction si aucune recherche n'a été effectuée
displayTextIntro();
} else {
if (!empty($resultatsGoogle['items'])) {
if (!empty($keyConcepts)) {
echo "<div class='reponse-openai'>";
echo "<p>Concepts clés identifiés par l'IA : " . htmlspecialchars($keyConcepts) . "</p>";
echo "</div>";
}
echo "<h2>Résultats de la recherche Google :</h2>";
foreach ($resultatsGoogle['items'] as $item) {
$faviconUrl = getFaviconUrl($item['link']); // Récupération de l'URL du favicon
echo "<a href='" . htmlspecialchars($item['link']) . "' target='_blank' class='result-link'>";
echo "<div class='resultat-texte'>";
echo "<img src='" . htmlspecialchars($faviconUrl) . "' alt='Favicon' class='favicon'>"; // Affichage du favicon
echo "<h3>" . htmlspecialchars($item['title']) . "</h3>";
echo "<p>" . htmlspecialchars($item['snippet']) . "</p>";
echo "</div>";
echo "</a>";
}
} else {
echo "<p style='color: white;'>Aucun résultat trouvé ou erreur lors de la recherche Google.</p>";
}
}
?>
</section>
<section id="imageResults" class="tabContent" style="display:none;">
<?php
if ($afficherImageIntro) {
// Affiche le texte d'introduction si aucune recherche n'a été effectuée
displayImageIntro();
}
if (!empty($resultatsImages['items'])) {
echo !empty($keyConcepts) ? "<div class='reponse-openai'><p>Concepts clés identifiés par l'IA : " . htmlspecialchars($keyConcepts) . "</p></div>" : '';
echo "<h2>Résultats de la recherche Google :</h2>";
echo "<div class='grid-container-images'>"; // Début du conteneur de grille
foreach ($resultatsImages['items'] as $image) {
echo "<div class='resultat-image'>";
// Ajoutez un gestionnaire d'erreur onerror à la balise img
echo "<img src='" . htmlspecialchars($image['link']) . "' alt='" . htmlspecialchars($image['snippet']) . "' onerror='this.onerror=null;this.src=\"logo_large.png\";'>";
echo "</div>";
}
echo "</div>"; // Fin du conteneur de grille
} else {
echo "<p style='color: white;'>Aucun résultat d'image trouvé ou erreur lors de la recherche Google.</p>";
}
?>
</section>
</main>
<footer>
<a href="politique_cookies.html" class="pc" title="Politique de confidentialité">Politique de confidentialité</a>
<a href="mentions.html" class="mentions" title="Mentions légales">Mentions légales</a>
</footer>
<script defer>
document.addEventListener('DOMContentLoaded', function() {
var form = document.querySelector('form');
var loadingIndicator = document.getElementById('loadingIndicator');
form.addEventListener('submit', function() {
loadingIndicator.style.display = 'block';
});
window.addEventListener('load', function() {
loadingIndicator.style.display = 'none';
});
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('service-worker.js')
.then(function(registration) {
console.log('Service Worker Registered', registration);
})
.catch(function(error) {
console.log('Service Worker Registration Failed', error);
});
}
});
function openTab(tabName) {
var i, tabcontent;
tabcontent = document.getElementsByClassName("tabContent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
document.getElementById(tabName).style.display = "block";
}
</script>
</body>
</html>