Changeset 2720
- Timestamp:
- 03/11/08 17:25:41 (10 months ago)
- Files:
-
- trunk/bknr/datastore/src/data/object.lisp (modified) (1 diff)
- trunk/bknr/web/src/packages.lisp (modified) (1 diff)
- trunk/bknr/web/src/rss/rss.lisp (modified) (3 diffs)
- trunk/bknr/web/src/web/handlers.lisp (modified) (4 diffs)
- trunk/bknr/web/src/web/template-handler.lisp (modified) (2 diffs)
- trunk/clean.lisp (modified) (1 diff)
- trunk/projects/quickhoney/src/handlers.lisp (modified) (1 diff)
- trunk/projects/quickhoney/src/image.lisp (modified) (2 diffs)
- trunk/projects/quickhoney/src/webserver.lisp (modified) (1 diff)
- trunk/projects/quickhoney/website/templates/index.xml (modified) (2 diffs)
- trunk/thirdparty/drakma-0.11.4/request.lisp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/bknr/datastore/src/data/object.lisp
r2693 r2720 639 639 640 640 (deftransaction change-slot-values (object &rest slots-and-values) 641 (warn "CHANGE-SLOT-VALUES is deprecated - use WITH-TRANSACTION and standard accessors!") 641 642 (when object 642 643 (loop for (slot value) on slots-and-values by #'cddr trunk/bknr/web/src/packages.lisp
r2660 r2720 256 256 #:website 257 257 #:website-name 258 #:website-hosts 258 #:website-host 259 259 #:website-authorizer 260 260 #:website-show-page trunk/bknr/web/src/rss/rss.lisp
r2695 r2720 19 19 :index-reader find-rss-channel) 20 20 (title :update :initform nil) 21 ( link:update :initform nil)21 (path :update :initform nil) 22 22 (description :update :initform nil) 23 23 (last-update :update :initform (get-universal-time)) … … 81 81 (text (or value (format nil "(channel ~(~A~) not defined)" element)))))) 82 82 83 (defmethod rss-channel-link ((channel rss-channel)) 84 (format nil "http://~A/~A" (bknr.web:website-host) (rss-channel-path channel))) 85 83 86 (defgeneric rss-channel-xml (channel stream) 84 87 (:documentation "Generate XML for the current state of RSS channel … … 89 92 (attribute "version" "2.0") 90 93 (attribute* "xmlns" "content" "http://purl.org/rss/1.0/modules/content/") 94 (attribute* "xmlns" "atom" "http://www.w3.org/2005/Atom") 91 95 (with-element "channel" 92 96 (render-mandatory-element channel 'title) 93 (render-mandatory-element channel 'link)94 97 (render-mandatory-element channel 'description) 98 (with-element "link" 99 (text (rss-channel-link channel))) 100 (with-element* ("atom" "link") 101 (attribute "href" (rss-channel-link channel)) 102 (attribute "rel" "self") 103 (attribute "type" "application/rss+xml")) 95 104 96 105 (dolist (item (remove-if-not #'(lambda (item) trunk/bknr/web/src/web/handlers.lisp
r2660 r2720 18 18 (url :initarg :url 19 19 :accessor website-url) 20 (vhosts :initarg :vhosts21 :accessor website-vhosts)22 20 (authorizer :initarg :authorizer 23 21 :accessor website-authorizer) … … 55 53 :reader website-template-handler)) 56 54 (:default-initargs :url nil 57 :vhosts :wild58 55 :authorizer (make-instance 'bknr-authorizer) 59 56 :menu nil … … 70 67 (:documentation "Class to hold all information on a web server that 71 68 is served within BKNR. Currently, this is a singleton object, and 72 *WEBSITE* will point to the only instance. Eventually, multiple 73 WEBSITE instances for virtual hosts may be supported.")) 69 *WEBSITE* will point to the only instance.")) 74 70 75 71 (defmethod initialize-instance :after ((website website) &key &allow-other-keys) … … 78 74 (setf *website* website) 79 75 (publish-site *website*)) 76 77 (defun website-host () 78 (if (and (boundp 'hunchentoot::*request*) 79 hunchentoot::*request* 80 (hunchentoot:header-in :host)) 81 (header-in :host) 82 "localhost")) 80 83 81 84 (defmethod show-handlers ((website website)) trunk/bknr/web/src/web/template-handler.lisp
r2650 r2720 45 45 :reader template-expander-destination) 46 46 (cached-templates :initform (make-hash-table :test 'equal) 47 :accessor template-expander-cached-templates))) 47 :accessor template-expander-cached-templates) 48 (default-template :initarg :default-template :initform nil 49 :reader template-expander-default-template 50 :documentation 51 "Name of the default template to use when no path 52 name has been specified."))) 48 53 49 54 (defmethod find-tag-function ((expander template-expander) name ns) … … 185 190 (values file (cdr components))))))) 186 191 192 (defun split-path (path) 193 "Split path into its components and return them as list. Empty components are removed." 194 (remove "" (split "/" path) :test #'equal)) 195 187 196 (defmethod find-template-pathname ((expander template-expander) template-name) 188 (let ((components (remove "" (split "/" template-name) :test #'equal))) 197 (let ((components (or (split-path template-name) 198 (and (template-expander-default-template expander) 199 (split-path (template-expander-default-template expander)))))) 189 200 (multiple-value-bind (pathname ret-components) 190 201 (find-template (template-expander-destination expander) components) trunk/clean.lisp
r2703 r2720 6 6 (mapc #'delete-file (directory (compile-file-pathname #P"**/*.lisp"))) 7 7 8 trunk/projects/quickhoney/src/handlers.lisp
r2712 r2720 186 186 :keywords (cons :upload keywords) 187 187 :initargs (list :client client :spider-keywords spider-keywords)))) 188 (with-http-response () 189 (with-http-body () 190 (html (:html 191 (:head 192 (:title "Upload successful") 193 ((:script :type "text/javascript" :language "JavaScript") 194 "function done() { window.opener.do_query(); window.close(); }")) 195 (:body 196 (:p "Image " (:princ-safe (store-image-name image)) " with " (:princ-safe (hash-table-count color-table)) " colors uploaded") 197 (:p ((:img :src (format nil "/image/~D" (store-object-id image)) 198 :width (round (* ratio width)) :height (round (* ratio height))))) 199 (:p ((:a :href "javascript:done()") "ok"))))))))))) 200 (error (e) 201 (with-http-response () 202 (with-http-body () 203 (html (:html 204 (:head 205 (:title "Error during upload")) 206 (:body 207 (:h2 "Error during upload") 208 (:p "Error during upload:") 209 (:p (:princ-safe (apply #'format nil (simple-condition-format-control e) (simple-condition-format-arguments e)))) 210 (:p ((:a :href "javascript:window.close()") "ok")))))))))))) 211 212 (defclass upload-news-handler (admin-only-handler page-handler) 213 ()) 214 215 (defmethod handle ((handler upload-news-handler)) 216 (with-query-params (title text) 217 (let ((uploaded-file (request-uploaded-file "image-file"))) 218 (handler-case 219 (progn 220 (unless uploaded-file 221 (error "no file uploaded")) 222 (with-image-from-upload* (uploaded-file) 223 (let* ((color-table (make-hash-table :test #'eql)) 224 (width (cl-gd:image-width)) 225 (height (cl-gd:image-height)) 226 (ratio (/ 1 (max (/ width 300) (/ height 200))))) 227 (cl-gd:do-pixels () 228 (incf (gethash (cl-gd:raw-pixel) color-table 0))) 229 (when (and (cl-gd:true-color-p) 230 (<= (hash-table-count color-table) 256)) 231 (cl-gd:true-color-to-palette)) 232 (let* ((image (make-store-image :name (pathname-name (upload-original-filename uploaded-file)) 233 :class-name 'quickhoney-news-item 234 :keywords (list :upload :news) 235 :initargs (list :title title 236 :text text)))) 188 237 (with-http-response () 189 238 (with-http-body () trunk/projects/quickhoney/src/image.lisp
r2712 r2720 62 62 (format nil "~@[~A~]/index#~(~A/~A~)/~A" 63 63 (unless internal 64 (format nil "http://~A/" 65 (if (and (boundp 'hunchentoot::*request*) 66 hunchentoot::*request* 67 (hunchentoot:header-in :host)) 68 (header-in :host) 69 "quickhoney.com"))) 64 (format nil "http://~A/" (website-host))) 70 65 (quickhoney-image-category image) (quickhoney-image-subcategory image) (store-image-name image))) 71 66 … … 76 71 (delete-object (quickhoney-animation-image-animation image))) 77 72 73 (define-persistent-class quickhoney-news-item (quickhoney-image) 74 ((title :update) 75 (text :update))) 76 77 (defmethod quickhoney-image-spider-keywords ((item quickhoney-news-item)) 78 (quickhoney-news-item-title item)) 79 80 (defmethod rss-item-title ((item quickhoney-news-item)) 81 (quickhoney-news-item-title item)) 82 83 (defmethod rss-item-encoded-content ((item quickhoney-news-item)) 84 (concatenate 'string 85 (call-next-method) 86 (quickhoney-news-item-text item))) trunk/projects/quickhoney/src/webserver.lisp
r2712 r2720 32 32 ("/rss" rss-handler) 33 33 ("/admin" admin-handler) 34 ("/upload-news" upload-news-handler) 34 35 ("/" template-handler 35 36 :default-template "frontpage" trunk/projects/quickhoney/website/templates/index.xml
r2712 r2720 254 254 <div id="edit_news_form" class="cms_form"> 255 255 <div class="cms_title">Create news entry</div> 256 <form action="/upload-news /news" method="post"256 <form action="/upload-news" method="post" 257 257 enctype="multipart/form-data" target="upload_result" onsubmit="do_upload(this.target);"> 258 258 <p class="cms"> … … 265 265 <tr> 266 266 <td>Title:</td> 267 <td><input name=" subject" size="60"/></td>267 <td><input name="title" size="60"/></td> 268 268 </tr> 269 269 <tr> trunk/thirdparty/drakma-0.11.4/request.lisp
r2663 r2720 200 200 #+:lispworks (read-timeout 20) 201 201 #+(and :lispworks (not :lw-does-not-have-write-timeout)) 202 (write-timeout 20 write-timeout-provided-p)) 202 (write-timeout 20 write-timeout-provided-p) 203 #+openmcl deadline) 203 204 "Sends an HTTP request to a web server and returns its reply. URI 204 205 is where the request is sent to, and it is either a string denoting a … … 374 375 if an existing stream is re-used. All timeout keyword arguments are 375 376 only available for LispWorks, WRITE-TIMEOUT is only available for 376 LispWorks 5.0 or higher." 377 LispWorks 5.0 or higher. 378 379 DEADLINE, a universal time in the future, specifies the time until 380 which the request should be finished. If the server fails to respond 381 until that time, a COMMUNICATION-DEADLINE-EXPIRED condition is 382 signalled. DEADLINE is available on CCL 1.2 and later." 377 383 (unless (member protocol '(:http/1.0 :http/1.1) :test #'eq) 378 384 (error "Don't know how to handle protocol ~S." protocol)) … … 444 450 (usocket:socket-stream 445 451 (usocket:socket-connect host port :element-type 'octet)))) 452 #+openmcl 453 (when deadline 454 (setf (ccl:stream-deadline http-stream) 455 (+ (get-internal-real-time) 456 (* (- deadline (get-universal-time)) internal-time-units-per-second)))) 446 457 (when (and use-ssl 447 458 ;; don't attach SSL to existing streams
