[bknr-cvs] hans changed trunk/projects/quickhoney/

BKNR Commits bknr at bknr.net
Wed Sep 17 20:20:54 UTC 2008


Revision: 3914
Author: hans
URL: http://bknr.net/trac/changeset/3914

Always show same button home page and category.
Add 'quickhoney' application to twitter message.
Use more images to create buttons on home page.

U   trunk/projects/quickhoney/src/handlers.lisp
U   trunk/projects/quickhoney/src/twitter.lisp
U   trunk/projects/quickhoney/website/static/javascript.js

Modified: trunk/projects/quickhoney/src/handlers.lisp
===================================================================
--- trunk/projects/quickhoney/src/handlers.lisp	2008-09-17 13:31:04 UTC (rev 3913)
+++ trunk/projects/quickhoney/src/handlers.lisp	2008-09-17 20:20:54 UTC (rev 3914)
@@ -236,7 +236,12 @@
                     (images-in-all-subcategories-sorted-by-time subcategory)
                     (images-in-category-sorted-by-time (list category subcategory)))))
     (when images
-      (cons :images images))))
+      (cons :images (loop with since = (- (get-universal-time) (* 60 60 24 14))
+                          for i from 0
+                          for image in images
+                          when (or (< i 10)
+                                   (> (blob-timestamp image) since))
+                          collect image)))))
 
 (defmethod handle ((handler json-buttons-handler))
   (with-json-response ()
@@ -256,8 +261,7 @@
                     ;; format and come with the caption rendered into
                     ;; them.
                     (let ((category (make-keyword-from-string category))
-                          (subcategory (make-keyword-from-string subcategory))
-                          (count 10))
+                          (subcategory (make-keyword-from-string subcategory)))
                       (destructuring-bind (&optional type &rest images)
                           (or (preproduced-buttons category subcategory)
                               (newest-images category subcategory)
@@ -265,9 +269,7 @@
                         (encode-array-element type)
                         (dolist (image (or images
                                            (list (store-image-with-name "button-dummy"))))
-                          (encode-array-element (store-object-id image))
-                          (when (zerop (decf count))
-                            (return)))))))))))))
+                          (encode-array-element (store-object-id image)))))))))))))
 
 (defclass upload-image-handler (admin-only-handler prefix-handler)
   ())

Modified: trunk/projects/quickhoney/src/twitter.lisp
===================================================================
--- trunk/projects/quickhoney/src/twitter.lisp	2008-09-17 13:31:04 UTC (rev 3913)
+++ trunk/projects/quickhoney/src/twitter.lisp	2008-09-17 20:20:54 UTC (rev 3914)
@@ -19,7 +19,8 @@
     (let ((result (babel:octets-to-string
                    (drakma:http-request "http://twitter.com/statuses/update.xml"
                                         :method :post
-                                                :content (format nil "status=~A" status-string)
+                                                :content (format nil "status=~A&source=quickhoney"
+                                                                 (hunchentoot:url-encode status-string))
                                                 :content-type "application/x-www-form-urlencoded"
                                                 :basic-authorization (account-authorization account)))))
       (when (cl-ppcre:scan "<error>" result)

Modified: trunk/projects/quickhoney/website/static/javascript.js
===================================================================
--- trunk/projects/quickhoney/website/static/javascript.js	2008-09-17 13:31:04 UTC (rev 3913)
+++ trunk/projects/quickhoney/website/static/javascript.js	2008-09-17 20:20:54 UTC (rev 3914)
@@ -645,13 +645,28 @@
 /* directory - first level category */
 
 var button_images = [];
+var last_category_buttons = {};
 
 function random_button_image(category, subcategory, width, height, cut_category) {
+
+    /* We want the last used button for a category used on the home
+     * page to also appear on that categories page next.  For that, we
+     * save the previously displayed home image button here.  Not pretty.
+     */
+
     var key = category + '/' + subcategory;
     var image_ids = button_images[key];
     if (image_ids && image_ids.length) {
         var type = image_ids[0];
-        var image_id = image_ids[1 + Math.floor(Math.random() * (image_ids.length - 1))];
+        var ids = image_ids.slice(1);
+        var image_id = ids[Math.floor(Math.random() * ids.length)];
+        if (last_category_buttons[category] && findValue(ids, last_category_buttons[category]) != -1) {
+            image_id = last_category_buttons[category];
+            last_category_buttons[category] = null;
+        }
+        if (category == 'home') {
+            last_category_buttons[subcategory] = image_id;
+        }
         if (type == 'buttons') {
             return '/image/' + image_id;
         } else {
@@ -1582,7 +1597,10 @@
                                        TBODY(null,
                                              TR(null,
                                                 TD({ 'class': 't-shirt-sample', valign: 'top' },
-                                                   IMG({ id: 't-shirt-sample', src: '/image/' + encodeURI(current_image.name) + '/cell,ffffff,100,100,10'})),
+                                                   IMG({ id: 't-shirt-sample',
+                                                         src: ('/image/'
+                                                               + encodeURI(current_image.name)
+                                                               + '/cell,ffffff,100,100,10')})),
                                                 TD(null,
                                                    "Color:", BR(),
                                                    "Tee - white", BR(),




More information about the Bknr-cvs mailing list