## 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-2012
## 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
   from r2.lib import tracking
   from pylons import request
   from r2.lib.strings import strings
   from r2.models import make_feedurl, Sub
%>
<%namespace file="login.html" import="login_panel, login_form"/>
<%namespace file="framebuster.html" import="framebuster"/>
<%namespace file="utils.html" import="tags, css_class"/>
<%inherit file="base.html"/>

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

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

  <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()">
  %if c.lang_rtl:
    <link rel="stylesheet" href="${static(g.stylesheet_rtl)}"
          type="text/css" />
    %if g.translator and request.get.get('css'):
      <link rel="stylesheet" href="${request.get.get('css')}"
            type="text/css" />
    %endif
    %if c.site.stylesheet_rtl:
      <link rel="stylesheet" href="${static(c.site.stylesheet_rtl)}"
            type="text/css" />
    %endif
  %else:
    <link rel="stylesheet" href="${static(g.stylesheet)}" 
          type="text/css" />
      %if c.site.stylesheet:
      <link rel="stylesheet" href="${static(c.site.stylesheet)}" 
            type="text/css" />
      %endif
  %endif

  %if c.can_apply_styles and c.allow_styles and c.site.stylesheet_contents:
     <% inline_stylesheet = (
          len(c.site.stylesheet_contents) < 1024
          and '<' not in c.site.stylesheet_contents) %>
     %if inline_stylesheet:
       ## for very simple stylesheets, we can just include them inline
       <style type="text/css" title="applied_subreddit_stylesheet">
           ${unsafe(c.site.stylesheet_contents)}
       </style>
     %else:
       <link rel="stylesheet"
             href="http://${get_domain(cname=False, subreddit=True)}/stylesheet.css?v=${c.site.stylesheet_hash}"
             title="applied_subreddit_stylesheet"
             type="text/css" />
     %endif
  %endif
  %if getattr(thing, "additional_css", None):
    <link rel="stylesheet" href="${static(thing.additional_css)}" 
          type="text/css" />
  %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="javascript()">
  <% from r2.lib import js %>
  ${unsafe(js.use('jquery', 'reddit'))}
  % if c.deny_frames:
    <script>if (window != top) top.location = window.location</script>
  % endif
</%def>

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

<%def name="bodyHTML()">
  <body ${tags(_class=' '.join(thing.page_classes()))}>
    <%include file="redditheader.html"/>
  
    %if thing.show_sidebar:
      <div class="side">
        ${sidebar(content = thing.rightbox())}
      </div>
    %endif
    
    %if thing.content:
      ##<div class="fixedwidth"><!--IE6sux--></div>
      ##<div class="clearleft"><!--IE6sux--></div>
      <a name="content"></a>
      <div ${tags(id=thing.content_id)} class="content${css_class(thing)}">
        ${thing.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">
            <h1 class="cover-msg">${strings.cover_msg}</h1>
            ${login_panel(login_form)}
            <div class="close-popup">
              <a href="#" onclick="return hidecover(this)">
                ${_("close this window")}
              </a>
            </div>
          </div>
        </div>
        %endif
        <div class="lang-popup cover-overlay" style="display: none">
          <div class="cover" onclick="return hidecover(this)"></div>
          <div class="popup">
            <%include file="prefoptions.html" />
            <div style="text-align:center; clear:both;">
              <a href="#" onclick="return hidecover(this)">
                ${_("close this window")}
              </a>
            </div>
          </div>
        </div>
      %endif
    %endif
    ${framebuster()}
  </body>
</%def>

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


