Portræt af Arne Jørgensen
Arne Jørgensen
[Download]
;;; webpublish.el --- publish a file on my website

;; Copyright (C) 2005 Arne Jørgensen

;; Author: Arne Jørgensen <arne@arnested.dk>
;; Keywords: web

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2 of the License, or (at
;; your option) any later version.

;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
;; USA.

;;; Commentary:

;;; Code:

(require 'htmlize)

(defvar webpublish-folder "/home/arne/web/arnested/filer/")

(defvar webpublish-header "<?php
if (isset($_GET{\"download\"}))
  {
    header(\"Content-Type: text/plain\");
    readfile( $_SERVER{\"DOCUMENT_ROOT\"} . ereg_replace(\".php\", \".code\", $_SERVER{\"PHP_SELF\"}));
    exit;
  };

$stylesheet = \"/site/htmlize.css\";
include \"/home/arne/web/arnested/site/header.php\";
print '<a href=\"?download\"><img src=\"gnome-dev-floppy.png\" title=\"Download ' . ereg_replace(\"/filer/\", \"\", $_SERVER{\"REQUEST_URI\"}) . '\" alt=\"[Download]\" id=\"download\" /></a>';
?>
")

(defvar webpublish-footer "<?php
include \"/home/arne/web/arnested/site/footer.php\";
?>")

;;;###autoload
(defun webpublish-region (begin end &optional ask)
  "Publish region on web."
  (interactive "r\nP")
  (save-excursion
    (save-window-excursion
      (let ((name (buffer-file-name)))
        (if (or ask
                (null buffer-file-name))
            (setq name (read-from-minibuffer "Publish under file name: "))
          (setq name (file-name-nondirectory name)))
        (write-region (point-min) (point-max) (concat webpublish-folder name ".code"))
        (set-buffer (htmlize-region begin end))
        (search-forward "    <pre>")
        (delete-region (point-min) (match-beginning 0))
        (goto-char (point-min))
        (insert webpublish-header)
        (goto-char (point-max))
        (search-backward "</pre>")
        (delete-region (match-end 0) (point-max))
        (goto-char (point-max))
        (insert webpublish-footer)
        (write-region (point-min) (point-max) (concat webpublish-folder name ".php"))
        (kill-this-buffer)))))

;;;###autoload
(defun webpublish-buffer (&optional ask)
  "Publish buffer on web."
  (interactive "P")
  (webpublish-region (point-min) (point-max) ask))

(provide 'webpublish)

;;; webpublish.el ends here