Source

reddish / reddish / templates / base.mako

Full commit
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
<%
self.new_window = literal(' target="_blank"') \
    if c.user is not None and c.user.prefs.new_window else ''
%>\
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title><%block name="title">${g.title}\
${' - ' + g.headline if g.headline else ''}</%block></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta name="description" content="\
<%block name="description" filter="h">${g.description}</%block>"/>
% if g.keywords:
<meta name="keywords" content="${g.keywords}"/>
% endif
<meta name="title" content="${self.title()}"/>
% if g.icon:
<link rel="icon" type="${g.icon_type}" href="${url(g.icon)}"/>
% endif
<link rel="stylesheet" type="text/css" href="${url(g.stylesheet)}"/>
</head>

<body>

% if g.debug:
<%!
JAVASCRIPT_FILES = (
    'jquery.js',
    'util.js',
    'json-form.js',
    'api.js',
    'edit.js',
    'ready.js',
)
%>
% for f in JAVASCRIPT_FILES:
<script type="text/javascript" src="${url('/script/' + f)}"></script>
% endfor
% else:
<script type="text/javascript" src="${url(g.script_name)}"></script>
% endif

<div id="report-form" class="report-form" style="display:none">
    <div>
        notify the moderators of a violation of the rules
    </div>
    <form class="json-form" method="post" action="/">
        <input type="hidden"/>
        <textarea name="report"></textarea><br/>
        <input type="submit" value="report"/>
        <button type="button" class="cancel">cancel</button>
        <span class="status"></span>
    </form>
</div>

<div id="header">
    <input type="hidden" name="token" id="token" value="${session.token or ''}"/>
    <div id="bar">
        <% subs = model.Community.get_subscribed(c.user) %>
        <span id="list-subscriptions">my communities</span>
        <a href="${url('/all')}">all</a>
        - <a href="${url('/random')}">random</a>
        % if c.user is not None and c.user.moderated:
        - <a href="${url('/communities/mine/moderator')}">mod</a>
        % endif
        |
    % for cmty, last in h.lookahead(subs):
        % if last:
        ${self.cmty_link(cmty)}
        % else:
        ${self.cmty_link(cmty)} -
        % endif
    % endfor
    </div>
    <div id="subscriptions" style="display:none">
    <ul>
    % for cmty in subs:
        <a href="${cmty.permalink}"><li>${cmty.name}</li></a>
    % endfor
        <a href="/communities"><li><em>edit subscriptions</em></li></a>
    </ul>
    </div>

    <a href="/"><div class="logo"></div></a>

    <span class="subtitle">
        <%block name="subtitle"/>
    </span>

    <div class="tabs">
        <%block name="tabs"/>
    </div>

    <div class="bottom-right">
% if c.user is None:
        <a href="${url('/login', secure = True)}">login or register</a>
% else:
        <a href="${url('/user/' + c.user.name)}" id="username">${c.user.name}</a> |
        % if c.user.admin:
        <a href="/admin-log">admin log</a> |
        % endif
        <% unread = c.user.unread_count() %>
        % if unread:
        <a href="${url('/message/unread')}" id="mail unread">inbox (${unread})</a> |
        % else:
        <a href="${url('/message/inbox')}" id="mail">inbox</a> |
        % endif
        % if c.user.moderated:
        <% mod_unread = c.user.mod_unread_count() %>
        %   if mod_unread:
        <a href="${url('/message/moderator/unread')}" id="modmail unread">mod inbox (${mod_unread})</a> |
        %   else:
        <a href="${url('/message/moderator')}" id="modmail">mod inbox</a> |
        %   endif
        % endif
        <a href="${url('/prefs')}" id="prefs">preferences</a> |
        <a href="#" id="logout">logout</a>
% endif
    </div>
</div>

<%block name="sidebar"/>

<div id="content">
    ${next.body(**context.kwargs)}

    % if c.num_items == -1 or c.num_items > c.prefs.n_items:
    <% n = c.prefs.n_items %>\
    more:
    %   if c.offset > 0:
    <a href="${url.current(offset = c.offset - n)}">prev</a> | \
    %   endif
    %   if c.num_items == -1 or c.num_items - c.offset > n:
    <a href="${url.current(offset = c.offset + n)}">next</a>
    %   else:
    next
    %   endif
    % endif
