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\" />"
228 (setq ret (www-format-encode-string
229 (est-format-object object 'readable)))
232 "<img alt=\"HNG\\([0-9]+\\)-\\([0-9]+\\)\"" ret)
233 (format "HNG/%s/cards/%s.jpg"
235 (match-string 2 ret))))
237 (format "<h%d>%s%s</h%d>\n"
241 (format "<a href=\"%s\">%s</a>"
242 ;; (if est-hide-cgi-mode
243 ;; "<a href=\"../%s\">%s</a>"
244 ;; "<a href=\"%s\">%s</a>")
245 (www-uri-make-object-url object uri-object)
250 "<a href=\"http://hng.chise.org/images/%s\">%s</a>"
256 " <a href=\"http://glyphwiki.org/wiki/%s\"><img alt=\"%s\" src=\"http://glyphwiki.org/glyph/%s.50px.png\" /></a>"
258 GlyphWiki-id GlyphWiki-id)
264 (when feature-name-to-edit
265 (princ "<form action=\"set.cgi\" method=\"GET\">\n")
267 (encode-coding-string
268 (format "<p>(%s : <input type=\"text\" name=\"%s\"
269 size=\"30\" maxlength=\"30\" value=\"%s\">)</p>
272 (decode-uri-string uri-object 'utf-8-mcs-er))
277 (setq feature-name-to-display
278 (www-uri-decode-feature-name uri-feature-name))
279 (setq est-eval-list-feature-items-limit nil)
281 (cons feature-name-to-display
282 (if (eq genre 'character)
283 (get-char-attribute object feature-name-to-display)
284 (concord-object-get object feature-name-to-display)))))
286 (if (eq genre 'character)
287 (char-attribute-alist object)
288 (concord-object-spec object)))))
289 (when feature-name-to-edit
290 (unless (assq base-name-to-edit object-spec)
291 (setq object-spec (cons (cons base-name-to-edit nil)
293 (dolist (cell (sort object-spec
295 (char-attribute-name<
296 (char-feature-name-sans-versions (car a))
297 (char-feature-name-sans-versions (car b))))))
298 (setq logical-feature (char-feature-name-sans-versions (car cell)))
299 (unless (memq logical-feature chise-wiki-displayed-features)
300 (push logical-feature chise-wiki-displayed-features)
302 ((and feature-name-to-edit
303 (eq (car cell) feature-name-to-edit))
304 (www-edit-display-feature-input-box
305 object feature-name-to-edit editing-format)
310 "<div class=\"feature\" style=\"line-height:150%\">\n"
313 (www-format-eval-list
314 (www-feature-format logical-feature)
316 logical-feature ; (car cell)
321 (format " <a href=\"%s?%s=%s&feature=%s&format=wiki-text\"
322 ><input type=\"submit\" value=\"note\" /></a>"
325 (www-format-encode-string uri-object)
326 (www-format-encode-string
327 (www-uri-encode-feature-name
328 (intern (format "%s*note"
329 logical-feature ; (car cell)
331 (when (and feature-name-to-edit
332 (eq base-name-to-edit (car cell)) metadata-name-to-edit)
335 (www-edit-display-feature-input-box
336 object feature-name-to-edit editing-format)
349 (when feature-name-to-edit
353 (format "<a href=\"%s?%s=%s\"
354 ><input type=\"submit\" value=\"add feature\" /></a>
358 (www-format-encode-string uri-object))))
363 (when (eq genre 'character)
365 "<form action=\"http://www.chise.org/ids-find\">\n")
367 (www-format-encode-string
368 (est-format-object object)
369 ;; (if (eq genre 'character)
370 ;; (format "%c" object)
371 ;; (format "%s" (concord-object-id object)))
375 " <input type=\"text\" name=\"components\"
376 size=\"30\" maxlength=\"30\" value=\"%s\" />"
377 (encode-coding-string
378 (est-format-object object)
379 ;; (if (eq genre 'character)
380 ;; (char-to-string object)
381 ;; (format "%s" (concord-object-id object)))
384 (www-format-encode-string
385 "を\u542Bむ\u6F22\u5B57を\u63A2す"))
386 (princ " <input type=\"submit\" value=\"search\" />\n")
390 "<form action=\"http://www.chise.org/hng-ids-find\">\n")
392 (www-format-encode-string
393 (est-format-object object)
394 ;; (if (eq genre 'character)
395 ;; (format "%c" object)
396 ;; (format "%s" (concord-object-id object)))
400 " <input type=\"text\" name=\"components\"
401 size=\"30\" maxlength=\"30\" value=\"%s\" />"
402 (encode-coding-string
403 (est-format-object object)
404 ;; (if (eq genre 'character)
405 ;; (char-to-string object)
406 ;; (format "%s" (concord-object-id object)))
409 (www-format-encode-string
410 "を\u542Bむ HNG の\u6F22\u5B57を\u63A2す"))
411 (princ " <input type=\"submit\" value=\"search\" />\n")
420 (defun www-display-feature-desc (uri-feature-name genre uri-object
421 &optional lang simple)
422 (let ((rdf-uri-object (if est-hide-cgi-mode
423 (if (string-match "=" uri-object)
425 (est-uri-decode-feature-name-body
426 (substring uri-object 0 (match-beginning 0)))
428 (est-uri-decode-feature-name-body
429 (substring uri-object (match-end 0))))
431 (feature-name (www-uri-decode-feature-name uri-feature-name))
432 (name@lang (intern (format "name@%s" lang))))
434 (encode-coding-string
436 <title>EsT feature: %s</title>
444 (if est-hide-cgi-mode
445 "<div style=\"text-align:right;\">
446 <a href=\"../../../edit/view.cgi?feature=%s&%s=%s\">
447 <input type=\"submit\" value=\"Edit\" />
449 <input type=\"submit\" value=\"New Account\" />
452 "<div style=\"text-align:right;\">
453 <a href=\"edit/view.cgi?feature=%s&%s=%s\">
454 <input type=\"submit\" value=\"Edit\" />
456 <input type=\"submit\" value=\"New Account\" />
459 uri-feature-name genre rdf-uri-object)
461 "<div style=\"text-align:right;\">
462 <a href=\"../view/feature/%s&%s/%s\">
463 <input type=\"submit\" value=\"Simple\" />
467 uri-feature-name genre uri-object)))
469 (format "<h1>%s</h1>\n"
470 (www-format-encode-string
471 (symbol-name feature-name))))
472 (princ (format "<p>name : %s "
473 (or (www-format-feature-name feature-name) "")))
477 " <a href=\"%s?feature=%s&property=name&format=string&%s=%s\">"
482 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
487 (www-format-encode-string
490 (or (char-feature-property feature-name name@lang) ""))))
494 " <a href=\"%s?feature=%s&property=%s&format=string&%s=%s\">"
500 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
502 (www-html-display-paragraph
504 (or (www-feature-type feature-name)
505 ;; (char-feature-property feature-name 'type)
507 (princ (format "<p>value-format : %s "
510 (or (www-feature-value-format feature-name)
518 " <a href=\"%s?feature=%s&property=value-format&format=wiki-text&%s=%s\"
524 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
527 (princ (format "<p>value-presentation-format : %s "
529 nil 'value-presentation-format
530 (or (www-feature-value-format feature-name)
538 " <a href=\"%s?feature=%s&property=value-presentation-format&format=wiki-text&%s=%s\"
544 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
547 (princ "<p>format : ")
548 (www-html-display-text
549 (decode-coding-string
551 (www-feature-format feature-name))
556 " <a href=\"%s?feature=%s&property=format&format=wiki-text&%s=%s\"
562 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
565 (www-html-display-paragraph
566 (format "description : %s"
567 (or (decode-coding-string
568 (char-feature-property feature-name 'description)
572 (www-html-display-paragraph
573 (format "description@%s : %s"
575 (or (char-feature-property
577 (intern (format "description@%s" lang)))
581 (defun www-batch-view ()
582 (setq terminal-coding-system 'binary)
584 (let* ((target (pop command-line-args-left))
585 (user (pop command-line-args-left))
586 (accept-language (pop command-line-args-left))
587 (mode (intern (pop command-line-args-left)))
592 (car (split-string accept-language ","))
596 (princ "Content-Type: text/html; charset=UTF-8
598 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
599 \"http://www.w3.org/TR/html4/loose.dtd\">
604 (when (string-match "^char=\\(&[^&;]+;\\)" target)
605 (setq ret (match-end 0))
608 (www-uri-encode-object
609 (www-uri-decode-object
610 'character (match-string 1 target)))
611 (substring target ret))))
613 (mapcar (lambda (cell)
614 (if (string-match "=" cell)
616 (setq genre (substring cell 0 (match-beginning 0))
617 ret (substring cell (match-end 0)))
620 (decode-uri-string genre 'utf-8-mcs-er))
622 (list (decode-uri-string cell 'utf-8-mcs-er))))
623 (split-string target "&")))
624 (setq ret (car target))
625 (cond ((eq (car ret) 'char)
626 (www-display-object-desc
627 'character (cdr ret) (cdr (assq 'feature target))
632 ((eq (car ret) 'feature)
633 (www-display-feature-desc
634 (decode-uri-string (cdr ret) 'utf-8-mcs-er)
641 (www-display-object-desc
642 (car ret) (cdr ret) (cdr (assq 'feature target))
649 (princ (format "mode=%S\n" mode))
650 (princ (format "user=%s\n" user))
651 ;; (princ (format "local user=%s\n" (user-login-name)))
652 (princ (format "lang=%S\n" lang))
653 (princ (encode-coding-string (emacs-version) 'utf-8-jp-er))
655 ;; (princ xemacs-chise-version)
661 (princ (format "%S" err)))
664 (defun www-batch-view-smart ()
665 (setq debug-on-error t)
666 (setq terminal-coding-system 'binary)
668 (let* ((est-hide-cgi-mode t)
669 (target (pop command-line-args-left))
670 (user (pop command-line-args-left))
671 (accept-language (pop command-line-args-left))
672 (mode (intern (pop command-line-args-left)))
677 (car (split-string accept-language ","))
680 ret genre feature obj-url json obj)
683 (when (string-match "/data\\.json$" target)
685 target (substring target 0 (match-beginning 0))))
686 (when (string-match "^char/\\(&[^&;]+;\\)" target)
687 (setq ret (match-end 0))
690 (www-uri-encode-object
691 (www-uri-decode-object
692 'character (match-string 1 target)))
693 (substring target ret))))
697 (if (string-match "/" cell)
699 (setq genre (substring cell 0 (match-beginning 0))
700 ret (substring cell (match-end 0)))
702 (intern (decode-uri-string genre 'utf-8-mcs-er))
703 (if (string-match "/feature=" ret)
704 (list (substring ret 0 (match-beginning 0))
705 (substring ret (match-end 0)))
707 (list (decode-uri-string cell 'utf-8-mcs-er)))
708 ;; (setq ret (split-string cell "/"))
710 ;; (decode-uri-string (car ret) 'utf-8-mcs-er))
713 (split-string target "&")))
714 (setq ret (car target))
716 (princ "Content-Type: application/json; charset=UTF-8
719 (princ "Content-Type: text/html; charset=UTF-8
721 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
722 \"http://www.w3.org/TR/html4/loose.dtd\">
726 ;; (princ (format "<p>%S, %S, %S</p>"
727 ;; (car ret)(nth 1 ret)(nth 2 ret)))
728 ;; (princ (format "// %S %S\n" ret json))
729 (cond ((or (eq (car ret) 'char)
730 (eq (car ret) 'character))
732 (setq obj (www-uri-decode-object
733 (car ret)(nth 1 ret)))
736 ;; (princ (encode-coding-string
737 ;; (format "// %S\n" obj)
738 ;; char-db-file-coding-system))
739 (char-db-json-char-data-with-variant obj 'printable)
740 (encode-coding-region
741 (point-min)(point-max)
742 char-db-file-coding-system)
743 (princ (buffer-string))
745 (www-display-object-desc
746 'character (nth 1 ret) (nth 2 ret)
751 ((eq (car ret) 'feature)
752 (www-display-feature-desc
753 (decode-uri-string (nth 1 ret) 'utf-8-mcs-er)
755 (nth 1 (nth 1 target))
759 ;; ((eq (car ret) 'image-resource)
761 ;; ;; ((string-match "^\\.iiif=" (nth 1 ret))
762 ;; ;; (setq obj-url (decode-uri-string
763 ;; ;; (substring (nth 1 ret) (match-end 0))
764 ;; ;; 'utf-8-mcs-er))
765 ;; ;; (setq obj (concord-images-add-iiif obj-url))
766 ;; ;; (www-display-object-desc
767 ;; ;; 'image-resource
768 ;; ;; (www-uri-encode-object obj)
771 ;; ;; (eq mode 'simple))
774 ;; (princ (nth 1 ret))
775 ;; (www-display-object-desc
776 ;; 'image-resource (nth 1 ret) (nth 2 ret)
778 ;; (eq mode 'simple))
782 (www-display-object-desc
783 (car ret) (nth 1 ret) (nth 2 ret)
791 (princ (format "mode=%S\n" mode))
792 (princ (format "user=%s\n" user))
793 ;; (princ (format "local user=%s\n" (user-login-name)))
794 (princ (format "lang=%S\n" lang))
795 (princ (encode-coding-string (emacs-version) 'utf-8-jp-er))
797 ;; (princ xemacs-chise-version)
804 (princ (format "%S" err)))
807 (provide 'cwiki-view)