## The contents of this file are subject to the Common Public Attribution
## License Version 1.0. (the "License"); you may not use this file except in
## compliance with the License. You may obtain a copy of the License at
## http://code.reddit.com/LICENSE. The License is based on the Mozilla Public
## License Version 1.1, but Sections 14 and 15 have been added to cover use of
## software over a computer network and provide for limited attribution for the
## Original Developer. In addition, Exhibit A has been modified to be
## consistent with Exhibit B.
##
## Software distributed under the License is distributed on an "AS IS" basis,
## WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
## the specific language governing rights and limitations under the License.
##
## The Original Code is reddit.
##
## The Original Developer is the Initial Developer.  The Initial Developer of
## the Original Code is reddit Inc.
##
## All portions of the code written by reddit are Copyright (c) 2006-2013
## reddit Inc. All Rights Reserved.
###############################################################################

<%! 
   from r2.lib.template_helpers import add_sr, static, join_urls, class_dict, get_domain
   from r2.lib.filters import unsafe
   from r2.lib.pages import SearchForm, ClickGadget, SideContentBox, Login
   from r2.lib import tracking
   from pylons import request
   from r2.lib.strings import strings
   from r2.models import make_feedurl, Sub
%>
<%namespace file="framebuster.html" import="framebuster"/>
<%namespace file="less.html" import="less_js, less_stylesheet"/>
<%namespace file="utils.html" import="tags, classes"/>
<%namespace file="adminbar.html" import="adminbar_stylesheet"/>
<%inherit file="base.html"/>

<%def name="Title()">
  %if thing.title:
    ${thing.title}
  %else:
    ${parent.Title()}
  %endif
</%def>

<%def name="global_stylesheets()">
  %if c.lang_rtl:
    <link rel="stylesheet" href="${static(g.stylesheet_rtl)}"
          type="text/css" />
    %if c.site.stylesheet_rtl:
      <link rel="stylesheet" href="${static(c.site.stylesheet_rtl)}"
            type="text/css" />
    %endif
  %else:
    ${less_stylesheet(g.stylesheet)}
    %if c.site.stylesheet:
    <link rel="stylesheet" href="${static(c.site.stylesheet)}"
          type="text/css" >
    %endif
  %endif

  <!--[if lt IE 7]>
    <link rel="stylesheet" href="${static('reddit-ie6-hax.css')}"
          type="text/css" />
  <![endif]-->

  <!--[if lt IE 8]>
    <link rel="stylesheet" href="${static('reddit-ie7-hax.css')}"
          type="text/css" />
  <![endif]-->
</%def>

<%def name="sr_stylesheets()">
  %if c.can_apply_styles and c.allow_styles and c.site.stylesheet_hash:
    <link rel="stylesheet"
          href="${c.site.stylesheet_url}"
          title="applied_subreddit_stylesheet"
          type="text/css">
  %endif
</%def>

<%def name="extra_stylesheets()">
  ${adminbar_stylesheet()}
  %for extra_stylesheet in getattr(thing, 'extra_stylesheets', ()):
    ${less_stylesheet(extra_stylesheet)}
  %endfor
</%def>

<%def name="pagemeta()">
  %if hasattr(thing, "shortlink"):
    <link rel="shorturl" href="http://${thing.shortlink}"/>
  %endif

  <link rel='icon' href="${static('icon.png')}" sizes="256x256" type="image/png" />
  <link rel='shortcut icon' href="${static('favicon.ico')}" type="image/x-icon" />
  <link rel='apple-touch-icon-precomposed' href="${static('icon-touch.png')}" />
  %if thing.extension_handling:
    <%
       rss = add_sr(join_urls(request.path,'.rss'))
       if thing.extension_handling == "private":
          rss = make_feedurl(c.user, rss)
     %>
    <link rel="alternate" type="application/rss+xml" title="RSS"
          href="${rss}" />
  %endif
</%def>

<%def name="stylesheet()">
  ${self.global_stylesheets()}
  ${self.sr_stylesheets()}
  ${self.extra_stylesheets()}
</%def>

<%def name="javascript()">
  <% from r2.lib import js %>
  ${unsafe(js.use('jquery', 'reddit-init'))}
  % if c.deny_frames:
    <script>if (window != top) top.location = window.location</script>
  % endif
  <!--[if lt IE 9]>
    ${unsafe(js.use('html5shiv'))}
  <![endif]-->
  ${less_js()}
</%def>

<%def name="javascript_bottom()">
  <% from r2.lib import js %>
  ${unsafe(js.use('reddit'))}
  ${unsafe(c.js_preload.use())}
</%def>

<%def name="javascript_run()">
   reddit.cur_site = "${c.site._fullname if hasattr(c.site, '_fullname') else ''}";
</%def>

<%def name="bodyContent()">
  <%include file="adminbar.html"/>
  <%include file="redditheader.html"/>

  %if thing.show_sidebar:
    <div class="side">
      ${sidebar(content = thing.rightbox())}
    </div>
  %endif

  <% content = getattr(self, "content", None) or thing.content %>
  %if content:
    ##<div class="fixedwidth"><!--IE6sux--></div>
    ##<div class="clearleft"><!--IE6sux--></div>
    <a name="content"></a>
    <div ${tags(id=thing.content_id)} ${classes("content", thing.css_class)} role="main">
      ${content()}
    </div>
  %endif

  %if thing.footer:

    ${thing.footer}

    %if not c.user_is_loggedin and not g.read_only_mode:
      %if thing.enable_login_cover:
      <div class="login-popup cover-overlay" style="display: none">
        <div class="cover" onclick="return hidecover(this)"></div>
        <div class="popup">
          <a href="#" onclick="return hidecover(this)" class="hidecover">
            ${_("close this window")}
          </a>
          <h1 class="cover-msg">${strings.cover_msg}</h1>
          ${Login(is_popup=True)}
        </div>
      </div>
      %endif
      <div class="lang-popup cover-overlay" style="display: none">
        <div class="cover" onclick="return hidecover(this)"></div>
        <div class="popup">
          <a href="#" onclick="return hidecover(this)" class="hidecover">
            ${_("close this window")}
          </a>
          <%include file="prefoptions.html" />
        </div>
      </div>
    %endif
  %endif
  ${framebuster()}
  <p class="bottommenu debuginfo"><span class="icon">&pi;</span>&nbsp;<span class="content">Rendered by PID ${g.reddit_pid} on ${g.reddit_host} at ${c.start_time} running ${g.short_version}.</span></p>
</%def>

<%def name="sidebar(content=None)">
  ${content}
</%def>