</div>

<div id="footer">
## TODO: Footer stuff
</div>

${self.google_analytics()}

</body>
</html>
<%def name="admin()">\
<a href="#" class="admin" title="${g.title} administrator">A</a>\
</%def>\
<%def name="author(u, item)">\
<%
tags = []
classes = ['author']

if isinstance(item, model.Post):
    post = item
else:
    post = item.get_post()

if u:
    if item.decoration == 'admin':
        classes.append('admin')
        # TODO: Some page about administrators
        tags.append(literal(capture(self.admin)))
    elif item.decoration == 'mod':
        classes.append('mod')
        cmty = item.get_community()
        tags.append(literal(capture(self.mod, cmty)))
    if u is not None and u is post.get_author() and post is not item:
        classes.append('op')
        tags.append(literal(capture(self.op, post)))
    if c.user is not None and u is not None and author is not c.user and c.user.has_friend(u):
        classes.append('friend')
        tags.append(literal('<a href="/friends" class="friend" title="friend">F</a>'))
%>\
% if u is None:
<span class="deleted">[deleted]</span>\
% else:
<a class="${' '.join(classes) | n}" href="/user/${u.name}">${u.name}</a>\
%   if tags:
 [${literal(',').join(tags)}]\
%   endif
% endif
</%def>\
<%def name="captcha()">\
% if g.enable_captcha:
<%def name="insert_captcha()">\
<% key = h.make_key() %>\
<img class="captcha" src="/captcha/${key}.png"/><br/>
<input type="hidden" class="captcha-key" name="captcha_key" value="${key}"/>
<input type="text" class="captcha-input" name="captcha"/>
</%def>\
${caller.body(insert_captcha)}
% endif
</%def>\
<%def name="checked(cond)">\
${' checked="checked"' if cond else ''}\
</%def>\
<%def name="cmty_link(cmty)">\
<a href="${cmty.permalink}">${cmty.name}</a>\
</%def>\
<%def name="confirm(text, cls, confirm_text = 'are you sure?')">\
<span class="confirm ${cls}">
    <a href="#" class="confirm-test">${text}</a>
    <span class="confirmation" style="display:none">
        ${confirm_text}
        <a href="#" class="${cls}">yes</a> / <a href="#" class="cancel">no</a>
    </span>
</span>
</%def>\
<%def name="decoration(typ, item)">\
<%
decorations_available = []
if c.user.admin:
    decorations_available.append(
        ('admin', literal('<span class="admin">A</span>')))
if c.user.true_moderator(item.get_community()):
    decorations_available.append(
        ('mod', literal('<span class="mod">M</span>')))
%>
        %  if decorations_available:
        <span class="decorate">
            <a href="#" class="decorate">decorate</a>
            <span style="display:none">
            <a href="#" class="cancel">cancel</a>
        %   for class_, text in decorations_available:
            <a href="#" title="${class_}" class="${typ}decorate-${class_}">${text}</a>
        %   endfor
            <a href="#" class="${typ}decorate-none">none</a>
            <span class="status"></span>
            </span>
        </span>
        % endif
</%def>\
<%def name="empty(cond)">\
% if not cond:
<div class="error">nothing</div>
% endif
</%def>\
<%def name="header()">\
<div class="collapsed" style="display:none">
    <a href="#" class="expand">[+]</a>
    ${caller.body()}
</div>
<div>
    <a href="#" class="collapse">[&ndash;]</a>
    ${caller.body()}
</div>
</%def>\
<%def name="google_analytics()">\
% if g.google_analytics:
<script type="text/javascript"><!--
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', '${g.google_analytics}']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
//--></script>
% endif
</%def>\
<%def name="hide(cond = True)">\
${' style="display:none"' if cond else '' | n}\
</%def>\
<%def name="edit_form(typ, _id, text)">\
<div class="edit" id="edit-${typ}-${_id}" style="display:none">
    <form class="edit-form" method="post" action="/api/edit-${typ}">
        <input type="hidden" name="${typ}" value="${_id}"/>
        <textarea name="text">${text}</textarea><br/>
        <input type="submit" value="save"/>
        <button type="button" class="cancel">cancel</button>
        <span class="status"></span>
    </form>
