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 ret object-spec)
75 (setq without-header t))
77 (when uri-feature-name-to-edit
78 (setq feature-name-to-edit
79 (www-uri-decode-feature-name uri-feature-name-to-edit))
80 (setq ret (symbol-name feature-name-to-edit))
81 (if (string-match "\\*" ret)
82 (setq base-name-to-edit (intern
83 (substring ret 0 (match-beginning 0)))
84 metadata-name-to-edit (intern
85 (substring ret (match-end 0))))
86 (setq base-name-to-edit feature-name-to-edit))
87 (when (stringp editing-format)
88 (setq editing-format (intern editing-format))))
89 (when (and (eq genre 'character)
90 (= (length uri-object) 1))
91 (setq uri-object (www-uri-encode-object object)))
96 <style type=\"text/css\">
99 .ids { vertical-align: middle; font-size: 40px; line-height: 100%%; }
100 a { text-decoration: none; }
101 .ids a { color: black; }
102 ul { margin: 0 0; color: black; }
103 li { margin: 0 0 0 2em; }
104 .feature-name { font-family: sans-serif; font-weight: bold; }
105 .feature-name a { color: black; }
109 display: inline-block;
110 border-bottom: 1px dotted black;
113 .tooltip .tooltiptext {
119 background-color: black;
129 .list .tooltip:hover .tooltiptext {
136 src=\"http://hng.chise.org/openseadragon/openseadragon.min.js\"></script>
138 <title>EsT %s = %s</title>
141 (decode-uri-string uri-object 'utf-8-mcs-er))
144 (when (eq genre 'character)
145 (dolist (feature (char-feature-property '$object 'additional-features))
146 (mount-char-attribute-table
147 (char-feature-name-at-domain feature '$rev=latest))))
151 (if est-hide-cgi-mode
152 "<div style=\"text-align:right;\">
153 <a href=\"../../edit/view.cgi?%s=%s\">
154 <input type=\"submit\" value=\"Edit\" />
156 "<div style=\"text-align:right;\">
157 <a href=\"edit/view.cgi?%s=%s\">
158 <input type=\"submit\" value=\"Edit\" />
160 genre rdf-uri-object)
162 "<div style=\"text-align:right;\">
163 <a href=\"../view/%s/%s\">
164 <input type=\"submit\" value=\"Simple\" />
167 (if (string-match ":" uri-object)
169 (est-uri-encode-feature-name-body
170 (substring uri-object 0 (match-beginning 0)))
172 (est-uri-encode-feature-name-body
173 (substring uri-object (match-end 0))))))))
175 (format "<input type=\"submit\" value=\"New Account\" />
176 <a href=\"http://www.chise.org/est/rdf.cgi?%s=%s\">
177 <input type=\"submit\" value=\"RDF\" />
182 (if (eq genre 'character)
184 <a href=\"/est/view/%s/%s/data.json\">
185 <input type=\"submit\" value=\"JSON\" />
187 genre rdf-uri-object)
189 (when (setq parents (www-get-feature-value object '<-denotational))
190 (princ (format "<p>%s %s</p>\n<hr>\n"
191 (www-format-value-as-char-list parents)
192 (www-format-feature-name '->denotational lang))))
193 (when (setq parents (www-get-feature-value object '<-subsumptive))
194 (princ (format "<p>%s %s</p>\n<hr>\n"
195 (www-format-value-as-char-list parents)
196 (www-format-feature-name '->subsumptive lang))))
197 (when (eq genre 'character)
198 (setq GlyphWiki-id (char-GlyphWiki-id object)))
200 ((eq genre 'image-resource)
202 (if (setq ret (concord-object-get object '=location@iiif))
203 (if (concord-object-get object 'image-offset-x)
204 (format "<img alt=\"%s\" src=\"%s\" />"
206 (format "<div id=\"openseadragon1\"
207 style=\"width: 800px; height: 600px;\"></div>
209 <script type=\"text/javascript\">
211 id: \"openseadragon1\",
212 prefixUrl: \"http://hng.chise.org/openseadragon/images/\",
213 preserveViewport: true,
218 tileSources: [ \"%s/info.json\" ]
223 (setq ret (concord-object-get object '=location))
224 (format "<img alt=\"%s\" src=\"%s\" />"
227 ((and (eq genre 'hng-card)
228 (setq ret (concord-object-get object '=hng-card))
229 (setq ret (symbol-name ret))
230 (string-match "\\([0-9]+\\)-\\([0-9]+\\)" ret))
233 "<img alt=\"HNG-card:%s\"
234 src=\"http://hng.chise.org/images/HNG/%03d/cards/%04d.jpg\"
235 style=\"height: 480px;\" />"
237 (string-to-int (match-string 1 ret))
238 (string-to-int (match-string 2 ret))))
241 (setq ret (www-format-encode-string
242 (est-format-object object 'readable)))
245 "<img alt=\"HNG\\([0-9]+\\)-\\([0-9]+\\)\"" ret)
246 (format "HNG/%s/cards/%s.jpg"
248 (match-string 2 ret))))
250 (format "<h%d>%s%s</h%d>\n"
254 (format "<a href=\"%s\">%s</a>"
255 ;; (if est-hide-cgi-mode
256 ;; "<a href=\"../%s\">%s</a>"
257 ;; "<a href=\"%s\">%s</a>")
258 (www-uri-make-object-url object uri-object)
263 "<a href=\"http://hng.chise.org/images/%s\">%s</a>"
269 " <a href=\"http://glyphwiki.org/wiki/%s\"><img alt=\"%s\" src=\"http://glyphwiki.org/glyph/%s.50px.png\" /></a>"
271 GlyphWiki-id GlyphWiki-id)
277 (when feature-name-to-edit
278 (princ "<form action=\"set.cgi\" method=\"GET\">\n")
280 (encode-coding-string
281 (format "<p>(%s : <input type=\"text\" name=\"%s\"
282 size=\"30\" maxlength=\"30\" value=\"%s\">)</p>
285 (decode-uri-string uri-object 'utf-8-mcs-er))
290 (setq feature-name-to-display
291 (www-uri-decode-feature-name uri-feature-name))
292 (setq est-eval-list-feature-items-limit nil)
294 (cons feature-name-to-display
295 (if (eq genre 'character)
296 (get-char-attribute object feature-name-to-display)
297 (concord-object-get object feature-name-to-display)))))
299 (if (eq genre 'character)
300 (char-attribute-alist object)
301 (concord-object-spec object)))))
302 (when feature-name-to-edit
303 (unless (assq base-name-to-edit object-spec)
304 (setq object-spec (cons (cons base-name-to-edit nil)
306 (dolist (cell (sort object-spec
308 (char-attribute-name<
309 (char-feature-name-sans-versions (car a))
310 (char-feature-name-sans-versions (car b))))))
311 (setq logical-feature (char-feature-name-sans-versions (car cell)))
312 (unless (memq logical-feature chise-wiki-displayed-features)
313 (push logical-feature chise-wiki-displayed-features)
315 ((and feature-name-to-edit
316 (eq (car cell) feature-name-to-edit))
317 (www-edit-display-feature-input-box
318 object feature-name-to-edit editing-format)
323 "<div class=\"feature\" style=\"line-height:150%\">\n"
326 (www-format-eval-list
327 (www-feature-format logical-feature)
329 logical-feature ; (car cell)
334 (format " <a href=\"%s?%s=%s&feature=%s&format=wiki-text\"
335 ><input type=\"submit\" value=\"note\" /></a>"
338 (www-format-encode-string uri-object)
339 (www-format-encode-string
340 (www-uri-encode-feature-name
341 (intern (format "%s*note"
342 logical-feature ; (car cell)
344 (when (and feature-name-to-edit
345 (eq base-name-to-edit (car cell)) metadata-name-to-edit)
348 (www-edit-display-feature-input-box
349 object feature-name-to-edit editing-format)
362 (when feature-name-to-edit
366 (format "<a href=\"%s?%s=%s\"
367 ><input type=\"submit\" value=\"add feature\" /></a>
371 (www-format-encode-string uri-object))))
376 (when (eq genre 'character)
378 "<form action=\"http://www.chise.org/ids-find\">\n")
380 (www-format-encode-string
381 (est-format-object object)
382 ;; (if (eq genre 'character)
383 ;; (format "%c" object)
384 ;; (format "%s" (concord-object-id object)))
388 " <input type=\"text\" name=\"components\"
389 size=\"30\" maxlength=\"30\" value=\"%s\" />"
390 (encode-coding-string
391 (est-format-object object)
392 ;; (if (eq genre 'character)
393 ;; (char-to-string object)
394 ;; (format "%s" (concord-object-id object)))
397 (www-format-encode-string
398 "を\u542Bむ\u6F22\u5B57を\u63A2す"))
399 (princ " <input type=\"submit\" value=\"search\" />\n")
403 "<form action=\"http://www.chise.org/hng-ids-find\">\n")
405 (www-format-encode-string
406 (est-format-object object)
407 ;; (if (eq genre 'character)
408 ;; (format "%c" object)
409 ;; (format "%s" (concord-object-id object)))
413 " <input type=\"text\" name=\"components\"
414 size=\"30\" maxlength=\"30\" value=\"%s\" />"
415 (encode-coding-string
416 (est-format-object object)
417 ;; (if (eq genre 'character)
418 ;; (char-to-string object)
419 ;; (format "%s" (concord-object-id object)))
422 (www-format-encode-string
423 "を\u542Bむ HNG の\u6F22\u5B57を\u63A2す"))
424 (princ " <input type=\"submit\" value=\"search\" />\n")
433 (defun www-display-feature-desc (uri-feature-name genre uri-object
434 &optional lang simple)
435 (let ((rdf-uri-object (if est-hide-cgi-mode
436 (if (string-match "=" uri-object)
438 (est-uri-decode-feature-name-body
439 (substring uri-object 0 (match-beginning 0)))
441 (est-uri-decode-feature-name-body
442 (substring uri-object (match-end 0))))
444 (feature-name (www-uri-decode-feature-name uri-feature-name))
445 (name@lang (intern (format "name@%s" lang))))
447 (encode-coding-string
449 <title>EsT feature: %s</title>
457 (if est-hide-cgi-mode
458 "<div style=\"text-align:right;\">
459 <a href=\"../../../edit/view.cgi?feature=%s&%s=%s\">
460 <input type=\"submit\" value=\"Edit\" />
462 <input type=\"submit\" value=\"New Account\" />
465 "<div style=\"text-align:right;\">
466 <a href=\"edit/view.cgi?feature=%s&%s=%s\">
467 <input type=\"submit\" value=\"Edit\" />
469 <input type=\"submit\" value=\"New Account\" />
472 uri-feature-name genre rdf-uri-object)
474 "<div style=\"text-align:right;\">
475 <a href=\"../view/feature/%s&%s/%s\">
476 <input type=\"submit\" value=\"Simple\" />
480 uri-feature-name genre uri-object)))
482 (format "<h1>%s</h1>\n"
483 (www-format-encode-string
484 (symbol-name feature-name))))
485 (princ (format "<p>name : %s "
486 (or (www-format-feature-name feature-name) "")))
490 " <a href=\"%s?feature=%s&property=name&format=string&%s=%s\">"
495 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
500 (www-format-encode-string
503 (or (char-feature-property feature-name name@lang) ""))))
507 " <a href=\"%s?feature=%s&property=%s&format=string&%s=%s\">"
513 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
515 (www-html-display-paragraph
517 (or (www-feature-type feature-name)
518 ;; (char-feature-property feature-name 'type)
520 (princ (format "<p>value-format : %s "
523 (or (www-feature-value-format feature-name)
531 " <a href=\"%s?feature=%s&property=value-format&format=wiki-text&%s=%s\"
537 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
540 (princ (format "<p>value-presentation-format : %s "
542 nil 'value-presentation-format
543 (or (www-feature-value-format feature-name)
551 " <a href=\"%s?feature=%s&property=value-presentation-format&format=wiki-text&%s=%s\"
557 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
560 (princ "<p>format : ")
561 (www-html-display-text
562 (decode-coding-string
564 (www-feature-format feature-name))
569 " <a href=\"%s?feature=%s&property=format&format=wiki-text&%s=%s\"
575 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
578 (www-html-display-paragraph
579 (format "description : %s"
580 (or (decode-coding-string
581 (char-feature-property feature-name 'description)
585 (www-html-display-paragraph
586 (format "description@%s : %s"
588 (or (char-feature-property
590 (intern (format "description@%s" lang)))
594 (defun www-batch-view ()
595 (setq terminal-coding-system 'binary)
597 (let* ((target (pop command-line-args-left))
598 (user (pop command-line-args-left))
599 (accept-language (pop command-line-args-left))
600 (mode (intern (pop command-line-args-left)))
605 (car (split-string accept-language ","))
609 (princ "Content-Type: text/html; charset=UTF-8
611 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
612 \"http://www.w3.org/TR/html4/loose.dtd\">
617 (when (string-match "^char=\\(&[^&;]+;\\)" target)
618 (setq ret (match-end 0))
621 (www-uri-encode-object
622 (www-uri-decode-object
623 'character (match-string 1 target)))
624 (substring target ret))))
626 (mapcar (lambda (cell)
627 (if (string-match "=" cell)
629 (setq genre (substring cell 0 (match-beginning 0))
630 ret (substring cell (match-end 0)))
633 (decode-uri-string genre 'utf-8-mcs-er))
635 (list (decode-uri-string cell 'utf-8-mcs-er))))
636 (split-string target "&")))
637 (setq ret (car target))
638 (cond ((eq (car ret) 'char)
639 (www-display-object-desc
640 'character (cdr ret) (cdr (assq 'feature target))
645 ((eq (car ret) 'feature)
646 (www-display-feature-desc
647 (decode-uri-string (cdr ret) 'utf-8-mcs-er)
654 (www-display-object-desc
655 (car ret) (cdr ret) (cdr (assq 'feature target))
662 (princ (format "mode=%S\n" mode))
663 (princ (format "user=%s\n" user))
664 ;; (princ (format "local user=%s\n" (user-login-name)))
665 (princ (format "lang=%S\n" lang))
666 (princ (encode-coding-string (emacs-version) 'utf-8-jp-er))
668 ;; (princ xemacs-chise-version)
674 (princ (format "%S" err)))
677 (defun www-batch-view-smart ()
678 (setq debug-on-error t)
679 (setq terminal-coding-system 'binary)
681 (let* ((est-hide-cgi-mode t)
682 (target (pop command-line-args-left))
683 (user (pop command-line-args-left))
684 (accept-language (pop command-line-args-left))
685 (mode (intern (pop command-line-args-left)))
690 (car (split-string accept-language ","))
693 ret genre feature obj-url json obj)
696 (when (string-match "/data\\.json$" target)
698 target (substring target 0 (match-beginning 0))))
699 (when (string-match "^char/\\(&[^&;]+;\\)" target)
700 (setq ret (match-end 0))
703 (www-uri-encode-object
704 (www-uri-decode-object
705 'character (match-string 1 target)))
706 (substring target ret))))
710 (if (string-match "/" cell)
712 (setq genre (substring cell 0 (match-beginning 0))
713 ret (substring cell (match-end 0)))
715 (intern (decode-uri-string genre 'utf-8-mcs-er))
716 (if (string-match "/feature=" ret)
717 (list (substring ret 0 (match-beginning 0))
718 (substring ret (match-end 0)))
720 (list (decode-uri-string cell 'utf-8-mcs-er)))
721 ;; (setq ret (split-string cell "/"))
723 ;; (decode-uri-string (car ret) 'utf-8-mcs-er))
726 (split-string target "&")))
727 (setq ret (car target))
729 (princ "Content-Type: application/json; charset=UTF-8
732 (princ "Content-Type: text/html; charset=UTF-8
734 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
735 \"http://www.w3.org/TR/html4/loose.dtd\">
739 ;; (princ (format "<p>%S, %S, %S</p>"
740 ;; (car ret)(nth 1 ret)(nth 2 ret)))
741 ;; (princ (format "// %S %S\n" ret json))
742 (cond ((or (eq (car ret) 'char)
743 (eq (car ret) 'character))
745 (setq obj (www-uri-decode-object
746 (car ret)(nth 1 ret)))
749 ;; (princ (encode-coding-string
750 ;; (format "// %S\n" obj)
751 ;; char-db-file-coding-system))
752 (char-db-json-char-data-with-variant obj 'printable)
753 (encode-coding-region
754 (point-min)(point-max)
755 char-db-file-coding-system)
756 (princ (buffer-string))
758 (www-display-object-desc
759 'character (nth 1 ret) (nth 2 ret)
764 ((eq (car ret) 'feature)
765 (www-display-feature-desc
766 (decode-uri-string (nth 1 ret) 'utf-8-mcs-er)
768 (nth 1 (nth 1 target))
772 ;; ((eq (car ret) 'image-resource)
774 ;; ;; ((string-match "^\\.iiif=" (nth 1 ret))
775 ;; ;; (setq obj-url (decode-uri-string
776 ;; ;; (substring (nth 1 ret) (match-end 0))
777 ;; ;; 'utf-8-mcs-er))
778 ;; ;; (setq obj (concord-images-add-iiif obj-url))
779 ;; ;; (www-display-object-desc
780 ;; ;; 'image-resource
781 ;; ;; (www-uri-encode-object obj)
784 ;; ;; (eq mode 'simple))
787 ;; (princ (nth 1 ret))
788 ;; (www-display-object-desc
789 ;; 'image-resource (nth 1 ret) (nth 2 ret)
791 ;; (eq mode 'simple))
795 (www-display-object-desc
796 (car ret) (nth 1 ret) (nth 2 ret)
804 (princ (format "mode=%S\n" mode))
805 (princ (format "user=%s\n" user))
806 ;; (princ (format "local user=%s\n" (user-login-name)))
807 (princ (format "lang=%S\n" lang))
808 (princ (encode-coding-string (emacs-version) 'utf-8-jp-er))
810 ;; (princ xemacs-chise-version)
817 (princ (format "%S" err)))
820 (provide 'cwiki-view)