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)
464 (let ((object-str (est-format-object object))
465 encoded-object-for-form)
467 "<form action=\"http://www.chise.org/ids-find\">\n")
468 (princ (www-format-encode-string object-str))
469 (setq encoded-object-for-form
471 (insert (encode-coding-string object-str 'utf-8-jp-er))
472 (goto-char (point-min))
473 (while (search-forward ">-" nil t)
474 (replace-match "&GT-" t t)
479 " <input type=\"text\" name=\"components\"
480 size=\"30\" maxlength=\"30\" value=\"%s\" />"
481 encoded-object-for-form))
483 (www-format-encode-string
484 "を\u542Bむ\u6F22\u5B57を\u63A2す"))
485 (princ " <input type=\"submit\" value=\"search\" />\n")
489 "<form action=\"http://www.chise.org/hng-ids-find\">\n")
490 (princ (www-format-encode-string object-str))
494 " <input type=\"text\" name=\"components\"
495 size=\"30\" maxlength=\"30\" value=\"%s\" />"
496 encoded-object-for-form))
498 (www-format-encode-string
499 "を\u542Bむ HNG の\u6F22\u5B57を\u63A2す"))
500 (princ " <input type=\"submit\" value=\"search\" />\n")
509 (defun www-display-feature-desc (uri-feature-name genre uri-object
510 &optional lang simple)
511 (let ((rdf-uri-object (if est-hide-cgi-mode
512 (if (string-match "=" uri-object)
514 (est-uri-decode-feature-name-body
515 (substring uri-object 0 (match-beginning 0)))
517 (est-uri-decode-feature-name-body
518 (substring uri-object (match-end 0))))
520 (feature-name (www-uri-decode-feature-name uri-feature-name))
521 (name@lang (intern (format "name@%s" lang))))
523 (encode-coding-string
525 <title>EsT feature: %s</title>
533 (if est-hide-cgi-mode
534 "<div style=\"text-align:right;\">
535 <a href=\"../../../edit/view.cgi?feature=%s&%s=%s\">
536 <input type=\"submit\" value=\"Edit\" />
538 <input type=\"submit\" value=\"New Account\" />
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 uri-feature-name genre rdf-uri-object)
550 "<div style=\"text-align:right;\">
551 <a href=\"../view/feature/%s&%s/%s\">
552 <input type=\"submit\" value=\"Simple\" />
556 uri-feature-name genre uri-object)))
558 (format "<h1>%s</h1>\n"
559 (www-format-encode-string
560 (symbol-name feature-name))))
561 (princ (format "<p>name : %s "
562 (or (www-format-feature-name feature-name) "")))
566 " <a href=\"%s?feature=%s&property=name&format=string&%s=%s\">"
571 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
576 (www-format-encode-string
579 (or (char-feature-property feature-name name@lang) ""))))
583 " <a href=\"%s?feature=%s&property=%s&format=string&%s=%s\">"
589 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
591 (www-html-display-paragraph
593 (or (www-feature-type feature-name)
594 ;; (char-feature-property feature-name 'type)
596 (princ (format "<p>value-format : %s "
599 (or (www-feature-value-format feature-name)
607 " <a href=\"%s?feature=%s&property=value-format&format=wiki-text&%s=%s\"
613 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
616 (princ (format "<p>value-presentation-format : %s "
618 nil 'value-presentation-format
619 (or (www-feature-value-format feature-name)
627 " <a href=\"%s?feature=%s&property=value-presentation-format&format=wiki-text&%s=%s\"
633 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
636 (princ "<p>format : ")
637 (www-html-display-text
638 (decode-coding-string
640 (www-feature-format feature-name))
645 " <a href=\"%s?feature=%s&property=format&format=wiki-text&%s=%s\"
651 (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
654 (www-html-display-paragraph
655 (format "description : %s"
656 (or (decode-coding-string
657 (char-feature-property feature-name 'description)
661 (www-html-display-paragraph
662 (format "description@%s : %s"
664 (or (char-feature-property
666 (intern (format "description@%s" lang)))
670 (defun www-batch-view ()
671 (setq terminal-coding-system 'binary)
673 (let* ((target (pop command-line-args-left))
674 (user (pop command-line-args-left))
675 (accept-language (pop command-line-args-left))
676 (mode (intern (pop command-line-args-left)))
681 (car (split-string accept-language ","))
685 (princ "Content-Type: text/html; charset=UTF-8
687 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
688 \"http://www.w3.org/TR/html4/loose.dtd\">
693 (when (string-match "^char=\\(&[^&;]+;\\)" target)
694 (setq ret (match-end 0))
697 (www-uri-encode-object
698 (www-uri-decode-object
699 'character (match-string 1 target)))
700 (substring target ret))))
702 (mapcar (lambda (cell)
703 (if (string-match "=" cell)
705 (setq genre (substring cell 0 (match-beginning 0))
706 ret (substring cell (match-end 0)))
709 (decode-uri-string genre 'utf-8-mcs-er))
711 (list (decode-uri-string cell 'utf-8-mcs-er))))
712 (split-string target "&")))
713 (setq ret (car target))
714 (cond ((eq (car ret) 'char)
715 (www-display-object-desc
716 'character (cdr ret) (cdr (assq 'feature target))
721 ((eq (car ret) 'feature)
722 (www-display-feature-desc
723 (decode-uri-string (cdr ret) 'utf-8-mcs-er)
730 (www-display-object-desc
731 (car ret) (cdr ret) (cdr (assq 'feature target))
738 (princ (format "mode=%S\n" mode))
739 (princ (format "user=%s\n" user))
740 ;; (princ (format "local user=%s\n" (user-login-name)))
741 (princ (format "lang=%S\n" lang))
742 (princ (encode-coding-string (emacs-version) 'utf-8-jp-er))
744 ;; (princ xemacs-chise-version)
750 (princ (format "%S" err)))
753 (defun www-batch-view-smart ()
754 (setq debug-on-error t)
755 (setq terminal-coding-system 'binary)
757 (let* ((est-hide-cgi-mode t)
758 (target (pop command-line-args-left))
759 (user (pop command-line-args-left))
760 (accept-language (pop command-line-args-left))
761 (mode (intern (pop command-line-args-left)))
766 (car (split-string accept-language ","))
769 ret genre feature obj-url json obj)
772 (when (string-match "/data\\.json$" target)
774 target (substring target 0 (match-beginning 0))))
775 (when (string-match "^char/\\(&[^&;]+;\\)" target)
776 (setq ret (match-end 0))
779 (www-uri-encode-object
780 (www-uri-decode-object
781 'character (match-string 1 target)))
782 (substring target ret))))
786 (if (string-match "/" cell)
788 (setq genre (substring cell 0 (match-beginning 0))
789 ret (substring cell (match-end 0)))
791 (intern (decode-uri-string genre 'utf-8-mcs-er))
793 ((string-match "/feature=" ret)
794 (list (substring ret 0 (match-beginning 0))
795 (substring ret (match-end 0)))
797 ((string-match "...$.zoom-xywh=" ret)
798 (list (substring ret 0 (match-beginning 0))
800 (substring ret (match-end 0)))
804 (list (decode-uri-string cell 'utf-8-mcs-er)))
805 ;; (setq ret (split-string cell "/"))
807 ;; (decode-uri-string (car ret) 'utf-8-mcs-er))
810 (split-string target "&")))
811 (setq ret (car target))
813 (princ "Content-Type: application/json; charset=UTF-8
816 (princ "Content-Type: text/html; charset=UTF-8
818 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
819 \"http://www.w3.org/TR/html4/loose.dtd\">
823 ;; (princ (format "<p>%S, %S, %S</p>"
824 ;; (car ret)(nth 1 ret)(nth 2 ret)))
825 ;; (princ (format "// %S %S\n" ret json))
826 (cond ((or (eq (car ret) 'char)
827 (eq (car ret) 'character))
829 (setq obj (www-uri-decode-object
830 (car ret)(nth 1 ret)))
833 ;; (princ (encode-coding-string
834 ;; (format "// %S\n" obj)
835 ;; char-db-file-coding-system))
836 (char-db-json-char-data-with-variant obj 'printable)
837 (encode-coding-region
838 (point-min)(point-max)
839 char-db-file-coding-system)
840 (princ (buffer-string))
842 (www-display-object-desc
843 'character (nth 1 ret) (nth 2 ret)
848 ((eq (car ret) 'feature)
849 (www-display-feature-desc
850 (decode-uri-string (nth 1 ret) 'utf-8-mcs-er)
852 (nth 1 (nth 1 target))
856 ;; ((eq (car ret) 'image-resource)
858 ;; ;; ((string-match "^\\.iiif=" (nth 1 ret))
859 ;; ;; (setq obj-url (decode-uri-string
860 ;; ;; (substring (nth 1 ret) (match-end 0))
861 ;; ;; 'utf-8-mcs-er))
862 ;; ;; (setq obj (concord-images-add-iiif obj-url))
863 ;; ;; (www-display-object-desc
864 ;; ;; 'image-resource
865 ;; ;; (www-uri-encode-object obj)
868 ;; ;; (eq mode 'simple))
871 ;; (princ (nth 1 ret))
872 ;; (www-display-object-desc
873 ;; 'image-resource (nth 1 ret) (nth 2 ret)
875 ;; (eq mode 'simple))
879 (www-display-object-desc
880 (car ret) (nth 1 ret) (nth 2 ret)
888 (princ (format "mode=%S\n" mode))
889 (princ (format "user=%s\n" user))
890 ;; (princ (format "local user=%s\n" (user-login-name)))
891 (princ (format "lang=%S\n" lang))
892 (princ (encode-coding-string (emacs-version) 'utf-8-jp-er))
894 ;; (princ xemacs-chise-version)
901 (princ (format "%S" err)))
904 (provide 'cwiki-view)