1a107601fa490ca69215facceebe3d0dc5e7f1f86bcef0037bdb2d139a15065c3f31e872bae79df3
34
from r2.models import *
34
from r2.models import *
35
from errors import ErrorSet
35
from errors import ErrorSet
36
from validator import *
36
from validator import *
37
from r2.lib.template_helpers import reddit_link
37
from r2.lib.template_helpers import add_sr
38
from r2.lib.jsontemplates import api_type
38
from r2.lib.jsontemplates import api_type
39
 
39
 
40
from copy import copy
40
from copy import copy
...
 
...
 
105
    uname = c.user.name if c.user_is_loggedin else ""
105
    uname = c.user.name if c.user_is_loggedin else ""
106
    c.response.set_cookie(uname + '_' + name,
106
    c.response.set_cookie(uname + '_' + name,
107
                          value = val,
107
                          value = val,
108
                          domain = c.domain)
108
                          domain = g.domain)
109
 
109
 
110
def read_click_cookie():
110
def read_click_cookie():
111
    if c.user_is_loggedin:
111
    if c.user_is_loggedin:
...
 
...
 
129
        if not request.cookies.get("reddit_first"):
129
        if not request.cookies.get("reddit_first"):
130
            c.response.set_cookie("reddit_first", "first",
130
            c.response.set_cookie("reddit_first", "first",
131
                                  expires = NEVER,
131
                                  expires = NEVER,
132
                                  domain = c.domain)
132
                                  domain = g.domain)
133
            return True
133
            return True
134
    return False
134
    return False
135
 
135
 
...
 
...
 
146
    sr_name=request.environ.get("subreddit", request.params.get('r'))
146
    sr_name=request.environ.get("subreddit", request.params.get('r'))
147
 
147
 
148
    if not sr_name or sr_name == Default.name:
148
    if not sr_name or sr_name == Default.name:
149
        c.site = Default
149
        sub_domain = request.environ.get('sub_domain')
 
 
150
        sr = Subreddit._by_domain(sub_domain) if sub_domain else None
 
 
151
        c.site = sr or Default
150
    elif sr_name == 'r':
152
    elif sr_name == 'r':
151
        c.site = Sub
153
        c.site = Sub
152
    else:
154
    else:
...
 
...
 
191
        c.response_wrappers.append(utils.to_js)
193
        c.response_wrappers.append(utils.to_js)
192
    elif extension == 'mobile':
194
    elif extension == 'mobile':
193
        c.render_style = 'mobile'
195
        c.render_style = 'mobile'
 
 
196
    #Insert new extentions above this line
 
 
197
    elif extension not in ('', 'html'):
 
 
198
        dest = "http://%s%s" % (request.host, request.path)
 
 
199
        if request.get:
 
 
200
            dest += utils.query_string(request.get)
 
 
201
        redirect_to(dest)
194
 
202
 
195
def get_browser_langs():
203
def get_browser_langs():
196
    browser_langs = []
204
    browser_langs = []
...
 
...
 
252
    else:
260
    else:
253
        c.content_langs = c.user.pref_content_langs
261
        c.content_langs = c.user.pref_content_langs
254
 
262
 
 
 
263
def set_cnameframe():
 
 
264
    if (bool(request.params.get('cnameframe')) 
 
 
265
        or request.host.split(":")[0] != g.domain):
 
 
266
        c.cname = True
 
 
267
 
255
def ratelimit_agents():
268
def ratelimit_agents():
256
    user_agent = request.user_agent
269
    user_agent = request.user_agent
257
    for s in g.agents:
270
    for s in g.agents:
...
 
...
 
308
        key = ''.join((str(c.lang),
321
        key = ''.join((str(c.lang),
309
                       str(c.content_langs),
322
                       str(c.content_langs),
310
                       request.host,
323
                       request.host,
 
 
324
                       c.cname, 
311
                       request.fullpath,
325
                       request.fullpath,
312
                       str(c.firsttime),
326
                       str(c.firsttime),
313
                       str(c.over18)))
327
                       str(c.over18)))
...
 
...
 
367
        set_content_type()
381
        set_content_type()
368
        set_iface_lang()
382
        set_iface_lang()
369
        set_content_lang()
383
        set_content_lang()
 
 
384
        set_cnameframe()
370
 
385
 
371
        # check if the user has access to this subreddit
386
        # check if the user has access to this subreddit
372
        if not c.site.can_view(c.user):
387
        if not c.site.can_view(c.user):
373
            abort(403, "forbidden")
388
            abort(403, "forbidden")
374
 
389
 
375
        #check over 18
390
        #check over 18
376
        if c.site.over_18 and not c.over18:
391
        if c.site.over_18 and not c.over18 and not request.path == "/frame":
377
            d = dict(dest=reddit_link(request.path, url = True) + utils.query_string(request.GET))
392
            d = dict(dest=add_sr(request.path) + utils.query_string(request.GET))
378
            return redirect_to("/over18" + utils.query_string(d))
393
            return redirect_to("/over18" + utils.query_string(d))
379
 
394
 
380
        #check content cache
395
        #check content cache
...
 
...
 
425
    def check_modified(self, thing, action):
440
    def check_modified(self, thing, action):
426
        if c.user_is_loggedin:
441
        if c.user_is_loggedin:
427
            return
442
            return
428
 
443
        
429
        date = utils.is_modified_since(thing, action, request.if_modified_since)
444
        date = utils.is_modified_since(thing, action, request.if_modified_since)
430
        if date is True:
445
        if date is True:
431
            abort(304, 'not modified')
446
            abort(304, 'not modified')