1 ;; -*- coding: utf-8-mcs-er -*-
2 (require 'cwiki-format)
3 (require 'char-db-json)
5 (defvar chise-wiki-view-url "view.cgi")
6 (defvar chise-wiki-edit-url "edit.cgi")
7 (defvar chise-wiki-add-url "add.cgi")
9 (defun www-edit-display-feature-input-box (char feature-name
10 &optional format value)
12 (setq char (or (concord-decode-object '=id char 'feature)
13 (concord-make-object 'feature char))))
15 (setq format 'default))
17 (setq value (www-get-feature-value char feature-name)))
18 (if (and (symbolp value)
19 (eq format 'wiki-text))
20 (setq value (list (list value))))
22 (format "<p><input type=\"text\" name=\"feature-name\"
23 size=\"32\" maxlength=\"256\" value=\"%s\">"
25 (princ (encode-coding-string " \u2190 " 'utf-8-mcs-er))
27 (format "%s<input type=\"text\" name=\"%s\"
28 size=\"64\" maxlength=\"256\" value=\"%s\">
29 <input type=\"submit\" value=\"set\" /></p>
31 (if (or (eq format 'HEX)(eq format 'hex))
35 (mapconcat (lambda (c)
37 ;; ((eq c ?<) "&lt;")
38 ;; ((eq c ?>) "&gt;")
39 ((eq c ?\u0022) """)
42 (est-format-list value format nil nil " ")
46 (defun www-display-object-desc (genre uri-object &optional uri-feature-name
49 uri-feature-name-to-edit editing-format)
52 (let ((object (www-uri-decode-object genre uri-object))
53 (est-eval-list-feature-items-limit est-eval-list-feature-items-limit)
54 (est-view-url-prefix (if uri-feature-name
57 (rdf-uri-object (if est-hide-cgi-mode
58 (if (string-match "=" uri-object)
60 (est-uri-decode-feature-name-body
61 (substring uri-object 0 (match-beginning 0)))
63 (est-uri-decode-feature-name-body
64 (substring uri-object (match-end 0))))
66 feature-name-to-display feature-name-to-edit
67 base-name-to-edit metadata-name-to-edit
69 logical-feature chise-wiki-displayed-features
71 GlyphWiki-id HNG-card HNG-card-id HNG-card-cobj ret object-spec
72 width height image-cobj base-image x y w h)
76 (setq without-header t))
78 (when uri-feature-name-to-edit
79 (setq feature-name-to-edit
80 (www-uri-decode-feature-name uri-feature-name-to-edit))
81 (setq ret (symbol-name feature-name-to-edit))
82 (if (string-match "\\*" ret)
83 (setq base-name-to-edit (intern
84 (substring ret 0 (match-beginning 0)))
85 metadata-name-to-edit (intern
86 (substring ret (match-end 0))))
87 (setq base-name-to-edit feature-name-to-edit))
88 (when (stringp editing-format)
89 (setq editing-format (intern editing-format))))
90 (when (and (eq genre 'character)
91 (= (length uri-object) 1))
92 (setq uri-object (www-uri-encode-object object)))
97 <style type=\"text/css\">
100 .ids { vertical-align: middle; font-size: 40px; line-height: 100%%; }
101 a { text-decoration: none; }
102 .ids a { color: black; }
103 ul { margin: 0 0; color: black; }
104 li { margin: 0 0 0 2em; }
105 .feature-name { font-family: sans-serif; font-weight: bold; }
106 .feature-name a { color: black; }
110 display: inline-block;
111 border-bottom: 1px dotted black;
114 .tooltip .tooltiptext {
120 background-color: black;
130 .value .image-list img { height: 320px; vertical-align: top; }
132 .list .tooltip:hover .tooltiptext {
139 src=\"http://hng.chise.org/openseadragon/openseadragon.min.js\"></script>
141 <title>EsT %s = %s</title>
144 (decode-uri-string uri-object 'utf-8-mcs-er))
147 (when (eq genre 'character)
148 (dolist (feature (char-feature-property '$object 'additional-features))
149 (mount-char-attribute-table
150 (char-feature-name-at-domain feature '$rev=latest))))
154 (if est-hide-cgi-mode
155 "<div style=\"text-align:right;\">
156 <a href=\"../../edit/view.cgi?%s=%s\">
157 <input type=\"submit\" value=\"Edit\" />
159 "<div style=\"text-align:right;\">
160 <a href=\"edit/view.cgi?%s=%s\">
161 <input type=\"submit\" value=\"Edit\" />
163 genre rdf-uri-object)
165 "<div style=\"text-align:right;\">
166 <a href=\"../view/%s/%s\">
167 <input type=\"submit\" value=\"Simple\" />
170 (if (string-match ":" uri-object)
172 (est-uri-encode-feature-name-body
173 (substring uri-object 0 (match-beginning 0)))
175 (est-uri-encode-feature-name-body
176 (substring uri-object (match-end 0))))))))
178 (format "<input type=\"submit\" value=\"New Account\" />
179 <a href=\"http://www.chise.org/est/rdf.cgi?%s=%s\">
180 <input type=\"submit\" value=\"RDF\" />
185 (if (eq genre 'character)
187 <a href=\"/est/view/%s/%s/data.json\">
188 <input type=\"submit\" value=\"JSON\" />
190 genre rdf-uri-object)
192 (when (setq parents (www-get-feature-value object '<-denotational))
193 (if (characterp parents)
194 (setq parents (list parents)))
195 (princ (format "<p>%s %s</p>\n<hr>\n"
196 (www-format-value-as-char-list parents)
197 (www-format-feature-name '->denotational lang))))
198 (when (setq parents (www-get-feature-value object '<-subsumptive))
199 (if (characterp parents)
200 (setq parents (list parents)))
201 (princ (format "<p>%s %s</p>\n<hr>\n"
202 (www-format-value-as-char-list parents)
203 (www-format-feature-name '->subsumptive lang))))
204 (when (eq genre 'character)
205 (setq GlyphWiki-id (char-GlyphWiki-id object)))
207 ((eq genre 'image-resource)
209 (if (setq ret (concord-object-get object '=location@iiif))
211 (car (concord-object-get object '<-image-segment)))
212 (format "<a href=\"%s...$.zoom-xywh=%d,%d,%d,%d\"
213 ><img alt=\"%s\" src=\"%s\" /></a>"
214 (www-uri-encode-object base-image)
215 (concord-object-get object 'image-offset-x)
216 (concord-object-get object 'image-offset-y)
217 (concord-object-get object 'image-width)
218 (concord-object-get object 'image-height)
220 (if (and image-selection
221 (string-match "\\([0-9]+\\),\\([0-9]+\\),\\([0-9]+\\),\\([0-9]+\\)" image-selection))
223 (setq x (string-to-int (match-string 1 image-selection))
224 y (string-to-int (match-string 2 image-selection))
225 w (string-to-int (match-string 3 image-selection))
226 h (string-to-int (match-string 4 image-selection)))
228 (concord-object-get object 'image-width)))
229 ;; (setq height (float
230 ;; (concord-object-get object 'image-height)))
231 (format "<div id=\"openseadragon1\"
232 style=\"width: 800px; height: 600px;\"></div>
234 <script type=\"text/javascript\">
236 viewer = OpenSeadragon({
237 id: \"openseadragon1\",
238 prefixUrl: \"http://hng.chise.org/openseadragon/images/\",
239 preserveViewport: true,
244 tileSources: [ \"%s/info.json\" ]
246 viewer.addHandler('open', function () {
247 var newBounds = new OpenSeadragon.Rect( %f, %f, %f, %f, 0 );
248 viewer.viewport.fitBounds(newBounds, true);
249 viewer.viewport.applyConstraints();
259 (format "<div id=\"openseadragon1\"
260 style=\"width: 800px; height: 600px;\"></div>
262 <script type=\"text/javascript\">
264 id: \"openseadragon1\",
265 prefixUrl: \"http://hng.chise.org/openseadragon/images/\",
266 preserveViewport: true,
271 tileSources: [ \"%s/info.json\" ]
276 (setq ret (concord-object-get object '=location))
277 (format "<img alt=\"%s\" src=\"%s\" />"
280 ((and (eq genre 'glyph-image)
282 (car (concord-object-get object '->image-resource))))
283 (if (and (setq ret (concord-object-get image-cobj '=location@iiif))
285 (car (concord-object-get image-cobj '<-image-segment))))
287 (format "<a href=\"../image-resource/%s...$.zoom-xywh=%d,%d,%d,%d\"
288 ><img alt=\"%s\" src=\"%s\" /></a>"
289 (www-uri-encode-object base-image)
290 (concord-object-get image-cobj 'image-offset-x)
291 (concord-object-get image-cobj 'image-offset-y)
292 (concord-object-get image-cobj 'image-width)
293 (concord-object-get image-cobj 'image-height)
295 (setq ret (concord-object-get image-cobj '=location))
296 (princ (format "<img alt=\"%s\" src=\"%s\" />"
299 ((and (eq genre 'hng-card)
300 (setq ret (concord-object-get object '=hng-card))
301 (setq ret (symbol-name ret))
302 (string-match "\\([0-9]+\\)-\\([0-9]+\\)" ret))
305 "<img alt=\"HNG-card:%s\"
306 src=\"http://hng.chise.org/images/HNG/%03d/card/%04d.jpg\"
307 style=\"height: 480px;\" />"
309 (string-to-int (match-string 1 ret))
310 (string-to-int (match-string 2 ret))))
313 (setq ret (www-format-encode-string
314 (est-format-object object 'readable)))
316 "<img alt=\"HNG\\([0-9]+\\)-\\([0-9]+\\)[a-z]?\"" ret)
320 (string-to-int (match-string 1 ret))
321 (string-to-int (match-string 2 ret)))))
323 (format "hng-card/rep.id=%s" HNG-card-id)))
325 (format "<h%d>%s%s</h%d>\n"
329 (format "<a href=\"%s\">%s</a>"
330 ;; (if est-hide-cgi-mode
331 ;; "<a href=\"../%s\">%s</a>"
332 ;; "<a href=\"%s\">%s</a>")
333 (www-uri-make-object-url object uri-object)
338 "<a href=\"../%s\">%s</a>"
344 " <a href=\"http://glyphwiki.org/wiki/%s\"><img alt=\"%s\" src=\"http://glyphwiki.org/glyph/%s.50px.png\" /></a>"
346 GlyphWiki-id GlyphWiki-id)
352 (when feature-name-to-edit
353 (princ "<form action=\"set.cgi\" method=\"GET\">\n")
355 (encode-coding-string
356 (format "<p>(%s : <input type=\"text\" name=\"%s\"
357 size=\"30\" maxlength=\"30\" value=\"%s\">)</p>
360 (decode-uri-string uri-object 'utf-8-mcs-er))
362 (when (and HNG-card-id
363 (eq genre 'character)
365 (concord-decode-object
368 (put-char-attribute object 'sources@HNG/card (list HNG-card-cobj))
369 (if (setq ret (concord-object-get
371 '->glyph-image@zinbun/takuhon))
372 (put-char-attribute object 'sources@zinbun/takuhon ret))
377 (setq feature-name-to-display
378 (www-uri-decode-feature-name uri-feature-name))
379 (setq est-eval-list-feature-items-limit nil)
381 (cons feature-name-to-display
382 (if (eq genre 'character)
383 (get-char-attribute object feature-name-to-display)
384 (concord-object-get object feature-name-to-display)))))
386 (if (eq genre 'character)
387 (char-attribute-alist object)
388 (concord-object-spec object)))))
389 (when feature-name-to-edit
390 (unless (assq base-name-to-edit object-spec)
391 (setq object-spec (cons (cons base-name-to-edit nil)
393 (dolist (cell (sort object-spec
395 (char-attribute-name<
396 (char-feature-name-sans-versions (car a))
397 (char-feature-name-sans-versions (car b))))))
398 (setq logical-feature (char-feature-name-sans-versions (car cell)))
399 (unless (memq logical-feature chise-wiki-displayed-features)
400 (push logical-feature chise-wiki-displayed-features)
402 ((and feature-name-to-edit
403 (eq (car cell) feature-name-to-edit))
404 (www-edit-display-feature-input-box
405 object feature-name-to-edit editing-format)
410 "<div class=\"feature\" style=\"line-height:150%\">\n"
413 (www-format-eval-list
414 (www-feature-format logical-feature)
416 logical-feature ; (car cell)
421 (format " <a href=\"%s?%s=%s&feature=%s&format=wiki-text\"
422 ><input type=\"submit\" value=\"note\" /></a>"
425 (www-format-encode-string uri-object)
426 (www-format-encode-string
427 (www-uri-encode-feature-name
428 (intern (format "%s*note"
429 logical-feature ; (car cell)
431 (when (and feature-name-to-edit
432 (eq base-name-to-edit (car cell)) metadata-name-to-edit)
435 (www-edit-display-feature-input-box
436 object feature-name-to-edit editing-format)
449 (when feature-name-to-edit
453 (format "<a href=\"%s?%s=%s\"
454 ><input type=\"submit\" value=\"add feature\" /></a>
458 (www-format-encode-string uri-object))))
463 (when (eq genre 'character)
465 "<form action=\"http://www.chise.org/ids-find\">\n")
467 (www-format-encode-string
468 (est-format-object object)
469 ;; (if (eq genre 'character)
470 ;; (format "%c" object)
471 ;; (format "%s" (concord-object-id object)))
475 " <input type=\"text\" name=\"components\"
476 size=\"30\" maxlength=\"30\" value=\"%s\" />"
477 (encode-coding-string
478 (est-format-object object)
479 ;; (if (eq genre 'character)
480 ;; (char-to-string object)
481 ;; (format "%s" (concord-object-id object)))
484 (www-format-encode-string
485 "を\u542Bむ\u6F22\u5B57を\u63A2す"))
486 (princ " <input type=\"submit\" value=\"search\" />\n")
490 "<form action=\"http://www.chise.org/hng-ids-find\">\n")
492 (www-format-encode-string
493 (est-format-object object)
494 ;; (if (eq genre 'character)
495 ;; (format "%c" object)
496 ;; (format "%s" (concord-object-id object)))
500 " <input type=\"text\" name=\"components\"
501 size=\"30\" maxlength=\"30\" value=\"%s\" />"
502 (encode-coding-string
503 (est-format-object object)
504 ;; (if (eq genre 'character)
505 ;; (char-to-string object)
506 ;; (format "%s" (concord-object-id object)))
509 (www-format-encode-string
510 "を\u542Bむ HNG の\u6F22\u5B57を\u63A2す"))
511 (princ " <input type=\"submit\" value=\"search\" />\n")
520 (defun www-display-feature-desc (uri-feature-name genre uri-object
521 &optional lang simple)
522 (let ((rdf-uri-object (if est-hide-cgi-mode
523 (if (string-match "=" uri-object)
525 (est-uri-decode-feature-name-body
526 (substring uri-object 0 (match-beginning 0)))
528 (est-uri-decode-feature-name-body
529 (substring uri-object (match-end 0))))
531 (feature-name (www-uri-decode-feature-name uri-feature-name))
532 (name@lang (intern (format "name@%s" lang))))
534 (encode-coding-string
536 <title>EsT feature: %s</title>
544 (if est-hide-cgi-mode
545 "<div style=\"text-align:right;\">
546 <a href=\"../../../edit/view.cgi?feature=%s&%s=%s\">
547 <input type=\"submit\" value=\"Edit\" />
549 <input type=\"submit\" value=\"New Account\" />
552 "<div style=\"text-align:right;\">
553 <a href=\"edit/view.cgi?feature=%s&%s=%s\">
554 <input type=\"submit\" value=\"Edit\" />
556 <input type=\"submit\" value=\"New Account\" />
559 uri-feature-name genre rdf-uri-object)
561 "<div style=\"text-align:right;\">
562 <a href=\"../view/feature/%s&%s/%s\">
563 <input type=\"submit\" value=\"Simple\" />
567 uri-feature-name genre uri-object)))
569 (format "<h1>%s</h1>\n"
570 (www-format-encode-string
571 (symbol-name feature-name))))
572 (princ (format "<p>name : %s "
573 (or (www-format-feature-name feature-name) "")))
577 " <a href=\"%s?feature=%s&property=name&format=string&%s=%s\">"
582 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
587 (www-format-encode-string
590 (or (char-feature-property feature-name name@lang) ""))))
594 " <a href=\"%s?feature=%s&property=%s&format=string&%s=%s\">"
600 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
602 (www-html-display-paragraph
604 (or (www-feature-type feature-name)
605 ;; (char-feature-property feature-name 'type)
607 (princ (format "<p>value-format : %s "
610 (or (www-feature-value-format feature-name)
618 " <a href=\"%s?feature=%s&property=value-format&format=wiki-text&%s=%s\"
624 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
627 (princ (format "<p>value-presentation-format : %s "
629 nil 'value-presentation-format
630 (or (www-feature-value-format feature-name)
638 " <a href=\"%s?feature=%s&property=value-presentation-format&format=wiki-text&%s=%s\"
644 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
647 (princ "<p>format : ")
648 (www-html-display-text
649 (decode-coding-string
651 (www-feature-format feature-name))
656 " <a href=\"%s?feature=%s&property=format&format=wiki-text&%s=%s\"
662 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
665 (www-html-display-paragraph
666 (format "description : %s"
667 (or (decode-coding-string
668 (char-feature-property feature-name 'description)
672 (www-html-display-paragraph
673 (format "description@%s : %s"
675 (or (char-feature-property
677 (intern (format "description@%s" lang)))
681 (defun www-batch-view ()
682 (setq terminal-coding-system 'binary)
684 (let* ((target (pop command-line-args-left))
685 (user (pop command-line-args-left))
686 (accept-language (pop command-line-args-left))
687 (mode (intern (pop command-line-args-left)))
692 (car (split-string accept-language ","))
696 (princ "Content-Type: text/html; charset=UTF-8
698 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
699 \"http://www.w3.org/TR/html4/loose.dtd\">
704 (when (string-match "^char=\\(&[^&;]+;\\)" target)
705 (setq ret (match-end 0))
708 (www-uri-encode-object
709 (www-uri-decode-object
710 'character (match-string 1 target)))
711 (substring target ret))))
713 (mapcar (lambda (cell)
714 (if (string-match "=" cell)
716 (setq genre (substring cell 0 (match-beginning 0))
717 ret (substring cell (match-end 0)))
720 (decode-uri-string genre 'utf-8-mcs-er))
722 (list (decode-uri-string cell 'utf-8-mcs-er))))
723 (split-string target "&")))
724 (setq ret (car target))
725 (cond ((eq (car ret) 'char)
726 (www-display-object-desc
727 'character (cdr ret) (cdr (assq 'feature target))
732 ((eq (car ret) 'feature)
733 (www-display-feature-desc
734 (decode-uri-string (cdr ret) 'utf-8-mcs-er)
741 (www-display-object-desc
742 (car ret) (cdr ret) (cdr (assq 'feature target))
749 (princ (format "mode=%S\n" mode))
750 (princ (format "user=%s\n" user))
751 ;; (princ (format "local user=%s\n" (user-login-name)))
752 (princ (format "lang=%S\n" lang))
753 (princ (encode-coding-string (emacs-version) 'utf-8-jp-er))
755 ;; (princ xemacs-chise-version)
761 (princ (format "%S" err)))
764 (defun www-batch-view-smart ()
765 (setq debug-on-error t)
766 (setq terminal-coding-system 'binary)
768 (let* ((est-hide-cgi-mode t)
769 (target (pop command-line-args-left))
770 (user (pop command-line-args-left))
771 (accept-language (pop command-line-args-left))
772 (mode (intern (pop command-line-args-left)))
777 (car (split-string accept-language ","))
780 ret genre feature obj-url json obj)
783 (when (string-match "/data\\.json$" target)
785 target (substring target 0 (match-beginning 0))))
786 (when (string-match "^char/\\(&[^&;]+;\\)" target)
787 (setq ret (match-end 0))
790 (www-uri-encode-object
791 (www-uri-decode-object
792 'character (match-string 1 target)))
793 (substring target ret))))
797 (if (string-match "/" cell)
799 (setq genre (substring cell 0 (match-beginning 0))
800 ret (substring cell (match-end 0)))
802 (intern (decode-uri-string genre 'utf-8-mcs-er))
804 ((string-match "/feature=" ret)
805 (list (substring ret 0 (match-beginning 0))
806 (substring ret (match-end 0)))
808 ((string-match "...$.zoom-xywh=" ret)
809 (list (substring ret 0 (match-beginning 0))
811 (substring ret (match-end 0)))
815 (list (decode-uri-string cell 'utf-8-mcs-er)))
816 ;; (setq ret (split-string cell "/"))
818 ;; (decode-uri-string (car ret) 'utf-8-mcs-er))
821 (split-string target "&")))
822 (setq ret (car target))
824 (princ "Content-Type: application/json; charset=UTF-8
827 (princ "Content-Type: text/html; charset=UTF-8
829 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
830 \"http://www.w3.org/TR/html4/loose.dtd\">
834 ;; (princ (format "<p>%S, %S, %S</p>"
835 ;; (car ret)(nth 1 ret)(nth 2 ret)))
836 ;; (princ (format "// %S %S\n" ret json))
837 (cond ((or (eq (car ret) 'char)
838 (eq (car ret) 'character))
840 (setq obj (www-uri-decode-object
841 (car ret)(nth 1 ret)))
844 ;; (princ (encode-coding-string
845 ;; (format "// %S\n" obj)
846 ;; char-db-file-coding-system))
847 (char-db-json-char-data-with-variant obj 'printable)
848 (encode-coding-region
849 (point-min)(point-max)
850 char-db-file-coding-system)
851 (princ (buffer-string))
853 (www-display-object-desc
854 'character (nth 1 ret) (nth 2 ret)
859 ((eq (car ret) 'feature)
860 (www-display-feature-desc
861 (decode-uri-string (nth 1 ret) 'utf-8-mcs-er)
863 (nth 1 (nth 1 target))
867 ;; ((eq (car ret) 'image-resource)
869 ;; ;; ((string-match "^\\.iiif=" (nth 1 ret))
870 ;; ;; (setq obj-url (decode-uri-string
871 ;; ;; (substring (nth 1 ret) (match-end 0))
872 ;; ;; 'utf-8-mcs-er))
873 ;; ;; (setq obj (concord-images-add-iiif obj-url))
874 ;; ;; (www-display-object-desc
875 ;; ;; 'image-resource
876 ;; ;; (www-uri-encode-object obj)
879 ;; ;; (eq mode 'simple))
882 ;; (princ (nth 1 ret))
883 ;; (www-display-object-desc
884 ;; 'image-resource (nth 1 ret) (nth 2 ret)
886 ;; (eq mode 'simple))
890 (www-display-object-desc
891 (car ret) (nth 1 ret) (nth 2 ret)
899 (princ (format "mode=%S\n" mode))
900 (princ (format "user=%s\n" user))
901 ;; (princ (format "local user=%s\n" (user-login-name)))
902 (princ (format "lang=%S\n" lang))
903 (princ (encode-coding-string (emacs-version) 'utf-8-jp-er))
905 ;; (princ xemacs-chise-version)
912 (princ (format "%S" err)))
915 (provide 'cwiki-view)