function do_update_if_needed($twitster) { if (time_for_refresh()) { if (file_exists(UPDATE_PID_FILE)) { twitlog("Time for an update, but one is already in progress. Skipping."); } else { twitlog("It is time to refresh the cache, beginning now."); $tweets = Tweet::find(); $since = is_array($tweets) && $tweets[0] ? $tweets[0]->id : false; $twitster->refresh($since); } } }
public function store(Request $request) { $type = $request->get('type'); $tweet = Tweet::find($id); if (!$tweet) { $tweet = new Tweet(); $tweet[$type] = 1; } $tweet->id = $request->get('id'); $tweet->text = $request->get('text'); $tweet->increment($type); $tweet->save(); return $request->all(); }
public function healthcheck() { // Check we have data from Mandrill $data = json_decode($this->PostData('mandrill_events')); if (!$data) { echo 'OK - No Data'; die; } // We need to check if we've sent an alert in the past // 8 hours, if not, send another one. $content = "Exchange Alert: Delivery Delay"; $cutoff = time() - 3600 * 8; $lastTweet = Tweet::find("tweets.message = '{$content}'", "publish_at DESC"); if ($lastTweet && $lastTweet->publish_at > $cutoff) { echo 'OK - Alert Already Sent'; die; } $account = TwitterAccount::find_by_code('site'); $account->add_tweet($content); echo 'OK - Alert Sent'; die; }
$twitster = new twitster(); $twitster->init(); $offset = isset($_REQUEST['offset']) ? $_REQUEST['offset'] : 0; $tag = $_REQUEST['tag']; if (!isset($_REQUEST['tag']) && HASHTAG) { $tag = HASHTAG; } $feed_link = 'rss.php?tag=' . urlencode($tag); $options = array(); $options['tag'] = $tag; $options['offset'] = $offset; $options['limit'] = PAGE_LIMIT; if ($offset == 0) { do_update_if_needed($twitster); } $tweets = Tweet::find($options); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title><?php echo SITE_TITLE; ?> : <?php echo SITE_SUBTITLE; ?> </title> <meta name="description" content="<?php echo SITE_SUBTITLE;