</div>
</%def>\
<%def name="markdown_help()">\
<table class="md md-help" style="display:none">
    <thead>
    <tr>
        <td>you type:</td>
        <td>you see:</td>
    </tr>
    </thead>
    <tr>
        <td>*italics*</td>
        <td><em>italics</em></td>
    </tr>
    <tr>
        <td>**bold**</td>
        <td><strong>bold</strong></td>
    </tr>
    <tr>
        <td>[link!](${url('/', qualified = True)})</td>
        <td><a href="${url('/', qualified = True)}">link!</a></td>
    </tr>
    <tr>
        <td>* item 1<br/>* item 2<br/>* item 3</td>
        <td><ul><li>item 1</li><li>item 2</li><li> item 3</li></ul></td>
    </tr>
    <tr>
        <td>&gt;quoted text</td>
        <td><blockquote>quoted text</blockquote></td>
    </tr>
    <tr>
        <td>~~strikethrough~~</td>
        <td><del>strikethrough</del></td>
    </tr>
    <tr>
        <td>super^script</td>
        <td>super<sup>script</sup></td>
    </tr>
</table>
</%def>\
<%def name="mod(cmty)">\
<a class="mod" title="moderator of ${cmty.permalink}" href="${cmty.permalink}/moderators">M</a>\
</%def>\
<%def name="nsfw()">\
<span title="Adult Content: Not Safe For Work">NSFW</span>\
</%def>\
<%def name="op(item)">\
<a href="${item.permalink}" title="original poster">OP</a>\
</%def>\
<%def name="tab(label, url, name = None)">\
<a href="${url}"${' class="tab-selected"' if c.active_tab == (name or label) else '' | n}>${label}</a>
</%def>\
<%def name="subtab(label, url, name = None)">\
<a href="${url}"${' class="tab-selected"' if c.active_subtab == (name or label) else '' | n}>${label}</a>
</%def>\
<%def name="selected(cond)">\
${' selected="selected"' if cond else ''}\
</%def>\
<%def name="show_ad()">\
% if g.google_ad_client:
<script type="text/javascript"><!--
google_ad_client = "${g.google_ad_client}";
google_ad_slot = "${g.google_ad_slot}";
google_ad_width = 300;
google_ad_height = 250;
//--></script>
<script type="text/javascript" src="//pagead2.googlesyndication.com/pagead/show_ads.js"></script>
% endif
</%def>\
<%def name="show_comment(comment, parent_rendered = False, can_reply = False, as_message = False)">\
<%
hilight = ' hilight' if comment is c.hilight_comment else ''
is_moderator = c.user and c.user.is_moderator(comment.get_community())
%>
<%def name="show_comment_header(comment, visible)">\
<div class="comment-header">
    % if visible:
    <a href="#" class="comment-collapse">[&ndash;]</a>
    % else:
    <a href="#" class="comment-expand">[+]</a>
    % endif
    % if comment.removed and not is_moderator:
    <span class="comment-author"><span class="deleted">[removed]</span></span>
    % else:
    <span class="comment-author">${self.author(comment.get_author(), comment)}</span>
    % endif
    ${h.ago(comment.created)}${'*' if comment.edited else '' | n}
    % if not visible:
    % if comment.num_children == 1:
    <a href="#" class="expand">(${comment.num_children} reply)</a>
    % elif comment.num_children:
    <a href="#" class="expand">(${comment.num_children} replies)</a>
    % endif
    % endif
