-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
48 lines (35 loc) · 1.3 KB
/
index.php
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
<?php
use ymdarake\tamai\news\server\searchclient\impl\BingNewsSearchApiClient;
use ymdarake\tamai\news\server\searchclient\impl\CnnClient;
use ymdarake\tamai\news\server\searchclient\impl\NatalieMusicClient;
date_default_timezone_set("Asia/Tokyo");
require_once(__DIR__ . '/vendor/autoload.php');
require_once(__DIR__ . "/config/env.php");
require_once(__DIR__ . "/searchclient/impl/BingNewsSearchApiClient.php");
require_once(__DIR__ . "/searchclient/impl/CnnClient.php");
require_once(__DIR__ . "/searchclient/impl/NatalieMusicClient.php");
$searchClient = getSearchClient();
$searchResult = $searchClient->search();
echo json_encode($searchResult);
exit;
function getSearchClient() {
if (!isKeywordSearch()) {
return new CnnClient();
}
if (isNatalieSearch()) {
return new NatalieMusicClient();
}
$client = new BingNewsSearchApiClient();
$client->setWord(getWord());
return $client;
}
function isKeywordSearch() {
$searchWhiteList = ["玉井詩織", "百田夏菜子", "ももクロ", "ももいろクローバーZ", "佐々木彩夏", "高城れに", "ももいろクローバー", "natalie"];
return !empty(getWord()) && in_array(getWord(), $searchWhiteList);
}
function isNatalieSearch() {
return getWord() === 'natalie';
}
function getWord() {
return isset($_GET["word"]) ? $_GET["word"] : "";
}