-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMyKeyworder.php
More file actions
64 lines (51 loc) · 2.01 KB
/
MyKeyworder.php
File metadata and controls
64 lines (51 loc) · 2.01 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
<?php
class MyKeyworder extends API {
function getInfo() : array
{
return [
"icon" => 'https://mykeyworder.com/img/logo.png',
"site" => 'https://mykeyworder.com/',
"info" => `
MyKeyworder is a keywording tool for photographers. The image recognition API provides programmatic access to the MyKeyworder Image Recognition service for automatically keywording larger volumes of images.
`
];
}
function getConfParams() : array
{
return [
'USER' => 'API Username',
'USER_PASSWORD'=> 'API Key'
];
}
function generateTags($conf, $params) : array
{
if (isset($_SERVER['HTTPS'])){
$file_path = "https://".$_SERVER['HTTP_HOST'].ltrim($this->getFileName($params['imageId']), '.');
} else {
$file_path = "http://".$_SERVER['HTTP_HOST'].ltrim($this->getFileName($params['imageId']), '.');
}
if (!(isset($conf['USER']) && isset($conf['USER_PASSWORD'])))
throw new Exception('API parameters are not set');
$api_credentials = array(
'key' => $conf['USER'],
'secret' => $conf['USER_PASSWORD']
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://mykeyworder.com/api/v1/analyze?url='.urlencode($file_path));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_USERPWD, $api_credentials['key'].':'.$api_credentials['secret']);
$response = curl_exec($ch);
curl_close($ch);
$json_response = json_decode($response);
$tags = [];
if(isset($json_response->keywords)){
foreach ($json_response->keywords as $tagObject)
{
$tagObjectArray = json_decode(json_encode($tagObject), true);
array_push($tags, $tagObjectArray);
}
}
return $tags;
}
}