</div>
</%def>\
<div class="comment" id="c-${comment._id}">
    % if c.cmty is None:
    %   if as_message:
    %       if comment.parents:
    <span class="message-subject">comment reply</span>
    %       else:
    <span class="message-subject">post reply</span>
    %       endif
    %   endif
    <% post = comment.get_post() %>
    <a href="${post.permalink}">${post.title}</a>
    by <span class="comment-author">${self.author(post.get_author(), post)}</span>
    in ${self.cmty_link(comment.get_community())}

    % endif
    <div class="comment-view comment-hidden" style="display:none">
        <div${' class="removed"' if is_moderator and comment.removed else '' | n}>
        ${show_comment_header(comment, False)}
        </div>
    </div>

    <div class="comment-view comment-visible">
        <div${' class="removed"' if is_moderator and comment.removed else '' | n}>
        ${show_comment_header(comment, True)}

        % if comment.deleted or (comment.removed and not is_moderator):
        <div class="comment-body md deleted${hilight}"></div>
        % else:
        <div class="comment-body md${hilight}">${h.markdown(comment.text)}</div>
        % endif
        <% is_author = comment.is_author(c.user) %>
        % if is_author:
        ${edit_form('comment', comment._id, comment.text)}
        % endif

        <div class="link-box">
            <a href="${comment.permalink}">permalink</a>
            % if c.cmty is None:
            <a href="${url(comment.permalink, context = 3)}">context</a>
            % else:
            %   if comment.parents:
            %       if parent_rendered:
            <a href="#c-${comment.parents[-1]}">parent</a>
            %       else:
            <a href="${model.Comment.get(comment.parents[-1]).permalink}">parent</a>
            %       endif
            %   endif
            % endif
            % if is_moderator:
            %   if comment.approved:
            approved by ${self.user(comment.get_approved())}
            ${self.confirm('remove', 'comment-remove')}
            %   elif comment.removed:
            ${self.confirm('approve', 'comment-approve')}
            <span>removed by ${self.user(comment.get_removed())}</span>
            %   else:
            ${self.confirm('remove', 'comment-remove')}
            %   endif
            % elif not (comment.deleted or comment.removed):
            <a href="#" class="comment-report">report</a>
            % endif
            % if can_reply:
            <a href="#" class="comment-reply">reply</a>
            % endif
            % if is_author:
            ${decoration('c', comment)}
            <a href="#" class="comment-edit">edit</a>
            % endif
            % if not comment.deleted and comment.can_delete(c.user):
            ${confirm('delete', 'comment-delete')}
            % endif
            % if comment.deleted and c.user and c.user.admin:
            <span><a href="#" class="comment-inspect">inspect</a>
                <span class="status"></span></span>
            % endif
            % if is_moderator and comment.num_reports:
            <a href="${comment.get_community().permalink + '/reports/comment/' + comment._id}"${self.new_window}>${comment.num_reports} reports</a>
            % endif
            % if as_message:
            <a href="#" class="mark-unread">mark unread</a>
            % endif
        </div>
        </div>

        <div class="comment-replies">
        <% replies = comment.replies %>
        % for r in replies:
        ${show_comment(r, True, can_reply)}
        % endfor
        % if parent_rendered and len(comment.replies) < comment.num_replies:
        <a href="${comment.permalink}">continue this thread</a>
        % endif
        </div>
    </div>
</div>
</%def>\
<%def name="show_community(cmty)">\
<div id="community-${cmty.name}" class="community${' removed' if cmty.banned else '' | n}">
    <a href="${cmty.permalink}">${cmty.title}</a> (${cmty.permalink})
    % if cmty.nsfw:
    <span class="nsfw">${self.nsfw()}</span>
    % endif

    <div class="desc">
        ${h.markdown(cmty.sidebar)}
    </div>
    <div>
        ${subscribe(cmty)}
    </div>
    <div>
        created ${h.ago(cmty.created)}
        by ${self.user(cmty.get_creator())}
    </div>
    <div class="link-box">
        % if c.user and c.user.admin:
        %   if cmty.banned:
        ${self.confirm('unban', 'community-unban')}
        <span>banned by ${self.user(cmty.get_banned_by())}</span>
        %   else:
        ${self.confirm('ban', 'community-ban')}
        %   endif
        %   if cmty.num_reports:
        <a href="/communities/reports/${cmty.name}">${cmty.num_reports} reports</a>
        %   endif
        % else:
        <a href="#" class="community-report">report</a>
        % endif
    </div>
