(www-display-object-desc): Add CSS setting for image-list.
[chise/est.git] / cwiki-view.el
1 ;; -*- coding: utf-8-mcs-er -*-
2 (require 'cwiki-format)
3 (require 'char-db-json)
4
5 (defvar chise-wiki-view-url "view.cgi")
6 (defvar chise-wiki-edit-url "edit.cgi")
7 (defvar chise-wiki-add-url "add.cgi")
8
9 (defun www-edit-display-feature-input-box (char feature-name
10                                                 &optional format value)
11   (if (symbolp char)
12       (setq char (or (concord-decode-object '=id char 'feature)
13                      (concord-make-object 'feature char))))
14   (unless format
15     (setq format 'default))
16   (unless value
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))))
21   (princ
22    (format "<p><input type=\"text\" name=\"feature-name\"
23 size=\"32\" maxlength=\"256\" value=\"%s\">"
24            feature-name))
25   (princ (encode-coding-string " \u2190 " 'utf-8-mcs-er))
26   (princ
27    (format "%s<input type=\"text\" name=\"%s\"
28 size=\"64\" maxlength=\"256\" value=\"%s\">
29 <input type=\"submit\" value=\"set\" /></p>
30 "
31            (if (or (eq format 'HEX)(eq format 'hex))
32                "0x"
33              "")
34            format
35            (mapconcat (lambda (c)
36                         (cond
37                          ;; ((eq c ?<) "&amp;lt;")
38                          ;; ((eq c ?>) "&amp;gt;")
39                          ((eq c ?\u0022) "&quot;")
40                          (t
41                           (char-to-string c))))
42                       (est-format-list value format nil nil " ")
43                       "")))
44   )
45
46 (defun www-display-object-desc (genre uri-object &optional uri-feature-name
47                                       image-selection
48                                       lang level simple
49                                       uri-feature-name-to-edit editing-format)
50   (unless level
51     (setq level 0))
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
55                                  "../.."
56                                ".."))
57         (rdf-uri-object (if est-hide-cgi-mode
58                             (if (string-match "=" uri-object)
59                                 (concat
60                                  (est-uri-decode-feature-name-body
61                                   (substring uri-object 0 (match-beginning 0)))
62                                  ":"
63                                  (est-uri-decode-feature-name-body
64                                   (substring uri-object (match-end 0))))
65                               uri-object)))
66         feature-name-to-display feature-name-to-edit
67         base-name-to-edit metadata-name-to-edit
68         without-header
69         logical-feature chise-wiki-displayed-features
70         parents
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)
73     (if (eq level 0)
74         (setq level 1
75               without-header nil)
76       (setq without-header t))
77     (when object
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)))
93       (when (= level 1)
94         (princ
95          (encode-coding-string
96           (format "<head>
97 <style type=\"text/css\">
98 <!--
99 hr { color: green; }
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; }
107
108 .tooltip {
109     position: relative;
110     display: inline-block;
111     border-bottom: 1px dotted black;
112 }
113
114 .tooltip .tooltiptext {
115     visibility: hidden;
116     width: 120px;
117     top: 100%%;
118     left: 50%%;
119     margin-left: -60px;
120     background-color: black;
121     color: #fff;
122     text-align: center;
123     padding: 5px 0;
124     border-radius: 6px;
125  
126     position: absolute;
127     z-index: 1;
128 }
129
130 .value .image-list img { height: 320px; vertical-align: top; }
131
132 .list .tooltip:hover .tooltiptext {
133     visibility: visible;
134 }
135 -->
136 </style>
137
138 <script
139  src=\"http://hng.chise.org/openseadragon/openseadragon.min.js\"></script>
140
141 <title>EsT %s = %s</title>
142 </head>\n"
143                   genre
144                   (decode-uri-string uri-object 'utf-8-mcs-er))
145           'utf-8-mcs-er))
146         (princ "<body>\n"))
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))))
151       (princ
152        (if simple
153            (format
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\" />
158 </a>\n"
159               "<div style=\"text-align:right;\">
160 <a href=\"edit/view.cgi?%s=%s\">
161 <input type=\"submit\" value=\"Edit\" />
162 </a>\n")
163             genre rdf-uri-object)
164          (format
165           "<div style=\"text-align:right;\">
166 <a href=\"../view/%s/%s\">
167 <input type=\"submit\" value=\"Simple\" />
168 </a>\n"
169           genre
170           (if (string-match ":" uri-object)
171               (concat
172                (est-uri-encode-feature-name-body
173                 (substring uri-object 0 (match-beginning 0)))
174                "="
175                (est-uri-encode-feature-name-body
176                 (substring uri-object (match-end 0))))))))
177       (princ
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\" />
181 </a>%s
182 </div>
183 <hr />\n"
184                genre rdf-uri-object
185                (if (eq genre 'character)
186                    (format "
187 <a href=\"/est/view/%s/%s/data.json\">
188 <input type=\"submit\" value=\"JSON\" />
189 </a>\n"
190                            genre rdf-uri-object)
191                  "")))
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)))
202       (cond
203        ((eq genre 'image-resource)
204         (princ
205          (if (setq ret (concord-object-get object '=location@iiif))
206              (if (setq base-image
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)
215                          ret ret)
216                (if (and image-selection
217                         (string-match "\\([0-9]+\\),\\([0-9]+\\),\\([0-9]+\\),\\([0-9]+\\)" image-selection))
218                    (progn
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)))
223                      (setq width (float
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>
229
230 <script type=\"text/javascript\">
231     var viewer;
232     viewer = OpenSeadragon({
233         id: \"openseadragon1\",
234         prefixUrl: \"http://hng.chise.org/openseadragon/images/\",
235         preserveViewport:   true,
236         visibilityRatio:    1,
237         minZoomLevel:       1,
238         defaultZoomLevel:   1,
239         sequenceMode:       true,
240         tileSources:   [ \"%s/info.json\" ]
241     });
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();
246     });
247 </script>
248 "
249                            ret
250                            (/ x width)
251                            (/ y width)
252                            (/ w width)
253                            (/ h width)
254                            ))
255                  (format "<div id=\"openseadragon1\"
256  style=\"width: 800px; height: 600px;\"></div>
257
258 <script type=\"text/javascript\">
259     OpenSeadragon({
260         id: \"openseadragon1\",
261         prefixUrl: \"http://hng.chise.org/openseadragon/images/\",
262         preserveViewport:   true,
263         visibilityRatio:    1,
264         minZoomLevel:       1,
265         defaultZoomLevel:   1,
266         sequenceMode:       true,
267         tileSources:   [ \"%s/info.json\" ]
268     });
269 </script>
270 "
271                          ret)))
272            (setq ret (concord-object-get object '=location))
273            (format "<img alt=\"%s\" src=\"%s\" />"
274                    ret ret)))
275         )
276        ((and (eq genre 'glyph-image)
277              (setq image-cobj
278                    (car (concord-object-get object '->image-resource))))
279         (if (and (setq ret (concord-object-get image-cobj '=location@iiif))
280                  (setq base-image
281                        (car (concord-object-get image-cobj '<-image-segment))))
282             (princ
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)
290                      ret ret))
291           (setq ret (concord-object-get image-cobj '=location))
292           (princ (format "<img alt=\"%s\" src=\"%s\" />"
293                          ret ret)))
294         )
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))
299         (princ
300          (format
301           "<img alt=\"HNG-card:%s\"
302 src=\"http://hng.chise.org/images/HNG/%03d/card/%04d.jpg\"
303 style=\"height: 480px;\" />"
304           ret
305           (string-to-int (match-string 1 ret))
306           (string-to-int (match-string 2 ret))))
307         )
308        (t
309         (setq ret (www-format-encode-string
310                    (est-format-object object 'readable)))
311         (when (string-match
312                "<img alt=\"HNG\\([0-9]+\\)-\\([0-9]+\\)[a-z]?\"" ret)
313           (setq HNG-card-id
314                 (intern
315                  (format "%d-%d"
316                          (string-to-int (match-string 1 ret))
317                          (string-to-int (match-string 2 ret)))))
318           (setq HNG-card
319                 (format "hng-card/rep.id=%s" HNG-card-id)))
320         (princ
321          (format "<h%d>%s%s</h%d>\n"
322                  level
323                  (cond
324                   (uri-feature-name
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)
330                            ret)
331                    )
332                   (HNG-card
333                    (format
334                     "<a href=\"../%s\">%s</a>"
335                     HNG-card ret)
336                    )
337                   (t ret))
338                  (if GlyphWiki-id
339                      (format
340                       " <a href=\"http://glyphwiki.org/wiki/%s\"><img alt=\"%s\" src=\"http://glyphwiki.org/glyph/%s.50px.png\" /></a>"
341                       GlyphWiki-id
342                       GlyphWiki-id GlyphWiki-id)
343                    "")
344                  level))
345         ))
346       (if (> level 1)
347           (princ "<ul>"))
348       (when feature-name-to-edit
349         (princ "<form action=\"set.cgi\" method=\"GET\">\n")
350         (princ
351          (encode-coding-string
352           (format "<p>(%s : <input type=\"text\" name=\"%s\"
353 size=\"30\" maxlength=\"30\" value=\"%s\">)</p>
354 "
355                   genre genre
356                   (decode-uri-string uri-object 'utf-8-mcs-er))
357           'utf-8-mcs-er)))
358       (when (and HNG-card-id
359                  (eq genre 'character)
360                  (setq HNG-card-cobj
361                        (concord-decode-object
362                         '=id HNG-card-id
363                         'hng-card)))
364         (put-char-attribute object 'sources@HNG/card (list HNG-card-cobj))
365         (if (setq ret (concord-object-get
366                        HNG-card-cobj
367                        '->glyph-image@zinbun/takuhon))
368             (put-char-attribute object 'sources@zinbun/takuhon ret))
369         )
370       (setq object-spec
371             (cond
372              (uri-feature-name
373               (setq feature-name-to-display
374                     (www-uri-decode-feature-name uri-feature-name))
375               (setq est-eval-list-feature-items-limit nil)
376               (list
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)))))
381              (t
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)
388                                   object-spec))))
389       (dolist (cell (sort object-spec
390                           (lambda (a b)
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)
397           (cond
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)
402             )
403            (t
404             (princ
405              (if (= level 1)
406                  "<div class=\"feature\" style=\"line-height:150%\">\n"
407                "<li>\n"))
408             (princ
409              (www-format-eval-list
410               (www-feature-format logical-feature)
411               object
412               logical-feature ; (car cell)
413               lang uri-object
414               nil simple))
415             (unless simple
416               (princ
417                (format " <a href=\"%s?%s=%s&feature=%s&format=wiki-text\"
418 ><input type=\"submit\" value=\"note\" /></a>"
419                        chise-wiki-edit-url
420                        genre
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)
426                                          )))))))
427             (when (and feature-name-to-edit
428                        (eq base-name-to-edit (car cell)) metadata-name-to-edit)
429               (princ "<ul>\n")
430               (princ "<li>")
431               (www-edit-display-feature-input-box
432                object feature-name-to-edit editing-format)
433               (princ "</li>")
434               (princ "</ul>"))
435             (princ
436              (if (= level 1)
437                  "</div>\n"
438                "<li>\n"))
439             ))
440           ))
441       (princ
442        (if (= level 1)
443            "<p>\n"
444          "<li>\n"))
445       (when feature-name-to-edit
446         (princ "</form>\n"))
447       (unless simple
448         (princ
449          (format "<a href=\"%s?%s=%s\"
450 ><input type=\"submit\" value=\"add feature\" /></a>
451 "
452                  chise-wiki-add-url
453                  genre
454                  (www-format-encode-string uri-object))))
455       (princ
456        (if (= level 1)
457            "<p>\n"
458          "<li>\n"))
459       (when (eq genre 'character)
460         (princ
461          "<form action=\"http://www.chise.org/ids-find\">\n")
462         (princ
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)))
468           ))
469         (princ
470          (format
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)))
478            'utf-8-jp-er)))
479         (princ
480          (www-format-encode-string
481           "を\u542Bむ\u6F22\u5B57を\u63A2す"))
482         (princ " <input type=\"submit\" value=\"search\" />\n")
483         (princ "</form>\n")
484
485         (princ
486          "<form action=\"http://www.chise.org/hng-ids-find\">\n")
487         (princ
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)))
493           ))
494         (princ
495          (format
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)))
503            'utf-8-jp-er)))
504         (princ
505          (www-format-encode-string
506           "を\u542Bむ HNG の\u6F22\u5B57を\u63A2す"))
507         (princ " <input type=\"submit\" value=\"search\" />\n")
508         (princ "</form>\n")
509         )
510       (princ
511        (if (= level 1)
512            "</p>\n"
513          "<li>\n"))
514       )))
515
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)
520                                 (concat
521                                  (est-uri-decode-feature-name-body
522                                   (substring uri-object 0 (match-beginning 0)))
523                                  ":"
524                                  (est-uri-decode-feature-name-body
525                                   (substring uri-object (match-end 0))))
526                               uri-object)))
527         (feature-name (www-uri-decode-feature-name uri-feature-name))
528         (name@lang (intern (format "name@%s" lang))))
529     (princ
530      (encode-coding-string
531       (format "<head>
532 <title>EsT feature: %s</title>
533 </head>\n"
534               feature-name)
535       'utf-8-mcs-er))
536     (princ "<body>\n")
537     (princ
538      (if simple
539          (format
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\" />
544 </a>
545 <input type=\"submit\" value=\"New Account\" />
546 </div>
547 <hr />\n"
548             "<div style=\"text-align:right;\">
549 <a href=\"edit/view.cgi?feature=%s&%s=%s\">
550 <input type=\"submit\" value=\"Edit\" />
551 </a>
552 <input type=\"submit\" value=\"New Account\" />
553 </div>
554 <hr />\n")
555           uri-feature-name genre rdf-uri-object)
556        (format
557         "<div style=\"text-align:right;\">
558 <a href=\"../view/feature/%s&%s/%s\">
559 <input type=\"submit\" value=\"Simple\" />
560 </a>
561 </div>
562 <hr />\n"
563         uri-feature-name genre uri-object)))
564     (princ
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) "")))
570     (unless simple
571       (princ
572        (format
573         " <a href=\"%s?feature=%s&property=name&format=string&%s=%s\">"
574         chise-wiki-edit-url
575         uri-feature-name
576         genre
577         uri-object))
578       (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
579     (princ "</p>\n")
580     (when lang
581       (princ "<p>")
582       (princ
583        (www-format-encode-string
584         (format "%s : %s"
585                 name@lang
586                 (or (char-feature-property feature-name name@lang) ""))))
587       (unless simple
588         (princ
589          (format
590           " <a href=\"%s?feature=%s&property=%s&format=string&%s=%s\">"
591           chise-wiki-edit-url
592           uri-feature-name
593           name@lang
594           genre
595           uri-object))
596         (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
597       (princ "</p>\n"))
598     (www-html-display-paragraph
599      (format "type : %s"
600              (or (www-feature-type feature-name)
601                  ;; (char-feature-property feature-name 'type)
602                  'generic)))
603     (princ (format "<p>value-format : %s "
604                    (www-format-value
605                     nil 'value-format 
606                     (or (www-feature-value-format feature-name)
607                         'default)
608                     'default
609                     'without-tags)
610                    ))
611     (unless simple
612       (princ
613        (format
614         " <a href=\"%s?feature=%s&property=value-format&format=wiki-text&%s=%s\"
615 >"
616         chise-wiki-edit-url
617         uri-feature-name
618         genre
619         uri-object))
620       (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
621     (princ "</p>\n")
622
623     (princ (format "<p>value-presentation-format : %s "
624                    (www-format-value
625                     nil 'value-presentation-format 
626                     (or (www-feature-value-format feature-name)
627                         'default)
628                     'default
629                     'without-tags)
630                    ))
631     (unless simple
632       (princ
633        (format
634         " <a href=\"%s?feature=%s&property=value-presentation-format&format=wiki-text&%s=%s\"
635 >"
636         chise-wiki-edit-url
637         uri-feature-name
638         genre
639         uri-object))
640       (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
641     (princ "</p>\n")
642
643     (princ "<p>format : ")
644     (www-html-display-text
645      (decode-coding-string
646       (www-xml-format-list
647        (www-feature-format feature-name))
648       'utf-8-mcs-er))
649     (unless simple
650       (princ
651        (format
652         " <a href=\"%s?feature=%s&property=format&format=wiki-text&%s=%s\"
653 >"
654         chise-wiki-edit-url
655         uri-feature-name
656         genre
657         uri-object))
658       (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
659     (princ "</p>\n")
660     
661     (www-html-display-paragraph
662      (format "description : %s"
663              (or (decode-coding-string
664                   (char-feature-property feature-name 'description)
665                   'utf-8-mcs-er)
666                  "")))
667     (when lang
668       (www-html-display-paragraph
669        (format "description@%s : %s"
670                lang
671                (or (char-feature-property
672                     feature-name
673                     (intern (format "description@%s" lang)))
674                    ""))))
675     ))
676   
677 (defun www-batch-view ()
678   (setq terminal-coding-system 'binary)
679   (condition-case err
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)))
684              (lang
685               (intern
686                (car (split-string
687                      (car (split-string
688                            (car (split-string accept-language ","))
689                            ";"))
690                      "-"))))
691              ret genre)
692         (princ "Content-Type: text/html; charset=UTF-8
693
694 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
695             \"http://www.w3.org/TR/html4/loose.dtd\">
696 <html lang=\"ja\">
697 ")
698         (cond
699          ((stringp target)
700           (when (string-match "^char=\\(&[^&;]+;\\)" target)
701             (setq ret (match-end 0))
702             (setq target
703                   (concat "char="
704                           (www-uri-encode-object
705                            (www-uri-decode-object
706                             'character (match-string 1 target)))
707                           (substring target ret))))
708           (setq target
709                 (mapcar (lambda (cell)
710                           (if (string-match "=" cell)
711                               (progn
712                                 (setq genre (substring cell 0 (match-beginning 0))
713                                       ret (substring cell (match-end 0)))
714                                 (cons
715                                  (intern
716                                   (decode-uri-string genre 'utf-8-mcs-er))
717                                  ret))
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))
724                   nil
725                   lang nil
726                   (eq mode 'simple))
727                  )
728                 ((eq (car ret) 'feature)
729                  (www-display-feature-desc
730                   (decode-uri-string (cdr ret) 'utf-8-mcs-er)
731                   (car (nth 1 target))
732                   (cdr (nth 1 target))
733                   lang
734                   (eq mode 'simple))
735                  )
736                 (t
737                  (www-display-object-desc
738                   (car ret) (cdr ret) (cdr (assq 'feature target))
739                   nil
740                   lang nil
741                   (eq mode 'simple))
742                  ))
743           ))
744         (princ "\n<hr>\n")
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))
750         ;; (princ " CHISE ")
751         ;; (princ xemacs-chise-version)
752         (princ "
753 </body>
754 </html>")
755         )
756     (error nil
757            (princ (format "%S" err)))
758     ))
759
760 (defun www-batch-view-smart ()
761   (setq debug-on-error t)
762   (setq terminal-coding-system 'binary)
763   (condition-case err
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)))
769              (lang
770               (intern
771                (car (split-string
772                      (car (split-string
773                            (car (split-string accept-language ","))
774                            ";"))
775                      "-"))))
776              ret genre feature obj-url json obj)
777         (cond
778          ((stringp target)
779           (when (string-match "/data\\.json$" target)
780             (setq json t
781                   target (substring target 0 (match-beginning 0))))
782           (when (string-match "^char/\\(&[^&;]+;\\)" target)
783             (setq ret (match-end 0))
784             (setq target
785                   (concat "char/"
786                           (www-uri-encode-object
787                            (www-uri-decode-object
788                             'character (match-string 1 target)))
789                           (substring target ret))))
790           (setq target
791                 (mapcar
792                  (lambda (cell)
793                    (if (string-match "/" cell)
794                        (progn
795                          (setq genre (substring cell 0 (match-beginning 0))
796                                ret (substring cell (match-end 0)))
797                          (cons
798                           (intern (decode-uri-string genre 'utf-8-mcs-er))
799                           (cond
800                            ((string-match "/feature=" ret)
801                             (list (substring ret 0 (match-beginning 0))
802                                   (substring ret (match-end 0)))
803                             )
804                            ((string-match "...$.zoom-xywh=" ret)
805                             (list (substring ret 0 (match-beginning 0))
806                                   nil
807                                   (substring ret (match-end 0)))
808                             )
809                            (t
810                             (list ret)))))
811                      (list (decode-uri-string cell 'utf-8-mcs-er)))
812                    ;; (setq ret (split-string cell "/"))
813                    ;; (cons (intern
814                    ;;        (decode-uri-string (car ret) 'utf-8-mcs-er))
815                    ;;       (cdr ret))
816                    )
817                  (split-string target "&")))
818           (setq ret (car target))
819           (if json
820               (princ "Content-Type: application/json; charset=UTF-8
821
822 ")
823             (princ "Content-Type: text/html; charset=UTF-8
824
825 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
826             \"http://www.w3.org/TR/html4/loose.dtd\">
827 <html lang=\"ja\">
828 ")
829             )
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))
835                  (if (and json
836                           (setq obj (www-uri-decode-object
837                                      (car ret)(nth 1 ret)))
838                           (characterp obj))
839                      (with-temp-buffer
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))
848                        )
849                    (www-display-object-desc
850                     'character (nth 1 ret) (nth 2 ret)
851                     nil
852                     lang nil
853                     (eq mode 'simple)))
854                  )
855                 ((eq (car ret) 'feature)
856                  (www-display-feature-desc
857                   (decode-uri-string (nth 1 ret) 'utf-8-mcs-er)
858                   (car (nth 1 target))
859                   (nth 1 (nth 1 target))
860                   lang
861                   (eq mode 'simple))
862                  )
863                 ;; ((eq (car ret) 'image-resource)
864                 ;; ;;  (cond
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)
873                 ;; ;;     (nth 2 ret)
874                 ;; ;;     lang nil
875                 ;; ;;     (eq mode 'simple))
876                 ;; ;;    )
877                 ;; ;;   (t
878                 ;;  (princ (nth 1 ret))
879                 ;;  (www-display-object-desc
880                 ;;   'image-resource (nth 1 ret) (nth 2 ret)
881                 ;;   lang nil
882                 ;;   (eq mode 'simple))
883                 ;; ;;    ))
884                 ;;  )
885                 (t
886                  (www-display-object-desc
887                   (car ret) (nth 1 ret) (nth 2 ret)
888                   (nth 3 ret)
889                   lang nil
890                   (eq mode 'simple))
891                  ))
892           ))
893         (unless json
894           (princ "\n<hr>\n")
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))
900           ;; (princ " CHISE ")
901           ;; (princ xemacs-chise-version)
902           (princ "
903 </body>
904 </html>")
905           )
906         )
907     (error nil
908            (princ (format "%S" err)))
909     ))
910
911 (provide 'cwiki-view)