From 0d800b1a694c13d9884b776bef0fb5a6c8365745 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Thu, 25 Jul 2019 09:30:24 +0200 Subject: [PATCH] init --- .gitignore | 2 ++ config.ini.dist | 9 ++++++++ index.php | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 .gitignore create mode 100644 config.ini.dist create mode 100644 index.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..564db9a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/cache.db +/config.ini diff --git a/config.ini.dist b/config.ini.dist new file mode 100644 index 0000000..3ebbe4c --- /dev/null +++ b/config.ini.dist @@ -0,0 +1,9 @@ +[feed] +url = + +[cache] +file = 'cache.db' + +[mattermost] +hook_url = +message_template = diff --git a/index.php b/index.php new file mode 100644 index 0000000..54e414c --- /dev/null +++ b/index.php @@ -0,0 +1,58 @@ +#isU', $feedContent, $titles, PREG_SET_ORDER); +preg_match_all('#(.*)#isU', $feedContent, $links, PREG_SET_ORDER); + +$commands = []; + +foreach ($titles as $key => $title) { + $link = $links[$key] ?? null; + + if (!$link) { + continue; + } + + $title = $title[1]; + $link = $link[1]; + + $hash = md5($title.$link); + + if (!isset($cache[$hash])) { + $cache[$hash] = true; + + $json = json_encode([ + 'text' => sprintf($template, $title, $link), + ]); + + $commands[] = sprintf( + 'curl -i -X POST -H "Content-Type: application/json" -d %s %s', + escapeshellarg($json), + escapeshellarg($hookUrl) + ); + } +} + +file_put_contents($cacheFile, json_encode($cache)); + +foreach ($commands as $command) { + shell_exec($command); +}