#!/usr/bin/php
<?php

$docRoot = getenv("DOCUMENT_ROOT");

require_once "DaemonWrapper.php";
$daemon = new DaemonWrapper("my_stellar");
$daemon->start($argv);

require_once $docRoot . "/mobi-config/mobi_lib_constants.php";
require_once LIBDIR . "db.php";
require_once LIBDIR . "StellarData.php";
require_once "apns_lib.php";

while($daemon->sleep(STELLAR_FEED_CACHE_TIMEOUT)) {
  db::ping();  //make sure the db keeps running

  $term = StellarData::get_term();
  $subject_ids = StellarData::check_subscriptions($term);

  foreach($subject_ids as $subject_id) {
    $announcements = StellarData::get_announcements($subject_id);

    if(count($announcements) > 0 ) {
      $notification_types = array(
	'apple' => new StellarAppleNotification($subject_id, $announcements)
      );

      foreach(StellarData::subscriptions_for_subject($subject_id, $term) as $subscription) {
        $notification_types[$subscription['device_type']]->queue_notification($subscription['device_id']);
      }
#!/usr/bin/php
<?php 
define("APNS_PUSH_REST_TIME", 15);
require_once dirname(__FILE__) . "/../../config/mobi_web_constants.php";
require_once "DaemonWrapper.php";
$daemon = new DaemonWrapper("apns_push");
$daemon->start($argv);
require_once 'apns_lib.php';
$apns_server = new ApplePushServersPool(APNS_CONNECTIONS_LIMIT);
// this is a daemon so loop forever
d_echo("push daemon activated");
while ($daemon->sleep(APNS_PUSH_REST_TIME)) {
    d_echo("waiting for messages to send...", False);
    db::ping();
    $messages = APNS_DB::get_unsent_notifications();
    while ($message = APNS_DB::fetch_notification($messages)) {
        $data = $message['payload'];
        $device_id = $message['device_id'];
        $device = APNS_DB::get_device($device_id);
        $module_name = get_module_name($message['tag']);
        // we only send to devices that have not been deactived
        // and we only send to enabled modules
        if ($device['active'] == 1 && APNS_DB::is_module_enabled($device_id, $module_name)) {
            // need to compute the number of unread messages
            // to be displayed on "badge" on the device
            $unreads = $device['unread_notifications'];
            // look for an old version of this message
            $old_position = array_search($message['tag'], $unreads);
            if ($old_position !== FALSE) {
                array_splice($unreads, $old_position, 1);
            }
$daemon->start($argv);

$docRoot = getenv("DOCUMENT_ROOT");

require_once $docRoot . "/mobi-config/mobi_lib_constants.php";
require_once LIBDIR . "rss_services.php";
require_once LIBDIR . "db.php";
require_once "apns_lib.php";

$date = NULL;
$emergency = new Emergency();
$emergency->use_cache = False;

$version = get_version();
  
while($daemon->sleep(15)) {
  $data = $emergency->get_feed();
  if($data !== False) {
    $new_version = intval($data[0]['version']);
  }

  if($version && ($new_version > $version)) {
    // there is emergency unfortunately we now have to notify ALL devices

    db::ping();
    $emergency_apns = array('aps' => 
      array('alert' => substr($data[0]['text'], 0, 100), 'sound' => 'default')
    );

    $result = APNS_DB::get_all_devices();
    while($row = $result->fetch_assoc()) {
$daemon = new DaemonWrapper("shuttle");
$daemon->start($argv);


require_once dirname(__FILE__) . "/../../../mobi-config/mobi_lib_constants.php";
require_once LIB_ROOT . "ShuttleSchedule.php";
require_once LIB_ROOT . "NextBusReader.php";
require_once LIB_ROOT . "db.php";
require_once "apns_lib.php";

ShuttleSchedule::init();
NextBusReader::init();

$all_routes = ShuttleSchedule::get_route_list();

while ($daemon->sleep(10)) {
  db::ping(); // keep the database connection running

  $time = time();
  $too_old = $time - 7200; // arbitrary 2 hour timeout threshold for now

  // only keep track of shuttles that are running
  $routes = array_filter($all_routes, array('ShuttleSchedule', 'is_running'));

  if (count($routes)) {
    foreach ($routes as $route) {
      // force NextBusReader to cache
      NextBusReader::get_predictions($route);
      NextBusReader::get_coordinates($route);
    }
#!/usr/bin/php
<?php 
define("APNS_FEEDBACK_REST_TIME", 5 * 60 * 60);
require_once "DaemonWrapper.php";
$daemon = new DaemonWrapper("apns_feedback");
$daemon->start($argv);
require_once 'apns_lib.php';
$apns_server = new ApplePushNotificationConnection();
while ($daemon->sleep(APNS_FEEDBACK_REST_TIME)) {
    // this is a daemon so loop forever
    $apns_server->open_feedback_connection();
    $messages = $apns_server->get_feedback_messages();
    db::ping();
    foreach ($messages as $message) {
        d_echo("received a deactivate message from apple for:{$message['device_token']}");
        APNS_DB::record_device_uninstalled_app($message['device_token'], $message['unixtime']);
    }
    $apns_server->close_feedback_connection();
}
$daemon->stop();