function getMyStellar()
{
    // read the cookie, and create three groups
    // first group all the classes in the cookie
    // second group is the classes for the current semester
    // third group is the classes from previou semesters
    if (!isset($_COOKIE["mystellar"])) {
        $allTags = array();
    } else {
        $term = StellarData::get_term();
        $allTags = explode(",", $_COOKIE["mystellar"]);
        natsort($allTags);
    }
    $currentTags = array();
    $currentIds = array();
    $oldIds = array();
    foreach ($allTags as $classTag) {
        $parts = explode(" ", $classTag);
        if ($parts[1] == $term) {
            $currentTags[] = $classTag;
            $currentIds[] = $parts[0];
        } else {
            $oldIds[] = $parts[0];
        }
    }
    return (object) array("allTags" => $allTags, "currentTags" => $currentTags, "currentIds" => $currentIds, "oldIds" => $oldIds);
}
$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']);
      }
    }
  }
Esempio n. 3
0
<?php
$docRoot = getenv("DOCUMENT_ROOT");

require_once $docRoot . "/mobi-config/mobi_web_constants.php";
require_once WEBROOT . "page_builder/page_header.php";
require_once LIBDIR . "StellarData.php";
require_once WEBROOT . "stellar/stellar_lib.php";

$class_id = $_REQUEST['id'];
$class = StellarData::get_subject_info($class_id);
$term = StellarData::get_term_text();
$term_id = StellarData::get_term();

$tabs = new Tabs(selfURL(), 'tab', array('News', 'Info', 'Staff'));

$back = $_REQUEST['back'];

/* My Stellar actions */
$mystellar = getMyStellar()->allTags;
$class_data = $class_id . " " . $term_id;

if(in_array($class_data, $mystellar)) { 
  $toggle = "ms_on";
  $mystellar_img = 'mystellar-on';
  $action = 'remove';
} elseif (!in_array($class_data, $mystellar)) {
  $toggle = "ms_off";
  $mystellar_img = 'mystellar-off';
  $action = 'add';
}
    } else {
      $data = array('error' => 'SubjectNotFound', 'message' => 'Stellar could not find this subject'); 
    }
    break;

  case 'search':
    $query = urldecode($_REQUEST['query']);
    $data = StellarData::search_subjects($query);
    $term = StellarData::get_term();
    foreach($data as $index => $value) {
      $data[$index]['term'] = $term;
    }
    break;

  case 'term':
    $data = array('term' => StellarData::get_term());
    break;

  case 'myStellar':
    require_once 'push/apns_lib.php';
    $pass_key = intval($_REQUEST['pass_key']);
    $device_id = intval($_REQUEST['device_id']);       
    $device_type = $_REQUEST['device_type'];       
    $subject = $_REQUEST['subject'];
    $term = $_REQUEST['term'];

    if($device_type == 'apple') {
      if(!APNS_DB::verify_device_id($device_id, $pass_key)) {
	Throw new Exception("invalid {$pass_key} for {$device_id}");
      }
    } else {