forked from newlisponrockets/newLISP-on-Rockets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrockets-comic.lsp
executable file
·95 lines (70 loc) · 3.87 KB
/
rockets-comic.lsp
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
#!/usr/bin/env newlisp
(load "newlisp-rockets.lisp") ; this is where the magic happens!
;; Rockets 2.0 - rockets-comic.html
;;
;; This is a view of comics. The idea is to have multiple comics based on tags.
;; First we get the whole list of comics, and then identify unique tags, then display
;; comic based on that tag in date order with prev/next and including comments.
(load "Rockets-config.lisp") ; load configuration information
(display-header RocketsConfig:Name)
(open-database RocketsConfig:Database)
(display-partial "rockets-checksignin") ; checks to see if user is signed in
(display-partial "rockets-common-functions") ; loads functions common to the blog but not part of Rockets
(set 'active-page "rockets-main")
(display-partial "rockets-navbar") ; shows the navigation bar with Rockets blog menus
; function to display a list of available comics
(define (display-comic-list)
; get the total list of comics
(set 'total-comics-list (query "Select DISTINCT PostTags from Posts WHERE PostType='Comic';"))
(if (nil? total-comics-list)
(displayln "<p><br><br>Sorry! You don't have any comics yet on this site. Try posting some!")
(begin
(displayln "<br><p> List of comics on this site: ")
(dolist (x total-comics-list)
(displayln "<p> <a href='rockets-comic.lsp?c=" (first x) "'><img src='images/" (first x) ".jpg'></a>")
(displayln "<p> <a href='rockets-comic.lsp?c=" (first x) "'>" (first x) "</a>"))
))
)
; function to display all comics in a series with forward/back/next/prev buttons
(define (display-comic comic-string comic-item)
(set 'comic-list (query (append "SELECT Id FROM Posts WHERE (PostType='Comic' AND PostTags='" comic-string "');")))
;get rid of inner lists inside list
(dolist (z comic-list)
(replace z comic-list (first z)))
(if comic-item ; if it's a specific comic display that one
(set 'display-list (first (query (append "SELECT * FROM Posts WHERE Id=" (string comic-item))))) ; otherwise display most recent
(set 'display-list (first (query (append "SELECT * FROM Posts WHERE Id=" (string (last comic-list)))))))
(set 'comic-title (display-list 3))
(set 'comic-text (display-list 4))
(set 'list-len (length comic-list))
(if comic-item
(set 'current-comic-num (int comic-item))
(set 'current-comic-num (last comic-list)))
(set 'current-comic-pos (int (first (ref current-comic-num comic-list))))
(displayln "<table border=0><tr><td width=200></td><td width=200>")
(if (> current-comic-pos 0)
(displayln "<p><a href='rockets-comic.lsp?c=" comic-string "&i=" (comic-list 0) "'><img src=images/nav-button-first.jpg></a>"))
(displayln "</td><td width=200>")
(if (> current-comic-pos 0)
(displayln "<a href='rockets-comic.lsp?c=" comic-string "&i=" (comic-list (- current-comic-pos 1)) "'><img src=images/nav-button-prev.jpg></a> "))
(displayln "</td><td width=200>")
(if (< current-comic-pos (- list-len 1))
(displayln "<a href='rockets-comic.lsp?c=" comic-string "&i=" (comic-list (+ current-comic-pos 1)) "'><img src=images/nav-button-next.jpg></a> "))
(displayln "</td><td width=200>")
(if (< current-comic-pos (- list-len 1))
(displayln "<a href='rockets-comic.lsp?c=" comic-string "&i=" (comic-list (- list-len 1)) "'><img src=images/nav-button-last.jpg>"))
(displayln "</td><td width=200></td></tr></table>")
(displayln "<br><br>")
(display-individual-post display-list true comic-item true) ; show comments but hide the headers (last parameter) for comic view
)
;--------------------------- page start
(set 'comic-type ($GET "c"))
(set 'comic-item (force-parameters 1 ($GET "i")))
;(if comic-type (displayln "Comic type:" comic-type))
; if we're requesting a specific comic, do that, otherwise display list
(if comic-type
(display-comic comic-type comic-item)
(display-comic-list))
(close-database)
(display-footer RocketsConfig:Owner)
(display-page) ; this is needed to actually display the page!