[OneFortuneADayBridge] Add lucky number feature (#1038)

This commit is contained in:
fulmeek 2019-02-24 11:49:17 +01:00 committed by LogMANOriginal
parent 3d24596a52
commit 958ba815c7

View file

@ -35,25 +35,33 @@ class OneFortuneADayBridge extends BridgeAbstract {
'23:00' => 23,
),
'defaultValue' => 5
),
'lucky' => array(
'name' => 'Lucky number (optional)',
'type' => 'text'
)
));
const LIMIT_ITEMS = 7;
const DAY_SECS = 86400;
public function getDescription(){
return self::DESCRIPTION . '<br/>Set a lucky number to get your personal quotes, like ' . mt_rand();
}
public function collectData() {
$time = gmmktime((int)$this->getInput('time'), 0, 0);
if ($time > time())
$time -= self::DAY_SECS;
for ($i = self::LIMIT_ITEMS; $i > 0; --$i) {
$seed = date('Ymd', $time);
$seed = date('Ymd', $time) . $this->getInput('lucky');
$quote = $this->getQuote($seed);
$item['title'] = strftime('%A, %x', $time);
$item['content'] = htmlentities($quote, ENT_QUOTES, 'UTF-8');
$item['timestamp'] = $time;
$item['uri'] = 'urn:sha1:' . hash('sha1', $seed);
$item['uid'] = hash('sha1', $seed);
$this->items[] = $item;