</div>
</%def>\
<%def name="show_post(post, full = False)">\
<% is_moderator = c.user is not None and c.user.is_moderator(post.get_community()) %>
<div id="p-${post._id}" class="post${' removed' if is_moderator and post.removed else '' | n}">
    <a href="${post.link or post.permalink}" class="title"${self.new_window}>${post.title}</a>
    % if post.domain:
    <span class="domain">(<a href="/domain/${post.domain}">${post.domain}</a>)</span>
    % endif
    % if not full and post.text:

    <div class="clear:both"></div>
    <div class="post-expander">
        <a href="#" class="post-expand">[+]</a>
        <a href="#" class="post-collapse" style="display:none">[&ndash;]</a>
    </div>
    % endif

    <div class="post-line">
        submitted ${h.ago(post.created)} by
        <span class="post-author">${self.author(post.get_author(), post)}</span>
        % if c.cmty is None:
        <% cmty = post.get_community() %>
        to ${self.cmty_link(cmty)}
        % endif
    </div>

    <div class="link-box">
        % if post.nsfw:
        <span class="nsfw">${self.nsfw()}</span>
        % elif post.can_nsfw(c.user, True):
        <span class="nsfw" style="display:none">${self.nsfw()}</span>
        % endif
        <a href="${post.permalink}"${self.new_window}>\
% if post.num_comments:
${post.num_comments} comments\
% else:
comment\
% endif
</a>
        % if c.user is None or not c.user.has_saved(post):
        <a href="#" class="post-save">save</a>
        % else:
        <a href="#" class="post-unsave">unsave</a>
        % endif
        <% is_author = post.is_author(c.user) %>
        % if is_author:
        ${decoration('p', post)}
        %   if full:
        <a href="#" class="post-edit">edit</a>
        %   endif
        % endif
        % if not post.deleted and post.can_delete(c.user):
        ${confirm('delete', 'post-delete')}
        % endif

        % if is_moderator:
        %   if post.approved:
        approved by ${self.user(post.get_approved())}
        ${confirm('remove', 'post-remove')}
        %   elif post.removed:
        ${confirm('approve', 'post-approve')}
        removed by ${self.user(post.get_removed())}
        %   else:
        ${confirm('remove', 'post-remove')}
        %   endif
        % endif
        % if not (post.deleted or post.removed) and c.user and not is_author:
        <a href="#" class="post-report">report</a>
        % endif
        % if post.can_nsfw(c.user, not post.nsfw):
        %   if post.nsfw:
        ${confirm('sfw', 'post-mark-sfw')}
        %   else:
        ${confirm('nsfw', 'post-mark-nsfw')}
        %   endif
        % endif
        % if post.deleted and c.user and c.user.admin:
        <span><a href="#" class="post-inspect">inspect</a>
            <span class="status"></span></span>
        % endif
        % if is_moderator and post.num_reports:
        <a href="${post.get_community().permalink + '/reports/post/' + post._id}"${self.new_window}>${post.num_reports} reports</a>
        % endif
    </div>

    % if full:
    <div class="post-body md"${hide(not post.text)}>\
${h.markdown(post.text)}</div>
    %   if is_author:
    ${edit_form('post', post._id, post.text)}
    %   endif
    % else:
    <span class="status"></span>
    % endif
</div>
</%def>\
<%def name="show_report(r)">\
<%def name="show_report_header(r, visible)">\
<div class="report-header${' collapsed' if not visible else '' | n}"${self.hide(not visible)}>
    % if visible:
    <a href="#" class="collapse">[&ndash;]</a>
    % else:
    <a href="#" class="expand">[+]</a>
    % endif
    <% u = r.get_user() %>
    <a href="${url('/user/' + u.name)}" class="author">${u.name}</a>
    ${h.ago(r.created)}
</div>
</%def>\
<div class="report">
    ${show_report_header(r, False)}
    ${show_report_header(r, True)}

    <div class="report-body md">
        ${h.markdown(r.text)}
    </div>
</div>
</%def>\
<%def name="subscribe(cmty)">\
<% subscribed = c.user is not None and c.user.is_subscribed(cmty._id) %>
    <span id="subscribe-${cmty.name}"${hide(subscribed)}>
        <a href="#" class="subscribe">subscribe</a>
        ${cmty.num_subscribers - subscribed} subscribers</span>
    <span id="unsubscribe-${cmty.name}"${hide(not subscribed)}>
        <a href="#" class="unsubscribe">unsubscribe</a>
        ${cmty.num_subscribers + (not subscribed)} subscribers</span>
</%def>\
<%def name="user(u)">\
% if u is None:
<span class="deleted">[deleted]</span>\
% else:
<a href="/user/${u.name}">${u.name}</a>\
% endif
</%def>