summaryrefslogtreecommitdiff
path: root/impattern/im/cgi-bin/gallery.cgi
blob: 0f762ebf0340ebf52022a0f12f222ccfdec890cc (plain)
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
#!/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'>&larr; 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 &rarr;</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>
"""