-
Notifications
You must be signed in to change notification settings - Fork 2
/
gitmoji.php
41 lines (34 loc) · 1.12 KB
/
gitmoji.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
<?php
require_once('workflows.php');
$w = new Workflows();
$query = urldecode(strtolower(trim($query)));
if (filemtime("data.json") <= (time() - 86400 * 7)) {
$dataUrl = 'https://raw.githubusercontent.com/carloscuesta/gitmoji/master/src/data/gitmojis.json';
$gitmojis = $w->request($dataUrl);
if (isset(json_decode($gitmojis)->gitmojis)) {
file_put_contents("data.json", $gitmojis);
}
}
function setResult($gitmojis) {
global $w;
foreach ($gitmojis as $key => $value) {
$id = $value->name;
$emoji = $value->emoji;
$title = $emoji." ".$value->description;
$subTitle = "Copy ".$id." to clipboard";
$w->result($id, $emoji, $title, $subTitle, ' ');
}
}
function filter($var) {
global $query;
$description = strtolower($var->description);
$name = strtolower($var->name);
return strpos($description,$query) !== false || strpos($name,$query) !== false;
}
$gitmojis = json_decode(file_get_contents('data.json'))->gitmojis;
$data = $gitmojis;
if (strlen($query) != 0) {
$data = array_filter($gitmojis, "filter");
}
setResult($data);
echo $w->toxml();