public function init() { spl_autoload_register(array(__CLASS__, 'autoload')); self::$libdir = FILETHIS_LIBDIR; self::$datdir = FILETHIS_DATDIR; self::$confdir = FILETHIS_CONFDIR; self::load_conf('filethis'); if (self::conf('filethis', 'data_dir')) { self::$datdir = self::conf('filethis', 'data_dir'); } self::load_conf('db'); $dbconf = self::conf('db'); if (!$dbconf) { throw new Exception('DB not configured.'); } $dsn = sprintf('pgsql:host=%s;dbname=%s;user=%s;password=%s', $dbconf->host, $dbconf->name, $dbconf->user, $dbconf->password); Rudb::connect($dsn); self::load_conf('twilio'); }
public function usedb($nm) { self::$_using = $nm; return true; }
public static function delete($num) { $sql = 'delete from track where sid=?'; return Rudb::query($sql, self::hashnum($num)); }
public static function find_tagged($tag, $add, $num = 1) { $r = self::find_address($add); if ($r) { $r = (object) $r; } else { return false; } $o = (int) $num - 1; $c = Rudb::connection(); $sql = 'select t.address as address, ST_AsText(t.location) as loc,' . ' ST_Distance(' . ' ST_Transform(t.location,3857),' . ' ST_Transform(ST_GeometryFromText(' . $c->quote($r->approx_loc) . ',4326),3857)) as dist' . ' from track t' . ' where t.tag = ? and t.tflag = \'at\'' . ' order by dist asc limit 1'; if ($o) { $sql .= ' offset ' . $o; } $r = Rudb::get_one($sql, $tag); if ($r) { $r = $r['address']; } return $r; }