Esempio n. 1
0
func pageBadgePage(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/html")
	id := strings.TrimSpace(r.FormValue("id"))
	if id != "" {
		doc, found := getDatabase().FindFullPackage(id)
		if !found {
			http.Error(w, fmt.Sprintf("Package %s not found!", id), http.StatusNotFound)
			return
		}
		badgeUrl := "http://go-search.org/badge?id=" + template.URLQueryEscaper(doc.Package)
		viewUrl := "http://go-search.org/view?id=" + template.URLQueryEscaper(doc.Package)

		htmlCode := fmt.Sprintf(`<a href="%s"><img src="%s" alt="GoSearch"></a>`, viewUrl, badgeUrl)
		mdCode := fmt.Sprintf(`[![GoSearch](%s)](%s)`, badgeUrl, viewUrl)

		if err := templates.ExecuteTemplate(w, "badgepage.html", struct {
			UIUtils
			gcse.HitInfo
			HTMLCode string
			MDCode   string
		}{
			HitInfo:  doc,
			HTMLCode: htmlCode,
			MDCode:   mdCode,
		}); err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
		}
	}
}
Esempio n. 2
0
func Example_escape() {
	const s = `"Fran & Freddie's Diner" <*****@*****.**>`
	v := []interface{}{`"Fran & Freddie's Diner"`, ' ', `<*****@*****.**>`}

	fmt.Println(template.HTMLEscapeString(s))
	template.HTMLEscape(os.Stdout, []byte(s))
	fmt.Fprintln(os.Stdout, "")
	fmt.Println(template.HTMLEscaper(v...))

	fmt.Println(template.JSEscapeString(s))
	template.JSEscape(os.Stdout, []byte(s))
	fmt.Fprintln(os.Stdout, "")
	fmt.Println(template.JSEscaper(v...))

	fmt.Println(template.URLQueryEscaper(v...))

	// Output:
	// &#34;Fran &amp; Freddie&#39;s Diner&#34; &lt;[email protected]&gt;
	// &#34;Fran &amp; Freddie&#39;s Diner&#34; &lt;[email protected]&gt;
	// &#34;Fran &amp; Freddie&#39;s Diner&#34;32&lt;[email protected]&gt;
	// \"Fran & Freddie\'s Diner\" \[email protected]\x3E
	// \"Fran & Freddie\'s Diner\" \[email protected]\x3E
	// \"Fran & Freddie\'s Diner\"32\[email protected]\x3E
	// %22Fran+%26+Freddie%27s+Diner%2232%3Ctasty%40example.com%3E

}
Esempio n. 3
0
func pageUpdate(w http.ResponseWriter, r *http.Request) {
	id := strings.TrimSpace(r.FormValue("id"))
	if id != "" {
		c := appengine.NewContext(r)
		updateDocInfo(c, id)

		http.Redirect(w, r, "view?id="+template.URLQueryEscaper(id), 302)
	}
}
Esempio n. 4
0
func TestHTMLEscape(t *testing.T) {
	const s = `"Fran & Freddie's Diner" <*****@*****.**>`
	v := []interface{}{`"Fran & Freddie's Diner"`, ' ', `<*****@*****.**>`}

	fmt.Println(template.HTMLEscapeString(s))
	template.HTMLEscape(os.Stdout, []byte(s))
	fmt.Fprint(os.Stdout, "")

	fmt.Println(template.JSEscapeString(s))
	fmt.Println(template.JSEscaper(v...))
	fmt.Println(template.URLQueryEscaper(v...))
}
Esempio n. 5
0
func pageView(w http.ResponseWriter, r *http.Request) {
	id := strings.TrimSpace(r.FormValue("id"))
	if id != "" {
		c := appengine.NewContext(r)
		ddb := NewCachedDocDB(c, "doc")
		var doc DocInfo
		err, exists := ddb.Get(id, &doc)
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}

		if !exists {
			fmt.Fprintf(w, `<html><body>No such entry!`)

			ent, _ := findCrawlingEntry(c, kindCrawlerPackage, id)
			if ent != nil {
				fmt.Fprintf(w, ` Scheduled to be crawled at %s`,
					ent.ScheduleTime.Format("2006-01-02 15:04:05"))
			} else {
				fmt.Fprintf(w, ` Not found yet!`)
			}
			fmt.Fprintf(w, ` Click to <a href="crawl?id=%s">crawl</a>.</body></html>`,
				template.URLQueryEscaper(id))
			return
		}

		if doc.StarCount < 0 {
			doc.StarCount = 0
		}

		var descHTML villa.ByteSlice
		godoc.ToHTML(&descHTML, doc.Description, nil)

		showReadme := len(doc.Description) < 10 && len(doc.ReadmeData) > 0

		err = templates.ExecuteTemplate(w, "view.html", struct {
			DocInfo
			DescHTML   template.HTML
			ShowReadme bool
		}{
			DocInfo:    doc,
			DescHTML:   template.HTML(descHTML),
			ShowReadme: showReadme,
		})
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
		}
	}
}
Esempio n. 6
0
func writeHTML(ctx data.Entry, dirname string) error {
	filename := strings.Replace(template.URLQueryEscaper(ctx.Translations[0].Language+"_"+ctx.Translations[0].Words[0].Written+".html"), "%", "X", -1)

	file, err := os.Create(filename)
	defer file.Close()
	if err != nil {
		return err
	}

	showme := struct {
		Title string
		Body  template.HTML
	}{
		ctx.Translations[0].Words[0].Written + ": " + ctx.Wordtype,
		template.HTML(""),
	}

	for _, translation := range ctx.Translations {
		showme.Body += template.HTML("<div class=\"word\"><div id=\"" + translation.Language + "\" class=\"wordheader\">" + translation.Language + "</div>\n<div class=\"definitions\">")
		for _, word := range translation.Words {
			showme.Body += template.HTML("<div class=\"definition\">" +
				template.HTMLEscapeString(word.Written))
			for _, sw := range word.Sources {
				showme.Body += template.HTML("<span class=\"source\">" +
					template.HTMLEscapeString(sw) + "</span>")
			}

			showme.Body += template.HTML("</div>")
			references = append(references, [3]string{translation.Language, word.Written, filename})
			found := false
			firstletter, _ := utf8.DecodeRuneInString(strings.ToLower(word.Written))
			for _, letter := range alphabet {
				if firstletter == letter {
					found = true
				}
			}
			if !found {
				alphabet = append(alphabet, firstletter)
			}
		}
		showme.Body += template.HTML("</div></div>")
	}

	err = tmpl.Execute(file, showme)
	if err != nil {
		return err
	}

	return nil
}
Esempio n. 7
0
/* http://xxx.xxx/?xxx=$text */
func Query(text interface{}) string {
	return template.URLQueryEscaper(fmt.Sprint(text))
}
Esempio n. 8
0
func LoginUrlFor(endpoint string, values ...string) string {
	return beego.UrlFor("AuthController.Login", ":returnurl", template.URLQueryEscaper(beego.UrlFor(endpoint, values...)))
}
Esempio n. 9
0
func (a *Api) WUI(c *gin.Context) {
	smss, errcode := a.getSms(c)
	if errcode > 0 {
		if errcode == 404 {
			c.HTML(404, "index.tmpl", gin.H{
				"NotFound": true,
			})
			return
		} else {
			c.AbortWithStatus(errcode)
		}
	}

	var err error
	var start, limit int64
	var sstart, slimit, q string
	q = c.Query("q")

	smscount := a.countSms(q)

	sstart = c.Query("start")
	slimit = c.Query("limit")

	if sstart == "" {
		start = 0
	} else {
		start, err = strconv.ParseInt(sstart, 10, 64)
		if err != nil {
			stringWebError(c, 400, "start must be an integer")
			return
		}
	}

	if slimit == "" {
		limit = 50
	} else {
		limit, err = strconv.ParseInt(slimit, 10, 64)
		if err != nil {
			stringWebError(c, 400, "limit must be an integer")
			return
		}
	}

	morePrev := start > 0
	moreNext := (start + limit) < int64(smscount)

	if q != "" {
		q = fmt.Sprintf("&q=%s", template.URLQueryEscaper(q))
	}

	log.Debugf("start: %v, limit %v, moreNext: %v, morePrev: %v, smsCount: %d", start, limit, moreNext, morePrev, smscount)

	for i := range smss {
		msg := smss[i].Message
		msg = template.HTMLEscapeString(msg)
		msg = strings.Replace(msg, "\n", "<br>", -1)
		smss[i].MessageHTML = template.HTML(msg)
	}

	c.HTML(200, "index.tmpl", gin.H{
		"SMS":       smss,
		"Count":     smscount,
		"MorePrev":  morePrev,
		"MoreNext":  moreNext,
		"Limit":     limit,
		"StartNext": start + limit,
		"StartPrev": start - limit,
		"Query":     template.URL(q),
	})
	return
}
Esempio n. 10
0
// EscapeURL escapes URLs using QueryEscapeString
func EscapeURL(s string) string {
	return got.URLQueryEscaper(s)
}
Esempio n. 11
0
	"ReviewGameCount": func(gameid string) (string, error) {
		count, err := Dal.GetReviewsGameCount(gameid)
		if err != nil {
			return "0", err
		}
		return strconv.Itoa(count), nil
	},
	"VideoGameCount": func(gameid string) (string, error) {
		count, err := Dal.GetGameVideosCount(gameid)
		if err != nil {
			return "0", err
		}
		return strconv.Itoa(count), nil
	},
	"URLQueryEscaper": func(s interface{}) (string, error) {
		return template.URLQueryEscaper(s), nil
	},
	"JSONify": func(s interface{}) (string, error) {
		js, err := json.Marshal(s)
		return string(js), err
	},
	"HTMLnewlines": func(s string) (template.HTML, error) {
		buf := bytes.NewBuffer(nil)
		lastind := 0
		for ind := StringIndexOf(s, "\n", lastind); ind >= 0; ind = StringIndexOf(s, "\n", ind+1) {
			fmt.Fprintln(buf, template.HTMLEscapeString(s[lastind:ind])+"<br/>")
			lastind = ind
		}
		return template.HTML(buf.String()), nil
	},
}
Esempio n. 12
0
/* ============================================================================================ */
func UrlEncode(str string) string {
	return template.URLQueryEscaper(str)
}
Esempio n. 13
0
// ScriptLink returns an html tag for a given file path
func ScriptLink(name string) template.HTML {
	if !strings.HasSuffix(name, ".js") {
		name = name + ".js"
	}
	return template.HTML(fmt.Sprintf(scriptTemplate, template.URLQueryEscaper(name)))
}
Esempio n. 14
0
// StyleLink returns an html tag for a given file path
func StyleLink(name string) template.HTML {
	if !strings.HasSuffix(name, ".css") {
		name = name + ".css"
	}
	return template.HTML(fmt.Sprintf(styleTemplate, template.URLQueryEscaper(name)))
}