Exemple #1
0
// Renders the example content including support for context sensitive
// text substitution.
func (c *exampleContent) Write(ctx context.Context, w io.Writer) (int, error) {
	e := c.Example
	wwwURL := fburl.URL{
		Env: rellenv.FbEnv(c.Context),
	}
	w = htmlwriter.New(w)
	tpl, err := template.New("example-" + e.URL).Parse(string(e.Content))
	if err != nil {
		// if template parsing fails, we ignore it. it's probably malformed html
		return fmt.Fprint(w, e.Content)
	}
	countingW := counting.NewWriter(w)
	err = tpl.Execute(countingW,
		struct {
			Rand     string // a random token
			RellFBNS string // the OG namespace
			RellURL  string // local http://www.fbrell.com/ URL
			WwwURL   string // server specific http://www.facebook.com/ URL
		}{
			Rand:     randString(10),
			RellFBNS: rellenv.FbApp(c.Context).Namespace(),
			RellURL:  c.Env.AbsoluteURL("/").String(),
			WwwURL:   wwwURL.String(),
		})
	if err != nil {
		// if template execution fails, we ignore it. it's probably malformed html
		return fmt.Fprint(w, e.Content)
	}
	return countingW.Count(), err
}
Exemple #2
0
func TestCustomAppID(t *testing.T) {
	t.Parallel()
	values := url.Values{}
	values.Add("appid", "123")
	_, ctx := fromValues(t, values)
	ensure.DeepEqual(t, rellenv.FbApp(ctx).ID(), uint64(123))
}
Exemple #3
0
// Create a new Object from query string data.
func (p *Parser) FromValues(ctx context.Context, env *rellenv.Env, values url.Values) (*Object, error) {
	object := &Object{
		context: ctx,
		env:     env,
		static:  p.Static,
	}
	for key, values := range values {
		if strings.Contains(key, ":") {
			for _, value := range values {
				object.AddPair(key, value)
			}
		}
	}

	if object.shouldGenerate("og:url") {
		copiedValues := copyValues(values)
		copiedValues.Del("og:type")
		copiedValues.Del("og:title")
		url := url.URL{
			Scheme:   env.Scheme,
			Host:     env.Host,
			Path:     "/og/" + object.Type() + "/" + object.Title(),
			RawQuery: sortedEncode(copiedValues),
		}
		object.AddPair("og:url", url.String())
	}

	ogType := object.Type()
	isGlobalOGType := !strings.Contains(ogType, ":")
	isOwnedOGType := strings.HasPrefix(ogType, rellenv.FbApp(ctx).Namespace()+":")
	if object.shouldGenerate("fb:app_id") && (isGlobalOGType || isOwnedOGType) {
		object.AddPair("fb:app_id", strconv.FormatUint(rellenv.FbApp(ctx).ID(), 10))
	}

	err := object.generateDefaults()
	if err != nil {
		return nil, err
	}
	return object, nil
}
Exemple #4
0
func (e *contextEditor) HTML(ctx context.Context) (h.HTML, error) {
	if !rellenv.IsEmployee(e.Context) {
		return h.HiddenInputs(e.Env.Values()), nil
	}
	return &h.Div{
		Class: "well form-horizontal",
		Inner: h.Frag{
			&ui.TextInput{
				Label:      h.String("Application ID"),
				Name:       "appid",
				Value:      rellenv.FbApp(e.Context).ID(),
				InputClass: "input-medium",
				Tooltip:    "Make sure the base domain in the application settings for the specified ID allows fbrell.com.",
			},
			&ui.ToggleGroup{
				Inner: h.Frag{
					&ui.ToggleItem{
						Name:        "init",
						Checked:     e.Env.Init,
						Description: h.String("Automatically initialize SDK."),
						Tooltip:     "This controls if FB.init() is automatically called. If off, you'll need to call it in your code.",
					},
					&ui.ToggleItem{
						Name:        "status",
						Checked:     e.Env.Status,
						Description: h.String("Automatically trigger status ping."),
						Tooltip:     "This controls the \"status\" parameter to FB.init.",
					},
					&ui.ToggleItem{
						Name:        "frictionlessRequests",
						Checked:     e.Env.FrictionlessRequests,
						Description: h.String("Enable frictionless requests."),
						Tooltip:     "This controls the \"frictionlessRequests\" parameter to FB.init.",
					},
				},
			},
			&h.Div{
				Class: "form-actions",
				Inner: h.Frag{
					&h.Button{
						Type:  "submit",
						Class: "btn btn-primary",
						Inner: h.Frag{
							&h.I{Class: "icon-refresh icon-white"},
							h.String(" Update"),
						},
					},
				},
			},
		},
	}, nil
}
Exemple #5
0
func (a *Handler) Start(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
	c, err := rellenv.FromContext(ctx)
	if err != nil {
		return err
	}
	values := url.Values{}
	values.Set("client_id", strconv.FormatUint(rellenv.FbApp(ctx).ID(), 10))
	if scope := r.FormValue("scope"); scope != "" {
		values.Set("scope", scope)
	}

	if c.ViewMode == rellenv.Website {
		values.Set("redirect_uri", redirectURI(c))
		values.Set("state", a.state(w, r))
	} else {
		values.Set("redirect_uri", c.ViewURL("/auth/session"))
	}

	dialogURL := fburl.URL{
		Scheme:    "https",
		SubDomain: fburl.DWww,
		Env:       rellenv.FbEnv(ctx),
		Path:      "/dialog/oauth",
		Values:    values,
	}

	if c.ViewMode == rellenv.Website {
		http.Redirect(w, r, dialogURL.String(), 302)
	} else {
		b, _ := json.Marshal(dialogURL.String())
		_, err := h.Write(ctx, w, &h.Script{
			Inner: h.Unsafe(fmt.Sprintf("top.location=%s", b)),
		})
		return err
	}
	return nil
}
Exemple #6
0
Fichier : og.go Projet : daaku/rell
// Render a document for the Object.
func renderObject(ctx context.Context, env *rellenv.Env, s *static.Handler, o *og.Object) h.HTML {
	var title, header h.HTML
	if o.Title() != "" {
		title = &h.Title{h.String(o.Title())}
		header = &h.H1{
			Inner: &h.A{
				HREF:  o.URL(),
				Inner: h.String(o.Title()),
			},
		}
	}
	return &h.Document{
		Inner: h.Frag{
			&h.Head{
				Inner: h.Frag{
					&h.Meta{Charset: "utf-8"},
					title,
					&static.LinkStyle{
						HREF: view.DefaultPageConfig.Style,
					},
					renderMeta(o),
				},
			},
			&h.Body{
				Class: "container",
				Inner: h.Frag{
					&h.Div{ID: "fb-root"},
					view.DefaultPageConfig.GA,
					&fb.Init{
						URL:   env.SdkURL(),
						AppID: rellenv.FbApp(ctx).ID(),
					},
					&h.Div{
						Class: "row",
						Inner: h.Frag{
							&h.Div{
								Class: "span8",
								Inner: header,
							},
							&h.Div{
								Class: "span4",
								Inner: &h.A{
									Class: "btn btn-info pull-right",
									HREF:  o.LintURL(),
									Inner: h.Frag{
										&h.I{Class: "icon-warning-sign icon-white"},
										h.String(" Debugger"),
									},
								},
							},
						},
					},
					&h.Div{
						Class: "row",
						Inner: h.Frag{
							&h.Div{
								Class: "span6",
								Inner: h.Frag{
									renderMetaTable(o),
									&h.Iframe{
										Class: "like",
										Src:   o.LikeURL(),
									},
								},
							},
							&h.Div{
								Class: "span6",
								Inner: &h.A{
									HREF: o.ImageURL(),
									Inner: &h.Img{
										Src: o.ImageURL(),
										Alt: o.Title(),
									},
								},
							},
						},
					},
				},
			},
		},
	}
}