diff --git a/activity.go b/activity.go index 53ee522..a79d397 100644 --- a/activity.go +++ b/activity.go @@ -700,6 +700,7 @@ func xonkxonk(user *WhatAbout, item junk.Junk, origin string) *Honk { p.Name = name p.Latitude, _ = tag["latitude"].(float64) p.Longitude, _ = tag["longitude"].(float64) + p.Url, _ = tag.GetString("url") log.Printf("place: %v", p) xonk.Place = p } @@ -931,6 +932,7 @@ func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) { t["name"] = p.Name t["latitude"] = p.Latitude t["longitude"] = p.Longitude + t["url"] = p.Url tags = append(tags, t) } if len(tags) > 0 { diff --git a/database.go b/database.go index f1ac6ac..16be546 100644 --- a/database.go +++ b/database.go @@ -251,7 +251,7 @@ func donksforhonks(honks []*Honk) { } rows.Close() // grab places - q = fmt.Sprintf("select honkid, name, latitude, longitude from places where honkid in (%s)", strings.Join(ids, ",")) + q = fmt.Sprintf("select honkid, name, latitude, longitude, url from places where honkid in (%s)", strings.Join(ids, ",")) rows, err = db.Query(q) if err != nil { log.Printf("error querying places: %s", err) @@ -261,7 +261,7 @@ func donksforhonks(honks []*Honk) { for rows.Next() { var hid int64 p := new(Place) - err = rows.Scan(&hid, &p.Name, &p.Latitude, &p.Longitude) + err = rows.Scan(&hid, &p.Name, &p.Latitude, &p.Longitude, &p.Url) if err != nil { log.Printf("error scanning place: %s", err) continue @@ -303,10 +303,10 @@ func saveextras(h *Honk) error { return err } } - if h.Place != nil { - _, err := stmtSavePlace.Exec(h.ID, h.Place.Name, h.Place.Latitude, h.Place.Longitude) + if p := h.Place; p != nil { + _, err := stmtSavePlace.Exec(h.ID, p.Name, p.Latitude, p.Longitude, p.Url) if err != nil { - log.Printf("error saving ont: %s", err) + log.Printf("error saving place: %s", err) return err } } @@ -419,7 +419,7 @@ func prepareStatements(db *sql.DB) { stmtSaveHonk = preparetodie(db, "insert into honks (userid, what, honker, xid, rid, dt, url, audience, noise, convoy, whofore, format, precis, oonker, flags) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") stmtDeleteHonk = preparetodie(db, "delete from honks where honkid = ?") stmtUpdateHonk = preparetodie(db, "update honks set precis = ?, noise = ?, format = ?, dt = ? where honkid = ?") - stmtSavePlace = preparetodie(db, "insert into places (honkid, name, latitude, longitude) values (?, ?, ?, ?)") + stmtSavePlace = preparetodie(db, "insert into places (honkid, name, latitude, longitude, url) values (?, ?, ?, ?, ?)") stmtDeletePlace = preparetodie(db, "delete from places where honkid = ?") stmtSaveOnt = preparetodie(db, "insert into onts (ontology, honkid) values (?, ?)") stmtDeleteOnts = preparetodie(db, "delete from onts where honkid = ?") diff --git a/honk.go b/honk.go index 72e2b35..27e2df9 100644 --- a/honk.go +++ b/honk.go @@ -92,6 +92,7 @@ type Place struct { Name string Latitude float64 Longitude float64 + Url string } type Honker struct { diff --git a/schema.sql b/schema.sql index 4da0db1..de50ab0 100644 --- a/schema.sql +++ b/schema.sql @@ -8,7 +8,7 @@ create table zonkers (zonkerid integer primary key, userid integer, name text, w create table doovers(dooverid integer primary key, dt text, tries integer, username text, rcpt text, msg blob); create table onts (ontology text, honkid integer); create table forsaken (honkid integer, precis text, noise text); -create table places (honkid integer, name text, latitude real, longitude real); +create table places (honkid integer, name text, latitude real, longitude real, url text); create index idx_honksxid on honks(xid); create index idx_honksconvoy on honks(convoy); diff --git a/upgradedb.go b/upgradedb.go index c541701..dc0a26b 100644 --- a/upgradedb.go +++ b/upgradedb.go @@ -188,8 +188,11 @@ func upgradedb() { case 19: doordie(db, "create table places (honkid integer, name text, latitude real, longitude real)") doordie(db, "create index idx_placehonkid on places(honkid)") - doordie(db, "update config set value = 20 where key = 'dbversion'") case 20: + doordie(db, "alter table places add column url text") + doordie(db, "update places set url = ''") + doordie(db, "update config set value = 21 where key = 'dbversion'") + case 21: default: log.Fatalf("can't upgrade unknown version %d", dbversion) } diff --git a/util.go b/util.go index 910f361..f4d6b3c 100644 --- a/util.go +++ b/util.go @@ -72,7 +72,7 @@ var dbtimeformat = "2006-01-02 15:04:05" var alreadyopendb *sql.DB var dbname = "honk.db" var stmtConfig *sql.Stmt -var myVersion = 20 +var myVersion = 21 func initdb() { schema, err := ioutil.ReadFile("schema.sql") diff --git a/views/honk.html b/views/honk.html index 3c24ee3..a4200bb 100644 --- a/views/honk.html +++ b/views/honk.html @@ -43,7 +43,7 @@ in reply to: {{ .RID }}

{{ .HTPrecis }}

{{ .HTML }} {{ with .Place }} -

Location: {{ .Name }} {{ .Latitude }} {{ .Longitude }} +

Location: {{ with .Url }}{{ end }}{{ .Name }}{{ if .Url }}{{ end }} {{ .Latitude }} {{ .Longitude }} {{ end }} {{ range .Donks }} {{ if .Local }} diff --git a/views/honkform.html b/views/honkform.html index d84b83e..08e2a07 100644 --- a/views/honkform.html +++ b/views/honkform.html @@ -13,6 +13,7 @@ description:

diff --git a/web.go b/web.go index 4705a67..9b54f44 100644 --- a/web.go +++ b/web.go @@ -1047,6 +1047,7 @@ func submithonk(w http.ResponseWriter, r *http.Request) { p.Name = placename p.Latitude, _ = strconv.ParseFloat(placelat, 64) p.Longitude, _ = strconv.ParseFloat(placelong, 64) + p.Url = r.FormValue("placeurl") honk.Place = p }