Changeset 2720

Show
Ignore:
Timestamp:
03/11/08 17:25:41 (10 months ago)
Author:
hans
Message:

Checkpoint QuickHoney? work.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/bknr/datastore/src/data/object.lisp

    r2693 r2720  
    639639 
    640640(deftransaction change-slot-values (object &rest slots-and-values) 
     641  (warn "CHANGE-SLOT-VALUES is deprecated - use WITH-TRANSACTION and standard accessors!") 
    641642  (when object 
    642643    (loop for (slot value) on slots-and-values by #'cddr 
  • trunk/bknr/web/src/packages.lisp

    r2660 r2720  
    256256           #:website 
    257257           #:website-name 
    258            #:website-hosts 
     258           #:website-host 
    259259           #:website-authorizer 
    260260           #:website-show-page 
  • trunk/bknr/web/src/rss/rss.lisp

    r2695 r2720  
    1919         :index-reader find-rss-channel) 
    2020   (title :update :initform nil) 
    21    (link :update :initform nil) 
     21   (path :update :initform nil) 
    2222   (description :update :initform nil) 
    2323   (last-update :update :initform (get-universal-time)) 
     
    8181      (text (or value (format nil "(channel ~(~A~) not defined)" element)))))) 
    8282 
     83(defmethod rss-channel-link ((channel rss-channel)) 
     84  (format nil "http://~A/~A" (bknr.web:website-host) (rss-channel-path channel))) 
     85 
    8386(defgeneric rss-channel-xml (channel stream) 
    8487  (:documentation "Generate XML for the current state of RSS channel 
     
    8992        (attribute "version" "2.0") 
    9093        (attribute* "xmlns" "content" "http://purl.org/rss/1.0/modules/content/") 
     94        (attribute* "xmlns" "atom" "http://www.w3.org/2005/Atom") 
    9195        (with-element "channel" 
    9296          (render-mandatory-element channel 'title) 
    93           (render-mandatory-element channel 'link) 
    9497          (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")) 
    95104         
    96105          (dolist (item (remove-if-not #'(lambda (item) 
  • trunk/bknr/web/src/web/handlers.lisp

    r2660 r2720  
    1818   (url :initarg :url 
    1919        :accessor website-url) 
    20    (vhosts :initarg :vhosts 
    21            :accessor website-vhosts) 
    2220   (authorizer :initarg :authorizer 
    2321               :accessor website-authorizer) 
     
    5553                     :reader website-template-handler)) 
    5654  (:default-initargs :url nil 
    57     :vhosts :wild 
    5855    :authorizer (make-instance 'bknr-authorizer) 
    5956    :menu nil 
     
    7067  (:documentation "Class to hold all information on a web server that 
    7168is 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.")) 
    7470 
    7571(defmethod initialize-instance :after ((website website) &key &allow-other-keys) 
     
    7874  (setf *website* website) 
    7975  (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")) 
    8083 
    8184(defmethod show-handlers ((website website)) 
  • trunk/bknr/web/src/web/template-handler.lisp

    r2650 r2720  
    4545                :reader template-expander-destination) 
    4646   (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 
     52name has been specified."))) 
    4853 
    4954(defmethod find-tag-function ((expander template-expander) name ns) 
     
    185190            (values file (cdr components))))))) 
    186191 
     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 
    187196(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)))))) 
    189200    (multiple-value-bind (pathname ret-components) 
    190201        (find-template (template-expander-destination expander) components) 
  • trunk/clean.lisp

    r2703 r2720  
    66(mapc #'delete-file (directory (compile-file-pathname #P"**/*.lisp"))) 
    77 
     8 
  • trunk/projects/quickhoney/src/handlers.lisp

    r2712 r2720  
    186186                                                :keywords (cons :upload keywords) 
    187187                                                :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)))) 
    188237                  (with-http-response () 
    189238                    (with-http-body () 
  • trunk/projects/quickhoney/src/image.lisp

    r2712 r2720  
    6262  (format nil "~@[~A~]/index#~(~A/~A~)/~A" 
    6363          (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))) 
    7065          (quickhoney-image-category image) (quickhoney-image-subcategory image) (store-image-name image))) 
    7166 
     
    7671  (delete-object (quickhoney-animation-image-animation image))) 
    7772 
     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  
    3232                                        ("/rss" rss-handler) 
    3333                                        ("/admin" admin-handler) 
     34                                        ("/upload-news" upload-news-handler) 
    3435                                        ("/" template-handler 
    3536                                         :default-template "frontpage" 
  • trunk/projects/quickhoney/website/templates/index.xml

    r2712 r2720  
    254254   <div id="edit_news_form" class="cms_form"> 
    255255    <div class="cms_title">Create news entry</div> 
    256     <form action="/upload-news/news" method="post" 
     256    <form action="/upload-news" method="post" 
    257257          enctype="multipart/form-data" target="upload_result" onsubmit="do_upload(this.target);"> 
    258258     <p class="cms"> 
     
    265265        <tr> 
    266266         <td>Title:</td> 
    267          <td><input name="subject" size="60"/></td> 
     267         <td><input name="title" size="60"/></td> 
    268268        </tr> 
    269269        <tr> 
  • trunk/thirdparty/drakma-0.11.4/request.lisp

    r2663 r2720  
    200200                              #+:lispworks (read-timeout 20) 
    201201                              #+(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) 
    203204  "Sends an HTTP request to a web server and returns its reply.  URI 
    204205is where the request is sent to, and it is either a string denoting a 
     
    374375if an existing stream is re-used.  All timeout keyword arguments are 
    375376only available for LispWorks, WRITE-TIMEOUT is only available for 
    376 LispWorks 5.0 or higher." 
     377LispWorks 5.0 or higher. 
     378 
     379DEADLINE, a universal time in the future, specifies the time until 
     380which the request should be finished.  If the server fails to respond 
     381until that time, a COMMUNICATION-DEADLINE-EXPIRED condition is 
     382signalled.  DEADLINE is available on CCL 1.2 and later." 
    377383  (unless (member protocol '(:http/1.0 :http/1.1) :test #'eq) 
    378384    (error "Don't know how to handle protocol ~S." protocol)) 
     
    444450                                    (usocket:socket-stream 
    445451                                     (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)))) 
    446457              (when (and use-ssl 
    447458                         ;; don't attach SSL to existing streams