doti3/bar/src/rss.php

46 lines
895 B
PHP
Raw Normal View History

2019-01-21 16:20:04 +01:00
#!/usr/bin/php7.1
2017-12-04 18:17:42 +01:00
<?php
require __DIR__.'/base/block.php';
2020-01-14 11:35:27 +01:00
$blockName = $argv[1] ?? 'rss';
$rss = $argv[2] ?? null;
$client = $argv[3] ?? null;
$color1 = $argv[4] ?? color('normal');
$color2 = $argv[5] ?? color('info');
2017-12-04 18:17:42 +01:00
2019-01-28 11:13:11 +01:00
if (empty($rss)) {
2017-12-04 18:17:42 +01:00
die;
}
$content = @file_get_contents($rss);
if (empty($content)) {
die;
}
2020-01-14 11:35:27 +01:00
preg_match_all('/<entry/isU', $content, $matches1, PREG_SET_ORDER);
preg_match_all('/<item/isU', $content, $matches2, PREG_SET_ORDER);
2017-12-04 18:17:42 +01:00
2019-01-28 11:13:11 +01:00
$title = pemoji(0xf09e);
2020-01-14 11:35:27 +01:00
$count1 = count($matches1);
$count2 = count($matches2);
$count = $count1 ? $count1 : $count2;
2019-01-21 16:20:04 +01:00
if ($count > 0) {
2020-01-14 11:35:27 +01:00
$title .= '+'.$count.' ';
2019-01-21 16:20:04 +01:00
}
2020-01-14 11:35:27 +01:00
$fullText = span($title, $count ? $color1 : $color2, '#333');
2017-12-04 18:17:42 +01:00
2019-01-28 11:13:11 +01:00
if ($client && (int) getenv('BLOCK_BUTTON') === 1) {
shell_exec(sprintf('xdg-open %s', escapeshellarg($client)));
2017-12-04 18:17:42 +01:00
}
2017-12-15 17:43:15 +01:00
echo block(
2020-01-14 11:35:27 +01:00
$blockName,
2017-12-15 17:43:15 +01:00
[
'full_text' => $fullText,
]
);