def get_inject_template(): script_urls = js.src("comment-embed", absolute=True, mangle_name=False) scripts = "".join('<script%s src="%s"></script>' % ( ' async' if len(script_urls) == 1 else '', script_url ) for script_url in script_urls) return _COMMENT_EMBED_TEMPLATE + scripts
def get_inject_template(omitscript=False): template = _COMMENT_EMBED_TEMPLATE if not omitscript: script_urls = js.src("comment-embed", absolute=True, mangle_name=False) scripts = "".join( '<script%s src="%s"></script>' % (' async' if len(script_urls) == 1 else '', script_url) for script_url in script_urls) template += scripts return template
def js_config(extra_config=None): logged = c.user_is_loggedin and c.user.name user_id = c.user_is_loggedin and c.user._id gold = bool(logged and c.user.gold) controller_name = request.environ['pylons.routes_dict']['controller'] action_name = request.environ['pylons.routes_dict']['action'] mac = hmac.new(g.secrets["action_name"], controller_name + '.' + action_name, hashlib.sha1) verification = mac.hexdigest() config = { # is the user logged in? "logged": logged, # logged in user's id "user_id": user_id, # the subreddit's name (for posts) "post_site": c.site.name if not c.default_sr else "", # the user's voting hash "modhash": c.modhash or False, # the current rendering style "renderstyle": c.render_style, # they're welcome to try to override this in the DOM because we just # disable the features server-side if applicable 'store_visits': gold and c.user.pref_store_visits, # 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), "stats_domain": g.stats_domain or '', "stats_sample_rate": g.stats_sample_rate or 0, "extension": c.extension, "https_endpoint": is_subdomain(request.host, g.domain) and g.https_endpoint, # does the client only want to communicate over HTTPS? "https_forced": c.user.https_forced, # debugging? "debug": g.debug, "send_logs": g.live_config["frontend_logging"], "server_time": math.floor(time.time()), "status_msg": { "fetching": _("fetching title..."), "submitting": _("submitting..."), "loading": _("loading...") }, "is_fake": isinstance(c.site, FakeSubreddit), "adtracker_url": g.adtracker_url, "clicktracker_url": g.clicktracker_url, "uitracker_url": g.uitracker_url, "eventtracker_url": g.eventtracker_url, "anon_eventtracker_url": g.anon_eventtracker_url, "comment_embed_scripts": js.src("comment-embed", absolute=True, mangle_name=False), "static_root": static(''), "over_18": bool(c.over18), "new_window": bool(c.user.pref_newwindow), "vote_hash": c.vote_hash, "gold": gold, "has_subscribed": logged and c.user.has_subscribed, "is_sponsor": logged and c.user_is_sponsor, "pageInfo": { "verification": verification, "actionName": controller_name + '.' + action_name, }, } if g.uncompressedJS: config["uncompressedJS"] = True if extra_config: config.update(extra_config) hooks.get_hook("js_config").call(config=config) return config