mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-05 03:00:15 -04:00
Move r.setup config data into a python dict.
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
################################################################################
|
||||
from r2.models import *
|
||||
from filters import unsafe, websafe
|
||||
from r2.lib.utils import vote_hash, UrlParser, timesince
|
||||
from r2.lib.utils import vote_hash, UrlParser, timesince, is_subdomain
|
||||
|
||||
from r2.lib.media import s3_direct_url
|
||||
|
||||
@@ -75,6 +75,42 @@ def s3_https_if_secure(url):
|
||||
replace = "https://%s/" % s3_direct_url
|
||||
return url.replace("http://", replace)
|
||||
|
||||
def js_config():
|
||||
config = {
|
||||
# is the user logged in?
|
||||
"logged": c.user_is_loggedin and c.user.name,
|
||||
# the subreddit's name (for posts)
|
||||
"post_site": c.site.name if not c.default_sr else "",
|
||||
# are we in an iframe?
|
||||
"cnameframe": bool(c.cname and not c.authorized_cname),
|
||||
# this page's referer
|
||||
"referer": request.referer or "",
|
||||
# the user's voting hash
|
||||
"modhash": c.modhash or False,
|
||||
# the current rendering style
|
||||
"renderstyle": c.render_style,
|
||||
# current domain
|
||||
"cur_domain": get_domain(cname=c.frameless_cname, subreddit=False, no_www=True),
|
||||
# where do ajax requests go?
|
||||
"ajax_domain": get_domain(cname=c.authorized_cname, subreddit=False),
|
||||
"extension": c.extension,
|
||||
"https_endpoint": is_subdomain(request.host, g.domain) and g.https_endpoint,
|
||||
# debugging?
|
||||
"debug": g.debug,
|
||||
"vl": {},
|
||||
"sr": {},
|
||||
"status_msg": {
|
||||
"fetching": _("fetching title..."),
|
||||
"submitting": _("submitting..."),
|
||||
"loading": _("loading...")
|
||||
},
|
||||
"is_fake": isinstance(c.site, FakeSubreddit),
|
||||
"tracking_domain": g.tracking_domain,
|
||||
"adtracker_url": g.adtracker_url,
|
||||
"clicktracker_url": g.clicktracker_url
|
||||
}
|
||||
return config
|
||||
|
||||
def generateurl(context, path, **kw):
|
||||
if kw:
|
||||
return path + '?' + '&'.join(["%s=%s"%(k, url_escape(v)) \
|
||||
|
||||
@@ -21,9 +21,10 @@
|
||||
################################################################################
|
||||
|
||||
<%!
|
||||
import json
|
||||
from r2.models import FakeSubreddit
|
||||
from r2.lib.filters import spaceCompress, unsafe
|
||||
from r2.lib.template_helpers import add_sr
|
||||
from r2.lib.template_helpers import add_sr, js_config
|
||||
from r2.lib.utils import cols, long_datetime, timesince
|
||||
from r2.lib.tracking import UserInfo
|
||||
%>
|
||||
@@ -375,46 +376,9 @@ ${unsafe(txt)}
|
||||
|
||||
|
||||
<%def name="js_setup()">
|
||||
<%
|
||||
from r2.lib.template_helpers import get_domain
|
||||
use_https_endpoint = request.host == g.domain or request.host.endswith("." + g.domain)
|
||||
%>
|
||||
<script type="text/javascript" id="config">
|
||||
r.setup({
|
||||
/* is the user logged in */
|
||||
logged: ${c.user_is_loggedin and ("'%s'" % c.user.name) or "false"},
|
||||
/* the subreddit's name (for posts) */
|
||||
post_site: "${c.site.name if not c.default_sr else ''}",
|
||||
/* are we in an iframe */
|
||||
cnameframe: ${"true" if (c.cname and not c.authorized_cname) else "false"},
|
||||
/* this page's referer */
|
||||
referer: "${request.referer or ""}",
|
||||
/* the user's voting hash */
|
||||
modhash: ${"'%s'" % c.modhash or "false"},
|
||||
/* the current rendering style */
|
||||
renderstyle: "${c.render_style}",
|
||||
/* current domain */
|
||||
cur_domain: "${get_domain(cname = c.frameless_cname, subreddit = False,
|
||||
no_www = True)}",
|
||||
/* where do ajax request go? */
|
||||
ajax_domain: "${get_domain(cname=c.authorized_cname, subreddit = False)}",
|
||||
extension: '${c.extension}',
|
||||
https_endpoint: '${g.https_endpoint if use_https_endpoint else ""}',
|
||||
/* debugging? */
|
||||
debug: ${"true" if g.debug else "false"},
|
||||
vl: {},
|
||||
sr: {},
|
||||
status_msg: {
|
||||
fetching: "${_('fetching title...')}",
|
||||
submitting: "${_('submitting...')}",
|
||||
loading: "${_('loading...')}"
|
||||
},
|
||||
is_fake: ${'true' if isinstance(c.site, FakeSubreddit) else 'false'},
|
||||
tracking_domain: '${g.tracking_domain}',
|
||||
adtracker_url: '${g.adtracker_url}',
|
||||
clicktracker_url: '${g.clicktracker_url}'
|
||||
})
|
||||
</script>
|
||||
<script type="text/javascript" id="config">
|
||||
r.setup(${unsafe(json.dumps(js_config()))})
|
||||
</script>
|
||||
</%def>
|
||||
|
||||
<%def name="googleanalytics(uitype)">
|
||||
|
||||
Reference in New Issue
Block a user