[OneFortuneADayBridge] Add lucky number feature (#1038)
This commit is contained in:
parent
3d24596a52
commit
958ba815c7
1 changed files with 10 additions and 2 deletions
|
@ -35,25 +35,33 @@ class OneFortuneADayBridge extends BridgeAbstract {
|
||||||
'23:00' => 23,
|
'23:00' => 23,
|
||||||
),
|
),
|
||||||
'defaultValue' => 5
|
'defaultValue' => 5
|
||||||
|
),
|
||||||
|
'lucky' => array(
|
||||||
|
'name' => 'Lucky number (optional)',
|
||||||
|
'type' => 'text'
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
|
||||||
const LIMIT_ITEMS = 7;
|
const LIMIT_ITEMS = 7;
|
||||||
const DAY_SECS = 86400;
|
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() {
|
public function collectData() {
|
||||||
$time = gmmktime((int)$this->getInput('time'), 0, 0);
|
$time = gmmktime((int)$this->getInput('time'), 0, 0);
|
||||||
if ($time > time())
|
if ($time > time())
|
||||||
$time -= self::DAY_SECS;
|
$time -= self::DAY_SECS;
|
||||||
|
|
||||||
for ($i = self::LIMIT_ITEMS; $i > 0; --$i) {
|
for ($i = self::LIMIT_ITEMS; $i > 0; --$i) {
|
||||||
$seed = date('Ymd', $time);
|
$seed = date('Ymd', $time) . $this->getInput('lucky');
|
||||||
$quote = $this->getQuote($seed);
|
$quote = $this->getQuote($seed);
|
||||||
|
|
||||||
$item['title'] = strftime('%A, %x', $time);
|
$item['title'] = strftime('%A, %x', $time);
|
||||||
$item['content'] = htmlentities($quote, ENT_QUOTES, 'UTF-8');
|
$item['content'] = htmlentities($quote, ENT_QUOTES, 'UTF-8');
|
||||||
$item['timestamp'] = $time;
|
$item['timestamp'] = $time;
|
||||||
$item['uri'] = 'urn:sha1:' . hash('sha1', $seed);
|
$item['uid'] = hash('sha1', $seed);
|
||||||
|
|
||||||
$this->items[] = $item;
|
$this->items[] = $item;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue