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 (princ (format "<p>%s %s</p>\n<hr>\n"
194 (www-format-value-as-char-list parents)
195 (www-format-feature-name '->denotational lang))))
196 (when (setq parents (www-get-feature-value object '<-subsumptive))
197 (princ (format "<p>%s %s</p>\n<hr>\n"
198 (www-format-value-as-char-list parents)
199 (www-format-feature-name '->subsumptive lang))))
200 (when (eq genre 'character)
201 (setq GlyphWiki-id (char-GlyphWiki-id object)))
203 ((eq genre 'image-resource)
205 (if (setq ret (concord-object-get object '=location@iiif))
207 (car (concord-object-get object '<-image-segment)))
208 (format "<a href=\"%s...$.zoom-xywh=%d,%d,%d,%d\"
209 ><img alt=\"%s\" src=\"%s\" /></a>"
210 (www-uri-encode-object base-image)
211 (concord-object-get object 'image-offset-x)
212 (concord-object-get object 'image-offset-y)
213 (concord-object-get object 'image-width)
214 (concord-object-get object 'image-height)
216 (if (and image-selection
217 (string-match "\\([0-9]+\\),\\([0-9]+\\),\\([0-9]+\\),\\([0-9]+\\)" image-selection))
219 (setq x (string-to-int (match-string 1 image-selection))
220 y (string-to-int (match-string 2 image-selection))
221 w (string-to-int (match-string 3 image-selection))
222 h (string-to-int (match-string 4 image-selection)))
224 (concord-object-get object 'image-width)))
225 ;; (setq height (float
226 ;; (concord-object-get object 'image-height)))
227 (format "<div id=\"openseadragon1\"
228 style=\"width: 800px; height: 600px;\"></div>
230 <script type=\"text/javascript\">
232 viewer = OpenSeadragon({
233 id: \"openseadragon1\",
234 prefixUrl: \"http://hng.chise.org/openseadragon/images/\",
235 preserveViewport: true,
240 tileSources: [ \"%s/info.json\" ]
242 viewer.addHandler('open', function () {
243 var newBounds = new OpenSeadragon.Rect( %f, %f, %f, %f, 0 );
244 viewer.viewport.fitBounds(newBounds, true);
245 viewer.viewport.applyConstraints();
255 (format "<div id=\"openseadragon1\"
256 style=\"width: 800px; height: 600px;\"></div>
258 <script type=\"text/javascript\">
260 id: \"openseadragon1\",
261 prefixUrl: \"http://hng.chise.org/openseadragon/images/\",
262 preserveViewport: true,
267 tileSources: [ \"%s/info.json\" ]
272 (setq ret (concord-object-get object '=location))
273 (format "<img alt=\"%s\" src=\"%s\" />"
276 ((and (eq genre 'glyph-image)
278 (car (concord-object-get object '->image-resource))))
279 (if (and (setq ret (concord-object-get image-cobj '=location@iiif))
281 (car (concord-object-get image-cobj '<-image-segment))))
283 (format "<a href=\"../image-resource/%s...$.zoom-xywh=%d,%d,%d,%d\"
284 ><img alt=\"%s\" src=\"%s\" /></a>"
285 (www-uri-encode-object base-image)
286 (concord-object-get image-cobj 'image-offset-x)
287 (concord-object-get image-cobj 'image-offset-y)
288 (concord-object-get image-cobj 'image-width)
289 (concord-object-get image-cobj 'image-height)
291 (setq ret (concord-object-get image-cobj '=location))
292 (princ (format "<img alt=\"%s\" src=\"%s\" />"
295 ((and (eq genre 'hng-card)
296 (setq ret (concord-object-get object '=hng-card))
297 (setq ret (symbol-name ret))
298 (string-match "\\([0-9]+\\)-\\([0-9]+\\)" ret))
301 "<img alt=\"HNG-card:%s\"
302 src=\"http://hng.chise.org/images/HNG/%03d/card/%04d.jpg\"
303 style=\"height: 480px;\" />"
305 (string-to-int (match-string 1 ret))
306 (string-to-int (match-string 2 ret))))
309 (setq ret (www-format-encode-string
310 (est-format-object object 'readable)))
312 "<img alt=\"HNG\\([0-9]+\\)-\\([0-9]+\\)[a-z]?\"" ret)
316 (string-to-int (match-string 1 ret))
317 (string-to-int (match-string 2 ret)))))
319 (format "hng-card/rep.id=%s" HNG-card-id)))
321 (format "<h%d>%s%s</h%d>\n"
325 (format "<a href=\"%s\">%s</a>"
326 ;; (if est-hide-cgi-mode
327 ;; "<a href=\"../%s\">%s</a>"
328 ;; "<a href=\"%s\">%s</a>")
329 (www-uri-make-object-url object uri-object)
334 "<a href=\"../%s\">%s</a>"
340 " <a href=\"http://glyphwiki.org/wiki/%s\"><img alt=\"%s\" src=\"http://glyphwiki.org/glyph/%s.50px.png\" /></a>"
342 GlyphWiki-id GlyphWiki-id)
348 (when feature-name-to-edit
349 (princ "<form action=\"set.cgi\" method=\"GET\">\n")
351 (encode-coding-string
352 (format "<p>(%s : <input type=\"text\" name=\"%s\"
353 size=\"30\" maxlength=\"30\" value=\"%s\">)</p>
356 (decode-uri-string uri-object 'utf-8-mcs-er))
358 (when (and HNG-card-id
359 (eq genre 'character)
361 (concord-decode-object
364 (put-char-attribute object 'sources@HNG/card (list HNG-card-cobj))
365 (if (setq ret (concord-object-get
367 '->glyph-image@zinbun/takuhon))
368 (put-char-attribute object 'sources@zinbun/takuhon ret))
373 (setq feature-name-to-display
374 (www-uri-decode-feature-name uri-feature-name))
375 (setq est-eval-list-feature-items-limit nil)
377 (cons feature-name-to-display
378 (if (eq genre 'character)
379 (get-char-attribute object feature-name-to-display)
380 (concord-object-get object feature-name-to-display)))))
382 (if (eq genre 'character)
383 (char-attribute-alist object)
384 (concord-object-spec object)))))
385 (when feature-name-to-edit
386 (unless (assq base-name-to-edit object-spec)
387 (setq object-spec (cons (cons base-name-to-edit nil)
389 (dolist (cell (sort object-spec
391 (char-attribute-name<
392 (char-feature-name-sans-versions (car a))
393 (char-feature-name-sans-versions (car b))))))
394 (setq logical-feature (char-feature-name-sans-versions (car cell)))
395 (unless (memq logical-feature chise-wiki-displayed-features)
396 (push logical-feature chise-wiki-displayed-features)
398 ((and feature-name-to-edit
399 (eq (car cell) feature-name-to-edit))
400 (www-edit-display-feature-input-box
401 object feature-name-to-edit editing-format)
406 "<div class=\"feature\" style=\"line-height:150%\">\n"
409 (www-format-eval-list
410 (www-feature-format logical-feature)
412 logical-feature ; (car cell)
417 (format " <a href=\"%s?%s=%s&feature=%s&format=wiki-text\"
418 ><input type=\"submit\" value=\"note\" /></a>"
421 (www-format-encode-string uri-object)
422 (www-format-encode-string
423 (www-uri-encode-feature-name
424 (intern (format "%s*note"
425 logical-feature ; (car cell)
427 (when (and feature-name-to-edit
428 (eq base-name-to-edit (car cell)) metadata-name-to-edit)
431 (www-edit-display-feature-input-box
432 object feature-name-to-edit editing-format)
445 (when feature-name-to-edit
449 (format "<a href=\"%s?%s=%s\"
450 ><input type=\"submit\" value=\"add feature\" /></a>
454 (www-format-encode-string uri-object))))
459 (when (eq genre 'character)
461 "<form action=\"http://www.chise.org/ids-find\">\n")
463 (www-format-encode-string
464 (est-format-object object)
465 ;; (if (eq genre 'character)
466 ;; (format "%c" object)
467 ;; (format "%s" (concord-object-id object)))
471 " <input type=\"text\" name=\"components\"
472 size=\"30\" maxlength=\"30\" value=\"%s\" />"
473 (encode-coding-string
474 (est-format-object object)
475 ;; (if (eq genre 'character)
476 ;; (char-to-string object)
477 ;; (format "%s" (concord-object-id object)))
480 (www-format-encode-string
481 "を\u542Bむ\u6F22\u5B57を\u63A2す"))
482 (princ " <input type=\"submit\" value=\"search\" />\n")
486 "<form action=\"http://www.chise.org/hng-ids-find\">\n")
488 (www-format-encode-string
489 (est-format-object object)
490 ;; (if (eq genre 'character)
491 ;; (format "%c" object)
492 ;; (format "%s" (concord-object-id object)))
496 " <input type=\"text\" name=\"components\"
497 size=\"30\" maxlength=\"30\" value=\"%s\" />"
498 (encode-coding-string
499 (est-format-object object)
500 ;; (if (eq genre 'character)
501 ;; (char-to-string object)
502 ;; (format "%s" (concord-object-id object)))
505 (www-format-encode-string
506 "を\u542Bむ HNG の\u6F22\u5B57を\u63A2す"))
507 (princ " <input type=\"submit\" value=\"search\" />\n")
516 (defun www-display-feature-desc (uri-feature-name genre uri-object
517 &optional lang simple)
518 (let ((rdf-uri-object (if est-hide-cgi-mode
519 (if (string-match "=" uri-object)
521 (est-uri-decode-feature-name-body
522 (substring uri-object 0 (match-beginning 0)))
524 (est-uri-decode-feature-name-body
525 (substring uri-object (match-end 0))))
527 (feature-name (www-uri-decode-feature-name uri-feature-name))
528 (name@lang (intern (format "name@%s" lang))))
530 (encode-coding-string
532 <title>EsT feature: %s</title>
540 (if est-hide-cgi-mode
541 "<div style=\"text-align:right;\">
542 <a href=\"../../../edit/view.cgi?feature=%s&%s=%s\">
543 <input type=\"submit\" value=\"Edit\" />
545 <input type=\"submit\" value=\"New Account\" />
548 "<div style=\"text-align:right;\">
549 <a href=\"edit/view.cgi?feature=%s&%s=%s\">
550 <input type=\"submit\" value=\"Edit\" />
552 <input type=\"submit\" value=\"New Account\" />
555 uri-feature-name genre rdf-uri-object)
557 "<div style=\"text-align:right;\">
558 <a href=\"../view/feature/%s&%s/%s\">
559 <input type=\"submit\" value=\"Simple\" />
563 uri-feature-name genre uri-object)))
565 (format "<h1>%s</h1>\n"
566 (www-format-encode-string
567 (symbol-name feature-name))))
568 (princ (format "<p>name : %s "
569 (or (www-format-feature-name feature-name) "")))
573 " <a href=\"%s?feature=%s&property=name&format=string&%s=%s\">"
578 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
583 (www-format-encode-string
586 (or (char-feature-property feature-name name@lang) ""))))
590 " <a href=\"%s?feature=%s&property=%s&format=string&%s=%s\">"
596 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
598 (www-html-display-paragraph
600 (or (www-feature-type feature-name)
601 ;; (char-feature-property feature-name 'type)
603 (princ (format "<p>value-format : %s "
606 (or (www-feature-value-format feature-name)
614 " <a href=\"%s?feature=%s&property=value-format&format=wiki-text&%s=%s\"
620 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
623 (princ (format "<p>value-presentation-format : %s "
625 nil 'value-presentation-format
626 (or (www-feature-value-format feature-name)
634 " <a href=\"%s?feature=%s&property=value-presentation-format&format=wiki-text&%s=%s\"
640 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
643 (princ "<p>format : ")
644 (www-html-display-text
645 (decode-coding-string
647 (www-feature-format feature-name))
652 " <a href=\"%s?feature=%s&property=format&format=wiki-text&%s=%s\"
658 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
661 (www-html-display-paragraph
662 (format "description : %s"
663 (or (decode-coding-string
664 (char-feature-property feature-name 'description)
668 (www-html-display-paragraph
669 (format "description@%s : %s"
671 (or (char-feature-property
673 (intern (format "description@%s" lang)))
677 (defun www-batch-view ()
678 (setq terminal-coding-system 'binary)
680 (let* ((target (pop command-line-args-left))
681 (user (pop command-line-args-left))
682 (accept-language (pop command-line-args-left))
683 (mode (intern (pop command-line-args-left)))
688 (car (split-string accept-language ","))
692 (princ "Content-Type: text/html; charset=UTF-8
694 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
695 \"http://www.w3.org/TR/html4/loose.dtd\">
700 (when (string-match "^char=\\(&[^&;]+;\\)" target)
701 (setq ret (match-end 0))
704 (www-uri-encode-object
705 (www-uri-decode-object
706 'character (match-string 1 target)))
707 (substring target ret))))
709 (mapcar (lambda (cell)
710 (if (string-match "=" cell)
712 (setq genre (substring cell 0 (match-beginning 0))
713 ret (substring cell (match-end 0)))
716 (decode-uri-string genre 'utf-8-mcs-er))
718 (list (decode-uri-string cell 'utf-8-mcs-er))))
719 (split-string target "&")))
720 (setq ret (car target))
721 (cond ((eq (car ret) 'char)
722 (www-display-object-desc
723 'character (cdr ret) (cdr (assq 'feature target))
728 ((eq (car ret) 'feature)
729 (www-display-feature-desc
730 (decode-uri-string (cdr ret) 'utf-8-mcs-er)
737 (www-display-object-desc
738 (car ret) (cdr ret) (cdr (assq 'feature target))
745 (princ (format "mode=%S\n" mode))
746 (princ (format "user=%s\n" user))
747 ;; (princ (format "local user=%s\n" (user-login-name)))
748 (princ (format "lang=%S\n" lang))
749 (princ (encode-coding-string (emacs-version) 'utf-8-jp-er))
751 ;; (princ xemacs-chise-version)
757 (princ (format "%S" err)))
760 (defun www-batch-view-smart ()
761 (setq debug-on-error t)
762 (setq terminal-coding-system 'binary)
764 (let* ((est-hide-cgi-mode t)
765 (target (pop command-line-args-left))
766 (user (pop command-line-args-left))
767 (accept-language (pop command-line-args-left))
768 (mode (intern (pop command-line-args-left)))
773 (car (split-string accept-language ","))
776 ret genre feature obj-url json obj)
779 (when (string-match "/data\\.json$" target)
781 target (substring target 0 (match-beginning 0))))
782 (when (string-match "^char/\\(&[^&;]+;\\)" target)
783 (setq ret (match-end 0))
786 (www-uri-encode-object
787 (www-uri-decode-object
788 'character (match-string 1 target)))
789 (substring target ret))))
793 (if (string-match "/" cell)
795 (setq genre (substring cell 0 (match-beginning 0))
796 ret (substring cell (match-end 0)))
798 (intern (decode-uri-string genre 'utf-8-mcs-er))
800 ((string-match "/feature=" ret)
801 (list (substring ret 0 (match-beginning 0))
802 (substring ret (match-end 0)))
804 ((string-match "...$.zoom-xywh=" ret)
805 (list (substring ret 0 (match-beginning 0))
807 (substring ret (match-end 0)))
811 (list (decode-uri-string cell 'utf-8-mcs-er)))
812 ;; (setq ret (split-string cell "/"))
814 ;; (decode-uri-string (car ret) 'utf-8-mcs-er))
817 (split-string target "&")))
818 (setq ret (car target))
820 (princ "Content-Type: application/json; charset=UTF-8
823 (princ "Content-Type: text/html; charset=UTF-8
825 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
826 \"http://www.w3.org/TR/html4/loose.dtd\">
830 ;; (princ (format "<p>%S, %S, %S</p>"
831 ;; (car ret)(nth 1 ret)(nth 2 ret)))
832 ;; (princ (format "// %S %S\n" ret json))
833 (cond ((or (eq (car ret) 'char)
834 (eq (car ret) 'character))
836 (setq obj (www-uri-decode-object
837 (car ret)(nth 1 ret)))
840 ;; (princ (encode-coding-string
841 ;; (format "// %S\n" obj)
842 ;; char-db-file-coding-system))
843 (char-db-json-char-data-with-variant obj 'printable)
844 (encode-coding-region
845 (point-min)(point-max)
846 char-db-file-coding-system)
847 (princ (buffer-string))
849 (www-display-object-desc
850 'character (nth 1 ret) (nth 2 ret)
855 ((eq (car ret) 'feature)
856 (www-display-feature-desc
857 (decode-uri-string (nth 1 ret) 'utf-8-mcs-er)
859 (nth 1 (nth 1 target))
863 ;; ((eq (car ret) 'image-resource)
865 ;; ;; ((string-match "^\\.iiif=" (nth 1 ret))
866 ;; ;; (setq obj-url (decode-uri-string
867 ;; ;; (substring (nth 1 ret) (match-end 0))
868 ;; ;; 'utf-8-mcs-er))
869 ;; ;; (setq obj (concord-images-add-iiif obj-url))
870 ;; ;; (www-display-object-desc
871 ;; ;; 'image-resource
872 ;; ;; (www-uri-encode-object obj)
875 ;; ;; (eq mode 'simple))
878 ;; (princ (nth 1 ret))
879 ;; (www-display-object-desc
880 ;; 'image-resource (nth 1 ret) (nth 2 ret)
882 ;; (eq mode 'simple))
886 (www-display-object-desc
887 (car ret) (nth 1 ret) (nth 2 ret)
895 (princ (format "mode=%S\n" mode))
896 (princ (format "user=%s\n" user))
897 ;; (princ (format "local user=%s\n" (user-login-name)))
898 (princ (format "lang=%S\n" lang))
899 (princ (encode-coding-string (emacs-version) 'utf-8-jp-er))
901 ;; (princ xemacs-chise-version)
908 (princ (format "%S" err)))
911 (provide 'cwiki-view)