46 lines
896 B
PHP
Executable file
46 lines
896 B
PHP
Executable file
#!/usr/bin/env php
|
|
<?php
|
|
|
|
require __DIR__.'/base/block.php';
|
|
|
|
$blockName = $argv[1] ?? 'rss';
|
|
$rss = $argv[2] ?? null;
|
|
$client = $argv[3] ?? null;
|
|
$color1 = $argv[4] ?? color('normal');
|
|
$color2 = $argv[5] ?? color('info');
|
|
|
|
if (empty($rss)) {
|
|
die;
|
|
}
|
|
|
|
$content = @file_get_contents($rss);
|
|
|
|
if (empty($content)) {
|
|
die;
|
|
}
|
|
|
|
preg_match_all('/<entry/isU', $content, $matches1, PREG_SET_ORDER);
|
|
preg_match_all('/<item/isU', $content, $matches2, PREG_SET_ORDER);
|
|
|
|
$title = pemoji(0xf09e);
|
|
$count1 = count($matches1);
|
|
$count2 = count($matches2);
|
|
$count = $count1 ? $count1 : $count2;
|
|
|
|
if ($count > 0) {
|
|
$title .= '+'.$count.' ';
|
|
}
|
|
|
|
$fullText = span($title, $count ? $color1 : $color2, '#333');
|
|
|
|
if ($client && (int) getenv('BLOCK_BUTTON') === 1) {
|
|
shell_exec(sprintf('xdg-open %s', escapeshellarg($client)));
|
|
}
|
|
|
|
echo block(
|
|
$blockName,
|
|
[
|
|
'full_text' => $fullText,
|
|
]
|
|
);
|