-
Notifications
You must be signed in to change notification settings - Fork 0
/
mackeys.php
90 lines (72 loc) · 1.66 KB
/
mackeys.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
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
<?php
require_once('workflows.php');
class MacKeys
{
/**
* @var string
*/
protected $title = 'Mackeys';
/**
* @var string
*/
protected $icon = 'icon.png';
/**
* @var Workflows
*/
protected $workflows;
/**
* @var array
*/
protected $keys = array();
/**
* @param Workflows $workflows
*/
public function __construct(Workflows $workflows)
{
$this->workflows = $workflows;
$this->keys = $this->getKeys();
}
/**
* Retrieves list of keys from json file
*
* @return array
*/
protected function getKeys()
{
if ( ! $keys = json_decode(file_get_contents('keyslist.json'), true)) {
echo $this->quit('Could not get the keys from "keyslist.json" :(');
exit();
}
return $keys;
}
/**
* Quits with message
*
* @param $message
* @return string
*/
protected function quit($message)
{
$this->workflows->result("999", "", $message, $this->title, $this->icon, 'no');
return $this->workflows->toxml();
}
/**
* @param string $query
* @return string
*/
public function process($query)
{
$result = str_replace(array_keys($this->keys), array_values($this->keys), $query);
$this->workflows->result(md5($query), $result, $result, $this->title, $this->icon, 'yes');
return $this->workflows->toxml();
}
}
// dependency
$workflows = new Workflows();
// query arg
if ( ! isset($query)) {
$query = $argv[1];
}
// get the result
$mackeys = new MacKeys($workflows);
echo $mackeys->process($query);