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 item-code page char-num glyph-image-id
73 width height image-cobj base-image x y w h)
77 (setq without-header t))
79 (when uri-feature-name-to-edit
80 (setq feature-name-to-edit
81 (www-uri-decode-feature-name uri-feature-name-to-edit))
82 (setq ret (symbol-name feature-name-to-edit))
83 (if (string-match "\\*" ret)
84 (setq base-name-to-edit (intern
85 (substring ret 0 (match-beginning 0)))
86 metadata-name-to-edit (intern
87 (substring ret (match-end 0))))
88 (setq base-name-to-edit feature-name-to-edit))
89 (when (stringp editing-format)
90 (setq editing-format (intern editing-format))))
91 (when (and (eq genre 'character)
92 (= (length uri-object) 1))
93 (setq uri-object (www-uri-encode-object object)))
98 <style type=\"text/css\">
101 .ids { vertical-align: middle; font-size: 40px; line-height: 100%%; }
102 a { text-decoration: none; }
103 .ids a { color: black; }
104 ul { margin: 0 0; color: black; }
105 li { margin: 0 0 0 2em; }
106 .feature-name { font-family: sans-serif; font-weight: bold; }
107 .feature-name a { color: black; }
111 display: inline-block;
112 border-bottom: 1px dotted black;
115 .tooltip .tooltiptext {
121 background-color: black;
131 .value .image-list img { height: 320px; vertical-align: top; }
133 .list .tooltip:hover .tooltiptext {
140 src=\"http://hng.chise.org/openseadragon/openseadragon.min.js\"></script>
142 <title>EsT %s = %s</title>
145 (decode-uri-string uri-object 'utf-8-mcs-er))
148 (when (eq genre 'character)
149 (dolist (feature (char-feature-property '$object 'additional-features))
150 (mount-char-attribute-table
151 (char-feature-name-at-domain feature '$rev=latest))))
155 (if est-hide-cgi-mode
156 "<div style=\"text-align:right;\">
157 <a href=\"../../edit/view.cgi?%s=%s\">
158 <input type=\"submit\" value=\"Edit\" />
160 "<div style=\"text-align:right;\">
161 <a href=\"edit/view.cgi?%s=%s\">
162 <input type=\"submit\" value=\"Edit\" />
164 genre rdf-uri-object)
166 "<div style=\"text-align:right;\">
167 <a href=\"../view/%s/%s\">
168 <input type=\"submit\" value=\"Simple\" />
171 (if (string-match ":" uri-object)
173 (est-uri-encode-feature-name-body
174 (substring uri-object 0 (match-beginning 0)))
176 (est-uri-encode-feature-name-body
177 (substring uri-object (match-end 0))))))))
179 (format "<input type=\"submit\" value=\"New Account\" />
180 <a href=\"http://www.chise.org/est/rdf.cgi?%s=%s\">
181 <input type=\"submit\" value=\"RDF\" />
186 (if (eq genre 'character)
188 <a href=\"/est/view/%s/%s/data.json\">
189 <input type=\"submit\" value=\"JSON\" />
191 genre rdf-uri-object)
193 (when (setq parents (www-get-feature-value object '<-denotational))
194 (if (characterp parents)
195 (setq parents (list parents)))
196 (princ (format "<p>%s %s</p>\n<hr>\n"
197 (www-format-value-as-char-list parents)
198 (www-format-feature-name '->denotational lang))))
199 (when (setq parents (www-get-feature-value object '<-subsumptive))
200 (if (characterp parents)
201 (setq parents (list parents)))
202 (princ (format "<p>%s %s</p>\n<hr>\n"
203 (www-format-value-as-char-list parents)
204 (www-format-feature-name '->subsumptive lang))))
205 (when (eq genre 'character)
206 (setq GlyphWiki-id (char-GlyphWiki-id object)))
208 ((eq genre 'image-resource)
210 (if (setq ret (concord-object-get object '=location@iiif))
212 (car (concord-object-get object '<-image-segment)))
213 (format "<a href=\"%s...$.zoom-xywh=%d,%d,%d,%d\"
214 ><img alt=\"%s\" src=\"%s\" /></a>"
215 (www-uri-encode-object base-image)
216 (concord-object-get object 'image-offset-x)
217 (concord-object-get object 'image-offset-y)
218 (concord-object-get object 'image-width)
219 (concord-object-get object 'image-height)
221 (if (and image-selection
222 (string-match "\\([0-9]+\\),\\([0-9]+\\),\\([0-9]+\\),\\([0-9]+\\)" image-selection))
224 (setq x (string-to-int (match-string 1 image-selection))
225 y (string-to-int (match-string 2 image-selection))
226 w (string-to-int (match-string 3 image-selection))
227 h (string-to-int (match-string 4 image-selection)))
229 (concord-object-get object 'image-width)))
230 ;; (setq height (float
231 ;; (concord-object-get object 'image-height)))
232 (format "<div id=\"openseadragon1\"
233 style=\"width: 800px; height: 600px;\"></div>
235 <script type=\"text/javascript\">
237 viewer = OpenSeadragon({
238 id: \"openseadragon1\",
239 prefixUrl: \"http://hng.chise.org/openseadragon/images/\",
240 preserveViewport: true,
245 tileSources: [ \"%s/info.json\" ]
247 viewer.addHandler('open', function () {
248 var newBounds = new OpenSeadragon.Rect( %f, %f, %f, %f, 0 );
249 viewer.viewport.fitBounds(newBounds, true);
250 viewer.viewport.applyConstraints();
260 (format "<div id=\"openseadragon1\"
261 style=\"width: 800px; height: 600px;\"></div>
263 <script type=\"text/javascript\">
265 id: \"openseadragon1\",
266 prefixUrl: \"http://hng.chise.org/openseadragon/images/\",
267 preserveViewport: true,
272 tileSources: [ \"%s/info.json\" ]
277 (setq ret (concord-object-get object '=location))
278 (format "<img alt=\"%s\" src=\"%s\" />"
281 ((or (and (eq genre 'glyph-image)
283 (car (concord-object-get object '->image-resource))))
284 (and (eq genre 'character)
285 (setq ret (www-format-encode-string
286 (est-format-object object 'readable)))
288 "<img alt=\"SW-JIGUGE\\([45]\\)-\\([0-9][0-9][0-9]\\)\\([0-9][0-9]\\)"
290 (setq item-code (string-to-int (match-string 1 ret))
291 page (string-to-int (match-string 2 ret))
292 char-num (string-to-int (match-string 3 ret)))
294 (cond ((eq item-code 4)
296 (format "zinbun/toho/A024/A024%04d/char=%d"
297 (+ page 18) char-num))
301 (format "zinbun/toho/A020/A020%04d/char=%d"
302 (+ page 16) char-num))
305 (concord-decode-object '=id glyph-image-id 'glyph-image))
307 (car (concord-object-get image-cobj '->image-resource)))
309 (if (and (setq ret (concord-object-get image-cobj '=location@iiif))
311 (car (concord-object-get image-cobj '<-image-segment))))
313 (format "<a href=\"../image-resource/%s...$.zoom-xywh=%d,%d,%d,%d\"
314 ><img alt=\"%s\" src=\"%s\" /></a>"
315 (www-uri-encode-object base-image)
316 (concord-object-get image-cobj 'image-offset-x)
317 (concord-object-get image-cobj 'image-offset-y)
318 (concord-object-get image-cobj 'image-width)
319 (concord-object-get image-cobj 'image-height)
321 (setq ret (concord-object-get image-cobj '=location))
322 (princ (format "<img alt=\"%s\" src=\"%s\" />"
325 ((and (eq genre 'hng-card)
326 (setq ret (concord-object-get object '=hng-card))
327 (setq ret (symbol-name ret))
328 (string-match "\\([0-9]+\\)-\\([0-9]+\\)" ret))
331 "<img alt=\"HNG-card:%s\"
332 src=\"http://hng.chise.org/images/HNG/%03d/card/%04d.jpg\"
333 style=\"height: 480px;\" />"
335 (string-to-int (match-string 1 ret))
336 (string-to-int (match-string 2 ret))))
339 (setq ret (www-format-encode-string
340 (est-format-object object 'readable)))
342 "<img alt=\"HNG\\([0-9]+\\)-\\([0-9]+\\)[a-z]?\"" ret)
346 (string-to-int (match-string 1 ret))
347 (string-to-int (match-string 2 ret)))))
349 (format "hng-card/rep.id=%s" HNG-card-id)))
351 (format "<h%d>%s%s</h%d>\n"
355 (format "<a href=\"%s\">%s</a>"
356 ;; (if est-hide-cgi-mode
357 ;; "<a href=\"../%s\">%s</a>"
358 ;; "<a href=\"%s\">%s</a>")
359 (www-uri-make-object-url object uri-object)
364 "<a href=\"../%s\">%s</a>"
370 " <a href=\"http://glyphwiki.org/wiki/%s\"><img alt=\"%s\" src=\"http://glyphwiki.org/glyph/%s.50px.png\" /></a>"
372 GlyphWiki-id GlyphWiki-id)
378 (when feature-name-to-edit
379 (princ "<form action=\"set.cgi\" method=\"GET\">\n")
381 (encode-coding-string
382 (format "<p>(%s : <input type=\"text\" name=\"%s\"
383 size=\"30\" maxlength=\"30\" value=\"%s\">)</p>
386 (decode-uri-string uri-object 'utf-8-mcs-er))
388 (when (and HNG-card-id
389 (eq genre 'character)
391 (concord-decode-object
394 (put-char-attribute object 'sources@HNG/card (list HNG-card-cobj))
395 (if (setq ret (concord-object-get
397 '->glyph-image@zinbun/takuhon))
398 (put-char-attribute object 'sources@zinbun/takuhon ret))
403 (setq feature-name-to-display
404 (www-uri-decode-feature-name uri-feature-name))
405 (setq est-eval-list-feature-items-limit nil)
407 (cons feature-name-to-display
408 (if (eq genre 'character)
409 (get-char-attribute object feature-name-to-display)
410 (concord-object-get object feature-name-to-display)))))
412 (if (eq genre 'character)
413 (char-attribute-alist object)
414 (concord-object-spec object)))))
415 (when feature-name-to-edit
416 (unless (assq base-name-to-edit object-spec)
417 (setq object-spec (cons (cons base-name-to-edit nil)
419 (dolist (cell (sort object-spec
421 (char-attribute-name<
422 (char-feature-name-sans-versions (car a))
423 (char-feature-name-sans-versions (car b))))))
424 (setq logical-feature (char-feature-name-sans-versions (car cell)))
425 (unless (memq logical-feature chise-wiki-displayed-features)
426 (push logical-feature chise-wiki-displayed-features)
428 ((and feature-name-to-edit
429 (eq (car cell) feature-name-to-edit))
430 (www-edit-display-feature-input-box
431 object feature-name-to-edit editing-format)
436 "<div class=\"feature\" style=\"line-height:150%\">\n"
439 (www-format-eval-list
440 (www-feature-format logical-feature)
442 logical-feature ; (car cell)
447 (format " <a href=\"%s?%s=%s&feature=%s&format=wiki-text\"
448 ><input type=\"submit\" value=\"note\" /></a>"
451 (www-format-encode-string uri-object)
452 (www-format-encode-string
453 (www-uri-encode-feature-name
454 (intern (format "%s*note"
455 logical-feature ; (car cell)
457 (when (and feature-name-to-edit
458 (eq base-name-to-edit (car cell)) metadata-name-to-edit)
461 (www-edit-display-feature-input-box
462 object feature-name-to-edit editing-format)
475 (when feature-name-to-edit
479 (format "<a href=\"%s?%s=%s\"
480 ><input type=\"submit\" value=\"add feature\" /></a>
484 (www-format-encode-string uri-object))))
489 (when (eq genre 'character)
490 (let ((object-str (est-format-object object))
491 encoded-object-for-form)
493 "<form action=\"http://www.chise.org/ids-find\">\n")
494 (princ (www-format-encode-string object-str))
495 (setq encoded-object-for-form
497 (insert (encode-coding-string object-str 'utf-8-jp-er))
498 (goto-char (point-min))
499 (while (search-forward ">-" nil t)
500 (replace-match "&GT-" t t)
505 " <input type=\"text\" name=\"components\"
506 size=\"30\" maxlength=\"30\" value=\"%s\" />"
507 encoded-object-for-form))
509 (www-format-encode-string
510 "を\u542Bむ\u6F22\u5B57を\u63A2す"))
511 (princ " <input type=\"submit\" value=\"search\" />\n")
515 "<form action=\"http://www.chise.org/hng-ids-find\">\n")
516 (princ (www-format-encode-string object-str))
520 " <input type=\"text\" name=\"components\"
521 size=\"30\" maxlength=\"30\" value=\"%s\" />"
522 encoded-object-for-form))
524 (www-format-encode-string
525 "を\u542Bむ HNG の\u6F22\u5B57を\u63A2す"))
526 (princ " <input type=\"submit\" value=\"search\" />\n")
535 (defun www-display-feature-desc (uri-feature-name genre uri-object
536 &optional lang simple)
537 (let ((rdf-uri-object (if est-hide-cgi-mode
538 (if (string-match "=" uri-object)
540 (est-uri-decode-feature-name-body
541 (substring uri-object 0 (match-beginning 0)))
543 (est-uri-decode-feature-name-body
544 (substring uri-object (match-end 0))))
546 (feature-name (www-uri-decode-feature-name uri-feature-name))
547 (name@lang (intern (format "name@%s" lang))))
549 (encode-coding-string
551 <title>EsT feature: %s</title>
559 (if est-hide-cgi-mode
560 "<div style=\"text-align:right;\">
561 <a href=\"../../../edit/view.cgi?feature=%s&%s=%s\">
562 <input type=\"submit\" value=\"Edit\" />
564 <input type=\"submit\" value=\"New Account\" />
567 "<div style=\"text-align:right;\">
568 <a href=\"edit/view.cgi?feature=%s&%s=%s\">
569 <input type=\"submit\" value=\"Edit\" />
571 <input type=\"submit\" value=\"New Account\" />
574 uri-feature-name genre rdf-uri-object)
576 "<div style=\"text-align:right;\">
577 <a href=\"../view/feature/%s&%s/%s\">
578 <input type=\"submit\" value=\"Simple\" />
582 uri-feature-name genre uri-object)))
584 (format "<h1>%s</h1>\n"
585 (www-format-encode-string
586 (symbol-name feature-name))))
587 (princ (format "<p>name : %s "
588 (or (www-format-feature-name feature-name) "")))
592 " <a href=\"%s?feature=%s&property=name&format=string&%s=%s\">"
597 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
602 (www-format-encode-string
605 (or (char-feature-property feature-name name@lang) ""))))
609 " <a href=\"%s?feature=%s&property=%s&format=string&%s=%s\">"
615 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
617 (www-html-display-paragraph
619 (or (www-feature-type feature-name)
620 ;; (char-feature-property feature-name 'type)
622 (princ (format "<p>value-format : %s "
625 (or (www-feature-value-format feature-name)
633 " <a href=\"%s?feature=%s&property=value-format&format=wiki-text&%s=%s\"
639 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
642 (princ (format "<p>value-presentation-format : %s "
644 nil 'value-presentation-format
645 (or (www-feature-value-format feature-name)
653 " <a href=\"%s?feature=%s&property=value-presentation-format&format=wiki-text&%s=%s\"
659 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
662 (princ "<p>format : ")
663 (www-html-display-text
664 (decode-coding-string
666 (www-feature-format feature-name))
671 " <a href=\"%s?feature=%s&property=format&format=wiki-text&%s=%s\"
677 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
680 (www-html-display-paragraph
681 (format "description : %s"
682 (or (decode-coding-string
683 (char-feature-property feature-name 'description)
687 (www-html-display-paragraph
688 (format "description@%s : %s"
690 (or (char-feature-property
692 (intern (format "description@%s" lang)))
696 (defun www-batch-view ()
697 (setq terminal-coding-system 'binary)
699 (let* ((target (pop command-line-args-left))
700 (user (pop command-line-args-left))
701 (accept-language (pop command-line-args-left))
702 (mode (intern (pop command-line-args-left)))
707 (car (split-string accept-language ","))
711 (princ "Content-Type: text/html; charset=UTF-8
713 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
714 \"http://www.w3.org/TR/html4/loose.dtd\">
719 (when (string-match "^char=\\(&[^&;]+;\\)" target)
720 (setq ret (match-end 0))
723 (www-uri-encode-object
724 (www-uri-decode-object
725 'character (match-string 1 target)))
726 (substring target ret))))
728 (mapcar (lambda (cell)
729 (if (string-match "=" cell)
731 (setq genre (substring cell 0 (match-beginning 0))
732 ret (substring cell (match-end 0)))
735 (decode-uri-string genre 'utf-8-mcs-er))
737 (list (decode-uri-string cell 'utf-8-mcs-er))))
738 (split-string target "&")))
739 (setq ret (car target))
740 (cond ((eq (car ret) 'char)
741 (www-display-object-desc
742 'character (cdr ret) (cdr (assq 'feature target))
747 ((eq (car ret) 'feature)
748 (www-display-feature-desc
749 (decode-uri-string (cdr ret) 'utf-8-mcs-er)
756 (www-display-object-desc
757 (car ret) (cdr ret) (cdr (assq 'feature target))
764 (princ (format "mode=%S\n" mode))
765 (princ (format "user=%s\n" user))
766 ;; (princ (format "local user=%s\n" (user-login-name)))
767 (princ (format "lang=%S\n" lang))
768 (princ (encode-coding-string (emacs-version) 'utf-8-jp-er))
770 ;; (princ xemacs-chise-version)
776 (princ (format "%S" err)))
779 (defun www-batch-view-smart ()
780 (setq debug-on-error t)
781 (setq terminal-coding-system 'binary)
783 (let* ((est-hide-cgi-mode t)
784 (target (pop command-line-args-left))
785 (user (pop command-line-args-left))
786 (accept-language (pop command-line-args-left))
787 (mode (intern (pop command-line-args-left)))
792 (car (split-string accept-language ","))
795 ret genre feature obj-url json obj)
798 (when (string-match "/data\\.json$" target)
800 target (substring target 0 (match-beginning 0))))
801 (when (string-match "^char/\\(&[^&;]+;\\)" target)
802 (setq ret (match-end 0))
805 (www-uri-encode-object
806 (www-uri-decode-object
807 'character (match-string 1 target)))
808 (substring target ret))))
812 (if (string-match "/" cell)
814 (setq genre (substring cell 0 (match-beginning 0))
815 ret (substring cell (match-end 0)))
817 (intern (decode-uri-string genre 'utf-8-mcs-er))
819 ((string-match "/feature=" ret)
820 (list (substring ret 0 (match-beginning 0))
821 (substring ret (match-end 0)))
823 ((string-match "...$.zoom-xywh=" ret)
824 (list (substring ret 0 (match-beginning 0))
826 (substring ret (match-end 0)))
830 (list (decode-uri-string cell 'utf-8-mcs-er)))
831 ;; (setq ret (split-string cell "/"))
833 ;; (decode-uri-string (car ret) 'utf-8-mcs-er))
836 (split-string target "&")))
837 (setq ret (car target))
839 (princ "Content-Type: application/json; charset=UTF-8
842 (princ "Content-Type: text/html; charset=UTF-8
844 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
845 \"http://www.w3.org/TR/html4/loose.dtd\">
849 ;; (princ (format "<p>%S, %S, %S</p>"
850 ;; (car ret)(nth 1 ret)(nth 2 ret)))
851 ;; (princ (format "// %S %S\n" ret json))
852 (cond ((or (eq (car ret) 'char)
853 (eq (car ret) 'character))
855 (setq obj (www-uri-decode-object
856 (car ret)(nth 1 ret)))
859 ;; (princ (encode-coding-string
860 ;; (format "// %S\n" obj)
861 ;; char-db-file-coding-system))
862 (char-db-json-char-data-with-variant obj 'printable)
863 (encode-coding-region
864 (point-min)(point-max)
865 char-db-file-coding-system)
866 (princ (buffer-string))
868 (www-display-object-desc
869 'character (nth 1 ret) (nth 2 ret)
874 ((eq (car ret) 'feature)
875 (www-display-feature-desc
876 (decode-uri-string (nth 1 ret) 'utf-8-mcs-er)
878 (nth 1 (nth 1 target))
882 ;; ((eq (car ret) 'image-resource)
884 ;; ;; ((string-match "^\\.iiif=" (nth 1 ret))
885 ;; ;; (setq obj-url (decode-uri-string
886 ;; ;; (substring (nth 1 ret) (match-end 0))
887 ;; ;; 'utf-8-mcs-er))
888 ;; ;; (setq obj (concord-images-add-iiif obj-url))
889 ;; ;; (www-display-object-desc
890 ;; ;; 'image-resource
891 ;; ;; (www-uri-encode-object obj)
894 ;; ;; (eq mode 'simple))
897 ;; (princ (nth 1 ret))
898 ;; (www-display-object-desc
899 ;; 'image-resource (nth 1 ret) (nth 2 ret)
901 ;; (eq mode 'simple))
905 (www-display-object-desc
906 (car ret) (nth 1 ret) (nth 2 ret)
914 (princ (format "mode=%S\n" mode))
915 (princ (format "user=%s\n" user))
916 ;; (princ (format "local user=%s\n" (user-login-name)))
917 (princ (format "lang=%S\n" lang))
918 (princ (encode-coding-string (emacs-version) 'utf-8-jp-er))
920 ;; (princ xemacs-chise-version)
927 (princ (format "%S" err)))
930 (provide 'cwiki-view)