diff options
| author | yo mama <pepper@scannerjammer.com> | 2015-02-13 01:33:31 -0800 |
|---|---|---|
| committer | yo mama <pepper@scannerjammer.com> | 2015-02-13 01:33:31 -0800 |
| commit | 4100860d10e2fb015db01d22bbf3f4735bcf10ec (patch) | |
| tree | 995b51fe3f8a6fe7fb58938c83463f3b09b5ee7c /impattern/im/cgi-bin/gallery.cgi | |
first
Diffstat (limited to 'impattern/im/cgi-bin/gallery.cgi')
| -rwxr-xr-x | impattern/im/cgi-bin/gallery.cgi | 474 |
1 files changed, 474 insertions, 0 deletions
diff --git a/impattern/im/cgi-bin/gallery.cgi b/impattern/im/cgi-bin/gallery.cgi new file mode 100755 index 0000000..0f762eb --- /dev/null +++ b/impattern/im/cgi-bin/gallery.cgi @@ -0,0 +1,474 @@ +#!/usr/bin/python +import os +import cgi +import re + +import random + +import db +db = db.db() + +BASE_HREF = "http://i.asdf.us/im/" +PARAMLIST = "addr start limit name interface random" +LIMIT = 20 + +def get_params (paramlist): + paramkeys = paramlist.split() + form = {} + try: + qs = os.environ['QUERY_STRING'] + except: + qs = "" + if len(qs): + pairs = qs.replace("&", "&").split("&") + for pair in pairs: + k,v = pair.split("=", 1) + form[k] = v + params = {} + for key in paramkeys: + if key in form: + params[key] = sanitize(form[key]) + else: + params[key] = None + return params +def sanitize (str): + return re.sub(r'\W+', '', str) +def get_files (params): + sql = "SELECT * FROM im_cmd " + args = [] + where = [] + + if params['start'] is not None: + where.append("id < %s") + args.append(params['start']) + if params['name'] is not None: + where.append("name=%s") + args.append(params['name']) + if len(where): + sql += "WHERE " + sql += " AND ".join(where) + sql += " " + + if params['random'] is not None: + sql += "ORDER BY RAND() " + else: + sql += "ORDER BY id DESC " + sql += "LIMIT %s" + + if params['limit'] is not None: + args.append( int(params['limit']) ) + else: + args.append( LIMIT ) + db.execute(sql, args) + rows = db.cursor.fetchall () + return rows + +def is_image (img): + if "jpeg" in img: + return True + if "jpg" in img: + return True + if "gif" in img: + return True + if "png" in img: + return True + return False + + +params = get_params(PARAMLIST) + +titlephrase = random.choice([ + 'Keep on pickin\' on..', + 'Pickolaus Pickleby by Charles Pickens!', + 'You pick potato and I pick potahto...', + 'Take your piq!', + 'Show em what you got', + 'I sure know how to pick \'em', + 'Jus pick somethin already!', + 'You can\'t pick your friends...', + 'Select your image my liege', + 'There\'s a time to choose...', + 'gimme a choice! gimme lil\' choice-a-that...', + 'You choose you lose', + 'novels by James CHOICE...', + 'Choose away, chooser-man...', + ]) + +print "Content-type: text/html" +print "Pragma: no-cache" +print +print """ + +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> +<head> +""" +print "<title>"+titlephrase+"</title>" +print""" +<style type="text/css"> +html,body{width:100%;height:100%;} + """ +if params['interface'] is not None and params['interface'] == "off": + print """ +body + { + background-color: white; + padding: 0; margin: 0; + } +#images + { + margin: 12px 0 0 8px; + } +div, div img + { + padding: 0; margin: 0; + margin-left: -4px; + margin-top: -4px; + } +""" +else: + print """ +body + { + background-color: #eee; + background-image: -webkit-gradient( linear, left bottom, left top, color-stop(0.32, rgb(245,238,235)), color-stop(0.66, rgb(252,252,252))); + background-image: -moz-linear-gradient( center bottom, rgb(245,238,235) 32%, rgb(252,252,252) 66%); overflow-y: scroll; + } +""" +print """ +html + { + padding-bottom: 200px; + } +#images + { + width: 100%; + } +#images div + { + width: 200px; + display: inline-block; + } +div img + { + max-width: 200px; + max-height: 200px; + border: 0; + } +#dump + { + position: fixed; + left: 0; + bottom: 10px; + padding: 10px; + width: 100%; + border-bottom: 2px solid #000; + background-color: #f8f8f8; + border-top: 1px solid #888; + } +#dump #rebus + { + clear: right; + width: 90%; + max-height: 700px; + overflow-y: scroll; + background-color: #fff; + padding-bottom: 5px; + border-bottom: 1px solid #ddd; + margin-bottom: 5px; + } +#dump #rebus img + { + display: inline; + max-width: 400px; + max-height: 400px; + margin-right: -4px; + } +#dump #urlz + { + width: 90%; + font-size: 15px; + } +#help + { + position: fixed; + top: 10px; + right: 10px; + cursor: pointer; + text-align: right; + font-family: sans-serif; + } +#help b + { + padding: 5px; + background-color: #f8f4fb; + display: block; + max-width: 160px; + text-align: right; + } +#help b:hover + { + color: cyan; + + } +#help #keys + { + clear: both; + background-color: #f8f8f8; + padding: 5px; + display: none; + width: 120px; + font-size: 12px; + } +#nextpage + { + position: fixed; + right: 160px; + font-family: sans-serif; + top: 10px; + padding: 5px; + background-color: rgba(255,255,255,0.7); + } +#nextpage a + { + color: #33f; + } +.rtlink + { + display: block; + width: 100%; + text-align: right; + } +#d_clip_container + { + display: inline-block; + } +#d_clip_button, #clear + { + font-family: Lucida Sans Unicode, Lucida Grande, sans-serif; + color: #333; + font-size: 13px; + line-height: 13px; + text-align: center; + margin: 2px; padding: 5px; + display: inline-block; + border-top: 1px solid #888; + border-left: 1px solid #888; + border-right: 1px solid #555; + border-bottom: 1px solid #333; + background-image: linear-gradient(bottom, rgb(235,235,235) 0%, rgb(250,250,250) 53%); + background-image: -o-linear-gradient(bottom, rgb(235,235,235) 0%, rgb(250,250,250) 53%); + background-image: -moz-linear-gradient(bottom, rgb(235,235,235) 0%, rgb(250,250,250) 53%); + background-image: -webkit-linear-gradient(bottom, rgb(235,235,235) 0%, rgb(250,250,250) 53%); + background-image: -ms-linear-gradient(bottom, rgb(235,235,235) 0%, rgb(250,250,250) 53%); + background-image: -webkit-gradient( linear, left bottom, left top, color-stop(0, rgb(235,235,235)), color-stop(0.53, rgb(250,250,250))); + } +#d_clip_button.hover, #clear:hover + { + color: #555; + background-image: linear-gradient(bottom, rgb(245,240,245) 0%, rgb(255,255,255) 78%); + background-image: -o-linear-gradient(bottom, rgb(245,240,245) 0%, rgb(255,255,255) 78%); + background-image: -moz-linear-gradient(bottom, rgb(245,240,245) 0%, rgb(255,255,255) 78%); + background-image: -webkit-linear-gradient(bottom, rgb(245,240,245) 0%, rgb(255,255,255) 78%); + background-image: -ms-linear-gradient(bottom, rgb(245,240,245) 0%, rgb(255,255,255) 78%); + background-image: -webkit-gradient( linear, left bottom, left top, color-stop(0, rgb(245,240,245)), color-stop(0.78, rgb(255,255,255))); + } +#d_clip_button.active, #clear:active + { + color: #111; + border-top: 1px solid #333; + border-left: 1px solid #555; + border-right: 1px solid #555; + border-bottom: 1px solid #333; + background-image: linear-gradient(bottom, rgb(194,194,194) 0%, rgb(235,235,235) 53%); + background-image: -o-linear-gradient(bottom, rgb(194,194,194) 0%, rgb(235,235,235) 53%); + background-image: -moz-linear-gradient(bottom, rgb(194,194,194) 0%, rgb(235,235,235) 53%); + background-image: -webkit-linear-gradient(bottom, rgb(194,194,194) 0%, rgb(235,235,235) 53%); + background-image: -ms-linear-gradient(bottom, rgb(194,194,194) 0%, rgb(235,235,235) 53%); + background-image: -webkit-gradient( linear, left bottom, left top, color-stop(0, rgb(194,194,194)), color-stop(0.53, rgb(235,235,235))); + } +</style> + +</head> +<body> +<div id="help"> + <b>key controls</b> + <div id="keys"> + ESC toggle<br/> + C clear<br/> + R reverse<br/> + BACKSPACE delete<br/> + LEFT ARROW newer<br/> + RIGHT ARROW older<br/> + </div> +</div> +<div id="dump"> + <div id="rebus"></div> + <input id="urlz" type="text" /> + <div id="d_clip_container" style="position:relative"> + <div id="d_clip_button">copy</div> + </div> + <button id="clear">clear</button> +</div> +<div id="images"> +""" + + +files = get_files(params) +count = 0 +for f in files: + # url = BASE_HREF + f.replace(" ","%20") + url = BASE_HREF + f[5] + "/" + f[7] + print "<div><img src='%s'/></div>" % (url) +print "</div>" + +lowest_id = files[-1][0] +previous_id = lowest_id + (LIMIT * 2) +back = ["start=%d" % lowest_id, "limit=%d" % LIMIT] +newer = ["start=%d" % previous_id, "limit=%d" % LIMIT] +random_time = [] +if params['name'] is not None: + back.append("name=%s" % params['name']) + newer.append("name=%s" % params['name']) + random_time.append("name=%s" % params['name']) + +newer_QS = "&".join(newer) +back_QS = "&".join(back) +random_time_QS = "&".join(back) +print "<div id='nextpage'>" +print "<a href='?%s'>← newer</a>" % newer_QS; +print "|" +print "<a href='/im/'>editor</a>" +print "|" +print "<a href='?random=1%s'>random</a>" % random_time_QS; +print "|" +print "<a href='?%s'>older →</a>" % back_QS; +print "</div>" +print """ +</body> +<script type="text/javascript"></script> +<script type="text/javascript" src="/js/jquery.js"></script> +<script type="text/javascript" src="/js/ZeroClipboard.js"></script> +<script type="text/javascript" src="http://asdf.us/js/pbembed.js"></script> +<script type="text/javascript"> +ZeroClipboard.setMoviePath( 'http://asdf.us/swf/ZeroClipboard10.swf' ); +var clip = new ZeroClipboard.Client(); +clip.glue( 'd_clip_button' ); +var Dump = + { + pick: function () + { + Dump.pickUrl( $(this).attr("src") ) + }, + pickUrl: function (url) + { + $("#rebus").append ($ ("<img>").attr ("src", url)) + $("#rebus").show() + var theDump = $("#urlz").val() + " " + url + $("#urlz").val( theDump ) + clip.setText( theDump ) + return false + }, + clear: function () + { + $("#rebus").html("") + $("#urlz").val("") + clip.setText("") + }, + backspace: function () + { + $("#rebus img:last").remove() + var urllist = $("#urlz").val().split(" ") + urllist.pop() + $("#urlz").val( urllist.join(" ") ) + }, + reverse: function () + { + urllist = $("#urlz").val().split(" ") + Dump.clear() + for (i in urllist.reverse()) + if (urllist[i]) + Dump.pickUrl(urllist[i]) + }, + showNewer: function() + { + window.location.href = '?"""+newer_QS+"""' + }, + showOlder: function() + { + window.location.href = '?"""+back_QS+"""' + } + } +var Main = + { + editing: false, + kp: function (event) + { + console.log(event.keyCode); + switch (event.keyCode) + { + // BS + case 8: + if (! Main.editing) + Dump.backspace() + return false + // C + case 67: + if (! Main.editing) + Dump.clear() + break + // R + case 82: + if (! Main.editing) + Dump.reverse() + break + // ESC + case 27: + // H + case 72: + if (! Main.editing) + $("#rebus").toggle() + break + // LEFT ARROW + case 37: + if (! Main.editing) + Dump.showNewer() + break + // RIGHT ARROW + case 39: + if (! Main.editing) + Dump.showOlder() + break + } + return true + }, + poll: function () + { + }, + pollCallback: function () + { + }, + init: function () + { + $(document).keydown(Main.kp) + $("#urlz").focus(function(){ Main.editing = true }) + $("#urlz").blur(function(){ Main.editing = false }) + $("#clear").live("click", Dump.clear) + $("#help").click(function(){ $("#keys").toggle() }) + $("div img").live("click", Dump.pick) + Dump.clear() + } + } +""" +if params['interface'] is not None and params['interface'] == "off": + print """ +$("#nextpage,#help,#dump").hide() +$("body").css({"margin": 0, "padding": 0, "overflow": hidden, "background-color": white}) +""" +else: + print "Main.init()" +print """ +</script> +</html> +""" + |
