Beispiel #1
0
 public function get()
 {
     $qadd = isset($_GET['a']) ? $_GET['a'] : '';
     print_r(OBFind::find_address($qadd));
     print_r(OBFind::parse_query('ob at ' . $qadd));
     print_r(OBFind::parse_query('Ob At 161 strathmore rd'));
     print_r(OBFind::parse_query('at ' . $qadd));
     print_r(OBFind::find('155 strathmore rd'));
     print_r(OBFind::find_tagged('ob', '155 strathmore rd'));
 }
Beispiel #2
0
 public static function init()
 {
     static $_initd = false;
     if ($_initd) {
         throw new Exception('Already initialized.');
     }
     spl_autoload_register(array('OBFind', 'autoload'));
     self::$libdir = defined(self::$const_prefix . 'LIBDIR') ? constant(self::$const_prefix . 'LIBDIR') : dirname(__FILE__);
     $dbconfig = array('dbhost', 'dbname', 'dbuser', 'dbpass');
     foreach ($dbconfig as $ci => $config) {
         if (defined('OBF_' . strtoupper($config))) {
             self::${$config} = constant('OBF_' . strtoupper($config));
         }
     }
     $dsn = sprintf('pgsql:host=%s;dbname=%s;user=%s;password=%s', self::$dbhost, self::$dbname, self::$dbuser, self::$dbpass);
     Rudb::connect($dsn);
     $_initd = true;
 }
Beispiel #3
0
 public function post()
 {
     $twreq = Twilio_Request::factory();
     if (!$twreq->check_signature(OBFind::TWILIO_AUTH_TOKEN)) {
         header('HTTP/1.1 403 Forbidden');
         throw new Exception('Invalid signature.');
     }
     $parsedq = OBFind::parse_query($twreq->msg_body);
     $qflag = $parsedq->tflag;
     $qadd = $parsedq->address;
     $qtag = $parsedq->tag ? $parsedq->tag : null;
     $qnum = $twreq->from;
     $last = false;
     if ($qnum && ($last = OBFind_Track::find($qnum))) {
         $last = (object) $last;
     }
     switch ($qflag) {
         case 'at':
             $loc = OBFind::find_address($qadd);
             if ($loc) {
                 $loc = $loc['approx_loc'];
                 if ($last) {
                     OBFind_Track::update($qnum, $qflag, $qadd, $loc, $qtag);
                 } else {
                     OBFind_Track::create($qnum, $qflag, $qadd, $loc, $qtag);
                 }
                 Twilio::send_sms($qnum, "ok: you're at {$qadd}");
             } else {
                 if (!$result) {
                     Twilio::send_sms($qnum, 'sorry. couldn\'t find that address (at).');
                 }
             }
             break;
         case 'near':
             $result = $qtag ? OBFind::find_tagged($qtag, $qadd) : OBFind::find($qadd);
             if (!$result) {
                 if (!OBFind::find_address($qadd)) {
                     Twilio::send_sms($qnum, 'sorry. couldn\'t find that address.');
                 } else {
                     Twilio::send_sms($qnum, 'found nothing nearby. try another address or start something new.');
                 }
             } else {
                 Twilio::send_sms($qnum, 'result 1: ' . $result);
             }
             if ($last) {
                 OBFind_Track::update($qnum, $qflag, $qadd, $qtag);
             } else {
                 OBFind_Track::create($qnum, $qflag, $qadd, $qtag);
             }
             break;
         case '?':
             if ($last) {
                 $result = $last->tag ? OBFind::find_tagged($last->tag, $qadd) : OBFind::find($last->address, $qadd);
                 if (!$result) {
                     Twilio::send_sms($qnum, 'sorry. couldn\'t find that address.');
                 }
                 if (!$result) {
                     if (!OBFind::find_address($qadd)) {
                         Twilio::send_sms($qnum, 'sorry. couldn\'t find that address.');
                     } else {
                         Twilio::send_sms($qnum, 'nothing else nearby. try another address or start something new.');
                     }
                 } else {
                     Twilio::send_sms($qnum, 'result ' . $qadd . ': ' . $result);
                 }
             } else {
                 Twilio::send_sms($qnum, 'no query. text "near <your address>".');
             }
             break;
         default:
             TWilio::send_sms('invalid command. text "near <your address>" to get started.');
             break;
     }
 }
Beispiel #4
0
<?php

if (getenv('OBF_LIBDIR')) {
    define('OBF_LIBDIR', getenv('OBF_LIBDIR'));
}
if (!defined('OBF_LIBDIR')) {
    die('Shit is all f****d up and bullshit: missing libdir.');
}
require_once OBF_LIBDIR . 'obfind.php';
OBFind::init();
try {
    Glue::stick(array('/' => 'obfind_handler_home', '/sms' => 'obfind_handler_sms'), '_obfind');
} catch (OBFindException $e) {
} catch (Exception $e) {
    header('HTTP/1.1 404 Not Found');
    die($e->getMessage());
}